@composio/core 0.14.1 → 0.15.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-BN2-Nktx.d.mts} +303 -258
- package/dist/{CustomTool-4nVuwLzO.d.mts → CustomTool-zjeDpZ91.d.mts} +1 -1
- package/dist/{Telemetry-CF0rNHu2.mjs → Telemetry-DuGJSwUt.mjs} +2 -2
- package/dist/{composio-ChU3eD9F.d.mts → composio-Bf8hnBBq.d.mts} +250 -250
- package/dist/{customTool.types-CX2-LbfI.d.mts → customTool.types-Bhom9a2R.d.mts} +88 -88
- 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 +8 -7
- package/dist/index.mjs +28 -13
- 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-CePuCfD-.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 +1 -1
- 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/models/ToolRouterSessionFileMount.ts +3 -0
- 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 +52 -8
- package/src/utils/fileUtils.node.ts +3 -0
- 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/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(
|
|
@@ -98,7 +142,7 @@ const ParametersSchema = z.preprocess(
|
|
|
98
142
|
properties: z.record(z.string(), JSONSchemaPropertySchema),
|
|
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
|
additionalProperties: z.boolean().default(false).optional(),
|
|
@@ -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);
|
|
@@ -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)
|
|
@@ -12,7 +12,8 @@ import { ComposioSensitiveFilePathBlockedError } from '../errors/FileModifierErr
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Path segments (a single path component) that indicate a sensitive directory when
|
|
15
|
-
* they appear anywhere in a resolved local path.
|
|
15
|
+
* they appear anywhere in a resolved local path. Matching follows the case sensitivity
|
|
16
|
+
* of the filesystem containing that path.
|
|
16
17
|
*/
|
|
17
18
|
export const BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS: readonly string[] = [
|
|
18
19
|
'.ssh',
|
|
@@ -30,12 +31,10 @@ const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
|
|
|
30
31
|
/** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
|
|
31
32
|
const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
|
|
32
33
|
|
|
33
|
-
const isWindows = typeof process !== 'undefined' && process.platform === 'win32';
|
|
34
|
-
|
|
35
34
|
/**
|
|
36
35
|
* Returns normalized path segments, resolving symlinks when the path exists.
|
|
37
36
|
*/
|
|
38
|
-
function
|
|
37
|
+
function normalizePath(filePath: string): { resolvedPath: string; segments: string[] } {
|
|
39
38
|
const absolute = platform.resolvePath(filePath);
|
|
40
39
|
let resolved = absolute;
|
|
41
40
|
try {
|
|
@@ -45,7 +44,10 @@ function normalizePathSegments(filePath: string): string[] {
|
|
|
45
44
|
} catch {
|
|
46
45
|
// If realpath fails (e.g. race), use resolved path
|
|
47
46
|
}
|
|
48
|
-
return
|
|
47
|
+
return {
|
|
48
|
+
resolvedPath: resolved,
|
|
49
|
+
segments: resolved.split(/[/\\]+/).filter(Boolean),
|
|
50
|
+
};
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -63,16 +65,17 @@ function getSensitiveFileUploadPathBlockReason(
|
|
|
63
65
|
filePath: string,
|
|
64
66
|
additionalDenySegments?: string[]
|
|
65
67
|
): string | null {
|
|
66
|
-
const segments =
|
|
68
|
+
const { resolvedPath, segments } = normalizePath(filePath);
|
|
69
|
+
const isCaseSensitive = platform.isFileSystemCaseSensitive?.(resolvedPath) ?? true;
|
|
70
|
+
const normalizeSegment = (segment: string) => (isCaseSensitive ? segment : segment.toLowerCase());
|
|
67
71
|
const deny = new Set(
|
|
68
72
|
[
|
|
69
73
|
...BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
|
|
70
74
|
...(additionalDenySegments ?? []).map(s => s.trim()).filter(Boolean),
|
|
71
|
-
].map(
|
|
75
|
+
].map(normalizeSegment)
|
|
72
76
|
);
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
const segmentsForMatch = isWindows ? segments.map(s => s.toLowerCase()) : segments;
|
|
78
|
+
const segmentsForMatch = isCaseSensitive ? segments : segments.map(normalizeSegment);
|
|
76
79
|
for (let i = 0; i < segments.length; i++) {
|
|
77
80
|
if (deny.has(segmentsForMatch[i]!)) {
|
|
78
81
|
return `path segment "${segments[i]}" is in the sensitive file upload denylist`;
|
|
@@ -171,8 +171,8 @@ export const assertSafeFetchTarget = async (rawUrl: string): Promise<void> => {
|
|
|
171
171
|
/**
|
|
172
172
|
* Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
|
|
173
173
|
* connecting and re-validates every redirect hop (redirects are followed
|
|
174
|
-
* manually up to {@link MAX_REDIRECTS}).
|
|
175
|
-
* unchanged.
|
|
174
|
+
* manually up to {@link MAX_REDIRECTS}). Intermediate redirect bodies are
|
|
175
|
+
* cancelled; non-redirect responses are returned unchanged.
|
|
176
176
|
*/
|
|
177
177
|
export const ssrfSafeFetch = async (
|
|
178
178
|
rawUrl: string,
|
|
@@ -192,6 +192,10 @@ export const ssrfSafeFetch = async (
|
|
|
192
192
|
return response;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// Only `location` is read from a redirect, so release its body explicitly rather
|
|
196
|
+
// than leaving it to the garbage collector (mirrors `readResponseBodyWithLimit`).
|
|
197
|
+
await response.body?.cancel().catch(() => undefined);
|
|
198
|
+
|
|
195
199
|
currentUrl = new URL(response.headers.get('location')!, currentUrl).toString();
|
|
196
200
|
}
|
|
197
201
|
|
package/src/utils/version.ts
CHANGED
|
@@ -2,26 +2,14 @@ import logger from './logger';
|
|
|
2
2
|
import { IS_DEVELOPMENT_OR_CI } from './constants';
|
|
3
3
|
import semver from 'semver';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Compares two semantic versions and returns true if the first version is newer than the second.
|
|
7
|
-
* @param version1 The first version to compare
|
|
8
|
-
* @param version2 The second version to compare
|
|
9
|
-
* @returns boolean indicating if version1 is newer than version2
|
|
10
|
-
*/
|
|
11
|
-
export function isNewerVersion(version1: string, version2: string): boolean {
|
|
12
|
-
const v1 = version1.split('.').map(Number);
|
|
13
|
-
const v2 = version2.split('.').map(Number);
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < 3; i++) {
|
|
16
|
-
if (v1[i] > v2[i]) return true;
|
|
17
|
-
if (v1[i] < v2[i]) return false;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
5
|
+
const VERSION_CHECK_TIMEOUT_MS = 2_000;
|
|
21
6
|
|
|
22
7
|
/**
|
|
23
8
|
* Checks for the latest version of the Composio SDK from NPM.
|
|
24
9
|
* If a newer version is available, it logs a warning to the console.
|
|
10
|
+
*
|
|
11
|
+
* Best-effort: never throws. The npm registry request is aborted after
|
|
12
|
+
* {@link VERSION_CHECK_TIMEOUT_MS} milliseconds.
|
|
25
13
|
*/
|
|
26
14
|
export async function checkForLatestVersionFromNPM(currentVersion: string) {
|
|
27
15
|
try {
|
|
@@ -42,14 +30,27 @@ export async function checkForLatestVersionFromNPM(currentVersion: string) {
|
|
|
42
30
|
return;
|
|
43
31
|
}
|
|
44
32
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
// Bound this best-effort request so a stalled registry cannot leave it pending
|
|
34
|
+
// indefinitely. A hand-rolled timer rather than AbortSignal.timeout so it can be
|
|
35
|
+
// cleared the moment the response lands: an uncleared timer is itself pending work,
|
|
36
|
+
// which on workerd pins the request context open for the full timeout on every
|
|
37
|
+
// successful check.
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timer = setTimeout(() => controller.abort(), VERSION_CHECK_TIMEOUT_MS);
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
|
|
43
|
+
signal: controller.signal,
|
|
44
|
+
});
|
|
45
|
+
data = await response.json();
|
|
46
|
+
} finally {
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
}
|
|
48
49
|
const latestVersion = data.version;
|
|
49
50
|
|
|
50
51
|
if (semver.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
|
|
51
52
|
logger.info(
|
|
52
|
-
`🚀 Upgrade available! Your
|
|
53
|
+
`🚀 Upgrade available! Your ${packageName} version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
56
|
} catch (_error) {
|