@mondaydotcomorg/atp-vercel-sdk 0.20.3 → 0.20.5
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/dist/index.cjs +130 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -63
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +140 -69
- package/dist/tools.js.map +1 -1
- package/package.json +3 -3
- package/src/tools.ts +145 -68
package/src/tools.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { VercelAIATPClient } from './client.js';
|
|
3
3
|
import type { CreateATPToolsOptions, ATPToolsResult, StreamingToolsOptions } from './types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ToolNames } from '@mondaydotcomorg/atp-client';
|
|
5
5
|
import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
|
|
6
6
|
import { tool } from 'ai';
|
|
7
|
-
import { createVercelEventHandler
|
|
7
|
+
import { createVercelEventHandler } from './event-adapter.js';
|
|
8
|
+
|
|
9
|
+
const TOOL_SCHEMAS = {
|
|
10
|
+
[ToolNames.EXECUTE_CODE]: z.object({
|
|
11
|
+
code: z.string().describe('The JavaScript/TypeScript code to execute'),
|
|
12
|
+
}),
|
|
13
|
+
[ToolNames.EXPLORE_API]: z.object({
|
|
14
|
+
path: z
|
|
15
|
+
.string()
|
|
16
|
+
.describe('The path to explore (e.g., "/" for root, "/openapi" for OpenAPI group)'),
|
|
17
|
+
}),
|
|
18
|
+
[ToolNames.SEARCH_API]: z.object({
|
|
19
|
+
query: z.string().describe('Search query string to find APIs'),
|
|
20
|
+
}),
|
|
21
|
+
[ToolNames.FETCH_ALL_APIS]: z.object({}),
|
|
22
|
+
} as const;
|
|
8
23
|
|
|
9
24
|
export async function createATPTools(options: CreateATPToolsOptions): Promise<ATPToolsResult> {
|
|
10
25
|
const { defaultExecutionConfig, ...clientOptions } = options;
|
|
@@ -12,71 +27,89 @@ export async function createATPTools(options: CreateATPToolsOptions): Promise<AT
|
|
|
12
27
|
const client = new VercelAIATPClient(clientOptions);
|
|
13
28
|
await client.connect();
|
|
14
29
|
|
|
15
|
-
const
|
|
16
|
-
|
|
30
|
+
const underlyingClient = client.getUnderlyingClient();
|
|
17
31
|
const vercelTools: Record<string, any> = {};
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
33
|
+
vercelTools.atp_execute_code = tool({
|
|
34
|
+
description:
|
|
35
|
+
'Execute TypeScript code in ATP sandbox with access to runtime APIs (atp.llm.*, atp.embedding.*, atp.approval.*)',
|
|
36
|
+
parameters: TOOL_SCHEMAS[ToolNames.EXECUTE_CODE],
|
|
37
|
+
execute: async ({ code }: { code: string }) => {
|
|
38
|
+
try {
|
|
39
|
+
const result = await client.execute(code, defaultExecutionConfig);
|
|
40
|
+
|
|
41
|
+
if (result.status === ExecutionStatus.COMPLETED) {
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
result: result.result,
|
|
45
|
+
stats: result.stats,
|
|
46
|
+
};
|
|
47
|
+
} else if (result.status === ExecutionStatus.FAILED) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
error: result.error,
|
|
51
|
+
stats: result.stats,
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: 'Execution in unexpected state: ' + result.status,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
} catch (error: any) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: error.message || 'Unknown error',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
vercelTools.atp_explore_api = tool({
|
|
69
|
+
description:
|
|
70
|
+
'Explore APIs using filesystem-like navigation. Navigate through directories to discover available functions.',
|
|
71
|
+
parameters: TOOL_SCHEMAS[ToolNames.EXPLORE_API],
|
|
72
|
+
execute: async ({ path }: { path: string }) => {
|
|
73
|
+
try {
|
|
74
|
+
const result = await underlyingClient.exploreAPI(path);
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
result,
|
|
78
|
+
};
|
|
79
|
+
} catch (error: any) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: error.message,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
vercelTools.atp_search_api = tool({
|
|
89
|
+
description:
|
|
90
|
+
'Search for APIs by keyword. Provide search term as string like "add", "math", "user", etc.',
|
|
91
|
+
parameters: TOOL_SCHEMAS[ToolNames.SEARCH_API],
|
|
92
|
+
execute: async ({ query }: { query: string }) => {
|
|
93
|
+
try {
|
|
94
|
+
const results = await underlyingClient.searchAPI(query);
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
results: results.map((r: any) => ({
|
|
98
|
+
apiGroup: r.apiGroup,
|
|
99
|
+
functionName: r.functionName,
|
|
100
|
+
description: r.description,
|
|
101
|
+
signature: r.signature,
|
|
102
|
+
})),
|
|
103
|
+
count: results.length,
|
|
104
|
+
};
|
|
105
|
+
} catch (error: any) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: error.message,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
80
113
|
|
|
81
114
|
vercelTools.atp_get_type_definitions = tool({
|
|
82
115
|
description:
|
|
@@ -146,9 +179,7 @@ export async function createATPStreamingTools(
|
|
|
146
179
|
vercelTools.atp_execute_code = tool({
|
|
147
180
|
description:
|
|
148
181
|
'Execute TypeScript code in ATP sandbox with streaming events for thinking, tool execution, and text output',
|
|
149
|
-
parameters:
|
|
150
|
-
code: z.string().describe('TypeScript code to execute in the ATP sandbox'),
|
|
151
|
-
}),
|
|
182
|
+
parameters: TOOL_SCHEMAS[ToolNames.EXECUTE_CODE],
|
|
152
183
|
execute: async ({ code }: { code: string }) => {
|
|
153
184
|
try {
|
|
154
185
|
const result = await underlyingClient.executeStream(
|
|
@@ -184,6 +215,52 @@ export async function createATPStreamingTools(
|
|
|
184
215
|
},
|
|
185
216
|
});
|
|
186
217
|
|
|
218
|
+
vercelTools.atp_explore_api = tool({
|
|
219
|
+
description:
|
|
220
|
+
'Explore APIs using filesystem-like navigation. Navigate through directories to discover available functions.',
|
|
221
|
+
parameters: TOOL_SCHEMAS[ToolNames.EXPLORE_API],
|
|
222
|
+
execute: async ({ path }: { path: string }) => {
|
|
223
|
+
try {
|
|
224
|
+
const result = await underlyingClient.exploreAPI(path);
|
|
225
|
+
return {
|
|
226
|
+
success: true,
|
|
227
|
+
result,
|
|
228
|
+
};
|
|
229
|
+
} catch (error: any) {
|
|
230
|
+
return {
|
|
231
|
+
success: false,
|
|
232
|
+
error: error.message,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
vercelTools.atp_search_api = tool({
|
|
239
|
+
description:
|
|
240
|
+
'Search for APIs by keyword. Provide search term as string like "add", "math", "user", etc.',
|
|
241
|
+
parameters: TOOL_SCHEMAS[ToolNames.SEARCH_API],
|
|
242
|
+
execute: async ({ query }: { query: string }) => {
|
|
243
|
+
try {
|
|
244
|
+
const results = await underlyingClient.searchAPI(query);
|
|
245
|
+
return {
|
|
246
|
+
success: true,
|
|
247
|
+
results: results.map((r: any) => ({
|
|
248
|
+
apiGroup: r.apiGroup,
|
|
249
|
+
functionName: r.functionName,
|
|
250
|
+
description: r.description,
|
|
251
|
+
signature: r.signature,
|
|
252
|
+
})),
|
|
253
|
+
count: results.length,
|
|
254
|
+
};
|
|
255
|
+
} catch (error: any) {
|
|
256
|
+
return {
|
|
257
|
+
success: false,
|
|
258
|
+
error: error.message,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
187
264
|
vercelTools.atp_get_type_definitions = tool({
|
|
188
265
|
description:
|
|
189
266
|
'Get TypeScript type definitions for ATP runtime APIs to understand available functions',
|