oneslash-design-system 2.23.0 → 2.24.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 +1 -1
- package/dist/DESIGN.md +13 -2
- package/dist/cases/activity-timeline/activity.d.ts +1 -0
- package/dist/cases/activity-timeline/activity.jsx +43 -0
- package/dist/cases/activity-timeline/versions.d.ts +1 -0
- package/dist/cases/activity-timeline/versions.jsx +130 -0
- package/dist/cases/activity-timeline.md +315 -0
- package/dist/cases/agent-plan-proposal.md +1 -0
- package/dist/cases/ask-page/answered.d.ts +1 -0
- package/dist/cases/ask-page/answered.jsx +240 -0
- package/dist/cases/ask-page/first-visit.d.ts +1 -0
- package/dist/cases/ask-page/first-visit.jsx +118 -0
- package/dist/cases/ask-page.md +542 -0
- package/dist/cases/chart/bars.d.ts +1 -0
- package/dist/cases/chart/bars.jsx +83 -0
- package/dist/cases/chart/lines.d.ts +1 -0
- package/dist/cases/chart/lines.jsx +71 -0
- package/dist/cases/chart.md +258 -0
- package/dist/cases/comment-thread/card.d.ts +1 -0
- package/dist/cases/comment-thread/card.jsx +141 -0
- package/dist/cases/comment-thread/thread.d.ts +1 -0
- package/dist/cases/comment-thread/thread.jsx +87 -0
- package/dist/cases/comment-thread.md +349 -0
- package/dist/cases/dashboard/numbers-first.jsx +62 -1
- package/dist/cases/dashboard.md +75 -3
- package/dist/cases/leaderboard/ranked.d.ts +1 -0
- package/dist/cases/leaderboard/ranked.jsx +44 -0
- package/dist/cases/leaderboard/table.d.ts +1 -0
- package/dist/cases/leaderboard/table.jsx +87 -0
- package/dist/cases/leaderboard.md +177 -0
- package/dist/cases/number-format.md +4 -2
- package/dist/cases/onboarding/checklist.d.ts +1 -0
- package/dist/cases/onboarding/checklist.jsx +92 -0
- package/dist/cases/onboarding/steps.d.ts +3 -0
- package/dist/cases/onboarding/steps.jsx +177 -0
- package/dist/cases/onboarding.md +368 -0
- package/dist/cases/plan-sign-off/one-approver.d.ts +1 -0
- package/dist/cases/plan-sign-off/one-approver.jsx +129 -0
- package/dist/cases/plan-sign-off/team.d.ts +1 -0
- package/dist/cases/plan-sign-off/team.jsx +213 -0
- package/dist/cases/plan-sign-off.md +541 -0
- package/dist/cases/stat-row.md +1 -1
- package/dist/cases/task-header/agent-sets-status.d.ts +1 -0
- package/dist/cases/task-header/agent-sets-status.jsx +164 -0
- package/dist/cases/task-header/people-change-status.d.ts +1 -0
- package/dist/cases/task-header/people-change-status.jsx +175 -0
- package/dist/cases/task-header.md +576 -0
- package/dist/cases.json +645 -7
- package/dist/components/barChart.d.ts +35 -0
- package/dist/components/barChart.jsx +90 -0
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/heading.jsx +5 -3
- package/dist/components/lineChart.d.ts +39 -0
- package/dist/components/lineChart.jsx +128 -0
- package/dist/components/popover.jsx +7 -2
- package/dist/components/timeline.d.ts +32 -0
- package/dist/components/timeline.jsx +54 -0
- package/dist/components/titleBar.d.ts +3 -1
- package/dist/components/titleBar.jsx +9 -4
- package/dist/internal/chart.d.ts +39 -0
- package/dist/internal/chart.js +110 -0
- package/dist/internal/chartFrame.d.ts +29 -0
- package/dist/internal/chartFrame.jsx +57 -0
- package/dist/native-mapping.json +19 -1
- package/dist/stories/BarChart.stories.d.ts +10 -0
- package/dist/stories/BarChart.stories.jsx +104 -0
- package/dist/stories/Cases.generated.stories.d.ts +16 -0
- package/dist/stories/Cases.generated.stories.jsx +32 -0
- package/dist/stories/Heading.stories.d.ts +1 -0
- package/dist/stories/Heading.stories.jsx +17 -0
- package/dist/stories/LineChart.stories.d.ts +9 -0
- package/dist/stories/LineChart.stories.jsx +34 -0
- package/dist/stories/Onboarding.probe.stories.d.ts +6 -0
- package/dist/stories/Onboarding.probe.stories.jsx +12 -0
- package/dist/stories/Popover.stories.d.ts +1 -0
- package/dist/stories/Popover.stories.jsx +17 -0
- package/dist/stories/Timeline.stories.d.ts +8 -0
- package/dist/stories/Timeline.stories.jsx +49 -0
- package/dist/stories/TitleBar.stories.d.ts +1 -0
- package/dist/stories/TitleBar.stories.jsx +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
# Ask page
|
|
2
|
+
|
|
3
|
+
A page where a person asks the agent about their work across one or more workspaces, and reads the answers with their sources.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Follow the cases 'Conversation starters', 'Scope picker', 'Reply sources' and 'Message composer'.
|
|
8
|
+
- Put the page in `AppShell`, with a `TitleBar` 'Ask' and the scope Button as its `actions`: 'All 3 Workspaces'.
|
|
9
|
+
- Show the empty page as `EmptyBox size="large"` with the text 'No questions yet' and a `secondText` that says what to do. Pass up to four starter `Tag`s as its `action`.
|
|
10
|
+
- Write each starter as a whole question in plain words. A starter fills the `Composer` and focuses it, and the person sends it.
|
|
11
|
+
- Say where the agent looks above the `Composer`: 'Acme Agent looks in the docs, chats and tasks of all 3 of your workspaces.' Change it with the scope.
|
|
12
|
+
- Name the `Composer` for who reads it: 'Ask Acme Agent'.
|
|
13
|
+
- Show the question as the person's `Message`, and the answer as the agent's, with its sources as cards under it, as the case 'Reply sources' says.
|
|
14
|
+
- Offer 'Save to Docs' under an answer when the product keeps answers as docs. While it saves it is `loading`. Then a toast says 'Answer saved to Docs.', a link 'Open in Docs' takes its place, and focus goes to the link.
|
|
15
|
+
- Keep the conversation when the person leaves the page, and show it again when they come back.
|
|
16
|
+
- Show the agent's progress row where the answer will appear while it works, with a Stop Button, as the rule 'An agent shows its progress' says. Once the run has ended, Stop gives way to 'Stopped. Nothing was changed.' and focus goes back to the `Composer`.
|
|
17
|
+
- Say so in one plain sentence when the agent found nothing in the scope. Name the scope and show no sources: 'I found nothing about this in the docs, chats and tasks of Acme Design.'
|
|
18
|
+
- Say which limit stopped the agent, and who can change it or when to try again, as the rule 'An agent refuses clearly' says.
|
|
19
|
+
|
|
20
|
+
## Don't
|
|
21
|
+
|
|
22
|
+
- Do not offer more than four starters.
|
|
23
|
+
- Do not put a blank to fill in a starter, such as '[project]'. The person edits the question in the Composer.
|
|
24
|
+
- Do not show an answer with no sources when the agent read something, as the rule 'An agent shows its sources' says.
|
|
25
|
+
- Do not hide where the agent looks behind the scope menu alone. Say it in words.
|
|
26
|
+
|
|
27
|
+
## Option: Nothing asked yet
|
|
28
|
+
|
|
29
|
+
Use when: The person has not asked anything yet.
|
|
30
|
+
|
|
31
|
+
Uses: `AppShell`, `Button`, `Cluster`, `Composer`, `EmptyBox`, `Line`, `Menu`, `MenuItem`, `Message`, `Navigation`, `Paragraph`, `Popover`, `Stack`, `Tag`, `TimeStamp`, `TitleBar`, `UserImage`
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
'use client';
|
|
35
|
+
import { useEffect, useRef, useState } from 'react';
|
|
36
|
+
import AppShell from 'oneslash-design-system/components/appShell';
|
|
37
|
+
import Navigation from 'oneslash-design-system/components/navigation';
|
|
38
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
39
|
+
import TitleBar from 'oneslash-design-system/components/titleBar';
|
|
40
|
+
import Button from 'oneslash-design-system/components/button';
|
|
41
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
42
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
43
|
+
import Line from 'oneslash-design-system/components/line';
|
|
44
|
+
import Message from 'oneslash-design-system/components/message';
|
|
45
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
46
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
47
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
48
|
+
import Composer from 'oneslash-design-system/components/composer';
|
|
49
|
+
import EmptyBox from 'oneslash-design-system/components/emptyBox';
|
|
50
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
51
|
+
import { Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
52
|
+
|
|
53
|
+
// A real app reads these from the session.
|
|
54
|
+
const me = 'Dana Lee';
|
|
55
|
+
const agentName = 'Acme Agent';
|
|
56
|
+
const workspaces = ['Acme Design', 'Acme Engineering', 'Acme Marketing'];
|
|
57
|
+
const all = `All ${workspaces.length} Workspaces`;
|
|
58
|
+
|
|
59
|
+
// Four things to ask at most, in plain words. Each one fills the Composer, where the person can change it.
|
|
60
|
+
const starters = [
|
|
61
|
+
'What changed in my workspaces this week?',
|
|
62
|
+
'What is still open on the launch?',
|
|
63
|
+
'Who is working on the pricing page?',
|
|
64
|
+
'What did we decide about the press kit?',
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
type Row = { id: string; from: string; at: Date; text: string };
|
|
68
|
+
|
|
69
|
+
// The places. A real app lets each link go to its page.
|
|
70
|
+
const sidebar = (
|
|
71
|
+
<Navigation aria-label="Main">
|
|
72
|
+
{[
|
|
73
|
+
['Home', 'House', '/'],
|
|
74
|
+
['Ask', 'MessageCircle', '/ask'],
|
|
75
|
+
['Docs', 'BookOpen', '/docs'],
|
|
76
|
+
].map(([label, icon, href]) => (
|
|
77
|
+
<MenuItem
|
|
78
|
+
key={href}
|
|
79
|
+
size="small"
|
|
80
|
+
label={label}
|
|
81
|
+
iconName={icon}
|
|
82
|
+
href={href}
|
|
83
|
+
isSelected={href === '/ask'}
|
|
84
|
+
aria-current={href === '/ask' ? 'page' : undefined}
|
|
85
|
+
onClick={(event: { preventDefault: () => void }) => event.preventDefault()}
|
|
86
|
+
/>
|
|
87
|
+
))}
|
|
88
|
+
</Navigation>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export default function AskPageFirstVisit() {
|
|
92
|
+
const [navOpen, setNavOpen] = useState(false);
|
|
93
|
+
// null means every workspace.
|
|
94
|
+
const [scope, setScope] = useState<string | null>(null);
|
|
95
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
96
|
+
const [open, setOpen] = useState(false);
|
|
97
|
+
const [thread, setThread] = useState<Row[]>([]);
|
|
98
|
+
const [text, setText] = useState('');
|
|
99
|
+
// Set when a starter fills the field; the effect below focuses it with the caret at the end.
|
|
100
|
+
const [filled, setFilled] = useState(0);
|
|
101
|
+
const field = useRef<HTMLTextAreaElement>(null);
|
|
102
|
+
const label = scope ?? all;
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!filled || !field.current) return;
|
|
106
|
+
const end = field.current.value.length;
|
|
107
|
+
field.current.focus();
|
|
108
|
+
field.current.setSelectionRange(end, end);
|
|
109
|
+
}, [filled]);
|
|
110
|
+
|
|
111
|
+
function choose(next: string | null) {
|
|
112
|
+
setScope(next);
|
|
113
|
+
setOpen(false);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fills the field and does not send: the person can change it first.
|
|
117
|
+
function fillWith(starter: string) {
|
|
118
|
+
setText(starter);
|
|
119
|
+
setFilled((n) => n + 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function send() {
|
|
123
|
+
// A real app sends the question to the agent here and shows it at once. The agent's progress row follows,
|
|
124
|
+
// with Stop, then the answer with its sources. The 'answered' example shows both.
|
|
125
|
+
setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date('2026-11-16T14:40:00Z'), text: text.trim() }]);
|
|
126
|
+
setText('');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<AppShell title="Ask" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>
|
|
131
|
+
<Stack gap="large">
|
|
132
|
+
<TitleBar
|
|
133
|
+
title="Ask"
|
|
134
|
+
actions={
|
|
135
|
+
// The label is the scope. The chevron says it opens a menu.
|
|
136
|
+
<Button
|
|
137
|
+
size="small"
|
|
138
|
+
type="tertiary"
|
|
139
|
+
state={open ? 'selected' : 'enabled'}
|
|
140
|
+
label={label}
|
|
141
|
+
actionIcon="ChevronDown"
|
|
142
|
+
aria-label={`${label}, change where ${agentName} looks`}
|
|
143
|
+
aria-haspopup="menu"
|
|
144
|
+
aria-expanded={open}
|
|
145
|
+
onClickButton={(e: { currentTarget: HTMLElement }) => {
|
|
146
|
+
setAnchor(e.currentTarget);
|
|
147
|
+
setOpen((o) => !o);
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
}
|
|
151
|
+
/>
|
|
152
|
+
{thread.length === 0 ? (
|
|
153
|
+
<EmptyBox
|
|
154
|
+
size="large"
|
|
155
|
+
icon="MessageCircle"
|
|
156
|
+
text="No questions yet"
|
|
157
|
+
secondText={`Ask ${agentName} anything about your work. It shows where each answer came from.`}
|
|
158
|
+
action={
|
|
159
|
+
<Cluster gap="small">
|
|
160
|
+
{starters.map((s) => (
|
|
161
|
+
<Tag key={s} variant="contained" size="small" label={s} toggle={false} onClick={() => fillWith(s)} />
|
|
162
|
+
))}
|
|
163
|
+
</Cluster>
|
|
164
|
+
}
|
|
165
|
+
/>
|
|
166
|
+
) : (
|
|
167
|
+
// A real app gives the list that holds the rows role="log".
|
|
168
|
+
<Stack gap="small">
|
|
169
|
+
{thread.map((m) => (
|
|
170
|
+
<Message
|
|
171
|
+
key={m.id}
|
|
172
|
+
aria-label={m.from}
|
|
173
|
+
avatar={<UserImage userHandle={m.from} decorative />}
|
|
174
|
+
name={m.from}
|
|
175
|
+
meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
|
|
176
|
+
>
|
|
177
|
+
<Paragraph measure="none">{m.text}</Paragraph>
|
|
178
|
+
</Message>
|
|
179
|
+
))}
|
|
180
|
+
</Stack>
|
|
181
|
+
)}
|
|
182
|
+
<Stack gap="small">
|
|
183
|
+
{/* Where the agent looks, said above the box it is asked in. */}
|
|
184
|
+
<Paragraph size="body2" tone="secondary" measure="none">
|
|
185
|
+
{scope ? `${agentName} looks in the docs, chats and tasks of ${scope}.` : `${agentName} looks in the docs, chats and tasks of all ${workspaces.length} of your workspaces.`}
|
|
186
|
+
</Paragraph>
|
|
187
|
+
<Composer
|
|
188
|
+
ref={field}
|
|
189
|
+
id="ask-page-first-visit-question"
|
|
190
|
+
aria-label={`Ask ${agentName}`}
|
|
191
|
+
placeholder={`Ask ${agentName}`}
|
|
192
|
+
value={text}
|
|
193
|
+
onChange={setText}
|
|
194
|
+
onSubmit={send}
|
|
195
|
+
/>
|
|
196
|
+
</Stack>
|
|
197
|
+
</Stack>
|
|
198
|
+
<Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
|
|
199
|
+
<Menu navigable aria-label={`Where ${agentName} looks`} width={220}>
|
|
200
|
+
<MenuItem size="small" label={all} isSelected={scope === null} role="menuitemradio" onClick={() => choose(null)} />
|
|
201
|
+
<Line />
|
|
202
|
+
{workspaces.map((w) => (
|
|
203
|
+
<MenuItem key={w} size="small" label={w} isSelected={scope === w} role="menuitemradio" onClick={() => choose(w)} />
|
|
204
|
+
))}
|
|
205
|
+
</Menu>
|
|
206
|
+
</Popover>
|
|
207
|
+
</AppShell>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Option: Answered
|
|
213
|
+
|
|
214
|
+
Use when: A question has its answer and sources, and the person can ask the next one.
|
|
215
|
+
|
|
216
|
+
Uses: `AppShell`, `Button`, `Cluster`, `Composer`, `Grid`, `Line`, `Menu`, `MenuItem`, `Message`, `Navigation`, `Paragraph`, `Popover`, `SourceCard`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `TitleBar`, `Toaster`, `UserImage`, `dismissToast`, `toast`
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
'use client';
|
|
220
|
+
import { useEffect, useRef, useState } from 'react';
|
|
221
|
+
import { BookOpen, Bot, ListChecks, MessageSquare, Plug } from 'lucide-react';
|
|
222
|
+
import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
|
|
223
|
+
import AppShell from 'oneslash-design-system/components/appShell';
|
|
224
|
+
import Navigation from 'oneslash-design-system/components/navigation';
|
|
225
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
226
|
+
import TitleBar from 'oneslash-design-system/components/titleBar';
|
|
227
|
+
import Button from 'oneslash-design-system/components/button';
|
|
228
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
229
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
230
|
+
import Line from 'oneslash-design-system/components/line';
|
|
231
|
+
import Message from 'oneslash-design-system/components/message';
|
|
232
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
233
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
234
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
235
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
236
|
+
import SourceCard from 'oneslash-design-system/components/sourceCard';
|
|
237
|
+
import Composer from 'oneslash-design-system/components/composer';
|
|
238
|
+
import StepList from 'oneslash-design-system/components/stepList';
|
|
239
|
+
import { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';
|
|
240
|
+
|
|
241
|
+
// A real app reads these from the session.
|
|
242
|
+
const me = 'Dana Lee';
|
|
243
|
+
const agentName = 'Acme Agent';
|
|
244
|
+
const workspaces = ['Acme Design', 'Acme Engineering', 'Acme Marketing'];
|
|
245
|
+
const all = `All ${workspaces.length} Workspaces`;
|
|
246
|
+
|
|
247
|
+
const question = { from: me, at: new Date('2026-11-16T14:40:00Z'), text: 'Who owns the press kit for the launch?' };
|
|
248
|
+
const answeredAt = new Date('2026-11-16T14:41:00Z');
|
|
249
|
+
const answer = 'Mia Park owns the press kit. Ben Carter handed it to her in #launch on Nov 12, 2026, and the launch plan lists her as its owner. It is due Nov 19, 2026.';
|
|
250
|
+
|
|
251
|
+
type Kind = 'chat' | 'docs' | 'tasks';
|
|
252
|
+
const kinds = {
|
|
253
|
+
chat: { label: 'Chat', icon: MessageSquare },
|
|
254
|
+
docs: { label: 'Docs', icon: BookOpen },
|
|
255
|
+
tasks: { label: 'Tasks', icon: ListChecks },
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// Each card links to the thing it read.
|
|
259
|
+
const sources: { kind: Kind; title: string; where: string; href: string }[] = [
|
|
260
|
+
{ kind: 'chat', title: 'Press kit hand-off', where: 'Acme Marketing · #launch · Nov 12', href: '/chat/launch/m-2210' },
|
|
261
|
+
{ kind: 'docs', title: 'Launch plan', where: 'Acme Marketing', href: '/docs/launch-plan' },
|
|
262
|
+
{ kind: 'tasks', title: 'Write the press kit', where: 'Acme Design · Due Nov 19', href: '/tasks/press-kit' },
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
// 'From Chat · Docs · Tasks': each kind once, in the order it first appears.
|
|
266
|
+
const kindsTag = `From ${sources.map((s) => kinds[s.kind].label).filter((l, i, list) => list.indexOf(l) === i).join(' · ')}`;
|
|
267
|
+
|
|
268
|
+
// The next question and the agent's run on it. 'nothing' is the end of a run that found nothing in the scope.
|
|
269
|
+
type Phase = 'running' | 'stopping' | 'stopped' | 'nothing';
|
|
270
|
+
type Turn = { id: string; text: string; scope: string | null; phase: Phase; seconds: number };
|
|
271
|
+
type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
|
|
272
|
+
|
|
273
|
+
// The places. A real app lets each link go to its page.
|
|
274
|
+
const sidebar = (
|
|
275
|
+
<Navigation aria-label="Main">
|
|
276
|
+
{[
|
|
277
|
+
['Home', 'House', '/'],
|
|
278
|
+
['Ask', 'MessageCircle', '/ask'],
|
|
279
|
+
['Docs', 'BookOpen', '/docs'],
|
|
280
|
+
].map(([label, icon, href]) => (
|
|
281
|
+
<MenuItem
|
|
282
|
+
key={href}
|
|
283
|
+
size="small"
|
|
284
|
+
label={label}
|
|
285
|
+
iconName={icon}
|
|
286
|
+
href={href}
|
|
287
|
+
isSelected={href === '/ask'}
|
|
288
|
+
aria-current={href === '/ask' ? 'page' : undefined}
|
|
289
|
+
onClick={(event: { preventDefault: () => void }) => event.preventDefault()}
|
|
290
|
+
/>
|
|
291
|
+
))}
|
|
292
|
+
</Navigation>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
export default function AskPageAnswered() {
|
|
296
|
+
const [navOpen, setNavOpen] = useState(false);
|
|
297
|
+
// null means every workspace.
|
|
298
|
+
const [scope, setScope] = useState<string | null>(null);
|
|
299
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
300
|
+
const [open, setOpen] = useState(false);
|
|
301
|
+
const [turns, setTurns] = useState<Turn[]>([]);
|
|
302
|
+
const [text, setText] = useState('');
|
|
303
|
+
const [saving, setSaving] = useState(false);
|
|
304
|
+
const [saved, setSaved] = useState(false);
|
|
305
|
+
const openButton = useRef<Focusable>(null);
|
|
306
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
307
|
+
const run = useRef<ReturnType<typeof setTimeout>>();
|
|
308
|
+
const tick = useRef<ReturnType<typeof setInterval>>();
|
|
309
|
+
const field = useRef<HTMLTextAreaElement>(null);
|
|
310
|
+
const toastIds = useRef<string[]>([]);
|
|
311
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
312
|
+
const focusNext = useRef<() => void>();
|
|
313
|
+
const label = scope ?? all;
|
|
314
|
+
|
|
315
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
316
|
+
useEffect(() => () => {
|
|
317
|
+
clearTimeout(timer.current);
|
|
318
|
+
clearTimeout(run.current);
|
|
319
|
+
clearInterval(tick.current);
|
|
320
|
+
toastIds.current.forEach((id) => dismissToast(id));
|
|
321
|
+
toastIds.current = [];
|
|
322
|
+
}, []);
|
|
323
|
+
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
const move = focusNext.current;
|
|
326
|
+
focusNext.current = undefined;
|
|
327
|
+
move?.();
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
function choose(next: string | null) {
|
|
331
|
+
setScope(next);
|
|
332
|
+
setOpen(false);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// The answer goes to Docs, away from this page, so a toast says where it went.
|
|
336
|
+
// 'Save to Docs' gives way to a link to the new doc, and focus goes to it.
|
|
337
|
+
function saveToDocs() {
|
|
338
|
+
if (saving || saved) return;
|
|
339
|
+
setSaving(true);
|
|
340
|
+
// Stands in for the request to the server.
|
|
341
|
+
timer.current = setTimeout(() => {
|
|
342
|
+
setSaving(false);
|
|
343
|
+
setSaved(true);
|
|
344
|
+
toastIds.current.push(toast({ type: 'success', message: 'Answer saved to Docs.' }));
|
|
345
|
+
focusNext.current = () => openButton.current?.focus({ preventScroll: true });
|
|
346
|
+
}, 1200);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const running = turns.some((t) => t.phase === 'running' || t.phase === 'stopping');
|
|
350
|
+
|
|
351
|
+
// Changes the last turn, the one the agent is working on.
|
|
352
|
+
function setLast(change: Partial<Turn>) {
|
|
353
|
+
setTurns((list) => list.map((t, i) => (i === list.length - 1 ? { ...t, ...change } : t)));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function endRun() {
|
|
357
|
+
clearTimeout(run.current);
|
|
358
|
+
clearInterval(tick.current);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// The question shows at once, and the agent's progress row takes the place of its answer while it works.
|
|
362
|
+
// This run finds nothing in the scope, so its answer says so in one plain sentence and shows no sources.
|
|
363
|
+
function send() {
|
|
364
|
+
if (running) return;
|
|
365
|
+
setTurns((list) => [...list, { id: `t${list.length + 1}`, text: text.trim(), scope, phase: 'running', seconds: 0 }]);
|
|
366
|
+
setText('');
|
|
367
|
+
tick.current = setInterval(() => setTurns((list) => list.map((t, i) => (i === list.length - 1 ? { ...t, seconds: t.seconds + 1 } : t))), 1000);
|
|
368
|
+
// Stands in for the agent's run.
|
|
369
|
+
run.current = setTimeout(() => {
|
|
370
|
+
endRun();
|
|
371
|
+
setLast({ phase: 'nothing' });
|
|
372
|
+
}, 3000);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended,
|
|
376
|
+
// then focus goes back to the question box, since Stop is gone.
|
|
377
|
+
function stop() {
|
|
378
|
+
clearTimeout(run.current);
|
|
379
|
+
setLast({ phase: 'stopping' });
|
|
380
|
+
run.current = setTimeout(() => {
|
|
381
|
+
endRun();
|
|
382
|
+
setLast({ phase: 'stopped' });
|
|
383
|
+
focusNext.current = () => field.current?.focus({ preventScroll: true });
|
|
384
|
+
}, 1200);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return (
|
|
388
|
+
<AppShell title="Ask" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>
|
|
389
|
+
<Stack gap="large">
|
|
390
|
+
<TitleBar
|
|
391
|
+
title="Ask"
|
|
392
|
+
actions={
|
|
393
|
+
// The label is the scope. The chevron says it opens a menu.
|
|
394
|
+
<Button
|
|
395
|
+
size="small"
|
|
396
|
+
type="tertiary"
|
|
397
|
+
state={open ? 'selected' : 'enabled'}
|
|
398
|
+
label={label}
|
|
399
|
+
actionIcon="ChevronDown"
|
|
400
|
+
aria-label={`${label}, change where ${agentName} looks`}
|
|
401
|
+
aria-haspopup="menu"
|
|
402
|
+
aria-expanded={open}
|
|
403
|
+
onClickButton={(e: { currentTarget: HTMLElement }) => {
|
|
404
|
+
setAnchor(e.currentTarget);
|
|
405
|
+
setOpen((o) => !o);
|
|
406
|
+
}}
|
|
407
|
+
/>
|
|
408
|
+
}
|
|
409
|
+
/>
|
|
410
|
+
{/* A real app keeps the conversation when the person leaves, and gives the list that holds the rows role="log". */}
|
|
411
|
+
<Stack gap="small">
|
|
412
|
+
<Message
|
|
413
|
+
aria-label={question.from}
|
|
414
|
+
avatar={<UserImage userHandle={question.from} decorative />}
|
|
415
|
+
name={question.from}
|
|
416
|
+
meta={<TimeStamp createdAt={question.at} dateFormat="absolute" data="time" />}
|
|
417
|
+
>
|
|
418
|
+
<Paragraph measure="none">{question.text}</Paragraph>
|
|
419
|
+
</Message>
|
|
420
|
+
<Message
|
|
421
|
+
aria-label={`${agentName}, agent`}
|
|
422
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
423
|
+
name={agentName}
|
|
424
|
+
meta={
|
|
425
|
+
<>
|
|
426
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
427
|
+
<TimeStamp createdAt={answeredAt} dateFormat="absolute" data="time" />
|
|
428
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
429
|
+
</>
|
|
430
|
+
}
|
|
431
|
+
// The sources sit directly under the answer they support.
|
|
432
|
+
footer={
|
|
433
|
+
<Stack gap="medium">
|
|
434
|
+
<Cluster>
|
|
435
|
+
<Tag variant="contained" size="small" color="success" icon={Plug} label={kindsTag} />
|
|
436
|
+
</Cluster>
|
|
437
|
+
<Grid columns={2} gap="medium">
|
|
438
|
+
{sources.map((s) => (
|
|
439
|
+
<SourceCard key={s.href} icon={kinds[s.kind].icon} title={s.title} meta={`${kinds[s.kind].label} · ${s.where}`} href={s.href} />
|
|
440
|
+
))}
|
|
441
|
+
</Grid>
|
|
442
|
+
<Cluster>
|
|
443
|
+
{saved ? (
|
|
444
|
+
<Button ref={openButton} size="small" type="tertiary" state="enabled" label="Open in Docs" decoIcon="FileText" href="/docs/press-kit-owner" />
|
|
445
|
+
) : (
|
|
446
|
+
<Button size="small" type="secondary" state="enabled" label="Save to Docs" decoIcon="BookmarkPlus" loading={saving} onClickButton={saveToDocs} />
|
|
447
|
+
)}
|
|
448
|
+
</Cluster>
|
|
449
|
+
</Stack>
|
|
450
|
+
}
|
|
451
|
+
>
|
|
452
|
+
<Paragraph measure="none">{answer}</Paragraph>
|
|
453
|
+
</Message>
|
|
454
|
+
{turns.map((t) => {
|
|
455
|
+
const place = t.scope ?? `all ${workspaces.length} of your workspaces`;
|
|
456
|
+
const working = t.phase === 'running' || t.phase === 'stopping';
|
|
457
|
+
return (
|
|
458
|
+
<Stack key={t.id} gap="small">
|
|
459
|
+
<Message
|
|
460
|
+
aria-label={me}
|
|
461
|
+
avatar={<UserImage userHandle={me} decorative />}
|
|
462
|
+
name={me}
|
|
463
|
+
meta={<TimeStamp createdAt={new Date('2026-11-16T14:45:00Z')} dateFormat="absolute" data="time" />}
|
|
464
|
+
>
|
|
465
|
+
<Paragraph measure="none">{t.text}</Paragraph>
|
|
466
|
+
</Message>
|
|
467
|
+
<Message
|
|
468
|
+
aria-label={`${agentName}, agent`}
|
|
469
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
470
|
+
name={agentName}
|
|
471
|
+
meta={
|
|
472
|
+
<>
|
|
473
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
474
|
+
<TimeStamp createdAt={new Date('2026-11-16T14:45:00Z')} dateFormat="absolute" data="time" />
|
|
475
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
476
|
+
</>
|
|
477
|
+
}
|
|
478
|
+
// The only Stop, on the row for the whole run. It shows loading while the run is stopping.
|
|
479
|
+
footer={working ? (
|
|
480
|
+
<Cluster>
|
|
481
|
+
<Button size="small" type="secondary" state="enabled" label="Stop" loading={t.phase === 'stopping'} onClickButton={stop} />
|
|
482
|
+
</Cluster>
|
|
483
|
+
) : undefined}
|
|
484
|
+
>
|
|
485
|
+
{working ? (
|
|
486
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
487
|
+
<Stack gap="medium">
|
|
488
|
+
<Paragraph size="caption" tone="secondary" measure="none">{`Working for ${t.seconds} ${t.seconds === 1 ? 'second' : 'seconds'}`}</Paragraph>
|
|
489
|
+
<StepList
|
|
490
|
+
aria-label={`${agentName}'s steps`}
|
|
491
|
+
steps={[
|
|
492
|
+
{ label: 'Read your question', status: 'done' },
|
|
493
|
+
{ label: `Looking in the docs, chats and tasks of ${place}`, status: 'running' },
|
|
494
|
+
]}
|
|
495
|
+
/>
|
|
496
|
+
</Stack>
|
|
497
|
+
) : t.phase === 'stopped' ? (
|
|
498
|
+
<Paragraph measure="none">Stopped. Nothing was changed.</Paragraph>
|
|
499
|
+
) : (
|
|
500
|
+
// It read nothing it could use, so the answer has no sources section.
|
|
501
|
+
<Paragraph measure="none">{`I found nothing about this in the docs, chats and tasks of ${place}. Try other words, or change where I look.`}</Paragraph>
|
|
502
|
+
)}
|
|
503
|
+
</Message>
|
|
504
|
+
</Stack>
|
|
505
|
+
);
|
|
506
|
+
})}
|
|
507
|
+
</Stack>
|
|
508
|
+
<Stack gap="small">
|
|
509
|
+
{/* Where the agent looks, said above the box it is asked in. */}
|
|
510
|
+
<Paragraph size="body2" tone="secondary" measure="none">
|
|
511
|
+
{scope ? `${agentName} looks in the docs, chats and tasks of ${scope}.` : `${agentName} looks in the docs, chats and tasks of all ${workspaces.length} of your workspaces.`}
|
|
512
|
+
</Paragraph>
|
|
513
|
+
<Composer
|
|
514
|
+
ref={field}
|
|
515
|
+
id="ask-page-answered-question"
|
|
516
|
+
aria-label={`Ask ${agentName}`}
|
|
517
|
+
placeholder={`Ask ${agentName}`}
|
|
518
|
+
value={text}
|
|
519
|
+
onChange={setText}
|
|
520
|
+
onSubmit={send}
|
|
521
|
+
/>
|
|
522
|
+
</Stack>
|
|
523
|
+
</Stack>
|
|
524
|
+
<Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
|
|
525
|
+
<Menu navigable aria-label={`Where ${agentName} looks`} width={220}>
|
|
526
|
+
<MenuItem size="small" label={all} isSelected={scope === null} role="menuitemradio" onClick={() => choose(null)} />
|
|
527
|
+
<Line />
|
|
528
|
+
{workspaces.map((w) => (
|
|
529
|
+
<MenuItem key={w} size="small" label={w} isSelected={scope === w} role="menuitemradio" onClick={() => choose(w)} />
|
|
530
|
+
))}
|
|
531
|
+
</Menu>
|
|
532
|
+
</Popover>
|
|
533
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
534
|
+
<Toaster />
|
|
535
|
+
</AppShell>
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
## Native
|
|
541
|
+
|
|
542
|
+
On Apple use a `NavigationStack` with the scope as a toolbar `Menu`, the starters as buttons in a `ContentUnavailableView`, and a text field in a bottom bar. On Android use a `Scaffold` with a dropdown menu in the top bar and suggestion chips over the text field.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ChartBars(): import("react").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import { useEffect, useRef, useState } from 'react';
|
|
12
|
+
import TitleBar from '../../components/titleBar';
|
|
13
|
+
import SegmentedControl from '../../components/segmentedControl';
|
|
14
|
+
import SettingsSection from '../../components/settingsSection';
|
|
15
|
+
import BarChart from '../../components/barChart';
|
|
16
|
+
import { formatCount } from '../../components/formatNumber';
|
|
17
|
+
import { Center, Stack } from '../../components/layout';
|
|
18
|
+
var ranges = [
|
|
19
|
+
{ value: 'week', label: 'Week' },
|
|
20
|
+
{ value: 'month', label: 'Month' },
|
|
21
|
+
{ value: 'quarter', label: 'Quarter' },
|
|
22
|
+
];
|
|
23
|
+
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
24
|
+
// 'Nov 14' for the day `back` days before Nov 16, 2026. Written from UTC, so the server and the browser agree.
|
|
25
|
+
function day(back) {
|
|
26
|
+
var d = new Date(Date.UTC(2026, 10, 16 - back));
|
|
27
|
+
return "".concat(months[d.getUTCMonth()], " ").concat(d.getUTCDate());
|
|
28
|
+
}
|
|
29
|
+
// A real app counts these on the server. The last seven days are the week.
|
|
30
|
+
var week = [40, 46, 38, 52, 58, 61, 72];
|
|
31
|
+
var month = __spreadArray(__spreadArray([], Array.from({ length: 23 }, function (_, i) { return 28 + Math.round(i * 0.8) + ((i * 7) % 5) * 3; }), true), week, true);
|
|
32
|
+
// The quarter is counted by week: 13 weeks, the last from Nov 10 to Nov 16.
|
|
33
|
+
var quarter = [236, 251, 228, 262, 270, 249, 281, 290, 276, 302, 311, 334, 367];
|
|
34
|
+
var data = {
|
|
35
|
+
week: week.map(function (value, i) { return ({ label: day(6 - i), value: value }); }),
|
|
36
|
+
month: month.map(function (value, i) { return ({ label: day(29 - i), value: value }); }),
|
|
37
|
+
quarter: quarter.map(function (value, i) { return ({ label: day(6 + (12 - i) * 7), value: value }); }),
|
|
38
|
+
};
|
|
39
|
+
var noun = { week: 'this week', month: 'this month', quarter: 'this quarter' };
|
|
40
|
+
// The summary says what changed, written from the same data the chart draws. A day with no data (null)
|
|
41
|
+
// is left out, never read as 0: the summary runs from the first day with data to the last.
|
|
42
|
+
function summary(points, range) {
|
|
43
|
+
var known = points.filter(function (p) { return p.value !== null; });
|
|
44
|
+
if (known.length === 0)
|
|
45
|
+
return "No comments were counted ".concat(noun[range], ".");
|
|
46
|
+
var first = known[0];
|
|
47
|
+
var last = known[known.length - 1];
|
|
48
|
+
var when = function (p) { return (range === 'quarter' ? "in the week of ".concat(p.label) : "on ".concat(p.label)); };
|
|
49
|
+
if (known.length === 1)
|
|
50
|
+
return "Comments were counted only ".concat(when(first), ": ").concat(formatCount(first.value), ".");
|
|
51
|
+
var move = last.value > first.value ? 'rose' : last.value < first.value ? 'fell' : 'stayed';
|
|
52
|
+
return move === 'stayed'
|
|
53
|
+
? "Comments stayed at ".concat(formatCount(first.value), " from ").concat(first.label, " to ").concat(last.label, ".")
|
|
54
|
+
: "Comments ".concat(move, " from ").concat(formatCount(first.value), " ").concat(when(first), " to ").concat(formatCount(last.value), " ").concat(when(last), ".");
|
|
55
|
+
}
|
|
56
|
+
export default function ChartBars() {
|
|
57
|
+
var _a = useState('week'), range = _a[0], setRange = _a[1];
|
|
58
|
+
// The numbers load again when the range changes.
|
|
59
|
+
var _b = useState(false), loading = _b[0], setLoading = _b[1];
|
|
60
|
+
var timer = useRef();
|
|
61
|
+
// Stops the request if the example goes away before it ends.
|
|
62
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
63
|
+
function changeRange(next) {
|
|
64
|
+
clearTimeout(timer.current);
|
|
65
|
+
setRange(next);
|
|
66
|
+
setLoading(true);
|
|
67
|
+
// Stands in for the request to the server.
|
|
68
|
+
timer.current = setTimeout(function () { return setLoading(false); }, 600);
|
|
69
|
+
}
|
|
70
|
+
var points = data[range];
|
|
71
|
+
// The total adds the days with data, and says so when a day has none.
|
|
72
|
+
var total = points.reduce(function (sum, p) { var _a; return sum + ((_a = p.value) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
73
|
+
var gap = points.some(function (p) { return p.value === null; });
|
|
74
|
+
return (<Center width="page">
|
|
75
|
+
<Stack gap="xlarge">
|
|
76
|
+
{/* The dashboard's one range drives the chart too. Below md the switch takes its own line under the title. */}
|
|
77
|
+
<TitleBar title="Dashboard" actionsBelow actions={<SegmentedControl size="small" width="fit" aria-label="Range" options={ranges} value={range} onChange={changeRange}/>}/>
|
|
78
|
+
<SettingsSection title={"Comments ".concat(noun[range])} description={"".concat(formatCount(total), " comments ").concat(gap ? 'on the days with data ' : '', "from ").concat(points[0].label, " to Nov 16, 2026")} id="chart-bars-comments">
|
|
79
|
+
<BarChart id="chart-bars-per-day" title={range === 'quarter' ? 'Comments per week' : 'Comments per day'} summary={summary(points, range)} data={points} unit="comments" labelHeader={range === 'quarter' ? 'Week of' : 'Date'} loading={loading} emptyText={"No comments ".concat(noun[range])}/>
|
|
80
|
+
</SettingsSection>
|
|
81
|
+
</Stack>
|
|
82
|
+
</Center>);
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ChartLines(): import("react").JSX.Element;
|