@voicelayer/sdk 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,88 +1,8 @@
1
1
  import { z, ZodType } from 'zod';
2
- import { JobContext, voice } from '@livekit/agents';
3
-
4
- declare const brand: unique symbol;
5
- type Brand<T, B> = T & {
6
- readonly [brand]: B;
7
- };
8
- type TenantId = Brand<string, 'TenantId'>;
9
- declare const TenantId: (s: string) => TenantId;
10
- type CallId = Brand<string, 'CallId'>;
11
- declare const CallId: (s: string) => CallId;
12
- type ModuleId = Brand<string, 'ModuleId'>;
13
- declare const ModuleId: (s: string) => ModuleId;
14
-
15
- declare const participantBrand: unique symbol;
16
- type ParticipantId = string & {
17
- readonly [participantBrand]: 'ParticipantId';
18
- };
19
- declare const ParticipantId: (s: string) => ParticipantId;
20
- /**
21
- * How this participant is connected to the room. Determines which transport
22
- * adapter owns the underlying media track.
23
- * - `sip` — PSTN-side via LiveKit SIP (Twilio/Telnyx trunk)
24
- * - `webrtc` — browser/native WebRTC peer
25
- * - `agent` — the AI agent itself (server-published track)
26
- * - `bridge` — incoming non-WebRTC ingress (e.g. an Egress recorder)
27
- */
28
- type ParticipantKind = 'sip' | 'webrtc' | 'agent' | 'bridge';
29
- /**
30
- * One participant in a room. Snapshot semantics: callers read from
31
- * `ParticipantSet`, which owns lifecycle. Fields are readonly because
32
- * mutations must go through the routing primitive to stay observable.
33
- */
34
- interface Participant {
35
- readonly id: ParticipantId;
36
- readonly kind: ParticipantKind;
37
- /** True iff `kind === 'agent'`. Convenience for filtering. */
38
- readonly isAgent: boolean;
39
- /** E.164 when known (always for SIP, never for agent, sometimes for WebRTC). */
40
- readonly phone: string | null;
41
- /** Human-readable label (caller name, agent name). */
42
- readonly displayName: string | null;
43
- /**
44
- * Free-form attributes attached by the dispatcher or runtime. Standardised
45
- * keys the platform reads:
46
- * - `lang` — BCP-47 (e.g. `en-US`, `es-MX`). Used by audio-experience.
47
- * - `role` — e.g. `claimant`, `witness`, `interpreter`. Used by handoff.
48
- * - `tier` — e.g. `vip`, `standard`. Used by audio-experience.
49
- */
50
- readonly attributes: Readonly<Record<string, string>>;
51
- readonly joinedAt: Date;
52
- /** Set when the participant has left. Stays in the set until call end. */
53
- readonly leftAt: Date | null;
54
- }
55
- /**
56
- * Live view of room participants. The agent-worker owns the underlying
57
- * collection; primitives consume it read-only. Snapshot semantics: methods
58
- * return arrays/values valid at call time. The set itself updates in place
59
- * as participants join/leave — re-call to see new state.
60
- */
61
- interface ParticipantSet {
62
- /** All participants ever in the room, including those who have left. */
63
- readonly all: readonly Participant[];
64
- /** Currently-connected, non-agent participants. */
65
- readonly humans: readonly Participant[];
66
- /** Currently-connected agents. Usually exactly one. */
67
- readonly agents: readonly Participant[];
68
- readonly size: number;
69
- get(id: ParticipantId): Participant | undefined;
70
- where(pred: (p: Participant) => boolean): readonly Participant[];
71
- }
72
- /**
73
- * The call container. One Room per call. Replaces the singular call+caller
74
- * model for multi-participant primitives; existing single-caller primitives
75
- * keep reading CallContext.callerId until migrated.
76
- */
77
- interface Room {
78
- readonly id: CallId;
79
- readonly tenantId: TenantId;
80
- readonly moduleId: ModuleId;
81
- readonly startedAt: Date;
82
- readonly participants: ParticipantSet;
83
- /** Dispatch metadata (LK job metadata) — projectId, agentId, etc. */
84
- readonly metadata: Readonly<Record<string, unknown>>;
85
- }
2
+ import { A as AgentContext, P as Participant, C as CallInfo } from './text-session-B8-jhQzv.js';
3
+ export { a as AgentTurnEvent, b as AudioProfile, c as AudioSurface, d as ChannelKind, D as DtmfEvent, e as DtmfHandler, E as EndCallControllerHandle, f as EndCallOutcome, F as FakeSessionAdapter, g as FloorControlConfig, I as InboundOptions, L as LK_AGENT_STATE_MAP, M as MemoryHandle, h as MetricsEvent, N as NON_BUSY_STATES, i as ParticipantId, j as ParticipantKind, k as ParticipantSet, l as ProcessSnapshot, R as RespondOptions, m as Room, n as RouteEntry, o as RoutingRule, p as RoutingSnapshot, q as RunTextSessionOptions, r as RunTextTranscriptOptions, S as SayOptions, s as SendDtmfOptions, t as SessionAdapter, u as SessionCapabilities, v as SessionErrorEvent, w as SessionEvent, x as SessionEventMap, y as SessionFactory, z as SessionFactoryInput, B as SessionOutbound, G as SessionState, H as SpeechResult, J as SpeechTarget, K as StateChangeEvent, T as TextSession, O as TextTranscriptResult, Q as TtsVoiceConfig, U as TurnEvent, V as Unsubscribe, W as UserInputEvent, X as UserTurn, Y as applySpeechTurnHandling, Z as dtmfCodeToDigit, _ as dtmfDigitToCode, $ as duck, a0 as mute, a1 as normalizeState, i as participantId, a2 as passthrough, a3 as runTextSession, a4 as runTextTranscript, a5 as transform } from './text-session-B8-jhQzv.js';
4
+ import { llm } from '@livekit/agents';
5
+ import { Redis } from 'ioredis';
86
6
 
87
7
  declare const AgentEnvironment: z.ZodEnum<["dev", "stg", "prd"]>;
88
8
  type AgentEnvironment = z.infer<typeof AgentEnvironment>;
@@ -226,7 +146,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
226
146
  entry: z.ZodArray<z.ZodString, "many">;
227
147
  nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
228
148
  id: z.ZodString;
229
- type: z.ZodEnum<["start", "say", "ask", "confirm", "tool", "decision", "handoff", "end", "trigger", "gate", "playbook", "route", "menu", "code", "set", "subflow", "llm", "rag", "memory", "classify", "router", "note"]>;
149
+ type: z.ZodEnum<["start", "say", "ask", "confirm", "tool", "decision", "handoff", "end", "trigger", "gate", "playbook", "menu", "code", "set", "subflow", "llm", "rag", "memory", "classify", "router", "note"]>;
230
150
  config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
231
151
  out: z.ZodArray<z.ZodObject<{
232
152
  to: z.ZodString;
@@ -245,7 +165,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
245
165
  condition?: string | undefined;
246
166
  }>, "many">;
247
167
  }, "strip", z.ZodTypeAny, {
248
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
168
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
249
169
  id: string;
250
170
  config: Record<string, unknown>;
251
171
  out: {
@@ -255,7 +175,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
255
175
  condition?: string | undefined;
256
176
  }[];
257
177
  }, {
258
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
178
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
259
179
  id: string;
260
180
  config: Record<string, unknown>;
261
181
  out: {
@@ -289,7 +209,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
289
209
  v: 1;
290
210
  id: string;
291
211
  nodes: Record<string, {
292
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
212
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
293
213
  id: string;
294
214
  config: Record<string, unknown>;
295
215
  out: {
@@ -312,7 +232,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
312
232
  v: 1;
313
233
  id: string;
314
234
  nodes: Record<string, {
315
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
235
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
316
236
  id: string;
317
237
  config: Record<string, unknown>;
318
238
  out: {
@@ -384,7 +304,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
384
304
  v: 1;
385
305
  id: string;
386
306
  nodes: Record<string, {
387
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
307
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
388
308
  id: string;
389
309
  config: Record<string, unknown>;
390
310
  out: {
@@ -456,7 +376,7 @@ declare const ProcessSchemaDTO: z.ZodObject<{
456
376
  v: 1;
457
377
  id: string;
458
378
  nodes: Record<string, {
459
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
379
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
460
380
  id: string;
461
381
  config: Record<string, unknown>;
462
382
  out: {
@@ -640,7 +560,7 @@ declare const AgentDTO: z.ZodObject<{
640
560
  entry: z.ZodArray<z.ZodString, "many">;
641
561
  nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
642
562
  id: z.ZodString;
643
- type: z.ZodEnum<["start", "say", "ask", "confirm", "tool", "decision", "handoff", "end", "trigger", "gate", "playbook", "route", "menu", "code", "set", "subflow", "llm", "rag", "memory", "classify", "router", "note"]>;
563
+ type: z.ZodEnum<["start", "say", "ask", "confirm", "tool", "decision", "handoff", "end", "trigger", "gate", "playbook", "menu", "code", "set", "subflow", "llm", "rag", "memory", "classify", "router", "note"]>;
644
564
  config: z.ZodRecord<z.ZodString, z.ZodUnknown>;
645
565
  out: z.ZodArray<z.ZodObject<{
646
566
  to: z.ZodString;
@@ -659,7 +579,7 @@ declare const AgentDTO: z.ZodObject<{
659
579
  condition?: string | undefined;
660
580
  }>, "many">;
661
581
  }, "strip", z.ZodTypeAny, {
662
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
582
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
663
583
  id: string;
664
584
  config: Record<string, unknown>;
665
585
  out: {
@@ -669,7 +589,7 @@ declare const AgentDTO: z.ZodObject<{
669
589
  condition?: string | undefined;
670
590
  }[];
671
591
  }, {
672
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
592
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
673
593
  id: string;
674
594
  config: Record<string, unknown>;
675
595
  out: {
@@ -703,7 +623,7 @@ declare const AgentDTO: z.ZodObject<{
703
623
  v: 1;
704
624
  id: string;
705
625
  nodes: Record<string, {
706
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
626
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
707
627
  id: string;
708
628
  config: Record<string, unknown>;
709
629
  out: {
@@ -726,7 +646,7 @@ declare const AgentDTO: z.ZodObject<{
726
646
  v: 1;
727
647
  id: string;
728
648
  nodes: Record<string, {
729
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
649
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
730
650
  id: string;
731
651
  config: Record<string, unknown>;
732
652
  out: {
@@ -798,7 +718,7 @@ declare const AgentDTO: z.ZodObject<{
798
718
  v: 1;
799
719
  id: string;
800
720
  nodes: Record<string, {
801
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
721
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
802
722
  id: string;
803
723
  config: Record<string, unknown>;
804
724
  out: {
@@ -870,7 +790,7 @@ declare const AgentDTO: z.ZodObject<{
870
790
  v: 1;
871
791
  id: string;
872
792
  nodes: Record<string, {
873
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
793
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
874
794
  id: string;
875
795
  config: Record<string, unknown>;
876
796
  out: {
@@ -963,7 +883,7 @@ declare const AgentDTO: z.ZodObject<{
963
883
  v: 1;
964
884
  id: string;
965
885
  nodes: Record<string, {
966
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
886
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
967
887
  id: string;
968
888
  config: Record<string, unknown>;
969
889
  out: {
@@ -1054,7 +974,7 @@ declare const AgentDTO: z.ZodObject<{
1054
974
  v: 1;
1055
975
  id: string;
1056
976
  nodes: Record<string, {
1057
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
977
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
1058
978
  id: string;
1059
979
  config: Record<string, unknown>;
1060
980
  out: {
@@ -1101,7 +1021,7 @@ declare const CallPlan: z.ZodObject<{
1101
1021
  displayName?: string | undefined;
1102
1022
  }>;
1103
1023
  draftConfig: z.ZodDefault<z.ZodObject<{
1104
- source: z.ZodOptional<z.ZodOptional<z.ZodEnum<["sdk", "flow"]>>>;
1024
+ source: z.ZodOptional<z.ZodOptional<z.ZodEnum<["sdk", "flow", "playbook", "connector"]>>>;
1105
1025
  name: z.ZodOptional<z.ZodString>;
1106
1026
  triggers: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
1107
1027
  on: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
@@ -1400,6 +1320,7 @@ declare const CallPlan: z.ZodObject<{
1400
1320
  completeWhen?: "all-required-captured" | "all-captured" | undefined;
1401
1321
  }>>>;
1402
1322
  tags: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
1323
+ brainConnectorId: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
1403
1324
  modeLocked: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
1404
1325
  requiredInfo: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
1405
1326
  name: z.ZodString;
@@ -1421,7 +1342,7 @@ declare const CallPlan: z.ZodObject<{
1421
1342
  description?: string | undefined;
1422
1343
  }>, "many">>>;
1423
1344
  }, "strip", z.ZodTypeAny, {
1424
- source?: "sdk" | "flow" | undefined;
1345
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
1425
1346
  name?: string | undefined;
1426
1347
  triggers?: Record<string, {
1427
1348
  then: {
@@ -1510,6 +1431,7 @@ declare const CallPlan: z.ZodObject<{
1510
1431
  } | undefined;
1511
1432
  } | undefined;
1512
1433
  tags?: string[] | undefined;
1434
+ brainConnectorId?: string | null | undefined;
1513
1435
  modeLocked?: boolean | undefined;
1514
1436
  requiredInfo?: {
1515
1437
  type: "string" | "number" | "boolean" | "string[]" | "datetime" | "email" | "phone";
@@ -1519,7 +1441,7 @@ declare const CallPlan: z.ZodObject<{
1519
1441
  description?: string | undefined;
1520
1442
  }[] | undefined;
1521
1443
  }, {
1522
- source?: "sdk" | "flow" | undefined;
1444
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
1523
1445
  name?: string | undefined;
1524
1446
  triggers?: Record<string, {
1525
1447
  then: {
@@ -1608,6 +1530,7 @@ declare const CallPlan: z.ZodObject<{
1608
1530
  completeWhen?: "all-required-captured" | "all-captured" | undefined;
1609
1531
  } | undefined;
1610
1532
  tags?: string[] | undefined;
1533
+ brainConnectorId?: string | null | undefined;
1611
1534
  modeLocked?: boolean | undefined;
1612
1535
  requiredInfo?: {
1613
1536
  type: "string" | "number" | "boolean" | "string[]" | "datetime" | "email" | "phone";
@@ -1688,7 +1611,7 @@ declare const CallPlan: z.ZodObject<{
1688
1611
  displayName?: string | undefined;
1689
1612
  };
1690
1613
  draftConfig: {
1691
- source?: "sdk" | "flow" | undefined;
1614
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
1692
1615
  name?: string | undefined;
1693
1616
  triggers?: Record<string, {
1694
1617
  then: {
@@ -1777,6 +1700,7 @@ declare const CallPlan: z.ZodObject<{
1777
1700
  } | undefined;
1778
1701
  } | undefined;
1779
1702
  tags?: string[] | undefined;
1703
+ brainConnectorId?: string | null | undefined;
1780
1704
  modeLocked?: boolean | undefined;
1781
1705
  requiredInfo?: {
1782
1706
  type: "string" | "number" | "boolean" | "string[]" | "datetime" | "email" | "phone";
@@ -1827,7 +1751,7 @@ declare const CallPlan: z.ZodObject<{
1827
1751
  secondary?: "ask_callee" | "fallback_phrase" | undefined;
1828
1752
  };
1829
1753
  draftConfig?: {
1830
- source?: "sdk" | "flow" | undefined;
1754
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
1831
1755
  name?: string | undefined;
1832
1756
  triggers?: Record<string, {
1833
1757
  then: {
@@ -1916,6 +1840,7 @@ declare const CallPlan: z.ZodObject<{
1916
1840
  completeWhen?: "all-required-captured" | "all-captured" | undefined;
1917
1841
  } | undefined;
1918
1842
  tags?: string[] | undefined;
1843
+ brainConnectorId?: string | null | undefined;
1919
1844
  modeLocked?: boolean | undefined;
1920
1845
  requiredInfo?: {
1921
1846
  type: "string" | "number" | "boolean" | "string[]" | "datetime" | "email" | "phone";
@@ -2375,7 +2300,8 @@ declare const AgentConfig$1: z.ZodObject<{
2375
2300
  onlyWhile?: string | undefined;
2376
2301
  }>>>;
2377
2302
  tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
2378
- source: z.ZodOptional<z.ZodEnum<["sdk", "flow"]>>;
2303
+ brainConnectorId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2304
+ source: z.ZodOptional<z.ZodEnum<["sdk", "flow", "playbook", "connector"]>>;
2379
2305
  modeLocked: z.ZodOptional<z.ZodBoolean>;
2380
2306
  requiredInfo: z.ZodDefault<z.ZodArray<z.ZodObject<{
2381
2307
  name: z.ZodString;
@@ -2444,7 +2370,7 @@ declare const AgentConfig$1: z.ZodObject<{
2444
2370
  enum?: string[] | undefined;
2445
2371
  description?: string | undefined;
2446
2372
  }[];
2447
- source?: "sdk" | "flow" | undefined;
2373
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
2448
2374
  triggers?: Record<string, {
2449
2375
  then: {
2450
2376
  kind: "handoff";
@@ -2499,6 +2425,7 @@ declare const AgentConfig$1: z.ZodObject<{
2499
2425
  } | undefined;
2500
2426
  } | undefined;
2501
2427
  tags?: string[] | undefined;
2428
+ brainConnectorId?: string | null | undefined;
2502
2429
  modeLocked?: boolean | undefined;
2503
2430
  }, {
2504
2431
  id: string;
@@ -2533,7 +2460,7 @@ declare const AgentConfig$1: z.ZodObject<{
2533
2460
  normal?: number | undefined;
2534
2461
  } | undefined;
2535
2462
  };
2536
- source?: "sdk" | "flow" | undefined;
2463
+ source?: "playbook" | "sdk" | "flow" | "connector" | undefined;
2537
2464
  triggers?: Record<string, {
2538
2465
  then: {
2539
2466
  kind: "handoff";
@@ -2594,6 +2521,7 @@ declare const AgentConfig$1: z.ZodObject<{
2594
2521
  completeWhen?: "all-required-captured" | "all-captured" | undefined;
2595
2522
  } | undefined;
2596
2523
  tags?: string[] | undefined;
2524
+ brainConnectorId?: string | null | undefined;
2597
2525
  modeLocked?: boolean | undefined;
2598
2526
  requiredInfo?: {
2599
2527
  type: "string" | "number" | "boolean" | "string[]" | "datetime" | "email" | "phone";
@@ -2605,6 +2533,96 @@ declare const AgentConfig$1: z.ZodObject<{
2605
2533
  }>;
2606
2534
  type AgentConfig$1 = z.infer<typeof AgentConfig$1>;
2607
2535
 
2536
+ /** Frames a daemon sends up to the relay. */
2537
+ declare const ConnectorUpFrame: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
2538
+ kind: z.ZodLiteral<"hello">;
2539
+ token: z.ZodString;
2540
+ replicaId: z.ZodString;
2541
+ version: z.ZodString;
2542
+ caps: z.ZodObject<{
2543
+ streaming: z.ZodBoolean;
2544
+ tools: z.ZodBoolean;
2545
+ litellm: z.ZodBoolean;
2546
+ }, "strip", z.ZodTypeAny, {
2547
+ tools: boolean;
2548
+ streaming: boolean;
2549
+ litellm: boolean;
2550
+ }, {
2551
+ tools: boolean;
2552
+ streaming: boolean;
2553
+ litellm: boolean;
2554
+ }>;
2555
+ }, "strip", z.ZodTypeAny, {
2556
+ kind: "hello";
2557
+ version: string;
2558
+ token: string;
2559
+ replicaId: string;
2560
+ caps: {
2561
+ tools: boolean;
2562
+ streaming: boolean;
2563
+ litellm: boolean;
2564
+ };
2565
+ }, {
2566
+ kind: "hello";
2567
+ version: string;
2568
+ token: string;
2569
+ replicaId: string;
2570
+ caps: {
2571
+ tools: boolean;
2572
+ streaming: boolean;
2573
+ litellm: boolean;
2574
+ };
2575
+ }>, z.ZodObject<{
2576
+ kind: z.ZodLiteral<"pong">;
2577
+ ts: z.ZodNumber;
2578
+ }, "strip", z.ZodTypeAny, {
2579
+ kind: "pong";
2580
+ ts: number;
2581
+ }, {
2582
+ kind: "pong";
2583
+ ts: number;
2584
+ }>, z.ZodObject<{
2585
+ kind: z.ZodLiteral<"brain.delta">;
2586
+ streamId: z.ZodString;
2587
+ content: z.ZodString;
2588
+ }, "strip", z.ZodTypeAny, {
2589
+ kind: "brain.delta";
2590
+ content: string;
2591
+ streamId: string;
2592
+ }, {
2593
+ kind: "brain.delta";
2594
+ content: string;
2595
+ streamId: string;
2596
+ }>, z.ZodObject<{
2597
+ kind: z.ZodLiteral<"brain.done">;
2598
+ streamId: z.ZodString;
2599
+ finishReason: z.ZodString;
2600
+ }, "strip", z.ZodTypeAny, {
2601
+ kind: "brain.done";
2602
+ streamId: string;
2603
+ finishReason: string;
2604
+ }, {
2605
+ kind: "brain.done";
2606
+ streamId: string;
2607
+ finishReason: string;
2608
+ }>, z.ZodObject<{
2609
+ kind: z.ZodLiteral<"brain.error">;
2610
+ streamId: z.ZodString;
2611
+ code: z.ZodEnum<["upstream_timeout", "upstream_error", "bad_response", "normalize_failed", "unreachable"]>;
2612
+ message: z.ZodString;
2613
+ }, "strip", z.ZodTypeAny, {
2614
+ message: string;
2615
+ kind: "brain.error";
2616
+ code: "upstream_timeout" | "upstream_error" | "bad_response" | "normalize_failed" | "unreachable";
2617
+ streamId: string;
2618
+ }, {
2619
+ message: string;
2620
+ kind: "brain.error";
2621
+ code: "upstream_timeout" | "upstream_error" | "bad_response" | "normalize_failed" | "unreachable";
2622
+ streamId: string;
2623
+ }>]>;
2624
+ type ConnectorUpFrame = z.infer<typeof ConnectorUpFrame>;
2625
+
2608
2626
  interface TransportOptions {
2609
2627
  readonly apiKey: string;
2610
2628
  readonly baseUrl: string;
@@ -2907,7 +2925,7 @@ declare class AgentsClient {
2907
2925
  v: 1;
2908
2926
  id: string;
2909
2927
  nodes: Record<string, {
2910
- type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "route" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
2928
+ type: "code" | "start" | "say" | "ask" | "confirm" | "tool" | "decision" | "handoff" | "end" | "trigger" | "gate" | "playbook" | "menu" | "set" | "subflow" | "llm" | "rag" | "memory" | "classify" | "router" | "note";
2911
2929
  id: string;
2912
2930
  config: Record<string, unknown>;
2913
2931
  out: {
@@ -2988,6 +3006,23 @@ interface CallSummary {
2988
3006
  readonly status: CallStatus;
2989
3007
  readonly startedAt: string;
2990
3008
  }
3009
+ interface CallUsageReport {
3010
+ readonly durationMs: number;
3011
+ readonly llm: readonly {
3012
+ readonly provider: string;
3013
+ readonly model: string;
3014
+ readonly inputTokens: number;
3015
+ readonly outputTokens: number;
3016
+ }[];
3017
+ readonly tts: readonly {
3018
+ readonly provider: string;
3019
+ readonly chars: number;
3020
+ }[];
3021
+ readonly stt: readonly {
3022
+ readonly provider: string;
3023
+ readonly seconds: number;
3024
+ }[];
3025
+ }
2991
3026
  interface AppendTranscriptInput {
2992
3027
  readonly speaker: 'caller' | 'agent';
2993
3028
  readonly text: string;
@@ -3049,6 +3084,7 @@ declare class CallsClient {
3049
3084
  ensureByRoom(input: EnsureCallByRoomInput): Promise<CallSummary>;
3050
3085
  syncState(callId: string, input: SyncCallStateInput): Promise<void>;
3051
3086
  appendTranscriptSegment(callId: string, input: AppendTranscriptInput): Promise<void>;
3087
+ reportUsage(callId: string, report: CallUsageReport): Promise<void>;
3052
3088
  appendDtmfEvent(callId: string, input: AppendDtmfEventInput): Promise<void>;
3053
3089
  /**
3054
3090
  * Append a structured call event. Today the API accepts consultation
@@ -3169,521 +3205,127 @@ declare const ProviderCredential: z.ZodObject<{
3169
3205
  baseUrl?: string | undefined;
3170
3206
  }>;
3171
3207
  type ProviderCredential = z.infer<typeof ProviderCredential>;
3208
+ declare const BrainConnectorConfig: z.ZodObject<{
3209
+ connector: z.ZodObject<{
3210
+ id: z.ZodString;
3211
+ mode: z.ZodEnum<["tunnel", "direct"]>;
3212
+ connectionId: z.ZodNullable<z.ZodString>;
3213
+ defaultModel: z.ZodNullable<z.ZodString>;
3214
+ normalize: z.ZodEnum<["auto", "on", "off"]>;
3215
+ enabled: z.ZodBoolean;
3216
+ credential: z.ZodOptional<z.ZodNullable<z.ZodObject<{
3217
+ apiKey: z.ZodString;
3218
+ baseUrl: z.ZodString;
3219
+ }, "strip", z.ZodTypeAny, {
3220
+ apiKey: string;
3221
+ baseUrl: string;
3222
+ }, {
3223
+ apiKey: string;
3224
+ baseUrl: string;
3225
+ }>>>;
3226
+ }, "strip", z.ZodTypeAny, {
3227
+ id: string;
3228
+ enabled: boolean;
3229
+ mode: "tunnel" | "direct";
3230
+ defaultModel: string | null;
3231
+ connectionId: string | null;
3232
+ normalize: "on" | "off" | "auto";
3233
+ credential?: {
3234
+ apiKey: string;
3235
+ baseUrl: string;
3236
+ } | null | undefined;
3237
+ }, {
3238
+ id: string;
3239
+ enabled: boolean;
3240
+ mode: "tunnel" | "direct";
3241
+ defaultModel: string | null;
3242
+ connectionId: string | null;
3243
+ normalize: "on" | "off" | "auto";
3244
+ credential?: {
3245
+ apiKey: string;
3246
+ baseUrl: string;
3247
+ } | null | undefined;
3248
+ }>;
3249
+ }, "strip", z.ZodTypeAny, {
3250
+ connector: {
3251
+ id: string;
3252
+ enabled: boolean;
3253
+ mode: "tunnel" | "direct";
3254
+ defaultModel: string | null;
3255
+ connectionId: string | null;
3256
+ normalize: "on" | "off" | "auto";
3257
+ credential?: {
3258
+ apiKey: string;
3259
+ baseUrl: string;
3260
+ } | null | undefined;
3261
+ };
3262
+ }, {
3263
+ connector: {
3264
+ id: string;
3265
+ enabled: boolean;
3266
+ mode: "tunnel" | "direct";
3267
+ defaultModel: string | null;
3268
+ connectionId: string | null;
3269
+ normalize: "on" | "off" | "auto";
3270
+ credential?: {
3271
+ apiKey: string;
3272
+ baseUrl: string;
3273
+ } | null | undefined;
3274
+ };
3275
+ }>;
3276
+ type BrainConnectorConfig = z.infer<typeof BrainConnectorConfig>['connector'];
3172
3277
  declare class ConnectionsClient {
3173
3278
  private readonly transport;
3174
3279
  constructor(transport: Transport);
3175
3280
  resolveProviderCredential(provider: string): Promise<ProviderCredential | null>;
3281
+ resolveBrainConnectorConfig(id: string): Promise<BrainConnectorConfig | null>;
3176
3282
  }
3177
3283
 
3178
- type SessionState = 'initializing' | 'idle' | 'listening' | 'thinking' | 'speaking';
3179
- declare const LK_AGENT_STATE_MAP: Readonly<Record<string, SessionState>>;
3180
- declare const NON_BUSY_STATES: ReadonlySet<SessionState>;
3181
- /** Normalize a raw LK state string to SessionState; unknown -> 'thinking' (fail-safe). */
3182
- declare function normalizeState(raw: string): SessionState;
3183
- interface UserInputEvent {
3184
- readonly transcript: string;
3185
- readonly isFinal: boolean;
3186
- readonly speakerId: string | null;
3187
- }
3188
- interface AgentTurnEvent {
3189
- readonly text: string;
3190
- }
3191
- interface DtmfEvent$1 {
3192
- readonly digit: string;
3193
- readonly code: number;
3194
- readonly participantId: string | null;
3195
- }
3196
- interface StateChangeEvent {
3197
- readonly oldState: SessionState | null;
3198
- readonly newState: SessionState | null;
3199
- readonly rawOldState: string | null;
3200
- readonly rawNewState: string | null;
3201
- }
3202
- interface SessionErrorEvent {
3203
- readonly error: unknown;
3204
- readonly source: 'llm' | 'stt' | 'tts' | 'realtime' | 'unknown';
3205
- readonly fatalTransport: boolean;
3206
- }
3207
- interface MetricsEvent {
3208
- readonly metrics: unknown;
3209
- }
3210
- interface SessionEventMap {
3211
- user_input: UserInputEvent;
3212
- agent_turn: AgentTurnEvent;
3213
- dtmf: DtmfEvent$1;
3214
- state: StateChangeEvent;
3215
- error: SessionErrorEvent;
3216
- metrics: MetricsEvent;
3217
- close: void;
3218
- }
3219
- type SessionEvent = keyof SessionEventMap;
3220
- type Unsubscribe = () => void;
3221
- type ChannelKind = 'voice' | 'text';
3222
- interface SessionCapabilities {
3223
- readonly channel: ChannelKind;
3224
- readonly usingRealtime: boolean;
3225
- readonly hasStreamingTranscripts: boolean;
3226
- readonly canBargeIn: boolean;
3227
- readonly canReceiveDtmf: boolean;
3228
- readonly canPublishDtmf: boolean;
3229
- readonly canResolveSpeaker: boolean;
3230
- }
3231
- interface SayOptions$1 {
3232
- readonly allowInterruptions?: boolean;
3233
- readonly to?: string | readonly string[];
3234
- }
3235
- interface SpeechResult {
3236
- readonly interrupted: boolean;
3237
- }
3238
- interface EndCallOutcome {
3239
- readonly torn: 'room' | 'agent' | 'none';
3240
- readonly stranded: boolean;
3241
- }
3242
- interface SessionOutbound {
3243
- /** Speak verbatim. Under usingRealtime the LiveKit adapter routes to
3244
- * generateReply(verbatim) NOT session.say (no TTS in S2S). Resolves after
3245
- * playout (voice) or after the text turn is committed (text). */
3246
- say(text: string, opts?: SayOptions$1): Promise<SpeechResult>;
3247
- /** Ask the LLM to produce a turn. */
3248
- generateReply(opts?: {
3249
- readonly instructions?: string;
3250
- }): Promise<void>;
3251
- /** Barge-in cancel (puppet interrupt mode). text => no-op. */
3252
- interrupt(): Promise<void>;
3253
- /** Publish outbound DTMF from the agent leg. Throws if !canPublishDtmf. */
3254
- sendDtmf(code: number, digit: string): Promise<void>;
3255
- /** Hang up via the SDK end-call controller (deletes room so the SIP leg drops). */
3256
- endCall(opts?: {
3257
- readonly reason?: string;
3258
- readonly trigger?: string;
3259
- }): Promise<EndCallOutcome>;
3260
- }
3261
- type TurnEvent = {
3262
- readonly kind: 'partial';
3263
- readonly text: string;
3264
- readonly speakerId: string | null;
3265
- } | {
3266
- readonly kind: 'final';
3267
- readonly text: string;
3268
- readonly speakerId: string | null;
3269
- readonly at: Date;
3270
- } | {
3271
- readonly kind: 'dtmf';
3272
- readonly digit: string;
3273
- readonly code: number;
3274
- readonly participantId: string | null;
3275
- readonly at: Date;
3276
- } | {
3277
- readonly kind: 'hangup';
3278
- } | {
3279
- readonly kind: 'timeout';
3280
- };
3281
- interface InboundOptions {
3282
- readonly idleTimeoutMs?: number;
3283
- readonly finalsOnly?: boolean;
3284
- }
3285
- interface SessionAdapter extends SessionOutbound {
3286
- readonly capabilities: SessionCapabilities;
3287
- on<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
3288
- once<E extends SessionEvent>(event: E, handler: (payload: SessionEventMap[E]) => void): Unsubscribe;
3289
- /** Graph read side. ONE underlying subscription. Mutually exclusive with the
3290
- * flat on('user_input') consumer (THROWS if both active). The iterator's
3291
- * return()/finally MUST unsubscribe. */
3292
- inbound(opts?: InboundOptions): AsyncIterableIterator<TurnEvent>;
3293
- /** Begin the session (was session.start + waitForSessionActivity). The LiveKit
3294
- * impl preserves the activity sequence VERBATIM so a provider/LLM init failure
3295
- * REJECTS rather than producing a silently-dead answered call. */
3296
- start(opts?: {
3297
- readonly agent?: unknown;
3298
- readonly room?: unknown;
3299
- }): Promise<void>;
3300
- readonly state: SessionState;
3301
- /** Resolve when idle/listening, on timeout, or on close. Synchronous fast-path:
3302
- * if already non-busy, resolves 'idle' in the same microtask. */
3303
- waitForIdle(timeoutMs: number): Promise<'idle' | 'timeout' | 'closed'>;
3304
- waitForClose(): Promise<void>;
3305
- /** Escape hatch for genuinely LK-coupled sites. undefined on the text adapter. */
3306
- readonly raw?: {
3307
- readonly job: JobContext;
3308
- readonly session: unknown;
3309
- readonly room: unknown;
3310
- };
3311
- dispose(): void;
3312
- }
3313
- interface EndCallControllerHandle {
3314
- hangUp(o: {
3315
- readonly trigger: string;
3316
- readonly reason?: string;
3317
- }): Promise<EndCallOutcome>;
3318
- armIdle(): void;
3319
- cancelIdle(): void;
3320
- noteEngineClosed(): void;
3321
- }
3322
- interface SessionFactoryInput {
3323
- readonly usingRealtime: boolean;
3324
- readonly graphMode: boolean;
3325
- readonly puppetMode: boolean;
3326
- readonly hostControlled: boolean;
3327
- readonly captureDtmf: boolean;
3328
- readonly pipeline?: {
3329
- readonly stt?: unknown;
3330
- readonly tts?: unknown;
3331
- readonly vad?: unknown;
3332
- readonly llm: unknown;
3333
- };
3334
- readonly turnHandling?: Record<string, unknown>;
3335
- readonly resolveSpeaker?: (speakerId: string | null) => {
3336
- readonly id: string | null;
3337
- readonly label: string;
3338
- };
3339
- readonly classifyEngineClosed?: (err: unknown) => boolean;
3340
- readonly endCallController?: EndCallControllerHandle;
3341
- }
3342
- type SessionFactory = (input: SessionFactoryInput) => Promise<SessionAdapter>;
3343
- interface UserTurn {
3344
- readonly text: string;
3345
- readonly speakerLabel: string;
3346
- readonly speakerId: string | null;
3347
- readonly at: Date;
3348
- }
3349
- interface FakeSessionAdapter extends SessionAdapter {
3350
- emitUserInput(e: UserInputEvent): void;
3351
- emitAgentTurn(text: string): void;
3352
- emitDtmf(digit: string): void;
3353
- /** Drives 'state' with correct oldState/rawOldState AND runs the SAME
3354
- * arm/cancel + idle-release as production. Unknown string => 'thinking'. */
3355
- setState(next: SessionState | string): void;
3356
- emitError(error: unknown, fatalTransport?: boolean): void;
3357
- emitClose(): void;
3358
- readonly spoken: ReadonlyArray<string>;
3359
- readonly generatedReplies: ReadonlyArray<string | undefined>;
3360
- readonly sentDtmf: ReadonlyArray<string>;
3361
- readonly endCalls: ReadonlyArray<{
3362
- readonly reason?: string;
3363
- readonly trigger?: string;
3364
- }>;
3365
- }
3366
-
3367
- interface DefaultMetadata {
3368
- readonly hostname: string;
3369
- readonly platform: NodeJS.Platform;
3370
- readonly arch: string;
3371
- readonly nodeVersion: string;
3372
- readonly pid: number;
3373
- /** From BUILD_SHA / GIT_COMMIT / VERCEL_GIT_COMMIT_SHA, or null. */
3374
- readonly buildSha: string | null;
3375
- readonly startedAt: string;
3376
- }
3377
- declare function collectDefaultMetadata(): DefaultMetadata;
3378
- /**
3379
- * Merge default metadata with user-supplied metadata. User values win on
3380
- * conflict; defaults fill in the rest. Returns a plain object suitable for
3381
- * the registry's metadata field.
3382
- */
3383
- declare function mergeMetadata(user: Record<string, unknown> | undefined, defaults: DefaultMetadata): Record<string, unknown>;
3384
-
3385
- interface TtsVoiceConfig {
3386
- readonly provider: 'deepgram' | 'openai' | 'elevenlabs' | 'cartesia';
3387
- readonly model: string;
3388
- readonly voice?: string;
3389
- readonly instructions?: string;
3390
- }
3391
- interface AudioProfile {
3392
- readonly holdMusicUrl: string;
3393
- readonly duckingDb: number;
3394
- readonly dtmfFallbackThreshold: number;
3395
- readonly languageHint: string;
3396
- readonly tts: TtsVoiceConfig;
3284
+ interface BrainMessage {
3285
+ readonly role: 'system' | 'user' | 'assistant';
3286
+ readonly content: string;
3397
3287
  }
3398
-
3399
- type RoutingRule = {
3400
- readonly kind: 'passthrough';
3401
- } | {
3402
- readonly kind: 'mute';
3403
- } | {
3404
- readonly kind: 'duck';
3405
- readonly db: number;
3406
- } | {
3407
- readonly kind: 'transform';
3408
- readonly id: string;
3409
- };
3410
- declare const passthrough: () => RoutingRule;
3411
- declare const mute: () => RoutingRule;
3412
- declare const duck: (db: number) => RoutingRule;
3413
- declare const transform: (id: string) => RoutingRule;
3414
- interface RouteEntry {
3415
- readonly source: ParticipantId;
3416
- readonly destination: ParticipantId;
3417
- readonly rule: RoutingRule;
3418
- }
3419
- interface FloorControlConfig {
3420
- /**
3421
- * Minimum quiet window (ms) after the last human utterance before the
3422
- * agent is allowed to speak. Prevents the agent from talking over a
3423
- * human who hasn't yielded the floor. Default 400ms.
3424
- */
3425
- readonly humanQuietWindowMs: number;
3426
- /**
3427
- * If true, the agent may speak immediately at call start before any
3428
- * human has spoken (the greeting). Default true.
3429
- */
3430
- readonly allowAgentGreeting: boolean;
3431
- }
3432
- interface RoutingSnapshot {
3433
- readonly entries: readonly RouteEntry[];
3434
- readonly lastSpokeAt: ReadonlyMap<ParticipantId, number>;
3435
- }
3436
-
3437
- interface CallInfo {
3438
- /** Stable id for the call; comes from dispatch metadata or room name. */
3439
- readonly callId: string;
3440
- /** Caller phone number (E.164) when available, else participant identity. */
3441
- readonly callerId: string;
3442
- /** Phone number that was called (E.164) when available. */
3443
- readonly to: string | null;
3444
- /** Wall-clock when the agent joined. */
3445
- readonly startedAt: Date;
3446
- /** Free-form metadata from the dispatch rule (e.g. projectId, agentId). */
3447
- readonly metadata: Record<string, unknown>;
3448
- }
3449
- interface MemoryHandle {
3450
- get(key: string): Promise<unknown>;
3451
- set(key: string, value: unknown): Promise<void>;
3452
- }
3453
- interface ProcessSnapshot {
3454
- /** Captured field values. */
3455
- readonly data: Record<string, unknown>;
3456
- /** True once the process completion gate has fired. */
3457
- readonly complete: boolean;
3458
- }
3459
- /**
3460
- * Input to ctx.recordEvent — id and timestamp are stamped by the runtime so
3461
- * callers only supply the semantic fields. `source` defaults to 'agent' for
3462
- * tool-call events; pass 'form'/'platform'/'caller' when emitting from a
3463
- * different surface (form-page bridge, webhook handler).
3464
- */
3465
- interface RecordEventInput {
3466
- readonly kind: string;
3467
- readonly source?: 'agent' | 'caller' | 'form' | 'platform';
3468
- readonly data?: Record<string, unknown>;
3469
- }
3470
- /**
3471
- * Targets for participant-scoped speech operations. Either a raw
3472
- * `ParticipantId`, a `Participant` snapshot, or an array of either.
3473
- * `'broadcast'` is the explicit form of the default — everyone in the room.
3474
- */
3475
- type SpeechTarget = ParticipantId | Participant | readonly (ParticipantId | Participant)[] | 'broadcast';
3476
- /**
3477
- * Audio surface — per-participant profiles, routing matrix, and floor
3478
- * control. Exposed on `ctx.audio` so user hooks (e.g. translation in
3479
- * onUtterance) can drive the underlying primitives without importing
3480
- * them directly.
3481
- *
3482
- * In PR#4 these are wired to live LK participant events but the audio
3483
- * fanout itself (per-participant STT, per-listener TTS) is still single-
3484
- * pipeline; users that need actual per-listener delivery should go
3485
- * through `ctx.livekit` for now.
3486
- */
3487
- interface AudioSurface {
3488
- /** Profile (voice/lang/DTMF) for one participant. */
3489
- profileFor(participantId: ParticipantId): AudioProfile;
3490
- /** Update one participant's language hint (also swaps TTS voice). */
3491
- setLanguage(participantId: ParticipantId, languageHint: string): AudioProfile;
3492
- /** Current routing matrix snapshot. */
3493
- routes(): RoutingSnapshot;
3494
- /** Override a single (source, destination) edge in the routing matrix. */
3495
- setRoute(source: ParticipantId, destination: ParticipantId, rule: RoutingRule): void;
3496
- /** Floor-control: true iff no human has spoken inside the quiet window. */
3497
- canAgentSpeak(): boolean;
3288
+ interface BrainCallMetadata {
3289
+ readonly channel: 'voice' | 'text';
3290
+ readonly callId?: string;
3291
+ readonly projectId?: string;
3498
3292
  }
3499
- interface SayOptions {
3500
- /** Restrict the spoken track to one or more participants. Default: broadcast. */
3501
- readonly to?: SpeechTarget;
3293
+ interface BrainRequest {
3294
+ readonly messages: readonly BrainMessage[];
3295
+ /** Upstream model id / alias. Omitted → the brain's own default. */
3296
+ readonly model?: string;
3297
+ readonly temperature?: number;
3298
+ readonly metadata: BrainCallMetadata;
3502
3299
  }
3503
- /**
3504
- * A DTMF keypress received from a participant. `code` is the RFC 4733 event
3505
- * code (0–15: digits 0–9, *=10, #=11, A–D=12–15); `digit` is the canonical
3506
- * single-character representation. `participantId` identifies the sender in
3507
- * the synthesized room (matches Room.participants).
3508
- */
3509
- interface DtmfEvent {
3510
- readonly participantId: ParticipantId;
3511
- readonly code: number;
3512
- readonly digit: string;
3513
- readonly at: Date;
3300
+ /** One streamed piece of the brain's reply. */
3301
+ interface BrainChunk {
3302
+ readonly content?: string;
3514
3303
  }
3515
- /** Handler signature for ctx.onDtmf. Returning false unsubscribes. */
3516
- type DtmfHandler = (event: DtmfEvent) => void | Promise<void>;
3517
- interface SendDtmfOptions {
3518
- /** Milliseconds between consecutive digits. Default 100. */
3519
- readonly delayMs?: number;
3304
+ interface BrainCapabilities {
3305
+ readonly reachable: boolean;
3306
+ readonly streaming: boolean;
3520
3307
  }
3521
- interface RespondOptions {
3522
- readonly instructions?: string;
3523
- readonly to?: SpeechTarget;
3308
+ interface BrainTransport {
3309
+ readonly kind: 'callback' | 'http' | 'tunnel';
3310
+ /** Stream the reply token-by-token (the voice path: first sentence → TTS ASAP). */
3311
+ stream(req: BrainRequest, signal: AbortSignal): AsyncIterable<BrainChunk>;
3312
+ /** Non-streaming convenience (the text path). */
3313
+ complete(req: BrainRequest, signal: AbortSignal): Promise<string>;
3524
3314
  }
3525
- interface AgentContext {
3526
- readonly call: CallInfo;
3527
- readonly memory: MemoryHandle;
3528
- /** Typed connector APIs. Empty record when no connectors are configured. */
3529
- readonly connectors: Readonly<Record<string, unknown>>;
3530
- /** Read-only view of process state. Undefined when no process is configured. */
3531
- readonly process: ProcessSnapshot | undefined;
3532
- /**
3533
- * Record a side-channel lifecycle event into the process actor. Visible
3534
- * to the dashboard React Flow board in real time alongside field
3535
- * captures. Use for "this happened on the call" facts — tool calls,
3536
- * form-page activity, webhook dispatches — that aren't field captures.
3537
- * No-op when the agent has no process configured.
3538
- */
3539
- recordEvent(event: RecordEventInput): void;
3540
- /**
3541
- * Subscribe the agent to a form-page session's WS stream so values typed
3542
- * on the form-page mirror into the process actor (channel-agnostic field
3543
- * capture). Tools call this after a successful sendFormLink; the runtime
3544
- * owns the lifecycle of the underlying WebSocket.
3545
- *
3546
- * Returns a function the tool can call to tear down the subscription
3547
- * early. The subscription also self-closes on form submission or idle.
3548
- *
3549
- * No-op (returns a no-op teardown) when the agent has no process or
3550
- * VOICELAYER_API_URL is unset.
3551
- */
3552
- watchFormSession(token: string): () => void;
3553
- /** Free-form scratch space for hooks to share state within a call. */
3554
- readonly metadata: Record<string, unknown>;
3555
- /**
3556
- * Live view of the call as a participant room. Always populated — for
3557
- * 1:1 calls the room contains one human participant + the agent.
3558
- */
3559
- readonly room: Room;
3560
- /** Per-participant audio profiles + routing matrix + floor control. */
3561
- readonly audio: AudioSurface;
3562
- /**
3563
- * Speak text (via TTS). Returns when the speech is queued.
3564
- * `opts.to` selects a participant subset; default is broadcast. The
3565
- * runtime currently publishes a single shared track; targeted delivery
3566
- * lands with the per-listener track work (PR#4).
3567
- */
3568
- say(text: string, opts?: SayOptions): Promise<void>;
3569
- /** Ask the LLM to produce a reply now (optionally with extra instructions). */
3570
- respond(instructionsOrOpts?: string | RespondOptions): Promise<void>;
3571
- /** Pose a question and resolve with the caller's transcribed answer. */
3572
- ask(question: string): Promise<string>;
3573
- /** Transfer the caller to another phone number. Ends the agent's leg.
3574
- * `mode` overrides the agent-level warm/cold default for this transfer. */
3575
- handoff(to: string, opts?: {
3576
- reason?: string;
3577
- briefing?: string;
3578
- mode?: 'warm' | 'cold';
3579
- }): Promise<void>;
3580
- /**
3581
- * Hang up the call. Optionally records a reason (surfaced to logs and
3582
- * `endCall.onEnd`). Teardown is owned by the SDK end-call controller, which
3583
- * deletes the whole LiveKit room by default so the SIP/PSTN leg drops too —
3584
- * not just the agent participant.
3585
- */
3586
- endCall(opts?: {
3587
- reason?: string;
3588
- }): Promise<void>;
3589
- /**
3590
- * Subscribe to inbound DTMF keypresses from participants. Returns an
3591
- * unsubscribe function. Handlers are called once per digit in the order
3592
- * received. Errors thrown inside a handler are caught and logged so one
3593
- * bad handler can't break others.
3594
- *
3595
- * @example
3596
- * ctx.onDtmf(async (ev) => {
3597
- * if (ev.digit === '0') await ctx.handoff('+18005551212');
3598
- * });
3599
- */
3600
- onDtmf(handler: DtmfHandler): () => void;
3601
- /**
3602
- * Send DTMF digits from the agent's leg. Each character is published as
3603
- * a separate RFC 4733 event; non-DTMF characters (anything not in
3604
- * 0-9*#A-D) are dropped. `opts.delayMs` controls pacing between digits.
3605
- *
3606
- * Useful for IVR navigation post-handoff or during outbound calls.
3607
- */
3608
- sendDtmf(digits: string, opts?: SendDtmfOptions): Promise<void>;
3609
- /** Escape hatch to LiveKit primitives — use when a hook isn't enough. */
3610
- readonly livekit: {
3611
- readonly job: JobContext;
3612
- readonly session: voice.AgentSession;
3613
- };
3315
+ /** Context handed to a customer's in-process `onQuery` brain. */
3316
+ interface OnQueryContext {
3317
+ /** Full conversation so far (system + prior turns + latest user message). */
3318
+ readonly messages: readonly BrainMessage[];
3319
+ /** Aborts when the caller barges in / the turn is cancelled. */
3320
+ readonly signal: AbortSignal;
3614
3321
  }
3322
+ type OnQueryResult = string | AsyncIterable<string>;
3615
3323
  /**
3616
- * Map a single character to its RFC 4733 event code, or null when the
3617
- * character isn't a valid DTMF digit. 0–9 → 0–9, * → 10, # → 11, A–D → 12–15.
3324
+ * Bring-your-own brain, in-process. Receives the latest user utterance (and the
3325
+ * full history via `ctx.messages`) and returns the reply — either a string or an
3326
+ * async-iterable of string pieces for token streaming.
3618
3327
  */
3619
- declare function dtmfDigitToCode(digit: string): number | null;
3620
- /** Inverse of dtmfDigitToCode. Returns null for codes outside 0..15. */
3621
- declare function dtmfCodeToDigit(code: number): string | null;
3622
-
3623
- /** Primitive shorthand types accepted in tool input. Extendable. */
3624
- type ShorthandPrimitive$1 = 'string' | 'number' | 'boolean';
3625
- /** What the user passes for a tool's input shape. */
3626
- type ToolInputShape$1 = Record<string, ShorthandPrimitive$1> | z.ZodTypeAny;
3627
- interface ToolDefinition$1<I = unknown, R = unknown> {
3628
- readonly description: string;
3629
- readonly input: ToolInputShape$1;
3630
- /** Implementation. Receives parsed input and the agent context. */
3631
- readonly run: (input: I, ctx: AgentContext) => Promise<R> | R;
3632
- /** Capability required for Action Guard. Defaults to `tool.<name>`. */
3633
- readonly capability?: string;
3634
- }
3635
-
3636
- interface ResendCredentials {
3637
- /** Resend API key — find under "API Keys" in the Resend dashboard. */
3638
- readonly apiKey: string;
3639
- /**
3640
- * The verified `From:` address — must be a sender on a domain you've
3641
- * verified in Resend (Settings → Domains). Accepts plain
3642
- * "you@yourdomain.com" or "Display Name <you@yourdomain.com>" format.
3643
- */
3644
- readonly from: string;
3645
- }
3646
- interface ResendEmailToolOptions extends ResendCredentials {
3647
- /**
3648
- * Optional subject prefix prepended to every send. Useful when an agent
3649
- * should always brand its emails consistently (e.g. "[Acme Support]").
3650
- * Agents can still override the full subject per call.
3651
- */
3652
- readonly subjectPrefix?: string;
3653
- /**
3654
- * Optional canned signature appended to the plain-text body. Lets agent
3655
- * authors enforce a sign-off without prompting the LLM to remember.
3656
- */
3657
- readonly signature?: string;
3658
- }
3659
- declare function resendEmailTool(options: ResendEmailToolOptions): ToolDefinition$1;
3660
-
3661
- interface FormToolsOptions {
3662
- /**
3663
- * Optional default webhook URL to attach to every form session the agent
3664
- * creates. Customers usually want this set globally per environment.
3665
- */
3666
- readonly defaultWebhookUrl?: string;
3667
- /**
3668
- * Customer-supplied Resend credentials. When set, sendFormLink mints the
3669
- * form session via the platform (so token/state lives on the platform)
3670
- * but sends the email DIRECTLY from the agent worker using the customer's
3671
- * Resend account. The API key never leaves the customer's process; the
3672
- * platform receives a structured log event after the send instead.
3673
- *
3674
- * When omitted, sendFormLink falls back to the platform's email path
3675
- * (POST /v1/forms with `sendEmail` block), which uses VoiceLayer's
3676
- * shared Resend account.
3677
- */
3678
- readonly resend?: ResendCredentials;
3679
- }
3680
- /**
3681
- * Build the standard set of form tools, bound to a VoiceLayer client.
3682
- *
3683
- * Each entry conforms to ToolDefinition and can be spread directly into an
3684
- * agent's `tools: {}` map (see defineAgent).
3685
- */
3686
- declare function formTools(vl: VoiceLayerClient, options?: FormToolsOptions): Record<string, ToolDefinition$1>;
3328
+ type OnQuery = (text: string, ctx: OnQueryContext) => OnQueryResult | Promise<OnQueryResult>;
3687
3329
 
3688
3330
  /** Primitive field types accepted in a process definition. */
3689
3331
  type ProcessFieldType = 'string' | 'string[]' | 'number' | 'boolean' | 'datetime' | 'email' | 'phone';
@@ -3914,11 +3556,42 @@ interface OutboundCallConfig {
3914
3556
  */
3915
3557
  readonly voicemailScript?: string;
3916
3558
  }
3559
+ /**
3560
+ * Barge-in tuning. The pipeline allows interruptions by default (LK defaults:
3561
+ * any speech ≥500ms cuts the agent off). These knobs tune that behavior per
3562
+ * agent WITHOUT switching to puppet/hostControlled mode — e.g. a senior-living
3563
+ * help desk wants `minWords: 2` so backchannels ("mm-hm", "okay") don't
3564
+ * truncate the agent mid-sentence, while a fast-paced escalation desk keeps
3565
+ * the zero-word default. Set `enabled: false` to make the agent
3566
+ * non-interruptible (kiosk / broadcast announcements).
3567
+ */
3568
+ interface InterruptionConfig {
3569
+ /** Allow the caller to barge in over agent speech. Default true. */
3570
+ readonly enabled?: boolean;
3571
+ /** Words the caller must say before it counts as an interruption. Default 0
3572
+ * (any speech interrupts). 2–3 filters out backchannels. */
3573
+ readonly minWords?: number;
3574
+ /** Minimum caller speech duration (ms) to count as an interruption. Default 500. */
3575
+ readonly minDuration?: number;
3576
+ }
3577
+ /**
3578
+ * End-of-turn detection tuning: how long the pipeline waits after the caller
3579
+ * stops speaking before treating the turn as finished. Raise `minDelay` for
3580
+ * callers who pause mid-thought (e.g. elderly speakers); lower it for
3581
+ * fast-paced lines.
3582
+ */
3583
+ interface EndpointingConfig {
3584
+ /** Minimum silence (ms) before the caller's turn is considered done. Default 500. */
3585
+ readonly minDelay?: number;
3586
+ /** Hard ceiling (ms) after which the turn ends regardless. Default 3000. */
3587
+ readonly maxDelay?: number;
3588
+ }
3917
3589
  /**
3918
3590
  * Speech polish. `pronunciations` rewrites brand names / acronyms / jargon to
3919
3591
  * a spoken form before TTS (e.g. `{ VoiceLayer: 'Voice Layer', API: 'A P I' }`)
3920
3592
  * via applyPronunciations(). `backgroundAudio` plays ambient room tone under
3921
3593
  * the agent so silence feels less dead (a URL or a named preset).
3594
+ * `interruption` + `endpointing` tune barge-in and turn-taking per agent.
3922
3595
  */
3923
3596
  interface SpeechConfig {
3924
3597
  readonly pronunciations?: Readonly<Record<string, string>>;
@@ -3926,6 +3599,8 @@ interface SpeechConfig {
3926
3599
  readonly url?: string;
3927
3600
  readonly volume?: number;
3928
3601
  };
3602
+ readonly interruption?: InterruptionConfig;
3603
+ readonly endpointing?: EndpointingConfig;
3929
3604
  }
3930
3605
  /** What caused the call to end. Surfaced to `endCall.onEnd` + logs. */
3931
3606
  type EndCallTrigger =
@@ -4007,11 +3682,11 @@ interface EndCallPolicy {
4007
3682
  */
4008
3683
  readonly onEnd?: (ctx: AgentContext, info: EndCallInfo) => boolean | void | Promise<boolean | void>;
4009
3684
  }
4010
- type ShorthandPrimitive = 'string' | 'number' | 'boolean';
4011
- type ToolInputShape = Record<string, ShorthandPrimitive> | z.ZodTypeAny;
4012
- interface ToolDefinition<I = unknown, R = unknown> {
3685
+ type ShorthandPrimitive$1 = 'string' | 'number' | 'boolean';
3686
+ type ToolInputShape$1 = Record<string, ShorthandPrimitive$1> | z.ZodTypeAny;
3687
+ interface ToolDefinition$1<I = unknown, R = unknown> {
4013
3688
  readonly description: string;
4014
- readonly input: ToolInputShape;
3689
+ readonly input: ToolInputShape$1;
4015
3690
  readonly run: (input: I, ctx: AgentContext) => Promise<R> | R;
4016
3691
  /**
4017
3692
  * Capability this tool requires. Action Guard hard-blocks the call if not
@@ -4088,7 +3763,11 @@ interface AgentConfig<TProcess extends Record<string, ProcessField> = Record<str
4088
3763
  readonly outbound?: OutboundCallConfig;
4089
3764
  readonly speech?: SpeechConfig;
4090
3765
  readonly endCall?: EndCallPolicy;
4091
- readonly tools?: Readonly<Record<string, ToolDefinition>>;
3766
+ readonly tools?: Readonly<Record<string, ToolDefinition$1>>;
3767
+ /** Per-agent registry-tool scoping (stored ToolBinding names, applied at
3768
+ * boot). Non-empty → only these dashboard HTTP tools attach; absent/[] →
3769
+ * every enabled registry tool attaches (the historical default). */
3770
+ readonly toolBindings?: readonly string[];
4092
3771
  readonly security?: SecurityConfig;
4093
3772
  /**
4094
3773
  * Per-call ConsultationPolicy used by the built-in `ask_host` tool. When
@@ -4098,6 +3777,17 @@ interface AgentConfig<TProcess extends Record<string, ProcessField> = Record<str
4098
3777
  * packages/contracts/src/consultation.ts for the schema + semantics.
4099
3778
  */
4100
3779
  readonly consultation?: ConsultationPolicy;
3780
+ /**
3781
+ * Use your existing text agent as the LLM. When set (and `models.llm` is
3782
+ * unset), defineAgent wires the pipeline's LLM slot to this function: the
3783
+ * caller's STT transcript is passed to `onQuery`, and its returned text (or
3784
+ * streamed pieces) is spoken by TTS. The "two lines, keep your stack" path.
3785
+ *
3786
+ * Equivalent to `models: { llm: connector.llm({ onQuery }) }`. For a remote
3787
+ * brain instead, use `connector.llm({ url })` (direct) or a tunnel transport.
3788
+ * See docs/specs/voice-brain-connector/.
3789
+ */
3790
+ readonly onQuery?: OnQuery;
4101
3791
  readonly onUtterance?: (text: string, ctx: AgentContext) => Promise<void> | void;
4102
3792
  readonly onFieldCaptured?: (field: string, value: unknown, ctx: AgentContext) => Promise<void> | void;
4103
3793
  readonly onCallEnd?: (outcome: CallOutcomeSummary, ctx: AgentContext) => Promise<void> | void;
@@ -4175,6 +3865,107 @@ interface CallOutcomeSummary {
4175
3865
  */
4176
3866
  declare function defineProcess<T extends Record<string, ProcessField>>(def: ProcessDefinition<T>): ProcessDefinition<T>;
4177
3867
 
3868
+ interface RunAgentTextTranscriptOptions {
3869
+ /** The agent's system prompt / instructions (its code-defined behavior). */
3870
+ readonly instructions: string;
3871
+ /** The LLM that generates replies — injected so this stays provider-agnostic and
3872
+ * unit-testable (real inference/openai LLM in prod; a scripted fake in tests). */
3873
+ readonly llm: llm.LLM;
3874
+ /** Scripted caller turns, run in order; each produces the agent's reply turn(s). */
3875
+ readonly messages: readonly string[];
3876
+ /** Optional id surfaced on the Agent (for traceability). */
3877
+ readonly agentId?: string;
3878
+ }
3879
+ interface AgentTextTranscriptResult {
3880
+ readonly replies: string[];
3881
+ }
3882
+ /** Drive an instruction-based agent over text and collect its replies. Stateless
3883
+ * batch turn — the request/response shape the text playground's agent path uses. */
3884
+ declare function runAgentTextTranscript(opts: RunAgentTextTranscriptOptions): Promise<AgentTextTranscriptResult>;
3885
+
3886
+ interface DefaultMetadata {
3887
+ readonly hostname: string;
3888
+ readonly platform: NodeJS.Platform;
3889
+ readonly arch: string;
3890
+ readonly nodeVersion: string;
3891
+ readonly pid: number;
3892
+ /** From BUILD_SHA / GIT_COMMIT / VERCEL_GIT_COMMIT_SHA, or null. */
3893
+ readonly buildSha: string | null;
3894
+ readonly startedAt: string;
3895
+ }
3896
+ declare function collectDefaultMetadata(): DefaultMetadata;
3897
+ /**
3898
+ * Merge default metadata with user-supplied metadata. User values win on
3899
+ * conflict; defaults fill in the rest. Returns a plain object suitable for
3900
+ * the registry's metadata field.
3901
+ */
3902
+ declare function mergeMetadata(user: Record<string, unknown> | undefined, defaults: DefaultMetadata): Record<string, unknown>;
3903
+
3904
+ /** Primitive shorthand types accepted in tool input. Extendable. */
3905
+ type ShorthandPrimitive = 'string' | 'number' | 'boolean';
3906
+ /** What the user passes for a tool's input shape. */
3907
+ type ToolInputShape = Record<string, ShorthandPrimitive> | z.ZodTypeAny;
3908
+ interface ToolDefinition<I = unknown, R = unknown> {
3909
+ readonly description: string;
3910
+ readonly input: ToolInputShape;
3911
+ /** Implementation. Receives parsed input and the agent context. */
3912
+ readonly run: (input: I, ctx: AgentContext) => Promise<R> | R;
3913
+ /** Capability required for Action Guard. Defaults to `tool.<name>`. */
3914
+ readonly capability?: string;
3915
+ }
3916
+
3917
+ interface ResendCredentials {
3918
+ /** Resend API key — find under "API Keys" in the Resend dashboard. */
3919
+ readonly apiKey: string;
3920
+ /**
3921
+ * The verified `From:` address — must be a sender on a domain you've
3922
+ * verified in Resend (Settings → Domains). Accepts plain
3923
+ * "you@yourdomain.com" or "Display Name <you@yourdomain.com>" format.
3924
+ */
3925
+ readonly from: string;
3926
+ }
3927
+ interface ResendEmailToolOptions extends ResendCredentials {
3928
+ /**
3929
+ * Optional subject prefix prepended to every send. Useful when an agent
3930
+ * should always brand its emails consistently (e.g. "[Acme Support]").
3931
+ * Agents can still override the full subject per call.
3932
+ */
3933
+ readonly subjectPrefix?: string;
3934
+ /**
3935
+ * Optional canned signature appended to the plain-text body. Lets agent
3936
+ * authors enforce a sign-off without prompting the LLM to remember.
3937
+ */
3938
+ readonly signature?: string;
3939
+ }
3940
+ declare function resendEmailTool(options: ResendEmailToolOptions): ToolDefinition;
3941
+
3942
+ interface FormToolsOptions {
3943
+ /**
3944
+ * Optional default webhook URL to attach to every form session the agent
3945
+ * creates. Customers usually want this set globally per environment.
3946
+ */
3947
+ readonly defaultWebhookUrl?: string;
3948
+ /**
3949
+ * Customer-supplied Resend credentials. When set, sendFormLink mints the
3950
+ * form session via the platform (so token/state lives on the platform)
3951
+ * but sends the email DIRECTLY from the agent worker using the customer's
3952
+ * Resend account. The API key never leaves the customer's process; the
3953
+ * platform receives a structured log event after the send instead.
3954
+ *
3955
+ * When omitted, sendFormLink falls back to the platform's email path
3956
+ * (POST /v1/forms with `sendEmail` block), which uses VoiceLayer's
3957
+ * shared Resend account.
3958
+ */
3959
+ readonly resend?: ResendCredentials;
3960
+ }
3961
+ /**
3962
+ * Build the standard set of form tools, bound to a VoiceLayer client.
3963
+ *
3964
+ * Each entry conforms to ToolDefinition and can be spread directly into an
3965
+ * agent's `tools: {}` map (see defineAgent).
3966
+ */
3967
+ declare function formTools(vl: VoiceLayerClient, options?: FormToolsOptions): Record<string, ToolDefinition>;
3968
+
4178
3969
  declare class Agent {
4179
3970
  private readonly config;
4180
3971
  private registered;
@@ -4413,6 +4204,128 @@ declare const livekitTurn: {
4413
4204
  english(): ProviderFactory<TurnDetectorProvider>;
4414
4205
  multilingual(): ProviderFactory<TurnDetectorProvider>;
4415
4206
  };
4207
+ interface ConnectorLLMConfig {
4208
+ /** Upstream model id / alias (defaults to the brain's own default). */
4209
+ readonly model?: string;
4210
+ readonly temperature?: number;
4211
+ /** Spoken instead of dead air when the brain errors before replying. */
4212
+ readonly fallbackText?: string;
4213
+ /** In-process brain. */
4214
+ readonly onQuery?: OnQuery;
4215
+ /** Direct-egress brain — a public OpenAI-compatible base URL. */
4216
+ readonly url?: string;
4217
+ /** API key for the direct-egress endpoint. */
4218
+ readonly apiKey?: string;
4219
+ /** Hostnames that bypass the SSRF IP checks (direct mode). */
4220
+ readonly allowHosts?: readonly string[];
4221
+ /** Advanced: a custom transport (tunnel, etc.). */
4222
+ readonly transport?: BrainTransport;
4223
+ }
4224
+ declare const connector: {
4225
+ llm(config?: ConnectorLLMConfig): ProviderFactory<LLMProvider>;
4226
+ };
4227
+
4228
+ declare function callbackTransport(onQuery: OnQuery): BrainTransport;
4229
+
4230
+ interface ConnectorLLMOptions {
4231
+ readonly model?: string;
4232
+ readonly temperature?: number;
4233
+ readonly callId?: string;
4234
+ readonly projectId?: string;
4235
+ /** Spoken instead of dead air when the brain errors before any reply. */
4236
+ readonly fallbackText?: string;
4237
+ }
4238
+ /**
4239
+ * Build a ConnectorLLM instance for the pipeline's `llm` slot. The returned
4240
+ * object's chat() yields the brain reply and exposes close() for barge-in.
4241
+ */
4242
+ declare function createConnectorLLM(transport: BrainTransport, options?: ConnectorLLMOptions): Promise<unknown>;
4243
+
4244
+ interface ConnectorChatModelOptions {
4245
+ readonly model?: string;
4246
+ }
4247
+ interface ChatModelInput {
4248
+ readonly messages: readonly {
4249
+ readonly role: 'system' | 'user' | 'assistant';
4250
+ readonly content: string;
4251
+ }[];
4252
+ readonly json?: boolean;
4253
+ readonly temperature?: number;
4254
+ readonly model?: string;
4255
+ }
4256
+ declare class ConnectorChatModel {
4257
+ private readonly transport;
4258
+ private readonly options;
4259
+ constructor(transport: BrainTransport, options?: ConnectorChatModelOptions);
4260
+ complete(input: ChatModelInput): Promise<string>;
4261
+ }
4262
+
4263
+ declare class BrainConfigError extends Error {
4264
+ constructor(message: string);
4265
+ }
4266
+ /** Resolve a hostname to a list of IP strings. Injectable for tests. */
4267
+ type HostLookup = (host: string) => Promise<readonly string[]>;
4268
+ interface AssertUrlOptions {
4269
+ /** Hostnames that bypass IP checks (explicit per-connector allowlist). */
4270
+ readonly allowHosts?: readonly string[];
4271
+ /** Override DNS resolution (tests). */
4272
+ readonly lookup?: HostLookup;
4273
+ }
4274
+ /**
4275
+ * Validate a brain URL for direct egress. Throws BrainConfigError on any
4276
+ * violation; returns the parsed URL when safe.
4277
+ */
4278
+ declare function assertPublicHttpsUrl(raw: string, opts?: AssertUrlOptions): Promise<URL>;
4279
+
4280
+ interface BrainPubSub {
4281
+ publish(channel: string, message: string): Promise<void>;
4282
+ /** Subscribe to a channel; returns an unsubscribe handle. */
4283
+ subscribe(channel: string, handler: (raw: string) => void): Promise<() => Promise<void>>;
4284
+ }
4285
+ interface TunnelBrainTransportOptions {
4286
+ readonly connectorId: string;
4287
+ readonly pubsub: BrainPubSub;
4288
+ /** Fail the turn if the daemon sends nothing within this window. Default 20s. */
4289
+ readonly firstChunkTimeoutMs?: number;
4290
+ }
4291
+ declare function tunnelBrainTransport(options: TunnelBrainTransportOptions): BrainTransport;
4292
+
4293
+ declare class RedisBrainPubSub implements BrainPubSub {
4294
+ private readonly sub;
4295
+ private readonly pub;
4296
+ private readonly listeners;
4297
+ constructor(sub: Redis, pub: Redis);
4298
+ publish(channel: string, message: string): Promise<void>;
4299
+ subscribe(channel: string, handler: (raw: string) => void): Promise<() => Promise<void>>;
4300
+ close(): Promise<void>;
4301
+ }
4302
+ declare function buildRedisBrainPubSub(redisUrl: string | undefined): RedisBrainPubSub | null;
4303
+
4304
+ interface SseDelta {
4305
+ readonly content?: string;
4306
+ readonly finishReason?: string;
4307
+ }
4308
+ declare function parseChatCompletionSse(source: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>): AsyncGenerator<SseDelta>;
4309
+
4310
+ interface BrainEndpointConfig {
4311
+ /** Base URL of the OpenAI-compatible endpoint, e.g. http://localhost:4000/v1. */
4312
+ readonly brainUrl: string;
4313
+ readonly apiKey?: string;
4314
+ readonly defaultModel?: string;
4315
+ /** Injectable for tests; defaults to global fetch. */
4316
+ readonly fetchImpl?: typeof fetch;
4317
+ }
4318
+ interface IncomingBrainRequest {
4319
+ readonly streamId: string;
4320
+ readonly model?: string;
4321
+ readonly temperature?: number;
4322
+ readonly messages: ReadonlyArray<{
4323
+ role: 'system' | 'user' | 'assistant';
4324
+ content: string;
4325
+ }>;
4326
+ }
4327
+ /** Run one brain.request and yield the reply frames. Never throws. */
4328
+ declare function runBrainRequest(req: IncomingBrainRequest, cfg: BrainEndpointConfig, signal: AbortSignal): AsyncGenerator<ConnectorUpFrame>;
4416
4329
 
4417
4330
  /**
4418
4331
  * Turn the persisted `agents.process_schema` (or a freshly-compiled flow) into a
@@ -4428,7 +4341,7 @@ interface CompiledAgentParts {
4428
4341
  readonly triggers?: Record<string, TriggerDefinition>;
4429
4342
  readonly handoff?: HandoffConfig;
4430
4343
  readonly memory?: MemoryConfig;
4431
- readonly tools?: Record<string, ToolDefinition>;
4344
+ readonly tools?: Record<string, ToolDefinition$1>;
4432
4345
  }
4433
4346
  /**
4434
4347
  * Turn a compiled ProcessSchemaDTO into the full set of `defineAgent` parts a
@@ -4450,22 +4363,22 @@ declare function processSchemaToAgentParts(schema: ProcessSchemaDTO, opts?: {
4450
4363
  declare abstract class BaseTool<I = unknown, R = unknown> {
4451
4364
  abstract readonly name: string;
4452
4365
  abstract readonly description: string;
4453
- abstract readonly input: ToolInputShape$1;
4366
+ abstract readonly input: ToolInputShape;
4454
4367
  readonly capability?: string;
4455
4368
  abstract run(input: I, ctx: AgentContext): Promise<R> | R;
4456
4369
  /** The ToolDefinition the runtime consumes. */
4457
- toDefinition(): ToolDefinition$1<I, R>;
4370
+ toDefinition(): ToolDefinition<I, R>;
4458
4371
  /** `{ [name]: definition }` — spread straight into `defineAgent({ tools })`. */
4459
- register(): Record<string, ToolDefinition$1>;
4372
+ register(): Record<string, ToolDefinition>;
4460
4373
  }
4461
4374
  /** Functional equivalent of BaseTool — same output, no class. */
4462
4375
  declare function defineTool<I = unknown, R = unknown>(spec: {
4463
4376
  readonly name: string;
4464
4377
  readonly description: string;
4465
- readonly input: ToolInputShape$1;
4378
+ readonly input: ToolInputShape;
4466
4379
  readonly capability?: string;
4467
4380
  readonly run: (input: I, ctx: AgentContext) => Promise<R> | R;
4468
- }): Record<string, ToolDefinition$1>;
4381
+ }): Record<string, ToolDefinition>;
4469
4382
  interface HttpToolResult {
4470
4383
  readonly ok: boolean;
4471
4384
  readonly status: number;
@@ -4474,7 +4387,7 @@ interface HttpToolResult {
4474
4387
  interface HttpToolSpec {
4475
4388
  readonly name: string;
4476
4389
  readonly description: string;
4477
- readonly input: ToolInputShape$1;
4390
+ readonly input: ToolInputShape;
4478
4391
  /** May contain `{field}` placeholders filled from input (URL-encoded). */
4479
4392
  readonly url: string;
4480
4393
  readonly method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
@@ -4490,7 +4403,7 @@ interface HttpToolSpec {
4490
4403
  * case. Use this for public/no-auth endpoints (e.g. an n8n webhook). Secrets
4491
4404
  * should NOT be inlined here; vault-backed credentials resolve server-side.
4492
4405
  */
4493
- declare function httpTool(spec: HttpToolSpec): Record<string, ToolDefinition$1>;
4406
+ declare function httpTool(spec: HttpToolSpec): Record<string, ToolDefinition>;
4494
4407
 
4495
4408
  interface CreateClientOptions {
4496
4409
  readonly apiKey?: string;
@@ -4513,4 +4426,4 @@ interface VoiceLayerClient {
4513
4426
  }
4514
4427
  declare function createClient(options?: CreateClientOptions): VoiceLayerClient;
4515
4428
 
4516
- export { Agent, type AgentConfig, type AgentContext, type AgentEventEmitter, type AgentEventListener, type AgentLifecycleEvent, type AgentTurnEvent, type AppendDtmfEventInput, type AppendTranscriptInput, type AudioProfile, type AudioSurface, BaseTool, type CallAttributeValue, type CallInfo, type CallLegInput, type CallOutcomeSummary, type CallParticipantInput, type CallStatus, type CallSummary, CallsClient, type ChannelKind, type CompiledAgentParts, type CompletionStrategy, type ComplianceTag, type ConnectorInstance, ConsultationPolicy, type CreateClientOptions, type CreatedFormSession, type DefaultMetadata, type DtmfDirection, type DtmfEvent, type DtmfHandler, EmailClient, type SendEmailInput as EmailSendInput, type EndCallControllerHandle, type EndCallInfo, type EndCallOutcome, type EndCallPolicy, type EndCallTrigger, type EnsureCallByRoomInput, type FakeSessionAdapter, type FloorControlConfig, type CreateFormSessionInput as FormCreateInput, type FormToolsOptions, FormsClient, type HandoffConfig, type HttpToolResult, type HttpToolSpec, type InboundOptions, type InferProcessData, LK_AGENT_STATE_MAP, type LLMProvider, type MemoryConfig, type MemoryHandle, type MemoryScope, type MetricsEvent, type ModelConfig, NON_BUSY_STATES, type Participant, ParticipantId, type ParticipantKind, type ParticipantSet, type ParticipantsConfig, type PipelineConfig, PlansClient, type ProcessBackendAck, type ProcessDefinition, type ProcessField, type ProcessFieldType, type ProcessSnapshot, type PronunciationDict, type ProviderFactory, type PublicFormSessionView, type PuppetControlDeps, type PuppetControlHandle, type ReadinessProbe, type ReadinessReport, type ReadinessResult, type RealtimeProvider, type RegisterInput, type RegisterOptions, type RegisteredAgent, type ResendCredentials, type ResendEmailToolOptions, type RespondOptions, type Room, type RouteEntry, type RoutingRule, type RoutingSnapshot, type STTProvider, type SayOptions, type SecurityConfig, type SendDtmfOptions, type SentEmail, type SessionAdapter, type SessionCapabilities, type SessionErrorEvent, type SessionEvent, type SessionEventMap, type SessionFactory, type SessionFactoryInput, type SessionOutbound, type SessionState, type ShorthandPrimitive, type SpeechConfig, type SpeechResult, type SpeechTarget, type StateChangeEvent, type SyncCallStateInput, type TTSProvider, type ToolDefinition, type ToolInputShape, type TriggerAction, type TriggerCondition, type TriggerDefinition, type TtsVoiceConfig, type TurnDetectorProvider, type TurnEvent, type Unsubscribe, type UserInputEvent, type UserTurn, type VADProvider, VoiceLayerAuthError, type VoiceLayerClient, VoiceLayerError, VoiceLayerHttpError, VoiceLayerNetworkError, VoiceLayerValidationError, type WebhookApi, type WebhookConfig, type WrapOptions, applyPronunciations, assemblyai, asyncProbe, cartesia, collectDefaultMetadata, createClient, createNoOpLLM, deepgram, defineAgent, defineFlowRuntime, defineProcess, defineTool, dtmfCodeToDigit, dtmfDigitToCode, duck, elevenlabs, envProbe, formTools, google, httpTool, livekitTurn, mergeMetadata, mute, normalizeState, openai, ParticipantId as participantId, passthrough, processSchemaToAgentParts, processSchemaToDefinition, puppetEnvAvailable, resendEmailTool, runProbes, silero, startPuppetControl, transform, urlProbe, webhook, wrap };
4429
+ export { Agent, type AgentConfig, AgentContext, type AgentEventEmitter, type AgentEventListener, type AgentLifecycleEvent, type AgentTextTranscriptResult, type AppendDtmfEventInput, type AppendTranscriptInput, BaseTool, type BrainCallMetadata, type BrainCapabilities, type BrainChunk, BrainConfigError, type BrainEndpointConfig, type BrainMessage, type BrainPubSub, type BrainRequest, type BrainTransport, type CallAttributeValue, CallInfo, type CallLegInput, type CallOutcomeSummary, type CallParticipantInput, type CallStatus, type CallSummary, CallsClient, type CompiledAgentParts, type CompletionStrategy, type ComplianceTag, ConnectorChatModel, type ConnectorChatModelOptions, type ConnectorInstance, type ConnectorLLMConfig, type ConnectorLLMOptions, ConsultationPolicy, type CreateClientOptions, type CreatedFormSession, type DefaultMetadata, type DtmfDirection, EmailClient, type SendEmailInput as EmailSendInput, type EndCallInfo, type EndCallPolicy, type EndCallTrigger, type EndpointingConfig, type EnsureCallByRoomInput, type CreateFormSessionInput as FormCreateInput, type FormToolsOptions, FormsClient, type HandoffConfig, type HttpToolResult, type HttpToolSpec, type IncomingBrainRequest, type InferProcessData, type InterruptionConfig, type LLMProvider, type MemoryConfig, type MemoryScope, type ModelConfig, type OnQuery, type OnQueryContext, type OnQueryResult, Participant, type ParticipantsConfig, type PipelineConfig, PlansClient, type ProcessBackendAck, type ProcessDefinition, type ProcessField, type ProcessFieldType, type PronunciationDict, type ProviderFactory, type PublicFormSessionView, type PuppetControlDeps, type PuppetControlHandle, type ReadinessProbe, type ReadinessReport, type ReadinessResult, type RealtimeProvider, RedisBrainPubSub, type RegisterInput, type RegisterOptions, type RegisteredAgent, type ResendCredentials, type ResendEmailToolOptions, type RunAgentTextTranscriptOptions, type STTProvider, type SecurityConfig, type SentEmail, type ShorthandPrimitive$1 as ShorthandPrimitive, type SpeechConfig, type SseDelta, type SyncCallStateInput, type TTSProvider, type ToolDefinition$1 as ToolDefinition, type ToolInputShape$1 as ToolInputShape, type TriggerAction, type TriggerCondition, type TriggerDefinition, type TunnelBrainTransportOptions, type TurnDetectorProvider, type VADProvider, VoiceLayerAuthError, type VoiceLayerClient, VoiceLayerError, VoiceLayerHttpError, VoiceLayerNetworkError, VoiceLayerValidationError, type WebhookApi, type WebhookConfig, type WrapOptions, applyPronunciations, assemblyai, assertPublicHttpsUrl, asyncProbe, buildRedisBrainPubSub, callbackTransport, cartesia, collectDefaultMetadata, connector, createClient, createConnectorLLM, createNoOpLLM, deepgram, defineAgent, defineFlowRuntime, defineProcess, defineTool, elevenlabs, envProbe, formTools, google, httpTool, livekitTurn, mergeMetadata, openai, parseChatCompletionSse, processSchemaToAgentParts, processSchemaToDefinition, puppetEnvAvailable, resendEmailTool, runAgentTextTranscript, runBrainRequest, runProbes, silero, startPuppetControl, tunnelBrainTransport, urlProbe, webhook, wrap };