github-router 0.3.269 → 0.3.271
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/{attribution-settings-B1txv_Lk.js → attribution-settings-DLRQEKpU.js} +3 -3
- package/dist/{attribution-settings-B1txv_Lk.js.map → attribution-settings-DLRQEKpU.js.map} +1 -1
- package/dist/{auth-r-my7efo.js → auth-DIFbHOu0.js} +2 -2
- package/dist/{auth-r-my7efo.js.map → auth-DIFbHOu0.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{check-usage-CZr2ZkG0.js → check-usage-DfnrR-d_.js} +3 -3
- package/dist/{check-usage-CZr2ZkG0.js.map → check-usage-DfnrR-d_.js.map} +1 -1
- package/dist/{claude-BjNY0J6e.js → claude-BpQVQE0T.js} +7 -7
- package/dist/{claude-BjNY0J6e.js.map → claude-BpQVQE0T.js.map} +1 -1
- package/dist/{codex-CoRWpkHL.js → codex-CGMiGJy1.js} +5 -5
- package/dist/{codex-CoRWpkHL.js.map → codex-CGMiGJy1.js.map} +1 -1
- package/dist/engine-DUJyXWZn.js +2 -0
- package/dist/{gate-discovery-D-7oua8b.js → gate-discovery-BBA7cV1D.js} +2 -2
- package/dist/{gate-discovery-D-7oua8b.js.map → gate-discovery-BBA7cV1D.js.map} +1 -1
- package/dist/{get-copilot-usage-CFEpeA7E.js → get-copilot-usage-Ds09xSmH.js} +2 -2
- package/dist/{get-copilot-usage-CFEpeA7E.js.map → get-copilot-usage-Ds09xSmH.js.map} +1 -1
- package/dist/{internal-stop-hook-Db5o9RcZ.js → internal-stop-hook-CO2NDmGL.js} +2 -2
- package/dist/{internal-stop-hook-Db5o9RcZ.js.map → internal-stop-hook-CO2NDmGL.js.map} +1 -1
- package/dist/main.js +8 -8
- package/dist/{models-CJLt4XjP.js → models-BFQUp0ov.js} +2 -2
- package/dist/{models-CJLt4XjP.js.map → models-BFQUp0ov.js.map} +1 -1
- package/dist/{peer-mcp-personas-DSbBlgFt.js → peer-mcp-personas-CN8xaXcV.js} +377 -101
- package/dist/peer-mcp-personas-CN8xaXcV.js.map +1 -0
- package/dist/{provision-CA-xwnFu.js → provision-CiPjSx7J.js} +2 -2
- package/dist/{provision-CA-xwnFu.js.map → provision-CiPjSx7J.js.map} +1 -1
- package/dist/{serve-DHny4ewF.js → serve-CpTMr5D9.js} +6 -6
- package/dist/{serve-DHny4ewF.js.map → serve-CpTMr5D9.js.map} +1 -1
- package/dist/{server-setup-Dd293T1O.js → server-setup-B02Myghc.js} +285 -99
- package/dist/server-setup-B02Myghc.js.map +1 -0
- package/dist/{start-P2rmHBkL.js → start-CIV9eXVb.js} +3 -3
- package/dist/{start-P2rmHBkL.js.map → start-CIV9eXVb.js.map} +1 -1
- package/dist/{token-C_q95GF7.js → token-iaSGp76k.js} +303 -143
- package/dist/token-iaSGp76k.js.map +1 -0
- package/package.json +1 -1
- package/dist/engine-DpVC7HRL.js +0 -2
- package/dist/peer-mcp-personas-DSbBlgFt.js.map +0 -1
- package/dist/server-setup-Dd293T1O.js.map +0 -1
- package/dist/token-C_q95GF7.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as getPackageVersion } from "./version-_Q1WpsQp.js";
|
|
2
2
|
import { t as PATHS } from "./paths-Bg1_DWhi.js";
|
|
3
|
-
import { C as
|
|
3
|
+
import { A as state, C as GITHUB_GRAPHQL_URL, D as githubAgentGraphQLHeaders, E as copilotVersion, O as githubAgentHeaders, S as GITHUB_API_BASE_URL, T as copilotHeaders, b as sanitizeTransportText, d as resolveModel, f as sleep$2, g as HTTPError, h as isAllowedCopilotHost, i as tryRefreshAndRetry, v as classifyTransportError, w as copilotBaseUrl, x as withTransientRetry, y as fetchWithTransientRetry } from "./token-iaSGp76k.js";
|
|
4
4
|
import { a as resolveExecutable, c as runManagedExeCapture, i as parseIntEnv, l as spawnTaskkillBestEffort, r as parseBoolEnv } from "./exec-y8C_MU8A.js";
|
|
5
5
|
import { i as registerExitHandlers$1, n as getInstanceUuid, r as recordWorkerRepo, t as WorktreeRegistry } from "./lifecycle-0XrazT05.js";
|
|
6
6
|
import { t as MCP_WORKSPACE_HEADER } from "./mcp-workspace-header-CGJbNeHb.js";
|
|
7
7
|
import { n as ArtifactError, r as applyInsecureTls, t as ArtifactClient } from "./client-CQMfroGV.js";
|
|
8
|
-
import { n as isPidAlive, r as registerColbertExitHandlers, s as trackChild, t as getColbertInstanceUuid } from "./lifecycle-AgNOtFRv.js";
|
|
8
|
+
import { n as isPidAlive$1, r as registerColbertExitHandlers, s as trackChild, t as getColbertInstanceUuid } from "./lifecycle-AgNOtFRv.js";
|
|
9
9
|
import { h as runGateChecks, m as sealedGateIds, p as resolveSealedGate } from "./stop-gate-hook-BqpumJtl.js";
|
|
10
10
|
import { t as liveExec } from "./orchestration-B_Q3ncXI.js";
|
|
11
11
|
import { createRequire } from "node:module";
|
|
@@ -4966,19 +4966,19 @@ function resolveTierModel(tier) {
|
|
|
4966
4966
|
}
|
|
4967
4967
|
//#endregion
|
|
4968
4968
|
//#region src/lib/first-mate/classifier.ts
|
|
4969
|
-
function isRecord$
|
|
4969
|
+
function isRecord$2(value) {
|
|
4970
4970
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4971
4971
|
}
|
|
4972
4972
|
function firstMessageContent$1(value) {
|
|
4973
|
-
if (!isRecord$
|
|
4973
|
+
if (!isRecord$2(value) || !Array.isArray(value.choices)) return null;
|
|
4974
4974
|
const first = value.choices[0];
|
|
4975
|
-
if (!isRecord$
|
|
4975
|
+
if (!isRecord$2(first) || !isRecord$2(first.message)) return null;
|
|
4976
4976
|
return typeof first.message.content === "string" ? first.message.content : null;
|
|
4977
4977
|
}
|
|
4978
4978
|
function parseJsonObject(value) {
|
|
4979
4979
|
try {
|
|
4980
4980
|
const parsed = JSON.parse(value);
|
|
4981
|
-
return isRecord$
|
|
4981
|
+
return isRecord$2(parsed) ? parsed : null;
|
|
4982
4982
|
} catch {
|
|
4983
4983
|
return null;
|
|
4984
4984
|
}
|
|
@@ -5048,7 +5048,7 @@ async function classifyPlanReady(logExcerpt) {
|
|
|
5048
5048
|
schemaHint: "{\"planReady\":boolean,\"planExcerpt\":\"<=1200 chars from the completed plan, or empty\",\"confidence\":number}",
|
|
5049
5049
|
maxTokens: 500,
|
|
5050
5050
|
validate(value) {
|
|
5051
|
-
if (!isRecord$
|
|
5051
|
+
if (!isRecord$2(value)) return null;
|
|
5052
5052
|
const planReady = booleanValue$1(value.planReady);
|
|
5053
5053
|
const planExcerpt = stringValue$1(value.planExcerpt);
|
|
5054
5054
|
if (planReady === null || planExcerpt === null) return null;
|
|
@@ -5065,7 +5065,7 @@ async function classifyQuestionAnswerable(question, acceptanceCriteria) {
|
|
|
5065
5065
|
user: `Acceptance criteria:\n${acceptanceCriteria}\n\nAgent question:\n${question}`,
|
|
5066
5066
|
schemaHint: "{\"answerable\":boolean,\"answer\":\"present only when answerable\",\"confidence\":number}",
|
|
5067
5067
|
validate(value) {
|
|
5068
|
-
if (!isRecord$
|
|
5068
|
+
if (!isRecord$2(value)) return null;
|
|
5069
5069
|
const answerable = booleanValue$1(value.answerable);
|
|
5070
5070
|
if (answerable === null) return null;
|
|
5071
5071
|
const answer = stringValue$1(value.answer);
|
|
@@ -5083,7 +5083,7 @@ async function classifyFixAddressed(failureSummary, latestLogExcerpt) {
|
|
|
5083
5083
|
user: `Failure summary:\n${failureSummary}\n\nLatest log excerpt:\n${latestLogExcerpt}`,
|
|
5084
5084
|
schemaHint: "{\"addressed\":boolean,\"confidence\":number}",
|
|
5085
5085
|
validate(value) {
|
|
5086
|
-
if (!isRecord$
|
|
5086
|
+
if (!isRecord$2(value)) return null;
|
|
5087
5087
|
const addressed = booleanValue$1(value.addressed);
|
|
5088
5088
|
return addressed === null ? null : { addressed };
|
|
5089
5089
|
}
|
|
@@ -5095,7 +5095,7 @@ async function classifyStuck(logExcerpt) {
|
|
|
5095
5095
|
user: `Log excerpt:\n${logExcerpt}`,
|
|
5096
5096
|
schemaHint: "{\"stuck\":boolean,\"confidence\":number}",
|
|
5097
5097
|
validate(value) {
|
|
5098
|
-
if (!isRecord$
|
|
5098
|
+
if (!isRecord$2(value)) return null;
|
|
5099
5099
|
const stuck = booleanValue$1(value.stuck);
|
|
5100
5100
|
return stuck === null ? null : { stuck };
|
|
5101
5101
|
}
|
|
@@ -9975,6 +9975,40 @@ const WIN_RENAME_TRANSIENT = /* @__PURE__ */ new Set([
|
|
|
9975
9975
|
"EBUSY"
|
|
9976
9976
|
]);
|
|
9977
9977
|
/**
|
|
9978
|
+
* Owner pid embedded in a `.draining.<pid>.<rand>` or `.claim.<pid>.<rand>`
|
|
9979
|
+
* segment. A file can carry both (a claimed orphan keeps the drain segment), so
|
|
9980
|
+
* the LAST match is the current owner.
|
|
9981
|
+
*/
|
|
9982
|
+
const OWNER_SEGMENT_RE = /\.(?:draining|claim)\.(\d+)\./g;
|
|
9983
|
+
/**
|
|
9984
|
+
* Claims held by a live drainer in THIS process, across instances. Per-instance
|
|
9985
|
+
* `inflight` cannot see a peer instance's claim, and both share our pid, so pid
|
|
9986
|
+
* liveness cannot separate them either. A claim abandoned on a read error is
|
|
9987
|
+
* never added here, which is what keeps it replayable (R3 #4).
|
|
9988
|
+
*/
|
|
9989
|
+
const heldClaims = /* @__PURE__ */ new Set();
|
|
9990
|
+
function ownerPidOf(name) {
|
|
9991
|
+
let pid;
|
|
9992
|
+
for (const match of name.matchAll(OWNER_SEGMENT_RE)) pid = Number(match[1]);
|
|
9993
|
+
return pid !== void 0 && Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
9994
|
+
}
|
|
9995
|
+
/**
|
|
9996
|
+
* `process.kill(pid, 0)` probes existence without signalling; `EPERM` means the
|
|
9997
|
+
* process exists but is owned by another user (still alive). Mirrors the copies
|
|
9998
|
+
* in `lib/paths.ts`, `lib/colbert/lifecycle.ts`, and `lib/worker-agent/
|
|
9999
|
+
* lifecycle.ts` — kept local so first-mate takes no dependency on those modules.
|
|
10000
|
+
*/
|
|
10001
|
+
function isPidAlive(pid) {
|
|
10002
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
10003
|
+
try {
|
|
10004
|
+
process.kill(pid, 0);
|
|
10005
|
+
return true;
|
|
10006
|
+
} catch (err) {
|
|
10007
|
+
if (err.code === "EPERM") return true;
|
|
10008
|
+
return false;
|
|
10009
|
+
}
|
|
10010
|
+
}
|
|
10011
|
+
/**
|
|
9978
10012
|
* Atomically claim `from` by renaming it to the process-unique `to`.
|
|
9979
10013
|
* Returns `true` if THIS caller won the claim, `false` if a peer already took it
|
|
9980
10014
|
* (source gone). Retries transient Windows sharing violations so two concurrent
|
|
@@ -10070,6 +10104,9 @@ var AnswerInbox = class {
|
|
|
10070
10104
|
if (!name.startsWith(`${base}.draining.`)) continue;
|
|
10071
10105
|
const orphan = path.join(dir, name);
|
|
10072
10106
|
if (this.inflight.has(orphan)) continue;
|
|
10107
|
+
if (heldClaims.has(orphan)) continue;
|
|
10108
|
+
const owner = ownerPidOf(name);
|
|
10109
|
+
if (owner !== void 0 && owner !== process.pid && isPidAlive(owner)) continue;
|
|
10073
10110
|
const claim = `${orphan}.claim.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
10074
10111
|
if (!await claimByRename(orphan, claim)) continue;
|
|
10075
10112
|
try {
|
|
@@ -10086,11 +10123,15 @@ var AnswerInbox = class {
|
|
|
10086
10123
|
} catch (err) {
|
|
10087
10124
|
if (err.code !== "ENOENT") consola.warn(`first-mate: deferring unreadable inbox claim ${target} for retry:`, err);
|
|
10088
10125
|
}
|
|
10089
|
-
for (const p of claimed)
|
|
10126
|
+
for (const p of claimed) {
|
|
10127
|
+
this.inflight.add(p);
|
|
10128
|
+
heldClaims.add(p);
|
|
10129
|
+
}
|
|
10090
10130
|
const ack = async () => {
|
|
10091
10131
|
for (const p of claimed) {
|
|
10092
10132
|
await fs$1.unlink(p).catch(() => {});
|
|
10093
10133
|
this.inflight.delete(p);
|
|
10134
|
+
heldClaims.delete(p);
|
|
10094
10135
|
}
|
|
10095
10136
|
};
|
|
10096
10137
|
return {
|
|
@@ -11499,7 +11540,7 @@ function parsePackageJson(text) {
|
|
|
11499
11540
|
if (text === void 0) return void 0;
|
|
11500
11541
|
try {
|
|
11501
11542
|
const parsed = JSON.parse(text);
|
|
11502
|
-
if (!isRecord(parsed)) return void 0;
|
|
11543
|
+
if (!isRecord$1(parsed)) return void 0;
|
|
11503
11544
|
return {
|
|
11504
11545
|
scripts: stringRecord(parsed.scripts),
|
|
11505
11546
|
dependencies: stringRecord(parsed.dependencies),
|
|
@@ -11699,11 +11740,11 @@ function buildScaffoldPrBody(reports) {
|
|
|
11699
11740
|
"No factory protocol files are seeded; orchestration remains external to the repository."
|
|
11700
11741
|
].join("\n");
|
|
11701
11742
|
}
|
|
11702
|
-
function isRecord(value) {
|
|
11743
|
+
function isRecord$1(value) {
|
|
11703
11744
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11704
11745
|
}
|
|
11705
11746
|
function stringRecord(value) {
|
|
11706
|
-
if (!isRecord(value)) return {};
|
|
11747
|
+
if (!isRecord$1(value)) return {};
|
|
11707
11748
|
const result = {};
|
|
11708
11749
|
for (const [key, entry] of Object.entries(value)) if (typeof entry === "string") result[key] = entry;
|
|
11709
11750
|
return result;
|
|
@@ -15779,7 +15820,7 @@ async function freshnessVerdict(workspace) {
|
|
|
15779
15820
|
};
|
|
15780
15821
|
if (meta.status === "building") {
|
|
15781
15822
|
const pid = typeof meta.buildPid === "number" ? meta.buildPid : 0;
|
|
15782
|
-
if (isInitInFlight(workspace) || pid > 0 && isPidAlive(pid)) return {
|
|
15823
|
+
if (isInitInFlight(workspace) || pid > 0 && isPidAlive$1(pid)) return {
|
|
15783
15824
|
verdict: "building",
|
|
15784
15825
|
meta
|
|
15785
15826
|
};
|
|
@@ -27263,10 +27304,8 @@ function relayAnthropicStream(body, opts) {
|
|
|
27263
27304
|
safeClose(controller);
|
|
27264
27305
|
return;
|
|
27265
27306
|
}
|
|
27266
|
-
const errName
|
|
27267
|
-
const
|
|
27268
|
-
consola.error(`Upstream stream interrupted at ${opts.routePath}: bytes=${bytesRelayed} errType=${errName} message=${JSON.stringify(errMessage)}`);
|
|
27269
|
-
const event = buildAnthropicErrorEvent(errName, errMessage);
|
|
27307
|
+
const { errName, errMessage, transport } = logStreamError(opts.routePath, error, bytesRelayed);
|
|
27308
|
+
const event = buildAnthropicErrorEvent(errName, errMessage, transport);
|
|
27270
27309
|
try {
|
|
27271
27310
|
controller.enqueue(ENCODER$1.encode(event));
|
|
27272
27311
|
} catch (enqueueError) {
|
|
@@ -27331,12 +27370,13 @@ async function readIteratorWithTimeout(iterator, timeoutMs) {
|
|
|
27331
27370
|
* event: error
|
|
27332
27371
|
* data: {"type":"error","error":{"type":"...","message":"..."}}
|
|
27333
27372
|
*/
|
|
27334
|
-
function buildAnthropicErrorEvent(errName, errMessage) {
|
|
27373
|
+
function buildAnthropicErrorEvent(errName, errMessage, transportDetails) {
|
|
27374
|
+
const details = transportDetails ?? classifyNamedStreamError(errName, errMessage);
|
|
27335
27375
|
const payload = {
|
|
27336
27376
|
type: "error",
|
|
27337
27377
|
error: {
|
|
27338
|
-
type: classifyStreamError(
|
|
27339
|
-
message:
|
|
27378
|
+
type: classifyStreamError(details),
|
|
27379
|
+
message: formatStreamErrorMessage(details)
|
|
27340
27380
|
}
|
|
27341
27381
|
};
|
|
27342
27382
|
return `event: error\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
@@ -27346,25 +27386,194 @@ function buildAnthropicErrorEvent(errName, errMessage) {
|
|
|
27346
27386
|
* followed by the `data: [DONE]` terminator that OpenAI clients expect.
|
|
27347
27387
|
*/
|
|
27348
27388
|
function buildOpenAIErrorEvent(errName, errMessage) {
|
|
27389
|
+
const details = classifyNamedStreamError(errName, errMessage);
|
|
27349
27390
|
const payload = { error: {
|
|
27350
|
-
type: classifyStreamError(
|
|
27351
|
-
message:
|
|
27391
|
+
type: classifyStreamError(details),
|
|
27392
|
+
message: formatStreamErrorMessage(details)
|
|
27352
27393
|
} };
|
|
27353
27394
|
return `data: ${JSON.stringify(payload)}\n\ndata: [DONE]\n\n`;
|
|
27354
27395
|
}
|
|
27355
|
-
function
|
|
27356
|
-
|
|
27357
|
-
|
|
27396
|
+
function classifyNamedStreamError(errName, errMessage) {
|
|
27397
|
+
const error = Object.assign(new Error(errMessage), { name: errName });
|
|
27398
|
+
return classifyTransportError(error);
|
|
27399
|
+
}
|
|
27400
|
+
function classifyStreamError(details) {
|
|
27401
|
+
if (details.name === "AbortError" || details.name === "InactivityTimeout" || details.name === "TimeoutError" || details.name === "timeout_error") return "timeout_error";
|
|
27402
|
+
if (details.classification === "transient") return "overloaded_error";
|
|
27358
27403
|
return "api_error";
|
|
27359
27404
|
}
|
|
27360
|
-
function
|
|
27361
|
-
const
|
|
27362
|
-
const
|
|
27363
|
-
|
|
27405
|
+
function formatStreamErrorMessage(details) {
|
|
27406
|
+
const code = details.causeCode ?? details.code;
|
|
27407
|
+
const suffix = code ? ` (${sanitizeTransportText(code)})` : "";
|
|
27408
|
+
const diagnostic = `${sanitizeTransportText(details.name)}: ${sanitizeTransportText(details.message)}${suffix}`;
|
|
27409
|
+
if (details.classification === "transient") return `Upstream stream interrupted by a transient transport failure; retry the request. ${diagnostic}`;
|
|
27410
|
+
if (details.classification === "deterministic") return `Upstream stream interrupted by a connectivity or TLS configuration failure. ${diagnostic}`;
|
|
27411
|
+
return `Upstream stream interrupted: ${diagnostic}`;
|
|
27412
|
+
}
|
|
27413
|
+
function logStreamError(routePath, error, bytesRelayed) {
|
|
27414
|
+
const transport = classifyTransportError(error);
|
|
27415
|
+
const errName = transport.name;
|
|
27416
|
+
const errMessage = transport.message;
|
|
27417
|
+
const byteField = bytesRelayed === void 0 ? "" : ` bytes=${Math.max(0, bytesRelayed)}`;
|
|
27418
|
+
const codeField = transport.code ? ` code=${JSON.stringify(transport.code)}` : "";
|
|
27419
|
+
const causeCodeField = transport.causeCode ? ` causeCode=${JSON.stringify(transport.causeCode)}` : "";
|
|
27420
|
+
consola.error("Upstream stream interrupted", `routePath=${JSON.stringify(routePath)}${byteField} classification=${transport.classification} errType=${errName}${codeField}${causeCodeField} message=${JSON.stringify(errMessage)}`);
|
|
27364
27421
|
return {
|
|
27365
27422
|
errName,
|
|
27366
|
-
errMessage
|
|
27423
|
+
errMessage,
|
|
27424
|
+
transport
|
|
27425
|
+
};
|
|
27426
|
+
}
|
|
27427
|
+
//#endregion
|
|
27428
|
+
//#region src/lib/thinking-history-repair.ts
|
|
27429
|
+
const THINKING_INTEGRITY_ERROR_RES = [/messages\.(\d+)\.content\.\d+:\s*`thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified/, /messages\.(\d+)\.content\.\d+:\s*Invalid `signature` in `thinking` block/];
|
|
27430
|
+
const MAX_REMEMBERED_REPAIRS = 1e3;
|
|
27431
|
+
const OMITTED_THINKING_PLACEHOLDER = "[prior reasoning omitted]";
|
|
27432
|
+
const repairSalt = randomBytes(32);
|
|
27433
|
+
const rememberedRepairs = /* @__PURE__ */ new Set();
|
|
27434
|
+
function declined(reason, detail = {}) {
|
|
27435
|
+
return {
|
|
27436
|
+
ok: false,
|
|
27437
|
+
decline: {
|
|
27438
|
+
reason,
|
|
27439
|
+
...detail
|
|
27440
|
+
}
|
|
27441
|
+
};
|
|
27442
|
+
}
|
|
27443
|
+
/** Render a decline as a single log-safe `key=value` line. */
|
|
27444
|
+
function formatThinkingRepairDecline(decline) {
|
|
27445
|
+
return Object.entries(decline).filter(([, value]) => value !== void 0).map(([key, value]) => `${key}=${String(value)}`).join(" ");
|
|
27446
|
+
}
|
|
27447
|
+
function isRecord(value) {
|
|
27448
|
+
return typeof value === "object" && value !== null;
|
|
27449
|
+
}
|
|
27450
|
+
/** Count signed blocks without hashing — used only to explain a decline. */
|
|
27451
|
+
function countSignedBlocks(content) {
|
|
27452
|
+
return content.filter((block) => isRecord(block) && (block.type === "thinking" || block.type === "redacted_thinking")).length;
|
|
27453
|
+
}
|
|
27454
|
+
function signedBlockFingerprint(_messageIndex, content) {
|
|
27455
|
+
const hash = createHash("sha256");
|
|
27456
|
+
hash.update(repairSalt);
|
|
27457
|
+
let signedBlocks = 0;
|
|
27458
|
+
for (let index = 0; index < content.length; index++) {
|
|
27459
|
+
const block = content[index];
|
|
27460
|
+
if (!isRecord(block)) continue;
|
|
27461
|
+
if (block.type !== "thinking" && block.type !== "redacted_thinking") continue;
|
|
27462
|
+
signedBlocks++;
|
|
27463
|
+
hash.update(String(index));
|
|
27464
|
+
hash.update(String(block.type));
|
|
27465
|
+
if (typeof block.signature === "string") hash.update(block.signature);
|
|
27466
|
+
if (typeof block.data === "string") hash.update(block.data);
|
|
27467
|
+
}
|
|
27468
|
+
return signedBlocks > 0 ? hash.digest("hex") : void 0;
|
|
27469
|
+
}
|
|
27470
|
+
function repairMessageAt(parsed, messageIndex) {
|
|
27471
|
+
if (!Array.isArray(parsed.messages)) return declined("no-messages-array", { messageIndex });
|
|
27472
|
+
const messages = [...parsed.messages];
|
|
27473
|
+
const detail = {
|
|
27474
|
+
messageIndex,
|
|
27475
|
+
messageCount: messages.length
|
|
27476
|
+
};
|
|
27477
|
+
const message = messages[messageIndex];
|
|
27478
|
+
if (!isRecord(message)) return declined("message-missing", detail);
|
|
27479
|
+
if (message.role !== "assistant") return declined("message-not-assistant", {
|
|
27480
|
+
...detail,
|
|
27481
|
+
roleAtIndex: typeof message.role === "string" ? message.role : "unknown"
|
|
27482
|
+
});
|
|
27483
|
+
if (!Array.isArray(message.content)) return declined("content-not-array", {
|
|
27484
|
+
...detail,
|
|
27485
|
+
roleAtIndex: "assistant"
|
|
27486
|
+
});
|
|
27487
|
+
const shape = {
|
|
27488
|
+
...detail,
|
|
27489
|
+
roleAtIndex: "assistant",
|
|
27490
|
+
blocksAtIndex: message.content.length,
|
|
27491
|
+
signedBlocksAtIndex: countSignedBlocks(message.content)
|
|
27492
|
+
};
|
|
27493
|
+
const fingerprint = signedBlockFingerprint(messageIndex, message.content);
|
|
27494
|
+
if (!fingerprint) return declined("no-signed-blocks", shape);
|
|
27495
|
+
const repairedContent = message.content.filter((block) => !isRecord(block) || block.type !== "thinking" && block.type !== "redacted_thinking");
|
|
27496
|
+
const removedBlocks = message.content.length - repairedContent.length;
|
|
27497
|
+
if (removedBlocks === 0) return declined("no-blocks-removed", shape);
|
|
27498
|
+
if (repairedContent.length === 0) repairedContent.push({
|
|
27499
|
+
type: "text",
|
|
27500
|
+
text: OMITTED_THINKING_PLACEHOLDER
|
|
27501
|
+
});
|
|
27502
|
+
messages[messageIndex] = {
|
|
27503
|
+
...message,
|
|
27504
|
+
content: repairedContent
|
|
27367
27505
|
};
|
|
27506
|
+
parsed.messages = messages;
|
|
27507
|
+
return {
|
|
27508
|
+
ok: true,
|
|
27509
|
+
repair: {
|
|
27510
|
+
body: JSON.stringify(parsed),
|
|
27511
|
+
fingerprint,
|
|
27512
|
+
messageIndex,
|
|
27513
|
+
removedBlocks
|
|
27514
|
+
}
|
|
27515
|
+
};
|
|
27516
|
+
}
|
|
27517
|
+
/**
|
|
27518
|
+
* Build a one-shot repair only for Copilot's known signed-thinking integrity
|
|
27519
|
+
* rejections. The upstream error is the oracle: valid omitted-display thinking
|
|
27520
|
+
* also has an empty `thinking` string, so request shape alone cannot identify a
|
|
27521
|
+
* corrupt signature safely.
|
|
27522
|
+
*
|
|
27523
|
+
* Returns a discriminated outcome so a caller can report WHY a repair was not
|
|
27524
|
+
* applied; a silent decline is what made the original incident undiagnosable.
|
|
27525
|
+
*/
|
|
27526
|
+
function repairRejectedThinkingHistory(rawBody, upstreamErrorText) {
|
|
27527
|
+
const match = THINKING_INTEGRITY_ERROR_RES.map((pattern) => pattern.exec(upstreamErrorText)).find((candidate) => candidate !== null);
|
|
27528
|
+
if (!match) return declined("error-not-recognized");
|
|
27529
|
+
const messageIndex = Number(match[1]);
|
|
27530
|
+
if (!Number.isSafeInteger(messageIndex) || messageIndex < 0) return declined("message-index-invalid", { messageIndex });
|
|
27531
|
+
let parsed;
|
|
27532
|
+
try {
|
|
27533
|
+
parsed = JSON.parse(rawBody);
|
|
27534
|
+
} catch {
|
|
27535
|
+
return declined("body-not-json", { messageIndex });
|
|
27536
|
+
}
|
|
27537
|
+
return repairMessageAt(parsed, messageIndex);
|
|
27538
|
+
}
|
|
27539
|
+
/**
|
|
27540
|
+
* Reapply a repair already proven successful in this process. Only salted
|
|
27541
|
+
* digests are retained; no message, thinking, signature, or tool content is
|
|
27542
|
+
* stored.
|
|
27543
|
+
*/
|
|
27544
|
+
function repairKnownThinkingHistory(rawBody) {
|
|
27545
|
+
if (rememberedRepairs.size === 0) return void 0;
|
|
27546
|
+
let parsed;
|
|
27547
|
+
try {
|
|
27548
|
+
parsed = JSON.parse(rawBody);
|
|
27549
|
+
} catch {
|
|
27550
|
+
return;
|
|
27551
|
+
}
|
|
27552
|
+
if (!Array.isArray(parsed.messages)) return void 0;
|
|
27553
|
+
let repaired;
|
|
27554
|
+
let totalRemovedBlocks = 0;
|
|
27555
|
+
for (let index = parsed.messages.length - 1; index >= 0; index--) {
|
|
27556
|
+
const message = parsed.messages[index];
|
|
27557
|
+
if (!isRecord(message) || !Array.isArray(message.content)) continue;
|
|
27558
|
+
const fingerprint = signedBlockFingerprint(index, message.content);
|
|
27559
|
+
if (!fingerprint || !rememberedRepairs.has(fingerprint)) continue;
|
|
27560
|
+
const attempt = repairMessageAt(parsed, index);
|
|
27561
|
+
if (!attempt.ok) continue;
|
|
27562
|
+
totalRemovedBlocks += attempt.repair.removedBlocks;
|
|
27563
|
+
repaired = {
|
|
27564
|
+
...attempt.repair,
|
|
27565
|
+
removedBlocks: totalRemovedBlocks
|
|
27566
|
+
};
|
|
27567
|
+
}
|
|
27568
|
+
return repaired;
|
|
27569
|
+
}
|
|
27570
|
+
function rememberThinkingHistoryRepair(fingerprint) {
|
|
27571
|
+
if (rememberedRepairs.has(fingerprint)) return;
|
|
27572
|
+
if (rememberedRepairs.size >= MAX_REMEMBERED_REPAIRS) {
|
|
27573
|
+
const oldest = rememberedRepairs.values().next().value;
|
|
27574
|
+
if (typeof oldest === "string") rememberedRepairs.delete(oldest);
|
|
27575
|
+
}
|
|
27576
|
+
rememberedRepairs.add(fingerprint);
|
|
27368
27577
|
}
|
|
27369
27578
|
//#endregion
|
|
27370
27579
|
//#region src/services/advisor/advisor.ts
|
|
@@ -27715,10 +27924,11 @@ async function runAdvisor(conversation, advisorModel, advisorEffort, signal) {
|
|
|
27715
27924
|
* against edge cases that would otherwise emit a malformed block —
|
|
27716
27925
|
* spec violation in either direction is a 400.
|
|
27717
27926
|
*/
|
|
27718
|
-
function toClientServerToolUseId(id,
|
|
27719
|
-
|
|
27720
|
-
|
|
27721
|
-
|
|
27927
|
+
function toClientServerToolUseId(id, _fallbackIndex) {
|
|
27928
|
+
if (!id.startsWith("toolu_")) throw new Error("advisor tool_use id is not round-trippable");
|
|
27929
|
+
const suffix = id.slice(6);
|
|
27930
|
+
if (!/^[a-zA-Z0-9_]+$/.test(suffix)) throw new Error("advisor tool_use id is not round-trippable");
|
|
27931
|
+
return `srvtoolu_${suffix}`;
|
|
27722
27932
|
}
|
|
27723
27933
|
/**
|
|
27724
27934
|
* Build an SSE event line in the canonical Anthropic shape:
|
|
@@ -27754,6 +27964,7 @@ function buildAdvisorStream(opts) {
|
|
|
27754
27964
|
let messageStartForwarded = false;
|
|
27755
27965
|
let nextSyntheticIndex = 0;
|
|
27756
27966
|
let turnsRun;
|
|
27967
|
+
let pendingMessageDelta = null;
|
|
27757
27968
|
const safeEnqueue = (bytes) => {
|
|
27758
27969
|
try {
|
|
27759
27970
|
controller.enqueue(bytes);
|
|
@@ -27767,9 +27978,42 @@ function buildAdvisorStream(opts) {
|
|
|
27767
27978
|
}
|
|
27768
27979
|
};
|
|
27769
27980
|
const safeEnqueueEvent = (type, data) => safeEnqueue(ENCODER.encode(sseEvent(type, data)));
|
|
27981
|
+
const captureMessageDelta = (payload) => {
|
|
27982
|
+
const delta = payload.delta && typeof payload.delta === "object" ? payload.delta : {};
|
|
27983
|
+
const usage = payload.usage && typeof payload.usage === "object" ? payload.usage : {};
|
|
27984
|
+
if (!pendingMessageDelta) pendingMessageDelta = {
|
|
27985
|
+
stopReason: delta.stop_reason ?? null,
|
|
27986
|
+
stopSequence: delta.stop_sequence ?? null,
|
|
27987
|
+
usage: {}
|
|
27988
|
+
};
|
|
27989
|
+
else {
|
|
27990
|
+
if (delta.stop_reason !== void 0) pendingMessageDelta.stopReason = delta.stop_reason;
|
|
27991
|
+
if (delta.stop_sequence !== void 0) pendingMessageDelta.stopSequence = delta.stop_sequence;
|
|
27992
|
+
}
|
|
27993
|
+
for (const [key, value] of Object.entries(usage)) if (typeof value === "number" && Number.isFinite(value)) pendingMessageDelta.usage[key] = (pendingMessageDelta.usage[key] ?? 0) + value;
|
|
27994
|
+
};
|
|
27995
|
+
const emitTerminal = (forcedStopReason) => {
|
|
27996
|
+
if (pendingMessageDelta || forcedStopReason) {
|
|
27997
|
+
const terminal = pendingMessageDelta ?? {
|
|
27998
|
+
stopReason: null,
|
|
27999
|
+
stopSequence: null,
|
|
28000
|
+
usage: {}
|
|
28001
|
+
};
|
|
28002
|
+
if (!safeEnqueueEvent("message_delta", {
|
|
28003
|
+
type: "message_delta",
|
|
28004
|
+
delta: {
|
|
28005
|
+
stop_reason: forcedStopReason ?? terminal.stopReason,
|
|
28006
|
+
stop_sequence: terminal.stopSequence
|
|
28007
|
+
},
|
|
28008
|
+
usage: terminal.usage
|
|
28009
|
+
})) return false;
|
|
28010
|
+
}
|
|
28011
|
+
return safeEnqueueEvent("message_stop", { type: "message_stop" });
|
|
28012
|
+
};
|
|
27770
28013
|
async function processOneTurn(response) {
|
|
27771
28014
|
const capturedBlocks = [];
|
|
27772
|
-
|
|
28015
|
+
const advisorToolUses = [];
|
|
28016
|
+
let clientToolUseCount = 0;
|
|
27773
28017
|
const indexToBlock = /* @__PURE__ */ new Map();
|
|
27774
28018
|
for await (const ev of events(response)) {
|
|
27775
28019
|
if (!ev.event || !ev.data) continue;
|
|
@@ -27779,7 +28023,8 @@ function buildAdvisorStream(opts) {
|
|
|
27779
28023
|
} catch {
|
|
27780
28024
|
if (!safeEnqueue(ENCODER.encode(`event: ${ev.event}\ndata: ${ev.data}\n\n`))) return {
|
|
27781
28025
|
capturedBlocks,
|
|
27782
|
-
|
|
28026
|
+
advisorToolUses,
|
|
28027
|
+
clientToolUseCount
|
|
27783
28028
|
};
|
|
27784
28029
|
continue;
|
|
27785
28030
|
}
|
|
@@ -27788,7 +28033,8 @@ function buildAdvisorStream(opts) {
|
|
|
27788
28033
|
if (!messageStartForwarded) {
|
|
27789
28034
|
if (!safeEnqueueEvent(ev.event, payload)) return {
|
|
27790
28035
|
capturedBlocks,
|
|
27791
|
-
|
|
28036
|
+
advisorToolUses,
|
|
28037
|
+
clientToolUseCount
|
|
27792
28038
|
};
|
|
27793
28039
|
messageStartForwarded = true;
|
|
27794
28040
|
}
|
|
@@ -27800,12 +28046,13 @@ function buildAdvisorStream(opts) {
|
|
|
27800
28046
|
const myIndex = nextSyntheticIndex++;
|
|
27801
28047
|
if (block.type === "tool_use" && block.name === "__anthropic_advisor") {
|
|
27802
28048
|
const id = typeof block.id === "string" ? block.id : `toolu_advisor_${myIndex}`;
|
|
27803
|
-
advisorToolUse = {
|
|
28049
|
+
const advisorToolUse = {
|
|
27804
28050
|
index: myIndex,
|
|
27805
28051
|
id,
|
|
27806
28052
|
clientId: toClientServerToolUseId(id, myIndex),
|
|
27807
28053
|
inputJson: ""
|
|
27808
28054
|
};
|
|
28055
|
+
advisorToolUses.push(advisorToolUse);
|
|
27809
28056
|
const translated = {
|
|
27810
28057
|
...payload,
|
|
27811
28058
|
index: myIndex,
|
|
@@ -27818,7 +28065,8 @@ function buildAdvisorStream(opts) {
|
|
|
27818
28065
|
};
|
|
27819
28066
|
if (!safeEnqueueEvent(ev.event, translated)) return {
|
|
27820
28067
|
capturedBlocks,
|
|
27821
|
-
|
|
28068
|
+
advisorToolUses,
|
|
28069
|
+
clientToolUseCount
|
|
27822
28070
|
};
|
|
27823
28071
|
const captured = {
|
|
27824
28072
|
block: {
|
|
@@ -27833,13 +28081,15 @@ function buildAdvisorStream(opts) {
|
|
|
27833
28081
|
capturedBlocks.push(captured);
|
|
27834
28082
|
indexToBlock.set(upstreamIndex, captured);
|
|
27835
28083
|
} else {
|
|
28084
|
+
if (block.type === "tool_use") clientToolUseCount++;
|
|
27836
28085
|
const reindexed = {
|
|
27837
28086
|
...payload,
|
|
27838
28087
|
index: myIndex
|
|
27839
28088
|
};
|
|
27840
28089
|
if (!safeEnqueueEvent(ev.event, reindexed)) return {
|
|
27841
28090
|
capturedBlocks,
|
|
27842
|
-
|
|
28091
|
+
advisorToolUses,
|
|
28092
|
+
clientToolUseCount
|
|
27843
28093
|
};
|
|
27844
28094
|
const captured = {
|
|
27845
28095
|
block: { ...block },
|
|
@@ -27862,7 +28112,8 @@ function buildAdvisorStream(opts) {
|
|
|
27862
28112
|
};
|
|
27863
28113
|
if (!safeEnqueueEvent(ev.event, reindexed)) return {
|
|
27864
28114
|
capturedBlocks,
|
|
27865
|
-
|
|
28115
|
+
advisorToolUses,
|
|
28116
|
+
clientToolUseCount
|
|
27866
28117
|
};
|
|
27867
28118
|
if (captured && delta) {
|
|
27868
28119
|
if (delta.type === "text_delta" && typeof delta.text === "string") captured.block.text = (captured.block.text ?? "") + delta.text;
|
|
@@ -27876,7 +28127,8 @@ function buildAdvisorStream(opts) {
|
|
|
27876
28127
|
}
|
|
27877
28128
|
} else if (!safeEnqueueEvent(ev.event, payload)) return {
|
|
27878
28129
|
capturedBlocks,
|
|
27879
|
-
|
|
28130
|
+
advisorToolUses,
|
|
28131
|
+
clientToolUseCount
|
|
27880
28132
|
};
|
|
27881
28133
|
continue;
|
|
27882
28134
|
}
|
|
@@ -27889,7 +28141,8 @@ function buildAdvisorStream(opts) {
|
|
|
27889
28141
|
};
|
|
27890
28142
|
if (!safeEnqueueEvent(ev.event, reindexed)) return {
|
|
27891
28143
|
capturedBlocks,
|
|
27892
|
-
|
|
28144
|
+
advisorToolUses,
|
|
28145
|
+
clientToolUseCount
|
|
27893
28146
|
};
|
|
27894
28147
|
if (captured) {
|
|
27895
28148
|
if (captured.block.type === "tool_use" && captured.partialJson.length > 0) try {
|
|
@@ -27898,38 +28151,28 @@ function buildAdvisorStream(opts) {
|
|
|
27898
28151
|
consola.warn(`advisor: malformed input_json_delta for tool_use id=${captured.block.id ?? "?"} name=${captured.block.name ?? "?"} partialJson.length=${captured.partialJson.length} parseError=${err instanceof Error ? err.message : String(err)}`);
|
|
27899
28152
|
captured.block.input = {};
|
|
27900
28153
|
}
|
|
27901
|
-
if (captured.block.type === "text" && (typeof captured.block.text !== "string" || captured.block.text.length === 0)) captured.dropFromReplay = true;
|
|
27902
28154
|
}
|
|
27903
28155
|
continue;
|
|
27904
28156
|
}
|
|
27905
28157
|
case "message_delta":
|
|
27906
|
-
|
|
27907
|
-
capturedBlocks,
|
|
27908
|
-
advisorToolUse
|
|
27909
|
-
};
|
|
28158
|
+
captureMessageDelta(payload);
|
|
27910
28159
|
continue;
|
|
27911
|
-
case "message_stop":
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
|
|
27915
|
-
|
|
27916
|
-
if (!safeEnqueueEvent(ev.event, payload)) return {
|
|
27917
|
-
capturedBlocks,
|
|
27918
|
-
advisorToolUse
|
|
27919
|
-
};
|
|
27920
|
-
return {
|
|
27921
|
-
capturedBlocks,
|
|
27922
|
-
advisorToolUse
|
|
27923
|
-
};
|
|
28160
|
+
case "message_stop": return {
|
|
28161
|
+
capturedBlocks,
|
|
28162
|
+
advisorToolUses,
|
|
28163
|
+
clientToolUseCount
|
|
28164
|
+
};
|
|
27924
28165
|
default: if (!safeEnqueueEvent(ev.event, payload)) return {
|
|
27925
28166
|
capturedBlocks,
|
|
27926
|
-
|
|
28167
|
+
advisorToolUses,
|
|
28168
|
+
clientToolUseCount
|
|
27927
28169
|
};
|
|
27928
28170
|
}
|
|
27929
28171
|
}
|
|
27930
28172
|
return {
|
|
27931
28173
|
capturedBlocks,
|
|
27932
|
-
|
|
28174
|
+
advisorToolUses,
|
|
28175
|
+
clientToolUseCount
|
|
27933
28176
|
};
|
|
27934
28177
|
}
|
|
27935
28178
|
try {
|
|
@@ -27937,13 +28180,16 @@ function buildAdvisorStream(opts) {
|
|
|
27937
28180
|
for (turnsRun = 0; turnsRun < 16; turnsRun++) {
|
|
27938
28181
|
if (aborter.signal.aborted) return;
|
|
27939
28182
|
if (conversation === null) return;
|
|
27940
|
-
const { capturedBlocks,
|
|
27941
|
-
if (
|
|
28183
|
+
const { capturedBlocks, advisorToolUses, clientToolUseCount } = await processOneTurn(response);
|
|
28184
|
+
if (advisorToolUses.length === 0) {
|
|
28185
|
+
emitTerminal();
|
|
28186
|
+
return;
|
|
28187
|
+
}
|
|
27942
28188
|
if (aborter.signal.aborted) return;
|
|
27943
28189
|
if (conversation === null) return;
|
|
27944
28190
|
const assistantTurn = {
|
|
27945
28191
|
role: "assistant",
|
|
27946
|
-
content: capturedBlocks.
|
|
28192
|
+
content: capturedBlocks.map((c) => {
|
|
27947
28193
|
if (c.advisorReplay) {
|
|
27948
28194
|
const input = typeof c.block.input === "object" && c.block.input !== null ? c.block.input : {};
|
|
27949
28195
|
return {
|
|
@@ -27957,48 +28203,78 @@ function buildAdvisorStream(opts) {
|
|
|
27957
28203
|
})
|
|
27958
28204
|
};
|
|
27959
28205
|
conversation.push(assistantTurn);
|
|
27960
|
-
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
27964
|
-
|
|
27965
|
-
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
|
|
28206
|
+
const advisorConversation = conversation;
|
|
28207
|
+
const advisorTexts = await Promise.all(advisorToolUses.map(async () => {
|
|
28208
|
+
try {
|
|
28209
|
+
return await runAdvisor(advisorConversation, advisorModel, advisorEffort, aborter.signal);
|
|
28210
|
+
} catch (err) {
|
|
28211
|
+
if (aborter.signal.aborted) throw err;
|
|
28212
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
28213
|
+
consola.warn(`Advisor model call failed: ${msg}`);
|
|
28214
|
+
return `[Advisor unavailable: ${msg}. Continuing without external review — proceed with caution and consider self-checking against your primary-source evidence.]`;
|
|
28215
|
+
}
|
|
28216
|
+
})).catch((err) => {
|
|
28217
|
+
if (aborter.signal.aborted) return null;
|
|
28218
|
+
throw err;
|
|
28219
|
+
});
|
|
28220
|
+
if (!advisorTexts) return;
|
|
27969
28221
|
if (aborter.signal.aborted) return;
|
|
27970
28222
|
if (conversation === null) return;
|
|
27971
|
-
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
type: "
|
|
27977
|
-
|
|
27978
|
-
|
|
27979
|
-
type: "
|
|
27980
|
-
|
|
28223
|
+
for (let index = 0; index < advisorToolUses.length; index++) {
|
|
28224
|
+
const advisorToolUse = advisorToolUses[index];
|
|
28225
|
+
const advisorText = advisorTexts[index];
|
|
28226
|
+
const resultIndex = nextSyntheticIndex++;
|
|
28227
|
+
if (!safeEnqueueEvent("content_block_start", {
|
|
28228
|
+
type: "content_block_start",
|
|
28229
|
+
index: resultIndex,
|
|
28230
|
+
content_block: {
|
|
28231
|
+
type: "advisor_tool_result",
|
|
28232
|
+
tool_use_id: advisorToolUse.clientId,
|
|
28233
|
+
content: {
|
|
28234
|
+
type: "advisor_result",
|
|
28235
|
+
text: advisorText
|
|
28236
|
+
}
|
|
27981
28237
|
}
|
|
27982
|
-
}
|
|
27983
|
-
|
|
27984
|
-
|
|
27985
|
-
|
|
27986
|
-
|
|
27987
|
-
}
|
|
28238
|
+
})) return;
|
|
28239
|
+
if (!safeEnqueueEvent("content_block_stop", {
|
|
28240
|
+
type: "content_block_stop",
|
|
28241
|
+
index: resultIndex
|
|
28242
|
+
})) return;
|
|
28243
|
+
}
|
|
28244
|
+
if (clientToolUseCount > 0) {
|
|
28245
|
+
emitTerminal("tool_use");
|
|
28246
|
+
return;
|
|
28247
|
+
}
|
|
27988
28248
|
conversation.push({
|
|
27989
28249
|
role: "user",
|
|
27990
|
-
content:
|
|
28250
|
+
content: advisorToolUses.map((advisorToolUse, index) => ({
|
|
27991
28251
|
type: "tool_result",
|
|
27992
28252
|
tool_use_id: advisorToolUse.id,
|
|
27993
|
-
content:
|
|
27994
|
-
}
|
|
28253
|
+
content: advisorTexts[index]
|
|
28254
|
+
}))
|
|
27995
28255
|
});
|
|
27996
28256
|
if (aborter.signal.aborted) return;
|
|
27997
|
-
|
|
28257
|
+
let continuationSend = JSON.stringify({
|
|
27998
28258
|
...opts.baseBody,
|
|
27999
28259
|
messages: conversation,
|
|
28000
28260
|
stream: true
|
|
28001
|
-
})
|
|
28261
|
+
});
|
|
28262
|
+
const knownRepair = repairKnownThinkingHistory(continuationSend);
|
|
28263
|
+
if (knownRepair) continuationSend = knownRepair.body;
|
|
28264
|
+
try {
|
|
28265
|
+
response = await createMessages(continuationSend, opts.requestHeaders, aborter.signal, true);
|
|
28266
|
+
} catch (continuationError) {
|
|
28267
|
+
if (!(continuationError instanceof HTTPError)) throw continuationError;
|
|
28268
|
+
const errorBody = await continuationError.response.clone().text().catch(() => "");
|
|
28269
|
+
const outcome = repairRejectedThinkingHistory(continuationSend, errorBody);
|
|
28270
|
+
if (!outcome.ok) {
|
|
28271
|
+
consola.warn(`Advisor continuation thinking-history repair declined: ${formatThinkingRepairDecline(outcome.decline)}`);
|
|
28272
|
+
throw continuationError;
|
|
28273
|
+
}
|
|
28274
|
+
consola.warn(`Advisor continuation: retrying without rejected thinking blocks: message=${outcome.repair.messageIndex} removed_blocks=${outcome.repair.removedBlocks}`);
|
|
28275
|
+
response = await createMessages(outcome.repair.body, opts.requestHeaders, aborter.signal, true);
|
|
28276
|
+
rememberThinkingHistoryRepair(outcome.repair.fingerprint);
|
|
28277
|
+
}
|
|
28002
28278
|
}
|
|
28003
28279
|
if (aborter.signal.aborted) return;
|
|
28004
28280
|
const finalIndex = nextSyntheticIndex++;
|
|
@@ -28022,7 +28298,7 @@ function buildAdvisorStream(opts) {
|
|
|
28022
28298
|
type: "content_block_stop",
|
|
28023
28299
|
index: finalIndex
|
|
28024
28300
|
});
|
|
28025
|
-
|
|
28301
|
+
emitTerminal("end_turn");
|
|
28026
28302
|
} catch (err) {
|
|
28027
28303
|
if (aborter.signal.aborted) return;
|
|
28028
28304
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -34217,6 +34493,6 @@ function enumerateInjectedMcpToolNames(groupKeys, opts = {}) {
|
|
|
34217
34493
|
return [...new Set(names)];
|
|
34218
34494
|
}
|
|
34219
34495
|
//#endregion
|
|
34220
|
-
export {
|
|
34496
|
+
export { browserToolsEnabled as $, searchWeb as A, collapsePathKeys as At, buildAnthropicErrorEvent as B, withOneMSuffix as Bt, buildToolbeltAwareness as C, provisionAndIndexColbert as Ct, TOOLBELT_TOOLS$1 as D, CONDENSED_OPERATING_SEQUENCE as Dt, vscodeRipgrepPath as E, warmTreeSitterPool as Et, isAdvisorRequested as F, DEFAULT_PORT as Ft, relayAnthropicStream as G, isControllerClosedError as H, formatThinkingRepairDecline as I, UPSTREAM_FETCH_TIMEOUT_MS as It, agentToolsEnabled as J, handleMcpDelete as K, rememberThinkingHistoryRepair as L, UPSTREAM_INACTIVITY_TIMEOUT_MS as Lt, ADVISOR_TOOL_INSTRUCTIONS as M, DEFAULT_CLAUDE_MODEL_FALLBACKS as Mt, buildAdvisorStream as N, DEFAULT_CODEX_MODEL as Nt, assetFor as O, DEFINITION_OF_GREATNESS as Ot, injectAdvisorTool as P, DEFAULT_CODEX_MODEL_FALLBACKS as Pt, browserCompoundToolsEnabled as Q, repairKnownThinkingHistory as R, generateRandomPort as Rt, availableToolCommands as S, colbertDegradedWarning as St, toolbeltSkipSet as T, extractZipMember as Tt, logStreamError as U, buildOpenAIErrorEvent as V, withInstallLock as Vt, readIteratorWithTimeout as W, brainstormModel as X, artifactToolsEnabled as Y, browseAgentEnabled as Z, appendPlanReminder as _, MAX_RESPONSE_BODY_BYTES as _t, buildPeerAwarenessSnippet as a, scribeModel as at, runWorkerAgent as b, provisionBrowserAssets as bt, personasFor as c, shimDefaultsToXhigh as ct, EXPLORE_DEFAULT_MODEL as d, getTokenCount as dt, fleetToolsEnabled as et, EXPLORE_DEFAULT_THINKING as f, assembleResponsesPayload as ft, TEST_DEFAULT_MODEL as g, createChatCompletions as gt, REVIEW_DEFAULT_MODEL as h, createResponses as ht, buildAgentPrompt as i, scoutModel as it, ADVISOR_INTERNAL_TOOL_NAME as j, toolbeltPathOverride as jt, satisfiesMinVersion as k, shouldUseInsecureTls as kt, BROWSE_DEFAULT_MODEL as l, countTokens as lt, PLAN_DEFAULT_MODEL as m, pickEndpoint as mt, MCP_GROUPS as n, nativeSubagentModel as nt, buildPeerAwarenessSummary as o, standInToolEnabled as ot, IMPLEMENT_DEFAULT_MODEL as p, resolveMcpToolTimeoutMs as pt, handleMcpPost as q, assertMcpToolSurfaceConsistent as r, reviewerModel as rt, enumerateInjectedMcpToolNames as s, workerToolsEnabled as st, GROUP_META as t, geminiAvailable as tt, DEFAULT_MODEL as u, createMessages as ut, resolveModeDefaults as v, readResponseBodyCapped as vt, toolbeltEnabled as w, extractTarGzMember as wt, buildEnv as x, hasSupportedBrowserInstalled as xt, resolveWorkerRunOpts as y, parseJsonOrDiagnose as yt, repairRejectedThinkingHistory as z, pickClaudeDefault as zt };
|
|
34221
34497
|
|
|
34222
|
-
//# sourceMappingURL=peer-mcp-personas-
|
|
34498
|
+
//# sourceMappingURL=peer-mcp-personas-CN8xaXcV.js.map
|