@dotobokuri/fleet-console 1.54.0 → 1.55.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.
Files changed (71) hide show
  1. package/AGENTS.md +1 -1
  2. package/dist/access-protocol.d.ts +58 -0
  3. package/dist/access-protocol.mjs +165 -0
  4. package/dist/cli.mjs +1207 -716
  5. package/dist/client/assets/{_baseUniq-B2XggV1b.js → _baseUniq-Cp0TuK00.js} +1 -1
  6. package/dist/client/assets/{arc-CPqvR_Wl.js → arc-Cwtz1wxV.js} +1 -1
  7. package/dist/client/assets/{architectureDiagram-Q4EWVU46-BczXSpod.js → architectureDiagram-Q4EWVU46-f2trvyEV.js} +1 -1
  8. package/dist/client/assets/{blockDiagram-DXYQGD6D-BPtW_zZR.js → blockDiagram-DXYQGD6D-BhEa9Mh6.js} +1 -1
  9. package/dist/client/assets/{c4Diagram-AHTNJAMY-Cry2oyLL.js → c4Diagram-AHTNJAMY-CuqbJbZK.js} +1 -1
  10. package/dist/client/assets/channel-D9kPbZ6w.js +1 -0
  11. package/dist/client/assets/{chunk-4BX2VUAB-DKkKt4m0.js → chunk-4BX2VUAB-Vx63wo1i.js} +1 -1
  12. package/dist/client/assets/{chunk-4TB4RGXK-DKGkDbqm.js → chunk-4TB4RGXK-DHRtIlLJ.js} +1 -1
  13. package/dist/client/assets/{chunk-55IACEB6-DawsVr8O.js → chunk-55IACEB6-ChTm2kCK.js} +1 -1
  14. package/dist/client/assets/{chunk-EDXVE4YY-tS8vRy63.js → chunk-EDXVE4YY-C_BQtaY5.js} +1 -1
  15. package/dist/client/assets/{chunk-FMBD7UC4-B0jQQkjI.js → chunk-FMBD7UC4-BPV9Mw6e.js} +1 -1
  16. package/dist/client/assets/{chunk-OYMX7WX6-FZQSRkEo.js → chunk-OYMX7WX6-ya-VyPHj.js} +1 -1
  17. package/dist/client/assets/{chunk-QZHKN3VN-Bq1WBmr8.js → chunk-QZHKN3VN-CLiSGdJ6.js} +1 -1
  18. package/dist/client/assets/{chunk-YZCP3GAM-CNWIYKHc.js → chunk-YZCP3GAM-DasGOM9R.js} +1 -1
  19. package/dist/client/assets/classDiagram-6PBFFD2Q-B1zyip5T.js +1 -0
  20. package/dist/client/assets/classDiagram-v2-HSJHXN6E-B1zyip5T.js +1 -0
  21. package/dist/client/assets/clone-x5mGq45q.js +1 -0
  22. package/dist/client/assets/{cose-bilkent-S5V4N54A-CmOaWS4P.js → cose-bilkent-S5V4N54A-C11PcGWz.js} +1 -1
  23. package/dist/client/assets/{dagre-KV5264BT-D2gJaf1o.js → dagre-KV5264BT-BGiNFCUB.js} +1 -1
  24. package/dist/client/assets/{diagram-5BDNPKRD-DH-M3VUk.js → diagram-5BDNPKRD-CSxK9ZtI.js} +1 -1
  25. package/dist/client/assets/{diagram-G4DWMVQ6-169IB8uN.js → diagram-G4DWMVQ6-COZtgx_6.js} +1 -1
  26. package/dist/client/assets/{diagram-MMDJMWI5-D1OVxCyQ.js → diagram-MMDJMWI5-4-mD0i99.js} +1 -1
  27. package/dist/client/assets/{diagram-TYMM5635-CkiS1glz.js → diagram-TYMM5635-BNX8i0L7.js} +1 -1
  28. package/dist/client/assets/{erDiagram-SMLLAGMA-CZUp7ncJ.js → erDiagram-SMLLAGMA-1a9K7CGs.js} +1 -1
  29. package/dist/client/assets/{flowDiagram-DWJPFMVM-9SIhR3aC.js → flowDiagram-DWJPFMVM-B7BZTT0P.js} +1 -1
  30. package/dist/client/assets/{ganttDiagram-T4ZO3ILL-CA4smcv3.js → ganttDiagram-T4ZO3ILL-FeCgSTyp.js} +1 -1
  31. package/dist/client/assets/{gitGraphDiagram-UUTBAWPF-DF8CSmoM.js → gitGraphDiagram-UUTBAWPF-ItC4KjyQ.js} +1 -1
  32. package/dist/client/assets/{graph-Bc_ceTI8.js → graph-C0wWu6sL.js} +1 -1
  33. package/dist/client/assets/{index-NNL49IzO.css → index-B0961B8M.css} +1 -1
  34. package/dist/client/assets/index-DEW90Ngb.js +479 -0
  35. package/dist/client/assets/{infoDiagram-42DDH7IO-BC5KSucM.js → infoDiagram-42DDH7IO-5ub69t3k.js} +1 -1
  36. package/dist/client/assets/{ishikawaDiagram-UXIWVN3A-JJIJclQD.js → ishikawaDiagram-UXIWVN3A-BEvDRmdo.js} +1 -1
  37. package/dist/client/assets/{journeyDiagram-VCZTEJTY-ERzBaHVf.js → journeyDiagram-VCZTEJTY-DUxQ-ZUX.js} +1 -1
  38. package/dist/client/assets/{kanban-definition-6JOO6SKY-KvnzNd3g.js → kanban-definition-6JOO6SKY-BiPkJbpE.js} +1 -1
  39. package/dist/client/assets/{layout-DJbQbTix.js → layout-Bhtd-qjm.js} +1 -1
  40. package/dist/client/assets/{linear-BzBkH5Aq.js → linear-BT8b8xym.js} +1 -1
  41. package/dist/client/assets/{mermaid.core-CAqwSbV2.js → mermaid.core-BlTpil8e.js} +4 -4
  42. package/dist/client/assets/{min-giSfwdiX.js → min-DrnMPIwV.js} +1 -1
  43. package/dist/client/assets/{mindmap-definition-QFDTVHPH-BH0wnMRm.js → mindmap-definition-QFDTVHPH-uQH7Nv45.js} +1 -1
  44. package/dist/client/assets/{pieDiagram-DEJITSTG-WOHMlPDe.js → pieDiagram-DEJITSTG-MOetI488.js} +1 -1
  45. package/dist/client/assets/{quadrantDiagram-34T5L4WZ-DcIpvIOj.js → quadrantDiagram-34T5L4WZ-C-jeoH4D.js} +1 -1
  46. package/dist/client/assets/{requirementDiagram-MS252O5E-C99uWiwG.js → requirementDiagram-MS252O5E-C7cKIVp5.js} +1 -1
  47. package/dist/client/assets/{sankeyDiagram-XADWPNL6-czWBcwBu.js → sankeyDiagram-XADWPNL6-Dcv2A0AY.js} +1 -1
  48. package/dist/client/assets/{sequenceDiagram-FGHM5R23-CjtCPppG.js → sequenceDiagram-FGHM5R23-CXO-xPvA.js} +1 -1
  49. package/dist/client/assets/{stateDiagram-FHFEXIEX-D0UKF8ze.js → stateDiagram-FHFEXIEX-GKivP2tt.js} +1 -1
  50. package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-BfnEUJRo.js +1 -0
  51. package/dist/client/assets/{timeline-definition-GMOUNBTQ-3isWQZNU.js → timeline-definition-GMOUNBTQ-DLJSUfwG.js} +1 -1
  52. package/dist/client/assets/{vennDiagram-DHZGUBPP-C_LF2g8l.js → vennDiagram-DHZGUBPP-DFihaprP.js} +1 -1
  53. package/dist/client/assets/{wardley-RL74JXVD-Bw0Y4M6p.js → wardley-RL74JXVD-BBV41M5Z.js} +1 -1
  54. package/dist/client/assets/{wardleyDiagram-NUSXRM2D-B6e3mxQI.js → wardleyDiagram-NUSXRM2D-B5J5AiY-.js} +1 -1
  55. package/dist/client/assets/{xychartDiagram-5P7HB3ND-DjlZXnLg.js → xychartDiagram-5P7HB3ND-D1NFEt18.js} +1 -1
  56. package/dist/client/index.html +2 -2
  57. package/dist/fleet-plugins/file-explorer/routes.mjs +13 -9
  58. package/dist/fleet-plugins/ledger/routes.mjs +6 -2
  59. package/dist/fleet-plugins/quota/routes.mjs +22 -18
  60. package/dist/fleet-plugins/repository/routes.mjs +17 -13
  61. package/dist/fleet-plugins/scuttlebutt/routes.mjs +13 -14
  62. package/dist/fleet-plugins/skills/routes.mjs +14 -10
  63. package/dist/fleet-plugins/terminal/routes.mjs +354 -314
  64. package/dist/fleet.mjs +3950 -3486
  65. package/package.json +5 -1
  66. package/dist/client/assets/channel-D5C5uwWd.js +0 -1
  67. package/dist/client/assets/classDiagram-6PBFFD2Q-Cv4Bxw_r.js +0 -1
  68. package/dist/client/assets/classDiagram-v2-HSJHXN6E-Cv4Bxw_r.js +0 -1
  69. package/dist/client/assets/clone-C7dthYDe.js +0 -1
  70. package/dist/client/assets/index-kTAFpDLu.js +0 -479
  71. package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-BdRUP2Pp.js +0 -1
@@ -26,10 +26,18 @@ var __export = (target2, all) => {
26
26
  function definePlugin(definition) {
27
27
  return definition;
28
28
  }
29
- function registerRouter(ctx, path42, handler) {
29
+ function registerRouter(ctx, path42, handler, catalog) {
30
+ if (catalog) {
31
+ ctx.registerRouter(normalizePath(path42), handler, catalog);
32
+ return;
33
+ }
30
34
  ctx.registerRouter(normalizePath(path42), handler);
31
35
  }
32
- function registerWsHandler(ctx, path42, handler) {
36
+ function registerWsHandler(ctx, path42, handler, catalog) {
37
+ if (catalog) {
38
+ ctx.registerWsHandler(normalizePath(path42), handler, catalog);
39
+ return;
40
+ }
33
41
  ctx.registerWsHandler(normalizePath(path42), handler);
34
42
  }
35
43
  function registerLaunchCatalog(ctx, provider) {
@@ -20113,6 +20121,8 @@ function cjkRatio(text2) {
20113
20121
  }
20114
20122
  var CLAUDE_COMPAT_CONTEXT_WINDOW = 1e6;
20115
20123
  var CLAUDE_DEFAULT_CONTEXT_WINDOW = 2e5;
20124
+ var CLAUDE_COMPACT_RESERVE = 32e3;
20125
+ var PROVIDER_COMPACT_RESERVE = 16e3;
20116
20126
  var DEFAULT_MAX_JSON_BYTES = 16 * 1024 * 1024;
20117
20127
  var DEFAULT_MAX_SSE_FRAME_BYTES = 1024 * 1024;
20118
20128
  var MAX_SSE_SEPARATOR_BYTES = 4;
@@ -20121,9 +20131,6 @@ var ANTHROPIC_INPUT_USAGE_FIELDS = [
20121
20131
  "cache_read_input_tokens",
20122
20132
  "cache_creation_input_tokens"
20123
20133
  ];
20124
- function canProjectClaudeContextWindow(contextWindow) {
20125
- return typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > CLAUDE_DEFAULT_CONTEXT_WINDOW;
20126
- }
20127
20134
  function isClaudeOneMillionContextWindow(contextWindow) {
20128
20135
  return typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow >= CLAUDE_COMPAT_CONTEXT_WINDOW;
20129
20136
  }
@@ -20134,18 +20141,21 @@ function stripClaudeOneMillionMarker(modelId) {
20134
20141
  return modelId.replace(/\[1m\]$/i, "");
20135
20142
  }
20136
20143
  function projectClaudeContextInputTokens(inputTokens, advertisedContextWindow, upstreamContextWindow = advertisedContextWindow) {
20137
- if (!Number.isFinite(inputTokens) || inputTokens < 0 || !canProjectClaudeContextWindow(advertisedContextWindow)) {
20138
- return inputTokens;
20139
- }
20140
- const projectionWindow = positiveContextWindow(upstreamContextWindow) ?? positiveContextWindow(advertisedContextWindow);
20141
- if (projectionWindow === void 0) return inputTokens;
20144
+ if (!Number.isFinite(inputTokens) || inputTokens < 0) return inputTokens;
20145
+ const advertisedWindow = positiveContextWindow(advertisedContextWindow);
20146
+ if (advertisedWindow === void 0) return inputTokens;
20147
+ const projectionWindow = positiveContextWindow(upstreamContextWindow) ?? advertisedWindow;
20148
+ const coordinate = advertisedWindow >= CLAUDE_COMPAT_CONTEXT_WINDOW ? CLAUDE_COMPAT_CONTEXT_WINDOW : CLAUDE_DEFAULT_CONTEXT_WINDOW;
20149
+ const claudeCompactThreshold = coordinate - CLAUDE_COMPACT_RESERVE;
20150
+ const providerCompactThreshold = projectionWindow - PROVIDER_COMPACT_RESERVE;
20151
+ if (providerCompactThreshold <= 0) return Math.min(coordinate, inputTokens);
20142
20152
  return Math.min(
20143
- CLAUDE_COMPAT_CONTEXT_WINDOW,
20144
- Math.ceil(inputTokens * CLAUDE_COMPAT_CONTEXT_WINDOW / projectionWindow)
20153
+ coordinate,
20154
+ Math.ceil(inputTokens * claudeCompactThreshold / providerCompactThreshold)
20145
20155
  );
20146
20156
  }
20147
20157
  async function* projectAnthropicResponseUsage(chunks, options) {
20148
- const contextWindow = canProjectClaudeContextWindow(options.contextWindow) ? options.contextWindow : void 0;
20158
+ const contextWindow = positiveContextWindow(options.contextWindow);
20149
20159
  const responseModel = typeof options.responseModel === "string" && options.responseModel.length > 0 ? options.responseModel : void 0;
20150
20160
  if (contextWindow === void 0 && responseModel === void 0) {
20151
20161
  yield* chunks;
@@ -20321,18 +20331,25 @@ function projectAnthropicUsageEnvelope(value, contextWindow, responseModel) {
20321
20331
  function projectUsageProperty(container, property, contextWindow) {
20322
20332
  const usage3 = container[property];
20323
20333
  if (!isRecord2(usage3)) return { changed: false, value: container };
20324
- let projectedUsage = usage3;
20325
- let changed = false;
20326
- for (const field of ANTHROPIC_INPUT_USAGE_FIELDS) {
20334
+ const coordinates = ANTHROPIC_INPUT_USAGE_FIELDS.map((field) => {
20327
20335
  const tokens = usage3[field];
20328
- if (typeof tokens !== "number" || !Number.isFinite(tokens) || tokens < 0) continue;
20329
- const projectedTokens = projectClaudeContextInputTokens(tokens, contextWindow);
20330
- if (projectedTokens === tokens) continue;
20331
- if (!changed) projectedUsage = { ...usage3 };
20332
- projectedUsage[field] = projectedTokens;
20333
- changed = true;
20334
- }
20335
- return changed ? { changed: true, value: { ...container, [property]: projectedUsage } } : { changed: false, value: container };
20336
+ return typeof tokens === "number" && Number.isFinite(tokens) && tokens >= 0 ? { field, tokens } : void 0;
20337
+ }).filter((entry) => entry !== void 0);
20338
+ if (coordinates.length === 0) return { changed: false, value: container };
20339
+ const total = coordinates.reduce((sum, entry) => sum + entry.tokens, 0);
20340
+ const projectedTotal = projectClaudeContextInputTokens(total, contextWindow);
20341
+ if (projectedTotal === total) return { changed: false, value: container };
20342
+ const projectedUsage = { ...usage3 };
20343
+ const remainderField = coordinates.some((entry) => entry.field === "input_tokens") ? "input_tokens" : coordinates[0].field;
20344
+ let assigned = 0;
20345
+ for (const entry of coordinates) {
20346
+ if (entry.field === remainderField) continue;
20347
+ const projectedTokens = total === 0 ? 0 : Math.floor(entry.tokens * projectedTotal / total);
20348
+ projectedUsage[entry.field] = projectedTokens;
20349
+ assigned += projectedTokens;
20350
+ }
20351
+ projectedUsage[remainderField] = projectedTotal - assigned;
20352
+ return { changed: true, value: { ...container, [property]: projectedUsage } };
20336
20353
  }
20337
20354
  function findSseSeparator(bytes) {
20338
20355
  for (let index = 0; index < bytes.byteLength - 1; index += 1) {
@@ -20999,10 +21016,6 @@ var KIMI_CODE_API_BASE_URL = "https://api.kimi.com/coding";
20999
21016
  var KIMI_CODE_MODEL = "k3";
21000
21017
  var GATEWAY_PROVIDERS = ["codex", "cursor", "kimi", "opencode"];
21001
21018
  var GATEWAY_MODEL_WIRES = ["anthropic", "responses", "chat-completions"];
21002
- function isAnthropicPassthroughModel(model) {
21003
- if (model.provider === "kimi") return true;
21004
- return model.provider === "opencode" && (model.wire ?? "anthropic") === "anthropic";
21005
- }
21006
21019
  var GATEWAY_REASONING_EFFORTS = [
21007
21020
  "low",
21008
21021
  "medium",
@@ -21138,10 +21151,7 @@ function toGatewayModelAlias(modelId) {
21138
21151
  }
21139
21152
  function toClaudeGatewayModelId(model) {
21140
21153
  const alias = toGatewayModelAlias(model.id);
21141
- if (canProjectClaudeContextWindow(model.contextWindow) && (!isAnthropicPassthroughModel(model) || isClaudeOneMillionContextWindow(model.contextWindow))) {
21142
- return `${alias}${CLAUDE_ONE_MILLION_MARKER}`;
21143
- }
21144
- return alias;
21154
+ return isClaudeOneMillionContextWindow(model.contextWindow) ? `${alias}${CLAUDE_ONE_MILLION_MARKER}` : alias;
21145
21155
  }
21146
21156
  function toClaudeGatewayModelDisplayName(model) {
21147
21157
  return isClaudeOneMillionContextWindow(model.contextWindow) ? `${model.displayName}${CLAUDE_ONE_MILLION_DISPLAY_SUFFIX}` : model.displayName;
@@ -22258,6 +22268,21 @@ function functionCallStart(item, index) {
22258
22268
  }
22259
22269
  };
22260
22270
  }
22271
+ function findCauseCode(error51) {
22272
+ let current = error51;
22273
+ const seen = /* @__PURE__ */ new Set();
22274
+ for (let depth = 0; depth <= 4; depth += 1) {
22275
+ if (current === null || typeof current !== "object") return void 0;
22276
+ if (seen.has(current)) return void 0;
22277
+ seen.add(current);
22278
+ if (Object.prototype.hasOwnProperty.call(current, "code")) {
22279
+ const code = current.code;
22280
+ if (typeof code === "string") return code;
22281
+ }
22282
+ current = current.cause;
22283
+ }
22284
+ return void 0;
22285
+ }
22261
22286
  var UpstreamBodyLimitError = class extends Error {
22262
22287
  constructor(maxBodyBytes) {
22263
22288
  super(`Upstream response exceeded ${maxBodyBytes} bytes`);
@@ -22348,6 +22373,51 @@ async function readWithIdleTimeout(reader, options) {
22348
22373
  );
22349
22374
  });
22350
22375
  }
22376
+ async function* parseUpstreamSseStream(body, options, parseFrame) {
22377
+ if (body === null) {
22378
+ options.onClose();
22379
+ throw new UpstreamProtocolError(options.missingBodyMessage);
22380
+ }
22381
+ const reader = body.getReader();
22382
+ const decoder = new TextDecoder();
22383
+ let buffer = "";
22384
+ let byteLength = 0;
22385
+ try {
22386
+ while (true) {
22387
+ const result = await readWithIdleTimeout(reader, options);
22388
+ if (result.done) {
22389
+ buffer += decoder.decode();
22390
+ break;
22391
+ }
22392
+ byteLength += result.value.byteLength;
22393
+ if (byteLength > options.maxBodyBytes) {
22394
+ const error51 = new UpstreamBodyLimitError(options.maxBodyBytes);
22395
+ options.controller.abort(error51);
22396
+ throw error51;
22397
+ }
22398
+ buffer += decoder.decode(result.value, { stream: true });
22399
+ let boundary = nextEventBoundary(buffer);
22400
+ while (boundary !== void 0) {
22401
+ const frame = buffer.slice(0, boundary.index);
22402
+ buffer = buffer.slice(boundary.index + boundary.length);
22403
+ const event = parseFrame(frame);
22404
+ if (event !== void 0) {
22405
+ yield event;
22406
+ }
22407
+ boundary = nextEventBoundary(buffer);
22408
+ }
22409
+ }
22410
+ if (buffer.trim().length > 0) {
22411
+ const event = parseFrame(buffer);
22412
+ if (event !== void 0) {
22413
+ yield event;
22414
+ }
22415
+ }
22416
+ } finally {
22417
+ await reader.cancel().catch(() => void 0);
22418
+ options.onClose();
22419
+ }
22420
+ }
22351
22421
  function nextEventBoundary(buffer) {
22352
22422
  const match = /\r\n\r\n|\n\n|\r\r/.exec(buffer);
22353
22423
  return match === null ? void 0 : { index: match.index, length: match[0].length };
@@ -22591,7 +22661,9 @@ var OpenAIResponsesAdapter = class {
22591
22661
  }
22592
22662
  };
22593
22663
  var CodexResponsesAdapter = class extends OpenAIResponsesAdapter {
22664
+ isMarkedFetchFailure;
22594
22665
  constructor(options = {}) {
22666
+ const fetchFailureTracker = createCodexFetchFailureTracker(options.fetch ?? globalThis.fetch.bind(globalThis));
22595
22667
  super({
22596
22668
  url: CHATGPT_CODEX_RESPONSES_URL,
22597
22669
  dropSamplingParams: true,
@@ -22599,11 +22671,12 @@ var CodexResponsesAdapter = class extends OpenAIResponsesAdapter {
22599
22671
  ...options.accountId ? { "chatgpt-account-id": options.accountId } : {},
22600
22672
  ...options.headers
22601
22673
  },
22602
- fetch: markCodexFetchFailures(options.fetch ?? globalThis.fetch.bind(globalThis)),
22674
+ fetch: fetchFailureTracker.fetch,
22603
22675
  // `!== undefined` 여야 명시적 0이 상속된 positiveInteger 검증을 통과한다.
22604
22676
  ...options.maxBodyBytes !== void 0 ? { maxBodyBytes: options.maxBodyBytes } : {},
22605
22677
  ...options.idleTimeoutMs !== void 0 ? { idleTimeoutMs: options.idleTimeoutMs } : {}
22606
22678
  });
22679
+ this.isMarkedFetchFailure = fetchFailureTracker.isMarkedFailure;
22607
22680
  }
22608
22681
  async stream(request, options) {
22609
22682
  const callController = new AbortController();
@@ -22614,7 +22687,7 @@ var CodexResponsesAdapter = class extends OpenAIResponsesAdapter {
22614
22687
  try {
22615
22688
  response = await super.stream(request, callOptions);
22616
22689
  } catch (error51) {
22617
- if (!isRetryableCodexFetchSocketTermination(error51, callOptions.signal)) {
22690
+ if (!isRetryableCodexFetchSocketTermination(error51, callOptions.signal, this.isMarkedFetchFailure)) {
22618
22691
  unlinkCallAbort();
22619
22692
  throw error51;
22620
22693
  }
@@ -22769,24 +22842,24 @@ function commitsCodexOutput(event) {
22769
22842
  return true;
22770
22843
  }
22771
22844
  }
22772
- var codexFetchFailures = /* @__PURE__ */ new WeakSet();
22773
- function markCodexFetchFailures(fetchImpl) {
22774
- return async (input, init) => {
22775
- try {
22776
- return await fetchImpl(input, init);
22777
- } catch (error51) {
22778
- if (error51 !== null && typeof error51 === "object") {
22779
- codexFetchFailures.add(error51);
22845
+ function createCodexFetchFailureTracker(fetchImpl) {
22846
+ const fetchFailures = /* @__PURE__ */ new WeakSet();
22847
+ return {
22848
+ fetch: async (input, init) => {
22849
+ try {
22850
+ return await fetchImpl(input, init);
22851
+ } catch (error51) {
22852
+ if (error51 !== null && typeof error51 === "object") {
22853
+ fetchFailures.add(error51);
22854
+ }
22855
+ throw error51;
22780
22856
  }
22781
- throw error51;
22782
- }
22857
+ },
22858
+ isMarkedFailure: (error51) => error51 !== null && typeof error51 === "object" && fetchFailures.has(error51)
22783
22859
  };
22784
22860
  }
22785
- function isRetryableCodexFetchSocketTermination(error51, signal) {
22786
- return signal?.aborted !== true && isMarkedCodexFetchFailure(error51) && isUndiciSocketTermination(error51);
22787
- }
22788
- function isMarkedCodexFetchFailure(error51) {
22789
- return error51 !== null && typeof error51 === "object" && codexFetchFailures.has(error51);
22861
+ function isRetryableCodexFetchSocketTermination(error51, signal, isMarkedFailure) {
22862
+ return signal?.aborted !== true && isMarkedFailure(error51) && isUndiciSocketTermination(error51);
22790
22863
  }
22791
22864
  function isUndiciSocketTermination(error51) {
22792
22865
  const seen = /* @__PURE__ */ new Set();
@@ -22902,50 +22975,12 @@ function isClaudeCodeSuggestionMode(request) {
22902
22975
  const last = request.input.at(-1);
22903
22976
  return last?.type === "message" && last.role === "user" && typeof last.content === "string" && last.content.startsWith(CLAUDE_CODE_SUGGESTION_MODE_PREFIX);
22904
22977
  }
22905
- async function* parseOpenAIEventStream(body, options) {
22906
- if (body === null) {
22907
- options.onClose();
22908
- throw new UpstreamProtocolError("OpenAI streaming response had no body");
22909
- }
22910
- const reader = body.getReader();
22911
- const decoder = new TextDecoder();
22912
- let buffer = "";
22913
- let byteLength = 0;
22914
- try {
22915
- while (true) {
22916
- const result = await readWithIdleTimeout(reader, options);
22917
- if (result.done) {
22918
- buffer += decoder.decode();
22919
- break;
22920
- }
22921
- byteLength += result.value.byteLength;
22922
- if (byteLength > options.maxBodyBytes) {
22923
- const error51 = new UpstreamBodyLimitError(options.maxBodyBytes);
22924
- options.controller.abort(error51);
22925
- throw error51;
22926
- }
22927
- buffer += decoder.decode(result.value, { stream: true });
22928
- let boundary = nextEventBoundary(buffer);
22929
- while (boundary !== void 0) {
22930
- const frame = buffer.slice(0, boundary.index);
22931
- buffer = buffer.slice(boundary.index + boundary.length);
22932
- const event = parseEventFrame(frame);
22933
- if (event !== void 0) {
22934
- yield event;
22935
- }
22936
- boundary = nextEventBoundary(buffer);
22937
- }
22938
- }
22939
- if (buffer.trim().length > 0) {
22940
- const event = parseEventFrame(buffer);
22941
- if (event !== void 0) {
22942
- yield event;
22943
- }
22944
- }
22945
- } finally {
22946
- await reader.cancel().catch(() => void 0);
22947
- options.onClose();
22948
- }
22978
+ function parseOpenAIEventStream(body, options) {
22979
+ return parseUpstreamSseStream(
22980
+ body,
22981
+ { ...options, missingBodyMessage: "OpenAI streaming response had no body" },
22982
+ parseEventFrame
22983
+ );
22949
22984
  }
22950
22985
  function parseEventFrame(frame) {
22951
22986
  const { event: eventName, data } = parseSseFrameFields(frame);
@@ -24394,50 +24429,12 @@ function forOpenCodeGoResponsesBackend(request) {
24394
24429
  }
24395
24430
  return payload;
24396
24431
  }
24397
- async function* parseOpenCodeGoEventStream(body, options) {
24398
- if (body === null) {
24399
- options.onClose();
24400
- throw new UpstreamProtocolError("OpenCode Go streaming response had no body");
24401
- }
24402
- const reader = body.getReader();
24403
- const decoder = new TextDecoder();
24404
- let buffer = "";
24405
- let byteLength = 0;
24406
- try {
24407
- while (true) {
24408
- const result = await readWithIdleTimeout(reader, options);
24409
- if (result.done) {
24410
- buffer += decoder.decode();
24411
- break;
24412
- }
24413
- byteLength += result.value.byteLength;
24414
- if (byteLength > options.maxBodyBytes) {
24415
- const error51 = new UpstreamBodyLimitError(options.maxBodyBytes);
24416
- options.controller.abort(error51);
24417
- throw error51;
24418
- }
24419
- buffer += decoder.decode(result.value, { stream: true });
24420
- let boundary = nextEventBoundary(buffer);
24421
- while (boundary !== void 0) {
24422
- const frame = buffer.slice(0, boundary.index);
24423
- buffer = buffer.slice(boundary.index + boundary.length);
24424
- const event = parseEventFrame2(frame);
24425
- if (event !== void 0) {
24426
- yield event;
24427
- }
24428
- boundary = nextEventBoundary(buffer);
24429
- }
24430
- }
24431
- if (buffer.trim().length > 0) {
24432
- const event = parseEventFrame2(buffer);
24433
- if (event !== void 0) {
24434
- yield event;
24435
- }
24436
- }
24437
- } finally {
24438
- await reader.cancel().catch(() => void 0);
24439
- options.onClose();
24440
- }
24432
+ function parseOpenCodeGoEventStream(body, options) {
24433
+ return parseUpstreamSseStream(
24434
+ body,
24435
+ { ...options, missingBodyMessage: "OpenCode Go streaming response had no body" },
24436
+ parseEventFrame2
24437
+ );
24441
24438
  }
24442
24439
  function parseEventFrame2(frame) {
24443
24440
  const { event: eventName, data } = parseSseFrameFields(frame);
@@ -25076,6 +25073,133 @@ function stringValue(value) {
25076
25073
  function isRecord7(value) {
25077
25074
  return typeof value === "object" && value !== null && !Array.isArray(value);
25078
25075
  }
25076
+ var EXECUTE_HOOK_FIELD_NUMBER = 27;
25077
+ var EXEC_CLIENT_MESSAGE_FIELD_NUMBER = 2;
25078
+ var EXEC_CLIENT_CONTROL_MESSAGE_FIELD_NUMBER = 5;
25079
+ var SUPPORTED_HOOK_CASES = /* @__PURE__ */ new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 11]);
25080
+ function cursorUnknownExecReply(exec2, unknownFields) {
25081
+ const executeHook = unknownFields.find(
25082
+ (field) => field.no === EXECUTE_HOOK_FIELD_NUMBER && field.wireType === WireType.LengthDelimited
25083
+ );
25084
+ if (executeHook) {
25085
+ const hookCase = executeHookRequestCase(executeHook);
25086
+ if (hookCase !== void 0 && SUPPORTED_HOOK_CASES.has(hookCase)) {
25087
+ return {
25088
+ payloads: [executeHookReply(exec2, hookCase)],
25089
+ replyKind: "exec.policy.executeHookArgs"
25090
+ };
25091
+ }
25092
+ }
25093
+ const caseName = cursorUnknownExecCaseName(unknownFields);
25094
+ return {
25095
+ payloads: unsupportedExecReplies(
25096
+ exec2,
25097
+ `Fleet AI Gateway cannot handle Cursor native exec ${caseName}; retry with an advertised client tool.`
25098
+ ),
25099
+ replyKind: `exec.control.${caseName}`
25100
+ };
25101
+ }
25102
+ function cursorUnknownExecCaseName(unknownFields) {
25103
+ const fieldNumbers = [...new Set(
25104
+ unknownFields.filter((field) => field.wireType === WireType.LengthDelimited).map((field) => field.no)
25105
+ )].sort((left, right) => left - right);
25106
+ if (fieldNumbers.includes(EXECUTE_HOOK_FIELD_NUMBER)) return "executeHookArgs";
25107
+ return fieldNumbers.length > 0 ? `unknownField${fieldNumbers.join("-")}` : "unknown";
25108
+ }
25109
+ function executeHookRequestCase(field) {
25110
+ const args = lengthDelimitedPayload(field);
25111
+ if (!args) return void 0;
25112
+ const request = embeddedMessage(args, 1);
25113
+ if (!request) return void 0;
25114
+ try {
25115
+ const reader = new BinaryReader(request);
25116
+ while (reader.pos < reader.len) {
25117
+ const [fieldNumber, wireType] = reader.tag();
25118
+ if (wireType === WireType.LengthDelimited) return fieldNumber;
25119
+ reader.skip(wireType, fieldNumber);
25120
+ }
25121
+ } catch {
25122
+ return void 0;
25123
+ }
25124
+ return void 0;
25125
+ }
25126
+ function lengthDelimitedPayload(field) {
25127
+ try {
25128
+ const reader = new BinaryReader(field.data);
25129
+ const payload = reader.bytes();
25130
+ return reader.pos === reader.len ? payload : void 0;
25131
+ } catch {
25132
+ return void 0;
25133
+ }
25134
+ }
25135
+ function embeddedMessage(message, wantedFieldNumber) {
25136
+ try {
25137
+ const reader = new BinaryReader(message);
25138
+ while (reader.pos < reader.len) {
25139
+ const [fieldNumber, wireType] = reader.tag();
25140
+ if (fieldNumber === wantedFieldNumber && wireType === WireType.LengthDelimited) {
25141
+ return reader.bytes();
25142
+ }
25143
+ reader.skip(wireType, fieldNumber);
25144
+ }
25145
+ } catch {
25146
+ return void 0;
25147
+ }
25148
+ return void 0;
25149
+ }
25150
+ function executeHookReply(exec2, hookCase) {
25151
+ const response = encodeMessage((writer) => {
25152
+ writer.tag(hookCase, WireType.LengthDelimited).bytes(new Uint8Array());
25153
+ });
25154
+ const result = encodeMessage((writer) => {
25155
+ writer.tag(1, WireType.LengthDelimited).bytes(response);
25156
+ });
25157
+ const execClientMessage = encodeMessage((writer) => {
25158
+ writer.tag(1, WireType.Varint).uint32(unknownExecUint32Value(exec2.id));
25159
+ const execId = unknownExecStringValue(exec2.execId);
25160
+ if (execId) writer.tag(15, WireType.LengthDelimited).string(execId);
25161
+ writer.tag(EXECUTE_HOOK_FIELD_NUMBER, WireType.LengthDelimited).bytes(result);
25162
+ });
25163
+ return encodeMessage((writer) => {
25164
+ writer.tag(EXEC_CLIENT_MESSAGE_FIELD_NUMBER, WireType.LengthDelimited).bytes(execClientMessage);
25165
+ });
25166
+ }
25167
+ function unsupportedExecReplies(exec2, error51) {
25168
+ const id = unknownExecUint32Value(exec2.id);
25169
+ const execThrow = encodeMessage((writer) => {
25170
+ writer.tag(1, WireType.Varint).uint32(id);
25171
+ writer.tag(2, WireType.LengthDelimited).string(error51);
25172
+ });
25173
+ const streamClose = encodeMessage((writer) => {
25174
+ writer.tag(1, WireType.Varint).uint32(id);
25175
+ });
25176
+ return [
25177
+ encodeControlMessage(2, execThrow),
25178
+ encodeControlMessage(1, streamClose)
25179
+ ];
25180
+ }
25181
+ function encodeControlMessage(caseNumber, value) {
25182
+ const control = encodeMessage((writer) => {
25183
+ writer.tag(caseNumber, WireType.LengthDelimited).bytes(value);
25184
+ });
25185
+ return encodeMessage((writer) => {
25186
+ writer.tag(EXEC_CLIENT_CONTROL_MESSAGE_FIELD_NUMBER, WireType.LengthDelimited).bytes(control);
25187
+ });
25188
+ }
25189
+ function encodeMessage(write) {
25190
+ const writer = new BinaryWriter();
25191
+ write(writer);
25192
+ return writer.finish();
25193
+ }
25194
+ function unknownExecUint32Value(value) {
25195
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 4294967295) {
25196
+ return value;
25197
+ }
25198
+ return 0;
25199
+ }
25200
+ function unknownExecStringValue(value) {
25201
+ return typeof value === "string" ? value : "";
25202
+ }
25079
25203
  var READ_CANDIDATES = ["Read"];
25080
25204
  var GREP_CANDIDATES = ["Grep"];
25081
25205
  var SHELL_CANDIDATES = ["Bash", "shell_command", "exec_command"];
@@ -25718,133 +25842,6 @@ function stringValue2(value) {
25718
25842
  function isRecord8(value) {
25719
25843
  return typeof value === "object" && value !== null && !Array.isArray(value);
25720
25844
  }
25721
- var EXECUTE_HOOK_FIELD_NUMBER = 27;
25722
- var EXEC_CLIENT_MESSAGE_FIELD_NUMBER = 2;
25723
- var EXEC_CLIENT_CONTROL_MESSAGE_FIELD_NUMBER = 5;
25724
- var SUPPORTED_HOOK_CASES = /* @__PURE__ */ new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 11]);
25725
- function cursorUnknownExecReply(exec2, unknownFields) {
25726
- const executeHook = unknownFields.find(
25727
- (field) => field.no === EXECUTE_HOOK_FIELD_NUMBER && field.wireType === WireType.LengthDelimited
25728
- );
25729
- if (executeHook) {
25730
- const hookCase = executeHookRequestCase(executeHook);
25731
- if (hookCase !== void 0 && SUPPORTED_HOOK_CASES.has(hookCase)) {
25732
- return {
25733
- payloads: [executeHookReply(exec2, hookCase)],
25734
- replyKind: "exec.policy.executeHookArgs"
25735
- };
25736
- }
25737
- }
25738
- const caseName = cursorUnknownExecCaseName(unknownFields);
25739
- return {
25740
- payloads: unsupportedExecReplies(
25741
- exec2,
25742
- `Fleet AI Gateway cannot handle Cursor native exec ${caseName}; retry with an advertised client tool.`
25743
- ),
25744
- replyKind: `exec.control.${caseName}`
25745
- };
25746
- }
25747
- function cursorUnknownExecCaseName(unknownFields) {
25748
- const fieldNumbers = [...new Set(
25749
- unknownFields.filter((field) => field.wireType === WireType.LengthDelimited).map((field) => field.no)
25750
- )].sort((left, right) => left - right);
25751
- if (fieldNumbers.includes(EXECUTE_HOOK_FIELD_NUMBER)) return "executeHookArgs";
25752
- return fieldNumbers.length > 0 ? `unknownField${fieldNumbers.join("-")}` : "unknown";
25753
- }
25754
- function executeHookRequestCase(field) {
25755
- const args = lengthDelimitedPayload(field);
25756
- if (!args) return void 0;
25757
- const request = embeddedMessage(args, 1);
25758
- if (!request) return void 0;
25759
- try {
25760
- const reader = new BinaryReader(request);
25761
- while (reader.pos < reader.len) {
25762
- const [fieldNumber, wireType] = reader.tag();
25763
- if (wireType === WireType.LengthDelimited) return fieldNumber;
25764
- reader.skip(wireType, fieldNumber);
25765
- }
25766
- } catch {
25767
- return void 0;
25768
- }
25769
- return void 0;
25770
- }
25771
- function lengthDelimitedPayload(field) {
25772
- try {
25773
- const reader = new BinaryReader(field.data);
25774
- const payload = reader.bytes();
25775
- return reader.pos === reader.len ? payload : void 0;
25776
- } catch {
25777
- return void 0;
25778
- }
25779
- }
25780
- function embeddedMessage(message, wantedFieldNumber) {
25781
- try {
25782
- const reader = new BinaryReader(message);
25783
- while (reader.pos < reader.len) {
25784
- const [fieldNumber, wireType] = reader.tag();
25785
- if (fieldNumber === wantedFieldNumber && wireType === WireType.LengthDelimited) {
25786
- return reader.bytes();
25787
- }
25788
- reader.skip(wireType, fieldNumber);
25789
- }
25790
- } catch {
25791
- return void 0;
25792
- }
25793
- return void 0;
25794
- }
25795
- function executeHookReply(exec2, hookCase) {
25796
- const response = encodeMessage((writer) => {
25797
- writer.tag(hookCase, WireType.LengthDelimited).bytes(new Uint8Array());
25798
- });
25799
- const result = encodeMessage((writer) => {
25800
- writer.tag(1, WireType.LengthDelimited).bytes(response);
25801
- });
25802
- const execClientMessage = encodeMessage((writer) => {
25803
- writer.tag(1, WireType.Varint).uint32(uint32Value(exec2.id));
25804
- const execId = stringValue3(exec2.execId);
25805
- if (execId) writer.tag(15, WireType.LengthDelimited).string(execId);
25806
- writer.tag(EXECUTE_HOOK_FIELD_NUMBER, WireType.LengthDelimited).bytes(result);
25807
- });
25808
- return encodeMessage((writer) => {
25809
- writer.tag(EXEC_CLIENT_MESSAGE_FIELD_NUMBER, WireType.LengthDelimited).bytes(execClientMessage);
25810
- });
25811
- }
25812
- function unsupportedExecReplies(exec2, error51) {
25813
- const id = uint32Value(exec2.id);
25814
- const execThrow = encodeMessage((writer) => {
25815
- writer.tag(1, WireType.Varint).uint32(id);
25816
- writer.tag(2, WireType.LengthDelimited).string(error51);
25817
- });
25818
- const streamClose = encodeMessage((writer) => {
25819
- writer.tag(1, WireType.Varint).uint32(id);
25820
- });
25821
- return [
25822
- encodeControlMessage(2, execThrow),
25823
- encodeControlMessage(1, streamClose)
25824
- ];
25825
- }
25826
- function encodeControlMessage(caseNumber, value) {
25827
- const control = encodeMessage((writer) => {
25828
- writer.tag(caseNumber, WireType.LengthDelimited).bytes(value);
25829
- });
25830
- return encodeMessage((writer) => {
25831
- writer.tag(EXEC_CLIENT_CONTROL_MESSAGE_FIELD_NUMBER, WireType.LengthDelimited).bytes(control);
25832
- });
25833
- }
25834
- function encodeMessage(write) {
25835
- const writer = new BinaryWriter();
25836
- write(writer);
25837
- return writer.finish();
25838
- }
25839
- function uint32Value(value) {
25840
- if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= 4294967295) {
25841
- return value;
25842
- }
25843
- return 0;
25844
- }
25845
- function stringValue3(value) {
25846
- return typeof value === "string" ? value : "";
25847
- }
25848
25845
  var cursorAgentDescriptor = [
25849
25846
  "CgthZ2VudC5wcm90bxIIYWdlbnQudjEicgoOR2xvYlRvb2xSZXN1bHQSLAoHc3VjY2VzcxgBIAEoCzIZLmFnZW50LnYxLkdsb2JUb29sU3VjY2Vzc0gAEigK",
25850
25847
  "BWVycm9yGAIgASgLMhcuYWdlbnQudjEuR2xvYlRvb2xFcnJvckgAQggKBnJlc3VsdCIeCg1HbG9iVG9vbEVycm9yEg0KBWVycm9yGAEgASgJIokBCg9HbG9i",
@@ -28765,9 +28762,9 @@ function cursorInteractionQueryReply(query) {
28765
28762
  });
28766
28763
  if (isRecord9(query.createPlanRequestQuery)) {
28767
28764
  const args = isRecord9(query.createPlanRequestQuery.args) ? query.createPlanRequestQuery.args : void 0;
28768
- const name = stringValue4(args?.name)?.trim();
28769
- const overview = stringValue4(args?.overview)?.trim();
28770
- const plan = stringValue4(args?.plan)?.trim();
28765
+ const name = stringValue3(args?.name)?.trim();
28766
+ const overview = stringValue3(args?.overview)?.trim();
28767
+ const plan = stringValue3(args?.plan)?.trim();
28771
28768
  const parts = [
28772
28769
  name ? `Plan: ${name}` : void 0,
28773
28770
  overview || void 0,
@@ -28922,16 +28919,16 @@ function mcpCallFromToolUpdate(value) {
28922
28919
  const toolCall = isRecord9(value.toolCall) ? value.toolCall : void 0;
28923
28920
  const args = toolCall ? mcpArgsFromToolCall(toolCall) : void 0;
28924
28921
  if (!args) return null;
28925
- const publicCallId = stringValue4(value.callId);
28926
- const toolCallId = stringValue4(args.toolCallId);
28922
+ const publicCallId = stringValue3(value.callId);
28923
+ const toolCallId = stringValue3(args.toolCallId);
28927
28924
  const callId = publicCallId ?? toolCallId;
28928
28925
  if (!callId) return null;
28929
28926
  return {
28930
28927
  callId,
28931
28928
  ...publicCallId ? { publicCallId } : {},
28932
28929
  ...toolCallId ? { toolCallId } : {},
28933
- name: stringValue4(args?.toolName) ?? stringValue4(args?.name) ?? "tool",
28934
- ...stringValue4(args?.providerIdentifier) ? { providerIdentifier: stringValue4(args?.providerIdentifier) } : {},
28930
+ name: stringValue3(args?.toolName) ?? stringValue3(args?.name) ?? "tool",
28931
+ ...stringValue3(args?.providerIdentifier) ? { providerIdentifier: stringValue3(args?.providerIdentifier) } : {},
28935
28932
  ...args ? cursorMcpArguments(args) : {}
28936
28933
  };
28937
28934
  }
@@ -28983,18 +28980,18 @@ function isCursorParkedResidueFrame(frame, parked) {
28983
28980
  function mcpCallFromExecMessage(value) {
28984
28981
  const args = isRecord9(value.mcpArgs) ? value.mcpArgs : void 0;
28985
28982
  if (!args) return null;
28986
- const toolCallId = stringValue4(args.toolCallId);
28983
+ const toolCallId = stringValue3(args.toolCallId);
28987
28984
  if (!toolCallId) return null;
28988
28985
  const rawMessageId = value.id ?? 0;
28989
28986
  const messageId = typeof rawMessageId === "number" && Number.isSafeInteger(rawMessageId) ? rawMessageId : void 0;
28990
- const execId = stringValue4(value.execId);
28987
+ const execId = stringValue3(value.execId);
28991
28988
  return {
28992
28989
  callId: toolCallId,
28993
28990
  toolCallId,
28994
28991
  ...messageId === void 0 ? {} : { messageId },
28995
28992
  ...execId ? { execId } : {},
28996
- name: stringValue4(args.toolName) ?? stringValue4(args.name) ?? "tool",
28997
- ...stringValue4(args.providerIdentifier) ? { providerIdentifier: stringValue4(args.providerIdentifier) } : {},
28993
+ name: stringValue3(args.toolName) ?? stringValue3(args.name) ?? "tool",
28994
+ ...stringValue3(args.providerIdentifier) ? { providerIdentifier: stringValue3(args.providerIdentifier) } : {},
28998
28995
  ...cursorMcpArguments(args)
28999
28996
  };
29000
28997
  }
@@ -29072,7 +29069,7 @@ function completeJson(value) {
29072
29069
  return void 0;
29073
29070
  }
29074
29071
  }
29075
- function stringValue4(value) {
29072
+ function stringValue3(value) {
29076
29073
  return typeof value === "string" && value.length > 0 ? value : void 0;
29077
29074
  }
29078
29075
  function cursorError(value) {
@@ -29499,24 +29496,9 @@ data: ${data}
29499
29496
  } catch {
29500
29497
  }
29501
29498
  }
29502
- function findCauseCode2(error51) {
29503
- let current = error51;
29504
- const seen = /* @__PURE__ */ new Set();
29505
- for (let depth = 0; depth <= 4; depth += 1) {
29506
- if (current === null || typeof current !== "object") return void 0;
29507
- if (seen.has(current)) return void 0;
29508
- seen.add(current);
29509
- if (Object.prototype.hasOwnProperty.call(current, "code")) {
29510
- const code = current.code;
29511
- if (typeof code === "string") return code;
29512
- }
29513
- current = current.cause;
29514
- }
29515
- return void 0;
29516
- }
29517
29499
  function errorMessage(error51) {
29518
29500
  const message = error51 instanceof Error ? error51.message : String(error51);
29519
- const code = findCauseCode2(error51);
29501
+ const code = findCauseCode(error51);
29520
29502
  return code !== void 0 && !message.includes(code) ? `${message} (${code})` : message;
29521
29503
  }
29522
29504
  function isOpencodeAnthropicPassthrough(model) {
@@ -29691,7 +29673,7 @@ function createAiGatewayRouter(deps) {
29691
29673
  await proxyToAnthropic(req.headers, res, body, fetchImpl, controller.signal);
29692
29674
  return true;
29693
29675
  }
29694
- const claudeContextWindow = hasClaudeOneMillionMarker(toClaudeGatewayModelId(target2)) ? target2.contextWindow : void 0;
29676
+ const claudeContextWindow = target2.contextWindow;
29695
29677
  if (target2.provider === "kimi") {
29696
29678
  await proxyToKimi(
29697
29679
  req.headers,
@@ -29960,6 +29942,9 @@ function prepareAiGatewayLaunchProfile(profile, options) {
29960
29942
  ANTHROPIC_BASE_URL: options.baseUrl,
29961
29943
  // 이게 있어야 /model picker가 게이트웨이의 GET /v1/models를 조회한다.
29962
29944
  CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY: "1",
29945
+ // 1M ceiling은 `[1m]` 모델의 선제 압축을 켜고, unmarked custom model에서는
29946
+ // Claude Code의 200k 좌표로 clamp된다. 명시적 운영자 override는 보존한다.
29947
+ CLAUDE_CODE_AUTO_COMPACT_WINDOW: profile.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW ?? "1000000",
29963
29948
  // Gateway가 tool_reference 계약을 보존한다. Cursor는 이를 지연 catalog 선택에 쓰고,
29964
29949
  // 호환 프로바이더 경계는 각자의 eager wire 형식으로 정규화한다.
29965
29950
  ENABLE_TOOL_SEARCH: "true"
@@ -33550,7 +33535,7 @@ async function writeWikiEntryAtTarget(entry, target2, paths) {
33550
33535
  throw new Error("wiki patch body id must match target filename");
33551
33536
  }
33552
33537
  await mkdir(path18__default.dirname(absoluteTarget), { recursive: true });
33553
- await writeMarkdownAtomic(absoluteTarget, serializeWikiEntry(entry), paths);
33538
+ await writeAtomic(absoluteTarget, serializeWikiEntry(entry), paths);
33554
33539
  return path18__default.join("wiki", relativeTarget).replaceAll(path18__default.sep, "/");
33555
33540
  }
33556
33541
  async function writeRawSourceEntry(entry, paths) {
@@ -33570,7 +33555,7 @@ async function writeRawSourceEntry(entry, paths) {
33570
33555
  },
33571
33556
  entry.content
33572
33557
  );
33573
- await writeMarkdownAtomic(path18__default.join(paths.root, relativePath), content, paths);
33558
+ await writeAtomic(path18__default.join(paths.root, relativePath), content, paths);
33574
33559
  return relativePath;
33575
33560
  }
33576
33561
  async function readRawSourceEntry(rawSourceRef, paths) {
@@ -33618,7 +33603,7 @@ async function rebuildIndex(paths) {
33618
33603
  entryPathMap[item.entry.id] = item.path;
33619
33604
  }
33620
33605
  await writeJsonAtomic(paths.indexFile, nextIndex, paths);
33621
- await writeMarkdownAtomic(getIndexMarkdownFile(paths), renderIndexMarkdown(entries.map((item) => item.entry), entryPathMap), paths);
33606
+ await writeAtomic(getIndexMarkdownFile(paths), renderIndexMarkdown(entries.map((item) => item.entry), entryPathMap), paths);
33622
33607
  await appendLog(paths, "index rebuilt", { entry_count: entries.length });
33623
33608
  return nextIndex;
33624
33609
  }
@@ -33698,7 +33683,7 @@ async function readPatchFile(filePath) {
33698
33683
  return readFile(filePath, "utf8");
33699
33684
  }
33700
33685
  async function writePatchFile(filePath, content, paths) {
33701
- await writeMarkdownAtomic(filePath, content, paths);
33686
+ await writeAtomic(filePath, content, paths);
33702
33687
  }
33703
33688
  async function readJsonFile2(filePath) {
33704
33689
  const raw = await readFile(filePath, "utf8");
@@ -33965,9 +33950,6 @@ function isFrontmatterBlock(rawFrontmatter) {
33965
33950
  }
33966
33951
  return keys.has("id") && keys.has("title");
33967
33952
  }
33968
- async function writeMarkdownAtomic(filePath, content, paths) {
33969
- await writeAtomic(filePath, content, paths);
33970
- }
33971
33953
  async function writeJsonAtomic(filePath, value, paths) {
33972
33954
  await writeAtomic(filePath, JSON.stringify(value, null, 2), paths);
33973
33955
  }
@@ -44098,6 +44080,7 @@ function claudeGatewayLaunchEnv(inherited, options) {
44098
44080
  env.CLAUDE_SECURESTORAGE_CONFIG_DIR = "";
44099
44081
  env.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1";
44100
44082
  env.ENABLE_TOOL_SEARCH = "true";
44083
+ env.CLAUDE_CODE_AUTO_COMPACT_WINDOW ??= "1000000";
44101
44084
  delete env.ANTHROPIC_AUTH_TOKEN;
44102
44085
  delete env.ANTHROPIC_API_KEY;
44103
44086
  delete env.ANTHROPIC_MODEL;
@@ -45267,7 +45250,10 @@ function registerTerminalSettingsRoutes(ctx, deps) {
45267
45250
  }
45268
45251
  ctx.host.http.writeJson(res, 405, { error: "Method not allowed" });
45269
45252
  return true;
45270
- });
45253
+ }, [
45254
+ { method: "GET", path: "", summary: "Read Terminal plugin settings.", category: "Terminal Plugin", gate: "loopback", transport: "http" },
45255
+ { method: "PUT", path: "", summary: "Save Terminal plugin settings.", category: "Terminal Plugin", gate: "origin-write", transport: "http" }
45256
+ ]);
45271
45257
  }
45272
45258
  function toTerminalSettingsState(data, aiGateway, wireLogEnabled2) {
45273
45259
  const configured = (aiGateway.models?.length ?? 0) > 0 || (aiGateway.providerPriority?.length ?? 0) > 0;
@@ -45364,7 +45350,23 @@ async function registerAgentRoutes(ctx, terminalRuntime, deps) {
45364
45350
  await api.handleExit(operationId);
45365
45351
  });
45366
45352
  ctx.host.lifecycle.registerCleanup(api.cleanup);
45367
- registerRouter(ctx, "agent", api.handle);
45353
+ registerRouter(ctx, "agent", api.handle, [
45354
+ { method: "GET", path: "/state", summary: "Read Agent session state.", category: "Terminal Plugin", gate: "loopback", transport: "http" },
45355
+ { method: "GET", path: "/agent-cli/state", summary: "Read installed Agent CLI status.", category: "Terminal Plugin", gate: "loopback", transport: "http" },
45356
+ { method: "GET", path: "/agent-cli/diagnostics", summary: "Read Agent CLI diagnostics.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45357
+ { method: "PUT", path: "/agent-cli/path", summary: "Save an Agent CLI executable path.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45358
+ { method: "GET", path: "/events", summary: "Stream Agent session events.", category: "Terminal Plugin", gate: "loopback", transport: "sse" },
45359
+ { method: "GET", path: "/sessions", summary: "List Agent sessions.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45360
+ { method: "POST", path: "/sessions", summary: "Create an Agent session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45361
+ { method: "DELETE", path: "/sessions/:sessionId", summary: "Delete an Agent session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45362
+ { method: "POST", path: "/sessions/:sessionId/resume", summary: "Resume an Agent session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
45363
+ { method: "POST", path: "/sessions/:sessionId/turn", summary: "Receive an Agent turn hook.", category: "Terminal Plugin", gate: "lock-token", transport: "http" },
45364
+ { method: "POST", path: "/sessions/:sessionId/background", summary: "Receive an Agent background-task hook.", category: "Terminal Plugin", gate: "lock-token", transport: "http" },
45365
+ { method: "POST", path: "/sessions/:sessionId/attention", summary: "Receive an Agent attention hook.", category: "Terminal Plugin", gate: "lock-token", transport: "http" },
45366
+ { method: "POST", path: "/sessions/:sessionId/auto-name", summary: "Receive an Agent auto-name hook.", category: "Terminal Plugin", gate: "lock-token", transport: "http" },
45367
+ { method: "POST", path: "/sessions/:sessionId/capture", summary: "Receive an Agent session capture hook.", category: "Terminal Plugin", gate: "lock-token", transport: "http" },
45368
+ { method: "POST", path: "/ticket", summary: "Issue an Agent Terminal WebSocket ticket.", category: "Terminal Plugin", gate: "origin-write", transport: "http" }
45369
+ ]);
45368
45370
  return api.launchKinds;
45369
45371
  }
45370
45372
  function buildAgentLaunchKindBackfillPatch(operation) {
@@ -45680,7 +45682,11 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45680
45682
  // toOperationPayload가 지우는 키 목록 밖이라 resume·복원을 지나도 그대로 남는다.
45681
45683
  payload: {
45682
45684
  ...toOperationPayload(void 0, cwd, session),
45683
- [AGENT_LAUNCH_PROVIDER_PAYLOAD_KEY]: agentLaunchProviderFromModel(launchOptions.model)
45685
+ [AGENT_LAUNCH_PROVIDER_PAYLOAD_KEY]: agentLaunchProviderFromModel(launchOptions.model),
45686
+ // Claude Code의 resume가 launch 좌표를 자체 복원한다고 가정하지 않는다 — 정규화된
45687
+ // 최초 선택을 Operation에 남겨 dormant·Console 재시작 뒤에도 같은 인자로 재개한다.
45688
+ ...launchOptions.model ? { launchModel: launchOptions.model } : {},
45689
+ ...launchOptions.effort ? { launchEffort: launchOptions.effort } : {}
45684
45690
  },
45685
45691
  createdAt: session.createdAt
45686
45692
  });
@@ -45708,7 +45714,7 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45708
45714
  } catch (error51) {
45709
45715
  if (error51 instanceof GatewayLaunchOptionError) {
45710
45716
  removeSession(sessionId);
45711
- ctx.host.http.writeJson(res, error51.code === "gateway_model_not_enabled" ? 409 : 400, { error: error51.code });
45717
+ ctx.host.http.writeJson(res, gatewayLaunchOptionErrorStatus(error51), { error: error51.code });
45712
45718
  return;
45713
45719
  }
45714
45720
  if (error51 instanceof LaunchPromptError) {
@@ -45741,6 +45747,8 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45741
45747
  ctx.host.http.writeJson(res, node ? 409 : 404, { error: node ? "resume_unavailable" : "session_not_found" });
45742
45748
  return true;
45743
45749
  }
45750
+ const launchModel = readPayloadString(node.payload, "launchModel") || (cliId === "claude-gateway" ? "opus[1m]" : void 0);
45751
+ const launchEffort = readPayloadString(node.payload, "launchEffort") || void 0;
45744
45752
  resetOscActivity(sessionId);
45745
45753
  const starting = observability.updateTerminalSessionStatus(sessionId, "starting") ?? injectOperation(node);
45746
45754
  try {
@@ -45763,6 +45771,8 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45763
45771
  pluginId: node.pluginId,
45764
45772
  theaterId: node.theaterId,
45765
45773
  cliId,
45774
+ ...launchModel ? { model: launchModel } : {},
45775
+ ...launchEffort ? { effort: launchEffort } : {},
45766
45776
  ...fresh ? {} : { resumeSessionId: providerSession?.sessionId }
45767
45777
  });
45768
45778
  const runtimeSession = pendingRuntimeSessions.get(sessionId);
@@ -45771,9 +45781,11 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45771
45781
  observability.notifySessionUpdated(resumed);
45772
45782
  const currentPayload = fresh ? ctx.host.operations.get(sessionId)?.payload : node.payload;
45773
45783
  const effectiveProviderSession = fresh ? readProviderSession(currentPayload) : providerSession;
45774
- ctx.host.operations.patch(sessionId, { payload: toOperationPayload(currentPayload ?? node.payload, cwd, resumed, effectiveProviderSession, observability.getDurableOperation(sessionId)?.providerTitle) });
45784
+ const resumedPayload = toOperationPayload(currentPayload ?? node.payload, cwd, resumed, effectiveProviderSession, observability.getDurableOperation(sessionId)?.providerTitle);
45785
+ if (!readPayloadString(resumedPayload, "launchModel") && launchModel) resumedPayload.launchModel = launchModel;
45786
+ ctx.host.operations.patch(sessionId, { payload: resumedPayload });
45775
45787
  ctx.host.http.writeJson(res, 200, resumed);
45776
- } catch {
45788
+ } catch (error51) {
45777
45789
  resetOscActivity(sessionId);
45778
45790
  if (fresh && providerSession) {
45779
45791
  const rollbackPayload = { ...ctx.host.operations.get(sessionId)?.payload ?? {} };
@@ -45784,7 +45796,11 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
45784
45796
  pendingRuntimeSessions.delete(sessionId);
45785
45797
  const reverted = observability.updateTerminalSessionStatus(sessionId, "dormant");
45786
45798
  if (reverted) observability.notifySessionUpdated(reverted);
45787
- ctx.host.http.writeJson(res, 503, { error: "terminal_unavailable" });
45799
+ if (error51 instanceof GatewayLaunchOptionError) {
45800
+ ctx.host.http.writeJson(res, gatewayLaunchOptionErrorStatus(error51), { error: error51.code });
45801
+ } else {
45802
+ ctx.host.http.writeJson(res, 503, { error: "terminal_unavailable" });
45803
+ }
45788
45804
  }
45789
45805
  return true;
45790
45806
  }
@@ -46136,6 +46152,9 @@ function readProviderTitle(value) {
46136
46152
  if (candidate.source !== "provider" || Object.keys(candidate).length !== 1) return void 0;
46137
46153
  return { source: "provider" };
46138
46154
  }
46155
+ function gatewayLaunchOptionErrorStatus(error51) {
46156
+ return error51.code === "gateway_model_not_enabled" ? 409 : 400;
46157
+ }
46139
46158
  function readPayloadString(payload, key) {
46140
46159
  const value = payload[key];
46141
46160
  return typeof value === "string" ? value : "";
@@ -47091,7 +47110,17 @@ function registerAnalysisRoutes(ctx, deps = {}) {
47091
47110
  if (action === "message") return handleMessage(ctx, req, res, operationId, registry3);
47092
47111
  if (action === "stream") return handleStream(ctx, req, res, operationId, registry3);
47093
47112
  return handleStop(ctx, req, res, operationId, registry3);
47094
- });
47113
+ }, [
47114
+ { method: "GET", path: "/catalog", summary: "Read Analyst model catalog.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47115
+ { method: "GET", path: "/stream", summary: "Stream all Analyst events.", category: "Terminal Plugin", gate: "origin-write", transport: "sse" },
47116
+ { method: "GET", path: "/artifacts/:artifactId", summary: "Read an Analyst artifact.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47117
+ { method: "DELETE", path: "/:operationId/artifacts", summary: "Clear Analyst artifacts.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47118
+ { method: "GET", path: "/:operationId/ready", summary: "Read Analyst readiness.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47119
+ { method: "POST", path: "/:operationId/start", summary: "Start an Analyst session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47120
+ { method: "POST", path: "/:operationId/message", summary: "Send an Analyst message.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47121
+ { method: "GET", path: "/:operationId/stream", summary: "Stream Analyst session events.", category: "Terminal Plugin", gate: "origin-write", transport: "sse" },
47122
+ { method: "POST", path: "/:operationId/stop", summary: "Stop an Analyst session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" }
47123
+ ]);
47095
47124
  const unsubscribeDelete = ctx.host.events.subscribe(OPERATION_DELETED_EVENT_CHANNEL, (payload) => {
47096
47125
  if (isOperationDeletedEvent(payload) && payload.pluginId === ctx.pluginId) {
47097
47126
  for (const marker of inFlightStartDeletionMarkers) {
@@ -47583,7 +47612,11 @@ function registerAiGatewayRoutes(ctx, deps = {}) {
47583
47612
  router.dispose();
47584
47613
  return ownedDiagnostics?.flush();
47585
47614
  });
47586
- registerRouter(ctx, AI_GATEWAY_ROUTE_SEGMENT, router.handle);
47615
+ registerRouter(ctx, AI_GATEWAY_ROUTE_SEGMENT, router.handle, [
47616
+ { method: "*", path: "/api/hello", summary: "Read the AI Gateway health response.", category: "Terminal Plugin", gate: "loopback", transport: "http" },
47617
+ { method: "*", path: "/v1/models", summary: "Proxy the AI Gateway model listing.", category: "Terminal Plugin", gate: "anthropic-credential", transport: "proxy" },
47618
+ { method: "POST", path: "/v1/messages", summary: "Proxy an Anthropic Messages request through the AI Gateway.", category: "Terminal Plugin", gate: "anthropic-credential", transport: "proxy" }
47619
+ ]);
47587
47620
  }
47588
47621
 
47589
47622
  // ../fleet-plugins/terminal/server/global.ts
@@ -47657,7 +47690,7 @@ function registerGlobalShellRoutes(ctx, runtime) {
47657
47690
  ...role ? { role } : {}
47658
47691
  }));
47659
47692
  return true;
47660
- });
47693
+ }, { method: "POST", path: "", summary: "Issue a Global Shell WebSocket ticket.", category: "Terminal Plugin", gate: "origin-strict", transport: "http" });
47661
47694
  }
47662
47695
 
47663
47696
  // ../fleet-plugins/terminal/server/model-auth-state.ts
@@ -47693,7 +47726,11 @@ function registerTerminalModelAuthRoutes(ctx, deps) {
47693
47726
  registerRouter(ctx, "model-auth", createTerminalModelAuthRouter(ctx, {
47694
47727
  ...deps,
47695
47728
  validateApiKey: (provider, apiKey) => MODEL_AUTH_VALIDATORS[provider](apiKey)
47696
- }));
47729
+ }), [
47730
+ { method: "GET", path: "/state", summary: "Read Terminal model provider authentication state.", category: "Terminal Plugin", gate: "loopback", transport: "http" },
47731
+ { method: "PUT", path: "/providers/:providerId", summary: "Save Terminal model provider credentials.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47732
+ { method: "DELETE", path: "/providers/:providerId", summary: "Remove Terminal model provider credentials.", category: "Terminal Plugin", gate: "origin-write", transport: "http" }
47733
+ ]);
47697
47734
  }
47698
47735
  function createTerminalModelAuthRouter(ctx, deps) {
47699
47736
  return async function handleTerminalModelAuthRoute({ req, res, pathname }) {
@@ -47858,7 +47895,7 @@ function registerShellRoutes(ctx, runtime) {
47858
47895
  ...role ? { role } : {}
47859
47896
  }));
47860
47897
  return true;
47861
- });
47898
+ }, { method: "POST", path: "", summary: "Issue a Shell WebSocket ticket.", category: "Terminal Plugin", gate: "origin-write", transport: "http" });
47862
47899
  registerRouter(ctx, "shell/sessions", ({ req, res, pathname }) => {
47863
47900
  const suffix = pathname.slice(`${ctx.basePath}/shell/sessions/`.length);
47864
47901
  const match = suffix.match(/^([^/]+)(?:\/(relaunch))?$/);
@@ -47895,7 +47932,10 @@ function registerShellRoutes(ctx, runtime) {
47895
47932
  ctx.host.operations.delete(operationId);
47896
47933
  ctx.host.http.writeJson(res, 200, { ok: true });
47897
47934
  return true;
47898
- });
47935
+ }, [
47936
+ { method: "DELETE", path: "/:operationId", summary: "Terminate a Shell session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" },
47937
+ { method: "POST", path: "/:operationId/relaunch", summary: "Relaunch a dormant Shell session.", category: "Terminal Plugin", gate: "origin-write", transport: "http" }
47938
+ ]);
47899
47939
  }
47900
47940
  function isRestoredShellEvent(value, pluginId) {
47901
47941
  if (!value || typeof value !== "object") return false;
@@ -47937,7 +47977,7 @@ var routes_default = definePlugin({
47937
47977
  ctx.host.operations.registerPayloadSanitizer(ctx.pluginId, TERMINAL_SENSITIVE_FIELDS);
47938
47978
  const infraServices = createInfraServices();
47939
47979
  const runtime = createTerminalRuntime(ctx);
47940
- registerWsHandler(ctx, "/", runtime.handleUpgrade);
47980
+ registerWsHandler(ctx, "/", runtime.handleUpgrade, { method: "GET", path: "", summary: "Open the Terminal WebSocket transport.", category: "Terminal Plugin", gate: "one-use-ticket", transport: "websocket" });
47941
47981
  ctx.host.lifecycle.registerCleanup(() => runtime.stop());
47942
47982
  const unsubscribeDelete = ctx.host.events.subscribe(OPERATION_DELETED_EVENT_CHANNEL2, (payload) => {
47943
47983
  if (!isOperationDeletedEvent2(payload) || payload.pluginId !== ctx.pluginId) return;