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.
- package/README.md +24 -8
- package/dist/src/chat/assistant-composer.js +58 -98
- package/dist/src/chat/assistant-content.d.ts +1 -3
- package/dist/src/chat/assistant-content.js +36 -44
- package/dist/src/chat/assistant-markdown.js +4 -8
- package/dist/src/chat/assistant-question.js +13 -14
- package/dist/src/chat/assistant.js +27 -26
- package/dist/src/chat/attachments.d.ts +3 -2
- package/dist/src/chat/attachments.js +39 -34
- package/dist/src/chat/composer-panel.d.ts +2 -3
- package/dist/src/chat/composer-panel.js +3 -4
- package/dist/src/chat/composer.d.ts +5 -3
- package/dist/src/chat/composer.js +67 -21
- package/dist/src/chat/task.js +9 -15
- package/dist/src/chat/tool-call.js +1 -8
- package/dist/src/components/accordion.d.ts +24 -0
- package/dist/src/components/accordion.js +50 -0
- package/dist/src/components/avatar.d.ts +22 -0
- package/dist/src/components/avatar.js +44 -0
- package/dist/src/components/checkbox.d.ts +6 -2
- package/dist/src/components/checkbox.js +36 -8
- package/dist/src/components/choice-group.d.ts +1 -0
- package/dist/src/components/choice-group.js +12 -17
- package/dist/src/components/choice-select.d.ts +3 -1
- package/dist/src/components/choice-select.js +56 -54
- package/dist/src/components/code-block.d.ts +3 -3
- package/dist/src/components/code-block.js +27 -23
- package/dist/src/components/context-menu.d.ts +16 -0
- package/dist/src/components/context-menu.js +49 -0
- package/dist/src/components/disclosure.d.ts +2 -2
- package/dist/src/components/disclosure.js +1 -1
- package/dist/src/components/index.d.ts +9 -0
- package/dist/src/components/index.js +9 -0
- package/dist/src/components/link.d.ts +13 -0
- package/dist/src/components/link.js +9 -0
- package/dist/src/components/menu-button.d.ts +13 -0
- package/dist/src/components/menu-button.js +10 -0
- package/dist/src/components/menu.d.ts +4 -0
- package/dist/src/components/menu.js +3 -3
- package/dist/src/components/meta-row.d.ts +5 -4
- package/dist/src/components/meta-row.js +34 -18
- package/dist/src/components/nav-item.js +2 -5
- package/dist/src/components/number-input.d.ts +29 -0
- package/dist/src/components/number-input.js +137 -0
- package/dist/src/components/output-block.js +1 -8
- package/dist/src/components/path-picker.js +5 -10
- package/dist/src/components/pill.js +2 -5
- package/dist/src/components/popover.js +4 -4
- package/dist/src/components/progress.d.ts +15 -0
- package/dist/src/components/progress.js +12 -0
- package/dist/src/components/risk-confirmation.js +2 -5
- package/dist/src/components/segmented-control.js +3 -3
- package/dist/src/components/skeleton-boundary.js +4 -7
- package/dist/src/components/slider.d.ts +22 -0
- package/dist/src/components/slider.js +49 -0
- package/dist/src/components/table.d.ts +41 -0
- package/dist/src/components/table.js +146 -0
- package/dist/src/components/tabs.d.ts +1 -1
- package/dist/src/components/tabs.js +11 -20
- package/dist/src/components/text-shimmer.js +2 -5
- package/dist/src/registry/index.d.ts +62 -3
- package/dist/src/registry/index.js +18 -2
- package/dist/src/theme/chat/composer-panel.styles.js +4 -1
- package/dist/src/theme/chat/composer.styles.js +45 -67
- package/dist/src/theme/chat/task.styles.js +5 -6
- package/dist/src/theme/components/accordion.styles.d.ts +1 -0
- package/dist/src/theme/components/accordion.styles.js +63 -0
- package/dist/src/theme/components/avatar.styles.d.ts +1 -0
- package/dist/src/theme/components/avatar.styles.js +52 -0
- package/dist/src/theme/components/button.styles.js +9 -0
- package/dist/src/theme/components/card.styles.js +2 -0
- package/dist/src/theme/components/context-menu.styles.d.ts +1 -0
- package/dist/src/theme/components/context-menu.styles.js +14 -0
- package/dist/src/theme/components/link.styles.d.ts +1 -0
- package/dist/src/theme/components/link.styles.js +33 -0
- package/dist/src/theme/components/menu.styles.js +9 -3
- package/dist/src/theme/components/number-input.styles.d.ts +1 -0
- package/dist/src/theme/components/number-input.styles.js +106 -0
- package/dist/src/theme/components/progress.styles.d.ts +1 -0
- package/dist/src/theme/components/progress.styles.js +71 -0
- package/dist/src/theme/components/slider.styles.d.ts +1 -0
- package/dist/src/theme/components/slider.styles.js +129 -0
- package/dist/src/theme/components/table.styles.d.ts +1 -0
- package/dist/src/theme/components/table.styles.js +156 -0
- package/dist/src/theme/components/toggle.styles.js +10 -0
- package/dist/src/theme/index.d.ts +1 -1
- package/dist/src/theme/index.js +16 -0
- 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
|
-
|
|
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,
|
|
316
|
-
SearchInput, Disclosure,
|
|
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`
|
|
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
|
|
369
|
-
`surface="none"` removes
|
|
370
|
-
`layout="inline"` puts short drafts and actions on the same row, and long drafts keep growing;
|
|
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`.
|
|
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 =
|
|
21
|
-
const 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 =
|
|
26
|
-
const submitDisabled =
|
|
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
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
203
|
+
}), context.part("feedback", "p", { role: "status", hidden: derived(() => !feedback.value) }, feedback));
|
|
244
204
|
});
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { type
|
|
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
|
|
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:
|
|
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
|
-
|
|
28
|
-
|
|
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:
|
|
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:
|
|
40
|
-
summary:
|
|
41
|
-
state:
|
|
42
|
-
statusLabel:
|
|
43
|
-
input:
|
|
44
|
-
output:
|
|
45
|
-
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:
|
|
62
|
-
canCancel:
|
|
63
|
-
retryDisabled:
|
|
64
|
-
cancelDisabled:
|
|
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:
|
|
71
|
-
state:
|
|
72
|
-
statusLabel:
|
|
73
|
-
description:
|
|
74
|
-
executionText:
|
|
75
|
-
replyText:
|
|
76
|
-
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:
|
|
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:
|
|
85
|
-
status:
|
|
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:
|
|
79
|
+
steps: derived(() => value.value.steps),
|
|
89
80
|
}),
|
|
90
81
|
});
|
|
91
82
|
}
|
|
92
83
|
else if (initial.kind === "code") {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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 =
|
|
90
|
+
fallback = h(ChatAttachments, {
|
|
91
|
+
items: derived(() => value.value.items),
|
|
92
|
+
});
|
|
101
93
|
}
|
|
102
|
-
const content = custom ?
|
|
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 =
|
|
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,
|
|
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) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[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
|
-
|
|
29
|
-
|
|
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 =
|
|
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:
|
|
40
|
+
question: derived(() => value.value.title),
|
|
42
41
|
label: assistantCopy.questions,
|
|
43
|
-
description:
|
|
44
|
-
feedback:
|
|
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:
|
|
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:
|
|
60
|
+
children: [
|
|
62
61
|
h("option", { value: "" }, assistantCopy.answerPlaceholder),
|
|
63
|
-
|
|
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:
|
|
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:
|
|
87
|
+
disabled: derived(() => sending.value || value.value.state !== "open"),
|
|
89
88
|
onClick: () => onDismiss(value.value.id),
|
|
90
89
|
children: assistantCopy.dismiss,
|
|
91
90
|
})
|