@sinch/functions-runtime 0.6.0 → 0.6.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/README.md +22 -5
- package/dist/bin/sinch-runtime.js +1 -1
- package/dist/{chunk-TOTJB6SW.js → chunk-DHM4MH2A.js} +584 -60
- package/dist/chunk-DHM4MH2A.js.map +1 -0
- package/dist/index.d.ts +200 -8
- package/dist/index.js +1 -1
- package/dist/voice/v2.d.ts +97 -8
- package/dist/voice/v2.js +1 -3
- package/package.json +1 -1
- package/dist/chunk-TOTJB6SW.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1716,6 +1716,15 @@ export interface FlowScope {
|
|
|
1716
1716
|
readonly joined?: string;
|
|
1717
1717
|
/** Legs dialled under this scope that the call-level `onHangup` must end. Shared by copies. */
|
|
1718
1718
|
readonly dialled: Set<string>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Every leg name used anywhere in this response's command tree so far, including a dial's
|
|
1721
|
+
* own leg before its nested outcome flows (`onBusy`, `onNoAnswer`, ...) are resolved — that
|
|
1722
|
+
* is what lets a fallback dial nested inside one of them see the outer leg's name and step
|
|
1723
|
+
* past it. Shared by copies, unlike {@link dialled} this is never gated on {@link namesLiveLeg}:
|
|
1724
|
+
* a repeat default has to be caught in a `call.answered` or `call.menu` response too, even
|
|
1725
|
+
* though neither carries a call-level `onHangup`.
|
|
1726
|
+
*/
|
|
1727
|
+
readonly usedNames: Set<string>;
|
|
1719
1728
|
}
|
|
1720
1729
|
/** Options for a single TTS message */
|
|
1721
1730
|
export interface SayOptions {
|
|
@@ -1793,7 +1802,17 @@ export interface BridgeToOptions {
|
|
|
1793
1802
|
timeout?: number;
|
|
1794
1803
|
/** Maximum call duration in seconds. Maximum 14400. */
|
|
1795
1804
|
maxDuration?: number;
|
|
1796
|
-
/**
|
|
1805
|
+
/**
|
|
1806
|
+
* Name for the dialled leg. Defaults by destination: `destination`, `stream` or `relay`. A
|
|
1807
|
+
* second dial with no `legName` that lands on the same default within one call flow — a
|
|
1808
|
+
* nested fallback in `onBusy`/`onTimeout`, or a sibling `dial*` call — gets `-2`, `-3`, and
|
|
1809
|
+
* so on instead of colliding.
|
|
1810
|
+
*
|
|
1811
|
+
* Voice v2 requires `callName` to stay unique over the call's *whole lifetime*, not just
|
|
1812
|
+
* within the commands built here — dialling again on a call that already has a leg by this
|
|
1813
|
+
* default name, such as from a later `PATCH`, needs an explicit `legName` to avoid a 500
|
|
1814
|
+
* with the leg stuck `QUEUED`.
|
|
1815
|
+
*/
|
|
1797
1816
|
legName?: string;
|
|
1798
1817
|
/** Bridge both legs join. Defaults to `bridge`; name another for a hold room or a whisper. */
|
|
1799
1818
|
bridgeName?: string;
|
|
@@ -2163,6 +2182,13 @@ export declare class CommandBuilder {
|
|
|
2163
2182
|
* Never answers the live leg: answering commits billing and forfeits ringback, so an inbound
|
|
2164
2183
|
* call that should be answered first says so with {@link answer}.
|
|
2165
2184
|
*
|
|
2185
|
+
* Voice v2 requires `callName` to be unique over the call's whole lifetime, not just within
|
|
2186
|
+
* this response. Leaving `legName` unset is safe within one response — a repeat of the same
|
|
2187
|
+
* default here, including a fallback dial nested in `onBusy`/`onTimeout`/etc., is numbered
|
|
2188
|
+
* (`destination-2`, `destination-3`, ...) instead of colliding — but dialling again on a
|
|
2189
|
+
* call that a previous response or `PATCH` already gave that default name needs an explicit
|
|
2190
|
+
* `legName`, or the platform returns a 500 with the leg stuck `QUEUED`.
|
|
2191
|
+
*
|
|
2166
2192
|
* @param destination - Who to connect
|
|
2167
2193
|
* @param options - Leg and bridge names, `from`, timeouts, and what happens on no answer
|
|
2168
2194
|
*/
|
|
@@ -2170,6 +2196,9 @@ export declare class CommandBuilder {
|
|
|
2170
2196
|
/**
|
|
2171
2197
|
* Connect the caller to a phone number. `from` defaults to the Sinch number the call is on.
|
|
2172
2198
|
*
|
|
2199
|
+
* See {@link bridgeTo} for how `legName` is defaulted and numbered on a repeat, and when it
|
|
2200
|
+
* needs to be passed explicitly.
|
|
2201
|
+
*
|
|
2173
2202
|
* @param number - E.164 number
|
|
2174
2203
|
* @param options - See {@link BridgeToOptions}
|
|
2175
2204
|
*
|
|
@@ -2318,6 +2347,10 @@ export declare class CommandBuilder {
|
|
|
2318
2347
|
* arrives as `'call.webhook.escalate'`. `Client.onCall` routes those by name to a handler
|
|
2319
2348
|
* registered under `webhooks`, and to `manage` when no name matches.
|
|
2320
2349
|
*
|
|
2350
|
+
* Like a dial's `callName` and `startRecording`'s `recordingName`, `webhookName` must be
|
|
2351
|
+
* unique for the session's whole lifetime — a flow that repeats across requests (a retry, a
|
|
2352
|
+
* second pass through the same command builder) needs a different name each time it does.
|
|
2353
|
+
*
|
|
2321
2354
|
* @param webhookName - Name for this event (1-64 chars, no whitespace)
|
|
2322
2355
|
* @param url - URL to call. The platform allows it 5 seconds to answer.
|
|
2323
2356
|
* @param options - Fallback URL
|
|
@@ -2339,6 +2372,10 @@ export declare class CommandBuilder {
|
|
|
2339
2372
|
* schema requires it and offers no short-lived alternative. See {@link RecordingCredentials}
|
|
2340
2373
|
* before logging anything a `startRecording` is part of.
|
|
2341
2374
|
*
|
|
2375
|
+
* Like a dial's `callName` and `webhook`'s `webhookName`, `recordingName` must be unique for
|
|
2376
|
+
* the session's whole lifetime — a flow that repeats across requests (a retry, a second pass
|
|
2377
|
+
* through the same command builder) needs a different name each time it does.
|
|
2378
|
+
*
|
|
2342
2379
|
* @param options - Destination, credentials, encoding, transcription and outcome events
|
|
2343
2380
|
* @throws If a structured credential component contains a colon
|
|
2344
2381
|
*
|
|
@@ -2479,7 +2516,6 @@ export type CompletedCall = Flattened<{
|
|
|
2479
2516
|
}>;
|
|
2480
2517
|
declare function toCallEvent(request: WebhookRequest): CallEvent;
|
|
2481
2518
|
declare function toWebhookRequest(call: CallEvent | WebhookRequest): WebhookRequest;
|
|
2482
|
-
declare const DEFAULT_TRANSFER_LEG = "transfer";
|
|
2483
2519
|
/** Options for {@link buildTransferCommands} and {@link Client.transfer}. */
|
|
2484
2520
|
export interface TransferOptions {
|
|
2485
2521
|
/**
|
|
@@ -2502,10 +2538,14 @@ export interface TransferOptions {
|
|
|
2502
2538
|
/** Seconds to wait for an answer. Defaults to 30; the platform maximum is 60. */
|
|
2503
2539
|
timeout?: number;
|
|
2504
2540
|
/**
|
|
2505
|
-
* Name for the new leg.
|
|
2541
|
+
* Name for the new leg. Left unnamed by default — the platform accepts a `dial` with no
|
|
2542
|
+
* `callName` — since a fixed default would collide with itself on a second transfer of the
|
|
2543
|
+
* same call (Voice v2 requires `callName` to be unique for the session's whole lifetime,
|
|
2544
|
+
* ended legs included) and this package will not invent a random suffix for something
|
|
2545
|
+
* author-facing and potentially read off a later webhook.
|
|
2506
2546
|
*
|
|
2507
|
-
*
|
|
2508
|
-
* leg names off the webhook payload
|
|
2547
|
+
* Pass one when something downstream needs to address this leg by name afterwards — a later
|
|
2548
|
+
* `PATCH`, a `hangup`, or reading leg names off the webhook payload.
|
|
2509
2549
|
*/
|
|
2510
2550
|
callName?: string;
|
|
2511
2551
|
/**
|
|
@@ -2529,7 +2569,12 @@ export interface TransferToOptions {
|
|
|
2529
2569
|
* `flows.call` give the live leg.
|
|
2530
2570
|
*/
|
|
2531
2571
|
liveLeg?: string;
|
|
2532
|
-
/**
|
|
2572
|
+
/**
|
|
2573
|
+
* Name for the dialled leg. Left unnamed by default, for the same reason as
|
|
2574
|
+
* {@link TransferOptions.callName}: no fixed default is safe against a second transfer on
|
|
2575
|
+
* the same call, and this package does not invent a random one. Pass it when something
|
|
2576
|
+
* downstream needs to address this leg afterwards.
|
|
2577
|
+
*/
|
|
2533
2578
|
legName?: string;
|
|
2534
2579
|
/** Seconds to wait for an answer. Defaults to 30. */
|
|
2535
2580
|
timeout?: number;
|
|
@@ -4680,6 +4725,24 @@ export interface RealtimeTurn {
|
|
|
4680
4725
|
text: string;
|
|
4681
4726
|
/** ISO 8601 */
|
|
4682
4727
|
timestamp: string;
|
|
4728
|
+
/**
|
|
4729
|
+
* Provider-reported speech (role `'user'`) or playback (role `'agent'`) boundaries, when the
|
|
4730
|
+
* adapter has them precisely — currently only `openai.ts` (GPT-Live), from
|
|
4731
|
+
* `session.input_transcript.delta`/`session.output_transcript.delta`'s own `start_ms`/`end_ms`.
|
|
4732
|
+
* Preferred over `agent.ts`'s own `onSpeechStart`/`onPlaybackStart` fallback chain when present.
|
|
4733
|
+
*/
|
|
4734
|
+
speechStartAt?: string;
|
|
4735
|
+
speechEndAt?: string;
|
|
4736
|
+
playbackStartAt?: string;
|
|
4737
|
+
playbackEndAt?: string;
|
|
4738
|
+
/**
|
|
4739
|
+
* `role: 'agent'` only, GPT-Live-specific: time from `session.delegation.created` to the first
|
|
4740
|
+
* backend output this delegation produced (`response.event`'s first inner event), plus the tool
|
|
4741
|
+
* handler run time summed across that delegation — the two combined into one number, not
|
|
4742
|
+
* reported separately. See `openai.ts`'s `Session.lastDelegationId` doc comment for the
|
|
4743
|
+
* one-delegation-per-turn simplification this makes. `undefined` for every other provider.
|
|
4744
|
+
*/
|
|
4745
|
+
delegationMs?: number;
|
|
4683
4746
|
}
|
|
4684
4747
|
/**
|
|
4685
4748
|
* One entry of `ctx.transcript` — a turn from either party, or a completed tool call, in the
|
|
@@ -4701,7 +4764,53 @@ export interface TranscriptEntry {
|
|
|
4701
4764
|
result?: unknown;
|
|
4702
4765
|
/** The handler's thrown value, if it threw. */
|
|
4703
4766
|
error?: unknown;
|
|
4767
|
+
/**
|
|
4768
|
+
* Present when `role` is `'tool'` (the handler's own run time), or `'agent'` (time from the
|
|
4769
|
+
* caller's turn finishing to this reply's first spoken sentence — voice-relay's `converse` and
|
|
4770
|
+
* the STREAM path's `onTurn` both set it; see each adapter for what "first" means there).
|
|
4771
|
+
*/
|
|
4704
4772
|
latencyMs?: number;
|
|
4773
|
+
/**
|
|
4774
|
+
* `'agent'` only: time from the caller's turn finishing to this whole reply completing,
|
|
4775
|
+
* including any tool rounds in between. Absent when the turn was abandoned by a barge-in.
|
|
4776
|
+
*/
|
|
4777
|
+
totalMs?: number;
|
|
4778
|
+
/**
|
|
4779
|
+
* `'agent'` only, GPT-Live-specific — see `RealtimeTurn.delegationMs`'s own doc comment for
|
|
4780
|
+
* exactly what this measures and its one-delegation-per-turn simplification. `undefined` for
|
|
4781
|
+
* every other provider.
|
|
4782
|
+
*/
|
|
4783
|
+
delegationMs?: number;
|
|
4784
|
+
/**
|
|
4785
|
+
* `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
|
|
4786
|
+
* speech-boundary event directly, that wins — GPT-Live from `session.input_transcript.delta`'s
|
|
4787
|
+
* own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
4788
|
+
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
4789
|
+
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
4790
|
+
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
4791
|
+
* published schema anywhere reachable). Every STREAM provider's real gap — Deepgram/Gemini's
|
|
4792
|
+
* missing `speechEndAt`, and any provider's missing `speechStartAt` — is filled by `agent.ts`'s
|
|
4793
|
+
* own energy-VAD fallback (`vad.ts`) on the caller's raw inbound audio, so in practice neither
|
|
4794
|
+
* field is ever actually unset for a STREAM call. voice-relay is the one exception: no VAD runs
|
|
4795
|
+
* there (Sinch does the STT itself, over the relay socket, not raw audio through this runtime),
|
|
4796
|
+
* and no wire field is documented for caller speech boundaries either — both stay unset, never
|
|
4797
|
+
* guessed at.
|
|
4798
|
+
*/
|
|
4799
|
+
speechStartAt?: string;
|
|
4800
|
+
speechEndAt?: string;
|
|
4801
|
+
/**
|
|
4802
|
+
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
4803
|
+
* caller, from whatever playback/response-audio event the provider reports — voice-relay's
|
|
4804
|
+
* `textPlaybackStart`/`Stop`/`Cancel`, OpenAI/Grok's first response audio delta and
|
|
4805
|
+
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. Gemini not wired (no
|
|
4806
|
+
* playback signal in what its adapter exposes). Left unset — never guessed — when a provider
|
|
4807
|
+
* doesn't report it.
|
|
4808
|
+
*/
|
|
4809
|
+
playbackStartAt?: string;
|
|
4810
|
+
playbackEndAt?: string;
|
|
4811
|
+
/** `'agent'` only: set when `playbackEndAt` was a cancellation (barge-in, or a newer reply
|
|
4812
|
+
* superseding this one) rather than the audio finishing on its own. */
|
|
4813
|
+
interrupted?: boolean;
|
|
4705
4814
|
}
|
|
4706
4815
|
/** Fired after a tool's handler resolves or throws — independent of the tool's own return value. */
|
|
4707
4816
|
export interface RealtimeToolCallEvent {
|
|
@@ -4713,6 +4822,24 @@ export interface RealtimeToolCallEvent {
|
|
|
4713
4822
|
error?: unknown;
|
|
4714
4823
|
latencyMs: number;
|
|
4715
4824
|
}
|
|
4825
|
+
/**
|
|
4826
|
+
* Tokens and seconds only — no dollar prices computed or stored anywhere in this runtime. A
|
|
4827
|
+
* vendor's own `onUsage` call (see `RealtimeAdapterCallbacks`) always reports the call's *running
|
|
4828
|
+
* total* so far, not a per-turn delta: the adapter itself is what knows whether its vendor's raw
|
|
4829
|
+
* usage event is a snapshot to replace with (GPT-Live's `session.usage.updated`) or a per-turn
|
|
4830
|
+
* value to sum into a running total (Grok/Gemini/voice-relay's per-round usage) — `agent.ts`/
|
|
4831
|
+
* `adapters/relay.ts` just take whatever's reported as the latest total.
|
|
4832
|
+
*/
|
|
4833
|
+
export interface RealtimeUsage {
|
|
4834
|
+
inputTokens?: number;
|
|
4835
|
+
outputTokens?: number;
|
|
4836
|
+
/**
|
|
4837
|
+
* GPT-Live: `session.usage.updated`'s `usage.seconds` directly (vendor-reported, replaces).
|
|
4838
|
+
* Deepgram: never vendor-reported (nothing in its stream carries usage) — `agent.ts` falls back
|
|
4839
|
+
* to its own wall-clock call duration instead, so this is never left unset for Deepgram either.
|
|
4840
|
+
*/
|
|
4841
|
+
audioSeconds?: number;
|
|
4842
|
+
}
|
|
4716
4843
|
/** A vendor-side error — session, transport, or a malformed frame. */
|
|
4717
4844
|
export interface RealtimeError {
|
|
4718
4845
|
message: string;
|
|
@@ -4754,6 +4881,13 @@ export interface RealtimeSessionContext {
|
|
|
4754
4881
|
* with. Read from `onEnd` or a tool `handler`; appended to by the relay, never by an author.
|
|
4755
4882
|
*/
|
|
4756
4883
|
readonly transcript: readonly TranscriptEntry[];
|
|
4884
|
+
/**
|
|
4885
|
+
* This call's running usage total, as of whatever the vendor (or, for Deepgram, our own
|
|
4886
|
+
* wall-clock measurement — see `RealtimeUsage.audioSeconds`'s own doc comment) has reported so
|
|
4887
|
+
* far. Read from `onEnd` to save it; the relay itself logs one summary line at call end too.
|
|
4888
|
+
* Tokens and seconds only — no dollar amounts computed or stored anywhere in this runtime.
|
|
4889
|
+
*/
|
|
4890
|
+
readonly usage: RealtimeUsage;
|
|
4757
4891
|
/**
|
|
4758
4892
|
* End the call. Closes the vendor session and the STREAM leg; `endOnFailure` on the caller's
|
|
4759
4893
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
@@ -4811,6 +4945,24 @@ export interface RealtimeAgentOptions {
|
|
|
4811
4945
|
* value`, resolved once per call.
|
|
4812
4946
|
*/
|
|
4813
4947
|
voice?: PerCallValue<string>;
|
|
4948
|
+
/**
|
|
4949
|
+
* IANA zone name (e.g. `'America/New_York'`) the current-date-and-time line prepended to every
|
|
4950
|
+
* provider's resolved prompt is formatted in — every provider gets one, so "Thursday" or
|
|
4951
|
+
* "tomorrow" resolves against the call's actual date rather than the model's training cutoff.
|
|
4952
|
+
* Defaults to `'America/Chicago'` (`DEFAULT_TIMEZONE` in `tool-injection.ts`). Not per-call —
|
|
4953
|
+
* unlike `prompt`/`greeting`/`voice`, a timezone is a property of the deployment, not the caller.
|
|
4954
|
+
*/
|
|
4955
|
+
timezone?: string;
|
|
4956
|
+
/**
|
|
4957
|
+
* BCP-47 speech language (e.g. `'en-US'`, `'es-MX'`) — pins the provider's recognition (and,
|
|
4958
|
+
* where the vendor doesn't separate the two, its reply language) rather than letting it
|
|
4959
|
+
* auto-detect. Added after a live Gemini call had the caller's speech misheard as Spanish
|
|
4960
|
+
* ("¿Cómo te") and answered in Spanish for a turn. A value, or `(call, context) => value`,
|
|
4961
|
+
* resolved once per call. Defaults to `'en-US'` (`DEFAULT_LANGUAGE`) — wired where the provider
|
|
4962
|
+
* has a field for it (`gemini`, `deepgram`, `grok`, `voice-relay`); `openai` (GPT-Live) has no
|
|
4963
|
+
* documented equivalent field and is left alone.
|
|
4964
|
+
*/
|
|
4965
|
+
language?: PerCallValue<string>;
|
|
4814
4966
|
/**
|
|
4815
4967
|
* The model id, sent straight through. Only `provider: 'voice-relay'` reads this — it names any
|
|
4816
4968
|
* model served by an OpenAI Responses-compatible endpoint (e.g. `'gpt-4o-mini'`); see
|
|
@@ -4898,10 +5050,14 @@ export interface RealtimeAgentOptions {
|
|
|
4898
5050
|
* closed over by the injected tool's handler. Everything else is unchanged from
|
|
4899
5051
|
* `RealtimeAgentOptions`.
|
|
4900
5052
|
*/
|
|
4901
|
-
export type ResolvedRealtimeAgentOptions = Omit<RealtimeAgentOptions, "prompt" | "greeting" | "voice" | "transferTo"> & {
|
|
5053
|
+
export type ResolvedRealtimeAgentOptions = Omit<RealtimeAgentOptions, "prompt" | "greeting" | "voice" | "transferTo" | "language"> & {
|
|
4902
5054
|
prompt: string;
|
|
4903
5055
|
greeting?: string;
|
|
4904
5056
|
voice?: string;
|
|
5057
|
+
/** Resolved from `RealtimeAgentOptions.language`, defaulted to `DEFAULT_LANGUAGE` by
|
|
5058
|
+
* `agent.ts`'s `resolvePerCallOptions` — optional here only so an adapter's own unit tests can
|
|
5059
|
+
* build one without it; every adapter that reads it falls back to `DEFAULT_LANGUAGE` itself. */
|
|
5060
|
+
language?: string;
|
|
4905
5061
|
};
|
|
4906
5062
|
/**
|
|
4907
5063
|
* Normalised events an adapter reports back to the relay loop as they happen. An adapter never
|
|
@@ -4930,6 +5086,36 @@ export interface RealtimeAdapterCallbacks {
|
|
|
4930
5086
|
onError(err: RealtimeError): void;
|
|
4931
5087
|
/** The vendor session closed, on either side. */
|
|
4932
5088
|
onClose(): void;
|
|
5089
|
+
/**
|
|
5090
|
+
* Optional — only called by an adapter whose vendor reports caller speech boundaries on its own
|
|
5091
|
+
* (OpenAI/Grok's `input_audio_buffer.speech_started`/`speech_stopped`, Deepgram's
|
|
5092
|
+
* `UserStartedSpeaking`). Stamps `TranscriptEntry.speechStartAt`/`speechEndAt` on the next user
|
|
5093
|
+
* turn. A vendor with no such signal (Gemini) simply never calls this — those fields stay unset,
|
|
5094
|
+
* never guessed at.
|
|
5095
|
+
*/
|
|
5096
|
+
onSpeechStart?(): void;
|
|
5097
|
+
onSpeechEnd?(): void;
|
|
5098
|
+
/**
|
|
5099
|
+
* Optional — only called by an adapter whose vendor reports when the reply's audio actually
|
|
5100
|
+
* started/stopped playing, distinct from `onTurn`'s "the reply text is fully known" (OpenAI/
|
|
5101
|
+
* Grok's first response audio delta and `response.done`; Deepgram's
|
|
5102
|
+
* `AgentStartedSpeaking`/`AgentAudioDone`). Stamps `TranscriptEntry.playbackStartAt`/
|
|
5103
|
+
* `playbackEndAt`/`interrupted` on the agent turn. `cancelled` distinguishes a barge-in or a
|
|
5104
|
+
* newer reply superseding this one from the audio finishing on its own.
|
|
5105
|
+
*/
|
|
5106
|
+
onPlaybackStart?(): void;
|
|
5107
|
+
onPlaybackStop?(info: {
|
|
5108
|
+
cancelled: boolean;
|
|
5109
|
+
}): void;
|
|
5110
|
+
/**
|
|
5111
|
+
* Optional — only called by an adapter whose vendor reports usage at all (see `RealtimeUsage`'s
|
|
5112
|
+
* own doc comment for what "reports" means per vendor: GPT-Live's `session.usage.updated`,
|
|
5113
|
+
* Grok's `response.done`, Gemini's `usageMetadata`). Always the call's running total so far, not
|
|
5114
|
+
* a delta — the adapter itself resolves its vendor's own replace-vs-sum semantics before calling
|
|
5115
|
+
* this. Deepgram never calls it; `agent.ts` falls back to a wall-clock `audioSeconds` for that
|
|
5116
|
+
* case instead.
|
|
5117
|
+
*/
|
|
5118
|
+
onUsage?(usage: RealtimeUsage): void;
|
|
4933
5119
|
}
|
|
4934
5120
|
/** Opaque per-call handle an adapter defines for itself and hands back to `sendAudio`/`clear`/`close`. */
|
|
4935
5121
|
export type VendorSession = unknown;
|
|
@@ -5045,6 +5231,12 @@ export interface RelayCall {
|
|
|
5045
5231
|
onDigits(handler: (digits: string) => void | Promise<void>): void;
|
|
5046
5232
|
/** The caller talked over a reply */
|
|
5047
5233
|
onInterrupted(handler: () => void): void;
|
|
5234
|
+
/** The platform started playing TTS audio for a queued `send()` reply. */
|
|
5235
|
+
onPlaybackStart(handler: () => void): void;
|
|
5236
|
+
/** That reply's audio finished playing, or was cut short by a barge-in or a newer reply. */
|
|
5237
|
+
onPlaybackStop(handler: (info: {
|
|
5238
|
+
cancelled: boolean;
|
|
5239
|
+
}) => void): void;
|
|
5048
5240
|
/** The relay socket closed */
|
|
5049
5241
|
onEnded(handler: () => void): void;
|
|
5050
5242
|
/** Move the caller to a phone number. See the voice client's `transferToPhone`. */
|
|
@@ -5753,7 +5945,7 @@ export declare class SecretsLoader {
|
|
|
5753
5945
|
export declare const secretsLoader: SecretsLoader;
|
|
5754
5946
|
|
|
5755
5947
|
declare namespace v2 {
|
|
5756
|
-
export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions$1 as ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE,
|
|
5948
|
+
export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions$1 as ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE, DEFAULT_VOICE, Destination, DialAgentOptions, DialEvents, DialOptions, DialRelayOptions, DialSipOptions, DialStreamOptions, DialableAgent, EventType, Flow, HandlerKey, HandlerResult, Headers$1 as Headers, IncomingCall, MenuCall, MenuDefinition, MenuInput, MenuItemBuilder, Money, Options, Origin, OriginationType, PatchTarget, PlaceCallOptions, PromptBuilder, PromptFlow, REDACTED, RecordingCredentials, RecordingDestination, RecordingFormat, RecordingType, RelayCallOptions, SampleRate, SayOptions, SipAgentOptions, SipAgentProvider, StartRecordingOptions, StopMessagesFlags, StreamCallOptions, TransferOptions, TransferToOptions, WebhookBody, WebhookCall, WebhookHandler, WebhookOptions, WebhookRequest, bridgeTo, buildTransferCommands, commands, connectAgent, createClient, dial, dialAgent, dialPhone, dialRelay, dialSip, dialStream, endpointNumber, menu, play, redactCredentials, resolveHandlerKey, resolveWebhookName, say, stringify as stringifyOrdered, toCallBody, toCallEvent, toWebhookBody, toWebhookRequest };
|
|
5757
5949
|
}
|
|
5758
5950
|
|
|
5759
5951
|
export {
|
package/dist/index.js
CHANGED
package/dist/voice/v2.d.ts
CHANGED
|
@@ -790,6 +790,15 @@ interface FlowScope {
|
|
|
790
790
|
readonly joined?: string;
|
|
791
791
|
/** Legs dialled under this scope that the call-level `onHangup` must end. Shared by copies. */
|
|
792
792
|
readonly dialled: Set<string>;
|
|
793
|
+
/**
|
|
794
|
+
* Every leg name used anywhere in this response's command tree so far, including a dial's
|
|
795
|
+
* own leg before its nested outcome flows (`onBusy`, `onNoAnswer`, ...) are resolved — that
|
|
796
|
+
* is what lets a fallback dial nested inside one of them see the outer leg's name and step
|
|
797
|
+
* past it. Shared by copies, unlike {@link dialled} this is never gated on {@link namesLiveLeg}:
|
|
798
|
+
* a repeat default has to be caught in a `call.answered` or `call.menu` response too, even
|
|
799
|
+
* though neither carries a call-level `onHangup`.
|
|
800
|
+
*/
|
|
801
|
+
readonly usedNames: Set<string>;
|
|
793
802
|
}
|
|
794
803
|
/** Options for a single TTS message */
|
|
795
804
|
export interface SayOptions {
|
|
@@ -868,7 +877,17 @@ export interface BridgeToOptions {
|
|
|
868
877
|
timeout?: number;
|
|
869
878
|
/** Maximum call duration in seconds. Maximum 14400. */
|
|
870
879
|
maxDuration?: number;
|
|
871
|
-
/**
|
|
880
|
+
/**
|
|
881
|
+
* Name for the dialled leg. Defaults by destination: `destination`, `stream` or `relay`. A
|
|
882
|
+
* second dial with no `legName` that lands on the same default within one call flow — a
|
|
883
|
+
* nested fallback in `onBusy`/`onTimeout`, or a sibling `dial*` call — gets `-2`, `-3`, and
|
|
884
|
+
* so on instead of colliding.
|
|
885
|
+
*
|
|
886
|
+
* Voice v2 requires `callName` to stay unique over the call's *whole lifetime*, not just
|
|
887
|
+
* within the commands built here — dialling again on a call that already has a leg by this
|
|
888
|
+
* default name, such as from a later `PATCH`, needs an explicit `legName` to avoid a 500
|
|
889
|
+
* with the leg stuck `QUEUED`.
|
|
890
|
+
*/
|
|
872
891
|
legName?: string;
|
|
873
892
|
/** Bridge both legs join. Defaults to `bridge`; name another for a hold room or a whisper. */
|
|
874
893
|
bridgeName?: string;
|
|
@@ -1314,8 +1333,6 @@ export declare function toCallEvent(request: WebhookRequest): CallEvent;
|
|
|
1314
1333
|
* "the call" (`connectAgent`, `transferTo*`) accept a handler's flattened call or a raw body.
|
|
1315
1334
|
*/
|
|
1316
1335
|
export declare function toWebhookRequest(call: CallEvent | WebhookRequest): WebhookRequest;
|
|
1317
|
-
/** Name given to the leg a transfer dials, when the caller does not name it. */
|
|
1318
|
-
export declare const DEFAULT_TRANSFER_LEG = "transfer";
|
|
1319
1336
|
/** Options for {@link buildTransferCommands} and {@link Client.transfer}. */
|
|
1320
1337
|
export interface TransferOptions {
|
|
1321
1338
|
/**
|
|
@@ -1338,10 +1355,14 @@ export interface TransferOptions {
|
|
|
1338
1355
|
/** Seconds to wait for an answer. Defaults to 30; the platform maximum is 60. */
|
|
1339
1356
|
timeout?: number;
|
|
1340
1357
|
/**
|
|
1341
|
-
* Name for the new leg.
|
|
1358
|
+
* Name for the new leg. Left unnamed by default — the platform accepts a `dial` with no
|
|
1359
|
+
* `callName` — since a fixed default would collide with itself on a second transfer of the
|
|
1360
|
+
* same call (Voice v2 requires `callName` to be unique for the session's whole lifetime,
|
|
1361
|
+
* ended legs included) and this package will not invent a random suffix for something
|
|
1362
|
+
* author-facing and potentially read off a later webhook.
|
|
1342
1363
|
*
|
|
1343
|
-
*
|
|
1344
|
-
* leg names off the webhook payload
|
|
1364
|
+
* Pass one when something downstream needs to address this leg by name afterwards — a later
|
|
1365
|
+
* `PATCH`, a `hangup`, or reading leg names off the webhook payload.
|
|
1345
1366
|
*/
|
|
1346
1367
|
callName?: string;
|
|
1347
1368
|
/**
|
|
@@ -1399,7 +1420,12 @@ export interface TransferToOptions {
|
|
|
1399
1420
|
* `flows.call` give the live leg.
|
|
1400
1421
|
*/
|
|
1401
1422
|
liveLeg?: string;
|
|
1402
|
-
/**
|
|
1423
|
+
/**
|
|
1424
|
+
* Name for the dialled leg. Left unnamed by default, for the same reason as
|
|
1425
|
+
* {@link TransferOptions.callName}: no fixed default is safe against a second transfer on
|
|
1426
|
+
* the same call, and this package does not invent a random one. Pass it when something
|
|
1427
|
+
* downstream needs to address this leg afterwards.
|
|
1428
|
+
*/
|
|
1403
1429
|
legName?: string;
|
|
1404
1430
|
/** Seconds to wait for an answer. Defaults to 30. */
|
|
1405
1431
|
timeout?: number;
|
|
@@ -1914,7 +1940,63 @@ interface TranscriptEntry {
|
|
|
1914
1940
|
result?: unknown;
|
|
1915
1941
|
/** The handler's thrown value, if it threw. */
|
|
1916
1942
|
error?: unknown;
|
|
1943
|
+
/**
|
|
1944
|
+
* Present when `role` is `'tool'` (the handler's own run time), or `'agent'` (time from the
|
|
1945
|
+
* caller's turn finishing to this reply's first spoken sentence — voice-relay's `converse` and
|
|
1946
|
+
* the STREAM path's `onTurn` both set it; see each adapter for what "first" means there).
|
|
1947
|
+
*/
|
|
1917
1948
|
latencyMs?: number;
|
|
1949
|
+
/**
|
|
1950
|
+
* `'agent'` only: time from the caller's turn finishing to this whole reply completing,
|
|
1951
|
+
* including any tool rounds in between. Absent when the turn was abandoned by a barge-in.
|
|
1952
|
+
*/
|
|
1953
|
+
totalMs?: number;
|
|
1954
|
+
/**
|
|
1955
|
+
* `'agent'` only, GPT-Live-specific — see `RealtimeTurn.delegationMs`'s own doc comment for
|
|
1956
|
+
* exactly what this measures and its one-delegation-per-turn simplification. `undefined` for
|
|
1957
|
+
* every other provider.
|
|
1958
|
+
*/
|
|
1959
|
+
delegationMs?: number;
|
|
1960
|
+
/**
|
|
1961
|
+
* `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
|
|
1962
|
+
* speech-boundary event directly, that wins — GPT-Live from `session.input_transcript.delta`'s
|
|
1963
|
+
* own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
1964
|
+
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
1965
|
+
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
1966
|
+
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
1967
|
+
* published schema anywhere reachable). Every STREAM provider's real gap — Deepgram/Gemini's
|
|
1968
|
+
* missing `speechEndAt`, and any provider's missing `speechStartAt` — is filled by `agent.ts`'s
|
|
1969
|
+
* own energy-VAD fallback (`vad.ts`) on the caller's raw inbound audio, so in practice neither
|
|
1970
|
+
* field is ever actually unset for a STREAM call. voice-relay is the one exception: no VAD runs
|
|
1971
|
+
* there (Sinch does the STT itself, over the relay socket, not raw audio through this runtime),
|
|
1972
|
+
* and no wire field is documented for caller speech boundaries either — both stay unset, never
|
|
1973
|
+
* guessed at.
|
|
1974
|
+
*/
|
|
1975
|
+
speechStartAt?: string;
|
|
1976
|
+
speechEndAt?: string;
|
|
1977
|
+
/**
|
|
1978
|
+
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
1979
|
+
* caller, from whatever playback/response-audio event the provider reports — voice-relay's
|
|
1980
|
+
* `textPlaybackStart`/`Stop`/`Cancel`, OpenAI/Grok's first response audio delta and
|
|
1981
|
+
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. Gemini not wired (no
|
|
1982
|
+
* playback signal in what its adapter exposes). Left unset — never guessed — when a provider
|
|
1983
|
+
* doesn't report it.
|
|
1984
|
+
*/
|
|
1985
|
+
playbackStartAt?: string;
|
|
1986
|
+
playbackEndAt?: string;
|
|
1987
|
+
/** `'agent'` only: set when `playbackEndAt` was a cancellation (barge-in, or a newer reply
|
|
1988
|
+
* superseding this one) rather than the audio finishing on its own. */
|
|
1989
|
+
interrupted?: boolean;
|
|
1990
|
+
}
|
|
1991
|
+
interface RealtimeUsage {
|
|
1992
|
+
inputTokens?: number;
|
|
1993
|
+
outputTokens?: number;
|
|
1994
|
+
/**
|
|
1995
|
+
* GPT-Live: `session.usage.updated`'s `usage.seconds` directly (vendor-reported, replaces).
|
|
1996
|
+
* Deepgram: never vendor-reported (nothing in its stream carries usage) — `agent.ts` falls back
|
|
1997
|
+
* to its own wall-clock call duration instead, so this is never left unset for Deepgram either.
|
|
1998
|
+
*/
|
|
1999
|
+
audioSeconds?: number;
|
|
1918
2000
|
}
|
|
1919
2001
|
interface RealtimeError {
|
|
1920
2002
|
message: string;
|
|
@@ -1946,6 +2028,13 @@ interface RealtimeSessionContext {
|
|
|
1946
2028
|
* with. Read from `onEnd` or a tool `handler`; appended to by the relay, never by an author.
|
|
1947
2029
|
*/
|
|
1948
2030
|
readonly transcript: readonly TranscriptEntry[];
|
|
2031
|
+
/**
|
|
2032
|
+
* This call's running usage total, as of whatever the vendor (or, for Deepgram, our own
|
|
2033
|
+
* wall-clock measurement — see `RealtimeUsage.audioSeconds`'s own doc comment) has reported so
|
|
2034
|
+
* far. Read from `onEnd` to save it; the relay itself logs one summary line at call end too.
|
|
2035
|
+
* Tokens and seconds only — no dollar amounts computed or stored anywhere in this runtime.
|
|
2036
|
+
*/
|
|
2037
|
+
readonly usage: RealtimeUsage;
|
|
1949
2038
|
/**
|
|
1950
2039
|
* End the call. Closes the vendor session and the STREAM leg; `endOnFailure` on the caller's
|
|
1951
2040
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
@@ -1970,7 +2059,7 @@ type PerCallSetting = string | ((call: v2.Call, context: FunctionContext) => str
|
|
|
1970
2059
|
type RelayTransferOptions = Omit<v2.TransferToOptions, "call">;
|
|
1971
2060
|
|
|
1972
2061
|
declare namespace v2 {
|
|
1973
|
-
export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE,
|
|
2062
|
+
export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE, DEFAULT_VOICE, Destination, DialAgentOptions, DialEvents, DialOptions, DialRelayOptions, DialSipOptions, DialStreamOptions, DialableAgent, EventType, Flow, HandlerKey, HandlerResult, Headers$1 as Headers, IncomingCall, MenuCall, MenuDefinition, MenuInput, MenuItemBuilder, Money, Options, Origin, OriginationType, PatchTarget, PlaceCallOptions, PromptBuilder, PromptFlow, REDACTED, RecordingCredentials, RecordingDestination, RecordingFormat, RecordingType, RelayCallOptions, SampleRate, SayOptions, SipAgentOptions, SipAgentProvider, StartRecordingOptions, StopMessagesFlags, StreamCallOptions, TransferOptions, TransferToOptions, WebhookBody, WebhookCall, WebhookHandler, WebhookOptions, WebhookRequest, bridgeTo, buildTransferCommands, commands, connectAgent, createClient, dial, dialAgent, dialPhone, dialRelay, dialSip, dialStream, endpointNumber, menu, play, redactCredentials, resolveHandlerKey, resolveWebhookName, say, stringify as stringifyOrdered, toCallBody, toCallEvent, toWebhookBody, toWebhookRequest };
|
|
1974
2063
|
}
|
|
1975
2064
|
|
|
1976
2065
|
export {
|
package/dist/voice/v2.js
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
DEFAULT_HOST,
|
|
10
10
|
DEFAULT_SAMPLE_RATE,
|
|
11
11
|
DEFAULT_STT_LANGUAGE,
|
|
12
|
-
DEFAULT_TRANSFER_LEG,
|
|
13
12
|
DEFAULT_VOICE,
|
|
14
13
|
MenuItemBuilder,
|
|
15
14
|
PromptBuilder,
|
|
@@ -41,7 +40,7 @@ import {
|
|
|
41
40
|
toWebhookRequest,
|
|
42
41
|
tool,
|
|
43
42
|
voiceRelay
|
|
44
|
-
} from "../chunk-
|
|
43
|
+
} from "../chunk-DHM4MH2A.js";
|
|
45
44
|
export {
|
|
46
45
|
Client,
|
|
47
46
|
CommandBuilder,
|
|
@@ -49,7 +48,6 @@ export {
|
|
|
49
48
|
DEFAULT_HOST,
|
|
50
49
|
DEFAULT_SAMPLE_RATE,
|
|
51
50
|
DEFAULT_STT_LANGUAGE,
|
|
52
|
-
DEFAULT_TRANSFER_LEG,
|
|
53
51
|
DEFAULT_VOICE,
|
|
54
52
|
MenuItemBuilder,
|
|
55
53
|
PromptBuilder,
|
package/package.json
CHANGED