@kuntur/a2a-carbon-chat-adapter 0.1.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.
- package/README.md +262 -0
- package/dist/index.cjs +2281 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1380 -0
- package/dist/index.d.ts +1380 -0
- package/dist/index.js +2247 -0
- package/dist/index.js.map +1 -0
- package/package.json +94 -0
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# @kuntur/a2a-carbon-chat-adapter
|
|
2
|
+
|
|
3
|
+
A2A protocol adapter for Carbon AI Chat - connect any A2A agent to Carbon UI.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @kuntur/a2a-carbon-chat-adapter @carbon/ai-chat react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { A2AChat } from '@kuntur/a2a-carbon-chat-adapter';
|
|
15
|
+
import '@carbon/ai-chat/styles.css';
|
|
16
|
+
|
|
17
|
+
function App() {
|
|
18
|
+
return (
|
|
19
|
+
<A2AChat
|
|
20
|
+
agentUrl="https://your-agent.example.com"
|
|
21
|
+
agentName="My Agent"
|
|
22
|
+
layout="fullscreen"
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Multi-Agent Setup
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { AgentProvider, A2AChat, AgentSwitcher, useAgentContext } from '@kuntur/a2a-carbon-chat-adapter';
|
|
32
|
+
|
|
33
|
+
const agents = [
|
|
34
|
+
{ id: 'research', name: 'Research Agent', url: 'https://research.example.com' },
|
|
35
|
+
{ id: 'code', name: 'Code Agent', url: 'https://code.example.com' },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
function App() {
|
|
39
|
+
return (
|
|
40
|
+
<AgentProvider agents={agents} defaultAgentId="research">
|
|
41
|
+
<ChatWithSwitcher />
|
|
42
|
+
</AgentProvider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function ChatWithSwitcher() {
|
|
47
|
+
const { agents, currentAgent, selectAgent } = useAgentContext();
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<AgentSwitcher
|
|
52
|
+
agents={agents}
|
|
53
|
+
currentAgentId={currentAgent?.id}
|
|
54
|
+
onSelect={selectAgent}
|
|
55
|
+
variant="tabs"
|
|
56
|
+
/>
|
|
57
|
+
<A2AChat />
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Server Setup (Next.js)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// app/api/agent/chat/route.ts
|
|
67
|
+
import { createA2AHandler } from '@kuntur/a2a-carbon-chat-adapter/server';
|
|
68
|
+
|
|
69
|
+
export const POST = createA2AHandler({
|
|
70
|
+
allowedAgentUrls: ['https://trusted-agents.example.com'],
|
|
71
|
+
timeout: 120000,
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Programmatic Usage with Hooks
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { useA2AAgent } from '@kuntur/a2a-carbon-chat-adapter';
|
|
79
|
+
|
|
80
|
+
function MyComponent() {
|
|
81
|
+
const { sendMessage, isStreaming, state } = useA2AAgent({
|
|
82
|
+
agent: { id: 'my-agent', name: 'My Agent', url: 'https://...' },
|
|
83
|
+
onMessage: (message) => console.log('Received:', message),
|
|
84
|
+
onError: (error) => console.error('Error:', error),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const handleSend = async () => {
|
|
88
|
+
await sendMessage('Hello, agent!');
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<button onClick={handleSend} disabled={isStreaming}>
|
|
93
|
+
{isStreaming ? 'Sending...' : 'Send Message'}
|
|
94
|
+
</button>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Components
|
|
100
|
+
|
|
101
|
+
### A2AChat
|
|
102
|
+
|
|
103
|
+
Main chat component that connects to A2A agents.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<A2AChat
|
|
107
|
+
// Agent configuration (pick one)
|
|
108
|
+
agent={{ id: 'agent', name: 'Agent', url: '...' }}
|
|
109
|
+
// OR
|
|
110
|
+
agentId="agent" // with AgentProvider
|
|
111
|
+
// OR
|
|
112
|
+
agentUrl="https://..." // simple URL-only
|
|
113
|
+
|
|
114
|
+
// Display options
|
|
115
|
+
layout="fullscreen" // 'fullscreen' | 'sidebar' | 'float'
|
|
116
|
+
className="my-chat"
|
|
117
|
+
|
|
118
|
+
// Behavior
|
|
119
|
+
showThinking={true}
|
|
120
|
+
showChainOfThought={true}
|
|
121
|
+
allowCancel={true}
|
|
122
|
+
|
|
123
|
+
// Callbacks
|
|
124
|
+
onSend={(message) => {}}
|
|
125
|
+
onResponse={(response) => {}}
|
|
126
|
+
onError={(error) => {}}
|
|
127
|
+
|
|
128
|
+
// Custom renderers
|
|
129
|
+
renderCitations={(citations, text) => <MyCitations ... />}
|
|
130
|
+
renderError={(error) => <MyError ... />}
|
|
131
|
+
/>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### AgentProvider
|
|
135
|
+
|
|
136
|
+
Context provider for multi-agent applications.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<AgentProvider
|
|
140
|
+
agents={[...]}
|
|
141
|
+
defaultAgentId="research"
|
|
142
|
+
persistSelection={true}
|
|
143
|
+
storageKey="my-app-agent"
|
|
144
|
+
>
|
|
145
|
+
{children}
|
|
146
|
+
</AgentProvider>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### AgentSwitcher
|
|
150
|
+
|
|
151
|
+
UI component for switching between agents.
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
<AgentSwitcher
|
|
155
|
+
agents={agents}
|
|
156
|
+
currentAgentId={currentAgentId}
|
|
157
|
+
onSelect={handleSelect}
|
|
158
|
+
variant="dropdown" // 'dropdown' | 'tabs' | 'cards'
|
|
159
|
+
showDescriptions={true}
|
|
160
|
+
showIcons={true}
|
|
161
|
+
/>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Hooks
|
|
165
|
+
|
|
166
|
+
### useA2AAgent
|
|
167
|
+
|
|
168
|
+
Programmatic agent interaction.
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
const {
|
|
172
|
+
agent, // Current agent config
|
|
173
|
+
state, // { connectionState, error, taskId, contextId }
|
|
174
|
+
sendMessage, // Send a message
|
|
175
|
+
cancelStream, // Cancel ongoing stream
|
|
176
|
+
disconnect, // Disconnect
|
|
177
|
+
isStreaming, // Boolean
|
|
178
|
+
isConnected, // Boolean
|
|
179
|
+
error, // Last error
|
|
180
|
+
} = useA2AAgent(options);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### useMultiAgent
|
|
184
|
+
|
|
185
|
+
Manage multiple agents without AgentProvider.
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const {
|
|
189
|
+
agents, // All agents
|
|
190
|
+
currentAgent, // Currently selected
|
|
191
|
+
switchAgent, // Switch by ID
|
|
192
|
+
registerAgent, // Add new agent
|
|
193
|
+
unregisterAgent, // Remove agent
|
|
194
|
+
} = useMultiAgent(options);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### useAgentContext
|
|
198
|
+
|
|
199
|
+
Access AgentProvider context.
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
const { currentAgent, agents, selectAgent, getAgent, hasAgent } = useAgentContext();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Renderers
|
|
206
|
+
|
|
207
|
+
Built-in renderers for A2A UI extensions:
|
|
208
|
+
|
|
209
|
+
- `CitationRenderer` - Renders text with inline citations
|
|
210
|
+
- `ErrorRenderer` - Renders error messages with optional stack trace
|
|
211
|
+
- `FormRenderer` - Renders dynamic forms from agent requests
|
|
212
|
+
|
|
213
|
+
## Exports
|
|
214
|
+
|
|
215
|
+
### From main package
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import {
|
|
219
|
+
// Components
|
|
220
|
+
A2AChat,
|
|
221
|
+
AgentProvider,
|
|
222
|
+
AgentSwitcher,
|
|
223
|
+
CitationRenderer,
|
|
224
|
+
ErrorRenderer,
|
|
225
|
+
FormRenderer,
|
|
226
|
+
|
|
227
|
+
// Hooks
|
|
228
|
+
useA2AAgent,
|
|
229
|
+
useMultiAgent,
|
|
230
|
+
useAgentContext,
|
|
231
|
+
useAgentContextOptional,
|
|
232
|
+
|
|
233
|
+
// A2A Client
|
|
234
|
+
A2AClient,
|
|
235
|
+
EXTENSION_URIS,
|
|
236
|
+
|
|
237
|
+
// Translator
|
|
238
|
+
A2AToCarbonTranslator,
|
|
239
|
+
createTranslator,
|
|
240
|
+
|
|
241
|
+
// Types
|
|
242
|
+
type AgentConfig,
|
|
243
|
+
type A2AChatProps,
|
|
244
|
+
// ... more types
|
|
245
|
+
} from '@kuntur/a2a-carbon-chat-adapter';
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### From server subpath
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
import { createA2AHandler } from '@kuntur/a2a-carbon-chat-adapter/server';
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Styles (optional)
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
import '@kuntur/a2a-carbon-chat-adapter/styles';
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT
|