@agimon-ai/po-core 0.0.0-alpha.131 → 0.0.0-alpha.133

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.
@@ -55,6 +55,35 @@ function nativeId(id) {
55
55
  function json(value) {
56
56
  return JSON.parse(JSON.stringify(value));
57
57
  }
58
+ /**
59
+ * A fixed category for a tool that threw, kept for telemetry: pi-durable turns the throw into text and drops the error.
60
+ * The reason is the error's code (ENOENT, invalid_request) or class name, never its message.
61
+ */
62
+ function thrownToolFailure(error) {
63
+ const code = error && typeof error === "object" && "code" in error ? error.code : void 0;
64
+ const name = error instanceof Error ? error.name === "Error" ? error.constructor.name : error.name : "NonError";
65
+ const reason = typeof code === "string" && code !== "" ? code : name;
66
+ if (name === "AbortError" || name === "OperationCancelledError") return {
67
+ kind: "aborted",
68
+ reason
69
+ };
70
+ if (name === "TimeoutError" || code === "ETIMEDOUT") return {
71
+ kind: "timeout",
72
+ reason
73
+ };
74
+ if (code === "ENOENT") return {
75
+ kind: "not_found",
76
+ reason
77
+ };
78
+ if (code === "EACCES" || code === "EPERM") return {
79
+ kind: "permission",
80
+ reason
81
+ };
82
+ return {
83
+ kind: "unknown",
84
+ reason
85
+ };
86
+ }
58
87
  /** A custom entry payload as JSON, refused rather than truncated when it exceeds the entry byte cap. */
59
88
  function customEntryJson(customType, value) {
60
89
  const serialized = JSON.stringify(value);
@@ -156,6 +185,7 @@ async function createLaneRuntime(options, attached) {
156
185
  const fitProviderImages = require_index$2.createProviderImageFitter();
157
186
  const terminatingCalls = /* @__PURE__ */ new Set();
158
187
  const hookedArgs = /* @__PURE__ */ new Map();
188
+ const thrownFailures = /* @__PURE__ */ new Map();
159
189
  let fastMode = false;
160
190
  let agentLocked = false;
161
191
  const assertUnlocked = () => {
@@ -375,41 +405,46 @@ async function createLaneRuntime(options, attached) {
375
405
  async execute(args, api, ctx) {
376
406
  if (!activeNames.has(tool.name)) throw new Error(`Tool '${tool.name}' is no longer active`);
377
407
  let reported = "";
378
- const pending = tool.execute(api.callId, args, (partial) => {
379
- const snapshot = partial.content.map((part) => part.type === "text" ? part.text : "").join("");
380
- const chunk = snapshot.startsWith(reported) ? snapshot.slice(reported.length) : `\n${snapshot}`;
381
- reported = snapshot;
382
- if (chunk) api.output(chunk);
383
- if (partial.details !== void 0) api.details(json(partial.details), ctx).catch((error) => emit({
384
- type: "error",
385
- error: String(error)
386
- }));
387
- }, await resolveToolContext(ctx), {
388
- ...options.beforeTool && options.afterTool ? { toolContinuation: require_index$9.createToolContinuation({
389
- toolName: tool.name,
390
- parameters: tool.parameters,
391
- beforeTool: options.beforeTool,
392
- afterTool: options.afterTool,
393
- assertAvailable() {
394
- assertUnlocked();
395
- if (disposed || disposePromise || quarantined || !activeNames.has(tool.name) || !tools.includes(tool)) throw new Error(`Tool '${tool.name}' is no longer active`);
408
+ try {
409
+ const pending = tool.execute(api.callId, args, (partial) => {
410
+ const snapshot = partial.content.map((part) => part.type === "text" ? part.text : "").join("");
411
+ const chunk = snapshot.startsWith(reported) ? snapshot.slice(reported.length) : `\n${snapshot}`;
412
+ reported = snapshot;
413
+ if (chunk) api.output(chunk);
414
+ if (partial.details !== void 0) api.details(json(partial.details), ctx).catch((error) => emit({
415
+ type: "error",
416
+ error: String(error)
417
+ }));
418
+ }, await resolveToolContext(ctx), {
419
+ ...options.beforeTool && options.afterTool ? { toolContinuation: require_index$9.createToolContinuation({
420
+ toolName: tool.name,
421
+ parameters: tool.parameters,
422
+ beforeTool: options.beforeTool,
423
+ afterTool: options.afterTool,
424
+ assertAvailable() {
425
+ assertUnlocked();
426
+ if (disposed || disposePromise || quarantined || !activeNames.has(tool.name) || !tools.includes(tool)) throw new Error(`Tool '${tool.name}' is no longer active`);
427
+ }
428
+ }) } : {},
429
+ invocationId: String(api.taskId),
430
+ operationId: String(api.taskId),
431
+ turnId: String(api.taskId),
432
+ getMemo: (name) => api.memo(name, ctx),
433
+ setMemo: async (name, value) => {
434
+ if (value === void 0) throw new Error("Durable invocation memos cannot be deleted");
435
+ await api.memo(name, value, ctx);
396
436
  }
397
- }) } : {},
398
- invocationId: String(api.taskId),
399
- operationId: String(api.taskId),
400
- turnId: String(api.taskId),
401
- getMemo: (name) => api.memo(name, ctx),
402
- setMemo: async (name, value) => {
403
- if (value === void 0) throw new Error("Durable invocation memos cannot be deleted");
404
- await api.memo(name, value, ctx);
405
- }
406
- }, ctx);
407
- const result = await (0, dist_interop_chordContext_mjs.awaitWithContext)(pending, ctx);
408
- return {
409
- output: result.content,
410
- isError: result.isError,
411
- ...result.details === void 0 ? {} : { details: json(result.details) }
412
- };
437
+ }, ctx);
438
+ const result = await (0, dist_interop_chordContext_mjs.awaitWithContext)(pending, ctx);
439
+ return {
440
+ output: result.content,
441
+ isError: result.isError,
442
+ ...result.details === void 0 ? {} : { details: json(result.details) }
443
+ };
444
+ } catch (error) {
445
+ thrownFailures.set(api.callId, thrownToolFailure(error));
446
+ throw error;
447
+ }
413
448
  }
414
449
  });
415
450
  const install = () => registry.install({
@@ -503,15 +538,26 @@ async function createLaneRuntime(options, attached) {
503
538
  block: patch.block?.reason
504
539
  } : void 0;
505
540
  },
506
- async afterTool(call, result, _api, ctx) {
541
+ async afterTool(call, executed, _api, ctx) {
542
+ const thrown = thrownFailures.get(call.id);
543
+ thrownFailures.delete(call.id);
507
544
  if (require_index$9.isBashSequenceEnvelope(call.name, call.arguments)) return void 0;
508
- if (result.diagnostics?.some((diagnostic) => HARNESS_TOOL_CODES.has(diagnostic.code ?? ""))) return terminatingCalls.delete(call.id) ? {
509
- ...result,
545
+ if (executed.diagnostics?.some((diagnostic) => HARNESS_TOOL_CODES.has(diagnostic.code ?? ""))) return terminatingCalls.delete(call.id) ? {
546
+ ...executed,
510
547
  control: {
511
- ...result.control,
548
+ ...executed.control,
512
549
  terminate: true
513
550
  }
514
551
  } : void 0;
552
+ const details = executed.details;
553
+ const detailsRecord = details !== null && typeof details === "object" && !Array.isArray(details) ? details : void 0;
554
+ const result = thrown && executed.isError && detailsRecord?.failure === void 0 ? {
555
+ ...executed,
556
+ details: {
557
+ ...detailsRecord,
558
+ failure: thrown
559
+ }
560
+ } : executed;
515
561
  const patch = await options.afterTool?.({
516
562
  toolCallId: call.id,
517
563
  toolName: call.name,
@@ -536,7 +582,7 @@ async function createLaneRuntime(options, attached) {
536
582
  ...result.control,
537
583
  terminate: true
538
584
  }
539
- } : void 0;
585
+ } : result === executed ? void 0 : result;
540
586
  }
541
587
  }),
542
588
  (0, _earendil_works_pi_durable.hook)(_earendil_works_pi_durable.CompactionTask, { async beforeCompact(input, api, ctx) {
@@ -2540,5 +2586,6 @@ async function createLaneRuntime(options, attached) {
2540
2586
  exports.createDirectHarnessRuntime = createDirectHarnessRuntime;
2541
2587
  exports.projectDurableConversationEntries = projectDurableConversationEntries;
2542
2588
  exports.promptForAssistantText = promptForAssistantText;
2589
+ exports.thrownToolFailure = thrownToolFailure;
2543
2590
 
2544
2591
  //# sourceMappingURL=directHarnessRuntime.cjs.map