@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,118 @@
|
|
|
1
|
+
import { announce, applySuggest, suggestQuery } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, state } from '@kerf-js/core'
|
|
3
|
+
import { held } from './bits'
|
|
4
|
+
import type { PromptProps, PromptSuggestion, PromptTool } from './Prompt'
|
|
5
|
+
|
|
6
|
+
export function promptState(p: PromptProps, id: string) {
|
|
7
|
+
const draft = held<string>(
|
|
8
|
+
() => p.value,
|
|
9
|
+
'',
|
|
10
|
+
() => p.onValueChange,
|
|
11
|
+
)
|
|
12
|
+
const toolset = derived(() => p.tools ?? ['attach', 'slash', 'mic', 'web'])
|
|
13
|
+
const shown = (t: PromptTool) => toolset.value.includes(t)
|
|
14
|
+
const open = state<ReturnType<typeof suggestQuery>>(null)
|
|
15
|
+
const active = state(0)
|
|
16
|
+
const drag = state(false)
|
|
17
|
+
const options = derived(() => {
|
|
18
|
+
const q = open.value
|
|
19
|
+
if (!q) return []
|
|
20
|
+
const list = (q.trigger === '/' ? p.commands : p.mentions) ?? []
|
|
21
|
+
return list.filter((o) => o.value.slice(1).toLowerCase().startsWith(q.query))
|
|
22
|
+
})
|
|
23
|
+
const listed = derived(() => options.value.length > 0)
|
|
24
|
+
const oid = (o: PromptSuggestion) => `${id}-o-${o.value.slice(1)}`
|
|
25
|
+
const current = derived(() => options.value[Math.min(active.value, options.value.length - 1)])
|
|
26
|
+
const activeId = derived(() => (current.value ? oid(current.value) : undefined))
|
|
27
|
+
const hasFiles = derived(() => p.attachments !== undefined || !!p.files?.length)
|
|
28
|
+
return { draft, shown, open, active, drag, options, listed, oid, current, activeId, hasFiles }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type PromptState = ReturnType<typeof promptState>
|
|
32
|
+
type Context = PromptState & { p: PromptProps; getBox: () => HTMLTextAreaElement | undefined }
|
|
33
|
+
|
|
34
|
+
export function suggestActions({ open, active, draft, getBox }: Context) {
|
|
35
|
+
const look = () => {
|
|
36
|
+
open.value = suggestQuery(getBox()!.value, getBox()!.selectionStart)
|
|
37
|
+
active.value = 0
|
|
38
|
+
}
|
|
39
|
+
const pick = (value: string) => {
|
|
40
|
+
const q = open.value!
|
|
41
|
+
const next = applySuggest(getBox()!.value, q.start, getBox()!.selectionStart, value)
|
|
42
|
+
draft.set(next.text)
|
|
43
|
+
open.value = null
|
|
44
|
+
getBox()!.value = next.text
|
|
45
|
+
getBox()!.focus()
|
|
46
|
+
getBox()!.setSelectionRange(next.caret, next.caret)
|
|
47
|
+
}
|
|
48
|
+
return { look, pick }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function sendActions({ p, draft, open, getBox }: Context) {
|
|
52
|
+
const send = () => {
|
|
53
|
+
const text = draft.value.trim()
|
|
54
|
+
if (!text) return
|
|
55
|
+
if (p.busy) {
|
|
56
|
+
if (!p.onQueue) return
|
|
57
|
+
p.onQueue(text)
|
|
58
|
+
announce(getBox()!.ownerDocument, 'Queued. It will run after the current step.')
|
|
59
|
+
} else if (p.blocked) return
|
|
60
|
+
else p.onSubmit?.(text)
|
|
61
|
+
draft.set('')
|
|
62
|
+
open.value = null
|
|
63
|
+
}
|
|
64
|
+
const sendOrStop = () => (p.busy ? p.onStop?.() : send())
|
|
65
|
+
return { send, sendOrStop }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function keyAction(
|
|
69
|
+
{ p, listed, options, open, active, current }: Context,
|
|
70
|
+
pick: ReturnType<typeof suggestActions>['pick'],
|
|
71
|
+
send: ReturnType<typeof sendActions>['send'],
|
|
72
|
+
) {
|
|
73
|
+
const onKey = (e: KeyboardEvent) => {
|
|
74
|
+
if (listed.value) {
|
|
75
|
+
const n = options.value.length
|
|
76
|
+
if (e.key === 'Escape') {
|
|
77
|
+
e.preventDefault()
|
|
78
|
+
open.value = null
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
82
|
+
e.preventDefault()
|
|
83
|
+
active.value = (active.value + (e.key === 'ArrowDown' ? 1 : n - 1)) % n
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
if (e.key === 'Enter' || e.key === 'Tab') {
|
|
87
|
+
e.preventDefault()
|
|
88
|
+
pick(current.value!.value)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
|
|
93
|
+
e.preventDefault()
|
|
94
|
+
send()
|
|
95
|
+
} else if (e.key === 'Escape' && p.busy) {
|
|
96
|
+
e.preventDefault()
|
|
97
|
+
p.onStop?.()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return onKey
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function fileActions({ p, drag }: Context) {
|
|
104
|
+
const add = (list: FileList | null | undefined) => {
|
|
105
|
+
const f = [...(list ?? [])]
|
|
106
|
+
if (f.length) p.onAttach?.(f)
|
|
107
|
+
}
|
|
108
|
+
const onDrop = (e: DragEvent) => {
|
|
109
|
+
e.preventDefault()
|
|
110
|
+
drag.value = false
|
|
111
|
+
add(e.dataTransfer?.files)
|
|
112
|
+
}
|
|
113
|
+
const over = (e: DragEvent) => {
|
|
114
|
+
e.preventDefault()
|
|
115
|
+
drag.value = true
|
|
116
|
+
}
|
|
117
|
+
return { add, onDrop, over }
|
|
118
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommandIcon,
|
|
3
|
+
FileIcon,
|
|
4
|
+
GlobeIcon,
|
|
5
|
+
MicIcon,
|
|
6
|
+
PaperclipIcon,
|
|
7
|
+
SendIcon,
|
|
8
|
+
StopIcon,
|
|
9
|
+
XIcon,
|
|
10
|
+
} from '@kerf-js/veneer-icons'
|
|
11
|
+
import { Button } from '../Button'
|
|
12
|
+
import { Bar, IconButton, Sweep } from './bits'
|
|
13
|
+
import { ContextMeter } from './ContextMeter'
|
|
14
|
+
import { ModelPicker } from './ModelPicker'
|
|
15
|
+
import type { PromptProps } from './Prompt'
|
|
16
|
+
import type { promptState, suggestActions, sendActions, fileActions } from './Prompt-model'
|
|
17
|
+
|
|
18
|
+
type View = ReturnType<typeof promptState> &
|
|
19
|
+
ReturnType<typeof suggestActions> &
|
|
20
|
+
Pick<ReturnType<typeof sendActions>, 'sendOrStop'> &
|
|
21
|
+
ReturnType<typeof fileActions> & {
|
|
22
|
+
p: PromptProps
|
|
23
|
+
id: string
|
|
24
|
+
onKey: (event: KeyboardEvent) => void
|
|
25
|
+
setHost: (node: HTMLElement) => void
|
|
26
|
+
setBox: (node: HTMLTextAreaElement) => void
|
|
27
|
+
setPicker: (node: HTMLInputElement) => void
|
|
28
|
+
getPicker: () => HTMLInputElement | undefined
|
|
29
|
+
getBox: () => HTMLTextAreaElement | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function promptView(view: View) {
|
|
33
|
+
const { p, id, draft, shown, open, drag, listed, activeId, hasFiles } = view
|
|
34
|
+
const { look, sendOrStop, onKey, onDrop, over } = view
|
|
35
|
+
const { setHost, setBox } = view
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
data-scope="prompt"
|
|
39
|
+
style="position:relative;padding:0 var(--veneer-space-group) var(--veneer-space-group)"
|
|
40
|
+
>
|
|
41
|
+
{p.children}
|
|
42
|
+
<div
|
|
43
|
+
ref={(n) => setHost(n)}
|
|
44
|
+
data-scope="composer"
|
|
45
|
+
data-sweep=""
|
|
46
|
+
data-pin={drag.value ? '' : undefined}
|
|
47
|
+
style="margin:0"
|
|
48
|
+
onDragOver={over}
|
|
49
|
+
onDragLeave={() => (drag.value = false)}
|
|
50
|
+
onDrop={onDrop}
|
|
51
|
+
>
|
|
52
|
+
<Sweep />
|
|
53
|
+
{hasFiles.value && fileChips(view)}
|
|
54
|
+
<label data-part="sr-only" for={`${id}-in`}>
|
|
55
|
+
{p.label ?? 'Message the assistant'}
|
|
56
|
+
</label>
|
|
57
|
+
<textarea
|
|
58
|
+
ref={(n) => setBox(n)}
|
|
59
|
+
id={`${id}-in`}
|
|
60
|
+
rows="1"
|
|
61
|
+
enterkeyhint="send"
|
|
62
|
+
placeholder={p.placeholder ?? 'Ask, or type / for commands'}
|
|
63
|
+
aria-describedby={p.blocked ? `${id}-hint ${id}-why` : `${id}-hint`}
|
|
64
|
+
aria-controls={listed.value ? `${id}-list` : undefined}
|
|
65
|
+
aria-activedescendant={activeId.value}
|
|
66
|
+
value={draft.value}
|
|
67
|
+
onInput={(e) => {
|
|
68
|
+
draft.set(e.currentTarget.value)
|
|
69
|
+
look()
|
|
70
|
+
}}
|
|
71
|
+
onKeyDown={onKey}
|
|
72
|
+
onClick={look}
|
|
73
|
+
onBlur={() => (open.value = null)}
|
|
74
|
+
></textarea>
|
|
75
|
+
{p.blocked && (
|
|
76
|
+
<span data-part="hint" data-state="error" id={`${id}-why`}>
|
|
77
|
+
{p.blocked}
|
|
78
|
+
</span>
|
|
79
|
+
)}
|
|
80
|
+
<div data-part="row">
|
|
81
|
+
{shown('attach') && attachButton(view)}
|
|
82
|
+
{shown('attach') && filePicker(view)}
|
|
83
|
+
{shown('slash') && !!p.commands?.length && commandsButton(view)}
|
|
84
|
+
{shown('mic') && micButton(view)}
|
|
85
|
+
{shown('web') && !p.compact && webButton(view)}
|
|
86
|
+
<span data-part="spacer"></span>
|
|
87
|
+
{p.context && contextView(view)}
|
|
88
|
+
{p.models && modelView(view)}
|
|
89
|
+
<Button
|
|
90
|
+
data-part="send"
|
|
91
|
+
data-icon-only=""
|
|
92
|
+
tone={p.busy ? 'neutral' : undefined}
|
|
93
|
+
label={p.busy ? 'Stop' : 'Send'}
|
|
94
|
+
aria-disabled={p.blocked && !p.busy ? 'true' : undefined}
|
|
95
|
+
onClick={sendOrStop}
|
|
96
|
+
>
|
|
97
|
+
{p.busy ? <StopIcon /> : <SendIcon />}
|
|
98
|
+
</Button>
|
|
99
|
+
</div>
|
|
100
|
+
<span data-part="sr-only" id={`${id}-hint`}>
|
|
101
|
+
Enter sends, Shift+Enter adds a line, Escape stops a running answer.
|
|
102
|
+
</span>
|
|
103
|
+
{listed.value && suggestList(view)}
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function fileChips({ p }: View) {
|
|
110
|
+
return (
|
|
111
|
+
<div data-part="files">
|
|
112
|
+
{p.attachments ??
|
|
113
|
+
(p.files ?? []).map((f) => (
|
|
114
|
+
<span key={f.id} data-part="file">
|
|
115
|
+
<FileIcon />
|
|
116
|
+
<span>{f.name}</span>
|
|
117
|
+
<IconButton
|
|
118
|
+
icon={XIcon}
|
|
119
|
+
label={`Remove ${f.name}`}
|
|
120
|
+
onClick={() => p.onRemoveFile?.(f.id)}
|
|
121
|
+
/>
|
|
122
|
+
{f.progress !== undefined && f.progress < 1 && (
|
|
123
|
+
<Bar label={`Uploading ${f.name}`} value={f.progress} />
|
|
124
|
+
)}
|
|
125
|
+
</span>
|
|
126
|
+
))}
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function attachButton({ getPicker }: View) {
|
|
132
|
+
return (
|
|
133
|
+
<IconButton icon={PaperclipIcon} label="Attach file" onClick={() => getPicker()?.click()} />
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function filePicker({ setPicker, add }: View) {
|
|
138
|
+
return (
|
|
139
|
+
<input
|
|
140
|
+
ref={(n) => setPicker(n)}
|
|
141
|
+
type="file"
|
|
142
|
+
multiple
|
|
143
|
+
hidden
|
|
144
|
+
onChange={(e) => {
|
|
145
|
+
add(e.currentTarget.files)
|
|
146
|
+
e.currentTarget.value = ''
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function commandsButton({ draft, getBox, look }: View) {
|
|
153
|
+
return (
|
|
154
|
+
<IconButton
|
|
155
|
+
icon={CommandIcon}
|
|
156
|
+
label="Commands"
|
|
157
|
+
onClick={() => {
|
|
158
|
+
draft.set('/')
|
|
159
|
+
getBox()!.value = '/'
|
|
160
|
+
getBox()!.focus()
|
|
161
|
+
getBox()!.setSelectionRange(1, 1)
|
|
162
|
+
look()
|
|
163
|
+
}}
|
|
164
|
+
/>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function micButton({ p }: View) {
|
|
169
|
+
return (
|
|
170
|
+
<IconButton
|
|
171
|
+
icon={MicIcon}
|
|
172
|
+
label="Dictate"
|
|
173
|
+
tone={p.mic ? 'critical' : 'neutral'}
|
|
174
|
+
aria-pressed={p.mic ? 'true' : 'false'}
|
|
175
|
+
onClick={p.onMic}
|
|
176
|
+
/>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function webButton({ p }: View) {
|
|
181
|
+
return (
|
|
182
|
+
<Button
|
|
183
|
+
emphasis="ghost"
|
|
184
|
+
tone="neutral"
|
|
185
|
+
size="sm"
|
|
186
|
+
aria-pressed={p.web ? 'true' : 'false'}
|
|
187
|
+
onClick={() => p.onWebChange?.(!p.web)}
|
|
188
|
+
>
|
|
189
|
+
<GlobeIcon />
|
|
190
|
+
<span data-part="label">Web</span>
|
|
191
|
+
</Button>
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function contextView({ p }: View) {
|
|
196
|
+
return (
|
|
197
|
+
<ContextMeter
|
|
198
|
+
used={p.context!.used}
|
|
199
|
+
limit={p.context!.limit}
|
|
200
|
+
parts={p.context!.parts}
|
|
201
|
+
onCompact={p.onCompact}
|
|
202
|
+
/>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function modelView({ p }: View) {
|
|
207
|
+
return (
|
|
208
|
+
<ModelPicker
|
|
209
|
+
models={p.models!}
|
|
210
|
+
value={p.model}
|
|
211
|
+
onChange={p.onModelChange}
|
|
212
|
+
compact={p.compact}
|
|
213
|
+
/>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function suggestList({ id, open, options, oid, current, pick }: View) {
|
|
218
|
+
return (
|
|
219
|
+
<div
|
|
220
|
+
data-scope="suggest"
|
|
221
|
+
role="listbox"
|
|
222
|
+
id={`${id}-list`}
|
|
223
|
+
aria-label={open.value?.trigger === '/' ? 'Commands' : 'Mentions'}
|
|
224
|
+
>
|
|
225
|
+
<div data-part="group" aria-hidden="true">
|
|
226
|
+
{open.value?.trigger === '/' ? 'Commands' : 'Mentions'}
|
|
227
|
+
</div>
|
|
228
|
+
{options.value.map((o) => (
|
|
229
|
+
<div
|
|
230
|
+
key={o.value}
|
|
231
|
+
id={oid(o)}
|
|
232
|
+
role="option"
|
|
233
|
+
aria-selected={o === current.value ? 'true' : 'false'}
|
|
234
|
+
onMouseDown={(e) => {
|
|
235
|
+
e.preventDefault()
|
|
236
|
+
pick(o.value)
|
|
237
|
+
}}
|
|
238
|
+
>
|
|
239
|
+
<span data-part="cmd">{o.value}</span>
|
|
240
|
+
<small>{o.description}</small>
|
|
241
|
+
<kbd>{o === current.value ? '↵' : ''}</kbd>
|
|
242
|
+
</div>
|
|
243
|
+
))}
|
|
244
|
+
</div>
|
|
245
|
+
)
|
|
246
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { announce, autosize, installSweep, uid } from '@kerf-js/veneer-core'
|
|
2
|
+
import { onMount, untrack, type State } from '@kerf-js/core'
|
|
3
|
+
import { use } from '@kerf-js/veneer-core/kerf'
|
|
4
|
+
import { promptState, suggestActions, sendActions, keyAction, fileActions } from './Prompt-model'
|
|
5
|
+
import { promptView } from './Prompt-view'
|
|
6
|
+
import type { ContextUse } from './ContextMeter'
|
|
7
|
+
import type { ModelOption } from './ModelPicker'
|
|
8
|
+
import '../styles'
|
|
9
|
+
import '@kerf-js/veneer-core/styles/app/prompt.css'
|
|
10
|
+
import '@kerf-js/veneer-core/styles/app/composer.css'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/app/suggest.css'
|
|
12
|
+
|
|
13
|
+
/** A tool the composer's row can offer. */
|
|
14
|
+
export type PromptTool = 'attach' | 'slash' | 'mic' | 'web'
|
|
15
|
+
/** A file attached to the prompt. */
|
|
16
|
+
export type PromptFile = { id: string; name: string; progress?: number }
|
|
17
|
+
/** A completion shown under the prompt. */
|
|
18
|
+
export type PromptSuggestion = { value: string; description?: string | undefined }
|
|
19
|
+
/** What the prompt hands out through `control`. */
|
|
20
|
+
export interface PromptControl {
|
|
21
|
+
insert(text: string): void
|
|
22
|
+
focus(): void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Props for Prompt. */
|
|
26
|
+
export interface PromptProps {
|
|
27
|
+
value?: State<string> | string
|
|
28
|
+
/** Called with the draft on every keystroke. */
|
|
29
|
+
onValueChange?: (v: string) => void
|
|
30
|
+
onSubmit?: (text: string) => void
|
|
31
|
+
/** Pressing Stop or Escape while busy. Stop keeps what arrived. */
|
|
32
|
+
onStop?: () => void
|
|
33
|
+
/** A message sent while busy goes to the queue. */
|
|
34
|
+
onQueue?: (text: string) => void
|
|
35
|
+
busy?: boolean | undefined
|
|
36
|
+
/** Why Send is off ("You're offline"): the button stays focusable and says why. */
|
|
37
|
+
blocked?: string
|
|
38
|
+
label?: string | undefined
|
|
39
|
+
placeholder?: string
|
|
40
|
+
tools?: PromptTool[]
|
|
41
|
+
/** The picked model's id: a state, or a plain value with `onModelChange`. */
|
|
42
|
+
model?: State<string> | string
|
|
43
|
+
models?: ModelOption[]
|
|
44
|
+
/** Called with the id of the model picked. */
|
|
45
|
+
onModelChange?: (id: string) => void
|
|
46
|
+
context?: ContextUse
|
|
47
|
+
/** Called from the context meter's Compact: summarise the conversation to free room. */
|
|
48
|
+
onCompact?: () => void
|
|
49
|
+
/** Attached files shown as chips above the input, with upload progress. */
|
|
50
|
+
files?: PromptFile[]
|
|
51
|
+
/** Your own attachment row, in place of `files`. */
|
|
52
|
+
attachments?: unknown
|
|
53
|
+
/** Called with the files picked or dropped. */
|
|
54
|
+
onAttach?: (files: File[]) => void
|
|
55
|
+
/** Called with a file's id when its chip is removed. */
|
|
56
|
+
onRemoveFile?: (id: string) => void
|
|
57
|
+
/** What `/` offers: one suggestion each, with a description. */
|
|
58
|
+
commands?: PromptSuggestion[]
|
|
59
|
+
/** What `@` offers: one suggestion each, with a description. */
|
|
60
|
+
mentions?: PromptSuggestion[]
|
|
61
|
+
/** Whether the Web toggle is on. */
|
|
62
|
+
web?: boolean
|
|
63
|
+
/** Called with the Web toggle's new state. */
|
|
64
|
+
onWebChange?: (on: boolean) => void
|
|
65
|
+
/** Whether dictation is on: the mic button turns critical. */
|
|
66
|
+
mic?: boolean
|
|
67
|
+
/** Called when the mic button is pressed. */
|
|
68
|
+
onMic?: () => void
|
|
69
|
+
/** Phone: fewer tools, the model's short name. */
|
|
70
|
+
compact?: boolean | undefined
|
|
71
|
+
/** Hands over insert() and focus(), for SpeechInput's Insert. */
|
|
72
|
+
control?: ((c: PromptControl) => void) | undefined
|
|
73
|
+
/** Above the composer: Suggestions. */
|
|
74
|
+
children?: unknown
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Prompt (07 §1.1, §1.6): one composer in the field's sweep. It grows to 8 lines; Enter sends, Shift+Enter adds a line,
|
|
79
|
+
* Escape stops. Send and Stop are one button, so focus never drops. `/` and `@` open a suggest listbox on the textarea
|
|
80
|
+
* (aria-activedescendant); files come by button or drop, the drag holding the sweep. Busy sends go to `onQueue`.
|
|
81
|
+
*/
|
|
82
|
+
export function Prompt(p: PromptProps) {
|
|
83
|
+
const id = uid('prompt')
|
|
84
|
+
const model = promptState(
|
|
85
|
+
untrack(() => p),
|
|
86
|
+
id,
|
|
87
|
+
)
|
|
88
|
+
const { draft } = model
|
|
89
|
+
let box: HTMLTextAreaElement | undefined
|
|
90
|
+
let host: HTMLElement | undefined
|
|
91
|
+
let picker: HTMLInputElement | undefined
|
|
92
|
+
use(
|
|
93
|
+
autosize,
|
|
94
|
+
() => box,
|
|
95
|
+
() => draft.value,
|
|
96
|
+
)
|
|
97
|
+
onMount(() => {
|
|
98
|
+
p.control?.({
|
|
99
|
+
insert(text) {
|
|
100
|
+
draft.set(draft.value ? `${draft.value} ${text}` : text)
|
|
101
|
+
box!.focus({ preventScroll: true })
|
|
102
|
+
installSweep().confirm(host)
|
|
103
|
+
announce(box!.ownerDocument, 'Inserted into the message box.')
|
|
104
|
+
},
|
|
105
|
+
focus: () => box!.focus(),
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
const context = { ...model, p: untrack(() => p), getBox: () => box }
|
|
109
|
+
const { look, pick } = suggestActions(context)
|
|
110
|
+
const { send, sendOrStop } = sendActions(context)
|
|
111
|
+
const onKey = keyAction(context, pick, send)
|
|
112
|
+
const { add, onDrop, over } = fileActions(context)
|
|
113
|
+
return promptView({
|
|
114
|
+
...context,
|
|
115
|
+
look,
|
|
116
|
+
pick,
|
|
117
|
+
sendOrStop,
|
|
118
|
+
onKey,
|
|
119
|
+
add,
|
|
120
|
+
onDrop,
|
|
121
|
+
over,
|
|
122
|
+
id,
|
|
123
|
+
setHost: (n) => (host = n),
|
|
124
|
+
setBox: (n) => (box = n),
|
|
125
|
+
setPicker: (n) => (picker = n),
|
|
126
|
+
getPicker: () => picker,
|
|
127
|
+
})
|
|
128
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseInline,
|
|
3
|
+
parseText,
|
|
4
|
+
type AgentSource,
|
|
5
|
+
type Inline,
|
|
6
|
+
type TextBlock,
|
|
7
|
+
} from '@kerf-js/veneer-core'
|
|
8
|
+
import { derived, untrack } from '@kerf-js/core'
|
|
9
|
+
import { Cite } from './Cite'
|
|
10
|
+
import '../styles'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/app/assistant.css'
|
|
12
|
+
|
|
13
|
+
function Cited({ n, sources, base }: { n: number; sources: AgentSource[]; base: string }) {
|
|
14
|
+
const source = derived(() => sources[n - 1])
|
|
15
|
+
return <Cite n={n} source={source.value} href={`#${base}-s${n}`} />
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Mark = Extract<Inline, { kind: 'cite' }>
|
|
19
|
+
type Run = Exclude<Inline, Mark>
|
|
20
|
+
type Para = Extract<TextBlock, { kind: 'p' }>
|
|
21
|
+
type List = Extract<TextBlock, { kind: 'ul' }>
|
|
22
|
+
type Fence = Extract<TextBlock, { kind: 'code' }>
|
|
23
|
+
|
|
24
|
+
function Span({ part, sources, base }: { part: Inline; sources: AgentSource[]; base: string }) {
|
|
25
|
+
const kind = derived(() => part.kind)
|
|
26
|
+
const view = derived(() => {
|
|
27
|
+
const k = kind.value
|
|
28
|
+
return untrack(() =>
|
|
29
|
+
k === 'cite' ? (
|
|
30
|
+
<Cited n={(part as Mark).n} sources={sources} base={base} />
|
|
31
|
+
) : k === 'code' ? (
|
|
32
|
+
<code>{(part as Run).text}</code>
|
|
33
|
+
) : (
|
|
34
|
+
<span>{(part as Run).text}</span>
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
return <>{view.value}</>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function Spans({ text, sources, base }: { text: string; sources: AgentSource[]; base: string }) {
|
|
42
|
+
const parts = derived<Inline[]>(() => parseInline(text))
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
{parts.value.map((p) => (
|
|
46
|
+
<Span key={p.at} part={p} sources={sources} base={base} />
|
|
47
|
+
))}
|
|
48
|
+
</>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Block({
|
|
53
|
+
block,
|
|
54
|
+
sources,
|
|
55
|
+
base,
|
|
56
|
+
}: {
|
|
57
|
+
block: TextBlock
|
|
58
|
+
sources: AgentSource[]
|
|
59
|
+
base: string
|
|
60
|
+
}) {
|
|
61
|
+
const kind = derived(() => block.kind)
|
|
62
|
+
// a block that changes kind (a paragraph becoming a list) rebuilds; one that only grows is patched
|
|
63
|
+
const view = derived(() => {
|
|
64
|
+
const k = kind.value
|
|
65
|
+
return untrack(() => {
|
|
66
|
+
if (k === 'p')
|
|
67
|
+
return (
|
|
68
|
+
<p>
|
|
69
|
+
<Spans text={(block as Para).text} sources={sources} base={base} />
|
|
70
|
+
</p>
|
|
71
|
+
)
|
|
72
|
+
if (k === 'ul')
|
|
73
|
+
return (
|
|
74
|
+
<ul>
|
|
75
|
+
{(block as List).items.map((i) => (
|
|
76
|
+
<li key={i.at}>
|
|
77
|
+
<Spans text={i.text} sources={sources} base={base} />
|
|
78
|
+
</li>
|
|
79
|
+
))}
|
|
80
|
+
</ul>
|
|
81
|
+
)
|
|
82
|
+
return (
|
|
83
|
+
<pre
|
|
84
|
+
role="group"
|
|
85
|
+
tabindex="0"
|
|
86
|
+
aria-label={(block as Fence).lang ? `Code, ${(block as Fence).lang}` : 'Code'}
|
|
87
|
+
>
|
|
88
|
+
<code>{(block as Fence).text}</code>
|
|
89
|
+
</pre>
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
return <>{view.value}</>
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Answer text, the safe default until Veneer has Markdown: paragraphs, `- ` lists, code fences (open ones already render
|
|
98
|
+
* as code), inline code and `[n]` cites. Text only: nothing in the model's output becomes markup. Blocks are keyed by
|
|
99
|
+
* where they start, so streaming patches the last one in place.
|
|
100
|
+
*/
|
|
101
|
+
export function Prose({
|
|
102
|
+
text,
|
|
103
|
+
sources = [],
|
|
104
|
+
base = 'src',
|
|
105
|
+
}: {
|
|
106
|
+
text: string
|
|
107
|
+
sources?: AgentSource[]
|
|
108
|
+
base?: string
|
|
109
|
+
}) {
|
|
110
|
+
const blocks = derived(() => parseText(text))
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
{blocks.value.map((b) => (
|
|
114
|
+
<Block key={b.at} block={b} sources={sources} base={base} />
|
|
115
|
+
))}
|
|
116
|
+
</>
|
|
117
|
+
)
|
|
118
|
+
}
|