1
-import zodToJsonSchema from 'zod-to-json-schema';
1
+import {
2
+ experimental_createTool as createCustomTool,
3
+ experimental_createToolkit as createCustomToolkit,
4
+ type CustomToolkit,
5
+} from '@composio/core/experimental';
6
import { beeperImessageToolkit } from './toolkits/beeper-imessage';
7
import { chromeDevtoolsToolkit } from './toolkits/chrome-devtools';
8
import { peekabooToolkit } from './toolkits/peekaboo';
5
-import type { z } from 'zod/v3';
9
import { formatSupportedPlatforms, detectCliPlatform, supportsCliPlatform } from './platform';
10
import { executeLocalTool } from './runtime';
11
import type {
18
19
export const LOCAL_TOOL_PREFIX = 'LOCAL_';
20
18
-interface LocalCustomTool {
19
- readonly slug: string;
20
- readonly name: string;
21
- readonly description: string;
22
- readonly inputSchema: Record<string, unknown>;
23
- readonly outputSchema?: Record<string, unknown>;
24
-}
25
-
26
-interface LocalCustomToolkit {
27
- readonly slug: string;
28
- readonly name: string;
29
- readonly description: string;
30
- readonly tools: ReadonlyArray<LocalCustomTool>;
31
-}
32
-
33
-/**
34
- * Built-in local toolkits shipped with @composio/cli-local-tools.
35
- *
36
- * The foundation package intentionally starts empty. Concrete integrations are
37
- * added in separate stack PRs so each app can be reviewed and validated on its
38
- * own.
39
- */
21
+/** Built-in local toolkits shipped with @composio/cli-local-tools. */
22
export const localToolkitDeclarations: ReadonlyArray<LocalToolkitDeclaration> = [
23
beeperImessageToolkit,
24
chromeDevtoolsToolkit,
41
platforms: ReadonlyArray<LocalCliPlatform>
42
): string => `${description}\n\nLocal CLI platforms: ${formatSupportedPlatforms(platforms)}.`;
43
62
-const zodObjectToJsonSchema = (schema: z.ZodTypeAny): Record<string, unknown> => {
63
- const converted = zodToJsonSchema(schema, { name: 'input' }) as {
64
- definitions?: { input?: Record<string, unknown> };
65
- } & Record<string, unknown>;
66
- const inputDefinition = converted.definitions?.input ?? converted;
67
- return {
68
- type: 'object',
69
- properties:
70
- inputDefinition.properties && typeof inputDefinition.properties === 'object'
71
- ? (inputDefinition.properties as Record<string, unknown>)
72
- : {},
73
- ...(Array.isArray(inputDefinition.required) ? { required: inputDefinition.required } : {}),
74
- };
75
-};
76
-
77
-const zodToOutputJsonSchema = (schema: z.ZodTypeAny): Record<string, unknown> => {
78
- const converted = zodToJsonSchema(schema, { name: 'output' }) as {
79
- definitions?: { output?: Record<string, unknown> };
80
- } & Record<string, unknown>;
81
- return converted.definitions?.output ?? converted;
82
-};
83
-
44
const toCustomTool = (
45
toolkit: LocalToolkitDeclaration,
86
- tool: LocalToolDeclaration
87
-): LocalCustomTool => ({
88
- slug: tool.slug,
89
- name: tool.name,
90
- description: descriptionWithPlatform(tool.description, tool.platforms),
91
- inputSchema: zodObjectToJsonSchema(tool.inputParams as z.ZodTypeAny),
92
- ...(tool.outputParams ? { outputSchema: zodToOutputJsonSchema(tool.outputParams) } : {}),
93
-});
46
+ tool: LocalToolDeclaration,
47
+ currentPlatform: LocalCliPlatform
48
+) =>
49
+ createCustomTool(tool.slug, {
50
+ name: tool.name,
51
+ description: descriptionWithPlatform(tool.description, tool.platforms),
52
+ inputParams: tool.inputParams,
53
+ ...(tool.outputParams ? { outputParams: tool.outputParams } : {}),
54
+ execute: async input =>
55
+ executeLocalTool(tool.execution, input as Record<string, unknown>, {
56
+ toolkit,
57
+ tool,
58
+ finalSlug: normalizeLocalToolSlug(tool.slug, toolkit.slug),
59
+ platform: currentPlatform,
60
+ }),
61
+ });
62
63
const toCustomToolkit = (
64
toolkit: LocalToolkitDeclaration,
97
- tools: ReadonlyArray<LocalCustomTool>
98
-): LocalCustomToolkit => ({
99
- slug: toolkit.slug,
100
- name: toolkit.name,
101
- description: descriptionWithPlatform(toolkit.description, toolkit.platforms),
102
- tools,
103
-});
65
+ currentPlatform: LocalCliPlatform
66
+): CustomToolkit =>
67
+ createCustomToolkit(toolkit.slug, {
68
+ name: toolkit.name,
69
+ description: descriptionWithPlatform(toolkit.description, toolkit.platforms),
70
+ tools: toolkit.tools.map(tool => toCustomTool(toolkit, tool, currentPlatform)),
71
+ });
72
73
const toolkitMatchesFilter = (
74
toolkit: LocalToolkitDeclaration,
135
readonly toolkits?: ReadonlyArray<string>;
136
readonly declarations?: ReadonlyArray<LocalToolkitDeclaration>;
137
} = {}
170
-): ReadonlyArray<LocalCustomToolkit> =>
171
- getLocalToolkitDeclarations(options).map(toolkit =>
172
- toCustomToolkit(
173
- toolkit,
174
- toolkit.tools.map(tool => toCustomTool(toolkit, tool))
175
- )
138
+): ReadonlyArray<CustomToolkit> => {
139
+ const currentPlatform = options.currentPlatform ?? detectCliPlatform();
140
+ return getLocalToolkitDeclarations({ ...options, currentPlatform }).map(toolkit =>
141
+ toCustomToolkit(toolkit, currentPlatform)
142
);
143
+};
144
145
const customToolkitToPayload = (
179
- toolkit: LocalCustomToolkit
146
+ toolkit: CustomToolkit
147
): NonNullable<LocalToolRouterExperimentalPayload['custom_toolkits']>[number] => ({
148
slug: toolkit.slug,
149
name: toolkit.name,
217
return {
218
finalSlug: resolution.finalSlug,
219
toolkit: resolution.toolkit.slug,
253
- schema: toCustomTool(resolution.toolkit, resolution.tool).inputSchema,
220
+ schema: toCustomTool(resolution.toolkit, resolution.tool, resolution.currentPlatform)
221
+ .inputSchema,
222
version: 'local',
223
};
224
};