@fabric-harness/sdk 6.0.0 → 6.1.0

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.
Files changed (48) hide show
  1. package/dist/abort.d.ts +16 -0
  2. package/dist/abort.d.ts.map +1 -0
  3. package/dist/abort.js +82 -0
  4. package/dist/abort.js.map +1 -0
  5. package/dist/history.d.ts +2 -2
  6. package/dist/history.d.ts.map +1 -1
  7. package/dist/history.js +101 -66
  8. package/dist/history.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/loop.d.ts +10 -8
  14. package/dist/loop.d.ts.map +1 -1
  15. package/dist/loop.js +120 -73
  16. package/dist/loop.js.map +1 -1
  17. package/dist/model.d.ts +2 -0
  18. package/dist/model.d.ts.map +1 -1
  19. package/dist/model.js +1 -1
  20. package/dist/model.js.map +1 -1
  21. package/dist/otel-observer.d.ts +6 -4
  22. package/dist/otel-observer.d.ts.map +1 -1
  23. package/dist/otel-observer.js +139 -52
  24. package/dist/otel-observer.js.map +1 -1
  25. package/dist/pi-loop-runtime.d.ts +4 -4
  26. package/dist/pi-loop-runtime.d.ts.map +1 -1
  27. package/dist/pi-loop-runtime.js +118 -72
  28. package/dist/pi-loop-runtime.js.map +1 -1
  29. package/dist/session.d.ts.map +1 -1
  30. package/dist/session.js +46 -21
  31. package/dist/session.js.map +1 -1
  32. package/dist/strict.d.ts +1 -1
  33. package/dist/strict.d.ts.map +1 -1
  34. package/dist/strict.js +1 -1
  35. package/dist/strict.js.map +1 -1
  36. package/dist/submission-runner.d.ts +15 -13
  37. package/dist/submission-runner.d.ts.map +1 -1
  38. package/dist/submission-runner.js +231 -94
  39. package/dist/submission-runner.js.map +1 -1
  40. package/dist/submission-telemetry.d.ts +11 -11
  41. package/dist/submission-telemetry.d.ts.map +1 -1
  42. package/dist/submission-telemetry.js +1 -1
  43. package/dist/submission-telemetry.js.map +1 -1
  44. package/dist/tools.d.ts +16 -0
  45. package/dist/tools.d.ts.map +1 -1
  46. package/dist/tools.js +291 -47
  47. package/dist/tools.js.map +1 -1
  48. package/package.json +26 -17
package/dist/session.js CHANGED
@@ -2,7 +2,8 @@ import { createHash, randomUUID } from "node:crypto";
2
2
  import { CostBudgetTracker } from "./cost-budget.js";
3
3
  import { inMemorySessionMemory } from "./session-memory.js";
4
4
  import { FabricError } from "./error.js";
5
- import { dynamicStateEntriesForTool, unwrapDynamicToolResult, } from "./dynamic-agent.js";
5
+ import { abandonToolOnAbort } from "./abort.js";
6
+ import { dynamicStateEntriesForTool, unwrapDynamicToolResult } from "./dynamic-agent.js";
6
7
  import { approvalGrantFromJson, approvalGrantFromState, approvalGrantToJson, approvalInputDigest, createApprovalGrant, sameApprovalOperation, } from "./approval.js";
7
8
  import { SessionHistory, buildModelMessagesFromHistory, findTrailingDanglingToolCalls, findTrailingUnfinishedTasks, } from "./history.js";
8
9
  import { getLogger } from "./logger.js";
@@ -165,9 +166,7 @@ export class StubFabricSession {
165
166
  const result = await durable.prompt({
166
167
  text,
167
168
  ...(options ? { options } : {}),
168
- ...(this.options.dynamic
169
- ? { dynamic: this.options.dynamic.executionDescriptor() }
170
- : {}),
169
+ ...(this.options.dynamic ? { dynamic: this.options.dynamic.executionDescriptor() } : {}),
171
170
  });
172
171
  await this.emit("prompt_end", { text });
173
172
  return result;
@@ -256,7 +255,10 @@ export class StubFabricSession {
256
255
  Reflect.deleteProperty(this.options, "compaction");
257
256
  if (options.role === undefined) {
258
257
  if (config.instructions) {
259
- this.options.role = { name: config.name ?? "instructions", content: config.instructions };
258
+ this.options.role = {
259
+ name: config.name ?? "instructions",
260
+ content: config.instructions,
261
+ };
260
262
  }
261
263
  else {
262
264
  Reflect.deleteProperty(this.options, "role");
@@ -326,8 +328,12 @@ export class StubFabricSession {
326
328
  const submissionId = options.submission?.submissionId;
327
329
  const dynamicPath = SessionHistory.fromData(await this.history()).getActivePath();
328
330
  const belongsToSubmission = (entry) => submissionId === undefined || entry.data?.submissionId === submissionId;
329
- const responseStarted = dynamicPath.some((entry) => entry.type === "response_metadata" && entry.data?.phase === "start" && belongsToSubmission(entry));
330
- const agentStarted = dynamicPath.some((entry) => entry.type === "agent_lifecycle" && entry.data?.phase === "start" && belongsToSubmission(entry));
331
+ const responseStarted = dynamicPath.some((entry) => entry.type === "response_metadata" &&
332
+ entry.data?.phase === "start" &&
333
+ belongsToSubmission(entry));
334
+ const agentStarted = dynamicPath.some((entry) => entry.type === "agent_lifecycle" &&
335
+ entry.data?.phase === "start" &&
336
+ belongsToSubmission(entry));
331
337
  if (!inputAlreadyApplied || !responseStarted) {
332
338
  await dynamic.runResponseStart(undefined, submissionCorrelation);
333
339
  }
@@ -410,8 +416,7 @@ export class StubFabricSession {
410
416
  return [];
411
417
  const messages = [];
412
418
  for (const input of inputs) {
413
- if (input.message &&
414
- renderDeliveredMessage(input.message) !== input.text) {
419
+ if (input.message && renderDeliveredMessage(input.message) !== input.text) {
415
420
  throw new FabricError({
416
421
  code: "INVALID_CONFIG",
417
422
  message: "A joined durable submission message does not match its rendered prompt text. " +
@@ -469,6 +474,16 @@ export class StubFabricSession {
469
474
  }
470
475
  : {}),
471
476
  executeToolCalls: (calls, policy, approvalTimeoutMs, attribution) => this.executeToolCalls(calls, tools, sandbox, policy, approvalTimeoutMs, options.onApproval, attribution, options.signal),
477
+ recordToolAdditions: async (toolCallId, names) => {
478
+ if (names.length === 0)
479
+ return;
480
+ await this.recordEntry("signal", {
481
+ signalType: "resources.tool_additions",
482
+ content: "Conditional tools became available after this tool result.",
483
+ toolCallId,
484
+ names,
485
+ });
486
+ },
472
487
  recordEntry: (type, data) => this.recordEntry(type, data),
473
488
  emit: (type, data) => this.emit(type, data),
474
489
  });
@@ -630,9 +645,7 @@ export class StubFabricSession {
630
645
  ...(Object.keys(taskOptions).length
631
646
  ? { options: taskOptions }
632
647
  : {}),
633
- ...(this.options.dynamic
634
- ? { dynamic: this.options.dynamic.executionDescriptor() }
635
- : {}),
648
+ ...(this.options.dynamic ? { dynamic: this.options.dynamic.executionDescriptor() } : {}),
636
649
  });
637
650
  await this.emit("task_end", { taskId, depth: 1, parentSessionId: this.id });
638
651
  return result;
@@ -1503,7 +1516,9 @@ export class StubFabricSession {
1503
1516
  input: call.input,
1504
1517
  inputDigest: approvalInputDigest(call.input),
1505
1518
  policyDigest: approvalInputDigest(policy ?? null),
1506
- ...(executingPrincipal ? { executingPrincipal: executingPrincipal } : {}),
1519
+ ...(executingPrincipal
1520
+ ? { executingPrincipal: executingPrincipal }
1521
+ : {}),
1507
1522
  ...(approvalGrant ? { approval: approvalGrantToJson(approvalGrant) } : {}),
1508
1523
  ...(tool?.metadata?.effect ? { effect: tool.metadata.effect } : {}),
1509
1524
  ...(tool?.durable ? { durable: true } : {}),
@@ -1561,7 +1576,7 @@ export class StubFabricSession {
1561
1576
  }
1562
1577
  : {}),
1563
1578
  }));
1564
- const rawOutput = await approvedSandboxCalls.reduceRight((next, approvedCall) => () => runWithSandboxPolicyApproval(sandbox, approvedCall, next), execute)();
1579
+ const rawOutput = await abandonToolOnAbort(approvedSandboxCalls.reduceRight((next, approvedCall) => () => runWithSandboxPolicyApproval(sandbox, approvedCall, next), execute), signal);
1565
1580
  const dynamicOutput = unwrapDynamicToolResult(rawOutput);
1566
1581
  const hookOutput = unwrapHookToolRunResult(dynamicOutput.output);
1567
1582
  const output = hookOutput.output;
@@ -1942,7 +1957,11 @@ export class StubFabricSession {
1942
1957
  const toolName = typeof call.data?.tool === "string" ? call.data.tool : undefined;
1943
1958
  const toolCallId = typeof call.data?.toolCallId === "string" ? call.data.toolCallId : undefined;
1944
1959
  const tool = toolName ? tools.get(toolName) : undefined;
1945
- if (call.data?.durable !== true || !tool?.durable || !tool.execute || !toolCallId || !toolName) {
1960
+ if (call.data?.durable !== true ||
1961
+ !tool?.durable ||
1962
+ !tool.execute ||
1963
+ !toolCallId ||
1964
+ !toolName) {
1946
1965
  continue;
1947
1966
  }
1948
1967
  await this.emit("tool_start", { tool: toolName, recovery: true, toolCallId });
@@ -1971,9 +1990,10 @@ export class StubFabricSession {
1971
1990
  }
1972
1991
  : {}),
1973
1992
  }));
1974
- const rawOutput = authorization.approvedCall
1975
- ? await runWithSandboxPolicyApproval(sandbox, authorization.approvedCall, execute)
1976
- : await execute();
1993
+ const approvedCall = authorization.approvedCall;
1994
+ const rawOutput = await abandonToolOnAbort(approvedCall
1995
+ ? () => runWithSandboxPolicyApproval(sandbox, approvedCall, execute)
1996
+ : execute, signal);
1977
1997
  const dynamicOutput = unwrapDynamicToolResult(rawOutput);
1978
1998
  const hookOutput = unwrapHookToolRunResult(dynamicOutput.output);
1979
1999
  await this.recordToolResult({
@@ -2088,7 +2108,8 @@ export class StubFabricSession {
2088
2108
  message: `Recovered tool ${toolName} has no matching persisted input authorization digest.`,
2089
2109
  });
2090
2110
  }
2091
- if (call.tenantId !== this.options.tenantId || !sameFabricActor(call.actor, this.options.actor)) {
2111
+ if (call.tenantId !== this.options.tenantId ||
2112
+ !sameFabricActor(call.actor, this.options.actor)) {
2092
2113
  throw new FabricError({
2093
2114
  code: "POLICY_DENIED",
2094
2115
  message: `Recovered tool ${toolName} does not match the current tenant and actor context.`,
@@ -2286,7 +2307,9 @@ export class StubFabricSession {
2286
2307
  toolCallId,
2287
2308
  name,
2288
2309
  value,
2289
- ...(submission ? { submissionId: submission.submissionId, attemptId: submission.attemptId } : {}),
2310
+ ...(submission
2311
+ ? { submissionId: submission.submissionId, attemptId: submission.attemptId }
2312
+ : {}),
2290
2313
  },
2291
2314
  };
2292
2315
  await this.store.appendEntry?.(this.id, entry);
@@ -2363,7 +2386,9 @@ export class StubFabricSession {
2363
2386
  ...(this.options.tenantId ? { tenantId: this.options.tenantId } : {}),
2364
2387
  data: {
2365
2388
  ...data,
2366
- ...(submission ? { submissionId: submission.submissionId, attemptId: submission.attemptId } : {}),
2389
+ ...(submission
2390
+ ? { submissionId: submission.submissionId, attemptId: submission.attemptId }
2391
+ : {}),
2367
2392
  },
2368
2393
  };
2369
2394
  const committed = await this.store.appendEntries(this.id, [...stateEntries, resultEntry], {