@sinch/functions-runtime 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -984,7 +984,38 @@ 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
+ /**
998
+ * The presigned PUT URL for `recordings/<callId>.<format>`: the same URL the host swaps in for
999
+ * `recordToFunctions()`. Use it to pass your own `startRecording({ destinationUrl })` (or any
1000
+ * recording command) the function's storage as the destination. Optional like
1001
+ * `getRecordingDestination`; the built-in dev and production storage both provide it.
1002
+ *
1003
+ * @param callId - The call the recording belongs to
1004
+ * @param format - `mp3` (default) or `wav`, any case
1005
+ * @throws On an unsupported format, or when no URL can be produced (dev without a tunnel)
1006
+ */
1007
+ recordingUrl?(callId: string, format?: string): Promise<string>;
1008
+ getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
987
1009
  }
1010
+ /** Where the dev runtime receives Sinch's recording upload (`PUT <path><callId>.<format>`). */
1011
+ export declare const RECORDING_RECEIVER_PATH = "/_sinch/recording/";
1012
+ /** Lowercase a recording format and reject anything but `mp3` or `wav`. */
1013
+ export declare function normalizeRecordingFormat(format: string): "mp3" | "wav";
1014
+ /**
1015
+ * The storage key for a call's recording, `recordings/<callId>.<format>`, with anything outside
1016
+ * `[\w-]` in the callId replaced so it cannot leave `recordings/`.
1017
+ */
1018
+ export declare function recordingKey(callId: string, format: "mp3" | "wav"): string;
988
1019
  /**
989
1020
  * The config seam — the only thing this module needs from its host.
990
1021
  *
@@ -1398,7 +1429,7 @@ interface RecordingOptions$1 {
1398
1429
  *
1399
1430
  * As sensitive as an IAM key — see {@link ../commands.js#RecordingCredentials}.
1400
1431
  */
1401
- credentials: string;
1432
+ credentials?: string;
1402
1433
  /** Speech-to-text settings */
1403
1434
  transcriptionOptions?: TranscriptionOptions;
1404
1435
  }
@@ -1666,6 +1697,11 @@ export interface DialableAgent {
1666
1697
  * @param context - The context the voice client was created with, when it had one
1667
1698
  */
1668
1699
  endpointFor(call: WebhookRequest, context: ClientContext | undefined): To;
1700
+ /**
1701
+ * Commands `dialAgent` places before the agent leg, built from the same call — a
1702
+ * `realtimeAgent` that records the call starts its recording here. Optional.
1703
+ */
1704
+ commandsBefore?(call: WebhookRequest, context: ClientContext | undefined): Command[];
1669
1705
  }
1670
1706
  /** SIP settings for an agent leg; each defaults to what the provider requires. */
1671
1707
  export interface SipAgentOptions {
@@ -1922,15 +1958,20 @@ export interface RecordingCredentials {
1922
1958
  /** Storage region, e.g. `eu-central-1` */
1923
1959
  region: string;
1924
1960
  }
1961
+ declare const RECORD_TO_FUNCTIONS_SENTINEL = "@functions";
1925
1962
  /** Everything a `startRecording` command can carry */
1926
1963
  export interface StartRecordingOptions {
1927
- /** Destination URL, e.g. `s3://voice-recordings-prod/calls` */
1964
+ /**
1965
+ * Destination URL, e.g. `s3://voice-recordings-prod/calls`, or a presigned `https://` PUT URL
1966
+ * (no credentials then).
1967
+ */
1928
1968
  destinationUrl: string;
1929
1969
  /**
1930
1970
  * Credentials for the destination. Prefer the structured form; the raw colon-delimited
1931
- * string is there for credential formats this library does not model.
1971
+ * string is there for credential formats this library does not model. Required unless
1972
+ * `destinationUrl` is an `https://` URL, which carries its own authorization.
1932
1973
  */
1933
- credentials: RecordingCredentials | string;
1974
+ credentials?: RecordingCredentials | string;
1934
1975
  /**
1935
1976
  * Storage service. Defaults to `AWS`, and is always emitted — the schema lists
1936
1977
  * `destination` as required, whatever its documented default.
@@ -1967,6 +2008,8 @@ export interface StartRecordingOptions {
1967
2008
  */
1968
2009
  onFailure?: Flow;
1969
2010
  }
2011
+ /** Options for {@link CommandBuilder.recordToFunctions} */
2012
+ export type RecordToFunctionsOptions = Pick<StartRecordingOptions, "recordingName" | "format" | "recordingType" | "onFinish" | "onFailure">;
1970
2013
  /** Anything that can stand in for a menu prompt: a builder, a callback, or plain text. */
1971
2014
  export type PromptFlow = string | PromptBuilder | ((prompt: PromptBuilder) => PromptBuilder | void);
1972
2015
  declare class PromptBuilder {
@@ -2403,6 +2446,22 @@ export declare class CommandBuilder {
2403
2446
  * ```
2404
2447
  */
2405
2448
  startRecording(options: StartRecordingOptions): this;
2449
+ /**
2450
+ * Record the call into this function's own storage (`recordings/<callId>.mp3`), with no
2451
+ * credentials. Emits a `startRecording` whose destination is a placeholder
2452
+ * ({@link RECORD_TO_FUNCTIONS_SENTINEL}); the runtime host replaces it with a presigned PUT
2453
+ * URL for the exact key just before the response is sent, and drops the command with a warning
2454
+ * when it cannot (no callId, or storage without a recording destination). Needs a runtime
2455
+ * that does the rewrite — sending this builder's output anywhere else delivers the placeholder.
2456
+ *
2457
+ * Transcription is not offered: the transcript URL is derived from the recording URL, which a
2458
+ * presigned URL cannot carry. The recording is named so {@link stopRecording} can end it;
2459
+ * `recordingName` defaults to `functions-recording`. Without an `onFailure` flow a failed
2460
+ * recording is silent — the platform sends no webhook for it.
2461
+ *
2462
+ * @param options - Format (default `MP3`), recording name, streams captured, outcome flows
2463
+ */
2464
+ recordToFunctions(options?: RecordToFunctionsOptions): this;
2406
2465
  /**
2407
2466
  * Stop a named recording. Non-blocking.
2408
2467
  *
@@ -2613,7 +2672,7 @@ export interface Options {
2613
2672
  serviceId?: string;
2614
2673
  /** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
2615
2674
  host?: string;
2616
- /** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
2675
+ /** 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
2676
  publicUrl?: string;
2618
2677
  /** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
2619
2678
  fetch?: typeof globalThis.fetch;
@@ -3105,6 +3164,7 @@ export declare function createClient(context?: ClientContext, options?: Options)
3105
3164
  declare const DEFAULT_HOST = "https://voice.api.sinch.com";
3106
3165
  declare const REDACTED = "[redacted]";
3107
3166
  declare function redactCredentials<T>(body: T): T;
3167
+ declare const MAX_SAY_CHARS = 600;
3108
3168
  declare function stringify(value: unknown): string;
3109
3169
  /** Options for {@link connectAgent}. */
3110
3170
  interface ConnectAgentOptions$1 extends SipAgentOptions {
@@ -3858,10 +3918,9 @@ export declare function resetVoiceSignatureWarning(): void;
3858
3918
  *
3859
3919
  * Gated by the same `WEBHOOK_PROTECTION` modes as the v1 callbacks, with one deliberate
3860
3920
  * exception: when the mode says validate but `VOICE_SERVICE_SECRET` is unset, the request is
3861
- * allowed and a single warning is logged. Sinch does not yet expose a service's secret through
3862
- * any API or portal, so enforcing without one would reject every legitimate webhook and take
3863
- * every v2 function down. Templates ship `WEBHOOK_PROTECTION=deploy` today and start enforcing
3864
- * the moment a secret is set, with no code or configuration change.
3921
+ * allowed and a single warning is logged. Deploying sets `VOICE_SERVICE_SECRET` from the
3922
+ * function's voice service, so the gate is unverified only for local runs and for a deploy that
3923
+ * could not read the service.
3865
3924
  *
3866
3925
  * @param request - The request as delivered, raw body included
3867
3926
  * @param options - Protection mode, environment and clock
@@ -4057,9 +4116,7 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
4057
4116
  * The Voice Platform signs every `call.*` event — `Authorization: service <serviceId>:<sig>`
4058
4117
  * over the raw body, `Content-Type`, `x-timestamp` and path — and `verifyVoiceWebhook` has
4059
4118
  * already checked it by the time a request gets here, whenever `VOICE_SERVICE_SECRET` is set.
4060
- * Until Sinch exposes that secret the check logs one warning and lets the request through, so
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.
4119
+ * Deploying sets it; when it is unset the check logs one warning and lets the request through.
4063
4120
  *
4064
4121
  * The plan-to-wire mapping belongs to the v2 client, so the handler's result is routed back
4065
4122
  * through `Client.onCall` rather than re-implementing `toWebhookBody` over `resolveFlow`
@@ -4068,6 +4125,18 @@ export declare function handleVoiceV1Callback(functionName: string, userFunction
4068
4125
  * @internal
4069
4126
  */
4070
4127
  export declare function handleVoiceWebhook(userFunction: SinchFunction, context: FunctionContext, event: WebhookRequest, request?: FunctionRequest, logger?: (...args: unknown[]) => void): Promise<FormattedResponse>;
4128
+ /**
4129
+ * Swap `recordToFunctions()`'s placeholder destination for a presigned PUT URL.
4130
+ *
4131
+ * The builder cannot reach the callId or the pod's credentials, so it emits a `startRecording`
4132
+ * whose `destinationUrl` is {@link RECORD_TO_FUNCTIONS_SENTINEL}. This walks the finished
4133
+ * webhook body (the command can sit inside any nested flow), asks the storage for a URL for the
4134
+ * exact key `recordings/<callId>.<format>`, and writes it in. Where that is impossible — no
4135
+ * callId, storage with neither `recordingUrl` nor `getRecordingDestination`, or it throws — the command is removed and
4136
+ * a warning logged, so the placeholder never reaches Sinch.
4137
+ * @internal
4138
+ */
4139
+ export declare function rewriteRecordingSentinels(body: unknown, callId: string | undefined, storage: IFunctionStorage | undefined): Promise<void>;
4071
4140
  /**
4072
4141
  * Handle custom endpoint execution
4073
4142
  * @internal
@@ -4600,10 +4669,27 @@ export declare const AGENT_STREAM_PATH = "/stream";
4600
4669
  * planted at dial time is readable the moment the socket opens.
4601
4670
  */
4602
4671
  export declare const AGENT_HEADER_TOKEN = "x-sinch-agent-token";
4672
+ /**
4673
+ * Set by the dev tunnel client once the gateway has welcomed it: the tunnel's public ingress URL,
4674
+ * `https://<gateway>/ingress?tunnel=<id>`. Under `sinch functions dev --tunnel` the tunnel forwards
4675
+ * webhooks to `http://localhost:<port>`, so `context.host` is `localhost:<port>` and useless to
4676
+ * Sinch; this is the address that is reachable.
4677
+ */
4678
+ export declare const TUNNEL_PUBLIC_URL_ENV = "SINCH_TUNNEL_PUBLIC_URL";
4679
+ /**
4680
+ * This function's public address through the dev tunnel, for `path` — `undefined` when no tunnel
4681
+ * is active. The gateway proxies a WebSocket upgrade at `/ingress/<path>?tunnel=<id>` the same as
4682
+ * an HTTP request, so a socket is `wss://<gateway>/ingress/<path>?tunnel=<id>`.
4683
+ *
4684
+ * @param path - Path on this function, e.g. `/stream`
4685
+ * @param kind - `'ws'` for a socket URL, `'http'` for a webhook or upload URL
4686
+ */
4687
+ export declare function tunnelPublicUrl(path: string, kind: "ws" | "http"): string | undefined;
4603
4688
  /**
4604
4689
  * Resolve the WebSocket URL Sinch should dial to reach this function's own media socket.
4605
4690
  *
4606
- * Same order `connectAgent()` uses on v1: an explicit override, then the host the runtime reports
4691
+ * Same order `connectAgent()` uses on v1: an explicit override, then the dev tunnel's public address
4692
+ * when one is active, then the host the runtime reports
4607
4693
  * for this function, then `STREAM_URL`, then derivation from the deploy env vars.
4608
4694
  *
4609
4695
  * @param context - Function context; `context.host` is only populated on a request-scoped one
@@ -4701,8 +4787,8 @@ export interface VoiceCallHandlers {
4701
4787
  * ```
4702
4788
  *
4703
4789
  * The events reaching these handlers are signed by the Voice Platform, and the host verifies
4704
- * that signature once `VOICE_SERVICE_SECRET` is set. While it is unset — Sinch does not expose
4705
- * a service's secret yet — the host logs one warning and delivers the event anyway.
4790
+ * that signature with `VOICE_SERVICE_SECRET`, which deploying sets. While it is unset the host
4791
+ * logs one warning and delivers the event anyway.
4706
4792
  *
4707
4793
  * Each handler is bound to `context` (and the raw `request`, if the host passed one) before
4708
4794
  * being handed to `context.voice.onCall`, which only knows the narrower, context-free
@@ -4721,7 +4807,7 @@ export declare function onCall(handlers: VoiceCallHandlers): VoiceWebhookHandler
4721
4807
  * inbound `call.incoming` event's own `Call`, so a lookup keyed on `call.from` can personalise
4722
4808
  * the prompt or greeting ("Hello Maria") before the vendor ever hears the line ring.
4723
4809
  */
4724
- export type PerCallValue<T> = T | ((call: Call, context: FunctionContext) => T | Promise<T>);
4810
+ export type PerCallValue<T> = T | ((call: Call, context: FunctionContext, data?: Record<string, unknown>) => T | Promise<T>);
4725
4811
  /**
4726
4812
  * JSON Schema, loosely typed. The runtime does not validate against it — the vendor does, after
4727
4813
  * an adapter translates it to that vendor's declaration format — so this stays a plain object
@@ -4735,16 +4821,6 @@ export interface RealtimeTurn {
4735
4821
  text: string;
4736
4822
  /** ISO 8601 */
4737
4823
  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
4824
  /**
4749
4825
  * `role: 'agent'` only, GPT-Live-specific: time from `session.delegation.created` to the first
4750
4826
  * backend output this delegation produced (`response.event`'s first inner event), plus the tool
@@ -4793,8 +4869,7 @@ export interface TranscriptEntry {
4793
4869
  delegationMs?: number;
4794
4870
  /**
4795
4871
  * `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
4796
- * speech-boundary event directly, that wins — GPT-Live from `session.input_transcript.delta`'s
4797
- * own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
4872
+ * speech-boundary event directly, that wins — Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
4798
4873
  * Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
4799
4874
  * all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
4800
4875
  * `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
@@ -4811,10 +4886,10 @@ export interface TranscriptEntry {
4811
4886
  /**
4812
4887
  * `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
4813
4888
  * caller, from whatever playback/response-audio event the provider reports — voice-relay's
4814
- * `textPlaybackStart`/`Stop`/`Cancel`, OpenAI/Grok's first response audio delta and
4815
- * `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. Gemini not wired (no
4816
- * playback signal in what its adapter exposes). Left unset — never guessed — when a provider
4817
- * doesn't report it.
4889
+ * `textPlaybackStart`/`Stop`/`Cancel`, Grok's first response audio delta and
4890
+ * `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. GPT-Live and Gemini
4891
+ * report none, so `agent.ts` stamps them from the first and last outbound speech frame it
4892
+ * forwards to Sinch (wall clock at the relay).
4818
4893
  */
4819
4894
  playbackStartAt?: string;
4820
4895
  playbackEndAt?: string;
@@ -4903,6 +4978,14 @@ export interface RealtimeSessionContext {
4903
4978
  * leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
4904
4979
  */
4905
4980
  hangup(): void;
4981
+ /**
4982
+ * Set by the relay once the call's stereo WAV (caller left, agent right) is in `storage`,
4983
+ * just before `onEnd` runs; absent unless `record` is on, and when saving failed. Read it from
4984
+ * `onEnd` to store the key next to the transcript.
4985
+ */
4986
+ recording?: {
4987
+ storageKey: string;
4988
+ };
4906
4989
  /**
4907
4990
  * Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
4908
4991
  * `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
@@ -4931,7 +5014,7 @@ export interface RealtimeTool<Args = unknown> {
4931
5014
  /** Identity helper — checks a tool's shape against `RealtimeTool` at declaration, not just at `tools: [...]`. */
4932
5015
  export declare function tool<Args = unknown>(def: RealtimeTool<Args>): RealtimeTool<Args>;
4933
5016
  /** A vendor whose realtime audio session an adapter drives directly — the {@link getRealtimeAdapter} registry keys. */
4934
- export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
5017
+ export type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
4935
5018
  /**
4936
5019
  * `'voice-relay'` runs no adapter at all: Sinch does speech-to-text and text-to-speech over Voice
4937
5020
  * Relay, and `realtimeAgent` drives the LLM loop in text over that same connection — see
@@ -4969,7 +5052,7 @@ export interface RealtimeAgentOptions {
4969
5052
  * auto-detect. Added after a live Gemini call had the caller's speech misheard as Spanish
4970
5053
  * ("¿Cómo te") and answered in Spanish for a turn. A value, or `(call, context) => value`,
4971
5054
  * 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
5055
+ * has a field for it (`gemini`, `deepgram`, `grok`, `voice-relay`; `elevenlabs` only when it differs from the default); `openai` (GPT-Live) has no
4973
5056
  * documented equivalent field and is left alone.
4974
5057
  */
4975
5058
  language?: PerCallValue<string>;
@@ -5047,6 +5130,29 @@ export interface RealtimeAgentOptions {
5047
5130
  * the Deepgram adapter.
5048
5131
  */
5049
5132
  providerOptions?: Record<string, unknown>;
5133
+ /**
5134
+ * Record the call. Two independent recordings, both into `ctx.storage` under `recordings/`:
5135
+ *
5136
+ * - `stream` (what `true` means): the caller (left) and agent (right) audio this relay sees,
5137
+ * on one timeline, written as `recordings/<callId>.wav` when the session ends
5138
+ * (`ctx.recording` carries the key). Held in memory until then, capped at `MAX_CALL_DURATION`
5139
+ * seconds of audio. Works for every STREAM provider.
5140
+ * - `sinch`: Sinch records the call itself and uploads `recordings/<callId>.mp3` to function
5141
+ * storage through a presigned URL the runtime mints; nothing is held here. Needs the Voice
5142
+ * platform to accept `https` recording destinations, and storage that can presign one.
5143
+ * `ctx.recording` does not report it; the key is fixed, so `storage.exists()` after the call.
5144
+ */
5145
+ record?: boolean | {
5146
+ stream?: boolean;
5147
+ sinch?: boolean;
5148
+ };
5149
+ /**
5150
+ * Outbound calls placed with `agent.call()` only. The callee is listened to first: when the
5151
+ * provider can speak on request (GPT-Live), `greeting` is held back and sent on the callee's
5152
+ * first speech, or after this many milliseconds of silence, whichever comes first. Defaults to
5153
+ * 4000. Other providers speak the greeting as soon as the session opens, as before.
5154
+ */
5155
+ outboundGreetingFallbackMs?: number;
5050
5156
  /** Override the derived stream URL — same escape hatch `resolveAgentStreamUrl` gives. */
5051
5157
  streamUrl?: string;
5052
5158
  }
@@ -5068,6 +5174,10 @@ export type ResolvedRealtimeAgentOptions = Omit<RealtimeAgentOptions, "prompt" |
5068
5174
  * `agent.ts`'s `resolvePerCallOptions` — optional here only so an adapter's own unit tests can
5069
5175
  * build one without it; every adapter that reads it falls back to `DEFAULT_LANGUAGE` itself. */
5070
5176
  language?: string;
5177
+ /** Set by `agent.ts` when it withholds `greeting` for the listen-first opening and will call
5178
+ * the adapter's `speak` later: an adapter whose vendor plays its own saved first message must
5179
+ * suppress it. */
5180
+ greetingHeld?: boolean;
5071
5181
  };
5072
5182
  /**
5073
5183
  * Normalised events an adapter reports back to the relay loop as they happen. An adapter never
@@ -5150,6 +5260,12 @@ export interface RealtimeAdapter {
5150
5260
  clear(session: VendorSession): void;
5151
5261
  /** Tear down the vendor session. */
5152
5262
  close(session: VendorSession): void;
5263
+ /**
5264
+ * Optional. Have the agent say `text` now, in a session opened without a greeting. Only an
5265
+ * adapter that implements it gets the listen-first opening on an outbound call; the rest
5266
+ * receive the greeting at `connect` as before.
5267
+ */
5268
+ speak?(session: VendorSession, text: string): void;
5153
5269
  }
5154
5270
  /**
5155
5271
  * A `realtimeAgent()` result, widened with `connect` — the plan-building half of the default
@@ -5181,7 +5297,42 @@ export interface RealtimeAdapter {
5181
5297
  */
5182
5298
  export type RealtimeAgentHandle = VoiceFunction & {
5183
5299
  connect: VoiceCallHandler;
5300
+ /**
5301
+ * Call `to` and put this agent on the call once it is answered. Mirrors `@sinch/agents`'
5302
+ * `agent.call(number, { context, from, ... })`. Resolves with the Calls API response (session
5303
+ * id, no call id). The callee is listened to first - see `outboundGreetingFallbackMs`.
5304
+ *
5305
+ * ```typescript
5306
+ * await agent.call('+15551234567', { from: '+15557654321', data: { name: 'Anna' } });
5307
+ * ```
5308
+ */
5309
+ call: (to: string, options?: RealtimeAgentCallOptions) => Promise<v2.CallResponse>;
5184
5310
  } & v2.DialableAgent;
5311
+ /** Options for {@link RealtimeAgentHandle.call}. */
5312
+ export interface RealtimeAgentCallOptions {
5313
+ /** Caller id presented to the callee. Defaults to the service's. */
5314
+ from?: string;
5315
+ /**
5316
+ * Per-call context. Handed, as the third argument, to `prompt`, `greeting`, `voice`,
5317
+ * `transferTo` and `language` when they are functions. Kept in this process until the call
5318
+ * ends, so it must be placed and answered on the same instance.
5319
+ */
5320
+ data?: Record<string, unknown>;
5321
+ /**
5322
+ * Realtime provider for this call, in place of the agent's `provider`. The prompt, tools,
5323
+ * recording and `onEnd` stay the agent's own. An unknown provider throws before dialling.
5324
+ */
5325
+ provider?: RealtimeAudioProvider;
5326
+ /** Seconds to wait for an answer. Maximum 60. */
5327
+ timeout?: number;
5328
+ /** Maximum call duration in seconds. */
5329
+ maxDuration?: number;
5330
+ /**
5331
+ * Request-scoped context to place the call with. Defaults to the one the function started
5332
+ * with, which carries credentials but no `host`.
5333
+ */
5334
+ context?: FunctionContext;
5335
+ }
5185
5336
  /**
5186
5337
  * Build a `RealtimeAgentOptions` into a `RealtimeAgentHandle` (a `VoiceFunction` plus `connect`).
5187
5338
  *
@@ -5880,6 +6031,13 @@ export declare class LocalStorage implements IFunctionStorage {
5880
6031
  private baseDir;
5881
6032
  constructor(baseDir?: string);
5882
6033
  private resolvePath;
6034
+ /**
6035
+ * Sinch Voice uploads the finished recording itself, so dev points it at the runtime's built-in
6036
+ * `PUT /_sinch/recording/:file` receiver (RECORDING_RECEIVER_PATH) over the tunnel, which writes into `recordings/`.
6037
+ */
6038
+ getRecordingDestination(callId: string, format: "mp3" | "wav"): Promise<string>;
6039
+ /** The URL `recordToFunctions()` records to; see {@link IFunctionStorage.recordingUrl}. */
6040
+ recordingUrl(callId: string, format?: string): Promise<string>;
5883
6041
  write(key: string, data: string | Buffer): Promise<void>;
5884
6042
  read(key: string): Promise<Buffer>;
5885
6043
  list(prefix?: string): Promise<string[]>;
@@ -6026,7 +6184,7 @@ export declare class SecretsLoader {
6026
6184
  export declare const secretsLoader: SecretsLoader;
6027
6185
 
6028
6186
  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 };
6187
+ 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
6188
  }
6031
6189
 
6032
6190
  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,
@@ -114,15 +116,18 @@ import {
114
116
  isTextMessage,
115
117
  isVoiceV1Callback,
116
118
  isVoiceWebhook,
119
+ normalizeRecordingFormat,
117
120
  onCall,
118
121
  parseJson,
119
122
  realtimeAgent,
123
+ recordingKey,
120
124
  redactAsText,
121
125
  redactSecrets,
122
126
  renderLoginPage,
123
127
  resetSinchClients,
124
128
  resetVoiceSignatureWarning,
125
129
  resolveAgentStreamUrl,
130
+ rewriteRecordingSentinels,
126
131
  safeCut,
127
132
  secretLookaheadBytes,
128
133
  secretsLoader,
@@ -138,12 +143,13 @@ import {
138
143
  tool,
139
144
  transformKeys,
140
145
  tryAutoConfigureAsync,
146
+ tunnelPublicUrl,
141
147
  validateBasicAuth,
142
148
  validateVoiceSignature,
143
149
  validateVoiceV1Request,
144
150
  verifyVoiceWebhook,
145
151
  voiceRelay
146
- } from "./chunk-5K5FDUEL.js";
152
+ } from "./chunk-KCLRM3MM.js";
147
153
  export {
148
154
  AGENT_HEADER_TOKEN,
149
155
  AGENT_STREAM_PATH,
@@ -167,8 +173,10 @@ export {
167
173
  MenuTemplates,
168
174
  NOTIFICATION_EVENTS,
169
175
  PieSvamlBuilder,
176
+ RECORDING_RECEIVER_PATH,
170
177
  SESSION_COOKIE_NAME,
171
178
  SecretsLoader,
179
+ TUNNEL_PUBLIC_URL_ENV,
172
180
  TemplateRender,
173
181
  TunnelClient,
174
182
  UniversalConfig,
@@ -258,16 +266,19 @@ export {
258
266
  isTextMessage,
259
267
  isVoiceV1Callback,
260
268
  isVoiceWebhook,
269
+ normalizeRecordingFormat,
261
270
  onCall,
262
271
  parseJson,
263
272
  parseJson as parseJsonLenient,
264
273
  realtimeAgent,
274
+ recordingKey,
265
275
  redactAsText,
266
276
  redactSecrets,
267
277
  renderLoginPage,
268
278
  resetSinchClients,
269
279
  resetVoiceSignatureWarning,
270
280
  resolveAgentStreamUrl,
281
+ rewriteRecordingSentinels,
271
282
  safeCut,
272
283
  secretLookaheadBytes,
273
284
  secretsLoader,
@@ -285,6 +296,7 @@ export {
285
296
  transformKeys,
286
297
  transformKeys as transformKeysToCamelCase,
287
298
  tryAutoConfigureAsync,
299
+ tunnelPublicUrl,
288
300
  validateBasicAuth,
289
301
  validateVoiceSignature,
290
302
  validateVoiceV1Request,