({
onApprovalRequest = null,
onAssistantText = null,
onCommentaryText = null,
onTurnStarted = null,
repoRoot,
stateDir,
text,
threadId,
}: {
onApprovalRequest?: ((request: { requestId?: string | null }) => Promise<void> | void) | null;
onAssistantText?: ((text: string) => Promise<void> | void) | null;
onCommentaryText?: ((text: string) => Promise<void> | void) | null;
onTurnStarted?: ((meta: {
bridgeSessionId: string;
providerProfileId: string;
threadId: string | null;
turnId: string | null;
}) => Promise<void> | void) | null;
repoRoot: string;
stateDir: string;
text: string;
threadId: string;
})
| 94 | } |
| 95 | |
| 96 | export async function executeWebThreadReply({ |
| 97 | onApprovalRequest = null, |
| 98 | onAssistantText = null, |
| 99 | onCommentaryText = null, |
| 100 | onTurnStarted = null, |
| 101 | repoRoot, |
| 102 | stateDir, |
| 103 | text, |
| 104 | threadId, |
| 105 | }: { |
| 106 | onApprovalRequest?: ((request: { requestId?: string | null }) => Promise<void> | void) | null; |
| 107 | onAssistantText?: ((text: string) => Promise<void> | void) | null; |
| 108 | onCommentaryText?: ((text: string) => Promise<void> | void) | null; |
| 109 | onTurnStarted?: ((meta: { |
| 110 | bridgeSessionId: string; |
| 111 | providerProfileId: string; |
| 112 | threadId: string | null; |
| 113 | turnId: string | null; |
| 114 | }) => Promise<void> | void) | null; |
| 115 | repoRoot: string; |
| 116 | stateDir: string; |
| 117 | text: string; |
| 118 | threadId: string; |
| 119 | }): Promise<WebReplyExecutionResult> { |
| 120 | const runtimeDir = path.join(stateDir, 'runtime'); |
| 121 | const repositories = createFileJsonRepositories(runtimeDir); |
| 122 | const providerProfiles = repositories.providerProfiles.list(); |
| 123 | const defaultProviderProfileId = providerProfiles.some((profile) => profile.id === 'openai-default') |
| 124 | ? 'openai-default' |
| 125 | : (providerProfiles[0]?.id ?? null); |
| 126 | |
| 127 | const runtime = createCodexBridgeRuntime({ |
| 128 | providerPlugins: [ |
| 129 | new OpenAINativeProviderPlugin(), |
| 130 | new OpenAICompatibleProviderPlugin(), |
| 131 | ], |
| 132 | providerProfiles, |
| 133 | defaultProviderProfileId, |
| 134 | defaultCwd: process.env.CODEXBRIDGE_DEFAULT_CWD ?? repoRoot, |
| 135 | locale: 'zh-CN', |
| 136 | repositories, |
| 137 | assistantAttachmentRoot: path.join(stateDir, 'assistant', 'attachments'), |
| 138 | codexAuthManager: new CodexAccountManager({ |
| 139 | rootDir: path.join(stateDir, 'runtime', 'codex-login'), |
| 140 | }), |
| 141 | codexGoalManager: new CodexGoalManager({ |
| 142 | filePath: path.join(stateDir, 'runtime', 'codex-goal.txt'), |
| 143 | }), |
| 144 | }); |
| 145 | |
| 146 | try { |
| 147 | const providerProfileId = inferNativeProviderProfileId(runtime, threadId); |
| 148 | const scopeRef = { |
| 149 | platform: 'web', |
| 150 | externalScopeId: `codex-thread:${threadId}`, |
| 151 | }; |
| 152 | const session = await runtime.services.bridgeSessions.bindScopeToProviderThread( |
| 153 | scopeRef, |
no test coverage detected