@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.
- package/dist/abort.d.ts +16 -0
- package/dist/abort.d.ts.map +1 -0
- package/dist/abort.js +82 -0
- package/dist/abort.js.map +1 -0
- package/dist/history.d.ts +2 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +101 -66
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loop.d.ts +10 -8
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +120 -73
- package/dist/loop.js.map +1 -1
- package/dist/model.d.ts +2 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +1 -1
- package/dist/model.js.map +1 -1
- package/dist/otel-observer.d.ts +6 -4
- package/dist/otel-observer.d.ts.map +1 -1
- package/dist/otel-observer.js +139 -52
- package/dist/otel-observer.js.map +1 -1
- package/dist/pi-loop-runtime.d.ts +4 -4
- package/dist/pi-loop-runtime.d.ts.map +1 -1
- package/dist/pi-loop-runtime.js +118 -72
- package/dist/pi-loop-runtime.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +46 -21
- package/dist/session.js.map +1 -1
- package/dist/strict.d.ts +1 -1
- package/dist/strict.d.ts.map +1 -1
- package/dist/strict.js +1 -1
- package/dist/strict.js.map +1 -1
- package/dist/submission-runner.d.ts +15 -13
- package/dist/submission-runner.d.ts.map +1 -1
- package/dist/submission-runner.js +231 -94
- package/dist/submission-runner.js.map +1 -1
- package/dist/submission-telemetry.d.ts +11 -11
- package/dist/submission-telemetry.d.ts.map +1 -1
- package/dist/submission-telemetry.js +1 -1
- package/dist/submission-telemetry.js.map +1 -1
- package/dist/tools.d.ts +16 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +291 -47
- package/dist/tools.js.map +1 -1
- 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 {
|
|
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 = {
|
|
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" &&
|
|
330
|
-
|
|
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
|
|
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 ||
|
|
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
|
|
1975
|
-
|
|
1976
|
-
|
|
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 ||
|
|
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
|
|
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
|
|
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], {
|