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,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inngest AgentKit adapter for bigtool-ts.
|
|
3
|
+
*
|
|
4
|
+
* Converts bigtool-ts tools to Inngest AgentKit format and provides
|
|
5
|
+
* search tools for dynamic tool discovery.
|
|
6
|
+
*
|
|
7
|
+
* @module adapters/inngest
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createInngestAdapter } from '@repo/bigtool-ts/adapters';
|
|
12
|
+
* import { createAgent, openai } from '@inngest/agent-kit';
|
|
13
|
+
*
|
|
14
|
+
* const adapter = createInngestAdapter({ catalog, loader, searchIndex });
|
|
15
|
+
*
|
|
16
|
+
* const agent = createAgent({
|
|
17
|
+
* name: 'tool-user',
|
|
18
|
+
* model: openai({ model: 'gpt-4o' }),
|
|
19
|
+
* tools: [
|
|
20
|
+
* adapter.createSearchTool(),
|
|
21
|
+
* adapter.createCallToolTool(),
|
|
22
|
+
* ],
|
|
23
|
+
* system: 'You are a helpful assistant...',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { z } from 'zod';
|
|
28
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
29
|
+
// ADAPTER IMPLEMENTATION
|
|
30
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
31
|
+
/**
|
|
32
|
+
* Inngest AgentKit adapter for bigtool-ts.
|
|
33
|
+
*
|
|
34
|
+
* Implements the ToolAdapter interface to convert bigtool-ts tools
|
|
35
|
+
* to Inngest AgentKit format. Provides additional tools for dynamic
|
|
36
|
+
* tool discovery and execution.
|
|
37
|
+
*
|
|
38
|
+
* Key features:
|
|
39
|
+
* - Automatic durable execution wrapping via step.run()
|
|
40
|
+
* - Search tool for runtime tool discovery
|
|
41
|
+
* - Call tool for executing discovered tools by name
|
|
42
|
+
*
|
|
43
|
+
* @example Basic usage
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const adapter = createInngestAdapter({ catalog, loader, searchIndex });
|
|
46
|
+
*
|
|
47
|
+
* // Get specific tools by ID
|
|
48
|
+
* const tools = await adapter.getTools(['github:create_pr', 'slack:send']);
|
|
49
|
+
*
|
|
50
|
+
* // Create discovery tools
|
|
51
|
+
* const searchTool = adapter.createSearchTool({ limit: 5 });
|
|
52
|
+
* const callTool = adapter.createCallToolTool();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export class InngestAdapter {
|
|
56
|
+
catalog;
|
|
57
|
+
loader;
|
|
58
|
+
searchIndex;
|
|
59
|
+
constructor(config) {
|
|
60
|
+
this.catalog = config.catalog;
|
|
61
|
+
this.loader = config.loader;
|
|
62
|
+
this.searchIndex = config.searchIndex;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert bigtool-ts metadata to an Inngest AgentKit tool.
|
|
66
|
+
*
|
|
67
|
+
* The resulting tool wraps the bigtool-ts loader and automatically
|
|
68
|
+
* uses step.run() for durable execution when available.
|
|
69
|
+
*
|
|
70
|
+
* **Note:** Parameter schemas are not converted from ToolMetadata to Zod.
|
|
71
|
+
* The underlying bigtool-ts tool handles its own input validation.
|
|
72
|
+
* If you need Inngest-side schema validation, provide tools with Zod
|
|
73
|
+
* schemas directly rather than using the adapter.
|
|
74
|
+
*
|
|
75
|
+
* @param metadata - Tool metadata from the catalog
|
|
76
|
+
* @returns Inngest-compatible tool
|
|
77
|
+
*/
|
|
78
|
+
toFrameworkTool(metadata) {
|
|
79
|
+
const loader = this.loader;
|
|
80
|
+
// Note: We don't convert metadata.parameters (JSON Schema) to Zod because
|
|
81
|
+
// the conversion is complex and error-prone. The underlying tool validates
|
|
82
|
+
// its own input. If Zod schemas are needed, use createTool directly.
|
|
83
|
+
return {
|
|
84
|
+
name: metadata.name,
|
|
85
|
+
description: metadata.description,
|
|
86
|
+
parameters: undefined,
|
|
87
|
+
handler: async (input, opts) => {
|
|
88
|
+
const execute = async () => {
|
|
89
|
+
const tool = await loader.load(metadata.id);
|
|
90
|
+
return tool.invoke(input);
|
|
91
|
+
};
|
|
92
|
+
// Use step.run for durable execution when available
|
|
93
|
+
if (opts.step) {
|
|
94
|
+
return opts.step.run(`bigtool:${metadata.name}`, execute);
|
|
95
|
+
}
|
|
96
|
+
return execute();
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get multiple tools by their IDs.
|
|
102
|
+
*
|
|
103
|
+
* Tools not found in the catalog are silently skipped.
|
|
104
|
+
* Use this when you know which tools you need ahead of time.
|
|
105
|
+
*
|
|
106
|
+
* @param toolIds - Array of tool IDs to retrieve
|
|
107
|
+
* @returns Array of Inngest-compatible tools
|
|
108
|
+
*/
|
|
109
|
+
async getTools(toolIds) {
|
|
110
|
+
const tools = [];
|
|
111
|
+
for (const id of toolIds) {
|
|
112
|
+
const metadata = this.catalog.getMetadata(id);
|
|
113
|
+
if (metadata) {
|
|
114
|
+
tools.push(this.toFrameworkTool(metadata));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return tools;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get all tools from the catalog.
|
|
121
|
+
*
|
|
122
|
+
* Use sparingly - prefer getTools() or createSearchTool() for
|
|
123
|
+
* large catalogs.
|
|
124
|
+
*
|
|
125
|
+
* @returns Array of all Inngest-compatible tools
|
|
126
|
+
*/
|
|
127
|
+
async getAllTools() {
|
|
128
|
+
const allMetadata = this.catalog.getAllMetadata();
|
|
129
|
+
return allMetadata.map((m) => this.toFrameworkTool(m));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get tools filtered by category.
|
|
133
|
+
*
|
|
134
|
+
* @param categories - Categories to filter by (matches any)
|
|
135
|
+
* @returns Array of matching Inngest-compatible tools
|
|
136
|
+
*/
|
|
137
|
+
async getToolsByCategory(categories) {
|
|
138
|
+
const allMetadata = this.catalog.getAllMetadata();
|
|
139
|
+
const filtered = allMetadata.filter((m) => m.categories?.some((c) => categories.includes(c)));
|
|
140
|
+
return filtered.map((m) => this.toFrameworkTool(m));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create a search tool for discovering available tools.
|
|
144
|
+
*
|
|
145
|
+
* This is the core tool for dynamic tool discovery. The agent
|
|
146
|
+
* can search for tools by natural language query and get back
|
|
147
|
+
* matching tool names and descriptions.
|
|
148
|
+
*
|
|
149
|
+
* @param options - Search options (limit, threshold, categories)
|
|
150
|
+
* @returns Inngest-compatible search tool
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const searchTool = adapter.createSearchTool({ limit: 5 });
|
|
155
|
+
* // Agent calls: search_tools({ query: "create github pr" })
|
|
156
|
+
* // Returns: [{ name: "create_pr", description: "...", score: 0.95 }]
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
createSearchTool(options = {}) {
|
|
160
|
+
const { limit = 5, threshold = 0, categories } = options;
|
|
161
|
+
const searchIndex = this.searchIndex;
|
|
162
|
+
const catalog = this.catalog;
|
|
163
|
+
return {
|
|
164
|
+
name: 'search_tools',
|
|
165
|
+
description: 'Search for available tools by query. Use this to discover what tools are available before calling them. Returns tool names and descriptions.',
|
|
166
|
+
parameters: z.object({
|
|
167
|
+
query: z
|
|
168
|
+
.string()
|
|
169
|
+
.describe('Natural language search query describing what you want to do'),
|
|
170
|
+
}),
|
|
171
|
+
handler: async (input, opts) => {
|
|
172
|
+
const { query } = input;
|
|
173
|
+
const execute = async () => {
|
|
174
|
+
const results = await searchIndex.search(query, {
|
|
175
|
+
limit,
|
|
176
|
+
threshold,
|
|
177
|
+
categories,
|
|
178
|
+
});
|
|
179
|
+
return results.map((r) => {
|
|
180
|
+
const meta = catalog.getMetadata(r.toolId);
|
|
181
|
+
return {
|
|
182
|
+
name: meta?.name ?? r.toolId,
|
|
183
|
+
description: meta?.description ?? '',
|
|
184
|
+
score: r.score,
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
// Wrap in step.run for durability when available
|
|
189
|
+
if (opts.step) {
|
|
190
|
+
return opts.step.run('bigtool:search_tools', execute);
|
|
191
|
+
}
|
|
192
|
+
return execute();
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create a tool for executing discovered tools by name.
|
|
198
|
+
*
|
|
199
|
+
* Use this in combination with createSearchTool() to enable
|
|
200
|
+
* dynamic tool discovery and execution patterns.
|
|
201
|
+
*
|
|
202
|
+
* **Note:** Tool lookup uses name matching. If multiple tools share the
|
|
203
|
+
* same name (from different sources), the first match wins. Ensure tool
|
|
204
|
+
* names are unique within your catalog to avoid ambiguity.
|
|
205
|
+
*
|
|
206
|
+
* @returns Inngest-compatible call tool
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const callTool = adapter.createCallToolTool();
|
|
211
|
+
* // Agent calls: call_tool({ toolName: "create_pr", arguments: { title: "..." } })
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
createCallToolTool() {
|
|
215
|
+
const loader = this.loader;
|
|
216
|
+
const catalog = this.catalog;
|
|
217
|
+
return {
|
|
218
|
+
name: 'call_tool',
|
|
219
|
+
description: 'Call a tool by name with the given arguments. Use this after discovering tools via search_tools.',
|
|
220
|
+
parameters: z.object({
|
|
221
|
+
toolName: z.string().describe('The name of the tool to call'),
|
|
222
|
+
arguments: z.record(z.unknown()).describe('Arguments to pass to the tool'),
|
|
223
|
+
}),
|
|
224
|
+
handler: async (input, opts) => {
|
|
225
|
+
const { toolName, arguments: args } = input;
|
|
226
|
+
const execute = async () => {
|
|
227
|
+
// Find the tool by name
|
|
228
|
+
const allMetadata = catalog.getAllMetadata();
|
|
229
|
+
const metadata = allMetadata.find((m) => m.name === toolName);
|
|
230
|
+
if (!metadata) {
|
|
231
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
232
|
+
}
|
|
233
|
+
const tool = await loader.load(metadata.id);
|
|
234
|
+
return tool.invoke(args);
|
|
235
|
+
};
|
|
236
|
+
// Wrap in step.run for durability when available
|
|
237
|
+
if (opts.step) {
|
|
238
|
+
return opts.step.run(`bigtool:call:${toolName}`, execute);
|
|
239
|
+
}
|
|
240
|
+
return execute();
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
246
|
+
// FACTORY FUNCTION
|
|
247
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
248
|
+
/**
|
|
249
|
+
* Create an Inngest AgentKit adapter.
|
|
250
|
+
*
|
|
251
|
+
* Factory function for creating InngestAdapter instances. Use this
|
|
252
|
+
* as the primary entry point for the adapter.
|
|
253
|
+
*
|
|
254
|
+
* @param config - Adapter configuration with catalog, loader, and search index
|
|
255
|
+
* @returns Configured InngestAdapter instance
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* import { createInngestAdapter } from '@repo/bigtool-ts/adapters';
|
|
260
|
+
* import { DefaultToolCatalog, OramaSearch, DefaultToolLoader } from '@repo/bigtool-ts';
|
|
261
|
+
*
|
|
262
|
+
* const catalog = new DefaultToolCatalog();
|
|
263
|
+
* await catalog.register(new LocalSource(myTools));
|
|
264
|
+
*
|
|
265
|
+
* const searchIndex = new OramaSearch();
|
|
266
|
+
* await searchIndex.index(catalog.getAllMetadata());
|
|
267
|
+
*
|
|
268
|
+
* const loader = new DefaultToolLoader(catalog);
|
|
269
|
+
*
|
|
270
|
+
* const adapter = createInngestAdapter({ catalog, loader, searchIndex });
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export function createInngestAdapter(config) {
|
|
274
|
+
return new InngestAdapter(config);
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=inngest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inngest.js","sourceRoot":"","sources":["../../src/adapters/inngest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsExB,sEAAsE;AACtE,yBAAyB;AACzB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAA2B;IAClC,MAAM,CAA0B;IAChC,WAAW,CAA+B;IAE3D,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,QAAsB;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE3B,0EAA0E;QAC1E,2EAA2E;QAC3E,qEA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,CAAC;oBAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;oBAE9D,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;oBACjD,CAAC;oBAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;oBAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC3B,CAAC,CAAC;gBAEF,iDAAiD;gBACjD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACd,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;gBAC5D,CAAC;gBACD,OAAO,OAAO,EAAE,CAAC;YACnB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAkBD,sEAAsE;AACtE,mBAAmB;AACnB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAqB;IACxD,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
import type { ToolMetadata } from '../types.js';
|
|
30
|
+
import type { AdapterConfig, ToolAdapter, SearchToolOptions } from './types.js';
|
|
31
|
+
/**
|
|
32
|
+
* Mastra tool execution context.
|
|
33
|
+
*
|
|
34
|
+
* Provides access to Mastra runtime services during tool execution.
|
|
35
|
+
* All properties are optional to handle various execution contexts.
|
|
36
|
+
*/
|
|
37
|
+
export interface MastraToolContext {
|
|
38
|
+
/** Mastra runtime instance for accessing services */
|
|
39
|
+
mastra?: unknown;
|
|
40
|
+
/** Request context for HTTP-triggered executions */
|
|
41
|
+
requestContext?: unknown;
|
|
42
|
+
/** Tracing context for observability */
|
|
43
|
+
tracingContext?: unknown;
|
|
44
|
+
/** Abort signal for cancellation support */
|
|
45
|
+
abortSignal?: AbortSignal;
|
|
46
|
+
/** Agent-specific context (suspend/resume support) */
|
|
47
|
+
agent?: unknown;
|
|
48
|
+
/** Workflow-specific context */
|
|
49
|
+
workflow?: unknown;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Mastra tool definition shape.
|
|
53
|
+
*
|
|
54
|
+
* This matches the output of `createTool()` from `@mastra/core/tools`.
|
|
55
|
+
*
|
|
56
|
+
* Key differences from other frameworks:
|
|
57
|
+
* - Uses `id` only (no `name` property)
|
|
58
|
+
* - Execute signature: `(inputData, context?)` NOT `({ input })`
|
|
59
|
+
* - Context is optional second parameter
|
|
60
|
+
*/
|
|
61
|
+
export interface MastraTool<TInput = unknown, TOutput = unknown> {
|
|
62
|
+
/** Unique identifier for the tool */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Description of what the tool does */
|
|
65
|
+
description: string;
|
|
66
|
+
/** Zod schema for input validation */
|
|
67
|
+
inputSchema: z.ZodSchema<TInput>;
|
|
68
|
+
/** Zod schema for output validation (null if not specified) */
|
|
69
|
+
outputSchema: z.ZodSchema<TOutput> | undefined;
|
|
70
|
+
/** Tool execution function */
|
|
71
|
+
execute: (inputData: TInput, context?: MastraToolContext) => Promise<TOutput>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Adapter for converting bigtool-ts tools to Mastra format.
|
|
75
|
+
*
|
|
76
|
+
* Implements the `ToolAdapter` interface for Mastra framework
|
|
77
|
+
* compatibility. Provides both array and record output formats
|
|
78
|
+
* to match Mastra's agent API expectations.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const adapter = new MastraAdapter({ catalog, loader, searchIndex });
|
|
83
|
+
*
|
|
84
|
+
* // Get tools as array
|
|
85
|
+
* const tools = await adapter.getTools(['github:create_pr']);
|
|
86
|
+
*
|
|
87
|
+
* // Get tools as Record for Agent constructor
|
|
88
|
+
* const toolRecord = await adapter.getToolsAsRecord(['github:create_pr']);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare class MastraAdapter implements ToolAdapter<MastraTool> {
|
|
92
|
+
private readonly catalog;
|
|
93
|
+
private readonly loader;
|
|
94
|
+
private readonly searchIndex;
|
|
95
|
+
constructor(config: AdapterConfig);
|
|
96
|
+
/**
|
|
97
|
+
* Convert bigtool-ts metadata to a Mastra tool.
|
|
98
|
+
*
|
|
99
|
+
* Creates a Mastra-compatible tool definition that lazily loads
|
|
100
|
+
* and executes the underlying bigtool-ts tool implementation.
|
|
101
|
+
*
|
|
102
|
+
* @param metadata - Tool metadata from the catalog
|
|
103
|
+
* @returns Mastra tool definition
|
|
104
|
+
*/
|
|
105
|
+
toFrameworkTool(metadata: ToolMetadata): MastraTool;
|
|
106
|
+
/**
|
|
107
|
+
* Get tools by IDs as an array.
|
|
108
|
+
*
|
|
109
|
+
* Converts each tool from bigtool-ts format to Mastra format.
|
|
110
|
+
* Tools not found in the catalog are silently skipped.
|
|
111
|
+
*
|
|
112
|
+
* @param toolIds - Array of tool IDs to retrieve
|
|
113
|
+
* @returns Array of Mastra tools
|
|
114
|
+
*/
|
|
115
|
+
getTools(toolIds: string[]): Promise<MastraTool[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Get tools as a Record for Mastra Agent constructor.
|
|
118
|
+
*
|
|
119
|
+
* Mastra agents expect tools in `Record<string, Tool>` format.
|
|
120
|
+
* Uses the tool name (last segment of ID) as the record key.
|
|
121
|
+
*
|
|
122
|
+
* @param toolIds - Array of tool IDs to retrieve
|
|
123
|
+
* @returns Record of tool name to Mastra tool
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const tools = await adapter.getToolsAsRecord(['github:create_pr']);
|
|
128
|
+
* // Returns: { create_pr: MastraTool }
|
|
129
|
+
*
|
|
130
|
+
* const agent = new Agent({
|
|
131
|
+
* tools: {
|
|
132
|
+
* search: adapter.createSearchTool(),
|
|
133
|
+
* ...tools,
|
|
134
|
+
* },
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
getToolsAsRecord(toolIds: string[]): Promise<Record<string, MastraTool>>;
|
|
139
|
+
/**
|
|
140
|
+
* Create a search tool for discovering available tools.
|
|
141
|
+
*
|
|
142
|
+
* Returns a Mastra tool that agents can use to search the
|
|
143
|
+
* bigtool-ts catalog using natural language queries.
|
|
144
|
+
*
|
|
145
|
+
* @param options - Search configuration options
|
|
146
|
+
* @returns Mastra search tool
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const agent = new Agent({
|
|
151
|
+
* tools: {
|
|
152
|
+
* search_tools: adapter.createSearchTool({ limit: 10 }),
|
|
153
|
+
* },
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
createSearchTool(options?: SearchToolOptions): MastraTool;
|
|
158
|
+
/**
|
|
159
|
+
* Extract the tool key from a fully-qualified tool ID.
|
|
160
|
+
*
|
|
161
|
+
* For IDs like 'github:create_pr', returns 'create_pr'.
|
|
162
|
+
* For IDs without a namespace, returns the full ID.
|
|
163
|
+
*/
|
|
164
|
+
private extractToolKey;
|
|
165
|
+
/**
|
|
166
|
+
* Build a Zod schema from JSON Schema parameters.
|
|
167
|
+
*
|
|
168
|
+
* Returns a permissive schema that accepts any object shape.
|
|
169
|
+
* Validation is delegated to the underlying bigtool-ts tool,
|
|
170
|
+
* avoiding the complexity of JSON Schema to Zod conversion.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* Converting JSON Schema to Zod at runtime would require a
|
|
174
|
+
* library like `json-schema-to-zod`. Since bigtool-ts tools
|
|
175
|
+
* perform their own validation, this passthrough approach
|
|
176
|
+
* avoids that dependency while maintaining compatibility.
|
|
177
|
+
*/
|
|
178
|
+
private buildInputSchema;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a Mastra adapter for bigtool-ts.
|
|
182
|
+
*
|
|
183
|
+
* Factory function that creates a configured `MastraAdapter` instance.
|
|
184
|
+
*
|
|
185
|
+
* @param config - Adapter configuration with catalog, loader, and search index
|
|
186
|
+
* @returns Configured Mastra adapter
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* import { createMastraAdapter } from '@repo/bigtool-ts/adapters';
|
|
191
|
+
* import { DefaultToolCatalog, DefaultToolLoader, OramaSearch } from '@repo/bigtool-ts';
|
|
192
|
+
*
|
|
193
|
+
* const catalog = new DefaultToolCatalog();
|
|
194
|
+
* const loader = new DefaultToolLoader(catalog);
|
|
195
|
+
* const searchIndex = new OramaSearch();
|
|
196
|
+
*
|
|
197
|
+
* const adapter = createMastraAdapter({ catalog, loader, searchIndex });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare function createMastraAdapter(config: AdapterConfig): MastraAdapter;
|
|
201
|
+
//# sourceMappingURL=mastra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.d.ts","sourceRoot":"","sources":["../../src/adapters/mastra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMhF;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,wCAAwC;IACxC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC7D,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,WAAW,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,+DAA+D;IAC/D,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/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