@mondaydotcomorg/atp-vercel-sdk 0.19.2

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 ADDED
@@ -0,0 +1,416 @@
1
+ # @mondaydotcomorg/atp-vercel-ai-sdk
2
+
3
+ Vercel AI SDK integration for Agent Tool Protocol with production-ready features.
4
+
5
+ ## Overview
6
+
7
+ This package integrates ATP with Vercel AI SDK, enabling agents to generate and execute ATP code as tools. Includes support for human-in-the-loop approvals, LLM sampling, and embeddings.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @mondaydotcomorg/atp-vercel-ai-sdk ai @ai-sdk/openai
13
+ ```
14
+
15
+ ## Architecture
16
+
17
+ ```mermaid
18
+ graph TB
19
+ Agent[Vercel AI SDK Agent] --> Tools[ATP Tools]
20
+ Tools --> Client[VercelAIATPClient]
21
+
22
+ Client --> Server[ATP Server]
23
+ Server --> Runtime[Runtime APIs]
24
+
25
+ Runtime --> LLM[atp.llm.*]
26
+ Runtime --> Embed[atp.embedding.*]
27
+ Runtime --> Approval[atp.approval.*]
28
+
29
+ LLM --> Callback[Client LLM Callback]
30
+ Embed --> EmbedCallback[Client Embedding Callback]
31
+ Approval --> Handler[Approval Handler]
32
+ ```
33
+
34
+ ## Features
35
+
36
+ - 🤖 **Vercel AI SDK Tools** - Use ATP as tools with `generateText` and `streamText`
37
+ - 🔄 **Multi-Step Execution** - Full integration with Vercel AI SDK's `maxSteps` parameter
38
+ - 🧠 **LLM Sampling** - `atp.llm.call()` routes to your Vercel AI SDK model
39
+ - 🔍 **Embedding Support** - `atp.embedding.*` routes to your embeddings model
40
+ - ✅ **Approval Workflows** - Human-in-the-loop via async callbacks
41
+ - 📡 **Streaming Support** - Works with both `generateText` and `streamText`
42
+ - 📝 **TypeScript** - Full type safety
43
+
44
+ ## Quick Start
45
+
46
+ ### Basic Agent with Tools
47
+
48
+ ```typescript
49
+ import { createATPTools } from '@mondaydotcomorg/atp-vercel-ai-sdk';
50
+ import { openai } from '@ai-sdk/openai';
51
+ import { generateText } from 'ai';
52
+
53
+ const model = openai('gpt-4o');
54
+
55
+ const { tools } = await createATPTools({
56
+ serverUrl: 'http://localhost:3333',
57
+ headers: { Authorization: 'Bearer your-api-key' },
58
+ model,
59
+ approvalHandler: async (message, context) => {
60
+ console.log('Approval needed:', message);
61
+ return true;
62
+ },
63
+ });
64
+
65
+ const result = await generateText({
66
+ model,
67
+ system: 'You can execute TypeScript code using ATP tools',
68
+ prompt: 'Use ATP to call an LLM and get a creative product idea',
69
+ tools,
70
+ maxSteps: 5,
71
+ });
72
+ ```
73
+
74
+ ### With Streaming
75
+
76
+ ```typescript
77
+ import { createATPTools } from '@mondaydotcomorg/atp-vercel-ai-sdk';
78
+ import { openai } from '@ai-sdk/openai';
79
+ import { streamText } from 'ai';
80
+
81
+ const model = openai('gpt-4o');
82
+
83
+ const { tools } = await createATPTools({
84
+ serverUrl: 'http://localhost:3333',
85
+ headers: { Authorization: 'Bearer your-api-key' },
86
+ model,
87
+ approvalHandler: async () => true,
88
+ });
89
+
90
+ const result = await streamText({
91
+ model,
92
+ prompt: 'Use ATP to generate code',
93
+ tools,
94
+ maxSteps: 5,
95
+ });
96
+
97
+ for await (const chunk of result.textStream) {
98
+ process.stdout.write(chunk);
99
+ }
100
+ ```
101
+
102
+ ### With Embeddings
103
+
104
+ ```typescript
105
+ import { createATPTools } from '@mondaydotcomorg/atp-vercel-ai-sdk';
106
+ import { openai } from '@ai-sdk/openai';
107
+ import { embed } from 'ai';
108
+
109
+ const model = openai('gpt-4o');
110
+
111
+ const embeddings = {
112
+ embed: async (text: string) => {
113
+ const result = await embed({
114
+ model: openai.embedding('text-embedding-3-small'),
115
+ value: text,
116
+ });
117
+ return result.embedding;
118
+ },
119
+ };
120
+
121
+ const { tools } = await createATPTools({
122
+ serverUrl: 'http://localhost:3333',
123
+ headers: { Authorization: 'Bearer your-api-key' },
124
+ model,
125
+ embeddings,
126
+ });
127
+
128
+ // Agent can now use atp.embedding.embed() in code
129
+ ```
130
+
131
+ ## How It Works
132
+
133
+ ### ATP Runtime in Vercel AI SDK
134
+
135
+ When agents use ATP tools, they can generate TypeScript code using ATP's runtime APIs:
136
+
137
+ ```typescript
138
+ // Agent generates this code:
139
+ const idea = await atp.llm.call({
140
+ prompt: 'Generate a product idea',
141
+ });
142
+
143
+ // Store embedding for semantic search
144
+ const embeddingId = await atp.embedding.embed(idea);
145
+
146
+ // Request approval
147
+ const approval = await atp.approval.request(`Launch product: ${idea}?`, { idea });
148
+
149
+ if (approval.approved) {
150
+ return await atp.llm.call({
151
+ prompt: `Create marketing copy for: ${idea}`,
152
+ });
153
+ }
154
+ ```
155
+
156
+ ### LLM Sampling
157
+
158
+ `atp.llm.call()` routes to your Vercel AI SDK model:
159
+
160
+ - Uses the same model as your agent
161
+ - Fresh context for sub-reasoning
162
+ - Supports `call()`, `extract()`, `classify()`
163
+
164
+ ```typescript
165
+ // In ATP code:
166
+ const analysis = await atp.llm.call({
167
+ prompt: 'Analyze this data: ' + JSON.stringify(data),
168
+ temperature: 0.7,
169
+ });
170
+
171
+ // Structured extraction
172
+ const structured = await atp.llm.extract({
173
+ prompt: 'Extract key information',
174
+ schema: z.object({
175
+ name: z.string(),
176
+ age: z.number(),
177
+ }),
178
+ });
179
+ ```
180
+
181
+ ### Approval Mechanism
182
+
183
+ When ATP code calls `atp.approval.request()`, your async handler is invoked:
184
+
185
+ ```typescript
186
+ const { tools } = await createATPTools({
187
+ serverUrl: 'http://localhost:3333',
188
+ headers: { Authorization: 'Bearer your-api-key' },
189
+ model,
190
+ approvalHandler: async (message, context) => {
191
+ // Option 1: CLI prompt
192
+ return confirm(message);
193
+
194
+ // Option 2: Webhook notification
195
+ await sendSlackNotification(message);
196
+ return await waitForWebhookResponse();
197
+
198
+ // Option 3: Database queue
199
+ await db.approvals.create({ message, context });
200
+ return await pollForApproval();
201
+ },
202
+ });
203
+ ```
204
+
205
+ ## API Reference
206
+
207
+ ### createATPTools()
208
+
209
+ ```typescript
210
+ async function createATPTools(options: CreateATPToolsOptions): Promise<ATPToolsResult>;
211
+ ```
212
+
213
+ **Options:**
214
+
215
+ ```typescript
216
+ interface CreateATPToolsOptions {
217
+ serverUrl: string;
218
+ headers?: Record<string, string>;
219
+ model: any;
220
+ embeddings?: EmbeddingProvider;
221
+ approvalHandler?: ApprovalHandler;
222
+ defaultExecutionConfig?: Partial<ExecutionConfig>;
223
+ hooks?: ClientHooks;
224
+ }
225
+ ```
226
+
227
+ **Returns:**
228
+
229
+ ```typescript
230
+ interface ATPToolsResult {
231
+ client: VercelAIATPClient;
232
+ tools: Record<string, any>;
233
+ }
234
+ ```
235
+
236
+ ### VercelAIATPClient
237
+
238
+ ```typescript
239
+ class VercelAIATPClient {
240
+ execute(code: string, config?: ExecutionConfig): Promise<ExecutionResult>;
241
+ getTypeDefinitions(): string;
242
+ getUnderlyingClient(): AgentToolProtocolClient;
243
+ }
244
+ ```
245
+
246
+ ## Production Patterns
247
+
248
+ ### Webhook-Based Approval
249
+
250
+ ```typescript
251
+ const pendingApprovals = new Map();
252
+
253
+ const approvalHandler = async (message: string, context?: any) => {
254
+ const approvalId = generateId();
255
+
256
+ await db.approvals.create({
257
+ id: approvalId,
258
+ message,
259
+ context,
260
+ status: 'pending',
261
+ });
262
+
263
+ await sendSlackNotification({
264
+ channel: '#approvals',
265
+ text: message,
266
+ actions: [
267
+ { type: 'button', text: 'Approve', action_id: `approve_${approvalId}` },
268
+ { type: 'button', text: 'Deny', action_id: `deny_${approvalId}` },
269
+ ],
270
+ });
271
+
272
+ return new Promise((resolve) => {
273
+ pendingApprovals.set(approvalId, resolve);
274
+ setTimeout(() => {
275
+ pendingApprovals.delete(approvalId);
276
+ resolve(false);
277
+ }, 300000);
278
+ });
279
+ };
280
+
281
+ app.post('/slack/actions', async (req, res) => {
282
+ const { action_id } = req.body;
283
+ const approvalId = action_id.replace(/^(approve|deny)_/, '');
284
+ const approved = action_id.startsWith('approve');
285
+
286
+ const resolve = pendingApprovals.get(approvalId);
287
+ if (resolve) {
288
+ resolve(approved);
289
+ pendingApprovals.delete(approvalId);
290
+ }
291
+
292
+ res.json({ ok: true });
293
+ });
294
+ ```
295
+
296
+ ### Multiple Sequential Approvals
297
+
298
+ ```typescript
299
+ // Agent generates ATP code with multiple approvals:
300
+ const step1 = await atp.approval.request('Approve step 1?');
301
+ if (!step1.approved) return { cancelled: true };
302
+
303
+ const step2 = await atp.approval.request('Approve step 2?');
304
+ if (!step2.approved) return { cancelled: true };
305
+
306
+ return { success: true };
307
+ ```
308
+
309
+ Each `atp.approval.request()` triggers your approval handler.
310
+
311
+ ### Error Handling
312
+
313
+ ```typescript
314
+ const { tools } = await createATPTools({
315
+ serverUrl: 'http://localhost:3333',
316
+ headers: { Authorization: 'Bearer your-api-key' },
317
+ model,
318
+ approvalHandler: async (message) => {
319
+ try {
320
+ return await requestApproval(message);
321
+ } catch (error) {
322
+ console.error('Approval error:', error);
323
+ return false;
324
+ }
325
+ },
326
+ });
327
+ ```
328
+
329
+ ## Comparison with LangChain Integration
330
+
331
+ | Feature | Vercel AI SDK | LangChain |
332
+ | ------------------------ | ------------------- | ----------------------- |
333
+ | Tool Format | `tool()` function | Tool classes |
334
+ | Agent Type | ToolLoopAgent | ReActAgent |
335
+ | Approval Mechanism | Async callbacks | Interrupts + Checkpoints|
336
+ | State Persistence | Custom | Built-in (LangGraph) |
337
+ | Streaming | Native support | Via LangChain |
338
+ | Model Integration | `generateText` | `ChatModel.invoke` |
339
+
340
+ ## Examples
341
+
342
+ See [`examples/vercel-ai-sdk-example/`](../../examples/vercel-ai-sdk-example/):
343
+
344
+ - **`agent.ts`** - Basic ToolLoopAgent with CLI approvals
345
+ - **`streaming.ts`** - Streaming responses with ATP tools
346
+ - **`webhook-approval.ts`** - Production webhook-based approvals
347
+
348
+ ### RAG with Embeddings
349
+
350
+ ```typescript
351
+ import { createATPTools } from '@mondaydotcomorg/atp-vercel-ai-sdk';
352
+ import { openai } from '@ai-sdk/openai';
353
+ import { embed } from 'ai';
354
+
355
+ const model = openai('gpt-4o');
356
+
357
+ const embeddings = {
358
+ embed: async (text: string) => {
359
+ const result = await embed({
360
+ model: openai.embedding('text-embedding-3-small'),
361
+ value: text,
362
+ });
363
+ return result.embedding;
364
+ },
365
+ };
366
+
367
+ const { tools } = await createATPTools({
368
+ serverUrl: 'http://localhost:3333',
369
+ headers: { Authorization: 'Bearer your-api-key' },
370
+ model,
371
+ embeddings,
372
+ });
373
+
374
+ const result = await generateText({
375
+ model,
376
+ tools,
377
+ maxSteps: 5,
378
+ prompt: `Use ATP to:
379
+ 1. Embed these documents: ["AI is...", "ML is...", "DL is..."]
380
+ 2. Search for content similar to "neural networks"
381
+ 3. Use atp.llm.call() to answer based on results`,
382
+ });
383
+ ```
384
+
385
+ ## TypeScript Support
386
+
387
+ ```typescript
388
+ import type {
389
+ VercelAIATPClient,
390
+ VercelAIATPClientOptions,
391
+ ApprovalRequest,
392
+ ApprovalResponse,
393
+ ApprovalHandler,
394
+ CreateATPToolsOptions,
395
+ ATPToolsResult,
396
+ EmbeddingProvider,
397
+ } from '@mondaydotcomorg/atp-vercel-ai-sdk';
398
+ ```
399
+
400
+ ## Requirements
401
+
402
+ - Node.js 18+
403
+ - TypeScript 5.0+
404
+ - `ai` ^4.0.0
405
+ - Vercel AI SDK provider (e.g., `@ai-sdk/openai`)
406
+
407
+ ## License
408
+
409
+ MIT
410
+
411
+ ## Learn More
412
+
413
+ - [ATP Documentation](../../README.md)
414
+ - [Vercel AI SDK Documentation](https://sdk.vercel.ai/docs)
415
+ - [Examples](../../examples/vercel-ai-sdk-example/)
416
+
@@ -0,0 +1,20 @@
1
+ import { AgentToolProtocolClient } from '@mondaydotcomorg/atp-client';
2
+ import type { ExecutionResult, ExecutionConfig } from '@mondaydotcomorg/atp-protocol';
3
+ import type { VercelAIATPClientOptions } from './types.js';
4
+ export declare class VercelAIATPClient {
5
+ private client;
6
+ private model;
7
+ private embeddings?;
8
+ private approvalHandler?;
9
+ constructor(options: VercelAIATPClientOptions);
10
+ connect(): Promise<void>;
11
+ getTypeDefinitions(): string;
12
+ execute(code: string, config?: Partial<ExecutionConfig>): Promise<ExecutionResult>;
13
+ getUnderlyingClient(): AgentToolProtocolClient;
14
+ private handleLLMCall;
15
+ private handleLLMExtract;
16
+ private handleLLMClassify;
17
+ private handleEmbedding;
18
+ private handleApprovalRequest;
19
+ }
20
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,KAAK,EACX,wBAAwB,EAIxB,MAAM,YAAY,CAAC;AAEpB,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,UAAU,CAAC,CAAoB;IACvC,OAAO,CAAC,eAAe,CAAC,CAAkB;gBAE9B,OAAO,EAAE,wBAAwB;IAwCvC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,kBAAkB,IAAI,MAAM;IAItB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC;IAIxF,mBAAmB,IAAI,uBAAuB;YAIhC,aAAa;YAYb,gBAAgB;YAahB,iBAAiB;YAkCjB,eAAe;YAUf,qBAAqB;CAgBnC"}
package/dist/client.js ADDED
@@ -0,0 +1,117 @@
1
+ import { AgentToolProtocolClient } from '@mondaydotcomorg/atp-client';
2
+ import { generateObject, generateText } from 'ai';
3
+ export class VercelAIATPClient {
4
+ client;
5
+ model;
6
+ embeddings;
7
+ approvalHandler;
8
+ constructor(options) {
9
+ const { serverUrl, headers, model, embeddings, tools, approvalHandler, hooks } = options;
10
+ this.client = new AgentToolProtocolClient({
11
+ baseUrl: serverUrl,
12
+ headers,
13
+ hooks,
14
+ serviceProviders: tools ? { tools } : undefined,
15
+ });
16
+ this.model = model;
17
+ this.embeddings = embeddings;
18
+ this.approvalHandler = approvalHandler;
19
+ this.client.provideLLM({
20
+ call: async (prompt, options) => {
21
+ return await this.handleLLMCall(prompt, options);
22
+ },
23
+ extract: async (prompt, schema, options) => {
24
+ return await this.handleLLMExtract(prompt, schema, options);
25
+ },
26
+ classify: async (text, categories, options) => {
27
+ return await this.handleLLMClassify(text, categories, options);
28
+ },
29
+ });
30
+ if (this.embeddings) {
31
+ this.client.provideEmbedding({
32
+ embed: async (text) => {
33
+ return await this.handleEmbedding(text);
34
+ },
35
+ });
36
+ }
37
+ this.client.provideApproval({
38
+ request: async (message, context) => {
39
+ return await this.handleApprovalRequest(message, context);
40
+ },
41
+ });
42
+ }
43
+ async connect() {
44
+ await this.client.init({ name: 'vercel-ai-sdk-atp-client', version: '1.0.0' });
45
+ await this.client.connect();
46
+ }
47
+ getTypeDefinitions() {
48
+ return this.client.getTypeDefinitions();
49
+ }
50
+ async execute(code, config) {
51
+ return await this.client.execute(code, config);
52
+ }
53
+ getUnderlyingClient() {
54
+ return this.client;
55
+ }
56
+ async handleLLMCall(prompt, options) {
57
+ const result = await generateText({
58
+ model: this.model,
59
+ prompt,
60
+ temperature: options?.temperature,
61
+ maxTokens: options?.maxTokens,
62
+ system: options?.systemPrompt,
63
+ });
64
+ return result.text;
65
+ }
66
+ async handleLLMExtract(prompt, schema, options) {
67
+ const result = await generateObject({
68
+ model: this.model,
69
+ prompt,
70
+ schema,
71
+ system: options?.systemPrompt,
72
+ temperature: options?.temperature,
73
+ maxTokens: options?.maxTokens,
74
+ });
75
+ return result.object;
76
+ }
77
+ async handleLLMClassify(text, categories, options) {
78
+ const promptText = `Classify the following text into one of these categories: ${categories.join(', ')}\n\nText: ${text}\n\nRespond with ONLY the category name, nothing else.`;
79
+ const result = await generateText({
80
+ model: this.model,
81
+ prompt: promptText,
82
+ system: options?.systemPrompt,
83
+ temperature: 0,
84
+ });
85
+ const classification = result.text.trim();
86
+ if (categories.includes(classification)) {
87
+ return classification;
88
+ }
89
+ for (const category of categories) {
90
+ if (classification.toLowerCase().includes(category.toLowerCase())) {
91
+ return category;
92
+ }
93
+ }
94
+ const fallback = categories[0];
95
+ if (!fallback) {
96
+ throw new Error('No categories provided for classification');
97
+ }
98
+ return fallback;
99
+ }
100
+ async handleEmbedding(text) {
101
+ if (!this.embeddings) {
102
+ throw new Error('Embeddings provider not configured. Pass embeddings option when creating VercelAIATPClient.');
103
+ }
104
+ return await this.embeddings.embed(text);
105
+ }
106
+ async handleApprovalRequest(message, context) {
107
+ if (!this.approvalHandler) {
108
+ throw new Error('No approval handler configured. Pass approvalHandler option when creating VercelAIATPClient.');
109
+ }
110
+ const approved = await this.approvalHandler(message, context);
111
+ return {
112
+ approved,
113
+ timestamp: Date.now(),
114
+ };
115
+ }
116
+ }
117
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAQlD,MAAM,OAAO,iBAAiB;IACrB,MAAM,CAA0B;IAChC,KAAK,CAAM;IACX,UAAU,CAAqB;IAC/B,eAAe,CAAmB;IAE1C,YAAY,OAAiC;QAC5C,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAEzF,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAuB,CAAC;YACzC,OAAO,EAAE,SAAS;YAClB,OAAO;YACP,KAAK;YACL,gBAAgB,EAAE,KAAK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CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9D,OAAO;YACN,QAAQ;YACR,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACrB,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ export { VercelAIATPClient } from './client.js';
2
+ export { createATPTools } from './tools.js';
3
+ export type { VercelAIATPClientOptions, CreateATPToolsOptions, ATPToolsResult, ApprovalHandler, ApprovalRequest, ApprovalResponse, EmbeddingProvider, } from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EACX,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { VercelAIATPClient } from './client.js';
2
+ export { createATPTools } from './tools.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CreateATPToolsOptions, ATPToolsResult } from './types.js';
2
+ export declare function createATPTools(options: CreateATPToolsOptions): Promise<ATPToolsResult>;
3
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKxE,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAgG5F"}
package/dist/tools.js ADDED
@@ -0,0 +1,100 @@
1
+ import { z } from 'zod';
2
+ import { VercelAIATPClient } from './client.js';
3
+ import { createToolsFromATPClient, ToolNames } from '@mondaydotcomorg/atp-client';
4
+ import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
5
+ import { tool } from 'ai';
6
+ export async function createATPTools(options) {
7
+ const { defaultExecutionConfig, ...clientOptions } = options;
8
+ const client = new VercelAIATPClient(clientOptions);
9
+ await client.connect();
10
+ const atpTools = createToolsFromATPClient(client.getUnderlyingClient());
11
+ const vercelTools = {};
12
+ for (const atpTool of atpTools) {
13
+ if (atpTool.name === ToolNames.EXECUTE_CODE) {
14
+ vercelTools.atp_execute_code = tool({
15
+ description: atpTool.description ||
16
+ 'Execute TypeScript code in ATP sandbox with access to runtime APIs (atp.llm.*, atp.embedding.*, atp.approval.*)',
17
+ parameters: z.object({
18
+ code: z.string().describe('TypeScript code to execute in the ATP sandbox'),
19
+ }),
20
+ execute: async ({ code }) => {
21
+ try {
22
+ const result = await client.execute(code, defaultExecutionConfig);
23
+ if (result.status === ExecutionStatus.COMPLETED) {
24
+ return {
25
+ success: true,
26
+ result: result.result,
27
+ stats: result.stats,
28
+ };
29
+ }
30
+ else if (result.status === ExecutionStatus.FAILED) {
31
+ return {
32
+ success: false,
33
+ error: result.error,
34
+ stats: result.stats,
35
+ };
36
+ }
37
+ else {
38
+ return {
39
+ success: false,
40
+ error: 'Execution in unexpected state: ' + result.status,
41
+ };
42
+ }
43
+ }
44
+ catch (error) {
45
+ return {
46
+ success: false,
47
+ error: error.message || 'Unknown error',
48
+ };
49
+ }
50
+ },
51
+ });
52
+ }
53
+ else {
54
+ const toolName = `atp_${atpTool.name}`;
55
+ vercelTools[toolName] = tool({
56
+ description: atpTool.description || '',
57
+ parameters: atpTool.zodSchema || z.object({}),
58
+ execute: async (input) => {
59
+ try {
60
+ const result = await atpTool.func(input);
61
+ return {
62
+ success: true,
63
+ result,
64
+ };
65
+ }
66
+ catch (error) {
67
+ return {
68
+ success: false,
69
+ error: error.message,
70
+ };
71
+ }
72
+ },
73
+ });
74
+ }
75
+ }
76
+ vercelTools.atp_get_type_definitions = tool({
77
+ description: 'Get TypeScript type definitions for ATP runtime APIs to understand available functions',
78
+ parameters: z.object({}),
79
+ execute: async () => {
80
+ try {
81
+ const types = client.getTypeDefinitions();
82
+ return {
83
+ success: true,
84
+ types,
85
+ };
86
+ }
87
+ catch (error) {
88
+ return {
89
+ success: false,
90
+ error: error.message,
91
+ };
92
+ }
93
+ },
94
+ });
95
+ return {
96
+ client,
97
+ tools: vercelTools,
98
+ };
99
+ }
100
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IAClE,MAAM,EAAE,sBAAsB,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAE7D,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACpD,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,MAAM,QAAQ,GAAG,wBAAwB,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAExE,MAAM,WAAW,GAAwB,EAAE,CAAC;IAE5C,KAAK,MAAM,OAAO,IAAI,QAAQ,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2
+ import type { ClientHooks } from '@mondaydotcomorg/atp-client';
3
+ export interface ApprovalRequest {
4
+ message: string;
5
+ context?: Record<string, unknown>;
6
+ timestamp: number;
7
+ }
8
+ export interface ApprovalResponse {
9
+ approved: boolean;
10
+ reason?: string;
11
+ timestamp: number;
12
+ }
13
+ export type ApprovalHandler = (message: string, context?: Record<string, unknown>) => Promise<boolean>;
14
+ export interface EmbeddingProvider {
15
+ embed(text: string): Promise<number[]>;
16
+ }
17
+ export interface VercelAIATPClientOptions {
18
+ serverUrl: string;
19
+ headers?: Record<string, string>;
20
+ model: any;
21
+ embeddings?: EmbeddingProvider;
22
+ tools?: ClientTool[];
23
+ approvalHandler?: ApprovalHandler;
24
+ hooks?: ClientHooks;
25
+ }
26
+ export interface CreateATPToolsOptions {
27
+ serverUrl: string;
28
+ headers?: Record<string, string>;
29
+ model: any;
30
+ embeddings?: EmbeddingProvider;
31
+ approvalHandler?: ApprovalHandler;
32
+ defaultExecutionConfig?: Partial<ExecutionConfig>;
33
+ hooks?: ClientHooks;
34
+ }
35
+ export interface ATPToolsResult {
36
+ client: any;
37
+ tools: Record<string, any>;
38
+ }
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,eAAe,GAAG,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IACjC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,wBAAwB;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,sBAAsB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAClD,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,GAAG,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@mondaydotcomorg/atp-vercel-sdk",
3
+ "version": "0.19.2",
4
+ "description": "Vercel AI SDK integration for Agent Tool Protocol",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/mondaycom/agent-tool-protocol",
21
+ "directory": "packages/vercel-ai-sdk"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "dev": "tsc -p tsconfig.json --watch",
29
+ "clean": "rm -rf dist *.tsbuildinfo",
30
+ "test": "NODE_OPTIONS='--no-node-snapshot' jest --runInBand --forceExit --testTimeout=30000",
31
+ "lint": "tsc --noEmit"
32
+ },
33
+ "keywords": [
34
+ "agent",
35
+ "protocol",
36
+ "atp",
37
+ "vercel",
38
+ "ai-sdk",
39
+ "ai",
40
+ "llm"
41
+ ],
42
+ "license": "MIT",
43
+ "dependencies": {
44
+ "@mondaydotcomorg/atp-client": "0.19.2",
45
+ "@mondaydotcomorg/atp-protocol": "0.19.2",
46
+ "zod": "^3.23.8"
47
+ },
48
+ "peerDependencies": {
49
+ "ai": "^4.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@jest/globals": "^29.7.0",
53
+ "@types/jest": "^29.5.11",
54
+ "jest": "^29.7.0",
55
+ "typescript": "^5.3.3"
56
+ }
57
+ }
package/src/client.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { AgentToolProtocolClient } from '@mondaydotcomorg/atp-client';
2
+ import type { ExecutionResult, ExecutionConfig } from '@mondaydotcomorg/atp-protocol';
3
+ import { generateObject, generateText } from 'ai';
4
+ import type {
5
+ VercelAIATPClientOptions,
6
+ ApprovalResponse,
7
+ EmbeddingProvider,
8
+ ApprovalHandler,
9
+ } from './types.js';
10
+
11
+ export class VercelAIATPClient {
12
+ private client: AgentToolProtocolClient;
13
+ private model: any;
14
+ private embeddings?: EmbeddingProvider;
15
+ private approvalHandler?: ApprovalHandler;
16
+
17
+ constructor(options: VercelAIATPClientOptions) {
18
+ const { serverUrl, headers, model, embeddings, tools, approvalHandler, hooks } = options;
19
+
20
+ this.client = new AgentToolProtocolClient({
21
+ baseUrl: serverUrl,
22
+ headers,
23
+ hooks,
24
+ serviceProviders: tools ? { tools } : undefined,
25
+ });
26
+ this.model = model;
27
+ this.embeddings = embeddings;
28
+ this.approvalHandler = approvalHandler;
29
+
30
+ this.client.provideLLM({
31
+ call: async (prompt: string, options?: any) => {
32
+ return await this.handleLLMCall(prompt, options);
33
+ },
34
+ extract: async (prompt: string, schema: any, options?: any) => {
35
+ return await this.handleLLMExtract(prompt, schema, options);
36
+ },
37
+ classify: async (text: string, categories: string[], options?: any) => {
38
+ return await this.handleLLMClassify(text, categories, options);
39
+ },
40
+ });
41
+
42
+ if (this.embeddings) {
43
+ this.client.provideEmbedding({
44
+ embed: async (text: string) => {
45
+ return await this.handleEmbedding(text);
46
+ },
47
+ });
48
+ }
49
+
50
+ this.client.provideApproval({
51
+ request: async (message: string, context?: Record<string, unknown>) => {
52
+ return await this.handleApprovalRequest(message, context);
53
+ },
54
+ });
55
+ }
56
+
57
+ async connect(): Promise<void> {
58
+ await this.client.init({ name: 'vercel-ai-sdk-atp-client', version: '1.0.0' });
59
+ await this.client.connect();
60
+ }
61
+
62
+ getTypeDefinitions(): string {
63
+ return this.client.getTypeDefinitions();
64
+ }
65
+
66
+ async execute(code: string, config?: Partial<ExecutionConfig>): Promise<ExecutionResult> {
67
+ return await this.client.execute(code, config);
68
+ }
69
+
70
+ getUnderlyingClient(): AgentToolProtocolClient {
71
+ return this.client;
72
+ }
73
+
74
+ private async handleLLMCall(prompt: string, options?: any): Promise<string> {
75
+ const result = await generateText({
76
+ model: this.model,
77
+ prompt,
78
+ temperature: options?.temperature,
79
+ maxTokens: options?.maxTokens,
80
+ system: options?.systemPrompt,
81
+ });
82
+
83
+ return result.text;
84
+ }
85
+
86
+ private async handleLLMExtract(prompt: string, schema: any, options?: any): Promise<any> {
87
+ const result = await generateObject({
88
+ model: this.model,
89
+ prompt,
90
+ schema,
91
+ system: options?.systemPrompt,
92
+ temperature: options?.temperature,
93
+ maxTokens: options?.maxTokens,
94
+ });
95
+
96
+ return result.object;
97
+ }
98
+
99
+ private async handleLLMClassify(
100
+ text: string,
101
+ categories: string[],
102
+ options?: any
103
+ ): Promise<string> {
104
+
105
+ const promptText = `Classify the following text into one of these categories: ${categories.join(', ')}\n\nText: ${text}\n\nRespond with ONLY the category name, nothing else.`;
106
+
107
+ const result = await generateText({
108
+ model: this.model,
109
+ prompt: promptText,
110
+ system: options?.systemPrompt,
111
+ temperature: 0,
112
+ });
113
+
114
+ const classification = result.text.trim();
115
+
116
+ if (categories.includes(classification)) {
117
+ return classification;
118
+ }
119
+
120
+ for (const category of categories) {
121
+ if (classification.toLowerCase().includes(category.toLowerCase())) {
122
+ return category;
123
+ }
124
+ }
125
+
126
+ const fallback = categories[0];
127
+ if (!fallback) {
128
+ throw new Error('No categories provided for classification');
129
+ }
130
+ return fallback;
131
+ }
132
+
133
+ private async handleEmbedding(text: string): Promise<number[]> {
134
+ if (!this.embeddings) {
135
+ throw new Error(
136
+ 'Embeddings provider not configured. Pass embeddings option when creating VercelAIATPClient.'
137
+ );
138
+ }
139
+
140
+ return await this.embeddings.embed(text);
141
+ }
142
+
143
+ private async handleApprovalRequest(
144
+ message: string,
145
+ context?: Record<string, unknown>
146
+ ): Promise<ApprovalResponse> {
147
+ if (!this.approvalHandler) {
148
+ throw new Error(
149
+ 'No approval handler configured. Pass approvalHandler option when creating VercelAIATPClient.'
150
+ );
151
+ }
152
+
153
+ const approved = await this.approvalHandler(message, context);
154
+ return {
155
+ approved,
156
+ timestamp: Date.now(),
157
+ };
158
+ }
159
+ }
160
+
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export { VercelAIATPClient } from './client.js';
2
+ export { createATPTools } from './tools.js';
3
+ export type {
4
+ VercelAIATPClientOptions,
5
+ CreateATPToolsOptions,
6
+ ATPToolsResult,
7
+ ApprovalHandler,
8
+ ApprovalRequest,
9
+ ApprovalResponse,
10
+ EmbeddingProvider,
11
+ } from './types.js';
12
+
package/src/tools.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { z } from 'zod';
2
+ import { VercelAIATPClient } from './client.js';
3
+ import type { CreateATPToolsOptions, ATPToolsResult } from './types.js';
4
+ import { createToolsFromATPClient, ToolNames } from '@mondaydotcomorg/atp-client';
5
+ import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
6
+ import { tool } from 'ai';
7
+
8
+ export async function createATPTools(options: CreateATPToolsOptions): Promise<ATPToolsResult> {
9
+ const { defaultExecutionConfig, ...clientOptions } = options;
10
+
11
+ const client = new VercelAIATPClient(clientOptions);
12
+ await client.connect();
13
+
14
+ const atpTools = createToolsFromATPClient(client.getUnderlyingClient());
15
+
16
+ const vercelTools: Record<string, any> = {};
17
+
18
+ for (const atpTool of atpTools) {
19
+ if (atpTool.name === ToolNames.EXECUTE_CODE) {
20
+ vercelTools.atp_execute_code = tool({
21
+ description:
22
+ atpTool.description ||
23
+ 'Execute TypeScript code in ATP sandbox with access to runtime APIs (atp.llm.*, atp.embedding.*, atp.approval.*)',
24
+ parameters: z.object({
25
+ code: z.string().describe('TypeScript code to execute in the ATP sandbox'),
26
+ }),
27
+ execute: async ({ code }: { code: string }) => {
28
+ try {
29
+ const result = await client.execute(code, defaultExecutionConfig);
30
+
31
+ if (result.status === ExecutionStatus.COMPLETED) {
32
+ return {
33
+ success: true,
34
+ result: result.result,
35
+ stats: result.stats,
36
+ };
37
+ } else if (result.status === ExecutionStatus.FAILED) {
38
+ return {
39
+ success: false,
40
+ error: result.error,
41
+ stats: result.stats,
42
+ };
43
+ } else {
44
+ return {
45
+ success: false,
46
+ error: 'Execution in unexpected state: ' + result.status,
47
+ };
48
+ }
49
+ } catch (error: any) {
50
+ return {
51
+ success: false,
52
+ error: error.message || 'Unknown error',
53
+ };
54
+ }
55
+ },
56
+ });
57
+ } else {
58
+ const toolName = `atp_${atpTool.name}`;
59
+ vercelTools[toolName] = tool({
60
+ description: atpTool.description || '',
61
+ parameters: atpTool.zodSchema || z.object({}),
62
+ execute: async (input: any) => {
63
+ try {
64
+ const result = await atpTool.func(input);
65
+ return {
66
+ success: true,
67
+ result,
68
+ };
69
+ } catch (error: any) {
70
+ return {
71
+ success: false,
72
+ error: error.message,
73
+ };
74
+ }
75
+ },
76
+ });
77
+ }
78
+ }
79
+
80
+ vercelTools.atp_get_type_definitions = tool({
81
+ description:
82
+ 'Get TypeScript type definitions for ATP runtime APIs to understand available functions',
83
+ parameters: z.object({}),
84
+ execute: async () => {
85
+ try {
86
+ const types = client.getTypeDefinitions();
87
+ return {
88
+ success: true,
89
+ types,
90
+ };
91
+ } catch (error: any) {
92
+ return {
93
+ success: false,
94
+ error: error.message,
95
+ };
96
+ }
97
+ },
98
+ });
99
+
100
+ return {
101
+ client,
102
+ tools: vercelTools,
103
+ };
104
+ }
105
+
package/src/types.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { ExecutionConfig, ClientTool } from '@mondaydotcomorg/atp-protocol';
2
+ import type { ClientHooks } from '@mondaydotcomorg/atp-client';
3
+
4
+ export interface ApprovalRequest {
5
+ message: string;
6
+ context?: Record<string, unknown>;
7
+ timestamp: number;
8
+ }
9
+
10
+ export interface ApprovalResponse {
11
+ approved: boolean;
12
+ reason?: string;
13
+ timestamp: number;
14
+ }
15
+
16
+ export type ApprovalHandler = (
17
+ message: string,
18
+ context?: Record<string, unknown>
19
+ ) => Promise<boolean>;
20
+
21
+ export interface EmbeddingProvider {
22
+ embed(text: string): Promise<number[]>;
23
+ }
24
+
25
+ export interface VercelAIATPClientOptions {
26
+ serverUrl: string;
27
+ headers?: Record<string, string>;
28
+ model: any;
29
+ embeddings?: EmbeddingProvider;
30
+ tools?: ClientTool[];
31
+ approvalHandler?: ApprovalHandler;
32
+ hooks?: ClientHooks;
33
+ }
34
+
35
+ export interface CreateATPToolsOptions {
36
+ serverUrl: string;
37
+ headers?: Record<string, string>;
38
+ model: any;
39
+ embeddings?: EmbeddingProvider;
40
+ approvalHandler?: ApprovalHandler;
41
+ defaultExecutionConfig?: Partial<ExecutionConfig>;
42
+ hooks?: ClientHooks;
43
+ }
44
+
45
+ export interface ATPToolsResult {
46
+ client: any;
47
+ tools: Record<string, any>;
48
+ }
49
+