Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# production
/build
/electron-dist

# misc
.DS_Store
Expand Down
105 changes: 105 additions & 0 deletions electron/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import builder from 'electron-builder';
import os from 'os';

const Platform = builder.Platform;

/**
* @type {import('electron-builder').Configuration}
*/
const options = {
appId: 'ai.gptscript.assistant-studio',
productName: 'Assistant Studio',
files: [
"**/*",
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
"!**/node_modules/.bin",
"!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
"!.editorconfig",
"!**/._*",
"!**/.next/cache",
"!**/node_modules/@next/swc*",
"!**/node_modules/@next/swc*/**",
"!**/{.DS_Store,.git,.github,*.zip,*.tar.gz,.hg,.svn,CVS,RCS,SCCS,.gitignore,.vscode,.gitattributes,package-lock.json}",
"!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
"!**/{appveyor.yml,.travis.yml,circle.yml}",
"!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}"
],
mac: {
hardenedRuntime: true,
gatekeeperAssess: false,
entitlements: 'electron/entitlements.mac.plist',
entitlementsInherit: 'electron/entitlements.mac.plist',
icon: 'electron/icon.icns',
category: 'public.app-category.productivity',
target: 'dmg',
},
dmg: {
writeUpdateInfo: false,
},
win: {
artifactName: '${productName}-Setup-${version}.${ext}',
target: {
target: 'nsis',
},
},
linux: {
maintainer: 'Acorn Labs',
category: 'Office',
desktop: {
StartupNotify: 'false',
Encoding: 'UTF-8',
MimeType: 'x-scheme-handler/deeplink',
},
icon: "electron/icon.icns",
target: ['AppImage'],
},
compression: 'normal',
removePackageScripts: true,
nodeGypRebuild: false,
buildDependenciesFromSource: false,
directories: {
// app: 'gptscript-ui',
output: 'electron-dist'
},
nsis: {deleteAppDataOnUninstall: true},
publish: {
provider: "github",
publishAutoUpdate: false,
}
};

function go() {
const platform = os.platform();
const arch = os.arch();

let targetPlatform;
switch (platform) {
case 'darwin':
targetPlatform = 'mac';
break;
case 'win32':
targetPlatform = 'windows';
break;
case 'linux':
targetPlatform = 'linux';
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
console.log(`targetPlatform: ${targetPlatform}`)

builder
.build({
targets: Platform[targetPlatform.toUpperCase()].createTarget(),
config: options,
})
.then((result) => {
console.info('----------------------------');
console.info('Platform:', platform);
console.info('Architecture:', arch);
console.info('Output:', JSON.stringify(result, null, 2));
});
}

go();
10 changes: 10 additions & 0 deletions electron/entitlements.mac.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
</dict>
</plist>
Binary file added electron/icon.icns
Binary file not shown.
Binary file added electron/icon.ico
Binary file not shown.
Binary file added electron/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions electron/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { app, BrowserWindow } from "electron";
import { getPort } from 'get-port-please';
import { startAppServer } from '../server/app.mjs';
import { join, dirname } from "path";
import { homedir } from "os";
import { existsSync, mkdirSync } from "fs";
import fixPath from "fix-path";

const appName = 'assistant-studio'; // Replace with your app's name
const gatewayUrl = process.env.GATEWAY_URL || 'https://gateway-api.gptscript.ai';
const resourcesDir = dirname(app.getAppPath());
const cacheDir = getCacheDir(appName);

function getCacheDir(appName) {
const platform = process.platform;
const baseDir = platform === 'win32' ? process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local') :
platform === 'darwin' ? join(homedir(), 'Library', 'Caches') :
process.env.XDG_CACHE_HOME || join(homedir(), '.cache');
return join(baseDir, appName);
}

function ensureDirExists(dir) {
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
}

async function startServer(isPackaged) {
const port = isPackaged ? await getPort({ portRange: [30000, 40000] }) : 3000;
const gptscriptBin = join(isPackaged ? resourcesDir : "", "node_modules", "@gptscript-ai", "gptscript", "bin", `gptscript${process.platform === "win32" ? ".exe" : ""}`);

process.env.GPTSCRIPT_BIN = process.env.GPTSCRIPT_BIN || gptscriptBin;
process.env.THREADS_DIR = process.env.THREADS_DIR || join(cacheDir, "threads");
process.env.WORKSPACE_DIR = process.env.WORKSPACE_DIR || join(cacheDir, "workspace");
process.env.GATEWAY_URL = process.env.GATEWAY_URL || gatewayUrl;

try {
const url = await startAppServer({ dev: !isPackaged, hostname: 'localhost', port, dir: app.getAppPath() });
console.log(`> ${isPackaged ? "" : "Dev "}Electron app started at ${url}`);
createWindow(url);
} catch (err) {
console.error(err);
process.exit(1);
}
}

function createWindow(url) {
const win = new BrowserWindow({
width: 1024,
height: 720,
frame: false, // This removes the title bar
webPreferences: {
preload: join(app.getAppPath(), "electron/preload.js"),
nodeIntegration: true,
allowRunningInsecureContent: true,
webSecurity: false,
disableBlinkFeatures: "Autofill",
}
});

win.loadURL(url);
win.webContents.on("did-fail-load", () => win.webContents.reloadIgnoringCache());
}

app.on("ready", () => {
fixPath();
ensureDirExists(cacheDir);
startServer(app.isPackaged);
});

app.on("window-all-closed", () => app.quit());
10 changes: 10 additions & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const electron = require('electron')

electron.contextBridge.exposeInMainWorld("electronAPI", {
on: (channel, callback) => {
electron.ipcRenderer.on(channel, callback);
},
send: (channel, args) => {
electron.ipcRenderer.send(channel, args);
}
});
Loading