@gpambrozio/paseo-herald 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/CHANGELOG.md +50 -0
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/client/announcer.ts +285 -0
- package/client/herald.tsx +617 -0
- package/client/option-picker.tsx +171 -0
- package/client/prompt-editor.tsx +185 -0
- package/client/settings-screen.tsx +407 -0
- package/client/timeline-card.tsx +146 -0
- package/client/web.ts +255 -0
- package/index.client.tsx +65 -0
- package/index.server.ts +55 -0
- package/package.json +43 -0
- package/paseo-plugin.json +7 -0
- package/server/card.ts +75 -0
- package/server/config.ts +62 -0
- package/server/hooks.ts +372 -0
- package/server/liveness.ts +159 -0
- package/server/say.ts +132 -0
- package/server/sdk-types.ts +24 -0
- package/server/store.ts +194 -0
- package/server/summarize.ts +223 -0
- package/server/timeline.ts +194 -0
- package/server/workspaces.ts +33 -0
- package/shared/herald.ts +234 -0
- package/shared/settings.ts +60 -0
- package/shared/timeline.ts +32 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The surface: every agent waiting on the user, each with the sentence Herald
|
|
3
|
+
* wrote for it, a button to open the session, and a button to hear it again.
|
|
4
|
+
*
|
|
5
|
+
* Two sources, joined by agent id. Paseo's own attention flag decides who is
|
|
6
|
+
* listed — it is what the sidebar badges already follow — and Herald's entries
|
|
7
|
+
* explain why, in a sentence. An agent Paseo flags that Herald has no entry
|
|
8
|
+
* for (an event before the plugin loaded, say) is still listed, with what Paseo
|
|
9
|
+
* knows about the reason.
|
|
10
|
+
*
|
|
11
|
+
* Async **function expressions**, never async arrows, anywhere in this file:
|
|
12
|
+
* the app `eval`s the client bundle, and Hermes's eval compiler on iOS and
|
|
13
|
+
* Android evaluates an async arrow to `undefined`. Same reason every closure
|
|
14
|
+
* over a list element goes through `.map`, never a `for…of` body.
|
|
15
|
+
*/
|
|
16
|
+
import { type PluginSurfaceProps, usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
17
|
+
import { Icon, useToast } from "@getpaseo/plugin/client/react-native";
|
|
18
|
+
import { type ReactElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
19
|
+
import { ActivityIndicator, Pressable, ScrollView, Text, View } from "react-native";
|
|
20
|
+
|
|
21
|
+
import { listAttention, type AttentionEntry, type AttentionReason } from "../shared/herald";
|
|
22
|
+
import { getAnnouncer, isMutedHere, setMutedHere, speechText } from "./announcer";
|
|
23
|
+
import { canPlaySpeech, speechPlatform } from "./web";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Opening the settings screen is a `PluginClientContext` capability:
|
|
27
|
+
* `PluginSurfaceProps` carries no `openSettings`, so the surface cannot reach
|
|
28
|
+
* its own settings on its own. `index.client.tsx` has the context and hands the
|
|
29
|
+
* opener down here at contribution time — which happens before any surface can
|
|
30
|
+
* mount — and the header button calls it. Module scope belongs to this client's
|
|
31
|
+
* bundle eval, the same place the other plugins here keep their surface caches.
|
|
32
|
+
*/
|
|
33
|
+
let openSettingsScreen: ((id: string) => void) | null = null;
|
|
34
|
+
|
|
35
|
+
export function bindSettingsOpener(open: ((id: string) => void) | null): void {
|
|
36
|
+
openSettingsScreen = open;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A row's reason: one of Herald's, or "attention" when only Paseo's flag is known. */
|
|
40
|
+
type RowReason = AttentionReason | "attention";
|
|
41
|
+
|
|
42
|
+
interface Row {
|
|
43
|
+
agentId: string;
|
|
44
|
+
title: string | null;
|
|
45
|
+
workspaceId: string | null;
|
|
46
|
+
cwd: string;
|
|
47
|
+
reason: RowReason;
|
|
48
|
+
/** ISO time the row sorts by: the event, or when Paseo flagged the agent. */
|
|
49
|
+
at: string;
|
|
50
|
+
entry: AttentionEntry | null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The fields this surface reads off a Paseo agent snapshot. */
|
|
54
|
+
interface FlaggedAgent {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string | null;
|
|
57
|
+
workspaceId: string | null;
|
|
58
|
+
cwd: string;
|
|
59
|
+
status: string;
|
|
60
|
+
attentionReason: "finished" | "error" | "permission" | null;
|
|
61
|
+
at: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A Paseo-flagged agent worth a row: one whose session is still open. Paseo
|
|
66
|
+
* keeps an agent flagged until the user's next message, however long ago the
|
|
67
|
+
* turn ended, and that is right — a question asked a week ago is still
|
|
68
|
+
* unanswered. A *closed* session is not waiting on anyone until it is opened
|
|
69
|
+
* again, and a turn reported as finished on an agent that is *running* was
|
|
70
|
+
* not the end of anything — some providers say a turn is done and carry on.
|
|
71
|
+
* Those two are the cases dropped here.
|
|
72
|
+
*/
|
|
73
|
+
function isCurrent(agent: FlaggedAgent): boolean {
|
|
74
|
+
if (agent.status === "closed") return false;
|
|
75
|
+
if (agent.attentionReason === "finished" && agent.status === "running") return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Module-scope caches, because the surface is unmounted whenever the user
|
|
81
|
+
* navigates to an agent — which the Open button does — and mounted fresh on
|
|
82
|
+
* the way back. The list repaints before the first load answers.
|
|
83
|
+
*
|
|
84
|
+
* Workspace names come from the host API, not `useWorkspace`: the SDK's state
|
|
85
|
+
* hooks are for workspace and agent panels and throw in a sidebar surface
|
|
86
|
+
* ("Plugin state hooks must run inside a workspace panel").
|
|
87
|
+
*/
|
|
88
|
+
let cachedRows: Row[] | null = null;
|
|
89
|
+
let cachedWorkspaceNames: Record<string, string> = {};
|
|
90
|
+
|
|
91
|
+
const IDLE_REFRESH_MS = 10_000;
|
|
92
|
+
const BUSY_REFRESH_MS = 2_500;
|
|
93
|
+
|
|
94
|
+
const TEST_SENTENCE = "This is Herald. Your agents will be announced like this.";
|
|
95
|
+
|
|
96
|
+
function withAlpha(color: string, alpha: string): string {
|
|
97
|
+
return /^#[0-9a-fA-F]{6}$/.test(color) ? `${color}${alpha}` : color;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function relativeTime(iso: string): string {
|
|
101
|
+
const seconds = Math.round((Date.now() - new Date(iso).getTime()) / 1000);
|
|
102
|
+
if (!Number.isFinite(seconds)) return "";
|
|
103
|
+
if (seconds < 45) return "just now";
|
|
104
|
+
const minutes = Math.round(seconds / 60);
|
|
105
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
106
|
+
const hours = Math.round(minutes / 60);
|
|
107
|
+
if (hours < 24) return `${hours} h ago`;
|
|
108
|
+
const days = Math.round(hours / 24);
|
|
109
|
+
return days === 1 ? "yesterday" : `${days} days ago`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function basename(path: string): string {
|
|
113
|
+
const parts = path.split("/").filter((part) => part !== "");
|
|
114
|
+
return parts[parts.length - 1] ?? path;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function errorText(error: unknown): string {
|
|
118
|
+
return error instanceof Error ? error.message : String(error);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface ReasonLook {
|
|
122
|
+
icon: string;
|
|
123
|
+
label: string;
|
|
124
|
+
tone: "accent" | "success" | "warning" | "danger" | "muted";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function lookOf(reason: RowReason): ReasonLook {
|
|
128
|
+
switch (reason) {
|
|
129
|
+
case "question":
|
|
130
|
+
return { icon: "MessageCircle", label: "Question", tone: "accent" };
|
|
131
|
+
case "plan":
|
|
132
|
+
return { icon: "ClipboardList", label: "Plan to approve", tone: "accent" };
|
|
133
|
+
case "permission":
|
|
134
|
+
return { icon: "Shield", label: "Permission", tone: "warning" };
|
|
135
|
+
case "finished":
|
|
136
|
+
return { icon: "Check", label: "Finished", tone: "success" };
|
|
137
|
+
case "error":
|
|
138
|
+
return { icon: "X", label: "Error", tone: "danger" };
|
|
139
|
+
case "canceled":
|
|
140
|
+
return { icon: "Ban", label: "Interrupted", tone: "muted" };
|
|
141
|
+
case "attention":
|
|
142
|
+
return { icon: "Megaphone", label: "Needs you", tone: "accent" };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Herald's entries win over Paseo's flags for the same agent, since they carry
|
|
148
|
+
* the reason and the sentence. A *finished* entry on an agent that is working
|
|
149
|
+
* again is already withheld by the daemon, which knows each entry's agent
|
|
150
|
+
* without having to enumerate every running one — see `Liveness`.
|
|
151
|
+
*/
|
|
152
|
+
function joinRows(entries: AttentionEntry[], flagged: FlaggedAgent[]): Row[] {
|
|
153
|
+
const byAgent = new Map<string, Row>();
|
|
154
|
+
entries.forEach((entry) => {
|
|
155
|
+
byAgent.set(entry.agentId, {
|
|
156
|
+
agentId: entry.agentId,
|
|
157
|
+
title: entry.agentTitle,
|
|
158
|
+
workspaceId: entry.workspaceId,
|
|
159
|
+
cwd: entry.cwd,
|
|
160
|
+
reason: entry.reason,
|
|
161
|
+
at: entry.createdAt,
|
|
162
|
+
entry,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
flagged.forEach((agent) => {
|
|
166
|
+
if (byAgent.has(agent.id) || !isCurrent(agent)) return;
|
|
167
|
+
byAgent.set(agent.id, {
|
|
168
|
+
agentId: agent.id,
|
|
169
|
+
title: agent.title,
|
|
170
|
+
workspaceId: agent.workspaceId,
|
|
171
|
+
cwd: agent.cwd,
|
|
172
|
+
reason: agent.attentionReason ?? "attention",
|
|
173
|
+
at: agent.at,
|
|
174
|
+
entry: null,
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return [...byAgent.values()].sort((a, b) => b.at.localeCompare(a.at));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
// Styles
|
|
182
|
+
|
|
183
|
+
function useStyles({ theme, layout }: PluginSurfaceProps) {
|
|
184
|
+
return useMemo(() => {
|
|
185
|
+
const { colors } = theme;
|
|
186
|
+
const separator = withAlpha(colors.foregroundMuted, "33");
|
|
187
|
+
const pad = layout.compact ? 12 : 16;
|
|
188
|
+
return {
|
|
189
|
+
screen: { flex: 1, backgroundColor: colors.surface0 },
|
|
190
|
+
header: {
|
|
191
|
+
flexDirection: "row" as const,
|
|
192
|
+
alignItems: "center" as const,
|
|
193
|
+
gap: 8,
|
|
194
|
+
paddingHorizontal: pad,
|
|
195
|
+
paddingVertical: layout.compact ? 10 : 12,
|
|
196
|
+
borderBottomWidth: 1,
|
|
197
|
+
borderBottomColor: separator,
|
|
198
|
+
},
|
|
199
|
+
title: { color: colors.foreground, fontSize: layout.compact ? 17 : 19, fontWeight: "600" as const },
|
|
200
|
+
count: {
|
|
201
|
+
color: colors.accentForeground,
|
|
202
|
+
backgroundColor: colors.accent,
|
|
203
|
+
borderRadius: 10,
|
|
204
|
+
paddingHorizontal: 7,
|
|
205
|
+
paddingVertical: 1,
|
|
206
|
+
fontSize: 12,
|
|
207
|
+
fontWeight: "600" as const,
|
|
208
|
+
},
|
|
209
|
+
spacer: { flex: 1 },
|
|
210
|
+
toolButton: {
|
|
211
|
+
flexDirection: "row" as const,
|
|
212
|
+
alignItems: "center" as const,
|
|
213
|
+
gap: 6,
|
|
214
|
+
paddingHorizontal: 10,
|
|
215
|
+
paddingVertical: 6,
|
|
216
|
+
borderRadius: 8,
|
|
217
|
+
borderWidth: 1,
|
|
218
|
+
borderColor: separator,
|
|
219
|
+
},
|
|
220
|
+
toolButtonText: { color: colors.foreground, fontSize: 13 },
|
|
221
|
+
hint: {
|
|
222
|
+
color: colors.foregroundMuted,
|
|
223
|
+
fontSize: 12,
|
|
224
|
+
paddingHorizontal: pad,
|
|
225
|
+
paddingTop: 8,
|
|
226
|
+
lineHeight: 17,
|
|
227
|
+
},
|
|
228
|
+
banner: {
|
|
229
|
+
marginHorizontal: pad,
|
|
230
|
+
marginTop: 10,
|
|
231
|
+
padding: 10,
|
|
232
|
+
borderRadius: 8,
|
|
233
|
+
backgroundColor: withAlpha(colors.statusDanger, "22"),
|
|
234
|
+
},
|
|
235
|
+
bannerText: { color: colors.statusDanger, fontSize: 13 },
|
|
236
|
+
list: { padding: pad, gap: 10 },
|
|
237
|
+
empty: { padding: pad * 2, alignItems: "center" as const, gap: 8 },
|
|
238
|
+
emptyTitle: { color: colors.foreground, fontSize: 15, fontWeight: "600" as const },
|
|
239
|
+
emptyText: { color: colors.foregroundMuted, fontSize: 13, textAlign: "center" as const },
|
|
240
|
+
card: {
|
|
241
|
+
backgroundColor: colors.surface1,
|
|
242
|
+
borderRadius: 10,
|
|
243
|
+
borderWidth: 1,
|
|
244
|
+
borderColor: separator,
|
|
245
|
+
padding: layout.compact ? 12 : 14,
|
|
246
|
+
gap: 8,
|
|
247
|
+
},
|
|
248
|
+
cardTop: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
|
|
249
|
+
cardTitle: { color: colors.foreground, fontSize: 15, fontWeight: "600" as const, flexShrink: 1 },
|
|
250
|
+
cardMeta: { color: colors.foregroundMuted, fontSize: 12 },
|
|
251
|
+
reasonPill: {
|
|
252
|
+
flexDirection: "row" as const,
|
|
253
|
+
alignItems: "center" as const,
|
|
254
|
+
gap: 4,
|
|
255
|
+
paddingHorizontal: 8,
|
|
256
|
+
paddingVertical: 2,
|
|
257
|
+
borderRadius: 999,
|
|
258
|
+
},
|
|
259
|
+
reasonText: { fontSize: 12, fontWeight: "600" as const },
|
|
260
|
+
headline: { color: colors.foreground, fontSize: 14, lineHeight: 20 },
|
|
261
|
+
detail: { color: colors.foregroundMuted, fontSize: 13, lineHeight: 18 },
|
|
262
|
+
summary: { color: colors.foreground, fontSize: 14, lineHeight: 20, fontStyle: "italic" as const },
|
|
263
|
+
summaryMuted: { color: colors.foregroundMuted, fontSize: 14, lineHeight: 20, fontStyle: "italic" as const },
|
|
264
|
+
pending: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
|
|
265
|
+
pendingText: { color: colors.foregroundMuted, fontSize: 13 },
|
|
266
|
+
cardPressed: { backgroundColor: colors.surface2 },
|
|
267
|
+
speaker: { padding: 4 },
|
|
268
|
+
};
|
|
269
|
+
}, [theme, layout.compact]);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
type Styles = ReturnType<typeof useStyles>;
|
|
273
|
+
|
|
274
|
+
function toneColor(theme: PluginSurfaceProps["theme"], tone: ReasonLook["tone"]): string {
|
|
275
|
+
const { colors } = theme;
|
|
276
|
+
switch (tone) {
|
|
277
|
+
case "accent":
|
|
278
|
+
return colors.accent;
|
|
279
|
+
case "success":
|
|
280
|
+
return colors.statusSuccess;
|
|
281
|
+
case "warning":
|
|
282
|
+
return colors.statusWarning;
|
|
283
|
+
case "danger":
|
|
284
|
+
return colors.statusDanger;
|
|
285
|
+
case "muted":
|
|
286
|
+
return colors.foregroundMuted;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
// Rows
|
|
292
|
+
|
|
293
|
+
interface RowCardProps {
|
|
294
|
+
row: Row;
|
|
295
|
+
workspaceName: string | null;
|
|
296
|
+
props: PluginSurfaceProps;
|
|
297
|
+
styles: Styles;
|
|
298
|
+
onOpen: ((agentId: string) => void) | null;
|
|
299
|
+
onSpeak: (row: Row) => void;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The whole card opens the session; the speaker right after the title says
|
|
304
|
+
* the sentence again — beside the title, not at the card's edge, so it is seen. Nested pressables: the speaker takes the touch
|
|
305
|
+
* and the card does not also open.
|
|
306
|
+
*/
|
|
307
|
+
function RowCard({ row, workspaceName, props, styles, onOpen, onSpeak }: RowCardProps) {
|
|
308
|
+
const look = lookOf(row.reason);
|
|
309
|
+
const color = toneColor(props.theme, look.tone);
|
|
310
|
+
const muted = props.theme.colors.foregroundMuted;
|
|
311
|
+
const entry = row.entry;
|
|
312
|
+
// Agents are usually untitled; the workspace names the work. Under it, the
|
|
313
|
+
// agent's own title or, failing that, what it was last asked — which is
|
|
314
|
+
// what tells two untitled agents in one workspace apart.
|
|
315
|
+
const title = workspaceName ?? entry?.workspaceTitle ?? basename(row.cwd);
|
|
316
|
+
const subtitle = row.title?.trim() || entry?.lastRequest || null;
|
|
317
|
+
const spoken = entry === null ? null : speechText(entry);
|
|
318
|
+
// Hidden outright where nothing can play it, rather than offered and failing.
|
|
319
|
+
const canSpeakRow = canPlaySpeech() && (entry === null || spoken !== null);
|
|
320
|
+
|
|
321
|
+
let summaryNode: ReactElement | null;
|
|
322
|
+
if (entry === null) {
|
|
323
|
+
summaryNode = null;
|
|
324
|
+
} else if (entry.summary.status === "pending") {
|
|
325
|
+
summaryNode = (
|
|
326
|
+
<View style={styles.pending}>
|
|
327
|
+
<ActivityIndicator size="small" color={muted} />
|
|
328
|
+
<Text style={styles.pendingText}>Writing the summary…</Text>
|
|
329
|
+
</View>
|
|
330
|
+
);
|
|
331
|
+
} else if (entry.summary.status === "ready") {
|
|
332
|
+
summaryNode = <Text style={styles.summary}>{entry.summary.text}</Text>;
|
|
333
|
+
} else if (entry.summary.status === "failed") {
|
|
334
|
+
summaryNode = (
|
|
335
|
+
<View style={{ gap: 2 }}>
|
|
336
|
+
<Text style={styles.summaryMuted}>{entry.summary.fallback}</Text>
|
|
337
|
+
<Text style={styles.cardMeta}>Summary failed: {entry.summary.error}</Text>
|
|
338
|
+
</View>
|
|
339
|
+
);
|
|
340
|
+
} else {
|
|
341
|
+
summaryNode = <Text style={styles.cardMeta}>Not announced: this kind of event is switched off in settings.</Text>;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<Pressable
|
|
346
|
+
accessibilityRole="button"
|
|
347
|
+
accessibilityLabel={`Open ${title}`}
|
|
348
|
+
disabled={onOpen === null}
|
|
349
|
+
onPress={onOpen === null ? undefined : () => onOpen(row.agentId)}
|
|
350
|
+
style={({ pressed }) => [styles.card, pressed ? styles.cardPressed : null]}
|
|
351
|
+
>
|
|
352
|
+
<View style={styles.cardTop}>
|
|
353
|
+
<View style={[styles.reasonPill, { backgroundColor: withAlpha(color, "22") }]}>
|
|
354
|
+
<Icon name={look.icon} size={13} color={color} />
|
|
355
|
+
<Text style={[styles.reasonText, { color }]}>{look.label}</Text>
|
|
356
|
+
</View>
|
|
357
|
+
<Text style={styles.cardTitle} numberOfLines={1}>
|
|
358
|
+
{title}
|
|
359
|
+
</Text>
|
|
360
|
+
{canSpeakRow ? (
|
|
361
|
+
<Pressable
|
|
362
|
+
accessibilityRole="button"
|
|
363
|
+
accessibilityLabel={`Speak the summary for ${title}`}
|
|
364
|
+
hitSlop={8}
|
|
365
|
+
onPress={() => onSpeak(row)}
|
|
366
|
+
style={styles.speaker}
|
|
367
|
+
>
|
|
368
|
+
<Icon name="Volume2" size={16} color={props.theme.colors.foreground} />
|
|
369
|
+
</Pressable>
|
|
370
|
+
) : null}
|
|
371
|
+
<View style={styles.spacer} />
|
|
372
|
+
<Text style={styles.cardMeta}>{relativeTime(row.at)}</Text>
|
|
373
|
+
</View>
|
|
374
|
+
{subtitle === null ? null : (
|
|
375
|
+
<Text style={styles.cardMeta} numberOfLines={1}>
|
|
376
|
+
{subtitle}
|
|
377
|
+
</Text>
|
|
378
|
+
)}
|
|
379
|
+
{entry === null ? (
|
|
380
|
+
<View style={{ gap: 2 }}>
|
|
381
|
+
<Text style={styles.headline}>{look.label === "Needs you" ? "Waiting for you." : `${look.label}.`}</Text>
|
|
382
|
+
<Text style={styles.detail}>No summary: this happened before Herald was watching this agent.</Text>
|
|
383
|
+
</View>
|
|
384
|
+
) : (
|
|
385
|
+
<View style={{ gap: 2 }}>
|
|
386
|
+
<Text style={styles.headline}>{entry.headline}</Text>
|
|
387
|
+
{entry.detail === null ? null : (
|
|
388
|
+
<Text style={styles.detail} numberOfLines={4}>
|
|
389
|
+
{entry.detail}
|
|
390
|
+
</Text>
|
|
391
|
+
)}
|
|
392
|
+
</View>
|
|
393
|
+
)}
|
|
394
|
+
{summaryNode}
|
|
395
|
+
</Pressable>
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// ---------------------------------------------------------------------------
|
|
400
|
+
// Surface
|
|
401
|
+
|
|
402
|
+
export function HeraldSurface(props: PluginSurfaceProps) {
|
|
403
|
+
const styles = useStyles(props);
|
|
404
|
+
const paseo = usePaseo();
|
|
405
|
+
const list = useRpc(listAttention);
|
|
406
|
+
const toast = useToast();
|
|
407
|
+
|
|
408
|
+
const [rows, setRows] = useState<Row[] | null>(cachedRows);
|
|
409
|
+
const [workspaceNames, setWorkspaceNames] = useState<Record<string, string>>(cachedWorkspaceNames);
|
|
410
|
+
const [error, setError] = useState<string | null>(null);
|
|
411
|
+
const [muted, setMuted] = useState(isMutedHere());
|
|
412
|
+
const [testing, setTesting] = useState(false);
|
|
413
|
+
const busyRef = useRef(false);
|
|
414
|
+
|
|
415
|
+
const refresh = useCallback(
|
|
416
|
+
async function refresh() {
|
|
417
|
+
if (busyRef.current) return;
|
|
418
|
+
busyRef.current = true;
|
|
419
|
+
try {
|
|
420
|
+
const [attention, flagged, workspaces] = await Promise.all([
|
|
421
|
+
list({}),
|
|
422
|
+
paseo.agents.list({ filter: { requiresAttention: true }, page: { limit: 100 } }),
|
|
423
|
+
paseo.workspaces.list({ page: { limit: 200 } }),
|
|
424
|
+
]);
|
|
425
|
+
const names: Record<string, string> = {};
|
|
426
|
+
workspaces.entries.forEach((workspace) => {
|
|
427
|
+
names[workspace.id] = workspace.title ?? workspace.name;
|
|
428
|
+
});
|
|
429
|
+
cachedWorkspaceNames = names;
|
|
430
|
+
setWorkspaceNames(names);
|
|
431
|
+
const agents: FlaggedAgent[] = flagged.entries.map((item) => ({
|
|
432
|
+
id: item.agent.id,
|
|
433
|
+
title: item.agent.title ?? null,
|
|
434
|
+
workspaceId: item.agent.workspaceId ?? null,
|
|
435
|
+
cwd: item.agent.cwd,
|
|
436
|
+
status: item.agent.status,
|
|
437
|
+
attentionReason: item.agent.attentionReason ?? null,
|
|
438
|
+
at: item.agent.attentionTimestamp ?? item.agent.updatedAt,
|
|
439
|
+
}));
|
|
440
|
+
const next = joinRows(attention.entries, agents);
|
|
441
|
+
cachedRows = next;
|
|
442
|
+
setRows(next);
|
|
443
|
+
setError(null);
|
|
444
|
+
} catch (caught) {
|
|
445
|
+
setError(errorText(caught));
|
|
446
|
+
} finally {
|
|
447
|
+
busyRef.current = false;
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
[list, paseo],
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
// A poll, quickened while a summary is being written, plus a nudge from
|
|
454
|
+
// Paseo's own agent stream so a new arrival shows within a moment.
|
|
455
|
+
const pending = rows?.some((row) => row.entry?.summary.status === "pending") ?? false;
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
void refresh();
|
|
458
|
+
const timer = setInterval(() => void refresh(), pending ? BUSY_REFRESH_MS : IDLE_REFRESH_MS);
|
|
459
|
+
let debounce: ReturnType<typeof setTimeout> | null = null;
|
|
460
|
+
const unsubscribe = paseo.agents.subscribe(() => {
|
|
461
|
+
if (debounce !== null) clearTimeout(debounce);
|
|
462
|
+
debounce = setTimeout(() => void refresh(), 400);
|
|
463
|
+
});
|
|
464
|
+
return () => {
|
|
465
|
+
clearInterval(timer);
|
|
466
|
+
if (debounce !== null) clearTimeout(debounce);
|
|
467
|
+
unsubscribe();
|
|
468
|
+
};
|
|
469
|
+
}, [refresh, pending, paseo]);
|
|
470
|
+
|
|
471
|
+
const openAgent = props.navigation?.openAgent;
|
|
472
|
+
const onOpen = useMemo(
|
|
473
|
+
() => (openAgent === undefined ? null : (agentId: string) => openAgent({ agentId })),
|
|
474
|
+
[openAgent],
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
const onSpeak = useCallback(
|
|
478
|
+
async function onSpeak(row: Row) {
|
|
479
|
+
const announcer = getAnnouncer();
|
|
480
|
+
if (announcer === null) return;
|
|
481
|
+
try {
|
|
482
|
+
const blocked =
|
|
483
|
+
row.entry !== null
|
|
484
|
+
? await announcer.speakEntry(row.entry)
|
|
485
|
+
: await announcer.speakText(
|
|
486
|
+
`${row.title?.trim() || workspaceNames[row.workspaceId ?? ""] || "An agent"} is waiting for you.`,
|
|
487
|
+
);
|
|
488
|
+
if (blocked !== null) toast.show(blocked, { variant: "info" });
|
|
489
|
+
} catch (caught) {
|
|
490
|
+
toast.error(errorText(caught));
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
[toast],
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
const onTest = useCallback(
|
|
497
|
+
async function onTest() {
|
|
498
|
+
const announcer = getAnnouncer();
|
|
499
|
+
if (announcer === null) return;
|
|
500
|
+
setTesting(true);
|
|
501
|
+
try {
|
|
502
|
+
await announcer.speakText(TEST_SENTENCE, { force: true });
|
|
503
|
+
} catch (caught) {
|
|
504
|
+
toast.error(errorText(caught));
|
|
505
|
+
} finally {
|
|
506
|
+
setTesting(false);
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
[toast],
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
const toggleMute = useCallback(() => {
|
|
513
|
+
const next = !isMutedHere();
|
|
514
|
+
setMutedHere(next);
|
|
515
|
+
setMuted(next);
|
|
516
|
+
}, []);
|
|
517
|
+
|
|
518
|
+
const platform = speechPlatform();
|
|
519
|
+
let hint: string | null = null;
|
|
520
|
+
if (platform === "mobile") {
|
|
521
|
+
hint = "Phones cannot play audio from a plugin yet, so there is nothing to press here. Herald vibrates instead when that is switched on in Settings › Plugins › Herald.";
|
|
522
|
+
} else if (!canPlaySpeech()) {
|
|
523
|
+
hint = "This browser can neither play audio nor speak, so summaries can only be read here.";
|
|
524
|
+
} else if (platform === "browser") {
|
|
525
|
+
hint = "In a browser tab, tap Test voice once so the page is allowed to speak.";
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const foreground = props.theme.colors.foreground;
|
|
529
|
+
const count = rows?.length ?? 0;
|
|
530
|
+
|
|
531
|
+
return (
|
|
532
|
+
<View style={styles.screen}>
|
|
533
|
+
<View style={styles.header}>
|
|
534
|
+
<Icon name="Megaphone" size={18} color={foreground} />
|
|
535
|
+
<Text style={styles.title}>Herald</Text>
|
|
536
|
+
{count > 0 ? <Text style={styles.count}>{count}</Text> : null}
|
|
537
|
+
<View style={styles.spacer} />
|
|
538
|
+
{canPlaySpeech() ? (
|
|
539
|
+
<>
|
|
540
|
+
<Pressable
|
|
541
|
+
accessibilityRole="button"
|
|
542
|
+
accessibilityLabel={muted ? "Unmute on this device" : "Mute on this device"}
|
|
543
|
+
onPress={toggleMute}
|
|
544
|
+
style={styles.toolButton}
|
|
545
|
+
>
|
|
546
|
+
<Icon name={muted ? "VolumeX" : "Volume2"} size={14} color={foreground} />
|
|
547
|
+
{props.layout.compact ? null : (
|
|
548
|
+
<Text style={styles.toolButtonText}>{muted ? "Muted here" : "Mute here"}</Text>
|
|
549
|
+
)}
|
|
550
|
+
</Pressable>
|
|
551
|
+
<Pressable
|
|
552
|
+
accessibilityRole="button"
|
|
553
|
+
accessibilityLabel="Test voice"
|
|
554
|
+
onPress={() => void onTest()}
|
|
555
|
+
disabled={testing}
|
|
556
|
+
style={styles.toolButton}
|
|
557
|
+
>
|
|
558
|
+
<Icon name="Play" size={14} color={foreground} />
|
|
559
|
+
{props.layout.compact ? null : <Text style={styles.toolButtonText}>Test voice</Text>}
|
|
560
|
+
</Pressable>
|
|
561
|
+
</>
|
|
562
|
+
) : null}
|
|
563
|
+
<Pressable
|
|
564
|
+
accessibilityRole="button"
|
|
565
|
+
accessibilityLabel="Refresh"
|
|
566
|
+
onPress={() => void refresh()}
|
|
567
|
+
style={styles.toolButton}
|
|
568
|
+
>
|
|
569
|
+
<Icon name="RefreshCw" size={14} color={foreground} />
|
|
570
|
+
</Pressable>
|
|
571
|
+
{openSettingsScreen === null ? null : (
|
|
572
|
+
<Pressable
|
|
573
|
+
accessibilityRole="button"
|
|
574
|
+
accessibilityLabel="Herald settings"
|
|
575
|
+
onPress={() => openSettingsScreen?.("herald")}
|
|
576
|
+
style={styles.toolButton}
|
|
577
|
+
>
|
|
578
|
+
<Icon name="Settings" size={14} color={foreground} />
|
|
579
|
+
</Pressable>
|
|
580
|
+
)}
|
|
581
|
+
</View>
|
|
582
|
+
{hint === null ? null : <Text style={styles.hint}>{hint}</Text>}
|
|
583
|
+
{error === null ? null : (
|
|
584
|
+
<View style={styles.banner}>
|
|
585
|
+
<Text style={styles.bannerText}>{error}</Text>
|
|
586
|
+
</View>
|
|
587
|
+
)}
|
|
588
|
+
<ScrollView contentContainerStyle={styles.list}>
|
|
589
|
+
{rows === null ? (
|
|
590
|
+
<View style={styles.empty}>
|
|
591
|
+
<ActivityIndicator color={props.theme.colors.foregroundMuted} />
|
|
592
|
+
</View>
|
|
593
|
+
) : rows.length === 0 ? (
|
|
594
|
+
<View style={styles.empty}>
|
|
595
|
+
<Text style={styles.emptyTitle}>Nothing needs you right now</Text>
|
|
596
|
+
<Text style={styles.emptyText}>
|
|
597
|
+
When an agent asks a question, pauses for permission, or finishes, it shows up here with a
|
|
598
|
+
one-sentence summary.
|
|
599
|
+
</Text>
|
|
600
|
+
</View>
|
|
601
|
+
) : (
|
|
602
|
+
rows.map((row) => (
|
|
603
|
+
<RowCard
|
|
604
|
+
key={row.agentId}
|
|
605
|
+
row={row}
|
|
606
|
+
workspaceName={row.workspaceId === null ? null : workspaceNames[row.workspaceId] ?? null}
|
|
607
|
+
props={props}
|
|
608
|
+
styles={styles}
|
|
609
|
+
onOpen={onOpen}
|
|
610
|
+
onSpeak={onSpeak}
|
|
611
|
+
/>
|
|
612
|
+
))
|
|
613
|
+
)}
|
|
614
|
+
</ScrollView>
|
|
615
|
+
</View>
|
|
616
|
+
);
|
|
617
|
+
}
|