@codelia/runtime 0.1.65 → 0.1.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +762 -522
- package/dist/index.js +724 -481
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
import path20 from "path";
|
|
3
3
|
import { SessionStateStoreImpl as SessionStateStoreImpl2 } from "@codelia/storage";
|
|
4
4
|
|
|
5
|
+
// src/agent-factory.ts
|
|
6
|
+
import { promises as fs15 } from "fs";
|
|
7
|
+
import {
|
|
8
|
+
Agent,
|
|
9
|
+
ANTHROPIC_DEFAULT_MODEL,
|
|
10
|
+
ChatAnthropic,
|
|
11
|
+
ChatOpenAI,
|
|
12
|
+
ChatOpenRouter,
|
|
13
|
+
DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY3,
|
|
14
|
+
OPENAI_DEFAULT_MODEL,
|
|
15
|
+
resolveModel as resolveModel2,
|
|
16
|
+
resolveProviderModelId as resolveProviderModelId2
|
|
17
|
+
} from "@codelia/core";
|
|
18
|
+
import { ModelMetadataServiceImpl as ModelMetadataServiceImpl2 } from "@codelia/model-metadata";
|
|
19
|
+
import { parseApprovalMode as parseApprovalMode2 } from "@codelia/shared-types";
|
|
20
|
+
import {
|
|
21
|
+
StoragePathServiceImpl as StoragePathServiceImpl3,
|
|
22
|
+
ToolOutputCacheStoreImpl as ToolOutputCacheStoreImpl2
|
|
23
|
+
} from "@codelia/storage";
|
|
24
|
+
|
|
5
25
|
// src/agents/context.ts
|
|
6
26
|
var createAgentsResolverKey = (resolver) => ({
|
|
7
27
|
id: "agents-resolver",
|
|
@@ -363,25 +383,6 @@ var appendInitialAgentsContext = (systemPrompt, agentsContext) => {
|
|
|
363
383
|
${agentsContext}`;
|
|
364
384
|
};
|
|
365
385
|
|
|
366
|
-
// src/agent-factory.ts
|
|
367
|
-
import { promises as fs15 } from "fs";
|
|
368
|
-
import {
|
|
369
|
-
Agent,
|
|
370
|
-
ANTHROPIC_DEFAULT_MODEL,
|
|
371
|
-
ChatAnthropic,
|
|
372
|
-
ChatOpenAI,
|
|
373
|
-
ChatOpenRouter,
|
|
374
|
-
DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY2,
|
|
375
|
-
OPENAI_DEFAULT_MODEL,
|
|
376
|
-
resolveProviderModelId as resolveProviderModelId2
|
|
377
|
-
} from "@codelia/core";
|
|
378
|
-
import { ModelMetadataServiceImpl as ModelMetadataServiceImpl2 } from "@codelia/model-metadata";
|
|
379
|
-
import { parseApprovalMode as parseApprovalMode2 } from "@codelia/shared-types";
|
|
380
|
-
import {
|
|
381
|
-
StoragePathServiceImpl as StoragePathServiceImpl3,
|
|
382
|
-
ToolOutputCacheStoreImpl as ToolOutputCacheStoreImpl2
|
|
383
|
-
} from "@codelia/storage";
|
|
384
|
-
|
|
385
386
|
// src/auth/oauth-utils.ts
|
|
386
387
|
import { createServer } from "http";
|
|
387
388
|
import * as oauth from "oauth4webapi";
|
|
@@ -804,6 +805,7 @@ var resolveModelConfig = async (workingDir) => {
|
|
|
804
805
|
name: effective.model?.name,
|
|
805
806
|
reasoning: effective.model?.reasoning,
|
|
806
807
|
verbosity: effective.model?.verbosity,
|
|
808
|
+
fast: effective.model?.fast,
|
|
807
809
|
experimental: effective.experimental
|
|
808
810
|
};
|
|
809
811
|
};
|
|
@@ -2357,6 +2359,24 @@ var createMcpOAuthSession = async (params, options = {}) => {
|
|
|
2357
2359
|
};
|
|
2358
2360
|
};
|
|
2359
2361
|
|
|
2362
|
+
// src/model-fast.ts
|
|
2363
|
+
import { DEFAULT_MODEL_REGISTRY, supportsFastMode } from "@codelia/core";
|
|
2364
|
+
var resolveFastMode = (params) => {
|
|
2365
|
+
if (params.requested !== true) {
|
|
2366
|
+
return { enabled: false };
|
|
2367
|
+
}
|
|
2368
|
+
if (!supportsFastMode(DEFAULT_MODEL_REGISTRY, params.model, params.provider)) {
|
|
2369
|
+
return { enabled: false };
|
|
2370
|
+
}
|
|
2371
|
+
if (params.provider === "openai") {
|
|
2372
|
+
return { enabled: true, provider: "openai", serviceTier: "priority" };
|
|
2373
|
+
}
|
|
2374
|
+
if (params.provider === "anthropic") {
|
|
2375
|
+
return { enabled: true, provider: "anthropic", fastMode: true };
|
|
2376
|
+
}
|
|
2377
|
+
return { enabled: false };
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2360
2380
|
// src/model-reasoning.ts
|
|
2361
2381
|
var REASONING_LEVEL_ORDER = [
|
|
2362
2382
|
"low",
|
|
@@ -2388,6 +2408,15 @@ var ANTHROPIC_BUDGET_PRESET_TOKENS = {
|
|
|
2388
2408
|
};
|
|
2389
2409
|
var ANTHROPIC_MAX_TOKENS_FALLBACK_HEADROOM = 4096;
|
|
2390
2410
|
var ANTHROPIC_REASONING_MODEL_TABLE = {
|
|
2411
|
+
"claude-opus-4-7": {
|
|
2412
|
+
supportedLevels: ["low", "medium", "high", "xhigh"],
|
|
2413
|
+
budgetPresetByLevel: {
|
|
2414
|
+
low: "reasoning_low",
|
|
2415
|
+
medium: "reasoning_medium",
|
|
2416
|
+
high: "reasoning_high",
|
|
2417
|
+
xhigh: "reasoning_xhigh"
|
|
2418
|
+
}
|
|
2419
|
+
},
|
|
2391
2420
|
"claude-opus-4-6": {
|
|
2392
2421
|
supportedLevels: ["low", "medium", "high", "xhigh"],
|
|
2393
2422
|
budgetPresetByLevel: {
|
|
@@ -2459,6 +2488,8 @@ var ANTHROPIC_REASONING_MODEL_TABLE = {
|
|
|
2459
2488
|
}
|
|
2460
2489
|
}
|
|
2461
2490
|
};
|
|
2491
|
+
var ANTHROPIC_ADAPTIVE_THINKING_MODELS = /* @__PURE__ */ new Set(["claude-opus-4-7"]);
|
|
2492
|
+
var toAnthropicOutputEffort = (level) => level === "xhigh" ? "max" : level;
|
|
2462
2493
|
var normalizeRequestedReasoning = (value) => value ?? DEFAULT_REASONING_LEVEL;
|
|
2463
2494
|
var resolveNearestSupportedLevel = (requested, supportedLevels) => {
|
|
2464
2495
|
const supported = new Set(supportedLevels);
|
|
@@ -2539,9 +2570,16 @@ var resolveAnthropicReasoning = ({
|
|
|
2539
2570
|
const budgetTokens = ANTHROPIC_BUDGET_PRESET_TOKENS[preset];
|
|
2540
2571
|
return {
|
|
2541
2572
|
...resolution,
|
|
2542
|
-
|
|
2543
|
-
type: "
|
|
2544
|
-
|
|
2573
|
+
...ANTHROPIC_ADAPTIVE_THINKING_MODELS.has(model) ? {
|
|
2574
|
+
thinking: { type: "adaptive" },
|
|
2575
|
+
outputConfig: {
|
|
2576
|
+
effort: toAnthropicOutputEffort(resolution.applied)
|
|
2577
|
+
}
|
|
2578
|
+
} : {
|
|
2579
|
+
thinking: {
|
|
2580
|
+
type: "enabled",
|
|
2581
|
+
budget_tokens: budgetTokens
|
|
2582
|
+
}
|
|
2545
2583
|
},
|
|
2546
2584
|
budgetPreset: preset,
|
|
2547
2585
|
usedFallbackModelProfile
|
|
@@ -2562,7 +2600,8 @@ var resolveAnthropicMaxTokens = ({
|
|
|
2562
2600
|
// src/model-registry.ts
|
|
2563
2601
|
import {
|
|
2564
2602
|
applyModelMetadata,
|
|
2565
|
-
DEFAULT_MODEL_REGISTRY,
|
|
2603
|
+
DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY2,
|
|
2604
|
+
isUsableModelSpec,
|
|
2566
2605
|
registerModels,
|
|
2567
2606
|
resolveModel,
|
|
2568
2607
|
resolveProviderModelId
|
|
@@ -2578,7 +2617,7 @@ var resolveProviderModelEntry = (providerEntries, provider, model) => {
|
|
|
2578
2617
|
return null;
|
|
2579
2618
|
}
|
|
2580
2619
|
const normalized = stripProviderPrefix(provider, model);
|
|
2581
|
-
const providerModelId = resolveProviderModelId(
|
|
2620
|
+
const providerModelId = resolveProviderModelId(DEFAULT_MODEL_REGISTRY2, model, provider) ?? normalized;
|
|
2582
2621
|
const providerModelNormalized = stripProviderPrefix(
|
|
2583
2622
|
provider,
|
|
2584
2623
|
providerModelId
|
|
@@ -2617,13 +2656,13 @@ var resolveDefaultRegistrySpec = (provider, model) => {
|
|
|
2617
2656
|
(value, index, array) => array.indexOf(value) === index
|
|
2618
2657
|
);
|
|
2619
2658
|
for (const candidate of candidates) {
|
|
2620
|
-
const spec = resolveModel(
|
|
2659
|
+
const spec = resolveModel(DEFAULT_MODEL_REGISTRY2, candidate, provider);
|
|
2621
2660
|
if (spec?.provider === provider) {
|
|
2622
2661
|
return spec;
|
|
2623
2662
|
}
|
|
2624
2663
|
}
|
|
2625
2664
|
const normalizedLower = normalized.toLowerCase();
|
|
2626
|
-
for (const spec of Object.values(
|
|
2665
|
+
for (const spec of Object.values(DEFAULT_MODEL_REGISTRY2.modelsById)) {
|
|
2627
2666
|
if (spec.provider !== provider) continue;
|
|
2628
2667
|
if (spec.id.toLowerCase() === normalizedLower) {
|
|
2629
2668
|
return spec;
|
|
@@ -2642,7 +2681,7 @@ var withOpenRouterDynamicModel = (registry, llm, entry) => {
|
|
|
2642
2681
|
const contextWindow = toPositiveInteger(entry.limits?.contextWindow) ?? toPositiveInteger(entry.limits?.inputTokens);
|
|
2643
2682
|
const maxInputTokens = toPositiveInteger(entry.limits?.inputTokens) ?? contextWindow;
|
|
2644
2683
|
const maxOutputTokens = toPositiveInteger(entry.limits?.outputTokens);
|
|
2645
|
-
if (!contextWindow && !maxInputTokens
|
|
2684
|
+
if (!contextWindow && !maxInputTokens) {
|
|
2646
2685
|
return registry;
|
|
2647
2686
|
}
|
|
2648
2687
|
const aliases = [llm.model, `${llm.provider}/${normalized}`].filter((value) => value !== normalized).filter((value, index, array) => array.indexOf(value) === index);
|
|
@@ -2690,13 +2729,13 @@ var buildModelRegistry = async (llm, options = {}) => {
|
|
|
2690
2729
|
}
|
|
2691
2730
|
if (!resolvedEntry) {
|
|
2692
2731
|
const fallbackSpec = resolveDefaultRegistrySpec(llm.provider, llm.model);
|
|
2693
|
-
if (strict && !fallbackSpec) {
|
|
2732
|
+
if (strict && !isUsableModelSpec(fallbackSpec)) {
|
|
2694
2733
|
throw new Error(
|
|
2695
|
-
`
|
|
2734
|
+
`Usable model metadata not found for ${llm.provider}/${llm.model} after refresh; add required limits to the static ModelSpec to use it without metadata`
|
|
2696
2735
|
);
|
|
2697
2736
|
}
|
|
2698
2737
|
}
|
|
2699
|
-
const baseRegistry = applyModelMetadata(
|
|
2738
|
+
const baseRegistry = applyModelMetadata(DEFAULT_MODEL_REGISTRY2, {
|
|
2700
2739
|
models: entries
|
|
2701
2740
|
});
|
|
2702
2741
|
return resolvedEntry ? withOpenRouterDynamicModel(baseRegistry, llm, resolvedEntry) : baseRegistry;
|
|
@@ -8800,13 +8839,28 @@ var resolveModelMaxTokensFromEntry = (entry) => {
|
|
|
8800
8839
|
}
|
|
8801
8840
|
return null;
|
|
8802
8841
|
};
|
|
8842
|
+
var resolveAnthropicStaticModelMaxTokens = (model) => {
|
|
8843
|
+
const spec = resolveModel2(DEFAULT_MODEL_REGISTRY3, model, "anthropic");
|
|
8844
|
+
const candidates = [
|
|
8845
|
+
spec?.maxOutputTokens,
|
|
8846
|
+
spec?.maxInputTokens,
|
|
8847
|
+
spec?.contextWindow
|
|
8848
|
+
];
|
|
8849
|
+
for (const value of candidates) {
|
|
8850
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
8851
|
+
continue;
|
|
8852
|
+
}
|
|
8853
|
+
return Math.trunc(value);
|
|
8854
|
+
}
|
|
8855
|
+
return null;
|
|
8856
|
+
};
|
|
8803
8857
|
var resolveAnthropicModelMaxTokens = async (model) => {
|
|
8804
8858
|
const metadataService = new ModelMetadataServiceImpl2({
|
|
8805
8859
|
storagePathService: new StoragePathServiceImpl3()
|
|
8806
8860
|
});
|
|
8807
8861
|
const direct = await metadataService.getModelEntry("anthropic", model);
|
|
8808
8862
|
const prefixed = model.startsWith("anthropic/") ? null : await metadataService.getModelEntry("anthropic", `anthropic/${model}`);
|
|
8809
|
-
return resolveModelMaxTokensFromEntry(direct) ?? resolveModelMaxTokensFromEntry(prefixed);
|
|
8863
|
+
return resolveModelMaxTokensFromEntry(direct) ?? resolveModelMaxTokensFromEntry(prefixed) ?? resolveAnthropicStaticModelMaxTokens(model);
|
|
8810
8864
|
};
|
|
8811
8865
|
var sleep2 = (ms) => new Promise((resolve) => {
|
|
8812
8866
|
setTimeout(resolve, ms);
|
|
@@ -9178,12 +9232,13 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9178
9232
|
let llm;
|
|
9179
9233
|
let resolvedModelName = null;
|
|
9180
9234
|
const requestedReasoning = resolveReasoningEffort(modelConfig.reasoning) ?? "medium";
|
|
9235
|
+
const isFastRequested = modelConfig.fast === true;
|
|
9181
9236
|
switch (provider) {
|
|
9182
9237
|
case "openai": {
|
|
9183
9238
|
const modelName = modelConfig.name ?? OPENAI_DEFAULT_MODEL;
|
|
9184
9239
|
resolvedModelName = modelName;
|
|
9185
9240
|
const providerModelName = resolveProviderModelId2(
|
|
9186
|
-
|
|
9241
|
+
DEFAULT_MODEL_REGISTRY3,
|
|
9187
9242
|
modelName,
|
|
9188
9243
|
"openai"
|
|
9189
9244
|
) ?? modelName;
|
|
@@ -9193,6 +9248,11 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9193
9248
|
});
|
|
9194
9249
|
const textVerbosity = resolveTextVerbosity(modelConfig.verbosity);
|
|
9195
9250
|
const websocketMode = modelConfig.experimental?.openai?.websocket_mode;
|
|
9251
|
+
const fastMode = resolveFastMode({
|
|
9252
|
+
provider: "openai",
|
|
9253
|
+
model: modelName,
|
|
9254
|
+
requested: isFastRequested
|
|
9255
|
+
});
|
|
9196
9256
|
llm = new ChatOpenAI({
|
|
9197
9257
|
clientOptions: buildOpenAiClientOptions(authResolver, providerAuth),
|
|
9198
9258
|
model: modelName,
|
|
@@ -9202,6 +9262,7 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9202
9262
|
reasoningLevelApplied: reasoning.applied,
|
|
9203
9263
|
reasoningFallbackApplied: reasoning.fallbackApplied,
|
|
9204
9264
|
...textVerbosity ? { textVerbosity } : {},
|
|
9265
|
+
...fastMode.enabled && fastMode.provider === "openai" ? { serviceTier: fastMode.serviceTier } : {},
|
|
9205
9266
|
...websocketMode ? { websocketMode } : {}
|
|
9206
9267
|
});
|
|
9207
9268
|
break;
|
|
@@ -9239,14 +9300,19 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9239
9300
|
});
|
|
9240
9301
|
const modelMaxTokens = await resolveAnthropicModelMaxTokens(modelName);
|
|
9241
9302
|
const maxTokens = resolveAnthropicMaxTokens({
|
|
9242
|
-
thinkingBudgetTokens: reasoning.thinking.budget_tokens,
|
|
9303
|
+
thinkingBudgetTokens: reasoning.thinking.type === "enabled" ? reasoning.thinking.budget_tokens : 0,
|
|
9243
9304
|
modelLimitMaxTokens: modelMaxTokens
|
|
9244
9305
|
});
|
|
9245
|
-
if (typeof modelMaxTokens === "number" && modelMaxTokens <= reasoning.thinking.budget_tokens) {
|
|
9306
|
+
if (reasoning.thinking.type === "enabled" && typeof modelMaxTokens === "number" && modelMaxTokens <= reasoning.thinking.budget_tokens) {
|
|
9246
9307
|
log(
|
|
9247
9308
|
`anthropic model '${modelName}' max token limit (${modelMaxTokens}) is not above thinking budget (${reasoning.thinking.budget_tokens}); using max_tokens=${maxTokens} to satisfy API constraint`
|
|
9248
9309
|
);
|
|
9249
9310
|
}
|
|
9311
|
+
const fastMode = resolveFastMode({
|
|
9312
|
+
provider: "anthropic",
|
|
9313
|
+
model: modelName,
|
|
9314
|
+
requested: isFastRequested
|
|
9315
|
+
});
|
|
9250
9316
|
llm = new ChatAnthropic({
|
|
9251
9317
|
clientOptions: {
|
|
9252
9318
|
apiKey: requireApiKeyAuth("Anthropic", providerAuth)
|
|
@@ -9254,12 +9320,14 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9254
9320
|
model: modelName,
|
|
9255
9321
|
maxTokens,
|
|
9256
9322
|
invokeOptions: {
|
|
9257
|
-
thinking: reasoning.thinking
|
|
9323
|
+
thinking: reasoning.thinking,
|
|
9324
|
+
...reasoning.outputConfig ? { output_config: reasoning.outputConfig } : {}
|
|
9258
9325
|
},
|
|
9259
9326
|
reasoningLevelRequested: reasoning.requested,
|
|
9260
9327
|
reasoningLevelApplied: reasoning.applied,
|
|
9261
9328
|
reasoningFallbackApplied: reasoning.fallbackApplied,
|
|
9262
|
-
reasoningBudgetPreset: reasoning.budgetPreset
|
|
9329
|
+
reasoningBudgetPreset: reasoning.budgetPreset,
|
|
9330
|
+
...fastMode.enabled && fastMode.provider === "anthropic" ? { fastMode: true } : {}
|
|
9263
9331
|
});
|
|
9264
9332
|
break;
|
|
9265
9333
|
}
|
|
@@ -9279,12 +9347,18 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
9279
9347
|
tools,
|
|
9280
9348
|
hostedTools: hostedSearchDefinitions,
|
|
9281
9349
|
systemPrompt,
|
|
9282
|
-
modelRegistry: modelRegistry ??
|
|
9350
|
+
modelRegistry: modelRegistry ?? DEFAULT_MODEL_REGISTRY3,
|
|
9283
9351
|
toolOutputCache: {
|
|
9284
9352
|
totalBudgetTrim: totalBudgetTrimEnabled
|
|
9285
9353
|
},
|
|
9286
9354
|
services: { toolOutputCacheStore },
|
|
9287
9355
|
canExecuteTool: async (call, rawArgs, toolCtx) => {
|
|
9356
|
+
if (state.autoApprovedClientToolNames.has(call.function.name)) {
|
|
9357
|
+
debugLog(
|
|
9358
|
+
`permission.evaluate tool=${call.function.name} decision=allow reason=client-tool-auto-approved`
|
|
9359
|
+
);
|
|
9360
|
+
return { decision: "allow" };
|
|
9361
|
+
}
|
|
9288
9362
|
const decision = permissionService.evaluate(
|
|
9289
9363
|
call.function.name,
|
|
9290
9364
|
rawArgs
|
|
@@ -11133,9 +11207,10 @@ var createHistoryHandlers = ({
|
|
|
11133
11207
|
// src/rpc/model.ts
|
|
11134
11208
|
import {
|
|
11135
11209
|
applyModelMetadata as applyModelMetadata2,
|
|
11136
|
-
DEFAULT_MODEL_REGISTRY as
|
|
11210
|
+
DEFAULT_MODEL_REGISTRY as DEFAULT_MODEL_REGISTRY4,
|
|
11211
|
+
isUsableModelSpec as isUsableModelSpec2,
|
|
11137
11212
|
listModels,
|
|
11138
|
-
resolveModel as
|
|
11213
|
+
resolveModel as resolveModel3,
|
|
11139
11214
|
resolveProviderModelId as resolveProviderModelId3
|
|
11140
11215
|
} from "@codelia/core";
|
|
11141
11216
|
import { ModelMetadataServiceImpl as ModelMetadataServiceImpl3 } from "@codelia/model-metadata";
|
|
@@ -11147,7 +11222,7 @@ var resolveProviderModelEntry2 = (providerEntries, provider, model) => {
|
|
|
11147
11222
|
if (!providerEntries) {
|
|
11148
11223
|
return null;
|
|
11149
11224
|
}
|
|
11150
|
-
const providerModelId = resolveProviderModelId3(
|
|
11225
|
+
const providerModelId = resolveProviderModelId3(DEFAULT_MODEL_REGISTRY4, model, provider) ?? model;
|
|
11151
11226
|
const candidates = [
|
|
11152
11227
|
model,
|
|
11153
11228
|
`${provider}/${model}`,
|
|
@@ -11176,7 +11251,7 @@ var normalizeUsdPer1M = (value) => {
|
|
|
11176
11251
|
return value;
|
|
11177
11252
|
};
|
|
11178
11253
|
var buildModelListDetail = (entry, registry, provider, model) => {
|
|
11179
|
-
const spec =
|
|
11254
|
+
const spec = resolveModel3(registry, model, provider);
|
|
11180
11255
|
if (!entry && !spec) return null;
|
|
11181
11256
|
const detail = {};
|
|
11182
11257
|
if (entry?.releaseDate?.trim()) {
|
|
@@ -11402,22 +11477,24 @@ var buildProviderModelList = async ({
|
|
|
11402
11477
|
}
|
|
11403
11478
|
}
|
|
11404
11479
|
}
|
|
11480
|
+
const mergedRegistry = applyModelMetadata2(DEFAULT_MODEL_REGISTRY4, {
|
|
11481
|
+
models: {
|
|
11482
|
+
openai: provider === "openai" ? providerEntries ?? {} : {},
|
|
11483
|
+
anthropic: provider === "anthropic" ? providerEntries ?? {} : {},
|
|
11484
|
+
openrouter: {},
|
|
11485
|
+
google: {}
|
|
11486
|
+
}
|
|
11487
|
+
});
|
|
11405
11488
|
const models = sortModelsByReleaseDate(
|
|
11406
|
-
listModels(
|
|
11489
|
+
listModels(DEFAULT_MODEL_REGISTRY4, provider).filter(
|
|
11490
|
+
(model) => isUsableModelSpec2(resolveModel3(mergedRegistry, model.id, provider))
|
|
11491
|
+
).map((model) => model.id),
|
|
11407
11492
|
provider,
|
|
11408
11493
|
providerEntries
|
|
11409
11494
|
);
|
|
11410
11495
|
if (!includeDetails || !providerEntries) {
|
|
11411
11496
|
return { models };
|
|
11412
11497
|
}
|
|
11413
|
-
const mergedRegistry = applyModelMetadata2(DEFAULT_MODEL_REGISTRY3, {
|
|
11414
|
-
models: {
|
|
11415
|
-
openai: provider === "openai" ? providerEntries : {},
|
|
11416
|
-
anthropic: provider === "anthropic" ? providerEntries : {},
|
|
11417
|
-
openrouter: {},
|
|
11418
|
-
google: {}
|
|
11419
|
-
}
|
|
11420
|
-
});
|
|
11421
11498
|
const details = {};
|
|
11422
11499
|
for (const model of models) {
|
|
11423
11500
|
const detail = buildModelListDetail(
|
|
@@ -11449,6 +11526,7 @@ var createModelHandlers = ({
|
|
|
11449
11526
|
let current;
|
|
11450
11527
|
let configuredProvider;
|
|
11451
11528
|
let configuredReasoning;
|
|
11529
|
+
let configuredFast;
|
|
11452
11530
|
try {
|
|
11453
11531
|
const config = await resolveModelConfig();
|
|
11454
11532
|
configuredProvider = config.provider ?? "openai";
|
|
@@ -11456,6 +11534,13 @@ var createModelHandlers = ({
|
|
|
11456
11534
|
if (!requestedProvider || requestedProvider === configuredProvider) {
|
|
11457
11535
|
current = config.name;
|
|
11458
11536
|
}
|
|
11537
|
+
if (config.fast !== void 0 && config.name && isSupportedProvider(configuredProvider)) {
|
|
11538
|
+
configuredFast = resolveFastMode({
|
|
11539
|
+
provider: configuredProvider,
|
|
11540
|
+
model: config.name,
|
|
11541
|
+
requested: config.fast
|
|
11542
|
+
}).enabled;
|
|
11543
|
+
}
|
|
11459
11544
|
} catch (error) {
|
|
11460
11545
|
sendError(id, {
|
|
11461
11546
|
code: RPC_ERROR_CODE3.RUNTIME_INTERNAL,
|
|
@@ -11497,6 +11582,7 @@ var createModelHandlers = ({
|
|
|
11497
11582
|
models,
|
|
11498
11583
|
current,
|
|
11499
11584
|
...configuredReasoning ? { reasoning: configuredReasoning } : {},
|
|
11585
|
+
...configuredFast !== void 0 ? { fast: configuredFast } : {},
|
|
11500
11586
|
...details ? { details } : {}
|
|
11501
11587
|
};
|
|
11502
11588
|
sendResult(id, result);
|
|
@@ -11538,7 +11624,7 @@ var createModelHandlers = ({
|
|
|
11538
11624
|
return;
|
|
11539
11625
|
}
|
|
11540
11626
|
if (provider !== "openrouter") {
|
|
11541
|
-
const spec =
|
|
11627
|
+
const spec = resolveModel3(DEFAULT_MODEL_REGISTRY4, name, provider);
|
|
11542
11628
|
if (!spec) {
|
|
11543
11629
|
sendError(id, {
|
|
11544
11630
|
code: RPC_ERROR_CODE3.INVALID_PARAMS,
|
|
@@ -11552,7 +11638,8 @@ var createModelHandlers = ({
|
|
|
11552
11638
|
const target = await updateModel(workingDir, {
|
|
11553
11639
|
provider,
|
|
11554
11640
|
name,
|
|
11555
|
-
...reasoning ? { reasoning } : {}
|
|
11641
|
+
...reasoning ? { reasoning } : {},
|
|
11642
|
+
...params.fast !== void 0 ? { fast: params.fast } : {}
|
|
11556
11643
|
});
|
|
11557
11644
|
state.currentModelProvider = provider;
|
|
11558
11645
|
state.currentModelName = name;
|
|
@@ -11561,10 +11648,16 @@ var createModelHandlers = ({
|
|
|
11561
11648
|
const effectiveReasoning = resolveReasoningEffort(
|
|
11562
11649
|
updatedConfig.reasoning
|
|
11563
11650
|
);
|
|
11651
|
+
const effectiveFast = resolveFastMode({
|
|
11652
|
+
provider,
|
|
11653
|
+
model: name,
|
|
11654
|
+
requested: updatedConfig.fast
|
|
11655
|
+
}).enabled;
|
|
11564
11656
|
const result = {
|
|
11565
11657
|
provider,
|
|
11566
11658
|
name,
|
|
11567
|
-
...effectiveReasoning ? { reasoning: effectiveReasoning } : {}
|
|
11659
|
+
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
11660
|
+
...updatedConfig.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
11568
11661
|
};
|
|
11569
11662
|
sendResult(id, result);
|
|
11570
11663
|
log2(
|
|
@@ -11580,346 +11673,61 @@ var createModelHandlers = ({
|
|
|
11580
11673
|
return { handleModelList, handleModelSet };
|
|
11581
11674
|
};
|
|
11582
11675
|
|
|
11583
|
-
// src/rpc/
|
|
11584
|
-
import {
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
var
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
var DEBUG_ERROR_STACK_MAX_CHARS = 8e3;
|
|
11596
|
-
var DEBUG_ERROR_CHAIN_MAX_CHARS = 4e3;
|
|
11597
|
-
var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
|
|
11598
|
-
var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
|
|
11599
|
-
var truncateText2 = (value, maxChars) => {
|
|
11600
|
-
if (value.length <= maxChars) return value;
|
|
11601
|
-
return `${value.slice(0, maxChars)}...[truncated]`;
|
|
11676
|
+
// src/rpc/resume-context.ts
|
|
11677
|
+
import { promises as fs17 } from "fs";
|
|
11678
|
+
import path16 from "path";
|
|
11679
|
+
var RESUME_CONTEXT_META_KEY = "codelia_resume_context";
|
|
11680
|
+
var RESUME_CONTEXT_SCHEMA_VERSION = 1;
|
|
11681
|
+
var RESUME_DIFF_TAG = '<system-reminder type="session.resume.diff">';
|
|
11682
|
+
var MAX_RESUME_DETAIL_LINES = 3;
|
|
11683
|
+
var normalizePath2 = (value) => {
|
|
11684
|
+
if (typeof value !== "string") return void 0;
|
|
11685
|
+
const trimmed = value.trim();
|
|
11686
|
+
if (!trimmed) return void 0;
|
|
11687
|
+
return path16.resolve(trimmed);
|
|
11602
11688
|
};
|
|
11603
|
-
var
|
|
11604
|
-
|
|
11605
|
-
return
|
|
11606
|
-
} catch {
|
|
11607
|
-
return String(value);
|
|
11689
|
+
var normalizeMtime3 = (value) => {
|
|
11690
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
11691
|
+
return void 0;
|
|
11608
11692
|
}
|
|
11693
|
+
return Math.trunc(value);
|
|
11609
11694
|
};
|
|
11610
|
-
var
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
includeOtherPayload: true
|
|
11615
|
-
});
|
|
11616
|
-
return truncateText2(text, maxChars);
|
|
11617
|
-
};
|
|
11618
|
-
var buildCompactionSnapshotLog = (messages) => {
|
|
11619
|
-
const payload = messages.map((message, index) => {
|
|
11620
|
-
if (message.role === "assistant") {
|
|
11621
|
-
return {
|
|
11622
|
-
index,
|
|
11623
|
-
role: message.role,
|
|
11624
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS),
|
|
11625
|
-
tool_calls: (message.tool_calls ?? []).map((call) => ({
|
|
11626
|
-
id: call.id,
|
|
11627
|
-
name: call.function.name
|
|
11628
|
-
}))
|
|
11629
|
-
};
|
|
11630
|
-
}
|
|
11631
|
-
if (message.role === "tool") {
|
|
11632
|
-
return {
|
|
11633
|
-
index,
|
|
11634
|
-
role: message.role,
|
|
11635
|
-
tool_name: message.tool_name,
|
|
11636
|
-
tool_call_id: message.tool_call_id,
|
|
11637
|
-
is_error: message.is_error ?? false,
|
|
11638
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
11639
|
-
};
|
|
11640
|
-
}
|
|
11641
|
-
if (message.role === "reasoning") {
|
|
11642
|
-
return {
|
|
11643
|
-
index,
|
|
11644
|
-
role: message.role,
|
|
11645
|
-
content: truncateText2(message.content ?? "", DEBUG_MAX_CONTENT_CHARS)
|
|
11646
|
-
};
|
|
11647
|
-
}
|
|
11648
|
-
return {
|
|
11649
|
-
index,
|
|
11650
|
-
role: message.role,
|
|
11651
|
-
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
11652
|
-
};
|
|
11653
|
-
});
|
|
11654
|
-
return truncateText2(stringifyUnknown(payload), DEBUG_MAX_LOG_CHARS);
|
|
11695
|
+
var normalizeText = (value) => {
|
|
11696
|
+
if (typeof value !== "string") return void 0;
|
|
11697
|
+
const trimmed = value.trim();
|
|
11698
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
11655
11699
|
};
|
|
11656
|
-
var
|
|
11657
|
-
if (
|
|
11658
|
-
|
|
11659
|
-
|
|
11660
|
-
|
|
11661
|
-
`compaction context snapshot run_id=${runId} compacted=${String(compacted)} messages=${messages.length} history=${snapshot}`
|
|
11662
|
-
);
|
|
11700
|
+
var normalizeApprovalMode = (value) => {
|
|
11701
|
+
if (value === "minimal" || value === "trusted" || value === "full-access") {
|
|
11702
|
+
return value;
|
|
11703
|
+
}
|
|
11704
|
+
return void 0;
|
|
11663
11705
|
};
|
|
11664
|
-
var
|
|
11665
|
-
|
|
11666
|
-
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
11676
|
-
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
11677
|
-
const isError = event.is_error === true;
|
|
11678
|
-
const result = typeof event.result === "string" ? truncateText2(event.result, DEBUG_MAX_EVENT_RESULT_CHARS) : truncateText2(
|
|
11679
|
-
stringifyUnknown(event.result),
|
|
11680
|
-
DEBUG_MAX_EVENT_RESULT_CHARS
|
|
11681
|
-
);
|
|
11682
|
-
return `type=tool_result tool=${tool} tool_call_id=${toolCallId} is_error=${String(isError)} result=${stringifyUnknown(result)}`;
|
|
11683
|
-
}
|
|
11684
|
-
case "step_start": {
|
|
11685
|
-
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
11686
|
-
const title = typeof event.title === "string" ? event.title : "unknown";
|
|
11687
|
-
return `type=step_start step_id=${stepId} title=${title}`;
|
|
11688
|
-
}
|
|
11689
|
-
case "step_complete": {
|
|
11690
|
-
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
11691
|
-
const status = typeof event.status === "string" ? event.status : "unknown";
|
|
11692
|
-
const durationMs = typeof event.duration_ms === "number" ? event.duration_ms : -1;
|
|
11693
|
-
return `type=step_complete step_id=${stepId} status=${status} duration_ms=${durationMs}`;
|
|
11694
|
-
}
|
|
11695
|
-
case "final": {
|
|
11696
|
-
const content = typeof event.content === "string" ? event.content : "";
|
|
11697
|
-
return `type=final content_chars=${content.length}`;
|
|
11698
|
-
}
|
|
11699
|
-
default:
|
|
11700
|
-
return `type=${event.type}`;
|
|
11706
|
+
var normalizeTrackedFiles = (value) => {
|
|
11707
|
+
if (!Array.isArray(value)) return [];
|
|
11708
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11709
|
+
const files = [];
|
|
11710
|
+
for (const entry of value) {
|
|
11711
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11712
|
+
const record = entry;
|
|
11713
|
+
const filePath = normalizePath2(record.path);
|
|
11714
|
+
const mtime = normalizeMtime3(record.mtime_ms);
|
|
11715
|
+
if (!filePath || mtime === void 0 || seen.has(filePath)) continue;
|
|
11716
|
+
seen.add(filePath);
|
|
11717
|
+
files.push({ path: filePath, mtime_ms: mtime });
|
|
11701
11718
|
}
|
|
11719
|
+
files.sort((left, right) => left.path.localeCompare(right.path));
|
|
11720
|
+
return files;
|
|
11702
11721
|
};
|
|
11703
|
-
var
|
|
11704
|
-
if (
|
|
11705
|
-
|
|
11706
|
-
}
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
for (const call of message.tool_calls ?? []) {
|
|
11713
|
-
assistantCallIds.add(call.id);
|
|
11714
|
-
}
|
|
11715
|
-
continue;
|
|
11716
|
-
}
|
|
11717
|
-
if (message.role === "tool") {
|
|
11718
|
-
toolOutputCallIds.add(message.tool_call_id);
|
|
11719
|
-
}
|
|
11720
|
-
}
|
|
11721
|
-
if (assistantCallIds.size === 0 && toolOutputCallIds.size === 0) {
|
|
11722
|
-
return messages;
|
|
11723
|
-
}
|
|
11724
|
-
const validCallIds = /* @__PURE__ */ new Set();
|
|
11725
|
-
for (const callId of assistantCallIds) {
|
|
11726
|
-
if (toolOutputCallIds.has(callId)) {
|
|
11727
|
-
validCallIds.add(callId);
|
|
11728
|
-
}
|
|
11729
|
-
}
|
|
11730
|
-
if (validCallIds.size === assistantCallIds.size && validCallIds.size === toolOutputCallIds.size) {
|
|
11731
|
-
return messages;
|
|
11732
|
-
}
|
|
11733
|
-
let changed = false;
|
|
11734
|
-
const normalized = [];
|
|
11735
|
-
for (const message of messages) {
|
|
11736
|
-
if (message.role === "assistant") {
|
|
11737
|
-
const calls = message.tool_calls ?? [];
|
|
11738
|
-
if (calls.length > 0) {
|
|
11739
|
-
const filteredCalls = calls.filter((call) => validCallIds.has(call.id));
|
|
11740
|
-
if (filteredCalls.length !== calls.length) {
|
|
11741
|
-
changed = true;
|
|
11742
|
-
if (filteredCalls.length === 0) {
|
|
11743
|
-
const next = { ...message };
|
|
11744
|
-
delete next.tool_calls;
|
|
11745
|
-
normalized.push(next);
|
|
11746
|
-
} else {
|
|
11747
|
-
normalized.push({ ...message, tool_calls: filteredCalls });
|
|
11748
|
-
}
|
|
11749
|
-
continue;
|
|
11750
|
-
}
|
|
11751
|
-
}
|
|
11752
|
-
normalized.push(message);
|
|
11753
|
-
continue;
|
|
11754
|
-
}
|
|
11755
|
-
if (message.role === "tool" && !validCallIds.has(message.tool_call_id)) {
|
|
11756
|
-
changed = true;
|
|
11757
|
-
continue;
|
|
11758
|
-
}
|
|
11759
|
-
normalized.push(message);
|
|
11760
|
-
}
|
|
11761
|
-
return changed ? normalized : messages;
|
|
11762
|
-
};
|
|
11763
|
-
var formatErrorForDebugLog = (error) => {
|
|
11764
|
-
const parts = [];
|
|
11765
|
-
parts.push(`name=${error.name}`);
|
|
11766
|
-
parts.push(
|
|
11767
|
-
`message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
|
|
11768
|
-
);
|
|
11769
|
-
if (error.stack) {
|
|
11770
|
-
parts.push(
|
|
11771
|
-
`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`
|
|
11772
|
-
);
|
|
11773
|
-
}
|
|
11774
|
-
const causeChain = [];
|
|
11775
|
-
let depth = 0;
|
|
11776
|
-
let current = error.cause;
|
|
11777
|
-
const seen = /* @__PURE__ */ new Set();
|
|
11778
|
-
while (current !== void 0 && current !== null && depth < 4) {
|
|
11779
|
-
if (seen.has(current)) {
|
|
11780
|
-
causeChain.push("[circular]");
|
|
11781
|
-
break;
|
|
11782
|
-
}
|
|
11783
|
-
seen.add(current);
|
|
11784
|
-
if (current instanceof Error) {
|
|
11785
|
-
causeChain.push(`${current.name}: ${current.message}`);
|
|
11786
|
-
current = current.cause;
|
|
11787
|
-
depth += 1;
|
|
11788
|
-
continue;
|
|
11789
|
-
}
|
|
11790
|
-
causeChain.push(stringifyUnknown(current));
|
|
11791
|
-
break;
|
|
11792
|
-
}
|
|
11793
|
-
if (causeChain.length > 0) {
|
|
11794
|
-
parts.push(
|
|
11795
|
-
`cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
|
|
11796
|
-
);
|
|
11797
|
-
}
|
|
11798
|
-
const extras = Object.entries(
|
|
11799
|
-
error
|
|
11800
|
-
).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
|
|
11801
|
-
if (extras.length > 0) {
|
|
11802
|
-
parts.push(
|
|
11803
|
-
`extras=${truncateText2(
|
|
11804
|
-
stringifyUnknown(Object.fromEntries(extras)),
|
|
11805
|
-
DEBUG_ERROR_EXTRAS_MAX_CHARS
|
|
11806
|
-
)}`
|
|
11807
|
-
);
|
|
11808
|
-
}
|
|
11809
|
-
return parts.join(" ");
|
|
11810
|
-
};
|
|
11811
|
-
var summarizeProviderMeta = (value) => {
|
|
11812
|
-
if (value === null || value === void 0) {
|
|
11813
|
-
return null;
|
|
11814
|
-
}
|
|
11815
|
-
if (typeof value === "string") {
|
|
11816
|
-
return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
|
|
11817
|
-
}
|
|
11818
|
-
if (Array.isArray(value)) {
|
|
11819
|
-
return `array(len=${value.length})`;
|
|
11820
|
-
}
|
|
11821
|
-
if (typeof value === "object") {
|
|
11822
|
-
const obj = value;
|
|
11823
|
-
const details = [];
|
|
11824
|
-
if (typeof obj.transport === "string") {
|
|
11825
|
-
details.push(`transport=${obj.transport}`);
|
|
11826
|
-
}
|
|
11827
|
-
if (typeof obj.websocket_mode === "string") {
|
|
11828
|
-
details.push(`websocket_mode=${obj.websocket_mode}`);
|
|
11829
|
-
}
|
|
11830
|
-
if (typeof obj.response_id === "string") {
|
|
11831
|
-
details.push(`response_id=${obj.response_id}`);
|
|
11832
|
-
}
|
|
11833
|
-
if (typeof obj.chain_reset === "boolean") {
|
|
11834
|
-
details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
|
|
11835
|
-
}
|
|
11836
|
-
if (typeof obj.fallback_used === "boolean") {
|
|
11837
|
-
details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
|
|
11838
|
-
}
|
|
11839
|
-
if (typeof obj.ws_input_mode === "string") {
|
|
11840
|
-
details.push(`ws_input_mode=${obj.ws_input_mode}`);
|
|
11841
|
-
}
|
|
11842
|
-
if (typeof obj.reasoning_requested === "string") {
|
|
11843
|
-
details.push(`reasoning_requested=${obj.reasoning_requested}`);
|
|
11844
|
-
}
|
|
11845
|
-
if (typeof obj.reasoning_applied === "string") {
|
|
11846
|
-
details.push(`reasoning_applied=${obj.reasoning_applied}`);
|
|
11847
|
-
}
|
|
11848
|
-
if (typeof obj.reasoning_fallback === "boolean") {
|
|
11849
|
-
details.push(
|
|
11850
|
-
`reasoning_fallback=${obj.reasoning_fallback ? "true" : "false"}`
|
|
11851
|
-
);
|
|
11852
|
-
}
|
|
11853
|
-
if (typeof obj.reasoning_budget_preset === "string") {
|
|
11854
|
-
details.push(`reasoning_budget_preset=${obj.reasoning_budget_preset}`);
|
|
11855
|
-
}
|
|
11856
|
-
if (details.length > 0) {
|
|
11857
|
-
return details.join(" ");
|
|
11858
|
-
}
|
|
11859
|
-
const keys = Object.keys(obj);
|
|
11860
|
-
if (keys.length === 0) return "object";
|
|
11861
|
-
const shown = keys.slice(0, 4).join(",");
|
|
11862
|
-
return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
|
|
11863
|
-
}
|
|
11864
|
-
return typeof value;
|
|
11865
|
-
};
|
|
11866
|
-
var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
|
|
11867
|
-
|
|
11868
|
-
// src/rpc/resume-context.ts
|
|
11869
|
-
import { promises as fs17 } from "fs";
|
|
11870
|
-
import path16 from "path";
|
|
11871
|
-
var RESUME_CONTEXT_META_KEY = "codelia_resume_context";
|
|
11872
|
-
var RESUME_CONTEXT_SCHEMA_VERSION = 1;
|
|
11873
|
-
var RESUME_DIFF_TAG = '<system-reminder type="session.resume.diff">';
|
|
11874
|
-
var MAX_RESUME_DETAIL_LINES = 3;
|
|
11875
|
-
var normalizePath2 = (value) => {
|
|
11876
|
-
if (typeof value !== "string") return void 0;
|
|
11877
|
-
const trimmed = value.trim();
|
|
11878
|
-
if (!trimmed) return void 0;
|
|
11879
|
-
return path16.resolve(trimmed);
|
|
11880
|
-
};
|
|
11881
|
-
var normalizeMtime3 = (value) => {
|
|
11882
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
11883
|
-
return void 0;
|
|
11884
|
-
}
|
|
11885
|
-
return Math.trunc(value);
|
|
11886
|
-
};
|
|
11887
|
-
var normalizeText = (value) => {
|
|
11888
|
-
if (typeof value !== "string") return void 0;
|
|
11889
|
-
const trimmed = value.trim();
|
|
11890
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
11891
|
-
};
|
|
11892
|
-
var normalizeApprovalMode = (value) => {
|
|
11893
|
-
if (value === "minimal" || value === "trusted" || value === "full-access") {
|
|
11894
|
-
return value;
|
|
11895
|
-
}
|
|
11896
|
-
return void 0;
|
|
11897
|
-
};
|
|
11898
|
-
var normalizeTrackedFiles = (value) => {
|
|
11899
|
-
if (!Array.isArray(value)) return [];
|
|
11900
|
-
const seen = /* @__PURE__ */ new Set();
|
|
11901
|
-
const files = [];
|
|
11902
|
-
for (const entry of value) {
|
|
11903
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11904
|
-
const record = entry;
|
|
11905
|
-
const filePath = normalizePath2(record.path);
|
|
11906
|
-
const mtime = normalizeMtime3(record.mtime_ms);
|
|
11907
|
-
if (!filePath || mtime === void 0 || seen.has(filePath)) continue;
|
|
11908
|
-
seen.add(filePath);
|
|
11909
|
-
files.push({ path: filePath, mtime_ms: mtime });
|
|
11910
|
-
}
|
|
11911
|
-
files.sort((left, right) => left.path.localeCompare(right.path));
|
|
11912
|
-
return files;
|
|
11913
|
-
};
|
|
11914
|
-
var trimDetails = (lines) => {
|
|
11915
|
-
if (lines.length <= MAX_RESUME_DETAIL_LINES) {
|
|
11916
|
-
return lines;
|
|
11917
|
-
}
|
|
11918
|
-
const remaining = lines.length - MAX_RESUME_DETAIL_LINES;
|
|
11919
|
-
return [
|
|
11920
|
-
...lines.slice(0, MAX_RESUME_DETAIL_LINES),
|
|
11921
|
-
`... and ${remaining} more change(s)`
|
|
11922
|
-
];
|
|
11722
|
+
var trimDetails = (lines) => {
|
|
11723
|
+
if (lines.length <= MAX_RESUME_DETAIL_LINES) {
|
|
11724
|
+
return lines;
|
|
11725
|
+
}
|
|
11726
|
+
const remaining = lines.length - MAX_RESUME_DETAIL_LINES;
|
|
11727
|
+
return [
|
|
11728
|
+
...lines.slice(0, MAX_RESUME_DETAIL_LINES),
|
|
11729
|
+
`... and ${remaining} more change(s)`
|
|
11730
|
+
];
|
|
11923
11731
|
};
|
|
11924
11732
|
var contentToString = (content) => {
|
|
11925
11733
|
if (typeof content === "string") {
|
|
@@ -11995,8 +11803,12 @@ var summarizeTrackedFileDiff = (label, savedFiles, currentFiles) => {
|
|
|
11995
11803
|
if (savedFiles.length === 0 && currentFiles.length === 0) {
|
|
11996
11804
|
return [];
|
|
11997
11805
|
}
|
|
11998
|
-
const savedByPath = new Map(
|
|
11999
|
-
|
|
11806
|
+
const savedByPath = new Map(
|
|
11807
|
+
savedFiles.map((file) => [file.path, file.mtime_ms])
|
|
11808
|
+
);
|
|
11809
|
+
const currentByPath = new Map(
|
|
11810
|
+
currentFiles.map((file) => [file.path, file.mtime_ms])
|
|
11811
|
+
);
|
|
12000
11812
|
const details = [];
|
|
12001
11813
|
for (const [filePath, savedMtime] of savedByPath) {
|
|
12002
11814
|
const currentMtime = currentByPath.get(filePath);
|
|
@@ -12021,7 +11833,9 @@ var summarizeCurrentLoadedSkillDiff = (savedSkills, currentSkills) => (async ()
|
|
|
12021
11833
|
if (savedSkills.length === 0 && currentSkills.length === 0) {
|
|
12022
11834
|
return [];
|
|
12023
11835
|
}
|
|
12024
|
-
const savedByPath = new Map(
|
|
11836
|
+
const savedByPath = new Map(
|
|
11837
|
+
savedSkills.map((file) => [file.path, file.mtime_ms])
|
|
11838
|
+
);
|
|
12025
11839
|
const currentByPath = new Map(
|
|
12026
11840
|
currentSkills.map((file) => [file.path, file.mtime_ms])
|
|
12027
11841
|
);
|
|
@@ -12124,112 +11938,509 @@ var buildResumeDiff = async (meta, state, options = {}) => {
|
|
|
12124
11938
|
if (currentWorkspaceRoot) {
|
|
12125
11939
|
contextLines.push(`Current workspace root: ${currentWorkspaceRoot}`);
|
|
12126
11940
|
}
|
|
12127
|
-
if (currentWorkingDir) {
|
|
12128
|
-
contextLines.push(`Current working directory: ${currentWorkingDir}`);
|
|
11941
|
+
if (currentWorkingDir) {
|
|
11942
|
+
contextLines.push(`Current working directory: ${currentWorkingDir}`);
|
|
11943
|
+
}
|
|
11944
|
+
if (currentSandboxRoot) {
|
|
11945
|
+
contextLines.push(`Current sandbox root: ${currentSandboxRoot}`);
|
|
11946
|
+
}
|
|
11947
|
+
if (currentApprovalMode) {
|
|
11948
|
+
contextLines.push(`Current approval mode: ${currentApprovalMode}`);
|
|
11949
|
+
}
|
|
11950
|
+
if (currentModelProvider || currentModelName) {
|
|
11951
|
+
contextLines.push(
|
|
11952
|
+
`Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
11953
|
+
);
|
|
11954
|
+
}
|
|
11955
|
+
const detailLines = [];
|
|
11956
|
+
let changed = false;
|
|
11957
|
+
if (!savedContext) {
|
|
11958
|
+
detailLines.push(
|
|
11959
|
+
"Saved session has no structured resume metadata. Treat the current runtime/workspace context as authoritative."
|
|
11960
|
+
);
|
|
11961
|
+
changed = true;
|
|
11962
|
+
} else {
|
|
11963
|
+
const comparePath = (label, savedValue, currentValue) => {
|
|
11964
|
+
if (bestEffortCurrentContext && currentValue === void 0) {
|
|
11965
|
+
return;
|
|
11966
|
+
}
|
|
11967
|
+
if (savedValue === currentValue) return;
|
|
11968
|
+
changed = true;
|
|
11969
|
+
detailLines.push(
|
|
11970
|
+
`${label}: ${savedValue ?? "(unknown)"} -> ${currentValue ?? "(unknown)"}`
|
|
11971
|
+
);
|
|
11972
|
+
};
|
|
11973
|
+
comparePath(
|
|
11974
|
+
"Workspace root changed",
|
|
11975
|
+
savedContext.workspace_root,
|
|
11976
|
+
currentWorkspaceRoot
|
|
11977
|
+
);
|
|
11978
|
+
comparePath(
|
|
11979
|
+
"Working directory changed",
|
|
11980
|
+
savedContext.working_dir,
|
|
11981
|
+
currentWorkingDir
|
|
11982
|
+
);
|
|
11983
|
+
comparePath(
|
|
11984
|
+
"Sandbox root changed",
|
|
11985
|
+
savedContext.sandbox_root,
|
|
11986
|
+
currentSandboxRoot
|
|
11987
|
+
);
|
|
11988
|
+
if (savedContext.approval_mode !== currentApprovalMode && (!bestEffortCurrentContext || currentApprovalMode !== void 0)) {
|
|
11989
|
+
changed = true;
|
|
11990
|
+
detailLines.push(
|
|
11991
|
+
`Approval mode changed: ${savedContext.approval_mode ?? "(unknown)"} -> ${currentApprovalMode ?? "(unknown)"}`
|
|
11992
|
+
);
|
|
11993
|
+
}
|
|
11994
|
+
if ((savedContext.model_provider !== currentModelProvider || savedContext.model_name !== currentModelName) && (!bestEffortCurrentContext || currentModelProvider !== void 0 || currentModelName !== void 0)) {
|
|
11995
|
+
changed = true;
|
|
11996
|
+
detailLines.push(
|
|
11997
|
+
`Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
11998
|
+
);
|
|
11999
|
+
}
|
|
12000
|
+
if (!(bestEffortCurrentContext && !currentInitialAgentsKnown)) {
|
|
12001
|
+
const agentDiffs = summarizeTrackedFileDiff(
|
|
12002
|
+
"Initial AGENTS",
|
|
12003
|
+
savedContext.initial_agents ?? [],
|
|
12004
|
+
currentAgents
|
|
12005
|
+
);
|
|
12006
|
+
if (agentDiffs.length > 0) {
|
|
12007
|
+
changed = true;
|
|
12008
|
+
detailLines.push(...agentDiffs);
|
|
12009
|
+
}
|
|
12010
|
+
}
|
|
12011
|
+
const skillDiffs = await summarizeCurrentLoadedSkillDiff(
|
|
12012
|
+
savedContext.loaded_skills ?? [],
|
|
12013
|
+
currentLoadedSkills
|
|
12014
|
+
);
|
|
12015
|
+
if (skillDiffs.length > 0) {
|
|
12016
|
+
changed = true;
|
|
12017
|
+
detailLines.push(...skillDiffs);
|
|
12018
|
+
}
|
|
12019
|
+
if (!changed) {
|
|
12020
|
+
detailLines.push(
|
|
12021
|
+
"No material workspace/AGENTS/skill changes were detected from saved resume metadata."
|
|
12022
|
+
);
|
|
12023
|
+
}
|
|
12024
|
+
}
|
|
12025
|
+
if (contextLines.length === 0 && detailLines.length === 0) {
|
|
12026
|
+
return null;
|
|
12027
|
+
}
|
|
12028
|
+
const summaryLines = [
|
|
12029
|
+
"Resume context:",
|
|
12030
|
+
...contextLines.map((line) => `- ${line}`),
|
|
12031
|
+
...detailLines.map((line) => `- ${line}`)
|
|
12032
|
+
];
|
|
12033
|
+
const systemLines = [
|
|
12034
|
+
'<system-reminder type="session.resume.diff">',
|
|
12035
|
+
"Session resumed in current runtime context:",
|
|
12036
|
+
...contextLines.map((line) => `- ${line}`),
|
|
12037
|
+
...detailLines.map((line) => `- ${line}`),
|
|
12038
|
+
"Use the current runtime/workspace context for subsequent actions.",
|
|
12039
|
+
"</system-reminder>"
|
|
12040
|
+
];
|
|
12041
|
+
return {
|
|
12042
|
+
summary: summaryLines.join("\n"),
|
|
12043
|
+
systemReminder: systemLines.join("\n"),
|
|
12044
|
+
changed
|
|
12045
|
+
};
|
|
12046
|
+
};
|
|
12047
|
+
|
|
12048
|
+
// src/rpc/run.ts
|
|
12049
|
+
import {
|
|
12050
|
+
RPC_ERROR_CODE as RPC_ERROR_CODE4
|
|
12051
|
+
} from "@codelia/protocol";
|
|
12052
|
+
|
|
12053
|
+
// src/rpc/client-tool-requests.ts
|
|
12054
|
+
var requestClientToolCall = async (state, params, timeoutMs) => {
|
|
12055
|
+
const id = state.nextUiRequestId();
|
|
12056
|
+
const request = {
|
|
12057
|
+
jsonrpc: "2.0",
|
|
12058
|
+
id,
|
|
12059
|
+
method: "client.tool.call",
|
|
12060
|
+
params
|
|
12061
|
+
};
|
|
12062
|
+
send(request);
|
|
12063
|
+
return await state.waitForUiResponse(id, timeoutMs);
|
|
12064
|
+
};
|
|
12065
|
+
|
|
12066
|
+
// src/tools/client.ts
|
|
12067
|
+
var DEFAULT_TIMEOUT_MS4 = 6e4;
|
|
12068
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12069
|
+
var normalizeClientToolResult = (value) => {
|
|
12070
|
+
if (typeof value === "string") {
|
|
12071
|
+
return { type: "text", text: value };
|
|
12072
|
+
}
|
|
12073
|
+
if (isRecord7(value)) {
|
|
12074
|
+
if (value.type === "text" && typeof value.text === "string") {
|
|
12075
|
+
return { type: "text", text: value.text };
|
|
12076
|
+
}
|
|
12077
|
+
if (value.type === "parts" && Array.isArray(value.parts)) {
|
|
12078
|
+
return { type: "parts", parts: value.parts };
|
|
12079
|
+
}
|
|
12080
|
+
if (value.type === "json" && "value" in value) {
|
|
12081
|
+
return { type: "json", value: value.value };
|
|
12082
|
+
}
|
|
12083
|
+
}
|
|
12084
|
+
return { type: "json", value };
|
|
12085
|
+
};
|
|
12086
|
+
var validateClientToolDefinition = (tool, existingNames) => {
|
|
12087
|
+
if (tool.type !== void 0 && tool.type !== "function") {
|
|
12088
|
+
throw new Error(`unsupported client tool type: ${String(tool.type)}`);
|
|
12089
|
+
}
|
|
12090
|
+
if (!tool.name || !/^[a-zA-Z0-9_-]+$/.test(tool.name)) {
|
|
12091
|
+
throw new Error(`invalid client tool name: ${tool.name}`);
|
|
12092
|
+
}
|
|
12093
|
+
if (existingNames.has(tool.name)) {
|
|
12094
|
+
throw new Error(
|
|
12095
|
+
`client tool name conflicts with existing tool: ${tool.name}`
|
|
12096
|
+
);
|
|
12097
|
+
}
|
|
12098
|
+
if (!tool.description.trim()) {
|
|
12099
|
+
throw new Error(`client tool description is required: ${tool.name}`);
|
|
12100
|
+
}
|
|
12101
|
+
if (!isRecord7(tool.parameters)) {
|
|
12102
|
+
throw new Error(
|
|
12103
|
+
`client tool parameters must be a JSON schema: ${tool.name}`
|
|
12104
|
+
);
|
|
12105
|
+
}
|
|
12106
|
+
if (tool.timeout_ms !== void 0 && (!Number.isFinite(tool.timeout_ms) || tool.timeout_ms <= 0)) {
|
|
12107
|
+
throw new Error(`client tool timeout_ms must be positive: ${tool.name}`);
|
|
12108
|
+
}
|
|
12109
|
+
};
|
|
12110
|
+
var createClientToolAdapters = ({
|
|
12111
|
+
runId,
|
|
12112
|
+
tools,
|
|
12113
|
+
state,
|
|
12114
|
+
existingTools
|
|
12115
|
+
}) => {
|
|
12116
|
+
if (!tools?.length) return [];
|
|
12117
|
+
const existingNames = new Set(existingTools.map((tool) => tool.name));
|
|
12118
|
+
const clientNames = /* @__PURE__ */ new Set();
|
|
12119
|
+
return tools.map((clientTool) => {
|
|
12120
|
+
validateClientToolDefinition(clientTool, existingNames);
|
|
12121
|
+
if (clientNames.has(clientTool.name)) {
|
|
12122
|
+
throw new Error(`duplicate client tool name: ${clientTool.name}`);
|
|
12123
|
+
}
|
|
12124
|
+
clientNames.add(clientTool.name);
|
|
12125
|
+
const timeoutMs = clientTool.timeout_ms ?? DEFAULT_TIMEOUT_MS4;
|
|
12126
|
+
const description = `${clientTool.description.trim()} (origin: runtime client)`;
|
|
12127
|
+
return {
|
|
12128
|
+
name: clientTool.name,
|
|
12129
|
+
description,
|
|
12130
|
+
definition: {
|
|
12131
|
+
name: clientTool.name,
|
|
12132
|
+
description,
|
|
12133
|
+
parameters: clientTool.parameters,
|
|
12134
|
+
strict: clientTool.strict ?? false
|
|
12135
|
+
},
|
|
12136
|
+
executeRaw: async (rawArgsJson) => {
|
|
12137
|
+
let args;
|
|
12138
|
+
try {
|
|
12139
|
+
const parsed = JSON.parse(rawArgsJson);
|
|
12140
|
+
args = isRecord7(parsed) ? parsed : { value: parsed };
|
|
12141
|
+
} catch (error) {
|
|
12142
|
+
throw new Error(
|
|
12143
|
+
`Invalid tool arguments JSON for ${clientTool.name}: ${String(error)}`
|
|
12144
|
+
);
|
|
12145
|
+
}
|
|
12146
|
+
const response = await requestClientToolCall(
|
|
12147
|
+
state,
|
|
12148
|
+
{
|
|
12149
|
+
run_id: runId,
|
|
12150
|
+
name: clientTool.name,
|
|
12151
|
+
arguments: args,
|
|
12152
|
+
raw_arguments: rawArgsJson
|
|
12153
|
+
},
|
|
12154
|
+
timeoutMs
|
|
12155
|
+
);
|
|
12156
|
+
if (!response.ok) {
|
|
12157
|
+
throw new Error(response.error);
|
|
12158
|
+
}
|
|
12159
|
+
return normalizeClientToolResult(response.result);
|
|
12160
|
+
}
|
|
12161
|
+
};
|
|
12162
|
+
});
|
|
12163
|
+
};
|
|
12164
|
+
|
|
12165
|
+
// src/rpc/run-debug.ts
|
|
12166
|
+
import { stringifyContent } from "@codelia/core";
|
|
12167
|
+
var DEBUG_MAX_CONTENT_CHARS = 2e3;
|
|
12168
|
+
var DEBUG_MAX_LOG_CHARS = 2e4;
|
|
12169
|
+
var DEBUG_MAX_EVENT_RESULT_CHARS = 500;
|
|
12170
|
+
var DEBUG_MAX_EVENT_ARGS_CHARS = 2e3;
|
|
12171
|
+
var DEBUG_ERROR_MESSAGE_MAX_CHARS = 2e3;
|
|
12172
|
+
var DEBUG_ERROR_STACK_MAX_CHARS = 8e3;
|
|
12173
|
+
var DEBUG_ERROR_CHAIN_MAX_CHARS = 4e3;
|
|
12174
|
+
var DEBUG_ERROR_EXTRAS_MAX_CHARS = 4e3;
|
|
12175
|
+
var DEBUG_PROVIDER_META_STRING_MAX_CHARS = 80;
|
|
12176
|
+
var truncateText2 = (value, maxChars) => {
|
|
12177
|
+
if (value.length <= maxChars) return value;
|
|
12178
|
+
return `${value.slice(0, maxChars)}...[truncated]`;
|
|
12179
|
+
};
|
|
12180
|
+
var stringifyUnknown = (value) => {
|
|
12181
|
+
try {
|
|
12182
|
+
return JSON.stringify(value);
|
|
12183
|
+
} catch {
|
|
12184
|
+
return String(value);
|
|
12185
|
+
}
|
|
12186
|
+
};
|
|
12187
|
+
var contentToDebugText = (content, maxChars) => {
|
|
12188
|
+
const text = stringifyContent(content, {
|
|
12189
|
+
mode: "log",
|
|
12190
|
+
joiner: "\n",
|
|
12191
|
+
includeOtherPayload: true
|
|
12192
|
+
});
|
|
12193
|
+
return truncateText2(text, maxChars);
|
|
12194
|
+
};
|
|
12195
|
+
var buildCompactionSnapshotLog = (messages) => {
|
|
12196
|
+
const payload = messages.map((message, index) => {
|
|
12197
|
+
if (message.role === "assistant") {
|
|
12198
|
+
return {
|
|
12199
|
+
index,
|
|
12200
|
+
role: message.role,
|
|
12201
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS),
|
|
12202
|
+
tool_calls: (message.tool_calls ?? []).map((call) => ({
|
|
12203
|
+
id: call.id,
|
|
12204
|
+
name: call.function.name
|
|
12205
|
+
}))
|
|
12206
|
+
};
|
|
12207
|
+
}
|
|
12208
|
+
if (message.role === "tool") {
|
|
12209
|
+
return {
|
|
12210
|
+
index,
|
|
12211
|
+
role: message.role,
|
|
12212
|
+
tool_name: message.tool_name,
|
|
12213
|
+
tool_call_id: message.tool_call_id,
|
|
12214
|
+
is_error: message.is_error ?? false,
|
|
12215
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
12216
|
+
};
|
|
12217
|
+
}
|
|
12218
|
+
if (message.role === "reasoning") {
|
|
12219
|
+
return {
|
|
12220
|
+
index,
|
|
12221
|
+
role: message.role,
|
|
12222
|
+
content: truncateText2(message.content ?? "", DEBUG_MAX_CONTENT_CHARS)
|
|
12223
|
+
};
|
|
12224
|
+
}
|
|
12225
|
+
return {
|
|
12226
|
+
index,
|
|
12227
|
+
role: message.role,
|
|
12228
|
+
content: contentToDebugText(message.content, DEBUG_MAX_CONTENT_CHARS)
|
|
12229
|
+
};
|
|
12230
|
+
});
|
|
12231
|
+
return truncateText2(stringifyUnknown(payload), DEBUG_MAX_LOG_CHARS);
|
|
12232
|
+
};
|
|
12233
|
+
var logCompactionSnapshot = (log2, runId, runtimeAgent, compacted) => {
|
|
12234
|
+
if (!isDebugEnabled()) return;
|
|
12235
|
+
const messages = runtimeAgent.getHistoryMessages();
|
|
12236
|
+
const snapshot = buildCompactionSnapshotLog(messages);
|
|
12237
|
+
log2(
|
|
12238
|
+
`compaction context snapshot run_id=${runId} compacted=${String(compacted)} messages=${messages.length} history=${snapshot}`
|
|
12239
|
+
);
|
|
12240
|
+
};
|
|
12241
|
+
var isTrackedRunEvent = (eventType) => eventType === "tool_call" || eventType === "tool_result" || eventType === "step_start" || eventType === "step_complete" || eventType === "final";
|
|
12242
|
+
var summarizeRunEvent = (event) => {
|
|
12243
|
+
switch (event.type) {
|
|
12244
|
+
case "tool_call": {
|
|
12245
|
+
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
12246
|
+
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
12247
|
+
const rawArgs = typeof event.raw_args === "string" ? event.raw_args : stringifyUnknown(event.args);
|
|
12248
|
+
const rawArgsSnippet = truncateText2(rawArgs, DEBUG_MAX_EVENT_ARGS_CHARS);
|
|
12249
|
+
return `type=tool_call tool=${tool} tool_call_id=${toolCallId} raw_args=${stringifyUnknown(rawArgsSnippet)}`;
|
|
12250
|
+
}
|
|
12251
|
+
case "tool_result": {
|
|
12252
|
+
const tool = typeof event.tool === "string" ? event.tool : "unknown";
|
|
12253
|
+
const toolCallId = typeof event.tool_call_id === "string" ? event.tool_call_id : "unknown";
|
|
12254
|
+
const isError = event.is_error === true;
|
|
12255
|
+
const result = typeof event.result === "string" ? truncateText2(event.result, DEBUG_MAX_EVENT_RESULT_CHARS) : truncateText2(
|
|
12256
|
+
stringifyUnknown(event.result),
|
|
12257
|
+
DEBUG_MAX_EVENT_RESULT_CHARS
|
|
12258
|
+
);
|
|
12259
|
+
return `type=tool_result tool=${tool} tool_call_id=${toolCallId} is_error=${String(isError)} result=${stringifyUnknown(result)}`;
|
|
12260
|
+
}
|
|
12261
|
+
case "step_start": {
|
|
12262
|
+
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
12263
|
+
const title = typeof event.title === "string" ? event.title : "unknown";
|
|
12264
|
+
return `type=step_start step_id=${stepId} title=${title}`;
|
|
12265
|
+
}
|
|
12266
|
+
case "step_complete": {
|
|
12267
|
+
const stepId = typeof event.step_id === "string" ? event.step_id : "unknown";
|
|
12268
|
+
const status = typeof event.status === "string" ? event.status : "unknown";
|
|
12269
|
+
const durationMs = typeof event.duration_ms === "number" ? event.duration_ms : -1;
|
|
12270
|
+
return `type=step_complete step_id=${stepId} status=${status} duration_ms=${durationMs}`;
|
|
12271
|
+
}
|
|
12272
|
+
case "final": {
|
|
12273
|
+
const content = typeof event.content === "string" ? event.content : "";
|
|
12274
|
+
return `type=final content_chars=${content.length}`;
|
|
12275
|
+
}
|
|
12276
|
+
default:
|
|
12277
|
+
return `type=${event.type}`;
|
|
12278
|
+
}
|
|
12279
|
+
};
|
|
12280
|
+
var logRunDebug = (log2, runId, message) => {
|
|
12281
|
+
if (!isDebugEnabled()) return;
|
|
12282
|
+
log2(`run debug run_id=${runId} ${message}`);
|
|
12283
|
+
};
|
|
12284
|
+
var normalizeToolCallHistory = (messages) => {
|
|
12285
|
+
const assistantCallIds = /* @__PURE__ */ new Set();
|
|
12286
|
+
const toolOutputCallIds = /* @__PURE__ */ new Set();
|
|
12287
|
+
for (const message of messages) {
|
|
12288
|
+
if (message.role === "assistant") {
|
|
12289
|
+
for (const call of message.tool_calls ?? []) {
|
|
12290
|
+
assistantCallIds.add(call.id);
|
|
12291
|
+
}
|
|
12292
|
+
continue;
|
|
12293
|
+
}
|
|
12294
|
+
if (message.role === "tool") {
|
|
12295
|
+
toolOutputCallIds.add(message.tool_call_id);
|
|
12296
|
+
}
|
|
12129
12297
|
}
|
|
12130
|
-
if (
|
|
12131
|
-
|
|
12298
|
+
if (assistantCallIds.size === 0 && toolOutputCallIds.size === 0) {
|
|
12299
|
+
return messages;
|
|
12132
12300
|
}
|
|
12133
|
-
|
|
12134
|
-
|
|
12301
|
+
const validCallIds = /* @__PURE__ */ new Set();
|
|
12302
|
+
for (const callId of assistantCallIds) {
|
|
12303
|
+
if (toolOutputCallIds.has(callId)) {
|
|
12304
|
+
validCallIds.add(callId);
|
|
12305
|
+
}
|
|
12135
12306
|
}
|
|
12136
|
-
if (
|
|
12137
|
-
|
|
12138
|
-
`Current model: ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12139
|
-
);
|
|
12307
|
+
if (validCallIds.size === assistantCallIds.size && validCallIds.size === toolOutputCallIds.size) {
|
|
12308
|
+
return messages;
|
|
12140
12309
|
}
|
|
12141
|
-
const detailLines = [];
|
|
12142
12310
|
let changed = false;
|
|
12143
|
-
|
|
12144
|
-
|
|
12145
|
-
|
|
12146
|
-
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12311
|
+
const normalized = [];
|
|
12312
|
+
for (const message of messages) {
|
|
12313
|
+
if (message.role === "assistant") {
|
|
12314
|
+
const calls = message.tool_calls ?? [];
|
|
12315
|
+
if (calls.length > 0) {
|
|
12316
|
+
const filteredCalls = calls.filter((call) => validCallIds.has(call.id));
|
|
12317
|
+
if (filteredCalls.length !== calls.length) {
|
|
12318
|
+
changed = true;
|
|
12319
|
+
if (filteredCalls.length === 0) {
|
|
12320
|
+
const next = { ...message };
|
|
12321
|
+
delete next.tool_calls;
|
|
12322
|
+
normalized.push(next);
|
|
12323
|
+
} else {
|
|
12324
|
+
normalized.push({ ...message, tool_calls: filteredCalls });
|
|
12325
|
+
}
|
|
12326
|
+
continue;
|
|
12327
|
+
}
|
|
12152
12328
|
}
|
|
12153
|
-
|
|
12329
|
+
normalized.push(message);
|
|
12330
|
+
continue;
|
|
12331
|
+
}
|
|
12332
|
+
if (message.role === "tool" && !validCallIds.has(message.tool_call_id)) {
|
|
12154
12333
|
changed = true;
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
|
|
12162
|
-
|
|
12334
|
+
continue;
|
|
12335
|
+
}
|
|
12336
|
+
normalized.push(message);
|
|
12337
|
+
}
|
|
12338
|
+
return changed ? normalized : messages;
|
|
12339
|
+
};
|
|
12340
|
+
var formatErrorForDebugLog = (error) => {
|
|
12341
|
+
const parts = [];
|
|
12342
|
+
parts.push(`name=${error.name}`);
|
|
12343
|
+
parts.push(
|
|
12344
|
+
`message=${truncateText2(error.message, DEBUG_ERROR_MESSAGE_MAX_CHARS)}`
|
|
12345
|
+
);
|
|
12346
|
+
if (error.stack) {
|
|
12347
|
+
parts.push(
|
|
12348
|
+
`stack=${truncateText2(error.stack, DEBUG_ERROR_STACK_MAX_CHARS)}`
|
|
12163
12349
|
);
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12350
|
+
}
|
|
12351
|
+
const causeChain = [];
|
|
12352
|
+
let depth = 0;
|
|
12353
|
+
let current = error.cause;
|
|
12354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12355
|
+
while (current !== void 0 && current !== null && depth < 4) {
|
|
12356
|
+
if (seen.has(current)) {
|
|
12357
|
+
causeChain.push("[circular]");
|
|
12358
|
+
break;
|
|
12359
|
+
}
|
|
12360
|
+
seen.add(current);
|
|
12361
|
+
if (current instanceof Error) {
|
|
12362
|
+
causeChain.push(`${current.name}: ${current.message}`);
|
|
12363
|
+
current = current.cause;
|
|
12364
|
+
depth += 1;
|
|
12365
|
+
continue;
|
|
12366
|
+
}
|
|
12367
|
+
causeChain.push(stringifyUnknown(current));
|
|
12368
|
+
break;
|
|
12369
|
+
}
|
|
12370
|
+
if (causeChain.length > 0) {
|
|
12371
|
+
parts.push(
|
|
12372
|
+
`cause_chain=${truncateText2(causeChain.join(" <- "), DEBUG_ERROR_CHAIN_MAX_CHARS)}`
|
|
12168
12373
|
);
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12374
|
+
}
|
|
12375
|
+
const extras = Object.entries(
|
|
12376
|
+
error
|
|
12377
|
+
).filter(([key]) => key !== "name" && key !== "message" && key !== "stack");
|
|
12378
|
+
if (extras.length > 0) {
|
|
12379
|
+
parts.push(
|
|
12380
|
+
`extras=${truncateText2(
|
|
12381
|
+
stringifyUnknown(Object.fromEntries(extras)),
|
|
12382
|
+
DEBUG_ERROR_EXTRAS_MAX_CHARS
|
|
12383
|
+
)}`
|
|
12173
12384
|
);
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12385
|
+
}
|
|
12386
|
+
return parts.join(" ");
|
|
12387
|
+
};
|
|
12388
|
+
var summarizeProviderMeta = (value) => {
|
|
12389
|
+
if (value === null || value === void 0) {
|
|
12390
|
+
return null;
|
|
12391
|
+
}
|
|
12392
|
+
if (typeof value === "string") {
|
|
12393
|
+
return value.length > DEBUG_PROVIDER_META_STRING_MAX_CHARS ? `${value.slice(0, DEBUG_PROVIDER_META_STRING_MAX_CHARS - 3)}...` : value;
|
|
12394
|
+
}
|
|
12395
|
+
if (Array.isArray(value)) {
|
|
12396
|
+
return `array(len=${value.length})`;
|
|
12397
|
+
}
|
|
12398
|
+
if (typeof value === "object") {
|
|
12399
|
+
const obj = value;
|
|
12400
|
+
const details = [];
|
|
12401
|
+
if (typeof obj.transport === "string") {
|
|
12402
|
+
details.push(`transport=${obj.transport}`);
|
|
12179
12403
|
}
|
|
12180
|
-
if (
|
|
12181
|
-
|
|
12182
|
-
detailLines.push(
|
|
12183
|
-
`Model changed: ${savedContext.model_provider ?? "(unknown provider)"}/${savedContext.model_name ?? "(unknown model)"} -> ${currentModelProvider ?? "(unknown provider)"}/${currentModelName ?? "(unknown model)"}`
|
|
12184
|
-
);
|
|
12404
|
+
if (typeof obj.websocket_mode === "string") {
|
|
12405
|
+
details.push(`websocket_mode=${obj.websocket_mode}`);
|
|
12185
12406
|
}
|
|
12186
|
-
if (
|
|
12187
|
-
|
|
12188
|
-
"Initial AGENTS",
|
|
12189
|
-
savedContext.initial_agents ?? [],
|
|
12190
|
-
currentAgents
|
|
12191
|
-
);
|
|
12192
|
-
if (agentDiffs.length > 0) {
|
|
12193
|
-
changed = true;
|
|
12194
|
-
detailLines.push(...agentDiffs);
|
|
12195
|
-
}
|
|
12407
|
+
if (typeof obj.response_id === "string") {
|
|
12408
|
+
details.push(`response_id=${obj.response_id}`);
|
|
12196
12409
|
}
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
currentLoadedSkills
|
|
12200
|
-
);
|
|
12201
|
-
if (skillDiffs.length > 0) {
|
|
12202
|
-
changed = true;
|
|
12203
|
-
detailLines.push(...skillDiffs);
|
|
12410
|
+
if (typeof obj.chain_reset === "boolean") {
|
|
12411
|
+
details.push(`chain_reset=${obj.chain_reset ? "true" : "false"}`);
|
|
12204
12412
|
}
|
|
12205
|
-
if (
|
|
12206
|
-
|
|
12207
|
-
|
|
12413
|
+
if (typeof obj.fallback_used === "boolean") {
|
|
12414
|
+
details.push(`fallback_used=${obj.fallback_used ? "true" : "false"}`);
|
|
12415
|
+
}
|
|
12416
|
+
if (typeof obj.ws_input_mode === "string") {
|
|
12417
|
+
details.push(`ws_input_mode=${obj.ws_input_mode}`);
|
|
12418
|
+
}
|
|
12419
|
+
if (typeof obj.reasoning_requested === "string") {
|
|
12420
|
+
details.push(`reasoning_requested=${obj.reasoning_requested}`);
|
|
12421
|
+
}
|
|
12422
|
+
if (typeof obj.reasoning_applied === "string") {
|
|
12423
|
+
details.push(`reasoning_applied=${obj.reasoning_applied}`);
|
|
12424
|
+
}
|
|
12425
|
+
if (typeof obj.reasoning_fallback === "boolean") {
|
|
12426
|
+
details.push(
|
|
12427
|
+
`reasoning_fallback=${obj.reasoning_fallback ? "true" : "false"}`
|
|
12208
12428
|
);
|
|
12209
12429
|
}
|
|
12430
|
+
if (typeof obj.reasoning_budget_preset === "string") {
|
|
12431
|
+
details.push(`reasoning_budget_preset=${obj.reasoning_budget_preset}`);
|
|
12432
|
+
}
|
|
12433
|
+
if (details.length > 0) {
|
|
12434
|
+
return details.join(" ");
|
|
12435
|
+
}
|
|
12436
|
+
const keys = Object.keys(obj);
|
|
12437
|
+
if (keys.length === 0) return "object";
|
|
12438
|
+
const shown = keys.slice(0, 4).join(",");
|
|
12439
|
+
return keys.length > 4 ? `object(keys=${shown},...)` : `object(keys=${shown})`;
|
|
12210
12440
|
}
|
|
12211
|
-
|
|
12212
|
-
return null;
|
|
12213
|
-
}
|
|
12214
|
-
const summaryLines = [
|
|
12215
|
-
"Resume context:",
|
|
12216
|
-
...contextLines.map((line) => `- ${line}`),
|
|
12217
|
-
...detailLines.map((line) => `- ${line}`)
|
|
12218
|
-
];
|
|
12219
|
-
const systemLines = [
|
|
12220
|
-
'<system-reminder type="session.resume.diff">',
|
|
12221
|
-
"Session resumed in current runtime context:",
|
|
12222
|
-
...contextLines.map((line) => `- ${line}`),
|
|
12223
|
-
...detailLines.map((line) => `- ${line}`),
|
|
12224
|
-
"Use the current runtime/workspace context for subsequent actions.",
|
|
12225
|
-
"</system-reminder>"
|
|
12226
|
-
];
|
|
12227
|
-
return {
|
|
12228
|
-
summary: summaryLines.join("\n"),
|
|
12229
|
-
systemReminder: systemLines.join("\n"),
|
|
12230
|
-
changed
|
|
12231
|
-
};
|
|
12441
|
+
return typeof value;
|
|
12232
12442
|
};
|
|
12443
|
+
var isAbortLikeError = (error) => error.name === "AbortError" || error.name === "APIUserAbortError" || error.name === "AbortSignal" || /aborted|abort/i.test(error.message);
|
|
12233
12444
|
|
|
12234
12445
|
// src/rpc/skill-mentions.ts
|
|
12235
12446
|
var SKILL_MENTION_PATTERN = /\$([a-z0-9]+(?:-[a-z0-9]+)*)/g;
|
|
@@ -12570,6 +12781,24 @@ var createRunHandlers = ({
|
|
|
12570
12781
|
};
|
|
12571
12782
|
}
|
|
12572
12783
|
const runId = state.nextRunId();
|
|
12784
|
+
let clientTools;
|
|
12785
|
+
try {
|
|
12786
|
+
clientTools = createClientToolAdapters({
|
|
12787
|
+
runId,
|
|
12788
|
+
tools: params.tools,
|
|
12789
|
+
state,
|
|
12790
|
+
existingTools: state.tools ?? []
|
|
12791
|
+
});
|
|
12792
|
+
state.autoApprovedClientToolNames = new Set(
|
|
12793
|
+
(params.tools ?? []).filter((tool) => tool.approval === "never").map((tool) => tool.name)
|
|
12794
|
+
);
|
|
12795
|
+
} catch (error) {
|
|
12796
|
+
sendError(id, {
|
|
12797
|
+
code: RPC_ERROR_CODE4.INVALID_PARAMS,
|
|
12798
|
+
message: String(error)
|
|
12799
|
+
});
|
|
12800
|
+
return;
|
|
12801
|
+
}
|
|
12573
12802
|
const startedAt = nowIso5();
|
|
12574
12803
|
state.beginRun(runId, params.ui_context ?? state.lastUiContext);
|
|
12575
12804
|
const runAbortController = new AbortController();
|
|
@@ -12700,10 +12929,17 @@ var createRunHandlers = ({
|
|
|
12700
12929
|
model: modelConfig ? {
|
|
12701
12930
|
provider: modelConfig.provider,
|
|
12702
12931
|
name: modelConfig.name,
|
|
12703
|
-
reasoning: modelConfig.reasoning
|
|
12932
|
+
reasoning: modelConfig.reasoning,
|
|
12933
|
+
...modelConfig.fast !== void 0 ? { fast: modelConfig.fast } : {}
|
|
12704
12934
|
} : void 0,
|
|
12705
12935
|
prompts: state.systemPrompt ? { system: state.systemPrompt } : void 0,
|
|
12706
|
-
tools: state.toolDefinitions ? {
|
|
12936
|
+
tools: state.toolDefinitions ? {
|
|
12937
|
+
definitions: [
|
|
12938
|
+
...state.toolDefinitions,
|
|
12939
|
+
...clientTools.map((tool) => tool.definition)
|
|
12940
|
+
],
|
|
12941
|
+
source: clientTools.length ? "runtime+client" : "runtime"
|
|
12942
|
+
} : void 0,
|
|
12707
12943
|
runtime: {
|
|
12708
12944
|
cwd: state.lastUiContext?.cwd,
|
|
12709
12945
|
os: process.platform,
|
|
@@ -12757,7 +12993,10 @@ var createRunHandlers = ({
|
|
|
12757
12993
|
);
|
|
12758
12994
|
const workspaceRoot = resolveSessionWorkspaceRoot(state);
|
|
12759
12995
|
const sessionMetaWithWorkspace = mergeWorkspaceRootIntoSessionMeta(sessionMeta, workspaceRoot);
|
|
12760
|
-
const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(
|
|
12996
|
+
const sessionMetaWithResumeContext = mergeResumeContextIntoSessionMeta(
|
|
12997
|
+
sessionMetaWithWorkspace,
|
|
12998
|
+
state
|
|
12999
|
+
);
|
|
12761
13000
|
const snapshot = buildSessionState(
|
|
12762
13001
|
sessionId,
|
|
12763
13002
|
runId,
|
|
@@ -12790,7 +13029,9 @@ var createRunHandlers = ({
|
|
|
12790
13029
|
for await (const event of runtimeAgent.runStream(normalizedInput, {
|
|
12791
13030
|
session,
|
|
12792
13031
|
signal: runAbortController.signal,
|
|
12793
|
-
forceCompaction: params.force_compaction
|
|
13032
|
+
forceCompaction: params.force_compaction,
|
|
13033
|
+
tools: clientTools,
|
|
13034
|
+
toolChoice: params.tool_choice
|
|
12794
13035
|
})) {
|
|
12795
13036
|
if (state.cancelRequested) {
|
|
12796
13037
|
break;
|
|
@@ -14492,6 +14733,7 @@ var RuntimeState = class {
|
|
|
14492
14733
|
executionEnvironmentDebugLogged = false;
|
|
14493
14734
|
toolDefinitions = null;
|
|
14494
14735
|
tools = null;
|
|
14736
|
+
autoApprovedClientToolNames = /* @__PURE__ */ new Set();
|
|
14495
14737
|
sessionId = null;
|
|
14496
14738
|
sessionMeta = null;
|
|
14497
14739
|
sessionAppend = null;
|
|
@@ -14527,6 +14769,7 @@ var RuntimeState = class {
|
|
|
14527
14769
|
}
|
|
14528
14770
|
this.cancelRequested = false;
|
|
14529
14771
|
this.lastContextLeftPercent = null;
|
|
14772
|
+
this.autoApprovedClientToolNames.clear();
|
|
14530
14773
|
this.runSeq.delete(runId);
|
|
14531
14774
|
if (this.activeRunId === null) {
|
|
14532
14775
|
this.sessionAppend = null;
|