@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as telemetry } from "../Telemetry-
|
|
1
|
+
import { t as telemetry } from "../Telemetry-41JkqpZ7.mjs";
|
|
2
2
|
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-DNLhLg0W.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/models/Files.node.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as ComposioConfig } from "./composio-
|
|
1
|
+
import { ar as BaseComposioProvider } from "./customTool.types-CK408sI-.mjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-C-418N1P.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 {
|
|
1
|
+
import { Ea as ToolExecuteResponse, wa as ToolExecuteParams, xa as Tool } from "../../customTool.types-CK408sI-.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 {
|
|
1
|
+
import { Ea as ToolExecuteResponse, wa as ToolExecuteParams, xa as Tool } from "../../customTool.types-CK408sI-.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.22.0",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.mjs",
|
|
10
10
|
"publishConfig": {
|
|
@@ -110,10 +110,12 @@
|
|
|
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.8",
|
|
115
117
|
"tsdown": "^0.23.0",
|
|
116
|
-
"tsx": "^4.23.
|
|
118
|
+
"tsx": "^4.23.15",
|
|
117
119
|
"typedoc": "^0.28.20",
|
|
118
120
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
119
121
|
"vitest": "^5.0.1",
|
|
@@ -126,7 +128,7 @@
|
|
|
126
128
|
"@composio/client": "2.0.0-rc.8",
|
|
127
129
|
"@types/json-schema": "^7.0.15",
|
|
128
130
|
"is-fs-case-sensitive": "^2.0.0",
|
|
129
|
-
"openai": "^7.
|
|
131
|
+
"openai": "^7.21.0",
|
|
130
132
|
"picocolors": "^1.1.1",
|
|
131
133
|
"pusher-js": "^8.6.0",
|
|
132
134
|
"semver": "^7.8.5",
|
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
|
+
ToolRouterInstant,
|
|
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;
|
|
@@ -188,12 +195,35 @@ export type SessionPatchBody = Omit<
|
|
|
188
195
|
SessionPatchParams,
|
|
189
196
|
'toolkits' | 'tools' | 'tags' | 'auth_configs' | 'preload' | 'search' | 'execute'
|
|
190
197
|
>,
|
|
191
|
-
'manage_connections' | 'multi_account' | 'experimental'
|
|
198
|
+
'manage_connections' | 'multi_account' | 'experimental' | 'premium_usage'
|
|
192
199
|
> & {
|
|
193
200
|
manage_connections?: SessionPatchManageConnectionsBody | null;
|
|
194
201
|
multi_account?: SessionPatchMultiAccountBody | null;
|
|
195
202
|
experimental?: SessionPatchExperimentalBody | null;
|
|
196
203
|
expected_config_version?: number;
|
|
204
|
+
instant?: SessionInstantBody;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/** SDK-owned wire contract until the generated client adopts the Instant names. */
|
|
208
|
+
export type SessionInstantBody =
|
|
209
|
+
| false
|
|
210
|
+
| (Omit<Exclude<ToolRouterInstant, false>, 'returnInstantCharge'> & {
|
|
211
|
+
return_instant_charge?: boolean;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
export type SessionCreateBody = Omit<SessionCreateParams, 'premium_usage'> & {
|
|
215
|
+
instant?: SessionInstantBody;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const transformToolRouterInstantParams = (config: ToolRouterInstant): SessionInstantBody => {
|
|
219
|
+
if (config === false) return false;
|
|
220
|
+
return {
|
|
221
|
+
...(config.toolkits !== undefined && { toolkits: config.toolkits }),
|
|
222
|
+
...(config.tools !== undefined && { tools: config.tools }),
|
|
223
|
+
...(config.returnInstantCharge !== undefined && {
|
|
224
|
+
return_instant_charge: config.returnInstantCharge,
|
|
225
|
+
}),
|
|
226
|
+
};
|
|
197
227
|
};
|
|
198
228
|
|
|
199
229
|
export const transformToolRouterUpdateManageConnectionsParams = (
|
|
@@ -276,7 +306,7 @@ export const transformToolRouterUpdateSandboxParams = (
|
|
|
276
306
|
export const transformToolRouterUpdateWorkbenchParams = transformToolRouterUpdateSandboxParams;
|
|
277
307
|
|
|
278
308
|
export const transformToolRouterMultiAccountParams = (
|
|
279
|
-
params?:
|
|
309
|
+
params?: ParsedCreateSessionConfig['multiAccount']
|
|
280
310
|
): SessionCreateParams.MultiAccount | undefined => {
|
|
281
311
|
if (!params) {
|
|
282
312
|
return undefined;
|
|
@@ -301,7 +331,7 @@ export const transformToolRouterMultiAccountParams = (
|
|
|
301
331
|
};
|
|
302
332
|
|
|
303
333
|
export const transformToolRouterToolkitsParams = (
|
|
304
|
-
params?:
|
|
334
|
+
params?: ParsedCreateSessionConfig['toolkits']
|
|
305
335
|
): SessionCreateParams.Enable | SessionCreateParams.Disable | undefined => {
|
|
306
336
|
if (!params) {
|
|
307
337
|
return undefined;
|
|
@@ -321,10 +351,10 @@ export const transformToolRouterToolkitsParams = (
|
|
|
321
351
|
* including `null` (remove the stored override) and empty collections (an
|
|
322
352
|
* empty toolkit allowlist denies every app toolkit). The
|
|
323
353
|
* `expectedConfigVersion` option is not a body field here: the session
|
|
324
|
-
*
|
|
354
|
+
* adds it only when the caller explicitly supplies a numeric version.
|
|
325
355
|
*/
|
|
326
356
|
export const transformToolRouterUpdateParams = (
|
|
327
|
-
config:
|
|
357
|
+
config: ParsedUpdateSessionConfig
|
|
328
358
|
): SessionPatchBody => {
|
|
329
359
|
const params: SessionPatchBody = {};
|
|
330
360
|
|
|
@@ -332,6 +362,9 @@ export const transformToolRouterUpdateParams = (
|
|
|
332
362
|
params.toolkits =
|
|
333
363
|
config.toolkits === null ? null : transformToolRouterToolkitsParams(config.toolkits);
|
|
334
364
|
}
|
|
365
|
+
if (config.instant !== undefined) {
|
|
366
|
+
params.instant = transformToolRouterInstantParams(config.instant);
|
|
367
|
+
}
|
|
335
368
|
if (config.tools !== undefined) {
|
|
336
369
|
params.tools = config.tools === null ? null : transformToolRouterToolsParams(config.tools);
|
|
337
370
|
}
|
|
@@ -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
|
+
};
|
|
@@ -45,15 +45,6 @@ export class AuthConfigs {
|
|
|
45
45
|
telemetry.instrument(this, 'AuthConfigs');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* Protected getter for the client instance.
|
|
50
|
-
* This is primarily used for testing purposes.
|
|
51
|
-
* @protected
|
|
52
|
-
*/
|
|
53
|
-
protected getClient(): ComposioClient {
|
|
54
|
-
return this.client;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
48
|
/**
|
|
58
49
|
* Lists authentication configurations based on provided filter criteria.
|
|
59
50
|
*
|
|
@@ -27,8 +27,7 @@ import { ConnectionRequest, ConnectionRequestState } from '../types/connectionRe
|
|
|
27
27
|
* @param {string} connectedAccountId - The ID of the connected account
|
|
28
28
|
* @param {ConnectedAccountStatus} [status] - Initial status of the connection
|
|
29
29
|
* @param {string | null} [redirectUrl] - OAuth redirect URL if applicable
|
|
30
|
-
* @returns {
|
|
31
|
-
* Connection request object with state and methods
|
|
30
|
+
* @returns {ConnectionRequest} Connection request object with state and methods
|
|
32
31
|
*/
|
|
33
32
|
export function createConnectionRequest(
|
|
34
33
|
client: ComposioClient,
|
|
@@ -36,13 +35,22 @@ export function createConnectionRequest(
|
|
|
36
35
|
status?: ConnectedAccountStatus,
|
|
37
36
|
redirectUrl?: string | null
|
|
38
37
|
): ConnectionRequest {
|
|
39
|
-
|
|
38
|
+
// `waitForConnection` records each observed status on this same object, so
|
|
39
|
+
// `request.status` and `toJSON()` never disagree.
|
|
40
|
+
const request: ConnectionRequest = {
|
|
40
41
|
id: connectedAccountId,
|
|
41
42
|
status: status || ConnectedAccountStatuses.INITIATED,
|
|
42
43
|
redirectUrl,
|
|
44
|
+
waitForConnection,
|
|
45
|
+
toJSON: (): ConnectionRequestState => ({
|
|
46
|
+
id: request.id,
|
|
47
|
+
status: request.status,
|
|
48
|
+
redirectUrl: request.redirectUrl,
|
|
49
|
+
}),
|
|
50
|
+
toString: () => JSON.stringify(request.toJSON(), null, 2),
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
telemetry.instrument(
|
|
53
|
+
telemetry.instrument(request, 'ConnectionRequest');
|
|
46
54
|
|
|
47
55
|
/**
|
|
48
56
|
* Waits for the connection request to complete and become active.
|
|
@@ -87,7 +95,7 @@ export function createConnectionRequest(
|
|
|
87
95
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ''}`,
|
|
88
96
|
{
|
|
89
97
|
meta: {
|
|
90
|
-
connectedAccountId:
|
|
98
|
+
connectedAccountId: request.id,
|
|
91
99
|
status: response.status,
|
|
92
100
|
statusReason: response.status_reason,
|
|
93
101
|
},
|
|
@@ -97,19 +105,19 @@ export function createConnectionRequest(
|
|
|
97
105
|
};
|
|
98
106
|
|
|
99
107
|
try {
|
|
100
|
-
const response = await client.connectedAccounts.retrieve(
|
|
108
|
+
const response = await client.connectedAccounts.retrieve(request.id);
|
|
109
|
+
request.status = response.status;
|
|
101
110
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
102
|
-
state.status = ConnectedAccountStatuses.ACTIVE;
|
|
103
111
|
return transformConnectedAccountResponse(response);
|
|
104
112
|
}
|
|
105
113
|
failIfTerminal(response);
|
|
106
114
|
} catch (error) {
|
|
107
115
|
if (error instanceof ComposioClient.NotFoundError) {
|
|
108
116
|
throw new ComposioConnectedAccountNotFoundError(
|
|
109
|
-
`Connected account with id ${
|
|
117
|
+
`Connected account with id ${request.id} not found`,
|
|
110
118
|
{
|
|
111
119
|
meta: {
|
|
112
|
-
connectedAccountId:
|
|
120
|
+
connectedAccountId: request.id,
|
|
113
121
|
},
|
|
114
122
|
}
|
|
115
123
|
);
|
|
@@ -123,9 +131,9 @@ export function createConnectionRequest(
|
|
|
123
131
|
|
|
124
132
|
while (Date.now() - start < timeout) {
|
|
125
133
|
try {
|
|
126
|
-
const response = await client.connectedAccounts.retrieve(
|
|
134
|
+
const response = await client.connectedAccounts.retrieve(request.id);
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
request.status = response.status;
|
|
129
137
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
130
138
|
return transformConnectedAccountResponse(response);
|
|
131
139
|
}
|
|
@@ -138,13 +146,8 @@ export function createConnectionRequest(
|
|
|
138
146
|
}
|
|
139
147
|
}
|
|
140
148
|
|
|
141
|
-
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${
|
|
149
|
+
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${request.id}`);
|
|
142
150
|
}
|
|
143
151
|
|
|
144
|
-
return
|
|
145
|
-
...state,
|
|
146
|
-
waitForConnection,
|
|
147
|
-
toJSON: () => ({ ...state }),
|
|
148
|
-
toString: () => JSON.stringify(state, null, 2),
|
|
149
|
-
};
|
|
152
|
+
return request;
|
|
150
153
|
}
|
package/src/models/Logs.ts
CHANGED
|
@@ -46,7 +46,7 @@ export class Logs {
|
|
|
46
46
|
* pagination.
|
|
47
47
|
*
|
|
48
48
|
* @param {LogSearchParams} [params] - Filters, `timeRange`, `limit` and `cursor`
|
|
49
|
-
* @returns {Promise<LogSearchResponse>} Matching logs and the next cursor
|
|
49
|
+
* @returns {Promise<LogSearchResponse>} Matching logs and the next cursor. Charged calls include `metadata.instant_charge` as an exact USD string.
|
|
50
50
|
* @throws {ValidationError} If the params fail validation
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
@@ -83,7 +83,7 @@ export class Logs {
|
|
|
83
83
|
* source and raw `data`).
|
|
84
84
|
*
|
|
85
85
|
* @param {string} id - The log id
|
|
86
|
-
* @returns {Promise<ToolExecutionLogDetail>} The log detail
|
|
86
|
+
* @returns {Promise<ToolExecutionLogDetail>} The log detail, with an optional exact USD charge in `metadata.instant_charge`
|
|
87
87
|
*
|
|
88
88
|
* @example
|
|
89
89
|
* ```typescript
|
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
|
}
|