@collective-intelligence/ui-react 0.3.5 → 0.3.7

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 (64) hide show
  1. package/README.md +133 -3
  2. package/dist/chat.d.ts +578 -0
  3. package/dist/chat.js +2 -0
  4. package/dist/components/icons/index.js +1 -1
  5. package/dist/components/illustrations/index.js +1 -1
  6. package/dist/components/ui/index.d.ts +28 -17
  7. package/dist/components/ui/index.js +2 -2
  8. package/dist/components/ui-extensions/atoms/ThemeToggle/index.js +1 -1
  9. package/dist/components/ui-extensions/hooks/use-mobile.js +1 -1
  10. package/dist/components/ui-extensions/index.d.ts +6 -6
  11. package/dist/components/ui-extensions/index.js +5 -5
  12. package/dist/components/ui-extensions/molecules/VideoPlayer/index.js +2 -2
  13. package/dist/hooks/index.js +1 -1
  14. package/dist/hooks/operations.js +1 -1
  15. package/dist/hooks/use-debounced-callback.js +1 -1
  16. package/dist/hooks/use-mount-action.js +1 -1
  17. package/dist/{index-y2h3pwvb.js → index-07wswd5f.js} +2 -2
  18. package/dist/index-1wmmfj25.js +2 -0
  19. package/dist/index-2thxhq0q.js +2 -0
  20. package/dist/index-3yxm33ex.js +42 -0
  21. package/dist/index-4ekvdxt4.js +2 -0
  22. package/dist/{index-r4k327de.js → index-4mm4a7nt.js} +2 -2
  23. package/dist/{index-dhysnhdt.js → index-590xzssr.js} +2 -2
  24. package/dist/index-7fcrqgn8.js +2 -0
  25. package/dist/index-99ad0xy6.js +2 -0
  26. package/dist/index-9at1018y.js +2 -0
  27. package/dist/index-9az9jb0y.js +2 -0
  28. package/dist/index-9me7rg96.js +2 -0
  29. package/dist/{index-t5c4bv5n.js → index-aahc5q93.js} +2 -2
  30. package/dist/index-adta20n6.js +2 -0
  31. package/dist/index-b3s2d1rk.js +2 -0
  32. package/dist/index-e105w3b8.js +2 -0
  33. package/dist/index-ek4ar1qs.js +2 -0
  34. package/dist/{index-38vsn5nv.js → index-hcecckjn.js} +2 -2
  35. package/dist/index-md173efw.js +2 -0
  36. package/dist/{index-fwsd4nes.js → index-mp8nkq9m.js} +2 -2
  37. package/dist/index-mxgt32b6.js +2 -0
  38. package/dist/index-n43k1xpt.js +6 -0
  39. package/dist/index-nadagexv.js +2 -0
  40. package/dist/{index-cx7rgb00.js → index-q04zgt5k.js} +2 -2
  41. package/dist/index-rbdjqvhp.js +2 -0
  42. package/dist/index-rvwx0vhw.js +2 -0
  43. package/dist/index-v31zghad.js +2 -0
  44. package/dist/index-vejf6hg0.js +2 -0
  45. package/dist/{index-a27yrhds.js → index-wwq9v1me.js} +2 -2
  46. package/dist/index.js +1 -1
  47. package/dist/resources.js +1 -1
  48. package/dist/styles.css +2 -0
  49. package/dist/tokens/theme.js +1 -1
  50. package/dist/utils/cn.js +1 -1
  51. package/package.json +22 -6
  52. package/dist/index-0warxk1d.js +0 -2
  53. package/dist/index-1qb5701q.js +0 -2
  54. package/dist/index-38vag578.js +0 -2
  55. package/dist/index-3y40hfmd.js +0 -2
  56. package/dist/index-4d90e50j.js +0 -2
  57. package/dist/index-50g897x2.js +0 -42
  58. package/dist/index-58jcemv5.js +0 -2
  59. package/dist/index-956qe6w8.js +0 -2
  60. package/dist/index-dcmmdjnn.js +0 -2
  61. package/dist/index-k8bsc1hv.js +0 -2
  62. package/dist/index-kgq1r8sg.js +0 -2
  63. package/dist/index-rvcf3zsv.js +0 -2
  64. package/dist/index-s18na57g.js +0 -6
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,134 @@ 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
+ ## Prebuilt stylesheet
173
+
174
+ Apps without Tailwind import `@collective-intelligence/ui-react/styles.css`
175
+ once and render the chat inside an element with the `ci-root` class. Every
176
+ rule of the stylesheet applies inside that element, so no style reaches the
177
+ rest of the page:
178
+
179
+ - Preflight, utilities and the design tokens apply to `.ci-root` and its
180
+ subtree. The tokens are CSS variables on `.ci-root`; set a variable on the
181
+ element (for example `--radius` or `--background`) to theme the chat. Every
182
+ radius size derives from `--radius`; `--font-text`, `--font-heading` and
183
+ `--font-code` set the fonts. The stylesheet loads no web font.
184
+ - Dark tokens apply with `.ci-root.dark` or under a `.dark` ancestor. A
185
+ `light` class on `.ci-root` keeps the chat light under a `.dark` ancestor.
186
+ - Keyframes names start with `ci-`. Overlay enter and exit animations of the
187
+ Tailwind apps are not part of the stylesheet.
188
+
189
+ `bun run build` compiles `src/styles/ci.css` with `@tailwindcss/cli` into
190
+ `dist/styles.css`, from the classes of this package's source and of the
191
+ `@collective-intelligence/ai-react` source, whose default `<Chat>` uses this
192
+ stylesheet only. Tests and stories are not scanned. `turbo.json` lists the
193
+ ai-react source as a build input, so a class change there rebuilds the
194
+ stylesheet. Tailwind writes
195
+ two document-level rules that nesting cannot scope: the preflight
196
+ `html, :host` rule and the `@property` fallback rule. The build moves both onto
197
+ the chat root and its subtree, and fails when Tailwind changes them. It also
198
+ removes every `@property` rule: a registration applies to the whole document,
199
+ and a typed one (`--tw-gradient-from` as `<color>`) breaks the same property
200
+ of a host page, for example the gradients of a Tailwind v3 app. The fallback
201
+ rule then sets the initial value of each Tailwind property inside the chat in
202
+ every browser. `test/styles-global-selectors.test.ts` fails on any `:root`,
203
+ `html`, `body`, bare `*` or other selector outside `.ci-root`, on any
204
+ `@property` rule, and on keyframes without the `ci-` prefix.
205
+
206
+ Tailwind apps of this repository (the Dashboard and the Studio) do not import
207
+ the prebuilt stylesheet. They import the canonical design tokens from
208
+ `src/styles/tokens.css`, keep only their own overrides, and keep scanning this
209
+ package's source with `@source`.
210
+
211
+ ## Overlay container
212
+
213
+ Dialogs, alert dialogs, sheets, drawers, popovers, menus, menubars, context
214
+ menus, tooltips and selects render into `document.body` by default. Wrap a
215
+ subtree in `PortalContainerProvider` (from `/ui`) with a `container` element to
216
+ render its overlays into that element, for example inside `.ci-root`. The
217
+ `container` prop of an overlay's content wins over the provider.
218
+
89
219
  ## Error alerts
90
220
 
91
221
  Import `ErrorAlert` from `@collective-intelligence/ui-react/ui-extensions`.