@kerf-js/veneer 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +1338 -2
- package/package.json +56 -3
- package/plugin.d.mts +187 -0
- package/plugin.mjs +399 -0
- package/src/Accordion.tsx +98 -0
- package/src/Alert.tsx +55 -0
- package/src/Badge.tsx +39 -0
- package/src/Button.tsx +175 -0
- package/src/Calendar-month.tsx +140 -0
- package/src/Calendar.tsx +335 -0
- package/src/Canvas.tsx +221 -0
- package/src/Card.tsx +85 -0
- package/src/Chart.tsx +278 -0
- package/src/Charts.tsx +158 -0
- package/src/Chip.tsx +61 -0
- package/src/Choice-checkbox.tsx +53 -0
- package/src/Choice-parts.tsx +7 -0
- package/src/Choice-radio.tsx +78 -0
- package/src/Choice-segmented.tsx +76 -0
- package/src/Choice-switch.tsx +51 -0
- package/src/Choice.tsx +4 -0
- package/src/CloseX.tsx +14 -0
- package/src/CodeBlock.tsx +81 -0
- package/src/CodeInput.tsx +256 -0
- package/src/Combobox.tsx +281 -0
- package/src/CommandPalette-controller.ts +314 -0
- package/src/CommandPalette-rows.tsx +137 -0
- package/src/CommandPalette.tsx +196 -0
- package/src/DataGrid-actions.ts +119 -0
- package/src/DataGrid-body.tsx +58 -0
- package/src/DataGrid-controller.ts +145 -0
- package/src/DataGrid-header.tsx +108 -0
- package/src/DataGrid-model.ts +248 -0
- package/src/DataGrid-pivot.tsx +108 -0
- package/src/DataGrid-rows.tsx +296 -0
- package/src/DataGrid-toolbar.tsx +127 -0
- package/src/DataGrid-tree.ts +149 -0
- package/src/DataGrid-viewport.tsx +37 -0
- package/src/DataGrid.tsx +145 -0
- package/src/DateField-presets.tsx +27 -0
- package/src/DateField-range.tsx +370 -0
- package/src/DateField.tsx +295 -0
- package/src/Dither.tsx +313 -0
- package/src/Drawer.tsx +123 -0
- package/src/DurationField.tsx +227 -0
- package/src/Feed.tsx +78 -0
- package/src/Field/view.tsx +147 -0
- package/src/Field.tsx +238 -0
- package/src/HamburgerMenu.tsx +119 -0
- package/src/Icon.tsx +15 -0
- package/src/Kbd.tsx +6 -0
- package/src/KeyValueEditor/actions.ts +75 -0
- package/src/KeyValueEditor/rows.tsx +104 -0
- package/src/KeyValueEditor.tsx +112 -0
- package/src/Layout.tsx +221 -0
- package/src/Markdown.tsx +127 -0
- package/src/MentionsInput/actions.ts +161 -0
- package/src/MentionsInput/end.tsx +82 -0
- package/src/MentionsInput.tsx +103 -0
- package/src/Menu.tsx +221 -0
- package/src/Modal.tsx +109 -0
- package/src/MonthPicker/month.tsx +117 -0
- package/src/MonthPicker/period.tsx +197 -0
- package/src/MonthPicker/shared.tsx +272 -0
- package/src/MonthPicker/week.tsx +103 -0
- package/src/MonthPicker.tsx +11 -0
- package/src/MultiSelect.tsx +139 -0
- package/src/Nav.tsx +36 -0
- package/src/NumberField.tsx +156 -0
- package/src/Pagination.tsx +335 -0
- package/src/PaymentCard.tsx +111 -0
- package/src/Picker.tsx +228 -0
- package/src/PlaceField.tsx +285 -0
- package/src/Popover.tsx +88 -0
- package/src/Presence.tsx +37 -0
- package/src/Progress.tsx +71 -0
- package/src/RecurrenceField.tsx +372 -0
- package/src/RichSelect/codes.tsx +94 -0
- package/src/RichSelect/list.tsx +380 -0
- package/src/RichSelect/phone-view.tsx +114 -0
- package/src/RichSelect/phone.tsx +305 -0
- package/src/RichSelect/search-keys.ts +28 -0
- package/src/RichSelect/timezone.tsx +53 -0
- package/src/RichSelect.tsx +13 -0
- package/src/RichTextEditor/controller.tsx +305 -0
- package/src/RichTextEditor/editor.tsx +61 -0
- package/src/RichTextEditor/tools.tsx +132 -0
- package/src/RichTextEditor/view.tsx +210 -0
- package/src/RichTextEditor.tsx +9 -0
- package/src/ScrollGrid/measure.ts +39 -0
- package/src/ScrollGrid/parts.tsx +112 -0
- package/src/ScrollGrid.tsx +375 -0
- package/src/ScrollRail.tsx +114 -0
- package/src/ScrollView.tsx +57 -0
- package/src/Segments/controller.tsx +148 -0
- package/src/Segments/events.ts +99 -0
- package/src/Segments/view.tsx +77 -0
- package/src/Segments.tsx +2 -0
- package/src/Select.tsx +343 -0
- package/src/Shape.tsx +41 -0
- package/src/Shell/branches.tsx +108 -0
- package/src/Shell/button.tsx +33 -0
- package/src/Shell/shared.tsx +220 -0
- package/src/Shell/shell.tsx +25 -0
- package/src/Shell/state.ts +138 -0
- package/src/Shell/view.tsx +280 -0
- package/src/Shell.tsx +17 -0
- package/src/SideNav/sections.tsx +50 -0
- package/src/SideNav/state.ts +140 -0
- package/src/SideNav.tsx +130 -0
- package/src/SideNavTitle.tsx +25 -0
- package/src/SignaturePad/state.ts +172 -0
- package/src/SignaturePad/view.tsx +69 -0
- package/src/SignaturePad.tsx +76 -0
- package/src/Skeleton.tsx +46 -0
- package/src/Slider.tsx +81 -0
- package/src/Spinner.tsx +21 -0
- package/src/Stage-director.ts +361 -0
- package/src/Stage-look.ts +75 -0
- package/src/Stage-poster.tsx +62 -0
- package/src/Stage-types.ts +206 -0
- package/src/Stage.tsx +147 -0
- package/src/TabBar.tsx +114 -0
- package/src/Table-actions.tsx +51 -0
- package/src/Table-base.ts +70 -0
- package/src/Table-body.tsx +84 -0
- package/src/Table-columns.tsx +58 -0
- package/src/Table-details.tsx +66 -0
- package/src/Table-editor.tsx +66 -0
- package/src/Table-head.tsx +52 -0
- package/src/Table-model.ts +82 -0
- package/src/Table-notice.ts +39 -0
- package/src/Table-paging.ts +50 -0
- package/src/Table-rows.tsx +308 -0
- package/src/Table-selection.ts +63 -0
- package/src/Table-sortbar.tsx +41 -0
- package/src/Table-source.ts +66 -0
- package/src/Table-toolbar.tsx +71 -0
- package/src/Table-types.ts +115 -0
- package/src/Table-view.tsx +87 -0
- package/src/Table.tsx +31 -0
- package/src/Tabs.tsx +129 -0
- package/src/Tag.tsx +40 -0
- package/src/Ticker.tsx +42 -0
- package/src/TimeField-date-model.ts +77 -0
- package/src/TimeField-date-view.tsx +152 -0
- package/src/TimeField-model.ts +80 -0
- package/src/TimeField-options.tsx +224 -0
- package/src/TimeField-slots.tsx +32 -0
- package/src/TimeField-types.ts +33 -0
- package/src/TimeField-view.tsx +124 -0
- package/src/TimeField.tsx +126 -0
- package/src/Toast.tsx +143 -0
- package/src/Toggle.tsx +75 -0
- package/src/Tooltip.tsx +69 -0
- package/src/Type.tsx +136 -0
- package/src/VirtualList-controls.ts +105 -0
- package/src/VirtualList-data.ts +43 -0
- package/src/VirtualList-measure.ts +169 -0
- package/src/VirtualList-metrics.ts +41 -0
- package/src/VirtualList-mount.ts +145 -0
- package/src/VirtualList-rows.tsx +91 -0
- package/src/VirtualList-types.ts +76 -0
- package/src/VirtualList-view.tsx +123 -0
- package/src/VirtualList.tsx +81 -0
- package/src/admin/ApiKeys-actions.ts +124 -0
- package/src/admin/ApiKeys-form.tsx +64 -0
- package/src/admin/ApiKeys-view.tsx +101 -0
- package/src/admin/ApiKeys.tsx +224 -0
- package/src/admin/Audit.tsx +246 -0
- package/src/admin/Billing.tsx +307 -0
- package/src/admin/Cart.tsx +177 -0
- package/src/admin/Checkout-address.tsx +125 -0
- package/src/admin/Checkout-cart.tsx +78 -0
- package/src/admin/Checkout-coupon.ts +34 -0
- package/src/admin/Checkout-done.tsx +31 -0
- package/src/admin/Checkout-model.ts +33 -0
- package/src/admin/Checkout-navigation.ts +76 -0
- package/src/admin/Checkout-payment-view.tsx +49 -0
- package/src/admin/Checkout-payment.ts +80 -0
- package/src/admin/Checkout-review.tsx +60 -0
- package/src/admin/Checkout-shipping.tsx +47 -0
- package/src/admin/Checkout-state.ts +122 -0
- package/src/admin/Checkout-steps.ts +10 -0
- package/src/admin/Checkout-summary.tsx +97 -0
- package/src/admin/Checkout-types.ts +60 -0
- package/src/admin/Checkout-view.tsx +51 -0
- package/src/admin/Checkout.tsx +72 -0
- package/src/admin/CsvImport-actions.ts +131 -0
- package/src/admin/CsvImport.tsx +379 -0
- package/src/admin/Danger.tsx +240 -0
- package/src/admin/Integrations/Card.tsx +82 -0
- package/src/admin/Integrations/Webhooks.tsx +341 -0
- package/src/admin/Integrations.tsx +169 -0
- package/src/admin/InviteDialog.tsx +153 -0
- package/src/admin/Members/columns.tsx +181 -0
- package/src/admin/Members.tsx +316 -0
- package/src/admin/Order.tsx +115 -0
- package/src/admin/PlainTable.tsx +34 -0
- package/src/admin/Plans.tsx +375 -0
- package/src/admin/SaveBar/actions.ts +86 -0
- package/src/admin/SaveBar.tsx +153 -0
- package/src/admin/Secret.tsx +74 -0
- package/src/admin/Settings.tsx +145 -0
- package/src/admin/StepBar.tsx +66 -0
- package/src/admin/TagsInput/actions.ts +60 -0
- package/src/admin/TagsInput.tsx +95 -0
- package/src/admin/atoms.tsx +73 -0
- package/src/admin/index.ts +67 -0
- package/src/agent/Actions/reasons.tsx +38 -0
- package/src/agent/Actions.tsx +166 -0
- package/src/agent/AgentPlan.tsx +86 -0
- package/src/agent/ArtifactPanel.tsx +299 -0
- package/src/agent/Assistant.tsx +168 -0
- package/src/agent/Checkpoint.tsx +19 -0
- package/src/agent/Cite.tsx +70 -0
- package/src/agent/ContextMeter.tsx +70 -0
- package/src/agent/Conversation.tsx +70 -0
- package/src/agent/Message.tsx +92 -0
- package/src/agent/ModelPicker.tsx +167 -0
- package/src/agent/Prompt-model.ts +118 -0
- package/src/agent/Prompt-view.tsx +246 -0
- package/src/agent/Prompt.tsx +128 -0
- package/src/agent/Prose.tsx +118 -0
- package/src/agent/Question.tsx +137 -0
- package/src/agent/Reasoning.tsx +31 -0
- package/src/agent/Shimmer.tsx +11 -0
- package/src/agent/Sources.tsx +23 -0
- package/src/agent/SpeechInput.tsx +243 -0
- package/src/agent/Suggestions.tsx +36 -0
- package/src/agent/ToolCall.tsx +219 -0
- package/src/agent/TraceViewer.tsx +96 -0
- package/src/agent/bits.tsx +88 -0
- package/src/agent/index.ts +38 -0
- package/src/bind.ts +57 -0
- package/src/collab/AutoTrack.tsx +91 -0
- package/src/collab/Comments.tsx +204 -0
- package/src/collab/Composer/state.ts +125 -0
- package/src/collab/Composer/view.tsx +155 -0
- package/src/collab/Composer.tsx +141 -0
- package/src/collab/ConversationList.tsx +120 -0
- package/src/collab/Cursors.tsx +71 -0
- package/src/collab/DataIntegrity.tsx +103 -0
- package/src/collab/Kanban-card.ts +74 -0
- package/src/collab/Kanban.tsx +368 -0
- package/src/collab/Lock.tsx +36 -0
- package/src/collab/PresenceStack.tsx +176 -0
- package/src/collab/ShareDialog.tsx +273 -0
- package/src/collab/Status.tsx +101 -0
- package/src/collab/SyncedForm.tsx +42 -0
- package/src/collab/Thread/Message.tsx +265 -0
- package/src/collab/Thread/rows.tsx +56 -0
- package/src/collab/Thread.tsx +323 -0
- package/src/collab/VersionHistory.tsx +173 -0
- package/src/collab/ViewportRail.tsx +73 -0
- package/src/collab/index.ts +37 -0
- package/src/collab/peer.tsx +42 -0
- package/src/fields.ts +5 -0
- package/src/flow/AuthScreen.tsx +81 -0
- package/src/flow/AuthSteps.tsx +296 -0
- package/src/flow/Checklist.tsx +211 -0
- package/src/flow/ConnBanner.tsx +304 -0
- package/src/flow/Flow.tsx +97 -0
- package/src/flow/MfaSetup.tsx +244 -0
- package/src/flow/Otp.tsx +243 -0
- package/src/flow/ReauthDialog.tsx +79 -0
- package/src/flow/ShortcutsOverlay.tsx +121 -0
- package/src/flow/SignGate.tsx +184 -0
- package/src/flow/SignIn.tsx +136 -0
- package/src/flow/SignUp.tsx +149 -0
- package/src/flow/Sso.tsx +96 -0
- package/src/flow/SystemPage/accounts.tsx +74 -0
- package/src/flow/SystemPage/art.tsx +113 -0
- package/src/flow/SystemPage.tsx +395 -0
- package/src/flow/Tour.tsx +207 -0
- package/src/flow/index.ts +29 -0
- package/src/flow/kit.tsx +334 -0
- package/src/index.ts +237 -0
- package/src/layout.css +4 -0
- package/src/links.css +4 -0
- package/src/live/ActivityFeed.tsx +88 -0
- package/src/live/Bell.tsx +108 -0
- package/src/live/Connection.tsx +113 -0
- package/src/live/Inbox.tsx +113 -0
- package/src/live/InboxFeed.tsx +67 -0
- package/src/live/InboxGestures.ts +41 -0
- package/src/live/InboxHandlers.ts +102 -0
- package/src/live/InboxHeader.tsx +81 -0
- package/src/live/InboxModel.ts +81 -0
- package/src/live/InboxRow.tsx +125 -0
- package/src/live/MeetingRoom.tsx +22 -0
- package/src/live/MeetingRoomControlBar.tsx +197 -0
- package/src/live/MeetingRoomHandlers.ts +53 -0
- package/src/live/MeetingRoomLayout.tsx +27 -0
- package/src/live/MeetingRoomModel.ts +49 -0
- package/src/live/MeetingRoomMount.ts +49 -0
- package/src/live/MeetingRoomParts.tsx +178 -0
- package/src/live/MeetingRoomPerson.tsx +21 -0
- package/src/live/MeetingRoomState.ts +88 -0
- package/src/live/MeetingRoomTile.tsx +84 -0
- package/src/live/MeetingRoomTypes.ts +68 -0
- package/src/live/MeetingRoomView.tsx +36 -0
- package/src/live/NotificationPreferences.tsx +99 -0
- package/src/live/NotificationPreferencesActions.ts +55 -0
- package/src/live/NotificationPreferencesCell.tsx +26 -0
- package/src/live/NotificationPreferencesCells.tsx +59 -0
- package/src/live/NotificationPreferencesGrid.tsx +129 -0
- package/src/live/NotificationPreferencesModel.tsx +91 -0
- package/src/live/NotificationPreferencesSave.ts +85 -0
- package/src/live/NotificationPreferencesWatch.ts +31 -0
- package/src/live/Prejoin.tsx +238 -0
- package/src/live/PrejoinMeter.tsx +26 -0
- package/src/live/PrejoinPreview.tsx +53 -0
- package/src/live/PushSoftAsk.tsx +63 -0
- package/src/live/TransportPicker.tsx +341 -0
- package/src/live/TransportPickerDetails.tsx +130 -0
- package/src/live/index.ts +31 -0
- package/src/live/notify.tsx +22 -0
- package/src/live/shared.tsx +110 -0
- package/src/parts.tsx +199 -0
- package/src/plugin/catalog.mjs +129 -0
- package/src/plugin/dtcg.mjs +79 -0
- package/src/plugin/icons.mjs +7 -0
- package/src/plugin/seed.mjs +40 -0
- package/src/plugin/theme-context.mjs +44 -0
- package/src/plugin/theme-css.mjs +143 -0
- package/src/plugin/theme-motion.mjs +43 -0
- package/src/plugin/theme-parts.d.mts +41 -0
- package/src/plugin/theme-parts.mjs +224 -0
- package/src/plugin/theme-text.mjs +93 -0
- package/src/plugin/theme-values.mjs +15 -0
- package/src/plugin/theme.d.mts +82 -0
- package/src/plugin/theme.mjs +316 -0
- package/src/schedule/Agenda.tsx +124 -0
- package/src/schedule/AgendaActions.ts +31 -0
- package/src/schedule/AgendaDay.tsx +124 -0
- package/src/schedule/AgendaGestures.ts +27 -0
- package/src/schedule/AgendaKeys.ts +52 -0
- package/src/schedule/AgendaModel.ts +82 -0
- package/src/schedule/AgendaNavigation.ts +38 -0
- package/src/schedule/AgendaPage.tsx +39 -0
- package/src/schedule/AgendaStrip.tsx +55 -0
- package/src/schedule/AvailabilityEditor-actions.ts +146 -0
- package/src/schedule/AvailabilityEditor-day.tsx +119 -0
- package/src/schedule/AvailabilityEditor-view.tsx +205 -0
- package/src/schedule/AvailabilityEditor.tsx +113 -0
- package/src/schedule/BookingCalendar.tsx +121 -0
- package/src/schedule/BookingCalendarActions.ts +85 -0
- package/src/schedule/BookingCalendarModel.ts +86 -0
- package/src/schedule/BookingCalendarParts.tsx +87 -0
- package/src/schedule/Calendar/AgendaView.tsx +45 -0
- package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
- package/src/schedule/Calendar/CalendarMain.tsx +47 -0
- package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
- package/src/schedule/Calendar/Column.tsx +129 -0
- package/src/schedule/Calendar/EventBlock.tsx +71 -0
- package/src/schedule/Calendar/MiniMonth.tsx +169 -0
- package/src/schedule/Calendar/MonthGrid.tsx +296 -0
- package/src/schedule/Calendar/TimeGrid.tsx +252 -0
- package/src/schedule/Calendar/Timeline.tsx +287 -0
- package/src/schedule/Calendar/ZoneChip.tsx +73 -0
- package/src/schedule/Calendar/calendar-shell.ts +160 -0
- package/src/schedule/Calendar/calendar-state.ts +30 -0
- package/src/schedule/Calendar/now-spans.tsx +33 -0
- package/src/schedule/Calendar/shared.ts +3 -0
- package/src/schedule/Calendar/state-actions.ts +189 -0
- package/src/schedule/Calendar/state-base.ts +143 -0
- package/src/schedule/Calendar/state-keys.ts +128 -0
- package/src/schedule/Calendar/time-fit.ts +84 -0
- package/src/schedule/Calendar.tsx +182 -0
- package/src/schedule/EventEditor.tsx +267 -0
- package/src/schedule/EventPopover.tsx +190 -0
- package/src/schedule/MeetingPlanner-model.ts +222 -0
- package/src/schedule/MeetingPlanner-view.tsx +310 -0
- package/src/schedule/MeetingPlanner.tsx +122 -0
- package/src/schedule/MoveSheet.tsx +168 -0
- package/src/schedule/YearView-model.ts +164 -0
- package/src/schedule/YearView-parts.tsx +147 -0
- package/src/schedule/YearView.tsx +100 -0
- package/src/schedule/bits.tsx +65 -0
- package/src/schedule/index.ts +25 -0
- package/src/skeleton-css.ts +4 -0
- package/src/styles.ts +13 -0
- package/src/type.css +15 -0
- package/src/ui.ts +41 -0
- package/src/use-ui.ts +10 -0
- package/tailwind.css +38 -0
- package/tokens/color.mjs +87 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { SparkleIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import {
|
|
3
|
+
announce,
|
|
4
|
+
answerText,
|
|
5
|
+
copyConfirm,
|
|
6
|
+
uid,
|
|
7
|
+
type AgentTool,
|
|
8
|
+
type Answer,
|
|
9
|
+
type AnswerBlock,
|
|
10
|
+
} from '@kerf-js/veneer-core'
|
|
11
|
+
import { derived, onMount, untrack, watch } from '@kerf-js/core'
|
|
12
|
+
import { Alert } from '../Alert'
|
|
13
|
+
import { Button } from '../Button'
|
|
14
|
+
import { MessageActions, type Feedback } from './Actions'
|
|
15
|
+
import { Prose } from './Prose'
|
|
16
|
+
import { Question } from './Question'
|
|
17
|
+
import { Reasoning } from './Reasoning'
|
|
18
|
+
import { Sources } from './Sources'
|
|
19
|
+
import { ToolCall } from './ToolCall'
|
|
20
|
+
import '../styles'
|
|
21
|
+
import '@kerf-js/veneer-core/styles/app/assistant.css'
|
|
22
|
+
|
|
23
|
+
/** Props for Assistant. */
|
|
24
|
+
export interface AssistantProps {
|
|
25
|
+
/** The folded value: `foldAnswer(events)`, or what a stream folds to. */
|
|
26
|
+
answer: Answer
|
|
27
|
+
/** The turn number, for its name: "Assistant answer 2". */
|
|
28
|
+
n?: number
|
|
29
|
+
arrive?: boolean
|
|
30
|
+
/** Was there on load: approvals and questions take no focus and announce nothing. */
|
|
31
|
+
quiet?: boolean | undefined
|
|
32
|
+
/** Render a block of answer text yourself (Markdown, say); the default is `Prose`. */
|
|
33
|
+
render?: (text: string, answer: Answer) => unknown
|
|
34
|
+
/** Called when a tool call is approved, with its arguments as edited and whether to always allow it. */
|
|
35
|
+
onApprove?: (tool: AgentTool, args: string, always: boolean) => void
|
|
36
|
+
/** Called when a tool call is denied. */
|
|
37
|
+
onDeny?: (tool: AgentTool) => void
|
|
38
|
+
alwaysAllow?: (tool: AgentTool) => string | undefined
|
|
39
|
+
/** Called with a question's id and the answer picked or typed. */
|
|
40
|
+
onAnswer?: (id: string, answer: string | string[]) => void
|
|
41
|
+
/** Called with `up`, `down` or null when thumbs change, and the reason picked for a thumbs down. */
|
|
42
|
+
onFeedback?: (value: Feedback, reason?: string) => void
|
|
43
|
+
/** Adds Regenerate: ask for a new answer. */
|
|
44
|
+
onRegenerate?: () => void
|
|
45
|
+
/** Adds Branch: start a new conversation from this answer. */
|
|
46
|
+
onBranch?: () => void
|
|
47
|
+
/** Which of several answers is shown, with arrows between them. */
|
|
48
|
+
branch?: { index: number; count: number; onChange: (index: number) => void }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Thought = Extract<AnswerBlock, { kind: 'reasoning' }>
|
|
52
|
+
type Said = Extract<AnswerBlock, { kind: 'text' }>
|
|
53
|
+
type Asked = Extract<AnswerBlock, { kind: 'question' }>
|
|
54
|
+
|
|
55
|
+
function Block({ block, base, p }: { block: AnswerBlock; base: string; p: AssistantProps }) {
|
|
56
|
+
const tool = derived(() => p.answer.tools.find((t) => t.id === block.id))
|
|
57
|
+
const kind = derived(() => block.kind)
|
|
58
|
+
// once per kind: a row's nodes are read again whenever the list changes
|
|
59
|
+
const view = derived(() => {
|
|
60
|
+
const k = kind.value
|
|
61
|
+
return untrack(() => {
|
|
62
|
+
if (k === 'reasoning')
|
|
63
|
+
return (
|
|
64
|
+
<Reasoning
|
|
65
|
+
text={(block as Thought).text}
|
|
66
|
+
streaming={(block as Thought).streaming}
|
|
67
|
+
seconds={(block as Thought).seconds}
|
|
68
|
+
/>
|
|
69
|
+
)
|
|
70
|
+
if (k === 'text')
|
|
71
|
+
return p.render ? (
|
|
72
|
+
<>{p.render((block as Said).text, p.answer)}</>
|
|
73
|
+
) : (
|
|
74
|
+
<Prose text={(block as Said).text} sources={p.answer.sources} base={base} />
|
|
75
|
+
)
|
|
76
|
+
if (k === 'question')
|
|
77
|
+
return (
|
|
78
|
+
<Question
|
|
79
|
+
question={(block as Asked).question}
|
|
80
|
+
quiet={p.quiet}
|
|
81
|
+
onAnswer={(a) => p.onAnswer?.(block.id, a)}
|
|
82
|
+
/>
|
|
83
|
+
)
|
|
84
|
+
return (
|
|
85
|
+
<ToolCall
|
|
86
|
+
call={tool.value!}
|
|
87
|
+
quiet={p.quiet}
|
|
88
|
+
alwaysAllow={p.alwaysAllow?.(tool.value!)}
|
|
89
|
+
onApprove={(a, al) => p.onApprove?.(tool.value!, a, al)}
|
|
90
|
+
onDeny={() => p.onDeny?.(tool.value!)}
|
|
91
|
+
/>
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
return <>{view.value}</>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The assistant's turn (07 §1.1, §1.2): renders the folded Answer only, so replay and hydration take the same path.
|
|
100
|
+
* Caret while streaming, aria-busy until done; the end of a turn is announced once, never each token.
|
|
101
|
+
*/
|
|
102
|
+
export function Assistant(p: AssistantProps) {
|
|
103
|
+
const base = uid('ans')
|
|
104
|
+
const st = derived(() => p.answer.state)
|
|
105
|
+
const busy = derived(
|
|
106
|
+
() => st.value === 'waiting' || st.value === 'streaming' || st.value === 'approval',
|
|
107
|
+
)
|
|
108
|
+
const empty = derived(() => p.answer.blocks.length === 0 && st.value !== 'error')
|
|
109
|
+
const blocks = derived(() => p.answer.blocks)
|
|
110
|
+
const many = derived(() => p.answer.sources.length > 0)
|
|
111
|
+
let root: HTMLElement | undefined
|
|
112
|
+
onMount(() => {
|
|
113
|
+
watch(
|
|
114
|
+
() => st.value,
|
|
115
|
+
(s, prev) => {
|
|
116
|
+
if (prev === undefined || !root) return
|
|
117
|
+
const doc = root.ownerDocument
|
|
118
|
+
if (s === 'done') announce(doc, 'Answer ready')
|
|
119
|
+
if (s === 'stopped') announce(doc, 'Stopped')
|
|
120
|
+
if (s === 'error') announce(doc, 'The answer failed', true)
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
return (
|
|
125
|
+
<article
|
|
126
|
+
ref={(n) => (root = n)}
|
|
127
|
+
data-scope="assistant"
|
|
128
|
+
data-state={st.value}
|
|
129
|
+
aria-label={p.n !== undefined ? `Assistant answer ${p.n}` : 'Assistant answer'}
|
|
130
|
+
aria-busy={busy.value ? 'true' : undefined}
|
|
131
|
+
data-arrive={p.arrive ? '' : undefined}
|
|
132
|
+
>
|
|
133
|
+
<span data-part="mark">
|
|
134
|
+
<SparkleIcon />
|
|
135
|
+
</span>
|
|
136
|
+
<div data-part="content">
|
|
137
|
+
{empty.value && <p></p>}
|
|
138
|
+
{blocks.value.map((b) => (
|
|
139
|
+
<Block key={b.id} block={b} base={base} p={p} />
|
|
140
|
+
))}
|
|
141
|
+
{st.value === 'error' && (
|
|
142
|
+
<Alert tone="critical" title="The answer failed">
|
|
143
|
+
{p.answer.error}
|
|
144
|
+
{p.onRegenerate && (
|
|
145
|
+
<>
|
|
146
|
+
{' '}
|
|
147
|
+
<Button emphasis="link" tone="neutral" onClick={p.onRegenerate}>
|
|
148
|
+
Retry
|
|
149
|
+
</Button>
|
|
150
|
+
</>
|
|
151
|
+
)}
|
|
152
|
+
</Alert>
|
|
153
|
+
)}
|
|
154
|
+
{many.value && <Sources items={p.answer.sources} base={base} />}
|
|
155
|
+
</div>
|
|
156
|
+
{!busy.value && (
|
|
157
|
+
<MessageActions
|
|
158
|
+
stopped={st.value === 'stopped'}
|
|
159
|
+
onCopy={(el) => void copyConfirm(el, answerText(untrack(() => p.answer)))}
|
|
160
|
+
onFeedback={p.onFeedback}
|
|
161
|
+
onRegenerate={p.onRegenerate}
|
|
162
|
+
onBranch={p.onBranch}
|
|
163
|
+
branch={p.branch}
|
|
164
|
+
/>
|
|
165
|
+
)}
|
|
166
|
+
</article>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UndoIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { Button } from '../Button'
|
|
3
|
+
import '../styles'
|
|
4
|
+
import '@kerf-js/veneer-core/styles/app/checkpoint.css'
|
|
5
|
+
|
|
6
|
+
/** Checkpoint (07 §1.3): a hairline with a label and Restore. Restoring forks a branch; `onRestore` decides how. */
|
|
7
|
+
export function Checkpoint({ label, onRestore }: { label: unknown; onRestore?: () => void }) {
|
|
8
|
+
return (
|
|
9
|
+
<div data-scope="checkpoint">
|
|
10
|
+
<span>{label}</span>
|
|
11
|
+
{onRestore && (
|
|
12
|
+
<Button emphasis="ghost" tone="neutral" size="sm" onClick={onRestore}>
|
|
13
|
+
<UndoIcon />
|
|
14
|
+
Restore
|
|
15
|
+
</Button>
|
|
16
|
+
)}
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { citePreview, installSweep, type AgentSource } from '@kerf-js/veneer-core'
|
|
2
|
+
import { state } from '@kerf-js/core'
|
|
3
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
4
|
+
import '../styles'
|
|
5
|
+
import '@kerf-js/veneer-core/styles/components/popover.css'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/app/cite.css'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A citation (07 §1.3, §1.6): a link to source n named "Source n", with a preview on hover and focus. The preview sits
|
|
10
|
+
* next in the DOM, so Tab reaches its link. Pressing moves focus to the source card and confirms it.
|
|
11
|
+
*/
|
|
12
|
+
export function Cite({
|
|
13
|
+
n,
|
|
14
|
+
source,
|
|
15
|
+
href,
|
|
16
|
+
}: {
|
|
17
|
+
n: number
|
|
18
|
+
source?: AgentSource | undefined
|
|
19
|
+
href: string
|
|
20
|
+
}) {
|
|
21
|
+
const open = state(false)
|
|
22
|
+
let link: HTMLAnchorElement | undefined
|
|
23
|
+
let panel: HTMLElement | undefined
|
|
24
|
+
use(
|
|
25
|
+
citePreview,
|
|
26
|
+
() => (source ? link : undefined),
|
|
27
|
+
() => ({ panel: panel!, onOpen: (o: boolean) => (open.value = o) }),
|
|
28
|
+
)
|
|
29
|
+
const jump = (e: MouseEvent) => {
|
|
30
|
+
const a = e.currentTarget as Element
|
|
31
|
+
const doc = a.ownerDocument
|
|
32
|
+
const card = doc.getElementById(a.getAttribute('href')!.slice(1)) // the page's id: a hydrated server id isn't this side's
|
|
33
|
+
if (!card) return
|
|
34
|
+
e.preventDefault()
|
|
35
|
+
card.focus()
|
|
36
|
+
installSweep(doc).confirm(card)
|
|
37
|
+
}
|
|
38
|
+
return (
|
|
39
|
+
<span style="display:contents">
|
|
40
|
+
<a
|
|
41
|
+
ref={(el) => (link = el)}
|
|
42
|
+
href={href}
|
|
43
|
+
data-scope="cite"
|
|
44
|
+
aria-label={`Source ${n}`}
|
|
45
|
+
aria-expanded={source ? (open.value ? 'true' : 'false') : undefined}
|
|
46
|
+
onClick={jump}
|
|
47
|
+
>
|
|
48
|
+
{n}
|
|
49
|
+
</a>
|
|
50
|
+
{source && (
|
|
51
|
+
<span ref={(el) => (panel = el)} data-scope="popover" data-part="content" popover="manual">
|
|
52
|
+
<span data-part="title" style="display:block">
|
|
53
|
+
{source.title}
|
|
54
|
+
</span>
|
|
55
|
+
{source.path !== undefined && (
|
|
56
|
+
<span data-part="description" style="display:block">
|
|
57
|
+
{source.path}
|
|
58
|
+
</span>
|
|
59
|
+
)}
|
|
60
|
+
{source.snippet !== undefined && <span>{source.snippet}</span>}
|
|
61
|
+
{source.url !== undefined && (
|
|
62
|
+
<a href={source.url} data-part="open">
|
|
63
|
+
Open source
|
|
64
|
+
</a>
|
|
65
|
+
)}
|
|
66
|
+
</span>
|
|
67
|
+
)}
|
|
68
|
+
</span>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { contextLevel, formatTokens } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived } from '@kerf-js/core'
|
|
3
|
+
import { Button } from '../Button'
|
|
4
|
+
import { Tooltip } from '../Tooltip'
|
|
5
|
+
import '../styles'
|
|
6
|
+
import '@kerf-js/veneer-core/styles/app/context-meter.css'
|
|
7
|
+
|
|
8
|
+
/** How full the context window is, and optionally what with. */
|
|
9
|
+
export type ContextUse = {
|
|
10
|
+
used: number
|
|
11
|
+
limit: number
|
|
12
|
+
parts?: { label: string; tokens: number }[] | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ContextMeter (07 §1.2): a ring and a number, caution at 80%, critical at 95%, where `onCompact` offers /compact. The
|
|
17
|
+
* tooltip lists what fills it. `showTokens` adds the count beside the percent.
|
|
18
|
+
*/
|
|
19
|
+
export function ContextMeter({
|
|
20
|
+
used,
|
|
21
|
+
limit,
|
|
22
|
+
parts,
|
|
23
|
+
showTokens,
|
|
24
|
+
onCompact,
|
|
25
|
+
}: ContextUse & { showTokens?: boolean; onCompact?: (() => void) | undefined }) {
|
|
26
|
+
const ratio = derived(() => Math.min(1, limit > 0 ? used / limit : 0))
|
|
27
|
+
const level = derived(() => contextLevel(ratio.value))
|
|
28
|
+
const pct = derived(() => Math.round(ratio.value * 100))
|
|
29
|
+
const tip = derived(() =>
|
|
30
|
+
[
|
|
31
|
+
`${formatTokens(used)} of ${formatTokens(limit)} tokens`,
|
|
32
|
+
...(parts ?? []).map((p) => `${p.label} ${formatTokens(p.tokens)}`),
|
|
33
|
+
].join(' · '),
|
|
34
|
+
)
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<Tooltip content={tip.value}>
|
|
38
|
+
<span
|
|
39
|
+
data-scope="context-meter"
|
|
40
|
+
data-level={level.value}
|
|
41
|
+
role="meter"
|
|
42
|
+
tabindex="0"
|
|
43
|
+
aria-label="Context used"
|
|
44
|
+
aria-valuemin="0"
|
|
45
|
+
aria-valuemax="100"
|
|
46
|
+
aria-valuenow={pct.value}
|
|
47
|
+
aria-valuetext={`${pct.value}%, ${formatTokens(used)} of ${formatTokens(limit)} tokens`}
|
|
48
|
+
style={`--_v:${ratio.value}`}
|
|
49
|
+
>
|
|
50
|
+
<svg viewBox="0 0 36 36" aria-hidden="true">
|
|
51
|
+
<circle
|
|
52
|
+
cx="18"
|
|
53
|
+
cy="18"
|
|
54
|
+
r="15.9"
|
|
55
|
+
stroke="var(--veneer-color-surface-active)"
|
|
56
|
+
pathLength="100"
|
|
57
|
+
/>
|
|
58
|
+
<circle cx="18" cy="18" r="15.9" pathLength="100" />
|
|
59
|
+
</svg>
|
|
60
|
+
<span>{showTokens ? `${pct.value}% · ${formatTokens(used)}` : `${pct.value}%`}</span>
|
|
61
|
+
</span>
|
|
62
|
+
</Tooltip>
|
|
63
|
+
{level.value && onCompact && (
|
|
64
|
+
<Button emphasis="link" tone="neutral" size="sm" onClick={onCompact}>
|
|
65
|
+
/compact
|
|
66
|
+
</Button>
|
|
67
|
+
)}
|
|
68
|
+
</>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { DownIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { stick } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, state } from '@kerf-js/core'
|
|
4
|
+
import { Button } from '../Button'
|
|
5
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
6
|
+
import '../styles'
|
|
7
|
+
import '@kerf-js/veneer-core/styles/app/tokens.css'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/app/base.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/app/thread.css'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Conversation (07 §1.1, §1.3, §1.6): role=log with aria-live off (a turn announces its own end), keyed turns as
|
|
13
|
+
* `children`, an optional app bar and the Prompt below. It sticks to the bottom only within 48px of it; otherwise Jump
|
|
14
|
+
* to latest appears, and pressing it goes back to the end and focuses the log.
|
|
15
|
+
*/
|
|
16
|
+
export function Conversation({
|
|
17
|
+
label = 'Assistant conversation',
|
|
18
|
+
title,
|
|
19
|
+
bar,
|
|
20
|
+
prompt,
|
|
21
|
+
children,
|
|
22
|
+
}: {
|
|
23
|
+
label?: string | undefined
|
|
24
|
+
title?: unknown
|
|
25
|
+
bar?: unknown
|
|
26
|
+
prompt?: unknown
|
|
27
|
+
children?: unknown
|
|
28
|
+
}) {
|
|
29
|
+
const away = state(false)
|
|
30
|
+
const head = derived(() => title !== undefined || bar !== undefined)
|
|
31
|
+
let log: HTMLElement | undefined
|
|
32
|
+
use(
|
|
33
|
+
stick,
|
|
34
|
+
() => log,
|
|
35
|
+
() => ({ onAway: (a: boolean) => (away.value = a) }),
|
|
36
|
+
)
|
|
37
|
+
const jump = () => {
|
|
38
|
+
log!.scrollTop = log!.scrollHeight
|
|
39
|
+
log!.focus({ preventScroll: true })
|
|
40
|
+
away.value = false
|
|
41
|
+
}
|
|
42
|
+
return (
|
|
43
|
+
<section data-scope="thread" data-part="root" aria-label={label}>
|
|
44
|
+
{head.value && (
|
|
45
|
+
<div data-part="app-bar">
|
|
46
|
+
<h2 data-part="app-title">{title}</h2>
|
|
47
|
+
<span data-part="spacer"></span>
|
|
48
|
+
{bar}
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
<div
|
|
52
|
+
ref={(n) => (log = n)}
|
|
53
|
+
data-part="log"
|
|
54
|
+
role="log"
|
|
55
|
+
aria-live="off"
|
|
56
|
+
aria-label="Messages"
|
|
57
|
+
tabindex="0"
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</div>
|
|
61
|
+
{away.value && (
|
|
62
|
+
<Button emphasis="soft" tone="neutral" size="sm" data-part="jump" onClick={jump}>
|
|
63
|
+
<DownIcon />
|
|
64
|
+
Jump to latest
|
|
65
|
+
</Button>
|
|
66
|
+
)}
|
|
67
|
+
<div style="grid-row:3">{prompt}</div>
|
|
68
|
+
</section>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CopyIcon, EditIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { copyConfirm, installSweep } from '@kerf-js/veneer-core'
|
|
3
|
+
import { onMount, state, untrack } from '@kerf-js/core'
|
|
4
|
+
import { Button } from '../Button'
|
|
5
|
+
import { Textarea } from '../Field'
|
|
6
|
+
import { IconButton, Sweep } from './bits'
|
|
7
|
+
import '../styles'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/app/message.css'
|
|
9
|
+
|
|
10
|
+
type MessageProps = {
|
|
11
|
+
text: string
|
|
12
|
+
arrive?: boolean
|
|
13
|
+
onEdit?: ((text: string) => void) | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The user's turn (07 §1.1): a prompt bubble with edit and copy. `arrive` is a message just sent: it enters and
|
|
18
|
+
* confirms one sweep. Edit opens the bubble as a Textarea in place; saving is `onEdit` (a new branch).
|
|
19
|
+
*/
|
|
20
|
+
export function Message({ text, arrive, onEdit }: MessageProps) {
|
|
21
|
+
const editing = state(false)
|
|
22
|
+
const draft = state('')
|
|
23
|
+
let bubble: HTMLElement | undefined
|
|
24
|
+
let root: HTMLElement | undefined
|
|
25
|
+
onMount(() => {
|
|
26
|
+
const s = installSweep()
|
|
27
|
+
if (untrack(() => arrive)) requestAnimationFrame(() => s.confirm(bubble))
|
|
28
|
+
})
|
|
29
|
+
const open = () => {
|
|
30
|
+
draft.value = text
|
|
31
|
+
editing.value = true
|
|
32
|
+
queueMicrotask(() => root?.querySelector('textarea')?.focus())
|
|
33
|
+
}
|
|
34
|
+
const close = () => {
|
|
35
|
+
editing.value = false
|
|
36
|
+
queueMicrotask(() => root?.querySelector<HTMLElement>('[aria-label="Edit message"]')?.focus())
|
|
37
|
+
}
|
|
38
|
+
const save = () => {
|
|
39
|
+
const t = draft.value.trim()
|
|
40
|
+
close()
|
|
41
|
+
if (t && t !== text) onEdit?.(t)
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
ref={(n) => (root = n)}
|
|
46
|
+
data-scope="message"
|
|
47
|
+
data-mine=""
|
|
48
|
+
data-arrive={arrive ? '' : undefined}
|
|
49
|
+
>
|
|
50
|
+
<div data-part="body">
|
|
51
|
+
{editing.value ? (
|
|
52
|
+
<>
|
|
53
|
+
<Textarea
|
|
54
|
+
label="Edit message"
|
|
55
|
+
value={draft.value}
|
|
56
|
+
onInput={(e) => (draft.value = e.currentTarget.value)}
|
|
57
|
+
onKeyDown={(e: KeyboardEvent) => {
|
|
58
|
+
if (e.key === 'Escape') {
|
|
59
|
+
e.preventDefault()
|
|
60
|
+
close()
|
|
61
|
+
}
|
|
62
|
+
}}
|
|
63
|
+
/>
|
|
64
|
+
<div data-part="status">
|
|
65
|
+
<Button size="sm" onClick={save}>
|
|
66
|
+
Save
|
|
67
|
+
</Button>
|
|
68
|
+
<Button emphasis="ghost" tone="neutral" size="sm" onClick={close}>
|
|
69
|
+
Cancel
|
|
70
|
+
</Button>
|
|
71
|
+
</div>
|
|
72
|
+
</>
|
|
73
|
+
) : (
|
|
74
|
+
<>
|
|
75
|
+
<div ref={(n) => (bubble = n)} data-part="bubble" data-variant="prompt" data-sweep="">
|
|
76
|
+
<Sweep />
|
|
77
|
+
{text}
|
|
78
|
+
</div>
|
|
79
|
+
<div data-part="status" style="gap:2px">
|
|
80
|
+
{onEdit && <IconButton icon={EditIcon} label="Edit message" onClick={open} />}
|
|
81
|
+
<IconButton
|
|
82
|
+
icon={CopyIcon}
|
|
83
|
+
label="Copy"
|
|
84
|
+
onClick={(e: Event) => copyConfirm(e.currentTarget as Element, text, bubble)}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</>
|
|
88
|
+
)}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { DownIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import { announce, nextIndex, popover, uid } from '@kerf-js/veneer-core'
|
|
3
|
+
import { derived, state, type State } from '@kerf-js/core'
|
|
4
|
+
import { Badge } from '../Badge'
|
|
5
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
6
|
+
import { held } from './bits'
|
|
7
|
+
import '../styles'
|
|
8
|
+
import '@kerf-js/veneer-core/styles/components/popover.css'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/app/prompt.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/app/suggest.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/app/model-menu.css'
|
|
12
|
+
|
|
13
|
+
/** A model on offer. */
|
|
14
|
+
export type ModelOption = {
|
|
15
|
+
id: string
|
|
16
|
+
name: string
|
|
17
|
+
short?: string
|
|
18
|
+
provider?: string | undefined
|
|
19
|
+
description?: string | undefined
|
|
20
|
+
capabilities?: string[]
|
|
21
|
+
context?: string
|
|
22
|
+
cost?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type ModelPickerProps = {
|
|
26
|
+
models: ModelOption[]
|
|
27
|
+
value?: string | State<string | undefined> | undefined
|
|
28
|
+
onChange?: ((id: string) => void) | undefined
|
|
29
|
+
compact?: boolean | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ModelPicker (07 §1.3): the model chip opens a Popover holding a listbox grouped by provider. Each option shows its
|
|
34
|
+
* capabilities, context size and relative cost; the current one is checked. ↑/↓, Home/End move, Enter picks, Escape
|
|
35
|
+
* closes; focus goes back to the chip. `compact` shows the short name.
|
|
36
|
+
*/
|
|
37
|
+
export function ModelPicker({ models, value, onChange, compact }: ModelPickerProps) {
|
|
38
|
+
const id = uid('model')
|
|
39
|
+
const open = state(false)
|
|
40
|
+
const picked = held<string | undefined>(
|
|
41
|
+
() => value,
|
|
42
|
+
undefined,
|
|
43
|
+
() => (v: string | undefined) => onChange?.(v!),
|
|
44
|
+
)
|
|
45
|
+
const current = derived(() => models.find((m) => m.id === picked.value) ?? models[0])
|
|
46
|
+
const groups = modelGroups(() => models)
|
|
47
|
+
let chip: HTMLButtonElement | undefined
|
|
48
|
+
let panel: HTMLElement | undefined
|
|
49
|
+
useModelPopover(
|
|
50
|
+
() => panel,
|
|
51
|
+
() => chip,
|
|
52
|
+
open,
|
|
53
|
+
)
|
|
54
|
+
const choose = (m: ModelOption) => chooseModel({ m, picked, open, panel: () => panel })
|
|
55
|
+
const onKey = (e: KeyboardEvent) => modelKey(e, panel!)
|
|
56
|
+
return (
|
|
57
|
+
<span data-scope="prompt" style="display:contents">
|
|
58
|
+
<button
|
|
59
|
+
ref={(n) => (chip = n)}
|
|
60
|
+
type="button"
|
|
61
|
+
data-part="model"
|
|
62
|
+
aria-haspopup="listbox"
|
|
63
|
+
aria-expanded={open.value ? 'true' : 'false'}
|
|
64
|
+
aria-controls={id}
|
|
65
|
+
onClick={() => (open.value = !open.value)}
|
|
66
|
+
>
|
|
67
|
+
<i></i>
|
|
68
|
+
<span data-part="sr-only">Model: </span>
|
|
69
|
+
<span>{compact ? (current.value?.short ?? current.value?.name) : current.value?.name}</span>
|
|
70
|
+
<DownIcon />
|
|
71
|
+
</button>
|
|
72
|
+
<div
|
|
73
|
+
ref={(n) => (panel = n)}
|
|
74
|
+
id={id}
|
|
75
|
+
data-scope="popover"
|
|
76
|
+
data-part="content"
|
|
77
|
+
popover="manual"
|
|
78
|
+
style="padding:4px;min-inline-size:280px"
|
|
79
|
+
>
|
|
80
|
+
<div data-scope="model-menu" role="listbox" aria-label="Model" onKeyDown={onKey}>
|
|
81
|
+
{groups.value.map((g) => (
|
|
82
|
+
<div key={g.name} role="group" aria-label={g.name || 'Models'}>
|
|
83
|
+
<div data-scope="suggest" style="all:unset">
|
|
84
|
+
<div data-part="group" aria-hidden="true">
|
|
85
|
+
{g.name || 'Models'}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
{g.models.map((m) => (
|
|
89
|
+
<div
|
|
90
|
+
key={m.id}
|
|
91
|
+
role="option"
|
|
92
|
+
tabindex="-1"
|
|
93
|
+
aria-selected={m.id === current.value?.id ? 'true' : 'false'}
|
|
94
|
+
data-initial={m.id === current.value?.id ? '' : undefined}
|
|
95
|
+
onClick={() => choose(m)}
|
|
96
|
+
>
|
|
97
|
+
<b>{m.name}</b>
|
|
98
|
+
<small>
|
|
99
|
+
{m.description}{' '}
|
|
100
|
+
{(m.capabilities ?? []).map((c) => (
|
|
101
|
+
<Badge key={c} tone="neutral">
|
|
102
|
+
{c}
|
|
103
|
+
</Badge>
|
|
104
|
+
))}
|
|
105
|
+
</small>
|
|
106
|
+
<code>{[m.context, m.cost].filter(Boolean).join(' · ')}</code>
|
|
107
|
+
</div>
|
|
108
|
+
))}
|
|
109
|
+
</div>
|
|
110
|
+
))}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</span>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function modelGroups(models: () => ModelOption[]) {
|
|
118
|
+
return derived(() =>
|
|
119
|
+
[...new Set(models().map((m) => m.provider ?? ''))].map((name) => ({
|
|
120
|
+
name,
|
|
121
|
+
models: models().filter((m) => (m.provider ?? '') === name),
|
|
122
|
+
})),
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function modelKey(e: KeyboardEvent, panel: HTMLElement) {
|
|
127
|
+
const list = [...panel.querySelectorAll<HTMLElement>('[role="option"]')]
|
|
128
|
+
const at = list.indexOf(e.target as HTMLElement)
|
|
129
|
+
const to = nextIndex(e.key, at, list.length, { orientation: 'vertical' })
|
|
130
|
+
if (to >= 0) {
|
|
131
|
+
e.preventDefault()
|
|
132
|
+
list[to]!.focus()
|
|
133
|
+
} else if (e.key === 'Enter' || e.key === ' ') {
|
|
134
|
+
e.preventDefault()
|
|
135
|
+
list[at]?.click()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function useModelPopover(
|
|
140
|
+
panel: () => HTMLElement | undefined,
|
|
141
|
+
chip: () => HTMLButtonElement | undefined,
|
|
142
|
+
open: State<boolean>,
|
|
143
|
+
) {
|
|
144
|
+
use(popover, panel, () => ({
|
|
145
|
+
open: open.value,
|
|
146
|
+
trigger: chip()!,
|
|
147
|
+
side: 'top' as const,
|
|
148
|
+
align: 'end' as const,
|
|
149
|
+
onClose: () => (open.value = false),
|
|
150
|
+
}))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function chooseModel({
|
|
154
|
+
m,
|
|
155
|
+
picked,
|
|
156
|
+
open,
|
|
157
|
+
panel,
|
|
158
|
+
}: {
|
|
159
|
+
m: ModelOption
|
|
160
|
+
picked: { set: (value: string | undefined) => void }
|
|
161
|
+
open: State<boolean>
|
|
162
|
+
panel: () => HTMLElement | undefined
|
|
163
|
+
}) {
|
|
164
|
+
picked.set(m.id)
|
|
165
|
+
open.value = false
|
|
166
|
+
announce(panel()!.ownerDocument, `Model: ${m.name}`)
|
|
167
|
+
}
|