oneslash-design-system 2.16.0 → 2.18.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 +2 -2
- package/dist/DESIGN.md +56 -17
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +3 -7
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +164 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +428 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +652 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +334 -0
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +2 -4
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +99 -0
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +282 -0
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +204 -0
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page.md +0 -4
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +248 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +647 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +306 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +352 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +175 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +367 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +185 -0
- package/dist/cases/not-found-page.md +0 -4
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +548 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +243 -0
- package/dist/cases/route-loading.md +0 -2
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +243 -0
- package/dist/cases/success-feedback.md +1 -5
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/type-to-confirm.md +0 -4
- package/dist/cases/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +92 -0
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +2331 -294
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +14 -9
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +12 -2
- package/dist/components/menuItem.jsx +6 -5
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +12 -1
- package/dist/components/radioGroup.jsx +20 -9
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +31 -0
- package/dist/components/settingsSection.jsx +58 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +6 -21
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +62 -1
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +53 -0
- package/dist/stories/Cases.generated.stories.jsx +106 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +11 -0
- package/dist/stories/SettingsSection.stories.jsx +64 -0
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +8 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Bot } from 'lucide-react';
|
|
4
|
+
import Message from '../../components/message';
|
|
5
|
+
import UserImage from '../../components/userImage';
|
|
6
|
+
import Tag from '../../components/tag';
|
|
7
|
+
import TimeStamp from '../../components/timeStamp';
|
|
8
|
+
import Heading from '../../components/heading';
|
|
9
|
+
import Paragraph from '../../components/paragraph';
|
|
10
|
+
import Button from '../../components/button';
|
|
11
|
+
import Surface from '../../components/surface';
|
|
12
|
+
import RadioGroup from '../../components/radioGroup';
|
|
13
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
14
|
+
var agentName = 'Acme Agent';
|
|
15
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };
|
|
16
|
+
var askedAt = new Date('2025-01-15T11:41:00Z');
|
|
17
|
+
var question = 'Which layout should the pricing page use?';
|
|
18
|
+
var options = [
|
|
19
|
+
{ value: 'columns', label: 'Three columns', secondLabel: 'One card per plan, side by side. Easy to compare.', badge: 'Recommended' },
|
|
20
|
+
{ value: 'table', label: 'Table', secondLabel: 'Plans as columns and features as rows.' },
|
|
21
|
+
{ value: 'switch', label: 'One plan at a time', secondLabel: 'A switch moves between the plans.' },
|
|
22
|
+
];
|
|
23
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
24
|
+
function agentMeta(at) {
|
|
25
|
+
return (<>
|
|
26
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
27
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
28
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
29
|
+
</>);
|
|
30
|
+
}
|
|
31
|
+
export default function AgentOptionsCards() {
|
|
32
|
+
// The recommended option starts selected: the agent has a view, and the person can pick another.
|
|
33
|
+
var _a = useState('columns'), selected = _a[0], setSelected = _a[1];
|
|
34
|
+
var _b = useState('open'), status = _b[0], setStatus = _b[1];
|
|
35
|
+
var _c = useState(null), pending = _c[0], setPending = _c[1];
|
|
36
|
+
var timer = useRef();
|
|
37
|
+
// On unmount it stops the request.
|
|
38
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
39
|
+
// Decided once: the buttons go away, so a second click cannot change it.
|
|
40
|
+
// Nothing takes their place, so a real app moves focus to the message box.
|
|
41
|
+
function decide(action) {
|
|
42
|
+
if (pending || status !== 'open' || (action === 'choose' && selected === ''))
|
|
43
|
+
return;
|
|
44
|
+
setPending(action);
|
|
45
|
+
// Stands in for the request to the server.
|
|
46
|
+
timer.current = setTimeout(function () {
|
|
47
|
+
setPending(null);
|
|
48
|
+
setStatus(action === 'choose' ? 'chosen' : 'cancelled');
|
|
49
|
+
}, 1200);
|
|
50
|
+
}
|
|
51
|
+
var chosen = options.find(function (o) { return o.value === selected; });
|
|
52
|
+
return (<Center width="page">
|
|
53
|
+
<Stack gap="large">
|
|
54
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
55
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
56
|
+
<Stack gap="small">
|
|
57
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
58
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
59
|
+
</Message>
|
|
60
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(askedAt)}>
|
|
61
|
+
<Surface padding="small">
|
|
62
|
+
<Stack gap="medium">
|
|
63
|
+
{/* A real app announces the decided Tag in a polite live region. */}
|
|
64
|
+
<Cluster gap="small">
|
|
65
|
+
<Heading level={2} size="subtitle1">{question}</Heading>
|
|
66
|
+
{status === 'chosen' && <Tag variant="contained" size="small" color="success" label="Chosen"/>}
|
|
67
|
+
{status === 'cancelled' && <Tag variant="contained" size="small" label="Cancelled"/>}
|
|
68
|
+
</Cluster>
|
|
69
|
+
{status === 'open' && (<>
|
|
70
|
+
<RadioGroup variant="card" aria-label={question} options={options} selectedValue={selected} onChange={setSelected} disabled={pending !== null}/>
|
|
71
|
+
{/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}
|
|
72
|
+
<Paragraph size="caption" tone="secondary" measure="none">Waits 10 more minutes, then cancels.</Paragraph>
|
|
73
|
+
<Cluster gap="small">
|
|
74
|
+
<Button size="small" type="tertiary" state={pending === 'choose' ? 'disabled' : 'enabled'} label="Cancel" loading={pending === 'cancel'} onClickButton={function () { return decide('cancel'); }}/>
|
|
75
|
+
<Button size="small" type="primary" state={selected === '' || pending === 'cancel' ? 'disabled' : 'enabled'} label="Choose" loading={pending === 'choose'} onClickButton={function () { return decide('choose'); }}/>
|
|
76
|
+
</Cluster>
|
|
77
|
+
</>)}
|
|
78
|
+
{/* Once decided, only the chosen option is left on the card. */}
|
|
79
|
+
{status === 'chosen' && chosen && <Paragraph measure="none">{chosen.label}</Paragraph>}
|
|
80
|
+
</Stack>
|
|
81
|
+
</Surface>
|
|
82
|
+
</Message>
|
|
83
|
+
{status === 'cancelled' && (
|
|
84
|
+
// One line in the thread on what was not done, under the card.
|
|
85
|
+
<Message compact aria-label={"".concat(agentName, ", agent")}>
|
|
86
|
+
<Paragraph measure="none">Cancelled. Nothing was changed.</Paragraph>
|
|
87
|
+
</Message>)}
|
|
88
|
+
</Stack>
|
|
89
|
+
</Stack>
|
|
90
|
+
</Center>);
|
|
91
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Agent options
|
|
2
|
+
|
|
3
|
+
The agent sees two to four ways forward and needs the person to pick one. These are ways forward for the agent's own work. For a fact or a decision only the person has, see the case 'Agent question'.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Put the card in the agent's `Message`, in a `Surface` with the question as its heading.
|
|
8
|
+
- Show each way forward as an option of `<RadioGroup variant="card">`, with a `secondLabel` that says what it means.
|
|
9
|
+
- Give the agent's pick the `badge` 'Recommended', on one option only.
|
|
10
|
+
- Preselect the recommended option: the agent has a view, and the person can pick another. With no recommended option, preselect nothing.
|
|
11
|
+
- Disable 'Choose' until an option is picked when nothing is preselected.
|
|
12
|
+
- Give the RadioGroup an `aria-label` that starts with the question.
|
|
13
|
+
- Order the buttons 'Cancel', then 'Choose' as the primary Button, at the start of the row.
|
|
14
|
+
- Make the pressed Button `loading` and keep its label. Disable the options and the other Button while the request runs.
|
|
15
|
+
- Keep the card and its buttons when a request fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.
|
|
16
|
+
- Show the waiting time on the card while it waits: 'Waits 10 more minutes, then cancels.'
|
|
17
|
+
- Notify the person who asked when the agent needs their answer.
|
|
18
|
+
- Keep only the chosen option once it is decided, as text, with a 'Chosen' `Tag`. Remove the buttons.
|
|
19
|
+
- Mark the card with a 'Cancelled' `Tag` when it is cancelled, and add one compact agent row under it that says what was not done: 'Cancelled. Nothing was changed.'
|
|
20
|
+
- Mark the card Cancelled when the waiting time is up, with the same row on what was not done.
|
|
21
|
+
- Announce the decided `Tag` politely: the app wraps it in a polite live region.
|
|
22
|
+
- Move focus to the message box once the card is decided, since its buttons are gone.
|
|
23
|
+
|
|
24
|
+
## Don't
|
|
25
|
+
|
|
26
|
+
- Do not offer one option, or more than four.
|
|
27
|
+
- Do not give more than one option the 'Recommended' badge.
|
|
28
|
+
- Do not preselect an option the agent does not recommend.
|
|
29
|
+
- Do not recommend or preselect an option that does more than the others, such as one that deletes, publishes or widens access.
|
|
30
|
+
- Do not act on an option before the person presses Choose.
|
|
31
|
+
- Do not change a Button's label while it is loading, such as to 'Confirming...'.
|
|
32
|
+
|
|
33
|
+
## Example: Option cards
|
|
34
|
+
|
|
35
|
+
Uses: `Button`, `Center`, `Cluster`, `Heading`, `Message`, `Paragraph`, `RadioGroup`, `Stack`, `Surface`, `Tag`, `TimeStamp`, `UserImage`
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
'use client';
|
|
39
|
+
import { useEffect, useRef, useState } from 'react';
|
|
40
|
+
import { Bot } from 'lucide-react';
|
|
41
|
+
import Message from 'oneslash-design-system/components/message';
|
|
42
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
43
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
44
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
45
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
46
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
47
|
+
import Button from 'oneslash-design-system/components/button';
|
|
48
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
49
|
+
import RadioGroup from 'oneslash-design-system/components/radioGroup';
|
|
50
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
51
|
+
|
|
52
|
+
const agentName = 'Acme Agent';
|
|
53
|
+
|
|
54
|
+
const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you add the Team plan to the pricing page?' };
|
|
55
|
+
const askedAt = new Date('2025-01-15T11:41:00Z');
|
|
56
|
+
|
|
57
|
+
const question = 'Which layout should the pricing page use?';
|
|
58
|
+
|
|
59
|
+
const options = [
|
|
60
|
+
{ value: 'columns', label: 'Three columns', secondLabel: 'One card per plan, side by side. Easy to compare.', badge: 'Recommended' },
|
|
61
|
+
{ value: 'table', label: 'Table', secondLabel: 'Plans as columns and features as rows.' },
|
|
62
|
+
{ value: 'switch', label: 'One plan at a time', secondLabel: 'A switch moves between the plans.' },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
type Status = 'open' | 'chosen' | 'cancelled';
|
|
66
|
+
|
|
67
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
68
|
+
function agentMeta(at: Date) {
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
72
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
73
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default function AgentOptionsCards() {
|
|
79
|
+
// The recommended option starts selected: the agent has a view, and the person can pick another.
|
|
80
|
+
const [selected, setSelected] = useState('columns');
|
|
81
|
+
const [status, setStatus] = useState<Status>('open');
|
|
82
|
+
const [pending, setPending] = useState<'choose' | 'cancel' | null>(null);
|
|
83
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
84
|
+
|
|
85
|
+
// On unmount it stops the request.
|
|
86
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
87
|
+
|
|
88
|
+
// Decided once: the buttons go away, so a second click cannot change it.
|
|
89
|
+
// Nothing takes their place, so a real app moves focus to the message box.
|
|
90
|
+
function decide(action: 'choose' | 'cancel') {
|
|
91
|
+
if (pending || status !== 'open' || (action === 'choose' && selected === '')) return;
|
|
92
|
+
setPending(action);
|
|
93
|
+
// Stands in for the request to the server.
|
|
94
|
+
timer.current = setTimeout(() => {
|
|
95
|
+
setPending(null);
|
|
96
|
+
setStatus(action === 'choose' ? 'chosen' : 'cancelled');
|
|
97
|
+
}, 1200);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const chosen = options.find((o) => o.value === selected);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Center width="page">
|
|
104
|
+
<Stack gap="large">
|
|
105
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
106
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
107
|
+
<Stack gap="small">
|
|
108
|
+
<Message
|
|
109
|
+
aria-label={request.from}
|
|
110
|
+
avatar={<UserImage userHandle={request.from} decorative />}
|
|
111
|
+
name={request.from}
|
|
112
|
+
meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
|
|
113
|
+
>
|
|
114
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
115
|
+
</Message>
|
|
116
|
+
<Message
|
|
117
|
+
aria-label={`${agentName}, agent`}
|
|
118
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
119
|
+
name={agentName}
|
|
120
|
+
meta={agentMeta(askedAt)}
|
|
121
|
+
>
|
|
122
|
+
<Surface padding="small">
|
|
123
|
+
<Stack gap="medium">
|
|
124
|
+
{/* A real app announces the decided Tag in a polite live region. */}
|
|
125
|
+
<Cluster gap="small">
|
|
126
|
+
<Heading level={2} size="subtitle1">{question}</Heading>
|
|
127
|
+
{status === 'chosen' && <Tag variant="contained" size="small" color="success" label="Chosen" />}
|
|
128
|
+
{status === 'cancelled' && <Tag variant="contained" size="small" label="Cancelled" />}
|
|
129
|
+
</Cluster>
|
|
130
|
+
{status === 'open' && (
|
|
131
|
+
<>
|
|
132
|
+
<RadioGroup
|
|
133
|
+
variant="card"
|
|
134
|
+
aria-label={question}
|
|
135
|
+
options={options}
|
|
136
|
+
selectedValue={selected}
|
|
137
|
+
onChange={setSelected}
|
|
138
|
+
disabled={pending !== null}
|
|
139
|
+
/>
|
|
140
|
+
{/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}
|
|
141
|
+
<Paragraph size="caption" tone="secondary" measure="none">Waits 10 more minutes, then cancels.</Paragraph>
|
|
142
|
+
<Cluster gap="small">
|
|
143
|
+
<Button size="small" type="tertiary" state={pending === 'choose' ? 'disabled' : 'enabled'} label="Cancel" loading={pending === 'cancel'} onClickButton={() => decide('cancel')} />
|
|
144
|
+
<Button size="small" type="primary" state={selected === '' || pending === 'cancel' ? 'disabled' : 'enabled'} label="Choose" loading={pending === 'choose'} onClickButton={() => decide('choose')} />
|
|
145
|
+
</Cluster>
|
|
146
|
+
</>
|
|
147
|
+
)}
|
|
148
|
+
{/* Once decided, only the chosen option is left on the card. */}
|
|
149
|
+
{status === 'chosen' && chosen && <Paragraph measure="none">{chosen.label}</Paragraph>}
|
|
150
|
+
</Stack>
|
|
151
|
+
</Surface>
|
|
152
|
+
</Message>
|
|
153
|
+
{status === 'cancelled' && (
|
|
154
|
+
// One line in the thread on what was not done, under the card.
|
|
155
|
+
<Message compact aria-label={`${agentName}, agent`}>
|
|
156
|
+
<Paragraph measure="none">Cancelled. Nothing was changed.</Paragraph>
|
|
157
|
+
</Message>
|
|
158
|
+
)}
|
|
159
|
+
</Stack>
|
|
160
|
+
</Stack>
|
|
161
|
+
</Center>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function AgentPendingReplySteps(): import("react").JSX.Element;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Bot } from 'lucide-react';
|
|
4
|
+
import Message from '../../components/message';
|
|
5
|
+
import UserImage from '../../components/userImage';
|
|
6
|
+
import Tag from '../../components/tag';
|
|
7
|
+
import TimeStamp from '../../components/timeStamp';
|
|
8
|
+
import Heading from '../../components/heading';
|
|
9
|
+
import Paragraph from '../../components/paragraph';
|
|
10
|
+
import Button from '../../components/button';
|
|
11
|
+
import Alert from '../../components/alert';
|
|
12
|
+
import StepList from '../../components/stepList';
|
|
13
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
14
|
+
var agentName = 'Acme Agent';
|
|
15
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };
|
|
16
|
+
var runStartedAt = new Date('2025-01-15T11:41:00Z');
|
|
17
|
+
// Each step in plain words: what the agent is doing now, and what it did once the step is done.
|
|
18
|
+
var plan = [
|
|
19
|
+
{ doing: 'Reading the thread', done: 'Read the thread' },
|
|
20
|
+
{ doing: 'Finding the new plans', done: 'Found the new plans' },
|
|
21
|
+
{ doing: 'Reading the pricing page', done: 'Read the pricing page' },
|
|
22
|
+
{ doing: 'Comparing the prices', done: 'Compared the prices' },
|
|
23
|
+
];
|
|
24
|
+
var reply = "The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15.";
|
|
25
|
+
// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.
|
|
26
|
+
function stepsUpTo(current, failed) {
|
|
27
|
+
return plan.slice(0, current + 1).map(function (s, i) {
|
|
28
|
+
return i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: failed ? 'failed' : 'running' };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function secondsLine(seconds) {
|
|
32
|
+
return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
|
|
33
|
+
}
|
|
34
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
35
|
+
function agentMeta(at) {
|
|
36
|
+
return (<>
|
|
37
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
38
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
39
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
40
|
+
</>);
|
|
41
|
+
}
|
|
42
|
+
export default function AgentPendingReplySteps() {
|
|
43
|
+
// Opens on a still of a run in progress, 12 seconds in, so the picture in the docs does not move.
|
|
44
|
+
// 'Run Again' runs it live: the seconds tick and the steps go on.
|
|
45
|
+
var _a = useState('running'), phase = _a[0], setPhase = _a[1];
|
|
46
|
+
var _b = useState(2), current = _b[0], setCurrent = _b[1];
|
|
47
|
+
var _c = useState(12), seconds = _c[0], setSeconds = _c[1];
|
|
48
|
+
var _d = useState(runStartedAt), startedAt = _d[0], setStartedAt = _d[1];
|
|
49
|
+
var tick = useRef();
|
|
50
|
+
var step = useRef();
|
|
51
|
+
var cancel = useRef();
|
|
52
|
+
var runAgainButton = useRef(null);
|
|
53
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
54
|
+
var focusNext = useRef();
|
|
55
|
+
// The first live run fails at the pricing page, so the example shows the failed row; 'Try Again' then works.
|
|
56
|
+
var triedAgain = useRef(false);
|
|
57
|
+
// On unmount it stops the run, its clock and the cancel request.
|
|
58
|
+
useEffect(function () { return function () {
|
|
59
|
+
clearInterval(tick.current);
|
|
60
|
+
clearTimeout(step.current);
|
|
61
|
+
clearTimeout(cancel.current);
|
|
62
|
+
}; }, []);
|
|
63
|
+
useEffect(function () {
|
|
64
|
+
var move = focusNext.current;
|
|
65
|
+
focusNext.current = undefined;
|
|
66
|
+
move === null || move === void 0 ? void 0 : move();
|
|
67
|
+
});
|
|
68
|
+
function stopTimers() {
|
|
69
|
+
clearInterval(tick.current);
|
|
70
|
+
clearTimeout(step.current);
|
|
71
|
+
}
|
|
72
|
+
// Stands in for the agent's run: one step every 1.5 seconds.
|
|
73
|
+
function advance(at) {
|
|
74
|
+
step.current = setTimeout(function () {
|
|
75
|
+
if (at === 2 && !triedAgain.current) {
|
|
76
|
+
stopTimers();
|
|
77
|
+
setPhase('failed');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (at === plan.length - 1) {
|
|
81
|
+
stopTimers();
|
|
82
|
+
setPhase('done');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setCurrent(at + 1);
|
|
86
|
+
advance(at + 1);
|
|
87
|
+
}, 1500);
|
|
88
|
+
}
|
|
89
|
+
function runLive() {
|
|
90
|
+
stopTimers();
|
|
91
|
+
setPhase('running');
|
|
92
|
+
setCurrent(0);
|
|
93
|
+
setSeconds(0);
|
|
94
|
+
setStartedAt(new Date());
|
|
95
|
+
tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
|
|
96
|
+
advance(0);
|
|
97
|
+
}
|
|
98
|
+
function tryAgain() {
|
|
99
|
+
triedAgain.current = true;
|
|
100
|
+
runLive();
|
|
101
|
+
}
|
|
102
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
103
|
+
function stop() {
|
|
104
|
+
if (phase !== 'running')
|
|
105
|
+
return;
|
|
106
|
+
clearTimeout(step.current);
|
|
107
|
+
setPhase('stopping');
|
|
108
|
+
// Stands in for the request to the server.
|
|
109
|
+
cancel.current = setTimeout(function () {
|
|
110
|
+
clearInterval(tick.current);
|
|
111
|
+
setPhase('stopped');
|
|
112
|
+
// 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.
|
|
113
|
+
focusNext.current = function () { var _a; return (_a = runAgainButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
114
|
+
}, 1200);
|
|
115
|
+
}
|
|
116
|
+
var working = phase === 'running' || phase === 'stopping';
|
|
117
|
+
return (<Center width="page">
|
|
118
|
+
<Stack gap="large">
|
|
119
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
120
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
121
|
+
<Stack gap="small">
|
|
122
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
123
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
124
|
+
</Message>
|
|
125
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(startedAt)} footer={working ? (
|
|
126
|
+
// The only Stop, on the row for the whole run. It shows loading while the run is stopping.
|
|
127
|
+
<Cluster>
|
|
128
|
+
<Button size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop}/>
|
|
129
|
+
</Cluster>) : phase === 'failed' ? (<Cluster>
|
|
130
|
+
<Button size="small" type="secondary" state="enabled" label="Try Again" onClickButton={tryAgain}/>
|
|
131
|
+
</Cluster>) : phase === 'stopped' ? (<Cluster>
|
|
132
|
+
<Button ref={runAgainButton} size="small" type="secondary" state="enabled" label="Run Again" onClickButton={runLive}/>
|
|
133
|
+
</Cluster>) : undefined}>
|
|
134
|
+
{phase === 'done' ? (
|
|
135
|
+
// The run is over: the row is the reply, and Stop is gone. A real app moves focus to the message box.
|
|
136
|
+
<Paragraph measure="none">{reply}</Paragraph>) : phase === 'stopped' ? (<Paragraph measure="none">Stopped. Nothing was changed.</Paragraph>) : (
|
|
137
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
138
|
+
<Stack gap="medium">
|
|
139
|
+
{working && <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>}
|
|
140
|
+
<StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current, phase === 'failed')}/>
|
|
141
|
+
{phase === 'failed' && (
|
|
142
|
+
// It reports where the run stands, so it has no close button and stays.
|
|
143
|
+
<Alert type="error" variant="inline" autoDismiss={false} message="Acme Agent could not open the pricing page. Nothing was changed."/>)}
|
|
144
|
+
</Stack>)}
|
|
145
|
+
</Message>
|
|
146
|
+
</Stack>
|
|
147
|
+
</Stack>
|
|
148
|
+
</Center>);
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function AgentPendingReplyStreaming(): import("react").JSX.Element;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Bot } from 'lucide-react';
|
|
4
|
+
import Message from '../../components/message';
|
|
5
|
+
import UserImage from '../../components/userImage';
|
|
6
|
+
import Tag from '../../components/tag';
|
|
7
|
+
import TimeStamp from '../../components/timeStamp';
|
|
8
|
+
import Heading from '../../components/heading';
|
|
9
|
+
import Paragraph from '../../components/paragraph';
|
|
10
|
+
import Button from '../../components/button';
|
|
11
|
+
import StepList from '../../components/stepList';
|
|
12
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
13
|
+
var agentName = 'Acme Agent';
|
|
14
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };
|
|
15
|
+
var runStartedAt = new Date('2025-01-15T11:41:00Z');
|
|
16
|
+
// Each step in plain words: what the agent is doing now, and what it did once the step is done.
|
|
17
|
+
var plan = [
|
|
18
|
+
{ doing: 'Reading the thread', done: 'Read the thread' },
|
|
19
|
+
{ doing: 'Reading the pricing page', done: 'Read the pricing page' },
|
|
20
|
+
{ doing: 'Writing the reply', done: 'Wrote the reply' },
|
|
21
|
+
];
|
|
22
|
+
var writing = plan.length - 1;
|
|
23
|
+
var words = "The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15. The Team plan is missing too.".split(' ');
|
|
24
|
+
function stepsUpTo(current) {
|
|
25
|
+
return plan.slice(0, current + 1).map(function (s, i) {
|
|
26
|
+
return i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function secondsLine(seconds) {
|
|
30
|
+
return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
|
|
31
|
+
}
|
|
32
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
33
|
+
function agentMeta(at) {
|
|
34
|
+
return (<>
|
|
35
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
36
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
37
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
38
|
+
</>);
|
|
39
|
+
}
|
|
40
|
+
export default function AgentPendingReplyStreaming() {
|
|
41
|
+
// Opens on a still of a run that is writing its reply, 18 seconds in, so the picture in the docs does not move.
|
|
42
|
+
// 'Run Again' runs it live: the seconds tick and the reply grows word by word.
|
|
43
|
+
var _a = useState('running'), phase = _a[0], setPhase = _a[1];
|
|
44
|
+
var _b = useState(writing), current = _b[0], setCurrent = _b[1];
|
|
45
|
+
var _c = useState(10), shown = _c[0], setShown = _c[1];
|
|
46
|
+
var _d = useState(18), seconds = _d[0], setSeconds = _d[1];
|
|
47
|
+
var _e = useState(runStartedAt), startedAt = _e[0], setStartedAt = _e[1];
|
|
48
|
+
var tick = useRef();
|
|
49
|
+
var step = useRef();
|
|
50
|
+
var cancel = useRef();
|
|
51
|
+
var runAgainButton = useRef(null);
|
|
52
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
53
|
+
var focusNext = useRef();
|
|
54
|
+
// On unmount it stops the run, its clock and the cancel request.
|
|
55
|
+
useEffect(function () { return function () {
|
|
56
|
+
clearInterval(tick.current);
|
|
57
|
+
clearTimeout(step.current);
|
|
58
|
+
clearTimeout(cancel.current);
|
|
59
|
+
}; }, []);
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
var move = focusNext.current;
|
|
62
|
+
focusNext.current = undefined;
|
|
63
|
+
move === null || move === void 0 ? void 0 : move();
|
|
64
|
+
});
|
|
65
|
+
function stopTimers() {
|
|
66
|
+
clearInterval(tick.current);
|
|
67
|
+
clearTimeout(step.current);
|
|
68
|
+
}
|
|
69
|
+
// Stands in for the agent's run: a step every 1.5 seconds, then a word of the reply every 0.2 seconds.
|
|
70
|
+
function advance(at, count) {
|
|
71
|
+
if (at < writing) {
|
|
72
|
+
step.current = setTimeout(function () {
|
|
73
|
+
setCurrent(at + 1);
|
|
74
|
+
advance(at + 1, 0);
|
|
75
|
+
}, 1500);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
step.current = setTimeout(function () {
|
|
79
|
+
if (count === words.length) {
|
|
80
|
+
stopTimers();
|
|
81
|
+
setPhase('done');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setShown(count + 1);
|
|
85
|
+
advance(at, count + 1);
|
|
86
|
+
}, 200);
|
|
87
|
+
}
|
|
88
|
+
function runLive() {
|
|
89
|
+
stopTimers();
|
|
90
|
+
setPhase('running');
|
|
91
|
+
setCurrent(0);
|
|
92
|
+
setShown(0);
|
|
93
|
+
setSeconds(0);
|
|
94
|
+
setStartedAt(new Date());
|
|
95
|
+
tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
|
|
96
|
+
advance(0, 0);
|
|
97
|
+
}
|
|
98
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
99
|
+
function stop() {
|
|
100
|
+
if (phase !== 'running')
|
|
101
|
+
return;
|
|
102
|
+
clearTimeout(step.current);
|
|
103
|
+
setPhase('stopping');
|
|
104
|
+
// Stands in for the request to the server.
|
|
105
|
+
cancel.current = setTimeout(function () {
|
|
106
|
+
clearInterval(tick.current);
|
|
107
|
+
setPhase('stopped');
|
|
108
|
+
// 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.
|
|
109
|
+
focusNext.current = function () { var _a; return (_a = runAgainButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
110
|
+
}, 1200);
|
|
111
|
+
}
|
|
112
|
+
var working = phase === 'running' || phase === 'stopping';
|
|
113
|
+
var text = words.slice(0, shown).join(' ');
|
|
114
|
+
return (<Center width="page">
|
|
115
|
+
<Stack gap="large">
|
|
116
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
117
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
118
|
+
<Stack gap="small">
|
|
119
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
120
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
121
|
+
</Message>
|
|
122
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(startedAt)} footer={working ? (
|
|
123
|
+
// The only Stop, under the reply while it is written. It shows loading while the run is stopping.
|
|
124
|
+
<Cluster>
|
|
125
|
+
<Button size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop}/>
|
|
126
|
+
</Cluster>) : phase === 'stopped' ? (<Cluster>
|
|
127
|
+
<Button ref={runAgainButton} size="small" type="secondary" state="enabled" label="Run Again" onClickButton={runLive}/>
|
|
128
|
+
</Cluster>) : undefined}>
|
|
129
|
+
{phase === 'done' ? (
|
|
130
|
+
// The run is over: the row is a plain reply, and Stop is gone. A real app moves focus to the message box.
|
|
131
|
+
<Paragraph measure="none">{text}</Paragraph>) : (
|
|
132
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
133
|
+
<Stack gap="medium">
|
|
134
|
+
{working && <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>}
|
|
135
|
+
{working && <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)}/>}
|
|
136
|
+
{text !== '' && <Paragraph measure="none">{text}</Paragraph>}
|
|
137
|
+
{/* A stop before any text says nothing was written; a stop after some text keeps it. */}
|
|
138
|
+
{phase === 'stopped' && (<Paragraph size="body2" tone="secondary" measure="none">
|
|
139
|
+
{text === '' ? 'Stopped. Nothing was written.' : 'Stopped before the reply was finished.'}
|
|
140
|
+
</Paragraph>)}
|
|
141
|
+
</Stack>)}
|
|
142
|
+
</Message>
|
|
143
|
+
</Stack>
|
|
144
|
+
</Stack>
|
|
145
|
+
</Center>);
|
|
146
|
+
}
|