@dotobokuri/fleet-console 1.69.0 → 1.70.0
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/client/assets/{_baseUniq-BPBd-J9P.js → _baseUniq-81Y5kFtp.js} +1 -1
- package/dist/client/assets/{arc-spHqy4X3.js → arc-d96Fgk-5.js} +1 -1
- package/dist/client/assets/{architectureDiagram-Q4EWVU46-7CHqKfxu.js → architectureDiagram-Q4EWVU46-BBgIklLp.js} +1 -1
- package/dist/client/assets/{blockDiagram-DXYQGD6D-YasFDgl_.js → blockDiagram-DXYQGD6D-BCjY9dJk.js} +1 -1
- package/dist/client/assets/{c4Diagram-AHTNJAMY-CcoPJq56.js → c4Diagram-AHTNJAMY-BVJRdf8q.js} +1 -1
- package/dist/client/assets/channel-CiSQi5S5.js +1 -0
- package/dist/client/assets/{chunk-4BX2VUAB-MYBJn9BE.js → chunk-4BX2VUAB-CT7BCzBg.js} +1 -1
- package/dist/client/assets/{chunk-4TB4RGXK-C1wg6GR_.js → chunk-4TB4RGXK-DUbDaHiY.js} +1 -1
- package/dist/client/assets/{chunk-55IACEB6-BoufMT1O.js → chunk-55IACEB6-C7HDwq0R.js} +1 -1
- package/dist/client/assets/{chunk-EDXVE4YY-BzAhAIl3.js → chunk-EDXVE4YY-Mh16Bf7t.js} +1 -1
- package/dist/client/assets/{chunk-FMBD7UC4-yVrLsKzP.js → chunk-FMBD7UC4-D3BjqAun.js} +1 -1
- package/dist/client/assets/{chunk-OYMX7WX6-YiiKaqRQ.js → chunk-OYMX7WX6-DmzxPT1k.js} +1 -1
- package/dist/client/assets/{chunk-QZHKN3VN-CqWQlGHT.js → chunk-QZHKN3VN-CaZdQK6Z.js} +1 -1
- package/dist/client/assets/{chunk-YZCP3GAM-9yLOmU5k.js → chunk-YZCP3GAM-Q2hrlgLY.js} +1 -1
- package/dist/client/assets/classDiagram-6PBFFD2Q-Cy-ZC6xF.js +1 -0
- package/dist/client/assets/classDiagram-v2-HSJHXN6E-Cy-ZC6xF.js +1 -0
- package/dist/client/assets/clone-BAhE6Fq8.js +1 -0
- package/dist/client/assets/{cose-bilkent-S5V4N54A-XkTuSq7v.js → cose-bilkent-S5V4N54A-CPdIsNiQ.js} +1 -1
- package/dist/client/assets/{dagre-KV5264BT-DyzXIEAe.js → dagre-KV5264BT-BYWdUXO0.js} +1 -1
- package/dist/client/assets/{diagram-5BDNPKRD-DF24YlCa.js → diagram-5BDNPKRD-BC8rqmOK.js} +1 -1
- package/dist/client/assets/{diagram-G4DWMVQ6-CVhcj9RK.js → diagram-G4DWMVQ6-CES6iBQQ.js} +1 -1
- package/dist/client/assets/{diagram-MMDJMWI5-C-kGKk4K.js → diagram-MMDJMWI5-BfhQrSaN.js} +1 -1
- package/dist/client/assets/{diagram-TYMM5635-mr285WbR.js → diagram-TYMM5635-C2FgHNxP.js} +1 -1
- package/dist/client/assets/{erDiagram-SMLLAGMA-BtEx-XlU.js → erDiagram-SMLLAGMA-KQgKZTcf.js} +1 -1
- package/dist/client/assets/{flowDiagram-DWJPFMVM-DuWy3xzN.js → flowDiagram-DWJPFMVM-7Ytk1sX_.js} +1 -1
- package/dist/client/assets/{ganttDiagram-T4ZO3ILL-B2-xEikU.js → ganttDiagram-T4ZO3ILL-C4yl6vGV.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-UUTBAWPF-EM17u_t7.js → gitGraphDiagram-UUTBAWPF-DyN7iLk4.js} +1 -1
- package/dist/client/assets/{graph-xuE12FIq.js → graph-BsOHL3Ty.js} +1 -1
- package/dist/client/assets/index-2049WCXu.css +1 -0
- package/dist/client/assets/index-DJcpFTNB.js +466 -0
- package/dist/client/assets/{infoDiagram-42DDH7IO-B3MF4XtW.js → infoDiagram-42DDH7IO-BIOEjyDP.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-UXIWVN3A-DoQ2mGyh.js → ishikawaDiagram-UXIWVN3A-C18t-DEH.js} +1 -1
- package/dist/client/assets/{journeyDiagram-VCZTEJTY-GeR9sFH-.js → journeyDiagram-VCZTEJTY-BysZXCkq.js} +1 -1
- package/dist/client/assets/{kanban-definition-6JOO6SKY-DrrYMuvL.js → kanban-definition-6JOO6SKY-Zdulrt1W.js} +1 -1
- package/dist/client/assets/{layout-DH63A-3u.js → layout-DhT9CiMw.js} +1 -1
- package/dist/client/assets/{linear-BIjE6zB1.js → linear-DQna1rOZ.js} +1 -1
- package/dist/client/assets/{mermaid.core-yrrC2Lqo.js → mermaid.core-C0sjt4NJ.js} +4 -4
- package/dist/client/assets/{min-CR-H8E6U.js → min-Dyx0ykEh.js} +1 -1
- package/dist/client/assets/{mindmap-definition-QFDTVHPH-BzSC43J-.js → mindmap-definition-QFDTVHPH-BzEvAUNd.js} +1 -1
- package/dist/client/assets/{pieDiagram-DEJITSTG-BdghNtCc.js → pieDiagram-DEJITSTG-Cd4ORVnw.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-34T5L4WZ-s_zN2epw.js → quadrantDiagram-34T5L4WZ-CvNxhBIm.js} +1 -1
- package/dist/client/assets/{requirementDiagram-MS252O5E-DuiGG6Tx.js → requirementDiagram-MS252O5E-CuGuie-o.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-XADWPNL6-Bp0JBk2g.js → sankeyDiagram-XADWPNL6-zn7buHsU.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-FGHM5R23-AzQ3M31V.js → sequenceDiagram-FGHM5R23-BxDReh8o.js} +1 -1
- package/dist/client/assets/{stateDiagram-FHFEXIEX-BGgm44ev.js → stateDiagram-FHFEXIEX-DtZ0UE1G.js} +1 -1
- package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-aYct9Owm.js +1 -0
- package/dist/client/assets/{timeline-definition-GMOUNBTQ-UqfsiBJY.js → timeline-definition-GMOUNBTQ-DfKveVha.js} +1 -1
- package/dist/client/assets/{vennDiagram-DHZGUBPP-PsCGF9nR.js → vennDiagram-DHZGUBPP-CZe6StT_.js} +1 -1
- package/dist/client/assets/{wardley-RL74JXVD-BDQbnh-d.js → wardley-RL74JXVD-B10WfMsc.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-NUSXRM2D-CtVA1JMs.js → wardleyDiagram-NUSXRM2D-DzN04fy9.js} +1 -1
- package/dist/client/assets/{xychartDiagram-5P7HB3ND-BsLlZWbc.js → xychartDiagram-5P7HB3ND-CIgNRRNp.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/fleet-plugins/repository/routes.mjs +41 -5
- package/dist/fleet-plugins/terminal/routes.mjs +580 -410
- package/dist/fleet.mjs +490 -258
- package/package.json +1 -1
- package/dist/client/assets/channel-DfEjadrw.js +0 -1
- package/dist/client/assets/classDiagram-6PBFFD2Q-D9vQdv0q.js +0 -1
- package/dist/client/assets/classDiagram-v2-HSJHXN6E-D9vQdv0q.js +0 -1
- package/dist/client/assets/clone-Ck2x5JX2.js +0 -1
- package/dist/client/assets/index-C5EOZGlC.js +0 -466
- package/dist/client/assets/index-CHHE3nPw.css +0 -1
- package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-CZDbnuN-.js +0 -1
package/dist/fleet.mjs
CHANGED
|
@@ -10,7 +10,8 @@ import http from 'node:http';
|
|
|
10
10
|
import { spawn, execFileSync, execFile as execFile$1 } from 'node:child_process';
|
|
11
11
|
import { builtinModules, createRequire } from 'node:module';
|
|
12
12
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
13
|
-
import
|
|
13
|
+
import { randomUUID, createHash } from 'crypto';
|
|
14
|
+
import * as fs42 from 'fs';
|
|
14
15
|
import { constants, mkdirSync as mkdirSync$1, rmSync, renameSync as renameSync$1, appendFileSync, statSync } from 'fs';
|
|
15
16
|
import * as path32 from 'path';
|
|
16
17
|
import path32__default, { dirname } from 'path';
|
|
@@ -18,7 +19,6 @@ import { execFile } from 'child_process';
|
|
|
18
19
|
import fs22, { appendFile, chmod, mkdir as mkdir$1, stat as stat$1, unlink, rename as rename$1 } from 'fs/promises';
|
|
19
20
|
import os4 from 'os';
|
|
20
21
|
import { promisify } from 'util';
|
|
21
|
-
import { randomUUID, createHash } from 'crypto';
|
|
22
22
|
import http2 from 'http2';
|
|
23
23
|
import { deflateRawSync, inflateRawSync } from 'zlib';
|
|
24
24
|
import { mkdtemp, rm, mkdir, readdir, readFile, stat, writeFile, appendFile as appendFile$1, realpath, lstat, rename } from 'node:fs/promises';
|
|
@@ -1085,7 +1085,7 @@ function joinChunks(chunks, totalBytes) {
|
|
|
1085
1085
|
return joined;
|
|
1086
1086
|
}
|
|
1087
1087
|
function parseVersion(version2) {
|
|
1088
|
-
const match =
|
|
1088
|
+
const match = VERSION_PATTERN2.exec(version2.trim());
|
|
1089
1089
|
if (match === null) {
|
|
1090
1090
|
return void 0;
|
|
1091
1091
|
}
|
|
@@ -1137,13 +1137,13 @@ function parseNumericPart(value) {
|
|
|
1137
1137
|
function compareNumbers(left, right) {
|
|
1138
1138
|
return left === right ? 0 : left > right ? 1 : -1;
|
|
1139
1139
|
}
|
|
1140
|
-
var NPM_REGISTRY_BASE_URL, REGISTRY_TIMEOUT_MS, MAX_REGISTRY_RESPONSE_BYTES,
|
|
1140
|
+
var NPM_REGISTRY_BASE_URL, REGISTRY_TIMEOUT_MS, MAX_REGISTRY_RESPONSE_BYTES, VERSION_PATTERN2;
|
|
1141
1141
|
var init_version_check = __esm({
|
|
1142
1142
|
"../../packages/core-agent/src/update/version-check.ts"() {
|
|
1143
1143
|
NPM_REGISTRY_BASE_URL = "https://registry.npmjs.org/";
|
|
1144
1144
|
REGISTRY_TIMEOUT_MS = 3e3;
|
|
1145
1145
|
MAX_REGISTRY_RESPONSE_BYTES = 1024 * 1024;
|
|
1146
|
-
|
|
1146
|
+
VERSION_PATTERN2 = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
1147
1147
|
}
|
|
1148
1148
|
});
|
|
1149
1149
|
function createGlobalPackageUpdater(deps) {
|
|
@@ -1517,9 +1517,9 @@ async function checkUpdateStatus(release, options = {}) {
|
|
|
1517
1517
|
}
|
|
1518
1518
|
const channel = resolveUpdateChannel(release.version);
|
|
1519
1519
|
if (options.forceRefresh !== true) {
|
|
1520
|
-
const
|
|
1521
|
-
if (
|
|
1522
|
-
return isVersionGreater(
|
|
1520
|
+
const cached3 = readCachedLatestVersion(channel);
|
|
1521
|
+
if (cached3 !== void 0) {
|
|
1522
|
+
return isVersionGreater(cached3, release.version) ? { status: "update", latest: cached3 } : { status: "current", latest: cached3 };
|
|
1523
1523
|
}
|
|
1524
1524
|
}
|
|
1525
1525
|
const latest = await fetchLatestFleetCliVersion(channel);
|
|
@@ -17642,11 +17642,11 @@ function createZeroMessage(desc) {
|
|
|
17642
17642
|
}
|
|
17643
17643
|
}
|
|
17644
17644
|
} else {
|
|
17645
|
-
const
|
|
17645
|
+
const cached3 = messagePrototypes.get(desc);
|
|
17646
17646
|
let prototype;
|
|
17647
17647
|
let members;
|
|
17648
|
-
if (
|
|
17649
|
-
({ prototype, members } =
|
|
17648
|
+
if (cached3) {
|
|
17649
|
+
({ prototype, members } = cached3);
|
|
17650
17650
|
} else {
|
|
17651
17651
|
prototype = {};
|
|
17652
17652
|
members = /* @__PURE__ */ new Set();
|
|
@@ -18417,9 +18417,9 @@ function reflect(messageDesc2, message, check2 = true) {
|
|
|
18417
18417
|
var messageSortedFields = /* @__PURE__ */ new WeakMap();
|
|
18418
18418
|
var ReflectMessageImpl = class {
|
|
18419
18419
|
get sortedFields() {
|
|
18420
|
-
const
|
|
18421
|
-
if (
|
|
18422
|
-
return
|
|
18420
|
+
const cached3 = messageSortedFields.get(this.desc);
|
|
18421
|
+
if (cached3) {
|
|
18422
|
+
return cached3;
|
|
18423
18423
|
}
|
|
18424
18424
|
const sortedFields = this.desc.fields.concat().sort((a, b) => a.number - b.number);
|
|
18425
18425
|
messageSortedFields.set(this.desc, sortedFields);
|
|
@@ -21538,6 +21538,20 @@ function clampReasoningEffort(effort, supportedEfforts, modelId) {
|
|
|
21538
21538
|
if (lower) return lower.supported;
|
|
21539
21539
|
throw new UnsupportedReasoningEffortError(effort, supportedEfforts, modelId);
|
|
21540
21540
|
}
|
|
21541
|
+
var REASONING_SIGNATURE_PREFIX = "fleet-reasoning:v1:";
|
|
21542
|
+
function encodeReasoningSignature(id, encrypted) {
|
|
21543
|
+
return `${REASONING_SIGNATURE_PREFIX}${id}:${encrypted}`;
|
|
21544
|
+
}
|
|
21545
|
+
function decodeReasoningSignature(signature) {
|
|
21546
|
+
if (typeof signature !== "string" || !signature.startsWith(REASONING_SIGNATURE_PREFIX)) {
|
|
21547
|
+
return void 0;
|
|
21548
|
+
}
|
|
21549
|
+
const body2 = signature.slice(REASONING_SIGNATURE_PREFIX.length);
|
|
21550
|
+
const separator = body2.indexOf(":");
|
|
21551
|
+
if (separator === -1) return void 0;
|
|
21552
|
+
const encrypted = body2.slice(separator + 1);
|
|
21553
|
+
return encrypted.length > 0 ? { id: body2.slice(0, separator), encrypted } : void 0;
|
|
21554
|
+
}
|
|
21541
21555
|
var ContextWindowExceededError = class extends Error {
|
|
21542
21556
|
constructor(requestTokens, contextWindow) {
|
|
21543
21557
|
super(`Prompt is too long: ${requestTokens} tokens > ${contextWindow} maximum context window`);
|
|
@@ -23867,11 +23881,21 @@ function translateMessage(message) {
|
|
|
23867
23881
|
const items = [];
|
|
23868
23882
|
const parts = [];
|
|
23869
23883
|
let reasoningContent = "";
|
|
23884
|
+
let reasoningBlob;
|
|
23870
23885
|
const takeReasoningContent = () => {
|
|
23871
|
-
if (role !== "assistant"
|
|
23886
|
+
if (role !== "assistant") return {};
|
|
23887
|
+
const blob = reasoningBlob;
|
|
23872
23888
|
const reasoning = reasoningContent;
|
|
23873
23889
|
reasoningContent = "";
|
|
23874
|
-
|
|
23890
|
+
reasoningBlob = void 0;
|
|
23891
|
+
if (reasoning.length === 0 && blob === void 0) return {};
|
|
23892
|
+
return {
|
|
23893
|
+
...reasoning.length === 0 ? {} : { reasoning_content: reasoning },
|
|
23894
|
+
...blob === void 0 ? {} : {
|
|
23895
|
+
reasoning_encrypted: blob.encrypted,
|
|
23896
|
+
...blob.id.length === 0 ? {} : { reasoning_id: blob.id }
|
|
23897
|
+
}
|
|
23898
|
+
};
|
|
23875
23899
|
};
|
|
23876
23900
|
const flushParts = (includeReasoning = true) => {
|
|
23877
23901
|
if (parts.length === 0) {
|
|
@@ -23920,6 +23944,9 @@ function translateMessage(message) {
|
|
|
23920
23944
|
if (role === "assistant" && typeof block.thinking === "string") {
|
|
23921
23945
|
reasoningContent += block.thinking;
|
|
23922
23946
|
}
|
|
23947
|
+
if (role === "assistant") {
|
|
23948
|
+
reasoningBlob = decodeReasoningSignature(block.signature) ?? reasoningBlob;
|
|
23949
|
+
}
|
|
23923
23950
|
break;
|
|
23924
23951
|
case "redacted_thinking":
|
|
23925
23952
|
break;
|
|
@@ -24075,6 +24102,7 @@ async function collectAnthropicMessage(events, fallbackModel, options = {}) {
|
|
|
24075
24102
|
let model = fallbackModel;
|
|
24076
24103
|
let text = "";
|
|
24077
24104
|
const thinking = /* @__PURE__ */ new Map();
|
|
24105
|
+
const reasoningBlobs = /* @__PURE__ */ new Map();
|
|
24078
24106
|
let stopReason = "end_turn";
|
|
24079
24107
|
let outputTokens = 0;
|
|
24080
24108
|
let inputTokens = 0;
|
|
@@ -24116,6 +24144,16 @@ async function collectAnthropicMessage(events, fallbackModel, options = {}) {
|
|
|
24116
24144
|
break;
|
|
24117
24145
|
}
|
|
24118
24146
|
case "response.output_item.done":
|
|
24147
|
+
if (event.item.type === "reasoning") {
|
|
24148
|
+
if (event.item.encrypted_content !== void 0) {
|
|
24149
|
+
reasoningBlobs.set(
|
|
24150
|
+
event.item.id,
|
|
24151
|
+
encodeReasoningSignature(event.item.id, event.item.encrypted_content)
|
|
24152
|
+
);
|
|
24153
|
+
if (!thinking.has(event.item.id)) thinking.set(event.item.id, "");
|
|
24154
|
+
}
|
|
24155
|
+
break;
|
|
24156
|
+
}
|
|
24119
24157
|
if (event.item.type === "web_search_call") {
|
|
24120
24158
|
const query = derivedWebSearchQuery(event.item.action);
|
|
24121
24159
|
content.push({
|
|
@@ -24152,7 +24190,7 @@ async function collectAnthropicMessage(events, fallbackModel, options = {}) {
|
|
|
24152
24190
|
content.unshift(...[...thinking].map(([itemId, value]) => ({
|
|
24153
24191
|
type: "thinking",
|
|
24154
24192
|
thinking: value,
|
|
24155
|
-
signature: `gateway_${reasoningBlockKey(itemId)}`
|
|
24193
|
+
signature: reasoningBlobs.get(itemId) ?? `gateway_${reasoningBlockKey(itemId)}`
|
|
24156
24194
|
})));
|
|
24157
24195
|
return {
|
|
24158
24196
|
id,
|
|
@@ -24189,6 +24227,7 @@ async function* encodeAnthropicSse(events, options = {}) {
|
|
|
24189
24227
|
let messageStopped = false;
|
|
24190
24228
|
let sawToolUse = false;
|
|
24191
24229
|
let activeContentKey;
|
|
24230
|
+
const reasoningBlobs = /* @__PURE__ */ new Map();
|
|
24192
24231
|
const encode3 = (event, data) => encoder2.encode(`event: ${event}
|
|
24193
24232
|
data: ${JSON.stringify(data)}
|
|
24194
24233
|
|
|
@@ -24222,7 +24261,9 @@ data: ${JSON.stringify(data)}
|
|
|
24222
24261
|
...block.kind === "thinking" ? [encode3("content_block_delta", {
|
|
24223
24262
|
type: "content_block_delta",
|
|
24224
24263
|
index: block.index,
|
|
24225
|
-
|
|
24264
|
+
// The blob is only known once the reasoning item closes, which is why the signature
|
|
24265
|
+
// is emitted here at block close rather than at block start.
|
|
24266
|
+
delta: { type: "signature_delta", signature: reasoningBlobs.get(key) ?? `gateway_${key}` }
|
|
24226
24267
|
})] : [],
|
|
24227
24268
|
encode3("content_block_stop", {
|
|
24228
24269
|
type: "content_block_stop",
|
|
@@ -24348,6 +24389,19 @@ data: ${JSON.stringify(data)}
|
|
|
24348
24389
|
break;
|
|
24349
24390
|
}
|
|
24350
24391
|
case "response.output_item.done":
|
|
24392
|
+
if (event.item.type === "reasoning") {
|
|
24393
|
+
if (event.item.encrypted_content !== void 0) {
|
|
24394
|
+
const key = reasoningBlockKey(event.item.id);
|
|
24395
|
+
reasoningBlobs.set(key, encodeReasoningSignature(event.item.id, event.item.encrypted_content));
|
|
24396
|
+
if (!blocks2.has(key)) {
|
|
24397
|
+
yield* closeActiveContent();
|
|
24398
|
+
const start = startContentBlock(key, "thinking");
|
|
24399
|
+
if (start !== void 0) yield start;
|
|
24400
|
+
}
|
|
24401
|
+
yield* closeBlock(key);
|
|
24402
|
+
}
|
|
24403
|
+
break;
|
|
24404
|
+
}
|
|
24351
24405
|
if (event.item.type === "function_call") {
|
|
24352
24406
|
let block = blocks2.get(event.item.id);
|
|
24353
24407
|
if (block === void 0) {
|
|
@@ -24952,6 +25006,13 @@ var OpenAIResponsesAdapter = class {
|
|
|
24952
25006
|
"idleTimeoutMs"
|
|
24953
25007
|
);
|
|
24954
25008
|
}
|
|
25009
|
+
/**
|
|
25010
|
+
* Headers a subclass derives from the request itself, merged over the constructor's.
|
|
25011
|
+
* The base Platform API surface derives none.
|
|
25012
|
+
*/
|
|
25013
|
+
perRequestHeaders(_request) {
|
|
25014
|
+
return {};
|
|
25015
|
+
}
|
|
24955
25016
|
async stream(request, options) {
|
|
24956
25017
|
if (options.apiKey.length === 0) {
|
|
24957
25018
|
throw new TypeError("apiKey must not be empty");
|
|
@@ -24968,7 +25029,8 @@ var OpenAIResponsesAdapter = class {
|
|
|
24968
25029
|
accept: "text/event-stream",
|
|
24969
25030
|
authorization: `Bearer ${options.apiKey}`,
|
|
24970
25031
|
"content-type": "application/json",
|
|
24971
|
-
...this.extraHeaders
|
|
25032
|
+
...this.extraHeaders,
|
|
25033
|
+
...this.perRequestHeaders(request)
|
|
24972
25034
|
},
|
|
24973
25035
|
body: JSON.stringify(payload),
|
|
24974
25036
|
signal: controller.signal
|
|
@@ -25029,6 +25091,10 @@ var CodexResponsesAdapter = class extends OpenAIResponsesAdapter {
|
|
|
25029
25091
|
});
|
|
25030
25092
|
this.isMarkedFetchFailure = fetchFailureTracker.isMarkedFailure;
|
|
25031
25093
|
}
|
|
25094
|
+
perRequestHeaders(request) {
|
|
25095
|
+
const sessionId = codexSessionIdentity(request);
|
|
25096
|
+
return sessionId === void 0 ? {} : { session_id: sessionId };
|
|
25097
|
+
}
|
|
25032
25098
|
async stream(request, options) {
|
|
25033
25099
|
const callController = new AbortController();
|
|
25034
25100
|
const unlinkCallAbort = linkAbortSignal(options.signal, callController);
|
|
@@ -25308,11 +25374,27 @@ function forOpenAIResponsesBackend(request, dropSamplingParams) {
|
|
|
25308
25374
|
}
|
|
25309
25375
|
return payload;
|
|
25310
25376
|
}
|
|
25377
|
+
function codexSessionIdentity(request) {
|
|
25378
|
+
const userId = request.metadata?.user_id?.trim();
|
|
25379
|
+
if (!userId) return void 0;
|
|
25380
|
+
const digest = createHash("sha256").update("fleet:codex:claude-session:").update(userId).digest("hex");
|
|
25381
|
+
return [
|
|
25382
|
+
digest.slice(0, 8),
|
|
25383
|
+
digest.slice(8, 12),
|
|
25384
|
+
digest.slice(12, 16),
|
|
25385
|
+
digest.slice(16, 20),
|
|
25386
|
+
digest.slice(20, 32)
|
|
25387
|
+
].join("-");
|
|
25388
|
+
}
|
|
25311
25389
|
function forChatGptBackend(request) {
|
|
25312
25390
|
const copy = { ...request };
|
|
25313
25391
|
for (const field of CHATGPT_UNSUPPORTED_FIELDS) {
|
|
25314
25392
|
delete copy[field];
|
|
25315
25393
|
}
|
|
25394
|
+
const sessionId = codexSessionIdentity(request);
|
|
25395
|
+
if (sessionId !== void 0) {
|
|
25396
|
+
copy.prompt_cache_key = sessionId;
|
|
25397
|
+
}
|
|
25316
25398
|
if (request.tool_choice === "none" || isClaudeCodeSuggestionMode(request)) {
|
|
25317
25399
|
delete copy.tools;
|
|
25318
25400
|
delete copy.tool_choice;
|
|
@@ -28191,10 +28273,10 @@ function createQuotaService(deps) {
|
|
|
28191
28273
|
if (id === "claude" && !await deps.isClaudeConnected() || id === "cursor" && !await deps.isCursorConnected()) {
|
|
28192
28274
|
return { status: "not_connected", method: (deps.platform ?? process.platform) === "darwin" ? "keychain" : "file" };
|
|
28193
28275
|
}
|
|
28194
|
-
const
|
|
28195
|
-
if (!force &&
|
|
28196
|
-
const staleStillValid =
|
|
28197
|
-
if (staleStillValid) return
|
|
28276
|
+
const cached22 = cache.get(id);
|
|
28277
|
+
if (!force && cached22 && cached22.expiresAt > now()) {
|
|
28278
|
+
const staleStillValid = cached22.value.status !== "stale" || typeof cached22.value.fetchedAt === "number" && now() - cached22.value.fetchedAt <= STALE_TTL_MS;
|
|
28279
|
+
if (staleStillValid) return cached22.value;
|
|
28198
28280
|
cache.delete(id);
|
|
28199
28281
|
}
|
|
28200
28282
|
const pending = inFlight.get(id);
|
|
@@ -28246,25 +28328,150 @@ function createQuotaService(deps) {
|
|
|
28246
28328
|
}
|
|
28247
28329
|
};
|
|
28248
28330
|
}
|
|
28331
|
+
var XAI_CLI_FALLBACK_CLIENT_VERSION = "1.0.5";
|
|
28332
|
+
var VERSION_PATTERN = /\b(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\b/;
|
|
28333
|
+
var VERSION_EXEC_TIMEOUT_MS = 2e3;
|
|
28334
|
+
var MAX_VERSION_FILE_BYTES = 256;
|
|
28335
|
+
function grokHomeDir(deps) {
|
|
28336
|
+
return optionalTrimmedString(deps.env.GROK_HOME) ?? path32__default.join(deps.homedir(), ".grok");
|
|
28337
|
+
}
|
|
28338
|
+
function versionFrom(value) {
|
|
28339
|
+
if (typeof value !== "string") return void 0;
|
|
28340
|
+
return VERSION_PATTERN.exec(value)?.[1];
|
|
28341
|
+
}
|
|
28342
|
+
async function fromInstallerSymlink(home, readLink) {
|
|
28343
|
+
try {
|
|
28344
|
+
return versionFrom(path32__default.basename(await readLink(path32__default.join(home, "bin", "grok"))));
|
|
28345
|
+
} catch {
|
|
28346
|
+
return void 0;
|
|
28347
|
+
}
|
|
28348
|
+
}
|
|
28349
|
+
async function fromMetadataMarker(home, deps) {
|
|
28350
|
+
try {
|
|
28351
|
+
return versionFrom(await deps.readBounded(path32__default.join(home, ".metadata_version"), MAX_VERSION_FILE_BYTES));
|
|
28352
|
+
} catch {
|
|
28353
|
+
return void 0;
|
|
28354
|
+
}
|
|
28355
|
+
}
|
|
28356
|
+
function grokExecutablePath(home, deps) {
|
|
28357
|
+
return path32__default.join(home, "bin", deps.platform === "win32" ? "grok.exe" : "grok");
|
|
28358
|
+
}
|
|
28359
|
+
async function fromCommand(deps, file2) {
|
|
28360
|
+
try {
|
|
28361
|
+
return versionFrom(await deps.execFile(file2, ["--version"], { timeout: VERSION_EXEC_TIMEOUT_MS }));
|
|
28362
|
+
} catch {
|
|
28363
|
+
return void 0;
|
|
28364
|
+
}
|
|
28365
|
+
}
|
|
28366
|
+
async function resolveXaiCliClientVersion(options = {}) {
|
|
28367
|
+
const deps = options.deps ?? defaultCredentialDeps;
|
|
28368
|
+
const readLink = options.readLink ?? ((filePath) => fs22.readlink(filePath));
|
|
28369
|
+
const override = versionFrom(optionalTrimmedString(deps.env.FLEET_XAI_CLI_VERSION));
|
|
28370
|
+
if (override) return override;
|
|
28371
|
+
const home = grokHomeDir(deps);
|
|
28372
|
+
return await fromInstallerSymlink(home, readLink) ?? await fromMetadataMarker(home, deps) ?? await fromCommand(deps, grokExecutablePath(home, deps)) ?? await fromCommand(deps, "grok") ?? XAI_CLI_FALLBACK_CLIENT_VERSION;
|
|
28373
|
+
}
|
|
28374
|
+
var cached2;
|
|
28375
|
+
function xaiCliClientVersion(options = {}) {
|
|
28376
|
+
cached2 ??= resolveXaiCliClientVersion(options).catch(() => XAI_CLI_FALLBACK_CLIENT_VERSION);
|
|
28377
|
+
return cached2;
|
|
28378
|
+
}
|
|
28379
|
+
var XAI_ENDPOINT_PREFERENCES = ["direct", "cli-proxy"];
|
|
28380
|
+
var DEFAULT_XAI_ENDPOINT_PREFERENCE = "cli-proxy";
|
|
28381
|
+
function sanitizeXaiEndpoint(value) {
|
|
28382
|
+
return typeof value === "string" && XAI_ENDPOINT_PREFERENCES.includes(value) ? value : void 0;
|
|
28383
|
+
}
|
|
28384
|
+
function normalizeAiGatewaySettings(value) {
|
|
28385
|
+
if (!isRecord7(value) || value.version !== 1) return { version: 1 };
|
|
28386
|
+
const models = Array.isArray(value.models) ? value.models.filter((entry) => isRecord7(entry) && typeof entry.id === "string" && entry.id.length > 0).flatMap((entry) => {
|
|
28387
|
+
const model = findGatewayModel(entry.id);
|
|
28388
|
+
if (!model) return [];
|
|
28389
|
+
const efforts = Array.isArray(entry.efforts) ? entry.efforts.filter((level) => typeof level === "string" && level.length > 0) : [];
|
|
28390
|
+
const exposed = efforts.length > 0 ? narrowEffortLadder(model, efforts) : void 0;
|
|
28391
|
+
return [{
|
|
28392
|
+
id: entry.id,
|
|
28393
|
+
...exposed ? { efforts: [...exposed] } : {},
|
|
28394
|
+
...entry.hostOnly === true ? { hostOnly: true } : {}
|
|
28395
|
+
}];
|
|
28396
|
+
}) : [];
|
|
28397
|
+
const providerPriority = sanitizeProviderPriority(value.providerPriority);
|
|
28398
|
+
const compactCeiling = normalizeCompactCeiling(value.compactCeiling);
|
|
28399
|
+
const xaiEndpoint = sanitizeXaiEndpoint(value.xaiEndpoint);
|
|
28400
|
+
return {
|
|
28401
|
+
version: 1,
|
|
28402
|
+
...models.length > 0 ? { models } : {},
|
|
28403
|
+
...value.cursorDiagnosticsEnabled === true ? { cursorDiagnosticsEnabled: true } : {},
|
|
28404
|
+
...typeof value.wireLogEnabled === "boolean" ? { wireLogEnabled: value.wireLogEnabled } : {},
|
|
28405
|
+
...providerPriority ? { providerPriority: [...providerPriority] } : {},
|
|
28406
|
+
...compactCeiling !== void 0 ? { compactCeiling } : {},
|
|
28407
|
+
...xaiEndpoint !== void 0 ? { xaiEndpoint } : {}
|
|
28408
|
+
};
|
|
28409
|
+
}
|
|
28410
|
+
function sanitizeProviderPriority(value) {
|
|
28411
|
+
if (!Array.isArray(value)) return void 0;
|
|
28412
|
+
const seen = /* @__PURE__ */ new Set();
|
|
28413
|
+
const cleaned = [];
|
|
28414
|
+
for (const entry of value) {
|
|
28415
|
+
if (typeof entry !== "string") continue;
|
|
28416
|
+
if (!GATEWAY_PROVIDERS.includes(entry)) continue;
|
|
28417
|
+
const provider = entry;
|
|
28418
|
+
if (seen.has(provider)) continue;
|
|
28419
|
+
seen.add(provider);
|
|
28420
|
+
cleaned.push(provider);
|
|
28421
|
+
}
|
|
28422
|
+
return cleaned.length > 0 ? cleaned : void 0;
|
|
28423
|
+
}
|
|
28424
|
+
function isRecord7(value) {
|
|
28425
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28426
|
+
}
|
|
28427
|
+
function resolveAiGatewaySelection(settings2) {
|
|
28428
|
+
const enabled = [];
|
|
28429
|
+
const hostOnlyIds = /* @__PURE__ */ new Set();
|
|
28430
|
+
const effortExposure = {};
|
|
28431
|
+
for (const entry of settings2?.models ?? []) {
|
|
28432
|
+
const model = findGatewayModel(entry.id);
|
|
28433
|
+
if (!model) continue;
|
|
28434
|
+
if (entry.hostOnly === true) hostOnlyIds.add(model.id);
|
|
28435
|
+
if (enabled.includes(model)) continue;
|
|
28436
|
+
enabled.push(model);
|
|
28437
|
+
const exposed = narrowEffortLadder(model, entry.efforts);
|
|
28438
|
+
if (exposed) effortExposure[model.id] = exposed;
|
|
28439
|
+
}
|
|
28440
|
+
const models = sortGatewayModelsByProvider(enabled);
|
|
28441
|
+
const delegationModels = models.filter((model) => !hostOnlyIds.has(model.id));
|
|
28442
|
+
return { models, delegationModels, effortExposure, providerPriority: settings2?.providerPriority };
|
|
28443
|
+
}
|
|
28444
|
+
function narrowEffortLadder(model, efforts) {
|
|
28445
|
+
if (!efforts || efforts.length === 0) return void 0;
|
|
28446
|
+
const ladder = buildGatewayModelConstraints(model).effortLadder;
|
|
28447
|
+
const narrowed = ladder.filter((rung) => efforts.includes(rung));
|
|
28448
|
+
if (narrowed.length === 0 || narrowed.length === ladder.length) return void 0;
|
|
28449
|
+
return narrowed;
|
|
28450
|
+
}
|
|
28451
|
+
function sortGatewayModelsByProvider(models) {
|
|
28452
|
+
return [...models].sort((left, right) => {
|
|
28453
|
+
const providerDelta = GATEWAY_PROVIDERS.indexOf(left.provider) - GATEWAY_PROVIDERS.indexOf(right.provider);
|
|
28454
|
+
if (providerDelta !== 0) return providerDelta;
|
|
28455
|
+
return GATEWAY_MODELS.indexOf(left) - GATEWAY_MODELS.indexOf(right);
|
|
28456
|
+
});
|
|
28457
|
+
}
|
|
28249
28458
|
var XAI_RESPONSES_URL = "https://api.x.ai/v1/responses";
|
|
28250
28459
|
var XAI_CLI_RESPONSES_URL = "https://cli-chat-proxy.grok.com/v1/responses";
|
|
28251
|
-
var XAI_CLI_CLIENT_VERSION = "1.0.3";
|
|
28252
|
-
var XAI_PROXY_FALLBACK_STATUSES = /* @__PURE__ */ new Set([402, 426]);
|
|
28253
28460
|
var DEFAULT_XAI_RESPONSES_MAX_UPSTREAM_BODY_BYTES = 64 * 1024 * 1024;
|
|
28254
28461
|
var DEFAULT_XAI_RESPONSES_UPSTREAM_IDLE_TIMEOUT_MS = 3e4;
|
|
28255
28462
|
var DEFAULT_XAI_RESPONSES_FUNCTION_CALL_TIMEOUT_MS = 3e4;
|
|
28256
28463
|
var DEFAULT_XAI_RESPONSES_SEMANTIC_STALL_TIMEOUT_MS = 6e4;
|
|
28257
28464
|
var XAI_RETRY_DELAY_MS = 200;
|
|
28258
|
-
var
|
|
28465
|
+
var XAI_REASONING_INCLUDE = "reasoning.encrypted_content";
|
|
28259
28466
|
function directXaiEndpoint() {
|
|
28260
28467
|
return { url: XAI_RESPONSES_URL, headers: {} };
|
|
28261
28468
|
}
|
|
28262
|
-
function proxyXaiEndpoint(model) {
|
|
28469
|
+
function proxyXaiEndpoint(model, clientVersion) {
|
|
28263
28470
|
return {
|
|
28264
28471
|
url: XAI_CLI_RESPONSES_URL,
|
|
28265
28472
|
headers: {
|
|
28266
28473
|
"x-xai-token-auth": "xai-grok-cli",
|
|
28267
|
-
"x-grok-client-version":
|
|
28474
|
+
"x-grok-client-version": clientVersion,
|
|
28268
28475
|
"x-grok-model-override": model
|
|
28269
28476
|
}
|
|
28270
28477
|
};
|
|
@@ -28277,6 +28484,8 @@ var XaiResponsesAdapter = class {
|
|
|
28277
28484
|
idleTimeoutMs;
|
|
28278
28485
|
functionCallTimeoutMs;
|
|
28279
28486
|
semanticStallTimeoutMs;
|
|
28487
|
+
endpointPreference;
|
|
28488
|
+
clientVersion;
|
|
28280
28489
|
extraHeaders;
|
|
28281
28490
|
constructor(options = {}) {
|
|
28282
28491
|
this.extraHeaders = options.headers ?? {};
|
|
@@ -28299,6 +28508,8 @@ var XaiResponsesAdapter = class {
|
|
|
28299
28508
|
options.semanticStallTimeoutMs ?? DEFAULT_XAI_RESPONSES_SEMANTIC_STALL_TIMEOUT_MS,
|
|
28300
28509
|
"semanticStallTimeoutMs"
|
|
28301
28510
|
);
|
|
28511
|
+
this.endpointPreference = options.endpoint ?? DEFAULT_XAI_ENDPOINT_PREFERENCE;
|
|
28512
|
+
this.clientVersion = options.clientVersion ?? (() => xaiCliClientVersion());
|
|
28302
28513
|
}
|
|
28303
28514
|
async stream(request, options) {
|
|
28304
28515
|
if (options.apiKey.length === 0) {
|
|
@@ -28306,22 +28517,14 @@ var XaiResponsesAdapter = class {
|
|
|
28306
28517
|
}
|
|
28307
28518
|
const controller = new AbortController();
|
|
28308
28519
|
const unlinkAbort = linkAbortSignal(options.signal, controller);
|
|
28309
|
-
const
|
|
28520
|
+
const tools = xaiWireTools(request);
|
|
28521
|
+
let payload = forXaiResponsesBackend(request, tools);
|
|
28522
|
+
let replayAvailable = replaysXaiReasoning(request);
|
|
28310
28523
|
let retryAvailable = true;
|
|
28311
28524
|
let response;
|
|
28312
|
-
|
|
28525
|
+
const endpoint = this.endpointPreference === "cli-proxy" ? await this.proxyEndpoint(payload.model) : directXaiEndpoint();
|
|
28313
28526
|
try {
|
|
28314
28527
|
response = await this.fetchResponse(options.apiKey, payload, controller, endpoint);
|
|
28315
|
-
if (!response.ok && endpoint.url === XAI_RESPONSES_URL && XAI_PROXY_FALLBACK_STATUSES.has(response.status)) {
|
|
28316
|
-
wireLog("xai-responses.endpoint.fallback", {
|
|
28317
|
-
status: response.status,
|
|
28318
|
-
from: XAI_RESPONSES_URL,
|
|
28319
|
-
to: XAI_CLI_RESPONSES_URL
|
|
28320
|
-
});
|
|
28321
|
-
xaiProxyOnlyAccount = true;
|
|
28322
|
-
endpoint = proxyXaiEndpoint(payload.model);
|
|
28323
|
-
response = await this.fetchResponse(options.apiKey, payload, controller, endpoint);
|
|
28324
|
-
}
|
|
28325
28528
|
} catch (error51) {
|
|
28326
28529
|
if (!isRetryableXaiFetchSocket(error51, controller.signal, this.isMarkedFetchFailure)) {
|
|
28327
28530
|
unlinkAbort();
|
|
@@ -28344,17 +28547,40 @@ var XaiResponsesAdapter = class {
|
|
|
28344
28547
|
unlinkAbort();
|
|
28345
28548
|
return response;
|
|
28346
28549
|
}
|
|
28347
|
-
|
|
28348
|
-
|
|
28349
|
-
|
|
28550
|
+
const reopen = async (signal, reason) => {
|
|
28551
|
+
if (reason === "empty_stream" && replayAvailable) {
|
|
28552
|
+
replayAvailable = false;
|
|
28553
|
+
payload = forXaiResponsesBackend(request, tools, false);
|
|
28554
|
+
wireLog("xai-responses.reasoning.replay_dropped", { reason });
|
|
28350
28555
|
await abortableXaiDelay(XAI_RETRY_DELAY_MS, signal);
|
|
28351
|
-
const
|
|
28352
|
-
if (!
|
|
28353
|
-
throw new UpstreamProtocolError(`xAI retry failed with status ${
|
|
28556
|
+
const withoutReplay = await this.fetchResponse(options.apiKey, payload, controller, endpoint);
|
|
28557
|
+
if (!withoutReplay.ok) {
|
|
28558
|
+
throw new UpstreamProtocolError(`xAI retry failed with status ${withoutReplay.status}`);
|
|
28354
28559
|
}
|
|
28355
|
-
return
|
|
28356
|
-
}
|
|
28560
|
+
return withoutReplay.events;
|
|
28561
|
+
}
|
|
28562
|
+
await abortableXaiDelay(XAI_RETRY_DELAY_MS, signal);
|
|
28563
|
+
const retried = await this.fetchResponse(options.apiKey, payload, controller, endpoint);
|
|
28564
|
+
if (!retried.ok) {
|
|
28565
|
+
throw new UpstreamProtocolError(`xAI retry failed with status ${retried.status}`);
|
|
28566
|
+
}
|
|
28567
|
+
return retried.events;
|
|
28357
28568
|
};
|
|
28569
|
+
return {
|
|
28570
|
+
...response,
|
|
28571
|
+
events: retryXaiEvents(
|
|
28572
|
+
response.events,
|
|
28573
|
+
reopen,
|
|
28574
|
+
controller,
|
|
28575
|
+
unlinkAbort,
|
|
28576
|
+
retryAvailable,
|
|
28577
|
+
() => replayAvailable
|
|
28578
|
+
)
|
|
28579
|
+
};
|
|
28580
|
+
}
|
|
28581
|
+
/** The proxy endpoint, with the installed CLI's version resolved for its gate. */
|
|
28582
|
+
async proxyEndpoint(model) {
|
|
28583
|
+
return proxyXaiEndpoint(model, await this.clientVersion());
|
|
28358
28584
|
}
|
|
28359
28585
|
async fetchResponse(apiKey, payload, controller, endpoint) {
|
|
28360
28586
|
wireLog("xai-responses.wire.request", { url: endpoint.url, payload });
|
|
@@ -28405,21 +28631,43 @@ var XaiResponsesAdapter = class {
|
|
|
28405
28631
|
return xaiWireTools(request) ?? [];
|
|
28406
28632
|
}
|
|
28407
28633
|
};
|
|
28408
|
-
function forXaiResponsesBackend(request, tools = xaiWireTools(request)) {
|
|
28634
|
+
function forXaiResponsesBackend(request, tools = xaiWireTools(request), replayReasoning = true) {
|
|
28409
28635
|
const { metadata: _metadata, native_tools: _nativeTools, ...rest } = request;
|
|
28636
|
+
const input = [];
|
|
28637
|
+
for (const item of request.input) {
|
|
28638
|
+
if (item.type === "function_call_output") {
|
|
28639
|
+
const { is_error: _isError, tool_references: _toolReferences, ...wireItem2 } = item;
|
|
28640
|
+
input.push(wireItem2);
|
|
28641
|
+
continue;
|
|
28642
|
+
}
|
|
28643
|
+
const {
|
|
28644
|
+
reasoning_content: _reasoningContent,
|
|
28645
|
+
reasoning_encrypted: encrypted,
|
|
28646
|
+
reasoning_id: reasoningId,
|
|
28647
|
+
...wireItem
|
|
28648
|
+
} = item;
|
|
28649
|
+
if (replayReasoning && encrypted !== void 0 && encrypted.length > 0) {
|
|
28650
|
+
input.push({
|
|
28651
|
+
type: "reasoning",
|
|
28652
|
+
...reasoningId === void 0 ? {} : { id: reasoningId },
|
|
28653
|
+
summary: [],
|
|
28654
|
+
encrypted_content: encrypted
|
|
28655
|
+
});
|
|
28656
|
+
}
|
|
28657
|
+
input.push(wireItem);
|
|
28658
|
+
}
|
|
28410
28659
|
return {
|
|
28411
28660
|
...rest,
|
|
28412
|
-
input
|
|
28413
|
-
|
|
28414
|
-
|
|
28415
|
-
|
|
28416
|
-
}
|
|
28417
|
-
const { reasoning_content: _reasoningContent, ...wireItem } = item;
|
|
28418
|
-
return wireItem;
|
|
28419
|
-
}),
|
|
28661
|
+
input,
|
|
28662
|
+
// Only asked for when a reply could carry one: on a turn that replays nothing the include
|
|
28663
|
+
// is inert, and on a retry that dropped the replay it must not invite a fresh blob back.
|
|
28664
|
+
...replayReasoning ? { include: [XAI_REASONING_INCLUDE] } : {},
|
|
28420
28665
|
...tools === void 0 ? {} : { tools: [...tools] }
|
|
28421
28666
|
};
|
|
28422
28667
|
}
|
|
28668
|
+
function replaysXaiReasoning(request) {
|
|
28669
|
+
return request.input.some((item) => item.type !== "function_call_output" && typeof item.reasoning_encrypted === "string" && item.reasoning_encrypted.length > 0);
|
|
28670
|
+
}
|
|
28423
28671
|
function xaiWireTools(request) {
|
|
28424
28672
|
if (request.tools === void 0) return void 0;
|
|
28425
28673
|
const tools = request.tools;
|
|
@@ -28440,11 +28688,18 @@ function isToolSearchName(name) {
|
|
|
28440
28688
|
function toolNameMatches(declaredName, selectedName) {
|
|
28441
28689
|
return declaredName === selectedName || toolLeafName(declaredName) === toolLeafName(selectedName);
|
|
28442
28690
|
}
|
|
28443
|
-
function retryXaiEvents(events, retry, controller, unlinkAbort, retryAvailable) {
|
|
28691
|
+
function retryXaiEvents(events, retry, controller, unlinkAbort, retryAvailable, replayAvailable) {
|
|
28444
28692
|
return {
|
|
28445
28693
|
[Symbol.asyncIterator]() {
|
|
28446
28694
|
const source = events[Symbol.asyncIterator]();
|
|
28447
|
-
const iterator = generateXaiRetryEvents(
|
|
28695
|
+
const iterator = generateXaiRetryEvents(
|
|
28696
|
+
source,
|
|
28697
|
+
retry,
|
|
28698
|
+
controller,
|
|
28699
|
+
unlinkAbort,
|
|
28700
|
+
retryAvailable,
|
|
28701
|
+
replayAvailable
|
|
28702
|
+
);
|
|
28448
28703
|
return {
|
|
28449
28704
|
next: () => iterator.next(),
|
|
28450
28705
|
return: async () => {
|
|
@@ -28459,7 +28714,7 @@ function retryXaiEvents(events, retry, controller, unlinkAbort, retryAvailable)
|
|
|
28459
28714
|
}
|
|
28460
28715
|
};
|
|
28461
28716
|
}
|
|
28462
|
-
async function* generateXaiRetryEvents(source, retry, controller, unlinkAbort, retryAvailable) {
|
|
28717
|
+
async function* generateXaiRetryEvents(source, retry, controller, unlinkAbort, retryAvailable, replayAvailable) {
|
|
28463
28718
|
const lead = [];
|
|
28464
28719
|
let committed = false;
|
|
28465
28720
|
let normalCompletion = false;
|
|
@@ -28483,14 +28738,26 @@ async function* generateXaiRetryEvents(source, retry, controller, unlinkAbort, r
|
|
|
28483
28738
|
});
|
|
28484
28739
|
await source.return?.();
|
|
28485
28740
|
lead.length = 0;
|
|
28486
|
-
yield* await retry(controller.signal);
|
|
28741
|
+
yield* await retry(controller.signal, "retryable_failure");
|
|
28487
28742
|
return;
|
|
28488
28743
|
}
|
|
28489
28744
|
if (result.done) {
|
|
28490
|
-
yield* lead;
|
|
28491
28745
|
if (pendingError !== void 0) {
|
|
28492
|
-
|
|
28746
|
+
wireLog("xai-responses.retry.discarded", {
|
|
28747
|
+
reason: "error_stream_end",
|
|
28748
|
+
errorTypes: [pendingError.error.type]
|
|
28749
|
+
});
|
|
28750
|
+
lead.length = 0;
|
|
28751
|
+
yield* await retry(controller.signal, "retryable_failure");
|
|
28752
|
+
return;
|
|
28753
|
+
}
|
|
28754
|
+
if (!committed && replayAvailable()) {
|
|
28755
|
+
wireLog("xai-responses.retry.discarded", { reason: "empty_stream" });
|
|
28756
|
+
lead.length = 0;
|
|
28757
|
+
yield* await retry(controller.signal, "empty_stream");
|
|
28758
|
+
return;
|
|
28493
28759
|
}
|
|
28760
|
+
yield* lead;
|
|
28494
28761
|
normalCompletion = true;
|
|
28495
28762
|
return;
|
|
28496
28763
|
}
|
|
@@ -28501,7 +28768,7 @@ async function* generateXaiRetryEvents(source, retry, controller, unlinkAbort, r
|
|
|
28501
28768
|
wireLog("xai-responses.retry.discarded", pendingError === void 0 ? { reason: "response.failed", errorTypes } : { reason: "error_failed_pair", errorTypes });
|
|
28502
28769
|
await source.return?.();
|
|
28503
28770
|
lead.length = 0;
|
|
28504
|
-
yield* await retry(controller.signal);
|
|
28771
|
+
yield* await retry(controller.signal, "retryable_failure");
|
|
28505
28772
|
return;
|
|
28506
28773
|
}
|
|
28507
28774
|
pendingError = event;
|
|
@@ -28535,7 +28802,7 @@ function isRetryableXaiFailure(event) {
|
|
|
28535
28802
|
return event.type === "response.failed" && isRetryableXaiErrorType(event.response.error.type) || event.type === "error" && isRetryableXaiErrorType(event.error.type);
|
|
28536
28803
|
}
|
|
28537
28804
|
function isRetryableXaiErrorType(type) {
|
|
28538
|
-
return type === "server_error" || type === "server_is_overloaded" || type === "service_unavailable_error";
|
|
28805
|
+
return type === "server_error" || type === "server_is_overloaded" || type === "service_unavailable_error" || type === XAI_OVERLOADED_ERROR_TYPE;
|
|
28539
28806
|
}
|
|
28540
28807
|
function commitsXaiOutput(event) {
|
|
28541
28808
|
if (event.type === "response.created" || event.type === "response.reasoning_summary_text.delta") {
|
|
@@ -28840,7 +29107,7 @@ function parseEventFrame3(frame) {
|
|
|
28840
29107
|
);
|
|
28841
29108
|
}
|
|
28842
29109
|
logRawWireEvent("xai-responses.wire.event", eventName, parsed);
|
|
28843
|
-
if (
|
|
29110
|
+
if (isRecord8(parsed) && typeof parsed.type !== "string" && eventName !== void 0) {
|
|
28844
29111
|
parsed = { ...parsed, type: eventName };
|
|
28845
29112
|
}
|
|
28846
29113
|
return canonicalEvent3(parsed);
|
|
@@ -28850,7 +29117,7 @@ function withoutXaiSentinel(text) {
|
|
|
28850
29117
|
return text.includes(XAI_EOS_SENTINEL) ? text.split(XAI_EOS_SENTINEL).join("") : text;
|
|
28851
29118
|
}
|
|
28852
29119
|
function canonicalEvent3(value) {
|
|
28853
|
-
if (!
|
|
29120
|
+
if (!isRecord8(value) || typeof value.type !== "string") {
|
|
28854
29121
|
throw new UpstreamProtocolError("Grok CLI SSE event was not an object with a type");
|
|
28855
29122
|
}
|
|
28856
29123
|
switch (value.type) {
|
|
@@ -28995,19 +29262,34 @@ function outputItem3(value) {
|
|
|
28995
29262
|
arguments: typeof item.arguments === "string" ? item.arguments : ""
|
|
28996
29263
|
};
|
|
28997
29264
|
}
|
|
29265
|
+
if (item.type === "reasoning") {
|
|
29266
|
+
const encrypted = typeof item.encrypted_content === "string" && item.encrypted_content.length > 0 ? item.encrypted_content : void 0;
|
|
29267
|
+
if (encrypted === void 0) return void 0;
|
|
29268
|
+
return {
|
|
29269
|
+
id: typeof item.id === "string" ? item.id : "",
|
|
29270
|
+
type: "reasoning",
|
|
29271
|
+
encrypted_content: encrypted
|
|
29272
|
+
};
|
|
29273
|
+
}
|
|
28998
29274
|
return void 0;
|
|
28999
29275
|
}
|
|
29276
|
+
var XAI_OVERLOADED_ERROR_TYPE = "overloaded_error";
|
|
29277
|
+
var XAI_CAPACITY_MESSAGE = /\bat capacity\b|\boverloaded\b/i;
|
|
29000
29278
|
function canonicalError3(value) {
|
|
29001
29279
|
const error51 = record3(value, "error");
|
|
29002
29280
|
const message = string32(error51.message, "error.message");
|
|
29003
|
-
|
|
29004
|
-
return { type, message };
|
|
29281
|
+
return { type: xaiErrorType(error51, message), message };
|
|
29005
29282
|
}
|
|
29006
|
-
function
|
|
29283
|
+
function xaiErrorType(error51, message) {
|
|
29284
|
+
if (typeof error51.type === "string" && error51.type !== "error") return error51.type;
|
|
29285
|
+
if (typeof error51.code === "string") return error51.code;
|
|
29286
|
+
return XAI_CAPACITY_MESSAGE.test(message) ? XAI_OVERLOADED_ERROR_TYPE : "api_error";
|
|
29287
|
+
}
|
|
29288
|
+
function isRecord8(value) {
|
|
29007
29289
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29008
29290
|
}
|
|
29009
29291
|
function record3(value, name) {
|
|
29010
|
-
if (!
|
|
29292
|
+
if (!isRecord8(value)) {
|
|
29011
29293
|
throw new UpstreamProtocolError(`${name} must be an object`);
|
|
29012
29294
|
}
|
|
29013
29295
|
return value;
|
|
@@ -29079,38 +29361,38 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29079
29361
|
"shell_command",
|
|
29080
29362
|
"exec_command"
|
|
29081
29363
|
]);
|
|
29082
|
-
if (
|
|
29364
|
+
if (isRecord9(exec2.readArgs)) {
|
|
29083
29365
|
return [execReply(exec2, "readResult", {
|
|
29084
29366
|
error: { path: stringValue(exec2.readArgs.path), error: readMessage3 }
|
|
29085
29367
|
})];
|
|
29086
29368
|
}
|
|
29087
|
-
if (
|
|
29369
|
+
if (isRecord9(exec2.writeArgs)) {
|
|
29088
29370
|
return [execReply(exec2, "writeResult", {
|
|
29089
29371
|
rejected: { path: stringValue(exec2.writeArgs.path), reason: mutationMessage }
|
|
29090
29372
|
})];
|
|
29091
29373
|
}
|
|
29092
|
-
if (
|
|
29374
|
+
if (isRecord9(exec2.deleteArgs)) {
|
|
29093
29375
|
return [execReply(exec2, "deleteResult", {
|
|
29094
29376
|
rejected: { path: stringValue(exec2.deleteArgs.path), reason: mutationMessage }
|
|
29095
29377
|
})];
|
|
29096
29378
|
}
|
|
29097
|
-
if (
|
|
29379
|
+
if (isRecord9(exec2.lsArgs)) {
|
|
29098
29380
|
return [execReply(exec2, "lsResult", {
|
|
29099
29381
|
error: { path: stringValue(exec2.lsArgs.path), error: listMessage }
|
|
29100
29382
|
})];
|
|
29101
29383
|
}
|
|
29102
|
-
if (
|
|
29384
|
+
if (isRecord9(exec2.grepArgs)) {
|
|
29103
29385
|
return [execReply(exec2, "grepResult", { error: { error: grepMessage } })];
|
|
29104
29386
|
}
|
|
29105
|
-
if (
|
|
29387
|
+
if (isRecord9(exec2.shellArgs)) {
|
|
29106
29388
|
return [execReply(exec2, "shellResult", shellFailure(exec2.shellArgs, shellMessage))];
|
|
29107
29389
|
}
|
|
29108
|
-
if (
|
|
29390
|
+
if (isRecord9(exec2.shellStreamArgs)) {
|
|
29109
29391
|
const args = exec2.shellStreamArgs;
|
|
29110
29392
|
const cwd = stringValue(args.workingDirectory);
|
|
29111
29393
|
return [
|
|
29112
29394
|
execReply(exec2, "shellStream", {
|
|
29113
|
-
start:
|
|
29395
|
+
start: isRecord9(args.requestedSandboxPolicy) ? { sandboxPolicy: args.requestedSandboxPolicy } : {}
|
|
29114
29396
|
}),
|
|
29115
29397
|
execReply(exec2, "shellStream", { stderr: { data: shellMessage } }),
|
|
29116
29398
|
execReply(exec2, "shellStream", { exit: { code: 1, cwd, aborted: true } }),
|
|
@@ -29118,7 +29400,7 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29118
29400
|
{ execClientControlMessage: { streamClose: { id: numberValue(exec2.id) } } }
|
|
29119
29401
|
];
|
|
29120
29402
|
}
|
|
29121
|
-
if (
|
|
29403
|
+
if (isRecord9(exec2.backgroundShellSpawnArgs)) {
|
|
29122
29404
|
const args = exec2.backgroundShellSpawnArgs;
|
|
29123
29405
|
return [execReply(exec2, "backgroundShellSpawnResult", {
|
|
29124
29406
|
error: {
|
|
@@ -29128,15 +29410,15 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29128
29410
|
}
|
|
29129
29411
|
})];
|
|
29130
29412
|
}
|
|
29131
|
-
if (
|
|
29413
|
+
if (isRecord9(exec2.writeShellStdinArgs)) {
|
|
29132
29414
|
return [execReply(exec2, "writeShellStdinResult", { error: { error: shellMessage } })];
|
|
29133
29415
|
}
|
|
29134
|
-
if (
|
|
29416
|
+
if (isRecord9(exec2.fetchArgs)) {
|
|
29135
29417
|
return [execReply(exec2, "fetchResult", {
|
|
29136
29418
|
error: { url: stringValue(exec2.fetchArgs.url), error: networkMessage }
|
|
29137
29419
|
})];
|
|
29138
29420
|
}
|
|
29139
|
-
if (
|
|
29421
|
+
if (isRecord9(exec2.diagnosticsArgs)) {
|
|
29140
29422
|
return [execReply(exec2, "diagnosticsResult", {
|
|
29141
29423
|
error: {
|
|
29142
29424
|
path: stringValue(exec2.diagnosticsArgs.path),
|
|
@@ -29144,12 +29426,12 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29144
29426
|
}
|
|
29145
29427
|
})];
|
|
29146
29428
|
}
|
|
29147
|
-
if (
|
|
29429
|
+
if (isRecord9(exec2.listMcpResourcesExecArgs)) {
|
|
29148
29430
|
return [execReply(exec2, "listMcpResourcesExecResult", {
|
|
29149
29431
|
error: { error: retryMessage(clientTools, ["ListMcpResources", "list_mcp_resources"]) }
|
|
29150
29432
|
})];
|
|
29151
29433
|
}
|
|
29152
|
-
if (
|
|
29434
|
+
if (isRecord9(exec2.readMcpResourceExecArgs)) {
|
|
29153
29435
|
return [execReply(exec2, "readMcpResourceExecResult", {
|
|
29154
29436
|
error: {
|
|
29155
29437
|
uri: stringValue(exec2.readMcpResourceExecArgs.uri),
|
|
@@ -29157,12 +29439,12 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29157
29439
|
}
|
|
29158
29440
|
})];
|
|
29159
29441
|
}
|
|
29160
|
-
if (
|
|
29442
|
+
if (isRecord9(exec2.recordScreenArgs)) {
|
|
29161
29443
|
return [execReply(exec2, "recordScreenResult", {
|
|
29162
29444
|
failure: { error: retryMessage(clientTools, ["record_screen", "computer_use"]) }
|
|
29163
29445
|
})];
|
|
29164
29446
|
}
|
|
29165
|
-
if (
|
|
29447
|
+
if (isRecord9(exec2.computerUseArgs)) {
|
|
29166
29448
|
return [execReply(exec2, "computerUseResult", {
|
|
29167
29449
|
error: {
|
|
29168
29450
|
error: retryMessage(clientTools, ["computer_use"]),
|
|
@@ -29172,7 +29454,7 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
29172
29454
|
}
|
|
29173
29455
|
})];
|
|
29174
29456
|
}
|
|
29175
|
-
if (
|
|
29457
|
+
if (isRecord9(exec2.mcpArgs)) {
|
|
29176
29458
|
return [execReply(exec2, "mcpResult", {
|
|
29177
29459
|
error: { error: retryMessage(clientTools, []) }
|
|
29178
29460
|
})];
|
|
@@ -29244,7 +29526,7 @@ function numberValue(value) {
|
|
|
29244
29526
|
function stringValue(value) {
|
|
29245
29527
|
return typeof value === "string" ? value : "";
|
|
29246
29528
|
}
|
|
29247
|
-
function
|
|
29529
|
+
function isRecord9(value) {
|
|
29248
29530
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29249
29531
|
}
|
|
29250
29532
|
var EXECUTE_HOOK_FIELD_NUMBER = 27;
|
|
@@ -29400,14 +29682,14 @@ function isCursorWithheldToolName(name) {
|
|
|
29400
29682
|
function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
29401
29683
|
const messageId = numberValue2(exec2.id ?? 0);
|
|
29402
29684
|
const execId = stringValue2(exec2.execId) || `redirect-${messageId}`;
|
|
29403
|
-
if (
|
|
29404
|
-
const
|
|
29405
|
-
if (!
|
|
29685
|
+
if (isRecord10(exec2.readArgs)) {
|
|
29686
|
+
const path82 = stringValue2(exec2.readArgs.path);
|
|
29687
|
+
if (!path82) return null;
|
|
29406
29688
|
if ([exec2.readArgs.offset, exec2.readArgs.limit].some((value) => typeof value === "number" && value < 0)) return null;
|
|
29407
29689
|
const offset = positiveNumber(exec2.readArgs.offset);
|
|
29408
29690
|
const limit = positiveNumber(exec2.readArgs.limit);
|
|
29409
29691
|
if (offset !== void 0 || limit !== void 0) return null;
|
|
29410
|
-
const mapped = tools.filter((tool) => matchesLeaf(tool, READ_CANDIDATES)).map((tool) => ({ tool, args: readArguments(tool.inputSchemaValue,
|
|
29692
|
+
const mapped = tools.filter((tool) => matchesLeaf(tool, READ_CANDIDATES)).map((tool) => ({ tool, args: readArguments(tool.inputSchemaValue, path82) })).find((candidate) => candidate.args !== null);
|
|
29411
29693
|
if (!mapped?.args) return null;
|
|
29412
29694
|
return redirect(
|
|
29413
29695
|
exec2,
|
|
@@ -29419,14 +29701,14 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
29419
29701
|
"readResult",
|
|
29420
29702
|
"read-direct",
|
|
29421
29703
|
mapped.args,
|
|
29422
|
-
{ path:
|
|
29704
|
+
{ path: path82 }
|
|
29423
29705
|
);
|
|
29424
29706
|
}
|
|
29425
|
-
if (
|
|
29707
|
+
if (isRecord10(exec2.grepArgs)) {
|
|
29426
29708
|
const grepArgs = exec2.grepArgs;
|
|
29427
29709
|
const pattern = stringValue2(grepArgs.pattern);
|
|
29428
29710
|
if (!pattern.trim()) return null;
|
|
29429
|
-
const
|
|
29711
|
+
const path82 = stringValue2(grepArgs.path) || ".";
|
|
29430
29712
|
const glob = stringValue2(grepArgs.glob);
|
|
29431
29713
|
const outputMode = normalizedGrepOutputMode(stringValue2(grepArgs.outputMode));
|
|
29432
29714
|
if (!outputMode) return null;
|
|
@@ -29442,7 +29724,7 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
29442
29724
|
if (numericOptions.some((value) => typeof value === "number" && value < 0)) return null;
|
|
29443
29725
|
const mappingInput = {
|
|
29444
29726
|
pattern,
|
|
29445
|
-
path:
|
|
29727
|
+
path: path82,
|
|
29446
29728
|
glob,
|
|
29447
29729
|
outputMode,
|
|
29448
29730
|
caseInsensitive: grepArgs.caseInsensitive === true,
|
|
@@ -29459,7 +29741,7 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
29459
29741
|
const mapped = tools.filter((tool) => matchesLeaf(tool, GREP_CANDIDATES)).map((tool) => ({ tool, args: grepArguments(tool, mappingInput) })).find((candidate) => candidate.args !== null);
|
|
29460
29742
|
const nativeArgs = {
|
|
29461
29743
|
pattern,
|
|
29462
|
-
path:
|
|
29744
|
+
path: path82,
|
|
29463
29745
|
outputMode,
|
|
29464
29746
|
...glob ? { glob } : {},
|
|
29465
29747
|
...positiveNumber(grepArgs.offset) === void 0 ? {} : { offset: String(positiveNumber(grepArgs.offset)) }
|
|
@@ -29496,15 +29778,15 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
29496
29778
|
nativeArgs
|
|
29497
29779
|
);
|
|
29498
29780
|
}
|
|
29499
|
-
if (
|
|
29500
|
-
const argsRecord =
|
|
29781
|
+
if (isRecord10(exec2.shellArgs) || isRecord10(exec2.shellStreamArgs)) {
|
|
29782
|
+
const argsRecord = isRecord10(exec2.shellArgs) ? exec2.shellArgs : exec2.shellStreamArgs;
|
|
29501
29783
|
const command2 = stringValue2(argsRecord.command);
|
|
29502
29784
|
if (!command2) return null;
|
|
29503
29785
|
const cwd = stringValue2(argsRecord.workingDirectory);
|
|
29504
29786
|
const timeout = positiveNumber(argsRecord.timeout) ?? positiveNumber(argsRecord.hardTimeout);
|
|
29505
29787
|
const mapped = tools.filter((tool) => matchesLeaf(tool, SHELL_CANDIDATES)).map((tool) => ({ tool, args: shellArguments(tool.inputSchemaValue, command2, cwd || void 0, timeout) })).find((candidate) => candidate.args !== null);
|
|
29506
29788
|
if (!mapped?.args) return null;
|
|
29507
|
-
const stream =
|
|
29789
|
+
const stream = isRecord10(exec2.shellStreamArgs);
|
|
29508
29790
|
return redirect(
|
|
29509
29791
|
exec2,
|
|
29510
29792
|
mapped.tool,
|
|
@@ -29594,9 +29876,9 @@ function cursorNativeRedirectErrorReplies(correlation, error51) {
|
|
|
29594
29876
|
}
|
|
29595
29877
|
}
|
|
29596
29878
|
}
|
|
29597
|
-
function readArguments(schema,
|
|
29879
|
+
function readArguments(schema, path82) {
|
|
29598
29880
|
const pathKey = firstSchemaProperty(schema, ["file_path", "path"]);
|
|
29599
|
-
return pathKey ? { [pathKey]:
|
|
29881
|
+
return pathKey ? { [pathKey]: path82 } : null;
|
|
29600
29882
|
}
|
|
29601
29883
|
function grepArguments(tool, input) {
|
|
29602
29884
|
const leaf = normalizedLeaf(tool.clientName);
|
|
@@ -29763,7 +30045,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
29763
30045
|
const decoded = JSON.parse(inflateRawSync(compressed, {
|
|
29764
30046
|
maxOutputLength: CURSOR_GREP_RECEIPT_MAX_BYTES
|
|
29765
30047
|
}).toString("utf8"));
|
|
29766
|
-
if (!
|
|
30048
|
+
if (!isRecord10(decoded)) throw new Error("receipt is not an object");
|
|
29767
30049
|
if (decoded.ok === false && typeof decoded.error === "string") {
|
|
29768
30050
|
return { ok: false, error: decoded.error };
|
|
29769
30051
|
}
|
|
@@ -29776,7 +30058,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
29776
30058
|
if (!Array.isArray(decoded.counts) || !decoded.counts.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "number" && Number.isSafeInteger(entry[1]) && entry[1] >= 0)) {
|
|
29777
30059
|
throw new Error("receipt counts are invalid");
|
|
29778
30060
|
}
|
|
29779
|
-
if (!Array.isArray(decoded.matches) || !decoded.matches.every((entry) =>
|
|
30061
|
+
if (!Array.isArray(decoded.matches) || !decoded.matches.every((entry) => isRecord10(entry) && typeof entry.file === "string" && typeof entry.lineNumber === "number" && Number.isSafeInteger(entry.lineNumber) && entry.lineNumber > 0 && typeof entry.content === "string" && typeof entry.contentTruncated === "boolean" && typeof entry.isContextLine === "boolean")) {
|
|
29780
30062
|
throw new Error("receipt matches are invalid");
|
|
29781
30063
|
}
|
|
29782
30064
|
for (const key of ["totalFiles", "totalLines", "totalMatchedLines"]) {
|
|
@@ -29794,7 +30076,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
29794
30076
|
}
|
|
29795
30077
|
}
|
|
29796
30078
|
function buildGrepReceiptSuccess(args, receipt) {
|
|
29797
|
-
const
|
|
30079
|
+
const path82 = args.path || ".";
|
|
29798
30080
|
let result;
|
|
29799
30081
|
if (receipt.outputMode === "files_with_matches") {
|
|
29800
30082
|
result = {
|
|
@@ -29840,15 +30122,15 @@ function buildGrepReceiptSuccess(args, receipt) {
|
|
|
29840
30122
|
}
|
|
29841
30123
|
return {
|
|
29842
30124
|
pattern: args.pattern ?? "",
|
|
29843
|
-
path:
|
|
30125
|
+
path: path82,
|
|
29844
30126
|
outputMode: receipt.outputMode,
|
|
29845
|
-
workspaceResults: { [
|
|
30127
|
+
workspaceResults: { [path82]: result }
|
|
29846
30128
|
};
|
|
29847
30129
|
}
|
|
29848
30130
|
function buildGrepSuccess(args, output) {
|
|
29849
30131
|
const outputMode = normalizedGrepOutputMode(args.outputMode) ?? "content";
|
|
29850
30132
|
const lines = output.split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.length > 0 && !line.startsWith("[") && !/^no matches/i.test(line));
|
|
29851
|
-
const
|
|
30133
|
+
const path82 = args.path || ".";
|
|
29852
30134
|
let result;
|
|
29853
30135
|
if (outputMode === "files_with_matches") {
|
|
29854
30136
|
result = {
|
|
@@ -29911,9 +30193,9 @@ function buildGrepSuccess(args, output) {
|
|
|
29911
30193
|
}
|
|
29912
30194
|
return {
|
|
29913
30195
|
pattern: args.pattern ?? "",
|
|
29914
|
-
path:
|
|
30196
|
+
path: path82,
|
|
29915
30197
|
outputMode,
|
|
29916
|
-
workspaceResults: { [
|
|
30198
|
+
workspaceResults: { [path82]: result }
|
|
29917
30199
|
};
|
|
29918
30200
|
}
|
|
29919
30201
|
function parseCallerShellOutput(output, isError) {
|
|
@@ -29975,7 +30257,7 @@ function redirect(exec2, tool, providerIdentifier, messageId, execId, execCase,
|
|
|
29975
30257
|
}
|
|
29976
30258
|
function execArgsToolCallId(exec2) {
|
|
29977
30259
|
for (const value of Object.values(exec2)) {
|
|
29978
|
-
if (!
|
|
30260
|
+
if (!isRecord10(value)) continue;
|
|
29979
30261
|
const toolCallId = stringValue2(value.toolCallId);
|
|
29980
30262
|
if (toolCallId) return toolCallId;
|
|
29981
30263
|
}
|
|
@@ -29996,7 +30278,7 @@ function firstSchemaProperty(schema, candidates) {
|
|
|
29996
30278
|
return candidates.find((candidate) => schemaHasProperty(schema, candidate));
|
|
29997
30279
|
}
|
|
29998
30280
|
function schemaHasProperty(schema, name) {
|
|
29999
|
-
return
|
|
30281
|
+
return isRecord10(schema.properties) && Object.prototype.hasOwnProperty.call(schema.properties, name);
|
|
30000
30282
|
}
|
|
30001
30283
|
function execReply2(exec2, resultName, result) {
|
|
30002
30284
|
return {
|
|
@@ -30023,7 +30305,7 @@ function positiveNumber(value) {
|
|
|
30023
30305
|
function stringValue2(value) {
|
|
30024
30306
|
return typeof value === "string" ? value : "";
|
|
30025
30307
|
}
|
|
30026
|
-
function
|
|
30308
|
+
function isRecord10(value) {
|
|
30027
30309
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30028
30310
|
}
|
|
30029
30311
|
var cursorAgentDescriptor = [
|
|
@@ -30854,18 +31136,18 @@ function decodeCursorServerMessage(payload) {
|
|
|
30854
31136
|
const message = fromBinary(AgentServerMessageSchema, payload);
|
|
30855
31137
|
const unknownExecFields = extractCursorUnknownExecFields(message);
|
|
30856
31138
|
const json3 = toJson(AgentServerMessageSchema, message);
|
|
30857
|
-
if (!
|
|
31139
|
+
if (!isRecord11(json3)) throw new TypeError("Cursor server frame was not a message object");
|
|
30858
31140
|
if (unknownExecFields.length > 0) {
|
|
30859
31141
|
Object.defineProperty(json3, CURSOR_UNKNOWN_EXEC_FIELDS, { value: unknownExecFields });
|
|
30860
31142
|
}
|
|
30861
31143
|
return json3;
|
|
30862
31144
|
}
|
|
30863
31145
|
function extractCursorUnknownExecFields(message) {
|
|
30864
|
-
if (!
|
|
30865
|
-
if (message.message.case !== "execServerMessage" || !
|
|
31146
|
+
if (!isRecord11(message) || !isRecord11(message.message)) return [];
|
|
31147
|
+
if (message.message.case !== "execServerMessage" || !isRecord11(message.message.value)) return [];
|
|
30866
31148
|
const fields = message.message.value.$unknown;
|
|
30867
31149
|
if (!Array.isArray(fields)) return [];
|
|
30868
|
-
return fields.filter((field) =>
|
|
31150
|
+
return fields.filter((field) => isRecord11(field) && typeof field.no === "number" && typeof field.wireType === "number" && field.data instanceof Uint8Array);
|
|
30869
31151
|
}
|
|
30870
31152
|
function parseConnectEndStreamError(payload) {
|
|
30871
31153
|
try {
|
|
@@ -31187,7 +31469,7 @@ function cursorToolArgumentBytes(argumentsText) {
|
|
|
31187
31469
|
} catch {
|
|
31188
31470
|
return {};
|
|
31189
31471
|
}
|
|
31190
|
-
if (!
|
|
31472
|
+
if (!isRecord11(parsed)) return {};
|
|
31191
31473
|
return Object.fromEntries(Object.entries(parsed).map(([name, value]) => [
|
|
31192
31474
|
name,
|
|
31193
31475
|
Buffer.from(toBinary(ValueSchema, fromJson(ValueSchema, value))).toString("base64")
|
|
@@ -32472,7 +32754,7 @@ ${argumentsText}`;
|
|
|
32472
32754
|
const handleFrame = (frame, replayed = false) => {
|
|
32473
32755
|
const unknownExecFields = frame[CURSOR_UNKNOWN_EXEC_FIELDS] ?? [];
|
|
32474
32756
|
lastFrame = describeCursorServerFrame(frame, unknownExecFields);
|
|
32475
|
-
const tokenDetails =
|
|
32757
|
+
const tokenDetails = isRecord11(frame.conversationCheckpointUpdate) && isRecord11(frame.conversationCheckpointUpdate.tokenDetails) ? frame.conversationCheckpointUpdate.tokenDetails : void 0;
|
|
32476
32758
|
const checkpointContextTokens = positiveTokenCount(tokenDetails?.usedTokens);
|
|
32477
32759
|
const checkpointContextWindow = positiveTokenCount(tokenDetails?.maxTokens);
|
|
32478
32760
|
if (!replayed) {
|
|
@@ -32485,7 +32767,7 @@ ${argumentsText}`;
|
|
|
32485
32767
|
...checkpointContextWindow === void 0 ? {} : { contextWindow: checkpointContextWindow }
|
|
32486
32768
|
});
|
|
32487
32769
|
}
|
|
32488
|
-
if (
|
|
32770
|
+
if (isRecord11(frame.conversationCheckpointUpdate)) {
|
|
32489
32771
|
if (checkpointContextTokens !== void 0) {
|
|
32490
32772
|
wireLog("cursor.wire.checkpoint", {
|
|
32491
32773
|
model: diagnosticModel,
|
|
@@ -32508,7 +32790,7 @@ ${argumentsText}`;
|
|
|
32508
32790
|
}
|
|
32509
32791
|
return;
|
|
32510
32792
|
}
|
|
32511
|
-
if (
|
|
32793
|
+
if (isRecord11(frame.kvServerMessage)) {
|
|
32512
32794
|
const kv = kvReply(frame.kvServerMessage, blobs);
|
|
32513
32795
|
stream.write(encodeCursorClientMessage(kv.message));
|
|
32514
32796
|
if (kv.fetch) {
|
|
@@ -32529,7 +32811,7 @@ ${argumentsText}`;
|
|
|
32529
32811
|
});
|
|
32530
32812
|
return;
|
|
32531
32813
|
}
|
|
32532
|
-
if (
|
|
32814
|
+
if (isRecord11(frame.interactionQuery)) {
|
|
32533
32815
|
const reply = cursorInteractionQueryReply(frame.interactionQuery);
|
|
32534
32816
|
stream.write(encodeCursorClientMessage(reply.message));
|
|
32535
32817
|
report("client.reply", { model: diagnosticModel, reply: reply.replyKind });
|
|
@@ -32545,7 +32827,7 @@ ${argumentsText}`;
|
|
|
32545
32827
|
}
|
|
32546
32828
|
return;
|
|
32547
32829
|
}
|
|
32548
|
-
if (
|
|
32830
|
+
if (isRecord11(frame.error)) {
|
|
32549
32831
|
if (state === "attached") {
|
|
32550
32832
|
emit({ type: "error", error: cursorError(frame.error) });
|
|
32551
32833
|
completeRun("server_error");
|
|
@@ -32574,8 +32856,8 @@ ${argumentsText}`;
|
|
|
32574
32856
|
return;
|
|
32575
32857
|
}
|
|
32576
32858
|
if (state !== "attached") return;
|
|
32577
|
-
if (
|
|
32578
|
-
if (
|
|
32859
|
+
if (isRecord11(frame.execServerMessage)) {
|
|
32860
|
+
if (isRecord11(frame.execServerMessage.requestContextArgs)) {
|
|
32579
32861
|
stream.write(encodeCursorClientMessage(cursorRequestContextReply(frame.execServerMessage, tools)));
|
|
32580
32862
|
report("client.reply", { model: diagnosticModel, reply: "exec.requestContext" });
|
|
32581
32863
|
return;
|
|
@@ -32664,10 +32946,10 @@ ${argumentsText}`;
|
|
|
32664
32946
|
}
|
|
32665
32947
|
return;
|
|
32666
32948
|
}
|
|
32667
|
-
const update =
|
|
32949
|
+
const update = isRecord11(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
32668
32950
|
if (update === void 0) return;
|
|
32669
32951
|
if (isSettledToolUpdate(update)) return;
|
|
32670
|
-
if (
|
|
32952
|
+
if (isRecord11(update.textDelta) && typeof update.textDelta.text === "string") {
|
|
32671
32953
|
activeSegment.outputText += update.textDelta.text;
|
|
32672
32954
|
emit({
|
|
32673
32955
|
type: "response.output_text.delta",
|
|
@@ -32678,7 +32960,7 @@ ${argumentsText}`;
|
|
|
32678
32960
|
});
|
|
32679
32961
|
return;
|
|
32680
32962
|
}
|
|
32681
|
-
if (
|
|
32963
|
+
if (isRecord11(update.thinkingDelta) && typeof update.thinkingDelta.text === "string") {
|
|
32682
32964
|
activeSegment.outputText += update.thinkingDelta.text;
|
|
32683
32965
|
emit({
|
|
32684
32966
|
type: "response.reasoning_summary_text.delta",
|
|
@@ -32688,12 +32970,12 @@ ${argumentsText}`;
|
|
|
32688
32970
|
});
|
|
32689
32971
|
return;
|
|
32690
32972
|
}
|
|
32691
|
-
if (
|
|
32973
|
+
if (isRecord11(update.tokenDelta)) {
|
|
32692
32974
|
const tokens = positiveTokenCount(update.tokenDelta.tokens);
|
|
32693
32975
|
if (tokens !== void 0) activeSegment.contextOutputTokens += tokens;
|
|
32694
32976
|
return;
|
|
32695
32977
|
}
|
|
32696
|
-
if (
|
|
32978
|
+
if (isRecord11(update.toolCallStarted)) {
|
|
32697
32979
|
const wireCall = mcpCallFromToolUpdate(update.toolCallStarted);
|
|
32698
32980
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
32699
32981
|
if (call) {
|
|
@@ -32703,7 +32985,7 @@ ${argumentsText}`;
|
|
|
32703
32985
|
}
|
|
32704
32986
|
return;
|
|
32705
32987
|
}
|
|
32706
|
-
if (
|
|
32988
|
+
if (isRecord11(update.partialToolCall)) {
|
|
32707
32989
|
const wireCall = mcpCallFromToolUpdate(update.partialToolCall);
|
|
32708
32990
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
32709
32991
|
if (!call) return;
|
|
@@ -32714,7 +32996,7 @@ ${argumentsText}`;
|
|
|
32714
32996
|
rescheduleToolTurnFinish();
|
|
32715
32997
|
return;
|
|
32716
32998
|
}
|
|
32717
|
-
if (
|
|
32999
|
+
if (isRecord11(update.toolCallCompleted)) {
|
|
32718
33000
|
const wireCall = mcpCallFromToolUpdate(update.toolCallCompleted);
|
|
32719
33001
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
32720
33002
|
if (!call) return;
|
|
@@ -32727,7 +33009,7 @@ ${argumentsText}`;
|
|
|
32727
33009
|
rescheduleToolTurnFinish();
|
|
32728
33010
|
return;
|
|
32729
33011
|
}
|
|
32730
|
-
if (
|
|
33012
|
+
if (isRecord11(update.turnEnded)) completeRun("turn_ended");
|
|
32731
33013
|
};
|
|
32732
33014
|
const eventsFor = (segment) => (async function* () {
|
|
32733
33015
|
try {
|
|
@@ -32938,34 +33220,34 @@ var CURSOR_INTERACTION_QUERY_CASES = [
|
|
|
32938
33220
|
];
|
|
32939
33221
|
var CURSOR_KV_CASES = ["getBlobArgs", "setBlobArgs"];
|
|
32940
33222
|
function describeCursorServerFrame(frame, unknownExecFields = []) {
|
|
32941
|
-
if (
|
|
33223
|
+
if (isRecord11(frame.interactionUpdate)) {
|
|
32942
33224
|
return `interactionUpdate.${cursorNestedRecordCase(
|
|
32943
33225
|
frame.interactionUpdate,
|
|
32944
33226
|
CURSOR_INTERACTION_UPDATE_CASES
|
|
32945
33227
|
)}`;
|
|
32946
33228
|
}
|
|
32947
|
-
if (
|
|
33229
|
+
if (isRecord11(frame.execServerMessage)) {
|
|
32948
33230
|
const knownCase = cursorNestedRecordCase(frame.execServerMessage, CURSOR_EXEC_CASES);
|
|
32949
33231
|
return `execServerMessage.${knownCase === "unknown" ? cursorUnknownExecCaseName(unknownExecFields) : knownCase}`;
|
|
32950
33232
|
}
|
|
32951
|
-
if (
|
|
33233
|
+
if (isRecord11(frame.interactionQuery)) {
|
|
32952
33234
|
return `interactionQuery.${cursorNestedRecordCase(
|
|
32953
33235
|
frame.interactionQuery,
|
|
32954
33236
|
CURSOR_INTERACTION_QUERY_CASES
|
|
32955
33237
|
)}`;
|
|
32956
33238
|
}
|
|
32957
|
-
if (
|
|
33239
|
+
if (isRecord11(frame.kvServerMessage)) {
|
|
32958
33240
|
return `kvServerMessage.${cursorNestedRecordCase(frame.kvServerMessage, CURSOR_KV_CASES)}`;
|
|
32959
33241
|
}
|
|
32960
|
-
if (
|
|
32961
|
-
if (
|
|
33242
|
+
if (isRecord11(frame.conversationCheckpointUpdate)) return "conversationCheckpointUpdate";
|
|
33243
|
+
if (isRecord11(frame.error)) return "error";
|
|
32962
33244
|
return "unknown";
|
|
32963
33245
|
}
|
|
32964
33246
|
function isCursorHeartbeatFrame(frame) {
|
|
32965
|
-
return
|
|
33247
|
+
return isRecord11(frame.interactionUpdate) && isRecord11(frame.interactionUpdate.heartbeat);
|
|
32966
33248
|
}
|
|
32967
33249
|
function cursorNestedRecordCase(value, cases) {
|
|
32968
|
-
return cases.find((candidate) =>
|
|
33250
|
+
return cases.find((candidate) => isRecord11(value[candidate])) ?? "unknown";
|
|
32969
33251
|
}
|
|
32970
33252
|
function positiveTokenCount(value) {
|
|
32971
33253
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) return void 0;
|
|
@@ -32977,8 +33259,8 @@ function cursorInteractionQueryReply(query) {
|
|
|
32977
33259
|
const response = (result = {}) => ({
|
|
32978
33260
|
interactionResponse: { id, ...result }
|
|
32979
33261
|
});
|
|
32980
|
-
if (
|
|
32981
|
-
const args =
|
|
33262
|
+
if (isRecord11(query.createPlanRequestQuery)) {
|
|
33263
|
+
const args = isRecord11(query.createPlanRequestQuery.args) ? query.createPlanRequestQuery.args : void 0;
|
|
32982
33264
|
const name = stringValue3(args?.name)?.trim();
|
|
32983
33265
|
const overview = stringValue3(args?.overview)?.trim();
|
|
32984
33266
|
const plan = stringValue3(args?.plan)?.trim();
|
|
@@ -32994,7 +33276,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
32994
33276
|
` } : {}
|
|
32995
33277
|
};
|
|
32996
33278
|
}
|
|
32997
|
-
if (
|
|
33279
|
+
if (isRecord11(query.askQuestionInteractionQuery)) {
|
|
32998
33280
|
return {
|
|
32999
33281
|
message: response({
|
|
33000
33282
|
askQuestionInteractionResponse: {
|
|
@@ -33004,7 +33286,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
33004
33286
|
replyKind: "interaction.askQuestion.rejected"
|
|
33005
33287
|
};
|
|
33006
33288
|
}
|
|
33007
|
-
if (
|
|
33289
|
+
if (isRecord11(query.switchModeRequestQuery)) {
|
|
33008
33290
|
return {
|
|
33009
33291
|
message: response({
|
|
33010
33292
|
switchModeRequestResponse: {
|
|
@@ -33014,19 +33296,19 @@ function cursorInteractionQueryReply(query) {
|
|
|
33014
33296
|
replyKind: "interaction.switchMode.rejected"
|
|
33015
33297
|
};
|
|
33016
33298
|
}
|
|
33017
|
-
if (
|
|
33299
|
+
if (isRecord11(query.webSearchRequestQuery)) {
|
|
33018
33300
|
return {
|
|
33019
33301
|
message: response({ webSearchRequestResponse: { approved: {} } }),
|
|
33020
33302
|
replyKind: "interaction.webSearch.approved"
|
|
33021
33303
|
};
|
|
33022
33304
|
}
|
|
33023
|
-
if (
|
|
33305
|
+
if (isRecord11(query.exaSearchRequestQuery)) {
|
|
33024
33306
|
return {
|
|
33025
33307
|
message: response({ exaSearchRequestResponse: { approved: {} } }),
|
|
33026
33308
|
replyKind: "interaction.exaSearch.approved"
|
|
33027
33309
|
};
|
|
33028
33310
|
}
|
|
33029
|
-
if (
|
|
33311
|
+
if (isRecord11(query.exaFetchRequestQuery)) {
|
|
33030
33312
|
return {
|
|
33031
33313
|
message: response({ exaFetchRequestResponse: { approved: {} } }),
|
|
33032
33314
|
replyKind: "interaction.exaFetch.approved"
|
|
@@ -33036,7 +33318,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
33036
33318
|
}
|
|
33037
33319
|
function kvReply(kv, blobs) {
|
|
33038
33320
|
const id = kv.id ?? 0;
|
|
33039
|
-
if (
|
|
33321
|
+
if (isRecord11(kv.getBlobArgs)) {
|
|
33040
33322
|
const blobId = typeof kv.getBlobArgs.blobId === "string" ? kv.getBlobArgs.blobId : "";
|
|
33041
33323
|
const blobData = blobs.get(blobId);
|
|
33042
33324
|
return {
|
|
@@ -33048,7 +33330,7 @@ function kvReply(kv, blobs) {
|
|
|
33048
33330
|
}
|
|
33049
33331
|
};
|
|
33050
33332
|
}
|
|
33051
|
-
if (
|
|
33333
|
+
if (isRecord11(kv.setBlobArgs)) {
|
|
33052
33334
|
const blobId = typeof kv.setBlobArgs.blobId === "string" ? kv.setBlobArgs.blobId : "";
|
|
33053
33335
|
const blobData = typeof kv.setBlobArgs.blobData === "string" ? kv.setBlobArgs.blobData : "";
|
|
33054
33336
|
if (blobId) blobs.set(blobId, blobData);
|
|
@@ -33099,7 +33381,7 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
33099
33381
|
return { value: String(value), count: 1 };
|
|
33100
33382
|
}
|
|
33101
33383
|
if (Array.isArray(value)) {
|
|
33102
|
-
const itemSchema =
|
|
33384
|
+
const itemSchema = isRecord11(schema) ? schema.items : void 0;
|
|
33103
33385
|
if (itemSchema === void 0) return { value, count: 0 };
|
|
33104
33386
|
let repairedValues;
|
|
33105
33387
|
let count2 = 0;
|
|
@@ -33112,7 +33394,7 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
33112
33394
|
});
|
|
33113
33395
|
return { value: repairedValues ?? value, count: count2 };
|
|
33114
33396
|
}
|
|
33115
|
-
if (!
|
|
33397
|
+
if (!isRecord11(value) || !isRecord11(schema) || !isRecord11(schema.properties)) {
|
|
33116
33398
|
return { value, count: 0 };
|
|
33117
33399
|
}
|
|
33118
33400
|
let repairedValue;
|
|
@@ -33128,12 +33410,12 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
33128
33410
|
return { value: repairedValue ?? value, count };
|
|
33129
33411
|
}
|
|
33130
33412
|
function cursorSchemaRequiresString(schema) {
|
|
33131
|
-
if (!
|
|
33413
|
+
if (!isRecord11(schema)) return false;
|
|
33132
33414
|
if (schema.type === "string") return true;
|
|
33133
33415
|
return Array.isArray(schema.type) && schema.type.includes("string") && schema.type.every((type) => type === "string" || type === "null");
|
|
33134
33416
|
}
|
|
33135
33417
|
function mcpCallFromToolUpdate(value) {
|
|
33136
|
-
const toolCall =
|
|
33418
|
+
const toolCall = isRecord11(value.toolCall) ? value.toolCall : void 0;
|
|
33137
33419
|
const args = toolCall ? mcpArgsFromToolCall(toolCall) : void 0;
|
|
33138
33420
|
if (!args) return null;
|
|
33139
33421
|
const publicCallId = stringValue3(value.callId);
|
|
@@ -33158,7 +33440,7 @@ var CURSOR_TOOL_UPDATE_CASES = [
|
|
|
33158
33440
|
function cursorToolUpdateIdentifiers(update) {
|
|
33159
33441
|
for (const key of CURSOR_TOOL_UPDATE_CASES) {
|
|
33160
33442
|
const value = update[key];
|
|
33161
|
-
if (!
|
|
33443
|
+
if (!isRecord11(value)) continue;
|
|
33162
33444
|
const call = mcpCallFromToolUpdate(value);
|
|
33163
33445
|
if (!call) return [];
|
|
33164
33446
|
return [...new Set(
|
|
@@ -33168,9 +33450,9 @@ function cursorToolUpdateIdentifiers(update) {
|
|
|
33168
33450
|
return void 0;
|
|
33169
33451
|
}
|
|
33170
33452
|
function isCursorClientToolFrame(frame, tools, redirectTools) {
|
|
33171
|
-
const update =
|
|
33453
|
+
const update = isRecord11(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
33172
33454
|
if (update !== void 0) return cursorToolUpdateIdentifiers(update) !== void 0;
|
|
33173
|
-
const exec2 =
|
|
33455
|
+
const exec2 = isRecord11(frame.execServerMessage) ? frame.execServerMessage : void 0;
|
|
33174
33456
|
if (exec2 === void 0) return false;
|
|
33175
33457
|
const wireCall = mcpCallFromExecMessage(exec2);
|
|
33176
33458
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
@@ -33186,16 +33468,16 @@ function isCursorClientToolFrame(frame, tools, redirectTools) {
|
|
|
33186
33468
|
) !== null;
|
|
33187
33469
|
}
|
|
33188
33470
|
function isCursorParkedResidueFrame(frame, parked) {
|
|
33189
|
-
const update =
|
|
33471
|
+
const update = isRecord11(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
33190
33472
|
if (update === void 0) return false;
|
|
33191
|
-
if (
|
|
33473
|
+
if (isRecord11(update.tokenDelta)) return true;
|
|
33192
33474
|
const identifiers = cursorToolUpdateIdentifiers(update);
|
|
33193
33475
|
if (identifiers === void 0 || identifiers.length === 0 || parked === void 0) return false;
|
|
33194
33476
|
const sealed = new Set(parked.flatMap((call) => [call.callId, call.toolCallId]));
|
|
33195
33477
|
return identifiers.some((identifier) => sealed.has(identifier));
|
|
33196
33478
|
}
|
|
33197
33479
|
function mcpCallFromExecMessage(value) {
|
|
33198
|
-
const args =
|
|
33480
|
+
const args = isRecord11(value.mcpArgs) ? value.mcpArgs : void 0;
|
|
33199
33481
|
if (!args) return null;
|
|
33200
33482
|
const toolCallId = stringValue3(args.toolCallId);
|
|
33201
33483
|
if (!toolCallId) return null;
|
|
@@ -33213,14 +33495,14 @@ function mcpCallFromExecMessage(value) {
|
|
|
33213
33495
|
};
|
|
33214
33496
|
}
|
|
33215
33497
|
function mcpArgsFromToolCall(toolCall) {
|
|
33216
|
-
const direct =
|
|
33217
|
-
if (direct &&
|
|
33218
|
-
const tool =
|
|
33219
|
-
const nested = tool &&
|
|
33220
|
-
return nested &&
|
|
33498
|
+
const direct = isRecord11(toolCall.mcpToolCall) ? toolCall.mcpToolCall : void 0;
|
|
33499
|
+
if (direct && isRecord11(direct.args)) return direct.args;
|
|
33500
|
+
const tool = isRecord11(toolCall.tool) ? toolCall.tool : void 0;
|
|
33501
|
+
const nested = tool && isRecord11(tool.mcpToolCall) ? tool.mcpToolCall : void 0;
|
|
33502
|
+
return nested && isRecord11(nested.args) ? nested.args : void 0;
|
|
33221
33503
|
}
|
|
33222
33504
|
function cursorMcpArguments(args) {
|
|
33223
|
-
if (!
|
|
33505
|
+
if (!isRecord11(args.args) || Object.keys(args.args).length === 0) return {};
|
|
33224
33506
|
const decoded = {};
|
|
33225
33507
|
for (const [name, value] of Object.entries(args.args)) {
|
|
33226
33508
|
if (typeof value !== "string") {
|
|
@@ -33295,7 +33577,7 @@ function cursorError(value) {
|
|
|
33295
33577
|
message: typeof value.message === "string" ? value.message : "Cursor request failed"
|
|
33296
33578
|
};
|
|
33297
33579
|
}
|
|
33298
|
-
function
|
|
33580
|
+
function isRecord11(value) {
|
|
33299
33581
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33300
33582
|
}
|
|
33301
33583
|
var DEFAULT_CURSOR_DIAGNOSTIC_MAX_BYTES = 4 * 1024 * 1024;
|
|
@@ -33472,78 +33754,6 @@ function kimiAnthropicHeaders(requestHeaders, apiKey) {
|
|
|
33472
33754
|
}
|
|
33473
33755
|
return headers;
|
|
33474
33756
|
}
|
|
33475
|
-
function normalizeAiGatewaySettings(value) {
|
|
33476
|
-
if (!isRecord11(value) || value.version !== 1) return { version: 1 };
|
|
33477
|
-
const models = Array.isArray(value.models) ? value.models.filter((entry) => isRecord11(entry) && typeof entry.id === "string" && entry.id.length > 0).flatMap((entry) => {
|
|
33478
|
-
const model = findGatewayModel(entry.id);
|
|
33479
|
-
if (!model) return [];
|
|
33480
|
-
const efforts = Array.isArray(entry.efforts) ? entry.efforts.filter((level) => typeof level === "string" && level.length > 0) : [];
|
|
33481
|
-
const exposed = efforts.length > 0 ? narrowEffortLadder(model, efforts) : void 0;
|
|
33482
|
-
return [{
|
|
33483
|
-
id: entry.id,
|
|
33484
|
-
...exposed ? { efforts: [...exposed] } : {},
|
|
33485
|
-
...entry.hostOnly === true ? { hostOnly: true } : {}
|
|
33486
|
-
}];
|
|
33487
|
-
}) : [];
|
|
33488
|
-
const providerPriority = sanitizeProviderPriority(value.providerPriority);
|
|
33489
|
-
const compactCeiling = normalizeCompactCeiling(value.compactCeiling);
|
|
33490
|
-
return {
|
|
33491
|
-
version: 1,
|
|
33492
|
-
...models.length > 0 ? { models } : {},
|
|
33493
|
-
...value.cursorDiagnosticsEnabled === true ? { cursorDiagnosticsEnabled: true } : {},
|
|
33494
|
-
...typeof value.wireLogEnabled === "boolean" ? { wireLogEnabled: value.wireLogEnabled } : {},
|
|
33495
|
-
...providerPriority ? { providerPriority: [...providerPriority] } : {},
|
|
33496
|
-
...compactCeiling !== void 0 ? { compactCeiling } : {}
|
|
33497
|
-
};
|
|
33498
|
-
}
|
|
33499
|
-
function sanitizeProviderPriority(value) {
|
|
33500
|
-
if (!Array.isArray(value)) return void 0;
|
|
33501
|
-
const seen = /* @__PURE__ */ new Set();
|
|
33502
|
-
const cleaned = [];
|
|
33503
|
-
for (const entry of value) {
|
|
33504
|
-
if (typeof entry !== "string") continue;
|
|
33505
|
-
if (!GATEWAY_PROVIDERS.includes(entry)) continue;
|
|
33506
|
-
const provider = entry;
|
|
33507
|
-
if (seen.has(provider)) continue;
|
|
33508
|
-
seen.add(provider);
|
|
33509
|
-
cleaned.push(provider);
|
|
33510
|
-
}
|
|
33511
|
-
return cleaned.length > 0 ? cleaned : void 0;
|
|
33512
|
-
}
|
|
33513
|
-
function isRecord11(value) {
|
|
33514
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33515
|
-
}
|
|
33516
|
-
function resolveAiGatewaySelection(settings2) {
|
|
33517
|
-
const enabled = [];
|
|
33518
|
-
const hostOnlyIds = /* @__PURE__ */ new Set();
|
|
33519
|
-
const effortExposure = {};
|
|
33520
|
-
for (const entry of settings2?.models ?? []) {
|
|
33521
|
-
const model = findGatewayModel(entry.id);
|
|
33522
|
-
if (!model) continue;
|
|
33523
|
-
if (entry.hostOnly === true) hostOnlyIds.add(model.id);
|
|
33524
|
-
if (enabled.includes(model)) continue;
|
|
33525
|
-
enabled.push(model);
|
|
33526
|
-
const exposed = narrowEffortLadder(model, entry.efforts);
|
|
33527
|
-
if (exposed) effortExposure[model.id] = exposed;
|
|
33528
|
-
}
|
|
33529
|
-
const models = sortGatewayModelsByProvider(enabled);
|
|
33530
|
-
const delegationModels = models.filter((model) => !hostOnlyIds.has(model.id));
|
|
33531
|
-
return { models, delegationModels, effortExposure, providerPriority: settings2?.providerPriority };
|
|
33532
|
-
}
|
|
33533
|
-
function narrowEffortLadder(model, efforts) {
|
|
33534
|
-
if (!efforts || efforts.length === 0) return void 0;
|
|
33535
|
-
const ladder = buildGatewayModelConstraints(model).effortLadder;
|
|
33536
|
-
const narrowed = ladder.filter((rung) => efforts.includes(rung));
|
|
33537
|
-
if (narrowed.length === 0 || narrowed.length === ladder.length) return void 0;
|
|
33538
|
-
return narrowed;
|
|
33539
|
-
}
|
|
33540
|
-
function sortGatewayModelsByProvider(models) {
|
|
33541
|
-
return [...models].sort((left, right) => {
|
|
33542
|
-
const providerDelta = GATEWAY_PROVIDERS.indexOf(left.provider) - GATEWAY_PROVIDERS.indexOf(right.provider);
|
|
33543
|
-
if (providerDelta !== 0) return providerDelta;
|
|
33544
|
-
return GATEWAY_MODELS.indexOf(left) - GATEWAY_MODELS.indexOf(right);
|
|
33545
|
-
});
|
|
33546
|
-
}
|
|
33547
33757
|
var codexRequestPolicy = {
|
|
33548
33758
|
provider: "codex",
|
|
33549
33759
|
shapeRequest: (request, steps) => steps.withholdWebSearchTools(steps.pruneSkillPayloads(request))
|
|
@@ -33754,6 +33964,14 @@ function createAiGatewayRouter(deps) {
|
|
|
33754
33964
|
return false;
|
|
33755
33965
|
}
|
|
33756
33966
|
};
|
|
33967
|
+
const xaiEndpoint = () => {
|
|
33968
|
+
if (!deps.readAiGatewaySettings) return DEFAULT_XAI_ENDPOINT_PREFERENCE;
|
|
33969
|
+
try {
|
|
33970
|
+
return deps.readAiGatewaySettings().xaiEndpoint ?? DEFAULT_XAI_ENDPOINT_PREFERENCE;
|
|
33971
|
+
} catch {
|
|
33972
|
+
return DEFAULT_XAI_ENDPOINT_PREFERENCE;
|
|
33973
|
+
}
|
|
33974
|
+
};
|
|
33757
33975
|
const compactCeiling = () => {
|
|
33758
33976
|
try {
|
|
33759
33977
|
return gatewaySettings()?.compactCeiling;
|
|
@@ -33901,7 +34119,10 @@ function createAiGatewayRouter(deps) {
|
|
|
33901
34119
|
);
|
|
33902
34120
|
return true;
|
|
33903
34121
|
}
|
|
33904
|
-
const gateway = deps.gateway ?? (target2.provider === "cursor" ? ownedCursorGateway : target2.provider === "opencode" ? createOpencodeGateway(opencodeGoWire(target2)) : target2.provider === "xai" ? new AnthropicMessagesGateway(new XaiResponsesAdapter({
|
|
34122
|
+
const gateway = deps.gateway ?? (target2.provider === "cursor" ? ownedCursorGateway : target2.provider === "opencode" ? createOpencodeGateway(opencodeGoWire(target2)) : target2.provider === "xai" ? new AnthropicMessagesGateway(new XaiResponsesAdapter({
|
|
34123
|
+
fetch: fetchImpl,
|
|
34124
|
+
endpoint: xaiEndpoint()
|
|
34125
|
+
})) : createGatewayFor(target2, chatgptAccountId, deps.originator));
|
|
33905
34126
|
const diagnosticsEnabled = target2.provider === "cursor" ? cursorDiagnosticsEnabled() : void 0;
|
|
33906
34127
|
const modelContextWindow = typeof target2.contextWindow === "number" && Number.isFinite(target2.contextWindow) && target2.contextWindow > 0 ? target2.contextWindow : void 0;
|
|
33907
34128
|
const upstream = await gateway.stream(body2, {
|
|
@@ -34063,6 +34284,7 @@ function createAiGatewaySettingsStore(deps = {}) {
|
|
|
34063
34284
|
// 무관한 모델 노출 저장 한 번이 사용자의 소진 순서를 지운다.
|
|
34064
34285
|
...current.providerPriority ? { providerPriority: current.providerPriority } : {},
|
|
34065
34286
|
...current.compactCeiling !== void 0 ? { compactCeiling: current.compactCeiling } : {},
|
|
34287
|
+
...current.xaiEndpoint !== void 0 ? { xaiEndpoint: current.xaiEndpoint } : {},
|
|
34066
34288
|
...value ?? {}
|
|
34067
34289
|
})),
|
|
34068
34290
|
writeCursorDiagnosticsEnabled: (enabled) => update((current) => normalizeAiGatewaySettings({
|
|
@@ -34088,12 +34310,22 @@ function createAiGatewaySettingsStore(deps = {}) {
|
|
|
34088
34310
|
const withoutCeiling = { ...next };
|
|
34089
34311
|
delete withoutCeiling.compactCeiling;
|
|
34090
34312
|
return withoutCeiling;
|
|
34313
|
+
}),
|
|
34314
|
+
writeXaiEndpoint: (endpoint) => update((current) => {
|
|
34315
|
+
const next = normalizeAiGatewaySettings({
|
|
34316
|
+
...current,
|
|
34317
|
+
...endpoint === void 0 ? {} : { xaiEndpoint: endpoint }
|
|
34318
|
+
});
|
|
34319
|
+
if (endpoint !== void 0) return next;
|
|
34320
|
+
const withoutEndpoint = { ...next };
|
|
34321
|
+
delete withoutEndpoint.xaiEndpoint;
|
|
34322
|
+
return withoutEndpoint;
|
|
34091
34323
|
})
|
|
34092
34324
|
};
|
|
34093
34325
|
}
|
|
34094
34326
|
function fileExists(filePath) {
|
|
34095
34327
|
try {
|
|
34096
|
-
return
|
|
34328
|
+
return fs42.lstatSync(filePath).isFile();
|
|
34097
34329
|
} catch {
|
|
34098
34330
|
return false;
|
|
34099
34331
|
}
|
|
@@ -34102,7 +34334,7 @@ var CONCLUSIVE_LEGACY_READ_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EISDIR",
|
|
|
34102
34334
|
function readLegacySettings(legacyPath) {
|
|
34103
34335
|
let raw;
|
|
34104
34336
|
try {
|
|
34105
|
-
raw =
|
|
34337
|
+
raw = fs42.readFileSync(legacyPath, "utf-8");
|
|
34106
34338
|
} catch (error51) {
|
|
34107
34339
|
return CONCLUSIVE_LEGACY_READ_ERRORS.has(error51.code ?? "") ? { kind: "nothing" } : { kind: "unavailable" };
|
|
34108
34340
|
}
|
|
@@ -34495,7 +34727,7 @@ var GATEWAY_MODELS_DOCTRINE = {
|
|
|
34495
34727
|
// usageGuidelines에 적은 문장은 모델에 도달하지 않으므로, 틀리면 조용히 실패하는 두 규칙은
|
|
34496
34728
|
// 여기에 둔다. 나머지 판정 규칙은 응답 본문을 보면 알 수 있어 싣지 않는다 — 길어질수록
|
|
34497
34729
|
// 읽히지 않고, 읽히지 않으면 없는 것과 같다.
|
|
34498
|
-
description: `Report the gateway models currently available to this session, each model's routing constraints, capability class, and benchmark evidence, and the current provider allowances and the user's provider spend priority. The roster is the models the user exposed in the Console minus the ones reserved for the host session, and it is editable while this session runs, so it is resolved at call time rather than remembered. Two spellings, never interchangeable: agentTypes names an identity
|
|
34730
|
+
description: `Report the gateway models currently available to this session, each model's routing constraints, capability class, and benchmark evidence, and the current provider allowances and the user's provider spend priority. The roster is the models the user exposed in the Console minus the ones reserved for the host session, and it is editable while this session runs, so it is resolved at call time rather than remembered. Two spellings, never interchangeable: agentTypes names an identity \u2014 the Agent tool's subagent_type, or a workflow stage's opts.agentType \u2014 while modelId is the model as a value for a workflow stage's opts.model, and each is refused where the other belongs. Names are registered once at session start while this roster is re-read live, so a model or reasoning rung exposed mid-session appears here under a name that will not resolve until a new session.`,
|
|
34499
34731
|
promptSnippet: `gateway_models \u2014 Live roster of assignable gateway models: constraints, capability class, benchmark evidence, provider allowances, and the user's provider priority.`,
|
|
34500
34732
|
whenToUse: [],
|
|
34501
34733
|
whenNotToUse: [],
|
|
@@ -34749,7 +34981,7 @@ init_paths();
|
|
|
34749
34981
|
|
|
34750
34982
|
// ../../packages/fleet-admiral/src/agent-cli/assets.generated.ts
|
|
34751
34983
|
var EMBEDDED_AGENT_CLI_HOOK_ASSETS = [
|
|
34752
|
-
{ relativePath: "fleet-gateway-model-guard.mjs", content: '#!/usr/bin/env node\n// Fleet gateway model guard \u2014 \uAC8C\uC774\uD2B8\uC6E8\uC774 \uC138\uC158\uC758 \uC704\uC784 \uC815\uCC45\uC744 \uCF54\uB4DC\uB85C \uAC15\uC81C\uD558\uB294 \uB2E8\uC77C \uD6C5.\n//\n// \uC774 \uC800\uC7A5\uC18C\uB294 Admiral \uC2DC\uC2A4\uD15C \uD504\uB86C\uD504\uD2B8\uB97C \uC2E3\uC9C0 \uC54A\uB294\uB2E4. \uC704\uC784 \uC804\uC5D0 \uB85C\uC2A4\uD130\uB97C \uC77D\uACE0 \uC815\uCCB4\uC131\uC744\n// \uD540\uD558\uB77C\uB294 \uC9C0\uCE68\uC774 \uC0C1\uC8FC \uD14D\uC2A4\uD2B8\uB85C \uC874\uC7AC\uD558\uC9C0 \uC54A\uC73C\uBBC0\uB85C, \uADF8 \uC5ED\uD560 \uC804\uBD80\uAC00 \uC774 \uC2A4\uD06C\uB9BD\uD2B8\uC5D0 \uC788\uB2E4.\n//\n// \uCCAB \uC778\uC790\uAC00 \uC11C\uBE0C\uCEE4\uB9E8\uB4DC\uB2E4. \uD6C5 \uC774\uBCA4\uD2B8\uB9C8\uB2E4 \uBCC4\uB3C4 \uD30C\uC77C\uC744 \uB450\uC9C0 \uC54A\uB294 \uC774\uC720\uB294 \uC138 \uD310\uC815\uC774 \uAC19\uC740\n// \uC5B4\uD718(\uC815\uCCB4\uC131 \uC774\uB984 / modelId / \uC811\uC218\uC99D)\uB97C \uACF5\uC720\uD558\uAE30 \uB54C\uBB38\uC774\uB2E4 \u2014 \uD30C\uC77C\uC744 \uCABC\uAC1C\uBA74 \uADF8 \uC5B4\uD718\uAC00\n// \uC138 \uACF3\uC5D0\uC11C \uB530\uB85C \uB299\uB294\uB2E4.\n//\n// remind UserPromptSubmit \uB9E4 \uD134 \uADDC\uC57D \uC8FC\uC785 (\uBB34\uC870\uAC74)\n// gate-delegation PreToolUse Agent|Workflow \uD540\uB418\uC9C0 \uC54A\uC740 \uC704\uC784\uC744 \uCC28\uB2E8\n// workflow-receipt PostToolUse Workflow \uC811\uC218\uC99D\uC744 \uACB0\uACFC\uB85C \uC77D\uB294 \uC0AC\uACE0\uB97C \uCC28\uB2E8\n//\n// \uC0C1\uD0DC\uB97C \uB0A8\uAE30\uC9C0 \uC54A\uB294\uB2E4. \uD6C5\uC740 \uD638\uCD9C\uB9C8\uB2E4 \uC0C8 \uD504\uB85C\uC138\uC2A4\uB85C \uB728\uBBC0\uB85C \uD504\uB85C\uC138\uC2A4 \uAC04 \uAE30\uC5B5\uC740 \uD30C\uC77C\uB85C\uB9CC\n// \uAC00\uB2A5\uD55C\uB370, \uADF8 \uD30C\uC77C\uC740 \uACE7 \uC2E0\uC120\uB3C4\xB7\uC815\uB9AC\xB7\uACBD\uD569\uC744 \uB5A0\uC548\uB294 \uB450 \uBC88\uC9F8 \uC9C4\uC2E4\uC774 \uB41C\uB2E4. \uC138 \uD310\uC815 \uBAA8\uB450\n// stdin \uD55C \uBC88\uC73C\uB85C \uB05D\uB098\uB3C4\uB85D \uC9F0\uB2E4 \u2014 \uADF8\uB798\uC11C \uD0C0\uC784\uC544\uC6C3\uC73C\uB85C \uAC8C\uC774\uD2B8\uAC00 \uC870\uC6A9\uD788 \uC5F4\uB9B4 \uC5EC\uC9C0\uB3C4 \uC791\uB2E4.\nimport { readFileSync } from "node:fs";\n\n// \uBAA8\uB378\uC5D0\uAC8C \uC8FC\uB294 \uC9C0\uC2DC\uC774\uBBC0\uB85C \uC601\uC5B4\uB85C \uC4F4\uB2E4.\nconst TURN_REMINDER = [\n "Before any Agent or Workflow run leaves the host, call gateway_models and pin an identity from what it",\n "reports \u2014 allowances move while work is in flight.",\n "Agent: subagent_type = the fleet:* name. Workflow: opts.model = the modelId, the claude-gateway-- prefix",\n "included. The two spellings are never interchangeable.",\n].join(" ");\n\nconst IN_FLIGHT_CONTRACT = [\n "This Workflow call returned a receipt, not a result. The run is still in flight and its result arrives later.",\n "End this turn with one status line: which surface, how many stages, and what you are waiting for.",\n "Do not review, conclude, summarize, or predict what the run will find \u2014 a reading written before the result is",\n "indistinguishable from the result to the reader, and it is still there after the real one lands.",\n "Report the finding once, in the turn the result arrives. If asked before then, say it is still running.",\n].join(" ");\n\nconst PIN_INSTRUCTION = [\n "Call gateway_models first, then pin the identity it reports:",\n "Agent \u2014 subagent_type = the fleet:* name;",\n "Workflow \u2014 opts.model = the modelId with the claude-gateway-- prefix, written as a literal.",\n].join(" ");\n\n/**\n * \uC815\uCCB4\uC131\uC774 \uD540\uB418\uC9C0 \uC54A\uC740 \uC704\uC784\uC73C\uB85C \uCDE8\uAE09\uD558\uB294 Agent \uD0C0\uC785.\n *\n * \uB0B4\uC7A5 \uC804\uBB38 \uC5D0\uC774\uC804\uD2B8(Explore/Plan/\u2026)\uC640 fork\uB294 \uD1B5\uACFC\uC2DC\uD0A8\uB2E4. fork\uB294 \uBD80\uBAA8 \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uC787\uB294 \uAC83\uC774\n * \uBAA9\uC801\uC774\uB77C \uB2E4\uB978 \uBAA8\uB378\uB85C \uC62E\uAE30\uB294 \uAC83 \uC790\uCCB4\uAC00 \uADF8 \uD45C\uBA74\uC758 \uC758\uBBF8\uB97C \uC5C6\uC560\uACE0, \uB098\uBA38\uC9C0\uB294 \uADF8 \uB3C4\uAD6C\uB97C \uC4F0\uB824\uACE0\n * \uACE0\uB978 \uC774\uB984\uC774\uC9C0 \uC704\uC784\uC744 \uBBF8\uB8EC \uACB0\uACFC\uAC00 \uC544\uB2C8\uB2E4. \uC544\uB798 \uB458\uB9CC\uC774 "\uC544\uBB34\uAC83\uB3C4 \uACE0\uB974\uC9C0 \uC54A\uC558\uB2E4"\uC758 \uCCA0\uC790\uB2E4.\n */\nconst UNPINNED_AGENT_TYPES = new Set(["general-purpose", "claude"]);\n\nconst GATEWAY_AGENT_PREFIX = "fleet:";\nconst MODEL_ALIASES = /^(fable|opus|sonnet|haiku)$/;\nconst PREFIXED_ALIAS_RE = /^claude-gateway--(fable|opus|sonnet|haiku)$/;\nconst GATEWAY_MODEL_PREFIX = "claude-gateway--";\nconst AGENT_TYPE_RE = /agentType\\s*:/;\nconst MODEL_VALUE_RE = /model:\\s*[\'"]([^\'"]+)[\'"]/g;\nconst AGENT_CALL_RE = /\\bagent\\s*\\(/g;\n\nfunction block(message) {\n process.stderr.write(`[fleet-gateway-model-guard] ${message}\\n`);\n process.exit(2);\n}\n\nfunction emitContext(hookEventName, additionalContext) {\n process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext } }));\n process.exit(0);\n}\n\nfunction readHookInput() {\n try {\n return JSON.parse(readFileSync(0, "utf8"));\n } catch {\n // \uC785\uB825\uC744 \uC77D\uC9C0 \uBABB\uD558\uBA74 \uD310\uC815\uD560 \uADFC\uAC70\uAC00 \uC5C6\uB2E4. \uCC28\uB2E8\uC740 \uADFC\uAC70\uAC00 \uC788\uC744 \uB54C\uB9CC \uD55C\uB2E4.\n process.exit(0);\n }\n}\n\n/**\n * `agent(` \uD638\uCD9C \uD558\uB098\uAC00 \uCC28\uC9C0\uD558\uB294 \uC6D0\uBB38 \uBC94\uC704. \uAD04\uD638 \uADE0\uD615\uC73C\uB85C \uB05D\uC744 \uCC3E\uB418 \uBB38\uC790\uC5F4\xB7\uC8FC\uC11D \uC548\uC758 \uAD04\uD638\uB294\n * \uC138\uC9C0 \uC54A\uB294\uB2E4 \u2014 \uD504\uB86C\uD504\uD2B8 \uD14D\uC2A4\uD2B8\uC5D0 \uAD04\uD638\uAC00 \uD754\uD574\uC11C, \uC138\uB294 \uC21C\uAC04 \uD638\uCD9C \uACBD\uACC4\uAC00 \uC5C9\uB6B1\uD55C \uACF3\uC5D0\uC11C \uB2EB\uD78C\uB2E4.\n *\n * \uB05D\uC744 \uCC3E\uC9C0 \uBABB\uD558\uBA74 undefined\uB97C \uB3CC\uB824\uC8FC\uACE0 \uD638\uCD9C\uC790\uB294 \uADF8 \uD638\uCD9C\uC744 \uAC80\uC0AC\uD558\uC9C0 \uC54A\uB294\uB2E4. \uC774 \uC2A4\uCE90\uB108\uB294\n * \uD30C\uC11C\uAC00 \uC544\uB2C8\uBBC0\uB85C, \uD310\uC815\uD560 \uC218 \uC5C6\uB294 \uD615\uD0DC\uB97C "\uD540 \uC5C6\uC74C"\uC73C\uB85C \uBAB0\uC544 \uBA40\uCA61\uD55C \uC2A4\uD06C\uB9BD\uD2B8\uB97C \uB9C9\uB294 \uCABD\uC774\n * \uAC80\uC0AC \uD55C \uAC74\uC744 \uB193\uCE58\uB294 \uCABD\uBCF4\uB2E4 \uB098\uC058\uB2E4.\n */\nfunction sliceCall(script, openParenIndex) {\n let depth = 0;\n let quote;\n let escaped = false;\n for (let i = openParenIndex; i < script.length; i += 1) {\n const char = script[i];\n if (quote !== undefined) {\n if (escaped) escaped = false;\n else if (char === "\\\\") escaped = true;\n else if (char === quote) quote = undefined;\n continue;\n }\n if (char === "\'" || char === \'"\' || char === "`") {\n quote = char;\n continue;\n }\n if (char === "/" && script[i + 1] === "/") {\n const lineEnd = script.indexOf("\\n", i);\n if (lineEnd === -1) return undefined;\n i = lineEnd;\n continue;\n }\n if (char === "/" && script[i + 1] === "*") {\n const blockEnd = script.indexOf("*/", i + 2);\n if (blockEnd === -1) return undefined;\n i = blockEnd + 1;\n continue;\n }\n if (char === "(") depth += 1;\n else if (char === ")") {\n depth -= 1;\n if (depth === 0) return script.slice(openParenIndex, i + 1);\n }\n }\n return undefined;\n}\n\n/** model \uC635\uC158\uC774 \uC5C6\uB294 `agent(` \uD638\uCD9C\uC758 \uAC1C\uC218. \uACBD\uACC4\uB97C \uBABB \uC77D\uC740 \uD638\uCD9C\uC740 \uC138\uC9C0 \uC54A\uB294\uB2E4. */\nfunction countUnpinnedAgentCalls(script) {\n let unpinned = 0;\n for (const match of script.matchAll(AGENT_CALL_RE)) {\n const call = sliceCall(script, match.index + match[0].length - 1);\n if (call === undefined) continue;\n if (!/\\bmodel\\s*:/.test(call)) unpinned += 1;\n }\n return unpinned;\n}\n\nfunction assertWorkflowModelValues(script) {\n for (const match of script.matchAll(MODEL_VALUE_RE)) {\n const value = match[1];\n if (MODEL_ALIASES.test(value)) continue;\n if (PREFIXED_ALIAS_RE.test(value)) {\n block(\n `lineage alias\uC5D0\uB294 claude-gateway-- prefix\uB97C \uBD99\uC774\uBA74 \uC548 \uB429\uB2C8\uB2E4: "${value}". ` +\n "alias\uB294 \uADF8\uB300\uB85C(fable|opus|sonnet|haiku) \uC0AC\uC6A9\uD558\uC138\uC694."\n );\n }\n if (value.startsWith(GATEWAY_MODEL_PREFIX)) continue;\n block(\n `opts.model \uAC12\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4: "${value}". gateway_models\uC758 modelId(claude-gateway-- prefix \uD3EC\uD568)\uB97C ` +\n "\uADF8\uB300\uB85C \uBCF5\uC0AC\uD558\uAC70\uB098 lineage alias(fable|opus|sonnet|haiku)\uB97C \uC0AC\uC6A9\uD558\uC138\uC694."\n );\n }\n}\n\n/** \uAC80\uC0AC \uB300\uC0C1 \uC2A4\uD06C\uB9BD\uD2B8 \uC6D0\uBB38. \uBCFC \uC218 \uC5C6\uB294 \uD638\uCD9C \uD615\uD0DC\uB294 undefined\uB97C \uB3CC\uB824\uC900\uB2E4. */\nfunction resolveWorkflowScript(toolInput) {\n if (typeof toolInput.script === "string" && toolInput.script.length > 0) return toolInput.script;\n // resumeFromRunId \uC7AC\uC2E4\uD589\uC740 scriptPath\uB85C \uB4E4\uC5B4\uC628\uB2E4. \uD30C\uC77C\uC744 \uC77D\uC5B4 \uB3D9\uC77C\uD558\uAC8C \uAC80\uC99D\uD55C\uB2E4.\n if (typeof toolInput.scriptPath === "string" && toolInput.scriptPath.length > 0) {\n try {\n return readFileSync(toolInput.scriptPath, "utf8");\n } catch {\n // \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC73C\uBA74 \uC2E4\uD589 \uB2E8\uACC4\uC5D0\uC11C \uB4DC\uB7EC\uB098\uB294 \uC624\uB958\uB2E4. \uC5EC\uAE30\uC11C\uB294 \uD310\uC815\uD558\uC9C0 \uC54A\uB294\uB2E4.\n return undefined;\n }\n }\n // name(\uC800\uC7A5 \uC6CC\uD06C\uD50C\uB85C\uC6B0)\uC740 \uB0B4\uC6A9\uC744 \uBCFC \uC218 \uC5C6\uB2E4. \uC0AC\uC804 \uAC80\uC99D\uB41C \uAC83\uC73C\uB85C \uC2E0\uB8B0\uD55C\uB2E4.\n return undefined;\n}\n\nfunction gateAgentDelegation(toolInput) {\n const agentType = typeof toolInput.subagent_type === "string" ? toolInput.subagent_type : undefined;\n if (agentType !== undefined && agentType.startsWith(GATEWAY_AGENT_PREFIX)) process.exit(0);\n if (agentType !== undefined && !UNPINNED_AGENT_TYPES.has(agentType)) process.exit(0);\n block(\n `\uC774 \uC704\uC784\uC740 \uC815\uCCB4\uC131\uC774 \uD540\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4(subagent_type: ${agentType ?? "\uBBF8\uC9C0\uC815"}). ` +\n PIN_INSTRUCTION\n );\n}\n\nfunction gateWorkflowDelegation(toolInput) {\n const script = resolveWorkflowScript(toolInput);\n if (script === undefined) process.exit(0);\n if (AGENT_TYPE_RE.test(script)) {\n block(\n "dynamic workflow \uC2A4\uD06C\uB9BD\uD2B8\uC5D0 agentType\uC774 \uAE08\uC9C0\uB429\uB2C8\uB2E4. agentType\uC740 \uD300\uBA54\uC774\uD2B8/\uC11C\uBE0C\uC5D0\uC774\uC804\uD2B8 \uD45C\uBA74 \uC804\uC6A9\uC774\uACE0, " +\n "\uC6CC\uD06C\uD50C\uB85C\uC6B0\uB294 opts.model\uB85C\uB9CC \uD32C\uC544\uC6C3\uD574\uC57C \uD569\uB2C8\uB2E4."\n );\n }\n const unpinned = countUnpinnedAgentCalls(script);\n if (unpinned > 0) {\n block(\n `model\uC774 \uC9C0\uC815\uB418\uC9C0 \uC54A\uC740 agent() \uD638\uCD9C\uC774 ${unpinned}\uAC74 \uC788\uC2B5\uB2C8\uB2E4. ` +\n PIN_INSTRUCTION +\n " \uC2A4\uD14C\uC774\uC9C0\uB9C8\uB2E4 \uBAA8\uB378\uC744 \uB098\uB204\uB294 \uAC83\uC774 \uC774 \uD45C\uBA74\uC758 \uBAA9\uC801\uC774\uBBC0\uB85C, \uD55C \uAC12\uC73C\uB85C \uCC44\uC6B0\uC9C0 \uB9D0\uACE0 \uC5ED\uD560\uBCC4\uB85C \uBC30\uBD84\uD558\uC138\uC694."\n );\n }\n assertWorkflowModelValues(script);\n process.exit(0);\n}\n\nconst subcommand = process.argv[2];\n\nif (subcommand === "remind") {\n emitContext("UserPromptSubmit", TURN_REMINDER);\n}\n\nconst input = readHookInput();\nconst toolName = input?.tool_name;\nconst toolInput = input?.tool_input ?? {};\n\nif (subcommand === "workflow-receipt") {\n if (toolName !== "Workflow") process.exit(0);\n emitContext("PostToolUse", IN_FLIGHT_CONTRACT);\n}\n\nif (subcommand === "gate-delegation") {\n if (toolName === "Agent") gateAgentDelegation(toolInput);\n if (toolName === "Workflow") gateWorkflowDelegation(toolInput);\n process.exit(0);\n}\n\nprocess.exit(0);\n' }
|
|
34984
|
+
{ relativePath: "fleet-gateway-model-guard.mjs", content: '#!/usr/bin/env node\n// Fleet gateway model guard \u2014 \uAC8C\uC774\uD2B8\uC6E8\uC774 \uC138\uC158\uC758 \uC704\uC784 \uC815\uCC45\uC744 \uCF54\uB4DC\uB85C \uAC15\uC81C\uD558\uB294 \uB2E8\uC77C \uD6C5.\n//\n// \uC774 \uC800\uC7A5\uC18C\uB294 Admiral \uC2DC\uC2A4\uD15C \uD504\uB86C\uD504\uD2B8\uB97C \uC2E3\uC9C0 \uC54A\uB294\uB2E4. \uC704\uC784 \uC804\uC5D0 \uB85C\uC2A4\uD130\uB97C \uC77D\uACE0 \uC815\uCCB4\uC131\uC744\n// \uD540\uD558\uB77C\uB294 \uC9C0\uCE68\uC774 \uC0C1\uC8FC \uD14D\uC2A4\uD2B8\uB85C \uC874\uC7AC\uD558\uC9C0 \uC54A\uC73C\uBBC0\uB85C, \uADF8 \uC5ED\uD560 \uC804\uBD80\uAC00 \uC774 \uC2A4\uD06C\uB9BD\uD2B8\uC5D0 \uC788\uB2E4.\n//\n// \uCCAB \uC778\uC790\uAC00 \uC11C\uBE0C\uCEE4\uB9E8\uB4DC\uB2E4. \uD6C5 \uC774\uBCA4\uD2B8\uB9C8\uB2E4 \uBCC4\uB3C4 \uD30C\uC77C\uC744 \uB450\uC9C0 \uC54A\uB294 \uC774\uC720\uB294 \uC138 \uD310\uC815\uC774 \uAC19\uC740\n// \uC5B4\uD718(\uC815\uCCB4\uC131 \uC774\uB984 / modelId / \uC811\uC218\uC99D)\uB97C \uACF5\uC720\uD558\uAE30 \uB54C\uBB38\uC774\uB2E4 \u2014 \uD30C\uC77C\uC744 \uCABC\uAC1C\uBA74 \uADF8 \uC5B4\uD718\uAC00\n// \uC138 \uACF3\uC5D0\uC11C \uB530\uB85C \uB299\uB294\uB2E4.\n//\n// remind UserPromptSubmit \uB9E4 \uD134 \uADDC\uC57D \uC8FC\uC785 (\uBB34\uC870\uAC74)\n// gate-delegation PreToolUse Agent|Workflow Agent\uC758 \uD540 \uB204\uB77D\uACFC workflow\uC758 \uD2C0\uB9B0 \uBAA8\uB378 \uCCA0\uC790\uB97C \uCC28\uB2E8\n// workflow-receipt PostToolUse Workflow \uC811\uC218\uC99D\uC744 \uACB0\uACFC\uB85C \uC77D\uB294 \uC0AC\uACE0\uB97C \uCC28\uB2E8\n//\n// \uC0C1\uD0DC\uB97C \uB0A8\uAE30\uC9C0 \uC54A\uB294\uB2E4. \uD6C5\uC740 \uD638\uCD9C\uB9C8\uB2E4 \uC0C8 \uD504\uB85C\uC138\uC2A4\uB85C \uB728\uBBC0\uB85C \uD504\uB85C\uC138\uC2A4 \uAC04 \uAE30\uC5B5\uC740 \uD30C\uC77C\uB85C\uB9CC\n// \uAC00\uB2A5\uD55C\uB370, \uADF8 \uD30C\uC77C\uC740 \uACE7 \uC2E0\uC120\uB3C4\xB7\uC815\uB9AC\xB7\uACBD\uD569\uC744 \uB5A0\uC548\uB294 \uB450 \uBC88\uC9F8 \uC9C4\uC2E4\uC774 \uB41C\uB2E4. \uC138 \uD310\uC815 \uBAA8\uB450\n// stdin \uD55C \uBC88\uC73C\uB85C \uB05D\uB098\uB3C4\uB85D \uC9F0\uB2E4 \u2014 \uADF8\uB798\uC11C \uD0C0\uC784\uC544\uC6C3\uC73C\uB85C \uAC8C\uC774\uD2B8\uAC00 \uC870\uC6A9\uD788 \uC5F4\uB9B4 \uC5EC\uC9C0\uB3C4 \uC791\uB2E4.\nimport { readFileSync } from "node:fs";\n\n// \uBAA8\uB378\uC5D0\uAC8C \uC8FC\uB294 \uC9C0\uC2DC\uC774\uBBC0\uB85C \uC601\uC5B4\uB85C \uC4F4\uB2E4.\nconst TURN_REMINDER = [\n "Call gateway_models before a run leaves the host and pin from what that call reports \u2014 allowances and the",\n "roster itself move while work is in flight, so a remembered name is not evidence that it still resolves.",\n "Agent: subagent_type = the fleet:* name, always.",\n "A Workflow stage may stay on the host model; when you do move one, pin it from that same lookup \u2014",\n "opts.model takes the modelId with the claude-gateway-- prefix, opts.agentType takes the fleet:* name.",\n "The spellings are never interchangeable.",\n].join(" ");\n\nconst IN_FLIGHT_CONTRACT = [\n "This Workflow call returned a receipt, not a result. The run is still in flight and its result arrives later.",\n "End this turn with one status line: which surface, how many stages, and what you are waiting for.",\n "Do not review, conclude, summarize, or predict what the run will find \u2014 a reading written before the result is",\n "indistinguishable from the result to the reader, and it is still there after the real one lands.",\n "Report the finding once, in the turn the result arrives. If asked before then, say it is still running.",\n].join(" ");\n\nconst PIN_INSTRUCTION =\n "Call gateway_models first, then pin the identity it reports: subagent_type = the fleet:* name.";\n\n/**\n * \uC815\uCCB4\uC131\uC774 \uD540\uB418\uC9C0 \uC54A\uC740 \uC704\uC784\uC73C\uB85C \uCDE8\uAE09\uD558\uB294 Agent \uD0C0\uC785.\n *\n * \uB0B4\uC7A5 \uC804\uBB38 \uC5D0\uC774\uC804\uD2B8(Explore/Plan/\u2026)\uC640 fork\uB294 \uD1B5\uACFC\uC2DC\uD0A8\uB2E4. fork\uB294 \uBD80\uBAA8 \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uC787\uB294 \uAC83\uC774\n * \uBAA9\uC801\uC774\uB77C \uB2E4\uB978 \uBAA8\uB378\uB85C \uC62E\uAE30\uB294 \uAC83 \uC790\uCCB4\uAC00 \uADF8 \uD45C\uBA74\uC758 \uC758\uBBF8\uB97C \uC5C6\uC560\uACE0, \uB098\uBA38\uC9C0\uB294 \uADF8 \uB3C4\uAD6C\uB97C \uC4F0\uB824\uACE0\n * \uACE0\uB978 \uC774\uB984\uC774\uC9C0 \uC704\uC784\uC744 \uBBF8\uB8EC \uACB0\uACFC\uAC00 \uC544\uB2C8\uB2E4. \uC544\uB798 \uB458\uB9CC\uC774 "\uC544\uBB34\uAC83\uB3C4 \uACE0\uB974\uC9C0 \uC54A\uC558\uB2E4"\uC758 \uCCA0\uC790\uB2E4.\n */\nconst UNPINNED_AGENT_TYPES = new Set(["general-purpose", "claude"]);\n\nconst GATEWAY_AGENT_PREFIX = "fleet:";\nconst MODEL_ALIASES = /^(fable|opus|sonnet|haiku)$/;\nconst PREFIXED_ALIAS_RE = /^claude-gateway--(fable|opus|sonnet|haiku)$/;\nconst GATEWAY_MODEL_PREFIX = "claude-gateway--";\n// \uCF5C\uB860 \uC55E \uACF5\uBC31\uC740 \uC720\uD6A8\uD55C \uD504\uB85C\uD37C\uD2F0 \uD45C\uAE30\uB2E4. \uC815\uADDC\uC2DD\uC774 \uC815\uADDC \uD45C\uAE30\uB9CC \uC54C\uBA74 \uADF8 \uD55C \uCE78\uC774 \uAC80\uC0AC\uB97C \uBE44\uCF1C\uAC04\uB2E4.\nconst MODEL_VALUE_RE = /model\\s*:\\s*[\'"]([^\'"]+)[\'"]/g;\nconst AGENT_TYPE_VALUE_RE = /agentType\\s*:\\s*[\'"]([^\'"]+)[\'"]/g;\n\nfunction block(message) {\n process.stderr.write(`[fleet-gateway-model-guard] ${message}\\n`);\n process.exit(2);\n}\n\nfunction emitContext(hookEventName, additionalContext) {\n process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext } }));\n process.exit(0);\n}\n\nfunction readHookInput() {\n try {\n return JSON.parse(readFileSync(0, "utf8"));\n } catch {\n // \uC785\uB825\uC744 \uC77D\uC9C0 \uBABB\uD558\uBA74 \uD310\uC815\uD560 \uADFC\uAC70\uAC00 \uC5C6\uB2E4. \uCC28\uB2E8\uC740 \uADFC\uAC70\uAC00 \uC788\uC744 \uB54C\uB9CC \uD55C\uB2E4.\n process.exit(0);\n }\n}\n\n/**\n * \uC6CC\uD06C\uD50C\uB85C\uC6B0\uAC00 \uC4F4 \uBAA8\uB378 \uAC12\uC758 \uCCA0\uC790 \uAC80\uC0AC.\n *\n * \uC2A4\uD14C\uC774\uC9C0\uB97C \uC62E\uAE38\uC9C0 \uB9D0\uC9C0\uB294 \uD638\uC2A4\uD2B8\uAC00 \uC815\uD55C\uB2E4 \u2014 \uD540\uD558\uC9C0 \uC54A\uC740 \uC2A4\uD14C\uC774\uC9C0\uB294 \uC138\uC158 \uBAA8\uB378\uB85C \uB3CC\uBA74 \uADF8\uB9CC\uC774\uB2E4.\n * \uC5EC\uAE30\uC11C \uB9C9\uB294 \uAC83\uC740 \uC62E\uAE30\uAE30\uB85C \uD574\uB193\uACE0 \uAC12\uC744 \uC798\uBABB \uC4F4 \uACBD\uC6B0\uBFD0\uC774\uB2E4. \uB85C\uC2A4\uD130 \uC774\uB984\uC774\uB098 prefix\uAC00 \uBE60\uC9C4\n * modelId\uAC00 `model` \uC790\uB9AC\uC5D0 \uB4E4\uC5B4\uAC00\uBA74 \uBAA8\uB4E0 \uBD84\uAE30\uAC00 \uC2DC\uC791 \uC989\uC2DC \uC8FD\uC73C\uBBC0\uB85C, \uADF8 \uC2E4\uD328\uB294 \uC2E4\uD589 \uC804\uC5D0 \uC7A1\uB294\n * \uD3B8\uC774 \uD6E8\uC52C \uC2F8\uB2E4.\n */\nfunction assertWorkflowModelValues(script) {\n for (const match of script.matchAll(MODEL_VALUE_RE)) {\n const value = match[1];\n if (MODEL_ALIASES.test(value)) continue;\n if (PREFIXED_ALIAS_RE.test(value)) {\n block(\n `lineage alias\uC5D0\uB294 claude-gateway-- prefix\uB97C \uBD99\uC774\uBA74 \uC548 \uB429\uB2C8\uB2E4: "${value}". ` +\n "alias\uB294 \uADF8\uB300\uB85C(fable|opus|sonnet|haiku) \uC0AC\uC6A9\uD558\uC138\uC694."\n );\n }\n if (value.startsWith(GATEWAY_MODEL_PREFIX)) continue;\n block(\n `opts.model \uAC12\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4: "${value}". gateway_models\uC758 modelId(claude-gateway-- prefix \uD3EC\uD568)\uB97C ` +\n "\uADF8\uB300\uB85C \uBCF5\uC0AC\uD558\uAC70\uB098 lineage alias(fable|opus|sonnet|haiku)\uB97C \uC0AC\uC6A9\uD558\uC138\uC694. " +\n "fleet:* \uC774\uB984\uC740 opts.agentType \uC790\uB9AC\uC785\uB2C8\uB2E4."\n );\n }\n}\n\n/**\n * \uC774\uB984 \uC790\uB9AC\uC5D0 \uB4E4\uC5B4\uAC04 modelId. \uB450 \uCCA0\uC790\uB97C \uB9DE\uBC14\uAFBC \uB098\uBA38\uC9C0 \uC808\uBC18\uC774\uB2E4.\n *\n * `fleet:` \uC811\uB450\uB9CC \uD1B5\uACFC\uC2DC\uD0A4\uC9C0\uB294 \uC54A\uB294\uB2E4 \u2014 `general-purpose`\uCC98\uB7FC \uC774 \uC800\uC7A5\uC18C\uAC00 \uC2E3\uC9C0 \uC54A\uC740 \uB0B4\uC7A5\n * agentType\uB3C4 \uADF8 \uC790\uB9AC\uC758 \uC815\uB2F9\uD55C \uAC12\uC774\uB77C, \uC811\uB450\uB85C \uAC70\uB974\uBA74 \uBA40\uCA61\uD55C \uC2A4\uD06C\uB9BD\uD2B8\uAC00 \uB9C9\uD78C\uB2E4. modelId\uB9CC\n * \uACE8\uB77C \uB9C9\uB294\uB2E4: \uADF8 \uAC12\uC740 \uC5B4\uB5A4 \uB808\uC9C0\uC2A4\uD2B8\uB9AC\uC5D0\uB3C4 \uC774\uB984\uC73C\uB85C \uB4F1\uB85D\uB418\uC5B4 \uC788\uC9C0 \uC54A\uC544 \uBC18\uB4DC\uC2DC \uC8FD\uB294\uB2E4.\n */\nfunction assertWorkflowAgentTypeValues(script) {\n for (const match of script.matchAll(AGENT_TYPE_VALUE_RE)) {\n const value = match[1];\n if (!value.startsWith(GATEWAY_MODEL_PREFIX)) continue;\n block(\n `opts.agentType \uAC12\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4: "${value}". modelId\uB294 opts.model \uC790\uB9AC\uC774\uACE0, ` +\n "agentType\uC5D0\uB294 gateway_models\uAC00 \uBCF4\uACE0\uD55C fleet:* \uC774\uB984\uC744 \uC501\uB2C8\uB2E4."\n );\n }\n}\n\n/** \uAC80\uC0AC \uB300\uC0C1 \uC2A4\uD06C\uB9BD\uD2B8 \uC6D0\uBB38. \uBCFC \uC218 \uC5C6\uB294 \uD638\uCD9C \uD615\uD0DC\uB294 undefined\uB97C \uB3CC\uB824\uC900\uB2E4. */\nfunction resolveWorkflowScript(toolInput) {\n if (typeof toolInput.script === "string" && toolInput.script.length > 0) return toolInput.script;\n // resumeFromRunId \uC7AC\uC2E4\uD589\uC740 scriptPath\uB85C \uB4E4\uC5B4\uC628\uB2E4. \uD30C\uC77C\uC744 \uC77D\uC5B4 \uB3D9\uC77C\uD558\uAC8C \uAC80\uC99D\uD55C\uB2E4.\n if (typeof toolInput.scriptPath === "string" && toolInput.scriptPath.length > 0) {\n try {\n return readFileSync(toolInput.scriptPath, "utf8");\n } catch {\n // \uD30C\uC77C\uC744 \uC77D\uC744 \uC218 \uC5C6\uC73C\uBA74 \uC2E4\uD589 \uB2E8\uACC4\uC5D0\uC11C \uB4DC\uB7EC\uB098\uB294 \uC624\uB958\uB2E4. \uC5EC\uAE30\uC11C\uB294 \uD310\uC815\uD558\uC9C0 \uC54A\uB294\uB2E4.\n return undefined;\n }\n }\n // name(\uC800\uC7A5 \uC6CC\uD06C\uD50C\uB85C\uC6B0)\uC740 \uB0B4\uC6A9\uC744 \uBCFC \uC218 \uC5C6\uB2E4. \uC0AC\uC804 \uAC80\uC99D\uB41C \uAC83\uC73C\uB85C \uC2E0\uB8B0\uD55C\uB2E4.\n return undefined;\n}\n\nfunction gateAgentDelegation(toolInput) {\n const agentType = typeof toolInput.subagent_type === "string" ? toolInput.subagent_type : undefined;\n if (agentType !== undefined && agentType.startsWith(GATEWAY_AGENT_PREFIX)) process.exit(0);\n if (agentType !== undefined && !UNPINNED_AGENT_TYPES.has(agentType)) process.exit(0);\n block(\n `\uC774 \uC704\uC784\uC740 \uC815\uCCB4\uC131\uC774 \uD540\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4(subagent_type: ${agentType ?? "\uBBF8\uC9C0\uC815"}). ` +\n PIN_INSTRUCTION\n );\n}\n\nfunction gateWorkflowDelegation(toolInput) {\n const script = resolveWorkflowScript(toolInput);\n if (script === undefined) process.exit(0);\n assertWorkflowModelValues(script);\n assertWorkflowAgentTypeValues(script);\n process.exit(0);\n}\n\nconst subcommand = process.argv[2];\n\nif (subcommand === "remind") {\n emitContext("UserPromptSubmit", TURN_REMINDER);\n}\n\nconst input = readHookInput();\nconst toolName = input?.tool_name;\nconst toolInput = input?.tool_input ?? {};\n\nif (subcommand === "workflow-receipt") {\n if (toolName !== "Workflow") process.exit(0);\n emitContext("PostToolUse", IN_FLIGHT_CONTRACT);\n}\n\nif (subcommand === "gate-delegation") {\n if (toolName === "Agent") gateAgentDelegation(toolInput);\n if (toolName === "Workflow") gateWorkflowDelegation(toolInput);\n process.exit(0);\n}\n\nprocess.exit(0);\n' }
|
|
34753
34985
|
];
|
|
34754
34986
|
var DIR_MODE = 448;
|
|
34755
34987
|
var FILE_MODE = 384;
|
|
@@ -49040,17 +49272,17 @@ function createSystemFontsService(deps = {}) {
|
|
|
49040
49272
|
const now = deps.now ?? Date.now;
|
|
49041
49273
|
const successTtlMs = deps.successTtlMs ?? SUCCESS_TTL_MS;
|
|
49042
49274
|
const failureTtlMs = deps.failureTtlMs ?? FAILURE_TTL_MS;
|
|
49043
|
-
let
|
|
49275
|
+
let cached3 = null;
|
|
49044
49276
|
let cachedFailure = null;
|
|
49045
49277
|
let inFlight = null;
|
|
49046
49278
|
const getFonts = () => {
|
|
49047
|
-
if (
|
|
49279
|
+
if (cached3 && now() - cached3.cachedAt < successTtlMs) return Promise.resolve(cached3.fonts);
|
|
49048
49280
|
if (cachedFailure && now() - cachedFailure.cachedAt < failureTtlMs) return Promise.reject(cachedFailure.error);
|
|
49049
49281
|
if (inFlight) return inFlight;
|
|
49050
49282
|
inFlight = loadFonts().then((fonts) => {
|
|
49051
49283
|
const normalized = normalizeSystemFonts(fonts);
|
|
49052
49284
|
if (normalized.length === 0) throw EMPTY_SYSTEM_FONTS_ERROR;
|
|
49053
|
-
|
|
49285
|
+
cached3 = { fonts: normalized, cachedAt: now() };
|
|
49054
49286
|
cachedFailure = null;
|
|
49055
49287
|
return normalized;
|
|
49056
49288
|
}).catch((error51) => {
|
|
@@ -52251,8 +52483,8 @@ function createCodexGateway(deps) {
|
|
|
52251
52483
|
return cachedAccessSets(`listener|${listener.origin}`, () => buildListenerAccessSets(listener));
|
|
52252
52484
|
}
|
|
52253
52485
|
function cachedAccessSets(key, build) {
|
|
52254
|
-
const
|
|
52255
|
-
if (
|
|
52486
|
+
const cached3 = accessSetsByGate.get(key);
|
|
52487
|
+
if (cached3) return cached3;
|
|
52256
52488
|
const sets = build();
|
|
52257
52489
|
accessSetsByGate.set(key, sets);
|
|
52258
52490
|
return sets;
|
|
@@ -54190,8 +54422,8 @@ function filterDiscoveredPlugins(plugins) {
|
|
|
54190
54422
|
}
|
|
54191
54423
|
var pluginBundleModules = /* @__PURE__ */ new Map();
|
|
54192
54424
|
function importPluginBundleOnce(digest, bundledPath) {
|
|
54193
|
-
const
|
|
54194
|
-
if (
|
|
54425
|
+
const cached3 = pluginBundleModules.get(digest);
|
|
54426
|
+
if (cached3) return cached3;
|
|
54195
54427
|
const loading = import(pathToFileURL(bundledPath).href);
|
|
54196
54428
|
pluginBundleModules.set(digest, loading);
|
|
54197
54429
|
return loading;
|
|
@@ -55437,12 +55669,12 @@ function createConsoleUpdateCheckService(deps = {}) {
|
|
|
55437
55669
|
const intervalMs = deps.intervalMs ?? UPDATE_CHECK_INTERVAL_MS;
|
|
55438
55670
|
const startInterval = deps.setInterval ?? ((callback, delayMs) => setInterval(callback, delayMs));
|
|
55439
55671
|
const stopInterval = deps.clearInterval ?? ((interval2) => clearInterval(interval2));
|
|
55440
|
-
let
|
|
55672
|
+
let cached3 = null;
|
|
55441
55673
|
let inFlight = null;
|
|
55442
55674
|
let interval = null;
|
|
55443
55675
|
const changeListeners = /* @__PURE__ */ new Set();
|
|
55444
55676
|
const getStatus = () => {
|
|
55445
|
-
const current =
|
|
55677
|
+
const current = cached3;
|
|
55446
55678
|
if (current && now() - current.checkedAt < current.ttlMs) {
|
|
55447
55679
|
return current.status;
|
|
55448
55680
|
}
|
|
@@ -55450,7 +55682,7 @@ function createConsoleUpdateCheckService(deps = {}) {
|
|
|
55450
55682
|
return current?.status ?? NO_UPDATE_STATUS;
|
|
55451
55683
|
};
|
|
55452
55684
|
const refresh = async (options = {}) => {
|
|
55453
|
-
const current =
|
|
55685
|
+
const current = cached3;
|
|
55454
55686
|
if (options.force !== true && current && now() - current.checkedAt < current.ttlMs) {
|
|
55455
55687
|
return current.status;
|
|
55456
55688
|
}
|
|
@@ -55458,12 +55690,12 @@ function createConsoleUpdateCheckService(deps = {}) {
|
|
|
55458
55690
|
return inFlight;
|
|
55459
55691
|
}
|
|
55460
55692
|
inFlight = resolveUpdateStatus().then((status2) => {
|
|
55461
|
-
const previousStatus =
|
|
55462
|
-
|
|
55693
|
+
const previousStatus = cached3?.status ?? NO_UPDATE_STATUS;
|
|
55694
|
+
cached3 = { status: status2, checkedAt: now(), ttlMs };
|
|
55463
55695
|
notifyIfChanged(previousStatus, status2);
|
|
55464
55696
|
return status2;
|
|
55465
55697
|
}).catch(() => {
|
|
55466
|
-
|
|
55698
|
+
cached3 = { status: NO_UPDATE_STATUS, checkedAt: now(), ttlMs: errorTtlMs };
|
|
55467
55699
|
return NO_UPDATE_STATUS;
|
|
55468
55700
|
}).finally(() => {
|
|
55469
55701
|
inFlight = null;
|