@fabric-harness/sdk 1.9.0 → 1.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.
@@ -0,0 +1,108 @@
1
+ import type { CostBudgetTracker, CostLimitContext } from './cost-budget.js';
2
+ import type { ModelUsage } from './model.js';
3
+ import type { ToolDef } from './tools.js';
4
+ /**
5
+ * Bidirectional voice / audio streaming surface. fabric-harness ships an
6
+ * OpenAI Realtime implementation; bring-your-own-vendor for Anthropic /
7
+ * Gemini Live / on-prem TTS+ASR pipelines.
8
+ *
9
+ * Audio frames flow in raw bytes — the standard format is PCM 16-bit
10
+ * little-endian at 24kHz mono (OpenAI Realtime default). Telephony
11
+ * bridges (Twilio Media Streams μ-law 8kHz, etc.) resample at the edge.
12
+ *
13
+ * Tool execution is the *caller's* responsibility: a `tool_call` event
14
+ * surfaces, the host code runs the tool through whatever governance gates
15
+ * apply (approvals, cost caps, rate limits), then calls
16
+ * `submitToolResult({ id, output })`. Voice sessions deliberately don't
17
+ * own the loop machinery — this keeps the audio path lean and lets users
18
+ * apply the v1-era policy primitives unchanged.
19
+ */
20
+ export type VoiceAudioFormat = 'pcm16' | 'g711_ulaw' | 'g711_alaw';
21
+ export interface VoiceConnectOptions {
22
+ /** Initial system instructions / persona. */
23
+ instructions?: string;
24
+ /** Voice timbre id (provider-specific, e.g. 'alloy', 'nova', 'verse'). */
25
+ voice?: string;
26
+ /** Audio format used on both directions. Default 'pcm16' at 24kHz mono. */
27
+ audioFormat?: VoiceAudioFormat;
28
+ /** Tools the model can call. Same shape as session.prompt() tools. */
29
+ tools?: ToolDef[];
30
+ /** Turn-detection mode (provider-specific). Default 'server_vad'. */
31
+ turnDetection?: 'server_vad' | 'none';
32
+ /** Sample rate hint for the provider. Default 24000 (PCM16). */
33
+ sampleRate?: number;
34
+ /**
35
+ * Optional cost budget tracker. Observed on every `response_done` with
36
+ * usage. Voice sessions thus participate in the same per-call /
37
+ * per-session / per-tenant ceilings as text agents (v1.4 + v1.6).
38
+ */
39
+ costBudget?: CostBudgetTracker;
40
+ /**
41
+ * Required when `costBudget.onExceed === 'approve'`. Returns true to
42
+ * resume, false to throw `CostLimitExceededError`.
43
+ */
44
+ requestCostLimitApproval?: (ctx: CostLimitContext) => Promise<boolean>;
45
+ /** Abort signal — closes the session when fired. */
46
+ signal?: AbortSignal;
47
+ }
48
+ /**
49
+ * Events streamed from a `VoiceSession`. `audio_delta` carries raw audio
50
+ * bytes; `text_delta` and `transcript` carry text; `tool_call` and
51
+ * `response_done` mark structured boundaries; `error` is fatal.
52
+ */
53
+ export type VoiceEvent = {
54
+ type: 'session_open';
55
+ } | {
56
+ type: 'audio_delta';
57
+ audio: Uint8Array;
58
+ } | {
59
+ type: 'text_delta';
60
+ delta: string;
61
+ role: 'assistant' | 'user';
62
+ } | {
63
+ type: 'transcript';
64
+ text: string;
65
+ role: 'assistant' | 'user';
66
+ } | {
67
+ type: 'tool_call';
68
+ id: string;
69
+ name: string;
70
+ input: unknown;
71
+ } | {
72
+ type: 'response_done';
73
+ usage?: ModelUsage;
74
+ } | {
75
+ type: 'cost_limit';
76
+ scope: 'call' | 'session' | 'cross-process';
77
+ observedUsd: number;
78
+ limitUsd: number;
79
+ scopeKey?: string;
80
+ } | {
81
+ type: 'error';
82
+ message: string;
83
+ };
84
+ export interface VoiceToolResultInput {
85
+ /** Tool-call id from the matching `tool_call` event. */
86
+ id: string;
87
+ /** JSON-serializable output — stringified before sending. */
88
+ output: unknown;
89
+ }
90
+ export interface VoiceSession {
91
+ /** Append a raw audio frame. Format matches `VoiceConnectOptions.audioFormat`. */
92
+ sendAudio(frame: Uint8Array): Promise<void>;
93
+ /** Send a text turn (the model responds with audio + text). */
94
+ sendText(text: string): Promise<void>;
95
+ /** Submit a tool-call result back to the model after a `tool_call` event. */
96
+ submitToolResult(input: VoiceToolResultInput): Promise<void>;
97
+ /** Cancel the in-progress response (barge-in). */
98
+ cancelResponse(): Promise<void>;
99
+ /** Async iterable of events. Closes when the session ends or aborts. */
100
+ events(): AsyncIterable<VoiceEvent>;
101
+ /** Tear down the underlying connection. */
102
+ close(): Promise<void>;
103
+ }
104
+ export interface VoiceProvider {
105
+ name: string;
106
+ connect(options: VoiceConnectOptions): Promise<VoiceSession>;
107
+ }
108
+ //# sourceMappingURL=voice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice.d.ts","sourceRoot":"","sources":["../src/voice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAEnE,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,qEAAqE;IACrE,aAAa,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IACtC,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvE,oDAAoD;IACpD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,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,CAAC,IAAI,CAAC,CAAC;IAChC,wEAAwE;IACxE,MAAM,IAAI,aAAa,CAAC,UAAU,CAAC,CAAC;IACpC,2CAA2C;IAC3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9D"}
package/dist/voice.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=voice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice.js","sourceRoot":"","sources":["../src/voice.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabric-harness/sdk",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Headless TypeScript framework for building durable, deployable autonomous agents — core SDK.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Fabric",