@composio/core 0.11.0 → 0.12.0

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 (69) hide show
  1. package/dist/{BaseProvider-CVbQxTNa.d.cts → BaseProvider-BBnsv9kS.d.mts} +139 -92
  2. package/dist/CustomTool-DEB4BQPl.mjs +468 -0
  3. package/dist/{CustomTool-C-IUByoU.d.cts → CustomTool-DH18rVQu.d.mts} +2 -4
  4. package/dist/{FileModifierErrors-C7z16Dfi.mjs → FileModifierErrors-3fSwIWoa.mjs} +35 -36
  5. package/dist/{Telemetry-DQax33Gh.mjs → Telemetry-DhGI_J4G.mjs} +15 -15
  6. package/dist/{composio-pcA13w87.d.cts → composio-CHnEggnv.d.mts} +394 -349
  7. package/dist/{customTool.types-QtkAZQma.d.cts → customTool.types-DpIdOJjL.d.mts} +171 -192
  8. package/dist/{CustomTool-D5s-aADw.mjs → errors-D5f4pfvI.mjs} +70 -457
  9. package/dist/experimental/index.d.mts +2 -3
  10. package/dist/experimental/index.mjs +1 -3
  11. package/dist/{fileUtils.node-Dq7ebZPC.mjs → fileUtils.node-BiO1JQsJ.mjs} +26 -25
  12. package/dist/index.d.mts +1685 -2400
  13. package/dist/index.mjs +2238 -1912
  14. package/dist/jsonSchema-daqF3S3d.mjs +251 -0
  15. package/dist/models/Files.node.d.mts +1 -2
  16. package/dist/models/Files.node.mjs +3 -4
  17. package/dist/models/Files.workerd.d.mts +0 -1
  18. package/dist/platform/node.d.mts +1 -2
  19. package/dist/platform/workerd.d.mts +1 -2
  20. package/dist/{chunk-CWQeghP5.mjs → rolldown-runtime-w6R9maHv.mjs} +3 -5
  21. package/dist/{types-J2KCXP8R.d.mts → types-CaI5Z4PA.d.mts} +2 -3
  22. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -4
  23. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -4
  24. package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +3 -0
  25. package/dist/utils/json-schema.d.mts +2 -0
  26. package/dist/utils/json-schema.mjs +3 -0
  27. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -1
  28. package/dist/utils/modifiers/FileToolModifier.node.mjs +44 -24
  29. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -1
  30. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  31. package/package.json +39 -88
  32. package/dist/BaseProvider-BvHvJLXc.d.mts +0 -29378
  33. package/dist/CustomTool-CChQSp44.d.mts +0 -76
  34. package/dist/CustomTool-D3-NreIm.cjs +0 -1341
  35. package/dist/FileModifierErrors-BYJBHiay.cjs +0 -554
  36. package/dist/FileToolModifier.utils.neutral-DSBQs9-i.cjs +0 -96
  37. package/dist/Telemetry-BQ_pl5AK.cjs +0 -360
  38. package/dist/buffer-BjWptbNH.cjs +0 -63
  39. package/dist/chunk-CQwRTUmo.cjs +0 -53
  40. package/dist/composio-BlASKqjQ.d.mts +0 -5437
  41. package/dist/customTool.types-DLIORcYN.d.mts +0 -2475
  42. package/dist/experimental/index.cjs +0 -5
  43. package/dist/experimental/index.d.cts +0 -3
  44. package/dist/fileUtils.node-DtnSRMWa.cjs +0 -462
  45. package/dist/files.types-lo4zZd87.d.cts +0 -17
  46. package/dist/index.cjs +0 -8523
  47. package/dist/index.d.cts +0 -6065
  48. package/dist/models/Files.node.cjs +0 -55
  49. package/dist/models/Files.node.d.cts +0 -56
  50. package/dist/models/Files.workerd.cjs +0 -29
  51. package/dist/models/Files.workerd.d.cts +0 -13
  52. package/dist/platform/node.cjs +0 -55
  53. package/dist/platform/node.d.cts +0 -11
  54. package/dist/platform/workerd.cjs +0 -42
  55. package/dist/platform/workerd.d.cts +0 -12
  56. package/dist/types-DRG5qLxI.d.cts +0 -13
  57. package/dist/types-pDNm1lYs.d.cts +0 -69
  58. package/dist/utils/config-defaults/ConfigDefaults.node.cjs +0 -10
  59. package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +0 -7
  60. package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +0 -10
  61. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +0 -7
  62. package/dist/utils/modifiers/FileToolModifier.node.cjs +0 -224
  63. package/dist/utils/modifiers/FileToolModifier.node.d.cts +0 -22
  64. package/dist/utils/modifiers/FileToolModifier.workerd.cjs +0 -27
  65. package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +0 -20
  66. /package/dist/{FileToolModifier.utils.neutral-BpSceNK8.mjs → FileToolModifier.utils.neutral-B5rT711M.mjs} +0 -0
  67. /package/dist/{buffer-yOtEsT4J.mjs → buffer-PcbMMsgm.mjs} +0 -0
  68. /package/dist/{files.types-BXDWA_zS.d.mts → files.types-DeMC_mAW.d.mts} +0 -0
  69. /package/dist/{types-HpJQ8K9l.d.mts → types-DdoCRzLj.d.mts} +0 -0
@@ -1,7 +1,6 @@
1
- import { s as ComposioError$1 } from "./FileModifierErrors-C7z16Dfi.mjs";
2
- import { APIError } from "@composio/client";
3
- import { ZodError, z as z$1 } from "zod/v3";
4
- import * as zodToJsonSchema from "zod-to-json-schema";
1
+ import { s as ComposioError$1 } from "./FileModifierErrors-3fSwIWoa.mjs";
2
+ import { APIError, APIUserAbortError } from "@composio/client";
3
+ import { ZodError } from "zod/v3";
5
4
 
6
5
  //#region src/errors/ConnectedAccountsErrors.ts
7
6
  const ConnectedAccountErrorCodes = {
@@ -322,7 +321,8 @@ var ValidationError = class extends ComposioError$1 {
322
321
  cause: zodErrorInstance
323
322
  });
324
323
  this.name = "ValidationError";
325
- this.message = `${message}: ${this.generateUserFriendlyMessage()}`;
324
+ const userFriendlyMessage = this.generateUserFriendlyMessage();
325
+ this.message = `${message}: ${userFriendlyMessage}`;
326
326
  }
327
327
  generateUserFriendlyMessage() {
328
328
  if (this.cause instanceof ZodError && this.cause.issues.length > 0) {
@@ -356,6 +356,70 @@ var JsonSchemaRefResolutionError = class extends ComposioError$1 {
356
356
  }
357
357
  };
358
358
 
359
+ //#endregion
360
+ //#region src/errors/SDKErrors.ts
361
+ const SDKErrorCodes = {
362
+ NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED",
363
+ REQUEST_CANCELLED: "REQUEST_CANCELLED"
364
+ };
365
+ var ComposioNoAPIKeyError = class extends ComposioError$1 {
366
+ constructor(message = "No Composio API key provided", options = {}) {
367
+ const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
368
+ super(message, {
369
+ ...options,
370
+ code: SDKErrorCodes.NO_API_KEY_PROVIDED,
371
+ cause: options.cause || defaultCause,
372
+ possibleFixes: options.possibleFixes || [
373
+ "Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
374
+ "To get an API key, please sign up at https://composio.dev/signup",
375
+ "You can also use the Composio CLI to create a project and get an API key"
376
+ ],
377
+ statusCode: 401
378
+ });
379
+ this.name = "ComposioNoAPIKeyError";
380
+ }
381
+ };
382
+ /**
383
+ * Thrown when an SDK call is cancelled via the caller-supplied `AbortSignal`.
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * try {
388
+ * await composio.tools.execute(slug, body, { signal: AbortSignal.timeout(5_000) });
389
+ * } catch (err) {
390
+ * if (err instanceof ComposioRequestCancelledError) return;
391
+ * throw err;
392
+ * }
393
+ * ```
394
+ */
395
+ var ComposioRequestCancelledError = class extends ComposioError$1 {
396
+ constructor(message = "Request was cancelled by the caller", options = {}) {
397
+ super(message, {
398
+ ...options,
399
+ code: SDKErrorCodes.REQUEST_CANCELLED,
400
+ possibleFixes: options.possibleFixes ?? ["This error is expected when you abort the request via AbortController. Handle it in your catch block to distinguish caller-initiated cancellation from other failures."]
401
+ });
402
+ this.name = "ComposioRequestCancelledError";
403
+ }
404
+ };
405
+ /**
406
+ * `APIUserAbortError` has `.name === "Error"` at runtime (doesn't override it),
407
+ * so we fall back to `constructor.name` for dual-package-hazard cases.
408
+ * @internal
409
+ */
410
+ function isRequestAbortError(error) {
411
+ return _isRequestAbortErrorAt(error, 0);
412
+ }
413
+ function _isRequestAbortErrorAt(error, depth) {
414
+ if (depth > 5) return false;
415
+ if (error instanceof APIUserAbortError) return true;
416
+ if (typeof DOMException !== "undefined" && error instanceof DOMException && error.name === "AbortError") return true;
417
+ if (!(error instanceof Error)) return false;
418
+ if (error.constructor.name === "APIUserAbortError" || error.name === "AbortError" || error.name === "APIUserAbortError") return true;
419
+ if ("cause" in error && error.cause !== void 0 && error.cause !== null) return _isRequestAbortErrorAt(error.cause, depth + 1);
420
+ return false;
421
+ }
422
+
359
423
  //#endregion
360
424
  //#region src/errors/AuthConfigErrors.ts
361
425
  const AuthConfigErrorCodes = { AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND" };
@@ -427,27 +491,6 @@ var ComposioToolkitFetchError = class extends ComposioError$1 {
427
491
  }
428
492
  };
429
493
 
430
- //#endregion
431
- //#region src/errors/SDKErrors.ts
432
- const SDKErrorCodes = { NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED" };
433
- var ComposioNoAPIKeyError = class extends ComposioError$1 {
434
- constructor(message = "No Composio API key provided", options = {}) {
435
- const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
436
- super(message, {
437
- ...options,
438
- code: SDKErrorCodes.NO_API_KEY_PROVIDED,
439
- cause: options.cause || defaultCause,
440
- possibleFixes: options.possibleFixes || [
441
- "Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
442
- "To get an API key, please sign up at https://composio.dev/signup",
443
- "You can also use the Composio CLI to create a project and get an API key"
444
- ],
445
- statusCode: 401
446
- });
447
- this.name = "ComposioNoAPIKeyError";
448
- }
449
- };
450
-
451
494
  //#endregion
452
495
  //#region src/errors/TriggerErrors.ts
453
496
  const TriggerErrorCodes = {
@@ -571,434 +614,4 @@ var RemoteFileDownloadError = class extends ComposioError$1 {
571
614
  };
572
615
 
573
616
  //#endregion
574
- //#region src/lib/toolRouterConstants.ts
575
- const PRELOAD_TOOLS_ALL = "all";
576
-
577
- //#endregion
578
- //#region src/types/customTool.types.ts
579
- /**
580
- * Zod schema for validating a custom tool slug.
581
- * Alphanumeric, underscores, and hyphens only. No `LOCAL_` or `COMPOSIO_` prefix.
582
- * Length is validated contextually (standalone vs extension vs toolkit) at creation time.
583
- */
584
- const CustomToolSlugSchema = z$1.string().min(1, "slug is required").regex(/^[A-Za-z0-9_-]+$/, "slug must only contain alphanumeric characters, underscores, and hyphens").refine((s) => !s.toUpperCase().startsWith("LOCAL_"), { message: "slug must not start with \"LOCAL_\" — this prefix is reserved for internal routing." }).refine((s) => !s.toUpperCase().startsWith("COMPOSIO_"), { message: "slug must not start with \"COMPOSIO_\" — this prefix is reserved for Composio meta tools." });
585
- /**
586
- * Zod schema for validating the string/scalar fields of createCustomTool() options.
587
- * Slug is validated separately as the first argument.
588
- * Used internally for validation — inputParams, outputParams, and execute are checked manually.
589
- */
590
- const CreateCustomToolBaseSchema = z$1.object({
591
- name: z$1.string().min(1, "createCustomTool: name is required"),
592
- description: z$1.string().min(1, "createCustomTool: description is required"),
593
- extendsToolkit: z$1.string().optional(),
594
- preload: z$1.boolean().optional().describe("When true, include this custom tool in session.tools() so it can be called without searching first.")
595
- });
596
- /**
597
- * Zod schema for validating the string/scalar fields of createCustomToolkit() options.
598
- * Slug is validated separately as the first argument.
599
- */
600
- const CreateCustomToolkitBaseSchema = z$1.object({
601
- name: z$1.string().min(1, "createCustomToolkit: name is required"),
602
- description: z$1.string().min(1, "createCustomToolkit: description is required"),
603
- preload: z$1.boolean().optional().describe("When true, include tools from this custom toolkit in session.tools(). Tool-level preload values override this default.")
604
- });
605
-
606
- //#endregion
607
- //#region src/models/CustomTool.ts
608
- /**
609
- * @fileoverview Factory functions for creating custom tools and toolkits.
610
- *
611
- * Usage:
612
- * ```typescript
613
- * import { experimental_createTool, experimental_createToolkit } from '@composio/core';
614
- *
615
- * const grep = createCustomTool('GREP', {
616
- * name: 'Grep Search',
617
- * description: 'Search for patterns in files',
618
- * inputParams: z.object({ pattern: z.string() }),
619
- * execute: async (input) => ({ matches: [] }),
620
- * });
621
- *
622
- * const devTools = createCustomToolkit('DEV_TOOLS', {
623
- * name: 'Dev Tools',
624
- * description: 'Local dev utilities',
625
- * tools: [grep],
626
- * });
627
- * ```
628
- */
629
- /** Prefix applied by the backend to local tool slugs for disambiguation. */
630
- const LOCAL_TOOL_PREFIX = "LOCAL_";
631
- /** Maximum allowed length for the final prefixed slug. */
632
- const MAX_SLUG_LENGTH = 60;
633
- /**
634
- * Compute the final slug length for a tool given its context.
635
- * Returns the expected length of LOCAL_[TOOLKIT_]SLUG.
636
- */
637
- function computeFinalSlugLength(toolSlug, toolkitSlug) {
638
- return 6 + (toolkitSlug ? toolkitSlug.length + 1 : 0) + toolSlug.length;
639
- }
640
- /**
641
- * Validate that the final slug won't exceed the max length.
642
- * Called early in createCustomTool/createCustomToolkit for fast feedback.
643
- */
644
- function validateSlugLength(toolSlug, toolkitSlug, context) {
645
- const finalLength = computeFinalSlugLength(toolSlug, toolkitSlug);
646
- if (finalLength > MAX_SLUG_LENGTH) {
647
- const prefix = LOCAL_TOOL_PREFIX + (toolkitSlug ? `${toolkitSlug.toUpperCase()}_` : "");
648
- throw new ValidationError(`${context}: slug "${toolSlug}" is too long. With prefix "${prefix}", the final slug would be ${finalLength} characters (max ${MAX_SLUG_LENGTH}). Shorten the slug to at most ${MAX_SLUG_LENGTH - prefix.length} characters.`);
649
- }
650
- }
651
- /**
652
- * Create a custom tool for use in tool router sessions.
653
- *
654
- * The returned object is a lightweight reference containing the tool's metadata
655
- * and execute function. Pass it to `composio.create(userId, { experimental: { customTools: [...] } })`
656
- * to bind it to a session.
657
- *
658
- * Just return the result data from `execute`, or throw an error.
659
- * The SDK wraps it into the standard response format internally.
660
- *
661
- * **Slug naming:** The slug you provide is automatically prefixed with `LOCAL_` when
662
- * exposed to the agent (e.g. `'GREP'` becomes `LOCAL_GREP`). If the tool is inside a
663
- * custom toolkit, the toolkit slug is also included (e.g. `LOCAL_DEV_TOOLS_GREP`).
664
- * The `LOCAL_` prefix is reserved and cannot be used in your slug.
665
- *
666
- * @param slug - Unique tool identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
667
- * @param options - Tool definition including name, schema, and execute function
668
- * @returns A CustomTool to pass to session creation
669
- *
670
- * @example Standalone tool (no auth)
671
- * ```typescript
672
- * const grep = createCustomTool('GREP', {
673
- * name: 'Grep Search',
674
- * description: 'Search for patterns in files',
675
- * inputParams: z.object({ pattern: z.string(), path: z.string() }),
676
- * execute: async (input) => ({ matches: [] }),
677
- * });
678
- * ```
679
- *
680
- * @example Tool extending a Composio toolkit (inherits auth)
681
- * ```typescript
682
- * const getImportant = createCustomTool('GET_IMPORTANT_EMAILS', {
683
- * name: 'Get Important Emails',
684
- * description: 'Fetch high-priority emails',
685
- * extendsToolkit: 'gmail',
686
- * inputParams: z.object({ limit: z.number().default(10) }),
687
- * execute: async (input, ctx) => {
688
- * // Same response shape as session.execute(): { data, error, logId }
689
- * const result = await ctx.execute('GMAIL_SEARCH', { query: 'is:important' });
690
- * return { emails: result.data };
691
- * },
692
- * });
693
- * ```
694
- */
695
- function createCustomTool(slug, options) {
696
- const slugResult = CustomToolSlugSchema.safeParse(slug);
697
- if (!slugResult.success) throw new ValidationError(`createCustomTool: ${slugResult.error.issues[0].message}`, { cause: slugResult.error });
698
- const validated = CreateCustomToolBaseSchema.parse(options);
699
- if (!options.inputParams) throw new ValidationError("createCustomTool: inputParams is required");
700
- if (options.inputParams?._def?.typeName !== "ZodObject") throw new ValidationError("createCustomTool: inputParams must be a z.object() schema. Tool input parameters are always an object with named properties.");
701
- if (typeof options.execute !== "function") throw new ValidationError("createCustomTool: execute must be a function");
702
- validateSlugLength(slug, validated.extendsToolkit, "createCustomTool");
703
- const { inputParams, execute } = options;
704
- const paramsSchemaJson = zodToJsonSchema.default(inputParams, { name: "input" }).definitions.input;
705
- const inputSchema = {
706
- type: "object",
707
- properties: paramsSchemaJson.properties,
708
- ...paramsSchemaJson.required ? { required: paramsSchemaJson.required } : {}
709
- };
710
- let outputSchema;
711
- if (options.outputParams) outputSchema = zodToJsonSchema.default(options.outputParams, { name: "output" }).definitions.output;
712
- return {
713
- slug: slugResult.data,
714
- name: validated.name,
715
- description: validated.description,
716
- extendsToolkit: validated.extendsToolkit,
717
- preload: validated.preload,
718
- inputSchema,
719
- outputSchema,
720
- inputParams,
721
- execute
722
- };
723
- }
724
- /**
725
- * Create a custom toolkit that groups related tools.
726
- *
727
- * Tools passed here must NOT have `extendsToolkit` set — they inherit the toolkit identity instead.
728
- *
729
- * **Slug naming:** The toolkit slug becomes part of the final tool slug exposed to the agent.
730
- * For example, a toolkit `'DEV_TOOLS'` with a tool `'GREP'` produces `LOCAL_DEV_TOOLS_GREP`.
731
- * The `LOCAL_` prefix is reserved and cannot be used in your slug.
732
- *
733
- * @param slug - Unique toolkit identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
734
- * @param options - Toolkit definition including name, description, and tools
735
- * @returns A CustomToolkit to pass to session creation
736
- *
737
- * @example
738
- * ```typescript
739
- * const devTools = createCustomToolkit('DEV_TOOLS', {
740
- * name: 'Dev Tools',
741
- * description: 'Local dev utilities',
742
- * tools: [grepTool, sedTool],
743
- * });
744
- * ```
745
- */
746
- function createCustomToolkit(slug, options) {
747
- const slugResult = CustomToolSlugSchema.safeParse(slug);
748
- if (!slugResult.success) throw new ValidationError(`createCustomToolkit: ${slugResult.error.issues[0].message}`, { cause: slugResult.error });
749
- const validated = CreateCustomToolkitBaseSchema.parse(options);
750
- if (!options.tools?.length) throw new ValidationError("createCustomToolkit: at least one tool is required");
751
- for (const tool of options.tools) {
752
- if (tool.extendsToolkit) throw new ValidationError(`createCustomToolkit: tool "${tool.slug}" has extendsToolkit set. Tools in a custom toolkit must not use extendsToolkit — they inherit the toolkit identity instead.`);
753
- validateSlugLength(tool.slug, slug, `createCustomToolkit("${slug}")`);
754
- }
755
- return {
756
- slug: slugResult.data,
757
- name: validated.name,
758
- description: validated.description,
759
- preload: validated.preload,
760
- tools: options.tools
761
- };
762
- }
763
- /**
764
- * Build the final slug for a custom tool given its context.
765
- * @internal
766
- */
767
- function buildFinalSlug(toolSlug, toolkitSlug) {
768
- const upper = toolSlug.toUpperCase();
769
- return toolkitSlug ? `${LOCAL_TOOL_PREFIX}${toolkitSlug.toUpperCase()}_${upper}` : `${LOCAL_TOOL_PREFIX}${upper}`;
770
- }
771
- const qualifiedOriginalSlugKey = (toolkit, originalSlug) => `${toolkit?.toUpperCase() ?? ""}::${originalSlug.toUpperCase()}`;
772
- const canShareOriginalSlug = (existing, next) => !!existing.toolkit && !!next.toolkit && existing.toolkit.toLowerCase() !== next.toolkit.toLowerCase();
773
- const addOriginalSlugAlias = (params) => {
774
- const originalSlugKey = params.originalSlug.toUpperCase();
775
- if (params.ambiguousOriginalSlugs.has(originalSlugKey)) return;
776
- const existing = params.byOriginalSlug.get(originalSlugKey);
777
- if (!existing) {
778
- params.byOriginalSlug.set(originalSlugKey, params.entry);
779
- return;
780
- }
781
- if (existing.finalSlug.toUpperCase() === params.entry.finalSlug.toUpperCase()) return;
782
- if (canShareOriginalSlug(existing, params.entry)) {
783
- params.byOriginalSlug.delete(originalSlugKey);
784
- params.ambiguousOriginalSlugs.add(originalSlugKey);
785
- return;
786
- }
787
- throw new ValidationError(`Custom tool slug collision: original slug "${params.originalSlug}" maps to multiple final slugs. "${existing.finalSlug}" and "${params.entry.finalSlug}" both resolve from "${originalSlugKey}".`);
788
- };
789
- /**
790
- * Build a CustomToolsMap from custom tools and toolkits.
791
- * Used internally by ToolRouter.create() to construct the per-session routing map.
792
- *
793
- * @internal
794
- * @param tools - Standalone custom tools
795
- * @param toolkits - Custom toolkits containing grouped tools
796
- * @returns Maps for O(1) lookup by both final and original slug
797
- * @throws If duplicate slugs or cross-group collisions
798
- */
799
- function buildCustomToolsMap(tools, toolkits) {
800
- const byFinalSlug = /* @__PURE__ */ new Map();
801
- const byOriginalSlug = /* @__PURE__ */ new Map();
802
- const byToolkitAndOriginalSlug = /* @__PURE__ */ new Map();
803
- const ambiguousOriginalSlugs = /* @__PURE__ */ new Set();
804
- const addEntry = (handle, finalSlug, toolkit) => {
805
- const originalSlug = handle.slug.toUpperCase();
806
- const finalSlugKey = finalSlug.toUpperCase();
807
- if (finalSlug.length > MAX_SLUG_LENGTH) throw new ValidationError(`Custom tool slug "${handle.slug}" produces final slug "${finalSlug}" which exceeds ${MAX_SLUG_LENGTH} characters.`);
808
- if (byFinalSlug.has(finalSlugKey)) throw new ValidationError(`Custom tool slug collision: "${finalSlug}" is already registered.`);
809
- const qualifiedKey = qualifiedOriginalSlugKey(toolkit, originalSlug);
810
- if (byToolkitAndOriginalSlug.has(qualifiedKey)) throw new ValidationError(`Custom tool slug collision: original slug "${handle.slug}" is already registered for toolkit "${toolkit ?? "custom"}".`);
811
- const entry = {
812
- handle,
813
- finalSlug,
814
- toolkit
815
- };
816
- byFinalSlug.set(finalSlugKey, entry);
817
- byToolkitAndOriginalSlug.set(qualifiedKey, entry);
818
- addOriginalSlugAlias({
819
- byOriginalSlug,
820
- ambiguousOriginalSlugs,
821
- originalSlug,
822
- entry
823
- });
824
- };
825
- for (const handle of tools) addEntry(handle, buildFinalSlug(handle.slug, handle.extendsToolkit), handle.extendsToolkit);
826
- if (toolkits) for (const toolkit of toolkits) for (const handle of toolkit.tools) addEntry(handle, buildFinalSlug(handle.slug, toolkit.slug), toolkit.slug);
827
- return {
828
- byFinalSlug,
829
- byOriginalSlug,
830
- byToolkitAndOriginalSlug,
831
- ...ambiguousOriginalSlugs.size ? { ambiguousOriginalSlugs } : {},
832
- toolkits,
833
- tools: tools.length ? tools : void 0
834
- };
835
- }
836
- function shouldSerializePreload(preload, inheritedPreload, defaultPreload) {
837
- const inheritedOrDefault = inheritedPreload ?? defaultPreload;
838
- if (preload !== void 0) return preload || inheritedOrDefault ? preload : void 0;
839
- if (inheritedPreload !== void 0) return inheritedPreload || defaultPreload ? inheritedPreload : void 0;
840
- return defaultPreload ? true : void 0;
841
- }
842
- function preloadWireProperty(preload, inheritedPreload, defaultPreload) {
843
- const serializedPreload = shouldSerializePreload(preload, inheritedPreload, defaultPreload);
844
- return serializedPreload === void 0 ? {} : { preload: serializedPreload };
845
- }
846
- function serializeCustomTools(tools, options = {}) {
847
- const defaultPreload = options.defaultPreload ?? false;
848
- return tools.map((handle) => ({
849
- slug: handle.slug,
850
- name: handle.name,
851
- description: handle.description,
852
- input_schema: handle.inputSchema,
853
- ...handle.outputSchema ? { output_schema: handle.outputSchema } : {},
854
- ...handle.extendsToolkit ? { extends_toolkit: handle.extendsToolkit } : {},
855
- ...preloadWireProperty(handle.preload, void 0, defaultPreload)
856
- }));
857
- }
858
- /**
859
- * Serialize custom toolkits into the format expected by the backend session creation API.
860
- *
861
- * @internal
862
- * @param toolkits - The custom toolkits to serialize
863
- * @returns Array of CustomToolkitDefinition for the API payload
864
- */
865
- function serializeCustomToolkits(toolkits, options = {}) {
866
- const defaultPreload = options.defaultPreload ?? false;
867
- return toolkits.map((tk) => ({
868
- slug: tk.slug,
869
- name: tk.name,
870
- description: tk.description,
871
- ...preloadWireProperty(tk.preload, void 0, defaultPreload),
872
- tools: tk.tools.map((t) => ({
873
- slug: t.slug,
874
- name: t.name,
875
- description: t.description,
876
- input_schema: t.inputSchema,
877
- ...t.outputSchema ? { output_schema: t.outputSchema } : {},
878
- ...preloadWireProperty(t.preload, tk.preload, defaultPreload)
879
- }))
880
- }));
881
- }
882
- /**
883
- * Build a CustomToolsMap using the slug/original_slug mapping from the session create response.
884
- * This uses the backend's authoritative prefixed slugs instead of computing them client-side.
885
- *
886
- * @internal
887
- * @param tools - The original custom tools passed to session creation
888
- * @param toolkits - The original custom toolkits passed to session creation
889
- * @param experimental - The experimental section from the session create response
890
- * @returns Maps for O(1) lookup by both final and original slug
891
- */
892
- function buildCustomToolsMapFromResponse(tools, toolkits, experimental) {
893
- const byFinalSlug = /* @__PURE__ */ new Map();
894
- const byOriginalSlug = /* @__PURE__ */ new Map();
895
- const byToolkitAndOriginalSlug = /* @__PURE__ */ new Map();
896
- const ambiguousOriginalSlugs = /* @__PURE__ */ new Set();
897
- const handlesByQualifiedOriginalSlug = /* @__PURE__ */ new Map();
898
- const handlesByOriginalSlug = /* @__PURE__ */ new Map();
899
- const registerHandle = (handle, toolkit) => {
900
- const originalSlug = handle.slug.toUpperCase();
901
- const match = {
902
- handle,
903
- toolkit
904
- };
905
- handlesByQualifiedOriginalSlug.set(qualifiedOriginalSlugKey(toolkit, originalSlug), match);
906
- const existing = handlesByOriginalSlug.get(originalSlug) ?? [];
907
- existing.push(match);
908
- handlesByOriginalSlug.set(originalSlug, existing);
909
- };
910
- for (const handle of tools) registerHandle(handle, handle.extendsToolkit);
911
- if (toolkits) for (const tk of toolkits) for (const handle of tk.tools) registerHandle(handle, tk.slug);
912
- const findHandle = (originalSlug, toolkit) => {
913
- const originalSlugKey = originalSlug.toUpperCase();
914
- const qualifiedMatch = handlesByQualifiedOriginalSlug.get(qualifiedOriginalSlugKey(toolkit, originalSlugKey));
915
- if (qualifiedMatch) return qualifiedMatch;
916
- const bareMatches = handlesByOriginalSlug.get(originalSlugKey) ?? [];
917
- return bareMatches.length === 1 ? bareMatches[0] : void 0;
918
- };
919
- const addEntry = (finalSlug, originalSlug, toolkit) => {
920
- const resolvedToolkit = toolkit ?? void 0;
921
- const match = findHandle(originalSlug, resolvedToolkit);
922
- if (!match) return;
923
- const finalSlugKey = finalSlug.toUpperCase();
924
- if (byFinalSlug.has(finalSlugKey)) throw new ValidationError(`Custom tool slug collision: "${finalSlug}" is already registered.`);
925
- const entry = {
926
- handle: match.handle,
927
- finalSlug,
928
- toolkit: resolvedToolkit ?? match.toolkit
929
- };
930
- byFinalSlug.set(finalSlugKey, entry);
931
- byToolkitAndOriginalSlug.set(qualifiedOriginalSlugKey(entry.toolkit, originalSlug), entry);
932
- addOriginalSlugAlias({
933
- byOriginalSlug,
934
- ambiguousOriginalSlugs,
935
- originalSlug,
936
- entry
937
- });
938
- };
939
- if (experimental?.custom_tools) for (const ct of experimental.custom_tools) addEntry(ct.slug, ct.original_slug, ct.extends_toolkit);
940
- if (experimental?.custom_toolkits) for (const ctk of experimental.custom_toolkits) for (const ct of ctk.tools) addEntry(ct.slug, ct.original_slug, ctk.slug);
941
- return {
942
- byFinalSlug,
943
- byOriginalSlug,
944
- byToolkitAndOriginalSlug,
945
- ...ambiguousOriginalSlugs.size ? { ambiguousOriginalSlugs } : {},
946
- toolkits,
947
- tools: tools.length ? tools : void 0
948
- };
949
- }
950
- /**
951
- * Find a custom tool entry by final slug only.
952
- *
953
- * @internal
954
- */
955
- function findCustomToolMapEntryByFinalSlug(customToolsMap, slug) {
956
- return customToolsMap?.byFinalSlug.get(slug.toUpperCase());
957
- }
958
- /**
959
- * Find a custom toolkit tool entry by toolkit slug and original tool slug.
960
- *
961
- * @internal
962
- */
963
- function findCustomToolMapEntryByToolkitAndOriginalSlug(customToolsMap, toolkit, slug) {
964
- return customToolsMap?.byToolkitAndOriginalSlug?.get(qualifiedOriginalSlugKey(toolkit, slug));
965
- }
966
- /**
967
- * Reject legacy attempts to preload custom tools through top-level preload.tools.
968
- *
969
- * Custom tool direct exposure is controlled by CustomTool.preload /
970
- * CustomToolkit.preload so it follows the current SDK-provided custom
971
- * definitions instead of stale session config.
972
- *
973
- * @internal
974
- */
975
- function assertNoCustomToolSlugsInPreload(preloadTools, customToolsMap) {
976
- if (!preloadTools || preloadTools === PRELOAD_TOOLS_ALL) return;
977
- const customPreloadSlugs = preloadTools.filter((slug) => {
978
- const normalized = slug.toUpperCase();
979
- return normalized.startsWith(LOCAL_TOOL_PREFIX) || customToolsMap?.byOriginalSlug.has(normalized) || customToolsMap?.ambiguousOriginalSlugs?.has(normalized) || customToolsMap?.byFinalSlug.has(normalized);
980
- });
981
- if (customPreloadSlugs.length) throw new ValidationError(`Custom tool slugs are not supported in preload.tools: ${customPreloadSlugs.join(", ")}. Set preload: true on the SDK custom tool or custom toolkit definition instead.`);
982
- }
983
- /**
984
- * Resolve custom tools that the SDK should expose directly from session.tools().
985
- *
986
- * @internal
987
- */
988
- function getPreloadedCustomToolSlugs(customToolsMap, defaultPreload = false) {
989
- if (!customToolsMap) return [];
990
- const seen = /* @__PURE__ */ new Set();
991
- const customToolSlugs = [];
992
- for (const entry of customToolsMap.byFinalSlug.values()) {
993
- const toolkit = customToolsMap.toolkits?.find((tk) => entry.toolkit && tk.slug.toLowerCase() === entry.toolkit.toLowerCase());
994
- if (!(entry.handle.preload ?? toolkit?.preload ?? defaultPreload)) continue;
995
- const finalSlugKey = entry.finalSlug.toUpperCase();
996
- if (seen.has(finalSlugKey)) continue;
997
- seen.add(finalSlugKey);
998
- customToolSlugs.push(entry.finalSlug);
999
- }
1000
- return customToolSlugs;
1001
- }
1002
-
1003
- //#endregion
1004
- export { ComposioMultipleConnectedAccountsError as $, ConnectionRequestErrorCodes as A, ComposioInvalidExecuteFunctionError as B, ComposioWebhookSignatureVerificationError as C, ComposioToolkitFetchError as D, SDKErrorCodes as E, JsonSchemaRefResolutionError as F, ComposioToolNotFoundError as G, ComposioInvalidToolArgumentsError as H, JsonSchemaToZodError as I, handleToolExecutionError as J, ComposioToolVersionRequiredError as K, ValidationError as L, ConnectionRequestTimeoutError as M, AuthConfigErrorCodes as N, ComposioToolkitNotFoundError as O, ComposioAuthConfigNotFoundError as P, ComposioLegacyConnectedAccountsEndpointRetiredError as Q, ValidationErrorCodes as R, ComposioWebhookPayloadError as S, ComposioNoAPIKeyError as T, ComposioProviderNotDefinedError as U, ComposioInvalidModifierError as V, ComposioToolExecutionError as W, ComposioConnectedAccountNotFoundError as X, ComposioAclOnlyForSharedError as Y, ComposioFailedToCreateConnectedAccountLink as Z, ComposioFailedToCreatePusherClientError as _, createCustomToolkit as a, ComposioFailedToUnsubscribeFromPusherChannelError as b, getPreloadedCustomToolSlugs as c, CreateCustomToolBaseSchema as d, ComposioSharedAccessDeniedError as et, CreateCustomToolkitBaseSchema as f, RemoteFileErrorCodes as g, RemoteFileDownloadError as h, createCustomTool as i, ConnectionRequestFailedError as j, ToolkitErrorCodes as k, serializeCustomToolkits as l, PRELOAD_TOOLS_ALL as m, buildCustomToolsMap as n, ConnectedAccountErrorCodes as nt, findCustomToolMapEntryByFinalSlug as o, CustomToolSlugSchema as p, ToolErrorCodes as q, buildCustomToolsMapFromResponse as r, findCustomToolMapEntryByToolkitAndOriginalSlug as s, assertNoCustomToolSlugsInPreload as t, ComposioSharedConnectionNotAccessibleError as tt, serializeCustomTools as u, ComposioFailedToGetSDKRealtimeCredentialsError as v, TriggerErrorCodes as w, ComposioTriggerTypeNotFoundError as x, ComposioFailedToSubscribeToPusherChannelError as y, ComposioGlobalExecuteToolFnNotSetError as z };
617
+ export { ComposioInvalidToolArgumentsError as A, ComposioLegacyConnectedAccountsEndpointRetiredError as B, JsonSchemaRefResolutionError as C, ComposioGlobalExecuteToolFnNotSetError as D, ValidationErrorCodes as E, ToolErrorCodes as F, ComposioSharedAccessDeniedError as H, handleToolExecutionError as I, ComposioAclOnlyForSharedError as L, ComposioToolExecutionError as M, ComposioToolNotFoundError as N, ComposioInvalidExecuteFunctionError as O, ComposioToolVersionRequiredError as P, ComposioConnectedAccountNotFoundError as R, isRequestAbortError as S, ValidationError as T, ComposioSharedConnectionNotAccessibleError as U, ComposioMultipleConnectedAccountsError as V, ConnectedAccountErrorCodes as W, AuthConfigErrorCodes as _, ComposioFailedToSubscribeToPusherChannelError as a, ComposioRequestCancelledError as b, ComposioWebhookPayloadError as c, ComposioToolkitFetchError as d, ComposioToolkitNotFoundError as f, ConnectionRequestTimeoutError as g, ConnectionRequestFailedError as h, ComposioFailedToGetSDKRealtimeCredentialsError as i, ComposioProviderNotDefinedError as j, ComposioInvalidModifierError as k, ComposioWebhookSignatureVerificationError as l, ConnectionRequestErrorCodes as m, RemoteFileErrorCodes as n, ComposioFailedToUnsubscribeFromPusherChannelError as o, ToolkitErrorCodes as p, ComposioFailedToCreatePusherClientError as r, ComposioTriggerTypeNotFoundError as s, RemoteFileDownloadError as t, TriggerErrorCodes as u, ComposioAuthConfigNotFoundError as v, JsonSchemaToZodError as w, SDKErrorCodes as x, ComposioNoAPIKeyError as y, ComposioFailedToCreateConnectedAccountLink as z };
@@ -1,4 +1,3 @@
1
- import "../BaseProvider-BvHvJLXc.mjs";
2
- import { a as CustomTool, b as SessionContext, d as CustomToolkit, i as CreateCustomToolkitParams, n as CreateCustomToolParams, s as CustomToolExecuteFn } from "../customTool.types-DLIORcYN.mjs";
3
- import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-CChQSp44.mjs";
1
+ import { S as SessionContext, a as CreateCustomToolkitParams, c as CustomToolExecuteFn, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams } from "../customTool.types-DpIdOJjL.mjs";
2
+ import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-DH18rVQu.mjs";
4
3
  export { type CreateCustomToolParams, type CreateCustomToolkitParams, type CustomTool, type CustomToolExecuteFn, type CustomToolkit, type SessionContext, createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
@@ -1,5 +1,3 @@
1
- import "../chunk-CWQeghP5.mjs";
2
- import "../FileModifierErrors-C7z16Dfi.mjs";
3
- import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-D5s-aADw.mjs";
1
+ import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-DEB4BQPl.mjs";
4
2
 
5
3
  export { createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };