@koinzhang/paseo-plugin-inbox 0.1.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.
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/client/agent-status.tsx +129 -0
- package/client/header-button.ts +127 -0
- package/client/inbox-surface.tsx +1369 -0
- package/client/last-exchange.ts +49 -0
- package/client/panel-visibility.ts +45 -0
- package/client/selection.ts +50 -0
- package/client/use-inbox-filters.ts +83 -0
- package/client/web.ts +84 -0
- package/client/workspace-panel.tsx +18 -0
- package/index.client.tsx +74 -0
- package/index.server.ts +17 -0
- package/package.json +43 -0
- package/paseo-plugin.json +7 -0
- package/server/agents.ts +106 -0
- package/server/daemon.ts +85 -0
- package/server/directory.ts +63 -0
- package/server/handlers.ts +144 -0
- package/server/project-key.ts +42 -0
- package/server/store.ts +394 -0
- package/server/tags.ts +41 -0
- package/shared/agent-status.ts +39 -0
- package/shared/contracts.ts +192 -0
- package/shared/filter-settings.ts +74 -0
- package/shared/item-title.ts +8 -0
- package/shared/last-exchange.ts +124 -0
- package/shared/note.ts +4 -0
- package/shared/plugin-id.ts +4 -0
- package/shared/project-key.ts +55 -0
- package/shared/slash-command.ts +9 -0
|
@@ -0,0 +1,1369 @@
|
|
|
1
|
+
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
|
+
import { type PluginSurfaceProps, usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
3
|
+
import { Icon, ScrollView, TextInput, useToast } from "@getpaseo/plugin/client/react-native";
|
|
4
|
+
import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import {
|
|
6
|
+
type ComponentProps,
|
|
7
|
+
type ComponentRef,
|
|
8
|
+
Fragment,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
useEffect,
|
|
11
|
+
useMemo,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react";
|
|
15
|
+
import { PanResponder, Platform, Pressable, Text, View } from "react-native";
|
|
16
|
+
import {
|
|
17
|
+
agentCandidates,
|
|
18
|
+
agentStates,
|
|
19
|
+
deleteItem,
|
|
20
|
+
type Item,
|
|
21
|
+
type ItemKind,
|
|
22
|
+
type ItemSort,
|
|
23
|
+
type AgentLive,
|
|
24
|
+
type AgentState,
|
|
25
|
+
listItems,
|
|
26
|
+
saveNote,
|
|
27
|
+
starAgent,
|
|
28
|
+
tagItem,
|
|
29
|
+
tagOptions,
|
|
30
|
+
unarchiveAgent,
|
|
31
|
+
updateItem,
|
|
32
|
+
} from "../shared/contracts.ts";
|
|
33
|
+
import { describeAgentStatus } from "../shared/agent-status.ts";
|
|
34
|
+
import { excerpt, type LastExchange } from "../shared/last-exchange.ts";
|
|
35
|
+
import { fetchLastExchange } from "./last-exchange.ts";
|
|
36
|
+
import { AgentIcon, PermissionBadge } from "./agent-status.tsx";
|
|
37
|
+
import { inboxListSort, visibleInboxFilters } from "../shared/filter-settings.ts";
|
|
38
|
+
import { itemTitle } from "../shared/item-title.ts";
|
|
39
|
+
import { isEmptyNote } from "../shared/note.ts";
|
|
40
|
+
import {
|
|
41
|
+
type DraftTags,
|
|
42
|
+
notifyItemsChanged,
|
|
43
|
+
onItemsChanged,
|
|
44
|
+
onSelectionRequest,
|
|
45
|
+
type SelectionRequest,
|
|
46
|
+
takeSelection,
|
|
47
|
+
} from "./selection.ts";
|
|
48
|
+
import { useInboxFilters } from "./use-inbox-filters.ts";
|
|
49
|
+
import { type HorizontalScrollNode, trackHorizontalDrag, wheelScrollsHorizontally } from "./web.ts";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `id` is the open item; `draft` is non-null for an unsaved note.
|
|
53
|
+
* `session` keys the editor so it survives a draft turning into a saved note.
|
|
54
|
+
*/
|
|
55
|
+
interface Selection {
|
|
56
|
+
id: string | null;
|
|
57
|
+
draft: DraftTags | null;
|
|
58
|
+
session: number;
|
|
59
|
+
fromDraft?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let sessionCounter = 0;
|
|
63
|
+
const nextSession = () => ++sessionCounter;
|
|
64
|
+
|
|
65
|
+
function toSelection(request: SelectionRequest | null): Selection | null {
|
|
66
|
+
if (!request) return null;
|
|
67
|
+
if ("itemId" in request) return { id: request.itemId, draft: null, session: nextSession() };
|
|
68
|
+
return { id: null, draft: request.draft, session: nextSession() };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Project keys and workspace ids no longer active on the host. */
|
|
72
|
+
interface Archived {
|
|
73
|
+
projects: ReadonlySet<string>;
|
|
74
|
+
workspaces: ReadonlySet<string>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const LIST_KEY = ["inbox", "items"] as const;
|
|
78
|
+
const STATES_KEY = ["inbox", "agent-states"] as const;
|
|
79
|
+
const CANDIDATES_KEY = ["inbox", "agent-candidates"] as const;
|
|
80
|
+
const TAG_OPTIONS_KEY = ["inbox", "tag-options"] as const;
|
|
81
|
+
const SAVE_DELAY_MS = 600;
|
|
82
|
+
|
|
83
|
+
const FILTERS: Array<{ id: ItemKind | "all"; label: string }> = [
|
|
84
|
+
{ id: "all", label: "All" },
|
|
85
|
+
{ id: "agent", label: "Agents" },
|
|
86
|
+
{ id: "note", label: "Notes" },
|
|
87
|
+
{ id: "scratch", label: "Scratch" },
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/** Tapping the sort button steps through these in order. */
|
|
91
|
+
const SORTS: Array<{ id: ItemSort; label: string; icon: string }> = [
|
|
92
|
+
{ id: "updated", label: "Updated", icon: "ClockArrowDown" },
|
|
93
|
+
{ id: "starred", label: "Starred", icon: "Star" },
|
|
94
|
+
{ id: "created", label: "Created", icon: "CalendarPlus" },
|
|
95
|
+
{ id: "name", label: "Name", icon: "ArrowDownAZ" },
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const LIST_WIDTH = { initial: 360, min: 280, max: 640 };
|
|
99
|
+
const clampListWidth = (width: number) => Math.min(LIST_WIDTH.max, Math.max(LIST_WIDTH.min, width));
|
|
100
|
+
/** Keeps the dragged width while the app runs, across surface remounts. */
|
|
101
|
+
let rememberedListWidth = LIST_WIDTH.initial;
|
|
102
|
+
|
|
103
|
+
/** The workspace an Explorer panel is scoped to. */
|
|
104
|
+
export interface InboxWorkspace {
|
|
105
|
+
id: string;
|
|
106
|
+
directory: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type Styles = ReturnType<typeof createStyles>;
|
|
110
|
+
|
|
111
|
+
const noOutline = Platform.OS === "web" ? ({ outlineStyle: "none" } as object) : {};
|
|
112
|
+
const resizeCursor = Platform.OS === "web" ? ({ cursor: "col-resize" } as object) : {};
|
|
113
|
+
|
|
114
|
+
/** Swaps the accent focus ring for a muted border, like Customize's search box. */
|
|
115
|
+
function Field({ styles, style, ...props }: ComponentProps<typeof TextInput> & { styles: Styles }) {
|
|
116
|
+
const [focused, setFocused] = useState(false);
|
|
117
|
+
return (
|
|
118
|
+
<TextInput
|
|
119
|
+
placeholderTextColor={styles.placeholderColor}
|
|
120
|
+
{...props}
|
|
121
|
+
style={[style, focused ? styles.inputFocused : null]}
|
|
122
|
+
onFocus={(e) => {
|
|
123
|
+
setFocused(true);
|
|
124
|
+
props.onFocus?.(e);
|
|
125
|
+
}}
|
|
126
|
+
onBlur={(e) => {
|
|
127
|
+
setFocused(false);
|
|
128
|
+
props.onBlur?.(e);
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function createStyles(theme: PluginTheme, compact: boolean) {
|
|
135
|
+
const c = theme.colors;
|
|
136
|
+
return {
|
|
137
|
+
screen: { flex: 1, backgroundColor: c.surface0, flexDirection: "row" as const },
|
|
138
|
+
listPane: { overflow: "hidden" as const },
|
|
139
|
+
divider: {
|
|
140
|
+
width: 9,
|
|
141
|
+
marginHorizontal: -4,
|
|
142
|
+
zIndex: 1,
|
|
143
|
+
alignItems: "center" as const,
|
|
144
|
+
...resizeCursor,
|
|
145
|
+
},
|
|
146
|
+
dividerLine: { width: 1, flex: 1, backgroundColor: c.border },
|
|
147
|
+
detailPane: { flex: 1, padding: compact ? 16 : 24, gap: 12 },
|
|
148
|
+
toolbar: { padding: compact ? 12 : 16, gap: 10, borderBottomWidth: 1, borderColor: c.border },
|
|
149
|
+
row: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
|
|
150
|
+
wrap: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 6 },
|
|
151
|
+
input: {
|
|
152
|
+
color: c.foreground,
|
|
153
|
+
backgroundColor: c.surface1,
|
|
154
|
+
borderColor: c.border,
|
|
155
|
+
borderWidth: 1,
|
|
156
|
+
borderRadius: 8,
|
|
157
|
+
paddingHorizontal: 10,
|
|
158
|
+
paddingVertical: 8,
|
|
159
|
+
fontSize: 14,
|
|
160
|
+
...noOutline,
|
|
161
|
+
},
|
|
162
|
+
inputFocused: { borderColor: c.foregroundMuted },
|
|
163
|
+
placeholderColor: c.foregroundMuted,
|
|
164
|
+
chip: (active: boolean) => ({
|
|
165
|
+
flexDirection: "row" as const,
|
|
166
|
+
alignItems: "center" as const,
|
|
167
|
+
gap: 4,
|
|
168
|
+
paddingHorizontal: 10,
|
|
169
|
+
paddingVertical: 5,
|
|
170
|
+
borderRadius: 999,
|
|
171
|
+
borderWidth: 1,
|
|
172
|
+
borderColor: active ? c.accent : c.border,
|
|
173
|
+
backgroundColor: active ? c.accent : "transparent",
|
|
174
|
+
}),
|
|
175
|
+
chipText: (active: boolean) => ({
|
|
176
|
+
color: active ? c.accentForeground : c.foregroundMuted,
|
|
177
|
+
fontSize: 12,
|
|
178
|
+
}),
|
|
179
|
+
item: (selected: boolean) => ({
|
|
180
|
+
paddingHorizontal: compact ? 12 : 16,
|
|
181
|
+
paddingVertical: 10,
|
|
182
|
+
gap: 4,
|
|
183
|
+
borderBottomWidth: 1,
|
|
184
|
+
borderColor: c.border,
|
|
185
|
+
backgroundColor: selected ? c.surface2 : "transparent",
|
|
186
|
+
}),
|
|
187
|
+
itemTitle: { color: c.foreground, fontSize: 14, flex: 1 },
|
|
188
|
+
muted: { color: c.foregroundMuted, fontSize: 12 },
|
|
189
|
+
struck: { textDecorationLine: "line-through" as const },
|
|
190
|
+
badge: (tone: "warning" | "danger" | "success") => ({
|
|
191
|
+
color:
|
|
192
|
+
tone === "warning" ? c.statusWarning : tone === "danger" ? c.statusDanger : c.statusSuccess,
|
|
193
|
+
fontSize: 11,
|
|
194
|
+
}),
|
|
195
|
+
heading: { color: c.foreground, fontSize: compact ? 18 : 20, fontWeight: "600" as const },
|
|
196
|
+
body: { color: c.foreground, fontSize: 14 },
|
|
197
|
+
message: {
|
|
198
|
+
color: c.foreground,
|
|
199
|
+
fontSize: 13,
|
|
200
|
+
lineHeight: 18,
|
|
201
|
+
backgroundColor: c.surface1,
|
|
202
|
+
borderColor: c.border,
|
|
203
|
+
borderWidth: 1,
|
|
204
|
+
borderRadius: 8,
|
|
205
|
+
padding: 10,
|
|
206
|
+
},
|
|
207
|
+
editor: {
|
|
208
|
+
flex: 1,
|
|
209
|
+
minHeight: 200,
|
|
210
|
+
color: c.foreground,
|
|
211
|
+
backgroundColor: c.surface1,
|
|
212
|
+
borderColor: c.border,
|
|
213
|
+
borderWidth: 1,
|
|
214
|
+
borderRadius: 8,
|
|
215
|
+
padding: 12,
|
|
216
|
+
fontSize: 14,
|
|
217
|
+
textAlignVertical: "top" as const,
|
|
218
|
+
...noOutline,
|
|
219
|
+
},
|
|
220
|
+
button: (kind: "primary" | "plain" | "danger") => ({
|
|
221
|
+
flexDirection: "row" as const,
|
|
222
|
+
alignItems: "center" as const,
|
|
223
|
+
gap: 6,
|
|
224
|
+
paddingHorizontal: 12,
|
|
225
|
+
paddingVertical: 7,
|
|
226
|
+
borderRadius: 8,
|
|
227
|
+
borderWidth: kind === "primary" ? 0 : 1,
|
|
228
|
+
borderColor: kind === "danger" ? c.statusDanger : c.border,
|
|
229
|
+
backgroundColor: kind === "primary" ? c.accent : "transparent",
|
|
230
|
+
}),
|
|
231
|
+
iconButton: { paddingHorizontal: 8, paddingVertical: 8 },
|
|
232
|
+
buttonText: (kind: "primary" | "plain" | "danger") => ({
|
|
233
|
+
color:
|
|
234
|
+
kind === "primary" ? c.accentForeground : kind === "danger" ? c.statusDanger : c.foreground,
|
|
235
|
+
fontSize: 13,
|
|
236
|
+
}),
|
|
237
|
+
empty: { padding: 24, alignItems: "center" as const, gap: 8 },
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function errorText(error: unknown): string {
|
|
242
|
+
return error instanceof Error ? error.message : String(error);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function Button({
|
|
246
|
+
styles,
|
|
247
|
+
theme,
|
|
248
|
+
kind = "plain",
|
|
249
|
+
icon,
|
|
250
|
+
label,
|
|
251
|
+
accessibilityLabel,
|
|
252
|
+
onPress,
|
|
253
|
+
disabled,
|
|
254
|
+
}: {
|
|
255
|
+
styles: Styles;
|
|
256
|
+
theme: PluginTheme;
|
|
257
|
+
kind?: "primary" | "plain" | "danger";
|
|
258
|
+
icon?: string;
|
|
259
|
+
label?: string;
|
|
260
|
+
accessibilityLabel?: string;
|
|
261
|
+
onPress: () => void;
|
|
262
|
+
disabled?: boolean;
|
|
263
|
+
}) {
|
|
264
|
+
const color =
|
|
265
|
+
kind === "primary"
|
|
266
|
+
? theme.colors.accentForeground
|
|
267
|
+
: kind === "danger"
|
|
268
|
+
? theme.colors.statusDanger
|
|
269
|
+
: theme.colors.foreground;
|
|
270
|
+
return (
|
|
271
|
+
<Pressable
|
|
272
|
+
accessibilityRole="button"
|
|
273
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
274
|
+
disabled={disabled}
|
|
275
|
+
onPress={onPress}
|
|
276
|
+
style={[styles.button(kind), label ? null : styles.iconButton, disabled ? { opacity: 0.5 } : null]}
|
|
277
|
+
>
|
|
278
|
+
{icon ? <Icon name={icon} size={14} color={color} /> : null}
|
|
279
|
+
{label ? <Text style={styles.buttonText(kind)}>{label}</Text> : null}
|
|
280
|
+
</Pressable>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const KIND_ICON: Record<ItemKind, string> = { agent: "Bot", note: "NotebookText", scratch: "StickyNote" };
|
|
285
|
+
|
|
286
|
+
/** Project and workspace tags of an item; archived ones are marked. */
|
|
287
|
+
function itemTags(item: Item, archived: Archived): Array<{ label: string; archived: boolean }> {
|
|
288
|
+
const tags: Array<{ label: string; archived: boolean }> = [];
|
|
289
|
+
if (item.projectKey) {
|
|
290
|
+
tags.push({ label: item.projectLabel ?? item.projectKey, archived: archived.projects.has(item.projectKey) });
|
|
291
|
+
}
|
|
292
|
+
if (item.workspaceId) {
|
|
293
|
+
tags.push({ label: item.workspaceLabel ?? item.workspaceId, archived: archived.workspaces.has(item.workspaceId) });
|
|
294
|
+
}
|
|
295
|
+
return tags;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function ItemRow({
|
|
299
|
+
item,
|
|
300
|
+
selected,
|
|
301
|
+
state,
|
|
302
|
+
live,
|
|
303
|
+
archived,
|
|
304
|
+
hideWorkspaceId,
|
|
305
|
+
styles,
|
|
306
|
+
theme,
|
|
307
|
+
onPress,
|
|
308
|
+
}: {
|
|
309
|
+
item: Item;
|
|
310
|
+
selected: boolean;
|
|
311
|
+
state: AgentState | undefined;
|
|
312
|
+
live: AgentLive | undefined;
|
|
313
|
+
archived: Archived;
|
|
314
|
+
/** The panel's own workspace, left out of the subtitle. */
|
|
315
|
+
hideWorkspaceId: string | null;
|
|
316
|
+
styles: Styles;
|
|
317
|
+
theme: PluginTheme;
|
|
318
|
+
onPress: () => void;
|
|
319
|
+
}) {
|
|
320
|
+
const agentState = state;
|
|
321
|
+
const status = item.kind === "agent" ? describeAgentStatus(agentState, live) : null;
|
|
322
|
+
const tags = itemTags(
|
|
323
|
+
hideWorkspaceId && item.workspaceId === hideWorkspaceId ? { ...item, workspaceId: null } : item,
|
|
324
|
+
archived,
|
|
325
|
+
);
|
|
326
|
+
const subtitle = [
|
|
327
|
+
...tags,
|
|
328
|
+
...[item.kind === "agent" ? item.agentSnapshot?.provider : null, new Date(item.updatedAt).toLocaleDateString()]
|
|
329
|
+
.filter((label): label is string => Boolean(label))
|
|
330
|
+
.map((label) => ({ label, archived: false })),
|
|
331
|
+
];
|
|
332
|
+
return (
|
|
333
|
+
<Pressable
|
|
334
|
+
accessibilityRole="button"
|
|
335
|
+
accessibilityLabel={status ? `${itemTitle(item)}, ${status.label}` : itemTitle(item)}
|
|
336
|
+
onPress={onPress}
|
|
337
|
+
style={styles.item(selected)}
|
|
338
|
+
>
|
|
339
|
+
<View style={styles.row}>
|
|
340
|
+
{item.kind === "agent" ? (
|
|
341
|
+
<AgentIcon state={agentState} live={live} size={14} theme={theme} />
|
|
342
|
+
) : (
|
|
343
|
+
<Icon name={KIND_ICON[item.kind]} size={14} color={theme.colors.foregroundMuted} />
|
|
344
|
+
)}
|
|
345
|
+
<Text style={styles.itemTitle} numberOfLines={1}>
|
|
346
|
+
{itemTitle(item)}
|
|
347
|
+
</Text>
|
|
348
|
+
{item.pinned ? <Icon name="Pin" size={12} color={theme.colors.accent} /> : null}
|
|
349
|
+
{item.kind === "agent" ? <PermissionBadge state={agentState} live={live} theme={theme} /> : null}
|
|
350
|
+
</View>
|
|
351
|
+
<Text style={styles.muted} numberOfLines={1}>
|
|
352
|
+
{subtitle.map((part, index) => (
|
|
353
|
+
<Fragment key={index}>
|
|
354
|
+
{index ? " · " : ""}
|
|
355
|
+
<Text style={part.archived ? styles.struck : null}>{part.label}</Text>
|
|
356
|
+
</Fragment>
|
|
357
|
+
))}
|
|
358
|
+
</Text>
|
|
359
|
+
</Pressable>
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Autosaving editor for notes and scratch. A draft (`item` null) is created on the
|
|
365
|
+
* first non-empty save; a note that is empty when the editor closes is deleted.
|
|
366
|
+
*/
|
|
367
|
+
function NoteEditor({
|
|
368
|
+
item,
|
|
369
|
+
draft,
|
|
370
|
+
styles,
|
|
371
|
+
onCreated,
|
|
372
|
+
}: {
|
|
373
|
+
item: Item | null;
|
|
374
|
+
draft: DraftTags;
|
|
375
|
+
styles: Styles;
|
|
376
|
+
onCreated: (id: string) => void;
|
|
377
|
+
}) {
|
|
378
|
+
const save = useRpc(saveNote);
|
|
379
|
+
const remove = useRpc(deleteItem);
|
|
380
|
+
const queryClient = useQueryClient();
|
|
381
|
+
const [title, setTitle] = useState(item?.title ?? "");
|
|
382
|
+
const [body, setBody] = useState(item?.body ?? "");
|
|
383
|
+
const [error, setError] = useState<string | null>(null);
|
|
384
|
+
const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle");
|
|
385
|
+
|
|
386
|
+
const kind = item?.kind === "scratch" ? "scratch" : "note";
|
|
387
|
+
const idRef = useRef(item?.id ?? null);
|
|
388
|
+
const saved = useRef({ title: item?.title ?? "", body: item?.body ?? "" });
|
|
389
|
+
const latest = useRef({ title, body });
|
|
390
|
+
latest.current = { title, body };
|
|
391
|
+
const queue = useRef<Promise<unknown>>(Promise.resolve());
|
|
392
|
+
const onCreatedRef = useRef(onCreated);
|
|
393
|
+
onCreatedRef.current = onCreated;
|
|
394
|
+
|
|
395
|
+
/** Serialized so a draft is created once even when saves overlap. */
|
|
396
|
+
const persist = (final: boolean) => {
|
|
397
|
+
queue.current = queue.current.then(async () => {
|
|
398
|
+
const { title: t, body: b } = latest.current;
|
|
399
|
+
const empty = isEmptyNote(t, b);
|
|
400
|
+
if (empty) {
|
|
401
|
+
if (!final || !idRef.current) return;
|
|
402
|
+
await remove({ id: idRef.current });
|
|
403
|
+
idRef.current = null;
|
|
404
|
+
} else {
|
|
405
|
+
if (t === saved.current.title && b === saved.current.body && idRef.current) return;
|
|
406
|
+
const { item: next } = await save({
|
|
407
|
+
...(idRef.current ? { id: idRef.current } : draft),
|
|
408
|
+
kind,
|
|
409
|
+
title: t.trim() ? t : null,
|
|
410
|
+
body: b,
|
|
411
|
+
});
|
|
412
|
+
saved.current = { title: t, body: b };
|
|
413
|
+
if (!idRef.current) {
|
|
414
|
+
idRef.current = next.id;
|
|
415
|
+
if (!final) onCreatedRef.current(next.id);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
await queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
419
|
+
});
|
|
420
|
+
return queue.current;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
useEffect(() => {
|
|
424
|
+
const dirty = title !== saved.current.title || body !== saved.current.body;
|
|
425
|
+
if (!dirty || isEmptyNote(title, body)) return;
|
|
426
|
+
setStatus("saving");
|
|
427
|
+
const timer = setTimeout(() => {
|
|
428
|
+
persist(false)
|
|
429
|
+
.then(() => {
|
|
430
|
+
setError(null);
|
|
431
|
+
setStatus("saved");
|
|
432
|
+
})
|
|
433
|
+
.catch((e: unknown) => setError(errorText(e)));
|
|
434
|
+
}, SAVE_DELAY_MS);
|
|
435
|
+
return () => clearTimeout(timer);
|
|
436
|
+
}, [title, body]);
|
|
437
|
+
|
|
438
|
+
// Leaving the editor flushes pending text, or drops the note if it ended up empty.
|
|
439
|
+
useEffect(() => () => void persist(true).catch(() => {}), []);
|
|
440
|
+
|
|
441
|
+
const empty = isEmptyNote(title, body);
|
|
442
|
+
const statusText = error
|
|
443
|
+
? error
|
|
444
|
+
: empty
|
|
445
|
+
? idRef.current
|
|
446
|
+
? "Empty — this note will be removed when you leave"
|
|
447
|
+
: "Not saved until it has a title or text"
|
|
448
|
+
: status === "saving"
|
|
449
|
+
? "Saving…"
|
|
450
|
+
: "Saved";
|
|
451
|
+
|
|
452
|
+
return (
|
|
453
|
+
<View style={{ flex: 1, gap: 10 }}>
|
|
454
|
+
<Field
|
|
455
|
+
styles={styles}
|
|
456
|
+
style={styles.input}
|
|
457
|
+
value={title}
|
|
458
|
+
onChangeText={setTitle}
|
|
459
|
+
placeholder="Title (optional)"
|
|
460
|
+
accessibilityLabel="Title"
|
|
461
|
+
/>
|
|
462
|
+
<Field
|
|
463
|
+
styles={styles}
|
|
464
|
+
style={styles.editor}
|
|
465
|
+
value={body}
|
|
466
|
+
onChangeText={setBody}
|
|
467
|
+
placeholder="Write something…"
|
|
468
|
+
accessibilityLabel="Note body"
|
|
469
|
+
multiline
|
|
470
|
+
autoFocus={!item}
|
|
471
|
+
/>
|
|
472
|
+
<Text style={error ? styles.badge("danger") : styles.muted}>{statusText}</Text>
|
|
473
|
+
</View>
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const EXCHANGE_KEY = ["inbox", "last-exchange"] as const;
|
|
478
|
+
|
|
479
|
+
function ExchangeBlock({
|
|
480
|
+
label,
|
|
481
|
+
text,
|
|
482
|
+
styles,
|
|
483
|
+
}: {
|
|
484
|
+
label: string;
|
|
485
|
+
text: string | null;
|
|
486
|
+
styles: Styles;
|
|
487
|
+
}) {
|
|
488
|
+
return (
|
|
489
|
+
<View style={{ gap: 2 }}>
|
|
490
|
+
<Text style={styles.muted}>{label}</Text>
|
|
491
|
+
{text ? (
|
|
492
|
+
<Text style={styles.message} selectable>
|
|
493
|
+
{excerpt(text)}
|
|
494
|
+
</Text>
|
|
495
|
+
) : (
|
|
496
|
+
<Text style={styles.muted}>None yet</Text>
|
|
497
|
+
)}
|
|
498
|
+
</View>
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Latest user prompt and agent reply. Skipped when the agent is gone from the host. */
|
|
503
|
+
function AgentExchange({
|
|
504
|
+
agentId,
|
|
505
|
+
enabled,
|
|
506
|
+
styles,
|
|
507
|
+
}: {
|
|
508
|
+
agentId: string;
|
|
509
|
+
enabled: boolean;
|
|
510
|
+
styles: Styles;
|
|
511
|
+
}) {
|
|
512
|
+
const paseo = usePaseo();
|
|
513
|
+
const query = useQuery({
|
|
514
|
+
queryKey: [...EXCHANGE_KEY, agentId],
|
|
515
|
+
queryFn: () => fetchLastExchange(paseo, agentId),
|
|
516
|
+
enabled,
|
|
517
|
+
refetchInterval: enabled ? 10_000 : false,
|
|
518
|
+
retry: false,
|
|
519
|
+
});
|
|
520
|
+
useEffect(() => {
|
|
521
|
+
if (!query.isError) return;
|
|
522
|
+
console.warn("[inbox] latest exchange failed", agentId, query.error);
|
|
523
|
+
}, [agentId, query.isError, query.error]);
|
|
524
|
+
|
|
525
|
+
if (!enabled) return null;
|
|
526
|
+
if (query.isPending) return <Text style={styles.muted}>Loading messages…</Text>;
|
|
527
|
+
if (query.isError) return <Text style={styles.muted}>Couldn't load the latest messages.</Text>;
|
|
528
|
+
const exchange: LastExchange = query.data ?? { prompt: null, agent: null };
|
|
529
|
+
return (
|
|
530
|
+
<View style={{ gap: 12 }}>
|
|
531
|
+
<ExchangeBlock label="Prompt" text={exchange.prompt} styles={styles} />
|
|
532
|
+
<ExchangeBlock label="Agent" text={exchange.agent} styles={styles} />
|
|
533
|
+
</View>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Open, or Unarchive once archived; sits in the Pin / Remove row. */
|
|
538
|
+
function AgentActions({
|
|
539
|
+
item,
|
|
540
|
+
state,
|
|
541
|
+
styles,
|
|
542
|
+
theme,
|
|
543
|
+
navigation,
|
|
544
|
+
}: {
|
|
545
|
+
item: Item;
|
|
546
|
+
state: AgentState | undefined;
|
|
547
|
+
styles: Styles;
|
|
548
|
+
theme: PluginTheme;
|
|
549
|
+
navigation: PluginSurfaceProps["navigation"];
|
|
550
|
+
}) {
|
|
551
|
+
const unarchive = useRpc(unarchiveAgent);
|
|
552
|
+
const queryClient = useQueryClient();
|
|
553
|
+
const toast = useToast();
|
|
554
|
+
const mutation = useMutation({
|
|
555
|
+
mutationFn: () => unarchive({ agentId: item.agentId! }),
|
|
556
|
+
onSuccess: ({ restoredWorkspace }) => {
|
|
557
|
+
toast.show(restoredWorkspace ? "Workspace and agent restored" : "Agent unarchived", {
|
|
558
|
+
variant: "success",
|
|
559
|
+
});
|
|
560
|
+
void queryClient.invalidateQueries({ queryKey: STATES_KEY });
|
|
561
|
+
},
|
|
562
|
+
onError: (error) => toast.error(errorText(error)),
|
|
563
|
+
});
|
|
564
|
+
if (state === "archived") {
|
|
565
|
+
return (
|
|
566
|
+
<Button
|
|
567
|
+
styles={styles}
|
|
568
|
+
theme={theme}
|
|
569
|
+
kind="primary"
|
|
570
|
+
icon="ArchiveRestore"
|
|
571
|
+
accessibilityLabel={mutation.isPending ? "Unarchiving" : "Unarchive"}
|
|
572
|
+
disabled={mutation.isPending}
|
|
573
|
+
onPress={() => mutation.mutate()}
|
|
574
|
+
/>
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
if (!navigation || state === "missing" || !item.agentId) return null;
|
|
578
|
+
return (
|
|
579
|
+
<Button
|
|
580
|
+
styles={styles}
|
|
581
|
+
theme={theme}
|
|
582
|
+
kind="primary"
|
|
583
|
+
icon="SquareArrowOutUpRight"
|
|
584
|
+
accessibilityLabel="Open"
|
|
585
|
+
onPress={() => navigation.openAgent({ agentId: item.agentId! })}
|
|
586
|
+
/>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function AgentDetail({
|
|
591
|
+
item,
|
|
592
|
+
state,
|
|
593
|
+
live,
|
|
594
|
+
styles,
|
|
595
|
+
}: {
|
|
596
|
+
item: Item;
|
|
597
|
+
state: AgentState | undefined;
|
|
598
|
+
live: AgentLive | undefined;
|
|
599
|
+
styles: Styles;
|
|
600
|
+
}) {
|
|
601
|
+
const agentState = state;
|
|
602
|
+
const snapshot = item.agentSnapshot;
|
|
603
|
+
const facts = [
|
|
604
|
+
["Status", describeAgentStatus(agentState, live)?.label],
|
|
605
|
+
["Provider", [snapshot?.provider, snapshot?.model].filter(Boolean).join(" / ")],
|
|
606
|
+
["Directory", snapshot?.cwd],
|
|
607
|
+
["Starred", new Date(item.createdAt).toLocaleString()],
|
|
608
|
+
] as const;
|
|
609
|
+
|
|
610
|
+
return (
|
|
611
|
+
<View style={{ gap: 12 }}>
|
|
612
|
+
{facts.map(([label, value]) =>
|
|
613
|
+
value ? (
|
|
614
|
+
<View key={label} style={{ gap: 2 }}>
|
|
615
|
+
<Text style={styles.muted}>{label}</Text>
|
|
616
|
+
<Text style={styles.body} selectable>
|
|
617
|
+
{value}
|
|
618
|
+
</Text>
|
|
619
|
+
</View>
|
|
620
|
+
) : null,
|
|
621
|
+
)}
|
|
622
|
+
{item.agentId ? (
|
|
623
|
+
<AgentExchange agentId={item.agentId} enabled={agentState !== "missing"} styles={styles} />
|
|
624
|
+
) : null}
|
|
625
|
+
{agentState === "missing" ? (
|
|
626
|
+
<Text style={styles.muted}>
|
|
627
|
+
This agent no longer exists on this host. You can remove it from the Inbox.
|
|
628
|
+
</Text>
|
|
629
|
+
) : null}
|
|
630
|
+
</View>
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function TagOption({
|
|
635
|
+
label,
|
|
636
|
+
detail,
|
|
637
|
+
selected,
|
|
638
|
+
disabled,
|
|
639
|
+
styles,
|
|
640
|
+
theme,
|
|
641
|
+
onPress,
|
|
642
|
+
}: {
|
|
643
|
+
label: string;
|
|
644
|
+
detail?: string;
|
|
645
|
+
selected: boolean;
|
|
646
|
+
disabled: boolean;
|
|
647
|
+
styles: Styles;
|
|
648
|
+
theme: PluginTheme;
|
|
649
|
+
onPress: () => void;
|
|
650
|
+
}) {
|
|
651
|
+
return (
|
|
652
|
+
<Pressable
|
|
653
|
+
accessibilityRole="button"
|
|
654
|
+
accessibilityLabel={label}
|
|
655
|
+
accessibilityState={{ selected, disabled }}
|
|
656
|
+
disabled={disabled}
|
|
657
|
+
onPress={onPress}
|
|
658
|
+
style={[styles.row, { paddingVertical: 6 }, disabled ? { opacity: 0.4 } : null]}
|
|
659
|
+
>
|
|
660
|
+
<Icon name="Check" size={14} color={selected ? theme.colors.accent : "transparent"} />
|
|
661
|
+
<Text style={styles.itemTitle} numberOfLines={1}>
|
|
662
|
+
{label}
|
|
663
|
+
</Text>
|
|
664
|
+
{detail ? <Text style={styles.muted}>{detail}</Text> : null}
|
|
665
|
+
</Pressable>
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Project and workspace tags. Notes and scratch can change them; a workspace
|
|
671
|
+
* must sit in the tagged project, so other projects are off while one is set.
|
|
672
|
+
* A starred agent's tags follow the agent and are read-only.
|
|
673
|
+
*/
|
|
674
|
+
function TagEditor({
|
|
675
|
+
item,
|
|
676
|
+
archived,
|
|
677
|
+
styles,
|
|
678
|
+
theme,
|
|
679
|
+
}: {
|
|
680
|
+
item: Item;
|
|
681
|
+
archived: Archived;
|
|
682
|
+
styles: Styles;
|
|
683
|
+
theme: PluginTheme;
|
|
684
|
+
}) {
|
|
685
|
+
const options = useRpc(tagOptions);
|
|
686
|
+
const tag = useRpc(tagItem);
|
|
687
|
+
const queryClient = useQueryClient();
|
|
688
|
+
const toast = useToast();
|
|
689
|
+
const [open, setOpen] = useState<"project" | "workspace" | null>(null);
|
|
690
|
+
const editable = item.kind !== "agent";
|
|
691
|
+
const optionsQuery = useQuery({
|
|
692
|
+
queryKey: TAG_OPTIONS_KEY,
|
|
693
|
+
queryFn: () => options({}),
|
|
694
|
+
enabled: editable,
|
|
695
|
+
});
|
|
696
|
+
const mutation = useMutation({
|
|
697
|
+
mutationFn: (next: { projectKey: string | null; workspaceId: string | null }) =>
|
|
698
|
+
tag({ id: item.id, ...next }),
|
|
699
|
+
onSuccess: () => {
|
|
700
|
+
setOpen(null);
|
|
701
|
+
void queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
702
|
+
},
|
|
703
|
+
onError: (error) => toast.error(errorText(error)),
|
|
704
|
+
});
|
|
705
|
+
const choose = (next: { projectKey: string | null; workspaceId: string | null }) => {
|
|
706
|
+
if (next.projectKey === item.projectKey && next.workspaceId === item.workspaceId) setOpen(null);
|
|
707
|
+
else mutation.mutate(next);
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
const projectArchived = Boolean(item.projectKey && archived.projects.has(item.projectKey));
|
|
711
|
+
const workspaceArchived = Boolean(item.workspaceId && archived.workspaces.has(item.workspaceId));
|
|
712
|
+
const chip = (kind: "project" | "workspace") => {
|
|
713
|
+
const isProject = kind === "project";
|
|
714
|
+
const value = isProject
|
|
715
|
+
? item.projectKey && (item.projectLabel ?? item.projectKey)
|
|
716
|
+
: item.workspaceId && (item.workspaceLabel ?? item.workspaceId);
|
|
717
|
+
const struck = isProject ? projectArchived : workspaceArchived;
|
|
718
|
+
const active = open === kind;
|
|
719
|
+
const label = value || (isProject ? "No project" : "No workspace");
|
|
720
|
+
const content = (
|
|
721
|
+
<>
|
|
722
|
+
<Icon
|
|
723
|
+
name={isProject ? "Folder" : "GitBranch"}
|
|
724
|
+
size={12}
|
|
725
|
+
color={active ? theme.colors.accentForeground : theme.colors.foregroundMuted}
|
|
726
|
+
/>
|
|
727
|
+
<Text style={[styles.chipText(active), struck ? styles.struck : null]} numberOfLines={1}>
|
|
728
|
+
{label}
|
|
729
|
+
{struck ? " (archived)" : ""}
|
|
730
|
+
</Text>
|
|
731
|
+
</>
|
|
732
|
+
);
|
|
733
|
+
if (!editable) {
|
|
734
|
+
return value ? <View style={styles.chip(false)}>{content}</View> : null;
|
|
735
|
+
}
|
|
736
|
+
return (
|
|
737
|
+
<Pressable
|
|
738
|
+
accessibilityRole="button"
|
|
739
|
+
accessibilityLabel={`${isProject ? "Project" : "Workspace"}: ${label}`}
|
|
740
|
+
onPress={() => setOpen(active ? null : kind)}
|
|
741
|
+
style={styles.chip(active)}
|
|
742
|
+
>
|
|
743
|
+
{content}
|
|
744
|
+
</Pressable>
|
|
745
|
+
);
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
const projectChip = chip("project");
|
|
749
|
+
const workspaceChip = chip("workspace");
|
|
750
|
+
if (!projectChip && !workspaceChip) return null;
|
|
751
|
+
|
|
752
|
+
const data = optionsQuery.data;
|
|
753
|
+
const projectLabels = new Map(data?.projects.map((project) => [project.key, project.label]));
|
|
754
|
+
const workspaces = data?.workspaces.filter((entry) => !item.projectKey || entry.projectKey === item.projectKey);
|
|
755
|
+
const busy = mutation.isPending;
|
|
756
|
+
|
|
757
|
+
return (
|
|
758
|
+
<View style={{ gap: 6 }}>
|
|
759
|
+
<View style={styles.wrap}>
|
|
760
|
+
{projectChip}
|
|
761
|
+
{workspaceChip}
|
|
762
|
+
</View>
|
|
763
|
+
{open && optionsQuery.isPending ? <Text style={styles.muted}>Loading…</Text> : null}
|
|
764
|
+
{open && optionsQuery.isError ? (
|
|
765
|
+
<Text style={styles.badge("danger")}>{errorText(optionsQuery.error)}</Text>
|
|
766
|
+
) : null}
|
|
767
|
+
{open === "project" && data ? (
|
|
768
|
+
<View style={{ gap: 2 }}>
|
|
769
|
+
{item.workspaceId ? (
|
|
770
|
+
<Text style={styles.muted}>Clear the workspace tag to pick another project.</Text>
|
|
771
|
+
) : null}
|
|
772
|
+
<TagOption
|
|
773
|
+
label="No project"
|
|
774
|
+
selected={!item.projectKey}
|
|
775
|
+
disabled={busy || Boolean(item.workspaceId)}
|
|
776
|
+
styles={styles}
|
|
777
|
+
theme={theme}
|
|
778
|
+
onPress={() => choose({ projectKey: null, workspaceId: null })}
|
|
779
|
+
/>
|
|
780
|
+
{data.projects.map((project) => (
|
|
781
|
+
<TagOption
|
|
782
|
+
key={project.key}
|
|
783
|
+
label={project.label}
|
|
784
|
+
selected={item.projectKey === project.key}
|
|
785
|
+
disabled={busy || Boolean(item.workspaceId && item.projectKey !== project.key)}
|
|
786
|
+
styles={styles}
|
|
787
|
+
theme={theme}
|
|
788
|
+
onPress={() => choose({ projectKey: project.key, workspaceId: item.workspaceId })}
|
|
789
|
+
/>
|
|
790
|
+
))}
|
|
791
|
+
</View>
|
|
792
|
+
) : null}
|
|
793
|
+
{open === "workspace" && data && workspaces ? (
|
|
794
|
+
<View style={{ gap: 2 }}>
|
|
795
|
+
<TagOption
|
|
796
|
+
label="No workspace"
|
|
797
|
+
selected={!item.workspaceId}
|
|
798
|
+
disabled={busy}
|
|
799
|
+
styles={styles}
|
|
800
|
+
theme={theme}
|
|
801
|
+
onPress={() => choose({ projectKey: item.projectKey, workspaceId: null })}
|
|
802
|
+
/>
|
|
803
|
+
{workspaces.map((entry) => (
|
|
804
|
+
<TagOption
|
|
805
|
+
key={entry.id}
|
|
806
|
+
label={entry.label}
|
|
807
|
+
detail={item.projectKey ? undefined : projectLabels.get(entry.projectKey)}
|
|
808
|
+
selected={item.workspaceId === entry.id}
|
|
809
|
+
disabled={busy}
|
|
810
|
+
styles={styles}
|
|
811
|
+
theme={theme}
|
|
812
|
+
onPress={() => choose({ projectKey: item.projectKey, workspaceId: entry.id })}
|
|
813
|
+
/>
|
|
814
|
+
))}
|
|
815
|
+
{workspaces.length === 0 ? (
|
|
816
|
+
<Text style={styles.muted}>No active workspace in this project.</Text>
|
|
817
|
+
) : null}
|
|
818
|
+
</View>
|
|
819
|
+
) : null}
|
|
820
|
+
</View>
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function Detail({
|
|
825
|
+
item,
|
|
826
|
+
draft,
|
|
827
|
+
archived,
|
|
828
|
+
state,
|
|
829
|
+
live,
|
|
830
|
+
styles,
|
|
831
|
+
theme,
|
|
832
|
+
navigation,
|
|
833
|
+
onBack,
|
|
834
|
+
onCreated,
|
|
835
|
+
onDeleted,
|
|
836
|
+
}: {
|
|
837
|
+
item: Item | null;
|
|
838
|
+
draft: DraftTags;
|
|
839
|
+
archived: Archived;
|
|
840
|
+
onCreated: (id: string) => void;
|
|
841
|
+
state: AgentState | undefined;
|
|
842
|
+
live: AgentLive | undefined;
|
|
843
|
+
styles: Styles;
|
|
844
|
+
theme: PluginTheme;
|
|
845
|
+
navigation: PluginSurfaceProps["navigation"];
|
|
846
|
+
onBack: (() => void) | null;
|
|
847
|
+
onDeleted: () => void;
|
|
848
|
+
}) {
|
|
849
|
+
const update = useRpc(updateItem);
|
|
850
|
+
const remove = useRpc(deleteItem);
|
|
851
|
+
const queryClient = useQueryClient();
|
|
852
|
+
const toast = useToast();
|
|
853
|
+
const refresh = () => queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
854
|
+
const run = (task: () => Promise<unknown>, after?: () => void) =>
|
|
855
|
+
task()
|
|
856
|
+
.then(() => {
|
|
857
|
+
after?.();
|
|
858
|
+
return refresh();
|
|
859
|
+
})
|
|
860
|
+
.catch((error: unknown) => toast.error(errorText(error)));
|
|
861
|
+
|
|
862
|
+
return (
|
|
863
|
+
<ScrollView contentContainerStyle={{ flexGrow: 1, gap: 12 }}>
|
|
864
|
+
<View style={styles.row}>
|
|
865
|
+
{onBack ? (
|
|
866
|
+
<Pressable accessibilityRole="button" accessibilityLabel="Back" onPress={onBack}>
|
|
867
|
+
<Icon name="ChevronLeft" size={20} color={theme.colors.foreground} />
|
|
868
|
+
</Pressable>
|
|
869
|
+
) : null}
|
|
870
|
+
{item?.kind === "agent" ? (
|
|
871
|
+
<AgentIcon state={state} live={live} size={18} theme={theme} />
|
|
872
|
+
) : (
|
|
873
|
+
<Icon name={KIND_ICON[item?.kind ?? "note"]} size={18} color={theme.colors.foregroundMuted} />
|
|
874
|
+
)}
|
|
875
|
+
<Text style={[styles.heading, { flex: 1 }]} numberOfLines={2}>
|
|
876
|
+
{item ? itemTitle(item) : "New note"}
|
|
877
|
+
</Text>
|
|
878
|
+
{item?.kind === "agent" ? <PermissionBadge state={state} live={live} theme={theme} /> : null}
|
|
879
|
+
</View>
|
|
880
|
+
{item ? (
|
|
881
|
+
<View style={styles.wrap}>
|
|
882
|
+
{item.kind === "agent" ? (
|
|
883
|
+
<AgentActions item={item} state={state} styles={styles} theme={theme} navigation={navigation} />
|
|
884
|
+
) : null}
|
|
885
|
+
<Button
|
|
886
|
+
styles={styles}
|
|
887
|
+
theme={theme}
|
|
888
|
+
icon={item.pinned ? "PinOff" : "Pin"}
|
|
889
|
+
accessibilityLabel={item.pinned ? "Unpin" : "Pin"}
|
|
890
|
+
onPress={() => run(() => update({ id: item.id, pinned: !item.pinned }))}
|
|
891
|
+
/>
|
|
892
|
+
{item.kind === "scratch" ? (
|
|
893
|
+
<Button
|
|
894
|
+
styles={styles}
|
|
895
|
+
theme={theme}
|
|
896
|
+
icon="NotebookText"
|
|
897
|
+
label="Convert to note"
|
|
898
|
+
onPress={() => run(() => update({ id: item.id, kind: "note" }))}
|
|
899
|
+
/>
|
|
900
|
+
) : null}
|
|
901
|
+
<Button
|
|
902
|
+
styles={styles}
|
|
903
|
+
theme={theme}
|
|
904
|
+
kind="danger"
|
|
905
|
+
icon={item.kind === "agent" ? "StarOff" : "Trash2"}
|
|
906
|
+
accessibilityLabel={item.kind === "agent" ? "Remove from Inbox" : "Delete"}
|
|
907
|
+
onPress={() => run(() => remove({ id: item.id }), onDeleted)}
|
|
908
|
+
/>
|
|
909
|
+
</View>
|
|
910
|
+
) : null}
|
|
911
|
+
{item ? <TagEditor item={item} archived={archived} styles={styles} theme={theme} /> : null}
|
|
912
|
+
{item?.kind === "agent" ? (
|
|
913
|
+
<AgentDetail item={item} state={state} live={live} styles={styles} />
|
|
914
|
+
) : (
|
|
915
|
+
<NoteEditor item={item} draft={draft} styles={styles} onCreated={onCreated} />
|
|
916
|
+
)}
|
|
917
|
+
</ScrollView>
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function AgentPicker({
|
|
922
|
+
workspaceId,
|
|
923
|
+
styles,
|
|
924
|
+
theme,
|
|
925
|
+
onStarred,
|
|
926
|
+
}: {
|
|
927
|
+
workspaceId: string;
|
|
928
|
+
styles: Styles;
|
|
929
|
+
theme: PluginTheme;
|
|
930
|
+
onStarred: () => void;
|
|
931
|
+
}) {
|
|
932
|
+
const candidates = useRpc(agentCandidates);
|
|
933
|
+
const star = useRpc(starAgent);
|
|
934
|
+
const queryClient = useQueryClient();
|
|
935
|
+
const toast = useToast();
|
|
936
|
+
const query = useQuery({
|
|
937
|
+
queryKey: [...CANDIDATES_KEY, workspaceId],
|
|
938
|
+
queryFn: () => candidates({ workspaceId }),
|
|
939
|
+
});
|
|
940
|
+
const mutation = useMutation({
|
|
941
|
+
mutationFn: (agentId: string) => star({ agentId }),
|
|
942
|
+
onSuccess: () => {
|
|
943
|
+
void queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
944
|
+
void queryClient.invalidateQueries({ queryKey: CANDIDATES_KEY });
|
|
945
|
+
onStarred();
|
|
946
|
+
},
|
|
947
|
+
onError: (error) => toast.error(errorText(error)),
|
|
948
|
+
});
|
|
949
|
+
const agents = query.data?.agents ?? [];
|
|
950
|
+
|
|
951
|
+
if (query.isError) return <Text style={styles.badge("danger")}>{errorText(query.error)}</Text>;
|
|
952
|
+
if (query.isPending) return <Text style={styles.muted}>Loading agents…</Text>;
|
|
953
|
+
if (agents.length === 0) {
|
|
954
|
+
return <Text style={styles.muted}>Every agent in this workspace is already in the Inbox.</Text>;
|
|
955
|
+
}
|
|
956
|
+
return (
|
|
957
|
+
<View style={{ gap: 4 }}>
|
|
958
|
+
{agents.map((agent) => (
|
|
959
|
+
<Pressable
|
|
960
|
+
key={agent.id}
|
|
961
|
+
accessibilityRole="button"
|
|
962
|
+
accessibilityLabel={`Add ${agent.title || "Untitled agent"} to the Inbox`}
|
|
963
|
+
disabled={mutation.isPending}
|
|
964
|
+
onPress={() => mutation.mutate(agent.id)}
|
|
965
|
+
style={[styles.row, { paddingVertical: 6 }]}
|
|
966
|
+
>
|
|
967
|
+
<Icon name="Star" size={14} color={theme.colors.foregroundMuted} />
|
|
968
|
+
<Text style={styles.itemTitle} numberOfLines={1}>
|
|
969
|
+
{agent.title || "Untitled agent"}
|
|
970
|
+
</Text>
|
|
971
|
+
<Text style={styles.muted}>{agent.provider}</Text>
|
|
972
|
+
</Pressable>
|
|
973
|
+
))}
|
|
974
|
+
</View>
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function Chip({
|
|
979
|
+
label,
|
|
980
|
+
icon,
|
|
981
|
+
accessibilityLabel,
|
|
982
|
+
active,
|
|
983
|
+
struck,
|
|
984
|
+
styles,
|
|
985
|
+
theme,
|
|
986
|
+
onPress,
|
|
987
|
+
}: {
|
|
988
|
+
label: string;
|
|
989
|
+
icon?: string;
|
|
990
|
+
accessibilityLabel: string;
|
|
991
|
+
active: boolean;
|
|
992
|
+
/** Archived project / workspace. */
|
|
993
|
+
struck?: boolean;
|
|
994
|
+
styles: Styles;
|
|
995
|
+
theme: PluginTheme;
|
|
996
|
+
onPress: () => void;
|
|
997
|
+
}) {
|
|
998
|
+
const color = active ? theme.colors.accentForeground : theme.colors.foregroundMuted;
|
|
999
|
+
return (
|
|
1000
|
+
<Pressable
|
|
1001
|
+
accessibilityRole="button"
|
|
1002
|
+
accessibilityLabel={accessibilityLabel}
|
|
1003
|
+
onPress={onPress}
|
|
1004
|
+
style={styles.chip(active)}
|
|
1005
|
+
>
|
|
1006
|
+
{icon ? <Icon name={icon} size={12} color={color} /> : null}
|
|
1007
|
+
<Text style={[styles.chipText(active), struck ? styles.struck : null]}>{label}</Text>
|
|
1008
|
+
</Pressable>
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/** A single-line chip row; on web the mouse wheel scrolls it sideways. */
|
|
1013
|
+
function ChipStrip({ styles, children }: { styles: Styles; children: ReactNode }) {
|
|
1014
|
+
const scrollRef = useRef<ComponentRef<typeof ScrollView>>(null);
|
|
1015
|
+
useEffect(() => {
|
|
1016
|
+
if (Platform.OS !== "web") return;
|
|
1017
|
+
const node = scrollRef.current?.getScrollableNode() as HorizontalScrollNode | null | undefined;
|
|
1018
|
+
return node ? wheelScrollsHorizontally(node) : undefined;
|
|
1019
|
+
}, []);
|
|
1020
|
+
return (
|
|
1021
|
+
<ScrollView ref={scrollRef} horizontal showsHorizontalScrollIndicator={false}>
|
|
1022
|
+
<View style={styles.row}>{children}</View>
|
|
1023
|
+
</ScrollView>
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* The Inbox list and editor. Without `workspace` it is the global page (every
|
|
1029
|
+
* visible item, workspace filter, ⌘K selection requests); with it, the list is
|
|
1030
|
+
* scoped to that workspace's Inbox for the Explorer panel.
|
|
1031
|
+
*/
|
|
1032
|
+
export function InboxView({
|
|
1033
|
+
theme,
|
|
1034
|
+
layout,
|
|
1035
|
+
navigation,
|
|
1036
|
+
workspace,
|
|
1037
|
+
}: Pick<PluginSurfaceProps, "theme" | "layout" | "navigation"> & { workspace?: InboxWorkspace }) {
|
|
1038
|
+
const compact = workspace ? true : layout.compact;
|
|
1039
|
+
const styles = useMemo(() => createStyles(theme, compact), [theme, compact]);
|
|
1040
|
+
const list = useRpc(listItems);
|
|
1041
|
+
const states = useRpc(agentStates);
|
|
1042
|
+
const queryClient = useQueryClient();
|
|
1043
|
+
|
|
1044
|
+
const filters = useInboxFilters();
|
|
1045
|
+
const updateFilters = useRef(filters.update);
|
|
1046
|
+
updateFilters.current = filters.update;
|
|
1047
|
+
const shown = filters.values ? visibleInboxFilters(filters.values, { workspaceId: workspace?.id }) : null;
|
|
1048
|
+
const kind = shown?.kind ?? null;
|
|
1049
|
+
const projectKey = shown?.projectKey ?? null;
|
|
1050
|
+
const scope = shown?.workspaceId ?? null;
|
|
1051
|
+
const [query, setQuery] = useState("");
|
|
1052
|
+
const [picking, setPicking] = useState(false);
|
|
1053
|
+
const sort = filters.values ? inboxListSort(filters.values, { workspaceId: workspace?.id }) : "updated";
|
|
1054
|
+
const [listWidth, setListWidth] = useState(rememberedListWidth);
|
|
1055
|
+
const widthAtGrant = useRef(listWidth);
|
|
1056
|
+
const listWidthRef = useRef(listWidth);
|
|
1057
|
+
listWidthRef.current = listWidth;
|
|
1058
|
+
const resizer = useMemo(
|
|
1059
|
+
() =>
|
|
1060
|
+
PanResponder.create({
|
|
1061
|
+
onStartShouldSetPanResponder: () => true,
|
|
1062
|
+
onMoveShouldSetPanResponder: () => true,
|
|
1063
|
+
onPanResponderTerminationRequest: () => false,
|
|
1064
|
+
onPanResponderGrant: (event) => {
|
|
1065
|
+
widthAtGrant.current = listWidthRef.current;
|
|
1066
|
+
// The web responder drops the drag once the pointer leaves the thin handle.
|
|
1067
|
+
if (Platform.OS === "web") {
|
|
1068
|
+
trackHorizontalDrag(event.nativeEvent.pageX, (dx) => {
|
|
1069
|
+
rememberedListWidth = clampListWidth(widthAtGrant.current + dx);
|
|
1070
|
+
setListWidth(rememberedListWidth);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
onPanResponderMove: (_, gesture) => {
|
|
1075
|
+
if (Platform.OS !== "web") setListWidth(clampListWidth(widthAtGrant.current + gesture.dx));
|
|
1076
|
+
},
|
|
1077
|
+
onPanResponderRelease: () => {
|
|
1078
|
+
if (Platform.OS !== "web") rememberedListWidth = listWidthRef.current;
|
|
1079
|
+
},
|
|
1080
|
+
onPanResponderTerminate: () => {
|
|
1081
|
+
if (Platform.OS !== "web") rememberedListWidth = listWidthRef.current;
|
|
1082
|
+
},
|
|
1083
|
+
}),
|
|
1084
|
+
[],
|
|
1085
|
+
);
|
|
1086
|
+
const [selection, setSelection] = useState<Selection | null>(() =>
|
|
1087
|
+
workspace ? null : toSelection(takeSelection()),
|
|
1088
|
+
);
|
|
1089
|
+
const selectedId = selection?.id ?? null;
|
|
1090
|
+
const select = (id: string | null) => setSelection(id ? { id, draft: null, session: nextSession() } : null);
|
|
1091
|
+
|
|
1092
|
+
// A command can request a selection while the surface is already mounted.
|
|
1093
|
+
useEffect(() => {
|
|
1094
|
+
if (workspace) return;
|
|
1095
|
+
return onSelectionRequest(() => {
|
|
1096
|
+
const next = toSelection(takeSelection());
|
|
1097
|
+
if (!next) return;
|
|
1098
|
+
updateFilters.current({ kind: "all", projectKey: null, workspaceId: null });
|
|
1099
|
+
setQuery("");
|
|
1100
|
+
setSelection(next);
|
|
1101
|
+
void queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
1102
|
+
});
|
|
1103
|
+
}, [queryClient, workspace]);
|
|
1104
|
+
|
|
1105
|
+
useEffect(
|
|
1106
|
+
() =>
|
|
1107
|
+
onItemsChanged(() => {
|
|
1108
|
+
void queryClient.invalidateQueries({ queryKey: LIST_KEY });
|
|
1109
|
+
void queryClient.invalidateQueries({ queryKey: CANDIDATES_KEY });
|
|
1110
|
+
}),
|
|
1111
|
+
[queryClient],
|
|
1112
|
+
);
|
|
1113
|
+
|
|
1114
|
+
const filter = shown
|
|
1115
|
+
? {
|
|
1116
|
+
...(shown.kind === "all" ? {} : { kind: shown.kind }),
|
|
1117
|
+
...(shown.projectKey ? { projectKey: shown.projectKey } : {}),
|
|
1118
|
+
...(workspace ? { inboxOf: workspace.id } : shown.workspaceId ? { workspaceId: shown.workspaceId } : {}),
|
|
1119
|
+
...(query.trim() ? { query: query.trim() } : {}),
|
|
1120
|
+
...(sort === "updated" ? {} : { sort }),
|
|
1121
|
+
}
|
|
1122
|
+
: null;
|
|
1123
|
+
const itemsQuery = useQuery({
|
|
1124
|
+
queryKey: [...LIST_KEY, filter],
|
|
1125
|
+
queryFn: () => list(filter!),
|
|
1126
|
+
enabled: filter !== null,
|
|
1127
|
+
// The filter chips render from this result; without the previous data they unmount on every uncached filter.
|
|
1128
|
+
placeholderData: keepPreviousData,
|
|
1129
|
+
});
|
|
1130
|
+
const items = itemsQuery.data?.items ?? [];
|
|
1131
|
+
const projects = itemsQuery.data?.projects ?? [];
|
|
1132
|
+
const workspaces = itemsQuery.data?.workspaces ?? [];
|
|
1133
|
+
const archivedData = itemsQuery.data?.archived;
|
|
1134
|
+
const archived = useMemo<Archived>(
|
|
1135
|
+
() => ({ projects: new Set(archivedData?.projects), workspaces: new Set(archivedData?.workspaces) }),
|
|
1136
|
+
[archivedData],
|
|
1137
|
+
);
|
|
1138
|
+
|
|
1139
|
+
// No item of this kind carries the selected tag: its chip is gone, so clear the saved choice.
|
|
1140
|
+
useEffect(() => {
|
|
1141
|
+
const current = filters.values;
|
|
1142
|
+
if (workspace || !itemsQuery.data || itemsQuery.isPlaceholderData || !current) return;
|
|
1143
|
+
const staleProject =
|
|
1144
|
+
current.projectKey && !itemsQuery.data.projects.some((entry) => entry.key === current.projectKey);
|
|
1145
|
+
const staleWorkspace =
|
|
1146
|
+
current.workspaceId && !itemsQuery.data.workspaces.some((entry) => entry.id === current.workspaceId);
|
|
1147
|
+
if (staleProject || staleWorkspace) {
|
|
1148
|
+
updateFilters.current({
|
|
1149
|
+
...(staleProject ? { projectKey: null } : {}),
|
|
1150
|
+
...(staleWorkspace ? { workspaceId: null } : {}),
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}, [filters.values, itemsQuery.data, itemsQuery.isPlaceholderData, workspace]);
|
|
1154
|
+
|
|
1155
|
+
const agentIds = items.flatMap((item) => (item.agentId ? [item.agentId] : [])).sort();
|
|
1156
|
+
const statesQuery = useQuery({
|
|
1157
|
+
queryKey: [...STATES_KEY, agentIds],
|
|
1158
|
+
queryFn: () => states({ agentIds }),
|
|
1159
|
+
enabled: agentIds.length > 0,
|
|
1160
|
+
refetchInterval: 10_000,
|
|
1161
|
+
});
|
|
1162
|
+
useEffect(() => {
|
|
1163
|
+
if (statesQuery.data?.titlesChanged) notifyItemsChanged();
|
|
1164
|
+
}, [statesQuery.data]);
|
|
1165
|
+
const agentState = (item: Item) =>
|
|
1166
|
+
item.agentId ? statesQuery.data?.states[item.agentId] : undefined;
|
|
1167
|
+
const agentLive = (item: Item) =>
|
|
1168
|
+
item.agentId ? statesQuery.data?.live?.[item.agentId] : undefined;
|
|
1169
|
+
|
|
1170
|
+
const selected = items.find((item) => item.id === selectedId) ?? null;
|
|
1171
|
+
// A draft, or a note just created from one, stays open while the list catches up.
|
|
1172
|
+
const editing = selection && (selected || selection.draft !== null || selection.fromDraft);
|
|
1173
|
+
const showList = !compact || !editing;
|
|
1174
|
+
const showDetail = !compact || Boolean(editing);
|
|
1175
|
+
|
|
1176
|
+
const createNote = () => {
|
|
1177
|
+
filters.update(workspace ? { panelKind: "all" } : { kind: "all", projectKey: null, workspaceId: null });
|
|
1178
|
+
setSelection({ id: null, draft: workspace ? { workspaceId: workspace.id } : {}, session: nextSession() });
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
const noteButton = (
|
|
1182
|
+
<Button
|
|
1183
|
+
styles={styles}
|
|
1184
|
+
theme={theme}
|
|
1185
|
+
kind="primary"
|
|
1186
|
+
icon="NotebookPen"
|
|
1187
|
+
accessibilityLabel="New note"
|
|
1188
|
+
onPress={createNote}
|
|
1189
|
+
/>
|
|
1190
|
+
);
|
|
1191
|
+
|
|
1192
|
+
return (
|
|
1193
|
+
<View style={styles.screen}>
|
|
1194
|
+
{showList ? (
|
|
1195
|
+
<View style={[styles.listPane, compact ? { flex: 1 } : { width: listWidth }]}>
|
|
1196
|
+
<View style={styles.toolbar}>
|
|
1197
|
+
<View style={styles.row}>
|
|
1198
|
+
<Field
|
|
1199
|
+
styles={styles}
|
|
1200
|
+
style={[styles.input, { flex: 1, minWidth: 0 }]}
|
|
1201
|
+
value={query}
|
|
1202
|
+
onChangeText={setQuery}
|
|
1203
|
+
placeholder="Search"
|
|
1204
|
+
accessibilityLabel="Search Inbox"
|
|
1205
|
+
/>
|
|
1206
|
+
{noteButton}
|
|
1207
|
+
{workspace ? (
|
|
1208
|
+
<Button
|
|
1209
|
+
styles={styles}
|
|
1210
|
+
theme={theme}
|
|
1211
|
+
icon={picking ? "X" : "Star"}
|
|
1212
|
+
accessibilityLabel={picking ? "Done" : "Add agent"}
|
|
1213
|
+
onPress={() => setPicking((open) => !open)}
|
|
1214
|
+
/>
|
|
1215
|
+
) : (
|
|
1216
|
+
<Button
|
|
1217
|
+
styles={styles}
|
|
1218
|
+
theme={theme}
|
|
1219
|
+
icon={SORTS.find((option) => option.id === sort)!.icon}
|
|
1220
|
+
accessibilityLabel={`Sort: ${SORTS.find((option) => option.id === sort)!.label}`}
|
|
1221
|
+
onPress={() => {
|
|
1222
|
+
const index = SORTS.findIndex((option) => option.id === sort);
|
|
1223
|
+
filters.update({ sort: SORTS[(index + 1) % SORTS.length]!.id });
|
|
1224
|
+
}}
|
|
1225
|
+
/>
|
|
1226
|
+
)}
|
|
1227
|
+
</View>
|
|
1228
|
+
{workspace && picking ? (
|
|
1229
|
+
<AgentPicker
|
|
1230
|
+
workspaceId={workspace.id}
|
|
1231
|
+
styles={styles}
|
|
1232
|
+
theme={theme}
|
|
1233
|
+
onStarred={() => {
|
|
1234
|
+
setPicking(false);
|
|
1235
|
+
filters.update({ panelKind: "all" });
|
|
1236
|
+
setQuery("");
|
|
1237
|
+
}}
|
|
1238
|
+
/>
|
|
1239
|
+
) : null}
|
|
1240
|
+
<View style={styles.wrap}>
|
|
1241
|
+
{FILTERS.map((option) => (
|
|
1242
|
+
<Chip
|
|
1243
|
+
key={option.id}
|
|
1244
|
+
label={option.label}
|
|
1245
|
+
accessibilityLabel={`Show ${option.label}`}
|
|
1246
|
+
active={kind === option.id}
|
|
1247
|
+
styles={styles}
|
|
1248
|
+
theme={theme}
|
|
1249
|
+
onPress={() => filters.update(workspace ? { panelKind: option.id } : { kind: option.id })}
|
|
1250
|
+
/>
|
|
1251
|
+
))}
|
|
1252
|
+
</View>
|
|
1253
|
+
{!workspace && projects.length > 0 ? (
|
|
1254
|
+
<ChipStrip styles={styles}>
|
|
1255
|
+
{projects.map((project) => {
|
|
1256
|
+
const active = projectKey === project.key;
|
|
1257
|
+
return (
|
|
1258
|
+
<Chip
|
|
1259
|
+
key={project.key}
|
|
1260
|
+
icon="Folder"
|
|
1261
|
+
label={`${project.label} · ${project.count}`}
|
|
1262
|
+
accessibilityLabel={`Filter by project ${project.label}${project.archived ? " (archived)" : ""}`}
|
|
1263
|
+
active={active}
|
|
1264
|
+
struck={project.archived}
|
|
1265
|
+
styles={styles}
|
|
1266
|
+
theme={theme}
|
|
1267
|
+
onPress={() => filters.update({ projectKey: active ? null : project.key })}
|
|
1268
|
+
/>
|
|
1269
|
+
);
|
|
1270
|
+
})}
|
|
1271
|
+
</ChipStrip>
|
|
1272
|
+
) : null}
|
|
1273
|
+
{!workspace && workspaces.length > 0 ? (
|
|
1274
|
+
<ChipStrip styles={styles}>
|
|
1275
|
+
{workspaces.map((entry) => (
|
|
1276
|
+
<Chip
|
|
1277
|
+
key={entry.id}
|
|
1278
|
+
icon="GitBranch"
|
|
1279
|
+
label={`${entry.label} · ${entry.count}`}
|
|
1280
|
+
accessibilityLabel={`Filter by workspace ${entry.label}${entry.archived ? " (archived)" : ""}`}
|
|
1281
|
+
active={scope === entry.id}
|
|
1282
|
+
struck={entry.archived}
|
|
1283
|
+
styles={styles}
|
|
1284
|
+
theme={theme}
|
|
1285
|
+
onPress={() =>
|
|
1286
|
+
filters.update({
|
|
1287
|
+
workspaceId: filters.values?.workspaceId === entry.id ? null : entry.id,
|
|
1288
|
+
})
|
|
1289
|
+
}
|
|
1290
|
+
/>
|
|
1291
|
+
))}
|
|
1292
|
+
</ChipStrip>
|
|
1293
|
+
) : null}
|
|
1294
|
+
</View>
|
|
1295
|
+
<ScrollView style={{ flex: 1 }}>
|
|
1296
|
+
{itemsQuery.isError ? (
|
|
1297
|
+
<View style={styles.empty}>
|
|
1298
|
+
<Text style={styles.badge("danger")}>{errorText(itemsQuery.error)}</Text>
|
|
1299
|
+
</View>
|
|
1300
|
+
) : items.length === 0 && !itemsQuery.isPending ? (
|
|
1301
|
+
<View style={styles.empty}>
|
|
1302
|
+
<Icon name="Inbox" size={28} color={theme.colors.foregroundMuted} />
|
|
1303
|
+
<Text style={styles.muted}>
|
|
1304
|
+
{workspace
|
|
1305
|
+
? "Nothing tagged with this workspace or its project yet. Add a note or star an agent."
|
|
1306
|
+
: "Nothing here yet. Star an agent from ⌘K or type /inbox in a composer."}
|
|
1307
|
+
</Text>
|
|
1308
|
+
</View>
|
|
1309
|
+
) : (
|
|
1310
|
+
items.map((item) => (
|
|
1311
|
+
<ItemRow
|
|
1312
|
+
key={item.id}
|
|
1313
|
+
item={item}
|
|
1314
|
+
selected={item.id === selectedId}
|
|
1315
|
+
state={agentState(item)}
|
|
1316
|
+
live={agentLive(item)}
|
|
1317
|
+
archived={archived}
|
|
1318
|
+
hideWorkspaceId={workspace?.id ?? null}
|
|
1319
|
+
styles={styles}
|
|
1320
|
+
theme={theme}
|
|
1321
|
+
onPress={() => select(item.id)}
|
|
1322
|
+
/>
|
|
1323
|
+
))
|
|
1324
|
+
)}
|
|
1325
|
+
</ScrollView>
|
|
1326
|
+
</View>
|
|
1327
|
+
) : null}
|
|
1328
|
+
{showList && showDetail ? (
|
|
1329
|
+
<View {...resizer.panHandlers} style={styles.divider} accessibilityLabel="Resize list">
|
|
1330
|
+
<View style={styles.dividerLine} />
|
|
1331
|
+
</View>
|
|
1332
|
+
) : null}
|
|
1333
|
+
{showDetail ? (
|
|
1334
|
+
<View style={styles.detailPane}>
|
|
1335
|
+
{editing ? (
|
|
1336
|
+
<Detail
|
|
1337
|
+
key={selection.session}
|
|
1338
|
+
item={selected}
|
|
1339
|
+
draft={selection.draft ?? {}}
|
|
1340
|
+
archived={archived}
|
|
1341
|
+
state={selected ? agentState(selected) : undefined}
|
|
1342
|
+
live={selected ? agentLive(selected) : undefined}
|
|
1343
|
+
styles={styles}
|
|
1344
|
+
theme={theme}
|
|
1345
|
+
navigation={navigation}
|
|
1346
|
+
onBack={compact ? () => select(null) : null}
|
|
1347
|
+
onCreated={(id) =>
|
|
1348
|
+
setSelection((current) =>
|
|
1349
|
+
current && current.session === selection.session
|
|
1350
|
+
? { ...current, id, fromDraft: true }
|
|
1351
|
+
: current,
|
|
1352
|
+
)
|
|
1353
|
+
}
|
|
1354
|
+
onDeleted={() => select(null)}
|
|
1355
|
+
/>
|
|
1356
|
+
) : (
|
|
1357
|
+
<View style={styles.empty}>
|
|
1358
|
+
<Text style={styles.muted}>Select an item to view it.</Text>
|
|
1359
|
+
</View>
|
|
1360
|
+
)}
|
|
1361
|
+
</View>
|
|
1362
|
+
) : null}
|
|
1363
|
+
</View>
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
export function InboxSurface({ theme, layout, navigation }: PluginSurfaceProps) {
|
|
1368
|
+
return <InboxView theme={theme} layout={layout} navigation={navigation} />;
|
|
1369
|
+
}
|