@composio/core 0.31.0 → 0.33.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/{CustomTool-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
- package/dist/{CustomTool-Ds5aLDth.d.mts → CustomTool-C2kvAvzk.d.mts} +1 -1
- package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
- package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
- package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-CcCuFVUb.mjs} +2 -2
- package/dist/composio-BqE615oV.d.mts +20365 -0
- package/dist/{customTool.types-DHxXBU6E.d.mts → customTool.types-DnyEZmlx.d.mts} +510 -33
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +20 -12
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +96 -40
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +53 -42
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
- package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +16 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
- package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-DPMtE0ER.mjs} +7 -71
- package/dist/index.d.mts +7 -245
- package/dist/index.mjs +573 -251
- package/dist/jsonSchema-CDHLYm7d.d.mts +237 -0
- package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-CfZwBS13.mjs} +7 -3
- package/dist/models/Files.node.mjs +3 -3
- package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-6NcnFSyX.mjs} +82 -85
- package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
- package/dist/{types-DcdZy5Nc.d.mts → types-Cwr_Makk.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/json-schema.d.mts +2 -1
- package/dist/utils/json-schema.mjs +2 -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/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +1 -1
- package/package.json +6 -6
- package/src/composio.ts +26 -7
- package/src/errors/ComposioError.ts +3 -2
- package/src/index.ts +19 -0
- package/src/lib/toolRouterParams.ts +38 -14
- package/src/models/AuthConfigs.ts +10 -3
- package/src/models/ConnectedAccounts.ts +101 -28
- package/src/models/CustomTool.ts +0 -10
- package/src/models/Keyring.ts +2 -1
- package/src/models/MCP.ts +43 -35
- package/src/models/SessionWebhooks.ts +136 -0
- package/src/models/ToolRouter.ts +39 -4
- package/src/models/ToolRouterSession.ts +2 -2
- package/src/models/ToolRouterSessionFileMount.ts +3 -1
- package/src/models/Toolkits.ts +1 -0
- package/src/models/Tools.ts +4 -8
- package/src/models/Triggers.ts +48 -213
- package/src/models/Webhooks.ts +2 -0
- package/src/provider/ComposioProvider.ts +0 -1
- package/src/telemetry/BatchProcessor.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/connectedAccountAuthStates.types.ts +0 -1
- package/src/types/connectedAccounts.types.ts +59 -1
- package/src/types/provider.types.ts +0 -1
- package/src/types/sessionWebhooks.types.ts +292 -0
- package/src/types/toolRouter.types.ts +35 -5
- package/src/types/triggers.types.ts +4 -0
- package/src/utils/crypto.ts +6 -5
- package/src/utils/env.ts +2 -5
- package/src/utils/fileUtils.node.ts +5 -86
- package/src/utils/json-schema.ts +6 -0
- package/src/utils/jsonSchema.ts +17 -4
- package/src/utils/logger.ts +19 -9
- package/src/utils/mime.ts +25 -385
- package/src/utils/mimeTables.generated.ts +356 -0
- package/src/utils/pusher.ts +5 -2
- package/src/utils/readResponseBody.ts +30 -17
- package/src/utils/transformers/authConfigs.ts +0 -1
- package/src/utils/userCallback.ts +3 -1
- package/src/utils/webhookVerification.ts +211 -0
- package/dist/composio-Ba89XGHL.d.mts +0 -9736
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
|
|
3
|
+
export const SessionWebhookEventTypes = {
|
|
4
|
+
BEFORE_EXECUTE: 'composio.session_hook.before_execute',
|
|
5
|
+
AFTER_EXECUTE: 'composio.session_hook.after_execute',
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export type SessionWebhookEventType =
|
|
9
|
+
(typeof SessionWebhookEventTypes)[keyof typeof SessionWebhookEventTypes];
|
|
10
|
+
|
|
11
|
+
const SessionWebhookMetadataSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
/** ID of the project */
|
|
14
|
+
project_id: z.string(),
|
|
15
|
+
/** ID of the session the call was made in */
|
|
16
|
+
session_id: z.string(),
|
|
17
|
+
/** ID of the user the session belongs to */
|
|
18
|
+
user_id: z.string(),
|
|
19
|
+
/** ID of the hook that sent this event, as set on the session */
|
|
20
|
+
hook_id: z.string(),
|
|
21
|
+
/**
|
|
22
|
+
* ID of the call. The `before_execute` and `after_execute` events for one
|
|
23
|
+
* call carry the same ID. Omitted by an API version that predates it.
|
|
24
|
+
*/
|
|
25
|
+
tool_call_id: z.string().optional(),
|
|
26
|
+
})
|
|
27
|
+
.passthrough();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Where an event came from. `hook_id` is the hook's id on the session, and
|
|
31
|
+
* `tool_call_id` pairs a call's `before_execute` event with its `after_execute`.
|
|
32
|
+
*/
|
|
33
|
+
export type SessionWebhookMetadata = z.infer<typeof SessionWebhookMetadataSchema>;
|
|
34
|
+
|
|
35
|
+
const SessionWebhookToolCallSchema = z
|
|
36
|
+
.object({
|
|
37
|
+
/** Slug of the toolkit (for example `gmail`) */
|
|
38
|
+
toolkit_slug: z.string(),
|
|
39
|
+
/** Slug of the tool (for example `GMAIL_SEND_EMAIL`) */
|
|
40
|
+
tool_slug: z.string(),
|
|
41
|
+
/** Version of the toolkit the tool runs from */
|
|
42
|
+
toolkit_version: z.string(),
|
|
43
|
+
/** ID of the connected account the call uses. Omitted when the call doesn't use one. */
|
|
44
|
+
connected_account_id: z.string().optional(),
|
|
45
|
+
/** The arguments the tool is called with */
|
|
46
|
+
arguments: z.record(z.unknown()),
|
|
47
|
+
})
|
|
48
|
+
.passthrough();
|
|
49
|
+
|
|
50
|
+
/** A tool call. */
|
|
51
|
+
export type SessionWebhookToolCall = z.infer<typeof SessionWebhookToolCallSchema>;
|
|
52
|
+
|
|
53
|
+
const SessionWebhookToolResponseSchema = z
|
|
54
|
+
.object({
|
|
55
|
+
/** The data the tool returned */
|
|
56
|
+
data: z.record(z.unknown()),
|
|
57
|
+
/** Error message when the tool failed, otherwise null */
|
|
58
|
+
error: z.string().nullable(),
|
|
59
|
+
})
|
|
60
|
+
.passthrough();
|
|
61
|
+
|
|
62
|
+
/** What a tool call returned. */
|
|
63
|
+
export type SessionWebhookToolResponse = z.infer<typeof SessionWebhookToolResponseSchema>;
|
|
64
|
+
|
|
65
|
+
const SessionWebhookHttpMethodSchema = z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']);
|
|
66
|
+
|
|
67
|
+
const SessionWebhookHttpParameterSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
/** Header or query parameter name */
|
|
70
|
+
name: z.string(),
|
|
71
|
+
/** Header or query parameter value */
|
|
72
|
+
value: z.string(),
|
|
73
|
+
/** Whether the parameter is a header or a query parameter */
|
|
74
|
+
type: z.enum(['header', 'query']),
|
|
75
|
+
})
|
|
76
|
+
.passthrough();
|
|
77
|
+
|
|
78
|
+
const BinaryBodyUrlSchema = z.object({
|
|
79
|
+
url: z.string(),
|
|
80
|
+
content_type: z.string().optional(),
|
|
81
|
+
base64: z.never().optional(),
|
|
82
|
+
});
|
|
83
|
+
const BinaryBodyBase64Schema = z.object({
|
|
84
|
+
base64: z.string(),
|
|
85
|
+
content_type: z.string().optional(),
|
|
86
|
+
url: z.never().optional(),
|
|
87
|
+
});
|
|
88
|
+
const BinaryBodySchema = z.union([
|
|
89
|
+
BinaryBodyUrlSchema.passthrough(),
|
|
90
|
+
BinaryBodyBase64Schema.passthrough(),
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
const SessionWebhookHttpRequestSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
/** Slug of the toolkit whose API is called (for example `github`) */
|
|
96
|
+
toolkit_slug: z.string(),
|
|
97
|
+
/** ID of the connected account the call uses. Omitted when the call doesn't use one. */
|
|
98
|
+
connected_account_id: z.string().optional(),
|
|
99
|
+
method: SessionWebhookHttpMethodSchema,
|
|
100
|
+
/** The endpoint as the agent gave it: a path relative to the toolkit's API base URL, or a full URL */
|
|
101
|
+
endpoint: z.string(),
|
|
102
|
+
/** Headers and query parameters the agent added. The credentials Composio adds are not included. */
|
|
103
|
+
parameters: z.array(SessionWebhookHttpParameterSchema),
|
|
104
|
+
/** The request body. Omitted when there is none or the request uploads a file. */
|
|
105
|
+
body: z.unknown().optional(),
|
|
106
|
+
/** The file the request uploads, as a URL or base64-encoded bytes. */
|
|
107
|
+
binary_body: BinaryBodySchema.optional(),
|
|
108
|
+
})
|
|
109
|
+
.passthrough();
|
|
110
|
+
|
|
111
|
+
/** A proxy call: an HTTP request to a toolkit's API. */
|
|
112
|
+
export type SessionWebhookHttpRequest = z.infer<typeof SessionWebhookHttpRequestSchema>;
|
|
113
|
+
|
|
114
|
+
const SessionWebhookHttpResponseSchema = z
|
|
115
|
+
.object({
|
|
116
|
+
/** HTTP status the app's API returned */
|
|
117
|
+
status: z.number(),
|
|
118
|
+
/** Headers the app's API returned. Credential values Composio added are redacted. */
|
|
119
|
+
headers: z.record(z.string()),
|
|
120
|
+
/** Response body the app's API returned. Omitted when it is binary. */
|
|
121
|
+
data: z.unknown().optional(),
|
|
122
|
+
/** The file the API returned, as a temporary download link. Present when the response is binary. */
|
|
123
|
+
binary_data: z
|
|
124
|
+
.object({
|
|
125
|
+
url: z.string(),
|
|
126
|
+
content_type: z.string(),
|
|
127
|
+
size: z.number(),
|
|
128
|
+
expires_at: z.string().optional(),
|
|
129
|
+
})
|
|
130
|
+
.passthrough()
|
|
131
|
+
.optional(),
|
|
132
|
+
})
|
|
133
|
+
.passthrough();
|
|
134
|
+
|
|
135
|
+
/** What a proxy call returned. */
|
|
136
|
+
export type SessionWebhookHttpResponse = z.infer<typeof SessionWebhookHttpResponseSchema>;
|
|
137
|
+
|
|
138
|
+
const sessionWebhookEnvelopeFields = {
|
|
139
|
+
/** Unique event ID (`msg_<uuid>`). Also sent as the `webhook-id` header. */
|
|
140
|
+
id: z.string(),
|
|
141
|
+
/** ISO-8601 timestamp of when the event was created */
|
|
142
|
+
timestamp: z.string(),
|
|
143
|
+
metadata: SessionWebhookMetadataSchema,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Sent before a call runs. `data.type` says whether it is a tool call
|
|
148
|
+
* (`tool_call`) or a proxy call (`http_request`).
|
|
149
|
+
*/
|
|
150
|
+
const SessionWebhookBeforeExecuteEventSchema = z
|
|
151
|
+
.object({
|
|
152
|
+
...sessionWebhookEnvelopeFields,
|
|
153
|
+
type: z.literal(SessionWebhookEventTypes.BEFORE_EXECUTE),
|
|
154
|
+
data: z.discriminatedUnion('type', [
|
|
155
|
+
z
|
|
156
|
+
.object({ type: z.literal('tool_execute'), tool_call: SessionWebhookToolCallSchema })
|
|
157
|
+
.passthrough(),
|
|
158
|
+
z
|
|
159
|
+
.object({ type: z.literal('proxy_execute'), http_request: SessionWebhookHttpRequestSchema })
|
|
160
|
+
.passthrough(),
|
|
161
|
+
]),
|
|
162
|
+
})
|
|
163
|
+
.passthrough();
|
|
164
|
+
|
|
165
|
+
export type SessionWebhookBeforeExecuteEvent = z.infer<
|
|
166
|
+
typeof SessionWebhookBeforeExecuteEventSchema
|
|
167
|
+
>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Sent after a call ran, with what it returned: `tool_response` for a tool
|
|
171
|
+
* call, `http_response` for a proxy call.
|
|
172
|
+
*/
|
|
173
|
+
const SessionWebhookAfterExecuteEventSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
...sessionWebhookEnvelopeFields,
|
|
176
|
+
type: z.literal(SessionWebhookEventTypes.AFTER_EXECUTE),
|
|
177
|
+
data: z.discriminatedUnion('type', [
|
|
178
|
+
z
|
|
179
|
+
.object({
|
|
180
|
+
type: z.literal('tool_execute'),
|
|
181
|
+
tool_call: SessionWebhookToolCallSchema,
|
|
182
|
+
tool_response: SessionWebhookToolResponseSchema,
|
|
183
|
+
})
|
|
184
|
+
.passthrough(),
|
|
185
|
+
z
|
|
186
|
+
.object({
|
|
187
|
+
type: z.literal('proxy_execute'),
|
|
188
|
+
http_request: SessionWebhookHttpRequestSchema,
|
|
189
|
+
http_response: SessionWebhookHttpResponseSchema,
|
|
190
|
+
})
|
|
191
|
+
.passthrough(),
|
|
192
|
+
]),
|
|
193
|
+
})
|
|
194
|
+
.passthrough();
|
|
195
|
+
|
|
196
|
+
export type SessionWebhookAfterExecuteEvent = z.infer<typeof SessionWebhookAfterExecuteEventSchema>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* An event Composio sends to the session webhook URL, as returned by
|
|
200
|
+
* `composio.sessions.webhooks.parse()`.
|
|
201
|
+
*/
|
|
202
|
+
export const SessionWebhookEventSchema = z.discriminatedUnion('type', [
|
|
203
|
+
SessionWebhookBeforeExecuteEventSchema,
|
|
204
|
+
SessionWebhookAfterExecuteEventSchema,
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
export type SessionWebhookEvent = z.infer<typeof SessionWebhookEventSchema>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Parameters of `composio.sessions.webhooks.parse()`.
|
|
211
|
+
*/
|
|
212
|
+
export type ParseSessionWebhookParams = {
|
|
213
|
+
/** The raw, unparsed request body. The signature covers its exact bytes. */
|
|
214
|
+
body: string | Uint8Array;
|
|
215
|
+
/** The request headers. Names are matched case-insensitively. */
|
|
216
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
217
|
+
/**
|
|
218
|
+
* The project's session webhook secret, shown once in the dashboard when the
|
|
219
|
+
* session webhook URL is saved or its secret is rotated.
|
|
220
|
+
*/
|
|
221
|
+
verifySecret: string;
|
|
222
|
+
/**
|
|
223
|
+
* Maximum allowed age of the event in seconds (default: 300 = 5 minutes).
|
|
224
|
+
* Set to 0 to disable timestamp validation.
|
|
225
|
+
*/
|
|
226
|
+
tolerance?: number;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// Composio rejects an answer with a field it doesn't know, except on a block,
|
|
230
|
+
// and then applies the hook's `fallback_action`.
|
|
231
|
+
|
|
232
|
+
/** Stops the call. `message` is shown to the agent. */
|
|
233
|
+
export type SessionWebhookBlockResponse = {
|
|
234
|
+
action: 'block';
|
|
235
|
+
message: string;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Fields of a proxy request to replace. Fields left out keep their original
|
|
240
|
+
* value. Set at most one of `body` and `binary_body`. The toolkit cannot be changed.
|
|
241
|
+
*/
|
|
242
|
+
export type SessionWebhookHttpRequestOverride = {
|
|
243
|
+
method?: z.infer<typeof SessionWebhookHttpMethodSchema>;
|
|
244
|
+
endpoint?: string;
|
|
245
|
+
parameters?: Array<{ name: string; value: string; type: 'header' | 'query' }>;
|
|
246
|
+
} & (
|
|
247
|
+
| { body?: unknown; binary_body?: never }
|
|
248
|
+
| {
|
|
249
|
+
body?: never;
|
|
250
|
+
binary_body: z.infer<typeof BinaryBodyUrlSchema> | z.infer<typeof BinaryBodyBase64Schema>;
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Fields of a proxy response to replace. Fields left out keep their original
|
|
256
|
+
* value. The status and a binary file cannot be changed.
|
|
257
|
+
*/
|
|
258
|
+
export type SessionWebhookHttpResponseOverride = {
|
|
259
|
+
data?: unknown;
|
|
260
|
+
/** Replaces the API's headers in full */
|
|
261
|
+
headers?: Record<string, string>;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The answer to a `before_execute` event: let the call run, run it with
|
|
266
|
+
* changes, or block it. Use `tool_call` to change a tool call and
|
|
267
|
+
* `http_request` to change a proxy call, never both.
|
|
268
|
+
*/
|
|
269
|
+
export type SessionWebhookBeforeExecuteResponse =
|
|
270
|
+
| {
|
|
271
|
+
action: 'continue';
|
|
272
|
+
override?:
|
|
273
|
+
| { tool_call: { arguments: Record<string, unknown> }; http_request?: null }
|
|
274
|
+
| { http_request: SessionWebhookHttpRequestOverride; tool_call?: null }
|
|
275
|
+
| null;
|
|
276
|
+
}
|
|
277
|
+
| SessionWebhookBlockResponse;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The answer to an `after_execute` event: pass the result on to the agent,
|
|
281
|
+
* pass on a changed result, or block it. Use `tool_response` to change a tool
|
|
282
|
+
* call's result and `http_response` to change a proxy call's, never both.
|
|
283
|
+
*/
|
|
284
|
+
export type SessionWebhookAfterExecuteResponse =
|
|
285
|
+
| {
|
|
286
|
+
action: 'continue';
|
|
287
|
+
override?:
|
|
288
|
+
| { tool_response: { data: Record<string, unknown> }; http_response?: null }
|
|
289
|
+
| { http_response: SessionWebhookHttpResponseOverride; tool_response?: null }
|
|
290
|
+
| null;
|
|
291
|
+
}
|
|
292
|
+
| SessionWebhookBlockResponse;
|
|
@@ -364,6 +364,28 @@ export type ToolRouterHookPromptInjectionCheckHandler = z.infer<
|
|
|
364
364
|
typeof ToolRouterHookPromptInjectionCheckHandlerSchema
|
|
365
365
|
>;
|
|
366
366
|
|
|
367
|
+
/**
|
|
368
|
+
* Sends the call to the project's session webhook URL and waits for your
|
|
369
|
+
* endpoint's answer: let it run, block it, or change it. Read the request in
|
|
370
|
+
* your endpoint with `composio.sessions.webhooks.parse()`.
|
|
371
|
+
*/
|
|
372
|
+
export const ToolRouterHookWebhookHandlerSchema = z
|
|
373
|
+
.object({
|
|
374
|
+
type: z.literal('webhook'),
|
|
375
|
+
fallbackAction: z
|
|
376
|
+
.enum(['block', 'continue'])
|
|
377
|
+
.describe(
|
|
378
|
+
"What happens to the call when your endpoint times out, can't be reached, or sends an answer that can't be read."
|
|
379
|
+
),
|
|
380
|
+
timeoutMs: z
|
|
381
|
+
.number()
|
|
382
|
+
.int()
|
|
383
|
+
.optional()
|
|
384
|
+
.describe('How long to wait for your endpoint to answer, in milliseconds. Defaults to 3000.'),
|
|
385
|
+
})
|
|
386
|
+
.strict();
|
|
387
|
+
export type ToolRouterHookWebhookHandler = z.infer<typeof ToolRouterHookWebhookHandlerSchema>;
|
|
388
|
+
|
|
367
389
|
const toolRouterHookIdentityFields = {
|
|
368
390
|
id: z.string().describe('Unique within the session. Shows up in results and logs.'),
|
|
369
391
|
name: z
|
|
@@ -376,14 +398,18 @@ const toolRouterHookIdentityFields = {
|
|
|
376
398
|
/**
|
|
377
399
|
* A hook on a session's tool calls. A `before_execute` hook can block a call
|
|
378
400
|
* before it runs; an `after_execute` hook can block its result before the
|
|
379
|
-
* agent sees it.
|
|
401
|
+
* agent sees it. A hook with a `webhook` handler can also change the call or
|
|
402
|
+
* its result.
|
|
380
403
|
*/
|
|
381
404
|
export const ToolRouterHookSchema = z.discriminatedUnion('type', [
|
|
382
405
|
z
|
|
383
406
|
.object({
|
|
384
407
|
type: z.literal('before_execute'),
|
|
385
408
|
...toolRouterHookIdentityFields,
|
|
386
|
-
handler:
|
|
409
|
+
handler: z.discriminatedUnion('type', [
|
|
410
|
+
ToolRouterHookConditionCheckHandlerSchema,
|
|
411
|
+
ToolRouterHookWebhookHandlerSchema,
|
|
412
|
+
]),
|
|
387
413
|
})
|
|
388
414
|
.strict(),
|
|
389
415
|
z
|
|
@@ -393,6 +419,7 @@ export const ToolRouterHookSchema = z.discriminatedUnion('type', [
|
|
|
393
419
|
handler: z.discriminatedUnion('type', [
|
|
394
420
|
ToolRouterHookConditionCheckHandlerSchema,
|
|
395
421
|
ToolRouterHookPromptInjectionCheckHandlerSchema,
|
|
422
|
+
ToolRouterHookWebhookHandlerSchema,
|
|
396
423
|
]),
|
|
397
424
|
})
|
|
398
425
|
.strict(),
|
|
@@ -847,8 +874,9 @@ export type ToolRouterSessionSearchResponse = z.infer<typeof ToolRouterSessionSe
|
|
|
847
874
|
|
|
848
875
|
/**
|
|
849
876
|
* What one session hook decided about a call. `unavailable` means the hook
|
|
850
|
-
* could not be evaluated (for example it timed out)
|
|
851
|
-
* call
|
|
877
|
+
* could not be evaluated (for example it timed out), and `detail` says why
|
|
878
|
+
* when the API gives a reason. An unavailable hook does not block the call,
|
|
879
|
+
* unless it has a `webhook` handler with `fallbackAction: 'block'`.
|
|
852
880
|
*/
|
|
853
881
|
export const ToolRouterHookResultSchema = z.discriminatedUnion('status', [
|
|
854
882
|
z.object({
|
|
@@ -859,6 +887,7 @@ export const ToolRouterHookResultSchema = z.discriminatedUnion('status', [
|
|
|
859
887
|
z.object({
|
|
860
888
|
id: z.string().describe('The hook id'),
|
|
861
889
|
status: z.literal('unavailable'),
|
|
890
|
+
detail: z.string().optional().describe('Why the hook could not be evaluated'),
|
|
862
891
|
}),
|
|
863
892
|
]);
|
|
864
893
|
export type ToolRouterHookResult = z.infer<typeof ToolRouterHookResultSchema>;
|
|
@@ -1094,9 +1123,10 @@ export const ToolRouterUpdateManageConnectionsSchema = z
|
|
|
1094
1123
|
.object({
|
|
1095
1124
|
enable: z
|
|
1096
1125
|
.boolean()
|
|
1126
|
+
.nullable()
|
|
1097
1127
|
.optional()
|
|
1098
1128
|
.describe(
|
|
1099
|
-
'Whether to
|
|
1129
|
+
'Whether to expose connection management tools in the session. Pass null to restore the default (true).'
|
|
1100
1130
|
),
|
|
1101
1131
|
callbackUrl: z
|
|
1102
1132
|
.string()
|
|
@@ -362,6 +362,8 @@ export const VerifyWebhookParamsSchema = z.object({
|
|
|
362
362
|
* @default 300 (5 minutes)
|
|
363
363
|
*/
|
|
364
364
|
tolerance: z.number().optional().default(300),
|
|
365
|
+
/** Maximum UTF-8 size of the supplied payload in bytes. */
|
|
366
|
+
maxBodyBytes: z.number().int().nonnegative().safe().optional(),
|
|
365
367
|
});
|
|
366
368
|
|
|
367
369
|
export type VerifyWebhookParams = z.input<typeof VerifyWebhookParamsSchema>;
|
|
@@ -399,6 +401,8 @@ export type ParseWebhookOptions = {
|
|
|
399
401
|
* validation.
|
|
400
402
|
*/
|
|
401
403
|
tolerance?: number;
|
|
404
|
+
/** Maximum request body size in bytes. Defaults to 10 MiB. */
|
|
405
|
+
maxBodyBytes?: number;
|
|
402
406
|
};
|
|
403
407
|
|
|
404
408
|
/**
|
package/src/utils/crypto.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { arrayBufferToBase64 } from './buffer';
|
|
|
3
3
|
/**
|
|
4
4
|
* Computes HMAC-SHA256 using Web Crypto API
|
|
5
5
|
*/
|
|
6
|
-
export async function hmacSha256Base64(
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export async function hmacSha256Base64(
|
|
7
|
+
secret: string,
|
|
8
|
+
message: Uint8Array<ArrayBuffer>
|
|
9
|
+
): Promise<string> {
|
|
10
|
+
const keyData = new TextEncoder().encode(secret);
|
|
9
11
|
const key = await globalThis.crypto.subtle.importKey(
|
|
10
12
|
'raw',
|
|
11
13
|
keyData,
|
|
@@ -13,8 +15,7 @@ export async function hmacSha256Base64(secret: string, message: string): Promise
|
|
|
13
15
|
false,
|
|
14
16
|
['sign']
|
|
15
17
|
);
|
|
16
|
-
const
|
|
17
|
-
const signatureBuffer = await globalThis.crypto.subtle.sign('HMAC', key, signatureData);
|
|
18
|
+
const signatureBuffer = await globalThis.crypto.subtle.sign('HMAC', key, message);
|
|
18
19
|
|
|
19
20
|
return arrayBufferToBase64(signatureBuffer);
|
|
20
21
|
}
|
package/src/utils/env.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export const getEnvVariable = (
|
|
2
|
-
name: string,
|
|
3
|
-
defaultValue: string | undefined = undefined
|
|
4
|
-
): string | undefined => {
|
|
1
|
+
export const getEnvVariable = (name: string, defaultValue?: string): string | undefined => {
|
|
5
2
|
try {
|
|
6
3
|
return process.env[name] || defaultValue;
|
|
7
4
|
} catch (_e) {
|
|
@@ -28,7 +25,7 @@ export const getEnvsWithPrefix = (prefix: string): Record<string, unknown> => {
|
|
|
28
25
|
} else {
|
|
29
26
|
return {};
|
|
30
27
|
}
|
|
31
|
-
} catch
|
|
28
|
+
} catch {
|
|
32
29
|
return {};
|
|
33
30
|
}
|
|
34
31
|
};
|
|
@@ -4,6 +4,7 @@ import { platform } from '#platform';
|
|
|
4
4
|
import ComposioClient from '@composio/client';
|
|
5
5
|
import { COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME } from './constants';
|
|
6
6
|
import logger from './logger';
|
|
7
|
+
import { describeThrown } from './userCallback';
|
|
7
8
|
import { getRandomShortId } from './uuid';
|
|
8
9
|
import { base64ToUint8Array, uint8ArrayToBase64 } from './buffer';
|
|
9
10
|
import type { FileDownloadData, FileUploadData } from '../types/files.types';
|
|
@@ -11,7 +12,7 @@ import { assertSafeFileUploadPath } from './sensitiveFileUploadPaths';
|
|
|
11
12
|
import { assertPathInsideUploadDirs } from './uploadDirAllowlist.node';
|
|
12
13
|
import { ssrfSafeFetch } from './ssrfGuard.node';
|
|
13
14
|
import { readResponseBodyWithLimit } from './readResponseBody';
|
|
14
|
-
import { getMimeTypeFromFileName } from './mime';
|
|
15
|
+
import { getExtensionFromMimeType, getMimeTypeFromFileName } from './mime';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Options for {@link getFileDataAfterUploadingToS3} (S3 presigned upload from local path, URL, or File).
|
|
@@ -61,88 +62,6 @@ export const isHttpUrl = (value: string): boolean => {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
// Helper function to get file extension from MIME type
|
|
65
|
-
const getExtensionFromMimeType = (mimeType: string): string => {
|
|
66
|
-
const mimeToExt: Record<string, string> = {
|
|
67
|
-
'text/plain': 'txt',
|
|
68
|
-
'text/html': 'html',
|
|
69
|
-
'text/css': 'css',
|
|
70
|
-
'text/csv': 'csv',
|
|
71
|
-
'text/javascript': 'js',
|
|
72
|
-
'application/json': 'json',
|
|
73
|
-
'application/xml': 'xml',
|
|
74
|
-
'application/pdf': 'pdf',
|
|
75
|
-
'application/zip': 'zip',
|
|
76
|
-
'application/x-zip-compressed': 'zip',
|
|
77
|
-
'application/gzip': 'gz',
|
|
78
|
-
'application/x-tar': 'tar',
|
|
79
|
-
'application/msword': 'doc',
|
|
80
|
-
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
|
|
81
|
-
'application/vnd.ms-excel': 'xls',
|
|
82
|
-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
|
|
83
|
-
'application/vnd.ms-powerpoint': 'ppt',
|
|
84
|
-
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
|
|
85
|
-
'image/jpeg': 'jpg',
|
|
86
|
-
'image/jpg': 'jpg',
|
|
87
|
-
'image/png': 'png',
|
|
88
|
-
'image/gif': 'gif',
|
|
89
|
-
'image/svg+xml': 'svg',
|
|
90
|
-
'image/webp': 'webp',
|
|
91
|
-
'image/bmp': 'bmp',
|
|
92
|
-
'image/tiff': 'tiff',
|
|
93
|
-
'audio/mpeg': 'mp3',
|
|
94
|
-
'audio/wav': 'wav',
|
|
95
|
-
'audio/ogg': 'ogg',
|
|
96
|
-
'video/mp4': 'mp4',
|
|
97
|
-
'video/mpeg': 'mpeg',
|
|
98
|
-
'video/quicktime': 'mov',
|
|
99
|
-
'video/x-msvideo': 'avi',
|
|
100
|
-
'video/webm': 'webm',
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Clean the MIME type by removing parameters (e.g., "text/plain; charset=utf-8" -> "text/plain")
|
|
104
|
-
const cleanMimeType = mimeType.split(';')[0].toLowerCase().trim();
|
|
105
|
-
|
|
106
|
-
// Try exact match first
|
|
107
|
-
// An own property only: `constructor` or `__proto__` must not reach Object.prototype.
|
|
108
|
-
if (Object.hasOwn(mimeToExt, cleanMimeType)) {
|
|
109
|
-
return mimeToExt[cleanMimeType];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Try to extract from the MIME type (e.g., "image/png" -> "png")
|
|
113
|
-
const parts = cleanMimeType.split('/');
|
|
114
|
-
if (parts.length === 2) {
|
|
115
|
-
const subtype = parts[1].toLowerCase();
|
|
116
|
-
const cleanSubtype = subtype; // Already cleaned above
|
|
117
|
-
|
|
118
|
-
// Handle structured MIME types with + (e.g., "application/vnd.api+json" -> "json")
|
|
119
|
-
if (cleanSubtype.includes('+')) {
|
|
120
|
-
const plusParts = cleanSubtype.split('+');
|
|
121
|
-
const prefix = plusParts[0];
|
|
122
|
-
const suffix = plusParts[plusParts.length - 1]; // Get the part after the last +
|
|
123
|
-
|
|
124
|
-
// For specific formats, prefer the prefix (e.g., "atom+xml" -> "atom")
|
|
125
|
-
const knownPrefixes = ['svg', 'atom', 'rss'];
|
|
126
|
-
if (knownPrefixes.includes(prefix)) {
|
|
127
|
-
return prefix;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// For common structured suffixes, use the suffix (e.g., "vnd.api+json" -> "json")
|
|
131
|
-
const structuredSuffixes = ['json', 'xml', 'yaml', 'zip', 'gzip'];
|
|
132
|
-
if (structuredSuffixes.includes(suffix)) {
|
|
133
|
-
return suffix;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Default to the suffix for other structured types
|
|
137
|
-
return suffix;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return cleanSubtype || 'txt';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return 'txt'; // Default fallback
|
|
144
|
-
};
|
|
145
|
-
|
|
146
65
|
// Helper function to generate a filename with timestamp and random ID
|
|
147
66
|
const generateTimestampedFilename = (extension: string, prefix?: string): string => {
|
|
148
67
|
const basePrefix = prefix || 'file_ts';
|
|
@@ -166,7 +85,7 @@ const readFileContent = async (
|
|
|
166
85
|
mimeType: getMimeTypeFromFileName(filePath),
|
|
167
86
|
};
|
|
168
87
|
} catch (error) {
|
|
169
|
-
throw new Error(`Error reading file at ${filePath}: ${error}`);
|
|
88
|
+
throw new Error(`Error reading file at ${filePath}: ${describeThrown(error)}`);
|
|
170
89
|
}
|
|
171
90
|
};
|
|
172
91
|
|
|
@@ -472,7 +391,7 @@ export const saveFile = (
|
|
|
472
391
|
} catch (err) {
|
|
473
392
|
logger.warn(
|
|
474
393
|
`fileDownloadDir "${absDir}" is not writable, falling back to the default ` +
|
|
475
|
-
`(~/.composio/files). Error: ${err}`
|
|
394
|
+
`(~/.composio/files). Error: ${describeThrown(err)}`
|
|
476
395
|
);
|
|
477
396
|
composioFilesDir = getComposioTempFilesDir(true);
|
|
478
397
|
}
|
|
@@ -495,7 +414,7 @@ export const saveFile = (
|
|
|
495
414
|
|
|
496
415
|
return filePath;
|
|
497
416
|
} catch (_error) {
|
|
498
|
-
logger.debug(`Error saving file: ${_error}`);
|
|
417
|
+
logger.debug(`Error saving file: ${describeThrown(_error)}`);
|
|
499
418
|
return null;
|
|
500
419
|
}
|
|
501
420
|
};
|
package/src/utils/json-schema.ts
CHANGED
package/src/utils/jsonSchema.ts
CHANGED
|
@@ -6,6 +6,11 @@ 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 the nodes one `dereferenceJsonSchema` call visits. Inlining copies a
|
|
10
|
+
// target once per `$ref` to it, so `$defs` whose entries each reference the next
|
|
11
|
+
// one twice expand exponentially while staying under both depth caps. The
|
|
12
|
+
// largest recorded Composio schemas visit about 2,600 nodes.
|
|
13
|
+
const MAX_DEREFERENCED_NODES = 100_000;
|
|
9
14
|
// Bounds on one null-acceptance check; past either, null is not proven accepted.
|
|
10
15
|
const MAX_NULL_CHECK_DEPTH = 64;
|
|
11
16
|
const MAX_NULL_CHECK_NODES = 2_000;
|
|
@@ -66,9 +71,9 @@ const UNRESOLVED_REF_DESCRIPTION =
|
|
|
66
71
|
* API-provided tool definition that emits `$ref` without a `$defs`
|
|
67
72
|
* block — see https://github.com/ComposioHQ/composio/issues/3307).
|
|
68
73
|
*
|
|
69
|
-
* Safety caps (`MAX_REF_CHAIN_DEPTH`, `MAX_NODE_DEPTH
|
|
70
|
-
* modes; cycle handling (already
|
|
71
|
-
* unaffected.
|
|
74
|
+
* Safety caps (`MAX_REF_CHAIN_DEPTH`, `MAX_NODE_DEPTH`,
|
|
75
|
+
* `MAX_DEREFERENCED_NODES`) still throw in both modes; cycle handling (already
|
|
76
|
+
* permissive via `CYCLE_BREAK_SENTINEL`) is unaffected.
|
|
72
77
|
*/
|
|
73
78
|
export type UnresolvedRefStrategy = 'throw' | 'sentinel';
|
|
74
79
|
|
|
@@ -174,7 +179,8 @@ const throwResolutionError = (
|
|
|
174
179
|
* `$defs`; see https://github.com/ComposioHQ/composio/issues/3307).
|
|
175
180
|
*
|
|
176
181
|
* @throws {JsonSchemaRefResolutionError} on malformed pointers, missing
|
|
177
|
-
* targets (strict mode only), or chains past the depth cap
|
|
182
|
+
* targets (strict mode only), or chains past the depth cap or an expansion
|
|
183
|
+
* past the node cap (both modes).
|
|
178
184
|
*/
|
|
179
185
|
export function dereferenceJsonSchema<T = unknown>(
|
|
180
186
|
schema: T,
|
|
@@ -187,6 +193,7 @@ export function dereferenceJsonSchema<T = unknown>(
|
|
|
187
193
|
|
|
188
194
|
const root = schema as Record<string, unknown>;
|
|
189
195
|
const visiting = new WeakSet<object>();
|
|
196
|
+
let visited = 0;
|
|
190
197
|
|
|
191
198
|
// POLLUTING_KEYS filter prevents an attacker-shaped $defs entry from altering
|
|
192
199
|
// the cloned node's prototype.
|
|
@@ -215,6 +222,12 @@ export function dereferenceJsonSchema<T = unknown>(
|
|
|
215
222
|
{ possibleFixes: REF_RESOLUTION_FIXES }
|
|
216
223
|
);
|
|
217
224
|
}
|
|
225
|
+
if (++visited > MAX_DEREFERENCED_NODES) {
|
|
226
|
+
throw new JsonSchemaRefResolutionError(
|
|
227
|
+
`JSON Schema $ref expansion exceeded node cap (${MAX_DEREFERENCED_NODES})`,
|
|
228
|
+
{ possibleFixes: REF_RESOLUTION_FIXES }
|
|
229
|
+
);
|
|
230
|
+
}
|
|
218
231
|
if (Array.isArray(node)) {
|
|
219
232
|
if (visiting.has(node)) return { ...CYCLE_BREAK_SENTINEL };
|
|
220
233
|
visiting.add(node);
|
package/src/utils/logger.ts
CHANGED
|
@@ -76,16 +76,9 @@ export class Logger {
|
|
|
76
76
|
.map((arg, index) => {
|
|
77
77
|
if (typeof arg === 'object') {
|
|
78
78
|
return JSON.stringify(arg);
|
|
79
|
-
} else {
|
|
80
|
-
if (index === 0) {
|
|
81
|
-
if (args.length > 1) {
|
|
82
|
-
return pc.yellow(`${arg}`);
|
|
83
|
-
} else {
|
|
84
|
-
return String(arg);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return String(arg);
|
|
88
79
|
}
|
|
80
|
+
const text = formatLogValue(arg);
|
|
81
|
+
return index === 0 && args.length > 1 ? pc.yellow(text) : text;
|
|
89
82
|
})
|
|
90
83
|
.join('\n');
|
|
91
84
|
|
|
@@ -126,6 +119,23 @@ export class Logger {
|
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
121
|
|
|
122
|
+
function formatLogValue(value: unknown): string {
|
|
123
|
+
switch (typeof value) {
|
|
124
|
+
case 'string':
|
|
125
|
+
return value;
|
|
126
|
+
case 'function':
|
|
127
|
+
return value.toString();
|
|
128
|
+
case 'number':
|
|
129
|
+
case 'boolean':
|
|
130
|
+
case 'bigint':
|
|
131
|
+
case 'symbol':
|
|
132
|
+
case 'undefined':
|
|
133
|
+
return String(value);
|
|
134
|
+
default:
|
|
135
|
+
return Object.prototype.toString.call(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
129
139
|
// Create and export a default logger instance
|
|
130
140
|
const logger = new Logger();
|
|
131
141
|
export default logger;
|