@composio/core 0.14.1 → 0.16.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.
- package/dist/{BaseProvider-Dc5yKZhk.d.mts → BaseProvider-D7p2OPEx.d.mts} +267 -200
- package/dist/{CustomTool-4nVuwLzO.d.mts → CustomTool-Bk38kFp0.d.mts} +1 -1
- package/dist/{Telemetry-CF0rNHu2.mjs → Telemetry-DuGJSwUt.mjs} +2 -2
- package/dist/{cancellation-BbJ-UQ__.mjs → cancellation-NVtGf3St.mjs} +69 -1
- package/dist/{composio-ChU3eD9F.d.mts → composio-DSs-1AhC.d.mts} +8 -3
- package/dist/{customTool.types-CX2-LbfI.d.mts → customTool.types-cGHcIBX-.d.mts} +1 -1
- package/dist/experimental/index.d.mts +2 -2
- package/dist/{fileUtils.node-DOkW4PBg.mjs → fileUtils.node-BQ0fWge3.mjs} +5 -2
- package/dist/index.d.mts +20 -7
- package/dist/index.mjs +85 -43
- package/dist/models/Files.node.mjs +2 -2
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +24 -0
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/platform/workerd.mjs +3 -0
- package/dist/{sensitiveFileUploadPaths-C43dHP7S.mjs → sensitiveFileUploadPaths-BVEt0peg.mjs} +12 -7
- package/dist/{types-D5N60gUD.d.mts → types-B4k-qoOf.d.mts} +2 -2
- package/dist/{types-DY1r-kN9.d.mts → types-D5A2wzBl.d.mts} +8 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +2 -2
- package/dist/utils/ssrfGuard.node.mjs +3 -2
- package/package.json +6 -5
- package/src/index.ts +1 -0
- package/src/models/ToolRouterSessionFileMount.ts +3 -0
- package/src/models/Tools.ts +108 -77
- package/src/platform/node.ts +40 -0
- package/src/platform/types.ts +9 -0
- package/src/platform/workerd.ts +5 -0
- package/src/telemetry/redact.ts +6 -1
- package/src/types/tool.types.ts +60 -10
- package/src/utils/fileUtils.node.ts +3 -0
- package/src/utils/jsonSchema.ts +86 -1
- package/src/utils/modifiers/FileToolModifier.node.ts +3 -3
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +6 -4
- package/src/utils/sdk.ts +2 -2
- package/src/utils/sensitiveFileUploadPaths.ts +12 -9
- package/src/utils/ssrfGuard.node.ts +6 -2
- package/src/utils/version.ts +21 -20
package/src/models/Tools.ts
CHANGED
|
@@ -470,14 +470,12 @@ export class Tools<
|
|
|
470
470
|
'important' in queryParams.data ? queryParams.data.important : shouldAutoApplyImportant;
|
|
471
471
|
|
|
472
472
|
// check if the query params contains atleast one of the following: tools, toolkits, search, authConfigIds
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
)
|
|
480
|
-
) {
|
|
473
|
+
if (!(
|
|
474
|
+
'tools' in queryParams.data ||
|
|
475
|
+
'toolkits' in queryParams.data ||
|
|
476
|
+
'search' in queryParams.data ||
|
|
477
|
+
'authConfigIds' in queryParams.data
|
|
478
|
+
)) {
|
|
481
479
|
throw new ValidationError(
|
|
482
480
|
'Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search, authConfigIds'
|
|
483
481
|
);
|
|
@@ -766,33 +764,44 @@ export class Tools<
|
|
|
766
764
|
const { signal: _, ...modifiers } = options ?? {};
|
|
767
765
|
|
|
768
766
|
if (typeof arg2 === 'string') {
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
requestOptions
|
|
775
|
-
);
|
|
776
|
-
return this.wrapToolsForProvider(
|
|
777
|
-
userId,
|
|
778
|
-
[tool],
|
|
779
|
-
modifiers as ExecuteToolModifiers
|
|
780
|
-
) as TToolCollection;
|
|
767
|
+
const rawTool = await this.getRawComposioToolBySlug(arg2, undefined, requestOptions);
|
|
768
|
+
const [tool] = await this.applySchemaModifiers([rawTool], options?.modifySchema);
|
|
769
|
+
return this.wrapToolsForProvider(userId, [tool], modifiers as ExecuteToolModifiers, [
|
|
770
|
+
rawTool,
|
|
771
|
+
]) as TToolCollection;
|
|
781
772
|
} else {
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
{
|
|
785
|
-
modifySchema: options?.modifySchema as TransformToolSchemaModifier,
|
|
786
|
-
},
|
|
787
|
-
requestOptions
|
|
788
|
-
);
|
|
773
|
+
const rawTools = await this.getRawComposioTools(arg2, undefined, requestOptions);
|
|
774
|
+
const tools = await this.applySchemaModifiers(rawTools, options?.modifySchema);
|
|
789
775
|
return this.wrapToolsForProvider(
|
|
790
776
|
userId,
|
|
791
777
|
tools,
|
|
792
|
-
modifiers as ExecuteToolModifiers
|
|
778
|
+
modifiers as ExecuteToolModifiers,
|
|
779
|
+
rawTools
|
|
793
780
|
) as TToolCollection;
|
|
794
781
|
}
|
|
795
782
|
}
|
|
783
|
+
|
|
784
|
+
private async applySchemaModifiers(
|
|
785
|
+
tools: Tool[],
|
|
786
|
+
modifier?: TransformToolSchemaModifier
|
|
787
|
+
): Promise<Tool[]> {
|
|
788
|
+
if (modifier && typeof modifier !== 'function') {
|
|
789
|
+
throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
|
|
790
|
+
}
|
|
791
|
+
return Promise.all(
|
|
792
|
+
tools.map(tool => {
|
|
793
|
+
const schema = ToolSchema.parse(tool);
|
|
794
|
+
return modifier
|
|
795
|
+
? modifier({
|
|
796
|
+
toolSlug: tool.slug,
|
|
797
|
+
toolkitSlug: tool.toolkit?.slug ?? 'unknown',
|
|
798
|
+
schema,
|
|
799
|
+
})
|
|
800
|
+
: schema;
|
|
801
|
+
})
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
|
|
796
805
|
/**
|
|
797
806
|
* @internal
|
|
798
807
|
* Creates a global execute tool function.
|
|
@@ -817,14 +826,16 @@ export class Tools<
|
|
|
817
826
|
* @param userId - The user id to get the tools for
|
|
818
827
|
* @param tools - The tools to wrap
|
|
819
828
|
* @param modifiers - The modifiers to be applied to the tools
|
|
829
|
+
* @param rawTools - The fetched schemas used during execution
|
|
820
830
|
* @returns The wrapped tools
|
|
821
831
|
*/
|
|
822
832
|
wrapToolsForProvider<T extends TProvider>(
|
|
823
833
|
userId: string,
|
|
824
834
|
tools: Tool[],
|
|
825
|
-
modifiers?: ExecuteToolModifiers
|
|
835
|
+
modifiers?: ExecuteToolModifiers,
|
|
836
|
+
rawTools: Tool[] = tools.map(tool => ToolSchema.parse(tool))
|
|
826
837
|
): ReturnType<T['wrapTools']> {
|
|
827
|
-
const executeToolFn = this.createExecuteToolFn(userId, modifiers);
|
|
838
|
+
const executeToolFn = this.createExecuteToolFn(userId, modifiers, rawTools);
|
|
828
839
|
return this.provider.wrapTools(tools, executeToolFn) as ReturnType<T['wrapTools']>;
|
|
829
840
|
}
|
|
830
841
|
|
|
@@ -854,21 +865,27 @@ export class Tools<
|
|
|
854
865
|
*
|
|
855
866
|
* @param {string} userId - The user id
|
|
856
867
|
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
|
|
868
|
+
* @param {Tool[]} tools - The fetched tools available to the provider
|
|
857
869
|
* @returns {ExecuteToolFn} The execute tool function
|
|
858
870
|
*/
|
|
859
|
-
private createExecuteToolFn(
|
|
871
|
+
private createExecuteToolFn(
|
|
872
|
+
userId: string,
|
|
873
|
+
modifiers: ExecuteToolModifiers | undefined,
|
|
874
|
+
tools: Tool[]
|
|
875
|
+
): ExecuteToolFn {
|
|
876
|
+
const toolBySlug = new Map(tools.map(tool => [tool.slug.toUpperCase(), tool]));
|
|
860
877
|
const executeToolFn = async (toolSlug: string, input: Record<string, unknown>) => {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
modifiers
|
|
871
|
-
|
|
878
|
+
const body: ToolExecuteParams = {
|
|
879
|
+
userId,
|
|
880
|
+
arguments: input,
|
|
881
|
+
// dangerously skip version check for agentic tool execution via providers
|
|
882
|
+
// this can be safe because most agentic flows users fetch latest version and then execute the tool
|
|
883
|
+
dangerouslySkipVersionCheck: true,
|
|
884
|
+
};
|
|
885
|
+
const tool = toolBySlug.get(toolSlug.toUpperCase());
|
|
886
|
+
return tool
|
|
887
|
+
? this.executeWithTool(toolSlug, this.parseToolExecuteParams(body), modifiers, tool)
|
|
888
|
+
: this.execute(toolSlug, body, modifiers);
|
|
872
889
|
};
|
|
873
890
|
return executeToolFn;
|
|
874
891
|
}
|
|
@@ -961,6 +978,52 @@ export class Tools<
|
|
|
961
978
|
}
|
|
962
979
|
}
|
|
963
980
|
|
|
981
|
+
private async executeWithTool(
|
|
982
|
+
slug: string,
|
|
983
|
+
body: ToolExecuteParams,
|
|
984
|
+
options: (ExecuteToolModifiers & ComposioRequestOptions) | undefined,
|
|
985
|
+
tool: Tool
|
|
986
|
+
): Promise<ToolExecuteResponse> {
|
|
987
|
+
const requestOptions: ComposioRequestOptions | undefined =
|
|
988
|
+
options?.signal != null ? { signal: options.signal } : undefined;
|
|
989
|
+
const { signal: _, ...modifiers } = options ?? {};
|
|
990
|
+
const toolkitSlug = tool.toolkit?.slug ?? 'unknown';
|
|
991
|
+
|
|
992
|
+
const params = await this.applyBeforeExecuteModifiers(
|
|
993
|
+
tool,
|
|
994
|
+
{
|
|
995
|
+
toolSlug: slug,
|
|
996
|
+
toolkitSlug,
|
|
997
|
+
params: body,
|
|
998
|
+
},
|
|
999
|
+
modifiers as ExecuteToolModifiers,
|
|
1000
|
+
requestOptions
|
|
1001
|
+
);
|
|
1002
|
+
|
|
1003
|
+
let result = await this.executeComposioTool(tool, params, requestOptions);
|
|
1004
|
+
|
|
1005
|
+
result = await this.applyAfterExecuteModifiers(
|
|
1006
|
+
tool,
|
|
1007
|
+
{
|
|
1008
|
+
toolSlug: slug,
|
|
1009
|
+
toolkitSlug,
|
|
1010
|
+
result,
|
|
1011
|
+
},
|
|
1012
|
+
(modifiers as ExecuteToolModifiers).afterExecute,
|
|
1013
|
+
requestOptions
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
return result;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
private parseToolExecuteParams(body: ToolExecuteParams): ToolExecuteParams {
|
|
1020
|
+
const executeParams = ToolExecuteParamsSchema.safeParse(body);
|
|
1021
|
+
if (!executeParams.success) {
|
|
1022
|
+
throw new ValidationError('Invalid tool execute parameters', { cause: executeParams.error });
|
|
1023
|
+
}
|
|
1024
|
+
return executeParams.data;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
964
1027
|
/**
|
|
965
1028
|
* Executes a given tool with the provided parameters.
|
|
966
1029
|
*
|
|
@@ -1046,51 +1109,19 @@ export class Tools<
|
|
|
1046
1109
|
body: ToolExecuteParams,
|
|
1047
1110
|
options?: ExecuteToolModifiers & ComposioRequestOptions
|
|
1048
1111
|
): Promise<ToolExecuteResponse> {
|
|
1049
|
-
const executeParams =
|
|
1050
|
-
if (!executeParams.success) {
|
|
1051
|
-
throw new ValidationError('Invalid tool execute parameters', { cause: executeParams.error });
|
|
1052
|
-
}
|
|
1112
|
+
const executeParams = this.parseToolExecuteParams(body);
|
|
1053
1113
|
|
|
1054
1114
|
const requestOptions: ComposioRequestOptions | undefined =
|
|
1055
1115
|
options?.signal != null ? { signal: options.signal } : undefined;
|
|
1056
|
-
const { signal: _, ...modifiers } = options ?? {};
|
|
1057
1116
|
|
|
1058
1117
|
const tool = await this.getRawComposioToolBySlug(
|
|
1059
1118
|
slug,
|
|
1060
1119
|
{
|
|
1061
|
-
version:
|
|
1062
|
-
},
|
|
1063
|
-
requestOptions
|
|
1064
|
-
);
|
|
1065
|
-
const toolkitSlug = tool.toolkit?.slug ?? 'unknown';
|
|
1066
|
-
|
|
1067
|
-
// Apply before execute modifiers
|
|
1068
|
-
const params = await this.applyBeforeExecuteModifiers(
|
|
1069
|
-
tool,
|
|
1070
|
-
{
|
|
1071
|
-
toolSlug: slug,
|
|
1072
|
-
toolkitSlug,
|
|
1073
|
-
params: executeParams.data,
|
|
1120
|
+
version: executeParams.version,
|
|
1074
1121
|
},
|
|
1075
|
-
modifiers as ExecuteToolModifiers,
|
|
1076
1122
|
requestOptions
|
|
1077
1123
|
);
|
|
1078
|
-
|
|
1079
|
-
let result = await this.executeComposioTool(tool, params, requestOptions);
|
|
1080
|
-
|
|
1081
|
-
// Apply after execute modifiers
|
|
1082
|
-
result = await this.applyAfterExecuteModifiers(
|
|
1083
|
-
tool,
|
|
1084
|
-
{
|
|
1085
|
-
toolSlug: slug,
|
|
1086
|
-
toolkitSlug,
|
|
1087
|
-
result,
|
|
1088
|
-
},
|
|
1089
|
-
(modifiers as ExecuteToolModifiers).afterExecute,
|
|
1090
|
-
requestOptions
|
|
1091
|
-
);
|
|
1092
|
-
|
|
1093
|
-
return result;
|
|
1124
|
+
return this.executeWithTool(slug, executeParams, options, tool);
|
|
1094
1125
|
}
|
|
1095
1126
|
|
|
1096
1127
|
/**
|
package/src/platform/node.ts
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as os from 'node:os';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
+
import { isFsCaseSensitive } from 'is-fs-case-sensitive';
|
|
4
5
|
import type { Platform, Uint8ArrayEncoding } from './types';
|
|
5
6
|
|
|
7
|
+
const findNearestExistingDirectory = (filePath: string): string => {
|
|
8
|
+
let candidate = path.resolve(filePath);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
if (!fs.statSync(candidate).isDirectory()) {
|
|
12
|
+
candidate = path.dirname(candidate);
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
candidate = path.dirname(candidate);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
while (true) {
|
|
19
|
+
try {
|
|
20
|
+
if (fs.statSync(candidate).isDirectory()) {
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
// Walk toward the filesystem root until an existing directory is found.
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const parent = path.dirname(candidate);
|
|
28
|
+
if (parent === candidate) {
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
candidate = parent;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
6
35
|
/**
|
|
7
36
|
* Node.js platform implementation.
|
|
8
37
|
* Provides full file system and OS operations using Node.js built-in modules.
|
|
@@ -42,6 +71,17 @@ export const platform = {
|
|
|
42
71
|
return fs.realpathSync(filePath);
|
|
43
72
|
},
|
|
44
73
|
|
|
74
|
+
isFileSystemCaseSensitive(filePath: string): boolean {
|
|
75
|
+
try {
|
|
76
|
+
return isFsCaseSensitive(findNearestExistingDirectory(filePath));
|
|
77
|
+
} catch {
|
|
78
|
+
// Detection must not weaken this security guard. If the target mount
|
|
79
|
+
// cannot be inspected, compare case-insensitively and accept possible
|
|
80
|
+
// false positives instead of allowing a casing bypass.
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
|
|
45
85
|
mkdirSync(dirPath: string): void {
|
|
46
86
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
47
87
|
},
|
package/src/platform/types.ts
CHANGED
|
@@ -52,6 +52,15 @@ export interface Platform {
|
|
|
52
52
|
*/
|
|
53
53
|
realpathSync(filePath: string): string;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Returns whether paths on the filesystem containing `filePath` are
|
|
57
|
+
* case-sensitive. Node checks the nearest existing directory so the result
|
|
58
|
+
* follows the target mount rather than the operating-system default.
|
|
59
|
+
* Runtimes without a filesystem return true to preserve exact path matching.
|
|
60
|
+
* @param filePath - A file or directory on the filesystem to inspect.
|
|
61
|
+
*/
|
|
62
|
+
isFileSystemCaseSensitive?(filePath: string): boolean;
|
|
63
|
+
|
|
55
64
|
/**
|
|
56
65
|
* Creates a directory at the given path, including parent directories if needed.
|
|
57
66
|
* @param dirPath - The directory path to create.
|
package/src/platform/workerd.ts
CHANGED
|
@@ -82,6 +82,11 @@ export const platform: Platform = {
|
|
|
82
82
|
return filePath;
|
|
83
83
|
},
|
|
84
84
|
|
|
85
|
+
isFileSystemCaseSensitive(_filePath: string): boolean {
|
|
86
|
+
// Preserve exact matching when there is no filesystem to inspect.
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
|
|
85
90
|
mkdirSync(_dirPath: string): void {
|
|
86
91
|
// No-op in edge runtimes - directories cannot be created
|
|
87
92
|
},
|
package/src/telemetry/redact.ts
CHANGED
|
@@ -20,8 +20,13 @@ const REDACTION_RULES: ReadonlyArray<readonly [RegExp, string]> = [
|
|
|
20
20
|
// Authorization scheme + credential: `Bearer <token>`, `Basic <token>`.
|
|
21
21
|
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
22
22
|
// Secret-ish `key: value` / `key=value` / `key: "value"` / `key: 'value'` pairs.
|
|
23
|
+
// The separator group allows a quote directly after the key name so JSON is
|
|
24
|
+
// covered: in `{"api_key": "secret"}` the key's own closing quote sits
|
|
25
|
+
// between the name and the colon.
|
|
26
|
+
// Leading lookbehind (not \b) so env-style names like COMPOSIO_API_KEY still
|
|
27
|
+
// match: underscore is a word char, so \b can't fire between COMPOSIO_ and API.
|
|
23
28
|
[
|
|
24
|
-
|
|
29
|
+
/(?<![A-Za-z0-9])(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(["']?\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi,
|
|
25
30
|
`$1$2$3${REDACTED}$3`,
|
|
26
31
|
],
|
|
27
32
|
];
|
package/src/types/tool.types.ts
CHANGED
|
@@ -26,10 +26,55 @@ const JSONSchemaType = z.enum([
|
|
|
26
26
|
'array',
|
|
27
27
|
'null',
|
|
28
28
|
]);
|
|
29
|
+
type JSONSchemaTypeName = z.infer<typeof JSONSchemaType>;
|
|
29
30
|
|
|
30
31
|
// JSON Schema property definition
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
export interface JSONSchemaProperty {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
type?: JSONSchemaTypeName | JSONSchemaTypeName[];
|
|
35
|
+
description?: string;
|
|
36
|
+
anyOf?: JSONSchemaProperty[];
|
|
37
|
+
oneOf?: JSONSchemaProperty[];
|
|
38
|
+
allOf?: JSONSchemaProperty[];
|
|
39
|
+
not?: JSONSchemaProperty;
|
|
40
|
+
title?: string;
|
|
41
|
+
default?: unknown;
|
|
42
|
+
nullable?: boolean;
|
|
43
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
44
|
+
required?: string[];
|
|
45
|
+
file_uploadable?: boolean;
|
|
46
|
+
file_downloadable?: boolean;
|
|
47
|
+
items?: JSONSchemaProperty | JSONSchemaProperty[];
|
|
48
|
+
enum?: unknown[];
|
|
49
|
+
const?: unknown;
|
|
50
|
+
minimum?: number;
|
|
51
|
+
maximum?: number;
|
|
52
|
+
exclusiveMinimum?: number;
|
|
53
|
+
exclusiveMaximum?: number;
|
|
54
|
+
multipleOf?: number;
|
|
55
|
+
minLength?: number;
|
|
56
|
+
maxLength?: number;
|
|
57
|
+
pattern?: string;
|
|
58
|
+
format?: string;
|
|
59
|
+
minItems?: number;
|
|
60
|
+
maxItems?: number;
|
|
61
|
+
uniqueItems?: boolean;
|
|
62
|
+
minProperties?: number;
|
|
63
|
+
maxProperties?: number;
|
|
64
|
+
patternProperties?: Record<string, JSONSchemaProperty>;
|
|
65
|
+
additionalProperties?: boolean | JSONSchemaProperty;
|
|
66
|
+
examples?: unknown[];
|
|
67
|
+
readOnly?: boolean;
|
|
68
|
+
writeOnly?: boolean;
|
|
69
|
+
if?: JSONSchemaProperty;
|
|
70
|
+
then?: JSONSchemaProperty;
|
|
71
|
+
else?: JSONSchemaProperty;
|
|
72
|
+
$ref?: string;
|
|
73
|
+
definitions?: Record<string, JSONSchemaProperty>;
|
|
74
|
+
$defs?: Record<string, JSONSchemaProperty>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const JSONSchemaPropertySchema: z.ZodType<JSONSchemaProperty> = z.object({
|
|
33
78
|
type: z.union([JSONSchemaType, z.array(JSONSchemaType)]).optional(),
|
|
34
79
|
description: z.string().optional(),
|
|
35
80
|
anyOf: z.lazy(() => z.array(JSONSchemaPropertySchema)).optional(),
|
|
@@ -37,7 +82,7 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
|
|
|
37
82
|
allOf: z.lazy(() => z.array(JSONSchemaPropertySchema)).optional(),
|
|
38
83
|
not: z.lazy(() => JSONSchemaPropertySchema).optional(),
|
|
39
84
|
title: z.string().optional(),
|
|
40
|
-
default: z.
|
|
85
|
+
default: z.unknown().optional(),
|
|
41
86
|
nullable: z.boolean().optional(),
|
|
42
87
|
properties: z.lazy(() => z.record(z.string(), JSONSchemaPropertySchema)).optional(),
|
|
43
88
|
required: z.array(z.string()).optional(),
|
|
@@ -46,8 +91,8 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
|
|
|
46
91
|
items: z
|
|
47
92
|
.lazy(() => z.union([JSONSchemaPropertySchema, z.array(JSONSchemaPropertySchema)]))
|
|
48
93
|
.optional(),
|
|
49
|
-
enum: z.array(z.
|
|
50
|
-
const: z.
|
|
94
|
+
enum: z.array(z.unknown()).optional(),
|
|
95
|
+
const: z.unknown().optional(),
|
|
51
96
|
minimum: z.number().optional(),
|
|
52
97
|
maximum: z.number().optional(),
|
|
53
98
|
exclusiveMinimum: z.number().optional(),
|
|
@@ -64,7 +109,7 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
|
|
|
64
109
|
maxProperties: z.number().optional(),
|
|
65
110
|
patternProperties: z.lazy(() => z.record(z.string(), JSONSchemaPropertySchema)).optional(),
|
|
66
111
|
additionalProperties: z.union([z.boolean(), z.lazy(() => JSONSchemaPropertySchema)]).optional(),
|
|
67
|
-
examples: z.array(z.
|
|
112
|
+
examples: z.array(z.unknown()).optional(),
|
|
68
113
|
readOnly: z.boolean().optional(),
|
|
69
114
|
writeOnly: z.boolean().optional(),
|
|
70
115
|
if: z.lazy(() => JSONSchemaPropertySchema).optional(),
|
|
@@ -84,7 +129,6 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
|
|
|
84
129
|
)
|
|
85
130
|
.optional(),
|
|
86
131
|
});
|
|
87
|
-
export type JSONSchemaProperty = z.infer<typeof JSONSchemaPropertySchema>;
|
|
88
132
|
|
|
89
133
|
// Schema for parameters (input/output)
|
|
90
134
|
const ParametersSchema = z.preprocess(
|
|
@@ -95,13 +139,19 @@ const ParametersSchema = z.preprocess(
|
|
|
95
139
|
oneOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
96
140
|
allOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
97
141
|
not: JSONSchemaPropertySchema.optional(),
|
|
98
|
-
properties: z.record(z.string(), JSONSchemaPropertySchema),
|
|
142
|
+
properties: z.record(z.string(), JSONSchemaPropertySchema).optional(),
|
|
99
143
|
required: z.array(z.string()).optional(),
|
|
100
144
|
title: z.string().optional(),
|
|
101
|
-
default: z.
|
|
145
|
+
default: z.unknown().optional(),
|
|
102
146
|
nullable: z.boolean().optional(),
|
|
103
147
|
description: z.string().optional(),
|
|
104
|
-
|
|
148
|
+
// Dynamic-key constraints the Composio API ships at the parameters root.
|
|
149
|
+
// Both were previously lost on parse: `patternProperties` was stripped as an
|
|
150
|
+
// unknown key, and a schema-valued `additionalProperties` was rejected
|
|
151
|
+
// outright by the boolean-only schema. Omission still stays omission —
|
|
152
|
+
// downstream converters, not the parser, decide the implicit policy.
|
|
153
|
+
patternProperties: z.record(z.string(), JSONSchemaPropertySchema).optional(),
|
|
154
|
+
additionalProperties: z.union([z.boolean(), JSONSchemaPropertySchema]).optional(),
|
|
105
155
|
// Definition blocks targeted by `$ref` pointers. The Composio API ships
|
|
106
156
|
// these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but
|
|
107
157
|
// because `z.object` strips unknown keys they were being dropped on parse —
|
|
@@ -176,6 +176,9 @@ const readFileContentFromURL = async (
|
|
|
176
176
|
// redirect into them. See ssrfGuard.node.ts.
|
|
177
177
|
const response = await ssrfSafeFetch(path, { signal });
|
|
178
178
|
if (!response.ok) {
|
|
179
|
+
// The error path never reads the body, so release it explicitly (mirrors
|
|
180
|
+
// `readResponseBodyWithLimit`) instead of leaving it to the garbage collector.
|
|
181
|
+
await response.body?.cancel().catch(() => undefined);
|
|
179
182
|
throw new Error(`Failed to fetch file: ${response.statusText}`);
|
|
180
183
|
}
|
|
181
184
|
const content = await readResponseBodyWithLimit(response);
|
package/src/utils/jsonSchema.ts
CHANGED
|
@@ -258,6 +258,91 @@ export function dereferenceJsonSchema<T = unknown>(
|
|
|
258
258
|
return out as T;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Returns a deep-cloned JSON Schema in which every node that carries a
|
|
263
|
+
* `properties` keyword also carries `type: "object"` when it has no explicit
|
|
264
|
+
* `type`. OpenAI tolerates the omission, but Google Gemini enforces OpenAPI
|
|
265
|
+
* 3.0 strictly and rejects function declarations whose nested objects are
|
|
266
|
+
* missing the `type` (see https://github.com/ComposioHQ/composio/issues/4022).
|
|
267
|
+
*
|
|
268
|
+
* The function follows JSON Schema's schema-bearing keywords while keeping
|
|
269
|
+
* property maps and instance values as containers. Nodes that already declare
|
|
270
|
+
* a `type` are left untouched.
|
|
271
|
+
*/
|
|
272
|
+
export function ensureObjectTypeOnProperties<T = unknown>(schema: T): T {
|
|
273
|
+
type WalkMode = 'schema' | 'schema-array' | 'schema-map' | 'dependencies-map' | 'value';
|
|
274
|
+
|
|
275
|
+
const schemaKeywords = new Set([
|
|
276
|
+
'additionalItems',
|
|
277
|
+
'additionalProperties',
|
|
278
|
+
'contains',
|
|
279
|
+
'contentSchema',
|
|
280
|
+
'else',
|
|
281
|
+
'if',
|
|
282
|
+
'not',
|
|
283
|
+
'propertyNames',
|
|
284
|
+
'then',
|
|
285
|
+
'unevaluatedItems',
|
|
286
|
+
'unevaluatedProperties',
|
|
287
|
+
]);
|
|
288
|
+
const schemaArrayKeywords = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
|
|
289
|
+
const schemaMapKeywords = new Set([
|
|
290
|
+
'$defs',
|
|
291
|
+
'definitions',
|
|
292
|
+
'dependentSchemas',
|
|
293
|
+
'patternProperties',
|
|
294
|
+
'properties',
|
|
295
|
+
]);
|
|
296
|
+
|
|
297
|
+
function walk(value: unknown, mode: WalkMode, depth = 0): unknown {
|
|
298
|
+
if (depth > MAX_NODE_DEPTH) {
|
|
299
|
+
throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (Array.isArray(value)) {
|
|
303
|
+
const itemMode = mode === 'schema-array' ? 'schema' : 'value';
|
|
304
|
+
return value.map(item => walk(item, itemMode, depth + 1));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!isPlainObject(value)) return value;
|
|
308
|
+
|
|
309
|
+
const clone: Record<string, unknown> = {};
|
|
310
|
+
for (const [key, child] of Object.entries(value)) {
|
|
311
|
+
let childMode: WalkMode = 'value';
|
|
312
|
+
if (mode === 'schema-map') {
|
|
313
|
+
childMode = 'schema';
|
|
314
|
+
} else if (mode === 'dependencies-map') {
|
|
315
|
+
childMode = Array.isArray(child) ? 'value' : 'schema';
|
|
316
|
+
} else if (mode === 'schema') {
|
|
317
|
+
if (schemaMapKeywords.has(key)) {
|
|
318
|
+
childMode = 'schema-map';
|
|
319
|
+
} else if (schemaArrayKeywords.has(key) || (key === 'items' && Array.isArray(child))) {
|
|
320
|
+
childMode = 'schema-array';
|
|
321
|
+
} else if (schemaKeywords.has(key) || key === 'items') {
|
|
322
|
+
childMode = 'schema';
|
|
323
|
+
} else if (key === 'dependencies') {
|
|
324
|
+
childMode = 'dependencies-map';
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
Object.defineProperty(clone, key, {
|
|
329
|
+
configurable: true,
|
|
330
|
+
enumerable: true,
|
|
331
|
+
value: walk(child, childMode, depth + 1),
|
|
332
|
+
writable: true,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (mode === 'schema' && clone.properties !== undefined && clone.type === undefined) {
|
|
337
|
+
clone.type = 'object';
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return clone;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return walk(schema, 'schema') as T;
|
|
344
|
+
}
|
|
345
|
+
|
|
261
346
|
/**
|
|
262
347
|
* Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
|
|
263
348
|
* at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
|
|
@@ -328,7 +413,7 @@ export const removeNonRequiredProperties = <
|
|
|
328
413
|
type: 'object';
|
|
329
414
|
properties: Record<string, unknown>;
|
|
330
415
|
required?: string[];
|
|
331
|
-
additionalProperties?:
|
|
416
|
+
additionalProperties?: unknown;
|
|
332
417
|
},
|
|
333
418
|
>(
|
|
334
419
|
schema: T
|
|
@@ -39,9 +39,9 @@ import { withCancellation } from '../cancellation';
|
|
|
39
39
|
* whose schema omits the `$defs` target working (see
|
|
40
40
|
* https://github.com/ComposioHQ/composio/issues/3307) instead of throwing.
|
|
41
41
|
*/
|
|
42
|
-
const resolveFileSchema = (
|
|
43
|
-
schema:
|
|
44
|
-
):
|
|
42
|
+
const resolveFileSchema = <Schema extends JSONSchemaProperty>(
|
|
43
|
+
schema: Schema | undefined
|
|
44
|
+
): Schema | undefined =>
|
|
45
45
|
schema ? dereferenceJsonSchema(schema, { onUnresolved: 'sentinel' }) : schema;
|
|
46
46
|
|
|
47
47
|
const getSchemaVariants = (schema: JSONSchemaProperty | undefined): JSONSchemaProperty[] => [
|
|
@@ -59,10 +59,12 @@ const transformSchema = (property: JSONSchemaProperty): JSONSchemaProperty => {
|
|
|
59
59
|
* @param properties - The properties of the tool schema.
|
|
60
60
|
* @returns The transformed properties.
|
|
61
61
|
*/
|
|
62
|
-
export const transformProperties = (
|
|
63
|
-
|
|
62
|
+
export const transformProperties = (
|
|
63
|
+
properties: Record<string, JSONSchemaProperty>
|
|
64
|
+
): Record<string, JSONSchemaProperty> => {
|
|
65
|
+
const newProperties: Record<string, JSONSchemaProperty> = {};
|
|
64
66
|
|
|
65
|
-
for (const [key, property] of Object.entries(properties)
|
|
67
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
66
68
|
newProperties[key] = transformSchema(property);
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -81,7 +83,7 @@ export const schemaHasFileProperty = (
|
|
|
81
83
|
|
|
82
84
|
// Check nested properties
|
|
83
85
|
if (schema.properties) {
|
|
84
|
-
for (const prop of Object.values(schema.properties)
|
|
86
|
+
for (const prop of Object.values(schema.properties)) {
|
|
85
87
|
if (schemaHasFileProperty(prop, property)) return true;
|
|
86
88
|
}
|
|
87
89
|
}
|
package/src/utils/sdk.ts
CHANGED
|
@@ -64,8 +64,8 @@ export function getSDKConfig(baseUrl?: string | null, apiKey?: string | null) {
|
|
|
64
64
|
*
|
|
65
65
|
* Priority order:
|
|
66
66
|
* 1. If defaultVersions is a string, use it as global version for all toolkits
|
|
67
|
-
* 2.
|
|
68
|
-
* 3.
|
|
67
|
+
* 2. User-provided toolkit version mappings (defaultVersions object)
|
|
68
|
+
* 3. Environment variables (COMPOSIO_TOOLKIT_VERSION_<TOOLKIT_NAME>)
|
|
69
69
|
* 4. Fallback to 'latest' if no versions are configured
|
|
70
70
|
*
|
|
71
71
|
* @param defaultVersions - Optional default versions configuration (string for global version or object mapping toolkit names to versions)
|