@composio/core 0.19.0 → 0.20.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-CB5vm1Jc.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
- package/dist/{CustomTool-BMlZfJVz.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
- package/dist/{FileModifierErrors-BqFmpRsm.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{SsrfErrors-C91YhASE.mjs → SsrfErrors-DiQldIdC.mjs} +18 -7
- package/dist/{Telemetry-HlftxMx6.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-CXpfmiVo.mjs → cancellation-Dwa9lGHA.mjs} +2 -2
- package/dist/{composio-DLGaeN70.d.mts → composio-B36OXii1.d.mts} +2691 -119
- package/dist/{customTool.types-BAmEh3MB.d.mts → customTool.types-C436M_D0.d.mts} +431 -98
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +5 -2
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +7 -0
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +8 -1
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +77 -27
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +149 -12
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
- package/dist/{errors-BuEKehbI.mjs → errors-D_A4b2c2.mjs} +123 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-L7XD8UPr.mjs → fileUtils.node-DNLhLg0W.mjs} +4 -4
- package/dist/index.d.mts +264 -51
- package/dist/index.mjs +2338 -168
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-B6pBt9lO.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +1 -1
- package/dist/{ssrfGuard.node-B9xQB4za.mjs → ssrfGuard.node-BZ270bcu.mjs} +1 -1
- package/dist/{types-CxLPO0Xq.d.mts → types-Br3GBya5.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 +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +1 -1
- package/package.json +2 -2
- package/src/composio.ts +207 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolRouterErrors.ts +57 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +11 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +116 -29
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/ToolRouter.ts +42 -14
- package/src/models/ToolRouterSession.ts +120 -9
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +3 -1
- package/src/models/Triggers.ts +3 -88
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +17 -6
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +205 -11
- package/src/types/toolkit.types.ts +144 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/logger.ts +39 -7
- package/src/utils/sdk.ts +385 -22
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +106 -3
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
import { ValidationError } from '../errors/ValidationErrors';
|
|
22
22
|
import { ComposioAclOnlyForSharedError } from '../errors';
|
|
23
23
|
import { telemetry } from '../telemetry/Telemetry';
|
|
24
|
+
import { Usage } from './Usage';
|
|
25
|
+
import { CustomToolkits } from './CustomToolkits';
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Server-side 400 message the API uses to reject ACL writes against a
|
|
@@ -129,8 +131,33 @@ export async function updateConnectedAccountAcl(
|
|
|
129
131
|
export class Experimental {
|
|
130
132
|
private client: ComposioClient;
|
|
131
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Project-scoped usage metering (`summary()` / `breakdown()`).
|
|
136
|
+
* **Experimental — shape may change in future releases.**
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const summary = await composio.experimental.usage.summary();
|
|
141
|
+
* const byTool = await composio.experimental.usage.breakdown('tool_calls');
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
usage: Usage;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Register and manage project-owned custom toolkits (`upsert()` / `sync()` / `delete()`).
|
|
148
|
+
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* await composio.experimental.customToolkits.sync('CUSTOM_MY_TOOLKIT');
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
customToolkits: CustomToolkits;
|
|
156
|
+
|
|
132
157
|
constructor(client: ComposioClient) {
|
|
133
158
|
this.client = client;
|
|
159
|
+
this.usage = new Usage(client);
|
|
160
|
+
this.customToolkits = new CustomToolkits(client);
|
|
134
161
|
telemetry.instrument(this, 'Experimental');
|
|
135
162
|
}
|
|
136
163
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The `composio.keyring` namespace: the public transfer keys of
|
|
3
|
+
* the organization's customer-managed keyring.
|
|
4
|
+
*
|
|
5
|
+
* @module Keyring
|
|
6
|
+
*/
|
|
7
|
+
import ComposioClient from '@composio/client';
|
|
8
|
+
import { KeyringTransferKeysResponse } from '../types/keyring.types';
|
|
9
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
10
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
11
|
+
import { withCancellation } from '../utils/cancellation';
|
|
12
|
+
import { transformKeyringTransferKeysResponse } from '../utils/transformers/keyring';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `composio.keyring` — the organization's customer-managed keyring.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { activeKid, keys } = await composio.keyring.listTransferKeys();
|
|
20
|
+
* const sealingKey = keys.find(key => key.kid === activeKid);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class Keyring {
|
|
24
|
+
private client: ComposioClient;
|
|
25
|
+
|
|
26
|
+
constructor(client: ComposioClient) {
|
|
27
|
+
this.client = client;
|
|
28
|
+
telemetry.instrument(this, 'Keyring');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Lists the public transfer keys of the organization's active customer
|
|
33
|
+
* keyring, the keys a secret is sealed to before it is sent to Composio.
|
|
34
|
+
*
|
|
35
|
+
* Always seal new secrets to the key whose `kid` is `activeKid`: a JWE with
|
|
36
|
+
* `RSA-OAEP-256` key management, `A256GCM` content encryption, and the
|
|
37
|
+
* `kid` in the protected header. Older keys stay listed so values sealed to
|
|
38
|
+
* them remain openable.
|
|
39
|
+
*
|
|
40
|
+
* The organization behind the API key must have an ACTIVE customer keyring
|
|
41
|
+
* instance; otherwise the API answers 404.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { CompactEncrypt, importJWK } from 'jose';
|
|
48
|
+
*
|
|
49
|
+
* const { activeKid, keys } = await composio.keyring.listTransferKeys();
|
|
50
|
+
* const jwk = keys.find(key => key.kid === activeKid)!;
|
|
51
|
+
* const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))
|
|
52
|
+
* .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM', kid: activeKid })
|
|
53
|
+
* .encrypt(await importJWK(jwk, 'RSA-OAEP-256'));
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async listTransferKeys(
|
|
57
|
+
requestOptions?: ComposioRequestOptions
|
|
58
|
+
): Promise<KeyringTransferKeysResponse> {
|
|
59
|
+
const result = await withCancellation(
|
|
60
|
+
() => this.client.keyring.listTransferKeys(requestOptions),
|
|
61
|
+
requestOptions?.signal
|
|
62
|
+
);
|
|
63
|
+
return transformKeyringTransferKeysResponse(result);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The `composio.logs` namespace: search and inspect
|
|
3
|
+
* tool-execution logs for the project.
|
|
4
|
+
*
|
|
5
|
+
* @module Logs
|
|
6
|
+
*/
|
|
7
|
+
import ComposioClient from '@composio/client';
|
|
8
|
+
import {
|
|
9
|
+
LogSearchParams,
|
|
10
|
+
LogSearchParamsSchema,
|
|
11
|
+
LogSearchResponse,
|
|
12
|
+
ToolExecutionLogDetail,
|
|
13
|
+
} from '../types/logs.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
|
+
transformLogSearchParams,
|
|
20
|
+
transformLogSearchResponse,
|
|
21
|
+
transformToolExecutionLogDetail,
|
|
22
|
+
} from '../utils/transformers/logs';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `composio.logs` — tool-execution logs.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const { logs, nextCursor } = await composio.logs.search({
|
|
30
|
+
* filters: [{ field: 'toolkit_slug', operator: '==', value: 'github' }],
|
|
31
|
+
* limit: 20,
|
|
32
|
+
* });
|
|
33
|
+
* const detail = await composio.logs.get(logs[0].id);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class Logs {
|
|
37
|
+
private client: ComposioClient;
|
|
38
|
+
|
|
39
|
+
constructor(client: ComposioClient) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
telemetry.instrument(this, 'Logs');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Search tool-execution logs with filters, a time range and cursor
|
|
46
|
+
* pagination.
|
|
47
|
+
*
|
|
48
|
+
* @param {LogSearchParams} [params] - Filters, `timeRange`, `limit` and `cursor`
|
|
49
|
+
* @returns {Promise<LogSearchResponse>} Matching logs and the next cursor
|
|
50
|
+
* @throws {ValidationError} If the params fail validation
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const { logs } = await composio.logs.search({
|
|
55
|
+
* filters: [
|
|
56
|
+
* { field: 'status', operator: '==', value: 'failed' },
|
|
57
|
+
* { field: 'user_id', operator: '==', value: 'user_123' },
|
|
58
|
+
* ],
|
|
59
|
+
* timeRange: { from: Date.now() - 24 * 60 * 60 * 1000, to: Date.now() },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
async search(
|
|
64
|
+
params?: LogSearchParams,
|
|
65
|
+
requestOptions?: ComposioRequestOptions
|
|
66
|
+
): Promise<LogSearchResponse> {
|
|
67
|
+
const parsedParams = LogSearchParamsSchema.safeParse(params ?? {});
|
|
68
|
+
if (!parsedParams.success) {
|
|
69
|
+
throw new ValidationError('Failed to parse log search params', {
|
|
70
|
+
cause: parsedParams.error,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const body = transformLogSearchParams(parsedParams.data);
|
|
74
|
+
const result = await withCancellation(
|
|
75
|
+
() => this.client.logs.createToolExecution(body, requestOptions),
|
|
76
|
+
requestOptions?.signal
|
|
77
|
+
);
|
|
78
|
+
return transformLogSearchResponse(result);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Retrieve one tool-execution log with its full detail (timings, context,
|
|
83
|
+
* source and raw `data`).
|
|
84
|
+
*
|
|
85
|
+
* @param {string} id - The log id
|
|
86
|
+
* @returns {Promise<ToolExecutionLogDetail>} The log detail
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const log = await composio.logs.get('log_abc123');
|
|
91
|
+
* console.log(log.status, log.timings?.endTime);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
async get(id: string, requestOptions?: ComposioRequestOptions): Promise<ToolExecutionLogDetail> {
|
|
95
|
+
const result = await withCancellation(
|
|
96
|
+
() => this.client.logs.retrieveToolExecution(id, requestOptions),
|
|
97
|
+
requestOptions?.signal
|
|
98
|
+
);
|
|
99
|
+
return transformToolExecutionLogDetail(result);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
resolveToolRouterSandboxConfig,
|
|
54
54
|
} from '../lib/toolRouterParams';
|
|
55
55
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
56
|
+
import { buildMCPServerConfig } from '../lib/toolRouterMcp';
|
|
56
57
|
import { ToolRouterSession } from './ToolRouterSession';
|
|
57
58
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
58
59
|
import { withCancellation } from '../utils/cancellation';
|
|
@@ -131,20 +132,30 @@ export class ToolRouter<
|
|
|
131
132
|
telemetry.instrument(this, 'ToolRouter');
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Derives the MCP config for a session from the auth context the session
|
|
137
|
+
* request was made with: the project key when one is configured, otherwise
|
|
138
|
+
* the resolved user API key, plus the org/project scope when configured.
|
|
139
|
+
* Headers are only attached when the MCP URL shares the client's API
|
|
140
|
+
* origin. Any other destination throws when the caller passed `mcp: true`
|
|
141
|
+
* and otherwise yields empty headers plus a warning; see
|
|
142
|
+
* `buildMCPServerConfig`.
|
|
143
|
+
*/
|
|
144
|
+
private createMCPServerConfig(
|
|
145
|
+
{ type, url }: { type: MCPServerType; url: string },
|
|
146
|
+
mcpRequested: boolean
|
|
147
|
+
): ToolRouterMCPServerConfig {
|
|
148
|
+
return buildMCPServerConfig({
|
|
142
149
|
type,
|
|
143
150
|
url,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
apiBaseURL: this.client.baseURL,
|
|
152
|
+
apiKey: this.config?.apiKey,
|
|
153
|
+
userApiKey: this.config?.userApiKey,
|
|
154
|
+
defaultHeaders: this.config?.defaultHeaders,
|
|
155
|
+
orgId: this.config?.orgId,
|
|
156
|
+
projectId: this.config?.projectId,
|
|
157
|
+
mcpRequested,
|
|
158
|
+
});
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
/**
|
|
@@ -152,9 +163,17 @@ export class ToolRouter<
|
|
|
152
163
|
* Use `sessionPreset: SessionPreset.DIRECT_TOOLS` when all needed tools
|
|
153
164
|
* should be exposed directly; see `ToolRouterCreateSessionConfig`.
|
|
154
165
|
*
|
|
166
|
+
* The session's MCP config carries the session credential only when the
|
|
167
|
+
* MCP URL shares the origin of the configured API base URL. When it does
|
|
168
|
+
* not, `mcp: true` makes the call throw `ComposioMCPDestinationError`
|
|
169
|
+
* (naming both origins, never a key); without `mcp: true` the session is
|
|
170
|
+
* returned with `session.mcp.headers` empty and a warning naming both
|
|
171
|
+
* origins is logged, so native tools keep working.
|
|
172
|
+
*
|
|
155
173
|
* @param userId {string} The user id to create the session for
|
|
156
174
|
* @param config {ToolRouterCreateSessionConfig} The config for the tool router session
|
|
157
175
|
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
176
|
+
* @throws {ComposioMCPDestinationError} When `mcp: true` is passed and the MCP URL is not on the API origin
|
|
158
177
|
*
|
|
159
178
|
* @example
|
|
160
179
|
* ```typescript
|
|
@@ -282,7 +301,7 @@ export class ToolRouter<
|
|
|
282
301
|
this.client,
|
|
283
302
|
this.config,
|
|
284
303
|
session.session_id,
|
|
285
|
-
this.createMCPServerConfig(session.mcp),
|
|
304
|
+
this.createMCPServerConfig(session.mcp, routerConfig.mcp === true),
|
|
286
305
|
{ assistivePrompt },
|
|
287
306
|
customToolsMap,
|
|
288
307
|
userId,
|
|
@@ -292,8 +311,17 @@ export class ToolRouter<
|
|
|
292
311
|
|
|
293
312
|
/**
|
|
294
313
|
* Use an existing session
|
|
314
|
+
*
|
|
315
|
+
* The session's MCP config carries the session credential only when the
|
|
316
|
+
* MCP URL shares the origin of the configured API base URL. When it does
|
|
317
|
+
* not, `mcp: true` makes the call throw `ComposioMCPDestinationError`
|
|
318
|
+
* (naming both origins, never a key); without `mcp: true` the session is
|
|
319
|
+
* returned with `session.mcp.headers` empty and a warning naming both
|
|
320
|
+
* origins is logged, so native tools keep working.
|
|
321
|
+
*
|
|
295
322
|
* @param id {string} The id of the session to use
|
|
296
323
|
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
324
|
+
* @throws {ComposioMCPDestinationError} When `mcp: true` is passed and the MCP URL is not on the API origin
|
|
297
325
|
*
|
|
298
326
|
* @example
|
|
299
327
|
* ```typescript
|
|
@@ -384,7 +412,7 @@ export class ToolRouter<
|
|
|
384
412
|
this.client,
|
|
385
413
|
this.config,
|
|
386
414
|
session.session_id,
|
|
387
|
-
this.createMCPServerConfig(session.mcp),
|
|
415
|
+
this.createMCPServerConfig(session.mcp, options?.mcp === true),
|
|
388
416
|
undefined,
|
|
389
417
|
customToolsMap,
|
|
390
418
|
userId,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { telemetry } from '../telemetry/Telemetry';
|
|
2
|
-
import { Composio as ComposioClient, BadRequestError } from '@composio/client';
|
|
2
|
+
import { Composio as ComposioClient, BadRequestError, ConflictError } from '@composio/client';
|
|
3
3
|
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
4
4
|
import type { ComposioConfig } from '../composio';
|
|
5
5
|
import type { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
6
6
|
import { withCancellation } from '../utils/cancellation';
|
|
7
7
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
8
|
+
import { ComposioSessionConfigConflictError } from '../errors/ToolRouterErrors';
|
|
8
9
|
import {
|
|
9
10
|
ToolRouterMCPServerConfig,
|
|
10
11
|
SessionExperimental,
|
|
@@ -26,6 +27,9 @@ import {
|
|
|
26
27
|
ToolRouterSessionEnsureConnectedOptions,
|
|
27
28
|
ToolRouterSessionEnsureConnectedOptionsSchema,
|
|
28
29
|
ToolRouterSessionEnsureConnectedResult,
|
|
30
|
+
ToolRouterSessionListConfigHistoryOptions,
|
|
31
|
+
ToolRouterSessionListConfigHistoryOptionsSchema,
|
|
32
|
+
type ToolRouterSessionListConfigHistoryResponse,
|
|
29
33
|
type ToolRouterSessionDeleteResponse,
|
|
30
34
|
} from '../types/toolRouter.types';
|
|
31
35
|
import {
|
|
@@ -64,6 +68,8 @@ import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
|
|
|
64
68
|
import type {
|
|
65
69
|
SessionExecuteParams,
|
|
66
70
|
SessionLinkParams,
|
|
71
|
+
SessionPatchParams,
|
|
72
|
+
SessionPatchResponse,
|
|
67
73
|
SessionSearchParams,
|
|
68
74
|
} from '@composio/client/resources/tool-router/session/session.mjs';
|
|
69
75
|
import { SessionProxyExecuteParamsSchema } from '../types/toolRouter.types';
|
|
@@ -131,6 +137,11 @@ export class ToolRouterSession<
|
|
|
131
137
|
public preload: ToolRouterSessionPreloadConfig;
|
|
132
138
|
/** Resolved sandbox (code-execution) config returned by the API. `enable` defaults to `true` server-side. */
|
|
133
139
|
public sandbox?: ToolRouterSessionWorkbenchConfig;
|
|
140
|
+
/**
|
|
141
|
+
* Version of the server-side configuration this object last observed.
|
|
142
|
+
* Refreshed in place by `update()`, which sends it as the
|
|
143
|
+
* `expected_config_version` precondition by default.
|
|
144
|
+
*/
|
|
134
145
|
public configVersion?: number;
|
|
135
146
|
public warnings: ToolRouterSessionWarning[];
|
|
136
147
|
private readonly preloadedCustomToolSlugs: string[];
|
|
@@ -154,6 +165,7 @@ export class ToolRouterSession<
|
|
|
154
165
|
execute: {},
|
|
155
166
|
search: {},
|
|
156
167
|
preload: { tools: [] },
|
|
168
|
+
premium_usage: false,
|
|
157
169
|
};
|
|
158
170
|
if (customToolsMap && !userId) {
|
|
159
171
|
throw new Error('userId is required when custom tools are bound to a session.');
|
|
@@ -757,20 +769,71 @@ export class ToolRouterSession<
|
|
|
757
769
|
|
|
758
770
|
/**
|
|
759
771
|
* Partially update the session configuration.
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
772
|
+
*
|
|
773
|
+
* Only the fields provided are changed; omitted fields are preserved. For
|
|
774
|
+
* each policy block `null` removes the stored override (which can increase
|
|
775
|
+
* access: `toolkits: null` restores the unrestricted default, while
|
|
776
|
+
* `toolkits: []` denies every app toolkit and is sent as-is). Supplied
|
|
777
|
+
* `tools`, `authConfigs` and `connectedAccounts` maps replace the stored
|
|
778
|
+
* map entirely. `manageConnections.callbackUrl: null` removes only the
|
|
779
|
+
* stored callback URL.
|
|
780
|
+
*
|
|
781
|
+
* The request carries the `configVersion` this object last observed as the
|
|
782
|
+
* `expected_config_version` precondition, so a concurrent change surfaces as
|
|
783
|
+
* {@link ComposioSessionConfigConflictError} (HTTP 409) instead of being
|
|
784
|
+
* overwritten. Pass `expectedConfigVersion` to send another version, or
|
|
785
|
+
* `expectedConfigVersion: false` to send no precondition (last writer
|
|
786
|
+
* wins). The PATCH is never retried by the transport, so a 409 is reported
|
|
787
|
+
* exactly once. On conflict this object is left unchanged: re-fetch the
|
|
788
|
+
* session with `sessions.use(sessionId)` and retry against the fresh
|
|
789
|
+
* `configVersion`.
|
|
790
|
+
*
|
|
791
|
+
* `config`, `configVersion`, `preload`, `sandbox` and `warnings` are
|
|
792
|
+
* refreshed in place only after a successful response, and the updated
|
|
793
|
+
* `config` is returned.
|
|
763
794
|
*/
|
|
764
795
|
async update(
|
|
765
796
|
config: ToolRouterUpdateSessionConfig,
|
|
766
797
|
requestOptions?: ComposioRequestOptions
|
|
767
798
|
): Promise<ToolRouterSessionConfig> {
|
|
768
799
|
const parsed = ToolRouterUpdateSessionConfigSchema.parse(config);
|
|
769
|
-
const
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
800
|
+
const body = transformToolRouterUpdateParams(parsed);
|
|
801
|
+
const expectedConfigVersion =
|
|
802
|
+
parsed.expectedConfigVersion === false
|
|
803
|
+
? undefined
|
|
804
|
+
: (parsed.expectedConfigVersion ?? this.configVersion);
|
|
805
|
+
if (expectedConfigVersion !== undefined) {
|
|
806
|
+
body.expected_config_version = expectedConfigVersion;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
let response: SessionPatchResponse;
|
|
810
|
+
try {
|
|
811
|
+
response = await withCancellation(
|
|
812
|
+
() =>
|
|
813
|
+
this.client.toolRouter.session.patch(
|
|
814
|
+
this.sessionId,
|
|
815
|
+
// The generated client does not type `expected_config_version` or
|
|
816
|
+
// the nullable policy blocks; the body is serialized as-is.
|
|
817
|
+
body as SessionPatchParams,
|
|
818
|
+
{ ...requestOptions, maxRetries: 0 }
|
|
819
|
+
),
|
|
820
|
+
requestOptions?.signal
|
|
821
|
+
);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
if (error instanceof ConflictError) {
|
|
824
|
+
throw new ComposioSessionConfigConflictError(
|
|
825
|
+
expectedConfigVersion === undefined
|
|
826
|
+
? `Session ${this.sessionId} configuration changed while this update was in flight; re-fetch the session and retry the update`
|
|
827
|
+
: `Session ${this.sessionId} configuration is no longer at version ${expectedConfigVersion}; re-fetch the session and retry the update`,
|
|
828
|
+
{
|
|
829
|
+
cause: error,
|
|
830
|
+
meta: { sessionId: this.sessionId, expectedConfigVersion },
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
throw error;
|
|
835
|
+
}
|
|
836
|
+
|
|
774
837
|
this.configVersion = response.config_version;
|
|
775
838
|
this.config = response.config;
|
|
776
839
|
this.preload = response.config.preload;
|
|
@@ -789,6 +852,54 @@ export class ToolRouterSession<
|
|
|
789
852
|
return deleteToolRouterSession(this.client, this.sessionId, requestOptions);
|
|
790
853
|
}
|
|
791
854
|
|
|
855
|
+
/**
|
|
856
|
+
* Page through this session's configuration history, newest first. The
|
|
857
|
+
* first page starts with the live config (`isCurrent: true`); every
|
|
858
|
+
* `session.update()` archives the previous version as a history row.
|
|
859
|
+
*
|
|
860
|
+
* @param options - Optional `cursor` and `limit` (max 100)
|
|
861
|
+
* @returns The config versions on this page plus pagination info
|
|
862
|
+
* @throws {ValidationError} If the options fail validation
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const { items, nextCursor } = await session.listConfigHistory({ limit: 10 });
|
|
867
|
+
* console.log(items[0].version, items[0].isCurrent); // e.g. 3, true
|
|
868
|
+
* console.log(items[1].config.toolkits);
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
async listConfigHistory(
|
|
872
|
+
options?: ToolRouterSessionListConfigHistoryOptions,
|
|
873
|
+
requestOptions?: ComposioRequestOptions
|
|
874
|
+
): Promise<ToolRouterSessionListConfigHistoryResponse> {
|
|
875
|
+
const parsedOptions = ToolRouterSessionListConfigHistoryOptionsSchema.safeParse(options ?? {});
|
|
876
|
+
if (!parsedOptions.success) {
|
|
877
|
+
throw new ValidationError('Failed to parse config history options', {
|
|
878
|
+
cause: parsedOptions.error,
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
const query = {
|
|
882
|
+
cursor: parsedOptions.data.cursor,
|
|
883
|
+
limit: parsedOptions.data.limit,
|
|
884
|
+
};
|
|
885
|
+
const response = await withCancellation(
|
|
886
|
+
() => this.client.toolRouter.session.configHistory(this.sessionId, query, requestOptions),
|
|
887
|
+
requestOptions?.signal
|
|
888
|
+
);
|
|
889
|
+
return {
|
|
890
|
+
items: response.items.map(item => ({
|
|
891
|
+
version: item.version,
|
|
892
|
+
createdAt: item.created_at,
|
|
893
|
+
isCurrent: item.is_current,
|
|
894
|
+
config: item.config,
|
|
895
|
+
})),
|
|
896
|
+
nextCursor: response.next_cursor ?? null,
|
|
897
|
+
totalPages: response.total_pages,
|
|
898
|
+
currentPage: response.current_page,
|
|
899
|
+
totalItems: response.total_items,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
|
|
792
903
|
// ── Private helpers ──────────────────────────────────────────
|
|
793
904
|
|
|
794
905
|
/** Check if this session has any custom tools bound. */
|