@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.
@@ -256,6 +256,17 @@ interface IFunctionStorage {
256
256
  list(prefix?: string): Promise<string[]>;
257
257
  exists(key: string): Promise<boolean>;
258
258
  delete(key: string): Promise<void>;
259
+ /**
260
+ * A short-lived `https://` PUT URL that Sinch Voice can upload a call recording to, for the
261
+ * exact key `recordings/<callId>.<format>` in this storage. Backs `recordToFunctions()` and
262
+ * `realtimeAgent({ record: { sinch: true } })`: the host swaps the builder's placeholder
263
+ * destination for this URL before the webhook response leaves. Optional — storage without it
264
+ * makes the host drop the recording command and warn.
265
+ *
266
+ * @param callId - The call the recording belongs to
267
+ * @param format - Lowercase file extension, `mp3` or `wav`
268
+ */
269
+ getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
259
270
  }
260
271
  interface ClientContext {
261
272
  /** Function configuration. Only `projectId` is read. */
@@ -564,7 +575,7 @@ interface RecordingOptions {
564
575
  *
565
576
  * As sensitive as an IAM key — see {@link ../commands.js#RecordingCredentials}.
566
577
  */
567
- credentials: string;
578
+ credentials?: string;
568
579
  /** Speech-to-text settings */
569
580
  transcriptionOptions?: TranscriptionOptions;
570
581
  }
@@ -761,6 +772,11 @@ export interface DialableAgent {
761
772
  * @param context - The context the voice client was created with, when it had one
762
773
  */
763
774
  endpointFor(call: WebhookRequest, context: ClientContext | undefined): To;
775
+ /**
776
+ * Commands `dialAgent` places before the agent leg, built from the same call — a
777
+ * `realtimeAgent` that records the call starts its recording here. Optional.
778
+ */
779
+ commandsBefore?(call: WebhookRequest, context: ClientContext | undefined): Command[];
764
780
  }
765
781
  /** SIP settings for an agent leg; each defaults to what the provider requires. */
766
782
  export interface SipAgentOptions {
@@ -997,15 +1013,25 @@ export interface RecordingCredentials {
997
1013
  /** Storage region, e.g. `eu-central-1` */
998
1014
  region: string;
999
1015
  }
1016
+ /**
1017
+ * `destinationUrl` placeholder that {@link CommandBuilder.recordToFunctions} emits. It is never
1018
+ * valid on the wire: the host swaps it for a short-lived presigned PUT URL into the function's
1019
+ * own storage before the response leaves, and drops the command when it cannot.
1020
+ */
1021
+ export declare const RECORD_TO_FUNCTIONS_SENTINEL = "@functions";
1000
1022
  /** Everything a `startRecording` command can carry */
1001
1023
  export interface StartRecordingOptions {
1002
- /** Destination URL, e.g. `s3://voice-recordings-prod/calls` */
1024
+ /**
1025
+ * Destination URL, e.g. `s3://voice-recordings-prod/calls`, or a presigned `https://` PUT URL
1026
+ * (no credentials then).
1027
+ */
1003
1028
  destinationUrl: string;
1004
1029
  /**
1005
1030
  * Credentials for the destination. Prefer the structured form; the raw colon-delimited
1006
- * string is there for credential formats this library does not model.
1031
+ * string is there for credential formats this library does not model. Required unless
1032
+ * `destinationUrl` is an `https://` URL, which carries its own authorization.
1007
1033
  */
1008
- credentials: RecordingCredentials | string;
1034
+ credentials?: RecordingCredentials | string;
1009
1035
  /**
1010
1036
  * Storage service. Defaults to `AWS`, and is always emitted — the schema lists
1011
1037
  * `destination` as required, whatever its documented default.
@@ -1042,6 +1068,8 @@ export interface StartRecordingOptions {
1042
1068
  */
1043
1069
  onFailure?: Flow;
1044
1070
  }
1071
+ /** Options for {@link CommandBuilder.recordToFunctions} */
1072
+ export type RecordToFunctionsOptions = Pick<StartRecordingOptions, "recordingName" | "format" | "recordingType" | "onFinish" | "onFailure">;
1045
1073
  /** Anything that can stand in for a menu prompt: a builder, a callback, or plain text. */
1046
1074
  export type PromptFlow = string | PromptBuilder | ((prompt: PromptBuilder) => PromptBuilder | void);
1047
1075
  /** Collects the messages a menu plays, and whether a keypress may cut them short. */
@@ -1053,12 +1081,15 @@ export declare class PromptBuilder {
1053
1081
  *
1054
1082
  * @param text - Text to synthesise, or an SSML document when `format` is `SSML`
1055
1083
  * @param options - Voice and format overrides
1084
+ * @throws If `text` is over 600 characters (prompts are never split), or the prompt would hold
1085
+ * more than 10 messages
1056
1086
  */
1057
1087
  say(text: string, options?: SayOptions): this;
1058
1088
  /**
1059
1089
  * Play an audio file.
1060
1090
  *
1061
1091
  * @param url - Publicly reachable URL of the audio file
1092
+ * @throws If the prompt would hold more than 10 messages
1062
1093
  */
1063
1094
  play(url: string): this;
1064
1095
  /**
@@ -1088,12 +1119,14 @@ export declare class MenuItemBuilder {
1088
1119
  * Prompt played when the menu is entered.
1089
1120
  *
1090
1121
  * @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
1122
+ * @throws If any prompt text is over 600 characters, or a callback queues more than 10 messages
1091
1123
  */
1092
1124
  prompt(prompt: PromptFlow): this;
1093
1125
  /**
1094
1126
  * Prompt played on each retry. Falls back to `prompt` when unset.
1095
1127
  *
1096
1128
  * @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
1129
+ * @throws If any prompt text is over 600 characters, or a callback queues more than 10 messages
1097
1130
  */
1098
1131
  repeatPrompt(prompt: PromptFlow): this;
1099
1132
  /**
@@ -1455,7 +1488,7 @@ export interface Options {
1455
1488
  serviceId?: string;
1456
1489
  /** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
1457
1490
  host?: string;
1458
- /** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
1491
+ /** 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. */
1459
1492
  publicUrl?: string;
1460
1493
  /** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
1461
1494
  fetch?: typeof globalThis.fetch;
@@ -1602,6 +1635,15 @@ export declare const REDACTED = "[redacted]";
1602
1635
  * ```
1603
1636
  */
1604
1637
  export declare function redactCredentials<T>(body: T): T;
1638
+ /**
1639
+ * The Voice v2 limits on SAY text and message lists, and the sentence splitter that keeps long
1640
+ * builder speech inside them.
1641
+ *
1642
+ * Spec: `docs/superpowers/specs/2026-10-22-voice-v2-say-600-char-limit.md`. The C# runtime
1643
+ * carries the same rule in `Voice/V2/SayLimit.cs`; the error text must stay identical.
1644
+ */
1645
+ /** Longest SAY message Voice v2 plays. Longer ones drop the call without an error. */
1646
+ export declare const MAX_SAY_CHARS = 600;
1605
1647
  /** `JSON.stringify`, but honouring any {@link tagOrder} tag found on nested objects. */
1606
1648
  declare function stringify(value: unknown): string;
1607
1649
  /** Options for {@link connectAgent}. */
@@ -1924,7 +1966,7 @@ interface VoiceFunction {
1924
1966
  /** Custom API endpoints (any other exported function) */
1925
1967
  [key: string]: unknown;
1926
1968
  }
1927
- type PerCallValue<T> = T | ((call: Call, context: FunctionContext) => T | Promise<T>);
1969
+ type PerCallValue<T> = T | ((call: Call, context: FunctionContext, data?: Record<string, unknown>) => T | Promise<T>);
1928
1970
  type JsonSchema = Record<string, unknown>;
1929
1971
  interface TranscriptEntry {
1930
1972
  /** `'tool'` is a completed tool call, not spoken turn. */
@@ -1959,8 +2001,7 @@ interface TranscriptEntry {
1959
2001
  delegationMs?: number;
1960
2002
  /**
1961
2003
  * `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
1962
- * speech-boundary event directly, that wins — GPT-Live from `session.input_transcript.delta`'s
1963
- * own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
2004
+ * speech-boundary event directly, that wins — Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
1964
2005
  * Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
1965
2006
  * all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
1966
2007
  * `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
@@ -1977,10 +2018,10 @@ interface TranscriptEntry {
1977
2018
  /**
1978
2019
  * `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
1979
2020
  * caller, from whatever playback/response-audio event the provider reports — voice-relay's
1980
- * `textPlaybackStart`/`Stop`/`Cancel`, OpenAI/Grok's first response audio delta and
1981
- * `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. Gemini not wired (no
1982
- * playback signal in what its adapter exposes). Left unset — never guessed — when a provider
1983
- * doesn't report it.
2021
+ * `textPlaybackStart`/`Stop`/`Cancel`, Grok's first response audio delta and
2022
+ * `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. GPT-Live and Gemini
2023
+ * report none, so `agent.ts` stamps them from the first and last outbound speech frame it
2024
+ * forwards to Sinch (wall clock at the relay).
1984
2025
  */
1985
2026
  playbackStartAt?: string;
1986
2027
  playbackEndAt?: string;
@@ -2040,6 +2081,14 @@ interface RealtimeSessionContext {
2040
2081
  * leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
2041
2082
  */
2042
2083
  hangup(): void;
2084
+ /**
2085
+ * Set by the relay once the call's stereo WAV (caller left, agent right) is in `storage`,
2086
+ * just before `onEnd` runs; absent unless `record` is on, and when saving failed. Read it from
2087
+ * `onEnd` to store the key next to the transcript.
2088
+ */
2089
+ recording?: {
2090
+ storageKey: string;
2091
+ };
2043
2092
  /**
2044
2093
  * Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
2045
2094
  * `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
@@ -2050,16 +2099,50 @@ interface RealtimeSessionContext {
2050
2099
  */
2051
2100
  transfer(number: string): Promise<void>;
2052
2101
  }
2053
- type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
2102
+ type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
2054
2103
  type RealtimeAgentProvider = RealtimeAudioProvider | "voice-relay";
2055
2104
  type RealtimeAgentHandle = VoiceFunction & {
2056
2105
  connect: VoiceCallHandler;
2106
+ /**
2107
+ * Call `to` and put this agent on the call once it is answered. Mirrors `@sinch/agents`'
2108
+ * `agent.call(number, { context, from, ... })`. Resolves with the Calls API response (session
2109
+ * id, no call id). The callee is listened to first - see `outboundGreetingFallbackMs`.
2110
+ *
2111
+ * ```typescript
2112
+ * await agent.call('+15551234567', { from: '+15557654321', data: { name: 'Anna' } });
2113
+ * ```
2114
+ */
2115
+ call: (to: string, options?: RealtimeAgentCallOptions) => Promise<v2.CallResponse>;
2057
2116
  } & v2.DialableAgent;
2117
+ interface RealtimeAgentCallOptions {
2118
+ /** Caller id presented to the callee. Defaults to the service's. */
2119
+ from?: string;
2120
+ /**
2121
+ * Per-call context. Handed, as the third argument, to `prompt`, `greeting`, `voice`,
2122
+ * `transferTo` and `language` when they are functions. Kept in this process until the call
2123
+ * ends, so it must be placed and answered on the same instance.
2124
+ */
2125
+ data?: Record<string, unknown>;
2126
+ /**
2127
+ * Realtime provider for this call, in place of the agent's `provider`. The prompt, tools,
2128
+ * recording and `onEnd` stay the agent's own. An unknown provider throws before dialling.
2129
+ */
2130
+ provider?: RealtimeAudioProvider;
2131
+ /** Seconds to wait for an answer. Maximum 60. */
2132
+ timeout?: number;
2133
+ /** Maximum call duration in seconds. */
2134
+ maxDuration?: number;
2135
+ /**
2136
+ * Request-scoped context to place the call with. Defaults to the one the function started
2137
+ * with, which carries credentials but no `host`.
2138
+ */
2139
+ context?: FunctionContext;
2140
+ }
2058
2141
  type PerCallSetting = string | ((call: v2.Call, context: FunctionContext) => string);
2059
2142
  type RelayTransferOptions = Omit<v2.TransferToOptions, "call">;
2060
2143
 
2061
2144
  declare namespace v2 {
2062
- export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE, DEFAULT_VOICE, Destination, DialAgentOptions, DialEvents, DialOptions, DialRelayOptions, DialSipOptions, DialStreamOptions, DialableAgent, EventType, Flow, HandlerKey, HandlerResult, Headers$1 as Headers, IncomingCall, MenuCall, MenuDefinition, MenuInput, MenuItemBuilder, Money, Options, Origin, OriginationType, PatchTarget, PlaceCallOptions, PromptBuilder, PromptFlow, REDACTED, RecordingCredentials, RecordingDestination, RecordingFormat, RecordingType, RelayCallOptions, SampleRate, SayOptions, SipAgentOptions, SipAgentProvider, StartRecordingOptions, StopMessagesFlags, StreamCallOptions, TransferOptions, TransferToOptions, WebhookBody, WebhookCall, WebhookHandler, WebhookOptions, WebhookRequest, bridgeTo, buildTransferCommands, commands, connectAgent, createClient, dial, dialAgent, dialPhone, dialRelay, dialSip, dialStream, endpointNumber, menu, play, redactCredentials, resolveHandlerKey, resolveWebhookName, say, stringify as stringifyOrdered, toCallBody, toCallEvent, toWebhookBody, toWebhookRequest };
2145
+ export { AmdEventOptions, AnsweredCall, BridgeOptions, BridgeToOptions, Call, CallDirection, CallEvent, CallFlow, CallHandlers, CallOptions, CallReason, CallResponse, CallResult, CallType, Client, ClientFlows, Command, CommandBuilder, CompletedCall, ConnectAgentOptions, DEFAULT_BRIDGE_NAME, DEFAULT_HOST, DEFAULT_SAMPLE_RATE, DEFAULT_STT_LANGUAGE, DEFAULT_VOICE, Destination, DialAgentOptions, DialEvents, DialOptions, DialRelayOptions, DialSipOptions, DialStreamOptions, DialableAgent, EventType, Flow, HandlerKey, HandlerResult, Headers$1 as Headers, IncomingCall, 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 };
2063
2146
  }
2064
2147
 
2065
2148
  export {
package/dist/voice/v2.js CHANGED
@@ -10,8 +10,10 @@ import {
10
10
  DEFAULT_SAMPLE_RATE,
11
11
  DEFAULT_STT_LANGUAGE,
12
12
  DEFAULT_VOICE,
13
+ MAX_SAY_CHARS,
13
14
  MenuItemBuilder,
14
15
  PromptBuilder,
16
+ RECORD_TO_FUNCTIONS_SENTINEL,
15
17
  REDACTED,
16
18
  bridgeTo,
17
19
  buildTransferCommands,
@@ -40,7 +42,7 @@ import {
40
42
  toWebhookRequest,
41
43
  tool,
42
44
  voiceRelay
43
- } from "../chunk-DLBCKZ6X.js";
45
+ } from "../chunk-KGCIUPCT.js";
44
46
  export {
45
47
  Client,
46
48
  CommandBuilder,
@@ -49,8 +51,10 @@ export {
49
51
  DEFAULT_SAMPLE_RATE,
50
52
  DEFAULT_STT_LANGUAGE,
51
53
  DEFAULT_VOICE,
54
+ MAX_SAY_CHARS,
52
55
  MenuItemBuilder,
53
56
  PromptBuilder,
57
+ RECORD_TO_FUNCTIONS_SENTINEL,
54
58
  REDACTED,
55
59
  bridgeTo,
56
60
  buildTransferCommands,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinch/functions-runtime",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Node.js SDK and local development runtime for Sinch Functions: voice, messaging and HTTP serverless functions",
5
5
  "type": "module",
6
6
  "exports": {