MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / main

Function main

apps/web/server/create-codex-thread.ts:48–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48async function main() {
49 const raw = await readStdin();
50 const payload = JSON.parse(raw || '{}') as InputPayload;
51 const cwd = normalizeText(payload.cwd);
52 const model = normalizeText(payload.model);
53 const permissionsMode = normalizePermissionsMode(payload.permissionsMode);
54 const reasoningEffort = normalizeText(payload.reasoningEffort);
55 const stateDir = normalizeText(payload.stateDir);
56 const repoRoot = normalizeText(payload.repoRoot);
57
58 if (!stateDir || !repoRoot) {
59 throw new Error('invalid_request');
60 }
61 const targetCwd = cwd || repoRoot;
62
63 const runtimeDir = path.join(stateDir, 'runtime');
64 const repositories = createFileJsonRepositories(runtimeDir);
65 const providerProfiles = repositories.providerProfiles.list();
66 const defaultProviderProfileId = providerProfiles.some((profile) => profile.id === 'openai-default')
67 ? 'openai-default'
68 : (providerProfiles[0]?.id ?? null);
69
70 const runtime = createCodexBridgeRuntime({
71 providerPlugins: [
72 new OpenAINativeProviderPlugin(),
73 new OpenAICompatibleProviderPlugin(),
74 ],
75 providerProfiles,
76 defaultProviderProfileId,
77 defaultCwd: process.env.CODEXBRIDGE_DEFAULT_CWD ?? repoRoot,
78 locale: 'zh-CN',
79 repositories,
80 assistantAttachmentRoot: path.join(stateDir, 'assistant', 'attachments'),
81 codexAuthManager: new CodexAccountManager({
82 rootDir: path.join(stateDir, 'runtime', 'codex-login'),
83 }),
84 codexGoalManager: new CodexGoalManager({
85 filePath: path.join(stateDir, 'runtime', 'codex-goal.txt'),
86 }),
87 });
88
89 const providerProfileId = resolveNativeProviderProfileId(runtime);
90 const initialSettings = {
91 ...(permissionsMode ? buildPermissionsSettingsUpdate(permissionsMode) : {}),
92 ...(model ? { model } : {}),
93 ...(reasoningEffort ? { reasoningEffort } : {}),
94 };
95 const session = await runtime.services.bridgeSessions.createDetachedSession({
96 providerProfileId,
97 cwd: targetCwd,
98 initialSettings,
99 title: null,
100 });
101
102 await Promise.allSettled(
103 runtime.registry.listProviders<any>().map((plugin) => plugin?.stop?.()),
104 );
105

Callers 1

Calls 12

normalizePermissionsModeFunction · 0.90
createCodexBridgeRuntimeFunction · 0.90
createDetachedSessionMethod · 0.80
listProvidersMethod · 0.80
writeMethod · 0.80
readStdinFunction · 0.70
normalizeTextFunction · 0.70
listMethod · 0.65
stopMethod · 0.65

Tested by

no test coverage detected