@mirrowel/opencode-openshare 0.2.0-dev.1 → 0.2.0-dev.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 +36 -37
- package/ci/README.md +9 -3
- package/ci/openshare.js +379 -85
- package/dist/binding-queue.d.ts +1 -0
- package/dist/binding-queue.js +22 -0
- package/dist/commands.js +41 -285
- package/dist/core.js +524 -88
- package/dist/dialogs.js +1 -1
- package/dist/settings.js +141 -16
- package/dist/share-flow.d.ts +7 -2
- package/dist/share-flow.js +32 -17
- package/dist/sidebar.js +0 -21
- package/dist/tui.js +256 -386
- package/dist/v2-server.js +55 -0
- package/package.json +1 -1
- package/src/binding-queue.ts +26 -0
- package/src/commands.ts +41 -280
- package/src/core.ts +505 -87
- package/src/dialogs.tsx +11 -2
- package/src/settings.ts +133 -15
- package/src/share-flow.ts +33 -19
- package/src/sidebar.tsx +0 -24
- package/src/v2-server.ts +50 -0
package/src/dialogs.tsx
CHANGED
|
@@ -733,8 +733,17 @@ function InfoDialog(props: { api: TuiPluginApi; title: string; message: string;
|
|
|
733
733
|
<box flexDirection="row" gap={1}>
|
|
734
734
|
<For each={actions()}>
|
|
735
735
|
{(action) => (
|
|
736
|
-
<box
|
|
737
|
-
|
|
736
|
+
<box
|
|
737
|
+
paddingLeft={2}
|
|
738
|
+
paddingRight={2}
|
|
739
|
+
backgroundColor={action.key === "enter" ? (action.danger ? theme().error : theme().primary) : undefined}
|
|
740
|
+
border={action.key === "enter" ? undefined : true}
|
|
741
|
+
borderColor={action.danger ? theme().error : theme().textMuted}
|
|
742
|
+
onMouseUp={() => props.onDone(action.value)}
|
|
743
|
+
>
|
|
744
|
+
<text fg={action.key === "enter" ? theme().background : action.danger ? theme().error : theme().textMuted}>
|
|
745
|
+
<b>{action.title}</b>
|
|
746
|
+
</text>
|
|
738
747
|
</box>
|
|
739
748
|
)}
|
|
740
749
|
</For>
|
package/src/settings.ts
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
saveServerEntry,
|
|
31
31
|
serverEntries,
|
|
32
32
|
setShareFlag,
|
|
33
|
+
shareWithConsent,
|
|
34
|
+
workerDeleteShare,
|
|
33
35
|
type AdminShare,
|
|
34
36
|
type AdminUser,
|
|
35
37
|
} from "./share-flow.js"
|
|
@@ -917,26 +919,68 @@ export async function settingsDialog(host: ShareHostApi, startAtSession?: string
|
|
|
917
919
|
|
|
918
920
|
const sessionRows = async (): Promise<ShareDialogSelectOption<string>[]> => {
|
|
919
921
|
if (!startAtSession) return []
|
|
920
|
-
const
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
|
|
922
|
+
const root = await resolveRoot(host.client, startAtSession)
|
|
923
|
+
const bindings = await readBindings(host.client, root)
|
|
924
|
+
const live = bindings.filter((b) => b.url && b.enabled !== false)
|
|
925
|
+
const rows: ShareDialogSelectOption<string>[] = []
|
|
926
|
+
if (live.length === 0) {
|
|
927
|
+
rows.push({
|
|
928
|
+
title: "Share this session",
|
|
924
929
|
value: "session:share",
|
|
925
|
-
description:
|
|
926
|
-
help:
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
930
|
+
description: "set the share flag; the server plugin creates the page",
|
|
931
|
+
help: "Publishes this session (and its subagent sessions) to the active server. The full history lands in the page — sharing mid-session is first-class, nothing is missed. You will be asked to confirm before anything is published.",
|
|
932
|
+
})
|
|
933
|
+
} else if (live.length === 1) {
|
|
934
|
+
const b = live[0]
|
|
935
|
+
rows.push({
|
|
936
|
+
title: "Copy share link",
|
|
937
|
+
value: "session:copy",
|
|
938
|
+
description: "copy the share URL to the clipboard",
|
|
939
|
+
help: `Copies the share URL to the clipboard.\n\nURL: ${b.url}\nShare id: ${b.id ?? "?"}`,
|
|
940
|
+
})
|
|
941
|
+
} else {
|
|
942
|
+
for (const b of live) {
|
|
943
|
+
rows.push({
|
|
944
|
+
title: `Copy link — ${hostOf(b.url || b.server)}`,
|
|
945
|
+
value: `session:copy:${b.server}`,
|
|
946
|
+
description: b.url,
|
|
947
|
+
help: `Copies this server's share URL to the clipboard.\n\nURL: ${b.url}\nShare id: ${b.id}\n\nEach server carries an independent page of the same session.`,
|
|
948
|
+
})
|
|
949
|
+
}
|
|
950
|
+
rows.push({
|
|
951
|
+
title: "Copy all links",
|
|
952
|
+
value: "session:copyall",
|
|
953
|
+
description: `${live.length} servers`,
|
|
954
|
+
help: `Copies every bound server's share URL.\n\n${live.map((b) => `• ${b.url}`).join("\n")}`,
|
|
955
|
+
})
|
|
956
|
+
}
|
|
957
|
+
if (live.length) {
|
|
932
958
|
rows.push({
|
|
933
959
|
title: "Stop sharing",
|
|
934
960
|
value: "session:unshare",
|
|
935
|
-
description:
|
|
961
|
+
description: live.length > 1 ? `delete every page (${live.length} servers), or leave snapshots` : "delete the page, or leave a snapshot",
|
|
936
962
|
danger: true,
|
|
937
|
-
help: `Choose per run: DELETE every page server-side (links stop working — final "gone" state), or LEAVE AS-IS (stop updating; pages stay readable until their TTL — a frozen snapshot).\n\nURLs:\n${
|
|
963
|
+
help: `Choose per run: DELETE every page server-side (links stop working — final "gone" state), or LEAVE AS-IS (stop updating; pages stay readable until their TTL — a frozen snapshot).\n\nURLs:\n${live.map((b) => b.url).join("\n")}\n\nSharing again later always creates fresh page(s) with new URLs.`,
|
|
938
964
|
})
|
|
965
|
+
if (live.length > 1) {
|
|
966
|
+
rows.push({
|
|
967
|
+
title: "Stop on one server…",
|
|
968
|
+
value: "session:unshare:one",
|
|
969
|
+
description: "delete or snapshot a single server's page",
|
|
970
|
+
help: `Per-server stop: pick the server, then delete its page or leave it as a read-only snapshot. Other servers are unaffected.\n\nBound servers:\n${live.map((b) => `• ${b.server} — ${b.url}`).join("\n")}`,
|
|
971
|
+
})
|
|
972
|
+
const otherServers = serverEntries().filter((s) => !live.some((b) => b.server === s.url))
|
|
973
|
+
if (otherServers.length) {
|
|
974
|
+
rows.push({
|
|
975
|
+
title: "Share to another server…",
|
|
976
|
+
value: "session:more",
|
|
977
|
+
description: otherServers.map((s) => hostOf(s.url)).join(", "),
|
|
978
|
+
help: `Adds one of your other configured servers as a destination for THIS session: it becomes the active server and the full history is mirrored there within seconds.\n\nAvailable:\n${otherServers.map((s) => `• ${s.url}`).join("\n")}`,
|
|
979
|
+
})
|
|
980
|
+
}
|
|
981
|
+
}
|
|
939
982
|
}
|
|
983
|
+
const binding = bindings[0]
|
|
940
984
|
rows.push({
|
|
941
985
|
title: "Session TTL override (days)",
|
|
942
986
|
value: "session:ttl",
|
|
@@ -1054,16 +1098,90 @@ export async function settingsDialog(host: ShareHostApi, startAtSession?: string
|
|
|
1054
1098
|
|
|
1055
1099
|
if (choice.startsWith("session:") && startAtSession) {
|
|
1056
1100
|
const root = await resolveRoot(host.client, startAtSession)
|
|
1057
|
-
const
|
|
1101
|
+
const all = await readBindings(host.client, root)
|
|
1102
|
+
const live = all.filter((b) => b.url && b.enabled !== false)
|
|
1103
|
+
const current = all[0]
|
|
1058
1104
|
if (choice === "session:share") {
|
|
1059
1105
|
if (!isConfigured(cfg)) {
|
|
1060
1106
|
await showInfo(host.ui, { title: "Not configured", message: "Connect a server (Servers group) first, then share." })
|
|
1061
1107
|
return
|
|
1062
1108
|
}
|
|
1063
|
-
const result = await
|
|
1109
|
+
const result = await shareWithConsent(host, startAtSession)
|
|
1064
1110
|
host.ui.toast({ variant: result.ok ? "success" : "error", title: "OpenShare", message: result.message, duration: result.ok ? 8000 : 15000 })
|
|
1065
1111
|
return
|
|
1066
1112
|
}
|
|
1113
|
+
if (choice === "session:copy" && live[0]) {
|
|
1114
|
+
const okw = await host.clipboard.write(live[0].url!)
|
|
1115
|
+
host.ui.toast({ variant: okw ? "success" : "error", title: "OpenShare", message: okw ? `Share URL copied: ${live[0].url}` : `Clipboard failed — ${live[0].url}` })
|
|
1116
|
+
return
|
|
1117
|
+
}
|
|
1118
|
+
if (choice.startsWith("session:copy:") ) {
|
|
1119
|
+
const b = live.find((x) => `session:copy:${x.server}` === choice)
|
|
1120
|
+
if (b) {
|
|
1121
|
+
const okw = await host.clipboard.write(b.url!)
|
|
1122
|
+
host.ui.toast({ variant: okw ? "success" : "error", title: "OpenShare", message: okw ? `Share URL copied: ${b.url}` : `Clipboard failed — ${b.url}` })
|
|
1123
|
+
}
|
|
1124
|
+
return
|
|
1125
|
+
}
|
|
1126
|
+
if (choice === "session:copyall") {
|
|
1127
|
+
const joined = live.map((b) => b.url).filter(Boolean).join("\n")
|
|
1128
|
+
const okw = await host.clipboard.write(joined)
|
|
1129
|
+
host.ui.toast({ variant: okw ? "success" : "error", title: "OpenShare", message: okw ? `${live.length} share URL(s) copied` : "Clipboard failed" })
|
|
1130
|
+
return
|
|
1131
|
+
}
|
|
1132
|
+
if (choice === "session:unshare:one") {
|
|
1133
|
+
const pick = await showSelect(host.ui, {
|
|
1134
|
+
title: "Stop on which server",
|
|
1135
|
+
options: [...live.map((b) => ({ title: hostOf(b.url || b.server), value: b.server, description: b.url })), { title: "Cancel", value: "__cancel" }],
|
|
1136
|
+
})
|
|
1137
|
+
if (!pick || pick === "__cancel") return
|
|
1138
|
+
const target = live.find((b) => b.server === pick)
|
|
1139
|
+
if (!target) return
|
|
1140
|
+
const how = await showSelect(host.ui, {
|
|
1141
|
+
title: `Stop sharing — ${hostOf(target.url || target.server)}`,
|
|
1142
|
+
options: [
|
|
1143
|
+
{ title: "Delete the page", value: "delete", description: "this link stops working for everyone", danger: true },
|
|
1144
|
+
{ title: "Leave as-is (snapshot)", value: "leave", description: "stop updating; the page stays until its TTL" },
|
|
1145
|
+
{ title: "Cancel", value: "__cancel" },
|
|
1146
|
+
],
|
|
1147
|
+
})
|
|
1148
|
+
if (!how || how === "__cancel") return
|
|
1149
|
+
if (how === "leave") {
|
|
1150
|
+
await patchSessionBinding(host.client, root, (servers) => {
|
|
1151
|
+
delete servers[target.server]
|
|
1152
|
+
servers[target.server] = { optedOut: true }
|
|
1153
|
+
})
|
|
1154
|
+
host.ui.toast({ variant: "success", title: "OpenShare", message: `${hostOf(target.url || target.server)} left as-is — a snapshot until its TTL.` })
|
|
1155
|
+
return
|
|
1156
|
+
}
|
|
1157
|
+
const targetEntry = all.find((b) => b.server === target.server)
|
|
1158
|
+
if (!targetEntry?.secret) {
|
|
1159
|
+
host.ui.toast({ variant: "error", title: "OpenShare", message: "No secret for this page — cannot delete it server-side; binding cleared." })
|
|
1160
|
+
await patchSessionBinding(host.client, root, (servers) => {
|
|
1161
|
+
delete servers[target.server]
|
|
1162
|
+
})
|
|
1163
|
+
return
|
|
1164
|
+
}
|
|
1165
|
+
const gone = await workerDeleteShare(target.server, target.id!, targetEntry.secret)
|
|
1166
|
+
await patchSessionBinding(host.client, root, (servers) => {
|
|
1167
|
+
delete servers[target.server]
|
|
1168
|
+
})
|
|
1169
|
+
host.ui.toast({ variant: gone ? "success" : "warning", title: "OpenShare", message: gone ? `Page deleted on ${hostOf(target.url || target.server)}.` : `Could not delete the page (it may already be gone) — binding cleared.` })
|
|
1170
|
+
return
|
|
1171
|
+
}
|
|
1172
|
+
if (choice === "session:more") {
|
|
1173
|
+
const otherServers = serverEntries().filter((s) => !live.some((b) => b.server === s.url))
|
|
1174
|
+
if (!otherServers.length) return
|
|
1175
|
+
const pick = await showSelect(host.ui, {
|
|
1176
|
+
title: "Share to another server",
|
|
1177
|
+
options: [...otherServers.map((s) => ({ title: hostOf(s.url), value: s.url, description: s.entry.label })), { title: "Cancel", value: "__cancel" }],
|
|
1178
|
+
})
|
|
1179
|
+
if (!pick || pick === "__cancel") return
|
|
1180
|
+
for (const s of serverEntries()) if (s.url !== pick) saveServerEntry(s.url, { active: undefined })
|
|
1181
|
+
saveServerEntry(pick, { active: true })
|
|
1182
|
+
host.ui.toast({ variant: "success", title: "OpenShare", message: `${hostOf(pick)} activated — this session mirrors there within seconds.` })
|
|
1183
|
+
return
|
|
1184
|
+
}
|
|
1067
1185
|
if (choice === "session:unshare") {
|
|
1068
1186
|
const how = await showSelect(host.ui, {
|
|
1069
1187
|
title: "Stop sharing",
|
package/src/share-flow.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs"
|
|
|
18
18
|
import { loadConfig, moduleDir, configPaths, configHomePath, resolveServer, saveServerEntry, deleteServerEntry, METADATA_KEY, type ShareConfig, type ServerEntry } from "./config.js"
|
|
19
19
|
import { dbg, dbgLog } from "./sidebar.js"
|
|
20
20
|
import type { ClientApi, SessionInfo, SessionOpts } from "./core.js"
|
|
21
|
+
import { queueBindingWrite } from "./binding-queue.js"
|
|
21
22
|
import type { ShareHostApi } from "./tui-host.js"
|
|
22
23
|
|
|
23
24
|
export type SessionBinding = {
|
|
@@ -29,8 +30,6 @@ export type SessionBinding = {
|
|
|
29
30
|
opts?: SessionOpts
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export const CONSENT_KV_KEY = "openshare_consent"
|
|
33
|
-
|
|
34
33
|
export function pluginConfigPaths(baseDir: string = moduleDir()): string[] {
|
|
35
34
|
return configPaths(baseDir)
|
|
36
35
|
}
|
|
@@ -174,18 +173,23 @@ export async function patchSessionBinding(
|
|
|
174
173
|
sid: string,
|
|
175
174
|
mutator: (servers: Record<string, unknown>, binding: Record<string, unknown>) => void,
|
|
176
175
|
): Promise<boolean> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
176
|
+
// the whole read-modify-write runs inside the shared per-session queue:
|
|
177
|
+
// the engine patches the same metadata (binding refresh) and interleaved
|
|
178
|
+
// RMWs silently lose one side's update (see binding-queue.ts)
|
|
179
|
+
return queueBindingWrite(sid, async () => {
|
|
180
|
+
const info = await getSession(client, sid)
|
|
181
|
+
if (!info) return false
|
|
182
|
+
const metadata: Record<string, unknown> = { ...(info.metadata ?? {}) }
|
|
183
|
+
const raw = info.metadata?.[METADATA_KEY]
|
|
184
|
+
const binding: Record<string, unknown> =
|
|
185
|
+
raw && typeof raw === "object" ? { ...(raw as Record<string, unknown>) } : { v: 2, servers: {} }
|
|
186
|
+
const servers: Record<string, unknown> =
|
|
187
|
+
binding.servers && typeof binding.servers === "object" ? { ...(binding.servers as Record<string, unknown>) } : {}
|
|
188
|
+
mutator(servers, binding)
|
|
189
|
+
binding.servers = servers
|
|
190
|
+
metadata[METADATA_KEY] = binding
|
|
191
|
+
return patchMetadata(client, sid, metadata)
|
|
192
|
+
})
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
/** The display/primary binding: the active server's entry when bound
|
|
@@ -482,7 +486,20 @@ export async function waitForBinding(
|
|
|
482
486
|
|
|
483
487
|
export type FlowResult = { ok: boolean; message: string; url?: string; unconfigured?: boolean }
|
|
484
488
|
|
|
485
|
-
|
|
489
|
+
/** Consent gate: EVERY share creation asks explicitly (per owner
|
|
490
|
+
* directive — no remembered consent, no silent creates). */
|
|
491
|
+
export async function requestShareConsent(host: ShareHostApi): Promise<boolean> {
|
|
492
|
+
return host.ui.showConfirm({
|
|
493
|
+
title: "Share Session",
|
|
494
|
+
message: "Publish this session (and its subagent sessions) to your openshare worker?\nThe link lets anyone with it read the conversation.",
|
|
495
|
+
confirmLabel: "Share",
|
|
496
|
+
})
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** runShareFlow with the consent gate applied: share copies the link,
|
|
500
|
+
* unshared asks consent once, then creates. Every create path routes
|
|
501
|
+
* through here (/share, settings, gone-again). */
|
|
502
|
+
export async function shareWithConsent(host: ShareHostApi, sessionID: string | undefined): Promise<FlowResult> {
|
|
486
503
|
if (!sessionID) return { ok: false, message: "No active session to share." }
|
|
487
504
|
const cfg = currentConfig()
|
|
488
505
|
if (!isConfigured(cfg)) {
|
|
@@ -495,10 +512,7 @@ export async function runShareFlow(host: ShareHostApi, sessionID: string | undef
|
|
|
495
512
|
await host.clipboard.write(existing.url)
|
|
496
513
|
return { ok: true, message: `Share URL copied to clipboard: ${existing.url}`, url: existing.url }
|
|
497
514
|
}
|
|
498
|
-
if (!
|
|
499
|
-
// caller shows the consent dialog before invoking confirmShare()
|
|
500
|
-
return { ok: false, message: "consent required" }
|
|
501
|
-
}
|
|
515
|
+
if (!(await requestShareConsent(host))) return { ok: false, message: "Share cancelled." }
|
|
502
516
|
return confirmShare(host, root)
|
|
503
517
|
}
|
|
504
518
|
|
package/src/sidebar.tsx
CHANGED
|
@@ -16,13 +16,6 @@
|
|
|
16
16
|
// proven consumer returns box-rooted trees (opencode's own default
|
|
17
17
|
// children, magic-context's sidebar, the host's slot self-test); text
|
|
18
18
|
// nodes stay LEAVES here — string content only.
|
|
19
|
-
//
|
|
20
|
-
// TEMPORARY crash-hunt instrumentation (owner-approved 2026-10-19): every
|
|
21
|
-
// render logs its inputs (with TYPES), the computed locals, and a dump of
|
|
22
|
-
// the returned element tree to %TEMP%/openshare-tui-debug.log via
|
|
23
|
-
// synchronous appends, so a crash mid-render still leaves evidence. Any
|
|
24
|
-
// throw inside the renderer is logged with its stack, then rethrown.
|
|
25
|
-
// Remove once the live crash is cornered.
|
|
26
19
|
|
|
27
20
|
import type { JSX } from "@opentui/solid"
|
|
28
21
|
import { bindingsOf, bindingOf, verifyShare } from "./share-flow.js"
|
|
@@ -46,23 +39,6 @@ export function dbg(v: unknown, depth = 0): string {
|
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
/** shallow structural dump of a rendered element tree (type names, children kinds) */
|
|
50
|
-
function dbgEl(el: unknown, depth = 0): string {
|
|
51
|
-
if (el === null || el === undefined || typeof el === "string" || typeof el === "number" || typeof el === "boolean") return dbg(el)
|
|
52
|
-
if (Array.isArray(el)) return `[${el.map((x) => dbgEl(x, depth)).join(",")}]`
|
|
53
|
-
if (typeof el === "function") return "fn-node"
|
|
54
|
-
if (depth >= 4) return "…"
|
|
55
|
-
try {
|
|
56
|
-
const rec = el as Record<string, unknown>
|
|
57
|
-
const t = dbg(rec.t ?? rec.type, 2)
|
|
58
|
-
const kids = rec.children
|
|
59
|
-
const props = Object.keys(rec).filter((k) => !["t", "type", "children"].includes(k))
|
|
60
|
-
return `<${t} ${props.join(" ")}>${kids === undefined ? "" : dbgEl(kids, depth + 1)}</${t}>`
|
|
61
|
-
} catch (e) {
|
|
62
|
-
return `el?-${dbg(e)}`
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
42
|
/** no-op: the TUI debug log file was a crash-hunt aid and must not write
|
|
67
43
|
* to temp any more (owner request 2026-10-21) */
|
|
68
44
|
export function dbgLog(_line: string): void {}
|
package/src/v2-server.ts
CHANGED
|
@@ -229,7 +229,20 @@ export function createV2ServerSetup() {
|
|
|
229
229
|
// the client adapter and feed them into the engine as the v1 events it
|
|
230
230
|
// understands (session.updated / message.updated / message.part.updated).
|
|
231
231
|
// The engine's keyed queue makes repeated re-syncs idempotent.
|
|
232
|
+
// NOTE: no content-hash dedupe here — a refresh that runs while the
|
|
233
|
+
// session is still dormant (pre-flag) would poison the cache without
|
|
234
|
+
// emitting anything, and the flag-time refresh would then SKIP the
|
|
235
|
+
// unchanged messages (live-caught in the v2 mock suite: the share's
|
|
236
|
+
// first assistant content arrived only as the next change). The dedupe
|
|
237
|
+
// belongs engine-side, where dormancy is known, if it's ever needed.
|
|
232
238
|
const pendingRefresh = new Map<string, ReturnType<typeof setTimeout>>()
|
|
239
|
+
// queued inbox inputs per session: v2 persists the prompt in the inbox
|
|
240
|
+
// (delivery "queue") while the current turn still runs — the message
|
|
241
|
+
// row can exist before the model ever sees it, and a mid-turn refresh
|
|
242
|
+
// would surface it early. Held here until session.inbox.delivered
|
|
243
|
+
// fires (the turn actually starts); "steer" inputs inject into the
|
|
244
|
+
// live run, so they pass straight through.
|
|
245
|
+
const queuedInbox = new Map<string, Set<string>>()
|
|
233
246
|
const refresh = (sessionID: string) => {
|
|
234
247
|
let timer = pendingRefresh.get(sessionID)
|
|
235
248
|
if (timer) clearTimeout(timer)
|
|
@@ -243,7 +256,9 @@ export function createV2ServerSetup() {
|
|
|
243
256
|
})
|
|
244
257
|
const messages = await (client as NonNullable<typeof client>).session.messages?.({ path: { id: sessionID } })
|
|
245
258
|
const list = ((messages as { data?: unknown })?.data ?? []) as Array<{ info: MessageInfo; parts: PartInfo[] }>
|
|
259
|
+
const held = queuedInbox.get(sessionID)
|
|
246
260
|
for (const message of list) {
|
|
261
|
+
if (held?.has(message.info.id)) continue // still queued — not sent to the model yet
|
|
247
262
|
await engine.hooks.event({
|
|
248
263
|
event: { type: "message.updated", properties: { sessionID, info: message.info } },
|
|
249
264
|
})
|
|
@@ -277,6 +292,41 @@ export function createV2ServerSetup() {
|
|
|
277
292
|
await engine.hooks.event({ event: { type, properties: { sessionID: sid } } })
|
|
278
293
|
continue
|
|
279
294
|
}
|
|
295
|
+
if (type.startsWith("session.inbox.")) {
|
|
296
|
+
// queued-prompt lifecycle: hold delivery="queue" inputs off
|
|
297
|
+
// the share until they are actually delivered to the model
|
|
298
|
+
// (cancelled ones never appear). inboxID shares the message
|
|
299
|
+
// id space (the inbox item promotes into that message row).
|
|
300
|
+
const data = (event.data ?? {}) as { inboxID?: string; item?: { delivery?: string } }
|
|
301
|
+
const inboxID = data.inboxID
|
|
302
|
+
if (inboxID) {
|
|
303
|
+
let set = queuedInbox.get(sid)
|
|
304
|
+
if (!set) {
|
|
305
|
+
set = new Set()
|
|
306
|
+
queuedInbox.set(sid, set)
|
|
307
|
+
}
|
|
308
|
+
if (type === "session.inbox.enqueued" && data.item?.delivery === "queue") {
|
|
309
|
+
set.add(inboxID)
|
|
310
|
+
} else if (type === "session.inbox.delivered") {
|
|
311
|
+
set.delete(inboxID)
|
|
312
|
+
refresh(sid) // the held prompt's turn is starting now
|
|
313
|
+
} else if (type === "session.inbox.cancelled") {
|
|
314
|
+
// cancelled-before-run: the prompt never reaches the
|
|
315
|
+
// model — keep it held forever so no later refresh
|
|
316
|
+
// surfaces the orphaned row
|
|
317
|
+
set.add(inboxID)
|
|
318
|
+
} else if (type === "session.inbox.delivery.changed") {
|
|
319
|
+
// steer inputs inject into the live run — the model
|
|
320
|
+
// sees them; only "queue" holds
|
|
321
|
+
if (data.item?.delivery === "queue") set.add(inboxID)
|
|
322
|
+
else {
|
|
323
|
+
set.delete(inboxID)
|
|
324
|
+
refresh(sid)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
continue
|
|
329
|
+
}
|
|
280
330
|
if (type === "message.removed" || type === "message.part.removed") {
|
|
281
331
|
// undo cleanup: forwarded verbatim — the engine emits the
|
|
282
332
|
// tombstones that purge the reverted items from the share
|