@fabric-harness/sdk 6.0.1 → 6.2.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/agent-route.d.ts +76 -0
- package/dist/agent-route.d.ts.map +1 -0
- package/dist/agent-route.js +78 -0
- package/dist/agent-route.js.map +1 -0
- package/dist/agent-router.d.ts +128 -0
- package/dist/agent-router.d.ts.map +1 -0
- package/dist/agent-router.js +193 -0
- package/dist/agent-router.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 +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/local-confinement.d.ts +31 -0
- package/dist/local-confinement.d.ts.map +1 -0
- package/dist/local-confinement.js +297 -0
- package/dist/local-confinement.js.map +1 -0
- package/dist/loop.d.ts +20 -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 +43 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +121 -13
- 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 +115 -73
- package/dist/pi-loop-runtime.js.map +1 -1
- package/dist/policied-sandbox.js +5 -5
- package/dist/policied-sandbox.js.map +1 -1
- package/dist/sandbox-ref.d.ts.map +1 -1
- package/dist/sandbox-ref.js +9 -6
- package/dist/sandbox-ref.js.map +1 -1
- package/dist/sandbox.d.ts +10 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +27 -11
- package/dist/sandbox.js.map +1 -1
- package/dist/session.d.ts +16 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +86 -22
- package/dist/session.js.map +1 -1
- package/dist/skill-definition.d.ts +40 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +37 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/strict.d.ts +10 -4
- package/dist/strict.d.ts.map +1 -1
- package/dist/strict.js +5 -2
- 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/suspending-sandbox.js +3 -3
- package/dist/suspending-sandbox.js.map +1 -1
- package/dist/testing.d.ts +2 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.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 +13 -9
- package/types/markdown.d.ts +35 -0
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";
|
|
@@ -113,6 +114,7 @@ export class StubFabricSession {
|
|
|
113
114
|
ownedSandboxRefId;
|
|
114
115
|
costBudget;
|
|
115
116
|
skillCache = new Map();
|
|
117
|
+
effectivePackagedSkillsCache = null;
|
|
116
118
|
constructor(agent, id, options = {}) {
|
|
117
119
|
this.agent = agent;
|
|
118
120
|
this.id = id;
|
|
@@ -165,9 +167,7 @@ export class StubFabricSession {
|
|
|
165
167
|
const result = await durable.prompt({
|
|
166
168
|
text,
|
|
167
169
|
...(options ? { options } : {}),
|
|
168
|
-
...(this.options.dynamic
|
|
169
|
-
? { dynamic: this.options.dynamic.executionDescriptor() }
|
|
170
|
-
: {}),
|
|
170
|
+
...(this.options.dynamic ? { dynamic: this.options.dynamic.executionDescriptor() } : {}),
|
|
171
171
|
});
|
|
172
172
|
await this.emit("prompt_end", { text });
|
|
173
173
|
return result;
|
|
@@ -256,7 +256,10 @@ export class StubFabricSession {
|
|
|
256
256
|
Reflect.deleteProperty(this.options, "compaction");
|
|
257
257
|
if (options.role === undefined) {
|
|
258
258
|
if (config.instructions) {
|
|
259
|
-
this.options.role = {
|
|
259
|
+
this.options.role = {
|
|
260
|
+
name: config.name ?? "instructions",
|
|
261
|
+
content: config.instructions,
|
|
262
|
+
};
|
|
260
263
|
}
|
|
261
264
|
else {
|
|
262
265
|
Reflect.deleteProperty(this.options, "role");
|
|
@@ -326,8 +329,12 @@ export class StubFabricSession {
|
|
|
326
329
|
const submissionId = options.submission?.submissionId;
|
|
327
330
|
const dynamicPath = SessionHistory.fromData(await this.history()).getActivePath();
|
|
328
331
|
const belongsToSubmission = (entry) => submissionId === undefined || entry.data?.submissionId === submissionId;
|
|
329
|
-
const responseStarted = dynamicPath.some((entry) => entry.type === "response_metadata" &&
|
|
330
|
-
|
|
332
|
+
const responseStarted = dynamicPath.some((entry) => entry.type === "response_metadata" &&
|
|
333
|
+
entry.data?.phase === "start" &&
|
|
334
|
+
belongsToSubmission(entry));
|
|
335
|
+
const agentStarted = dynamicPath.some((entry) => entry.type === "agent_lifecycle" &&
|
|
336
|
+
entry.data?.phase === "start" &&
|
|
337
|
+
belongsToSubmission(entry));
|
|
331
338
|
if (!inputAlreadyApplied || !responseStarted) {
|
|
332
339
|
await dynamic.runResponseStart(undefined, submissionCorrelation);
|
|
333
340
|
}
|
|
@@ -365,6 +372,9 @@ export class StubFabricSession {
|
|
|
365
372
|
? { affinityKey: sessionData.affinityKey }
|
|
366
373
|
: {}),
|
|
367
374
|
text,
|
|
375
|
+
...(options.submission?.message !== undefined
|
|
376
|
+
? { delivery: options.submission.message }
|
|
377
|
+
: {}),
|
|
368
378
|
messages,
|
|
369
379
|
tools,
|
|
370
380
|
sandbox,
|
|
@@ -410,8 +420,7 @@ export class StubFabricSession {
|
|
|
410
420
|
return [];
|
|
411
421
|
const messages = [];
|
|
412
422
|
for (const input of inputs) {
|
|
413
|
-
if (input.message &&
|
|
414
|
-
renderDeliveredMessage(input.message) !== input.text) {
|
|
423
|
+
if (input.message && renderDeliveredMessage(input.message) !== input.text) {
|
|
415
424
|
throw new FabricError({
|
|
416
425
|
code: "INVALID_CONFIG",
|
|
417
426
|
message: "A joined durable submission message does not match its rendered prompt text. " +
|
|
@@ -469,6 +478,16 @@ export class StubFabricSession {
|
|
|
469
478
|
}
|
|
470
479
|
: {}),
|
|
471
480
|
executeToolCalls: (calls, policy, approvalTimeoutMs, attribution) => this.executeToolCalls(calls, tools, sandbox, policy, approvalTimeoutMs, options.onApproval, attribution, options.signal),
|
|
481
|
+
recordToolAdditions: async (toolCallId, names) => {
|
|
482
|
+
if (names.length === 0)
|
|
483
|
+
return;
|
|
484
|
+
await this.recordEntry("signal", {
|
|
485
|
+
signalType: "resources.tool_additions",
|
|
486
|
+
content: "Conditional tools became available after this tool result.",
|
|
487
|
+
toolCallId,
|
|
488
|
+
names,
|
|
489
|
+
});
|
|
490
|
+
},
|
|
472
491
|
recordEntry: (type, data) => this.recordEntry(type, data),
|
|
473
492
|
emit: (type, data) => this.emit(type, data),
|
|
474
493
|
});
|
|
@@ -630,9 +649,7 @@ export class StubFabricSession {
|
|
|
630
649
|
...(Object.keys(taskOptions).length
|
|
631
650
|
? { options: taskOptions }
|
|
632
651
|
: {}),
|
|
633
|
-
...(this.options.dynamic
|
|
634
|
-
? { dynamic: this.options.dynamic.executionDescriptor() }
|
|
635
|
-
: {}),
|
|
652
|
+
...(this.options.dynamic ? { dynamic: this.options.dynamic.executionDescriptor() } : {}),
|
|
636
653
|
});
|
|
637
654
|
await this.emit("task_end", { taskId, depth: 1, parentSessionId: this.id });
|
|
638
655
|
return result;
|
|
@@ -1503,7 +1520,9 @@ export class StubFabricSession {
|
|
|
1503
1520
|
input: call.input,
|
|
1504
1521
|
inputDigest: approvalInputDigest(call.input),
|
|
1505
1522
|
policyDigest: approvalInputDigest(policy ?? null),
|
|
1506
|
-
...(executingPrincipal
|
|
1523
|
+
...(executingPrincipal
|
|
1524
|
+
? { executingPrincipal: executingPrincipal }
|
|
1525
|
+
: {}),
|
|
1507
1526
|
...(approvalGrant ? { approval: approvalGrantToJson(approvalGrant) } : {}),
|
|
1508
1527
|
...(tool?.metadata?.effect ? { effect: tool.metadata.effect } : {}),
|
|
1509
1528
|
...(tool?.durable ? { durable: true } : {}),
|
|
@@ -1561,7 +1580,7 @@ export class StubFabricSession {
|
|
|
1561
1580
|
}
|
|
1562
1581
|
: {}),
|
|
1563
1582
|
}));
|
|
1564
|
-
const rawOutput = await approvedSandboxCalls.reduceRight((next, approvedCall) => () => runWithSandboxPolicyApproval(sandbox, approvedCall, next), execute)
|
|
1583
|
+
const rawOutput = await abandonToolOnAbort(approvedSandboxCalls.reduceRight((next, approvedCall) => () => runWithSandboxPolicyApproval(sandbox, approvedCall, next), execute), signal);
|
|
1565
1584
|
const dynamicOutput = unwrapDynamicToolResult(rawOutput);
|
|
1566
1585
|
const hookOutput = unwrapHookToolRunResult(dynamicOutput.output);
|
|
1567
1586
|
const output = hookOutput.output;
|
|
@@ -1805,7 +1824,7 @@ export class StubFabricSession {
|
|
|
1805
1824
|
const commandToolOptions = this.options.resolveSecret
|
|
1806
1825
|
? { resolveSecret: this.options.resolveSecret }
|
|
1807
1826
|
: {};
|
|
1808
|
-
for (const tool of createBuiltinTools(sandbox, this.
|
|
1827
|
+
for (const tool of createBuiltinTools(sandbox, this.effectivePackagedSkills()))
|
|
1809
1828
|
tools.set(tool.name, tool);
|
|
1810
1829
|
for (const tool of createCommandTools(this.options.commands ?? [], commandToolOptions))
|
|
1811
1830
|
tools.set(tool.name, tool);
|
|
@@ -1849,6 +1868,41 @@ export class StubFabricSession {
|
|
|
1849
1868
|
this.skillCache.set(name, content);
|
|
1850
1869
|
return content;
|
|
1851
1870
|
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Packaged directories the `read` tool can serve.
|
|
1873
|
+
*
|
|
1874
|
+
* A skill carrying `packaged` advertises its files to the model at
|
|
1875
|
+
* activation time (see `formatPackagedSkillResourceList`). Those paths are
|
|
1876
|
+
* only readable if the directory is also registered here, so registered
|
|
1877
|
+
* skills contribute their own directories on top of the explicit
|
|
1878
|
+
* `packagedSkills` option. Without this, an imported or `defineSkill()`
|
|
1879
|
+
* skill would advertise resources that every `read` call reports missing.
|
|
1880
|
+
*
|
|
1881
|
+
* The explicit option wins on `id` collision: it is the caller's deliberate
|
|
1882
|
+
* registration, and silently shadowing it with a skill-carried directory
|
|
1883
|
+
* would change which bytes a known path returns.
|
|
1884
|
+
*/
|
|
1885
|
+
effectivePackagedSkills() {
|
|
1886
|
+
if (this.effectivePackagedSkillsCache !== null) {
|
|
1887
|
+
return this.effectivePackagedSkillsCache;
|
|
1888
|
+
}
|
|
1889
|
+
const explicit = this.options.packagedSkills;
|
|
1890
|
+
const carried = (this.options.skills ?? []).flatMap((skill) => skill.packaged ? [skill.packaged] : []);
|
|
1891
|
+
if (carried.length === 0) {
|
|
1892
|
+
this.effectivePackagedSkillsCache = explicit;
|
|
1893
|
+
return explicit;
|
|
1894
|
+
}
|
|
1895
|
+
const merged = { ...(explicit ?? {}) };
|
|
1896
|
+
const claimed = new Set(Object.values(merged).map((directory) => directory.id));
|
|
1897
|
+
for (const directory of carried) {
|
|
1898
|
+
if (claimed.has(directory.id))
|
|
1899
|
+
continue;
|
|
1900
|
+
claimed.add(directory.id);
|
|
1901
|
+
merged[directory.id] = directory;
|
|
1902
|
+
}
|
|
1903
|
+
this.effectivePackagedSkillsCache = merged;
|
|
1904
|
+
return merged;
|
|
1905
|
+
}
|
|
1852
1906
|
resolveSkill(name) {
|
|
1853
1907
|
const normalized = normalizeSkillReference(name);
|
|
1854
1908
|
return this.options.skills?.find((skill) => {
|
|
@@ -1942,7 +1996,11 @@ export class StubFabricSession {
|
|
|
1942
1996
|
const toolName = typeof call.data?.tool === "string" ? call.data.tool : undefined;
|
|
1943
1997
|
const toolCallId = typeof call.data?.toolCallId === "string" ? call.data.toolCallId : undefined;
|
|
1944
1998
|
const tool = toolName ? tools.get(toolName) : undefined;
|
|
1945
|
-
if (call.data?.durable !== true ||
|
|
1999
|
+
if (call.data?.durable !== true ||
|
|
2000
|
+
!tool?.durable ||
|
|
2001
|
+
!tool.execute ||
|
|
2002
|
+
!toolCallId ||
|
|
2003
|
+
!toolName) {
|
|
1946
2004
|
continue;
|
|
1947
2005
|
}
|
|
1948
2006
|
await this.emit("tool_start", { tool: toolName, recovery: true, toolCallId });
|
|
@@ -1971,9 +2029,10 @@ export class StubFabricSession {
|
|
|
1971
2029
|
}
|
|
1972
2030
|
: {}),
|
|
1973
2031
|
}));
|
|
1974
|
-
const
|
|
1975
|
-
|
|
1976
|
-
|
|
2032
|
+
const approvedCall = authorization.approvedCall;
|
|
2033
|
+
const rawOutput = await abandonToolOnAbort(approvedCall
|
|
2034
|
+
? () => runWithSandboxPolicyApproval(sandbox, approvedCall, execute)
|
|
2035
|
+
: execute, signal);
|
|
1977
2036
|
const dynamicOutput = unwrapDynamicToolResult(rawOutput);
|
|
1978
2037
|
const hookOutput = unwrapHookToolRunResult(dynamicOutput.output);
|
|
1979
2038
|
await this.recordToolResult({
|
|
@@ -2088,7 +2147,8 @@ export class StubFabricSession {
|
|
|
2088
2147
|
message: `Recovered tool ${toolName} has no matching persisted input authorization digest.`,
|
|
2089
2148
|
});
|
|
2090
2149
|
}
|
|
2091
|
-
if (call.tenantId !== this.options.tenantId ||
|
|
2150
|
+
if (call.tenantId !== this.options.tenantId ||
|
|
2151
|
+
!sameFabricActor(call.actor, this.options.actor)) {
|
|
2092
2152
|
throw new FabricError({
|
|
2093
2153
|
code: "POLICY_DENIED",
|
|
2094
2154
|
message: `Recovered tool ${toolName} does not match the current tenant and actor context.`,
|
|
@@ -2286,7 +2346,9 @@ export class StubFabricSession {
|
|
|
2286
2346
|
toolCallId,
|
|
2287
2347
|
name,
|
|
2288
2348
|
value,
|
|
2289
|
-
...(submission
|
|
2349
|
+
...(submission
|
|
2350
|
+
? { submissionId: submission.submissionId, attemptId: submission.attemptId }
|
|
2351
|
+
: {}),
|
|
2290
2352
|
},
|
|
2291
2353
|
};
|
|
2292
2354
|
await this.store.appendEntry?.(this.id, entry);
|
|
@@ -2363,7 +2425,9 @@ export class StubFabricSession {
|
|
|
2363
2425
|
...(this.options.tenantId ? { tenantId: this.options.tenantId } : {}),
|
|
2364
2426
|
data: {
|
|
2365
2427
|
...data,
|
|
2366
|
-
...(submission
|
|
2428
|
+
...(submission
|
|
2429
|
+
? { submissionId: submission.submissionId, attemptId: submission.attemptId }
|
|
2430
|
+
: {}),
|
|
2367
2431
|
},
|
|
2368
2432
|
};
|
|
2369
2433
|
const committed = await this.store.appendEntries(this.id, [...stateEntries, resultEntry], {
|