rift-ds 1.32.0 → 1.34.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/README.md +4 -4
- package/behaviors/chat-card.css +11 -6
- package/behaviors/clipboard.d.ts +7 -0
- package/behaviors/clipboard.js +35 -0
- package/behaviors/headingSlug.d.ts +8 -0
- package/behaviors/headingSlug.js +4 -0
- package/behaviors/shell.css +64 -0
- package/behaviors/syncedChoice.d.ts +2 -0
- package/behaviors/syncedChoice.js +48 -0
- package/behaviors/useLayer.d.ts +15 -2
- package/behaviors/useLayer.js +3 -2
- package/bin/templates/blocks/app/guide/PageFeedback.tsx +55 -0
- package/bin/templates/blocks/app/guide/page.module.css +94 -0
- package/bin/templates/blocks/app/guide/page.tsx +168 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +3 -1
- package/bin/templates/blocks/components/blocks/AppShell.tsx +8 -0
- package/bin/templates/blocks/components/blocks/DocsShell.module.css +18 -0
- package/bin/templates/blocks/components/blocks/DocsShell.tsx +179 -0
- package/bin/templates/blocks/registry.json +13 -0
- package/chat/AssistantTurn.d.ts +2 -0
- package/chat/AssistantTurn.js +18 -7
- package/chat/ChatProvider.js +14 -0
- package/chat/ChatWidget.css +10 -0
- package/chat/ChatWidget.d.ts +7 -3
- package/chat/ChatWidget.js +6 -3
- package/chat/agentState.d.ts +2 -1
- package/chat/agentState.js +4 -1
- package/chat/awaiting.d.ts +19 -0
- package/chat/awaiting.js +21 -0
- package/chat/context.d.ts +4 -0
- package/chat/index.d.ts +1 -0
- package/chat/index.js +3 -1
- package/chat/server.d.ts +8 -3
- package/chat/server.js +1 -1
- package/code/highlight.d.ts +4 -0
- package/code/highlight.js +34 -0
- package/code/index.d.ts +16 -0
- package/code/index.js +23 -0
- package/components/ActionCard/ActionCard.css +3 -3
- package/components/AgentStatus/AgentStatus.css +114 -22
- package/components/AgentStatus/AgentStatus.d.ts +10 -7
- package/components/AgentStatus/AgentStatus.js +10 -0
- package/components/AiButton/AiButton.d.ts +3 -3
- package/components/AnchorNav/AnchorNav.d.ts +29 -3
- package/components/AnchorNav/AnchorNav.js +69 -5
- package/components/AppLayout/AppLayout.css +8 -4
- package/components/AppLayout/AppLayout.d.ts +13 -3
- package/components/AppLayout/AppLayout.js +2 -0
- package/components/ArtifactPanel/ArtifactPanel.css +46 -0
- package/components/ArtifactPanel/ArtifactPanel.d.ts +14 -4
- package/components/ArtifactPanel/ArtifactPanel.js +8 -5
- package/components/BackToTop/BackToTop.css +28 -0
- package/components/BackToTop/BackToTop.d.ts +28 -0
- package/components/BackToTop/BackToTop.js +47 -0
- package/components/BentoTile/BentoTile.css +3 -0
- package/components/CodeBlock/CodeBlock.css +63 -24
- package/components/CodeBlock/CodeBlock.d.ts +62 -6
- package/components/CodeBlock/CodeBlock.js +90 -48
- package/components/Composer/Composer.css +14 -9
- package/components/Composer/Composer.d.ts +10 -8
- package/components/Composer/Composer.js +2 -1
- package/components/CopyButton/CopyButton.d.ts +42 -0
- package/components/CopyButton/CopyButton.js +72 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +2 -2
- package/components/DescriptionList/DescriptionListCopy.js +7 -35
- package/components/Figure/Figure.css +26 -0
- package/components/Figure/Figure.d.ts +10 -1
- package/components/Figure/Figure.js +15 -3
- package/components/Heading/Heading.css +43 -0
- package/components/Heading/Heading.d.ts +14 -3
- package/components/Heading/Heading.js +22 -4
- package/components/HoverCard/HoverCard.js +1 -0
- package/components/Link/Link.css +38 -0
- package/components/Link/Link.d.ts +3 -3
- package/components/Link/Link.js +1 -1
- package/components/Menubar/Menubar.css +82 -0
- package/components/Menubar/Menubar.d.ts +40 -0
- package/components/Menubar/Menubar.js +97 -0
- package/components/MessageCard/MessageCard.css +1 -1
- package/components/NavList/NavList.css +197 -0
- package/components/NavList/NavList.d.ts +54 -6
- package/components/NavList/NavList.js +136 -8
- package/components/Pagination/Pagination.css +80 -0
- package/components/Pagination/Pagination.d.ts +29 -3
- package/components/Pagination/Pagination.js +49 -5
- package/components/Rating/Rating.css +26 -0
- package/components/Rating/Rating.d.ts +18 -5
- package/components/Rating/Rating.js +16 -7
- package/components/SectionTitle/SectionTitle.css +36 -0
- package/components/SectionTitle/SectionTitle.d.ts +10 -1
- package/components/SectionTitle/SectionTitle.js +7 -2
- package/components/ShaderScene/ShaderScene.d.ts +2 -1
- package/components/ShaderScene/ShaderScene.js +20 -2
- package/components/SiteFooter/SiteFooter.css +157 -0
- package/components/SiteFooter/SiteFooter.d.ts +53 -0
- package/components/SiteFooter/SiteFooter.js +61 -0
- package/components/SiteHeader/SiteHeader.css +106 -4
- package/components/SiteHeader/SiteHeader.d.ts +25 -2
- package/components/SiteHeader/SiteHeader.js +46 -8
- package/components/SiteLayout/SiteLayout.css +361 -0
- package/components/SiteLayout/SiteLayout.d.ts +103 -0
- package/components/SiteLayout/SiteLayout.js +68 -0
- package/components/SourceTrail/SourceTrail.css +1 -1
- package/components/Table/Table.css +14 -0
- package/components/Table/Table.d.ts +2 -0
- package/components/Table/Table.js +1 -1
- package/components/ToolCall/ToolCall.css +2 -2
- package/components/Tooltip/Tooltip.js +1 -0
- package/components/UsageCard/UsageCard.css +4 -3
- package/components/keyboard-patterns.json.d.ts +57 -0
- package/components/keyboard-patterns.json.js +1 -1
- package/components/registry.json +89 -19
- package/components/registry.json.d.ts +89 -19
- package/components/registry.json.js +1 -1
- package/index.d.ts +5 -0
- package/index.js +14 -1
- package/package.json +14 -2
- package/tokens/breakpoints.js +3 -3
- package/tokens/registry.json +5 -0
- package/tokens/registry.json.d.ts +5 -0
- package/tokens/registry.json.js +1 -1
- package/tokens/tokens-dark.css +12 -0
- package/tokens/tokens-light.css +12 -0
- package/tokens/values.json.js +1 -1
|
@@ -41,6 +41,13 @@ import styles from './AppShell.module.css';
|
|
|
41
41
|
*/
|
|
42
42
|
const SHELL_LAYOUT: AppSidebarLayout = 'floating';
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* How wide the page runs, apart from the mode: `contained` centres the
|
|
46
|
+
* content column at 1440px, `full` runs it the whole width the mode leaves.
|
|
47
|
+
* Any mode takes either.
|
|
48
|
+
*/
|
|
49
|
+
const CONTENT_WIDTH: 'contained' | 'full' = 'contained';
|
|
50
|
+
|
|
44
51
|
/** The product's name, shown beside the logo in the sidebar. */
|
|
45
52
|
const PRODUCT_NAME = 'Acme';
|
|
46
53
|
|
|
@@ -101,6 +108,7 @@ export function AppShell({ activeKey, breadcrumb, title, actions, children }: Ap
|
|
|
101
108
|
<div
|
|
102
109
|
className={styles.shell}
|
|
103
110
|
data-ds-shell={SHELL_LAYOUT}
|
|
111
|
+
data-ds-width={CONTENT_WIDTH}
|
|
104
112
|
>
|
|
105
113
|
<AppSidebar
|
|
106
114
|
sections={NAV_SECTIONS}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The docs shell's own touches. SiteLayout owns the columns, the sticky
|
|
3
|
+
* sidebar, the widths, the reading measure and the fold; every value here
|
|
4
|
+
* is a rift-ds token.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.brand {
|
|
8
|
+
font-family: var(--font-title-body-family);
|
|
9
|
+
font-size: var(--font-title-body-size);
|
|
10
|
+
font-weight: var(--font-title-body-weight);
|
|
11
|
+
color: var(--color-text-primary);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.article {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: var(--gap-500);
|
|
18
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
/**
|
|
3
|
+
* The documentation shell the docs block sits in: rift-ds's SiteLayout
|
|
4
|
+
* holding a site header (search and colour mode), a long sidebar of pages,
|
|
5
|
+
* the article with its breadcrumb, an on-this-page rail read from the
|
|
6
|
+
* article's headings, and a sitemap footer. This file is yours: rename the
|
|
7
|
+
* product, replace the navigation and the footer with your own, and wire
|
|
8
|
+
* the search to your command palette.
|
|
9
|
+
*
|
|
10
|
+
* Two settings below lay it out: PAGE_WIDTH (the columns contained at
|
|
11
|
+
* 1440px or full width) and SIDEBAR_DOCK, which moves the header, the
|
|
12
|
+
* sidebar and the footer as one frame: docked to the window's edge, the
|
|
13
|
+
* header and the footer run full width with it; beside the content, all
|
|
14
|
+
* three follow the page. SiteLayout's readingWidth holds the article to a
|
|
15
|
+
* reading measure while the page is contained.
|
|
16
|
+
*
|
|
17
|
+
* Responsive by construction: below 1152px the on-this-page rail gives
|
|
18
|
+
* way, and below 960px the sidebar leaves the page and the header's menu
|
|
19
|
+
* carries its pages (each section's drawerItems), so there is one menu.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { ReactNode } from 'react';
|
|
23
|
+
import { AnchorNav } from 'rift-ds/components/AnchorNav/AnchorNav';
|
|
24
|
+
import { BackToTop } from 'rift-ds/components/BackToTop/BackToTop';
|
|
25
|
+
import { Breadcrumb, type BreadcrumbItem } from 'rift-ds/components/Breadcrumb/Breadcrumb';
|
|
26
|
+
import { CommandPaletteTrigger } from 'rift-ds/components/CommandPaletteTrigger/CommandPaletteTrigger';
|
|
27
|
+
import { NavList, type NavListEntry } from 'rift-ds/components/NavList/NavList';
|
|
28
|
+
import { SiteFooter, type SiteFooterColumn } from 'rift-ds/components/SiteFooter/SiteFooter';
|
|
29
|
+
import { SiteHeader, type SiteHeaderSection } from 'rift-ds/components/SiteHeader/SiteHeader';
|
|
30
|
+
import { SiteLayout } from 'rift-ds/components/SiteLayout/SiteLayout';
|
|
31
|
+
import { ThemeToggle } from 'rift-ds/components/ThemeToggle/ThemeToggle';
|
|
32
|
+
import styles from './DocsShell.module.css';
|
|
33
|
+
|
|
34
|
+
/** How wide the page's columns run: centred at 1440px, or the full window. */
|
|
35
|
+
const PAGE_WIDTH: 'contained' | 'full' = 'full';
|
|
36
|
+
|
|
37
|
+
/** Where the sidebar sits, the header and the footer moving with it: docked to the window's start edge, or beside the content in the page's row. */
|
|
38
|
+
const SIDEBAR_DOCK: 'edge' | 'content' = 'edge';
|
|
39
|
+
|
|
40
|
+
/** The product's name, shown in the header and the footer. */
|
|
41
|
+
const PRODUCT_NAME = 'Acme';
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/** Every page of the docs, in sections; a long list scrolls inside the sidebar. */
|
|
45
|
+
const COMPONENT_PAGES = [
|
|
46
|
+
'Accordion', 'Alert', 'Avatar', 'Badge', 'Breadcrumb', 'Button', 'Calendar', 'Card', 'Checkbox', 'Code block',
|
|
47
|
+
'Combobox', 'Dialog', 'Drawer', 'Dropdown menu', 'Field', 'Input', 'Menubar', 'Pagination', 'Popover', 'Select',
|
|
48
|
+
'Slider', 'Switch', 'Table', 'Tabs', 'Toast', 'Tooltip',
|
|
49
|
+
];
|
|
50
|
+
const NAV: NavListEntry[] = [
|
|
51
|
+
{
|
|
52
|
+
type: 'section',
|
|
53
|
+
label: 'Getting started',
|
|
54
|
+
items: [
|
|
55
|
+
{ label: 'Introduction', href: '#introduction' },
|
|
56
|
+
{ label: 'Installation', href: '#installation' },
|
|
57
|
+
{
|
|
58
|
+
label: 'Theming',
|
|
59
|
+
href: '#theming',
|
|
60
|
+
items: [
|
|
61
|
+
{ label: 'Colours', href: '#theming-colours' },
|
|
62
|
+
{ label: 'Dark mode', href: '#theming-dark-mode' },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{ label: 'CLI', href: '#cli', badge: 'New' },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'section',
|
|
70
|
+
label: 'Components',
|
|
71
|
+
items: COMPONENT_PAGES.map((label) => ({ label, href: `#${label.toLowerCase().replace(/ /g, '-')}` })),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'section',
|
|
75
|
+
label: 'Guides',
|
|
76
|
+
collapsible: true,
|
|
77
|
+
items: [
|
|
78
|
+
{ label: 'Forms', href: '#guide-forms' },
|
|
79
|
+
{ label: 'Server rendering', href: '#guide-server-rendering' },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The header's top-level sections. Each lists its pages as drawerItems: on a
|
|
86
|
+
* phone the sidebar leaves the page and the header's one menu carries them.
|
|
87
|
+
*/
|
|
88
|
+
const SECTIONS: SiteHeaderSection[] = [
|
|
89
|
+
{
|
|
90
|
+
id: 'docs',
|
|
91
|
+
label: 'Docs',
|
|
92
|
+
href: '#docs',
|
|
93
|
+
drawerItems: [
|
|
94
|
+
{ label: 'Introduction', href: '#introduction' },
|
|
95
|
+
{ label: 'Installation', href: '#installation' },
|
|
96
|
+
{ label: 'Theming', href: '#theming' },
|
|
97
|
+
{ label: 'CLI', href: '#cli' },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'components',
|
|
102
|
+
label: 'Components',
|
|
103
|
+
href: '#components',
|
|
104
|
+
drawerItems: COMPONENT_PAGES.map((label) => ({ label, href: `#${label.toLowerCase().replace(/ /g, '-')}` })),
|
|
105
|
+
},
|
|
106
|
+
{ id: 'changelog', label: 'Changelog', href: '#changelog' },
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/** The footer's sitemap. */
|
|
110
|
+
const FOOTER_COLUMNS: SiteFooterColumn[] = [
|
|
111
|
+
{ label: 'Docs', links: [{ label: 'Introduction', href: '#introduction' }, { label: 'Installation', href: '#installation' }] },
|
|
112
|
+
{ label: 'Components', links: [{ label: 'Button', href: '#button' }, { label: 'Table', href: '#table' }] },
|
|
113
|
+
{ label: 'Community', links: [{ label: 'Discussions', href: 'https://example.com/discussions', external: true }] },
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
export interface DocsShellProps {
|
|
117
|
+
/** The href of this page, which the sidebar marks as current. */
|
|
118
|
+
currentHref: string;
|
|
119
|
+
/** The page's place in the docs, ending with the page itself. */
|
|
120
|
+
breadcrumb: BreadcrumbItem[];
|
|
121
|
+
/** The article: its h1, then its sections, each opened by an h2. */
|
|
122
|
+
children: ReactNode;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function DocsShell({ currentHref, breadcrumb, children }: DocsShellProps) {
|
|
126
|
+
return (
|
|
127
|
+
<SiteLayout
|
|
128
|
+
width={PAGE_WIDTH}
|
|
129
|
+
readingWidth
|
|
130
|
+
sidebarDock={SIDEBAR_DOCK}
|
|
131
|
+
mainId="docs-article"
|
|
132
|
+
header={
|
|
133
|
+
<SiteHeader
|
|
134
|
+
brand={<span className={styles.brand}>{PRODUCT_NAME}</span>}
|
|
135
|
+
sections={SECTIONS}
|
|
136
|
+
currentHref="#docs"
|
|
137
|
+
foldBelow="tablet"
|
|
138
|
+
actions={
|
|
139
|
+
<>
|
|
140
|
+
{/* Wire it to your command palette: CommandPalette from rift-ds,
|
|
141
|
+
opened from here and from Cmd+K. */}
|
|
142
|
+
<CommandPaletteTrigger label="Search the docs" size="compact" />
|
|
143
|
+
<ThemeToggle showLabels={false} size="compact" />
|
|
144
|
+
</>
|
|
145
|
+
}
|
|
146
|
+
condensedActions={
|
|
147
|
+
<>
|
|
148
|
+
{/* The same two at their narrowest, for a phone: the bar uses
|
|
149
|
+
these before it folds. */}
|
|
150
|
+
<CommandPaletteTrigger label="Search the docs" size="compact" iconOnly />
|
|
151
|
+
<ThemeToggle size="compact" cycle />
|
|
152
|
+
</>
|
|
153
|
+
}
|
|
154
|
+
/>
|
|
155
|
+
}
|
|
156
|
+
sidebar={
|
|
157
|
+
<NavList
|
|
158
|
+
items={NAV}
|
|
159
|
+
size="compact"
|
|
160
|
+
scrollable
|
|
161
|
+
currentHref={currentHref}
|
|
162
|
+
/>
|
|
163
|
+
}
|
|
164
|
+
aside={<AnchorNav fromHeadings={{ root: '#docs-article' }} />}
|
|
165
|
+
footer={
|
|
166
|
+
<SiteFooter
|
|
167
|
+
brand={PRODUCT_NAME}
|
|
168
|
+
description="Components and guides for building the Acme app."
|
|
169
|
+
columns={FOOTER_COLUMNS}
|
|
170
|
+
legal={`© ${new Date().getFullYear()} ${PRODUCT_NAME}.`}
|
|
171
|
+
/>
|
|
172
|
+
}
|
|
173
|
+
>
|
|
174
|
+
<Breadcrumb items={breadcrumb} />
|
|
175
|
+
<div className={styles.article}>{children}</div>
|
|
176
|
+
<BackToTop focusTarget="docs-article" />
|
|
177
|
+
</SiteLayout>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -72,6 +72,19 @@
|
|
|
72
72
|
"app/shader/page.tsx",
|
|
73
73
|
"app/shader/page.module.css"
|
|
74
74
|
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "docs",
|
|
78
|
+
"label": "Docs",
|
|
79
|
+
"description": "A documentation page: a site header, a long sidebar of pages, an article with tabbed install commands and live examples, an on-this-page rail and a footer.",
|
|
80
|
+
"route": "/guide",
|
|
81
|
+
"files": [
|
|
82
|
+
"components/blocks/DocsShell.tsx",
|
|
83
|
+
"components/blocks/DocsShell.module.css",
|
|
84
|
+
"app/guide/page.tsx",
|
|
85
|
+
"app/guide/page.module.css",
|
|
86
|
+
"app/guide/PageFeedback.tsx"
|
|
87
|
+
]
|
|
75
88
|
}
|
|
76
89
|
]
|
|
77
90
|
}
|
package/chat/AssistantTurn.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface AssistantTurnLabels {
|
|
|
10
10
|
};
|
|
11
11
|
/** The reasoning disclosure's summary once thinking is over, given the seconds it took when known. */
|
|
12
12
|
reasoning?: (durationSeconds: number | undefined) => string;
|
|
13
|
+
/** The status line while a card in the reply waits on the reader's Confirm. Defaults to "Waiting for approval". */
|
|
14
|
+
awaitingApproval?: string;
|
|
13
15
|
/** The question card a reply ends in. */
|
|
14
16
|
questionCard?: Partial<QuestionCardLabels>;
|
|
15
17
|
/** The follow-up row's hidden "(chosen)" text. */
|
package/chat/AssistantTurn.js
CHANGED
|
@@ -8,6 +8,7 @@ import { CodeBlock } from "../components/CodeBlock/CodeBlock.js";
|
|
|
8
8
|
import { ChatMessage } from "../components/ChatMessage/ChatMessage.js";
|
|
9
9
|
import { Prose } from "../components/Prose/Prose.js";
|
|
10
10
|
import { Reasoning } from "../components/Reasoning/Reasoning.js";
|
|
11
|
+
import { TurnIdContext } from "./awaiting.js";
|
|
11
12
|
import { useChatWidget } from "./context.js";
|
|
12
13
|
import { DOCK_QUERY } from "./queries.js";
|
|
13
14
|
import { FollowupSuggestions } from "./FollowupSuggestions.js";
|
|
@@ -15,6 +16,8 @@ import { ResponseActions } from "./ResponseActions.js";
|
|
|
15
16
|
import { turnCards } from "./artifacts.js";
|
|
16
17
|
import { TurnCard } from "./TurnContent.js";
|
|
17
18
|
import { TurnQuestion } from "./TurnQuestion.js";
|
|
19
|
+
const DEFAULT_REASONING_LABEL = (durationSeconds) => durationSeconds !== void 0 ? `Thought for ${durationSeconds}s` : "Thought process";
|
|
20
|
+
const DEFAULT_AWAITING_APPROVAL_LABEL = "Waiting for approval";
|
|
18
21
|
const CodeBlockLabelsContext = createContext(void 0);
|
|
19
22
|
function MarkdownLink({ href, children }) {
|
|
20
23
|
const { view, setOpen, renderLink, isInternalHref } = useChatWidget();
|
|
@@ -66,9 +69,11 @@ function AssistantTurn({
|
|
|
66
69
|
const leadCards = allCards.filter((card) => card.lead);
|
|
67
70
|
const cards = allCards.filter((card) => !card.lead);
|
|
68
71
|
const led = leadCards.length > 0;
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
+
const showReasoning = thinking || tracePoints.length > 0 || led || durationSeconds !== void 0;
|
|
73
|
+
const { turns, live: liveTurn, freshFollowupsId, awaiting: awaitingCards } = useChatWidget();
|
|
74
|
+
const turnId = (live ?? turn)?.id ?? null;
|
|
75
|
+
let awaiting = false;
|
|
76
|
+
for (const id of awaitingCards.values()) if (id === turnId) awaiting = true;
|
|
72
77
|
const followupsPending = !!turn && turn.text !== "" && !!turn.exchangeId && !turn.followups && !turn.question && !liveTurn && turns[turns.length - 1]?.id === turn.id;
|
|
73
78
|
return /* @__PURE__ */ jsx(
|
|
74
79
|
ChatMessage,
|
|
@@ -86,15 +91,21 @@ function AssistantTurn({
|
|
|
86
91
|
chosenLabel: labels?.promptSuggestions?.chosenLabel
|
|
87
92
|
}
|
|
88
93
|
) : followupsPending && turn ? /* @__PURE__ */ jsx(FollowupSuggestions, { turnId: turn.id, suggestions: [], pending: true }) : void 0,
|
|
89
|
-
children: /* @__PURE__ */ jsxs("div", { className: "ds-chat-widget__response", children: [
|
|
94
|
+
children: /* @__PURE__ */ jsx(TurnIdContext.Provider, { value: turnId, children: /* @__PURE__ */ jsxs("div", { className: "ds-chat-widget__response", children: [
|
|
90
95
|
showReasoning && /* @__PURE__ */ jsx(
|
|
91
96
|
Reasoning,
|
|
92
97
|
{
|
|
93
98
|
streaming: thinking && !led,
|
|
94
99
|
summaryOnly: tracePoints.length === 0,
|
|
95
100
|
duration: durationSeconds,
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
summary: thinking && live ? /* @__PURE__ */ jsx(AgentStatus, { state: "working", label: live.statusLabel }) : awaiting ? /* @__PURE__ */ jsx(AgentStatus, { state: "waiting", label: labels?.awaitingApproval ?? DEFAULT_AWAITING_APPROVAL_LABEL }) : /* @__PURE__ */ jsx(
|
|
102
|
+
AgentStatus,
|
|
103
|
+
{
|
|
104
|
+
state: source?.outcome === "failed" ? "error" : "done",
|
|
105
|
+
className: "ds-chat-widget__thought",
|
|
106
|
+
label: (labels?.reasoning ?? DEFAULT_REASONING_LABEL)(durationSeconds)
|
|
107
|
+
}
|
|
108
|
+
),
|
|
98
109
|
children: tracePoints.length > 0 && /* @__PURE__ */ jsx("ul", { children: tracePoints.map((point, index) => /* @__PURE__ */ jsx("li", { children: point }, `${index}-${point.slice(0, 24)}`)) })
|
|
99
110
|
}
|
|
100
111
|
),
|
|
@@ -103,7 +114,7 @@ function AssistantTurn({
|
|
|
103
114
|
cards.map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index)),
|
|
104
115
|
text !== "" && /* @__PURE__ */ jsx(CodeBlockLabelsContext.Provider, { value: labels?.codeBlock, children: /* @__PURE__ */ jsx(Prose, { children: /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: markdownComponents, children: text }) }) }),
|
|
105
116
|
turn?.question && /* @__PURE__ */ jsx(TurnQuestion, { turn, labels: labels?.questionCard })
|
|
106
|
-
] })
|
|
117
|
+
] }) })
|
|
107
118
|
}
|
|
108
119
|
);
|
|
109
120
|
}
|
package/chat/ChatProvider.js
CHANGED
|
@@ -72,6 +72,16 @@ function ChatProvider({
|
|
|
72
72
|
const target = useMemo(() => followupTarget(chat.turns), [chat.turns]);
|
|
73
73
|
const askedRef = useRef(/* @__PURE__ */ new Set());
|
|
74
74
|
const [freshFollowupsId, setFreshFollowupsId] = useState(null);
|
|
75
|
+
const [awaiting, setAwaitingMap] = useState(() => /* @__PURE__ */ new Map());
|
|
76
|
+
const setAwaiting = useCallback((key, turnId) => {
|
|
77
|
+
setAwaitingMap((current) => {
|
|
78
|
+
if ((current.get(key) ?? null) === turnId) return current;
|
|
79
|
+
const next = new Map(current);
|
|
80
|
+
if (turnId === null) next.delete(key);
|
|
81
|
+
else next.set(key, turnId);
|
|
82
|
+
return next;
|
|
83
|
+
});
|
|
84
|
+
}, []);
|
|
75
85
|
useEffect(() => {
|
|
76
86
|
if (!target || askedRef.current.has(target.id)) return;
|
|
77
87
|
askedRef.current.add(target.id);
|
|
@@ -176,6 +186,8 @@ function ChatProvider({
|
|
|
176
186
|
setStarterRevealKey,
|
|
177
187
|
starterSeed,
|
|
178
188
|
freshFollowupsId,
|
|
189
|
+
awaiting,
|
|
190
|
+
setAwaiting,
|
|
179
191
|
view,
|
|
180
192
|
setView,
|
|
181
193
|
placement,
|
|
@@ -206,6 +218,8 @@ function ChatProvider({
|
|
|
206
218
|
starterRevealKey,
|
|
207
219
|
starterSeed,
|
|
208
220
|
freshFollowupsId,
|
|
221
|
+
awaiting,
|
|
222
|
+
setAwaiting,
|
|
209
223
|
view,
|
|
210
224
|
placement,
|
|
211
225
|
setPlacement,
|
package/chat/ChatWidget.css
CHANGED
|
@@ -510,6 +510,16 @@
|
|
|
510
510
|
gap: var(--gap-500);
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
/* The finished reasoning line: the tick keeps the positive colour and the
|
|
514
|
+
words go back to the quiet summary they were, in the trigger's own face
|
|
515
|
+
and colour, so the mark is the only thing on the line that says done. */
|
|
516
|
+
.ds-chat-widget__thought.ds-agent-status {
|
|
517
|
+
--ds-agent-label-color: inherit;
|
|
518
|
+
|
|
519
|
+
font: inherit;
|
|
520
|
+
letter-spacing: inherit;
|
|
521
|
+
}
|
|
522
|
+
|
|
513
523
|
/* No divider: the composer floats free of the transcript. */
|
|
514
524
|
.ds-chat-widget__footer {
|
|
515
525
|
display: flex;
|
package/chat/ChatWidget.d.ts
CHANGED
|
@@ -112,8 +112,8 @@ export interface ChatWidgetProps {
|
|
|
112
112
|
questionsPlaceholder?: string;
|
|
113
113
|
/** Show the conversation starters on the welcome screen. */
|
|
114
114
|
showStarters?: boolean;
|
|
115
|
-
/** The header mark
|
|
116
|
-
logo?: string | null;
|
|
115
|
+
/** The header mark: an image src, or a node drawn as given, such as an inline SVG that reads the theme's tokens. Null (the default) shows the name alone. */
|
|
116
|
+
logo?: string | ReactNode | null;
|
|
117
117
|
/** The welcome screen's line under the greeting. */
|
|
118
118
|
tagline?: string;
|
|
119
119
|
/** The conversation starters: a few pre-written questions. Each must fit the chip budget (SUGGESTION_MAX_CHARS); one that does not is dropped rather than clipped. */
|
|
@@ -124,6 +124,8 @@ export interface ChatWidgetProps {
|
|
|
124
124
|
startersPending?: boolean;
|
|
125
125
|
/** Replaces the composer's leading actions (the model picker). */
|
|
126
126
|
composerActions?: ReactNode;
|
|
127
|
+
/** The composer's gradient ring, Composer's `aiGlow`: `'streaming'` (the default) lights it only while a reply is in flight, `true` also on focus, `false` never. */
|
|
128
|
+
composerGlow?: boolean | 'streaming';
|
|
127
129
|
/** The models the picker offers. The pick rides on each send as a wire value; the server resolves it. Omit for no picker. */
|
|
128
130
|
models?: ChatModelOption[];
|
|
129
131
|
/** The picker's selection before the server has reported its default. Defaults to the first model. */
|
|
@@ -252,6 +254,8 @@ export interface ChatWidgetProps {
|
|
|
252
254
|
pastedTextLabel?: string;
|
|
253
255
|
/** The reasoning disclosure's summary once the thinking is over, given the seconds it took when known. Defaults to "Thought for <n>s", or "Thought process" with no duration. */
|
|
254
256
|
reasoningLabel?: (durationSeconds: number | undefined) => string;
|
|
257
|
+
/** A reply's status line while a card in it waits on the reader's Confirm. Defaults to "Waiting for approval". */
|
|
258
|
+
awaitingApprovalLabel?: string;
|
|
255
259
|
/** The composer's words, over Composer's English defaults: the attach button ("Attach files"), the drop overlay on the shell ("Drop files to attach"), the queued files' list ("Attachments") and their tiles (`attachmentTileLabels`), the stop button ("Stop generating"), the text field's name ("Message"), and the sentences announced when files or mention matches change. The send button's name is `sendLabel`. */
|
|
256
260
|
composerLabels?: Pick<ComposerProps, 'attachLabel' | 'dropLabel' | 'filesLabel' | 'attachmentTileLabels' | 'stopLabel' | 'aria-label' | 'formatFileAnnouncement' | 'formatMentionAnnouncement'>;
|
|
257
261
|
/** The drop overlay's headline when a file is dragged over the chat with attachments on, over AttachmentDropZone's "Drop files to attach". Its second line is `attachHint`. */
|
|
@@ -287,4 +291,4 @@ export interface ChatWidgetProps {
|
|
|
287
291
|
* a stage card, a whole page). It reads all of its state from ChatProvider,
|
|
288
292
|
* so the conversation is the same object wherever it shows.
|
|
289
293
|
*/
|
|
290
|
-
export declare function ChatWidget({ fullscreenEnabled, layout, backdrop, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, startersPending, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, context: contextProp, contextClearLabel, contextLabel, contextNote, contextPlacement, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, renderAttachmentPreview, onAttachmentDownload, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
|
|
294
|
+
export declare function ChatWidget({ fullscreenEnabled, layout, backdrop, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, startersPending, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, context: contextProp, contextClearLabel, contextLabel, contextNote, contextPlacement, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, awaitingApprovalLabel, composerGlow, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, renderAttachmentPreview, onAttachmentDownload, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
|
package/chat/ChatWidget.js
CHANGED
|
@@ -116,6 +116,8 @@ function ChatWidget({
|
|
|
116
116
|
followupsLabel = "Follow-up questions",
|
|
117
117
|
pastedTextLabel,
|
|
118
118
|
reasoningLabel,
|
|
119
|
+
awaitingApprovalLabel,
|
|
120
|
+
composerGlow = "streaming",
|
|
119
121
|
tabsProps,
|
|
120
122
|
composerLabels,
|
|
121
123
|
attachmentDropZoneLabels,
|
|
@@ -145,10 +147,11 @@ function ChatWidget({
|
|
|
145
147
|
() => ({
|
|
146
148
|
codeBlock: codeBlockLabels,
|
|
147
149
|
reasoning: reasoningLabel,
|
|
150
|
+
awaitingApproval: awaitingApprovalLabel,
|
|
148
151
|
questionCard: questionCardLabels,
|
|
149
152
|
promptSuggestions: promptSuggestionsLabels
|
|
150
153
|
}),
|
|
151
|
-
[codeBlockLabels, reasoningLabel, questionCardLabels, promptSuggestionsLabels]
|
|
154
|
+
[codeBlockLabels, reasoningLabel, awaitingApprovalLabel, questionCardLabels, promptSuggestionsLabels]
|
|
152
155
|
);
|
|
153
156
|
const {
|
|
154
157
|
turns,
|
|
@@ -612,7 +615,7 @@ function ChatWidget({
|
|
|
612
615
|
onClick: () => setThreadsOpen(true)
|
|
613
616
|
}
|
|
614
617
|
),
|
|
615
|
-
logo
|
|
618
|
+
typeof logo === "string" ? /* @__PURE__ */ jsx("img", { src: logo, alt: "", width: 20, height: 20 }) : logo,
|
|
616
619
|
/* @__PURE__ */ jsx("span", { className: "ds-chat-widget__brand-name", children: title })
|
|
617
620
|
] }),
|
|
618
621
|
actions: (
|
|
@@ -685,7 +688,7 @@ function ChatWidget({
|
|
|
685
688
|
disabled: questionsOpen,
|
|
686
689
|
sendLabel,
|
|
687
690
|
inline: composerHasActions ? false : "chat",
|
|
688
|
-
aiGlow:
|
|
691
|
+
aiGlow: composerGlow,
|
|
689
692
|
value: draft,
|
|
690
693
|
onValueChange: setDraft,
|
|
691
694
|
onSubmit: handleSubmit,
|
package/chat/agentState.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { AgentStatusState } from '../components/AgentStatus/AgentStatusPatterns'
|
|
|
7
7
|
* the end of a reply is only reported once.
|
|
8
8
|
*
|
|
9
9
|
* `thinking` until the first words, `working` once words or rich content are
|
|
10
|
-
* arriving, `waiting` while a question stands unanswered
|
|
10
|
+
* arriving, `waiting` while a question stands unanswered or a card waits on
|
|
11
|
+
* the reader's Confirm (see `useTurnAwaiting`), then `done` or
|
|
11
12
|
* `error` for a beat as a reply ends. A reply the visitor stopped, or a chat
|
|
12
13
|
* they reset, goes straight back to `idle`.
|
|
13
14
|
*/
|
package/chat/agentState.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
|
|
|
3
3
|
import { MOTION_FEEDBACK_RESET_MS } from "../tokens/motion.js";
|
|
4
4
|
import { useChatWidget } from "./context.js";
|
|
5
5
|
function useChatAgentState() {
|
|
6
|
-
const { live, turns } = useChatWidget();
|
|
6
|
+
const { live, turns, awaiting } = useChatWidget();
|
|
7
7
|
const [ended, setEnded] = useState(null);
|
|
8
8
|
const last = turns[turns.length - 1];
|
|
9
9
|
const inFlight = live !== null;
|
|
@@ -22,6 +22,9 @@ function useChatAgentState() {
|
|
|
22
22
|
return live.phase === "thinking" && !live.content && !live.cards?.length ? "thinking" : "working";
|
|
23
23
|
}
|
|
24
24
|
if (last?.role === "assistant" && last.question && !last.answers) return "waiting";
|
|
25
|
+
for (const turnId of awaiting.values()) {
|
|
26
|
+
if (turns.some((turn) => turn.id === turnId)) return "waiting";
|
|
27
|
+
}
|
|
25
28
|
return ended ?? "idle";
|
|
26
29
|
}
|
|
27
30
|
export {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The id of the assistant turn a card is drawn in, so a card's wait is recorded against its reply. */
|
|
2
|
+
export declare const TurnIdContext: import('react').Context<string | null>;
|
|
3
|
+
/**
|
|
4
|
+
* Report that the card this is called from waits on the reader, such as a
|
|
5
|
+
* proposed change with Confirm still to press. The wait is recorded once, on
|
|
6
|
+
* the chat provider, and everything that reports the agent reads it from
|
|
7
|
+
* there: the reply's status line reads as waiting for approval, and
|
|
8
|
+
* `useChatAgentState` returns `waiting` for whatever opens the chat, so the
|
|
9
|
+
* two can never disagree. Outside a chat turn it does nothing.
|
|
10
|
+
*
|
|
11
|
+
* Pass the card's own stable `key` when it has one: the wait then outlives
|
|
12
|
+
* the card being unmounted with the panel closed, which is when the opener's
|
|
13
|
+
* state matters most, and ends only when the card says it no longer waits.
|
|
14
|
+
* Without a key the wait ends when the card unmounts.
|
|
15
|
+
*
|
|
16
|
+
* A layout effect, so the line never paints its finished form for a frame
|
|
17
|
+
* before the card's wait is counted.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useTurnAwaiting(awaiting: boolean, key?: string): void;
|
package/chat/awaiting.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContext, useId, useLayoutEffect, createContext } from "react";
|
|
3
|
+
import { ChatWidgetContext } from "./context.js";
|
|
4
|
+
const TurnIdContext = createContext(null);
|
|
5
|
+
function useTurnAwaiting(awaiting, key) {
|
|
6
|
+
const setAwaiting = useContext(ChatWidgetContext)?.setAwaiting;
|
|
7
|
+
const turnId = useContext(TurnIdContext);
|
|
8
|
+
const ownKey = useId();
|
|
9
|
+
const entry = key ?? ownKey;
|
|
10
|
+
const sticky = key !== void 0;
|
|
11
|
+
useLayoutEffect(() => {
|
|
12
|
+
if (!setAwaiting || !turnId) return;
|
|
13
|
+
setAwaiting(entry, awaiting ? turnId : null);
|
|
14
|
+
if (sticky) return;
|
|
15
|
+
return () => setAwaiting(entry, null);
|
|
16
|
+
}, [setAwaiting, turnId, entry, awaiting, sticky]);
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
TurnIdContext,
|
|
20
|
+
useTurnAwaiting
|
|
21
|
+
};
|
package/chat/context.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export interface ChatWidgetContextValue extends ChatState {
|
|
|
47
47
|
starterSeed: number;
|
|
48
48
|
/** The turn whose follow-ups landed most recently in this open session, or null. Its row plays the entrance. */
|
|
49
49
|
freshFollowupsId: string | null;
|
|
50
|
+
/** The cards waiting on the reader's Confirm, by card key, each with the id of the turn it stands in. The one record the reply's status line and `useChatAgentState` both read. Written through `setAwaiting`, usually by `useTurnAwaiting`. */
|
|
51
|
+
awaiting: ReadonlyMap<string, string>;
|
|
52
|
+
/** Record that the card under `key` waits on the reader in the turn `turnId`, or, given `null`, that it no longer does. */
|
|
53
|
+
setAwaiting: (key: string, turnId: string | null) => void;
|
|
50
54
|
view: ChatView;
|
|
51
55
|
setView: (view: ChatView) => void;
|
|
52
56
|
/** The panel's seat: a dock edge or floating. Provider-lifetime, so a reload returns to the host's default. */
|
package/chat/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export { defineAction, planAction, skippedText, createConfirmationMark, sanitise
|
|
|
22
22
|
export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
|
|
23
23
|
export { preloadChatWidget } from './deferredChatWidget';
|
|
24
24
|
export { useChatAgentState } from './agentState';
|
|
25
|
+
export { useTurnAwaiting } from './awaiting';
|
|
25
26
|
export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
|
|
26
27
|
export { ChatTabs, type ChatTabsProps } from './ChatTabs';
|
|
27
28
|
export { ChatAgentPane, type ChatAgentPaneProps } from './ChatAgentPane';
|
package/chat/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { confirmSequence, confirmationLine, createConfirmationMark, defineAction
|
|
|
7
7
|
import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
|
|
8
8
|
import { preloadChatWidget } from "./deferredChatWidget.js";
|
|
9
9
|
import { useChatAgentState } from "./agentState.js";
|
|
10
|
+
import { useTurnAwaiting } from "./awaiting.js";
|
|
10
11
|
import { ChatThreads } from "./ChatThreads.js";
|
|
11
12
|
import { ChatTabs } from "./ChatTabs.js";
|
|
12
13
|
import { ChatAgentPane } from "./ChatAgentPane.js";
|
|
@@ -128,5 +129,6 @@ export {
|
|
|
128
129
|
useHeldHighlight,
|
|
129
130
|
useSelectionFocus,
|
|
130
131
|
useTakeoverViewport,
|
|
131
|
-
useThreads
|
|
132
|
+
useThreads,
|
|
133
|
+
useTurnAwaiting
|
|
132
134
|
};
|
package/chat/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
-
import { ChatCard, ChatFeedbackVerdict, ChatModelOption, ChatPageAction } from './types';
|
|
2
|
+
import { ChatCard, ChatFeedbackVerdict, ChatModelOption, ChatPageAction, ChatTransportMessage } from './types';
|
|
3
3
|
/** What a tool hands back: text for the model, and optionally a card for the visitor. */
|
|
4
4
|
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, planSequence, confirmSequence, defineContext, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, type SequenceStep, type SequencePlan, type ConfirmedStep, type ContextField, type ContextShape, type ContextValues, type ContextSchema, } from './actions';
|
|
5
5
|
export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatSelection, type SelectionKind, type SelectionLimits, type SelectionLinesOptions } from './selectionContext';
|
|
@@ -156,9 +156,14 @@ export interface ChatHandlerOptions {
|
|
|
156
156
|
}) => string | SystemBlocks);
|
|
157
157
|
/**
|
|
158
158
|
* An uncached trailing block built from the request's context, after the
|
|
159
|
-
* cache breakpoint. Defaults to naming the page; return null for none.
|
|
159
|
+
* cache breakpoint. Defaults to naming the page; return null for none. The
|
|
160
|
+
* second argument is the conversation as the handler received it, the
|
|
161
|
+
* latest message last, for a block that answers what the visitor named
|
|
162
|
+
* (a page, a record) as well as where they are.
|
|
160
163
|
*/
|
|
161
|
-
contextBlock?: (path: string
|
|
164
|
+
contextBlock?: (path: string, conversation: {
|
|
165
|
+
messages: readonly ChatTransportMessage[];
|
|
166
|
+
}) => string | null;
|
|
162
167
|
/** The models on offer. The client sends a `value`; the handler calls the matching `id`. */
|
|
163
168
|
models: ChatModelOption[];
|
|
164
169
|
/** The wire value that serves when the budget has headroom and the visitor has not chosen. Defaults to the first model. */
|
package/chat/server.js
CHANGED
|
@@ -224,7 +224,7 @@ function createChatHandler(options) {
|
|
|
224
224
|
typeof options.system === "function" ? options.system({ path: parsed.path }) : options.system
|
|
225
225
|
);
|
|
226
226
|
const toolContext = { context: parsed.path, request: {} };
|
|
227
|
-
const trailing = parsed.path ? contextBlock(parsed.path) : null;
|
|
227
|
+
const trailing = parsed.path ? contextBlock(parsed.path, { messages: parsed.messages }) : null;
|
|
228
228
|
const system = trailing ? [...systemBase, { type: "text", text: trailing }] : systemBase;
|
|
229
229
|
const body = new ReadableStream({
|
|
230
230
|
async start(controller) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CodeLine } from '../components/CodeBlock/CodeBlock';
|
|
2
|
+
export type { CodeLine, CodeToken, CodeTokenRole } from '../components/CodeBlock/CodeBlock';
|
|
3
|
+
/** Highlight `code` as `lang` (any language shiki bundles: "tsx", "css", "bash", "json" and the rest). */
|
|
4
|
+
export declare function highlight(code: string, lang: string): Promise<CodeLine[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createCssVariablesTheme, createHighlighter } from "shiki";
|
|
2
|
+
const PREFIX = "--rift-code-";
|
|
3
|
+
const theme = createCssVariablesTheme({ name: "rift", variablePrefix: PREFIX, variableDefaults: {}, fontStyle: false });
|
|
4
|
+
const ROLES = {
|
|
5
|
+
"token-keyword": "keyword",
|
|
6
|
+
"token-string": "string",
|
|
7
|
+
"token-string-expression": "string",
|
|
8
|
+
"token-link": "string",
|
|
9
|
+
"token-function": "function",
|
|
10
|
+
"token-constant": "constant",
|
|
11
|
+
"token-comment": "comment"
|
|
12
|
+
};
|
|
13
|
+
let highlighter;
|
|
14
|
+
const plain = (code) => code.split("\n").map((text) => [{ content: text }]);
|
|
15
|
+
async function highlight(code, lang) {
|
|
16
|
+
highlighter ??= createHighlighter({ themes: [theme], langs: [] });
|
|
17
|
+
const h = await highlighter;
|
|
18
|
+
try {
|
|
19
|
+
if (!h.getLoadedLanguages().includes(lang)) await h.loadLanguage(lang);
|
|
20
|
+
} catch {
|
|
21
|
+
return plain(code);
|
|
22
|
+
}
|
|
23
|
+
const { tokens } = h.codeToTokens(code, { lang, theme: "rift" });
|
|
24
|
+
return tokens.map(
|
|
25
|
+
(line) => line.map((token) => {
|
|
26
|
+
const match = token.color?.match(/var\(--rift-code-([a-z-]+)\)/);
|
|
27
|
+
const role = match ? ROLES[match[1]] : void 0;
|
|
28
|
+
return role ? { content: token.content, role } : { content: token.content };
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
highlight
|
|
34
|
+
};
|