@seed-ship/mcp-ui-solid 5.0.0 → 5.2.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 (56) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +160 -6
  3. package/dist/components/ChatPrompt.cjs +71 -53
  4. package/dist/components/ChatPrompt.cjs.map +1 -1
  5. package/dist/components/ChatPrompt.d.ts +37 -2
  6. package/dist/components/ChatPrompt.d.ts.map +1 -1
  7. package/dist/components/ChatPrompt.js +72 -54
  8. package/dist/components/ChatPrompt.js.map +1 -1
  9. package/dist/components/FeedbackInline.cjs +57 -0
  10. package/dist/components/FeedbackInline.cjs.map +1 -0
  11. package/dist/components/FeedbackInline.d.ts +71 -0
  12. package/dist/components/FeedbackInline.d.ts.map +1 -0
  13. package/dist/components/FeedbackInline.js +57 -0
  14. package/dist/components/FeedbackInline.js.map +1 -0
  15. package/dist/index.cjs +9 -0
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +8 -2
  18. package/dist/index.d.ts +8 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +11 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/services/chat-bus.cjs +71 -0
  23. package/dist/services/chat-bus.cjs.map +1 -1
  24. package/dist/services/chat-bus.d.ts +31 -1
  25. package/dist/services/chat-bus.d.ts.map +1 -1
  26. package/dist/services/chat-bus.js +71 -0
  27. package/dist/services/chat-bus.js.map +1 -1
  28. package/dist/services/chat-prompt-controller.cjs +83 -0
  29. package/dist/services/chat-prompt-controller.cjs.map +1 -0
  30. package/dist/services/chat-prompt-controller.d.ts +93 -0
  31. package/dist/services/chat-prompt-controller.d.ts.map +1 -0
  32. package/dist/services/chat-prompt-controller.js +83 -0
  33. package/dist/services/chat-prompt-controller.js.map +1 -0
  34. package/dist/stores/scratchpad-store.cjs +105 -77
  35. package/dist/stores/scratchpad-store.cjs.map +1 -1
  36. package/dist/stores/scratchpad-store.d.ts +88 -19
  37. package/dist/stores/scratchpad-store.d.ts.map +1 -1
  38. package/dist/stores/scratchpad-store.js +105 -77
  39. package/dist/stores/scratchpad-store.js.map +1 -1
  40. package/dist/types/chat-bus.d.ts +164 -22
  41. package/dist/types/chat-bus.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/components/ChatPrompt.test.tsx +122 -0
  44. package/src/components/ChatPrompt.tsx +70 -15
  45. package/src/components/FeedbackInline.test.tsx +117 -0
  46. package/src/components/FeedbackInline.tsx +143 -0
  47. package/src/index.ts +24 -1
  48. package/src/services/chat-bus.test.ts +154 -2
  49. package/src/services/chat-bus.ts +115 -0
  50. package/src/services/chat-prompt-controller.test.ts +144 -0
  51. package/src/services/chat-prompt-controller.ts +214 -0
  52. package/src/stores/scratchpad-store.test.tsx +140 -0
  53. package/src/stores/scratchpad-store.tsx +244 -0
  54. package/src/types/chat-bus.ts +166 -22
  55. package/tsconfig.tsbuildinfo +1 -1
  56. package/src/stores/scratchpad-store.ts +0 -126
@@ -1,126 +0,0 @@
1
- /**
2
- * Scratchpad Store — singleton reactive state for HITL scratchpad
3
- * v3.0.3: Eliminates ChatBus relay chain race condition
4
- *
5
- * @experimental
6
- *
7
- * Parser calls dispatchScratchpad() → store updates → ScratchpadPanel reads reactively.
8
- * Zero bus, zero relay, zero race condition.
9
- *
10
- * **Known limitation (v4.3.9):** This store is a module-level singleton, not
11
- * a context-scoped factory. Two `ScratchpadPanel` instances in the same app
12
- * will share the same state. Multi-panel scenarios (e.g. chat + admin dashboard
13
- * both showing scratchpads simultaneously) are unsupported. Host apps that need
14
- * isolated scratchpads should not reuse this store — wait for v4.4.0 which
15
- * will expose `createScratchpadStore()` factory for per-panel instances.
16
- */
17
-
18
- import { createStore, produce } from 'solid-js/store'
19
- import type { ScratchpadState, ScratchpadEvent, ScratchpadSection } from '../types/chat-bus'
20
-
21
- const [scratchpadStore, setScratchpadStore] = createStore<{
22
- current: ScratchpadState | null
23
- pinned: boolean
24
- }>({ current: null, pinned: false })
25
-
26
- /**
27
- * Hook for the COMPONENT — reads the scratchpad state reactively.
28
- *
29
- * @example
30
- * const { state, pinned, close } = useScratchpadState()
31
- * <Show when={state()}>
32
- * <ScratchpadPanel state={state()!} pinned={pinned()} onClose={close} />
33
- * </Show>
34
- */
35
- export function useScratchpadState() {
36
- return {
37
- state: () => scratchpadStore.current,
38
- pinned: () => scratchpadStore.pinned,
39
- close: () => setScratchpadStore({ current: null, pinned: false }),
40
- }
41
- }
42
-
43
- /**
44
- * Function for the PARSER/STORE — mutates the scratchpad state.
45
- * Called from the SSE callback, no bus needed.
46
- *
47
- * @example
48
- * // In your SSE parser callback — ONE LINE
49
- * onScratchpad: (data) => dispatchScratchpad(data as ScratchpadEvent)
50
- */
51
- export function dispatchScratchpad(event: ScratchpadEvent): void {
52
- // DX1: lifecycle logging
53
- if (event.action === 'create') {
54
- console.info(
55
- `%c[MCP-UI] dispatchScratchpad%c create id=${event.id} sections=${event.sections?.length || 0} status=${event.status || 'loading'}${event.pinned ? ' pinned' : ''}`,
56
- 'color: #10b981; font-weight: bold', 'color: inherit'
57
- )
58
- setScratchpadStore({
59
- current: {
60
- id: event.id,
61
- title: event.title || '',
62
- sections: event.sections || [],
63
- filters: event.filters || {},
64
- preview: event.preview,
65
- agentMessages: event.agentMessages || [],
66
- status: event.status || 'loading',
67
- previewEndpoint: (event as any).previewEndpoint,
68
- previewDebounce: (event as any).previewDebounce,
69
- previewMethod: (event as any).previewMethod,
70
- previewHeaders: (event as any).previewHeaders,
71
- turn: (event as any).turn,
72
- totalTurns: (event as any).totalTurns,
73
- turnHistory: (event as any).turnHistory,
74
- },
75
- pinned: event.pinned || false,
76
- })
77
- } else if (event.action === 'update') {
78
- console.info(
79
- `%c[MCP-UI] dispatchScratchpad%c update id=${event.id} sectionMode=${event.sectionMode || 'replace'} sections=${event.sections?.length || 0} status=${event.status || '-'}`,
80
- 'color: #3b82f6; font-weight: bold', 'color: inherit'
81
- )
82
- setScratchpadStore(produce((s) => {
83
- if (!s.current || s.current.id !== event.id) {
84
- console.warn(`[MCP-UI] dispatchScratchpad: update for id=${event.id} but current is ${s.current?.id || 'null'}. Ignoring.`)
85
- return
86
- }
87
-
88
- if (event.sections) {
89
- const mode = event.sectionMode || 'replace'
90
- if (mode === 'replace') {
91
- s.current.sections = event.sections
92
- } else if (mode === 'append') {
93
- s.current.sections = [...s.current.sections, ...event.sections]
94
- } else if (mode === 'upsert') {
95
- let matchCount = 0
96
- for (const incoming of event.sections) {
97
- const idx = s.current.sections.findIndex((sec: ScratchpadSection) => sec.id === incoming.id)
98
- if (idx >= 0) {
99
- s.current.sections[idx] = incoming
100
- matchCount++
101
- } else {
102
- s.current.sections.push(incoming)
103
- }
104
- }
105
- if (matchCount === 0 && event.sections.length > 0) {
106
- console.warn(
107
- `[MCP-UI] dispatchScratchpad: sectionMode='upsert' but no IDs matched. ` +
108
- `Incoming: [${event.sections.map((s: ScratchpadSection) => s.id).join(', ')}] ` +
109
- `Existing: [${s.current.sections.map((s: ScratchpadSection) => s.id).join(', ')}]. All appended.`
110
- )
111
- }
112
- }
113
- }
114
- if (event.agentMessages) s.current.agentMessages = event.agentMessages
115
- if (event.status) s.current.status = event.status
116
- if (event.filters) s.current.filters = event.filters
117
- if (event.preview) s.current.preview = event.preview
118
- if (event.pinned != null) s.pinned = event.pinned
119
- if ((event as any).turnHistory) s.current.turnHistory = (event as any).turnHistory
120
- if ((event as any).turn != null) s.current.turn = (event as any).turn
121
- }))
122
- } else if (event.action === 'close') {
123
- console.info(`%c[MCP-UI] dispatchScratchpad%c close id=${event.id}`, 'color: #6b7280; font-weight: bold', 'color: inherit')
124
- setScratchpadStore({ current: null, pinned: false })
125
- }
126
- }