@fabric-harness/sdk 6.2.0 → 6.4.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 (160) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +9 -9
  3. package/connector-spec/channel.md +2 -2
  4. package/connector-spec/sandbox.md +1 -1
  5. package/connector-spec/tooling.md +1 -1
  6. package/connector-spec/voice-telephony.md +1 -1
  7. package/dist/action.d.ts +2 -2
  8. package/dist/action.js +1 -1
  9. package/dist/agent-route.d.ts +2 -0
  10. package/dist/agent-route.d.ts.map +1 -1
  11. package/dist/agent-route.js +1 -0
  12. package/dist/agent-route.js.map +1 -1
  13. package/dist/agent-router.d.ts +4 -0
  14. package/dist/agent-router.d.ts.map +1 -1
  15. package/dist/agent-router.js +14 -1
  16. package/dist/agent-router.js.map +1 -1
  17. package/dist/ai-gateway.d.ts +1 -1
  18. package/dist/ai-gateway.js +1 -1
  19. package/dist/attachment-store.d.ts +3 -3
  20. package/dist/attachment-store.js +2 -2
  21. package/dist/channel.d.ts +3 -3
  22. package/dist/channel.js +2 -2
  23. package/dist/conversation-projection.d.ts +2 -2
  24. package/dist/conversation-projection.js +2 -2
  25. package/dist/conversation-stream.d.ts +5 -5
  26. package/dist/conversation-stream.js +1 -1
  27. package/dist/cost-budget.d.ts +3 -3
  28. package/dist/cost-budget.js +1 -1
  29. package/dist/delivered-message.d.ts +3 -3
  30. package/dist/error.js +2 -2
  31. package/dist/error.js.map +1 -1
  32. package/dist/events.d.ts +4 -2
  33. package/dist/events.d.ts.map +1 -1
  34. package/dist/events.js +1 -1
  35. package/dist/events.js.map +1 -1
  36. package/dist/filesystem-source.d.ts +3 -3
  37. package/dist/filesystem-source.js +1 -1
  38. package/dist/governed-voice.d.ts +55 -0
  39. package/dist/governed-voice.d.ts.map +1 -0
  40. package/dist/governed-voice.js +357 -0
  41. package/dist/governed-voice.js.map +1 -0
  42. package/dist/history.d.ts +3 -3
  43. package/dist/history.js +3 -3
  44. package/dist/index.d.ts +3 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/langfuse.d.ts +2 -2
  49. package/dist/mcp.d.ts +1 -0
  50. package/dist/mcp.d.ts.map +1 -1
  51. package/dist/mcp.js +2 -0
  52. package/dist/mcp.js.map +1 -1
  53. package/dist/model-pricing.d.ts +7 -4
  54. package/dist/model-pricing.d.ts.map +1 -1
  55. package/dist/model-pricing.js +8 -7
  56. package/dist/model-pricing.js.map +1 -1
  57. package/dist/model.d.ts +3 -1
  58. package/dist/model.d.ts.map +1 -1
  59. package/dist/model.js +3 -1
  60. package/dist/model.js.map +1 -1
  61. package/dist/otel-observer.d.ts +3 -1
  62. package/dist/otel-observer.d.ts.map +1 -1
  63. package/dist/otel-observer.js +40 -8
  64. package/dist/otel-observer.js.map +1 -1
  65. package/dist/persistent-agent.d.ts +6 -1
  66. package/dist/persistent-agent.d.ts.map +1 -1
  67. package/dist/persistent-agent.js +9 -1
  68. package/dist/persistent-agent.js.map +1 -1
  69. package/dist/policy.d.ts +1 -1
  70. package/dist/rate-limiter.d.ts +2 -2
  71. package/dist/rate-limiter.js +2 -2
  72. package/dist/retrieval.d.ts +1 -1
  73. package/dist/sandbox-ref.d.ts +2 -2
  74. package/dist/sandbox.js +1 -1
  75. package/dist/sandbox.js.map +1 -1
  76. package/dist/session-memory.d.ts +4 -3
  77. package/dist/session-memory.d.ts.map +1 -1
  78. package/dist/session-memory.js +4 -3
  79. package/dist/session-memory.js.map +1 -1
  80. package/dist/session.d.ts +3 -0
  81. package/dist/session.d.ts.map +1 -1
  82. package/dist/session.js +36 -5
  83. package/dist/session.js.map +1 -1
  84. package/dist/skill-definition.d.ts +1 -1
  85. package/dist/skill-definition.js +1 -1
  86. package/dist/store.d.ts +1 -1
  87. package/dist/store.js +1 -1
  88. package/dist/strict.d.ts +3 -0
  89. package/dist/strict.d.ts.map +1 -1
  90. package/dist/strict.js +2 -0
  91. package/dist/strict.js.map +1 -1
  92. package/dist/submission-runner.d.ts +1 -1
  93. package/dist/submission-runner.d.ts.map +1 -1
  94. package/dist/submission-runner.js +101 -12
  95. package/dist/submission-runner.js.map +1 -1
  96. package/dist/submission-state.d.ts +3 -3
  97. package/dist/submission-state.js +3 -3
  98. package/dist/submission-store-contract.d.ts.map +1 -1
  99. package/dist/submission-store-contract.js +15 -1
  100. package/dist/submission-store-contract.js.map +1 -1
  101. package/dist/submission-store.d.ts +16 -4
  102. package/dist/submission-store.d.ts.map +1 -1
  103. package/dist/submission-store.js +15 -6
  104. package/dist/submission-store.js.map +1 -1
  105. package/dist/tool-execution.d.ts +11 -0
  106. package/dist/tool-execution.d.ts.map +1 -0
  107. package/dist/tool-execution.js +36 -0
  108. package/dist/tool-execution.js.map +1 -0
  109. package/dist/tools.d.ts +6 -0
  110. package/dist/tools.d.ts.map +1 -1
  111. package/dist/tools.js +5 -0
  112. package/dist/tools.js.map +1 -1
  113. package/dist/trace-content.d.ts +21 -0
  114. package/dist/trace-content.d.ts.map +1 -0
  115. package/dist/trace-content.js +69 -0
  116. package/dist/trace-content.js.map +1 -0
  117. package/dist/types.d.ts +3 -3
  118. package/dist/vercel-ai-gateway.d.ts +4 -4
  119. package/dist/vercel-ai-gateway.js +4 -4
  120. package/dist/voice-openai-realtime.d.ts +2 -2
  121. package/dist/voice-openai-realtime.d.ts.map +1 -1
  122. package/dist/voice-openai-realtime.js +48 -41
  123. package/dist/voice-openai-realtime.js.map +1 -1
  124. package/dist/voice-pipeline.d.ts +3 -0
  125. package/dist/voice-pipeline.d.ts.map +1 -1
  126. package/dist/voice-pipeline.js +71 -23
  127. package/dist/voice-pipeline.js.map +1 -1
  128. package/dist/voice-stt-cartesia.d.ts +1 -0
  129. package/dist/voice-stt-cartesia.d.ts.map +1 -1
  130. package/dist/voice-stt-cartesia.js +8 -1
  131. package/dist/voice-stt-cartesia.js.map +1 -1
  132. package/dist/voice-stt-deepgram.d.ts +1 -0
  133. package/dist/voice-stt-deepgram.d.ts.map +1 -1
  134. package/dist/voice-stt-deepgram.js +8 -1
  135. package/dist/voice-stt-deepgram.js.map +1 -1
  136. package/dist/voice-stt.d.ts +2 -0
  137. package/dist/voice-stt.d.ts.map +1 -1
  138. package/dist/voice-tts-cartesia.d.ts +1 -0
  139. package/dist/voice-tts-cartesia.d.ts.map +1 -1
  140. package/dist/voice-tts-cartesia.js +2 -1
  141. package/dist/voice-tts-cartesia.js.map +1 -1
  142. package/dist/voice-tts-elevenlabs.d.ts +1 -0
  143. package/dist/voice-tts-elevenlabs.d.ts.map +1 -1
  144. package/dist/voice-tts-elevenlabs.js +4 -1
  145. package/dist/voice-tts-elevenlabs.js.map +1 -1
  146. package/dist/voice-tts.d.ts +2 -0
  147. package/dist/voice-tts.d.ts.map +1 -1
  148. package/dist/voice-ws-client.d.ts +6 -4
  149. package/dist/voice-ws-client.d.ts.map +1 -1
  150. package/dist/voice-ws-client.js +11 -6
  151. package/dist/voice-ws-client.js.map +1 -1
  152. package/dist/voice-ws-shared.d.ts +10 -3
  153. package/dist/voice-ws-shared.d.ts.map +1 -1
  154. package/dist/voice-ws-shared.js +45 -9
  155. package/dist/voice-ws-shared.js.map +1 -1
  156. package/dist/voice.d.ts +6 -7
  157. package/dist/voice.d.ts.map +1 -1
  158. package/dist/webhook-subscription.d.ts +1 -1
  159. package/dist/ws-client.d.ts +1 -1
  160. package/package.json +16 -10
package/dist/events.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Typed event payloads for `init({ onEvent })` and `session.stream()`.
3
3
  *
4
- * Fabric Harness already emits a structured event stream via the
4
+ * TechFabric Harness already emits a structured event stream via the
5
5
  * untyped `FabricEvent` interface (see `types.ts`). This module layers
6
6
  * a discriminated union on top so consumers can write `if (event.type
7
7
  * === 'tool_start')` and have TypeScript narrow `event.data` for them.
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAqJH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CACrB,KAAiB,EACjB,IAAO;IAEP,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAuJH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CACrB,KAAiB,EACjB,IAAO;IAEP,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC7B,CAAC"}
@@ -3,12 +3,12 @@ import type { SandboxBackend } from './types.js';
3
3
  /**
4
4
  * A read-only content source that can be mounted into a sandbox at
5
5
  * sandbox-creation time. The agent then has built-in `read`, `glob`,
6
- * and `grep` tools available over the mounted content — no retrieval
6
+ * and `grep` tools available over the mounted content, no retrieval
7
7
  * pipeline, no embeddings, no vector store required.
8
8
  *
9
9
  * Sources are intentionally minimal: they yield (path, content) pairs.
10
10
  * Implementations decide how to enumerate (eager vs lazy is up to the
11
- * source author) — the mount step pulls the full set into the sandbox.
11
+ * source author). The mount step pulls the full set into the sandbox.
12
12
  */
13
13
  export interface FilesystemSource {
14
14
  /** Stable name for telemetry / logs. */
@@ -73,7 +73,7 @@ export declare function inMemorySource(files: Record<string, string | Uint8Array
73
73
  * withFilesystemSources('virtual', [{ mountAt, source }])
74
74
  * ```
75
75
  *
76
- * Used for support agents, runbook lookup, FAQ assistants — anywhere a
76
+ * Use it for support agents, runbook lookup, and FAQ assistants: anywhere a
77
77
  * small Markdown corpus needs to be searchable via the agent's built-in
78
78
  * `grep`/`glob`/`read` tools.
79
79
  *
@@ -84,7 +84,7 @@ export function inMemorySource(files, options = {}) {
84
84
  * withFilesystemSources('virtual', [{ mountAt, source }])
85
85
  * ```
86
86
  *
87
- * Used for support agents, runbook lookup, FAQ assistants — anywhere a
87
+ * Use it for support agents, runbook lookup, and FAQ assistants: anywhere a
88
88
  * small Markdown corpus needs to be searchable via the agent's built-in
89
89
  * `grep`/`glob`/`read` tools.
90
90
  *
@@ -0,0 +1,55 @@
1
+ import type { CostLimit } from './cost-budget.js';
2
+ import type { ToolCall, ToolCallResult, ToolDef } from './tools.js';
3
+ import type { JsonObject, SessionStore } from './types.js';
4
+ import type { VoiceConnectOptions, VoiceProvider, VoiceSession } from './voice.js';
5
+ export interface GovernedVoiceOptions {
6
+ provider: VoiceProvider;
7
+ /** Trusted application binding, resolved from authenticated server state. */
8
+ callId: string;
9
+ resourceId: string;
10
+ instructions: string;
11
+ tools: ToolDef[];
12
+ voice?: string;
13
+ audioFormat?: VoiceConnectOptions['audioFormat'];
14
+ sampleRate?: number;
15
+ signal?: AbortSignal;
16
+ limits: {
17
+ durationMs: number;
18
+ maxTurns: number;
19
+ maxToolCalls: number;
20
+ maxAudioFrameBytes?: number;
21
+ };
22
+ /** Estimated spend, checked after each response. One in-flight response can overshoot. */
23
+ costLimit: Pick<CostLimit, 'perCall' | 'perScope' | 'scopeKey'> & {
24
+ perSession: number;
25
+ };
26
+ /** Checked on admission and immediately before every tool execution/replay. */
27
+ authorize: (operation: {
28
+ kind: 'connect' | 'input' | 'tool';
29
+ tool?: string;
30
+ }) => boolean | Promise<boolean>;
31
+ /** Validate and remove sensitive values before policy/history/model exposure. Throw to reject. */
32
+ prepareToolInput: (name: string, input: unknown) => unknown | Promise<unknown>;
33
+ /** Trusted logical action identity, stable across provider reconnects. Never use a provider call ID. */
34
+ toolOperationKey: (name: string, preparedInput: unknown) => string | Promise<string>;
35
+ /** Return only model-safe output; the safe value is also what the journal retains. */
36
+ prepareToolOutput: (name: string, output: unknown) => unknown | Promise<unknown>;
37
+ /** Redact before transcript/text is exposed. Raw audio is never persisted by Harness. */
38
+ redactTranscript: (text: string) => string | Promise<string>;
39
+ /** Awaited audit delivery; failures stop the session. Contains metadata, never audio/text/arguments. */
40
+ onAudit?: (event: JsonObject) => void | Promise<void>;
41
+ }
42
+ /** Only sessions opened through session.voice() carry this server-route marker. */
43
+ export interface GovernedVoiceSession extends VoiceSession {
44
+ readonly governed: true;
45
+ }
46
+ export interface GovernedVoiceRuntime {
47
+ sessionId: string;
48
+ tenantId: string;
49
+ actorId: string;
50
+ store: SessionStore;
51
+ execute: (call: ToolCall, tools: ToolDef[], signal: AbortSignal) => Promise<ToolCallResult>;
52
+ }
53
+ /** Internal session adapter. Public callers use session.voice(). */
54
+ export declare function openGovernedVoice(options: GovernedVoiceOptions, runtime: GovernedVoiceRuntime): Promise<GovernedVoiceSession>;
55
+ //# sourceMappingURL=governed-voice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governed-voice.d.ts","sourceRoot":"","sources":["../src/governed-voice.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAc,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/F,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,aAAa,CAAC;IACxB,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QA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jB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7F;AAED,oEAAoE;AACpE,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAoPnI"}
@@ -0,0 +1,357 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { abandonToolOnAbort } from './abort.js';
3
+ /** Internal session adapter. Public callers use session.voice(). */
4
+ export async function openGovernedVoice(options, runtime) {
5
+ for (const value of [options.limits.durationMs, options.limits.maxTurns, options.limits.maxToolCalls]) {
6
+ if (!Number.isSafeInteger(value) || value <= 0)
7
+ throw new Error('Voice limits must be positive safe integers');
8
+ }
9
+ if (options.limits.durationMs > 2_147_483_647)
10
+ throw new Error('Voice duration exceeds timer range');
11
+ if (options.limits.maxAudioFrameBytes !== undefined && (!Number.isSafeInteger(options.limits.maxAudioFrameBytes) || options.limits.maxAudioFrameBytes <= 0))
12
+ throw new Error('Invalid voice frame limit');
13
+ for (const limit of [options.costLimit.perSession, options.costLimit.perCall, options.costLimit.perScope]) {
14
+ if (limit !== undefined && (!Number.isFinite(limit) || limit <= 0))
15
+ throw new Error('Voice cost limits must be finite positive numbers');
16
+ }
17
+ if (options.costLimit.perSession === undefined)
18
+ throw new Error('Voice requires a session cost limit');
19
+ if (options.costLimit.perScope !== undefined && !options.costLimit.scopeKey)
20
+ throw new Error('Voice scope limit requires a scope key');
21
+ if (!options.instructions.trim() || !options.callId || !options.resourceId || !runtime.tenantId || !runtime.actorId) {
22
+ throw new Error('Governed voice requires instructions and a trusted tenant, actor, resource and call binding');
23
+ }
24
+ if (!runtime.store.appendEntries)
25
+ throw new Error('Governed voice requires an atomic session store');
26
+ const appendEntries = runtime.store.appendEntries.bind(runtime.store);
27
+ const tools = new Map(options.tools.map(tool => [tool.name, tool]));
28
+ if (tools.size !== options.tools.length)
29
+ throw new Error('Duplicate voice tool name');
30
+ if (options.tools.some(tool => tool.durable))
31
+ throw new Error('Voice tools must use application action idempotency, not unredacted durable substeps');
32
+ const binding = JSON.stringify([runtime.tenantId, runtime.actorId, runtime.sessionId, options.resourceId, options.callId]);
33
+ const journalId = `voice:${hash(binding)}`;
34
+ const owner = randomUUID();
35
+ const abort = new AbortController();
36
+ const signal = options.signal ? AbortSignal.any([options.signal, abort.signal]) : abort.signal;
37
+ let voice;
38
+ let closed = false;
39
+ let turns = 0;
40
+ let calls = 0;
41
+ let consumed = false;
42
+ let inputPending = false;
43
+ let inputAdmission;
44
+ let timer;
45
+ const bounded = (work) => abandonToolOnAbort(work, signal);
46
+ const close = async () => {
47
+ if (closed)
48
+ return;
49
+ closed = true;
50
+ clearTimeout(timer);
51
+ abort.abort();
52
+ const current = voice;
53
+ if (current)
54
+ await abandonToolOnAbort(() => current.close(), AbortSignal.timeout(2000)).catch(() => { });
55
+ };
56
+ timer = setTimeout(() => { void close(); }, options.limits.durationMs);
57
+ signal.addEventListener('abort', () => { void close(); }, { once: true });
58
+ const load = () => bounded(() => runtime.store.load(journalId));
59
+ const assertOwner = async () => {
60
+ signal.throwIfAborted();
61
+ const data = await load();
62
+ const current = data?.entries?.filter(entry => entry.data?.kind === 'owner').at(-1);
63
+ if (current?.data?.owner !== owner)
64
+ throw new Error('Voice connection ownership changed');
65
+ };
66
+ const append = async (data, id = randomUUID(), claim = false) => {
67
+ for (let attempt = 0; attempt < 8; attempt++) {
68
+ const current = await load();
69
+ signal.throwIfAborted();
70
+ if (!claim && current?.entries?.filter(entry => entry.data?.kind === 'owner').at(-1)?.data?.owner !== owner)
71
+ throw new Error('Voice connection ownership changed');
72
+ const timestamp = new Date().toISOString();
73
+ if (await bounded(() => appendEntries(journalId, [{
74
+ id, type: 'activity_result', timestamp,
75
+ ...(current?.leafId ? { parentId: current.leafId } : {}),
76
+ tenantId: runtime.tenantId,
77
+ data: { ...data, sessionId: runtime.sessionId, resourceId: options.resourceId, callId: options.callId, owner },
78
+ }], { expectedLeafId: current?.leafId })))
79
+ return;
80
+ }
81
+ throw new Error('Voice journal contention');
82
+ };
83
+ const audit = async (kind, details = {}) => {
84
+ const event = { kind, tenantId: runtime.tenantId, actorId: runtime.actorId, ...details };
85
+ await append(event);
86
+ await bounded(async () => options.onAudit?.({ ...event, sessionId: runtime.sessionId, resourceId: options.resourceId, callId: options.callId }));
87
+ };
88
+ // Idempotent, durable ledgers share the session store. Replaying journal usage
89
+ // repairs a crash between the journal commit and either ledger commit.
90
+ const ledgers = [
91
+ { key: ['session', runtime.sessionId], limit: options.costLimit.perSession },
92
+ ...(options.costLimit.perScope === undefined ? [] : [{ key: ['scope', options.costLimit.scopeKey ?? ''], limit: options.costLimit.perScope }]),
93
+ ];
94
+ const account = async (observation) => {
95
+ let exceeded = false;
96
+ for (const ledger of ledgers) {
97
+ const id = `voice-cost:${hash(JSON.stringify([runtime.tenantId, ...ledger.key]))}`;
98
+ let committed = false;
99
+ for (let attempt = 0; attempt < 8; attempt++) {
100
+ signal.throwIfAborted();
101
+ const data = await bounded(() => runtime.store.load(id));
102
+ const entries = data?.entries ?? [];
103
+ const total = entries.reduce((sum, entry) => sum + (typeof entry.data?.costUsd === 'number' ? entry.data.costUsd : 0), 0);
104
+ const exists = !observation || entries.some(entry => entry.id === observation.id);
105
+ exceeded ||= total + (exists ? 0 : observation?.costUsd ?? 0) >= ledger.limit;
106
+ if (exists || !observation) {
107
+ committed = true;
108
+ break;
109
+ }
110
+ if (await bounded(() => appendEntries(id, [{ id: observation.id, type: 'activity_result', timestamp: new Date().toISOString(),
111
+ ...(data?.leafId ? { parentId: data.leafId } : {}), tenantId: runtime.tenantId,
112
+ data: { kind: 'voice_cost', costUsd: observation.costUsd },
113
+ }], { expectedLeafId: data?.leafId }))) {
114
+ committed = true;
115
+ break;
116
+ }
117
+ }
118
+ if (!committed)
119
+ throw new Error('Voice cost ledger unavailable');
120
+ }
121
+ return exceeded || (observation !== undefined && options.costLimit.perCall !== undefined && observation.costUsd >= options.costLimit.perCall);
122
+ };
123
+ try {
124
+ if (!(await bounded(async () => options.authorize({ kind: 'connect' }))))
125
+ throw new Error('Voice admission denied');
126
+ await append({ kind: 'owner' }, owner, true);
127
+ const prior = await load();
128
+ if (prior?.entries?.filter(entry => entry.data?.kind === 'input_open' || entry.data?.kind === 'usage').at(-1)?.data?.kind === 'input_open')
129
+ throw new Error('Interrupted voice usage requires application reconciliation');
130
+ const first = prior?.entries?.find(entry => entry.data?.kind === 'owner');
131
+ if (!first || !Number.isFinite(Date.parse(first.timestamp)))
132
+ throw new Error('Voice journal timestamp invalid');
133
+ const remaining = options.limits.durationMs - (Date.now() - Date.parse(first.timestamp));
134
+ if (remaining <= 0)
135
+ throw new Error('Voice duration limit reached');
136
+ clearTimeout(timer);
137
+ timer = setTimeout(() => { void close(); }, remaining);
138
+ turns = prior?.entries?.filter(entry => entry.data?.kind === 'usage').length ?? 0;
139
+ calls = prior?.entries?.filter(entry => entry.data?.kind === 'tool_started').length ?? 0;
140
+ let exceeded = false;
141
+ for (const entry of prior?.entries ?? []) {
142
+ if (entry.data?.kind === 'usage' && typeof entry.data.costUsd === 'number')
143
+ exceeded = (await account({ id: entry.id, costUsd: entry.data.costUsd })) || exceeded;
144
+ }
145
+ if (exceeded || await account() || turns >= options.limits.maxTurns || prior?.entries?.some(entry => entry.data?.kind === 'cost_unknown'))
146
+ throw new Error('Voice budget exhausted or requires reconciliation');
147
+ await audit('connected');
148
+ voice = await bounded(() => options.provider.connect({
149
+ instructions: options.instructions, tools: options.tools,
150
+ ...(options.voice ? { voice: options.voice } : {}),
151
+ ...(options.audioFormat ? { audioFormat: options.audioFormat } : {}),
152
+ ...(options.sampleRate ? { sampleRate: options.sampleRate } : {}),
153
+ signal,
154
+ }).then(async (connected) => { if (signal.aborted) {
155
+ await connected.close();
156
+ throw new Error('Voice connection aborted');
157
+ } return connected; }));
158
+ signal.throwIfAborted();
159
+ }
160
+ catch (error) {
161
+ await close();
162
+ throw error;
163
+ }
164
+ if (!voice)
165
+ throw new Error('Voice connection did not open');
166
+ const upstream = voice;
167
+ const check = async (kind, tool) => {
168
+ await assertOwner();
169
+ if (!(await bounded(async () => options.authorize({ kind, ...(tool ? { tool } : {}) }))))
170
+ throw new Error('Voice operation denied');
171
+ if (turns >= options.limits.maxTurns)
172
+ throw new Error('Voice turn limit reached');
173
+ if (await account())
174
+ throw new Error('Voice cost limit reached');
175
+ };
176
+ // Media frames arrive about every 20ms. Coalesce durable checks and bound the
177
+ // revocation/ownership cache to one second; tool execution is never cached.
178
+ let mediaValidUntil = 0;
179
+ let mediaCheck;
180
+ const checkMedia = async () => {
181
+ signal.throwIfAborted();
182
+ if (Date.now() < mediaValidUntil)
183
+ return;
184
+ if (!mediaCheck)
185
+ mediaCheck = check('input').then(() => { mediaValidUntil = Date.now() + 1000; }).finally(() => { mediaCheck = undefined; });
186
+ await mediaCheck;
187
+ };
188
+ const markInput = async () => {
189
+ if (inputPending)
190
+ return inputAdmission;
191
+ inputPending = true;
192
+ inputAdmission = audit('input_open');
193
+ try {
194
+ await inputAdmission;
195
+ }
196
+ catch (error) {
197
+ inputPending = false;
198
+ throw error;
199
+ }
200
+ };
201
+ return {
202
+ governed: true,
203
+ async sendAudio(frame) {
204
+ try {
205
+ if (frame.byteLength > (options.limits.maxAudioFrameBytes ?? 64 * 1024))
206
+ throw new Error('Voice frame too large');
207
+ await checkMedia();
208
+ await markInput();
209
+ await bounded(() => upstream.sendAudio(frame));
210
+ }
211
+ catch (error) {
212
+ await close();
213
+ throw error;
214
+ }
215
+ },
216
+ async sendText(text) { try {
217
+ await check('input');
218
+ if (text.length > 16_384)
219
+ throw new Error('Voice text too large');
220
+ await markInput();
221
+ await bounded(() => upstream.sendText(text));
222
+ }
223
+ catch (error) {
224
+ await close();
225
+ throw error;
226
+ } },
227
+ async submitToolResult() { throw new Error('Governed voice tool results are server-owned'); },
228
+ async cancelResponse() { try {
229
+ await check('input');
230
+ await bounded(() => upstream.cancelResponse());
231
+ }
232
+ catch (error) {
233
+ await close();
234
+ throw error;
235
+ } },
236
+ close,
237
+ events() {
238
+ if (consumed)
239
+ throw new Error('Voice events can only be consumed once');
240
+ consumed = true;
241
+ return {
242
+ async *[Symbol.asyncIterator]() {
243
+ try {
244
+ const iterator = upstream.events()[Symbol.asyncIterator]();
245
+ while (true) {
246
+ const next = await bounded(() => iterator.next());
247
+ if (next.done)
248
+ break;
249
+ const event = next.value;
250
+ if (event.type === 'text_delta') {
251
+ signal.throwIfAborted();
252
+ continue;
253
+ }
254
+ if (event.type === 'audio_delta')
255
+ await checkMedia();
256
+ else
257
+ await assertOwner();
258
+ if (event.type === 'tool_call') {
259
+ await check('tool', event.name);
260
+ const tool = tools.get(event.name);
261
+ if (!tool?.execute)
262
+ throw new Error('Voice tool is not granted');
263
+ const prepared = await bounded(async () => options.prepareToolInput(event.name, event.input));
264
+ const inputJson = JSON.stringify(prepared ?? null);
265
+ if (inputJson.length > 65_536)
266
+ throw new Error('Voice tool input too large');
267
+ const input = JSON.parse(inputJson);
268
+ const digest = hash(JSON.stringify([event.name, input]));
269
+ const operationKey = await bounded(async () => options.toolOperationKey(event.name, input));
270
+ if (typeof operationKey !== 'string' || !operationKey.trim() || operationKey.length > 512)
271
+ throw new Error('Invalid voice operation key');
272
+ const id = hash(JSON.stringify([journalId, event.name, operationKey]));
273
+ const entries = (await load())?.entries ?? [];
274
+ const started = entries.find(entry => entry.data?.operationId === id && entry.data?.kind === 'tool_started');
275
+ const completed = entries.find(entry => entry.data?.operationId === id && entry.data?.kind === 'tool_completed');
276
+ if (started && started.data?.digest !== digest)
277
+ throw new Error('Conflicting voice tool replay');
278
+ if (completed) {
279
+ await bounded(() => upstream.submitToolResult({ id: event.id, output: completed.data?.output }));
280
+ continue;
281
+ }
282
+ if (started)
283
+ throw new Error('Voice tool outcome requires application reconciliation');
284
+ if (++calls > options.limits.maxToolCalls)
285
+ throw new Error('Voice tool limit reached');
286
+ await audit('tool_started', { operationId: id, tool: event.name, digest });
287
+ let effectStarted = false;
288
+ const safeTool = { ...tool, execute: async (args, context) => {
289
+ await check('tool', event.name);
290
+ effectStarted = true;
291
+ let output;
292
+ // Tool progress can contain raw outputs. Voice exports metadata-only audit instead.
293
+ try {
294
+ output = await tool.execute?.(args, context ? { ...context, log: { info() { }, warn() { }, error() { } } } : undefined);
295
+ }
296
+ catch {
297
+ throw new Error('Voice tool failed');
298
+ }
299
+ await assertOwner();
300
+ return output;
301
+ } };
302
+ const result = await bounded(() => runtime.execute({ tool: event.name, input, id }, [safeTool], signal));
303
+ await assertOwner();
304
+ if (result.error && effectStarted) {
305
+ await audit('tool_uncertain', { operationId: id, tool: event.name });
306
+ throw new Error('Voice tool outcome requires application reconciliation');
307
+ }
308
+ const output = result.error ? { error: 'Voice tool rejected or failed' } : result.output ?? null;
309
+ await append({ kind: 'tool_completed', operationId: id, tool: event.name, output: output });
310
+ await bounded(async () => options.onAudit?.({ kind: 'tool_completed', operationId: id, sessionId: runtime.sessionId, tenantId: runtime.tenantId, actorId: runtime.actorId, resourceId: options.resourceId, callId: options.callId }));
311
+ await bounded(() => upstream.submitToolResult({ id: event.id, output }));
312
+ if (result.terminate)
313
+ break;
314
+ continue;
315
+ }
316
+ if (event.type === 'response_done') {
317
+ turns++;
318
+ const cost = event.usage?.costUsd;
319
+ if (cost === undefined || !Number.isFinite(cost) || cost < 0) {
320
+ await audit('cost_unknown');
321
+ throw new Error('Voice cost is unknown');
322
+ }
323
+ const observation = { id: randomUUID(), costUsd: cost };
324
+ await append({ kind: 'usage', costUsd: cost, turn: turns }, observation.id);
325
+ inputPending = false;
326
+ inputAdmission = undefined;
327
+ const exceeded = await account(observation);
328
+ await bounded(async () => options.onAudit?.({ kind: 'usage', costUsd: cost, turn: turns, sessionId: runtime.sessionId, tenantId: runtime.tenantId, actorId: runtime.actorId, resourceId: options.resourceId, callId: options.callId }));
329
+ if (exceeded)
330
+ throw new Error('Voice cost limit reached');
331
+ if (turns >= options.limits.maxTurns) {
332
+ yield event;
333
+ break;
334
+ }
335
+ }
336
+ if (event.type === 'error')
337
+ throw new Error('Voice provider failed');
338
+ if (event.type === 'transcript')
339
+ yield { ...event, text: await bounded(async () => options.redactTranscript(event.text)) };
340
+ else
341
+ yield event;
342
+ // Partial text can split sensitive values across chunks. Only redacted final transcripts are exposed.
343
+ }
344
+ }
345
+ catch {
346
+ yield { type: 'error', message: 'Governed voice stopped; consult server audit and reconcile pending actions' };
347
+ }
348
+ finally {
349
+ await close();
350
+ }
351
+ },
352
+ };
353
+ },
354
+ };
355
+ }
356
+ function hash(value) { return createHash('sha256').update(value).digest('hex'); }
357
+ //# sourceMappingURL=governed-voice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governed-voice.js","sourceRoot":"","sources":["../src/governed-voice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA4ChD,oEAAoE;AACpE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAA6B,EAAE,OAA6B;IAClG,KAAK,MAAM,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACtG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjH,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,aAAa;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACrG,IAAI,OAAO,CAAC,MAAM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C,uBAAuB,CAAC,CAAC;4BACrE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;gCAAE,MAAM,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;;gCACtH,MAAM,KAAK,CAAC;4BACjB,sGAAsG;wBACxG,CAAC;oBACH,CAAC;oBAAC,MAAM,CAAC;wBACP,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,4EAA4E,EAAuB,CAAC;oBACtI,CAAC;4BAAS,CAAC;wBAAC,MAAM,KAAK,EAAE,CAAC;oBAAC,CAAC;gBAC9B,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,IAAI,CAAC,KAAa,IAAY,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
package/dist/history.d.ts CHANGED
@@ -53,13 +53,13 @@ export declare class SessionHistory {
53
53
  export declare function buildModelMessagesFromHistory(data: SessionData | undefined, role?: Role): ModelMessage[];
54
54
  /**
55
55
  * Find trailing `tool_call` entries on the active path that were never
56
- * settled — no matching `tool_result` (paired by `toolCallId`, falling back
56
+ * settled: no matching `tool_result` (paired by `toolCallId`, falling back
57
57
  * to tool name) and no subsequent `error` entry for the same tool.
58
58
  *
59
59
  * A dangling call means a model turn died (crash/abort) between recording
60
60
  * the call and recording its outcome. Left in place it produces an
61
61
  * assistant `tool_use` with no `tool_result` on resume, which providers
62
- * reject — the repair path appends synthetic interrupted outcomes for
62
+ * reject; the repair path appends synthetic interrupted outcomes for
63
63
  * exactly the entries returned here.
64
64
  *
65
65
  * Conservative by construction: only the window after the last turn
@@ -71,7 +71,7 @@ export declare function buildModelMessagesFromHistory(data: SessionData | undefi
71
71
  export declare function findTrailingDanglingToolCalls(path: SessionEntry[]): SessionEntry[];
72
72
  /**
73
73
  * Trailing `task_start` entries in the same window with no matching
74
- * `task_end` — a subtask that was in flight when the turn died. These do not
74
+ * `task_end`. A subtask that was in flight when the turn died. These do not
75
75
  * corrupt model context (task entries are bookkeeping), but settling them
76
76
  * keeps UI/audit state coherent.
77
77
  */
package/dist/history.js CHANGED
@@ -233,13 +233,13 @@ function isToolWindowBoundary(entry) {
233
233
  }
234
234
  /**
235
235
  * Find trailing `tool_call` entries on the active path that were never
236
- * settled — no matching `tool_result` (paired by `toolCallId`, falling back
236
+ * settled: no matching `tool_result` (paired by `toolCallId`, falling back
237
237
  * to tool name) and no subsequent `error` entry for the same tool.
238
238
  *
239
239
  * A dangling call means a model turn died (crash/abort) between recording
240
240
  * the call and recording its outcome. Left in place it produces an
241
241
  * assistant `tool_use` with no `tool_result` on resume, which providers
242
- * reject — the repair path appends synthetic interrupted outcomes for
242
+ * reject; the repair path appends synthetic interrupted outcomes for
243
243
  * exactly the entries returned here.
244
244
  *
245
245
  * Conservative by construction: only the window after the last turn
@@ -286,7 +286,7 @@ export function findTrailingDanglingToolCalls(path) {
286
286
  }
287
287
  /**
288
288
  * Trailing `task_start` entries in the same window with no matching
289
- * `task_end` — a subtask that was in flight when the turn died. These do not
289
+ * `task_end`. A subtask that was in flight when the turn died. These do not
290
290
  * corrupt model context (task entries are bookkeeping), but settling them
291
291
  * keeps UI/audit state coherent.
292
292
  */
package/dist/index.d.ts CHANGED
@@ -83,6 +83,9 @@ export { connectFabricWs } from "./ws-client.js";
83
83
  export type { WsClientOptions, WsClientCommand, WsClientHandle } from "./ws-client.js";
84
84
  export { inMemorySessionMemory } from "./session-memory.js";
85
85
  export type { SessionMemory, SessionMemoryEntry, SessionMemorySetInput, SessionMemoryFilter, SessionMemoryGetOptions, } from "./session-memory.js";
86
+ export { executeTool, ToolTimeoutError } from "./tool-execution.js";
87
+ export type { GovernedVoiceOptions, GovernedVoiceSession } from "./governed-voice.js";
88
+ export { VoiceConnectionError } from "./voice-ws-shared.js";
86
89
  export { OpenAIRealtimeVoiceProvider } from "./voice-openai-realtime.js";
87
90
  export type { OpenAIRealtimeVoiceProviderOptions } from "./voice-openai-realtime.js";
88
91
  export type { VoiceProvider, VoiceSession, VoiceConnectOptions, VoiceEvent, VoiceAudioFormat, VoiceToolResultInput, } from "./voice.js";