@codelia/runtime 0.1.91 → 0.1.93
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/{chunk-X4222JDX.js → chunk-K42SQONI.js} +265 -36
- package/dist/{chunk-EC2N4PCP.js → chunk-OQGZHVYU.js} +781 -627
- package/dist/index.cjs +1036 -661
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +1036 -661
- package/dist/sdk.d.cts +2 -0
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.js +2 -2
- package/dist/subagents/child-entry.cjs +273 -20
- package/dist/subagents/child-entry.js +1 -1
- package/package.json +12 -12
|
@@ -111,9 +111,21 @@ var resolveTuiConfig = async (workingDir) => {
|
|
|
111
111
|
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
112
112
|
const effective = configRegistry.resolve([globalConfig, projectConfig]);
|
|
113
113
|
return {
|
|
114
|
-
theme: effective.tui
|
|
114
|
+
...effective.tui?.theme ? { theme: effective.tui.theme } : {},
|
|
115
|
+
...effective.tui?.color_scheme ? { color_scheme: effective.tui.color_scheme } : {},
|
|
116
|
+
...effective.tui?.image_protocol ? { image_protocol: effective.tui.image_protocol } : {}
|
|
115
117
|
};
|
|
116
118
|
};
|
|
119
|
+
var resolveAgentsEnabled = async (workingDir) => {
|
|
120
|
+
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
121
|
+
const effective = configRegistry.resolve([globalConfig, projectConfig]);
|
|
122
|
+
return effective.agents?.enabled ?? true;
|
|
123
|
+
};
|
|
124
|
+
var resolveAuthOAuthBrowser = async (workingDir) => {
|
|
125
|
+
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
126
|
+
const effective = configRegistry.resolve([globalConfig, projectConfig]);
|
|
127
|
+
return effective.auth?.oauth_browser;
|
|
128
|
+
};
|
|
117
129
|
var resolvePermissionsConfig = async (workingDir) => {
|
|
118
130
|
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
119
131
|
const effective = configRegistry.resolve([globalConfig, projectConfig]);
|
|
@@ -294,7 +306,7 @@ var hasDefinedGroup = (group, value) => {
|
|
|
294
306
|
case "permissions":
|
|
295
307
|
return Array.isArray(value?.permissions?.allow) || Array.isArray(value?.permissions?.deny);
|
|
296
308
|
case "tui":
|
|
297
|
-
return typeof value?.tui?.theme === "string" && value.tui.theme.trim().length > 0;
|
|
309
|
+
return typeof value?.tui?.theme === "string" && value.tui.theme.trim().length > 0 || value?.tui?.color_scheme !== void 0 || value?.tui?.image_protocol !== void 0;
|
|
298
310
|
default:
|
|
299
311
|
return false;
|
|
300
312
|
}
|
|
@@ -437,6 +449,8 @@ var sendNotificationAsync = async (state, notify) => {
|
|
|
437
449
|
}
|
|
438
450
|
await sendAsync(notify);
|
|
439
451
|
};
|
|
452
|
+
var transportBackpressureEvents = 0;
|
|
453
|
+
var getTransportBackpressureEvents = () => transportBackpressureEvents;
|
|
440
454
|
var send = (msg) => {
|
|
441
455
|
const { payload, label } = serializeMessage(msg);
|
|
442
456
|
const writable = process.stdout.write(payload, (error) => {
|
|
@@ -445,6 +459,7 @@ var send = (msg) => {
|
|
|
445
459
|
}
|
|
446
460
|
});
|
|
447
461
|
if (!writable) {
|
|
462
|
+
transportBackpressureEvents += 1;
|
|
448
463
|
debugLog(`transport.backpressure label=${label} bytes=${payload.length}`);
|
|
449
464
|
}
|
|
450
465
|
};
|
|
@@ -459,6 +474,7 @@ var sendAsync = async (msg) => new Promise((resolve) => {
|
|
|
459
474
|
resolve();
|
|
460
475
|
});
|
|
461
476
|
if (!writable) {
|
|
477
|
+
transportBackpressureEvents += 1;
|
|
462
478
|
debugLog(`transport.backpressure label=${label} bytes=${payload.length}`);
|
|
463
479
|
}
|
|
464
480
|
});
|
|
@@ -508,12 +524,12 @@ var sendRunContext = (state, runId, contextLeftPercent) => {
|
|
|
508
524
|
})
|
|
509
525
|
);
|
|
510
526
|
};
|
|
511
|
-
var sendRunDiagnostics = (state, params) => {
|
|
512
|
-
sendNotification(state, notificationMessage("run.diagnostics", params));
|
|
513
|
-
};
|
|
514
527
|
var sendRunMetrics = (state, params) => {
|
|
515
528
|
sendNotification(state, notificationMessage("run.metrics", params));
|
|
516
529
|
};
|
|
530
|
+
var sendRunSummary = (state, params) => {
|
|
531
|
+
sendNotification(state, notificationMessage("run.summary", params));
|
|
532
|
+
};
|
|
517
533
|
|
|
518
534
|
// src/rpc/protocol.ts
|
|
519
535
|
var MAX_ISSUES = 10;
|
|
@@ -529,8 +545,18 @@ var schemaFor = (method, slot) => {
|
|
|
529
545
|
throw new Error(`${method} is a notification without a result`);
|
|
530
546
|
return spec.result;
|
|
531
547
|
};
|
|
548
|
+
var cachedProtocolAssertRaw;
|
|
549
|
+
var cachedProtocolAssertEnabled = false;
|
|
550
|
+
var isProtocolAssertEnabled = () => {
|
|
551
|
+
const raw = process.env.CODELIA_TEST_PROTOCOL_ASSERT;
|
|
552
|
+
if (raw !== cachedProtocolAssertRaw) {
|
|
553
|
+
cachedProtocolAssertRaw = raw;
|
|
554
|
+
cachedProtocolAssertEnabled = raw === "1";
|
|
555
|
+
}
|
|
556
|
+
return cachedProtocolAssertEnabled;
|
|
557
|
+
};
|
|
532
558
|
var assertOutgoing = (method, slot, value) => {
|
|
533
|
-
if (
|
|
559
|
+
if (!isProtocolAssertEnabled()) return;
|
|
534
560
|
const result = schemaFor(method, slot).safeParse(value);
|
|
535
561
|
if (!result.success)
|
|
536
562
|
throw new Error(
|
|
@@ -671,14 +697,14 @@ var readBrowserMode = (value) => {
|
|
|
671
697
|
return null;
|
|
672
698
|
};
|
|
673
699
|
var hasSshSession = (env) => !!env.SSH_CONNECTION || !!env.SSH_CLIENT || !!env.SSH_TTY;
|
|
674
|
-
var resolveOAuthBrowserMode = (env = process.env) => {
|
|
675
|
-
const configured = readBrowserMode(
|
|
700
|
+
var resolveOAuthBrowserMode = (configuredMode, env = process.env) => {
|
|
701
|
+
const configured = readBrowserMode(configuredMode);
|
|
676
702
|
if (configured) {
|
|
677
703
|
return configured;
|
|
678
704
|
}
|
|
679
705
|
return hasSshSession(env) ? "manual" : "auto";
|
|
680
706
|
};
|
|
681
|
-
var shouldAutoOpenOAuthBrowser = (env = process.env) => resolveOAuthBrowserMode(env) === "auto";
|
|
707
|
+
var shouldAutoOpenOAuthBrowser = (configuredMode, env = process.env) => resolveOAuthBrowserMode(configuredMode, env) === "auto";
|
|
682
708
|
var parseCallbackParams = (input) => {
|
|
683
709
|
const trimmed = input.trim();
|
|
684
710
|
if (!trimmed) {
|
|
@@ -851,7 +877,7 @@ var OPENAI_OAUTH_ORIGINATOR = "codelia";
|
|
|
851
877
|
var OPENAI_OAUTH_USER_AGENT = "codelia-cli";
|
|
852
878
|
var HTML_SUCCESS = "<!doctype html><html><head><title>codelia - Authorization successful</title></head><body><h2>Authorization successful</h2><p>You can close this window.</p></body></html>";
|
|
853
879
|
var HTML_ERROR = (message) => `<!doctype html><html><head><title>codelia - Authorization failed</title></head><body><h2>Authorization failed</h2><pre>${message}</pre></body></html>`;
|
|
854
|
-
var clientId = () =>
|
|
880
|
+
var clientId = () => DEFAULT_CLIENT_ID;
|
|
855
881
|
var oauthPort = () => readPositiveIntEnv("CODELIA_OPENAI_OAUTH_PORT", DEFAULT_PORT);
|
|
856
882
|
var buildAuthorizeUrl = (redirectUri, pkce, state) => {
|
|
857
883
|
const params = new URLSearchParams({
|
|
@@ -1075,11 +1101,8 @@ var DEFAULT_CLIENT_ID2 = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
|
1075
1101
|
var ISSUER2 = "https://auth.openai.com";
|
|
1076
1102
|
var DEFAULT_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
1077
1103
|
var DEFAULT_INTERVAL_SECONDS = 5;
|
|
1078
|
-
var clientId2 = () =>
|
|
1079
|
-
var deviceCodeTimeoutMs = () =>
|
|
1080
|
-
"CODELIA_OPENAI_DEVICE_CODE_TIMEOUT_MS",
|
|
1081
|
-
DEFAULT_TIMEOUT_MS
|
|
1082
|
-
);
|
|
1104
|
+
var clientId2 = () => DEFAULT_CLIENT_ID2;
|
|
1105
|
+
var deviceCodeTimeoutMs = () => DEFAULT_TIMEOUT_MS;
|
|
1083
1106
|
var cancelledError = () => new Error("device code login cancelled");
|
|
1084
1107
|
var sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
1085
1108
|
if (signal?.aborted) {
|
|
@@ -1795,7 +1818,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
1795
1818
|
if (!supportsPick || !supportsPrompt) {
|
|
1796
1819
|
throw new Error("UI does not support auth prompts");
|
|
1797
1820
|
}
|
|
1798
|
-
const
|
|
1821
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
1822
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
1823
|
+
).catch(() => void 0);
|
|
1824
|
+
const prefersDeviceCode = resolveOAuthBrowserMode(configuredBrowser) === "manual";
|
|
1799
1825
|
const pick = await requestUiPick(this.state, {
|
|
1800
1826
|
title: "How would you like to connect OpenAI?",
|
|
1801
1827
|
items: prefersDeviceCode ? [
|
|
@@ -1854,7 +1880,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
1854
1880
|
throw new Error("UI does not support device code confirmation");
|
|
1855
1881
|
}
|
|
1856
1882
|
const session = await createOpenAiDeviceCodeSession();
|
|
1857
|
-
const
|
|
1883
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
1884
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
1885
|
+
).catch(() => void 0);
|
|
1886
|
+
const shouldAutoOpen = shouldAutoOpenOAuthBrowser(configuredBrowser);
|
|
1858
1887
|
const confirm = await requestUiConfirm(this.state, {
|
|
1859
1888
|
title: "OpenAI device code",
|
|
1860
1889
|
message: [
|
|
@@ -1897,7 +1926,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
1897
1926
|
if (!supportsConfirm) {
|
|
1898
1927
|
throw new Error("UI does not support OAuth confirmation");
|
|
1899
1928
|
}
|
|
1900
|
-
const
|
|
1929
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
1930
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
1931
|
+
).catch(() => void 0);
|
|
1932
|
+
const shouldAutoOpen = shouldAutoOpenOAuthBrowser(configuredBrowser);
|
|
1901
1933
|
const canPasteCallback = !shouldAutoOpen && supportsPrompt;
|
|
1902
1934
|
const session = await createOAuthSession({
|
|
1903
1935
|
callbackMode: canPasteCallback ? "paste" : "server"
|
|
@@ -5212,6 +5244,7 @@ import {
|
|
|
5212
5244
|
ZAI_DEFAULT_MODEL,
|
|
5213
5245
|
ZAI_REASONING_EFFORT_MODELS
|
|
5214
5246
|
} from "@codelia/core";
|
|
5247
|
+
import { isDebugEnabled as isDebugEnabled2 } from "@codelia/logger";
|
|
5215
5248
|
import { ModelMetadataServiceImpl } from "@codelia/model-metadata";
|
|
5216
5249
|
import { StoragePathServiceImpl as StoragePathServiceImpl2 } from "@codelia/storage";
|
|
5217
5250
|
|
|
@@ -5746,17 +5779,12 @@ var requireApiKeyAuth = (provider, auth) => {
|
|
|
5746
5779
|
}
|
|
5747
5780
|
return auth.api_key;
|
|
5748
5781
|
};
|
|
5749
|
-
var envTruthy = (value) => {
|
|
5750
|
-
if (!value) return false;
|
|
5751
|
-
const normalized = value.trim().toLowerCase();
|
|
5752
|
-
return normalized === "1" || normalized === "true";
|
|
5753
|
-
};
|
|
5754
5782
|
var buildOpenAiClientOptions = (getOpenAiAccessToken, auth, log2) => {
|
|
5755
5783
|
if (auth.method === "api_key") {
|
|
5756
5784
|
return { apiKey: auth.api_key };
|
|
5757
5785
|
}
|
|
5758
5786
|
let accountId = auth.oauth.account_id;
|
|
5759
|
-
const enableDebugHttp =
|
|
5787
|
+
const enableDebugHttp = isDebugEnabled2();
|
|
5760
5788
|
const apiKey = async () => {
|
|
5761
5789
|
if (!getOpenAiAccessToken) {
|
|
5762
5790
|
throw new Error("OpenAI OAuth token refresh is unavailable");
|
|
@@ -6379,9 +6407,6 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
6379
6407
|
const modeFlag = readFlag(args, "--sandbox-mode");
|
|
6380
6408
|
if (modeFlag !== void 0)
|
|
6381
6409
|
return parseMode(modeFlag, "--sandbox-mode", "cli", false);
|
|
6382
|
-
const legacyFlag = readFlag(args, "--approval-mode");
|
|
6383
|
-
if (legacyFlag !== void 0)
|
|
6384
|
-
return parseMode(legacyFlag, "--approval-mode", "cli", true);
|
|
6385
6410
|
if (env.CODELIA_SANDBOX_MODE !== void 0)
|
|
6386
6411
|
return parseMode(
|
|
6387
6412
|
env.CODELIA_SANDBOX_MODE,
|
|
@@ -6389,13 +6414,6 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
6389
6414
|
"env",
|
|
6390
6415
|
false
|
|
6391
6416
|
);
|
|
6392
|
-
if (env.CODELIA_APPROVAL_MODE !== void 0)
|
|
6393
|
-
return parseMode(
|
|
6394
|
-
env.CODELIA_APPROVAL_MODE,
|
|
6395
|
-
"CODELIA_APPROVAL_MODE",
|
|
6396
|
-
"env",
|
|
6397
|
-
true
|
|
6398
|
-
);
|
|
6399
6417
|
const store = input.store ?? new ProjectsPolicyStore();
|
|
6400
6418
|
const projectKey = await fs3.realpath(root).catch((error) => {
|
|
6401
6419
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -6417,6 +6435,213 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
6417
6435
|
return defaultSandboxMode;
|
|
6418
6436
|
};
|
|
6419
6437
|
|
|
6438
|
+
// src/telemetry.ts
|
|
6439
|
+
var MAX_RECENT_CALLS = 64;
|
|
6440
|
+
var MAX_RECENT_TOOLS = 64;
|
|
6441
|
+
var cloneModelUsage = (entry) => ({
|
|
6442
|
+
...entry
|
|
6443
|
+
});
|
|
6444
|
+
var createEmptyTelemetrySummary = () => ({
|
|
6445
|
+
total_calls: 0,
|
|
6446
|
+
total_tokens: 0,
|
|
6447
|
+
total_input_tokens: 0,
|
|
6448
|
+
total_output_tokens: 0,
|
|
6449
|
+
total_output_reasoning_tokens: 0,
|
|
6450
|
+
total_cached_input_tokens: 0,
|
|
6451
|
+
total_cache_creation_tokens: 0,
|
|
6452
|
+
total_input_image_tokens: 0,
|
|
6453
|
+
cache_hit_calls: 0,
|
|
6454
|
+
cache_miss_calls: 0,
|
|
6455
|
+
cache_unknown_calls: 0,
|
|
6456
|
+
total_cost_usd: null,
|
|
6457
|
+
retry_count: 0,
|
|
6458
|
+
retry_wait_ms: 0,
|
|
6459
|
+
tool_calls: 0,
|
|
6460
|
+
tool_errors: 0,
|
|
6461
|
+
tool_exec_ms: 0,
|
|
6462
|
+
tool_approval_wait_ms: 0,
|
|
6463
|
+
compaction_count: 0,
|
|
6464
|
+
compaction_duration_ms: 0,
|
|
6465
|
+
by_model: {}
|
|
6466
|
+
});
|
|
6467
|
+
var cloneTelemetrySummary = (summary) => ({
|
|
6468
|
+
...summary,
|
|
6469
|
+
by_model: Object.fromEntries(
|
|
6470
|
+
Object.entries(summary.by_model).map(([model, entry]) => [
|
|
6471
|
+
model,
|
|
6472
|
+
cloneModelUsage(entry)
|
|
6473
|
+
])
|
|
6474
|
+
)
|
|
6475
|
+
});
|
|
6476
|
+
var applyCallToSummary = (summary, call) => {
|
|
6477
|
+
const usage = call.usage ?? null;
|
|
6478
|
+
const inputTokens = usage?.input_tokens ?? 0;
|
|
6479
|
+
const outputTokens = usage?.output_tokens ?? 0;
|
|
6480
|
+
const reasoningTokens = usage?.output_reasoning_tokens ?? 0;
|
|
6481
|
+
const cachedTokens = usage?.input_cached_tokens ?? 0;
|
|
6482
|
+
const cacheCreationTokens = usage?.input_cache_creation_tokens ?? 0;
|
|
6483
|
+
const imageTokens = usage?.input_image_tokens ?? 0;
|
|
6484
|
+
const totalTokens = usage?.total_tokens ?? 0;
|
|
6485
|
+
const hitState = call.cache?.hit_state ?? (typeof usage?.input_cached_tokens === "number" ? cachedTokens > 0 ? "hit" : "miss" : "unknown");
|
|
6486
|
+
const validCost = typeof call.cost_usd === "number" && Number.isFinite(call.cost_usd) && call.cost_usd >= 0 ? call.cost_usd : null;
|
|
6487
|
+
summary.total_calls += 1;
|
|
6488
|
+
summary.total_tokens += totalTokens;
|
|
6489
|
+
summary.total_input_tokens += inputTokens;
|
|
6490
|
+
summary.total_output_tokens += outputTokens;
|
|
6491
|
+
summary.total_output_reasoning_tokens += reasoningTokens;
|
|
6492
|
+
summary.total_cached_input_tokens += cachedTokens;
|
|
6493
|
+
summary.total_cache_creation_tokens += cacheCreationTokens;
|
|
6494
|
+
summary.total_input_image_tokens += imageTokens;
|
|
6495
|
+
if (hitState === "hit") summary.cache_hit_calls += 1;
|
|
6496
|
+
else if (hitState === "miss") summary.cache_miss_calls += 1;
|
|
6497
|
+
else summary.cache_unknown_calls += 1;
|
|
6498
|
+
if (validCost !== null) {
|
|
6499
|
+
summary.total_cost_usd = (summary.total_cost_usd ?? 0) + validCost;
|
|
6500
|
+
}
|
|
6501
|
+
const modelKey = call.model ?? "unknown";
|
|
6502
|
+
const existing = summary.by_model[modelKey];
|
|
6503
|
+
if (!existing) {
|
|
6504
|
+
summary.by_model[modelKey] = {
|
|
6505
|
+
calls: 1,
|
|
6506
|
+
input_tokens: inputTokens,
|
|
6507
|
+
output_tokens: outputTokens,
|
|
6508
|
+
output_reasoning_tokens: reasoningTokens,
|
|
6509
|
+
cached_input_tokens: cachedTokens,
|
|
6510
|
+
cache_creation_tokens: cacheCreationTokens,
|
|
6511
|
+
input_image_tokens: imageTokens,
|
|
6512
|
+
cache_hit_calls: hitState === "hit" ? 1 : 0,
|
|
6513
|
+
cache_miss_calls: hitState === "miss" ? 1 : 0,
|
|
6514
|
+
cache_unknown_calls: hitState === "unknown" ? 1 : 0,
|
|
6515
|
+
total_tokens: totalTokens,
|
|
6516
|
+
cost_usd: validCost
|
|
6517
|
+
};
|
|
6518
|
+
} else {
|
|
6519
|
+
existing.calls += 1;
|
|
6520
|
+
existing.input_tokens += inputTokens;
|
|
6521
|
+
existing.output_tokens += outputTokens;
|
|
6522
|
+
existing.output_reasoning_tokens += reasoningTokens;
|
|
6523
|
+
existing.cached_input_tokens += cachedTokens;
|
|
6524
|
+
existing.cache_creation_tokens += cacheCreationTokens;
|
|
6525
|
+
existing.input_image_tokens += imageTokens;
|
|
6526
|
+
if (hitState === "hit") existing.cache_hit_calls += 1;
|
|
6527
|
+
else if (hitState === "miss") existing.cache_miss_calls += 1;
|
|
6528
|
+
else existing.cache_unknown_calls += 1;
|
|
6529
|
+
existing.total_tokens += totalTokens;
|
|
6530
|
+
if (validCost !== null) {
|
|
6531
|
+
existing.cost_usd = (existing.cost_usd ?? 0) + validCost;
|
|
6532
|
+
}
|
|
6533
|
+
}
|
|
6534
|
+
};
|
|
6535
|
+
var applyToolToSummary = (summary, record) => {
|
|
6536
|
+
summary.tool_calls += 1;
|
|
6537
|
+
if (record.status === "error") {
|
|
6538
|
+
summary.tool_errors += 1;
|
|
6539
|
+
}
|
|
6540
|
+
summary.tool_exec_ms += Math.max(
|
|
6541
|
+
0,
|
|
6542
|
+
record.exec_duration_ms ?? record.duration_ms
|
|
6543
|
+
);
|
|
6544
|
+
summary.tool_approval_wait_ms += Math.max(0, record.approval_wait_ms ?? 0);
|
|
6545
|
+
};
|
|
6546
|
+
var applyRetryToSummary = (summary, delayMs) => {
|
|
6547
|
+
summary.retry_count += 1;
|
|
6548
|
+
summary.retry_wait_ms += Math.max(0, Math.round(delayMs));
|
|
6549
|
+
};
|
|
6550
|
+
var applyCompactionToSummary = (summary, durationMs) => {
|
|
6551
|
+
summary.compaction_count += 1;
|
|
6552
|
+
summary.compaction_duration_ms += Math.max(0, durationMs);
|
|
6553
|
+
};
|
|
6554
|
+
var RuntimeTelemetryStore = class {
|
|
6555
|
+
sessionSummary = createEmptyTelemetrySummary();
|
|
6556
|
+
currentRunId = null;
|
|
6557
|
+
currentRunSummary = null;
|
|
6558
|
+
recentCalls = [];
|
|
6559
|
+
recentTools = [];
|
|
6560
|
+
startupPhases = [];
|
|
6561
|
+
agentInitPhases = [];
|
|
6562
|
+
resetSession() {
|
|
6563
|
+
this.sessionSummary = createEmptyTelemetrySummary();
|
|
6564
|
+
this.currentRunId = null;
|
|
6565
|
+
this.currentRunSummary = null;
|
|
6566
|
+
this.recentCalls.length = 0;
|
|
6567
|
+
this.recentTools.length = 0;
|
|
6568
|
+
}
|
|
6569
|
+
beginRun(runId) {
|
|
6570
|
+
this.currentRunId = runId;
|
|
6571
|
+
this.currentRunSummary = createEmptyTelemetrySummary();
|
|
6572
|
+
}
|
|
6573
|
+
recordLlmCall(call) {
|
|
6574
|
+
applyCallToSummary(this.sessionSummary, call);
|
|
6575
|
+
if (this.currentRunId === call.run_id && this.currentRunSummary) {
|
|
6576
|
+
applyCallToSummary(this.currentRunSummary, call);
|
|
6577
|
+
}
|
|
6578
|
+
const { session: _session, ...callRecord } = call;
|
|
6579
|
+
this.recentCalls.push(callRecord);
|
|
6580
|
+
if (this.recentCalls.length > MAX_RECENT_CALLS) {
|
|
6581
|
+
this.recentCalls.shift();
|
|
6582
|
+
}
|
|
6583
|
+
}
|
|
6584
|
+
recordToolComplete(record) {
|
|
6585
|
+
applyToolToSummary(this.sessionSummary, record);
|
|
6586
|
+
if (this.currentRunId === record.run_id && this.currentRunSummary) {
|
|
6587
|
+
applyToolToSummary(this.currentRunSummary, record);
|
|
6588
|
+
}
|
|
6589
|
+
this.recentTools.push(record);
|
|
6590
|
+
if (this.recentTools.length > MAX_RECENT_TOOLS) {
|
|
6591
|
+
this.recentTools.shift();
|
|
6592
|
+
}
|
|
6593
|
+
}
|
|
6594
|
+
recordRetry(runId, delayMs) {
|
|
6595
|
+
applyRetryToSummary(this.sessionSummary, delayMs);
|
|
6596
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
6597
|
+
applyRetryToSummary(this.currentRunSummary, delayMs);
|
|
6598
|
+
}
|
|
6599
|
+
}
|
|
6600
|
+
recordRetryWait(runId, waitMs) {
|
|
6601
|
+
const rounded = Math.max(0, Math.round(waitMs));
|
|
6602
|
+
this.sessionSummary.retry_wait_ms += rounded;
|
|
6603
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
6604
|
+
this.currentRunSummary.retry_wait_ms += rounded;
|
|
6605
|
+
}
|
|
6606
|
+
}
|
|
6607
|
+
recordCompaction(runId, durationMs) {
|
|
6608
|
+
applyCompactionToSummary(this.sessionSummary, durationMs);
|
|
6609
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
6610
|
+
applyCompactionToSummary(this.currentRunSummary, durationMs);
|
|
6611
|
+
}
|
|
6612
|
+
}
|
|
6613
|
+
recordStartupPhase(name, durationMs) {
|
|
6614
|
+
this.startupPhases.push({
|
|
6615
|
+
name,
|
|
6616
|
+
duration_ms: Math.max(0, Math.round(durationMs))
|
|
6617
|
+
});
|
|
6618
|
+
}
|
|
6619
|
+
setAgentInitPhases(phases) {
|
|
6620
|
+
this.agentInitPhases = phases.map((phase) => ({
|
|
6621
|
+
name: phase.name,
|
|
6622
|
+
duration_ms: Math.max(0, Math.round(phase.duration_ms))
|
|
6623
|
+
}));
|
|
6624
|
+
}
|
|
6625
|
+
getSessionSummary() {
|
|
6626
|
+
return cloneTelemetrySummary(this.sessionSummary);
|
|
6627
|
+
}
|
|
6628
|
+
getRunSummary() {
|
|
6629
|
+
return this.currentRunSummary ? cloneTelemetrySummary(this.currentRunSummary) : null;
|
|
6630
|
+
}
|
|
6631
|
+
getRecentCalls() {
|
|
6632
|
+
return this.recentCalls.slice();
|
|
6633
|
+
}
|
|
6634
|
+
getRecentTools() {
|
|
6635
|
+
return this.recentTools.slice();
|
|
6636
|
+
}
|
|
6637
|
+
getStartupPhases() {
|
|
6638
|
+
return this.startupPhases.slice();
|
|
6639
|
+
}
|
|
6640
|
+
getAgentInitPhases() {
|
|
6641
|
+
return this.agentInitPhases.slice();
|
|
6642
|
+
}
|
|
6643
|
+
};
|
|
6644
|
+
|
|
6420
6645
|
// src/runtime-state.ts
|
|
6421
6646
|
var RuntimeState = class {
|
|
6422
6647
|
attachments;
|
|
@@ -6549,6 +6774,7 @@ var RuntimeState = class {
|
|
|
6549
6774
|
set sessionId(value) {
|
|
6550
6775
|
if (value === this.boundSessionId) return;
|
|
6551
6776
|
this.boundSessionId = value;
|
|
6777
|
+
this.telemetry.resetSession();
|
|
6552
6778
|
this.receiptOwner.abort();
|
|
6553
6779
|
this.receiptOwner = new AbortController();
|
|
6554
6780
|
this.signalApprovalChange();
|
|
@@ -6612,7 +6838,7 @@ var RuntimeState = class {
|
|
|
6612
6838
|
currentModelName = null;
|
|
6613
6839
|
currentModelSource = null;
|
|
6614
6840
|
sessionModelOverride = null;
|
|
6615
|
-
|
|
6841
|
+
telemetry = new RuntimeTelemetryStore();
|
|
6616
6842
|
setRuntimeEnvironment(options) {
|
|
6617
6843
|
this.effectiveEnvironment = resolveRuntimeEnvironment(options);
|
|
6618
6844
|
const value = this.effectiveEnvironment.workspace.sandboxMode;
|
|
@@ -8934,6 +9160,8 @@ export {
|
|
|
8934
9160
|
resolveModelConfig,
|
|
8935
9161
|
resolveSubagentConfig,
|
|
8936
9162
|
resolveTuiConfig,
|
|
9163
|
+
resolveAgentsEnabled,
|
|
9164
|
+
resolveAuthOAuthBrowser,
|
|
8937
9165
|
resolvePermissionsConfig,
|
|
8938
9166
|
resolveSkillsConfig,
|
|
8939
9167
|
resolveExecutionEnvironmentConfig,
|
|
@@ -8949,13 +9177,14 @@ export {
|
|
|
8949
9177
|
withRpcResponseContext,
|
|
8950
9178
|
hasRpcResponse,
|
|
8951
9179
|
sendNotificationAsync,
|
|
9180
|
+
getTransportBackpressureEvents,
|
|
8952
9181
|
send,
|
|
8953
9182
|
sendError,
|
|
8954
9183
|
sendAgentEvent,
|
|
8955
9184
|
sendRunStatus,
|
|
8956
9185
|
sendRunContext,
|
|
8957
|
-
sendRunDiagnostics,
|
|
8958
9186
|
sendRunMetrics,
|
|
9187
|
+
sendRunSummary,
|
|
8959
9188
|
parseRequestParams,
|
|
8960
9189
|
parseUiNotificationParams,
|
|
8961
9190
|
sendRequestResult,
|