@agentclientprotocol/codex-acp 2.5.1-preview.19 → 2.5.1-preview.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +74 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40747,6 +40747,9 @@ function isCodexAuthRequest(request) {
|
|
|
40747
40747
|
return request.methodId === "api-key" || request.methodId === "chat-gpt" || request.methodId === "chat-gpt-device-code" || request.methodId === "gateway";
|
|
40748
40748
|
}
|
|
40749
40749
|
|
|
40750
|
+
// src/CodexAcpServer.ts
|
|
40751
|
+
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
40752
|
+
|
|
40750
40753
|
// src/mcp/McpServerSignIn.ts
|
|
40751
40754
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
40752
40755
|
function createMcpServerSignIn(connection, codexAcpClient, clientCapabilities) {
|
|
@@ -41948,7 +41951,7 @@ var package_default = {
|
|
|
41948
41951
|
publishConfig: {
|
|
41949
41952
|
access: "public"
|
|
41950
41953
|
},
|
|
41951
|
-
version: "2.5.1-preview.
|
|
41954
|
+
version: "2.5.1-preview.20",
|
|
41952
41955
|
description: "",
|
|
41953
41956
|
main: "dist/index.js",
|
|
41954
41957
|
bin: {
|
|
@@ -42521,6 +42524,19 @@ function narrowToListedModels(models, listed) {
|
|
|
42521
42524
|
return narrowed.map((model, index) => model.isDefault === (index === defaultIndex) ? model : { ...model, isDefault: index === defaultIndex });
|
|
42522
42525
|
}
|
|
42523
42526
|
|
|
42527
|
+
// src/CodexConfigOverride.ts
|
|
42528
|
+
function configOverride(key, value) {
|
|
42529
|
+
return ["-c", `${key}=${toToml(value)}`];
|
|
42530
|
+
}
|
|
42531
|
+
function toToml(value) {
|
|
42532
|
+
if (Array.isArray(value)) return `[${value.map(toToml).join(", ")}]`;
|
|
42533
|
+
if (value !== null && typeof value === "object") {
|
|
42534
|
+
return `{ ${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)} = ${toToml(item)}`).join(", ")} }`;
|
|
42535
|
+
}
|
|
42536
|
+
return JSON.stringify(value);
|
|
42537
|
+
}
|
|
42538
|
+
var NO_PROVIDER_STARTUP_CONFIG = { args: [], env: {} };
|
|
42539
|
+
|
|
42524
42540
|
// src/UnsupportedSkills.ts
|
|
42525
42541
|
var UNSUPPORTED_SKILL_NAMES = /* @__PURE__ */ new Set(["visualize:visualize"]);
|
|
42526
42542
|
function disableUnsupportedSkills(config2) {
|
|
@@ -43456,6 +43472,10 @@ var CodexAcpClient = class _CodexAcpClient {
|
|
|
43456
43472
|
getModelProvider() {
|
|
43457
43473
|
return this.gatewayConfig?.modelProvider ?? this.modelProvider;
|
|
43458
43474
|
}
|
|
43475
|
+
/** The provider routing that the app-server of this client must start with, see {@link providerStartupConfig}. */
|
|
43476
|
+
providerStartupConfig() {
|
|
43477
|
+
return providerStartupConfig(this.modelProvider, this.config, this.gatewayConfig);
|
|
43478
|
+
}
|
|
43459
43479
|
async getResumeModelProvider() {
|
|
43460
43480
|
return await this.getCurrentModelProvider() ?? "openai";
|
|
43461
43481
|
}
|
|
@@ -43909,6 +43929,28 @@ function mergeGatewayConfig(config2, gatewayConfig) {
|
|
|
43909
43929
|
return config2;
|
|
43910
43930
|
}
|
|
43911
43931
|
}
|
|
43932
|
+
function providerStartupConfig(modelProvider, config2, gatewayConfig) {
|
|
43933
|
+
const configuredProvider = typeof config2["model_provider"] === "string" ? config2["model_provider"] : null;
|
|
43934
|
+
const effectiveProvider = gatewayConfig?.modelProvider ?? modelProvider ?? configuredProvider;
|
|
43935
|
+
if (effectiveProvider === null) return NO_PROVIDER_STARTUP_CONFIG;
|
|
43936
|
+
const args = configOverride("model_provider", effectiveProvider);
|
|
43937
|
+
const providers = mergeGatewayConfig(config2, gatewayConfig)["model_providers"];
|
|
43938
|
+
const providerDefinition = isJsonObject3(providers) ? providers[effectiveProvider] : void 0;
|
|
43939
|
+
if (!isJsonObject3(providerDefinition)) return { args, env: {} };
|
|
43940
|
+
const { http_headers: headers, ...provider } = providerDefinition;
|
|
43941
|
+
const env = {};
|
|
43942
|
+
const envHeaders = isJsonObject3(provider["env_http_headers"]) ? { ...provider["env_http_headers"] } : {};
|
|
43943
|
+
if (isJsonObject3(headers)) {
|
|
43944
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
43945
|
+
if (typeof value !== "string") continue;
|
|
43946
|
+
const variable = `CODEX_ACP_PROVIDER_HEADER_${Object.keys(env).length}`;
|
|
43947
|
+
env[variable] = value;
|
|
43948
|
+
envHeaders[name] = variable;
|
|
43949
|
+
}
|
|
43950
|
+
}
|
|
43951
|
+
if (Object.keys(envHeaders).length > 0) provider["env_http_headers"] = envHeaders;
|
|
43952
|
+
return { args: [...args, ...configOverride(`model_providers.${effectiveProvider}`, provider)], env };
|
|
43953
|
+
}
|
|
43912
43954
|
async function* noItems() {
|
|
43913
43955
|
}
|
|
43914
43956
|
async function* oneItemPage(items) {
|
|
@@ -46083,6 +46125,10 @@ function isConnectionDeathError(error62) {
|
|
|
46083
46125
|
}
|
|
46084
46126
|
|
|
46085
46127
|
// src/app-server-recovery/CodexAppServerSupervisor.ts
|
|
46128
|
+
function appServerStartup(state) {
|
|
46129
|
+
const providerStartupConfig2 = state.providerStartupConfig ?? NO_PROVIDER_STARTUP_CONFIG;
|
|
46130
|
+
return { args: [...state.appServerStartupArgs ?? ["app-server"], ...providerStartupConfig2.args], env: providerStartupConfig2.env };
|
|
46131
|
+
}
|
|
46086
46132
|
var DEFAULT_TIMINGS = {
|
|
46087
46133
|
closeGraceMs: 1e3,
|
|
46088
46134
|
drainMs: 50,
|
|
@@ -46092,7 +46138,7 @@ var DEFAULT_TIMINGS = {
|
|
|
46092
46138
|
};
|
|
46093
46139
|
var KEPT_EXITS = 16;
|
|
46094
46140
|
var CodexAppServerSupervisor = class {
|
|
46095
|
-
constructor(state, spawnConnection = (codexPath, appServerStartupArgs) => startCodexConnection(codexPath,
|
|
46141
|
+
constructor(state, spawnConnection = (codexPath, appServerStartupArgs, env) => startCodexConnection(codexPath, { ...process.env, ...env }, appServerStartupArgs, { disposeOnExit: false }), timings = {}, now = Date.now) {
|
|
46096
46142
|
this.state = state;
|
|
46097
46143
|
this.spawnConnection = spawnConnection;
|
|
46098
46144
|
this.now = now;
|
|
@@ -46157,7 +46203,8 @@ var CodexAppServerSupervisor = class {
|
|
|
46157
46203
|
if (this.isShuttingDown) throw new Error("The agent is shutting down");
|
|
46158
46204
|
if (this.child.exit === null) throw new Error("The Codex app-server is still running or draining");
|
|
46159
46205
|
this.state.stderr = "";
|
|
46160
|
-
const
|
|
46206
|
+
const { args, env } = appServerStartup(this.state);
|
|
46207
|
+
const connection = this.spawnConnection(this.state.codexPath, args, env);
|
|
46161
46208
|
this.state.connection = connection;
|
|
46162
46209
|
this.child = this.watch(connection);
|
|
46163
46210
|
logger.log("[APP-SERVER START]", { generation: this.child.generation, pid: connection.process.pid ?? null });
|
|
@@ -46193,6 +46240,7 @@ var CodexAppServerSupervisor = class {
|
|
|
46193
46240
|
generation,
|
|
46194
46241
|
connection,
|
|
46195
46242
|
startedAt: this.now(),
|
|
46243
|
+
providerStartupConfig: this.state.providerStartupConfig ?? NO_PROVIDER_STARTUP_CONFIG,
|
|
46196
46244
|
exit: null,
|
|
46197
46245
|
dead: false,
|
|
46198
46246
|
intentional: false,
|
|
@@ -52285,6 +52333,10 @@ You have been logged out. Please try again.`);
|
|
|
52285
52333
|
logger.log("Authenticate request failed");
|
|
52286
52334
|
throw RequestError.authRequired({ methodId: _params.methodId }, "Sign-in did not complete");
|
|
52287
52335
|
}
|
|
52336
|
+
if (this.providerStartupConfigChanged()) {
|
|
52337
|
+
await withRequestCancellation(this.enqueueProviderUpdate(() => {
|
|
52338
|
+
}), signal);
|
|
52339
|
+
}
|
|
52288
52340
|
await withRequestCancellation(this.refreshAuthState(this.getAuthProviderForAuthenticateRequest(_params)), signal);
|
|
52289
52341
|
logger.log("Authenticate request completed");
|
|
52290
52342
|
return {};
|
|
@@ -52374,7 +52426,7 @@ You have been logged out. Please try again.`);
|
|
|
52374
52426
|
async enqueueProviderUpdate(apply2) {
|
|
52375
52427
|
const previous = this.providerUpdate?.catch(() => void 0) ?? Promise.resolve();
|
|
52376
52428
|
const update = previous.then(async () => {
|
|
52377
|
-
if (this.sessions.size === 0) {
|
|
52429
|
+
if (this.sessions.size === 0 && !this.providerStartupConfigChanged()) {
|
|
52378
52430
|
return;
|
|
52379
52431
|
}
|
|
52380
52432
|
const activePrompts = [...this.activePrompts.values()].map((prompt) => prompt.completion);
|
|
@@ -52484,11 +52536,20 @@ You have been logged out. Please try again.`);
|
|
|
52484
52536
|
});
|
|
52485
52537
|
}
|
|
52486
52538
|
async restartCodexClient() {
|
|
52487
|
-
if (this.recovery === null) {
|
|
52539
|
+
if (this.recovery === null || this.codexProcessState === null) {
|
|
52488
52540
|
throw new Error("Codex process state is unavailable");
|
|
52489
52541
|
}
|
|
52542
|
+
this.codexProcessState.providerStartupConfig = this.codexAcpClient.providerStartupConfig();
|
|
52490
52543
|
return await this.recovery.beginReplacement();
|
|
52491
52544
|
}
|
|
52545
|
+
/**
|
|
52546
|
+
* Whether the app-server runs with other provider routing than the agent has now. Codex 0.166 refuses input for a
|
|
52547
|
+
* thread whose provider is not the one that its app-server started with, so the app-server has to restart.
|
|
52548
|
+
*/
|
|
52549
|
+
providerStartupConfigChanged() {
|
|
52550
|
+
const supervisor = this.codexProcessState?.supervisor;
|
|
52551
|
+
return supervisor !== void 0 && !isDeepStrictEqual2(supervisor.current.providerStartupConfig, this.codexAcpClient.providerStartupConfig());
|
|
52552
|
+
}
|
|
52492
52553
|
/**
|
|
52493
52554
|
* Waits for the provider update in flight. When its app-server died, the request goes on: the failure belongs to
|
|
52494
52555
|
* the `providers/set` request, and the request restarts the app-server itself. Any other failure fails it, as before.
|
|
@@ -55463,14 +55524,7 @@ function spawnCodexCli(codexPath, args) {
|
|
|
55463
55524
|
function prepareCodexHookConfig(config2) {
|
|
55464
55525
|
if (config2?.["hooks"] === void 0) return { sessionConfig: config2, appServerStartupArgs: ["app-server"] };
|
|
55465
55526
|
const { hooks, ...sessionConfig } = config2;
|
|
55466
|
-
return { sessionConfig, appServerStartupArgs: ["app-server", "
|
|
55467
|
-
}
|
|
55468
|
-
function toToml(value) {
|
|
55469
|
-
if (Array.isArray(value)) return `[${value.map(toToml).join(", ")}]`;
|
|
55470
|
-
if (value !== null && typeof value === "object") {
|
|
55471
|
-
return `{ ${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)} = ${toToml(item)}`).join(", ")} }`;
|
|
55472
|
-
}
|
|
55473
|
-
return JSON.stringify(value);
|
|
55527
|
+
return { sessionConfig, appServerStartupArgs: ["app-server", ...configOverride("hooks", hooks)] };
|
|
55474
55528
|
}
|
|
55475
55529
|
|
|
55476
55530
|
// src/AcpResponseDelivery.ts
|
|
@@ -55711,12 +55765,17 @@ function startAcpServer() {
|
|
|
55711
55765
|
authRequest: authRequestString ?? null,
|
|
55712
55766
|
defaultAuthRequest: defaultAuthRequest ?? null
|
|
55713
55767
|
});
|
|
55768
|
+
const startupState = {
|
|
55769
|
+
appServerStartupArgs: hookConfig.appServerStartupArgs,
|
|
55770
|
+
providerStartupConfig: providerStartupConfig(modelProvider ?? null, hookConfig.sessionConfig ?? {}, null)
|
|
55771
|
+
};
|
|
55772
|
+
const startup = appServerStartup(startupState);
|
|
55714
55773
|
const codexProcessState = {
|
|
55715
55774
|
// The supervisor disposes the connection itself, after the last output of the process was read.
|
|
55716
|
-
connection: startCodexConnection(codexPath,
|
|
55775
|
+
connection: startCodexConnection(codexPath, { ...process.env, ...startup.env }, startup.args, { disposeOnExit: false }),
|
|
55717
55776
|
codexPath,
|
|
55718
55777
|
config: hookConfig.sessionConfig,
|
|
55719
|
-
|
|
55778
|
+
...startupState,
|
|
55720
55779
|
modelProvider,
|
|
55721
55780
|
stderr: ""
|
|
55722
55781
|
};
|