oneslash-design-system 2.16.0 → 2.17.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 +26 -3
- 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 +2 -2
- 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 +168 -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 +432 -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 +656 -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 +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- 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 +103 -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 +286 -0
- 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 +208 -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 +252 -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 +651 -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 +310 -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 +356 -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 +179 -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 +371 -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 +189 -0
- 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 +552 -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 +247 -0
- 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 +247 -0
- package/dist/cases/success-feedback.md +1 -1
- 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 +96 -0
- package/dist/cases.json +1276 -14
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- 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 +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- 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 +8 -1
- package/dist/components/radioGroup.jsx +19 -8
- 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/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- 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/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/native-mapping.json +32 -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 +30 -0
- package/dist/stories/Cases.generated.stories.jsx +60 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -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/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/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/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
# Agent at work
|
|
2
|
+
|
|
3
|
+
The agent is working on a request in the thread, and its reply is not ready yet.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** Scindo on the web shows no 'Agent' tag on the progress row, its Stop is an icon button with a cross, and its current step is a blinking dot. Scindo's Apple app shows no progress row: while the agent works, Send turns into Stop.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Follow the rule 'An agent shows its progress': one row in the thread, where the reply will appear.
|
|
10
|
+
- Mark the row as the rule 'An agent says what it is' says: an icon avatar, the agent's name, an 'Agent' `Tag`, the time and the model line.
|
|
11
|
+
- Show the seconds so far in a caption, 'Working for 12 seconds', and update it once a second.
|
|
12
|
+
- Show the steps in a `StepList`: the finished ones with a check, and the current one running, in plain words.
|
|
13
|
+
- Leave out steps the agent has not started, unless it knows them.
|
|
14
|
+
- Put the only 'Stop' in the row's `footer`, for the whole run, and under the reply while it is written.
|
|
15
|
+
- Make 'Stop' `loading` while the run stops. Once the run has ended, replace the row in place with a note on what was and was not done.
|
|
16
|
+
- Say 'Stopped. Nothing was changed.' when nothing was. When part was done, say what: 'Stopped after 2 of 4 steps. The rest of the plan was not done.'
|
|
17
|
+
- Say 'Stopped. Nothing was written.' when a streaming reply is stopped before any text.
|
|
18
|
+
- Keep the text and say 'Stopped before the reply was finished.' when a streaming reply is stopped after some text.
|
|
19
|
+
- Show a failed run in the row: an inline error `Alert` with no close button and `autoDismiss={false}`, the failed step marked, and 'Try Again'.
|
|
20
|
+
- Turn the row into the agent's reply when the run is done, and remove 'Stop'.
|
|
21
|
+
- Move focus to the message box when 'Stop' goes away and no other control takes its place.
|
|
22
|
+
- Announce the changing part politely, such as the running step: the app wraps it in a polite live region, since `StepList` has none.
|
|
23
|
+
- Give the list that holds the rows `role="log"`.
|
|
24
|
+
|
|
25
|
+
## Don't
|
|
26
|
+
|
|
27
|
+
- Do not show a spinner with no words.
|
|
28
|
+
- Do not hide 'Stop' while the agent writes its reply.
|
|
29
|
+
- Do not put 'Stop' in the Composer of a thread that people also write in.
|
|
30
|
+
- Do not say the agent stopped before the run has really ended.
|
|
31
|
+
- Do not report a failed run only in a toast away from the row.
|
|
32
|
+
|
|
33
|
+
## Option: Steps
|
|
34
|
+
|
|
35
|
+
Use when: The run has steps to show.
|
|
36
|
+
|
|
37
|
+
Uses: `Alert`, `Button`, `Center`, `Cluster`, `Heading`, `Message`, `Paragraph`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `UserImage`
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
'use client';
|
|
41
|
+
import { useEffect, useRef, useState } from 'react';
|
|
42
|
+
import { Bot } from 'lucide-react';
|
|
43
|
+
import Message from 'oneslash-design-system/components/message';
|
|
44
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
45
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
46
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
47
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
48
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
49
|
+
import Button from 'oneslash-design-system/components/button';
|
|
50
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
51
|
+
import StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';
|
|
52
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
53
|
+
|
|
54
|
+
const agentName = 'Acme Agent';
|
|
55
|
+
|
|
56
|
+
const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };
|
|
57
|
+
const runStartedAt = new Date('2025-01-15T11:41:00Z');
|
|
58
|
+
|
|
59
|
+
// Each step in plain words: what the agent is doing now, and what it did once the step is done.
|
|
60
|
+
const plan = [
|
|
61
|
+
{ doing: 'Reading the thread', done: 'Read the thread' },
|
|
62
|
+
{ doing: 'Finding the new plans', done: 'Found the new plans' },
|
|
63
|
+
{ doing: 'Reading the pricing page', done: 'Read the pricing page' },
|
|
64
|
+
{ doing: 'Comparing the prices', done: 'Compared the prices' },
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const reply = "The pricing page still shows last year's prices. Pro is $12 there, and the new plans set it at $15.";
|
|
68
|
+
|
|
69
|
+
type Phase = 'running' | 'stopping' | 'stopped' | 'failed' | 'done';
|
|
70
|
+
|
|
71
|
+
// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.
|
|
72
|
+
function stepsUpTo(current: number, failed: boolean): StepListStep[] {
|
|
73
|
+
return plan.slice(0, current + 1).map((s, i) =>
|
|
74
|
+
i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: failed ? 'failed' : 'running' },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function secondsLine(seconds: number) {
|
|
79
|
+
return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
83
|
+
function agentMeta(at: Date) {
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
87
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
88
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default function AgentPendingReplySteps() {
|
|
94
|
+
// Opens on a still of a run in progress, 12 seconds in, so the picture in the docs does not move.
|
|
95
|
+
// 'Run Again' runs it live: the seconds tick and the steps go on.
|
|
96
|
+
const [phase, setPhase] = useState<Phase>('running');
|
|
97
|
+
const [current, setCurrent] = useState(2);
|
|
98
|
+
const [seconds, setSeconds] = useState(12);
|
|
99
|
+
const [startedAt, setStartedAt] = useState(runStartedAt);
|
|
100
|
+
const tick = useRef<ReturnType<typeof setInterval>>();
|
|
101
|
+
const step = useRef<ReturnType<typeof setTimeout>>();
|
|
102
|
+
const cancel = useRef<ReturnType<typeof setTimeout>>();
|
|
103
|
+
const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
|
|
104
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
105
|
+
const focusNext = useRef<() => void>();
|
|
106
|
+
// The first live run fails at the pricing page, so the example shows the failed row; 'Try Again' then works.
|
|
107
|
+
const triedAgain = useRef(false);
|
|
108
|
+
|
|
109
|
+
// On unmount it stops the run, its clock and the cancel request.
|
|
110
|
+
useEffect(() => () => {
|
|
111
|
+
clearInterval(tick.current);
|
|
112
|
+
clearTimeout(step.current);
|
|
113
|
+
clearTimeout(cancel.current);
|
|
114
|
+
}, []);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
const move = focusNext.current;
|
|
118
|
+
focusNext.current = undefined;
|
|
119
|
+
move?.();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
function stopTimers() {
|
|
123
|
+
clearInterval(tick.current);
|
|
124
|
+
clearTimeout(step.current);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Stands in for the agent's run: one step every 1.5 seconds.
|
|
128
|
+
function advance(at: number) {
|
|
129
|
+
step.current = setTimeout(() => {
|
|
130
|
+
if (at === 2 && !triedAgain.current) {
|
|
131
|
+
stopTimers();
|
|
132
|
+
setPhase('failed');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (at === plan.length - 1) {
|
|
136
|
+
stopTimers();
|
|
137
|
+
setPhase('done');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
setCurrent(at + 1);
|
|
141
|
+
advance(at + 1);
|
|
142
|
+
}, 1500);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function runLive() {
|
|
146
|
+
stopTimers();
|
|
147
|
+
setPhase('running');
|
|
148
|
+
setCurrent(0);
|
|
149
|
+
setSeconds(0);
|
|
150
|
+
setStartedAt(new Date());
|
|
151
|
+
tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);
|
|
152
|
+
advance(0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function tryAgain() {
|
|
156
|
+
triedAgain.current = true;
|
|
157
|
+
runLive();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
161
|
+
function stop() {
|
|
162
|
+
if (phase !== 'running') return;
|
|
163
|
+
clearTimeout(step.current);
|
|
164
|
+
setPhase('stopping');
|
|
165
|
+
// Stands in for the request to the server.
|
|
166
|
+
cancel.current = setTimeout(() => {
|
|
167
|
+
clearInterval(tick.current);
|
|
168
|
+
setPhase('stopped');
|
|
169
|
+
// 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.
|
|
170
|
+
focusNext.current = () => runAgainButton.current?.focus();
|
|
171
|
+
}, 1200);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const working = phase === 'running' || phase === 'stopping';
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Center width="page">
|
|
178
|
+
<Stack gap="large">
|
|
179
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
180
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
181
|
+
<Stack gap="small">
|
|
182
|
+
<Message
|
|
183
|
+
aria-label={request.from}
|
|
184
|
+
avatar={<UserImage userHandle={request.from} decorative />}
|
|
185
|
+
name={request.from}
|
|
186
|
+
meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
|
|
187
|
+
>
|
|
188
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
189
|
+
</Message>
|
|
190
|
+
<Message
|
|
191
|
+
aria-label={`${agentName}, agent`}
|
|
192
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
193
|
+
name={agentName}
|
|
194
|
+
meta={agentMeta(startedAt)}
|
|
195
|
+
footer={
|
|
196
|
+
working ? (
|
|
197
|
+
// The only Stop, on the row for the whole run. It shows loading while the run is stopping.
|
|
198
|
+
<Cluster>
|
|
199
|
+
<Button size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop} />
|
|
200
|
+
</Cluster>
|
|
201
|
+
) : phase === 'failed' ? (
|
|
202
|
+
<Cluster>
|
|
203
|
+
<Button size="small" type="secondary" state="enabled" label="Try Again" onClickButton={tryAgain} />
|
|
204
|
+
</Cluster>
|
|
205
|
+
) : phase === 'stopped' ? (
|
|
206
|
+
<Cluster>
|
|
207
|
+
<Button ref={runAgainButton} size="small" type="secondary" state="enabled" label="Run Again" onClickButton={runLive} />
|
|
208
|
+
</Cluster>
|
|
209
|
+
) : undefined
|
|
210
|
+
}
|
|
211
|
+
>
|
|
212
|
+
{phase === 'done' ? (
|
|
213
|
+
// The run is over: the row is the reply, and Stop is gone. A real app moves focus to the message box.
|
|
214
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
215
|
+
) : phase === 'stopped' ? (
|
|
216
|
+
<Paragraph measure="none">Stopped. Nothing was changed.</Paragraph>
|
|
217
|
+
) : (
|
|
218
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
219
|
+
<Stack gap="medium">
|
|
220
|
+
{working && <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>}
|
|
221
|
+
<StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current, phase === 'failed')} />
|
|
222
|
+
{phase === 'failed' && (
|
|
223
|
+
// It reports where the run stands, so it has no close button and stays.
|
|
224
|
+
<Alert type="error" variant="inline" autoDismiss={false} message="Acme Agent could not open the pricing page. Nothing was changed." />
|
|
225
|
+
)}
|
|
226
|
+
</Stack>
|
|
227
|
+
)}
|
|
228
|
+
</Message>
|
|
229
|
+
</Stack>
|
|
230
|
+
</Stack>
|
|
231
|
+
</Center>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Option: Streaming reply
|
|
237
|
+
|
|
238
|
+
Use when: The reply text arrives as it is written.
|
|
239
|
+
|
|
240
|
+
Uses: `Button`, `Center`, `Cluster`, `Heading`, `Message`, `Paragraph`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `UserImage`
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
'use client';
|
|
244
|
+
import { useEffect, useRef, useState } from 'react';
|
|
245
|
+
import { Bot } from 'lucide-react';
|
|
246
|
+
import Message from 'oneslash-design-system/components/message';
|
|
247
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
248
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
249
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
250
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
251
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
252
|
+
import Button from 'oneslash-design-system/components/button';
|
|
253
|
+
import StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';
|
|
254
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
255
|
+
|
|
256
|
+
const agentName = 'Acme Agent';
|
|
257
|
+
|
|
258
|
+
const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you check the pricing page against the new plans?' };
|
|
259
|
+
const runStartedAt = new Date('2025-01-15T11:41:00Z');
|
|
260
|
+
|
|
261
|
+
// Each step in plain words: what the agent is doing now, and what it did once the step is done.
|
|
262
|
+
const plan = [
|
|
263
|
+
{ doing: 'Reading the thread', done: 'Read the thread' },
|
|
264
|
+
{ doing: 'Reading the pricing page', done: 'Read the pricing page' },
|
|
265
|
+
{ doing: 'Writing the reply', done: 'Wrote the reply' },
|
|
266
|
+
];
|
|
267
|
+
const writing = plan.length - 1;
|
|
268
|
+
|
|
269
|
+
const 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(' ');
|
|
270
|
+
|
|
271
|
+
type Phase = 'running' | 'stopping' | 'stopped' | 'done';
|
|
272
|
+
|
|
273
|
+
function stepsUpTo(current: number): StepListStep[] {
|
|
274
|
+
return plan.slice(0, current + 1).map((s, i) =>
|
|
275
|
+
i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' },
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function secondsLine(seconds: number) {
|
|
280
|
+
return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
284
|
+
function agentMeta(at: Date) {
|
|
285
|
+
return (
|
|
286
|
+
<>
|
|
287
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
288
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
289
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
290
|
+
</>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export default function AgentPendingReplyStreaming() {
|
|
295
|
+
// Opens on a still of a run that is writing its reply, 18 seconds in, so the picture in the docs does not move.
|
|
296
|
+
// 'Run Again' runs it live: the seconds tick and the reply grows word by word.
|
|
297
|
+
const [phase, setPhase] = useState<Phase>('running');
|
|
298
|
+
const [current, setCurrent] = useState(writing);
|
|
299
|
+
const [shown, setShown] = useState(10);
|
|
300
|
+
const [seconds, setSeconds] = useState(18);
|
|
301
|
+
const [startedAt, setStartedAt] = useState(runStartedAt);
|
|
302
|
+
const tick = useRef<ReturnType<typeof setInterval>>();
|
|
303
|
+
const step = useRef<ReturnType<typeof setTimeout>>();
|
|
304
|
+
const cancel = useRef<ReturnType<typeof setTimeout>>();
|
|
305
|
+
const runAgainButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
|
|
306
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
307
|
+
const focusNext = useRef<() => void>();
|
|
308
|
+
|
|
309
|
+
// On unmount it stops the run, its clock and the cancel request.
|
|
310
|
+
useEffect(() => () => {
|
|
311
|
+
clearInterval(tick.current);
|
|
312
|
+
clearTimeout(step.current);
|
|
313
|
+
clearTimeout(cancel.current);
|
|
314
|
+
}, []);
|
|
315
|
+
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
const move = focusNext.current;
|
|
318
|
+
focusNext.current = undefined;
|
|
319
|
+
move?.();
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
function stopTimers() {
|
|
323
|
+
clearInterval(tick.current);
|
|
324
|
+
clearTimeout(step.current);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Stands in for the agent's run: a step every 1.5 seconds, then a word of the reply every 0.2 seconds.
|
|
328
|
+
function advance(at: number, count: number) {
|
|
329
|
+
if (at < writing) {
|
|
330
|
+
step.current = setTimeout(() => {
|
|
331
|
+
setCurrent(at + 1);
|
|
332
|
+
advance(at + 1, 0);
|
|
333
|
+
}, 1500);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
step.current = setTimeout(() => {
|
|
337
|
+
if (count === words.length) {
|
|
338
|
+
stopTimers();
|
|
339
|
+
setPhase('done');
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
setShown(count + 1);
|
|
343
|
+
advance(at, count + 1);
|
|
344
|
+
}, 200);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function runLive() {
|
|
348
|
+
stopTimers();
|
|
349
|
+
setPhase('running');
|
|
350
|
+
setCurrent(0);
|
|
351
|
+
setShown(0);
|
|
352
|
+
setSeconds(0);
|
|
353
|
+
setStartedAt(new Date());
|
|
354
|
+
tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);
|
|
355
|
+
advance(0, 0);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
359
|
+
function stop() {
|
|
360
|
+
if (phase !== 'running') return;
|
|
361
|
+
clearTimeout(step.current);
|
|
362
|
+
setPhase('stopping');
|
|
363
|
+
// Stands in for the request to the server.
|
|
364
|
+
cancel.current = setTimeout(() => {
|
|
365
|
+
clearInterval(tick.current);
|
|
366
|
+
setPhase('stopped');
|
|
367
|
+
// 'Stop' had focus and is gone. Here 'Run Again' takes its place; in a real app, the message box.
|
|
368
|
+
focusNext.current = () => runAgainButton.current?.focus();
|
|
369
|
+
}, 1200);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const working = phase === 'running' || phase === 'stopping';
|
|
373
|
+
const text = words.slice(0, shown).join(' ');
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<Center width="page">
|
|
377
|
+
<Stack gap="large">
|
|
378
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
379
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
380
|
+
<Stack gap="small">
|
|
381
|
+
<Message
|
|
382
|
+
aria-label={request.from}
|
|
383
|
+
avatar={<UserImage userHandle={request.from} decorative />}
|
|
384
|
+
name={request.from}
|
|
385
|
+
meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
|
|
386
|
+
>
|
|
387
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
388
|
+
</Message>
|
|
389
|
+
<Message
|
|
390
|
+
aria-label={`${agentName}, agent`}
|
|
391
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
392
|
+
name={agentName}
|
|
393
|
+
meta={agentMeta(startedAt)}
|
|
394
|
+
footer={
|
|
395
|
+
working ? (
|
|
396
|
+
// The only Stop, under the reply while it is written. It shows loading while the run is stopping.
|
|
397
|
+
<Cluster>
|
|
398
|
+
<Button size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop} />
|
|
399
|
+
</Cluster>
|
|
400
|
+
) : phase === 'stopped' ? (
|
|
401
|
+
<Cluster>
|
|
402
|
+
<Button ref={runAgainButton} size="small" type="secondary" state="enabled" label="Run Again" onClickButton={runLive} />
|
|
403
|
+
</Cluster>
|
|
404
|
+
) : undefined
|
|
405
|
+
}
|
|
406
|
+
>
|
|
407
|
+
{phase === 'done' ? (
|
|
408
|
+
// The run is over: the row is a plain reply, and Stop is gone. A real app moves focus to the message box.
|
|
409
|
+
<Paragraph measure="none">{text}</Paragraph>
|
|
410
|
+
) : (
|
|
411
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
412
|
+
<Stack gap="medium">
|
|
413
|
+
{working && <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>}
|
|
414
|
+
{working && <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)} />}
|
|
415
|
+
{text !== '' && <Paragraph measure="none">{text}</Paragraph>}
|
|
416
|
+
{/* A stop before any text says nothing was written; a stop after some text keeps it. */}
|
|
417
|
+
{phase === 'stopped' && (
|
|
418
|
+
<Paragraph size="body2" tone="secondary" measure="none">
|
|
419
|
+
{text === '' ? 'Stopped. Nothing was written.' : 'Stopped before the reply was finished.'}
|
|
420
|
+
</Paragraph>
|
|
421
|
+
)}
|
|
422
|
+
</Stack>
|
|
423
|
+
)}
|
|
424
|
+
</Message>
|
|
425
|
+
</Stack>
|
|
426
|
+
</Stack>
|
|
427
|
+
</Center>
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Seen in: Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function AgentPlanProposalChanges(): import("react").JSX.Element;
|