@mastra/editor 0.3.0 → 0.4.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 +210 -0
- package/dist/arcade.cjs +293 -0
- package/dist/arcade.d.cts +66 -0
- package/dist/arcade.d.ts +66 -0
- package/dist/arcade.js +266 -0
- package/dist/composio.cjs +143 -0
- package/dist/composio.d.cts +59 -0
- package/dist/composio.d.ts +59 -0
- package/dist/composio.js +116 -0
- package/dist/index.cjs +238 -12
- package/dist/index.d.cts +57 -7
- package/dist/index.d.ts +57 -7
- package/dist/index.js +226 -11
- package/package.json +50 -9
package/dist/arcade.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// src/providers/arcade.ts
|
|
2
|
+
import { Arcade } from "@arcadeai/arcadejs";
|
|
3
|
+
import { toZodToolSet, executeOrAuthorizeZodTool } from "@arcadeai/arcadejs/lib/index";
|
|
4
|
+
var KNOWN_TOOLKITS = [
|
|
5
|
+
{ slug: "AirtableApi", name: "Airtable API", category: "productivity" },
|
|
6
|
+
{ slug: "ArcadeEngineApi", name: "Arcade Engine API", category: "development" },
|
|
7
|
+
{ slug: "Asana", name: "Asana", category: "productivity" },
|
|
8
|
+
{ slug: "AsanaApi", name: "Asana API", category: "productivity" },
|
|
9
|
+
{ slug: "AshbyApi", name: "Ashby API", category: "productivity" },
|
|
10
|
+
{ slug: "Attio", name: "Attio", category: "sales" },
|
|
11
|
+
{ slug: "BoxApi", name: "Box API", category: "productivity" },
|
|
12
|
+
{ slug: "Brightdata", name: "Bright Data", category: "development" },
|
|
13
|
+
{ slug: "CalendlyApi", name: "Calendly API", category: "productivity" },
|
|
14
|
+
{ slug: "Clickup", name: "ClickUp", category: "productivity" },
|
|
15
|
+
{ slug: "ClickupApi", name: "ClickUp API", category: "productivity" },
|
|
16
|
+
{ slug: "Confluence", name: "Confluence", category: "productivity" },
|
|
17
|
+
{ slug: "CursorAgentsApi", name: "Cursor Agents API", category: "development" },
|
|
18
|
+
{ slug: "CustomerioApi", name: "Customer.io API", category: "customer-support" },
|
|
19
|
+
{ slug: "CustomerioPipelinesApi", name: "Customer.io Pipelines API", category: "customer-support" },
|
|
20
|
+
{ slug: "CustomerioTrackApi", name: "Customer.io Track API", category: "customer-support" },
|
|
21
|
+
{ slug: "DatadogApi", name: "Datadog API", category: "development" },
|
|
22
|
+
{ slug: "Dropbox", name: "Dropbox", category: "productivity" },
|
|
23
|
+
{ slug: "E2b", name: "E2B", category: "development" },
|
|
24
|
+
{ slug: "ExaApi", name: "Exa API", category: "search" },
|
|
25
|
+
{ slug: "Figma", name: "Figma", category: "productivity" },
|
|
26
|
+
{ slug: "FigmaApi", name: "Figma API", category: "productivity" },
|
|
27
|
+
{ slug: "Firecrawl", name: "Firecrawl", category: "development" },
|
|
28
|
+
{ slug: "FreshserviceApi", name: "Freshservice API", category: "customer-support" },
|
|
29
|
+
{ slug: "Github", name: "GitHub", category: "development" },
|
|
30
|
+
{ slug: "GithubApi", name: "GitHub API", category: "development" },
|
|
31
|
+
{ slug: "Gmail", name: "Gmail", category: "productivity" },
|
|
32
|
+
{ slug: "Google", name: "Google", category: "search" },
|
|
33
|
+
{ slug: "GoogleCalendar", name: "Google Calendar", category: "productivity" },
|
|
34
|
+
{ slug: "GoogleContacts", name: "Google Contacts", category: "productivity" },
|
|
35
|
+
{ slug: "GoogleDocs", name: "Google Docs", category: "productivity" },
|
|
36
|
+
{ slug: "GoogleDrive", name: "Google Drive", category: "productivity" },
|
|
37
|
+
{ slug: "GoogleFinance", name: "Google Finance", category: "search" },
|
|
38
|
+
{ slug: "GoogleFlights", name: "Google Flights", category: "search" },
|
|
39
|
+
{ slug: "GoogleHotels", name: "Google Hotels", category: "search" },
|
|
40
|
+
{ slug: "GoogleJobs", name: "Google Jobs", category: "search" },
|
|
41
|
+
{ slug: "GoogleMaps", name: "Google Maps", category: "search" },
|
|
42
|
+
{ slug: "GoogleNews", name: "Google News", category: "search" },
|
|
43
|
+
{ slug: "GoogleSearch", name: "Google Search", category: "search" },
|
|
44
|
+
{ slug: "GoogleSheets", name: "Google Sheets", category: "productivity" },
|
|
45
|
+
{ slug: "GoogleShopping", name: "Google Shopping", category: "search" },
|
|
46
|
+
{ slug: "GoogleSlides", name: "Google Slides", category: "productivity" },
|
|
47
|
+
{ slug: "Hubspot", name: "HubSpot", category: "sales" },
|
|
48
|
+
{ slug: "HubspotAutomationApi", name: "HubSpot Automation API", category: "sales" },
|
|
49
|
+
{ slug: "HubspotCmsApi", name: "HubSpot CMS API", category: "sales" },
|
|
50
|
+
{ slug: "HubspotConversationsApi", name: "HubSpot Conversations API", category: "sales" },
|
|
51
|
+
{ slug: "HubspotCrmApi", name: "HubSpot CRM API", category: "sales" },
|
|
52
|
+
{ slug: "HubspotEventsApi", name: "HubSpot Events API", category: "sales" },
|
|
53
|
+
{ slug: "HubspotMarketingApi", name: "HubSpot Marketing API", category: "sales" },
|
|
54
|
+
{ slug: "HubspotMeetingsApi", name: "HubSpot Meetings API", category: "sales" },
|
|
55
|
+
{ slug: "HubspotUsersApi", name: "HubSpot Users API", category: "sales" },
|
|
56
|
+
{ slug: "Imgflip", name: "Imgflip", category: "entertainment" },
|
|
57
|
+
{ slug: "IntercomApi", name: "Intercom API", category: "customer-support" },
|
|
58
|
+
{ slug: "Jira", name: "Jira", category: "productivity" },
|
|
59
|
+
{ slug: "Linear", name: "Linear", category: "productivity" },
|
|
60
|
+
{ slug: "Linkedin", name: "LinkedIn", category: "social" },
|
|
61
|
+
{ slug: "LumaApi", name: "Luma API", category: "productivity" },
|
|
62
|
+
{ slug: "MailchimpMarketingApi", name: "Mailchimp API", category: "productivity" },
|
|
63
|
+
{ slug: "Math", name: "Math", category: "utility" },
|
|
64
|
+
{ slug: "Microsoft", name: "Microsoft", category: "productivity" },
|
|
65
|
+
{ slug: "MicrosoftOnedrive", name: "Microsoft OneDrive", category: "productivity" },
|
|
66
|
+
{ slug: "MicrosoftTeams", name: "Microsoft Teams", category: "social" },
|
|
67
|
+
{ slug: "MicrosoftWord", name: "Microsoft Word", category: "productivity" },
|
|
68
|
+
{ slug: "MiroApi", name: "Miro API", category: "productivity" },
|
|
69
|
+
{ slug: "NotionToolkit", name: "Notion", category: "productivity" },
|
|
70
|
+
{ slug: "OutlookCalendar", name: "Outlook Calendar", category: "productivity" },
|
|
71
|
+
{ slug: "OutlookMail", name: "Outlook Mail", category: "productivity" },
|
|
72
|
+
{ slug: "Pagerduty", name: "PagerDuty", category: "development" },
|
|
73
|
+
{ slug: "PagerdutyApi", name: "PagerDuty API", category: "development" },
|
|
74
|
+
{ slug: "PosthogApi", name: "PostHog API", category: "development" },
|
|
75
|
+
{ slug: "Pylon", name: "Pylon", category: "customer-support" },
|
|
76
|
+
{ slug: "PylonApi", name: "Pylon API", category: "customer-support" },
|
|
77
|
+
{ slug: "Reddit", name: "Reddit", category: "social" },
|
|
78
|
+
{ slug: "Salesforce", name: "Salesforce", category: "sales" },
|
|
79
|
+
{ slug: "Sharepoint", name: "Microsoft SharePoint", category: "productivity" },
|
|
80
|
+
{ slug: "Slack", name: "Slack", category: "social" },
|
|
81
|
+
{ slug: "SlackApi", name: "Slack API", category: "social" },
|
|
82
|
+
{ slug: "Spotify", name: "Spotify", category: "entertainment" },
|
|
83
|
+
{ slug: "SquareupApi", name: "SquareUp API", category: "productivity" },
|
|
84
|
+
{ slug: "Stripe", name: "Stripe", category: "payments" },
|
|
85
|
+
{ slug: "StripeApi", name: "Stripe API", category: "payments" },
|
|
86
|
+
{ slug: "TicktickApi", name: "TickTick API", category: "productivity" },
|
|
87
|
+
{ slug: "TrelloApi", name: "Trello API", category: "productivity" },
|
|
88
|
+
{ slug: "Twilio", name: "Twilio", category: "social" },
|
|
89
|
+
{ slug: "VercelApi", name: "Vercel API", category: "development" },
|
|
90
|
+
{ slug: "Walmart", name: "Walmart", category: "search" },
|
|
91
|
+
{ slug: "WeaviateApi", name: "Weaviate API", category: "development" },
|
|
92
|
+
{ slug: "X", name: "X", category: "social" },
|
|
93
|
+
{ slug: "XeroApi", name: "Xero API", category: "productivity" },
|
|
94
|
+
{ slug: "Youtube", name: "Youtube", category: "search" },
|
|
95
|
+
{ slug: "Zendesk", name: "Zendesk", category: "customer-support" },
|
|
96
|
+
{ slug: "ZohoBooksApi", name: "Zoho Books API", category: "payments" },
|
|
97
|
+
{ slug: "Zoom", name: "Zoom", category: "social" }
|
|
98
|
+
];
|
|
99
|
+
var ArcadeToolProvider = class {
|
|
100
|
+
constructor(config) {
|
|
101
|
+
this.info = {
|
|
102
|
+
id: "arcade",
|
|
103
|
+
name: "Arcade AI",
|
|
104
|
+
description: "Access 7,000+ tools from 130+ app integrations via Arcade AI"
|
|
105
|
+
};
|
|
106
|
+
this.client = null;
|
|
107
|
+
this.config = config;
|
|
108
|
+
this.toolkitCache = /* @__PURE__ */ new Map();
|
|
109
|
+
for (const tk of KNOWN_TOOLKITS) {
|
|
110
|
+
this.toolkitCache.set(tk.slug, {
|
|
111
|
+
slug: tk.slug,
|
|
112
|
+
name: tk.name,
|
|
113
|
+
description: tk.description ?? `Arcade AI ${tk.name} tools`,
|
|
114
|
+
icon: tk.category
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get or create an Arcade client.
|
|
120
|
+
*/
|
|
121
|
+
getClient() {
|
|
122
|
+
if (!this.client) {
|
|
123
|
+
this.client = new Arcade({
|
|
124
|
+
apiKey: this.config.apiKey,
|
|
125
|
+
...this.config.baseURL ? { baseURL: this.config.baseURL } : {}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return this.client;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Absorb toolkit metadata from a tool listing into the cache.
|
|
132
|
+
* Returns true if any new toolkit was discovered.
|
|
133
|
+
*/
|
|
134
|
+
absorbToolkits(items) {
|
|
135
|
+
let discovered = false;
|
|
136
|
+
for (const tool of items) {
|
|
137
|
+
const tk = tool.toolkit;
|
|
138
|
+
if (tk?.name && !this.toolkitCache.has(tk.name)) {
|
|
139
|
+
this.toolkitCache.set(tk.name, {
|
|
140
|
+
slug: tk.name,
|
|
141
|
+
name: tk.name,
|
|
142
|
+
description: tk.description ?? `Arcade AI ${tk.name} tools`
|
|
143
|
+
});
|
|
144
|
+
discovered = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return discovered;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* List toolkits.
|
|
151
|
+
*
|
|
152
|
+
* Returns the pre-seeded catalog merged with any toolkits discovered at
|
|
153
|
+
* runtime via `listTools()` or `resolveTools()` calls.
|
|
154
|
+
*/
|
|
155
|
+
async listToolkits() {
|
|
156
|
+
const data = [...this.toolkitCache.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
157
|
+
return { data };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* List available tools with optional toolkit and pagination filters.
|
|
161
|
+
* Uses `tools.list({ toolkit, limit, offset })`.
|
|
162
|
+
*/
|
|
163
|
+
async listTools(options) {
|
|
164
|
+
const client = this.getClient();
|
|
165
|
+
const limit = options?.perPage ?? 50;
|
|
166
|
+
const page = options?.page ?? 1;
|
|
167
|
+
const offset = (page - 1) * limit;
|
|
168
|
+
const query = { limit, offset };
|
|
169
|
+
if (options?.toolkit) query.toolkit = options.toolkit;
|
|
170
|
+
const result = await client.tools.list(query);
|
|
171
|
+
const items = result.items ?? [];
|
|
172
|
+
this.absorbToolkits(items);
|
|
173
|
+
let filtered = items;
|
|
174
|
+
if (options?.search) {
|
|
175
|
+
const searchLower = options.search.toLowerCase();
|
|
176
|
+
filtered = items.filter(
|
|
177
|
+
(t) => t.name?.toLowerCase().includes(searchLower) || t.description?.toLowerCase().includes(searchLower) || t.qualified_name?.toLowerCase().includes(searchLower)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
const data = filtered.map((tool) => ({
|
|
181
|
+
slug: tool.qualified_name ?? `${tool.toolkit?.name}.${tool.name}`,
|
|
182
|
+
name: tool.name,
|
|
183
|
+
description: tool.description,
|
|
184
|
+
toolkit: tool.toolkit?.name
|
|
185
|
+
}));
|
|
186
|
+
return {
|
|
187
|
+
data,
|
|
188
|
+
pagination: {
|
|
189
|
+
page,
|
|
190
|
+
perPage: limit,
|
|
191
|
+
total: result.total_count,
|
|
192
|
+
hasMore: offset + items.length < (result.total_count ?? 0)
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the JSON schema for a specific tool by its qualified name (e.g., `Github.GetRepository`).
|
|
198
|
+
*/
|
|
199
|
+
async getToolSchema(toolSlug) {
|
|
200
|
+
try {
|
|
201
|
+
const client = this.getClient();
|
|
202
|
+
const tool = await client.tools.get(toolSlug);
|
|
203
|
+
if (!tool) return null;
|
|
204
|
+
const properties = {};
|
|
205
|
+
const required = [];
|
|
206
|
+
for (const param of tool.input?.parameters ?? []) {
|
|
207
|
+
properties[param.name] = {
|
|
208
|
+
...param.value_schema ?? {},
|
|
209
|
+
description: param.description
|
|
210
|
+
};
|
|
211
|
+
if (param.required) required.push(param.name);
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
type: "object",
|
|
215
|
+
properties,
|
|
216
|
+
...required.length > 0 ? { required } : {}
|
|
217
|
+
};
|
|
218
|
+
} catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Resolve executable tools in Mastra's ToolAction format.
|
|
224
|
+
*
|
|
225
|
+
* Uses `toZodToolSet` from `@arcadeai/arcadejs/lib` to create ZodTool objects
|
|
226
|
+
* with Zod schemas and execute functions, then wraps them as ToolAction objects.
|
|
227
|
+
*/
|
|
228
|
+
async resolveTools(toolSlugs, toolConfigs, options) {
|
|
229
|
+
if (toolSlugs.length === 0) return {};
|
|
230
|
+
const client = this.getClient();
|
|
231
|
+
const userId = options?.userId ?? "default";
|
|
232
|
+
const toolDefs = await Promise.all(toolSlugs.map((slug) => client.tools.get(slug).catch(() => null)));
|
|
233
|
+
const validDefs = toolDefs.filter((d) => d !== null);
|
|
234
|
+
if (validDefs.length === 0) return {};
|
|
235
|
+
this.absorbToolkits(validDefs);
|
|
236
|
+
const zodToolSet = toZodToolSet({
|
|
237
|
+
tools: validDefs,
|
|
238
|
+
client,
|
|
239
|
+
userId,
|
|
240
|
+
executeFactory: executeOrAuthorizeZodTool
|
|
241
|
+
});
|
|
242
|
+
const result = {};
|
|
243
|
+
const normalizedToQualified = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const d of validDefs) {
|
|
245
|
+
const qn = d.qualified_name ?? `${d.toolkit?.name}.${d.name}`;
|
|
246
|
+
normalizedToQualified.set(qn.replace(/\./g, "_"), qn);
|
|
247
|
+
}
|
|
248
|
+
for (const [key, zodTool] of Object.entries(zodToolSet)) {
|
|
249
|
+
const qualifiedName = normalizedToQualified.get(key) ?? key;
|
|
250
|
+
const descOverride = toolConfigs?.[qualifiedName]?.description ?? toolConfigs?.[key]?.description;
|
|
251
|
+
result[qualifiedName] = {
|
|
252
|
+
id: qualifiedName,
|
|
253
|
+
description: descOverride ?? zodTool.description ?? "",
|
|
254
|
+
inputSchema: zodTool.parameters,
|
|
255
|
+
outputSchema: zodTool.output,
|
|
256
|
+
execute: async (input) => {
|
|
257
|
+
return zodTool.execute(input);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
export {
|
|
265
|
+
ArcadeToolProvider
|
|
266
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/composio.ts
|
|
21
|
+
var composio_exports = {};
|
|
22
|
+
__export(composio_exports, {
|
|
23
|
+
ComposioToolProvider: () => ComposioToolProvider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(composio_exports);
|
|
26
|
+
|
|
27
|
+
// src/providers/composio.ts
|
|
28
|
+
var import_core = require("@composio/core");
|
|
29
|
+
var import_mastra = require("@composio/mastra");
|
|
30
|
+
var ComposioToolProvider = class {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.info = {
|
|
33
|
+
id: "composio",
|
|
34
|
+
name: "Composio",
|
|
35
|
+
description: "Access 10,000+ tools from 150+ apps via Composio"
|
|
36
|
+
};
|
|
37
|
+
this.rawClient = null;
|
|
38
|
+
this.mastraClient = null;
|
|
39
|
+
this.apiKey = config.apiKey;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get or create a raw Composio client (no provider — for discovery only).
|
|
43
|
+
*/
|
|
44
|
+
getRawClient() {
|
|
45
|
+
if (!this.rawClient) {
|
|
46
|
+
this.rawClient = new import_core.Composio({ apiKey: this.apiKey });
|
|
47
|
+
}
|
|
48
|
+
return this.rawClient;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get or create a Composio client with MastraProvider (for runtime tools).
|
|
52
|
+
*/
|
|
53
|
+
getMastraClient() {
|
|
54
|
+
if (!this.mastraClient) {
|
|
55
|
+
this.mastraClient = new import_core.Composio({
|
|
56
|
+
apiKey: this.apiKey,
|
|
57
|
+
provider: new import_mastra.MastraProvider()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return this.mastraClient;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* List available toolkits via `composio.toolkits.get({})`.
|
|
64
|
+
* Returns: `ToolKitListResponse` — an array of `{ slug, name, meta: { description, logo, ... } }`.
|
|
65
|
+
*/
|
|
66
|
+
async listToolkits() {
|
|
67
|
+
const composio = this.getRawClient();
|
|
68
|
+
const toolkits = await composio.toolkits.get({});
|
|
69
|
+
const data = toolkits.map((tk) => ({
|
|
70
|
+
slug: tk.slug,
|
|
71
|
+
name: tk.name,
|
|
72
|
+
description: tk.meta?.description,
|
|
73
|
+
icon: tk.meta?.logo
|
|
74
|
+
}));
|
|
75
|
+
return { data };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* List available tools via `composio.tools.getRawComposioTools()`.
|
|
79
|
+
* No userId required — returns raw tool definitions for UI browsing.
|
|
80
|
+
*/
|
|
81
|
+
async listTools(options) {
|
|
82
|
+
const composio = this.getRawClient();
|
|
83
|
+
const limit = options?.perPage;
|
|
84
|
+
const query = options?.toolkit ? { toolkits: [options.toolkit], limit, search: options?.search } : options?.search ? { search: options.search, limit } : { toolkits: [], limit };
|
|
85
|
+
const rawTools = await composio.tools.getRawComposioTools(query);
|
|
86
|
+
const data = rawTools.map((tool) => ({
|
|
87
|
+
slug: tool.slug,
|
|
88
|
+
name: tool.name ?? tool.slug,
|
|
89
|
+
description: tool.description,
|
|
90
|
+
toolkit: tool.toolkit?.slug
|
|
91
|
+
}));
|
|
92
|
+
return {
|
|
93
|
+
data,
|
|
94
|
+
pagination: {
|
|
95
|
+
page: options?.page ?? 1,
|
|
96
|
+
perPage: limit,
|
|
97
|
+
hasMore: limit !== void 0 && rawTools.length >= limit
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get JSON schema for a specific tool via `composio.tools.getRawComposioToolBySlug()`.
|
|
103
|
+
*/
|
|
104
|
+
async getToolSchema(toolSlug) {
|
|
105
|
+
try {
|
|
106
|
+
const composio = this.getRawClient();
|
|
107
|
+
const tool = await composio.tools.getRawComposioToolBySlug(toolSlug);
|
|
108
|
+
if (!tool) return null;
|
|
109
|
+
return tool.inputParameters ?? {};
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resolve executable tools in Mastra format via `composio.tools.get(userId, { tools: [...] })`.
|
|
116
|
+
*
|
|
117
|
+
* Uses MastraProvider so returned tools are `ReturnType<typeof createTool>` — compatible
|
|
118
|
+
* with Mastra's `ToolAction` interface.
|
|
119
|
+
*/
|
|
120
|
+
async resolveTools(toolSlugs, toolConfigs, options) {
|
|
121
|
+
if (toolSlugs.length === 0) return {};
|
|
122
|
+
const userId = options?.userId ?? "default";
|
|
123
|
+
const composio = this.getMastraClient();
|
|
124
|
+
const mastraTools = await composio.tools.get(userId, { tools: toolSlugs });
|
|
125
|
+
const result = {};
|
|
126
|
+
const entries = Object.entries(mastraTools ?? {});
|
|
127
|
+
for (const [key, tool] of entries) {
|
|
128
|
+
if (!tool) continue;
|
|
129
|
+
const slug = tool.id ?? key;
|
|
130
|
+
const descOverride = toolConfigs?.[slug]?.description;
|
|
131
|
+
if (descOverride) {
|
|
132
|
+
result[slug] = { ...tool, description: descOverride };
|
|
133
|
+
} else {
|
|
134
|
+
result[slug] = tool;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
+
0 && (module.exports = {
|
|
142
|
+
ComposioToolProvider
|
|
143
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ToolProvider, ToolProviderInfo, ToolProviderListResult, ToolProviderToolkit, ListToolProviderToolsOptions, ToolProviderToolInfo, ResolveToolProviderToolsOptions } from '@mastra/core/tool-provider';
|
|
2
|
+
import { ToolAction } from '@mastra/core/tools';
|
|
3
|
+
import { StorageToolConfig } from '@mastra/core/storage';
|
|
4
|
+
|
|
5
|
+
interface ComposioToolProviderConfig {
|
|
6
|
+
/** Composio API key */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Composio tool provider adapter.
|
|
11
|
+
*
|
|
12
|
+
* Uses `@composio/core` + `@composio/mastra` SDKs for both tool discovery
|
|
13
|
+
* and runtime resolution. Both packages are optional peer dependencies and
|
|
14
|
+
* tree-shaken if this provider class isn't imported.
|
|
15
|
+
*
|
|
16
|
+
* Discovery methods (`listToolkits`, `listTools`, `getToolSchema`) use the
|
|
17
|
+
* raw Composio client (no userId required).
|
|
18
|
+
*
|
|
19
|
+
* Runtime method (`resolveTools`) uses the MastraProvider so returned tools are
|
|
20
|
+
* already in Mastra's `createTool()` format.
|
|
21
|
+
*/
|
|
22
|
+
declare class ComposioToolProvider implements ToolProvider {
|
|
23
|
+
readonly info: ToolProviderInfo;
|
|
24
|
+
private apiKey;
|
|
25
|
+
private rawClient;
|
|
26
|
+
private mastraClient;
|
|
27
|
+
constructor(config: ComposioToolProviderConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Get or create a raw Composio client (no provider — for discovery only).
|
|
30
|
+
*/
|
|
31
|
+
private getRawClient;
|
|
32
|
+
/**
|
|
33
|
+
* Get or create a Composio client with MastraProvider (for runtime tools).
|
|
34
|
+
*/
|
|
35
|
+
private getMastraClient;
|
|
36
|
+
/**
|
|
37
|
+
* List available toolkits via `composio.toolkits.get({})`.
|
|
38
|
+
* Returns: `ToolKitListResponse` — an array of `{ slug, name, meta: { description, logo, ... } }`.
|
|
39
|
+
*/
|
|
40
|
+
listToolkits(): Promise<ToolProviderListResult<ToolProviderToolkit>>;
|
|
41
|
+
/**
|
|
42
|
+
* List available tools via `composio.tools.getRawComposioTools()`.
|
|
43
|
+
* No userId required — returns raw tool definitions for UI browsing.
|
|
44
|
+
*/
|
|
45
|
+
listTools(options?: ListToolProviderToolsOptions): Promise<ToolProviderListResult<ToolProviderToolInfo>>;
|
|
46
|
+
/**
|
|
47
|
+
* Get JSON schema for a specific tool via `composio.tools.getRawComposioToolBySlug()`.
|
|
48
|
+
*/
|
|
49
|
+
getToolSchema(toolSlug: string): Promise<Record<string, unknown> | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve executable tools in Mastra format via `composio.tools.get(userId, { tools: [...] })`.
|
|
52
|
+
*
|
|
53
|
+
* Uses MastraProvider so returned tools are `ReturnType<typeof createTool>` — compatible
|
|
54
|
+
* with Mastra's `ToolAction` interface.
|
|
55
|
+
*/
|
|
56
|
+
resolveTools(toolSlugs: string[], toolConfigs?: Record<string, StorageToolConfig>, options?: ResolveToolProviderToolsOptions): Promise<Record<string, ToolAction<unknown, unknown>>>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { ComposioToolProvider, type ComposioToolProviderConfig };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ToolProvider, ToolProviderInfo, ToolProviderListResult, ToolProviderToolkit, ListToolProviderToolsOptions, ToolProviderToolInfo, ResolveToolProviderToolsOptions } from '@mastra/core/tool-provider';
|
|
2
|
+
import { ToolAction } from '@mastra/core/tools';
|
|
3
|
+
import { StorageToolConfig } from '@mastra/core/storage';
|
|
4
|
+
|
|
5
|
+
interface ComposioToolProviderConfig {
|
|
6
|
+
/** Composio API key */
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Composio tool provider adapter.
|
|
11
|
+
*
|
|
12
|
+
* Uses `@composio/core` + `@composio/mastra` SDKs for both tool discovery
|
|
13
|
+
* and runtime resolution. Both packages are optional peer dependencies and
|
|
14
|
+
* tree-shaken if this provider class isn't imported.
|
|
15
|
+
*
|
|
16
|
+
* Discovery methods (`listToolkits`, `listTools`, `getToolSchema`) use the
|
|
17
|
+
* raw Composio client (no userId required).
|
|
18
|
+
*
|
|
19
|
+
* Runtime method (`resolveTools`) uses the MastraProvider so returned tools are
|
|
20
|
+
* already in Mastra's `createTool()` format.
|
|
21
|
+
*/
|
|
22
|
+
declare class ComposioToolProvider implements ToolProvider {
|
|
23
|
+
readonly info: ToolProviderInfo;
|
|
24
|
+
private apiKey;
|
|
25
|
+
private rawClient;
|
|
26
|
+
private mastraClient;
|
|
27
|
+
constructor(config: ComposioToolProviderConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Get or create a raw Composio client (no provider — for discovery only).
|
|
30
|
+
*/
|
|
31
|
+
private getRawClient;
|
|
32
|
+
/**
|
|
33
|
+
* Get or create a Composio client with MastraProvider (for runtime tools).
|
|
34
|
+
*/
|
|
35
|
+
private getMastraClient;
|
|
36
|
+
/**
|
|
37
|
+
* List available toolkits via `composio.toolkits.get({})`.
|
|
38
|
+
* Returns: `ToolKitListResponse` — an array of `{ slug, name, meta: { description, logo, ... } }`.
|
|
39
|
+
*/
|
|
40
|
+
listToolkits(): Promise<ToolProviderListResult<ToolProviderToolkit>>;
|
|
41
|
+
/**
|
|
42
|
+
* List available tools via `composio.tools.getRawComposioTools()`.
|
|
43
|
+
* No userId required — returns raw tool definitions for UI browsing.
|
|
44
|
+
*/
|
|
45
|
+
listTools(options?: ListToolProviderToolsOptions): Promise<ToolProviderListResult<ToolProviderToolInfo>>;
|
|
46
|
+
/**
|
|
47
|
+
* Get JSON schema for a specific tool via `composio.tools.getRawComposioToolBySlug()`.
|
|
48
|
+
*/
|
|
49
|
+
getToolSchema(toolSlug: string): Promise<Record<string, unknown> | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve executable tools in Mastra format via `composio.tools.get(userId, { tools: [...] })`.
|
|
52
|
+
*
|
|
53
|
+
* Uses MastraProvider so returned tools are `ReturnType<typeof createTool>` — compatible
|
|
54
|
+
* with Mastra's `ToolAction` interface.
|
|
55
|
+
*/
|
|
56
|
+
resolveTools(toolSlugs: string[], toolConfigs?: Record<string, StorageToolConfig>, options?: ResolveToolProviderToolsOptions): Promise<Record<string, ToolAction<unknown, unknown>>>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { ComposioToolProvider, type ComposioToolProviderConfig };
|
package/dist/composio.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// src/providers/composio.ts
|
|
2
|
+
import { Composio } from "@composio/core";
|
|
3
|
+
import { MastraProvider } from "@composio/mastra";
|
|
4
|
+
var ComposioToolProvider = class {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.info = {
|
|
7
|
+
id: "composio",
|
|
8
|
+
name: "Composio",
|
|
9
|
+
description: "Access 10,000+ tools from 150+ apps via Composio"
|
|
10
|
+
};
|
|
11
|
+
this.rawClient = null;
|
|
12
|
+
this.mastraClient = null;
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get or create a raw Composio client (no provider — for discovery only).
|
|
17
|
+
*/
|
|
18
|
+
getRawClient() {
|
|
19
|
+
if (!this.rawClient) {
|
|
20
|
+
this.rawClient = new Composio({ apiKey: this.apiKey });
|
|
21
|
+
}
|
|
22
|
+
return this.rawClient;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get or create a Composio client with MastraProvider (for runtime tools).
|
|
26
|
+
*/
|
|
27
|
+
getMastraClient() {
|
|
28
|
+
if (!this.mastraClient) {
|
|
29
|
+
this.mastraClient = new Composio({
|
|
30
|
+
apiKey: this.apiKey,
|
|
31
|
+
provider: new MastraProvider()
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return this.mastraClient;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* List available toolkits via `composio.toolkits.get({})`.
|
|
38
|
+
* Returns: `ToolKitListResponse` — an array of `{ slug, name, meta: { description, logo, ... } }`.
|
|
39
|
+
*/
|
|
40
|
+
async listToolkits() {
|
|
41
|
+
const composio = this.getRawClient();
|
|
42
|
+
const toolkits = await composio.toolkits.get({});
|
|
43
|
+
const data = toolkits.map((tk) => ({
|
|
44
|
+
slug: tk.slug,
|
|
45
|
+
name: tk.name,
|
|
46
|
+
description: tk.meta?.description,
|
|
47
|
+
icon: tk.meta?.logo
|
|
48
|
+
}));
|
|
49
|
+
return { data };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* List available tools via `composio.tools.getRawComposioTools()`.
|
|
53
|
+
* No userId required — returns raw tool definitions for UI browsing.
|
|
54
|
+
*/
|
|
55
|
+
async listTools(options) {
|
|
56
|
+
const composio = this.getRawClient();
|
|
57
|
+
const limit = options?.perPage;
|
|
58
|
+
const query = options?.toolkit ? { toolkits: [options.toolkit], limit, search: options?.search } : options?.search ? { search: options.search, limit } : { toolkits: [], limit };
|
|
59
|
+
const rawTools = await composio.tools.getRawComposioTools(query);
|
|
60
|
+
const data = rawTools.map((tool) => ({
|
|
61
|
+
slug: tool.slug,
|
|
62
|
+
name: tool.name ?? tool.slug,
|
|
63
|
+
description: tool.description,
|
|
64
|
+
toolkit: tool.toolkit?.slug
|
|
65
|
+
}));
|
|
66
|
+
return {
|
|
67
|
+
data,
|
|
68
|
+
pagination: {
|
|
69
|
+
page: options?.page ?? 1,
|
|
70
|
+
perPage: limit,
|
|
71
|
+
hasMore: limit !== void 0 && rawTools.length >= limit
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get JSON schema for a specific tool via `composio.tools.getRawComposioToolBySlug()`.
|
|
77
|
+
*/
|
|
78
|
+
async getToolSchema(toolSlug) {
|
|
79
|
+
try {
|
|
80
|
+
const composio = this.getRawClient();
|
|
81
|
+
const tool = await composio.tools.getRawComposioToolBySlug(toolSlug);
|
|
82
|
+
if (!tool) return null;
|
|
83
|
+
return tool.inputParameters ?? {};
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve executable tools in Mastra format via `composio.tools.get(userId, { tools: [...] })`.
|
|
90
|
+
*
|
|
91
|
+
* Uses MastraProvider so returned tools are `ReturnType<typeof createTool>` — compatible
|
|
92
|
+
* with Mastra's `ToolAction` interface.
|
|
93
|
+
*/
|
|
94
|
+
async resolveTools(toolSlugs, toolConfigs, options) {
|
|
95
|
+
if (toolSlugs.length === 0) return {};
|
|
96
|
+
const userId = options?.userId ?? "default";
|
|
97
|
+
const composio = this.getMastraClient();
|
|
98
|
+
const mastraTools = await composio.tools.get(userId, { tools: toolSlugs });
|
|
99
|
+
const result = {};
|
|
100
|
+
const entries = Object.entries(mastraTools ?? {});
|
|
101
|
+
for (const [key, tool] of entries) {
|
|
102
|
+
if (!tool) continue;
|
|
103
|
+
const slug = tool.id ?? key;
|
|
104
|
+
const descOverride = toolConfigs?.[slug]?.description;
|
|
105
|
+
if (descOverride) {
|
|
106
|
+
result[slug] = { ...tool, description: descOverride };
|
|
107
|
+
} else {
|
|
108
|
+
result[slug] = tool;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export {
|
|
115
|
+
ComposioToolProvider
|
|
116
|
+
};
|