@tangle-network/agent-runtime 0.105.0 → 0.106.1
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 +2 -2
- package/dist/activation-CRjVfOiy.js +203 -0
- package/dist/activation-CRjVfOiy.js.map +1 -0
- package/dist/activation-DyWB0K6E.d.ts +98 -0
- package/dist/agent.d.ts +216 -234
- package/dist/agent.js +615 -547
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop-DGdtVENg.js +517 -0
- package/dist/analyst-loop-DGdtVENg.js.map +1 -0
- package/dist/analyst-loop.d.ts +10 -43
- package/dist/analyst-loop.js +2 -11
- package/dist/backends-CiOCyRHb.js +743 -0
- package/dist/backends-CiOCyRHb.js.map +1 -0
- package/dist/candidate-execution/index.d.ts +4 -192
- package/dist/candidate-execution/index.js +5 -66
- package/dist/candidate-execution-DqMbv1rU.js +488 -0
- package/dist/candidate-execution-DqMbv1rU.js.map +1 -0
- package/dist/coder-yhVWbdWc.js +40 -0
- package/dist/coder-yhVWbdWc.js.map +1 -0
- package/dist/conversation-BpLQZGPH.js +1265 -0
- package/dist/conversation-BpLQZGPH.js.map +1 -0
- package/dist/conversation.d.ts +2 -804
- package/dist/conversation.js +2 -55
- package/dist/environment-provider-CfLUmKmf.js +1168 -0
- package/dist/environment-provider-CfLUmKmf.js.map +1 -0
- package/dist/environment-provider-IUGU3epE.d.ts +964 -0
- package/dist/environment-provider.d.ts +2 -78
- package/dist/environment-provider.js +2 -18
- package/dist/errors-DEAvWQPy.js +111 -0
- package/dist/errors-DEAvWQPy.js.map +1 -0
- package/dist/improvement-adapter-Cr5TBSji.d.ts +166 -0
- package/dist/improvement-cycle-C095kS_g.js +2624 -0
- package/dist/improvement-cycle-C095kS_g.js.map +1 -0
- package/dist/index-BGdxAwfO.d.ts +838 -0
- package/dist/index-C-FYUuFG.d.ts +193 -0
- package/dist/index-CbNM40xG.d.ts +140 -0
- package/dist/index-DruSKs3Z.d.ts +7224 -0
- package/dist/index-Efjb3nrQ.d.ts +671 -0
- package/dist/index.d.ts +14 -1058
- package/dist/index.js +2106 -2082
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +768 -889
- package/dist/intelligence.js +1466 -1367
- package/dist/intelligence.js.map +1 -1
- package/dist/{kb-gate-CwHO0vz6.d.ts → kb-gate-C8z2juK8.d.ts} +33 -31
- package/dist/kb-gate-DpaSwXVx.js +80 -0
- package/dist/kb-gate-DpaSwXVx.js.map +1 -0
- package/dist/knowledge-Ku-mPP4f.js +433 -0
- package/dist/knowledge-Ku-mPP4f.js.map +1 -0
- package/dist/knowledge.d.ts +2 -150
- package/dist/knowledge.js +2 -40
- package/dist/local-harness-Dh8PJ0ot.d.ts +455 -0
- package/dist/loop-runner-bin-BXsFEUcf.d.ts +162 -0
- package/dist/loop-runner-bin-CRagyuNb.js +268 -0
- package/dist/loop-runner-bin-CRagyuNb.js.map +1 -0
- package/dist/loop-runner-bin.d.ts +2 -15
- package/dist/loop-runner-bin.js +2 -24
- package/dist/loops.d.ts +5 -4164
- package/dist/loops.js +8 -419
- package/dist/mcp/bin.d.ts +1 -1
- package/dist/mcp/bin.js +116 -146
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +295 -436
- package/dist/mcp/index.js +1242 -1177
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/memory-bin.d.ts +1 -1
- package/dist/mcp/memory-bin.js +37 -16
- package/dist/mcp/memory-bin.js.map +1 -1
- package/dist/memory-server-DL6cE2Ag.js +234 -0
- package/dist/memory-server-DL6cE2Ag.js.map +1 -0
- package/dist/model-resolution-Btd9iIKV.js +98 -0
- package/dist/model-resolution-Btd9iIKV.js.map +1 -0
- package/dist/openai-tools-B68JaOCx.d.ts +24 -0
- package/dist/openai-tools-CKLy1C7M.js +44 -0
- package/dist/openai-tools-CKLy1C7M.js.map +1 -0
- package/dist/otel-export-D34IQW1C.js +843 -0
- package/dist/otel-export-D34IQW1C.js.map +1 -0
- package/dist/platform.d.ts +188 -185
- package/dist/platform.js +185 -218
- package/dist/platform.js.map +1 -1
- package/dist/prepare-B53sPV7M.js +4292 -0
- package/dist/prepare-B53sPV7M.js.map +1 -0
- package/dist/primeintellect/index.d.ts +149 -145
- package/dist/primeintellect/index.js +626 -1003
- package/dist/primeintellect/index.js.map +1 -1
- package/dist/profiles.d.ts +296 -490
- package/dist/profiles.js +722 -749
- package/dist/profiles.js.map +1 -1
- package/dist/protected-model-port-BLPH5VVv.js +722 -0
- package/dist/protected-model-port-BLPH5VVv.js.map +1 -0
- package/dist/protected-model-port-BP6Z4eau.d.ts +283 -0
- package/dist/protected-redaction--F3v1oo8.js +200 -0
- package/dist/protected-redaction--F3v1oo8.js.map +1 -0
- package/dist/redact-D-u-rrcn.js +82 -0
- package/dist/redact-D-u-rrcn.js.map +1 -0
- package/dist/redact-kbIOjfjM.d.ts +452 -0
- package/dist/researcher-CoVqNhfI.js +433 -0
- package/dist/researcher-CoVqNhfI.js.map +1 -0
- package/dist/runtime-5zM5XxLr.js +5408 -0
- package/dist/runtime-5zM5XxLr.js.map +1 -0
- package/dist/sandbox-events-DeI5xX8P.js +316 -0
- package/dist/sandbox-events-DeI5xX8P.js.map +1 -0
- package/dist/spawn-journal-CwPvKUTa.js +456 -0
- package/dist/spawn-journal-CwPvKUTa.js.map +1 -0
- package/dist/structural-rollout-IXUEplky.js +1445 -0
- package/dist/structural-rollout-IXUEplky.js.map +1 -0
- package/dist/substrate-B0TYNrXn.js +27 -0
- package/dist/substrate-B0TYNrXn.js.map +1 -0
- package/dist/{substrate-Dyiqmd3o.d.ts → substrate-BcnuSHXm.d.ts} +57 -54
- package/dist/supervise-BiRutHS9.js +7321 -0
- package/dist/supervise-BiRutHS9.js.map +1 -0
- package/dist/supervisor-DTKhF-RV.js +3826 -0
- package/dist/supervisor-DTKhF-RV.js.map +1 -0
- package/dist/testing.d.ts +4 -3
- package/dist/testing.js +2478 -2637
- package/dist/testing.js.map +1 -1
- package/dist/tool-server-RcWgLIsL.js +141 -0
- package/dist/tool-server-RcWgLIsL.js.map +1 -0
- package/dist/trace-propagation-CJJC7SVB.js +57 -0
- package/dist/trace-propagation-CJJC7SVB.js.map +1 -0
- package/dist/types-BaIpb0XT.d.ts +492 -0
- package/dist/types-BevOjfTY.d.ts +765 -0
- package/dist/types-C9j4qg6l.d.ts +500 -0
- package/dist/types-Cja5OTGh.d.ts +190 -0
- package/dist/util-MVgdwuIS.js +145 -0
- package/dist/util-MVgdwuIS.js.map +1 -0
- package/dist/workspace-archive-BosQiotA.js +575 -0
- package/dist/workspace-archive-BosQiotA.js.map +1 -0
- package/package.json +44 -56
- package/skills/build-with-agent-runtime/SKILL.md +1 -0
- package/dist/activation-Cm-9MMX1.d.ts +0 -69
- package/dist/analyst-loop.js.map +0 -1
- package/dist/backends-BO4Jqoe2.d.ts +0 -134
- package/dist/candidate-execution/index.js.map +0 -1
- package/dist/chunk-2KGAN2HM.js +0 -1256
- package/dist/chunk-2KGAN2HM.js.map +0 -1
- package/dist/chunk-2VZYRB55.js +0 -834
- package/dist/chunk-2VZYRB55.js.map +0 -1
- package/dist/chunk-3MDZX7YU.js +0 -125
- package/dist/chunk-3MDZX7YU.js.map +0 -1
- package/dist/chunk-5IBQAPVB.js +0 -29
- package/dist/chunk-5IBQAPVB.js.map +0 -1
- package/dist/chunk-5QOB7H74.js +0 -387
- package/dist/chunk-5QOB7H74.js.map +0 -1
- package/dist/chunk-C5RTIBNZ.js +0 -48
- package/dist/chunk-C5RTIBNZ.js.map +0 -1
- package/dist/chunk-CTRA64LY.js +0 -680
- package/dist/chunk-CTRA64LY.js.map +0 -1
- package/dist/chunk-DPEUKJRO.js +0 -27
- package/dist/chunk-DPEUKJRO.js.map +0 -1
- package/dist/chunk-FD2MBMOH.js +0 -494
- package/dist/chunk-FD2MBMOH.js.map +0 -1
- package/dist/chunk-H5QPIZNX.js +0 -907
- package/dist/chunk-H5QPIZNX.js.map +0 -1
- package/dist/chunk-HLKC4UYB.js +0 -3514
- package/dist/chunk-HLKC4UYB.js.map +0 -1
- package/dist/chunk-HNP72PNU.js +0 -192
- package/dist/chunk-HNP72PNU.js.map +0 -1
- package/dist/chunk-ISPWRSEC.js +0 -408
- package/dist/chunk-ISPWRSEC.js.map +0 -1
- package/dist/chunk-KRBFHMV6.js +0 -1228
- package/dist/chunk-KRBFHMV6.js.map +0 -1
- package/dist/chunk-M22PL4GH.js +0 -171
- package/dist/chunk-M22PL4GH.js.map +0 -1
- package/dist/chunk-NURIQBJQ.js +0 -72
- package/dist/chunk-NURIQBJQ.js.map +0 -1
- package/dist/chunk-OPVWXJ2H.js +0 -75
- package/dist/chunk-OPVWXJ2H.js.map +0 -1
- package/dist/chunk-PZZKQVQV.js +0 -52
- package/dist/chunk-PZZKQVQV.js.map +0 -1
- package/dist/chunk-Q2JSAVQ3.js +0 -671
- package/dist/chunk-Q2JSAVQ3.js.map +0 -1
- package/dist/chunk-RDOAVVHY.js +0 -699
- package/dist/chunk-RDOAVVHY.js.map +0 -1
- package/dist/chunk-SGKPNBXE.js +0 -60
- package/dist/chunk-SGKPNBXE.js.map +0 -1
- package/dist/chunk-SMQXZGLZ.js +0 -351
- package/dist/chunk-SMQXZGLZ.js.map +0 -1
- package/dist/chunk-UHEZW5BU.js +0 -2918
- package/dist/chunk-UHEZW5BU.js.map +0 -1
- package/dist/chunk-UPWGXKXB.js +0 -254
- package/dist/chunk-UPWGXKXB.js.map +0 -1
- package/dist/chunk-VISA6CI3.js +0 -200
- package/dist/chunk-VISA6CI3.js.map +0 -1
- package/dist/chunk-WMTCUOQL.js +0 -474
- package/dist/chunk-WMTCUOQL.js.map +0 -1
- package/dist/chunk-WRTOVNN4.js +0 -4728
- package/dist/chunk-WRTOVNN4.js.map +0 -1
- package/dist/chunk-WSTRQZYQ.js +0 -5576
- package/dist/chunk-WSTRQZYQ.js.map +0 -1
- package/dist/chunk-XBG2W2VW.js +0 -6434
- package/dist/chunk-XBG2W2VW.js.map +0 -1
- package/dist/chunk-YEJR7IXO.js +0 -68
- package/dist/chunk-YEJR7IXO.js.map +0 -1
- package/dist/chunk-YJZA2BIK.js +0 -1338
- package/dist/chunk-YJZA2BIK.js.map +0 -1
- package/dist/completion-gate-BMy5LGoP.d.ts +0 -256
- package/dist/conversation.js.map +0 -1
- package/dist/coordination-BZZSVYpZ.d.ts +0 -2570
- package/dist/environment-provider.js.map +0 -1
- package/dist/improvement-adapter-HAZz-7vK.d.ts +0 -203
- package/dist/knowledge.js.map +0 -1
- package/dist/local-harness-BDNcl6jI.d.ts +0 -175
- package/dist/loop-runner-bin-68aoM9-7.d.ts +0 -199
- package/dist/loop-runner-bin.js.map +0 -1
- package/dist/loops.js.map +0 -1
- package/dist/openai-tools-fnj6SRVg.d.ts +0 -46
- package/dist/protected-model-port-B4t-OQjL.d.ts +0 -271
- package/dist/redact-BuFjxBUJ.d.ts +0 -481
- package/dist/sanitize-DEbPNtyI.d.ts +0 -328
- package/dist/structural-rollout-DEh6CEsa.d.ts +0 -446
- package/dist/supervise-4_48wwvy.d.ts +0 -379
- package/dist/types-BCoemcXU.d.ts +0 -802
- package/dist/types-BwoZWq-i.d.ts +0 -510
- package/dist/types-Cbp72qyu.d.ts +0 -491
- package/dist/types-CmYCMbFT.d.ts +0 -203
- package/dist/types-CvNwMzQt.d.ts +0 -957
- package/dist/worktree-fanout-DxhAWr5Z.d.ts +0 -999
package/dist/chunk-2VZYRB55.js
DELETED
|
@@ -1,834 +0,0 @@
|
|
|
1
|
-
// src/sanitize.ts
|
|
2
|
-
function sanitizeKnowledgeReadinessReport(report, options = {}) {
|
|
3
|
-
return {
|
|
4
|
-
taskId: report.taskId,
|
|
5
|
-
readinessScore: report.readinessScore,
|
|
6
|
-
recommendedAction: report.recommendedAction,
|
|
7
|
-
severity: report.severity,
|
|
8
|
-
reason: report.reason,
|
|
9
|
-
blockingMissingRequirements: report.blockingMissingRequirements.map(
|
|
10
|
-
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
11
|
-
),
|
|
12
|
-
nonBlockingGaps: report.nonBlockingGaps.map(
|
|
13
|
-
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
14
|
-
),
|
|
15
|
-
evidenceCount: report.bundle.evidenceIds.length,
|
|
16
|
-
evidenceIds: options.includeEvidenceIds ? report.bundle.evidenceIds : void 0,
|
|
17
|
-
missingRequirementIds: report.bundle.missing.map((requirement) => requirement.id)
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function sanitizeAgentRuntimeEvent(event, options = {}) {
|
|
21
|
-
const base = { type: event.type, task: sanitizeTask(event.task, options) };
|
|
22
|
-
if (event.type === "readiness_start" || event.type === "task_start" || event.type === "control_start") {
|
|
23
|
-
return event.type === "control_start" ? { ...base, knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options) } : base;
|
|
24
|
-
}
|
|
25
|
-
if (event.type === "readiness_end") {
|
|
26
|
-
return { ...base, knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options) };
|
|
27
|
-
}
|
|
28
|
-
if (event.type === "questions_start") {
|
|
29
|
-
return {
|
|
30
|
-
...base,
|
|
31
|
-
questions: event.questions.map((question) => sanitizeQuestion(question, options))
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (event.type === "questions_end") {
|
|
35
|
-
return {
|
|
36
|
-
...base,
|
|
37
|
-
questions: event.questions.map((question) => sanitizeQuestion(question, options)),
|
|
38
|
-
userAnswers: options.includeUserAnswers ? event.userAnswers : redactRecord(event.userAnswers)
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (event.type === "acquisition_start") {
|
|
42
|
-
return { ...base, acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan) };
|
|
43
|
-
}
|
|
44
|
-
if (event.type === "acquisition_end") {
|
|
45
|
-
return {
|
|
46
|
-
...base,
|
|
47
|
-
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan),
|
|
48
|
-
acquiredEvidenceCount: event.acquiredEvidenceIds.length,
|
|
49
|
-
acquiredEvidenceIds: options.includeEvidenceIds ? event.acquiredEvidenceIds : void 0
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (event.type === "control_step") {
|
|
53
|
-
return { ...base, step: sanitizeControlStep(event.step, options) };
|
|
54
|
-
}
|
|
55
|
-
if (event.type === "control_end") {
|
|
56
|
-
return { ...base, control: sanitizeControlRun(event.control, options) };
|
|
57
|
-
}
|
|
58
|
-
return { ...base, status: event.status, reason: event.reason };
|
|
59
|
-
}
|
|
60
|
-
function sanitizeRuntimeStreamEvent(event, options = {}) {
|
|
61
|
-
const withTask = "task" in event && event.task ? { task: sanitizeTask(event.task, options) } : {};
|
|
62
|
-
const withSession = "session" in event && event.session ? { session: sanitizeRuntimeSession(event.session, options) } : {};
|
|
63
|
-
if (event.type === "readiness_end") {
|
|
64
|
-
return {
|
|
65
|
-
type: event.type,
|
|
66
|
-
...withTask,
|
|
67
|
-
timestamp: event.timestamp,
|
|
68
|
-
decision: event.decision,
|
|
69
|
-
knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options)
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (event.type === "questions_start") {
|
|
73
|
-
return {
|
|
74
|
-
type: event.type,
|
|
75
|
-
...withTask,
|
|
76
|
-
timestamp: event.timestamp,
|
|
77
|
-
questions: event.questions.map((question) => sanitizeQuestion(question, options))
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (event.type === "questions_end") {
|
|
81
|
-
return {
|
|
82
|
-
type: event.type,
|
|
83
|
-
...withTask,
|
|
84
|
-
timestamp: event.timestamp,
|
|
85
|
-
questions: event.questions.map((question) => sanitizeQuestion(question, options)),
|
|
86
|
-
userAnswers: options.includeUserAnswers ? event.userAnswers : redactRecord(event.userAnswers)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (event.type === "acquisition_start") {
|
|
90
|
-
return {
|
|
91
|
-
type: event.type,
|
|
92
|
-
...withTask,
|
|
93
|
-
timestamp: event.timestamp,
|
|
94
|
-
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan)
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
if (event.type === "acquisition_end") {
|
|
98
|
-
return {
|
|
99
|
-
type: event.type,
|
|
100
|
-
...withTask,
|
|
101
|
-
timestamp: event.timestamp,
|
|
102
|
-
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan),
|
|
103
|
-
acquiredEvidenceCount: event.acquiredEvidenceIds.length,
|
|
104
|
-
acquiredEvidenceIds: options.includeEvidenceIds ? event.acquiredEvidenceIds : void 0
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
if (event.type === "tool_call") {
|
|
108
|
-
return {
|
|
109
|
-
type: event.type,
|
|
110
|
-
...withTask,
|
|
111
|
-
...withSession,
|
|
112
|
-
timestamp: event.timestamp,
|
|
113
|
-
toolName: event.toolName,
|
|
114
|
-
toolCallId: event.toolCallId,
|
|
115
|
-
args: options.includeControlPayloads ? event.args : void 0
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (event.type === "tool_result") {
|
|
119
|
-
return {
|
|
120
|
-
type: event.type,
|
|
121
|
-
...withTask,
|
|
122
|
-
...withSession,
|
|
123
|
-
timestamp: event.timestamp,
|
|
124
|
-
toolName: event.toolName,
|
|
125
|
-
toolCallId: event.toolCallId,
|
|
126
|
-
result: options.includeControlPayloads ? event.result : void 0
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (event.type === "llm_call") {
|
|
130
|
-
return {
|
|
131
|
-
type: event.type,
|
|
132
|
-
...withTask,
|
|
133
|
-
...withSession,
|
|
134
|
-
timestamp: event.timestamp,
|
|
135
|
-
model: event.model,
|
|
136
|
-
tokensIn: event.tokensIn,
|
|
137
|
-
tokensOut: event.tokensOut,
|
|
138
|
-
costUsd: event.costUsd,
|
|
139
|
-
latencyMs: event.latencyMs,
|
|
140
|
-
finishReason: event.finishReason
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (event.type === "artifact") {
|
|
144
|
-
return {
|
|
145
|
-
type: event.type,
|
|
146
|
-
...withTask,
|
|
147
|
-
...withSession,
|
|
148
|
-
timestamp: event.timestamp,
|
|
149
|
-
artifactId: event.artifactId,
|
|
150
|
-
name: event.name,
|
|
151
|
-
mimeType: event.mimeType,
|
|
152
|
-
uri: options.includeEvidenceIds ? event.uri : void 0,
|
|
153
|
-
content: options.includeControlPayloads ? event.content : void 0,
|
|
154
|
-
metadata: options.includeMetadata ? event.metadata : void 0
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (event.type === "proposal_created") {
|
|
158
|
-
return {
|
|
159
|
-
type: event.type,
|
|
160
|
-
...withTask,
|
|
161
|
-
...withSession,
|
|
162
|
-
timestamp: event.timestamp,
|
|
163
|
-
proposalId: event.proposalId,
|
|
164
|
-
title: options.includeControlPayloads ? event.title : void 0,
|
|
165
|
-
content: options.includeControlPayloads ? event.content : void 0,
|
|
166
|
-
status: event.status
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
if (event.type === "final") {
|
|
170
|
-
const sanitizedError = event.error !== void 0 ? {
|
|
171
|
-
kind: event.error.kind,
|
|
172
|
-
message: event.error.message,
|
|
173
|
-
status: event.error.status,
|
|
174
|
-
body: options.includeControlPayloads ? event.error.body : void 0
|
|
175
|
-
} : void 0;
|
|
176
|
-
return {
|
|
177
|
-
type: event.type,
|
|
178
|
-
...withTask,
|
|
179
|
-
...withSession,
|
|
180
|
-
timestamp: event.timestamp,
|
|
181
|
-
status: event.status,
|
|
182
|
-
reason: event.reason,
|
|
183
|
-
text: options.includeControlPayloads ? event.text : void 0,
|
|
184
|
-
metadata: options.includeMetadata ? event.metadata : void 0,
|
|
185
|
-
...sanitizedError !== void 0 ? { error: sanitizedError } : {}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
type: event.type,
|
|
190
|
-
...withTask,
|
|
191
|
-
...withSession,
|
|
192
|
-
timestamp: "timestamp" in event ? event.timestamp : void 0,
|
|
193
|
-
...pickPublicStreamFields(event)
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function sanitizeTask(task, options) {
|
|
197
|
-
return {
|
|
198
|
-
id: task.id,
|
|
199
|
-
intent: task.intent,
|
|
200
|
-
domain: task.domain,
|
|
201
|
-
inputs: options.includeInputs ? task.inputs : task.inputs ? "[redacted]" : void 0,
|
|
202
|
-
requiredKnowledge: task.requiredKnowledge?.map(
|
|
203
|
-
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
204
|
-
),
|
|
205
|
-
metadata: options.includeMetadata ? task.metadata : task.metadata ? "[redacted]" : void 0
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function sanitizeRuntimeSession(session, options) {
|
|
209
|
-
return {
|
|
210
|
-
id: session.id,
|
|
211
|
-
backend: session.backend,
|
|
212
|
-
status: session.status,
|
|
213
|
-
hasResumeToken: Boolean(session.resumeToken),
|
|
214
|
-
createdAt: session.createdAt,
|
|
215
|
-
updatedAt: session.updatedAt,
|
|
216
|
-
metadata: options.includeMetadata ? session.metadata : session.metadata ? "[redacted]" : void 0
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function sanitizeKnowledgeRequirement(requirement, options) {
|
|
220
|
-
const includeDescription = options.includeRequirementDescriptions && requirement.sensitivity !== "secret";
|
|
221
|
-
return {
|
|
222
|
-
id: requirement.id,
|
|
223
|
-
description: includeDescription ? requirement.description : void 0,
|
|
224
|
-
requiredFor: requirement.requiredFor,
|
|
225
|
-
category: requirement.category,
|
|
226
|
-
acquisitionMode: requirement.acquisitionMode,
|
|
227
|
-
importance: requirement.importance,
|
|
228
|
-
freshness: requirement.freshness,
|
|
229
|
-
sensitivity: requirement.sensitivity,
|
|
230
|
-
confidenceNeeded: requirement.confidenceNeeded,
|
|
231
|
-
currentConfidence: requirement.currentConfidence,
|
|
232
|
-
evidenceCount: requirement.evidenceIds.length,
|
|
233
|
-
evidenceIds: options.includeEvidenceIds ? requirement.evidenceIds : void 0,
|
|
234
|
-
fallbackPolicy: requirement.fallbackPolicy
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function sanitizeQuestion(question, options) {
|
|
238
|
-
return {
|
|
239
|
-
id: question.id,
|
|
240
|
-
question: options.includeRequirementDescriptions && question.answerType !== "credential" ? question.question : void 0,
|
|
241
|
-
reason: options.includeRequirementDescriptions ? question.reason : void 0,
|
|
242
|
-
requirementId: question.requirementId,
|
|
243
|
-
importance: question.importance,
|
|
244
|
-
answerType: question.answerType,
|
|
245
|
-
impactIfUnknown: options.includeRequirementDescriptions ? question.impactIfUnknown : void 0,
|
|
246
|
-
optionCount: question.options?.length ?? 0
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
function sanitizeAcquisitionPlan(plan) {
|
|
250
|
-
return {
|
|
251
|
-
id: plan.id,
|
|
252
|
-
requirementIds: plan.requirementIds,
|
|
253
|
-
mode: plan.mode,
|
|
254
|
-
priority: plan.priority,
|
|
255
|
-
expectedEvidenceCount: plan.expectedEvidenceIds?.length ?? 0,
|
|
256
|
-
questionCount: plan.questions?.length ?? 0
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function sanitizeControlStep(step, options) {
|
|
260
|
-
const actionOutcome = step.actionOutcome;
|
|
261
|
-
return {
|
|
262
|
-
index: step.index,
|
|
263
|
-
decisionType: step.decision.type,
|
|
264
|
-
reason: step.decision.reason,
|
|
265
|
-
action: options.includeControlPayloads && step.decision.type === "continue" ? step.decision.action : void 0,
|
|
266
|
-
result: options.includeControlPayloads && actionOutcome?.ok ? actionOutcome.result : void 0,
|
|
267
|
-
actionOk: actionOutcome?.ok,
|
|
268
|
-
actionError: actionOutcome?.ok === false ? actionOutcome.error : void 0,
|
|
269
|
-
durationMs: actionOutcome?.durationMs,
|
|
270
|
-
evalsBefore: summarizeEvals(step.evalsBefore, options),
|
|
271
|
-
evalsAfter: summarizeEvals(step.evalsAfter, options),
|
|
272
|
-
startedAt: step.startedAt,
|
|
273
|
-
endedAt: step.endedAt
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function sanitizeControlRun(control, options) {
|
|
277
|
-
return {
|
|
278
|
-
pass: control.pass,
|
|
279
|
-
completed: control.completed,
|
|
280
|
-
reason: control.reason,
|
|
281
|
-
score: control.score,
|
|
282
|
-
stepCount: control.steps.length,
|
|
283
|
-
wallMs: control.wallMs,
|
|
284
|
-
spentCostUsd: control.spentCostUsd,
|
|
285
|
-
failureClass: control.failureClass,
|
|
286
|
-
stoppedBy: control.stoppedBy,
|
|
287
|
-
runId: control.runId,
|
|
288
|
-
runtimeErrorCount: control.runtimeErrors.length,
|
|
289
|
-
finalEvals: summarizeEvals(control.finalEvals, options)
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function summarizeEvals(evals, options) {
|
|
293
|
-
return evals.map((evalResult) => ({
|
|
294
|
-
id: evalResult.id,
|
|
295
|
-
passed: evalResult.passed,
|
|
296
|
-
score: evalResult.score,
|
|
297
|
-
severity: evalResult.severity,
|
|
298
|
-
objective: evalResult.objective,
|
|
299
|
-
detail: options.includeEvalDetails ? evalResult.detail : void 0,
|
|
300
|
-
evidence: options.includeEvalDetails ? evalResult.evidence : void 0
|
|
301
|
-
}));
|
|
302
|
-
}
|
|
303
|
-
function redactRecord(record) {
|
|
304
|
-
return Object.fromEntries(Object.keys(record).map((key) => [key, "[redacted]"]));
|
|
305
|
-
}
|
|
306
|
-
function pickPublicStreamFields(event) {
|
|
307
|
-
if (event.type === "session_created" || event.type === "session_resumed") return {};
|
|
308
|
-
if (event.type === "backend_start" || event.type === "backend_end")
|
|
309
|
-
return { backend: event.backend };
|
|
310
|
-
if (event.type === "backend_error") {
|
|
311
|
-
const sanitizedError = event.error !== void 0 ? {
|
|
312
|
-
kind: event.error.kind,
|
|
313
|
-
status: event.error.status
|
|
314
|
-
} : void 0;
|
|
315
|
-
return {
|
|
316
|
-
backend: event.backend,
|
|
317
|
-
message: event.message,
|
|
318
|
-
recoverable: event.recoverable,
|
|
319
|
-
...sanitizedError !== void 0 ? { error: sanitizedError } : {}
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
if (event.type === "task_end") return { status: event.status, reason: event.reason };
|
|
323
|
-
if (event.type === "text_delta" || event.type === "reasoning_delta") return { text: event.text };
|
|
324
|
-
return {};
|
|
325
|
-
}
|
|
326
|
-
function createRuntimeEventCollector(options = {}) {
|
|
327
|
-
const events = [];
|
|
328
|
-
return {
|
|
329
|
-
events,
|
|
330
|
-
onEvent: (event) => {
|
|
331
|
-
events.push(sanitizeAgentRuntimeEvent(event, options));
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function createRuntimeStreamEventCollector(options = {}) {
|
|
336
|
-
const events = [];
|
|
337
|
-
const eventCountsByType = {};
|
|
338
|
-
let firstSessionId;
|
|
339
|
-
let finalStatus;
|
|
340
|
-
let finalReason;
|
|
341
|
-
let finalText = "";
|
|
342
|
-
return {
|
|
343
|
-
events,
|
|
344
|
-
onEvent: (event) => {
|
|
345
|
-
events.push(sanitizeRuntimeStreamEvent(event, options));
|
|
346
|
-
eventCountsByType[event.type] = (eventCountsByType[event.type] ?? 0) + 1;
|
|
347
|
-
if (event.type === "text_delta") finalText += event.text;
|
|
348
|
-
if (!firstSessionId && (event.type === "session_created" || event.type === "session_resumed")) {
|
|
349
|
-
firstSessionId = event.session.id;
|
|
350
|
-
}
|
|
351
|
-
if (event.type === "final") {
|
|
352
|
-
finalStatus = event.status;
|
|
353
|
-
finalReason = event.reason;
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
summary() {
|
|
357
|
-
return {
|
|
358
|
-
eventCount: events.length,
|
|
359
|
-
eventCountsByType: { ...eventCountsByType },
|
|
360
|
-
firstSessionId,
|
|
361
|
-
finalStatus,
|
|
362
|
-
finalReason,
|
|
363
|
-
finalText
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// src/otel-export.ts
|
|
370
|
-
var SCOPE = { name: "@tangle-network/agent-runtime", version: "0.83.0" };
|
|
371
|
-
var GEN_AI = {
|
|
372
|
-
operation: "gen_ai.operation.name",
|
|
373
|
-
agentName: "gen_ai.agent.name",
|
|
374
|
-
conversationId: "gen_ai.conversation.id",
|
|
375
|
-
inputTokens: "gen_ai.usage.input_tokens",
|
|
376
|
-
outputTokens: "gen_ai.usage.output_tokens"
|
|
377
|
-
};
|
|
378
|
-
function createOtelExporter(config) {
|
|
379
|
-
const resolvedEndpoint = config?.endpoint ?? (typeof process !== "undefined" ? process.env.OTEL_EXPORTER_OTLP_ENDPOINT : void 0);
|
|
380
|
-
if (!resolvedEndpoint) return void 0;
|
|
381
|
-
const endpoint = resolvedEndpoint;
|
|
382
|
-
const headers = config?.headers ?? parseHeadersFromEnv();
|
|
383
|
-
const batchSize = config?.batchSize ?? 64;
|
|
384
|
-
const flushIntervalMs = config?.flushIntervalMs ?? 5e3;
|
|
385
|
-
const serviceName = config?.serviceName ?? "agent-runtime";
|
|
386
|
-
const resourceAttrs = config?.resourceAttributes ?? {};
|
|
387
|
-
const pending = [];
|
|
388
|
-
let timer;
|
|
389
|
-
let stopped = false;
|
|
390
|
-
const exporter = {
|
|
391
|
-
exportSpan(span) {
|
|
392
|
-
if (stopped) return;
|
|
393
|
-
pending.push(span);
|
|
394
|
-
if (pending.length >= batchSize) {
|
|
395
|
-
void doFlush();
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
async flush() {
|
|
399
|
-
await doFlush();
|
|
400
|
-
},
|
|
401
|
-
async shutdown() {
|
|
402
|
-
stopped = true;
|
|
403
|
-
if (timer !== void 0) {
|
|
404
|
-
clearInterval(timer);
|
|
405
|
-
timer = void 0;
|
|
406
|
-
}
|
|
407
|
-
await doFlush();
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
timer = setInterval(() => {
|
|
411
|
-
if (pending.length > 0) void doFlush();
|
|
412
|
-
}, flushIntervalMs);
|
|
413
|
-
if (typeof timer === "object" && "unref" in timer) {
|
|
414
|
-
;
|
|
415
|
-
timer.unref();
|
|
416
|
-
}
|
|
417
|
-
async function doFlush() {
|
|
418
|
-
if (pending.length === 0) return;
|
|
419
|
-
const batch = pending.splice(0);
|
|
420
|
-
const body = {
|
|
421
|
-
resourceSpans: [
|
|
422
|
-
{
|
|
423
|
-
resource: {
|
|
424
|
-
attributes: toAttributes({
|
|
425
|
-
"service.name": serviceName,
|
|
426
|
-
...resourceAttrs
|
|
427
|
-
})
|
|
428
|
-
},
|
|
429
|
-
scopeSpans: [{ scope: SCOPE, spans: batch }]
|
|
430
|
-
}
|
|
431
|
-
]
|
|
432
|
-
};
|
|
433
|
-
const url = `${endpoint.replace(/\/+$/, "")}/v1/traces`;
|
|
434
|
-
try {
|
|
435
|
-
await fetch(url, {
|
|
436
|
-
method: "POST",
|
|
437
|
-
headers: { "content-type": "application/json", ...headers },
|
|
438
|
-
body: JSON.stringify(body)
|
|
439
|
-
});
|
|
440
|
-
} catch {
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return exporter;
|
|
444
|
-
}
|
|
445
|
-
function loopEventToOtelSpan(event, traceId, parentSpanId) {
|
|
446
|
-
const spanId = generateSpanId();
|
|
447
|
-
const attrs = {
|
|
448
|
-
"loop.event_kind": event.kind,
|
|
449
|
-
"loop.run_id": event.runId
|
|
450
|
-
};
|
|
451
|
-
for (const [k, v] of Object.entries(event.payload)) {
|
|
452
|
-
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
453
|
-
attrs[`loop.${k}`] = v;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
const ts = msToNs(event.timestamp);
|
|
457
|
-
return {
|
|
458
|
-
traceId: padTraceId(traceId),
|
|
459
|
-
spanId,
|
|
460
|
-
parentSpanId: parentSpanId ? padSpanId(parentSpanId) : void 0,
|
|
461
|
-
name: event.kind,
|
|
462
|
-
kind: 1,
|
|
463
|
-
startTimeUnixNano: ts,
|
|
464
|
-
endTimeUnixNano: ts,
|
|
465
|
-
attributes: toAttributes(attrs),
|
|
466
|
-
status: { code: 1 }
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
function flatOtelSpan(name, attributes, traceId, timestampMs, parentSpanId, endTimestampMs = timestampMs) {
|
|
470
|
-
const start = msToNs(timestampMs);
|
|
471
|
-
const end = msToNs(Math.max(timestampMs, endTimestampMs));
|
|
472
|
-
return {
|
|
473
|
-
traceId: padTraceId(traceId),
|
|
474
|
-
spanId: generateSpanId(),
|
|
475
|
-
parentSpanId: parentSpanId ? padSpanId(parentSpanId) : void 0,
|
|
476
|
-
name,
|
|
477
|
-
kind: 1,
|
|
478
|
-
startTimeUnixNano: start,
|
|
479
|
-
endTimeUnixNano: end,
|
|
480
|
-
attributes: toAttributes(attributes),
|
|
481
|
-
status: { code: 1 }
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
function eventTimestampMs(event) {
|
|
485
|
-
if ("timestamp" in event && typeof event.timestamp === "string") {
|
|
486
|
-
const parsed = Date.parse(event.timestamp);
|
|
487
|
-
if (Number.isFinite(parsed)) return parsed;
|
|
488
|
-
}
|
|
489
|
-
return Date.now();
|
|
490
|
-
}
|
|
491
|
-
function serialized(value) {
|
|
492
|
-
try {
|
|
493
|
-
return JSON.stringify(value) ?? String(value);
|
|
494
|
-
} catch {
|
|
495
|
-
return String(value);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function mcpIdentity(toolName) {
|
|
499
|
-
if (!toolName.startsWith("mcp__")) return {};
|
|
500
|
-
const [, server, ...toolParts] = toolName.split("__");
|
|
501
|
-
return {
|
|
502
|
-
...server ? { server } : {},
|
|
503
|
-
...toolParts.length > 0 ? { tool: toolParts.join("__") } : {}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
function buildRuntimeEventOtelSpans(events, traceId, parentSpanId, options = {}) {
|
|
507
|
-
return events.map((event) => {
|
|
508
|
-
const sanitized = sanitizeRuntimeStreamEvent(event, options);
|
|
509
|
-
const safe = options.redact ? options.redact(sanitized) : sanitized;
|
|
510
|
-
const record = safe && typeof safe === "object" && !Array.isArray(safe) ? safe : { value: safe };
|
|
511
|
-
const attrs = {
|
|
512
|
-
"tangle.runtime.event_type": event.type,
|
|
513
|
-
"tangle.runtime.event": serialized(record)
|
|
514
|
-
};
|
|
515
|
-
let name = `tangle.runtime.${event.type}`;
|
|
516
|
-
if (event.type === "tool_call" || event.type === "tool_result") {
|
|
517
|
-
name = `agent.${event.type}`;
|
|
518
|
-
attrs["tool.name"] = event.toolName;
|
|
519
|
-
if (event.toolCallId) attrs["tool.call_id"] = event.toolCallId;
|
|
520
|
-
const mcp = mcpIdentity(event.toolName);
|
|
521
|
-
if (mcp.server) attrs["mcp.server"] = mcp.server;
|
|
522
|
-
if (mcp.tool) attrs["mcp.tool.name"] = mcp.tool;
|
|
523
|
-
const payload = event.type === "tool_call" ? record.args : record.result;
|
|
524
|
-
if (payload !== void 0) {
|
|
525
|
-
attrs[event.type === "tool_call" ? "tool.input" : "tool.output"] = serialized(payload);
|
|
526
|
-
}
|
|
527
|
-
} else if (event.type === "llm_call") {
|
|
528
|
-
name = "gen_ai.client.inference";
|
|
529
|
-
attrs["gen_ai.request.model"] = event.model;
|
|
530
|
-
if (event.tokensIn !== void 0) attrs["gen_ai.usage.input_tokens"] = event.tokensIn;
|
|
531
|
-
if (event.tokensOut !== void 0) attrs["gen_ai.usage.output_tokens"] = event.tokensOut;
|
|
532
|
-
if (event.costUsd !== void 0) attrs["tangle.cost.usd"] = event.costUsd;
|
|
533
|
-
if (event.latencyMs !== void 0) attrs["tangle.latency_ms"] = event.latencyMs;
|
|
534
|
-
if (event.finishReason !== void 0)
|
|
535
|
-
attrs["gen_ai.response.finish_reasons"] = event.finishReason;
|
|
536
|
-
} else if (event.type === "backend_error") {
|
|
537
|
-
attrs["error.type"] = event.error?.kind ?? "backend";
|
|
538
|
-
attrs["error.message"] = event.message;
|
|
539
|
-
} else if (event.type === "final") {
|
|
540
|
-
attrs["tangle.outcome.status"] = event.status;
|
|
541
|
-
attrs["tangle.outcome.reason"] = event.reason;
|
|
542
|
-
if (event.error) {
|
|
543
|
-
attrs["error.type"] = event.error.kind;
|
|
544
|
-
attrs["error.message"] = event.error.message;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
const startMs = eventTimestampMs(event);
|
|
548
|
-
const endMs = event.type === "llm_call" && event.latencyMs !== void 0 && Number.isFinite(event.latencyMs) ? startMs + event.latencyMs : startMs;
|
|
549
|
-
const span = flatOtelSpan(name, attrs, traceId, startMs, parentSpanId, endMs);
|
|
550
|
-
if (event.type === "backend_error" || event.type === "final" && event.status !== "completed") {
|
|
551
|
-
span.status = { code: 2, message: attrs["error.message"]?.toString() ?? event.type };
|
|
552
|
-
}
|
|
553
|
-
return span;
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
function buildLoopOtelSpans(events, traceId, rootParentSpanId) {
|
|
557
|
-
const tid = padTraceId(traceId);
|
|
558
|
-
return buildLoopSpanNodes(events).map((node) => ({
|
|
559
|
-
traceId: tid,
|
|
560
|
-
spanId: node.spanId,
|
|
561
|
-
parentSpanId: node.parentSpanId ? padSpanId(node.parentSpanId) : rootParentSpanId ? padSpanId(rootParentSpanId) : void 0,
|
|
562
|
-
name: node.name,
|
|
563
|
-
kind: 1,
|
|
564
|
-
startTimeUnixNano: msToNs(node.startMs),
|
|
565
|
-
endTimeUnixNano: msToNs(node.endMs),
|
|
566
|
-
attributes: toAttributes(node.attrs),
|
|
567
|
-
status: { code: node.error ? 2 : 1 }
|
|
568
|
-
}));
|
|
569
|
-
}
|
|
570
|
-
function buildLoopSpanNodes(events) {
|
|
571
|
-
if (events.length === 0) return [];
|
|
572
|
-
const out = [];
|
|
573
|
-
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
574
|
-
const str = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
575
|
-
const rec = (v) => v && typeof v === "object" ? v : {};
|
|
576
|
-
const started = events.find((e) => e.kind === "loop.started");
|
|
577
|
-
const ended = events.find((e) => e.kind === "loop.ended");
|
|
578
|
-
const runId = events[0]?.runId ?? "";
|
|
579
|
-
const rootStart = started?.timestamp ?? events[0].timestamp;
|
|
580
|
-
const rootEnd = ended?.timestamp ?? events[events.length - 1].timestamp;
|
|
581
|
-
const rootId = generateSpanId();
|
|
582
|
-
const make = (spanId, parentSpanId, name, kind, startMs, endMs, attrs, error = false) => ({
|
|
583
|
-
spanId,
|
|
584
|
-
parentSpanId,
|
|
585
|
-
name,
|
|
586
|
-
kind,
|
|
587
|
-
startMs,
|
|
588
|
-
endMs,
|
|
589
|
-
attrs,
|
|
590
|
-
error
|
|
591
|
-
});
|
|
592
|
-
const sp = rec(started?.payload);
|
|
593
|
-
const rootAttrs = {
|
|
594
|
-
[GEN_AI.operation]: "invoke_workflow",
|
|
595
|
-
[GEN_AI.conversationId]: runId,
|
|
596
|
-
// Explicit run identity under the tangle namespace so a consuming system of
|
|
597
|
-
// record (Tangle Intelligence's run spine) maps this span tree to one run
|
|
598
|
-
// deterministically, instead of inferring it from the conversation id.
|
|
599
|
-
"tangle.run.id": runId,
|
|
600
|
-
"tangle.loop.driver": str(sp.driver) ?? "driver"
|
|
601
|
-
};
|
|
602
|
-
if (Array.isArray(sp.agentRunNames) && sp.agentRunNames.length > 0) {
|
|
603
|
-
rootAttrs["tangle.loop.agents"] = sp.agentRunNames.map(String).join(",");
|
|
604
|
-
rootAttrs["tangle.subject.key"] = String(sp.agentRunNames[0]);
|
|
605
|
-
}
|
|
606
|
-
if (ended) {
|
|
607
|
-
const ep = rec(ended.payload);
|
|
608
|
-
const win = num(ep.winnerIterationIndex);
|
|
609
|
-
if (win !== void 0) rootAttrs["tangle.loop.winner.iteration_index"] = win;
|
|
610
|
-
const cost = num(ep.totalCostUsd);
|
|
611
|
-
if (cost !== void 0) rootAttrs["tangle.cost.usd"] = cost;
|
|
612
|
-
const dur = num(ep.durationMs);
|
|
613
|
-
if (dur !== void 0) rootAttrs["tangle.loop.duration_ms"] = dur;
|
|
614
|
-
const iters = num(ep.iterations);
|
|
615
|
-
if (iters !== void 0) rootAttrs["tangle.loop.iterations"] = iters;
|
|
616
|
-
}
|
|
617
|
-
out.push(make(rootId, void 0, "loop", "loop", rootStart, rootEnd, rootAttrs));
|
|
618
|
-
const iterStartTs = /* @__PURE__ */ new Map();
|
|
619
|
-
const placementByIdx = /* @__PURE__ */ new Map();
|
|
620
|
-
let currentRoundId;
|
|
621
|
-
let pendingRound;
|
|
622
|
-
const flushRound = (endMs) => {
|
|
623
|
-
if (!pendingRound) return;
|
|
624
|
-
out.push(
|
|
625
|
-
make(
|
|
626
|
-
pendingRound.id,
|
|
627
|
-
rootId,
|
|
628
|
-
"loop.round",
|
|
629
|
-
"round",
|
|
630
|
-
pendingRound.start,
|
|
631
|
-
endMs,
|
|
632
|
-
pendingRound.attrs
|
|
633
|
-
)
|
|
634
|
-
);
|
|
635
|
-
pendingRound = void 0;
|
|
636
|
-
};
|
|
637
|
-
for (const e of events) {
|
|
638
|
-
const p = rec(e.payload);
|
|
639
|
-
switch (e.kind) {
|
|
640
|
-
case "loop.plan": {
|
|
641
|
-
flushRound(e.timestamp);
|
|
642
|
-
const id = generateSpanId();
|
|
643
|
-
const roundIdx = num(p.roundIndex) ?? 0;
|
|
644
|
-
const attrs = {
|
|
645
|
-
[GEN_AI.operation]: "invoke_workflow",
|
|
646
|
-
"tangle.loop.round.index": roundIdx,
|
|
647
|
-
"tangle.loop.move.kind": str(p.moveKind) ?? "unknown",
|
|
648
|
-
"tangle.loop.move.round": roundIdx,
|
|
649
|
-
"tangle.loop.move.width": num(p.plannedCount) ?? 0
|
|
650
|
-
};
|
|
651
|
-
const r = str(p.rationale);
|
|
652
|
-
if (r) attrs["tangle.loop.move.rationale"] = r;
|
|
653
|
-
const parent = num(p.parentIndex);
|
|
654
|
-
if (parent !== void 0) attrs["tangle.loop.move.parent_index"] = parent;
|
|
655
|
-
if (Array.isArray(p.childIndices) && p.childIndices.length > 0) {
|
|
656
|
-
attrs["tangle.loop.move.child_indices"] = p.childIndices.map(String).join(",");
|
|
657
|
-
}
|
|
658
|
-
pendingRound = { id, start: e.timestamp, attrs };
|
|
659
|
-
currentRoundId = id;
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
case "loop.iteration.started": {
|
|
663
|
-
const idx = num(p.iterationIndex);
|
|
664
|
-
if (idx !== void 0) iterStartTs.set(idx, e.timestamp);
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
case "loop.iteration.dispatch": {
|
|
668
|
-
const idx = num(p.iterationIndex);
|
|
669
|
-
if (idx === void 0) break;
|
|
670
|
-
const place = {};
|
|
671
|
-
const kind = str(p.placement);
|
|
672
|
-
if (kind) place["tangle.loop.placement.kind"] = kind;
|
|
673
|
-
const sid = str(p.sandboxId);
|
|
674
|
-
if (sid) place["tangle.sandbox.id"] = sid;
|
|
675
|
-
const fid = str(p.fleetId);
|
|
676
|
-
if (fid) place["tangle.fleet.id"] = fid;
|
|
677
|
-
const mid = str(p.machineId);
|
|
678
|
-
if (mid) place["tangle.machine.id"] = mid;
|
|
679
|
-
placementByIdx.set(idx, place);
|
|
680
|
-
break;
|
|
681
|
-
}
|
|
682
|
-
case "loop.iteration.ended": {
|
|
683
|
-
const idx = num(p.iterationIndex) ?? 0;
|
|
684
|
-
const start = iterStartTs.get(idx) ?? e.timestamp;
|
|
685
|
-
const err = str(p.error);
|
|
686
|
-
const attrs = {
|
|
687
|
-
[GEN_AI.operation]: "invoke_agent",
|
|
688
|
-
"tangle.loop.iteration.index": idx
|
|
689
|
-
};
|
|
690
|
-
const agent = str(p.agentRunName);
|
|
691
|
-
if (agent) attrs[GEN_AI.agentName] = agent;
|
|
692
|
-
const tu = rec(p.tokenUsage);
|
|
693
|
-
const inTok = num(tu.input);
|
|
694
|
-
if (inTok !== void 0) attrs[GEN_AI.inputTokens] = inTok;
|
|
695
|
-
const outTok = num(tu.output);
|
|
696
|
-
if (outTok !== void 0) attrs[GEN_AI.outputTokens] = outTok;
|
|
697
|
-
const cost = num(p.costUsd);
|
|
698
|
-
if (cost !== void 0) attrs["tangle.cost.usd"] = cost;
|
|
699
|
-
const verdict = rec(p.verdict);
|
|
700
|
-
if (typeof verdict.valid === "boolean") attrs["tangle.loop.verdict.valid"] = verdict.valid;
|
|
701
|
-
const score = num(verdict.score);
|
|
702
|
-
if (score !== void 0) attrs["tangle.loop.verdict.score"] = score;
|
|
703
|
-
if (err) attrs["tangle.loop.error"] = err;
|
|
704
|
-
const gid = num(p.groupId);
|
|
705
|
-
if (gid !== void 0) attrs["tangle.loop.iteration.group_id"] = gid;
|
|
706
|
-
const par = num(p.parentIndex);
|
|
707
|
-
if (par !== void 0) attrs["tangle.loop.iteration.parent_index"] = par;
|
|
708
|
-
const dur = num(p.durationMs);
|
|
709
|
-
if (dur !== void 0) attrs["tangle.loop.iteration.duration_ms"] = dur;
|
|
710
|
-
const preview = str(p.outputPreview);
|
|
711
|
-
if (preview) attrs["tangle.loop.iteration.output_preview"] = preview;
|
|
712
|
-
Object.assign(attrs, placementByIdx.get(idx) ?? {});
|
|
713
|
-
out.push(
|
|
714
|
-
make(
|
|
715
|
-
generateSpanId(),
|
|
716
|
-
currentRoundId ?? rootId,
|
|
717
|
-
"loop.iteration",
|
|
718
|
-
"branch",
|
|
719
|
-
start,
|
|
720
|
-
e.timestamp,
|
|
721
|
-
attrs,
|
|
722
|
-
err !== void 0
|
|
723
|
-
)
|
|
724
|
-
);
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
case "loop.decision": {
|
|
728
|
-
if (pendingRound) {
|
|
729
|
-
const dec = str(p.decision);
|
|
730
|
-
if (dec) pendingRound.attrs["tangle.loop.decision"] = dec;
|
|
731
|
-
flushRound(e.timestamp);
|
|
732
|
-
}
|
|
733
|
-
currentRoundId = void 0;
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
flushRound(rootEnd);
|
|
739
|
-
return out;
|
|
740
|
-
}
|
|
741
|
-
function parseHeadersFromEnv() {
|
|
742
|
-
if (typeof process === "undefined") return {};
|
|
743
|
-
const raw = process.env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
744
|
-
if (!raw) return {};
|
|
745
|
-
const out = {};
|
|
746
|
-
for (const pair of raw.split(",")) {
|
|
747
|
-
const eq = pair.indexOf("=");
|
|
748
|
-
if (eq < 0) continue;
|
|
749
|
-
const key = pair.slice(0, eq).trim();
|
|
750
|
-
const value = pair.slice(eq + 1).trim();
|
|
751
|
-
if (key) out[key] = value;
|
|
752
|
-
}
|
|
753
|
-
return out;
|
|
754
|
-
}
|
|
755
|
-
function toAttributes(record) {
|
|
756
|
-
return Object.entries(record).flatMap(([key, value]) => {
|
|
757
|
-
if (typeof value === "number" && !Number.isFinite(value)) return [];
|
|
758
|
-
return [
|
|
759
|
-
{
|
|
760
|
-
key,
|
|
761
|
-
value: typeof value === "number" ? Number.isInteger(value) ? { intValue: value.toString() } : { doubleValue: value } : typeof value === "boolean" ? { boolValue: value } : { stringValue: value }
|
|
762
|
-
}
|
|
763
|
-
];
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
function msToNs(ms) {
|
|
767
|
-
const safeMs = Number.isFinite(ms) ? ms : Date.now();
|
|
768
|
-
return (BigInt(Math.floor(safeMs)) * 1000000n).toString();
|
|
769
|
-
}
|
|
770
|
-
function padSpanId(id) {
|
|
771
|
-
const cleaned = id.replace(/-/g, "");
|
|
772
|
-
return cleaned.slice(0, 16).padEnd(16, "0");
|
|
773
|
-
}
|
|
774
|
-
function padTraceId(id) {
|
|
775
|
-
const cleaned = id.replace(/-/g, "");
|
|
776
|
-
return cleaned.slice(0, 32).padEnd(32, "0");
|
|
777
|
-
}
|
|
778
|
-
function generateSpanId() {
|
|
779
|
-
const bytes = new Uint8Array(8);
|
|
780
|
-
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
781
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
782
|
-
} else {
|
|
783
|
-
for (let i = 0; i < 8; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
784
|
-
}
|
|
785
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
786
|
-
}
|
|
787
|
-
var INTELLIGENCE_WIRE_VERSION = "2026-05-26.v1";
|
|
788
|
-
var DEFAULT_INTELLIGENCE_BASE = "https://intelligence.tangle.tools";
|
|
789
|
-
async function exportEvalRuns(events, config) {
|
|
790
|
-
if (events.length === 0) return { ok: true, status: 0, accepted: 0, rejected: [] };
|
|
791
|
-
const apiKey = config?.apiKey ?? (typeof process !== "undefined" ? process.env.TANGLE_API_KEY : void 0);
|
|
792
|
-
if (!apiKey)
|
|
793
|
-
throw new Error("exportEvalRuns: apiKey required (pass config.apiKey or set TANGLE_API_KEY)");
|
|
794
|
-
const base = config?.base ?? (typeof process !== "undefined" ? process.env.TANGLE_INTELLIGENCE_URL : void 0) ?? DEFAULT_INTELLIGENCE_BASE;
|
|
795
|
-
const url = `${base.replace(/\/+$/, "")}/v1/ingest/eval-runs`;
|
|
796
|
-
const res = await fetch(url, {
|
|
797
|
-
method: "POST",
|
|
798
|
-
headers: {
|
|
799
|
-
"content-type": "application/json",
|
|
800
|
-
authorization: `Bearer ${apiKey}`,
|
|
801
|
-
"X-Tangle-Wire-Version": INTELLIGENCE_WIRE_VERSION,
|
|
802
|
-
...config?.idempotencyKey ? { "Idempotency-Key": config.idempotencyKey } : {}
|
|
803
|
-
},
|
|
804
|
-
body: JSON.stringify({ wireVersion: INTELLIGENCE_WIRE_VERSION, events })
|
|
805
|
-
});
|
|
806
|
-
let parsed = {};
|
|
807
|
-
try {
|
|
808
|
-
parsed = await res.json();
|
|
809
|
-
} catch {
|
|
810
|
-
}
|
|
811
|
-
return {
|
|
812
|
-
ok: res.ok,
|
|
813
|
-
status: res.status,
|
|
814
|
-
accepted: parsed.accepted ?? (res.ok ? events.length : 0),
|
|
815
|
-
rejected: parsed.rejected ?? []
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
export {
|
|
820
|
-
sanitizeKnowledgeReadinessReport,
|
|
821
|
-
sanitizeAgentRuntimeEvent,
|
|
822
|
-
sanitizeRuntimeStreamEvent,
|
|
823
|
-
createRuntimeEventCollector,
|
|
824
|
-
createRuntimeStreamEventCollector,
|
|
825
|
-
createOtelExporter,
|
|
826
|
-
loopEventToOtelSpan,
|
|
827
|
-
flatOtelSpan,
|
|
828
|
-
buildRuntimeEventOtelSpans,
|
|
829
|
-
buildLoopOtelSpans,
|
|
830
|
-
buildLoopSpanNodes,
|
|
831
|
-
INTELLIGENCE_WIRE_VERSION,
|
|
832
|
-
exportEvalRuns
|
|
833
|
-
};
|
|
834
|
-
//# sourceMappingURL=chunk-2VZYRB55.js.map
|