omnigateway 0.1.8 → 0.2.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/README.md +27 -33
- package/bin/omni.js +607 -78
- package/gateway.js +2877 -150
- package/package.json +1 -1
- package/public/assets/{Chip-CM9ZMdr9.js → Chip-BB_5C1Zp.js} +1 -1
- package/public/assets/Confirm-B6aAiVbT.js +4 -0
- package/public/assets/{CopyValue-WrOTcHwq.js → CopyValue-CRQDLo7k.js} +1 -1
- package/public/assets/{Field-Br6jKPz8.js → Field-uHZxl4fI.js} +1 -1
- package/public/assets/Lamp-B-5SjXbG.js +25 -0
- package/public/assets/{Meter-BzMaum0C.js → Meter-DI_BRUKt.js} +1 -1
- package/public/assets/Modal-CI6jk2D4.js +82 -0
- package/public/assets/{Rack-BFWC50ex.js → Rack-D1WJswv3.js} +8 -4
- package/public/assets/{Readout-DMJs4gYD.js → Readout-BocZ2HXP.js} +1 -1
- package/public/assets/{States-BNeCLhZn.js → States-Bbiu5cHE.js} +1 -1
- package/public/assets/{Table-nOg_lgEJ.js → Table-CdPWxYaz.js} +1 -1
- package/public/assets/Toggle-CiLC67Dw.js +39 -0
- package/public/assets/TokenBreakdown-B96iPBm9.js +28 -0
- package/public/assets/_app-BBOF6A0T.js +1 -0
- package/public/assets/{_app.accounts-BTb5vHI_.js → _app.accounts-BNkhpvaB.js} +8 -5
- package/public/assets/_app.console-Daz4aKhf.js +44 -0
- package/public/assets/_app.index-LO6d38oe.js +62 -0
- package/public/assets/{_app.keys-B-cy-2DS.js → _app.keys-kBqLqoFf.js} +3 -3
- package/public/assets/_app.logs-_wYNS47N.js +32 -0
- package/public/assets/{_app.models-BAmXHlf2.js → _app.models-Cjng8ohC.js} +5 -5
- package/public/assets/_app.settings-a0FKyQAi.js +38 -0
- package/public/assets/{_app.usage-BLrQ2hB8.js → _app.usage-D3KtgLrC.js} +9 -6
- package/public/assets/dist-C-IbPRiV.js +1 -0
- package/public/assets/index-PW6EvVh5.js +170 -0
- package/public/assets/{login-BpUl6C5b.js → login-CTvH_KAd.js} +1 -1
- package/public/assets/queries-D2o-X8Pj.js +144 -0
- package/public/assets/{trash-2-DjWP2u19.js → trash-2-BcZb-sCT.js} +1 -1
- package/public/index.html +2 -2
- package/public/assets/Lamp-DO-sRDg2.js +0 -25
- package/public/assets/Modal-lhjr949H.js +0 -82
- package/public/assets/Toggle-DYoCVD37.js +0 -42
- package/public/assets/_app-lXr06Xli.js +0 -1
- package/public/assets/_app.console-DHUClMsI.js +0 -25
- package/public/assets/_app.index-DZ--9mKU.js +0 -61
- package/public/assets/_app.logs-BQjAIT2P.js +0 -33
- package/public/assets/_app.settings-CG8bv_rm.js +0 -34
- package/public/assets/index-UAZ0O5y0.js +0 -170
- package/public/assets/queries-D_-Jj9vt.js +0 -144
package/gateway.js
CHANGED
|
@@ -5296,6 +5296,11 @@ function createAdminAuth(store, opts) {
|
|
|
5296
5296
|
};
|
|
5297
5297
|
}
|
|
5298
5298
|
// packages/ir/src/capabilities.ts
|
|
5299
|
+
var ANTHROPIC_NATIVE_TOOLS = {
|
|
5300
|
+
anthropic: true,
|
|
5301
|
+
openai: false,
|
|
5302
|
+
kimi: false
|
|
5303
|
+
};
|
|
5299
5304
|
var PROVIDER_CAPABILITIES = {
|
|
5300
5305
|
anthropic: { tools: true, images: true, reasoning: true },
|
|
5301
5306
|
openai: { tools: true, images: true, reasoning: true },
|
|
@@ -5497,7 +5502,13 @@ function collect(events) {
|
|
|
5497
5502
|
model = ev.model;
|
|
5498
5503
|
break;
|
|
5499
5504
|
case "blockStart":
|
|
5500
|
-
blocks.set(ev.index, ev.block.type === "toolUse" ? { kind: "toolUse", id: ev.block.id, name: ev.block.name, json: "" } : ev.block.type === "thinking" ? { kind: "thinking", text: "" } :
|
|
5505
|
+
blocks.set(ev.index, ev.block.type === "toolUse" ? { kind: "toolUse", id: ev.block.id, name: ev.block.name, json: "" } : ev.block.type === "thinking" ? { kind: "thinking", text: "" } : ev.block.type === "anthropicNative" ? {
|
|
5506
|
+
kind: "anthropicNative",
|
|
5507
|
+
blockType: ev.block.blockType,
|
|
5508
|
+
data: ev.block.data,
|
|
5509
|
+
json: "",
|
|
5510
|
+
deltas: []
|
|
5511
|
+
} : { kind: "text", text: "", citations: [] });
|
|
5501
5512
|
break;
|
|
5502
5513
|
case "blockDelta": {
|
|
5503
5514
|
const acc = blocks.get(ev.index);
|
|
@@ -5511,6 +5522,14 @@ function collect(events) {
|
|
|
5511
5522
|
acc.signature = (acc.signature ?? "") + ev.delta.signature;
|
|
5512
5523
|
else if (ev.delta.type === "toolJson" && acc.kind === "toolUse")
|
|
5513
5524
|
acc.json += ev.delta.partial;
|
|
5525
|
+
else if (ev.delta.type === "anthropicNativeJson" && acc.kind === "anthropicNative")
|
|
5526
|
+
acc.json += ev.delta.partial;
|
|
5527
|
+
else if (ev.delta.type === "anthropicNative") {
|
|
5528
|
+
if (acc.kind === "anthropicNative")
|
|
5529
|
+
acc.deltas.push(ev.delta);
|
|
5530
|
+
else if (acc.kind === "text" && ev.delta.deltaType === "citations_delta")
|
|
5531
|
+
acc.citations.push(ev.delta.data.citation);
|
|
5532
|
+
}
|
|
5514
5533
|
break;
|
|
5515
5534
|
}
|
|
5516
5535
|
case "end":
|
|
@@ -5523,13 +5542,25 @@ function collect(events) {
|
|
|
5523
5542
|
}
|
|
5524
5543
|
const content = [...blocks.entries()].sort(([a], [b]) => a - b).map(([, acc]) => {
|
|
5525
5544
|
if (acc.kind === "text")
|
|
5526
|
-
return {
|
|
5545
|
+
return {
|
|
5546
|
+
type: "text",
|
|
5547
|
+
text: acc.text,
|
|
5548
|
+
...acc.citations.length === 0 ? {} : { citations: acc.citations }
|
|
5549
|
+
};
|
|
5527
5550
|
if (acc.kind === "thinking")
|
|
5528
5551
|
return {
|
|
5529
5552
|
type: "thinking",
|
|
5530
5553
|
text: acc.text,
|
|
5531
5554
|
...acc.signature === undefined ? {} : { signature: acc.signature }
|
|
5532
5555
|
};
|
|
5556
|
+
if (acc.kind === "anthropicNative") {
|
|
5557
|
+
let data = acc.json === "" ? acc.data : { ...acc.data, input: parseJson(acc.json) };
|
|
5558
|
+
for (const delta of acc.deltas) {
|
|
5559
|
+
if (delta.deltaType === "compaction_delta")
|
|
5560
|
+
data = { ...data, ...delta.data };
|
|
5561
|
+
}
|
|
5562
|
+
return { type: "anthropicNative", blockType: acc.blockType, data };
|
|
5563
|
+
}
|
|
5533
5564
|
return { type: "toolUse", id: acc.id, name: acc.name, input: parseJson(acc.json) };
|
|
5534
5565
|
});
|
|
5535
5566
|
return { id, model, content, stopReason, usage };
|
|
@@ -5563,6 +5594,8 @@ function blockTokens(block) {
|
|
|
5563
5594
|
return BLOCK_OVERHEAD + fromText(block.name) + fromText(safeJson(block.input));
|
|
5564
5595
|
case "toolResult":
|
|
5565
5596
|
return BLOCK_OVERHEAD + fromText(block.toolUseId) + fromText(block.content);
|
|
5597
|
+
case "anthropicNative":
|
|
5598
|
+
return BLOCK_OVERHEAD + fromText(block.blockType) + fromText(safeJson(block.data));
|
|
5566
5599
|
}
|
|
5567
5600
|
}
|
|
5568
5601
|
function messageTokens(message) {
|
|
@@ -5572,6 +5605,9 @@ function messageTokens(message) {
|
|
|
5572
5605
|
return total;
|
|
5573
5606
|
}
|
|
5574
5607
|
function toolTokens(tool) {
|
|
5608
|
+
if (tool.provider === "anthropic") {
|
|
5609
|
+
return BLOCK_OVERHEAD + fromText(tool.name) + fromText(tool.type) + fromText(safeJson(tool.wire));
|
|
5610
|
+
}
|
|
5575
5611
|
return BLOCK_OVERHEAD + fromText(tool.name) + fromText(tool.description ?? "") + fromText(safeJson(tool.inputSchema));
|
|
5576
5612
|
}
|
|
5577
5613
|
function safeJson(value) {
|
|
@@ -6142,14 +6178,248 @@ function parseRecord(record) {
|
|
|
6142
6178
|
`) };
|
|
6143
6179
|
}
|
|
6144
6180
|
|
|
6181
|
+
// packages/providers/src/anthropic/tools.ts
|
|
6182
|
+
var COMMON = ["cache_control", "strict", "defer_loading", "allowed_callers"];
|
|
6183
|
+
var COMMON_WITH_EXAMPLES = [...COMMON, "input_examples"];
|
|
6184
|
+
var searchDomains = ["max_uses", "allowed_domains", "blocked_domains"];
|
|
6185
|
+
var ANTHROPIC_TOOL_SPECS = {
|
|
6186
|
+
web_search_20250305: {
|
|
6187
|
+
family: "webSearch",
|
|
6188
|
+
name: "web_search",
|
|
6189
|
+
required: [],
|
|
6190
|
+
optional: [...COMMON, ...searchDomains, "user_location"]
|
|
6191
|
+
},
|
|
6192
|
+
web_search_20260209: {
|
|
6193
|
+
family: "webSearch",
|
|
6194
|
+
name: "web_search",
|
|
6195
|
+
required: [],
|
|
6196
|
+
optional: [...COMMON, ...searchDomains, "user_location"]
|
|
6197
|
+
},
|
|
6198
|
+
web_search_20260318: {
|
|
6199
|
+
family: "webSearch",
|
|
6200
|
+
name: "web_search",
|
|
6201
|
+
required: [],
|
|
6202
|
+
optional: [...COMMON, ...searchDomains, "user_location", "response_inclusion"]
|
|
6203
|
+
},
|
|
6204
|
+
web_fetch_20250910: {
|
|
6205
|
+
family: "webFetch",
|
|
6206
|
+
name: "web_fetch",
|
|
6207
|
+
required: [],
|
|
6208
|
+
optional: [...COMMON, ...searchDomains, "citations", "max_content_tokens"]
|
|
6209
|
+
},
|
|
6210
|
+
web_fetch_20260209: {
|
|
6211
|
+
family: "webFetch",
|
|
6212
|
+
name: "web_fetch",
|
|
6213
|
+
required: [],
|
|
6214
|
+
optional: [...COMMON, ...searchDomains, "citations", "max_content_tokens"]
|
|
6215
|
+
},
|
|
6216
|
+
web_fetch_20260309: {
|
|
6217
|
+
family: "webFetch",
|
|
6218
|
+
name: "web_fetch",
|
|
6219
|
+
required: [],
|
|
6220
|
+
optional: [...COMMON, ...searchDomains, "citations", "max_content_tokens", "use_cache"]
|
|
6221
|
+
},
|
|
6222
|
+
web_fetch_20260318: {
|
|
6223
|
+
family: "webFetch",
|
|
6224
|
+
name: "web_fetch",
|
|
6225
|
+
required: [],
|
|
6226
|
+
optional: [
|
|
6227
|
+
...COMMON,
|
|
6228
|
+
...searchDomains,
|
|
6229
|
+
"citations",
|
|
6230
|
+
"max_content_tokens",
|
|
6231
|
+
"use_cache",
|
|
6232
|
+
"response_inclusion"
|
|
6233
|
+
]
|
|
6234
|
+
},
|
|
6235
|
+
code_execution_20250522: {
|
|
6236
|
+
family: "codeExecution",
|
|
6237
|
+
name: "code_execution",
|
|
6238
|
+
required: [],
|
|
6239
|
+
optional: [...COMMON]
|
|
6240
|
+
},
|
|
6241
|
+
code_execution_20250825: {
|
|
6242
|
+
family: "codeExecution",
|
|
6243
|
+
name: "code_execution",
|
|
6244
|
+
required: [],
|
|
6245
|
+
optional: [...COMMON]
|
|
6246
|
+
},
|
|
6247
|
+
code_execution_20260120: {
|
|
6248
|
+
family: "codeExecution",
|
|
6249
|
+
name: "code_execution",
|
|
6250
|
+
required: [],
|
|
6251
|
+
optional: [...COMMON]
|
|
6252
|
+
},
|
|
6253
|
+
code_execution_20260521: {
|
|
6254
|
+
family: "codeExecution",
|
|
6255
|
+
name: "code_execution",
|
|
6256
|
+
required: [],
|
|
6257
|
+
optional: [...COMMON]
|
|
6258
|
+
},
|
|
6259
|
+
bash_20241022: {
|
|
6260
|
+
family: "bash",
|
|
6261
|
+
name: "bash",
|
|
6262
|
+
required: [],
|
|
6263
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6264
|
+
},
|
|
6265
|
+
bash_20250124: {
|
|
6266
|
+
family: "bash",
|
|
6267
|
+
name: "bash",
|
|
6268
|
+
required: [],
|
|
6269
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6270
|
+
},
|
|
6271
|
+
text_editor_20241022: {
|
|
6272
|
+
family: "textEditor",
|
|
6273
|
+
name: "str_replace_editor",
|
|
6274
|
+
required: [],
|
|
6275
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6276
|
+
},
|
|
6277
|
+
text_editor_20250124: {
|
|
6278
|
+
family: "textEditor",
|
|
6279
|
+
name: "str_replace_editor",
|
|
6280
|
+
required: [],
|
|
6281
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6282
|
+
},
|
|
6283
|
+
text_editor_20250429: {
|
|
6284
|
+
family: "textEditor",
|
|
6285
|
+
name: "str_replace_based_edit_tool",
|
|
6286
|
+
required: [],
|
|
6287
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6288
|
+
},
|
|
6289
|
+
text_editor_20250728: {
|
|
6290
|
+
family: "textEditor",
|
|
6291
|
+
name: "str_replace_based_edit_tool",
|
|
6292
|
+
required: [],
|
|
6293
|
+
optional: [...COMMON_WITH_EXAMPLES, "max_characters"]
|
|
6294
|
+
},
|
|
6295
|
+
computer_20241022: {
|
|
6296
|
+
family: "computer",
|
|
6297
|
+
name: "computer",
|
|
6298
|
+
required: ["display_width_px", "display_height_px"],
|
|
6299
|
+
optional: [...COMMON_WITH_EXAMPLES, "display_number"]
|
|
6300
|
+
},
|
|
6301
|
+
computer_20250124: {
|
|
6302
|
+
family: "computer",
|
|
6303
|
+
name: "computer",
|
|
6304
|
+
required: ["display_width_px", "display_height_px"],
|
|
6305
|
+
optional: [...COMMON_WITH_EXAMPLES, "display_number"]
|
|
6306
|
+
},
|
|
6307
|
+
computer_20251124: {
|
|
6308
|
+
family: "computer",
|
|
6309
|
+
name: "computer",
|
|
6310
|
+
required: ["display_width_px", "display_height_px"],
|
|
6311
|
+
optional: [...COMMON_WITH_EXAMPLES, "display_number", "enable_zoom"]
|
|
6312
|
+
},
|
|
6313
|
+
memory_20250818: {
|
|
6314
|
+
family: "memory",
|
|
6315
|
+
name: "memory",
|
|
6316
|
+
required: [],
|
|
6317
|
+
optional: [...COMMON_WITH_EXAMPLES]
|
|
6318
|
+
},
|
|
6319
|
+
tool_search_tool_regex_20251119: {
|
|
6320
|
+
family: "toolSearchRegex",
|
|
6321
|
+
name: "tool_search_tool_regex",
|
|
6322
|
+
required: [],
|
|
6323
|
+
optional: [...COMMON]
|
|
6324
|
+
},
|
|
6325
|
+
tool_search_tool_regex: {
|
|
6326
|
+
family: "toolSearchRegex",
|
|
6327
|
+
name: "tool_search_tool_regex",
|
|
6328
|
+
required: [],
|
|
6329
|
+
optional: [...COMMON]
|
|
6330
|
+
},
|
|
6331
|
+
tool_search_tool_bm25_20251119: {
|
|
6332
|
+
family: "toolSearchBm25",
|
|
6333
|
+
name: "tool_search_tool_bm25",
|
|
6334
|
+
required: [],
|
|
6335
|
+
optional: [...COMMON]
|
|
6336
|
+
},
|
|
6337
|
+
tool_search_tool_bm25: {
|
|
6338
|
+
family: "toolSearchBm25",
|
|
6339
|
+
name: "tool_search_tool_bm25",
|
|
6340
|
+
required: [],
|
|
6341
|
+
optional: [...COMMON]
|
|
6342
|
+
},
|
|
6343
|
+
advisor_20260301: {
|
|
6344
|
+
family: "advisor",
|
|
6345
|
+
name: "advisor",
|
|
6346
|
+
required: ["model"],
|
|
6347
|
+
optional: [...COMMON, "caching", "max_uses", "max_tokens"]
|
|
6348
|
+
},
|
|
6349
|
+
mcp_toolset: {
|
|
6350
|
+
family: "mcpToolset",
|
|
6351
|
+
required: ["mcp_server_name"],
|
|
6352
|
+
optional: ["cache_control", "configs", "default_config"]
|
|
6353
|
+
}
|
|
6354
|
+
};
|
|
6355
|
+
function anthropicToolSpec(type) {
|
|
6356
|
+
return Object.hasOwn(ANTHROPIC_TOOL_SPECS, type) ? ANTHROPIC_TOOL_SPECS[type] : undefined;
|
|
6357
|
+
}
|
|
6358
|
+
var ANTHROPIC_TOOL_CALLERS = [
|
|
6359
|
+
"direct",
|
|
6360
|
+
"code_execution_20250825",
|
|
6361
|
+
"code_execution_20260120",
|
|
6362
|
+
"code_execution_20260521"
|
|
6363
|
+
];
|
|
6364
|
+
var ANTHROPIC_CUSTOM_TOOL_OPTIONS = [
|
|
6365
|
+
"strict",
|
|
6366
|
+
"defer_loading",
|
|
6367
|
+
"allowed_callers",
|
|
6368
|
+
"input_examples",
|
|
6369
|
+
"eager_input_streaming"
|
|
6370
|
+
];
|
|
6371
|
+
var ANTHROPIC_NATIVE_BLOCK_TYPES = new Set([
|
|
6372
|
+
"server_tool_use",
|
|
6373
|
+
"web_search_tool_result",
|
|
6374
|
+
"web_fetch_tool_result",
|
|
6375
|
+
"code_execution_tool_result",
|
|
6376
|
+
"bash_code_execution_tool_result",
|
|
6377
|
+
"text_editor_code_execution_tool_result",
|
|
6378
|
+
"mcp_tool_use",
|
|
6379
|
+
"mcp_tool_result",
|
|
6380
|
+
"tool_search_tool_result",
|
|
6381
|
+
"tool_reference",
|
|
6382
|
+
"advisor_tool_result",
|
|
6383
|
+
"advisor_result",
|
|
6384
|
+
"advisor_redacted_result",
|
|
6385
|
+
"container_upload",
|
|
6386
|
+
"compaction",
|
|
6387
|
+
"search_result",
|
|
6388
|
+
"document",
|
|
6389
|
+
"mid_conv_system",
|
|
6390
|
+
"tool_addition",
|
|
6391
|
+
"tool_removal",
|
|
6392
|
+
"fallback",
|
|
6393
|
+
"redacted_thinking"
|
|
6394
|
+
]);
|
|
6395
|
+
|
|
6145
6396
|
// packages/providers/src/anthropic/decode.ts
|
|
6146
6397
|
var STOP_REASON = {
|
|
6147
6398
|
end_turn: "endTurn",
|
|
6148
6399
|
max_tokens: "maxTokens",
|
|
6149
6400
|
stop_sequence: "stopSequence",
|
|
6150
6401
|
tool_use: "toolUse",
|
|
6151
|
-
refusal: "contentFilter"
|
|
6152
|
-
|
|
6402
|
+
refusal: "contentFilter",
|
|
6403
|
+
pause_turn: "pauseTurn"
|
|
6404
|
+
};
|
|
6405
|
+
var KNOWN_EVENTS = new Set([
|
|
6406
|
+
"message_start",
|
|
6407
|
+
"content_block_start",
|
|
6408
|
+
"content_block_delta",
|
|
6409
|
+
"content_block_stop",
|
|
6410
|
+
"message_delta",
|
|
6411
|
+
"message_stop",
|
|
6412
|
+
"error",
|
|
6413
|
+
"ping"
|
|
6414
|
+
]);
|
|
6415
|
+
var KNOWN_DELTAS = new Set([
|
|
6416
|
+
"text_delta",
|
|
6417
|
+
"thinking_delta",
|
|
6418
|
+
"signature_delta",
|
|
6419
|
+
"input_json_delta",
|
|
6420
|
+
"citations_delta",
|
|
6421
|
+
"compaction_delta"
|
|
6422
|
+
]);
|
|
6153
6423
|
var ERROR_TYPE = {
|
|
6154
6424
|
overloaded_error: "OVERLOADED",
|
|
6155
6425
|
rate_limit_error: "RATE_LIMIT",
|
|
@@ -6175,10 +6445,21 @@ async function* decodeAnthropic(messages) {
|
|
|
6175
6445
|
let outputTokens = 0;
|
|
6176
6446
|
let stopReason = "endTurn";
|
|
6177
6447
|
let terminal = false;
|
|
6448
|
+
const nativeBlocks = new Set;
|
|
6449
|
+
const protocolError = (message) => ({
|
|
6450
|
+
type: "error",
|
|
6451
|
+
code: "UPSTREAM",
|
|
6452
|
+
message,
|
|
6453
|
+
retryable: false
|
|
6454
|
+
});
|
|
6178
6455
|
for await (const msg of messages) {
|
|
6179
6456
|
const d = json(msg.data);
|
|
6180
6457
|
if (d === null)
|
|
6181
6458
|
continue;
|
|
6459
|
+
if (!KNOWN_EVENTS.has(msg.event)) {
|
|
6460
|
+
yield protocolError(`unrecognized Anthropic stream event "${msg.event}"`);
|
|
6461
|
+
return;
|
|
6462
|
+
}
|
|
6182
6463
|
switch (msg.event) {
|
|
6183
6464
|
case "message_start": {
|
|
6184
6465
|
const m = d.message ?? {};
|
|
@@ -6203,6 +6484,18 @@ async function* decodeAnthropic(messages) {
|
|
|
6203
6484
|
index,
|
|
6204
6485
|
block: { type: "toolUse", id: String(cb.id), name: String(cb.name) }
|
|
6205
6486
|
};
|
|
6487
|
+
else if (cb.type !== undefined && ANTHROPIC_NATIVE_BLOCK_TYPES.has(cb.type)) {
|
|
6488
|
+
nativeBlocks.add(index);
|
|
6489
|
+
const { type: _blockType, ...data } = cb;
|
|
6490
|
+
yield {
|
|
6491
|
+
type: "blockStart",
|
|
6492
|
+
index,
|
|
6493
|
+
block: { type: "anthropicNative", blockType: cb.type, data }
|
|
6494
|
+
};
|
|
6495
|
+
} else {
|
|
6496
|
+
yield protocolError(`unrecognized Anthropic content block type "${String(cb.type)}"`);
|
|
6497
|
+
return;
|
|
6498
|
+
}
|
|
6206
6499
|
break;
|
|
6207
6500
|
}
|
|
6208
6501
|
case "content_block_delta": {
|
|
@@ -6226,17 +6519,51 @@ async function* decodeAnthropic(messages) {
|
|
|
6226
6519
|
yield {
|
|
6227
6520
|
type: "blockDelta",
|
|
6228
6521
|
index,
|
|
6229
|
-
delta: { type: "toolJson", partial: delta.partial_json ?? "" }
|
|
6522
|
+
delta: nativeBlocks.has(index) ? { type: "anthropicNativeJson", partial: delta.partial_json ?? "" } : { type: "toolJson", partial: delta.partial_json ?? "" }
|
|
6523
|
+
};
|
|
6524
|
+
else if (delta.type === "citations_delta")
|
|
6525
|
+
yield {
|
|
6526
|
+
type: "blockDelta",
|
|
6527
|
+
index,
|
|
6528
|
+
delta: {
|
|
6529
|
+
type: "anthropicNative",
|
|
6530
|
+
deltaType: delta.type,
|
|
6531
|
+
data: { citation: delta.citation }
|
|
6532
|
+
}
|
|
6230
6533
|
};
|
|
6534
|
+
else if (delta.type === "compaction_delta")
|
|
6535
|
+
yield {
|
|
6536
|
+
type: "blockDelta",
|
|
6537
|
+
index,
|
|
6538
|
+
delta: {
|
|
6539
|
+
type: "anthropicNative",
|
|
6540
|
+
deltaType: delta.type,
|
|
6541
|
+
data: {
|
|
6542
|
+
...delta.content === undefined ? {} : { content: delta.content },
|
|
6543
|
+
...delta.encrypted_content === undefined ? {} : { encrypted_content: delta.encrypted_content }
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
};
|
|
6547
|
+
else if (delta.type === undefined || !KNOWN_DELTAS.has(delta.type)) {
|
|
6548
|
+
yield protocolError(`unrecognized Anthropic content block delta "${String(delta.type)}"`);
|
|
6549
|
+
return;
|
|
6550
|
+
}
|
|
6231
6551
|
break;
|
|
6232
6552
|
}
|
|
6233
6553
|
case "content_block_stop":
|
|
6554
|
+
nativeBlocks.delete(d.index ?? 0);
|
|
6234
6555
|
yield { type: "blockEnd", index: d.index ?? 0 };
|
|
6235
6556
|
break;
|
|
6236
6557
|
case "message_delta": {
|
|
6237
6558
|
const reason = d.delta?.stop_reason;
|
|
6238
|
-
if (typeof reason === "string")
|
|
6239
|
-
|
|
6559
|
+
if (typeof reason === "string") {
|
|
6560
|
+
const mapped = STOP_REASON[reason];
|
|
6561
|
+
if (mapped === undefined) {
|
|
6562
|
+
yield protocolError(`unrecognized Anthropic stop reason "${reason}"`);
|
|
6563
|
+
return;
|
|
6564
|
+
}
|
|
6565
|
+
stopReason = mapped;
|
|
6566
|
+
}
|
|
6240
6567
|
inputTokens = d.usage?.input_tokens ?? inputTokens;
|
|
6241
6568
|
outputTokens = d.usage?.output_tokens ?? outputTokens;
|
|
6242
6569
|
break;
|
|
@@ -6295,7 +6622,12 @@ function encodeBlock(b) {
|
|
|
6295
6622
|
const cache = wireCacheControl(cacheControlOf(b));
|
|
6296
6623
|
switch (b.type) {
|
|
6297
6624
|
case "text":
|
|
6298
|
-
return {
|
|
6625
|
+
return {
|
|
6626
|
+
type: "text",
|
|
6627
|
+
text: b.text,
|
|
6628
|
+
...b.citations === undefined ? {} : { citations: b.citations },
|
|
6629
|
+
...cache
|
|
6630
|
+
};
|
|
6299
6631
|
case "image":
|
|
6300
6632
|
return {
|
|
6301
6633
|
type: "image",
|
|
@@ -6314,11 +6646,16 @@ function encodeBlock(b) {
|
|
|
6314
6646
|
is_error: b.isError,
|
|
6315
6647
|
...cache
|
|
6316
6648
|
};
|
|
6649
|
+
case "anthropicNative":
|
|
6650
|
+
return { ...b.data, type: b.blockType, ...cache };
|
|
6317
6651
|
}
|
|
6318
6652
|
}
|
|
6319
6653
|
function encodeSystemTurn(content) {
|
|
6320
|
-
|
|
6654
|
+
if (content.every((block) => block.type === "text")) {
|
|
6655
|
+
return content.map((block) => block.text).join(`
|
|
6321
6656
|
`);
|
|
6657
|
+
}
|
|
6658
|
+
return content.map(encodeBlock);
|
|
6322
6659
|
}
|
|
6323
6660
|
function systemCacheControl(req) {
|
|
6324
6661
|
const cacheable = req.messages.flatMap((message) => message.content.flatMap((block) => block.type === "thinking" ? [] : [{ role: message.role, block }]));
|
|
@@ -6330,6 +6667,23 @@ function systemCacheControl(req) {
|
|
|
6330
6667
|
lost: markedSystemBlocks.length > (promoted === undefined ? 0 : 1)
|
|
6331
6668
|
};
|
|
6332
6669
|
}
|
|
6670
|
+
function encodeTool(t) {
|
|
6671
|
+
if (t.provider === "anthropic") {
|
|
6672
|
+
return {
|
|
6673
|
+
type: t.type,
|
|
6674
|
+
...t.name === "" ? {} : { name: t.name },
|
|
6675
|
+
...t.wire,
|
|
6676
|
+
...wireCacheControl(t.cacheControl)
|
|
6677
|
+
};
|
|
6678
|
+
}
|
|
6679
|
+
return {
|
|
6680
|
+
name: t.name,
|
|
6681
|
+
...t.description === undefined ? {} : { description: t.description },
|
|
6682
|
+
input_schema: t.inputSchema,
|
|
6683
|
+
...t.options ?? {},
|
|
6684
|
+
...wireCacheControl(t.cacheControl)
|
|
6685
|
+
};
|
|
6686
|
+
}
|
|
6333
6687
|
function encodeToolChoice(c) {
|
|
6334
6688
|
switch (c.type) {
|
|
6335
6689
|
case "auto":
|
|
@@ -6384,14 +6738,8 @@ function toWire(req, model, opts) {
|
|
|
6384
6738
|
body.temperature = req.temperature;
|
|
6385
6739
|
if (req.stopSequences !== undefined)
|
|
6386
6740
|
body.stop_sequences = req.stopSequences;
|
|
6387
|
-
if (req.tools !== undefined)
|
|
6388
|
-
body.tools = req.tools.map(
|
|
6389
|
-
name: t.name,
|
|
6390
|
-
...t.description === undefined ? {} : { description: t.description },
|
|
6391
|
-
input_schema: t.inputSchema,
|
|
6392
|
-
...wireCacheControl(t.cacheControl)
|
|
6393
|
-
}));
|
|
6394
|
-
}
|
|
6741
|
+
if (req.tools !== undefined)
|
|
6742
|
+
body.tools = req.tools.map(encodeTool);
|
|
6395
6743
|
if (req.toolChoice !== undefined)
|
|
6396
6744
|
body.tool_choice = encodeToolChoice(req.toolChoice);
|
|
6397
6745
|
if (req.reasoning !== undefined) {
|
|
@@ -6738,6 +7086,9 @@ function toChatWire(req, model) {
|
|
|
6738
7086
|
content: block.content
|
|
6739
7087
|
});
|
|
6740
7088
|
break;
|
|
7089
|
+
case "anthropicNative":
|
|
7090
|
+
note("kimi:anthropic-native-block-dropped");
|
|
7091
|
+
break;
|
|
6741
7092
|
}
|
|
6742
7093
|
}
|
|
6743
7094
|
if (toolCalls.length > 0) {
|
|
@@ -6765,7 +7116,10 @@ function toChatWire(req, model) {
|
|
|
6765
7116
|
if (req.stopSequences !== undefined)
|
|
6766
7117
|
body.stop = req.stopSequences;
|
|
6767
7118
|
if (req.tools !== undefined) {
|
|
6768
|
-
|
|
7119
|
+
const custom = req.tools.filter((t) => t.provider === "custom");
|
|
7120
|
+
if (custom.length !== req.tools.length)
|
|
7121
|
+
note("kimi:anthropic-tool-dropped");
|
|
7122
|
+
body.tools = custom.map((t) => ({
|
|
6769
7123
|
type: "function",
|
|
6770
7124
|
function: { name: t.name, description: t.description, parameters: t.inputSchema }
|
|
6771
7125
|
}));
|
|
@@ -7032,6 +7386,9 @@ ${block.text}
|
|
|
7032
7386
|
output: block.content
|
|
7033
7387
|
});
|
|
7034
7388
|
break;
|
|
7389
|
+
case "anthropicNative":
|
|
7390
|
+
note("openai:anthropic-native-block-dropped");
|
|
7391
|
+
break;
|
|
7035
7392
|
}
|
|
7036
7393
|
}
|
|
7037
7394
|
flush();
|
|
@@ -7055,7 +7412,10 @@ ${block.text}
|
|
|
7055
7412
|
body.temperature = req.temperature;
|
|
7056
7413
|
}
|
|
7057
7414
|
if (req.tools !== undefined) {
|
|
7058
|
-
|
|
7415
|
+
const custom = req.tools.filter((t) => t.provider === "custom");
|
|
7416
|
+
if (custom.length !== req.tools.length)
|
|
7417
|
+
note("openai:anthropic-tool-dropped");
|
|
7418
|
+
body.tools = custom.map((t) => ({
|
|
7059
7419
|
type: "function",
|
|
7060
7420
|
name: t.name,
|
|
7061
7421
|
description: t.description,
|
|
@@ -22027,11 +22387,12 @@ var settingsSchema = exports_external.object({
|
|
|
22027
22387
|
recency: exports_external.number()
|
|
22028
22388
|
}).strict(),
|
|
22029
22389
|
maxAttempts: exports_external.number().int().min(1).max(10),
|
|
22030
|
-
requestDeadlineMs: exports_external.number().int().
|
|
22390
|
+
requestDeadlineMs: exports_external.number().int().min(0),
|
|
22031
22391
|
breakerThreshold: exports_external.number().int().min(1),
|
|
22032
22392
|
breakerCooldownMs: exports_external.number().int().positive(),
|
|
22033
22393
|
logRetentionDays: exports_external.number().int().min(1),
|
|
22034
|
-
quotaPollIntervalMs: exports_external.number().int().min(0)
|
|
22394
|
+
quotaPollIntervalMs: exports_external.number().int().min(0),
|
|
22395
|
+
rtkEnabled: exports_external.boolean()
|
|
22035
22396
|
});
|
|
22036
22397
|
var credentialPatchSchema = exports_external.object({
|
|
22037
22398
|
label: exports_external.string().min(1).optional(),
|
|
@@ -22147,6 +22508,11 @@ async function buildSnapshot(store, now) {
|
|
|
22147
22508
|
}
|
|
22148
22509
|
|
|
22149
22510
|
// packages/router/src/filters.ts
|
|
22511
|
+
function needsAnthropicNative(request2) {
|
|
22512
|
+
if (request2.tools?.some((t) => t.provider === "anthropic") === true)
|
|
22513
|
+
return true;
|
|
22514
|
+
return request2.messages.some((m) => m.content.some((b) => b.type === "anthropicNative"));
|
|
22515
|
+
}
|
|
22150
22516
|
function requiredCapabilities(request2) {
|
|
22151
22517
|
const images = request2.messages.some((m) => m.content.some((b) => b.type === "image"));
|
|
22152
22518
|
return {
|
|
@@ -22163,10 +22529,11 @@ function eligible(input) {
|
|
|
22163
22529
|
const { request: request2, model, snapshot, now } = input;
|
|
22164
22530
|
const { breakerThreshold, breakerCooldownMs } = snapshot.settings;
|
|
22165
22531
|
const need = requiredCapabilities(request2);
|
|
22532
|
+
const needNative = needsAnthropicNative(request2);
|
|
22166
22533
|
const pairs = [];
|
|
22167
22534
|
const excluded = [];
|
|
22168
22535
|
for (const target of model.targets) {
|
|
22169
|
-
const missing = ["tools", "images", "reasoning"].find((cap) => need[cap] && !target.capabilities[cap]);
|
|
22536
|
+
const missing = needNative && !ANTHROPIC_NATIVE_TOOLS[target.provider] ? "anthropicTools" : ["tools", "images", "reasoning"].find((cap) => need[cap] && !target.capabilities[cap]);
|
|
22170
22537
|
for (const credential of snapshot.credentials) {
|
|
22171
22538
|
if (credential.provider !== target.provider)
|
|
22172
22539
|
continue;
|
|
@@ -22474,7 +22841,11 @@ async function dryRun(deps, modelId, input) {
|
|
|
22474
22841
|
}
|
|
22475
22842
|
],
|
|
22476
22843
|
stream: false,
|
|
22477
|
-
...need.tools ? {
|
|
22844
|
+
...need.tools ? {
|
|
22845
|
+
tools: [
|
|
22846
|
+
{ provider: "custom", name: "probe", description: "", inputSchema: { type: "object" } }
|
|
22847
|
+
]
|
|
22848
|
+
} : {},
|
|
22478
22849
|
...need.reasoning ? { reasoning: { mode: "adaptive" } } : {}
|
|
22479
22850
|
};
|
|
22480
22851
|
const result = rank({ request: probe, model, snapshot, now, rand: 0 });
|
|
@@ -22542,7 +22913,8 @@ var DEFAULT_SETTINGS = {
|
|
|
22542
22913
|
breakerThreshold: 3,
|
|
22543
22914
|
breakerCooldownMs: 30000,
|
|
22544
22915
|
logRetentionDays: 30,
|
|
22545
|
-
quotaPollIntervalMs: 300000
|
|
22916
|
+
quotaPollIntervalMs: 300000,
|
|
22917
|
+
rtkEnabled: false
|
|
22546
22918
|
};
|
|
22547
22919
|
|
|
22548
22920
|
// packages/store/src/sqlite/config.ts
|
|
@@ -22578,12 +22950,18 @@ function createConfigRepo(db, emit = () => {}) {
|
|
|
22578
22950
|
const raw = readRaw(SETTINGS_KEY);
|
|
22579
22951
|
if (raw === null)
|
|
22580
22952
|
return DEFAULT_SETTINGS;
|
|
22581
|
-
|
|
22582
|
-
|
|
22583
|
-
|
|
22584
|
-
|
|
22585
|
-
|
|
22586
|
-
|
|
22953
|
+
try {
|
|
22954
|
+
const parsed = JSON.parse(raw);
|
|
22955
|
+
const stored = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
22956
|
+
return {
|
|
22957
|
+
...DEFAULT_SETTINGS,
|
|
22958
|
+
...stored,
|
|
22959
|
+
rtkEnabled: stored.rtkEnabled === true,
|
|
22960
|
+
weights: { ...DEFAULT_SETTINGS.weights, ...stored.weights }
|
|
22961
|
+
};
|
|
22962
|
+
} catch {
|
|
22963
|
+
return DEFAULT_SETTINGS;
|
|
22964
|
+
}
|
|
22587
22965
|
},
|
|
22588
22966
|
async putSettings(patch) {
|
|
22589
22967
|
const current = await this.getSettings();
|
|
@@ -23025,6 +23403,20 @@ ALTER TABLE request_logs ADD COLUMN state TEXT NOT NULL DEFAULT 'done';
|
|
|
23025
23403
|
CREATE INDEX idx_request_logs_pending ON request_logs(state) WHERE state = 'pending';
|
|
23026
23404
|
`;
|
|
23027
23405
|
|
|
23406
|
+
// packages/store/src/sqlite/migrations/005_rtk_metrics.sql
|
|
23407
|
+
var _005_rtk_metrics_default = `ALTER TABLE request_logs ADD COLUMN rtk_applied INTEGER NOT NULL DEFAULT 0;
|
|
23408
|
+
ALTER TABLE request_logs ADD COLUMN rtk_filter_hits INTEGER NOT NULL DEFAULT 0;
|
|
23409
|
+
ALTER TABLE request_logs ADD COLUMN rtk_original_code_units INTEGER NOT NULL DEFAULT 0;
|
|
23410
|
+
ALTER TABLE request_logs ADD COLUMN rtk_compressed_code_units INTEGER NOT NULL DEFAULT 0;
|
|
23411
|
+
ALTER TABLE request_logs ADD COLUMN rtk_estimated_tokens_saved INTEGER NOT NULL DEFAULT 0;
|
|
23412
|
+
ALTER TABLE request_logs ADD COLUMN rtk_filters TEXT NOT NULL DEFAULT '[]';
|
|
23413
|
+
`;
|
|
23414
|
+
|
|
23415
|
+
// packages/store/src/sqlite/migrations/006_rtk_usage.sql
|
|
23416
|
+
var _006_rtk_usage_default = `ALTER TABLE usage_daily ADD COLUMN rtk_saved_tokens INTEGER NOT NULL DEFAULT 0;
|
|
23417
|
+
ALTER TABLE usage_daily ADD COLUMN rtk_applied_requests INTEGER NOT NULL DEFAULT 0;
|
|
23418
|
+
`;
|
|
23419
|
+
|
|
23028
23420
|
// packages/store/src/sqlite/rollup.ts
|
|
23029
23421
|
function startOfLocalDay(at) {
|
|
23030
23422
|
const day = new Date(at);
|
|
@@ -23035,8 +23427,8 @@ var UPSERT = `
|
|
|
23035
23427
|
INSERT INTO usage_daily
|
|
23036
23428
|
(day, provider, credential_id, requested_model, resolved_model, api_key_id,
|
|
23037
23429
|
requests, errors, input_tokens, output_tokens, cache_read_tokens,
|
|
23038
|
-
cache_write_tokens, cost_usd, duration_ms_sum)
|
|
23039
|
-
VALUES (
|
|
23430
|
+
cache_write_tokens, rtk_saved_tokens, rtk_applied_requests, cost_usd, duration_ms_sum)
|
|
23431
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
23040
23432
|
ON CONFLICT (day, provider, credential_id, requested_model, resolved_model, api_key_id)
|
|
23041
23433
|
DO UPDATE SET
|
|
23042
23434
|
requests = requests + excluded.requests,
|
|
@@ -23044,8 +23436,10 @@ var UPSERT = `
|
|
|
23044
23436
|
input_tokens = input_tokens + excluded.input_tokens,
|
|
23045
23437
|
output_tokens = output_tokens + excluded.output_tokens,
|
|
23046
23438
|
cache_read_tokens = cache_read_tokens + excluded.cache_read_tokens,
|
|
23047
|
-
cache_write_tokens
|
|
23048
|
-
|
|
23439
|
+
cache_write_tokens = cache_write_tokens + excluded.cache_write_tokens,
|
|
23440
|
+
rtk_saved_tokens = rtk_saved_tokens + excluded.rtk_saved_tokens,
|
|
23441
|
+
rtk_applied_requests = rtk_applied_requests + excluded.rtk_applied_requests,
|
|
23442
|
+
cost_usd = cost_usd + excluded.cost_usd,
|
|
23049
23443
|
duration_ms_sum = duration_ms_sum + excluded.duration_ms_sum`;
|
|
23050
23444
|
function keyOf(log) {
|
|
23051
23445
|
return [
|
|
@@ -23065,6 +23459,8 @@ function countersOf(log) {
|
|
|
23065
23459
|
outputTokens: log.outputTokens,
|
|
23066
23460
|
cacheReadTokens: log.cacheReadTokens,
|
|
23067
23461
|
cacheWriteTokens: log.cacheWriteTokens,
|
|
23462
|
+
rtkSavedTokens: log.rtkEstimatedTokensSaved,
|
|
23463
|
+
rtkAppliedRequests: log.rtkApplied ? 1 : 0,
|
|
23068
23464
|
costUsd: log.costUsd,
|
|
23069
23465
|
durationMsSum: log.durationMs
|
|
23070
23466
|
};
|
|
@@ -23078,6 +23474,8 @@ function upsert(db, key, c) {
|
|
|
23078
23474
|
c.outputTokens,
|
|
23079
23475
|
c.cacheReadTokens,
|
|
23080
23476
|
c.cacheWriteTokens,
|
|
23477
|
+
c.rtkSavedTokens,
|
|
23478
|
+
c.rtkAppliedRequests,
|
|
23081
23479
|
c.costUsd,
|
|
23082
23480
|
c.durationMsSum
|
|
23083
23481
|
]);
|
|
@@ -23108,6 +23506,8 @@ function backfillDaily(db) {
|
|
|
23108
23506
|
outputTokens: 0,
|
|
23109
23507
|
cacheReadTokens: 0,
|
|
23110
23508
|
cacheWriteTokens: 0,
|
|
23509
|
+
rtkSavedTokens: 0,
|
|
23510
|
+
rtkAppliedRequests: 0,
|
|
23111
23511
|
costUsd: 0,
|
|
23112
23512
|
durationMsSum: 0
|
|
23113
23513
|
};
|
|
@@ -23126,13 +23526,42 @@ function backfillDaily(db) {
|
|
|
23126
23526
|
upsert(db, group.key, group.counters);
|
|
23127
23527
|
return groups.size;
|
|
23128
23528
|
}
|
|
23529
|
+
function backfillRtkUsage(db) {
|
|
23530
|
+
const groups = new Map;
|
|
23531
|
+
for (const row of db.query(`SELECT at, api_key_id, requested_model, resolved_provider, resolved_model, credential_id,
|
|
23532
|
+
rtk_applied, rtk_estimated_tokens_saved
|
|
23533
|
+
FROM request_logs
|
|
23534
|
+
WHERE state = 'done'`).all()) {
|
|
23535
|
+
const key = [
|
|
23536
|
+
startOfLocalDay(row.at),
|
|
23537
|
+
row.resolved_provider ?? "",
|
|
23538
|
+
row.credential_id ?? "",
|
|
23539
|
+
row.requested_model,
|
|
23540
|
+
row.resolved_model ?? "",
|
|
23541
|
+
row.api_key_id ?? ""
|
|
23542
|
+
];
|
|
23543
|
+
const id = key.join("\x00");
|
|
23544
|
+
const group = groups.get(id) ?? { key, saved: 0, applied: 0 };
|
|
23545
|
+
group.saved += row.rtk_estimated_tokens_saved;
|
|
23546
|
+
group.applied += row.rtk_applied === 1 ? 1 : 0;
|
|
23547
|
+
groups.set(id, group);
|
|
23548
|
+
}
|
|
23549
|
+
for (const { key, saved, applied } of groups.values()) {
|
|
23550
|
+
db.run(`UPDATE usage_daily
|
|
23551
|
+
SET rtk_saved_tokens = ?, rtk_applied_requests = ?
|
|
23552
|
+
WHERE day = ? AND provider = ? AND credential_id = ? AND requested_model = ?
|
|
23553
|
+
AND resolved_model = ? AND api_key_id = ?`, [saved, applied, ...key]);
|
|
23554
|
+
}
|
|
23555
|
+
}
|
|
23129
23556
|
|
|
23130
23557
|
// packages/store/src/sqlite/db.ts
|
|
23131
23558
|
var MIGRATIONS = [
|
|
23132
23559
|
{ id: 1, sql: _001_init_default },
|
|
23133
23560
|
{ id: 2, sql: _002_usage_daily_default, after: backfillDaily },
|
|
23134
23561
|
{ id: 3, sql: _003_quota_snapshot_default },
|
|
23135
|
-
{ id: 4, sql: _004_request_state_default }
|
|
23562
|
+
{ id: 4, sql: _004_request_state_default },
|
|
23563
|
+
{ id: 5, sql: _005_rtk_metrics_default },
|
|
23564
|
+
{ id: 6, sql: _006_rtk_usage_default, after: backfillRtkUsage }
|
|
23136
23565
|
];
|
|
23137
23566
|
function openDb(path) {
|
|
23138
23567
|
const db = new Database(path, { create: true });
|
|
@@ -23201,7 +23630,38 @@ function createKeyRepo(db) {
|
|
|
23201
23630
|
}
|
|
23202
23631
|
};
|
|
23203
23632
|
}
|
|
23633
|
+
// packages/rtk/src/catalog.ts
|
|
23634
|
+
var RTK_FILTER_IDS = [
|
|
23635
|
+
"git-diff",
|
|
23636
|
+
"git-status",
|
|
23637
|
+
"git-log",
|
|
23638
|
+
"grep",
|
|
23639
|
+
"path-list",
|
|
23640
|
+
"numbered-read",
|
|
23641
|
+
"build-output",
|
|
23642
|
+
"test-output",
|
|
23643
|
+
"deduplicate-log",
|
|
23644
|
+
"smart-truncate",
|
|
23645
|
+
"lint-output",
|
|
23646
|
+
"package-output",
|
|
23647
|
+
"tree-output",
|
|
23648
|
+
"git-operation",
|
|
23649
|
+
"docker-build"
|
|
23650
|
+
];
|
|
23651
|
+
var FILTER_IDS = new Set(RTK_FILTER_IDS);
|
|
23652
|
+
function isRtkFilterId(value) {
|
|
23653
|
+
return FILTER_IDS.has(value);
|
|
23654
|
+
}
|
|
23655
|
+
|
|
23204
23656
|
// packages/store/src/sqlite/usage.ts
|
|
23657
|
+
function parseRtkFilters(raw) {
|
|
23658
|
+
try {
|
|
23659
|
+
const parsed = JSON.parse(raw);
|
|
23660
|
+
return Array.isArray(parsed) ? parsed.filter(isRtkFilterId) : [];
|
|
23661
|
+
} catch {
|
|
23662
|
+
return [];
|
|
23663
|
+
}
|
|
23664
|
+
}
|
|
23205
23665
|
var toLog = (r) => ({
|
|
23206
23666
|
id: r.id,
|
|
23207
23667
|
state: r.state === "pending" ? "pending" : "done",
|
|
@@ -23221,7 +23681,13 @@ var toLog = (r) => ({
|
|
|
23221
23681
|
ttftMs: r.ttft_ms,
|
|
23222
23682
|
durationMs: r.duration_ms,
|
|
23223
23683
|
costUsd: r.cost_usd,
|
|
23224
|
-
degradations: JSON.parse(r.degradations)
|
|
23684
|
+
degradations: JSON.parse(r.degradations),
|
|
23685
|
+
rtkApplied: r.rtk_applied === 1,
|
|
23686
|
+
rtkFilterHits: r.rtk_filter_hits,
|
|
23687
|
+
rtkOriginalCodeUnits: r.rtk_original_code_units,
|
|
23688
|
+
rtkCompressedCodeUnits: r.rtk_compressed_code_units,
|
|
23689
|
+
rtkEstimatedTokensSaved: r.rtk_estimated_tokens_saved,
|
|
23690
|
+
rtkFilters: parseRtkFilters(r.rtk_filters)
|
|
23225
23691
|
});
|
|
23226
23692
|
var GROUP_COLUMN = {
|
|
23227
23693
|
raw: {
|
|
@@ -23266,8 +23732,9 @@ function label(value) {
|
|
|
23266
23732
|
var COLUMNS = `(id, state, at, api_key_id, requested_model, resolved_provider, resolved_model,
|
|
23267
23733
|
credential_id, attempts, status, error_code, input_tokens, output_tokens,
|
|
23268
23734
|
cache_read_tokens, cache_write_tokens, ttft_ms, duration_ms, cost_usd,
|
|
23269
|
-
degradations
|
|
23270
|
-
|
|
23735
|
+
degradations, rtk_applied, rtk_filter_hits, rtk_original_code_units,
|
|
23736
|
+
rtk_compressed_code_units, rtk_estimated_tokens_saved, rtk_filters)`;
|
|
23737
|
+
var PLACEHOLDERS = "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
23271
23738
|
function values(log, state) {
|
|
23272
23739
|
return [
|
|
23273
23740
|
log.id,
|
|
@@ -23288,7 +23755,13 @@ function values(log, state) {
|
|
|
23288
23755
|
log.ttftMs,
|
|
23289
23756
|
log.durationMs,
|
|
23290
23757
|
log.costUsd,
|
|
23291
|
-
JSON.stringify(log.degradations)
|
|
23758
|
+
JSON.stringify(log.degradations),
|
|
23759
|
+
log.rtkApplied === true ? 1 : 0,
|
|
23760
|
+
log.rtkFilterHits ?? 0,
|
|
23761
|
+
log.rtkOriginalCodeUnits ?? 0,
|
|
23762
|
+
log.rtkCompressedCodeUnits ?? 0,
|
|
23763
|
+
log.rtkEstimatedTokensSaved ?? 0,
|
|
23764
|
+
JSON.stringify(log.rtkFilters ?? [])
|
|
23292
23765
|
];
|
|
23293
23766
|
}
|
|
23294
23767
|
var COMPLETE = `INSERT INTO request_logs ${COLUMNS} VALUES ${PLACEHOLDERS}
|
|
@@ -23309,7 +23782,13 @@ var COMPLETE = `INSERT INTO request_logs ${COLUMNS} VALUES ${PLACEHOLDERS}
|
|
|
23309
23782
|
ttft_ms = excluded.ttft_ms,
|
|
23310
23783
|
duration_ms = excluded.duration_ms,
|
|
23311
23784
|
cost_usd = excluded.cost_usd,
|
|
23312
|
-
degradations = excluded.degradations
|
|
23785
|
+
degradations = excluded.degradations,
|
|
23786
|
+
rtk_applied = excluded.rtk_applied,
|
|
23787
|
+
rtk_filter_hits = excluded.rtk_filter_hits,
|
|
23788
|
+
rtk_original_code_units = excluded.rtk_original_code_units,
|
|
23789
|
+
rtk_compressed_code_units = excluded.rtk_compressed_code_units,
|
|
23790
|
+
rtk_estimated_tokens_saved = excluded.rtk_estimated_tokens_saved,
|
|
23791
|
+
rtk_filters = excluded.rtk_filters`;
|
|
23313
23792
|
function createUsageRepo(db) {
|
|
23314
23793
|
const complete = db.transaction((log) => {
|
|
23315
23794
|
db.run(COMPLETE, values(log, "done"));
|
|
@@ -23354,6 +23833,8 @@ function createUsageRepo(db) {
|
|
|
23354
23833
|
COALESCE(SUM(output_tokens), 0) AS output_tokens,
|
|
23355
23834
|
COALESCE(SUM(cache_read_tokens), 0) AS cache_read_tokens,
|
|
23356
23835
|
COALESCE(SUM(cache_write_tokens), 0) AS cache_write_tokens,
|
|
23836
|
+
COALESCE(SUM(${daily ? "rtk_saved_tokens" : "rtk_estimated_tokens_saved"}), 0) AS rtk_saved_tokens,
|
|
23837
|
+
COALESCE(SUM(${daily ? "rtk_applied_requests" : "CASE WHEN rtk_applied = 1 THEN 1 ELSE 0 END"}), 0) AS rtk_applied_requests,
|
|
23357
23838
|
COALESCE(SUM(cost_usd), 0) AS cost_usd
|
|
23358
23839
|
FROM ${daily ? "usage_daily" : "request_logs"}
|
|
23359
23840
|
WHERE ${daily ? "" : "state = 'done' AND "}${timeColumn} >= ? AND ${timeColumn} <= ?
|
|
@@ -23367,6 +23848,8 @@ function createUsageRepo(db) {
|
|
|
23367
23848
|
outputTokens: r.output_tokens,
|
|
23368
23849
|
cacheReadTokens: r.cache_read_tokens,
|
|
23369
23850
|
cacheWriteTokens: r.cache_write_tokens,
|
|
23851
|
+
rtkSavedTokens: r.rtk_saved_tokens,
|
|
23852
|
+
rtkAppliedRequests: r.rtk_applied_requests,
|
|
23370
23853
|
costUsd: r.cost_usd,
|
|
23371
23854
|
errors: r.errors,
|
|
23372
23855
|
durationMsSum: r.duration_ms_sum
|
|
@@ -23927,33 +24410,77 @@ async function describeModelsForSetup(store) {
|
|
|
23927
24410
|
label: modelDisplayName(model)
|
|
23928
24411
|
}));
|
|
23929
24412
|
}
|
|
23930
|
-
|
|
23931
|
-
|
|
23932
|
-
|
|
23933
|
-
|
|
23934
|
-
|
|
23935
|
-
|
|
23936
|
-
|
|
23937
|
-
|
|
23938
|
-
|
|
23939
|
-
|
|
23940
|
-
|
|
23941
|
-
|
|
23942
|
-
|
|
23943
|
-
|
|
23944
|
-
if (limits.contextWindow !== undefined && !/^claude-/i.test(modelId)) {
|
|
23945
|
-
env2.CLAUDE_CODE_MAX_CONTEXT_TOKENS = String(limits.contextWindow);
|
|
24413
|
+
var CLAUDE_MAPPING_KEYS = {
|
|
24414
|
+
defaultModel: "ANTHROPIC_MODEL",
|
|
24415
|
+
fableModel: "ANTHROPIC_DEFAULT_FABLE_MODEL",
|
|
24416
|
+
opusModel: "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
24417
|
+
sonnetModel: "ANTHROPIC_DEFAULT_SONNET_MODEL",
|
|
24418
|
+
haikuModel: "ANTHROPIC_DEFAULT_HAIKU_MODEL"
|
|
24419
|
+
};
|
|
24420
|
+
function settingsObject(existing) {
|
|
24421
|
+
if (existing === undefined)
|
|
24422
|
+
return {};
|
|
24423
|
+
try {
|
|
24424
|
+
const parsed = JSON.parse(existing);
|
|
24425
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
24426
|
+
throw new Error("settings root is not an object");
|
|
23946
24427
|
}
|
|
23947
|
-
return
|
|
23948
|
-
|
|
23949
|
-
|
|
24428
|
+
return parsed;
|
|
24429
|
+
} catch (error51) {
|
|
24430
|
+
const reason = error51 instanceof Error ? error51.message : "invalid JSON";
|
|
24431
|
+
throw new Error(`cannot parse existing settings.json: ${reason}`);
|
|
24432
|
+
}
|
|
24433
|
+
}
|
|
24434
|
+
function claudeSettings(described, input, mapping, existing) {
|
|
24435
|
+
if (mapping.defaultModel === "")
|
|
24436
|
+
throw new Error("default model is required");
|
|
24437
|
+
const ids = new Set(described.map(({ model }) => model.id));
|
|
24438
|
+
const visibleId = (slot, id) => {
|
|
24439
|
+
if (!ids.has(id))
|
|
24440
|
+
throw new Error(`${slot} names unknown virtual model "${id}"`);
|
|
24441
|
+
const useMirror = input.discoveryMirrors === true && !/^(?:claude|anthropic)/i.test(id);
|
|
24442
|
+
return useMirror ? `claude/${id}` : id;
|
|
24443
|
+
};
|
|
24444
|
+
const settings = settingsObject(existing);
|
|
24445
|
+
const currentEnv = settings.env;
|
|
24446
|
+
const env2 = typeof currentEnv === "object" && currentEnv !== null && !Array.isArray(currentEnv) ? { ...currentEnv } : {};
|
|
24447
|
+
for (const key of Object.values(CLAUDE_MAPPING_KEYS))
|
|
24448
|
+
delete env2[key];
|
|
24449
|
+
delete env2.CLAUDE_CODE_MAX_CONTEXT_TOKENS;
|
|
24450
|
+
env2.ANTHROPIC_BASE_URL = input.baseUrl;
|
|
24451
|
+
env2.ANTHROPIC_AUTH_TOKEN = input.apiKey ?? KEY_PLACEHOLDER;
|
|
24452
|
+
env2.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1";
|
|
24453
|
+
for (const [slot, key] of Object.entries(CLAUDE_MAPPING_KEYS)) {
|
|
24454
|
+
const id = mapping[slot];
|
|
24455
|
+
if (id !== undefined && id !== "")
|
|
24456
|
+
env2[key] = visibleId(slot, id);
|
|
24457
|
+
}
|
|
24458
|
+
return {
|
|
24459
|
+
path: "settings.json",
|
|
24460
|
+
contents: `${JSON.stringify({ ...settings, env: env2 }, null, 2)}
|
|
23950
24461
|
`
|
|
23951
|
-
|
|
23952
|
-
});
|
|
24462
|
+
};
|
|
23953
24463
|
}
|
|
23954
|
-
function opencodeConfig(described, input) {
|
|
24464
|
+
function opencodeConfig(described, input, mapping) {
|
|
24465
|
+
if (mapping.defaultModel === "")
|
|
24466
|
+
throw new Error("default model is required");
|
|
24467
|
+
const byId = new Map(described.map((entry) => [entry.model.id, entry]));
|
|
24468
|
+
const selected = [];
|
|
24469
|
+
const seen = new Set;
|
|
24470
|
+
for (const slot of Object.keys(CLAUDE_MAPPING_KEYS)) {
|
|
24471
|
+
const id = mapping[slot];
|
|
24472
|
+
if (id === undefined || id === "")
|
|
24473
|
+
continue;
|
|
24474
|
+
const entry = byId.get(id);
|
|
24475
|
+
if (entry === undefined)
|
|
24476
|
+
throw new Error(`${slot} names unknown virtual model "${id}"`);
|
|
24477
|
+
if (!seen.has(id)) {
|
|
24478
|
+
seen.add(id);
|
|
24479
|
+
selected.push(entry);
|
|
24480
|
+
}
|
|
24481
|
+
}
|
|
23955
24482
|
const models = {};
|
|
23956
|
-
for (const { model, limits, label: label2 } of
|
|
24483
|
+
for (const { model, limits, label: label2 } of selected) {
|
|
23957
24484
|
const limit = limits.contextWindow === undefined ? undefined : {
|
|
23958
24485
|
context: limits.contextWindow,
|
|
23959
24486
|
...limits.maxOutputTokens === undefined ? {} : { output: limits.maxOutputTokens }
|
|
@@ -23962,6 +24489,7 @@ function opencodeConfig(described, input) {
|
|
|
23962
24489
|
}
|
|
23963
24490
|
const contents = `${JSON.stringify({
|
|
23964
24491
|
$schema: "https://opencode.ai/config.json",
|
|
24492
|
+
model: `omnigateway/${mapping.defaultModel}`,
|
|
23965
24493
|
provider: {
|
|
23966
24494
|
omnigateway: {
|
|
23967
24495
|
npm: "@ai-sdk/openai-compatible",
|
|
@@ -23977,9 +24505,11 @@ function opencodeConfig(described, input) {
|
|
|
23977
24505
|
`;
|
|
23978
24506
|
return { path: "opencode.json", contents };
|
|
23979
24507
|
}
|
|
23980
|
-
async function setupFiles(store, client, input) {
|
|
24508
|
+
async function setupFiles(store, client, input, mapping) {
|
|
23981
24509
|
const described = await describeModelsForSetup(store);
|
|
23982
|
-
|
|
24510
|
+
if (mapping === undefined)
|
|
24511
|
+
throw new Error(`defaultModel is required for ${client} setup`);
|
|
24512
|
+
return client === "opencode" ? [opencodeConfig(described, input, mapping)] : [claudeSettings(described, input, mapping)];
|
|
23983
24513
|
}
|
|
23984
24514
|
// packages/control/src/tail.ts
|
|
23985
24515
|
import { closeSync, fstatSync, openSync, readSync, statSync } from "fs";
|
|
@@ -26951,7 +27481,7 @@ __export(exports_type3, {
|
|
|
26951
27481
|
// node_modules/.bun/@sinclair+typebox@0.34.52/node_modules/@sinclair/typebox/build/esm/type/type/index.mjs
|
|
26952
27482
|
var Type = exports_type3;
|
|
26953
27483
|
|
|
26954
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
27484
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/index.mjs
|
|
26955
27485
|
var import_fast_decode_uri_component4 = __toESM(require_fast_decode_uri_component(), 1);
|
|
26956
27486
|
// node_modules/.bun/@sinclair+typebox@0.34.52/node_modules/@sinclair/typebox/build/esm/system/evaluate.mjs
|
|
26957
27487
|
function Evaluate(...args) {
|
|
@@ -30829,7 +31359,7 @@ var TypeCompiler;
|
|
|
30829
31359
|
TypeCompiler2.Compile = Compile;
|
|
30830
31360
|
})(TypeCompiler || (TypeCompiler = {}));
|
|
30831
31361
|
|
|
30832
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
31362
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/universal/utils.mjs
|
|
30833
31363
|
var isBun = typeof Bun < "u";
|
|
30834
31364
|
function isCloudflareWorker() {
|
|
30835
31365
|
try {
|
|
@@ -30841,7 +31371,7 @@ function isCloudflareWorker() {
|
|
|
30841
31371
|
return false;
|
|
30842
31372
|
}
|
|
30843
31373
|
|
|
30844
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
31374
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/universal/file.mjs
|
|
30845
31375
|
var mime = {
|
|
30846
31376
|
aac: "audio/aac",
|
|
30847
31377
|
abw: "application/x-abiword",
|
|
@@ -30968,7 +31498,7 @@ class ElysiaFile {
|
|
|
30968
31498
|
}
|
|
30969
31499
|
}
|
|
30970
31500
|
|
|
30971
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
31501
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/utils.mjs
|
|
30972
31502
|
var replaceUrlPath = (url2, pathname) => {
|
|
30973
31503
|
const pathStartIndex = url2.indexOf("/", 11), queryIndex = url2.indexOf("?", pathStartIndex);
|
|
30974
31504
|
return queryIndex === -1 ? `${url2.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}` : `${url2.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}${url2.slice(queryIndex)}`;
|
|
@@ -31442,7 +31972,7 @@ var emptySchema = {
|
|
|
31442
31972
|
response: true
|
|
31443
31973
|
};
|
|
31444
31974
|
|
|
31445
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
31975
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/error.mjs
|
|
31446
31976
|
var env2 = typeof Bun < "u" ? Bun.env : typeof process < "u" ? process?.env : undefined;
|
|
31447
31977
|
var ERROR_CODE2 = Symbol("ElysiaErrorCode");
|
|
31448
31978
|
var isProduction = (env2?.NODE_ENV ?? env2?.ENV) === "production";
|
|
@@ -31691,7 +32221,7 @@ class ValidationError extends Error {
|
|
|
31691
32221
|
}
|
|
31692
32222
|
}
|
|
31693
32223
|
|
|
31694
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
32224
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/type-system/utils.mjs
|
|
31695
32225
|
var tryParse = (v, schema) => {
|
|
31696
32226
|
try {
|
|
31697
32227
|
return JSON.parse(v);
|
|
@@ -31773,7 +32303,7 @@ var validateFile = (options, value) => {
|
|
|
31773
32303
|
return true;
|
|
31774
32304
|
};
|
|
31775
32305
|
|
|
31776
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
32306
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/type-system/format.mjs
|
|
31777
32307
|
var fullFormats = {
|
|
31778
32308
|
date: date5,
|
|
31779
32309
|
time: getTime(true),
|
|
@@ -31912,7 +32442,7 @@ exports_format.Has("date") || exports_format.Set("date", (value) => {
|
|
|
31912
32442
|
}
|
|
31913
32443
|
});
|
|
31914
32444
|
|
|
31915
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
32445
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/type-system/index.mjs
|
|
31916
32446
|
var t = Object.assign({}, Type);
|
|
31917
32447
|
createType("UnionEnum", (schema, value) => (typeof value == "number" || typeof value == "string" || value === null) && schema.enum.includes(value)), createType("ArrayBuffer", (schema, value) => value instanceof ArrayBuffer);
|
|
31918
32448
|
var internalFiles = createType("Files", (options, value) => {
|
|
@@ -32235,7 +32765,7 @@ t.BooleanString = ElysiaType.BooleanString, t.ObjectString = ElysiaType.ObjectSt
|
|
|
32235
32765
|
}
|
|
32236
32766
|
})), t.Nullable = ElysiaType.Nullable, t.MaybeEmpty = ElysiaType.MaybeEmpty, t.Cookie = ElysiaType.Cookie, t.Date = ElysiaType.Date, t.UnionEnum = ElysiaType.UnionEnum, t.NoValidate = ElysiaType.NoValidate, t.Form = ElysiaType.Form, t.ArrayBuffer = ElysiaType.ArrayBuffer, t.Uint8Array = ElysiaType.Uint8Array;
|
|
32237
32767
|
|
|
32238
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
32768
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/sucrose.mjs
|
|
32239
32769
|
var separateFunction = (code) => {
|
|
32240
32770
|
code.startsWith("async") && (code = code.slice(5)), code = code.trimStart();
|
|
32241
32771
|
let index = -1;
|
|
@@ -32499,7 +33029,7 @@ var sucrose = (lifeCycle, inference = {
|
|
|
32499
33029
|
return inference;
|
|
32500
33030
|
};
|
|
32501
33031
|
|
|
32502
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
33032
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/cookies.mjs
|
|
32503
33033
|
var import_cookie = __toESM(require_dist(), 1);
|
|
32504
33034
|
var import_fast_decode_uri_component = __toESM(require_fast_decode_uri_component(), 1);
|
|
32505
33035
|
var hashString = (str) => {
|
|
@@ -32700,7 +33230,7 @@ var serializeCookie = (cookies) => {
|
|
|
32700
33230
|
return set2.length === 1 ? set2[0] : set2;
|
|
32701
33231
|
};
|
|
32702
33232
|
|
|
32703
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
33233
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/utils.mjs
|
|
32704
33234
|
var handleFile = (response, set2, request2) => {
|
|
32705
33235
|
if (!isBun && response instanceof Promise)
|
|
32706
33236
|
return response.then((res) => handleFile(res, set2, request2));
|
|
@@ -32957,7 +33487,7 @@ async function tee(source, branches = 2) {
|
|
|
32957
33487
|
return Array.from({ length: branches }, makeIterator);
|
|
32958
33488
|
}
|
|
32959
33489
|
|
|
32960
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
33490
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/web-standard/handler.mjs
|
|
32961
33491
|
var handleElysiaFile = (file2, set2 = {
|
|
32962
33492
|
headers: {}
|
|
32963
33493
|
}, request2) => {
|
|
@@ -33274,7 +33804,7 @@ var handleStream = createStreamHandler({
|
|
|
33274
33804
|
mapCompactResponse
|
|
33275
33805
|
});
|
|
33276
33806
|
|
|
33277
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
33807
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/web-standard/index.mjs
|
|
33278
33808
|
var WebStandardAdapter = {
|
|
33279
33809
|
name: "web-standard",
|
|
33280
33810
|
isWebStandard: true,
|
|
@@ -33411,7 +33941,7 @@ const error404=new Response(error404Message,{status:404})
|
|
|
33411
33941
|
}
|
|
33412
33942
|
};
|
|
33413
33943
|
|
|
33414
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
33944
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/bun/handler.mjs
|
|
33415
33945
|
var mapResponse2 = (response, set2, request2) => {
|
|
33416
33946
|
if (isNotEmpty(set2.headers) || set2.status !== 200 || set2.cookie)
|
|
33417
33947
|
switch (handleSet(set2), response?.constructor?.name) {
|
|
@@ -33683,10 +34213,10 @@ var handleStream2 = createStreamHandler({
|
|
|
33683
34213
|
mapCompactResponse: mapCompactResponse2
|
|
33684
34214
|
});
|
|
33685
34215
|
|
|
33686
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
34216
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/compose.mjs
|
|
33687
34217
|
var import_fast_decode_uri_component3 = __toESM(require_fast_decode_uri_component(), 1);
|
|
33688
34218
|
|
|
33689
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
34219
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/parse-query.mjs
|
|
33690
34220
|
var import_fast_decode_uri_component2 = __toESM(require_fast_decode_uri_component(), 1);
|
|
33691
34221
|
var KEY_HAS_PLUS = 1;
|
|
33692
34222
|
var KEY_NEEDS_DECODE = 2;
|
|
@@ -33812,7 +34342,7 @@ function parseQuery(input) {
|
|
|
33812
34342
|
}
|
|
33813
34343
|
}
|
|
33814
34344
|
|
|
33815
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
34345
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/trace.mjs
|
|
33816
34346
|
var ELYSIA_TRACE = Symbol("ElysiaTrace");
|
|
33817
34347
|
var createProcess = () => {
|
|
33818
34348
|
const { promise: promise2, resolve } = Promise.withResolvers(), { promise: end, resolve: resolveEnd } = Promise.withResolvers(), { promise: error51, resolve: resolveError } = Promise.withResolvers(), callbacks = [], callbacksEnd = [];
|
|
@@ -34253,7 +34783,7 @@ var createMirror = (schema, {
|
|
|
34253
34783
|
});
|
|
34254
34784
|
};
|
|
34255
34785
|
|
|
34256
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
34786
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/replace-schema.mjs
|
|
34257
34787
|
var replaceSchemaTypeFromManyOptions = (schema, options) => {
|
|
34258
34788
|
if (Array.isArray(options)) {
|
|
34259
34789
|
let result = schema;
|
|
@@ -34351,7 +34881,7 @@ var coerceFormData = () => (_coerceFormData || (_coerceFormData = [
|
|
|
34351
34881
|
}
|
|
34352
34882
|
]), _coerceFormData);
|
|
34353
34883
|
|
|
34354
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
34884
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/schema.mjs
|
|
34355
34885
|
var isOptional = (schema) => schema ? schema?.[Kind] === "Import" && schema.References ? schema.References().some(isOptional) : (schema.schema && (schema = schema.schema), !!schema && (OptionalKind in schema)) : false;
|
|
34356
34886
|
var hasAdditionalProperties = (_schema) => {
|
|
34357
34887
|
if (!_schema)
|
|
@@ -35138,7 +35668,7 @@ var getCookieValidator = ({
|
|
|
35138
35668
|
};
|
|
35139
35669
|
var unwrapImportSchema = (schema) => schema && schema[Kind] === "Import" && schema.$defs[schema.$ref][Kind] === "Object" ? schema.$defs[schema.$ref] : schema;
|
|
35140
35670
|
|
|
35141
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
35671
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/compose.mjs
|
|
35142
35672
|
var allocateIf = (value, condition) => condition ? value : "";
|
|
35143
35673
|
var defaultParsers = [
|
|
35144
35674
|
"json",
|
|
@@ -36287,7 +36817,7 @@ return mapResponse(${saveResponse}error,set${adapter.mapResponseContext})}`;
|
|
|
36287
36817
|
});
|
|
36288
36818
|
};
|
|
36289
36819
|
|
|
36290
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
36820
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/bun/compose.mjs
|
|
36291
36821
|
var allocateIf2 = (value, condition) => condition ? value : "";
|
|
36292
36822
|
var createContext = (app, route, inference, isInline = false) => {
|
|
36293
36823
|
let fnLiteral = "";
|
|
@@ -36338,7 +36868,7 @@ var createBunRouteHandler = (app, route) => {
|
|
|
36338
36868
|
});
|
|
36339
36869
|
};
|
|
36340
36870
|
|
|
36341
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
36871
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/bun/handler-native.mjs
|
|
36342
36872
|
var createNativeStaticHandler = (handle, hooks, set2) => {
|
|
36343
36873
|
if (typeof handle == "function" || handle instanceof Blob)
|
|
36344
36874
|
return;
|
|
@@ -36354,7 +36884,7 @@ var createNativeStaticHandler = (handle, hooks, set2) => {
|
|
|
36354
36884
|
}) : () => response.clone();
|
|
36355
36885
|
};
|
|
36356
36886
|
|
|
36357
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
36887
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/ws/index.mjs
|
|
36358
36888
|
var websocket = {
|
|
36359
36889
|
open(ws) {
|
|
36360
36890
|
ws.data.open?.(ws);
|
|
@@ -36457,7 +36987,7 @@ var createHandleWSResponse = (responseValidator) => {
|
|
|
36457
36987
|
return handleWSResponse;
|
|
36458
36988
|
};
|
|
36459
36989
|
|
|
36460
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
36990
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/adapter/bun/index.mjs
|
|
36461
36991
|
var optionalParam = /:.+?\?(?=\/|$)/;
|
|
36462
36992
|
var getPossibleParams = (path) => {
|
|
36463
36993
|
const match = optionalParam.exec(path);
|
|
@@ -36741,10 +37271,10 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
|
|
|
36741
37271
|
}
|
|
36742
37272
|
};
|
|
36743
37273
|
|
|
36744
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
37274
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/universal/env.mjs
|
|
36745
37275
|
var env3 = isBun ? Bun.env : typeof process < "u" && process?.env ? process.env : {};
|
|
36746
37276
|
|
|
36747
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
37277
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/dynamic-handle.mjs
|
|
36748
37278
|
var ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/;
|
|
36749
37279
|
var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
36750
37280
|
var isDangerousKey = (key) => {
|
|
@@ -37180,7 +37710,7 @@ var createDynamicErrorHandler = (app) => {
|
|
|
37180
37710
|
};
|
|
37181
37711
|
};
|
|
37182
37712
|
|
|
37183
|
-
// node_modules/.bun/elysia@1.4.29+
|
|
37713
|
+
// node_modules/.bun/elysia@1.4.29+5b33ebcc42722450/node_modules/elysia/dist/index.mjs
|
|
37184
37714
|
var _a3;
|
|
37185
37715
|
_a3 = Symbol.dispose;
|
|
37186
37716
|
var _Elysia = class _Elysia2 {
|
|
@@ -38698,13 +39228,27 @@ function adminRoutes(deps) {
|
|
|
38698
39228
|
}).get("/api/agent-setup", async ({ request: request2, query }) => {
|
|
38699
39229
|
await requireAdmin(request2, deps.admin);
|
|
38700
39230
|
const client = query.client === "opencode" ? "opencode" : "claude";
|
|
38701
|
-
|
|
38702
|
-
|
|
38703
|
-
|
|
38704
|
-
|
|
38705
|
-
|
|
38706
|
-
|
|
38707
|
-
|
|
39231
|
+
const defaultModel = query.defaultModel;
|
|
39232
|
+
if (!defaultModel) {
|
|
39233
|
+
throw new GatewayError("BAD_REQUEST", `defaultModel is required for ${client} setup`);
|
|
39234
|
+
}
|
|
39235
|
+
try {
|
|
39236
|
+
return {
|
|
39237
|
+
client,
|
|
39238
|
+
files: await setupFiles(deps.store, client, {
|
|
39239
|
+
baseUrl: deps.baseUrl,
|
|
39240
|
+
discoveryMirrors: deps.discoveryMirrors === true
|
|
39241
|
+
}, {
|
|
39242
|
+
defaultModel,
|
|
39243
|
+
...query.fableModel ? { fableModel: query.fableModel } : {},
|
|
39244
|
+
...query.opusModel ? { opusModel: query.opusModel } : {},
|
|
39245
|
+
...query.sonnetModel ? { sonnetModel: query.sonnetModel } : {},
|
|
39246
|
+
...query.haikuModel ? { haikuModel: query.haikuModel } : {}
|
|
39247
|
+
})
|
|
39248
|
+
};
|
|
39249
|
+
} catch (error51) {
|
|
39250
|
+
throw new GatewayError("BAD_REQUEST", error51 instanceof Error ? error51.message : "invalid Claude model mapping");
|
|
39251
|
+
}
|
|
38708
39252
|
}).get("/api/keys", async ({ request: request2 }) => {
|
|
38709
39253
|
await requireAdmin(request2, deps.admin);
|
|
38710
39254
|
return { keys: await listKeys(deps.store) };
|
|
@@ -38809,6 +39353,1797 @@ function extractToken(header) {
|
|
|
38809
39353
|
return match === null ? value : match[1].trim();
|
|
38810
39354
|
}
|
|
38811
39355
|
|
|
39356
|
+
// packages/rtk/src/command.ts
|
|
39357
|
+
var UNSUPPORTED_OUTPUT = new Set(["--json", "--sarif"]);
|
|
39358
|
+
function tokenize(command) {
|
|
39359
|
+
if (command.length > 16384 || /[\r\n`]/.test(command) || command.includes("$(") || command.includes("<(") || command.includes(">("))
|
|
39360
|
+
return;
|
|
39361
|
+
const tokens2 = [];
|
|
39362
|
+
let word = "";
|
|
39363
|
+
let wordStarted = false;
|
|
39364
|
+
let quote;
|
|
39365
|
+
const pushWord = () => {
|
|
39366
|
+
if (wordStarted)
|
|
39367
|
+
tokens2.push({ kind: "word", value: word });
|
|
39368
|
+
word = "";
|
|
39369
|
+
wordStarted = false;
|
|
39370
|
+
};
|
|
39371
|
+
for (let i = 0;i < command.length; i++) {
|
|
39372
|
+
const char = command[i];
|
|
39373
|
+
if (char === undefined)
|
|
39374
|
+
continue;
|
|
39375
|
+
if (quote !== undefined) {
|
|
39376
|
+
if (char === quote)
|
|
39377
|
+
quote = undefined;
|
|
39378
|
+
else if (char === "\\" && quote === '"' && command[i + 1] !== undefined)
|
|
39379
|
+
word += command[++i];
|
|
39380
|
+
else
|
|
39381
|
+
word += char;
|
|
39382
|
+
continue;
|
|
39383
|
+
}
|
|
39384
|
+
if (char === "'" || char === '"') {
|
|
39385
|
+
quote = char;
|
|
39386
|
+
wordStarted = true;
|
|
39387
|
+
continue;
|
|
39388
|
+
}
|
|
39389
|
+
if (/\s/.test(char)) {
|
|
39390
|
+
pushWord();
|
|
39391
|
+
continue;
|
|
39392
|
+
}
|
|
39393
|
+
if (";&|<>".includes(char) || char === "$" && command[i + 1] === "(") {
|
|
39394
|
+
pushWord();
|
|
39395
|
+
const next = command[i + 1];
|
|
39396
|
+
const value = next !== undefined && (next === char || char === ">" && next === ">") ? char + command[++i] : char;
|
|
39397
|
+
tokens2.push({ kind: "operator", value });
|
|
39398
|
+
continue;
|
|
39399
|
+
}
|
|
39400
|
+
word += char;
|
|
39401
|
+
wordStarted = true;
|
|
39402
|
+
}
|
|
39403
|
+
if (quote !== undefined)
|
|
39404
|
+
return;
|
|
39405
|
+
pushWord();
|
|
39406
|
+
return tokens2.length <= 256 ? tokens2 : undefined;
|
|
39407
|
+
}
|
|
39408
|
+
function unwrap(tokens2) {
|
|
39409
|
+
let words = tokens2;
|
|
39410
|
+
const operatorIndexes = words.flatMap((token, index) => token.kind === "operator" ? [index] : []);
|
|
39411
|
+
if (operatorIndexes.length > 1)
|
|
39412
|
+
return;
|
|
39413
|
+
if (operatorIndexes.length === 1) {
|
|
39414
|
+
const index = operatorIndexes[0];
|
|
39415
|
+
if (index === undefined || words[index]?.value !== "&&" || words[0]?.kind !== "word" || words[0].value !== "cd" || index !== 2)
|
|
39416
|
+
return;
|
|
39417
|
+
words = words.slice(index + 1);
|
|
39418
|
+
}
|
|
39419
|
+
if (words.some((token) => token.kind === "operator"))
|
|
39420
|
+
return;
|
|
39421
|
+
const values2 = words.map((token) => token.value);
|
|
39422
|
+
while (/^[A-Za-z_][A-Za-z0-9_]*=/.test(values2[0] ?? ""))
|
|
39423
|
+
values2.shift();
|
|
39424
|
+
if (values2[0] === "env") {
|
|
39425
|
+
values2.shift();
|
|
39426
|
+
while (values2.length > 0) {
|
|
39427
|
+
const value = values2.at(0);
|
|
39428
|
+
if (value === "-i" || value === "--ignore-environment" || /^[A-Za-z_][A-Za-z0-9_]*=/.test(value ?? ""))
|
|
39429
|
+
values2.shift();
|
|
39430
|
+
else if (value === "-u") {
|
|
39431
|
+
if (values2[1] === undefined)
|
|
39432
|
+
return;
|
|
39433
|
+
values2.splice(0, 2);
|
|
39434
|
+
} else if (value?.startsWith("--unset="))
|
|
39435
|
+
values2.shift();
|
|
39436
|
+
else if (value === "--")
|
|
39437
|
+
values2.shift();
|
|
39438
|
+
else
|
|
39439
|
+
break;
|
|
39440
|
+
}
|
|
39441
|
+
}
|
|
39442
|
+
if (values2[0] === "timeout") {
|
|
39443
|
+
values2.shift();
|
|
39444
|
+
while (values2[0]?.startsWith("-")) {
|
|
39445
|
+
const option = values2.shift();
|
|
39446
|
+
if (option === "--")
|
|
39447
|
+
break;
|
|
39448
|
+
if (option === "-s" || option === "-k") {
|
|
39449
|
+
if (values2.shift() === undefined)
|
|
39450
|
+
return;
|
|
39451
|
+
} else if (!option?.startsWith("--signal=") && !option?.startsWith("--kill-after="))
|
|
39452
|
+
return;
|
|
39453
|
+
}
|
|
39454
|
+
if (values2.shift() === undefined)
|
|
39455
|
+
return;
|
|
39456
|
+
}
|
|
39457
|
+
return values2.length > 0 ? values2 : undefined;
|
|
39458
|
+
}
|
|
39459
|
+
function scriptFamily(name) {
|
|
39460
|
+
if (["test", "test:unit", "test:integration", "test:e2e"].includes(name) || name.startsWith("test:"))
|
|
39461
|
+
return "test-output";
|
|
39462
|
+
if (["lint", "typecheck", "check"].includes(name) || name.startsWith("lint:") || name.startsWith("typecheck:"))
|
|
39463
|
+
return "lint-output";
|
|
39464
|
+
return "build-output";
|
|
39465
|
+
}
|
|
39466
|
+
function classifyGrep(executable, args) {
|
|
39467
|
+
let heading = false;
|
|
39468
|
+
let beforeContext = 0;
|
|
39469
|
+
let afterContext = 0;
|
|
39470
|
+
let lineNumber = false;
|
|
39471
|
+
let operands = 0;
|
|
39472
|
+
for (let index = 0;index < args.length; index++) {
|
|
39473
|
+
const argument = args[index] ?? "";
|
|
39474
|
+
if (argument === "--") {
|
|
39475
|
+
operands += args.length - index - 1;
|
|
39476
|
+
break;
|
|
39477
|
+
}
|
|
39478
|
+
if (!argument.startsWith("-")) {
|
|
39479
|
+
operands++;
|
|
39480
|
+
continue;
|
|
39481
|
+
}
|
|
39482
|
+
if (["--json", "--files", "--replace", "-r", "--files-with-matches", "-l", "-P"].includes(argument))
|
|
39483
|
+
return;
|
|
39484
|
+
if (argument === "--heading")
|
|
39485
|
+
heading = true;
|
|
39486
|
+
else if (argument === "--no-heading")
|
|
39487
|
+
heading = false;
|
|
39488
|
+
else if (argument === "-n" || argument === "--line-number")
|
|
39489
|
+
lineNumber = true;
|
|
39490
|
+
else if (["-C", "-A", "-B", "--context", "--after-context", "--before-context"].includes(argument)) {
|
|
39491
|
+
const count = args[++index];
|
|
39492
|
+
if (count === undefined || !/^\d+$/.test(count))
|
|
39493
|
+
return;
|
|
39494
|
+
const value = Number(count);
|
|
39495
|
+
if (argument === "-C" || argument === "--context") {
|
|
39496
|
+
beforeContext = value;
|
|
39497
|
+
afterContext = value;
|
|
39498
|
+
} else if (argument === "-A" || argument === "--after-context")
|
|
39499
|
+
afterContext = value;
|
|
39500
|
+
else
|
|
39501
|
+
beforeContext = value;
|
|
39502
|
+
} else if (/^-[CAB]\d+$/.test(argument)) {
|
|
39503
|
+
const value = Number(argument.slice(2));
|
|
39504
|
+
if (argument[1] === "C") {
|
|
39505
|
+
beforeContext = value;
|
|
39506
|
+
afterContext = value;
|
|
39507
|
+
} else if (argument[1] === "A")
|
|
39508
|
+
afterContext = value;
|
|
39509
|
+
else
|
|
39510
|
+
beforeContext = value;
|
|
39511
|
+
} else if (/^--(?:context|after-context|before-context)=\d+$/.test(argument)) {
|
|
39512
|
+
const value = Number(argument.slice(argument.indexOf("=") + 1));
|
|
39513
|
+
if (argument.startsWith("--context=")) {
|
|
39514
|
+
beforeContext = value;
|
|
39515
|
+
afterContext = value;
|
|
39516
|
+
} else if (argument.startsWith("--after-context="))
|
|
39517
|
+
afterContext = value;
|
|
39518
|
+
else
|
|
39519
|
+
beforeContext = value;
|
|
39520
|
+
} else if (!["-i", "--ignore-case", "-F", "--fixed-strings", "-w", "--word-regexp"].includes(argument))
|
|
39521
|
+
return;
|
|
39522
|
+
}
|
|
39523
|
+
if (operands === 0)
|
|
39524
|
+
return;
|
|
39525
|
+
return {
|
|
39526
|
+
family: "grep",
|
|
39527
|
+
executable,
|
|
39528
|
+
grepMode: { heading, lineNumber, beforeContext, afterContext }
|
|
39529
|
+
};
|
|
39530
|
+
}
|
|
39531
|
+
function direct(executable, args) {
|
|
39532
|
+
if (executable.length === 0)
|
|
39533
|
+
return;
|
|
39534
|
+
if (executable === "rg" || executable === "grep")
|
|
39535
|
+
return classifyGrep(executable, args);
|
|
39536
|
+
const subcommand = args[0];
|
|
39537
|
+
if (executable === "git") {
|
|
39538
|
+
if (subcommand === "diff")
|
|
39539
|
+
return { family: "git-diff", executable, subcommand };
|
|
39540
|
+
if (subcommand === "status")
|
|
39541
|
+
return { family: "git-status", executable, subcommand };
|
|
39542
|
+
if (subcommand === "log")
|
|
39543
|
+
return { family: "git-log", executable, subcommand };
|
|
39544
|
+
if (["branch", "switch", "checkout", "push", "pull", "fetch"].includes(subcommand ?? ""))
|
|
39545
|
+
return { family: "git-operation", executable, subcommand: subcommand ?? "" };
|
|
39546
|
+
if (subcommand === "ls-files")
|
|
39547
|
+
return { family: "path-list", executable, subcommand };
|
|
39548
|
+
}
|
|
39549
|
+
if (executable === "docker" && (subcommand === "build" || subcommand === "buildx" && args[1] === "build" || subcommand === "compose" && args[1] === "build"))
|
|
39550
|
+
return { family: "docker-build", executable, subcommand };
|
|
39551
|
+
if (executable === "tree") {
|
|
39552
|
+
const options = args.filter((argument) => argument.startsWith("-"));
|
|
39553
|
+
if (options.some((option) => option !== "-F" && option !== "--classify"))
|
|
39554
|
+
return;
|
|
39555
|
+
return {
|
|
39556
|
+
family: "tree-output",
|
|
39557
|
+
executable,
|
|
39558
|
+
...options.length === 0 ? {} : { subcommand: "classified" }
|
|
39559
|
+
};
|
|
39560
|
+
}
|
|
39561
|
+
if (executable === "ls") {
|
|
39562
|
+
const options = args.filter((arg) => arg.startsWith("-"));
|
|
39563
|
+
if (options.some((option) => !/^-+[alRh]+$/.test(option)))
|
|
39564
|
+
return;
|
|
39565
|
+
const recursive = options.some((option) => option.includes("R"));
|
|
39566
|
+
const long = options.some((option) => option.includes("l"));
|
|
39567
|
+
if (!recursive && !long)
|
|
39568
|
+
return;
|
|
39569
|
+
return {
|
|
39570
|
+
family: "tree-output",
|
|
39571
|
+
executable,
|
|
39572
|
+
subcommand: recursive ? long ? "recursive-long" : "recursive-plain" : "long"
|
|
39573
|
+
};
|
|
39574
|
+
}
|
|
39575
|
+
if (["find", "glob"].includes(executable))
|
|
39576
|
+
return { family: "path-list", executable };
|
|
39577
|
+
if (["sed", "cat", "head", "tail", "awk", "nl"].includes(executable))
|
|
39578
|
+
return { family: "numbered-read", executable };
|
|
39579
|
+
if (executable === "tsc" || executable === "eslint" || executable === "golangci-lint" || executable === "biome" && ["check", "lint"].includes(subcommand ?? "") || executable === "ruff" && subcommand === "check" || executable === "cargo" && subcommand === "clippy")
|
|
39580
|
+
return {
|
|
39581
|
+
family: "lint-output",
|
|
39582
|
+
executable,
|
|
39583
|
+
...subcommand === undefined ? {} : { subcommand }
|
|
39584
|
+
};
|
|
39585
|
+
if (["vitest", "jest", "pytest"].includes(executable) || executable === "go" && subcommand === "test")
|
|
39586
|
+
return {
|
|
39587
|
+
family: "test-output",
|
|
39588
|
+
executable,
|
|
39589
|
+
...subcommand === undefined ? {} : { subcommand }
|
|
39590
|
+
};
|
|
39591
|
+
if (executable === "bun" && ["add", "install", "update", "remove"].includes(subcommand ?? "") || executable === "npm" && ["install", "update", "audit"].includes(subcommand ?? "") || executable === "pnpm" && ["install", "update"].includes(subcommand ?? "") || executable === "yarn" && ["install", "up"].includes(subcommand ?? "") || executable === "cargo" && ["add", "update", "fetch"].includes(subcommand ?? "") || executable === "pip" && subcommand === "install" || executable === "uv" && ["sync", "add", "remove"].includes(subcommand ?? ""))
|
|
39592
|
+
return { family: "package-output", executable, subcommand: subcommand ?? "" };
|
|
39593
|
+
if (executable === "bun" && subcommand === "test" || executable === "npm" && subcommand === "test" || executable === "cargo" && subcommand === "test")
|
|
39594
|
+
return { family: "test-output", executable, subcommand };
|
|
39595
|
+
if (executable === "bun" && subcommand === "build" || executable === "cargo" && ["build", "check"].includes(subcommand ?? ""))
|
|
39596
|
+
return { family: "build-output", executable, subcommand: subcommand ?? "" };
|
|
39597
|
+
return;
|
|
39598
|
+
}
|
|
39599
|
+
function classifyCommand(command) {
|
|
39600
|
+
const tokens2 = tokenize(command);
|
|
39601
|
+
if (tokens2 === undefined)
|
|
39602
|
+
return;
|
|
39603
|
+
const words = unwrap(tokens2);
|
|
39604
|
+
if (words === undefined)
|
|
39605
|
+
return;
|
|
39606
|
+
if (words.some((word) => UNSUPPORTED_OUTPUT.has(word) || /^(?:--format|--output-format|--reporter)=/.test(word)))
|
|
39607
|
+
return;
|
|
39608
|
+
for (let index = 0;index < words.length; index++) {
|
|
39609
|
+
if (!["--format", "--output-format", "--reporter"].includes(words[index] ?? ""))
|
|
39610
|
+
continue;
|
|
39611
|
+
if (words[index + 1] === undefined)
|
|
39612
|
+
return;
|
|
39613
|
+
return;
|
|
39614
|
+
}
|
|
39615
|
+
const executable = words[0];
|
|
39616
|
+
if (executable === undefined)
|
|
39617
|
+
return;
|
|
39618
|
+
if (executable === "bun" && words[1] === "run" || executable === "npm" && words[1] === "run") {
|
|
39619
|
+
let index = 2;
|
|
39620
|
+
if (words[index] === "--")
|
|
39621
|
+
index++;
|
|
39622
|
+
const script = words[index];
|
|
39623
|
+
return script === undefined || script.length === 0 ? undefined : { family: scriptFamily(script), executable, subcommand: "run" };
|
|
39624
|
+
}
|
|
39625
|
+
if (executable === "bun" && words[1] === "x" || executable === "bunx") {
|
|
39626
|
+
let index = executable === "bun" ? 2 : 1;
|
|
39627
|
+
let sawBun = false;
|
|
39628
|
+
let sawSeparator = false;
|
|
39629
|
+
while (words[index]?.startsWith("-")) {
|
|
39630
|
+
const option = words[index++];
|
|
39631
|
+
if (option === "--bun" && !sawBun && !sawSeparator)
|
|
39632
|
+
sawBun = true;
|
|
39633
|
+
else if (option === "--" && !sawSeparator)
|
|
39634
|
+
sawSeparator = true;
|
|
39635
|
+
else
|
|
39636
|
+
return;
|
|
39637
|
+
}
|
|
39638
|
+
const wrapped = words[index];
|
|
39639
|
+
return wrapped === undefined || wrapped.length === 0 || wrapped === "--" ? undefined : direct(wrapped, words.slice(index + 1));
|
|
39640
|
+
}
|
|
39641
|
+
if (executable === "npx") {
|
|
39642
|
+
let index = 1;
|
|
39643
|
+
let sawYes = false;
|
|
39644
|
+
let sawSeparator = false;
|
|
39645
|
+
while (words[index]?.startsWith("-")) {
|
|
39646
|
+
const option = words[index++];
|
|
39647
|
+
if ((option === "--yes" || option === "-y") && !sawYes && !sawSeparator)
|
|
39648
|
+
sawYes = true;
|
|
39649
|
+
else if (option === "--" && !sawSeparator)
|
|
39650
|
+
sawSeparator = true;
|
|
39651
|
+
else
|
|
39652
|
+
return;
|
|
39653
|
+
}
|
|
39654
|
+
const wrapped = words[index];
|
|
39655
|
+
return wrapped === undefined || wrapped.length === 0 || wrapped === "--" ? undefined : direct(wrapped, words.slice(index + 1));
|
|
39656
|
+
}
|
|
39657
|
+
return direct(executable, words.slice(1));
|
|
39658
|
+
}
|
|
39659
|
+
|
|
39660
|
+
// packages/rtk/src/detect.ts
|
|
39661
|
+
function distinctRows(lines, patterns) {
|
|
39662
|
+
const rows = new Set;
|
|
39663
|
+
for (let index = 0;index < lines.length; index++)
|
|
39664
|
+
if (patterns.some((pattern) => pattern.test(lines[index] ?? "")))
|
|
39665
|
+
rows.add(index);
|
|
39666
|
+
return rows;
|
|
39667
|
+
}
|
|
39668
|
+
function inferBuildOrTest(lines) {
|
|
39669
|
+
const bunBuildA = distinctRows(lines, [/^\$?\s*bun (?:run|build)\b/, /^bun build v/]);
|
|
39670
|
+
const bunBuildB = distinctRows(lines, [
|
|
39671
|
+
/^(?:Bundled |Build (?:completed|failed)|\S+\.(?:js|css|map)\s+\d)/
|
|
39672
|
+
]);
|
|
39673
|
+
if ([...bunBuildA].some((row) => [...bunBuildB].some((other) => other !== row)))
|
|
39674
|
+
return "build-output";
|
|
39675
|
+
const cargoA = distinctRows(lines, [/^(?:Compiling |Checking |\$?\s*cargo (?:build|check)\b)/]);
|
|
39676
|
+
const cargoB = distinctRows(lines, [
|
|
39677
|
+
/^Finished .+ target/,
|
|
39678
|
+
/^(?:error|warning)\[[A-Z]\d+\]:/,
|
|
39679
|
+
/^\s*--> \S+:\d+:\d+/
|
|
39680
|
+
]);
|
|
39681
|
+
if ([...cargoA].some((row) => [...cargoB].some((other) => other !== row)))
|
|
39682
|
+
return "build-output";
|
|
39683
|
+
const compiler = distinctRows(lines, [/^\S.+:\d+:\d+.*(?:error|warning).*(?:TS\d+|[A-Z]\d+)/]);
|
|
39684
|
+
const buildSummary = distinctRows(lines, [
|
|
39685
|
+
/^(?:Build|Compilation).*(?:failed|completed|errors?)/
|
|
39686
|
+
]);
|
|
39687
|
+
if (compiler.size >= 2 || [...compiler].some((row) => [...buildSummary].some((other) => other !== row)))
|
|
39688
|
+
return "build-output";
|
|
39689
|
+
const bunTestA = distinctRows(lines, [/^(?:bun test v|vitest|jest|PASS |FAIL |Test Files)/i]);
|
|
39690
|
+
const bunTestB = distinctRows(lines, [
|
|
39691
|
+
/^(?:\d+ (?:pass|fail)|Ran \d+ tests?|Tests?:|Test Files)/
|
|
39692
|
+
]);
|
|
39693
|
+
if ([...bunTestA].some((row) => [...bunTestB].some((other) => other !== row)))
|
|
39694
|
+
return "test-output";
|
|
39695
|
+
const pytestA = distinctRows(lines, [/^={2,} test session starts/, /^collected \d+ items/]);
|
|
39696
|
+
const pytestB = distinctRows(lines, [/^={2,} short test summary/, /\d+ (?:passed|failed|error)/]);
|
|
39697
|
+
if ([...pytestA].some((row) => [...pytestB].some((other) => other !== row)))
|
|
39698
|
+
return "test-output";
|
|
39699
|
+
const goA = distinctRows(lines, [/^=== RUN /, /^\$?\s*go test\b/]);
|
|
39700
|
+
const goB = distinctRows(lines, [/^--- (?:PASS|FAIL):/, /^(?:ok|FAIL)\s+\S/]);
|
|
39701
|
+
if ([...goA].some((row) => [...goB].some((other) => other !== row)))
|
|
39702
|
+
return "test-output";
|
|
39703
|
+
return;
|
|
39704
|
+
}
|
|
39705
|
+
|
|
39706
|
+
// packages/rtk/src/filters/shared.ts
|
|
39707
|
+
var MAX_OUTPUT = 250000;
|
|
39708
|
+
|
|
39709
|
+
class ParserBudget {
|
|
39710
|
+
inputCodeUnits;
|
|
39711
|
+
records = 0;
|
|
39712
|
+
codeUnits = 0;
|
|
39713
|
+
constructor(inputCodeUnits) {
|
|
39714
|
+
this.inputCodeUnits = inputCodeUnits;
|
|
39715
|
+
}
|
|
39716
|
+
chargeRecords(count) {
|
|
39717
|
+
this.records += count;
|
|
39718
|
+
return this.records <= 1e5;
|
|
39719
|
+
}
|
|
39720
|
+
chargeCodeUnits(count) {
|
|
39721
|
+
this.codeUnits += count;
|
|
39722
|
+
return this.codeUnits <= this.inputCodeUnits * 3;
|
|
39723
|
+
}
|
|
39724
|
+
}
|
|
39725
|
+
function scanText(text) {
|
|
39726
|
+
const lines = [];
|
|
39727
|
+
const budget = new ParserBudget(text.length);
|
|
39728
|
+
let start = 0;
|
|
39729
|
+
for (let index = 0;index < text.length; index++) {
|
|
39730
|
+
const code = text.charCodeAt(index);
|
|
39731
|
+
if (code !== 10 && code !== 13)
|
|
39732
|
+
continue;
|
|
39733
|
+
if (!budget.chargeRecords(1))
|
|
39734
|
+
return;
|
|
39735
|
+
const line2 = text.slice(start, index);
|
|
39736
|
+
if (!budget.chargeCodeUnits(line2.length))
|
|
39737
|
+
return;
|
|
39738
|
+
lines.push(line2);
|
|
39739
|
+
if (code === 13 && text.charCodeAt(index + 1) === 10)
|
|
39740
|
+
index++;
|
|
39741
|
+
start = index + 1;
|
|
39742
|
+
}
|
|
39743
|
+
if (!budget.chargeRecords(1))
|
|
39744
|
+
return;
|
|
39745
|
+
const line = text.slice(start);
|
|
39746
|
+
if (!budget.chargeCodeUnits(line.length))
|
|
39747
|
+
return;
|
|
39748
|
+
lines.push(line);
|
|
39749
|
+
return { text, lines, budget };
|
|
39750
|
+
}
|
|
39751
|
+
function renderGaps(input, selected, describe3) {
|
|
39752
|
+
const output = [];
|
|
39753
|
+
if (!input.budget.chargeRecords(selected.size))
|
|
39754
|
+
return;
|
|
39755
|
+
let previous = -1;
|
|
39756
|
+
for (const index of [...selected].sort((left, right) => left - right)) {
|
|
39757
|
+
if (previous >= 0 && index > previous + 1) {
|
|
39758
|
+
const marker = describe3(previous + 1, index - 1);
|
|
39759
|
+
if (marker !== undefined) {
|
|
39760
|
+
if (!input.budget.chargeCodeUnits(marker.length))
|
|
39761
|
+
return;
|
|
39762
|
+
output.push(marker);
|
|
39763
|
+
}
|
|
39764
|
+
}
|
|
39765
|
+
const line = input.lines[index];
|
|
39766
|
+
if (line !== undefined) {
|
|
39767
|
+
if (!input.budget.chargeCodeUnits(line.length))
|
|
39768
|
+
return;
|
|
39769
|
+
output.push(line);
|
|
39770
|
+
}
|
|
39771
|
+
previous = index;
|
|
39772
|
+
}
|
|
39773
|
+
return output.join(`
|
|
39774
|
+
`);
|
|
39775
|
+
}
|
|
39776
|
+
function renderSelection(input, selected, unit = "lines") {
|
|
39777
|
+
return renderGaps(input, selected, (start, end) => `... ${end - start + 1} ${unit} omitted ...`);
|
|
39778
|
+
}
|
|
39779
|
+
function selectBlock(input, selected, block) {
|
|
39780
|
+
const count = block.end - block.start + 1;
|
|
39781
|
+
if (!input.budget.chargeRecords(count))
|
|
39782
|
+
return false;
|
|
39783
|
+
for (let index = block.start;index <= block.end; index++)
|
|
39784
|
+
selected.add(index);
|
|
39785
|
+
return true;
|
|
39786
|
+
}
|
|
39787
|
+
function diagnosticBlocks(input, primary) {
|
|
39788
|
+
const starts = [];
|
|
39789
|
+
for (let index = 0;index < input.lines.length; index++) {
|
|
39790
|
+
if (!primary.test(input.lines[index] ?? ""))
|
|
39791
|
+
continue;
|
|
39792
|
+
if (!input.budget.chargeRecords(1))
|
|
39793
|
+
return;
|
|
39794
|
+
starts.push(index);
|
|
39795
|
+
}
|
|
39796
|
+
const blocks = [];
|
|
39797
|
+
for (let offset = 0;offset < starts.length; offset++) {
|
|
39798
|
+
const start = starts[offset];
|
|
39799
|
+
if (start === undefined || !input.budget.chargeRecords(1))
|
|
39800
|
+
return;
|
|
39801
|
+
const next = starts[offset + 1] ?? input.lines.length;
|
|
39802
|
+
let end = start;
|
|
39803
|
+
while (end + 1 < next) {
|
|
39804
|
+
const line = input.lines[end + 1] ?? "";
|
|
39805
|
+
if (!/^(?:\s|\||\^|~|help:|note:|=|-->|Caused by:|at\s|detail$)/.test(line))
|
|
39806
|
+
break;
|
|
39807
|
+
end++;
|
|
39808
|
+
}
|
|
39809
|
+
const header = input.lines[start] ?? "";
|
|
39810
|
+
blocks.push({
|
|
39811
|
+
start,
|
|
39812
|
+
end,
|
|
39813
|
+
severity: /\bwarning\b/i.test(header) ? "warning" : "error",
|
|
39814
|
+
identity: header
|
|
39815
|
+
});
|
|
39816
|
+
}
|
|
39817
|
+
return blocks;
|
|
39818
|
+
}
|
|
39819
|
+
|
|
39820
|
+
// packages/rtk/src/filters/build.ts
|
|
39821
|
+
var DIAGNOSTIC = /^(?:[^\n]+:\d+:\d+.*(?:error|warning)|(?:error|warning)(?:\[[^\]]+\])?:|panic:|\s*--> \S+:\d+:\d+)/i;
|
|
39822
|
+
var SEMANTIC = /^(?:bun build v|Compiling \S|Checking \S|Downloading \S|Downloaded \S|Running `.+`|Finished .+ target|Build (?:completed|failed)|Bundled |\S*(?:dist|build|target)[/\\]\S+|\S+\.(?:js|css|map|wasm)\s+\d|sourcemap)/i;
|
|
39823
|
+
var PROGRESS = /^progress \d+$|^(?:Compiling|Downloading) repeated\b/i;
|
|
39824
|
+
var CONTINUATION = /^(?:\s|\||\^|~|help:|note:|Caused by:|at\s)/;
|
|
39825
|
+
function compressBuild(input) {
|
|
39826
|
+
const { text, lines } = input;
|
|
39827
|
+
const selected = new Set;
|
|
39828
|
+
const compileRows = new Set;
|
|
39829
|
+
let inDiagnostic = false;
|
|
39830
|
+
for (let index = 0;index < lines.length; index++) {
|
|
39831
|
+
const line = lines[index] ?? "";
|
|
39832
|
+
if (line.length === 0 || PROGRESS.test(line)) {
|
|
39833
|
+
if (/^(?:Compiling|Downloading) repeated/.test(line))
|
|
39834
|
+
compileRows.add(index);
|
|
39835
|
+
continue;
|
|
39836
|
+
}
|
|
39837
|
+
if (DIAGNOSTIC.test(line))
|
|
39838
|
+
inDiagnostic = true;
|
|
39839
|
+
else if (inDiagnostic && CONTINUATION.test(line)) {
|
|
39840
|
+
selected.add(index);
|
|
39841
|
+
continue;
|
|
39842
|
+
} else
|
|
39843
|
+
inDiagnostic = false;
|
|
39844
|
+
if (!DIAGNOSTIC.test(line) && !SEMANTIC.test(line))
|
|
39845
|
+
return text;
|
|
39846
|
+
if (!input.budget.chargeRecords(1))
|
|
39847
|
+
return text;
|
|
39848
|
+
selected.add(index);
|
|
39849
|
+
}
|
|
39850
|
+
if (selected.size === 0 || !lines.some((line) => /^(?:Finished|Build |Bundled )/.test(line)))
|
|
39851
|
+
return text;
|
|
39852
|
+
let rendered = renderGaps(input, selected, (start, end) => {
|
|
39853
|
+
let compile2 = 0;
|
|
39854
|
+
for (let index = start;index <= end; index++)
|
|
39855
|
+
if (compileRows.has(index))
|
|
39856
|
+
compile2++;
|
|
39857
|
+
const others = end - start + 1 - compile2;
|
|
39858
|
+
const parts = [];
|
|
39859
|
+
if (compile2 > 0)
|
|
39860
|
+
parts.push(`... ${compile2} compile/download rows omitted ...`);
|
|
39861
|
+
if (others > 0)
|
|
39862
|
+
parts.push(`... ${others} lines omitted ...`);
|
|
39863
|
+
return parts.length === 0 ? undefined : parts.join(`
|
|
39864
|
+
`);
|
|
39865
|
+
});
|
|
39866
|
+
if (rendered === undefined)
|
|
39867
|
+
return text;
|
|
39868
|
+
const indexes = [...selected];
|
|
39869
|
+
const first = Math.min(...indexes);
|
|
39870
|
+
const last = Math.max(...indexes);
|
|
39871
|
+
const describeOutside = (from, to) => {
|
|
39872
|
+
let compile2 = 0;
|
|
39873
|
+
for (let index = from;index < to; index++)
|
|
39874
|
+
if (compileRows.has(index))
|
|
39875
|
+
compile2++;
|
|
39876
|
+
const others = to - from - compile2;
|
|
39877
|
+
const parts = [];
|
|
39878
|
+
if (compile2 > 0)
|
|
39879
|
+
parts.push(`... ${compile2} compile/download rows omitted ...`);
|
|
39880
|
+
if (others > 0)
|
|
39881
|
+
parts.push(`... ${others} lines omitted ...`);
|
|
39882
|
+
return parts.length === 0 ? undefined : parts.join(`
|
|
39883
|
+
`);
|
|
39884
|
+
};
|
|
39885
|
+
const leading = describeOutside(0, first);
|
|
39886
|
+
const trailing = describeOutside(last + 1, lines.length);
|
|
39887
|
+
if (leading !== undefined)
|
|
39888
|
+
rendered = `${leading}
|
|
39889
|
+
${rendered}`;
|
|
39890
|
+
if (trailing !== undefined)
|
|
39891
|
+
rendered = `${rendered}
|
|
39892
|
+
${trailing}`;
|
|
39893
|
+
return rendered.length > MAX_OUTPUT ? text : rendered;
|
|
39894
|
+
}
|
|
39895
|
+
|
|
39896
|
+
// packages/rtk/src/filters/diagnostics.ts
|
|
39897
|
+
var PRIMARY = /^(?:[^\n]+\(\d+,\d+\):\s+(?:error|warning)\s+TS\d+:|[^\n]+:\d+:\d+(?::|\s).+|[^\n]+\n\s*\d+:\d+\s+(?:error|warning)\s|\s*\d+:\d+\s+(?:error|warning)\s|(?:error|warning)(?:\[[^\]]+\])?:)/i;
|
|
39898
|
+
var SUMMARY = /(?:Found \d+ errors?(?: and \d+ warnings?)?(?: in \d+ files?)?|\d+ problems?(?: \([^)\n]*\))?|Checked \d+ files?|could not compile|\d+ issues?)\.?$/i;
|
|
39899
|
+
function compressDiagnostics(input) {
|
|
39900
|
+
const { text, lines } = input;
|
|
39901
|
+
const blocks = diagnosticBlocks(input, PRIMARY);
|
|
39902
|
+
if (blocks === undefined || blocks.length === 0)
|
|
39903
|
+
return text;
|
|
39904
|
+
const summary = lines.findLastIndex((line) => SUMMARY.test(line));
|
|
39905
|
+
if (summary < 0)
|
|
39906
|
+
return text;
|
|
39907
|
+
const selected = new Set([0, summary]);
|
|
39908
|
+
const errors4 = blocks.filter((block) => block.severity === "error");
|
|
39909
|
+
const warningByIdentity = new Map;
|
|
39910
|
+
for (const block of blocks)
|
|
39911
|
+
if (block.severity === "warning" && !warningByIdentity.has(block.identity))
|
|
39912
|
+
warningByIdentity.set(block.identity, block);
|
|
39913
|
+
const warnings = [...warningByIdentity.values()];
|
|
39914
|
+
for (const block of [...errors4, ...warnings.slice(0, 20)])
|
|
39915
|
+
if (!selectBlock(input, selected, block))
|
|
39916
|
+
return text;
|
|
39917
|
+
const omittedWarningRows = new Set;
|
|
39918
|
+
const omittedWarningStarts = new Set;
|
|
39919
|
+
for (const block of warnings.slice(20)) {
|
|
39920
|
+
if (!input.budget.chargeRecords(block.end - block.start + 1))
|
|
39921
|
+
return text;
|
|
39922
|
+
let whole = true;
|
|
39923
|
+
for (let index = block.start;index <= block.end; index++)
|
|
39924
|
+
whole &&= !selected.has(index);
|
|
39925
|
+
if (!whole)
|
|
39926
|
+
continue;
|
|
39927
|
+
omittedWarningStarts.add(block.start);
|
|
39928
|
+
for (let index = block.start;index <= block.end; index++)
|
|
39929
|
+
omittedWarningRows.add(index);
|
|
39930
|
+
}
|
|
39931
|
+
const describe3 = (from, to) => {
|
|
39932
|
+
let warningBlocks = 0;
|
|
39933
|
+
let otherRows = 0;
|
|
39934
|
+
for (let index = from;index < to; index++) {
|
|
39935
|
+
if (omittedWarningStarts.has(index))
|
|
39936
|
+
warningBlocks++;
|
|
39937
|
+
if (!omittedWarningRows.has(index))
|
|
39938
|
+
otherRows++;
|
|
39939
|
+
}
|
|
39940
|
+
const parts = [];
|
|
39941
|
+
if (warningBlocks > 0)
|
|
39942
|
+
parts.push(`... ${warningBlocks} warnings omitted ...`);
|
|
39943
|
+
if (otherRows > 0)
|
|
39944
|
+
parts.push(`... ${otherRows} lines omitted ...`);
|
|
39945
|
+
return parts.length === 0 ? undefined : parts.join(`
|
|
39946
|
+
`);
|
|
39947
|
+
};
|
|
39948
|
+
let rendered = renderGaps(input, selected, (start, end) => describe3(start, end + 1));
|
|
39949
|
+
if (rendered === undefined)
|
|
39950
|
+
return text;
|
|
39951
|
+
const indexes = [...selected];
|
|
39952
|
+
const leading = describe3(0, Math.min(...indexes));
|
|
39953
|
+
const trailing = describe3(Math.max(...indexes) + 1, lines.length);
|
|
39954
|
+
if (leading !== undefined)
|
|
39955
|
+
rendered = `${leading}
|
|
39956
|
+
${rendered}`;
|
|
39957
|
+
if (trailing !== undefined)
|
|
39958
|
+
rendered = `${rendered}
|
|
39959
|
+
${trailing}`;
|
|
39960
|
+
if (rendered.length > MAX_OUTPUT)
|
|
39961
|
+
return text;
|
|
39962
|
+
for (const block of errors4)
|
|
39963
|
+
for (let index = block.start;index <= block.end; index++)
|
|
39964
|
+
if (!rendered.includes(lines[index] ?? ""))
|
|
39965
|
+
return text;
|
|
39966
|
+
return rendered;
|
|
39967
|
+
}
|
|
39968
|
+
|
|
39969
|
+
// packages/rtk/src/filters/docker.ts
|
|
39970
|
+
var SEMANTIC2 = /^(?:#\d+\s+(?:\[[^\]]+\].*(?:FROM|RUN|COPY|ADD|load build definition)|(?:\d+(?:\.\d+)?\s+)?(?:Dockerfile:|ERROR|error|warning|caused|Caused|failed|exit code|exporting|naming|writing|DONE|CACHED|command:|digest:|manifest|provenance))|Dockerfile:\d+|naming to |digest:|manifest |provenance |image id |Step \d+\/\d+|Successfully built|Successfully tagged|ERROR|failed to solve)/;
|
|
39971
|
+
var CONTINUATION2 = /^(?:#\d+\s+(?:\d+(?:\.\d+)?\s+)?\s+(?:command:|caused by|Caused by:|at\s)|\s+(?:command:|caused by|Caused by:|at\s)|Dockerfile:\d+)/;
|
|
39972
|
+
var PROGRESS2 = /^(?:#\d+\s+\d+(?:\.\d+)?\s+)(?:\d+% transferring|\d+(?:\.\d+)?s$)|^#\d+\s+(?:transferring|extracting|downloading)\b/i;
|
|
39973
|
+
function compressDocker(input) {
|
|
39974
|
+
const { text, lines } = input;
|
|
39975
|
+
const selected = new Set;
|
|
39976
|
+
const cached2 = new Set;
|
|
39977
|
+
for (let index = 0;index < lines.length; index++) {
|
|
39978
|
+
const line = lines[index] ?? "";
|
|
39979
|
+
if (line.length === 0 || PROGRESS2.test(line))
|
|
39980
|
+
continue;
|
|
39981
|
+
if (CONTINUATION2.test(line)) {
|
|
39982
|
+
if (selected.size === 0)
|
|
39983
|
+
return text;
|
|
39984
|
+
selected.add(index);
|
|
39985
|
+
continue;
|
|
39986
|
+
}
|
|
39987
|
+
if (!SEMANTIC2.test(line))
|
|
39988
|
+
return text;
|
|
39989
|
+
if (/\bCACHED\b/.test(line)) {
|
|
39990
|
+
const key = line.replace(/\s+\d+(?:\.\d+)?s$/, "");
|
|
39991
|
+
if (cached2.has(key))
|
|
39992
|
+
continue;
|
|
39993
|
+
cached2.add(key);
|
|
39994
|
+
}
|
|
39995
|
+
if (!input.budget.chargeRecords(1))
|
|
39996
|
+
return text;
|
|
39997
|
+
selected.add(index);
|
|
39998
|
+
}
|
|
39999
|
+
if (selected.size === 0)
|
|
40000
|
+
return text;
|
|
40001
|
+
let rendered = renderSelection(input, selected);
|
|
40002
|
+
if (rendered === undefined)
|
|
40003
|
+
return text;
|
|
40004
|
+
const indexes = [...selected];
|
|
40005
|
+
const leading = Math.min(...indexes);
|
|
40006
|
+
const trailing = lines.length - 1 - Math.max(...indexes);
|
|
40007
|
+
if (leading > 0)
|
|
40008
|
+
rendered = `... ${leading} lines omitted ...
|
|
40009
|
+
${rendered}`;
|
|
40010
|
+
if (trailing > 0)
|
|
40011
|
+
rendered = `${rendered}
|
|
40012
|
+
... ${trailing} lines omitted ...`;
|
|
40013
|
+
return rendered.length <= MAX_OUTPUT ? rendered : text;
|
|
40014
|
+
}
|
|
40015
|
+
|
|
40016
|
+
// packages/rtk/src/filters/git.ts
|
|
40017
|
+
var DIFF_HEADER_ROW = "diff --(?:git|cc|combined) ";
|
|
40018
|
+
var DIFF_PAIR_ROW = "(?:--- |\\+\\+\\+ |@@+ )";
|
|
40019
|
+
var DIFF_DETAIL_ROW = "(?:index [0-9a-f][0-9a-f,]*\\.\\.|(?:old|new|new file|deleted file) mode |mode [0-7][0-7,]*\\.\\.|(?:similarity|dissimilarity) index |(?:rename|copy) (?:from|to) |Binary files |GIT binary patch$|(?:literal|delta) \\d+$|\\\\ No newline|[ +-]*[-+]| .+files? changed)";
|
|
40020
|
+
var LOG_COMMIT_ROW = "commit [0-9a-f]{4,}(?: \\(|$)";
|
|
40021
|
+
var LOG_BODY_ROW = "(?:Author:|Date:| {4}[ \\t]*\\S)";
|
|
40022
|
+
var LOG_DETAIL_ROW = "(?:Merge: |AuthorDate:|Commit:|CommitDate:|Reflog:|Tag:| \\S.*\\|\\s+\\d+| .+files? changed)";
|
|
40023
|
+
var LOG_SEPARATOR_ROW = "\\s*$";
|
|
40024
|
+
var GIT_DIFF_ANCHOR = new RegExp(`^(?:${DIFF_HEADER_ROW}|${DIFF_PAIR_ROW}|${DIFF_DETAIL_ROW})`);
|
|
40025
|
+
var GIT_LOG_ANCHOR = new RegExp(`^(?:${LOG_COMMIT_ROW}|${LOG_BODY_ROW}|${LOG_DETAIL_ROW}|${LOG_SEPARATOR_ROW})`);
|
|
40026
|
+
var GIT_DIFF_EVIDENCE_HEADER = new RegExp(`^${DIFF_HEADER_ROW}`, "m");
|
|
40027
|
+
var GIT_DIFF_EVIDENCE_PAIR = new RegExp(`^${DIFF_PAIR_ROW}`, "m");
|
|
40028
|
+
var GIT_LOG_EVIDENCE_COMMIT = new RegExp(`^${LOG_COMMIT_ROW}`, "m");
|
|
40029
|
+
var GIT_LOG_EVIDENCE_BODY = new RegExp(`^${LOG_BODY_ROW}`, "m");
|
|
40030
|
+
var SEMANTIC3 = /^(?:\* |\+ | {2}|Already on|Switched to|Your branch|HEAD is now|From |To |!?\s*\[| \* | - |error:|fatal:|CONFLICT|Everything up-to-date|Updating |Fast-forward|remote:|## |On branch|rebase |merge |cherry-pick |revert |bisect |[0-9a-f]+\.\.[0-9a-f]+\s+\S+\s+->\s+\S+|\s+\S.+\|\s+\d+|\s+\d+ files? changed|Automatic merge failed|\s+(?:modified|deleted|new file|renamed|copied):)/;
|
|
40031
|
+
var PROGRESS3 = /^(?:remote: )?(?:Enumerating|Counting|Compressing|Receiving|Resolving|Writing) objects|^(?:remote: )?Total \d+|^\s*\d+% \(|^(?:remote )?progress \d+$/;
|
|
40032
|
+
function compressGitOperation(input) {
|
|
40033
|
+
const { text, lines } = input;
|
|
40034
|
+
const selected = new Set;
|
|
40035
|
+
for (let index = 0;index < lines.length; index++) {
|
|
40036
|
+
const line = lines[index] ?? "";
|
|
40037
|
+
if (line.length === 0 || PROGRESS3.test(line))
|
|
40038
|
+
continue;
|
|
40039
|
+
if (!SEMANTIC3.test(line))
|
|
40040
|
+
return text;
|
|
40041
|
+
selected.add(index);
|
|
40042
|
+
}
|
|
40043
|
+
if (selected.size === 0)
|
|
40044
|
+
return text;
|
|
40045
|
+
let rendered = renderSelection(input, selected);
|
|
40046
|
+
if (rendered === undefined)
|
|
40047
|
+
return text;
|
|
40048
|
+
const indexes = [...selected];
|
|
40049
|
+
const leading = Math.min(...indexes);
|
|
40050
|
+
const trailing = lines.length - 1 - Math.max(...indexes);
|
|
40051
|
+
if (leading > 0)
|
|
40052
|
+
rendered = `... ${leading} lines omitted ...
|
|
40053
|
+
${rendered}`;
|
|
40054
|
+
if (trailing > 0)
|
|
40055
|
+
rendered = `${rendered}
|
|
40056
|
+
... ${trailing} lines omitted ...`;
|
|
40057
|
+
return rendered.length <= MAX_OUTPUT ? rendered : text;
|
|
40058
|
+
}
|
|
40059
|
+
|
|
40060
|
+
// packages/rtk/src/filters/listings.ts
|
|
40061
|
+
var LONG = /^[bcdlps-][rwxStTs-]{9}\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+(?:\d{2}:\d{2}|\d{4})\s+.+$/;
|
|
40062
|
+
var SUMMARY2 = /^\d+ director(?:y|ies), \d+ files?$/;
|
|
40063
|
+
var TREE_ROW = /^((?:\u2502 {3}| {4})*)(\u251C\u2500\u2500 |\u2514\u2500\u2500 )(.+)$/;
|
|
40064
|
+
function renderGroups(input, groups) {
|
|
40065
|
+
const output = [];
|
|
40066
|
+
let omittedGroups = 0;
|
|
40067
|
+
let omittedEntries = 0;
|
|
40068
|
+
const append = (fragment) => {
|
|
40069
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(fragment.length))
|
|
40070
|
+
return false;
|
|
40071
|
+
output.push(fragment);
|
|
40072
|
+
return true;
|
|
40073
|
+
};
|
|
40074
|
+
const flushOmitted = () => {
|
|
40075
|
+
if (omittedGroups === 0)
|
|
40076
|
+
return true;
|
|
40077
|
+
const marker = `... ${omittedGroups} ${omittedGroups === 1 ? "directory" : "directories"} omitted containing ${omittedEntries} ${omittedEntries === 1 ? "entry" : "entries"} ...`;
|
|
40078
|
+
omittedGroups = 0;
|
|
40079
|
+
omittedEntries = 0;
|
|
40080
|
+
return append(marker);
|
|
40081
|
+
};
|
|
40082
|
+
for (let groupIndex = 0;groupIndex < groups.length; groupIndex++) {
|
|
40083
|
+
const group = groups[groupIndex];
|
|
40084
|
+
if (group === undefined || !input.budget.chargeRecords(1))
|
|
40085
|
+
return;
|
|
40086
|
+
const retain = groups.length <= 40 || groupIndex < 20 || groupIndex >= groups.length - 20;
|
|
40087
|
+
if (!retain) {
|
|
40088
|
+
omittedGroups++;
|
|
40089
|
+
omittedEntries += group.entryCount;
|
|
40090
|
+
continue;
|
|
40091
|
+
}
|
|
40092
|
+
if (!flushOmitted())
|
|
40093
|
+
return;
|
|
40094
|
+
const prefixCount = group.rows.length - group.entryCount;
|
|
40095
|
+
for (let rowIndex = 0;rowIndex < group.rows.length; rowIndex++) {
|
|
40096
|
+
const row = group.rows[rowIndex];
|
|
40097
|
+
if (row === undefined || !input.budget.chargeRecords(1))
|
|
40098
|
+
return;
|
|
40099
|
+
const entryIndex = rowIndex - prefixCount;
|
|
40100
|
+
const retainEntry = entryIndex < 0 || group.entryCount <= 12 || entryIndex < 6 || entryIndex >= group.entryCount - 6;
|
|
40101
|
+
if (retainEntry && !append(row))
|
|
40102
|
+
return;
|
|
40103
|
+
}
|
|
40104
|
+
if (group.entryCount > 12) {
|
|
40105
|
+
const count = group.entryCount - 12;
|
|
40106
|
+
if (!append(`... ${count} ${count === 1 ? "entry" : "entries"} omitted from ${group.key} ...`))
|
|
40107
|
+
return;
|
|
40108
|
+
}
|
|
40109
|
+
}
|
|
40110
|
+
if (!flushOmitted())
|
|
40111
|
+
return;
|
|
40112
|
+
const rendered = output.join(`
|
|
40113
|
+
`);
|
|
40114
|
+
return rendered.length <= MAX_OUTPUT ? rendered : undefined;
|
|
40115
|
+
}
|
|
40116
|
+
function subtreeCounts(input, node, classified) {
|
|
40117
|
+
if (!input.budget.chargeRecords(1))
|
|
40118
|
+
return;
|
|
40119
|
+
if (node.children.length === 0)
|
|
40120
|
+
return {
|
|
40121
|
+
directories: node.classifiedDirectory ? 1 : 0,
|
|
40122
|
+
entries: node.classifiedDirectory ? 0 : 1,
|
|
40123
|
+
ambiguous: !classified
|
|
40124
|
+
};
|
|
40125
|
+
let directories = 1;
|
|
40126
|
+
let entries = 0;
|
|
40127
|
+
let ambiguous = false;
|
|
40128
|
+
for (const child of node.children) {
|
|
40129
|
+
const count = subtreeCounts(input, child, classified);
|
|
40130
|
+
if (count === undefined)
|
|
40131
|
+
return;
|
|
40132
|
+
directories += count.directories;
|
|
40133
|
+
entries += count.entries;
|
|
40134
|
+
ambiguous ||= count.ambiguous;
|
|
40135
|
+
}
|
|
40136
|
+
return { directories, entries, ambiguous };
|
|
40137
|
+
}
|
|
40138
|
+
function appendSubtree(input, output, node, classified) {
|
|
40139
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(node.line.length))
|
|
40140
|
+
return false;
|
|
40141
|
+
output.push(node.line);
|
|
40142
|
+
const retainedValues = node.children.length <= 12 ? node.children : [...node.children.slice(0, 6), ...node.children.slice(-6)];
|
|
40143
|
+
if (!input.budget.chargeRecords(retainedValues.length))
|
|
40144
|
+
return false;
|
|
40145
|
+
const retained = new Set(retainedValues);
|
|
40146
|
+
let omitted = [];
|
|
40147
|
+
const flushOmitted = () => {
|
|
40148
|
+
if (omitted.length === 0)
|
|
40149
|
+
return true;
|
|
40150
|
+
let directories = 0;
|
|
40151
|
+
let entries = 0;
|
|
40152
|
+
let ambiguous = false;
|
|
40153
|
+
for (const child of omitted) {
|
|
40154
|
+
const count = subtreeCounts(input, child, classified);
|
|
40155
|
+
if (count === undefined)
|
|
40156
|
+
return false;
|
|
40157
|
+
directories += count.directories;
|
|
40158
|
+
entries += count.entries;
|
|
40159
|
+
ambiguous ||= count.ambiguous;
|
|
40160
|
+
}
|
|
40161
|
+
if (ambiguous)
|
|
40162
|
+
return false;
|
|
40163
|
+
const marker = directories === 0 ? `... ${entries} ${entries === 1 ? "entry" : "entries"} omitted from ${node.key} ...` : `... ${directories} ${directories === 1 ? "directory" : "directories"} omitted containing ${entries} ${entries === 1 ? "entry" : "entries"} ...`;
|
|
40164
|
+
if (!input.budget.chargeCodeUnits(marker.length))
|
|
40165
|
+
return false;
|
|
40166
|
+
output.push(marker);
|
|
40167
|
+
omitted = [];
|
|
40168
|
+
return true;
|
|
40169
|
+
};
|
|
40170
|
+
for (const child of node.children) {
|
|
40171
|
+
if (!input.budget.chargeRecords(1))
|
|
40172
|
+
return false;
|
|
40173
|
+
if (!retained.has(child)) {
|
|
40174
|
+
omitted.push(child);
|
|
40175
|
+
continue;
|
|
40176
|
+
}
|
|
40177
|
+
if (!flushOmitted() || !appendSubtree(input, output, child, classified))
|
|
40178
|
+
return false;
|
|
40179
|
+
}
|
|
40180
|
+
return flushOmitted();
|
|
40181
|
+
}
|
|
40182
|
+
function tree(input, lines, classified) {
|
|
40183
|
+
const root = lines[0];
|
|
40184
|
+
const summary = lines.at(-1);
|
|
40185
|
+
if (lines.length < 3 || root === undefined || /[\u2502\u251C\u2514]/.test(root) || summary === undefined || !SUMMARY2.test(summary))
|
|
40186
|
+
return input.text;
|
|
40187
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(root.length))
|
|
40188
|
+
return input.text;
|
|
40189
|
+
const rootNode = { key: root, line: root, classifiedDirectory: true, children: [] };
|
|
40190
|
+
const stack = [rootNode];
|
|
40191
|
+
for (const line of lines.slice(1, -1)) {
|
|
40192
|
+
const match = line.match(TREE_ROW);
|
|
40193
|
+
const depth = (match?.[1]?.length ?? -1) / 4;
|
|
40194
|
+
const parent = stack[depth];
|
|
40195
|
+
const name = match?.[3];
|
|
40196
|
+
if (!Number.isInteger(depth) || parent === undefined || name === undefined)
|
|
40197
|
+
return input.text;
|
|
40198
|
+
const plainName = name.replace(/ -> .+$/, "").replace(/[/@*=>|]$/, "");
|
|
40199
|
+
const key = `${parent.key}/${plainName}`;
|
|
40200
|
+
if (!input.budget.chargeRecords(3) || !input.budget.chargeCodeUnits(key.length))
|
|
40201
|
+
return input.text;
|
|
40202
|
+
const node = {
|
|
40203
|
+
key,
|
|
40204
|
+
line,
|
|
40205
|
+
classifiedDirectory: classified && name.endsWith("/"),
|
|
40206
|
+
children: []
|
|
40207
|
+
};
|
|
40208
|
+
parent.children.push(node);
|
|
40209
|
+
stack.length = depth + 1;
|
|
40210
|
+
stack.push(node);
|
|
40211
|
+
}
|
|
40212
|
+
const output = [];
|
|
40213
|
+
if (!appendSubtree(input, output, rootNode, classified))
|
|
40214
|
+
return input.text;
|
|
40215
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(summary.length))
|
|
40216
|
+
return input.text;
|
|
40217
|
+
output.push(summary);
|
|
40218
|
+
const rendered = output.join(`
|
|
40219
|
+
`);
|
|
40220
|
+
return rendered.length <= MAX_OUTPUT ? rendered : input.text;
|
|
40221
|
+
}
|
|
40222
|
+
function recursiveLs(input, long) {
|
|
40223
|
+
const groups = [];
|
|
40224
|
+
let current;
|
|
40225
|
+
let sawTotal = false;
|
|
40226
|
+
for (const line of input.lines) {
|
|
40227
|
+
if (line.length === 0)
|
|
40228
|
+
continue;
|
|
40229
|
+
if (/^.+:$/.test(line)) {
|
|
40230
|
+
if (current !== undefined && (long && !sawTotal || current.entryCount === 0))
|
|
40231
|
+
return input.text;
|
|
40232
|
+
const key = line.slice(0, -1);
|
|
40233
|
+
if (!input.budget.chargeRecords(3) || !input.budget.chargeCodeUnits(key.length + line.length))
|
|
40234
|
+
return input.text;
|
|
40235
|
+
current = { key, rows: [line], entryCount: 0 };
|
|
40236
|
+
groups.push(current);
|
|
40237
|
+
sawTotal = false;
|
|
40238
|
+
continue;
|
|
40239
|
+
}
|
|
40240
|
+
if (current === undefined)
|
|
40241
|
+
return input.text;
|
|
40242
|
+
if (/^total \d+$/.test(line)) {
|
|
40243
|
+
if (!long || sawTotal || current.entryCount > 0)
|
|
40244
|
+
return input.text;
|
|
40245
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(line.length))
|
|
40246
|
+
return input.text;
|
|
40247
|
+
current.rows.push(line);
|
|
40248
|
+
sawTotal = true;
|
|
40249
|
+
continue;
|
|
40250
|
+
}
|
|
40251
|
+
if (long && (!sawTotal || !LONG.test(line)) || !long && !/^[^/\\:\n]+$/.test(line))
|
|
40252
|
+
return input.text;
|
|
40253
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(line.length))
|
|
40254
|
+
return input.text;
|
|
40255
|
+
current.rows.push(line);
|
|
40256
|
+
current.entryCount++;
|
|
40257
|
+
}
|
|
40258
|
+
if (current === undefined || long && !sawTotal || current.entryCount === 0)
|
|
40259
|
+
return input.text;
|
|
40260
|
+
return renderGroups(input, groups) ?? input.text;
|
|
40261
|
+
}
|
|
40262
|
+
var RELATIVE_PATH = /^(?![[{`|])(?!.+:\d+(?::|$))[^\s:\n]+(?:[/\\][^\s:\n]+)*$/;
|
|
40263
|
+
var GATED_PROSE = /\s(?:is|are|the|this|that|because|and|with|from|into|were)\s/i;
|
|
40264
|
+
var GATED_TABLE = /^\|.*\|$/;
|
|
40265
|
+
var GATED_STRUCTURE = /^(?:```|\{|\[|`|\|)/;
|
|
40266
|
+
var GATED_DRIVE = /^[A-Za-z]:[/\\]/;
|
|
40267
|
+
function hasIllegalControl(line) {
|
|
40268
|
+
for (let index = 0;index < line.length; index++) {
|
|
40269
|
+
const code = line.charCodeAt(index);
|
|
40270
|
+
if (code === 9)
|
|
40271
|
+
continue;
|
|
40272
|
+
if (code < 32 || code === 127)
|
|
40273
|
+
return true;
|
|
40274
|
+
}
|
|
40275
|
+
return false;
|
|
40276
|
+
}
|
|
40277
|
+
function gatedPath(line) {
|
|
40278
|
+
if (line.length === 0 || hasIllegalControl(line))
|
|
40279
|
+
return false;
|
|
40280
|
+
if (line !== line.trim())
|
|
40281
|
+
return false;
|
|
40282
|
+
if (GATED_STRUCTURE.test(line) || GATED_TABLE.test(line) || GATED_PROSE.test(line))
|
|
40283
|
+
return false;
|
|
40284
|
+
const drive = GATED_DRIVE.test(line);
|
|
40285
|
+
if (line.indexOf(":", drive ? 2 : 0) >= 0)
|
|
40286
|
+
return false;
|
|
40287
|
+
const separator = line.search(/[/\\]/);
|
|
40288
|
+
if (separator < 0)
|
|
40289
|
+
return !/\s/.test(line);
|
|
40290
|
+
return !/\s/.test(line.slice(0, separator));
|
|
40291
|
+
}
|
|
40292
|
+
function paths(input, commandGated) {
|
|
40293
|
+
const groups = new Map;
|
|
40294
|
+
const ordered = [];
|
|
40295
|
+
for (const line of input.lines) {
|
|
40296
|
+
if (line.length === 0)
|
|
40297
|
+
continue;
|
|
40298
|
+
if (!(commandGated ? gatedPath(line) : RELATIVE_PATH.test(line)))
|
|
40299
|
+
return input.text;
|
|
40300
|
+
const separator = Math.max(line.lastIndexOf("/"), line.lastIndexOf("\\"));
|
|
40301
|
+
const key = separator < 0 ? "." : line.slice(0, separator) || ".";
|
|
40302
|
+
let group = groups.get(key);
|
|
40303
|
+
if (group === undefined) {
|
|
40304
|
+
if (!input.budget.chargeRecords(2) || !input.budget.chargeCodeUnits(key.length))
|
|
40305
|
+
return input.text;
|
|
40306
|
+
group = { key, rows: [], entryCount: 0 };
|
|
40307
|
+
groups.set(key, group);
|
|
40308
|
+
ordered.push(group);
|
|
40309
|
+
}
|
|
40310
|
+
if (!input.budget.chargeRecords(1))
|
|
40311
|
+
return input.text;
|
|
40312
|
+
group.rows.push(line);
|
|
40313
|
+
group.entryCount++;
|
|
40314
|
+
}
|
|
40315
|
+
if (ordered.length === 0)
|
|
40316
|
+
return input.text;
|
|
40317
|
+
return renderGroups(input, ordered) ?? input.text;
|
|
40318
|
+
}
|
|
40319
|
+
function longLs(input) {
|
|
40320
|
+
let header;
|
|
40321
|
+
const rows = [];
|
|
40322
|
+
for (const line of input.lines) {
|
|
40323
|
+
if (line.length === 0)
|
|
40324
|
+
continue;
|
|
40325
|
+
if (/^total \d+$/.test(line)) {
|
|
40326
|
+
if (header !== undefined || rows.length > 0)
|
|
40327
|
+
return input.text;
|
|
40328
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(line.length))
|
|
40329
|
+
return input.text;
|
|
40330
|
+
header = line;
|
|
40331
|
+
continue;
|
|
40332
|
+
}
|
|
40333
|
+
if (header === undefined || !LONG.test(line))
|
|
40334
|
+
return input.text;
|
|
40335
|
+
if (!input.budget.chargeRecords(1))
|
|
40336
|
+
return input.text;
|
|
40337
|
+
rows.push(line);
|
|
40338
|
+
}
|
|
40339
|
+
if (header === undefined || rows.length === 0)
|
|
40340
|
+
return input.text;
|
|
40341
|
+
const rendered = renderGroups(input, [{ key: ".", rows, entryCount: rows.length }]);
|
|
40342
|
+
if (rendered === undefined)
|
|
40343
|
+
return input.text;
|
|
40344
|
+
const output = `${header}
|
|
40345
|
+
${rendered}`;
|
|
40346
|
+
return output.length <= MAX_OUTPUT ? output : input.text;
|
|
40347
|
+
}
|
|
40348
|
+
function nonemptyLines(input) {
|
|
40349
|
+
const lines = [];
|
|
40350
|
+
for (const line of input.lines) {
|
|
40351
|
+
if (line.length === 0)
|
|
40352
|
+
continue;
|
|
40353
|
+
if (!input.budget.chargeRecords(1))
|
|
40354
|
+
return;
|
|
40355
|
+
lines.push(line);
|
|
40356
|
+
}
|
|
40357
|
+
return lines;
|
|
40358
|
+
}
|
|
40359
|
+
function compressListing(input, executable, subcommand, commandGated = false) {
|
|
40360
|
+
if (executable === "ls" && subcommand === "recursive-long")
|
|
40361
|
+
return recursiveLs(input, true);
|
|
40362
|
+
if (executable === "ls" && subcommand === "recursive-plain")
|
|
40363
|
+
return recursiveLs(input, false);
|
|
40364
|
+
if (executable === "ls")
|
|
40365
|
+
return longLs(input);
|
|
40366
|
+
if (executable === "tree") {
|
|
40367
|
+
const lines = nonemptyLines(input);
|
|
40368
|
+
if (lines === undefined)
|
|
40369
|
+
return input.text;
|
|
40370
|
+
return tree(input, lines, subcommand === "classified");
|
|
40371
|
+
}
|
|
40372
|
+
return paths(input, commandGated);
|
|
40373
|
+
}
|
|
40374
|
+
|
|
40375
|
+
// packages/rtk/src/filters/packages.ts
|
|
40376
|
+
var MUTATION = /(?:^|\s)(?:added|removed|updated|upgraded|downgraded|installed)\s+\S|lockfile|package-lock|blocked.*script|postinstall|lifecycle|vulnerabilit|peer.*conflict|resolution.*conflict|generated\s+\S/i;
|
|
40377
|
+
var SUMMARY3 = /(?:installed|added|removed|updated|audited) \d+ packages?|found \d+ vulnerabilities|Saved lockfile/i;
|
|
40378
|
+
var PROGRESS4 = /^(?:download|Resolving|Progress:|Packages:|Fetching|Downloaded|Using cached|Collecting)\b/i;
|
|
40379
|
+
function diagnosticStart(line, executable) {
|
|
40380
|
+
const lower = line.toLowerCase();
|
|
40381
|
+
if (executable === "npm" && /^npm (?:warn|warning|error)\b/.test(lower))
|
|
40382
|
+
return lower.startsWith("npm error") ? "error" : "warning";
|
|
40383
|
+
if (executable === "pnpm" && /^(?:warn(?:ing)?\b|err_pnpm_|error\b)/i.test(line))
|
|
40384
|
+
return /^(?:err_pnpm_|error\b)/i.test(line) ? "error" : "warning";
|
|
40385
|
+
if (executable === "yarn" && /^YN\d{4}:/.test(line))
|
|
40386
|
+
return /^YN(?:0009|0018|0028):/.test(line) ? "error" : "warning";
|
|
40387
|
+
if (["cargo", "uv", "bun"].includes(executable) && /^(?:warning|error):/i.test(line))
|
|
40388
|
+
return /^error:/i.test(line) ? "error" : "warning";
|
|
40389
|
+
if (executable === "pip" && /^(?:WARNING|ERROR):/.test(line))
|
|
40390
|
+
return line.startsWith("ERROR") ? "error" : "warning";
|
|
40391
|
+
return;
|
|
40392
|
+
}
|
|
40393
|
+
function stableIdentity(line, executable, severity) {
|
|
40394
|
+
let normalized = line;
|
|
40395
|
+
if (executable === "npm") {
|
|
40396
|
+
normalized = normalized.replace(/^npm (?:warn|warning|error)\s+/i, "").replace(/^\[\d+\/\d+\]\s+/, "").replace(/^workspace\s+[^:]+:\s*/i, "");
|
|
40397
|
+
} else if (executable === "pnpm") {
|
|
40398
|
+
normalized = normalized.replace(/^(?:WARN(?:ING)?|ERR_PNPM_[A-Z_]+|ERROR)\s+/i, "");
|
|
40399
|
+
} else if (executable === "yarn") {
|
|
40400
|
+
normalized = normalized.replace(/^(YN\d{4}:)\s*(?:\[[^\]]+\]\s*)?/, "$1 ");
|
|
40401
|
+
} else {
|
|
40402
|
+
normalized = normalized.replace(/^(?:warning|error):\s*/i, "");
|
|
40403
|
+
}
|
|
40404
|
+
return `${executable}\x00${severity}\x00${normalized}`;
|
|
40405
|
+
}
|
|
40406
|
+
function blocks(input, executable) {
|
|
40407
|
+
const { lines } = input;
|
|
40408
|
+
const result = [];
|
|
40409
|
+
for (let index = 0;index < lines.length; index++) {
|
|
40410
|
+
const line = lines[index] ?? "";
|
|
40411
|
+
const severity = diagnosticStart(line, executable);
|
|
40412
|
+
if (severity === undefined) {
|
|
40413
|
+
if (/^(?:DIAGNOSTIC|WARN(?:ING)?|ERR(?:OR)?|npm (?!install\b)|YN\d{4}:)/i.test(line) && !PROGRESS4.test(line))
|
|
40414
|
+
return;
|
|
40415
|
+
continue;
|
|
40416
|
+
}
|
|
40417
|
+
let end = index;
|
|
40418
|
+
while (end + 1 < lines.length) {
|
|
40419
|
+
const continuation = lines[end + 1] ?? "";
|
|
40420
|
+
if (SUMMARY3.test(continuation) || PROGRESS4.test(continuation))
|
|
40421
|
+
break;
|
|
40422
|
+
const nextSeverity = diagnosticStart(continuation, executable);
|
|
40423
|
+
if (nextSeverity !== undefined) {
|
|
40424
|
+
const continuationMessage = continuation.replace(/^npm (?:warn|error)\s+/i, "");
|
|
40425
|
+
if (!/^(?:required by|While resolving|Found:|Could not resolve)/i.test(continuationMessage))
|
|
40426
|
+
break;
|
|
40427
|
+
} else if (!/^(?:\s|Caused by:|note:|help:)/i.test(continuation)) {
|
|
40428
|
+
break;
|
|
40429
|
+
}
|
|
40430
|
+
end++;
|
|
40431
|
+
}
|
|
40432
|
+
if (!input.budget.chargeRecords(1))
|
|
40433
|
+
return;
|
|
40434
|
+
const identity = stableIdentity(line, executable, severity);
|
|
40435
|
+
if (!input.budget.chargeCodeUnits(identity.length))
|
|
40436
|
+
return;
|
|
40437
|
+
result.push({ start: index, end, severity, identity });
|
|
40438
|
+
index = end;
|
|
40439
|
+
}
|
|
40440
|
+
return result;
|
|
40441
|
+
}
|
|
40442
|
+
function compressPackages(input, executable) {
|
|
40443
|
+
const { text, lines } = input;
|
|
40444
|
+
const parsed = blocks(input, executable);
|
|
40445
|
+
if (parsed === undefined)
|
|
40446
|
+
return text;
|
|
40447
|
+
const byIdentity = new Map;
|
|
40448
|
+
for (const block of parsed) {
|
|
40449
|
+
if (byIdentity.has(block.identity))
|
|
40450
|
+
continue;
|
|
40451
|
+
if (!input.budget.chargeRecords(1))
|
|
40452
|
+
return text;
|
|
40453
|
+
byIdentity.set(block.identity, block);
|
|
40454
|
+
}
|
|
40455
|
+
if (!input.budget.chargeRecords(byIdentity.size))
|
|
40456
|
+
return text;
|
|
40457
|
+
const unique = [...byIdentity.values()];
|
|
40458
|
+
const errors4 = unique.filter((block) => block.severity === "error");
|
|
40459
|
+
const warnings = unique.filter((block) => block.severity === "warning");
|
|
40460
|
+
const selected = new Set;
|
|
40461
|
+
for (const block of [...errors4, ...warnings.slice(0, 20)])
|
|
40462
|
+
for (let index = block.start;index <= block.end; index++) {
|
|
40463
|
+
if (!input.budget.chargeRecords(1))
|
|
40464
|
+
return text;
|
|
40465
|
+
selected.add(index);
|
|
40466
|
+
}
|
|
40467
|
+
const diagnosticRows = new Set;
|
|
40468
|
+
for (const block of parsed)
|
|
40469
|
+
for (let index = block.start;index <= block.end; index++) {
|
|
40470
|
+
if (!input.budget.chargeRecords(1))
|
|
40471
|
+
return text;
|
|
40472
|
+
diagnosticRows.add(index);
|
|
40473
|
+
}
|
|
40474
|
+
for (let index = 0;index < lines.length; index++)
|
|
40475
|
+
if (!diagnosticRows.has(index) && (MUTATION.test(lines[index] ?? "") || SUMMARY3.test(lines[index] ?? "")))
|
|
40476
|
+
selected.add(index);
|
|
40477
|
+
if (selected.size === 0 || !lines.some((line) => SUMMARY3.test(line)))
|
|
40478
|
+
return text;
|
|
40479
|
+
const omittedWarningRows = new Set;
|
|
40480
|
+
const omittedWarningStarts = new Set;
|
|
40481
|
+
for (const block of warnings.slice(20)) {
|
|
40482
|
+
if (!input.budget.chargeRecords(block.end - block.start + 1))
|
|
40483
|
+
return text;
|
|
40484
|
+
let whole = true;
|
|
40485
|
+
for (let index = block.start;index <= block.end; index++)
|
|
40486
|
+
whole &&= !selected.has(index);
|
|
40487
|
+
if (!whole)
|
|
40488
|
+
continue;
|
|
40489
|
+
omittedWarningStarts.add(block.start);
|
|
40490
|
+
for (let index = block.start;index <= block.end; index++)
|
|
40491
|
+
omittedWarningRows.add(index);
|
|
40492
|
+
}
|
|
40493
|
+
const describe3 = (from, to) => {
|
|
40494
|
+
let warningBlocks = 0;
|
|
40495
|
+
let otherRows = 0;
|
|
40496
|
+
for (let index = from;index < to; index++) {
|
|
40497
|
+
if (omittedWarningStarts.has(index))
|
|
40498
|
+
warningBlocks++;
|
|
40499
|
+
if (!omittedWarningRows.has(index))
|
|
40500
|
+
otherRows++;
|
|
40501
|
+
}
|
|
40502
|
+
const parts = [];
|
|
40503
|
+
if (warningBlocks > 0)
|
|
40504
|
+
parts.push(`... ${warningBlocks} warnings omitted ...`);
|
|
40505
|
+
if (otherRows > 0)
|
|
40506
|
+
parts.push(`... ${otherRows} lines omitted ...`);
|
|
40507
|
+
return parts.length === 0 ? undefined : parts.join(`
|
|
40508
|
+
`);
|
|
40509
|
+
};
|
|
40510
|
+
let rendered = renderGaps(input, selected, (start, end) => describe3(start, end + 1));
|
|
40511
|
+
if (rendered === undefined)
|
|
40512
|
+
return text;
|
|
40513
|
+
const indexes = [...selected];
|
|
40514
|
+
const leading = describe3(0, Math.min(...indexes));
|
|
40515
|
+
const trailing = describe3(Math.max(...indexes) + 1, lines.length);
|
|
40516
|
+
if (leading !== undefined)
|
|
40517
|
+
rendered = `${leading}
|
|
40518
|
+
${rendered}`;
|
|
40519
|
+
if (trailing !== undefined)
|
|
40520
|
+
rendered = `${rendered}
|
|
40521
|
+
${trailing}`;
|
|
40522
|
+
if (rendered.length > MAX_OUTPUT)
|
|
40523
|
+
return text;
|
|
40524
|
+
for (const block of errors4)
|
|
40525
|
+
for (let index = block.start;index <= block.end; index++)
|
|
40526
|
+
if (!rendered.includes(lines[index] ?? ""))
|
|
40527
|
+
return text;
|
|
40528
|
+
return rendered;
|
|
40529
|
+
}
|
|
40530
|
+
|
|
40531
|
+
// packages/rtk/src/filters/search.ts
|
|
40532
|
+
var FULL = /^((?:[A-Za-z]:\\[^\n:]+|[^\n:]+)):(\d+):(.+)$/;
|
|
40533
|
+
var CONTEXT = /^((?:[A-Za-z]:\\[^\n]+|[^\n]+))-(\d+)-(.+)$/;
|
|
40534
|
+
var HEADING_MATCH = /^\d+:.+$/;
|
|
40535
|
+
var HEADING_CONTEXT = /^\d+-.+$/;
|
|
40536
|
+
var PATH = /^(?:[A-Za-z]:\\|[./~])?[^\n:]+$/;
|
|
40537
|
+
function retainedRecords(group, mode) {
|
|
40538
|
+
const matches = group.records.flatMap((record2, index) => record2.kind === "match" ? [index] : []);
|
|
40539
|
+
const retained = new Set(matches.length <= 12 ? matches : [...matches.slice(0, 6), ...matches.slice(-6)]);
|
|
40540
|
+
const selected = new Set;
|
|
40541
|
+
for (const match of retained) {
|
|
40542
|
+
selected.add(match);
|
|
40543
|
+
for (let index = match - 1;index >= 0; index--) {
|
|
40544
|
+
const record2 = group.records[index];
|
|
40545
|
+
if (record2?.kind === "match")
|
|
40546
|
+
break;
|
|
40547
|
+
if (record2?.kind === "separator")
|
|
40548
|
+
selected.add(index);
|
|
40549
|
+
}
|
|
40550
|
+
for (let index = match + 1;index < group.records.length; index++) {
|
|
40551
|
+
const record2 = group.records[index];
|
|
40552
|
+
if (record2?.kind === "match")
|
|
40553
|
+
break;
|
|
40554
|
+
if (record2?.kind === "separator")
|
|
40555
|
+
selected.add(index);
|
|
40556
|
+
}
|
|
40557
|
+
let before = mode.beforeContext;
|
|
40558
|
+
for (let index = match - 1;index >= 0 && before > 0; index--) {
|
|
40559
|
+
const record2 = group.records[index];
|
|
40560
|
+
if (record2?.kind === "match")
|
|
40561
|
+
break;
|
|
40562
|
+
if (record2?.kind === "context")
|
|
40563
|
+
before--;
|
|
40564
|
+
if (record2 !== undefined)
|
|
40565
|
+
selected.add(index);
|
|
40566
|
+
}
|
|
40567
|
+
let after = mode.afterContext;
|
|
40568
|
+
for (let index = match + 1;index < group.records.length && after > 0; index++) {
|
|
40569
|
+
const record2 = group.records[index];
|
|
40570
|
+
if (record2?.kind === "match")
|
|
40571
|
+
break;
|
|
40572
|
+
if (record2?.kind === "context")
|
|
40573
|
+
after--;
|
|
40574
|
+
if (record2 !== undefined)
|
|
40575
|
+
selected.add(index);
|
|
40576
|
+
}
|
|
40577
|
+
}
|
|
40578
|
+
for (let index = 0;index < group.records.length; index++)
|
|
40579
|
+
if (group.records[index]?.kind === "heading")
|
|
40580
|
+
selected.add(index);
|
|
40581
|
+
return {
|
|
40582
|
+
records: group.records.filter((_2, index) => selected.has(index)),
|
|
40583
|
+
omittedMatches: matches.length - retained.size
|
|
40584
|
+
};
|
|
40585
|
+
}
|
|
40586
|
+
function render(input, groups, mode) {
|
|
40587
|
+
if (!input.budget.chargeRecords(groups.length))
|
|
40588
|
+
return;
|
|
40589
|
+
const base = groups.length <= 40 ? groups : [...groups.slice(0, 20), ...groups.slice(-20)];
|
|
40590
|
+
const retained = new Set(base);
|
|
40591
|
+
for (const group of groups)
|
|
40592
|
+
if (group.matches === 1)
|
|
40593
|
+
retained.add(group);
|
|
40594
|
+
const output = [];
|
|
40595
|
+
let omitted = [];
|
|
40596
|
+
const flushOmitted = () => {
|
|
40597
|
+
if (omitted.length === 0)
|
|
40598
|
+
return;
|
|
40599
|
+
const matches = omitted.reduce((sum, group) => sum + group.matches, 0);
|
|
40600
|
+
output.push(`... ${omitted.length} ${omitted.length === 1 ? "file" : "files"} omitted containing ${matches} ${matches === 1 ? "match" : "matches"} ...`);
|
|
40601
|
+
omitted = [];
|
|
40602
|
+
};
|
|
40603
|
+
for (const group of groups) {
|
|
40604
|
+
if (!retained.has(group)) {
|
|
40605
|
+
omitted.push(group);
|
|
40606
|
+
continue;
|
|
40607
|
+
}
|
|
40608
|
+
flushOmitted();
|
|
40609
|
+
const selection = retainedRecords(group, mode);
|
|
40610
|
+
if (!input.budget.chargeRecords(selection.records.length))
|
|
40611
|
+
return;
|
|
40612
|
+
output.push(...selection.records.map((record2) => record2.text));
|
|
40613
|
+
if (selection.omittedMatches > 0) {
|
|
40614
|
+
const unit = selection.omittedMatches === 1 ? "match" : "matches";
|
|
40615
|
+
output.push(`... ${selection.omittedMatches} ${unit} omitted from ${group.file} ...`);
|
|
40616
|
+
}
|
|
40617
|
+
}
|
|
40618
|
+
flushOmitted();
|
|
40619
|
+
const content = output.join(`
|
|
40620
|
+
`);
|
|
40621
|
+
return input.budget.chargeCodeUnits(content.length) && content.length <= MAX_OUTPUT ? content : undefined;
|
|
40622
|
+
}
|
|
40623
|
+
function compressGrep(input, mode) {
|
|
40624
|
+
const groups = new Map;
|
|
40625
|
+
let heading;
|
|
40626
|
+
let activeFile;
|
|
40627
|
+
let pendingSeparator = false;
|
|
40628
|
+
for (const line of input.lines) {
|
|
40629
|
+
if (line === "--") {
|
|
40630
|
+
if (activeFile === undefined || pendingSeparator)
|
|
40631
|
+
return input.text;
|
|
40632
|
+
pendingSeparator = true;
|
|
40633
|
+
continue;
|
|
40634
|
+
}
|
|
40635
|
+
if (mode.heading && PATH.test(line) && !HEADING_MATCH.test(line) && !HEADING_CONTEXT.test(line)) {
|
|
40636
|
+
heading = line;
|
|
40637
|
+
activeFile = line;
|
|
40638
|
+
const group2 = groups.get(line) ?? { file: line, records: [], matches: 0 };
|
|
40639
|
+
if (!input.budget.chargeRecords(1))
|
|
40640
|
+
return input.text;
|
|
40641
|
+
group2.records.push({ kind: "heading", text: line });
|
|
40642
|
+
groups.set(line, group2);
|
|
40643
|
+
continue;
|
|
40644
|
+
}
|
|
40645
|
+
const full = line.match(FULL);
|
|
40646
|
+
const context = mode.beforeContext > 0 || mode.afterContext > 0 ? line.match(CONTEXT) : null;
|
|
40647
|
+
const file3 = mode.heading ? heading : full?.[1] ?? context?.[1];
|
|
40648
|
+
const matched = mode.heading ? HEADING_MATCH.test(line) : full !== null;
|
|
40649
|
+
const validContext = mode.heading ? (mode.beforeContext > 0 || mode.afterContext > 0) && HEADING_CONTEXT.test(line) : context !== null;
|
|
40650
|
+
if (file3 === undefined || !matched && !validContext)
|
|
40651
|
+
return input.text;
|
|
40652
|
+
if (pendingSeparator && file3 !== activeFile)
|
|
40653
|
+
return input.text;
|
|
40654
|
+
const group = groups.get(file3) ?? { file: file3, records: [], matches: 0 };
|
|
40655
|
+
const addedRecords = pendingSeparator ? 2 : 1;
|
|
40656
|
+
if (!input.budget.chargeRecords(addedRecords))
|
|
40657
|
+
return input.text;
|
|
40658
|
+
if (pendingSeparator)
|
|
40659
|
+
group.records.push({ kind: "separator", text: "--" });
|
|
40660
|
+
group.records.push({ kind: matched ? "match" : "context", text: line });
|
|
40661
|
+
if (matched)
|
|
40662
|
+
group.matches++;
|
|
40663
|
+
groups.set(file3, group);
|
|
40664
|
+
activeFile = file3;
|
|
40665
|
+
pendingSeparator = false;
|
|
40666
|
+
}
|
|
40667
|
+
if (groups.size === 0 || pendingSeparator)
|
|
40668
|
+
return input.text;
|
|
40669
|
+
return render(input, [...groups.values()], mode) ?? input.text;
|
|
40670
|
+
}
|
|
40671
|
+
|
|
40672
|
+
// packages/rtk/src/filters/status.ts
|
|
40673
|
+
var HEADER = /^(?:## .+|On branch .+|HEAD detached at .+|HEAD detached from .+)$/;
|
|
40674
|
+
var OPERATION = /^(?:(?:(?:interactive )?rebase|merge|cherry-pick|revert|bisect)(?: in progress| currently|ing|ing in progress| .*)|You are currently rebasing .+|All conflicts fixed but you are still merging\.)/i;
|
|
40675
|
+
var CHATTER = /^ {2}\((?:use |fix conflicts|all conflicts|no commands remaining).+\)$/i;
|
|
40676
|
+
var RELATION = /^(?:Your branch (?:is ahead of|is behind|and .+ have diverged).*[,.]|and have \d+ and \d+ different commits each, respectively\.)$/;
|
|
40677
|
+
var SECTION = /^(?:Changes to be committed|Changes not staged for commit|Unmerged paths|Untracked files):$/;
|
|
40678
|
+
var FINAL = /^(?:nothing to commit, working tree clean|no changes added to commit .+|nothing added to commit but untracked files present .+)$/;
|
|
40679
|
+
var LONG_RECORD = /^\t(?:modified|deleted|new file|renamed|copied|both modified|both added|added by us|added by them|deleted by us|deleted by them):\s+.+$/;
|
|
40680
|
+
var XY = new Set([
|
|
40681
|
+
" M",
|
|
40682
|
+
"M ",
|
|
40683
|
+
"MM",
|
|
40684
|
+
" A",
|
|
40685
|
+
"A ",
|
|
40686
|
+
"AM",
|
|
40687
|
+
" D",
|
|
40688
|
+
"D ",
|
|
40689
|
+
"DM",
|
|
40690
|
+
" R",
|
|
40691
|
+
"R ",
|
|
40692
|
+
"RM",
|
|
40693
|
+
" C",
|
|
40694
|
+
"C ",
|
|
40695
|
+
"CM",
|
|
40696
|
+
"??",
|
|
40697
|
+
"!!",
|
|
40698
|
+
"DD",
|
|
40699
|
+
"AU",
|
|
40700
|
+
"UD",
|
|
40701
|
+
"UA",
|
|
40702
|
+
"DU",
|
|
40703
|
+
"AA",
|
|
40704
|
+
"UU"
|
|
40705
|
+
]);
|
|
40706
|
+
function statusRecord(line) {
|
|
40707
|
+
if (line.length < 3 || !XY.has(line.slice(0, 2)))
|
|
40708
|
+
return false;
|
|
40709
|
+
const separator = line[2];
|
|
40710
|
+
if (separator !== " " && separator !== "\t")
|
|
40711
|
+
return false;
|
|
40712
|
+
const path = line.slice(3);
|
|
40713
|
+
if (path.length === 0)
|
|
40714
|
+
return false;
|
|
40715
|
+
if (line[0] === "R" || line[1] === "R" || line[0] === "C" || line[1] === "C")
|
|
40716
|
+
return /^.+ -> .+$/.test(path);
|
|
40717
|
+
return true;
|
|
40718
|
+
}
|
|
40719
|
+
function append(input, output, line) {
|
|
40720
|
+
if (!input.budget.chargeRecords(1) || !input.budget.chargeCodeUnits(line.length))
|
|
40721
|
+
return false;
|
|
40722
|
+
output.push(line);
|
|
40723
|
+
return true;
|
|
40724
|
+
}
|
|
40725
|
+
function compressGitStatus(input) {
|
|
40726
|
+
const output = [];
|
|
40727
|
+
let section;
|
|
40728
|
+
let long = false;
|
|
40729
|
+
let sawRecord = false;
|
|
40730
|
+
for (const line of input.lines) {
|
|
40731
|
+
if (line.length === 0)
|
|
40732
|
+
continue;
|
|
40733
|
+
if (!input.budget.chargeRecords(1))
|
|
40734
|
+
return input.text;
|
|
40735
|
+
if (SECTION.test(line)) {
|
|
40736
|
+
long = true;
|
|
40737
|
+
section = line === "Untracked files:" ? "untracked" : "tracked";
|
|
40738
|
+
if (!append(input, output, line))
|
|
40739
|
+
return input.text;
|
|
40740
|
+
continue;
|
|
40741
|
+
}
|
|
40742
|
+
if (HEADER.test(line) || RELATION.test(line) || OPERATION.test(line) || FINAL.test(line)) {
|
|
40743
|
+
if (!append(input, output, line))
|
|
40744
|
+
return input.text;
|
|
40745
|
+
continue;
|
|
40746
|
+
}
|
|
40747
|
+
if (CHATTER.test(line))
|
|
40748
|
+
continue;
|
|
40749
|
+
if (long) {
|
|
40750
|
+
const record2 = section === "untracked" ? /^\t\S.+$/.test(line) : LONG_RECORD.test(line);
|
|
40751
|
+
if (!record2)
|
|
40752
|
+
return input.text;
|
|
40753
|
+
sawRecord = true;
|
|
40754
|
+
if (!append(input, output, line))
|
|
40755
|
+
return input.text;
|
|
40756
|
+
continue;
|
|
40757
|
+
}
|
|
40758
|
+
if (!statusRecord(line))
|
|
40759
|
+
return input.text;
|
|
40760
|
+
sawRecord = true;
|
|
40761
|
+
if (!append(input, output, line))
|
|
40762
|
+
return input.text;
|
|
40763
|
+
}
|
|
40764
|
+
if (!sawRecord)
|
|
40765
|
+
return input.text;
|
|
40766
|
+
const rendered = output.join(`
|
|
40767
|
+
`);
|
|
40768
|
+
return rendered.length <= MAX_OUTPUT ? rendered : input.text;
|
|
40769
|
+
}
|
|
40770
|
+
|
|
40771
|
+
// packages/rtk/src/filters/tests.ts
|
|
40772
|
+
function isFailureStart(line, executable) {
|
|
40773
|
+
if (executable === "vitest")
|
|
40774
|
+
return /^\s*FAIL\s{2}\S.+\s>\s/.test(line);
|
|
40775
|
+
if (executable === "jest")
|
|
40776
|
+
return /^\s*\u25CF\s/.test(line);
|
|
40777
|
+
if (executable === "bun")
|
|
40778
|
+
return /^\s*(?:FAIL\s|UnhandledPromiseRejection|Uncaught exception|panic:|error:.*(?:hook|unhandled rejection))/.test(line);
|
|
40779
|
+
if (executable === "pytest")
|
|
40780
|
+
return /^\s*(?:FAILED\s|={2,} FAILURES ={2,}|ERROR collecting)/.test(line);
|
|
40781
|
+
if (executable === "go")
|
|
40782
|
+
return /^\s*(?:--- FAIL:|# \S|FAIL\s+\S+\s+\[build failed\])/.test(line);
|
|
40783
|
+
return /^\s*(?:FAIL\b|--- FAIL:|FAILED\b|={2,} FAILURES ={2,}|panic:|ERROR collecting|\u25CF )/.test(line);
|
|
40784
|
+
}
|
|
40785
|
+
function isSummary(line, executable) {
|
|
40786
|
+
if (executable === "bun")
|
|
40787
|
+
return /^(?:\d+ (?:pass|fail|skip|todo)|Ran \d+ tests?|error: \d+ unhandled)/.test(line);
|
|
40788
|
+
if (executable === "vitest")
|
|
40789
|
+
return /^(?:Test Files|Tests |Snapshots |Snapshots:|Projects? |Shards? |Attachments? |Retries? )/i.test(line);
|
|
40790
|
+
if (executable === "jest")
|
|
40791
|
+
return /^(?:Test Suites:|Tests:|Snapshots:)/.test(line);
|
|
40792
|
+
if (executable === "pytest")
|
|
40793
|
+
return /(?:\d+ (?:passed|failed|errors?|skipped|xfailed|xpassed))(?:,| in|$)/.test(line) || /^=+ short test summary/.test(line);
|
|
40794
|
+
if (executable === "go")
|
|
40795
|
+
return /^(?:--- SKIP:|(?:ok|FAIL)\s+\S)/.test(line);
|
|
40796
|
+
return /^(?:\d+ (?:pass|fail|skip|todo)|Ran \d+ tests?|Tests?:|Test Files|Snapshots:|test result:|(?:ok|FAIL)\s+\S|=+ .* (?:passed|failed|error|skipped))/i.test(line);
|
|
40797
|
+
}
|
|
40798
|
+
function isFailureSummary(line, executable) {
|
|
40799
|
+
if (executable === "bun")
|
|
40800
|
+
return /^(?:[1-9]\d* fail|error: [1-9]\d* unhandled)/.test(line);
|
|
40801
|
+
if (["vitest", "jest"].includes(executable))
|
|
40802
|
+
return /(?:^|\s)[1-9]\d* failed/.test(line);
|
|
40803
|
+
if (executable === "pytest")
|
|
40804
|
+
return /[1-9]\d* (?:failed|errors?)/.test(line);
|
|
40805
|
+
if (executable === "go")
|
|
40806
|
+
return /^FAIL\s+\S/.test(line);
|
|
40807
|
+
return /(?:[1-9]\d* fail|[1-9]\d* failed|FAIL\s+\S)/.test(line);
|
|
40808
|
+
}
|
|
40809
|
+
function compressTests(input, executable = "unknown") {
|
|
40810
|
+
const { text, lines } = input;
|
|
40811
|
+
const selected = new Set;
|
|
40812
|
+
const starts = [];
|
|
40813
|
+
let hasFailureSummary = false;
|
|
40814
|
+
for (let index = 0;index < lines.length; index++) {
|
|
40815
|
+
const line = lines[index] ?? "";
|
|
40816
|
+
if (isFailureStart(line, executable))
|
|
40817
|
+
starts.push(index);
|
|
40818
|
+
if (isSummary(line, executable))
|
|
40819
|
+
selected.add(index);
|
|
40820
|
+
if (isFailureSummary(line, executable))
|
|
40821
|
+
hasFailureSummary = true;
|
|
40822
|
+
}
|
|
40823
|
+
if (hasFailureSummary && starts.length === 0)
|
|
40824
|
+
return text;
|
|
40825
|
+
for (let offset = 0;offset < starts.length; offset++) {
|
|
40826
|
+
const start = starts[offset];
|
|
40827
|
+
if (start === undefined || !input.budget.chargeRecords(1))
|
|
40828
|
+
return text;
|
|
40829
|
+
const nextFailure = starts[offset + 1] ?? lines.length;
|
|
40830
|
+
let end = start;
|
|
40831
|
+
while (end + 1 < nextFailure) {
|
|
40832
|
+
const line = lines[end + 1] ?? "";
|
|
40833
|
+
if (/^progress \d+$/.test(line) || isSummary(line, executable))
|
|
40834
|
+
break;
|
|
40835
|
+
end++;
|
|
40836
|
+
}
|
|
40837
|
+
const count = end - start + 1;
|
|
40838
|
+
if (!input.budget.chargeRecords(count))
|
|
40839
|
+
return text;
|
|
40840
|
+
for (let index = start;index <= end; index++)
|
|
40841
|
+
selected.add(index);
|
|
40842
|
+
}
|
|
40843
|
+
if (selected.size === 0)
|
|
40844
|
+
return text;
|
|
40845
|
+
let rendered = renderGaps(input, selected, (start, end) => `... ${end - start + 1} lines omitted ...`);
|
|
40846
|
+
if (rendered === undefined)
|
|
40847
|
+
return text;
|
|
40848
|
+
const indexes = [...selected];
|
|
40849
|
+
const leading = Math.min(...indexes);
|
|
40850
|
+
const trailing = lines.length - 1 - Math.max(...indexes);
|
|
40851
|
+
if (leading > 0)
|
|
40852
|
+
rendered = `... ${leading} lines omitted ...
|
|
40853
|
+
${rendered}`;
|
|
40854
|
+
if (trailing > 0)
|
|
40855
|
+
rendered = `${rendered}
|
|
40856
|
+
... ${trailing} lines omitted ...`;
|
|
40857
|
+
if (rendered.length > MAX_OUTPUT)
|
|
40858
|
+
return text;
|
|
40859
|
+
for (const start of starts)
|
|
40860
|
+
if (!rendered.includes(lines[start] ?? ""))
|
|
40861
|
+
return text;
|
|
40862
|
+
return rendered;
|
|
40863
|
+
}
|
|
40864
|
+
|
|
40865
|
+
// packages/rtk/src/index.ts
|
|
40866
|
+
var MIN_INPUT = 500;
|
|
40867
|
+
var MAX_INPUT = 1e6;
|
|
40868
|
+
var MAX_OUTPUT2 = 250000;
|
|
40869
|
+
var SHELL = new Set(["bash", "shell", "terminal", "exec", "run_command", "execute_command"]);
|
|
40870
|
+
var NON_SHELL = new Set([
|
|
40871
|
+
"read",
|
|
40872
|
+
"edit",
|
|
40873
|
+
"write",
|
|
40874
|
+
"glob",
|
|
40875
|
+
"grep_search",
|
|
40876
|
+
"search",
|
|
40877
|
+
"web_search",
|
|
40878
|
+
"web_fetch",
|
|
40879
|
+
"read_file",
|
|
40880
|
+
"list_directory",
|
|
40881
|
+
"find_files",
|
|
40882
|
+
"code_search",
|
|
40883
|
+
"apply_patch"
|
|
40884
|
+
]);
|
|
40885
|
+
function emptyReport(errors4 = 0) {
|
|
40886
|
+
return {
|
|
40887
|
+
applied: false,
|
|
40888
|
+
filterHits: 0,
|
|
40889
|
+
originalCodeUnits: 0,
|
|
40890
|
+
compressedCodeUnits: 0,
|
|
40891
|
+
estimatedTokensSaved: 0,
|
|
40892
|
+
filters: [],
|
|
40893
|
+
skippedInternalErrors: errors4
|
|
40894
|
+
};
|
|
40895
|
+
}
|
|
40896
|
+
function normalizeName(name) {
|
|
40897
|
+
return name.toLowerCase().replace(/[-./\s]+/g, "_");
|
|
40898
|
+
}
|
|
40899
|
+
function originOf(tool) {
|
|
40900
|
+
if (tool === undefined)
|
|
40901
|
+
return "unknown";
|
|
40902
|
+
const name = normalizeName(tool.name);
|
|
40903
|
+
if (SHELL.has(name))
|
|
40904
|
+
return "shell";
|
|
40905
|
+
if (NON_SHELL.has(name))
|
|
40906
|
+
return "non-shell";
|
|
40907
|
+
return "unknown";
|
|
40908
|
+
}
|
|
40909
|
+
function extractCommand(input) {
|
|
40910
|
+
if (typeof input === "string")
|
|
40911
|
+
return input.length === 0 ? undefined : input;
|
|
40912
|
+
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
40913
|
+
return;
|
|
40914
|
+
if (Object.getPrototypeOf(input) !== Object.prototype)
|
|
40915
|
+
return;
|
|
40916
|
+
const object2 = input;
|
|
40917
|
+
for (const key of ["command", "cmd", "script"]) {
|
|
40918
|
+
if (!Object.hasOwn(object2, key))
|
|
40919
|
+
continue;
|
|
40920
|
+
const value = object2[key];
|
|
40921
|
+
if (typeof value === "string" && value.length > 0)
|
|
40922
|
+
return value;
|
|
40923
|
+
}
|
|
40924
|
+
return;
|
|
40925
|
+
}
|
|
40926
|
+
function prefix(lines) {
|
|
40927
|
+
return lines.slice(0, 64).join(`
|
|
40928
|
+
`).slice(0, 4096);
|
|
40929
|
+
}
|
|
40930
|
+
function sampleRows(lines) {
|
|
40931
|
+
return lines.length <= 128 ? lines : [...lines.slice(0, 64), ...lines.slice(-64)];
|
|
40932
|
+
}
|
|
40933
|
+
function detect(input, command, origin) {
|
|
40934
|
+
const { lines } = input;
|
|
40935
|
+
const sample = prefix(lines);
|
|
40936
|
+
const classification = origin === "shell" && command !== undefined ? classifyCommand(command) : undefined;
|
|
40937
|
+
if (origin === "shell" && command !== undefined && classification === undefined)
|
|
40938
|
+
return;
|
|
40939
|
+
if (classification !== undefined)
|
|
40940
|
+
return { id: classification.family, classification };
|
|
40941
|
+
if (GIT_DIFF_EVIDENCE_HEADER.test(sample) && GIT_DIFF_EVIDENCE_PAIR.test(sample))
|
|
40942
|
+
return { id: "git-diff" };
|
|
40943
|
+
if (/^(?:On branch |## |Changes |Untracked files:)/m.test(sample) && /^(?:[ MADRCU?!]{2} |\s+(?:modified|deleted|new file):)/m.test(sample))
|
|
40944
|
+
return { id: "git-status" };
|
|
40945
|
+
if (GIT_LOG_EVIDENCE_COMMIT.test(sample) && GIT_LOG_EVIDENCE_BODY.test(sample))
|
|
40946
|
+
return { id: "git-log" };
|
|
40947
|
+
if (origin === "unknown") {
|
|
40948
|
+
const inferred = inferBuildOrTest(sampleRows(lines));
|
|
40949
|
+
if (inferred !== undefined)
|
|
40950
|
+
return { id: inferred };
|
|
40951
|
+
}
|
|
40952
|
+
const inferredGrepRows = lines.filter((line) => /^(?:[A-Za-z]:\\.+|[^\n:]+):\d+:.+$/.test(line));
|
|
40953
|
+
if (origin === "unknown" && inferredGrepRows.length >= 3 && inferredGrepRows.length / Math.max(1, lines.filter((line) => line.length > 0).length) >= 0.8)
|
|
40954
|
+
return {
|
|
40955
|
+
id: "grep",
|
|
40956
|
+
classification: {
|
|
40957
|
+
family: "grep",
|
|
40958
|
+
executable: "inferred",
|
|
40959
|
+
grepMode: { heading: false, lineNumber: true, beforeContext: 0, afterContext: 0 }
|
|
40960
|
+
}
|
|
40961
|
+
};
|
|
40962
|
+
let candidates = 0;
|
|
40963
|
+
let pathLines = 0;
|
|
40964
|
+
let conflicts = 0;
|
|
40965
|
+
for (const line of lines) {
|
|
40966
|
+
if (line.length === 0)
|
|
40967
|
+
continue;
|
|
40968
|
+
candidates++;
|
|
40969
|
+
if (/^(?![[{`|])(?!.+:\d+(?::|$))[^\s:\n]+(?:[/\\][^\s:\n]+)*$/.test(line))
|
|
40970
|
+
pathLines++;
|
|
40971
|
+
if (/\s(?:is|are|the|this|that)\s/i.test(line) || /^(?:```|\{|\[)|\|.+\|$/.test(line))
|
|
40972
|
+
conflicts++;
|
|
40973
|
+
}
|
|
40974
|
+
if (candidates >= 10 && pathLines / candidates >= 0.8 && conflicts / candidates <= 0.1)
|
|
40975
|
+
return { id: "path-list" };
|
|
40976
|
+
if (origin === "shell" && (sample.match(/^\s*\d+[\t |:].+$/gm)?.length ?? 0) >= 10)
|
|
40977
|
+
return { id: "numbered-read" };
|
|
40978
|
+
return;
|
|
40979
|
+
}
|
|
40980
|
+
function keepRegions(input, head, tail) {
|
|
40981
|
+
const selected = new Set;
|
|
40982
|
+
if (!input.budget.chargeRecords(head + tail))
|
|
40983
|
+
return input.text;
|
|
40984
|
+
for (let index = 0;index < Math.min(head, input.lines.length); index++)
|
|
40985
|
+
selected.add(index);
|
|
40986
|
+
for (let index = Math.max(head, input.lines.length - tail);index < input.lines.length; index++)
|
|
40987
|
+
selected.add(index);
|
|
40988
|
+
return renderSelection(input, selected) ?? input.text;
|
|
40989
|
+
}
|
|
40990
|
+
function deduplicate(input) {
|
|
40991
|
+
const selected = new Set;
|
|
40992
|
+
let previous;
|
|
40993
|
+
for (let index = 0;index < input.lines.length; index++) {
|
|
40994
|
+
const line = input.lines[index] ?? "";
|
|
40995
|
+
if (line === previous)
|
|
40996
|
+
continue;
|
|
40997
|
+
if (!input.budget.chargeRecords(1))
|
|
40998
|
+
return input.text;
|
|
40999
|
+
selected.add(index);
|
|
41000
|
+
previous = line;
|
|
41001
|
+
}
|
|
41002
|
+
return renderSelection(input, selected) ?? input.text;
|
|
41003
|
+
}
|
|
41004
|
+
function keepAnchors(input, isAnchor, head, tail) {
|
|
41005
|
+
const selected = new Set;
|
|
41006
|
+
for (let index = 0;index < input.lines.length; index++) {
|
|
41007
|
+
if (index < head || index >= input.lines.length - tail || isAnchor(input.lines[index] ?? "")) {
|
|
41008
|
+
if (!input.budget.chargeRecords(1))
|
|
41009
|
+
return input.text;
|
|
41010
|
+
selected.add(index);
|
|
41011
|
+
}
|
|
41012
|
+
}
|
|
41013
|
+
return renderSelection(input, selected) ?? input.text;
|
|
41014
|
+
}
|
|
41015
|
+
function specialized(input, id, classification) {
|
|
41016
|
+
const { text: content, lines } = input;
|
|
41017
|
+
if (id === "git-status")
|
|
41018
|
+
return compressGitStatus(input);
|
|
41019
|
+
if (id === "lint-output")
|
|
41020
|
+
return compressDiagnostics(input);
|
|
41021
|
+
if (id === "build-output")
|
|
41022
|
+
return compressBuild(input);
|
|
41023
|
+
if (id === "test-output")
|
|
41024
|
+
return compressTests(input, classification?.executable);
|
|
41025
|
+
if (id === "package-output")
|
|
41026
|
+
return compressPackages(input, classification?.executable ?? "unknown");
|
|
41027
|
+
if (id === "git-operation")
|
|
41028
|
+
return compressGitOperation(input);
|
|
41029
|
+
if (id === "docker-build")
|
|
41030
|
+
return compressDocker(input);
|
|
41031
|
+
if (id === "tree-output" || id === "path-list")
|
|
41032
|
+
return compressListing(input, classification?.executable ?? "find", classification?.subcommand, classification !== undefined);
|
|
41033
|
+
if (id === "grep" && classification?.grepMode !== undefined)
|
|
41034
|
+
return compressGrep(input, classification.grepMode);
|
|
41035
|
+
if (!input.budget.chargeRecords(lines.length))
|
|
41036
|
+
return content;
|
|
41037
|
+
switch (id) {
|
|
41038
|
+
case "git-diff":
|
|
41039
|
+
return keepAnchors(input, (line) => GIT_DIFF_ANCHOR.test(line), 20, 12);
|
|
41040
|
+
case "git-log":
|
|
41041
|
+
return keepAnchors(input, (line) => GIT_LOG_ANCHOR.test(line), 20, 12);
|
|
41042
|
+
case "grep":
|
|
41043
|
+
return keepRegions(input, 40, 20);
|
|
41044
|
+
case "numbered-read":
|
|
41045
|
+
return lines.length >= 250 ? keepRegions(input, 100, 50) : content;
|
|
41046
|
+
case "deduplicate-log":
|
|
41047
|
+
return deduplicate(input);
|
|
41048
|
+
case "smart-truncate":
|
|
41049
|
+
return keepRegions(input, 200, 100);
|
|
41050
|
+
}
|
|
41051
|
+
}
|
|
41052
|
+
function accept(original, candidate) {
|
|
41053
|
+
return candidate.length > 0 && candidate.length < original.length && candidate.length <= MAX_OUTPUT2 ? candidate : undefined;
|
|
41054
|
+
}
|
|
41055
|
+
function filter(input, origin, command) {
|
|
41056
|
+
const { text: content, lines } = input;
|
|
41057
|
+
const detection = detect(input, command, origin);
|
|
41058
|
+
if (detection !== undefined) {
|
|
41059
|
+
const { id, classification } = detection;
|
|
41060
|
+
const first = accept(content, specialized(input, id, classification));
|
|
41061
|
+
if (first === undefined)
|
|
41062
|
+
return;
|
|
41063
|
+
return { content: first, filters: [id] };
|
|
41064
|
+
}
|
|
41065
|
+
if (origin !== "shell")
|
|
41066
|
+
return;
|
|
41067
|
+
if (lines.length >= 20) {
|
|
41068
|
+
const compact = accept(content, deduplicate(input));
|
|
41069
|
+
if (compact !== undefined)
|
|
41070
|
+
return { content: compact, filters: ["deduplicate-log"] };
|
|
41071
|
+
}
|
|
41072
|
+
if (lines.length >= 500) {
|
|
41073
|
+
const compact = accept(content, specialized(input, "smart-truncate"));
|
|
41074
|
+
if (compact !== undefined)
|
|
41075
|
+
return { content: compact, filters: ["smart-truncate"] };
|
|
41076
|
+
}
|
|
41077
|
+
return;
|
|
41078
|
+
}
|
|
41079
|
+
function transformRequest(request2, config2) {
|
|
41080
|
+
if (!config2.enabled)
|
|
41081
|
+
return { request: request2, report: emptyReport() };
|
|
41082
|
+
try {
|
|
41083
|
+
const uses = new Map;
|
|
41084
|
+
let changed = false;
|
|
41085
|
+
let originalCodeUnits = 0;
|
|
41086
|
+
let compressedCodeUnits = 0;
|
|
41087
|
+
let filterHits = 0;
|
|
41088
|
+
let skippedInternalErrors = 0;
|
|
41089
|
+
const filterOrder = [];
|
|
41090
|
+
const messages = request2.messages.map((message) => {
|
|
41091
|
+
let messageChanged = false;
|
|
41092
|
+
const content = message.content.map((block) => {
|
|
41093
|
+
if (block.type === "toolUse") {
|
|
41094
|
+
uses.set(block.id, block);
|
|
41095
|
+
return block;
|
|
41096
|
+
}
|
|
41097
|
+
if (block.type !== "toolResult" || block.isError === true || block.cacheControl !== undefined || block.content.length < MIN_INPUT || block.content.length > MAX_INPUT)
|
|
41098
|
+
return block;
|
|
41099
|
+
const use = uses.get(block.toolUseId);
|
|
41100
|
+
const origin = originOf(use);
|
|
41101
|
+
if (origin === "non-shell")
|
|
41102
|
+
return block;
|
|
41103
|
+
try {
|
|
41104
|
+
const command = origin === "shell" && use !== undefined ? extractCommand(use.input) : undefined;
|
|
41105
|
+
const bounded = scanText(block.content);
|
|
41106
|
+
if (bounded === undefined)
|
|
41107
|
+
return block;
|
|
41108
|
+
const result = filter(bounded, origin, command);
|
|
41109
|
+
if (result === undefined)
|
|
41110
|
+
return block;
|
|
41111
|
+
changed = true;
|
|
41112
|
+
messageChanged = true;
|
|
41113
|
+
originalCodeUnits += block.content.length;
|
|
41114
|
+
compressedCodeUnits += result.content.length;
|
|
41115
|
+
filterHits += result.filters.length;
|
|
41116
|
+
for (const id of result.filters)
|
|
41117
|
+
if (!filterOrder.includes(id))
|
|
41118
|
+
filterOrder.push(id);
|
|
41119
|
+
return { ...block, content: result.content };
|
|
41120
|
+
} catch {
|
|
41121
|
+
skippedInternalErrors++;
|
|
41122
|
+
return block;
|
|
41123
|
+
}
|
|
41124
|
+
});
|
|
41125
|
+
return messageChanged ? { ...message, content } : message;
|
|
41126
|
+
});
|
|
41127
|
+
if (!changed)
|
|
41128
|
+
return { request: request2, report: { ...emptyReport(), skippedInternalErrors } };
|
|
41129
|
+
const transformed = { ...request2, messages };
|
|
41130
|
+
return {
|
|
41131
|
+
request: transformed,
|
|
41132
|
+
report: {
|
|
41133
|
+
applied: true,
|
|
41134
|
+
filterHits,
|
|
41135
|
+
originalCodeUnits,
|
|
41136
|
+
compressedCodeUnits,
|
|
41137
|
+
estimatedTokensSaved: Math.max(0, estimateInputTokens(request2) - estimateInputTokens(transformed)),
|
|
41138
|
+
filters: filterOrder,
|
|
41139
|
+
skippedInternalErrors
|
|
41140
|
+
}
|
|
41141
|
+
};
|
|
41142
|
+
} catch {
|
|
41143
|
+
return { request: request2, report: emptyReport(1) };
|
|
41144
|
+
}
|
|
41145
|
+
}
|
|
41146
|
+
|
|
38812
41147
|
// apps/gateway/src/logging.ts
|
|
38813
41148
|
function requestLogDefaults(id, at) {
|
|
38814
41149
|
return {
|
|
@@ -38830,7 +41165,13 @@ function requestLogDefaults(id, at) {
|
|
|
38830
41165
|
ttftMs: null,
|
|
38831
41166
|
durationMs: 0,
|
|
38832
41167
|
costUsd: 0,
|
|
38833
|
-
degradations: []
|
|
41168
|
+
degradations: [],
|
|
41169
|
+
rtkApplied: false,
|
|
41170
|
+
rtkFilterHits: 0,
|
|
41171
|
+
rtkOriginalCodeUnits: 0,
|
|
41172
|
+
rtkCompressedCodeUnits: 0,
|
|
41173
|
+
rtkEstimatedTokensSaved: 0,
|
|
41174
|
+
rtkFilters: []
|
|
38834
41175
|
};
|
|
38835
41176
|
}
|
|
38836
41177
|
function newCompletedRequestLog(id, at, overrides) {
|
|
@@ -38965,11 +41306,12 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
38965
41306
|
const logger2 = deps.logger ?? noopLogger;
|
|
38966
41307
|
const startedAt = deps.now();
|
|
38967
41308
|
const snapshot = await deps.snapshots.get(startedAt);
|
|
38968
|
-
const deadlineAt = startedAt + snapshot.settings.requestDeadlineMs;
|
|
41309
|
+
const deadlineAt = snapshot.settings.requestDeadlineMs === 0 ? null : startedAt + snapshot.settings.requestDeadlineMs;
|
|
38969
41310
|
const log = newCompletedRequestLog(requestId, startedAt, {
|
|
38970
41311
|
requestedModel: request2.model,
|
|
38971
41312
|
status: 0
|
|
38972
41313
|
});
|
|
41314
|
+
let dispatchRequest = request2;
|
|
38973
41315
|
const fail = (code, message) => {
|
|
38974
41316
|
log.errorCode = code;
|
|
38975
41317
|
log.status = HTTP_STATUS[code];
|
|
@@ -38981,36 +41323,45 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
38981
41323
|
log: () => log
|
|
38982
41324
|
};
|
|
38983
41325
|
};
|
|
38984
|
-
const
|
|
38985
|
-
const abortFromClient = () =>
|
|
41326
|
+
const dispatchController = new AbortController;
|
|
41327
|
+
const abortFromClient = () => dispatchController.abort(signal.reason);
|
|
38986
41328
|
if (signal.aborted)
|
|
38987
41329
|
abortFromClient();
|
|
38988
41330
|
else
|
|
38989
41331
|
signal.addEventListener("abort", abortFromClient, { once: true });
|
|
38990
|
-
const deadlineTimer = setTimeout(() =>
|
|
38991
|
-
const dispatchSignal =
|
|
41332
|
+
const deadlineTimer = deadlineAt === null ? null : setTimeout(() => dispatchController.abort(new GatewayError("TIMEOUT", "request deadline exceeded")), Math.max(0, deadlineAt - deps.now()));
|
|
41333
|
+
const dispatchSignal = dispatchController.signal;
|
|
38992
41334
|
const clearDeadline = () => {
|
|
38993
|
-
|
|
41335
|
+
if (deadlineTimer !== null)
|
|
41336
|
+
clearTimeout(deadlineTimer);
|
|
38994
41337
|
signal.removeEventListener("abort", abortFromClient);
|
|
38995
41338
|
};
|
|
38996
41339
|
const checkCancellation = () => {
|
|
38997
|
-
if (!dispatchSignal.aborted)
|
|
38998
|
-
return;
|
|
38999
41340
|
if (signal.aborted)
|
|
39000
41341
|
throw signal.reason;
|
|
39001
|
-
|
|
41342
|
+
if (deadlineAt !== null && (dispatchSignal.aborted || deps.now() >= deadlineAt))
|
|
41343
|
+
throw new GatewayError("TIMEOUT", "request deadline exceeded");
|
|
39002
41344
|
};
|
|
39003
41345
|
let model;
|
|
39004
41346
|
try {
|
|
39005
41347
|
checkCancellation();
|
|
39006
|
-
|
|
41348
|
+
const transformed = transformRequest(request2, { enabled: snapshot.settings.rtkEnabled });
|
|
41349
|
+
dispatchRequest = transformed.request;
|
|
41350
|
+
log.rtkApplied = transformed.report.applied;
|
|
41351
|
+
log.rtkFilterHits = transformed.report.filterHits;
|
|
41352
|
+
log.rtkOriginalCodeUnits = transformed.report.originalCodeUnits;
|
|
41353
|
+
log.rtkCompressedCodeUnits = transformed.report.compressedCodeUnits;
|
|
41354
|
+
log.rtkEstimatedTokensSaved = transformed.report.estimatedTokensSaved;
|
|
41355
|
+
log.rtkFilters = transformed.report.filters;
|
|
41356
|
+
checkCancellation();
|
|
41357
|
+
model = resolveModel(dispatchRequest.model, snapshot);
|
|
39007
41358
|
} catch (error51) {
|
|
39008
41359
|
const { code } = classify(error51);
|
|
39009
41360
|
clearDeadline();
|
|
39010
41361
|
return fail(code, error51 instanceof Error ? error51.message : "unresolvable model");
|
|
39011
41362
|
}
|
|
39012
41363
|
const { candidates, excluded } = rank({
|
|
39013
|
-
request:
|
|
41364
|
+
request: dispatchRequest,
|
|
39014
41365
|
model,
|
|
39015
41366
|
snapshot,
|
|
39016
41367
|
now: startedAt,
|
|
@@ -39024,10 +41375,11 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39024
41375
|
count: candidates.length
|
|
39025
41376
|
});
|
|
39026
41377
|
for (const e of excluded) {
|
|
39027
|
-
|
|
41378
|
+
const capabilityOnly = e.reason === "capability:anthropicTools";
|
|
41379
|
+
log.degradations.push(capabilityOnly ? `excluded:${e.reason}` : `excluded:${e.credentialId}:${e.reason}`);
|
|
39028
41380
|
logger2.debug("routing candidate excluded", {
|
|
39029
41381
|
requestId,
|
|
39030
|
-
credentialId: e.credentialId,
|
|
41382
|
+
...capabilityOnly ? {} : { credentialId: e.credentialId },
|
|
39031
41383
|
reason: e.reason
|
|
39032
41384
|
});
|
|
39033
41385
|
}
|
|
@@ -39045,11 +41397,14 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39045
41397
|
let lastError = null;
|
|
39046
41398
|
candidateLoop:
|
|
39047
41399
|
for (let i = 0;i < maxAttempts; i++) {
|
|
39048
|
-
|
|
39049
|
-
|
|
41400
|
+
try {
|
|
41401
|
+
checkCancellation();
|
|
41402
|
+
} catch (error51) {
|
|
41403
|
+
if (signal.aborted)
|
|
41404
|
+
throw signal.reason;
|
|
41405
|
+
lastError = error51 instanceof GatewayError ? error51 : new GatewayError("TIMEOUT", "request deadline exceeded");
|
|
39050
41406
|
break;
|
|
39051
41407
|
}
|
|
39052
|
-
checkCancellation();
|
|
39053
41408
|
const candidate = candidates[i];
|
|
39054
41409
|
log.attempts = i + 1;
|
|
39055
41410
|
log.credentialId = candidate.credential.id;
|
|
@@ -39081,7 +41436,7 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39081
41436
|
try {
|
|
39082
41437
|
const result = await waitForCancellation(attempt({
|
|
39083
41438
|
candidate,
|
|
39084
|
-
request:
|
|
41439
|
+
request: dispatchRequest,
|
|
39085
41440
|
adapter: deps.adapters[candidate.target.provider],
|
|
39086
41441
|
http: deps.http,
|
|
39087
41442
|
now: attemptNow,
|
|
@@ -39166,7 +41521,7 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39166
41521
|
} catch (error51) {
|
|
39167
41522
|
if (signal.aborted)
|
|
39168
41523
|
throw signal.reason;
|
|
39169
|
-
const classifiedError = dispatchSignal.aborted ? { code: "TIMEOUT" } : classify(error51);
|
|
41524
|
+
const classifiedError = deadlineAt !== null && dispatchSignal.aborted ? { code: "TIMEOUT" } : classify(error51);
|
|
39170
41525
|
const { code: code2, retryAfterMs } = classifiedError;
|
|
39171
41526
|
const message = error51 instanceof Error ? error51.message : "attempt failed";
|
|
39172
41527
|
lastError = retryAfterMs === undefined ? new GatewayError(code2, message) : new GatewayError(code2, message, { retryAfterMs });
|
|
@@ -39186,7 +41541,7 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39186
41541
|
} catch (refreshError) {
|
|
39187
41542
|
if (signal.aborted)
|
|
39188
41543
|
throw signal.reason;
|
|
39189
|
-
const classified = dispatchSignal.aborted ? { code: "TIMEOUT" } : classify(refreshError);
|
|
41544
|
+
const classified = deadlineAt !== null && dispatchSignal.aborted ? { code: "TIMEOUT" } : classify(refreshError);
|
|
39190
41545
|
const refreshMessage = refreshError instanceof Error ? refreshError.message : "credential refresh failed";
|
|
39191
41546
|
lastError = classified.retryAfterMs === undefined ? new GatewayError(classified.code, refreshMessage) : new GatewayError(classified.code, refreshMessage, {
|
|
39192
41547
|
retryAfterMs: classified.retryAfterMs
|
|
@@ -39243,8 +41598,8 @@ async function dispatch(request2, deps, signal, requestId) {
|
|
|
39243
41598
|
};
|
|
39244
41599
|
} finally {
|
|
39245
41600
|
clearDeadline();
|
|
39246
|
-
if (!
|
|
39247
|
-
|
|
41601
|
+
if (!dispatchController.signal.aborted)
|
|
41602
|
+
dispatchController.abort();
|
|
39248
41603
|
}
|
|
39249
41604
|
}
|
|
39250
41605
|
return { events: run(), log: () => log };
|
|
@@ -39271,7 +41626,8 @@ var STOP_REASON2 = {
|
|
|
39271
41626
|
maxTokens: "max_tokens",
|
|
39272
41627
|
stopSequence: "stop_sequence",
|
|
39273
41628
|
toolUse: "tool_use",
|
|
39274
|
-
contentFilter: "refusal"
|
|
41629
|
+
contentFilter: "refusal",
|
|
41630
|
+
pauseTurn: "pause_turn"
|
|
39275
41631
|
};
|
|
39276
41632
|
var ERROR_TYPE2 = {
|
|
39277
41633
|
AUTH: "authentication_error",
|
|
@@ -39327,7 +41683,7 @@ async function* anthropicStream(events, requestId) {
|
|
|
39327
41683
|
suppressed.add(event.index);
|
|
39328
41684
|
break;
|
|
39329
41685
|
}
|
|
39330
|
-
const content_block = b.type === "text" ? { type: "text", text: "" } : b.type === "thinking" ? { type: "thinking", thinking: "" } : { type: "tool_use", id: b.id, name: b.name, input: {} };
|
|
41686
|
+
const content_block = b.type === "text" ? { type: "text", text: "" } : b.type === "thinking" ? { type: "thinking", thinking: "" } : b.type === "anthropicNative" ? { ...b.data, type: b.blockType } : { type: "tool_use", id: b.id, name: b.name, input: {} };
|
|
39331
41687
|
const index = nextOutIndex++;
|
|
39332
41688
|
outIndex.set(event.index, index);
|
|
39333
41689
|
yield frame("content_block_start", {
|
|
@@ -39341,7 +41697,7 @@ async function* anthropicStream(events, requestId) {
|
|
|
39341
41697
|
if (suppressed.has(event.index))
|
|
39342
41698
|
break;
|
|
39343
41699
|
const d = event.delta;
|
|
39344
|
-
const delta2 = d.type === "text" ? { type: "text_delta", text: d.text } : d.type === "thinking" ? { type: "thinking_delta", thinking: d.text } : d.type === "thinkingSignature" ? { type: "signature_delta", signature: d.signature } : { type: "input_json_delta", partial_json: d.partial };
|
|
41700
|
+
const delta2 = d.type === "text" ? { type: "text_delta", text: d.text } : d.type === "thinking" ? { type: "thinking_delta", thinking: d.text } : d.type === "thinkingSignature" ? { type: "signature_delta", signature: d.signature } : d.type === "anthropicNative" ? { type: d.deltaType, ...d.data } : { type: "input_json_delta", partial_json: d.partial };
|
|
39345
41701
|
yield frame("content_block_delta", {
|
|
39346
41702
|
type: "content_block_delta",
|
|
39347
41703
|
index: outIndex.get(event.index) ?? event.index,
|
|
@@ -39388,11 +41744,17 @@ function anthropicResponse(collected, requestId) {
|
|
|
39388
41744
|
content: collected.content.filter((b) => b.type !== "thinking" || b.signature !== undefined && b.signature !== "").map((b) => {
|
|
39389
41745
|
switch (b.type) {
|
|
39390
41746
|
case "text":
|
|
39391
|
-
return {
|
|
41747
|
+
return {
|
|
41748
|
+
type: "text",
|
|
41749
|
+
text: b.text,
|
|
41750
|
+
...b.citations === undefined ? {} : { citations: b.citations }
|
|
41751
|
+
};
|
|
39392
41752
|
case "thinking":
|
|
39393
41753
|
return { type: "thinking", thinking: b.text, signature: b.signature };
|
|
39394
41754
|
case "toolUse":
|
|
39395
41755
|
return { type: "tool_use", id: b.id, name: b.name, input: b.input };
|
|
41756
|
+
case "anthropicNative":
|
|
41757
|
+
return { ...b.data, type: b.blockType };
|
|
39396
41758
|
default:
|
|
39397
41759
|
return { type: "text", text: "" };
|
|
39398
41760
|
}
|
|
@@ -39426,7 +41788,8 @@ var FINISH2 = {
|
|
|
39426
41788
|
maxTokens: "length",
|
|
39427
41789
|
stopSequence: "stop",
|
|
39428
41790
|
toolUse: "tool_calls",
|
|
39429
|
-
contentFilter: "content_filter"
|
|
41791
|
+
contentFilter: "content_filter",
|
|
41792
|
+
pauseTurn: "stop"
|
|
39430
41793
|
};
|
|
39431
41794
|
var ERROR_TYPE3 = {
|
|
39432
41795
|
AUTH: { type: "invalid_request_error", code: "invalid_api_key" },
|
|
@@ -39563,6 +41926,165 @@ function openaiErrorBody(code, message) {
|
|
|
39563
41926
|
return { error: { message, type: e.type, code: e.code } };
|
|
39564
41927
|
}
|
|
39565
41928
|
|
|
41929
|
+
// apps/gateway/src/ingress/anthropicTools.ts
|
|
41930
|
+
var TOOL_FIELDS = {
|
|
41931
|
+
cache_control: cacheControlSchema.nullable(),
|
|
41932
|
+
strict: exports_external.boolean().nullable(),
|
|
41933
|
+
defer_loading: exports_external.boolean().nullable(),
|
|
41934
|
+
allowed_callers: exports_external.array(exports_external.enum(ANTHROPIC_TOOL_CALLERS)).nullable(),
|
|
41935
|
+
input_examples: exports_external.array(exports_external.record(exports_external.string(), exports_external.unknown())).nullable(),
|
|
41936
|
+
eager_input_streaming: exports_external.boolean().nullable(),
|
|
41937
|
+
max_uses: exports_external.number().int().positive().nullable(),
|
|
41938
|
+
allowed_domains: exports_external.array(exports_external.string()).nullable(),
|
|
41939
|
+
blocked_domains: exports_external.array(exports_external.string()).nullable(),
|
|
41940
|
+
user_location: exports_external.object({
|
|
41941
|
+
type: exports_external.literal("approximate"),
|
|
41942
|
+
city: exports_external.string().optional(),
|
|
41943
|
+
region: exports_external.string().optional(),
|
|
41944
|
+
country: exports_external.string().optional(),
|
|
41945
|
+
timezone: exports_external.string().optional()
|
|
41946
|
+
}).nullable(),
|
|
41947
|
+
citations: exports_external.object({ enabled: exports_external.boolean() }).nullable(),
|
|
41948
|
+
max_content_tokens: exports_external.number().int().positive().nullable(),
|
|
41949
|
+
use_cache: exports_external.boolean().nullable(),
|
|
41950
|
+
response_inclusion: exports_external.enum(["full", "excluded"]).nullable(),
|
|
41951
|
+
display_width_px: exports_external.number().int().positive(),
|
|
41952
|
+
display_height_px: exports_external.number().int().positive(),
|
|
41953
|
+
display_number: exports_external.number().int().nullable(),
|
|
41954
|
+
enable_zoom: exports_external.boolean().nullable(),
|
|
41955
|
+
max_characters: exports_external.number().int().positive().nullable(),
|
|
41956
|
+
model: exports_external.string().min(1),
|
|
41957
|
+
caching: cacheControlSchema.nullable(),
|
|
41958
|
+
max_tokens: exports_external.number().int().positive().nullable(),
|
|
41959
|
+
mcp_server_name: exports_external.string().min(1),
|
|
41960
|
+
configs: exports_external.record(exports_external.string(), exports_external.unknown()).nullable(),
|
|
41961
|
+
default_config: exports_external.record(exports_external.string(), exports_external.unknown()).nullable()
|
|
41962
|
+
};
|
|
41963
|
+
var customToolSchema = exports_external.object({
|
|
41964
|
+
type: exports_external.literal("custom").nullish(),
|
|
41965
|
+
name: exports_external.string().min(1),
|
|
41966
|
+
description: exports_external.string().optional(),
|
|
41967
|
+
input_schema: exports_external.record(exports_external.string(), exports_external.unknown()),
|
|
41968
|
+
cache_control: cacheControlSchema.nullish()
|
|
41969
|
+
});
|
|
41970
|
+
function fail(path, message) {
|
|
41971
|
+
throw new GatewayError("BAD_REQUEST", `${path}: ${message}`);
|
|
41972
|
+
}
|
|
41973
|
+
function field(path, name, value) {
|
|
41974
|
+
const schema = TOOL_FIELDS[name];
|
|
41975
|
+
if (schema === undefined)
|
|
41976
|
+
fail(`${path}.${name}`, `unsupported field "${name}"`);
|
|
41977
|
+
const parsed = schema.safeParse(value);
|
|
41978
|
+
if (!parsed.success) {
|
|
41979
|
+
fail(`${path}.${name}`, parsed.error.issues[0]?.message ?? "invalid value");
|
|
41980
|
+
}
|
|
41981
|
+
return parsed.data;
|
|
41982
|
+
}
|
|
41983
|
+
function parseAnthropicTool(raw, type, path, mcpServerNames) {
|
|
41984
|
+
const spec = anthropicToolSpec(type);
|
|
41985
|
+
if (spec === undefined)
|
|
41986
|
+
fail(`${path}.type`, `unrecognized tool type "${type}"`);
|
|
41987
|
+
if (spec.name !== undefined && raw.name !== spec.name) {
|
|
41988
|
+
fail(`${path}.name`, `${type} must be declared with name "${spec.name}"`);
|
|
41989
|
+
}
|
|
41990
|
+
if (spec.name === undefined && raw.name !== undefined) {
|
|
41991
|
+
fail(`${path}.name`, `${type} does not take a name`);
|
|
41992
|
+
}
|
|
41993
|
+
for (const required2 of spec.required) {
|
|
41994
|
+
if (raw[required2] === undefined)
|
|
41995
|
+
fail(`${path}.${required2}`, `${type} requires ${required2}`);
|
|
41996
|
+
}
|
|
41997
|
+
const allowed = new Set([...spec.required, ...spec.optional]);
|
|
41998
|
+
const wire = {};
|
|
41999
|
+
let cacheControl;
|
|
42000
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
42001
|
+
if (key === "type" || key === "name")
|
|
42002
|
+
continue;
|
|
42003
|
+
if (!allowed.has(key))
|
|
42004
|
+
fail(`${path}.${key}`, `${type} does not accept "${key}"`);
|
|
42005
|
+
const parsed = field(path, key, value);
|
|
42006
|
+
if (key === "cache_control") {
|
|
42007
|
+
cacheControl = irCacheControl(parsed === null ? undefined : parsed).cacheControl;
|
|
42008
|
+
continue;
|
|
42009
|
+
}
|
|
42010
|
+
if (parsed !== null)
|
|
42011
|
+
wire[key] = parsed;
|
|
42012
|
+
}
|
|
42013
|
+
if (wire.allowed_domains !== undefined && wire.blocked_domains !== undefined) {
|
|
42014
|
+
fail(`${path}.blocked_domains`, "allowed_domains and blocked_domains are mutually exclusive");
|
|
42015
|
+
}
|
|
42016
|
+
if (spec.family === "mcpToolset") {
|
|
42017
|
+
const server = wire.mcp_server_name;
|
|
42018
|
+
if (typeof server === "string" && !mcpServerNames.has(server)) {
|
|
42019
|
+
fail(`${path}.mcp_server_name`, `no mcp_servers entry named "${server}"`);
|
|
42020
|
+
}
|
|
42021
|
+
}
|
|
42022
|
+
return {
|
|
42023
|
+
provider: "anthropic",
|
|
42024
|
+
family: spec.family,
|
|
42025
|
+
type,
|
|
42026
|
+
name: spec.name ?? "",
|
|
42027
|
+
wire,
|
|
42028
|
+
...cacheControl === undefined ? {} : { cacheControl }
|
|
42029
|
+
};
|
|
42030
|
+
}
|
|
42031
|
+
function parseCustomTool(raw, path) {
|
|
42032
|
+
const parsed = customToolSchema.safeParse(raw);
|
|
42033
|
+
if (!parsed.success) {
|
|
42034
|
+
const issue2 = parsed.error.issues[0];
|
|
42035
|
+
fail(`${path}${issue2?.path.length ? `.${issue2.path.join(".")}` : ""}`, issue2?.message ?? "invalid tool");
|
|
42036
|
+
}
|
|
42037
|
+
const options = {};
|
|
42038
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
42039
|
+
if (["type", "name", "description", "input_schema", "cache_control"].includes(key))
|
|
42040
|
+
continue;
|
|
42041
|
+
if (!ANTHROPIC_CUSTOM_TOOL_OPTIONS.includes(key)) {
|
|
42042
|
+
fail(`${path}.${key}`, `unsupported field "${key}"`);
|
|
42043
|
+
}
|
|
42044
|
+
const value_ = field(path, key, value);
|
|
42045
|
+
if (value_ !== null)
|
|
42046
|
+
options[key] = value_;
|
|
42047
|
+
}
|
|
42048
|
+
return {
|
|
42049
|
+
provider: "custom",
|
|
42050
|
+
name: parsed.data.name,
|
|
42051
|
+
...parsed.data.description === undefined ? {} : { description: parsed.data.description },
|
|
42052
|
+
inputSchema: parsed.data.input_schema,
|
|
42053
|
+
...irCacheControl(parsed.data.cache_control ?? undefined),
|
|
42054
|
+
...Object.keys(options).length === 0 ? {} : { options }
|
|
42055
|
+
};
|
|
42056
|
+
}
|
|
42057
|
+
function parseTools(raw, mcpServerNames) {
|
|
42058
|
+
return raw.map((entry, index) => {
|
|
42059
|
+
const path = `tools.${index}`;
|
|
42060
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
42061
|
+
fail(path, "expected a tool definition object");
|
|
42062
|
+
}
|
|
42063
|
+
const tool = entry;
|
|
42064
|
+
const type = tool.type;
|
|
42065
|
+
if (type === undefined || type === null || type === "custom") {
|
|
42066
|
+
return parseCustomTool(tool, path);
|
|
42067
|
+
}
|
|
42068
|
+
if (typeof type !== "string")
|
|
42069
|
+
fail(`${path}.type`, "expected a string");
|
|
42070
|
+
return parseAnthropicTool(tool, type, path, mcpServerNames);
|
|
42071
|
+
});
|
|
42072
|
+
}
|
|
42073
|
+
function mcpServerNames(body2) {
|
|
42074
|
+
const servers = body2.mcp_servers;
|
|
42075
|
+
if (!Array.isArray(servers))
|
|
42076
|
+
return new Set;
|
|
42077
|
+
const names = new Set;
|
|
42078
|
+
for (const server of servers) {
|
|
42079
|
+
if (typeof server === "object" && server !== null) {
|
|
42080
|
+
const name = server.name;
|
|
42081
|
+
if (typeof name === "string")
|
|
42082
|
+
names.add(name);
|
|
42083
|
+
}
|
|
42084
|
+
}
|
|
42085
|
+
return names;
|
|
42086
|
+
}
|
|
42087
|
+
|
|
39566
42088
|
// apps/gateway/src/ingress/model.ts
|
|
39567
42089
|
var DISCOVERY_PREFIX = "claude/";
|
|
39568
42090
|
var ONE_M_SUFFIX = "[1m]";
|
|
@@ -39591,7 +42113,12 @@ function normalizeClientModel(raw, betas2 = []) {
|
|
|
39591
42113
|
var textBlock = exports_external.object({
|
|
39592
42114
|
type: exports_external.literal("text"),
|
|
39593
42115
|
text: exports_external.string(),
|
|
39594
|
-
cache_control: cacheControlSchema.optional()
|
|
42116
|
+
cache_control: cacheControlSchema.optional(),
|
|
42117
|
+
citations: exports_external.array(exports_external.unknown()).optional()
|
|
42118
|
+
});
|
|
42119
|
+
var midConversationTextBlock = textBlock.extend({
|
|
42120
|
+
cache_control: cacheControlSchema.nullable().optional(),
|
|
42121
|
+
citations: exports_external.array(exports_external.unknown()).nullable().optional()
|
|
39595
42122
|
});
|
|
39596
42123
|
var imageBlock = exports_external.object({
|
|
39597
42124
|
type: exports_external.literal("image"),
|
|
@@ -39628,9 +42155,137 @@ var block = exports_external.discriminatedUnion("type", [
|
|
|
39628
42155
|
toolUseBlock,
|
|
39629
42156
|
toolResultBlock
|
|
39630
42157
|
]);
|
|
42158
|
+
var nativeBase = {
|
|
42159
|
+
cache_control: cacheControlSchema.nullable().optional()
|
|
42160
|
+
};
|
|
42161
|
+
var nativeResultContent = exports_external.unknown().refine((value) => value !== null, {
|
|
42162
|
+
message: "expected native result content"
|
|
42163
|
+
});
|
|
42164
|
+
var caller = exports_external.discriminatedUnion("type", [
|
|
42165
|
+
exports_external.object({ type: exports_external.literal("direct") }).strict(),
|
|
42166
|
+
exports_external.object({
|
|
42167
|
+
type: exports_external.enum([
|
|
42168
|
+
"code_execution_20250825",
|
|
42169
|
+
"code_execution_20260120",
|
|
42170
|
+
"code_execution_20260521"
|
|
42171
|
+
]),
|
|
42172
|
+
tool_id: exports_external.string()
|
|
42173
|
+
}).strict()
|
|
42174
|
+
]).optional();
|
|
42175
|
+
var documentSource = exports_external.discriminatedUnion("type", [
|
|
42176
|
+
exports_external.object({
|
|
42177
|
+
type: exports_external.literal("base64"),
|
|
42178
|
+
media_type: exports_external.literal("application/pdf"),
|
|
42179
|
+
data: exports_external.string()
|
|
42180
|
+
}).strict(),
|
|
42181
|
+
exports_external.object({ type: exports_external.literal("text"), media_type: exports_external.literal("text/plain"), data: exports_external.string() }).strict(),
|
|
42182
|
+
exports_external.object({ type: exports_external.literal("content"), content: exports_external.array(exports_external.unknown()) }).strict(),
|
|
42183
|
+
exports_external.object({ type: exports_external.literal("url"), url: exports_external.string() }).strict(),
|
|
42184
|
+
exports_external.object({ type: exports_external.literal("file"), file_id: exports_external.string() }).strict()
|
|
42185
|
+
]);
|
|
42186
|
+
var citationsConfig = exports_external.object({ enabled: exports_external.boolean().optional() }).strict();
|
|
42187
|
+
var fallbackModel = exports_external.object({ model: exports_external.string() }).strict();
|
|
42188
|
+
var toolChangeReference = exports_external.discriminatedUnion("type", [
|
|
42189
|
+
exports_external.object({ type: exports_external.literal("tool_reference"), name: exports_external.string() }).strict(),
|
|
42190
|
+
exports_external.object({ type: exports_external.literal("mcp_tool_reference"), server_name: exports_external.string(), name: exports_external.string() }).strict(),
|
|
42191
|
+
exports_external.object({ type: exports_external.literal("mcp_toolset_reference"), server_name: exports_external.string() }).strict()
|
|
42192
|
+
]);
|
|
42193
|
+
function nativeToolChange(type) {
|
|
42194
|
+
return exports_external.object({ type: exports_external.literal(type), tool: toolChangeReference, ...nativeBase }).strict();
|
|
42195
|
+
}
|
|
42196
|
+
var toolAddition = nativeToolChange("tool_addition");
|
|
42197
|
+
var toolRemoval = nativeToolChange("tool_removal");
|
|
42198
|
+
var midConversationSystem = exports_external.object({
|
|
42199
|
+
type: exports_external.literal("mid_conv_system"),
|
|
42200
|
+
content: exports_external.array(exports_external.discriminatedUnion("type", [midConversationTextBlock.strict(), toolAddition, toolRemoval])),
|
|
42201
|
+
...nativeBase
|
|
42202
|
+
}).strict();
|
|
42203
|
+
var nativeSchemas = {
|
|
42204
|
+
server_tool_use: exports_external.object({
|
|
42205
|
+
type: exports_external.literal("server_tool_use"),
|
|
42206
|
+
id: exports_external.string(),
|
|
42207
|
+
name: exports_external.enum([
|
|
42208
|
+
"advisor",
|
|
42209
|
+
"web_search",
|
|
42210
|
+
"web_fetch",
|
|
42211
|
+
"code_execution",
|
|
42212
|
+
"bash_code_execution",
|
|
42213
|
+
"text_editor_code_execution",
|
|
42214
|
+
"tool_search_tool_regex",
|
|
42215
|
+
"tool_search_tool_bm25"
|
|
42216
|
+
]),
|
|
42217
|
+
input: exports_external.unknown(),
|
|
42218
|
+
caller,
|
|
42219
|
+
...nativeBase
|
|
42220
|
+
}).strict(),
|
|
42221
|
+
web_search_tool_result: nativeResult("web_search_tool_result", true),
|
|
42222
|
+
web_fetch_tool_result: nativeResult("web_fetch_tool_result", true),
|
|
42223
|
+
code_execution_tool_result: nativeResult("code_execution_tool_result"),
|
|
42224
|
+
bash_code_execution_tool_result: nativeResult("bash_code_execution_tool_result"),
|
|
42225
|
+
text_editor_code_execution_tool_result: nativeResult("text_editor_code_execution_tool_result"),
|
|
42226
|
+
tool_search_tool_result: nativeResult("tool_search_tool_result"),
|
|
42227
|
+
advisor_tool_result: nativeResult("advisor_tool_result"),
|
|
42228
|
+
mcp_tool_use: exports_external.object({
|
|
42229
|
+
type: exports_external.literal("mcp_tool_use"),
|
|
42230
|
+
id: exports_external.string(),
|
|
42231
|
+
name: exports_external.string(),
|
|
42232
|
+
server_name: exports_external.string(),
|
|
42233
|
+
input: exports_external.unknown(),
|
|
42234
|
+
...nativeBase
|
|
42235
|
+
}).strict(),
|
|
42236
|
+
mcp_tool_result: exports_external.object({
|
|
42237
|
+
type: exports_external.literal("mcp_tool_result"),
|
|
42238
|
+
tool_use_id: exports_external.string(),
|
|
42239
|
+
content: exports_external.union([exports_external.string(), exports_external.array(exports_external.unknown())]).optional(),
|
|
42240
|
+
is_error: exports_external.boolean().optional(),
|
|
42241
|
+
...nativeBase
|
|
42242
|
+
}).strict(),
|
|
42243
|
+
container_upload: exports_external.object({ type: exports_external.literal("container_upload"), file_id: exports_external.string(), ...nativeBase }).strict(),
|
|
42244
|
+
compaction: exports_external.object({
|
|
42245
|
+
type: exports_external.literal("compaction"),
|
|
42246
|
+
content: exports_external.string().nullable(),
|
|
42247
|
+
encrypted_content: exports_external.string().nullable().optional(),
|
|
42248
|
+
...nativeBase
|
|
42249
|
+
}).strict(),
|
|
42250
|
+
search_result: exports_external.object({
|
|
42251
|
+
type: exports_external.literal("search_result"),
|
|
42252
|
+
source: exports_external.string(),
|
|
42253
|
+
title: exports_external.string(),
|
|
42254
|
+
content: exports_external.array(exports_external.unknown()),
|
|
42255
|
+
citations: citationsConfig.optional(),
|
|
42256
|
+
...nativeBase
|
|
42257
|
+
}).strict(),
|
|
42258
|
+
redacted_thinking: exports_external.object({ type: exports_external.literal("redacted_thinking"), data: exports_external.string() }).strict(),
|
|
42259
|
+
document: exports_external.object({
|
|
42260
|
+
type: exports_external.literal("document"),
|
|
42261
|
+
source: documentSource,
|
|
42262
|
+
citations: citationsConfig.nullable().optional(),
|
|
42263
|
+
context: exports_external.string().nullable().optional(),
|
|
42264
|
+
title: exports_external.string().nullable().optional(),
|
|
42265
|
+
...nativeBase
|
|
42266
|
+
}).strict(),
|
|
42267
|
+
mid_conv_system: midConversationSystem,
|
|
42268
|
+
tool_addition: toolAddition,
|
|
42269
|
+
tool_removal: toolRemoval,
|
|
42270
|
+
fallback: exports_external.object({
|
|
42271
|
+
type: exports_external.literal("fallback"),
|
|
42272
|
+
from: fallbackModel,
|
|
42273
|
+
to: fallbackModel,
|
|
42274
|
+
trigger: exports_external.unknown().optional()
|
|
42275
|
+
}).strict()
|
|
42276
|
+
};
|
|
42277
|
+
function nativeResult(type, hasCaller = false) {
|
|
42278
|
+
return exports_external.object({
|
|
42279
|
+
type: exports_external.literal(type),
|
|
42280
|
+
tool_use_id: exports_external.string(),
|
|
42281
|
+
content: nativeResultContent,
|
|
42282
|
+
...hasCaller ? { caller } : {},
|
|
42283
|
+
...nativeBase
|
|
42284
|
+
}).strict();
|
|
42285
|
+
}
|
|
39631
42286
|
var message = exports_external.object({
|
|
39632
42287
|
role: exports_external.enum(["user", "assistant", "system"]),
|
|
39633
|
-
content: exports_external.union([exports_external.string(), exports_external.array(
|
|
42288
|
+
content: exports_external.union([exports_external.string(), exports_external.array(exports_external.unknown())])
|
|
39634
42289
|
});
|
|
39635
42290
|
var schema = exports_external.object({
|
|
39636
42291
|
model: exports_external.string().min(1),
|
|
@@ -39640,12 +42295,7 @@ var schema = exports_external.object({
|
|
|
39640
42295
|
temperature: exports_external.number().optional(),
|
|
39641
42296
|
stop_sequences: exports_external.array(exports_external.string()).optional(),
|
|
39642
42297
|
stream: exports_external.boolean().optional(),
|
|
39643
|
-
tools: exports_external.array(exports_external.
|
|
39644
|
-
name: exports_external.string(),
|
|
39645
|
-
description: exports_external.string().optional(),
|
|
39646
|
-
input_schema: exports_external.record(exports_external.string(), exports_external.unknown()),
|
|
39647
|
-
cache_control: cacheControlSchema.optional()
|
|
39648
|
-
})).optional(),
|
|
42298
|
+
tools: exports_external.array(exports_external.unknown()).optional(),
|
|
39649
42299
|
tool_choice: exports_external.union([
|
|
39650
42300
|
exports_external.object({ type: exports_external.enum(["auto", "any", "none"]) }),
|
|
39651
42301
|
exports_external.object({ type: exports_external.literal("tool"), name: exports_external.string() })
|
|
@@ -39688,7 +42338,12 @@ function flattenToolResult(content) {
|
|
|
39688
42338
|
function toIrBlock(b) {
|
|
39689
42339
|
switch (b.type) {
|
|
39690
42340
|
case "text":
|
|
39691
|
-
return {
|
|
42341
|
+
return {
|
|
42342
|
+
type: "text",
|
|
42343
|
+
text: b.text,
|
|
42344
|
+
...b.citations === undefined ? {} : { citations: b.citations },
|
|
42345
|
+
...irCacheControl(b.cache_control)
|
|
42346
|
+
};
|
|
39692
42347
|
case "image":
|
|
39693
42348
|
return {
|
|
39694
42349
|
type: "image",
|
|
@@ -39720,6 +42375,69 @@ function toIrBlock(b) {
|
|
|
39720
42375
|
};
|
|
39721
42376
|
}
|
|
39722
42377
|
}
|
|
42378
|
+
var nativeRoles = {
|
|
42379
|
+
server_tool_use: "assistant",
|
|
42380
|
+
web_search_tool_result: "assistant",
|
|
42381
|
+
web_fetch_tool_result: "assistant",
|
|
42382
|
+
code_execution_tool_result: "assistant",
|
|
42383
|
+
bash_code_execution_tool_result: "assistant",
|
|
42384
|
+
text_editor_code_execution_tool_result: "assistant",
|
|
42385
|
+
tool_search_tool_result: "assistant",
|
|
42386
|
+
advisor_tool_result: "assistant",
|
|
42387
|
+
mcp_tool_use: "assistant",
|
|
42388
|
+
mcp_tool_result: "user",
|
|
42389
|
+
container_upload: "user",
|
|
42390
|
+
compaction: "assistant",
|
|
42391
|
+
search_result: "user",
|
|
42392
|
+
redacted_thinking: "assistant",
|
|
42393
|
+
document: "user",
|
|
42394
|
+
mid_conv_system: "system",
|
|
42395
|
+
tool_addition: "system",
|
|
42396
|
+
tool_removal: "system",
|
|
42397
|
+
fallback: "assistant"
|
|
42398
|
+
};
|
|
42399
|
+
function readBlock(raw, role, path) {
|
|
42400
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
42401
|
+
const type = raw.type;
|
|
42402
|
+
if (typeof type === "string" && ANTHROPIC_NATIVE_BLOCK_TYPES.has(type)) {
|
|
42403
|
+
const nativeSchema = nativeSchemas[type];
|
|
42404
|
+
const nativeRole = nativeRoles[type];
|
|
42405
|
+
if (nativeSchema === undefined || nativeRole === undefined) {
|
|
42406
|
+
throw new GatewayError("BAD_REQUEST", `${path}.type: block type "${type}" is not legal in request history`);
|
|
42407
|
+
}
|
|
42408
|
+
if (role !== nativeRole) {
|
|
42409
|
+
throw new GatewayError("BAD_REQUEST", `${path}: block type "${type}" is not legal in ${role} messages`);
|
|
42410
|
+
}
|
|
42411
|
+
const parsed2 = nativeSchema.safeParse(raw);
|
|
42412
|
+
if (!parsed2.success) {
|
|
42413
|
+
const issue2 = parsed2.error.issues[0];
|
|
42414
|
+
const issuePath = issue2?.code === "unrecognized_keys" ? [...issue2.path, issue2.keys[0]] : issue2?.path;
|
|
42415
|
+
const suffix = issuePath?.length ? `.${issuePath.join(".")}` : "";
|
|
42416
|
+
throw new GatewayError("BAD_REQUEST", `${path}${suffix}: ${issue2?.message ?? "invalid native content block"}`);
|
|
42417
|
+
}
|
|
42418
|
+
const { type: _type, cache_control, ...data } = parsed2.data;
|
|
42419
|
+
return {
|
|
42420
|
+
type: "anthropicNative",
|
|
42421
|
+
blockType: type,
|
|
42422
|
+
data,
|
|
42423
|
+
...cache_control === undefined || cache_control === null ? {} : irCacheControl(cache_control)
|
|
42424
|
+
};
|
|
42425
|
+
}
|
|
42426
|
+
}
|
|
42427
|
+
const parsed = block.safeParse(raw);
|
|
42428
|
+
if (!parsed.success) {
|
|
42429
|
+
const issue2 = parsed.error.issues[0];
|
|
42430
|
+
if (issue2?.code === "invalid_union" || issue2?.path.at(-1) === "type") {
|
|
42431
|
+
const type = raw?.type;
|
|
42432
|
+
if (typeof type === "string") {
|
|
42433
|
+
throw new GatewayError("BAD_REQUEST", `${path}.type: unrecognized block type "${type}"`);
|
|
42434
|
+
}
|
|
42435
|
+
}
|
|
42436
|
+
const suffix = issue2?.path.length ? `.${issue2.path.join(".")}` : "";
|
|
42437
|
+
throw new GatewayError("BAD_REQUEST", `${path}${suffix}: ${issue2?.message ?? "invalid content block"}`);
|
|
42438
|
+
}
|
|
42439
|
+
return toIrBlock(parsed.data);
|
|
42440
|
+
}
|
|
39723
42441
|
function toIrToolChoice(c) {
|
|
39724
42442
|
return c.type === "tool" ? { type: "tool", name: c.name } : { type: c.type };
|
|
39725
42443
|
}
|
|
@@ -39759,10 +42477,17 @@ function parseAnthropicRequest(body2, headers) {
|
|
|
39759
42477
|
throw new GatewayError("BAD_REQUEST", "request body must be a JSON object");
|
|
39760
42478
|
}
|
|
39761
42479
|
const parsed = parseOrThrow2(schema, body2);
|
|
39762
|
-
const messages = parsed.messages.map((m) =>
|
|
39763
|
-
|
|
39764
|
-
|
|
39765
|
-
|
|
42480
|
+
const messages = parsed.messages.map((m, i) => {
|
|
42481
|
+
const content = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content.map((b, j) => readBlock(b, m.role, `messages.${i}.content.${j}`));
|
|
42482
|
+
if (m.role === "system") {
|
|
42483
|
+
const previous = parsed.messages[i - 1];
|
|
42484
|
+
const next = parsed.messages[i + 1];
|
|
42485
|
+
if (previous === undefined || next !== undefined && next.role !== "assistant") {
|
|
42486
|
+
throw new GatewayError("BAD_REQUEST", `messages.${i}: system message must follow another message and be last or precede an assistant message`);
|
|
42487
|
+
}
|
|
42488
|
+
}
|
|
42489
|
+
return { role: m.role, content };
|
|
42490
|
+
});
|
|
39766
42491
|
const system = parsed.system === undefined ? undefined : typeof parsed.system === "string" ? [{ type: "text", text: parsed.system }] : parsed.system.map((b) => ({
|
|
39767
42492
|
type: "text",
|
|
39768
42493
|
text: b.text,
|
|
@@ -39783,12 +42508,7 @@ function parseAnthropicRequest(body2, headers) {
|
|
|
39783
42508
|
if (parsed.stop_sequences !== undefined)
|
|
39784
42509
|
request2.stopSequences = parsed.stop_sequences;
|
|
39785
42510
|
if (parsed.tools !== undefined) {
|
|
39786
|
-
request2.tools = parsed.tools
|
|
39787
|
-
name: t2.name,
|
|
39788
|
-
...t2.description !== undefined && { description: t2.description },
|
|
39789
|
-
inputSchema: t2.input_schema,
|
|
39790
|
-
...irCacheControl(t2.cache_control)
|
|
39791
|
-
}));
|
|
42511
|
+
request2.tools = parseTools(parsed.tools, mcpServerNames(body2));
|
|
39792
42512
|
}
|
|
39793
42513
|
if (parsed.tool_choice !== undefined)
|
|
39794
42514
|
request2.toolChoice = toIrToolChoice(parsed.tool_choice);
|
|
@@ -39911,9 +42631,9 @@ function parseOpenAIRequest(body2) {
|
|
|
39911
42631
|
const messages = [];
|
|
39912
42632
|
for (const m of parsed.messages) {
|
|
39913
42633
|
if (m.role === "system" || m.role === "developer") {
|
|
39914
|
-
const
|
|
39915
|
-
applyMessageCacheControl(
|
|
39916
|
-
system.push(...
|
|
42634
|
+
const blocks2 = contentBlocks(m.content);
|
|
42635
|
+
applyMessageCacheControl(blocks2, m.cache_control);
|
|
42636
|
+
system.push(...blocks2);
|
|
39917
42637
|
continue;
|
|
39918
42638
|
}
|
|
39919
42639
|
if (m.role === "tool") {
|
|
@@ -39967,6 +42687,7 @@ function parseOpenAIRequest(body2) {
|
|
|
39967
42687
|
}
|
|
39968
42688
|
if (parsed.tools !== undefined) {
|
|
39969
42689
|
request2.tools = parsed.tools.map((t2) => ({
|
|
42690
|
+
provider: "custom",
|
|
39970
42691
|
name: t2.function.name,
|
|
39971
42692
|
...t2.function.description !== undefined && { description: t2.function.description },
|
|
39972
42693
|
inputSchema: t2.function.parameters ?? { type: "object" },
|
|
@@ -40217,7 +42938,13 @@ function proxyRoutes(deps) {
|
|
|
40217
42938
|
snapshots: deps.snapshots ?? createRoutingSnapshotCache(deps.store, logger2),
|
|
40218
42939
|
keepaliveMs: deps.keepaliveMs ?? KEEPALIVE_MS
|
|
40219
42940
|
};
|
|
40220
|
-
return new Elysia().post("/v1/messages", ({ request: request2
|
|
42941
|
+
return new Elysia().post("/v1/messages", ({ request: request2, server }) => {
|
|
42942
|
+
server?.timeout(request2, 0);
|
|
42943
|
+
return handle(dispatchDeps, rateLimiter, "anthropic", request2);
|
|
42944
|
+
}).post("/v1/chat/completions", ({ request: request2, server }) => {
|
|
42945
|
+
server?.timeout(request2, 0);
|
|
42946
|
+
return handle(dispatchDeps, rateLimiter, "openai", request2);
|
|
42947
|
+
}).get("/v1/models", async ({ request: request2 }) => {
|
|
40221
42948
|
try {
|
|
40222
42949
|
const key = await authenticateApiKey(deps.store, apiKeyHeader(request2.headers));
|
|
40223
42950
|
const snapshot = await dispatchDeps.snapshots.get(deps.now());
|
|
@@ -40333,7 +43060,7 @@ function createApp(deps) {
|
|
|
40333
43060
|
} catch {
|
|
40334
43061
|
return error51();
|
|
40335
43062
|
}
|
|
40336
|
-
const protectedPrefix = ["/api", "/v1", "/oauth"].some((
|
|
43063
|
+
const protectedPrefix = ["/api", "/v1", "/oauth"].some((prefix2) => decodedPath === prefix2 || decodedPath.startsWith(`${prefix2}/`));
|
|
40337
43064
|
if (protectedPrefix)
|
|
40338
43065
|
return error51();
|
|
40339
43066
|
const requestedPath = decodedPath === "/" ? "/index.html" : decodedPath;
|