@sinch/functions-runtime 0.7.1 → 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-5K5FDUEL.js → chunk-KGCIUPCT.js} +1229 -429
- package/dist/chunk-KGCIUPCT.js.map +1 -0
- package/dist/index.d.ts +178 -35
- package/dist/index.js +11 -1
- package/dist/voice/v2.d.ts +92 -14
- package/dist/voice/v2.js +5 -1
- package/package.json +1 -1
- package/dist/chunk-5K5FDUEL.js.map +0 -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 {
|
|
@@ -2403,6 +2433,22 @@ export declare class CommandBuilder {
|
|
|
2403
2433
|
* ```
|
|
2404
2434
|
*/
|
|
2405
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;
|
|
2406
2452
|
/**
|
|
2407
2453
|
* Stop a named recording. Non-blocking.
|
|
2408
2454
|
*
|
|
@@ -2613,7 +2659,7 @@ export interface Options {
|
|
|
2613
2659
|
serviceId?: string;
|
|
2614
2660
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
2615
2661
|
host?: string;
|
|
2616
|
-
/** 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. */
|
|
2617
2663
|
publicUrl?: string;
|
|
2618
2664
|
/** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
|
|
2619
2665
|
fetch?: typeof globalThis.fetch;
|
|
@@ -3105,6 +3151,7 @@ export declare function createClient(context?: ClientContext, options?: Options)
|
|
|
3105
3151
|
declare const DEFAULT_HOST = "https://voice.api.sinch.com";
|
|
3106
3152
|
declare const REDACTED = "[redacted]";
|
|
3107
3153
|
declare function redactCredentials<T>(body: T): T;
|
|
3154
|
+
declare const MAX_SAY_CHARS = 600;
|
|
3108
3155
|
declare function stringify(value: unknown): string;
|
|
3109
3156
|
/** Options for {@link connectAgent}. */
|
|
3110
3157
|
interface ConnectAgentOptions$1 extends SipAgentOptions {
|
|
@@ -3858,10 +3905,9 @@ export declare function resetVoiceSignatureWarning(): void;
|
|
|
3858
3905
|
*
|
|
3859
3906
|
* Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks, with one deliberate
|
|
3860
3907
|
* exception: when the mode says validate but `VOICE_SERVICE_SECRET` is unset, the request is
|
|
3861
|
-
* allowed and a single warning is logged.
|
|
3862
|
-
*
|
|
3863
|
-
*
|
|
3864
|
-
* 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.
|
|
3865
3911
|
*
|
|
3866
3912
|
* @param request - The request as delivered, raw body included
|
|
3867
3913
|
* @param options - Protection mode, environment and clock
|
|
@@ -4057,9 +4103,7 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
|
|
|
4057
4103
|
* The Voice Platform signs every `call.*` event — `Authorization: service <serviceId>:<sig>`
|
|
4058
4104
|
* over the raw body, `Content-Type`, `x-timestamp` and path — and `verifyVoiceWebhook` has
|
|
4059
4105
|
* already checked it by the time a request gets here, whenever `VOICE_SERVICE_SECRET` is set.
|
|
4060
|
-
*
|
|
4061
|
-
* a function that wants the endpoint locked before then lists `voiceWebhook` in its `auth`
|
|
4062
|
-
* 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.
|
|
4063
4107
|
*
|
|
4064
4108
|
* The plan-to-wire mapping belongs to the v2 client, so the handler's result is routed back
|
|
4065
4109
|
* through `Client.onCall` rather than re-implementing `toWebhookBody` over `resolveFlow`
|
|
@@ -4068,6 +4112,18 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
|
|
|
4068
4112
|
* @internal
|
|
4069
4113
|
*/
|
|
4070
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>;
|
|
4071
4127
|
/**
|
|
4072
4128
|
* Handle custom endpoint execution
|
|
4073
4129
|
* @internal
|
|
@@ -4600,10 +4656,27 @@ export declare const AGENT_STREAM_PATH = "/stream";
|
|
|
4600
4656
|
* planted at dial time is readable the moment the socket opens.
|
|
4601
4657
|
*/
|
|
4602
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;
|
|
4603
4675
|
/**
|
|
4604
4676
|
* Resolve the WebSocket URL Sinch should dial to reach this function's own media socket.
|
|
4605
4677
|
*
|
|
4606
|
-
* 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
|
|
4607
4680
|
* for this function, then `STREAM_URL`, then derivation from the deploy env vars.
|
|
4608
4681
|
*
|
|
4609
4682
|
* @param context - Function context; `context.host` is only populated on a request-scoped one
|
|
@@ -4701,8 +4774,8 @@ export interface VoiceCallHandlers {
|
|
|
4701
4774
|
* ```
|
|
4702
4775
|
*
|
|
4703
4776
|
* The events reaching these handlers are signed by the Voice Platform, and the host verifies
|
|
4704
|
-
* that signature
|
|
4705
|
-
*
|
|
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.
|
|
4706
4779
|
*
|
|
4707
4780
|
* Each handler is bound to `context` (and the raw `request`, if the host passed one) before
|
|
4708
4781
|
* being handed to `context.voice.onCall`, which only knows the narrower, context-free
|
|
@@ -4721,7 +4794,7 @@ export declare function onCall(handlers: VoiceCallHandlers): VoiceWebhookHandler
|
|
|
4721
4794
|
* inbound `call.incoming` event's own `Call`, so a lookup keyed on `call.from` can personalise
|
|
4722
4795
|
* the prompt or greeting ("Hello Maria") before the vendor ever hears the line ring.
|
|
4723
4796
|
*/
|
|
4724
|
-
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>);
|
|
4725
4798
|
/**
|
|
4726
4799
|
* JSON Schema, loosely typed. The runtime does not validate against it — the vendor does, after
|
|
4727
4800
|
* an adapter translates it to that vendor's declaration format — so this stays a plain object
|
|
@@ -4735,16 +4808,6 @@ export interface RealtimeTurn {
|
|
|
4735
4808
|
text: string;
|
|
4736
4809
|
/** ISO 8601 */
|
|
4737
4810
|
timestamp: string;
|
|
4738
|
-
/**
|
|
4739
|
-
* Provider-reported speech (role `'user'`) or playback (role `'agent'`) boundaries, when the
|
|
4740
|
-
* adapter has them precisely — currently only `openai.ts` (GPT-Live), from
|
|
4741
|
-
* `session.input_transcript.delta`/`session.output_transcript.delta`'s own `start_ms`/`end_ms`.
|
|
4742
|
-
* Preferred over `agent.ts`'s own `onSpeechStart`/`onPlaybackStart` fallback chain when present.
|
|
4743
|
-
*/
|
|
4744
|
-
speechStartAt?: string;
|
|
4745
|
-
speechEndAt?: string;
|
|
4746
|
-
playbackStartAt?: string;
|
|
4747
|
-
playbackEndAt?: string;
|
|
4748
4811
|
/**
|
|
4749
4812
|
* `role: 'agent'` only, GPT-Live-specific: time from `session.delegation.created` to the first
|
|
4750
4813
|
* backend output this delegation produced (`response.event`'s first inner event), plus the tool
|
|
@@ -4793,8 +4856,7 @@ export interface TranscriptEntry {
|
|
|
4793
4856
|
delegationMs?: number;
|
|
4794
4857
|
/**
|
|
4795
4858
|
* `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
|
|
4796
|
-
* speech-boundary event directly, that wins —
|
|
4797
|
-
* 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`,
|
|
4798
4860
|
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
4799
4861
|
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
4800
4862
|
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
@@ -4811,10 +4873,10 @@ export interface TranscriptEntry {
|
|
|
4811
4873
|
/**
|
|
4812
4874
|
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
4813
4875
|
* caller, from whatever playback/response-audio event the provider reports — voice-relay's
|
|
4814
|
-
* `textPlaybackStart`/`Stop`/`Cancel`,
|
|
4815
|
-
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`.
|
|
4816
|
-
*
|
|
4817
|
-
*
|
|
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).
|
|
4818
4880
|
*/
|
|
4819
4881
|
playbackStartAt?: string;
|
|
4820
4882
|
playbackEndAt?: string;
|
|
@@ -4903,6 +4965,14 @@ export interface RealtimeSessionContext {
|
|
|
4903
4965
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
4904
4966
|
*/
|
|
4905
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
|
+
};
|
|
4906
4976
|
/**
|
|
4907
4977
|
* Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
|
|
4908
4978
|
* `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
|
|
@@ -4931,7 +5001,7 @@ export interface RealtimeTool<Args = unknown> {
|
|
|
4931
5001
|
/** Identity helper — checks a tool's shape against `RealtimeTool` at declaration, not just at `tools: [...]`. */
|
|
4932
5002
|
export declare function tool<Args = unknown>(def: RealtimeTool<Args>): RealtimeTool<Args>;
|
|
4933
5003
|
/** A vendor whose realtime audio session an adapter drives directly — the {@link getRealtimeAdapter} registry keys. */
|
|
4934
|
-
export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
|
|
5004
|
+
export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
|
|
4935
5005
|
/**
|
|
4936
5006
|
* `'voice-relay'` runs no adapter at all: Sinch does speech-to-text and text-to-speech over Voice
|
|
4937
5007
|
* Relay, and `realtimeAgent` drives the LLM loop in text over that same connection — see
|
|
@@ -4969,7 +5039,7 @@ export interface RealtimeAgentOptions {
|
|
|
4969
5039
|
* auto-detect. Added after a live Gemini call had the caller's speech misheard as Spanish
|
|
4970
5040
|
* ("¿Cómo te") and answered in Spanish for a turn. A value, or `(call, context) => value`,
|
|
4971
5041
|
* resolved once per call. Defaults to `'en-US'` (`DEFAULT_LANGUAGE`) — wired where the provider
|
|
4972
|
-
* 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
|
|
4973
5043
|
* documented equivalent field and is left alone.
|
|
4974
5044
|
*/
|
|
4975
5045
|
language?: PerCallValue<string>;
|
|
@@ -5047,6 +5117,29 @@ export interface RealtimeAgentOptions {
|
|
|
5047
5117
|
* the Deepgram adapter.
|
|
5048
5118
|
*/
|
|
5049
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;
|
|
5050
5143
|
/** Override the derived stream URL — same escape hatch `resolveAgentStreamUrl` gives. */
|
|
5051
5144
|
streamUrl?: string;
|
|
5052
5145
|
}
|
|
@@ -5068,6 +5161,10 @@ export type ResolvedRealtimeAgentOptions = Omit<RealtimeAgentOptions, "prompt" |
|
|
|
5068
5161
|
* `agent.ts`'s `resolvePerCallOptions` — optional here only so an adapter's own unit tests can
|
|
5069
5162
|
* build one without it; every adapter that reads it falls back to `DEFAULT_LANGUAGE` itself. */
|
|
5070
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;
|
|
5071
5168
|
};
|
|
5072
5169
|
/**
|
|
5073
5170
|
* Normalised events an adapter reports back to the relay loop as they happen. An adapter never
|
|
@@ -5150,6 +5247,12 @@ export interface RealtimeAdapter {
|
|
|
5150
5247
|
clear(session: VendorSession): void;
|
|
5151
5248
|
/** Tear down the vendor session. */
|
|
5152
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;
|
|
5153
5256
|
}
|
|
5154
5257
|
/**
|
|
5155
5258
|
* A `realtimeAgent()` result, widened with `connect` — the plan-building half of the default
|
|
@@ -5181,7 +5284,42 @@ export interface RealtimeAdapter {
|
|
|
5181
5284
|
*/
|
|
5182
5285
|
export type RealtimeAgentHandle = VoiceFunction & {
|
|
5183
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>;
|
|
5184
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
|
+
}
|
|
5185
5323
|
/**
|
|
5186
5324
|
* Build a `RealtimeAgentOptions` into a `RealtimeAgentHandle` (a `VoiceFunction` plus `connect`).
|
|
5187
5325
|
*
|
|
@@ -5880,6 +6018,11 @@ export declare class LocalStorage implements IFunctionStorage {
|
|
|
5880
6018
|
private baseDir;
|
|
5881
6019
|
constructor(baseDir?: string);
|
|
5882
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>;
|
|
5883
6026
|
write(key: string, data: string | Buffer): Promise<void>;
|
|
5884
6027
|
read(key: string): Promise<Buffer>;
|
|
5885
6028
|
list(prefix?: string): Promise<string[]>;
|
|
@@ -6026,7 +6169,7 @@ export declare class SecretsLoader {
|
|
|
6026
6169
|
export declare const secretsLoader: SecretsLoader;
|
|
6027
6170
|
|
|
6028
6171
|
declare namespace v2 {
|
|
6029
|
-
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 };
|
|
6030
6173
|
}
|
|
6031
6174
|
|
|
6032
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,
|