bigtool-ts 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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +641 -0
- package/dist/adapters/agent-protocol.d.ts +149 -0
- package/dist/adapters/agent-protocol.d.ts.map +1 -0
- package/dist/adapters/agent-protocol.js +133 -0
- package/dist/adapters/agent-protocol.js.map +1 -0
- package/dist/adapters/index.d.ts +39 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +42 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/inngest.d.ts +234 -0
- package/dist/adapters/inngest.d.ts.map +1 -0
- package/dist/adapters/inngest.js +276 -0
- package/dist/adapters/inngest.js.map +1 -0
- package/dist/adapters/mastra.d.ts +201 -0
- package/dist/adapters/mastra.d.ts.map +1 -0
- package/dist/adapters/mastra.js +250 -0
- package/dist/adapters/mastra.js.map +1 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +6 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +176 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +244 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/catalog/index.d.ts +177 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +244 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/graph/agent.d.ts +214 -0
- package/dist/graph/agent.d.ts.map +1 -0
- package/dist/graph/agent.js +196 -0
- package/dist/graph/agent.js.map +1 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/nodes.d.ts +100 -0
- package/dist/graph/nodes.d.ts.map +1 -0
- package/dist/graph/nodes.js +190 -0
- package/dist/graph/nodes.js.map +1 -0
- package/dist/graph/search-tool.d.ts +34 -0
- package/dist/graph/search-tool.d.ts.map +1 -0
- package/dist/graph/search-tool.js +54 -0
- package/dist/graph/search-tool.js.map +1 -0
- package/dist/graph/state.d.ts +26 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +29 -0
- package/dist/graph/state.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/index.d.ts +172 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/index.js +179 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/loader.d.ts +114 -0
- package/dist/loader/loader.d.ts.map +1 -0
- package/dist/loader/loader.js +185 -0
- package/dist/loader/loader.js.map +1 -0
- package/dist/search/cache.d.ts +76 -0
- package/dist/search/cache.d.ts.map +1 -0
- package/dist/search/cache.js +135 -0
- package/dist/search/cache.js.map +1 -0
- package/dist/search/index.d.ts +63 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +122 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/normalize.d.ts +104 -0
- package/dist/search/normalize.d.ts.map +1 -0
- package/dist/search/normalize.js +211 -0
- package/dist/search/normalize.js.map +1 -0
- package/dist/search/orama.d.ts +256 -0
- package/dist/search/orama.d.ts.map +1 -0
- package/dist/search/orama.js +511 -0
- package/dist/search/orama.js.map +1 -0
- package/dist/search/types.d.ts +96 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search/types.js +8 -0
- package/dist/search/types.js.map +1 -0
- package/dist/sources/dynamic.d.ts +200 -0
- package/dist/sources/dynamic.d.ts.map +1 -0
- package/dist/sources/dynamic.js +194 -0
- package/dist/sources/dynamic.js.map +1 -0
- package/dist/sources/index.d.ts +11 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +14 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/local.d.ts +128 -0
- package/dist/sources/local.d.ts.map +1 -0
- package/dist/sources/local.js +155 -0
- package/dist/sources/local.js.map +1 -0
- package/dist/sources/mcp.d.ts +438 -0
- package/dist/sources/mcp.d.ts.map +1 -0
- package/dist/sources/mcp.js +438 -0
- package/dist/sources/mcp.js.map +1 -0
- package/dist/sources/types.d.ts +16 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +7 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/sources/with-metadata.d.ts +7 -0
- package/dist/sources/with-metadata.d.ts.map +1 -0
- package/dist/sources/with-metadata.js +7 -0
- package/dist/sources/with-metadata.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +700 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +97 -0
- package/dist/types.js.map +1 -0
- package/package.json +118 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra Adapter for bigtool-ts
|
|
3
|
+
*
|
|
4
|
+
* Converts bigtool-ts tools to Mastra-compatible tools.
|
|
5
|
+
*
|
|
6
|
+
* @module adapters/mastra
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createMastraAdapter } from '@repo/bigtool-ts/adapters';
|
|
11
|
+
* import { Agent } from '@mastra/core/agent';
|
|
12
|
+
*
|
|
13
|
+
* const adapter = createMastraAdapter({ catalog, loader, searchIndex });
|
|
14
|
+
*
|
|
15
|
+
* const agent = new Agent({
|
|
16
|
+
* id: 'my-agent',
|
|
17
|
+
* tools: {
|
|
18
|
+
* search: adapter.createSearchTool(),
|
|
19
|
+
* ...await adapter.getToolsAsRecord(['github:create_pr']),
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Requires `@mastra/core` v1.0.0-beta.24+ as a peer dependency.
|
|
26
|
+
* Install separately: `pnpm add @mastra/core`
|
|
27
|
+
*/
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
30
|
+
// ADAPTER IMPLEMENTATION
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
32
|
+
/**
|
|
33
|
+
* Adapter for converting bigtool-ts tools to Mastra format.
|
|
34
|
+
*
|
|
35
|
+
* Implements the `ToolAdapter` interface for Mastra framework
|
|
36
|
+
* compatibility. Provides both array and record output formats
|
|
37
|
+
* to match Mastra's agent API expectations.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const adapter = new MastraAdapter({ catalog, loader, searchIndex });
|
|
42
|
+
*
|
|
43
|
+
* // Get tools as array
|
|
44
|
+
* const tools = await adapter.getTools(['github:create_pr']);
|
|
45
|
+
*
|
|
46
|
+
* // Get tools as Record for Agent constructor
|
|
47
|
+
* const toolRecord = await adapter.getToolsAsRecord(['github:create_pr']);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export class MastraAdapter {
|
|
51
|
+
catalog;
|
|
52
|
+
loader;
|
|
53
|
+
searchIndex;
|
|
54
|
+
constructor(config) {
|
|
55
|
+
this.catalog = config.catalog;
|
|
56
|
+
this.loader = config.loader;
|
|
57
|
+
this.searchIndex = config.searchIndex;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Convert bigtool-ts metadata to a Mastra tool.
|
|
61
|
+
*
|
|
62
|
+
* Creates a Mastra-compatible tool definition that lazily loads
|
|
63
|
+
* and executes the underlying bigtool-ts tool implementation.
|
|
64
|
+
*
|
|
65
|
+
* @param metadata - Tool metadata from the catalog
|
|
66
|
+
* @returns Mastra tool definition
|
|
67
|
+
*/
|
|
68
|
+
toFrameworkTool(metadata) {
|
|
69
|
+
const loader = this.loader;
|
|
70
|
+
// Build Zod schema from JSON Schema parameters
|
|
71
|
+
const inputSchema = this.buildInputSchema(metadata.parameters);
|
|
72
|
+
return {
|
|
73
|
+
id: metadata.id,
|
|
74
|
+
description: metadata.description,
|
|
75
|
+
inputSchema,
|
|
76
|
+
outputSchema: undefined,
|
|
77
|
+
execute: async (inputData) => {
|
|
78
|
+
const tool = await loader.load(metadata.id);
|
|
79
|
+
return tool.invoke(inputData);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get tools by IDs as an array.
|
|
85
|
+
*
|
|
86
|
+
* Converts each tool from bigtool-ts format to Mastra format.
|
|
87
|
+
* Tools not found in the catalog are silently skipped.
|
|
88
|
+
*
|
|
89
|
+
* @param toolIds - Array of tool IDs to retrieve
|
|
90
|
+
* @returns Array of Mastra tools
|
|
91
|
+
*/
|
|
92
|
+
async getTools(toolIds) {
|
|
93
|
+
const tools = [];
|
|
94
|
+
for (const id of toolIds) {
|
|
95
|
+
const metadata = this.catalog.getMetadata(id);
|
|
96
|
+
if (metadata === null) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
tools.push(this.toFrameworkTool(metadata));
|
|
100
|
+
}
|
|
101
|
+
return tools;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get tools as a Record for Mastra Agent constructor.
|
|
105
|
+
*
|
|
106
|
+
* Mastra agents expect tools in `Record<string, Tool>` format.
|
|
107
|
+
* Uses the tool name (last segment of ID) as the record key.
|
|
108
|
+
*
|
|
109
|
+
* @param toolIds - Array of tool IDs to retrieve
|
|
110
|
+
* @returns Record of tool name to Mastra tool
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const tools = await adapter.getToolsAsRecord(['github:create_pr']);
|
|
115
|
+
* // Returns: { create_pr: MastraTool }
|
|
116
|
+
*
|
|
117
|
+
* const agent = new Agent({
|
|
118
|
+
* tools: {
|
|
119
|
+
* search: adapter.createSearchTool(),
|
|
120
|
+
* ...tools,
|
|
121
|
+
* },
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
async getToolsAsRecord(toolIds) {
|
|
126
|
+
const tools = {};
|
|
127
|
+
for (const id of toolIds) {
|
|
128
|
+
const metadata = this.catalog.getMetadata(id);
|
|
129
|
+
if (metadata === null) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const toolKey = this.extractToolKey(id);
|
|
133
|
+
tools[toolKey] = this.toFrameworkTool(metadata);
|
|
134
|
+
}
|
|
135
|
+
return tools;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a search tool for discovering available tools.
|
|
139
|
+
*
|
|
140
|
+
* Returns a Mastra tool that agents can use to search the
|
|
141
|
+
* bigtool-ts catalog using natural language queries.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Search configuration options
|
|
144
|
+
* @returns Mastra search tool
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const agent = new Agent({
|
|
149
|
+
* tools: {
|
|
150
|
+
* search_tools: adapter.createSearchTool({ limit: 10 }),
|
|
151
|
+
* },
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
createSearchTool(options = {}) {
|
|
156
|
+
const limit = options.limit ?? 5;
|
|
157
|
+
const threshold = options.threshold ?? 0;
|
|
158
|
+
const categories = options.categories;
|
|
159
|
+
const searchIndex = this.searchIndex;
|
|
160
|
+
const catalog = this.catalog;
|
|
161
|
+
const inputSchema = z.object({
|
|
162
|
+
query: z.string().describe('Natural language search query for finding tools'),
|
|
163
|
+
});
|
|
164
|
+
const outputSchema = z.array(z.object({
|
|
165
|
+
id: z.string().describe('Tool ID'),
|
|
166
|
+
description: z.string().describe('Tool description'),
|
|
167
|
+
score: z.number().describe('Relevance score (0-1)'),
|
|
168
|
+
}));
|
|
169
|
+
return {
|
|
170
|
+
id: 'bigtool-search-tools',
|
|
171
|
+
description: 'Search for available tools by query. Use this to discover what tools are available before calling them.',
|
|
172
|
+
inputSchema,
|
|
173
|
+
outputSchema,
|
|
174
|
+
execute: async (inputData) => {
|
|
175
|
+
const results = await searchIndex.search(inputData.query, {
|
|
176
|
+
limit,
|
|
177
|
+
threshold,
|
|
178
|
+
categories,
|
|
179
|
+
});
|
|
180
|
+
return results.map((searchResult) => {
|
|
181
|
+
const meta = catalog.getMetadata(searchResult.toolId);
|
|
182
|
+
return {
|
|
183
|
+
id: searchResult.toolId,
|
|
184
|
+
description: meta?.description ?? '',
|
|
185
|
+
score: searchResult.score,
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
192
|
+
// PRIVATE HELPERS
|
|
193
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
194
|
+
/**
|
|
195
|
+
* Extract the tool key from a fully-qualified tool ID.
|
|
196
|
+
*
|
|
197
|
+
* For IDs like 'github:create_pr', returns 'create_pr'.
|
|
198
|
+
* For IDs without a namespace, returns the full ID.
|
|
199
|
+
*/
|
|
200
|
+
extractToolKey(id) {
|
|
201
|
+
const colonIndex = id.lastIndexOf(':');
|
|
202
|
+
if (colonIndex === -1) {
|
|
203
|
+
return id;
|
|
204
|
+
}
|
|
205
|
+
return id.slice(colonIndex + 1);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Build a Zod schema from JSON Schema parameters.
|
|
209
|
+
*
|
|
210
|
+
* Returns a permissive schema that accepts any object shape.
|
|
211
|
+
* Validation is delegated to the underlying bigtool-ts tool,
|
|
212
|
+
* avoiding the complexity of JSON Schema to Zod conversion.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* Converting JSON Schema to Zod at runtime would require a
|
|
216
|
+
* library like `json-schema-to-zod`. Since bigtool-ts tools
|
|
217
|
+
* perform their own validation, this passthrough approach
|
|
218
|
+
* avoids that dependency while maintaining compatibility.
|
|
219
|
+
*/
|
|
220
|
+
buildInputSchema(_parameters) {
|
|
221
|
+
return z.object({}).passthrough();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
225
|
+
// FACTORY FUNCTION
|
|
226
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
227
|
+
/**
|
|
228
|
+
* Create a Mastra adapter for bigtool-ts.
|
|
229
|
+
*
|
|
230
|
+
* Factory function that creates a configured `MastraAdapter` instance.
|
|
231
|
+
*
|
|
232
|
+
* @param config - Adapter configuration with catalog, loader, and search index
|
|
233
|
+
* @returns Configured Mastra adapter
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* import { createMastraAdapter } from '@repo/bigtool-ts/adapters';
|
|
238
|
+
* import { DefaultToolCatalog, DefaultToolLoader, OramaSearch } from '@repo/bigtool-ts';
|
|
239
|
+
*
|
|
240
|
+
* const catalog = new DefaultToolCatalog();
|
|
241
|
+
* const loader = new DefaultToolLoader(catalog);
|
|
242
|
+
* const searchIndex = new OramaSearch();
|
|
243
|
+
*
|
|
244
|
+
* const adapter = createMastraAdapter({ catalog, loader, searchIndex });
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export function createMastraAdapter(config) {
|
|
248
|
+
return new MastraAdapter(config);
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=mastra.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.js","sourceRoot":"","sources":["../../src/adapters/mastra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoExB,sEAAsE;AACtE,yBAAyB;AACzB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAa;IACP,OAAO,CAA2B;IACl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Aa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types for framework adapters
|
|
3
|
+
* @module adapters/types
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolCatalog, ToolLoader, SearchIndex, ToolMetadata } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for creating framework adapters
|
|
8
|
+
*/
|
|
9
|
+
export interface AdapterConfig {
|
|
10
|
+
catalog: ToolCatalog;
|
|
11
|
+
loader: ToolLoader;
|
|
12
|
+
searchIndex: SearchIndex;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for creating search tools
|
|
16
|
+
*/
|
|
17
|
+
export interface SearchToolOptions {
|
|
18
|
+
/** Maximum number of results to return (default: 5) */
|
|
19
|
+
limit?: number;
|
|
20
|
+
/** Minimum score threshold (default: 0) */
|
|
21
|
+
threshold?: number;
|
|
22
|
+
/** Filter by categories */
|
|
23
|
+
categories?: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Common interface that all adapters implement
|
|
27
|
+
*/
|
|
28
|
+
export interface ToolAdapter<TFrameworkTool> {
|
|
29
|
+
/**
|
|
30
|
+
* Convert a bigtool-ts metadata to framework-specific tool
|
|
31
|
+
*/
|
|
32
|
+
toFrameworkTool(metadata: ToolMetadata): TFrameworkTool;
|
|
33
|
+
/**
|
|
34
|
+
* Get tools by IDs, converted to framework format
|
|
35
|
+
*/
|
|
36
|
+
getTools(toolIds: string[]): Promise<TFrameworkTool[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Create a search tool in framework format
|
|
39
|
+
*/
|
|
40
|
+
createSearchTool(options?: SearchToolOptions): TFrameworkTool;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,cAAc;IACzC;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,cAAc,CAAC;IAExD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEvD;;OAEG;IACH,gBAAgB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAAC;CAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel AI SDK adapter for bigtool-ts.
|
|
3
|
+
*
|
|
4
|
+
* Converts bigtool-ts tools to Vercel AI SDK format for use with
|
|
5
|
+
* generateText(), streamText(), and other SDK functions.
|
|
6
|
+
*
|
|
7
|
+
* @module adapters/vercel-ai
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolMetadata } from '../types.js';
|
|
10
|
+
import type { AdapterConfig, ToolAdapter, SearchToolOptions } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Options passed to tool execute functions.
|
|
13
|
+
* Matches the ToolExecutionOptions from 'ai' package.
|
|
14
|
+
*/
|
|
15
|
+
interface ToolExecutionOptions {
|
|
16
|
+
/** The ID of the tool call */
|
|
17
|
+
toolCallId: string;
|
|
18
|
+
/** Abort signal for cancellation */
|
|
19
|
+
abortSignal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Vercel AI SDK Tool type.
|
|
23
|
+
*
|
|
24
|
+
* This is a simplified version of the Tool type from the 'ai' package.
|
|
25
|
+
* We define it here to avoid runtime dependencies on the 'ai' package
|
|
26
|
+
* while maintaining type compatibility.
|
|
27
|
+
*
|
|
28
|
+
* @see https://github.com/vercel/ai - Full type definition
|
|
29
|
+
*/
|
|
30
|
+
interface VercelTool<INPUT = unknown, OUTPUT = unknown> {
|
|
31
|
+
/** Description for the language model */
|
|
32
|
+
description?: string;
|
|
33
|
+
/** Schema for tool input */
|
|
34
|
+
inputSchema: unknown;
|
|
35
|
+
/** Execute function */
|
|
36
|
+
execute?: (input: INPUT, options: ToolExecutionOptions) => Promise<OUTPUT> | OUTPUT;
|
|
37
|
+
/** Output schema for validation */
|
|
38
|
+
outputSchema?: unknown;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A record of tools keyed by name (ToolSet in Vercel AI SDK).
|
|
42
|
+
*/
|
|
43
|
+
type ToolSet = Record<string, VercelTool>;
|
|
44
|
+
/**
|
|
45
|
+
* Vercel AI SDK adapter for bigtool-ts.
|
|
46
|
+
*
|
|
47
|
+
* Converts bigtool-ts tools to Vercel AI SDK format. Tools are lazily
|
|
48
|
+
* loaded when executed, and the adapter handles abort signal propagation.
|
|
49
|
+
*
|
|
50
|
+
* @example Basic usage with streamText
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { streamText } from 'ai';
|
|
53
|
+
* import { openai } from '@ai-sdk/openai';
|
|
54
|
+
* import { createVercelAdapter } from '@repo/bigtool-ts/adapters';
|
|
55
|
+
*
|
|
56
|
+
* const adapter = createVercelAdapter({ catalog, loader, searchIndex });
|
|
57
|
+
*
|
|
58
|
+
* const result = await streamText({
|
|
59
|
+
* model: openai('gpt-4o'),
|
|
60
|
+
* tools: {
|
|
61
|
+
* search_tools: adapter.createSearchTool(),
|
|
62
|
+
* ...await adapter.getToolsAsRecord(['github:create_pr']),
|
|
63
|
+
* },
|
|
64
|
+
* prompt: 'Create a PR with title "Fix bug"',
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example With search tool for dynamic discovery
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const result = await generateText({
|
|
71
|
+
* model: openai('gpt-4o'),
|
|
72
|
+
* tools: {
|
|
73
|
+
* search_tools: adapter.createSearchTool({ limit: 10 }),
|
|
74
|
+
* },
|
|
75
|
+
* prompt: 'What tools are available for GitHub?',
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare class VercelAIAdapter implements ToolAdapter<VercelTool> {
|
|
80
|
+
private readonly catalog;
|
|
81
|
+
private readonly loader;
|
|
82
|
+
private readonly searchIndex;
|
|
83
|
+
constructor(config: AdapterConfig);
|
|
84
|
+
/**
|
|
85
|
+
* Convert bigtool-ts metadata to a Vercel AI SDK tool.
|
|
86
|
+
*
|
|
87
|
+
* The returned tool lazily loads the implementation on first execute.
|
|
88
|
+
* Abort signals are checked before loading to fail fast on cancellation.
|
|
89
|
+
*
|
|
90
|
+
* @param metadata - Tool metadata from the catalog
|
|
91
|
+
* @returns Vercel AI SDK compatible tool
|
|
92
|
+
*/
|
|
93
|
+
toFrameworkTool(metadata: ToolMetadata): VercelTool;
|
|
94
|
+
/**
|
|
95
|
+
* Get tools by IDs as an array.
|
|
96
|
+
*
|
|
97
|
+
* Missing tools are silently skipped. Use this when you need an array
|
|
98
|
+
* of tools and don't care about the tool names.
|
|
99
|
+
*
|
|
100
|
+
* @param toolIds - Array of tool IDs to load
|
|
101
|
+
* @returns Array of Vercel AI SDK tools
|
|
102
|
+
*/
|
|
103
|
+
getTools(toolIds: string[]): Promise<VercelTool[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Get tools by IDs as a record (ToolSet).
|
|
106
|
+
*
|
|
107
|
+
* The record keys are the tool names from metadata. Missing tools are
|
|
108
|
+
* silently skipped. Use this for passing to generateText/streamText.
|
|
109
|
+
*
|
|
110
|
+
* @param toolIds - Array of tool IDs to load
|
|
111
|
+
* @returns Record of tools keyed by name
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const tools = await adapter.getToolsAsRecord([
|
|
116
|
+
* 'github:create_pr',
|
|
117
|
+
* 'slack:send_message',
|
|
118
|
+
* ]);
|
|
119
|
+
*
|
|
120
|
+
* const result = await streamText({
|
|
121
|
+
* model: openai('gpt-4o'),
|
|
122
|
+
* tools,
|
|
123
|
+
* prompt: 'Create a PR and notify the team',
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
getToolsAsRecord(toolIds: string[]): Promise<ToolSet>;
|
|
128
|
+
/**
|
|
129
|
+
* Create a search tool for discovering available tools.
|
|
130
|
+
*
|
|
131
|
+
* The search tool enables dynamic tool discovery in agentic workflows.
|
|
132
|
+
* The LLM can use this tool to find relevant tools before calling them.
|
|
133
|
+
*
|
|
134
|
+
* @param options - Search configuration options
|
|
135
|
+
* @returns Vercel AI SDK tool for searching the catalog
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const searchTool = adapter.createSearchTool({
|
|
140
|
+
* limit: 5,
|
|
141
|
+
* threshold: 0.3,
|
|
142
|
+
* categories: ['github'],
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* const result = await generateText({
|
|
146
|
+
* model: openai('gpt-4o'),
|
|
147
|
+
* tools: { search_tools: searchTool },
|
|
148
|
+
* prompt: 'Find tools for creating pull requests',
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
createSearchTool(options?: SearchToolOptions): VercelTool;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a Vercel AI SDK adapter.
|
|
156
|
+
*
|
|
157
|
+
* Factory function for creating a VercelAIAdapter instance.
|
|
158
|
+
* Use this as the primary entry point for creating adapters.
|
|
159
|
+
*
|
|
160
|
+
* @param config - Adapter configuration with catalog, loader, and searchIndex
|
|
161
|
+
* @returns Configured VercelAIAdapter instance
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { createVercelAdapter } from '@repo/bigtool-ts/adapters';
|
|
166
|
+
*
|
|
167
|
+
* const adapter = createVercelAdapter({
|
|
168
|
+
* catalog: new DefaultToolCatalog(),
|
|
169
|
+
* loader: new DefaultToolLoader(catalog),
|
|
170
|
+
* searchIndex: new OramaSearch(),
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function createVercelAdapter(config: AdapterConfig): VercelAIAdapter;
|
|
175
|
+
export {};
|
|
176
|
+
//# sourceMappingURL=vercel-ai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../src/adapters/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMhF;;;GAGG;AACH,UAAU,oBAAoB;IAC5B,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,UAAU,UAAU,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO;IACpD,yCAAyC;IACzC,WAAW,CAA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