@composio/core 0.24.0 → 0.26.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-CnJxXr07.mjs → CustomTool-BYHB7sPs.mjs} +1 -1
- package/dist/{CustomTool-CNJysHMK.d.mts → CustomTool-DfP4ldQl.d.mts} +1 -1
- package/dist/{cancellation-BQibgpRG.mjs → cancellation-ZoRh6EJQ.mjs} +55 -3
- package/dist/{composio-BFTtZj82.d.mts → composio-BMDH-1Qj.d.mts} +35 -15
- package/dist/{customTool.types-D57QrTns.d.mts → customTool.types-BoOELgJF.d.mts} +346 -23
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +22 -22
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -8
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -5
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -5
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +56 -21
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +22 -22
- 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 +6 -6
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +14 -14
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -13
- package/dist/{errors-BN15NcCW.mjs → errors-Cly0vXFh.mjs} +5 -5
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +19 -11
- package/dist/index.mjs +693 -196
- package/dist/{types-q8TwAngA.d.mts → types-DHNV_T_z.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 -5
- package/src/composio.ts +81 -67
- package/src/errors/ToolRouterErrors.ts +5 -5
- package/src/lib/toolRouterMcp.ts +2 -0
- package/src/lib/toolRouterParams.ts +28 -16
- package/src/models/ConnectedAccounts.ts +7 -16
- package/src/models/ToolRouter.ts +8 -1
- package/src/models/ToolRouterSession.ts +17 -0
- package/src/models/Tools.ts +1 -4
- package/src/models/Triggers.ts +14 -7
- package/src/services/internal/InternalService.ts +3 -4
- package/src/services/pusher/Pusher.ts +170 -92
- package/src/types/connectedAccountAuthStates.types.ts +2 -1
- package/src/types/pusher.types.ts +2 -0
- package/src/types/requestOptions.types.ts +1 -10
- package/src/types/toolRouter.types.ts +104 -18
- package/src/utils/jsonSchema.ts +76 -4
- package/src/utils/sdk.ts +172 -11
- package/src/utils/session.ts +25 -47
- package/src/utils/toolkitDeprecation.ts +271 -0
- package/src/utils/transformers/connectedAccounts.ts +9 -20
- package/src/utils/transformers/mcp.ts +3 -10
- package/src/utils/userCallback.ts +41 -0
package/src/utils/session.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
2
2
|
// Resolve against the installed package, including slim's copy of the core build.
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { VERSION as clientLibraryVersion } from '@composio/client';
|
|
6
|
-
import type { ComposioRequestHeaders } from '../types/composio.types';
|
|
3
|
+
import manifest from '#client_identity' with { type: 'json' };
|
|
4
|
+
import type { ClientIdentity } from '@composio/client';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Extended globalThis interface for runtime detection
|
|
@@ -93,51 +91,31 @@ function detectRuntime(): string {
|
|
|
93
91
|
|
|
94
92
|
// Detect once at module initialization
|
|
95
93
|
const RUNTIME_ENV = detectRuntime();
|
|
96
|
-
const RuntimeVersionsSchema = z.object({
|
|
97
|
-
Bun: z.object({ version: z.string() }).optional(),
|
|
98
|
-
Deno: z.object({ version: z.object({ deno: z.string() }) }).optional(),
|
|
99
|
-
});
|
|
100
|
-
const runtimeVersions = RuntimeVersionsSchema.safeParse(globalThis);
|
|
101
|
-
const detectRuntimeVersion = (): string | undefined => {
|
|
102
|
-
switch (RUNTIME_ENV) {
|
|
103
|
-
case 'BUN':
|
|
104
|
-
return runtimeVersions.success ? runtimeVersions.data.Bun?.version : undefined;
|
|
105
|
-
case 'DENO':
|
|
106
|
-
return runtimeVersions.success ? runtimeVersions.data.Deno?.version.deno : undefined;
|
|
107
|
-
case 'NODEJS':
|
|
108
|
-
return process.versions.node;
|
|
109
|
-
default:
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const RUNTIME_VERSION = detectRuntimeVersion();
|
|
114
94
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'x-source': 'TYPESCRIPT_SDK',
|
|
121
|
-
'x-runtime': RUNTIME_ENV,
|
|
122
|
-
'x-client-runtime':
|
|
123
|
-
RUNTIME_ENV === 'CLOUDFLARE_WORKERS' ? 'cloudflare' : RUNTIME_ENV.toLowerCase(),
|
|
124
|
-
'x-sdk-version': identity.version,
|
|
125
|
-
'x-client-provenance': identity.name,
|
|
126
|
-
'x-client-version': identity.version,
|
|
127
|
-
'x-client-language': 'typescript',
|
|
128
|
-
'x-client-library': '@composio/client',
|
|
129
|
-
'x-client-library-version': clientLibraryVersion,
|
|
130
|
-
...(RUNTIME_VERSION ? { 'x-runtime-version': RUNTIME_VERSION } : {}),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
95
|
+
/**
|
|
96
|
+
* An identity value is sent as a header, so the client accepts only non-empty
|
|
97
|
+
* printable ASCII with no leading or trailing whitespace.
|
|
98
|
+
*/
|
|
99
|
+
const HEADER_SAFE = /^[\x21-\x7e](?:[\x20-\x7e]*[\x21-\x7e])?$/;
|
|
133
100
|
|
|
134
|
-
|
|
135
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The identity the API client reports for this SDK: its product headers
|
|
103
|
+
* (`x-client-provenance`, `x-client-version`, `x-sdk-version`) and the legacy
|
|
104
|
+
* `x-source`, `x-framework` and `x-runtime` labels. The client adds the
|
|
105
|
+
* library headers and detects the runtime and its version itself.
|
|
106
|
+
*
|
|
107
|
+
* A custom provider whose name cannot be sent as a header value is reported
|
|
108
|
+
* as `unknown` rather than making the SDK fail to construct.
|
|
109
|
+
*/
|
|
110
|
+
export function getClientIdentity(
|
|
136
111
|
provider: BaseComposioProvider<unknown, unknown, unknown> | undefined
|
|
137
|
-
)
|
|
138
|
-
const
|
|
112
|
+
): ClientIdentity {
|
|
113
|
+
const framework = provider?.name;
|
|
139
114
|
return {
|
|
140
|
-
|
|
141
|
-
|
|
115
|
+
product: manifest.name,
|
|
116
|
+
version: manifest.version,
|
|
117
|
+
source: 'TYPESCRIPT_SDK',
|
|
118
|
+
framework: framework && HEADER_SAFE.test(framework) ? framework : 'unknown',
|
|
119
|
+
runtime: RUNTIME_ENV,
|
|
142
120
|
};
|
|
143
|
-
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolkit version deprecation warnings.
|
|
3
|
+
*
|
|
4
|
+
* When a request resolves to a deprecated toolkit version, the API adds a
|
|
5
|
+
* `Composio-Deprecated-Toolkits` response header (an RFC 9651 structured-field
|
|
6
|
+
* list). This module parses that header below the generated client, through a
|
|
7
|
+
* `fetch` wrapper, and warns once per process for each deprecated toolkit
|
|
8
|
+
* version it sees. The response itself is never read, cloned or altered.
|
|
9
|
+
*
|
|
10
|
+
* Example header:
|
|
11
|
+
*
|
|
12
|
+
* "GMAIL";version="20250114_00";deprecated=@1779840000;sunset=@1787788800;reason="lifecycle"
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import logger from './logger';
|
|
16
|
+
import { normalizeToolkitSlug } from './toolkitVersion';
|
|
17
|
+
|
|
18
|
+
/** Response header name. `Headers.get` is case-insensitive. */
|
|
19
|
+
export const TOOLKIT_DEPRECATION_HEADER = 'composio-deprecated-toolkits';
|
|
20
|
+
|
|
21
|
+
/** Anchor of the docs section every warning points at. */
|
|
22
|
+
export const TOOLKIT_DEPRECATION_DOCS_URL =
|
|
23
|
+
'https://docs.composio.dev/docs/tools-direct/toolkit-versioning#deprecation-and-sunset';
|
|
24
|
+
|
|
25
|
+
/** Versions named per toolkit before the formatter collapses the rest into "and N more". */
|
|
26
|
+
const MAX_VERSIONS_PER_LINE = 5;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The three limits below mirror the `@composio/client` deprecation module,
|
|
30
|
+
* which reads the same kind of server-controlled header.
|
|
31
|
+
*/
|
|
32
|
+
/** A header longer than this is ignored whole rather than parsed. */
|
|
33
|
+
const MAX_HEADER_LENGTH = 2048;
|
|
34
|
+
/** A header holding any of these is ignored whole, so nothing partially cleaned reaches the log. */
|
|
35
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
36
|
+
/** Keys the process will ever record; past this, new versions are neither recorded nor warned about. */
|
|
37
|
+
const MAX_TRACKED_VERSIONS = 1024;
|
|
38
|
+
|
|
39
|
+
const DeprecatedToolkitEntrySchema = z.object({
|
|
40
|
+
slug: z.string().min(1),
|
|
41
|
+
version: z.string().min(1),
|
|
42
|
+
deprecatedAt: z.date().optional(),
|
|
43
|
+
sunsetAt: z.date().optional(),
|
|
44
|
+
reason: z.string().min(1).optional(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type DeprecatedToolkitEntry = z.infer<typeof DeprecatedToolkitEntrySchema>;
|
|
48
|
+
|
|
49
|
+
/** Keys (`UPPER(slug)@version`) already warned about in this process. */
|
|
50
|
+
const warnedToolkitVersions = new Set<string>();
|
|
51
|
+
|
|
52
|
+
const dedupeKey = (entry: Pick<DeprecatedToolkitEntry, 'slug' | 'version'>): string =>
|
|
53
|
+
`${entry.slug.toUpperCase()}@${entry.version}`;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Splits `value` on `delimiter` characters that sit outside double-quoted
|
|
57
|
+
* strings, honouring backslash escapes inside the quotes. Empty pieces are
|
|
58
|
+
* dropped and the rest are trimmed.
|
|
59
|
+
*/
|
|
60
|
+
const splitOutsideQuotes = (value: string, delimiter: string): string[] => {
|
|
61
|
+
const pieces: string[] = [];
|
|
62
|
+
let current = '';
|
|
63
|
+
let inString = false;
|
|
64
|
+
for (let index = 0; index < value.length; index++) {
|
|
65
|
+
const char = value[index];
|
|
66
|
+
if (inString) {
|
|
67
|
+
current += char;
|
|
68
|
+
if (char === '\\' && index + 1 < value.length) {
|
|
69
|
+
index += 1;
|
|
70
|
+
current += value[index];
|
|
71
|
+
} else if (char === '"') {
|
|
72
|
+
inString = false;
|
|
73
|
+
}
|
|
74
|
+
} else if (char === '"') {
|
|
75
|
+
inString = true;
|
|
76
|
+
current += char;
|
|
77
|
+
} else if (char === delimiter) {
|
|
78
|
+
pieces.push(current);
|
|
79
|
+
current = '';
|
|
80
|
+
} else {
|
|
81
|
+
current += char;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
pieces.push(current);
|
|
85
|
+
return pieces.map(piece => piece.trim()).filter(piece => piece.length > 0);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Decodes an sf-string (`"..."` with `\"` and `\\` escapes). Returns
|
|
90
|
+
* `undefined` for anything that is not a complete, validly escaped sf-string.
|
|
91
|
+
*/
|
|
92
|
+
const decodeSfString = (raw: string): string | undefined => {
|
|
93
|
+
const match = /^"((?:[^"\\]|\\.)*)"$/.exec(raw);
|
|
94
|
+
if (match === null) return undefined;
|
|
95
|
+
let invalidEscape = false;
|
|
96
|
+
const decoded = match[1].replace(/\\(.)/g, (_whole, escaped: string) => {
|
|
97
|
+
if (escaped === '"' || escaped === '\\') return escaped;
|
|
98
|
+
invalidEscape = true;
|
|
99
|
+
return '';
|
|
100
|
+
});
|
|
101
|
+
return invalidEscape ? undefined : decoded;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Decodes an sf-date (`@` followed by Unix seconds). */
|
|
105
|
+
const decodeSfDate = (raw: string): Date | undefined => {
|
|
106
|
+
const match = /^@(-?\d{1,15})$/.exec(raw);
|
|
107
|
+
if (match === null) return undefined;
|
|
108
|
+
const date = new Date(Number(match[1]) * 1000);
|
|
109
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Header parameters the SDK understands, by wire name. */
|
|
113
|
+
const KNOWN_PARAMETERS = new Map<
|
|
114
|
+
string,
|
|
115
|
+
{ name: Exclude<keyof DeprecatedToolkitEntry, 'slug'>; kind: 'string' | 'date' }
|
|
116
|
+
>([
|
|
117
|
+
['version', { name: 'version', kind: 'string' }],
|
|
118
|
+
['reason', { name: 'reason', kind: 'string' }],
|
|
119
|
+
['deprecated', { name: 'deprecatedAt', kind: 'date' }],
|
|
120
|
+
['sunset', { name: 'sunsetAt', kind: 'date' }],
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Parses one list item: an sf-string slug followed by `;key=value` parameters.
|
|
125
|
+
* Unknown parameters are ignored; a known parameter with the wrong type drops
|
|
126
|
+
* the item.
|
|
127
|
+
*/
|
|
128
|
+
const parseItem = (item: string): DeprecatedToolkitEntry | undefined => {
|
|
129
|
+
const [head, ...params] = splitOutsideQuotes(item, ';');
|
|
130
|
+
if (head === undefined) return undefined;
|
|
131
|
+
const candidate: Record<string, unknown> = { slug: decodeSfString(head) };
|
|
132
|
+
for (const param of params) {
|
|
133
|
+
const separator = param.indexOf('=');
|
|
134
|
+
if (separator === -1) continue;
|
|
135
|
+
const key = param.slice(0, separator).trim();
|
|
136
|
+
const rawValue = param.slice(separator + 1).trim();
|
|
137
|
+
const field = KNOWN_PARAMETERS.get(key);
|
|
138
|
+
if (field === undefined) continue;
|
|
139
|
+
const decoded = field.kind === 'string' ? decodeSfString(rawValue) : decodeSfDate(rawValue);
|
|
140
|
+
if (decoded === undefined) return undefined;
|
|
141
|
+
candidate[field.name] = decoded;
|
|
142
|
+
}
|
|
143
|
+
const parsed = DeprecatedToolkitEntrySchema.safeParse(candidate);
|
|
144
|
+
return parsed.success ? parsed.data : undefined;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Parses a `Composio-Deprecated-Toolkits` header value. Items that fail to
|
|
149
|
+
* parse are dropped silently; garbage input yields an empty array. Never throws.
|
|
150
|
+
*/
|
|
151
|
+
export function parseDeprecatedToolkitsHeader(value: string): DeprecatedToolkitEntry[] {
|
|
152
|
+
try {
|
|
153
|
+
const entries: DeprecatedToolkitEntry[] = [];
|
|
154
|
+
for (const item of splitOutsideQuotes(value, ',')) {
|
|
155
|
+
const entry = parseItem(item);
|
|
156
|
+
if (entry !== undefined) entries.push(entry);
|
|
157
|
+
}
|
|
158
|
+
return entries;
|
|
159
|
+
} catch {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isoDate = (date: Date): string => date.toISOString().slice(0, 10);
|
|
165
|
+
|
|
166
|
+
const pinHint = (slug: string, docsUrl: string): string => {
|
|
167
|
+
const configKey = normalizeToolkitSlug(slug);
|
|
168
|
+
const envVar = `COMPOSIO_TOOLKIT_VERSION_${slug.toUpperCase()}`;
|
|
169
|
+
return `Pin a newer version with toolkitVersions: { ${configKey}: '<version>' } or ${envVar}. See ${docsUrl}.`;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const formatSingle = (entry: DeprecatedToolkitEntry, docsUrl: string): string => {
|
|
173
|
+
let sentence = `[Deprecation] Toolkit ${entry.slug.toUpperCase()} version ${entry.version} was deprecated`;
|
|
174
|
+
if (entry.deprecatedAt !== undefined) sentence += ` on ${isoDate(entry.deprecatedAt)}`;
|
|
175
|
+
if (entry.reason !== undefined) sentence += ` (${entry.reason})`;
|
|
176
|
+
if (entry.sunsetAt !== undefined)
|
|
177
|
+
sentence += ` and will stop working on ${isoDate(entry.sunsetAt)}`;
|
|
178
|
+
return `${sentence}. ${pinHint(entry.slug, docsUrl)}`;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const formatGroup = (slug: string, entries: DeprecatedToolkitEntry[], docsUrl: string): string => {
|
|
182
|
+
const versions = entries.map(entry => entry.version);
|
|
183
|
+
const named = versions.slice(0, MAX_VERSIONS_PER_LINE).join(', ');
|
|
184
|
+
const remaining = versions.length - MAX_VERSIONS_PER_LINE;
|
|
185
|
+
const list = remaining > 0 ? `${named} and ${remaining} more` : named;
|
|
186
|
+
let sentence = `[Deprecation] Toolkit ${slug} versions ${list} are deprecated`;
|
|
187
|
+
const sunsets = entries
|
|
188
|
+
.map(entry => entry.sunsetAt)
|
|
189
|
+
.filter((date): date is Date => date !== undefined)
|
|
190
|
+
.sort((a, b) => a.getTime() - b.getTime());
|
|
191
|
+
if (sunsets.length > 0) {
|
|
192
|
+
sentence += ` and the earliest will stop working on ${isoDate(sunsets[0])}`;
|
|
193
|
+
}
|
|
194
|
+
return `${sentence}. ${pinHint(slug, docsUrl)}`;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Renders one warning line per toolkit slug. A slug with a single deprecated
|
|
199
|
+
* version gets the full sentence with its dates and reason; a slug with several
|
|
200
|
+
* names at most five versions and collapses the rest into "and N more".
|
|
201
|
+
*/
|
|
202
|
+
export function formatToolkitDeprecationWarnings(
|
|
203
|
+
entries: DeprecatedToolkitEntry[],
|
|
204
|
+
docsUrl: string = TOOLKIT_DEPRECATION_DOCS_URL
|
|
205
|
+
): string[] {
|
|
206
|
+
const groups = new Map<string, DeprecatedToolkitEntry[]>();
|
|
207
|
+
for (const entry of entries) {
|
|
208
|
+
const slug = entry.slug.toUpperCase();
|
|
209
|
+
const group = groups.get(slug);
|
|
210
|
+
if (group === undefined) groups.set(slug, [entry]);
|
|
211
|
+
else group.push(entry);
|
|
212
|
+
}
|
|
213
|
+
return Array.from(groups, ([slug, group]) =>
|
|
214
|
+
group.length === 1 ? formatSingle(group[0], docsUrl) : formatGroup(slug, group, docsUrl)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Parses the header on `response`, drops versions already warned about in this
|
|
220
|
+
* process, records the new ones and warns once per formatted line.
|
|
221
|
+
*/
|
|
222
|
+
const warnDeprecatedToolkits = (response: Response): void => {
|
|
223
|
+
const value = response.headers.get(TOOLKIT_DEPRECATION_HEADER);
|
|
224
|
+
if (value === null || value.length === 0) return;
|
|
225
|
+
if (value.length > MAX_HEADER_LENGTH || CONTROL_CHARACTERS.test(value)) return;
|
|
226
|
+
if (warnedToolkitVersions.size >= MAX_TRACKED_VERSIONS) return;
|
|
227
|
+
const fresh: DeprecatedToolkitEntry[] = [];
|
|
228
|
+
for (const entry of parseDeprecatedToolkitsHeader(value)) {
|
|
229
|
+
const key = dedupeKey(entry);
|
|
230
|
+
if (warnedToolkitVersions.has(key) || warnedToolkitVersions.size >= MAX_TRACKED_VERSIONS)
|
|
231
|
+
continue;
|
|
232
|
+
warnedToolkitVersions.add(key);
|
|
233
|
+
fresh.push(entry);
|
|
234
|
+
}
|
|
235
|
+
for (const line of formatToolkitDeprecationWarnings(fresh)) {
|
|
236
|
+
logger.warn(line);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Wraps a `fetch` implementation so every response is checked for the
|
|
242
|
+
* `Composio-Deprecated-Toolkits` header. The wrapper is `this`-independent,
|
|
243
|
+
* returns the response unchanged on every path and never fails a call over
|
|
244
|
+
* the header: any error while inspecting it is logged at debug and swallowed.
|
|
245
|
+
*
|
|
246
|
+
* When no `baseFetch` is given, `globalThis.fetch` is resolved per call so a
|
|
247
|
+
* runtime that installs or replaces `fetch` after construction still works.
|
|
248
|
+
*/
|
|
249
|
+
export function createToolkitDeprecationFetch(
|
|
250
|
+
baseFetch?: typeof globalThis.fetch
|
|
251
|
+
): typeof globalThis.fetch {
|
|
252
|
+
return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
253
|
+
const target = baseFetch ?? globalThis.fetch;
|
|
254
|
+
const response = await target(input, init);
|
|
255
|
+
try {
|
|
256
|
+
warnDeprecatedToolkits(response);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
try {
|
|
259
|
+
logger.debug('Failed to inspect the toolkit deprecation header', error);
|
|
260
|
+
} catch {
|
|
261
|
+
// The fallback is best-effort too: a sink that throws must not fail the call.
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return response;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Clears the once-per-process record. Tests only. */
|
|
269
|
+
export function _resetToolkitDeprecationWarningsForTests(): void {
|
|
270
|
+
warnedToolkitVersions.clear();
|
|
271
|
+
}
|
|
@@ -23,13 +23,6 @@ import { ConnectionDataSchema } from '../../types/connectedAccountAuthStates.typ
|
|
|
23
23
|
import logger from '../logger';
|
|
24
24
|
import { transform } from '../transform';
|
|
25
25
|
|
|
26
|
-
type RawConnectedAccountResponseWithLabels = (
|
|
27
|
-
RawConnectedAccountRetrieveResponse | RawConnectedAccountListResponse['items'][0]
|
|
28
|
-
) & {
|
|
29
|
-
word_id?: string | null;
|
|
30
|
-
alias?: string | null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
26
|
/**
|
|
34
27
|
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
35
28
|
*
|
|
@@ -45,8 +38,6 @@ type RawConnectedAccountResponseWithLabels = (
|
|
|
45
38
|
export function transformConnectedAccountResponse(
|
|
46
39
|
response: RawConnectedAccountRetrieveResponse | RawConnectedAccountListResponse['items'][0]
|
|
47
40
|
): ConnectedAccountRetrieveResponse {
|
|
48
|
-
const responseWithLabels = response as RawConnectedAccountResponseWithLabels;
|
|
49
|
-
|
|
50
41
|
// Safely parse the state field, filtering out unsupported auth schemes
|
|
51
42
|
const parseState = (state: unknown) => {
|
|
52
43
|
try {
|
|
@@ -70,9 +61,9 @@ export function transformConnectedAccountResponse(
|
|
|
70
61
|
isComposioManaged: response.auth_config.is_composio_managed,
|
|
71
62
|
isDisabled: response.auth_config.is_disabled,
|
|
72
63
|
},
|
|
73
|
-
wordId:
|
|
74
|
-
alias:
|
|
75
|
-
data:
|
|
64
|
+
wordId: response.word_id ?? null,
|
|
65
|
+
alias: response.alias ?? null,
|
|
66
|
+
data: response.data ?? undefined,
|
|
76
67
|
state: parseState(response.state),
|
|
77
68
|
status: response.status,
|
|
78
69
|
statusReason: response.status_reason,
|
|
@@ -86,17 +77,15 @@ export function transformConnectedAccountResponse(
|
|
|
86
77
|
// caller isn't authorised to see the ACL), so distinguish "I can't
|
|
87
78
|
// see the ACL" from "ACL is the default deny-by-default state" by
|
|
88
79
|
// checking field presence.
|
|
89
|
-
experimental:
|
|
80
|
+
experimental: response.experimental
|
|
90
81
|
? {
|
|
91
|
-
accountType:
|
|
92
|
-
aclConfigForShared:
|
|
82
|
+
accountType: response.experimental.account_type,
|
|
83
|
+
aclConfigForShared: response.experimental.acl_config_for_shared
|
|
93
84
|
? {
|
|
94
|
-
allowAllUsers:
|
|
95
|
-
|
|
96
|
-
allowedUserIds:
|
|
97
|
-
responseWithLabels.experimental.acl_config_for_shared.allowed_user_ids,
|
|
85
|
+
allowAllUsers: response.experimental.acl_config_for_shared.allow_all_users,
|
|
86
|
+
allowedUserIds: response.experimental.acl_config_for_shared.allowed_user_ids,
|
|
98
87
|
notAllowedUserIds:
|
|
99
|
-
|
|
88
|
+
response.experimental.acl_config_for_shared.not_allowed_user_ids,
|
|
100
89
|
}
|
|
101
90
|
: undefined,
|
|
102
91
|
}
|
|
@@ -32,9 +32,6 @@ export function transformMcpCreateResponse(
|
|
|
32
32
|
const result = CustomCreateResponseSchema.safeParse({
|
|
33
33
|
id: response.id,
|
|
34
34
|
name: response.name,
|
|
35
|
-
createdAt: (response as unknown as Record<string, unknown>).created_at,
|
|
36
|
-
updatedAt: (response as unknown as Record<string, unknown>).updated_at,
|
|
37
|
-
status: (response as unknown as Record<string, unknown>).status,
|
|
38
35
|
});
|
|
39
36
|
|
|
40
37
|
if (!result.success) {
|
|
@@ -55,7 +52,6 @@ export function transformMcpListResponse(response: McpListResponseRaw): McpListR
|
|
|
55
52
|
name: item.name,
|
|
56
53
|
createdAt: item.created_at,
|
|
57
54
|
updatedAt: item.updated_at,
|
|
58
|
-
status: (item as unknown as Record<string, unknown>).status,
|
|
59
55
|
}));
|
|
60
56
|
|
|
61
57
|
const result = McpListResponseSchema.safeParse({
|
|
@@ -82,7 +78,6 @@ export function transformMcpRetrieveResponse(
|
|
|
82
78
|
name: response.name,
|
|
83
79
|
createdAt: response.created_at,
|
|
84
80
|
updatedAt: response.updated_at,
|
|
85
|
-
status: (response as unknown as Record<string, unknown>).status,
|
|
86
81
|
toolkits: response.toolkits,
|
|
87
82
|
tools: response.allowed_tools,
|
|
88
83
|
managedAuthViaComposio: response.managed_auth_via_composio,
|
|
@@ -105,9 +100,8 @@ export function transformMcpRetrieveResponse(
|
|
|
105
100
|
*/
|
|
106
101
|
export function transformMcpDeleteResponse(response: McpDeleteResponseRaw): McpDeleteResponse {
|
|
107
102
|
const result = McpDeleteResponseSchema.safeParse({
|
|
108
|
-
id:
|
|
109
|
-
deleted:
|
|
110
|
-
message: (response as unknown as Record<string, unknown>).message,
|
|
103
|
+
id: response.id,
|
|
104
|
+
deleted: response.deleted,
|
|
111
105
|
});
|
|
112
106
|
|
|
113
107
|
if (!result.success) {
|
|
@@ -128,9 +122,8 @@ export function transformMcpUpdateResponse(response: McpUpdateResponseRaw): McpU
|
|
|
128
122
|
name: response.name,
|
|
129
123
|
createdAt: response.created_at,
|
|
130
124
|
updatedAt: response.updated_at,
|
|
131
|
-
status: (response as unknown as Record<string, unknown>).status,
|
|
132
125
|
toolkits: response.toolkits,
|
|
133
|
-
tools:
|
|
126
|
+
tools: response.allowed_tools,
|
|
134
127
|
});
|
|
135
128
|
|
|
136
129
|
if (!result.success) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import logger from './logger';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes a thrown or rejected value for a log line without ever throwing.
|
|
5
|
+
*
|
|
6
|
+
* The logger serializes object arguments with `JSON.stringify`, which turns an `Error` into `{}`
|
|
7
|
+
* and throws on a circular value, so callers log this string instead of the raw value.
|
|
8
|
+
* `JSON.stringify` and `String()` can both throw (a circular value, an object without a
|
|
9
|
+
* prototype), so each is tried in turn.
|
|
10
|
+
*/
|
|
11
|
+
export function describeThrown(value: unknown): string {
|
|
12
|
+
try {
|
|
13
|
+
if (value instanceof Error) return value.message;
|
|
14
|
+
if (typeof value === 'object' && value !== null) return JSON.stringify(value) ?? String(value);
|
|
15
|
+
return String(value);
|
|
16
|
+
} catch {
|
|
17
|
+
try {
|
|
18
|
+
return String(value);
|
|
19
|
+
} catch {
|
|
20
|
+
return '[unprintable value]';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calls a user-supplied event callback so that neither a synchronous throw nor a rejected promise
|
|
27
|
+
* escapes into the event emitter that invoked it. Failures are logged after `label`.
|
|
28
|
+
*
|
|
29
|
+
* pusher-js does not catch listener exceptions, and nothing awaits the promise an `async`
|
|
30
|
+
* listener returns, so an escaped failure would end a Node process.
|
|
31
|
+
*/
|
|
32
|
+
export function invokeUserCallback(label: string, callback: () => unknown): void {
|
|
33
|
+
const logFailure = (error: unknown) => {
|
|
34
|
+
logger.error(label, describeThrown(error));
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
Promise.resolve(callback()).catch(logFailure);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logFailure(error);
|
|
40
|
+
}
|
|
41
|
+
}
|