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/adapters/index.js
CHANGED
|
@@ -7429,6 +7429,230 @@ var init_utils = __esm(() => {
|
|
|
7429
7429
|
init_zod();
|
|
7430
7430
|
});
|
|
7431
7431
|
|
|
7432
|
+
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
7433
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
7434
|
+
var init_url_alphabet = () => {};
|
|
7435
|
+
|
|
7436
|
+
// ../../node_modules/nanoid/index.js
|
|
7437
|
+
import crypto2 from "crypto";
|
|
7438
|
+
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset, fillPool = (bytes) => {
|
|
7439
|
+
if (!pool || pool.length < bytes) {
|
|
7440
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
7441
|
+
crypto2.randomFillSync(pool);
|
|
7442
|
+
poolOffset = 0;
|
|
7443
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
7444
|
+
crypto2.randomFillSync(pool);
|
|
7445
|
+
poolOffset = 0;
|
|
7446
|
+
}
|
|
7447
|
+
poolOffset += bytes;
|
|
7448
|
+
}, nanoid = (size = 21) => {
|
|
7449
|
+
fillPool(size |= 0);
|
|
7450
|
+
let id = "";
|
|
7451
|
+
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
7452
|
+
id += urlAlphabet[pool[i] & 63];
|
|
7453
|
+
}
|
|
7454
|
+
return id;
|
|
7455
|
+
};
|
|
7456
|
+
var init_nanoid = __esm(() => {
|
|
7457
|
+
init_url_alphabet();
|
|
7458
|
+
});
|
|
7459
|
+
|
|
7460
|
+
// ../triggers/utils.ts
|
|
7461
|
+
var exports_utils = {};
|
|
7462
|
+
__export(exports_utils, {
|
|
7463
|
+
validateStatusTransition: () => validateStatusTransition,
|
|
7464
|
+
generateTriggerId: () => generateTriggerId,
|
|
7465
|
+
extractProviderFromToolName: () => extractProviderFromToolName,
|
|
7466
|
+
calculateHasMore: () => calculateHasMore
|
|
7467
|
+
});
|
|
7468
|
+
function generateTriggerId() {
|
|
7469
|
+
return `trig_${nanoid(12)}`;
|
|
7470
|
+
}
|
|
7471
|
+
function extractProviderFromToolName(toolName) {
|
|
7472
|
+
const parts = toolName.split("_");
|
|
7473
|
+
return parts[0] || toolName;
|
|
7474
|
+
}
|
|
7475
|
+
function validateStatusTransition(currentStatus, targetStatus) {
|
|
7476
|
+
if (targetStatus === "paused" && currentStatus !== "active") {
|
|
7477
|
+
return {
|
|
7478
|
+
valid: false,
|
|
7479
|
+
error: `Cannot pause trigger with status '${currentStatus}'. Only 'active' triggers can be paused.`
|
|
7480
|
+
};
|
|
7481
|
+
}
|
|
7482
|
+
if (targetStatus === "active" && currentStatus !== "paused") {
|
|
7483
|
+
return {
|
|
7484
|
+
valid: false,
|
|
7485
|
+
error: `Cannot resume trigger with status '${currentStatus}'. Only 'paused' triggers can be resumed.`
|
|
7486
|
+
};
|
|
7487
|
+
}
|
|
7488
|
+
return { valid: true };
|
|
7489
|
+
}
|
|
7490
|
+
function calculateHasMore(offset, returnedCount, total) {
|
|
7491
|
+
return offset + returnedCount < total;
|
|
7492
|
+
}
|
|
7493
|
+
var init_utils2 = __esm(() => {
|
|
7494
|
+
init_nanoid();
|
|
7495
|
+
});
|
|
7496
|
+
|
|
7497
|
+
// ../ai/trigger-tools.ts
|
|
7498
|
+
function createTriggerTools(config, context) {
|
|
7499
|
+
const { callbacks } = config;
|
|
7500
|
+
return {
|
|
7501
|
+
create_trigger: {
|
|
7502
|
+
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.",
|
|
7503
|
+
inputSchema: exports_external.object({
|
|
7504
|
+
name: exports_external.string().optional().describe("Human-readable trigger name"),
|
|
7505
|
+
description: exports_external.string().optional().describe("Trigger description"),
|
|
7506
|
+
toolName: exports_external.string().describe("MCP tool name to execute (e.g., gmail_send_email, github_create_issue)"),
|
|
7507
|
+
toolArguments: exports_external.record(exports_external.unknown()).describe("Arguments to pass to the tool when it executes"),
|
|
7508
|
+
schedule: exports_external.union([
|
|
7509
|
+
exports_external.object({
|
|
7510
|
+
type: exports_external.literal("once"),
|
|
7511
|
+
runAt: exports_external.string().describe("ISO datetime string (e.g., 2024-12-13T22:00:00Z)")
|
|
7512
|
+
}),
|
|
7513
|
+
exports_external.object({
|
|
7514
|
+
type: exports_external.literal("cron"),
|
|
7515
|
+
expression: exports_external.string().describe("Cron expression (e.g., '0 9 * * *' for daily at 9 AM)")
|
|
7516
|
+
})
|
|
7517
|
+
]).describe("When to execute the tool")
|
|
7518
|
+
}),
|
|
7519
|
+
execute: async (args) => {
|
|
7520
|
+
const triggerId = generateTriggerId();
|
|
7521
|
+
const provider = extractProviderFromToolName(args.toolName);
|
|
7522
|
+
const now = new Date().toISOString();
|
|
7523
|
+
const trigger = {
|
|
7524
|
+
id: triggerId,
|
|
7525
|
+
...args,
|
|
7526
|
+
provider,
|
|
7527
|
+
status: "active",
|
|
7528
|
+
createdAt: now,
|
|
7529
|
+
updatedAt: now,
|
|
7530
|
+
runCount: 0
|
|
7531
|
+
};
|
|
7532
|
+
return callbacks.create(trigger, context);
|
|
7533
|
+
}
|
|
7534
|
+
},
|
|
7535
|
+
list_triggers: {
|
|
7536
|
+
description: "List all scheduled triggers with optional filtering by status or tool name",
|
|
7537
|
+
inputSchema: exports_external.object({
|
|
7538
|
+
status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
|
|
7539
|
+
toolName: exports_external.string().optional().describe("Filter by tool name"),
|
|
7540
|
+
limit: exports_external.number().optional().describe("Maximum number of results (default: 20)"),
|
|
7541
|
+
offset: exports_external.number().optional().describe("Number of results to skip for pagination (default: 0)")
|
|
7542
|
+
}),
|
|
7543
|
+
execute: async (args) => {
|
|
7544
|
+
const params = {
|
|
7545
|
+
status: args.status,
|
|
7546
|
+
toolName: args.toolName,
|
|
7547
|
+
limit: args.limit || 20,
|
|
7548
|
+
offset: args.offset || 0
|
|
7549
|
+
};
|
|
7550
|
+
const result = await callbacks.list(params, context);
|
|
7551
|
+
const hasMore = calculateHasMore(params.offset, result.triggers.length, result.total);
|
|
7552
|
+
return {
|
|
7553
|
+
triggers: result.triggers,
|
|
7554
|
+
total: result.total,
|
|
7555
|
+
hasMore
|
|
7556
|
+
};
|
|
7557
|
+
}
|
|
7558
|
+
},
|
|
7559
|
+
get_trigger: {
|
|
7560
|
+
description: "Get details of a specific trigger by its ID",
|
|
7561
|
+
inputSchema: exports_external.object({
|
|
7562
|
+
triggerId: exports_external.string().describe("The trigger ID to retrieve")
|
|
7563
|
+
}),
|
|
7564
|
+
execute: async (args) => {
|
|
7565
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7566
|
+
if (!trigger) {
|
|
7567
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7568
|
+
}
|
|
7569
|
+
return trigger;
|
|
7570
|
+
}
|
|
7571
|
+
},
|
|
7572
|
+
update_trigger: {
|
|
7573
|
+
description: "Update a trigger's properties like name, description, arguments, or schedule",
|
|
7574
|
+
inputSchema: exports_external.object({
|
|
7575
|
+
triggerId: exports_external.string().describe("The trigger ID to update"),
|
|
7576
|
+
name: exports_external.string().optional().describe("New trigger name"),
|
|
7577
|
+
description: exports_external.string().optional().describe("New trigger description"),
|
|
7578
|
+
toolArguments: exports_external.record(exports_external.unknown()).optional().describe("New tool arguments"),
|
|
7579
|
+
schedule: exports_external.union([
|
|
7580
|
+
exports_external.object({
|
|
7581
|
+
type: exports_external.literal("once"),
|
|
7582
|
+
runAt: exports_external.string().describe("ISO datetime string")
|
|
7583
|
+
}),
|
|
7584
|
+
exports_external.object({
|
|
7585
|
+
type: exports_external.literal("cron"),
|
|
7586
|
+
expression: exports_external.string().describe("Cron expression")
|
|
7587
|
+
})
|
|
7588
|
+
]).optional().describe("New schedule")
|
|
7589
|
+
}),
|
|
7590
|
+
execute: async (args) => {
|
|
7591
|
+
const { triggerId, ...updates } = args;
|
|
7592
|
+
const updatesWithTimestamp = {
|
|
7593
|
+
...updates,
|
|
7594
|
+
updatedAt: new Date().toISOString()
|
|
7595
|
+
};
|
|
7596
|
+
return callbacks.update(triggerId, updatesWithTimestamp, context);
|
|
7597
|
+
}
|
|
7598
|
+
},
|
|
7599
|
+
delete_trigger: {
|
|
7600
|
+
description: "Delete a trigger permanently. This cannot be undone.",
|
|
7601
|
+
inputSchema: exports_external.object({
|
|
7602
|
+
triggerId: exports_external.string().describe("The trigger ID to delete")
|
|
7603
|
+
}),
|
|
7604
|
+
execute: async (args) => {
|
|
7605
|
+
await callbacks.delete(args.triggerId, context);
|
|
7606
|
+
return { success: true, message: `Trigger ${args.triggerId} deleted` };
|
|
7607
|
+
}
|
|
7608
|
+
},
|
|
7609
|
+
pause_trigger: {
|
|
7610
|
+
description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
|
|
7611
|
+
inputSchema: exports_external.object({
|
|
7612
|
+
triggerId: exports_external.string().describe("The trigger ID to pause")
|
|
7613
|
+
}),
|
|
7614
|
+
execute: async (args) => {
|
|
7615
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7616
|
+
if (!trigger) {
|
|
7617
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7618
|
+
}
|
|
7619
|
+
const validation = validateStatusTransition(trigger.status, "paused");
|
|
7620
|
+
if (!validation.valid) {
|
|
7621
|
+
throw new Error(validation.error);
|
|
7622
|
+
}
|
|
7623
|
+
return callbacks.update(args.triggerId, {
|
|
7624
|
+
status: "paused",
|
|
7625
|
+
updatedAt: new Date().toISOString()
|
|
7626
|
+
}, context);
|
|
7627
|
+
}
|
|
7628
|
+
},
|
|
7629
|
+
resume_trigger: {
|
|
7630
|
+
description: "Resume a paused trigger to start executing it again on schedule",
|
|
7631
|
+
inputSchema: exports_external.object({
|
|
7632
|
+
triggerId: exports_external.string().describe("The trigger ID to resume")
|
|
7633
|
+
}),
|
|
7634
|
+
execute: async (args) => {
|
|
7635
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7636
|
+
if (!trigger) {
|
|
7637
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7638
|
+
}
|
|
7639
|
+
const validation = validateStatusTransition(trigger.status, "active");
|
|
7640
|
+
if (!validation.valid) {
|
|
7641
|
+
throw new Error(validation.error);
|
|
7642
|
+
}
|
|
7643
|
+
return callbacks.update(args.triggerId, {
|
|
7644
|
+
status: "active",
|
|
7645
|
+
updatedAt: new Date().toISOString()
|
|
7646
|
+
}, context);
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7649
|
+
};
|
|
7650
|
+
}
|
|
7651
|
+
var init_trigger_tools = __esm(() => {
|
|
7652
|
+
init_zod();
|
|
7653
|
+
init_utils2();
|
|
7654
|
+
});
|
|
7655
|
+
|
|
7432
7656
|
// ../ai/vercel-ai.ts
|
|
7433
7657
|
function convertMCPToolToVercelAI(mcpTool, client, options) {
|
|
7434
7658
|
return {
|
|
@@ -7456,10 +7680,16 @@ async function getVercelAITools(client, options) {
|
|
|
7456
7680
|
for (const mcpTool of mcpTools) {
|
|
7457
7681
|
vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
|
|
7458
7682
|
}
|
|
7683
|
+
const triggerConfig = client.__triggerConfig;
|
|
7684
|
+
if (triggerConfig) {
|
|
7685
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
7686
|
+
Object.assign(vercelTools, triggerTools);
|
|
7687
|
+
}
|
|
7459
7688
|
return vercelTools;
|
|
7460
7689
|
}
|
|
7461
7690
|
var init_vercel_ai = __esm(() => {
|
|
7462
7691
|
init_utils();
|
|
7692
|
+
init_trigger_tools();
|
|
7463
7693
|
});
|
|
7464
7694
|
|
|
7465
7695
|
// ../ai/openai.ts
|
|
@@ -7483,10 +7713,48 @@ async function getOpenAITools(client, options) {
|
|
|
7483
7713
|
}
|
|
7484
7714
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7485
7715
|
const mcpTools = client.getEnabledTools();
|
|
7486
|
-
|
|
7716
|
+
const openaiTools = mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
|
|
7717
|
+
const triggerConfig = client.__triggerConfig;
|
|
7718
|
+
if (triggerConfig) {
|
|
7719
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
7720
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
7721
|
+
const zodSchema = tool.inputSchema;
|
|
7722
|
+
const jsonSchema = zodToJsonSchema(zodSchema);
|
|
7723
|
+
openaiTools.push({
|
|
7724
|
+
type: "function",
|
|
7725
|
+
name,
|
|
7726
|
+
parameters: jsonSchema,
|
|
7727
|
+
strict: options?.strict ?? null,
|
|
7728
|
+
description: tool.description || null
|
|
7729
|
+
});
|
|
7730
|
+
}
|
|
7731
|
+
}
|
|
7732
|
+
return openaiTools;
|
|
7733
|
+
}
|
|
7734
|
+
function zodToJsonSchema(schema) {
|
|
7735
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
7736
|
+
const shape = schema._def.shape();
|
|
7737
|
+
const properties = {};
|
|
7738
|
+
const required = [];
|
|
7739
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
7740
|
+
const fieldSchema = value;
|
|
7741
|
+
properties[key] = { type: "string" };
|
|
7742
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
7743
|
+
required.push(key);
|
|
7744
|
+
}
|
|
7745
|
+
}
|
|
7746
|
+
return {
|
|
7747
|
+
type: "object",
|
|
7748
|
+
properties,
|
|
7749
|
+
...required.length > 0 ? { required } : {}
|
|
7750
|
+
};
|
|
7751
|
+
}
|
|
7752
|
+
return { type: "object" };
|
|
7487
7753
|
}
|
|
7488
7754
|
async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
7489
7755
|
const toolOutputs = [];
|
|
7756
|
+
const triggerConfig = client.__triggerConfig;
|
|
7757
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7490
7758
|
for (const output of toolCalls) {
|
|
7491
7759
|
if (output.type === "function_call") {
|
|
7492
7760
|
const toolCall = {
|
|
@@ -7496,7 +7764,12 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
7496
7764
|
};
|
|
7497
7765
|
try {
|
|
7498
7766
|
const args = JSON.parse(toolCall.arguments);
|
|
7499
|
-
|
|
7767
|
+
let result;
|
|
7768
|
+
if (triggerTools && triggerTools[toolCall.name]) {
|
|
7769
|
+
result = await triggerTools[toolCall.name].execute(args);
|
|
7770
|
+
} else {
|
|
7771
|
+
result = await executeToolWithToken(client, toolCall.name, args, options);
|
|
7772
|
+
}
|
|
7500
7773
|
const resultString = JSON.stringify(result);
|
|
7501
7774
|
toolOutputs.push({
|
|
7502
7775
|
call_id: output.call_id ?? output.id ?? "",
|
|
@@ -7532,6 +7805,7 @@ async function handleOpenAIResponse(client, response, options) {
|
|
|
7532
7805
|
}
|
|
7533
7806
|
var init_openai = __esm(() => {
|
|
7534
7807
|
init_utils();
|
|
7808
|
+
init_trigger_tools();
|
|
7535
7809
|
});
|
|
7536
7810
|
|
|
7537
7811
|
// ../ai/anthropic.ts
|
|
@@ -7548,10 +7822,17 @@ function convertMCPToolToAnthropic(mcpTool, _client, _options) {
|
|
|
7548
7822
|
}
|
|
7549
7823
|
async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
7550
7824
|
const toolResults = [];
|
|
7825
|
+
const triggerConfig = client.__triggerConfig;
|
|
7826
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7551
7827
|
const toolUseBlocks = messageContent.filter((block) => block.type === "tool_use" && ("id" in block) && ("name" in block) && ("input" in block));
|
|
7552
7828
|
for (const toolUse of toolUseBlocks) {
|
|
7553
7829
|
try {
|
|
7554
|
-
|
|
7830
|
+
let result;
|
|
7831
|
+
if (triggerTools && triggerTools[toolUse.name]) {
|
|
7832
|
+
result = await triggerTools[toolUse.name].execute(toolUse.input);
|
|
7833
|
+
} else {
|
|
7834
|
+
result = await executeToolWithToken(client, toolUse.name, toolUse.input, options);
|
|
7835
|
+
}
|
|
7555
7836
|
const resultString = JSON.stringify(result);
|
|
7556
7837
|
toolResults.push({
|
|
7557
7838
|
type: "tool_result",
|
|
@@ -7580,7 +7861,41 @@ async function getAnthropicTools(client, options) {
|
|
|
7580
7861
|
}
|
|
7581
7862
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7582
7863
|
const mcpTools = client.getEnabledTools();
|
|
7583
|
-
|
|
7864
|
+
const anthropicTools = mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
|
|
7865
|
+
const triggerConfig = client.__triggerConfig;
|
|
7866
|
+
if (triggerConfig) {
|
|
7867
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
7868
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
7869
|
+
const zodSchema = tool.inputSchema;
|
|
7870
|
+
const jsonSchema = zodToAnthropicSchema(zodSchema);
|
|
7871
|
+
anthropicTools.push({
|
|
7872
|
+
name,
|
|
7873
|
+
description: tool.description || `Execute ${name}`,
|
|
7874
|
+
input_schema: jsonSchema
|
|
7875
|
+
});
|
|
7876
|
+
}
|
|
7877
|
+
}
|
|
7878
|
+
return anthropicTools;
|
|
7879
|
+
}
|
|
7880
|
+
function zodToAnthropicSchema(schema) {
|
|
7881
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
7882
|
+
const shape = schema._def.shape();
|
|
7883
|
+
const properties = {};
|
|
7884
|
+
const required = [];
|
|
7885
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
7886
|
+
const fieldSchema = value;
|
|
7887
|
+
properties[key] = { type: "string" };
|
|
7888
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
7889
|
+
required.push(key);
|
|
7890
|
+
}
|
|
7891
|
+
}
|
|
7892
|
+
return {
|
|
7893
|
+
type: "object",
|
|
7894
|
+
properties,
|
|
7895
|
+
...required.length > 0 ? { required } : {}
|
|
7896
|
+
};
|
|
7897
|
+
}
|
|
7898
|
+
return { type: "object", properties: {}, required: [] };
|
|
7584
7899
|
}
|
|
7585
7900
|
async function handleAnthropicMessage(client, message, options) {
|
|
7586
7901
|
let providerTokens = options?.providerTokens;
|
|
@@ -7607,6 +7922,7 @@ async function handleAnthropicMessage(client, message, options) {
|
|
|
7607
7922
|
}
|
|
7608
7923
|
var init_anthropic = __esm(() => {
|
|
7609
7924
|
init_utils();
|
|
7925
|
+
init_trigger_tools();
|
|
7610
7926
|
});
|
|
7611
7927
|
|
|
7612
7928
|
// ../ai/google.ts
|
|
@@ -7689,12 +8005,19 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
7689
8005
|
} catch {}
|
|
7690
8006
|
}
|
|
7691
8007
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
8008
|
+
const triggerConfig = client.__triggerConfig;
|
|
8009
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7692
8010
|
const results = await Promise.all(functionCalls.map(async (call) => {
|
|
7693
8011
|
if (!call?.name) {
|
|
7694
8012
|
throw new Error("Function call must have a name");
|
|
7695
8013
|
}
|
|
7696
8014
|
const args = call.args || {};
|
|
7697
|
-
|
|
8015
|
+
let result;
|
|
8016
|
+
if (triggerTools && triggerTools[call.name]) {
|
|
8017
|
+
result = await triggerTools[call.name].execute(args);
|
|
8018
|
+
} else {
|
|
8019
|
+
result = await executeToolWithToken(client, call.name, args, finalOptions);
|
|
8020
|
+
}
|
|
7698
8021
|
return JSON.stringify(result);
|
|
7699
8022
|
}));
|
|
7700
8023
|
return results;
|
|
@@ -7709,10 +8032,46 @@ async function getGoogleTools(client, options) {
|
|
|
7709
8032
|
}
|
|
7710
8033
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7711
8034
|
const mcpTools = client.getEnabledTools();
|
|
7712
|
-
|
|
8035
|
+
const googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|
|
8036
|
+
const triggerConfig = client.__triggerConfig;
|
|
8037
|
+
if (triggerConfig) {
|
|
8038
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
8039
|
+
const TypeEnum = await getGoogleType();
|
|
8040
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
8041
|
+
const zodSchema = tool.inputSchema;
|
|
8042
|
+
const jsonSchema = zodToGoogleSchema(zodSchema, TypeEnum);
|
|
8043
|
+
googleTools.push({
|
|
8044
|
+
name,
|
|
8045
|
+
description: tool.description || `Execute ${name}`,
|
|
8046
|
+
parameters: jsonSchema
|
|
8047
|
+
});
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
8050
|
+
return googleTools;
|
|
8051
|
+
}
|
|
8052
|
+
function zodToGoogleSchema(schema, TypeEnum) {
|
|
8053
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
8054
|
+
const shape = schema._def.shape();
|
|
8055
|
+
const properties = {};
|
|
8056
|
+
const required = [];
|
|
8057
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
8058
|
+
const fieldSchema = value;
|
|
8059
|
+
properties[key] = { type: TypeEnum.STRING };
|
|
8060
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
8061
|
+
required.push(key);
|
|
8062
|
+
}
|
|
8063
|
+
}
|
|
8064
|
+
return {
|
|
8065
|
+
type: TypeEnum.OBJECT,
|
|
8066
|
+
properties,
|
|
8067
|
+
...required.length > 0 ? { required } : {}
|
|
8068
|
+
};
|
|
8069
|
+
}
|
|
8070
|
+
return { type: TypeEnum.OBJECT, properties: {} };
|
|
7713
8071
|
}
|
|
7714
8072
|
var init_google = __esm(() => {
|
|
7715
8073
|
init_utils();
|
|
8074
|
+
init_trigger_tools();
|
|
7716
8075
|
});
|
|
7717
8076
|
|
|
7718
8077
|
// ../ai/index.ts
|
|
@@ -7721,71 +8080,7 @@ var init_ai = __esm(() => {
|
|
|
7721
8080
|
init_openai();
|
|
7722
8081
|
init_anthropic();
|
|
7723
8082
|
init_google();
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
// ../../node_modules/nanoid/url-alphabet/index.js
|
|
7727
|
-
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
7728
|
-
var init_url_alphabet = () => {};
|
|
7729
|
-
|
|
7730
|
-
// ../../node_modules/nanoid/index.js
|
|
7731
|
-
import crypto2 from "crypto";
|
|
7732
|
-
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset, fillPool = (bytes) => {
|
|
7733
|
-
if (!pool || pool.length < bytes) {
|
|
7734
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
7735
|
-
crypto2.randomFillSync(pool);
|
|
7736
|
-
poolOffset = 0;
|
|
7737
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
7738
|
-
crypto2.randomFillSync(pool);
|
|
7739
|
-
poolOffset = 0;
|
|
7740
|
-
}
|
|
7741
|
-
poolOffset += bytes;
|
|
7742
|
-
}, nanoid = (size = 21) => {
|
|
7743
|
-
fillPool(size |= 0);
|
|
7744
|
-
let id = "";
|
|
7745
|
-
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
7746
|
-
id += urlAlphabet[pool[i] & 63];
|
|
7747
|
-
}
|
|
7748
|
-
return id;
|
|
7749
|
-
};
|
|
7750
|
-
var init_nanoid = __esm(() => {
|
|
7751
|
-
init_url_alphabet();
|
|
7752
|
-
});
|
|
7753
|
-
|
|
7754
|
-
// ../triggers/utils.ts
|
|
7755
|
-
var exports_utils = {};
|
|
7756
|
-
__export(exports_utils, {
|
|
7757
|
-
validateStatusTransition: () => validateStatusTransition,
|
|
7758
|
-
generateTriggerId: () => generateTriggerId,
|
|
7759
|
-
extractProviderFromToolName: () => extractProviderFromToolName,
|
|
7760
|
-
calculateHasMore: () => calculateHasMore
|
|
7761
|
-
});
|
|
7762
|
-
function generateTriggerId() {
|
|
7763
|
-
return `trig_${nanoid(12)}`;
|
|
7764
|
-
}
|
|
7765
|
-
function extractProviderFromToolName(toolName) {
|
|
7766
|
-
const parts = toolName.split("_");
|
|
7767
|
-
return parts[0] || toolName;
|
|
7768
|
-
}
|
|
7769
|
-
function validateStatusTransition(currentStatus, targetStatus) {
|
|
7770
|
-
if (targetStatus === "paused" && currentStatus !== "active") {
|
|
7771
|
-
return {
|
|
7772
|
-
valid: false,
|
|
7773
|
-
error: `Cannot pause trigger with status '${currentStatus}'. Only 'active' triggers can be paused.`
|
|
7774
|
-
};
|
|
7775
|
-
}
|
|
7776
|
-
if (targetStatus === "active" && currentStatus !== "paused") {
|
|
7777
|
-
return {
|
|
7778
|
-
valid: false,
|
|
7779
|
-
error: `Cannot resume trigger with status '${currentStatus}'. Only 'paused' triggers can be resumed.`
|
|
7780
|
-
};
|
|
7781
|
-
}
|
|
7782
|
-
return { valid: true };
|
|
7783
|
-
}
|
|
7784
|
-
function calculateHasMore(offset, returnedCount, total) {
|
|
7785
|
-
return offset + returnedCount < total;
|
|
7786
|
-
}
|
|
7787
|
-
var init_utils2 = __esm(() => {
|
|
7788
|
-
init_nanoid();
|
|
8083
|
+
init_trigger_tools();
|
|
7789
8084
|
});
|
|
7790
8085
|
|
|
7791
8086
|
// ../server.ts
|
|
@@ -7825,6 +8120,7 @@ __export(exports_server, {
|
|
|
7825
8120
|
figmaIntegration: () => figmaIntegration,
|
|
7826
8121
|
executeGoogleFunctionCalls: () => executeGoogleFunctionCalls,
|
|
7827
8122
|
cursorIntegration: () => cursorIntegration,
|
|
8123
|
+
createTriggerTools: () => createTriggerTools,
|
|
7828
8124
|
createSimpleIntegration: () => createSimpleIntegration,
|
|
7829
8125
|
createMCPServer: () => createMCPServer,
|
|
7830
8126
|
calcomIntegration: () => calcomIntegration,
|
|
@@ -7922,6 +8218,10 @@ function createMCPServer(config) {
|
|
|
7922
8218
|
setProviderToken: config.setProviderToken,
|
|
7923
8219
|
removeProviderToken: config.removeProviderToken
|
|
7924
8220
|
};
|
|
8221
|
+
client.__triggerConfig = config.triggers ? {
|
|
8222
|
+
callbacks: config.triggers,
|
|
8223
|
+
getSessionContext: config.getSessionContext
|
|
8224
|
+
} : undefined;
|
|
7925
8225
|
const { POST, GET } = createOAuthRouteHandlers({
|
|
7926
8226
|
providers,
|
|
7927
8227
|
serverUrl: config.serverUrl,
|