@voicelayer/sdk 0.1.11 → 0.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.
@@ -1,5 +1,248 @@
1
1
  import { JobContext, voice } from '@livekit/agents';
2
2
  import { z } from 'zod';
3
+ import OpenAI from 'openai';
4
+
5
+ type SessionState = 'initializing' | 'idle' | 'listening' | 'thinking' | 'speaking';
6
+ declare const LK_AGENT_STATE_MAP: Readonly<Record<string, SessionState>>;
7
+ declare const NON_BUSY_STATES: ReadonlySet<SessionState>;
8
+ /** Normalize a raw LK state string to SessionState; unknown -> 'thinking' (fail-safe). */
9
+ declare function normalizeState(raw: string): SessionState;
10
+ interface UserInputEvent {
11
+ readonly transcript: string;
12
+ readonly isFinal: boolean;
13
+ readonly speakerId: string | null;
14
+ }
15
+ interface AgentTurnEvent {
16
+ readonly text: string;
17
+ }
18
+ interface DtmfEvent$1 {
19
+ readonly digit: string;
20
+ readonly code: number;
21
+ readonly participantId: string | null;
22
+ }
23
+ interface StateChangeEvent {
24
+ readonly oldState: SessionState | null;
25
+ readonly newState: SessionState | null;
26
+ readonly rawOldState: string | null;
27
+ readonly rawNewState: string | null;
28
+ }
29
+ interface UserStateEvent {
30
+ readonly speaking: boolean;
31
+ readonly at: number;
32
+ }
33
+ interface SessionErrorEvent {
34
+ readonly error: unknown;
35
+ readonly source: 'llm' | 'stt' | 'tts' | 'realtime' | 'unknown';
36
+ readonly fatalTransport: boolean;
37
+ }
38
+ interface MetricsEvent {
39
+ readonly metrics: unknown;
40
+ }
41
+ interface SessionEventMap {
42
+ user_input: UserInputEvent;
43
+ agent_turn: AgentTurnEvent;
44
+ dtmf: DtmfEvent$1;
45
+ state: StateChangeEvent;
46
+ user_state: UserStateEvent;
47
+ error: SessionErrorEvent;
48
+ metrics: MetricsEvent;
49
+ close: void;
50
+ }
51
+ type SessionEvent = keyof SessionEventMap;
52
+ type Unsubscribe = () => void;
53
+ type ChannelKind = 'voice' | 'text';
54
+ interface SessionCapabilities {
55
+ readonly channel: ChannelKind;
56
+ readonly usingRealtime: boolean;
57
+ readonly hasStreamingTranscripts: boolean;
58
+ readonly canBargeIn: boolean;
59
+ readonly canReceiveDtmf: boolean;
60
+ readonly canPublishDtmf: boolean;
61
+ readonly canResolveSpeaker: boolean;
62
+ }
63
+ interface SayOptions$1 {
64
+ readonly allowInterruptions?: boolean;
65
+ readonly to?: string | readonly string[];
66
+ }
67
+ interface SpeechResult {
68
+ readonly interrupted: boolean;
69
+ }
70
+ interface EndCallOutcome {
71
+ readonly torn: 'room' | 'agent' | 'none';
72
+ readonly stranded: boolean;
73
+ }
74
+ interface SessionOutbound {
75
+ /** Speak verbatim. Under usingRealtime the LiveKit adapter routes to
76
+ * generateReply(verbatim) NOT session.say (no TTS in S2S). Resolves after
77
+ * playout (voice) or after the text turn is committed (text). */
78
+ say(text: string, opts?: SayOptions$1): Promise<SpeechResult>;
79
+ /** Queue a verbatim line and return once it is QUEUED, not played out (a host's `say` — burn-down G-5). `interrupt`
80
+ * first cancels what the agent is saying. Realtime routes through the model, as say() does. */
81
+ enqueueSay(text: string, opts?: {
82
+ readonly interrupt?: boolean;
83
+ readonly allowInterruptions?: boolean;
84
+ }): Promise<void>;
85
+ /** Ask the LLM to produce a turn. */
86
+ generateReply(opts?: {
87
+ readonly instructions?: string;
88
+ }): Promise<void>;
89
+ /** Barge-in cancel (puppet interrupt mode). text => no-op. */
90
+ interrupt(): Promise<void>;
91
+ /** Publish outbound DTMF from the agent leg. Throws if !canPublishDtmf. */
92
+ sendDtmf(code: number, digit: string): Promise<void>;
93
+ /** Hang up via the SDK end-call controller (deletes room so the SIP leg drops). */
94
+ endCall(opts?: {
95
+ readonly reason?: string;
96
+ readonly trigger?: string;
97
+ }): Promise<EndCallOutcome>;
98
+ }
99
+ type TurnEvent = {
100
+ readonly kind: 'partial';
101
+ readonly text: string;
102
+ readonly speakerId: string | null;
103
+ } | {
104
+ readonly kind: 'final';
105
+ readonly text: string;
106
+ readonly speakerId: string | null;
107
+ readonly at: Date;
108
+ } | {
109
+ readonly kind: 'dtmf';
110
+ readonly digit: string;
111
+ readonly code: number;
112
+ readonly participantId: string | null;
113
+ readonly at: Date;
114
+ } | {
115
+ readonly kind: 'hangup';
116
+ } | {
117
+ readonly kind: 'timeout';
118
+ };
119
+ interface InboundOptions {
120
+ readonly idleTimeoutMs?: number;
121
+ readonly finalsOnly?: boolean;
122
+ }
123
+ interface SessionAdapter extends SessionOutbound {
124
+ readonly capabilities: SessionCapabilities;
125
+ on<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
126
+ once<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
127
+ /** Graph read side. ONE underlying subscription. Mutually exclusive with the
128
+ * flat on('user_input') consumer (THROWS if both active). The iterator's
129
+ * return()/finally MUST unsubscribe. */
130
+ inbound(opts?: InboundOptions): AsyncIterableIterator<TurnEvent>;
131
+ /** Begin the session (was session.start + waitForSessionActivity). The LiveKit
132
+ * impl preserves the activity sequence VERBATIM so a provider/LLM init failure
133
+ * REJECTS rather than producing a silently-dead answered call. */
134
+ start(opts?: {
135
+ readonly agent?: unknown;
136
+ readonly room?: unknown;
137
+ }): Promise<void>;
138
+ readonly state: SessionState;
139
+ /** Resolve when idle/listening, on timeout, or on close. Synchronous fast-path:
140
+ * if already non-busy, resolves 'idle' in the same microtask. */
141
+ waitForIdle(timeoutMs: number): Promise<'idle' | 'timeout' | 'closed'>;
142
+ waitForClose(): Promise<void>;
143
+ /** Escape hatch for genuinely LK-coupled sites. undefined on the text adapter. */
144
+ readonly raw?: {
145
+ readonly job: JobContext;
146
+ readonly session: unknown;
147
+ readonly room: unknown;
148
+ };
149
+ dispose(): void;
150
+ /**
151
+ * Phase 0b-2: span-end teardown of the adapter's own engine-session listeners.
152
+ * Optional — the text adapter has none. Awaited from runCallSpan's finally
153
+ * AFTER close, so the post-close engine-death Error listener survives its
154
+ * window (PR #141). Distinct from `dispose()` (per-call fan-out cleanup).
155
+ */
156
+ [Symbol.asyncDispose]?(): Promise<void>;
157
+ }
158
+ interface EndCallControllerHandle {
159
+ hangUp(opts?: {
160
+ readonly trigger?: string;
161
+ readonly reason?: string;
162
+ }): Promise<void>;
163
+ armIdle(): void;
164
+ cancelIdle(): void;
165
+ noteEngineClosed(): void;
166
+ }
167
+ /**
168
+ * Fold the user's `speech.interruption` / `speech.endpointing` config into an
169
+ * LK turnHandling object. User-set fields are merged over whatever mode
170
+ * defaults (puppet/hostControlled) already put there — explicit agent config
171
+ * wins. No-op when the config is absent, so existing agents keep LK defaults.
172
+ * Lives here (not session-adapter-livekit) so agent.ts can import it without
173
+ * pulling @livekit/agents in at module load.
174
+ */
175
+ declare function applySpeechTurnHandling(turnHandling: Record<string, unknown>, speech?: {
176
+ readonly interruption?: {
177
+ readonly enabled?: boolean;
178
+ readonly minWords?: number;
179
+ readonly minDuration?: number;
180
+ };
181
+ readonly endpointing?: {
182
+ readonly minDelay?: number;
183
+ readonly maxDelay?: number;
184
+ };
185
+ }): Record<string, unknown>;
186
+ interface SessionFactoryInput {
187
+ readonly usingRealtime: boolean;
188
+ readonly graphMode: boolean;
189
+ readonly puppetMode: boolean;
190
+ readonly hostControlled: boolean;
191
+ /** Connector-brain agent: disable preemptive generation (a multi-second remote
192
+ * turn otherwise regenerates on the final transcript and drops the reply). */
193
+ readonly connectorAgentMode?: boolean;
194
+ readonly captureDtmf: boolean;
195
+ readonly pipeline?: {
196
+ readonly stt?: unknown;
197
+ readonly tts?: unknown;
198
+ readonly vad?: unknown;
199
+ readonly llm: unknown;
200
+ };
201
+ readonly turnHandling?: Record<string, unknown>;
202
+ /** Per-agent barge-in + endpointing tuning (AgentConfig `speech`). Merged
203
+ * over mode defaults by applySpeechTurnHandling — explicit config wins. */
204
+ readonly speech?: {
205
+ readonly interruption?: {
206
+ readonly enabled?: boolean;
207
+ readonly minWords?: number;
208
+ readonly minDuration?: number;
209
+ };
210
+ readonly endpointing?: {
211
+ readonly minDelay?: number;
212
+ readonly maxDelay?: number;
213
+ };
214
+ };
215
+ readonly resolveSpeaker?: (speakerId: string | null) => {
216
+ readonly id: string | null;
217
+ readonly label: string;
218
+ };
219
+ readonly classifyEngineClosed?: (err: unknown) => boolean;
220
+ readonly endCallController?: EndCallControllerHandle;
221
+ }
222
+ type SessionFactory = (input: SessionFactoryInput) => Promise<SessionAdapter>;
223
+ interface UserTurn {
224
+ readonly text: string;
225
+ readonly speakerLabel: string;
226
+ readonly speakerId: string | null;
227
+ readonly at: Date;
228
+ }
229
+ interface FakeSessionAdapter extends SessionAdapter {
230
+ emitUserInput(e: UserInputEvent): void;
231
+ emitAgentTurn(text: string): void;
232
+ emitDtmf(digit: string): void;
233
+ /** Drives 'state' with correct oldState/rawOldState AND runs the SAME
234
+ * arm/cancel + idle-release as production. Unknown string => 'thinking'. */
235
+ setState(next: SessionState | string): void;
236
+ emitError(error: unknown, fatalTransport?: boolean): void;
237
+ emitClose(): void;
238
+ readonly spoken: ReadonlyArray<string>;
239
+ readonly generatedReplies: ReadonlyArray<string | undefined>;
240
+ readonly sentDtmf: ReadonlyArray<string>;
241
+ readonly endCalls: ReadonlyArray<{
242
+ readonly reason?: string;
243
+ readonly trigger?: string;
244
+ }>;
245
+ }
3
246
 
4
247
  declare const brand: unique symbol;
5
248
  type Brand<T, B> = T & {
@@ -94,11 +337,11 @@ declare const ProcessSchemaDTO: z.ZodObject<{
94
337
  id: z.ZodString;
95
338
  text: z.ZodString;
96
339
  }, "strip", z.ZodTypeAny, {
97
- id: string;
98
340
  text: string;
99
- }, {
100
341
  id: string;
342
+ }, {
101
343
  text: string;
344
+ id: string;
102
345
  }>, "many">>;
103
346
  fields: z.ZodArray<z.ZodObject<{
104
347
  name: z.ZodString;
@@ -206,7 +449,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
206
449
  description: string;
207
450
  input: Record<string, "string" | "number" | "boolean">;
208
451
  url: string;
209
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
452
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
210
453
  auth: "none" | "connection";
211
454
  headers?: Record<string, string> | undefined;
212
455
  connectionRef?: string | undefined;
@@ -215,7 +458,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
215
458
  description: string;
216
459
  input: Record<string, "string" | "number" | "boolean">;
217
460
  url: string;
218
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
461
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
219
462
  auth: "none" | "connection";
220
463
  headers?: Record<string, string> | undefined;
221
464
  connectionRef?: string | undefined;
@@ -290,7 +533,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
290
533
  condition?: string | undefined;
291
534
  }>, "many">;
292
535
  }, "strip", z.ZodTypeAny, {
293
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
536
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
294
537
  id: string;
295
538
  config: Record<string, unknown>;
296
539
  out: {
@@ -300,7 +543,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
300
543
  condition?: string | undefined;
301
544
  }[];
302
545
  }, {
303
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
546
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
304
547
  id: string;
305
548
  config: Record<string, unknown>;
306
549
  out: {
@@ -321,20 +564,22 @@ declare const ProcessSchemaDTO: z.ZodObject<{
321
564
  acyclic: z.ZodBoolean;
322
565
  droppedEdges: z.ZodArray<z.ZodString, "many">;
323
566
  unsupportedNodes: z.ZodArray<z.ZodString, "many">;
567
+ labelOnlyEdges: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
324
568
  }, "strip", z.ZodTypeAny, {
325
569
  acyclic: boolean;
326
570
  droppedEdges: string[];
327
571
  unsupportedNodes: string[];
572
+ labelOnlyEdges?: string[] | undefined;
328
573
  }, {
329
574
  acyclic: boolean;
330
575
  droppedEdges: string[];
331
576
  unsupportedNodes: string[];
577
+ labelOnlyEdges?: string[] | undefined;
332
578
  }>>;
333
579
  }, "strip", z.ZodTypeAny, {
334
- v: 1;
335
580
  id: string;
336
581
  nodes: Record<string, {
337
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
582
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
338
583
  id: string;
339
584
  config: Record<string, unknown>;
340
585
  out: {
@@ -344,6 +589,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
344
589
  condition?: string | undefined;
345
590
  }[];
346
591
  }>;
592
+ v: 1;
347
593
  entry: string[];
348
594
  completionGate: {
349
595
  requiredFields: string[];
@@ -352,12 +598,12 @@ declare const ProcessSchemaDTO: z.ZodObject<{
352
598
  acyclic: boolean;
353
599
  droppedEdges: string[];
354
600
  unsupportedNodes: string[];
601
+ labelOnlyEdges?: string[] | undefined;
355
602
  } | undefined;
356
603
  }, {
357
- v: 1;
358
604
  id: string;
359
605
  nodes: Record<string, {
360
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
606
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
361
607
  id: string;
362
608
  config: Record<string, unknown>;
363
609
  out: {
@@ -367,6 +613,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
367
613
  condition?: string | undefined;
368
614
  }[];
369
615
  }>;
616
+ v: 1;
370
617
  entry: string[];
371
618
  completionGate: {
372
619
  requiredFields: string[];
@@ -375,6 +622,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
375
622
  acyclic: boolean;
376
623
  droppedEdges: string[];
377
624
  unsupportedNodes: string[];
625
+ labelOnlyEdges?: string[] | undefined;
378
626
  } | undefined;
379
627
  }>>;
380
628
  }, "strip", z.ZodTypeAny, {
@@ -417,8 +665,8 @@ declare const ProcessSchemaDTO: z.ZodObject<{
417
665
  } | undefined;
418
666
  } | undefined;
419
667
  prompts?: {
420
- id: string;
421
668
  text: string;
669
+ id: string;
422
670
  }[] | undefined;
423
671
  triggers?: {
424
672
  then: string;
@@ -431,16 +679,15 @@ declare const ProcessSchemaDTO: z.ZodObject<{
431
679
  description: string;
432
680
  input: Record<string, "string" | "number" | "boolean">;
433
681
  url: string;
434
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
682
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
435
683
  auth: "none" | "connection";
436
684
  headers?: Record<string, string> | undefined;
437
685
  connectionRef?: string | undefined;
438
686
  }[] | undefined;
439
687
  program?: {
440
- v: 1;
441
688
  id: string;
442
689
  nodes: Record<string, {
443
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
690
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
444
691
  id: string;
445
692
  config: Record<string, unknown>;
446
693
  out: {
@@ -450,6 +697,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
450
697
  condition?: string | undefined;
451
698
  }[];
452
699
  }>;
700
+ v: 1;
453
701
  entry: string[];
454
702
  completionGate: {
455
703
  requiredFields: string[];
@@ -458,6 +706,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
458
706
  acyclic: boolean;
459
707
  droppedEdges: string[];
460
708
  unsupportedNodes: string[];
709
+ labelOnlyEdges?: string[] | undefined;
461
710
  } | undefined;
462
711
  } | undefined;
463
712
  }, {
@@ -500,8 +749,8 @@ declare const ProcessSchemaDTO: z.ZodObject<{
500
749
  } | undefined;
501
750
  } | undefined;
502
751
  prompts?: {
503
- id: string;
504
752
  text: string;
753
+ id: string;
505
754
  }[] | undefined;
506
755
  triggers?: {
507
756
  then: string;
@@ -514,16 +763,15 @@ declare const ProcessSchemaDTO: z.ZodObject<{
514
763
  description: string;
515
764
  input: Record<string, "string" | "number" | "boolean">;
516
765
  url: string;
517
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
766
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
518
767
  auth: "none" | "connection";
519
768
  headers?: Record<string, string> | undefined;
520
769
  connectionRef?: string | undefined;
521
770
  }[] | undefined;
522
771
  program?: {
523
- v: 1;
524
772
  id: string;
525
773
  nodes: Record<string, {
526
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
774
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
527
775
  id: string;
528
776
  config: Record<string, unknown>;
529
777
  out: {
@@ -533,6 +781,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
533
781
  condition?: string | undefined;
534
782
  }[];
535
783
  }>;
784
+ v: 1;
536
785
  entry: string[];
537
786
  completionGate: {
538
787
  requiredFields: string[];
@@ -541,6 +790,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
541
790
  acyclic: boolean;
542
791
  droppedEdges: string[];
543
792
  unsupportedNodes: string[];
793
+ labelOnlyEdges?: string[] | undefined;
544
794
  } | undefined;
545
795
  } | undefined;
546
796
  }>;
@@ -575,11 +825,11 @@ declare const AgentDTO: z.ZodObject<{
575
825
  id: z.ZodString;
576
826
  text: z.ZodString;
577
827
  }, "strip", z.ZodTypeAny, {
578
- id: string;
579
828
  text: string;
580
- }, {
581
829
  id: string;
830
+ }, {
582
831
  text: string;
832
+ id: string;
583
833
  }>, "many">>;
584
834
  fields: z.ZodArray<z.ZodObject<{
585
835
  name: z.ZodString;
@@ -687,7 +937,7 @@ declare const AgentDTO: z.ZodObject<{
687
937
  description: string;
688
938
  input: Record<string, "string" | "number" | "boolean">;
689
939
  url: string;
690
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
940
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
691
941
  auth: "none" | "connection";
692
942
  headers?: Record<string, string> | undefined;
693
943
  connectionRef?: string | undefined;
@@ -696,7 +946,7 @@ declare const AgentDTO: z.ZodObject<{
696
946
  description: string;
697
947
  input: Record<string, "string" | "number" | "boolean">;
698
948
  url: string;
699
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
949
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
700
950
  auth: "none" | "connection";
701
951
  headers?: Record<string, string> | undefined;
702
952
  connectionRef?: string | undefined;
@@ -771,7 +1021,7 @@ declare const AgentDTO: z.ZodObject<{
771
1021
  condition?: string | undefined;
772
1022
  }>, "many">;
773
1023
  }, "strip", z.ZodTypeAny, {
774
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1024
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
775
1025
  id: string;
776
1026
  config: Record<string, unknown>;
777
1027
  out: {
@@ -781,7 +1031,7 @@ declare const AgentDTO: z.ZodObject<{
781
1031
  condition?: string | undefined;
782
1032
  }[];
783
1033
  }, {
784
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1034
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
785
1035
  id: string;
786
1036
  config: Record<string, unknown>;
787
1037
  out: {
@@ -802,20 +1052,22 @@ declare const AgentDTO: z.ZodObject<{
802
1052
  acyclic: z.ZodBoolean;
803
1053
  droppedEdges: z.ZodArray<z.ZodString, "many">;
804
1054
  unsupportedNodes: z.ZodArray<z.ZodString, "many">;
1055
+ labelOnlyEdges: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
805
1056
  }, "strip", z.ZodTypeAny, {
806
1057
  acyclic: boolean;
807
1058
  droppedEdges: string[];
808
1059
  unsupportedNodes: string[];
1060
+ labelOnlyEdges?: string[] | undefined;
809
1061
  }, {
810
1062
  acyclic: boolean;
811
1063
  droppedEdges: string[];
812
1064
  unsupportedNodes: string[];
1065
+ labelOnlyEdges?: string[] | undefined;
813
1066
  }>>;
814
1067
  }, "strip", z.ZodTypeAny, {
815
- v: 1;
816
1068
  id: string;
817
1069
  nodes: Record<string, {
818
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1070
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
819
1071
  id: string;
820
1072
  config: Record<string, unknown>;
821
1073
  out: {
@@ -825,6 +1077,7 @@ declare const AgentDTO: z.ZodObject<{
825
1077
  condition?: string | undefined;
826
1078
  }[];
827
1079
  }>;
1080
+ v: 1;
828
1081
  entry: string[];
829
1082
  completionGate: {
830
1083
  requiredFields: string[];
@@ -833,12 +1086,12 @@ declare const AgentDTO: z.ZodObject<{
833
1086
  acyclic: boolean;
834
1087
  droppedEdges: string[];
835
1088
  unsupportedNodes: string[];
1089
+ labelOnlyEdges?: string[] | undefined;
836
1090
  } | undefined;
837
1091
  }, {
838
- v: 1;
839
1092
  id: string;
840
1093
  nodes: Record<string, {
841
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1094
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
842
1095
  id: string;
843
1096
  config: Record<string, unknown>;
844
1097
  out: {
@@ -848,6 +1101,7 @@ declare const AgentDTO: z.ZodObject<{
848
1101
  condition?: string | undefined;
849
1102
  }[];
850
1103
  }>;
1104
+ v: 1;
851
1105
  entry: string[];
852
1106
  completionGate: {
853
1107
  requiredFields: string[];
@@ -856,6 +1110,7 @@ declare const AgentDTO: z.ZodObject<{
856
1110
  acyclic: boolean;
857
1111
  droppedEdges: string[];
858
1112
  unsupportedNodes: string[];
1113
+ labelOnlyEdges?: string[] | undefined;
859
1114
  } | undefined;
860
1115
  }>>;
861
1116
  }, "strip", z.ZodTypeAny, {
@@ -898,8 +1153,8 @@ declare const AgentDTO: z.ZodObject<{
898
1153
  } | undefined;
899
1154
  } | undefined;
900
1155
  prompts?: {
901
- id: string;
902
1156
  text: string;
1157
+ id: string;
903
1158
  }[] | undefined;
904
1159
  triggers?: {
905
1160
  then: string;
@@ -912,16 +1167,15 @@ declare const AgentDTO: z.ZodObject<{
912
1167
  description: string;
913
1168
  input: Record<string, "string" | "number" | "boolean">;
914
1169
  url: string;
915
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
1170
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
916
1171
  auth: "none" | "connection";
917
1172
  headers?: Record<string, string> | undefined;
918
1173
  connectionRef?: string | undefined;
919
1174
  }[] | undefined;
920
1175
  program?: {
921
- v: 1;
922
1176
  id: string;
923
1177
  nodes: Record<string, {
924
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1178
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
925
1179
  id: string;
926
1180
  config: Record<string, unknown>;
927
1181
  out: {
@@ -931,6 +1185,7 @@ declare const AgentDTO: z.ZodObject<{
931
1185
  condition?: string | undefined;
932
1186
  }[];
933
1187
  }>;
1188
+ v: 1;
934
1189
  entry: string[];
935
1190
  completionGate: {
936
1191
  requiredFields: string[];
@@ -939,6 +1194,7 @@ declare const AgentDTO: z.ZodObject<{
939
1194
  acyclic: boolean;
940
1195
  droppedEdges: string[];
941
1196
  unsupportedNodes: string[];
1197
+ labelOnlyEdges?: string[] | undefined;
942
1198
  } | undefined;
943
1199
  } | undefined;
944
1200
  }, {
@@ -981,8 +1237,8 @@ declare const AgentDTO: z.ZodObject<{
981
1237
  } | undefined;
982
1238
  } | undefined;
983
1239
  prompts?: {
984
- id: string;
985
1240
  text: string;
1241
+ id: string;
986
1242
  }[] | undefined;
987
1243
  triggers?: {
988
1244
  then: string;
@@ -995,16 +1251,15 @@ declare const AgentDTO: z.ZodObject<{
995
1251
  description: string;
996
1252
  input: Record<string, "string" | "number" | "boolean">;
997
1253
  url: string;
998
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
1254
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
999
1255
  auth: "none" | "connection";
1000
1256
  headers?: Record<string, string> | undefined;
1001
1257
  connectionRef?: string | undefined;
1002
1258
  }[] | undefined;
1003
1259
  program?: {
1004
- v: 1;
1005
1260
  id: string;
1006
1261
  nodes: Record<string, {
1007
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1262
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1008
1263
  id: string;
1009
1264
  config: Record<string, unknown>;
1010
1265
  out: {
@@ -1014,6 +1269,7 @@ declare const AgentDTO: z.ZodObject<{
1014
1269
  condition?: string | undefined;
1015
1270
  }[];
1016
1271
  }>;
1272
+ v: 1;
1017
1273
  entry: string[];
1018
1274
  completionGate: {
1019
1275
  requiredFields: string[];
@@ -1022,9 +1278,11 @@ declare const AgentDTO: z.ZodObject<{
1022
1278
  acyclic: boolean;
1023
1279
  droppedEdges: string[];
1024
1280
  unsupportedNodes: string[];
1281
+ labelOnlyEdges?: string[] | undefined;
1025
1282
  } | undefined;
1026
1283
  } | undefined;
1027
1284
  }>>>;
1285
+ textRunnable: z.ZodOptional<z.ZodBoolean>;
1028
1286
  createdAt: z.ZodString;
1029
1287
  updatedAt: z.ZodString;
1030
1288
  }, "strip", z.ZodTypeAny, {
@@ -1085,8 +1343,8 @@ declare const AgentDTO: z.ZodObject<{
1085
1343
  } | undefined;
1086
1344
  } | undefined;
1087
1345
  prompts?: {
1088
- id: string;
1089
1346
  text: string;
1347
+ id: string;
1090
1348
  }[] | undefined;
1091
1349
  triggers?: {
1092
1350
  then: string;
@@ -1099,16 +1357,15 @@ declare const AgentDTO: z.ZodObject<{
1099
1357
  description: string;
1100
1358
  input: Record<string, "string" | "number" | "boolean">;
1101
1359
  url: string;
1102
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
1360
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
1103
1361
  auth: "none" | "connection";
1104
1362
  headers?: Record<string, string> | undefined;
1105
1363
  connectionRef?: string | undefined;
1106
1364
  }[] | undefined;
1107
1365
  program?: {
1108
- v: 1;
1109
1366
  id: string;
1110
1367
  nodes: Record<string, {
1111
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1368
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1112
1369
  id: string;
1113
1370
  config: Record<string, unknown>;
1114
1371
  out: {
@@ -1118,6 +1375,7 @@ declare const AgentDTO: z.ZodObject<{
1118
1375
  condition?: string | undefined;
1119
1376
  }[];
1120
1377
  }>;
1378
+ v: 1;
1121
1379
  entry: string[];
1122
1380
  completionGate: {
1123
1381
  requiredFields: string[];
@@ -1126,9 +1384,11 @@ declare const AgentDTO: z.ZodObject<{
1126
1384
  acyclic: boolean;
1127
1385
  droppedEdges: string[];
1128
1386
  unsupportedNodes: string[];
1387
+ labelOnlyEdges?: string[] | undefined;
1129
1388
  } | undefined;
1130
1389
  } | undefined;
1131
1390
  } | null | undefined;
1391
+ textRunnable?: boolean | undefined;
1132
1392
  }, {
1133
1393
  status: "online" | "offline" | "degraded";
1134
1394
  id: string;
@@ -1187,8 +1447,8 @@ declare const AgentDTO: z.ZodObject<{
1187
1447
  } | undefined;
1188
1448
  } | undefined;
1189
1449
  prompts?: {
1190
- id: string;
1191
1450
  text: string;
1451
+ id: string;
1192
1452
  }[] | undefined;
1193
1453
  triggers?: {
1194
1454
  then: string;
@@ -1201,16 +1461,15 @@ declare const AgentDTO: z.ZodObject<{
1201
1461
  description: string;
1202
1462
  input: Record<string, "string" | "number" | "boolean">;
1203
1463
  url: string;
1204
- method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
1464
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
1205
1465
  auth: "none" | "connection";
1206
1466
  headers?: Record<string, string> | undefined;
1207
1467
  connectionRef?: string | undefined;
1208
1468
  }[] | undefined;
1209
1469
  program?: {
1210
- v: 1;
1211
1470
  id: string;
1212
1471
  nodes: Record<string, {
1213
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1472
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1214
1473
  id: string;
1215
1474
  config: Record<string, unknown>;
1216
1475
  out: {
@@ -1220,6 +1479,7 @@ declare const AgentDTO: z.ZodObject<{
1220
1479
  condition?: string | undefined;
1221
1480
  }[];
1222
1481
  }>;
1482
+ v: 1;
1223
1483
  entry: string[];
1224
1484
  completionGate: {
1225
1485
  requiredFields: string[];
@@ -1228,9 +1488,11 @@ declare const AgentDTO: z.ZodObject<{
1228
1488
  acyclic: boolean;
1229
1489
  droppedEdges: string[];
1230
1490
  unsupportedNodes: string[];
1491
+ labelOnlyEdges?: string[] | undefined;
1231
1492
  } | undefined;
1232
1493
  } | undefined;
1233
1494
  } | null | undefined;
1495
+ textRunnable?: boolean | undefined;
1234
1496
  }>;
1235
1497
  type AgentDTO = z.infer<typeof AgentDTO>;
1236
1498
 
@@ -1259,7 +1521,7 @@ declare const FlowProgram: z.ZodObject<{
1259
1521
  condition?: string | undefined;
1260
1522
  }>, "many">;
1261
1523
  }, "strip", z.ZodTypeAny, {
1262
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1524
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1263
1525
  id: string;
1264
1526
  config: Record<string, unknown>;
1265
1527
  out: {
@@ -1269,7 +1531,7 @@ declare const FlowProgram: z.ZodObject<{
1269
1531
  condition?: string | undefined;
1270
1532
  }[];
1271
1533
  }, {
1272
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1534
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1273
1535
  id: string;
1274
1536
  config: Record<string, unknown>;
1275
1537
  out: {
@@ -1290,20 +1552,22 @@ declare const FlowProgram: z.ZodObject<{
1290
1552
  acyclic: z.ZodBoolean;
1291
1553
  droppedEdges: z.ZodArray<z.ZodString, "many">;
1292
1554
  unsupportedNodes: z.ZodArray<z.ZodString, "many">;
1555
+ labelOnlyEdges: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1293
1556
  }, "strip", z.ZodTypeAny, {
1294
1557
  acyclic: boolean;
1295
1558
  droppedEdges: string[];
1296
1559
  unsupportedNodes: string[];
1560
+ labelOnlyEdges?: string[] | undefined;
1297
1561
  }, {
1298
1562
  acyclic: boolean;
1299
1563
  droppedEdges: string[];
1300
1564
  unsupportedNodes: string[];
1565
+ labelOnlyEdges?: string[] | undefined;
1301
1566
  }>>;
1302
1567
  }, "strip", z.ZodTypeAny, {
1303
- v: 1;
1304
1568
  id: string;
1305
1569
  nodes: Record<string, {
1306
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1570
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1307
1571
  id: string;
1308
1572
  config: Record<string, unknown>;
1309
1573
  out: {
@@ -1313,6 +1577,7 @@ declare const FlowProgram: z.ZodObject<{
1313
1577
  condition?: string | undefined;
1314
1578
  }[];
1315
1579
  }>;
1580
+ v: 1;
1316
1581
  entry: string[];
1317
1582
  completionGate: {
1318
1583
  requiredFields: string[];
@@ -1321,12 +1586,12 @@ declare const FlowProgram: z.ZodObject<{
1321
1586
  acyclic: boolean;
1322
1587
  droppedEdges: string[];
1323
1588
  unsupportedNodes: string[];
1589
+ labelOnlyEdges?: string[] | undefined;
1324
1590
  } | undefined;
1325
1591
  }, {
1326
- v: 1;
1327
1592
  id: string;
1328
1593
  nodes: Record<string, {
1329
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1594
+ type: "llm" | "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "rag" | "memory" | "speech" | "classify" | "router" | "note";
1330
1595
  id: string;
1331
1596
  config: Record<string, unknown>;
1332
1597
  out: {
@@ -1336,6 +1601,7 @@ declare const FlowProgram: z.ZodObject<{
1336
1601
  condition?: string | undefined;
1337
1602
  }[];
1338
1603
  }>;
1604
+ v: 1;
1339
1605
  entry: string[];
1340
1606
  completionGate: {
1341
1607
  requiredFields: string[];
@@ -1344,231 +1610,11 @@ declare const FlowProgram: z.ZodObject<{
1344
1610
  acyclic: boolean;
1345
1611
  droppedEdges: string[];
1346
1612
  unsupportedNodes: string[];
1613
+ labelOnlyEdges?: string[] | undefined;
1347
1614
  } | undefined;
1348
1615
  }>;
1349
1616
  type FlowProgram = z.infer<typeof FlowProgram>;
1350
1617
 
1351
- type SessionState = 'initializing' | 'idle' | 'listening' | 'thinking' | 'speaking';
1352
- declare const LK_AGENT_STATE_MAP: Readonly<Record<string, SessionState>>;
1353
- declare const NON_BUSY_STATES: ReadonlySet<SessionState>;
1354
- /** Normalize a raw LK state string to SessionState; unknown -> 'thinking' (fail-safe). */
1355
- declare function normalizeState(raw: string): SessionState;
1356
- interface UserInputEvent {
1357
- readonly transcript: string;
1358
- readonly isFinal: boolean;
1359
- readonly speakerId: string | null;
1360
- }
1361
- interface AgentTurnEvent {
1362
- readonly text: string;
1363
- }
1364
- interface DtmfEvent$1 {
1365
- readonly digit: string;
1366
- readonly code: number;
1367
- readonly participantId: string | null;
1368
- }
1369
- interface StateChangeEvent {
1370
- readonly oldState: SessionState | null;
1371
- readonly newState: SessionState | null;
1372
- readonly rawOldState: string | null;
1373
- readonly rawNewState: string | null;
1374
- }
1375
- interface SessionErrorEvent {
1376
- readonly error: unknown;
1377
- readonly source: 'llm' | 'stt' | 'tts' | 'realtime' | 'unknown';
1378
- readonly fatalTransport: boolean;
1379
- }
1380
- interface MetricsEvent {
1381
- readonly metrics: unknown;
1382
- }
1383
- interface SessionEventMap {
1384
- user_input: UserInputEvent;
1385
- agent_turn: AgentTurnEvent;
1386
- dtmf: DtmfEvent$1;
1387
- state: StateChangeEvent;
1388
- error: SessionErrorEvent;
1389
- metrics: MetricsEvent;
1390
- close: void;
1391
- }
1392
- type SessionEvent = keyof SessionEventMap;
1393
- type Unsubscribe = () => void;
1394
- type ChannelKind = 'voice' | 'text';
1395
- interface SessionCapabilities {
1396
- readonly channel: ChannelKind;
1397
- readonly usingRealtime: boolean;
1398
- readonly hasStreamingTranscripts: boolean;
1399
- readonly canBargeIn: boolean;
1400
- readonly canReceiveDtmf: boolean;
1401
- readonly canPublishDtmf: boolean;
1402
- readonly canResolveSpeaker: boolean;
1403
- }
1404
- interface SayOptions$1 {
1405
- readonly allowInterruptions?: boolean;
1406
- readonly to?: string | readonly string[];
1407
- }
1408
- interface SpeechResult {
1409
- readonly interrupted: boolean;
1410
- }
1411
- interface EndCallOutcome {
1412
- readonly torn: 'room' | 'agent' | 'none';
1413
- readonly stranded: boolean;
1414
- }
1415
- interface SessionOutbound {
1416
- /** Speak verbatim. Under usingRealtime the LiveKit adapter routes to
1417
- * generateReply(verbatim) NOT session.say (no TTS in S2S). Resolves after
1418
- * playout (voice) or after the text turn is committed (text). */
1419
- say(text: string, opts?: SayOptions$1): Promise<SpeechResult>;
1420
- /** Ask the LLM to produce a turn. */
1421
- generateReply(opts?: {
1422
- readonly instructions?: string;
1423
- }): Promise<void>;
1424
- /** Barge-in cancel (puppet interrupt mode). text => no-op. */
1425
- interrupt(): Promise<void>;
1426
- /** Publish outbound DTMF from the agent leg. Throws if !canPublishDtmf. */
1427
- sendDtmf(code: number, digit: string): Promise<void>;
1428
- /** Hang up via the SDK end-call controller (deletes room so the SIP leg drops). */
1429
- endCall(opts?: {
1430
- readonly reason?: string;
1431
- readonly trigger?: string;
1432
- }): Promise<EndCallOutcome>;
1433
- }
1434
- type TurnEvent = {
1435
- readonly kind: 'partial';
1436
- readonly text: string;
1437
- readonly speakerId: string | null;
1438
- } | {
1439
- readonly kind: 'final';
1440
- readonly text: string;
1441
- readonly speakerId: string | null;
1442
- readonly at: Date;
1443
- } | {
1444
- readonly kind: 'dtmf';
1445
- readonly digit: string;
1446
- readonly code: number;
1447
- readonly participantId: string | null;
1448
- readonly at: Date;
1449
- } | {
1450
- readonly kind: 'hangup';
1451
- } | {
1452
- readonly kind: 'timeout';
1453
- };
1454
- interface InboundOptions {
1455
- readonly idleTimeoutMs?: number;
1456
- readonly finalsOnly?: boolean;
1457
- }
1458
- interface SessionAdapter extends SessionOutbound {
1459
- readonly capabilities: SessionCapabilities;
1460
- on<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
1461
- once<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
1462
- /** Graph read side. ONE underlying subscription. Mutually exclusive with the
1463
- * flat on('user_input') consumer (THROWS if both active). The iterator's
1464
- * return()/finally MUST unsubscribe. */
1465
- inbound(opts?: InboundOptions): AsyncIterableIterator<TurnEvent>;
1466
- /** Begin the session (was session.start + waitForSessionActivity). The LiveKit
1467
- * impl preserves the activity sequence VERBATIM so a provider/LLM init failure
1468
- * REJECTS rather than producing a silently-dead answered call. */
1469
- start(opts?: {
1470
- readonly agent?: unknown;
1471
- readonly room?: unknown;
1472
- }): Promise<void>;
1473
- readonly state: SessionState;
1474
- /** Resolve when idle/listening, on timeout, or on close. Synchronous fast-path:
1475
- * if already non-busy, resolves 'idle' in the same microtask. */
1476
- waitForIdle(timeoutMs: number): Promise<'idle' | 'timeout' | 'closed'>;
1477
- waitForClose(): Promise<void>;
1478
- /** Escape hatch for genuinely LK-coupled sites. undefined on the text adapter. */
1479
- readonly raw?: {
1480
- readonly job: JobContext;
1481
- readonly session: unknown;
1482
- readonly room: unknown;
1483
- };
1484
- dispose(): void;
1485
- }
1486
- interface EndCallControllerHandle {
1487
- hangUp(opts?: {
1488
- readonly trigger?: string;
1489
- readonly reason?: string;
1490
- }): Promise<void>;
1491
- armIdle(): void;
1492
- cancelIdle(): void;
1493
- noteEngineClosed(): void;
1494
- }
1495
- /**
1496
- * Fold the user's `speech.interruption` / `speech.endpointing` config into an
1497
- * LK turnHandling object. User-set fields are merged over whatever mode
1498
- * defaults (puppet/hostControlled) already put there — explicit agent config
1499
- * wins. No-op when the config is absent, so existing agents keep LK defaults.
1500
- * Lives here (not session-adapter-livekit) so agent.ts can import it without
1501
- * pulling @livekit/agents in at module load.
1502
- */
1503
- declare function applySpeechTurnHandling(turnHandling: Record<string, unknown>, speech?: {
1504
- readonly interruption?: {
1505
- readonly enabled?: boolean;
1506
- readonly minWords?: number;
1507
- readonly minDuration?: number;
1508
- };
1509
- readonly endpointing?: {
1510
- readonly minDelay?: number;
1511
- readonly maxDelay?: number;
1512
- };
1513
- }): Record<string, unknown>;
1514
- interface SessionFactoryInput {
1515
- readonly usingRealtime: boolean;
1516
- readonly graphMode: boolean;
1517
- readonly puppetMode: boolean;
1518
- readonly hostControlled: boolean;
1519
- readonly captureDtmf: boolean;
1520
- readonly pipeline?: {
1521
- readonly stt?: unknown;
1522
- readonly tts?: unknown;
1523
- readonly vad?: unknown;
1524
- readonly llm: unknown;
1525
- };
1526
- readonly turnHandling?: Record<string, unknown>;
1527
- /** Per-agent barge-in + endpointing tuning (AgentConfig `speech`). Merged
1528
- * over mode defaults by applySpeechTurnHandling — explicit config wins. */
1529
- readonly speech?: {
1530
- readonly interruption?: {
1531
- readonly enabled?: boolean;
1532
- readonly minWords?: number;
1533
- readonly minDuration?: number;
1534
- };
1535
- readonly endpointing?: {
1536
- readonly minDelay?: number;
1537
- readonly maxDelay?: number;
1538
- };
1539
- };
1540
- readonly resolveSpeaker?: (speakerId: string | null) => {
1541
- readonly id: string | null;
1542
- readonly label: string;
1543
- };
1544
- readonly classifyEngineClosed?: (err: unknown) => boolean;
1545
- readonly endCallController?: EndCallControllerHandle;
1546
- }
1547
- type SessionFactory = (input: SessionFactoryInput) => Promise<SessionAdapter>;
1548
- interface UserTurn {
1549
- readonly text: string;
1550
- readonly speakerLabel: string;
1551
- readonly speakerId: string | null;
1552
- readonly at: Date;
1553
- }
1554
- interface FakeSessionAdapter extends SessionAdapter {
1555
- emitUserInput(e: UserInputEvent): void;
1556
- emitAgentTurn(text: string): void;
1557
- emitDtmf(digit: string): void;
1558
- /** Drives 'state' with correct oldState/rawOldState AND runs the SAME
1559
- * arm/cancel + idle-release as production. Unknown string => 'thinking'. */
1560
- setState(next: SessionState | string): void;
1561
- emitError(error: unknown, fatalTransport?: boolean): void;
1562
- emitClose(): void;
1563
- readonly spoken: ReadonlyArray<string>;
1564
- readonly generatedReplies: ReadonlyArray<string | undefined>;
1565
- readonly sentDtmf: ReadonlyArray<string>;
1566
- readonly endCalls: ReadonlyArray<{
1567
- readonly reason?: string;
1568
- readonly trigger?: string;
1569
- }>;
1570
- }
1571
-
1572
1618
  interface ProcessSchema {
1573
1619
  readonly id: string;
1574
1620
  readonly fields: readonly FieldSpec[];
@@ -1931,6 +1977,13 @@ type FlowOutcome = {
1931
1977
  readonly message: string;
1932
1978
  };
1933
1979
 
1980
+ /**
1981
+ * Run `fn` with `client` as the internal helpers' OpenAI client. The scope follows the async work `fn` starts (an
1982
+ * interpreter loop started inside keeps it for its whole life), so a conversation started inside it uses `client`
1983
+ * for every extraction, condition judge and embedding it makes.
1984
+ */
1985
+ declare function runWithOpenAIScope<T>(client: OpenAI, fn: () => T): T;
1986
+
1934
1987
  /** One graph-lifecycle event, for the builder's dry-run trace overlay. */
1935
1988
  interface GraphTraceEvent {
1936
1989
  readonly kind: string;
@@ -1953,6 +2006,9 @@ interface RunTextSessionOptions {
1953
2006
  /** Tap the graph lifecycle (node.entered / edge.traversed / notes) — the
1954
2007
  * same stream the live timeline records, surfaced for the dry-run trace. */
1955
2008
  readonly onTrace?: (event: GraphTraceEvent) => void;
2009
+ /** Fires when the interpreter finishes a turn and blocks for the next user
2010
+ * message — the per-turn boundary used by the live driver below. */
2011
+ readonly onAwaitInput?: () => void;
1956
2012
  }
1957
2013
  interface TextSession {
1958
2014
  /** Feed an inbound user message (a final turn). */
@@ -1992,5 +2048,38 @@ interface TextTranscriptResult {
1992
2048
  * flow consumes them in order as it reaches ask points. Stateless — the request/
1993
2049
  * response shape the text playground route uses. */
1994
2050
  declare function runTextTranscript(opts: RunTextTranscriptOptions): Promise<TextTranscriptResult>;
2051
+ /** One live turn's result: the agent text emitted for this turn, whether the flow
2052
+ * has ended, and (when ended) the final outcome. */
2053
+ interface LiveTurnResult {
2054
+ readonly replies: readonly string[];
2055
+ readonly done: boolean;
2056
+ readonly outcome?: FlowOutcome;
2057
+ }
2058
+ /** A live, turn-by-turn flow conversation: keeps ONE interpreter session alive
2059
+ * (graph cursor + collected slots preserved between turns), so each `turn()`
2060
+ * advances the real flow one user message at a time — the incremental complement
2061
+ * to the stateless `runTextTranscript`. Backs a chat UI / an HTTP turn endpoint. */
2062
+ interface LiveTextConversation {
2063
+ /** Collect the agent's opening turn (greeting / first prompt) before any user
2064
+ * input. Call once, right after construction. */
2065
+ start(): Promise<LiveTurnResult>;
2066
+ /** Feed one user message; resolves with the agent's replies for THIS turn once
2067
+ * the interpreter parks for the next input (or the flow ends). */
2068
+ turn(text: string): Promise<LiveTurnResult>;
2069
+ /** End the conversation (hangup); resolves with the final outcome. */
2070
+ end(): Promise<FlowOutcome>;
2071
+ }
2072
+ type RunLiveTextOptions = Omit<RunTextSessionOptions, 'onAgentText' | 'onAwaitInput'> & {
2073
+ /** Optional extra sink for agent text (the driver always buffers per turn). */
2074
+ readonly onAgentText?: (text: string) => void | Promise<void>;
2075
+ /** The flow's compiled schema. When `processRt` is not supplied, the runtime is
2076
+ * built from this (else derived from the program) — required for ask nodes to
2077
+ * capture, exactly as `runTextTranscript` does. */
2078
+ readonly schema?: ProcessSchemaDTO;
2079
+ };
2080
+ /** Drive a flow live, one user turn at a time, preserving interpreter state
2081
+ * between turns. Uses the `onAwaitInput` boundary: a turn is "done" once the
2082
+ * interpreter blocks for the next message, or the flow ends. */
2083
+ declare function runLiveTextConversation(opts: RunLiveTextOptions): LiveTextConversation;
1995
2084
 
1996
- export { type UserTurn as $, AgentDTO as A, type SessionEvent as B, type CallInfo as C, type DtmfEvent as D, type EndCallControllerHandle as E, type FakeSessionAdapter as F, type SessionEventMap as G, type SessionFactory as H, type InboundOptions as I, type SessionFactoryInput as J, type SessionOutbound as K, LK_AGENT_STATE_MAP as L, type MemoryHandle as M, NON_BUSY_STATES as N, type SessionState as O, ProcessSchemaDTO as P, type SpeechResult as Q, type RespondOptions as R, type SayOptions as S, type SpeechTarget as T, type StateChangeEvent as U, type TextSession as V, type TextTranscriptResult as W, type TtsVoiceConfig as X, type TurnEvent as Y, type Unsubscribe as Z, type UserInputEvent as _, AgentStatus as a, applySpeechTurnHandling as a0, dtmfCodeToDigit as a1, dtmfDigitToCode as a2, duck as a3, mute as a4, normalizeState as a5, passthrough as a6, runTextSession as a7, runTextTranscript as a8, transform as a9, type GraphTraceEvent as aa, AgentEnvironment as b, type AgentContext as c, type Participant as d, type AgentTurnEvent as e, type AudioProfile as f, type AudioSurface as g, type ChannelKind as h, type DtmfHandler as i, type EndCallOutcome as j, type FloorControlConfig as k, type MetricsEvent as l, ParticipantId as m, type ParticipantKind as n, type ParticipantSet as o, type ProcessSnapshot as p, type Room as q, type RouteEntry as r, type RoutingRule as s, type RoutingSnapshot as t, type RunTextSessionOptions as u, type RunTextTranscriptOptions as v, type SendDtmfOptions as w, type SessionAdapter as x, type SessionCapabilities as y, type SessionErrorEvent as z };
2085
+ export { type UserStateEvent as $, AgentDTO as A, type SessionEvent as B, type CallInfo as C, type DtmfEvent as D, type EndCallControllerHandle as E, type FakeSessionAdapter as F, type SessionEventMap as G, type SessionFactory as H, type InboundOptions as I, type SessionFactoryInput as J, type SessionOutbound as K, LK_AGENT_STATE_MAP as L, type MemoryHandle as M, NON_BUSY_STATES as N, type SessionState as O, type Participant as P, type SpeechResult as Q, type RespondOptions as R, type SayOptions as S, type SpeechTarget as T, type StateChangeEvent as U, type TextSession as V, type TextTranscriptResult as W, type TtsVoiceConfig as X, type TurnEvent as Y, type Unsubscribe as Z, type UserInputEvent as _, AgentStatus as a, type UserTurn as a0, applySpeechTurnHandling as a1, dtmfCodeToDigit as a2, dtmfDigitToCode as a3, duck as a4, mute as a5, normalizeState as a6, passthrough as a7, runTextSession as a8, runTextTranscript as a9, transform as aa, type GraphTraceEvent as ab, type LiveTextConversation as ac, type LiveTurnResult as ad, type RunLiveTextOptions as ae, runLiveTextConversation as af, runWithOpenAIScope as ag, AgentEnvironment as b, type AgentContext as c, ProcessSchemaDTO as d, type AgentTurnEvent as e, type AudioProfile as f, type AudioSurface as g, type ChannelKind as h, type DtmfHandler as i, type EndCallOutcome as j, type FloorControlConfig as k, type MetricsEvent as l, ParticipantId as m, type ParticipantKind as n, type ParticipantSet as o, type ProcessSnapshot as p, type Room as q, type RouteEntry as r, type RoutingRule as s, type RoutingSnapshot as t, type RunTextSessionOptions as u, type RunTextTranscriptOptions as v, type SendDtmfOptions as w, type SessionAdapter as x, type SessionCapabilities as y, type SessionErrorEvent as z };