@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/README.md +31 -10
- package/dist/bin/sinch-runtime.js +24 -1
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/{chunk-5K5FDUEL.js → chunk-KCLRM3MM.js} +1251 -430
- package/dist/chunk-KCLRM3MM.js.map +1 -0
- package/dist/index.d.ts +193 -35
- package/dist/index.js +13 -1
- package/dist/voice/v2.d.ts +103 -14
- package/dist/voice/v2.js +5 -1
- package/package.json +1 -1
- package/dist/chunk-5K5FDUEL.js.map +0 -1
package/dist/voice/v2.d.ts
CHANGED
|
@@ -256,6 +256,28 @@ 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
|
+
/**
|
|
270
|
+
* The presigned PUT URL for `recordings/<callId>.<format>`: the same URL the host swaps in for
|
|
271
|
+
* `recordToFunctions()`. Use it to pass your own `startRecording({ destinationUrl })` (or any
|
|
272
|
+
* recording command) the function's storage as the destination. Optional like
|
|
273
|
+
* `getRecordingDestination`; the built-in dev and production storage both provide it.
|
|
274
|
+
*
|
|
275
|
+
* @param callId - The call the recording belongs to
|
|
276
|
+
* @param format - `mp3` (default) or `wav`, any case
|
|
277
|
+
* @throws On an unsupported format, or when no URL can be produced (dev without a tunnel)
|
|
278
|
+
*/
|
|
279
|
+
recordingUrl?(callId: string, format?: string): Promise<string>;
|
|
280
|
+
getRecordingDestination?(callId: string, format: "mp3" | "wav"): Promise<string>;
|
|
259
281
|
}
|
|
260
282
|
interface ClientContext {
|
|
261
283
|
/** Function configuration. Only `projectId` is read. */
|
|
@@ -564,7 +586,7 @@ interface RecordingOptions {
|
|
|
564
586
|
*
|
|
565
587
|
* As sensitive as an IAM key — see {@link ../commands.js#RecordingCredentials}.
|
|
566
588
|
*/
|
|
567
|
-
credentials
|
|
589
|
+
credentials?: string;
|
|
568
590
|
/** Speech-to-text settings */
|
|
569
591
|
transcriptionOptions?: TranscriptionOptions;
|
|
570
592
|
}
|
|
@@ -761,6 +783,11 @@ export interface DialableAgent {
|
|
|
761
783
|
* @param context - The context the voice client was created with, when it had one
|
|
762
784
|
*/
|
|
763
785
|
endpointFor(call: WebhookRequest, context: ClientContext | undefined): To;
|
|
786
|
+
/**
|
|
787
|
+
* Commands `dialAgent` places before the agent leg, built from the same call — a
|
|
788
|
+
* `realtimeAgent` that records the call starts its recording here. Optional.
|
|
789
|
+
*/
|
|
790
|
+
commandsBefore?(call: WebhookRequest, context: ClientContext | undefined): Command[];
|
|
764
791
|
}
|
|
765
792
|
/** SIP settings for an agent leg; each defaults to what the provider requires. */
|
|
766
793
|
export interface SipAgentOptions {
|
|
@@ -997,15 +1024,25 @@ export interface RecordingCredentials {
|
|
|
997
1024
|
/** Storage region, e.g. `eu-central-1` */
|
|
998
1025
|
region: string;
|
|
999
1026
|
}
|
|
1027
|
+
/**
|
|
1028
|
+
* `destinationUrl` placeholder that {@link CommandBuilder.recordToFunctions} emits. It is never
|
|
1029
|
+
* valid on the wire: the host swaps it for a short-lived presigned PUT URL into the function's
|
|
1030
|
+
* own storage before the response leaves, and drops the command when it cannot.
|
|
1031
|
+
*/
|
|
1032
|
+
export declare const RECORD_TO_FUNCTIONS_SENTINEL = "@functions";
|
|
1000
1033
|
/** Everything a `startRecording` command can carry */
|
|
1001
1034
|
export interface StartRecordingOptions {
|
|
1002
|
-
/**
|
|
1035
|
+
/**
|
|
1036
|
+
* Destination URL, e.g. `s3://voice-recordings-prod/calls`, or a presigned `https://` PUT URL
|
|
1037
|
+
* (no credentials then).
|
|
1038
|
+
*/
|
|
1003
1039
|
destinationUrl: string;
|
|
1004
1040
|
/**
|
|
1005
1041
|
* Credentials for the destination. Prefer the structured form; the raw colon-delimited
|
|
1006
|
-
* string is there for credential formats this library does not model.
|
|
1042
|
+
* string is there for credential formats this library does not model. Required unless
|
|
1043
|
+
* `destinationUrl` is an `https://` URL, which carries its own authorization.
|
|
1007
1044
|
*/
|
|
1008
|
-
credentials
|
|
1045
|
+
credentials?: RecordingCredentials | string;
|
|
1009
1046
|
/**
|
|
1010
1047
|
* Storage service. Defaults to `AWS`, and is always emitted — the schema lists
|
|
1011
1048
|
* `destination` as required, whatever its documented default.
|
|
@@ -1042,6 +1079,8 @@ export interface StartRecordingOptions {
|
|
|
1042
1079
|
*/
|
|
1043
1080
|
onFailure?: Flow;
|
|
1044
1081
|
}
|
|
1082
|
+
/** Options for {@link CommandBuilder.recordToFunctions} */
|
|
1083
|
+
export type RecordToFunctionsOptions = Pick<StartRecordingOptions, "recordingName" | "format" | "recordingType" | "onFinish" | "onFailure">;
|
|
1045
1084
|
/** Anything that can stand in for a menu prompt: a builder, a callback, or plain text. */
|
|
1046
1085
|
export type PromptFlow = string | PromptBuilder | ((prompt: PromptBuilder) => PromptBuilder | void);
|
|
1047
1086
|
/** Collects the messages a menu plays, and whether a keypress may cut them short. */
|
|
@@ -1460,7 +1499,7 @@ export interface Options {
|
|
|
1460
1499
|
serviceId?: string;
|
|
1461
1500
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
1462
1501
|
host?: string;
|
|
1463
|
-
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
|
|
1502
|
+
/** 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. */
|
|
1464
1503
|
publicUrl?: string;
|
|
1465
1504
|
/** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
|
|
1466
1505
|
fetch?: typeof globalThis.fetch;
|
|
@@ -1607,6 +1646,15 @@ export declare const REDACTED = "[redacted]";
|
|
|
1607
1646
|
* ```
|
|
1608
1647
|
*/
|
|
1609
1648
|
export declare function redactCredentials<T>(body: T): T;
|
|
1649
|
+
/**
|
|
1650
|
+
* The Voice v2 limits on SAY text and message lists, and the sentence splitter that keeps long
|
|
1651
|
+
* builder speech inside them.
|
|
1652
|
+
*
|
|
1653
|
+
* Spec: `docs/superpowers/specs/2026-10-22-voice-v2-say-600-char-limit.md`. The C# runtime
|
|
1654
|
+
* carries the same rule in `Voice/V2/SayLimit.cs`; the error text must stay identical.
|
|
1655
|
+
*/
|
|
1656
|
+
/** Longest SAY message Voice v2 plays. Longer ones drop the call without an error. */
|
|
1657
|
+
export declare const MAX_SAY_CHARS = 600;
|
|
1610
1658
|
/** `JSON.stringify`, but honouring any {@link tagOrder} tag found on nested objects. */
|
|
1611
1659
|
declare function stringify(value: unknown): string;
|
|
1612
1660
|
/** Options for {@link connectAgent}. */
|
|
@@ -1929,7 +1977,7 @@ interface VoiceFunction {
|
|
|
1929
1977
|
/** Custom API endpoints (any other exported function) */
|
|
1930
1978
|
[key: string]: unknown;
|
|
1931
1979
|
}
|
|
1932
|
-
type PerCallValue<T> = T | ((call: Call, context: FunctionContext) => T | Promise<T>);
|
|
1980
|
+
type PerCallValue<T> = T | ((call: Call, context: FunctionContext, data?: Record<string, unknown>) => T | Promise<T>);
|
|
1933
1981
|
type JsonSchema = Record<string, unknown>;
|
|
1934
1982
|
interface TranscriptEntry {
|
|
1935
1983
|
/** `'tool'` is a completed tool call, not spoken turn. */
|
|
@@ -1964,8 +2012,7 @@ interface TranscriptEntry {
|
|
|
1964
2012
|
delegationMs?: number;
|
|
1965
2013
|
/**
|
|
1966
2014
|
* `'user'` only: ISO timestamps of the caller's speech. Where a provider reports a
|
|
1967
|
-
* speech-boundary event directly, that wins —
|
|
1968
|
-
* own `start_ms`/`end_ms`, Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
2015
|
+
* speech-boundary event directly, that wins — Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
1969
2016
|
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
1970
2017
|
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
1971
2018
|
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
@@ -1982,10 +2029,10 @@ interface TranscriptEntry {
|
|
|
1982
2029
|
/**
|
|
1983
2030
|
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
1984
2031
|
* caller, from whatever playback/response-audio event the provider reports — voice-relay's
|
|
1985
|
-
* `textPlaybackStart`/`Stop`/`Cancel`,
|
|
1986
|
-
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`.
|
|
1987
|
-
*
|
|
1988
|
-
*
|
|
2032
|
+
* `textPlaybackStart`/`Stop`/`Cancel`, Grok's first response audio delta and
|
|
2033
|
+
* `response.done`, Deepgram's `AgentStartedSpeaking`/`AgentAudioDone`. GPT-Live and Gemini
|
|
2034
|
+
* report none, so `agent.ts` stamps them from the first and last outbound speech frame it
|
|
2035
|
+
* forwards to Sinch (wall clock at the relay).
|
|
1989
2036
|
*/
|
|
1990
2037
|
playbackStartAt?: string;
|
|
1991
2038
|
playbackEndAt?: string;
|
|
@@ -2045,6 +2092,14 @@ interface RealtimeSessionContext {
|
|
|
2045
2092
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
2046
2093
|
*/
|
|
2047
2094
|
hangup(): void;
|
|
2095
|
+
/**
|
|
2096
|
+
* Set by the relay once the call's stereo WAV (caller left, agent right) is in `storage`,
|
|
2097
|
+
* just before `onEnd` runs; absent unless `record` is on, and when saving failed. Read it from
|
|
2098
|
+
* `onEnd` to store the key next to the transcript.
|
|
2099
|
+
*/
|
|
2100
|
+
recording?: {
|
|
2101
|
+
storageKey: string;
|
|
2102
|
+
};
|
|
2048
2103
|
/**
|
|
2049
2104
|
* Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
|
|
2050
2105
|
* `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
|
|
@@ -2055,16 +2110,50 @@ interface RealtimeSessionContext {
|
|
|
2055
2110
|
*/
|
|
2056
2111
|
transfer(number: string): Promise<void>;
|
|
2057
2112
|
}
|
|
2058
|
-
type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
|
|
2113
|
+
type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
|
|
2059
2114
|
type RealtimeAgentProvider = RealtimeAudioProvider | "voice-relay";
|
|
2060
2115
|
type RealtimeAgentHandle = VoiceFunction & {
|
|
2061
2116
|
connect: VoiceCallHandler;
|
|
2117
|
+
/**
|
|
2118
|
+
* Call `to` and put this agent on the call once it is answered. Mirrors `@sinch/agents`'
|
|
2119
|
+
* `agent.call(number, { context, from, ... })`. Resolves with the Calls API response (session
|
|
2120
|
+
* id, no call id). The callee is listened to first - see `outboundGreetingFallbackMs`.
|
|
2121
|
+
*
|
|
2122
|
+
* ```typescript
|
|
2123
|
+
* await agent.call('+15551234567', { from: '+15557654321', data: { name: 'Anna' } });
|
|
2124
|
+
* ```
|
|
2125
|
+
*/
|
|
2126
|
+
call: (to: string, options?: RealtimeAgentCallOptions) => Promise<v2.CallResponse>;
|
|
2062
2127
|
} & v2.DialableAgent;
|
|
2128
|
+
interface RealtimeAgentCallOptions {
|
|
2129
|
+
/** Caller id presented to the callee. Defaults to the service's. */
|
|
2130
|
+
from?: string;
|
|
2131
|
+
/**
|
|
2132
|
+
* Per-call context. Handed, as the third argument, to `prompt`, `greeting`, `voice`,
|
|
2133
|
+
* `transferTo` and `language` when they are functions. Kept in this process until the call
|
|
2134
|
+
* ends, so it must be placed and answered on the same instance.
|
|
2135
|
+
*/
|
|
2136
|
+
data?: Record<string, unknown>;
|
|
2137
|
+
/**
|
|
2138
|
+
* Realtime provider for this call, in place of the agent's `provider`. The prompt, tools,
|
|
2139
|
+
* recording and `onEnd` stay the agent's own. An unknown provider throws before dialling.
|
|
2140
|
+
*/
|
|
2141
|
+
provider?: RealtimeAudioProvider;
|
|
2142
|
+
/** Seconds to wait for an answer. Maximum 60. */
|
|
2143
|
+
timeout?: number;
|
|
2144
|
+
/** Maximum call duration in seconds. */
|
|
2145
|
+
maxDuration?: number;
|
|
2146
|
+
/**
|
|
2147
|
+
* Request-scoped context to place the call with. Defaults to the one the function started
|
|
2148
|
+
* with, which carries credentials but no `host`.
|
|
2149
|
+
*/
|
|
2150
|
+
context?: FunctionContext;
|
|
2151
|
+
}
|
|
2063
2152
|
type PerCallSetting = string | ((call: v2.Call, context: FunctionContext) => string);
|
|
2064
2153
|
type RelayTransferOptions = Omit<v2.TransferToOptions, "call">;
|
|
2065
2154
|
|
|
2066
2155
|
declare namespace v2 {
|
|
2067
|
-
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 };
|
|
2156
|
+
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 };
|
|
2068
2157
|
}
|
|
2069
2158
|
|
|
2070
2159
|
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-
|
|
45
|
+
} from "../chunk-KCLRM3MM.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