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