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

next
tsx 166 lines 5.2 KB
Raw
1 'use client';
2
3 import type { ReactNode } from 'react';
4
5 import { Input, Message, TerminalLine, TerminalWindow } from '@/components/terminal-kit';
6
7 type InChatAuthTerminalProps = {
8 /** Label shown in the window chrome header and footer. */
9 path?: string;
10 /** The user's opening request. */
11 task: string;
12 /** Toolkit the agent needs connected, display name, e.g. "Gmail". */
13 toolkit: string;
14 /** Lowercase toolkit slug used in tool args, e.g. "gmail". */
15 toolkitSlug: string;
16 /** The tool the agent executes once connected, e.g. "GMAIL_FETCH_EMAILS". */
17 tool: string;
18 /** Dim args shown on the executed tool call. */
19 toolArgs?: string;
20 /** Short result shown under the executed tool call, e.g. "12 emails". */
21 toolResult?: string;
22 /** The Connect Link the agent returns mid-conversation. */
23 connectUrl?: string;
24 /** The agent's final reply after the connection is established. */
25 result: string;
26 };
27
28 /**
29 * A Claude-Code-style tool call: a green bullet, the tool name (foreground), dim
30 * `(args)`, and an optional `⎿ result` continuation line. Grouped in one session
31 * row so the call and its result sit tight together.
32 */
33 function ToolCall({
34 name,
35 args,
36 result,
37 resultTone = 'dim',
38 }: {
39 name: string;
40 args?: ReactNode;
41 result?: ReactNode;
42 resultTone?: 'dim' | 'success';
43 }) {
44 return (
45 <div className="terminal-session-inset text-[10px]">
46 <TerminalLine className="text-[10px]">
47 <span className="inline-flex min-w-0 items-baseline gap-2">
48 <span className="shrink-0" style={{ color: 'var(--terminal-green)' }}>
49 ⏺
50 </span>
51 <span className="min-w-0 truncate" style={{ color: 'var(--terminal-fg)' }}>
52 {name}
53 </span>
54 </span>
55 </TerminalLine>
56 {result ? (
57 <TerminalLine className="text-[10px]">
58 <span className="inline-flex min-w-0 items-baseline gap-2">
59 <span className="shrink-0" style={{ color: 'var(--terminal-vdim)' }}>
60 ⎿
61 </span>
62 <span
63 className="min-w-0 truncate"
64 style={{
65 color:
66 resultTone === 'success'
67 ? 'var(--terminal-green)'
68 : 'var(--terminal-dim)',
69 }}
70 >
71 {result}
72 </span>
73 </span>
74 </TerminalLine>
75 ) : null}
76 </div>
77 );
78 }
79
80 /**
81 * An agent message — same box shape as the user's `Message` bar, but outlined
82 * with a border instead of a filled background so it reads as the agent, not the
83 * tool plumbing. An optional `footer` (e.g. a link) renders inside, underneath.
84 */
85 function AgentMessage({ children, footer }: { children: ReactNode; footer?: ReactNode }) {
86 return (
87 <div
88 className="terminal-session-sent w-full border py-1.5 text-[11px]"
89 style={{ borderColor: 'var(--terminal-border)', color: 'var(--terminal-fg)' }}
90 >
91 <span className="block min-w-0 whitespace-pre-wrap break-words">{children}</span>
92 {footer ? <div className="mt-1">{footer}</div> : null}
93 </div>
94 );
95 }
96
97 /**
98 * Renders an in-chat authentication exchange using terminal-kit (Claude palette,
99 * adapts to the docs light/dark theme). The agent searches for a tool, hits a
100 * missing connection, returns a Connect Link, then `COMPOSIO_WAIT_FOR_CONNECTIONS`
101 * waits for the user to authenticate and the agent continues automatically — the
102 * user never has to confirm in chat. Static transcript, no animation.
103 */
104 export function InChatAuthTerminal({
105 path = 'agent',
106 task,
107 toolkit,
108 toolkitSlug,
109 tool,
110 toolArgs,
111 toolResult,
112 connectUrl = 'https://connect.composio.dev/link/ln_abc123',
113 result,
114 }: InChatAuthTerminalProps) {
115 return (
116 <div className="not-prose mx-auto my-6 w-full max-w-[400px]">
117 <TerminalWindow
118 className="shadow-2xl"
119 path={path}
120 theme="claude"
121 footer={<Input placeholder="Send a message…" showCursor />}
122 >
123 {/* Static transcript — rendered up front, no streaming/word animation.
124 The pb-[50px] adds 50px below the transcript. */}
125 <div className="terminal-session pb-[50px]">
126 <Message>{task}</Message>
127
128 <ToolCall
129 name="COMPOSIO_MANAGE_CONNECTIONS"
130 args={toolkitSlug}
131 result={`${toolkit} not connected — sent Connect Link`}
132 />
133
134 <AgentMessage
135 footer={
136 <a
137 href={connectUrl}
138 target="_blank"
139 rel="noreferrer"
140 style={{
141 color: 'var(--terminal-teal)',
142 textDecoration: 'underline',
143 textUnderlineOffset: 2,
144 }}
145 >
146 {connectUrl}
147 </a>
148 }
149 >
150 {`Connect your ${toolkit} account to continue:`}
151 </AgentMessage>
152
153 <ToolCall
154 name="COMPOSIO_WAIT_FOR_CONNECTIONS"
155 args={toolkitSlug}
156 result={`✓ ${toolkit} connected`}
157 resultTone="success"
158 />
159 <ToolCall name={tool} args={toolArgs} result={toolResult} />
160
161 <AgentMessage>{result}</AgentMessage>
162 </div>
163 </TerminalWindow>
164 </div>
165 );
166 }