-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.mjs
More file actions
65 lines (58 loc) · 2.42 KB
/
Copy pathserver.mjs
File metadata and controls
65 lines (58 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { pathToFileURL } from "node:url";
import { ClankerBendHost, createMockTranscriptAdapter } from "./host/src/index.js";
import { createCodexDesktopMuxAdapter } from "./launch/codex-mux-adapter.mjs";
import { navigateProfile, printLaunchStatus } from "./launch/profiles.mjs";
export async function launchClankerBendCodex(options = {}) {
const mockMode = Boolean(options.mock);
const localDevInsecure = options.localDevInsecure === true || process.env.ONEWILL_CLANKERBEND_DISABLE_AUTH === "1";
const profile = await navigateProfile({
stateDir: options.stateDir,
runDir: options.runDir,
registryConfigPath: options.registryConfigPath,
registryProfileId: options.registryProfileId,
accountId: options.accountId,
primaryCodexHome: options.primaryCodexHome
});
const host = new ClankerBendHost({
hostId: profile.hostId,
hostName: profile.hostName,
token: options.token || process.env.ONEWILL_CLANKERBEND_TOKEN || undefined,
localDevInsecure,
runDir: profile.runDir,
accountRegistry: profile.accountRegistry,
transcriptAdapter: mockMode
? createMockTranscriptAdapter({ defaultAppId: profile.defaultPanelAppId, providers: profile.providers })
: createCodexDesktopMuxAdapter({
accountRegistry: profile.accountRegistry,
startAccountId: profile.startAccountId,
providers: profile.providers,
adapterOptions: {
runDir: profile.runDir,
rendererBridges: profile.rendererBridges,
providers: profile.providers
}
})
});
for (const app of profile.apps) host.registerApp(app);
host.setActivePanelApp(profile.defaultPanelAppId);
const cleanupAndExit = async (code = 0) => {
await host.stop().catch(() => {});
process.exit(code);
};
if (options.installSignalHandlers !== false) {
process.once("SIGINT", () => cleanupAndExit(0));
process.once("SIGTERM", () => cleanupAndExit(0));
process.once("uncaughtException", (err) => {
console.error(`ClankerBend could not start. Close any ClankerBend-launched Codex Desktop window, then run this command again. Details: ${err.message}`);
cleanupAndExit(1);
});
}
await host.start();
printLaunchStatus(profile, host, { mockMode });
return { host, profile, mockMode };
}
if (import.meta.url === pathToFileURL(process.argv[1] || "").href) {
await launchClankerBendCodex({
mock: process.argv.includes("--mock")
});
}