@kognitivedev/backend-cloud 0.2.29

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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +2 -0
  2. package/.turbo/turbo-test.log +14 -0
  3. package/CHANGELOG.md +11 -0
  4. package/README.md +88 -0
  5. package/dist/cloud-voice-parameters.d.ts +11 -0
  6. package/dist/cloud-voice-parameters.js +219 -0
  7. package/dist/cloud-voice-prompt-service.d.ts +24 -0
  8. package/dist/cloud-voice-prompt-service.js +382 -0
  9. package/dist/cloud-voice-runtime-service.d.ts +73 -0
  10. package/dist/cloud-voice-runtime-service.js +443 -0
  11. package/dist/cloud-voice.d.ts +36 -0
  12. package/dist/cloud-voice.js +683 -0
  13. package/dist/index.d.ts +10 -0
  14. package/dist/index.js +26 -0
  15. package/dist/phone-control.d.ts +50 -0
  16. package/dist/phone-control.js +97 -0
  17. package/dist/phone-runtime/audio-playout-tracker.d.ts +51 -0
  18. package/dist/phone-runtime/audio-playout-tracker.js +93 -0
  19. package/dist/phone-runtime/openai-twilio-realtime.d.ts +95 -0
  20. package/dist/phone-runtime/openai-twilio-realtime.js +1074 -0
  21. package/dist/tools.d.ts +2 -0
  22. package/dist/tools.js +216 -0
  23. package/dist/types.d.ts +468 -0
  24. package/dist/types.js +2 -0
  25. package/dist/utils.d.ts +3 -0
  26. package/dist/utils.js +14 -0
  27. package/package.json +47 -0
  28. package/src/__tests__/audio-playout-tracker.test.ts +46 -0
  29. package/src/__tests__/cloud-voice.test.ts +1006 -0
  30. package/src/__tests__/openai-twilio-realtime.test.ts +1193 -0
  31. package/src/__tests__/phone-control.test.ts +105 -0
  32. package/src/cloud-voice-parameters.ts +236 -0
  33. package/src/cloud-voice-prompt-service.ts +493 -0
  34. package/src/cloud-voice-runtime-service.ts +465 -0
  35. package/src/cloud-voice.ts +831 -0
  36. package/src/index.ts +10 -0
  37. package/src/phone-control.ts +156 -0
  38. package/src/phone-runtime/audio-playout-tracker.ts +132 -0
  39. package/src/phone-runtime/openai-twilio-realtime.ts +1250 -0
  40. package/src/tools.ts +227 -0
  41. package/src/types.ts +529 -0
  42. package/src/utils.ts +11 -0
  43. package/tsconfig.json +13 -0
@@ -0,0 +1,2 @@
1
+ import type { ExecuteCloudVoiceToolBindingInput, ExecuteCloudVoiceToolBindingResult } from "./types";
2
+ export declare function executeCloudVoiceToolBinding(input: ExecuteCloudVoiceToolBindingInput): Promise<ExecuteCloudVoiceToolBindingResult>;
package/dist/tools.js ADDED
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeCloudVoiceToolBinding = executeCloudVoiceToolBinding;
4
+ const cloud_voice_parameters_1 = require("./cloud-voice-parameters");
5
+ const utils_1 = require("./utils");
6
+ function requiredHandler(handler, toolType) {
7
+ if (!handler)
8
+ throw new Error(`Cloud Voice tool type "${toolType}" is not configured`);
9
+ return handler;
10
+ }
11
+ function applyParameterBindings(input) {
12
+ const args = Object.assign({}, (0, utils_1.getRecord)(input.args));
13
+ const bindings = (0, utils_1.getRecord)(input.tool.parameterBindings);
14
+ const parameters = (0, utils_1.getRecord)(input.parameters);
15
+ for (const [field, rawBinding] of Object.entries(bindings)) {
16
+ const binding = (0, utils_1.getRecord)(rawBinding);
17
+ const parameterKey = (0, utils_1.getString)(binding.parameter, "");
18
+ if (!field || !parameterKey || !Object.prototype.hasOwnProperty.call(parameters, parameterKey))
19
+ continue;
20
+ if (Object.prototype.hasOwnProperty.call(args, field) && args[field] !== undefined && args[field] !== null && args[field] !== "")
21
+ continue;
22
+ args[field] = parameters[parameterKey];
23
+ }
24
+ return args;
25
+ }
26
+ function omitReservedToolArgs(args) {
27
+ const next = Object.assign({}, args);
28
+ delete next.to;
29
+ delete next.fromNumberId;
30
+ delete next.timeoutMs;
31
+ delete next.intervalMs;
32
+ return next;
33
+ }
34
+ function readMappedValue(value, context) {
35
+ var _a, _b;
36
+ if (typeof value === "string")
37
+ return (0, cloud_voice_parameters_1.renderCloudVoiceParameterTemplate)(value, context);
38
+ const record = (0, utils_1.getRecord)(value);
39
+ const mode = (0, utils_1.getString)(record.mode, "");
40
+ if (mode === "literal")
41
+ return record.value;
42
+ if (mode === "tool_input")
43
+ return context[(0, utils_1.getString)((_a = record.value) !== null && _a !== void 0 ? _a : record.key, "")];
44
+ if (mode === "parent_parameter")
45
+ return context[(0, utils_1.getString)((_b = record.value) !== null && _b !== void 0 ? _b : record.parameter, "")];
46
+ if (Object.keys(record).length > 0 && "value" in record)
47
+ return record.value;
48
+ return undefined;
49
+ }
50
+ function resolveCloudVoiceAgentParameters(input, args) {
51
+ var _a;
52
+ const config = (0, utils_1.getRecord)(input.tool.config);
53
+ const context = Object.assign(Object.assign({}, ((_a = input.parameters) !== null && _a !== void 0 ? _a : {})), args);
54
+ const parameters = omitReservedToolArgs(args);
55
+ const mappings = (0, utils_1.getRecord)(config.parameterMappings);
56
+ for (const [key, mapping] of Object.entries(mappings)) {
57
+ const mapped = readMappedValue(mapping, context);
58
+ if (mapped !== undefined && mapped !== null && mapped !== "") {
59
+ parameters[key] = mapped;
60
+ }
61
+ }
62
+ return parameters;
63
+ }
64
+ function resolveTransferDestination(value) {
65
+ const record = (0, utils_1.getRecord)(value);
66
+ if (record.type === "phone_number" && typeof record.phoneNumber === "string" && record.phoneNumber.trim()) {
67
+ return {
68
+ type: "phone_number",
69
+ phoneNumber: record.phoneNumber.trim(),
70
+ connectionId: (0, utils_1.getString)(record.connectionId, "") || undefined,
71
+ callerId: (0, utils_1.getString)(record.callerId, "") || undefined,
72
+ metadata: (0, utils_1.getRecord)(record.metadata),
73
+ };
74
+ }
75
+ if (record.type === "sip_uri" && typeof record.uri === "string" && record.uri.trim()) {
76
+ return {
77
+ type: "sip_uri",
78
+ uri: record.uri.trim(),
79
+ connectionId: (0, utils_1.getString)(record.connectionId, "") || undefined,
80
+ transport: record.transport === "udp" || record.transport === "tcp" || record.transport === "tls" ? record.transport : undefined,
81
+ metadata: (0, utils_1.getRecord)(record.metadata),
82
+ };
83
+ }
84
+ if (record.type === "extension" && typeof record.extension === "string" && record.extension.trim()) {
85
+ const connectionId = (0, utils_1.getString)(record.connectionId, "");
86
+ if (!connectionId)
87
+ throw new Error("SIP extension transfer destination is missing connectionId");
88
+ return {
89
+ type: "extension",
90
+ extension: record.extension.trim(),
91
+ connectionId,
92
+ metadata: (0, utils_1.getRecord)(record.metadata),
93
+ };
94
+ }
95
+ if (record.type === "queue" && typeof record.queueId === "string" && record.queueId.trim()) {
96
+ return {
97
+ type: "queue",
98
+ queueId: record.queueId.trim(),
99
+ metadata: (0, utils_1.getRecord)(record.metadata),
100
+ };
101
+ }
102
+ throw new Error("SIP transfer destination is invalid");
103
+ }
104
+ async function executeCloudVoiceToolBinding(input) {
105
+ var _a, _b, _c, _d;
106
+ const { tool } = input;
107
+ const args = applyParameterBindings(input);
108
+ if (tool.type === "web_search") {
109
+ const query = (0, utils_1.getString)(args.query, (0, utils_1.getString)(tool.config.query, ""));
110
+ const result = await requiredHandler(input.executeWebSearch, tool.type)({
111
+ query,
112
+ parameters: (0, utils_1.getRecord)(tool.config.parameters),
113
+ });
114
+ return { result, metadata: {} };
115
+ }
116
+ if (tool.type === "cloud_flow") {
117
+ const flowSlug = (0, utils_1.getString)(tool.config.flowSlug, "");
118
+ const result = await requiredHandler(input.executeCloudFlow, tool.type)({
119
+ flowSlug,
120
+ args,
121
+ resourceId: input.resourceId,
122
+ });
123
+ return { result, metadata: {} };
124
+ }
125
+ if (tool.type === "knowledge_base") {
126
+ const result = await requiredHandler(input.executeKnowledgeBase, tool.type)({
127
+ pipelineId: (0, utils_1.getString)(tool.config.pipelineId, ""),
128
+ query: (0, utils_1.getString)(args.query, ""),
129
+ topK: (0, utils_1.getNumber)(tool.config.topK, 5),
130
+ });
131
+ return { result, metadata: {} };
132
+ }
133
+ if (tool.type === "platform_action") {
134
+ const result = await requiredHandler(input.executePlatformAction, tool.type)({
135
+ actionSlug: (0, utils_1.getString)(tool.config.actionSlug, ""),
136
+ connectionId: (0, utils_1.getString)(tool.config.connectionId, ""),
137
+ args,
138
+ });
139
+ return { result, metadata: {} };
140
+ }
141
+ if (tool.type === "calendar_action") {
142
+ const result = await requiredHandler(input.executeCalendarAction, tool.type)({
143
+ action: (0, utils_1.getString)(tool.config.action, (0, utils_1.getString)(tool.config.actionSlug, tool.id)),
144
+ args,
145
+ config: (0, utils_1.getRecord)(tool.config),
146
+ });
147
+ return { result, metadata: {} };
148
+ }
149
+ if (tool.type === "appointment_action") {
150
+ const result = await requiredHandler(input.executeAppointmentAction, tool.type)({
151
+ action: (0, utils_1.getString)(tool.config.action, (0, utils_1.getString)(tool.config.actionSlug, tool.id)),
152
+ args,
153
+ config: (0, utils_1.getRecord)(tool.config),
154
+ });
155
+ return { result, metadata: {} };
156
+ }
157
+ if (tool.type === "cloud_voice_agent") {
158
+ const config = (0, utils_1.getRecord)(tool.config);
159
+ const context = Object.assign(Object.assign({}, ((_a = input.parameters) !== null && _a !== void 0 ? _a : {})), args);
160
+ const toTemplate = (0, utils_1.getString)(config.toTemplate, (0, utils_1.getString)(config.to, ""));
161
+ const to = (0, utils_1.getString)(args.to, toTemplate ? (0, cloud_voice_parameters_1.renderCloudVoiceParameterTemplate)(toTemplate, context) : "");
162
+ const fromNumberId = (0, utils_1.getString)(args.fromNumberId, (0, utils_1.getString)(config.fromNumberId, ""));
163
+ const timeoutMs = (0, utils_1.getNumber)(args.timeoutMs, (0, utils_1.getNumber)(config.timeoutMs, 600000));
164
+ const intervalMs = (0, utils_1.getNumber)(args.intervalMs, (0, utils_1.getNumber)(config.intervalMs, 2000));
165
+ const result = await requiredHandler(input.executeCloudVoiceAgent, tool.type)({
166
+ agentSlug: (0, utils_1.getString)(config.agentSlug, ""),
167
+ fromNumberId,
168
+ to,
169
+ parameters: resolveCloudVoiceAgentParameters(input, args),
170
+ timeoutMs,
171
+ intervalMs,
172
+ metadata: (0, utils_1.getRecord)(config.metadata),
173
+ tool,
174
+ args,
175
+ });
176
+ return { result, metadata: {} };
177
+ }
178
+ if (tool.type === "external_webhook") {
179
+ const result = await requiredHandler(input.executeExternalWebhook, tool.type)({
180
+ tool,
181
+ args,
182
+ });
183
+ return { result, metadata: {} };
184
+ }
185
+ if (tool.type === "sip_transfer") {
186
+ const config = (0, utils_1.getRecord)(tool.config);
187
+ const providerCallId = (0, utils_1.getString)(args.providerCallId, (0, utils_1.getString)(config.providerCallId, ""));
188
+ if (!providerCallId)
189
+ throw new Error(`SIP transfer tool "${tool.id}" is missing providerCallId`);
190
+ const mode = args.mode === "attended" || args.mode === "warm" || args.mode === "blind"
191
+ ? args.mode
192
+ : config.mode === "attended" || config.mode === "warm" || config.mode === "blind"
193
+ ? config.mode
194
+ : undefined;
195
+ const result = await requiredHandler(input.executeSipTransfer, tool.type)({
196
+ providerCallId,
197
+ destination: resolveTransferDestination((_b = args.destination) !== null && _b !== void 0 ? _b : config.destination),
198
+ mode,
199
+ reason: (0, utils_1.getString)(args.reason, (0, utils_1.getString)(config.reason, "agent_requested_transfer")),
200
+ policy: (0, utils_1.getRecord)((_c = args.policy) !== null && _c !== void 0 ? _c : config.policy),
201
+ metadata: Object.assign({ projectId: input.projectId, sessionId: input.sessionId, toolId: tool.id }, ((_d = input.resourceId) !== null && _d !== void 0 ? _d : {})),
202
+ });
203
+ return {
204
+ result,
205
+ metadata: {
206
+ transfer: {
207
+ providerCallId: result.providerCallId,
208
+ transferId: result.transferId,
209
+ mode: result.mode,
210
+ status: result.status,
211
+ },
212
+ },
213
+ };
214
+ }
215
+ throw new Error(`Unsupported Cloud Voice tool type "${String(tool.type)}"`);
216
+ }
@@ -0,0 +1,468 @@
1
+ import type { TelephonyDestination, TelephonyProvider, TelephonyTransferCallResult, TelephonyTransferMode, TelephonyTransferPolicy } from "@kognitivedev/telephony";
2
+ export type CloudVoiceChannel = "web" | "iframe" | "script" | "phone" | "sip" | "outbound";
3
+ export type CloudVoiceProvider = "openai-realtime" | "gemini-live" | "kognitive-voice" | "xai-realtime";
4
+ export type CloudVoiceTransport = "webrtc" | "websocket";
5
+ export type CloudVoicePipelineTransportProvider = "kognitive-websocket" | "daily";
6
+ export type CloudVoiceToolType = "cloud_flow" | "web_search" | "knowledge_base" | "platform_action" | "calendar_action" | "appointment_action" | "cloud_voice_agent" | "external_webhook" | "sip_transfer" | "code_defined_tool";
7
+ export interface CloudVoiceToolBinding {
8
+ id: string;
9
+ type: CloudVoiceToolType;
10
+ name: string;
11
+ description?: string;
12
+ inputSchema?: Record<string, unknown>;
13
+ outputSchema?: Record<string, unknown>;
14
+ parameterBindings?: Record<string, {
15
+ parameter: string;
16
+ }>;
17
+ ui?: {
18
+ type?: "card" | "status" | "table" | "timeline" | "custom";
19
+ title?: string;
20
+ description?: string;
21
+ renderer?: string;
22
+ config?: Record<string, unknown>;
23
+ };
24
+ config: Record<string, unknown>;
25
+ }
26
+ export type CloudVoiceTelephonyProvider = Exclude<TelephonyProvider, "twilio"> | string;
27
+ export type CloudVoiceTelephonyDestination = TelephonyDestination;
28
+ export type CloudVoiceTransferMode = TelephonyTransferMode;
29
+ export type CloudVoiceTransferPolicy = TelephonyTransferPolicy & {
30
+ fallbackDestinationId?: string;
31
+ };
32
+ export interface CloudVoiceTransferDestination {
33
+ id: string;
34
+ name: string;
35
+ provider?: CloudVoiceTelephonyProvider;
36
+ destination: CloudVoiceTelephonyDestination;
37
+ policy?: CloudVoiceTransferPolicy;
38
+ metadata?: Record<string, unknown>;
39
+ }
40
+ export interface CloudVoiceSipConfig {
41
+ enabled?: boolean;
42
+ defaultConnectionId?: string;
43
+ defaultProvider?: CloudVoiceTelephonyProvider;
44
+ inboundRouting?: {
45
+ mode: "agent" | "flow" | "queue";
46
+ agentId?: string;
47
+ flowId?: string;
48
+ queueId?: string;
49
+ };
50
+ transferPolicy?: CloudVoiceTransferPolicy;
51
+ }
52
+ export type CloudVoiceFlowNodeType = "initial" | "case" | "tool" | "transfer" | "end" | string;
53
+ export interface CloudVoiceFlowNodeOutput {
54
+ id: string;
55
+ label: string;
56
+ description?: string;
57
+ desc?: string;
58
+ condition?: string;
59
+ icon?: string;
60
+ metadata?: Record<string, unknown>;
61
+ }
62
+ export interface CloudVoiceSpeechConfig extends Record<string, unknown> {
63
+ language?: string;
64
+ accent?: string;
65
+ style?: string;
66
+ pace?: string;
67
+ emotion?: string;
68
+ }
69
+ export interface CloudVoiceNodeVoiceSettings extends Record<string, unknown> {
70
+ speed?: number;
71
+ pitch?: number;
72
+ backgroundNoise?: boolean;
73
+ fillerWords?: boolean;
74
+ }
75
+ export interface CloudVoiceNodeModelSettings extends Record<string, unknown> {
76
+ temperature?: number;
77
+ maxOutputTokens?: number;
78
+ sentimentGuardrails?: boolean;
79
+ recordTranscript?: boolean;
80
+ }
81
+ export interface CloudVoiceFlowNode {
82
+ id: string;
83
+ type: CloudVoiceFlowNodeType;
84
+ entryMode?: "incoming" | "outgoing" | "both" | "default" | string;
85
+ title?: string;
86
+ prompt?: string;
87
+ firstMessage?: string;
88
+ language?: string;
89
+ maxDuration?: string | number;
90
+ provider?: CloudVoiceProvider;
91
+ model?: string;
92
+ voice?: string;
93
+ transport?: CloudVoiceTransport;
94
+ providerOptions?: Record<string, unknown>;
95
+ transcription?: Record<string, unknown> | null;
96
+ turnDetection?: Record<string, unknown> | null;
97
+ inputNoiseReduction?: Record<string, unknown> | null;
98
+ humanization?: CloudVoiceHumanizationConfig;
99
+ speech?: CloudVoiceSpeechConfig;
100
+ phoneNumberIds?: string[];
101
+ voiceSettings?: CloudVoiceNodeVoiceSettings;
102
+ modelSettings?: CloudVoiceNodeModelSettings;
103
+ outputs?: CloudVoiceFlowNodeOutput[];
104
+ toolId?: string;
105
+ toolIds?: string[];
106
+ transferTarget?: string;
107
+ transferDestinationId?: string;
108
+ transferMode?: CloudVoiceTransferMode;
109
+ metadata?: Record<string, unknown>;
110
+ }
111
+ export interface CloudVoiceFlowEdge {
112
+ id?: string;
113
+ from: string;
114
+ fromPort?: string | null;
115
+ to: string;
116
+ }
117
+ export interface CloudVoiceFlowGraph {
118
+ version?: 1;
119
+ startNodeId?: string;
120
+ nodes: CloudVoiceFlowNode[];
121
+ edges: CloudVoiceFlowEdge[];
122
+ metadata?: Record<string, unknown>;
123
+ }
124
+ export interface CloudVoiceAgentMetadata extends Record<string, unknown> {
125
+ flowGraph?: CloudVoiceFlowGraph;
126
+ speech?: CloudVoiceSpeechConfig;
127
+ sip?: CloudVoiceSipConfig;
128
+ transferDestinations?: CloudVoiceTransferDestination[];
129
+ }
130
+ export interface CloudVoiceClientToolManifest {
131
+ id: string;
132
+ name?: string;
133
+ description?: string;
134
+ inputSchema?: Record<string, unknown>;
135
+ }
136
+ export interface CloudVoiceHumanizationConfig {
137
+ enabled?: boolean;
138
+ openingMode?: "auto" | "wait";
139
+ openingStyle?: "brief" | "warm" | "professional";
140
+ fillerStyle?: "off" | "light" | "natural";
141
+ backchannelFrequency?: "off" | "low" | "medium";
142
+ disfluency?: "off" | "rare";
143
+ toolLatencyFillerMs?: number;
144
+ conversationProfile?: CloudVoiceConversationProfile;
145
+ }
146
+ export interface CloudVoiceConversationProfile {
147
+ personality: "neutral" | "warm" | "expert" | "concierge";
148
+ tone: "casual" | "professional" | "empathetic" | "polished";
149
+ pacing: "concise" | "measured" | "deliberate" | "energetic";
150
+ unclearAudio: "ask_repeat" | "confirm_best_guess";
151
+ confirmation: "critical_fields" | "all_actions" | "minimal";
152
+ escalation: "when_blocked" | "on_request" | "never";
153
+ numberReadback: boolean;
154
+ }
155
+ export interface CloudVoiceRuntimeCapabilities {
156
+ canUpdateInstructionsLive: boolean;
157
+ supportsSessionResume: boolean;
158
+ supportsToolCalling: boolean;
159
+ supportsOutputAudioTranscripts: boolean;
160
+ supportsServerVadConfig: boolean;
161
+ supportsSemanticVad?: boolean;
162
+ supportsNativeAudioOptions?: boolean;
163
+ supportsAffectiveDialog?: boolean;
164
+ supportsProactiveAudio?: boolean;
165
+ supportsPipelineEotConfig?: boolean;
166
+ supportsCartesiaTtsControls?: boolean;
167
+ }
168
+ export interface CloudVoiceCartesiaTtsOptions extends Record<string, unknown> {
169
+ modelId?: string;
170
+ voice?: string;
171
+ speed?: number | "slow" | "normal" | "fast";
172
+ emotion?: string[];
173
+ pronunciationDictId?: string;
174
+ contextMode?: "continue" | "reset";
175
+ }
176
+ export interface CloudVoicePipelineTransportConfig {
177
+ type: CloudVoiceTransport;
178
+ provider?: CloudVoicePipelineTransportProvider;
179
+ }
180
+ export interface CloudVoicePipelineSTTConfig {
181
+ provider: string;
182
+ model: string;
183
+ language?: string;
184
+ }
185
+ export interface CloudVoicePipelineLLMConfig {
186
+ provider: string;
187
+ model: string;
188
+ }
189
+ export interface CloudVoicePipelineTTSConfig {
190
+ provider: string;
191
+ model: string;
192
+ voice?: string;
193
+ options?: CloudVoiceCartesiaTtsOptions;
194
+ }
195
+ export interface CloudVoicePipelineTurnConfig extends Record<string, unknown> {
196
+ interruptResponse?: boolean;
197
+ createResponse?: boolean;
198
+ prefixPaddingMs?: number;
199
+ silenceDurationMs?: number;
200
+ threshold?: number;
201
+ }
202
+ export interface CloudVoicePipelineConfig {
203
+ transport: CloudVoicePipelineTransportConfig;
204
+ stt: CloudVoicePipelineSTTConfig;
205
+ llm: CloudVoicePipelineLLMConfig;
206
+ tts: CloudVoicePipelineTTSConfig;
207
+ turn?: CloudVoicePipelineTurnConfig;
208
+ backgroundAudio?: {
209
+ preset?: string;
210
+ };
211
+ }
212
+ export type CloudVoiceParameterType = "string" | "number" | "boolean" | "json" | "phone" | "email";
213
+ export type CloudVoiceParameterSource = "system" | "session" | "call" | "custom";
214
+ export type CloudVoiceParameterPreset = "user_id" | "session_id" | "agent_slug" | "channel" | "phone" | "caller_phone" | "from_phone" | "to_phone" | "provider" | "provider_call_id" | "call_direction" | "phone_number_id" | "embed_origin";
215
+ export type CloudVoiceParameterResolutionMode = "strict" | "permissive";
216
+ export type CloudVoiceParameterValueMap = Record<string, unknown>;
217
+ export interface CloudVoiceParameterDefinition {
218
+ key: string;
219
+ label: string;
220
+ type: CloudVoiceParameterType;
221
+ required?: boolean;
222
+ description?: string;
223
+ defaultValue?: unknown;
224
+ enum?: unknown[];
225
+ source?: CloudVoiceParameterSource;
226
+ preset?: CloudVoiceParameterPreset;
227
+ sensitive?: boolean;
228
+ jsonSchema?: Record<string, unknown>;
229
+ }
230
+ export interface CloudVoiceParameterResolutionResult {
231
+ definitions: CloudVoiceParameterDefinition[];
232
+ values: CloudVoiceParameterValueMap;
233
+ missingRequired: string[];
234
+ errors: string[];
235
+ sensitiveKeys: string[];
236
+ }
237
+ export interface CloudVoiceAgentConfig {
238
+ instructions: string;
239
+ provider: CloudVoiceProvider;
240
+ model: string;
241
+ voice: string;
242
+ transport: CloudVoiceTransport;
243
+ pipeline?: CloudVoicePipelineConfig;
244
+ memoryEnabled?: boolean;
245
+ providerOptions?: Record<string, unknown>;
246
+ transcription?: Record<string, unknown> | null;
247
+ turnDetection?: Record<string, unknown> | null;
248
+ inputNoiseReduction?: Record<string, unknown> | null;
249
+ tools: CloudVoiceToolBinding[];
250
+ knowledgeBases: Array<{
251
+ pipelineId: string;
252
+ name?: string;
253
+ topK?: number;
254
+ }>;
255
+ webSearch?: {
256
+ enabled?: boolean;
257
+ maxResults?: number;
258
+ maxPages?: number;
259
+ };
260
+ widget: {
261
+ title: string;
262
+ subtitle?: string;
263
+ layout?: "expanded" | "compact";
264
+ accentColor?: string;
265
+ backgroundColor?: string;
266
+ surfaceColor?: string;
267
+ textColor?: string;
268
+ mutedColor?: string;
269
+ ctaLabel?: string;
270
+ launcher?: "button" | "inline";
271
+ position?: "bottom-right" | "bottom-left";
272
+ };
273
+ channels: {
274
+ web: boolean;
275
+ iframe: boolean;
276
+ script: boolean;
277
+ phone: boolean;
278
+ sip: boolean;
279
+ outbound: boolean;
280
+ };
281
+ humanization?: CloudVoiceHumanizationConfig;
282
+ cloudVoiceConfigVersion?: 2;
283
+ parameters?: CloudVoiceParameterDefinition[];
284
+ metadata?: CloudVoiceAgentMetadata;
285
+ }
286
+ export interface CloudVoiceFunctionToolManifest {
287
+ type: "function";
288
+ name: string;
289
+ description: string;
290
+ parameters: Record<string, unknown>;
291
+ }
292
+ export interface CompiledCloudVoiceFlowInstructions {
293
+ instructions: string;
294
+ compilerVersion: string;
295
+ graphSignature: string;
296
+ startNodeId: string | null;
297
+ entryMode?: "incoming" | "outgoing" | "both";
298
+ nodeCount: number;
299
+ edgeCount: number;
300
+ referencedToolIds: string[];
301
+ missingToolIds: string[];
302
+ toolManifest: CloudVoiceFunctionToolManifest[];
303
+ warnings: string[];
304
+ }
305
+ export interface PreparedCloudVoiceConfig {
306
+ name: string;
307
+ system: string;
308
+ runtime: {
309
+ provider: CloudVoiceProvider;
310
+ mode: "pipeline" | "realtime";
311
+ transport: CloudVoiceTransport;
312
+ model: string;
313
+ voice: string;
314
+ providerOptions?: Record<string, unknown>;
315
+ pipeline?: CloudVoicePipelineConfig;
316
+ capabilities: CloudVoiceRuntimeCapabilities;
317
+ };
318
+ voiceConfig: {
319
+ system: string;
320
+ model: string;
321
+ voice: string;
322
+ speech?: CloudVoiceSpeechConfig;
323
+ languageCode?: string;
324
+ turnDetection?: Record<string, unknown> | null;
325
+ transcription?: Record<string, unknown> | null;
326
+ inputNoiseReduction?: Record<string, unknown> | null;
327
+ maxOutputTokens: number | "inf";
328
+ temperature?: number;
329
+ tts?: {
330
+ provider: "cartesia";
331
+ options: CloudVoiceCartesiaTtsOptions;
332
+ };
333
+ };
334
+ tools: [];
335
+ toolManifest: CloudVoiceFunctionToolManifest[];
336
+ resourceId: Record<string, unknown>;
337
+ parameters: CloudVoiceParameterValueMap;
338
+ metadata: {
339
+ cloudVoice: true;
340
+ sessionId: string;
341
+ cloudVoiceConfigVersion: 2;
342
+ promptCompilerVersion: string;
343
+ clientTools: string[];
344
+ transferDestinations: string[];
345
+ parameterKeys: string[];
346
+ missingRequiredParameters: string[];
347
+ sensitiveParameterKeys: string[];
348
+ flowGraph?: {
349
+ startNodeId: string | null;
350
+ entryMode?: "incoming" | "outgoing" | "both";
351
+ nodeCount: number;
352
+ edgeCount: number;
353
+ referencedToolIds: string[];
354
+ missingToolIds: string[];
355
+ };
356
+ };
357
+ }
358
+ export interface CloudVoiceAgentSnapshot {
359
+ id: string;
360
+ slug: string;
361
+ name: string;
362
+ draftVersion: number;
363
+ publishedVersion: number | null;
364
+ }
365
+ export interface CloudVoicePhonePrepareSnapshot {
366
+ schemaVersion: 1;
367
+ createdAt: string;
368
+ channel: CloudVoiceChannel;
369
+ agent: {
370
+ id: string;
371
+ slug: string;
372
+ name: string;
373
+ version: number;
374
+ };
375
+ runtime: PreparedCloudVoiceConfig["runtime"];
376
+ voiceConfig: PreparedCloudVoiceConfig["voiceConfig"];
377
+ toolManifest: CloudVoiceFunctionToolManifest[];
378
+ config: CloudVoiceAgentConfig;
379
+ parameters: CloudVoiceParameterValueMap;
380
+ }
381
+ export interface ExecuteCloudVoiceToolBindingInput {
382
+ projectId: string;
383
+ sessionId: string;
384
+ tool: CloudVoiceToolBinding;
385
+ args: unknown;
386
+ resourceId?: Record<string, unknown>;
387
+ parameters?: CloudVoiceParameterValueMap;
388
+ executeWebSearch?: (input: {
389
+ query: string;
390
+ parameters: Record<string, unknown>;
391
+ }) => Promise<unknown>;
392
+ executeCloudFlow?: (input: {
393
+ flowSlug: string;
394
+ args: unknown;
395
+ resourceId?: Record<string, unknown>;
396
+ }) => Promise<unknown>;
397
+ executeKnowledgeBase?: (input: {
398
+ pipelineId: string;
399
+ query: string;
400
+ topK: number;
401
+ }) => Promise<unknown>;
402
+ executePlatformAction?: (input: {
403
+ actionSlug: string;
404
+ connectionId: string;
405
+ args: Record<string, unknown>;
406
+ }) => Promise<unknown>;
407
+ executeCalendarAction?: (input: {
408
+ action: string;
409
+ args: Record<string, unknown>;
410
+ config?: Record<string, unknown>;
411
+ }) => Promise<unknown>;
412
+ executeAppointmentAction?: (input: {
413
+ action: string;
414
+ args: Record<string, unknown>;
415
+ config?: Record<string, unknown>;
416
+ }) => Promise<unknown>;
417
+ executeCloudVoiceAgent?: (input: {
418
+ agentSlug: string;
419
+ fromNumberId: string;
420
+ to: string;
421
+ parameters: Record<string, unknown>;
422
+ timeoutMs: number;
423
+ intervalMs: number;
424
+ metadata: Record<string, unknown>;
425
+ tool: CloudVoiceToolBinding;
426
+ args: Record<string, unknown>;
427
+ }) => Promise<unknown>;
428
+ executeExternalWebhook?: (input: {
429
+ tool: CloudVoiceToolBinding;
430
+ args: unknown;
431
+ }) => Promise<unknown>;
432
+ executeSipTransfer?: (input: {
433
+ providerCallId: string;
434
+ destination: CloudVoiceTelephonyDestination;
435
+ mode?: CloudVoiceTransferMode;
436
+ reason?: string;
437
+ policy?: CloudVoiceTransferPolicy;
438
+ metadata?: Record<string, unknown>;
439
+ }) => Promise<TelephonyTransferCallResult>;
440
+ }
441
+ export interface ExecuteCloudVoiceToolBindingResult {
442
+ result: unknown;
443
+ metadata: Record<string, unknown>;
444
+ }
445
+ export interface CloudVoicePhoneControlAdapter {
446
+ provider: string;
447
+ hangUpCall(input: {
448
+ providerCallId: string;
449
+ reason?: string;
450
+ metadata?: Record<string, unknown>;
451
+ }): Promise<{
452
+ provider: string;
453
+ providerCallId: string;
454
+ status: string;
455
+ raw?: unknown;
456
+ }>;
457
+ }
458
+ export interface CloudVoiceSipControlAdapter {
459
+ provider: string;
460
+ transferCall(input: {
461
+ providerCallId: string;
462
+ destination: CloudVoiceTelephonyDestination;
463
+ mode?: CloudVoiceTransferMode;
464
+ reason?: string;
465
+ policy?: CloudVoiceTransferPolicy;
466
+ metadata?: Record<string, unknown>;
467
+ }): Promise<TelephonyTransferCallResult>;
468
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare function getString(value: unknown, fallback?: string): string;
2
+ export declare function getNumber(value: unknown, fallback: number): number;
3
+ export declare function getRecord(value: unknown): Record<string, unknown>;