integrate-sdk 0.8.35 → 0.8.37
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/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/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/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/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/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/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/oauth.js
CHANGED
|
@@ -7633,6 +7633,230 @@ var init_utils = __esm(() => {
|
|
|
7633
7633
|
init_zod();
|
|
7634
7634
|
});
|
|
7635
7635
|
|
|
7636
|
+
// node_modules/nanoid/url-alphabet/index.js
|
|
7637
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
7638
|
+
var init_url_alphabet = () => {};
|
|
7639
|
+
|
|
7640
|
+
// node_modules/nanoid/index.js
|
|
7641
|
+
import crypto2 from "crypto";
|
|
7642
|
+
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset, fillPool = (bytes) => {
|
|
7643
|
+
if (!pool || pool.length < bytes) {
|
|
7644
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
7645
|
+
crypto2.randomFillSync(pool);
|
|
7646
|
+
poolOffset = 0;
|
|
7647
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
7648
|
+
crypto2.randomFillSync(pool);
|
|
7649
|
+
poolOffset = 0;
|
|
7650
|
+
}
|
|
7651
|
+
poolOffset += bytes;
|
|
7652
|
+
}, nanoid = (size = 21) => {
|
|
7653
|
+
fillPool(size |= 0);
|
|
7654
|
+
let id = "";
|
|
7655
|
+
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
7656
|
+
id += urlAlphabet[pool[i] & 63];
|
|
7657
|
+
}
|
|
7658
|
+
return id;
|
|
7659
|
+
};
|
|
7660
|
+
var init_nanoid = __esm(() => {
|
|
7661
|
+
init_url_alphabet();
|
|
7662
|
+
});
|
|
7663
|
+
|
|
7664
|
+
// src/triggers/utils.ts
|
|
7665
|
+
var exports_utils = {};
|
|
7666
|
+
__export(exports_utils, {
|
|
7667
|
+
validateStatusTransition: () => validateStatusTransition,
|
|
7668
|
+
generateTriggerId: () => generateTriggerId,
|
|
7669
|
+
extractProviderFromToolName: () => extractProviderFromToolName,
|
|
7670
|
+
calculateHasMore: () => calculateHasMore
|
|
7671
|
+
});
|
|
7672
|
+
function generateTriggerId() {
|
|
7673
|
+
return `trig_${nanoid(12)}`;
|
|
7674
|
+
}
|
|
7675
|
+
function extractProviderFromToolName(toolName) {
|
|
7676
|
+
const parts = toolName.split("_");
|
|
7677
|
+
return parts[0] || toolName;
|
|
7678
|
+
}
|
|
7679
|
+
function validateStatusTransition(currentStatus, targetStatus) {
|
|
7680
|
+
if (targetStatus === "paused" && currentStatus !== "active") {
|
|
7681
|
+
return {
|
|
7682
|
+
valid: false,
|
|
7683
|
+
error: `Cannot pause trigger with status '${currentStatus}'. Only 'active' triggers can be paused.`
|
|
7684
|
+
};
|
|
7685
|
+
}
|
|
7686
|
+
if (targetStatus === "active" && currentStatus !== "paused") {
|
|
7687
|
+
return {
|
|
7688
|
+
valid: false,
|
|
7689
|
+
error: `Cannot resume trigger with status '${currentStatus}'. Only 'paused' triggers can be resumed.`
|
|
7690
|
+
};
|
|
7691
|
+
}
|
|
7692
|
+
return { valid: true };
|
|
7693
|
+
}
|
|
7694
|
+
function calculateHasMore(offset, returnedCount, total) {
|
|
7695
|
+
return offset + returnedCount < total;
|
|
7696
|
+
}
|
|
7697
|
+
var init_utils2 = __esm(() => {
|
|
7698
|
+
init_nanoid();
|
|
7699
|
+
});
|
|
7700
|
+
|
|
7701
|
+
// src/ai/trigger-tools.ts
|
|
7702
|
+
function createTriggerTools(config, context) {
|
|
7703
|
+
const { callbacks } = config;
|
|
7704
|
+
return {
|
|
7705
|
+
create_trigger: {
|
|
7706
|
+
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.",
|
|
7707
|
+
inputSchema: exports_external.object({
|
|
7708
|
+
name: exports_external.string().optional().describe("Human-readable trigger name"),
|
|
7709
|
+
description: exports_external.string().optional().describe("Trigger description"),
|
|
7710
|
+
toolName: exports_external.string().describe("MCP tool name to execute (e.g., gmail_send_email, github_create_issue)"),
|
|
7711
|
+
toolArguments: exports_external.record(exports_external.unknown()).describe("Arguments to pass to the tool when it executes"),
|
|
7712
|
+
schedule: exports_external.union([
|
|
7713
|
+
exports_external.object({
|
|
7714
|
+
type: exports_external.literal("once"),
|
|
7715
|
+
runAt: exports_external.string().describe("ISO datetime string (e.g., 2024-12-13T22:00:00Z)")
|
|
7716
|
+
}),
|
|
7717
|
+
exports_external.object({
|
|
7718
|
+
type: exports_external.literal("cron"),
|
|
7719
|
+
expression: exports_external.string().describe("Cron expression (e.g., '0 9 * * *' for daily at 9 AM)")
|
|
7720
|
+
})
|
|
7721
|
+
]).describe("When to execute the tool")
|
|
7722
|
+
}),
|
|
7723
|
+
execute: async (args) => {
|
|
7724
|
+
const triggerId = generateTriggerId();
|
|
7725
|
+
const provider = extractProviderFromToolName(args.toolName);
|
|
7726
|
+
const now = new Date().toISOString();
|
|
7727
|
+
const trigger = {
|
|
7728
|
+
id: triggerId,
|
|
7729
|
+
...args,
|
|
7730
|
+
provider,
|
|
7731
|
+
status: "active",
|
|
7732
|
+
createdAt: now,
|
|
7733
|
+
updatedAt: now,
|
|
7734
|
+
runCount: 0
|
|
7735
|
+
};
|
|
7736
|
+
return callbacks.create(trigger, context);
|
|
7737
|
+
}
|
|
7738
|
+
},
|
|
7739
|
+
list_triggers: {
|
|
7740
|
+
description: "List all scheduled triggers with optional filtering by status or tool name",
|
|
7741
|
+
inputSchema: exports_external.object({
|
|
7742
|
+
status: exports_external.enum(["active", "paused", "completed", "failed"]).optional().describe("Filter by trigger status"),
|
|
7743
|
+
toolName: exports_external.string().optional().describe("Filter by tool name"),
|
|
7744
|
+
limit: exports_external.number().optional().describe("Maximum number of results (default: 20)"),
|
|
7745
|
+
offset: exports_external.number().optional().describe("Number of results to skip for pagination (default: 0)")
|
|
7746
|
+
}),
|
|
7747
|
+
execute: async (args) => {
|
|
7748
|
+
const params = {
|
|
7749
|
+
status: args.status,
|
|
7750
|
+
toolName: args.toolName,
|
|
7751
|
+
limit: args.limit || 20,
|
|
7752
|
+
offset: args.offset || 0
|
|
7753
|
+
};
|
|
7754
|
+
const result = await callbacks.list(params, context);
|
|
7755
|
+
const hasMore = calculateHasMore(params.offset, result.triggers.length, result.total);
|
|
7756
|
+
return {
|
|
7757
|
+
triggers: result.triggers,
|
|
7758
|
+
total: result.total,
|
|
7759
|
+
hasMore
|
|
7760
|
+
};
|
|
7761
|
+
}
|
|
7762
|
+
},
|
|
7763
|
+
get_trigger: {
|
|
7764
|
+
description: "Get details of a specific trigger by its ID",
|
|
7765
|
+
inputSchema: exports_external.object({
|
|
7766
|
+
triggerId: exports_external.string().describe("The trigger ID to retrieve")
|
|
7767
|
+
}),
|
|
7768
|
+
execute: async (args) => {
|
|
7769
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7770
|
+
if (!trigger) {
|
|
7771
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7772
|
+
}
|
|
7773
|
+
return trigger;
|
|
7774
|
+
}
|
|
7775
|
+
},
|
|
7776
|
+
update_trigger: {
|
|
7777
|
+
description: "Update a trigger's properties like name, description, arguments, or schedule",
|
|
7778
|
+
inputSchema: exports_external.object({
|
|
7779
|
+
triggerId: exports_external.string().describe("The trigger ID to update"),
|
|
7780
|
+
name: exports_external.string().optional().describe("New trigger name"),
|
|
7781
|
+
description: exports_external.string().optional().describe("New trigger description"),
|
|
7782
|
+
toolArguments: exports_external.record(exports_external.unknown()).optional().describe("New tool arguments"),
|
|
7783
|
+
schedule: exports_external.union([
|
|
7784
|
+
exports_external.object({
|
|
7785
|
+
type: exports_external.literal("once"),
|
|
7786
|
+
runAt: exports_external.string().describe("ISO datetime string")
|
|
7787
|
+
}),
|
|
7788
|
+
exports_external.object({
|
|
7789
|
+
type: exports_external.literal("cron"),
|
|
7790
|
+
expression: exports_external.string().describe("Cron expression")
|
|
7791
|
+
})
|
|
7792
|
+
]).optional().describe("New schedule")
|
|
7793
|
+
}),
|
|
7794
|
+
execute: async (args) => {
|
|
7795
|
+
const { triggerId, ...updates } = args;
|
|
7796
|
+
const updatesWithTimestamp = {
|
|
7797
|
+
...updates,
|
|
7798
|
+
updatedAt: new Date().toISOString()
|
|
7799
|
+
};
|
|
7800
|
+
return callbacks.update(triggerId, updatesWithTimestamp, context);
|
|
7801
|
+
}
|
|
7802
|
+
},
|
|
7803
|
+
delete_trigger: {
|
|
7804
|
+
description: "Delete a trigger permanently. This cannot be undone.",
|
|
7805
|
+
inputSchema: exports_external.object({
|
|
7806
|
+
triggerId: exports_external.string().describe("The trigger ID to delete")
|
|
7807
|
+
}),
|
|
7808
|
+
execute: async (args) => {
|
|
7809
|
+
await callbacks.delete(args.triggerId, context);
|
|
7810
|
+
return { success: true, message: `Trigger ${args.triggerId} deleted` };
|
|
7811
|
+
}
|
|
7812
|
+
},
|
|
7813
|
+
pause_trigger: {
|
|
7814
|
+
description: "Pause a trigger to temporarily stop it from executing. Can be resumed later.",
|
|
7815
|
+
inputSchema: exports_external.object({
|
|
7816
|
+
triggerId: exports_external.string().describe("The trigger ID to pause")
|
|
7817
|
+
}),
|
|
7818
|
+
execute: async (args) => {
|
|
7819
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7820
|
+
if (!trigger) {
|
|
7821
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7822
|
+
}
|
|
7823
|
+
const validation = validateStatusTransition(trigger.status, "paused");
|
|
7824
|
+
if (!validation.valid) {
|
|
7825
|
+
throw new Error(validation.error);
|
|
7826
|
+
}
|
|
7827
|
+
return callbacks.update(args.triggerId, {
|
|
7828
|
+
status: "paused",
|
|
7829
|
+
updatedAt: new Date().toISOString()
|
|
7830
|
+
}, context);
|
|
7831
|
+
}
|
|
7832
|
+
},
|
|
7833
|
+
resume_trigger: {
|
|
7834
|
+
description: "Resume a paused trigger to start executing it again on schedule",
|
|
7835
|
+
inputSchema: exports_external.object({
|
|
7836
|
+
triggerId: exports_external.string().describe("The trigger ID to resume")
|
|
7837
|
+
}),
|
|
7838
|
+
execute: async (args) => {
|
|
7839
|
+
const trigger = await callbacks.get(args.triggerId, context);
|
|
7840
|
+
if (!trigger) {
|
|
7841
|
+
throw new Error(`Trigger ${args.triggerId} not found`);
|
|
7842
|
+
}
|
|
7843
|
+
const validation = validateStatusTransition(trigger.status, "active");
|
|
7844
|
+
if (!validation.valid) {
|
|
7845
|
+
throw new Error(validation.error);
|
|
7846
|
+
}
|
|
7847
|
+
return callbacks.update(args.triggerId, {
|
|
7848
|
+
status: "active",
|
|
7849
|
+
updatedAt: new Date().toISOString()
|
|
7850
|
+
}, context);
|
|
7851
|
+
}
|
|
7852
|
+
}
|
|
7853
|
+
};
|
|
7854
|
+
}
|
|
7855
|
+
var init_trigger_tools = __esm(() => {
|
|
7856
|
+
init_zod();
|
|
7857
|
+
init_utils2();
|
|
7858
|
+
});
|
|
7859
|
+
|
|
7636
7860
|
// src/ai/vercel-ai.ts
|
|
7637
7861
|
function convertMCPToolToVercelAI(mcpTool, client, options) {
|
|
7638
7862
|
return {
|
|
@@ -7660,10 +7884,16 @@ async function getVercelAITools(client, options) {
|
|
|
7660
7884
|
for (const mcpTool of mcpTools) {
|
|
7661
7885
|
vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
|
|
7662
7886
|
}
|
|
7887
|
+
const triggerConfig = client.__triggerConfig;
|
|
7888
|
+
if (triggerConfig) {
|
|
7889
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
7890
|
+
Object.assign(vercelTools, triggerTools);
|
|
7891
|
+
}
|
|
7663
7892
|
return vercelTools;
|
|
7664
7893
|
}
|
|
7665
7894
|
var init_vercel_ai = __esm(() => {
|
|
7666
7895
|
init_utils();
|
|
7896
|
+
init_trigger_tools();
|
|
7667
7897
|
});
|
|
7668
7898
|
|
|
7669
7899
|
// src/ai/openai.ts
|
|
@@ -7687,10 +7917,48 @@ async function getOpenAITools(client, options) {
|
|
|
7687
7917
|
}
|
|
7688
7918
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7689
7919
|
const mcpTools = client.getEnabledTools();
|
|
7690
|
-
|
|
7920
|
+
const openaiTools = mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
|
|
7921
|
+
const triggerConfig = client.__triggerConfig;
|
|
7922
|
+
if (triggerConfig) {
|
|
7923
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
7924
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
7925
|
+
const zodSchema = tool.inputSchema;
|
|
7926
|
+
const jsonSchema = zodToJsonSchema(zodSchema);
|
|
7927
|
+
openaiTools.push({
|
|
7928
|
+
type: "function",
|
|
7929
|
+
name,
|
|
7930
|
+
parameters: jsonSchema,
|
|
7931
|
+
strict: options?.strict ?? null,
|
|
7932
|
+
description: tool.description || null
|
|
7933
|
+
});
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
return openaiTools;
|
|
7937
|
+
}
|
|
7938
|
+
function zodToJsonSchema(schema) {
|
|
7939
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
7940
|
+
const shape = schema._def.shape();
|
|
7941
|
+
const properties = {};
|
|
7942
|
+
const required = [];
|
|
7943
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
7944
|
+
const fieldSchema = value;
|
|
7945
|
+
properties[key] = { type: "string" };
|
|
7946
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
7947
|
+
required.push(key);
|
|
7948
|
+
}
|
|
7949
|
+
}
|
|
7950
|
+
return {
|
|
7951
|
+
type: "object",
|
|
7952
|
+
properties,
|
|
7953
|
+
...required.length > 0 ? { required } : {}
|
|
7954
|
+
};
|
|
7955
|
+
}
|
|
7956
|
+
return { type: "object" };
|
|
7691
7957
|
}
|
|
7692
7958
|
async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
7693
7959
|
const toolOutputs = [];
|
|
7960
|
+
const triggerConfig = client.__triggerConfig;
|
|
7961
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7694
7962
|
for (const output of toolCalls) {
|
|
7695
7963
|
if (output.type === "function_call") {
|
|
7696
7964
|
const toolCall = {
|
|
@@ -7700,7 +7968,12 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
7700
7968
|
};
|
|
7701
7969
|
try {
|
|
7702
7970
|
const args = JSON.parse(toolCall.arguments);
|
|
7703
|
-
|
|
7971
|
+
let result;
|
|
7972
|
+
if (triggerTools && triggerTools[toolCall.name]) {
|
|
7973
|
+
result = await triggerTools[toolCall.name].execute(args);
|
|
7974
|
+
} else {
|
|
7975
|
+
result = await executeToolWithToken(client, toolCall.name, args, options);
|
|
7976
|
+
}
|
|
7704
7977
|
const resultString = JSON.stringify(result);
|
|
7705
7978
|
toolOutputs.push({
|
|
7706
7979
|
call_id: output.call_id ?? output.id ?? "",
|
|
@@ -7736,6 +8009,7 @@ async function handleOpenAIResponse(client, response, options) {
|
|
|
7736
8009
|
}
|
|
7737
8010
|
var init_openai = __esm(() => {
|
|
7738
8011
|
init_utils();
|
|
8012
|
+
init_trigger_tools();
|
|
7739
8013
|
});
|
|
7740
8014
|
|
|
7741
8015
|
// src/ai/anthropic.ts
|
|
@@ -7752,10 +8026,17 @@ function convertMCPToolToAnthropic(mcpTool, _client, _options) {
|
|
|
7752
8026
|
}
|
|
7753
8027
|
async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
7754
8028
|
const toolResults = [];
|
|
8029
|
+
const triggerConfig = client.__triggerConfig;
|
|
8030
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7755
8031
|
const toolUseBlocks = messageContent.filter((block) => block.type === "tool_use" && ("id" in block) && ("name" in block) && ("input" in block));
|
|
7756
8032
|
for (const toolUse of toolUseBlocks) {
|
|
7757
8033
|
try {
|
|
7758
|
-
|
|
8034
|
+
let result;
|
|
8035
|
+
if (triggerTools && triggerTools[toolUse.name]) {
|
|
8036
|
+
result = await triggerTools[toolUse.name].execute(toolUse.input);
|
|
8037
|
+
} else {
|
|
8038
|
+
result = await executeToolWithToken(client, toolUse.name, toolUse.input, options);
|
|
8039
|
+
}
|
|
7759
8040
|
const resultString = JSON.stringify(result);
|
|
7760
8041
|
toolResults.push({
|
|
7761
8042
|
type: "tool_result",
|
|
@@ -7784,7 +8065,41 @@ async function getAnthropicTools(client, options) {
|
|
|
7784
8065
|
}
|
|
7785
8066
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7786
8067
|
const mcpTools = client.getEnabledTools();
|
|
7787
|
-
|
|
8068
|
+
const anthropicTools = mcpTools.map((mcpTool) => convertMCPToolToAnthropic(mcpTool, client, finalOptions));
|
|
8069
|
+
const triggerConfig = client.__triggerConfig;
|
|
8070
|
+
if (triggerConfig) {
|
|
8071
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
8072
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
8073
|
+
const zodSchema = tool.inputSchema;
|
|
8074
|
+
const jsonSchema = zodToAnthropicSchema(zodSchema);
|
|
8075
|
+
anthropicTools.push({
|
|
8076
|
+
name,
|
|
8077
|
+
description: tool.description || `Execute ${name}`,
|
|
8078
|
+
input_schema: jsonSchema
|
|
8079
|
+
});
|
|
8080
|
+
}
|
|
8081
|
+
}
|
|
8082
|
+
return anthropicTools;
|
|
8083
|
+
}
|
|
8084
|
+
function zodToAnthropicSchema(schema) {
|
|
8085
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
8086
|
+
const shape = schema._def.shape();
|
|
8087
|
+
const properties = {};
|
|
8088
|
+
const required = [];
|
|
8089
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
8090
|
+
const fieldSchema = value;
|
|
8091
|
+
properties[key] = { type: "string" };
|
|
8092
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
8093
|
+
required.push(key);
|
|
8094
|
+
}
|
|
8095
|
+
}
|
|
8096
|
+
return {
|
|
8097
|
+
type: "object",
|
|
8098
|
+
properties,
|
|
8099
|
+
...required.length > 0 ? { required } : {}
|
|
8100
|
+
};
|
|
8101
|
+
}
|
|
8102
|
+
return { type: "object", properties: {}, required: [] };
|
|
7788
8103
|
}
|
|
7789
8104
|
async function handleAnthropicMessage(client, message, options) {
|
|
7790
8105
|
let providerTokens = options?.providerTokens;
|
|
@@ -7811,6 +8126,7 @@ async function handleAnthropicMessage(client, message, options) {
|
|
|
7811
8126
|
}
|
|
7812
8127
|
var init_anthropic = __esm(() => {
|
|
7813
8128
|
init_utils();
|
|
8129
|
+
init_trigger_tools();
|
|
7814
8130
|
});
|
|
7815
8131
|
|
|
7816
8132
|
// src/ai/google.ts
|
|
@@ -7893,12 +8209,19 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
7893
8209
|
} catch {}
|
|
7894
8210
|
}
|
|
7895
8211
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
8212
|
+
const triggerConfig = client.__triggerConfig;
|
|
8213
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
7896
8214
|
const results = await Promise.all(functionCalls.map(async (call) => {
|
|
7897
8215
|
if (!call?.name) {
|
|
7898
8216
|
throw new Error("Function call must have a name");
|
|
7899
8217
|
}
|
|
7900
8218
|
const args = call.args || {};
|
|
7901
|
-
|
|
8219
|
+
let result;
|
|
8220
|
+
if (triggerTools && triggerTools[call.name]) {
|
|
8221
|
+
result = await triggerTools[call.name].execute(args);
|
|
8222
|
+
} else {
|
|
8223
|
+
result = await executeToolWithToken(client, call.name, args, finalOptions);
|
|
8224
|
+
}
|
|
7902
8225
|
return JSON.stringify(result);
|
|
7903
8226
|
}));
|
|
7904
8227
|
return results;
|
|
@@ -7913,10 +8236,46 @@ async function getGoogleTools(client, options) {
|
|
|
7913
8236
|
}
|
|
7914
8237
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
7915
8238
|
const mcpTools = client.getEnabledTools();
|
|
7916
|
-
|
|
8239
|
+
const googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|
|
8240
|
+
const triggerConfig = client.__triggerConfig;
|
|
8241
|
+
if (triggerConfig) {
|
|
8242
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
8243
|
+
const TypeEnum = await getGoogleType();
|
|
8244
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
8245
|
+
const zodSchema = tool.inputSchema;
|
|
8246
|
+
const jsonSchema = zodToGoogleSchema(zodSchema, TypeEnum);
|
|
8247
|
+
googleTools.push({
|
|
8248
|
+
name,
|
|
8249
|
+
description: tool.description || `Execute ${name}`,
|
|
8250
|
+
parameters: jsonSchema
|
|
8251
|
+
});
|
|
8252
|
+
}
|
|
8253
|
+
}
|
|
8254
|
+
return googleTools;
|
|
8255
|
+
}
|
|
8256
|
+
function zodToGoogleSchema(schema, TypeEnum) {
|
|
8257
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
8258
|
+
const shape = schema._def.shape();
|
|
8259
|
+
const properties = {};
|
|
8260
|
+
const required = [];
|
|
8261
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
8262
|
+
const fieldSchema = value;
|
|
8263
|
+
properties[key] = { type: TypeEnum.STRING };
|
|
8264
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
8265
|
+
required.push(key);
|
|
8266
|
+
}
|
|
8267
|
+
}
|
|
8268
|
+
return {
|
|
8269
|
+
type: TypeEnum.OBJECT,
|
|
8270
|
+
properties,
|
|
8271
|
+
...required.length > 0 ? { required } : {}
|
|
8272
|
+
};
|
|
8273
|
+
}
|
|
8274
|
+
return { type: TypeEnum.OBJECT, properties: {} };
|
|
7917
8275
|
}
|
|
7918
8276
|
var init_google = __esm(() => {
|
|
7919
8277
|
init_utils();
|
|
8278
|
+
init_trigger_tools();
|
|
7920
8279
|
});
|
|
7921
8280
|
|
|
7922
8281
|
// src/ai/index.ts
|
|
@@ -7925,71 +8284,7 @@ var init_ai = __esm(() => {
|
|
|
7925
8284
|
init_openai();
|
|
7926
8285
|
init_anthropic();
|
|
7927
8286
|
init_google();
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
// node_modules/nanoid/url-alphabet/index.js
|
|
7931
|
-
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
7932
|
-
var init_url_alphabet = () => {};
|
|
7933
|
-
|
|
7934
|
-
// node_modules/nanoid/index.js
|
|
7935
|
-
import crypto2 from "crypto";
|
|
7936
|
-
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset, fillPool = (bytes) => {
|
|
7937
|
-
if (!pool || pool.length < bytes) {
|
|
7938
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
7939
|
-
crypto2.randomFillSync(pool);
|
|
7940
|
-
poolOffset = 0;
|
|
7941
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
7942
|
-
crypto2.randomFillSync(pool);
|
|
7943
|
-
poolOffset = 0;
|
|
7944
|
-
}
|
|
7945
|
-
poolOffset += bytes;
|
|
7946
|
-
}, nanoid = (size = 21) => {
|
|
7947
|
-
fillPool(size |= 0);
|
|
7948
|
-
let id = "";
|
|
7949
|
-
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
7950
|
-
id += urlAlphabet[pool[i] & 63];
|
|
7951
|
-
}
|
|
7952
|
-
return id;
|
|
7953
|
-
};
|
|
7954
|
-
var init_nanoid = __esm(() => {
|
|
7955
|
-
init_url_alphabet();
|
|
7956
|
-
});
|
|
7957
|
-
|
|
7958
|
-
// src/triggers/utils.ts
|
|
7959
|
-
var exports_utils = {};
|
|
7960
|
-
__export(exports_utils, {
|
|
7961
|
-
validateStatusTransition: () => validateStatusTransition,
|
|
7962
|
-
generateTriggerId: () => generateTriggerId,
|
|
7963
|
-
extractProviderFromToolName: () => extractProviderFromToolName,
|
|
7964
|
-
calculateHasMore: () => calculateHasMore
|
|
7965
|
-
});
|
|
7966
|
-
function generateTriggerId() {
|
|
7967
|
-
return `trig_${nanoid(12)}`;
|
|
7968
|
-
}
|
|
7969
|
-
function extractProviderFromToolName(toolName) {
|
|
7970
|
-
const parts = toolName.split("_");
|
|
7971
|
-
return parts[0] || toolName;
|
|
7972
|
-
}
|
|
7973
|
-
function validateStatusTransition(currentStatus, targetStatus) {
|
|
7974
|
-
if (targetStatus === "paused" && currentStatus !== "active") {
|
|
7975
|
-
return {
|
|
7976
|
-
valid: false,
|
|
7977
|
-
error: `Cannot pause trigger with status '${currentStatus}'. Only 'active' triggers can be paused.`
|
|
7978
|
-
};
|
|
7979
|
-
}
|
|
7980
|
-
if (targetStatus === "active" && currentStatus !== "paused") {
|
|
7981
|
-
return {
|
|
7982
|
-
valid: false,
|
|
7983
|
-
error: `Cannot resume trigger with status '${currentStatus}'. Only 'paused' triggers can be resumed.`
|
|
7984
|
-
};
|
|
7985
|
-
}
|
|
7986
|
-
return { valid: true };
|
|
7987
|
-
}
|
|
7988
|
-
function calculateHasMore(offset, returnedCount, total) {
|
|
7989
|
-
return offset + returnedCount < total;
|
|
7990
|
-
}
|
|
7991
|
-
var init_utils2 = __esm(() => {
|
|
7992
|
-
init_nanoid();
|
|
8287
|
+
init_trigger_tools();
|
|
7993
8288
|
});
|
|
7994
8289
|
|
|
7995
8290
|
// src/server.ts
|
|
@@ -8029,6 +8324,7 @@ __export(exports_server, {
|
|
|
8029
8324
|
figmaIntegration: () => figmaIntegration,
|
|
8030
8325
|
executeGoogleFunctionCalls: () => executeGoogleFunctionCalls,
|
|
8031
8326
|
cursorIntegration: () => cursorIntegration,
|
|
8327
|
+
createTriggerTools: () => createTriggerTools,
|
|
8032
8328
|
createSimpleIntegration: () => createSimpleIntegration,
|
|
8033
8329
|
createMCPServer: () => createMCPServer,
|
|
8034
8330
|
calcomIntegration: () => calcomIntegration,
|
|
@@ -8126,6 +8422,10 @@ function createMCPServer(config) {
|
|
|
8126
8422
|
setProviderToken: config.setProviderToken,
|
|
8127
8423
|
removeProviderToken: config.removeProviderToken
|
|
8128
8424
|
};
|
|
8425
|
+
client.__triggerConfig = config.triggers ? {
|
|
8426
|
+
callbacks: config.triggers,
|
|
8427
|
+
getSessionContext: config.getSessionContext
|
|
8428
|
+
} : undefined;
|
|
8129
8429
|
const { POST, GET } = createOAuthRouteHandlers({
|
|
8130
8430
|
providers,
|
|
8131
8431
|
serverUrl: config.serverUrl,
|