bom-pi 0.0.0-stage → 0.0.2
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/README.md +33 -2
- package/apps/README.md +7 -0
- package/apps/web/README.md +21 -0
- package/apps/web/pocket-adapter.mjs +323 -0
- package/apps/web/public/LICENSE.pocket +21 -0
- package/apps/web/public/activity-fold.js +28 -0
- package/apps/web/public/agent-now.js +37 -0
- package/apps/web/public/agent-tile.js +79 -0
- package/apps/web/public/app.js +975 -0
- package/apps/web/public/apple-touch-icon.png +0 -0
- package/apps/web/public/artifact-bridge.js +687 -0
- package/apps/web/public/avatar.js +87 -0
- package/apps/web/public/back.js +554 -0
- package/apps/web/public/box-keys.js +216 -0
- package/apps/web/public/browser-panel.js +1097 -0
- package/apps/web/public/browser.js +68 -0
- package/apps/web/public/calls.js +139 -0
- package/apps/web/public/chat.js +919 -0
- package/apps/web/public/clock.js +34 -0
- package/apps/web/public/commands.js +578 -0
- package/apps/web/public/composer.js +2068 -0
- package/apps/web/public/diff-parse.js +672 -0
- package/apps/web/public/diff.js +1646 -0
- package/apps/web/public/dock.js +299 -0
- package/apps/web/public/extension-ui.js +2734 -0
- package/apps/web/public/files-panel.js +775 -0
- package/apps/web/public/files.js +368 -0
- package/apps/web/public/fonts/FiraCode-VF.woff2 +0 -0
- package/apps/web/public/fonts/Geist.woff2 +0 -0
- package/apps/web/public/fonts/IBMPlexMono-Variable-Italic.woff2 +0 -0
- package/apps/web/public/fonts/IBMPlexMono-Variable.woff2 +0 -0
- package/apps/web/public/fonts/InterVariable-Italic.woff2 +0 -0
- package/apps/web/public/fonts/InterVariable.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-Bold.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-BoldItalic.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-Italic.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-Regular.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-SemiBold.woff2 +0 -0
- package/apps/web/public/fonts/Iosevka-SemiBoldItalic.woff2 +0 -0
- package/apps/web/public/fonts/JetBrainsMono-Italic.woff2 +0 -0
- package/apps/web/public/fonts/JetBrainsMono.woff2 +0 -0
- package/apps/web/public/fonts/NerdFontsSymbolsMono.woff2 +0 -0
- package/apps/web/public/fonts/SOURCES.md +69 -0
- package/apps/web/public/gestures.js +610 -0
- package/apps/web/public/highlight.js +480 -0
- package/apps/web/public/history.js +70 -0
- package/apps/web/public/home.js +169 -0
- package/apps/web/public/icon-192.png +0 -0
- package/apps/web/public/icon-512.png +0 -0
- package/apps/web/public/icon-maskable-512.png +0 -0
- package/apps/web/public/icon.svg +16 -0
- package/apps/web/public/index.html +71 -0
- package/apps/web/public/launcher.js +1293 -0
- package/apps/web/public/linked-sessions.js +55 -0
- package/apps/web/public/live.js +39 -0
- package/apps/web/public/manifest.webmanifest +32 -0
- package/apps/web/public/model-refresh.js +73 -0
- package/apps/web/public/notify.js +251 -0
- package/apps/web/public/peeks.js +920 -0
- package/apps/web/public/pip-attachments.js +182 -0
- package/apps/web/public/pip-window.js +141 -0
- package/apps/web/public/pip.js +1217 -0
- package/apps/web/public/quote-reply.js +109 -0
- package/apps/web/public/quote-text.js +31 -0
- package/apps/web/public/rich.js +403 -0
- package/apps/web/public/run-frame.js +106 -0
- package/apps/web/public/safe-mode.js +71 -0
- package/apps/web/public/seen.js +169 -0
- package/apps/web/public/session-tree.js +117 -0
- package/apps/web/public/sessions.js +2695 -0
- package/apps/web/public/share.js +126 -0
- package/apps/web/public/sheets/appearance.js +820 -0
- package/apps/web/public/sheets/branch.js +353 -0
- package/apps/web/public/sheets/extensions.js +818 -0
- package/apps/web/public/sheets/file.js +318 -0
- package/apps/web/public/sheets/find.js +250 -0
- package/apps/web/public/sheets/folder.js +680 -0
- package/apps/web/public/sheets/gallery.js +2340 -0
- package/apps/web/public/sheets/hooks.js +350 -0
- package/apps/web/public/sheets/memory.js +531 -0
- package/apps/web/public/sheets/menu.js +580 -0
- package/apps/web/public/sheets/message.js +220 -0
- package/apps/web/public/sheets/model.js +412 -0
- package/apps/web/public/sheets/people.js +414 -0
- package/apps/web/public/sheets/pi-sessions.js +264 -0
- package/apps/web/public/sheets/providers.js +525 -0
- package/apps/web/public/sheets/running.js +130 -0
- package/apps/web/public/sheets/schedules.js +71 -0
- package/apps/web/public/sheets/session.js +249 -0
- package/apps/web/public/sheets/shortcuts.js +101 -0
- package/apps/web/public/sheets/spend.js +150 -0
- package/apps/web/public/sheets/text.js +53 -0
- package/apps/web/public/sheets/viewers.js +363 -0
- package/apps/web/public/sheets/worktree.js +50 -0
- package/apps/web/public/sheets.js +410 -0
- package/apps/web/public/signin.js +57 -0
- package/apps/web/public/slots.js +208 -0
- package/apps/web/public/store.js +1760 -0
- package/apps/web/public/style.css +18625 -0
- package/apps/web/public/subagents-board.js +879 -0
- package/apps/web/public/subagents.js +273 -0
- package/apps/web/public/sw.js +169 -0
- package/apps/web/public/taps.js +26 -0
- package/apps/web/public/theme-surface.d.ts +4 -0
- package/apps/web/public/theme-surface.js +266 -0
- package/apps/web/public/theme.js +845 -0
- package/apps/web/public/themes/lantern/colors.toml +25 -0
- package/apps/web/public/themes/lantern/direction.css +60 -0
- package/apps/web/public/themes/lantern/frame.css +254 -0
- package/apps/web/public/themes/lantern/theme.css +10 -0
- package/apps/web/public/themes/lantern/theme.json +7 -0
- package/apps/web/public/themes/pocket/theme.css +189 -0
- package/apps/web/public/themes/pocket/theme.json +6 -0
- package/apps/web/public/themes.js +556 -0
- package/apps/web/public/transcript.js +3348 -0
- package/apps/web/public/trust.js +295 -0
- package/apps/web/public/turns.js +507 -0
- package/apps/web/public/ui.js +1910 -0
- package/apps/web/public/voice.js +345 -0
- package/apps/web/server.mjs +774 -0
- package/package.json +43 -4
- package/packages/cli/src/bom-pi.mjs +452 -0
- package/packages/cli/templates/blank.factory.json +7 -0
- package/packages/cli/templates/dev.factory.json +11 -0
- package/packages/cli/templates/docs.factory.json +12 -0
- package/packages/cli/templates/ops.factory.json +14 -0
- package/packages/cli/templates/triage.factory.json +10 -0
- package/packages/core/src/daemon.mjs +2047 -0
- package/packages/core/src/limit-gate.mjs +192 -0
- package/packages/core/src/rpc-client.mjs +66 -0
- package/systemd/README.md +11 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// The open sheet: which component shows it. The sheets themselves are in web/sheets/, and a few beside their features
|
|
2
|
+
// (chat.js, notify.js, share.js).
|
|
3
|
+
import { ChatSheet } from "./chat.js";
|
|
4
|
+
import { ExtensionSheet, onExtensionsGone } from "./extension-ui.js";
|
|
5
|
+
import { NotificationsSheet } from "./notify.js";
|
|
6
|
+
import { ShareSheet } from "./share.js";
|
|
7
|
+
import { AppearanceSheet } from "./sheets/appearance.js";
|
|
8
|
+
import { BranchPicker } from "./sheets/branch.js";
|
|
9
|
+
import { ExtensionsContent, ExtensionsSheet } from "./sheets/extensions.js";
|
|
10
|
+
import { FileSheet } from "./sheets/file.js";
|
|
11
|
+
import { FindSheet } from "./sheets/find.js";
|
|
12
|
+
import {
|
|
13
|
+
galleryAvailable,
|
|
14
|
+
GalleryShareSheet,
|
|
15
|
+
GallerySheet,
|
|
16
|
+
GallerySourceSheet,
|
|
17
|
+
GalleryUpdateSheet,
|
|
18
|
+
} from "./sheets/gallery.js";
|
|
19
|
+
import { CwdSheet } from "./sheets/folder.js";
|
|
20
|
+
import { MemorySheet } from "./sheets/memory.js";
|
|
21
|
+
import { MenuSheet, PlacesSheet } from "./sheets/menu.js";
|
|
22
|
+
import { MessageSheet } from "./sheets/message.js";
|
|
23
|
+
import { ModelPicker } from "./sheets/model.js";
|
|
24
|
+
import { InviteSheet, PeopleSheet } from "./sheets/people.js";
|
|
25
|
+
import { AuthDialog, ProvidersSheet } from "./sheets/providers.js";
|
|
26
|
+
import { RunningSheet } from "./sheets/running.js";
|
|
27
|
+
import { HooksSheet } from "./sheets/hooks.js";
|
|
28
|
+
import { SchedulesSheet } from "./sheets/schedules.js";
|
|
29
|
+
import { SessionSheet } from "./sheets/session.js";
|
|
30
|
+
import { ShortcutsSheet } from "./sheets/shortcuts.js";
|
|
31
|
+
import { SpendSheet } from "./sheets/spend.js";
|
|
32
|
+
import { TextSheet } from "./sheets/text.js";
|
|
33
|
+
import {
|
|
34
|
+
ArtifactsSheet,
|
|
35
|
+
ArtifactShareSheet,
|
|
36
|
+
ArtifactViewer,
|
|
37
|
+
ImageViewer,
|
|
38
|
+
} from "./sheets/viewers.js";
|
|
39
|
+
import { PiSessionSheet, PiSessionsSheet, piSessionsAvailable } from "./sheets/pi-sessions.js";
|
|
40
|
+
import { WorktreeSheet } from "./sheets/worktree.js";
|
|
41
|
+
import { TrustSheet } from "./trust.js";
|
|
42
|
+
import { addLayer, goBack, removeLayer } from "./back.js";
|
|
43
|
+
import { actions, api, signOut, store } from "./store.js";
|
|
44
|
+
import { Boundary, html, Icon, SheetBack, SheetInfo, usePresence } from "./ui.js";
|
|
45
|
+
|
|
46
|
+
// ─── Back ─────────────────────────────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
// Identity must not change when Installed turns the gallery module on or off.
|
|
49
|
+
const isExtensionHub = (sheet) => ["extensions", "gallery", "gallery-entry"].includes(sheet.type);
|
|
50
|
+
|
|
51
|
+
/** A hub selection is one step back, even when desktop browsing changes the selected entry. */
|
|
52
|
+
const sheetKey = (sheet) =>
|
|
53
|
+
isExtensionHub(sheet)
|
|
54
|
+
? `extension-hub:${sheet.type === "gallery-entry" ? "entry" : "list"}`
|
|
55
|
+
: `${sheet.type}:${sheet.entryId ?? sheet.id ?? ""}`;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The sheets opened one from another, oldest first (the menu, then the model picker it opened): each is a step back,
|
|
59
|
+
* so back from one shows the sheet before it. `{ key, sheet, layer }`.
|
|
60
|
+
*/
|
|
61
|
+
const trail = [];
|
|
62
|
+
/** The conversation the trail's sheets were opened in: another one (a notice's link, with its sheet) starts afresh. */
|
|
63
|
+
let trailIn = store.state.conversationId;
|
|
64
|
+
|
|
65
|
+
store.subscribe(({ sheet, conversationId }) => {
|
|
66
|
+
if (!sheet || conversationId !== trailIn) {
|
|
67
|
+
trailIn = conversationId;
|
|
68
|
+
|
|
69
|
+
for (const step of trail.splice(0)) {
|
|
70
|
+
removeLayer(step.layer);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!sheet) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const key = sheetKey(sheet);
|
|
79
|
+
const at = trail.findIndex((step) => step.key === key);
|
|
80
|
+
|
|
81
|
+
// The same sheet, or one opened before it, shown again: the steps after it are gone.
|
|
82
|
+
if (at !== -1) {
|
|
83
|
+
for (const step of trail.splice(at + 1)) {
|
|
84
|
+
removeLayer(step.layer);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
trail[at].sheet = sheet;
|
|
88
|
+
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const step = { key, sheet, layer: null };
|
|
93
|
+
|
|
94
|
+
step.layer = addLayer(() => {
|
|
95
|
+
const index = trail.indexOf(step);
|
|
96
|
+
|
|
97
|
+
if (index !== -1) {
|
|
98
|
+
trail.splice(index);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
store.set({ sheet: trail.at(-1)?.sheet ?? null });
|
|
102
|
+
});
|
|
103
|
+
trail.push(step);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// A module turned off: its sheets under the one open come out of the trail, with their steps back, so back never shows
|
|
107
|
+
// one of a module that is gone. Its sheet that is open closes (`extension-ui.js`), and the whole trail with it.
|
|
108
|
+
onExtensionsGone((gone) => {
|
|
109
|
+
const went = trail.filter((each) => each.sheet.type === "ext" && gone(each.sheet.module));
|
|
110
|
+
|
|
111
|
+
for (const step of went) {
|
|
112
|
+
trail.splice(trail.indexOf(step), 1);
|
|
113
|
+
removeLayer(step.layer);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// ─── Focus ────────────────────────────────────────────────────────────────────────
|
|
118
|
+
|
|
119
|
+
/** What had focus when a sheet opened over the app: it has it again when the last sheet closes. */
|
|
120
|
+
let opener = null;
|
|
121
|
+
/** What last had focus outside the sheets and the launcher: a sheet the launcher opens goes back there. */
|
|
122
|
+
let lastFocus = null;
|
|
123
|
+
|
|
124
|
+
addEventListener("focusin", (event) => {
|
|
125
|
+
if (!event.target.closest?.(".sheet-host, .launcher-overlay")) {
|
|
126
|
+
lastFocus = event.target;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
store.subscribe(({ sheet, launcher }) => {
|
|
131
|
+
if (sheet && !opener) {
|
|
132
|
+
const active = document.activeElement;
|
|
133
|
+
|
|
134
|
+
opener = active?.closest(".launcher-overlay") ? lastFocus : active;
|
|
135
|
+
} else if (!sheet && opener) {
|
|
136
|
+
const back = opener;
|
|
137
|
+
const active = document.activeElement;
|
|
138
|
+
|
|
139
|
+
opener = null;
|
|
140
|
+
|
|
141
|
+
// Unless something else took focus meanwhile (a session the sheet opened), or a phone's keyboard would pop up.
|
|
142
|
+
if (
|
|
143
|
+
(active === null || active === document.body || active.closest(".sheet-host")) &&
|
|
144
|
+
!launcher &&
|
|
145
|
+
back.isConnected &&
|
|
146
|
+
!back.closest(".sheet-host") &&
|
|
147
|
+
!(
|
|
148
|
+
matchMedia("(pointer: coarse)").matches &&
|
|
149
|
+
back.matches("input, textarea, [contenteditable]")
|
|
150
|
+
)
|
|
151
|
+
) {
|
|
152
|
+
back.focus({ preventScroll: true });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The open sheet, if any. A sheet that closes stays a moment longer, marked as leaving, so it can animate out; one sheet
|
|
159
|
+
* replacing another swaps at once.
|
|
160
|
+
*/
|
|
161
|
+
export function Sheets() {
|
|
162
|
+
const [sheet, leaving] = usePresence(store.state.sheet, 200);
|
|
163
|
+
const auth = store.state.auth && sheet?.type !== "providers" ? html`<${AuthDialog} />` : null;
|
|
164
|
+
|
|
165
|
+
if (!sheet) {
|
|
166
|
+
return auth;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const key = isExtensionHub(sheet)
|
|
170
|
+
? "extension-hub"
|
|
171
|
+
: `${sheet.type}:${sheet.entryId ?? sheet.id ?? sheet.pipId ?? ""}`;
|
|
172
|
+
|
|
173
|
+
return html`<div class=${`sheet-host ${leaving ? "leaving" : ""}`} inert=${leaving}>
|
|
174
|
+
<${SheetBack.Provider} value=${trail.length > 1 ? goBack : null}>
|
|
175
|
+
<${SheetInfo.Provider} value=${{ type: sheet.type, closing: Boolean(leaving) }}>
|
|
176
|
+
<${Boundary} key=${key} reset=${sheet}>${sheetBody(sheet)}<//>
|
|
177
|
+
<//>
|
|
178
|
+
<//>
|
|
179
|
+
</div>
|
|
180
|
+
${auth}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function sheetBody(sheet) {
|
|
184
|
+
const { view, me } = store.state;
|
|
185
|
+
let body = null;
|
|
186
|
+
|
|
187
|
+
switch (sheet.type) {
|
|
188
|
+
case "appearance":
|
|
189
|
+
body = html`<${AppearanceSheet} />`;
|
|
190
|
+
break;
|
|
191
|
+
case "shortcuts":
|
|
192
|
+
body = html`<${ShortcutsSheet} />`;
|
|
193
|
+
break;
|
|
194
|
+
case "model":
|
|
195
|
+
body = html`<${ModelPicker} />`;
|
|
196
|
+
break;
|
|
197
|
+
case "branch":
|
|
198
|
+
body = view.conversation ? html`<${BranchPicker} />` : null;
|
|
199
|
+
break;
|
|
200
|
+
case "cwd":
|
|
201
|
+
body = html`<${CwdSheet} mode=${sheet.mode} fromList=${sheet.fromList === true} />`;
|
|
202
|
+
break;
|
|
203
|
+
case "artifacts":
|
|
204
|
+
body = html`<${ArtifactsSheet} />`;
|
|
205
|
+
break;
|
|
206
|
+
case "viewer":
|
|
207
|
+
body = view.conversation
|
|
208
|
+
? html`<${ArtifactViewer} id=${sheet.id} version=${sheet.version} />`
|
|
209
|
+
: null;
|
|
210
|
+
break;
|
|
211
|
+
case "artifact-share":
|
|
212
|
+
body = view.conversation
|
|
213
|
+
? html`<${ArtifactShareSheet} id=${sheet.id} version=${sheet.version} />`
|
|
214
|
+
: null;
|
|
215
|
+
break;
|
|
216
|
+
case "providers":
|
|
217
|
+
body = html`<${ProvidersSheet} />`;
|
|
218
|
+
break;
|
|
219
|
+
case "extensions":
|
|
220
|
+
case "gallery":
|
|
221
|
+
case "gallery-entry":
|
|
222
|
+
body = galleryAvailable()
|
|
223
|
+
? html`<${GallerySheet}
|
|
224
|
+
selected=${sheet.type === "gallery-entry" ? sheet.id : null}
|
|
225
|
+
tab=${sheet.tab ?? "discover"}
|
|
226
|
+
origin=${sheet.origin ?? (sheet.type === "gallery" ? "gallery" : "extensions")}
|
|
227
|
+
show=${sheet.show ?? null}
|
|
228
|
+
Management=${ExtensionsContent}
|
|
229
|
+
/>`
|
|
230
|
+
: sheet.type === "extensions"
|
|
231
|
+
? html`<${ExtensionsSheet} />`
|
|
232
|
+
: null;
|
|
233
|
+
break;
|
|
234
|
+
case "gallery-source":
|
|
235
|
+
body = galleryAvailable()
|
|
236
|
+
? html`<${GallerySourceSheet} key=${sheet.id} name=${sheet.id} />`
|
|
237
|
+
: null;
|
|
238
|
+
break;
|
|
239
|
+
case "gallery-update":
|
|
240
|
+
body = galleryAvailable()
|
|
241
|
+
? html`<${GalleryUpdateSheet} key=${sheet.id} name=${sheet.id} />`
|
|
242
|
+
: null;
|
|
243
|
+
break;
|
|
244
|
+
case "gallery-share":
|
|
245
|
+
body = galleryAvailable()
|
|
246
|
+
? html`<${GalleryShareSheet}
|
|
247
|
+
key=${sheet.id}
|
|
248
|
+
file=${sheet.id}
|
|
249
|
+
theme=${sheet.theme === true}
|
|
250
|
+
/>`
|
|
251
|
+
: null;
|
|
252
|
+
break;
|
|
253
|
+
// A sheet an extension's browser module added (`extension-ui.js`).
|
|
254
|
+
case "ext":
|
|
255
|
+
body = html`<${ExtensionSheet} sheet=${sheet} />`;
|
|
256
|
+
break;
|
|
257
|
+
case "image":
|
|
258
|
+
body = html`<${ImageViewer} src=${sheet.src} alt=${sheet.alt} />`;
|
|
259
|
+
break;
|
|
260
|
+
case "invite":
|
|
261
|
+
body = html`<${InviteSheet} session=${sheet.session ?? null} />`;
|
|
262
|
+
break;
|
|
263
|
+
case "people":
|
|
264
|
+
body = html`<${PeopleSheet} />`;
|
|
265
|
+
break;
|
|
266
|
+
case "notifications":
|
|
267
|
+
body = html`<${NotificationsSheet} />`;
|
|
268
|
+
break;
|
|
269
|
+
case "menu":
|
|
270
|
+
body = html`<${MenuSheet} places=${!sheet.fromPlaces} />`;
|
|
271
|
+
break;
|
|
272
|
+
case "session":
|
|
273
|
+
body = store.state.sessions.some((each) => each.id === sheet.id)
|
|
274
|
+
? html`<${SessionSheet} id=${sheet.id} at=${sheet.at ?? null} />`
|
|
275
|
+
: null;
|
|
276
|
+
break;
|
|
277
|
+
case "places":
|
|
278
|
+
body = view.conversation ? html`<${PlacesSheet} />` : null;
|
|
279
|
+
break;
|
|
280
|
+
case "chat":
|
|
281
|
+
body = view.conversation ? html`<${ChatSheet} />` : null;
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case "rename": {
|
|
285
|
+
const renamed = sheet.id
|
|
286
|
+
? store.state.sessions.find((each) => each.id === sheet.id)
|
|
287
|
+
: view.conversation;
|
|
288
|
+
|
|
289
|
+
body =
|
|
290
|
+
renamed &&
|
|
291
|
+
html`<${TextSheet}
|
|
292
|
+
title="Rename"
|
|
293
|
+
label="Session title"
|
|
294
|
+
initial=${renamed.title ?? ""}
|
|
295
|
+
submit=${(value) => actions.updateSession(renamed.id, { title: value })}
|
|
296
|
+
/>`;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
case "worktree":
|
|
301
|
+
body = html`<${WorktreeSheet} />`;
|
|
302
|
+
break;
|
|
303
|
+
case "trust":
|
|
304
|
+
body = view.conversation ? html`<${TrustSheet} />` : null;
|
|
305
|
+
break;
|
|
306
|
+
case "pi-sessions":
|
|
307
|
+
body = piSessionsAvailable() ? html`<${PiSessionsSheet} />` : null;
|
|
308
|
+
break;
|
|
309
|
+
case "pi-session":
|
|
310
|
+
body = piSessionsAvailable()
|
|
311
|
+
? html`<${PiSessionSheet} key=${sheet.id} path=${sheet.id} />`
|
|
312
|
+
: null;
|
|
313
|
+
break;
|
|
314
|
+
case "file":
|
|
315
|
+
body = view.conversation
|
|
316
|
+
? html`<${FileSheet}
|
|
317
|
+
key=${sheet.id}
|
|
318
|
+
path=${sheet.id}
|
|
319
|
+
line=${sheet.line}
|
|
320
|
+
refresh=${sheet.n}
|
|
321
|
+
/>`
|
|
322
|
+
: null;
|
|
323
|
+
break;
|
|
324
|
+
case "find":
|
|
325
|
+
body = view.conversation
|
|
326
|
+
? html`<${FindSheet} key=${view.conversation.id} initial=${sheet.query ?? ""} />`
|
|
327
|
+
: null;
|
|
328
|
+
break;
|
|
329
|
+
case "spend":
|
|
330
|
+
body = html`<${SpendSheet} />`;
|
|
331
|
+
break;
|
|
332
|
+
case "running":
|
|
333
|
+
body = html`<${RunningSheet} />`;
|
|
334
|
+
break;
|
|
335
|
+
case "schedules":
|
|
336
|
+
body = view.conversation ? html`<${SchedulesSheet} />` : null;
|
|
337
|
+
break;
|
|
338
|
+
case "hooks":
|
|
339
|
+
body = html`<${HooksSheet} />`;
|
|
340
|
+
break;
|
|
341
|
+
case "memory":
|
|
342
|
+
body =
|
|
343
|
+
sheet.conversationId !== undefined || view.conversation
|
|
344
|
+
? html`<${MemorySheet}
|
|
345
|
+
draft=${sheet.draft ?? ""}
|
|
346
|
+
conversationId=${sheet.conversationId}
|
|
347
|
+
pendingOnly=${sheet.pendingOnly === true}
|
|
348
|
+
/>`
|
|
349
|
+
: null;
|
|
350
|
+
break;
|
|
351
|
+
case "share":
|
|
352
|
+
body = html`<${ShareSheet} share=${sheet.share} />`;
|
|
353
|
+
break;
|
|
354
|
+
case "message":
|
|
355
|
+
body = view.conversation
|
|
356
|
+
? html`<${MessageSheet} key=${sheet.entryId} entryId=${sheet.entryId} />`
|
|
357
|
+
: null;
|
|
358
|
+
break;
|
|
359
|
+
case "reset":
|
|
360
|
+
body = html`<${TextSheet}
|
|
361
|
+
title="New context"
|
|
362
|
+
hint="Pi starts fresh: it no longer sees the messages so far, though everyone here still does."
|
|
363
|
+
label="Handoff note (optional)"
|
|
364
|
+
placeholder="e.g. We fixed the login bug; next is the signup form."
|
|
365
|
+
multiline=${true}
|
|
366
|
+
button="Start a new context"
|
|
367
|
+
submit=${(value) => actions.reset(value)}
|
|
368
|
+
/>`;
|
|
369
|
+
break;
|
|
370
|
+
case "instructions":
|
|
371
|
+
body = html`<${TextSheet}
|
|
372
|
+
title="Instructions for Pi"
|
|
373
|
+
hint="Pi gets these with every message in this session, after its own instructions. Everyone here can see them. Leave empty for none."
|
|
374
|
+
label="Instructions"
|
|
375
|
+
initial=${view.agent?.instructions ?? ""}
|
|
376
|
+
placeholder="e.g. Use pnpm, not npm. Ask before adding dependencies."
|
|
377
|
+
multiline=${true}
|
|
378
|
+
submit=${(value) => actions.setInstructions(value)}
|
|
379
|
+
/>`;
|
|
380
|
+
break;
|
|
381
|
+
case "compact":
|
|
382
|
+
body = html`<${TextSheet}
|
|
383
|
+
title="Compact context"
|
|
384
|
+
label="What should the summary keep? (optional)"
|
|
385
|
+
placeholder="e.g. the failing test names"
|
|
386
|
+
multiline=${true}
|
|
387
|
+
button="Compact"
|
|
388
|
+
submit=${(value) => actions.compact(value)}
|
|
389
|
+
/>`;
|
|
390
|
+
break;
|
|
391
|
+
case "name":
|
|
392
|
+
body = html`<${TextSheet}
|
|
393
|
+
title="Your name"
|
|
394
|
+
label="Shown on your messages to others"
|
|
395
|
+
initial=${me?.name ?? ""}
|
|
396
|
+
footer=${html`<button class="button ghost wide sheet-footer signout" onClick=${signOut}>
|
|
397
|
+
<${Icon} name="logout" size=${16} /> Sign out
|
|
398
|
+
</button>`}
|
|
399
|
+
submit=${async (value) => {
|
|
400
|
+
await api("me", { name: value });
|
|
401
|
+
const hello = await api("me");
|
|
402
|
+
|
|
403
|
+
store.set({ me: hello.user, users: hello.users });
|
|
404
|
+
}}
|
|
405
|
+
/>`;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return body;
|
|
410
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The sign-in screen, for a browser that is not signed in.
|
|
2
|
+
|
|
3
|
+
import { useState } from "preact/hooks";
|
|
4
|
+
import { html } from "./ui.js";
|
|
5
|
+
|
|
6
|
+
export function SignIn() {
|
|
7
|
+
const [value, setValue] = useState("");
|
|
8
|
+
|
|
9
|
+
const go = () => {
|
|
10
|
+
const text = value.trim();
|
|
11
|
+
|
|
12
|
+
if (!text) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL(text, location.origin);
|
|
18
|
+
|
|
19
|
+
if (url.pathname.startsWith("/join/") || url.searchParams.has("token")) {
|
|
20
|
+
location.href = `${url.pathname}${url.search}`;
|
|
21
|
+
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
// not a URL
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Invite codes are ten lowercase letters and digits, and phones capitalize the first letter typed. Tokens are longer.
|
|
29
|
+
// The invite sheet shows a code in two groups, so spaces typed or copied between them are dropped.
|
|
30
|
+
const code = text.toLowerCase().replace(/\s+/g, "");
|
|
31
|
+
|
|
32
|
+
location.href = /^[a-z0-9]{10}$/.test(code)
|
|
33
|
+
? `/join/${code}`
|
|
34
|
+
: `/login?token=${encodeURIComponent(text)}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return html`<div class="signin" data-part="sign-in">
|
|
38
|
+
<div class="pi big">π</div>
|
|
39
|
+
<h1>Pi Pocket</h1>
|
|
40
|
+
<p class="muted">
|
|
41
|
+
Open the sign-in link Pi Pocket printed when it started, or an invite from a signed-in device. You can also paste the link, the token, or an invite code here.
|
|
42
|
+
</p>
|
|
43
|
+
<div class="row">
|
|
44
|
+
<input
|
|
45
|
+
value=${value}
|
|
46
|
+
placeholder="Link, token, or invite code"
|
|
47
|
+
autocapitalize="none"
|
|
48
|
+
autocorrect="off"
|
|
49
|
+
autocomplete="off"
|
|
50
|
+
spellcheck=${false}
|
|
51
|
+
onInput=${(event) => setValue(event.currentTarget.value)}
|
|
52
|
+
onKeyDown=${(event) => event.key === "Enter" && go()}
|
|
53
|
+
/>
|
|
54
|
+
<button class="button primary" onClick=${go}>Sign in</button>
|
|
55
|
+
</div>
|
|
56
|
+
</div>`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Slots: places in the app built from named items, the app's own and extensions' alike, in one order that a person and
|
|
2
|
+
// extensions can change. The app's items have `core:` names (`core:files`, `core:cache`), extensions' `ext:<module>:<id>`.
|
|
3
|
+
// What shows, and where, comes in layers: each item's default place, then where an extension asked to put its own item
|
|
4
|
+
// (`before`, `after`), then what extensions arranged (`pocket.arrange`), then this browser's person's own choices
|
|
5
|
+
// (Appearance → Layout), which win. Fixed items (the menu, Lancet Guard) always show, in their own place.
|
|
6
|
+
import { Fragment, h } from "preact";
|
|
7
|
+
import { prefs, setPrefs } from "./theme.js";
|
|
8
|
+
|
|
9
|
+
/** The slots, with their names for people and where extensions' items go by default. */
|
|
10
|
+
export const SLOTS = {
|
|
11
|
+
topbar: { label: "Top bar buttons", extensions: 550 },
|
|
12
|
+
status: { label: "Status line items", extensions: 500 },
|
|
13
|
+
places: { label: "Places", extensions: 1000 },
|
|
14
|
+
composer: { label: "Message box buttons", extensions: 500 },
|
|
15
|
+
reply: { label: "Under Pi's answers", extensions: 500 },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The app's own items, by slot: `{ id, label, order, fixed, render(context), detail(context) }`. `render` gives what
|
|
20
|
+
* shows, or null when it has nothing to show now; `detail`, what a tap on the status line says of it. `context` is what
|
|
21
|
+
* the place that draws the slot gives: the answer, for the actions under one.
|
|
22
|
+
*/
|
|
23
|
+
const core = new Map(Object.keys(SLOTS).map((slot) => [slot, []]));
|
|
24
|
+
/** Where extensions' items come from (`extension-ui.js`): `(slot) => items`, with `before` and `after` too. */
|
|
25
|
+
let extensionItems = () => [];
|
|
26
|
+
/** What extensions arranged: `(slot) => [{ module, title, hide, order }]`, in the server's order of modules. */
|
|
27
|
+
let extensionArrangements = () => [];
|
|
28
|
+
/** Counts changes to the items and arrangements above: each slot's order (`arranged`) is kept until the next. */
|
|
29
|
+
let version = 0;
|
|
30
|
+
/** Each slot's order as it was last worked out: `{ version, layout, list, key }`. */
|
|
31
|
+
const kept = new Map();
|
|
32
|
+
|
|
33
|
+
/** Add one of the app's own items to a slot. */
|
|
34
|
+
export function defineItem(slot, item) {
|
|
35
|
+
core.get(slot).push(item);
|
|
36
|
+
version++;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Where extensions' items and arrangements come from: `extension-ui.js`, which imports this module. */
|
|
40
|
+
export function fromExtensions(items, arrangements) {
|
|
41
|
+
extensionItems = items;
|
|
42
|
+
extensionArrangements = arrangements;
|
|
43
|
+
version++;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Extensions' items or arrangements changed: `extension-ui.js` says so as they do, before it draws them. */
|
|
47
|
+
export function slotsChanged() {
|
|
48
|
+
version++;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The items named in `ids` take the places those items had, in the order `ids` gives; the rest stay where they are. So
|
|
53
|
+
* an order saved before an item came still holds, and the new item keeps its default place.
|
|
54
|
+
*/
|
|
55
|
+
function reorder(list, ids) {
|
|
56
|
+
// Each id once: a list with an id twice would put one item in two places, and drop another.
|
|
57
|
+
const named = [...new Set(ids)]
|
|
58
|
+
.map((id) => list.find((item) => item.id === id))
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
const places = new Set(named);
|
|
61
|
+
let next = 0;
|
|
62
|
+
|
|
63
|
+
return list.map((item) => (places.has(item) ? named[next++] : item));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Move `item` just before or after the item named `target`, when that one is there. */
|
|
67
|
+
function place(list, item, target, after) {
|
|
68
|
+
const rest = list.filter((each) => each !== item);
|
|
69
|
+
const at = rest.findIndex((each) => each.id === target);
|
|
70
|
+
|
|
71
|
+
if (at === -1) {
|
|
72
|
+
return list;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rest.splice(after ? at + 1 : at, 0, item);
|
|
76
|
+
|
|
77
|
+
return rest;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Every item of a slot, in the order it shows: `{ item, hidden, hiddenBy }`, `hiddenBy` naming the extension that hid it
|
|
82
|
+
* when the person made no choice of their own. Items that show nothing now (no artifacts yet, say) are here too: the
|
|
83
|
+
* Layout settings list them all. Worked out again only when the items, what extensions arranged, or the person's
|
|
84
|
+
* layout changed: the top bar, the message box, the status line, and each of Pi's answers ask on every draw.
|
|
85
|
+
*/
|
|
86
|
+
export function arranged(slot) {
|
|
87
|
+
return keptFor(slot).list;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function keptFor(slot) {
|
|
91
|
+
const layout = prefs().layout;
|
|
92
|
+
const last = kept.get(slot);
|
|
93
|
+
|
|
94
|
+
if (last?.version === version && last.layout === layout) {
|
|
95
|
+
return last;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const list = arrange(slot);
|
|
99
|
+
const next = {
|
|
100
|
+
version,
|
|
101
|
+
layout,
|
|
102
|
+
list,
|
|
103
|
+
key: list
|
|
104
|
+
.map(({ item, hidden }) => `${item.id}${item.revision ?? ""}${hidden ? "-" : "+"}`)
|
|
105
|
+
.join(),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
kept.set(slot, next);
|
|
109
|
+
|
|
110
|
+
return next;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function arrange(slot) {
|
|
114
|
+
const defaultPlace = (item) => item.order ?? SLOTS[slot].extensions;
|
|
115
|
+
let list = [...core.get(slot), ...extensionItems(slot)]
|
|
116
|
+
.map((item, index) => ({ item, index }))
|
|
117
|
+
.sort((a, b) => defaultPlace(a.item) - defaultPlace(b.item) || a.index - b.index)
|
|
118
|
+
.map(({ item }) => item);
|
|
119
|
+
|
|
120
|
+
for (const item of list.filter((each) => each.before || each.after)) {
|
|
121
|
+
list = place(list, item, item.before ?? item.after, item.before === undefined);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Fixed items keep their places: the rest move around them.
|
|
125
|
+
const fixed = list.map((item, index) => [item, index]).filter(([item]) => item.fixed);
|
|
126
|
+
const arrangements = extensionArrangements(slot);
|
|
127
|
+
const mine = prefs().layout?.[slot] ?? {};
|
|
128
|
+
|
|
129
|
+
list = list.filter((item) => !item.fixed);
|
|
130
|
+
|
|
131
|
+
for (const arrangement of arrangements) {
|
|
132
|
+
list = reorder(list, arrangement.order ?? []);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
list = reorder(list, mine.order ?? []);
|
|
136
|
+
|
|
137
|
+
for (const [item, index] of fixed) {
|
|
138
|
+
list.splice(index, 0, item);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return list.map((item) => {
|
|
142
|
+
const by = arrangements.find((each) => each.hide?.includes(item.id));
|
|
143
|
+
const choice = mine.hidden?.[item.id];
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
item,
|
|
147
|
+
hidden: !item.fixed && (choice ?? by !== undefined),
|
|
148
|
+
hiddenBy: !item.fixed && choice === undefined && by ? by.title : null,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* What a slot shows now: `{ id, node, detail }` for each item that shows and has something to show, in its order. Each
|
|
155
|
+
* node keeps its item's key, so a reorder moves it rather than drawing it again.
|
|
156
|
+
*/
|
|
157
|
+
export function slotItems(slot, context = {}) {
|
|
158
|
+
return arranged(slot)
|
|
159
|
+
.filter(({ hidden }) => !hidden)
|
|
160
|
+
.map(({ item }) => ({
|
|
161
|
+
id: item.id,
|
|
162
|
+
node: item.render(context),
|
|
163
|
+
detail: item.detail?.(context),
|
|
164
|
+
}))
|
|
165
|
+
.filter(({ node }) => node !== null && node !== undefined && node !== false)
|
|
166
|
+
.map(({ id, node, detail }) => ({ id, node: h(Fragment, { key: id }, node), detail }));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* What a slot holds and how it is arranged, as one string: for a place that draws again only when its inputs change
|
|
171
|
+
* (the transcript's answers), so a change to the slot draws it again.
|
|
172
|
+
*/
|
|
173
|
+
export const slotKey = (slot) => keptFor(slot).key;
|
|
174
|
+
|
|
175
|
+
// ─── This browser's person's own choices ─────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
function saveMine(slot, change) {
|
|
178
|
+
const layout = prefs().layout ?? {};
|
|
179
|
+
const mine = change(layout[slot] ?? {});
|
|
180
|
+
|
|
181
|
+
setPrefs({ layout: { ...layout, [slot]: mine } });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Show or hide an item, over what any extension asked. */
|
|
185
|
+
export function setShown(slot, id, shown) {
|
|
186
|
+
saveMine(slot, (mine) => ({ ...mine, hidden: { ...mine.hidden, [id]: !shown } }));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Move an item one place up (`-1`) or down (`1`) among the items that can move. */
|
|
190
|
+
export function move(slot, id, by) {
|
|
191
|
+
const ids = arranged(slot)
|
|
192
|
+
.filter(({ item }) => !item.fixed)
|
|
193
|
+
.map(({ item }) => item.id);
|
|
194
|
+
const at = ids.indexOf(id);
|
|
195
|
+
const to = at + by;
|
|
196
|
+
|
|
197
|
+
if (at === -1 || to < 0 || to >= ids.length) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
[ids[at], ids[to]] = [ids[to], ids[at]];
|
|
202
|
+
saveMine(slot, (mine) => ({ ...mine, order: ids }));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Back to the defaults and what extensions arranged. */
|
|
206
|
+
export function resetSlot(slot) {
|
|
207
|
+
saveMine(slot, () => ({}));
|
|
208
|
+
}
|