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/index.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;
|
|
@@ -4341,12 +4594,19 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
4341
4594
|
} catch {}
|
|
4342
4595
|
}
|
|
4343
4596
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4597
|
+
const triggerConfig = client.__triggerConfig;
|
|
4598
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
4344
4599
|
const results = await Promise.all(functionCalls.map(async (call) => {
|
|
4345
4600
|
if (!call?.name) {
|
|
4346
4601
|
throw new Error("Function call must have a name");
|
|
4347
4602
|
}
|
|
4348
4603
|
const args = call.args || {};
|
|
4349
|
-
|
|
4604
|
+
let result;
|
|
4605
|
+
if (triggerTools && triggerTools[call.name]) {
|
|
4606
|
+
result = await triggerTools[call.name].execute(args);
|
|
4607
|
+
} else {
|
|
4608
|
+
result = await executeToolWithToken(client, call.name, args, finalOptions);
|
|
4609
|
+
}
|
|
4350
4610
|
return JSON.stringify(result);
|
|
4351
4611
|
}));
|
|
4352
4612
|
return results;
|
|
@@ -4361,7 +4621,42 @@ async function getGoogleTools(client, options) {
|
|
|
4361
4621
|
}
|
|
4362
4622
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4363
4623
|
const mcpTools = client.getEnabledTools();
|
|
4364
|
-
|
|
4624
|
+
const googleTools = await Promise.all(mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, finalOptions)));
|
|
4625
|
+
const triggerConfig = client.__triggerConfig;
|
|
4626
|
+
if (triggerConfig) {
|
|
4627
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
4628
|
+
const TypeEnum = await getGoogleType();
|
|
4629
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
4630
|
+
const zodSchema = tool.inputSchema;
|
|
4631
|
+
const jsonSchema = zodToGoogleSchema(zodSchema, TypeEnum);
|
|
4632
|
+
googleTools.push({
|
|
4633
|
+
name,
|
|
4634
|
+
description: tool.description || `Execute ${name}`,
|
|
4635
|
+
parameters: jsonSchema
|
|
4636
|
+
});
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
return googleTools;
|
|
4640
|
+
}
|
|
4641
|
+
function zodToGoogleSchema(schema, TypeEnum) {
|
|
4642
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
4643
|
+
const shape = schema._def.shape();
|
|
4644
|
+
const properties = {};
|
|
4645
|
+
const required = [];
|
|
4646
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
4647
|
+
const fieldSchema = value;
|
|
4648
|
+
properties[key] = { type: TypeEnum.STRING };
|
|
4649
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
4650
|
+
required.push(key);
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4653
|
+
return {
|
|
4654
|
+
type: TypeEnum.OBJECT,
|
|
4655
|
+
properties,
|
|
4656
|
+
...required.length > 0 ? { required } : {}
|
|
4657
|
+
};
|
|
4658
|
+
}
|
|
4659
|
+
return { type: TypeEnum.OBJECT, properties: {} };
|
|
4365
4660
|
}
|
|
4366
4661
|
|
|
4367
4662
|
// vercel-ai.ts
|
|
@@ -4391,6 +4686,11 @@ async function getVercelAITools(client, options) {
|
|
|
4391
4686
|
for (const mcpTool of mcpTools) {
|
|
4392
4687
|
vercelTools[mcpTool.name] = convertMCPToolToVercelAI(mcpTool, client, finalOptions);
|
|
4393
4688
|
}
|
|
4689
|
+
const triggerConfig = client.__triggerConfig;
|
|
4690
|
+
if (triggerConfig) {
|
|
4691
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
4692
|
+
Object.assign(vercelTools, triggerTools);
|
|
4693
|
+
}
|
|
4394
4694
|
return vercelTools;
|
|
4395
4695
|
}
|
|
4396
4696
|
|
|
@@ -4415,10 +4715,48 @@ async function getOpenAITools(client, options) {
|
|
|
4415
4715
|
}
|
|
4416
4716
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4417
4717
|
const mcpTools = client.getEnabledTools();
|
|
4418
|
-
|
|
4718
|
+
const openaiTools = mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
|
|
4719
|
+
const triggerConfig = client.__triggerConfig;
|
|
4720
|
+
if (triggerConfig) {
|
|
4721
|
+
const triggerTools = createTriggerTools(triggerConfig, options?.context);
|
|
4722
|
+
for (const [name, tool] of Object.entries(triggerTools)) {
|
|
4723
|
+
const zodSchema = tool.inputSchema;
|
|
4724
|
+
const jsonSchema = zodToJsonSchema(zodSchema);
|
|
4725
|
+
openaiTools.push({
|
|
4726
|
+
type: "function",
|
|
4727
|
+
name,
|
|
4728
|
+
parameters: jsonSchema,
|
|
4729
|
+
strict: options?.strict ?? null,
|
|
4730
|
+
description: tool.description || null
|
|
4731
|
+
});
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
return openaiTools;
|
|
4735
|
+
}
|
|
4736
|
+
function zodToJsonSchema(schema) {
|
|
4737
|
+
if (schema._def?.typeName === "ZodObject") {
|
|
4738
|
+
const shape = schema._def.shape();
|
|
4739
|
+
const properties = {};
|
|
4740
|
+
const required = [];
|
|
4741
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
4742
|
+
const fieldSchema = value;
|
|
4743
|
+
properties[key] = { type: "string" };
|
|
4744
|
+
if (fieldSchema._def?.typeName !== "ZodOptional") {
|
|
4745
|
+
required.push(key);
|
|
4746
|
+
}
|
|
4747
|
+
}
|
|
4748
|
+
return {
|
|
4749
|
+
type: "object",
|
|
4750
|
+
properties,
|
|
4751
|
+
...required.length > 0 ? { required } : {}
|
|
4752
|
+
};
|
|
4753
|
+
}
|
|
4754
|
+
return { type: "object" };
|
|
4419
4755
|
}
|
|
4420
4756
|
async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
4421
4757
|
const toolOutputs = [];
|
|
4758
|
+
const triggerConfig = client.__triggerConfig;
|
|
4759
|
+
const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
|
|
4422
4760
|
for (const output of toolCalls) {
|
|
4423
4761
|
if (output.type === "function_call") {
|
|
4424
4762
|
const toolCall = {
|
|
@@ -4428,7 +4766,12 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
4428
4766
|
};
|
|
4429
4767
|
try {
|
|
4430
4768
|
const args = JSON.parse(toolCall.arguments);
|
|
4431
|
-
|
|
4769
|
+
let result;
|
|
4770
|
+
if (triggerTools && triggerTools[toolCall.name]) {
|
|
4771
|
+
result = await triggerTools[toolCall.name].execute(args);
|
|
4772
|
+
} else {
|
|
4773
|
+
result = await executeToolWithToken(client, toolCall.name, args, options);
|
|
4774
|
+
}
|
|
4432
4775
|
const resultString = JSON.stringify(result);
|
|
4433
4776
|
toolOutputs.push({
|
|
4434
4777
|
call_id: output.call_id ?? output.id ?? "",
|
|
@@ -4469,5 +4812,6 @@ export {
|
|
|
4469
4812
|
getOpenAITools,
|
|
4470
4813
|
getGoogleTools,
|
|
4471
4814
|
getAnthropicTools,
|
|
4472
|
-
executeGoogleFunctionCalls
|
|
4815
|
+
executeGoogleFunctionCalls,
|
|
4816
|
+
createTriggerTools
|
|
4473
4817
|
};
|
package/dist/ai/openai.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Helper functions to convert MCP tools to OpenAI Responses API 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 { OpenAI } from "openai";
|
|
9
10
|
/**
|
|
@@ -28,6 +29,8 @@ export interface OpenAIToolsOptions extends AIToolsOptions {
|
|
|
28
29
|
* @default false
|
|
29
30
|
*/
|
|
30
31
|
strict?: boolean;
|
|
32
|
+
/** User context for multi-tenant token storage */
|
|
33
|
+
context?: MCPContext;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Get tools in a format compatible with OpenAI Responses API
|
package/dist/ai/openai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.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":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/openai.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;AAEjH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GAAG,IAAI,CAAC;IACT,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAsHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,QAAQ,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,EAChE,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,GAAG;IAAE,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAA,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAyB3H"}
|