integrate-sdk 0.8.36 → 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/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;
|
package/dist/ai/google.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Helper functions to convert MCP tools to Google GenAI format
|
|
5
5
|
*/
|
|
6
6
|
import type { MCPClient } from "../client.js";
|
|
7
|
+
import type { MCPContext } from "../config/types.js";
|
|
7
8
|
import { type AIToolsOptions } from "./utils.js";
|
|
8
9
|
import type { Schema, FunctionDeclaration, FunctionCall, Type } from "@google/genai";
|
|
9
10
|
export type GoogleTool = FunctionDeclaration;
|
|
@@ -13,6 +14,8 @@ export type { Schema, Type };
|
|
|
13
14
|
* Options for converting MCP tools to Google GenAI format
|
|
14
15
|
*/
|
|
15
16
|
export interface GoogleToolsOptions extends AIToolsOptions {
|
|
17
|
+
/** User context for multi-tenant token storage */
|
|
18
|
+
context?: MCPContext;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* Execute multiple function calls from Google GenAI response
|
package/dist/ai/google.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAKjH,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,YAAY,EACZ,IAAI,EACL,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC9C,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAuB7B;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAsGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,aAAa,EAAE,kBAAkB,EAAE,GAAG,SAAS,GAAG,IAAI,EACtD,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC,CA2CnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAwCvB"}
|
package/dist/ai/google.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
|
// google.ts
|
|
4193
4405
|
async function getGoogleType() {
|
|
4194
4406
|
try {
|
|
@@ -4269,12 +4481,19 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
4269
4481
|
} catch {}
|
|
4270
4482
|
}
|
|
4271
4483
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4484
|
+
const triggerConfig = client.__triggerConfig;
|
|
4485
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
4272
4486
|
const results = await Promise.all(functionCalls.map(async (call) => {
|
|
4273
4487
|
if (!call?.name) {
|
|
4274
4488
|
throw new Error("Function call must have a name");
|
|
4275
4489
|
}
|
|
4276
4490
|
const args = call.args || {};
|
|
4277
|
-
|
|
4491
|
+
let result;
|
|
4492
|
+
if (triggerTools && triggerTools[call.name]) {
|
|
4493
|
+
result = await triggerTools[call.name].execute(args);
|
|
4494
|
+
} else {
|
|
4495
|
+
result = await executeToolWithToken(client, call.name, args, finalOptions);
|
|
4496
|
+
}
|
|
4278
4497
|
return JSON.stringify(result);
|
|
4279
4498
|
}));
|
|
4280
4499
|
return results;
|
|
@@ -4289,7 +4508,42 @@ async function getGoogleTools(client, options) {
|
|
|
4289
4508
|
}
|
|
4290
4509
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4291
4510
|
const mcpTools = client.getEnabledTools();
|
|
4292
|
-
|
|
4511
|
+
const googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|
|
4512
|
+
const triggerConfig = client.__triggerConfig;
|
|
4513
|
+
if (triggerConfig) {
|
|
4514
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
4515
|
+
const TypeEnum = await getGoogleType();
|
|
4516
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
4517
|
+
const zodSchema = tool.inputSchema;
|
|
4518
|
+
const jsonSchema = zodToGoogleSchema(zodSchema, TypeEnum);
|
|
4519
|
+
googleTools.push({
|
|
4520
|
+
name,
|
|
4521
|
+
description: tool.description || `Execute ${name}`,
|
|
4522
|
+
parameters: jsonSchema
|
|
4523
|
+
});
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
return googleTools;
|
|
4527
|
+
}
|
|
4528
|
+
function zodToGoogleSchema(schema, TypeEnum) {
|
|
4529
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
4530
|
+
const shape = schema._def.shape();
|
|
4531
|
+
const properties = {};
|
|
4532
|
+
const required = [];
|
|
4533
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
4534
|
+
const fieldSchema = value;
|
|
4535
|
+
properties[key] = { type: TypeEnum.STRING };
|
|
4536
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
4537
|
+
required.push(key);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
return {
|
|
4541
|
+
type: TypeEnum.OBJECT,
|
|
4542
|
+
properties,
|
|
4543
|
+
...required.length > 0 ? { required } : {}
|
|
4544
|
+
};
|
|
4545
|
+
}
|
|
4546
|
+
return { type: TypeEnum.OBJECT, properties: {} };
|
|
4293
4547
|
}
|
|
4294
4548
|
export {
|
|
4295
4549
|
getGoogleTools,
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export { getVercelAITools, type VercelAITool, type VercelAIToolsOptions } from "
|
|
|
7
7
|
export { getOpenAITools, handleOpenAIResponse, type OpenAITool, type OpenAIToolsOptions } from "./openai.js";
|
|
8
8
|
export { getAnthropicTools, handleAnthropicMessage, type AnthropicTool, type AnthropicToolsOptions, type AnthropicToolUseBlock, type AnthropicToolResultBlock } from "./anthropic.js";
|
|
9
9
|
export { getGoogleTools, executeGoogleFunctionCalls, type GoogleTool, type GoogleFunctionCall, type GoogleToolsOptions } from "./google.js";
|
|
10
|
+
export { createTriggerTools, type TriggerToolsConfig } from "./trigger-tools.js";
|
|
10
11
|
export type { AIToolsOptions } from "./utils.js";
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ai/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,kBAAkB,EAClB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|