integrate-sdk 0.7.46 → 0.7.48

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.
@@ -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;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjH,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;AAW7B;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAAI;AA4D9D;;;;;;;;;;;;GAYG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EACvB,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAqBrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAKvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,YAAY,EAAE,kBAAkB,EAChC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA2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AqBrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAKvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,YAAY,EAAE,kBAAkB,EAChC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAsBnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAevB"}
package/dist/ai/google.js CHANGED
@@ -4204,8 +4204,12 @@ async function ensureClientConnected(client) {
4204
4204
 
4205
4205
  // google.ts
4206
4206
  async function getGoogleType() {
4207
- const { Type } = await import("@google/genai");
4208
- return Type;
4207
+ const packageName = ["@google", "genai"].join("/");
4208
+ const googleGenAI = await import(packageName).catch(() => null);
4209
+ if (!googleGenAI) {
4210
+ throw new Error("The @google/genai package is required to use Google AI integration. Install it with: npm install @google/genai");
4211
+ }
4212
+ return googleGenAI.Type;
4209
4213
  }
4210
4214
  function convertJsonSchemaTypeToGoogleType(type, TypeEnum) {
4211
4215
  const typeMap = {
package/dist/ai/index.js CHANGED
@@ -4318,8 +4318,12 @@ async function getCloudflareTools(client, options) {
4318
4318
 
4319
4319
  // google.ts
4320
4320
  async function getGoogleType() {
4321
- const { Type } = await import("@google/genai");
4322
- return Type;
4321
+ const packageName = ["@google", "genai"].join("/");
4322
+ const googleGenAI = await import(packageName).catch(() => null);
4323
+ if (!googleGenAI) {
4324
+ throw new Error("The @google/genai package is required to use Google AI integration. Install it with: npm install @google/genai");
4325
+ }
4326
+ return googleGenAI.Type;
4323
4327
  }
4324
4328
  function convertJsonSchemaTypeToGoogleType(type, TypeEnum) {
4325
4329
  const typeMap = {
package/dist/server.d.ts CHANGED
@@ -18,6 +18,6 @@
18
18
  * ```
19
19
  */
20
20
  export * from './src/server.js';
21
- export * from './src/ai/index.js';
22
21
  export * from './src/adapters/index.js';
22
+ export { getVercelAITools, convertMCPToolsToVercelAI, convertMCPToolToVercelAI, getOpenAITools, convertMCPToolsToOpenAI, convertMCPToolToOpenAI, executeOpenAIToolCall, getAnthropicTools, convertMCPToolsToAnthropic, convertMCPToolToAnthropic, executeAnthropicToolCall, getGoogleTools, convertMCPToolsToGoogle, convertMCPToolToGoogle, executeGoogleFunctionCall, executeGoogleFunctionCalls, getCloudflareTools, convertMCPToolsToCloudflare, convertMCPToolToCloudflare, executeCloudflareToolCall, getLangChainTools, convertMCPToolsToLangChain, convertMCPToolToLangChain, getLlamaIndexTools, convertMCPToolsToLlamaIndex, convertMCPToolToLlamaIndex, getMastraTools, convertMCPToolsToMastra, convertMCPToolToMastra, getAITools, getProviderForTool, executeToolWithToken, type AIProviderName, type AIToolsOptions, type VercelAITool, type OpenAITool, type AnthropicTool, type GoogleTool, type CloudflareTool, } from './src/ai/index.js';
23
23
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,cAAc,iBAAiB,CAAC;AAGhC,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EAEL,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EAExB,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EAErB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EAExB,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAE1B,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,yBAAyB,EAEzB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EAEzB,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAE1B,cAAc,EACd,uBAAuB,EACvB,sBAAsB,EAEtB,UAAU,EAEV,kBAAkB,EAClB,oBAAoB,EAEpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC"}
package/dist/server.js CHANGED
@@ -2341,6 +2341,165 @@ function toSvelteKitHandler(clientOrHandlerOrOptions, _redirectOptions) {
2341
2341
  }
2342
2342
  };
2343
2343
  }
2344
+ // src/adapters/node.ts
2345
+ function fromNodeHeaders(nodeHeaders) {
2346
+ const webHeaders = new Headers;
2347
+ for (const [key, value] of Object.entries(nodeHeaders)) {
2348
+ if (value !== undefined) {
2349
+ if (Array.isArray(value)) {
2350
+ value.forEach((v) => webHeaders.append(key, v));
2351
+ } else {
2352
+ webHeaders.set(key, value);
2353
+ }
2354
+ }
2355
+ }
2356
+ return webHeaders;
2357
+ }
2358
+ async function toWebRequest(req) {
2359
+ const protocol = req.socket.encrypted ? "https" : "http";
2360
+ const host = req.headers.host || "localhost";
2361
+ const url = `${protocol}://${host}${req.url}`;
2362
+ const headers = fromNodeHeaders(req.headers);
2363
+ let body;
2364
+ if (req.method && ["POST", "PUT", "PATCH"].includes(req.method)) {
2365
+ body = await new Promise((resolve, reject) => {
2366
+ let data = "";
2367
+ req.on("data", (chunk) => data += chunk);
2368
+ req.on("end", () => resolve(data));
2369
+ req.on("error", reject);
2370
+ });
2371
+ }
2372
+ return new Request(url, {
2373
+ method: req.method,
2374
+ headers,
2375
+ body: body || undefined
2376
+ });
2377
+ }
2378
+ async function sendWebResponse(webRes, nodeRes) {
2379
+ nodeRes.statusCode = webRes.status;
2380
+ webRes.headers.forEach((value, key) => {
2381
+ nodeRes.setHeader(key, value);
2382
+ });
2383
+ const body = await webRes.text();
2384
+ nodeRes.end(body);
2385
+ }
2386
+ function toNodeHandler(config) {
2387
+ const oauthHandler = new OAuthHandler(config);
2388
+ return async (req, res) => {
2389
+ try {
2390
+ const webReq = await toWebRequest(req);
2391
+ const url = new URL(webReq.url);
2392
+ const segments = url.pathname.split("/").filter(Boolean);
2393
+ const action = segments[segments.length - 1];
2394
+ let webRes;
2395
+ if (req.method === "POST") {
2396
+ if (action === "authorize") {
2397
+ const body = await webReq.json();
2398
+ const result = await oauthHandler.handleAuthorize(body);
2399
+ webRes = new Response(JSON.stringify(result), {
2400
+ status: 200,
2401
+ headers: { "Content-Type": "application/json" }
2402
+ });
2403
+ } else if (action === "callback") {
2404
+ const body = await webReq.json();
2405
+ const result = await oauthHandler.handleCallback(body);
2406
+ webRes = new Response(JSON.stringify(result), {
2407
+ status: 200,
2408
+ headers: { "Content-Type": "application/json" }
2409
+ });
2410
+ } else if (action === "disconnect") {
2411
+ const authHeader = webReq.headers.get("authorization");
2412
+ if (!authHeader || !authHeader.startsWith("Bearer ")) {
2413
+ webRes = new Response(JSON.stringify({ error: "Missing or invalid Authorization header" }), {
2414
+ status: 400,
2415
+ headers: { "Content-Type": "application/json" }
2416
+ });
2417
+ } else {
2418
+ const accessToken = authHeader.substring(7);
2419
+ const body = await webReq.json();
2420
+ const { provider } = body;
2421
+ if (!provider) {
2422
+ webRes = new Response(JSON.stringify({ error: "Missing provider in request body" }), {
2423
+ status: 400,
2424
+ headers: { "Content-Type": "application/json" }
2425
+ });
2426
+ } else {
2427
+ const result = await oauthHandler.handleDisconnect({ provider }, accessToken);
2428
+ webRes = new Response(JSON.stringify(result), {
2429
+ status: 200,
2430
+ headers: { "Content-Type": "application/json" }
2431
+ });
2432
+ }
2433
+ }
2434
+ } else {
2435
+ webRes = new Response(JSON.stringify({ error: `Unknown action: ${action}` }), {
2436
+ status: 404,
2437
+ headers: { "Content-Type": "application/json" }
2438
+ });
2439
+ }
2440
+ } else if (req.method === "GET" && action === "status") {
2441
+ const provider = url.searchParams.get("provider");
2442
+ const authHeader = webReq.headers.get("authorization");
2443
+ if (!provider) {
2444
+ webRes = new Response(JSON.stringify({ error: "Missing provider query parameter" }), {
2445
+ status: 400,
2446
+ headers: { "Content-Type": "application/json" }
2447
+ });
2448
+ } else if (!authHeader || !authHeader.startsWith("Bearer ")) {
2449
+ webRes = new Response(JSON.stringify({ error: "Missing or invalid Authorization header" }), {
2450
+ status: 400,
2451
+ headers: { "Content-Type": "application/json" }
2452
+ });
2453
+ } else {
2454
+ const accessToken = authHeader.substring(7);
2455
+ const result = await oauthHandler.handleStatus(provider, accessToken);
2456
+ webRes = new Response(JSON.stringify(result), {
2457
+ status: 200,
2458
+ headers: { "Content-Type": "application/json" }
2459
+ });
2460
+ }
2461
+ } else {
2462
+ webRes = new Response(JSON.stringify({ error: `Unknown action: ${action}` }), {
2463
+ status: 404,
2464
+ headers: { "Content-Type": "application/json" }
2465
+ });
2466
+ }
2467
+ await sendWebResponse(webRes, res);
2468
+ } catch (error) {
2469
+ console.error("[OAuth Handler] Error:", error);
2470
+ const errorRes = new Response(JSON.stringify({ error: error.message || "Internal server error" }), {
2471
+ status: 500,
2472
+ headers: { "Content-Type": "application/json" }
2473
+ });
2474
+ await sendWebResponse(errorRes, res);
2475
+ }
2476
+ };
2477
+ }
2478
+ // src/adapters/svelte-kit.ts
2479
+ async function svelteKitHandler({
2480
+ authConfig,
2481
+ event,
2482
+ resolve,
2483
+ basePath = "/api/integrate"
2484
+ }) {
2485
+ const { url } = event;
2486
+ const baseUrl = new URL(basePath, url.origin);
2487
+ if (!url.pathname.startsWith(baseUrl.pathname)) {
2488
+ return resolve(event);
2489
+ }
2490
+ return authConfig(event.request);
2491
+ }
2492
+ // src/adapters/tanstack-start.ts
2493
+ function toTanStackStartHandler(handler) {
2494
+ const baseHandler = async ({ request }) => {
2495
+ return handler(request);
2496
+ };
2497
+ return {
2498
+ GET: baseHandler,
2499
+ POST: baseHandler
2500
+ };
2501
+ }
2502
+ var createTanStackOAuthHandler = toTanStackStartHandler;
2344
2503
  // node_modules/zod/v3/external.js
2345
2504
  var exports_external = {};
2346
2505
  __export(exports_external, {
@@ -6362,13 +6521,6 @@ async function getProviderTokens(manualTokens) {
6362
6521
  }
6363
6522
  throw new Error("Provider tokens not found. Please pass tokens manually via options.providerTokens or set the x-integrate-tokens header in your request.");
6364
6523
  }
6365
- async function tryGetProviderTokens(manualTokens) {
6366
- try {
6367
- return await getProviderTokens(manualTokens);
6368
- } catch {
6369
- return null;
6370
- }
6371
- }
6372
6524
 
6373
6525
  // src/ai/utils.ts
6374
6526
  function getProviderForTool(client, toolName) {
@@ -6580,49 +6732,6 @@ async function getOpenAITools(client, options) {
6580
6732
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
6581
6733
  return convertMCPToolsToOpenAI(client, finalOptions);
6582
6734
  }
6583
- async function handleOpenAIToolCalls(client, toolCalls, options) {
6584
- const toolOutputs = [];
6585
- for (const output of toolCalls) {
6586
- if (output.type === "function_call") {
6587
- const toolCall = {
6588
- id: output.id ?? "",
6589
- name: output.name,
6590
- arguments: output.arguments
6591
- };
6592
- try {
6593
- const result = await executeOpenAIToolCall(client, toolCall, options);
6594
- toolOutputs.push({
6595
- call_id: output.call_id ?? output.id ?? "",
6596
- type: "function_call_output",
6597
- output: result,
6598
- status: "completed"
6599
- });
6600
- } catch (error) {
6601
- toolOutputs.push({
6602
- call_id: output.call_id ?? output.id ?? "",
6603
- type: "function_call_output",
6604
- output: error instanceof Error ? error.message : "Unknown error",
6605
- status: "incomplete"
6606
- });
6607
- }
6608
- }
6609
- }
6610
- return toolOutputs;
6611
- }
6612
- async function handleOpenAIResponse(client, response, options) {
6613
- let providerTokens = options?.providerTokens;
6614
- if (!providerTokens) {
6615
- try {
6616
- providerTokens = await getProviderTokens();
6617
- } catch {}
6618
- }
6619
- const finalOptions = providerTokens ? { ...options, providerTokens } : options;
6620
- const functionCalls = response.output.filter((output) => output.type === "function_call");
6621
- if (functionCalls.length === 0) {
6622
- return response;
6623
- }
6624
- return handleOpenAIToolCalls(client, functionCalls, finalOptions);
6625
- }
6626
6735
  // src/ai/anthropic.ts
6627
6736
  function convertMCPToolToAnthropic(mcpTool, _client, _options) {
6628
6737
  return {
@@ -6643,29 +6752,6 @@ async function executeAnthropicToolCall(client, toolUse, options) {
6643
6752
  const result = await executeToolWithToken(client, toolUse.name, toolUse.input, options);
6644
6753
  return JSON.stringify(result);
6645
6754
  }
6646
- async function handleAnthropicToolCalls(client, messageContent, options) {
6647
- const toolResults = [];
6648
- const toolUseBlocks = messageContent.filter((block) => block.type === "tool_use" && ("id" in block) && ("name" in block) && ("input" in block));
6649
- for (const toolUse of toolUseBlocks) {
6650
- try {
6651
- const result = await executeAnthropicToolCall(client, toolUse, options);
6652
- toolResults.push({
6653
- type: "tool_result",
6654
- tool_use_id: toolUse.id,
6655
- content: result
6656
- });
6657
- } catch (error) {
6658
- toolResults.push({
6659
- type: "tool_result",
6660
- tool_use_id: toolUse.id,
6661
- content: JSON.stringify({
6662
- error: error instanceof Error ? error.message : "Unknown error"
6663
- })
6664
- });
6665
- }
6666
- }
6667
- return toolResults;
6668
- }
6669
6755
  async function getAnthropicTools(client, options) {
6670
6756
  await ensureClientConnected(client);
6671
6757
  let providerTokens = options?.providerTokens;
@@ -6677,29 +6763,14 @@ async function getAnthropicTools(client, options) {
6677
6763
  const finalOptions = providerTokens ? { ...options, providerTokens } : options;
6678
6764
  return convertMCPToolsToAnthropic(client, finalOptions);
6679
6765
  }
6680
- async function handleAnthropicMessage(client, message, options) {
6681
- let providerTokens = options?.providerTokens;
6682
- if (!providerTokens) {
6683
- try {
6684
- providerTokens = await getProviderTokens();
6685
- } catch {}
6686
- }
6687
- const finalOptions = providerTokens ? { ...options, providerTokens } : options;
6688
- const toolResults = await handleAnthropicToolCalls(client, message.content, finalOptions);
6689
- if (toolResults.length === 0) {
6690
- return [];
6691
- }
6692
- return [
6693
- {
6694
- role: "user",
6695
- content: toolResults
6696
- }
6697
- ];
6698
- }
6699
6766
  // src/ai/google.ts
6700
6767
  async function getGoogleType() {
6701
- const { Type } = await import("@google/genai");
6702
- return Type;
6768
+ const packageName = ["@google", "genai"].join("/");
6769
+ const googleGenAI = await import(packageName).catch(() => null);
6770
+ if (!googleGenAI) {
6771
+ throw new Error("The @google/genai package is required to use Google AI integration. Install it with: npm install @google/genai");
6772
+ }
6773
+ return googleGenAI.Type;
6703
6774
  }
6704
6775
  function convertJsonSchemaTypeToGoogleType(type, TypeEnum) {
6705
6776
  const typeMap = {
@@ -6951,183 +7022,16 @@ async function getAITools(client, provider, options) {
6951
7022
  throw new Error(`Unsupported AI provider: ${provider}`);
6952
7023
  }
6953
7024
  }
6954
- // src/adapters/node.ts
6955
- function fromNodeHeaders(nodeHeaders) {
6956
- const webHeaders = new Headers;
6957
- for (const [key, value] of Object.entries(nodeHeaders)) {
6958
- if (value !== undefined) {
6959
- if (Array.isArray(value)) {
6960
- value.forEach((v) => webHeaders.append(key, v));
6961
- } else {
6962
- webHeaders.set(key, value);
6963
- }
6964
- }
6965
- }
6966
- return webHeaders;
6967
- }
6968
- async function toWebRequest(req) {
6969
- const protocol = req.socket.encrypted ? "https" : "http";
6970
- const host = req.headers.host || "localhost";
6971
- const url = `${protocol}://${host}${req.url}`;
6972
- const headers = fromNodeHeaders(req.headers);
6973
- let body;
6974
- if (req.method && ["POST", "PUT", "PATCH"].includes(req.method)) {
6975
- body = await new Promise((resolve, reject) => {
6976
- let data = "";
6977
- req.on("data", (chunk) => data += chunk);
6978
- req.on("end", () => resolve(data));
6979
- req.on("error", reject);
6980
- });
6981
- }
6982
- return new Request(url, {
6983
- method: req.method,
6984
- headers,
6985
- body: body || undefined
6986
- });
6987
- }
6988
- async function sendWebResponse(webRes, nodeRes) {
6989
- nodeRes.statusCode = webRes.status;
6990
- webRes.headers.forEach((value, key) => {
6991
- nodeRes.setHeader(key, value);
6992
- });
6993
- const body = await webRes.text();
6994
- nodeRes.end(body);
6995
- }
6996
- function toNodeHandler(config) {
6997
- const oauthHandler = new OAuthHandler(config);
6998
- return async (req, res) => {
6999
- try {
7000
- const webReq = await toWebRequest(req);
7001
- const url = new URL(webReq.url);
7002
- const segments = url.pathname.split("/").filter(Boolean);
7003
- const action = segments[segments.length - 1];
7004
- let webRes;
7005
- if (req.method === "POST") {
7006
- if (action === "authorize") {
7007
- const body = await webReq.json();
7008
- const result = await oauthHandler.handleAuthorize(body);
7009
- webRes = new Response(JSON.stringify(result), {
7010
- status: 200,
7011
- headers: { "Content-Type": "application/json" }
7012
- });
7013
- } else if (action === "callback") {
7014
- const body = await webReq.json();
7015
- const result = await oauthHandler.handleCallback(body);
7016
- webRes = new Response(JSON.stringify(result), {
7017
- status: 200,
7018
- headers: { "Content-Type": "application/json" }
7019
- });
7020
- } else if (action === "disconnect") {
7021
- const authHeader = webReq.headers.get("authorization");
7022
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
7023
- webRes = new Response(JSON.stringify({ error: "Missing or invalid Authorization header" }), {
7024
- status: 400,
7025
- headers: { "Content-Type": "application/json" }
7026
- });
7027
- } else {
7028
- const accessToken = authHeader.substring(7);
7029
- const body = await webReq.json();
7030
- const { provider } = body;
7031
- if (!provider) {
7032
- webRes = new Response(JSON.stringify({ error: "Missing provider in request body" }), {
7033
- status: 400,
7034
- headers: { "Content-Type": "application/json" }
7035
- });
7036
- } else {
7037
- const result = await oauthHandler.handleDisconnect({ provider }, accessToken);
7038
- webRes = new Response(JSON.stringify(result), {
7039
- status: 200,
7040
- headers: { "Content-Type": "application/json" }
7041
- });
7042
- }
7043
- }
7044
- } else {
7045
- webRes = new Response(JSON.stringify({ error: `Unknown action: ${action}` }), {
7046
- status: 404,
7047
- headers: { "Content-Type": "application/json" }
7048
- });
7049
- }
7050
- } else if (req.method === "GET" && action === "status") {
7051
- const provider = url.searchParams.get("provider");
7052
- const authHeader = webReq.headers.get("authorization");
7053
- if (!provider) {
7054
- webRes = new Response(JSON.stringify({ error: "Missing provider query parameter" }), {
7055
- status: 400,
7056
- headers: { "Content-Type": "application/json" }
7057
- });
7058
- } else if (!authHeader || !authHeader.startsWith("Bearer ")) {
7059
- webRes = new Response(JSON.stringify({ error: "Missing or invalid Authorization header" }), {
7060
- status: 400,
7061
- headers: { "Content-Type": "application/json" }
7062
- });
7063
- } else {
7064
- const accessToken = authHeader.substring(7);
7065
- const result = await oauthHandler.handleStatus(provider, accessToken);
7066
- webRes = new Response(JSON.stringify(result), {
7067
- status: 200,
7068
- headers: { "Content-Type": "application/json" }
7069
- });
7070
- }
7071
- } else {
7072
- webRes = new Response(JSON.stringify({ error: `Unknown action: ${action}` }), {
7073
- status: 404,
7074
- headers: { "Content-Type": "application/json" }
7075
- });
7076
- }
7077
- await sendWebResponse(webRes, res);
7078
- } catch (error) {
7079
- console.error("[OAuth Handler] Error:", error);
7080
- const errorRes = new Response(JSON.stringify({ error: error.message || "Internal server error" }), {
7081
- status: 500,
7082
- headers: { "Content-Type": "application/json" }
7083
- });
7084
- await sendWebResponse(errorRes, res);
7085
- }
7086
- };
7087
- }
7088
- // src/adapters/svelte-kit.ts
7089
- async function svelteKitHandler({
7090
- authConfig,
7091
- event,
7092
- resolve,
7093
- basePath = "/api/integrate"
7094
- }) {
7095
- const { url } = event;
7096
- const baseUrl = new URL(basePath, url.origin);
7097
- if (!url.pathname.startsWith(baseUrl.pathname)) {
7098
- return resolve(event);
7099
- }
7100
- return authConfig(event.request);
7101
- }
7102
- // src/adapters/tanstack-start.ts
7103
- function toTanStackStartHandler(handler) {
7104
- const baseHandler = async ({ request }) => {
7105
- return handler(request);
7106
- };
7107
- return {
7108
- GET: baseHandler,
7109
- POST: baseHandler
7110
- };
7111
- }
7112
- var createTanStackOAuthHandler = toTanStackStartHandler;
7113
7025
  export {
7114
- tryGetProviderTokens,
7115
7026
  toTanStackStartHandler,
7116
7027
  toSvelteKitHandler,
7117
7028
  toSolidStartHandler,
7118
7029
  toNodeHandler,
7119
7030
  toNextJsHandler,
7120
7031
  svelteKitHandler,
7121
- jsonSchemaToZod,
7122
- jsonSchemaPropertyToZod,
7123
- handleOpenAIToolCalls,
7124
- handleOpenAIResponse,
7125
- handleAnthropicToolCalls,
7126
- handleAnthropicMessage,
7127
7032
  gmailIntegration,
7128
7033
  githubIntegration,
7129
7034
  getVercelAITools,
7130
- getProviderTokens,
7131
7035
  getProviderForTool,
7132
7036
  getOpenAITools,
7133
7037
  getMastraTools,
@@ -7145,7 +7049,6 @@ export {
7145
7049
  executeGoogleFunctionCall,
7146
7050
  executeCloudflareToolCall,
7147
7051
  executeAnthropicToolCall,
7148
- ensureClientConnected,
7149
7052
  createTanStackOAuthHandler,
7150
7053
  createSimpleIntegration,
7151
7054
  createNextOAuthHandler,
@@ -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;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAA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AAC,MAAM,CAAC,CA2BjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAsBnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAevB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integrate-sdk",
3
- "version": "0.7.46",
3
+ "version": "0.7.48",
4
4
  "description": "Type-safe 3rd party integration SDK for the Integrate MCP server",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,6 +30,38 @@
30
30
  "./integrations": {
31
31
  "types": "./dist/integrations.d.ts",
32
32
  "import": "./dist/integrations.js"
33
+ },
34
+ "./ai/vercel": {
35
+ "types": "./dist/ai/vercel-ai.d.ts",
36
+ "import": "./dist/ai/vercel-ai.js"
37
+ },
38
+ "./ai/openai": {
39
+ "types": "./dist/ai/openai.d.ts",
40
+ "import": "./dist/ai/openai.js"
41
+ },
42
+ "./ai/anthropic": {
43
+ "types": "./dist/ai/anthropic.d.ts",
44
+ "import": "./dist/ai/anthropic.js"
45
+ },
46
+ "./ai/google": {
47
+ "types": "./dist/ai/google.d.ts",
48
+ "import": "./dist/ai/google.js"
49
+ },
50
+ "./ai/cloudflare": {
51
+ "types": "./dist/ai/cloudflare.d.ts",
52
+ "import": "./dist/ai/cloudflare.js"
53
+ },
54
+ "./ai/langchain": {
55
+ "types": "./dist/ai/langchain.d.ts",
56
+ "import": "./dist/ai/langchain.js"
57
+ },
58
+ "./ai/llamaindex": {
59
+ "types": "./dist/ai/llamaindex.d.ts",
60
+ "import": "./dist/ai/llamaindex.js"
61
+ },
62
+ "./ai/mastra": {
63
+ "types": "./dist/ai/mastra.d.ts",
64
+ "import": "./dist/ai/mastra.js"
33
65
  }
34
66
  },
35
67
  "files": [
@@ -71,11 +103,8 @@
71
103
  "zod": "^3.23.8"
72
104
  },
73
105
  "devDependencies": {
74
- "@anthropic-ai/sdk": "^0.32.1",
75
- "@google/genai": "^1.29.0",
76
106
  "@types/bun": "latest",
77
107
  "@types/react": "^18.3.0",
78
- "openai": "^4.77.3",
79
108
  "react": "^19.2.0",
80
109
  "simple-git-hooks": "^2.13.1",
81
110
  "typescript": "^5.3.3"
@@ -85,7 +114,6 @@
85
114
  "react": ">=19.0.0",
86
115
  "ai": ">=4.0.0",
87
116
  "openai": ">=4.0.0",
88
- "@openai/agents": ">=0.1.0",
89
117
  "@anthropic-ai/sdk": ">=0.20.0",
90
118
  "@google/genai": "",
91
119
  "@cloudflare/workers-types": ">=4.0.0",
package/server.ts CHANGED
@@ -18,7 +18,63 @@
18
18
  * ```
19
19
  */
20
20
 
21
+ // Core server exports
21
22
  export * from './src/server.js';
22
- export * from './src/ai/index.js';
23
+
24
+ // Framework adapter exports
23
25
  export * from './src/adapters/index.js';
24
26
 
27
+ // AI provider exports - explicitly imported to prevent tree-shaking
28
+ export {
29
+ // Vercel AI
30
+ getVercelAITools,
31
+ convertMCPToolsToVercelAI,
32
+ convertMCPToolToVercelAI,
33
+ // OpenAI
34
+ getOpenAITools,
35
+ convertMCPToolsToOpenAI,
36
+ convertMCPToolToOpenAI,
37
+ executeOpenAIToolCall,
38
+ // Anthropic
39
+ getAnthropicTools,
40
+ convertMCPToolsToAnthropic,
41
+ convertMCPToolToAnthropic,
42
+ executeAnthropicToolCall,
43
+ // Google
44
+ getGoogleTools,
45
+ convertMCPToolsToGoogle,
46
+ convertMCPToolToGoogle,
47
+ executeGoogleFunctionCall,
48
+ executeGoogleFunctionCalls,
49
+ // Cloudflare
50
+ getCloudflareTools,
51
+ convertMCPToolsToCloudflare,
52
+ convertMCPToolToCloudflare,
53
+ executeCloudflareToolCall,
54
+ // LangChain
55
+ getLangChainTools,
56
+ convertMCPToolsToLangChain,
57
+ convertMCPToolToLangChain,
58
+ // LlamaIndex
59
+ getLlamaIndexTools,
60
+ convertMCPToolsToLlamaIndex,
61
+ convertMCPToolToLlamaIndex,
62
+ // Mastra
63
+ getMastraTools,
64
+ convertMCPToolsToMastra,
65
+ convertMCPToolToMastra,
66
+ // Unified interface
67
+ getAITools,
68
+ // Utilities
69
+ getProviderForTool,
70
+ executeToolWithToken,
71
+ // Types
72
+ type AIProviderName,
73
+ type AIToolsOptions,
74
+ type VercelAITool,
75
+ type OpenAITool,
76
+ type AnthropicTool,
77
+ type GoogleTool,
78
+ type CloudflareTool,
79
+ } from './src/ai/index.js';
80
+