@seed-ship/mcp-ui-solid 2.3.0 → 2.5.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.
Files changed (39) hide show
  1. package/dist/components/ChatPrompt.cjs +271 -0
  2. package/dist/components/ChatPrompt.cjs.map +1 -0
  3. package/dist/components/ChatPrompt.d.ts +33 -0
  4. package/dist/components/ChatPrompt.d.ts.map +1 -0
  5. package/dist/components/ChatPrompt.js +271 -0
  6. package/dist/components/ChatPrompt.js.map +1 -0
  7. package/dist/hooks/useChatBus.cjs +28 -0
  8. package/dist/hooks/useChatBus.cjs.map +1 -0
  9. package/dist/hooks/useChatBus.d.ts +56 -0
  10. package/dist/hooks/useChatBus.d.ts.map +1 -0
  11. package/dist/hooks/useChatBus.js +28 -0
  12. package/dist/hooks/useChatBus.js.map +1 -0
  13. package/dist/index.cjs +9 -0
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +5 -1
  16. package/dist/index.d.ts +5 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +9 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/services/chat-bus.cjs +118 -0
  21. package/dist/services/chat-bus.cjs.map +1 -0
  22. package/dist/services/chat-bus.d.ts +43 -0
  23. package/dist/services/chat-bus.d.ts.map +1 -0
  24. package/dist/services/chat-bus.js +118 -0
  25. package/dist/services/chat-bus.js.map +1 -0
  26. package/dist/services/index.d.ts +1 -0
  27. package/dist/services/index.d.ts.map +1 -1
  28. package/dist/types/chat-bus.d.ts +286 -0
  29. package/dist/types/chat-bus.d.ts.map +1 -0
  30. package/package.json +1 -1
  31. package/src/components/ChatPrompt.test.tsx +280 -0
  32. package/src/components/ChatPrompt.tsx +263 -0
  33. package/src/hooks/useChatBus.tsx +81 -0
  34. package/src/index.ts +34 -0
  35. package/src/services/chat-bus.test.ts +306 -0
  36. package/src/services/chat-bus.ts +183 -0
  37. package/src/services/index.ts +2 -0
  38. package/src/types/chat-bus.ts +320 -0
  39. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,320 @@
1
+ /**
2
+ * Chat Bus — Type Definitions
3
+ * v2.4.0: Event-driven chat toolkit for agent interactions
4
+ *
5
+ * @experimental — These types may change without major bump until stabilized in v2.5.0.
6
+ * See CHANGELOG for breaking changes on experimental types.
7
+ */
8
+
9
+ import type { UIComponent, UILayout } from './index'
10
+
11
+ // ─── Event Base ──────────────────────────────────────────────
12
+
13
+ /**
14
+ * @experimental
15
+ * Base for all chat events — identifies the source stream (C2).
16
+ * Enables multi-stream support (Deposium supports 3 concurrent streams).
17
+ */
18
+ export interface ChatEventBase {
19
+ /** Unique key identifying the active stream */
20
+ streamKey: string
21
+ /** Conversation ID (if available) */
22
+ conversationId?: string
23
+ /** Space/context ID */
24
+ spaceId?: string
25
+ /** Correlation ID linking a sendPrompt command to its resulting stream (C6) */
26
+ correlationId?: string
27
+ }
28
+
29
+ // ─── Chat Events (read — from chat to agents) ───────────────
30
+
31
+ /**
32
+ * @experimental
33
+ * Events emitted by the chat. The host app connects its SSE stream
34
+ * to these callbacks. Agents consume events to react.
35
+ *
36
+ * `onToken` is a hot path (C3) — subscribe with throttle option.
37
+ * Most agents only need `onStreamEnd`.
38
+ */
39
+ export interface ChatEvents {
40
+ // --- Streaming ---
41
+ onToken: (event: ChatEventBase & { token: string }) => void
42
+ onStreamStart: (event: ChatEventBase) => void
43
+ onStreamEnd: (event: ChatEventBase & { metadata: StreamDoneMetadata }) => void
44
+ onError: (event: ChatEventBase & { error: ChatError }) => void
45
+
46
+ // --- Structured content ---
47
+ onUILayout: (event: ChatEventBase & { layout: UILayout }) => void
48
+ onCitation: (event: ChatEventBase & { citation: Citation }) => void
49
+ onToolCall: (event: ChatEventBase & { tool: ToolCallEvent }) => void
50
+ onSuggestions: (event: ChatEventBase & { items: string[] }) => void
51
+
52
+ // --- Interactions ---
53
+ onChatPromptResponse: (event: ChatEventBase & { response: ChatPromptResponse }) => void
54
+ onClarificationNeeded: (event: ChatEventBase & { clarification: ClarificationEvent }) => void
55
+
56
+ // --- Agentic (handled by app, not MCP-UI) ---
57
+ onAgentSwitch: (event: ChatEventBase & { agent: AgentContext }) => void
58
+ onBriefing: (event: ChatEventBase & { briefing: BriefingEvent }) => void
59
+ onCapabilityChange: (event: ChatEventBase & { capabilities: string[] }) => void
60
+
61
+ // --- Fallback ---
62
+ onCustomEvent: (type: string, event: ChatEventBase & { data: unknown }) => void
63
+ }
64
+
65
+ /**
66
+ * @experimental
67
+ * Subscription options for event listeners (C3).
68
+ */
69
+ export interface EventSubscribeOptions {
70
+ /** Throttle in ms — recommended 100ms for onToken */
71
+ throttle?: number
72
+ /** Filter events by streamKey */
73
+ streamKey?: string
74
+ }
75
+
76
+ // ─── Chat Commands (write — from agents to chat) ────────────
77
+
78
+ /**
79
+ * @experimental
80
+ * Commands that agents send to the chat. The host app implements
81
+ * these commands on its UI (maps to existing signals).
82
+ */
83
+ export interface ChatCommands {
84
+ // --- Prompt injection ---
85
+ /** Fill the input field without sending */
86
+ injectPrompt: (text: string) => void
87
+ /** Fill the input and send immediately. Returns correlationId (C6). */
88
+ sendPrompt: (text: string, metadata?: Record<string, unknown>) => string
89
+ /** Append text to the current input value */
90
+ appendPrompt: (text: string) => void
91
+
92
+ // --- Structured interactions ---
93
+ /** Show a ChatPrompt (choice, confirm, form) above the input (C4) */
94
+ showChatPrompt: (config: ChatPromptConfig, signal?: AbortSignal) => Promise<ChatPromptResponse>
95
+ /** Dismiss the active ChatPrompt */
96
+ dismissChatPrompt: () => void
97
+ /** Show suggestion chips */
98
+ showSuggestions: (items: SuggestionItem[]) => void
99
+
100
+ // --- Configuration ---
101
+ /** Toggle a connector on/off */
102
+ toggleConnector: (connectorId: string, enabled: boolean) => void
103
+ /** Change the chat mode */
104
+ setMode: (mode: string) => void
105
+
106
+ // --- UI ---
107
+ /** Scroll to a specific message */
108
+ scrollToMessage: (messageId: string) => void
109
+ /** Show a notification in the chat context */
110
+ notify: (message: string, type?: 'info' | 'success' | 'warning' | 'error') => void
111
+ }
112
+
113
+ // ─── Chat Bus ────────────────────────────────────────────────
114
+
115
+ /**
116
+ * @experimental
117
+ * The combined events + commands bus.
118
+ */
119
+ export interface ChatBus {
120
+ events: ChatEventEmitter
121
+ commands: ChatCommandHandler
122
+ }
123
+
124
+ /**
125
+ * @experimental
126
+ * Typed event emitter for ChatEvents.
127
+ */
128
+ export interface ChatEventEmitter {
129
+ /** Subscribe to an event */
130
+ on<K extends keyof ChatEvents>(
131
+ event: K,
132
+ handler: ChatEvents[K],
133
+ options?: EventSubscribeOptions
134
+ ): () => void // returns unsubscribe function
135
+
136
+ /** Emit an event to all subscribers */
137
+ emit<K extends keyof ChatEvents>(
138
+ event: K,
139
+ ...args: Parameters<ChatEvents[K]>
140
+ ): void
141
+
142
+ /** Remove all listeners (cleanup) */
143
+ clear(): void
144
+ }
145
+
146
+ /**
147
+ * @experimental
148
+ * Typed command handler for ChatCommands.
149
+ */
150
+ export interface ChatCommandHandler {
151
+ /** Register a command handler (app-side) */
152
+ handle<K extends keyof ChatCommands>(
153
+ command: K,
154
+ handler: ChatCommands[K]
155
+ ): void
156
+
157
+ /** Execute a command (agent-side) */
158
+ exec<K extends keyof ChatCommands>(
159
+ command: K,
160
+ ...args: Parameters<ChatCommands[K]>
161
+ ): ReturnType<ChatCommands[K]>
162
+ }
163
+
164
+ // ─── ChatPrompt ──────────────────────────────────────────────
165
+
166
+ /**
167
+ * @experimental
168
+ * Configuration for a ChatPrompt interaction.
169
+ */
170
+ export interface ChatPromptConfig {
171
+ /** Prompt type */
172
+ type: 'choice' | 'confirm' | 'form' | 'select'
173
+ /** Title / question displayed */
174
+ title: string
175
+ /** Type-specific configuration */
176
+ config: ChoicePromptConfig | ConfirmPromptConfig | FormPromptConfig | SelectPromptConfig
177
+ }
178
+
179
+ export interface ChoicePromptConfig {
180
+ options: Array<{
181
+ value: string
182
+ label: string
183
+ icon?: string
184
+ description?: string
185
+ }>
186
+ layout?: 'horizontal' | 'vertical' | 'grid'
187
+ }
188
+
189
+ export interface ConfirmPromptConfig {
190
+ message?: string
191
+ confirmLabel?: string
192
+ cancelLabel?: string
193
+ variant?: 'default' | 'danger'
194
+ }
195
+
196
+ export interface FormPromptConfig {
197
+ fields: Array<{
198
+ name: string
199
+ label: string
200
+ type: 'text' | 'number' | 'select' | 'textarea'
201
+ required?: boolean
202
+ placeholder?: string
203
+ options?: Array<{ label: string; value: string }>
204
+ }>
205
+ submitLabel?: string
206
+ }
207
+
208
+ export interface SelectPromptConfig {
209
+ options: Array<{ value: string; label: string; group?: string }>
210
+ placeholder?: string
211
+ searchable?: boolean
212
+ }
213
+
214
+ /**
215
+ * @experimental
216
+ * Structured response from a ChatPrompt.
217
+ */
218
+ export interface ChatPromptResponse {
219
+ type: ChatPromptConfig['type']
220
+ /** The selected value or form data */
221
+ value: string | Record<string, unknown>
222
+ /** Human-readable label (for display in chat as user message) */
223
+ label: string
224
+ /** Whether the user dismissed without answering */
225
+ dismissed?: boolean
226
+ }
227
+
228
+ // ─── Suggestion ──────────────────────────────────────────────
229
+
230
+ export interface SuggestionItem {
231
+ /** Text to inject when clicked */
232
+ text: string
233
+ /** Display label (defaults to text) */
234
+ label?: string
235
+ /** Icon */
236
+ icon?: string
237
+ }
238
+
239
+ // ─── Agentic types ───────────────────────────────────────────
240
+
241
+ /**
242
+ * @experimental
243
+ * Agent context — who is the active agent?
244
+ */
245
+ export interface AgentContext {
246
+ id: string
247
+ name: string
248
+ persona?: string
249
+ avatar?: string
250
+ capabilities?: string[]
251
+ metadata?: Record<string, unknown>
252
+ }
253
+
254
+ /**
255
+ * @experimental
256
+ * Briefing event — update the briefings tab.
257
+ */
258
+ export interface BriefingEvent {
259
+ id: string
260
+ action: 'create' | 'update' | 'complete' | 'archive'
261
+ title: string
262
+ sections?: BriefingSection[]
263
+ status?: 'draft' | 'in_progress' | 'complete'
264
+ agent?: string
265
+ components?: UIComponent[]
266
+ /** true = do not persist (tooltip, preview). false/absent = app decides storage. */
267
+ ephemeral?: boolean
268
+ }
269
+
270
+ export interface BriefingSection {
271
+ title: string
272
+ content: string
273
+ components?: UIComponent[]
274
+ }
275
+
276
+ // ─── SSE / Stream types ──────────────────────────────────────
277
+
278
+ export interface StreamDoneMetadata {
279
+ message_hash?: string
280
+ intent?: string
281
+ model?: string
282
+ tokens?: { input: number; output: number }
283
+ cost_usd?: number
284
+ suggestions?: string[]
285
+ extracted_charts?: unknown[]
286
+ timing_breakdown?: Record<string, number>
287
+ [key: string]: unknown // forward-compatible
288
+ }
289
+
290
+ export interface ChatError {
291
+ message: string
292
+ code?: string
293
+ recoverable?: boolean
294
+ }
295
+
296
+ export interface Citation {
297
+ page?: number
298
+ document_id?: string
299
+ document_name?: string
300
+ snippet?: string
301
+ score?: number
302
+ }
303
+
304
+ export interface ToolCallEvent {
305
+ tool: string
306
+ status: 'running' | 'completed' | 'failed'
307
+ params?: Record<string, unknown>
308
+ results?: unknown
309
+ duration_ms?: number
310
+ }
311
+
312
+ export interface ClarificationEvent {
313
+ question: string
314
+ options: Array<{
315
+ value: string
316
+ label: string
317
+ file_id?: number
318
+ }>
319
+ original_message?: string
320
+ }