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,224 @@
|
|
|
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 Modal from '../../components/modal';
|
|
13
|
+
import List from '../../components/list';
|
|
14
|
+
import StepList from '../../components/stepList';
|
|
15
|
+
import Textarea from '../../components/textarea';
|
|
16
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
17
|
+
var agentName = 'Acme Agent';
|
|
18
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };
|
|
19
|
+
var proposedAt = new Date('2025-01-15T11:44:00Z');
|
|
20
|
+
// ODS has no diff part yet, so the changes are a list of the files they touch, each with what changes in it.
|
|
21
|
+
var changedFiles = [
|
|
22
|
+
{ path: 'pages/pricing.tsx', change: 'Adds the Team plan to the page.' },
|
|
23
|
+
{ path: 'data/plans.json', change: 'Sets the Pro price to $15 and adds the Team plan at $25 per seat.' },
|
|
24
|
+
{ path: 'components/planTable.tsx', change: 'Adds a column for the Team plan.' },
|
|
25
|
+
];
|
|
26
|
+
// The run after 'Approve': one step per file.
|
|
27
|
+
var runSteps = changedFiles.map(function (f) { return "Change ".concat(f.path); });
|
|
28
|
+
var reply = 'The three files are changed. The pricing page shows the new plans.';
|
|
29
|
+
// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.
|
|
30
|
+
function stepsUpTo(current) {
|
|
31
|
+
return runSteps.slice(0, current + 1).map(function (label, i) { return ({ label: label, status: i < current ? 'done' : 'running' }); });
|
|
32
|
+
}
|
|
33
|
+
function secondsLine(seconds) {
|
|
34
|
+
return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
|
|
35
|
+
}
|
|
36
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
37
|
+
function agentMeta(at) {
|
|
38
|
+
return (<>
|
|
39
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
40
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
41
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
42
|
+
</>);
|
|
43
|
+
}
|
|
44
|
+
export default function AgentPlanProposalChanges() {
|
|
45
|
+
var _a = useState('open'), status = _a[0], setStatus = _a[1];
|
|
46
|
+
var _b = useState(null), pending = _b[0], setPending = _b[1];
|
|
47
|
+
var _c = useState(false), viewing = _c[0], setViewing = _c[1];
|
|
48
|
+
var _d = useState(''), draft = _d[0], setDraft = _d[1];
|
|
49
|
+
// The run after 'Approve', in its own progress row under the card.
|
|
50
|
+
var _e = useState(null), run = _e[0], setRun = _e[1];
|
|
51
|
+
var _f = useState(0), current = _f[0], setCurrent = _f[1];
|
|
52
|
+
var _g = useState(0), seconds = _g[0], setSeconds = _g[1];
|
|
53
|
+
var _h = useState(proposedAt), startedAt = _h[0], setStartedAt = _h[1];
|
|
54
|
+
var timer = useRef();
|
|
55
|
+
var tick = useRef();
|
|
56
|
+
var step = useRef();
|
|
57
|
+
var cancel = useRef();
|
|
58
|
+
var requestButton = useRef(null);
|
|
59
|
+
var stopButton = useRef(null);
|
|
60
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
61
|
+
var focusNext = useRef();
|
|
62
|
+
// On unmount it stops the requests, the run and its clock.
|
|
63
|
+
useEffect(function () { return function () {
|
|
64
|
+
clearTimeout(timer.current);
|
|
65
|
+
clearInterval(tick.current);
|
|
66
|
+
clearTimeout(step.current);
|
|
67
|
+
clearTimeout(cancel.current);
|
|
68
|
+
}; }, []);
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
var move = focusNext.current;
|
|
71
|
+
focusNext.current = undefined;
|
|
72
|
+
move === null || move === void 0 ? void 0 : move();
|
|
73
|
+
});
|
|
74
|
+
// Stands in for the agent's run: one step every 1.5 seconds.
|
|
75
|
+
function advance(at) {
|
|
76
|
+
step.current = setTimeout(function () {
|
|
77
|
+
if (at === runSteps.length - 1) {
|
|
78
|
+
clearInterval(tick.current);
|
|
79
|
+
setRun('done');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setCurrent(at + 1);
|
|
83
|
+
advance(at + 1);
|
|
84
|
+
}, 1500);
|
|
85
|
+
}
|
|
86
|
+
// The card stays as the record, and the run shows in its own progress row below it.
|
|
87
|
+
// 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.
|
|
88
|
+
function startRun() {
|
|
89
|
+
setRun('running');
|
|
90
|
+
setCurrent(0);
|
|
91
|
+
setSeconds(0);
|
|
92
|
+
setStartedAt(new Date());
|
|
93
|
+
tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
|
|
94
|
+
advance(0);
|
|
95
|
+
focusNext.current = function () { var _a; return (_a = stopButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
96
|
+
}
|
|
97
|
+
// Decided once: the buttons go away, so a second click cannot approve or cancel it again.
|
|
98
|
+
// After 'Cancel' nothing takes their place: a real app moves focus to the message box.
|
|
99
|
+
function decide(action) {
|
|
100
|
+
if (pending || status !== 'open')
|
|
101
|
+
return;
|
|
102
|
+
setPending(action);
|
|
103
|
+
// Stands in for the request to the server.
|
|
104
|
+
timer.current = setTimeout(function () {
|
|
105
|
+
setPending(null);
|
|
106
|
+
if (action === 'cancel') {
|
|
107
|
+
setStatus('cancelled');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
setStatus('approved');
|
|
111
|
+
startRun();
|
|
112
|
+
}, 1200);
|
|
113
|
+
}
|
|
114
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
115
|
+
function stop() {
|
|
116
|
+
if (run !== 'running')
|
|
117
|
+
return;
|
|
118
|
+
clearTimeout(step.current);
|
|
119
|
+
setRun('stopping');
|
|
120
|
+
// Stands in for the request to the server.
|
|
121
|
+
cancel.current = setTimeout(function () {
|
|
122
|
+
clearInterval(tick.current);
|
|
123
|
+
setRun('stopped');
|
|
124
|
+
}, 1200);
|
|
125
|
+
}
|
|
126
|
+
function startRequest() {
|
|
127
|
+
if (pending)
|
|
128
|
+
return;
|
|
129
|
+
setDraft('');
|
|
130
|
+
setStatus('requesting');
|
|
131
|
+
}
|
|
132
|
+
// 'Discard' leaves the sub-form and keeps the proposal open. 'Cancel' would cancel the whole proposal.
|
|
133
|
+
function discard() {
|
|
134
|
+
setStatus('open');
|
|
135
|
+
focusNext.current = function () { var _a; return (_a = requestButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
136
|
+
}
|
|
137
|
+
var empty = draft.trim() === '';
|
|
138
|
+
// 'Send' gives the agent what should change. The card's buttons go, and the agent redoes the changes.
|
|
139
|
+
// Nothing takes their place: a real app moves focus to the message box.
|
|
140
|
+
function send() {
|
|
141
|
+
if (pending || empty)
|
|
142
|
+
return;
|
|
143
|
+
setPending('send');
|
|
144
|
+
// Stands in for the request to the server.
|
|
145
|
+
timer.current = setTimeout(function () {
|
|
146
|
+
setPending(null);
|
|
147
|
+
setStatus('redoing');
|
|
148
|
+
}, 1200);
|
|
149
|
+
}
|
|
150
|
+
// A real app takes the count from the server's answer. Here the file that was being changed when the run
|
|
151
|
+
// stopped may be partly changed, so the note says so and does not claim it is untouched.
|
|
152
|
+
var partFile = changedFiles[current].path;
|
|
153
|
+
var stoppedNote = current === 0
|
|
154
|
+
? "Stopped before any file was done. ".concat(partFile, " may be partly changed. Check it.")
|
|
155
|
+
: "Stopped after ".concat(current, " of ").concat(runSteps.length, " files. ").concat(partFile, " may be partly changed. Check it.");
|
|
156
|
+
return (<Center width="page">
|
|
157
|
+
<Stack gap="large">
|
|
158
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
159
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
160
|
+
<Stack gap="small">
|
|
161
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
162
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
163
|
+
</Message>
|
|
164
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(proposedAt)}>
|
|
165
|
+
<Surface padding="small">
|
|
166
|
+
<Stack gap="medium">
|
|
167
|
+
{/* A real app announces the decided Tag in a polite live region. */}
|
|
168
|
+
<Cluster gap="small">
|
|
169
|
+
<Heading level={2} size="subtitle1">Changes ready</Heading>
|
|
170
|
+
{status === 'approved' && <Tag variant="contained" size="small" color="success" label="Approved"/>}
|
|
171
|
+
{status === 'cancelled' && <Tag variant="contained" size="small" label="Cancelled"/>}
|
|
172
|
+
</Cluster>
|
|
173
|
+
<Paragraph measure="none">These changes set the Pro price to $15 and add the Team plan to the pricing page. Three files change.</Paragraph>
|
|
174
|
+
{(status === 'open' || status === 'requesting') && (<Cluster>
|
|
175
|
+
<Button size="small" type="secondary" state="enabled" label="View Changes" onClickButton={function () { return setViewing(true); }}/>
|
|
176
|
+
</Cluster>)}
|
|
177
|
+
{status === 'requesting' && (<Textarea id="agent-plan-proposal-change-request" label="What should change?" value={draft} onChange={function (e) { return setDraft(e.target.value); }} onSubmit={send} autoFocus disabled={pending === 'send'}/>)}
|
|
178
|
+
{status === 'redoing' && (<Paragraph measure="none">Acme Agent is redoing the changes. It posts a new card when they are ready.</Paragraph>)}
|
|
179
|
+
{/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}
|
|
180
|
+
{(status === 'open' || status === 'requesting') && (<Paragraph size="caption" tone="secondary" measure="none">Waits 10 more minutes, then cancels.</Paragraph>)}
|
|
181
|
+
{status === 'open' && (<Cluster gap="small">
|
|
182
|
+
<Button size="small" type="tertiary" state={pending === 'approve' ? 'disabled' : 'enabled'} label="Cancel" loading={pending === 'cancel'} onClickButton={function () { return decide('cancel'); }}/>
|
|
183
|
+
<Button ref={requestButton} size="small" type="secondary" state={pending ? 'disabled' : 'enabled'} label="Request Changes" onClickButton={startRequest}/>
|
|
184
|
+
{/* The product writes this label, never the agent. */}
|
|
185
|
+
<Button size="small" type="primary" state={pending === 'cancel' ? 'disabled' : 'enabled'} label="Approve" loading={pending === 'approve'} onClickButton={function () { return decide('approve'); }}/>
|
|
186
|
+
</Cluster>)}
|
|
187
|
+
{status === 'requesting' && (<Cluster gap="small">
|
|
188
|
+
<Button size="small" type="tertiary" state={pending === 'send' ? 'disabled' : 'enabled'} label="Discard" onClickButton={discard}/>
|
|
189
|
+
<Button size="small" type="primary" state={empty ? 'disabled' : 'enabled'} label="Send" loading={pending === 'send'} onClickButton={send}/>
|
|
190
|
+
</Cluster>)}
|
|
191
|
+
</Stack>
|
|
192
|
+
</Surface>
|
|
193
|
+
</Message>
|
|
194
|
+
{status === 'cancelled' && (
|
|
195
|
+
// One line in the thread on what was not done, under the card.
|
|
196
|
+
<Message compact aria-label={"".concat(agentName, ", agent")}>
|
|
197
|
+
<Paragraph measure="none">Cancelled. Nothing was changed.</Paragraph>
|
|
198
|
+
</Message>)}
|
|
199
|
+
{run && (
|
|
200
|
+
// The run's own progress row, as the case 'Agent at work' shows.
|
|
201
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(startedAt)} footer={run === 'running' || run === 'stopping' ? (
|
|
202
|
+
// The only Stop, on the row for the whole run. It shows loading while the run is stopping.
|
|
203
|
+
// When it goes, a real app moves focus to the message box.
|
|
204
|
+
<Cluster>
|
|
205
|
+
<Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={run === 'stopping'} onClickButton={stop}/>
|
|
206
|
+
</Cluster>) : undefined}>
|
|
207
|
+
{run === 'done' ? (<Paragraph measure="none">{reply}</Paragraph>) : run === 'stopped' ? (<Paragraph measure="none">{stoppedNote}</Paragraph>) : (
|
|
208
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
209
|
+
<Stack gap="medium">
|
|
210
|
+
<Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
|
|
211
|
+
<StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)}/>
|
|
212
|
+
</Stack>)}
|
|
213
|
+
</Message>)}
|
|
214
|
+
</Stack>
|
|
215
|
+
</Stack>
|
|
216
|
+
<Modal isOpen={viewing} title="Changed Files" onClose={function () { return setViewing(false); }} actions={<Button size="small" type="tertiary" state="enabled" label="Close" onClickButton={function () { return setViewing(false); }}/>}>
|
|
217
|
+
<Paragraph measure="none">Approve changes these files.</Paragraph>
|
|
218
|
+
<List marker="dot" size="body1" items={changedFiles.map(function (f) { return (<Stack key={f.path} gap="small">
|
|
219
|
+
<Paragraph mono measure="none">{f.path}</Paragraph>
|
|
220
|
+
<Paragraph size="body2" tone="secondary" measure="none">{f.change}</Paragraph>
|
|
221
|
+
</Stack>); })}/>
|
|
222
|
+
</Modal>
|
|
223
|
+
</Center>);
|
|
224
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function AgentPlanProposalSteps(): import("react").JSX.Element;
|
|
@@ -0,0 +1,211 @@
|
|
|
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 StepList from '../../components/stepList';
|
|
13
|
+
import Textarea from '../../components/textarea';
|
|
14
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
15
|
+
var agentName = 'Acme Agent';
|
|
16
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you update the pricing page for the new plans?' };
|
|
17
|
+
var proposedAt = new Date('2025-01-15T11:41:00Z');
|
|
18
|
+
var firstSteps = [
|
|
19
|
+
'Change the Pro price from $12 to $15',
|
|
20
|
+
'Add the Team plan at $25 per seat',
|
|
21
|
+
'Update the plan table on the pricing page',
|
|
22
|
+
'Open a pull request for review',
|
|
23
|
+
];
|
|
24
|
+
var reply = 'The pricing page is updated, and the pull request is open for review.';
|
|
25
|
+
// Finished steps keep a check, the current one runs, and steps the agent has not started are not shown.
|
|
26
|
+
function stepsUpTo(steps, current) {
|
|
27
|
+
return steps.slice(0, current + 1).map(function (label, i) { return ({ label: label, status: i < current ? 'done' : 'running' }); });
|
|
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 AgentPlanProposalSteps() {
|
|
41
|
+
var _a = useState(firstSteps), steps = _a[0], setSteps = _a[1];
|
|
42
|
+
var _b = useState('open'), status = _b[0], setStatus = _b[1];
|
|
43
|
+
var _c = useState(null), pending = _c[0], setPending = _c[1];
|
|
44
|
+
var _d = useState(''), draft = _d[0], setDraft = _d[1];
|
|
45
|
+
// The run after 'Approve', in its own progress row under the card.
|
|
46
|
+
var _e = useState(null), run = _e[0], setRun = _e[1];
|
|
47
|
+
var _f = useState(0), current = _f[0], setCurrent = _f[1];
|
|
48
|
+
var _g = useState(0), seconds = _g[0], setSeconds = _g[1];
|
|
49
|
+
var _h = useState(proposedAt), startedAt = _h[0], setStartedAt = _h[1];
|
|
50
|
+
var timer = useRef();
|
|
51
|
+
var tick = useRef();
|
|
52
|
+
var step = useRef();
|
|
53
|
+
var cancel = useRef();
|
|
54
|
+
var editButton = useRef(null);
|
|
55
|
+
var stopButton = useRef(null);
|
|
56
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
57
|
+
var focusNext = useRef();
|
|
58
|
+
// On unmount it stops the requests, the run and its clock.
|
|
59
|
+
useEffect(function () { return function () {
|
|
60
|
+
clearTimeout(timer.current);
|
|
61
|
+
clearInterval(tick.current);
|
|
62
|
+
clearTimeout(step.current);
|
|
63
|
+
clearTimeout(cancel.current);
|
|
64
|
+
}; }, []);
|
|
65
|
+
useEffect(function () {
|
|
66
|
+
var move = focusNext.current;
|
|
67
|
+
focusNext.current = undefined;
|
|
68
|
+
move === null || move === void 0 ? void 0 : move();
|
|
69
|
+
});
|
|
70
|
+
// Stands in for the agent's run: one step every 1.5 seconds.
|
|
71
|
+
function advance(at) {
|
|
72
|
+
step.current = setTimeout(function () {
|
|
73
|
+
if (at === steps.length - 1) {
|
|
74
|
+
clearInterval(tick.current);
|
|
75
|
+
setRun('done');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
setCurrent(at + 1);
|
|
79
|
+
advance(at + 1);
|
|
80
|
+
}, 1500);
|
|
81
|
+
}
|
|
82
|
+
// The card stays as the record, and the run shows in its own progress row below it.
|
|
83
|
+
// 'Approve' is gone and 'Stop' is the control that took its place, so focus goes to 'Stop'.
|
|
84
|
+
function startRun() {
|
|
85
|
+
setRun('running');
|
|
86
|
+
setCurrent(0);
|
|
87
|
+
setSeconds(0);
|
|
88
|
+
setStartedAt(new Date());
|
|
89
|
+
tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
|
|
90
|
+
advance(0);
|
|
91
|
+
focusNext.current = function () { var _a; return (_a = stopButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
92
|
+
}
|
|
93
|
+
// Decided once: the buttons go away, so a second click cannot approve or cancel it again.
|
|
94
|
+
// After 'Cancel' nothing takes their place: a real app moves focus to the message box.
|
|
95
|
+
function decide(action) {
|
|
96
|
+
if (pending || status !== 'open')
|
|
97
|
+
return;
|
|
98
|
+
setPending(action);
|
|
99
|
+
// Stands in for the request to the server.
|
|
100
|
+
timer.current = setTimeout(function () {
|
|
101
|
+
setPending(null);
|
|
102
|
+
if (action === 'cancel') {
|
|
103
|
+
setStatus('cancelled');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
setStatus('approved');
|
|
107
|
+
startRun();
|
|
108
|
+
}, 1200);
|
|
109
|
+
}
|
|
110
|
+
// Stop asks the server to end the run. The row says it stopped only once the run has ended.
|
|
111
|
+
function stop() {
|
|
112
|
+
if (run !== 'running')
|
|
113
|
+
return;
|
|
114
|
+
clearTimeout(step.current);
|
|
115
|
+
setRun('stopping');
|
|
116
|
+
// Stands in for the request to the server.
|
|
117
|
+
cancel.current = setTimeout(function () {
|
|
118
|
+
clearInterval(tick.current);
|
|
119
|
+
setRun('stopped');
|
|
120
|
+
}, 1200);
|
|
121
|
+
}
|
|
122
|
+
function startEditing() {
|
|
123
|
+
if (pending)
|
|
124
|
+
return;
|
|
125
|
+
setDraft(steps.join('\n'));
|
|
126
|
+
setStatus('editing');
|
|
127
|
+
}
|
|
128
|
+
// 'Discard' leaves the edit and keeps the plan as it was. 'Cancel' would cancel the whole proposal.
|
|
129
|
+
function discard() {
|
|
130
|
+
setStatus('open');
|
|
131
|
+
focusNext.current = function () { var _a; return (_a = editButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
132
|
+
}
|
|
133
|
+
var draftSteps = draft.split('\n').map(function (s) { return s.trim(); }).filter(function (s) { return s !== ''; });
|
|
134
|
+
// 'Save' sends the edited steps to the agent. The plan comes back with them, still waiting for a yes.
|
|
135
|
+
function save() {
|
|
136
|
+
if (pending || draftSteps.length === 0)
|
|
137
|
+
return;
|
|
138
|
+
setPending('save');
|
|
139
|
+
// Stands in for the request to the server.
|
|
140
|
+
timer.current = setTimeout(function () {
|
|
141
|
+
setPending(null);
|
|
142
|
+
setSteps(draftSteps);
|
|
143
|
+
setStatus('open');
|
|
144
|
+
focusNext.current = function () { var _a; return (_a = editButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
145
|
+
}, 1200);
|
|
146
|
+
}
|
|
147
|
+
// A stop says how far the run got, so it never says nothing changed when something did.
|
|
148
|
+
// A real app takes the count from the server's answer, not from the list on screen.
|
|
149
|
+
var stoppedNote = current === 0
|
|
150
|
+
? 'Stopped. Nothing was changed.'
|
|
151
|
+
: "Stopped after ".concat(current, " of ").concat(steps.length, " steps. The rest of the plan was not done.");
|
|
152
|
+
return (<Center width="page">
|
|
153
|
+
<Stack gap="large">
|
|
154
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
155
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
156
|
+
<Stack gap="small">
|
|
157
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
158
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
159
|
+
</Message>
|
|
160
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(proposedAt)}>
|
|
161
|
+
<Surface padding="small">
|
|
162
|
+
<Stack gap="medium">
|
|
163
|
+
{/* A real app announces the decided Tag in a polite live region. */}
|
|
164
|
+
<Cluster gap="small">
|
|
165
|
+
<Heading level={2} size="subtitle1">Proposed plan</Heading>
|
|
166
|
+
{status === 'approved' && <Tag variant="contained" size="small" color="success" label="Approved"/>}
|
|
167
|
+
{status === 'cancelled' && <Tag variant="contained" size="small" label="Cancelled"/>}
|
|
168
|
+
</Cluster>
|
|
169
|
+
{status === 'editing' ? (<Textarea id="agent-plan-proposal-steps" label="Steps, one per line" value={draft} onChange={function (e) { return setDraft(e.target.value); }} onSubmit={save} autoFocus maxRows={10} disabled={pending === 'save'}/>) : (
|
|
170
|
+
// Every step, in the order the agent will do them. Once decided, the card is the record:
|
|
171
|
+
// an approved plan keeps its steps as they were, and a cancelled one marks each step cancelled.
|
|
172
|
+
<StepList numbered aria-label="Proposed plan" steps={steps.map(function (label) { return ({ label: label, status: status === 'cancelled' ? 'cancelled' : 'waiting' }); })}/>)}
|
|
173
|
+
{/* The product sets the waiting time and counts it down. When it is up, the card is marked Cancelled. */}
|
|
174
|
+
{(status === 'open' || status === 'editing') && (<Paragraph size="caption" tone="secondary" measure="none">Waits 10 more minutes, then cancels.</Paragraph>)}
|
|
175
|
+
{status === 'open' && (<Cluster gap="small">
|
|
176
|
+
<Button size="small" type="tertiary" state={pending === 'approve' ? 'disabled' : 'enabled'} label="Cancel" loading={pending === 'cancel'} onClickButton={function () { return decide('cancel'); }}/>
|
|
177
|
+
<Button ref={editButton} size="small" type="secondary" state={pending ? 'disabled' : 'enabled'} label="Edit" onClickButton={startEditing}/>
|
|
178
|
+
{/* The product writes this label, never the agent. */}
|
|
179
|
+
<Button size="small" type="primary" state={pending === 'cancel' ? 'disabled' : 'enabled'} label="Approve" loading={pending === 'approve'} onClickButton={function () { return decide('approve'); }}/>
|
|
180
|
+
</Cluster>)}
|
|
181
|
+
{status === 'editing' && (<Cluster gap="small">
|
|
182
|
+
<Button size="small" type="tertiary" state={pending === 'save' ? 'disabled' : 'enabled'} label="Discard" onClickButton={discard}/>
|
|
183
|
+
<Button size="small" type="primary" state={draftSteps.length === 0 ? 'disabled' : 'enabled'} label="Save" loading={pending === 'save'} onClickButton={save}/>
|
|
184
|
+
</Cluster>)}
|
|
185
|
+
</Stack>
|
|
186
|
+
</Surface>
|
|
187
|
+
</Message>
|
|
188
|
+
{status === 'cancelled' && (
|
|
189
|
+
// One line in the thread on what was not done, under the card.
|
|
190
|
+
<Message compact aria-label={"".concat(agentName, ", agent")}>
|
|
191
|
+
<Paragraph measure="none">Cancelled. Nothing was changed.</Paragraph>
|
|
192
|
+
</Message>)}
|
|
193
|
+
{run && (
|
|
194
|
+
// The run's own progress row, as the case 'Agent at work' shows.
|
|
195
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(startedAt)} footer={run === 'running' || run === 'stopping' ? (
|
|
196
|
+
// The only Stop, on the row for the whole run. It shows loading while the run is stopping.
|
|
197
|
+
// When it goes, a real app moves focus to the message box.
|
|
198
|
+
<Cluster>
|
|
199
|
+
<Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={run === 'stopping'} onClickButton={stop}/>
|
|
200
|
+
</Cluster>) : undefined}>
|
|
201
|
+
{run === 'done' ? (<Paragraph measure="none">{reply}</Paragraph>) : run === 'stopped' ? (<Paragraph measure="none">{stoppedNote}</Paragraph>) : (
|
|
202
|
+
// A real app wraps this part in a polite live region, since StepList has none.
|
|
203
|
+
<Stack gap="medium">
|
|
204
|
+
<Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
|
|
205
|
+
<StepList aria-label="Acme Agent's steps" steps={stepsUpTo(steps, current)}/>
|
|
206
|
+
</Stack>)}
|
|
207
|
+
</Message>)}
|
|
208
|
+
</Stack>
|
|
209
|
+
</Stack>
|
|
210
|
+
</Center>);
|
|
211
|
+
}
|