1 | |
2 | type Ultravox = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Tools create |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Ultravox, |
11 | body: { |
12 | toolId: string; |
13 | name: string; |
14 | created: string; |
15 | definition: { |
16 | modelToolName?: string; |
17 | description?: string; |
18 | dynamicParameters?: { |
19 | name?: string; |
20 | location?: |
21 | | "PARAMETER_LOCATION_UNSPECIFIED" |
22 | | "PARAMETER_LOCATION_QUERY" |
23 | | "PARAMETER_LOCATION_PATH" |
24 | | "PARAMETER_LOCATION_HEADER" |
25 | | "PARAMETER_LOCATION_BODY"; |
26 | schema?: {}; |
27 | required?: false | true; |
28 | }[]; |
29 | staticParameters?: { |
30 | name?: string; |
31 | location?: |
32 | | "PARAMETER_LOCATION_UNSPECIFIED" |
33 | | "PARAMETER_LOCATION_QUERY" |
34 | | "PARAMETER_LOCATION_PATH" |
35 | | "PARAMETER_LOCATION_HEADER" |
36 | | "PARAMETER_LOCATION_BODY"; |
37 | value?: {}; |
38 | }[]; |
39 | automaticParameters?: { |
40 | name?: string; |
41 | location?: |
42 | | "PARAMETER_LOCATION_UNSPECIFIED" |
43 | | "PARAMETER_LOCATION_QUERY" |
44 | | "PARAMETER_LOCATION_PATH" |
45 | | "PARAMETER_LOCATION_HEADER" |
46 | | "PARAMETER_LOCATION_BODY"; |
47 | knownValue?: |
48 | | "KNOWN_PARAM_UNSPECIFIED" |
49 | | "KNOWN_PARAM_CALL_ID" |
50 | | "KNOWN_PARAM_CONVERSATION_HISTORY" |
51 | | "KNOWN_PARAM_OUTPUT_SAMPLE_RATE"; |
52 | }[]; |
53 | requirements?: { |
54 | httpSecurityOptions?: { options?: { requirements?: {} }[] }; |
55 | requiredParameterOverrides?: string[]; |
56 | }; |
57 | timeout?: string; |
58 | precomputable?: false | true; |
59 | http?: { baseUrlPattern?: string; httpMethod?: string }; |
60 | client?: {}; |
61 | }; |
62 | }, |
63 | ) { |
64 | const url = new URL(`https://api.ultravox.ai/api/tools`); |
65 |
|
66 | const formData = new FormData(); |
67 | for (const [k, v] of Object.entries(body)) { |
68 | if (v !== undefined && v !== "") { |
69 | formData.append(k, String(v)); |
70 | } |
71 | } |
72 | const response = await fetch(url, { |
73 | method: "POST", |
74 | headers: { |
75 | "Content-Type": "application/json", |
76 | "X-API-Key": auth.apiKey, |
77 | }, |
78 | body: JSON.stringify(body), |
79 | }); |
80 | if (!response.ok) { |
81 | const text = await response.text(); |
82 | throw new Error(`${response.status} ${text}`); |
83 | } |
84 | return await response.json(); |
85 | } |
86 |
|