@composio/core 0.20.0 → 0.21.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-BHOYxLZX.d.mts} +1 -1
- package/dist/{cancellation-Dwa9lGHA.mjs → cancellation-DV8CIi52.mjs} +1 -1
- package/dist/{composio-B36OXii1.d.mts → composio-BTZsFajb.d.mts} +464 -4
- package/dist/{customTool.types-C436M_D0.d.mts → customTool.types-D_w21L56.d.mts} +454 -59
- 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 +39 -26
- package/dist/index.mjs +1482 -1049
- package/dist/{types-Br3GBya5.d.mts → types-CgRsUGqm.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 +3 -1
- 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 +34 -9
- package/src/lib/toolRouterSourceSessionConfig.ts +12 -0
- package/src/models/RemoteFile.ts +25 -8
- package/src/models/SessionConfigs.ts +117 -0
- package/src/models/ToolRouter.ts +19 -3
- package/src/models/ToolRouterSession.ts +45 -21
- package/src/models/Tools.ts +7 -5
- package/src/types/sessionConfigs.types.ts +81 -0
- package/src/types/tool.types.ts +2 -0
- package/src/types/toolRouter.types.ts +149 -7
- package/src/utils/safePath.ts +172 -0
- package/src/utils/transformers/sessionConfigs.ts +54 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +6 -0
|
@@ -86,6 +86,8 @@ import {
|
|
|
86
86
|
import { transformProxyParams } from './proxyParamsTransform';
|
|
87
87
|
import { inlineCustomToolsExperimental } from './inlineCustomToolsPayload';
|
|
88
88
|
import { transformToolRouterUpdateParams } from '../lib/toolRouterParams';
|
|
89
|
+
import { parseSessionConfigInput } from '../lib/sessionConfigConflict';
|
|
90
|
+
import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
|
|
89
91
|
import { deleteToolRouterSession } from '../lib/toolRouterSessionDelete';
|
|
90
92
|
|
|
91
93
|
const COMPOSIO_MULTI_EXECUTE_TOOL = 'COMPOSIO_MULTI_EXECUTE_TOOL';
|
|
@@ -129,9 +131,9 @@ export class ToolRouterSession<
|
|
|
129
131
|
public readonly mcp: ToolRouterMCPServerConfig;
|
|
130
132
|
public readonly experimental: SessionExperimental;
|
|
131
133
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* `
|
|
134
|
+
* The session's current configuration (policy snapshot and runtime
|
|
135
|
+
* settings). Refreshed in place by `update()`. For saved, reusable Session
|
|
136
|
+
* configs, see `composio.sessionConfigs`.
|
|
135
137
|
*/
|
|
136
138
|
public config: ToolRouterSessionConfig;
|
|
137
139
|
public preload: ToolRouterSessionPreloadConfig;
|
|
@@ -139,8 +141,8 @@ export class ToolRouterSession<
|
|
|
139
141
|
public sandbox?: ToolRouterSessionWorkbenchConfig;
|
|
140
142
|
/**
|
|
141
143
|
* Version of the server-side configuration this object last observed.
|
|
142
|
-
* Refreshed in place by `update()
|
|
143
|
-
*
|
|
144
|
+
* Refreshed in place by `update()`. Pass it as `expectedConfigVersion` to
|
|
145
|
+
* make an update conditional.
|
|
144
146
|
*/
|
|
145
147
|
public configVersion?: number;
|
|
146
148
|
public warnings: ToolRouterSessionWarning[];
|
|
@@ -155,7 +157,7 @@ export class ToolRouterSession<
|
|
|
155
157
|
private readonly sdkConfig: ComposioConfig<TProvider> | undefined,
|
|
156
158
|
sessionId: string,
|
|
157
159
|
mcp: ToolRouterMCPServerConfig,
|
|
158
|
-
experimentalOverrides?: Pick<SessionExperimental, 'assistivePrompt'>,
|
|
160
|
+
experimentalOverrides?: Pick<SessionExperimental, 'assistivePrompt' | 'sourceSessionConfig'>,
|
|
159
161
|
private readonly customToolsMap?: CustomToolsMap,
|
|
160
162
|
private readonly userId?: string,
|
|
161
163
|
metadata?: ToolRouterSessionMetadata
|
|
@@ -175,6 +177,7 @@ export class ToolRouterSession<
|
|
|
175
177
|
this.experimental = {
|
|
176
178
|
assistivePrompt: experimentalOverrides?.assistivePrompt,
|
|
177
179
|
files: new ToolRouterSessionFilesMount(client, sessionId),
|
|
180
|
+
sourceSessionConfig: experimentalOverrides?.sourceSessionConfig,
|
|
178
181
|
};
|
|
179
182
|
this.config = config;
|
|
180
183
|
this.preload = metadata?.preload ?? config.preload;
|
|
@@ -778,30 +781,37 @@ export class ToolRouterSession<
|
|
|
778
781
|
* map entirely. `manageConnections.callbackUrl: null` removes only the
|
|
779
782
|
* stored callback URL.
|
|
780
783
|
*
|
|
781
|
-
*
|
|
782
|
-
* `
|
|
784
|
+
* By default the request carries no precondition: the last writer wins.
|
|
785
|
+
* Pass `expectedConfigVersion` (for example `session.configVersion`) to make
|
|
786
|
+
* the update conditional: the API then applies it only when the stored
|
|
787
|
+
* version still matches, and a concurrent change surfaces as
|
|
783
788
|
* {@link ComposioSessionConfigConflictError} (HTTP 409) instead of being
|
|
784
|
-
* overwritten.
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
* exactly once. On conflict this object is left
|
|
788
|
-
* session with `sessions.use(sessionId)` and retry
|
|
789
|
-
* `configVersion`.
|
|
789
|
+
* overwritten. The API must support the `expected_config_version` field;
|
|
790
|
+
* otherwise it rejects the request with a 400. `expectedConfigVersion: false`
|
|
791
|
+
* is the same as omitting it. The PATCH is never retried by the transport,
|
|
792
|
+
* so a 409 is reported exactly once. On conflict this object is left
|
|
793
|
+
* unchanged: re-fetch the session with `sessions.use(sessionId)` and retry
|
|
794
|
+
* against the fresh `configVersion`.
|
|
790
795
|
*
|
|
791
|
-
* `
|
|
792
|
-
*
|
|
793
|
-
* `
|
|
796
|
+
* `experimental.sessionConfigId` applies a saved Session config: it
|
|
797
|
+
* replaces the session's toolkit, tool and tag access and cannot be combined
|
|
798
|
+
* with `toolkits`, `tools` or `tags` (a `ValidationError` is thrown before
|
|
799
|
+
* any request). A 409 while applying it means the session or the config
|
|
800
|
+
* changed; re-fetch the session and retry. Backend 400, 403 and 404 errors,
|
|
801
|
+
* for example for an archived or missing config, surface unchanged.
|
|
802
|
+
*
|
|
803
|
+
* `config`, `configVersion`, `preload`, `sandbox`, `warnings` and
|
|
804
|
+
* `experimental.sourceSessionConfig` are refreshed in place only after a
|
|
805
|
+
* successful response, and the updated `config` is returned.
|
|
794
806
|
*/
|
|
795
807
|
async update(
|
|
796
808
|
config: ToolRouterUpdateSessionConfig,
|
|
797
809
|
requestOptions?: ComposioRequestOptions
|
|
798
810
|
): Promise<ToolRouterSessionConfig> {
|
|
799
|
-
const parsed = ToolRouterUpdateSessionConfigSchema
|
|
811
|
+
const parsed = parseSessionConfigInput(ToolRouterUpdateSessionConfigSchema, config);
|
|
800
812
|
const body = transformToolRouterUpdateParams(parsed);
|
|
801
813
|
const expectedConfigVersion =
|
|
802
|
-
parsed.expectedConfigVersion === false
|
|
803
|
-
? undefined
|
|
804
|
-
: (parsed.expectedConfigVersion ?? this.configVersion);
|
|
814
|
+
parsed.expectedConfigVersion === false ? undefined : parsed.expectedConfigVersion;
|
|
805
815
|
if (expectedConfigVersion !== undefined) {
|
|
806
816
|
body.expected_config_version = expectedConfigVersion;
|
|
807
817
|
}
|
|
@@ -821,6 +831,16 @@ export class ToolRouterSession<
|
|
|
821
831
|
);
|
|
822
832
|
} catch (error) {
|
|
823
833
|
if (error instanceof ConflictError) {
|
|
834
|
+
const sessionConfigId = parsed.experimental?.sessionConfigId;
|
|
835
|
+
if (sessionConfigId !== undefined) {
|
|
836
|
+
throw new ComposioSessionConfigConflictError(
|
|
837
|
+
`Session ${this.sessionId} or Session config ${sessionConfigId} changed while the config was being applied; re-fetch the session and retry the update`,
|
|
838
|
+
{
|
|
839
|
+
cause: error,
|
|
840
|
+
meta: { sessionId: this.sessionId, sessionConfigId, expectedConfigVersion },
|
|
841
|
+
}
|
|
842
|
+
);
|
|
843
|
+
}
|
|
824
844
|
throw new ComposioSessionConfigConflictError(
|
|
825
845
|
expectedConfigVersion === undefined
|
|
826
846
|
? `Session ${this.sessionId} configuration changed while this update was in flight; re-fetch the session and retry the update`
|
|
@@ -839,6 +859,7 @@ export class ToolRouterSession<
|
|
|
839
859
|
this.preload = response.config.preload;
|
|
840
860
|
this.sandbox = response.config.workbench;
|
|
841
861
|
this.warnings = response.warnings ?? [];
|
|
862
|
+
this.experimental.sourceSessionConfig = getSourceSessionConfig(response);
|
|
842
863
|
return this.config;
|
|
843
864
|
}
|
|
844
865
|
|
|
@@ -1097,6 +1118,9 @@ export class ToolRouterSession<
|
|
|
1097
1118
|
: `${failedCount} out of ${allResults.length} tools failed`
|
|
1098
1119
|
: null,
|
|
1099
1120
|
successful: !hasAnyError,
|
|
1121
|
+
...(remoteResult?.premiumCharge !== undefined && {
|
|
1122
|
+
premiumCharge: remoteResult.premiumCharge,
|
|
1123
|
+
}),
|
|
1100
1124
|
};
|
|
1101
1125
|
}
|
|
1102
1126
|
}
|
package/src/models/Tools.ts
CHANGED
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
import { dereferenceJsonSchema } from '../utils/jsonSchema';
|
|
63
63
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
64
64
|
import { withCancellation } from '../utils/cancellation';
|
|
65
|
+
import { transformExecuteResponse } from '../utils/transformers/toolRouterResponseTransform';
|
|
65
66
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
66
67
|
|
|
67
68
|
const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
|
|
@@ -1257,12 +1258,13 @@ export class Tools<
|
|
|
1257
1258
|
requestOptions?.signal
|
|
1258
1259
|
);
|
|
1259
1260
|
|
|
1260
|
-
|
|
1261
|
+
const { data, error, logId, premiumCharge } = transformExecuteResponse(response);
|
|
1261
1262
|
let result: ToolExecuteResponse = {
|
|
1262
|
-
data
|
|
1263
|
-
error
|
|
1264
|
-
successful: !
|
|
1265
|
-
logId
|
|
1263
|
+
data,
|
|
1264
|
+
error,
|
|
1265
|
+
successful: !error,
|
|
1266
|
+
logId,
|
|
1267
|
+
...(premiumCharge !== undefined && { premiumCharge }),
|
|
1266
1268
|
};
|
|
1267
1269
|
|
|
1268
1270
|
// Apply afterExecute modifier if provided
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
import { ToolRouterTagsParamSchema } from './toolRouter.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Params for `composio.sessionConfigs.list()`. The backend owns the defaults:
|
|
6
|
+
* active configs only, 20 per page, at most 100.
|
|
7
|
+
*/
|
|
8
|
+
export const SessionConfigListParamsSchema = z.object({
|
|
9
|
+
/** Case-insensitive substring match against the config name. */
|
|
10
|
+
search: z.string().optional(),
|
|
11
|
+
/** `true` returns only archived configs. Omitted returns active configs. */
|
|
12
|
+
archived: z.boolean().optional(),
|
|
13
|
+
/** Page size. The backend defaults to 20 and caps it at 100. */
|
|
14
|
+
limit: z.number().optional(),
|
|
15
|
+
/** `nextCursor` from a previous page. */
|
|
16
|
+
cursor: z.string().optional(),
|
|
17
|
+
});
|
|
18
|
+
export type SessionConfigListParams = z.infer<typeof SessionConfigListParamsSchema>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A saved Session config as listed by `composio.sessionConfigs.list()`.
|
|
22
|
+
*/
|
|
23
|
+
export const SessionConfigSummarySchema = z.object({
|
|
24
|
+
/** Stable `sc_…` identifier. */
|
|
25
|
+
id: z.string(),
|
|
26
|
+
/** Project-unique display name. */
|
|
27
|
+
name: z.string(),
|
|
28
|
+
archived: z.boolean(),
|
|
29
|
+
/** ISO 8601 timestamp. */
|
|
30
|
+
createdAt: z.string(),
|
|
31
|
+
/** ISO 8601 timestamp. */
|
|
32
|
+
updatedAt: z.string(),
|
|
33
|
+
});
|
|
34
|
+
export type SessionConfigSummary = z.infer<typeof SessionConfigSummarySchema>;
|
|
35
|
+
|
|
36
|
+
export const SessionConfigListResponseSchema = z.object({
|
|
37
|
+
items: z.array(SessionConfigSummarySchema),
|
|
38
|
+
/** Cursor for the next page, or `null` on the last page. */
|
|
39
|
+
nextCursor: z.string().nullable(),
|
|
40
|
+
});
|
|
41
|
+
export type SessionConfigListResponse = z.infer<typeof SessionConfigListResponseSchema>;
|
|
42
|
+
|
|
43
|
+
const SessionConfigTagPolicySchema = z.object({
|
|
44
|
+
enable: z.array(ToolRouterTagsParamSchema.element).optional(),
|
|
45
|
+
disable: z.array(ToolRouterTagsParamSchema.element).optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The access policy stored in a saved Session config, in the backend's
|
|
50
|
+
* `enable`/`disable` shape. Toolkit slug keys and tag names are kept exactly
|
|
51
|
+
* as the backend sends them.
|
|
52
|
+
*/
|
|
53
|
+
export const SessionConfigPolicySchema = z.object({
|
|
54
|
+
toolkits: z
|
|
55
|
+
.union([z.object({ enable: z.array(z.string()) }), z.object({ disable: z.array(z.string()) })])
|
|
56
|
+
.optional(),
|
|
57
|
+
/** Per-toolkit tool policy, keyed by toolkit slug. */
|
|
58
|
+
tools: z
|
|
59
|
+
.record(
|
|
60
|
+
z.string(),
|
|
61
|
+
z.union([
|
|
62
|
+
z.object({ enable: z.array(z.string()) }),
|
|
63
|
+
z.object({ disable: z.array(z.string()) }),
|
|
64
|
+
z.object({ tags: SessionConfigTagPolicySchema }),
|
|
65
|
+
])
|
|
66
|
+
)
|
|
67
|
+
.optional(),
|
|
68
|
+
/** Global tag policy. */
|
|
69
|
+
tags: SessionConfigTagPolicySchema.optional(),
|
|
70
|
+
});
|
|
71
|
+
export type SessionConfigPolicy = z.infer<typeof SessionConfigPolicySchema>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A saved Session config with its description and access policy, as returned
|
|
75
|
+
* by `composio.sessionConfigs.get()`.
|
|
76
|
+
*/
|
|
77
|
+
export const SessionConfigSchema = SessionConfigSummarySchema.extend({
|
|
78
|
+
description: z.string().nullable(),
|
|
79
|
+
config: SessionConfigPolicySchema,
|
|
80
|
+
});
|
|
81
|
+
export type SessionConfig = z.infer<typeof SessionConfigSchema>;
|
package/src/types/tool.types.ts
CHANGED
|
@@ -407,6 +407,8 @@ export const ToolExecuteResponseSchema = z.object({
|
|
|
407
407
|
successful: z.boolean(),
|
|
408
408
|
logId: z.string().optional(),
|
|
409
409
|
sessionInfo: z.unknown().optional(),
|
|
410
|
+
/** Actual premium usage charge when the Session opts into returning it. */
|
|
411
|
+
premiumCharge: z.unknown().optional(),
|
|
410
412
|
});
|
|
411
413
|
export type ToolExecuteResponse = z.infer<typeof ToolExecuteResponseSchema>;
|
|
412
414
|
|
|
@@ -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 premium usage policy for a Session. */
|
|
112
|
+
export const ToolRouterPremiumUsageSchema = 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 premium charge in Session tool responses. Controls
|
|
130
|
+
* visibility only; on update, any policy object still re-enables premium
|
|
131
|
+
* usage on a Session set to `false`.
|
|
132
|
+
*/
|
|
133
|
+
returnPremiumCharge: z.boolean().optional(),
|
|
134
|
+
})
|
|
135
|
+
.strict(),
|
|
136
|
+
]);
|
|
137
|
+
export type ToolRouterPremiumUsage = z.infer<typeof ToolRouterPremiumUsageSchema>;
|
|
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
|
+
premiumUsage: ToolRouterPremiumUsageSchema.optional().describe(
|
|
269
|
+
'Experimental premium usage policy. Omission permits eligible tools when the project allows premium 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 {ToolRouterPremiumUsage} [premiumUsage] - Experimental premium usage policy. The project must allow premium 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 hosted account; only these tools run on it. */
|
|
612
|
+
hostedAccount: 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 premium usage charge when the Session opts into returning it. */
|
|
634
|
+
premiumCharge: 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: {
|
|
@@ -744,8 +841,11 @@ export const ToolRouterUpdateExperimentalSchema = z
|
|
|
744
841
|
),
|
|
745
842
|
sessionConfigId: z
|
|
746
843
|
.string()
|
|
844
|
+
.min(1)
|
|
747
845
|
.optional()
|
|
748
|
-
.describe(
|
|
846
|
+
.describe(
|
|
847
|
+
"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"
|
|
848
|
+
),
|
|
749
849
|
})
|
|
750
850
|
.strict();
|
|
751
851
|
export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdateExperimentalSchema>;
|
|
@@ -758,6 +858,9 @@ export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdate
|
|
|
758
858
|
*/
|
|
759
859
|
export const ToolRouterUpdateSessionConfigSchema = z
|
|
760
860
|
.object({
|
|
861
|
+
premiumUsage: ToolRouterPremiumUsageSchema.optional().describe(
|
|
862
|
+
'Experimental premium usage policy. False disables it. Any supplied object, even one that only sets returnPremiumCharge, re-enables it. Omitted subfields keep their stored values.'
|
|
863
|
+
),
|
|
761
864
|
toolkits: z
|
|
762
865
|
.union([
|
|
763
866
|
ToolRouterToolkitsParamSchema,
|
|
@@ -843,11 +946,22 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
843
946
|
.union([z.number().int().positive(), z.literal(false)])
|
|
844
947
|
.optional()
|
|
845
948
|
.describe(
|
|
846
|
-
'Precondition sent as `expected_config_version`.
|
|
949
|
+
'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
950
|
),
|
|
848
951
|
})
|
|
849
952
|
.partial()
|
|
850
953
|
.superRefine((config, ctx) => {
|
|
954
|
+
// "Provided" means `!== undefined`, so `null` conflicts too.
|
|
955
|
+
if (config.experimental?.sessionConfigId !== undefined) {
|
|
956
|
+
addSessionConfigConflictIssue(
|
|
957
|
+
ctx,
|
|
958
|
+
[
|
|
959
|
+
config.toolkits !== undefined && 'toolkits',
|
|
960
|
+
config.tools !== undefined && 'tools',
|
|
961
|
+
config.tags !== undefined && 'tags',
|
|
962
|
+
].filter((field): field is string => field !== false)
|
|
963
|
+
);
|
|
964
|
+
}
|
|
851
965
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
852
966
|
ctx.addIssue({
|
|
853
967
|
code: z.ZodIssueCode.custom,
|
|
@@ -858,7 +972,35 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
858
972
|
}
|
|
859
973
|
});
|
|
860
974
|
|
|
861
|
-
|
|
975
|
+
/**
|
|
976
|
+
* Options for `session.update()`. `experimental.sessionConfigId` applies a
|
|
977
|
+
* saved Session config and cannot be combined with `toolkits`, `tools` or
|
|
978
|
+
* `tags` (including `null`).
|
|
979
|
+
*/
|
|
980
|
+
export type ToolRouterUpdateSessionConfig =
|
|
981
|
+
InlineAccessUpdateSessionConfig | SavedConfigUpdateSessionConfig;
|
|
982
|
+
|
|
983
|
+
type ParsedUpdateSessionConfig = z.infer<typeof ToolRouterUpdateSessionConfigSchema>;
|
|
984
|
+
type ParsedUpdateSessionExperimental = NonNullable<ParsedUpdateSessionConfig['experimental']>;
|
|
985
|
+
|
|
986
|
+
/** Update input that sets access inline and applies no saved Session config. */
|
|
987
|
+
type InlineAccessUpdateSessionConfig = Omit<ParsedUpdateSessionConfig, 'experimental'> & {
|
|
988
|
+
experimental?:
|
|
989
|
+
(Omit<ParsedUpdateSessionExperimental, 'sessionConfigId'> & { sessionConfigId?: never }) | null;
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
/** Update input that applies a saved Session config. */
|
|
993
|
+
type SavedConfigUpdateSessionConfig = Omit<
|
|
994
|
+
ParsedUpdateSessionConfig,
|
|
995
|
+
'toolkits' | 'tools' | 'tags' | 'experimental'
|
|
996
|
+
> & {
|
|
997
|
+
toolkits?: never;
|
|
998
|
+
tools?: never;
|
|
999
|
+
tags?: never;
|
|
1000
|
+
experimental: Omit<ParsedUpdateSessionExperimental, 'sessionConfigId'> & {
|
|
1001
|
+
sessionConfigId: string;
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
862
1004
|
|
|
863
1005
|
export type ToolRouterSessionUpdateFn = (
|
|
864
1006
|
config: ToolRouterUpdateSessionConfig
|
|
@@ -955,9 +1097,9 @@ export interface Session<
|
|
|
955
1097
|
sessionId: string;
|
|
956
1098
|
mcp: ToolRouterMCPServerConfig;
|
|
957
1099
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* `
|
|
1100
|
+
* The session's current configuration (policy snapshot and runtime
|
|
1101
|
+
* settings). Refreshed in place by `update()`. For saved, reusable Session
|
|
1102
|
+
* configs, see `composio.sessionConfigs`.
|
|
961
1103
|
*/
|
|
962
1104
|
config: ToolRouterSessionConfig;
|
|
963
1105
|
/** Stored preload configuration for this session. */
|