@composio/core 0.21.0 → 0.23.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.
Files changed (59) hide show
  1. package/dist/{CustomTool-BHOYxLZX.d.mts → CustomTool-CnHdegDK.d.mts} +1 -1
  2. package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
  3. package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
  4. package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
  5. package/dist/{composio-BTZsFajb.d.mts → composio-Dq708dZS.d.mts} +81 -185
  6. package/dist/{customTool.types-D_w21L56.d.mts → customTool.types-B8lVpHOP.d.mts} +77 -59
  7. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
  8. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
  9. package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
  12. package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
  13. package/dist/experimental/index.d.mts +2 -2
  14. package/dist/experimental/index.mjs +1 -1
  15. package/dist/index.d.mts +46 -6
  16. package/dist/index.mjs +315 -363
  17. package/dist/models/Files.node.mjs +1 -1
  18. package/dist/platform/node.d.mts +1 -1
  19. package/dist/platform/node.mjs +13 -0
  20. package/dist/platform/workerd.d.mts +1 -1
  21. package/dist/platform/workerd.mjs +3 -0
  22. package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
  23. package/dist/{types-CgRsUGqm.d.mts → types-eTw8Yw7Y.d.mts} +2 -2
  24. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  25. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  26. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  27. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  28. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  29. package/package.json +10 -7
  30. package/src/errors/ToolRouterErrors.ts +65 -0
  31. package/src/lib/toolRouterParams.ts +8 -10
  32. package/src/models/AuthConfigs.ts +0 -9
  33. package/src/models/ConnectionRequest.ts +21 -18
  34. package/src/models/CustomToolkits.ts +1 -1
  35. package/src/models/Logs.ts +2 -2
  36. package/src/models/RemoteFile.ts +24 -5
  37. package/src/models/SessionContext.ts +24 -4
  38. package/src/models/ToolRouter.ts +3 -3
  39. package/src/models/ToolRouterSession.ts +45 -13
  40. package/src/models/Tools.ts +21 -37
  41. package/src/models/Usage.ts +2 -1
  42. package/src/models/customToolExecution.ts +10 -0
  43. package/src/platform/node.ts +16 -0
  44. package/src/platform/types.ts +3 -0
  45. package/src/platform/workerd.ts +4 -0
  46. package/src/provider/BaseProvider.ts +2 -1
  47. package/src/provider/OpenAIProvider.ts +0 -283
  48. package/src/telemetry/Telemetry.ts +4 -2
  49. package/src/types/logs.types.ts +9 -1
  50. package/src/types/tool.types.ts +8 -3
  51. package/src/types/toolRouter.types.ts +27 -19
  52. package/src/types/usage.types.ts +2 -0
  53. package/src/utils/jsonSchema.ts +191 -36
  54. package/src/utils/retries.ts +20 -0
  55. package/src/utils/safePath.ts +135 -54
  56. package/src/utils/session.ts +31 -2
  57. package/src/utils/transformers/logs.ts +3 -2
  58. package/src/utils/transformers/toolRouterResponseTransform.ts +69 -12
  59. package/src/utils/transformers/usage.ts +1 -0
@@ -17,14 +17,21 @@ import { ValidationError } from '../errors/ValidationErrors';
17
17
 
18
18
  /**
19
19
  * Upper bound on a filename, well under the 255-byte limit common to
20
- * ext4/APFS/NTFS. Keeps a long server-supplied name from failing with a raw
21
- * `ENAMETOOLONG` mid-write. Matches `MAX_COMPONENT_LENGTH` in the Python SDK.
20
+ * ext4/APFS/NTFS. A longer server-supplied name is truncated to fit rather
21
+ * than failing with a raw `ENAMETOOLONG` mid-write. Matches
22
+ * `MAX_COMPONENT_LENGTH` in the Python SDK.
22
23
  */
23
24
  export const MAX_FILENAME_BYTES = 128;
24
25
 
26
+ /**
27
+ * Longest extension, in bytes and including its dot, that truncation keeps.
28
+ * Anything longer is not a real extension and is truncated with the rest.
29
+ */
30
+ const MAX_PRESERVED_EXTENSION_BYTES = 32;
31
+
25
32
  /**
26
33
  * Reserved DOS device names. Writing to one on Windows targets the device
27
- * rather than a file. Rejected on every platform so behavior does not diverge
34
+ * rather than a file. Prefixed on every platform so behavior does not diverge
28
35
  * between a POSIX developer machine and a Windows deployment.
29
36
  */
30
37
  const WINDOWS_RESERVED_NAMES: ReadonlySet<string> = new Set([
@@ -38,7 +45,28 @@ const WINDOWS_RESERVED_NAMES: ReadonlySet<string> = new Set([
38
45
  ]);
39
46
 
40
47
  /** Control characters and characters reserved by Windows. */
41
- const WINDOWS_INVALID_CHARS = /[\u0000-\u001f<>:"|?*]/;
48
+ const WINDOWS_INVALID_CHARS = /[\u0000-\u001f<>:"|?*]/g;
49
+
50
+ /** Windows drops trailing spaces and dots from a filename. */
51
+ const TRAILING_SPACES_AND_DOTS = /[. ]+$/;
52
+
53
+ const utf8Length = (value: string): number => new TextEncoder().encode(value).length;
54
+
55
+ const FNV_OFFSET_BASIS_64 = 0xcbf29ce484222325n;
56
+ const FNV_PRIME_64 = 0x100000001b3n;
57
+ const UINT64_MASK = 0xffffffffffffffffn;
58
+
59
+ /**
60
+ * 64-bit FNV-1a of the UTF-8 bytes, as 16 hex digits. Pure and synchronous, so
61
+ * it runs on every runtime; `_fnv1a64_hex` in the Python SDK matches it.
62
+ */
63
+ function fnv1a64Hex(value: string): string {
64
+ let hash = FNV_OFFSET_BASIS_64;
65
+ for (const byte of new TextEncoder().encode(value)) {
66
+ hash = ((hash ^ BigInt(byte)) * FNV_PRIME_64) & UINT64_MASK;
67
+ }
68
+ return hash.toString(16).padStart(16, '0');
69
+ }
42
70
 
43
71
  /**
44
72
  * Python str.strip() whitespace: Unicode White_Space plus U+001C–U+001F.
@@ -93,80 +121,133 @@ function hasLoneSurrogate(value: string): boolean {
93
121
  return false;
94
122
  }
95
123
 
124
+ /** The longest prefix of `value`, by whole code points, that fits in `maxBytes`. */
125
+ function truncateToBytes(value: string, maxBytes: number): string {
126
+ let truncated = '';
127
+ let bytes = 0;
128
+ for (const char of value) {
129
+ bytes += utf8Length(char);
130
+ if (bytes > maxBytes) {
131
+ break;
132
+ }
133
+ truncated += char;
134
+ }
135
+ return truncated;
136
+ }
137
+
138
+ /** Splits off a short trailing extension (with its dot); a leading dot is not one. */
139
+ function splitExtension(name: string): [stem: string, extension: string] {
140
+ const dot = name.lastIndexOf('.');
141
+ const extension = dot > 0 ? name.slice(dot) : '';
142
+ return extension && utf8Length(extension) <= MAX_PRESERVED_EXTENSION_BYTES
143
+ ? [name.slice(0, dot), extension]
144
+ : [name, ''];
145
+ }
146
+
96
147
  /**
97
- * Collapses an untrusted filename to a bare, writable basename.
148
+ * Truncates `name` to `maxBytes`, keeping a short extension so the file still
149
+ * opens with the right application.
150
+ */
151
+ function fitFilenameBytes(name: string, maxBytes: number = MAX_FILENAME_BYTES): string {
152
+ if (utf8Length(name) <= maxBytes) {
153
+ return name;
154
+ }
155
+ const [stem, extension] = splitExtension(name);
156
+ return truncateToBytes(stem, maxBytes - utf8Length(extension)) + extension;
157
+ }
158
+
159
+ /** Adds a copy number before the extension without exceeding the filename byte limit. */
160
+ export function numberedBasename(name: string, copy: number): string {
161
+ const suffix = `-${copy}`;
162
+ const [stem, extension] = splitExtension(name);
163
+ return (
164
+ truncateToBytes(stem, MAX_FILENAME_BYTES - utf8Length(extension) - suffix.length) +
165
+ suffix +
166
+ extension
167
+ );
168
+ }
169
+
170
+ /**
171
+ * Tags a name that portability changed with a digest of the name it came
172
+ * from, before the extension: `report?.png` and `report*.png` both become
173
+ * `report_.png`, and two long names can share a truncated prefix, so without
174
+ * the tag one download would overwrite the other in a shared directory.
175
+ */
176
+ function tagWithOriginal(portable: string, original: string): string {
177
+ const tag = `-${fnv1a64Hex(original)}`;
178
+ const [stem, extension] = splitExtension(
179
+ fitFilenameBytes(portable, MAX_FILENAME_BYTES - tag.length)
180
+ );
181
+ return stem + tag + extension;
182
+ }
183
+
184
+ /**
185
+ * Collapses an untrusted filename to a bare basename that is safe to write on
186
+ * every platform.
98
187
  *
99
- * Applies, in order: no usable basename (empty or a run of dots once
100
- * surrounding whitespace is stripped), NUL bytes, control and Windows-reserved
101
- * characters, trailing space or dot, invalid Unicode, a byte-length bound, and
102
- * reserved device names. This is the order `safe_basename` uses in the Python
103
- * SDK. This implementation rejects lone surrogates rather than relying on
104
- * Python filesystem encoding behavior.
188
+ * Names that cannot be written at all are refused: a NUL byte, invalid
189
+ * Unicode, or no usable basename (empty or a run of dots). A response that
190
+ * cannot name its own file is malformed or hostile, and inventing a name would
191
+ * hide that. `""`, `"."` and `".."` make an output path equal to, or escape,
192
+ * its own directory, which surfaces as a raw `EISDIR` at write time instead of
193
+ * a validation error.
105
194
  *
106
- * Names that leave no usable basename are refused rather than replaced with a
107
- * generated one: a response that cannot name its own file is malformed or
108
- * hostile, and inventing a name would hide that. `""`, `"."` and `".."` make
109
- * an output path equal to, or escape, its own directory, which surfaces as a
110
- * raw `EISDIR` at write time instead of a validation error.
195
+ * Names that are merely unportable are made portable instead, because ordinary
196
+ * files have them (`report_2026-09-29T10:30:00.csv`, `What is this?.png`), on
197
+ * every platform so a name does not depend on where the SDK runs:
198
+ * control and Windows-reserved characters become `_`, names over
199
+ * {@link MAX_FILENAME_BYTES} are truncated with their extension kept, trailing
200
+ * spaces and dots are dropped as Windows would, and a resulting reserved
201
+ * device name gets a `_` prefix. A name any of these rules changed is then
202
+ * tagged with a digest of the original before its extension
203
+ * (`report_-<16 hex>.png`) to distinguish ordinary normalization collisions;
204
+ * a name that was already portable is returned unchanged. A result can still
205
+ * equal a literal server name, so default saves create files exclusively.
206
+ * `safe_basename` in
207
+ * the Python SDK applies the same rules in the same order.
111
208
  *
112
- * The usability check runs on the *trimmed* basename because that is what gets
113
- * written: Python-compatible stripping removes whitespace, so `"\u00a0.\u00a0"` would
114
- * otherwise pass a check on the raw segment and then be written as `"."`. The
115
- * hazard checks that follow run on the raw segment so a trailing ASCII space or
116
- * dot is refused, not trimmed away. Check the stripped value for trailing dots
117
- * too, since stripping whitespace can expose one.
209
+ * Python-compatible stripping removes surrounding whitespace first, and the
210
+ * usability check runs last, on the value that gets written, so neither
211
+ * `"\u00a0.\u00a0"` nor `". ."` can be written as `.` or as its own directory.
118
212
  *
119
213
  * @param name - The untrusted filename or relative path to reduce.
120
214
  * @param label - How the value is described in error messages.
121
- * @returns The validated bare basename, with surrounding whitespace trimmed.
122
- * @throws ValidationError if `name` yields no usable basename or is unsafe to write.
215
+ * @returns The bare basename to write, adjusted to be portable.
216
+ * @throws ValidationError if `name` contains a NUL byte or invalid Unicode, or
217
+ * leaves no usable basename.
123
218
  */
124
219
  export function safeBasename(name: string, label: string = 'filename'): string {
125
- const rawBasename = untrustedBasename(name);
126
- const basename = rawBasename.replace(SURROUNDING_WHITESPACE, '');
220
+ const basename = untrustedBasename(name).replace(SURROUNDING_WHITESPACE, '');
127
221
 
128
- if (!basename || /^\.+$/.test(basename)) {
129
- throw new ValidationError(
130
- `Path traversal detected: ${label} ${JSON.stringify(name)} leaves no usable basename to write to.`
131
- );
132
- }
133
- if (rawBasename.includes('\u0000')) {
222
+ if (basename.includes('\u0000')) {
134
223
  throw new ValidationError(
135
224
  `Refusing to write ${label} containing a NUL byte: ${JSON.stringify(name)}`
136
225
  );
137
226
  }
138
- if (WINDOWS_INVALID_CHARS.test(rawBasename)) {
139
- throw new ValidationError(
140
- `Refusing to write ${label} containing characters reserved by Windows: ${JSON.stringify(name)}`
141
- );
142
- }
143
- if (rawBasename.endsWith(' ') || rawBasename.endsWith('.') || basename.endsWith('.')) {
144
- throw new ValidationError(
145
- `Refusing to write ${label} ending in a space or dot: ${JSON.stringify(name)}`
146
- );
147
- }
148
227
  if (hasLoneSurrogate(basename)) {
149
228
  throw new ValidationError(
150
229
  `Refusing to write ${label} containing invalid Unicode: ${JSON.stringify(name)}`
151
230
  );
152
231
  }
153
232
 
154
- const encodedLength = new TextEncoder().encode(basename).length;
155
- if (encodedLength > MAX_FILENAME_BYTES) {
156
- throw new ValidationError(
157
- `Refusing to write ${label} longer than ${MAX_FILENAME_BYTES} bytes: ` +
158
- `${JSON.stringify(basename.slice(0, 32))}... (${encodedLength} bytes)`
159
- );
233
+ const fit = (value: string): string =>
234
+ fitFilenameBytes(value).replace(TRAILING_SPACES_AND_DOTS, '');
235
+ let portable = fit(basename.replace(WINDOWS_INVALID_CHARS, '_'));
236
+ // Checked on the fitted name, because truncation and trailing-dot removal
237
+ // can expose one (`NUL` followed by spaces and a long tail). Compare
238
+ // everything before the first dot: on Windows `NUL.tar.gz` opens the null
239
+ // device just as `NUL` does, so extensions provide no protection. Fitting
240
+ // again keeps the byte bound, and a `_`-prefixed name is never a device.
241
+ const deviceName = portable.split('.', 1)[0].replace(/ +$/, '').toUpperCase();
242
+ if (WINDOWS_RESERVED_NAMES.has(deviceName)) {
243
+ portable = fit(`_${portable}`);
160
244
  }
161
245
 
162
- // Compare everything before the first dot: on Windows `NUL.tar.gz` opens the
163
- // null device just as `NUL` does, so extensions provide no protection.
164
- const deviceName = basename.split('.', 1)[0].replace(/ +$/, '').toUpperCase();
165
- if (WINDOWS_RESERVED_NAMES.has(deviceName)) {
246
+ if (!portable) {
166
247
  throw new ValidationError(
167
- `Refusing to write ${label} that is a reserved device name: ${JSON.stringify(name)}`
248
+ `Path traversal detected: ${label} ${JSON.stringify(name)} leaves no usable basename to write to.`
168
249
  );
169
250
  }
170
251
 
171
- return basename;
252
+ return portable === basename ? portable : tagWithOriginal(portable, basename);
172
253
  }
@@ -1,5 +1,8 @@
1
1
  import type { BaseComposioProvider } from '../provider/BaseProvider';
2
- import { version } from '../../package.json';
2
+ // Resolve against the installed package, including slim's copy of the core build.
3
+ import identity from '#client_identity' with { type: 'json' };
4
+ import { z } from 'zod';
5
+ import { VERSION as clientLibraryVersion } from '@composio/client';
3
6
  import type { ComposioRequestHeaders } from '../types/composio.types';
4
7
 
5
8
  /**
@@ -90,6 +93,24 @@ function detectRuntime(): string {
90
93
 
91
94
  // Detect once at module initialization
92
95
  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();
93
114
 
94
115
  export function getSessionHeaders(
95
116
  provider: BaseComposioProvider<unknown, unknown, unknown> | undefined
@@ -98,7 +119,15 @@ export function getSessionHeaders(
98
119
  'x-framework': provider?.name || 'unknown',
99
120
  'x-source': 'TYPESCRIPT_SDK',
100
121
  'x-runtime': RUNTIME_ENV,
101
- 'x-sdk-version': version,
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 } : {}),
102
131
  };
103
132
  }
104
133
 
@@ -10,6 +10,7 @@ import {
10
10
  ToolExecutionLog,
11
11
  ToolExecutionLogDetail,
12
12
  ToolExecutionLogDetailSchema,
13
+ ToolExecutionLogMetadataSchema,
13
14
  ToolExecutionLogSchema,
14
15
  } from '../../types/logs.types';
15
16
  import { transform } from '../transform';
@@ -33,7 +34,7 @@ export const transformToolExecutionLog = (
33
34
  status: response.status,
34
35
  level: response.level,
35
36
  message: response.message,
36
- metadata: response.metadata,
37
+ metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
37
38
  metrics: response.metrics,
38
39
  parent: response.parent
39
40
  ? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
@@ -62,7 +63,7 @@ export const transformToolExecutionLogDetail = (
62
63
  status: response.status,
63
64
  level: response.level,
64
65
  message: response.message,
65
- metadata: response.metadata,
66
+ metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
66
67
  metrics: response.metrics,
67
68
  parent: response.parent
68
69
  ? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
@@ -1,6 +1,58 @@
1
1
  /**
2
2
  * Transforms snake_case Tool Router API responses to camelCase for SDK consumers.
3
3
  */
4
+ import type {
5
+ SessionExecuteResponse,
6
+ SessionProxyExecuteResponse,
7
+ } from '@composio/client/resources/tool-router/session/session.mjs';
8
+ import z from 'zod/v3';
9
+ import { ComposioToolInputRequiredError } from '../../errors/ToolRouterErrors';
10
+ import { ValidationError } from '../../errors/ValidationErrors';
11
+ import type { ToolRouterSessionExecuteResponse } from '../../types/toolRouter.types';
12
+
13
+ /** The `result_type` values of a call that ran. `input_required` is raised before this is read. */
14
+ const ExecutedResponseSchema = z.object({ result_type: z.enum(['completed', 'failed']) });
15
+
16
+ /**
17
+ * Whether a session tool execution succeeded. `resultType` decides: a `failed`
18
+ * execution is not successful even when its `error` is `null` or empty.
19
+ */
20
+ export function isExecutionSuccessful(
21
+ result: Pick<ToolRouterSessionExecuteResponse, 'resultType'>
22
+ ): boolean {
23
+ return result.resultType === 'completed';
24
+ }
25
+
26
+ type InputRequiredResponse = Extract<
27
+ SessionExecuteResponse | SessionProxyExecuteResponse,
28
+ { result_type: 'input_required' }
29
+ >;
30
+
31
+ /**
32
+ * Narrows an execute-family response to the variants that carry a result.
33
+ * `input_required` means the call did not run: it is raised as a
34
+ * {@link ComposioToolInputRequiredError} instead of being returned as a result
35
+ * it is not.
36
+ */
37
+ export function assertNotInputRequired<
38
+ Response extends SessionExecuteResponse | SessionProxyExecuteResponse,
39
+ >(raw: Response, subject: string): asserts raw is Exclude<Response, InputRequiredResponse> {
40
+ if (raw.result_type !== 'input_required') return;
41
+ throw new ComposioToolInputRequiredError(subject, {
42
+ inputRequests: Object.fromEntries(
43
+ Object.entries(raw.input_requests).map(([id, request]) => [
44
+ id,
45
+ {
46
+ type: request.type,
47
+ mode: request.mode,
48
+ message: request.message,
49
+ requestedSchema: request.requested_schema,
50
+ },
51
+ ])
52
+ ),
53
+ requestState: raw.request_state,
54
+ });
55
+ }
4
56
 
5
57
  interface RawSearchResult {
6
58
  index: number;
@@ -51,7 +103,7 @@ interface RawToolkitConnectionStatus {
51
103
  status_message: string;
52
104
  connection_details?: Record<string, unknown>;
53
105
  current_user_info?: Record<string, unknown>;
54
- hosted_account?: { allowed_tool_slugs: string[] };
106
+ instant_account?: { allowed_tool_slugs: string[] };
55
107
  }
56
108
 
57
109
  interface RawSearchResponse {
@@ -65,13 +117,6 @@ interface RawSearchResponse {
65
117
  time_info: RawSearchTimeInfo;
66
118
  }
67
119
 
68
- interface RawExecuteResponse {
69
- data: Record<string, unknown>;
70
- error: string | null;
71
- log_id: string;
72
- premium_charge?: unknown;
73
- }
74
-
75
120
  function transformSearchResult(raw: RawSearchResult) {
76
121
  return {
77
122
  index: raw.index,
@@ -116,8 +161,8 @@ function transformToolkitConnectionStatus(raw: RawToolkitConnectionStatus) {
116
161
  statusMessage: raw.status_message,
117
162
  connectionDetails: raw.connection_details,
118
163
  currentUserInfo: raw.current_user_info,
119
- ...(raw.hosted_account !== undefined && {
120
- hostedAccount: { allowedToolSlugs: raw.hosted_account.allowed_tool_slugs },
164
+ ...(raw.instant_account !== undefined && {
165
+ instantAccount: { allowedToolSlugs: raw.instant_account.allowed_tool_slugs },
121
166
  }),
122
167
  };
123
168
  }
@@ -155,12 +200,24 @@ export function transformSearchResponse(raw: RawSearchResponse) {
155
200
 
156
201
  /**
157
202
  * Transforms a raw session execute API response to camelCase.
203
+ *
204
+ * @throws {ComposioToolInputRequiredError} If the tool asked for user input instead of running
205
+ * @throws {ValidationError} If the response carries no `result_type`, or one this SDK does not know
158
206
  */
159
- export function transformExecuteResponse(raw: RawExecuteResponse) {
207
+ export function transformExecuteResponse(raw: SessionExecuteResponse, toolSlug: string) {
208
+ assertNotInputRequired(raw, `Tool ${toolSlug}`);
209
+ const executed = ExecutedResponseSchema.safeParse(raw);
210
+ if (!executed.success) {
211
+ throw new ValidationError(
212
+ `Tool ${toolSlug} returned an execute response without a known result_type`,
213
+ { cause: executed.error }
214
+ );
215
+ }
160
216
  return {
161
217
  data: raw.data,
162
218
  error: raw.error,
163
219
  logId: raw.log_id,
164
- ...(raw.premium_charge !== undefined && { premiumCharge: raw.premium_charge }),
220
+ resultType: executed.data.result_type,
221
+ ...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
165
222
  };
166
223
  }
@@ -55,6 +55,7 @@ export const transformUsageSummaryResponse = (
55
55
  },
56
56
  ])
57
57
  ),
58
+ instantCharge: response.instant_charge,
58
59
  }));
59
60
  };
60
61