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
3 changes: 1 addition & 2 deletions config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import {GPTScript} from "@gptscript-ai/gptscript"
import path from "path";

export const SCRIPTS_PATH = () => process.env.SCRIPTS_PATH || "gptscripts";
export const WORKSPACE_DIR = () => process.env.GPTSCRIPT_WORKSPACE_DIR || "";
export const WORKSPACE_DIR = () => process.env.WORKSPACE_DIR || "";
export const THREADS_DIR = () => process.env.THREADS_DIR || path.join(WORKSPACE_DIR(), "threads");
export const GATEWAY_URL = () => process.env.GATEWAY_URL || "http://localhost:8080";

export const set_WORKSPACE_DIR = (dir: string) => process.env.GPTSCRIPT_WORKSPACE_DIR = dir;
export const set_SCRIPTS_PATH = (dir: string) => process.env.SCRIPTS_PATH = dir;

let gptscript: GPTScript | null = null;

Expand Down
23 changes: 11 additions & 12 deletions electron/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ 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 appName = 'Assistant Studio';
const gatewayUrl = process.env.GATEWAY_URL || 'https://gateway-api.gptscript.ai';
const resourcesDir = dirname(app.getAppPath());
const cacheDir = getCacheDir(appName);
const dataDir = getDataDir(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 getDataDir(appName) {
const userDataPath = app.getPath('userData');
return join(userDataPath, appName);
}

function ensureDirExists(dir) {
Expand All @@ -28,9 +24,12 @@ async function startServer(isPackaged) {
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.THREADS_DIR = process.env.THREADS_DIR || join(dataDir, "threads");
process.env.WORKSPACE_DIR = process.env.WORKSPACE_DIR || join(dataDir, "workspace");
process.env.GATEWAY_URL = process.env.GATEWAY_URL || gatewayUrl;
process.env.DISABLE_CACHE = "true"; // TODO: Remove after https://github.com/gptscript-ai/gptscript/issues/713 is addressed

console.log(`Starting app server with GPTSCRIPT_BIN="${process.env.GPTSCRIPT_BIN}"`);

try {
const url = await startAppServer({ dev: !isPackaged, hostname: 'localhost', port, dir: app.getAppPath() });
Expand Down Expand Up @@ -62,7 +61,7 @@ function createWindow(url) {

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

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"main": "electron/main.mjs",
"dependencies": {
"@gptscript-ai/gptscript": "^0.9.2",
"@gptscript-ai/gptscript": "^0.9.4",
"@monaco-editor/react": "^4.6.0",
"@nextui-org/button": "2.0.32",
"@nextui-org/code": "2.0.28",
Expand Down
1 change: 0 additions & 1 deletion server/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dotenv.config({path: ['../.env', '../.env.local']});
const AGENT = 1;
const USER = 2;
const STATE_FILE = "state.json";
const DISABLE_CACHE = process.env.DISABLE_CACHE === "true";
let runningScript = null;
let serverRunning = false;

Expand Down