@fabric-harness/sdk 6.9.1 → 6.11.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 (102) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +8 -0
  3. package/dist/agent.js.map +1 -1
  4. package/dist/channel-runtime.d.ts +2 -0
  5. package/dist/channel-runtime.d.ts.map +1 -1
  6. package/dist/channel-runtime.js +1 -0
  7. package/dist/channel-runtime.js.map +1 -1
  8. package/dist/channel.d.ts +11 -0
  9. package/dist/channel.d.ts.map +1 -1
  10. package/dist/channel.js.map +1 -1
  11. package/dist/context.d.ts +28 -0
  12. package/dist/context.d.ts.map +1 -1
  13. package/dist/context.js +18 -0
  14. package/dist/context.js.map +1 -1
  15. package/dist/conversation-ownership.d.ts +151 -0
  16. package/dist/conversation-ownership.d.ts.map +1 -0
  17. package/dist/conversation-ownership.js +239 -0
  18. package/dist/conversation-ownership.js.map +1 -0
  19. package/dist/dispatch.d.ts +7 -0
  20. package/dist/dispatch.d.ts.map +1 -1
  21. package/dist/dispatch.js.map +1 -1
  22. package/dist/dynamic-agent.d.ts.map +1 -1
  23. package/dist/dynamic-agent.js +8 -0
  24. package/dist/dynamic-agent.js.map +1 -1
  25. package/dist/error.d.ts +1 -1
  26. package/dist/error.d.ts.map +1 -1
  27. package/dist/error.js.map +1 -1
  28. package/dist/events.d.ts +16 -4
  29. package/dist/events.d.ts.map +1 -1
  30. package/dist/events.js.map +1 -1
  31. package/dist/governed-voice.d.ts.map +1 -1
  32. package/dist/governed-voice.js +192 -125
  33. package/dist/governed-voice.js.map +1 -1
  34. package/dist/index.d.ts +9 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/loop.d.ts +8 -0
  39. package/dist/loop.d.ts.map +1 -1
  40. package/dist/loop.js +22 -1
  41. package/dist/loop.js.map +1 -1
  42. package/dist/model-pricing.js +1 -1
  43. package/dist/model-pricing.js.map +1 -1
  44. package/dist/model.d.ts +20 -2
  45. package/dist/model.d.ts.map +1 -1
  46. package/dist/model.js +88 -9
  47. package/dist/model.js.map +1 -1
  48. package/dist/operational-metrics.d.ts.map +1 -1
  49. package/dist/operational-metrics.js +3 -1
  50. package/dist/operational-metrics.js.map +1 -1
  51. package/dist/otel-observer.d.ts.map +1 -1
  52. package/dist/otel-observer.js +32 -10
  53. package/dist/otel-observer.js.map +1 -1
  54. package/dist/persistent-agent.d.ts +1 -1
  55. package/dist/persistent-agent.d.ts.map +1 -1
  56. package/dist/persistent-agent.js.map +1 -1
  57. package/dist/pi-loop-runtime.d.ts.map +1 -1
  58. package/dist/pi-loop-runtime.js +152 -8
  59. package/dist/pi-loop-runtime.js.map +1 -1
  60. package/dist/policied-sandbox.d.ts.map +1 -1
  61. package/dist/policied-sandbox.js +16 -3
  62. package/dist/policied-sandbox.js.map +1 -1
  63. package/dist/proposal-tool.d.ts +260 -0
  64. package/dist/proposal-tool.d.ts.map +1 -0
  65. package/dist/proposal-tool.js +562 -0
  66. package/dist/proposal-tool.js.map +1 -0
  67. package/dist/session.d.ts +55 -0
  68. package/dist/session.d.ts.map +1 -1
  69. package/dist/session.js +528 -181
  70. package/dist/session.js.map +1 -1
  71. package/dist/stop-reason-guard.d.ts +89 -0
  72. package/dist/stop-reason-guard.d.ts.map +1 -0
  73. package/dist/stop-reason-guard.js +261 -0
  74. package/dist/stop-reason-guard.js.map +1 -0
  75. package/dist/strict.d.ts +8 -1
  76. package/dist/strict.d.ts.map +1 -1
  77. package/dist/strict.js +4 -1
  78. package/dist/strict.js.map +1 -1
  79. package/dist/tools.d.ts +2 -0
  80. package/dist/tools.d.ts.map +1 -1
  81. package/dist/tools.js +10 -2
  82. package/dist/tools.js.map +1 -1
  83. package/dist/trace-content.d.ts +1 -1
  84. package/dist/trace-content.d.ts.map +1 -1
  85. package/dist/trace-content.js +2 -2
  86. package/dist/trace-content.js.map +1 -1
  87. package/dist/types.d.ts +23 -1
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js.map +1 -1
  90. package/dist/voice-pipeline.d.ts +70 -3
  91. package/dist/voice-pipeline.d.ts.map +1 -1
  92. package/dist/voice-pipeline.js +386 -44
  93. package/dist/voice-pipeline.js.map +1 -1
  94. package/dist/voice-sentences.d.ts +43 -0
  95. package/dist/voice-sentences.d.ts.map +1 -0
  96. package/dist/voice-sentences.js +99 -0
  97. package/dist/voice-sentences.js.map +1 -0
  98. package/dist/voice.d.ts +9 -0
  99. package/dist/voice.d.ts.map +1 -1
  100. package/dist/voice.js +6 -0
  101. package/dist/voice.js.map +1 -1
  102. package/package.json +30 -13
@@ -0,0 +1,562 @@
1
+ import { createHash } from "node:crypto";
2
+ import { FabricError } from "./error.js";
3
+ import { getLogger } from "./logger.js";
4
+ import { evaluateToolCallPolicy } from "./policy.js";
5
+ import { SchemaValidationError } from "./schema.js";
6
+ import { HARNESS_RESULT_TOOL_NAMES } from "./tools.js";
7
+ /**
8
+ * Top-level param keys a proposal may not carry: the harness owns the
9
+ * idempotency key and the session and run identity, and these fields steer how
10
+ * the authority routes a mutation (`MutationCommonInput` in
11
+ * `@fabric-harness/agent-registry`). Matched case-insensitively.
12
+ */
13
+ export const RESERVED_PROPOSAL_PARAM_KEYS = Object.freeze([
14
+ "idempotencyKey",
15
+ "causedByApprovalRequestId",
16
+ "agentSessionId",
17
+ "agentRunId",
18
+ "confidence",
19
+ "riskTier",
20
+ ]);
21
+ const RESERVED_LOWER = new Set(RESERVED_PROPOSAL_PARAM_KEYS.map((key) => key.toLowerCase()));
22
+ /**
23
+ * Proposal tools are recognized by their `execute` function, which only this
24
+ * module creates and which throws when called directly. When the session
25
+ * resolves its tools it looks up each tool's own `execute` data property
26
+ * here, once, and keeps the runner with the resolved tool; a definition whose
27
+ * `execute` is any other function, or a getter, is an ordinary tool and runs
28
+ * as one.
29
+ */
30
+ const proposalRunners = new WeakMap();
31
+ /** @internal The proposal runner for an `execute` reference, if it is a proposal tool's. */
32
+ export function proposalRunnerFor(execute) {
33
+ return typeof execute === "function" ? proposalRunners.get(execute) : undefined;
34
+ }
35
+ /**
36
+ * Whether `tool` is a proposal tool: its own `execute` data property is a
37
+ * function `defineProposalTool()` created. The property is read through its
38
+ * descriptor, so no getter runs; an `execute` getter is never a proposal tool.
39
+ */
40
+ export function isProposalTool(tool) {
41
+ return proposalRunnerOf(tool) !== undefined;
42
+ }
43
+ /**
44
+ * @internal The runner of a proposal tool, found through the tool's own
45
+ * `execute` data property, so no getter runs and an inherited `execute` is
46
+ * ignored. Every place that decides whether a tool is a proposal tool uses this.
47
+ */
48
+ export function proposalRunnerOf(tool) {
49
+ if (typeof tool !== "object" || tool === null)
50
+ return undefined;
51
+ const descriptor = Object.getOwnPropertyDescriptor(tool, "execute");
52
+ return descriptor && "value" in descriptor ? proposalRunnerFor(descriptor.value) : undefined;
53
+ }
54
+ /**
55
+ * The idempotency key one proposal is submitted under: a SHA-256 digest of the
56
+ * session's tenant id (when it has one), the session id, the action id and the
57
+ * digest of the params' plain-JSON snapshot, with object keys in code-unit
58
+ * order. Throws for params that are not plain JSON. The same action and params
59
+ * in the same session produce the same key. Pass the session's `tenantId` to
60
+ * reproduce the key of a tenant-scoped session; without it the key differs.
61
+ */
62
+ export function proposalIdempotencyKey(sessionId, actionId, params, tenantId) {
63
+ return idempotencyKeyFor(tenantId, sessionId, actionId, paramsDigestOf(jsonSnapshot(params, "params")));
64
+ }
65
+ /** The tenant is key material because session ids are host-chosen and may repeat across tenants. */
66
+ function idempotencyKeyFor(tenantId, sessionId, actionId, paramsDigest) {
67
+ return `fh-proposal-v1:${sha256(proposalCanonicalJson([
68
+ "fabric-harness.proposal.v1",
69
+ tenantId ?? null,
70
+ sessionId,
71
+ actionId,
72
+ paramsDigest,
73
+ ]))}`;
74
+ }
75
+ function paramsDigestOf(snapshot) {
76
+ return `sha256:${sha256(proposalCanonicalJson(snapshot))}`;
77
+ }
78
+ /**
79
+ * Build a tool whose effect is a governed proposal to the external approval
80
+ * authority the session is configured with. The session runs it through an
81
+ * SDK-owned runner that validates input, maps it to params, snapshots them to
82
+ * plain JSON, refuses reserved param keys in that snapshot, resolves the
83
+ * principal, calls the port at most once, and maps the authority's answer to
84
+ * a route.
85
+ */
86
+ export function defineProposalTool(definition) {
87
+ const { name, actionId } = definition;
88
+ if (typeof name !== "string" || name.length === 0) {
89
+ throw new TypeError("Proposal tool name must be a non-empty string.");
90
+ }
91
+ if (typeof actionId !== "string" || actionId.trim().length === 0) {
92
+ throw new TypeError(`Proposal tool "${name}" needs a non-empty actionId.`);
93
+ }
94
+ if (!hasParser(definition.input)) {
95
+ throw new TypeError(`Proposal tool "${name}" needs an input schema with parse() or safeParse(); its input is validated before anything is submitted.`);
96
+ }
97
+ if (typeof definition.params !== "function") {
98
+ throw new TypeError(`Proposal tool "${name}" needs a params function that maps validated input to the action's params.`);
99
+ }
100
+ const timeoutMs = definition.timeoutMs;
101
+ if (timeoutMs !== undefined &&
102
+ (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2_147_483_647)) {
103
+ throw new TypeError("Proposal tool timeoutMs must be a positive safe integer.");
104
+ }
105
+ const schema = definition.input;
106
+ const mapParams = definition.params;
107
+ const runner = {
108
+ actionId,
109
+ async run(rawInput, context, binding) {
110
+ const input = parseInput(schema, rawInput, name, actionId);
111
+ let mapped;
112
+ try {
113
+ mapped = mapParams(input);
114
+ }
115
+ catch {
116
+ // The mapper is host code; its error text does not reach the model.
117
+ reportFailure("proposal params mapping failed", name, actionId);
118
+ throw new Error(`Proposal tool "${name}" could not map its input to params; nothing was submitted.`);
119
+ }
120
+ // Every check below reads this snapshot, never `mapped`, and the port
121
+ // receives this snapshot: what was checked is what is sent.
122
+ const params = jsonSnapshot(mapped, `Proposal tool "${name}" params`);
123
+ assertProposalParams(params, name);
124
+ const idempotencyKey = idempotencyKeyFor(binding.tenantId, binding.sessionId, actionId, paramsDigestOf(params));
125
+ // The deadline bounds how long the harness waits for the principal
126
+ // resolver and the port call, and the caller's signal ends that wait too;
127
+ // neither is passed to the resolver or the port. It is a timer, so it is checked only
128
+ // when the event loop gets a turn: synchronous work in a resolver or
129
+ // port can outrun it.
130
+ const deadline = new AbortController();
131
+ const timer = timeoutMs === undefined ? undefined : setTimeout(() => deadline.abort(), timeoutMs);
132
+ const signals = [deadline.signal, ...(context?.signal ? [context.signal] : [])];
133
+ const signal = signals.length === 1 ? deadline.signal : AbortSignal.any(signals);
134
+ let submitted = false;
135
+ try {
136
+ let principal;
137
+ try {
138
+ principal = await boundBy(Promise.resolve().then(() => binding.authority.resolvePrincipal({
139
+ sessionId: binding.sessionId,
140
+ ...(binding.tenantId !== undefined ? { tenantId: binding.tenantId } : {}),
141
+ ...(binding.actor !== undefined ? { actor: binding.actor } : {}),
142
+ })), signal);
143
+ }
144
+ catch {
145
+ reportFailure("proposal principal resolution failed", name, actionId);
146
+ throw new Error(`Proposal tool "${name}" could not resolve a principal; nothing was submitted.`);
147
+ }
148
+ let response;
149
+ try {
150
+ response = await boundBy(Promise.resolve().then(() => {
151
+ // Everything from here to the call is synchronous, so what is
152
+ // checked is what is sent. A call already cancelled, or already
153
+ // aborted by the deadline timer, is not submitted; synchronous
154
+ // work in the resolver or port can outrun that timer.
155
+ if (signal.aborted)
156
+ throw new Error("Proposal call ended before submission.");
157
+ assertPrincipalTenant(principal, binding.tenantId, name);
158
+ const port = binding.authority.port;
159
+ const invoke = port?.invoke;
160
+ if (typeof invoke !== "function") {
161
+ throw new ProposalRefusal(`Proposal tool "${name}" has a proposal authority whose port has no invoke function; nothing was submitted.`);
162
+ }
163
+ submitted = true;
164
+ binding.submitting(idempotencyKey);
165
+ return invoke.call(port, {
166
+ principal,
167
+ actionId,
168
+ params,
169
+ idempotencyKey,
170
+ });
171
+ }), signal);
172
+ }
173
+ catch (error) {
174
+ if (!submitted) {
175
+ if (error instanceof ProposalRefusal)
176
+ throw error;
177
+ throw new Error(`Proposal tool "${name}" was cancelled or timed out before submission; nothing was submitted.`);
178
+ }
179
+ reportFailure("proposal submission outcome unknown", name, actionId);
180
+ const result = unknownResult(idempotencyKey);
181
+ binding.settled({ actionId, result });
182
+ return result;
183
+ }
184
+ const result = proposalResultFromAnswer(answerShape(response), idempotencyKey);
185
+ binding.settled({ actionId, result });
186
+ return result;
187
+ }
188
+ finally {
189
+ if (timer !== undefined)
190
+ clearTimeout(timer);
191
+ }
192
+ },
193
+ };
194
+ // The session's proposal runner performs the call; this function is the
195
+ // registry key, and it throws when called directly.
196
+ const execute = async () => {
197
+ throw new Error(`[fabric-harness] Proposal tool "${name}" runs only through a session configured with a proposalAuthority; nothing was submitted.`);
198
+ };
199
+ proposalRunners.set(execute, runner);
200
+ return {
201
+ name,
202
+ ...(definition.description !== undefined ? { description: definition.description } : {}),
203
+ ...(definition.annotations !== undefined
204
+ ? { annotations: Object.freeze({ ...definition.annotations }) }
205
+ : {}),
206
+ inputSchema: schemaToJson(schema),
207
+ metadata: { effect: "write", kind: "proposal", actionId },
208
+ execute,
209
+ };
210
+ }
211
+ /** @internal The configuration error a proposal tool is refused with. */
212
+ export function proposalConfigurationError(toolName, reason) {
213
+ return new FabricError({
214
+ code: "INVALID_CONFIG",
215
+ message: `[fabric-harness] Proposal tool "${toolName}" ${reason}`,
216
+ });
217
+ }
218
+ /** @internal Reason text for a proposal tool matched by a policy approval rule. */
219
+ export function proposalApprovalRuleReason(pattern) {
220
+ return `is matched by the policy approval rule "${pattern ?? "unknown"}". Its external authority owns approval; remove the rule so a person is not asked twice.`;
221
+ }
222
+ /**
223
+ * @internal Classify each tool once, as `isProposalTool()` does, without
224
+ * running any getter. The session keeps this result with its resolved tools
225
+ * and does not classify a resolved tool again.
226
+ */
227
+ export function classifyTools(tools) {
228
+ return tools.map((tool) => ({ tool, runner: proposalRunnerOf(tool) }));
229
+ }
230
+ /**
231
+ * @internal Refuse a configuration in which a proposal tool would be asked
232
+ * for a harness approval, could not be served, or is shadowed. Runs wherever
233
+ * a session or prompt resolves its tools, on the same classification dispatch
234
+ * will use.
235
+ */
236
+ export function assertProposalToolConfiguration(input) {
237
+ input.tools.forEach(({ tool, runner }, index) => {
238
+ if (!runner)
239
+ return;
240
+ const fail = (reason) => {
241
+ throw proposalConfigurationError(tool.name, reason);
242
+ };
243
+ if (!input.authority) {
244
+ fail("needs a proposalAuthority on the agent or session: there is no external approval authority to submit to.");
245
+ }
246
+ if (tool.policyAlias !== undefined) {
247
+ fail("must not set policyAlias: policy must judge it by its own name.");
248
+ }
249
+ if (HARNESS_RESULT_TOOL_NAMES.includes(tool.name)) {
250
+ fail(`has the name of a tool the harness adds for result validation (${HARNESS_RESULT_TOOL_NAMES.join(", ")}), which would replace it.`);
251
+ }
252
+ // Every registration counts, including the same object registered twice.
253
+ const sameName = input.tools.filter((other, at) => at !== index && other.tool.name === tool.name);
254
+ if (sameName.length > 0) {
255
+ fail("shares its name with another tool; one of them would silently replace the other.");
256
+ }
257
+ const decision = evaluateToolCallPolicy({ tool: tool.name, input: {} }, approvalRulesOnly(input.policy));
258
+ if (decision.approvalRequired)
259
+ fail(proposalApprovalRuleReason(decision.matchedPattern));
260
+ });
261
+ }
262
+ /**
263
+ * The policy with its tool deny rules and allowlist removed, so the policy
264
+ * module's own matcher reports an approval rule even where a deny rule would
265
+ * otherwise answer first.
266
+ */
267
+ function approvalRulesOnly(policy) {
268
+ if (!policy?.toolPolicy)
269
+ return policy;
270
+ const { deny: _deny, allow: _allow, ...approvalOnly } = policy.toolPolicy;
271
+ return { ...policy, toolPolicy: approvalOnly };
272
+ }
273
+ /** @internal A per-call tracker the session builds the binding from. */
274
+ export function createProposalCallTracker(input) {
275
+ let submittedKey;
276
+ let outcome;
277
+ const binding = {
278
+ sessionId: input.sessionId,
279
+ ...(input.tenantId !== undefined ? { tenantId: input.tenantId } : {}),
280
+ ...(input.actor !== undefined ? { actor: input.actor } : {}),
281
+ authority: input.authority,
282
+ submitting(idempotencyKey) {
283
+ submittedKey = idempotencyKey;
284
+ },
285
+ settled(record) {
286
+ outcome = { actionId: record.actionId, result: { ...record.result } };
287
+ },
288
+ };
289
+ return { binding, submittedKey: () => submittedKey, outcome: () => outcome };
290
+ }
291
+ /**
292
+ * @internal The result of a call whose submission cannot be confirmed either
293
+ * way. `idempotencyKey` is absent when the call is settled after a crash.
294
+ */
295
+ export function unknownResult(idempotencyKey) {
296
+ return {
297
+ route: "unknown",
298
+ executed: false,
299
+ ...(idempotencyKey !== undefined ? { idempotencyKey } : {}),
300
+ message: "The harness cannot tell whether this proposal was submitted. Do not submit it again; ask a person to check it with the approval authority.",
301
+ };
302
+ }
303
+ /** @internal The harness-set transcript record for a proposal call's result. */
304
+ export function proposalTranscriptRecord(outcome) {
305
+ return {
306
+ actionId: outcome.actionId,
307
+ route: outcome.result.route,
308
+ executed: outcome.result.executed,
309
+ ...(outcome.result.idempotencyKey !== undefined
310
+ ? { idempotencyKey: outcome.result.idempotencyKey }
311
+ : {}),
312
+ ...(outcome.result.proposalRef !== undefined
313
+ ? { proposalRef: outcome.result.proposalRef }
314
+ : {}),
315
+ };
316
+ }
317
+ function answerShape(response) {
318
+ const value = typeof response === "object" && response !== null ? response : {};
319
+ const id = value.actionInvocationId;
320
+ const status = value.status;
321
+ return {
322
+ actionInvocationId: typeof id === "string" ? id : null,
323
+ status: typeof status === "string" ? status : null,
324
+ };
325
+ }
326
+ /**
327
+ * Map the authority's answer to a route by exact match against the
328
+ * agent-registry routing vocabulary (`ActionRoute`, decisions.ts). A reference
329
+ * that is empty or whitespace-only counts as missing. `rejected` carries no
330
+ * invocation id in `ActionRoute`, so it is valid without one.
331
+ */
332
+ function proposalResultFromAnswer(answer, idempotencyKey) {
333
+ const ref = typeof answer.actionInvocationId === "string" && answer.actionInvocationId.trim() !== ""
334
+ ? answer.actionInvocationId
335
+ : undefined;
336
+ switch (answer.status) {
337
+ case "auto-executed":
338
+ if (!ref)
339
+ return unknownResult(idempotencyKey);
340
+ return {
341
+ proposalRef: ref,
342
+ route: "auto-executed",
343
+ executed: true,
344
+ idempotencyKey,
345
+ message: "The approval authority accepted and executed the proposal.",
346
+ };
347
+ case "awaiting-approval":
348
+ if (!ref)
349
+ return unknownResult(idempotencyKey);
350
+ return {
351
+ proposalRef: ref,
352
+ route: "awaiting-approval",
353
+ executed: false,
354
+ idempotencyKey,
355
+ message: "The proposal was submitted and awaits a decision by the approval authority. It has not been executed. Do not submit it again; the decision happens outside this conversation.",
356
+ };
357
+ case "escalated":
358
+ if (!ref)
359
+ return unknownResult(idempotencyKey);
360
+ return {
361
+ proposalRef: ref,
362
+ route: "awaiting-approval",
363
+ executed: false,
364
+ idempotencyKey,
365
+ message: "The approval authority escalated the proposal for review. It has not been executed. Do not submit it again; the decision happens outside this conversation.",
366
+ };
367
+ case "rejected":
368
+ return {
369
+ ...(ref ? { proposalRef: ref } : {}),
370
+ route: "rejected",
371
+ executed: false,
372
+ idempotencyKey,
373
+ message: "The approval authority rejected the proposal. It was not executed.",
374
+ };
375
+ default:
376
+ return unknownResult(idempotencyKey);
377
+ }
378
+ }
379
+ /** Settle with `pending`, or reject as soon as `signal` aborts. */
380
+ function boundBy(pending, signal) {
381
+ return new Promise((resolve, reject) => {
382
+ const onAbort = () => reject(new Error("Proposal call was cancelled or timed out."));
383
+ // Handlers go on first, so work abandoned below never surfaces as an
384
+ // unhandled rejection.
385
+ pending.then((value) => {
386
+ signal.removeEventListener("abort", onAbort);
387
+ resolve(value);
388
+ }, (error) => {
389
+ signal.removeEventListener("abort", onAbort);
390
+ reject(error);
391
+ });
392
+ if (signal.aborted) {
393
+ onAbort();
394
+ return;
395
+ }
396
+ signal.addEventListener("abort", onAbort, { once: true });
397
+ });
398
+ }
399
+ function assertProposalParams(params, name) {
400
+ if (!isPlainObject(params)) {
401
+ throw new Error(`Proposal tool "${name}" params must be a plain object; nothing was submitted.`);
402
+ }
403
+ for (const key of Object.keys(params)) {
404
+ if (RESERVED_LOWER.has(key.toLowerCase())) {
405
+ throw new Error(`Proposal tool "${name}" params must not set "${key}": the harness owns it; nothing was submitted.`);
406
+ }
407
+ }
408
+ }
409
+ /**
410
+ * A fresh plain-JSON copy of `value`. It throws for undefined, functions,
411
+ * symbols (as values or keys), bigints, non-finite numbers, -0, holes in
412
+ * arrays, cycles, and objects whose prototype is not `Object.prototype` or
413
+ * null (a `Date` or `Map` included). Some shapes are normalized rather than
414
+ * refused: an array, including an array subclass, is copied as a plain array
415
+ * of its indexed elements (other properties are dropped), and an object keeps
416
+ * only its own enumerable string keys, as a plain object.
417
+ */
418
+ function jsonSnapshot(value, label) {
419
+ const seen = new Set();
420
+ const fail = (path, what) => {
421
+ throw new Error(`${label} must be plain JSON: ${path} is ${what}; nothing was submitted.`);
422
+ };
423
+ const copy = (current, path) => {
424
+ if (current === null || typeof current === "string" || typeof current === "boolean")
425
+ return current;
426
+ if (typeof current === "number") {
427
+ if (!Number.isFinite(current))
428
+ fail(path, "not a finite number");
429
+ if (Object.is(current, -0))
430
+ fail(path, "-0");
431
+ return current;
432
+ }
433
+ if (typeof current !== "object")
434
+ return fail(path, typeof current);
435
+ if (seen.has(current))
436
+ fail(path, "a cycle");
437
+ seen.add(current);
438
+ try {
439
+ if (Array.isArray(current)) {
440
+ const out = [];
441
+ for (let index = 0; index < current.length; index += 1) {
442
+ if (!(index in current))
443
+ fail(`${path}[${index}]`, "a hole");
444
+ out.push(copy(current[index], `${path}[${index}]`));
445
+ }
446
+ return out;
447
+ }
448
+ if (!isPlainObject(current))
449
+ return fail(path, "not a plain object");
450
+ if (Object.getOwnPropertySymbols(current).length > 0)
451
+ fail(path, "keyed by a symbol");
452
+ const out = {};
453
+ for (const key of Object.keys(current)) {
454
+ Object.defineProperty(out, key, {
455
+ value: copy(current[key], `${path}.${key}`),
456
+ enumerable: true,
457
+ writable: true,
458
+ configurable: true,
459
+ });
460
+ }
461
+ return out;
462
+ }
463
+ finally {
464
+ seen.delete(current);
465
+ }
466
+ };
467
+ return copy(value, "$");
468
+ }
469
+ /**
470
+ * Canonical JSON for proposal digests: object keys sorted by UTF-16 code
471
+ * unit, which is total and locale-independent. Input is a `jsonSnapshot`.
472
+ */
473
+ function proposalCanonicalJson(value) {
474
+ if (value === null || typeof value !== "object")
475
+ return JSON.stringify(value);
476
+ if (Array.isArray(value))
477
+ return `[${value.map(proposalCanonicalJson).join(",")}]`;
478
+ const record = value;
479
+ const keys = Object.keys(record).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
480
+ return `{${keys.map((key) => `${JSON.stringify(key)}:${proposalCanonicalJson(record[key])}`).join(",")}}`;
481
+ }
482
+ function sha256(text) {
483
+ return createHash("sha256").update(text, "utf8").digest("hex");
484
+ }
485
+ /** A refusal before submission whose fixed message is the call's error. */
486
+ class ProposalRefusal extends Error {
487
+ }
488
+ function assertPrincipalTenant(principal, tenantId, name) {
489
+ if (typeof principal !== "object" || principal === null) {
490
+ throw new ProposalRefusal(`Proposal tool "${name}" resolved no principal; nothing was submitted.`);
491
+ }
492
+ const principalTenant = principal.tenantId;
493
+ // Both must be absent, or both the same string.
494
+ if (principalTenant !== tenantId) {
495
+ throw new ProposalRefusal(`Proposal tool "${name}" resolved a principal whose tenant is not this session's; nothing was submitted.`);
496
+ }
497
+ }
498
+ function hasParser(schema) {
499
+ return (typeof schema === "object" &&
500
+ schema !== null &&
501
+ (typeof schema.parse === "function" ||
502
+ typeof schema.safeParse === "function"));
503
+ }
504
+ /**
505
+ * Validate the model's input. A validation failure keeps the schema's own
506
+ * message, as other SDK tools do. Anything else a schema throws (a refinement
507
+ * that throws, say) is host code failing: a fixed message, nothing from it.
508
+ */
509
+ function parseInput(schema, value, name, actionId) {
510
+ const path = `$tool.${name}.input`;
511
+ const parser = schema;
512
+ const schemaFailed = () => {
513
+ reportFailure("proposal input schema threw", name, actionId);
514
+ throw new Error(`Proposal tool "${name}" could not validate its input; nothing was submitted.`);
515
+ };
516
+ if (typeof parser.safeParse === "function") {
517
+ let parsed;
518
+ try {
519
+ parsed = parser.safeParse(value);
520
+ }
521
+ catch {
522
+ return schemaFailed();
523
+ }
524
+ if (parsed.success)
525
+ return parsed.data;
526
+ throw new Error(`[fabric-harness] ${path} failed schema validation: ${String(parsed.error ?? "invalid value")}`);
527
+ }
528
+ try {
529
+ return parser.parse(value, path);
530
+ }
531
+ catch (error) {
532
+ if (error instanceof SchemaValidationError)
533
+ throw error;
534
+ return schemaFailed();
535
+ }
536
+ }
537
+ function schemaToJson(schema) {
538
+ const candidate = schema;
539
+ return typeof candidate.toJSONSchema === "function" ? candidate.toJSONSchema() : undefined;
540
+ }
541
+ function isPlainObject(value) {
542
+ if (typeof value !== "object" || value === null || Array.isArray(value))
543
+ return false;
544
+ const prototype = Object.getPrototypeOf(value);
545
+ return prototype === Object.prototype || prototype === null;
546
+ }
547
+ /**
548
+ * Failure diagnostics: a fixed label per failure site and the tool and action
549
+ * names, to the SDK logger only (the tool progress channel writes transcript
550
+ * entries, which must not land between a call and its result). Nothing is
551
+ * taken from the caught error (not its message, name or code), and a logger
552
+ * that throws cannot change how the call settles.
553
+ */
554
+ function reportFailure(label, tool, actionId) {
555
+ try {
556
+ getLogger().warn(label, { tool, actionId });
557
+ }
558
+ catch {
559
+ // Diagnostics never decide the outcome.
560
+ }
561
+ }
562
+ //# sourceMappingURL=proposal-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proposal-tool.js","sourceRoot":"","sources":["../src/proposal-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAqJvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAsB,MAAM,CAAC,MAAM,CAA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