@tangle-network/agent-runtime 0.94.13 → 0.96.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 +64 -15
- package/dist/activation-B0ZD7nfX.d.ts +63 -0
- package/dist/agent.d.ts +6 -193
- package/dist/agent.js +10 -234
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +7 -10
- package/dist/analyst-loop.js +1 -2
- package/dist/candidate-execution/index.d.ts +43 -16
- package/dist/candidate-execution/index.js +17 -8
- package/dist/{chunk-VYA2YEKA.js → chunk-2KGAN2HM.js} +83 -14
- package/dist/chunk-2KGAN2HM.js.map +1 -0
- package/dist/chunk-3XKSBI2U.js +474 -0
- package/dist/chunk-3XKSBI2U.js.map +1 -0
- package/dist/{chunk-TVJQAYQM.js → chunk-6XKPVJAZ.js} +107 -716
- package/dist/chunk-6XKPVJAZ.js.map +1 -0
- package/dist/chunk-BLQIYRVR.js +699 -0
- package/dist/chunk-BLQIYRVR.js.map +1 -0
- package/dist/{chunk-QDSOD7RC.js → chunk-FD2MBMOH.js} +13 -101
- package/dist/chunk-FD2MBMOH.js.map +1 -0
- package/dist/{chunk-U33YZ7B2.js → chunk-FXF2OL34.js} +8 -8
- package/dist/{chunk-EP6RVHMX.js → chunk-HZDEXTSL.js} +848 -2
- package/dist/chunk-HZDEXTSL.js.map +1 -0
- package/dist/{chunk-WIPGQ4GT.js → chunk-IMSNJSXH.js} +1 -1
- package/dist/{chunk-WIPGQ4GT.js.map → chunk-IMSNJSXH.js.map} +1 -1
- package/dist/{chunk-VSWBYWFK.js → chunk-M6MD6JBS.js} +20 -27
- package/dist/chunk-M6MD6JBS.js.map +1 -0
- package/dist/chunk-PSOCBNM3.js +2069 -0
- package/dist/chunk-PSOCBNM3.js.map +1 -0
- package/dist/{chunk-AEG3NGJ2.js → chunk-Q2JSAVQ3.js} +34 -2
- package/dist/chunk-Q2JSAVQ3.js.map +1 -0
- package/dist/{chunk-XP5KDM3R.js → chunk-SGQ4YIQW.js} +4 -4
- package/dist/{chunk-C3UKLQ54.js → chunk-UQ6PNNXM.js} +18 -10
- package/dist/chunk-UQ6PNNXM.js.map +1 -0
- package/dist/{chunk-33OG2NN3.js → chunk-WYC2XJF2.js} +2 -2
- package/dist/{chunk-ZEYAT33L.js → chunk-Y3SRWZMP.js} +2 -2
- package/dist/{chunk-CNH7DF7Z.js → chunk-YOLKCWRV.js} +1116 -591
- package/dist/chunk-YOLKCWRV.js.map +1 -0
- package/dist/{completion-gate-D1gX1-hg.d.ts → completion-gate-C80jiRfN.d.ts} +1 -1
- package/dist/conversation.d.ts +12 -1
- package/dist/conversation.js +2 -3
- package/dist/{coordination-Dr_axlAf.d.ts → coordination-BFE3Den7.d.ts} +10 -11
- package/dist/environment-provider.d.ts +2 -2
- package/dist/environment-provider.js +1 -2
- package/dist/{agentic-generator-DDMM45kZ.d.ts → improve-g75IE2Cx.d.ts} +152 -4
- package/dist/{improvement-adapter-BieWeK5J.d.ts → improvement-adapter-HAZz-7vK.d.ts} +8 -31
- package/dist/index.d.ts +55 -28
- package/dist/index.js +206 -82
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +185 -120
- package/dist/intelligence.js +509 -345
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +40 -12
- package/dist/knowledge.js +13 -7
- package/dist/{loop-runner-bin-BRQSQdHa.d.ts → loop-runner-bin-Cn1N2rRo.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +6 -6
- package/dist/loop-runner-bin.js +8 -10
- package/dist/loops.d.ts +13 -13
- package/dist/loops.js +6 -8
- package/dist/mcp/bin.js +5 -7
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.js +12 -14
- package/dist/mcp/index.js.map +1 -1
- package/dist/platform.js +0 -2
- package/dist/platform.js.map +1 -1
- package/dist/primeintellect/index.js +1 -2
- package/dist/primeintellect/index.js.map +1 -1
- package/dist/profile-DbfaMTdk.d.ts +233 -0
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.js +0 -1
- package/dist/profiles.js.map +1 -1
- package/dist/{supervise-DmYOug5f.d.ts → supervise-BLPI50-w.d.ts} +3 -3
- package/dist/{types-ByAYqlVb.d.ts → types-B3vAW0Oq.d.ts} +1 -1
- package/dist/{prepare-CtdtsFNG.d.ts → types-CWqfCO8s.d.ts} +67 -298
- package/dist/{types-BC3bZpH0.d.ts → types-CmYCMbFT.d.ts} +12 -54
- package/dist/{types-1d5QGK3t.d.ts → types-CmnA2iL3.d.ts} +3 -3
- package/dist/{worktree-fanout-CPprU-qI.d.ts → worktree-fanout-DCA3G4bO.d.ts} +3 -3
- package/package.json +14 -16
- package/skills/build-with-agent-runtime/SKILL.md +122 -213
- package/dist/chunk-6O73TRHW.js +0 -142
- package/dist/chunk-6O73TRHW.js.map +0 -1
- package/dist/chunk-AEG3NGJ2.js.map +0 -1
- package/dist/chunk-C3UKLQ54.js.map +0 -1
- package/dist/chunk-CNH7DF7Z.js.map +0 -1
- package/dist/chunk-D3H7F6L2.js +0 -626
- package/dist/chunk-D3H7F6L2.js.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -11
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-EP6RVHMX.js.map +0 -1
- package/dist/chunk-HGRW27YY.js +0 -214
- package/dist/chunk-HGRW27YY.js.map +0 -1
- package/dist/chunk-ISTDY47H.js +0 -849
- package/dist/chunk-ISTDY47H.js.map +0 -1
- package/dist/chunk-PCURO3DL.js +0 -661
- package/dist/chunk-PCURO3DL.js.map +0 -1
- package/dist/chunk-QDSOD7RC.js.map +0 -1
- package/dist/chunk-TVJQAYQM.js.map +0 -1
- package/dist/chunk-VSWBYWFK.js.map +0 -1
- package/dist/chunk-VYA2YEKA.js.map +0 -1
- package/dist/generator-YkAQrOoD.d.ts +0 -382
- package/dist/improve-BN3HyXIO.d.ts +0 -172
- package/dist/lifecycle.d.ts +0 -870
- package/dist/lifecycle.js +0 -981
- package/dist/lifecycle.js.map +0 -1
- package/dist/mcp-serve-verifier-DQQDbuyz.d.ts +0 -34
- package/skills/agent-runtime-adoption/SKILL.md +0 -246
- /package/dist/{chunk-U33YZ7B2.js.map → chunk-FXF2OL34.js.map} +0 -0
- /package/dist/{chunk-XP5KDM3R.js.map → chunk-SGQ4YIQW.js.map} +0 -0
- /package/dist/{chunk-33OG2NN3.js.map → chunk-WYC2XJF2.js.map} +0 -0
- /package/dist/{chunk-ZEYAT33L.js.map → chunk-Y3SRWZMP.js.map} +0 -0
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigError
|
|
3
|
+
} from "./chunk-YEJR7IXO.js";
|
|
4
|
+
|
|
1
5
|
// src/mcp/codex-diagnostics.ts
|
|
2
6
|
import { constants } from "fs";
|
|
3
7
|
import { open } from "fs/promises";
|
|
@@ -1091,10 +1095,852 @@ function naturalNumber(value, field) {
|
|
|
1091
1095
|
return value;
|
|
1092
1096
|
}
|
|
1093
1097
|
|
|
1098
|
+
// src/runtime/supervise/model-policy.ts
|
|
1099
|
+
function assertModelAllowed(model, allowed) {
|
|
1100
|
+
if (!allowed || model === void 0) return;
|
|
1101
|
+
if (!allowed.includes(model)) {
|
|
1102
|
+
throw new ConfigError(
|
|
1103
|
+
`model ${JSON.stringify(model)} is not in the allowed set ${JSON.stringify([...allowed])}`
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/sanitize.ts
|
|
1109
|
+
function sanitizeKnowledgeReadinessReport(report, options = {}) {
|
|
1110
|
+
return {
|
|
1111
|
+
taskId: report.taskId,
|
|
1112
|
+
readinessScore: report.readinessScore,
|
|
1113
|
+
recommendedAction: report.recommendedAction,
|
|
1114
|
+
severity: report.severity,
|
|
1115
|
+
reason: report.reason,
|
|
1116
|
+
blockingMissingRequirements: report.blockingMissingRequirements.map(
|
|
1117
|
+
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
1118
|
+
),
|
|
1119
|
+
nonBlockingGaps: report.nonBlockingGaps.map(
|
|
1120
|
+
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
1121
|
+
),
|
|
1122
|
+
evidenceCount: report.bundle.evidenceIds.length,
|
|
1123
|
+
evidenceIds: options.includeEvidenceIds ? report.bundle.evidenceIds : void 0,
|
|
1124
|
+
missingRequirementIds: report.bundle.missing.map((requirement) => requirement.id)
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
function sanitizeAgentRuntimeEvent(event, options = {}) {
|
|
1128
|
+
const base = { type: event.type, task: sanitizeTask(event.task, options) };
|
|
1129
|
+
if (event.type === "readiness_start" || event.type === "task_start" || event.type === "control_start") {
|
|
1130
|
+
return event.type === "control_start" ? { ...base, knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options) } : base;
|
|
1131
|
+
}
|
|
1132
|
+
if (event.type === "readiness_end") {
|
|
1133
|
+
return { ...base, knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options) };
|
|
1134
|
+
}
|
|
1135
|
+
if (event.type === "questions_start") {
|
|
1136
|
+
return {
|
|
1137
|
+
...base,
|
|
1138
|
+
questions: event.questions.map((question) => sanitizeQuestion(question, options))
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
if (event.type === "questions_end") {
|
|
1142
|
+
return {
|
|
1143
|
+
...base,
|
|
1144
|
+
questions: event.questions.map((question) => sanitizeQuestion(question, options)),
|
|
1145
|
+
userAnswers: options.includeUserAnswers ? event.userAnswers : redactRecord(event.userAnswers)
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
if (event.type === "acquisition_start") {
|
|
1149
|
+
return { ...base, acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan) };
|
|
1150
|
+
}
|
|
1151
|
+
if (event.type === "acquisition_end") {
|
|
1152
|
+
return {
|
|
1153
|
+
...base,
|
|
1154
|
+
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan),
|
|
1155
|
+
acquiredEvidenceCount: event.acquiredEvidenceIds.length,
|
|
1156
|
+
acquiredEvidenceIds: options.includeEvidenceIds ? event.acquiredEvidenceIds : void 0
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
if (event.type === "control_step") {
|
|
1160
|
+
return { ...base, step: sanitizeControlStep(event.step, options) };
|
|
1161
|
+
}
|
|
1162
|
+
if (event.type === "control_end") {
|
|
1163
|
+
return { ...base, control: sanitizeControlRun(event.control, options) };
|
|
1164
|
+
}
|
|
1165
|
+
return { ...base, status: event.status, reason: event.reason };
|
|
1166
|
+
}
|
|
1167
|
+
function sanitizeRuntimeStreamEvent(event, options = {}) {
|
|
1168
|
+
const withTask = "task" in event && event.task ? { task: sanitizeTask(event.task, options) } : {};
|
|
1169
|
+
const withSession = "session" in event && event.session ? { session: sanitizeRuntimeSession(event.session, options) } : {};
|
|
1170
|
+
if (event.type === "readiness_end") {
|
|
1171
|
+
return {
|
|
1172
|
+
type: event.type,
|
|
1173
|
+
...withTask,
|
|
1174
|
+
timestamp: event.timestamp,
|
|
1175
|
+
decision: event.decision,
|
|
1176
|
+
knowledge: sanitizeKnowledgeReadinessReport(event.knowledge, options)
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
if (event.type === "questions_start") {
|
|
1180
|
+
return {
|
|
1181
|
+
type: event.type,
|
|
1182
|
+
...withTask,
|
|
1183
|
+
timestamp: event.timestamp,
|
|
1184
|
+
questions: event.questions.map((question) => sanitizeQuestion(question, options))
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
if (event.type === "questions_end") {
|
|
1188
|
+
return {
|
|
1189
|
+
type: event.type,
|
|
1190
|
+
...withTask,
|
|
1191
|
+
timestamp: event.timestamp,
|
|
1192
|
+
questions: event.questions.map((question) => sanitizeQuestion(question, options)),
|
|
1193
|
+
userAnswers: options.includeUserAnswers ? event.userAnswers : redactRecord(event.userAnswers)
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
if (event.type === "acquisition_start") {
|
|
1197
|
+
return {
|
|
1198
|
+
type: event.type,
|
|
1199
|
+
...withTask,
|
|
1200
|
+
timestamp: event.timestamp,
|
|
1201
|
+
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan)
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
if (event.type === "acquisition_end") {
|
|
1205
|
+
return {
|
|
1206
|
+
type: event.type,
|
|
1207
|
+
...withTask,
|
|
1208
|
+
timestamp: event.timestamp,
|
|
1209
|
+
acquisitionPlans: event.acquisitionPlans.map(sanitizeAcquisitionPlan),
|
|
1210
|
+
acquiredEvidenceCount: event.acquiredEvidenceIds.length,
|
|
1211
|
+
acquiredEvidenceIds: options.includeEvidenceIds ? event.acquiredEvidenceIds : void 0
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
if (event.type === "tool_call") {
|
|
1215
|
+
return {
|
|
1216
|
+
type: event.type,
|
|
1217
|
+
...withTask,
|
|
1218
|
+
...withSession,
|
|
1219
|
+
timestamp: event.timestamp,
|
|
1220
|
+
toolName: event.toolName,
|
|
1221
|
+
toolCallId: event.toolCallId,
|
|
1222
|
+
args: options.includeControlPayloads ? event.args : void 0
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
if (event.type === "tool_result") {
|
|
1226
|
+
return {
|
|
1227
|
+
type: event.type,
|
|
1228
|
+
...withTask,
|
|
1229
|
+
...withSession,
|
|
1230
|
+
timestamp: event.timestamp,
|
|
1231
|
+
toolName: event.toolName,
|
|
1232
|
+
toolCallId: event.toolCallId,
|
|
1233
|
+
result: options.includeControlPayloads ? event.result : void 0
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
if (event.type === "llm_call") {
|
|
1237
|
+
return {
|
|
1238
|
+
type: event.type,
|
|
1239
|
+
...withTask,
|
|
1240
|
+
...withSession,
|
|
1241
|
+
timestamp: event.timestamp,
|
|
1242
|
+
model: event.model,
|
|
1243
|
+
tokensIn: event.tokensIn,
|
|
1244
|
+
tokensOut: event.tokensOut,
|
|
1245
|
+
costUsd: event.costUsd,
|
|
1246
|
+
latencyMs: event.latencyMs,
|
|
1247
|
+
finishReason: event.finishReason
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
if (event.type === "artifact") {
|
|
1251
|
+
return {
|
|
1252
|
+
type: event.type,
|
|
1253
|
+
...withTask,
|
|
1254
|
+
...withSession,
|
|
1255
|
+
timestamp: event.timestamp,
|
|
1256
|
+
artifactId: event.artifactId,
|
|
1257
|
+
name: event.name,
|
|
1258
|
+
mimeType: event.mimeType,
|
|
1259
|
+
uri: options.includeEvidenceIds ? event.uri : void 0,
|
|
1260
|
+
content: options.includeControlPayloads ? event.content : void 0,
|
|
1261
|
+
metadata: options.includeMetadata ? event.metadata : void 0
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
if (event.type === "proposal_created") {
|
|
1265
|
+
return {
|
|
1266
|
+
type: event.type,
|
|
1267
|
+
...withTask,
|
|
1268
|
+
...withSession,
|
|
1269
|
+
timestamp: event.timestamp,
|
|
1270
|
+
proposalId: event.proposalId,
|
|
1271
|
+
title: options.includeControlPayloads ? event.title : void 0,
|
|
1272
|
+
content: options.includeControlPayloads ? event.content : void 0,
|
|
1273
|
+
status: event.status
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
if (event.type === "final") {
|
|
1277
|
+
const sanitizedError = event.error !== void 0 ? {
|
|
1278
|
+
kind: event.error.kind,
|
|
1279
|
+
message: event.error.message,
|
|
1280
|
+
status: event.error.status,
|
|
1281
|
+
body: options.includeControlPayloads ? event.error.body : void 0
|
|
1282
|
+
} : void 0;
|
|
1283
|
+
return {
|
|
1284
|
+
type: event.type,
|
|
1285
|
+
...withTask,
|
|
1286
|
+
...withSession,
|
|
1287
|
+
timestamp: event.timestamp,
|
|
1288
|
+
status: event.status,
|
|
1289
|
+
reason: event.reason,
|
|
1290
|
+
text: options.includeControlPayloads ? event.text : void 0,
|
|
1291
|
+
metadata: options.includeMetadata ? event.metadata : void 0,
|
|
1292
|
+
...sanitizedError !== void 0 ? { error: sanitizedError } : {}
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
return {
|
|
1296
|
+
type: event.type,
|
|
1297
|
+
...withTask,
|
|
1298
|
+
...withSession,
|
|
1299
|
+
timestamp: "timestamp" in event ? event.timestamp : void 0,
|
|
1300
|
+
...pickPublicStreamFields(event)
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function sanitizeTask(task, options) {
|
|
1304
|
+
return {
|
|
1305
|
+
id: task.id,
|
|
1306
|
+
intent: task.intent,
|
|
1307
|
+
domain: task.domain,
|
|
1308
|
+
inputs: options.includeInputs ? task.inputs : task.inputs ? "[redacted]" : void 0,
|
|
1309
|
+
requiredKnowledge: task.requiredKnowledge?.map(
|
|
1310
|
+
(requirement) => sanitizeKnowledgeRequirement(requirement, options)
|
|
1311
|
+
),
|
|
1312
|
+
metadata: options.includeMetadata ? task.metadata : task.metadata ? "[redacted]" : void 0
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
function sanitizeRuntimeSession(session, options) {
|
|
1316
|
+
return {
|
|
1317
|
+
id: session.id,
|
|
1318
|
+
backend: session.backend,
|
|
1319
|
+
status: session.status,
|
|
1320
|
+
hasResumeToken: Boolean(session.resumeToken),
|
|
1321
|
+
createdAt: session.createdAt,
|
|
1322
|
+
updatedAt: session.updatedAt,
|
|
1323
|
+
metadata: options.includeMetadata ? session.metadata : session.metadata ? "[redacted]" : void 0
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function sanitizeKnowledgeRequirement(requirement, options) {
|
|
1327
|
+
const includeDescription = options.includeRequirementDescriptions && requirement.sensitivity !== "secret";
|
|
1328
|
+
return {
|
|
1329
|
+
id: requirement.id,
|
|
1330
|
+
description: includeDescription ? requirement.description : void 0,
|
|
1331
|
+
requiredFor: requirement.requiredFor,
|
|
1332
|
+
category: requirement.category,
|
|
1333
|
+
acquisitionMode: requirement.acquisitionMode,
|
|
1334
|
+
importance: requirement.importance,
|
|
1335
|
+
freshness: requirement.freshness,
|
|
1336
|
+
sensitivity: requirement.sensitivity,
|
|
1337
|
+
confidenceNeeded: requirement.confidenceNeeded,
|
|
1338
|
+
currentConfidence: requirement.currentConfidence,
|
|
1339
|
+
evidenceCount: requirement.evidenceIds.length,
|
|
1340
|
+
evidenceIds: options.includeEvidenceIds ? requirement.evidenceIds : void 0,
|
|
1341
|
+
fallbackPolicy: requirement.fallbackPolicy
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function sanitizeQuestion(question, options) {
|
|
1345
|
+
return {
|
|
1346
|
+
id: question.id,
|
|
1347
|
+
question: options.includeRequirementDescriptions && question.answerType !== "credential" ? question.question : void 0,
|
|
1348
|
+
reason: options.includeRequirementDescriptions ? question.reason : void 0,
|
|
1349
|
+
requirementId: question.requirementId,
|
|
1350
|
+
importance: question.importance,
|
|
1351
|
+
answerType: question.answerType,
|
|
1352
|
+
impactIfUnknown: options.includeRequirementDescriptions ? question.impactIfUnknown : void 0,
|
|
1353
|
+
optionCount: question.options?.length ?? 0
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
function sanitizeAcquisitionPlan(plan) {
|
|
1357
|
+
return {
|
|
1358
|
+
id: plan.id,
|
|
1359
|
+
requirementIds: plan.requirementIds,
|
|
1360
|
+
mode: plan.mode,
|
|
1361
|
+
priority: plan.priority,
|
|
1362
|
+
expectedEvidenceCount: plan.expectedEvidenceIds?.length ?? 0,
|
|
1363
|
+
questionCount: plan.questions?.length ?? 0
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
function sanitizeControlStep(step, options) {
|
|
1367
|
+
const actionOutcome = step.actionOutcome;
|
|
1368
|
+
return {
|
|
1369
|
+
index: step.index,
|
|
1370
|
+
decisionType: step.decision.type,
|
|
1371
|
+
reason: step.decision.reason,
|
|
1372
|
+
action: options.includeControlPayloads && step.decision.type === "continue" ? step.decision.action : void 0,
|
|
1373
|
+
result: options.includeControlPayloads && actionOutcome?.ok ? actionOutcome.result : void 0,
|
|
1374
|
+
actionOk: actionOutcome?.ok,
|
|
1375
|
+
actionError: actionOutcome?.ok === false ? actionOutcome.error : void 0,
|
|
1376
|
+
durationMs: actionOutcome?.durationMs,
|
|
1377
|
+
evalsBefore: summarizeEvals(step.evalsBefore, options),
|
|
1378
|
+
evalsAfter: summarizeEvals(step.evalsAfter, options),
|
|
1379
|
+
startedAt: step.startedAt,
|
|
1380
|
+
endedAt: step.endedAt
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
function sanitizeControlRun(control, options) {
|
|
1384
|
+
return {
|
|
1385
|
+
pass: control.pass,
|
|
1386
|
+
completed: control.completed,
|
|
1387
|
+
reason: control.reason,
|
|
1388
|
+
score: control.score,
|
|
1389
|
+
stepCount: control.steps.length,
|
|
1390
|
+
wallMs: control.wallMs,
|
|
1391
|
+
spentCostUsd: control.spentCostUsd,
|
|
1392
|
+
failureClass: control.failureClass,
|
|
1393
|
+
stoppedBy: control.stoppedBy,
|
|
1394
|
+
runId: control.runId,
|
|
1395
|
+
runtimeErrorCount: control.runtimeErrors.length,
|
|
1396
|
+
finalEvals: summarizeEvals(control.finalEvals, options)
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function summarizeEvals(evals, options) {
|
|
1400
|
+
return evals.map((evalResult) => ({
|
|
1401
|
+
id: evalResult.id,
|
|
1402
|
+
passed: evalResult.passed,
|
|
1403
|
+
score: evalResult.score,
|
|
1404
|
+
severity: evalResult.severity,
|
|
1405
|
+
objective: evalResult.objective,
|
|
1406
|
+
detail: options.includeEvalDetails ? evalResult.detail : void 0,
|
|
1407
|
+
evidence: options.includeEvalDetails ? evalResult.evidence : void 0
|
|
1408
|
+
}));
|
|
1409
|
+
}
|
|
1410
|
+
function redactRecord(record) {
|
|
1411
|
+
return Object.fromEntries(Object.keys(record).map((key) => [key, "[redacted]"]));
|
|
1412
|
+
}
|
|
1413
|
+
function pickPublicStreamFields(event) {
|
|
1414
|
+
if (event.type === "session_created" || event.type === "session_resumed") return {};
|
|
1415
|
+
if (event.type === "backend_start" || event.type === "backend_end")
|
|
1416
|
+
return { backend: event.backend };
|
|
1417
|
+
if (event.type === "backend_error") {
|
|
1418
|
+
const sanitizedError = event.error !== void 0 ? {
|
|
1419
|
+
kind: event.error.kind,
|
|
1420
|
+
status: event.error.status
|
|
1421
|
+
} : void 0;
|
|
1422
|
+
return {
|
|
1423
|
+
backend: event.backend,
|
|
1424
|
+
message: event.message,
|
|
1425
|
+
recoverable: event.recoverable,
|
|
1426
|
+
...sanitizedError !== void 0 ? { error: sanitizedError } : {}
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
if (event.type === "task_end") return { status: event.status, reason: event.reason };
|
|
1430
|
+
if (event.type === "text_delta" || event.type === "reasoning_delta") return { text: event.text };
|
|
1431
|
+
return {};
|
|
1432
|
+
}
|
|
1433
|
+
function createRuntimeEventCollector(options = {}) {
|
|
1434
|
+
const events = [];
|
|
1435
|
+
return {
|
|
1436
|
+
events,
|
|
1437
|
+
onEvent: (event) => {
|
|
1438
|
+
events.push(sanitizeAgentRuntimeEvent(event, options));
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
function createRuntimeStreamEventCollector(options = {}) {
|
|
1443
|
+
const events = [];
|
|
1444
|
+
const eventCountsByType = {};
|
|
1445
|
+
let firstSessionId;
|
|
1446
|
+
let finalStatus;
|
|
1447
|
+
let finalReason;
|
|
1448
|
+
let finalText = "";
|
|
1449
|
+
return {
|
|
1450
|
+
events,
|
|
1451
|
+
onEvent: (event) => {
|
|
1452
|
+
events.push(sanitizeRuntimeStreamEvent(event, options));
|
|
1453
|
+
eventCountsByType[event.type] = (eventCountsByType[event.type] ?? 0) + 1;
|
|
1454
|
+
if (event.type === "text_delta") finalText += event.text;
|
|
1455
|
+
if (!firstSessionId && (event.type === "session_created" || event.type === "session_resumed")) {
|
|
1456
|
+
firstSessionId = event.session.id;
|
|
1457
|
+
}
|
|
1458
|
+
if (event.type === "final") {
|
|
1459
|
+
finalStatus = event.status;
|
|
1460
|
+
finalReason = event.reason;
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
summary() {
|
|
1464
|
+
return {
|
|
1465
|
+
eventCount: events.length,
|
|
1466
|
+
eventCountsByType: { ...eventCountsByType },
|
|
1467
|
+
firstSessionId,
|
|
1468
|
+
finalStatus,
|
|
1469
|
+
finalReason,
|
|
1470
|
+
finalText
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/otel-export.ts
|
|
1477
|
+
var SCOPE = { name: "@tangle-network/agent-runtime", version: "0.83.0" };
|
|
1478
|
+
var GEN_AI = {
|
|
1479
|
+
operation: "gen_ai.operation.name",
|
|
1480
|
+
agentName: "gen_ai.agent.name",
|
|
1481
|
+
conversationId: "gen_ai.conversation.id",
|
|
1482
|
+
inputTokens: "gen_ai.usage.input_tokens",
|
|
1483
|
+
outputTokens: "gen_ai.usage.output_tokens"
|
|
1484
|
+
};
|
|
1485
|
+
function createOtelExporter(config) {
|
|
1486
|
+
const resolvedEndpoint = config?.endpoint ?? (typeof process !== "undefined" ? process.env.OTEL_EXPORTER_OTLP_ENDPOINT : void 0);
|
|
1487
|
+
if (!resolvedEndpoint) return void 0;
|
|
1488
|
+
const endpoint = resolvedEndpoint;
|
|
1489
|
+
const headers = config?.headers ?? parseHeadersFromEnv();
|
|
1490
|
+
const batchSize = config?.batchSize ?? 64;
|
|
1491
|
+
const flushIntervalMs = config?.flushIntervalMs ?? 5e3;
|
|
1492
|
+
const serviceName = config?.serviceName ?? "agent-runtime";
|
|
1493
|
+
const resourceAttrs = config?.resourceAttributes ?? {};
|
|
1494
|
+
const pending = [];
|
|
1495
|
+
let timer;
|
|
1496
|
+
let stopped = false;
|
|
1497
|
+
const exporter = {
|
|
1498
|
+
exportSpan(span) {
|
|
1499
|
+
if (stopped) return;
|
|
1500
|
+
pending.push(span);
|
|
1501
|
+
if (pending.length >= batchSize) {
|
|
1502
|
+
void doFlush();
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
async flush() {
|
|
1506
|
+
await doFlush();
|
|
1507
|
+
},
|
|
1508
|
+
async shutdown() {
|
|
1509
|
+
stopped = true;
|
|
1510
|
+
if (timer !== void 0) {
|
|
1511
|
+
clearInterval(timer);
|
|
1512
|
+
timer = void 0;
|
|
1513
|
+
}
|
|
1514
|
+
await doFlush();
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
timer = setInterval(() => {
|
|
1518
|
+
if (pending.length > 0) void doFlush();
|
|
1519
|
+
}, flushIntervalMs);
|
|
1520
|
+
if (typeof timer === "object" && "unref" in timer) {
|
|
1521
|
+
;
|
|
1522
|
+
timer.unref();
|
|
1523
|
+
}
|
|
1524
|
+
async function doFlush() {
|
|
1525
|
+
if (pending.length === 0) return;
|
|
1526
|
+
const batch = pending.splice(0);
|
|
1527
|
+
const body = {
|
|
1528
|
+
resourceSpans: [
|
|
1529
|
+
{
|
|
1530
|
+
resource: {
|
|
1531
|
+
attributes: toAttributes({
|
|
1532
|
+
"service.name": serviceName,
|
|
1533
|
+
...resourceAttrs
|
|
1534
|
+
})
|
|
1535
|
+
},
|
|
1536
|
+
scopeSpans: [{ scope: SCOPE, spans: batch }]
|
|
1537
|
+
}
|
|
1538
|
+
]
|
|
1539
|
+
};
|
|
1540
|
+
const url = `${endpoint.replace(/\/+$/, "")}/v1/traces`;
|
|
1541
|
+
try {
|
|
1542
|
+
await fetch(url, {
|
|
1543
|
+
method: "POST",
|
|
1544
|
+
headers: { "content-type": "application/json", ...headers },
|
|
1545
|
+
body: JSON.stringify(body)
|
|
1546
|
+
});
|
|
1547
|
+
} catch {
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return exporter;
|
|
1551
|
+
}
|
|
1552
|
+
function loopEventToOtelSpan(event, traceId, parentSpanId) {
|
|
1553
|
+
const spanId = generateSpanId();
|
|
1554
|
+
const attrs = {
|
|
1555
|
+
"loop.event_kind": event.kind,
|
|
1556
|
+
"loop.run_id": event.runId
|
|
1557
|
+
};
|
|
1558
|
+
for (const [k, v] of Object.entries(event.payload)) {
|
|
1559
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
1560
|
+
attrs[`loop.${k}`] = v;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
const ts = msToNs(event.timestamp);
|
|
1564
|
+
return {
|
|
1565
|
+
traceId: padTraceId(traceId),
|
|
1566
|
+
spanId,
|
|
1567
|
+
parentSpanId: parentSpanId ? padSpanId(parentSpanId) : void 0,
|
|
1568
|
+
name: event.kind,
|
|
1569
|
+
kind: 1,
|
|
1570
|
+
startTimeUnixNano: ts,
|
|
1571
|
+
endTimeUnixNano: ts,
|
|
1572
|
+
attributes: toAttributes(attrs),
|
|
1573
|
+
status: { code: 1 }
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
function flatOtelSpan(name, attributes, traceId, timestampMs, parentSpanId, endTimestampMs = timestampMs) {
|
|
1577
|
+
const start = msToNs(timestampMs);
|
|
1578
|
+
const end = msToNs(Math.max(timestampMs, endTimestampMs));
|
|
1579
|
+
return {
|
|
1580
|
+
traceId: padTraceId(traceId),
|
|
1581
|
+
spanId: generateSpanId(),
|
|
1582
|
+
parentSpanId: parentSpanId ? padSpanId(parentSpanId) : void 0,
|
|
1583
|
+
name,
|
|
1584
|
+
kind: 1,
|
|
1585
|
+
startTimeUnixNano: start,
|
|
1586
|
+
endTimeUnixNano: end,
|
|
1587
|
+
attributes: toAttributes(attributes),
|
|
1588
|
+
status: { code: 1 }
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
function eventTimestampMs(event) {
|
|
1592
|
+
if ("timestamp" in event && typeof event.timestamp === "string") {
|
|
1593
|
+
const parsed = Date.parse(event.timestamp);
|
|
1594
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
1595
|
+
}
|
|
1596
|
+
return Date.now();
|
|
1597
|
+
}
|
|
1598
|
+
function serialized(value) {
|
|
1599
|
+
try {
|
|
1600
|
+
return JSON.stringify(value) ?? String(value);
|
|
1601
|
+
} catch {
|
|
1602
|
+
return String(value);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
function mcpIdentity(toolName) {
|
|
1606
|
+
if (!toolName.startsWith("mcp__")) return {};
|
|
1607
|
+
const [, server, ...toolParts] = toolName.split("__");
|
|
1608
|
+
return {
|
|
1609
|
+
...server ? { server } : {},
|
|
1610
|
+
...toolParts.length > 0 ? { tool: toolParts.join("__") } : {}
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function buildRuntimeEventOtelSpans(events, traceId, parentSpanId, options = {}) {
|
|
1614
|
+
return events.map((event) => {
|
|
1615
|
+
const sanitized = sanitizeRuntimeStreamEvent(event, options);
|
|
1616
|
+
const safe = options.redact ? options.redact(sanitized) : sanitized;
|
|
1617
|
+
const record = safe && typeof safe === "object" && !Array.isArray(safe) ? safe : { value: safe };
|
|
1618
|
+
const attrs = {
|
|
1619
|
+
"tangle.runtime.event_type": event.type,
|
|
1620
|
+
"tangle.runtime.event": serialized(record)
|
|
1621
|
+
};
|
|
1622
|
+
let name = `tangle.runtime.${event.type}`;
|
|
1623
|
+
if (event.type === "tool_call" || event.type === "tool_result") {
|
|
1624
|
+
name = `agent.${event.type}`;
|
|
1625
|
+
attrs["tool.name"] = event.toolName;
|
|
1626
|
+
if (event.toolCallId) attrs["tool.call_id"] = event.toolCallId;
|
|
1627
|
+
const mcp = mcpIdentity(event.toolName);
|
|
1628
|
+
if (mcp.server) attrs["mcp.server"] = mcp.server;
|
|
1629
|
+
if (mcp.tool) attrs["mcp.tool.name"] = mcp.tool;
|
|
1630
|
+
const payload = event.type === "tool_call" ? record.args : record.result;
|
|
1631
|
+
if (payload !== void 0) {
|
|
1632
|
+
attrs[event.type === "tool_call" ? "tool.input" : "tool.output"] = serialized(payload);
|
|
1633
|
+
}
|
|
1634
|
+
} else if (event.type === "llm_call") {
|
|
1635
|
+
name = "gen_ai.client.inference";
|
|
1636
|
+
attrs["gen_ai.request.model"] = event.model;
|
|
1637
|
+
if (event.tokensIn !== void 0) attrs["gen_ai.usage.input_tokens"] = event.tokensIn;
|
|
1638
|
+
if (event.tokensOut !== void 0) attrs["gen_ai.usage.output_tokens"] = event.tokensOut;
|
|
1639
|
+
if (event.costUsd !== void 0) attrs["tangle.cost.usd"] = event.costUsd;
|
|
1640
|
+
if (event.latencyMs !== void 0) attrs["tangle.latency_ms"] = event.latencyMs;
|
|
1641
|
+
if (event.finishReason !== void 0)
|
|
1642
|
+
attrs["gen_ai.response.finish_reasons"] = event.finishReason;
|
|
1643
|
+
} else if (event.type === "backend_error") {
|
|
1644
|
+
attrs["error.type"] = event.error?.kind ?? "backend";
|
|
1645
|
+
attrs["error.message"] = event.message;
|
|
1646
|
+
} else if (event.type === "final") {
|
|
1647
|
+
attrs["tangle.outcome.status"] = event.status;
|
|
1648
|
+
attrs["tangle.outcome.reason"] = event.reason;
|
|
1649
|
+
if (event.error) {
|
|
1650
|
+
attrs["error.type"] = event.error.kind;
|
|
1651
|
+
attrs["error.message"] = event.error.message;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
const startMs = eventTimestampMs(event);
|
|
1655
|
+
const endMs = event.type === "llm_call" && event.latencyMs !== void 0 && Number.isFinite(event.latencyMs) ? startMs + event.latencyMs : startMs;
|
|
1656
|
+
const span = flatOtelSpan(name, attrs, traceId, startMs, parentSpanId, endMs);
|
|
1657
|
+
if (event.type === "backend_error" || event.type === "final" && event.status !== "completed") {
|
|
1658
|
+
span.status = { code: 2, message: attrs["error.message"]?.toString() ?? event.type };
|
|
1659
|
+
}
|
|
1660
|
+
return span;
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
function buildLoopOtelSpans(events, traceId, rootParentSpanId) {
|
|
1664
|
+
const tid = padTraceId(traceId);
|
|
1665
|
+
return buildLoopSpanNodes(events).map((node) => ({
|
|
1666
|
+
traceId: tid,
|
|
1667
|
+
spanId: node.spanId,
|
|
1668
|
+
parentSpanId: node.parentSpanId ? padSpanId(node.parentSpanId) : rootParentSpanId ? padSpanId(rootParentSpanId) : void 0,
|
|
1669
|
+
name: node.name,
|
|
1670
|
+
kind: 1,
|
|
1671
|
+
startTimeUnixNano: msToNs(node.startMs),
|
|
1672
|
+
endTimeUnixNano: msToNs(node.endMs),
|
|
1673
|
+
attributes: toAttributes(node.attrs),
|
|
1674
|
+
status: { code: node.error ? 2 : 1 }
|
|
1675
|
+
}));
|
|
1676
|
+
}
|
|
1677
|
+
function buildLoopSpanNodes(events) {
|
|
1678
|
+
if (events.length === 0) return [];
|
|
1679
|
+
const out = [];
|
|
1680
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
1681
|
+
const str = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
1682
|
+
const rec = (v) => v && typeof v === "object" ? v : {};
|
|
1683
|
+
const started = events.find((e) => e.kind === "loop.started");
|
|
1684
|
+
const ended = events.find((e) => e.kind === "loop.ended");
|
|
1685
|
+
const runId = events[0]?.runId ?? "";
|
|
1686
|
+
const rootStart = started?.timestamp ?? events[0].timestamp;
|
|
1687
|
+
const rootEnd = ended?.timestamp ?? events[events.length - 1].timestamp;
|
|
1688
|
+
const rootId = generateSpanId();
|
|
1689
|
+
const make = (spanId, parentSpanId, name, kind, startMs, endMs, attrs, error = false) => ({
|
|
1690
|
+
spanId,
|
|
1691
|
+
parentSpanId,
|
|
1692
|
+
name,
|
|
1693
|
+
kind,
|
|
1694
|
+
startMs,
|
|
1695
|
+
endMs,
|
|
1696
|
+
attrs,
|
|
1697
|
+
error
|
|
1698
|
+
});
|
|
1699
|
+
const sp = rec(started?.payload);
|
|
1700
|
+
const rootAttrs = {
|
|
1701
|
+
[GEN_AI.operation]: "invoke_workflow",
|
|
1702
|
+
[GEN_AI.conversationId]: runId,
|
|
1703
|
+
// Explicit run identity under the tangle namespace so a consuming system of
|
|
1704
|
+
// record (Tangle Intelligence's run spine) maps this span tree to one run
|
|
1705
|
+
// deterministically, instead of inferring it from the conversation id.
|
|
1706
|
+
"tangle.run.id": runId,
|
|
1707
|
+
"tangle.loop.driver": str(sp.driver) ?? "driver"
|
|
1708
|
+
};
|
|
1709
|
+
if (Array.isArray(sp.agentRunNames) && sp.agentRunNames.length > 0) {
|
|
1710
|
+
rootAttrs["tangle.loop.agents"] = sp.agentRunNames.map(String).join(",");
|
|
1711
|
+
rootAttrs["tangle.subject.key"] = String(sp.agentRunNames[0]);
|
|
1712
|
+
}
|
|
1713
|
+
if (ended) {
|
|
1714
|
+
const ep = rec(ended.payload);
|
|
1715
|
+
const win = num(ep.winnerIterationIndex);
|
|
1716
|
+
if (win !== void 0) rootAttrs["tangle.loop.winner.iteration_index"] = win;
|
|
1717
|
+
const cost = num(ep.totalCostUsd);
|
|
1718
|
+
if (cost !== void 0) rootAttrs["tangle.cost.usd"] = cost;
|
|
1719
|
+
const dur = num(ep.durationMs);
|
|
1720
|
+
if (dur !== void 0) rootAttrs["tangle.loop.duration_ms"] = dur;
|
|
1721
|
+
const iters = num(ep.iterations);
|
|
1722
|
+
if (iters !== void 0) rootAttrs["tangle.loop.iterations"] = iters;
|
|
1723
|
+
}
|
|
1724
|
+
out.push(make(rootId, void 0, "loop", "loop", rootStart, rootEnd, rootAttrs));
|
|
1725
|
+
const iterStartTs = /* @__PURE__ */ new Map();
|
|
1726
|
+
const placementByIdx = /* @__PURE__ */ new Map();
|
|
1727
|
+
let currentRoundId;
|
|
1728
|
+
let pendingRound;
|
|
1729
|
+
const flushRound = (endMs) => {
|
|
1730
|
+
if (!pendingRound) return;
|
|
1731
|
+
out.push(
|
|
1732
|
+
make(
|
|
1733
|
+
pendingRound.id,
|
|
1734
|
+
rootId,
|
|
1735
|
+
"loop.round",
|
|
1736
|
+
"round",
|
|
1737
|
+
pendingRound.start,
|
|
1738
|
+
endMs,
|
|
1739
|
+
pendingRound.attrs
|
|
1740
|
+
)
|
|
1741
|
+
);
|
|
1742
|
+
pendingRound = void 0;
|
|
1743
|
+
};
|
|
1744
|
+
for (const e of events) {
|
|
1745
|
+
const p = rec(e.payload);
|
|
1746
|
+
switch (e.kind) {
|
|
1747
|
+
case "loop.plan": {
|
|
1748
|
+
flushRound(e.timestamp);
|
|
1749
|
+
const id = generateSpanId();
|
|
1750
|
+
const roundIdx = num(p.roundIndex) ?? 0;
|
|
1751
|
+
const attrs = {
|
|
1752
|
+
[GEN_AI.operation]: "invoke_workflow",
|
|
1753
|
+
"tangle.loop.round.index": roundIdx,
|
|
1754
|
+
"tangle.loop.move.kind": str(p.moveKind) ?? "unknown",
|
|
1755
|
+
"tangle.loop.move.round": roundIdx,
|
|
1756
|
+
"tangle.loop.move.width": num(p.plannedCount) ?? 0
|
|
1757
|
+
};
|
|
1758
|
+
const r = str(p.rationale);
|
|
1759
|
+
if (r) attrs["tangle.loop.move.rationale"] = r;
|
|
1760
|
+
const parent = num(p.parentIndex);
|
|
1761
|
+
if (parent !== void 0) attrs["tangle.loop.move.parent_index"] = parent;
|
|
1762
|
+
if (Array.isArray(p.childIndices) && p.childIndices.length > 0) {
|
|
1763
|
+
attrs["tangle.loop.move.child_indices"] = p.childIndices.map(String).join(",");
|
|
1764
|
+
}
|
|
1765
|
+
pendingRound = { id, start: e.timestamp, attrs };
|
|
1766
|
+
currentRoundId = id;
|
|
1767
|
+
break;
|
|
1768
|
+
}
|
|
1769
|
+
case "loop.iteration.started": {
|
|
1770
|
+
const idx = num(p.iterationIndex);
|
|
1771
|
+
if (idx !== void 0) iterStartTs.set(idx, e.timestamp);
|
|
1772
|
+
break;
|
|
1773
|
+
}
|
|
1774
|
+
case "loop.iteration.dispatch": {
|
|
1775
|
+
const idx = num(p.iterationIndex);
|
|
1776
|
+
if (idx === void 0) break;
|
|
1777
|
+
const place = {};
|
|
1778
|
+
const kind = str(p.placement);
|
|
1779
|
+
if (kind) place["tangle.loop.placement.kind"] = kind;
|
|
1780
|
+
const sid = str(p.sandboxId);
|
|
1781
|
+
if (sid) place["tangle.sandbox.id"] = sid;
|
|
1782
|
+
const fid = str(p.fleetId);
|
|
1783
|
+
if (fid) place["tangle.fleet.id"] = fid;
|
|
1784
|
+
const mid = str(p.machineId);
|
|
1785
|
+
if (mid) place["tangle.machine.id"] = mid;
|
|
1786
|
+
placementByIdx.set(idx, place);
|
|
1787
|
+
break;
|
|
1788
|
+
}
|
|
1789
|
+
case "loop.iteration.ended": {
|
|
1790
|
+
const idx = num(p.iterationIndex) ?? 0;
|
|
1791
|
+
const start = iterStartTs.get(idx) ?? e.timestamp;
|
|
1792
|
+
const err = str(p.error);
|
|
1793
|
+
const attrs = {
|
|
1794
|
+
[GEN_AI.operation]: "invoke_agent",
|
|
1795
|
+
"tangle.loop.iteration.index": idx
|
|
1796
|
+
};
|
|
1797
|
+
const agent = str(p.agentRunName);
|
|
1798
|
+
if (agent) attrs[GEN_AI.agentName] = agent;
|
|
1799
|
+
const tu = rec(p.tokenUsage);
|
|
1800
|
+
const inTok = num(tu.input);
|
|
1801
|
+
if (inTok !== void 0) attrs[GEN_AI.inputTokens] = inTok;
|
|
1802
|
+
const outTok = num(tu.output);
|
|
1803
|
+
if (outTok !== void 0) attrs[GEN_AI.outputTokens] = outTok;
|
|
1804
|
+
const cost = num(p.costUsd);
|
|
1805
|
+
if (cost !== void 0) attrs["tangle.cost.usd"] = cost;
|
|
1806
|
+
const verdict = rec(p.verdict);
|
|
1807
|
+
if (typeof verdict.valid === "boolean") attrs["tangle.loop.verdict.valid"] = verdict.valid;
|
|
1808
|
+
const score = num(verdict.score);
|
|
1809
|
+
if (score !== void 0) attrs["tangle.loop.verdict.score"] = score;
|
|
1810
|
+
if (err) attrs["tangle.loop.error"] = err;
|
|
1811
|
+
const gid = num(p.groupId);
|
|
1812
|
+
if (gid !== void 0) attrs["tangle.loop.iteration.group_id"] = gid;
|
|
1813
|
+
const par = num(p.parentIndex);
|
|
1814
|
+
if (par !== void 0) attrs["tangle.loop.iteration.parent_index"] = par;
|
|
1815
|
+
const dur = num(p.durationMs);
|
|
1816
|
+
if (dur !== void 0) attrs["tangle.loop.iteration.duration_ms"] = dur;
|
|
1817
|
+
const preview = str(p.outputPreview);
|
|
1818
|
+
if (preview) attrs["tangle.loop.iteration.output_preview"] = preview;
|
|
1819
|
+
Object.assign(attrs, placementByIdx.get(idx) ?? {});
|
|
1820
|
+
out.push(
|
|
1821
|
+
make(
|
|
1822
|
+
generateSpanId(),
|
|
1823
|
+
currentRoundId ?? rootId,
|
|
1824
|
+
"loop.iteration",
|
|
1825
|
+
"branch",
|
|
1826
|
+
start,
|
|
1827
|
+
e.timestamp,
|
|
1828
|
+
attrs,
|
|
1829
|
+
err !== void 0
|
|
1830
|
+
)
|
|
1831
|
+
);
|
|
1832
|
+
break;
|
|
1833
|
+
}
|
|
1834
|
+
case "loop.decision": {
|
|
1835
|
+
if (pendingRound) {
|
|
1836
|
+
const dec = str(p.decision);
|
|
1837
|
+
if (dec) pendingRound.attrs["tangle.loop.decision"] = dec;
|
|
1838
|
+
flushRound(e.timestamp);
|
|
1839
|
+
}
|
|
1840
|
+
currentRoundId = void 0;
|
|
1841
|
+
break;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
flushRound(rootEnd);
|
|
1846
|
+
return out;
|
|
1847
|
+
}
|
|
1848
|
+
function parseHeadersFromEnv() {
|
|
1849
|
+
if (typeof process === "undefined") return {};
|
|
1850
|
+
const raw = process.env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
1851
|
+
if (!raw) return {};
|
|
1852
|
+
const out = {};
|
|
1853
|
+
for (const pair of raw.split(",")) {
|
|
1854
|
+
const eq = pair.indexOf("=");
|
|
1855
|
+
if (eq < 0) continue;
|
|
1856
|
+
const key = pair.slice(0, eq).trim();
|
|
1857
|
+
const value = pair.slice(eq + 1).trim();
|
|
1858
|
+
if (key) out[key] = value;
|
|
1859
|
+
}
|
|
1860
|
+
return out;
|
|
1861
|
+
}
|
|
1862
|
+
function toAttributes(record) {
|
|
1863
|
+
return Object.entries(record).flatMap(([key, value]) => {
|
|
1864
|
+
if (typeof value === "number" && !Number.isFinite(value)) return [];
|
|
1865
|
+
return [
|
|
1866
|
+
{
|
|
1867
|
+
key,
|
|
1868
|
+
value: typeof value === "number" ? Number.isInteger(value) ? { intValue: value.toString() } : { doubleValue: value } : typeof value === "boolean" ? { boolValue: value } : { stringValue: value }
|
|
1869
|
+
}
|
|
1870
|
+
];
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
function msToNs(ms) {
|
|
1874
|
+
const safeMs = Number.isFinite(ms) ? ms : Date.now();
|
|
1875
|
+
return (BigInt(Math.floor(safeMs)) * 1000000n).toString();
|
|
1876
|
+
}
|
|
1877
|
+
function padSpanId(id) {
|
|
1878
|
+
const cleaned = id.replace(/-/g, "");
|
|
1879
|
+
return cleaned.slice(0, 16).padEnd(16, "0");
|
|
1880
|
+
}
|
|
1881
|
+
function padTraceId(id) {
|
|
1882
|
+
const cleaned = id.replace(/-/g, "");
|
|
1883
|
+
return cleaned.slice(0, 32).padEnd(32, "0");
|
|
1884
|
+
}
|
|
1885
|
+
function generateSpanId() {
|
|
1886
|
+
const bytes = new Uint8Array(8);
|
|
1887
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
1888
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1889
|
+
} else {
|
|
1890
|
+
for (let i = 0; i < 8; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
1891
|
+
}
|
|
1892
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1893
|
+
}
|
|
1894
|
+
var INTELLIGENCE_WIRE_VERSION = "2026-05-26.v1";
|
|
1895
|
+
var DEFAULT_INTELLIGENCE_BASE = "https://intelligence.tangle.tools";
|
|
1896
|
+
async function exportEvalRuns(events, config) {
|
|
1897
|
+
if (events.length === 0) return { ok: true, status: 0, accepted: 0, rejected: [] };
|
|
1898
|
+
const apiKey = config?.apiKey ?? (typeof process !== "undefined" ? process.env.TANGLE_API_KEY : void 0);
|
|
1899
|
+
if (!apiKey)
|
|
1900
|
+
throw new Error("exportEvalRuns: apiKey required (pass config.apiKey or set TANGLE_API_KEY)");
|
|
1901
|
+
const base = config?.base ?? (typeof process !== "undefined" ? process.env.TANGLE_INTELLIGENCE_URL : void 0) ?? DEFAULT_INTELLIGENCE_BASE;
|
|
1902
|
+
const url = `${base.replace(/\/+$/, "")}/v1/ingest/eval-runs`;
|
|
1903
|
+
const res = await fetch(url, {
|
|
1904
|
+
method: "POST",
|
|
1905
|
+
headers: {
|
|
1906
|
+
"content-type": "application/json",
|
|
1907
|
+
authorization: `Bearer ${apiKey}`,
|
|
1908
|
+
"X-Tangle-Wire-Version": INTELLIGENCE_WIRE_VERSION,
|
|
1909
|
+
...config?.idempotencyKey ? { "Idempotency-Key": config.idempotencyKey } : {}
|
|
1910
|
+
},
|
|
1911
|
+
body: JSON.stringify({ wireVersion: INTELLIGENCE_WIRE_VERSION, events })
|
|
1912
|
+
});
|
|
1913
|
+
let parsed = {};
|
|
1914
|
+
try {
|
|
1915
|
+
parsed = await res.json();
|
|
1916
|
+
} catch {
|
|
1917
|
+
}
|
|
1918
|
+
return {
|
|
1919
|
+
ok: res.ok,
|
|
1920
|
+
status: res.status,
|
|
1921
|
+
accepted: parsed.accepted ?? (res.ok ? events.length : 0),
|
|
1922
|
+
rejected: parsed.rejected ?? []
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1094
1926
|
export {
|
|
1095
1927
|
CodexExecutionDiagnosticError,
|
|
1096
1928
|
harnessInvocation,
|
|
1097
1929
|
runLocalHarness,
|
|
1098
|
-
parseCodexTokenUsage
|
|
1930
|
+
parseCodexTokenUsage,
|
|
1931
|
+
assertModelAllowed,
|
|
1932
|
+
sanitizeKnowledgeReadinessReport,
|
|
1933
|
+
sanitizeAgentRuntimeEvent,
|
|
1934
|
+
sanitizeRuntimeStreamEvent,
|
|
1935
|
+
createRuntimeEventCollector,
|
|
1936
|
+
createRuntimeStreamEventCollector,
|
|
1937
|
+
createOtelExporter,
|
|
1938
|
+
loopEventToOtelSpan,
|
|
1939
|
+
flatOtelSpan,
|
|
1940
|
+
buildRuntimeEventOtelSpans,
|
|
1941
|
+
buildLoopOtelSpans,
|
|
1942
|
+
buildLoopSpanNodes,
|
|
1943
|
+
INTELLIGENCE_WIRE_VERSION,
|
|
1944
|
+
exportEvalRuns
|
|
1099
1945
|
};
|
|
1100
|
-
//# sourceMappingURL=chunk-
|
|
1946
|
+
//# sourceMappingURL=chunk-HZDEXTSL.js.map
|