@cortex-agent/server 2026.10.21 → 2026.10.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/defaults/context/projects/AGENTS.md +1 -1
- package/defaults/gitignore +3 -3
- package/defaults/hooks/new-session-hook.mjs +1 -1
- package/defaults/hooks/status-md-guard.mjs +6 -6
- package/defaults/plugins/cortex-system/plugin.json +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
- package/defaults/rules/agents-md.md +1 -1
- package/defaults/rules/issues-md.md +1 -1
- package/defaults/rules/meta-conventions.md +3 -3
- package/defaults/rules/mission-md.md +1 -1
- package/defaults/rules/status-md.md +1 -1
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +3 -1
- package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
- package/dist/agent-adapter/claude/mcp-config.js +11 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +2 -1
- package/dist/agent-adapter/claude/turn-machine.js +8 -5
- package/dist/agent-adapter/continuation-phase.d.ts +6 -3
- package/dist/agent-adapter/continuation-phase.js +8 -3
- package/dist/agent-adapter/run-events.d.ts +4 -0
- package/dist/agent-adapter/types.d.ts +9 -2
- package/dist/build-info.json +1 -0
- package/dist/client-bundle/client.mjs +10 -5
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/claude-credentials.d.ts +6 -0
- package/dist/core/claude-credentials.js +11 -0
- package/dist/core/gateway-generator.d.ts +17 -0
- package/dist/core/gateway-generator.js +42 -4
- package/dist/core/hook-bus.d.ts +1 -1
- package/dist/core/hook-bus.js +1 -8
- package/dist/core/locales/en.d.ts +1 -0
- package/dist/core/locales/slices/init.d.ts +1 -0
- package/dist/core/locales/slices/init.js +2 -0
- package/dist/core/log.d.ts +3 -0
- package/dist/core/log.js +18 -1
- package/dist/core/settings-spec.d.ts +5 -0
- package/dist/core/settings-spec.js +4 -0
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/environment-types.d.ts +1 -6
- package/dist/domain/agents/environments/registry.js +3 -2
- package/dist/domain/agents/environments/schema.d.ts +3 -2
- package/dist/domain/agents/environments/schema.js +4 -3
- package/dist/domain/auth/auth-watch.js +48 -18
- package/dist/domain/mcp/tools/context.d.ts +0 -1
- package/dist/domain/mcp/tools/context.js +0 -1
- package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
- package/dist/domain/monitor/event-loop-monitor.js +5 -1
- package/dist/domain/plugins/authoring.d.ts +8 -1
- package/dist/domain/plugins/authoring.js +24 -9
- package/dist/domain/plugins/runtime-gc.d.ts +7 -0
- package/dist/domain/plugins/runtime-gc.js +52 -19
- package/dist/domain/plugins/runtime.js +2 -1
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-manager.js +6 -1
- package/dist/domain/runs/retryable-errors.js +3 -1
- package/dist/domain/runs/service.d.ts +0 -9
- package/dist/domain/runs/service.js +29 -15
- package/dist/domain/scheduling/builtin-job-controller.d.ts +3 -1
- package/dist/domain/scheduling/builtin-job-controller.js +5 -2
- package/dist/domain/scheduling/builtin-jobs.js +7 -0
- package/dist/domain/scheduling/scheduler.js +14 -5
- package/dist/domain/system/server-update-check.js +2 -1
- package/dist/domain/telemetry/bus-collector.d.ts +3 -0
- package/dist/domain/telemetry/bus-collector.js +22 -0
- package/dist/domain/telemetry/child-exit.d.ts +11 -0
- package/dist/domain/telemetry/child-exit.js +36 -0
- package/dist/domain/telemetry/client-kind.d.ts +4 -0
- package/dist/domain/telemetry/client-kind.js +7 -0
- package/dist/domain/telemetry/crash-limits.d.ts +15 -0
- package/dist/domain/telemetry/crash-limits.js +50 -0
- package/dist/domain/telemetry/crash.d.ts +25 -0
- package/dist/domain/telemetry/crash.js +70 -0
- package/dist/domain/telemetry/daily-upload.d.ts +5 -0
- package/dist/domain/telemetry/daily-upload.js +20 -0
- package/dist/domain/telemetry/daily.d.ts +5 -0
- package/dist/domain/telemetry/daily.js +104 -0
- package/dist/domain/telemetry/endpoint.d.ts +7 -0
- package/dist/domain/telemetry/endpoint.js +40 -0
- package/dist/domain/telemetry/envelope.d.ts +6 -0
- package/dist/domain/telemetry/envelope.js +35 -0
- package/dist/domain/telemetry/error-digest.d.ts +7 -0
- package/dist/domain/telemetry/error-digest.js +43 -0
- package/dist/domain/telemetry/funnel.d.ts +6 -0
- package/dist/domain/telemetry/funnel.js +22 -0
- package/dist/domain/telemetry/gate.d.ts +19 -0
- package/dist/domain/telemetry/gate.js +67 -0
- package/dist/domain/telemetry/heartbeat.d.ts +17 -0
- package/dist/domain/telemetry/heartbeat.js +49 -0
- package/dist/domain/telemetry/info.d.ts +9 -0
- package/dist/domain/telemetry/info.js +12 -0
- package/dist/domain/telemetry/init-answer.d.ts +12 -0
- package/dist/domain/telemetry/init-answer.js +42 -0
- package/dist/domain/telemetry/install-id.d.ts +5 -0
- package/dist/domain/telemetry/install-id.js +42 -0
- package/dist/domain/telemetry/normalize.d.ts +33 -0
- package/dist/domain/telemetry/normalize.js +88 -0
- package/dist/domain/telemetry/outbox.d.ts +18 -0
- package/dist/domain/telemetry/outbox.js +93 -0
- package/dist/domain/telemetry/panic-group.d.ts +4 -0
- package/dist/domain/telemetry/panic-group.js +51 -0
- package/dist/domain/telemetry/paths.d.ts +7 -0
- package/dist/domain/telemetry/paths.js +11 -0
- package/dist/domain/telemetry/redact.d.ts +18 -0
- package/dist/domain/telemetry/redact.js +109 -0
- package/dist/domain/telemetry/rollup-types.d.ts +81 -0
- package/dist/domain/telemetry/rollup-types.js +31 -0
- package/dist/domain/telemetry/rollup.d.ts +16 -0
- package/dist/domain/telemetry/rollup.js +102 -0
- package/dist/domain/telemetry/schema.d.ts +931 -0
- package/dist/domain/telemetry/schema.js +275 -0
- package/dist/domain/telemetry/service.d.ts +34 -0
- package/dist/domain/telemetry/service.js +146 -0
- package/dist/domain/telemetry/state.d.ts +17 -0
- package/dist/domain/telemetry/state.js +29 -0
- package/dist/domain/telemetry/turns.d.ts +17 -0
- package/dist/domain/telemetry/turns.js +176 -0
- package/dist/domain/telemetry/upgrade.d.ts +14 -0
- package/dist/domain/telemetry/upgrade.js +87 -0
- package/dist/domain/telemetry/uploader.d.ts +21 -0
- package/dist/domain/telemetry/uploader.js +82 -0
- package/dist/domain/telemetry/usage.d.ts +25 -0
- package/dist/domain/telemetry/usage.js +153 -0
- package/dist/domain/telemetry/web-report.d.ts +8 -0
- package/dist/domain/telemetry/web-report.js +15 -0
- package/dist/domain/ui-service/app-router.d.ts +69 -25
- package/dist/domain/ui-service/app-router.js +9 -2
- package/dist/domain/ui-service/input-schemas.d.ts +68 -4
- package/dist/domain/ui-service/input-schemas.js +9 -1
- package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
- package/dist/domain/ui-service/mutate/approvals.js +3 -2
- package/dist/domain/ui-service/mutate/plugin-packages.js +1 -1
- package/dist/domain/ui-service/mutate/telemetry.d.ts +5 -0
- package/dist/domain/ui-service/mutate/telemetry.js +6 -0
- package/dist/domain/ui-service/query/approvals.js +4 -3
- package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
- package/dist/domain/ui-service/query/machine-probe.js +3 -2
- package/dist/domain/ui-service/query/models.d.ts +3 -0
- package/dist/domain/ui-service/query/models.js +47 -30
- package/dist/domain/ui-service/query/plugin-source.js +4 -3
- package/dist/domain/ui-service/query/sessions.js +1 -0
- package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
- package/dist/domain/ui-service/query/telemetry.js +4 -0
- package/dist/domain/ui-service/trpc.d.ts +8 -3
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +20 -2
- package/dist/domain/ui-service/ui-service.d.ts +33 -4
- package/dist/domain/ui-service/ui-service.js +19 -18
- package/dist/entry/app.js +20 -2
- package/dist/entry/cli-help.js +27 -14
- package/dist/entry/daemon.d.ts +1 -1
- package/dist/entry/daemon.js +86 -72
- package/dist/entry/init.d.ts +3 -0
- package/dist/entry/init.js +50 -28
- package/dist/entry/shutdown.js +3 -0
- package/dist/entry/signal-cli.js +8 -11
- package/dist/entry/start-ui-http.js +40 -18
- package/dist/entry/telemetry-wiring.d.ts +12 -0
- package/dist/entry/telemetry-wiring.js +56 -0
- package/dist/entry/ui-cli.d.ts +0 -11
- package/dist/entry/ui-cli.js +42 -33
- package/dist/events/event-types.d.ts +1 -4
- package/dist/orchestration/routing/message-router.js +2 -0
- package/dist/orchestration/routing/webhook.js +2 -0
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +17 -0
- package/dist/orchestration/waitpoint-ingress.js +3 -0
- package/dist/platform/ui-http/ui-auth-routes.d.ts +2 -0
- package/dist/platform/ui-http/ui-auth-routes.js +9 -2
- package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
- package/dist/platform/ui-http/ui-device-routes.js +81 -0
- package/dist/platform/ui-http/ui-devices.d.ts +24 -0
- package/dist/platform/ui-http/ui-devices.js +107 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +10 -3
- package/dist/platform/ui-http/ui-http-server.js +11 -7
- package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
- package/dist/platform/ui-http/ui-pairing.js +98 -0
- package/dist/store/gitignore-migration.d.ts +2 -0
- package/dist/store/gitignore-migration.js +16 -0
- package/dist/store/hook-registry.d.ts +1 -1
- package/dist/store/hook-registry.js +11 -6
- package/dist/store/session-registry-journal.js +3 -0
- package/dist/store/version-migrations.d.ts +5 -0
- package/dist/store/version-migrations.js +117 -80
- package/dist/tui/components/Dashboard.js +4 -3
- package/dist/tui/hooks/useDashboardData.js +1 -1
- package/package.json +3 -3
- package/web/dist/assets/{board-math-css-CB4GJ6qO.js → board-math-css-spk7yR6n.js} +1 -1
- package/web/dist/assets/index-BQ69u-92.css +1 -0
- package/web/dist/assets/{index-cIGFv27z.js → index-CKNLatCd.js} +1 -1
- package/web/dist/assets/index-CkzWfC98.js +525 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CaSZPg_H.css +0 -1
- package/web/dist/assets/index-CzOR7Edh.js +0 -522
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { getSettings } from '../../core/settings.js';
|
|
2
|
+
import { classifyAuthError } from '../auth/auth-events.js';
|
|
3
|
+
import { isApiRateLimitError, isRetryableError } from '../runs/retryable-errors.js';
|
|
4
|
+
import { recordFunnelStep } from './funnel.js';
|
|
5
|
+
import { updateRollup } from './rollup.js';
|
|
6
|
+
import { emptyTurnRow } from './rollup-types.js';
|
|
7
|
+
import { bucketIndex } from './schema.js';
|
|
8
|
+
/** Runs that are not conversation turns: cache keep-warm pings and the compact command. */
|
|
9
|
+
const NOT_TURNS = new Set(['cache-refresh', 'manual-compact']);
|
|
10
|
+
export function classifyTurnFailure(message) {
|
|
11
|
+
if (classifyAuthError(message))
|
|
12
|
+
return 'auth';
|
|
13
|
+
if (isApiRateLimitError(message))
|
|
14
|
+
return 'rate_limit';
|
|
15
|
+
if (/tim(?:ed? ?out|eout)/i.test(message))
|
|
16
|
+
return 'timeout';
|
|
17
|
+
if (isRetryableError(new Error(message)))
|
|
18
|
+
return 'network';
|
|
19
|
+
if (/exited with code|process exited|spawn|SIGSEGV|SIGABRT|killed|crash/i.test(message))
|
|
20
|
+
return 'adapter_crash';
|
|
21
|
+
return 'other';
|
|
22
|
+
}
|
|
23
|
+
function billingOf(request) {
|
|
24
|
+
const { backend, mode } = request.selection;
|
|
25
|
+
const settings = getSettings();
|
|
26
|
+
const planModes = backend === 'claude' ? settings.anthropicSubscriptionModes : settings.subscriptionBillingModes;
|
|
27
|
+
return planModes.includes(mode) ? 'plan' : 'api';
|
|
28
|
+
}
|
|
29
|
+
function tool(stats, name) {
|
|
30
|
+
if (!stats.tools.has(name))
|
|
31
|
+
stats.tools.set(name, { calls: 0, errors: 0 });
|
|
32
|
+
return stats.tools.get(name);
|
|
33
|
+
}
|
|
34
|
+
const OUTPUT_EVENTS = new Set(['assistant_text', 'assistant_delta', 'assistant_thinking', 'assistant_thinking_delta', 'tool_use']);
|
|
35
|
+
const SUBAGENT_END = { completed: 'completed', failed: 'failed', killed: 'cancelled' };
|
|
36
|
+
function onToolEvent(stats, event) {
|
|
37
|
+
if (event.type === 'tool_use') {
|
|
38
|
+
stats.toolNames.set(event.toolUseId, event.name);
|
|
39
|
+
tool(stats, event.name).calls += 1;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const name = stats.toolNames.get(event.toolUseId);
|
|
43
|
+
if (name && !event.ok)
|
|
44
|
+
tool(stats, name).errors += 1;
|
|
45
|
+
}
|
|
46
|
+
function onCost(stats, event) {
|
|
47
|
+
stats.tokens.input += event.input_tokens ?? 0;
|
|
48
|
+
stats.tokens.output += event.output_tokens ?? 0;
|
|
49
|
+
stats.tokens.cacheRead += event.cache_read_tokens ?? 0;
|
|
50
|
+
stats.tokens.cacheWrite += event.cache_creation_tokens ?? 0;
|
|
51
|
+
}
|
|
52
|
+
const HANDLERS = {
|
|
53
|
+
tool_use: onToolEvent,
|
|
54
|
+
tool_result: onToolEvent,
|
|
55
|
+
cost_record: onCost,
|
|
56
|
+
context_usage: (stats, event) => { stats.contextPct = event.percent ?? stats.contextPct; },
|
|
57
|
+
context_compacted: (stats, event) => {
|
|
58
|
+
stats.compactions[event.trigger === 'manual' ? 'manual' : 'auto'] += 1;
|
|
59
|
+
},
|
|
60
|
+
model_fallback: (stats) => { stats.fallbacks += 1; },
|
|
61
|
+
error: (stats, event) => { if (!event.fatal)
|
|
62
|
+
stats.retries += 1; },
|
|
63
|
+
subagent_end: (stats, event) => {
|
|
64
|
+
stats.subagents[SUBAGENT_END[event.status] ?? 'failed'] += 1;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
function observe(stats, event) {
|
|
68
|
+
if (stats.firstOutputAt === null && OUTPUT_EVENTS.has(event.type))
|
|
69
|
+
stats.firstOutputAt = Date.now();
|
|
70
|
+
HANDLERS[event.type]?.(stats, event);
|
|
71
|
+
}
|
|
72
|
+
function newStats() {
|
|
73
|
+
return {
|
|
74
|
+
startedAt: Date.now(), firstOutputAt: null, contextPct: null, compactions: { auto: 0, manual: 0 },
|
|
75
|
+
tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, retries: 0, fallbacks: 0,
|
|
76
|
+
toolNames: new Map(), tools: new Map(), subagents: { completed: 0, failed: 0, cancelled: 0 },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Per-run collector: an observer for the run's events and a hook for its terminal state. */
|
|
80
|
+
export function createRunTelemetry(request) {
|
|
81
|
+
const stats = newStats();
|
|
82
|
+
let finished = false;
|
|
83
|
+
return {
|
|
84
|
+
observer: { onEvent: (event) => { try {
|
|
85
|
+
observe(stats, event);
|
|
86
|
+
}
|
|
87
|
+
catch { /* never disturb a run */ } } },
|
|
88
|
+
finish: (facts) => {
|
|
89
|
+
if (finished)
|
|
90
|
+
return;
|
|
91
|
+
finished = true;
|
|
92
|
+
updateRollup((rollup) => foldRun(rollup, request, stats, facts));
|
|
93
|
+
if (facts.status === 'completed' && !NOT_TURNS.has(request.context.trigger)) {
|
|
94
|
+
recordFunnelStep('provider_authed', request.selection.backend);
|
|
95
|
+
recordFunnelStep('first_turn_completed');
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function turnRow(rollup, request) {
|
|
101
|
+
const { backend, provider, model } = request.selection;
|
|
102
|
+
const billing = billingOf(request);
|
|
103
|
+
const key = [backend, provider ?? '', model, billing].join('|');
|
|
104
|
+
rollup.turns[key] ??= emptyTurnRow(backend, provider ?? '', model, billing);
|
|
105
|
+
return rollup.turns[key];
|
|
106
|
+
}
|
|
107
|
+
function addOutcome(row, facts) {
|
|
108
|
+
if (facts.status === 'rate-limited')
|
|
109
|
+
row.outcomes.rateLimited += 1;
|
|
110
|
+
else
|
|
111
|
+
row.outcomes[facts.status] += 1;
|
|
112
|
+
if (facts.status === 'failed') {
|
|
113
|
+
const failure = classifyTurnFailure(facts.error?.message ?? '');
|
|
114
|
+
row.failures[failure] = (row.failures[failure] ?? 0) + 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function foldTurn(row, stats, facts) {
|
|
118
|
+
addOutcome(row, facts);
|
|
119
|
+
row.retries += stats.retries;
|
|
120
|
+
row.fallbacks += stats.fallbacks;
|
|
121
|
+
// A failed run's first "output" is often the error text itself, so only completed turns time it.
|
|
122
|
+
if (facts.status === 'completed' && stats.firstOutputAt !== null) {
|
|
123
|
+
row.ttftMs[bucketIndex('ttftMs', stats.firstOutputAt - stats.startedAt)] += 1;
|
|
124
|
+
}
|
|
125
|
+
row.durationS[bucketIndex('turnDurationS', facts.durationS)] += 1;
|
|
126
|
+
if (stats.contextPct !== null)
|
|
127
|
+
row.contextPctAtEnd[bucketIndex('contextPct', stats.contextPct)] += 1;
|
|
128
|
+
row.compactions.auto += stats.compactions.auto;
|
|
129
|
+
row.compactions.manual += stats.compactions.manual;
|
|
130
|
+
for (const key of ['input', 'output', 'cacheRead', 'cacheWrite'])
|
|
131
|
+
row.tokens[key] += stats.tokens[key];
|
|
132
|
+
}
|
|
133
|
+
function outcomeOf(facts) {
|
|
134
|
+
return facts.status === 'rate-limited' ? 'failed' : facts.status;
|
|
135
|
+
}
|
|
136
|
+
function cancelReason(facts) {
|
|
137
|
+
return facts.status === 'cancelled' ? /\((\w+)\)/.exec(facts.error?.message ?? '')?.[1] ?? null : null;
|
|
138
|
+
}
|
|
139
|
+
function foldTools(rollup, stats) {
|
|
140
|
+
for (const [name, counts] of stats.tools) {
|
|
141
|
+
const entry = rollup.tools[name] ??= { calls: 0, errors: 0 };
|
|
142
|
+
entry.calls += counts.calls;
|
|
143
|
+
entry.errors += counts.errors;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function foldAgent(rollup, request, stats, facts) {
|
|
147
|
+
const reason = cancelReason(facts);
|
|
148
|
+
if (reason === 'user')
|
|
149
|
+
rollup.agent.userInterrupts += 1;
|
|
150
|
+
if (reason === 'supersede')
|
|
151
|
+
rollup.agent.superseded += 1;
|
|
152
|
+
for (const key of ['completed', 'failed', 'cancelled'])
|
|
153
|
+
rollup.agent.subagents[key] += stats.subagents[key];
|
|
154
|
+
if (request.context.teamWorker)
|
|
155
|
+
rollup.agent.workers[outcomeOf(facts)] += 1;
|
|
156
|
+
const sessionId = request.session.sessionId;
|
|
157
|
+
if (sessionId)
|
|
158
|
+
rollup.agent.sessionTurns[sessionId] = (rollup.agent.sessionTurns[sessionId] ?? 0) + 1;
|
|
159
|
+
}
|
|
160
|
+
/** Turns go into the health rows; Agent-tool children count as subagent runs; the rest only
|
|
161
|
+
* contribute a manual compaction. */
|
|
162
|
+
function foldRun(rollup, request, stats, facts) {
|
|
163
|
+
const { trigger } = request.context;
|
|
164
|
+
if (trigger === 'subagent') {
|
|
165
|
+
rollup.agent.subagents[outcomeOf(facts)] += 1;
|
|
166
|
+
return foldTools(rollup, stats);
|
|
167
|
+
}
|
|
168
|
+
if (NOT_TURNS.has(trigger)) {
|
|
169
|
+
if (stats.compactions.manual > 0)
|
|
170
|
+
turnRow(rollup, request).compactions.manual += stats.compactions.manual;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
foldTurn(turnRow(rollup, request), stats, facts);
|
|
174
|
+
foldTools(rollup, stats);
|
|
175
|
+
foldAgent(rollup, request, stats, facts);
|
|
176
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UpgradeEvent } from './schema.js';
|
|
2
|
+
type InstallRunner = (version: string, done: (error: string | null) => void) => void;
|
|
3
|
+
type FailureClass = NonNullable<UpgradeEvent['failure']>['class'];
|
|
4
|
+
export declare function classifyUpgradeFailure(message: string): FailureClass;
|
|
5
|
+
/** Wrap the npm installer: report its outcome and leave the upgrade for the next boot to confirm. */
|
|
6
|
+
export declare function trackInstall(run: InstallRunner): InstallRunner;
|
|
7
|
+
/** At boot: confirm a recorded upgrade, or notice an unannounced version change. */
|
|
8
|
+
export declare function confirmUpgradeAtBoot(now?: number): void;
|
|
9
|
+
/** `runMigrations` observer: one event per migration that threw. */
|
|
10
|
+
export declare function recordMigrationFailure(failure: {
|
|
11
|
+
migration: string;
|
|
12
|
+
error: unknown;
|
|
13
|
+
}): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getSettings } from '../../core/settings.js';
|
|
2
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
3
|
+
import { redactMessage } from './redact.js';
|
|
4
|
+
import { recordTelemetryEvent } from './service.js';
|
|
5
|
+
import { readTelemetryState, updateTelemetryState } from './state.js';
|
|
6
|
+
const FAILURE_PATTERNS = [
|
|
7
|
+
['permission', /\b(EACCES|EPERM)\b|permission denied/i],
|
|
8
|
+
['disk', /\bENOSPC\b|no space left/i],
|
|
9
|
+
['timeout', /\bETIMEDOUT\b|timed? ?out|killed by SIG/i],
|
|
10
|
+
['network', /\b(ENOTFOUND|ECONNRESET|ECONNREFUSED|EAI_AGAIN|ENETUNREACH)\b|network|fetch failed/i],
|
|
11
|
+
['npm', /npm (ERR|error)|exited with code|could not start/i],
|
|
12
|
+
];
|
|
13
|
+
export function classifyUpgradeFailure(message) {
|
|
14
|
+
return FAILURE_PATTERNS.find(([, pattern]) => pattern.test(message))?.[0] ?? 'other';
|
|
15
|
+
}
|
|
16
|
+
function seconds(fromMs, toMs) {
|
|
17
|
+
return Math.max(0, Math.round((toMs - fromMs) / 1000));
|
|
18
|
+
}
|
|
19
|
+
function upgradeEvent(base, at = new Date()) {
|
|
20
|
+
return { type: 'upgrade', at: at.toISOString(), ...base };
|
|
21
|
+
}
|
|
22
|
+
function onInstallDone(pending, error) {
|
|
23
|
+
const durationS = seconds(Date.parse(pending.startedAt), Date.now());
|
|
24
|
+
const { from, to, method } = pending;
|
|
25
|
+
if (error === null) {
|
|
26
|
+
updateTelemetryState((state) => ({ ...state, pendingUpgrade: pending }));
|
|
27
|
+
recordTelemetryEvent(upgradeEvent({ from, to, method, stage: 'installed', durationS, failure: null }));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const failure = { class: classifyUpgradeFailure(error), message: redactMessage(error) };
|
|
31
|
+
recordTelemetryEvent(upgradeEvent({ from, to, method, stage: 'failed', durationS, failure }), { urgent: true });
|
|
32
|
+
}
|
|
33
|
+
/** Wrap the npm installer: report its outcome and leave the upgrade for the next boot to confirm. */
|
|
34
|
+
export function trackInstall(run) {
|
|
35
|
+
return (version, done) => {
|
|
36
|
+
const pending = {
|
|
37
|
+
from: CORTEX_VERSION, to: version, startedAt: new Date().toISOString(),
|
|
38
|
+
method: getSettings().serverAutoUpdate ? 'auto' : 'prompt',
|
|
39
|
+
};
|
|
40
|
+
run(version, (error) => {
|
|
41
|
+
try {
|
|
42
|
+
onInstallDone(pending, error);
|
|
43
|
+
}
|
|
44
|
+
catch { /* telemetry never blocks an update */ }
|
|
45
|
+
done(error);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function bootEvent(pending, lastVersion, now) {
|
|
50
|
+
if (pending) {
|
|
51
|
+
const stage = pending.to === CORTEX_VERSION ? 'confirmed' : 'unconfirmed';
|
|
52
|
+
const durationS = seconds(Date.parse(pending.startedAt), now);
|
|
53
|
+
return upgradeEvent({ ...pending, stage, durationS, failure: null }, new Date(now));
|
|
54
|
+
}
|
|
55
|
+
if (!lastVersion || lastVersion === CORTEX_VERSION)
|
|
56
|
+
return null;
|
|
57
|
+
return upgradeEvent({
|
|
58
|
+
from: lastVersion, to: CORTEX_VERSION, method: 'manual', stage: 'version-changed', durationS: null, failure: null,
|
|
59
|
+
}, new Date(now));
|
|
60
|
+
}
|
|
61
|
+
/** At boot: confirm a recorded upgrade, or notice an unannounced version change. */
|
|
62
|
+
export function confirmUpgradeAtBoot(now = Date.now()) {
|
|
63
|
+
const state = readTelemetryState();
|
|
64
|
+
const event = bootEvent(state.pendingUpgrade, state.lastVersion, now);
|
|
65
|
+
updateTelemetryState((current) => ({ ...current, pendingUpgrade: null, lastVersion: CORTEX_VERSION }));
|
|
66
|
+
if (event)
|
|
67
|
+
recordTelemetryEvent(event);
|
|
68
|
+
}
|
|
69
|
+
function migrationErrorClass(error) {
|
|
70
|
+
const code = error?.code;
|
|
71
|
+
if (code === 'EACCES' || code === 'EPERM')
|
|
72
|
+
return 'permission';
|
|
73
|
+
if (error instanceof SyntaxError)
|
|
74
|
+
return 'parse';
|
|
75
|
+
return typeof code === 'string' && code.startsWith('E') ? 'io' : 'other';
|
|
76
|
+
}
|
|
77
|
+
/** `runMigrations` observer: one event per migration that threw. */
|
|
78
|
+
export function recordMigrationFailure(failure) {
|
|
79
|
+
const message = failure.error instanceof Error ? failure.error.message : String(failure.error);
|
|
80
|
+
recordTelemetryEvent({
|
|
81
|
+
type: 'migration_failure',
|
|
82
|
+
at: new Date().toISOString(),
|
|
83
|
+
migration: failure.migration.replace(/[^A-Za-z0-9._:/@[\]-]/g, '_').slice(0, 80),
|
|
84
|
+
errorClass: migrationErrorClass(failure.error),
|
|
85
|
+
message: redactMessage(message),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type TelemetryEnvelope, type TelemetryEvent } from './schema.js';
|
|
2
|
+
export declare const UPLOAD_TIMEOUT_MS = 10000;
|
|
3
|
+
export type PostOutcome = 'sent' | 'rejected' | 'retry';
|
|
4
|
+
export type FetchLike = (url: string, init: RequestInit) => Promise<{
|
|
5
|
+
ok: boolean;
|
|
6
|
+
status: number;
|
|
7
|
+
}>;
|
|
8
|
+
/** Split events into batches under the Worker's event-count and body-size caps. */
|
|
9
|
+
export declare function chunkEvents(events: TelemetryEvent[]): TelemetryEvent[][];
|
|
10
|
+
/** POST one batch. Never throws; failures are debug-logged only. */
|
|
11
|
+
export declare function postBatch(endpoint: string, envelope: TelemetryEnvelope, events: TelemetryEvent[], fetchImpl?: FetchLike): Promise<PostOutcome>;
|
|
12
|
+
/** Exponential backoff between failed uploads: 1 min doubling up to 6 h. */
|
|
13
|
+
export declare class UploadBackoff {
|
|
14
|
+
private readonly now;
|
|
15
|
+
private failures;
|
|
16
|
+
private nextAt;
|
|
17
|
+
constructor(now?: () => number);
|
|
18
|
+
ready(): boolean;
|
|
19
|
+
succeeded(): void;
|
|
20
|
+
failed(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createLogger } from '../../core/log.js';
|
|
2
|
+
import { TELEMETRY_MAX_BATCH_BYTES, TELEMETRY_MAX_EVENTS_PER_BATCH, TelemetryBatchSchema, } from './schema.js';
|
|
3
|
+
const log = createLogger('telemetry');
|
|
4
|
+
export const UPLOAD_TIMEOUT_MS = 10_000;
|
|
5
|
+
/** Room left in a request body for the envelope and JSON framing. */
|
|
6
|
+
const ENVELOPE_ALLOWANCE_BYTES = 2_048;
|
|
7
|
+
/** Split events into batches under the Worker's event-count and body-size caps. */
|
|
8
|
+
export function chunkEvents(events) {
|
|
9
|
+
const budget = TELEMETRY_MAX_BATCH_BYTES - ENVELOPE_ALLOWANCE_BYTES;
|
|
10
|
+
const batches = [];
|
|
11
|
+
let current = [];
|
|
12
|
+
let bytes = 0;
|
|
13
|
+
for (const event of events) {
|
|
14
|
+
const size = Buffer.byteLength(JSON.stringify(event)) + 1;
|
|
15
|
+
if (size > budget)
|
|
16
|
+
continue;
|
|
17
|
+
if (current.length >= TELEMETRY_MAX_EVENTS_PER_BATCH || bytes + size > budget) {
|
|
18
|
+
batches.push(current);
|
|
19
|
+
current = [];
|
|
20
|
+
bytes = 0;
|
|
21
|
+
}
|
|
22
|
+
current.push(event);
|
|
23
|
+
bytes += size;
|
|
24
|
+
}
|
|
25
|
+
if (current.length > 0)
|
|
26
|
+
batches.push(current);
|
|
27
|
+
return batches;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The Worker's contract: 2xx stored; 400 invalid and 413 too large are never accepted; 429 means
|
|
31
|
+
* the install's daily cap is used up and the excess is dropped for good. Only 5xx (and network
|
|
32
|
+
* errors) are worth sending again.
|
|
33
|
+
*/
|
|
34
|
+
function outcomeOf(status, ok) {
|
|
35
|
+
if (ok)
|
|
36
|
+
return 'sent';
|
|
37
|
+
return status >= 400 && status < 500 ? 'rejected' : 'retry';
|
|
38
|
+
}
|
|
39
|
+
/** POST one batch. Never throws; failures are debug-logged only. */
|
|
40
|
+
export async function postBatch(endpoint, envelope, events, fetchImpl = fetch) {
|
|
41
|
+
const batch = TelemetryBatchSchema.safeParse({ envelope, events });
|
|
42
|
+
if (!batch.success)
|
|
43
|
+
return 'rejected';
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetchImpl(endpoint, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
body: JSON.stringify(batch.data),
|
|
49
|
+
signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS),
|
|
50
|
+
});
|
|
51
|
+
void response.body?.cancel?.().catch(() => undefined);
|
|
52
|
+
const outcome = outcomeOf(response.status, response.ok);
|
|
53
|
+
if (outcome !== 'sent')
|
|
54
|
+
log.debug(`telemetry upload ${outcome}: HTTP ${response.status}`);
|
|
55
|
+
return outcome;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
log.debug(`telemetry upload failed: ${error.message}`);
|
|
59
|
+
return 'retry';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Exponential backoff between failed uploads: 1 min doubling up to 6 h. */
|
|
63
|
+
export class UploadBackoff {
|
|
64
|
+
now;
|
|
65
|
+
failures = 0;
|
|
66
|
+
nextAt = 0;
|
|
67
|
+
constructor(now = Date.now) {
|
|
68
|
+
this.now = now;
|
|
69
|
+
}
|
|
70
|
+
ready() {
|
|
71
|
+
return this.now() >= this.nextAt;
|
|
72
|
+
}
|
|
73
|
+
succeeded() {
|
|
74
|
+
this.failures = 0;
|
|
75
|
+
this.nextAt = 0;
|
|
76
|
+
}
|
|
77
|
+
failed() {
|
|
78
|
+
this.failures += 1;
|
|
79
|
+
const delay = Math.min(60_000 * 2 ** (this.failures - 1), 6 * 60 * 60_000);
|
|
80
|
+
this.nextAt = this.now() + delay;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ClientKind } from './client-kind.js';
|
|
2
|
+
import { type FEATURE_COUNTERS, type MESSAGE_CHANNELS } from './schema.js';
|
|
3
|
+
export type FeatureCounter = (typeof FEATURE_COUNTERS)[number];
|
|
4
|
+
type MessageChannel = (typeof MESSAGE_CHANNELS)[number];
|
|
5
|
+
export declare function countFeature(name: FeatureCounter, by?: number): void;
|
|
6
|
+
export declare function countMessage(channel: MessageChannel): void;
|
|
7
|
+
/** A chat-platform conduit's channel bucket (`slack:…`, `feishu:…`, `tui-…`). */
|
|
8
|
+
export declare function platformChannel(conduit: string): MessageChannel;
|
|
9
|
+
export declare function countUiOp(op: string): void;
|
|
10
|
+
/** `ui.mutate-invoked`: the op name, plus a message by app when it sent one. */
|
|
11
|
+
export declare function recordUiMutation(op: string, ok: boolean, client: ClientKind | null | undefined): void;
|
|
12
|
+
export declare function recordWebhookCall(url: string | undefined, data: unknown): void;
|
|
13
|
+
export declare function recordScheduleCreated(count?: number): void;
|
|
14
|
+
export declare function recordRemoteClientConnected(): void;
|
|
15
|
+
export declare function recordRemoteClientDisconnected(): void;
|
|
16
|
+
export declare function recordEventLoopLag(p99Ms: number): void;
|
|
17
|
+
/** Mark the end of a boot phase (time since the previous mark). */
|
|
18
|
+
export declare function markBootPhase(name: string, at?: number): void;
|
|
19
|
+
/** Record this boot's phase durations in milliseconds; `imports` is module loading. */
|
|
20
|
+
export declare function recordStartup(importsMs: number, totalMs?: number): void;
|
|
21
|
+
/** Crash routes must be router patterns (`/m/session/:sessionId`). Anything else is dropped rather
|
|
22
|
+
* than repaired, because a concrete path can carry session ids, project names or file names. */
|
|
23
|
+
export declare function routeTemplate(route: string | null): string | null;
|
|
24
|
+
export declare function installWebReportSink(): void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { captureCrash } from './crash.js';
|
|
2
|
+
import { recordFunnelStep } from './funnel.js';
|
|
3
|
+
import { recordEventLoopP99, updateRollup, utcDay } from './rollup.js';
|
|
4
|
+
import { bucketIndex } from './schema.js';
|
|
5
|
+
import { setWebReportSink } from './web-report.js';
|
|
6
|
+
export function countFeature(name, by = 1) {
|
|
7
|
+
if (by <= 0)
|
|
8
|
+
return;
|
|
9
|
+
updateRollup((rollup) => { rollup.features[name] = (rollup.features[name] ?? 0) + by; });
|
|
10
|
+
}
|
|
11
|
+
export function countMessage(channel) {
|
|
12
|
+
updateRollup((rollup) => { rollup.messagesByChannel[channel] = (rollup.messagesByChannel[channel] ?? 0) + 1; });
|
|
13
|
+
}
|
|
14
|
+
/** A chat-platform conduit's channel bucket (`slack:…`, `feishu:…`, `tui-…`). */
|
|
15
|
+
export function platformChannel(conduit) {
|
|
16
|
+
if (conduit.startsWith('slack'))
|
|
17
|
+
return 'slack';
|
|
18
|
+
if (conduit.startsWith('feishu'))
|
|
19
|
+
return 'feishu';
|
|
20
|
+
return conduit.startsWith('tui') ? 'tui' : 'other';
|
|
21
|
+
}
|
|
22
|
+
export function countUiOp(op) {
|
|
23
|
+
updateRollup((rollup) => { rollup.uiOps[op] = (rollup.uiOps[op] ?? 0) + 1; });
|
|
24
|
+
}
|
|
25
|
+
const MESSAGE_OPS = new Set(['sessions.send', 'sessions.createAndSend']);
|
|
26
|
+
const SESSION_OPS = new Set(['sessions.create', 'sessions.createAndSend']);
|
|
27
|
+
/** `ui.mutate-invoked`: the op name, plus a message by app when it sent one. */
|
|
28
|
+
export function recordUiMutation(op, ok, client) {
|
|
29
|
+
countUiOp(op);
|
|
30
|
+
if (!ok)
|
|
31
|
+
return;
|
|
32
|
+
if (MESSAGE_OPS.has(op))
|
|
33
|
+
countMessage(client ?? 'other');
|
|
34
|
+
if (SESSION_OPS.has(op)) {
|
|
35
|
+
countFeature('session_created');
|
|
36
|
+
recordFunnelStep('first_session');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Agent-side webhook calls that mark a feature in use: `route → action → counter`. */
|
|
40
|
+
const WEBHOOK_FEATURES = {
|
|
41
|
+
'/webhook/subagent': { start: 'subagent_run' },
|
|
42
|
+
'/webhook/team': { spawn: 'worker_spawned' },
|
|
43
|
+
'/webhook/board': { open: 'board_opened' },
|
|
44
|
+
'/webhook/waitpoint': { create: 'waitpoint_created' },
|
|
45
|
+
};
|
|
46
|
+
const browserSessions = { day: '', ids: new Set() };
|
|
47
|
+
/** A browser counts once per session per day, however often its lease is renewed. */
|
|
48
|
+
function countBrowserLease(sessionId) {
|
|
49
|
+
const day = utcDay(Date.now());
|
|
50
|
+
if (browserSessions.day !== day)
|
|
51
|
+
Object.assign(browserSessions, { day, ids: new Set() });
|
|
52
|
+
const key = typeof sessionId === 'string' ? sessionId : '';
|
|
53
|
+
if (browserSessions.ids.has(key))
|
|
54
|
+
return;
|
|
55
|
+
browserSessions.ids.add(key);
|
|
56
|
+
countFeature('browser_session');
|
|
57
|
+
}
|
|
58
|
+
export function recordWebhookCall(url, data) {
|
|
59
|
+
const body = (data ?? {});
|
|
60
|
+
if (url === '/webhook/browser' && body.action === 'lease')
|
|
61
|
+
return countBrowserLease(body.sessionId);
|
|
62
|
+
const feature = WEBHOOK_FEATURES[url ?? '']?.[String(body.action)];
|
|
63
|
+
if (!feature)
|
|
64
|
+
return;
|
|
65
|
+
countFeature(feature);
|
|
66
|
+
if (feature === 'worker_spawned')
|
|
67
|
+
recordFunnelStep('first_worker');
|
|
68
|
+
}
|
|
69
|
+
export function recordScheduleCreated(count = 1) {
|
|
70
|
+
if (count <= 0)
|
|
71
|
+
return;
|
|
72
|
+
countFeature('schedule_created', count);
|
|
73
|
+
recordFunnelStep('first_schedule');
|
|
74
|
+
}
|
|
75
|
+
export function recordRemoteClientConnected() {
|
|
76
|
+
countFeature('remote_client_connected');
|
|
77
|
+
recordFunnelStep('first_remote_client');
|
|
78
|
+
}
|
|
79
|
+
export function recordRemoteClientDisconnected() {
|
|
80
|
+
updateRollup((rollup) => { rollup.perf.remoteClientDisconnects += 1; });
|
|
81
|
+
}
|
|
82
|
+
export function recordEventLoopLag(p99Ms) {
|
|
83
|
+
updateRollup((rollup) => recordEventLoopP99(rollup, p99Ms));
|
|
84
|
+
}
|
|
85
|
+
// ── Boot phases ─────────────────────────────────────────
|
|
86
|
+
const bootMarks = [];
|
|
87
|
+
/** Mark the end of a boot phase (time since the previous mark). */
|
|
88
|
+
export function markBootPhase(name, at = performance.now()) {
|
|
89
|
+
bootMarks.push([name, at]);
|
|
90
|
+
}
|
|
91
|
+
/** Record this boot's phase durations in milliseconds; `imports` is module loading. */
|
|
92
|
+
export function recordStartup(importsMs, totalMs = performance.now()) {
|
|
93
|
+
const phases = { imports: Math.round(importsMs) };
|
|
94
|
+
let previous = importsMs;
|
|
95
|
+
for (const [name, at] of bootMarks) {
|
|
96
|
+
phases[name] = Math.max(0, Math.round(at - previous));
|
|
97
|
+
previous = at;
|
|
98
|
+
}
|
|
99
|
+
phases.total = Math.round(totalMs);
|
|
100
|
+
updateRollup((rollup) => {
|
|
101
|
+
rollup.perf.startups.push(phases);
|
|
102
|
+
if (rollup.perf.startups.length > 10)
|
|
103
|
+
rollup.perf.startups.shift();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// ── Web reports (`telemetry.report`) ────────────────────
|
|
107
|
+
/** A route pattern segment: `:param`, a splat, or a short lowercase static word. */
|
|
108
|
+
const ROUTE_SEGMENT = /^(?::[A-Za-z][A-Za-z0-9_]{0,30}|\*|[a-z][a-z-]{0,23})$/;
|
|
109
|
+
/** Crash routes must be router patterns (`/m/session/:sessionId`). Anything else is dropped rather
|
|
110
|
+
* than repaired, because a concrete path can carry session ids, project names or file names. */
|
|
111
|
+
export function routeTemplate(route) {
|
|
112
|
+
if (!route || route.length > 80 || !route.startsWith('/'))
|
|
113
|
+
return null;
|
|
114
|
+
const segments = route.split('/').filter((segment) => segment !== '');
|
|
115
|
+
return segments.every((segment) => ROUTE_SEGMENT.test(segment)) ? route : null;
|
|
116
|
+
}
|
|
117
|
+
function recordWebLoad(report) {
|
|
118
|
+
updateRollup(({ perf: { web } }) => {
|
|
119
|
+
web.loads += 1;
|
|
120
|
+
if (report.ttfbMs !== null)
|
|
121
|
+
web.ttfbMs[bucketIndex('webLoadMs', report.ttfbMs)] += 1;
|
|
122
|
+
if (report.firstRenderMs !== null)
|
|
123
|
+
web.firstRenderMs[bucketIndex('webLoadMs', report.firstRenderMs)] += 1;
|
|
124
|
+
if (report.interactiveMs !== null)
|
|
125
|
+
web.interactiveMs[bucketIndex('webLoadMs', report.interactiveMs)] += 1;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function recordWebCrash(report, client) {
|
|
129
|
+
if (report.kind === 'crash') {
|
|
130
|
+
const { crashKind: kind, errorName, message, stack, buildStamp, uptimeS } = report;
|
|
131
|
+
return captureCrash({
|
|
132
|
+
component: 'web', kind, errorName, message, stack, buildStamp, uptimeS, client, route: routeTemplate(report.route),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (report.kind !== 'native_crash')
|
|
136
|
+
return;
|
|
137
|
+
const at = new Date(report.at);
|
|
138
|
+
captureCrash({
|
|
139
|
+
component: report.component, kind: 'panic', errorName: 'panic', message: report.message, stack: report.stack,
|
|
140
|
+
buildStamp: report.appVersion, client, at: Number.isNaN(at.getTime()) ? new Date() : at,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function onWebReport(report, client) {
|
|
144
|
+
if (report.kind === 'load')
|
|
145
|
+
return recordWebLoad(report);
|
|
146
|
+
if (report.kind === 'sse_reconnect') {
|
|
147
|
+
return updateRollup((rollup) => { rollup.perf.sseReconnects += report.count; });
|
|
148
|
+
}
|
|
149
|
+
recordWebCrash(report, client);
|
|
150
|
+
}
|
|
151
|
+
export function installWebReportSink() {
|
|
152
|
+
setWebReportSink(onWebReport);
|
|
153
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClientKind } from './client-kind.js';
|
|
2
|
+
import type { WebTelemetryReport } from './schema.js';
|
|
3
|
+
type WebReportSink = (report: WebTelemetryReport, client: ClientKind | null) => void;
|
|
4
|
+
/** The telemetry service installs the real handler once it starts. */
|
|
5
|
+
export declare function setWebReportSink(next: WebReportSink | null): void;
|
|
6
|
+
/** Fold one `telemetry.report` observation in; dropped when telemetry is inactive. */
|
|
7
|
+
export declare function recordWebReport(report: WebTelemetryReport, client: ClientKind | null): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isTelemetryActive } from './gate.js';
|
|
2
|
+
let sink = null;
|
|
3
|
+
/** The telemetry service installs the real handler once it starts. */
|
|
4
|
+
export function setWebReportSink(next) {
|
|
5
|
+
sink = next;
|
|
6
|
+
}
|
|
7
|
+
/** Fold one `telemetry.report` observation in; dropped when telemetry is inactive. */
|
|
8
|
+
export function recordWebReport(report, client) {
|
|
9
|
+
if (!sink || !isTelemetryActive())
|
|
10
|
+
return;
|
|
11
|
+
try {
|
|
12
|
+
sink(report, client);
|
|
13
|
+
}
|
|
14
|
+
catch { /* telemetry never fails a request */ }
|
|
15
|
+
}
|