@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 143 lines 4.37 KB
Raw
1 /**
2 * Cumulative stages of the iMessage SEND tool, built up one piece at a time.
3 * Each stage's `code` is the full file at that point; <FileBuildup>
4 * diffs consecutive stages so the reader watches the tool grow.
5 */
6 export interface BuildStage {
7 title: string;
8 description: string;
9 /** Full file contents at this stage. */
10 code: string;
11 }
12
13 const shell = `import { experimental_createTool } from '@composio/core';
14 import { z } from 'zod/v3';
15
16 export const sendMessage = experimental_createTool('SEND', {
17 name: 'Send iMessage',
18 description: 'Send an iMessage from your Mac to a phone number or iMessage email.',
19 preload: true,
20 inputParams: z.object({}),
21 execute: async () => ({ sent: false }),
22 });
23 `;
24
25 const typed = `import { experimental_createTool } from '@composio/core';
26 import { z } from 'zod/v3';
27
28 export const sendMessage = experimental_createTool('SEND', {
29 name: 'Send iMessage',
30 description: 'Send an iMessage from your Mac to a phone number or iMessage email.',
31 preload: true,
32 inputParams: z.object({
33 to: z.string().describe('Phone number or iMessage email.'),
34 text: z.string().describe('Message body to send.'),
35 }),
36 execute: async () => ({ sent: false }),
37 });
38 `;
39
40 const full = `import { experimental_createTool } from '@composio/core';
41 import { z } from 'zod/v3';
42 import { runAppleScript, SEND_SCRIPT } from './applescript';
43
44 export const sendMessage = experimental_createTool('SEND', {
45 name: 'Send iMessage',
46 description: 'Send an iMessage from your Mac to a phone number or iMessage email.',
47 preload: true,
48 inputParams: z.object({
49 to: z.string().describe('Phone number or iMessage email.'),
50 text: z.string().describe('Message body to send.'),
51 }),
52 execute: async ({ to, text }) => {
53 await runAppleScript(SEND_SCRIPT, [to, text]);
54 return { sent: true, to };
55 },
56 });
57 `;
58
59 const wiringClient = `import { Composio } from '@composio/core';
60 import { EveProvider, requireApprovalForTools } from '@composio/experimental/eve';
61
62 export const composio = new Composio({
63 provider: new EveProvider({
64 needsApproval: requireApprovalForTools('LOCAL_IMESSAGE_SEND'),
65 }),
66 });
67 `;
68
69 const wiringSession = `import { Composio } from '@composio/core';
70 import { EveProvider, requireApprovalForTools } from '@composio/experimental/eve';
71
72 export const composio = new Composio({
73 provider: new EveProvider({
74 needsApproval: requireApprovalForTools('LOCAL_IMESSAGE_SEND'),
75 }),
76 });
77
78 export const session = composio.sessions.create('user_123');
79 `;
80
81 const wiringToolkit = `import { Composio } from '@composio/core';
82 import { EveProvider, requireApprovalForTools } from '@composio/experimental/eve';
83 import { createImessageToolkit } from './imessage';
84
85 export const composio = new Composio({
86 provider: new EveProvider({
87 needsApproval: requireApprovalForTools('LOCAL_IMESSAGE_SEND'),
88 }),
89 });
90
91 export const session = composio.sessions.create('user_123', {
92 experimental: { customToolkits: [createImessageToolkit()] },
93 });
94 `;
95
96 export const FILE_BUILDS: Record<string, { file: string; stages: BuildStage[] }> = {
97 wiring: {
98 file: 'composio.ts',
99 stages: [
100 {
101 title: 'Client with the eve provider',
102 description:
103 'The eve provider makes session.tools() return eve-native tools, so eve can call them directly.',
104 code: wiringClient,
105 },
106 {
107 title: 'A session for the user',
108 description:
109 'sessions.create scopes the toolset to one user. It already exposes the whole Composio catalog.',
110 code: wiringSession,
111 },
112 {
113 title: 'Register the local toolkit',
114 description:
115 'Pass the custom toolkit so the local iMessage tools join the catalog on the same session.',
116 code: wiringToolkit,
117 },
118 ],
119 },
120 send: {
121 file: 'imessage/send-message.ts',
122 stages: [
123 {
124 title: 'The tool shell',
125 description:
126 'A custom tool is a slug, a description, and an execute. preload:true surfaces it in session.tools() without a search step.',
127 code: shell,
128 },
129 {
130 title: 'Typed inputs',
131 description:
132 'Declare the input schema with zod/v3, which the Composio custom-tool API expects.',
133 code: typed,
134 },
135 {
136 title: 'Send via AppleScript',
137 description:
138 'The execute runs locally on your Mac, driving Messages.app through osascript.',
139 code: full,
140 },
141 ],
142 },
143 };