@composio/core 0.23.0 → 0.25.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-CnJxXr07.mjs → CustomTool-BYHB7sPs.mjs} +1 -1
- package/dist/{CustomTool-CnHdegDK.d.mts → CustomTool-DZY1yLHN.d.mts} +1 -1
- package/dist/{cancellation-BQibgpRG.mjs → cancellation-D-tMPk48.mjs} +1 -1
- package/dist/{composio-Dq708dZS.d.mts → composio-B8AENilE.d.mts} +74 -62
- package/dist/{customTool.types-B8lVpHOP.d.mts → customTool.types-Bi6-keZC.d.mts} +612 -141
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +22 -22
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -8
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -5
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -5
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +56 -21
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +22 -22
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -6
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +14 -14
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -13
- package/dist/{errors-BN15NcCW.mjs → errors-Cly0vXFh.mjs} +5 -5
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +31 -7
- package/dist/index.mjs +382 -147
- package/dist/{types-eTw8Yw7Y.d.mts → types-BGDMkEUl.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 +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +8 -8
- package/src/composio.ts +19 -16
- package/src/errors/ToolRouterErrors.ts +5 -5
- package/src/lib/toolRouterParams.ts +44 -16
- package/src/models/MCP.ts +20 -1
- package/src/models/ToolRouter.ts +9 -0
- package/src/models/ToolRouterSession.ts +68 -0
- package/src/models/Triggers.ts +8 -6
- package/src/services/pusher/Pusher.ts +159 -88
- package/src/types/pusher.types.ts +2 -0
- package/src/types/toolRouter.types.ts +190 -19
- package/src/utils/session.ts +25 -47
- package/src/utils/transformers/toolRouterResponseTransform.ts +8 -2
- package/src/utils/userCallback.ts +41 -0
|
@@ -8,6 +8,8 @@ import { ConnectedAccountExperimentalSchema } from './connectedAccounts.types';
|
|
|
8
8
|
import type {
|
|
9
9
|
SessionConfigHistoryResponse,
|
|
10
10
|
SessionCreateResponse,
|
|
11
|
+
SessionExecuteMetaParams,
|
|
12
|
+
SessionExecuteParams,
|
|
11
13
|
} from '@composio/client/resources/tool-router/session/session.mjs';
|
|
12
14
|
import type {
|
|
13
15
|
CustomTool,
|
|
@@ -108,6 +110,39 @@ export const ToolRouterToolkitsEnabledConfigSchema = z
|
|
|
108
110
|
})
|
|
109
111
|
.strict();
|
|
110
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Toolkits whose tools need the user's approval before they run. A call that
|
|
115
|
+
* needs approval doesn't run: `session.execute()` throws
|
|
116
|
+
* `ComposioToolInputRequiredError` with the question to show the user.
|
|
117
|
+
* @experimental
|
|
118
|
+
*/
|
|
119
|
+
const ToolRouterToolkitsRequireApprovalSchema = ToolRouterToolkitsParamSchema.describe(
|
|
120
|
+
'Experimental. Toolkits whose tools need the user approval before they run'
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
/** Session toolkit policy: a list to enable, an enable/disable object, or only an approval list. */
|
|
124
|
+
const ToolRouterSessionToolkitsSchema = z.union([
|
|
125
|
+
ToolRouterToolkitsParamSchema,
|
|
126
|
+
ToolRouterToolkitsDisabledConfigSchema.extend({
|
|
127
|
+
requireApproval: ToolRouterToolkitsRequireApprovalSchema.optional(),
|
|
128
|
+
}).strict(),
|
|
129
|
+
ToolRouterToolkitsEnabledConfigSchema.extend({
|
|
130
|
+
requireApproval: ToolRouterToolkitsRequireApprovalSchema.optional(),
|
|
131
|
+
}).strict(),
|
|
132
|
+
z.object({ requireApproval: ToolRouterToolkitsRequireApprovalSchema }).strict(),
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* What happens to a call that needs the user's approval when the session's MCP
|
|
137
|
+
* client can't ask the user.
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
140
|
+
const ToolRouterNoElicitationSupportFallbackSchema = z
|
|
141
|
+
.enum(['deny', 'allow'])
|
|
142
|
+
.describe(
|
|
143
|
+
'Experimental. What happens to a call that needs approval when the MCP client cannot ask the user'
|
|
144
|
+
);
|
|
145
|
+
|
|
111
146
|
/** Experimental Instant usage policy for a Session. */
|
|
112
147
|
export const ToolRouterInstantSchema = z.union([
|
|
113
148
|
z.literal(false),
|
|
@@ -131,6 +166,12 @@ export const ToolRouterInstantSchema = z.union([
|
|
|
131
166
|
* usage on a Session set to `false`.
|
|
132
167
|
*/
|
|
133
168
|
returnInstantCharge: z.boolean().optional(),
|
|
169
|
+
/**
|
|
170
|
+
* Experimental. Show each Instant tool's price in Session search
|
|
171
|
+
* results, under `toolkitConnectionStatuses[].instantAccount.prices`.
|
|
172
|
+
* Controls visibility only.
|
|
173
|
+
*/
|
|
174
|
+
returnPricesInSearch: z.boolean().optional(),
|
|
134
175
|
})
|
|
135
176
|
.strict(),
|
|
136
177
|
]);
|
|
@@ -149,7 +190,16 @@ export const ToolRouterManageConnectionsConfigSchema = z.object({
|
|
|
149
190
|
|
|
150
191
|
// Tags
|
|
151
192
|
export const ToolRouterTagsParamSchema = z
|
|
152
|
-
.array(
|
|
193
|
+
.array(
|
|
194
|
+
z.enum([
|
|
195
|
+
'readOnlyHint',
|
|
196
|
+
'createHint',
|
|
197
|
+
'updateHint',
|
|
198
|
+
'destructiveHint',
|
|
199
|
+
'idempotentHint',
|
|
200
|
+
'openWorldHint',
|
|
201
|
+
])
|
|
202
|
+
)
|
|
153
203
|
.describe('The tags to filter the tools by');
|
|
154
204
|
export const ToolRouterTagsEnableDisableSchema = z
|
|
155
205
|
.object({
|
|
@@ -159,6 +209,13 @@ export const ToolRouterTagsEnableDisableSchema = z
|
|
|
159
209
|
disable: ToolRouterTagsParamSchema.optional().describe(
|
|
160
210
|
'The tags to disable in the tool router session'
|
|
161
211
|
),
|
|
212
|
+
/**
|
|
213
|
+
* Tools with any of these tags need the user's approval before they run.
|
|
214
|
+
* @experimental
|
|
215
|
+
*/
|
|
216
|
+
requireApproval: ToolRouterTagsParamSchema.optional().describe(
|
|
217
|
+
'Experimental. Tools with any of these tags need the user approval before they run'
|
|
218
|
+
),
|
|
162
219
|
})
|
|
163
220
|
.strict();
|
|
164
221
|
export const ToolRouterConfigTagsSchema = z
|
|
@@ -193,6 +250,14 @@ export const ToolRouterToolsParamSchema = z
|
|
|
193
250
|
.describe('The tools to use in the tool router session');
|
|
194
251
|
export type ToolRouterToolsParam = z.infer<typeof ToolRouterToolsParamSchema>;
|
|
195
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Tools of the toolkit that need the user's approval before they run.
|
|
255
|
+
* @experimental
|
|
256
|
+
*/
|
|
257
|
+
const ToolRouterToolsRequireApprovalSchema = ToolRouterToolsParamSchema.describe(
|
|
258
|
+
'Experimental. Tools of this toolkit that need the user approval before they run'
|
|
259
|
+
);
|
|
260
|
+
|
|
196
261
|
export const ToolRouterConfigToolsSchema = z
|
|
197
262
|
.union([
|
|
198
263
|
ToolRouterToolsParamSchema,
|
|
@@ -201,6 +266,7 @@ export const ToolRouterConfigToolsSchema = z
|
|
|
201
266
|
enable: ToolRouterToolsParamSchema.describe(
|
|
202
267
|
'The tools to enable in the tool router session'
|
|
203
268
|
),
|
|
269
|
+
requireApproval: ToolRouterToolsRequireApprovalSchema.optional(),
|
|
204
270
|
})
|
|
205
271
|
.strict(),
|
|
206
272
|
z
|
|
@@ -208,6 +274,7 @@ export const ToolRouterConfigToolsSchema = z
|
|
|
208
274
|
disable: ToolRouterToolsParamSchema.describe(
|
|
209
275
|
'The tools to disable in the tool router session'
|
|
210
276
|
),
|
|
277
|
+
requireApproval: ToolRouterToolsRequireApprovalSchema.optional(),
|
|
211
278
|
})
|
|
212
279
|
.strict(),
|
|
213
280
|
z
|
|
@@ -215,13 +282,15 @@ export const ToolRouterConfigToolsSchema = z
|
|
|
215
282
|
tags: ToolRouterConfigTagsSchema.describe(
|
|
216
283
|
'The tags to filter the tools by, this will override the global tags'
|
|
217
284
|
),
|
|
285
|
+
requireApproval: ToolRouterToolsRequireApprovalSchema.optional(),
|
|
218
286
|
})
|
|
219
287
|
.strict(),
|
|
288
|
+
z.object({ requireApproval: ToolRouterToolsRequireApprovalSchema }).strict(),
|
|
220
289
|
])
|
|
221
290
|
.superRefine((val, ctx) => {
|
|
222
|
-
// If it's an object (not an array),
|
|
291
|
+
// If it's an object (not an array), allow at most one of enable, disable and tags
|
|
223
292
|
if (typeof val === 'object' && !Array.isArray(val)) {
|
|
224
|
-
const keys = Object.keys(val);
|
|
293
|
+
const keys = Object.keys(val).filter(key => key !== 'requireApproval');
|
|
225
294
|
if (keys.length > 1) {
|
|
226
295
|
ctx.addIssue({
|
|
227
296
|
code: z.ZodIssueCode.custom,
|
|
@@ -233,6 +302,33 @@ export const ToolRouterConfigToolsSchema = z
|
|
|
233
302
|
});
|
|
234
303
|
export type ToolRouterConfigTools = z.infer<typeof ToolRouterConfigToolsSchema>;
|
|
235
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Proxy execute settings for a session. `enable: true` exposes the
|
|
307
|
+
* `COMPOSIO_PROXY_EXECUTE` meta tool and `enable: false` also turns off the
|
|
308
|
+
* sandbox `proxy_execute()` helper. Leaving the block out keeps the meta tool
|
|
309
|
+
* off while `sandbox.enableProxyExecution` controls the helper.
|
|
310
|
+
*/
|
|
311
|
+
export const ToolRouterProxyExecuteConfigSchema = z
|
|
312
|
+
.object({
|
|
313
|
+
enable: z
|
|
314
|
+
.boolean()
|
|
315
|
+
.describe(
|
|
316
|
+
'true exposes the COMPOSIO_PROXY_EXECUTE meta tool. false also turns off the sandbox proxy_execute() helper.'
|
|
317
|
+
),
|
|
318
|
+
})
|
|
319
|
+
.strict();
|
|
320
|
+
export type ToolRouterProxyExecuteConfig = z.infer<typeof ToolRouterProxyExecuteConfigSchema>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* `proxyExecute` as accepted by `sessions.create()` and `session.update()`:
|
|
324
|
+
* a boolean is shorthand for `{ enable: boolean }`.
|
|
325
|
+
*/
|
|
326
|
+
export const ToolRouterProxyExecuteSchema = z.union([
|
|
327
|
+
z.boolean(),
|
|
328
|
+
ToolRouterProxyExecuteConfigSchema,
|
|
329
|
+
]);
|
|
330
|
+
export type ToolRouterProxyExecute = z.infer<typeof ToolRouterProxyExecuteSchema>;
|
|
331
|
+
|
|
236
332
|
const ToolRouterCreateSessionConfigBaseSchema = z
|
|
237
333
|
.object({
|
|
238
334
|
sessionPreset: z
|
|
@@ -256,14 +352,9 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
256
352
|
|
|
257
353
|
tags: ToolRouterConfigTagsSchema.optional().describe('Global tags to filter the tools by'),
|
|
258
354
|
|
|
259
|
-
toolkits:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
ToolRouterToolkitsDisabledConfigSchema,
|
|
263
|
-
ToolRouterToolkitsEnabledConfigSchema,
|
|
264
|
-
])
|
|
265
|
-
.optional()
|
|
266
|
-
.describe('The toolkits to use in the tool router session'),
|
|
355
|
+
toolkits: ToolRouterSessionToolkitsSchema.optional().describe(
|
|
356
|
+
'The toolkits to use in the tool router session'
|
|
357
|
+
),
|
|
267
358
|
|
|
268
359
|
instant: ToolRouterInstantSchema.optional().describe(
|
|
269
360
|
'Experimental Instant usage policy. Omission permits eligible tools when the project allows Instant usage; false disables it for this Session.'
|
|
@@ -319,6 +410,10 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
319
410
|
.optional()
|
|
320
411
|
.describe('Multi-account configuration for this session'),
|
|
321
412
|
|
|
413
|
+
proxyExecute: ToolRouterProxyExecuteSchema.optional().describe(
|
|
414
|
+
'Proxy execute configuration for this session; a boolean is shorthand for `{ enable }`. Rejected by the API when enable is false and sandbox.enableProxyExecution is true.'
|
|
415
|
+
),
|
|
416
|
+
|
|
322
417
|
preload: z
|
|
323
418
|
.object({
|
|
324
419
|
tools: z
|
|
@@ -364,6 +459,13 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
364
459
|
.describe(
|
|
365
460
|
'ID of a saved Session config (`sc_…`) to apply when the session is created. Cannot be combined with toolkits, tools, tags, customTools or customToolkits.'
|
|
366
461
|
),
|
|
462
|
+
/**
|
|
463
|
+
* What happens to a call that needs the user's approval when the
|
|
464
|
+
* session's MCP client can't ask the user: `deny` (the default) or
|
|
465
|
+
* `allow`.
|
|
466
|
+
* @experimental
|
|
467
|
+
*/
|
|
468
|
+
noElicitationSupportFallback: ToolRouterNoElicitationSupportFallbackSchema.optional(),
|
|
367
469
|
})
|
|
368
470
|
.optional()
|
|
369
471
|
.describe('Experimental features configuration - not stable, may be modified or removed'),
|
|
@@ -440,6 +542,8 @@ export const ToolRouterCreateSessionConfigSchema = z
|
|
|
440
542
|
* @param {boolean} [multiAccount.enable] - When true, enables multi-account mode. Falls back to org/project-level config when not set.
|
|
441
543
|
* @param {number} [multiAccount.maxAccountsPerToolkit] - Max connected accounts per toolkit (2-10, default 5)
|
|
442
544
|
* @param {boolean} [multiAccount.requireExplicitSelection] - When true, require explicit account selection when multiple accounts are connected
|
|
545
|
+
* @param {boolean | object} [proxyExecute] - Proxy execute configuration for this session. A boolean is shorthand for `{ enable }`.
|
|
546
|
+
* @param {boolean} proxyExecute.enable - `true` exposes the `COMPOSIO_PROXY_EXECUTE` meta tool. `false` also turns off the sandbox `proxy_execute()` helper.
|
|
443
547
|
* @param {object} [preload] - Tools to preload into session.tools() and the MCP tool list
|
|
444
548
|
* @param {string[] | 'all'} [preload.tools] - Tool slugs to preload, or "all" to preload every app tool allowed by the session filters. "all" requires a positive filter such as toolkits, tools, or tags; the backend validates and caps the final tool set.
|
|
445
549
|
* @param {object} [experimental] - Experimental features configuration. Not stable; may change or be removed.
|
|
@@ -609,7 +713,24 @@ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
|
|
|
609
713
|
connectionDetails: z.record(z.string(), z.unknown()).optional(),
|
|
610
714
|
currentUserInfo: z.record(z.string(), z.unknown()).optional(),
|
|
611
715
|
/** Present when the toolkit runs on a Composio Instant account; only these tools run on it. */
|
|
612
|
-
instantAccount: z
|
|
716
|
+
instantAccount: z
|
|
717
|
+
.object({
|
|
718
|
+
allowedToolSlugs: z.array(z.string()),
|
|
719
|
+
/**
|
|
720
|
+
* Price of each tool, keyed by tool slug. Present only when the Session
|
|
721
|
+
* sets `instant.returnPricesInSearch`.
|
|
722
|
+
*/
|
|
723
|
+
prices: z
|
|
724
|
+
.record(
|
|
725
|
+
z.string(),
|
|
726
|
+
z.object({
|
|
727
|
+
description: z.string().optional(),
|
|
728
|
+
discount: z.string().nullable().optional(),
|
|
729
|
+
})
|
|
730
|
+
)
|
|
731
|
+
.optional(),
|
|
732
|
+
})
|
|
733
|
+
.optional(),
|
|
613
734
|
});
|
|
614
735
|
|
|
615
736
|
export const ToolRouterSessionSearchResponseSchema = z.object({
|
|
@@ -707,8 +828,51 @@ export interface ToolRouterSessionExecuteOptions {
|
|
|
707
828
|
* COMPOSIO_MULTI_EXECUTE_TOOL.tools[].account.
|
|
708
829
|
*/
|
|
709
830
|
account?: string;
|
|
831
|
+
/**
|
|
832
|
+
* The user's answers to the questions of a `ComposioToolInputRequiredError`,
|
|
833
|
+
* keyed by the IDs in its `inputRequests`. Send them by repeating the same
|
|
834
|
+
* call (same tool and arguments). An approved call runs; a denied or
|
|
835
|
+
* declined one returns `resultType: 'failed'`.
|
|
836
|
+
* @experimental
|
|
837
|
+
*/
|
|
838
|
+
inputResponses?: Record<string, ToolRouterInputResponse>;
|
|
839
|
+
/**
|
|
840
|
+
* The `requestState` of the `ComposioToolInputRequiredError`, sent back
|
|
841
|
+
* unchanged with `inputResponses`.
|
|
842
|
+
* @experimental
|
|
843
|
+
*/
|
|
844
|
+
requestState?: string;
|
|
710
845
|
}
|
|
711
846
|
|
|
847
|
+
/**
|
|
848
|
+
* The user's answer to one question, in the shape of an MCP elicitation
|
|
849
|
+
* result: `accept` with the form's fields in `content`, `decline` when they
|
|
850
|
+
* said no, or `cancel` when they dismissed it. For an approval, `content` is
|
|
851
|
+
* `{ decision: 'approve' }`, `{ decision: 'always_approve' }` or
|
|
852
|
+
* `{ decision: 'deny' }`.
|
|
853
|
+
* @experimental
|
|
854
|
+
*/
|
|
855
|
+
export type ToolRouterInputResponse = NonNullable<SessionExecuteParams['input_responses']>[string];
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Slug of a Composio meta tool (`COMPOSIO_*`) that `session.executeMeta()` can
|
|
859
|
+
* run, for example `COMPOSIO_SEARCH_TOOLS`.
|
|
860
|
+
*/
|
|
861
|
+
export type ToolRouterSessionMetaToolSlug = SessionExecuteMetaParams['slug'];
|
|
862
|
+
|
|
863
|
+
/** Options for `session.executeMeta()`: the user's answers to an earlier `input_required` call. */
|
|
864
|
+
export type ToolRouterSessionExecuteMetaOptions = Pick<
|
|
865
|
+
ToolRouterSessionExecuteOptions,
|
|
866
|
+
'inputResponses' | 'requestState'
|
|
867
|
+
>;
|
|
868
|
+
|
|
869
|
+
export type ToolRouterSessionExecuteMetaFn = (
|
|
870
|
+
slug: ToolRouterSessionMetaToolSlug,
|
|
871
|
+
arguments_?: Record<string, unknown>,
|
|
872
|
+
options?: ToolRouterSessionExecuteMetaOptions,
|
|
873
|
+
requestOptions?: ComposioRequestOptions
|
|
874
|
+
) => Promise<ToolRouterSessionExecuteResponse>;
|
|
875
|
+
|
|
712
876
|
export type ToolRouterSessionPreloadConfig = SessionCreateResponse.Config.Preload;
|
|
713
877
|
|
|
714
878
|
export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Workbench;
|
|
@@ -847,6 +1011,12 @@ export const ToolRouterUpdateExperimentalSchema = z
|
|
|
847
1011
|
.describe(
|
|
848
1012
|
'Exposes the COMPOSIO_SUBMIT_FEEDBACK helper tool. `null` removes the stored block'
|
|
849
1013
|
),
|
|
1014
|
+
/**
|
|
1015
|
+
* What happens to a call that needs the user's approval when the session's
|
|
1016
|
+
* MCP client can't ask the user: `deny` or `allow`.
|
|
1017
|
+
* @experimental
|
|
1018
|
+
*/
|
|
1019
|
+
noElicitationSupportFallback: ToolRouterNoElicitationSupportFallbackSchema.optional(),
|
|
850
1020
|
sessionConfigId: z
|
|
851
1021
|
.string()
|
|
852
1022
|
.min(1)
|
|
@@ -869,13 +1039,7 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
869
1039
|
instant: ToolRouterInstantSchema.optional().describe(
|
|
870
1040
|
'Experimental Instant usage policy. False disables it. Any supplied object, even one that only sets returnInstantCharge, re-enables it. Omitted subfields keep their stored values.'
|
|
871
1041
|
),
|
|
872
|
-
toolkits:
|
|
873
|
-
.union([
|
|
874
|
-
ToolRouterToolkitsParamSchema,
|
|
875
|
-
ToolRouterToolkitsDisabledConfigSchema,
|
|
876
|
-
ToolRouterToolkitsEnabledConfigSchema,
|
|
877
|
-
])
|
|
878
|
-
.nullable()
|
|
1042
|
+
toolkits: ToolRouterSessionToolkitsSchema.nullable()
|
|
879
1043
|
.optional()
|
|
880
1044
|
.describe(
|
|
881
1045
|
'Toolkit policy. An empty allowlist (`[]` or `{ enable: [] }`) is sent as-is and denies every app toolkit; `null` removes the stored policy and restores the unrestricted default'
|
|
@@ -927,6 +1091,11 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
927
1091
|
.nullable()
|
|
928
1092
|
.optional()
|
|
929
1093
|
.describe('`null` removes the session override; the mode then resolves to disabled'),
|
|
1094
|
+
proxyExecute: ToolRouterProxyExecuteSchema.nullable()
|
|
1095
|
+
.optional()
|
|
1096
|
+
.describe(
|
|
1097
|
+
'Replaces the proxy execute block; a boolean is shorthand for `{ enable }` and `null` removes it'
|
|
1098
|
+
),
|
|
930
1099
|
preload: z
|
|
931
1100
|
.object({
|
|
932
1101
|
tools: z.union([z.array(z.string()), z.literal('all')]).optional(),
|
|
@@ -1137,6 +1306,8 @@ export interface Session<
|
|
|
1137
1306
|
search: ToolRouterSessionSearchFn;
|
|
1138
1307
|
/** Execute a tool within the session */
|
|
1139
1308
|
execute: ToolRouterSessionExecuteFn;
|
|
1309
|
+
/** Execute a Composio meta tool (`COMPOSIO_*`) within the session */
|
|
1310
|
+
executeMeta: ToolRouterSessionExecuteMetaFn;
|
|
1140
1311
|
/** Update the session configuration. Mutates this session in-place and resolves to the updated `config`. */
|
|
1141
1312
|
update: ToolRouterSessionUpdateFn;
|
|
1142
1313
|
/** Delete the session. Deleted sessions are no longer retrievable or executable. */
|
package/src/utils/session.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
2
2
|
// Resolve against the installed package, including slim's copy of the core build.
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { VERSION as clientLibraryVersion } from '@composio/client';
|
|
6
|
-
import type { ComposioRequestHeaders } from '../types/composio.types';
|
|
3
|
+
import manifest from '#client_identity' with { type: 'json' };
|
|
4
|
+
import type { ClientIdentity } from '@composio/client';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Extended globalThis interface for runtime detection
|
|
@@ -93,51 +91,31 @@ function detectRuntime(): string {
|
|
|
93
91
|
|
|
94
92
|
// Detect once at module initialization
|
|
95
93
|
const RUNTIME_ENV = detectRuntime();
|
|
96
|
-
const RuntimeVersionsSchema = z.object({
|
|
97
|
-
Bun: z.object({ version: z.string() }).optional(),
|
|
98
|
-
Deno: z.object({ version: z.object({ deno: z.string() }) }).optional(),
|
|
99
|
-
});
|
|
100
|
-
const runtimeVersions = RuntimeVersionsSchema.safeParse(globalThis);
|
|
101
|
-
const detectRuntimeVersion = (): string | undefined => {
|
|
102
|
-
switch (RUNTIME_ENV) {
|
|
103
|
-
case 'BUN':
|
|
104
|
-
return runtimeVersions.success ? runtimeVersions.data.Bun?.version : undefined;
|
|
105
|
-
case 'DENO':
|
|
106
|
-
return runtimeVersions.success ? runtimeVersions.data.Deno?.version.deno : undefined;
|
|
107
|
-
case 'NODEJS':
|
|
108
|
-
return process.versions.node;
|
|
109
|
-
default:
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const RUNTIME_VERSION = detectRuntimeVersion();
|
|
114
94
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'x-source': 'TYPESCRIPT_SDK',
|
|
121
|
-
'x-runtime': RUNTIME_ENV,
|
|
122
|
-
'x-client-runtime':
|
|
123
|
-
RUNTIME_ENV === 'CLOUDFLARE_WORKERS' ? 'cloudflare' : RUNTIME_ENV.toLowerCase(),
|
|
124
|
-
'x-sdk-version': identity.version,
|
|
125
|
-
'x-client-provenance': identity.name,
|
|
126
|
-
'x-client-version': identity.version,
|
|
127
|
-
'x-client-language': 'typescript',
|
|
128
|
-
'x-client-library': '@composio/client',
|
|
129
|
-
'x-client-library-version': clientLibraryVersion,
|
|
130
|
-
...(RUNTIME_VERSION ? { 'x-runtime-version': RUNTIME_VERSION } : {}),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
95
|
+
/**
|
|
96
|
+
* An identity value is sent as a header, so the client accepts only non-empty
|
|
97
|
+
* printable ASCII with no leading or trailing whitespace.
|
|
98
|
+
*/
|
|
99
|
+
const HEADER_SAFE = /^[\x21-\x7e](?:[\x20-\x7e]*[\x21-\x7e])?$/;
|
|
133
100
|
|
|
134
|
-
|
|
135
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The identity the API client reports for this SDK: its product headers
|
|
103
|
+
* (`x-client-provenance`, `x-client-version`, `x-sdk-version`) and the legacy
|
|
104
|
+
* `x-source`, `x-framework` and `x-runtime` labels. The client adds the
|
|
105
|
+
* library headers and detects the runtime and its version itself.
|
|
106
|
+
*
|
|
107
|
+
* A custom provider whose name cannot be sent as a header value is reported
|
|
108
|
+
* as `unknown` rather than making the SDK fail to construct.
|
|
109
|
+
*/
|
|
110
|
+
export function getClientIdentity(
|
|
136
111
|
provider: BaseComposioProvider<unknown, unknown, unknown> | undefined
|
|
137
|
-
)
|
|
138
|
-
const
|
|
112
|
+
): ClientIdentity {
|
|
113
|
+
const framework = provider?.name;
|
|
139
114
|
return {
|
|
140
|
-
|
|
141
|
-
|
|
115
|
+
product: manifest.name,
|
|
116
|
+
version: manifest.version,
|
|
117
|
+
source: 'TYPESCRIPT_SDK',
|
|
118
|
+
framework: framework && HEADER_SAFE.test(framework) ? framework : 'unknown',
|
|
119
|
+
runtime: RUNTIME_ENV,
|
|
142
120
|
};
|
|
143
|
-
}
|
|
121
|
+
}
|
|
@@ -103,7 +103,10 @@ interface RawToolkitConnectionStatus {
|
|
|
103
103
|
status_message: string;
|
|
104
104
|
connection_details?: Record<string, unknown>;
|
|
105
105
|
current_user_info?: Record<string, unknown>;
|
|
106
|
-
instant_account?: {
|
|
106
|
+
instant_account?: {
|
|
107
|
+
allowed_tool_slugs: string[];
|
|
108
|
+
prices?: Record<string, { description?: string; discount?: string | null }>;
|
|
109
|
+
};
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
interface RawSearchResponse {
|
|
@@ -162,7 +165,10 @@ function transformToolkitConnectionStatus(raw: RawToolkitConnectionStatus) {
|
|
|
162
165
|
connectionDetails: raw.connection_details,
|
|
163
166
|
currentUserInfo: raw.current_user_info,
|
|
164
167
|
...(raw.instant_account !== undefined && {
|
|
165
|
-
instantAccount: {
|
|
168
|
+
instantAccount: {
|
|
169
|
+
allowedToolSlugs: raw.instant_account.allowed_tool_slugs,
|
|
170
|
+
...(raw.instant_account.prices !== undefined && { prices: raw.instant_account.prices }),
|
|
171
|
+
},
|
|
166
172
|
}),
|
|
167
173
|
};
|
|
168
174
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import logger from './logger';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes a thrown or rejected value for a log line without ever throwing.
|
|
5
|
+
*
|
|
6
|
+
* The logger serializes object arguments with `JSON.stringify`, which turns an `Error` into `{}`
|
|
7
|
+
* and throws on a circular value, so callers log this string instead of the raw value.
|
|
8
|
+
* `JSON.stringify` and `String()` can both throw (a circular value, an object without a
|
|
9
|
+
* prototype), so each is tried in turn.
|
|
10
|
+
*/
|
|
11
|
+
export function describeThrown(value: unknown): string {
|
|
12
|
+
try {
|
|
13
|
+
if (value instanceof Error) return value.message;
|
|
14
|
+
if (typeof value === 'object' && value !== null) return JSON.stringify(value) ?? String(value);
|
|
15
|
+
return String(value);
|
|
16
|
+
} catch {
|
|
17
|
+
try {
|
|
18
|
+
return String(value);
|
|
19
|
+
} catch {
|
|
20
|
+
return '[unprintable value]';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calls a user-supplied event callback so that neither a synchronous throw nor a rejected promise
|
|
27
|
+
* escapes into the event emitter that invoked it. Failures are logged after `label`.
|
|
28
|
+
*
|
|
29
|
+
* pusher-js does not catch listener exceptions, and nothing awaits the promise an `async`
|
|
30
|
+
* listener returns, so an escaped failure would end a Node process.
|
|
31
|
+
*/
|
|
32
|
+
export function invokeUserCallback(label: string, callback: () => unknown): void {
|
|
33
|
+
const logFailure = (error: unknown) => {
|
|
34
|
+
logger.error(label, describeThrown(error));
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
Promise.resolve(callback()).catch(logFailure);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logFailure(error);
|
|
40
|
+
}
|
|
41
|
+
}
|