@composio/core 0.13.1 → 0.14.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/README.md +62 -247
- package/dist/BaseProvider-lCxnjFKQ.d.mts +29395 -0
- package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-C_5NvBsX.mjs} +17 -15
- package/dist/{CustomTool-DLf7JeKt.d.mts → CustomTool-CmokRT9q.d.mts} +1 -1
- package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-BQRozkeU.mjs} +33 -1
- package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-llfvticE.mjs} +40 -8
- package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-W65QRyj2.mjs} +64 -19
- package/dist/{composio-BHSQwOUz.d.mts → composio-6C8kHtqc.d.mts} +827 -808
- package/dist/{customTool.types-9yFqPjdw.d.mts → customTool.types-kFhNYuzh.d.mts} +502 -502
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
- package/dist/{errors-DSIlYfl5.mjs → errors-B165yJUQ.mjs} +74 -74
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-iPFi2o4i.mjs} +182 -68
- package/dist/index.d.mts +1451 -1400
- package/dist/index.mjs +1408 -1378
- package/dist/models/Files.node.mjs +2 -2
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +3 -0
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/platform/workerd.mjs +3 -0
- package/dist/sensitiveFileUploadPaths-B1OLsd8F.mjs +114 -0
- package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
- package/dist/{types-BJLCRj9q.d.mts → types-yCrveqAj.d.mts} +2 -2
- 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 +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +10 -10
- package/src/errors/SsrfErrors.ts +47 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +10 -0
- package/src/models/CustomTool.ts +1 -3
- package/src/models/ToolRouterSession.ts +38 -16
- package/src/models/Tools.ts +32 -2
- package/src/models/Triggers.ts +16 -76
- package/src/platform/node.ts +4 -0
- package/src/platform/types.ts +10 -0
- package/src/platform/workerd.ts +6 -0
- package/src/provider/OpenAIProvider.ts +19 -14
- package/src/telemetry/Telemetry.ts +9 -6
- package/src/telemetry/redact.ts +40 -0
- package/src/types/tool.types.ts +36 -32
- package/src/utils/fileUtils.node.ts +27 -4
- package/src/utils/jsonSchema.ts +58 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
- package/src/utils/sdk.ts +5 -4
- package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
- package/src/utils/ssrfGuard.node.ts +202 -0
- package/src/utils/toolkitVersion.ts +21 -2
- package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
- package/dist/CustomTool-NpHpqdnU.d.mts +0 -74
- package/dist/buffer-PcbMMsgm.mjs +0 -33
- package/dist/composio-DfPD7BAi.d.mts +0 -5666
- package/dist/customTool.types-D-6YqFdW.d.mts +0 -2826
- package/dist/types-CCh8qvui.d.mts +0 -12
package/src/models/Triggers.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
} from '../types/triggers.types';
|
|
41
41
|
import logger from '../utils/logger';
|
|
42
42
|
import { telemetry } from '../telemetry/Telemetry';
|
|
43
|
-
import {
|
|
43
|
+
import { ValidationError } from '../errors';
|
|
44
44
|
import { PusherService } from '../services/pusher/Pusher';
|
|
45
45
|
import {
|
|
46
46
|
ComposioTriggerTypeNotFoundError,
|
|
@@ -328,6 +328,10 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
328
328
|
body?: TriggerInstanceUpsertParams,
|
|
329
329
|
requestOptions?: ComposioRequestOptions
|
|
330
330
|
): Promise<TriggerInstanceUpsertResponse> {
|
|
331
|
+
if (!userId?.trim()) {
|
|
332
|
+
throw new ValidationError(`A non-empty userId is required to create a trigger`);
|
|
333
|
+
}
|
|
334
|
+
|
|
331
335
|
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
|
|
332
336
|
|
|
333
337
|
if (!parsedBody.success) {
|
|
@@ -336,14 +340,12 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
336
340
|
});
|
|
337
341
|
}
|
|
338
342
|
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
let toolkitSlug: string;
|
|
343
|
+
// Validate the trigger slug up-front so callers get a clear client-side
|
|
344
|
+
// `ComposioTriggerTypeNotFoundError`. The Python SDK mirrors this behavior.
|
|
342
345
|
try {
|
|
343
|
-
|
|
344
|
-
toolkitSlug = triggerType.toolkit.slug;
|
|
346
|
+
await this.getType(slug, requestOptions);
|
|
345
347
|
} catch (error) {
|
|
346
|
-
//
|
|
348
|
+
// The trigger types endpoint returns 400 (not 404) for an unknown slug.
|
|
347
349
|
if (error instanceof APIError && (error.status === 400 || error.status === 404)) {
|
|
348
350
|
throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
|
|
349
351
|
cause: error,
|
|
@@ -353,79 +355,17 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
353
355
|
`Visit the toolkit page to see the available triggers`,
|
|
354
356
|
],
|
|
355
357
|
});
|
|
356
|
-
} else {
|
|
357
|
-
throw error;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Attempt to get connected account ID
|
|
362
|
-
let connectedAccountId: string | undefined = body?.connectedAccountId;
|
|
363
|
-
|
|
364
|
-
try {
|
|
365
|
-
const connectedAccountListParams = {
|
|
366
|
-
user_ids: [userId],
|
|
367
|
-
toolkit_slugs: [toolkitSlug],
|
|
368
|
-
};
|
|
369
|
-
const { items: connectedAccounts } = await withCancellation(
|
|
370
|
-
() => this.client.connectedAccounts.list(connectedAccountListParams, requestOptions),
|
|
371
|
-
requestOptions?.signal
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
if (connectedAccounts.length === 0) {
|
|
375
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
376
|
-
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
377
|
-
{
|
|
378
|
-
cause: new Error(`No connected account found for user ${userId}`),
|
|
379
|
-
possibleFixes: [`Create a new connected account for user ${userId}`],
|
|
380
|
-
}
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const accountExists = connectedAccounts.some(acc => acc.id === connectedAccountId);
|
|
385
|
-
// if the connected account id is provided and it does not exist, throw an error
|
|
386
|
-
if (connectedAccountId && !accountExists) {
|
|
387
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
388
|
-
`Connected account ID ${connectedAccountId} not found for user ${userId}`,
|
|
389
|
-
{
|
|
390
|
-
cause: new Error(
|
|
391
|
-
`Connected account ID ${connectedAccountId} not found for user ${userId}`
|
|
392
|
-
),
|
|
393
|
-
possibleFixes: [
|
|
394
|
-
`Create a new connected account for user ${userId}`,
|
|
395
|
-
`Verify the connected account ID`,
|
|
396
|
-
],
|
|
397
|
-
}
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// if the connected account id is not provided, use the first connected account
|
|
402
|
-
if (!connectedAccountId) {
|
|
403
|
-
connectedAccountId = connectedAccounts[0].id;
|
|
404
|
-
logger.warn(
|
|
405
|
-
`[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
} catch (error) {
|
|
409
|
-
if (error instanceof APIError && [400, 404].includes(error.status)) {
|
|
410
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
411
|
-
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
412
|
-
{
|
|
413
|
-
cause: error,
|
|
414
|
-
possibleFixes: [`Create a new connected account for user ${userId}`],
|
|
415
|
-
}
|
|
416
|
-
);
|
|
417
358
|
}
|
|
418
359
|
throw error;
|
|
419
360
|
}
|
|
420
361
|
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
connected_account_id: connectedAccountId,
|
|
362
|
+
// Pass `user_id` straight through: when `connected_account_id` is omitted the
|
|
363
|
+
// backend resolves the first active connection for this user and the
|
|
364
|
+
// trigger's toolkit, mirroring tool execution. When 2FA is enabled and
|
|
365
|
+
// `connected_account_id` is pinned, the backend validates that `user_id`
|
|
366
|
+
// owns it.
|
|
367
|
+
const upsertParams: ClientTriggerInstanceUpsertParams = {
|
|
368
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
429
369
|
trigger_config: parsedBody.data.triggerConfig,
|
|
430
370
|
toolkit_versions: this.toolkitVersions,
|
|
431
371
|
user_id: userId,
|
package/src/platform/node.ts
CHANGED
package/src/platform/types.ts
CHANGED
|
@@ -42,6 +42,16 @@ export interface Platform {
|
|
|
42
42
|
*/
|
|
43
43
|
existsSync(filePath: string): boolean;
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Resolves symlinks in a path, returning the canonical absolute path. On Node
|
|
47
|
+
* this is `fs.realpathSync`; on edge runtimes without a filesystem it returns
|
|
48
|
+
* the input path unchanged (best-effort). Used to prevent a symlink from
|
|
49
|
+
* smuggling an upload past the sensitive-path denylist.
|
|
50
|
+
* @param filePath - The path to canonicalize.
|
|
51
|
+
* @returns The resolved path, or the input path if it cannot be resolved.
|
|
52
|
+
*/
|
|
53
|
+
realpathSync(filePath: string): string;
|
|
54
|
+
|
|
45
55
|
/**
|
|
46
56
|
* Creates a directory at the given path, including parent directories if needed.
|
|
47
57
|
* @param dirPath - The directory path to create.
|
package/src/platform/workerd.ts
CHANGED
|
@@ -49,6 +49,12 @@ export const platform: Platform = {
|
|
|
49
49
|
return false;
|
|
50
50
|
},
|
|
51
51
|
|
|
52
|
+
realpathSync(filePath: string): string {
|
|
53
|
+
// No filesystem in edge runtimes: cannot resolve symlinks, so return the
|
|
54
|
+
// input unchanged. Local-path uploads don't happen on workerd anyway.
|
|
55
|
+
return filePath;
|
|
56
|
+
},
|
|
57
|
+
|
|
52
58
|
mkdirSync(_dirPath: string): void {
|
|
53
59
|
// No-op in edge runtimes - directories cannot be created
|
|
54
60
|
},
|
|
@@ -16,6 +16,7 @@ import { ExecuteToolModifiers } from '../types/modifiers.types';
|
|
|
16
16
|
import { ExecuteToolFnOptions } from '../types/provider.types';
|
|
17
17
|
import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
|
|
18
18
|
import { normalizeToolArguments } from '../utils/toolArguments';
|
|
19
|
+
import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
|
|
19
20
|
|
|
20
21
|
export type OpenAiTool = OpenAI.ChatCompletionTool;
|
|
21
22
|
export type OpenAiToolCollection = Array<OpenAiTool>;
|
|
@@ -96,7 +97,7 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
96
97
|
const formattedSchema: OpenAI.FunctionDefinition = {
|
|
97
98
|
name: tool.slug,
|
|
98
99
|
description: tool.description,
|
|
99
|
-
parameters: tool.inputParameters,
|
|
100
|
+
parameters: deduplicateJsonSchemaRequiredArrays(tool.inputParameters),
|
|
100
101
|
};
|
|
101
102
|
return {
|
|
102
103
|
type: 'function',
|
|
@@ -246,20 +247,24 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
246
247
|
modifiers?: ExecuteToolModifiers
|
|
247
248
|
): Promise<OpenAI.ChatCompletionToolMessageParam[]> {
|
|
248
249
|
const outputs: OpenAI.ChatCompletionToolMessageParam[] = [];
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
content: toolResult,
|
|
261
|
-
});
|
|
250
|
+
// Only the first choice is actionable: its tool results feed back into a
|
|
251
|
+
// single assistant turn. With n > 1, iterating every choice would run each
|
|
252
|
+
// tool call once per choice and orphan the tool_call_ids belonging to the
|
|
253
|
+
// alternative completions.
|
|
254
|
+
const [choice] = chatCompletion.choices;
|
|
255
|
+
// A single assistant message can carry several tool calls (parallel tool
|
|
256
|
+
// calls, on by default). Each one needs its own tool result, otherwise the
|
|
257
|
+
// next request fails since some tool_call_ids go unanswered.
|
|
258
|
+
for (const toolCall of choice?.message.tool_calls ?? []) {
|
|
259
|
+
if (toolCall.type !== 'function') {
|
|
260
|
+
continue;
|
|
262
261
|
}
|
|
262
|
+
const toolResult = await this.executeToolCall(userId, toolCall, options, modifiers);
|
|
263
|
+
outputs.push({
|
|
264
|
+
role: 'tool',
|
|
265
|
+
tool_call_id: toolCall.id,
|
|
266
|
+
content: toolResult,
|
|
267
|
+
});
|
|
263
268
|
}
|
|
264
269
|
return outputs;
|
|
265
270
|
}
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from '../services/telemetry/TelemetryService.types';
|
|
19
19
|
import { TelemetryService } from '../services/telemetry/TelemetryService';
|
|
20
20
|
import logger from '../utils/logger';
|
|
21
|
+
import { redactSensitiveText } from './redact';
|
|
21
22
|
/**
|
|
22
23
|
* The Telemetry class is used to log the telemetry for any given instance which extends InstrumentedInstance.
|
|
23
24
|
*
|
|
@@ -207,28 +208,30 @@ export class TelemetryTransport {
|
|
|
207
208
|
},
|
|
208
209
|
source: this.telemetrySource,
|
|
209
210
|
};
|
|
211
|
+
// Redact secrets (URLs with tokens, Authorization headers, API keys, etc.)
|
|
212
|
+
// from free-form error text before it is transported off-process.
|
|
210
213
|
// client error, this is likely handled by the API itseld
|
|
211
214
|
if (error instanceof ComposioClientError) {
|
|
212
215
|
telemetryPayload.error = {
|
|
213
216
|
errorId: error.errorId,
|
|
214
217
|
name: error.name,
|
|
215
|
-
message: error.message,
|
|
216
|
-
stack: error.stack,
|
|
218
|
+
message: redactSensitiveText(error.message),
|
|
219
|
+
stack: redactSensitiveText(error.stack),
|
|
217
220
|
};
|
|
218
221
|
} else if (error instanceof ComposioError) {
|
|
219
222
|
telemetryPayload.error = {
|
|
220
223
|
errorId: error.errorId,
|
|
221
224
|
name: error.name,
|
|
222
225
|
code: error.code,
|
|
223
|
-
message: error.message,
|
|
224
|
-
stack: error.stack,
|
|
226
|
+
message: redactSensitiveText(error.message),
|
|
227
|
+
stack: redactSensitiveText(error.stack),
|
|
225
228
|
};
|
|
226
229
|
} else if (error instanceof Error) {
|
|
227
230
|
telemetryPayload.error = {
|
|
228
231
|
errorId: error.errorId,
|
|
229
232
|
name: error.name ?? 'Unknown error',
|
|
230
|
-
message: error.message,
|
|
231
|
-
stack: error.stack,
|
|
233
|
+
message: redactSensitiveText(error.message),
|
|
234
|
+
stack: redactSensitiveText(error.stack),
|
|
232
235
|
};
|
|
233
236
|
}
|
|
234
237
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
3
|
+
* to the telemetry endpoint.
|
|
4
|
+
*
|
|
5
|
+
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
6
|
+
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
7
|
+
* keys, and connected-account identifiers. None of that should leave the
|
|
8
|
+
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
9
|
+
* free-form strings are passed through here.
|
|
10
|
+
*
|
|
11
|
+
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
12
|
+
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const REDACTED = '[REDACTED]';
|
|
16
|
+
|
|
17
|
+
const REDACTION_RULES: ReadonlyArray<readonly [RegExp, string]> = [
|
|
18
|
+
// URL query strings — tokens, presigned signatures, one-time codes.
|
|
19
|
+
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
20
|
+
// Authorization scheme + credential: `Bearer <token>`, `Basic <token>`.
|
|
21
|
+
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
22
|
+
// Secret-ish `key: value` / `key=value` / `key: "value"` / `key: 'value'` pairs.
|
|
23
|
+
[
|
|
24
|
+
/\b(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi,
|
|
25
|
+
`$1$2$3${REDACTED}$3`,
|
|
26
|
+
],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Redact common secret shapes from a free-form string. Returns the input
|
|
31
|
+
* unchanged when it is empty or `undefined`.
|
|
32
|
+
*/
|
|
33
|
+
export const redactSensitiveText = (input: string | undefined): string | undefined => {
|
|
34
|
+
if (!input) return input;
|
|
35
|
+
let output = input;
|
|
36
|
+
for (const [pattern, replacement] of REDACTION_RULES) {
|
|
37
|
+
output = output.replace(pattern, replacement);
|
|
38
|
+
}
|
|
39
|
+
return output;
|
|
40
|
+
};
|
package/src/types/tool.types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
2
|
import { CustomConnectionDataSchema } from './connectedAccountAuthStates.types';
|
|
3
3
|
import { TransformToolSchemaModifier } from './modifiers.types';
|
|
4
|
+
import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Toolkit is the collection of tools,
|
|
@@ -86,38 +87,41 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
|
|
|
86
87
|
export type JSONSchemaProperty = z.infer<typeof JSONSchemaPropertySchema>;
|
|
87
88
|
|
|
88
89
|
// Schema for parameters (input/output)
|
|
89
|
-
const ParametersSchema = z.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
90
|
+
const ParametersSchema = z.preprocess(
|
|
91
|
+
deduplicateJsonSchemaRequiredArrays,
|
|
92
|
+
z.object({
|
|
93
|
+
type: z.literal('object'),
|
|
94
|
+
anyOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
95
|
+
oneOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
96
|
+
allOf: z.array(JSONSchemaPropertySchema).optional(),
|
|
97
|
+
not: JSONSchemaPropertySchema.optional(),
|
|
98
|
+
properties: z.record(z.string(), JSONSchemaPropertySchema),
|
|
99
|
+
required: z.array(z.string()).optional(),
|
|
100
|
+
title: z.string().optional(),
|
|
101
|
+
default: z.any().optional(),
|
|
102
|
+
nullable: z.boolean().optional(),
|
|
103
|
+
description: z.string().optional(),
|
|
104
|
+
additionalProperties: z.boolean().default(false).optional(),
|
|
105
|
+
// Definition blocks targeted by `$ref` pointers. The Composio API ships
|
|
106
|
+
// these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but
|
|
107
|
+
// because `z.object` strips unknown keys they were being dropped on parse —
|
|
108
|
+
// leaving every nested `$ref` dangling and unresolvable downstream
|
|
109
|
+
// (providers, file modifiers). `JSONSchemaPropertySchema` already accepts
|
|
110
|
+
// both keywords; the parameters root must too.
|
|
111
|
+
$defs: z
|
|
112
|
+
.record(
|
|
113
|
+
z.string(),
|
|
114
|
+
z.lazy(() => JSONSchemaPropertySchema)
|
|
115
|
+
)
|
|
116
|
+
.optional(),
|
|
117
|
+
definitions: z
|
|
118
|
+
.record(
|
|
119
|
+
z.string(),
|
|
120
|
+
z.lazy(() => JSONSchemaPropertySchema)
|
|
121
|
+
)
|
|
122
|
+
.optional(),
|
|
123
|
+
})
|
|
124
|
+
);
|
|
121
125
|
|
|
122
126
|
/**
|
|
123
127
|
* Tool is a single action that can be performed by a toolkit.
|
|
@@ -7,8 +7,9 @@ import logger from './logger';
|
|
|
7
7
|
import { getRandomShortId } from './uuid';
|
|
8
8
|
import { base64ToUint8Array, uint8ArrayToBase64 } from './buffer';
|
|
9
9
|
import type { FileDownloadData, FileUploadData } from '../types/files.types';
|
|
10
|
-
import { assertSafeFileUploadPath } from './sensitiveFileUploadPaths
|
|
10
|
+
import { assertSafeFileUploadPath } from './sensitiveFileUploadPaths';
|
|
11
11
|
import { assertPathInsideUploadDirs } from './uploadDirAllowlist.node';
|
|
12
|
+
import { ssrfSafeFetch } from './ssrfGuard.node';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Options for {@link getFileDataAfterUploadingToS3} (S3 presigned upload from local path, URL, or File).
|
|
@@ -39,6 +40,25 @@ export type GetFileDataAfterUploadingToS3Options = {
|
|
|
39
40
|
signal?: AbortSignal;
|
|
40
41
|
};
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether `value` is an absolute http(s) URL rather than a local path.
|
|
45
|
+
*
|
|
46
|
+
* A bare `startsWith('http')` check also matches local paths like
|
|
47
|
+
* `http_export/report.csv` or `httpdocs/.env`, which routes them into the URL
|
|
48
|
+
* fetch branch and skips the allowlist/denylist checks in
|
|
49
|
+
* {@link getFileDataAfterUploadingToS3}. `new URL()` requires a real scheme
|
|
50
|
+
* (`http:` or `https:`) followed by `//`, so relative-looking paths correctly
|
|
51
|
+
* fail to parse and are treated as local.
|
|
52
|
+
*/
|
|
53
|
+
export const isHttpUrl = (value: string): boolean => {
|
|
54
|
+
try {
|
|
55
|
+
const url = new URL(value);
|
|
56
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
42
62
|
// Helper function to get file extension from MIME type
|
|
43
63
|
const getExtensionFromMimeType = (mimeType: string): string => {
|
|
44
64
|
const mimeToExt: Record<string, string> = {
|
|
@@ -150,7 +170,10 @@ const readFileContentFromURL = async (
|
|
|
150
170
|
path: string,
|
|
151
171
|
signal?: AbortSignal
|
|
152
172
|
): Promise<{ fileName: string; content: string; mimeType: string }> => {
|
|
153
|
-
|
|
173
|
+
// SSRF guard: `path` is user-supplied (and can come from an LLM-produced tool
|
|
174
|
+
// argument), so it must not be allowed to reach internal/private addresses or
|
|
175
|
+
// redirect into them. See ssrfGuard.node.ts.
|
|
176
|
+
const response = await ssrfSafeFetch(path, { signal });
|
|
154
177
|
if (!response.ok) {
|
|
155
178
|
throw new Error(`Failed to fetch file: ${response.statusText}`);
|
|
156
179
|
}
|
|
@@ -248,7 +271,7 @@ const readFile = async (
|
|
|
248
271
|
mimeType: file.type,
|
|
249
272
|
};
|
|
250
273
|
} else if (typeof file === 'string') {
|
|
251
|
-
if (file
|
|
274
|
+
if (isHttpUrl(file)) {
|
|
252
275
|
return await readFileContentFromURL(file, signal);
|
|
253
276
|
} else {
|
|
254
277
|
return await readFileContent(file);
|
|
@@ -273,7 +296,7 @@ export const getFileDataAfterUploadingToS3 = async (
|
|
|
273
296
|
throw new Error('Either path or blob must be provided');
|
|
274
297
|
}
|
|
275
298
|
|
|
276
|
-
const isLocalPath = typeof file === 'string' && !file
|
|
299
|
+
const isLocalPath = typeof file === 'string' && !isHttpUrl(file);
|
|
277
300
|
|
|
278
301
|
if (isLocalPath && fileUploadAllowlist !== undefined) {
|
|
279
302
|
assertPathInsideUploadDirs(file as string, fileUploadAllowlist);
|
package/src/utils/jsonSchema.ts
CHANGED
|
@@ -258,6 +258,64 @@ export function dereferenceJsonSchema<T = unknown>(
|
|
|
258
258
|
return out as T;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
|
|
263
|
+
* at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
|
|
264
|
+
* not change the schema's meaning, so preserving the first occurrence is safe.
|
|
265
|
+
*
|
|
266
|
+
* Tool schemas originate both from the Composio API and direct provider calls.
|
|
267
|
+
* Keeping this normalization provider-agnostic lets every SDK provider receive
|
|
268
|
+
* canonical API schemas, while providers that further transform a schema can
|
|
269
|
+
* reapply it at their own emission boundary.
|
|
270
|
+
*/
|
|
271
|
+
export function deduplicateJsonSchemaRequiredArrays<T = unknown>(schema: T): T {
|
|
272
|
+
const seenSchemaValues = new WeakMap<object, unknown>();
|
|
273
|
+
const seenInstanceValues = new WeakMap<object, unknown>();
|
|
274
|
+
const instanceValueKeywords = new Set(['const', 'default', 'enum', 'examples']);
|
|
275
|
+
|
|
276
|
+
function walk(value: unknown, isSchema: boolean, depth = 0): unknown {
|
|
277
|
+
if (depth > MAX_NODE_DEPTH) {
|
|
278
|
+
throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const seen = isSchema ? seenSchemaValues : seenInstanceValues;
|
|
282
|
+
|
|
283
|
+
if (Array.isArray(value)) {
|
|
284
|
+
const existing = seen.get(value);
|
|
285
|
+
if (existing) return existing;
|
|
286
|
+
|
|
287
|
+
const clone: unknown[] = [];
|
|
288
|
+
seen.set(value, clone);
|
|
289
|
+
for (const item of value) {
|
|
290
|
+
clone.push(walk(item, isSchema, depth + 1));
|
|
291
|
+
}
|
|
292
|
+
return clone;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (!isPlainObject(value)) return value;
|
|
296
|
+
|
|
297
|
+
const existing = seen.get(value);
|
|
298
|
+
if (existing) return existing;
|
|
299
|
+
|
|
300
|
+
const clone: Record<string, unknown> = {};
|
|
301
|
+
seen.set(value, clone);
|
|
302
|
+
for (const [key, child] of Object.entries(value)) {
|
|
303
|
+
Object.defineProperty(clone, key, {
|
|
304
|
+
configurable: true,
|
|
305
|
+
enumerable: true,
|
|
306
|
+
value:
|
|
307
|
+
isSchema && key === 'required' && Array.isArray(child)
|
|
308
|
+
? [...new Set(walk(child, false, depth + 1) as unknown[])]
|
|
309
|
+
: walk(child, isSchema && !instanceValueKeywords.has(key), depth + 1),
|
|
310
|
+
writable: true,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return clone;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return walk(schema, true) as T;
|
|
317
|
+
}
|
|
318
|
+
|
|
261
319
|
/**
|
|
262
320
|
* Removes all non-required properties from the schema
|
|
263
321
|
*
|
|
@@ -18,6 +18,7 @@ import type { beforeFileUploadModifier } from '../../types/modifiers.types';
|
|
|
18
18
|
import {
|
|
19
19
|
downloadFileFromS3,
|
|
20
20
|
getFileDataAfterUploadingToS3,
|
|
21
|
+
isHttpUrl,
|
|
21
22
|
type GetFileDataAfterUploadingToS3Options,
|
|
22
23
|
} from '../fileUtils.node';
|
|
23
24
|
import {
|
|
@@ -150,7 +151,7 @@ const hydrateFiles = async (
|
|
|
150
151
|
if (typeof value === 'string') {
|
|
151
152
|
// Match the URL/local-path split used downstream in
|
|
152
153
|
// getFileDataAfterUploadingToS3 so the hook sees the same categorisation.
|
|
153
|
-
const source = value
|
|
154
|
+
const source = isHttpUrl(value) ? 'url' : 'path';
|
|
154
155
|
const pathOrUrl = await runBeforeFileUpload(value, source);
|
|
155
156
|
logger.debug(`Uploading file "${pathOrUrl}"`);
|
|
156
157
|
return getFileDataAfterUploadingToS3(pathOrUrl, {
|
package/src/utils/sdk.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { getEnvsWithPrefix, getEnvVariable } from './env';
|
|
|
4
4
|
import logger from './logger';
|
|
5
5
|
import { ComposioError } from '../errors/ComposioError';
|
|
6
6
|
import { ToolkitVersion, ToolkitVersionParam, ToolkitVersions } from '../types/tool.types';
|
|
7
|
+
import { normalizeToolkitSlug } from './toolkitVersion';
|
|
7
8
|
import { platform } from '#platform';
|
|
8
9
|
|
|
9
10
|
// File path helpers
|
|
@@ -82,16 +83,16 @@ export function getToolkitVersionsFromEnv(
|
|
|
82
83
|
const envPrefixedVersions = getEnvsWithPrefix(`COMPOSIO_TOOLKIT_VERSION_`);
|
|
83
84
|
const toolkitVersionsFromEnv = Object.entries(envPrefixedVersions).reduce((acc, [key, value]) => {
|
|
84
85
|
const toolkitName = key.replace('COMPOSIO_TOOLKIT_VERSION_', '');
|
|
85
|
-
acc[toolkitName
|
|
86
|
+
acc[normalizeToolkitSlug(toolkitName)] = value as ToolkitVersion;
|
|
86
87
|
return acc;
|
|
87
88
|
}, {} as ToolkitVersions);
|
|
88
89
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
90
|
+
// normalize keys via normalizeToolkitSlug (the same helper the lookup uses);
|
|
91
|
+
// user provided values act as overrides
|
|
91
92
|
let userProvidedToolkitVersions = {};
|
|
92
93
|
if (defaultVersions && typeof defaultVersions === 'object') {
|
|
93
94
|
userProvidedToolkitVersions = Object.fromEntries(
|
|
94
|
-
Object.entries(defaultVersions).map(([key, value]) => [key
|
|
95
|
+
Object.entries(defaultVersions).map(([key, value]) => [normalizeToolkitSlug(key), value])
|
|
95
96
|
);
|
|
96
97
|
}
|
|
97
98
|
|