@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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as ComposioConfig } from "./composio-
|
|
1
|
+
import { rr as BaseComposioProvider } from "./customTool.types-D_w21L56.mjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-BTZsFajb.mjs";
|
|
3
3
|
//#region src/utils/config-defaults/types.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Configuration defaults for Composio.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Sa as
|
|
1
|
+
import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.mjs";
|
|
2
2
|
import ComposioClient from "@composio/client";
|
|
3
3
|
//#region src/utils/modifiers/FileToolModifier.node.d.ts
|
|
4
4
|
export declare class FileToolModifier {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as logger } from "../../SsrfErrors-DiQldIdC.mjs";
|
|
2
|
-
import { g as ComposioRequestCancelledError } from "../../errors-
|
|
2
|
+
import { g as ComposioRequestCancelledError } from "../../errors-Dyiu3ifQ.mjs";
|
|
3
3
|
import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-CdGSABoq.mjs";
|
|
4
4
|
import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-DWFpnsj2.mjs";
|
|
5
|
-
import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-
|
|
5
|
+
import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-DV8CIi52.mjs";
|
|
6
6
|
import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-DNLhLg0W.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/utils/modifiers/FileToolModifier.node.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Sa as
|
|
1
|
+
import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.mjs";
|
|
2
2
|
import ComposioClient from "@composio/client";
|
|
3
3
|
//#region src/utils/modifiers/FileToolModifier.workerd.d.ts
|
|
4
4
|
export declare class FileToolModifier {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22.22.3"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.21.0",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.mjs",
|
|
10
10
|
"publishConfig": {
|
|
@@ -110,8 +110,10 @@
|
|
|
110
110
|
],
|
|
111
111
|
"license": "ISC",
|
|
112
112
|
"devDependencies": {
|
|
113
|
+
"@hono/node-server": "^2.1.1",
|
|
113
114
|
"@type-challenges/utils": "^0.1.1",
|
|
114
115
|
"@types/semver": "^7.8.0",
|
|
116
|
+
"hono": "^4.13.7",
|
|
115
117
|
"tsdown": "^0.23.0",
|
|
116
118
|
"tsx": "^4.23.13",
|
|
117
119
|
"typedoc": "^0.28.20",
|
package/src/composio.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { Experimental } from './models/Experimental';
|
|
|
10
10
|
import { MCP } from './models/MCP';
|
|
11
11
|
import { Webhooks } from './models/Webhooks';
|
|
12
12
|
import { Logs } from './models/Logs';
|
|
13
|
+
import { SessionConfigs } from './models/SessionConfigs';
|
|
13
14
|
import { Keyring } from './models/Keyring';
|
|
14
15
|
import { telemetry } from './telemetry/Telemetry';
|
|
15
16
|
import {
|
|
@@ -362,6 +363,12 @@ export class Composio<
|
|
|
362
363
|
* `composio.create(...)` method is kept as an alias.
|
|
363
364
|
*/
|
|
364
365
|
sessions: Sessions<unknown, unknown, TProvider>;
|
|
366
|
+
/**
|
|
367
|
+
* Read the project's saved Session configs. Apply one with
|
|
368
|
+
* `experimental.sessionConfigId` on `sessions.create()` or `session.update()`.
|
|
369
|
+
* Requires Session configs to be enabled for the project.
|
|
370
|
+
*/
|
|
371
|
+
sessionConfigs: SessionConfigs;
|
|
365
372
|
/**
|
|
366
373
|
* Legacy alias for `composio.sessions`.
|
|
367
374
|
* @deprecated Use `composio.sessions` instead — `toolRouter` was renamed to `sessions` and is kept only for backwards compatibility. Prefer `composio.sessions`; do not generate new code against `composio.toolRouter`.
|
|
@@ -549,6 +556,7 @@ export class Composio<
|
|
|
549
556
|
this.experimental = new Experimental(this.client);
|
|
550
557
|
this.sessions = new Sessions(this.client, this.config);
|
|
551
558
|
this.toolRouter = this.sessions;
|
|
559
|
+
this.sessionConfigs = new SessionConfigs(this.client);
|
|
552
560
|
|
|
553
561
|
/**
|
|
554
562
|
* Initialize session aliases.
|
|
@@ -32,11 +32,15 @@ export class ComposioMCPDestinationError extends ComposioError {
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Thrown when a session update is rejected with HTTP 409 because the session
|
|
35
|
-
* configuration changed since it was last read
|
|
36
|
-
* precondition
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
35
|
+
* configuration changed since it was last read, for example when an
|
|
36
|
+
* `expectedConfigVersion` precondition passed to `update()` is stale. The
|
|
37
|
+
* local session object is left as it was before the call. Re-fetch the session
|
|
38
|
+
* with `sessions.use(sessionId)` and retry the update against the fresh
|
|
39
|
+
* `configVersion`.
|
|
40
|
+
*
|
|
41
|
+
* Applying a saved Session config with `experimental.sessionConfigId` can
|
|
42
|
+
* also conflict when the session or the config changes while the update is
|
|
43
|
+
* applied; `meta.sessionConfigId` then names the config.
|
|
40
44
|
*/
|
|
41
45
|
export class ComposioSessionConfigConflictError extends ComposioError {
|
|
42
46
|
constructor(
|
|
@@ -49,7 +53,7 @@ export class ComposioSessionConfigConflictError extends ComposioError {
|
|
|
49
53
|
statusCode: 409,
|
|
50
54
|
possibleFixes: options.possibleFixes ?? [
|
|
51
55
|
'Re-fetch the session with `composio.sessions.use(sessionId)` to observe the current configVersion, then retry the update',
|
|
52
|
-
'
|
|
56
|
+
'Omit `expectedConfigVersion` to apply the update regardless of concurrent changes (last writer wins)',
|
|
53
57
|
],
|
|
54
58
|
});
|
|
55
59
|
this.name = 'ComposioSessionConfigConflictError';
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export { RemoteFile } from './models/RemoteFile';
|
|
|
54
54
|
export { createConnectionRequest } from './models/ConnectionRequest';
|
|
55
55
|
export { ToolRouterSession } from './models/ToolRouterSession';
|
|
56
56
|
export { Sessions } from './models/Sessions';
|
|
57
|
+
export { SessionConfigs } from './models/SessionConfigs';
|
|
57
58
|
export * from './types/provider.types';
|
|
58
59
|
export * from './types/customTool.types';
|
|
59
60
|
export * from './types/tool.types';
|
|
@@ -73,6 +74,7 @@ export * from './types/mcp.types';
|
|
|
73
74
|
export * from './types/files.types';
|
|
74
75
|
export * from './types/connectionRequest.types';
|
|
75
76
|
export * from './types/toolRouter.types';
|
|
77
|
+
export * from './types/sessionConfigs.types';
|
|
76
78
|
export * from './types/ToolRouterSessionFilesMount.types';
|
|
77
79
|
export * from './types/requestOptions.types';
|
|
78
80
|
export * as constants from './utils/constants';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod/v3';
|
|
2
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
3
|
+
|
|
4
|
+
const SESSION_CONFIG_CONFLICT_MARKER = 'sessionConfigConflict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Adds the issue raised when a saved Session config (`experimental.sessionConfigId`)
|
|
8
|
+
* is combined with inline access fields. `fields` lists every conflicting
|
|
9
|
+
* field that was provided; nothing is added when it is empty.
|
|
10
|
+
*/
|
|
11
|
+
export const addSessionConfigConflictIssue = (ctx: z.RefinementCtx, fields: string[]): void => {
|
|
12
|
+
if (fields.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
ctx.addIssue({
|
|
16
|
+
code: z.ZodIssueCode.custom,
|
|
17
|
+
message: `experimental.sessionConfigId cannot be combined with ${fields.join(', ')}. A saved Session config sets the session's toolkit, tool and tag access; remove ${fields.length === 1 ? 'that field' : 'those fields'} or sessionConfigId`,
|
|
18
|
+
path: ['experimental', 'sessionConfigId'],
|
|
19
|
+
params: { [SESSION_CONFIG_CONFLICT_MARKER]: true },
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parses session create or update input. A saved Session config combined with
|
|
25
|
+
* inline access fields throws `ValidationError`; any other failure rethrows the
|
|
26
|
+
* original `ZodError`, as `schema.parse()` would.
|
|
27
|
+
*/
|
|
28
|
+
export const parseSessionConfigInput = <TSchema extends z.ZodTypeAny>(
|
|
29
|
+
schema: TSchema,
|
|
30
|
+
input: unknown
|
|
31
|
+
): z.output<TSchema> => {
|
|
32
|
+
const result = schema.safeParse(input);
|
|
33
|
+
if (result.success) {
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
const isConflict = result.error.issues.some(
|
|
37
|
+
issue => issue.code === z.ZodIssueCode.custom && issue.params?.[SESSION_CONFIG_CONFLICT_MARKER]
|
|
38
|
+
);
|
|
39
|
+
if (isConflict) {
|
|
40
|
+
throw new ValidationError('Invalid session config', { cause: result.error });
|
|
41
|
+
}
|
|
42
|
+
throw result.error;
|
|
43
|
+
};
|
|
@@ -8,18 +8,25 @@ import {
|
|
|
8
8
|
ToolRouterConfigToolsSchema,
|
|
9
9
|
ToolRouterToolsParam,
|
|
10
10
|
ToolRouterConfigManageConnectionsSchema,
|
|
11
|
-
|
|
11
|
+
ToolRouterCreateSessionConfigSchema,
|
|
12
12
|
ToolRouterToolkitsParamSchema,
|
|
13
13
|
ToolRouterToolkitsDisabledConfigSchema,
|
|
14
14
|
ToolRouterToolkitsEnabledConfigSchema,
|
|
15
|
-
|
|
15
|
+
ToolRouterUpdateSessionConfigSchema,
|
|
16
16
|
ToolRouterUpdateManageConnectionsConfig,
|
|
17
17
|
ToolRouterUpdateManageConnectionsSchema,
|
|
18
18
|
ToolRouterUpdateExperimentalConfig,
|
|
19
19
|
ToolRouterSandboxConfig,
|
|
20
|
+
ToolRouterPremiumUsage,
|
|
20
21
|
} from '../types/toolRouter.types';
|
|
21
22
|
import { ValidationError } from '../errors';
|
|
22
23
|
import { z } from 'zod';
|
|
24
|
+
import type { TypeOf } from 'zod/v3';
|
|
25
|
+
|
|
26
|
+
/** Parsed create input; the public `ToolRouterCreateSessionConfig` is a union over it. */
|
|
27
|
+
type ParsedCreateSessionConfig = TypeOf<typeof ToolRouterCreateSessionConfigSchema>;
|
|
28
|
+
/** Parsed update input; the public `ToolRouterUpdateSessionConfig` is a union over it. */
|
|
29
|
+
type ParsedUpdateSessionConfig = TypeOf<typeof ToolRouterUpdateSessionConfigSchema>;
|
|
23
30
|
|
|
24
31
|
export const transformToolRouterToolsParams = (
|
|
25
32
|
params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools> | undefined
|
|
@@ -120,8 +127,8 @@ export const transformToolRouterManageConnectionsParams = (
|
|
|
120
127
|
};
|
|
121
128
|
|
|
122
129
|
export const resolveToolRouterSandboxConfig = (
|
|
123
|
-
config: Pick<
|
|
124
|
-
):
|
|
130
|
+
config: Pick<ParsedCreateSessionConfig, 'sandbox' | 'workbench'>
|
|
131
|
+
): ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench'] => {
|
|
125
132
|
if (config.sandbox !== undefined && config.workbench !== undefined) {
|
|
126
133
|
throw new ValidationError(
|
|
127
134
|
'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.'
|
|
@@ -131,7 +138,7 @@ export const resolveToolRouterSandboxConfig = (
|
|
|
131
138
|
};
|
|
132
139
|
|
|
133
140
|
export const transformToolRouterSandboxParams = (
|
|
134
|
-
params?:
|
|
141
|
+
params?: ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench']
|
|
135
142
|
): SessionCreateParams.Workbench | undefined => {
|
|
136
143
|
if (!params) {
|
|
137
144
|
return undefined;
|
|
@@ -196,6 +203,21 @@ export type SessionPatchBody = Omit<
|
|
|
196
203
|
expected_config_version?: number;
|
|
197
204
|
};
|
|
198
205
|
|
|
206
|
+
export type SessionPremiumUsageBody = NonNullable<SessionPatchParams['premium_usage']>;
|
|
207
|
+
|
|
208
|
+
export const transformToolRouterPremiumUsageParams = (
|
|
209
|
+
config: ToolRouterPremiumUsage
|
|
210
|
+
): SessionPremiumUsageBody => {
|
|
211
|
+
if (config === false) return false;
|
|
212
|
+
return {
|
|
213
|
+
...(config.toolkits !== undefined && { toolkits: config.toolkits }),
|
|
214
|
+
...(config.tools !== undefined && { tools: config.tools }),
|
|
215
|
+
...(config.returnPremiumCharge !== undefined && {
|
|
216
|
+
return_premium_charge: config.returnPremiumCharge,
|
|
217
|
+
}),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
199
221
|
export const transformToolRouterUpdateManageConnectionsParams = (
|
|
200
222
|
params: boolean | ToolRouterUpdateManageConnectionsConfig
|
|
201
223
|
): SessionPatchManageConnectionsBody => {
|
|
@@ -276,7 +298,7 @@ export const transformToolRouterUpdateSandboxParams = (
|
|
|
276
298
|
export const transformToolRouterUpdateWorkbenchParams = transformToolRouterUpdateSandboxParams;
|
|
277
299
|
|
|
278
300
|
export const transformToolRouterMultiAccountParams = (
|
|
279
|
-
params?:
|
|
301
|
+
params?: ParsedCreateSessionConfig['multiAccount']
|
|
280
302
|
): SessionCreateParams.MultiAccount | undefined => {
|
|
281
303
|
if (!params) {
|
|
282
304
|
return undefined;
|
|
@@ -301,7 +323,7 @@ export const transformToolRouterMultiAccountParams = (
|
|
|
301
323
|
};
|
|
302
324
|
|
|
303
325
|
export const transformToolRouterToolkitsParams = (
|
|
304
|
-
params?:
|
|
326
|
+
params?: ParsedCreateSessionConfig['toolkits']
|
|
305
327
|
): SessionCreateParams.Enable | SessionCreateParams.Disable | undefined => {
|
|
306
328
|
if (!params) {
|
|
307
329
|
return undefined;
|
|
@@ -321,10 +343,10 @@ export const transformToolRouterToolkitsParams = (
|
|
|
321
343
|
* including `null` (remove the stored override) and empty collections (an
|
|
322
344
|
* empty toolkit allowlist denies every app toolkit). The
|
|
323
345
|
* `expectedConfigVersion` option is not a body field here: the session
|
|
324
|
-
*
|
|
346
|
+
* adds it only when the caller explicitly supplies a numeric version.
|
|
325
347
|
*/
|
|
326
348
|
export const transformToolRouterUpdateParams = (
|
|
327
|
-
config:
|
|
349
|
+
config: ParsedUpdateSessionConfig
|
|
328
350
|
): SessionPatchBody => {
|
|
329
351
|
const params: SessionPatchBody = {};
|
|
330
352
|
|
|
@@ -332,6 +354,9 @@ export const transformToolRouterUpdateParams = (
|
|
|
332
354
|
params.toolkits =
|
|
333
355
|
config.toolkits === null ? null : transformToolRouterToolkitsParams(config.toolkits);
|
|
334
356
|
}
|
|
357
|
+
if (config.premiumUsage !== undefined) {
|
|
358
|
+
params.premium_usage = transformToolRouterPremiumUsageParams(config.premiumUsage);
|
|
359
|
+
}
|
|
335
360
|
if (config.tools !== undefined) {
|
|
336
361
|
params.tools = config.tools === null ? null : transformToolRouterToolsParams(config.tools);
|
|
337
362
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SessionExperimental } from '../types/toolRouter.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads the saved Session config most recently applied to a session from a
|
|
5
|
+
* create, retrieve, attach or patch response. Copies only `id`.
|
|
6
|
+
*/
|
|
7
|
+
export const getSourceSessionConfig = (response: {
|
|
8
|
+
experimental?: { source_session_config?: { id: string } };
|
|
9
|
+
}): SessionExperimental['sourceSessionConfig'] => {
|
|
10
|
+
const source = response.experimental?.source_session_config;
|
|
11
|
+
return source ? { id: source.id } : undefined;
|
|
12
|
+
};
|
package/src/models/RemoteFile.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
ValidationError,
|
|
15
15
|
} from '../errors';
|
|
16
16
|
import { readResponseBodyWithLimit } from '../utils/readResponseBody';
|
|
17
|
+
import { safeBasename, untrustedBasename } from '../utils/safePath';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Represents a file stored in a tool router session's file mount.
|
|
@@ -77,9 +78,20 @@ export class RemoteFile {
|
|
|
77
78
|
return new RemoteFile(parsed.data);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Filename extracted from the mount path (e.g. "report.pdf" from "output/report.pdf").
|
|
83
|
+
*
|
|
84
|
+
* Deliberately non-throwing: this is a display value, and `downloadBytes()`
|
|
85
|
+
* reads it while constructing `RemoteFileDownloadError`. A validator here
|
|
86
|
+
* would replace a genuine download error with a validation error thrown from
|
|
87
|
+
* inside the error constructor. {@link save} validates instead, at the point
|
|
88
|
+
* the value actually becomes a path.
|
|
89
|
+
*
|
|
90
|
+
* Both `/` and `\` count as separators, as in the Python SDK, so a mount path
|
|
91
|
+
* crafted for a Windows target is reduced the same way on every platform.
|
|
92
|
+
*/
|
|
81
93
|
get filename(): string {
|
|
82
|
-
return
|
|
94
|
+
return untrustedBasename(this.mountRelativePath);
|
|
83
95
|
}
|
|
84
96
|
|
|
85
97
|
private downloadError(message: string, cause: unknown, response?: Response) {
|
|
@@ -163,6 +175,7 @@ export class RemoteFile {
|
|
|
163
175
|
* @param path - Local path to save the file. If omitted, saves to the Composio temp directory using the filename from the mount path.
|
|
164
176
|
* @returns The absolute path where the file was saved
|
|
165
177
|
* @throws Error if file system is not supported or the save fails
|
|
178
|
+
* @throws ValidationError if `path` is omitted and the mount path yields no usable filename
|
|
166
179
|
*/
|
|
167
180
|
async save(path?: string): Promise<string> {
|
|
168
181
|
if (!platform.supportsFileSystem) {
|
|
@@ -172,19 +185,23 @@ export class RemoteFile {
|
|
|
172
185
|
);
|
|
173
186
|
}
|
|
174
187
|
|
|
175
|
-
const content = await this.buffer();
|
|
176
188
|
const homeDir = platform.homedir();
|
|
177
189
|
if (!homeDir) {
|
|
178
190
|
throw new Error('Cannot determine save location: home directory is not available');
|
|
179
191
|
}
|
|
180
192
|
|
|
193
|
+
// An explicit `path` is the caller's own. The default branch builds a path
|
|
194
|
+
// out of `mountRelativePath`, a server-controlled response field, so it is
|
|
195
|
+
// validated first (SEC-316, mirroring the Python SDK): a value such as `""`,
|
|
196
|
+
// `"."` or `"foo/.."` would otherwise make `savePath` its own directory or
|
|
197
|
+
// the parent, and fail with a raw `EISDIR` only after `mkdirSync` had run.
|
|
198
|
+
const defaultDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
181
199
|
const savePath =
|
|
182
|
-
path ?? platform.joinPath(
|
|
200
|
+
path ?? platform.joinPath(defaultDir, safeBasename(this.mountRelativePath, 'mount path'));
|
|
201
|
+
|
|
202
|
+
const content = await this.buffer();
|
|
183
203
|
|
|
184
|
-
const dir =
|
|
185
|
-
path != null
|
|
186
|
-
? getParentDir(savePath)
|
|
187
|
-
: platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
204
|
+
const dir = path != null ? getParentDir(savePath) : defaultDir;
|
|
188
205
|
if (dir && !platform.existsSync(dir)) {
|
|
189
206
|
platform.mkdirSync(dir);
|
|
190
207
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The `composio.sessionConfigs` namespace: read the saved
|
|
3
|
+
* Session configs of the project.
|
|
4
|
+
*
|
|
5
|
+
* @module SessionConfigs
|
|
6
|
+
*/
|
|
7
|
+
import ComposioClient from '@composio/client';
|
|
8
|
+
import {
|
|
9
|
+
SessionConfig,
|
|
10
|
+
SessionConfigListParams,
|
|
11
|
+
SessionConfigListParamsSchema,
|
|
12
|
+
SessionConfigListResponse,
|
|
13
|
+
} from '../types/sessionConfigs.types';
|
|
14
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
15
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
16
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
17
|
+
import { withCancellation } from '../utils/cancellation';
|
|
18
|
+
import {
|
|
19
|
+
transformSessionConfig,
|
|
20
|
+
transformSessionConfigListResponse,
|
|
21
|
+
} from '../utils/transformers/sessionConfigs';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `composio.sessionConfigs` — saved, reusable Session configs.
|
|
25
|
+
*
|
|
26
|
+
* A Session config is a named access policy (`sc_…`) built in the Composio
|
|
27
|
+
* Dashboard under Sessions → Configs. Pass its id as
|
|
28
|
+
* `experimental.sessionConfigId` to `composio.sessions.create()` or
|
|
29
|
+
* `session.update()` to apply it.
|
|
30
|
+
*
|
|
31
|
+
* These endpoints require Session configs to be enabled for the project;
|
|
32
|
+
* otherwise the backend returns 403.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const { items } = await composio.sessionConfigs.list({ search: 'support' });
|
|
37
|
+
* const sessionConfig = await composio.sessionConfigs.get(items[0].id);
|
|
38
|
+
* const session = await composio.sessions.create('user_123', {
|
|
39
|
+
* experimental: { sessionConfigId: sessionConfig.id },
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export class SessionConfigs {
|
|
44
|
+
private client: ComposioClient;
|
|
45
|
+
|
|
46
|
+
constructor(client: ComposioClient) {
|
|
47
|
+
this.client = client;
|
|
48
|
+
telemetry.instrument(this, 'SessionConfigs');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* List the project's saved Session configs with cursor pagination.
|
|
53
|
+
*
|
|
54
|
+
* Omitting `archived` returns active configs; `archived: true` returns only
|
|
55
|
+
* archived ones. The backend defaults `limit` to 20 and caps it at 100.
|
|
56
|
+
*
|
|
57
|
+
* Requires Session configs to be enabled for the project.
|
|
58
|
+
*
|
|
59
|
+
* @param {SessionConfigListParams} [params] - `search`, `archived`, `limit` and `cursor`
|
|
60
|
+
* @returns {Promise<SessionConfigListResponse>} Config summaries and the next cursor
|
|
61
|
+
* @throws {ValidationError} If the params fail validation
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* let cursor: string | undefined;
|
|
66
|
+
* do {
|
|
67
|
+
* const page = await composio.sessionConfigs.list({ cursor });
|
|
68
|
+
* for (const item of page.items) console.log(item.id, item.name);
|
|
69
|
+
* cursor = page.nextCursor ?? undefined;
|
|
70
|
+
* } while (cursor);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async list(
|
|
74
|
+
params?: SessionConfigListParams,
|
|
75
|
+
requestOptions?: ComposioRequestOptions
|
|
76
|
+
): Promise<SessionConfigListResponse> {
|
|
77
|
+
const parsedParams = SessionConfigListParamsSchema.safeParse(params ?? {});
|
|
78
|
+
if (!parsedParams.success) {
|
|
79
|
+
throw new ValidationError('Failed to parse session config list params', {
|
|
80
|
+
cause: parsedParams.error,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const result = await withCancellation(
|
|
84
|
+
() => this.client.sessionConfigs.list(parsedParams.data, requestOptions),
|
|
85
|
+
requestOptions?.signal
|
|
86
|
+
);
|
|
87
|
+
return transformSessionConfigListResponse(result);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Retrieve one saved Session config with its description and access
|
|
92
|
+
* policy. A missing or cross-project id surfaces as the backend's 404.
|
|
93
|
+
*
|
|
94
|
+
* Requires Session configs to be enabled for the project.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} id - The `sc_…` id of the Session config
|
|
97
|
+
* @returns {Promise<SessionConfig>} The config and its policy
|
|
98
|
+
* @throws {ValidationError} If `id` is empty
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const sessionConfig = await composio.sessionConfigs.get('sc_abc123');
|
|
103
|
+
* console.log(sessionConfig.config.toolkits);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
async get(id: string, requestOptions?: ComposioRequestOptions): Promise<SessionConfig> {
|
|
107
|
+
// An empty id would request the collection path and return a list page.
|
|
108
|
+
if (id.trim() === '') {
|
|
109
|
+
throw new ValidationError('Session config id must be a non-empty string');
|
|
110
|
+
}
|
|
111
|
+
const result = await withCancellation(
|
|
112
|
+
() => this.client.sessionConfigs.retrieve(id, requestOptions),
|
|
113
|
+
requestOptions?.signal
|
|
114
|
+
);
|
|
115
|
+
return transformSessionConfig(result);
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -50,10 +50,13 @@ import {
|
|
|
50
50
|
transformToolRouterSandboxParams,
|
|
51
51
|
transformToolRouterToolkitsParams,
|
|
52
52
|
transformToolRouterMultiAccountParams,
|
|
53
|
+
transformToolRouterPremiumUsageParams,
|
|
53
54
|
resolveToolRouterSandboxConfig,
|
|
54
55
|
} from '../lib/toolRouterParams';
|
|
55
56
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
56
57
|
import { buildMCPServerConfig } from '../lib/toolRouterMcp';
|
|
58
|
+
import { parseSessionConfigInput } from '../lib/sessionConfigConflict';
|
|
59
|
+
import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
|
|
57
60
|
import { ToolRouterSession } from './ToolRouterSession';
|
|
58
61
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
59
62
|
import { withCancellation } from '../utils/cancellation';
|
|
@@ -189,6 +192,12 @@ export class ToolRouter<
|
|
|
189
192
|
* customToolkits: [myToolkit],
|
|
190
193
|
* },
|
|
191
194
|
* });
|
|
195
|
+
*
|
|
196
|
+
* // Start from a saved Session config instead of inline access fields
|
|
197
|
+
* const configured = await composio.sessions.create('user_123', {
|
|
198
|
+
* authConfigs: { github: 'ac_123' },
|
|
199
|
+
* experimental: { sessionConfigId: 'sc_123' },
|
|
200
|
+
* });
|
|
192
201
|
* ```
|
|
193
202
|
*/
|
|
194
203
|
// Overloads: passing `{ mcp: true }` surfaces `session.mcp` in the returned
|
|
@@ -209,7 +218,7 @@ export class ToolRouter<
|
|
|
209
218
|
config?: ToolRouterCreateSessionConfig,
|
|
210
219
|
requestOptions?: ComposioRequestOptions
|
|
211
220
|
): Promise<Session<TToolCollection, TTool, TProvider>> {
|
|
212
|
-
const routerConfig = ToolRouterCreateSessionConfigSchema
|
|
221
|
+
const routerConfig = parseSessionConfigInput(ToolRouterCreateSessionConfigSchema, config ?? {});
|
|
213
222
|
const isDirectToolsPreset = routerConfig.sessionPreset === SessionPreset.DIRECT_TOOLS;
|
|
214
223
|
|
|
215
224
|
// Extract custom tools/toolkits from experimental config
|
|
@@ -226,6 +235,10 @@ export class ToolRouter<
|
|
|
226
235
|
// Build the typed experimental payload for the backend
|
|
227
236
|
const experimentalPayload: SessionCreateParams['experimental'] = {};
|
|
228
237
|
|
|
238
|
+
if (routerConfig.experimental?.sessionConfigId !== undefined) {
|
|
239
|
+
experimentalPayload.session_config_id = routerConfig.experimental.sessionConfigId;
|
|
240
|
+
}
|
|
241
|
+
|
|
229
242
|
if (routerConfig.experimental?.assistivePrompt?.userTimezone) {
|
|
230
243
|
experimentalPayload.assistive_prompt_config = {
|
|
231
244
|
user_timezone: routerConfig.experimental.assistivePrompt.userTimezone,
|
|
@@ -259,6 +272,9 @@ export class ToolRouter<
|
|
|
259
272
|
auth_configs: routerConfig.authConfigs,
|
|
260
273
|
connected_accounts: connectedAccountsPayload,
|
|
261
274
|
toolkits: transformToolRouterToolkitsParams(routerConfig.toolkits),
|
|
275
|
+
...(routerConfig.premiumUsage !== undefined && {
|
|
276
|
+
premium_usage: transformToolRouterPremiumUsageParams(routerConfig.premiumUsage),
|
|
277
|
+
}),
|
|
262
278
|
tools: transformToolRouterToolsParams(routerConfig.tools),
|
|
263
279
|
tags: transformToolRouterTagsParams(routerConfig.tags),
|
|
264
280
|
manage_connections: transformToolRouterManageConnectionsParams(
|
|
@@ -302,7 +318,7 @@ export class ToolRouter<
|
|
|
302
318
|
this.config,
|
|
303
319
|
session.session_id,
|
|
304
320
|
this.createMCPServerConfig(session.mcp, routerConfig.mcp === true),
|
|
305
|
-
{ assistivePrompt },
|
|
321
|
+
{ assistivePrompt, sourceSessionConfig: getSourceSessionConfig(session) },
|
|
306
322
|
customToolsMap,
|
|
307
323
|
userId,
|
|
308
324
|
metadata
|
|
@@ -413,7 +429,7 @@ export class ToolRouter<
|
|
|
413
429
|
this.config,
|
|
414
430
|
session.session_id,
|
|
415
431
|
this.createMCPServerConfig(session.mcp, options?.mcp === true),
|
|
416
|
-
|
|
432
|
+
{ sourceSessionConfig: getSourceSessionConfig(session) },
|
|
417
433
|
customToolsMap,
|
|
418
434
|
userId,
|
|
419
435
|
metadata
|