@tangle-network/traces 0.9.14 → 0.9.15

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.
@@ -4192,6 +4192,17 @@ function textOf8(content) {
4192
4192
  content.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("")
4193
4193
  );
4194
4194
  }
4195
+ function toolResultOutput(content) {
4196
+ if (content?.length === 1 && content[0]?.type === "text" && typeof content[0].text === "string") {
4197
+ return content[0].text;
4198
+ }
4199
+ return content;
4200
+ }
4201
+ function completeToolSpan(toolSpan, result) {
4202
+ toolSpan.end_time = result.timestamp;
4203
+ toolSpan.status = result.isError ? { code: "ERROR", message: result.errorMessage } : { code: "OK" };
4204
+ recordToolOutput(toolSpan, result.output);
4205
+ }
4195
4206
  var PiAdapter = class {
4196
4207
  harness = "pi";
4197
4208
  root() {
@@ -4240,6 +4251,7 @@ var PiAdapter = class {
4240
4251
  const sourceRootId = `root:${sourceTraceId}`;
4241
4252
  const spans = [];
4242
4253
  const toolByCallId = /* @__PURE__ */ new Map();
4254
+ const pendingResults = /* @__PURE__ */ new Map();
4243
4255
  let firstTimestamp;
4244
4256
  let lastTimestamp;
4245
4257
  let sessionLine;
@@ -4259,7 +4271,26 @@ var PiAdapter = class {
4259
4271
  const mid = l.id ?? `m${step}`;
4260
4272
  const msg = l.message;
4261
4273
  const llmId = `llm:${mid}`;
4262
- if (msg.role === "user") {
4274
+ if (msg.role === "toolResult") {
4275
+ const callId = msg.toolCallId ?? `${mid}:result`;
4276
+ const errorMessage = textOf8(msg.content).slice(0, 500) || "tool result reported error";
4277
+ const result = {
4278
+ callId,
4279
+ toolName: msg.toolName ?? "tool",
4280
+ timestamp: ts,
4281
+ isError: msg.isError === true,
4282
+ output: toolResultOutput(msg.content),
4283
+ errorMessage,
4284
+ step
4285
+ };
4286
+ const toolSpan = toolByCallId.get(callId);
4287
+ if (toolSpan) completeToolSpan(toolSpan, result);
4288
+ else {
4289
+ pendingResults.set(callId, result);
4290
+ step += 1;
4291
+ }
4292
+ continue;
4293
+ } else if (msg.role === "user") {
4263
4294
  const prompt = textOf8(msg.content);
4264
4295
  if (prompt) {
4265
4296
  spans.push(
@@ -4313,11 +4344,17 @@ var PiAdapter = class {
4313
4344
  service: SERVICE9,
4314
4345
  agent: SERVICE9,
4315
4346
  tool: name,
4347
+ status: "UNSET",
4316
4348
  step,
4317
4349
  extra: toolIoAttributes({ input: b.input ?? b.args ?? b.arguments })
4318
4350
  });
4319
4351
  spans.push(toolSpan);
4320
4352
  toolByCallId.set(callId, toolSpan);
4353
+ const pending = pendingResults.get(callId);
4354
+ if (pending) {
4355
+ completeToolSpan(toolSpan, pending);
4356
+ pendingResults.delete(callId);
4357
+ }
4321
4358
  step += 1;
4322
4359
  } else if (isToolResultBlock(b)) {
4323
4360
  const callId = b.toolCallId ?? b.callId ?? b.id ?? "";
@@ -4331,6 +4368,29 @@ var PiAdapter = class {
4331
4368
  }
4332
4369
  }
4333
4370
  }
4371
+ for (const result of pendingResults.values()) {
4372
+ spans.push(
4373
+ span({
4374
+ traceId: sourceTraceId,
4375
+ spanId: `tool:${result.callId}`,
4376
+ parentSpanId: sourceRootId,
4377
+ name: `tool.${result.toolName}`,
4378
+ kind: "TOOL",
4379
+ startTime: result.timestamp,
4380
+ endTime: result.timestamp,
4381
+ status: result.isError ? "ERROR" : "OK",
4382
+ statusMessage: result.isError ? result.errorMessage : void 0,
4383
+ service: SERVICE9,
4384
+ agent: SERVICE9,
4385
+ tool: result.toolName,
4386
+ step: result.step,
4387
+ extra: {
4388
+ ...toolIoAttributes({ output: result.output }),
4389
+ "traces.pi.tool_result_without_call": true
4390
+ }
4391
+ })
4392
+ );
4393
+ }
4334
4394
  const traceId = sessionLine?.id ?? sourceTraceId;
4335
4395
  const rootId = `root:${traceId}`;
4336
4396
  for (const item of spans) {
package/dist/cli.js CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  writePolicyEvidenceFile,
44
44
  writeSessionIndexFile,
45
45
  writeTraceEvidenceExportFile
46
- } from "./chunk-SKUFTUDV.js";
46
+ } from "./chunk-CLJJ5YFI.js";
47
47
 
48
48
  // src/cli.ts
49
49
  import { readFileSync } from "fs";
package/dist/index.d.ts CHANGED
@@ -713,7 +713,8 @@ declare class FactoryAdapter implements HarnessTraceAdapter {
713
713
  * Line types: `session` (id + cwd), `model_change`, `thinking_level_change`,
714
714
  * and `message`. A `message` line wraps `message.{role, model, provider,
715
715
  * content[], usage.{input,output}, stopReason, errorMessage}`. Tool calls
716
- * ride inside `message.content[]` as tool blocks.
716
+ * ride inside assistant `message.content[]` blocks; their completions are
717
+ * separate `role: "toolResult"` messages keyed by `message.toolCallId`.
717
718
  */
718
719
 
719
720
  declare class PiAdapter implements HarnessTraceAdapter {
package/dist/index.js CHANGED
@@ -130,7 +130,7 @@ import {
130
130
  writeSessionIndexFile,
131
131
  writeTraceEvidenceExportFile,
132
132
  writeTraceImprovementArtifacts
133
- } from "./chunk-SKUFTUDV.js";
133
+ } from "./chunk-CLJJ5YFI.js";
134
134
 
135
135
  // src/collect.ts
136
136
  async function collectSessions(opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/traces",
3
- "version": "0.9.14",
3
+ "version": "0.9.15",
4
4
  "description": "Point it at your coding-agent session traces (Claude Code, Codex, OpenCode, Gemini, Pi, …) and get failure-mode + efficiency findings. CLI + SDK over the @tangle-network/agent-eval analyst suite — observe live sessions, run your own analysts, redact, and upload to the Tangle Intelligence Platform.",
5
5
  "type": "module",
6
6
  "license": "MIT",