@composio/core 0.25.0 → 0.27.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-DZY1yLHN.d.mts → CustomTool-CqPoLUD6.d.mts} +1 -1
- package/dist/{cancellation-D-tMPk48.mjs → cancellation-ZoRh6EJQ.mjs} +54 -2
- package/dist/{composio-B8AENilE.d.mts → composio-BUa10iB3.d.mts} +65 -57
- package/dist/{customTool.types-Bi6-keZC.d.mts → customTool.types-gX421uPT.d.mts} +789 -33
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +3 -3
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -1
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +5 -1
- package/dist/experimental/index.d.mts +2 -2
- package/dist/index.d.mts +18 -13
- package/dist/index.mjs +6787 -6316
- package/dist/{types-BGDMkEUl.d.mts → types-DXxfzBX3.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 +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +3 -3
- package/src/composio.ts +68 -57
- package/src/lib/toolRouterMcp.ts +2 -0
- package/src/lib/toolRouterParams.ts +26 -3
- package/src/models/ConnectedAccounts.ts +7 -16
- package/src/models/SessionContext.ts +2 -17
- package/src/models/ToolRouter.ts +9 -2
- package/src/models/ToolRouterSession.ts +4 -19
- package/src/models/Tools.ts +1 -4
- package/src/models/Triggers.ts +6 -1
- package/src/services/internal/InternalService.ts +3 -4
- package/src/services/pusher/Pusher.ts +11 -4
- package/src/types/connectedAccountAuthStates.types.ts +2 -1
- package/src/types/requestOptions.types.ts +1 -10
- package/src/types/toolRouter.types.ts +156 -11
- package/src/utils/jsonSchema.ts +76 -4
- package/src/utils/sdk.ts +172 -11
- package/src/utils/toolkitDeprecation.ts +271 -0
- package/src/utils/transformers/connectedAccounts.ts +9 -20
- package/src/utils/transformers/mcp.ts +3 -10
- package/src/utils/transformers/toolRouterResponseTransform.ts +123 -5
|
@@ -8,10 +8,53 @@ import type {
|
|
|
8
8
|
import z from 'zod/v3';
|
|
9
9
|
import { ComposioToolInputRequiredError } from '../../errors/ToolRouterErrors';
|
|
10
10
|
import { ValidationError } from '../../errors/ValidationErrors';
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
ToolRouterHookResultSchema,
|
|
13
|
+
type ToolRouterSessionExecuteResponse,
|
|
14
|
+
type ToolRouterSessionProxyExecuteResponse,
|
|
15
|
+
} from '../../types/toolRouter.types';
|
|
12
16
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The `result_type` values of a call that ran. `input_required` and `blocked`
|
|
19
|
+
* are handled before this is read. `hook_results` is validated in its own step
|
|
20
|
+
* so a shape drift there doesn't read as an unknown `result_type`.
|
|
21
|
+
*/
|
|
22
|
+
const ExecutedResponseSchema = z.object({
|
|
23
|
+
result_type: z.enum(['completed', 'failed']),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** A call a session hook blocked. The generated client does not type it yet. */
|
|
27
|
+
const BlockedResponseSchema = z.object({
|
|
28
|
+
result_type: z.literal('blocked'),
|
|
29
|
+
reason: z.object({
|
|
30
|
+
type: z.enum(['request_blocked', 'response_blocked']),
|
|
31
|
+
hook_id: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
message: z.string(),
|
|
34
|
+
// Only session execute carries these; session proxy execute leaves them out.
|
|
35
|
+
log_id: z.string().optional(),
|
|
36
|
+
instant_charge: z.unknown().optional(),
|
|
37
|
+
hook_results: z.array(ToolRouterHookResultSchema).optional(),
|
|
38
|
+
});
|
|
39
|
+
type BlockedResponse = z.infer<typeof BlockedResponseSchema>;
|
|
40
|
+
|
|
41
|
+
const IsBlockedSchema = z.object({ result_type: z.literal('blocked') });
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Reads a `blocked` response, or returns `undefined` for any other
|
|
45
|
+
* `result_type`. A `blocked` response that does not match its schema is
|
|
46
|
+
* raised rather than read as a result.
|
|
47
|
+
*/
|
|
48
|
+
function parseBlockedResponse(raw: unknown, subject: string): BlockedResponse | undefined {
|
|
49
|
+
if (!IsBlockedSchema.safeParse(raw).success) return undefined;
|
|
50
|
+
const blocked = BlockedResponseSchema.safeParse(raw);
|
|
51
|
+
if (!blocked.success) {
|
|
52
|
+
throw new ValidationError(`${subject} returned a malformed blocked response`, {
|
|
53
|
+
cause: blocked.error,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return blocked.data;
|
|
57
|
+
}
|
|
15
58
|
|
|
16
59
|
/**
|
|
17
60
|
* Whether a session tool execution succeeded. `resultType` decides: a `failed`
|
|
@@ -208,10 +251,27 @@ export function transformSearchResponse(raw: RawSearchResponse) {
|
|
|
208
251
|
* Transforms a raw session execute API response to camelCase.
|
|
209
252
|
*
|
|
210
253
|
* @throws {ComposioToolInputRequiredError} If the tool asked for user input instead of running
|
|
211
|
-
* @throws {ValidationError} If the response carries no `result_type`,
|
|
254
|
+
* @throws {ValidationError} If the response carries no `result_type`, one this SDK does not know, or malformed `hook_results`
|
|
212
255
|
*/
|
|
213
|
-
export function transformExecuteResponse(
|
|
256
|
+
export function transformExecuteResponse(
|
|
257
|
+
raw: SessionExecuteResponse,
|
|
258
|
+
toolSlug: string
|
|
259
|
+
): ToolRouterSessionExecuteResponse {
|
|
214
260
|
assertNotInputRequired(raw, `Tool ${toolSlug}`);
|
|
261
|
+
const blocked = parseBlockedResponse(raw, `Tool ${toolSlug}`);
|
|
262
|
+
if (blocked) {
|
|
263
|
+
// The agent reads `error`, so a blocked call reaches it as a failed call
|
|
264
|
+
// with the hook's message.
|
|
265
|
+
return {
|
|
266
|
+
data: {},
|
|
267
|
+
error: blocked.message,
|
|
268
|
+
logId: blocked.log_id ?? '',
|
|
269
|
+
resultType: 'blocked',
|
|
270
|
+
blockReason: { type: blocked.reason.type, hookId: blocked.reason.hook_id },
|
|
271
|
+
...(blocked.hook_results !== undefined && { hookResults: blocked.hook_results }),
|
|
272
|
+
...(blocked.instant_charge !== undefined && { instantCharge: blocked.instant_charge }),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
215
275
|
const executed = ExecutedResponseSchema.safeParse(raw);
|
|
216
276
|
if (!executed.success) {
|
|
217
277
|
throw new ValidationError(
|
|
@@ -219,11 +279,69 @@ export function transformExecuteResponse(raw: SessionExecuteResponse, toolSlug:
|
|
|
219
279
|
{ cause: executed.error }
|
|
220
280
|
);
|
|
221
281
|
}
|
|
282
|
+
const hookResults = CompletedHookResultsSchema.safeParse(raw);
|
|
283
|
+
if (!hookResults.success) {
|
|
284
|
+
throw new ValidationError(`Tool ${toolSlug} returned malformed hook results`, {
|
|
285
|
+
cause: hookResults.error,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
222
288
|
return {
|
|
223
289
|
data: raw.data,
|
|
224
290
|
error: raw.error,
|
|
225
291
|
logId: raw.log_id,
|
|
226
292
|
resultType: executed.data.result_type,
|
|
227
293
|
...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
|
|
294
|
+
...(hookResults.data.hook_results !== undefined && {
|
|
295
|
+
hookResults: hookResults.data.hook_results,
|
|
296
|
+
}),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Hook results on a call that ran: session execute, or a proxied request that was sent. */
|
|
301
|
+
const CompletedHookResultsSchema = z.object({
|
|
302
|
+
hook_results: z.array(ToolRouterHookResultSchema).optional(),
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Projects a session proxy execute response onto the SDK's shape: a request a
|
|
307
|
+
* session hook blocked comes back as `resultType: 'blocked'` with no HTTP
|
|
308
|
+
* response.
|
|
309
|
+
*/
|
|
310
|
+
export function transformProxyExecuteResponse(
|
|
311
|
+
raw: SessionProxyExecuteResponse,
|
|
312
|
+
subject: string
|
|
313
|
+
): ToolRouterSessionProxyExecuteResponse {
|
|
314
|
+
assertNotInputRequired(raw, subject);
|
|
315
|
+
const blocked = parseBlockedResponse(raw, subject);
|
|
316
|
+
if (blocked) {
|
|
317
|
+
return {
|
|
318
|
+
resultType: 'blocked',
|
|
319
|
+
blockReason: { type: blocked.reason.type, hookId: blocked.reason.hook_id },
|
|
320
|
+
message: blocked.message,
|
|
321
|
+
...(blocked.hook_results !== undefined && { hookResults: blocked.hook_results }),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const hookResults = CompletedHookResultsSchema.safeParse(raw);
|
|
325
|
+
if (!hookResults.success) {
|
|
326
|
+
throw new ValidationError(`${subject} returned malformed hook results`, {
|
|
327
|
+
cause: hookResults.error,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
resultType: 'completed',
|
|
332
|
+
status: raw.status,
|
|
333
|
+
data: raw.data,
|
|
334
|
+
headers: raw.headers,
|
|
335
|
+
...(raw.binary_data && {
|
|
336
|
+
binaryData: {
|
|
337
|
+
contentType: raw.binary_data.content_type,
|
|
338
|
+
size: raw.binary_data.size,
|
|
339
|
+
url: raw.binary_data.url,
|
|
340
|
+
expiresAt: raw.binary_data.expires_at,
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
...(hookResults.data.hook_results !== undefined && {
|
|
344
|
+
hookResults: hookResults.data.hook_results,
|
|
345
|
+
}),
|
|
228
346
|
};
|
|
229
347
|
}
|