oneie 3.6.35 → 3.6.38
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/.claude/agents/agent-writer.md +356 -10
- package/.claude/commands/news.md +274 -0
- package/.claude/hooks/.last-news-context +1 -1
- package/.claude/hooks/__pycache__/todo.cpython-311.pyc +0 -0
- package/.claude/hooks/validate-ontology-structure.py +25 -3
- package/.claude/hooks/validate-ontology-structure.py.backup +518 -0
- package/one/knowledge/ag-ui-protocol.md +613 -0
- package/one/knowledge/ai-api-reference.md +715 -0
- package/one/knowledge/ai-quickstart.md +355 -0
- package/one/knowledge/ai-sdk-implementation.md +436 -0
- package/one/knowledge/astro-effect-simple-architecture.md +41 -8
- package/one/knowledge/generative-ui-patterns.md +559 -0
- package/one/things/plans/ai-integration-plan.md +263 -0
- package/package.json +1 -1
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Ag Ui Protocol
|
|
3
|
+
dimension: knowledge
|
|
4
|
+
category: protocols
|
|
5
|
+
tags: ai, ag-ui, protocol, generative-ui, agents
|
|
6
|
+
related_dimensions: connections, events
|
|
7
|
+
scope: global
|
|
8
|
+
created: 2025-11-10
|
|
9
|
+
updated: 2025-11-10
|
|
10
|
+
version: 1.0.0
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# AG-UI Protocol Specification
|
|
14
|
+
|
|
15
|
+
**Version:** 1.0.0
|
|
16
|
+
**Purpose:** Agent-Generated User Interface communication protocol
|
|
17
|
+
**Inspired by:** CopilotKit's AG-UI concept
|
|
18
|
+
**Stack:** Effect.ts + Convex + React
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
|
|
22
|
+
**AG-UI (Agent-Generated User Interface)** is a communication protocol that allows AI agents to dynamically render UI components, request context from applications, and suggest actions for user approval.
|
|
23
|
+
|
|
24
|
+
**Key Capabilities:**
|
|
25
|
+
- Send structured UI data to frontend (not HTML strings)
|
|
26
|
+
- Request application context bidirectionally
|
|
27
|
+
- Suggest actions with human-in-the-loop approval
|
|
28
|
+
- Stream reasoning/thinking process
|
|
29
|
+
- Coordinate multiple agents
|
|
30
|
+
|
|
31
|
+
## Protocol Architecture
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
AI Agent (Backend)
|
|
35
|
+
↓
|
|
36
|
+
AgentUIService (Effect.ts)
|
|
37
|
+
↓
|
|
38
|
+
AG-UI Protocol Message
|
|
39
|
+
↓
|
|
40
|
+
Convex Real-time Events
|
|
41
|
+
↓
|
|
42
|
+
React Frontend
|
|
43
|
+
↓
|
|
44
|
+
GenerativeUIRenderer
|
|
45
|
+
↓
|
|
46
|
+
shadcn/ui Components
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Message Types
|
|
50
|
+
|
|
51
|
+
### 1. TEXT - Plain Text Message
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
agentId: Id<'things'>,
|
|
57
|
+
conversationId: Id<'things'>,
|
|
58
|
+
timestamp: number,
|
|
59
|
+
payload: {
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: "Here's your analysis...",
|
|
62
|
+
sentiment?: 'positive' | 'neutral' | 'negative',
|
|
63
|
+
formatting?: {
|
|
64
|
+
bold?: boolean,
|
|
65
|
+
italic?: boolean,
|
|
66
|
+
code?: boolean
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. UI - Structured UI Component
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
{
|
|
76
|
+
type: 'ui',
|
|
77
|
+
agentId: Id<'things'>,
|
|
78
|
+
conversationId: Id<'things'>,
|
|
79
|
+
timestamp: number,
|
|
80
|
+
payload: {
|
|
81
|
+
type: 'ui',
|
|
82
|
+
component: 'chart' | 'table' | 'card' | 'form',
|
|
83
|
+
data: ComponentData,
|
|
84
|
+
layout?: {
|
|
85
|
+
width?: 'full' | 'half' | 'third',
|
|
86
|
+
height?: string,
|
|
87
|
+
position?: 'inline' | 'modal' | 'sidebar'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 3. ACTION - Action Suggestions
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
{
|
|
97
|
+
type: 'action',
|
|
98
|
+
agentId: Id<'things'>,
|
|
99
|
+
conversationId: Id<'things'>,
|
|
100
|
+
timestamp: number,
|
|
101
|
+
payload: {
|
|
102
|
+
type: 'action',
|
|
103
|
+
actions: [
|
|
104
|
+
{
|
|
105
|
+
id: 'export_report',
|
|
106
|
+
label: 'Export Full Report',
|
|
107
|
+
description: 'Download PDF with detailed analysis',
|
|
108
|
+
icon?: string,
|
|
109
|
+
params?: Record<string, any>,
|
|
110
|
+
confirmationRequired?: boolean,
|
|
111
|
+
confirmationMessage?: string
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 4. CONTEXT_REQUEST - Request App Context
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
{
|
|
122
|
+
type: 'context_request',
|
|
123
|
+
agentId: Id<'things'>,
|
|
124
|
+
conversationId: Id<'things'>,
|
|
125
|
+
timestamp: number,
|
|
126
|
+
payload: {
|
|
127
|
+
type: 'context_request',
|
|
128
|
+
fields: ['user.cart', 'user.preferences', 'app.currentPage'],
|
|
129
|
+
reason: 'Need to personalize recommendations',
|
|
130
|
+
optional?: boolean
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 5. REASONING - Agent Thinking Steps
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
{
|
|
139
|
+
type: 'reasoning',
|
|
140
|
+
agentId: Id<'things'>,
|
|
141
|
+
conversationId: Id<'things'>,
|
|
142
|
+
timestamp: number,
|
|
143
|
+
payload: {
|
|
144
|
+
type: 'reasoning',
|
|
145
|
+
steps: [
|
|
146
|
+
{
|
|
147
|
+
step: 1,
|
|
148
|
+
title: 'Understanding the question',
|
|
149
|
+
description: 'Parsing user intent',
|
|
150
|
+
completed: true,
|
|
151
|
+
result?: any
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
currentStep?: number,
|
|
155
|
+
streaming?: boolean
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 6. TOOL_CALL - Function Execution
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
{
|
|
164
|
+
type: 'tool_call',
|
|
165
|
+
agentId: Id<'things'>,
|
|
166
|
+
conversationId: Id<'things'>,
|
|
167
|
+
timestamp: number,
|
|
168
|
+
payload: {
|
|
169
|
+
type: 'tool_call',
|
|
170
|
+
toolName: 'searchKnowledge',
|
|
171
|
+
arguments: { query: 'AI agents' },
|
|
172
|
+
result?: any,
|
|
173
|
+
status: 'pending' | 'running' | 'completed' | 'failed',
|
|
174
|
+
error?: string
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 7. ERROR - Error Message
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
{
|
|
183
|
+
type: 'error',
|
|
184
|
+
agentId: Id<'things'>,
|
|
185
|
+
conversationId: Id<'things'>,
|
|
186
|
+
timestamp: number,
|
|
187
|
+
payload: {
|
|
188
|
+
type: 'error',
|
|
189
|
+
message: 'AI service unavailable',
|
|
190
|
+
code?: 'RATE_LIMIT' | 'QUOTA_EXCEEDED',
|
|
191
|
+
recoverable?: boolean,
|
|
192
|
+
retryable?: boolean,
|
|
193
|
+
details?: any
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Component Data Structures
|
|
199
|
+
|
|
200
|
+
### ChartComponentData
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
{
|
|
204
|
+
component: 'chart',
|
|
205
|
+
data: {
|
|
206
|
+
title: 'Revenue Trend',
|
|
207
|
+
description: '20% growth month-over-month',
|
|
208
|
+
chartType: 'line' | 'bar' | 'pie' | 'area',
|
|
209
|
+
labels: ['Jan', 'Feb', 'Mar'],
|
|
210
|
+
datasets: [
|
|
211
|
+
{
|
|
212
|
+
label: 'Revenue',
|
|
213
|
+
data: [10000, 12000, 15000],
|
|
214
|
+
color?: 'hsl(var(--chart-1))',
|
|
215
|
+
fill?: boolean
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
options?: any // Recharts options
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### TableComponentData
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
{
|
|
227
|
+
component: 'table',
|
|
228
|
+
data: {
|
|
229
|
+
title: 'Performance Summary',
|
|
230
|
+
description?: string,
|
|
231
|
+
headers: ['Month', 'Revenue', 'Users'],
|
|
232
|
+
rows: [
|
|
233
|
+
['Jan', '$10,000', 100],
|
|
234
|
+
['Feb', '$12,000', 120]
|
|
235
|
+
],
|
|
236
|
+
sortable?: boolean,
|
|
237
|
+
filterable?: boolean,
|
|
238
|
+
pagination?: {
|
|
239
|
+
pageSize: 10,
|
|
240
|
+
currentPage: 1,
|
|
241
|
+
totalPages: 5
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### CardComponentData
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
{
|
|
251
|
+
component: 'card',
|
|
252
|
+
data: {
|
|
253
|
+
title: 'Quick Stats',
|
|
254
|
+
description?: string,
|
|
255
|
+
content: string | any,
|
|
256
|
+
footer?: string,
|
|
257
|
+
actions?: [
|
|
258
|
+
{
|
|
259
|
+
label: 'View Details',
|
|
260
|
+
actionId: 'view_details',
|
|
261
|
+
variant?: 'default' | 'destructive' | 'outline'
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### FormComponentData
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
{
|
|
272
|
+
component: 'form',
|
|
273
|
+
data: {
|
|
274
|
+
title: 'Update Profile',
|
|
275
|
+
description?: string,
|
|
276
|
+
fields: [
|
|
277
|
+
{
|
|
278
|
+
name: 'email',
|
|
279
|
+
label: 'Email',
|
|
280
|
+
type: 'email',
|
|
281
|
+
required: true,
|
|
282
|
+
defaultValue?: string,
|
|
283
|
+
validation?: any
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
submitLabel?: 'Submit',
|
|
287
|
+
onSubmitActionId: 'update_profile'
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## AgentUIService Implementation
|
|
293
|
+
|
|
294
|
+
**File:** `backend/convex/services/agent-ui.ts`
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { Effect, Context, Layer } from "effect";
|
|
298
|
+
import type { AgentUIMessage } from "../protocols/agent-ui";
|
|
299
|
+
|
|
300
|
+
export class AgentUIService extends Context.Tag("AgentUIService")<
|
|
301
|
+
AgentUIService,
|
|
302
|
+
{
|
|
303
|
+
readonly sendText: (args: {
|
|
304
|
+
agentId: Id<'things'>;
|
|
305
|
+
conversationId: Id<'things'>;
|
|
306
|
+
text: string;
|
|
307
|
+
sentiment?: 'positive' | 'neutral' | 'negative';
|
|
308
|
+
}) => Effect.Effect<Id<'things'>, never>;
|
|
309
|
+
|
|
310
|
+
readonly sendUI: (args: {
|
|
311
|
+
agentId: Id<'things'>;
|
|
312
|
+
conversationId: Id<'things'>;
|
|
313
|
+
component: ComponentData;
|
|
314
|
+
}) => Effect.Effect<Id<'things'>, never>;
|
|
315
|
+
|
|
316
|
+
readonly sendActions: (args: {
|
|
317
|
+
agentId: Id<'things'>;
|
|
318
|
+
conversationId: Id<'things'>;
|
|
319
|
+
actions: Action[];
|
|
320
|
+
}) => Effect.Effect<Id<'things'>, never>;
|
|
321
|
+
|
|
322
|
+
readonly requestContext: (args: {
|
|
323
|
+
agentId: Id<'things'>;
|
|
324
|
+
conversationId: Id<'things'>;
|
|
325
|
+
fields: string[];
|
|
326
|
+
reason: string;
|
|
327
|
+
}) => Effect.Effect<Id<'things'>, never>;
|
|
328
|
+
|
|
329
|
+
readonly sendReasoning: (args: {
|
|
330
|
+
agentId: Id<'things'>;
|
|
331
|
+
conversationId: Id<'things'>;
|
|
332
|
+
steps: ReasoningStep[];
|
|
333
|
+
}) => Effect.Effect<Id<'things'>, never>;
|
|
334
|
+
}
|
|
335
|
+
>() {}
|
|
336
|
+
|
|
337
|
+
export const AgentUIServiceLive = Layer.effect(
|
|
338
|
+
AgentUIService,
|
|
339
|
+
Effect.gen(function* () {
|
|
340
|
+
const db = yield* ConvexDatabase;
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
sendText: (args) =>
|
|
344
|
+
Effect.gen(function* () {
|
|
345
|
+
const messageId = yield* db.insert('things', {
|
|
346
|
+
type: 'message',
|
|
347
|
+
groupId: args.conversationId,
|
|
348
|
+
name: 'AG-UI Text',
|
|
349
|
+
properties: {
|
|
350
|
+
protocol: 'ag-ui',
|
|
351
|
+
messageType: 'text',
|
|
352
|
+
agentId: args.agentId,
|
|
353
|
+
text: args.text,
|
|
354
|
+
sentiment: args.sentiment
|
|
355
|
+
},
|
|
356
|
+
status: 'active',
|
|
357
|
+
createdAt: Date.now(),
|
|
358
|
+
updatedAt: Date.now()
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
yield* db.insert('events', {
|
|
362
|
+
type: 'agent_executed',
|
|
363
|
+
groupId: args.conversationId,
|
|
364
|
+
actorId: args.agentId,
|
|
365
|
+
targetId: messageId,
|
|
366
|
+
timestamp: Date.now(),
|
|
367
|
+
metadata: { action: 'ag_ui_message_sent', messageType: 'text' }
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
return messageId;
|
|
371
|
+
}),
|
|
372
|
+
|
|
373
|
+
sendUI: (args) =>
|
|
374
|
+
Effect.gen(function* () {
|
|
375
|
+
const messageId = yield* db.insert('things', {
|
|
376
|
+
type: 'message',
|
|
377
|
+
groupId: args.conversationId,
|
|
378
|
+
name: `AG-UI ${args.component.component}`,
|
|
379
|
+
properties: {
|
|
380
|
+
protocol: 'ag-ui',
|
|
381
|
+
messageType: 'ui',
|
|
382
|
+
agentId: args.agentId,
|
|
383
|
+
component: args.component
|
|
384
|
+
},
|
|
385
|
+
status: 'active',
|
|
386
|
+
createdAt: Date.now(),
|
|
387
|
+
updatedAt: Date.now()
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
yield* db.insert('events', {
|
|
391
|
+
type: 'agent_executed',
|
|
392
|
+
groupId: args.conversationId,
|
|
393
|
+
actorId: args.agentId,
|
|
394
|
+
targetId: messageId,
|
|
395
|
+
timestamp: Date.now(),
|
|
396
|
+
metadata: { action: 'ag_ui_message_sent', messageType: 'ui' }
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
return messageId;
|
|
400
|
+
}),
|
|
401
|
+
|
|
402
|
+
// Other methods...
|
|
403
|
+
};
|
|
404
|
+
})
|
|
405
|
+
);
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Frontend Rendering
|
|
409
|
+
|
|
410
|
+
**GenerativeUIRenderer Component:**
|
|
411
|
+
|
|
412
|
+
```tsx
|
|
413
|
+
import { ChartComponentData, TableComponentData } from '@/convex/protocols/agent-ui';
|
|
414
|
+
import { Card } from '@/components/ui/card';
|
|
415
|
+
import { LineChart, BarChart } from 'recharts';
|
|
416
|
+
import { Table } from '@/components/ui/table';
|
|
417
|
+
|
|
418
|
+
export function GenerativeUIRenderer({ payload }) {
|
|
419
|
+
const { component, data, layout } = payload;
|
|
420
|
+
|
|
421
|
+
switch (component) {
|
|
422
|
+
case 'chart':
|
|
423
|
+
return <DynamicChart data={data} layout={layout} />;
|
|
424
|
+
case 'table':
|
|
425
|
+
return <DynamicTable data={data} layout={layout} />;
|
|
426
|
+
case 'card':
|
|
427
|
+
return <DynamicCard data={data} layout={layout} />;
|
|
428
|
+
case 'form':
|
|
429
|
+
return <DynamicForm data={data} layout={layout} />;
|
|
430
|
+
default:
|
|
431
|
+
return <div>Unknown component: {component}</div>;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function DynamicChart({ data, layout }) {
|
|
436
|
+
// Transform data for Recharts
|
|
437
|
+
const chartData = data.labels.map((label, i) => ({
|
|
438
|
+
name: label,
|
|
439
|
+
...data.datasets.reduce((acc, dataset) => ({
|
|
440
|
+
...acc,
|
|
441
|
+
[dataset.label]: dataset.data[i]
|
|
442
|
+
}), {})
|
|
443
|
+
}));
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<Card>
|
|
447
|
+
<CardHeader>
|
|
448
|
+
<CardTitle>{data.title}</CardTitle>
|
|
449
|
+
</CardHeader>
|
|
450
|
+
<CardContent>
|
|
451
|
+
<LineChart data={chartData} width={600} height={300}>
|
|
452
|
+
{/* Recharts configuration */}
|
|
453
|
+
</LineChart>
|
|
454
|
+
</CardContent>
|
|
455
|
+
</Card>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## Context Sharing Pattern
|
|
461
|
+
|
|
462
|
+
**useAgentContext Hook:**
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
import { useMutation } from 'convex/react';
|
|
466
|
+
import { useState, useEffect } from 'react';
|
|
467
|
+
|
|
468
|
+
export function useAgentContext(conversationId) {
|
|
469
|
+
const [context, setContext] = useState({});
|
|
470
|
+
const updateContext = useMutation(api.conversations.updateContext);
|
|
471
|
+
|
|
472
|
+
useEffect(() => {
|
|
473
|
+
updateContext({ conversationId, context });
|
|
474
|
+
}, [context, conversationId]);
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
shareContext: (key, value) => {
|
|
478
|
+
setContext(prev => ({ ...prev, [key]: value }));
|
|
479
|
+
},
|
|
480
|
+
removeContext: (key) => {
|
|
481
|
+
setContext(prev => {
|
|
482
|
+
const { [key]: _, ...rest } = prev;
|
|
483
|
+
return rest;
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
getContext: () => context
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**Usage:**
|
|
492
|
+
|
|
493
|
+
```tsx
|
|
494
|
+
function MyComponent() {
|
|
495
|
+
const { shareContext } = useAgentContext(conversationId);
|
|
496
|
+
|
|
497
|
+
// Share cart with agent
|
|
498
|
+
shareContext('cart', cart);
|
|
499
|
+
|
|
500
|
+
// Share current page
|
|
501
|
+
shareContext('currentPage', location.pathname);
|
|
502
|
+
|
|
503
|
+
// Share user preferences
|
|
504
|
+
shareContext('userPreferences', preferences);
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
## Agent Example
|
|
509
|
+
|
|
510
|
+
**Intelligence Agent with AG-UI:**
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
export class IntelligenceAgent {
|
|
514
|
+
analyzePerformance: (args) =>
|
|
515
|
+
Effect.gen(function* () {
|
|
516
|
+
const agentUI = yield* AgentUIService;
|
|
517
|
+
|
|
518
|
+
// Send reasoning steps
|
|
519
|
+
yield* agentUI.sendReasoning({
|
|
520
|
+
agentId: AGENT_ID,
|
|
521
|
+
conversationId: args.conversationId,
|
|
522
|
+
steps: [
|
|
523
|
+
{ step: 1, title: 'Fetching metrics', description: '...', completed: true },
|
|
524
|
+
{ step: 2, title: 'Analyzing trends', description: '...', completed: true }
|
|
525
|
+
]
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// Send chart
|
|
529
|
+
yield* agentUI.sendUI({
|
|
530
|
+
agentId: AGENT_ID,
|
|
531
|
+
conversationId: args.conversationId,
|
|
532
|
+
component: {
|
|
533
|
+
component: 'chart',
|
|
534
|
+
data: {
|
|
535
|
+
title: 'Revenue Trend',
|
|
536
|
+
chartType: 'line',
|
|
537
|
+
labels: ['Jan', 'Feb', 'Mar'],
|
|
538
|
+
datasets: [{ label: 'Revenue', data: [10000, 12000, 15000] }]
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
// Send action suggestions
|
|
544
|
+
yield* agentUI.sendActions({
|
|
545
|
+
agentId: AGENT_ID,
|
|
546
|
+
conversationId: args.conversationId,
|
|
547
|
+
actions: [
|
|
548
|
+
{
|
|
549
|
+
id: 'export_report',
|
|
550
|
+
label: 'Export Full Report',
|
|
551
|
+
params: { format: 'pdf' }
|
|
552
|
+
}
|
|
553
|
+
]
|
|
554
|
+
});
|
|
555
|
+
})
|
|
556
|
+
}
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
## Security Considerations
|
|
560
|
+
|
|
561
|
+
**Input Validation:**
|
|
562
|
+
- Sanitize all component data before rendering
|
|
563
|
+
- Validate action parameters before execution
|
|
564
|
+
- Limit component complexity (max rows, max datasets)
|
|
565
|
+
|
|
566
|
+
**Authorization:**
|
|
567
|
+
- Check user permissions before executing actions
|
|
568
|
+
- Validate groupId on all operations
|
|
569
|
+
- Rate limit AG-UI message creation
|
|
570
|
+
|
|
571
|
+
**Sandboxing:**
|
|
572
|
+
- Never render user-provided HTML
|
|
573
|
+
- Use structured component data only
|
|
574
|
+
- Validate all data against schemas
|
|
575
|
+
|
|
576
|
+
## Performance Optimization
|
|
577
|
+
|
|
578
|
+
**Message Batching:**
|
|
579
|
+
- Batch multiple UI updates into single message
|
|
580
|
+
- Debounce rapid reasoning updates
|
|
581
|
+
- Use streaming for long sequences
|
|
582
|
+
|
|
583
|
+
**Component Rendering:**
|
|
584
|
+
- Lazy load heavy components (charts, tables)
|
|
585
|
+
- Virtualize large lists and tables
|
|
586
|
+
- Memoize component renderers
|
|
587
|
+
|
|
588
|
+
**Context Sharing:**
|
|
589
|
+
- Throttle context updates
|
|
590
|
+
- Only share necessary fields
|
|
591
|
+
- Use delta updates when possible
|
|
592
|
+
|
|
593
|
+
## Summary
|
|
594
|
+
|
|
595
|
+
**AG-UI Protocol provides:**
|
|
596
|
+
- Structured UI communication (not HTML)
|
|
597
|
+
- Type-safe component data
|
|
598
|
+
- Bidirectional context sharing
|
|
599
|
+
- Human-in-the-loop actions
|
|
600
|
+
- Multi-agent coordination
|
|
601
|
+
|
|
602
|
+
**Key Benefits:**
|
|
603
|
+
- Security (no XSS via HTML strings)
|
|
604
|
+
- Type safety (TypeScript throughout)
|
|
605
|
+
- Flexibility (any UI component)
|
|
606
|
+
- Real-time (Convex subscriptions)
|
|
607
|
+
- Multi-tenant (groupId scoping)
|
|
608
|
+
|
|
609
|
+
**Related Documentation:**
|
|
610
|
+
- [AI SDK Implementation](./ai-sdk-implementation.md)
|
|
611
|
+
- [Generative UI Patterns](./generative-ui-patterns.md)
|
|
612
|
+
- [CopilotKit Protocol](../connections/copilotkit.md)
|
|
613
|
+
|