paseo-office 0.2.5 → 0.2.7
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/client/activity-panel.tsx +10 -1
- package/client/alert-card.tsx +195 -0
- package/client/host-switches.tsx +50 -0
- package/client/office-surface.tsx +79 -10
- package/client/timeline-open.ts +3 -0
- package/client/use-alerts.ts +71 -0
- package/client/vault-card.tsx +316 -0
- package/docs/office.md +49 -0
- package/index.server.ts +92 -2
- package/package.json +1 -1
- package/server/live-ports.ts +7 -0
- package/server/paths.ts +5 -0
- package/server/vault.ts +168 -0
- package/server/watchers.ts +308 -0
- package/shared/alerts.ts +48 -0
- package/shared/contracts.ts +40 -0
- package/shared/settings.ts +7 -1
- package/shared/vault.ts +127 -0
|
@@ -4,7 +4,7 @@ import { ScrollView } from "@getpaseo/plugin/client/ui";
|
|
|
4
4
|
import type { OfficeAgent } from "../shared/contracts.js";
|
|
5
5
|
import { dotTone, type DotTone } from "../shared/model.js";
|
|
6
6
|
import { ActionButton } from "./action-button.js";
|
|
7
|
-
import { OpenTimelineContext } from "./timeline-open.js";
|
|
7
|
+
import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
|
|
8
8
|
import {
|
|
9
9
|
feedCards,
|
|
10
10
|
feedStore,
|
|
@@ -226,6 +226,7 @@ export function ActivityPanel({ office, styles, link, layout }: ColumnPanelProps
|
|
|
226
226
|
const problem = loadProblem(subscription);
|
|
227
227
|
// What the agents did before now: the lanes, their replay and the week.
|
|
228
228
|
const openTimeline = useContext(OpenTimelineContext);
|
|
229
|
+
const openHistory = useContext(OpenHistoryContext);
|
|
229
230
|
return (
|
|
230
231
|
<View style={styles.screen}>
|
|
231
232
|
<ScrollView contentContainerStyle={styles.panelFeed}>
|
|
@@ -250,6 +251,14 @@ export function ActivityPanel({ office, styles, link, layout }: ColumnPanelProps
|
|
|
250
251
|
styles={styles}
|
|
251
252
|
/>
|
|
252
253
|
) : null}
|
|
254
|
+
{openHistory ? (
|
|
255
|
+
<ActionButton
|
|
256
|
+
label="History"
|
|
257
|
+
pendingLabel="History"
|
|
258
|
+
onPress={openHistory}
|
|
259
|
+
styles={styles}
|
|
260
|
+
/>
|
|
261
|
+
) : null}
|
|
253
262
|
</View>
|
|
254
263
|
<View role="group" aria-label="Feed" style={styles.activityTabs}>
|
|
255
264
|
<Pill<FeedTab>
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import { Icon, TextInput } from "@getpaseo/plugin/client/ui";
|
|
4
|
+
import {
|
|
5
|
+
HINT_MAX,
|
|
6
|
+
checksNote,
|
|
7
|
+
clashNote,
|
|
8
|
+
portNote,
|
|
9
|
+
type Alert,
|
|
10
|
+
type AlertKind,
|
|
11
|
+
} from "../shared/alerts.js";
|
|
12
|
+
import type { Machine } from "../shared/contracts.js";
|
|
13
|
+
import { ActionButton } from "./action-button.js";
|
|
14
|
+
import { OfficeModal as Modal } from "./office-modal.js";
|
|
15
|
+
import type { OfficeStyles } from "./styles.js";
|
|
16
|
+
import type { AgentActions } from "./use-agent-actions.js";
|
|
17
|
+
|
|
18
|
+
const layout = StyleSheet.create({
|
|
19
|
+
row: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 },
|
|
20
|
+
field: { flex: 1, minWidth: 160 },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const STEER = { activeTurnBehavior: "steer" } as const;
|
|
24
|
+
|
|
25
|
+
const ABOUT: Readonly<Record<AlertKind, string>> = {
|
|
26
|
+
loop: "Stop ends its turn. A hint is sent into the turn, so the agent reads it without starting over.",
|
|
27
|
+
refused:
|
|
28
|
+
"The provider's auto mode refused this call. The agent was told and goes on; nothing is waiting for you.",
|
|
29
|
+
clash: "Tell both sends each a line about the other, into its turn.",
|
|
30
|
+
port: "Tell the agent sends it a line to use another port, into its turn.",
|
|
31
|
+
checks: "Fix it sends the failing checks to an agent of this workspace that is resting.",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface AlertCardProps {
|
|
35
|
+
/** The alert to show; null closes the card. */
|
|
36
|
+
alert: Alert | null;
|
|
37
|
+
/** The office's name for an agent, for a line sent to another one. */
|
|
38
|
+
nameOf(agentId: string): string;
|
|
39
|
+
/** The host's readings: who holds a port. */
|
|
40
|
+
machine: Machine | null;
|
|
41
|
+
actions: AgentActions;
|
|
42
|
+
styles: OfficeStyles;
|
|
43
|
+
onClose(): void;
|
|
44
|
+
onDismiss(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ActProps extends Omit<AlertCardProps, "alert" | "onClose"> {
|
|
48
|
+
alert: Alert;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The loop's: stop the turn, or send a hint into it. */
|
|
52
|
+
function LoopActions({ alert, actions, styles, onDismiss }: ActProps) {
|
|
53
|
+
const [hint, setHint] = useState("");
|
|
54
|
+
const agentId = alert.agentId ?? "";
|
|
55
|
+
const { cancel } = actions;
|
|
56
|
+
const stop = useCallback(async () => {
|
|
57
|
+
await cancel?.(agentId);
|
|
58
|
+
await onDismiss();
|
|
59
|
+
}, [cancel, agentId, onDismiss]);
|
|
60
|
+
const send = useCallback(async () => {
|
|
61
|
+
await actions.send(agentId, hint.trim().slice(0, HINT_MAX), STEER);
|
|
62
|
+
await onDismiss();
|
|
63
|
+
}, [actions, agentId, hint, onDismiss]);
|
|
64
|
+
const field = useMemo(() => [styles.fieldInput, layout.field], [styles]);
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<View style={layout.row}>
|
|
68
|
+
<TextInput
|
|
69
|
+
accessibilityLabel="Hint for the agent"
|
|
70
|
+
value={hint}
|
|
71
|
+
onChangeText={setHint}
|
|
72
|
+
placeholder="What it should try instead"
|
|
73
|
+
maxLength={HINT_MAX}
|
|
74
|
+
style={field}
|
|
75
|
+
/>
|
|
76
|
+
<ActionButton
|
|
77
|
+
label="Send a hint"
|
|
78
|
+
pendingLabel="Sending..."
|
|
79
|
+
onPress={send}
|
|
80
|
+
disabled={hint.trim() === ""}
|
|
81
|
+
styles={styles}
|
|
82
|
+
primary
|
|
83
|
+
/>
|
|
84
|
+
</View>
|
|
85
|
+
{cancel ? (
|
|
86
|
+
<ActionButton label="Stop" pendingLabel="Stopping..." onPress={stop} styles={styles} />
|
|
87
|
+
) : null}
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** What is sent to whom for an alert that is answered with one line; null when there is nobody to send to. */
|
|
93
|
+
function linesOf({
|
|
94
|
+
alert,
|
|
95
|
+
nameOf,
|
|
96
|
+
machine,
|
|
97
|
+
}: ActProps): { label: string; to: [string, string][] } | null {
|
|
98
|
+
const { agentId, otherAgentId } = alert;
|
|
99
|
+
if (agentId === undefined) return null;
|
|
100
|
+
if (alert.kind === "clash" && otherAgentId !== undefined) {
|
|
101
|
+
// (the alert's title names the file only when the host may name files)
|
|
102
|
+
const file = /are in (.+)$/.exec(alert.title)?.[1] ?? "the same file";
|
|
103
|
+
return {
|
|
104
|
+
label: "Tell both",
|
|
105
|
+
to: [
|
|
106
|
+
[agentId, clashNote(file, nameOf(otherAgentId))],
|
|
107
|
+
[otherAgentId, clashNote(file, nameOf(agentId))],
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (alert.kind === "port" && alert.port !== undefined) {
|
|
112
|
+
const { port } = alert;
|
|
113
|
+
const holder = machine?.agents.find(
|
|
114
|
+
(held) => held.agentId !== agentId && held.ports.includes(port),
|
|
115
|
+
);
|
|
116
|
+
const name = holder === undefined ? null : nameOf(holder.agentId);
|
|
117
|
+
return { label: "Tell the agent", to: [[agentId, portNote(port, name)]] };
|
|
118
|
+
}
|
|
119
|
+
if (alert.kind === "checks") {
|
|
120
|
+
return { label: "Fix it", to: [[agentId, checksNote(alert.detail)]] };
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function LineAction(props: ActProps) {
|
|
126
|
+
const { alert, actions, styles, onDismiss } = props;
|
|
127
|
+
const lines = linesOf(props);
|
|
128
|
+
const send = useCallback(async () => {
|
|
129
|
+
if (lines === null) return;
|
|
130
|
+
// Failing checks go to a resting agent as its prompt; the rest join a running turn.
|
|
131
|
+
const options = alert.kind === "checks" ? undefined : STEER;
|
|
132
|
+
await Promise.all(lines.to.map(([agentId, text]) => actions.send(agentId, text, options)));
|
|
133
|
+
await onDismiss();
|
|
134
|
+
}, [lines, alert.kind, actions, onDismiss]);
|
|
135
|
+
if (alert.kind === "refused") return null;
|
|
136
|
+
if (lines === null) {
|
|
137
|
+
return <Text style={styles.host.note}>No agent of this workspace is resting now.</Text>;
|
|
138
|
+
}
|
|
139
|
+
return (
|
|
140
|
+
<ActionButton
|
|
141
|
+
label={lines.label}
|
|
142
|
+
pendingLabel="Sending..."
|
|
143
|
+
onPress={send}
|
|
144
|
+
styles={styles}
|
|
145
|
+
primary
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** One thing the office noticed, with what can be done about it. */
|
|
151
|
+
export function AlertCard({ alert, onClose, ...rest }: AlertCardProps) {
|
|
152
|
+
const { styles, onDismiss } = rest;
|
|
153
|
+
const change = useCallback(
|
|
154
|
+
(next: boolean) => {
|
|
155
|
+
if (!next) onClose();
|
|
156
|
+
},
|
|
157
|
+
[onClose],
|
|
158
|
+
);
|
|
159
|
+
const icon = useMemo(
|
|
160
|
+
() => <Icon name="TriangleAlert" size={18} color={String(styles.host.label.color)} />,
|
|
161
|
+
[styles],
|
|
162
|
+
);
|
|
163
|
+
return (
|
|
164
|
+
<Modal icon={icon} title="Noticed" open={alert !== null} onOpenChange={change}>
|
|
165
|
+
<Modal.Content>
|
|
166
|
+
{alert !== null && (
|
|
167
|
+
<View style={styles.host.body}>
|
|
168
|
+
<View style={styles.host.group}>
|
|
169
|
+
<Text accessibilityRole="header" style={styles.host.title}>
|
|
170
|
+
{alert.title}
|
|
171
|
+
</Text>
|
|
172
|
+
{alert.detail !== "" && (
|
|
173
|
+
<Text selectable style={styles.rowMeta}>
|
|
174
|
+
{alert.detail}
|
|
175
|
+
</Text>
|
|
176
|
+
)}
|
|
177
|
+
<Text style={styles.host.note}>{ABOUT[alert.kind]}</Text>
|
|
178
|
+
</View>
|
|
179
|
+
{alert.kind === "loop" ? (
|
|
180
|
+
<LoopActions alert={alert} {...rest} />
|
|
181
|
+
) : (
|
|
182
|
+
<LineAction alert={alert} {...rest} />
|
|
183
|
+
)}
|
|
184
|
+
<ActionButton
|
|
185
|
+
label="Dismiss"
|
|
186
|
+
pendingLabel="Dismissing..."
|
|
187
|
+
onPress={onDismiss}
|
|
188
|
+
styles={styles}
|
|
189
|
+
/>
|
|
190
|
+
</View>
|
|
191
|
+
)}
|
|
192
|
+
</Modal.Content>
|
|
193
|
+
</Modal>
|
|
194
|
+
);
|
|
195
|
+
}
|
package/client/host-switches.tsx
CHANGED
|
@@ -33,6 +33,8 @@ type HostSetting =
|
|
|
33
33
|
| "Archive idle sessions"
|
|
34
34
|
| "Agent tools"
|
|
35
35
|
| "Streamer mode"
|
|
36
|
+
| "History vault"
|
|
37
|
+
| "Pinned notes"
|
|
36
38
|
| "Sticky notes"
|
|
37
39
|
| "Notes folder"
|
|
38
40
|
| "Time zone"
|
|
@@ -256,6 +258,7 @@ export function HostSwitches({
|
|
|
256
258
|
saveProblem={saveProblem}
|
|
257
259
|
styles={styles}
|
|
258
260
|
/>
|
|
261
|
+
<PinnedNotes values={stored} change={change} saveProblem={saveProblem} styles={styles} />
|
|
259
262
|
<Text style={styles.sheetLabel}>Stand-up schedule</Text>
|
|
260
263
|
<View style={styles.headerFields}>
|
|
261
264
|
<SettingField
|
|
@@ -447,6 +450,11 @@ function FloorSettings({
|
|
|
447
450
|
[change],
|
|
448
451
|
);
|
|
449
452
|
const problem = saveProblem("Streamer mode");
|
|
453
|
+
const toggleVault = useCallback(
|
|
454
|
+
(next: boolean) => void change("History vault", { historyVault: next }),
|
|
455
|
+
[change],
|
|
456
|
+
);
|
|
457
|
+
const vaultProblem = saveProblem("History vault");
|
|
450
458
|
return (
|
|
451
459
|
<View style={settingsLayout.block}>
|
|
452
460
|
{stored && (
|
|
@@ -466,6 +474,24 @@ function FloorSettings({
|
|
|
466
474
|
{problem}
|
|
467
475
|
</Text>
|
|
468
476
|
)}
|
|
477
|
+
{stored && (
|
|
478
|
+
<LabeledSwitch
|
|
479
|
+
label="History vault"
|
|
480
|
+
value={stored.historyVault}
|
|
481
|
+
onChange={toggleVault}
|
|
482
|
+
styles={styles}
|
|
483
|
+
/>
|
|
484
|
+
)}
|
|
485
|
+
<Text style={styles.fieldHint}>
|
|
486
|
+
Off by default. On, the office keeps the prompts and the replies of each conversation in a
|
|
487
|
+
file on this host, readable by its owner only, so they can be searched from History after
|
|
488
|
+
the agent is gone.
|
|
489
|
+
</Text>
|
|
490
|
+
{vaultProblem && (
|
|
491
|
+
<Text accessibilityRole="alert" style={styles.actionError}>
|
|
492
|
+
{vaultProblem}
|
|
493
|
+
</Text>
|
|
494
|
+
)}
|
|
469
495
|
<SettingField
|
|
470
496
|
label="Sticky notes"
|
|
471
497
|
hint={`Your notes on the 3D whiteboard, with ; between them. Up to ${STICKY_NOTES_MAX}, ${STICKY_NOTE_MAX} characters each.`}
|
|
@@ -478,6 +504,30 @@ function FloorSettings({
|
|
|
478
504
|
);
|
|
479
505
|
}
|
|
480
506
|
|
|
507
|
+
function PinnedNotes({
|
|
508
|
+
values: stored,
|
|
509
|
+
change,
|
|
510
|
+
saveProblem,
|
|
511
|
+
styles,
|
|
512
|
+
}: Omit<TrackerFieldsProps, "incidents">) {
|
|
513
|
+
const save = useCallback(
|
|
514
|
+
(next: string) => change("Pinned notes", { pinnedNotes: next }),
|
|
515
|
+
[change],
|
|
516
|
+
);
|
|
517
|
+
return (
|
|
518
|
+
<View style={styles.headerFields}>
|
|
519
|
+
<SettingField
|
|
520
|
+
label="Pinned notes"
|
|
521
|
+
hint="Said again to an agent whose conversation is compacted during a turn, so a rule you gave it is not lost. Empty says nothing."
|
|
522
|
+
value={stored?.pinnedNotes ?? null}
|
|
523
|
+
onSave={save}
|
|
524
|
+
problem={saveProblem("Pinned notes")}
|
|
525
|
+
styles={styles}
|
|
526
|
+
/>
|
|
527
|
+
</View>
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
481
531
|
function ArchiveSetting({
|
|
482
532
|
values: stored,
|
|
483
533
|
change,
|
|
@@ -61,7 +61,10 @@ import { incidentsEntry } from "./incidents-text.js";
|
|
|
61
61
|
import { janitorNote, janitorRows } from "./context-text.js";
|
|
62
62
|
import { JanitorCard } from "./janitor-card.js";
|
|
63
63
|
import { TimelineCard } from "./timeline-card.js";
|
|
64
|
-
import { OpenTimelineContext } from "./timeline-open.js";
|
|
64
|
+
import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
|
|
65
|
+
import { VaultCard } from "./vault-card.js";
|
|
66
|
+
import { AlertCard } from "./alert-card.js";
|
|
67
|
+
import { useAlerts } from "./use-alerts.js";
|
|
65
68
|
import { useSshServers } from "./ssh-hosts.js";
|
|
66
69
|
import { MachineCard } from "./machine-card.js";
|
|
67
70
|
import { hostNote, memoryPercent, namedMachine, type HostNote } from "../shared/machine-text.js";
|
|
@@ -876,6 +879,7 @@ interface ViewControlsProps {
|
|
|
876
879
|
machine: Machine | null;
|
|
877
880
|
onMachine?: () => void;
|
|
878
881
|
onTimeline?: () => void;
|
|
882
|
+
onHistory?: () => void;
|
|
879
883
|
onChange(next: OfficeViewChoice): void;
|
|
880
884
|
compact: boolean;
|
|
881
885
|
touchScreen: boolean;
|
|
@@ -926,6 +930,48 @@ function HostResourceButton({
|
|
|
926
930
|
);
|
|
927
931
|
}
|
|
928
932
|
|
|
933
|
+
/** The toolbar's buttons for what was: the timeline and the history, each while it is offered. */
|
|
934
|
+
function PastButtons({
|
|
935
|
+
onTimeline,
|
|
936
|
+
onHistory,
|
|
937
|
+
size,
|
|
938
|
+
color,
|
|
939
|
+
styles,
|
|
940
|
+
}: {
|
|
941
|
+
onTimeline: (() => void) | undefined;
|
|
942
|
+
onHistory: (() => void) | undefined;
|
|
943
|
+
size: number;
|
|
944
|
+
color: string;
|
|
945
|
+
styles: OfficeStyles;
|
|
946
|
+
}) {
|
|
947
|
+
return (
|
|
948
|
+
<>
|
|
949
|
+
{onTimeline ? (
|
|
950
|
+
<PanelButton
|
|
951
|
+
label="Timeline"
|
|
952
|
+
icon="History"
|
|
953
|
+
screenId="timeline"
|
|
954
|
+
size={size}
|
|
955
|
+
color={color}
|
|
956
|
+
onOpen={onTimeline}
|
|
957
|
+
styles={styles}
|
|
958
|
+
/>
|
|
959
|
+
) : null}
|
|
960
|
+
{onHistory ? (
|
|
961
|
+
<PanelButton
|
|
962
|
+
label="History"
|
|
963
|
+
icon="Archive"
|
|
964
|
+
screenId="history"
|
|
965
|
+
size={size}
|
|
966
|
+
color={color}
|
|
967
|
+
onOpen={onHistory}
|
|
968
|
+
styles={styles}
|
|
969
|
+
/>
|
|
970
|
+
) : null}
|
|
971
|
+
</>
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
|
|
929
975
|
/** The view switch and the settings button. */
|
|
930
976
|
function ViewControls({
|
|
931
977
|
keyboardVisible,
|
|
@@ -940,6 +986,7 @@ function ViewControls({
|
|
|
940
986
|
machine,
|
|
941
987
|
onMachine,
|
|
942
988
|
onTimeline,
|
|
989
|
+
onHistory,
|
|
943
990
|
onChange,
|
|
944
991
|
compact,
|
|
945
992
|
touchScreen,
|
|
@@ -982,14 +1029,12 @@ function ViewControls({
|
|
|
982
1029
|
styles={styles}
|
|
983
1030
|
/>
|
|
984
1031
|
)}
|
|
985
|
-
{sidebars
|
|
986
|
-
<
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
screenId="timeline"
|
|
1032
|
+
{sidebars ? (
|
|
1033
|
+
<PastButtons
|
|
1034
|
+
onTimeline={onTimeline}
|
|
1035
|
+
onHistory={onHistory}
|
|
990
1036
|
size={touchScreen ? 20 : 16}
|
|
991
1037
|
color={color}
|
|
992
|
-
onOpen={onTimeline}
|
|
993
1038
|
styles={styles}
|
|
994
1039
|
/>
|
|
995
1040
|
) : null}
|
|
@@ -1796,23 +1841,27 @@ function OfficeContexts({
|
|
|
1796
1841
|
brand,
|
|
1797
1842
|
planUsage,
|
|
1798
1843
|
onTimeline,
|
|
1844
|
+
onHistory,
|
|
1799
1845
|
children,
|
|
1800
1846
|
}: {
|
|
1801
1847
|
brand: OfficeState["state"]["brand"];
|
|
1802
1848
|
planUsage: readonly PlanUsage[];
|
|
1803
1849
|
onTimeline: (() => void) | undefined;
|
|
1850
|
+
onHistory: (() => void) | undefined;
|
|
1804
1851
|
children: ReactNode;
|
|
1805
1852
|
}) {
|
|
1806
1853
|
return (
|
|
1807
1854
|
<OfficeBrandContext.Provider value={brand}>
|
|
1808
1855
|
<PlanUsageContext.Provider value={planUsage}>
|
|
1809
|
-
<OpenTimelineContext.Provider value={onTimeline}>
|
|
1856
|
+
<OpenTimelineContext.Provider value={onTimeline}>
|
|
1857
|
+
<OpenHistoryContext.Provider value={onHistory}>{children}</OpenHistoryContext.Provider>
|
|
1858
|
+
</OpenTimelineContext.Provider>
|
|
1810
1859
|
</PlanUsageContext.Provider>
|
|
1811
1860
|
</OfficeBrandContext.Provider>
|
|
1812
1861
|
);
|
|
1813
1862
|
}
|
|
1814
1863
|
|
|
1815
|
-
/**
|
|
1864
|
+
/** A card of the toolbar's, the timeline's or the history's: offered and shown only while the office's data is live. */
|
|
1816
1865
|
function useTimelineCard(live: boolean) {
|
|
1817
1866
|
const [open, setOpen] = useState(false);
|
|
1818
1867
|
const show = useCallback(() => setOpen(true), []);
|
|
@@ -1898,6 +1947,8 @@ export function OfficeSurface(
|
|
|
1898
1947
|
);
|
|
1899
1948
|
const planUsage = usePlanUsage(live);
|
|
1900
1949
|
const timeline = useTimelineCard(live);
|
|
1950
|
+
const history = useTimelineCard(live);
|
|
1951
|
+
const alerts = useAlerts(live);
|
|
1901
1952
|
const board = useBoardSheet(model, live);
|
|
1902
1953
|
const dutyCard = useCardOpening(live);
|
|
1903
1954
|
// Until the host sends its duty list (an older host has none) nothing offers the duty board.
|
|
@@ -2027,6 +2078,7 @@ export function OfficeSurface(
|
|
|
2027
2078
|
() =>
|
|
2028
2079
|
[
|
|
2029
2080
|
incidentsStripEntry,
|
|
2081
|
+
...alerts.cards,
|
|
2030
2082
|
settingsStripEntry,
|
|
2031
2083
|
weatherStripEntry,
|
|
2032
2084
|
hostEntry,
|
|
@@ -2038,6 +2090,7 @@ export function OfficeSurface(
|
|
|
2038
2090
|
].filter((card) => card !== null),
|
|
2039
2091
|
[
|
|
2040
2092
|
incidentsStripEntry,
|
|
2093
|
+
alerts.cards,
|
|
2041
2094
|
settingsStripEntry,
|
|
2042
2095
|
weatherStripEntry,
|
|
2043
2096
|
hostEntry,
|
|
@@ -2116,6 +2169,7 @@ export function OfficeSurface(
|
|
|
2116
2169
|
machine={machine}
|
|
2117
2170
|
onMachine={hostEntry?.onOpen}
|
|
2118
2171
|
onTimeline={timeline.onOpen}
|
|
2172
|
+
onHistory={history.onOpen}
|
|
2119
2173
|
onChange={changeView}
|
|
2120
2174
|
compact={compact}
|
|
2121
2175
|
touchScreen={touchScreen}
|
|
@@ -2247,6 +2301,16 @@ export function OfficeSurface(
|
|
|
2247
2301
|
onClose={closeMachine}
|
|
2248
2302
|
/>
|
|
2249
2303
|
<TimelineCard open={timeline.open} styles={styles} onClose={timeline.close} />
|
|
2304
|
+
<VaultCard open={history.open} styles={styles} onClose={history.close} />
|
|
2305
|
+
<AlertCard
|
|
2306
|
+
alert={alerts.open}
|
|
2307
|
+
nameOf={name}
|
|
2308
|
+
machine={machine}
|
|
2309
|
+
actions={actions}
|
|
2310
|
+
styles={styles}
|
|
2311
|
+
onClose={alerts.close}
|
|
2312
|
+
onDismiss={alerts.dismiss}
|
|
2313
|
+
/>
|
|
2250
2314
|
<JanitorCard
|
|
2251
2315
|
rows={contexts}
|
|
2252
2316
|
open={janitorOpen && live}
|
|
@@ -2357,7 +2421,12 @@ export function OfficeSurface(
|
|
|
2357
2421
|
</View>
|
|
2358
2422
|
);
|
|
2359
2423
|
return (
|
|
2360
|
-
<OfficeContexts
|
|
2424
|
+
<OfficeContexts
|
|
2425
|
+
brand={office.state.brand}
|
|
2426
|
+
planUsage={planUsage}
|
|
2427
|
+
onTimeline={timeline.onOpen}
|
|
2428
|
+
onHistory={history.onOpen}
|
|
2429
|
+
>
|
|
2361
2430
|
<OfficeDialogs fullscreen={full.integrated} theme={theme} styles={styles}>
|
|
2362
2431
|
{surface}
|
|
2363
2432
|
</OfficeDialogs>
|
package/client/timeline-open.ts
CHANGED
|
@@ -2,3 +2,6 @@ import { createContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
/** Opens the Timeline card; absent while the office's data is not live. */
|
|
4
4
|
export const OpenTimelineContext = createContext<(() => void) | undefined>(undefined);
|
|
5
|
+
|
|
6
|
+
/** Opens the History card; absent while the office's data is not live. */
|
|
7
|
+
export const OpenHistoryContext = createContext<(() => void) | undefined>(undefined);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
3
|
+
import type { Alert } from "../shared/alerts.js";
|
|
4
|
+
import { alertDismissRpc, alertsRpc } from "../shared/contracts.js";
|
|
5
|
+
import type { StripCard } from "./attention-strip.js";
|
|
6
|
+
|
|
7
|
+
const NO_ALERTS: readonly Alert[] = [];
|
|
8
|
+
/** The office's own reads are 5 s apart: asking every other one is soon enough. */
|
|
9
|
+
const EVERY_MS = 10_000;
|
|
10
|
+
|
|
11
|
+
export interface AlertsState {
|
|
12
|
+
/** A card of the Attention strip for each alert, newest first. */
|
|
13
|
+
cards: StripCard[];
|
|
14
|
+
/** The alert whose card is open; null when none is, and once it is gone. */
|
|
15
|
+
open: Alert | null;
|
|
16
|
+
close(): void;
|
|
17
|
+
/** Dismisses the open alert and closes its card. */
|
|
18
|
+
dismiss(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What the office noticed, asked for while `live`, as cards that open one alert at a time. */
|
|
22
|
+
export function useAlerts(live: boolean): AlertsState {
|
|
23
|
+
const ask = useRpc(alertsRpc);
|
|
24
|
+
const drop = useRpc(alertDismissRpc);
|
|
25
|
+
// Kept in a ref: the poll restarts when the office goes live, not when the call's identity changes.
|
|
26
|
+
const asking = useRef(ask);
|
|
27
|
+
asking.current = ask;
|
|
28
|
+
const [alerts, setAlerts] = useState<readonly Alert[]>(NO_ALERTS);
|
|
29
|
+
const [openId, setOpenId] = useState<string | null>(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!live) {
|
|
32
|
+
setAlerts(NO_ALERTS);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
let ended = false;
|
|
36
|
+
const read = async () => {
|
|
37
|
+
try {
|
|
38
|
+
const answer = await asking.current({});
|
|
39
|
+
if (!ended) setAlerts(answer.alerts);
|
|
40
|
+
} catch {
|
|
41
|
+
// (the host went away: the next reading says)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
void read();
|
|
45
|
+
const timer = setInterval(() => void read(), EVERY_MS);
|
|
46
|
+
return () => {
|
|
47
|
+
ended = true;
|
|
48
|
+
clearInterval(timer);
|
|
49
|
+
};
|
|
50
|
+
}, [live]);
|
|
51
|
+
const cards = useMemo(
|
|
52
|
+
() =>
|
|
53
|
+
alerts.map(
|
|
54
|
+
(alert): StripCard => ({
|
|
55
|
+
title: alert.title,
|
|
56
|
+
note: { text: alert.detail || "Open to act on it", tone: "warning" },
|
|
57
|
+
onOpen: () => setOpenId(alert.id),
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
[alerts],
|
|
61
|
+
);
|
|
62
|
+
const open = useMemo(() => alerts.find((alert) => alert.id === openId) ?? null, [alerts, openId]);
|
|
63
|
+
const close = useCallback(() => setOpenId(null), []);
|
|
64
|
+
const dismiss = useCallback(async () => {
|
|
65
|
+
if (openId === null) return;
|
|
66
|
+
const answer = await drop({ id: openId });
|
|
67
|
+
setAlerts(answer.alerts);
|
|
68
|
+
setOpenId(null);
|
|
69
|
+
}, [drop, openId]);
|
|
70
|
+
return { cards, open, close, dismiss };
|
|
71
|
+
}
|