@collective-intelligence/ui-react 0.3.5 → 0.3.8

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 (75) hide show
  1. package/README.md +207 -3
  2. package/dist/chat.d.ts +578 -0
  3. package/dist/chat.js +2 -0
  4. package/dist/components/ai-elements/index.d.ts +95 -0
  5. package/dist/components/ai-elements/index.js +2 -0
  6. package/dist/components/icons/index.js +1 -1
  7. package/dist/components/illustrations/index.js +1 -1
  8. package/dist/components/ui/index.d.ts +183 -26
  9. package/dist/components/ui/index.js +4 -2
  10. package/dist/components/ui-extensions/atoms/ThemeToggle/index.js +1 -1
  11. package/dist/components/ui-extensions/hooks/use-mobile.js +1 -1
  12. package/dist/components/ui-extensions/index.d.ts +6 -6
  13. package/dist/components/ui-extensions/index.js +6 -6
  14. package/dist/components/ui-extensions/molecules/VideoPlayer/index.js +2 -2
  15. package/dist/hooks/index.js +1 -1
  16. package/dist/hooks/operations.js +1 -1
  17. package/dist/hooks/use-debounced-callback.js +1 -1
  18. package/dist/hooks/use-mount-action.js +1 -1
  19. package/dist/index-064d20xp.js +2 -0
  20. package/dist/index-0gzm7bb9.js +2 -0
  21. package/dist/index-1hxjsnw5.js +2 -0
  22. package/dist/index-2twj52t7.js +2 -0
  23. package/dist/index-2yf6mq9g.js +2 -0
  24. package/dist/{index-cx7rgb00.js → index-4cds99c5.js} +2 -2
  25. package/dist/index-64r6cav3.js +1 -0
  26. package/dist/{index-38vsn5nv.js → index-6r0znbzv.js} +2 -2
  27. package/dist/index-7j277075.js +2 -0
  28. package/dist/{index-r4k327de.js → index-9289ppfk.js} +2 -2
  29. package/dist/{index-a27yrhds.js → index-9gtg7nt7.js} +2 -2
  30. package/dist/index-ab3fc47y.js +2 -0
  31. package/dist/index-b1wfq5b8.js +2 -0
  32. package/dist/index-dg126t3v.js +2 -0
  33. package/dist/index-dvvkk1vk.js +2 -0
  34. package/dist/index-ecvn2gnv.js +2 -0
  35. package/dist/index-fnk7gsdd.js +2 -0
  36. package/dist/index-ggr2edm8.js +2 -0
  37. package/dist/index-m0v264jr.js +2 -0
  38. package/dist/index-ngpxevag.js +2 -0
  39. package/dist/index-nxbvv8m4.js +2 -0
  40. package/dist/index-pearjjhb.js +2 -0
  41. package/dist/{index-fwsd4nes.js → index-qbwndfn2.js} +2 -2
  42. package/dist/index-r2snvwyb.js +42 -0
  43. package/dist/index-r5ds1mtq.js +2 -0
  44. package/dist/index-r7hjj3ek.js +2 -0
  45. package/dist/index-rgbg5bsy.js +2 -0
  46. package/dist/{index-dhysnhdt.js → index-rjemhrz1.js} +2 -2
  47. package/dist/index-sd38wa4w.js +2 -0
  48. package/dist/index-t9yq7kfg.js +2 -0
  49. package/dist/index-tcwzyy71.js +2 -0
  50. package/dist/{index-y2h3pwvb.js → index-vx2b9cz3.js} +2 -2
  51. package/dist/index-vyhk8kgm.js +6 -0
  52. package/dist/index-ykjbsyeq.js +2 -0
  53. package/dist/index-zmwpsfzp.js +2 -0
  54. package/dist/index-zrw7ne3f.js +2 -0
  55. package/dist/index.js +1 -1
  56. package/dist/resources.js +1 -1
  57. package/dist/shadcn.css +667 -0
  58. package/dist/styles.css +2 -0
  59. package/dist/tokens/theme.js +1 -1
  60. package/dist/utils/cn.js +1 -1
  61. package/package.json +43 -7
  62. package/dist/index-0warxk1d.js +0 -2
  63. package/dist/index-1qb5701q.js +0 -2
  64. package/dist/index-38vag578.js +0 -2
  65. package/dist/index-3y40hfmd.js +0 -2
  66. package/dist/index-4d90e50j.js +0 -2
  67. package/dist/index-50g897x2.js +0 -42
  68. package/dist/index-58jcemv5.js +0 -2
  69. package/dist/index-956qe6w8.js +0 -2
  70. package/dist/index-dcmmdjnn.js +0 -2
  71. package/dist/index-k8bsc1hv.js +0 -2
  72. package/dist/index-kgq1r8sg.js +0 -2
  73. package/dist/index-rvcf3zsv.js +0 -2
  74. package/dist/index-s18na57g.js +0 -6
  75. package/dist/index-t5c4bv5n.js +0 -2
package/README.md CHANGED
@@ -7,7 +7,9 @@ The package preserves the design-system source structure under
7
7
  `src/components/`, including `ui`, `ui-extensions`, `icons`, and
8
8
  `illustrations`, plus shared hooks, utilities, and theme tokens. The
9
9
  `/resources` entrypoint contains generic table, list, filter, pagination,
10
- dialog, and action primitives.
10
+ dialog, and action primitives. The `/chat` entrypoint contains the chat
11
+ display parts, and `/styles.css` is the prebuilt stylesheet for apps without
12
+ Tailwind.
11
13
 
12
14
  All components accept display-ready props and do not fetch data, own
13
15
  authentication, or depend on private CI packages. React and React DOM remain
@@ -22,8 +24,8 @@ keeping React and React DOM external. These artifacts support consumers using
22
24
  either production or development React. After building,
23
25
  `bun run test test/built-runtime.test.ts` verifies rendering with both modes.
24
26
 
25
- `react-markdown` remains a regular runtime dependency and is excluded only
26
- from this package's browser prebundle. Browser and server-side rendering
27
+ `react-markdown` and `remark-gfm` remain regular runtime dependencies and are
28
+ excluded only from this package's browser prebundle. Browser and server-side rendering
27
29
  consumers resolve its dependencies for their own runtime, keeping browser-only
28
30
  DOM code out of server imports.
29
31
 
@@ -86,6 +88,208 @@ Run `bun run build-storybook` for the interactive **Resources / Controlled
86
88
  entity / Journey** example. `bun run test:pack` checks these exports from the
87
89
  packed JavaScript and declarations in an isolated external consumer.
88
90
 
91
+ ## Chat parts
92
+
93
+ Import the generic chat display parts from
94
+ `@collective-intelligence/ui-react/chat`. They take display-ready values and
95
+ callbacks only: they make no request, hold no query state and construct no
96
+ client. The AI React package composes them with the chat state.
97
+
98
+ - `ChatMessage`: one message row. Pass `sender` (`user` or `assistant`), the
99
+ display-ready `author` and `timestamp`, and the body as `children`. `avatar`
100
+ replaces the default sender avatar.
101
+ - `ChatMarkdown`: an answer's Markdown with GitHub extensions (tables, task
102
+ lists, strikethrough, autolinks) through `remark-gfm`. Links open in a new
103
+ tab. `components` replaces element renderers over the chat defaults.
104
+ - `ChatComposerShell`: the composer frame with a controlled `value`,
105
+ `onValueChange` and `onSubmit`. Enter sends; Shift+Enter adds a line.
106
+ `state` is `idle`, `submitting` or `running`; with `onStop`, a running
107
+ answer shows a stop button in place of Send, which waits and takes no
108
+ second press while `stopping` is `true`. With `showStop`, the stop button
109
+ shows in any `state` and Send stays, for an answer that still takes
110
+ messages: the stop button comes first in the trailing controls, so a send
111
+ menu in `trailing` stays beside Send. `onFilesAdd` receives dropped and
112
+ pasted files.
113
+ The `notice`, `attachments`, `suggestions`, `leading`, `trailing` and
114
+ `footer` slots place caller content around the input. `onInputKeyDown` runs
115
+ first; prevent its default to replace Enter-to-send, for example in a slash
116
+ command menu. `labels` holds every visible and accessible text.
117
+ - `ChatToolEvidence`: the display parts of tool results, each in a titled
118
+ frame. A part is one of `evidence`, `table`, `sources`, `links`, `summary`,
119
+ `warnings`, `text`, `json` or `custom`. Only `http` and `https` URLs become
120
+ links. Long tables and source lists show more rows on request.
121
+ - `ChatProcessingSteps`: a run summary that opens to a timeline of `steps`
122
+ (`kind`, `label`, optional `detail`, `status`). Use `open` and
123
+ `onOpenChange` to control it, or `defaultOpen`.
124
+ - `ChatApprovalCard`: an approval request with its `status` (`pending`,
125
+ `approved`, `rejected`, `cancelled`, `expired`), `summary`, `meta`, `steps`
126
+ with progress, recorded `decisions` and `resolution`. `onApprove` receives
127
+ the optional comment (or `null`); `onReject` receives the required reason,
128
+ which a reject form asks for. Leave a callback out to hide its control;
129
+ leave both out to show a pending request as read only. `pendingAction`
130
+ (`approve` or `reject`) holds every control. `outcome` (`recorded`,
131
+ `continuation_in_progress`, `continuation_failed`,
132
+ `reconciliation_required`, `already_approved`, `already_decided`) replaces
133
+ the controls with its label. `children` shows caller content, for example
134
+ the request context, above the controls.
135
+ - `ChatQuestionCard`: a question or a direct confirmation. `mode` is `choice`
136
+ (the first click answers), `choice_or_text` (choices and a free-text answer
137
+ with Continue), `text` (an open answer) or `confirm` (approve, or revise
138
+ with text). `onRespond` receives `{ action: "answer", optionId }`,
139
+ `{ action: "answer", text }`, `{ action: "approve" }` or
140
+ `{ action: "revise", text }`. `status` `responding` holds the controls;
141
+ `completed`, `failed` and `cancelled` show the prompt, the status label and
142
+ the optional `outcome`.
143
+ - `ChatPermissionPrompt`: a capability permission prompt for the capability
144
+ `name`. `onDecide` receives `deny`, `allow_this_conversation` or
145
+ `allow_always`; `pendingDecision` holds the buttons.
146
+ - `ChatAnswerFeedback`: thumbs up and down for an answer. `value` is the
147
+ current `positive` or `negative` rating; a second press calls `onClear`.
148
+ Thumbs down asks for an optional note in a dialog before `onSubmit`.
149
+ `pending` holds the buttons.
150
+ - `ChatAttachmentChip`: one file. `mode="draft"` takes `onRemove`;
151
+ `mode="stored"` takes an optional `onDownload` (no callback, no download
152
+ button), `pending` and `error`. `previewUrl` shows an image thumbnail that
153
+ opens in a dialog; the caller owns the URL, for example an object URL.
154
+ - `ChatRunStatus`: an answer's run with a display-ready status `label`, a
155
+ `tone` (`success`, `warning`, `danger`, `primary`, `neutral`) and an
156
+ optional `detail`, for example a short run id.
157
+ - `ChatMemoryEvidence`: the `used` and `saved` counts, a `memoryDisabled`
158
+ badge and the first six display-ready `events`. It renders nothing without
159
+ events.
160
+ - `ChatContextUsageRing`: how full the conversation context is, from a
161
+ `ratio` between 0 and 1, as a ring meter named by `label`.
162
+ - `ChatCompactionMarker`: the transcript line above which a summary replaces
163
+ the older context, with the covered `messageCount`, else `runCount`.
164
+
165
+ The parts with an `error` prop show it as an alert. Overlays (the feedback
166
+ note and the image preview) render in the container of
167
+ `PortalContainerProvider`.
168
+
169
+ Each part takes `className` and `classNames` for its inner elements and marks
170
+ its root with `data-part`.
171
+
172
+ ## Base UI chat primitives
173
+
174
+ `/ui` also exports the shadcn `base-lyra` chat primitives, built on Base UI
175
+ (`@base-ui/react`) and `@shadcn/react`. They sit beside the Radix components:
176
+ no Radix component changes, and their names do not clash with the existing
177
+ `/ui` exports.
178
+
179
+ | Component | Exports |
180
+ | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
181
+ | Message scroller | `MessageScrollerProvider`, `MessageScroller`, `MessageScrollerViewport`, `MessageScrollerContent`, `MessageScrollerItem`, `MessageScrollerButton`, `useMessageScroller`, `useMessageScrollerScrollable`, `useMessageScrollerVisibility` |
182
+ | Message | `MessageGroup`, `Message`, `MessageAvatar`, `MessageContent`, `MessageHeader`, `MessageFooter` |
183
+ | Bubble | `BubbleGroup`, `Bubble`, `BubbleContent`, `BubbleReactions`, `bubbleVariants` |
184
+ | Attachment | `AttachmentGroup`, `Attachment`, `AttachmentMedia`, `AttachmentContent`, `AttachmentTitle`, `AttachmentDescription`, `AttachmentActions`, `AttachmentAction`, `AttachmentTrigger`, type `AttachmentState` |
185
+ | Marker | `Marker`, `MarkerIcon`, `MarkerContent`, `markerVariants` |
186
+ | Trace | `Trace`, `TraceLine`, `TraceIcon`, `TraceTitle`, `TraceDescription`, `TraceCollapsible`, `TraceCollapsibleTrigger`, `TraceCollapsibleContent` |
187
+ | Code block | `CodeBlock`, `CodeBlockHeader`, `CodeBlockTitle`, `CodeBlockActions`, `CodeBlockCopyButton`, `CodeBlockContent`, `CodeBlockLine`, `CodeBlockFooter`, `codeBlockVariants` |
188
+ | Item | `ItemGroup`, `Item`, `ItemMedia`, `ItemContent`, `ItemTitle`, `ItemDescription`, `ItemActions`, `ItemHeader`, `ItemFooter`, `ItemSeparator`, `itemVariants` |
189
+ | Hover card | `HoverCard`, `HoverCardTrigger`, `HoverCardContent`, type `HoverCardContentProps` |
190
+ | Empty | `Empty`, `EmptyHeader`, `EmptyMedia`, `EmptyTitle`, `EmptyDescription`, `EmptyContent`, `emptyMediaVariants` |
191
+ | Spinner | `Spinner` |
192
+
193
+ - `Spinner` from `/ui` is the shadcn loader with the `status` role. `/icons`
194
+ keeps its own `Spinner`; import one of them per file, or rename one.
195
+ - `Empty` is the shadcn empty-state layout. `EmptyState` in `/ui-extensions`
196
+ is unchanged.
197
+ - `CodeBlock` has no syntax highlighting: `CodeBlockContent` renders the text
198
+ or the children you pass, and `lineNumbers` numbers a text child. The
199
+ package does not bundle `shiki`.
200
+ - `HoverCardContent` renders into the nearest `PortalContainerProvider`
201
+ container, like the Radix overlays, and takes its own `container` prop.
202
+ - The Base UI `Button`, `Collapsible` and `Separator` that these parts use
203
+ are internal (`src/components/ui/base/`). `/ui` still exports the Radix
204
+ `Button`, `Collapsible` and `Separator`.
205
+ - The primitives use the `base-lyra` classes and the shadcn variants and
206
+ utilities (`data-open:`, `scroll-fade-*`, `shimmer`, `no-scrollbar`). A
207
+ Tailwind v4 app that renders them adds
208
+ `@import "@collective-intelligence/ui-react/shadcn.css";` after
209
+ `@import "tailwindcss"`. The published `shadcn.css` registers the package's
210
+ `dist` folder with `@source`, because Tailwind does not scan `node_modules`
211
+ on its own, so the app needs no `@source` of its own for these parts. Today only this package's Storybook does; the
212
+ Dashboard, the Studio and `tokens.css` do not.
213
+ - The prebuilt `/styles.css` does not include their classes: `ci.css`
214
+ excludes their files with `@source not`, so the stylesheet is byte-identical
215
+ to the one before they were added.
216
+ - `@shadcn/react` declares `react >=19`. It uses no React 19 hook; under React
217
+ 18 a `ref` you pass to a message-scroller part does not reach the element,
218
+ as for the other `/ui` components that take `ref` as a prop.
219
+
220
+ ## AI Elements
221
+
222
+ `/ai-elements` exports the AI Elements that do not depend on the AI SDK
223
+ (`ai`), on the Base UI collapsible:
224
+
225
+ - `Reasoning`, `ReasoningTrigger`, `ReasoningContent` and `useReasoning`.
226
+ `ReasoningContent` renders its Markdown string with core Streamdown (no
227
+ code, math, Mermaid or CJK plugin). Without `open` or `defaultOpen`, the
228
+ panel opens while `isStreaming` is true and closes one second after the
229
+ stream ends; `defaultOpen={false}` keeps it closed. `onOpenChange` reports
230
+ the member's toggles. Without `duration`, the trigger shows the measured
231
+ streaming time.
232
+ - `ChainOfThought`, `ChainOfThoughtHeader`, `ChainOfThoughtContent`,
233
+ `ChainOfThoughtStep`, `ChainOfThoughtSearchResults`,
234
+ `ChainOfThoughtSearchResult` and `ChainOfThoughtImage`.
235
+ - `Sources`, `SourcesTrigger`, `SourcesContent` and `Source`.
236
+ - `Shimmer`, which animates with the Web Animations API instead of `motion`.
237
+
238
+ `streamdown` is an optional peer dependency, needed only by `/ai-elements`,
239
+ and is excluded from this package's browser prebundle like `react-markdown`.
240
+ Install it next to the package when you import `/ai-elements`. Streamdown's
241
+ own classes need a Tailwind `@source` on `node_modules/streamdown/dist/*.js`
242
+ in the app. The entry is client-only (`"use client"`) and renders on the
243
+ server.
244
+
245
+ ## Prebuilt stylesheet
246
+
247
+ Apps without Tailwind import `@collective-intelligence/ui-react/styles.css`
248
+ once and render the chat inside an element with the `ci-root` class. Every
249
+ rule of the stylesheet applies inside that element, so no style reaches the
250
+ rest of the page:
251
+
252
+ - Preflight, utilities and the design tokens apply to `.ci-root` and its
253
+ subtree. The tokens are CSS variables on `.ci-root`; set a variable on the
254
+ element (for example `--radius` or `--background`) to theme the chat. Every
255
+ radius size derives from `--radius`; `--font-text`, `--font-heading` and
256
+ `--font-code` set the fonts. The stylesheet loads no web font.
257
+ - Dark tokens apply with `.ci-root.dark` or under a `.dark` ancestor. A
258
+ `light` class on `.ci-root` keeps the chat light under a `.dark` ancestor.
259
+ - Keyframes names start with `ci-`. Overlay enter and exit animations of the
260
+ Tailwind apps are not part of the stylesheet.
261
+
262
+ `bun run build` compiles `src/styles/ci.css` with `@tailwindcss/cli` into
263
+ `dist/styles.css`, from the classes of this package's source and of the
264
+ `@collective-intelligence/ai-react` source, whose default `<Chat>` uses this
265
+ stylesheet only. Tests and stories are not scanned. `turbo.json` lists the
266
+ ai-react source as a build input, so a class change there rebuilds the
267
+ stylesheet. Tailwind writes
268
+ two document-level rules that nesting cannot scope: the preflight
269
+ `html, :host` rule and the `@property` fallback rule. The build moves both onto
270
+ the chat root and its subtree, and fails when Tailwind changes them. It also
271
+ removes every `@property` rule: a registration applies to the whole document,
272
+ and a typed one (`--tw-gradient-from` as `<color>`) breaks the same property
273
+ of a host page, for example the gradients of a Tailwind v3 app. The fallback
274
+ rule then sets the initial value of each Tailwind property inside the chat in
275
+ every browser. `test/styles-global-selectors.test.ts` fails on any `:root`,
276
+ `html`, `body`, bare `*` or other selector outside `.ci-root`, on any
277
+ `@property` rule, and on keyframes without the `ci-` prefix.
278
+
279
+ Tailwind apps of this repository (the Dashboard and the Studio) do not import
280
+ the prebuilt stylesheet. They import the canonical design tokens from
281
+ `src/styles/tokens.css`, keep only their own overrides, and keep scanning this
282
+ package's source with `@source`.
283
+
284
+ ## Overlay container
285
+
286
+ Dialogs, alert dialogs, sheets, drawers, popovers, menus, menubars, context
287
+ menus, tooltips, selects and hover cards render into `document.body` by
288
+ default. Wrap a
289
+ subtree in `PortalContainerProvider` (from `/ui`) with a `container` element to
290
+ render its overlays into that element, for example inside `.ci-root`. The
291
+ `container` prop of an overlay's content wins over the provider.
292
+
89
293
  ## Error alerts
90
294
 
91
295
  Import `ErrorAlert` from `@collective-intelligence/ui-react/ui-extensions`.