basalt-ui 0.4.2 → 1.0.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/AGENTS.md +70 -0
- package/CHANGELOG.md +199 -41
- package/LICENSE +201 -0
- package/README.md +434 -160
- package/agent/rules/basalt-agent.md +395 -0
- package/agent/rules/basalt-charts.md +170 -0
- package/agent/rules/basalt-commands.md +320 -0
- package/agent/rules/basalt-content.md +390 -0
- package/agent/rules/basalt-data.md +237 -0
- package/agent/rules/basalt-forms.md +186 -0
- package/agent/rules/basalt-mantine.md +327 -0
- package/agent/rules/basalt-notifications.md +264 -0
- package/agent/rules/basalt-query.md +130 -0
- package/agent/rules/basalt-router.md +173 -0
- package/agent/rules/basalt-state.md +99 -0
- package/agent/rules/basalt-tokens.md +148 -0
- package/agent/templates/CLAUDE-block.md.tpl +35 -0
- package/agent/templates/DESIGN.md.tpl +71 -0
- package/agent/templates/__root.tpl +31 -0
- package/agent/templates/query-client.ts.tpl +12 -0
- package/bin/basalt.mjs +14 -0
- package/configs/check.yml +29 -0
- package/configs/lefthook.yml +21 -0
- package/configs/oxfmt.json +8 -0
- package/configs/oxlint-plugin.js +269 -0
- package/configs/oxlint-plugin.test.ts +107 -0
- package/configs/oxlint.json +116 -0
- package/configs/tsconfig.base.json +20 -0
- package/configs/tsconfig.node.json +8 -0
- package/configs/tsconfig.react-app.json +8 -0
- package/dist/agent/ai-sdk-transport.d.ts +85 -0
- package/dist/agent/ai-sdk-transport.d.ts.map +1 -0
- package/dist/agent/ai-sdk-transport.js +109 -0
- package/dist/agent/history.d.ts +55 -0
- package/dist/agent/history.d.ts.map +1 -0
- package/dist/agent/history.js +32 -0
- package/dist/agent/index.d.ts +53 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +23 -0
- package/dist/agent/outcome.d.ts +71 -0
- package/dist/agent/outcome.d.ts.map +1 -0
- package/dist/agent/outcome.js +30 -0
- package/dist/agent/part-list.d.ts +75 -0
- package/dist/agent/part-list.d.ts.map +1 -0
- package/dist/agent/part-list.js +127 -0
- package/dist/agent/parts.d.ts +91 -0
- package/dist/agent/parts.d.ts.map +1 -0
- package/dist/agent/parts.js +49 -0
- package/dist/agent/stick-to-bottom.d.ts +23 -0
- package/dist/agent/stick-to-bottom.d.ts.map +1 -0
- package/dist/agent/stick-to-bottom.js +73 -0
- package/dist/agent/thread.d.ts +124 -0
- package/dist/agent/thread.d.ts.map +1 -0
- package/dist/agent/thread.js +131 -0
- package/dist/agent/transport.d.ts +87 -0
- package/dist/agent/transport.d.ts.map +1 -0
- package/dist/agent/transport.js +21 -0
- package/dist/agent/use-agent-stream.d.ts +34 -0
- package/dist/agent/use-agent-stream.d.ts.map +1 -0
- package/dist/agent/use-agent-stream.js +56 -0
- package/dist/agent/use-agent-thread-runs.d.ts +72 -0
- package/dist/agent/use-agent-thread-runs.d.ts.map +1 -0
- package/dist/agent/use-agent-thread-runs.js +217 -0
- package/dist/agent-chat/composer.d.ts +18 -0
- package/dist/agent-chat/composer.d.ts.map +1 -0
- package/dist/agent-chat/composer.js +86 -0
- package/dist/agent-chat/index.d.ts +24 -0
- package/dist/agent-chat/index.d.ts.map +1 -0
- package/dist/agent-chat/index.js +15 -0
- package/dist/agent-chat/thread-detail-panel.d.ts +27 -0
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -0
- package/dist/agent-chat/thread-detail-panel.js +108 -0
- package/dist/agent-chat/thread-feed.d.ts +18 -0
- package/dist/agent-chat/thread-feed.d.ts.map +1 -0
- package/dist/agent-chat/thread-feed.js +42 -0
- package/dist/agent-chat/thread-message.d.ts +31 -0
- package/dist/agent-chat/thread-message.d.ts.map +1 -0
- package/dist/agent-chat/thread-message.js +128 -0
- package/dist/agent-chat/thread-outcome-card.d.ts +19 -0
- package/dist/agent-chat/thread-outcome-card.d.ts.map +1 -0
- package/dist/agent-chat/thread-outcome-card.js +120 -0
- package/dist/agent-chat/thread-workspace.d.ts +27 -0
- package/dist/agent-chat/thread-workspace.d.ts.map +1 -0
- package/dist/agent-chat/thread-workspace.js +95 -0
- package/dist/charts/hooks/useChartSize.d.ts +25 -0
- package/dist/charts/hooks/useChartSize.d.ts.map +1 -0
- package/dist/charts/hooks/useChartSize.js +8 -0
- package/dist/charts/hooks/useChartTooltip.d.ts +13 -0
- package/dist/charts/hooks/useChartTooltip.d.ts.map +1 -0
- package/dist/charts/hooks/useChartTooltip.js +26 -0
- package/dist/charts/hooks/useHoverSync.d.ts +30 -0
- package/dist/charts/hooks/useHoverSync.d.ts.map +1 -0
- package/dist/charts/hooks/useHoverSync.js +70 -0
- package/dist/charts/hover-context.d.ts +21 -0
- package/dist/charts/hover-context.d.ts.map +1 -0
- package/dist/charts/hover-context.js +12 -0
- package/dist/charts/hover-sync.d.ts +14 -0
- package/dist/charts/hover-sync.d.ts.map +1 -0
- package/dist/charts/hover-sync.js +17 -0
- package/dist/charts/index.d.ts +47 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/index.js +129 -0
- package/dist/charts/kinds/Bars.d.ts +129 -0
- package/dist/charts/kinds/Bars.d.ts.map +1 -0
- package/dist/charts/kinds/Bars.js +467 -0
- package/dist/charts/kinds/Donut.d.ts +65 -0
- package/dist/charts/kinds/Donut.d.ts.map +1 -0
- package/dist/charts/kinds/Donut.js +158 -0
- package/dist/charts/kinds/DualPanel.d.ts +67 -0
- package/dist/charts/kinds/DualPanel.d.ts.map +1 -0
- package/dist/charts/kinds/DualPanel.js +326 -0
- package/dist/charts/kinds/Heatmap.d.ts +59 -0
- package/dist/charts/kinds/Heatmap.d.ts.map +1 -0
- package/dist/charts/kinds/Heatmap.js +175 -0
- package/dist/charts/kinds/MultiLine.d.ts +73 -0
- package/dist/charts/kinds/MultiLine.d.ts.map +1 -0
- package/dist/charts/kinds/MultiLine.js +275 -0
- package/dist/charts/kinds/StackedArea.d.ts +35 -0
- package/dist/charts/kinds/StackedArea.d.ts.map +1 -0
- package/dist/charts/kinds/StackedArea.js +151 -0
- package/dist/charts/kinds/ZonedLine.d.ts +94 -0
- package/dist/charts/kinds/ZonedLine.d.ts.map +1 -0
- package/dist/charts/kinds/ZonedLine.js +218 -0
- package/dist/charts/primitives/AreaGradient.d.ts +18 -0
- package/dist/charts/primitives/AreaGradient.d.ts.map +1 -0
- package/dist/charts/primitives/AreaGradient.js +13 -0
- package/dist/charts/primitives/Axes.d.ts +22 -0
- package/dist/charts/primitives/Axes.d.ts.map +1 -0
- package/dist/charts/primitives/Axes.js +79 -0
- package/dist/charts/primitives/ChartCard.d.ts +14 -0
- package/dist/charts/primitives/ChartCard.d.ts.map +1 -0
- package/dist/charts/primitives/ChartCard.js +144 -0
- package/dist/charts/primitives/ChartFrame.d.ts +70 -0
- package/dist/charts/primitives/ChartFrame.d.ts.map +1 -0
- package/dist/charts/primitives/ChartFrame.js +77 -0
- package/dist/charts/primitives/ChartLegend.d.ts +36 -0
- package/dist/charts/primitives/ChartLegend.d.ts.map +1 -0
- package/dist/charts/primitives/ChartLegend.js +234 -0
- package/dist/charts/primitives/ChartTooltip.d.ts +34 -0
- package/dist/charts/primitives/ChartTooltip.d.ts.map +1 -0
- package/dist/charts/primitives/ChartTooltip.js +134 -0
- package/dist/charts/primitives/Crosshair.d.ts +23 -0
- package/dist/charts/primitives/Crosshair.d.ts.map +1 -0
- package/dist/charts/primitives/Crosshair.js +21 -0
- package/dist/charts/primitives/HoverOverlay.d.ts +9 -0
- package/dist/charts/primitives/HoverOverlay.d.ts.map +1 -0
- package/dist/charts/primitives/HoverOverlay.js +21 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts +45 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts.map +1 -0
- package/dist/charts/primitives/ResponsiveChart.js +24 -0
- package/dist/charts/primitives/ZoneRects.d.ts +38 -0
- package/dist/charts/primitives/ZoneRects.d.ts.map +1 -0
- package/dist/charts/primitives/ZoneRects.js +30 -0
- package/dist/charts/series.d.ts +99 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +55 -0
- package/dist/charts/sparklines/BarSparkline.d.ts +13 -0
- package/dist/charts/sparklines/BarSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/BarSparkline.js +33 -0
- package/dist/charts/sparklines/LineSparkline.d.ts +15 -0
- package/dist/charts/sparklines/LineSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/LineSparkline.js +39 -0
- package/dist/charts/sparklines/index.d.ts +3 -0
- package/dist/charts/sparklines/index.d.ts.map +1 -0
- package/dist/charts/sparklines/index.js +6 -0
- package/dist/charts/theme.d.ts +21 -0
- package/dist/charts/theme.d.ts.map +1 -0
- package/dist/charts/theme.js +30 -0
- package/dist/charts/utils/domain.d.ts +20 -0
- package/dist/charts/utils/domain.d.ts.map +1 -0
- package/dist/charts/utils/domain.js +7 -0
- package/dist/charts/utils/format.d.ts +5 -0
- package/dist/charts/utils/format.d.ts.map +1 -0
- package/dist/charts/utils/format.js +27 -0
- package/dist/charts/utils/ticks.d.ts +5 -0
- package/dist/charts/utils/ticks.d.ts.map +1 -0
- package/dist/charts/utils/ticks.js +18 -0
- package/dist/cli/index.d.ts +273 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +907 -0
- package/dist/commands/ShortcutsHelp.d.ts +17 -0
- package/dist/commands/ShortcutsHelp.d.ts.map +1 -0
- package/dist/commands/ShortcutsHelp.js +64 -0
- package/dist/commands/define-commands.d.ts +140 -0
- package/dist/commands/define-commands.d.ts.map +1 -0
- package/dist/commands/define-commands.js +26 -0
- package/dist/commands/define-overlays.d.ts +134 -0
- package/dist/commands/define-overlays.d.ts.map +1 -0
- package/dist/commands/define-overlays.js +53 -0
- package/dist/commands/index.d.ts +42 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +46 -0
- package/dist/commands/overlays-mount.d.ts +117 -0
- package/dist/commands/overlays-mount.d.ts.map +1 -0
- package/dist/commands/overlays-mount.js +116 -0
- package/dist/commands/projectors.d.ts +152 -0
- package/dist/commands/projectors.d.ts.map +1 -0
- package/dist/commands/projectors.js +87 -0
- package/dist/commands/shortcut-format.d.ts +48 -0
- package/dist/commands/shortcut-format.d.ts.map +1 -0
- package/dist/commands/shortcut-format.js +33 -0
- package/dist/commands/useCommandHotkeys.d.ts +14 -0
- package/dist/commands/useCommandHotkeys.d.ts.map +1 -0
- package/dist/commands/useCommandHotkeys.js +45 -0
- package/dist/connectivity/connectivity-indicator.d.ts +8 -0
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -0
- package/dist/connectivity/connectivity-indicator.js +203 -0
- package/dist/connectivity/connectivity-provider.d.ts +7 -0
- package/dist/connectivity/connectivity-provider.d.ts.map +1 -0
- package/dist/connectivity/connectivity-provider.js +125 -0
- package/dist/connectivity/index.d.ts +13 -0
- package/dist/connectivity/index.d.ts.map +1 -0
- package/dist/connectivity/index.js +8 -0
- package/dist/connectivity/types.d.ts +36 -0
- package/dist/connectivity/types.d.ts.map +1 -0
- package/dist/connectivity/types.js +0 -0
- package/dist/connectivity/use-connectivity.d.ts +3 -0
- package/dist/connectivity/use-connectivity.d.ts.map +1 -0
- package/dist/connectivity/use-connectivity.js +14 -0
- package/dist/content/article-actions.d.ts +39 -0
- package/dist/content/article-actions.d.ts.map +1 -0
- package/dist/content/article-actions.js +28 -0
- package/dist/content/article-card.d.ts +58 -0
- package/dist/content/article-card.d.ts.map +1 -0
- package/dist/content/article-card.js +76 -0
- package/dist/content/article-card.module.css +109 -0
- package/dist/content/article-card.module.css.d.ts +16 -0
- package/dist/content/article-filter-bar.d.ts +40 -0
- package/dist/content/article-filter-bar.d.ts.map +1 -0
- package/dist/content/article-filter-bar.js +56 -0
- package/dist/content/article-layout.d.ts +61 -0
- package/dist/content/article-layout.d.ts.map +1 -0
- package/dist/content/article-layout.js +71 -0
- package/dist/content/article-layout.module.css +131 -0
- package/dist/content/article-layout.module.css.d.ts +20 -0
- package/dist/content/article-model.d.ts +62 -0
- package/dist/content/article-model.d.ts.map +1 -0
- package/dist/content/article-model.js +41 -0
- package/dist/content/block-split.d.ts +24 -0
- package/dist/content/block-split.d.ts.map +1 -0
- package/dist/content/block-split.js +63 -0
- package/dist/content/callout-alert.d.ts +27 -0
- package/dist/content/callout-alert.d.ts.map +1 -0
- package/dist/content/callout-alert.js +59 -0
- package/dist/content/callout.d.ts +24 -0
- package/dist/content/callout.d.ts.map +1 -0
- package/dist/content/callout.js +59 -0
- package/dist/content/callout.module.css +77 -0
- package/dist/content/callout.module.css.d.ts +16 -0
- package/dist/content/code-block.d.ts +26 -0
- package/dist/content/code-block.d.ts.map +1 -0
- package/dist/content/code-block.js +41 -0
- package/dist/content/code-block.module.css +86 -0
- package/dist/content/code-block.module.css.d.ts +14 -0
- package/dist/content/copy-action.d.ts +29 -0
- package/dist/content/copy-action.d.ts.map +1 -0
- package/dist/content/copy-action.js +46 -0
- package/dist/content/fence-block.d.ts +19 -0
- package/dist/content/fence-block.d.ts.map +1 -0
- package/dist/content/fence-block.js +23 -0
- package/dist/content/glyphs.d.ts +18 -0
- package/dist/content/glyphs.d.ts.map +1 -0
- package/dist/content/glyphs.js +43 -0
- package/dist/content/guide.d.ts +47 -0
- package/dist/content/guide.d.ts.map +1 -0
- package/dist/content/guide.js +110 -0
- package/dist/content/guide.module.css +62 -0
- package/dist/content/guide.module.css.d.ts +13 -0
- package/dist/content/heading-anchor.d.ts +8 -0
- package/dist/content/heading-anchor.d.ts.map +1 -0
- package/dist/content/heading-anchor.js +23 -0
- package/dist/content/heading-components.d.ts +5 -0
- package/dist/content/heading-components.d.ts.map +1 -0
- package/dist/content/heading-components.js +41 -0
- package/dist/content/highlighter.d.ts +8 -0
- package/dist/content/highlighter.d.ts.map +1 -0
- package/dist/content/highlighter.js +85 -0
- package/dist/content/index.d.ts +45 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +43 -0
- package/dist/content/markdown-hast.d.ts +23 -0
- package/dist/content/markdown-hast.d.ts.map +1 -0
- package/dist/content/markdown-hast.js +48 -0
- package/dist/content/markdown.d.ts +68 -0
- package/dist/content/markdown.d.ts.map +1 -0
- package/dist/content/markdown.js +180 -0
- package/dist/content/mdx.d.ts +20 -0
- package/dist/content/mdx.d.ts.map +1 -0
- package/dist/content/mdx.js +64 -0
- package/dist/content/mermaid.d.ts +32 -0
- package/dist/content/mermaid.d.ts.map +1 -0
- package/dist/content/mermaid.js +70 -0
- package/dist/content/mermaid.module.css +20 -0
- package/dist/content/mermaid.module.css.d.ts +8 -0
- package/dist/content/prose.d.ts +29 -0
- package/dist/content/prose.d.ts.map +1 -0
- package/dist/content/prose.js +24 -0
- package/dist/content/prose.module.css +330 -0
- package/dist/content/prose.module.css.d.ts +12 -0
- package/dist/content/reading-progress.d.ts +20 -0
- package/dist/content/reading-progress.d.ts.map +1 -0
- package/dist/content/reading-progress.js +38 -0
- package/dist/content/reading-progress.module.css +22 -0
- package/dist/content/reading-progress.module.css.d.ts +9 -0
- package/dist/content/slug.d.ts +28 -0
- package/dist/content/slug.d.ts.map +1 -0
- package/dist/content/slug.js +28 -0
- package/dist/content/toc.d.ts +37 -0
- package/dist/content/toc.d.ts.map +1 -0
- package/dist/content/toc.js +134 -0
- package/dist/content/toc.module.css +51 -0
- package/dist/content/toc.module.css.d.ts +13 -0
- package/dist/content/url-hardening.d.ts +23 -0
- package/dist/content/url-hardening.d.ts.map +1 -0
- package/dist/content/url-hardening.js +23 -0
- package/dist/dashboard/delta-badge.d.ts +13 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -0
- package/dist/dashboard/delta-badge.js +45 -0
- package/dist/dashboard/empty-state.d.ts +15 -0
- package/dist/dashboard/empty-state.d.ts.map +1 -0
- package/dist/dashboard/empty-state.js +56 -0
- package/dist/dashboard/index.d.ts +5 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +16 -0
- package/dist/dashboard/settings-section.d.ts +24 -0
- package/dist/dashboard/settings-section.d.ts.map +1 -0
- package/dist/dashboard/settings-section.js +61 -0
- package/dist/dashboard/settings-section.module.css +23 -0
- package/dist/dashboard/settings-section.module.css.d.ts +10 -0
- package/dist/dashboard/stat-card.d.ts +18 -0
- package/dist/dashboard/stat-card.d.ts.map +1 -0
- package/dist/dashboard/stat-card.js +74 -0
- package/dist/data/data-table.d.ts +198 -0
- package/dist/data/data-table.d.ts.map +1 -0
- package/dist/data/data-table.js +342 -0
- package/dist/data/index.d.ts +34 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +2 -0
- package/dist/data/table.d.ts +24 -0
- package/dist/data/table.d.ts.map +1 -0
- package/dist/data/table.js +20 -0
- package/dist/data/virtual-list.d.ts +74 -0
- package/dist/data/virtual-list.d.ts.map +1 -0
- package/dist/data/virtual-list.js +86 -0
- package/dist/data/virtual.d.ts +20 -0
- package/dist/data/virtual.d.ts.map +1 -0
- package/dist/data/virtual.js +4 -0
- package/dist/forms/FormErrorSummary.d.ts +29 -0
- package/dist/forms/FormErrorSummary.d.ts.map +1 -0
- package/dist/forms/FormErrorSummary.js +28 -0
- package/dist/forms/create-form.d.ts +31 -0
- package/dist/forms/create-form.d.ts.map +1 -0
- package/dist/forms/create-form.js +18 -0
- package/dist/forms/field.d.ts +22 -0
- package/dist/forms/field.d.ts.map +1 -0
- package/dist/forms/field.js +9 -0
- package/dist/forms/index.d.ts +17 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/index.js +13 -0
- package/dist/forms/use-form-draft.d.ts +61 -0
- package/dist/forms/use-form-draft.d.ts.map +1 -0
- package/dist/forms/use-form-draft.js +55 -0
- package/dist/guard/guard-hook.d.ts +40 -0
- package/dist/guard/guard-hook.d.ts.map +1 -0
- package/dist/guard/guard-hook.js +55 -0
- package/dist/guard/index.d.ts +144 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +315 -0
- package/dist/guard/types.d.ts +97 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +0 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/motion/index.d.ts +29 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +12 -0
- package/dist/notifications/bell.d.ts +12 -0
- package/dist/notifications/bell.d.ts.map +1 -0
- package/dist/notifications/bell.js +84 -0
- package/dist/notifications/center.d.ts +20 -0
- package/dist/notifications/center.d.ts.map +1 -0
- package/dist/notifications/center.js +144 -0
- package/dist/notifications/define-notifications.d.ts +97 -0
- package/dist/notifications/define-notifications.d.ts.map +1 -0
- package/dist/notifications/define-notifications.js +27 -0
- package/dist/notifications/index.d.ts +36 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +52 -0
- package/dist/notifications/notify.d.ts +92 -0
- package/dist/notifications/notify.d.ts.map +1 -0
- package/dist/notifications/notify.js +127 -0
- package/dist/notifications/overlay.d.ts +20 -0
- package/dist/notifications/overlay.d.ts.map +1 -0
- package/dist/notifications/overlay.js +12 -0
- package/dist/notifications/store.d.ts +120 -0
- package/dist/notifications/store.d.ts.map +1 -0
- package/dist/notifications/store.js +113 -0
- package/dist/provider/index.d.ts +93 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +106 -0
- package/dist/query/devtools.d.ts +21 -0
- package/dist/query/devtools.d.ts.map +1 -0
- package/dist/query/devtools.js +12 -0
- package/dist/query/index.d.ts +65 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +68 -0
- package/dist/register.d.ts +139 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +6 -0
- package/dist/router-tanstack/index.d.ts +74 -0
- package/dist/router-tanstack/index.d.ts.map +1 -0
- package/dist/router-tanstack/index.js +29 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts +78 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/multi-search-param-store.js +35 -0
- package/dist/router-tanstack/search-param-store.d.ts +92 -0
- package/dist/router-tanstack/search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/search-param-store.js +26 -0
- package/dist/shell/account-types.d.ts +118 -0
- package/dist/shell/account-types.d.ts.map +1 -0
- package/dist/shell/account-types.js +0 -0
- package/dist/shell/app-breadcrumbs.d.ts +17 -0
- package/dist/shell/app-breadcrumbs.d.ts.map +1 -0
- package/dist/shell/app-breadcrumbs.js +39 -0
- package/dist/shell/app-header.module.css +73 -0
- package/dist/shell/app-header.module.css.d.ts +11 -0
- package/dist/shell/app-mobile-nav.d.ts +26 -0
- package/dist/shell/app-mobile-nav.d.ts.map +1 -0
- package/dist/shell/app-mobile-nav.js +106 -0
- package/dist/shell/app-mobile-nav.module.css +100 -0
- package/dist/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/dist/shell/app-sidebar-account.d.ts +3 -0
- package/dist/shell/app-sidebar-account.d.ts.map +1 -0
- package/dist/shell/app-sidebar-account.js +84 -0
- package/dist/shell/app-sidebar.d.ts +56 -0
- package/dist/shell/app-sidebar.d.ts.map +1 -0
- package/dist/shell/app-sidebar.js +455 -0
- package/dist/shell/app-sidebar.module.css +414 -0
- package/dist/shell/app-sidebar.module.css.d.ts +34 -0
- package/dist/shell/index.d.ts +123 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +179 -0
- package/dist/shell/page-header.d.ts +13 -0
- package/dist/shell/page-header.d.ts.map +1 -0
- package/dist/shell/page-header.js +23 -0
- package/dist/shell/sidebar-search.d.ts +12 -0
- package/dist/shell/sidebar-search.d.ts.map +1 -0
- package/dist/shell/sidebar-search.js +62 -0
- package/dist/shell/sidebar-search.module.css +62 -0
- package/dist/shell/sidebar-search.module.css.d.ts +11 -0
- package/dist/state.d.ts +62 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +124 -0
- package/dist/styles.css +166 -0
- package/dist/surfaces.d.ts +376 -0
- package/dist/surfaces.d.ts.map +1 -0
- package/dist/surfaces.js +306 -0
- package/dist/theme/controls.module.css +143 -0
- package/dist/theme/controls.module.css.d.ts +17 -0
- package/dist/theme/floating.module.css +35 -0
- package/dist/theme/floating.module.css.d.ts +9 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +733 -0
- package/dist/theme/nav-link.module.css +67 -0
- package/dist/theme/nav-link.module.css.d.ts +8 -0
- package/dist/theme/segmented-control.module.css +14 -0
- package/dist/theme/segmented-control.module.css.d.ts +8 -0
- package/dist/theme/timeline.module.css +29 -0
- package/dist/theme/timeline.module.css.d.ts +9 -0
- package/dist/theme-lab/index.d.ts +59 -0
- package/dist/theme-lab/index.d.ts.map +1 -0
- package/dist/theme-lab/index.js +263 -0
- package/dist/theme-toggle/index.d.ts +8 -0
- package/dist/theme-toggle/index.d.ts.map +1 -0
- package/dist/theme-toggle/index.js +155 -0
- package/dist/tokens/index.d.ts +151 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +246 -0
- package/dist/tokens/palette.d.ts +304 -0
- package/dist/tokens/palette.d.ts.map +1 -0
- package/dist/tokens/palette.js +186 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +68 -0
- package/llms.txt +149 -0
- package/package.json +243 -46
- package/src/agent/ai-sdk-transport.ts +280 -0
- package/src/agent/history.ts +128 -0
- package/src/agent/index.ts +92 -0
- package/src/agent/outcome.ts +120 -0
- package/src/agent/part-list.tsx +292 -0
- package/src/agent/parts.ts +136 -0
- package/src/agent/stick-to-bottom.tsx +154 -0
- package/src/agent/thread.ts +312 -0
- package/src/agent/transport.ts +114 -0
- package/src/agent/use-agent-stream.ts +141 -0
- package/src/agent/use-agent-thread-runs.ts +440 -0
- package/src/agent-chat/composer.tsx +131 -0
- package/src/agent-chat/index.ts +35 -0
- package/src/agent-chat/thread-detail-panel.tsx +192 -0
- package/src/agent-chat/thread-feed.tsx +81 -0
- package/src/agent-chat/thread-message.tsx +251 -0
- package/src/agent-chat/thread-outcome-card.tsx +196 -0
- package/src/agent-chat/thread-workspace.tsx +179 -0
- package/src/charts/hooks/useChartSize.ts +31 -0
- package/src/charts/hooks/useChartTooltip.ts +31 -0
- package/src/charts/hooks/useHoverSync.ts +116 -0
- package/src/charts/hover-context.ts +28 -0
- package/src/charts/hover-sync.tsx +37 -0
- package/src/charts/index.ts +118 -0
- package/src/charts/kinds/Bars.tsx +634 -0
- package/src/charts/kinds/Donut.tsx +233 -0
- package/src/charts/kinds/DualPanel.tsx +432 -0
- package/src/charts/kinds/Heatmap.tsx +255 -0
- package/src/charts/kinds/MultiLine.tsx +376 -0
- package/src/charts/kinds/StackedArea.tsx +218 -0
- package/src/charts/kinds/ZonedLine.tsx +346 -0
- package/src/charts/primitives/AreaGradient.tsx +26 -0
- package/src/charts/primitives/Axes.tsx +97 -0
- package/src/charts/primitives/ChartCard.tsx +180 -0
- package/src/charts/primitives/ChartFrame.tsx +157 -0
- package/src/charts/primitives/ChartLegend.tsx +302 -0
- package/src/charts/primitives/ChartTooltip.tsx +158 -0
- package/src/charts/primitives/Crosshair.tsx +40 -0
- package/src/charts/primitives/HoverOverlay.tsx +24 -0
- package/src/charts/primitives/ResponsiveChart.tsx +64 -0
- package/src/charts/primitives/ZoneRects.tsx +67 -0
- package/src/charts/series.ts +163 -0
- package/src/charts/sparklines/BarSparkline.tsx +48 -0
- package/src/charts/sparklines/LineSparkline.tsx +57 -0
- package/src/charts/sparklines/index.ts +2 -0
- package/src/charts/theme.tsx +53 -0
- package/src/charts/utils/domain.test.ts +24 -0
- package/src/charts/utils/domain.ts +22 -0
- package/src/charts/utils/format.ts +27 -0
- package/src/charts/utils/ticks.ts +18 -0
- package/src/cli/check-theme.test.ts +658 -0
- package/src/cli/index.ts +1497 -0
- package/src/cli/init-sync.test.ts +160 -0
- package/src/commands/ShortcutsHelp.tsx +129 -0
- package/src/commands/define-commands.ts +184 -0
- package/src/commands/define-overlays.ts +197 -0
- package/src/commands/index.ts +86 -0
- package/src/commands/overlays-mount.tsx +301 -0
- package/src/commands/projectors.ts +267 -0
- package/src/commands/shortcut-format.ts +83 -0
- package/src/commands/useCommandHotkeys.ts +114 -0
- package/src/connectivity/connectivity-indicator.tsx +249 -0
- package/src/connectivity/connectivity-provider.tsx +186 -0
- package/src/connectivity/index.ts +18 -0
- package/src/connectivity/types.ts +39 -0
- package/src/connectivity/use-connectivity.ts +25 -0
- package/src/content/article-actions.test.ts +78 -0
- package/src/content/article-actions.ts +72 -0
- package/src/content/article-card.module.css +109 -0
- package/src/content/article-card.module.css.d.ts +16 -0
- package/src/content/article-card.tsx +173 -0
- package/src/content/article-filter-bar.tsx +88 -0
- package/src/content/article-layout.module.css +131 -0
- package/src/content/article-layout.module.css.d.ts +20 -0
- package/src/content/article-layout.tsx +167 -0
- package/src/content/article-model.test.ts +119 -0
- package/src/content/article-model.ts +110 -0
- package/src/content/block-split.test.ts +75 -0
- package/src/content/block-split.ts +102 -0
- package/src/content/callout-alert.ts +88 -0
- package/src/content/callout.module.css +77 -0
- package/src/content/callout.module.css.d.ts +16 -0
- package/src/content/callout.tsx +96 -0
- package/src/content/code-block.module.css +86 -0
- package/src/content/code-block.module.css.d.ts +14 -0
- package/src/content/code-block.tsx +82 -0
- package/src/content/copy-action.tsx +79 -0
- package/src/content/fence-block.tsx +39 -0
- package/src/content/glyphs.tsx +53 -0
- package/src/content/guide.module.css +62 -0
- package/src/content/guide.module.css.d.ts +13 -0
- package/src/content/guide.tsx +174 -0
- package/src/content/heading-anchor.tsx +54 -0
- package/src/content/heading-components.tsx +62 -0
- package/src/content/highlighter.ts +123 -0
- package/src/content/index.ts +60 -0
- package/src/content/markdown-hast.ts +80 -0
- package/src/content/markdown.tsx +346 -0
- package/src/content/mdx.tsx +127 -0
- package/src/content/mermaid.module.css +20 -0
- package/src/content/mermaid.module.css.d.ts +8 -0
- package/src/content/mermaid.tsx +124 -0
- package/src/content/prose.module.css +330 -0
- package/src/content/prose.module.css.d.ts +12 -0
- package/src/content/prose.tsx +53 -0
- package/src/content/reading-progress.module.css +22 -0
- package/src/content/reading-progress.module.css.d.ts +9 -0
- package/src/content/reading-progress.tsx +67 -0
- package/src/content/slug.test.ts +62 -0
- package/src/content/slug.ts +57 -0
- package/src/content/toc.module.css +51 -0
- package/src/content/toc.module.css.d.ts +13 -0
- package/src/content/toc.tsx +226 -0
- package/src/content/url-hardening.ts +46 -0
- package/src/dashboard/delta-badge.tsx +70 -0
- package/src/dashboard/empty-state.tsx +80 -0
- package/src/dashboard/index.ts +11 -0
- package/src/dashboard/settings-section.module.css +23 -0
- package/src/dashboard/settings-section.module.css.d.ts +10 -0
- package/src/dashboard/settings-section.tsx +118 -0
- package/src/dashboard/stat-card.tsx +105 -0
- package/src/data/data-table.tsx +695 -0
- package/src/data/index.ts +37 -0
- package/src/data/table.ts +46 -0
- package/src/data/virtual-list.tsx +180 -0
- package/src/data/virtual.ts +21 -0
- package/src/forms/FormErrorSummary.tsx +64 -0
- package/src/forms/create-form.ts +57 -0
- package/src/forms/field.ts +30 -0
- package/src/forms/index.ts +26 -0
- package/src/forms/use-form-draft.ts +170 -0
- package/src/guard/check-source.test.ts +834 -0
- package/src/guard/guard-hook.test.ts +173 -0
- package/src/guard/guard-hook.ts +122 -0
- package/src/guard/index.ts +510 -0
- package/src/guard/types.ts +117 -0
- package/src/index.ts +139 -0
- package/src/motion/index.ts +26 -0
- package/src/notifications/bell.tsx +108 -0
- package/src/notifications/center.tsx +245 -0
- package/src/notifications/define-notifications.ts +162 -0
- package/src/notifications/index.ts +79 -0
- package/src/notifications/notify.tsx +260 -0
- package/src/notifications/overlay.tsx +64 -0
- package/src/notifications/store.ts +287 -0
- package/src/provider/index.tsx +234 -0
- package/src/query/devtools.tsx +38 -0
- package/src/query/index.ts +129 -0
- package/src/register.ts +158 -0
- package/src/router-tanstack/index.ts +111 -0
- package/src/router-tanstack/multi-search-param-store.test.ts +56 -0
- package/src/router-tanstack/multi-search-param-store.ts +122 -0
- package/src/router-tanstack/search-param-store.ts +125 -0
- package/src/shell/account-types.ts +119 -0
- package/src/shell/app-breadcrumbs.tsx +90 -0
- package/src/shell/app-header.module.css +73 -0
- package/src/shell/app-header.module.css.d.ts +11 -0
- package/src/shell/app-mobile-nav.module.css +100 -0
- package/src/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/src/shell/app-mobile-nav.tsx +146 -0
- package/src/shell/app-sidebar-account.tsx +142 -0
- package/src/shell/app-sidebar.module.css +414 -0
- package/src/shell/app-sidebar.module.css.d.ts +34 -0
- package/src/shell/app-sidebar.tsx +632 -0
- package/src/shell/index.tsx +343 -0
- package/src/shell/page-header.tsx +35 -0
- package/src/shell/sidebar-search.module.css +62 -0
- package/src/shell/sidebar-search.module.css.d.ts +11 -0
- package/src/shell/sidebar-search.tsx +80 -0
- package/src/state.ts +246 -0
- package/src/styles.css +166 -0
- package/src/styles.floor.test.ts +36 -0
- package/src/surfaces.ts +489 -0
- package/src/theme/border-coverage.test.ts +272 -0
- package/src/theme/contrast.test.ts +306 -0
- package/src/theme/controls.module.css +143 -0
- package/src/theme/controls.module.css.d.ts +17 -0
- package/src/theme/floating.module.css +35 -0
- package/src/theme/floating.module.css.d.ts +9 -0
- package/src/theme/index.ts +933 -0
- package/src/theme/nav-link.module.css +67 -0
- package/src/theme/nav-link.module.css.d.ts +8 -0
- package/src/theme/segmented-control.module.css +14 -0
- package/src/theme/segmented-control.module.css.d.ts +8 -0
- package/src/theme/shadow-surfaces.test.ts +421 -0
- package/src/theme/timeline.module.css +29 -0
- package/src/theme/timeline.module.css.d.ts +9 -0
- package/src/theme-lab/index.tsx +359 -0
- package/src/theme-lab/theme-lab.test.ts +60 -0
- package/src/theme-toggle/index.tsx +180 -0
- package/src/tokens/index.ts +363 -0
- package/src/tokens/palette.ts +288 -0
- package/src/vite.ts +122 -0
- package/src/index.css +0 -877
- package/src/starlight.css +0 -308
- package/tailwind.config.js +0 -78
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiSdkTransport — an AgentTransport backed by Vercel AI SDK's native streaming + resumption
|
|
3
|
+
* primitives (the `ai` npm package). This is the RECOMMENDED DEFAULT transport for LLM chat use
|
|
4
|
+
* cases — edenTransport remains the zero-extra-dependency alternative (see agent/rules/basalt-agent.md).
|
|
5
|
+
*
|
|
6
|
+
* OPTIONAL PEER: `ai` is not a required dependency. Importing 'basalt-ui/agent' (and calling this
|
|
7
|
+
* factory) does NOT eagerly resolve it — the package is loaded via a memoized dynamic import()
|
|
8
|
+
* only when the first stream()/resume() call actually runs, mirroring the lazy-optional-peer
|
|
9
|
+
* contract used by BasaltStickToBottom. Unlike that, there is no meaningful "plain text" fallback
|
|
10
|
+
* for a missing transport: if 'ai' is not installed, the dynamic import
|
|
11
|
+
* rejects and the error propagates through the async generator to the consumer's EXISTING error
|
|
12
|
+
* handling (useAgentStream sets status: 'error'; useAgentThreadRuns falls back to its
|
|
13
|
+
* onFailureStatus) — no separate crash path is introduced.
|
|
14
|
+
*
|
|
15
|
+
* Install the optional peer:
|
|
16
|
+
* bun add ai
|
|
17
|
+
*
|
|
18
|
+
* WHY DIFFING IS NEEDED: AI SDK's `readUIMessageStream` yields the FULL accumulated `UIMessage`
|
|
19
|
+
* snapshot (a growing `parts` array, with existing parts' content growing in place) on every
|
|
20
|
+
* update — it is not itself a delta stream. basalt-ui's whole part-accumulation model
|
|
21
|
+
* (useAgentStream / useAgentThreadRuns, and every consumer's own coalescing) is delta-based: many
|
|
22
|
+
* small parts merged at render time. This module diffs consecutive snapshots and yields only the
|
|
23
|
+
* new deltas as AgentParts, so nothing is double-rendered.
|
|
24
|
+
*
|
|
25
|
+
* CHAT ID BINDING: AI SDK's convention is that the chat id is known client-side before the
|
|
26
|
+
* request (unlike a river/server-minted id) — `aiSdkTransport(options)` mints ONE stable chat id
|
|
27
|
+
* at construction time, so the returned object is immediately usable with useAgentStream (a single
|
|
28
|
+
* ongoing conversation). `.forThread(threadId)` returns a transport bound to an arbitrary
|
|
29
|
+
* caller-supplied id instead — pass a basalt-ui thread id here to plug into
|
|
30
|
+
* useAgentThreadRuns's per-thread transport-factory form, so a thread's turns (and its mount-time
|
|
31
|
+
* resume) share one continuous AI SDK chat session:
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import { useAgentStream, aiSdkTransport } from 'basalt-ui/agent'
|
|
35
|
+
*
|
|
36
|
+
* const transport = aiSdkTransport({ api: '/api/chat' })
|
|
37
|
+
* const { parts, status, send } = useAgentStream({ transport })
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* import { useAgentThreadRuns, aiSdkTransport, createThreadsStore, heuristicOutcome } from 'basalt-ui/agent'
|
|
41
|
+
*
|
|
42
|
+
* const useThreads = createThreadsStore({ key: 'main-threads', version: 1 })
|
|
43
|
+
* const transport = aiSdkTransport({ api: '/api/chat' })
|
|
44
|
+
* const { runs, start } = useAgentThreadRuns({
|
|
45
|
+
* transport: (threadId) => transport.forThread(threadId),
|
|
46
|
+
* store: useThreads(),
|
|
47
|
+
* resolveOutcome: heuristicOutcome,
|
|
48
|
+
* })
|
|
49
|
+
*/
|
|
50
|
+
import type { AgentPart, SourcePart, ToolCallPart } from './parts'
|
|
51
|
+
import type { AgentTransport } from './transport'
|
|
52
|
+
|
|
53
|
+
// ── ai (optional peer) — TYPE-ONLY imports, erased at runtime ────────────────
|
|
54
|
+
// verbatimModuleSyntax-safe: these never trigger a runtime resolution of 'ai'. The actual runtime
|
|
55
|
+
// access goes through the memoized `import('ai')` inside resolveAiSdk() below.
|
|
56
|
+
import type { DefaultChatTransport, UIMessage, UIMessageChunk, readUIMessageStream } from 'ai'
|
|
57
|
+
|
|
58
|
+
/** The element type of an AI SDK UIMessage's `parts` array (defaults applied). */
|
|
59
|
+
type AiPart = UIMessage['parts'][number]
|
|
60
|
+
|
|
61
|
+
// ── AiSdkTransportOptions ─────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
export type AiSdkTransportOptions = {
|
|
64
|
+
/** The API URL AI SDK's transport POSTs new turns to and GETs reconnects from. */
|
|
65
|
+
readonly api: string
|
|
66
|
+
/** HTTP headers to send with every request. */
|
|
67
|
+
readonly headers?: Record<string, string> | Headers
|
|
68
|
+
/** The fetch credentials mode. Defaults to 'same-origin' (AI SDK's own default). */
|
|
69
|
+
readonly credentials?: RequestCredentials
|
|
70
|
+
/**
|
|
71
|
+
* Custom fetch implementation — e.g. to scope requests to a mock backend in tests/playground,
|
|
72
|
+
* or to add middleware. Defaults to the ambient `fetch` when omitted.
|
|
73
|
+
*/
|
|
74
|
+
readonly fetch?: typeof globalThis.fetch
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── AiSdkTransport ─────────────────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
export type AiSdkTransport<TPart = AgentPart> = AgentTransport<TPart, string> & {
|
|
80
|
+
/**
|
|
81
|
+
* Returns an AgentTransport bound to a stable chat id (e.g. a basalt-ui thread id) instead of
|
|
82
|
+
* this transport's own fixed one. Use this for useAgentThreadRuns's per-thread transport-factory
|
|
83
|
+
* form so each thread's turns share one continuous AI SDK chat session.
|
|
84
|
+
*/
|
|
85
|
+
readonly forThread: (chatId: string) => AgentTransport<TPart, string>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── Lazy, memoized 'ai' resolution ────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
/** Everything resolved from the dynamically-imported 'ai' module, memoized per aiSdkTransport() call. */
|
|
91
|
+
type ResolvedAiSdk = {
|
|
92
|
+
readonly httpTransport: DefaultChatTransport<UIMessage>
|
|
93
|
+
readonly readUIMessageStream: typeof readUIMessageStream
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Builds the lazy resolver for one aiSdkTransport() call: the dynamic import() AND the constructed
|
|
98
|
+
* DefaultChatTransport are memoized here (module-stable per call, not per stream()/resume() call),
|
|
99
|
+
* so repeated turns across any chat id reuse the same underlying HTTP transport.
|
|
100
|
+
*/
|
|
101
|
+
function createAiSdkResolver(options: AiSdkTransportOptions): () => Promise<ResolvedAiSdk> {
|
|
102
|
+
let resolved: Promise<ResolvedAiSdk> | undefined
|
|
103
|
+
return function resolveAiSdk(): Promise<ResolvedAiSdk> {
|
|
104
|
+
resolved ??= import('ai').then(
|
|
105
|
+
({ DefaultChatTransport: DefaultChatTransportCtor, readUIMessageStream: read }) => ({
|
|
106
|
+
httpTransport: new DefaultChatTransportCtor<UIMessage>({
|
|
107
|
+
api: options.api,
|
|
108
|
+
...(options.headers !== undefined ? { headers: options.headers } : {}),
|
|
109
|
+
...(options.credentials !== undefined ? { credentials: options.credentials } : {}),
|
|
110
|
+
...(options.fetch !== undefined ? { fetch: options.fetch } : {}),
|
|
111
|
+
}),
|
|
112
|
+
readUIMessageStream: read,
|
|
113
|
+
}),
|
|
114
|
+
)
|
|
115
|
+
return resolved
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── Snapshot diffing: UIMessage → AgentPart deltas ────────────────────────────
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Diffs one AI SDK part (by array index) against its previous snapshot at that same index,
|
|
123
|
+
* returning zero or more new AgentPart deltas.
|
|
124
|
+
*
|
|
125
|
+
* source-document, file, reasoning-file, data-*, step-start, custom, and dynamic-tool parts have
|
|
126
|
+
* no AgentPart equivalent yet — deliberate v1 gap, skipped rather than inventing new variants.
|
|
127
|
+
*/
|
|
128
|
+
function diffPart(prevPart: AiPart | undefined, currPart: AiPart): AgentPart[] {
|
|
129
|
+
switch (currPart.type) {
|
|
130
|
+
case 'text': {
|
|
131
|
+
const prevText = prevPart?.type === 'text' ? prevPart.text : ''
|
|
132
|
+
const delta = currPart.text.slice(prevText.length)
|
|
133
|
+
return delta.length === 0 ? [] : [{ type: 'text', text: delta }]
|
|
134
|
+
}
|
|
135
|
+
case 'reasoning': {
|
|
136
|
+
const prevText = prevPart?.type === 'reasoning' ? prevPart.text : ''
|
|
137
|
+
const delta = currPart.text.slice(prevText.length)
|
|
138
|
+
return delta.length === 0 ? [] : [{ type: 'reasoning', text: delta }]
|
|
139
|
+
}
|
|
140
|
+
case 'source-url': {
|
|
141
|
+
// Emit once, the first time this part appears at this index.
|
|
142
|
+
if (prevPart !== undefined) return []
|
|
143
|
+
const source: SourcePart = { type: 'source', url: currPart.url }
|
|
144
|
+
return [currPart.title !== undefined ? { ...source, title: currPart.title } : source]
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return currPart.type.startsWith('tool-') ? diffToolPart(prevPart, currPart) : []
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Minimal structural shape read off a `tool-${name}` UIMessagePart. Cast to this (rather than
|
|
153
|
+
* AI SDK's own generic ToolUIPart<TOOLS>) because we diff by raw `type`/`state` string comparison,
|
|
154
|
+
* not by a caller-supplied tool registry.
|
|
155
|
+
*/
|
|
156
|
+
type ToolLike = {
|
|
157
|
+
readonly type: string
|
|
158
|
+
readonly toolCallId: string
|
|
159
|
+
readonly state: string
|
|
160
|
+
readonly input?: unknown
|
|
161
|
+
readonly output?: unknown
|
|
162
|
+
readonly errorText?: string
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function diffToolPart(prevPart: AiPart | undefined, currPart: AiPart): AgentPart[] {
|
|
166
|
+
const curr = currPart as unknown as ToolLike
|
|
167
|
+
// Deliberate v1 simplification: never emit on 'input-streaming' (partial/DeepPartial input) —
|
|
168
|
+
// wait for at least 'input-available' so the consumer isn't flooded with incomplete fragments.
|
|
169
|
+
if (curr.state === 'input-streaming') return []
|
|
170
|
+
|
|
171
|
+
const prev =
|
|
172
|
+
prevPart !== undefined && prevPart.type === currPart.type
|
|
173
|
+
? (prevPart as unknown as ToolLike)
|
|
174
|
+
: undefined
|
|
175
|
+
// Already emitted this exact state for this tool call index — nothing new to report.
|
|
176
|
+
if (prev?.state === curr.state) return []
|
|
177
|
+
|
|
178
|
+
const toolName = curr.type.slice('tool-'.length)
|
|
179
|
+
const base: ToolCallPart = {
|
|
180
|
+
type: 'tool',
|
|
181
|
+
toolName,
|
|
182
|
+
toolCallId: curr.toolCallId,
|
|
183
|
+
input: curr.input,
|
|
184
|
+
}
|
|
185
|
+
if (curr.state === 'output-available') return [{ ...base, output: curr.output }]
|
|
186
|
+
// output-error: still surface it as a tool part rather than silently dropping the failure — the
|
|
187
|
+
// error text becomes the output payload since ToolCallPart has no dedicated error field.
|
|
188
|
+
if (curr.state === 'output-error') return [{ ...base, output: { error: curr.errorText } }]
|
|
189
|
+
return [base]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Diffs every index of one UIMessage snapshot against the previous snapshot. */
|
|
193
|
+
function diffMessage(prev: UIMessage | undefined, curr: UIMessage): AgentPart[] {
|
|
194
|
+
const deltas: AgentPart[] = []
|
|
195
|
+
curr.parts.forEach((part, i) => {
|
|
196
|
+
deltas.push(...diffPart(prev?.parts[i], part))
|
|
197
|
+
})
|
|
198
|
+
return deltas
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Reads a raw UIMessageChunk stream through readUIMessageStream and yields only the new deltas
|
|
203
|
+
* between consecutive UIMessage snapshots, cast to TPart (this transport only ever constructs the
|
|
204
|
+
* built-in AgentPart variants, so TPart must be — or be assignable from — AgentPart for a
|
|
205
|
+
* meaningful result; same documented-cast convention as useAgentThreadRuns' defaultToUserParts).
|
|
206
|
+
*
|
|
207
|
+
* `resume()`'s underlying reconnectToStream call has no AbortSignal parameter in the current AI
|
|
208
|
+
* SDK API (unlike sendMessages), so we can't cancel the in-flight fetch directly — checking
|
|
209
|
+
* `signal.aborted` here at least stops yielding further deltas to an aborted caller promptly.
|
|
210
|
+
*/
|
|
211
|
+
async function* diffChunkStream<TPart>(
|
|
212
|
+
chunkStream: ReadableStream<UIMessageChunk>,
|
|
213
|
+
readStream: typeof readUIMessageStream,
|
|
214
|
+
signal?: AbortSignal,
|
|
215
|
+
): AsyncGenerator<TPart> {
|
|
216
|
+
let prev: UIMessage | undefined
|
|
217
|
+
for await (const curr of readStream<UIMessage>({ stream: chunkStream })) {
|
|
218
|
+
if (signal?.aborted) return
|
|
219
|
+
for (const part of diffMessage(prev, curr)) {
|
|
220
|
+
yield part as TPart
|
|
221
|
+
}
|
|
222
|
+
prev = curr
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ── aiSdkTransport ─────────────────────────────────────────────────────────────
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Wraps AI SDK's `DefaultChatTransport` + `readUIMessageStream` into an AgentTransport.
|
|
230
|
+
*
|
|
231
|
+
* The returned object is immediately usable with useAgentStream (one fixed, stable chat id for
|
|
232
|
+
* the whole conversation). Call `.forThread(threadId)` to get a transport bound to a different
|
|
233
|
+
* (caller-supplied) chat id — the per-thread form for useAgentThreadRuns.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* const transport = aiSdkTransport<AgentPart>({ api: '/api/chat' })
|
|
237
|
+
* const { send, parts, status } = useAgentStream({ transport })
|
|
238
|
+
*/
|
|
239
|
+
export function aiSdkTransport<TPart = AgentPart>(
|
|
240
|
+
options: AiSdkTransportOptions,
|
|
241
|
+
): AiSdkTransport<TPart> {
|
|
242
|
+
const resolveAiSdk = createAiSdkResolver(options)
|
|
243
|
+
|
|
244
|
+
function makeTransport(chatId: string): AgentTransport<TPart, string> {
|
|
245
|
+
return {
|
|
246
|
+
async *stream(input: string, signal?: AbortSignal): AsyncGenerator<TPart> {
|
|
247
|
+
// Synthesized locally, first — we already know the chat id client-side, so there is no
|
|
248
|
+
// need to wait on the server to hand us a run id (unlike a river-style protocol).
|
|
249
|
+
yield { type: 'start', runId: chatId, resumeToken: chatId } as TPart
|
|
250
|
+
|
|
251
|
+
const { httpTransport, readUIMessageStream: readStream } = await resolveAiSdk()
|
|
252
|
+
const userMessage: UIMessage = {
|
|
253
|
+
id: crypto.randomUUID(),
|
|
254
|
+
role: 'user',
|
|
255
|
+
parts: [{ type: 'text', text: input }],
|
|
256
|
+
}
|
|
257
|
+
const chunkStream = await httpTransport.sendMessages({
|
|
258
|
+
chatId,
|
|
259
|
+
messages: [userMessage],
|
|
260
|
+
trigger: 'submit-message',
|
|
261
|
+
messageId: undefined,
|
|
262
|
+
abortSignal: signal,
|
|
263
|
+
})
|
|
264
|
+
yield* diffChunkStream<TPart>(chunkStream, readStream, signal)
|
|
265
|
+
},
|
|
266
|
+
async *resume(resumeToken: string, signal?: AbortSignal): AsyncGenerator<TPart> {
|
|
267
|
+
const { httpTransport, readUIMessageStream: readStream } = await resolveAiSdk()
|
|
268
|
+
const chunkStream = await httpTransport.reconnectToStream({ chatId: resumeToken })
|
|
269
|
+
if (chunkStream === null) return
|
|
270
|
+
yield* diffChunkStream<TPart>(chunkStream, readStream, signal)
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const fixedChatId = crypto.randomUUID()
|
|
276
|
+
return {
|
|
277
|
+
...makeTransport(fixedChatId),
|
|
278
|
+
forThread: (chatId: string) => makeTransport(chatId),
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createChatHistoryStore — persisted, ring-buffered chat history on createPersistedState.
|
|
3
|
+
*
|
|
4
|
+
* Returns a stable hook factory (call once per module per stable key) that provides the full
|
|
5
|
+
* message history, an append function, and a clear function. Messages are trimmed to `max`
|
|
6
|
+
* (default 100) via a ring-buffer strategy — oldest entries are dropped first.
|
|
7
|
+
*
|
|
8
|
+
* SSR-safe: the underlying createPersistedState handles the server snapshot (returns initial).
|
|
9
|
+
* Cross-tab: the 'storage' event propagates changes to other tabs automatically.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { createChatHistoryStore } from 'basalt-ui/agent'
|
|
13
|
+
*
|
|
14
|
+
* // Call once at module scope with a stable key:
|
|
15
|
+
* const useChatHistory = createChatHistoryStore({ key: 'main-chat', version: 1 })
|
|
16
|
+
*
|
|
17
|
+
* // In a component:
|
|
18
|
+
* function Chat() {
|
|
19
|
+
* const { messages, append, clear } = useChatHistory()
|
|
20
|
+
* // ...
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
import { useCallback, useRef } from 'react'
|
|
24
|
+
import { createPersistedState } from '../state'
|
|
25
|
+
import type { AgentPart } from './parts'
|
|
26
|
+
|
|
27
|
+
// ── ChatMessage ───────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A single chat message. The `id` is a stable identifier for React keys and de-duplication.
|
|
31
|
+
* Parts are the typed agent stream parts accumulated for this turn.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const msg: ChatMessage = {
|
|
35
|
+
* id: crypto.randomUUID(),
|
|
36
|
+
* role: 'user',
|
|
37
|
+
* parts: [{ type: 'text', text: 'Hello' }],
|
|
38
|
+
* createdAt: Date.now(),
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
export type ChatMessage<TPart = AgentPart> = {
|
|
42
|
+
readonly id: string
|
|
43
|
+
readonly role: 'user' | 'assistant'
|
|
44
|
+
readonly parts: TPart[]
|
|
45
|
+
readonly createdAt: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ── createChatHistoryStore options ────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
export type ChatHistoryStoreOptions = {
|
|
51
|
+
/** localStorage key (namespaced as `basalt:<key>`). Stable — changes key lose history. */
|
|
52
|
+
readonly key: string
|
|
53
|
+
/** Envelope version. Increment when the ChatMessage shape changes to clear old data. */
|
|
54
|
+
readonly version: number
|
|
55
|
+
/**
|
|
56
|
+
* Maximum number of messages to retain. Oldest messages are dropped when exceeded.
|
|
57
|
+
* @default 100
|
|
58
|
+
*/
|
|
59
|
+
readonly max?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── Return type of the factory hook ──────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
export type ChatHistoryStore<TPart = AgentPart> = {
|
|
65
|
+
/** All retained messages, oldest first. */
|
|
66
|
+
readonly messages: ChatMessage<TPart>[]
|
|
67
|
+
/** Append a message. Trims to `max` if needed (ring-buffer: drops oldest). */
|
|
68
|
+
readonly append: (message: ChatMessage<TPart>) => void
|
|
69
|
+
/** Clear all messages. */
|
|
70
|
+
readonly clear: () => void
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ── createChatHistoryStore ────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates a stable persisted chat history hook for the given key + version.
|
|
77
|
+
*
|
|
78
|
+
* Call this ONCE per module (not inside a component). The returned hook can be called in any
|
|
79
|
+
* component that needs access to the same history. All instances sharing the same key stay
|
|
80
|
+
* in sync across tabs via the 'storage' event.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // src/chat/history.ts — ONE stable creation per key:
|
|
84
|
+
* export const useChatHistory = createChatHistoryStore({ key: 'main-chat', version: 1 })
|
|
85
|
+
*
|
|
86
|
+
* // In a component:
|
|
87
|
+
* const { messages, append, clear } = useChatHistory()
|
|
88
|
+
* append({ id: crypto.randomUUID(), role: 'user', parts: [...], createdAt: Date.now() })
|
|
89
|
+
*/
|
|
90
|
+
export function createChatHistoryStore<TPart = AgentPart>(
|
|
91
|
+
opts: ChatHistoryStoreOptions,
|
|
92
|
+
): () => ChatHistoryStore<TPart> {
|
|
93
|
+
const max = opts.max ?? 100
|
|
94
|
+
|
|
95
|
+
const usePersistedMessages = createPersistedState<ChatMessage<TPart>[]>({
|
|
96
|
+
key: opts.key,
|
|
97
|
+
version: opts.version,
|
|
98
|
+
initial: [],
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return function useChatHistoryStore(): ChatHistoryStore<TPart> {
|
|
102
|
+
const [messages, setMessages] = usePersistedMessages()
|
|
103
|
+
|
|
104
|
+
// Ref mirrors the latest committed value so that two synchronous append() calls in one
|
|
105
|
+
// render cycle accumulate correctly. createPersistedState's setter is a whole-value setter
|
|
106
|
+
// (not a functional updater), so the second call would otherwise overwrite the first.
|
|
107
|
+
const ref = useRef(messages)
|
|
108
|
+
ref.current = messages
|
|
109
|
+
|
|
110
|
+
const append = useCallback(
|
|
111
|
+
(message: ChatMessage<TPart>): void => {
|
|
112
|
+
const next = [...ref.current, message]
|
|
113
|
+
// Ring-buffer: trim to max, dropping oldest entries first.
|
|
114
|
+
const trimmed = next.length > max ? next.slice(next.length - max) : next
|
|
115
|
+
ref.current = trimmed // sync so a second append in the same tick sees the update
|
|
116
|
+
setMessages(trimmed)
|
|
117
|
+
},
|
|
118
|
+
[setMessages],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
const clear = useCallback((): void => {
|
|
122
|
+
ref.current = []
|
|
123
|
+
setMessages([])
|
|
124
|
+
}, [setMessages])
|
|
125
|
+
|
|
126
|
+
return { messages, append, clear }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* basalt-ui/agent — headless, Mantine-free streaming-chat layer over an injected transport seam.
|
|
3
|
+
*
|
|
4
|
+
* `aiSdkTransport` (backed by the `ai` npm package) is the RECOMMENDED DEFAULT transport for LLM
|
|
5
|
+
* chat use cases; `edenTransport` remains the zero-extra-dependency alternative. Optional peers
|
|
6
|
+
* (ai, use-stick-to-bottom) are all lazily loaded — importing this module does NOT eagerly resolve
|
|
7
|
+
* either of them. This module ships no markdown renderer — `agent/** -> content` is lint-blocked
|
|
8
|
+
* by design, so `PartList` takes a consumer-supplied `components.text`; basalt's own is
|
|
9
|
+
* `basalt-ui/content`'s `Markdown`.
|
|
10
|
+
*
|
|
11
|
+
* Install optional peers:
|
|
12
|
+
* bun add ai # aiSdkTransport
|
|
13
|
+
* bun add use-stick-to-bottom # BasaltStickToBottom
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { useAgentStream, edenTransport, PartList, BasaltStickToBottom } from 'basalt-ui/agent'
|
|
17
|
+
*
|
|
18
|
+
* const transport = edenTransport((input, signal) =>
|
|
19
|
+
* api.chat.post({ body: { message: input }, fetch: { signal } }),
|
|
20
|
+
* )
|
|
21
|
+
*
|
|
22
|
+
* function Chat() {
|
|
23
|
+
* const { parts, status, send, stop } = useAgentStream({ transport })
|
|
24
|
+
* return (
|
|
25
|
+
* <BasaltStickToBottom style={{ height: '400px', overflow: 'auto' }}>
|
|
26
|
+
* <PartList parts={parts} />
|
|
27
|
+
* <button onClick={() => send('Hello')}>Send</button>
|
|
28
|
+
* {status === 'streaming' && <button onClick={stop}>Stop</button>}
|
|
29
|
+
* </BasaltStickToBottom>
|
|
30
|
+
* )
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
// ── AgentPart discriminated union ─────────────────────────────────────────────
|
|
35
|
+
export type {
|
|
36
|
+
AgentPart,
|
|
37
|
+
StartPart,
|
|
38
|
+
TextPart,
|
|
39
|
+
ReasoningPart,
|
|
40
|
+
ToolCallPart,
|
|
41
|
+
SourcePart,
|
|
42
|
+
ErrorPart,
|
|
43
|
+
} from './parts'
|
|
44
|
+
export { parseAgentPart, isStartPart } from './parts'
|
|
45
|
+
|
|
46
|
+
// ── AgentTransport + edenTransport ───────────────────────────────────────────
|
|
47
|
+
export type { AgentTransport } from './transport'
|
|
48
|
+
export { edenTransport } from './transport'
|
|
49
|
+
|
|
50
|
+
// ── aiSdkTransport (recommended default, optional peer: ai) ──────────────────
|
|
51
|
+
export { aiSdkTransport } from './ai-sdk-transport'
|
|
52
|
+
export type { AiSdkTransport, AiSdkTransportOptions } from './ai-sdk-transport'
|
|
53
|
+
|
|
54
|
+
// ── useAgentStream ────────────────────────────────────────────────────────────
|
|
55
|
+
export { useAgentStream } from './use-agent-stream'
|
|
56
|
+
export type { StreamStatus, UseAgentStreamReturn } from './use-agent-stream'
|
|
57
|
+
|
|
58
|
+
// ── useAgentThreadRuns ────────────────────────────────────────────────────────
|
|
59
|
+
export { useAgentThreadRuns } from './use-agent-thread-runs'
|
|
60
|
+
export type {
|
|
61
|
+
ThreadRunState,
|
|
62
|
+
UseAgentThreadRunsArgs,
|
|
63
|
+
UseAgentThreadRunsReturn,
|
|
64
|
+
} from './use-agent-thread-runs'
|
|
65
|
+
|
|
66
|
+
// ── PartList + renderer types ─────────────────────────────────────────────────
|
|
67
|
+
export { PartList } from './part-list'
|
|
68
|
+
export type {
|
|
69
|
+
PartListProps,
|
|
70
|
+
AgentPartRenderers,
|
|
71
|
+
TextPartRenderer,
|
|
72
|
+
ReasoningPartRenderer,
|
|
73
|
+
ToolCallPartRenderer,
|
|
74
|
+
SourcePartRenderer,
|
|
75
|
+
ErrorPartRenderer,
|
|
76
|
+
} from './part-list'
|
|
77
|
+
|
|
78
|
+
// ── BasaltStickToBottom (lazy, optional peer: use-stick-to-bottom) ────────────
|
|
79
|
+
export { BasaltStickToBottom } from './stick-to-bottom'
|
|
80
|
+
export type { BasaltStickToBottomProps } from './stick-to-bottom'
|
|
81
|
+
|
|
82
|
+
// ── createChatHistoryStore + ChatMessage ──────────────────────────────────────
|
|
83
|
+
export { createChatHistoryStore } from './history'
|
|
84
|
+
export type { ChatMessage, ChatHistoryStore, ChatHistoryStoreOptions } from './history'
|
|
85
|
+
|
|
86
|
+
// ── createThreadsStore + AgentThread ──────────────────────────────────────────
|
|
87
|
+
export { createThreadsStore } from './thread'
|
|
88
|
+
export type { AgentThread, ThreadStatus, ThreadsStore, ThreadsStoreOptions } from './thread'
|
|
89
|
+
|
|
90
|
+
// ── AgentOutcome + heuristicOutcome ────────────────────────────────────────────
|
|
91
|
+
export { heuristicOutcome } from './outcome'
|
|
92
|
+
export type { AgentOutcome, OutcomeResolver } from './outcome'
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentOutcome — the distilled feed projection of a finished AgentThread.
|
|
3
|
+
*
|
|
4
|
+
* A thread's raw transcript (prompt text, reasoning, tool calls) must never render in a
|
|
5
|
+
* multi-thread feed — only a short, past-tense summary of what happened. AgentOutcome is
|
|
6
|
+
* that DIFFERENT, smaller shape: a title, a one-line summary, and a status. Producing one
|
|
7
|
+
* is the job of an OutcomeResolver (typically an LLM-backed summarizer wired by the
|
|
8
|
+
* consumer); heuristicOutcome below is a text-only fallback for demos and early wiring.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import type { AgentOutcome } from 'basalt-ui/agent'
|
|
12
|
+
*
|
|
13
|
+
* const outcome: AgentOutcome = {
|
|
14
|
+
* title: 'Refactor auth middleware',
|
|
15
|
+
* summary: 'Extracted the token check into a shared guard and added tests.',
|
|
16
|
+
* status: 'done',
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentPart } from './parts'
|
|
20
|
+
import type { AgentThread } from './thread'
|
|
21
|
+
|
|
22
|
+
// ── AgentOutcome ──────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A distilled outcome for one thread — what shows in a multi-thread feed. `title` is the
|
|
26
|
+
* subject/intent (capped ~48 chars); `summary` is a concrete, past-tense description of what
|
|
27
|
+
* happened (capped ~88 chars); `status` drives the feed's visual treatment.
|
|
28
|
+
*
|
|
29
|
+
* `status` is the TERMINAL subset of `ThreadStatus` (see `./thread`): only the three outcomes a
|
|
30
|
+
* finished turn can resolve to. It deliberately excludes `ThreadStatus`'s in-flight/unresolved
|
|
31
|
+
* members (`'pending'`, `'streaming'`, `'interrupted'`) — an `AgentOutcome` only exists once a
|
|
32
|
+
* turn has settled, so those never apply here.
|
|
33
|
+
*
|
|
34
|
+
* Note there are THREE overlapping status-shaped unions in this module family, one per layer:
|
|
35
|
+
* `StreamStatus` (single-turn stream lifecycle, `./use-agent-stream`), `ThreadStatus` (persisted
|
|
36
|
+
* thread lifecycle, `./thread`), and this `AgentOutcome['status']` (feed-facing terminal
|
|
37
|
+
* projection). They are related but not identical — `StreamStatus`'s `'idle'` (no turn in
|
|
38
|
+
* flight) corresponds to `ThreadStatus`'s `'pending'` (thread created, no turn started yet); the
|
|
39
|
+
* literal rename from `'idle'` to `'pending'` is intentionally deferred since it would ripple
|
|
40
|
+
* into `use-agent-stream.ts` and its call sites.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const outcome: AgentOutcome = { title: 'New chat', summary: '', status: 'done' }
|
|
44
|
+
*/
|
|
45
|
+
export type AgentOutcome = {
|
|
46
|
+
readonly title: string
|
|
47
|
+
readonly summary: string
|
|
48
|
+
readonly status: 'done' | 'attention' | 'error'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ── OutcomeResolver ───────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A function that distills a finished (or in-flight) AgentThread into an AgentOutcome for
|
|
55
|
+
* the feed. Consumers typically wire this to an LLM call that reads the transcript and
|
|
56
|
+
* returns a short subject + summary — hence the Promise return, so a resolver can await a
|
|
57
|
+
* network call.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const resolveOutcome: OutcomeResolver = async (thread) => {
|
|
61
|
+
* const summary = await summarizeTranscript(thread.messages)
|
|
62
|
+
* return { title: summary.title, summary: summary.body, status: 'done' }
|
|
63
|
+
* }
|
|
64
|
+
*/
|
|
65
|
+
export type OutcomeResolver<TPart = AgentPart> = (
|
|
66
|
+
thread: AgentThread<TPart>,
|
|
67
|
+
) => AgentOutcome | Promise<AgentOutcome>
|
|
68
|
+
|
|
69
|
+
// ── heuristicOutcome ──────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
const TITLE_MAX = 48
|
|
72
|
+
const SUMMARY_MAX = 88
|
|
73
|
+
|
|
74
|
+
/** Trim `text` to at most `max` characters, appending an ellipsis when cut. */
|
|
75
|
+
function truncate(text: string, max: number): string {
|
|
76
|
+
if (text.length <= max) return text
|
|
77
|
+
return `${text.slice(0, max - 1).trimEnd()}…`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The leading sentence/clause of `text` (up to the first `.`, `!`, or `?`), trimmed. */
|
|
81
|
+
function firstClause(text: string): string {
|
|
82
|
+
const match = text.match(/^[^.!?]+[.!?]?/)
|
|
83
|
+
return (match?.[0] ?? text).trim()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* DEMO-ONLY provisional heuristic — never the production path. Coalesces the last assistant
|
|
88
|
+
* message's text parts into one string and derives a title/summary/status from it with no
|
|
89
|
+
* model call. Real apps should wire an OutcomeResolver backed by an LLM summarizer; this
|
|
90
|
+
* exists purely so a feed has something to render before that wiring lands.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* const outcome = heuristicOutcome(thread)
|
|
94
|
+
* // { title: 'Fixed the flaky test', summary: 'Fixed the flaky test by awaiting…', status: 'done' }
|
|
95
|
+
*/
|
|
96
|
+
export function heuristicOutcome(thread: AgentThread): AgentOutcome {
|
|
97
|
+
const lastAssistant = thread.messages.toReversed().find((message) => message.role === 'assistant')
|
|
98
|
+
if (lastAssistant === undefined) {
|
|
99
|
+
return { title: 'New chat', summary: '', status: 'done' }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const text = lastAssistant.parts
|
|
103
|
+
.filter((part): part is Extract<AgentPart, { type: 'text' }> => part.type === 'text')
|
|
104
|
+
.map((part) => part.text)
|
|
105
|
+
.join('')
|
|
106
|
+
.trim()
|
|
107
|
+
|
|
108
|
+
if (text.length === 0) {
|
|
109
|
+
return { title: 'New chat', summary: '', status: 'done' }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const lastPart = lastAssistant.parts[lastAssistant.parts.length - 1]
|
|
113
|
+
const status: AgentOutcome['status'] = lastPart?.type === 'error' ? 'error' : 'done'
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
title: truncate(firstClause(text), TITLE_MAX),
|
|
117
|
+
summary: truncate(text, SUMMARY_MAX),
|
|
118
|
+
status,
|
|
119
|
+
}
|
|
120
|
+
}
|