@sinch/functions-runtime 0.7.0 → 0.7.2
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 +41 -22
- package/dist/bin/sinch-runtime.js +24 -1
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/{chunk-DLBCKZ6X.js → chunk-KGCIUPCT.js} +1247 -371
- package/dist/{chunk-DLBCKZ6X.js.map → chunk-KGCIUPCT.js.map} +1 -1
- package/dist/index.d.ts +188 -36
- package/dist/index.js +11 -1
- package/dist/voice/v2.d.ts +97 -14
- package/dist/voice/v2.js +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -984,7 +984,25 @@ export interface IFunctionStorage {
|
|
|
984
984
|
list(prefix?: string): Promise<string[]>;
|
|
985
985
|
exists(key: string): Promise<boolean>;
|
|
986
986
|
delete(key: string): Promise<void>;
|
|
987
|
+
/**
|
|
988
|
+
* A short-lived `https://` PUT URL that Sinch Voice can upload a call recording to, for the
|
|
989
|
+
* exact key `recordings/<callId>.<format>` in this storage. Backs `recordToFunctions()` and
|
|
990
|
+
* `realtimeAgent({ record: { sinch: true } })`: the host swaps the builder's placeholder
|
|
991
|
+
* destination for this URL before the webhook response leaves. Optional — storage without it
|
|
992
|
+
* makes the host drop the recording command and warn.
|
|
993
|
+
*
|
|
994
|
+
* @param callId - The call the recording belongs to
|
|
995
|
+
* @param format - Lowercase file extension, `mp3` or `wav`
|
|
996
|
+
*/
|
|
997
|
+
getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
|
|
987
998
|
}
|
|
999
|
+
/** Where the dev runtime receives Sinch's recording upload (`PUT <path><callId>.<format>`). */
|
|
1000
|
+
export declare const RECORDING_RECEIVER_PATH = "/_sinch/recording/";
|
|
1001
|
+
/**
|
|
1002
|
+
* The storage key for a call's recording, `recordings/<callId>.<format>`, with anything outside
|
|
1003
|
+
* `[\w-]` in the callId replaced so it cannot leave `recordings/`.
|
|
1004
|
+
*/
|
|
1005
|
+
export declare function recordingKey(callId: string, format: "mp3" | "wav"): string;
|
|
988
1006
|
/**
|
|
989
1007
|
* The config seam — the only thing this module needs from its host.
|
|
990
1008
|
*
|
|
@@ -1398,7 +1416,7 @@ interface RecordingOptions$1 {
|
|
|
1398
1416
|
*
|
|
1399
1417
|
* As sensitive as an IAM key — see {@link ../commands.js#RecordingCredentials}.
|
|
1400
1418
|
*/
|
|
1401
|
-
credentials
|
|
1419
|
+
credentials?: string;
|
|
1402
1420
|
/** Speech-to-text settings */
|
|
1403
1421
|
transcriptionOptions?: TranscriptionOptions;
|
|
1404
1422
|
}
|
|
@@ -1666,6 +1684,11 @@ export interface DialableAgent {
|
|
|
1666
1684
|
* @param context - The context the voice client was created with, when it had one
|
|
1667
1685
|
*/
|
|
1668
1686
|
endpointFor(call: WebhookRequest, context: ClientContext | undefined): To;
|
|
1687
|
+
/**
|
|
1688
|
+
* Commands `dialAgent` places before the agent leg, built from the same call — a
|
|
1689
|
+
* `realtimeAgent` that records the call starts its recording here. Optional.
|
|
1690
|
+
*/
|
|
1691
|
+
commandsBefore?(call: WebhookRequest, context: ClientContext | undefined): Command[];
|
|
1669
1692
|
}
|
|
1670
1693
|
/** SIP settings for an agent leg; each defaults to what the provider requires. */
|
|
1671
1694
|
export interface SipAgentOptions {
|
|
@@ -1922,15 +1945,20 @@ export interface RecordingCredentials {
|
|
|
1922
1945
|
/** Storage region, e.g. `eu-central-1` */
|
|
1923
1946
|
region: string;
|
|
1924
1947
|
}
|
|
1948
|
+
declare const RECORD_TO_FUNCTIONS_SENTINEL = "@functions";
|
|
1925
1949
|
/** Everything a `startRecording` command can carry */
|
|
1926
1950
|
export interface StartRecordingOptions {
|
|
1927
|
-
/**
|
|
1951
|
+
/**
|
|
1952
|
+
* Destination URL, e.g. `s3://voice-recordings-prod/calls`, or a presigned `https://` PUT URL
|
|
1953
|
+
* (no credentials then).
|
|
1954
|
+
*/
|
|
1928
1955
|
destinationUrl: string;
|
|
1929
1956
|
/**
|
|
1930
1957
|
* Credentials for the destination. Prefer the structured form; the raw colon-delimited
|
|
1931
|
-
* string is there for credential formats this library does not model.
|
|
1958
|
+
* string is there for credential formats this library does not model. Required unless
|
|
1959
|
+
* `destinationUrl` is an `https://` URL, which carries its own authorization.
|
|
1932
1960
|
*/
|
|
1933
|
-
credentials
|
|
1961
|
+
credentials?: RecordingCredentials | string;
|
|
1934
1962
|
/**
|
|
1935
1963
|
* Storage service. Defaults to `AWS`, and is always emitted — the schema lists
|
|
1936
1964
|
* `destination` as required, whatever its documented default.
|
|
@@ -1967,6 +1995,8 @@ export interface StartRecordingOptions {
|
|
|
1967
1995
|
*/
|
|
1968
1996
|
onFailure?: Flow;
|
|
1969
1997
|
}
|
|
1998
|
+
/** Options for {@link CommandBuilder.recordToFunctions} */
|
|
1999
|
+
export type RecordToFunctionsOptions = Pick<StartRecordingOptions, "recordingName" | "format" | "recordingType" | "onFinish" | "onFailure">;
|
|
1970
2000
|
/** Anything that can stand in for a menu prompt: a builder, a callback, or plain text. */
|
|
1971
2001
|
export type PromptFlow = string | PromptBuilder | ((prompt: PromptBuilder) => PromptBuilder | void);
|
|
1972
2002
|
declare class PromptBuilder {
|
|
@@ -1977,12 +2007,15 @@ declare class PromptBuilder {
|
|
|
1977
2007
|
*
|
|
1978
2008
|
* @param text - Text to synthesise, or an SSML document when `format` is `SSML`
|
|
1979
2009
|
* @param options - Voice and format overrides
|
|
2010
|
+
* @throws If `text` is over 600 characters (prompts are never split), or the prompt would hold
|
|
2011
|
+
* more than 10 messages
|
|
1980
2012
|
*/
|
|
1981
2013
|
say(text: string, options?: SayOptions): this;
|
|
1982
2014
|
/**
|
|
1983
2015
|
* Play an audio file.
|
|
1984
2016
|
*
|
|
1985
2017
|
* @param url - Publicly reachable URL of the audio file
|
|
2018
|
+
* @throws If the prompt would hold more than 10 messages
|
|
1986
2019
|
*/
|
|
1987
2020
|
play(url: string): this;
|
|
1988
2021
|
/**
|
|
@@ -2006,12 +2039,14 @@ declare class MenuItemBuilder {
|
|
|
2006
2039
|
* Prompt played when the menu is entered.
|
|
2007
2040
|
*
|
|
2008
2041
|
* @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
|
|
2042
|
+
* @throws If any prompt text is over 600 characters, or a callback queues more than 10 messages
|
|
2009
2043
|
*/
|
|
2010
2044
|
prompt(prompt: PromptFlow): this;
|
|
2011
2045
|
/**
|
|
2012
2046
|
* Prompt played on each retry. Falls back to `prompt` when unset.
|
|
2013
2047
|
*
|
|
2014
2048
|
* @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
|
|
2049
|
+
* @throws If any prompt text is over 600 characters, or a callback queues more than 10 messages
|
|
2015
2050
|
*/
|
|
2016
2051
|
repeatPrompt(prompt: PromptFlow): this;
|
|
2017
2052
|
/**
|
|
@@ -2137,16 +2172,20 @@ export declare class CommandBuilder {
|
|
|
2137
2172
|
/** Set only on the builder `onCall` injects — see {@link FlowScope} */
|
|
2138
2173
|
private scope?;
|
|
2139
2174
|
/**
|
|
2140
|
-
* Speak text on the call.
|
|
2175
|
+
* Speak text on the call. `TEXT` over 600 characters is split between sentences into
|
|
2176
|
+
* consecutive messages.
|
|
2141
2177
|
*
|
|
2142
2178
|
* @param text - Text to synthesise, or an SSML document when `format` is `SSML`
|
|
2143
2179
|
* @param options - Voice and format overrides
|
|
2180
|
+
* @throws If a sentence, or any SSML document, is over 600 characters, or the pending
|
|
2181
|
+
* messages would pass 10 items
|
|
2144
2182
|
*/
|
|
2145
2183
|
say(text: string, options?: SayOptions): this;
|
|
2146
2184
|
/**
|
|
2147
2185
|
* Play an audio file on the call.
|
|
2148
2186
|
*
|
|
2149
2187
|
* @param url - Publicly reachable URL of the audio file
|
|
2188
|
+
* @throws If the pending messages would pass 10 items
|
|
2150
2189
|
*/
|
|
2151
2190
|
play(url: string): this;
|
|
2152
2191
|
/**
|
|
@@ -2394,6 +2433,22 @@ export declare class CommandBuilder {
|
|
|
2394
2433
|
* ```
|
|
2395
2434
|
*/
|
|
2396
2435
|
startRecording(options: StartRecordingOptions): this;
|
|
2436
|
+
/**
|
|
2437
|
+
* Record the call into this function's own storage (`recordings/<callId>.mp3`), with no
|
|
2438
|
+
* credentials. Emits a `startRecording` whose destination is a placeholder
|
|
2439
|
+
* ({@link RECORD_TO_FUNCTIONS_SENTINEL}); the runtime host replaces it with a presigned PUT
|
|
2440
|
+
* URL for the exact key just before the response is sent, and drops the command with a warning
|
|
2441
|
+
* when it cannot (no callId, or storage without a recording destination). Needs a runtime
|
|
2442
|
+
* that does the rewrite — sending this builder's output anywhere else delivers the placeholder.
|
|
2443
|
+
*
|
|
2444
|
+
* Transcription is not offered: the transcript URL is derived from the recording URL, which a
|
|
2445
|
+
* presigned URL cannot carry. The recording is named so {@link stopRecording} can end it;
|
|
2446
|
+
* `recordingName` defaults to `functions-recording`. Without an `onFailure` flow a failed
|
|
2447
|
+
* recording is silent — the platform sends no webhook for it.
|
|
2448
|
+
*
|
|
2449
|
+
* @param options - Format (default `MP3`), recording name, streams captured, outcome flows
|
|
2450
|
+
*/
|
|
2451
|
+
recordToFunctions(options?: RecordToFunctionsOptions): this;
|
|
2397
2452
|
/**
|
|
2398
2453
|
* Stop a named recording. Non-blocking.
|
|
2399
2454
|
*
|
|
@@ -2604,7 +2659,7 @@ export interface Options {
|
|
|
2604
2659
|
serviceId?: string;
|
|
2605
2660
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
2606
2661
|
host?: string;
|
|
2607
|
-
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
|
|
2662
|
+
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. May end in a query string, which stays after a resolved path. */
|
|
2608
2663
|
publicUrl?: string;
|
|
2609
2664
|
/** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
|
|
2610
2665
|
fetch?: typeof globalThis.fetch;
|
|
@@ -3096,6 +3151,7 @@ export declare function createClient(context?: ClientContext, options?: Options)
|
|
|
3096
3151
|
declare const DEFAULT_HOST = "https://voice.api.sinch.com";
|
|
3097
3152
|
declare const REDACTED = "[redacted]";
|
|
3098
3153
|
declare function redactCredentials<T>(body: T): T;
|
|
3154
|
+
declare const MAX_SAY_CHARS = 600;
|
|
3099
3155
|
declare function stringify(value: unknown): string;
|
|
3100
3156
|
/** Options for {@link connectAgent}. */
|
|
3101
3157
|
interface ConnectAgentOptions$1 extends SipAgentOptions {
|
|
@@ -3849,10 +3905,9 @@ export declare function resetVoiceSignatureWarning(): void;
|
|
|
3849
3905
|
*
|
|
3850
3906
|
* Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks, with one deliberate
|
|
3851
3907
|
* exception: when the mode says validate but `VOICE_SERVICE_SECRET` is unset, the request is
|
|
3852
|
-
* allowed and a single warning is logged.
|
|
3853
|
-
*
|
|
3854
|
-
*
|
|
3855
|
-
* the moment a secret is set, with no code or configuration change.
|
|
3908
|
+
* allowed and a single warning is logged. Deploying sets `VOICE_SERVICE_SECRET` from the
|
|
3909
|
+
* function's voice service, so the gate is unverified only for local runs and for a deploy that
|
|
3910
|
+
* could not read the service.
|
|
3856
3911
|
*
|
|
3857
3912
|
* @param request - The request as delivered, raw body included
|
|
3858
3913
|
* @param options - Protection mode, environment and clock
|
|
@@ -4048,9 +4103,7 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
|
|
|
4048
4103
|
* The Voice Platform signs every `call.*` event — `Authorization: service <serviceId>:<sig>`
|
|
4049
4104
|
* over the raw body, `Content-Type`, `x-timestamp` and path — and `verifyVoiceWebhook` has
|
|
4050
4105
|
* already checked it by the time a request gets here, whenever `VOICE_SERVICE_SECRET` is set.
|
|
4051
|
-
*
|
|
4052
|
-
* a function that wants the endpoint locked before then lists `voiceWebhook` in its `auth`
|
|
4053
|
-
* export, which turns on Basic auth for it like any other handler.
|
|
4106
|
+
* Deploying sets it; when it is unset the check logs one warning and lets the request through.
|
|
4054
4107
|
*
|
|
4055
4108
|
* The plan-to-wire mapping belongs to the v2 client, so the handler's result is routed back
|
|
4056
4109
|
* through `Client.onCall` rather than re-implementing `toWebhookBody` over `resolveFlow`
|
|
@@ -4059,6 +4112,18 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
|
|
|
4059
4112
|
* @internal
|
|
4060
4113
|
*/
|
|
4061
4114
|
export declare function handleVoiceWebhook(userFunction: SinchFunction, context: FunctionContext, event: WebhookRequest, request?: FunctionRequest, logger?: (...args: unknown[]) => void): Promise<FormattedResponse>;
|
|
4115
|
+
/**
|
|
4116
|
+
* Swap `recordToFunctions()`'s placeholder destination for a presigned PUT URL.
|
|
4117
|
+
*
|
|
4118
|
+
* The builder cannot reach the callId or the pod's credentials, so it emits a `startRecording`
|
|
4119
|
+
* whose `destinationUrl` is {@link RECORD_TO_FUNCTIONS_SENTINEL}. This walks the finished
|
|
4120
|
+
* webhook body (the command can sit inside any nested flow), asks the storage for a URL for the
|
|
4121
|
+
* exact key `recordings/<callId>.<format>`, and writes it in. Where that is impossible — no
|
|
4122
|
+
* callId, storage without `getRecordingDestination`, or it throws — the command is removed and
|
|
4123
|
+
* a warning logged, so the placeholder never reaches Sinch.
|
|
4124
|
+
* @internal
|
|
4125
|
+
*/
|
|
4126
|
+
export declare function rewriteRecordingSentinels(body: unknown, callId: string | undefined, storage: IFunctionStorage | undefined): Promise<void>;
|
|
4062
4127
|
/**
|
|
4063
4128
|
* Handle custom endpoint execution
|
|
4064
4129
|
* @internal
|
|
@@ -4591,10 +4656,27 @@ export declare const AGENT_STREAM_PATH = "/stream";
|
|
|
4591
4656
|
* planted at dial time is readable the moment the socket opens.
|
|
4592
4657
|
*/
|
|
4593
4658
|
export declare const AGENT_HEADER_TOKEN = "x-sinch-agent-token";
|
|
4659
|
+
/**
|
|
4660
|
+
* Set by the dev tunnel client once the gateway has welcomed it: the tunnel's public ingress URL,
|
|
4661
|
+
* `https://<gateway>/ingress?tunnel=<id>`. Under `sinch functions dev --tunnel` the tunnel forwards
|
|
4662
|
+
* webhooks to `http://localhost:<port>`, so `context.host` is `localhost:<port>` and useless to
|
|
4663
|
+
* Sinch; this is the address that is reachable.
|
|
4664
|
+
*/
|
|
4665
|
+
export declare const TUNNEL_PUBLIC_URL_ENV = "SINCH_TUNNEL_PUBLIC_URL";
|
|
4666
|
+
/**
|
|
4667
|
+
* This function's public address through the dev tunnel, for `path` — `undefined` when no tunnel
|
|
4668
|
+
* is active. The gateway proxies a WebSocket upgrade at `/ingress/<path>?tunnel=<id>` the same as
|
|
4669
|
+
* an HTTP request, so a socket is `wss://<gateway>/ingress/<path>?tunnel=<id>`.
|
|
4670
|
+
*
|
|
4671
|
+
* @param path - Path on this function, e.g. `/stream`
|
|
4672
|
+
* @param kind - `'ws'` for a socket URL, `'http'` for a webhook or upload URL
|
|
4673
|
+
*/
|
|
4674
|
+
export declare function tunnelPublicUrl(path: string, kind: "ws" | "http"): string | undefined;
|
|
4594
4675
|
/**
|
|
4595
4676
|
* Resolve the WebSocket URL Sinch should dial to reach this function's own media socket.
|
|
4596
4677
|
*
|
|
4597
|
-
* Same order `connectAgent()` uses on v1: an explicit override, then the
|
|
4678
|
+
* Same order `connectAgent()` uses on v1: an explicit override, then the dev tunnel's public address
|
|
4679
|
+
* when one is active, then the host the runtime reports
|
|
4598
4680
|
* for this function, then `STREAM_URL`, then derivation from the deploy env vars.
|
|
4599
4681
|
*
|
|
4600
4682
|
* @param context - Function context; `context.host` is only populated on a request-scoped one
|
|
@@ -4692,8 +4774,8 @@ export interface VoiceCallHandlers {
|
|
|
4692
4774
|
* ```
|
|
4693
4775
|
*
|
|
4694
4776
|
* The events reaching these handlers are signed by the Voice Platform, and the host verifies
|
|
4695
|
-
* that signature
|
|
4696
|
-
*
|
|
4777
|
+
* that signature with `VOICE_SERVICE_SECRET`, which deploying sets. While it is unset the host
|
|
4778
|
+
* logs one warning and delivers the event anyway.
|
|
4697
4779
|
*
|
|
4698
4780
|
* Each handler is bound to `context` (and the raw `request`, if the host passed one) before
|
|
4699
4781
|
* being handed to `context.voice.onCall`, which only knows the narrower, context-free
|
|
@@ -4712,7 +4794,7 @@ export declare function onCall(handlers: VoiceCallHandlers): VoiceWebhookHandler
|
|
|
4712
4794
|
* inbound `call.incoming` event's own `Call`, so a lookup keyed on `call.from` can personalise
|
|
4713
4795
|
* the prompt or greeting ("Hello Maria") before the vendor ever hears the line ring.
|
|
4714
4796
|
*/
|
|
4715
|
-
export type PerCallValue<T> = T | ((call: Call, context: FunctionContext) => T | Promise<T>);
|
|
4797
|
+
export type PerCallValue<T> = T | ((call: Call, context: FunctionContext, data?: Record<string, unknown>) => T | Promise<T>);
|
|
4716
4798
|
/**
|
|
4717
4799
|
* JSON Schema, loosely typed. The runtime does not validate against it — the vendor does, after
|
|
4718
4800
|
* an adapter translates it to that vendor's declaration format — so this stays a plain object
|
|
@@ -4726,16 +4808,6 @@ export interface RealtimeTurn {
|
|
|
4726
4808
|
text: string;
|
|
4727
4809
|
/** ISO 8601 */
|
|
4728
4810
|
timestamp: string;
|
|
4729
|
-
/**
|
|
4730
|
-
* Provider-reported speech (role `'user'`) or playback (role `'agent'`) boundaries, when the
|
|
4731
|
-
* adapter has them precisely — currently only `openai.ts` (GPT-Live), from
|
|
4732
|
-
* `session.input_transcript.delta`/`session.output_transcript.delta`'s own `start_ms`/`end_ms`.
|
|
4733
|
-
* Preferred over `agent.ts`'s own `onSpeechStart`/`onPlaybackStart` fallback chain when present.
|
|
4734
|
-
*/
|
|
4735
|
-
speechStartAt?: string;
|
|
4736
|
-
speechEndAt?: string;
|
|
4737
|
-
playbackStartAt?: string;
|
|
4738
|
-
playbackEndAt?: string;
|
|
4739
4811
|
/**
|
|
4740
4812
|
* `role: 'agent'` only, GPT-Live-specific: time from `session.delegation.created` to the first
|
|
4741
4813
|
* backend output this delegation produced (`response.event`'s first inner event), plus the tool
|
|
@@ -4784,8 +4856,7 @@ export interface TranscriptEntry {
|
|
|
4784
4856
|
delegationMs?: number;
|
|
4785
4857
|
/**
|
|
4786
4858
|
* `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
|
|
4787
|
-
* speech-boundary event directly, that wins —
|
|
4788
|
-
* own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
4859
|
+
* speech-boundary event directly, that wins — Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
4789
4860
|
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
4790
4861
|
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
4791
4862
|
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
@@ -4802,10 +4873,10 @@ export interface TranscriptEntry {
|
|
|
4802
4873
|
/**
|
|
4803
4874
|
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
4804
4875
|
* caller, from whatever playback/response-audio event the provider reports — voice-relay's
|
|
4805
|
-
* `textPlaybackStart`/`Stop`/`Cancel`,
|
|
4806
|
-
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`.
|
|
4807
|
-
*
|
|
4808
|
-
*
|
|
4876
|
+
* `textPlaybackStart`/`Stop`/`Cancel`, Grok's first response audio delta and
|
|
4877
|
+
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. GPT-Live and Gemini
|
|
4878
|
+
* report none, so `agent.ts` stamps them from the first and last outbound speech frame it
|
|
4879
|
+
* forwards to Sinch (wall clock at the relay).
|
|
4809
4880
|
*/
|
|
4810
4881
|
playbackStartAt?: string;
|
|
4811
4882
|
playbackEndAt?: string;
|
|
@@ -4894,6 +4965,14 @@ export interface RealtimeSessionContext {
|
|
|
4894
4965
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
4895
4966
|
*/
|
|
4896
4967
|
hangup(): void;
|
|
4968
|
+
/**
|
|
4969
|
+
* Set by the relay once the call's stereo WAV (caller left, agent right) is in `storage`,
|
|
4970
|
+
* just before `onEnd` runs; absent unless `record` is on, and when saving failed. Read it from
|
|
4971
|
+
* `onEnd` to store the key next to the transcript.
|
|
4972
|
+
*/
|
|
4973
|
+
recording?: {
|
|
4974
|
+
storageKey: string;
|
|
4975
|
+
};
|
|
4897
4976
|
/**
|
|
4898
4977
|
* Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
|
|
4899
4978
|
* `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
|
|
@@ -4922,7 +5001,7 @@ export interface RealtimeTool<Args = unknown> {
|
|
|
4922
5001
|
/** Identity helper — checks a tool's shape against `RealtimeTool` at declaration, not just at `tools: [...]`. */
|
|
4923
5002
|
export declare function tool<Args = unknown>(def: RealtimeTool<Args>): RealtimeTool<Args>;
|
|
4924
5003
|
/** A vendor whose realtime audio session an adapter drives directly — the {@link getRealtimeAdapter} registry keys. */
|
|
4925
|
-
export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
|
|
5004
|
+
export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
|
|
4926
5005
|
/**
|
|
4927
5006
|
* `'voice-relay'` runs no adapter at all: Sinch does speech-to-text and text-to-speech over Voice
|
|
4928
5007
|
* Relay, and `realtimeAgent` drives the LLM loop in text over that same connection — see
|
|
@@ -4960,7 +5039,7 @@ export interface RealtimeAgentOptions {
|
|
|
4960
5039
|
* auto-detect. Added after a live Gemini call had the caller's speech misheard as Spanish
|
|
4961
5040
|
* ("¿Cómo te") and answered in Spanish for a turn. A value, or `(call, context) => value`,
|
|
4962
5041
|
* resolved once per call. Defaults to `'en-US'` (`DEFAULT_LANGUAGE`) — wired where the provider
|
|
4963
|
-
* has a field for it (`gemini`, `deepgram`, `grok`, `voice-relay`); `openai` (GPT-Live) has no
|
|
5042
|
+
* has a field for it (`gemini`, `deepgram`, `grok`, `voice-relay`; `elevenlabs` only when it differs from the default); `openai` (GPT-Live) has no
|
|
4964
5043
|
* documented equivalent field and is left alone.
|
|
4965
5044
|
*/
|
|
4966
5045
|
language?: PerCallValue<string>;
|
|
@@ -5038,6 +5117,29 @@ export interface RealtimeAgentOptions {
|
|
|
5038
5117
|
* the Deepgram adapter.
|
|
5039
5118
|
*/
|
|
5040
5119
|
providerOptions?: Record<string, unknown>;
|
|
5120
|
+
/**
|
|
5121
|
+
* Record the call. Two independent recordings, both into `ctx.storage` under `recordings/`:
|
|
5122
|
+
*
|
|
5123
|
+
* - `stream` (what `true` means): the caller (left) and agent (right) audio this relay sees,
|
|
5124
|
+
* on one timeline, written as `recordings/<callId>.wav` when the session ends
|
|
5125
|
+
* (`ctx.recording` carries the key). Held in memory until then, capped at `MAX_CALL_DURATION`
|
|
5126
|
+
* seconds of audio. Works for every STREAM provider.
|
|
5127
|
+
* - `sinch`: Sinch records the call itself and uploads `recordings/<callId>.mp3` to function
|
|
5128
|
+
* storage through a presigned URL the runtime mints; nothing is held here. Needs the Voice
|
|
5129
|
+
* platform to accept `https` recording destinations, and storage that can presign one.
|
|
5130
|
+
* `ctx.recording` does not report it; the key is fixed, so `storage.exists()` after the call.
|
|
5131
|
+
*/
|
|
5132
|
+
record?: boolean | {
|
|
5133
|
+
stream?: boolean;
|
|
5134
|
+
sinch?: boolean;
|
|
5135
|
+
};
|
|
5136
|
+
/**
|
|
5137
|
+
* Outbound calls placed with `agent.call()` only. The callee is listened to first: when the
|
|
5138
|
+
* provider can speak on request (GPT-Live), `greeting` is held back and sent on the callee's
|
|
5139
|
+
* first speech, or after this many milliseconds of silence, whichever comes first. Defaults to
|
|
5140
|
+
* 4000. Other providers speak the greeting as soon as the session opens, as before.
|
|
5141
|
+
*/
|
|
5142
|
+
outboundGreetingFallbackMs?: number;
|
|
5041
5143
|
/** Override the derived stream URL — same escape hatch `resolveAgentStreamUrl` gives. */
|
|
5042
5144
|
streamUrl?: string;
|
|
5043
5145
|
}
|
|
@@ -5059,6 +5161,10 @@ export type ResolvedRealtimeAgentOptions = Omit<RealtimeAgentOptions, "prompt" |
|
|
|
5059
5161
|
* `agent.ts`'s `resolvePerCallOptions` — optional here only so an adapter's own unit tests can
|
|
5060
5162
|
* build one without it; every adapter that reads it falls back to `DEFAULT_LANGUAGE` itself. */
|
|
5061
5163
|
language?: string;
|
|
5164
|
+
/** Set by `agent.ts` when it withholds `greeting` for the listen-first opening and will call
|
|
5165
|
+
* the adapter's `speak` later: an adapter whose vendor plays its own saved first message must
|
|
5166
|
+
* suppress it. */
|
|
5167
|
+
greetingHeld?: boolean;
|
|
5062
5168
|
};
|
|
5063
5169
|
/**
|
|
5064
5170
|
* Normalised events an adapter reports back to the relay loop as they happen. An adapter never
|
|
@@ -5141,6 +5247,12 @@ export interface RealtimeAdapter {
|
|
|
5141
5247
|
clear(session: VendorSession): void;
|
|
5142
5248
|
/** Tear down the vendor session. */
|
|
5143
5249
|
close(session: VendorSession): void;
|
|
5250
|
+
/**
|
|
5251
|
+
* Optional. Have the agent say `text` now, in a session opened without a greeting. Only an
|
|
5252
|
+
* adapter that implements it gets the listen-first opening on an outbound call; the rest
|
|
5253
|
+
* receive the greeting at `connect` as before.
|
|
5254
|
+
*/
|
|
5255
|
+
speak?(session: VendorSession, text: string): void;
|
|
5144
5256
|
}
|
|
5145
5257
|
/**
|
|
5146
5258
|
* A `realtimeAgent()` result, widened with `connect` — the plan-building half of the default
|
|
@@ -5172,7 +5284,42 @@ export interface RealtimeAdapter {
|
|
|
5172
5284
|
*/
|
|
5173
5285
|
export type RealtimeAgentHandle = VoiceFunction & {
|
|
5174
5286
|
connect: VoiceCallHandler;
|
|
5287
|
+
/**
|
|
5288
|
+
* Call `to` and put this agent on the call once it is answered. Mirrors `@sinch/agents`'
|
|
5289
|
+
* `agent.call(number, { context, from, ... })`. Resolves with the Calls API response (session
|
|
5290
|
+
* id, no call id). The callee is listened to first - see `outboundGreetingFallbackMs`.
|
|
5291
|
+
*
|
|
5292
|
+
* ```typescript
|
|
5293
|
+
* await agent.call('+15551234567', { from: '+15557654321', data: { name: 'Anna' } });
|
|
5294
|
+
* ```
|
|
5295
|
+
*/
|
|
5296
|
+
call: (to: string, options?: RealtimeAgentCallOptions) => Promise<v2.CallResponse>;
|
|
5175
5297
|
} & v2.DialableAgent;
|
|
5298
|
+
/** Options for {@link RealtimeAgentHandle.call}. */
|
|
5299
|
+
export interface RealtimeAgentCallOptions {
|
|
5300
|
+
/** Caller id presented to the callee. Defaults to the service's. */
|
|
5301
|
+
from?: string;
|
|
5302
|
+
/**
|
|
5303
|
+
* Per-call context. Handed, as the third argument, to `prompt`, `greeting`, `voice`,
|
|
5304
|
+
* `transferTo` and `language` when they are functions. Kept in this process until the call
|
|
5305
|
+
* ends, so it must be placed and answered on the same instance.
|
|
5306
|
+
*/
|
|
5307
|
+
data?: Record<string, unknown>;
|
|
5308
|
+
/**
|
|
5309
|
+
* Realtime provider for this call, in place of the agent's `provider`. The prompt, tools,
|
|
5310
|
+
* recording and `onEnd` stay the agent's own. An unknown provider throws before dialling.
|
|
5311
|
+
*/
|
|
5312
|
+
provider?: RealtimeAudioProvider;
|
|
5313
|
+
/** Seconds to wait for an answer. Maximum 60. */
|
|
5314
|
+
timeout?: number;
|
|
5315
|
+
/** Maximum call duration in seconds. */
|
|
5316
|
+
maxDuration?: number;
|
|
5317
|
+
/**
|
|
5318
|
+
* Request-scoped context to place the call with. Defaults to the one the function started
|
|
5319
|
+
* with, which carries credentials but no `host`.
|
|
5320
|
+
*/
|
|
5321
|
+
context?: FunctionContext;
|
|
5322
|
+
}
|
|
5176
5323
|
/**
|
|
5177
5324
|
* Build a `RealtimeAgentOptions` into a `RealtimeAgentHandle` (a `VoiceFunction` plus `connect`).
|
|
5178
5325
|
*
|
|
@@ -5871,6 +6018,11 @@ export declare class LocalStorage implements IFunctionStorage {
|
|
|
5871
6018
|
private baseDir;
|
|
5872
6019
|
constructor(baseDir?: string);
|
|
5873
6020
|
private resolvePath;
|
|
6021
|
+
/**
|
|
6022
|
+
* Sinch Voice uploads the finished recording itself, so dev points it at the runtime's built-in
|
|
6023
|
+
* `PUT /_sinch/recording/:file` receiver (RECORDING_RECEIVER_PATH) over the tunnel, which writes into `recordings/`.
|
|
6024
|
+
*/
|
|
6025
|
+
getRecordingDestination(callId: string, format: "mp3" | "wav"): Promise<string>;
|
|
5874
6026
|
write(key: string, data: string | Buffer): Promise<void>;
|
|
5875
6027
|
read(key: string): Promise<Buffer>;
|
|
5876
6028
|
list(prefix?: string): Promise<string[]>;
|
|
@@ -6017,7 +6169,7 @@ export declare class SecretsLoader {
|
|
|
6017
6169
|
export declare const secretsLoader: SecretsLoader;
|
|
6018
6170
|
|
|
6019
6171
|
declare namespace v2 {
|
|
6020
|
-
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 };
|
|
6172
|
+
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, MAX_SAY_CHARS, MenuCall, MenuDefinition, MenuInput, MenuItemBuilder, Money, Options, Origin, OriginationType, PatchTarget, PlaceCallOptions, PromptBuilder, PromptFlow, RECORD_TO_FUNCTIONS_SENTINEL, REDACTED, RecordToFunctionsOptions, 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 };
|
|
6021
6173
|
}
|
|
6022
6174
|
|
|
6023
6175
|
export {
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,10 @@ import {
|
|
|
25
25
|
MenuTemplates,
|
|
26
26
|
NOTIFICATION_EVENTS,
|
|
27
27
|
PieSvamlBuilder,
|
|
28
|
+
RECORDING_RECEIVER_PATH,
|
|
28
29
|
SESSION_COOKIE_NAME,
|
|
29
30
|
SecretsLoader,
|
|
31
|
+
TUNNEL_PUBLIC_URL_ENV,
|
|
30
32
|
TemplateRender,
|
|
31
33
|
TunnelClient,
|
|
32
34
|
UniversalConfig,
|
|
@@ -117,12 +119,14 @@ import {
|
|
|
117
119
|
onCall,
|
|
118
120
|
parseJson,
|
|
119
121
|
realtimeAgent,
|
|
122
|
+
recordingKey,
|
|
120
123
|
redactAsText,
|
|
121
124
|
redactSecrets,
|
|
122
125
|
renderLoginPage,
|
|
123
126
|
resetSinchClients,
|
|
124
127
|
resetVoiceSignatureWarning,
|
|
125
128
|
resolveAgentStreamUrl,
|
|
129
|
+
rewriteRecordingSentinels,
|
|
126
130
|
safeCut,
|
|
127
131
|
secretLookaheadBytes,
|
|
128
132
|
secretsLoader,
|
|
@@ -138,12 +142,13 @@ import {
|
|
|
138
142
|
tool,
|
|
139
143
|
transformKeys,
|
|
140
144
|
tryAutoConfigureAsync,
|
|
145
|
+
tunnelPublicUrl,
|
|
141
146
|
validateBasicAuth,
|
|
142
147
|
validateVoiceSignature,
|
|
143
148
|
validateVoiceV1Request,
|
|
144
149
|
verifyVoiceWebhook,
|
|
145
150
|
voiceRelay
|
|
146
|
-
} from "./chunk-
|
|
151
|
+
} from "./chunk-KGCIUPCT.js";
|
|
147
152
|
export {
|
|
148
153
|
AGENT_HEADER_TOKEN,
|
|
149
154
|
AGENT_STREAM_PATH,
|
|
@@ -167,8 +172,10 @@ export {
|
|
|
167
172
|
MenuTemplates,
|
|
168
173
|
NOTIFICATION_EVENTS,
|
|
169
174
|
PieSvamlBuilder,
|
|
175
|
+
RECORDING_RECEIVER_PATH,
|
|
170
176
|
SESSION_COOKIE_NAME,
|
|
171
177
|
SecretsLoader,
|
|
178
|
+
TUNNEL_PUBLIC_URL_ENV,
|
|
172
179
|
TemplateRender,
|
|
173
180
|
TunnelClient,
|
|
174
181
|
UniversalConfig,
|
|
@@ -262,12 +269,14 @@ export {
|
|
|
262
269
|
parseJson,
|
|
263
270
|
parseJson as parseJsonLenient,
|
|
264
271
|
realtimeAgent,
|
|
272
|
+
recordingKey,
|
|
265
273
|
redactAsText,
|
|
266
274
|
redactSecrets,
|
|
267
275
|
renderLoginPage,
|
|
268
276
|
resetSinchClients,
|
|
269
277
|
resetVoiceSignatureWarning,
|
|
270
278
|
resolveAgentStreamUrl,
|
|
279
|
+
rewriteRecordingSentinels,
|
|
271
280
|
safeCut,
|
|
272
281
|
secretLookaheadBytes,
|
|
273
282
|
secretsLoader,
|
|
@@ -285,6 +294,7 @@ export {
|
|
|
285
294
|
transformKeys,
|
|
286
295
|
transformKeys as transformKeysToCamelCase,
|
|
287
296
|
tryAutoConfigureAsync,
|
|
297
|
+
tunnelPublicUrl,
|
|
288
298
|
validateBasicAuth,
|
|
289
299
|
validateVoiceSignature,
|
|
290
300
|
validateVoiceV1Request,
|