@mondaydotcomorg/atp-vercel-sdk 0.20.3 → 0.20.4

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