@vapi-ai/mcp-server 0.0.10 → 0.1.0
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 +152 -6
- package/dist/knowledge/docs.d.ts +96 -0
- package/dist/knowledge/docs.d.ts.map +1 -0
- package/dist/knowledge/docs.js +16 -0
- package/dist/knowledge/skills.d.ts +28 -0
- package/dist/knowledge/skills.d.ts.map +1 -0
- package/dist/knowledge/skills.js +131 -0
- package/dist/schemas/assistant-openapi.d.ts +31 -0
- package/dist/schemas/assistant-openapi.d.ts.map +1 -0
- package/dist/schemas/assistant-openapi.js +87 -0
- package/dist/schemas/assistant-openapi.json +2341 -0
- package/dist/schemas/index.d.ts +158 -1181
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +95 -172
- package/dist/schemas/simulation-openapi.d.ts +9 -0
- package/dist/schemas/simulation-openapi.d.ts.map +1 -0
- package/dist/schemas/simulation-openapi.js +81 -0
- package/dist/schemas/simulation-openapi.json +27558 -0
- package/dist/schemas/simulation.d.ts +54 -0
- package/dist/schemas/simulation.d.ts.map +1 -0
- package/dist/schemas/simulation.js +76 -0
- package/dist/tools/api-schema.d.ts +4 -0
- package/dist/tools/api-schema.d.ts.map +1 -0
- package/dist/tools/api-schema.js +67 -0
- package/dist/tools/assistant.d.ts.map +1 -1
- package/dist/tools/assistant.js +25 -10
- package/dist/tools/call.d.ts.map +1 -1
- package/dist/tools/call.js +13 -6
- package/dist/tools/docs.d.ts +3 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +27 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +8 -0
- package/dist/tools/input-schema.d.ts +5 -0
- package/dist/tools/input-schema.d.ts.map +1 -0
- package/dist/tools/input-schema.js +59 -0
- package/dist/tools/phone-number.d.ts.map +1 -1
- package/dist/tools/phone-number.js +11 -5
- package/dist/tools/simulation.d.ts +4 -0
- package/dist/tools/simulation.d.ts.map +1 -0
- package/dist/tools/simulation.js +133 -0
- package/dist/tools/skills.d.ts +3 -0
- package/dist/tools/skills.d.ts.map +1 -0
- package/dist/tools/skills.js +31 -0
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/tools/tool.js +23 -9
- package/dist/tools/validation.d.ts +22 -0
- package/dist/tools/validation.d.ts.map +1 -0
- package/dist/tools/validation.js +94 -0
- package/dist/transformers/index.d.ts +3 -3
- package/dist/transformers/index.d.ts.map +1 -1
- package/dist/transformers/index.js +52 -31
- package/package.json +10 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAwD,gBAAgB,EAAsH,MAAM,wBAAwB,CAAC;AAEpO,eAAO,MAAM,gBAAgB,gCAAe,CAAC;AAI7C,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAEX,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAC/E,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAa/E,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;AAE7E,eAAO,MAAM,aAAa;cACF,iBAAiB;;CAExC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;CAG/B,CAAC;AAEF,eAAO,MAAM,kBAAkB;;;;;;CAMrB,CAAC;AAIX,eAAO,MAAM,kBAAkB;;;;iBAI7B,CAAC;AAIH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BrC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;iBAgBhC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;iBAElC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwBrC,CAAC;AAIH,eAAO,MAAM,eAAe;;;;;;;;;;iBA4B1B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;iBAW3B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;iBAE7B,CAAC;AAIH,eAAO,MAAM,yBAAyB;;iBAEpC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;iBAUlC,CAAC;AAIH,eAAO,MAAM,kBAAkB;;iBAE7B,CAAC;AAqEH,eAAO,MAAM,qBAAqB;;;;;;;;;;kBAnEqB,QAAQ;oBAAU,MAAM;wBAAc,MAAM;uBAAa,MAAM;0BAAgB,MAAM;;kBAArF,QAAQ;oBAAU,MAAM;wBAAc,MAAM;uBAAa,MAAM;0BAAgB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;iBAgFxI,CAAC;AAEL,eAAO,MAAM,qBAAqB;;;;;;;;;;kBAlFqB,QAAQ;oBAAU,MAAM;wBAAc,MAAM;uBAAa,MAAM;0BAAgB,MAAM;;kBAArF,QAAQ;oBAAU,MAAM;wBAAc,MAAM;uBAAa,MAAM;0BAAgB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;iBAoF1I,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;iBAQ3B,CAAC;AAIH,eAAO,MAAM,uBAAuB;;;iBAalC,CAAC;AAEH,cAAc,iBAAiB,CAAC"}
|
package/dist/schemas/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { CreateAssistantNameSchema, UpdateAssistantNameSchema, VoiceInputSchema, TranscriberInputSchema, LLMInputSchema, apiField, apiObjectField, requiredToolConfigurations, functionRequiresName } from './assistant-openapi.js';
|
|
3
|
+
export const EmptyInputSchema = z.object({});
|
|
2
4
|
// ===== Model Provider and Models =====
|
|
3
5
|
export const ModelProvider = {
|
|
4
6
|
OpenAI: 'openai',
|
|
@@ -19,58 +21,22 @@ export const GoogleModels = {
|
|
|
19
21
|
Gemini2Flash: 'gemini-2.0-flash',
|
|
20
22
|
Gemini2Pro: 'gemini-2.0-pro',
|
|
21
23
|
};
|
|
22
|
-
const OpenAILLMSchema = z.object({
|
|
23
|
-
provider: z.literal(ModelProvider.OpenAI),
|
|
24
|
-
model: z.enum([OpenAIModels.GPT4o, OpenAIModels.GPT4oMini]),
|
|
25
|
-
});
|
|
26
|
-
const AnthropicLLMSchema = z.object({
|
|
27
|
-
provider: z.literal(ModelProvider.Anthropic),
|
|
28
|
-
model: z.enum([
|
|
29
|
-
AnthropicModels.Claude3Sonnet,
|
|
30
|
-
AnthropicModels.Claude3Haiku,
|
|
31
|
-
]),
|
|
32
|
-
});
|
|
33
|
-
const GoogleLLMSchema = z.object({
|
|
34
|
-
provider: z.literal(ModelProvider.GoogleAI),
|
|
35
|
-
model: z.enum([
|
|
36
|
-
GoogleModels.GeminiPro,
|
|
37
|
-
GoogleModels.GeminiFlash,
|
|
38
|
-
GoogleModels.Gemini2Flash,
|
|
39
|
-
GoogleModels.Gemini2Pro,
|
|
40
|
-
]),
|
|
41
|
-
});
|
|
42
|
-
const GenericLLMSchema = z.object({
|
|
43
|
-
provider: z.string(),
|
|
44
|
-
model: z.string(),
|
|
45
|
-
});
|
|
46
24
|
const LLMSchema = z.union([
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
LLMInputSchema,
|
|
26
|
+
z.string().transform((value, ctx) => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
ctx.addIssue({ code: 'custom', message: 'Invalid JSON. Provide an LLM object or a valid JSON object string.' });
|
|
32
|
+
return z.NEVER;
|
|
33
|
+
}
|
|
34
|
+
}).pipe(LLMInputSchema),
|
|
51
35
|
]);
|
|
52
36
|
export const DEFAULT_LLM = {
|
|
53
37
|
provider: ModelProvider.OpenAI,
|
|
54
38
|
model: OpenAIModels.GPT4o,
|
|
55
39
|
};
|
|
56
|
-
const VoiceProviderSchema = z.enum([
|
|
57
|
-
'vapi',
|
|
58
|
-
'11labs',
|
|
59
|
-
'azure',
|
|
60
|
-
'cartesia',
|
|
61
|
-
'custom-voice',
|
|
62
|
-
'deepgram',
|
|
63
|
-
'11labs',
|
|
64
|
-
'hume',
|
|
65
|
-
'lmnt',
|
|
66
|
-
'neuphonic',
|
|
67
|
-
'openai',
|
|
68
|
-
'playht',
|
|
69
|
-
'rime-ai',
|
|
70
|
-
'smallest-ai',
|
|
71
|
-
'tavus',
|
|
72
|
-
'sesame',
|
|
73
|
-
]);
|
|
74
40
|
export const DEFAULT_VOICE = {
|
|
75
41
|
provider: '11labs',
|
|
76
42
|
voiceId: 'sarah',
|
|
@@ -94,58 +60,31 @@ export const BaseResponseSchema = z.object({
|
|
|
94
60
|
});
|
|
95
61
|
// ===== Assistant Schemas =====
|
|
96
62
|
export const CreateAssistantInputSchema = z.object({
|
|
97
|
-
name:
|
|
98
|
-
instructions:
|
|
99
|
-
.string()
|
|
63
|
+
name: CreateAssistantNameSchema.describe('Name of the assistant'),
|
|
64
|
+
instructions: apiField('instructions', { nullable: false })
|
|
100
65
|
.optional()
|
|
101
66
|
.default('You are a helpful assistant.')
|
|
102
67
|
.describe('Instructions for the assistant'),
|
|
103
|
-
llm:
|
|
104
|
-
.union([
|
|
105
|
-
LLMSchema,
|
|
106
|
-
z.string().transform((str) => {
|
|
107
|
-
try {
|
|
108
|
-
return JSON.parse(str);
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
throw new Error(`Invalid LLM JSON string: ${str}`);
|
|
112
|
-
}
|
|
113
|
-
}),
|
|
114
|
-
])
|
|
68
|
+
llm: LLMSchema
|
|
115
69
|
.default(DEFAULT_LLM)
|
|
116
70
|
.describe('LLM configuration'),
|
|
117
|
-
toolIds:
|
|
118
|
-
.array(z.string())
|
|
71
|
+
toolIds: apiField('toolIds')
|
|
119
72
|
.optional()
|
|
120
73
|
.describe('IDs of tools to use with this assistant'),
|
|
121
|
-
transcriber:
|
|
122
|
-
.object({
|
|
123
|
-
provider: z.string().describe('Provider to use for transcription'),
|
|
124
|
-
model: z.string().describe('Transcription model to use'),
|
|
125
|
-
})
|
|
74
|
+
transcriber: TranscriberInputSchema
|
|
126
75
|
.default(DEFAULT_TRANSCRIBER)
|
|
127
76
|
.describe('Transcription configuration'),
|
|
128
|
-
voice:
|
|
129
|
-
.object({
|
|
130
|
-
provider: VoiceProviderSchema.describe('Provider to use for voice'),
|
|
131
|
-
voiceId: z.string().describe('Voice ID to use'),
|
|
132
|
-
model: z.string().optional().describe('Voice model to use'),
|
|
133
|
-
})
|
|
77
|
+
voice: VoiceInputSchema
|
|
134
78
|
.default(DEFAULT_VOICE)
|
|
135
79
|
.describe('Voice configuration'),
|
|
136
|
-
firstMessage:
|
|
137
|
-
.string()
|
|
80
|
+
firstMessage: apiField('firstMessage')
|
|
138
81
|
.optional()
|
|
139
82
|
.default('Hello, how can I help you today?')
|
|
140
83
|
.describe('First message to say to the user'),
|
|
141
|
-
firstMessageMode:
|
|
142
|
-
.enum([
|
|
143
|
-
'assistant-speaks-first',
|
|
144
|
-
'assistant-waits-for-user',
|
|
145
|
-
'assistant-speaks-first-with-model-generated-message',
|
|
146
|
-
])
|
|
147
|
-
.default('assistant-speaks-first')
|
|
84
|
+
firstMessageMode: apiField('firstMessageMode')
|
|
148
85
|
.optional()
|
|
86
|
+
// Keep the advertised default without applying it to omitted input (Zod 3 behavior).
|
|
87
|
+
.meta({ default: 'assistant-speaks-first' })
|
|
149
88
|
.describe('This determines who speaks first, either assistant or user'),
|
|
150
89
|
});
|
|
151
90
|
export const AssistantOutputSchema = BaseResponseSchema.extend({
|
|
@@ -161,90 +100,58 @@ export const AssistantOutputSchema = BaseResponseSchema.extend({
|
|
|
161
100
|
}),
|
|
162
101
|
transcriber: z.object({
|
|
163
102
|
provider: z.string(),
|
|
164
|
-
model: z.string(),
|
|
103
|
+
model: z.string().optional(),
|
|
165
104
|
}),
|
|
166
105
|
toolIds: z.array(z.string()).optional(),
|
|
167
106
|
});
|
|
168
107
|
export const GetAssistantInputSchema = z.object({
|
|
169
|
-
assistantId:
|
|
108
|
+
assistantId: apiField('assistantId').describe('ID of the assistant to get'),
|
|
170
109
|
});
|
|
171
110
|
export const UpdateAssistantInputSchema = z.object({
|
|
172
|
-
assistantId:
|
|
173
|
-
name:
|
|
174
|
-
instructions:
|
|
175
|
-
.string()
|
|
111
|
+
assistantId: apiField('assistantId').describe('ID of the assistant to update'),
|
|
112
|
+
name: UpdateAssistantNameSchema.optional().describe('New name for the assistant'),
|
|
113
|
+
instructions: apiField('instructions', { nullable: false })
|
|
176
114
|
.optional()
|
|
177
115
|
.describe('New instructions for the assistant'),
|
|
178
|
-
llm:
|
|
179
|
-
.union([
|
|
180
|
-
LLMSchema,
|
|
181
|
-
z.string().transform((str) => {
|
|
182
|
-
try {
|
|
183
|
-
return JSON.parse(str);
|
|
184
|
-
}
|
|
185
|
-
catch (e) {
|
|
186
|
-
throw new Error(`Invalid LLM JSON string: ${str}`);
|
|
187
|
-
}
|
|
188
|
-
}),
|
|
189
|
-
])
|
|
116
|
+
llm: LLMSchema
|
|
190
117
|
.optional()
|
|
191
118
|
.describe('New LLM configuration'),
|
|
192
|
-
toolIds:
|
|
193
|
-
.array(z.string())
|
|
119
|
+
toolIds: apiField('toolIds')
|
|
194
120
|
.optional()
|
|
195
121
|
.describe('New IDs of tools to use with this assistant'),
|
|
196
|
-
transcriber:
|
|
197
|
-
.object({
|
|
198
|
-
provider: z.string().describe('Provider to use for transcription'),
|
|
199
|
-
model: z.string().describe('Transcription model to use'),
|
|
200
|
-
})
|
|
122
|
+
transcriber: TranscriberInputSchema
|
|
201
123
|
.optional()
|
|
202
124
|
.describe('New transcription configuration'),
|
|
203
|
-
voice:
|
|
204
|
-
.object({
|
|
205
|
-
provider: VoiceProviderSchema.describe('Provider to use for voice'),
|
|
206
|
-
voiceId: z.string().describe('Voice ID to use'),
|
|
207
|
-
model: z.string().optional().describe('Voice model to use'),
|
|
208
|
-
})
|
|
125
|
+
voice: VoiceInputSchema
|
|
209
126
|
.optional()
|
|
210
127
|
.describe('New voice configuration'),
|
|
211
|
-
firstMessage:
|
|
212
|
-
.string()
|
|
128
|
+
firstMessage: apiField('firstMessage')
|
|
213
129
|
.optional()
|
|
214
130
|
.describe('First message to say to the user'),
|
|
215
|
-
firstMessageMode:
|
|
216
|
-
.enum([
|
|
217
|
-
'assistant-speaks-first',
|
|
218
|
-
'assistant-waits-for-user',
|
|
219
|
-
'assistant-speaks-first-with-model-generated-message',
|
|
220
|
-
])
|
|
131
|
+
firstMessageMode: apiField('firstMessageMode')
|
|
221
132
|
.optional()
|
|
222
133
|
.describe('This determines who speaks first, either assistant or user'),
|
|
223
134
|
});
|
|
224
135
|
// ===== Call Schemas =====
|
|
225
136
|
export const CallInputSchema = z.object({
|
|
226
|
-
assistantId:
|
|
227
|
-
.string()
|
|
137
|
+
assistantId: apiField('callAssistantId')
|
|
228
138
|
.optional()
|
|
229
139
|
.describe('ID of the assistant to use for the call'),
|
|
230
|
-
phoneNumberId:
|
|
231
|
-
.string()
|
|
140
|
+
phoneNumberId: apiField('callPhoneNumberId')
|
|
232
141
|
.optional()
|
|
233
142
|
.describe('ID of the phone number to use for the call'),
|
|
234
143
|
customer: z
|
|
235
144
|
.object({
|
|
236
|
-
number:
|
|
145
|
+
number: apiField('customerNumber').describe('Customer phone number'),
|
|
237
146
|
})
|
|
238
147
|
.optional()
|
|
239
148
|
.describe('Customer information'),
|
|
240
|
-
scheduledAt:
|
|
241
|
-
.string()
|
|
149
|
+
scheduledAt: apiField('scheduledAt')
|
|
242
150
|
.optional()
|
|
243
151
|
.describe('ISO datetime string for when the call should be scheduled (e.g. "2025-03-25T22:39:27.771Z")'),
|
|
244
152
|
assistantOverrides: z
|
|
245
153
|
.object({
|
|
246
|
-
variableValues:
|
|
247
|
-
.record(z.string(), z.any())
|
|
154
|
+
variableValues: apiField('variableValues')
|
|
248
155
|
.optional()
|
|
249
156
|
.describe('Key-value pairs for dynamic variables to use in the assistant\'s prompts (e.g. {"name": "Joe", "age": "24"})'),
|
|
250
157
|
})
|
|
@@ -264,11 +171,11 @@ export const CallOutputSchema = BaseResponseSchema.extend({
|
|
|
264
171
|
scheduledAt: z.string().optional(),
|
|
265
172
|
});
|
|
266
173
|
export const GetCallInputSchema = z.object({
|
|
267
|
-
callId:
|
|
174
|
+
callId: apiField('callId').describe('ID of the call to get'),
|
|
268
175
|
});
|
|
269
176
|
// ===== Phone Number Schemas =====
|
|
270
177
|
export const GetPhoneNumberInputSchema = z.object({
|
|
271
|
-
phoneNumberId:
|
|
178
|
+
phoneNumberId: apiField('phoneNumberId').describe('ID of the phone number to get'),
|
|
272
179
|
});
|
|
273
180
|
export const PhoneNumberOutputSchema = BaseResponseSchema.extend({
|
|
274
181
|
name: z.string().optional(),
|
|
@@ -283,43 +190,30 @@ export const PhoneNumberOutputSchema = BaseResponseSchema.extend({
|
|
|
283
190
|
});
|
|
284
191
|
// ===== Tool Schemas =====
|
|
285
192
|
export const GetToolInputSchema = z.object({
|
|
286
|
-
toolId:
|
|
287
|
-
});
|
|
288
|
-
const TransferCallDestinationSchema = z.object({
|
|
289
|
-
type: z.literal('number'),
|
|
290
|
-
number: z.string().describe('Phone number to transfer to (e.g., "+16054440129"). It can be any phone number in E.164 format.'),
|
|
291
|
-
extension: z.string().optional().describe('Extension number if applicable'),
|
|
292
|
-
callerId: z.string().optional().describe('Caller ID to use for the transfer'),
|
|
293
|
-
description: z.string().optional().describe('Description of the transfer destination'),
|
|
294
|
-
});
|
|
295
|
-
// Generic custom tool schemas
|
|
296
|
-
const JsonSchemaProperty = z.object({
|
|
297
|
-
type: z.string(),
|
|
298
|
-
description: z.string().optional(),
|
|
299
|
-
enum: z.array(z.string()).optional(),
|
|
300
|
-
items: z.any().optional(),
|
|
301
|
-
properties: z.record(z.any()).optional(),
|
|
302
|
-
required: z.array(z.string()).optional(),
|
|
303
|
-
});
|
|
304
|
-
const JsonSchema = z.object({
|
|
305
|
-
type: z.literal('object'),
|
|
306
|
-
properties: z.record(JsonSchemaProperty),
|
|
307
|
-
required: z.array(z.string()).optional(),
|
|
193
|
+
toolId: apiField('toolId').describe('ID of the tool to get'),
|
|
308
194
|
});
|
|
195
|
+
const TransferCallDestinationSchema = apiField('transferDestination', { additionalProperties: true })
|
|
196
|
+
.describe('Transfer destination. Other TransferDestinationNumber fields, such as transferPlan and message, are sent as given (see get_api_schema).');
|
|
197
|
+
const FunctionParametersSchema = apiObjectField('functionParameters');
|
|
198
|
+
const ApiBodySchema = apiObjectField('apiBody');
|
|
199
|
+
// URLs and string-valued headers are retained MCP transport constraints where
|
|
200
|
+
// the published DTO describes only a string/object. They are not copied API rules.
|
|
201
|
+
const HeaderMapSchema = apiField('serverHeaders').pipe(z.record(z.string(), z.string()))
|
|
202
|
+
.meta({ type: 'object', additionalProperties: { type: 'string' } });
|
|
309
203
|
const ServerSchema = z.object({
|
|
310
|
-
url: z.string().url().describe('Server URL where the function will be called'),
|
|
311
|
-
headers:
|
|
204
|
+
url: apiField('serverUrl').pipe(z.string().url()).meta({ format: 'uri' }).describe('Server URL where the function will be called'),
|
|
205
|
+
headers: HeaderMapSchema.optional().describe('Headers to send with the request'),
|
|
312
206
|
});
|
|
313
207
|
const BackoffPlanSchema = z.object({
|
|
314
|
-
type:
|
|
315
|
-
maxRetries:
|
|
316
|
-
baseDelaySeconds:
|
|
208
|
+
type: apiField('backoffType').default('fixed'),
|
|
209
|
+
maxRetries: apiField('backoffMaxRetries').default(3).describe('Maximum number of retries'),
|
|
210
|
+
baseDelaySeconds: apiField('backoffDelay').default(1).describe('Base delay between retries in seconds'),
|
|
317
211
|
});
|
|
318
212
|
// Base tool configuration schema (reusable for both create and update)
|
|
319
213
|
const BaseToolConfigSchema = z.object({
|
|
320
214
|
// Common fields for all tools
|
|
321
|
-
name:
|
|
322
|
-
description:
|
|
215
|
+
name: apiField('functionName').optional().describe('Name of the function/tool'),
|
|
216
|
+
description: apiField('functionDescription').optional().describe('Description of what the function/tool does'),
|
|
323
217
|
// SMS tool configuration
|
|
324
218
|
sms: z.object({
|
|
325
219
|
metadata: z.object({
|
|
@@ -332,25 +226,42 @@ const BaseToolConfigSchema = z.object({
|
|
|
332
226
|
}).optional().describe('Transfer call tool configuration - to transfer calls to destinations'),
|
|
333
227
|
// Function tool configuration (custom functions with parameters)
|
|
334
228
|
function: z.object({
|
|
335
|
-
parameters:
|
|
229
|
+
parameters: FunctionParametersSchema.describe('JSON schema for function parameters'),
|
|
336
230
|
server: ServerSchema.describe('Server configuration with URL where the function will be called'),
|
|
337
231
|
}).optional().describe('Custom function tool configuration - for custom server-side functions'),
|
|
338
232
|
// API Request tool configuration
|
|
339
233
|
apiRequest: z.object({
|
|
340
|
-
url: z.string().url().describe('URL to make the API request to'),
|
|
341
|
-
method:
|
|
342
|
-
headers:
|
|
343
|
-
body:
|
|
234
|
+
url: apiField('apiUrl').pipe(z.string().url()).meta({ format: 'uri' }).describe('URL to make the API request to'),
|
|
235
|
+
method: apiField('apiMethod').default('POST').describe('HTTP method for the API request'),
|
|
236
|
+
headers: HeaderMapSchema.optional().describe('Headers to send with the request (key-value pairs)'),
|
|
237
|
+
body: ApiBodySchema.optional().describe('Body schema for the API request in JSON Schema format'),
|
|
344
238
|
backoffPlan: BackoffPlanSchema.optional().describe('Retry configuration for failed API requests'),
|
|
345
|
-
timeoutSeconds:
|
|
239
|
+
timeoutSeconds: apiField('apiTimeout').default(20).describe('Request timeout in seconds'),
|
|
346
240
|
}).optional().describe('API Request tool configuration - for HTTP API integration'),
|
|
241
|
+
// Documented fields the options above don't cover
|
|
242
|
+
additionalFields: z
|
|
243
|
+
.record(z.string(), z.any())
|
|
244
|
+
.optional()
|
|
245
|
+
.describe('Other top-level fields from the Vapi API for this tool type, such as messages or rejectionPlan, sent as given. ' +
|
|
246
|
+
'Look them up with get_api_schema, e.g. CreateTransferCallToolDTO. ' +
|
|
247
|
+
'On update_tool, each field given here replaces that whole field.'),
|
|
347
248
|
});
|
|
348
249
|
export const CreateToolInputSchema = BaseToolConfigSchema.extend({
|
|
349
|
-
type:
|
|
250
|
+
type: apiField('toolType')
|
|
350
251
|
.describe('Type of the tool to create'),
|
|
351
|
-
})
|
|
252
|
+
}).superRefine((input, ctx) => {
|
|
253
|
+
if (requiredToolConfigurations.includes(input.type) && !input[input.type]) {
|
|
254
|
+
ctx.addIssue({ code: 'custom', path: [input.type], message: 'This configuration is required for the selected tool type.' });
|
|
255
|
+
}
|
|
256
|
+
if (functionRequiresName && input.type === 'function' && (input.function || input.description) && !input.name) {
|
|
257
|
+
ctx.addIssue({ code: 'custom', path: ['name'], message: 'A function name is required when providing a function definition.' });
|
|
258
|
+
}
|
|
259
|
+
}).meta({ allOf: [
|
|
260
|
+
...requiredToolConfigurations.map(type => ({ if: { properties: { type: { const: type } }, required: ['type'] }, then: { required: [type] } })),
|
|
261
|
+
...(functionRequiresName ? [{ if: { properties: { type: { const: 'function' } }, required: ['type'], anyOf: [{ required: ['function'] }, { required: ['description'], properties: { description: { minLength: 1 } } }] }, then: { required: ['name'] } }] : []),
|
|
262
|
+
] });
|
|
352
263
|
export const UpdateToolInputSchema = BaseToolConfigSchema.extend({
|
|
353
|
-
toolId:
|
|
264
|
+
toolId: apiField('toolId').describe('ID of the tool to update'),
|
|
354
265
|
});
|
|
355
266
|
export const ToolOutputSchema = BaseResponseSchema.extend({
|
|
356
267
|
type: z
|
|
@@ -358,6 +269,18 @@ export const ToolOutputSchema = BaseResponseSchema.extend({
|
|
|
358
269
|
.describe('Type of the tool (dtmf, function, mcp, query, etc.)'),
|
|
359
270
|
name: z.string().describe('Name of the tool'),
|
|
360
271
|
description: z.string().describe('Description of the tool'),
|
|
361
|
-
parameters: z.record(z.any()).describe('Parameters of the tool'),
|
|
272
|
+
parameters: z.record(z.string(), z.any()).describe('Parameters of the tool'),
|
|
362
273
|
server: ServerSchema.describe('Server of the tool'),
|
|
363
274
|
});
|
|
275
|
+
// ===== API Schema Lookup =====
|
|
276
|
+
export const GetApiSchemaInputSchema = z.object({
|
|
277
|
+
name: z
|
|
278
|
+
.string()
|
|
279
|
+
.optional()
|
|
280
|
+
.describe('Exact schema name to return, e.g. "CreateTransferCallToolDTO" or "TransferPlan"'),
|
|
281
|
+
search: z
|
|
282
|
+
.string()
|
|
283
|
+
.optional()
|
|
284
|
+
.describe('Case-insensitive text to find schema names, e.g. "transfer". Used when name is not given.'),
|
|
285
|
+
});
|
|
286
|
+
export * from './simulation.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type JsonSchema = z.core.JSONSchema.JSONSchema;
|
|
3
|
+
export declare function simulationContract(name: string): JsonSchema;
|
|
4
|
+
export declare function simulationValidator(name: string): z.ZodType;
|
|
5
|
+
export declare function simulationParameter<T>(name: string): z.ZodType<T>;
|
|
6
|
+
export declare function simulationField<T>(dto: string, field: string): z.ZodType<T>;
|
|
7
|
+
export declare function validateSimulationBody(dto: string, input: Record<string, unknown>, ctx: z.RefinementCtx): void;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=simulation-openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulation-openapi.d.ts","sourceRoot":"","sources":["../../src/schemas/simulation-openapi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,KAAK,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;AAQ/C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAK3D;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,CAO3D;AAkCD,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAEjE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAS3E;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa,QAQvG"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { inputContract } from './assistant-openapi.js';
|
|
4
|
+
const snapshot = JSON.parse(readFileSync(new URL('./simulation-openapi.json', import.meta.url), 'utf8'));
|
|
5
|
+
export function simulationContract(name) {
|
|
6
|
+
const schema = snapshot.schemas[name] ?? snapshot.parameters[name] ?? snapshot.definitions[name];
|
|
7
|
+
if (!schema)
|
|
8
|
+
throw new Error(`Unknown simulation contract: ${name}`);
|
|
9
|
+
return JSON.parse(JSON.stringify(inputContract({ ...schema, definitions: snapshot.definitions }), (key, value) => key === '$ref' && typeof value === 'string' ? value.replace('#/components/schemas/', '#/definitions/') : value));
|
|
10
|
+
}
|
|
11
|
+
const validators = new Map();
|
|
12
|
+
export function simulationValidator(name) {
|
|
13
|
+
let validator = validators.get(name);
|
|
14
|
+
if (!validator) {
|
|
15
|
+
validator = z.fromJSONSchema(simulationContract(name), { defaultTarget: 'openapi-3.0' });
|
|
16
|
+
validators.set(name, validator);
|
|
17
|
+
}
|
|
18
|
+
return validator;
|
|
19
|
+
}
|
|
20
|
+
// Full assistant/structured-output DTOs expand to hundreds of MB if converted
|
|
21
|
+
// back to inline tool JSON. Advertise compact object envelopes for these fields,
|
|
22
|
+
// while validating their complete published contracts at the same boundary.
|
|
23
|
+
function compact(schema) {
|
|
24
|
+
if (typeof schema === 'boolean')
|
|
25
|
+
return schema;
|
|
26
|
+
if (schema.$ref) {
|
|
27
|
+
const name = schema.$ref.split('/').at(-1);
|
|
28
|
+
return compact(inputContract(snapshot.definitions[name]));
|
|
29
|
+
}
|
|
30
|
+
const result = { ...schema };
|
|
31
|
+
delete result.definitions;
|
|
32
|
+
for (const key of ['allOf', 'oneOf', 'anyOf']) {
|
|
33
|
+
if (result[key])
|
|
34
|
+
result[key] = result[key].map(compact);
|
|
35
|
+
}
|
|
36
|
+
if (result.items && !Array.isArray(result.items))
|
|
37
|
+
result.items = compact(result.items);
|
|
38
|
+
if (result.properties)
|
|
39
|
+
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key,
|
|
40
|
+
['assistant', 'structuredOutput', 'targetOverrides'].includes(key)
|
|
41
|
+
? { type: 'object', additionalProperties: true, description: `Full ${key} configuration, validated against the bundled Vapi OpenAPI schema. See https://api.vapi.ai/api-json.` }
|
|
42
|
+
: compact(value),
|
|
43
|
+
]));
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function advertised(validator, contract) {
|
|
47
|
+
return z.any().superRefine((value, ctx) => {
|
|
48
|
+
const result = validator.safeParse(value);
|
|
49
|
+
if (!result.success)
|
|
50
|
+
for (const issue of result.error.issues)
|
|
51
|
+
ctx.addIssue({ ...issue });
|
|
52
|
+
// Preserve the submitted payload: imported defaults are annotations and
|
|
53
|
+
// unknown documented extension fields must not disappear during parsing.
|
|
54
|
+
}).meta(compact(contract));
|
|
55
|
+
}
|
|
56
|
+
export function simulationParameter(name) {
|
|
57
|
+
return advertised(simulationValidator(name), simulationContract(name));
|
|
58
|
+
}
|
|
59
|
+
export function simulationField(dto, field) {
|
|
60
|
+
const validator = simulationValidator(dto);
|
|
61
|
+
if (!(validator instanceof z.ZodObject))
|
|
62
|
+
throw new Error(`${dto} must be an object schema`);
|
|
63
|
+
const contract = simulationContract(dto).properties?.[field];
|
|
64
|
+
if (!contract || !validator.shape[field])
|
|
65
|
+
throw new Error(`Missing simulation field: ${dto}.${field}`);
|
|
66
|
+
const result = advertised(validator.shape[field], field === 'assistant'
|
|
67
|
+
? { type: 'object', additionalProperties: true, description: 'Full tester assistant configuration, validated against the bundled Vapi OpenAPI schema. See https://api.vapi.ai/api-json (TransientAssistantDTO).' }
|
|
68
|
+
: contract);
|
|
69
|
+
return simulationContract(dto).required?.includes(field) ? result : result.optional();
|
|
70
|
+
}
|
|
71
|
+
export function validateSimulationBody(dto, input, ctx) {
|
|
72
|
+
const { additionalFields, ...fields } = input;
|
|
73
|
+
const extra = additionalFields;
|
|
74
|
+
const result = simulationValidator(dto).safeParse({ ...fields, ...extra });
|
|
75
|
+
if (!result.success)
|
|
76
|
+
for (const issue of result.error.issues)
|
|
77
|
+
ctx.addIssue({
|
|
78
|
+
...issue,
|
|
79
|
+
path: extra && Object.hasOwn(extra, issue.path[0]) ? ['additionalFields', ...issue.path] : issue.path,
|
|
80
|
+
});
|
|
81
|
+
}
|