@composio/core 0.20.0 → 0.22.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-fYEFjSLM.mjs → CustomTool-B-_VjWpy.mjs} +1 -1
- package/dist/{CustomTool-B3m-188G.d.mts → CustomTool-CKBCElpT.d.mts} +1 -1
- package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
- package/dist/{cancellation-Dwa9lGHA.mjs → cancellation-DV8CIi52.mjs} +1 -1
- package/dist/{composio-B36OXii1.d.mts → composio-C-418N1P.d.mts} +542 -168
- package/dist/{customTool.types-C436M_D0.d.mts → customTool.types-CK408sI-.d.mts} +522 -66
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -1
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -0
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +83 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +29 -20
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +10 -4
- package/dist/{errors-D_A4b2c2.mjs → errors-Dyiu3ifQ.mjs} +10 -6
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +40 -28
- package/dist/index.mjs +6815 -6571
- package/dist/models/Files.node.mjs +1 -1
- package/dist/{types-Br3GBya5.d.mts → types-RpMRVn4D.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 +5 -3
- package/src/composio.ts +8 -0
- package/src/errors/ToolRouterErrors.ts +10 -6
- package/src/index.ts +2 -0
- package/src/lib/sessionConfigConflict.ts +43 -0
- package/src/lib/toolRouterParams.ts +43 -10
- package/src/lib/toolRouterSourceSessionConfig.ts +12 -0
- package/src/models/AuthConfigs.ts +0 -9
- package/src/models/ConnectionRequest.ts +21 -18
- package/src/models/Logs.ts +2 -2
- package/src/models/RemoteFile.ts +25 -8
- package/src/models/SessionConfigs.ts +117 -0
- package/src/models/ToolRouter.ts +23 -5
- package/src/models/ToolRouterSession.ts +49 -24
- package/src/models/Tools.ts +7 -5
- package/src/models/Usage.ts +2 -1
- package/src/provider/OpenAIProvider.ts +0 -283
- package/src/telemetry/Telemetry.ts +4 -2
- package/src/types/logs.types.ts +9 -1
- package/src/types/sessionConfigs.types.ts +81 -0
- package/src/types/tool.types.ts +3 -1
- package/src/types/toolRouter.types.ts +177 -13
- package/src/types/usage.types.ts +2 -0
- package/src/utils/safePath.ts +172 -0
- package/src/utils/transformers/logs.ts +3 -2
- package/src/utils/transformers/sessionConfigs.ts +54 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +24 -0
- package/src/utils/transformers/usage.ts +4 -0
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
RegisteredCustomToolkit,
|
|
18
18
|
} from './customTool.types';
|
|
19
19
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
20
|
+
import { addSessionConfigConflictIssue } from '../lib/sessionConfigConflict';
|
|
20
21
|
|
|
21
22
|
export const SessionPreset = {
|
|
22
23
|
DIRECT_TOOLS: 'direct_tools',
|
|
@@ -107,6 +108,34 @@ export const ToolRouterToolkitsEnabledConfigSchema = z
|
|
|
107
108
|
})
|
|
108
109
|
.strict();
|
|
109
110
|
|
|
111
|
+
/** Experimental Instant usage policy for a Session. */
|
|
112
|
+
export const ToolRouterInstantSchema = z.union([
|
|
113
|
+
z.literal(false),
|
|
114
|
+
z
|
|
115
|
+
.object({
|
|
116
|
+
toolkits: z
|
|
117
|
+
.union([ToolRouterToolkitsEnabledConfigSchema, ToolRouterToolkitsDisabledConfigSchema])
|
|
118
|
+
.optional(),
|
|
119
|
+
tools: z
|
|
120
|
+
.record(
|
|
121
|
+
z.string(),
|
|
122
|
+
z.union([
|
|
123
|
+
z.object({ enable: z.array(z.string()) }).strict(),
|
|
124
|
+
z.object({ disable: z.array(z.string()) }).strict(),
|
|
125
|
+
])
|
|
126
|
+
)
|
|
127
|
+
.optional(),
|
|
128
|
+
/**
|
|
129
|
+
* Return the actual Instant charge in Session tool responses. Controls
|
|
130
|
+
* visibility only; on update, any policy object still re-enables Instant
|
|
131
|
+
* usage on a Session set to `false`.
|
|
132
|
+
*/
|
|
133
|
+
returnInstantCharge: z.boolean().optional(),
|
|
134
|
+
})
|
|
135
|
+
.strict(),
|
|
136
|
+
]);
|
|
137
|
+
export type ToolRouterInstant = z.infer<typeof ToolRouterInstantSchema>;
|
|
138
|
+
|
|
110
139
|
export const ToolRouterManageConnectionsConfigSchema = z.object({
|
|
111
140
|
enable: z
|
|
112
141
|
.boolean()
|
|
@@ -236,6 +265,10 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
236
265
|
.optional()
|
|
237
266
|
.describe('The toolkits to use in the tool router session'),
|
|
238
267
|
|
|
268
|
+
instant: ToolRouterInstantSchema.optional().describe(
|
|
269
|
+
'Experimental Instant usage policy. Omission permits eligible tools when the project allows Instant usage; false disables it for this Session.'
|
|
270
|
+
),
|
|
271
|
+
|
|
239
272
|
authConfigs: z
|
|
240
273
|
.record(z.string(), z.string())
|
|
241
274
|
.describe(
|
|
@@ -324,12 +357,32 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
324
357
|
.describe(
|
|
325
358
|
'Custom toolkits to include in this session. Created via createCustomToolkit() from @composio/core/experimental.'
|
|
326
359
|
),
|
|
360
|
+
sessionConfigId: z
|
|
361
|
+
.string()
|
|
362
|
+
.min(1)
|
|
363
|
+
.optional()
|
|
364
|
+
.describe(
|
|
365
|
+
'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
|
+
),
|
|
327
367
|
})
|
|
328
368
|
.optional()
|
|
329
369
|
.describe('Experimental features configuration - not stable, may be modified or removed'),
|
|
330
370
|
})
|
|
331
371
|
.partial()
|
|
332
372
|
.superRefine((config, ctx) => {
|
|
373
|
+
// "Provided" means `!== undefined`, so empty arrays conflict too.
|
|
374
|
+
if (config.experimental?.sessionConfigId !== undefined) {
|
|
375
|
+
addSessionConfigConflictIssue(
|
|
376
|
+
ctx,
|
|
377
|
+
[
|
|
378
|
+
config.toolkits !== undefined && 'toolkits',
|
|
379
|
+
config.tools !== undefined && 'tools',
|
|
380
|
+
config.tags !== undefined && 'tags',
|
|
381
|
+
config.experimental.customTools !== undefined && 'experimental.customTools',
|
|
382
|
+
config.experimental.customToolkits !== undefined && 'experimental.customToolkits',
|
|
383
|
+
].filter((field): field is string => field !== false)
|
|
384
|
+
);
|
|
385
|
+
}
|
|
333
386
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
334
387
|
ctx.addIssue({
|
|
335
388
|
code: z.ZodIssueCode.custom,
|
|
@@ -373,6 +426,7 @@ export const ToolRouterCreateSessionConfigSchema = z
|
|
|
373
426
|
* @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
|
|
374
427
|
* @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
|
|
375
428
|
* @param {Record<string, string | string[]>} connectedAccounts - The connected accounts to use in the tool router session. A single string is coerced to a single-element array before being sent to the backend.
|
|
429
|
+
* @param {ToolRouterInstant} [instant] - Experimental Instant usage policy. The project must allow Instant usage.
|
|
376
430
|
* @param {ToolRouterConfigManageConnectionsSchema | boolean} manageConnections - The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.
|
|
377
431
|
* @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
|
|
378
432
|
* @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session
|
|
@@ -388,8 +442,39 @@ export const ToolRouterCreateSessionConfigSchema = z
|
|
|
388
442
|
* @param {boolean} [multiAccount.requireExplicitSelection] - When true, require explicit account selection when multiple accounts are connected
|
|
389
443
|
* @param {object} [preload] - Tools to preload into session.tools() and the MCP tool list
|
|
390
444
|
* @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
|
+
* @param {object} [experimental] - Experimental features configuration. Not stable; may change or be removed.
|
|
446
|
+
* @param {string} [experimental.sessionConfigId] - ID of a saved Session config (`sc_…`) to apply at creation; see `composio.sessionConfigs`. Cannot be combined with `toolkits`, `tools`, `tags`, `experimental.customTools` or `experimental.customToolkits`. Per-session fields such as `authConfigs`, `connectedAccounts`, `manageConnections`, `sandbox`, `multiAccount` and `preload` stay allowed.
|
|
391
447
|
*/
|
|
392
|
-
export type ToolRouterCreateSessionConfig =
|
|
448
|
+
export type ToolRouterCreateSessionConfig =
|
|
449
|
+
InlineAccessCreateSessionConfig | SavedConfigCreateSessionConfig;
|
|
450
|
+
|
|
451
|
+
type ParsedCreateSessionConfig = z.infer<typeof ToolRouterCreateSessionConfigSchema>;
|
|
452
|
+
type ParsedCreateSessionExperimental = NonNullable<ParsedCreateSessionConfig['experimental']>;
|
|
453
|
+
|
|
454
|
+
/** Create input that sets access inline and applies no saved Session config. */
|
|
455
|
+
type InlineAccessCreateSessionConfig = Omit<ParsedCreateSessionConfig, 'experimental'> & {
|
|
456
|
+
experimental?: Omit<ParsedCreateSessionExperimental, 'sessionConfigId'> & {
|
|
457
|
+
sessionConfigId?: never;
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/** Create input that takes its access policy from a saved Session config. */
|
|
462
|
+
type SavedConfigCreateSessionConfig = Omit<
|
|
463
|
+
ParsedCreateSessionConfig,
|
|
464
|
+
'toolkits' | 'tools' | 'tags' | 'experimental'
|
|
465
|
+
> & {
|
|
466
|
+
toolkits?: never;
|
|
467
|
+
tools?: never;
|
|
468
|
+
tags?: never;
|
|
469
|
+
experimental: Omit<
|
|
470
|
+
ParsedCreateSessionExperimental,
|
|
471
|
+
'sessionConfigId' | 'customTools' | 'customToolkits'
|
|
472
|
+
> & {
|
|
473
|
+
sessionConfigId: string;
|
|
474
|
+
customTools?: never;
|
|
475
|
+
customToolkits?: never;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
393
478
|
|
|
394
479
|
export const ToolkitConnectionStateSchema = z
|
|
395
480
|
.object({
|
|
@@ -523,6 +608,8 @@ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
|
|
|
523
608
|
statusMessage: z.string(),
|
|
524
609
|
connectionDetails: z.record(z.string(), z.unknown()).optional(),
|
|
525
610
|
currentUserInfo: z.record(z.string(), z.unknown()).optional(),
|
|
611
|
+
/** Present when the toolkit runs on a Composio Instant account; only these tools run on it. */
|
|
612
|
+
instantAccount: z.object({ allowedToolSlugs: z.array(z.string()) }).optional(),
|
|
526
613
|
});
|
|
527
614
|
|
|
528
615
|
export const ToolRouterSessionSearchResponseSchema = z.object({
|
|
@@ -543,6 +630,8 @@ export const ToolRouterSessionExecuteResponseSchema = z.object({
|
|
|
543
630
|
data: z.record(z.string(), z.unknown()),
|
|
544
631
|
error: z.string().nullable(),
|
|
545
632
|
logId: z.string(),
|
|
633
|
+
/** Actual Instant usage charge when the Session opts into returning it. */
|
|
634
|
+
instantCharge: z.unknown().optional(),
|
|
546
635
|
});
|
|
547
636
|
export type ToolRouterSessionExecuteResponse = z.infer<
|
|
548
637
|
typeof ToolRouterSessionExecuteResponseSchema
|
|
@@ -580,6 +669,14 @@ export interface SessionExperimental {
|
|
|
580
669
|
* File mount operations (list, upload, download, delete) for the session's virtual filesystem.
|
|
581
670
|
*/
|
|
582
671
|
files: ToolRouterSessionFilesMount;
|
|
672
|
+
/**
|
|
673
|
+
* The last saved Session config applied to this session, set from the
|
|
674
|
+
* create, `use()` and `update()` responses. Later inline access updates
|
|
675
|
+
* keep it. It reflects the last response this object saw: an update from
|
|
676
|
+
* another process leaves it stale until `sessions.use()`.
|
|
677
|
+
* @experimental
|
|
678
|
+
*/
|
|
679
|
+
sourceSessionConfig?: { id: string };
|
|
583
680
|
}
|
|
584
681
|
|
|
585
682
|
export type ToolRouterSessionSearchFn = (params: {
|
|
@@ -595,7 +692,8 @@ export type ToolRouterSessionExecuteFn = (
|
|
|
595
692
|
|
|
596
693
|
export interface ToolRouterSessionExecuteOptions {
|
|
597
694
|
/**
|
|
598
|
-
* Account identifier for direct app tool execution.
|
|
695
|
+
* Account identifier for direct app tool execution. Use `instant_account` to
|
|
696
|
+
* explicitly select the Composio Instant account. Accepted on every project:
|
|
599
697
|
* in multi-account sessions it picks the account; on single-account projects it
|
|
600
698
|
* must match one of the session's active connections for the toolkit.
|
|
601
699
|
* Meta/helper tools either ignore this top-level field or define
|
|
@@ -611,12 +709,28 @@ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Work
|
|
|
611
709
|
|
|
612
710
|
export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
|
|
613
711
|
|
|
712
|
+
const ToolRouterInstantResponseFilterSchema = z.union([
|
|
713
|
+
z.object({ enabled: z.array(z.string()) }),
|
|
714
|
+
z.object({ disabled: z.array(z.string()) }),
|
|
715
|
+
]);
|
|
716
|
+
|
|
717
|
+
/** Instant policy in the server's Session config (wire field casing). */
|
|
718
|
+
export const ToolRouterInstantResponseSchema = z.object({
|
|
719
|
+
toolkits: ToolRouterInstantResponseFilterSchema.optional(),
|
|
720
|
+
tools: z.record(z.string(), ToolRouterInstantResponseFilterSchema).optional(),
|
|
721
|
+
return_instant_charge: z.boolean(),
|
|
722
|
+
});
|
|
723
|
+
export type ToolRouterInstantResponse = z.infer<typeof ToolRouterInstantResponseSchema>;
|
|
724
|
+
|
|
614
725
|
/**
|
|
615
|
-
* Server-side session configuration as returned by the API: toolkit
|
|
726
|
+
* Server-side session configuration as returned by the API: toolkit/tool
|
|
616
727
|
* allowlists, tags, auth configs, connected accounts, manage_connections,
|
|
617
|
-
* preload, sandbox (`workbench`), search and
|
|
728
|
+
* preload, sandbox (`workbench`), search, execute and Instant settings.
|
|
729
|
+
* The generated client still declares the old policy name.
|
|
618
730
|
*/
|
|
619
|
-
export type ToolRouterSessionConfig = SessionCreateResponse.Config
|
|
731
|
+
export type ToolRouterSessionConfig = Omit<SessionCreateResponse.Config, 'premium_usage'> & {
|
|
732
|
+
instant?: false | ToolRouterInstantResponse;
|
|
733
|
+
};
|
|
620
734
|
|
|
621
735
|
export interface ToolRouterSessionMetadata {
|
|
622
736
|
/** Present on every session built from an API response; the constructor synthesises a minimal config when absent. */
|
|
@@ -744,8 +858,11 @@ export const ToolRouterUpdateExperimentalSchema = z
|
|
|
744
858
|
),
|
|
745
859
|
sessionConfigId: z
|
|
746
860
|
.string()
|
|
861
|
+
.min(1)
|
|
747
862
|
.optional()
|
|
748
|
-
.describe(
|
|
863
|
+
.describe(
|
|
864
|
+
"Apply the latest active saved Session config (`sc_…`) from this project to this session. Replaces the session's toolkit, tool and tag access and cannot be combined with toolkits, tools or tags"
|
|
865
|
+
),
|
|
749
866
|
})
|
|
750
867
|
.strict();
|
|
751
868
|
export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdateExperimentalSchema>;
|
|
@@ -758,6 +875,9 @@ export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdate
|
|
|
758
875
|
*/
|
|
759
876
|
export const ToolRouterUpdateSessionConfigSchema = z
|
|
760
877
|
.object({
|
|
878
|
+
instant: ToolRouterInstantSchema.optional().describe(
|
|
879
|
+
'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.'
|
|
880
|
+
),
|
|
761
881
|
toolkits: z
|
|
762
882
|
.union([
|
|
763
883
|
ToolRouterToolkitsParamSchema,
|
|
@@ -843,11 +963,22 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
843
963
|
.union([z.number().int().positive(), z.literal(false)])
|
|
844
964
|
.optional()
|
|
845
965
|
.describe(
|
|
846
|
-
'Precondition sent as `expected_config_version`.
|
|
966
|
+
'Precondition sent as `expected_config_version`. A positive integer (for example `session.configVersion`) makes the update conditional, so a concurrent change surfaces as ComposioSessionConfigConflictError instead of being overwritten; the API must support the field. Omitted or `false`: no precondition (last writer wins)'
|
|
847
967
|
),
|
|
848
968
|
})
|
|
849
969
|
.partial()
|
|
850
970
|
.superRefine((config, ctx) => {
|
|
971
|
+
// "Provided" means `!== undefined`, so `null` conflicts too.
|
|
972
|
+
if (config.experimental?.sessionConfigId !== undefined) {
|
|
973
|
+
addSessionConfigConflictIssue(
|
|
974
|
+
ctx,
|
|
975
|
+
[
|
|
976
|
+
config.toolkits !== undefined && 'toolkits',
|
|
977
|
+
config.tools !== undefined && 'tools',
|
|
978
|
+
config.tags !== undefined && 'tags',
|
|
979
|
+
].filter((field): field is string => field !== false)
|
|
980
|
+
);
|
|
981
|
+
}
|
|
851
982
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
852
983
|
ctx.addIssue({
|
|
853
984
|
code: z.ZodIssueCode.custom,
|
|
@@ -858,7 +989,35 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
858
989
|
}
|
|
859
990
|
});
|
|
860
991
|
|
|
861
|
-
|
|
992
|
+
/**
|
|
993
|
+
* Options for `session.update()`. `experimental.sessionConfigId` applies a
|
|
994
|
+
* saved Session config and cannot be combined with `toolkits`, `tools` or
|
|
995
|
+
* `tags` (including `null`).
|
|
996
|
+
*/
|
|
997
|
+
export type ToolRouterUpdateSessionConfig =
|
|
998
|
+
InlineAccessUpdateSessionConfig | SavedConfigUpdateSessionConfig;
|
|
999
|
+
|
|
1000
|
+
type ParsedUpdateSessionConfig = z.infer<typeof ToolRouterUpdateSessionConfigSchema>;
|
|
1001
|
+
type ParsedUpdateSessionExperimental = NonNullable<ParsedUpdateSessionConfig['experimental']>;
|
|
1002
|
+
|
|
1003
|
+
/** Update input that sets access inline and applies no saved Session config. */
|
|
1004
|
+
type InlineAccessUpdateSessionConfig = Omit<ParsedUpdateSessionConfig, 'experimental'> & {
|
|
1005
|
+
experimental?:
|
|
1006
|
+
(Omit<ParsedUpdateSessionExperimental, 'sessionConfigId'> & { sessionConfigId?: never }) | null;
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
/** Update input that applies a saved Session config. */
|
|
1010
|
+
type SavedConfigUpdateSessionConfig = Omit<
|
|
1011
|
+
ParsedUpdateSessionConfig,
|
|
1012
|
+
'toolkits' | 'tools' | 'tags' | 'experimental'
|
|
1013
|
+
> & {
|
|
1014
|
+
toolkits?: never;
|
|
1015
|
+
tools?: never;
|
|
1016
|
+
tags?: never;
|
|
1017
|
+
experimental: Omit<ParsedUpdateSessionExperimental, 'sessionConfigId'> & {
|
|
1018
|
+
sessionConfigId: string;
|
|
1019
|
+
};
|
|
1020
|
+
};
|
|
862
1021
|
|
|
863
1022
|
export type ToolRouterSessionUpdateFn = (
|
|
864
1023
|
config: ToolRouterUpdateSessionConfig
|
|
@@ -885,9 +1044,14 @@ export type ToolRouterSessionListConfigHistoryOptions = z.infer<
|
|
|
885
1044
|
|
|
886
1045
|
/**
|
|
887
1046
|
* The session configuration at one version, as stored by the API. This is
|
|
888
|
-
* the wire shape (snake_case),
|
|
1047
|
+
* the wire shape (snake_case), with the Instant policy under `instant`.
|
|
889
1048
|
*/
|
|
890
|
-
export type ToolRouterSessionConfigHistoryConfig =
|
|
1049
|
+
export type ToolRouterSessionConfigHistoryConfig = Omit<
|
|
1050
|
+
SessionConfigHistoryResponse.Item.Config,
|
|
1051
|
+
'premium_usage'
|
|
1052
|
+
> & {
|
|
1053
|
+
instant?: false | ToolRouterInstantResponse;
|
|
1054
|
+
};
|
|
891
1055
|
|
|
892
1056
|
export type ToolRouterSessionConfigHistoryItem = {
|
|
893
1057
|
/** The config version this entry represents. */
|
|
@@ -955,9 +1119,9 @@ export interface Session<
|
|
|
955
1119
|
sessionId: string;
|
|
956
1120
|
mcp: ToolRouterMCPServerConfig;
|
|
957
1121
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* `
|
|
1122
|
+
* The session's current configuration (policy snapshot and runtime
|
|
1123
|
+
* settings). Refreshed in place by `update()`. For saved, reusable Session
|
|
1124
|
+
* configs, see `composio.sessionConfigs`.
|
|
961
1125
|
*/
|
|
962
1126
|
config: ToolRouterSessionConfig;
|
|
963
1127
|
/** Stored preload configuration for this session. */
|
package/src/types/usage.types.ts
CHANGED
|
@@ -61,6 +61,8 @@ export type UsageEntitySummary = z.infer<typeof UsageEntitySummarySchema>;
|
|
|
61
61
|
export const UsageSummaryResponseSchema = z.object({
|
|
62
62
|
/** Aggregates keyed by metering entity type (e.g. `tool_calls`, `sessions`). */
|
|
63
63
|
entities: z.record(z.string(), UsageEntitySummarySchema),
|
|
64
|
+
/** Total Instant charge for the window, in USD as an exact decimal string. */
|
|
65
|
+
instantCharge: z.string(),
|
|
64
66
|
});
|
|
65
67
|
export type UsageSummaryResponse = z.infer<typeof UsageSummaryResponseSchema>;
|
|
66
68
|
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filename containment for untrusted input.
|
|
3
|
+
*
|
|
4
|
+
* Every field of an API response is untrusted, including filenames. When such a
|
|
5
|
+
* value becomes part of a filesystem path it must pass through this module
|
|
6
|
+
* first, and validation must happen before any `mkdir` or write so a rejected
|
|
7
|
+
* value leaves nothing behind on disk.
|
|
8
|
+
*
|
|
9
|
+
* TypeScript counterpart of `safe_basename` in `python/composio/utils/safe_path.py`.
|
|
10
|
+
* The two use the same validation order and whitespace rules. Path extraction
|
|
11
|
+
* is intentionally limited here; see `untrustedBasename`.
|
|
12
|
+
*
|
|
13
|
+
* Pure string logic with no filesystem access: no static `node:*` imports, so
|
|
14
|
+
* it is usable from edge/workerd builds.
|
|
15
|
+
*/
|
|
16
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Upper bound on a filename, well under the 255-byte limit common to
|
|
20
|
+
* ext4/APFS/NTFS. Keeps a long server-supplied name from failing with a raw
|
|
21
|
+
* `ENAMETOOLONG` mid-write. Matches `MAX_COMPONENT_LENGTH` in the Python SDK.
|
|
22
|
+
*/
|
|
23
|
+
export const MAX_FILENAME_BYTES = 128;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reserved DOS device names. Writing to one on Windows targets the device
|
|
27
|
+
* rather than a file. Rejected on every platform so behavior does not diverge
|
|
28
|
+
* between a POSIX developer machine and a Windows deployment.
|
|
29
|
+
*/
|
|
30
|
+
const WINDOWS_RESERVED_NAMES: ReadonlySet<string> = new Set([
|
|
31
|
+
'CON',
|
|
32
|
+
'PRN',
|
|
33
|
+
'AUX',
|
|
34
|
+
'NUL',
|
|
35
|
+
...Array.from({ length: 9 }, (_, i) => `COM${i + 1}`),
|
|
36
|
+
...Array.from({ length: 9 }, (_, i) => `LPT${i + 1}`),
|
|
37
|
+
...['¹', '²', '³'].flatMap(superscript => [`COM${superscript}`, `LPT${superscript}`]),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
/** Control characters and characters reserved by Windows. */
|
|
41
|
+
const WINDOWS_INVALID_CHARS = /[\u0000-\u001f<>:"|?*]/;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Python str.strip() whitespace: Unicode White_Space plus U+001C–U+001F.
|
|
45
|
+
* Unlike JavaScript trim(), this includes U+0085 and preserves U+FEFF.
|
|
46
|
+
*/
|
|
47
|
+
const PYTHON_WHITESPACE =
|
|
48
|
+
'[\\u0009-\\u000d\\u001c-\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]';
|
|
49
|
+
const SURROUNDING_WHITESPACE = new RegExp(`^${PYTHON_WHITESPACE}+|${PYTHON_WHITESPACE}+$`, 'g');
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns the last path segment of `value`, treating both `/` and `\` as
|
|
53
|
+
* separators, or `''` when there is none.
|
|
54
|
+
*
|
|
55
|
+
* `path.basename()` on POSIX only splits on `/`, so a name crafted for a
|
|
56
|
+
* Windows target (`..\..\evil`) comes back intact on macOS and Linux. Splitting
|
|
57
|
+
* on both and removing an initial drive prefix also handles `C:report.txt`.
|
|
58
|
+
* This is not a full `PureWindowsPath` parser: dot components stay literal,
|
|
59
|
+
* and UNC anchors are not interpreted.
|
|
60
|
+
*
|
|
61
|
+
* Never throws: this is a display value as well as the input to
|
|
62
|
+
* {@link safeBasename}, and it is read while constructing download errors.
|
|
63
|
+
*/
|
|
64
|
+
export function untrustedBasename(value: string): string {
|
|
65
|
+
const segments = value.replace(/^[a-z]:/i, '').split(/[/\\]+/);
|
|
66
|
+
// Trailing separators name the same file: `a/b/` and `a/b` both basename to `b`.
|
|
67
|
+
while (segments.length > 0 && segments[segments.length - 1] === '') {
|
|
68
|
+
segments.pop();
|
|
69
|
+
}
|
|
70
|
+
return segments[segments.length - 1] ?? '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* True when `value` contains a surrogate code unit that is not part of a valid
|
|
75
|
+
* pair. Such a string cannot be encoded as UTF-8; `TextEncoder` silently
|
|
76
|
+
* substitutes U+FFFD, which would write a file under a name the response never
|
|
77
|
+
* specified. `String.prototype.isWellFormed()` is ES2024 and this package
|
|
78
|
+
* targets es2022, hence the manual scan.
|
|
79
|
+
*/
|
|
80
|
+
function hasLoneSurrogate(value: string): boolean {
|
|
81
|
+
for (let i = 0; i < value.length; i++) {
|
|
82
|
+
const code = value.charCodeAt(i);
|
|
83
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
84
|
+
const next = value.charCodeAt(i + 1);
|
|
85
|
+
if (!(next >= 0xdc00 && next <= 0xdfff)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
i++;
|
|
89
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Collapses an untrusted filename to a bare, writable basename.
|
|
98
|
+
*
|
|
99
|
+
* Applies, in order: no usable basename (empty or a run of dots once
|
|
100
|
+
* surrounding whitespace is stripped), NUL bytes, control and Windows-reserved
|
|
101
|
+
* characters, trailing space or dot, invalid Unicode, a byte-length bound, and
|
|
102
|
+
* reserved device names. This is the order `safe_basename` uses in the Python
|
|
103
|
+
* SDK. This implementation rejects lone surrogates rather than relying on
|
|
104
|
+
* Python filesystem encoding behavior.
|
|
105
|
+
*
|
|
106
|
+
* Names that leave no usable basename are refused rather than replaced with a
|
|
107
|
+
* generated one: a response that cannot name its own file is malformed or
|
|
108
|
+
* hostile, and inventing a name would hide that. `""`, `"."` and `".."` make
|
|
109
|
+
* an output path equal to, or escape, its own directory, which surfaces as a
|
|
110
|
+
* raw `EISDIR` at write time instead of a validation error.
|
|
111
|
+
*
|
|
112
|
+
* The usability check runs on the *trimmed* basename because that is what gets
|
|
113
|
+
* written: Python-compatible stripping removes whitespace, so `"\u00a0.\u00a0"` would
|
|
114
|
+
* otherwise pass a check on the raw segment and then be written as `"."`. The
|
|
115
|
+
* hazard checks that follow run on the raw segment so a trailing ASCII space or
|
|
116
|
+
* dot is refused, not trimmed away. Check the stripped value for trailing dots
|
|
117
|
+
* too, since stripping whitespace can expose one.
|
|
118
|
+
*
|
|
119
|
+
* @param name - The untrusted filename or relative path to reduce.
|
|
120
|
+
* @param label - How the value is described in error messages.
|
|
121
|
+
* @returns The validated bare basename, with surrounding whitespace trimmed.
|
|
122
|
+
* @throws ValidationError if `name` yields no usable basename or is unsafe to write.
|
|
123
|
+
*/
|
|
124
|
+
export function safeBasename(name: string, label: string = 'filename'): string {
|
|
125
|
+
const rawBasename = untrustedBasename(name);
|
|
126
|
+
const basename = rawBasename.replace(SURROUNDING_WHITESPACE, '');
|
|
127
|
+
|
|
128
|
+
if (!basename || /^\.+$/.test(basename)) {
|
|
129
|
+
throw new ValidationError(
|
|
130
|
+
`Path traversal detected: ${label} ${JSON.stringify(name)} leaves no usable basename to write to.`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (rawBasename.includes('\u0000')) {
|
|
134
|
+
throw new ValidationError(
|
|
135
|
+
`Refusing to write ${label} containing a NUL byte: ${JSON.stringify(name)}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (WINDOWS_INVALID_CHARS.test(rawBasename)) {
|
|
139
|
+
throw new ValidationError(
|
|
140
|
+
`Refusing to write ${label} containing characters reserved by Windows: ${JSON.stringify(name)}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (rawBasename.endsWith(' ') || rawBasename.endsWith('.') || basename.endsWith('.')) {
|
|
144
|
+
throw new ValidationError(
|
|
145
|
+
`Refusing to write ${label} ending in a space or dot: ${JSON.stringify(name)}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (hasLoneSurrogate(basename)) {
|
|
149
|
+
throw new ValidationError(
|
|
150
|
+
`Refusing to write ${label} containing invalid Unicode: ${JSON.stringify(name)}`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const encodedLength = new TextEncoder().encode(basename).length;
|
|
155
|
+
if (encodedLength > MAX_FILENAME_BYTES) {
|
|
156
|
+
throw new ValidationError(
|
|
157
|
+
`Refusing to write ${label} longer than ${MAX_FILENAME_BYTES} bytes: ` +
|
|
158
|
+
`${JSON.stringify(basename.slice(0, 32))}... (${encodedLength} bytes)`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Compare everything before the first dot: on Windows `NUL.tar.gz` opens the
|
|
163
|
+
// null device just as `NUL` does, so extensions provide no protection.
|
|
164
|
+
const deviceName = basename.split('.', 1)[0].replace(/ +$/, '').toUpperCase();
|
|
165
|
+
if (WINDOWS_RESERVED_NAMES.has(deviceName)) {
|
|
166
|
+
throw new ValidationError(
|
|
167
|
+
`Refusing to write ${label} that is a reserved device name: ${JSON.stringify(name)}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return basename;
|
|
172
|
+
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ToolExecutionLog,
|
|
11
11
|
ToolExecutionLogDetail,
|
|
12
12
|
ToolExecutionLogDetailSchema,
|
|
13
|
+
ToolExecutionLogMetadataSchema,
|
|
13
14
|
ToolExecutionLogSchema,
|
|
14
15
|
} from '../../types/logs.types';
|
|
15
16
|
import { transform } from '../transform';
|
|
@@ -33,7 +34,7 @@ export const transformToolExecutionLog = (
|
|
|
33
34
|
status: response.status,
|
|
34
35
|
level: response.level,
|
|
35
36
|
message: response.message,
|
|
36
|
-
metadata: response.metadata,
|
|
37
|
+
metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
|
|
37
38
|
metrics: response.metrics,
|
|
38
39
|
parent: response.parent
|
|
39
40
|
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
@@ -62,7 +63,7 @@ export const transformToolExecutionLogDetail = (
|
|
|
62
63
|
status: response.status,
|
|
63
64
|
level: response.level,
|
|
64
65
|
message: response.message,
|
|
65
|
-
metadata: response.metadata,
|
|
66
|
+
metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
|
|
66
67
|
metrics: response.metrics,
|
|
67
68
|
parent: response.parent
|
|
68
69
|
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SessionConfigsListResponse as RawSessionConfigListResponse,
|
|
3
|
+
SessionConfigsRetrieveResponse as RawSessionConfig,
|
|
4
|
+
} from '@composio/client/resources/session-configs';
|
|
5
|
+
import {
|
|
6
|
+
SessionConfig,
|
|
7
|
+
SessionConfigListResponse,
|
|
8
|
+
SessionConfigListResponseSchema,
|
|
9
|
+
SessionConfigSchema,
|
|
10
|
+
SessionConfigSummary,
|
|
11
|
+
SessionConfigSummarySchema,
|
|
12
|
+
} from '../../types/sessionConfigs.types';
|
|
13
|
+
import { transform } from '../transform';
|
|
14
|
+
|
|
15
|
+
export const transformSessionConfigSummary = (
|
|
16
|
+
response: RawSessionConfigListResponse.Item
|
|
17
|
+
): SessionConfigSummary => {
|
|
18
|
+
return transform(response)
|
|
19
|
+
.with(SessionConfigSummarySchema)
|
|
20
|
+
.using(response => ({
|
|
21
|
+
id: response.id,
|
|
22
|
+
name: response.name,
|
|
23
|
+
archived: response.archived,
|
|
24
|
+
createdAt: response.created_at,
|
|
25
|
+
updatedAt: response.updated_at,
|
|
26
|
+
}));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const transformSessionConfigListResponse = (
|
|
30
|
+
response: RawSessionConfigListResponse
|
|
31
|
+
): SessionConfigListResponse => {
|
|
32
|
+
return transform(response)
|
|
33
|
+
.with(SessionConfigListResponseSchema)
|
|
34
|
+
.using(response => ({
|
|
35
|
+
items: response.items.map(transformSessionConfigSummary),
|
|
36
|
+
nextCursor: response.next_cursor,
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const transformSessionConfig = (response: RawSessionConfig): SessionConfig => {
|
|
41
|
+
return transform(response)
|
|
42
|
+
.with(SessionConfigSchema)
|
|
43
|
+
.using(response => ({
|
|
44
|
+
id: response.id,
|
|
45
|
+
name: response.name,
|
|
46
|
+
description: response.description,
|
|
47
|
+
archived: response.archived,
|
|
48
|
+
// The policy has no snake_case keys: copy it as-is so toolkit slugs
|
|
49
|
+
// and tag names survive.
|
|
50
|
+
config: response.config,
|
|
51
|
+
createdAt: response.created_at,
|
|
52
|
+
updatedAt: response.updated_at,
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transforms snake_case Tool Router API responses to camelCase for SDK consumers.
|
|
3
3
|
*/
|
|
4
|
+
import { z } from 'zod/v3';
|
|
5
|
+
import {
|
|
6
|
+
ToolRouterInstantResponseSchema,
|
|
7
|
+
type ToolRouterInstantResponse,
|
|
8
|
+
} from '../../types/toolRouter.types';
|
|
9
|
+
|
|
10
|
+
const SessionConfigInstantSchema = z.object({
|
|
11
|
+
instant: z.union([z.literal(false), ToolRouterInstantResponseSchema]).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** Session config retains its API casing, including `instant.return_instant_charge`. */
|
|
15
|
+
export function transformSessionConfig<Config extends { premium_usage?: unknown }>(
|
|
16
|
+
raw: Config
|
|
17
|
+
): Omit<Config, 'premium_usage'> & { instant?: false | ToolRouterInstantResponse } {
|
|
18
|
+
const { instant } = SessionConfigInstantSchema.parse(raw);
|
|
19
|
+
const { premium_usage: _previousPolicy, ...config } = raw;
|
|
20
|
+
return { ...config, ...(instant !== undefined && { instant }) };
|
|
21
|
+
}
|
|
4
22
|
|
|
5
23
|
interface RawSearchResult {
|
|
6
24
|
index: number;
|
|
@@ -51,6 +69,7 @@ interface RawToolkitConnectionStatus {
|
|
|
51
69
|
status_message: string;
|
|
52
70
|
connection_details?: Record<string, unknown>;
|
|
53
71
|
current_user_info?: Record<string, unknown>;
|
|
72
|
+
instant_account?: { allowed_tool_slugs: string[] };
|
|
54
73
|
}
|
|
55
74
|
|
|
56
75
|
interface RawSearchResponse {
|
|
@@ -68,6 +87,7 @@ interface RawExecuteResponse {
|
|
|
68
87
|
data: Record<string, unknown>;
|
|
69
88
|
error: string | null;
|
|
70
89
|
log_id: string;
|
|
90
|
+
instant_charge?: unknown;
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
function transformSearchResult(raw: RawSearchResult) {
|
|
@@ -114,6 +134,9 @@ function transformToolkitConnectionStatus(raw: RawToolkitConnectionStatus) {
|
|
|
114
134
|
statusMessage: raw.status_message,
|
|
115
135
|
connectionDetails: raw.connection_details,
|
|
116
136
|
currentUserInfo: raw.current_user_info,
|
|
137
|
+
...(raw.instant_account !== undefined && {
|
|
138
|
+
instantAccount: { allowedToolSlugs: raw.instant_account.allowed_tool_slugs },
|
|
139
|
+
}),
|
|
117
140
|
};
|
|
118
141
|
}
|
|
119
142
|
|
|
@@ -156,5 +179,6 @@ export function transformExecuteResponse(raw: RawExecuteResponse) {
|
|
|
156
179
|
data: raw.data,
|
|
157
180
|
error: raw.error,
|
|
158
181
|
logId: raw.log_id,
|
|
182
|
+
...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
|
|
159
183
|
};
|
|
160
184
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
UsageRetrieveSummaryParams as RawUsageSummaryParams,
|
|
5
5
|
UsageRetrieveSummaryResponse as RawUsageSummaryResponse,
|
|
6
6
|
} from '@composio/client/resources/project/usage';
|
|
7
|
+
import { z } from 'zod/v3';
|
|
7
8
|
import {
|
|
8
9
|
UsageBreakdownParams,
|
|
9
10
|
UsageBreakdownResponse,
|
|
@@ -42,6 +43,8 @@ export const transformUsageBreakdownParams = (
|
|
|
42
43
|
export const transformUsageSummaryResponse = (
|
|
43
44
|
response: RawUsageSummaryResponse
|
|
44
45
|
): UsageSummaryResponse => {
|
|
46
|
+
// The pinned generated client predates this response field but preserves the raw JSON.
|
|
47
|
+
const { instant_charge } = z.object({ instant_charge: z.string() }).parse(response);
|
|
45
48
|
return transform(response)
|
|
46
49
|
.with(UsageSummaryResponseSchema)
|
|
47
50
|
.using(response => ({
|
|
@@ -55,6 +58,7 @@ export const transformUsageSummaryResponse = (
|
|
|
55
58
|
},
|
|
56
59
|
])
|
|
57
60
|
),
|
|
61
|
+
instantCharge: instant_charge,
|
|
58
62
|
}));
|
|
59
63
|
};
|
|
60
64
|
|