meowtail 0.2.0-alpha.1 → 0.2.0-alpha.2

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 (88) hide show
  1. package/README.md +24 -8
  2. package/dist/src/chat/assistant-composer.js +58 -98
  3. package/dist/src/chat/assistant-content.d.ts +1 -3
  4. package/dist/src/chat/assistant-content.js +36 -44
  5. package/dist/src/chat/assistant-markdown.js +4 -8
  6. package/dist/src/chat/assistant-question.js +13 -14
  7. package/dist/src/chat/assistant.js +27 -26
  8. package/dist/src/chat/attachments.d.ts +3 -2
  9. package/dist/src/chat/attachments.js +39 -34
  10. package/dist/src/chat/composer-panel.d.ts +2 -3
  11. package/dist/src/chat/composer-panel.js +3 -4
  12. package/dist/src/chat/composer.d.ts +5 -3
  13. package/dist/src/chat/composer.js +67 -21
  14. package/dist/src/chat/task.js +9 -15
  15. package/dist/src/chat/tool-call.js +1 -8
  16. package/dist/src/components/accordion.d.ts +24 -0
  17. package/dist/src/components/accordion.js +50 -0
  18. package/dist/src/components/avatar.d.ts +22 -0
  19. package/dist/src/components/avatar.js +44 -0
  20. package/dist/src/components/checkbox.d.ts +6 -2
  21. package/dist/src/components/checkbox.js +36 -8
  22. package/dist/src/components/choice-group.d.ts +1 -0
  23. package/dist/src/components/choice-group.js +12 -17
  24. package/dist/src/components/choice-select.d.ts +3 -1
  25. package/dist/src/components/choice-select.js +56 -54
  26. package/dist/src/components/code-block.d.ts +3 -3
  27. package/dist/src/components/code-block.js +27 -23
  28. package/dist/src/components/context-menu.d.ts +16 -0
  29. package/dist/src/components/context-menu.js +49 -0
  30. package/dist/src/components/disclosure.d.ts +2 -2
  31. package/dist/src/components/disclosure.js +1 -1
  32. package/dist/src/components/index.d.ts +9 -0
  33. package/dist/src/components/index.js +9 -0
  34. package/dist/src/components/link.d.ts +13 -0
  35. package/dist/src/components/link.js +9 -0
  36. package/dist/src/components/menu-button.d.ts +13 -0
  37. package/dist/src/components/menu-button.js +10 -0
  38. package/dist/src/components/menu.d.ts +4 -0
  39. package/dist/src/components/menu.js +3 -3
  40. package/dist/src/components/meta-row.d.ts +5 -4
  41. package/dist/src/components/meta-row.js +34 -18
  42. package/dist/src/components/nav-item.js +2 -5
  43. package/dist/src/components/number-input.d.ts +29 -0
  44. package/dist/src/components/number-input.js +137 -0
  45. package/dist/src/components/output-block.js +1 -8
  46. package/dist/src/components/path-picker.js +5 -10
  47. package/dist/src/components/pill.js +2 -5
  48. package/dist/src/components/popover.js +4 -4
  49. package/dist/src/components/progress.d.ts +15 -0
  50. package/dist/src/components/progress.js +12 -0
  51. package/dist/src/components/risk-confirmation.js +2 -5
  52. package/dist/src/components/segmented-control.js +3 -3
  53. package/dist/src/components/skeleton-boundary.js +4 -7
  54. package/dist/src/components/slider.d.ts +22 -0
  55. package/dist/src/components/slider.js +49 -0
  56. package/dist/src/components/table.d.ts +41 -0
  57. package/dist/src/components/table.js +146 -0
  58. package/dist/src/components/tabs.d.ts +1 -1
  59. package/dist/src/components/tabs.js +11 -20
  60. package/dist/src/components/text-shimmer.js +2 -5
  61. package/dist/src/registry/index.d.ts +62 -3
  62. package/dist/src/registry/index.js +18 -2
  63. package/dist/src/theme/chat/composer-panel.styles.js +4 -1
  64. package/dist/src/theme/chat/composer.styles.js +45 -67
  65. package/dist/src/theme/chat/task.styles.js +5 -6
  66. package/dist/src/theme/components/accordion.styles.d.ts +1 -0
  67. package/dist/src/theme/components/accordion.styles.js +63 -0
  68. package/dist/src/theme/components/avatar.styles.d.ts +1 -0
  69. package/dist/src/theme/components/avatar.styles.js +52 -0
  70. package/dist/src/theme/components/button.styles.js +9 -0
  71. package/dist/src/theme/components/card.styles.js +2 -0
  72. package/dist/src/theme/components/context-menu.styles.d.ts +1 -0
  73. package/dist/src/theme/components/context-menu.styles.js +14 -0
  74. package/dist/src/theme/components/link.styles.d.ts +1 -0
  75. package/dist/src/theme/components/link.styles.js +33 -0
  76. package/dist/src/theme/components/menu.styles.js +9 -3
  77. package/dist/src/theme/components/number-input.styles.d.ts +1 -0
  78. package/dist/src/theme/components/number-input.styles.js +106 -0
  79. package/dist/src/theme/components/progress.styles.d.ts +1 -0
  80. package/dist/src/theme/components/progress.styles.js +71 -0
  81. package/dist/src/theme/components/slider.styles.d.ts +1 -0
  82. package/dist/src/theme/components/slider.styles.js +129 -0
  83. package/dist/src/theme/components/table.styles.d.ts +1 -0
  84. package/dist/src/theme/components/table.styles.js +156 -0
  85. package/dist/src/theme/components/toggle.styles.js +10 -0
  86. package/dist/src/theme/index.d.ts +1 -1
  87. package/dist/src/theme/index.js +16 -0
  88. package/package.json +3 -3
package/README.md CHANGED
@@ -10,6 +10,12 @@ This package's npm name is `meowtail`; existing APIs such as `createMeowUI`, `in
10
10
 
11
11
  See [Assistant](ASSISTANT.md) for the usage contract of the complete composition and [JSON catalog](JSON.md) for the finite JSON entry point. Implementation and independent acceptance of both are still in progress; the API descriptions and early artifact verification on this page do not equal a same-source acceptance pass for all current source code.
12
12
 
13
+ ## Runtime compatibility
14
+
15
+ The current alpha requires `meowjsx@^0.1.1-alpha.1`: live component props use its public
16
+ `derived` signal primitive. Earlier JSX stable and alpha builds do not provide that export.
17
+ The existing MeowCSS peer range remains compatible.
18
+
13
19
  ## Minimal browser integration
14
20
 
15
21
  In a browser entry point containing `<main id="app"></main>`, first complete component registration on the same runtime, full CSS loading, and theme root binding, then render content.
@@ -103,7 +109,15 @@ clipboard implementation, and the component does not execute code. With no langu
103
109
  Unknown languages or failed highlight loads keep a plain-text display.
104
110
 
105
111
  `Checkbox`, `Switch`, and `SegmentedControl` provide native form selection; `Tabs` handles switching panels that stay mounted.
106
- `Menu`, `HoverCard`, `Toast`, and `RiskConfirmation` provide menus, previews, and feedback, while business actions and display lifetimes are the host's responsibility.
112
+ A `Checkbox` can be `indeterminate` for a parent of mixed children; assistive technology reads `aria-checked="mixed"`.
113
+ `Slider` is a native range with a visible figure for the same value; `NumberInput` steps and clamps a number and formats the committed figure.
114
+ `Progress` is a labeled native progress bar, determinate or indeterminate; `Spinner` remains the wait with no known amount. `ChatTask` reuses `Progress` for explicit host progress.
115
+ `Avatar` shows a picture or initials; `ChatMessage` still takes any avatar child in its identity column, because that slot already hosts icons and other artwork.
116
+ `Link` is a themed inline text link. It is not `ResourceLink`, which remains the whole-row reference to an openable object.
117
+ `Table` shows host rows in columns that the user can sort, resize, and multi-select; row order and records stay with the caller.
118
+ `Accordion` groups `Disclosure` sections in single- or multiple-open mode.
119
+ `Menu`, `MenuButton`, `ContextMenu`, `HoverCard`, `Toast`, and `RiskConfirmation` provide menus, previews, and feedback, while business actions and display lifetimes are the host's responsibility.
120
+ `MenuButton` is a button that opens the existing `Menu`; `ContextMenu` opens that same `Menu` from a right-click or Shift+F10, including nested items.
107
121
  Menu's Tab / Shift+Tab closes the whole menu chain and leaves along the native order without activating menu items; Escape closes one layer at a time and returns to that layer's entry point.
108
122
  `TerminalBlock`, `ReadBlock`, `DiffBlock`, `SearchBlock`, `WebBlock`, and `JsonBlock/JsonTree`
109
123
  display host-provided output; components do not execute tools or read files. `ReadBlock` accepts `lang`, loads highlighting when it first enters the viewport, and keeps unknown languages as plain text.
@@ -312,8 +326,9 @@ trigger. Error messages use the browser's native validation copy. Reset restores
312
326
  The theme visually hides the native form carrier; a hidden input is not used to fake required validation. It provides no custom multiple selection or asynchronous search.
313
327
  The parts are `root/trigger/value/indicator/list/group/option/native/validation`.
314
328
 
315
- - Basics: Button, AddButton, IconButton, Card, Badge, Input, Textarea, Select, Field,
316
- SearchInput, Disclosure, Separator, NavItem, EmptyState.
329
+ - Basics: Button, AddButton, IconButton, MenuButton, Card, Badge, Avatar, Input, NumberInput,
330
+ Textarea, Select, Field, SearchInput, Slider, Progress, Link, Disclosure, Accordion, Table,
331
+ Separator, NavItem, EmptyState.
317
332
  - Dialogs: Dialog, DialogPanel, DialogHeader, DialogActions.
318
333
  - Chat: ChatFrame, ChatHeader, ChatStatus, ChatConversation, ChatMessageList, ChatMessage, ChatBubble,
319
334
  ChatMessageActions, ChatComposer, ChatToolCall, ChatAttachments, ChatProcess, ChatSources.
@@ -356,7 +371,7 @@ The theme uses the `root/entry/image/preview/file/icon/details/name/size/preview
356
371
  through `partSelector(chatAttachmentsContract, part)`.
357
372
  Each item can provide `onRemove`, passed only when a draft needs a remove action; upload, file deletion, and URL lifecycles still belong to the host.
358
373
 
359
- `ComposerPanel` is the composition directly above `ChatComposer`: it owns the writing surface and an optional page-level meta row, while draft, actions and submission stay in `ChatComposer`. It renders `ChatComposer` with `surface="none"`, so the panel never stacks a second chrome. Narrow composition stays with `ChatComposer`'s own layout and the page/footer edge; the panel has no device variant. The meta slot usually holds a `MetaRow`.
374
+ `ComposerPanel` composes one `ChatComposer` and an optional page-level meta row, usually a `MetaRow`. It refines the same internal writing surface rather than wrapping the whole form in a second surface. Draft, actions, submission and the external supporting hint stay in `ChatComposer`. Narrow composition stays with `ChatComposer`'s own layout and the page/footer edge; the panel has no device variant.
360
375
 
361
376
  `ChatFrame` provides reading margins only for a direct `ChatComposer`; if a footer, Card, or other wrapper container owns that region's space,
362
377
  the Composer inside uses its natural width within that container and is no longer narrowed or margined by an ancestor Frame.
@@ -365,9 +380,9 @@ the Composer inside uses its natural width within that container and is no longe
365
380
  `onInput` is bound on the textarea and `onSubmit` on the outer form. `value` supports Signals, and
366
381
  `submitDisabled` only prevents submission, which suits continued editing while waiting for a result; `disabled` prevents both editing and submission.
367
382
  Request state, submitted snapshots, and the latest draft are managed by the caller. `attachments` holds materials to send, and `inputLabel` provides the input name.
368
- The standard theme organizes attachments, input, supporting actions, and submission on one writing surface.
369
- `surface="none"` removes ChatComposer's own surface chrome and padding so a parent such as `ComposerPanel` can own the writing surface; the default keeps the standard surface.
370
- `layout="inline"` puts short drafts and actions on the same row, and long drafts keep growing; hints appear on focus, and the default `stacked` keeps a separate tool row.
383
+ The form groups a writing `surface` and its supporting `hint`. Attachments, input and actions stay inside the surface; the hint follows outside its rounded edge and focus outline, associated with the textarea by `hintId`. Page-level metadata follows the whole composer.
384
+ `surface="none"` removes only the internal writing surface's chrome and padding for explicit bare embedding; it does not move the hint back inside a surface.
385
+ `layout="inline"` puts short drafts and actions on the same row, and long drafts keep growing; its external hint appears on focus. The default `stacked` keeps the tool row at the bottom of the writing surface. On narrow screens, attach/input/send share the writing row and model selection sits below it; the supporting hint remains outside the surface and wraps. The `hero` hint retains its visually hidden presentation.
371
386
  `layout="hero"` uses the input height of the desktop master blank conversation. `trailing` composes selection entry points such as provider and model to the left of the send button;
372
387
  a controlled `ChoiceSelect` can be passed, expanding grouped options upward with `placement="top"`, `align="end"`, and `matchTriggerWidth={false}`.
373
388
  Option sources, current values, and the actual switching of runtime configuration are still the host's responsibility.
@@ -425,7 +440,8 @@ Choosing only fills in the path; it does not read files, upload files, or grant
425
440
 
426
441
  `Disclosure` uses native details/summary, accepts `summary: Child` and content children, and supports
427
442
  `open/name/onToggle` and other native attributes. `summaryClassName` and `contentClassName` are for host layout;
428
- the parts are `root/summary/icon/content`. It does not maintain a second expansion state and is not a multi-item Accordion.
443
+ the parts are `root/summary/icon/content`. `Accordion` groups several Disclosures, with `type="single"` or
444
+ `type="multiple"`, and still does not own business content.
429
445
 
430
446
  ## Standard theme (meowtail/theme)
431
447
 
@@ -1,10 +1,9 @@
1
- import { defineComponent, h, unwrap } from "meowjsx";
1
+ import { defineComponent, derived, h, isSignal, unwrap } from "meowjsx";
2
2
  import { ChatComposer } from "./composer.js";
3
3
  import { ChatAttachments } from "./attachments.js";
4
4
  import { IconButton } from "../components/icon-button.js";
5
5
  import { ChoiceSelect } from "../components/choice-select.js";
6
6
  import { Icon } from "../icons/icon.js";
7
- import { assistantDerived } from "./assistant-content.js";
8
7
  import { consumeAssistantDraft, snapshotAssistantDraft } from "./assistant-draft.js";
9
8
  import { assistantCopy as defaultAssistantCopy, } from "./assistant-types.js";
10
9
  export const assistantComposerContract = {
@@ -17,20 +16,19 @@ export const AssistantComposer = defineComponent(assistantComposerContract, ({ o
17
16
  if (controlled && !options.onDraftChange && !options.readOnly)
18
17
  throw new Error("A controlled Assistant draft requires onDraftChange or readOnly");
19
18
  const local = context.signal(options.defaultDraft ?? { text: "", attachments: [] });
20
- const draft = assistantDerived(context, () => controlled ? unwrap(options.draft) : local.value);
21
- const text = assistantDerived(context, () => draft.value.text);
19
+ const draft = derived(() => (controlled ? unwrap(options.draft) : local.value));
20
+ const text = derived(() => draft.value.text);
22
21
  const pending = context.signal(false);
23
22
  const attaching = context.signal(false);
24
23
  const feedback = context.signal("");
25
- const disabled = assistantDerived(context, () => options.readOnly || unwrap(options.disabled ?? false));
26
- const submitDisabled = assistantDerived(context, () => disabled.value ||
24
+ const disabled = derived(() => options.readOnly || unwrap(options.disabled ?? false));
25
+ const submitDisabled = derived(() => disabled.value ||
27
26
  pending.value ||
28
27
  !options.onSubmit ||
29
28
  (!draft.value.text.trim() && !draft.value.attachments.length));
30
29
  let textVersion = 0;
31
30
  let previousText = draft.value.text;
32
31
  let disposed = false;
33
- let textarea;
34
32
  let fileInput;
35
33
  const urls = new Set();
36
34
  context.effect(() => {
@@ -46,12 +44,6 @@ export const AssistantComposer = defineComponent(assistantComposerContract, ({ o
46
44
  local.value = next;
47
45
  options.onDraftChange?.(next);
48
46
  };
49
- const resize = () => {
50
- if (!textarea)
51
- return;
52
- textarea.style.height = "auto";
53
- textarea.style.height = `${textarea.scrollHeight}px`;
54
- };
55
47
  const send = async (event) => {
56
48
  event.preventDefault();
57
49
  if (pending.value || submitDisabled.value || !options.onSubmit)
@@ -75,10 +67,8 @@ export const AssistantComposer = defineComponent(assistantComposerContract, ({ o
75
67
  feedback.value = assistantCopy.submitError;
76
68
  }
77
69
  finally {
78
- if (!disposed) {
70
+ if (!disposed)
79
71
  pending.value = false;
80
- resize();
81
- }
82
72
  }
83
73
  };
84
74
  const attach = async (event) => {
@@ -122,111 +112,81 @@ export const AssistantComposer = defineComponent(assistantComposerContract, ({ o
122
112
  });
123
113
  const localModel = context.signal(unwrap(options.models ?? [])[0]?.value ?? "");
124
114
  const localReasoning = context.signal(unwrap(options.reasoningOptions ?? [])[0]?.value ?? "");
125
- const choices = context.part("choices", "div", null, assistantDerived(context, () => {
126
- const models = unwrap(options.models ?? []);
127
- return models.length
128
- ? h(ChoiceSelect, {
129
- options: models,
130
- value: options.model ?? localModel,
131
- "aria-label": assistantCopy.model,
132
- onValueChange: (value) => {
133
- if (options.model === undefined)
134
- localModel.value = value;
135
- options.onModelChange?.(value);
136
- },
137
- placement: "top",
138
- matchTriggerWidth: false,
139
- })
140
- : null;
141
- }), assistantDerived(context, () => {
142
- const reasoning = unwrap(options.reasoningOptions ?? []);
143
- return reasoning.length
144
- ? h(ChoiceSelect, {
145
- options: reasoning,
146
- value: options.reasoning ?? localReasoning,
147
- "aria-label": assistantCopy.reasoning,
148
- onValueChange: (value) => {
149
- if (options.reasoning === undefined)
150
- localReasoning.value = value;
151
- options.onReasoningChange?.(value);
152
- },
153
- placement: "top",
154
- matchTriggerWidth: false,
155
- })
156
- : null;
157
- }), options.composerTrailing);
115
+ const modelsLive = options.models !== undefined && (isSignal(options.models) || options.models.length > 0);
116
+ const reasoningLive = options.reasoningOptions !== undefined &&
117
+ (isSignal(options.reasoningOptions) || options.reasoningOptions.length > 0);
118
+ const choices = context.part("choices", "div", null, modelsLive
119
+ ? h(ChoiceSelect, {
120
+ hidden: derived(() => unwrap(options.models ?? []).length === 0),
121
+ options: derived(() => unwrap(options.models ?? [])),
122
+ value: options.model ?? localModel,
123
+ "aria-label": assistantCopy.model,
124
+ onValueChange: (value) => {
125
+ if (options.model === undefined)
126
+ localModel.value = value;
127
+ options.onModelChange?.(value);
128
+ },
129
+ placement: "top",
130
+ matchTriggerWidth: false,
131
+ })
132
+ : null, reasoningLive
133
+ ? h(ChoiceSelect, {
134
+ hidden: derived(() => unwrap(options.reasoningOptions ?? []).length === 0),
135
+ options: derived(() => unwrap(options.reasoningOptions ?? [])),
136
+ value: options.reasoning ?? localReasoning,
137
+ "aria-label": assistantCopy.reasoning,
138
+ onValueChange: (value) => {
139
+ if (options.reasoning === undefined)
140
+ localReasoning.value = value;
141
+ options.onReasoningChange?.(value);
142
+ },
143
+ placement: "top",
144
+ matchTriggerWidth: false,
145
+ })
146
+ : null, options.composerTrailing);
158
147
  return context.part("root", "div", null, h(ChatComposer, {
159
148
  value: text,
160
149
  placeholder: assistantCopy.placeholder,
161
150
  inputLabel: assistantCopy.composer,
162
151
  submitLabel: assistantCopy.send,
152
+ disabled,
153
+ readOnly: Boolean(options.readOnly),
163
154
  submitDisabled,
164
155
  trailing: choices,
165
- attachments: assistantDerived(context, () => draft.value.attachments.length
166
- ? h(ChatAttachments, {
167
- items: draft.value.attachments.map((attachment) => ({
168
- ...attachment,
169
- onRemove: disabled.value
170
- ? undefined
171
- : () => change({
172
- ...draft.value,
173
- attachments: draft.value.attachments.filter((item) => item !== attachment),
174
- }),
175
- })),
176
- })
177
- : null),
178
- hint: assistantDerived(context, () => unwrap(options.disabledReason ?? "")),
156
+ attachments: h(ChatAttachments, {
157
+ hidden: derived(() => draft.value.attachments.length === 0),
158
+ items: derived(() => draft.value.attachments.map((attachment) => ({
159
+ ...attachment,
160
+ onRemove: disabled.value
161
+ ? undefined
162
+ : () => change({
163
+ ...draft.value,
164
+ attachments: draft.value.attachments.filter((item) => item.id !== attachment.id),
165
+ }),
166
+ }))),
167
+ }),
168
+ hint: derived(() => unwrap(options.disabledReason ?? "")),
179
169
  onSubmit: send,
180
170
  onInput: (event) => {
181
171
  textVersion++;
182
172
  change({ ...draft.value, text: event.target.value });
183
- resize();
184
173
  },
185
174
  onKeyDown: (event) => {
186
- if (event.target === textarea &&
175
+ const target = event.target;
176
+ if (target instanceof HTMLTextAreaElement &&
177
+ target.dataset.chatInput !== undefined &&
187
178
  event.key === "Enter" &&
188
179
  !event.shiftKey &&
189
180
  !event.isComposing &&
190
181
  event.keyCode !== 229)
191
182
  void send(event);
192
183
  },
193
- ref: (form) => {
194
- let active = true;
195
- let stop;
196
- const observer = new ResizeObserver(resize);
197
- observer.observe(form);
198
- // Host refs run before children mount; find the native input after this tree is mounted.
199
- queueMicrotask(() => {
200
- if (!active || disposed || !form.isConnected)
201
- return;
202
- textarea = form.querySelector("textarea");
203
- stop = context.effect(() => {
204
- const value = text.value;
205
- textarea.disabled = !!disabled.value;
206
- textarea.readOnly = !!options.readOnly;
207
- queueMicrotask(() => {
208
- if (!disposed && textarea) {
209
- if (textarea.value !== value)
210
- textarea.value = value;
211
- resize();
212
- }
213
- });
214
- });
215
- resize();
216
- });
217
- return () => {
218
- active = false;
219
- stop?.();
220
- observer.disconnect();
221
- textarea = undefined;
222
- };
223
- },
224
184
  children: options.allowAttachments === false
225
185
  ? []
226
186
  : [
227
187
  h(IconButton, {
228
188
  label: assistantCopy.attach,
229
- disabled: assistantDerived(context, () => disabled.value || attaching.value),
189
+ disabled: derived(() => disabled.value || attaching.value),
230
190
  onClick: () => fileInput?.click(),
231
191
  children: h(Icon, { name: "paperclip" }),
232
192
  }),
@@ -240,5 +200,5 @@ export const AssistantComposer = defineComponent(assistantComposerContract, ({ o
240
200
  },
241
201
  }),
242
202
  ],
243
- }), context.part("feedback", "p", { role: "status", hidden: assistantDerived(context, () => !feedback.value) }, feedback));
203
+ }), context.part("feedback", "p", { role: "status", hidden: derived(() => !feedback.value) }, feedback));
244
204
  });
@@ -1,7 +1,5 @@
1
- import { type LifecycleScope, type Signal } from "meowjsx";
1
+ import { type Signal } from "meowjsx";
2
2
  import type { AssistantMessage, AssistantMessagePart, AssistantProcessStep, AssistantViewProps } from "./assistant-types.js";
3
- /** All derived values live in their owning component lifecycle. */
4
- export declare function assistantDerived<T>(context: Pick<LifecycleScope, "signal" | "effect">, read: () => T): import("meowjsx").WritableSignal<T>;
5
3
  export declare const assistantStepsContract: {
6
4
  readonly name: "assistant-steps";
7
5
  readonly parts: readonly ["root", "step", "label", "description", "status"];
@@ -1,4 +1,4 @@
1
- import { defineComponent, h, keyed, unwrap, } from "meowjsx";
1
+ import { defineComponent, derived, h, keyed, unwrap } from "meowjsx";
2
2
  import { ChatMessage } from "./message.js";
3
3
  import { ChatAttachments } from "./attachments.js";
4
4
  import { ChatToolCall } from "./tool-call.js";
@@ -7,42 +7,33 @@ import { ProcessGroup } from "../components/process-group.js";
7
7
  import { CodeBlock } from "../components/code-block.js";
8
8
  import { StatusDot } from "../components/status-dot.js";
9
9
  import { AssistantMarkdown } from "./assistant-markdown.js";
10
- /** All derived values live in their owning component lifecycle. */
11
- export function assistantDerived(context, read) {
12
- const value = context.signal(read());
13
- context.effect(() => {
14
- value.value = read();
15
- });
16
- return value;
17
- }
18
10
  export const assistantStepsContract = {
19
11
  name: "assistant-steps",
20
12
  parts: ["root", "step", "label", "description", "status"],
21
13
  };
22
- const AssistantStep = defineComponent(assistantStepsContract, ({ value }, context) => context.part("step", "li", null, h(StatusDot, { state: assistantDerived(context, () => value.value.tone ?? "unknown") }), context.part("label", "div", null, h("strong", null, assistantDerived(context, () => value.value.title)), context.part("description", "p", { hidden: assistantDerived(context, () => !value.value.description) }, assistantDerived(context, () => value.value.description ?? ""))), context.part("status", "span", null, assistantDerived(context, () => value.value.statusText ?? ""))));
14
+ const AssistantStep = defineComponent(assistantStepsContract, ({ value }, context) => context.part("step", "li", null, h(StatusDot, { state: derived(() => value.value.tone ?? "unknown") }), context.part("label", "div", null, h("strong", null, derived(() => value.value.title)), context.part("description", "p", { hidden: derived(() => !value.value.description) }, derived(() => value.value.description ?? ""))), context.part("status", "span", null, derived(() => value.value.statusText ?? ""))));
23
15
  export const AssistantSteps = defineComponent(assistantStepsContract, ({ steps }, context) => context.part("root", "ol", null, keyed(steps, (step) => step.id, (value) => h(AssistantStep, { value }))));
24
16
  export const AssistantPartView = defineComponent({ name: "assistant-part", parts: ["root"] }, ({ value, message, renderPart, onToolAction }, context) => {
25
17
  // The keyed identity includes kind, so this component's structural variant is stable.
26
18
  const initial = value.value;
27
- const custom = renderPart
28
- ? assistantDerived(context, () => renderPart(value.value, message.value))
29
- : undefined;
19
+ // Host slots may return a node. Component fallbacks stay mounted and take signals instead.
20
+ const custom = renderPart ? derived(() => renderPart(value.value, message.value)) : undefined;
30
21
  let fallback;
31
22
  if (initial.kind === "text") {
32
23
  fallback = h(AssistantMarkdown, {
33
- text: assistantDerived(context, () => value.value.text),
24
+ text: derived(() => value.value.text),
34
25
  });
35
26
  }
36
27
  else if (initial.kind === "tool") {
37
28
  const tool = () => value.value;
38
29
  fallback = h(ChatToolCall, {
39
- label: assistantDerived(context, () => tool().label),
40
- summary: assistantDerived(context, () => tool().summary),
41
- state: assistantDerived(context, () => tool().state ?? "unknown"),
42
- statusLabel: assistantDerived(context, () => tool().statusLabel),
43
- input: assistantDerived(context, () => tool().input),
44
- output: assistantDerived(context, () => tool().output),
45
- outputSummary: assistantDerived(context, () => tool().outputSummary),
30
+ label: derived(() => tool().label),
31
+ summary: derived(() => tool().summary),
32
+ state: derived(() => tool().state ?? "unknown"),
33
+ statusLabel: derived(() => tool().statusLabel),
34
+ input: derived(() => tool().input),
35
+ output: derived(() => tool().output),
36
+ outputSummary: derived(() => tool().outputSummary),
46
37
  maxLines: initial.maxLines,
47
38
  collapsible: true,
48
39
  open: initial.defaultOpen ?? false,
@@ -58,56 +49,57 @@ export const AssistantPartView = defineComponent({ name: "assistant-part", parts
58
49
  onToolAction(message.value.id, tool().id, "cancel");
59
50
  }
60
51
  : undefined,
61
- canRetry: assistantDerived(context, () => tool().canRetry ?? false),
62
- canCancel: assistantDerived(context, () => tool().canCancel ?? false),
63
- retryDisabled: assistantDerived(context, () => tool().retryDisabled ?? false),
64
- cancelDisabled: assistantDerived(context, () => tool().cancelDisabled ?? false),
52
+ canRetry: derived(() => tool().canRetry ?? false),
53
+ canCancel: derived(() => tool().canCancel ?? false),
54
+ retryDisabled: derived(() => tool().retryDisabled ?? false),
55
+ cancelDisabled: derived(() => tool().cancelDisabled ?? false),
65
56
  });
66
57
  }
67
58
  else if (initial.kind === "task") {
68
59
  const task = () => value.value;
69
60
  fallback = h(ChatTask, {
70
- title: assistantDerived(context, () => task().title),
71
- state: assistantDerived(context, () => task().state),
72
- statusLabel: assistantDerived(context, () => task().statusLabel),
73
- description: assistantDerived(context, () => task().description),
74
- executionText: assistantDerived(context, () => task().executionText),
75
- replyText: assistantDerived(context, () => task().replyText),
76
- progress: assistantDerived(context, () => task().progress),
61
+ title: derived(() => task().title),
62
+ state: derived(() => task().state),
63
+ statusLabel: derived(() => task().statusLabel),
64
+ description: derived(() => task().description),
65
+ executionText: derived(() => task().executionText),
66
+ replyText: derived(() => task().replyText),
67
+ progress: derived(() => task().progress),
77
68
  children: h(AssistantSteps, {
78
- steps: assistantDerived(context, () => task().steps ?? []),
69
+ steps: derived(() => task().steps ?? []),
79
70
  }),
80
71
  });
81
72
  }
82
73
  else if (initial.kind === "process") {
83
74
  fallback = h(ProcessGroup, {
84
- title: assistantDerived(context, () => value.value.title),
85
- status: assistantDerived(context, () => value.value.statusText),
75
+ title: derived(() => value.value.title),
76
+ status: derived(() => value.value.statusText),
86
77
  open: initial.defaultOpen ?? false,
87
78
  children: h(AssistantSteps, {
88
- steps: assistantDerived(context, () => value.value.steps),
79
+ steps: derived(() => value.value.steps),
89
80
  }),
90
81
  });
91
82
  }
92
83
  else if (initial.kind === "code") {
93
- // CodeBlock owns its copy/wrap/highlight lifecycle. Replace only this block on code changes.
94
- fallback = assistantDerived(context, () => {
95
- const part = value.value;
96
- return h(CodeBlock, { code: part.code, language: part.language });
84
+ fallback = h(CodeBlock, {
85
+ code: derived(() => value.value.code),
86
+ language: derived(() => value.value.language),
97
87
  });
98
88
  }
99
89
  else {
100
- fallback = assistantDerived(context, () => h(ChatAttachments, { items: value.value.items }));
90
+ fallback = h(ChatAttachments, {
91
+ items: derived(() => value.value.items),
92
+ });
101
93
  }
102
- const content = custom ? assistantDerived(context, () => unwrap(custom) ?? fallback) : fallback;
94
+ const content = custom ? derived(() => unwrap(custom) ?? fallback) : fallback;
103
95
  return context.part("root", "div", { "data-assistant-part-id": initial.id, "data-kind": initial.kind }, content);
104
96
  });
105
97
  export const AssistantMessageView = defineComponent({ name: "assistant-message", parts: ["root"] }, ({ value, renderPart, onToolAction }, context) => {
106
- const parts = assistantDerived(context, () => value.value.parts);
98
+ const parts = derived(() => value.value.parts);
107
99
  return context.part("root", "div", { "data-assistant-message-id": value.value.id }, h(ChatMessage, {
108
100
  role: value.value.role,
109
101
  author: "",
110
- header: h("div", { "data-assistant-message-header": true }, h("strong", null, assistantDerived(context, () => value.value.author)), h("time", null, assistantDerived(context, () => value.value.timestamp ?? "")), h("span", { role: "status" }, assistantDerived(context, () => value.value.status && value.value.status !== "complete" ? value.value.status : ""))),
102
+ header: h("div", { "data-assistant-message-header": true }, h("strong", null, derived(() => value.value.author)), h("time", null, derived(() => value.value.timestamp ?? "")), h("span", { role: "status" }, derived(() => value.value.status && value.value.status !== "complete" ? value.value.status : ""))),
111
103
  surface: "none",
112
104
  children: keyed(parts, (part) => `${part.id}:${part.kind}`, (part) => h(AssistantPartView, { value: part, message: value, renderPart, onToolAction })),
113
105
  }));
@@ -1,4 +1,4 @@
1
- import { defineComponent } from "meowjsx";
1
+ import { defineComponent, derived } from "meowjsx";
2
2
  import { Marked, Renderer } from "marked";
3
3
  const escape = (text) => text.replace(/[&<>"']/g, (value) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[value]);
4
4
  export function assistantSafeLink(href) {
@@ -24,10 +24,6 @@ const markdown = new Marked({ renderer, gfm: true, breaks: true });
24
24
  /** Raw HTML and images are text. Only explicit safe external links become navigation. */
25
25
  export const assistantMarkdown = (text) => markdown.parse(text, { async: false });
26
26
  export const assistantMarkdownContract = { name: "assistant-markdown", parts: ["root"] };
27
- export const AssistantMarkdown = defineComponent(assistantMarkdownContract, ({ text }, context) => {
28
- const html = context.signal({ __html: assistantMarkdown(text.value) });
29
- context.effect(() => {
30
- html.value = { __html: assistantMarkdown(text.value) };
31
- });
32
- return context.part("root", "div", { dangerouslySetInnerHTML: html });
33
- });
27
+ export const AssistantMarkdown = defineComponent(assistantMarkdownContract, ({ text }, context) => context.part("root", "div", {
28
+ dangerouslySetInnerHTML: derived(() => ({ __html: assistantMarkdown(text.value) })),
29
+ }));
@@ -1,8 +1,7 @@
1
- import { defineComponent, h } from "meowjsx";
1
+ import { defineComponent, derived, h, keyed } from "meowjsx";
2
2
  import { ChatQuestion } from "./question.js";
3
3
  import { Button } from "../components/button.js";
4
4
  import { Select } from "../components/select.js";
5
- import { assistantDerived } from "./assistant-content.js";
6
5
  import { assistantCopy as defaultAssistantCopy, } from "./assistant-types.js";
7
6
  export const assistantQuestionContract = {
8
7
  name: "assistant-question",
@@ -13,7 +12,7 @@ export const AssistantQuestionView = defineComponent(assistantQuestionContract,
13
12
  const answer = context.signal("");
14
13
  const sending = context.signal(false);
15
14
  const error = context.signal("");
16
- const disabled = assistantDerived(context, () => sending.value || value.value.state !== "open" || !onAnswer);
15
+ const disabled = derived(() => sending.value || value.value.state !== "open" || !onAnswer);
17
16
  let disposed = false;
18
17
  context.onCleanup(() => {
19
18
  disposed = true;
@@ -38,10 +37,10 @@ export const AssistantQuestionView = defineComponent(assistantQuestionContract,
38
37
  // Question state and answer acceptance remain facts supplied by the host.
39
38
  };
40
39
  return context.part("root", "form", { onSubmit: submit }, h(ChatQuestion, {
41
- question: assistantDerived(context, () => value.value.title),
40
+ question: derived(() => value.value.title),
42
41
  label: assistantCopy.questions,
43
- description: assistantDerived(context, () => value.value.description),
44
- feedback: assistantDerived(context, () => error.value ||
42
+ description: derived(() => value.value.description),
43
+ feedback: derived(() => error.value ||
45
44
  value.value.feedback ||
46
45
  (value.value.state === "submitting"
47
46
  ? assistantCopy.questionSubmitting
@@ -51,22 +50,22 @@ export const AssistantQuestionView = defineComponent(assistantQuestionContract,
51
50
  ? assistantCopy.questionUnavailable
52
51
  : "")),
53
52
  children: [
54
- context.part("options", "div", { hidden: assistantDerived(context, () => !value.value.options?.length) }, h(Select, {
53
+ context.part("options", "div", { hidden: derived(() => !value.value.options?.length) }, h(Select, {
55
54
  value: answer,
56
55
  disabled,
57
- "aria-label": value.value.title,
56
+ "aria-label": derived(() => value.value.title),
58
57
  onChange: (event) => {
59
58
  answer.value = event.currentTarget.value;
60
59
  },
61
- children: assistantDerived(context, () => [
60
+ children: [
62
61
  h("option", { value: "" }, assistantCopy.answerPlaceholder),
63
- ...(value.value.options ?? []).map((option) => h("option", { value: option.value }, option.label)),
64
- ]),
62
+ keyed(derived(() => value.value.options ?? []), (option) => option.value, (option) => h("option", { value: derived(() => option.value.value) }, derived(() => option.value.label))),
63
+ ],
65
64
  })),
66
65
  context.part("answer", "textarea", {
67
66
  value: answer,
68
67
  rows: 2,
69
- "aria-label": `${assistantCopy.answer}: ${value.value.title}`,
68
+ "aria-label": derived(() => `${assistantCopy.answer}: ${value.value.title}`),
70
69
  placeholder: assistantCopy.answerPlaceholder,
71
70
  disabled,
72
71
  onInput: (event) => {
@@ -78,14 +77,14 @@ export const AssistantQuestionView = defineComponent(assistantQuestionContract,
78
77
  h(Button, {
79
78
  type: "submit",
80
79
  size: "small",
81
- disabled: assistantDerived(context, () => disabled.value || !answer.value.trim()),
80
+ disabled: derived(() => disabled.value || !answer.value.trim()),
82
81
  children: assistantCopy.answer,
83
82
  }),
84
83
  onDismiss
85
84
  ? h(Button, {
86
85
  variant: "quiet",
87
86
  size: "small",
88
- disabled: assistantDerived(context, () => sending.value || value.value.state !== "open"),
87
+ disabled: derived(() => sending.value || value.value.state !== "open"),
89
88
  onClick: () => onDismiss(value.value.id),
90
89
  children: assistantCopy.dismiss,
91
90
  })