paseo-office 0.2.0 → 0.2.1
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/OVERVIEW.md +27 -0
- package/README.md +65 -134
- package/client/action-button.tsx +4 -1
- package/client/activity-panel.tsx +6 -4
- package/client/agent-appearance.tsx +257 -0
- package/client/agent-card.tsx +2 -1
- package/client/agent-picker-text.ts +23 -4
- package/client/agent-picker.tsx +5 -8
- package/client/board-sheet.tsx +48 -16
- package/client/board-text.ts +12 -2
- package/client/brand.ts +1 -0
- package/client/chat-chrome.tsx +318 -0
- package/client/chat-compose-tools.tsx +314 -0
- package/client/chat-dictation.tsx +133 -0
- package/client/chat-more.tsx +119 -0
- package/client/chat-panel.tsx +401 -146
- package/client/chat-quick.tsx +198 -0
- package/client/chat-text.ts +25 -6
- package/client/column-sheet.tsx +93 -23
- package/client/conversation-model.ts +19 -5
- package/client/duty-sheet.tsx +321 -0
- package/client/duty-text.ts +20 -0
- package/client/fullscreen-header.tsx +28 -13
- package/client/fullscreen-theme.ts +38 -0
- package/client/host-details.tsx +269 -0
- package/client/host-styles.ts +129 -0
- package/client/host-switches.tsx +197 -73
- package/client/incidents-card.tsx +2 -1
- package/client/janitor-card.tsx +1 -1
- package/client/library-card.tsx +2 -1
- package/client/list-text.ts +8 -6
- package/client/lobby-board.tsx +73 -53
- package/client/machine-card.tsx +225 -85
- package/client/messenger-styles.ts +216 -0
- package/client/new-agent-form.tsx +153 -61
- package/client/new-agent-model.ts +2 -0
- package/client/notes-card.tsx +111 -83
- package/client/notes-days.tsx +1 -1
- package/client/office-brand-context.ts +44 -0
- package/client/office-column.tsx +2 -1
- package/client/office-keyboard.ts +79 -0
- package/client/office-link.ts +7 -1
- package/client/office-mark.tsx +29 -0
- package/client/office-modal.tsx +440 -0
- package/client/office-settings.tsx +75 -30
- package/client/office-state.ts +12 -2
- package/client/office-surface.tsx +591 -81
- package/client/pixel/actors.ts +2 -1
- package/client/pixel/art.ts +33 -19
- package/client/pixel/pixel-office.tsx +2 -2
- package/client/prompt-coach.tsx +152 -0
- package/client/qa-card.tsx +2 -1
- package/client/review-card.tsx +2 -1
- package/client/room-board.tsx +26 -2
- package/client/scene-picker.tsx +158 -0
- package/client/scene-previews.ts +10 -0
- package/client/session-pane.tsx +25 -5
- package/client/session-panel-detail.tsx +238 -0
- package/client/session-panel.tsx +222 -137
- package/client/session-styles.ts +224 -1
- package/client/session-transcript.tsx +243 -0
- package/client/sessions-panel.tsx +181 -22
- package/client/sessions-text.ts +18 -0
- package/client/settings-sections.tsx +126 -0
- package/client/sidebar-launcher.ts +29 -0
- package/client/ssh-hosts.tsx +331 -0
- package/client/ssh-metrics.ts +76 -0
- package/client/standup-card.tsx +2 -1
- package/client/structure-view.tsx +20 -3
- package/client/styles.ts +170 -62
- package/client/team-chat-preview.tsx +96 -0
- package/client/transcript-styles.ts +90 -0
- package/client/use-device-switch.ts +21 -12
- package/client/use-duty-actions.ts +43 -0
- package/client/use-group-photo.ts +48 -0
- package/client/use-new-agent.ts +4 -0
- package/client/use-street.ts +8 -0
- package/client/workspace-office-tools.tsx +102 -0
- package/client/workspace-overlay-route.web.ts +47 -0
- package/client/workspace-overlay.tsx +195 -0
- package/client/world/adapter.ts +37 -2
- package/client/world/escape.ts +58 -0
- package/client/world/use-world-feed.ts +6 -2
- package/client/world/workspace-dock.ts +6 -0
- package/client/world/world-api.ts +45 -4
- package/client/world/world-bridge-page.ts +14 -3
- package/client/world/world-bridge.ts +50 -5
- package/client/world/world-frame.web.ts +8 -0
- package/client/world/world-view-native.tsx +31 -10
- package/client/world/world-view-shared.ts +36 -7
- package/client/world/world-view.tsx +93 -21
- package/docs/office.md +148 -58
- package/index.client.tsx +13 -6
- package/index.server.ts +125 -9
- package/package.json +2 -1
- package/server/activity.ts +42 -19
- package/server/agent-tools.ts +11 -5
- package/server/board-service.ts +381 -10
- package/server/brand-logo.ts +34 -0
- package/server/chat-group.ts +83 -0
- package/server/chat-service.ts +406 -62
- package/server/chat-store.ts +1 -4
- package/server/directory.ts +22 -7
- package/server/duty-service.ts +230 -0
- package/server/group-photo.ts +39 -0
- package/server/home-departure.ts +47 -0
- package/server/hub.ts +43 -1
- package/server/live-ports.ts +114 -18
- package/server/lobby-pickup.ts +170 -0
- package/server/machine/details.ts +91 -0
- package/server/mention-queue.ts +14 -0
- package/server/office.ts +110 -6
- package/server/paths.ts +9 -0
- package/server/ssh/LICENSE.paseo +211 -0
- package/server/ssh/client.ts +401 -0
- package/server/ssh/discovery.ts +230 -0
- package/server/ssh/installed.ts +104 -0
- package/server/ssh/monitor.ts +104 -0
- package/server/ssh/pid-files.ts +194 -0
- package/server/ssh/read.ts +136 -0
- package/server/subagent-names.ts +4 -0
- package/server/words.generated.ts +1 -1
- package/server/world.generated.ts +1 -1
- package/shared/appearance.ts +43 -0
- package/shared/branding.ts +53 -0
- package/shared/chat-words.ts +2 -2
- package/shared/contracts.ts +135 -4
- package/shared/duties.ts +100 -0
- package/shared/host-details.ts +25 -0
- package/shared/lobby-assignment.ts +34 -0
- package/shared/model.ts +9 -1
- package/shared/names.ts +2 -0
- package/shared/settings.ts +14 -3
- package/shared/ssh.ts +34 -0
- package/shared/upstream/README.md +1 -3
- package/shared/upstream/chat-engine.d.ts +4 -0
- package/shared/upstream/prompt-coach.d.ts +6 -0
- package/shared/upstream/prompt-coach.js +178 -0
package/server/directory.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type WorkspaceScript,
|
|
13
13
|
type WorkspaceTicket,
|
|
14
14
|
} from "../shared/contracts.js";
|
|
15
|
+
import { APPEARANCE_KEY, AppearanceSchema } from "../shared/appearance.js";
|
|
15
16
|
import { NEXT_KEY, NUMBER_KEY, storedNumber } from "./subagent-names.js";
|
|
16
17
|
|
|
17
18
|
// PARENT_AGENT_ID_LABEL in packages/protocol/src/agent-labels.ts. Server code may import the
|
|
@@ -56,6 +57,8 @@ export interface DirectoryAgentInput {
|
|
|
56
57
|
createdAt: string;
|
|
57
58
|
/** When anything about the agent last changed on the host. */
|
|
58
59
|
updatedAt?: string;
|
|
60
|
+
attentionTimestamp?: string | null;
|
|
61
|
+
attentionReason?: string | null;
|
|
59
62
|
labels?: Readonly<Record<string, string>>;
|
|
60
63
|
pendingPermissions: readonly DirectoryPermissionInput[];
|
|
61
64
|
archivedAt?: string | null;
|
|
@@ -223,10 +226,22 @@ function costOf(agent: DirectoryAgentInput): number | undefined {
|
|
|
223
226
|
return cost !== undefined && Number.isFinite(cost) && cost >= 0 ? cost : undefined;
|
|
224
227
|
}
|
|
225
228
|
|
|
226
|
-
/**
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
/** Timestamps the host has for the row's turn, rest, or pending permission. */
|
|
230
|
+
function stateTimes(
|
|
231
|
+
agent: DirectoryAgentInput,
|
|
232
|
+
status: AgentStatus,
|
|
233
|
+
): Pick<OfficeAgent, "promptedAt" | "idleSince" | "permissionSince"> {
|
|
234
|
+
const times: Pick<OfficeAgent, "promptedAt" | "idleSince" | "permissionSince"> = {};
|
|
235
|
+
if ((status === "running" || status === "initializing") && agent.lastUserMessageAt)
|
|
236
|
+
times.promptedAt = agent.lastUserMessageAt;
|
|
237
|
+
if (status === "idle" && agent.updatedAt) times.idleSince = agent.updatedAt;
|
|
238
|
+
if (
|
|
239
|
+
agent.pendingPermissions.length &&
|
|
240
|
+
agent.attentionReason === "permission" &&
|
|
241
|
+
agent.attentionTimestamp
|
|
242
|
+
)
|
|
243
|
+
times.permissionSince = agent.attentionTimestamp;
|
|
244
|
+
return times;
|
|
230
245
|
}
|
|
231
246
|
|
|
232
247
|
/** The office's view of an agent, or null when the office does not show it. */
|
|
@@ -237,7 +252,7 @@ export function projectAgent(agent: DirectoryAgentInput): OfficeAgent | null {
|
|
|
237
252
|
const parent = agent.labels?.[PARENT_AGENT_ID_LABEL]?.trim() ?? "";
|
|
238
253
|
const context = contextOf(agent);
|
|
239
254
|
const cost = costOf(agent);
|
|
240
|
-
const
|
|
255
|
+
const appearance = AppearanceSchema.safeParse(agent.metadata?.[APPEARANCE_KEY]);
|
|
241
256
|
const number = storedNumber(agent.metadata?.[NUMBER_KEY]);
|
|
242
257
|
const next = storedNumber(agent.metadata?.[NEXT_KEY]);
|
|
243
258
|
return {
|
|
@@ -259,12 +274,12 @@ export function projectAgent(agent: DirectoryAgentInput): OfficeAgent | null {
|
|
|
259
274
|
};
|
|
260
275
|
}),
|
|
261
276
|
createdAt: agent.createdAt,
|
|
277
|
+
...stateTimes(agent, status.data),
|
|
278
|
+
...(appearance.success ? { appearance: appearance.data } : {}),
|
|
262
279
|
...(context === undefined ? {} : { context }),
|
|
263
280
|
...(number === undefined ? {} : { number }),
|
|
264
281
|
...(next === undefined ? {} : { next }),
|
|
265
|
-
...(status.data === "idle" && agent.updatedAt ? { idleSince: agent.updatedAt } : {}),
|
|
266
282
|
...(cost === undefined ? {} : { costUsd: cost }),
|
|
267
|
-
...(promptedAt === undefined ? {} : { promptedAt }),
|
|
268
283
|
};
|
|
269
284
|
}
|
|
270
285
|
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFile, rename } from "node:fs/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { DutySchema, type Duty, type DutyBoard } from "../shared/contracts.js";
|
|
5
|
+
import {
|
|
6
|
+
DUTY_DUE_MINUTE,
|
|
7
|
+
STARTING_DUTIES,
|
|
8
|
+
dutyListProblem,
|
|
9
|
+
type DutyDraft,
|
|
10
|
+
} from "../shared/duties.js";
|
|
11
|
+
import type { BoardService } from "./board-service.js";
|
|
12
|
+
import { errorMessage } from "./errors.js";
|
|
13
|
+
import { createLifeFile, type LifeFile } from "./life-store.js";
|
|
14
|
+
import type { OfficeCadence, OfficeSchedules } from "./local-schedules.js";
|
|
15
|
+
import { createScheduleFollower, type OfficeSchedule } from "./schedule-follower.js";
|
|
16
|
+
|
|
17
|
+
/** The daily run's name among the office's schedules, and the handler that answers it. */
|
|
18
|
+
export const DUTY_SCHEDULE = "duty-board";
|
|
19
|
+
const DUTIES: OfficeSchedule = { name: DUTY_SCHEDULE, label: "Duty board", logName: "duty board" };
|
|
20
|
+
|
|
21
|
+
/** `<PASEO_HOME>/office/duties.json`: the owner's duty list, in a versioned shape of its own. */
|
|
22
|
+
export const DutiesFileSchema = z.object({ version: z.literal(1), duties: z.array(DutySchema) });
|
|
23
|
+
export type DutiesFile = z.output<typeof DutiesFileSchema>;
|
|
24
|
+
|
|
25
|
+
function isMissing(error: unknown): boolean {
|
|
26
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The kept list. Missing, it is null. Anything else that cannot be read (a broken, newer or
|
|
31
|
+
* unreadable file) is moved aside to `duties.json.corrupt-<time>`, so a save never replaces it,
|
|
32
|
+
* and is null; one that cannot even be moved aside rejects.
|
|
33
|
+
*/
|
|
34
|
+
async function loadDuties(
|
|
35
|
+
file: string,
|
|
36
|
+
ports: { now(): number; log(message: string): void },
|
|
37
|
+
): Promise<DutiesFile | null> {
|
|
38
|
+
let reason: string;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = DutiesFileSchema.safeParse(JSON.parse(await readFile(file, "utf8")));
|
|
41
|
+
if (parsed.success) return parsed.data;
|
|
42
|
+
reason = "unexpected shape, or a newer version";
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (isMissing(error)) return null;
|
|
45
|
+
reason = errorMessage(error);
|
|
46
|
+
}
|
|
47
|
+
const target = `${file}.corrupt-${ports.now()}`;
|
|
48
|
+
try {
|
|
49
|
+
await rename(file, target);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`${file} is unreadable (${reason}) and could not be moved aside (${errorMessage(error)})`,
|
|
53
|
+
{ cause: error },
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
ports.log(
|
|
57
|
+
`[office] ${file} is unreadable (${reason}); moved to ${target}, starting from the pantry chores`,
|
|
58
|
+
);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The file. It is loaded once, as the service starts, before any save. */
|
|
63
|
+
export function dutiesFileStore(
|
|
64
|
+
file: string,
|
|
65
|
+
ports: { now(): number; log(message: string): void },
|
|
66
|
+
): LifeFile<DutiesFile> {
|
|
67
|
+
const kept = createLifeFile(file, DutiesFileSchema);
|
|
68
|
+
return { load: () => loadDuties(file, ports), save: kept.save };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The duty board's day at an instant: from 08:00 in the zone it is that date, before it the day before. */
|
|
72
|
+
export interface DutyClock {
|
|
73
|
+
day: string;
|
|
74
|
+
/** The day's weekday, 0 for Sunday. */
|
|
75
|
+
weekday: number;
|
|
76
|
+
/** It is 08:00 or later: the day's duties are due. */
|
|
77
|
+
open: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function dutyClock(at: number, timeZone: string): DutyClock {
|
|
81
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
82
|
+
timeZone,
|
|
83
|
+
hourCycle: "h23",
|
|
84
|
+
year: "numeric",
|
|
85
|
+
month: "numeric",
|
|
86
|
+
day: "numeric",
|
|
87
|
+
hour: "numeric",
|
|
88
|
+
minute: "numeric",
|
|
89
|
+
}).formatToParts(at);
|
|
90
|
+
const read = (type: string) => Number(parts.find((part) => part.type === type)?.value);
|
|
91
|
+
const open = read("hour") * 60 + read("minute") >= DUTY_DUE_MINUTE;
|
|
92
|
+
const date = new Date(Date.UTC(read("year"), read("month") - 1, read("day") - (open ? 0 : 1)));
|
|
93
|
+
return { day: date.toISOString().slice(0, 10), weekday: date.getUTCDay(), open };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The daily run: 08:00 every day in the notes' zone. A day with nothing due still clears the board. */
|
|
97
|
+
export function dutyCadence(timeZone: string): OfficeCadence {
|
|
98
|
+
return { type: "cron", expression: "0 8 * * *", timezone: timeZone };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type DutySaveResult = { ok: true } | { ok: false; error: string };
|
|
102
|
+
|
|
103
|
+
export interface DutyServicePorts {
|
|
104
|
+
file: LifeFile<DutiesFile>;
|
|
105
|
+
board: Pick<BoardService, "syncDuties">;
|
|
106
|
+
schedules: OfficeSchedules;
|
|
107
|
+
/** The notes' zone: the settings', or the host's when they name none or cannot be read. */
|
|
108
|
+
zone(): Promise<string>;
|
|
109
|
+
now(): number;
|
|
110
|
+
/** The list now: the office hands out only duties with instructions. */
|
|
111
|
+
listed(duties: readonly Duty[]): void;
|
|
112
|
+
/** The list and the board's day, for the office's snapshot. */
|
|
113
|
+
changed(board: DutyBoard): void;
|
|
114
|
+
log(message: string): void;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface DutyService {
|
|
118
|
+
/** Reads the list and brings the board up to it. Never rejects. */
|
|
119
|
+
start(): Promise<void>;
|
|
120
|
+
list(): readonly Duty[];
|
|
121
|
+
save(drafts: readonly DutyDraft[]): Promise<DutySaveResult>;
|
|
122
|
+
/**
|
|
123
|
+
* The 08:00 run, given the instant it was due, and the catch-up at start and at each save.
|
|
124
|
+
* Never rejects.
|
|
125
|
+
*/
|
|
126
|
+
sync(dueAt?: number): Promise<void>;
|
|
127
|
+
/** Follows the notes' zone: the schedule, and the day it makes. Never rejects. */
|
|
128
|
+
settingsChanged(): Promise<void>;
|
|
129
|
+
/** Why the 08:00 schedule could not follow the settings; null once it does. */
|
|
130
|
+
error(): string | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A draft as kept: trimmed, days in order, the id and chore of the duty it edits, or a new id. An
|
|
135
|
+
* id an earlier draft of the save took (`taken`) is a new duty.
|
|
136
|
+
*/
|
|
137
|
+
function keptDuty(draft: DutyDraft, current: readonly Duty[], taken: Set<string>): Duty {
|
|
138
|
+
const was = taken.has(draft.id ?? "") ? undefined : current.find((duty) => duty.id === draft.id);
|
|
139
|
+
const id = was?.id ?? `d-${randomUUID().slice(0, 8)}`;
|
|
140
|
+
taken.add(id);
|
|
141
|
+
return {
|
|
142
|
+
id,
|
|
143
|
+
name: draft.name.trim(),
|
|
144
|
+
instructions: draft.instructions.trim(),
|
|
145
|
+
days: [...new Set(draft.days)].sort((a, b) => a - b),
|
|
146
|
+
...(was?.chore === undefined ? {} : { chore: was.chore }),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function createDutyService(ports: DutyServicePorts): DutyService {
|
|
151
|
+
let duties: readonly Duty[] = STARTING_DUTIES;
|
|
152
|
+
let day: string | null = null;
|
|
153
|
+
// Why the kept file could not be read nor moved aside: a save would replace it, so none is made.
|
|
154
|
+
let unreadable: string | null = null;
|
|
155
|
+
let chain: Promise<unknown> = Promise.resolve();
|
|
156
|
+
const follower = createScheduleFollower({
|
|
157
|
+
schedules: ports.schedules,
|
|
158
|
+
schedule: DUTIES,
|
|
159
|
+
log: ports.log,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
function exclusive<T>(work: () => Promise<T>): Promise<T> {
|
|
163
|
+
const run = chain.then(work);
|
|
164
|
+
chain = run.catch(() => undefined);
|
|
165
|
+
return run;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function tell(): void {
|
|
169
|
+
ports.changed({ duties: [...duties], day });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** `dueAt`: a timer can fire a little before its 08:00, which is then the board's instant. */
|
|
173
|
+
async function bringUp(dueAt?: number): Promise<void> {
|
|
174
|
+
try {
|
|
175
|
+
const zone = await ports.zone();
|
|
176
|
+
const clock = dutyClock(Math.max(ports.now(), dueAt ?? 0), zone);
|
|
177
|
+
const due = clock.open ? duties.filter((duty) => duty.days.includes(clock.weekday)) : [];
|
|
178
|
+
const dayOf = (at: number) => dutyClock(at, zone).day;
|
|
179
|
+
await ports.board.syncDuties({ duties, day: clock.day, due, dayOf });
|
|
180
|
+
day = clock.day;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
ports.log(`[office] duty board sync failed: ${errorMessage(error)}`);
|
|
183
|
+
}
|
|
184
|
+
tell();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
start: () =>
|
|
189
|
+
exclusive(async () => {
|
|
190
|
+
const kept = await ports.file.load().catch((error: unknown) => {
|
|
191
|
+
unreadable = errorMessage(error);
|
|
192
|
+
ports.log(`[office] duty list unreadable: ${unreadable}`);
|
|
193
|
+
return null;
|
|
194
|
+
});
|
|
195
|
+
if (kept !== null) duties = kept.duties;
|
|
196
|
+
ports.listed(duties);
|
|
197
|
+
await bringUp();
|
|
198
|
+
}),
|
|
199
|
+
list: () => duties,
|
|
200
|
+
save: (drafts) =>
|
|
201
|
+
exclusive(async (): Promise<DutySaveResult> => {
|
|
202
|
+
const problem = dutyListProblem(drafts);
|
|
203
|
+
if (problem !== null) return { ok: false, error: problem };
|
|
204
|
+
if (unreadable !== null) {
|
|
205
|
+
return {
|
|
206
|
+
ok: false,
|
|
207
|
+
error: `Unable to save the duty list: the kept one could not be read, and a save would replace it (${unreadable})`,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const taken = new Set<string>();
|
|
211
|
+
const next = drafts.map((draft) => keptDuty(draft, duties, taken));
|
|
212
|
+
try {
|
|
213
|
+
await ports.file.save({ version: 1, duties: next });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
return { ok: false, error: `Unable to save the duty list: ${errorMessage(error)}` };
|
|
216
|
+
}
|
|
217
|
+
duties = next;
|
|
218
|
+
ports.listed(duties);
|
|
219
|
+
await bringUp();
|
|
220
|
+
return { ok: true };
|
|
221
|
+
}),
|
|
222
|
+
sync: (dueAt) => exclusive(() => bringUp(dueAt)),
|
|
223
|
+
async settingsChanged() {
|
|
224
|
+
const zone = await ports.zone();
|
|
225
|
+
await follower.sync(() => dutyCadence(zone));
|
|
226
|
+
await exclusive(() => bringUp());
|
|
227
|
+
},
|
|
228
|
+
error: follower.error,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { GroupPhotoSchema } from "../shared/contracts.js";
|
|
2
|
+
|
|
3
|
+
/** Check the JPEG's frame size before keeping or broadcasting a client's data URL. */
|
|
4
|
+
export function isOfficePhoto(data: string): boolean {
|
|
5
|
+
if (!GroupPhotoSchema.safeParse(data).success) return false;
|
|
6
|
+
const encoded = data.slice("data:image/jpeg;base64,".length);
|
|
7
|
+
const image = Buffer.from(encoded, "base64");
|
|
8
|
+
if (
|
|
9
|
+
image.length < 16 ||
|
|
10
|
+
image.toString("base64") !== encoded ||
|
|
11
|
+
image.readUInt16BE(image.length - 2) !== 0xffd9
|
|
12
|
+
)
|
|
13
|
+
return false;
|
|
14
|
+
let framed = false;
|
|
15
|
+
for (let at = 2; at + 4 <= image.length; ) {
|
|
16
|
+
if (image[at] !== 0xff) return false;
|
|
17
|
+
if (image[at + 1] === 0xff) {
|
|
18
|
+
at++;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const marker = image[at + 1];
|
|
22
|
+
const length = image.readUInt16BE(at + 2);
|
|
23
|
+
if (length < 2 || at + 2 + length > image.length - 2) return false;
|
|
24
|
+
if (marker === 0xda) return framed && length >= 6 && at + 2 + length < image.length - 2;
|
|
25
|
+
if (marker === 0xc0 || marker === 0xc2) {
|
|
26
|
+
if (
|
|
27
|
+
framed ||
|
|
28
|
+
length < 11 ||
|
|
29
|
+
image[at + 4] !== 8 ||
|
|
30
|
+
image.readUInt16BE(at + 5) !== 360 ||
|
|
31
|
+
image.readUInt16BE(at + 7) !== 480
|
|
32
|
+
)
|
|
33
|
+
return false;
|
|
34
|
+
framed = true;
|
|
35
|
+
}
|
|
36
|
+
at += length + 2;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { waitingOnOf } from "../shared/model.js";
|
|
2
|
+
import type { OfficeSnapshot } from "../shared/contracts.js";
|
|
3
|
+
import type { Paseo } from "./paseo-holder.js";
|
|
4
|
+
|
|
5
|
+
// Several open floors can see the same person leave. Archive once per session and idle period.
|
|
6
|
+
export function createDepartureArchiver(
|
|
7
|
+
read: () => Promise<OfficeSnapshot>,
|
|
8
|
+
archiveEnabled: () => Promise<boolean>,
|
|
9
|
+
) {
|
|
10
|
+
const pending = new Map<string, Promise<boolean>>();
|
|
11
|
+
|
|
12
|
+
async function archive(paseo: Paseo, agentId: string, idleSince: string) {
|
|
13
|
+
const { agents } = await read();
|
|
14
|
+
const row = agents.find((agent) => agent.id === agentId);
|
|
15
|
+
if (
|
|
16
|
+
!row ||
|
|
17
|
+
row.status !== "idle" ||
|
|
18
|
+
row.idleSince !== idleSince ||
|
|
19
|
+
row.permissions.length ||
|
|
20
|
+
waitingOnOf(agents).has(agentId)
|
|
21
|
+
)
|
|
22
|
+
return false;
|
|
23
|
+
const ref = paseo.agents.ref(agentId);
|
|
24
|
+
const result = await ref.refresh();
|
|
25
|
+
const agent = result?.agent;
|
|
26
|
+
if (
|
|
27
|
+
!agent ||
|
|
28
|
+
agent.archivedAt ||
|
|
29
|
+
agent.status !== "idle" ||
|
|
30
|
+
agent.pendingPermissions.length ||
|
|
31
|
+
agent.updatedAt !== idleSince
|
|
32
|
+
)
|
|
33
|
+
return false;
|
|
34
|
+
if (!(await archiveEnabled())) return false;
|
|
35
|
+
await ref.archive();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (paseo: Paseo, agentId: string, idleSince: string) => {
|
|
40
|
+
const key = JSON.stringify([agentId, idleSince]);
|
|
41
|
+
const current = pending.get(key);
|
|
42
|
+
if (current) return current;
|
|
43
|
+
const work = archive(paseo, agentId, idleSince).finally(() => pending.delete(key));
|
|
44
|
+
pending.set(key, work);
|
|
45
|
+
return work;
|
|
46
|
+
};
|
|
47
|
+
}
|
package/server/hub.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type {
|
|
|
4
4
|
IncidentsState,
|
|
5
5
|
WeatherState,
|
|
6
6
|
Checklists,
|
|
7
|
+
ChecklistCounts,
|
|
8
|
+
DutyBoard,
|
|
7
9
|
NotesState,
|
|
8
10
|
OfficeAgent,
|
|
9
11
|
OfficeEvent,
|
|
@@ -51,6 +53,7 @@ export interface HubPorts {
|
|
|
51
53
|
activity: ActivityLines,
|
|
52
54
|
doing: ActivitySteps,
|
|
53
55
|
checklists: Readonly<Checklists>,
|
|
56
|
+
progress?: Readonly<ChecklistCounts>,
|
|
54
57
|
) => void,
|
|
55
58
|
): () => void;
|
|
56
59
|
timers: Timers;
|
|
@@ -68,9 +71,12 @@ export interface Hub {
|
|
|
68
71
|
setWake(wake: WakeState): void;
|
|
69
72
|
/** The stand-up notes writer's state; the same state again sends nothing. */
|
|
70
73
|
setNotes(notes: NotesState): void;
|
|
74
|
+
/** The duty list and the duty board's day; the same again sends nothing. */
|
|
75
|
+
setDuties(duties: DutyBoard): void;
|
|
71
76
|
/** The open incidents and the trackers' state; the same state again sends nothing. */
|
|
72
77
|
setIncidents(incidents: IncidentsState): void;
|
|
73
78
|
/** A changed sky or service status is sent to every subscriber. */
|
|
79
|
+
setBrand(brand: OfficeSnapshot["brand"]): void;
|
|
74
80
|
setWeather(weather: WeatherState): void;
|
|
75
81
|
/**
|
|
76
82
|
* The conversation each snapshot carries from now on; null removes it. Every subscriber gets a
|
|
@@ -131,11 +137,15 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
131
137
|
let doing: ActivitySteps = {};
|
|
132
138
|
// Kept after an agent stops, as the poller reads only running agents; dropped when it leaves.
|
|
133
139
|
let checklists: Checklists = {};
|
|
140
|
+
let checklistProgress: ChecklistCounts = {};
|
|
134
141
|
let boards: Record<string, readonly Post[]> = {};
|
|
135
142
|
let wake: WakeState = { paused: false, queued: {} };
|
|
136
143
|
let notes: NotesState | null = null;
|
|
137
144
|
let sentNotes = "";
|
|
145
|
+
let duties: DutyBoard | null = null;
|
|
146
|
+
let sentDuties = "";
|
|
138
147
|
let incidents: IncidentsState | null = null;
|
|
148
|
+
let brand: OfficeSnapshot["brand"];
|
|
139
149
|
let weather: WeatherState | null = null;
|
|
140
150
|
let sentWeather = "";
|
|
141
151
|
let sentIncidents = "";
|
|
@@ -159,12 +169,17 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
159
169
|
activity: { ...activity },
|
|
160
170
|
doing: { ...doing },
|
|
161
171
|
checklists: { ...checklists },
|
|
172
|
+
...(Object.keys(checklistProgress).length
|
|
173
|
+
? { checklistProgress: { ...checklistProgress } }
|
|
174
|
+
: {}),
|
|
162
175
|
boards: copy,
|
|
176
|
+
...(brand ? { brand } : {}),
|
|
163
177
|
wake: { paused: wake.paused, queued: { ...wake.queued } },
|
|
164
178
|
...(notes === null ? {} : { notes: { ...notes } }),
|
|
165
179
|
...(weather === null ? {} : { weather }),
|
|
166
180
|
...(incidents === null ? {} : { incidents: { ...incidents } }),
|
|
167
181
|
...(chatSource === null ? {} : { chat: chatSource() }),
|
|
182
|
+
...(duties === null ? {} : { duties: { ...duties, duties: [...duties.duties] } }),
|
|
168
183
|
};
|
|
169
184
|
}
|
|
170
185
|
|
|
@@ -271,6 +286,9 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
271
286
|
activity: { ...activity },
|
|
272
287
|
doing: { ...doing },
|
|
273
288
|
checklists: { ...checklists },
|
|
289
|
+
...(Object.keys(checklistProgress).length
|
|
290
|
+
? { checklistProgress: { ...checklistProgress } }
|
|
291
|
+
: {}),
|
|
274
292
|
};
|
|
275
293
|
}
|
|
276
294
|
|
|
@@ -278,7 +296,12 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
278
296
|
reported = next;
|
|
279
297
|
const listed = new Set(next.agents.map((agent) => agent.id));
|
|
280
298
|
const kept = Object.entries(checklists).filter(([agentId]) => listed.has(agentId));
|
|
281
|
-
|
|
299
|
+
const keptProgress = Object.entries(checklistProgress).filter(([id]) => listed.has(id));
|
|
300
|
+
if (
|
|
301
|
+
kept.length < Object.keys(checklists).length ||
|
|
302
|
+
keptProgress.length < Object.keys(checklistProgress).length
|
|
303
|
+
) {
|
|
304
|
+
checklistProgress = Object.fromEntries(keptProgress);
|
|
282
305
|
checklists = Object.fromEntries(kept);
|
|
283
306
|
// An agent that left the list takes its checklist with it now, not at the next poll round.
|
|
284
307
|
if (stopDirectory !== null) broadcast(activityEvent());
|
|
@@ -311,6 +334,7 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
311
334
|
next: ActivityLines,
|
|
312
335
|
steps: ActivitySteps,
|
|
313
336
|
report: Readonly<Checklists>,
|
|
337
|
+
progress: Readonly<ChecklistCounts> = {},
|
|
314
338
|
): void {
|
|
315
339
|
activity = next;
|
|
316
340
|
doing = steps;
|
|
@@ -318,6 +342,11 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
318
342
|
const fresh = Object.entries(report).filter(([agentId]) => listed.has(agentId));
|
|
319
343
|
const merged = Object.entries({ ...checklists, ...Object.fromEntries(fresh) });
|
|
320
344
|
checklists = Object.fromEntries(merged.filter(([, list]) => list.length > 0));
|
|
345
|
+
for (const [id, count] of Object.entries(progress)) {
|
|
346
|
+
if (!listed.has(id)) continue;
|
|
347
|
+
if (count.total > 0) checklistProgress[id] = count;
|
|
348
|
+
else delete checklistProgress[id];
|
|
349
|
+
}
|
|
321
350
|
broadcast(activityEvent());
|
|
322
351
|
}
|
|
323
352
|
|
|
@@ -414,6 +443,7 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
414
443
|
activity = {};
|
|
415
444
|
doing = {};
|
|
416
445
|
checklists = {};
|
|
446
|
+
checklistProgress = {};
|
|
417
447
|
const stop = stopDirectory;
|
|
418
448
|
stopDirectory = null;
|
|
419
449
|
view = EMPTY_VIEW;
|
|
@@ -481,6 +511,18 @@ export function createHub(ports: HubPorts): Hub {
|
|
|
481
511
|
notes = { ...next };
|
|
482
512
|
broadcast({ type: "snapshot", state: snapshot() });
|
|
483
513
|
},
|
|
514
|
+
setDuties(next) {
|
|
515
|
+
const text = JSON.stringify(next);
|
|
516
|
+
if (text === sentDuties) return;
|
|
517
|
+
sentDuties = text;
|
|
518
|
+
duties = { ...next, duties: [...next.duties] };
|
|
519
|
+
broadcast({ type: "snapshot", state: snapshot() });
|
|
520
|
+
},
|
|
521
|
+
setBrand(next) {
|
|
522
|
+
if (JSON.stringify(brand) === JSON.stringify(next)) return;
|
|
523
|
+
brand = next;
|
|
524
|
+
broadcast({ type: "snapshot", state: snapshot() });
|
|
525
|
+
},
|
|
484
526
|
setWeather(next) {
|
|
485
527
|
const text = JSON.stringify(next);
|
|
486
528
|
if (text === sentWeather) return;
|