@koinzhang/paseo-plugin-inbox 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ import type { Item } from "../shared/contracts.ts";
2
+
3
+ export interface SubtitlePart {
4
+ label: string;
5
+ archived: boolean;
6
+ }
7
+
8
+ export function formatItemTime(value: string, locale?: string): string {
9
+ const date = new Date(value);
10
+ return [
11
+ date.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit", second: "2-digit" }),
12
+ date.toLocaleDateString(locale),
13
+ ].join(" · ");
14
+ }
15
+
16
+ export function workspaceItemSubtitle(item: Item, agentUpdatedAt: string | null | undefined): SubtitlePart[] {
17
+ if (item.kind === "note") return [{ label: formatItemTime(item.updatedAt), archived: false }];
18
+ const provider = item.agentSnapshot?.provider ?? "agent";
19
+ const label = agentUpdatedAt ? `${provider} · ${formatItemTime(agentUpdatedAt)}` : `${provider} · starred ${formatItemTime(item.createdAt)}`;
20
+ return [{ label, archived: false }];
21
+ }
@@ -0,0 +1,145 @@
1
+ import { Icon } from "@getpaseo/plugin/client/ui";
2
+ import type { PluginTheme } from "@getpaseo/plugin";
3
+ import { Pressable, ScrollView, Text, View } from "react-native";
4
+ import type { ItemKind, ProjectSummary, WorkspaceSummary } from "../shared/contracts.ts";
5
+
6
+ const OPTIONS: ReadonlyArray<{ id: ItemKind; label: string; icon: string }> = [
7
+ { id: "agent", label: "Agents", icon: "Bot" },
8
+ { id: "note", label: "Notes", icon: "FileText" },
9
+ ];
10
+
11
+ export function KindFilterMenu({
12
+ value,
13
+ theme,
14
+ open,
15
+ onOpenChange,
16
+ }: {
17
+ value: ItemKind[];
18
+ theme: PluginTheme;
19
+ open: boolean;
20
+ onOpenChange: (open: boolean) => void;
21
+ }) {
22
+ const c = theme.colors;
23
+ return (
24
+ <View>
25
+ <Pressable
26
+ accessibilityRole="button"
27
+ accessibilityLabel={`Filter: ${OPTIONS.filter((option) => value.includes(option.id)).map((option) => option.label).join(", ") || "none"}`}
28
+ accessibilityState={{ expanded: open }}
29
+ hitSlop={8}
30
+ onPress={() => onOpenChange(!open)}
31
+ style={({ pressed }) => ({
32
+ flexDirection: "row",
33
+ alignItems: "center",
34
+ justifyContent: "center",
35
+ gap: 2,
36
+ width: 24,
37
+ height: 24,
38
+ borderRadius: 6,
39
+ backgroundColor: pressed || open ? c.surface2 : "transparent",
40
+ })}
41
+ >
42
+ <Icon name="ListFilter" size={16} color={c.foregroundMuted} />
43
+ </Pressable>
44
+ </View>
45
+ );
46
+ }
47
+ export function KindFilterMenuPanel({
48
+ value,
49
+ onChange,
50
+ projects,
51
+ projectKeys,
52
+ onProjectChange,
53
+ workspaces,
54
+ workspaceIds,
55
+ onWorkspaceChange,
56
+ theme,
57
+ }: {
58
+ value: ItemKind[];
59
+ onChange: (kind: ItemKind) => void;
60
+ projects?: ProjectSummary[];
61
+ projectKeys?: string[];
62
+ onProjectChange?: (key: string) => void;
63
+ workspaces?: WorkspaceSummary[];
64
+ workspaceIds?: string[];
65
+ onWorkspaceChange?: (id: string) => void;
66
+ theme: PluginTheme;
67
+ }) {
68
+ const c = theme.colors;
69
+ const optionRow = (icon: string, label: string, selected: boolean, onPress: () => void, struck = false) => (
70
+ <Pressable
71
+ accessibilityRole="button"
72
+ accessibilityLabel={`Filter ${label}`}
73
+ accessibilityState={{ selected }}
74
+ onPress={onPress}
75
+ style={({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) => ({
76
+ flexDirection: "row",
77
+ alignItems: "center",
78
+ gap: 8,
79
+ minHeight: 32,
80
+ marginHorizontal: 4,
81
+ paddingHorizontal: 8,
82
+ borderRadius: 6,
83
+ backgroundColor: pressed || hovered ? c.surface2 : "transparent",
84
+ })}
85
+ >
86
+ <Icon name={icon} size={14} color={c.foregroundMuted} />
87
+ <Text style={{ flex: 1, minWidth: 0, color: c.foreground, fontSize: 13, textDecorationLine: struck ? "line-through" : "none" }} numberOfLines={1}>
88
+ {label}
89
+ </Text>
90
+ {selected ? <Icon name="Check" size={14} color={c.foreground} /> : null}
91
+ </Pressable>
92
+ );
93
+ return (
94
+ <View accessibilityLabel="Projects and workspaces filter">
95
+ <View
96
+ style={{
97
+ width: 240,
98
+ maxHeight: 420,
99
+ paddingVertical: 4,
100
+ borderRadius: 8,
101
+ borderWidth: 1,
102
+ borderColor: c.border,
103
+ backgroundColor: c.surface1,
104
+ shadowColor: c.foreground,
105
+ shadowOffset: { width: 0, height: 4 },
106
+ shadowOpacity: 0.08,
107
+ shadowRadius: 12,
108
+ elevation: 4,
109
+ zIndex: 31,
110
+ overflow: "hidden",
111
+ isolation: "isolate",
112
+ }}
113
+ >
114
+ <ScrollView style={{ flexShrink: 1 }}>
115
+ {OPTIONS.map((option) => (
116
+ <View key={option.id}>
117
+ {optionRow(option.icon, option.label, value.includes(option.id), () => onChange(option.id))}
118
+ </View>
119
+ ))}
120
+ {projects?.length && projectKeys && onProjectChange ? (
121
+ <View accessibilityLabel="Projects">
122
+ <View style={{ height: 1, marginVertical: 4, backgroundColor: c.border }} />
123
+ {projects.map((project) => (
124
+ <View key={project.key}>
125
+ {optionRow("Folder", `${project.label} · ${project.count}`, projectKeys.includes(project.key), () => onProjectChange(project.key), project.archived)}
126
+ </View>
127
+ ))}
128
+ </View>
129
+ ) : null}
130
+ {workspaces?.length && workspaceIds && onWorkspaceChange ? (
131
+ <View accessibilityLabel="Workspaces">
132
+ <View style={{ height: 1, marginVertical: 4, backgroundColor: c.border }} />
133
+ {workspaces.map((workspace) => (
134
+ <View key={workspace.id}>
135
+ {optionRow("PanelsTopLeft", `${workspace.label} · ${workspace.count}`, workspaceIds.includes(workspace.id), () => onWorkspaceChange(workspace.id), workspace.archived)}
136
+ </View>
137
+ ))}
138
+ </View>
139
+ ) : null}
140
+ </ScrollView>
141
+ </View>
142
+ </View>
143
+ );
144
+ }
145
+
@@ -0,0 +1,9 @@
1
+ import type { ItemKind } from "../shared/contracts.ts";
2
+
3
+ export function toggleInboxKind(kinds: ItemKind[], next: ItemKind): ItemKind[] {
4
+ return kinds.includes(next) ? kinds.filter((kind) => kind !== next) : [...kinds, next];
5
+ }
6
+
7
+ export function toggleInboxSelection(selected: string[], next: string): string[] {
8
+ return selected.includes(next) ? selected.filter((value) => value !== next) : [...selected, next];
9
+ }
@@ -0,0 +1,12 @@
1
+ export interface NoteComposer {
2
+ insertText(text: string): void;
3
+ focus(): Promise<void>;
4
+ }
5
+
6
+ export async function insertNoteIntoComposer(
7
+ composer: NoteComposer,
8
+ body: string,
9
+ ): Promise<void> {
10
+ composer.insertText(body);
11
+ await composer.focus();
12
+ }
@@ -0,0 +1,13 @@
1
+ export function noteFieldFocusBorder({
2
+ borderless,
3
+ focused,
4
+ }: {
5
+ borderless: boolean;
6
+ focused: boolean;
7
+ }): boolean {
8
+ return focused && !borderless;
9
+ }
10
+
11
+ export function noteActionOpacity(disabled: boolean): number {
12
+ return disabled ? 0.5 : 1;
13
+ }
@@ -0,0 +1,11 @@
1
+ export function showsNoteRowActions({
2
+ web,
3
+ hovered,
4
+ busy,
5
+ }: {
6
+ web: boolean;
7
+ hovered: boolean;
8
+ busy: boolean;
9
+ }): boolean {
10
+ return !web || hovered || busy;
11
+ }
@@ -0,0 +1,2 @@
1
+ /** Plugin-local screen and sidebar item id (Paseo 0.11+ screens). */
2
+ export const INBOX_SCREEN_ID = "inbox";
@@ -6,7 +6,7 @@ export interface DraftTags {
6
6
  projectOfWorkspace?: string;
7
7
  }
8
8
 
9
- /** What the Inbox surface should open next; set by commands before `openSurface`. */
9
+ /** What the Inbox screen should open next; set by commands before `openScreen`. */
10
10
  export type SelectionRequest = { itemId: string } | { draft: DraftTags };
11
11
 
12
12
  let pending: SelectionRequest | null = null;
@@ -0,0 +1,14 @@
1
+ import type { PluginSidebarItemProps } from "@getpaseo/plugin/client";
2
+ import { SidebarRow } from "@getpaseo/plugin/client/ui";
3
+ import { INBOX_SCREEN_ID } from "./screen-id.ts";
4
+
5
+ /** Sidebar header row that opens the Inbox screen. */
6
+ export function InboxSidebarItem({ currentScreen, openScreen }: PluginSidebarItemProps) {
7
+ return (
8
+ <SidebarRow
9
+ icon="Inbox"
10
+ active={currentScreen?.screenId === INBOX_SCREEN_ID}
11
+ onPress={() => openScreen({ screenId: INBOX_SCREEN_ID })}
12
+ />
13
+ );
14
+ }
@@ -1,5 +1,5 @@
1
1
  import { useSettings } from "@getpaseo/plugin/client";
2
- import { useToast } from "@getpaseo/plugin/client/react-native";
2
+ import { useToast } from "@getpaseo/plugin/client/ui";
3
3
  import { useEffect, useMemo, useRef, useState } from "react";
4
4
  import {
5
5
  INBOX_FILTER_DEFAULTS,
@@ -1,18 +1,36 @@
1
- import { type PluginWorkspacePanelProps, useWorkspace } from "@getpaseo/plugin/client";
1
+ import { type PluginWorkspacePanelProps, type WorkspaceRef, useWorkspace, useWorkspaces } from "@getpaseo/plugin/client";
2
2
  import { Text, View } from "react-native";
3
3
  import { InboxView } from "./inbox-surface.tsx";
4
4
  import { usePanelPresenceReport } from "./panel-visibility.ts";
5
5
 
6
6
  /** Explorer panel: the Inbox of one workspace. */
7
- export function WorkspaceInboxPanel({ theme, layout, navigation, workspaceId }: PluginWorkspacePanelProps) {
8
- usePanelPresenceReport(workspaceId);
9
- const workspace = useWorkspace(workspaceId, ({ id, directory }) => ({ id, directory }));
7
+ function WorkspaceInboxContent({
8
+ theme, layout, navigation, workspaceRef,
9
+ }: PluginWorkspacePanelProps & { workspaceRef: WorkspaceRef }) {
10
+ const workspace = useWorkspace(workspaceRef, ({ id, directory }) => ({ id, directory }));
10
11
  if (!workspace) {
11
12
  return (
12
- <View style={{ flex: 1, padding: 16, backgroundColor: theme.colors.surface0 }}>
13
+ <View style={{ flex: 1, padding: 16, backgroundColor: "transparent" }}>
13
14
  <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>Workspace unavailable.</Text>
14
15
  </View>
15
16
  );
16
17
  }
17
18
  return <InboxView theme={theme} layout={layout} navigation={navigation} workspace={workspace} />;
18
19
  }
20
+
21
+ export function WorkspaceInboxPanel(props: PluginWorkspacePanelProps) {
22
+ usePanelPresenceReport(props.workspaceId);
23
+ const workspaces = useWorkspaces({
24
+ hosts: [props.host.id],
25
+ where: (workspace) => workspace.id === props.workspaceId,
26
+ });
27
+ const workspaceRef = workspaces[0];
28
+ if (!workspaceRef) {
29
+ return (
30
+ <View style={{ flex: 1, padding: 16, backgroundColor: "transparent" }}>
31
+ <Text style={{ color: props.theme.colors.foregroundMuted, fontSize: 12 }}>Workspace unavailable.</Text>
32
+ </View>
33
+ );
34
+ }
35
+ return <WorkspaceInboxContent {...props} workspaceRef={workspaceRef} />;
36
+ }
package/index.client.tsx CHANGED
@@ -1,22 +1,27 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { watchInboxChanges } from "./client/changes.ts";
2
3
  import { contributeHeaderButtons } from "./client/header-button.ts";
3
4
  import { InboxSurface } from "./client/inbox-surface.tsx";
5
+ import { INBOX_SCREEN_ID } from "./client/screen-id.ts";
6
+ import { InboxSidebarItem } from "./client/sidebar-item.tsx";
4
7
  import { notifyItemsChanged, requestDraft, requestSelection } from "./client/selection.ts";
5
8
  import { WorkspaceInboxPanel } from "./client/workspace-panel.tsx";
6
9
  import { saveNote, starAgent } from "./shared/contracts.ts";
7
10
  import { parseInboxCommand } from "./shared/slash-command.ts";
8
-
9
- const SURFACE = "inbox";
11
+ import { itemsChanged } from "./shared/changes.ts";
10
12
 
11
13
  export default function contribute(client: PluginClientContext) {
12
14
  const removers = [
13
- client.addSurface(SURFACE, InboxSurface),
14
- client.addSidebarItem({ id: SURFACE, title: "Inbox", icon: "Inbox", surface: SURFACE }),
15
+ client.addScreen({ id: INBOX_SCREEN_ID, title: "Inbox", Component: InboxSurface }),
16
+ client.addSidebarHeaderItem({
17
+ id: INBOX_SCREEN_ID,
18
+ title: "Inbox",
19
+ Component: InboxSidebarItem,
20
+ }),
15
21
  client.addWorkspacePanel({
16
22
  id: "workspace-inbox",
17
23
  title: "Inbox",
18
24
  icon: "Inbox",
19
- context: "workspace",
20
25
  locations: ["explorer"],
21
26
  Component: WorkspaceInboxPanel,
22
27
  }),
@@ -26,7 +31,7 @@ export default function contribute(client: PluginClientContext) {
26
31
  icon: "Inbox",
27
32
  keywords: ["open"],
28
33
  context: "global",
29
- onSelect: ({ openSurface }) => openSurface(SURFACE),
34
+ onSelect: ({ openScreen }) => openScreen({ screenId: INBOX_SCREEN_ID }),
30
35
  }),
31
36
  client.addCommandCenterItem({
32
37
  id: "star-agent",
@@ -34,26 +39,26 @@ export default function contribute(client: PluginClientContext) {
34
39
  icon: "Star",
35
40
  keywords: ["star", "favorite", "bookmark", "inbox"],
36
41
  context: "agent",
37
- async onSelect({ agent, rpc, openSurface }) {
42
+ async onSelect({ agent, rpc, openScreen }) {
38
43
  const { item } = await rpc(starAgent, { agentId: agent.id });
39
44
  requestSelection(item.id);
40
- openSurface(SURFACE);
45
+ openScreen({ screenId: INBOX_SCREEN_ID });
41
46
  },
42
47
  }),
43
48
  client.addCommandCenterItem({
44
49
  id: "quick-note",
45
50
  title: "New Inbox note",
46
- icon: "NotebookPen",
51
+ icon: "FilePlus2",
47
52
  keywords: ["note", "inbox", "capture"],
48
53
  context: "workspace",
49
- onSelect({ workspace, openSurface }) {
54
+ onSelect({ workspace, openScreen }) {
50
55
  requestDraft({ projectOfWorkspace: workspace.id });
51
- openSurface(SURFACE);
56
+ openScreen({ screenId: INBOX_SCREEN_ID });
52
57
  },
53
58
  }),
54
59
  client.addSlashCommand({
55
60
  name: "inbox",
56
- description: "Add this agent to the Inbox, or save text as a scratch note tagged with this project.",
61
+ description: "Add this agent to the Inbox, or save text as a note tagged with this project.",
57
62
  argumentHint: "[text]",
58
63
  context: "agent",
59
64
  async onSubmit({ args, agent, workspace, rpc }) {
@@ -61,12 +66,18 @@ export default function contribute(client: PluginClientContext) {
61
66
  if (!command.text) {
62
67
  await rpc(starAgent, { agentId: agent.id });
63
68
  } else {
64
- await rpc(saveNote, { kind: "scratch", body: command.text, projectOfWorkspace: workspace.id });
69
+ await rpc(saveNote, { body: command.text, projectOfWorkspace: workspace.id });
65
70
  }
66
71
  notifyItemsChanged();
67
72
  },
68
73
  }),
69
74
  contributeHeaderButtons(client),
75
+ watchInboxChanges(
76
+ (onEvent, onClosed) => client.subscribe(itemsChanged, {}, onEvent, {
77
+ onClosed: ({ error }) => onClosed(error),
78
+ }),
79
+ notifyItemsChanged,
80
+ ),
70
81
  ];
71
82
  return () => {
72
83
  for (const remove of removers) remove();
package/index.server.ts CHANGED
@@ -1,17 +1,32 @@
1
1
  import type { PluginServerContext } from "@getpaseo/plugin/server";
2
+ import { InboxChanges } from "./server/changes.ts";
2
3
  import { createDaemonConnection } from "./server/daemon.ts";
3
4
  import { registerHandlers } from "./server/handlers.ts";
4
5
  import { createProjectResolver } from "./server/project-key.ts";
5
6
  import { InboxStore } from "./server/store.ts";
6
7
  import { inboxFilterSettings } from "./shared/filter-settings.ts";
8
+ import { itemsChanged } from "./shared/changes.ts";
7
9
 
8
10
  export default function contribute(server: PluginServerContext) {
9
11
  server.registerSettings(inboxFilterSettings);
10
- const store = new InboxStore();
12
+ const changes = new InboxChanges();
13
+ const store = new InboxStore({ onChange: () => changes.invalidate() });
11
14
  const daemon = createDaemonConnection();
12
- registerHandlers(server, { store, resolveProject: createProjectResolver(), daemon });
15
+ server.handle(itemsChanged, (_input, context) => changes.subscribe(context));
16
+ const hooks = [
17
+ server.addHook("workspace.archive.after", async () => changes.invalidate()),
18
+ server.addHook("workspace.create.after", async () => changes.invalidate()),
19
+ server.addHook("agent.archive.after", async () => changes.invalidate()),
20
+ server.addHook("agent.create.after", async () => changes.invalidate()),
21
+ ];
22
+ registerHandlers(server, { store, resolveProject: createProjectResolver(), daemon, changes });
13
23
  return async () => {
14
- await daemon.close();
15
- store.close();
24
+ for (const remove of hooks) remove();
25
+ changes.close();
26
+ try {
27
+ await daemon.close();
28
+ } finally {
29
+ store.close();
30
+ }
16
31
  };
17
32
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koinzhang/paseo-plugin-inbox",
3
- "version": "0.1.0",
4
- "description": "Personal inbox for Paseo: star agents, keep notes per project, and capture scratch text.",
3
+ "version": "0.3.0",
4
+ "description": "Personal inbox for Paseo: star agents and keep notes per project.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -26,11 +26,12 @@
26
26
  "test": "node --experimental-strip-types --test shared/*.test.ts server/*.test.ts client/*.test.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@getpaseo/client": "0.9.2",
29
+ "@getpaseo/client": "0.17.4",
30
30
  "ws": "^8.18.3"
31
31
  },
32
32
  "devDependencies": {
33
- "@getpaseo/plugin": "0.9.2",
33
+ "@getpaseo/plugin": "0.17.4",
34
+ "@getpaseo/protocol": "0.17.4",
34
35
  "@tanstack/react-query": "^5.90.11",
35
36
  "@types/node": "^24.13.5",
36
37
  "@types/react": "~19.2.0",
package/paseo-plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "inbox",
3
- "description": "Personal inbox: starred agents, notes, project records, and quick scratch captures",
3
+ "description": "Personal inbox: starred agents, notes, and project records",
4
4
  "requirements": {
5
- "paseo": ">=0.9.0"
5
+ "paseo": ">=0.17.4"
6
6
  }
7
7
  }
package/server/agents.ts CHANGED
@@ -9,6 +9,7 @@ export interface AgentLookup {
9
9
  snapshot: AgentSnapshot;
10
10
  archived: boolean;
11
11
  live: AgentLive;
12
+ updatedAt: string;
12
13
  }
13
14
 
14
15
  function liveAttention(agent: {
@@ -42,6 +43,7 @@ export async function lookupAgent(paseo: PaseoApi, agentId: string): Promise<Age
42
43
  createdAt: agent.createdAt,
43
44
  },
44
45
  archived: Boolean(agent.archivedAt),
46
+ updatedAt: agent.updatedAt,
45
47
  live: {
46
48
  status: agent.status,
47
49
  attention: liveAttention(agent),
@@ -53,10 +55,10 @@ export async function lookupAgent(paseo: PaseoApi, agentId: string): Promise<Age
53
55
  export async function agentState(
54
56
  paseo: PaseoApi,
55
57
  agentId: string,
56
- ): Promise<{ state: AgentState; live: AgentLive | null; title: string | null }> {
58
+ ): Promise<{ state: AgentState; live: AgentLive | null; title: string | null; updatedAt: string | null }> {
57
59
  const found = await lookupAgent(paseo, agentId);
58
- if (!found) return { state: "missing", live: null, title: null };
59
- return { state: found.archived ? "archived" : "active", live: found.live, title: found.snapshot.title };
60
+ if (!found) return { state: "missing", live: null, title: null, updatedAt: null };
61
+ return { state: found.archived ? "archived" : "active", live: found.live, title: found.snapshot.title, updatedAt: found.updatedAt };
60
62
  }
61
63
 
62
64
  /** Unarchived agents of one workspace. */
@@ -0,0 +1,67 @@
1
+ import type { InboxChange } from "../shared/changes.ts";
2
+
3
+ interface Subscriber {
4
+ invalidate(): void;
5
+ stop(): void;
6
+ }
7
+
8
+ export class InboxChanges {
9
+ private readonly subscribers = new Set<Subscriber>();
10
+ private closed = false;
11
+
12
+ invalidate(): void {
13
+ for (const subscriber of this.subscribers) subscriber.invalidate();
14
+ }
15
+
16
+ subscribe({ push, signal }: { push(event: InboxChange): Promise<void>; signal: AbortSignal }): Promise<void> {
17
+ if (this.closed || signal.aborted) return Promise.resolve();
18
+ return new Promise<void>((resolve, reject) => {
19
+ let active = true;
20
+ let pending = false;
21
+ let sending = false;
22
+
23
+ const stop = (error?: unknown) => {
24
+ if (!active) return;
25
+ active = false;
26
+ pending = false;
27
+ this.subscribers.delete(subscriber);
28
+ signal.removeEventListener("abort", onAbort);
29
+ if (error !== undefined) reject(error);
30
+ else resolve();
31
+ };
32
+ const onAbort = () => stop();
33
+
34
+ const send = async () => {
35
+ if (!active || sending) return;
36
+ sending = true;
37
+ try {
38
+ while (active && pending) {
39
+ pending = false;
40
+ await push({ type: "invalidate" });
41
+ }
42
+ } catch (error) {
43
+ stop(error);
44
+ } finally {
45
+ sending = false;
46
+ }
47
+ };
48
+
49
+ const subscriber: Subscriber = {
50
+ invalidate: () => {
51
+ if (!active) return;
52
+ pending = true;
53
+ void send();
54
+ },
55
+ stop: () => stop(),
56
+ };
57
+ this.subscribers.add(subscriber);
58
+ signal.addEventListener("abort", onAbort, { once: true });
59
+ subscriber.invalidate();
60
+ });
61
+ }
62
+
63
+ close(): void {
64
+ this.closed = true;
65
+ for (const subscriber of this.subscribers) subscriber.stop();
66
+ }
67
+ }
@@ -13,6 +13,7 @@ import {
13
13
  updateItem,
14
14
  } from "../shared/contracts.ts";
15
15
  import { agentState, lookupAgent, unarchiveAgent as runUnarchive, workspaceAgents } from "./agents.ts";
16
+ import type { InboxChanges } from "./changes.ts";
16
17
  import type { createDaemonConnection } from "./daemon.ts";
17
18
  import { type Directory, loadDirectory } from "./directory.ts";
18
19
  import type { createProjectResolver } from "./project-key.ts";
@@ -23,9 +24,10 @@ interface Deps {
23
24
  store: InboxStore;
24
25
  resolveProject: ReturnType<typeof createProjectResolver>;
25
26
  daemon: ReturnType<typeof createDaemonConnection>;
27
+ changes: InboxChanges;
26
28
  }
27
29
 
28
- export function registerHandlers(server: PluginServerContext, { store, resolveProject, daemon }: Deps): void {
30
+ export function registerHandlers(server: PluginServerContext, { store, resolveProject, daemon, changes }: Deps): void {
29
31
  const directory = (paseo: PaseoApi) => loadDirectory(paseo, resolveProject);
30
32
  /** Null when the host directory is unreadable; then nothing is treated as archived. */
31
33
  const tryDirectory = (paseo: PaseoApi): Promise<Directory | null> =>
@@ -57,21 +59,20 @@ export function registerHandlers(server: PluginServerContext, { store, resolvePr
57
59
  }
58
60
  return {
59
61
  items,
60
- projects: store.projects(filter.kind).map((entry) => ({ ...entry, archived: projectArchived(entry.key) })),
61
- workspaces: store.workspaces(filter.kind).map((entry) => ({ ...entry, archived: workspaceArchived(entry.id) })),
62
+ projects: store.projects(filter.kinds).map((entry) => ({ ...entry, archived: projectArchived(entry.key) })),
63
+ workspaces: store.workspaces(filter.kinds).map((entry) => ({ ...entry, archived: workspaceArchived(entry.id) })),
62
64
  archived: { projects: [...archived.projects], workspaces: [...archived.workspaces] },
63
65
  };
64
66
  });
65
67
 
66
- server.handle(saveNote, async ({ id, kind, title, body, workspaceId, projectOfWorkspace }, { paseo }) => {
67
- if (id) return { item: store.updateNote(id, { kind, title, body }) };
68
+ server.handle(saveNote, async ({ id, title, body, workspaceId, projectOfWorkspace }, { paseo }) => {
69
+ if (id) return { item: store.updateNote(id, { title, body }) };
68
70
  const target = workspaceId ?? projectOfWorkspace;
69
- if (!target) return { item: store.createNote({ kind, title, body }) };
71
+ if (!target) return { item: store.createNote({ title, body }) };
70
72
  const found = (await tryDirectory(paseo))?.workspaces.get(target);
71
73
  if (!found && workspaceId) throw new Error("This workspace is archived or no longer on this host");
72
74
  return {
73
75
  item: store.createNote({
74
- kind,
75
76
  title,
76
77
  body,
77
78
  project: found?.project ?? null,
@@ -136,9 +137,16 @@ export function registerHandlers(server: PluginServerContext, { store, resolvePr
136
137
  return {
137
138
  states: Object.fromEntries(entries.map(([id, { state }]) => [id, state])),
138
139
  live: Object.fromEntries(entries.flatMap(([id, { live }]) => (live ? [[id, live]] : []))),
140
+ lastActivityAt: Object.fromEntries(entries.flatMap(([id, { updatedAt }]) => (updatedAt ? [[id, updatedAt]] : []))),
139
141
  ...(titlesChanged ? { titlesChanged } : {}),
140
142
  };
141
143
  });
142
144
 
143
- server.handle(unarchiveAgent, async ({ agentId }) => runUnarchive(await daemon.get(), agentId));
145
+ server.handle(unarchiveAgent, async ({ agentId }) => {
146
+ try {
147
+ return await runUnarchive(await daemon.get(), agentId);
148
+ } finally {
149
+ changes.invalidate();
150
+ }
151
+ });
144
152
  }