@tangle-network/agent-app 0.60.220 → 0.60.221
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/chat-routes/index.js +4 -3
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/turn-routes.d.ts +10 -5
- package/dist/{chunk-MAOTZ77B.js → chunk-A5DGO2XT.js} +2 -2
- package/dist/{chunk-NHCS55QI.js → chunk-DMXEPYB5.js} +2 -1
- package/dist/{chunk-NHCS55QI.js.map → chunk-DMXEPYB5.js.map} +1 -1
- package/dist/chunk-LGMJMCSE.js +157 -0
- package/dist/chunk-LGMJMCSE.js.map +1 -0
- package/dist/{chunk-WDY47GBR.js → chunk-N7WTF5P2.js} +47 -13
- package/dist/chunk-N7WTF5P2.js.map +1 -0
- package/dist/{chunk-WLH4DEB2.js → chunk-OMB4HQ2W.js} +54 -19
- package/dist/chunk-OMB4HQ2W.js.map +1 -0
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +2 -1
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/router-turn.js +1 -1
- package/dist/signoff/app-defaults.d.ts +2 -1
- package/dist/signoff/cli.js +1 -1
- package/dist/signoff/index.js +1 -1
- package/dist/turn-trace/index.js +6 -146
- package/dist/turn-trace/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-WDY47GBR.js.map +0 -1
- package/dist/chunk-WLH4DEB2.js.map +0 -1
- /package/dist/{chunk-MAOTZ77B.js.map → chunk-A5DGO2XT.js.map} +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TURN_SPAN_KINDS
|
|
3
|
+
} from "./chunk-HA5USG2Z.js";
|
|
4
|
+
|
|
5
|
+
// src/turn-trace/otel.ts
|
|
6
|
+
function attributes(record, doubles = /* @__PURE__ */ new Set()) {
|
|
7
|
+
return Object.entries(record).flatMap(([key, value]) => {
|
|
8
|
+
if (typeof value === "number" && !Number.isFinite(value)) return [];
|
|
9
|
+
return [{
|
|
10
|
+
key,
|
|
11
|
+
value: typeof value === "number" ? Number.isInteger(value) && !doubles.has(key) ? { intValue: value.toString() } : { doubleValue: value } : typeof value === "boolean" ? { boolValue: value } : { stringValue: value }
|
|
12
|
+
}];
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
var ROOT_MEASUREMENTS = /* @__PURE__ */ new Set([
|
|
16
|
+
"tangle.duration_ms",
|
|
17
|
+
"tangle.turn.wall_ms",
|
|
18
|
+
"tangle.turn.covered_ms",
|
|
19
|
+
"tangle.turn.coverage_pct",
|
|
20
|
+
"tangle.turn.uncovered_ms",
|
|
21
|
+
"tangle.turn.largest_gap_ms",
|
|
22
|
+
"tangle.turn.first_text_ms",
|
|
23
|
+
...TURN_SPAN_KINDS.map((kind) => `tangle.turn.${kind}_ms`)
|
|
24
|
+
]);
|
|
25
|
+
function otlpTraceId(traceId) {
|
|
26
|
+
if (/^[0-9a-f]{32}$/.test(traceId)) return traceId;
|
|
27
|
+
const dashless = traceId.replace(/-/g, "");
|
|
28
|
+
if (/^[0-9a-f]{32}$/.test(dashless)) return dashless;
|
|
29
|
+
return hexId(traceId, 32);
|
|
30
|
+
}
|
|
31
|
+
function hexId(input, length) {
|
|
32
|
+
const hashes = [2166136261, 2654435769, 2246822507, 3266489909];
|
|
33
|
+
for (const byte of new TextEncoder().encode(input)) {
|
|
34
|
+
for (let lane = 0; lane < hashes.length; lane += 1) hashes[lane] = Math.imul(hashes[lane] ^ byte + lane, 16777619);
|
|
35
|
+
}
|
|
36
|
+
let out = hashes.map((hash) => (hash >>> 0).toString(16).padStart(8, "0")).join("");
|
|
37
|
+
while (out.length < length) out += hexId(`${input}:${out.length}`, 32);
|
|
38
|
+
return out.slice(0, length);
|
|
39
|
+
}
|
|
40
|
+
var msToNs = (ms) => (BigInt(Math.floor(ms)) * 1000000n).toString();
|
|
41
|
+
var SPAN_KIND = { "model.call": "LLM", "tool.call": "TOOL" };
|
|
42
|
+
function buildTurnTraceOtelSpans(snapshot, labels = {}) {
|
|
43
|
+
const traceId = otlpTraceId(snapshot.traceId);
|
|
44
|
+
const root = snapshot.rootSpanId;
|
|
45
|
+
const { summary } = snapshot;
|
|
46
|
+
const rootAttrs = {
|
|
47
|
+
...labels,
|
|
48
|
+
"openinference.span.kind": "CHAIN",
|
|
49
|
+
"tangle.execution_id": snapshot.executionId,
|
|
50
|
+
"tangle.trace_id": snapshot.traceId,
|
|
51
|
+
"tangle.started_at_ms": snapshot.startedAt,
|
|
52
|
+
"tangle.completed_at_ms": snapshot.endedAt,
|
|
53
|
+
"tangle.duration_ms": summary.wallMs,
|
|
54
|
+
"tangle.turn.wall_ms": summary.wallMs,
|
|
55
|
+
"tangle.turn.covered_ms": summary.coveredMs,
|
|
56
|
+
"tangle.turn.coverage_pct": summary.coveragePct,
|
|
57
|
+
"tangle.turn.uncovered_ms": summary.uncoveredMs,
|
|
58
|
+
"tangle.turn.largest_gap_ms": summary.largestGapMs,
|
|
59
|
+
"tangle.turn.spans": summary.spans,
|
|
60
|
+
"tangle.turn.model_calls": summary.modelCalls,
|
|
61
|
+
"tangle.turn.tool_calls": summary.toolCalls,
|
|
62
|
+
...summary.firstTextMs === void 0 ? {} : { "tangle.turn.first_text_ms": summary.firstTextMs },
|
|
63
|
+
...summary.dropped ? { "tangle.turn.spans_dropped": summary.dropped } : {},
|
|
64
|
+
...Object.fromEntries(TURN_SPAN_KINDS.map((kind) => [`tangle.turn.${kind}_ms`, summary.byKind[kind]]))
|
|
65
|
+
};
|
|
66
|
+
const spans = [{
|
|
67
|
+
traceId,
|
|
68
|
+
spanId: root,
|
|
69
|
+
name: "agent_app.turn",
|
|
70
|
+
kind: 1,
|
|
71
|
+
startTimeUnixNano: msToNs(snapshot.startedAt),
|
|
72
|
+
endTimeUnixNano: msToNs(snapshot.endedAt),
|
|
73
|
+
attributes: attributes(rootAttrs, ROOT_MEASUREMENTS),
|
|
74
|
+
status: snapshot.status === "ok" ? { code: 1 } : { code: 2, ...snapshot.error ? { message: snapshot.error } : {} }
|
|
75
|
+
}];
|
|
76
|
+
for (const span of snapshot.spans) {
|
|
77
|
+
const attrs = {
|
|
78
|
+
...span.attrs,
|
|
79
|
+
"openinference.span.kind": SPAN_KIND[span.name] ?? "CHAIN",
|
|
80
|
+
"tangle.turn.span_kind": span.kind,
|
|
81
|
+
"agent.parent.confidence": "explicit",
|
|
82
|
+
...span.name === "tool.call" ? { "gen_ai.operation.name": "execute_tool" } : {},
|
|
83
|
+
...span.unfinished ? { "tangle.turn.unfinished": true } : {},
|
|
84
|
+
...span.error ? { "error.message": span.error } : {}
|
|
85
|
+
};
|
|
86
|
+
spans.push({
|
|
87
|
+
traceId,
|
|
88
|
+
spanId: span.spanId,
|
|
89
|
+
parentSpanId: span.parentSpanId,
|
|
90
|
+
name: span.name,
|
|
91
|
+
kind: 1,
|
|
92
|
+
startTimeUnixNano: msToNs(span.startMs),
|
|
93
|
+
endTimeUnixNano: msToNs(span.endMs),
|
|
94
|
+
attributes: attributes(attrs),
|
|
95
|
+
status: span.error ? { code: 2, message: span.error } : { code: 1 }
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return spans;
|
|
99
|
+
}
|
|
100
|
+
var DEFAULT_INTELLIGENCE_BASE_URL = "https://intelligence.tangle.tools";
|
|
101
|
+
var INGEST_KEY_ENV = ["SANDBOX_PRODUCTION_API_KEY", "TCLOUD_SANDBOX_API_KEY", "SANDBOX_API_KEY"];
|
|
102
|
+
function resolveIngestKey() {
|
|
103
|
+
if (typeof process === "undefined") return void 0;
|
|
104
|
+
for (const name of INGEST_KEY_ENV) {
|
|
105
|
+
const value = process.env?.[name]?.trim();
|
|
106
|
+
if (value) return value;
|
|
107
|
+
}
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
var SCOPE = { name: "@tangle-network/agent-app", version: "turn-trace" };
|
|
111
|
+
function createIntelligenceTurnTraceSink(options) {
|
|
112
|
+
const url = `${(options.baseUrl ?? DEFAULT_INTELLIGENCE_BASE_URL).replace(/\/+$/, "")}/v1/otlp/v1/traces`;
|
|
113
|
+
const report = options.onError ?? ((reason) => console.warn(`[turn-trace] export failed: ${reason}`));
|
|
114
|
+
const fail = (reason) => {
|
|
115
|
+
try {
|
|
116
|
+
report(reason.slice(0, 200));
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
let missingKeyReported = false;
|
|
121
|
+
return async (snapshot, labels) => {
|
|
122
|
+
const apiKey = options.apiKey?.trim() || resolveIngestKey();
|
|
123
|
+
if (!apiKey) {
|
|
124
|
+
if (!missingKeyReported) fail(`no ingest key: set ${INGEST_KEY_ENV.join(", ")} or pass apiKey`);
|
|
125
|
+
missingKeyReported = true;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const body = {
|
|
130
|
+
resourceSpans: [{
|
|
131
|
+
resource: { attributes: attributes({ "service.name": options.project, "tangle.project": options.project }) },
|
|
132
|
+
scopeSpans: [{ scope: SCOPE, spans: buildTurnTraceOtelSpans(snapshot, { project: options.project, ...labels }) }]
|
|
133
|
+
}]
|
|
134
|
+
};
|
|
135
|
+
const response = await fetch(url, {
|
|
136
|
+
method: "POST",
|
|
137
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
|
|
138
|
+
body: JSON.stringify(body),
|
|
139
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 5e3)
|
|
140
|
+
});
|
|
141
|
+
const text = await response.text();
|
|
142
|
+
if (!response.ok) return fail(`HTTP ${response.status} from the OTLP ingest`);
|
|
143
|
+
const rejected = Number(JSON.parse(text || "{}").partialSuccess?.rejectedSpans ?? 0);
|
|
144
|
+
if (rejected > 0) fail(`the OTLP ingest rejected ${rejected} spans`);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
fail(error instanceof Error ? error.message : "turn trace export failed");
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export {
|
|
152
|
+
otlpTraceId,
|
|
153
|
+
buildTurnTraceOtelSpans,
|
|
154
|
+
resolveIngestKey,
|
|
155
|
+
createIntelligenceTurnTraceSink
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=chunk-LGMJMCSE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/turn-trace/otel.ts"],"sourcesContent":["/**\n * A finished turn trace as OTLP spans, sent to Tangle Intelligence.\n *\n * The attribute vocabulary is the one agent-runtime's span builders write\n * (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.*`,\n * `gen_ai.tool.name`, OpenInference's span kind, `agent.parent.confidence`), and\n * the wire shape is the one its `createOtelExporter` posts to\n * `<base>/v1/otlp/v1/traces`.\n *\n * It does not import agent-runtime. The runtime root pulls the whole sandbox\n * SDK into a Worker bundle, and the SDK's chain client imports `viem`, which a\n * Worker build cannot resolve (Hospitality's release failed on exactly that);\n * and its exporter keeps a timer a Worker refuses at module scope. One OTLP\n * POST per finished turn needs neither.\n */\nimport { TURN_SPAN_KINDS, type TurnSpanAttrs, type TurnSpanKind, type TurnTraceSink, type TurnTraceSnapshot } from './recorder'\n\n/** One OTLP/JSON span, as Intelligence's ingest reads it. */\nexport interface OtlpSpan {\n traceId: string\n spanId: string\n parentSpanId?: string\n name: string\n kind: number\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes: Array<{ key: string; value: { stringValue?: string; intValue?: string; doubleValue?: number; boolValue?: boolean } }>\n status: { code: number; message?: string }\n}\n\n/** `doubles` names measurements that stay `doubleValue` when they land on a whole number, so a reader sees one type per key. */\nfunction attributes(record: Record<string, string | number | boolean>, doubles: ReadonlySet<string> = new Set()): OtlpSpan['attributes'] {\n return Object.entries(record).flatMap(([key, value]) => {\n if (typeof value === 'number' && !Number.isFinite(value)) return []\n return [{\n key,\n value: typeof value === 'number' ? (Number.isInteger(value) && !doubles.has(key) ? { intValue: value.toString() } : { doubleValue: value })\n : typeof value === 'boolean' ? { boolValue: value } : { stringValue: value },\n }]\n })\n}\n\n/** The root span's measured numbers: one decimal, so each is always a `doubleValue`. */\nconst ROOT_MEASUREMENTS: ReadonlySet<string> = new Set([\n 'tangle.duration_ms',\n 'tangle.turn.wall_ms',\n 'tangle.turn.covered_ms',\n 'tangle.turn.coverage_pct',\n 'tangle.turn.uncovered_ms',\n 'tangle.turn.largest_gap_ms',\n 'tangle.turn.first_text_ms',\n ...TURN_SPAN_KINDS.map((kind) => `tangle.turn.${kind}_ms`),\n])\n\n/**\n * A Tangle trace id as the 32-hex OTLP trace id. The mapping is the Sandbox SDK's `otelTraceIdForTangleTrace`, so a\n * Sandbox trace export of the same turn lands in the same OTLP trace. An id that is already 32 hex, or a UUID, is used as it is.\n */\nexport function otlpTraceId(traceId: string): string {\n if (/^[0-9a-f]{32}$/.test(traceId)) return traceId\n const dashless = traceId.replace(/-/g, '')\n if (/^[0-9a-f]{32}$/.test(dashless)) return dashless\n return hexId(traceId, 32)\n}\n\nfunction hexId(input: string, length: number): string {\n const hashes = [2166136261, 2654435769, 2246822507, 3266489909]\n for (const byte of new TextEncoder().encode(input)) {\n for (let lane = 0; lane < hashes.length; lane += 1) hashes[lane] = Math.imul((hashes[lane] as number) ^ (byte + lane), 16777619)\n }\n let out = hashes.map((hash) => (hash >>> 0).toString(16).padStart(8, '0')).join('')\n while (out.length < length) out += hexId(`${input}:${out.length}`, 32)\n return out.slice(0, length)\n}\n\nconst msToNs = (ms: number) => (BigInt(Math.floor(ms)) * 1_000_000n).toString()\n\n/** OpenInference span kind per turn span: model calls read as LLM, tool calls as TOOL. */\nconst SPAN_KIND: Partial<Record<string, 'LLM' | 'TOOL'>> = { 'model.call': 'LLM', 'tool.call': 'TOOL' }\n\n/**\n * The root span (`agent_app.turn`) carries the host's labels and the turn's\n * numbers: wall time, the share inside child spans, and the time credited to\n * each kind of span. Children follow under it.\n */\nexport function buildTurnTraceOtelSpans(snapshot: TurnTraceSnapshot, labels: TurnSpanAttrs = {}): OtlpSpan[] {\n const traceId = otlpTraceId(snapshot.traceId)\n const root = snapshot.rootSpanId\n const { summary } = snapshot\n const rootAttrs: Record<string, string | number | boolean> = {\n ...labels,\n 'openinference.span.kind': 'CHAIN',\n 'tangle.execution_id': snapshot.executionId,\n 'tangle.trace_id': snapshot.traceId,\n 'tangle.started_at_ms': snapshot.startedAt,\n 'tangle.completed_at_ms': snapshot.endedAt,\n 'tangle.duration_ms': summary.wallMs,\n 'tangle.turn.wall_ms': summary.wallMs,\n 'tangle.turn.covered_ms': summary.coveredMs,\n 'tangle.turn.coverage_pct': summary.coveragePct,\n 'tangle.turn.uncovered_ms': summary.uncoveredMs,\n 'tangle.turn.largest_gap_ms': summary.largestGapMs,\n 'tangle.turn.spans': summary.spans,\n 'tangle.turn.model_calls': summary.modelCalls,\n 'tangle.turn.tool_calls': summary.toolCalls,\n ...(summary.firstTextMs === undefined ? {} : { 'tangle.turn.first_text_ms': summary.firstTextMs }),\n ...(summary.dropped ? { 'tangle.turn.spans_dropped': summary.dropped } : {}),\n ...Object.fromEntries(TURN_SPAN_KINDS.map((kind: TurnSpanKind) => [`tangle.turn.${kind}_ms`, summary.byKind[kind]])),\n }\n const spans: OtlpSpan[] = [{\n traceId,\n spanId: root,\n name: 'agent_app.turn',\n kind: 1,\n startTimeUnixNano: msToNs(snapshot.startedAt),\n endTimeUnixNano: msToNs(snapshot.endedAt),\n attributes: attributes(rootAttrs, ROOT_MEASUREMENTS),\n status: snapshot.status === 'ok' ? { code: 1 } : { code: 2, ...(snapshot.error ? { message: snapshot.error } : {}) },\n }]\n for (const span of snapshot.spans) {\n const attrs: Record<string, string | number | boolean> = {\n ...span.attrs,\n 'openinference.span.kind': SPAN_KIND[span.name] ?? 'CHAIN',\n 'tangle.turn.span_kind': span.kind,\n 'agent.parent.confidence': 'explicit',\n ...(span.name === 'tool.call' ? { 'gen_ai.operation.name': 'execute_tool' } : {}),\n ...(span.unfinished ? { 'tangle.turn.unfinished': true } : {}),\n ...(span.error ? { 'error.message': span.error } : {}),\n }\n spans.push({\n traceId,\n spanId: span.spanId,\n parentSpanId: span.parentSpanId,\n name: span.name,\n kind: 1,\n startTimeUnixNano: msToNs(span.startMs),\n endTimeUnixNano: msToNs(span.endMs),\n attributes: attributes(attrs),\n status: span.error ? { code: 2, message: span.error } : { code: 1 },\n })\n }\n return spans\n}\n\nexport interface IntelligenceTurnTraceSinkOptions {\n /** The Intelligence project the spans belong to, e.g. `legal-agent`. */\n project: string\n /**\n * The tenant key the ingest requires. Omit it: the sink reads the Sandbox product key from the first of\n * `SANDBOX_PRODUCTION_API_KEY`, `TCLOUD_SANDBOX_API_KEY` and `SANDBOX_API_KEY` that is set, the platform key the\n * ingest verifies. Legal's Worker `TANGLE_API_KEY` got 401 on every export (#468, 2026-10-19), so a key is never assumed: a refusal is a console warning.\n */\n apiKey?: string\n /** Default `https://intelligence.tangle.tools`; spans go to `<base>/v1/otlp/v1/traces`. */\n baseUrl?: string\n /** Called with a short reason when a delivery fails. Never receives span content. Default: a console warning. */\n onError?: (reason: string) => void\n /** Milliseconds one POST may take (default 5000). */\n timeoutMs?: number\n}\n\nconst DEFAULT_INTELLIGENCE_BASE_URL = 'https://intelligence.tangle.tools'\n/** The Sandbox product key names, in the order the apps' sandbox lanes prefer them. Read per delivery: a Worker's env is not populated at module scope. */\nconst INGEST_KEY_ENV = ['SANDBOX_PRODUCTION_API_KEY', 'TCLOUD_SANDBOX_API_KEY', 'SANDBOX_API_KEY'] as const\n\n/** The key the ingest verifies, from the host's environment: what the sink uses when it is given none, and what an app's other Intelligence client should use too. */\nexport function resolveIngestKey(): string | undefined {\n if (typeof process === 'undefined') return undefined\n for (const name of INGEST_KEY_ENV) {\n const value = process.env?.[name]?.trim()\n if (value) return value\n }\n return undefined\n}\nconst SCOPE = { name: '@tangle-network/agent-app', version: 'turn-trace' }\n\n/**\n * The sink a chat route or a Worker turn hands each finished trace to: one OTLP POST per turn, awaited, so a host that\n * runs it under `waitUntil` keeps the isolate alive until delivery. It never throws; every failure, including a missing\n * key and a non-2xx answer, goes to `onError` (a console warning by default), because a silent sink hid Legal's 401s.\n */\nexport function createIntelligenceTurnTraceSink(options: IntelligenceTurnTraceSinkOptions): TurnTraceSink {\n const url = `${(options.baseUrl ?? DEFAULT_INTELLIGENCE_BASE_URL).replace(/\\/+$/, '')}/v1/otlp/v1/traces`\n const report = options.onError ?? ((reason: string) => console.warn(`[turn-trace] export failed: ${reason}`))\n const fail = (reason: string) => { try { report(reason.slice(0, 200)) } catch { /* telemetry only */ } }\n let missingKeyReported = false\n return async (snapshot, labels) => {\n const apiKey = options.apiKey?.trim() || resolveIngestKey()\n if (!apiKey) {\n if (!missingKeyReported) fail(`no ingest key: set ${INGEST_KEY_ENV.join(', ')} or pass apiKey`)\n missingKeyReported = true\n return\n }\n try {\n const body = {\n resourceSpans: [{\n resource: { attributes: attributes({ 'service.name': options.project, 'tangle.project': options.project }) },\n scopeSpans: [{ scope: SCOPE, spans: buildTurnTraceOtelSpans(snapshot, { project: options.project, ...labels }) }],\n }],\n }\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json', authorization: `Bearer ${apiKey}` },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(options.timeoutMs ?? 5_000),\n })\n const text = await response.text()\n if (!response.ok) return fail(`HTTP ${response.status} from the OTLP ingest`)\n // A 2xx can still refuse part of a batch (`partialSuccess.rejectedSpans`).\n const rejected = Number((JSON.parse(text || '{}') as { partialSuccess?: { rejectedSpans?: unknown } }).partialSuccess?.rejectedSpans ?? 0)\n if (rejected > 0) fail(`the OTLP ingest rejected ${rejected} spans`)\n } catch (error) {\n fail(error instanceof Error ? error.message : 'turn trace export failed')\n }\n }\n}\n"],"mappings":";;;;;AA+BA,SAAS,WAAW,QAAmD,UAA+B,oBAAI,IAAI,GAA2B;AACvI,SAAO,OAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAA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EAAG,MAAK,4BAA4B,QAAQ,QAAQ;AAAA,IACrE,SAAS,OAAO;AACd,WAAK,iBAAiB,QAAQ,MAAM,UAAU,0BAA0B;AAAA,IAC1E;AAAA,EACF;AACF;","names":[]}
|
|
@@ -119,7 +119,9 @@ var APP_DEFAULTS_STEP = "agent-app defaults";
|
|
|
119
119
|
var EXEMPTIBLE_DEFAULTS = ["turn-trace", "first-text", "prewarm", "placement", "limit-alarms"];
|
|
120
120
|
var AGENT_APP_OUTCOME_FLOORS = [
|
|
121
121
|
{ id: "turn-trace", label: "turn trace", since: "0.60.199" },
|
|
122
|
-
{ id: "first-text", label: "first text", since: "0.60.203" }
|
|
122
|
+
{ id: "first-text", label: "first text", since: "0.60.203" },
|
|
123
|
+
// createChatTurnRoutes exports every turn without a sink option, and a turn handed to `handoffCompletion` too.
|
|
124
|
+
{ id: "default-trace", label: "default turn trace", since: "0.60.221" }
|
|
123
125
|
];
|
|
124
126
|
var SOURCE_EXTENSIONS = /\.(?:[cm]?[jt]sx?)$/;
|
|
125
127
|
var NOT_SOURCE = /(?:^|\/)(?:node_modules|dist|build|\.wrangler|tests?|__tests__|e2e|scripts|proof|journeys?|evals?|docs|examples|stories|\.storybook)\/|\.(?:test|spec|stories|e2e|bench)\.[cm]?[jt]sx?$|\.d\.ts$/;
|
|
@@ -187,6 +189,24 @@ function callArguments(text, openIndex) {
|
|
|
187
189
|
}
|
|
188
190
|
return text.slice(openIndex, openIndex + 1200);
|
|
189
191
|
}
|
|
192
|
+
function namedString(text, args, property) {
|
|
193
|
+
const direct = new RegExp(`\\b${property}\\s*:\\s*['"\`]([^'"\`]+)['"\`]`).exec(args);
|
|
194
|
+
if (direct) return direct[1] ?? null;
|
|
195
|
+
const named = new RegExp(`\\b${property}\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[,}\\n]`).exec(args) ?? new RegExp(`\\b${property}\\b\\s*[,}]`).exec(args);
|
|
196
|
+
const identifier = named?.[1] ?? (named ? property : void 0);
|
|
197
|
+
if (!identifier) return null;
|
|
198
|
+
return new RegExp(`(?:const|let)\\s+${identifier}\\s*(?::\\s*string\\s*)?=\\s*['"\`]([^'"\`]+)['"\`]`).exec(text)?.[1] ?? null;
|
|
199
|
+
}
|
|
200
|
+
function routeProjects(sources) {
|
|
201
|
+
const calls = [];
|
|
202
|
+
for (const file of sources) {
|
|
203
|
+
for (const match of file.text.matchAll(/\bcreateChatTurnRoutes\s*(?:<[^>(]*>)?\s*\(/g)) {
|
|
204
|
+
const args = callArguments(file.text, match.index + match[0].length - 1);
|
|
205
|
+
calls.push({ file: file.path, args, project: namedString(file.text, args, "projectId") ?? namedString(file.text, file.text, "projectId") });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return calls;
|
|
209
|
+
}
|
|
190
210
|
function sinkCalls(sources) {
|
|
191
211
|
const calls = [];
|
|
192
212
|
for (const file of sources) {
|
|
@@ -220,17 +240,30 @@ function withExemption(row, id, exemptions, optedOut) {
|
|
|
220
240
|
}
|
|
221
241
|
return { row, finding: null };
|
|
222
242
|
}
|
|
223
|
-
function turnTraceRow(sources, calls, exports) {
|
|
243
|
+
function turnTraceRow(pin, sources, calls, exports) {
|
|
224
244
|
const optOut = filesMatching(sources, /\bturnTrace\s*:\s*false\b/)[0];
|
|
225
245
|
if (optOut) return { row: { id: "turn-trace", label: "turn trace", status: "gap", detail: "" }, optedOut: `turnTrace: false in ${optOut.path}`, wired: false };
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
246
|
+
const floor = AGENT_APP_OUTCOME_FLOORS.find((entry) => entry.id === "default-trace")?.since ?? "";
|
|
247
|
+
const tuple = pin === null ? null : versionTuple(pin);
|
|
248
|
+
const byDefault = tuple !== null && atLeast(tuple, floor);
|
|
249
|
+
const routes = routeProjects(sources);
|
|
250
|
+
const handoff = filesMatching(sources, /\bhandoffCompletion\b/)[0];
|
|
251
|
+
if (handoff && !byDefault) {
|
|
252
|
+
return {
|
|
253
|
+
row: { id: "turn-trace", label: "turn trace", status: "gap", detail: `${handoff.path} hands turns to a completion owner (handoffCompletion) and agent-app ${pin ?? "at this pin"} does not export a handed-off turn's trace; ${floor} does` },
|
|
254
|
+
optedOut: null,
|
|
255
|
+
wired: false
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const customSink = filesMatching(sources, /\bturnTrace\s*:\s*\{[^}]*\bsink\b/);
|
|
259
|
+
const defaulted = byDefault && routes.length > 0;
|
|
260
|
+
if (calls.length === 0 && customSink.length === 0 && !defaulted) {
|
|
261
|
+
return { row: { id: "turn-trace", label: "turn trace", status: "gap", detail: routes.length > 0 ? `no turn trace sink, and agent-app ${pin ?? "at this pin"} exports by default only from ${floor}` : "no turn trace sink; createChatTurnRoutes gets no turnTrace" }, optedOut: null, wired: false };
|
|
229
262
|
}
|
|
230
|
-
const project = calls.find((call) => call.project)?.project ?? null;
|
|
263
|
+
const project = calls.find((call) => call.project)?.project ?? (customSink.length === 0 ? routes.find((call) => call.project)?.project : void 0) ?? null;
|
|
231
264
|
const last = project === null ? void 0 : exports?.get(project);
|
|
232
|
-
const where = calls[0]?.file ?? customSink[0]?.path
|
|
233
|
-
const wired = `sink wired in ${where}${project ? ` (${project})` : ""}`;
|
|
265
|
+
const where = calls[0]?.file ?? customSink[0]?.path;
|
|
266
|
+
const wired = where ? `sink wired in ${where}${project ? ` (${project})` : ""}` : `createChatTurnRoutes exports every turn by default${project ? ` (${project})` : ""}`;
|
|
234
267
|
if (last) {
|
|
235
268
|
return { row: { id: "turn-trace", label: "turn trace", status: "ok", detail: `${wired}; last export accepted ${new Date(last.at).toISOString().slice(0, 16)}Z` }, optedOut: null, wired: true };
|
|
236
269
|
}
|
|
@@ -251,7 +284,7 @@ function firstTextRow(pin, sources, traceWired, calls, exports) {
|
|
|
251
284
|
if (!traceWired) return { id: "first-text", label: "first text", status: "gap", detail: "needs the turn trace" };
|
|
252
285
|
if (tuple !== null && !atLeast(tuple, floor)) return { id: "first-text", label: "first text", status: "gap", detail: `agent-app ${pin} does not mark first text; ${floor} does` };
|
|
253
286
|
if (!routes && !marks) return { id: "first-text", label: "first text", status: "gap", detail: "the turn owner does not call trace.markFirstText() and the app does not use createChatTurnRoutes" };
|
|
254
|
-
const project = calls.find((call) => call.project)?.project ?? null;
|
|
287
|
+
const project = calls.find((call) => call.project)?.project ?? routeProjects(sources).find((call) => call.project)?.project ?? null;
|
|
255
288
|
const last = project === null ? void 0 : exports?.get(project);
|
|
256
289
|
const observed = last?.firstTextMs === void 0 ? "" : `; last turn first_text_ms ${Math.round(last.firstTextMs)}`;
|
|
257
290
|
if (last && last.firstTextMs === void 0) return { id: "first-text", label: "first text", status: "gap", detail: "the last exported turn has no tangle.turn.first_text_ms" };
|
|
@@ -340,7 +373,7 @@ ${run.stderr}`);
|
|
|
340
373
|
}
|
|
341
374
|
}
|
|
342
375
|
function toolCountRow() {
|
|
343
|
-
return { id: "tool-count", label: "
|
|
376
|
+
return { id: "tool-count", label: "tool calls p50", status: "unknown", detail: "tangle.turn.tool_calls on each root span; no ceiling until a measured link to first text exists" };
|
|
344
377
|
}
|
|
345
378
|
function checkAppDefaults(repoRoot, options = {}) {
|
|
346
379
|
const tracked = trackedFiles(repoRoot);
|
|
@@ -359,7 +392,7 @@ function checkAppDefaults(repoRoot, options = {}) {
|
|
|
359
392
|
const exemptions = options.exemptions ?? {};
|
|
360
393
|
const pin = versionTuple(pkg.spec) ? /(\d+\.\d+\.\d+)/.exec(pkg.spec)?.[1] ?? null : null;
|
|
361
394
|
const calls = sinkCalls(sources);
|
|
362
|
-
const trace = turnTraceRow(sources, calls, options.exports);
|
|
395
|
+
const trace = turnTraceRow(pin, sources, calls, options.exports);
|
|
363
396
|
const traceWired = trace.wired;
|
|
364
397
|
const reports = [
|
|
365
398
|
{ row: pinRow(pin, pkg.spec), id: null, optedOut: null },
|
|
@@ -437,7 +470,8 @@ async function collectLastExports(repoRoot, apiKey) {
|
|
|
437
470
|
const tracked = trackedFiles(repoRoot);
|
|
438
471
|
const projects = /* @__PURE__ */ new Set();
|
|
439
472
|
for (const pkg of findAppPackages(repoRoot, tracked)) {
|
|
440
|
-
|
|
473
|
+
const sources = readSources(repoRoot, tracked, pkg.dir, []);
|
|
474
|
+
for (const call of [...sinkCalls(sources), ...routeProjects(sources)]) if (call.project) projects.add(call.project);
|
|
441
475
|
}
|
|
442
476
|
const exports = /* @__PURE__ */ new Map();
|
|
443
477
|
for (const project of projects) {
|
|
@@ -2785,4 +2819,4 @@ export {
|
|
|
2785
2819
|
formatWorkspaceSurfaceReport,
|
|
2786
2820
|
runWorkspaceSurfaceCli
|
|
2787
2821
|
};
|
|
2788
|
-
//# sourceMappingURL=chunk-
|
|
2822
|
+
//# sourceMappingURL=chunk-N7WTF5P2.js.map
|