@composio/core 0.27.0 → 0.29.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/README.md +2 -0
- package/dist/{CustomTool-BYHB7sPs.mjs → CustomTool-Bd1KdWvo.mjs} +9 -8
- package/dist/{CustomTool-CqPoLUD6.d.mts → CustomTool-CMW-d2ZN.d.mts} +10 -9
- package/dist/{Telemetry-41JkqpZ7.mjs → Telemetry-D2PJwXKx.mjs} +1 -1
- package/dist/{cancellation-ZoRh6EJQ.mjs → cancellation-BoJjs34Y.mjs} +1 -1
- package/dist/{composio-BUa10iB3.d.mts → composio-D5UV5HXN.d.mts} +799 -100
- package/dist/{customTool.types-gX421uPT.d.mts → customTool.types-B9fs34dv.d.mts} +105 -60
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +86 -3
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +51 -13
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +5 -1
- package/dist/{errors-Cly0vXFh.mjs → errors-BK6Xc7Ia.mjs} +65 -1
- package/dist/experimental/index.d.mts +3 -3
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-DNLhLg0W.mjs → fileUtils.node-ILI1IjnZ.mjs} +4 -3
- package/dist/index.d.mts +46 -16
- package/dist/index.mjs +2973 -2778
- package/dist/models/Files.node.mjs +2 -2
- package/dist/sensitiveFileUploadPaths-BaEORC7-.mjs +588 -0
- package/dist/{types-DXxfzBX3.d.mts → types-CaP2SytR.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 +3 -3
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +7 -6
- package/src/errors/ToolErrors.ts +73 -1
- package/src/experimental/index.ts +6 -1
- package/src/lib/toolRouterParams.ts +68 -33
- package/src/lib/toolRouterSessionDelete.ts +1 -10
- package/src/models/ConnectedAccounts.ts +3 -3
- package/src/models/ConnectionRequest.ts +38 -34
- package/src/models/CustomTool.ts +26 -31
- package/src/models/CustomToolkits.ts +116 -10
- package/src/models/Experimental.ts +1 -1
- package/src/models/MCP.ts +1 -2
- package/src/models/SessionConfigs.ts +11 -3
- package/src/models/SessionContext.ts +4 -4
- package/src/models/ToolRouter.ts +26 -17
- package/src/models/ToolRouterSession.ts +39 -24
- package/src/models/Tools.ts +60 -14
- package/src/models/Triggers.ts +12 -5
- package/src/models/inlineCustomToolsPayload.ts +3 -3
- package/src/models/proxyParamsTransform.ts +1 -1
- package/src/types/customTool.types.ts +62 -33
- package/src/types/customToolkits.types.ts +91 -11
- package/src/types/sessionConfigs.types.ts +21 -7
- package/src/types/toolRouter.types.ts +53 -24
- package/src/types/triggers.types.ts +14 -0
- package/src/utils/fileUtils.node.ts +5 -2
- package/src/utils/mime.ts +347 -1
- package/src/utils/rateLimit.ts +25 -0
- package/src/utils/transformers/connectedAccounts.ts +2 -7
- package/src/utils/transformers/customToolkits.ts +79 -10
- package/src/utils/transformers/sessionConfigs.ts +3 -3
- package/src/utils/transformers/toolRouterResponseTransform.ts +23 -75
- package/src/utils/transformers/toolkits.ts +7 -13
- package/src/utils/transformers/triggers.ts +28 -18
- package/dist/sensitiveFileUploadPaths-BlLp-Yo2.mjs +0 -189
|
@@ -67,8 +67,8 @@ import type {
|
|
|
67
67
|
CustomToolsMap,
|
|
68
68
|
CustomToolsMapEntry,
|
|
69
69
|
SessionContext,
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
RegisteredLocalTool,
|
|
71
|
+
RegisteredLocalToolkit,
|
|
72
72
|
} from '../types/customTool.types';
|
|
73
73
|
import { ToolSchema, type Tool, type ToolExecuteResponse } from '../types/tool.types';
|
|
74
74
|
import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
|
|
@@ -79,7 +79,7 @@ import type {
|
|
|
79
79
|
SessionPatchParams,
|
|
80
80
|
SessionPatchResponse,
|
|
81
81
|
SessionSearchParams,
|
|
82
|
-
} from '@composio/client/resources/tool-router/session
|
|
82
|
+
} from '@composio/client/resources/tool-router/session';
|
|
83
83
|
import { SessionProxyExecuteParamsSchema } from '../types/toolRouter.types';
|
|
84
84
|
import { SessionContextImpl } from './SessionContext';
|
|
85
85
|
import {
|
|
@@ -384,13 +384,13 @@ export class ToolRouterSession<
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
/**
|
|
387
|
-
* List all
|
|
387
|
+
* List all local tools registered in this session.
|
|
388
388
|
* Returns tools with their final slugs, schemas, and resolved toolkit.
|
|
389
389
|
*
|
|
390
390
|
* @param options.toolkit - Filter by toolkit slug (e.g. 'gmail', 'DEV_TOOLS')
|
|
391
|
-
* @returns Array of registered
|
|
391
|
+
* @returns Array of registered local tools
|
|
392
392
|
*/
|
|
393
|
-
|
|
393
|
+
localTools(options?: { toolkit?: string }): RegisteredLocalTool[] {
|
|
394
394
|
if (!this.customToolsMap) return [];
|
|
395
395
|
|
|
396
396
|
const entries = Array.from(this.customToolsMap.byFinalSlug.values());
|
|
@@ -409,12 +409,19 @@ export class ToolRouterSession<
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
|
-
*
|
|
412
|
+
* @deprecated Use `localTools()` instead.
|
|
413
|
+
*/
|
|
414
|
+
customTools(options?: { toolkit?: string }): RegisteredLocalTool[] {
|
|
415
|
+
return this.localTools(options);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* List all toolkits of local tools registered in this session.
|
|
413
420
|
* Returns toolkits with their tools showing final slugs.
|
|
414
421
|
*
|
|
415
|
-
* @returns Array of registered
|
|
422
|
+
* @returns Array of registered toolkits of local tools
|
|
416
423
|
*/
|
|
417
|
-
|
|
424
|
+
localToolkits(): RegisteredLocalToolkit[] {
|
|
418
425
|
const toolkits = this.customToolsMap?.toolkits;
|
|
419
426
|
if (!toolkits?.length) return [];
|
|
420
427
|
|
|
@@ -444,6 +451,13 @@ export class ToolRouterSession<
|
|
|
444
451
|
}));
|
|
445
452
|
}
|
|
446
453
|
|
|
454
|
+
/**
|
|
455
|
+
* @deprecated Use `localToolkits()` instead.
|
|
456
|
+
*/
|
|
457
|
+
customToolkits(): RegisteredLocalToolkit[] {
|
|
458
|
+
return this.localToolkits();
|
|
459
|
+
}
|
|
460
|
+
|
|
447
461
|
/**
|
|
448
462
|
* Initiate an authorization flow for a toolkit.
|
|
449
463
|
* Returns a ConnectionRequest with a redirect URL for the user.
|
|
@@ -484,7 +498,7 @@ export class ToolRouterSession<
|
|
|
484
498
|
...(opts.callbackUrl !== undefined && { callback_url: opts.callbackUrl }),
|
|
485
499
|
...(opts.alias !== undefined && { alias: opts.alias }),
|
|
486
500
|
...(experimentalWire !== undefined && {
|
|
487
|
-
experimental: experimentalWire as SessionLinkParams
|
|
501
|
+
experimental: experimentalWire as NonNullable<SessionLinkParams['experimental']>,
|
|
488
502
|
}),
|
|
489
503
|
};
|
|
490
504
|
|
|
@@ -667,9 +681,9 @@ export class ToolRouterSession<
|
|
|
667
681
|
},
|
|
668
682
|
requestOptions?: ComposioRequestOptions
|
|
669
683
|
): Promise<ToolRouterSessionSearchResponse> {
|
|
670
|
-
const experimental = inlineCustomToolsExperimental<
|
|
671
|
-
|
|
672
|
-
);
|
|
684
|
+
const experimental = inlineCustomToolsExperimental<
|
|
685
|
+
NonNullable<SessionSearchParams['experimental']>
|
|
686
|
+
>(this.inlineCustomToolsPayload);
|
|
673
687
|
const searchParams = {
|
|
674
688
|
queries: [{ use_case: params.query }],
|
|
675
689
|
...(params.toolkits?.length ? { toolkits: params.toolkits } : {}),
|
|
@@ -738,9 +752,9 @@ export class ToolRouterSession<
|
|
|
738
752
|
if (options?.account) {
|
|
739
753
|
executeParams.account = options.account;
|
|
740
754
|
}
|
|
741
|
-
const experimental = inlineCustomToolsExperimental<
|
|
742
|
-
|
|
743
|
-
);
|
|
755
|
+
const experimental = inlineCustomToolsExperimental<
|
|
756
|
+
NonNullable<SessionExecuteParams['experimental']>
|
|
757
|
+
>(this.inlineCustomToolsPayload);
|
|
744
758
|
if (experimental) {
|
|
745
759
|
executeParams.experimental = experimental;
|
|
746
760
|
}
|
|
@@ -790,9 +804,9 @@ export class ToolRouterSession<
|
|
|
790
804
|
arguments: arguments_ ?? {},
|
|
791
805
|
...inputResponseParams(options),
|
|
792
806
|
};
|
|
793
|
-
const experimental = inlineCustomToolsExperimental<
|
|
794
|
-
|
|
795
|
-
);
|
|
807
|
+
const experimental = inlineCustomToolsExperimental<
|
|
808
|
+
NonNullable<SessionExecuteMetaParams['experimental']>
|
|
809
|
+
>(this.inlineCustomToolsPayload);
|
|
796
810
|
if (experimental) {
|
|
797
811
|
executeMetaParams.experimental = experimental;
|
|
798
812
|
}
|
|
@@ -896,8 +910,9 @@ export class ToolRouterSession<
|
|
|
896
910
|
() =>
|
|
897
911
|
this.client.toolRouter.session.patch(
|
|
898
912
|
this.sessionId,
|
|
899
|
-
//
|
|
900
|
-
// the
|
|
913
|
+
// `expected_config_version` and the nullable policy blocks are not in
|
|
914
|
+
// the spec until ComposioHQ/platform#13157 lands; the body is
|
|
915
|
+
// serialized as-is.
|
|
901
916
|
body as SessionPatchParams,
|
|
902
917
|
{ ...requestOptions, maxRetries: 0 }
|
|
903
918
|
),
|
|
@@ -1010,9 +1025,9 @@ export class ToolRouterSession<
|
|
|
1010
1025
|
tool?: Tool
|
|
1011
1026
|
): Promise<ToolExecuteResponse> {
|
|
1012
1027
|
const body = { sessionId: this.sessionId, arguments: input };
|
|
1013
|
-
const experimental = inlineCustomToolsExperimental<
|
|
1014
|
-
|
|
1015
|
-
);
|
|
1028
|
+
const experimental = inlineCustomToolsExperimental<
|
|
1029
|
+
NonNullable<SessionExecuteParams['experimental']>
|
|
1030
|
+
>(this.inlineCustomToolsPayload);
|
|
1016
1031
|
if (experimental) {
|
|
1017
1032
|
return ToolsModel.executeSessionTool(toolSlug, body, modifiers, tool, { experimental });
|
|
1018
1033
|
}
|
package/src/models/Tools.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { ExecuteToolFn, GlobalExecuteToolFn } from '../types/provider.types';
|
|
|
43
43
|
import {
|
|
44
44
|
ComposioInvalidModifierError,
|
|
45
45
|
ComposioToolFetchError,
|
|
46
|
+
ComposioToolFetchRateLimitError,
|
|
46
47
|
ComposioToolNotFoundError,
|
|
47
48
|
ComposioProviderNotDefinedError,
|
|
48
49
|
ComposioToolVersionRequiredError,
|
|
@@ -52,7 +53,7 @@ import { telemetry } from '../telemetry/Telemetry';
|
|
|
52
53
|
import type { ComposioConfig } from '../composio';
|
|
53
54
|
import { getToolkitVersion } from '../utils/toolkitVersion';
|
|
54
55
|
import { handleToolExecutionError } from '../errors/ToolErrors';
|
|
55
|
-
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session
|
|
56
|
+
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session';
|
|
56
57
|
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
|
|
57
58
|
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
|
|
58
59
|
import {
|
|
@@ -68,11 +69,12 @@ import {
|
|
|
68
69
|
transformExecuteResponse,
|
|
69
70
|
} from '../utils/transformers/toolRouterResponseTransform';
|
|
70
71
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
72
|
+
import { isRateLimitResponse } from '../utils/rateLimit';
|
|
71
73
|
|
|
72
74
|
const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
|
|
73
75
|
|
|
74
76
|
type ToolRouterSessionExecuteOptions = {
|
|
75
|
-
experimental?: SessionExecuteParams
|
|
77
|
+
experimental?: NonNullable<SessionExecuteParams['experimental']>;
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
type RawToolParameters =
|
|
@@ -98,6 +100,13 @@ function normalizeRawToolParameters(
|
|
|
98
100
|
return params;
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/** How long `execute()` reuses a schema fetched for `latest`, which can change at any release. */
|
|
104
|
+
const LATEST_TOOL_SCHEMA_TTL_MS = 5 * 60 * 1000;
|
|
105
|
+
/** How long `execute()` reuses a schema fetched for a pinned toolkit version. */
|
|
106
|
+
const PINNED_TOOL_SCHEMA_TTL_MS = 60 * 60 * 1000;
|
|
107
|
+
/** Most schemas `execute()` keeps per `Tools` instance; the oldest is dropped first. */
|
|
108
|
+
const MAX_CACHED_TOOL_SCHEMAS = 500;
|
|
109
|
+
|
|
101
110
|
/**
|
|
102
111
|
* This class is used to manage tools in the Composio SDK.
|
|
103
112
|
* It provides methods to list, get, and execute tools.
|
|
@@ -123,6 +132,12 @@ export class Tools<
|
|
|
123
132
|
* Scoped per-instance so a fresh `Composio` starts with a clean slate.
|
|
124
133
|
*/
|
|
125
134
|
private readonly warnedAutoUploadDisabledForTool = new Set<string>();
|
|
135
|
+
/**
|
|
136
|
+
* Schemas `execute()` already fetched, so repeated executions don't each spend a request.
|
|
137
|
+
* Holds what `getRawComposioToolBySlug` returned with no `modifySchema`, so a caller's schema
|
|
138
|
+
* modifiers never reach it.
|
|
139
|
+
*/
|
|
140
|
+
private readonly executeToolSchemas = new Map<string, { tool: Tool; expiresAt: number }>();
|
|
126
141
|
|
|
127
142
|
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
128
143
|
if (!client) {
|
|
@@ -409,9 +424,9 @@ export class Tools<
|
|
|
409
424
|
* Lists Composio API tools available to the SDK.
|
|
410
425
|
*
|
|
411
426
|
* This method fetches remote Composio tools from the API in raw format. The response can be
|
|
412
|
-
* filtered and modified as needed.
|
|
427
|
+
* filtered and modified as needed. Experimental local tools are session-scoped; attach
|
|
413
428
|
* them when creating or reusing a Tool Router session, then use `session.tools()`,
|
|
414
|
-
* `session.
|
|
429
|
+
* `session.localTools()`, or `session.execute()`.
|
|
415
430
|
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
416
431
|
*
|
|
417
432
|
* @param {ToolListParams} query - Query parameters to filter the tools (required)
|
|
@@ -628,8 +643,8 @@ export class Tools<
|
|
|
628
643
|
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
629
644
|
* providing direct access to the tool's schema and metadata. Tool versions are controlled
|
|
630
645
|
* at the Composio SDK initialization level through the `toolkitVersions` configuration.
|
|
631
|
-
*
|
|
632
|
-
* Tool Router session, then use `session.tools()`, `session.
|
|
646
|
+
* Experimental local tools are session-scoped; attach them when creating or reusing a
|
|
647
|
+
* Tool Router session, then use `session.tools()`, `session.localTools()`, or
|
|
633
648
|
* `session.execute()`.
|
|
634
649
|
*
|
|
635
650
|
* @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
|
|
@@ -692,6 +707,13 @@ export class Tools<
|
|
|
692
707
|
if (error instanceof ComposioRequestCancelledError) {
|
|
693
708
|
throw error;
|
|
694
709
|
}
|
|
710
|
+
if (isRateLimitResponse(error)) {
|
|
711
|
+
throw new ComposioToolFetchRateLimitError(
|
|
712
|
+
`Rate limited while retrieving tool with slug ${slug}`,
|
|
713
|
+
error,
|
|
714
|
+
{ slug }
|
|
715
|
+
);
|
|
716
|
+
}
|
|
695
717
|
// The tools endpoint reports an unknown slug as 404 (or 400 for a
|
|
696
718
|
// malformed one). Anything else (401, 5xx, network) is not "not found",
|
|
697
719
|
// so keep the client error reachable as `cause` under a generic error.
|
|
@@ -1153,16 +1175,40 @@ export class Tools<
|
|
|
1153
1175
|
const requestOptions: ComposioRequestOptions | undefined =
|
|
1154
1176
|
options?.signal != null ? { signal: options.signal } : undefined;
|
|
1155
1177
|
|
|
1156
|
-
const tool = await this.
|
|
1157
|
-
slug,
|
|
1158
|
-
{
|
|
1159
|
-
version: executeParams.version,
|
|
1160
|
-
},
|
|
1161
|
-
requestOptions
|
|
1162
|
-
);
|
|
1178
|
+
const tool = await this.getToolSchemaForExecute(slug, executeParams.version, requestOptions);
|
|
1163
1179
|
return this.executeWithTool(slug, executeParams, options, tool);
|
|
1164
1180
|
}
|
|
1165
1181
|
|
|
1182
|
+
/** The tool's schema for `execute()`, fetched only if no unexpired copy is cached. Failures aren't cached. */
|
|
1183
|
+
private async getToolSchemaForExecute(
|
|
1184
|
+
slug: string,
|
|
1185
|
+
version: string | undefined,
|
|
1186
|
+
requestOptions: ComposioRequestOptions | undefined
|
|
1187
|
+
): Promise<Tool> {
|
|
1188
|
+
const key = `${slug}\0${version ?? ''}`;
|
|
1189
|
+
const cached = this.executeToolSchemas.get(key);
|
|
1190
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
1191
|
+
return cached.tool;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const tool = await this.getRawComposioToolBySlug(slug, { version }, requestOptions);
|
|
1195
|
+
|
|
1196
|
+
const resolvedVersion =
|
|
1197
|
+
version ?? getToolkitVersion(tool.toolkit?.slug ?? 'unknown', this.toolkitVersions);
|
|
1198
|
+
const ttlMs =
|
|
1199
|
+
resolvedVersion === 'latest' ? LATEST_TOOL_SCHEMA_TTL_MS : PINNED_TOOL_SCHEMA_TTL_MS;
|
|
1200
|
+
// Re-insert so a refreshed entry counts as the newest.
|
|
1201
|
+
this.executeToolSchemas.delete(key);
|
|
1202
|
+
if (this.executeToolSchemas.size >= MAX_CACHED_TOOL_SCHEMAS) {
|
|
1203
|
+
const oldestKey = this.executeToolSchemas.keys().next().value;
|
|
1204
|
+
if (oldestKey !== undefined) {
|
|
1205
|
+
this.executeToolSchemas.delete(oldestKey);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
this.executeToolSchemas.set(key, { tool, expiresAt: Date.now() + ttlMs });
|
|
1209
|
+
return tool;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1166
1212
|
/**
|
|
1167
1213
|
* Executes a tool based on a tool router session.
|
|
1168
1214
|
*
|
|
@@ -1362,7 +1408,7 @@ export class Tools<
|
|
|
1362
1408
|
}
|
|
1363
1409
|
// convert the headers and query to the composio format
|
|
1364
1410
|
// { name: string, type: 'header' | 'query', value: string }
|
|
1365
|
-
const parameters: ComposioToolProxyParams
|
|
1411
|
+
const parameters: NonNullable<ComposioToolProxyParams['parameters']>[number][] = [];
|
|
1366
1412
|
const parameterTypes = {
|
|
1367
1413
|
header: 'header',
|
|
1368
1414
|
query: 'query',
|
package/src/models/Triggers.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import ComposioClient, { APIError } from '@composio/client';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type TriggerInstanceUpsertParams as ClientTriggerInstanceUpsertParams,
|
|
5
|
-
} from '@composio/client/resources/index';
|
|
2
|
+
import type { TriggerInstanceUpsertParams as ClientTriggerInstanceUpsertParams } from '@composio/client/resources/trigger-instances';
|
|
3
|
+
import { TriggersTypeRetrieveEnumResponse } from '@composio/client/resources/triggers-types';
|
|
6
4
|
import {
|
|
7
5
|
TriggerInstanceUpsertResponse,
|
|
8
6
|
TriggerInstanceUpsertParamsSchema,
|
|
@@ -238,10 +236,14 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
238
236
|
* Create a new trigger instance for a user
|
|
239
237
|
* If the connected account id is not provided, the first connected account for the user and toolkit will be used
|
|
240
238
|
*
|
|
239
|
+
* For a trigger that supports both webhook and polling, `body.type` picks one; omit it to let Composio choose.
|
|
240
|
+
* `body.pollingInterval` sets the minutes between polls and wins over `triggerConfig.interval`.
|
|
241
|
+
*
|
|
241
242
|
* @param {string} userId - The user id of the trigger instance
|
|
242
243
|
* @param {string} slug - The slug of the trigger instance
|
|
243
244
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
244
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The
|
|
245
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The trigger instance, with the type it uses, why it polls
|
|
246
|
+
* when it fell back from a webhook, and its polling interval
|
|
245
247
|
*/
|
|
246
248
|
async create(
|
|
247
249
|
userId: string,
|
|
@@ -288,6 +290,8 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
288
290
|
const upsertParams: ClientTriggerInstanceUpsertParams = {
|
|
289
291
|
connected_account_id: parsedBody.data.connectedAccountId,
|
|
290
292
|
trigger_config: parsedBody.data.triggerConfig,
|
|
293
|
+
type: parsedBody.data.type,
|
|
294
|
+
polling_interval: parsedBody.data.pollingInterval,
|
|
291
295
|
toolkit_versions: this.toolkitVersions,
|
|
292
296
|
user_id: userId,
|
|
293
297
|
};
|
|
@@ -298,6 +302,9 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
298
302
|
|
|
299
303
|
return {
|
|
300
304
|
triggerId: result.trigger_id,
|
|
305
|
+
type: result.type,
|
|
306
|
+
fallbackReason: result.fallback_reason,
|
|
307
|
+
pollingInterval: result.polling_interval,
|
|
301
308
|
};
|
|
302
309
|
}
|
|
303
310
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SessionExecuteParams,
|
|
3
3
|
SessionSearchParams,
|
|
4
|
-
} from '@composio/client/resources/tool-router/session
|
|
4
|
+
} from '@composio/client/resources/tool-router/session';
|
|
5
5
|
import type { InlineCustomToolsWirePayload } from '../types/customTool.types';
|
|
6
6
|
|
|
7
7
|
type InlineCustomToolsExperimental =
|
|
8
|
-
| SessionExecuteParams
|
|
9
|
-
| SessionSearchParams
|
|
8
|
+
| NonNullable<SessionExecuteParams['experimental']>
|
|
9
|
+
| NonNullable<SessionSearchParams['experimental']>;
|
|
10
10
|
|
|
11
11
|
export function inlineCustomToolsExperimental<TExperimental extends InlineCustomToolsExperimental>(
|
|
12
12
|
payload?: InlineCustomToolsWirePayload
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* to the official @composio/client proxy execute params.
|
|
4
4
|
*/
|
|
5
5
|
import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
|
|
6
|
-
import type { SessionProxyExecuteParams as ClientProxyExecuteParams } from '@composio/client/resources/tool-router/session
|
|
6
|
+
import type { SessionProxyExecuteParams as ClientProxyExecuteParams } from '@composio/client/resources/tool-router/session';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Transform SDK session proxy params to the official client request format.
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import type {
|
|
9
9
|
SessionCreateParams,
|
|
10
10
|
SessionCreateResponse,
|
|
11
|
-
} from '@composio/client/resources/tool-router/session
|
|
11
|
+
} from '@composio/client/resources/tool-router/session';
|
|
12
12
|
|
|
13
13
|
export type AnyZodSchema = z.ZodType | z4.ZodType;
|
|
14
14
|
export type InferZodSchema<T extends AnyZodSchema> = T extends z.ZodType
|
|
@@ -46,18 +46,21 @@ export interface SessionContext {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Execute function for
|
|
49
|
+
* Execute function for local tools.
|
|
50
50
|
* Just return the result data, or throw an error. The SDK wraps it internally.
|
|
51
51
|
*
|
|
52
52
|
* Supports two call patterns:
|
|
53
53
|
* - `(input) => data` — for tools that don't need session context
|
|
54
54
|
* - `(input, ctx) => data` — for tools that need to call other tools or proxy APIs
|
|
55
55
|
*/
|
|
56
|
-
export type
|
|
56
|
+
export type LocalToolExecuteFn<T extends AnyZodSchema> = (
|
|
57
57
|
input: InferZodSchema<T>,
|
|
58
58
|
ctx: SessionContext
|
|
59
59
|
) => Promise<Record<string, unknown>>;
|
|
60
60
|
|
|
61
|
+
/** @deprecated Use `LocalToolExecuteFn` instead; local tools were previously called custom tools. */
|
|
62
|
+
export type CustomToolExecuteFn<T extends AnyZodSchema> = LocalToolExecuteFn<T>;
|
|
63
|
+
|
|
61
64
|
/**
|
|
62
65
|
* Zod schema for validating a custom tool slug.
|
|
63
66
|
* Alphanumeric, underscores, and hyphens only. No `LOCAL_` or `COMPOSIO_` prefix.
|
|
@@ -101,8 +104,8 @@ export const CreateCustomToolBaseSchema = z.object({
|
|
|
101
104
|
),
|
|
102
105
|
});
|
|
103
106
|
|
|
104
|
-
/** Options for creating
|
|
105
|
-
export type
|
|
107
|
+
/** Options for creating local tools via `experimental_createTool()`. */
|
|
108
|
+
export type CreateLocalToolParams<T extends AnyZodSchema> = z.infer<
|
|
106
109
|
typeof CreateCustomToolBaseSchema
|
|
107
110
|
> & {
|
|
108
111
|
/** Zod schema for input parameters */
|
|
@@ -110,14 +113,17 @@ export type CreateCustomToolParams<T extends AnyZodSchema> = z.infer<
|
|
|
110
113
|
/** Optional Zod schema for output parameters (sent to backend for documentation) */
|
|
111
114
|
outputParams?: AnyZodSchema;
|
|
112
115
|
/** The function that executes the tool */
|
|
113
|
-
execute:
|
|
116
|
+
execute: LocalToolExecuteFn<T>;
|
|
114
117
|
};
|
|
115
118
|
|
|
119
|
+
/** @deprecated Use `CreateLocalToolParams` instead; local tools were previously called custom tools. */
|
|
120
|
+
export type CreateCustomToolParams<T extends AnyZodSchema> = CreateLocalToolParams<T>;
|
|
121
|
+
|
|
116
122
|
/**
|
|
117
|
-
*
|
|
118
|
-
* Pass to `composio.create(userId, { experimental: {
|
|
123
|
+
* One of your local tools, returned from `experimental_createTool()`; it runs in your process.
|
|
124
|
+
* Pass to `composio.create(userId, { experimental: { localTools: [...] } })` to bind to a session.
|
|
119
125
|
*/
|
|
120
|
-
export interface
|
|
126
|
+
export interface LocalTool {
|
|
121
127
|
readonly slug: string;
|
|
122
128
|
readonly name: string;
|
|
123
129
|
readonly description: string;
|
|
@@ -138,11 +144,16 @@ export interface CustomTool {
|
|
|
138
144
|
/** @internal Original Zod schema — used for runtime input validation (defaults, coercions, transforms) */
|
|
139
145
|
readonly inputParams: AnyZodSchema;
|
|
140
146
|
/** Direct reference to the execute function — useful for testing */
|
|
141
|
-
readonly execute:
|
|
147
|
+
readonly execute: LocalToolExecuteFn<AnyZodSchema>;
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
/** @deprecated Use `LocalTool` instead; local tools were previously called custom tools. */
|
|
151
|
+
export type CustomTool = LocalTool;
|
|
152
|
+
|
|
144
153
|
/** Serialized tool definition sent to backend for search indexing. Uses official client type. */
|
|
145
|
-
export type CustomToolDefinition =
|
|
154
|
+
export type CustomToolDefinition = NonNullable<
|
|
155
|
+
NonNullable<SessionCreateParams['experimental']>['custom_tools']
|
|
156
|
+
>[number];
|
|
146
157
|
|
|
147
158
|
export type CustomToolWireDefinition = CustomToolDefinition;
|
|
148
159
|
|
|
@@ -165,17 +176,20 @@ export const CreateCustomToolkitBaseSchema = z.object({
|
|
|
165
176
|
),
|
|
166
177
|
});
|
|
167
178
|
|
|
168
|
-
/** Options for
|
|
169
|
-
export type
|
|
179
|
+
/** Options for grouping local tools into a toolkit via `experimental_createToolkit()`. */
|
|
180
|
+
export type CreateLocalToolkitParams = z.infer<typeof CreateCustomToolkitBaseSchema> & {
|
|
170
181
|
/** Tools to include in this toolkit. Must not have `extendsToolkit` set. */
|
|
171
|
-
tools:
|
|
182
|
+
tools: LocalTool[];
|
|
172
183
|
};
|
|
173
184
|
|
|
185
|
+
/** @deprecated Use `CreateLocalToolkitParams` instead; local toolkits were previously called custom toolkits. */
|
|
186
|
+
export type CreateCustomToolkitParams = CreateLocalToolkitParams;
|
|
187
|
+
|
|
174
188
|
/**
|
|
175
|
-
*
|
|
176
|
-
* Pass to `composio.create(userId, { experimental: {
|
|
189
|
+
* A toolkit of local tools returned from `experimental_createToolkit()`.
|
|
190
|
+
* Pass to `composio.create(userId, { experimental: { localToolkits: [...] } })`.
|
|
177
191
|
*/
|
|
178
|
-
export interface
|
|
192
|
+
export interface LocalToolkit {
|
|
179
193
|
readonly slug: string;
|
|
180
194
|
readonly name: string;
|
|
181
195
|
readonly description: string;
|
|
@@ -184,11 +198,16 @@ export interface CustomToolkit {
|
|
|
184
198
|
* Tool-level preload values override this default.
|
|
185
199
|
*/
|
|
186
200
|
readonly preload?: boolean;
|
|
187
|
-
readonly tools: readonly
|
|
201
|
+
readonly tools: readonly LocalTool[];
|
|
188
202
|
}
|
|
189
203
|
|
|
204
|
+
/** @deprecated Use `LocalToolkit` instead; local toolkits were previously called custom toolkits. */
|
|
205
|
+
export type CustomToolkit = LocalToolkit;
|
|
206
|
+
|
|
190
207
|
/** Serialized toolkit definition sent to backend. Uses official client type. */
|
|
191
|
-
export type CustomToolkitDefinition =
|
|
208
|
+
export type CustomToolkitDefinition = NonNullable<
|
|
209
|
+
NonNullable<NonNullable<SessionCreateParams['experimental']>['custom_toolkits']>[number]
|
|
210
|
+
>;
|
|
192
211
|
|
|
193
212
|
export type CustomToolkitWireDefinition = CustomToolkitDefinition;
|
|
194
213
|
|
|
@@ -203,7 +222,7 @@ export interface InlineCustomToolsWirePayload {
|
|
|
203
222
|
|
|
204
223
|
/** @internal Entry in the per-session custom tools routing map. */
|
|
205
224
|
export type CustomToolsMapEntry = {
|
|
206
|
-
handle:
|
|
225
|
+
handle: LocalTool;
|
|
207
226
|
/** @internal The final slug assigned by the prefixing rules (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
|
|
208
227
|
finalSlug: string;
|
|
209
228
|
/** Resolved toolkit — from extendsToolkit, parent custom toolkit, or undefined for standalone */
|
|
@@ -220,42 +239,52 @@ export type CustomToolsMap = {
|
|
|
220
239
|
byToolkitAndOriginalSlug?: Map<string, CustomToolsMapEntry>;
|
|
221
240
|
/** Original slugs that appear in multiple toolkits and cannot be resolved safely without the final slug */
|
|
222
241
|
ambiguousOriginalSlugs?: Set<string>;
|
|
223
|
-
/** The original
|
|
224
|
-
toolkits?:
|
|
225
|
-
/** The original standalone
|
|
226
|
-
tools?:
|
|
242
|
+
/** The original local toolkits passed at session creation — used for session.localToolkits() */
|
|
243
|
+
toolkits?: LocalToolkit[];
|
|
244
|
+
/** The original standalone local tools passed at session creation — kept for inline re-injection on later requests. */
|
|
245
|
+
tools?: LocalTool[];
|
|
227
246
|
};
|
|
228
247
|
|
|
229
248
|
// ────────────────────────────────────────────────────────────────
|
|
230
|
-
// Registered
|
|
249
|
+
// Registered local tool types (returned by session.localTools())
|
|
231
250
|
// ────────────────────────────────────────────────────────────────
|
|
232
251
|
|
|
233
|
-
/**
|
|
234
|
-
export interface
|
|
252
|
+
/** One of your local tools as registered in a session, with its final resolved slug. */
|
|
253
|
+
export interface RegisteredLocalTool {
|
|
235
254
|
/** The final slug as registered with the backend (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
|
|
236
255
|
slug: string;
|
|
237
256
|
name: string;
|
|
238
257
|
description: string;
|
|
239
|
-
/** Resolved toolkit — extendsToolkit value,
|
|
258
|
+
/** Resolved toolkit — extendsToolkit value, local toolkit slug, or undefined for standalone */
|
|
240
259
|
toolkit?: string;
|
|
241
260
|
inputSchema: Record<string, unknown>;
|
|
242
261
|
outputSchema?: Record<string, unknown>;
|
|
243
262
|
}
|
|
244
263
|
|
|
245
|
-
/** A
|
|
246
|
-
export interface
|
|
264
|
+
/** A toolkit of local tools as registered in a session, with final slugs on nested tools. */
|
|
265
|
+
export interface RegisteredLocalToolkit {
|
|
247
266
|
slug: string;
|
|
248
267
|
name: string;
|
|
249
268
|
description: string;
|
|
250
|
-
tools:
|
|
269
|
+
tools: RegisteredLocalTool[];
|
|
251
270
|
}
|
|
252
271
|
|
|
272
|
+
/** @deprecated Use `RegisteredLocalTool` instead; local tools were previously called custom tools. */
|
|
273
|
+
export type RegisteredCustomTool = RegisteredLocalTool;
|
|
274
|
+
|
|
275
|
+
/** @deprecated Use `RegisteredLocalToolkit` instead; local toolkits were previously called custom toolkits. */
|
|
276
|
+
export type RegisteredCustomToolkit = RegisteredLocalToolkit;
|
|
277
|
+
|
|
253
278
|
// ────────────────────────────────────────────────────────────────
|
|
254
279
|
// Response types from the backend (slug + original_slug mapping)
|
|
255
280
|
// ────────────────────────────────────────────────────────────────
|
|
256
281
|
|
|
257
282
|
/** Custom tool as returned in the session create response (has prefixed slug + original_slug). */
|
|
258
|
-
export type CustomToolResponse =
|
|
283
|
+
export type CustomToolResponse = NonNullable<
|
|
284
|
+
NonNullable<SessionCreateResponse['experimental']>['custom_tools']
|
|
285
|
+
>[number];
|
|
259
286
|
|
|
260
287
|
/** Custom toolkit as returned in the session create response (has prefixed slugs + original_slugs). */
|
|
261
|
-
export type CustomToolkitResponse =
|
|
288
|
+
export type CustomToolkitResponse = NonNullable<
|
|
289
|
+
NonNullable<NonNullable<SessionCreateResponse['experimental']>['custom_toolkits']>[number]
|
|
290
|
+
>;
|