@jambonz/sdk 0.7.0 → 0.8.1
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/AGENTS.md +21 -14
- package/dist/client/index.cjs +4 -0
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +4 -2
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -1
- package/dist/index.cjs +18 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/{rest-CoEMXJy6.d.ts → rest-C4J_YJN5.d.cts} +3 -1
- package/dist/{rest-B1Gb3E0R.d.cts → rest-DVExRUxz.d.ts} +3 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/{verb-builder-D3TNKZcU.d.cts → verb-builder-BjrRSray.d.cts} +3 -1
- package/dist/{verb-builder-CwXZO4NY.d.ts → verb-builder-C5tteeud.d.ts} +3 -1
- package/dist/{verbs-O_ofvl8T.d.cts → verbs-DXbSDMKR.d.cts} +91 -3
- package/dist/{verbs-O_ofvl8T.d.ts → verbs-DXbSDMKR.d.ts} +91 -3
- package/dist/webhook/index.cjs +4 -0
- package/dist/webhook/index.cjs.map +1 -1
- package/dist/webhook/index.d.cts +2 -2
- package/dist/webhook/index.d.ts +2 -2
- package/dist/webhook/index.js +4 -0
- package/dist/webhook/index.js.map +1 -1
- package/dist/websocket/index.cjs +14 -1
- package/dist/websocket/index.cjs.map +1 -1
- package/dist/websocket/index.d.cts +4 -2
- package/dist/websocket/index.d.ts +4 -2
- package/dist/websocket/index.js +14 -1
- package/dist/websocket/index.js.map +1 -1
- package/examples/bedrock-agent.ts +6 -1
- package/examples/room-play-tone/ws-app.ts +63 -0
- package/examples/room-say/ws-app.ts +67 -0
- package/examples/room-with-stream/ws-app.ts +64 -0
- package/examples/s2s-move-to-room/ws-app.ts +82 -0
- package/examples/{listen-record → stream-record}/app.ts +2 -2
- package/examples/stream-then-room/ws-app.ts +74 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ActionHook,
|
|
1
|
+
import { A as ActionHook, $ as Verb, S as SayVerb, Z as TransferVerb } from './verbs-DXbSDMKR.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Types for the jambonz REST API client.
|
|
@@ -126,6 +126,8 @@ interface UpdateCallRequest {
|
|
|
126
126
|
digit: string;
|
|
127
127
|
duration?: number;
|
|
128
128
|
};
|
|
129
|
+
/** Redirect the in-progress call to a packaged transfer (blind or warm). */
|
|
130
|
+
transfer?: Omit<TransferVerb, 'verb'>;
|
|
129
131
|
/** Tag metadata. */
|
|
130
132
|
tag?: Record<string, unknown>;
|
|
131
133
|
/** Mid-conversation agent update. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ActionHook,
|
|
1
|
+
import { A as ActionHook, $ as Verb, S as SayVerb, Z as TransferVerb } from './verbs-DXbSDMKR.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Types for the jambonz REST API client.
|
|
@@ -126,6 +126,8 @@ interface UpdateCallRequest {
|
|
|
126
126
|
digit: string;
|
|
127
127
|
duration?: number;
|
|
128
128
|
};
|
|
129
|
+
/** Redirect the in-progress call to a packaged transfer (blind or warm). */
|
|
130
|
+
transfer?: Omit<TransferVerb, 'verb'>;
|
|
129
131
|
/** Tag metadata. */
|
|
130
132
|
tag?: Record<string, unknown>;
|
|
131
133
|
/** Mid-conversation agent update. */
|
package/dist/types/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/llm-vendors.generated.ts"],"names":[],"mappings":";;;AAQO,IAAM,WAAA,GAAc;AAAA,EACzB,QAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF","file":"index.cjs","sourcesContent":["// AUTO-GENERATED — DO NOT EDIT BY HAND.\n// Source of truth: @jambonz/schema@0.3.
|
|
1
|
+
{"version":3,"sources":["../../src/types/llm-vendors.generated.ts"],"names":[],"mappings":";;;AAQO,IAAM,WAAA,GAAc;AAAA,EACzB,QAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF","file":"index.cjs","sourcesContent":["// AUTO-GENERATED — DO NOT EDIT BY HAND.\n// Source of truth: @jambonz/schema@0.3.16 verbs/agent.schema.json (llm.vendor.enum)\n// Regenerate with: npm run gen:types\n//\n// This file derives the LLM vendor list from the JSON schema so the SDK's\n// types never drift from the schema when a new vendor is added.\n\n/** Supported LLM vendors for the agent verb, derived from the schema enum. */\nexport const LLM_VENDORS = [\n 'openai',\n 'anthropic',\n 'google',\n 'vertex-gemini',\n 'vertex-openai',\n 'bedrock',\n 'deepseek',\n 'baseten',\n 'azure-openai',\n 'groq',\n 'huggingface',\n] as const;\n\n/** Union of LLM vendor ids accepted by the agent verb's `llm.vendor`. */\nexport type LlmVendor = (typeof LLM_VENDORS)[number];\n"]}
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ActionHook, a as ActionHookDelayAction, b as ActionHookObject, c as AgentLlm, d as AgentLlmOptions, e as AgentVerb, f as AlertVerb, g as Amd, h as AmdTimers, i as AnswerVerb, j as Auth, B as BidirectionalAudio, C as ConferenceVerb, k as ConfigVerb, D as DequeueVerb, l as DialVerb, m as DtmfVerb, n as DubVerb, E as EnqueueVerb, F as FillerNoise, G as GatherVerb, H as HangupVerb, J as JambonzApp, L as LLM_VENDORS,
|
|
1
|
+
export { A as ActionHook, a as ActionHookDelayAction, b as ActionHookObject, c as AgentLlm, d as AgentLlmOptions, e as AgentVerb, f as AlertVerb, g as Amd, h as AmdTimers, i as AnswerVerb, j as Auth, B as BidirectionalAudio, C as ConferenceVerb, k as ConfigVerb, D as DequeueVerb, l as DialVerb, m as DtmfVerb, n as DubVerb, E as EnqueueVerb, F as FillerNoise, G as GatherVerb, H as Handoff, o as HangupVerb, J as JambonzApp, L as LLM_VENDORS, p as LeaveVerb, q as ListenVerb, r as LlmMessage, s as LlmTool, t as LlmToolOpenAIWrapped, u as LlmToolOutputData, v as LlmVendor, w as LlmVerb, M as McpServerConfig, x as MessageVerb, P as PauseVerb, y as PlayVerb, R as Recognizer, z as RedirectVerb, S as SayVerb, I as SipDeclineVerb, K as SipReferVerb, N as SipRequestVerb, O as StreamVerb, Q as Synthesizer, T as TagVerb, U as Target, V as TranscribeVerb, W as TransferConfirm, X as TransferDisposition, Y as TransferOptions, Z as TransferVerb, _ as Vad, $ as Verb, a0 as VerbName } from '../verbs-DXbSDMKR.cjs';
|
|
2
2
|
export { A as AgentEvent, a as AgentEventType, b as AgentLlmResponseEvent, c as AgentPreflightMetrics, d as AgentTurnEndEvent, e as AgentTurnLatency, f as AgentUserInterruptionEvent, g as AgentUserTranscriptEvent, C as CallSession, T as TtsStreamingEvent, h as TtsStreamingEventType, W as WsMessage, i as WsMessageType, j as WsResponse } from '../session-DKaSRkIo.cjs';
|
|
3
3
|
export { E as EnvVarDef, a as EnvVarSchema, L as Logger } from '../common-BSJZX7WO.cjs';
|
|
4
|
-
export { C as CallCount, a as CallInfo, b as CreateCallRequest, L as ListCallsFilter, Q as QueueInfo, U as UpdateCallRequest } from '../rest-
|
|
4
|
+
export { C as CallCount, a as CallInfo, b as CreateCallRequest, L as ListCallsFilter, Q as QueueInfo, U as UpdateCallRequest } from '../rest-C4J_YJN5.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as ActionHook, a as ActionHookDelayAction, b as ActionHookObject, c as AgentLlm, d as AgentLlmOptions, e as AgentVerb, f as AlertVerb, g as Amd, h as AmdTimers, i as AnswerVerb, j as Auth, B as BidirectionalAudio, C as ConferenceVerb, k as ConfigVerb, D as DequeueVerb, l as DialVerb, m as DtmfVerb, n as DubVerb, E as EnqueueVerb, F as FillerNoise, G as GatherVerb, H as HangupVerb, J as JambonzApp, L as LLM_VENDORS,
|
|
1
|
+
export { A as ActionHook, a as ActionHookDelayAction, b as ActionHookObject, c as AgentLlm, d as AgentLlmOptions, e as AgentVerb, f as AlertVerb, g as Amd, h as AmdTimers, i as AnswerVerb, j as Auth, B as BidirectionalAudio, C as ConferenceVerb, k as ConfigVerb, D as DequeueVerb, l as DialVerb, m as DtmfVerb, n as DubVerb, E as EnqueueVerb, F as FillerNoise, G as GatherVerb, H as Handoff, o as HangupVerb, J as JambonzApp, L as LLM_VENDORS, p as LeaveVerb, q as ListenVerb, r as LlmMessage, s as LlmTool, t as LlmToolOpenAIWrapped, u as LlmToolOutputData, v as LlmVendor, w as LlmVerb, M as McpServerConfig, x as MessageVerb, P as PauseVerb, y as PlayVerb, R as Recognizer, z as RedirectVerb, S as SayVerb, I as SipDeclineVerb, K as SipReferVerb, N as SipRequestVerb, O as StreamVerb, Q as Synthesizer, T as TagVerb, U as Target, V as TranscribeVerb, W as TransferConfirm, X as TransferDisposition, Y as TransferOptions, Z as TransferVerb, _ as Vad, $ as Verb, a0 as VerbName } from '../verbs-DXbSDMKR.js';
|
|
2
2
|
export { A as AgentEvent, a as AgentEventType, b as AgentLlmResponseEvent, c as AgentPreflightMetrics, d as AgentTurnEndEvent, e as AgentTurnLatency, f as AgentUserInterruptionEvent, g as AgentUserTranscriptEvent, C as CallSession, T as TtsStreamingEvent, h as TtsStreamingEventType, W as WsMessage, i as WsMessageType, j as WsResponse } from '../session-DKaSRkIo.js';
|
|
3
3
|
export { E as EnvVarDef, a as EnvVarSchema, L as Logger } from '../common-BSJZX7WO.js';
|
|
4
|
-
export { C as CallCount, a as CallInfo, b as CreateCallRequest, L as ListCallsFilter, Q as QueueInfo, U as UpdateCallRequest } from '../rest-
|
|
4
|
+
export { C as CallCount, a as CallInfo, b as CreateCallRequest, L as ListCallsFilter, Q as QueueInfo, U as UpdateCallRequest } from '../rest-DVExRUxz.js';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/llm-vendors.generated.ts"],"names":[],"mappings":";AAQO,IAAM,WAAA,GAAc;AAAA,EACzB,QAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF","file":"index.js","sourcesContent":["// AUTO-GENERATED — DO NOT EDIT BY HAND.\n// Source of truth: @jambonz/schema@0.3.
|
|
1
|
+
{"version":3,"sources":["../../src/types/llm-vendors.generated.ts"],"names":[],"mappings":";AAQO,IAAM,WAAA,GAAc;AAAA,EACzB,QAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF","file":"index.js","sourcesContent":["// AUTO-GENERATED — DO NOT EDIT BY HAND.\n// Source of truth: @jambonz/schema@0.3.16 verbs/agent.schema.json (llm.vendor.enum)\n// Regenerate with: npm run gen:types\n//\n// This file derives the LLM vendor list from the JSON schema so the SDK's\n// types never drift from the schema when a new vendor is added.\n\n/** Supported LLM vendors for the agent verb, derived from the schema enum. */\nexport const LLM_VENDORS = [\n 'openai',\n 'anthropic',\n 'google',\n 'vertex-gemini',\n 'vertex-openai',\n 'bedrock',\n 'deepseek',\n 'baseten',\n 'azure-openai',\n 'groq',\n 'huggingface',\n] as const;\n\n/** Union of LLM vendor ids accepted by the agent verb's `llm.vendor`. */\nexport type LlmVendor = (typeof LLM_VENDORS)[number];\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as Verb, S as SayVerb, y as PlayVerb, G as GatherVerb, w as LlmVerb, a1 as S2sVerb, a2 as LlmBaseOptions, a3 as DialogflowVerb, e as AgentVerb, q as ListenVerb, O as StreamVerb, V as TranscribeVerb, l as DialVerb, C as ConferenceVerb, a4 as RoomVerb, E as EnqueueVerb, D as DequeueVerb, o as HangupVerb, z as RedirectVerb, P as PauseVerb, p as LeaveVerb, I as SipDeclineVerb, N as SipRequestVerb, K as SipReferVerb, Z as TransferVerb, k as ConfigVerb, i as AnswerVerb, f as AlertVerb, T as TagVerb, m as DtmfVerb, n as DubVerb, x as MessageVerb } from './verbs-DXbSDMKR.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Schema-based validation using AJV.
|
|
@@ -100,6 +100,8 @@ declare class VerbBuilder {
|
|
|
100
100
|
sipRequest(opts: Omit<SipRequestVerb, 'verb'>): this;
|
|
101
101
|
/** Transfer the call via SIP REFER. */
|
|
102
102
|
sipRefer(opts: Omit<SipReferVerb, 'verb'>): this;
|
|
103
|
+
/** Transfer the caller to a destination (blind, or warm parked/three-way) with built-in failure handling. */
|
|
104
|
+
transfer(opts: Omit<TransferVerb, 'verb'>): this;
|
|
103
105
|
/** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */
|
|
104
106
|
config(opts: Omit<ConfigVerb, 'verb'>): this;
|
|
105
107
|
/** Explicitly answer the call (sends a 200 OK). */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as Verb, S as SayVerb, y as PlayVerb, G as GatherVerb, w as LlmVerb, a1 as S2sVerb, a2 as LlmBaseOptions, a3 as DialogflowVerb, e as AgentVerb, q as ListenVerb, O as StreamVerb, V as TranscribeVerb, l as DialVerb, C as ConferenceVerb, a4 as RoomVerb, E as EnqueueVerb, D as DequeueVerb, o as HangupVerb, z as RedirectVerb, P as PauseVerb, p as LeaveVerb, I as SipDeclineVerb, N as SipRequestVerb, K as SipReferVerb, Z as TransferVerb, k as ConfigVerb, i as AnswerVerb, f as AlertVerb, T as TagVerb, m as DtmfVerb, n as DubVerb, x as MessageVerb } from './verbs-DXbSDMKR.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Schema-based validation using AJV.
|
|
@@ -100,6 +100,8 @@ declare class VerbBuilder {
|
|
|
100
100
|
sipRequest(opts: Omit<SipRequestVerb, 'verb'>): this;
|
|
101
101
|
/** Transfer the call via SIP REFER. */
|
|
102
102
|
sipRefer(opts: Omit<SipReferVerb, 'verb'>): this;
|
|
103
|
+
/** Transfer the caller to a destination (blind, or warm parked/three-way) with built-in failure handling. */
|
|
104
|
+
transfer(opts: Omit<TransferVerb, 'verb'>): this;
|
|
103
105
|
/** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */
|
|
104
106
|
config(opts: Omit<ConfigVerb, 'verb'>): this;
|
|
105
107
|
/** Explicitly answer the call (sends a 200 OK). */
|
|
@@ -426,6 +426,8 @@ interface LlmBaseOptions {
|
|
|
426
426
|
toolHook?: ActionHook;
|
|
427
427
|
/** Event types to receive via eventHook. */
|
|
428
428
|
events?: string[];
|
|
429
|
+
/** Declarative transfer-to-human: injects a transfer tool and runs the packaged transfer when the model calls it. */
|
|
430
|
+
handoff?: Handoff;
|
|
429
431
|
}
|
|
430
432
|
interface LlmVerb extends LlmBaseOptions {
|
|
431
433
|
verb: 'llm';
|
|
@@ -530,6 +532,8 @@ interface AgentVerb {
|
|
|
530
532
|
eventHook?: ActionHook;
|
|
531
533
|
/** Webhook when the LLM requests a tool/function call. */
|
|
532
534
|
toolHook?: ActionHook;
|
|
535
|
+
/** Declarative transfer-to-human: injects a transfer tool and runs the packaged transfer when the model calls it. */
|
|
536
|
+
handoff?: Handoff;
|
|
533
537
|
/** Configuration for playing filler audio while tool calls are in progress. Prevents silence during long-running tool executions. */
|
|
534
538
|
toolFiller?: false | {
|
|
535
539
|
/** Filler mode. 'audio' plays a looping audio file. 'backchannel' uses TTS to speak short phrases. */
|
|
@@ -745,7 +749,9 @@ interface ConferenceVerb {
|
|
|
745
749
|
enterHook?: ActionHook;
|
|
746
750
|
/** Conference recording config. */
|
|
747
751
|
record?: Record<string, unknown>;
|
|
748
|
-
/**
|
|
752
|
+
/** Fork the room's mixed audio to a WebSocket. Prefer `stream`; `listen` is a synonym. */
|
|
753
|
+
stream?: Omit<StreamVerb, 'verb'>;
|
|
754
|
+
/** Audio streaming config (synonym for `stream`). */
|
|
749
755
|
listen?: Omit<ListenVerb, 'verb'>;
|
|
750
756
|
/** Distribute DTMF to all participants. */
|
|
751
757
|
distributeDtmf?: boolean;
|
|
@@ -846,6 +852,88 @@ interface SipReferVerb {
|
|
|
846
852
|
/** Webhook for NOTIFY progress events. */
|
|
847
853
|
eventHook?: ActionHook;
|
|
848
854
|
}
|
|
855
|
+
/** Per-outcome fallback actions when a transfer does not complete normally. */
|
|
856
|
+
interface TransferDisposition {
|
|
857
|
+
/** Action when the destination does not answer within timeout. Default: 'return'. */
|
|
858
|
+
onNoAnswer?: 'return' | 'voicemail' | 'hangup';
|
|
859
|
+
/** Action when the destination is busy. Default: 'return'. */
|
|
860
|
+
onBusy?: 'return' | 'voicemail' | 'hangup';
|
|
861
|
+
/** Action when the destination declines (confirm gate failed, AMD machine, or rejection). Default: 'return'. */
|
|
862
|
+
onDecline?: 'return' | 'voicemail' | 'hangup';
|
|
863
|
+
/** Action when a protocol-level error occurs on the destination leg. Default: 'return'. */
|
|
864
|
+
onFailure?: 'return' | 'voicemail' | 'hangup';
|
|
865
|
+
/** SIP URI or HTTP URL for voicemail. Required when any disposition value is 'voicemail'. */
|
|
866
|
+
voicemailUrl?: string;
|
|
867
|
+
}
|
|
868
|
+
/** Human-side acceptance gate: the destination must press a digit to accept. */
|
|
869
|
+
interface TransferConfirm {
|
|
870
|
+
/** Text or URL of the prompt played to the destination. */
|
|
871
|
+
prompt: string;
|
|
872
|
+
/** Single DTMF digit the destination must press to accept. */
|
|
873
|
+
digit: string;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Shared configuration for blind and warm transfer choreography. Reused by the
|
|
877
|
+
* `transfer` verb and the `handoff` block on conversational verbs.
|
|
878
|
+
*/
|
|
879
|
+
interface TransferOptions {
|
|
880
|
+
/** 'blind' hands off immediately; 'warm' lets the agent brief the destination first. */
|
|
881
|
+
mode: 'blind' | 'warm';
|
|
882
|
+
/** blind only: 'refer' sends a SIP REFER; 'dial' places a bridged outbound call. Default: 'refer'. */
|
|
883
|
+
blindMethod?: 'refer' | 'dial';
|
|
884
|
+
/** warm only: true = caller joins a three-way conference and hears the brief; false = caller is parked. Default: false. */
|
|
885
|
+
callerPresent?: boolean;
|
|
886
|
+
/** One or more destinations. All are rung simultaneously; first to answer wins. */
|
|
887
|
+
target: Target[];
|
|
888
|
+
/** Caller ID presented to the destination. */
|
|
889
|
+
callerId?: string;
|
|
890
|
+
/** warm/parked only: verbs for the parked caller while the agent briefs the destination. */
|
|
891
|
+
onHoldHook?: ActionHook;
|
|
892
|
+
/** Seconds to wait for the destination to answer before applying onNoAnswer. Default: 30. */
|
|
893
|
+
timeout?: number;
|
|
894
|
+
/** Optional human-side acceptance gate. */
|
|
895
|
+
confirm?: TransferConfirm;
|
|
896
|
+
/** warm only: optional answering-machine detection on the destination leg. */
|
|
897
|
+
amd?: Amd;
|
|
898
|
+
/** Per-outcome fallback actions. */
|
|
899
|
+
disposition?: TransferDisposition;
|
|
900
|
+
/** Fires when the transfer resolves (bridged, returned, voicemail, or failed). */
|
|
901
|
+
actionHook?: ActionHook;
|
|
902
|
+
/** Optional hook for in-progress transfer events (ringing, brief started). */
|
|
903
|
+
eventHook?: ActionHook;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Declarative transfer-to-human config for conversational verbs (`agent`, `llm`/`s2s`).
|
|
907
|
+
* The runtime injects a `transfer_to_human` tool and runs the packaged transfer
|
|
908
|
+
* choreography when the model calls it.
|
|
909
|
+
*/
|
|
910
|
+
interface Handoff extends TransferOptions {
|
|
911
|
+
/** 'auto' = LLM writes the summary; 'none' = no spoken brief; {template} = guidance for the summary. Default: 'auto'. */
|
|
912
|
+
brief?: 'auto' | 'none' | {
|
|
913
|
+
template: string;
|
|
914
|
+
};
|
|
915
|
+
/** Optional voice/vendor for the spoken brief. Defaults to the session synthesizer. */
|
|
916
|
+
briefSynthesizer?: Synthesizer;
|
|
917
|
+
/** Override the injected tool name. Default: 'transfer_to_human'. */
|
|
918
|
+
toolName?: string;
|
|
919
|
+
/** Override the injected tool description shown to the LLM. */
|
|
920
|
+
toolDescription?: string;
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Packaged blind and warm (parked / three-way) transfer with built-in failure
|
|
924
|
+
* handling. Composes {@link TransferOptions} for the shared choreography.
|
|
925
|
+
*/
|
|
926
|
+
interface TransferVerb extends TransferOptions {
|
|
927
|
+
verb: 'transfer';
|
|
928
|
+
id?: string;
|
|
929
|
+
/** warm only: the spoken summary delivered to the destination (human). */
|
|
930
|
+
brief?: {
|
|
931
|
+
/** The spoken briefing text. */
|
|
932
|
+
text: string;
|
|
933
|
+
/** Optional voice/vendor for the brief. Defaults to the session synthesizer. */
|
|
934
|
+
synthesizer?: Synthesizer;
|
|
935
|
+
};
|
|
936
|
+
}
|
|
849
937
|
interface ConfigVerb {
|
|
850
938
|
verb: 'config';
|
|
851
939
|
id?: string;
|
|
@@ -980,10 +1068,10 @@ interface MessageVerb {
|
|
|
980
1068
|
actionHook?: ActionHook;
|
|
981
1069
|
}
|
|
982
1070
|
/** Any jambonz verb. Discriminated on the 'verb' property. */
|
|
983
|
-
type Verb = AnswerVerb | AlertVerb | ConfigVerb | SayVerb | PlayVerb | GatherVerb | DialVerb | ListenVerb | StreamVerb | LlmVerb | S2sVerb | OpenaiS2sVerb | GoogleS2sVerb | ElevenlabsS2sVerb | DeepgramS2sVerb | UltravoxS2sVerb | DialogflowVerb | AgentVerb | ConferenceVerb | RoomVerb | TranscribeVerb | EnqueueVerb | DequeueVerb | DtmfVerb | DubVerb | HangupVerb | LeaveVerb | MessageVerb | PauseVerb | RedirectVerb | TagVerb | SipDeclineVerb | SipRequestVerb | SipReferVerb;
|
|
1071
|
+
type Verb = AnswerVerb | AlertVerb | ConfigVerb | SayVerb | PlayVerb | GatherVerb | DialVerb | ListenVerb | StreamVerb | LlmVerb | S2sVerb | OpenaiS2sVerb | GoogleS2sVerb | ElevenlabsS2sVerb | DeepgramS2sVerb | UltravoxS2sVerb | DialogflowVerb | AgentVerb | ConferenceVerb | RoomVerb | TranscribeVerb | EnqueueVerb | DequeueVerb | DtmfVerb | DubVerb | HangupVerb | LeaveVerb | MessageVerb | PauseVerb | RedirectVerb | TagVerb | SipDeclineVerb | SipRequestVerb | SipReferVerb | TransferVerb;
|
|
984
1072
|
/** A jambonz application — an array of verbs executed sequentially. */
|
|
985
1073
|
type JambonzApp = Verb[];
|
|
986
1074
|
/** All valid verb names. */
|
|
987
1075
|
type VerbName = Verb['verb'];
|
|
988
1076
|
|
|
989
|
-
export { type
|
|
1077
|
+
export { type Verb as $, type ActionHook as A, type BidirectionalAudio as B, type ConferenceVerb as C, type DequeueVerb as D, type EnqueueVerb as E, type FillerNoise as F, type GatherVerb as G, type Handoff as H, type SipDeclineVerb as I, type JambonzApp as J, type SipReferVerb as K, LLM_VENDORS as L, type McpServerConfig as M, type SipRequestVerb as N, type StreamVerb as O, type PauseVerb as P, type Synthesizer as Q, type Recognizer as R, type SayVerb as S, type TagVerb as T, type Target as U, type TranscribeVerb as V, type TransferConfirm as W, type TransferDisposition as X, type TransferOptions as Y, type TransferVerb as Z, type Vad as _, type ActionHookDelayAction as a, type VerbName as a0, type S2sVerb as a1, type LlmBaseOptions as a2, type DialogflowVerb as a3, type RoomVerb as a4, type ActionHookObject as b, type AgentLlm as c, type AgentLlmOptions as d, type AgentVerb as e, type AlertVerb as f, type Amd as g, type AmdTimers as h, type AnswerVerb as i, type Auth as j, type ConfigVerb as k, type DialVerb as l, type DtmfVerb as m, type DubVerb as n, type HangupVerb as o, type LeaveVerb as p, type ListenVerb as q, type LlmMessage as r, type LlmTool as s, type LlmToolOpenAIWrapped as t, type LlmToolOutputData as u, type LlmVendor as v, type LlmVerb as w, type MessageVerb as x, type PlayVerb as y, type RedirectVerb as z };
|
|
@@ -426,6 +426,8 @@ interface LlmBaseOptions {
|
|
|
426
426
|
toolHook?: ActionHook;
|
|
427
427
|
/** Event types to receive via eventHook. */
|
|
428
428
|
events?: string[];
|
|
429
|
+
/** Declarative transfer-to-human: injects a transfer tool and runs the packaged transfer when the model calls it. */
|
|
430
|
+
handoff?: Handoff;
|
|
429
431
|
}
|
|
430
432
|
interface LlmVerb extends LlmBaseOptions {
|
|
431
433
|
verb: 'llm';
|
|
@@ -530,6 +532,8 @@ interface AgentVerb {
|
|
|
530
532
|
eventHook?: ActionHook;
|
|
531
533
|
/** Webhook when the LLM requests a tool/function call. */
|
|
532
534
|
toolHook?: ActionHook;
|
|
535
|
+
/** Declarative transfer-to-human: injects a transfer tool and runs the packaged transfer when the model calls it. */
|
|
536
|
+
handoff?: Handoff;
|
|
533
537
|
/** Configuration for playing filler audio while tool calls are in progress. Prevents silence during long-running tool executions. */
|
|
534
538
|
toolFiller?: false | {
|
|
535
539
|
/** Filler mode. 'audio' plays a looping audio file. 'backchannel' uses TTS to speak short phrases. */
|
|
@@ -745,7 +749,9 @@ interface ConferenceVerb {
|
|
|
745
749
|
enterHook?: ActionHook;
|
|
746
750
|
/** Conference recording config. */
|
|
747
751
|
record?: Record<string, unknown>;
|
|
748
|
-
/**
|
|
752
|
+
/** Fork the room's mixed audio to a WebSocket. Prefer `stream`; `listen` is a synonym. */
|
|
753
|
+
stream?: Omit<StreamVerb, 'verb'>;
|
|
754
|
+
/** Audio streaming config (synonym for `stream`). */
|
|
749
755
|
listen?: Omit<ListenVerb, 'verb'>;
|
|
750
756
|
/** Distribute DTMF to all participants. */
|
|
751
757
|
distributeDtmf?: boolean;
|
|
@@ -846,6 +852,88 @@ interface SipReferVerb {
|
|
|
846
852
|
/** Webhook for NOTIFY progress events. */
|
|
847
853
|
eventHook?: ActionHook;
|
|
848
854
|
}
|
|
855
|
+
/** Per-outcome fallback actions when a transfer does not complete normally. */
|
|
856
|
+
interface TransferDisposition {
|
|
857
|
+
/** Action when the destination does not answer within timeout. Default: 'return'. */
|
|
858
|
+
onNoAnswer?: 'return' | 'voicemail' | 'hangup';
|
|
859
|
+
/** Action when the destination is busy. Default: 'return'. */
|
|
860
|
+
onBusy?: 'return' | 'voicemail' | 'hangup';
|
|
861
|
+
/** Action when the destination declines (confirm gate failed, AMD machine, or rejection). Default: 'return'. */
|
|
862
|
+
onDecline?: 'return' | 'voicemail' | 'hangup';
|
|
863
|
+
/** Action when a protocol-level error occurs on the destination leg. Default: 'return'. */
|
|
864
|
+
onFailure?: 'return' | 'voicemail' | 'hangup';
|
|
865
|
+
/** SIP URI or HTTP URL for voicemail. Required when any disposition value is 'voicemail'. */
|
|
866
|
+
voicemailUrl?: string;
|
|
867
|
+
}
|
|
868
|
+
/** Human-side acceptance gate: the destination must press a digit to accept. */
|
|
869
|
+
interface TransferConfirm {
|
|
870
|
+
/** Text or URL of the prompt played to the destination. */
|
|
871
|
+
prompt: string;
|
|
872
|
+
/** Single DTMF digit the destination must press to accept. */
|
|
873
|
+
digit: string;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Shared configuration for blind and warm transfer choreography. Reused by the
|
|
877
|
+
* `transfer` verb and the `handoff` block on conversational verbs.
|
|
878
|
+
*/
|
|
879
|
+
interface TransferOptions {
|
|
880
|
+
/** 'blind' hands off immediately; 'warm' lets the agent brief the destination first. */
|
|
881
|
+
mode: 'blind' | 'warm';
|
|
882
|
+
/** blind only: 'refer' sends a SIP REFER; 'dial' places a bridged outbound call. Default: 'refer'. */
|
|
883
|
+
blindMethod?: 'refer' | 'dial';
|
|
884
|
+
/** warm only: true = caller joins a three-way conference and hears the brief; false = caller is parked. Default: false. */
|
|
885
|
+
callerPresent?: boolean;
|
|
886
|
+
/** One or more destinations. All are rung simultaneously; first to answer wins. */
|
|
887
|
+
target: Target[];
|
|
888
|
+
/** Caller ID presented to the destination. */
|
|
889
|
+
callerId?: string;
|
|
890
|
+
/** warm/parked only: verbs for the parked caller while the agent briefs the destination. */
|
|
891
|
+
onHoldHook?: ActionHook;
|
|
892
|
+
/** Seconds to wait for the destination to answer before applying onNoAnswer. Default: 30. */
|
|
893
|
+
timeout?: number;
|
|
894
|
+
/** Optional human-side acceptance gate. */
|
|
895
|
+
confirm?: TransferConfirm;
|
|
896
|
+
/** warm only: optional answering-machine detection on the destination leg. */
|
|
897
|
+
amd?: Amd;
|
|
898
|
+
/** Per-outcome fallback actions. */
|
|
899
|
+
disposition?: TransferDisposition;
|
|
900
|
+
/** Fires when the transfer resolves (bridged, returned, voicemail, or failed). */
|
|
901
|
+
actionHook?: ActionHook;
|
|
902
|
+
/** Optional hook for in-progress transfer events (ringing, brief started). */
|
|
903
|
+
eventHook?: ActionHook;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Declarative transfer-to-human config for conversational verbs (`agent`, `llm`/`s2s`).
|
|
907
|
+
* The runtime injects a `transfer_to_human` tool and runs the packaged transfer
|
|
908
|
+
* choreography when the model calls it.
|
|
909
|
+
*/
|
|
910
|
+
interface Handoff extends TransferOptions {
|
|
911
|
+
/** 'auto' = LLM writes the summary; 'none' = no spoken brief; {template} = guidance for the summary. Default: 'auto'. */
|
|
912
|
+
brief?: 'auto' | 'none' | {
|
|
913
|
+
template: string;
|
|
914
|
+
};
|
|
915
|
+
/** Optional voice/vendor for the spoken brief. Defaults to the session synthesizer. */
|
|
916
|
+
briefSynthesizer?: Synthesizer;
|
|
917
|
+
/** Override the injected tool name. Default: 'transfer_to_human'. */
|
|
918
|
+
toolName?: string;
|
|
919
|
+
/** Override the injected tool description shown to the LLM. */
|
|
920
|
+
toolDescription?: string;
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Packaged blind and warm (parked / three-way) transfer with built-in failure
|
|
924
|
+
* handling. Composes {@link TransferOptions} for the shared choreography.
|
|
925
|
+
*/
|
|
926
|
+
interface TransferVerb extends TransferOptions {
|
|
927
|
+
verb: 'transfer';
|
|
928
|
+
id?: string;
|
|
929
|
+
/** warm only: the spoken summary delivered to the destination (human). */
|
|
930
|
+
brief?: {
|
|
931
|
+
/** The spoken briefing text. */
|
|
932
|
+
text: string;
|
|
933
|
+
/** Optional voice/vendor for the brief. Defaults to the session synthesizer. */
|
|
934
|
+
synthesizer?: Synthesizer;
|
|
935
|
+
};
|
|
936
|
+
}
|
|
849
937
|
interface ConfigVerb {
|
|
850
938
|
verb: 'config';
|
|
851
939
|
id?: string;
|
|
@@ -980,10 +1068,10 @@ interface MessageVerb {
|
|
|
980
1068
|
actionHook?: ActionHook;
|
|
981
1069
|
}
|
|
982
1070
|
/** Any jambonz verb. Discriminated on the 'verb' property. */
|
|
983
|
-
type Verb = AnswerVerb | AlertVerb | ConfigVerb | SayVerb | PlayVerb | GatherVerb | DialVerb | ListenVerb | StreamVerb | LlmVerb | S2sVerb | OpenaiS2sVerb | GoogleS2sVerb | ElevenlabsS2sVerb | DeepgramS2sVerb | UltravoxS2sVerb | DialogflowVerb | AgentVerb | ConferenceVerb | RoomVerb | TranscribeVerb | EnqueueVerb | DequeueVerb | DtmfVerb | DubVerb | HangupVerb | LeaveVerb | MessageVerb | PauseVerb | RedirectVerb | TagVerb | SipDeclineVerb | SipRequestVerb | SipReferVerb;
|
|
1071
|
+
type Verb = AnswerVerb | AlertVerb | ConfigVerb | SayVerb | PlayVerb | GatherVerb | DialVerb | ListenVerb | StreamVerb | LlmVerb | S2sVerb | OpenaiS2sVerb | GoogleS2sVerb | ElevenlabsS2sVerb | DeepgramS2sVerb | UltravoxS2sVerb | DialogflowVerb | AgentVerb | ConferenceVerb | RoomVerb | TranscribeVerb | EnqueueVerb | DequeueVerb | DtmfVerb | DubVerb | HangupVerb | LeaveVerb | MessageVerb | PauseVerb | RedirectVerb | TagVerb | SipDeclineVerb | SipRequestVerb | SipReferVerb | TransferVerb;
|
|
984
1072
|
/** A jambonz application — an array of verbs executed sequentially. */
|
|
985
1073
|
type JambonzApp = Verb[];
|
|
986
1074
|
/** All valid verb names. */
|
|
987
1075
|
type VerbName = Verb['verb'];
|
|
988
1076
|
|
|
989
|
-
export { type
|
|
1077
|
+
export { type Verb as $, type ActionHook as A, type BidirectionalAudio as B, type ConferenceVerb as C, type DequeueVerb as D, type EnqueueVerb as E, type FillerNoise as F, type GatherVerb as G, type Handoff as H, type SipDeclineVerb as I, type JambonzApp as J, type SipReferVerb as K, LLM_VENDORS as L, type McpServerConfig as M, type SipRequestVerb as N, type StreamVerb as O, type PauseVerb as P, type Synthesizer as Q, type Recognizer as R, type SayVerb as S, type TagVerb as T, type Target as U, type TranscribeVerb as V, type TransferConfirm as W, type TransferDisposition as X, type TransferOptions as Y, type TransferVerb as Z, type Vad as _, type ActionHookDelayAction as a, type VerbName as a0, type S2sVerb as a1, type LlmBaseOptions as a2, type DialogflowVerb as a3, type RoomVerb as a4, type ActionHookObject as b, type AgentLlm as c, type AgentLlmOptions as d, type AgentVerb as e, type AlertVerb as f, type Amd as g, type AmdTimers as h, type AnswerVerb as i, type Auth as j, type ConfigVerb as k, type DialVerb as l, type DtmfVerb as m, type DubVerb as n, type HangupVerb as o, type LeaveVerb as p, type ListenVerb as q, type LlmMessage as r, type LlmTool as s, type LlmToolOpenAIWrapped as t, type LlmToolOutputData as u, type LlmVendor as v, type LlmVerb as w, type MessageVerb as x, type PlayVerb as y, type RedirectVerb as z };
|
package/dist/webhook/index.cjs
CHANGED
|
@@ -222,6 +222,10 @@ var VerbBuilder = class {
|
|
|
222
222
|
sipRefer(opts) {
|
|
223
223
|
return this.addVerb({ verb: "sip:refer", ...opts });
|
|
224
224
|
}
|
|
225
|
+
/** Transfer the caller to a destination (blind, or warm parked/three-way) with built-in failure handling. */
|
|
226
|
+
transfer(opts) {
|
|
227
|
+
return this.addVerb({ verb: "transfer", ...opts });
|
|
228
|
+
}
|
|
225
229
|
// --- Utility ---
|
|
226
230
|
/** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */
|
|
227
231
|
config(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validator.ts","../../src/verb-builder.ts","../../src/webhook/response.ts","../../src/webhook/env-vars.ts"],"names":["createRequire","dir","resolve","existsSync","dirname","fileURLToPath","readdirSync","basename","readFileSync","Ajv","createHmac","timingSafeEqual"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAS,aAAA,GAAwB;AAE/B,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAMA,sBAAA,CAAc,2PAAe,CAAA;AACzC,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,OAAA,CAAQ,iBAAiB,CAAA;AACjD,IAAA,MAAMC,IAAAA,GAAMC,YAAA,CAAQ,WAAA,EAAa,IAAI,CAAA;AACrC,IAAA,IAAIC,aAAA,CAAWD,YAAA,CAAQD,IAAAA,EAAK,yBAAyB,CAAC,CAAA,EAAG;AACvD,MAAA,OAAOA,IAAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAGA,EAAA,MAAM,UAAA,GAAa,OAAO,SAAA,KAAc,WAAA,GACpC,YACAG,YAAA,CAAQC,iBAAA,CAAc,2PAAe,CAAC,CAAA;AAE1C,EAAA,IAAI,GAAA,GAAM,UAAA;AACV,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,EAAA,EAAI,CAAA,EAAA,EAAK;AAC3B,IAAA,MAAM,SA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AA,QACzD;AAEA,QAAA,IAAA,EAAK;AAAA,MACP,SAAS,GAAA,EAAK;AACZ,QAAA,IAAA,CAAK,GAAA,YAAe,QAAQ,GAAA,GAAM,IAAI,MAAM,MAAA,CAAO,GAAG,CAAC,CAAC,CAAA;AAAA,MAC1D;AAAA,IACF,CAAA;AAAA,EACF;AACF;;;AC9EO,SAAS,kBAAkB,MAAA,EAAsB;AACtD,EAAA,OAAO,CAAC,GAAA,EAAyB,GAAA,EAAwC,IAAA,KAAqB;AAC5F,IAAA,IAAI,GAAA,CAAI,WAAW,SAAA,EAAW;AAC5B,MAAA,GAAA,CAAI,KAAK,MAAM,CAAA;AACf,MAAA;AAAA,IACF;AACA,IAAA,IAAA,EAAK;AAAA,EACP,CAAA;AACF","file":"index.cjs","sourcesContent":["/**\n * Schema-based validation using AJV.\n * Loads all JSON schemas from the @jambonz/schema package.\n */\n\nimport Ajv, { type ValidateFunction, type ErrorObject } from 'ajv';\nimport { readFileSync, readdirSync, existsSync } from 'fs';\nimport { resolve, dirname, basename } from 'path';\nimport { fileURLToPath } from 'url';\nimport { createRequire } from 'module';\n\nexport interface ValidationResult {\n valid: boolean;\n errors: ValidationError[];\n}\n\nexport interface ValidationError {\n path: string;\n message: string;\n}\n\n/** Locate the @jambonz/schema package directory. */\nfunction findSchemaDir(): string {\n // Method 1: use createRequire to resolve the package\n try {\n const req = createRequire(import.meta.url);\n const schemaIndex = req.resolve('@jambonz/schema');\n const dir = resolve(schemaIndex, '..');\n if (existsSync(resolve(dir, 'jambonz-app.schema.json'))) {\n return dir;\n }\n } catch {\n // fall through\n }\n\n // Method 2: walk up from this file to find node_modules/@jambonz/schema\n const currentDir = typeof __dirname !== 'undefined'\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\n let dir = currentDir;\n for (let i = 0; i < 10; i++) {\n const candidate = resolve(dir, 'node_modules', '@jambonz', 'schema');\n if (existsSync(resolve(candidate, 'jambonz-app.schema.json'))) {\n return candidate;\n }\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n throw new Error(\n 'Could not find @jambonz/schema package. Ensure it is installed as a dependency.'\n );\n}\n\n/** Discover schema files in a subdirectory. */\nfunction discoverSchemas(dir: string): string[] {\n try {\n return readdirSync(dir)\n .filter((f) => f.endsWith('.schema.json'))\n .map((f) => basename(f, '.schema.json'));\n } catch {\n return [];\n }\n}\n\nfunction loadSchema(filePath: string): Record<string, unknown> {\n return JSON.parse(readFileSync(filePath, 'utf-8')) as Record<string, unknown>;\n}\n\nexport class JambonzValidator {\n private validateApp: ValidateFunction;\n private ajv: Ajv;\n\n constructor(schemaDir?: string) {\n const dir = schemaDir ?? findSchemaDir();\n this.ajv = new Ajv({\n allErrors: true,\n strict: false,\n validateSchema: false,\n logger: false,\n });\n\n // Register component schemas first (they are referenced by verb schemas)\n const componentsDir = resolve(dir, 'components');\n for (const name of discoverSchemas(componentsDir)) {\n const schema = loadSchema(resolve(componentsDir, `${name}.schema.json`));\n this.ajv.addSchema(schema);\n }\n\n // Register verb schemas\n const verbsDir = resolve(dir, 'verbs');\n for (const name of discoverSchemas(verbsDir)) {\n const schema = loadSchema(resolve(verbsDir, `${name}.schema.json`));\n this.ajv.addSchema(schema);\n }\n\n // Compile the root app schema\n const appSchema = loadSchema(resolve(dir, 'jambonz-app.schema.json'));\n this.validateApp = this.ajv.compile(appSchema);\n }\n\n /** Validate a complete verb array (a jambonz application). */\n validate(app: unknown): ValidationResult {\n const valid = this.validateApp(app);\n if (valid) {\n return { valid: true, errors: [] };\n }\n return {\n valid: false,\n errors: formatErrors(this.validateApp.errors),\n };\n }\n\n /** Validate a single verb object. */\n validateVerb(verb: unknown): ValidationResult {\n // Wrap in an array and validate as an app\n return this.validate([verb]);\n }\n}\n\nfunction formatErrors(errors: ErrorObject[] | null | undefined): ValidationError[] {\n if (!errors) return [];\n return errors.map((err) => ({\n path: err.instancePath || '/',\n message: err.message || 'Unknown validation error',\n }));\n}\n\nlet _defaultValidator: JambonzValidator | null = null;\n\n/** Get a shared validator instance. */\nexport function getValidator(schemaDir?: string): JambonzValidator {\n if (!_defaultValidator) {\n _defaultValidator = new JambonzValidator(schemaDir);\n }\n return _defaultValidator;\n}\n","/**\n * Shared VerbBuilder base class.\n * Provides typed verb methods and raw JSON input for both WebhookResponse and WS Session.\n */\n\nimport type {\n AgentVerb,\n AlertVerb,\n AnswerVerb,\n ConferenceVerb,\n ConfigVerb,\n DequeueVerb,\n DialogflowVerb,\n DialVerb,\n DtmfVerb,\n DubVerb,\n EnqueueVerb,\n GatherVerb,\n HangupVerb,\n LeaveVerb,\n ListenVerb,\n LlmBaseOptions,\n LlmVerb,\n MessageVerb,\n PauseVerb,\n PlayVerb,\n RedirectVerb,\n RoomVerb,\n S2sVerb,\n SayVerb,\n SipDeclineVerb,\n SipReferVerb,\n SipRequestVerb,\n StreamVerb,\n TagVerb,\n TranscribeVerb,\n Verb,\n} from './types/verbs.js';\nimport { JambonzValidator } from './validator.js';\n\nexport interface VerbBuilderOptions {\n /** Enable runtime schema validation. Default: true. */\n validate?: boolean;\n /** Path to schema directory. Auto-detected if omitted. */\n schemaDir?: string;\n}\n\n/**\n * Base class for building jambonz verb arrays. Extended by {@link WebhookResponse}\n * and WsSession. Provides typed verb methods and optional runtime schema validation.\n */\nexport class VerbBuilder {\n protected verbs: Verb[] = [];\n protected validator: JambonzValidator | null;\n\n /**\n * @param opts - Options for validation and schema directory.\n */\n constructor(opts?: VerbBuilderOptions) {\n if (opts?.validate === false) {\n this.validator = null;\n } else {\n this.validator = new JambonzValidator(opts?.schemaDir);\n }\n }\n\n // --- Audio & Speech ---\n\n /** Speak text using TTS. Supports SSML, multiple voices, and streaming. */\n say(opts: Omit<SayVerb, 'verb'>): this {\n return this.addVerb({ verb: 'say', ...opts });\n }\n\n /** Play an audio file from a URL. */\n play(opts: Omit<PlayVerb, 'verb'>): this {\n return this.addVerb({ verb: 'play', ...opts });\n }\n\n /** Collect speech (STT) and/or DTMF input from the caller. */\n gather(opts: Omit<GatherVerb, 'verb'>): this {\n return this.addVerb({ verb: 'gather', ...opts });\n }\n\n // --- AI & Real-time ---\n\n /** Connect the caller to an LLM for real-time voice conversation. */\n llm(opts: Omit<LlmVerb, 'verb'>): this {\n return this.addVerb({ verb: 'llm', ...opts });\n }\n\n /** Synonym for {@link llm}. Requires vendor to be specified. */\n s2s(opts: Omit<S2sVerb, 'verb'>): this {\n return this.addVerb({ verb: 's2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='openai'. */\n openai_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'openai_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='google'. */\n google_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'google_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='elevenlabs'. */\n elevenlabs_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'elevenlabs_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='deepgram'. */\n deepgram_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'deepgram_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='ultravox'. */\n ultravox_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'ultravox_s2s', ...opts });\n }\n\n /** Connect the caller to a Google Dialogflow agent (ES, CX, or CES). */\n dialogflow(opts: Omit<DialogflowVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dialogflow', ...opts });\n }\n\n /** Voice AI agent with integrated turn detection. */\n agent(opts: Omit<AgentVerb, 'verb'>): this {\n return this.addVerb({ verb: 'agent', ...opts });\n }\n\n /** Stream real-time call audio to a WebSocket endpoint. Supports bidirectional audio. */\n listen(opts: Omit<ListenVerb, 'verb'>): this {\n return this.addVerb({ verb: 'listen', ...opts });\n }\n\n /** Stream real-time call audio to a WebSocket endpoint. Synonym for {@link listen}. */\n stream(opts: Omit<StreamVerb, 'verb'>): this {\n return this.addVerb({ verb: 'stream', ...opts });\n }\n\n /** Real-time call transcription sent to a webhook. */\n transcribe(opts: Omit<TranscribeVerb, 'verb'>): this {\n return this.addVerb({ verb: 'transcribe', ...opts });\n }\n\n // --- Call Control ---\n\n /** Place an outbound call and bridge it to the current caller. */\n dial(opts: Omit<DialVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dial', ...opts });\n }\n\n /** Join or create a multi-party conference room. */\n conference(opts: Omit<ConferenceVerb, 'verb'>): this {\n return this.addVerb({ verb: 'conference', ...opts });\n }\n\n /** `room` is a synonym for `conference` — prefer it in new applications. */\n room(opts: Omit<RoomVerb, 'verb'>): this {\n return this.addVerb({ verb: 'room', ...opts });\n }\n\n /** Place the caller into a named queue. */\n enqueue(opts: Omit<EnqueueVerb, 'verb'>): this {\n return this.addVerb({ verb: 'enqueue', ...opts });\n }\n\n /** Remove a caller from a queue and bridge them. */\n dequeue(opts: Omit<DequeueVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dequeue', ...opts });\n }\n\n /** End the call. */\n hangup(opts?: Omit<HangupVerb, 'verb'>): this {\n return this.addVerb({ verb: 'hangup', ...opts });\n }\n\n /** Transfer control to a different webhook URL. */\n redirect(opts: Omit<RedirectVerb, 'verb'>): this {\n return this.addVerb({ verb: 'redirect', ...opts });\n }\n\n /** Wait for a specified duration before continuing. */\n pause(opts: Omit<PauseVerb, 'verb'>): this {\n return this.addVerb({ verb: 'pause', ...opts });\n }\n\n /** Leave a conference or queue. */\n leave(opts?: Omit<LeaveVerb, 'verb'>): this {\n return this.addVerb({ verb: 'leave', ...opts });\n }\n\n // --- SIP ---\n\n /** Reject an incoming call with a SIP error response. */\n sipDecline(opts: Omit<SipDeclineVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:decline', ...opts });\n }\n\n /** Send a SIP INFO or other request within the dialog. */\n sipRequest(opts: Omit<SipRequestVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:request', ...opts });\n }\n\n /** Transfer the call via SIP REFER. */\n sipRefer(opts: Omit<SipReferVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:refer', ...opts });\n }\n\n // --- Utility ---\n\n /** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */\n config(opts: Omit<ConfigVerb, 'verb'>): this {\n return this.addVerb({ verb: 'config', ...opts });\n }\n\n /** Explicitly answer the call (sends a 200 OK). */\n answer(opts?: Omit<AnswerVerb, 'verb'>): this {\n return this.addVerb({ verb: 'answer', ...opts });\n }\n\n /** Send a SIP 180 Ringing with optional Alert-Info header. */\n alert(opts: Omit<AlertVerb, 'verb'>): this {\n return this.addVerb({ verb: 'alert', ...opts });\n }\n\n /** Attach metadata to the call for tracking or routing. */\n tag(opts: Omit<TagVerb, 'verb'>): this {\n return this.addVerb({ verb: 'tag', ...opts });\n }\n\n /** Send DTMF tones into the call. */\n dtmf(opts: Omit<DtmfVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dtmf', ...opts });\n }\n\n /** Mix an auxiliary audio track into the call. */\n dub(opts: Omit<DubVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dub', ...opts });\n }\n\n /** Send an SMS or MMS message. */\n message(opts: Omit<MessageVerb, 'verb'>): this {\n return this.addVerb({ verb: 'message', ...opts });\n }\n\n // --- Raw JSON input (primary AI agent path) ---\n\n /**\n * Add one or more verbs from raw JSON.\n * Validates against the JSON schemas at runtime if validation is enabled.\n */\n addVerbs(verbs: Verb[]): this {\n if (this.validator) {\n const result = this.validator.validate(verbs);\n if (!result.valid) {\n const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join('; ');\n throw new Error(`Verb validation failed: ${messages}`);\n }\n }\n this.verbs.push(...verbs);\n return this;\n }\n\n // --- Internal ---\n\n protected addVerb(verb: Verb): this {\n if (this.validator) {\n const result = this.validator.validateVerb(verb);\n if (!result.valid) {\n const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join('; ');\n throw new Error(`Verb '${verb.verb}' validation failed: ${messages}`);\n }\n }\n this.verbs.push(verb);\n return this;\n }\n\n /** Get the current verb count. */\n get length(): number {\n return this.verbs.length;\n }\n\n /** Clear all queued verbs. */\n clear(): this {\n this.verbs = [];\n return this;\n }\n\n /** Returns a copy of the current verb array. */\n toJSON(): Verb[] {\n return [...this.verbs];\n }\n}\n","/**\n * WebhookResponse — verb builder for HTTP webhook applications.\n * Extends VerbBuilder with toJSON() and signature verification.\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto';\nimport { VerbBuilder, type VerbBuilderOptions } from '../verb-builder.js';\nimport type { JambonzApp } from '../types/verbs.js';\nimport type { IncomingMessage, ServerResponse } from 'http';\n\n/**\n * Verb builder for HTTP webhook applications.\n * Construct one per request, chain verb methods, and pass to `res.json()`.\n *\n * @example\n * ```typescript\n * app.post('/incoming', (req, res) => {\n * const jambonz = new WebhookResponse();\n * jambonz.say({ text: 'Hello!' }).hangup();\n * res.json(jambonz);\n * });\n * ```\n */\nexport class WebhookResponse extends VerbBuilder {\n /** @param opts - Options for validation and schema directory. */\n constructor(opts?: VerbBuilderOptions) {\n super(opts);\n }\n\n /** Returns the verb array for JSON serialization. */\n toJSON(): JambonzApp {\n return [...this.verbs];\n }\n\n /**\n * Express-compatible middleware for verifying jambonz webhook signatures.\n * Uses HMAC-SHA256 with timing-safe comparison.\n */\n static verifySignature(secret: string, opts?: { tolerance?: number }) {\n const tolerance = opts?.tolerance ?? 300; // 5 minutes default\n\n return (\n req: IncomingMessage & { body?: unknown; rawBody?: Buffer },\n _res: ServerResponse,\n next: (err?: Error) => void\n ) => {\n try {\n const signature = (req.headers as Record<string, string | undefined>)['jambonz-signature'];\n if (!signature) {\n throw new Error('Missing Jambonz-Signature header');\n }\n\n const parts = signature.split(',');\n let timestamp = '';\n const signatures: string[] = [];\n\n for (const part of parts) {\n const [key, value] = part.split('=');\n if (key === 't') timestamp = value;\n else if (key === 'v1') signatures.push(value);\n }\n\n if (!timestamp || signatures.length === 0) {\n throw new Error('Invalid Jambonz-Signature format');\n }\n\n // Check timestamp tolerance\n const ts = parseInt(timestamp, 10);\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > tolerance) {\n throw new Error('Webhook signature timestamp outside tolerance');\n }\n\n // Compute expected signature\n const payload = typeof req.body === 'string'\n ? req.body\n : JSON.stringify(req.body);\n const signedPayload = `${timestamp}.${payload}`;\n const expected = createHmac('sha256', secret)\n .update(signedPayload)\n .digest('hex');\n\n // Timing-safe comparison\n const matched = signatures.some((sig) => {\n try {\n return timingSafeEqual(Buffer.from(sig), Buffer.from(expected));\n } catch {\n return false;\n }\n });\n\n if (!matched) {\n throw new Error('Webhook signature verification failed');\n }\n\n next();\n } catch (err) {\n next(err instanceof Error ? err : new Error(String(err)));\n }\n };\n }\n}\n","/**\n * Express middleware that auto-responds to HTTP OPTIONS requests with the\n * application environment variables schema for jambonz portal discovery.\n */\n\nimport type { EnvVarSchema } from '../types/common.js';\n\n/**\n * Express middleware that auto-responds to HTTP OPTIONS requests with the\n * application's environment variable schema, enabling jambonz portal discovery.\n *\n * @param schema - The environment variable schema to expose.\n *\n * @example\n * ```typescript\n * import { envVarsMiddleware } from '@jambonz/sdk/webhook';\n *\n * const envVars = {\n * API_KEY: { type: 'string', description: 'Your API key', required: true },\n * };\n * app.use(envVarsMiddleware(envVars));\n * ```\n */\nexport function envVarsMiddleware(schema: EnvVarSchema) {\n return (req: { method: string }, res: { json: (body: unknown) => void }, next: () => void) => {\n if (req.method === 'OPTIONS') {\n res.json(schema);\n return;\n }\n next();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/validator.ts","../../src/verb-builder.ts","../../src/webhook/response.ts","../../src/webhook/env-vars.ts"],"names":["createRequire","dir","resolve","existsSync","dirname","fileURLToPath","readdirSync","basename","readFileSync","Ajv","createHmac","timingSafeEqual"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAS,aAAA,GAAwB;AAE/B,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GA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using AJV.\n * Loads all JSON schemas from the @jambonz/schema package.\n */\n\nimport Ajv, { type ValidateFunction, type ErrorObject } from 'ajv';\nimport { readFileSync, readdirSync, existsSync } from 'fs';\nimport { resolve, dirname, basename } from 'path';\nimport { fileURLToPath } from 'url';\nimport { createRequire } from 'module';\n\nexport interface ValidationResult {\n valid: boolean;\n errors: ValidationError[];\n}\n\nexport interface ValidationError {\n path: string;\n message: string;\n}\n\n/** Locate the @jambonz/schema package directory. */\nfunction findSchemaDir(): string {\n // Method 1: use createRequire to resolve the package\n try {\n const req = createRequire(import.meta.url);\n const schemaIndex = req.resolve('@jambonz/schema');\n const dir = resolve(schemaIndex, '..');\n if (existsSync(resolve(dir, 'jambonz-app.schema.json'))) {\n return dir;\n }\n } catch {\n // fall through\n }\n\n // Method 2: walk up from this file to find node_modules/@jambonz/schema\n const currentDir = typeof __dirname !== 'undefined'\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\n let dir = currentDir;\n for (let i = 0; i < 10; i++) {\n const candidate = resolve(dir, 'node_modules', '@jambonz', 'schema');\n if (existsSync(resolve(candidate, 'jambonz-app.schema.json'))) {\n return candidate;\n }\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n throw new Error(\n 'Could not find @jambonz/schema package. Ensure it is installed as a dependency.'\n );\n}\n\n/** Discover schema files in a subdirectory. */\nfunction discoverSchemas(dir: string): string[] {\n try {\n return readdirSync(dir)\n .filter((f) => f.endsWith('.schema.json'))\n .map((f) => basename(f, '.schema.json'));\n } catch {\n return [];\n }\n}\n\nfunction loadSchema(filePath: string): Record<string, unknown> {\n return JSON.parse(readFileSync(filePath, 'utf-8')) as Record<string, unknown>;\n}\n\nexport class JambonzValidator {\n private validateApp: ValidateFunction;\n private ajv: Ajv;\n\n constructor(schemaDir?: string) {\n const dir = schemaDir ?? findSchemaDir();\n this.ajv = new Ajv({\n allErrors: true,\n strict: false,\n validateSchema: false,\n logger: false,\n });\n\n // Register component schemas first (they are referenced by verb schemas)\n const componentsDir = resolve(dir, 'components');\n for (const name of discoverSchemas(componentsDir)) {\n const schema = loadSchema(resolve(componentsDir, `${name}.schema.json`));\n this.ajv.addSchema(schema);\n }\n\n // Register verb schemas\n const verbsDir = resolve(dir, 'verbs');\n for (const name of discoverSchemas(verbsDir)) {\n const schema = loadSchema(resolve(verbsDir, `${name}.schema.json`));\n this.ajv.addSchema(schema);\n }\n\n // Compile the root app schema\n const appSchema = loadSchema(resolve(dir, 'jambonz-app.schema.json'));\n this.validateApp = this.ajv.compile(appSchema);\n }\n\n /** Validate a complete verb array (a jambonz application). */\n validate(app: unknown): ValidationResult {\n const valid = this.validateApp(app);\n if (valid) {\n return { valid: true, errors: [] };\n }\n return {\n valid: false,\n errors: formatErrors(this.validateApp.errors),\n };\n }\n\n /** Validate a single verb object. */\n validateVerb(verb: unknown): ValidationResult {\n // Wrap in an array and validate as an app\n return this.validate([verb]);\n }\n}\n\nfunction formatErrors(errors: ErrorObject[] | null | undefined): ValidationError[] {\n if (!errors) return [];\n return errors.map((err) => ({\n path: err.instancePath || '/',\n message: err.message || 'Unknown validation error',\n }));\n}\n\nlet _defaultValidator: JambonzValidator | null = null;\n\n/** Get a shared validator instance. */\nexport function getValidator(schemaDir?: string): JambonzValidator {\n if (!_defaultValidator) {\n _defaultValidator = new JambonzValidator(schemaDir);\n }\n return _defaultValidator;\n}\n","/**\n * Shared VerbBuilder base class.\n * Provides typed verb methods and raw JSON input for both WebhookResponse and WS Session.\n */\n\nimport type {\n AgentVerb,\n AlertVerb,\n AnswerVerb,\n ConferenceVerb,\n ConfigVerb,\n DequeueVerb,\n DialogflowVerb,\n DialVerb,\n DtmfVerb,\n DubVerb,\n EnqueueVerb,\n GatherVerb,\n HangupVerb,\n LeaveVerb,\n ListenVerb,\n LlmBaseOptions,\n LlmVerb,\n MessageVerb,\n PauseVerb,\n PlayVerb,\n RedirectVerb,\n RoomVerb,\n S2sVerb,\n SayVerb,\n SipDeclineVerb,\n SipReferVerb,\n SipRequestVerb,\n StreamVerb,\n TagVerb,\n TranscribeVerb,\n TransferVerb,\n Verb,\n} from './types/verbs.js';\nimport { JambonzValidator } from './validator.js';\n\nexport interface VerbBuilderOptions {\n /** Enable runtime schema validation. Default: true. */\n validate?: boolean;\n /** Path to schema directory. Auto-detected if omitted. */\n schemaDir?: string;\n}\n\n/**\n * Base class for building jambonz verb arrays. Extended by {@link WebhookResponse}\n * and WsSession. Provides typed verb methods and optional runtime schema validation.\n */\nexport class VerbBuilder {\n protected verbs: Verb[] = [];\n protected validator: JambonzValidator | null;\n\n /**\n * @param opts - Options for validation and schema directory.\n */\n constructor(opts?: VerbBuilderOptions) {\n if (opts?.validate === false) {\n this.validator = null;\n } else {\n this.validator = new JambonzValidator(opts?.schemaDir);\n }\n }\n\n // --- Audio & Speech ---\n\n /** Speak text using TTS. Supports SSML, multiple voices, and streaming. */\n say(opts: Omit<SayVerb, 'verb'>): this {\n return this.addVerb({ verb: 'say', ...opts });\n }\n\n /** Play an audio file from a URL. */\n play(opts: Omit<PlayVerb, 'verb'>): this {\n return this.addVerb({ verb: 'play', ...opts });\n }\n\n /** Collect speech (STT) and/or DTMF input from the caller. */\n gather(opts: Omit<GatherVerb, 'verb'>): this {\n return this.addVerb({ verb: 'gather', ...opts });\n }\n\n // --- AI & Real-time ---\n\n /** Connect the caller to an LLM for real-time voice conversation. */\n llm(opts: Omit<LlmVerb, 'verb'>): this {\n return this.addVerb({ verb: 'llm', ...opts });\n }\n\n /** Synonym for {@link llm}. Requires vendor to be specified. */\n s2s(opts: Omit<S2sVerb, 'verb'>): this {\n return this.addVerb({ verb: 's2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='openai'. */\n openai_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'openai_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='google'. */\n google_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'google_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='elevenlabs'. */\n elevenlabs_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'elevenlabs_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='deepgram'. */\n deepgram_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'deepgram_s2s', ...opts });\n }\n\n /** Shortcut for s2s with vendor='ultravox'. */\n ultravox_s2s(opts: Omit<LlmBaseOptions, 'vendor'>): this {\n return this.addVerb({ verb: 'ultravox_s2s', ...opts });\n }\n\n /** Connect the caller to a Google Dialogflow agent (ES, CX, or CES). */\n dialogflow(opts: Omit<DialogflowVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dialogflow', ...opts });\n }\n\n /** Voice AI agent with integrated turn detection. */\n agent(opts: Omit<AgentVerb, 'verb'>): this {\n return this.addVerb({ verb: 'agent', ...opts });\n }\n\n /** Stream real-time call audio to a WebSocket endpoint. Supports bidirectional audio. */\n listen(opts: Omit<ListenVerb, 'verb'>): this {\n return this.addVerb({ verb: 'listen', ...opts });\n }\n\n /** Stream real-time call audio to a WebSocket endpoint. Synonym for {@link listen}. */\n stream(opts: Omit<StreamVerb, 'verb'>): this {\n return this.addVerb({ verb: 'stream', ...opts });\n }\n\n /** Real-time call transcription sent to a webhook. */\n transcribe(opts: Omit<TranscribeVerb, 'verb'>): this {\n return this.addVerb({ verb: 'transcribe', ...opts });\n }\n\n // --- Call Control ---\n\n /** Place an outbound call and bridge it to the current caller. */\n dial(opts: Omit<DialVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dial', ...opts });\n }\n\n /** Join or create a multi-party conference room. */\n conference(opts: Omit<ConferenceVerb, 'verb'>): this {\n return this.addVerb({ verb: 'conference', ...opts });\n }\n\n /** `room` is a synonym for `conference` — prefer it in new applications. */\n room(opts: Omit<RoomVerb, 'verb'>): this {\n return this.addVerb({ verb: 'room', ...opts });\n }\n\n /** Place the caller into a named queue. */\n enqueue(opts: Omit<EnqueueVerb, 'verb'>): this {\n return this.addVerb({ verb: 'enqueue', ...opts });\n }\n\n /** Remove a caller from a queue and bridge them. */\n dequeue(opts: Omit<DequeueVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dequeue', ...opts });\n }\n\n /** End the call. */\n hangup(opts?: Omit<HangupVerb, 'verb'>): this {\n return this.addVerb({ verb: 'hangup', ...opts });\n }\n\n /** Transfer control to a different webhook URL. */\n redirect(opts: Omit<RedirectVerb, 'verb'>): this {\n return this.addVerb({ verb: 'redirect', ...opts });\n }\n\n /** Wait for a specified duration before continuing. */\n pause(opts: Omit<PauseVerb, 'verb'>): this {\n return this.addVerb({ verb: 'pause', ...opts });\n }\n\n /** Leave a conference or queue. */\n leave(opts?: Omit<LeaveVerb, 'verb'>): this {\n return this.addVerb({ verb: 'leave', ...opts });\n }\n\n // --- SIP ---\n\n /** Reject an incoming call with a SIP error response. */\n sipDecline(opts: Omit<SipDeclineVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:decline', ...opts });\n }\n\n /** Send a SIP INFO or other request within the dialog. */\n sipRequest(opts: Omit<SipRequestVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:request', ...opts });\n }\n\n /** Transfer the call via SIP REFER. */\n sipRefer(opts: Omit<SipReferVerb, 'verb'>): this {\n return this.addVerb({ verb: 'sip:refer', ...opts });\n }\n\n /** Transfer the caller to a destination (blind, or warm parked/three-way) with built-in failure handling. */\n transfer(opts: Omit<TransferVerb, 'verb'>): this {\n return this.addVerb({ verb: 'transfer', ...opts });\n }\n\n // --- Utility ---\n\n /** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */\n config(opts: Omit<ConfigVerb, 'verb'>): this {\n return this.addVerb({ verb: 'config', ...opts });\n }\n\n /** Explicitly answer the call (sends a 200 OK). */\n answer(opts?: Omit<AnswerVerb, 'verb'>): this {\n return this.addVerb({ verb: 'answer', ...opts });\n }\n\n /** Send a SIP 180 Ringing with optional Alert-Info header. */\n alert(opts: Omit<AlertVerb, 'verb'>): this {\n return this.addVerb({ verb: 'alert', ...opts });\n }\n\n /** Attach metadata to the call for tracking or routing. */\n tag(opts: Omit<TagVerb, 'verb'>): this {\n return this.addVerb({ verb: 'tag', ...opts });\n }\n\n /** Send DTMF tones into the call. */\n dtmf(opts: Omit<DtmfVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dtmf', ...opts });\n }\n\n /** Mix an auxiliary audio track into the call. */\n dub(opts: Omit<DubVerb, 'verb'>): this {\n return this.addVerb({ verb: 'dub', ...opts });\n }\n\n /** Send an SMS or MMS message. */\n message(opts: Omit<MessageVerb, 'verb'>): this {\n return this.addVerb({ verb: 'message', ...opts });\n }\n\n // --- Raw JSON input (primary AI agent path) ---\n\n /**\n * Add one or more verbs from raw JSON.\n * Validates against the JSON schemas at runtime if validation is enabled.\n */\n addVerbs(verbs: Verb[]): this {\n if (this.validator) {\n const result = this.validator.validate(verbs);\n if (!result.valid) {\n const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join('; ');\n throw new Error(`Verb validation failed: ${messages}`);\n }\n }\n this.verbs.push(...verbs);\n return this;\n }\n\n // --- Internal ---\n\n protected addVerb(verb: Verb): this {\n if (this.validator) {\n const result = this.validator.validateVerb(verb);\n if (!result.valid) {\n const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join('; ');\n throw new Error(`Verb '${verb.verb}' validation failed: ${messages}`);\n }\n }\n this.verbs.push(verb);\n return this;\n }\n\n /** Get the current verb count. */\n get length(): number {\n return this.verbs.length;\n }\n\n /** Clear all queued verbs. */\n clear(): this {\n this.verbs = [];\n return this;\n }\n\n /** Returns a copy of the current verb array. */\n toJSON(): Verb[] {\n return [...this.verbs];\n }\n}\n","/**\n * WebhookResponse — verb builder for HTTP webhook applications.\n * Extends VerbBuilder with toJSON() and signature verification.\n */\n\nimport { createHmac, timingSafeEqual } from 'crypto';\nimport { VerbBuilder, type VerbBuilderOptions } from '../verb-builder.js';\nimport type { JambonzApp } from '../types/verbs.js';\nimport type { IncomingMessage, ServerResponse } from 'http';\n\n/**\n * Verb builder for HTTP webhook applications.\n * Construct one per request, chain verb methods, and pass to `res.json()`.\n *\n * @example\n * ```typescript\n * app.post('/incoming', (req, res) => {\n * const jambonz = new WebhookResponse();\n * jambonz.say({ text: 'Hello!' }).hangup();\n * res.json(jambonz);\n * });\n * ```\n */\nexport class WebhookResponse extends VerbBuilder {\n /** @param opts - Options for validation and schema directory. */\n constructor(opts?: VerbBuilderOptions) {\n super(opts);\n }\n\n /** Returns the verb array for JSON serialization. */\n toJSON(): JambonzApp {\n return [...this.verbs];\n }\n\n /**\n * Express-compatible middleware for verifying jambonz webhook signatures.\n * Uses HMAC-SHA256 with timing-safe comparison.\n */\n static verifySignature(secret: string, opts?: { tolerance?: number }) {\n const tolerance = opts?.tolerance ?? 300; // 5 minutes default\n\n return (\n req: IncomingMessage & { body?: unknown; rawBody?: Buffer },\n _res: ServerResponse,\n next: (err?: Error) => void\n ) => {\n try {\n const signature = (req.headers as Record<string, string | undefined>)['jambonz-signature'];\n if (!signature) {\n throw new Error('Missing Jambonz-Signature header');\n }\n\n const parts = signature.split(',');\n let timestamp = '';\n const signatures: string[] = [];\n\n for (const part of parts) {\n const [key, value] = part.split('=');\n if (key === 't') timestamp = value;\n else if (key === 'v1') signatures.push(value);\n }\n\n if (!timestamp || signatures.length === 0) {\n throw new Error('Invalid Jambonz-Signature format');\n }\n\n // Check timestamp tolerance\n const ts = parseInt(timestamp, 10);\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > tolerance) {\n throw new Error('Webhook signature timestamp outside tolerance');\n }\n\n // Compute expected signature\n const payload = typeof req.body === 'string'\n ? req.body\n : JSON.stringify(req.body);\n const signedPayload = `${timestamp}.${payload}`;\n const expected = createHmac('sha256', secret)\n .update(signedPayload)\n .digest('hex');\n\n // Timing-safe comparison\n const matched = signatures.some((sig) => {\n try {\n return timingSafeEqual(Buffer.from(sig), Buffer.from(expected));\n } catch {\n return false;\n }\n });\n\n if (!matched) {\n throw new Error('Webhook signature verification failed');\n }\n\n next();\n } catch (err) {\n next(err instanceof Error ? err : new Error(String(err)));\n }\n };\n }\n}\n","/**\n * Express middleware that auto-responds to HTTP OPTIONS requests with the\n * application environment variables schema for jambonz portal discovery.\n */\n\nimport type { EnvVarSchema } from '../types/common.js';\n\n/**\n * Express middleware that auto-responds to HTTP OPTIONS requests with the\n * application's environment variable schema, enabling jambonz portal discovery.\n *\n * @param schema - The environment variable schema to expose.\n *\n * @example\n * ```typescript\n * import { envVarsMiddleware } from '@jambonz/sdk/webhook';\n *\n * const envVars = {\n * API_KEY: { type: 'string', description: 'Your API key', required: true },\n * };\n * app.use(envVarsMiddleware(envVars));\n * ```\n */\nexport function envVarsMiddleware(schema: EnvVarSchema) {\n return (req: { method: string }, res: { json: (body: unknown) => void }, next: () => void) => {\n if (req.method === 'OPTIONS') {\n res.json(schema);\n return;\n }\n next();\n };\n}\n"]}
|
package/dist/webhook/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as VerbBuilder, c as VerbBuilderOptions } from '../verb-builder-
|
|
2
|
-
import { J as JambonzApp } from '../verbs-
|
|
1
|
+
import { b as VerbBuilder, c as VerbBuilderOptions } from '../verb-builder-BjrRSray.cjs';
|
|
2
|
+
import { J as JambonzApp } from '../verbs-DXbSDMKR.cjs';
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import { a as EnvVarSchema } from '../common-BSJZX7WO.cjs';
|
|
5
5
|
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as VerbBuilder, c as VerbBuilderOptions } from '../verb-builder-
|
|
2
|
-
import { J as JambonzApp } from '../verbs-
|
|
1
|
+
import { b as VerbBuilder, c as VerbBuilderOptions } from '../verb-builder-C5tteeud.js';
|
|
2
|
+
import { J as JambonzApp } from '../verbs-DXbSDMKR.js';
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import { a as EnvVarSchema } from '../common-BSJZX7WO.js';
|
|
5
5
|
|
package/dist/webhook/index.js
CHANGED
|
@@ -215,6 +215,10 @@ var VerbBuilder = class {
|
|
|
215
215
|
sipRefer(opts) {
|
|
216
216
|
return this.addVerb({ verb: "sip:refer", ...opts });
|
|
217
217
|
}
|
|
218
|
+
/** Transfer the caller to a destination (blind, or warm parked/three-way) with built-in failure handling. */
|
|
219
|
+
transfer(opts) {
|
|
220
|
+
return this.addVerb({ verb: "transfer", ...opts });
|
|
221
|
+
}
|
|
218
222
|
// --- Utility ---
|
|
219
223
|
/** Set session-level defaults (TTS vendor/voice, STT vendor, VAD, etc.). */
|
|
220
224
|
config(opts) {
|