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.
Files changed (39) hide show
  1. package/dist/adapters/auto-routes.js +371 -71
  2. package/dist/adapters/index.js +371 -71
  3. package/dist/adapters/nextjs.js +371 -71
  4. package/dist/adapters/node.js +371 -71
  5. package/dist/adapters/svelte-kit.js +371 -71
  6. package/dist/adapters/tanstack-start.js +371 -71
  7. package/dist/ai/anthropic.d.ts +3 -0
  8. package/dist/ai/anthropic.d.ts.map +1 -1
  9. package/dist/ai/anthropic.js +255 -2
  10. package/dist/ai/google.d.ts +3 -0
  11. package/dist/ai/google.d.ts.map +1 -1
  12. package/dist/ai/google.js +256 -2
  13. package/dist/ai/index.d.ts +1 -0
  14. package/dist/ai/index.d.ts.map +1 -1
  15. package/dist/ai/index.js +351 -7
  16. package/dist/ai/openai.d.ts +3 -0
  17. package/dist/ai/openai.d.ts.map +1 -1
  18. package/dist/ai/openai.js +257 -2
  19. package/dist/ai/trigger-tools.d.ts +206 -0
  20. package/dist/ai/trigger-tools.d.ts.map +1 -0
  21. package/dist/ai/trigger-tools.js +4198 -0
  22. package/dist/ai/vercel-ai.d.ts.map +1 -1
  23. package/dist/ai/vercel-ai.js +217 -0
  24. package/dist/index.js +359 -59
  25. package/dist/oauth.js +371 -71
  26. package/dist/server.js +372 -71
  27. package/dist/src/ai/anthropic.d.ts +3 -0
  28. package/dist/src/ai/anthropic.d.ts.map +1 -1
  29. package/dist/src/ai/google.d.ts +3 -0
  30. package/dist/src/ai/google.d.ts.map +1 -1
  31. package/dist/src/ai/index.d.ts +1 -0
  32. package/dist/src/ai/index.d.ts.map +1 -1
  33. package/dist/src/ai/openai.d.ts +3 -0
  34. package/dist/src/ai/openai.d.ts.map +1 -1
  35. package/dist/src/ai/trigger-tools.d.ts +206 -0
  36. package/dist/src/ai/trigger-tools.d.ts.map +1 -0
  37. package/dist/src/ai/vercel-ai.d.ts.map +1 -1
  38. package/dist/src/server.d.ts.map +1 -1
  39. package/package.json +1 -1
package/dist/ai/openai.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
  // openai.ts
4193
4405
  function convertMCPToolToOpenAI(mcpTool, _client, options) {
4194
4406
  const inputParams = mcpTool.inputSchema;
@@ -4210,10 +4422,48 @@ async function getOpenAITools(client, options) {
4210
4422
  }
4211
4423
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
4212
4424
  const mcpTools = client.getEnabledTools();
4213
- return mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
4425
+ const openaiTools = mcpTools.map((mcpTool) => convertMCPToolToOpenAI(mcpTool, client, finalOptions));
4426
+ const triggerConfig = client.__triggerConfig;
4427
+ if (triggerConfig) {
4428
+ const triggerTools = createTriggerTools(triggerConfig, options?.context);
4429
+ for (const [name, tool] of Object.entries(triggerTools)) {
4430
+ const zodSchema = tool.inputSchema;
4431
+ const jsonSchema = zodToJsonSchema(zodSchema);
4432
+ openaiTools.push({
4433
+ type: "function",
4434
+ name,
4435
+ parameters: jsonSchema,
4436
+ strict: options?.strict ?? null,
4437
+ description: tool.description || null
4438
+ });
4439
+ }
4440
+ }
4441
+ return openaiTools;
4442
+ }
4443
+ function zodToJsonSchema(schema) {
4444
+ if (schema._def?.typeName === "ZodObject") {
4445
+ const shape = schema._def.shape();
4446
+ const properties = {};
4447
+ const required = [];
4448
+ for (const [key, value] of Object.entries(shape)) {
4449
+ const fieldSchema = value;
4450
+ properties[key] = { type: "string" };
4451
+ if (fieldSchema._def?.typeName !== "ZodOptional") {
4452
+ required.push(key);
4453
+ }
4454
+ }
4455
+ return {
4456
+ type: "object",
4457
+ properties,
4458
+ ...required.length > 0 ? { required } : {}
4459
+ };
4460
+ }
4461
+ return { type: "object" };
4214
4462
  }
4215
4463
  async function handleOpenAIToolCalls(client, toolCalls, options) {
4216
4464
  const toolOutputs = [];
4465
+ const triggerConfig = client.__triggerConfig;
4466
+ const triggerTools = triggerConfig ? createTriggerTools(triggerConfig, options?.context) : null;
4217
4467
  for (const output of toolCalls) {
4218
4468
  if (output.type === "function_call") {
4219
4469
  const toolCall = {
@@ -4223,7 +4473,12 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
4223
4473
  };
4224
4474
  try {
4225
4475
  const args = JSON.parse(toolCall.arguments);
4226
- const result = await executeToolWithToken(client, toolCall.name, args, options);
4476
+ let result;
4477
+ if (triggerTools && triggerTools[toolCall.name]) {
4478
+ result = await triggerTools[toolCall.name].execute(args);
4479
+ } else {
4480
+ result = await executeToolWithToken(client, toolCall.name, args, options);
4481
+ }
4227
4482
  const resultString = JSON.stringify(result);
4228
4483
  toolOutputs.push({
4229
4484
  call_id: output.call_id ?? output.id ?? "",
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Trigger Management Tools for AI
3
+ *
4
+ * SDK-level tools that call trigger callbacks directly
5
+ * Automatically included in AI provider helpers when triggers are configured
6
+ */
7
+ import { z } from "zod";
8
+ import type { MCPContext } from "../config/types.js";
9
+ import type { TriggerCallbacks } from "../triggers/types.js";
10
+ /**
11
+ * Configuration for trigger tools
12
+ */
13
+ export interface TriggerToolsConfig {
14
+ /** Trigger storage callbacks */
15
+ callbacks: TriggerCallbacks;
16
+ /** Session context extraction function */
17
+ getSessionContext?: (request: Request) => Promise<MCPContext | undefined> | MCPContext | undefined;
18
+ }
19
+ /**
20
+ * Create trigger management tools for AI providers
21
+ * These tools call the trigger callbacks directly with pre-processing
22
+ *
23
+ * @param config - Trigger configuration including callbacks
24
+ * @param context - Optional user context for multi-tenant support
25
+ * @returns Object containing trigger management tools
26
+ */
27
+ export declare function createTriggerTools(config: TriggerToolsConfig, context?: MCPContext): {
28
+ create_trigger: {
29
+ description: string;
30
+ inputSchema: z.ZodObject<{
31
+ name: z.ZodOptional<z.ZodString>;
32
+ description: z.ZodOptional<z.ZodString>;
33
+ toolName: z.ZodString;
34
+ toolArguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
35
+ schedule: z.ZodUnion<[z.ZodObject<{
36
+ type: z.ZodLiteral<"once">;
37
+ runAt: z.ZodString;
38
+ }, "strip", z.ZodTypeAny, {
39
+ type: "once";
40
+ runAt: string;
41
+ }, {
42
+ type: "once";
43
+ runAt: string;
44
+ }>, z.ZodObject<{
45
+ type: z.ZodLiteral<"cron">;
46
+ expression: z.ZodString;
47
+ }, "strip", z.ZodTypeAny, {
48
+ type: "cron";
49
+ expression: string;
50
+ }, {
51
+ type: "cron";
52
+ expression: string;
53
+ }>]>;
54
+ }, "strip", z.ZodTypeAny, {
55
+ toolName: string;
56
+ toolArguments: Record<string, unknown>;
57
+ schedule: {
58
+ type: "once";
59
+ runAt: string;
60
+ } | {
61
+ type: "cron";
62
+ expression: string;
63
+ };
64
+ name?: string | undefined;
65
+ description?: string | undefined;
66
+ }, {
67
+ toolName: string;
68
+ toolArguments: Record<string, unknown>;
69
+ schedule: {
70
+ type: "once";
71
+ runAt: string;
72
+ } | {
73
+ type: "cron";
74
+ expression: string;
75
+ };
76
+ name?: string | undefined;
77
+ description?: string | undefined;
78
+ }>;
79
+ execute: (args: any) => Promise<import("../index.js").Trigger>;
80
+ };
81
+ list_triggers: {
82
+ description: string;
83
+ inputSchema: z.ZodObject<{
84
+ status: z.ZodOptional<z.ZodEnum<["active", "paused", "completed", "failed"]>>;
85
+ toolName: z.ZodOptional<z.ZodString>;
86
+ limit: z.ZodOptional<z.ZodNumber>;
87
+ offset: z.ZodOptional<z.ZodNumber>;
88
+ }, "strip", z.ZodTypeAny, {
89
+ toolName?: string | undefined;
90
+ status?: "active" | "paused" | "completed" | "failed" | undefined;
91
+ limit?: number | undefined;
92
+ offset?: number | undefined;
93
+ }, {
94
+ toolName?: string | undefined;
95
+ status?: "active" | "paused" | "completed" | "failed" | undefined;
96
+ limit?: number | undefined;
97
+ offset?: number | undefined;
98
+ }>;
99
+ execute: (args: any) => Promise<{
100
+ triggers: import("../index.js").Trigger[];
101
+ total: number;
102
+ hasMore: boolean;
103
+ }>;
104
+ };
105
+ get_trigger: {
106
+ description: string;
107
+ inputSchema: z.ZodObject<{
108
+ triggerId: z.ZodString;
109
+ }, "strip", z.ZodTypeAny, {
110
+ triggerId: string;
111
+ }, {
112
+ triggerId: string;
113
+ }>;
114
+ execute: (args: any) => Promise<import("../index.js").Trigger>;
115
+ };
116
+ update_trigger: {
117
+ description: string;
118
+ inputSchema: z.ZodObject<{
119
+ triggerId: z.ZodString;
120
+ name: z.ZodOptional<z.ZodString>;
121
+ description: z.ZodOptional<z.ZodString>;
122
+ toolArguments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
123
+ schedule: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
124
+ type: z.ZodLiteral<"once">;
125
+ runAt: z.ZodString;
126
+ }, "strip", z.ZodTypeAny, {
127
+ type: "once";
128
+ runAt: string;
129
+ }, {
130
+ type: "once";
131
+ runAt: string;
132
+ }>, z.ZodObject<{
133
+ type: z.ZodLiteral<"cron">;
134
+ expression: z.ZodString;
135
+ }, "strip", z.ZodTypeAny, {
136
+ type: "cron";
137
+ expression: string;
138
+ }, {
139
+ type: "cron";
140
+ expression: string;
141
+ }>]>>;
142
+ }, "strip", z.ZodTypeAny, {
143
+ triggerId: string;
144
+ name?: string | undefined;
145
+ description?: string | undefined;
146
+ toolArguments?: Record<string, unknown> | undefined;
147
+ schedule?: {
148
+ type: "once";
149
+ runAt: string;
150
+ } | {
151
+ type: "cron";
152
+ expression: string;
153
+ } | undefined;
154
+ }, {
155
+ triggerId: string;
156
+ name?: string | undefined;
157
+ description?: string | undefined;
158
+ toolArguments?: Record<string, unknown> | undefined;
159
+ schedule?: {
160
+ type: "once";
161
+ runAt: string;
162
+ } | {
163
+ type: "cron";
164
+ expression: string;
165
+ } | undefined;
166
+ }>;
167
+ execute: (args: any) => Promise<import("../index.js").Trigger>;
168
+ };
169
+ delete_trigger: {
170
+ description: string;
171
+ inputSchema: z.ZodObject<{
172
+ triggerId: z.ZodString;
173
+ }, "strip", z.ZodTypeAny, {
174
+ triggerId: string;
175
+ }, {
176
+ triggerId: string;
177
+ }>;
178
+ execute: (args: any) => Promise<{
179
+ success: boolean;
180
+ message: string;
181
+ }>;
182
+ };
183
+ pause_trigger: {
184
+ description: string;
185
+ inputSchema: z.ZodObject<{
186
+ triggerId: z.ZodString;
187
+ }, "strip", z.ZodTypeAny, {
188
+ triggerId: string;
189
+ }, {
190
+ triggerId: string;
191
+ }>;
192
+ execute: (args: any) => Promise<import("../index.js").Trigger>;
193
+ };
194
+ resume_trigger: {
195
+ description: string;
196
+ inputSchema: z.ZodObject<{
197
+ triggerId: z.ZodString;
198
+ }, "strip", z.ZodTypeAny, {
199
+ triggerId: string;
200
+ }, {
201
+ triggerId: string;
202
+ }>;
203
+ execute: (args: any) => Promise<import("../index.js").Trigger>;
204
+ };
205
+ };
206
+ //# sourceMappingURL=trigger-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-tools.d.ts","sourceRoot":"","sources":["../../../src/ai/trigger-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAQ7D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,gCAAgC;IAChC,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0CAA0C;IAC1C,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC;CACpG;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsBvD,GAAG;;;;;;;;;;;;;;;;;;;;wBA4BH,GAAG;;;;;;;;;;;;;;;wBA2BH,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6BH,GAAG;;;;;;;;;;;wBAkBH,GAAG;;;;;;;;;;;;;;wBAWH,GAAG;;;;;;;;;;;wBA+BH,GAAG;;EA0B9B"}