@autohq/cli 0.1.315 → 0.1.317
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/agent-bridge.js +192 -59
- package/dist/index.js +193 -60
- package/package.json +1 -1
package/dist/agent-bridge.js
CHANGED
|
@@ -23431,7 +23431,7 @@ Object.assign(lookup, {
|
|
|
23431
23431
|
// package.json
|
|
23432
23432
|
var package_default = {
|
|
23433
23433
|
name: "@autohq/cli",
|
|
23434
|
-
version: "0.1.
|
|
23434
|
+
version: "0.1.317",
|
|
23435
23435
|
license: "SEE LICENSE IN README.md",
|
|
23436
23436
|
publishConfig: {
|
|
23437
23437
|
access: "public"
|
|
@@ -25285,6 +25285,12 @@ var AgentModelSelectionSchema = external_exports.object({
|
|
|
25285
25285
|
var ResolvedAgentModelSelectionSchema = AgentModelSelectionSchema.extend({
|
|
25286
25286
|
provider: ModelApiTokenProviderSchema
|
|
25287
25287
|
});
|
|
25288
|
+
var InvalidModelSelectionError = class extends Error {
|
|
25289
|
+
constructor(message) {
|
|
25290
|
+
super(message);
|
|
25291
|
+
this.name = "InvalidModelSelectionError";
|
|
25292
|
+
}
|
|
25293
|
+
};
|
|
25288
25294
|
var HARNESS_MODEL_RULES = {
|
|
25289
25295
|
"claude-code": {
|
|
25290
25296
|
defaultProvider: "anthropic",
|
|
@@ -25335,7 +25341,7 @@ function validateReasoningEffortForHarness(input) {
|
|
|
25335
25341
|
}
|
|
25336
25342
|
const rules = modelRulesForHarness(input.harness);
|
|
25337
25343
|
if (!rules.reasoningEfforts.includes(input.reasoningEffort)) {
|
|
25338
|
-
throw new
|
|
25344
|
+
throw new InvalidModelSelectionError(
|
|
25339
25345
|
`${input.harness} does not support reasoning effort "${input.reasoningEffort}"`
|
|
25340
25346
|
);
|
|
25341
25347
|
}
|
|
@@ -25372,7 +25378,9 @@ function validateAgentModelFieldsForHarness(spec, context) {
|
|
|
25372
25378
|
function validateModelProviderForHarness(harness, provider) {
|
|
25373
25379
|
const rules = modelRulesForHarness(harness);
|
|
25374
25380
|
if (!rules.providers.includes(provider)) {
|
|
25375
|
-
throw new
|
|
25381
|
+
throw new InvalidModelSelectionError(
|
|
25382
|
+
`${harness} does not support ${provider} models`
|
|
25383
|
+
);
|
|
25376
25384
|
}
|
|
25377
25385
|
}
|
|
25378
25386
|
function validateModelIdForProvider(input) {
|
|
@@ -25386,11 +25394,11 @@ function validateModelIdForProvider(input) {
|
|
|
25386
25394
|
return;
|
|
25387
25395
|
}
|
|
25388
25396
|
if (curated) {
|
|
25389
|
-
throw new
|
|
25397
|
+
throw new InvalidModelSelectionError(
|
|
25390
25398
|
`${input.provider} model "${input.id}" is not available for ${input.harness}`
|
|
25391
25399
|
);
|
|
25392
25400
|
}
|
|
25393
|
-
throw new
|
|
25401
|
+
throw new InvalidModelSelectionError(
|
|
25394
25402
|
`${input.provider} model ids are not open for ${input.harness}`
|
|
25395
25403
|
);
|
|
25396
25404
|
}
|
|
@@ -40833,7 +40841,7 @@ var UiMessagePartTracker = class {
|
|
|
40833
40841
|
}
|
|
40834
40842
|
}
|
|
40835
40843
|
appendDataChunk(chunk) {
|
|
40836
|
-
if (!chunk.type.startsWith("data-")
|
|
40844
|
+
if (!chunk.type.startsWith("data-")) {
|
|
40837
40845
|
return [];
|
|
40838
40846
|
}
|
|
40839
40847
|
const dataChunk = chunk;
|
|
@@ -40974,22 +40982,6 @@ var AgentBridgeOutputBuffer = class {
|
|
|
40974
40982
|
await this.drainPendingOutputs({ force: true });
|
|
40975
40983
|
}
|
|
40976
40984
|
async emitUiMessageChunk(context, projection) {
|
|
40977
|
-
if (projection.chunk.type === "data-auto-question") {
|
|
40978
|
-
await this.flushPendingDelta();
|
|
40979
|
-
await this.emitLiveUiMessageChunk(context, projection.chunk);
|
|
40980
|
-
await this.enqueueProjectionAndDrain(context, {
|
|
40981
|
-
type: "entry",
|
|
40982
|
-
entry: {
|
|
40983
|
-
role: "assistant",
|
|
40984
|
-
kind: "question",
|
|
40985
|
-
...projection.turnStatus ? { turnStatus: projection.turnStatus } : {},
|
|
40986
|
-
content: {
|
|
40987
|
-
parts: [questionPart(projection.chunk.data)]
|
|
40988
|
-
}
|
|
40989
|
-
}
|
|
40990
|
-
});
|
|
40991
|
-
return;
|
|
40992
|
-
}
|
|
40993
40985
|
await this.flushPendingDelta();
|
|
40994
40986
|
await this.emitLiveUiMessageChunk(context, projection.chunk);
|
|
40995
40987
|
await this.emitUiMessagePartSnapshots(context, projection.chunk, {
|
|
@@ -41334,14 +41326,6 @@ var UiMessageAssembler = class {
|
|
|
41334
41326
|
function isTerminalUiMessageChunk(chunk) {
|
|
41335
41327
|
return chunk.type === "finish" || chunk.type === "error" || chunk.type === "abort";
|
|
41336
41328
|
}
|
|
41337
|
-
function questionPart(data) {
|
|
41338
|
-
const parsed = data;
|
|
41339
|
-
return {
|
|
41340
|
-
type: "question",
|
|
41341
|
-
toolCallId: parsed.toolCallId ?? null,
|
|
41342
|
-
questions: parsed.questions
|
|
41343
|
-
};
|
|
41344
|
-
}
|
|
41345
41329
|
function legacyToolEntry(chunk) {
|
|
41346
41330
|
switch (chunk.type) {
|
|
41347
41331
|
case "tool-input-available":
|
|
@@ -41952,15 +41936,21 @@ function conversationProjectionToUiChunks(projection) {
|
|
|
41952
41936
|
turnStatus: "waiting_for_input"
|
|
41953
41937
|
},
|
|
41954
41938
|
{
|
|
41955
|
-
type: "
|
|
41956
|
-
|
|
41957
|
-
|
|
41958
|
-
|
|
41959
|
-
|
|
41960
|
-
|
|
41939
|
+
type: "entry",
|
|
41940
|
+
entry: {
|
|
41941
|
+
role: "assistant",
|
|
41942
|
+
kind: "question",
|
|
41943
|
+
turnStatus: "waiting_for_input",
|
|
41944
|
+
content: {
|
|
41945
|
+
parts: [
|
|
41946
|
+
{
|
|
41947
|
+
type: "question",
|
|
41948
|
+
toolCallId: part.toolCallId,
|
|
41949
|
+
questions: part.questions
|
|
41950
|
+
}
|
|
41951
|
+
]
|
|
41961
41952
|
}
|
|
41962
|
-
}
|
|
41963
|
-
turnStatus: "waiting_for_input"
|
|
41953
|
+
}
|
|
41964
41954
|
}
|
|
41965
41955
|
] : []
|
|
41966
41956
|
);
|
|
@@ -61696,7 +61686,8 @@ function claudeAgentOptions(config2, input = {}) {
|
|
|
61696
61686
|
includePartialMessages: true,
|
|
61697
61687
|
thinking: { type: "adaptive", display: "summarized" },
|
|
61698
61688
|
settings: { showThinkingSummaries: true },
|
|
61699
|
-
model: CLAUDE_CODE_DEFAULT_MODEL,
|
|
61689
|
+
model: config2.model?.id ?? CLAUDE_CODE_DEFAULT_MODEL,
|
|
61690
|
+
...config2.reasoningEffort ? { effort: config2.reasoningEffort } : {},
|
|
61700
61691
|
permissionMode: "bypassPermissions",
|
|
61701
61692
|
allowDangerouslySkipPermissions: true,
|
|
61702
61693
|
pathToClaudeCodeExecutable: claudeCodeExecutablePath(),
|
|
@@ -62438,7 +62429,10 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
62438
62429
|
);
|
|
62439
62430
|
return { outcome: "timeout" };
|
|
62440
62431
|
}
|
|
62441
|
-
await delay(
|
|
62432
|
+
await delay(
|
|
62433
|
+
CLAUDE_MCP_REGISTRATION_POLL_INTERVAL_MS,
|
|
62434
|
+
this.abortController.signal
|
|
62435
|
+
);
|
|
62442
62436
|
}
|
|
62443
62437
|
}
|
|
62444
62438
|
messageProbeContext() {
|
|
@@ -62593,10 +62587,19 @@ function mcpStatusDetailList(statuses) {
|
|
|
62593
62587
|
(server) => server.error ? `${server.name}:${server.status}(${server.error})` : `${server.name}:${server.status}`
|
|
62594
62588
|
).join(",");
|
|
62595
62589
|
}
|
|
62596
|
-
function delay(ms) {
|
|
62590
|
+
function delay(ms, signal) {
|
|
62591
|
+
if (signal?.aborted) {
|
|
62592
|
+
return Promise.resolve();
|
|
62593
|
+
}
|
|
62597
62594
|
return new Promise((resolve2) => {
|
|
62598
|
-
const
|
|
62595
|
+
const finish = () => {
|
|
62596
|
+
clearTimeout(timer);
|
|
62597
|
+
signal?.removeEventListener("abort", finish);
|
|
62598
|
+
resolve2();
|
|
62599
|
+
};
|
|
62600
|
+
const timer = setTimeout(finish, ms);
|
|
62599
62601
|
timer.unref?.();
|
|
62602
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
62600
62603
|
});
|
|
62601
62604
|
}
|
|
62602
62605
|
function claudeAgentUserMessage(message) {
|
|
@@ -62693,11 +62696,13 @@ function createClaudeCodeCommandHandler(input) {
|
|
|
62693
62696
|
var ClaudeCodeCommandHandler = class {
|
|
62694
62697
|
constructor(input) {
|
|
62695
62698
|
this.input = input;
|
|
62699
|
+
this.claudeConfig = input.claude;
|
|
62696
62700
|
this.outputBuffer = new AgentBridgeOutputBuffer(input);
|
|
62697
62701
|
}
|
|
62698
62702
|
input;
|
|
62699
62703
|
context = null;
|
|
62700
62704
|
agentSession = null;
|
|
62705
|
+
claudeConfig;
|
|
62701
62706
|
persistedAgentId = null;
|
|
62702
62707
|
injectedCommands = /* @__PURE__ */ new Set();
|
|
62703
62708
|
// Message commands whose injection has started but not settled. A fresh SDK
|
|
@@ -62897,6 +62902,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
62897
62902
|
);
|
|
62898
62903
|
const sendStartedAt = Date.now();
|
|
62899
62904
|
const mode = deliveryMode(delivery);
|
|
62905
|
+
this.applySelectionForMessage(delivery);
|
|
62900
62906
|
this.input.runtimeLogger?.info(
|
|
62901
62907
|
"agent_bridge_claude_command_send_message_started",
|
|
62902
62908
|
commandLogContext(delivery, {
|
|
@@ -63130,7 +63136,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
63130
63136
|
return this.agentSession;
|
|
63131
63137
|
}
|
|
63132
63138
|
const session = claudeAgentBridgeRuntime.start({
|
|
63133
|
-
claude: this.
|
|
63139
|
+
claude: this.claudeConfig,
|
|
63134
63140
|
resumeAgentId: this.storedResumeAgentId(),
|
|
63135
63141
|
canUseTool: this.canUseTool,
|
|
63136
63142
|
onMessage: (message, meta3) => this.handleAgentMessage(message, meta3),
|
|
@@ -63147,6 +63153,27 @@ var ClaudeCodeCommandHandler = class {
|
|
|
63147
63153
|
this.agentSession = session;
|
|
63148
63154
|
return session;
|
|
63149
63155
|
}
|
|
63156
|
+
applySelectionForMessage(delivery) {
|
|
63157
|
+
const selection = deliverySelection(delivery);
|
|
63158
|
+
if (!selection.model && selection.reasoningEffort === void 0) {
|
|
63159
|
+
return;
|
|
63160
|
+
}
|
|
63161
|
+
const next = {
|
|
63162
|
+
...this.claudeConfig,
|
|
63163
|
+
...selection.model ? { model: selection.model } : {},
|
|
63164
|
+
...selection.reasoningEffort ? { reasoningEffort: selection.reasoningEffort } : {}
|
|
63165
|
+
};
|
|
63166
|
+
if (sameClaudeConfigSelection(this.claudeConfig, next)) {
|
|
63167
|
+
return;
|
|
63168
|
+
}
|
|
63169
|
+
this.claudeConfig = next;
|
|
63170
|
+
this.agentSession?.close();
|
|
63171
|
+
this.agentSession = null;
|
|
63172
|
+
this.settlePendingQuestions("The runtime restarted to change model");
|
|
63173
|
+
this.input.writeOutput?.(
|
|
63174
|
+
`agent_bridge_claude_model_selection_changed provider=${next.model?.provider ?? ""} model=${next.model?.id ?? ""} reasoning_effort=${next.reasoningEffort ?? ""}`
|
|
63175
|
+
);
|
|
63176
|
+
}
|
|
63150
63177
|
};
|
|
63151
63178
|
function withConsumedCommandIds(projection, meta3) {
|
|
63152
63179
|
const consumedCommandIds = meta3?.consumedCommandIds;
|
|
@@ -63171,6 +63198,23 @@ function deliveryMessage(delivery) {
|
|
|
63171
63198
|
}
|
|
63172
63199
|
return null;
|
|
63173
63200
|
}
|
|
63201
|
+
function deliverySelection(delivery) {
|
|
63202
|
+
const payload = delivery.payload;
|
|
63203
|
+
if (!payload || typeof payload !== "object") {
|
|
63204
|
+
return {};
|
|
63205
|
+
}
|
|
63206
|
+
const model = "model" in payload ? AgentBridgeModelSelectionSchema.safeParse(payload.model) : null;
|
|
63207
|
+
const reasoningEffort = "reasoningEffort" in payload ? AgentBridgeClaudeReasoningEffortSchema.safeParse(
|
|
63208
|
+
payload.reasoningEffort
|
|
63209
|
+
) : null;
|
|
63210
|
+
return {
|
|
63211
|
+
...model?.success ? { model: model.data } : {},
|
|
63212
|
+
...reasoningEffort?.success ? { reasoningEffort: reasoningEffort.data } : {}
|
|
63213
|
+
};
|
|
63214
|
+
}
|
|
63215
|
+
function sameClaudeConfigSelection(current, next) {
|
|
63216
|
+
return current.model?.provider === next.model?.provider && current.model?.id === next.model?.id && current.reasoningEffort === next.reasoningEffort;
|
|
63217
|
+
}
|
|
63174
63218
|
function deliveryMode(delivery) {
|
|
63175
63219
|
const payload = delivery.payload;
|
|
63176
63220
|
if (payload && typeof payload === "object" && "deliveryMode" in payload) {
|
|
@@ -63223,8 +63267,10 @@ var CodexProjector = class {
|
|
|
63223
63267
|
return [];
|
|
63224
63268
|
}
|
|
63225
63269
|
}
|
|
63226
|
-
// An approval parks the turn on operator input
|
|
63227
|
-
//
|
|
63270
|
+
// An approval parks the turn on operator input: the native approval chunk
|
|
63271
|
+
// transitions the tool part to `approval-requested` for AI SDK clients, and
|
|
63272
|
+
// the durable question entry keeps owning answer routing for the CLI
|
|
63273
|
+
// transcript. Both mark the delivered turn as waiting for input.
|
|
63228
63274
|
projectApproval(request) {
|
|
63229
63275
|
return [
|
|
63230
63276
|
{
|
|
@@ -63237,15 +63283,21 @@ var CodexProjector = class {
|
|
|
63237
63283
|
turnStatus: "waiting_for_input"
|
|
63238
63284
|
},
|
|
63239
63285
|
{
|
|
63240
|
-
type: "
|
|
63241
|
-
|
|
63242
|
-
|
|
63243
|
-
|
|
63244
|
-
|
|
63245
|
-
|
|
63286
|
+
type: "entry",
|
|
63287
|
+
entry: {
|
|
63288
|
+
role: "assistant",
|
|
63289
|
+
kind: "question",
|
|
63290
|
+
turnStatus: "waiting_for_input",
|
|
63291
|
+
content: {
|
|
63292
|
+
parts: [
|
|
63293
|
+
{
|
|
63294
|
+
type: "question",
|
|
63295
|
+
toolCallId: request.itemId,
|
|
63296
|
+
questions: [approvalQuestion(request)]
|
|
63297
|
+
}
|
|
63298
|
+
]
|
|
63246
63299
|
}
|
|
63247
|
-
}
|
|
63248
|
-
turnStatus: "waiting_for_input"
|
|
63300
|
+
}
|
|
63249
63301
|
}
|
|
63250
63302
|
];
|
|
63251
63303
|
}
|
|
@@ -63546,9 +63598,12 @@ import { join } from "path";
|
|
|
63546
63598
|
var CODEX_EXECUTABLE_PATH = "codex";
|
|
63547
63599
|
var CODEX_DEFAULT_MODEL = "gpt-5.3-codex";
|
|
63548
63600
|
var CODEX_HTTP_PROVIDER_ID = "openai-responses-http";
|
|
63601
|
+
var CODEX_OPENROUTER_PROVIDER_ID = "openrouter-responses-http";
|
|
63549
63602
|
var CODEX_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
63603
|
+
var CODEX_OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
63550
63604
|
var CODEX_API_KEY_ENV = "OPENAI_API_KEY";
|
|
63551
63605
|
var MODEL_GATEWAY_OPENAI_BASE_URL_ENV = "AUTO_MODEL_GATEWAY_OPENAI_BASE_URL";
|
|
63606
|
+
var MODEL_GATEWAY_OPENROUTER_BASE_URL_ENV = "AUTO_MODEL_GATEWAY_OPENROUTER_BASE_URL";
|
|
63552
63607
|
var CODEX_RUNTIME_PROCESS_ENV_KEYS = ["PATH", "HOME"];
|
|
63553
63608
|
function codexLaunchOptions(config2) {
|
|
63554
63609
|
return {
|
|
@@ -63571,8 +63626,14 @@ function codexThreadParams(config2) {
|
|
|
63571
63626
|
}
|
|
63572
63627
|
function renderCodexConfigToml(config2) {
|
|
63573
63628
|
const lines = [];
|
|
63574
|
-
|
|
63575
|
-
lines.push(`
|
|
63629
|
+
const selectedProvider = codexProviderIdForModel(config2);
|
|
63630
|
+
lines.push(`model = ${tomlString(config2.model?.id ?? CODEX_DEFAULT_MODEL)}`);
|
|
63631
|
+
lines.push(`model_provider = ${tomlString(selectedProvider)}`);
|
|
63632
|
+
if (config2.reasoningEffort) {
|
|
63633
|
+
lines.push(
|
|
63634
|
+
`model_reasoning_effort = ${tomlString(config2.reasoningEffort)}`
|
|
63635
|
+
);
|
|
63636
|
+
}
|
|
63576
63637
|
lines.push("");
|
|
63577
63638
|
lines.push(`[model_providers.${CODEX_HTTP_PROVIDER_ID}]`);
|
|
63578
63639
|
lines.push('name = "OpenAI"');
|
|
@@ -63582,6 +63643,15 @@ function renderCodexConfigToml(config2) {
|
|
|
63582
63643
|
lines.push('wire_api = "responses"');
|
|
63583
63644
|
lines.push(`env_key = ${tomlString(CODEX_API_KEY_ENV)}`);
|
|
63584
63645
|
lines.push("supports_websockets = false");
|
|
63646
|
+
lines.push("");
|
|
63647
|
+
lines.push(`[model_providers.${CODEX_OPENROUTER_PROVIDER_ID}]`);
|
|
63648
|
+
lines.push('name = "OpenRouter"');
|
|
63649
|
+
lines.push(
|
|
63650
|
+
`base_url = ${tomlString(openRouterBaseUrlForCodexConfig(config2.env))}`
|
|
63651
|
+
);
|
|
63652
|
+
lines.push('wire_api = "responses"');
|
|
63653
|
+
lines.push(`env_key = ${tomlString(CODEX_API_KEY_ENV)}`);
|
|
63654
|
+
lines.push("supports_websockets = false");
|
|
63585
63655
|
for (const [name23, server] of Object.entries(config2.mcpServers ?? {})) {
|
|
63586
63656
|
lines.push("");
|
|
63587
63657
|
lines.push(`[mcp_servers.${tomlKey(name23)}]`);
|
|
@@ -63609,6 +63679,12 @@ function codexProcessEnv(env) {
|
|
|
63609
63679
|
function openaiBaseUrlForCodexConfig(env) {
|
|
63610
63680
|
return env[MODEL_GATEWAY_OPENAI_BASE_URL_ENV] ?? CODEX_OPENAI_BASE_URL;
|
|
63611
63681
|
}
|
|
63682
|
+
function openRouterBaseUrlForCodexConfig(env) {
|
|
63683
|
+
return env[MODEL_GATEWAY_OPENROUTER_BASE_URL_ENV] ?? CODEX_OPENROUTER_BASE_URL;
|
|
63684
|
+
}
|
|
63685
|
+
function codexProviderIdForModel(config2) {
|
|
63686
|
+
return config2.model?.provider === "openrouter" ? CODEX_OPENROUTER_PROVIDER_ID : CODEX_HTTP_PROVIDER_ID;
|
|
63687
|
+
}
|
|
63612
63688
|
function codexHomeDir() {
|
|
63613
63689
|
const home = process.env.HOME;
|
|
63614
63690
|
if (!home) {
|
|
@@ -63663,6 +63739,7 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
63663
63739
|
// set means an interrupt/steer would race an unsettled item (FRA-3049 analog).
|
|
63664
63740
|
pendingToolItemIds = /* @__PURE__ */ new Set();
|
|
63665
63741
|
settlementWaiters = /* @__PURE__ */ new Set();
|
|
63742
|
+
callbackQueue = Promise.resolve();
|
|
63666
63743
|
// Messages held in "deferred" mode while a turn is in flight; flushed as a
|
|
63667
63744
|
// fresh turn once the active turn completes.
|
|
63668
63745
|
deferredMessages = [];
|
|
@@ -63934,10 +64011,12 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
63934
64011
|
return;
|
|
63935
64012
|
case "notification":
|
|
63936
64013
|
this.trackNotification(message.notification);
|
|
63937
|
-
|
|
64014
|
+
this.enqueueCallback(
|
|
64015
|
+
() => this.input.onNotification(message.notification)
|
|
64016
|
+
);
|
|
63938
64017
|
return;
|
|
63939
64018
|
case "serverRequest":
|
|
63940
|
-
|
|
64019
|
+
this.enqueueCallback(() => this.input.onServerRequest(message.request));
|
|
63941
64020
|
return;
|
|
63942
64021
|
case "elicitation":
|
|
63943
64022
|
this.writeFrame({
|
|
@@ -63963,6 +64042,18 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
63963
64042
|
return;
|
|
63964
64043
|
}
|
|
63965
64044
|
}
|
|
64045
|
+
enqueueCallback(callback) {
|
|
64046
|
+
this.callbackQueue = this.callbackQueue.then(async () => {
|
|
64047
|
+
try {
|
|
64048
|
+
await callback();
|
|
64049
|
+
} catch (error51) {
|
|
64050
|
+
try {
|
|
64051
|
+
await this.input.onError(error51);
|
|
64052
|
+
} catch {
|
|
64053
|
+
}
|
|
64054
|
+
}
|
|
64055
|
+
});
|
|
64056
|
+
}
|
|
63966
64057
|
// Track turn/item lifecycle so steer/interrupt target the live turn and gate on
|
|
63967
64058
|
// tool-item settlement.
|
|
63968
64059
|
trackNotification(notification) {
|
|
@@ -64100,17 +64191,20 @@ function createCodexCommandHandler(input) {
|
|
|
64100
64191
|
var CodexCommandHandler = class {
|
|
64101
64192
|
constructor(input) {
|
|
64102
64193
|
this.input = input;
|
|
64194
|
+
this.codexConfig = input.codex;
|
|
64103
64195
|
this.outputBuffer = new AgentBridgeOutputBuffer(input);
|
|
64104
64196
|
}
|
|
64105
64197
|
input;
|
|
64106
64198
|
context = null;
|
|
64107
64199
|
session = null;
|
|
64200
|
+
codexConfig;
|
|
64108
64201
|
injectedCommands = /* @__PURE__ */ new Set();
|
|
64109
64202
|
// itemId -> JSON-RPC request id of the parked approval request, so an `answer`
|
|
64110
64203
|
// command keyed by toolCallId (= itemId) can resolve the right server request.
|
|
64111
64204
|
pendingApprovals = /* @__PURE__ */ new Map();
|
|
64112
64205
|
outputBuffer;
|
|
64113
64206
|
projector = new CodexProjector();
|
|
64207
|
+
skipResumeForNextSession = false;
|
|
64114
64208
|
// ---------------------------------------------------------------------------
|
|
64115
64209
|
// Lifecycle (public API)
|
|
64116
64210
|
// ---------------------------------------------------------------------------
|
|
@@ -64165,6 +64259,7 @@ var CodexCommandHandler = class {
|
|
|
64165
64259
|
}
|
|
64166
64260
|
this.injectedCommands.add(delivery.commandId);
|
|
64167
64261
|
try {
|
|
64262
|
+
this.applySelectionForMessage(delivery);
|
|
64168
64263
|
await this.emitUserMessageEntry(
|
|
64169
64264
|
activeContext,
|
|
64170
64265
|
delivery.commandId,
|
|
@@ -64298,9 +64393,10 @@ var CodexCommandHandler = class {
|
|
|
64298
64393
|
if (this.session) {
|
|
64299
64394
|
return this.session;
|
|
64300
64395
|
}
|
|
64301
|
-
const resumeThreadId = this.storedResumeThreadId();
|
|
64396
|
+
const resumeThreadId = this.skipResumeForNextSession ? void 0 : this.storedResumeThreadId();
|
|
64397
|
+
this.skipResumeForNextSession = false;
|
|
64302
64398
|
const session = codexAgentBridgeRuntime.start({
|
|
64303
|
-
codex: this.
|
|
64399
|
+
codex: this.codexConfig,
|
|
64304
64400
|
...resumeThreadId ? { resumeThreadId } : {},
|
|
64305
64401
|
onNotification: (notification) => this.handleNotification(notification),
|
|
64306
64402
|
onServerRequest: (request) => this.handleServerRequest(request),
|
|
@@ -64317,6 +64413,28 @@ var CodexCommandHandler = class {
|
|
|
64317
64413
|
this.session = session;
|
|
64318
64414
|
return session;
|
|
64319
64415
|
}
|
|
64416
|
+
applySelectionForMessage(delivery) {
|
|
64417
|
+
const selection = deliverySelection2(delivery);
|
|
64418
|
+
if (!selection.model && selection.reasoningEffort === void 0) {
|
|
64419
|
+
return;
|
|
64420
|
+
}
|
|
64421
|
+
const next = {
|
|
64422
|
+
...this.codexConfig,
|
|
64423
|
+
...selection.model ? { model: selection.model } : {},
|
|
64424
|
+
...selection.reasoningEffort ? { reasoningEffort: selection.reasoningEffort } : {}
|
|
64425
|
+
};
|
|
64426
|
+
if (sameCodexConfigSelection(this.codexConfig, next)) {
|
|
64427
|
+
return;
|
|
64428
|
+
}
|
|
64429
|
+
this.codexConfig = next;
|
|
64430
|
+
this.skipResumeForNextSession = true;
|
|
64431
|
+
this.session?.close();
|
|
64432
|
+
this.session = null;
|
|
64433
|
+
this.pendingApprovals.clear();
|
|
64434
|
+
this.input.writeOutput?.(
|
|
64435
|
+
`agent_bridge_codex_model_selection_changed provider=${next.model?.provider ?? ""} model=${next.model?.id ?? ""} reasoning_effort=${next.reasoningEffort ?? ""}`
|
|
64436
|
+
);
|
|
64437
|
+
}
|
|
64320
64438
|
storedResumeThreadId() {
|
|
64321
64439
|
const store = this.input.sessionResume;
|
|
64322
64440
|
const activeContext = this.context;
|
|
@@ -64363,6 +64481,21 @@ function deliveryMessage2(delivery) {
|
|
|
64363
64481
|
}
|
|
64364
64482
|
return null;
|
|
64365
64483
|
}
|
|
64484
|
+
function deliverySelection2(delivery) {
|
|
64485
|
+
const payload = delivery.payload;
|
|
64486
|
+
if (!payload || typeof payload !== "object") {
|
|
64487
|
+
return {};
|
|
64488
|
+
}
|
|
64489
|
+
const model = "model" in payload ? AgentBridgeModelSelectionSchema.safeParse(payload.model) : null;
|
|
64490
|
+
const reasoningEffort = "reasoningEffort" in payload ? AgentBridgeCodexReasoningEffortSchema.safeParse(payload.reasoningEffort) : null;
|
|
64491
|
+
return {
|
|
64492
|
+
...model?.success ? { model: model.data } : {},
|
|
64493
|
+
...reasoningEffort?.success ? { reasoningEffort: reasoningEffort.data } : {}
|
|
64494
|
+
};
|
|
64495
|
+
}
|
|
64496
|
+
function sameCodexConfigSelection(current, next) {
|
|
64497
|
+
return current.model?.provider === next.model?.provider && current.model?.id === next.model?.id && current.reasoningEffort === next.reasoningEffort;
|
|
64498
|
+
}
|
|
64366
64499
|
function deliveryMode2(delivery) {
|
|
64367
64500
|
const payload = delivery.payload;
|
|
64368
64501
|
if (payload && typeof payload === "object" && "deliveryMode" in payload) {
|
package/dist/index.js
CHANGED
|
@@ -16694,7 +16694,7 @@ function validateReasoningEffortForHarness(input) {
|
|
|
16694
16694
|
}
|
|
16695
16695
|
const rules = modelRulesForHarness(input.harness);
|
|
16696
16696
|
if (!rules.reasoningEfforts.includes(input.reasoningEffort)) {
|
|
16697
|
-
throw new
|
|
16697
|
+
throw new InvalidModelSelectionError(
|
|
16698
16698
|
`${input.harness} does not support reasoning effort "${input.reasoningEffort}"`
|
|
16699
16699
|
);
|
|
16700
16700
|
}
|
|
@@ -16731,7 +16731,9 @@ function validateAgentModelFieldsForHarness(spec, context) {
|
|
|
16731
16731
|
function validateModelProviderForHarness(harness, provider) {
|
|
16732
16732
|
const rules = modelRulesForHarness(harness);
|
|
16733
16733
|
if (!rules.providers.includes(provider)) {
|
|
16734
|
-
throw new
|
|
16734
|
+
throw new InvalidModelSelectionError(
|
|
16735
|
+
`${harness} does not support ${provider} models`
|
|
16736
|
+
);
|
|
16735
16737
|
}
|
|
16736
16738
|
}
|
|
16737
16739
|
function validateModelIdForProvider(input) {
|
|
@@ -16745,15 +16747,15 @@ function validateModelIdForProvider(input) {
|
|
|
16745
16747
|
return;
|
|
16746
16748
|
}
|
|
16747
16749
|
if (curated) {
|
|
16748
|
-
throw new
|
|
16750
|
+
throw new InvalidModelSelectionError(
|
|
16749
16751
|
`${input.provider} model "${input.id}" is not available for ${input.harness}`
|
|
16750
16752
|
);
|
|
16751
16753
|
}
|
|
16752
|
-
throw new
|
|
16754
|
+
throw new InvalidModelSelectionError(
|
|
16753
16755
|
`${input.provider} model ids are not open for ${input.harness}`
|
|
16754
16756
|
);
|
|
16755
16757
|
}
|
|
16756
|
-
var MODEL_API_TOKEN_PROVIDERS, ModelApiTokenProviderSchema, CLAUDE_CODE_REASONING_EFFORTS, CODEX_REASONING_EFFORTS, ClaudeCodeReasoningEffortSchema, CodexReasoningEffortSchema, AgentReasoningEffortSchema, OPENROUTER_MODEL_SLUG_PATTERN, AgentModelSelectionSchema, ResolvedAgentModelSelectionSchema, HARNESS_MODEL_RULES;
|
|
16758
|
+
var MODEL_API_TOKEN_PROVIDERS, ModelApiTokenProviderSchema, CLAUDE_CODE_REASONING_EFFORTS, CODEX_REASONING_EFFORTS, ClaudeCodeReasoningEffortSchema, CodexReasoningEffortSchema, AgentReasoningEffortSchema, OPENROUTER_MODEL_SLUG_PATTERN, AgentModelSelectionSchema, ResolvedAgentModelSelectionSchema, InvalidModelSelectionError, HARNESS_MODEL_RULES;
|
|
16757
16759
|
var init_model_selection = __esm({
|
|
16758
16760
|
"../../packages/schemas/src/model-selection.ts"() {
|
|
16759
16761
|
"use strict";
|
|
@@ -16797,6 +16799,12 @@ var init_model_selection = __esm({
|
|
|
16797
16799
|
ResolvedAgentModelSelectionSchema = AgentModelSelectionSchema.extend({
|
|
16798
16800
|
provider: ModelApiTokenProviderSchema
|
|
16799
16801
|
});
|
|
16802
|
+
InvalidModelSelectionError = class extends Error {
|
|
16803
|
+
constructor(message) {
|
|
16804
|
+
super(message);
|
|
16805
|
+
this.name = "InvalidModelSelectionError";
|
|
16806
|
+
}
|
|
16807
|
+
};
|
|
16800
16808
|
HARNESS_MODEL_RULES = {
|
|
16801
16809
|
"claude-code": {
|
|
16802
16810
|
defaultProvider: "anthropic",
|
|
@@ -27058,7 +27066,7 @@ var init_package = __esm({
|
|
|
27058
27066
|
"package.json"() {
|
|
27059
27067
|
package_default = {
|
|
27060
27068
|
name: "@autohq/cli",
|
|
27061
|
-
version: "0.1.
|
|
27069
|
+
version: "0.1.317",
|
|
27062
27070
|
license: "SEE LICENSE IN README.md",
|
|
27063
27071
|
publishConfig: {
|
|
27064
27072
|
access: "public"
|
|
@@ -37945,7 +37953,7 @@ var UiMessagePartTracker = class {
|
|
|
37945
37953
|
}
|
|
37946
37954
|
}
|
|
37947
37955
|
appendDataChunk(chunk) {
|
|
37948
|
-
if (!chunk.type.startsWith("data-")
|
|
37956
|
+
if (!chunk.type.startsWith("data-")) {
|
|
37949
37957
|
return [];
|
|
37950
37958
|
}
|
|
37951
37959
|
const dataChunk = chunk;
|
|
@@ -38086,22 +38094,6 @@ var AgentBridgeOutputBuffer = class {
|
|
|
38086
38094
|
await this.drainPendingOutputs({ force: true });
|
|
38087
38095
|
}
|
|
38088
38096
|
async emitUiMessageChunk(context, projection) {
|
|
38089
|
-
if (projection.chunk.type === "data-auto-question") {
|
|
38090
|
-
await this.flushPendingDelta();
|
|
38091
|
-
await this.emitLiveUiMessageChunk(context, projection.chunk);
|
|
38092
|
-
await this.enqueueProjectionAndDrain(context, {
|
|
38093
|
-
type: "entry",
|
|
38094
|
-
entry: {
|
|
38095
|
-
role: "assistant",
|
|
38096
|
-
kind: "question",
|
|
38097
|
-
...projection.turnStatus ? { turnStatus: projection.turnStatus } : {},
|
|
38098
|
-
content: {
|
|
38099
|
-
parts: [questionPart(projection.chunk.data)]
|
|
38100
|
-
}
|
|
38101
|
-
}
|
|
38102
|
-
});
|
|
38103
|
-
return;
|
|
38104
|
-
}
|
|
38105
38097
|
await this.flushPendingDelta();
|
|
38106
38098
|
await this.emitLiveUiMessageChunk(context, projection.chunk);
|
|
38107
38099
|
await this.emitUiMessagePartSnapshots(context, projection.chunk, {
|
|
@@ -38446,14 +38438,6 @@ var UiMessageAssembler = class {
|
|
|
38446
38438
|
function isTerminalUiMessageChunk(chunk) {
|
|
38447
38439
|
return chunk.type === "finish" || chunk.type === "error" || chunk.type === "abort";
|
|
38448
38440
|
}
|
|
38449
|
-
function questionPart(data) {
|
|
38450
|
-
const parsed = data;
|
|
38451
|
-
return {
|
|
38452
|
-
type: "question",
|
|
38453
|
-
toolCallId: parsed.toolCallId ?? null,
|
|
38454
|
-
questions: parsed.questions
|
|
38455
|
-
};
|
|
38456
|
-
}
|
|
38457
38441
|
function legacyToolEntry(chunk) {
|
|
38458
38442
|
switch (chunk.type) {
|
|
38459
38443
|
case "tool-input-available":
|
|
@@ -39065,15 +39049,21 @@ function conversationProjectionToUiChunks(projection) {
|
|
|
39065
39049
|
turnStatus: "waiting_for_input"
|
|
39066
39050
|
},
|
|
39067
39051
|
{
|
|
39068
|
-
type: "
|
|
39069
|
-
|
|
39070
|
-
|
|
39071
|
-
|
|
39072
|
-
|
|
39073
|
-
|
|
39052
|
+
type: "entry",
|
|
39053
|
+
entry: {
|
|
39054
|
+
role: "assistant",
|
|
39055
|
+
kind: "question",
|
|
39056
|
+
turnStatus: "waiting_for_input",
|
|
39057
|
+
content: {
|
|
39058
|
+
parts: [
|
|
39059
|
+
{
|
|
39060
|
+
type: "question",
|
|
39061
|
+
toolCallId: part.toolCallId,
|
|
39062
|
+
questions: part.questions
|
|
39063
|
+
}
|
|
39064
|
+
]
|
|
39074
39065
|
}
|
|
39075
|
-
}
|
|
39076
|
-
turnStatus: "waiting_for_input"
|
|
39066
|
+
}
|
|
39077
39067
|
}
|
|
39078
39068
|
] : []
|
|
39079
39069
|
);
|
|
@@ -39237,7 +39227,8 @@ function claudeAgentOptions(config2, input = {}) {
|
|
|
39237
39227
|
includePartialMessages: true,
|
|
39238
39228
|
thinking: { type: "adaptive", display: "summarized" },
|
|
39239
39229
|
settings: { showThinkingSummaries: true },
|
|
39240
|
-
model: CLAUDE_CODE_DEFAULT_MODEL,
|
|
39230
|
+
model: config2.model?.id ?? CLAUDE_CODE_DEFAULT_MODEL,
|
|
39231
|
+
...config2.reasoningEffort ? { effort: config2.reasoningEffort } : {},
|
|
39241
39232
|
permissionMode: "bypassPermissions",
|
|
39242
39233
|
allowDangerouslySkipPermissions: true,
|
|
39243
39234
|
pathToClaudeCodeExecutable: claudeCodeExecutablePath(),
|
|
@@ -39979,7 +39970,10 @@ var ClaudeAgentBridgeSessionImpl = class {
|
|
|
39979
39970
|
);
|
|
39980
39971
|
return { outcome: "timeout" };
|
|
39981
39972
|
}
|
|
39982
|
-
await delay(
|
|
39973
|
+
await delay(
|
|
39974
|
+
CLAUDE_MCP_REGISTRATION_POLL_INTERVAL_MS,
|
|
39975
|
+
this.abortController.signal
|
|
39976
|
+
);
|
|
39983
39977
|
}
|
|
39984
39978
|
}
|
|
39985
39979
|
messageProbeContext() {
|
|
@@ -40134,10 +40128,19 @@ function mcpStatusDetailList(statuses) {
|
|
|
40134
40128
|
(server) => server.error ? `${server.name}:${server.status}(${server.error})` : `${server.name}:${server.status}`
|
|
40135
40129
|
).join(",");
|
|
40136
40130
|
}
|
|
40137
|
-
function delay(ms) {
|
|
40131
|
+
function delay(ms, signal) {
|
|
40132
|
+
if (signal?.aborted) {
|
|
40133
|
+
return Promise.resolve();
|
|
40134
|
+
}
|
|
40138
40135
|
return new Promise((resolve4) => {
|
|
40139
|
-
const
|
|
40136
|
+
const finish = () => {
|
|
40137
|
+
clearTimeout(timer);
|
|
40138
|
+
signal?.removeEventListener("abort", finish);
|
|
40139
|
+
resolve4();
|
|
40140
|
+
};
|
|
40141
|
+
const timer = setTimeout(finish, ms);
|
|
40140
40142
|
timer.unref?.();
|
|
40143
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
40141
40144
|
});
|
|
40142
40145
|
}
|
|
40143
40146
|
function claudeAgentUserMessage(message) {
|
|
@@ -40234,11 +40237,13 @@ function createClaudeCodeCommandHandler(input) {
|
|
|
40234
40237
|
var ClaudeCodeCommandHandler = class {
|
|
40235
40238
|
constructor(input) {
|
|
40236
40239
|
this.input = input;
|
|
40240
|
+
this.claudeConfig = input.claude;
|
|
40237
40241
|
this.outputBuffer = new AgentBridgeOutputBuffer(input);
|
|
40238
40242
|
}
|
|
40239
40243
|
input;
|
|
40240
40244
|
context = null;
|
|
40241
40245
|
agentSession = null;
|
|
40246
|
+
claudeConfig;
|
|
40242
40247
|
persistedAgentId = null;
|
|
40243
40248
|
injectedCommands = /* @__PURE__ */ new Set();
|
|
40244
40249
|
// Message commands whose injection has started but not settled. A fresh SDK
|
|
@@ -40438,6 +40443,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
40438
40443
|
);
|
|
40439
40444
|
const sendStartedAt = Date.now();
|
|
40440
40445
|
const mode = deliveryMode(delivery);
|
|
40446
|
+
this.applySelectionForMessage(delivery);
|
|
40441
40447
|
this.input.runtimeLogger?.info(
|
|
40442
40448
|
"agent_bridge_claude_command_send_message_started",
|
|
40443
40449
|
commandLogContext(delivery, {
|
|
@@ -40671,7 +40677,7 @@ var ClaudeCodeCommandHandler = class {
|
|
|
40671
40677
|
return this.agentSession;
|
|
40672
40678
|
}
|
|
40673
40679
|
const session = claudeAgentBridgeRuntime.start({
|
|
40674
|
-
claude: this.
|
|
40680
|
+
claude: this.claudeConfig,
|
|
40675
40681
|
resumeAgentId: this.storedResumeAgentId(),
|
|
40676
40682
|
canUseTool: this.canUseTool,
|
|
40677
40683
|
onMessage: (message, meta3) => this.handleAgentMessage(message, meta3),
|
|
@@ -40688,6 +40694,27 @@ var ClaudeCodeCommandHandler = class {
|
|
|
40688
40694
|
this.agentSession = session;
|
|
40689
40695
|
return session;
|
|
40690
40696
|
}
|
|
40697
|
+
applySelectionForMessage(delivery) {
|
|
40698
|
+
const selection = deliverySelection(delivery);
|
|
40699
|
+
if (!selection.model && selection.reasoningEffort === void 0) {
|
|
40700
|
+
return;
|
|
40701
|
+
}
|
|
40702
|
+
const next = {
|
|
40703
|
+
...this.claudeConfig,
|
|
40704
|
+
...selection.model ? { model: selection.model } : {},
|
|
40705
|
+
...selection.reasoningEffort ? { reasoningEffort: selection.reasoningEffort } : {}
|
|
40706
|
+
};
|
|
40707
|
+
if (sameClaudeConfigSelection(this.claudeConfig, next)) {
|
|
40708
|
+
return;
|
|
40709
|
+
}
|
|
40710
|
+
this.claudeConfig = next;
|
|
40711
|
+
this.agentSession?.close();
|
|
40712
|
+
this.agentSession = null;
|
|
40713
|
+
this.settlePendingQuestions("The runtime restarted to change model");
|
|
40714
|
+
this.input.writeOutput?.(
|
|
40715
|
+
`agent_bridge_claude_model_selection_changed provider=${next.model?.provider ?? ""} model=${next.model?.id ?? ""} reasoning_effort=${next.reasoningEffort ?? ""}`
|
|
40716
|
+
);
|
|
40717
|
+
}
|
|
40691
40718
|
};
|
|
40692
40719
|
function withConsumedCommandIds(projection, meta3) {
|
|
40693
40720
|
const consumedCommandIds = meta3?.consumedCommandIds;
|
|
@@ -40712,6 +40739,23 @@ function deliveryMessage(delivery) {
|
|
|
40712
40739
|
}
|
|
40713
40740
|
return null;
|
|
40714
40741
|
}
|
|
40742
|
+
function deliverySelection(delivery) {
|
|
40743
|
+
const payload = delivery.payload;
|
|
40744
|
+
if (!payload || typeof payload !== "object") {
|
|
40745
|
+
return {};
|
|
40746
|
+
}
|
|
40747
|
+
const model = "model" in payload ? AgentBridgeModelSelectionSchema.safeParse(payload.model) : null;
|
|
40748
|
+
const reasoningEffort = "reasoningEffort" in payload ? AgentBridgeClaudeReasoningEffortSchema.safeParse(
|
|
40749
|
+
payload.reasoningEffort
|
|
40750
|
+
) : null;
|
|
40751
|
+
return {
|
|
40752
|
+
...model?.success ? { model: model.data } : {},
|
|
40753
|
+
...reasoningEffort?.success ? { reasoningEffort: reasoningEffort.data } : {}
|
|
40754
|
+
};
|
|
40755
|
+
}
|
|
40756
|
+
function sameClaudeConfigSelection(current, next) {
|
|
40757
|
+
return current.model?.provider === next.model?.provider && current.model?.id === next.model?.id && current.reasoningEffort === next.reasoningEffort;
|
|
40758
|
+
}
|
|
40715
40759
|
function deliveryMode(delivery) {
|
|
40716
40760
|
const payload = delivery.payload;
|
|
40717
40761
|
if (payload && typeof payload === "object" && "deliveryMode" in payload) {
|
|
@@ -40768,8 +40812,10 @@ var CodexProjector = class {
|
|
|
40768
40812
|
return [];
|
|
40769
40813
|
}
|
|
40770
40814
|
}
|
|
40771
|
-
// An approval parks the turn on operator input
|
|
40772
|
-
//
|
|
40815
|
+
// An approval parks the turn on operator input: the native approval chunk
|
|
40816
|
+
// transitions the tool part to `approval-requested` for AI SDK clients, and
|
|
40817
|
+
// the durable question entry keeps owning answer routing for the CLI
|
|
40818
|
+
// transcript. Both mark the delivered turn as waiting for input.
|
|
40773
40819
|
projectApproval(request) {
|
|
40774
40820
|
return [
|
|
40775
40821
|
{
|
|
@@ -40782,15 +40828,21 @@ var CodexProjector = class {
|
|
|
40782
40828
|
turnStatus: "waiting_for_input"
|
|
40783
40829
|
},
|
|
40784
40830
|
{
|
|
40785
|
-
type: "
|
|
40786
|
-
|
|
40787
|
-
|
|
40788
|
-
|
|
40789
|
-
|
|
40790
|
-
|
|
40831
|
+
type: "entry",
|
|
40832
|
+
entry: {
|
|
40833
|
+
role: "assistant",
|
|
40834
|
+
kind: "question",
|
|
40835
|
+
turnStatus: "waiting_for_input",
|
|
40836
|
+
content: {
|
|
40837
|
+
parts: [
|
|
40838
|
+
{
|
|
40839
|
+
type: "question",
|
|
40840
|
+
toolCallId: request.itemId,
|
|
40841
|
+
questions: [approvalQuestion(request)]
|
|
40842
|
+
}
|
|
40843
|
+
]
|
|
40791
40844
|
}
|
|
40792
|
-
}
|
|
40793
|
-
turnStatus: "waiting_for_input"
|
|
40845
|
+
}
|
|
40794
40846
|
}
|
|
40795
40847
|
];
|
|
40796
40848
|
}
|
|
@@ -41092,9 +41144,12 @@ import { join as join3 } from "path";
|
|
|
41092
41144
|
var CODEX_EXECUTABLE_PATH = "codex";
|
|
41093
41145
|
var CODEX_DEFAULT_MODEL = "gpt-5.3-codex";
|
|
41094
41146
|
var CODEX_HTTP_PROVIDER_ID = "openai-responses-http";
|
|
41147
|
+
var CODEX_OPENROUTER_PROVIDER_ID = "openrouter-responses-http";
|
|
41095
41148
|
var CODEX_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
41149
|
+
var CODEX_OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
41096
41150
|
var CODEX_API_KEY_ENV = "OPENAI_API_KEY";
|
|
41097
41151
|
var MODEL_GATEWAY_OPENAI_BASE_URL_ENV = "AUTO_MODEL_GATEWAY_OPENAI_BASE_URL";
|
|
41152
|
+
var MODEL_GATEWAY_OPENROUTER_BASE_URL_ENV = "AUTO_MODEL_GATEWAY_OPENROUTER_BASE_URL";
|
|
41098
41153
|
var CODEX_RUNTIME_PROCESS_ENV_KEYS = ["PATH", "HOME"];
|
|
41099
41154
|
function codexLaunchOptions(config2) {
|
|
41100
41155
|
return {
|
|
@@ -41117,8 +41172,14 @@ function codexThreadParams(config2) {
|
|
|
41117
41172
|
}
|
|
41118
41173
|
function renderCodexConfigToml(config2) {
|
|
41119
41174
|
const lines = [];
|
|
41120
|
-
|
|
41121
|
-
lines.push(`
|
|
41175
|
+
const selectedProvider = codexProviderIdForModel(config2);
|
|
41176
|
+
lines.push(`model = ${tomlString(config2.model?.id ?? CODEX_DEFAULT_MODEL)}`);
|
|
41177
|
+
lines.push(`model_provider = ${tomlString(selectedProvider)}`);
|
|
41178
|
+
if (config2.reasoningEffort) {
|
|
41179
|
+
lines.push(
|
|
41180
|
+
`model_reasoning_effort = ${tomlString(config2.reasoningEffort)}`
|
|
41181
|
+
);
|
|
41182
|
+
}
|
|
41122
41183
|
lines.push("");
|
|
41123
41184
|
lines.push(`[model_providers.${CODEX_HTTP_PROVIDER_ID}]`);
|
|
41124
41185
|
lines.push('name = "OpenAI"');
|
|
@@ -41128,6 +41189,15 @@ function renderCodexConfigToml(config2) {
|
|
|
41128
41189
|
lines.push('wire_api = "responses"');
|
|
41129
41190
|
lines.push(`env_key = ${tomlString(CODEX_API_KEY_ENV)}`);
|
|
41130
41191
|
lines.push("supports_websockets = false");
|
|
41192
|
+
lines.push("");
|
|
41193
|
+
lines.push(`[model_providers.${CODEX_OPENROUTER_PROVIDER_ID}]`);
|
|
41194
|
+
lines.push('name = "OpenRouter"');
|
|
41195
|
+
lines.push(
|
|
41196
|
+
`base_url = ${tomlString(openRouterBaseUrlForCodexConfig(config2.env))}`
|
|
41197
|
+
);
|
|
41198
|
+
lines.push('wire_api = "responses"');
|
|
41199
|
+
lines.push(`env_key = ${tomlString(CODEX_API_KEY_ENV)}`);
|
|
41200
|
+
lines.push("supports_websockets = false");
|
|
41131
41201
|
for (const [name, server] of Object.entries(config2.mcpServers ?? {})) {
|
|
41132
41202
|
lines.push("");
|
|
41133
41203
|
lines.push(`[mcp_servers.${tomlKey(name)}]`);
|
|
@@ -41155,6 +41225,12 @@ function codexProcessEnv(env) {
|
|
|
41155
41225
|
function openaiBaseUrlForCodexConfig(env) {
|
|
41156
41226
|
return env[MODEL_GATEWAY_OPENAI_BASE_URL_ENV] ?? CODEX_OPENAI_BASE_URL;
|
|
41157
41227
|
}
|
|
41228
|
+
function openRouterBaseUrlForCodexConfig(env) {
|
|
41229
|
+
return env[MODEL_GATEWAY_OPENROUTER_BASE_URL_ENV] ?? CODEX_OPENROUTER_BASE_URL;
|
|
41230
|
+
}
|
|
41231
|
+
function codexProviderIdForModel(config2) {
|
|
41232
|
+
return config2.model?.provider === "openrouter" ? CODEX_OPENROUTER_PROVIDER_ID : CODEX_HTTP_PROVIDER_ID;
|
|
41233
|
+
}
|
|
41158
41234
|
function codexHomeDir() {
|
|
41159
41235
|
const home = process.env.HOME;
|
|
41160
41236
|
if (!home) {
|
|
@@ -41209,6 +41285,7 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
41209
41285
|
// set means an interrupt/steer would race an unsettled item (FRA-3049 analog).
|
|
41210
41286
|
pendingToolItemIds = /* @__PURE__ */ new Set();
|
|
41211
41287
|
settlementWaiters = /* @__PURE__ */ new Set();
|
|
41288
|
+
callbackQueue = Promise.resolve();
|
|
41212
41289
|
// Messages held in "deferred" mode while a turn is in flight; flushed as a
|
|
41213
41290
|
// fresh turn once the active turn completes.
|
|
41214
41291
|
deferredMessages = [];
|
|
@@ -41480,10 +41557,12 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
41480
41557
|
return;
|
|
41481
41558
|
case "notification":
|
|
41482
41559
|
this.trackNotification(message.notification);
|
|
41483
|
-
|
|
41560
|
+
this.enqueueCallback(
|
|
41561
|
+
() => this.input.onNotification(message.notification)
|
|
41562
|
+
);
|
|
41484
41563
|
return;
|
|
41485
41564
|
case "serverRequest":
|
|
41486
|
-
|
|
41565
|
+
this.enqueueCallback(() => this.input.onServerRequest(message.request));
|
|
41487
41566
|
return;
|
|
41488
41567
|
case "elicitation":
|
|
41489
41568
|
this.writeFrame({
|
|
@@ -41509,6 +41588,18 @@ var CodexAgentBridgeSessionImpl = class {
|
|
|
41509
41588
|
return;
|
|
41510
41589
|
}
|
|
41511
41590
|
}
|
|
41591
|
+
enqueueCallback(callback) {
|
|
41592
|
+
this.callbackQueue = this.callbackQueue.then(async () => {
|
|
41593
|
+
try {
|
|
41594
|
+
await callback();
|
|
41595
|
+
} catch (error51) {
|
|
41596
|
+
try {
|
|
41597
|
+
await this.input.onError(error51);
|
|
41598
|
+
} catch {
|
|
41599
|
+
}
|
|
41600
|
+
}
|
|
41601
|
+
});
|
|
41602
|
+
}
|
|
41512
41603
|
// Track turn/item lifecycle so steer/interrupt target the live turn and gate on
|
|
41513
41604
|
// tool-item settlement.
|
|
41514
41605
|
trackNotification(notification) {
|
|
@@ -41646,17 +41737,20 @@ function createCodexCommandHandler(input) {
|
|
|
41646
41737
|
var CodexCommandHandler = class {
|
|
41647
41738
|
constructor(input) {
|
|
41648
41739
|
this.input = input;
|
|
41740
|
+
this.codexConfig = input.codex;
|
|
41649
41741
|
this.outputBuffer = new AgentBridgeOutputBuffer(input);
|
|
41650
41742
|
}
|
|
41651
41743
|
input;
|
|
41652
41744
|
context = null;
|
|
41653
41745
|
session = null;
|
|
41746
|
+
codexConfig;
|
|
41654
41747
|
injectedCommands = /* @__PURE__ */ new Set();
|
|
41655
41748
|
// itemId -> JSON-RPC request id of the parked approval request, so an `answer`
|
|
41656
41749
|
// command keyed by toolCallId (= itemId) can resolve the right server request.
|
|
41657
41750
|
pendingApprovals = /* @__PURE__ */ new Map();
|
|
41658
41751
|
outputBuffer;
|
|
41659
41752
|
projector = new CodexProjector();
|
|
41753
|
+
skipResumeForNextSession = false;
|
|
41660
41754
|
// ---------------------------------------------------------------------------
|
|
41661
41755
|
// Lifecycle (public API)
|
|
41662
41756
|
// ---------------------------------------------------------------------------
|
|
@@ -41711,6 +41805,7 @@ var CodexCommandHandler = class {
|
|
|
41711
41805
|
}
|
|
41712
41806
|
this.injectedCommands.add(delivery.commandId);
|
|
41713
41807
|
try {
|
|
41808
|
+
this.applySelectionForMessage(delivery);
|
|
41714
41809
|
await this.emitUserMessageEntry(
|
|
41715
41810
|
activeContext,
|
|
41716
41811
|
delivery.commandId,
|
|
@@ -41844,9 +41939,10 @@ var CodexCommandHandler = class {
|
|
|
41844
41939
|
if (this.session) {
|
|
41845
41940
|
return this.session;
|
|
41846
41941
|
}
|
|
41847
|
-
const resumeThreadId = this.storedResumeThreadId();
|
|
41942
|
+
const resumeThreadId = this.skipResumeForNextSession ? void 0 : this.storedResumeThreadId();
|
|
41943
|
+
this.skipResumeForNextSession = false;
|
|
41848
41944
|
const session = codexAgentBridgeRuntime.start({
|
|
41849
|
-
codex: this.
|
|
41945
|
+
codex: this.codexConfig,
|
|
41850
41946
|
...resumeThreadId ? { resumeThreadId } : {},
|
|
41851
41947
|
onNotification: (notification) => this.handleNotification(notification),
|
|
41852
41948
|
onServerRequest: (request) => this.handleServerRequest(request),
|
|
@@ -41863,6 +41959,28 @@ var CodexCommandHandler = class {
|
|
|
41863
41959
|
this.session = session;
|
|
41864
41960
|
return session;
|
|
41865
41961
|
}
|
|
41962
|
+
applySelectionForMessage(delivery) {
|
|
41963
|
+
const selection = deliverySelection2(delivery);
|
|
41964
|
+
if (!selection.model && selection.reasoningEffort === void 0) {
|
|
41965
|
+
return;
|
|
41966
|
+
}
|
|
41967
|
+
const next = {
|
|
41968
|
+
...this.codexConfig,
|
|
41969
|
+
...selection.model ? { model: selection.model } : {},
|
|
41970
|
+
...selection.reasoningEffort ? { reasoningEffort: selection.reasoningEffort } : {}
|
|
41971
|
+
};
|
|
41972
|
+
if (sameCodexConfigSelection(this.codexConfig, next)) {
|
|
41973
|
+
return;
|
|
41974
|
+
}
|
|
41975
|
+
this.codexConfig = next;
|
|
41976
|
+
this.skipResumeForNextSession = true;
|
|
41977
|
+
this.session?.close();
|
|
41978
|
+
this.session = null;
|
|
41979
|
+
this.pendingApprovals.clear();
|
|
41980
|
+
this.input.writeOutput?.(
|
|
41981
|
+
`agent_bridge_codex_model_selection_changed provider=${next.model?.provider ?? ""} model=${next.model?.id ?? ""} reasoning_effort=${next.reasoningEffort ?? ""}`
|
|
41982
|
+
);
|
|
41983
|
+
}
|
|
41866
41984
|
storedResumeThreadId() {
|
|
41867
41985
|
const store = this.input.sessionResume;
|
|
41868
41986
|
const activeContext = this.context;
|
|
@@ -41909,6 +42027,21 @@ function deliveryMessage2(delivery) {
|
|
|
41909
42027
|
}
|
|
41910
42028
|
return null;
|
|
41911
42029
|
}
|
|
42030
|
+
function deliverySelection2(delivery) {
|
|
42031
|
+
const payload = delivery.payload;
|
|
42032
|
+
if (!payload || typeof payload !== "object") {
|
|
42033
|
+
return {};
|
|
42034
|
+
}
|
|
42035
|
+
const model = "model" in payload ? AgentBridgeModelSelectionSchema.safeParse(payload.model) : null;
|
|
42036
|
+
const reasoningEffort = "reasoningEffort" in payload ? AgentBridgeCodexReasoningEffortSchema.safeParse(payload.reasoningEffort) : null;
|
|
42037
|
+
return {
|
|
42038
|
+
...model?.success ? { model: model.data } : {},
|
|
42039
|
+
...reasoningEffort?.success ? { reasoningEffort: reasoningEffort.data } : {}
|
|
42040
|
+
};
|
|
42041
|
+
}
|
|
42042
|
+
function sameCodexConfigSelection(current, next) {
|
|
42043
|
+
return current.model?.provider === next.model?.provider && current.model?.id === next.model?.id && current.reasoningEffort === next.reasoningEffort;
|
|
42044
|
+
}
|
|
41912
42045
|
function deliveryMode2(delivery) {
|
|
41913
42046
|
const payload = delivery.payload;
|
|
41914
42047
|
if (payload && typeof payload === "object" && "deliveryMode" in payload) {
|