@composio/core 0.21.0 → 0.23.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 (59) hide show
  1. package/dist/{CustomTool-BHOYxLZX.d.mts → CustomTool-CnHdegDK.d.mts} +1 -1
  2. package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
  3. package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
  4. package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
  5. package/dist/{composio-BTZsFajb.d.mts → composio-Dq708dZS.d.mts} +81 -185
  6. package/dist/{customTool.types-D_w21L56.d.mts → customTool.types-B8lVpHOP.d.mts} +77 -59
  7. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
  8. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
  9. package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
  12. package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
  13. package/dist/experimental/index.d.mts +2 -2
  14. package/dist/experimental/index.mjs +1 -1
  15. package/dist/index.d.mts +46 -6
  16. package/dist/index.mjs +315 -363
  17. package/dist/models/Files.node.mjs +1 -1
  18. package/dist/platform/node.d.mts +1 -1
  19. package/dist/platform/node.mjs +13 -0
  20. package/dist/platform/workerd.d.mts +1 -1
  21. package/dist/platform/workerd.mjs +3 -0
  22. package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
  23. package/dist/{types-CgRsUGqm.d.mts → types-eTw8Yw7Y.d.mts} +2 -2
  24. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  25. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  26. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  27. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  28. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  29. package/package.json +10 -7
  30. package/src/errors/ToolRouterErrors.ts +65 -0
  31. package/src/lib/toolRouterParams.ts +8 -10
  32. package/src/models/AuthConfigs.ts +0 -9
  33. package/src/models/ConnectionRequest.ts +21 -18
  34. package/src/models/CustomToolkits.ts +1 -1
  35. package/src/models/Logs.ts +2 -2
  36. package/src/models/RemoteFile.ts +24 -5
  37. package/src/models/SessionContext.ts +24 -4
  38. package/src/models/ToolRouter.ts +3 -3
  39. package/src/models/ToolRouterSession.ts +45 -13
  40. package/src/models/Tools.ts +21 -37
  41. package/src/models/Usage.ts +2 -1
  42. package/src/models/customToolExecution.ts +10 -0
  43. package/src/platform/node.ts +16 -0
  44. package/src/platform/types.ts +3 -0
  45. package/src/platform/workerd.ts +4 -0
  46. package/src/provider/BaseProvider.ts +2 -1
  47. package/src/provider/OpenAIProvider.ts +0 -283
  48. package/src/telemetry/Telemetry.ts +4 -2
  49. package/src/types/logs.types.ts +9 -1
  50. package/src/types/tool.types.ts +8 -3
  51. package/src/types/toolRouter.types.ts +27 -19
  52. package/src/types/usage.types.ts +2 -0
  53. package/src/utils/jsonSchema.ts +191 -36
  54. package/src/utils/retries.ts +20 -0
  55. package/src/utils/safePath.ts +135 -54
  56. package/src/utils/session.ts +31 -2
  57. package/src/utils/transformers/logs.ts +3 -2
  58. package/src/utils/transformers/toolRouterResponseTransform.ts +69 -12
  59. package/src/utils/transformers/usage.ts +1 -0
@@ -56,6 +56,14 @@ export const ToolExecutionLogParentSchema = z
56
56
  })
57
57
  .nullable();
58
58
 
59
+ /** Tool log metadata, including the optional exact USD Instant charge. */
60
+ export const ToolExecutionLogMetadataSchema = z
61
+ .object({
62
+ instant_charge: z.string().optional(),
63
+ })
64
+ .catchall(z.unknown());
65
+ export type ToolExecutionLogMetadata = z.infer<typeof ToolExecutionLogMetadataSchema>;
66
+
59
67
  /**
60
68
  * A tool-execution log entry as returned by `composio.logs.search()`.
61
69
  */
@@ -68,7 +76,7 @@ export const ToolExecutionLogSchema = z.object({
68
76
  status: ToolExecutionLogStatusSchema,
69
77
  level: ToolExecutionLogLevelSchema,
70
78
  message: z.string().optional(),
71
- metadata: z.record(z.string(), z.unknown()),
79
+ metadata: ToolExecutionLogMetadataSchema,
72
80
  metrics: z.record(z.string(), z.unknown()),
73
81
  parent: ToolExecutionLogParentSchema,
74
82
  });
@@ -347,7 +347,7 @@ export type CustomAuthParams = z.infer<typeof CustomAuthParamsSchema>;
347
347
  * Parameters for tool execution.
348
348
  *
349
349
  * @property {boolean} [allowTracing] - Enable tracing for this tool execution
350
- * @property {string} [connectedAccountId] - The connected account ID to use for authenticated tools
350
+ * @property {string} [connectedAccountId] - Connected account ID, or `instant_account` to explicitly use the Composio Instant account
351
351
  * @property {CustomAuthParams} [customAuthParams] - Custom authentication parameters
352
352
  * @property {CustomConnectionData} [customConnectionData] - Custom connection data (takes priority over customAuthParams)
353
353
  * @property {Record<string, unknown>} [arguments] - The arguments to pass to the tool
@@ -407,8 +407,8 @@ export const ToolExecuteResponseSchema = z.object({
407
407
  successful: z.boolean(),
408
408
  logId: z.string().optional(),
409
409
  sessionInfo: z.unknown().optional(),
410
- /** Actual premium usage charge when the Session opts into returning it. */
411
- premiumCharge: z.unknown().optional(),
410
+ /** Actual Instant usage charge when the Session opts into returning it. */
411
+ instantCharge: z.unknown().optional(),
412
412
  });
413
413
  export type ToolExecuteResponse = z.infer<typeof ToolExecuteResponseSchema>;
414
414
 
@@ -426,6 +426,11 @@ export const ToolProxyParamsSchema = z.object({
426
426
  )
427
427
  .optional(),
428
428
  connectedAccountId: z.string().optional(),
429
+ /**
430
+ * The user the connected account belongs to. Projects with 2FA enabled check it
431
+ * against the connected account, and require it for orgs created on or after
432
+ */
433
+ userId: z.string().optional(),
429
434
  /**
430
435
  * @deprecated
431
436
  */
@@ -108,8 +108,8 @@ export const ToolRouterToolkitsEnabledConfigSchema = z
108
108
  })
109
109
  .strict();
110
110
 
111
- /** Experimental premium usage policy for a Session. */
112
- export const ToolRouterPremiumUsageSchema = z.union([
111
+ /** Experimental Instant usage policy for a Session. */
112
+ export const ToolRouterInstantSchema = z.union([
113
113
  z.literal(false),
114
114
  z
115
115
  .object({
@@ -126,15 +126,15 @@ export const ToolRouterPremiumUsageSchema = z.union([
126
126
  )
127
127
  .optional(),
128
128
  /**
129
- * Return the actual premium charge in Session tool responses. Controls
130
- * visibility only; on update, any policy object still re-enables premium
129
+ * Return the actual Instant charge in Session tool responses. Controls
130
+ * visibility only; on update, any policy object still re-enables Instant
131
131
  * usage on a Session set to `false`.
132
132
  */
133
- returnPremiumCharge: z.boolean().optional(),
133
+ returnInstantCharge: z.boolean().optional(),
134
134
  })
135
135
  .strict(),
136
136
  ]);
137
- export type ToolRouterPremiumUsage = z.infer<typeof ToolRouterPremiumUsageSchema>;
137
+ export type ToolRouterInstant = z.infer<typeof ToolRouterInstantSchema>;
138
138
 
139
139
  export const ToolRouterManageConnectionsConfigSchema = z.object({
140
140
  enable: z
@@ -265,8 +265,8 @@ const ToolRouterCreateSessionConfigBaseSchema = z
265
265
  .optional()
266
266
  .describe('The toolkits to use in the tool router session'),
267
267
 
268
- premiumUsage: ToolRouterPremiumUsageSchema.optional().describe(
269
- 'Experimental premium usage policy. Omission permits eligible tools when the project allows premium usage; false disables it for this Session.'
268
+ instant: ToolRouterInstantSchema.optional().describe(
269
+ 'Experimental Instant usage policy. Omission permits eligible tools when the project allows Instant usage; false disables it for this Session.'
270
270
  ),
271
271
 
272
272
  authConfigs: z
@@ -426,7 +426,7 @@ export const ToolRouterCreateSessionConfigSchema = z
426
426
  * @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
427
427
  * @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
428
428
  * @param {Record<string, string | string[]>} connectedAccounts - The connected accounts to use in the tool router session. A single string is coerced to a single-element array before being sent to the backend.
429
- * @param {ToolRouterPremiumUsage} [premiumUsage] - Experimental premium usage policy. The project must allow premium usage.
429
+ * @param {ToolRouterInstant} [instant] - Experimental Instant usage policy. The project must allow Instant usage.
430
430
  * @param {ToolRouterConfigManageConnectionsSchema | boolean} manageConnections - The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.
431
431
  * @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
432
432
  * @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session
@@ -608,8 +608,8 @@ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
608
608
  statusMessage: z.string(),
609
609
  connectionDetails: z.record(z.string(), z.unknown()).optional(),
610
610
  currentUserInfo: z.record(z.string(), z.unknown()).optional(),
611
- /** Present when the toolkit runs on a Composio hosted account; only these tools run on it. */
612
- hostedAccount: z.object({ allowedToolSlugs: z.array(z.string()) }).optional(),
611
+ /** Present when the toolkit runs on a Composio Instant account; only these tools run on it. */
612
+ instantAccount: z.object({ allowedToolSlugs: z.array(z.string()) }).optional(),
613
613
  });
614
614
 
615
615
  export const ToolRouterSessionSearchResponseSchema = z.object({
@@ -630,8 +630,14 @@ export const ToolRouterSessionExecuteResponseSchema = z.object({
630
630
  data: z.record(z.string(), z.unknown()),
631
631
  error: z.string().nullable(),
632
632
  logId: z.string(),
633
- /** Actual premium usage charge when the Session opts into returning it. */
634
- premiumCharge: z.unknown().optional(),
633
+ /**
634
+ * Whether the tool ran and succeeded (`completed`) or ran and failed
635
+ * (`failed`). A failed execution can carry a `null` or empty `error`, so
636
+ * read this rather than `error` to tell the two apart.
637
+ */
638
+ resultType: z.enum(['completed', 'failed']),
639
+ /** Actual Instant usage charge when the Session opts into returning it. */
640
+ instantCharge: z.unknown().optional(),
635
641
  });
636
642
  export type ToolRouterSessionExecuteResponse = z.infer<
637
643
  typeof ToolRouterSessionExecuteResponseSchema
@@ -692,7 +698,8 @@ export type ToolRouterSessionExecuteFn = (
692
698
 
693
699
  export interface ToolRouterSessionExecuteOptions {
694
700
  /**
695
- * Account identifier for direct app tool execution. Accepted on every project:
701
+ * Account identifier for direct app tool execution. Use `instant_account` to
702
+ * explicitly select the Composio Instant account. Accepted on every project:
696
703
  * in multi-account sessions it picks the account; on single-account projects it
697
704
  * must match one of the session's active connections for the toolkit.
698
705
  * Meta/helper tools either ignore this top-level field or define
@@ -709,9 +716,10 @@ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Work
709
716
  export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
710
717
 
711
718
  /**
712
- * Server-side session configuration as returned by the API: toolkit and tool
719
+ * Server-side session configuration as returned by the API: toolkit/tool
713
720
  * allowlists, tags, auth configs, connected accounts, manage_connections,
714
- * preload, sandbox (`workbench`), search and execute settings.
721
+ * preload, sandbox (`workbench`), search, execute, proxy execute and Instant
722
+ * settings.
715
723
  */
716
724
  export type ToolRouterSessionConfig = SessionCreateResponse.Config;
717
725
 
@@ -858,8 +866,8 @@ export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdate
858
866
  */
859
867
  export const ToolRouterUpdateSessionConfigSchema = z
860
868
  .object({
861
- premiumUsage: ToolRouterPremiumUsageSchema.optional().describe(
862
- 'Experimental premium usage policy. False disables it. Any supplied object, even one that only sets returnPremiumCharge, re-enables it. Omitted subfields keep their stored values.'
869
+ instant: ToolRouterInstantSchema.optional().describe(
870
+ 'Experimental Instant usage policy. False disables it. Any supplied object, even one that only sets returnInstantCharge, re-enables it. Omitted subfields keep their stored values.'
863
871
  ),
864
872
  toolkits: z
865
873
  .union([
@@ -1027,7 +1035,7 @@ export type ToolRouterSessionListConfigHistoryOptions = z.infer<
1027
1035
 
1028
1036
  /**
1029
1037
  * The session configuration at one version, as stored by the API. This is
1030
- * the wire shape (snake_case), typed from the generated client.
1038
+ * the wire shape (snake_case), with the Instant policy under `instant`.
1031
1039
  */
1032
1040
  export type ToolRouterSessionConfigHistoryConfig = SessionConfigHistoryResponse.Item.Config;
1033
1041
 
@@ -61,6 +61,8 @@ export type UsageEntitySummary = z.infer<typeof UsageEntitySummarySchema>;
61
61
  export const UsageSummaryResponseSchema = z.object({
62
62
  /** Aggregates keyed by metering entity type (e.g. `tool_calls`, `sessions`). */
63
63
  entities: z.record(z.string(), UsageEntitySummarySchema),
64
+ /** Total Instant charge for the window, in USD as an exact decimal string. */
65
+ instantCharge: z.string(),
64
66
  });
65
67
  export type UsageSummaryResponse = z.infer<typeof UsageSummaryResponseSchema>;
66
68
 
@@ -6,6 +6,9 @@ import { isPlainObject } from './modifiers/FileToolModifier.utils.neutral';
6
6
 
7
7
  const MAX_REF_CHAIN_DEPTH = 100;
8
8
  const MAX_NODE_DEPTH = 512;
9
+ // Bounds on one null-acceptance check; past either, null is not proven accepted.
10
+ const MAX_NULL_CHECK_DEPTH = 64;
11
+ const MAX_NULL_CHECK_NODES = 2_000;
9
12
  const CYCLE_BREAK_SENTINEL = { type: 'object', additionalProperties: true } as const;
10
13
 
11
14
  /** Keywords whose value is a single subschema. */
@@ -603,27 +606,44 @@ function setOwn(target: Record<string, unknown>, key: string, value: unknown): v
603
606
  }
604
607
 
605
608
  /**
606
- * Widens a property schema so that `null` is an accepted value, without
607
- * placing `type` beside `anyOf` (the API rejects that combination).
609
+ * The only keywords that can reject a `null` instance; every other keyword
610
+ * constrains strings, numbers, arrays or objects and ignores `null`.
608
611
  */
609
- function widenToNullable(node: Record<string, unknown>): Record<string, unknown> {
610
- if (Array.isArray(node.anyOf)) {
611
- const alreadyNullable = node.anyOf.some(
612
- branch => isPlainObject(branch) && branch.type === 'null'
613
- );
614
- return alreadyNullable ? node : { ...node, anyOf: [...node.anyOf, { type: 'null' }] };
615
- }
616
- if (typeof node.type === 'string') {
617
- return node.type === 'null' ? node : { ...node, type: [node.type, 'null'] };
612
+ const NULL_CONSTRAINT_KEYWORDS = [
613
+ 'type',
614
+ 'enum',
615
+ 'const',
616
+ '$ref',
617
+ 'anyOf',
618
+ 'oneOf',
619
+ 'allOf',
620
+ 'not',
621
+ 'if',
622
+ 'then',
623
+ 'else',
624
+ ] as const;
625
+
626
+ /**
627
+ * Widens a property schema so that `null` is an accepted value while keeping
628
+ * every other constraint it declares. A node whose only obstacle is `type` or
629
+ * `anyOf` is widened in place. Anything else is wrapped whole, because JSON
630
+ * Schema keywords apply together: adding `null` to `type` does not lift a
631
+ * sibling `enum`. `acceptsNull` must answer for the strict output.
632
+ */
633
+ function widenToNullable(
634
+ node: Record<string, unknown>,
635
+ acceptsNull: (schema: unknown) => boolean
636
+ ): Record<string, unknown> {
637
+ if (acceptsNull(node)) return node;
638
+ const constraints = NULL_CONSTRAINT_KEYWORDS.filter(key => key in node);
639
+ if (constraints.length === 1 && constraints[0] === 'type') {
640
+ const members = Array.isArray(node.type) ? node.type : [node.type];
641
+ return { ...node, type: [...members, 'null'] };
618
642
  }
619
- if (Array.isArray(node.type)) {
620
- return node.type.includes('null') ? node : { ...node, type: [...node.type, 'null'] };
643
+ if (constraints.length === 1 && constraints[0] === 'anyOf' && Array.isArray(node.anyOf)) {
644
+ return { ...node, anyOf: [...node.anyOf, { type: 'null' }] };
621
645
  }
622
- if ((Array.isArray(node.enum) && node.enum.includes(null)) || node.const === null) return node;
623
- // No `type` at all: an empty schema already accepts null; anything else
624
- // (enum-only, const, composition) is wrapped so the annotation stays outside.
625
646
  const { description, title, ...rest } = node;
626
- if (Object.keys(rest).length === 0) return node;
627
647
  return {
628
648
  ...(description !== undefined ? { description } : {}),
629
649
  ...(title !== undefined ? { title } : {}),
@@ -646,19 +666,136 @@ function resolveLocalRefs(node: unknown, root: Record<string, unknown>): unknown
646
666
  return current;
647
667
  }
648
668
 
649
- /** Whether a schema node accepts `null` as an instance. */
650
- function schemaAcceptsNull(schema: unknown, root: Record<string, unknown>): boolean {
651
- const node = resolveLocalRefs(schema, root);
652
- if (!isPlainObject(node)) return true;
653
- if (typeof node.type === 'string') return node.type === 'null';
654
- if (Array.isArray(node.type)) return node.type.includes('null');
655
- if (Array.isArray(node.enum)) return node.enum.includes(null);
656
- if ('const' in node) return node.const === null;
657
- for (const keyword of ['anyOf', 'oneOf']) {
658
- const branches = node[keyword];
659
- if (Array.isArray(branches)) return branches.some(branch => schemaAcceptsNull(branch, root));
660
- }
661
- return true;
669
+ /**
670
+ * Creates the check for whether schemas of one document accept `null` as an
671
+ * instance: every keyword in `NULL_CONSTRAINT_KEYWORDS` that is present must
672
+ * accept it. This is the single definition of null acceptance; the strict
673
+ * rewrite and `omitNullToolArguments` both decide with it.
674
+ *
675
+ * `strictOutput` answers for the schema `toStrictJsonSchema` emits instead of
676
+ * the one it was given: the rewrite types every node that declares
677
+ * `properties` as an object, so such a node stops accepting null.
678
+ *
679
+ * One check serves a whole document, and an answer is computed once per node.
680
+ * A reference cycle never yields a null by itself, so a node met again while
681
+ * it is being evaluated counts as rejecting. An answer that leans on that is
682
+ * provisional until the node it leans on is done: it is kept if that node
683
+ * does reject null and discarded otherwise.
684
+ *
685
+ * Each check is bounded in depth and in nodes visited. A check that meets a
686
+ * bound proves nothing, so it rejects null whatever its other branches say,
687
+ * which costs at most a redundant null branch or a dropped null. The nodes it
688
+ * went through stay marked as unproven, so a later check that reaches one of
689
+ * them neither repeats the work nor trusts the answer.
690
+ */
691
+ function createNullCheck(
692
+ root: Record<string, unknown>,
693
+ strictOutput = false
694
+ ): (schema: unknown) => boolean {
695
+ // Markers for what an answer leans on, besides the depth of a node on the path.
696
+ const NOTHING = MAX_NULL_CHECK_DEPTH + 1;
697
+ const A_BOUND = -1;
698
+ const answers = new Map<object, { answer: boolean; leansOn: number }>();
699
+ // Nodes whose answer is provisional, oldest first.
700
+ const provisional: object[] = [];
701
+ // Nodes being evaluated, mapped to their depth on the current path.
702
+ const path = new Map<object, number>();
703
+ // Depths of the path nodes that were met again below themselves.
704
+ const metAgain = new Set<number>();
705
+ let budget = 0;
706
+ // Shallowest thing the answers used since the last reset lean on.
707
+ let leansOn = NOTHING;
708
+
709
+ const accepts = (schema: unknown): boolean => {
710
+ if (typeof schema === 'boolean') return schema;
711
+ if (!isPlainObject(schema)) return true;
712
+ const remembered = answers.get(schema);
713
+ if (remembered !== undefined) {
714
+ if (path.size === 0) return remembered.answer && remembered.leansOn !== A_BOUND;
715
+ leansOn = Math.min(leansOn, remembered.leansOn);
716
+ return remembered.answer;
717
+ }
718
+ const onPath = path.get(schema);
719
+ if (onPath !== undefined) {
720
+ metAgain.add(onPath);
721
+ leansOn = Math.min(leansOn, onPath);
722
+ return false;
723
+ }
724
+ const depth = path.size;
725
+ if (depth === 0) budget = MAX_NULL_CHECK_NODES;
726
+ if (depth >= MAX_NULL_CHECK_DEPTH || budget <= 0) {
727
+ leansOn = A_BOUND;
728
+ return false;
729
+ }
730
+ budget -= 1;
731
+
732
+ const outer = leansOn;
733
+ leansOn = NOTHING;
734
+ const mark = provisional.length;
735
+ path.set(schema, depth);
736
+ let answer = keywordsAccept(schema);
737
+ path.delete(schema);
738
+
739
+ const own = leansOn;
740
+ const settled = own >= depth;
741
+ const below = provisional.splice(mark);
742
+ if (answer && metAgain.has(depth)) {
743
+ // The answers below took this node for rejecting null.
744
+ for (const other of below) answers.delete(other);
745
+ } else {
746
+ for (const other of below) {
747
+ const entry = answers.get(other);
748
+ if (entry === undefined) continue;
749
+ if (settled) {
750
+ entry.leansOn = NOTHING;
751
+ } else {
752
+ if (entry.leansOn >= depth) entry.leansOn = own;
753
+ provisional.push(other);
754
+ }
755
+ }
756
+ }
757
+ metAgain.delete(depth);
758
+
759
+ if (depth === 0 && own === A_BOUND) answer = false;
760
+ answers.set(schema, { answer, leansOn: settled ? NOTHING : own });
761
+ if (!settled) provisional.push(schema);
762
+ leansOn = settled ? outer : Math.min(outer, own);
763
+ if (depth === 0) {
764
+ // Whatever is still provisional leans on a bound, and stays so.
765
+ provisional.length = 0;
766
+ leansOn = NOTHING;
767
+ }
768
+ return answer;
769
+ };
770
+
771
+ const keywordsAccept = (node: Record<string, unknown>): boolean => {
772
+ if (typeof node.type === 'string' && node.type !== 'null') return false;
773
+ if (Array.isArray(node.type) && !node.type.includes('null')) return false;
774
+ if (strictOutput && !('type' in node) && isPlainObject(node.properties)) return false;
775
+ if (Array.isArray(node.enum) && !node.enum.includes(null)) return false;
776
+ if ('const' in node && node.const !== null) return false;
777
+ if ('$ref' in node) {
778
+ const resolution =
779
+ typeof node.$ref === 'string' ? tryResolvePointer(root, node.$ref) : undefined;
780
+ if (resolution === undefined || resolution.kind === 'unresolved') return false;
781
+ if (!accepts(resolution.value)) return false;
782
+ }
783
+ if (Array.isArray(node.anyOf) && !node.anyOf.some(accepts)) return false;
784
+ if (Array.isArray(node.oneOf)) {
785
+ const matches = node.oneOf.filter(accepts).length;
786
+ // The strict rewrite turns oneOf into anyOf.
787
+ if (matches === 0 || (matches > 1 && !strictOutput)) return false;
788
+ }
789
+ if (Array.isArray(node.allOf) && !node.allOf.every(accepts)) return false;
790
+ if ('not' in node && accepts(node.not)) return false;
791
+ if ('if' in node) {
792
+ const branch = accepts(node.if) ? 'then' : 'else';
793
+ if (branch in node && !accepts(node[branch])) return false;
794
+ }
795
+ return true;
796
+ };
797
+
798
+ return accepts;
662
799
  }
663
800
 
664
801
  /**
@@ -694,6 +831,8 @@ function schemaAcceptsNull(schema: unknown, root: Record<string, unknown>): bool
694
831
  export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
695
832
  const changes: StrictSchemaChange[] = [];
696
833
  const unsupported: StrictSchemaIncompatibility[] = [];
834
+ // Resolved references, re-checked against the rewritten schema.
835
+ const references: { path: string; ref: string }[] = [];
697
836
  let totalChanges = 0;
698
837
  const recordChange = (change: StrictSchemaChange): void => {
699
838
  totalChanges += 1;
@@ -701,6 +840,7 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
701
840
  };
702
841
 
703
842
  const root: Record<string, unknown> = isPlainObject(schema) ? schema : {};
843
+ const acceptsNullInOutput = createNullCheck(root, true);
704
844
 
705
845
  function walkChildren(
706
846
  node: Record<string, unknown>,
@@ -805,6 +945,8 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
805
945
  keyword: '$ref',
806
946
  detail: `unresolved $ref "${node.$ref}"`,
807
947
  });
948
+ } else {
949
+ references.push({ path, ref: node.$ref });
808
950
  }
809
951
  // The referenced definition is normalized where it is declared.
810
952
  return out;
@@ -834,7 +976,7 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
834
976
  continue;
835
977
  }
836
978
  if (declaredRequired.has(name) || !isPlainObject(propertySchema)) continue;
837
- setOwn(properties, name, widenToNullable(propertySchema));
979
+ setOwn(properties, name, widenToNullable(propertySchema, acceptsNullInOutput));
838
980
  recordChange({
839
981
  path: joinPath(path, `properties.${name}`),
840
982
  reason: 'optional-property-nullable',
@@ -874,6 +1016,18 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
874
1016
  }
875
1017
 
876
1018
  const normalized = walk(root, 'schema', 0, '');
1019
+ if (isPlainObject(normalized)) {
1020
+ // Wrapping a property in a null branch moves everything nested in it.
1021
+ for (const { path, ref } of references) {
1022
+ if (tryResolvePointer(normalized, ref).kind === 'unresolved') {
1023
+ unsupported.push({
1024
+ path,
1025
+ keyword: '$ref',
1026
+ detail: `$ref "${ref}" target moved by the rewrite`,
1027
+ });
1028
+ }
1029
+ }
1030
+ }
877
1031
  if (!isPlainObject(normalized) || !isObjectType(normalized.type)) {
878
1032
  unsupported.push({
879
1033
  path: '',
@@ -912,7 +1066,7 @@ export function omitNullToolArguments(
912
1066
  schema: unknown
913
1067
  ): Record<string, unknown> {
914
1068
  const root: Record<string, unknown> = isPlainObject(schema) ? schema : {};
915
- return omitNulls(args, root, root, 0) as Record<string, unknown>;
1069
+ return omitNulls(args, root, root, 0, createNullCheck(root)) as Record<string, unknown>;
916
1070
  }
917
1071
 
918
1072
  /**
@@ -949,7 +1103,8 @@ function omitNulls(
949
1103
  value: unknown,
950
1104
  schema: unknown,
951
1105
  root: Record<string, unknown>,
952
- depth: number
1106
+ depth: number,
1107
+ acceptsNull: (schema: unknown) => boolean
953
1108
  ): unknown {
954
1109
  if (depth > MAX_NODE_DEPTH) {
955
1110
  throw new RangeError(`Tool arguments exceed maximum nesting depth of ${MAX_NODE_DEPTH}`);
@@ -957,7 +1112,7 @@ function omitNulls(
957
1112
  const node = selectBranchFor(schema, value, root);
958
1113
  if (Array.isArray(value)) {
959
1114
  const items = node && isPlainObject(node.items) ? node.items : undefined;
960
- return value.map(item => omitNulls(item, items, root, depth + 1));
1115
+ return value.map(item => omitNulls(item, items, root, depth + 1, acceptsNull));
961
1116
  }
962
1117
  if (!isPlainObject(value)) return value;
963
1118
 
@@ -968,12 +1123,12 @@ function omitNulls(
968
1123
  ? properties[key]
969
1124
  : undefined;
970
1125
  if (child === null) {
971
- if (propertySchema === undefined || schemaAcceptsNull(propertySchema, root)) {
1126
+ if (propertySchema === undefined || acceptsNull(propertySchema)) {
972
1127
  setOwn(clone, key, child);
973
1128
  }
974
1129
  continue;
975
1130
  }
976
- setOwn(clone, key, omitNulls(child, propertySchema, root, depth + 1));
1131
+ setOwn(clone, key, omitNulls(child, propertySchema, root, depth + 1, acceptsNull));
977
1132
  }
978
1133
  return clone;
979
1134
  }
@@ -0,0 +1,20 @@
1
+ import type { ComposioRequestOptions } from '../types/requestOptions.types';
2
+
3
+ /**
4
+ * Request options for a call that executes a tool or proxies an API call: the
5
+ * caller's options with retries disabled.
6
+ *
7
+ * These calls are non-idempotent writes. The client retries timeouts,
8
+ * connection errors, and 408/409/429/5xx responses by default, and a retry
9
+ * after the backend already acted duplicates the side effect (e.g. sends the
10
+ * same email twice). The backend does not deduplicate executions, so every
11
+ * execution path must go through this helper. Reads keep the default retries.
12
+ * See https://github.com/ComposioHQ/composio/issues/3654.
13
+ *
14
+ * @internal
15
+ */
16
+ export function withoutRetries(
17
+ requestOptions?: ComposioRequestOptions
18
+ ): ComposioRequestOptions & { maxRetries: 0 } {
19
+ return { ...requestOptions, maxRetries: 0 };
20
+ }