@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/voice/v2.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
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
|
|
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. */
|
|
@@ -1460,7 +1488,7 @@ export interface Options {
|
|
|
1460
1488
|
serviceId?: string;
|
|
1461
1489
|
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
1462
1490
|
host?: string;
|
|
1463
|
-
/** 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. */
|
|
1464
1492
|
publicUrl?: string;
|
|
1465
1493
|
/** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
|
|
1466
1494
|
fetch?: typeof globalThis.fetch;
|
|
@@ -1607,6 +1635,15 @@ export declare const REDACTED = "[redacted]";
|
|
|
1607
1635
|
* ```
|
|
1608
1636
|
*/
|
|
1609
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;
|
|
1610
1647
|
/** `JSON.stringify`, but honouring any {@link tagOrder} tag found on nested objects. */
|
|
1611
1648
|
declare function stringify(value: unknown): string;
|
|
1612
1649
|
/** Options for {@link connectAgent}. */
|
|
@@ -1929,7 +1966,7 @@ interface VoiceFunction {
|
|
|
1929
1966
|
/** Custom API endpoints (any other exported function) */
|
|
1930
1967
|
[key: string]: unknown;
|
|
1931
1968
|
}
|
|
1932
|
-
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>);
|
|
1933
1970
|
type JsonSchema = Record<string, unknown>;
|
|
1934
1971
|
interface TranscriptEntry {
|
|
1935
1972
|
/** `'tool'` is a completed tool call, not spoken turn. */
|
|
@@ -1964,8 +2001,7 @@ interface TranscriptEntry {
|
|
|
1964
2001
|
delegationMs?: number;
|
|
1965
2002
|
/**
|
|
1966
2003
|
* `'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`,
|
|
2004
|
+
* speech-boundary event directly, that wins — Grok from `input_audio_buffer.speech_started`/`speech_stopped`,
|
|
1969
2005
|
* Deepgram `speechStartAt` only from `UserStartedSpeaking` (it has no `speechEndAt` event at
|
|
1970
2006
|
* all), Gemini `speechStartAt` only from `interimInputTranscription` (no `speechEndAt` signal —
|
|
1971
2007
|
* `VoiceActivity`, which Google's own docs say replaces the deprecated `speechState`, has no
|
|
@@ -1982,10 +2018,10 @@ interface TranscriptEntry {
|
|
|
1982
2018
|
/**
|
|
1983
2019
|
* `'agent'` only: ISO timestamps bracketing when this reply's audio actually played to the
|
|
1984
2020
|
* 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
|
-
*
|
|
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).
|
|
1989
2025
|
*/
|
|
1990
2026
|
playbackStartAt?: string;
|
|
1991
2027
|
playbackEndAt?: string;
|
|
@@ -2045,6 +2081,14 @@ interface RealtimeSessionContext {
|
|
|
2045
2081
|
* leg (set by `realtimeAgent`'s own call plan) ends the caller's leg in turn.
|
|
2046
2082
|
*/
|
|
2047
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
|
+
};
|
|
2048
2092
|
/**
|
|
2049
2093
|
* Move the caller to a human number. Same move-the-live-leg mechanism as the voice builder's
|
|
2050
2094
|
* `transferTo*`/`voiceRelay`'s `call.transferToPhone`: the caller's leg leaves this call's
|
|
@@ -2055,16 +2099,50 @@ interface RealtimeSessionContext {
|
|
|
2055
2099
|
*/
|
|
2056
2100
|
transfer(number: string): Promise<void>;
|
|
2057
2101
|
}
|
|
2058
|
-
type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok";
|
|
2102
|
+
type RealtimeAudioProvider = "openai" | "gemini" | "deepgram" | "grok" | "elevenlabs";
|
|
2059
2103
|
type RealtimeAgentProvider = RealtimeAudioProvider | "voice-relay";
|
|
2060
2104
|
type RealtimeAgentHandle = VoiceFunction & {
|
|
2061
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>;
|
|
2062
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
|
+
}
|
|
2063
2141
|
type PerCallSetting = string | ((call: v2.Call, context: FunctionContext) => string);
|
|
2064
2142
|
type RelayTransferOptions = Omit<v2.TransferToOptions, "call">;
|
|
2065
2143
|
|
|
2066
2144
|
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 };
|
|
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 };
|
|
2068
2146
|
}
|
|
2069
2147
|
|
|
2070
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-
|
|
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