paseo-office 0.2.2 → 0.2.4

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.
@@ -7,12 +7,18 @@ import { SettingsSections, settingsLayout } from "./settings-sections.js";
7
7
  import { SettingField } from "./setting-field.js";
8
8
  import { WeatherFields, type WeatherSetting } from "./weather-settings.js";
9
9
  import type { IncidentsState, WakeState } from "../shared/contracts.js";
10
- import { officeHostSettings, type FloorPlanChoice } from "../shared/settings.js";
10
+ import {
11
+ officeHostSettings,
12
+ STICKY_NOTES_MAX,
13
+ STICKY_NOTE_MAX,
14
+ type FloorPlanChoice,
15
+ } from "../shared/settings.js";
11
16
  import { failureText } from "./action-button.js";
12
17
  import { wakeSummary } from "./board-text.js";
13
18
  import { FLOOR_PLAN_LABEL, FloorPlanRow } from "./floor-plan-row.js";
14
19
  import { LabeledSwitch } from "./labeled-switch.js";
15
20
  import { NOTES_DAYS_LABEL, NotesDays } from "./notes-days.js";
21
+ import { NOTES_MODE_LABEL, NotesModeRow } from "./notes-mode-row.js";
16
22
  import { JiraConnection, SentryConnection } from "./tracker-connections.js";
17
23
  import type { OfficeStyles } from "./styles.js";
18
24
  import type { BoardActions } from "./use-board-actions.js";
@@ -26,9 +32,12 @@ type HostSetting =
26
32
  | "Brand color"
27
33
  | "Archive idle sessions"
28
34
  | "Agent tools"
35
+ | "Streamer mode"
36
+ | "Sticky notes"
29
37
  | "Notes folder"
30
38
  | "Time zone"
31
39
  | typeof NOTES_DAYS_LABEL
40
+ | typeof NOTES_MODE_LABEL
32
41
  | typeof FLOOR_PLAN_LABEL
33
42
  | "Jira projects"
34
43
  | "Sentry organisation"
@@ -166,6 +175,10 @@ export function HostSwitches({
166
175
  (next: number[]) => change(NOTES_DAYS_LABEL, { notesDays: next }),
167
176
  [change],
168
177
  );
178
+ const saveMode = useCallback(
179
+ (next: string) => change(NOTES_MODE_LABEL, { notesMode: next }),
180
+ [change],
181
+ );
169
182
  const savePlan = useCallback(
170
183
  (next: FloorPlanChoice) => change(FLOOR_PLAN_LABEL, { floorPlan: next }),
171
184
  [change],
@@ -204,6 +217,12 @@ export function HostSwitches({
204
217
  />
205
218
  </View>
206
219
  <View style={styles.headerFields}>{language}</View>
220
+ <FloorSettings
221
+ values={stored}
222
+ change={change}
223
+ saveProblem={saveProblem}
224
+ styles={styles}
225
+ />
207
226
  {deviceProblem && (
208
227
  <Text accessibilityRole="alert" style={styles.actionError}>
209
228
  {deviceProblem}
@@ -261,6 +280,12 @@ export function HostSwitches({
261
280
  problem={saveProblem(NOTES_DAYS_LABEL)}
262
281
  styles={styles}
263
282
  />
283
+ <NotesModeRow
284
+ value={storedMode(stored)}
285
+ onSave={saveMode}
286
+ problem={saveProblem(NOTES_MODE_LABEL)}
287
+ styles={styles}
288
+ />
264
289
  </View>
265
290
  {problems.length > 0 ? (
266
291
  <View style={styles.headerProblems}>
@@ -297,6 +322,11 @@ export function HostSwitches({
297
322
  );
298
323
  }
299
324
 
325
+ /** The stored writer mode; null while the settings are read or cannot be read. */
326
+ function storedMode(values: HostValues | null): string | null {
327
+ return values === null ? null : values.notesMode;
328
+ }
329
+
300
330
  type TrackerField = "jiraProjects" | "sentryOrg" | "sentryProjects" | "sentryUrl";
301
331
 
302
332
  /** A tracker field's stored text; null while the settings are read or cannot be read. */
@@ -401,6 +431,53 @@ function TrackerFields({ values, incidents, change, saveProblem, styles }: Track
401
431
  );
402
432
  }
403
433
 
434
+ /** The floor's own: what bubbles may name, and the owner's notes on the whiteboard. */
435
+ function FloorSettings({
436
+ values: stored,
437
+ change,
438
+ saveProblem,
439
+ styles,
440
+ }: Omit<TrackerFieldsProps, "incidents">) {
441
+ const toggle = useCallback(
442
+ (next: boolean) => void change("Streamer mode", { streamerMode: next }),
443
+ [change],
444
+ );
445
+ const saveNotes = useCallback(
446
+ (next: string) => change("Sticky notes", { stickyNotes: next }),
447
+ [change],
448
+ );
449
+ const problem = saveProblem("Streamer mode");
450
+ return (
451
+ <View style={settingsLayout.block}>
452
+ {stored && (
453
+ <LabeledSwitch
454
+ label="Streamer mode"
455
+ value={stored.streamerMode}
456
+ onChange={toggle}
457
+ styles={styles}
458
+ />
459
+ )}
460
+ <Text style={styles.fieldHint}>
461
+ On by default: the 3D floor names no file, command or site. Off, the bubble over a person
462
+ names the one they are at, to everyone who opens this office.
463
+ </Text>
464
+ {problem && (
465
+ <Text accessibilityRole="alert" style={styles.actionError}>
466
+ {problem}
467
+ </Text>
468
+ )}
469
+ <SettingField
470
+ label="Sticky notes"
471
+ hint={`Your notes on the 3D whiteboard, with ; between them. Up to ${STICKY_NOTES_MAX}, ${STICKY_NOTE_MAX} characters each.`}
472
+ value={stored?.stickyNotes ?? null}
473
+ onSave={saveNotes}
474
+ problem={saveProblem("Sticky notes")}
475
+ styles={styles}
476
+ />
477
+ </View>
478
+ );
479
+ }
480
+
404
481
  function ArchiveSetting({
405
482
  values: stored,
406
483
  change,
@@ -17,6 +17,8 @@ import {
17
17
  readAtText,
18
18
  type HostTone,
19
19
  } from "../shared/machine-text.js";
20
+ import { planTone, resetText, type PlanUsage } from "../shared/plan-usage.js";
21
+ import { usePlanUsageValue } from "./use-plan-usage.js";
20
22
  import type { OfficeStyles } from "./styles.js";
21
23
 
22
24
  interface MeterProps {
@@ -67,6 +69,43 @@ function Meter({ label, icon, detail, percent, tone, styles }: MeterProps) {
67
69
  );
68
70
  }
69
71
 
72
+ const PLAN_TONE = { ok: "muted", warning: "warning", danger: "danger" } as const;
73
+
74
+ /** Each plan's limits as meters: how much is used, and when it resets. */
75
+ function PlanLimits({
76
+ usage,
77
+ now,
78
+ styles,
79
+ }: {
80
+ usage: readonly PlanUsage[];
81
+ now: number;
82
+ styles: OfficeStyles;
83
+ }) {
84
+ if (usage.length === 0) return null;
85
+ return (
86
+ <View style={styles.host.group}>
87
+ <Text accessibilityRole="header" style={styles.host.title}>
88
+ Plan limits
89
+ </Text>
90
+ {usage.map((provider) => (
91
+ <View key={provider.provider} style={styles.host.meters}>
92
+ {provider.windows.map((window) => (
93
+ <Meter
94
+ key={window.id}
95
+ icon="Gauge"
96
+ label={`${provider.name} ${window.label}`}
97
+ detail={resetText(window.resetsAt, now) || (provider.plan ?? undefined)}
98
+ percent={Math.floor(window.usedPct)}
99
+ tone={PLAN_TONE[planTone(window.usedPct)]}
100
+ styles={styles}
101
+ />
102
+ ))}
103
+ </View>
104
+ ))}
105
+ </View>
106
+ );
107
+ }
108
+
70
109
  interface RowAction {
71
110
  label: string;
72
111
  pendingLabel: string;
@@ -209,6 +248,7 @@ const CLOSE = { label: "Close runtime", pendingLabel: "Closing...", primary: fal
209
248
  const NO_WORKSPACES: readonly OfficeWorkspace[] = [];
210
249
 
211
250
  function MachineBody({ machine, cleanUp, styles, workspaces = NO_WORKSPACES }: MachineBodyProps) {
251
+ const usage = usePlanUsageValue();
212
252
  const [expanded, setExpanded] = useState(false);
213
253
  const toggle = useCallback(() => setExpanded((value) => !value), []);
214
254
  const now = Date.parse(machine.readAt);
@@ -260,6 +300,7 @@ function MachineBody({ machine, cleanUp, styles, workspaces = NO_WORKSPACES }: M
260
300
  />
261
301
  </View>
262
302
  {expanded && <LocalHostDetails machine={machine} workspaces={workspaces} styles={styles} />}
303
+ <PlanLimits usage={usage} now={now} styles={styles} />
263
304
  {left.length > 0 ? (
264
305
  <View style={styles.host.group}>
265
306
  <AgentGroup
@@ -0,0 +1,140 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { Text, View } from "react-native";
3
+ import { useRpc } from "@getpaseo/plugin/client";
4
+ import { notesModesRpc, type WriterModes } from "../shared/contracts.js";
5
+ import { SegmentPill } from "./segment-pill.js";
6
+ import type { OfficeStyles } from "./styles.js";
7
+
8
+ /** The row's label, and the setting a refused save names. */
9
+ export const NOTES_MODE_LABEL = "Writer mode";
10
+ /** The pill for no mode set: the office picks, as it did before the setting. */
11
+ const OWN_CHOICE = "Office's choice";
12
+ const HINT =
13
+ "The mode the stand-up writer starts in. Nobody answers its questions at 8:00, so a mode that asks leaves the note unwritten.";
14
+ // The modes that ask for nothing: Claude's and Codex's.
15
+ const UNATTENDED: ReadonlySet<string> = new Set(["bypassPermissions", "full-access"]);
16
+ const UNATTENDED_HINT = "In this mode the writer runs any tool or command without asking.";
17
+
18
+ export interface NotesModeRowProps {
19
+ /** The stored mode's id, empty for none; null while the settings are read or cannot be read. */
20
+ value: string | null;
21
+ /** Resolves once the host has answered, and never rejects. */
22
+ onSave(next: string): Promise<unknown>;
23
+ problem: string | null;
24
+ styles: OfficeStyles;
25
+ }
26
+
27
+ type Asked = WriterModes | { problem: string } | null;
28
+
29
+ /** What stands under the pills beside the hint: the fallback, the warning, or why none is listed. */
30
+ function noteOf(asked: Asked, shown: string | null): string | null {
31
+ if (asked === null) return null;
32
+ if ("problem" in asked) return `The writer's modes cannot be listed: ${asked.problem}`;
33
+ if (asked.fellBack) {
34
+ const used = asked.modes.find((mode) => mode.id === asked.modeId)?.label ?? "its default";
35
+ return `${asked.provider} has no mode "${shown}": the writer starts in ${used}.`;
36
+ }
37
+ return shown !== null && UNATTENDED.has(shown) ? UNATTENDED_HINT : null;
38
+ }
39
+
40
+ /**
41
+ * The stand-up writer's mode, as pills of the modes its provider offers, by the provider's own
42
+ * names. The host is asked for them when the row shows and after each save, since the stored
43
+ * mode decides what it says of a fallback. A press shows, and the row takes no other, until the
44
+ * host has answered.
45
+ */
46
+ export function NotesModeRow({ value, onSave, problem, styles }: NotesModeRowProps) {
47
+ const ask = useRpc(notesModesRpc);
48
+ const mounted = useRef(true);
49
+ const [asked, setAsked] = useState<Asked>(null);
50
+ useEffect(() => {
51
+ mounted.current = true;
52
+ return () => {
53
+ mounted.current = false;
54
+ };
55
+ }, []);
56
+ // Kept in a ref: the row asks again when the stored mode changes, not when the call's identity does.
57
+ const asking = useRef(ask);
58
+ asking.current = ask;
59
+ useEffect(() => {
60
+ if (value === null) return;
61
+ void asking.current({}).then(
62
+ (answer) => {
63
+ if (mounted.current) setAsked(answer.ok ? answer : { problem: answer.problem });
64
+ return undefined;
65
+ },
66
+ (error: unknown) => {
67
+ if (mounted.current) {
68
+ setAsked({ problem: error instanceof Error ? error.message : String(error) });
69
+ }
70
+ },
71
+ );
72
+ }, [value]);
73
+ const [wanted, setWanted] = useState<string | null>(null);
74
+ const shown = wanted ?? value;
75
+ const saving = useRef(false);
76
+ const choose = useCallback(
77
+ (next: string) => {
78
+ if (shown === null || saving.current || next === shown) return;
79
+ saving.current = true;
80
+ setWanted(next);
81
+ void onSave(next).finally(() => {
82
+ saving.current = false;
83
+ if (mounted.current) setWanted(null);
84
+ });
85
+ },
86
+ [shown, onSave],
87
+ );
88
+ const modes = asked !== null && "modes" in asked ? asked.modes : [];
89
+ // A stored mode this provider lacks still shows as a pill, so what is stored can be seen.
90
+ const stored = shown !== null && shown !== "" && !modes.some((mode) => mode.id === shown);
91
+ const disabled = shown === null || wanted !== null;
92
+ const note = wanted === null ? noteOf(asked, shown) : null;
93
+ return (
94
+ <View style={styles.headerField}>
95
+ <Text style={styles.sheetLabel}>{NOTES_MODE_LABEL}</Text>
96
+ <View
97
+ role="group"
98
+ aria-label={NOTES_MODE_LABEL}
99
+ style={disabled ? styles.segmentsDisabled : styles.segments}
100
+ >
101
+ <SegmentPill
102
+ value=""
103
+ name={OWN_CHOICE}
104
+ on={shown === ""}
105
+ disabled={disabled}
106
+ onPress={choose}
107
+ styles={styles}
108
+ />
109
+ {modes.map((mode) => (
110
+ <SegmentPill
111
+ key={mode.id}
112
+ value={mode.id}
113
+ name={mode.label}
114
+ on={shown === mode.id}
115
+ disabled={disabled}
116
+ onPress={choose}
117
+ styles={styles}
118
+ />
119
+ ))}
120
+ {stored && shown !== null ? (
121
+ <SegmentPill
122
+ value={shown}
123
+ name={shown}
124
+ on
125
+ disabled={disabled}
126
+ onPress={choose}
127
+ styles={styles}
128
+ />
129
+ ) : null}
130
+ </View>
131
+ <Text style={styles.fieldHint}>{HINT}</Text>
132
+ {note === null ? null : <Text style={styles.fieldHint}>{note}</Text>}
133
+ {problem === null ? null : (
134
+ <Text accessibilityRole="alert" style={styles.actionError}>
135
+ {problem}
136
+ </Text>
137
+ )}
138
+ </View>
139
+ );
140
+ }
@@ -26,6 +26,7 @@ export function applyOfficeEvent(state: OfficeSnapshot, event: OfficeEvent): Off
26
26
  ...state,
27
27
  activity: event.activity,
28
28
  doing: event.doing ?? {},
29
+ subagents: event.subagents,
29
30
  checklists: event.checklists ?? {},
30
31
  checklistProgress: event.checklistProgress,
31
32
  };
@@ -2,6 +2,7 @@ import { useChatKeyboard } from "./office-keyboard.js";
2
2
  import { OfficeBrandContext } from "./office-brand-context.js";
3
3
  import {
4
4
  useCallback,
5
+ useContext,
5
6
  useEffect,
6
7
  useMemo,
7
8
  useReducer,
@@ -111,6 +112,8 @@ import { useReviews } from "./use-reviews.js";
111
112
  import { useScriptLog } from "./use-script-log.js";
112
113
  import { useStandup } from "./use-standup.js";
113
114
  import { useMachine } from "./use-machine.js";
115
+ import { PlanUsageContext, usePlanUsage } from "./use-plan-usage.js";
116
+ import { planNote } from "../shared/plan-usage.js";
114
117
  import { useOffice, type OfficeState } from "./use-office.js";
115
118
  import { UNSAVED_SOUND, useSoundSwitch, type SoundSwitch } from "./use-sound.js";
116
119
  import { ViewSwitch } from "./view-switch.js";
@@ -888,6 +891,25 @@ function HostResourceButton({
888
891
  styles: OfficeStyles;
889
892
  }) {
890
893
  const percent = machine ? memoryPercent(machine) : null;
894
+ // A plan close to its limit takes the button's words: that is what stops the work first.
895
+ const plan = planNote(useContext(PlanUsageContext));
896
+ const planText = useMemo(
897
+ () => [styles.sidebarButtonText, plan && styles.stripNote[plan.tone]],
898
+ [styles, plan],
899
+ );
900
+ if (plan !== null) {
901
+ return (
902
+ <Pressable
903
+ accessibilityRole="button"
904
+ accessibilityLabel={`Host resources. Plan limit: ${plan.text}`}
905
+ onPress={onOpen}
906
+ style={styles.sidebarButton}
907
+ >
908
+ <Icon name="Gauge" size={15} color={String(styles.stripNote[plan.tone].color)} />
909
+ <Text style={planText}>{plan.text}</Text>
910
+ </Pressable>
911
+ );
912
+ }
891
913
  return (
892
914
  <Pressable
893
915
  accessibilityRole="button"
@@ -1830,6 +1852,7 @@ export function OfficeSurface(
1830
1852
  machine,
1831
1853
  live,
1832
1854
  );
1855
+ const planUsage = usePlanUsage(live);
1833
1856
  const board = useBoardSheet(model, live);
1834
1857
  const dutyCard = useCardOpening(live);
1835
1858
  // Until the host sends its duty list (an older host has none) nothing offers the duty board.
@@ -2288,9 +2311,11 @@ export function OfficeSurface(
2288
2311
  );
2289
2312
  return (
2290
2313
  <OfficeBrandContext.Provider value={office.state.brand}>
2291
- <OfficeDialogs fullscreen={full.integrated} theme={theme} styles={styles}>
2292
- {surface}
2293
- </OfficeDialogs>
2314
+ <PlanUsageContext.Provider value={planUsage}>
2315
+ <OfficeDialogs fullscreen={full.integrated} theme={theme} styles={styles}>
2316
+ {surface}
2317
+ </OfficeDialogs>
2318
+ </PlanUsageContext.Provider>
2294
2319
  </OfficeBrandContext.Provider>
2295
2320
  );
2296
2321
  }
@@ -8,13 +8,14 @@ import {
8
8
  type PressableStateCallbackType,
9
9
  } from "react-native";
10
10
  import { Icon } from "@getpaseo/plugin/client/ui";
11
- import { OFFICE_LIGHTING, OFFICE_SCENES } from "../shared/settings.js";
11
+ import { OFFICE_GRAPHICS, OFFICE_LIGHTING, OFFICE_SCENES } from "../shared/settings.js";
12
12
  import type { OfficeStyles } from "./styles.js";
13
13
  import type { useOfficeScene } from "./use-street.js";
14
14
  import { scenePreviews } from "./scene-previews.js";
15
15
 
16
16
  const scenes = { plain: "Plain", city: "City", countryside: "Countryside", beach: "Beach" };
17
17
  const lighting = { auto: "App theme", day: "Day", night: "Night" };
18
+ const graphics = { auto: "Auto", low: "Low", medium: "Medium", high: "High" };
18
19
  const lightIcons = { auto: "Monitor", day: "Sun", night: "Moon" };
19
20
  const layout = StyleSheet.create({
20
21
  body: { gap: 20 },
@@ -153,6 +154,24 @@ export function SceneChoices({
153
154
  ))}
154
155
  </View>
155
156
  </View>
157
+ <View style={layout.section}>
158
+ <Text style={styles.sheetLabel}>Graphics</Text>
159
+ <View role="group" aria-label="Graphics" style={layout.row}>
160
+ {OFFICE_GRAPHICS.map((value) => (
161
+ <Choice
162
+ key={value}
163
+ value={value}
164
+ label={graphics[value]}
165
+ setting={choice.graphics}
166
+ styles={styles}
167
+ />
168
+ ))}
169
+ </View>
170
+ <Text style={styles.fieldHint}>
171
+ Auto picks for this device and steps down when frames come late. Low draws no shadows, at
172
+ 30 frames a second.
173
+ </Text>
174
+ </View>
156
175
  </View>
157
176
  );
158
177
  }
@@ -1,3 +1,4 @@
1
+ import { TeamName } from "./team-name.js";
1
2
  import { useCallback, useEffect, useId, useMemo, useState } from "react";
2
3
  import {
3
4
  Platform,
@@ -241,6 +242,7 @@ function RoomCard({
241
242
  {room.subtitle}
242
243
  </Text>
243
244
  ) : null}
245
+ <TeamName room={room} styles={styles} />
244
246
  </View>
245
247
  {room.rows.length === 0 ? <Text style={styles.empty}>No agents</Text> : null}
246
248
  {room.rows.map((row, index) => (
@@ -0,0 +1,81 @@
1
+ import { useCallback, useState } from "react";
2
+ import { Pressable, Text, View } from "react-native";
3
+ import { useRpc } from "@getpaseo/plugin/client";
4
+ import { TextInput } from "@getpaseo/plugin/client/ui";
5
+ import { teamRenameRpc } from "../shared/contracts.js";
6
+ import type { OfficeRoom } from "../shared/model.js";
7
+ import { TEAM_NAME_MAX } from "../shared/team-name.js";
8
+ import { ActionButton } from "./action-button.js";
9
+ import type { OfficeStyles } from "./styles.js";
10
+
11
+ interface TeamNameProps {
12
+ room: OfficeRoom;
13
+ styles: OfficeStyles;
14
+ }
15
+
16
+ const HINT = "The office's own name for this team. Empty goes back to the workspace's name.";
17
+
18
+ /**
19
+ * Gives a room's team a name of the office's own: a line under the room's title that opens a
20
+ * field. The workspace keeps its name in Paseo; while the team goes by another, the line says
21
+ * which workspace it is.
22
+ */
23
+ export function TeamName({ room, styles }: TeamNameProps) {
24
+ const rename = useRpc(teamRenameRpc);
25
+ const [open, setOpen] = useState(false);
26
+ const [draft, setDraft] = useState("");
27
+ const workspace = room.workspace;
28
+ const own = workspace?.workspaceName;
29
+ const start = useCallback(() => {
30
+ // The field starts from the team's own name, empty while it goes by the workspace's.
31
+ setDraft(own === undefined ? "" : room.name);
32
+ setOpen(true);
33
+ }, [own, room.name]);
34
+ const cancel = useCallback(() => setOpen(false), []);
35
+ const save = useCallback(async () => {
36
+ if (!workspace) return;
37
+ const answer = await rename({ workspaceId: workspace.id, name: draft });
38
+ if (!answer.ok) throw new Error(answer.problem);
39
+ setOpen(false);
40
+ }, [rename, workspace, draft]);
41
+ if (!workspace) return null;
42
+ if (!open) {
43
+ return (
44
+ <Pressable
45
+ accessibilityRole="button"
46
+ accessibilityLabel={`Rename team ${room.name}`}
47
+ onPress={start}
48
+ >
49
+ <Text style={styles.fieldHint}>
50
+ {own === undefined ? "Rename team" : `Workspace ${own} · Rename team`}
51
+ </Text>
52
+ </Pressable>
53
+ );
54
+ }
55
+ return (
56
+ <View style={styles.headerField}>
57
+ <TextInput
58
+ accessibilityLabel="Team name"
59
+ accessibilityHint={HINT}
60
+ value={draft}
61
+ onChangeText={setDraft}
62
+ maxLength={TEAM_NAME_MAX}
63
+ placeholder={own ?? room.name}
64
+ autoCapitalize="none"
65
+ autoCorrect={false}
66
+ style={styles.fieldInput}
67
+ />
68
+ <Text style={styles.fieldHint}>{HINT}</Text>
69
+ <View style={styles.actions}>
70
+ <ActionButton
71
+ label="Save team name"
72
+ pendingLabel="Saving..."
73
+ onPress={save}
74
+ primary
75
+ styles={styles}
76
+ />
77
+ <ActionButton label="Cancel" pendingLabel="Cancel" onPress={cancel} styles={styles} />
78
+ </View>
79
+ </View>
80
+ );
81
+ }
@@ -1,6 +1,11 @@
1
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
2
  import { useSettings } from "@getpaseo/plugin/client";
3
- import { officeDeviceSettings, type OfficeScene, type OfficeLighting } from "../shared/settings.js";
3
+ import {
4
+ officeDeviceSettings,
5
+ type OfficeGraphics,
6
+ type OfficeLighting,
7
+ type OfficeScene,
8
+ } from "../shared/settings.js";
4
9
 
5
10
  export interface DeviceSwitch {
6
11
  /** The switch as the person left it (a tap shows at once); null while the device's setting is read or unreadable. */
@@ -29,6 +34,7 @@ interface Preferences {
29
34
  sessionsHidden: boolean;
30
35
  scene: OfficeScene;
31
36
  lighting: OfficeLighting;
37
+ graphics: OfficeGraphics;
32
38
  }
33
39
 
34
40
  export function useDeviceSwitch<Field extends keyof Preferences>(
@@ -0,0 +1,46 @@
1
+ import { createContext, useContext, useEffect, useRef, useState } from "react";
2
+ import { useRpc } from "@getpaseo/plugin/client";
3
+ import { planUsageRpc } from "../shared/contracts.js";
4
+ import type { PlanUsage } from "../shared/plan-usage.js";
5
+
6
+ const NO_USAGE: readonly PlanUsage[] = [];
7
+ /** The providers refresh their own readings about this often; asking sooner reads the same. */
8
+ const EVERY_MS = 120_000;
9
+
10
+ /** The plans' limits, for the floor and the Host card; empty where nothing provides them. */
11
+ export const PlanUsageContext = createContext<readonly PlanUsage[]>(NO_USAGE);
12
+
13
+ export function usePlanUsageValue(): readonly PlanUsage[] {
14
+ return useContext(PlanUsageContext);
15
+ }
16
+
17
+ /**
18
+ * The plans of the providers the host can read, asked for while `live` and again every two
19
+ * minutes. A host that cannot say leaves the last reading, and none before the first.
20
+ */
21
+ export function usePlanUsage(live: boolean): readonly PlanUsage[] {
22
+ const ask = useRpc(planUsageRpc);
23
+ // Kept in a ref: the poll restarts when the office goes live, not when the call's identity changes.
24
+ const asking = useRef(ask);
25
+ asking.current = ask;
26
+ const [usage, setUsage] = useState<readonly PlanUsage[]>(NO_USAGE);
27
+ useEffect(() => {
28
+ if (!live) return undefined;
29
+ let ended = false;
30
+ const read = async () => {
31
+ try {
32
+ const answer = await asking.current({});
33
+ if (!ended && answer.ok) setUsage(answer.providers);
34
+ } catch {
35
+ // (the host went away: the next reading says)
36
+ }
37
+ };
38
+ void read();
39
+ const timer = setInterval(() => void read(), EVERY_MS);
40
+ return () => {
41
+ ended = true;
42
+ clearInterval(timer);
43
+ };
44
+ }, [live]);
45
+ return usage;
46
+ }
@@ -17,5 +17,11 @@ export function useOfficeScene(layout: StreetLayout) {
17
17
  const legacy = useStreetSwitch(layout);
18
18
  const scene = useDeviceSwitch("scene", legacy.on ? "city" : "plain");
19
19
  const lighting = useDeviceSwitch("lighting", "auto");
20
- return { scene, lighting, unsaved: scene.unsaved || lighting.unsaved };
20
+ const graphics = useDeviceSwitch("graphics", "auto");
21
+ return {
22
+ scene,
23
+ lighting,
24
+ graphics,
25
+ unsaved: scene.unsaved || lighting.unsaved || graphics.unsaved,
26
+ };
21
27
  }