@composio/core 0.22.0 → 0.24.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 (49) hide show
  1. package/dist/{CustomTool-CKBCElpT.d.mts → CustomTool-CNJysHMK.d.mts} +1 -1
  2. package/dist/{CustomTool-B-_VjWpy.mjs → CustomTool-CnJxXr07.mjs} +1 -1
  3. package/dist/{cancellation-DV8CIi52.mjs → cancellation-BQibgpRG.mjs} +166 -34
  4. package/dist/{composio-C-418N1P.d.mts → composio-BFTtZj82.d.mts} +62 -80
  5. package/dist/{customTool.types-CK408sI-.d.mts → customTool.types-D57QrTns.d.mts} +309 -204
  6. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +4 -4
  7. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
  8. package/dist/docs/reference/sdk-reference/typescript/session.mdx +2 -2
  9. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
  10. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +2 -2
  11. package/dist/{errors-Dyiu3ifQ.mjs → errors-BN15NcCW.mjs} +34 -2
  12. package/dist/experimental/index.d.mts +2 -2
  13. package/dist/experimental/index.mjs +1 -1
  14. package/dist/index.d.mts +66 -4
  15. package/dist/index.mjs +3321 -3103
  16. package/dist/platform/node.d.mts +1 -1
  17. package/dist/platform/node.mjs +13 -0
  18. package/dist/platform/workerd.d.mts +1 -1
  19. package/dist/platform/workerd.mjs +3 -0
  20. package/dist/{types-D5A2wzBl.d.mts → types-DuVZKrXO.d.mts} +2 -0
  21. package/dist/{types-RpMRVn4D.d.mts → types-q8TwAngA.d.mts} +2 -2
  22. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  23. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  24. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  25. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  26. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  27. package/package.json +12 -9
  28. package/src/errors/ToolRouterErrors.ts +65 -0
  29. package/src/lib/toolRouterParams.ts +19 -13
  30. package/src/models/CustomToolkits.ts +1 -1
  31. package/src/models/MCP.ts +20 -1
  32. package/src/models/RemoteFile.ts +24 -5
  33. package/src/models/SessionContext.ts +24 -4
  34. package/src/models/ToolRouter.ts +6 -4
  35. package/src/models/ToolRouterSession.ts +95 -13
  36. package/src/models/Tools.ts +20 -36
  37. package/src/models/customToolExecution.ts +10 -0
  38. package/src/platform/node.ts +16 -0
  39. package/src/platform/types.ts +3 -0
  40. package/src/platform/workerd.ts +4 -0
  41. package/src/provider/BaseProvider.ts +2 -1
  42. package/src/types/tool.types.ts +5 -0
  43. package/src/types/toolRouter.types.ts +97 -26
  44. package/src/utils/jsonSchema.ts +191 -36
  45. package/src/utils/retries.ts +20 -0
  46. package/src/utils/safePath.ts +135 -54
  47. package/src/utils/session.ts +31 -2
  48. package/src/utils/transformers/toolRouterResponseTransform.ts +72 -27
  49. package/src/utils/transformers/usage.ts +1 -4
@@ -1,23 +1,57 @@
1
1
  /**
2
2
  * Transforms snake_case Tool Router API responses to camelCase for SDK consumers.
3
3
  */
4
- import { z } from 'zod/v3';
5
- import {
6
- ToolRouterInstantResponseSchema,
7
- type ToolRouterInstantResponse,
8
- } from '../../types/toolRouter.types';
9
-
10
- const SessionConfigInstantSchema = z.object({
11
- instant: z.union([z.literal(false), ToolRouterInstantResponseSchema]).optional(),
12
- });
13
-
14
- /** Session config retains its API casing, including `instant.return_instant_charge`. */
15
- export function transformSessionConfig<Config extends { premium_usage?: unknown }>(
16
- raw: Config
17
- ): Omit<Config, 'premium_usage'> & { instant?: false | ToolRouterInstantResponse } {
18
- const { instant } = SessionConfigInstantSchema.parse(raw);
19
- const { premium_usage: _previousPolicy, ...config } = raw;
20
- return { ...config, ...(instant !== undefined && { instant }) };
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
+ });
21
55
  }
22
56
 
23
57
  interface RawSearchResult {
@@ -69,7 +103,10 @@ interface RawToolkitConnectionStatus {
69
103
  status_message: string;
70
104
  connection_details?: Record<string, unknown>;
71
105
  current_user_info?: Record<string, unknown>;
72
- instant_account?: { allowed_tool_slugs: string[] };
106
+ instant_account?: {
107
+ allowed_tool_slugs: string[];
108
+ prices?: Record<string, { description?: string; discount?: string | null }>;
109
+ };
73
110
  }
74
111
 
75
112
  interface RawSearchResponse {
@@ -83,13 +120,6 @@ interface RawSearchResponse {
83
120
  time_info: RawSearchTimeInfo;
84
121
  }
85
122
 
86
- interface RawExecuteResponse {
87
- data: Record<string, unknown>;
88
- error: string | null;
89
- log_id: string;
90
- instant_charge?: unknown;
91
- }
92
-
93
123
  function transformSearchResult(raw: RawSearchResult) {
94
124
  return {
95
125
  index: raw.index,
@@ -135,7 +165,10 @@ function transformToolkitConnectionStatus(raw: RawToolkitConnectionStatus) {
135
165
  connectionDetails: raw.connection_details,
136
166
  currentUserInfo: raw.current_user_info,
137
167
  ...(raw.instant_account !== undefined && {
138
- instantAccount: { allowedToolSlugs: raw.instant_account.allowed_tool_slugs },
168
+ instantAccount: {
169
+ allowedToolSlugs: raw.instant_account.allowed_tool_slugs,
170
+ ...(raw.instant_account.prices !== undefined && { prices: raw.instant_account.prices }),
171
+ },
139
172
  }),
140
173
  };
141
174
  }
@@ -173,12 +206,24 @@ export function transformSearchResponse(raw: RawSearchResponse) {
173
206
 
174
207
  /**
175
208
  * Transforms a raw session execute API response to camelCase.
209
+ *
210
+ * @throws {ComposioToolInputRequiredError} If the tool asked for user input instead of running
211
+ * @throws {ValidationError} If the response carries no `result_type`, or one this SDK does not know
176
212
  */
177
- export function transformExecuteResponse(raw: RawExecuteResponse) {
213
+ export function transformExecuteResponse(raw: SessionExecuteResponse, toolSlug: string) {
214
+ assertNotInputRequired(raw, `Tool ${toolSlug}`);
215
+ const executed = ExecutedResponseSchema.safeParse(raw);
216
+ if (!executed.success) {
217
+ throw new ValidationError(
218
+ `Tool ${toolSlug} returned an execute response without a known result_type`,
219
+ { cause: executed.error }
220
+ );
221
+ }
178
222
  return {
179
223
  data: raw.data,
180
224
  error: raw.error,
181
225
  logId: raw.log_id,
226
+ resultType: executed.data.result_type,
182
227
  ...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
183
228
  };
184
229
  }
@@ -4,7 +4,6 @@ import type {
4
4
  UsageRetrieveSummaryParams as RawUsageSummaryParams,
5
5
  UsageRetrieveSummaryResponse as RawUsageSummaryResponse,
6
6
  } from '@composio/client/resources/project/usage';
7
- import { z } from 'zod/v3';
8
7
  import {
9
8
  UsageBreakdownParams,
10
9
  UsageBreakdownResponse,
@@ -43,8 +42,6 @@ export const transformUsageBreakdownParams = (
43
42
  export const transformUsageSummaryResponse = (
44
43
  response: RawUsageSummaryResponse
45
44
  ): UsageSummaryResponse => {
46
- // The pinned generated client predates this response field but preserves the raw JSON.
47
- const { instant_charge } = z.object({ instant_charge: z.string() }).parse(response);
48
45
  return transform(response)
49
46
  .with(UsageSummaryResponseSchema)
50
47
  .using(response => ({
@@ -58,7 +55,7 @@ export const transformUsageSummaryResponse = (
58
55
  },
59
56
  ])
60
57
  ),
61
- instantCharge: instant_charge,
58
+ instantCharge: response.instant_charge,
62
59
  }));
63
60
  };
64
61