integrate-sdk 0.8.36 → 0.8.39
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/dist/adapters/auto-routes.js +371 -71
- package/dist/adapters/base-handler.js +561 -0
- package/dist/adapters/index.js +371 -71
- package/dist/adapters/nextjs.js +371 -71
- package/dist/adapters/node.js +371 -71
- package/dist/adapters/svelte-kit.js +371 -71
- package/dist/adapters/tanstack-start.js +371 -71
- package/dist/ai/anthropic.d.ts +3 -0
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +255 -2
- package/dist/ai/cloudflare.d.ts +158 -0
- package/dist/ai/cloudflare.d.ts.map +1 -0
- package/dist/ai/cloudflare.js +4249 -0
- package/dist/ai/google.d.ts +3 -0
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +256 -2
- package/dist/ai/index.d.ts +1 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +351 -7
- package/dist/ai/langchain.d.ts +139 -0
- package/dist/ai/langchain.d.ts.map +1 -0
- package/dist/ai/langchain.js +4237 -0
- package/dist/ai/llamaindex.d.ts +125 -0
- package/dist/ai/llamaindex.d.ts.map +1 -0
- package/dist/ai/llamaindex.js +4236 -0
- package/dist/ai/mastra.d.ts +138 -0
- package/dist/ai/mastra.d.ts.map +1 -0
- package/dist/ai/mastra.js +4240 -0
- package/dist/ai/openai.d.ts +3 -0
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +257 -2
- package/dist/ai/trigger-tools.d.ts +206 -0
- package/dist/ai/trigger-tools.d.ts.map +1 -0
- package/dist/ai/trigger-tools.js +4198 -0
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +217 -0
- package/dist/index.js +359 -59
- package/dist/oauth.js +371 -71
- package/dist/server.js +372 -71
- package/dist/src/ai/anthropic.d.ts +3 -0
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/cloudflare.d.ts +158 -0
- package/dist/src/ai/cloudflare.d.ts.map +1 -0
- package/dist/src/ai/google.d.ts +3 -0
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/index.d.ts +1 -0
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/langchain.d.ts +139 -0
- package/dist/src/ai/langchain.d.ts.map +1 -0
- package/dist/src/ai/llamaindex.d.ts +125 -0
- package/dist/src/ai/llamaindex.d.ts.map +1 -0
- package/dist/src/ai/mastra.d.ts +138 -0
- package/dist/src/ai/mastra.d.ts.map +1 -0
- package/dist/src/ai/openai.d.ts +3 -0
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/trigger-tools.d.ts +206 -0
- package/dist/src/ai/trigger-tools.d.ts.map +1 -0
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/integrations/vercel-ai.d.ts +127 -0
- package/dist/src/integrations/vercel-ai.d.ts.map +1 -0
- package/dist/src/plugins/generic.d.ts +99 -0
- package/dist/src/plugins/generic.d.ts.map +1 -0
- package/dist/src/plugins/github-client.d.ts +320 -0
- package/dist/src/plugins/github-client.d.ts.map +1 -0
- package/dist/src/plugins/github.d.ts +89 -0
- package/dist/src/plugins/github.d.ts.map +1 -0
- package/dist/src/plugins/gmail-client.d.ts +106 -0
- package/dist/src/plugins/gmail-client.d.ts.map +1 -0
- package/dist/src/plugins/gmail.d.ts +87 -0
- package/dist/src/plugins/gmail.d.ts.map +1 -0
- package/dist/src/plugins/server-client.d.ts +18 -0
- package/dist/src/plugins/server-client.d.ts.map +1 -0
- package/dist/src/plugins/types.d.ts +70 -0
- package/dist/src/plugins/types.d.ts.map +1 -0
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/ai/anthropic.js
CHANGED
|
@@ -4189,6 +4189,218 @@ async function ensureClientConnected(client) {
|
|
|
4189
4189
|
}
|
|
4190
4190
|
}
|
|
4191
4191
|
|
|
4192
|
+
// ../../node_modules/nanoid/index.js
|
|
4193
|
+
import crypto from "crypto";
|
|
4194
|
+
|
|
4195
|
+
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
4196
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
4197
|
+
|
|
4198
|
+
// ../../node_modules/nanoid/index.js
|
|
4199
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
4200
|
+
var pool;
|
|
4201
|
+
var poolOffset;
|
|
4202
|
+
var fillPool = (bytes) => {
|
|
4203
|
+
if (!pool || pool.length < bytes) {
|
|
4204
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
4205
|
+
crypto.randomFillSync(pool);
|
|
4206
|
+
poolOffset = 0;
|
|
4207
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
4208
|
+
crypto.randomFillSync(pool);
|
|
4209
|
+
poolOffset = 0;
|
|
4210
|
+
}
|
|
4211
|
+
poolOffset += bytes;
|
|
4212
|
+
};
|
|
4213
|
+
var nanoid = (size = 21) => {
|
|
4214
|
+
fillPool(size |= 0);
|
|
4215
|
+
let id = "";
|
|
4216
|
+
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
4217
|
+
id += urlAlphabet[pool[i] & 63];
|
|
4218
|
+
}
|
|
4219
|
+
return id;
|
|
4220
|
+
};
|
|
4221
|
+
|
|
4222
|
+
// ../triggers/utils.ts
|
|
4223
|
+
function generateTriggerId() {
|
|
4224
|
+
return `trig_${nanoid(12)}`;
|
|
4225
|
+
}
|
|
4226
|
+
function extractProviderFromToolName(toolName) {
|
|
4227
|
+
const parts = toolName.split("_");
|
|
4228
|
+
return parts[0] || toolName;
|
|
4229
|
+
}
|
|
4230
|
+
function validateStatusTransition(currentStatus, targetStatus) {
|
|
4231
|
+
if (targetStatus === "paused" && currentStatus !== "active") {
|
|
4232
|
+
return {
|
|
4233
|
+
valid: false,
|
|
4234
|
+
error: `Cannot pause trigger with status '${currentStatus}'. Only 'active' triggers can be paused.`
|
|
4235
|
+
};
|
|
4236
|
+
}
|
|
4237
|
+
if (targetStatus === "active" && currentStatus !== "paused") {
|
|
4238
|
+
return {
|
|
4239
|
+
valid: false,
|
|
4240
|
+
error: `Cannot resume trigger with status '${currentStatus}'. Only 'paused' triggers can be resumed.`
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
return { valid: true };
|
|
4244
|
+
}
|
|
4245
|
+
function calculateHasMore(offset, returnedCount, total) {
|
|
4246
|
+
return offset + returnedCount < total;
|
|
4247
|
+
}
|
|
4248
|
+
|
|
4249
|
+
// trigger-tools.ts
|
|
4250
|
+
function createTriggerTools(config, context) {
|
|
4251
|
+
const { callbacks } = config;
|
|
4252
|
+
return {
|
|
4253
|
+
create_trigger: {
|
|
4254
|
+
description: "Schedule a tool to run at a specific time or on a recurring schedule. Use this when the user wants to do something later.",
|
|
4255
|
+
inputSchema: exports_external.object({
|
|
4256
|
+
name: exports_external.string().optional().describe("Human-readable trigger name"),
|
|
4257
|
+
description: exports_external.string().optional().describe("Trigger description"),
|
|
4258
|
+
toolName: exports_external.string().describe("MCP tool name to execute (e.g., gmail_send_email, github_create_issue)"),
|
|
4259
|
+
toolArguments: exports_external.record(exports_external.unknown()).describe("Arguments to pass to the tool when it executes"),
|
|
4260
|
+
schedule: exports_external.union([
|
|
4261
|
+
exports_external.object({
|
|
4262
|
+
type: exports_external.literal("once"),
|
|
4263
|
+
runAt: exports_external.string().describe("ISO datetime string (e.g., 2024-12-13T22:00:00Z)")
|
|
4264
|
+
}),
|
|
4265
|
+
exports_external.object({
|
|
4266
|
+
type: exports_external.literal("cron"),
|
|
4267
|
+
expression: exports_external.string().describe("Cron expression (e.g., '0 9 * * *' for daily at 9 AM)")
|
|
4268
|
+
})
|
|
4269
|
+
]).describe("When to execute the tool")
|
|
4270
|
+
}),
|
|
4271
|
+
execute: async (args) => {
|
|
4272
|
+
const triggerId = generateTriggerId();
|
|
4273
|
+
const provider = extractProviderFromToolName(args.toolName);
|
|
4274
|
+
const now = new Date().toISOString();
|
|
4275
|
+
const trigger = {
|
|
4276
|
+
id: triggerId,
|
|
4277
|
+
...args,
|
|
4278
|
+
provider,
|
|
4279
|
+
status: "active",
|
|
4280
|
+
createdAt: now,
|
|
4281
|
+
updatedAt: now,
|
|
4282
|
+
runCount: 0
|
|
4283
|
+
};
|
|
4284
|
+
return callbacks.create(trigger, context);
|
|
4285
|
+
}
|
|
4286
|
+
},
|
|
4287
|
+
list_triggers: {
|
|
4288
|
+
description: "List all scheduled triggers with optional filtering by status or tool name",
|
|
4289
|
+
inputSchema: exports_external.object({
|
|
4290
|
+
status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
|
|
4291
|
+
toolName: exports_external.string().optional().describe("Filter by tool name"),
|
|
4292
|
+
limit: exports_external.number().optional().describe("Maximum number of results (default: 20)"),
|
|
4293
|
+
offset: exports_external.number().optional().describe("Number of results to skip for pagination (default: 0)")
|
|
4294
|
+
}),
|
|
4295
|
+
execute: async (args) => {
|
|
4296
|
+
const params = {
|
|
4297
|
+
status: args.status,
|
|
4298
|
+
toolName: args.toolName,
|
|
4299
|
+
limit: args.limit || 20,
|
|
4300
|
+
offset: args.offset || 0
|
|
4301
|
+
};
|
|
4302
|
+
const result = await callbacks.list(params, context);
|
|
4303
|
+
const hasMore = calculateHasMore(params.offset, result.triggers.length, result.total);
|
|
4304
|
+
return {
|
|
4305
|
+
triggers: result.triggers,
|
|
4306
|
+
total: result.total,
|
|
4307
|
+
hasMore
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
},
|
|
4311
|
+
get_trigger: {
|
|
4312
|
+
description: "Get details of a specific trigger by its ID",
|
|
4313
|
+
inputSchema: exports_external.object({
|
|
4314
|
+
triggerId: exports_external.string().describe("The trigger ID to retrieve")
|
|
4315
|
+
}),
|
|
4316
|
+
execute: async (args) => {
|
|
4317
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
4318
|
+
if (!trigger) {
|
|
4319
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
4320
|
+
}
|
|
4321
|
+
return trigger;
|
|
4322
|
+
}
|
|
4323
|
+
},
|
|
4324
|
+
update_trigger: {
|
|
4325
|
+
description: "Update a trigger's properties like name, description, arguments, or schedule",
|
|
4326
|
+
inputSchema: exports_external.object({
|
|
4327
|
+
triggerId: exports_external.string().describe("The trigger ID to update"),
|
|
4328
|
+
name: exports_external.string().optional().describe("New trigger name"),
|
|
4329
|
+
description: exports_external.string().optional().describe("New trigger description"),
|
|
4330
|
+
toolArguments: exports_external.record(exports_external.unknown()).optional().describe("New tool arguments"),
|
|
4331
|
+
schedule: exports_external.union([
|
|
4332
|
+
exports_external.object({
|
|
4333
|
+
type: exports_external.literal("once"),
|
|
4334
|
+
runAt: exports_external.string().describe("ISO datetime string")
|
|
4335
|
+
}),
|
|
4336
|
+
exports_external.object({
|
|
4337
|
+
type: exports_external.literal("cron"),
|
|
4338
|
+
expression: exports_external.string().describe("Cron expression")
|
|
4339
|
+
})
|
|
4340
|
+
]).optional().describe("New schedule")
|
|
4341
|
+
}),
|
|
4342
|
+
execute: async (args) => {
|
|
4343
|
+
const { triggerId, ...updates } = args;
|
|
4344
|
+
const updatesWithTimestamp = {
|
|
4345
|
+
...updates,
|
|
4346
|
+
updatedAt: new Date().toISOString()
|
|
4347
|
+
};
|
|
4348
|
+
return callbacks.update(triggerId, updatesWithTimestamp, context);
|
|
4349
|
+
}
|
|
4350
|
+
},
|
|
4351
|
+
delete_trigger: {
|
|
4352
|
+
description: "Delete a trigger permanently. This cannot be undone.",
|
|
4353
|
+
inputSchema: exports_external.object({
|
|
4354
|
+
triggerId: exports_external.string().describe("The trigger ID to delete")
|
|
4355
|
+
}),
|
|
4356
|
+
execute: async (args) => {
|
|
4357
|
+
await callbacks.delete(args.triggerId, context);
|
|
4358
|
+
return { success: true, message: `Trigger ${args.triggerId} deleted` };
|
|
4359
|
+
}
|
|
4360
|
+
},
|
|
4361
|
+
pause_trigger: {
|
|
4362
|
+
description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
|
|
4363
|
+
inputSchema: exports_external.object({
|
|
4364
|
+
triggerId: exports_external.string().describe("The trigger ID to pause")
|
|
4365
|
+
}),
|
|
4366
|
+
execute: async (args) => {
|
|
4367
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
4368
|
+
if (!trigger) {
|
|
4369
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
4370
|
+
}
|
|
4371
|
+
const validation = validateStatusTransition(trigger.status, "paused");
|
|
4372
|
+
if (!validation.valid) {
|
|
4373
|
+
throw new Error(validation.error);
|
|
4374
|
+
}
|
|
4375
|
+
return callbacks.update(args.triggerId, {
|
|
4376
|
+
status: "paused",
|
|
4377
|
+
updatedAt: new Date().toISOString()
|
|
4378
|
+
}, context);
|
|
4379
|
+
}
|
|
4380
|
+
},
|
|
4381
|
+
resume_trigger: {
|
|
4382
|
+
description: "Resume a paused trigger to start executing it again on schedule",
|
|
4383
|
+
inputSchema: exports_external.object({
|
|
4384
|
+
triggerId: exports_external.string().describe("The trigger ID to resume")
|
|
4385
|
+
}),
|
|
4386
|
+
execute: async (args) => {
|
|
4387
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
4388
|
+
if (!trigger) {
|
|
4389
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
4390
|
+
}
|
|
4391
|
+
const validation = validateStatusTransition(trigger.status, "active");
|
|
4392
|
+
if (!validation.valid) {
|
|
4393
|
+
throw new Error(validation.error);
|
|
4394
|
+
}
|
|
4395
|
+
return callbacks.update(args.triggerId, {
|
|
4396
|
+
status: "active",
|
|
4397
|
+
updatedAt: new Date().toISOString()
|
|
4398
|
+
}, context);
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
};
|
|
4402
|
+
}
|
|
4403
|
+
|
|
4192
4404
|
// anthropic.ts
|
|
4193
4405
|
function convertMCPToolToAnthropic(mcpTool, _client, _options) {
|
|
4194
4406
|
return {
|
|
@@ -4203,10 +4415,17 @@ function convertMCPToolToAnthropic(mcpTool, _client, _options) {
|
|
|
4203
4415
|
}
|
|
4204
4416
|
async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
4205
4417
|
const toolResults = [];
|
|
4418
|
+
const triggerConfig = client.__triggerConfig;
|
|
4419
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
4206
4420
|
const toolUseBlocks = messageContent.filter((block) => block.type === "tool_use" && ("id" in block) && ("name" in block) && ("input" in block));
|
|
4207
4421
|
for (const toolUse of toolUseBlocks) {
|
|
4208
4422
|
try {
|
|
4209
|
-
|
|
4423
|
+
let result;
|
|
4424
|
+
if (triggerTools && triggerTools[toolUse.name]) {
|
|
4425
|
+
result = await triggerTools[toolUse.name].execute(toolUse.input);
|
|
4426
|
+
} else {
|
|
4427
|
+
result = await executeToolWithToken(client, toolUse.name, toolUse.input, options);
|
|
4428
|
+
}
|
|
4210
4429
|
const resultString = JSON.stringify(result);
|
|
4211
4430
|
toolResults.push({
|
|
4212
4431
|
type: "tool_result",
|
|
@@ -4235,7 +4454,41 @@ async function getAnthropicTools(client, options) {
|
|
|
4235
4454
|
}
|
|
4236
4455
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4237
4456
|
const mcpTools = client.getEnabledTools();
|
|
4238
|
-
|
|
4457
|
+
const anthropicTools = mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
|
|
4458
|
+
const triggerConfig = client.__triggerConfig;
|
|
4459
|
+
if (triggerConfig) {
|
|
4460
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
4461
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
4462
|
+
const zodSchema = tool.inputSchema;
|
|
4463
|
+
const jsonSchema = zodToAnthropicSchema(zodSchema);
|
|
4464
|
+
anthropicTools.push({
|
|
4465
|
+
name,
|
|
4466
|
+
description: tool.description || `Execute ${name}`,
|
|
4467
|
+
input_schema: jsonSchema
|
|
4468
|
+
});
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4471
|
+
return anthropicTools;
|
|
4472
|
+
}
|
|
4473
|
+
function zodToAnthropicSchema(schema) {
|
|
4474
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
4475
|
+
const shape = schema._def.shape();
|
|
4476
|
+
const properties = {};
|
|
4477
|
+
const required = [];
|
|
4478
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
4479
|
+
const fieldSchema = value;
|
|
4480
|
+
properties[key] = { type: "string" };
|
|
4481
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
4482
|
+
required.push(key);
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
return {
|
|
4486
|
+
type: "object",
|
|
4487
|
+
properties,
|
|
4488
|
+
...required.length > 0 ? { required } : {}
|
|
4489
|
+
};
|
|
4490
|
+
}
|
|
4491
|
+
return { type: "object", properties: {}, required: [] };
|
|
4239
4492
|
}
|
|
4240
4493
|
async function handleAnthropicMessage(client, message, options) {
|
|
4241
4494
|
let providerTokens = options?.providerTokens;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers AI Integration
|
|
3
|
+
*
|
|
4
|
+
* Helper functions to convert MCP tools to Cloudflare Workers AI format
|
|
5
|
+
*/
|
|
6
|
+
import type { MCPClient } from "../client.js";
|
|
7
|
+
import type { MCPTool } from "../protocol/messages.js";
|
|
8
|
+
import { type AIToolsOptions } from "./utils.js";
|
|
9
|
+
/**
|
|
10
|
+
* Cloudflare AI tool definition
|
|
11
|
+
* Compatible with Cloudflare Workers AI
|
|
12
|
+
*/
|
|
13
|
+
export interface CloudflareTool {
|
|
14
|
+
type: 'function';
|
|
15
|
+
function: {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
parameters: {
|
|
19
|
+
type: 'object';
|
|
20
|
+
properties: Record<string, {
|
|
21
|
+
type: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
}>;
|
|
24
|
+
required: string[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for converting MCP tools to Cloudflare format
|
|
30
|
+
*/
|
|
31
|
+
export interface CloudflareToolsOptions extends AIToolsOptions {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert a single MCP tool to Cloudflare Workers AI format
|
|
35
|
+
*
|
|
36
|
+
* @param mcpTool - The MCP tool definition
|
|
37
|
+
* @param client - The MCP client instance (used for executing the tool)
|
|
38
|
+
* @param options - Optional configuration including provider tokens
|
|
39
|
+
* @returns Cloudflare compatible tool definition
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const cloudflareTool = convertMCPToolToCloudflare(mcpTool, client);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function convertMCPToolToCloudflare(mcpTool: MCPTool, _client: MCPClient<any>, _options?: CloudflareToolsOptions): CloudflareTool;
|
|
47
|
+
/**
|
|
48
|
+
* Convert all enabled MCP tools to Cloudflare Workers AI format
|
|
49
|
+
* Returns a dictionary keyed by tool name
|
|
50
|
+
*
|
|
51
|
+
* @param client - The MCP client instance (must be connected)
|
|
52
|
+
* @param options - Optional configuration including provider tokens
|
|
53
|
+
* @returns Dictionary of Cloudflare compatible tool definitions
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Client-side usage
|
|
58
|
+
* const tools = convertMCPToolsToCloudflare(mcpClient);
|
|
59
|
+
*
|
|
60
|
+
* // Server-side with provider tokens
|
|
61
|
+
* const tools = convertMCPToolsToCloudflare(serverClient, {
|
|
62
|
+
* providerTokens: { github: 'ghp_...', gmail: 'ya29...' }
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function convertMCPToolsToCloudflare(client: MCPClient<any>, options?: CloudflareToolsOptions): Record<string, CloudflareTool>;
|
|
67
|
+
/**
|
|
68
|
+
* Execute a tool call from Cloudflare Workers AI
|
|
69
|
+
*
|
|
70
|
+
* @param client - The MCP client instance
|
|
71
|
+
* @param toolCall - The tool call with name and arguments
|
|
72
|
+
* @param options - Optional configuration including provider tokens
|
|
73
|
+
* @returns Tool execution result as JSON string
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const result = await executeCloudflareToolCall(client, {
|
|
78
|
+
* name: 'github_create_issue',
|
|
79
|
+
* arguments: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
80
|
+
* }, { providerTokens });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function executeCloudflareToolCall(client: MCPClient<any>, toolCall: {
|
|
84
|
+
name: string;
|
|
85
|
+
arguments: Record<string, unknown> | string;
|
|
86
|
+
}, options?: CloudflareToolsOptions): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Get tools in a format compatible with Cloudflare Workers AI
|
|
89
|
+
*
|
|
90
|
+
* Automatically connects the client if not already connected.
|
|
91
|
+
*
|
|
92
|
+
* @param client - The MCP client instance
|
|
93
|
+
* @param options - Optional configuration including provider tokens for server-side usage
|
|
94
|
+
* @returns Dictionary of tools ready to use with Cloudflare Workers AI
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Cloudflare Worker usage
|
|
99
|
+
* import { createMCPClient, githubIntegration } from 'integrate-sdk';
|
|
100
|
+
* import { getCloudflareTools, executeCloudflareToolCall } from 'integrate-sdk/ai/cloudflare';
|
|
101
|
+
*
|
|
102
|
+
* export default {
|
|
103
|
+
* async fetch(request: Request, env: Env): Promise<Response> {
|
|
104
|
+
* const client = createMCPClient({
|
|
105
|
+
* integrations: [githubIntegration({ clientId: env.GITHUB_CLIENT_ID })],
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* const tools = await getCloudflareTools(client);
|
|
109
|
+
* const ai = new Ai(env.AI);
|
|
110
|
+
*
|
|
111
|
+
* const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
|
|
112
|
+
* messages: [{ role: 'user', content: 'Create a GitHub issue' }],
|
|
113
|
+
* tools: Object.values(tools)
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* return Response.json(response);
|
|
117
|
+
* }
|
|
118
|
+
* };
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Server-side usage with tokens from client
|
|
124
|
+
* import { createMCPServer, githubIntegration } from 'integrate-sdk/server';
|
|
125
|
+
* import { getCloudflareTools, executeCloudflareToolCall } from 'integrate-sdk/ai/cloudflare';
|
|
126
|
+
*
|
|
127
|
+
* const { client: serverClient } = createMCPServer({
|
|
128
|
+
* integrations: [githubIntegration({
|
|
129
|
+
* clientId: '...',
|
|
130
|
+
* clientSecret: '...'
|
|
131
|
+
* })],
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* // In your API route
|
|
135
|
+
* export async function POST(req: Request) {
|
|
136
|
+
* const providerTokens = JSON.parse(req.headers.get('x-integrate-tokens') || '{}');
|
|
137
|
+
* const tools = await getCloudflareTools(serverClient, { providerTokens });
|
|
138
|
+
*
|
|
139
|
+
* // Use with Cloudflare AI
|
|
140
|
+
* const ai = new Ai(env.AI);
|
|
141
|
+
* const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
|
|
142
|
+
* messages: [{ role: 'user', content: 'Create a GitHub issue' }],
|
|
143
|
+
* tools: Object.values(tools)
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* // Handle tool calls
|
|
147
|
+
* if (response.tool_calls) {
|
|
148
|
+
* for (const toolCall of response.tool_calls) {
|
|
149
|
+
* await executeCloudflareToolCall(serverClient, toolCall, { providerTokens });
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
*
|
|
153
|
+
* return Response.json(response);
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function getCloudflareTools(client: MCPClient<any>, options?: CloudflareToolsOptions): Promise<Record<string, CloudflareTool>>;
|
|
158
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/ai/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ,CAAC;YACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;gBACzB,IAAI,EAAE,MAAM,CAAC;gBACb,WAAW,CAAC,EAAE,MAAM,CAAC;aACtB,CAAC,CAAC;YACH,QAAQ,EAAE,MAAM,EAAE,CAAC;SACpB,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc;CAAI;AAElE;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,cAAc,CAahB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAShC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,QAAQ,EAAE;IACR,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;CAC7C,EACD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAezC"}
|