mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(browser): a preview opens the pane and selects its tab, whatever the pane showed before
A person who opened the side panel and closed it again during a run, before the agent showed anything, was taken to have dismissed the agent's pages: the first preview then opened nothing. Closing the pane is a dismissal only once the pane has shown the agent's page in that run. A preview now selects its tab in a pane that is open on another tab, behind the same click guard, and so does a file preview. For a session that is off screen or in a hidden window the tab is selected in its strip and marked, so it shows when the person returns. A request that arrives before the strip can be written or before the inventory that carries its tab is kept and applied when they land. A focused tabs.open, tabs.focus and navigate behave as before.
This commit is contained in:
parent
5fa21a811e
commit
5c6673b8b4
6 changed files with 251 additions and 73 deletions
|
|
@ -154,7 +154,9 @@ export const PaneEvent = Schema.Union([
|
|||
// What the tab waits on the user for; null once nothing waits.
|
||||
Schema.Struct({ type: Schema.Literal("prompt"), tabID: Browser.TabID, prompt: Schema.NullOr(PromptView) }),
|
||||
Schema.Struct({ type: Schema.Literal("focus"), tabID: Browser.TabID }),
|
||||
Schema.Struct({ type: Schema.Literal("activity"), tabID: Browser.TabID, reveal: Schema.Boolean }),
|
||||
// What the agent did on the tab asks of the pane. `none`: nothing, the tab is only marked. `pane`: a closed pane
|
||||
// opens on the tab. `tab`: the tab is selected, in a closed pane or in an open one that shows another tab.
|
||||
Schema.Struct({ type: Schema.Literal("activity"), tabID: Browser.TabID, reveal: Schema.Literals(["none", "pane", "tab"]) }),
|
||||
Schema.Struct({ type: Schema.Literal("preview"), path: text(2_048) }),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("state"),
|
||||
|
|
|
|||
|
|
@ -97,39 +97,115 @@ const ready = (state = replay(attach()).state) => replay([paneState(state, inven
|
|||
const types = (effects: readonly MachineEffect[]) => effects.map((effect) => effect.type)
|
||||
|
||||
describe("browser pane machine", () => {
|
||||
// A preview of tab A for the routed session, in a window with room, with the pane closed.
|
||||
const activity = (state: State) => ({ type: "pane.activity" as const, sessionKey: key, attempt: attempt(state),
|
||||
tabID: tabA, reveal: true, room: true, enabled: true, onScreen: true, opened: false, visible: false })
|
||||
tabID: tabA, reveal: "tab" as const, room: true, enabled: true, onScreen: true, opened: false, visible: false })
|
||||
|
||||
const side = (open: boolean): Event => ({ type: "side.changed", sessionKey: key, open, running: true })
|
||||
|
||||
// "open": the tab is selected behind the click guard. "select": selected and marked, with no guard, as nobody is
|
||||
// looking. "mark": only the unseen mark. "none": nothing.
|
||||
test.each([
|
||||
["closed pane", {}, "open"],
|
||||
["another browser tab, Review or Files selected", { opened: true }, "mark"],
|
||||
["a preview with the pane closed", {}, "open"],
|
||||
["a preview with another browser tab, Review or Files selected", { opened: true }, "open"],
|
||||
["a focused new tab with the pane closed", { reveal: "pane" }, "open"],
|
||||
["a focused new tab with another tab selected", { reveal: "pane", opened: true }, "mark"],
|
||||
["target already visible", { opened: true, visible: true }, "none"],
|
||||
["session off screen or window hidden", { onScreen: false }, "none"],
|
||||
["disabled", { enabled: false }, "mark"],
|
||||
["open pane with setting disabled", { enabled: false, opened: true }, "mark"],
|
||||
["a preview of the tab a closed pane has selected", { visible: true }, "open"],
|
||||
["a preview for a session off screen or in a hidden window", { onScreen: false }, "select"],
|
||||
["a preview off screen with the setting turned off", { onScreen: false, enabled: false }, "mark"],
|
||||
["a focused new tab off screen", { onScreen: false, reveal: "pane" }, "none"],
|
||||
["the setting turned off", { enabled: false }, "mark"],
|
||||
["open pane with the setting turned off", { enabled: false, opened: true }, "mark"],
|
||||
["no room beside the chat", { room: false }, "mark"],
|
||||
["navigate, popup, focus, implicit open or quiet tab", { reveal: false }, "mark"],
|
||||
["navigate, popup, focus, implicit open or quiet tab", { reveal: "none" }, "mark"],
|
||||
["superseded binding", { attempt: -1 }, "none"],
|
||||
["since-closed tab", { tabID: tabB }, "none"],
|
||||
] as const)("agent navigation, preview or new tab: %s", (_label, input, expected) => {
|
||||
const start = ready()
|
||||
const next = transition(start, { ...activity(start), ...input })
|
||||
expect(types(next.effects)).toEqual(expected === "open" ? ["focus-strip-tab"] : [])
|
||||
expect(attachment(next.state)?.unseen).toEqual(expected === "mark" ? [tabA] : [])
|
||||
expect(types(next.effects)).toEqual(expected === "open" || expected === "select" ? ["focus-strip-tab"] : [])
|
||||
expect(attachment(next.state)?.unseen).toEqual(expected === "mark" || expected === "select" ? [tabA] : [])
|
||||
expect(revealGuard(next.state, key, tabA) !== undefined).toBe(expected === "open")
|
||||
})
|
||||
|
||||
test("closing the pane during a run wins until reopening it or finishing the run", () => {
|
||||
test("closing the pane the agent showed its page in wins until reopening it or finishing the run", () => {
|
||||
const start = ready()
|
||||
const side = (open: boolean): Event => ({ type: "side.changed", sessionKey: key, open, running: true })
|
||||
const hidden = replay([side(true), side(false)], start).state
|
||||
const shown = transition(start, activity(start)).state
|
||||
const hidden = replay([side(true), side(false)], shown).state
|
||||
expect(attachment(hidden)?.side).toBe("dismissed")
|
||||
expect(transition(hidden, activity(hidden)).effects).toEqual([])
|
||||
const nextRun = transition(hidden, { type: "execution.ended", sessionKey: key }).state
|
||||
expect(types(transition(nextRun, activity(nextRun)).effects)).toEqual(["focus-strip-tab"])
|
||||
const mark = replay([side(true), { ...activity(hidden), opened: true }], hidden).state
|
||||
const mark = replay([side(true), { ...activity(hidden), reveal: "pane", opened: true }], hidden).state
|
||||
expect(attachment(mark)?.unseen).toEqual([tabA])
|
||||
expect(attachment(transition(mark, { type: "activity.seen", sessionKey: key, tabID: tabA }).state)?.unseen).toEqual([])
|
||||
})
|
||||
|
||||
// The person opens the side panel to look at something of their own, closes it, and only then does the agent ask to
|
||||
// show its first page: closing that panel was no answer to the agent.
|
||||
test("closing a pane that showed nothing of the agent's keeps its first show request", () => {
|
||||
const start = ready()
|
||||
const closed = replay([side(true), side(false)], start).state
|
||||
expect(attachment(closed)?.side).toBe("closed")
|
||||
expect(types(transition(closed, activity(closed)).effects)).toEqual(["focus-strip-tab"])
|
||||
})
|
||||
|
||||
test("closing a pane in which the agent worked on the visible tab is a dismissal", () => {
|
||||
const start = ready()
|
||||
|
||||
const hidden = replay(
|
||||
[side(true), { ...activity(start), reveal: "none", opened: true, visible: true }, side(false)],
|
||||
start,
|
||||
).state
|
||||
|
||||
expect(attachment(hidden)?.side).toBe("dismissed")
|
||||
expect(transition(hidden, activity(hidden)).effects).toEqual([])
|
||||
})
|
||||
|
||||
test("a show request that arrives before its tab's inventory lands with it, after the strip has the tab", () => {
|
||||
const start = ready()
|
||||
const early = transition(start, { ...activity(start), tabID: tabB })
|
||||
expect(early.effects).toEqual([])
|
||||
const landed = transition(early.state, paneState(early.state, inventory(tab(tabA), tab(tabB))))
|
||||
|
||||
expect(landed.effects).toEqual([
|
||||
{ type: "sync-strip", sessionKey: key, keep: [tabA, tabB], open: [tabB] },
|
||||
{ type: "record-history", sessionKey: key },
|
||||
{ type: "focus-strip-tab", sessionKey: key, tabID: tabB },
|
||||
])
|
||||
expect(revealGuard(landed.state, key, tabB)).toBeDefined()
|
||||
// It lands once.
|
||||
expect(types(transition(landed.state, paneState(landed.state, inventory(tab(tabA), tab(tabB)))).effects)).not.toContain("focus-strip-tab")
|
||||
})
|
||||
|
||||
test("a show request that arrives before the strip can be written lands when it can", () => {
|
||||
const start = replay(attach(key, false)).state
|
||||
const listed = transition(start, paneState(start, inventory(tab(tabA)))).state
|
||||
const early = transition(listed, activity(listed))
|
||||
expect(early.effects).toEqual([])
|
||||
const located = transition(early.state, { type: "session.located", sessionKey: key, located: true })
|
||||
|
||||
expect(located.effects).toEqual([
|
||||
{ type: "sync-strip", sessionKey: key, keep: [tabA], open: [tabA] },
|
||||
{ type: "focus-strip-tab", sessionKey: key, tabID: tabA },
|
||||
])
|
||||
expect(revealGuard(located.state, key, tabA)).toBeDefined()
|
||||
})
|
||||
|
||||
test("a newer request replaces a kept one, and a kept mark lands as a mark", () => {
|
||||
const start = ready()
|
||||
|
||||
const kept = replay(
|
||||
[{ ...activity(start), tabID: tabB }, { ...activity(start), tabID: tabC, reveal: "none" }],
|
||||
start,
|
||||
).state
|
||||
|
||||
const landed = transition(kept, paneState(kept, inventory(tab(tabA), tab(tabB), tab(tabC))))
|
||||
expect(types(landed.effects)).not.toContain("focus-strip-tab")
|
||||
expect(attachment(landed.state)?.unseen).toEqual([tabC])
|
||||
})
|
||||
|
||||
test("only the newly revealed page is held back, and an old timer cannot expose it", () => {
|
||||
const start = ready()
|
||||
const reveal = transition(start, activity(start)).state
|
||||
|
|
@ -167,13 +243,25 @@ describe("browser pane machine", () => {
|
|||
expect(revealGuard(next.state, key, tabA) !== undefined).toBe(guarded)
|
||||
})
|
||||
|
||||
test("starting with a closed pane does not dismiss the run; file previews use the same rule without replay", () => {
|
||||
test.each([
|
||||
["the pane closed", {}, true],
|
||||
["another tab selected in the open pane", { opened: true }, true],
|
||||
["the setting turned off", { enabled: false }, false],
|
||||
["no room beside the chat", { room: false }, false],
|
||||
] as const)("a file preview is selected with %s, and starting with a closed pane does not dismiss the run", (_label, input, select) => {
|
||||
const start = ready()
|
||||
const observed = transition(start, { type: "side.changed", sessionKey: key, open: false, running: true }).state
|
||||
const file = { ...activity(observed), type: "pane.file" as const, path: "report.pdf" }
|
||||
expect(transition(observed, file).effects).toEqual([{ type: "present-file", sessionKey: key, path: file.path, select: true }])
|
||||
expect(transition(observed, { ...file, opened: true }).effects).toEqual([{ type: "present-file", sessionKey: key, path: file.path, select: false }])
|
||||
expect(transition(observed, { ...file, onScreen: false })).toEqual({ state: observed, effects: [] })
|
||||
const file = { ...activity(observed), type: "pane.file" as const, path: "report.pdf", ...input }
|
||||
expect(transition(observed, file).effects).toEqual([{ type: "present-file", sessionKey: key, path: file.path, select }])
|
||||
})
|
||||
|
||||
test("a file preview follows the person's dismissal, counts as shown, and waits for an off-screen session's file panel", () => {
|
||||
const start = ready()
|
||||
const file = { ...activity(start), type: "pane.file" as const, path: "report.pdf" }
|
||||
expect(transition(start, { ...file, onScreen: false })).toEqual({ state: start, effects: [] })
|
||||
const hidden = replay([file, side(true), side(false)], start).state
|
||||
expect(attachment(hidden)?.side).toBe("dismissed")
|
||||
expect(transition(hidden, file).effects).toEqual([{ type: "present-file", sessionKey: key, path: file.path, select: false }])
|
||||
})
|
||||
|
||||
test.each([
|
||||
|
|
@ -187,6 +275,7 @@ describe("browser pane machine", () => {
|
|||
const changed = (open: boolean): Event => ({ type: "side.changed", sessionKey: key, open, running: true })
|
||||
|
||||
const next = replay([
|
||||
activity(start),
|
||||
changed(true),
|
||||
changed(false),
|
||||
...(author === "user" ? [{ type: "prompt.enqueued" as const, sessionKey: key, id: "msg_1", delivery: enqueued }] : []),
|
||||
|
|
@ -207,6 +296,7 @@ describe("browser pane machine", () => {
|
|||
const changed = (open: boolean): Event => ({ type: "side.changed", sessionKey: key, open, running: true })
|
||||
|
||||
const next = replay([
|
||||
activity(start),
|
||||
changed(true),
|
||||
changed(false),
|
||||
{ type: "prompt.enqueued", sessionKey: key, id: "msg_1", delivery: "queue" },
|
||||
|
|
|
|||
|
|
@ -84,7 +84,21 @@ export type Attachment = {
|
|||
readonly failure: Failure | undefined
|
||||
readonly strip: Strip
|
||||
readonly addressFocus: AddressFocus
|
||||
/**
|
||||
* `dismissed`: the person closed the pane during a run in which it had shown the agent's page (`shown`), so nothing
|
||||
* opens it again until the run ends, their next queued prompt starts, or they open it themselves.
|
||||
*/
|
||||
readonly side: "unobserved" | "open" | "closed" | "dismissed"
|
||||
/**
|
||||
* The pane has shown the agent's page in this run: a show request opened or took the pane, or the agent worked in
|
||||
* the tab the open pane showed. Closing a pane that showed none of that says nothing about the agent's pages.
|
||||
*/
|
||||
readonly shown: boolean
|
||||
/**
|
||||
* What an agent's activity asks of the pane, kept while it cannot be applied: the strip cannot be written yet, or the
|
||||
* inventory that carries the tab has not arrived. It applies once both are there, and a newer one replaces it.
|
||||
*/
|
||||
readonly held?: Presentation
|
||||
readonly unseen: readonly Browser.TabID[]
|
||||
/** The person's prompts that wait in the session's inbox, by inbox ID, with how each will be delivered. */
|
||||
readonly prompts: Readonly<Record<string, "steer" | "queue">>
|
||||
|
|
@ -95,6 +109,18 @@ export type Attachment = {
|
|||
readonly reveal?: { readonly tabID: Browser.TabID; readonly token: number; readonly timing: boolean }
|
||||
}
|
||||
|
||||
/**
|
||||
* What an agent's activity on a tab asks of the pane. `select`: the tab is selected, which opens a closed pane.
|
||||
* `onScreen`: the person sees the session now, so the click guard applies and the tab needs no unseen mark.
|
||||
* `visible`: the open pane already shows the tab.
|
||||
*/
|
||||
export type Presentation = {
|
||||
readonly tabID: Browser.TabID
|
||||
readonly select: boolean
|
||||
readonly onScreen: boolean
|
||||
readonly visible: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Every attachment of this window, which belongs to its shell session tab rather than the route. `issued` is the last
|
||||
* attempt or request id handed out. A Location whose browser RPC is not available blocks only its session.
|
||||
|
|
@ -122,7 +148,11 @@ export type Event =
|
|||
| { readonly type: "reveal.elapsed"; readonly sessionKey: string; readonly token: number }
|
||||
| {
|
||||
readonly type: "pane.activity"
|
||||
readonly reveal: boolean
|
||||
/**
|
||||
* `none`: the tab is only marked. `pane`: a closed pane opens on the tab. `tab`: the tab is selected, in a closed
|
||||
* pane or in an open one that shows another tab (a preview).
|
||||
*/
|
||||
readonly reveal: "none" | "pane" | "tab"
|
||||
readonly room: boolean
|
||||
readonly sessionKey: string
|
||||
readonly attempt: number
|
||||
|
|
@ -462,6 +492,7 @@ function attached(state: Open, event: Extract<Event, { type: "session.attached"
|
|||
strip: { located: event.located, mirrored: [], prune: false, focus: undefined },
|
||||
addressFocus: noFocus(),
|
||||
side: "unobserved",
|
||||
shown: false,
|
||||
unseen: [],
|
||||
prompts: {},
|
||||
})
|
||||
|
|
@ -522,19 +553,25 @@ function session(state: Open, key: string, attachment: Attachment, event: Sessio
|
|||
return put(state, key, {
|
||||
...attachment,
|
||||
side: next ? "closed" : attachment.side,
|
||||
// Their queued prompt is the next run, which has shown nothing yet.
|
||||
shown: event.type === "inbox.delivered" && attachment.prompts[event.id] === "queue" ? false : attachment.shown,
|
||||
prompts: Object.fromEntries(Object.entries(attachment.prompts).filter(([id]) => id !== event.id)),
|
||||
})
|
||||
}
|
||||
|
||||
case "side.changed": {
|
||||
const dismissed = event.running && (attachment.side === "open" || attachment.side === "dismissed")
|
||||
// Closing a pane that showed nothing of the agent's in this run, such as one the person opened to look at
|
||||
// something else, is not an answer to the agent: its next show request still opens the pane.
|
||||
const dismissed = event.running && (attachment.side === "dismissed" || (attachment.side === "open" && attachment.shown))
|
||||
const side = event.open ? "open" : dismissed ? "dismissed" : "closed"
|
||||
|
||||
return side === attachment.side ? { state, effects: [] } : put(state, key, { ...attachment, side, reveal: event.open ? attachment.reveal : undefined })
|
||||
}
|
||||
|
||||
case "execution.ended":
|
||||
return attachment.side === "dismissed" ? put(state, key, { ...attachment, side: "closed" }) : { state, effects: [] }
|
||||
if (attachment.side !== "dismissed" && !attachment.shown) return { state, effects: [] }
|
||||
|
||||
return put(state, key, { ...attachment, side: attachment.side === "dismissed" ? "closed" : attachment.side, shown: false })
|
||||
case "reveal.drawn": {
|
||||
const reveal = attachment.reveal
|
||||
|
||||
|
|
@ -551,27 +588,34 @@ function session(state: Open, key: string, attachment: Attachment, event: Sessio
|
|||
return attachment.unseen.includes(event.tabID)
|
||||
? put(state, key, { ...attachment, unseen: attachment.unseen.filter(id => id !== event.tabID) })
|
||||
: { state, effects: [] }
|
||||
case "pane.file":
|
||||
case "pane.file": {
|
||||
// Only the routed session has a file panel, which holds its own write until the session's location is known.
|
||||
if (!current(phase, event.attempt) || !event.onScreen) return { state, effects: [] }
|
||||
// A file preview is a show request: it takes the pane even when another tab is selected there.
|
||||
const select = event.room && event.enabled && attachment.side !== "dismissed"
|
||||
const effects: MachineEffect[] = [{ type: "present-file", sessionKey: key, path: event.path, select }]
|
||||
|
||||
return select && !attachment.shown ? put(state, key, { ...attachment, shown: true }, effects) : { state, effects }
|
||||
}
|
||||
|
||||
case "pane.activity": {
|
||||
if (!current(phase, event.attempt) || !event.onScreen || !attachment.strip.located)
|
||||
return { state, effects: [] }
|
||||
const select = !event.opened && event.room && event.enabled && attachment.side !== "dismissed" && (event.type === "pane.file" || event.reveal)
|
||||
if (!current(phase, event.attempt)) return { state, effects: [] }
|
||||
|
||||
if (event.type === "pane.file") return { state, effects: [{ type: "present-file", sessionKey: key, path: event.path, select }] }
|
||||
// Off screen only a preview acts: its tab is selected in the session's strip, so it shows when the person returns.
|
||||
if (!event.onScreen && event.reveal !== "tab") return { state, effects: [] }
|
||||
|
||||
if (!attachment.browser?.tabs.some(tab => tab.id === event.tabID)) return { state, effects: [] }
|
||||
const select =
|
||||
event.enabled &&
|
||||
attachment.side !== "dismissed" &&
|
||||
(!event.onScreen || (event.room && (event.reveal === "tab" || (event.reveal === "pane" && !event.opened))))
|
||||
|
||||
if (select) {
|
||||
const token = state.issued + 1
|
||||
|
||||
return put(state, key, { ...attachment, reveal: { token, tabID: event.tabID, timing: false } }, [
|
||||
{ type: "focus-strip-tab", sessionKey: key, tabID: event.tabID },
|
||||
], token)
|
||||
}
|
||||
|
||||
if (event.visible || attachment.unseen.includes(event.tabID)) return { state, effects: [] }
|
||||
|
||||
return put(state, key, { ...attachment, unseen: [...attachment.unseen, event.tabID] })
|
||||
return present(state, key, attachment, {
|
||||
tabID: event.tabID,
|
||||
select,
|
||||
onScreen: event.onScreen,
|
||||
// The strip's selected tab is not on show while its pane is closed.
|
||||
visible: event.onScreen && event.opened && event.visible,
|
||||
})
|
||||
}
|
||||
|
||||
case "session.capability.changed":
|
||||
|
|
@ -694,6 +738,39 @@ function session(state: Open, key: string, attachment: Attachment, event: Sessio
|
|||
}
|
||||
}
|
||||
|
||||
// Applies what an agent's activity asks of the pane, or keeps it until it can be applied: the strip must be writable and
|
||||
// the inventory must carry the tab. Nothing is dropped for arriving first.
|
||||
function present(state: Open, key: string, attachment: Attachment, request: Presentation): Transition {
|
||||
if (!attachment.strip.located || !attachment.browser?.tabs.some((tab) => tab.id === request.tabID))
|
||||
return attachment.held === request ? { state, effects: [] } : put(state, key, { ...attachment, held: request })
|
||||
const settled = { ...attachment, held: undefined }
|
||||
|
||||
// The agent worked in the tab the person is looking at.
|
||||
if (request.visible)
|
||||
return attachment.shown && !attachment.held ? { state, effects: [] } : put(state, key, { ...settled, shown: true })
|
||||
const marked = attachment.unseen.includes(request.tabID) ? attachment.unseen : [...attachment.unseen, request.tabID]
|
||||
|
||||
if (!request.select)
|
||||
return marked === attachment.unseen && !attachment.held ? { state, effects: [] } : put(state, key, { ...settled, unseen: marked })
|
||||
const focus: MachineEffect = { type: "focus-strip-tab", sessionKey: key, tabID: request.tabID }
|
||||
|
||||
// Nobody is looking, so no click can land in the page: the tab waits selected, with its mark.
|
||||
if (!request.onScreen) return put(state, key, { ...settled, unseen: marked }, [focus])
|
||||
const token = state.issued + 1
|
||||
|
||||
return put(state, key, { ...settled, shown: true, reveal: { token, tabID: request.tabID, timing: false } }, [focus], token)
|
||||
}
|
||||
|
||||
// A kept request lands with the state that makes it possible.
|
||||
function settle(result: { readonly state: Open; readonly effects: readonly MachineEffect[] }, key: string): Transition {
|
||||
const attachment = result.state.sessions[key]
|
||||
|
||||
if (!attachment?.held) return result
|
||||
const applied = present(result.state, key, attachment, attachment.held)
|
||||
|
||||
return { state: applied.state, effects: [...result.effects, ...applied.effects] }
|
||||
}
|
||||
|
||||
// Writes held while the session's location was unknown land once the server reports it. A held focus lands only for
|
||||
// a tab the desktop still has.
|
||||
function located(state: Open, key: string, attachment: Attachment, value: boolean): Transition {
|
||||
|
|
@ -705,14 +782,17 @@ function located(state: Open, key: string, attachment: Attachment, value: boolea
|
|||
const ids = attachment.browser?.tabs.map((tab) => tab.id)
|
||||
const focus = strip.focus
|
||||
|
||||
return put(
|
||||
state,
|
||||
return settle(
|
||||
put(
|
||||
state,
|
||||
key,
|
||||
{ ...attachment, strip: { located: true, mirrored: ids ?? [], prune: false, focus: undefined } },
|
||||
[
|
||||
...(ids ? sync(key, ids, strip.mirrored, strip.prune) : []),
|
||||
...(focus && ids?.includes(focus) ? [{ type: "focus-strip-tab" as const, sessionKey: key, tabID: focus }] : []),
|
||||
],
|
||||
),
|
||||
key,
|
||||
{ ...attachment, strip: { located: true, mirrored: ids ?? [], prune: false, focus: undefined } },
|
||||
[
|
||||
...(ids ? sync(key, ids, strip.mirrored, strip.prune) : []),
|
||||
...(focus && ids?.includes(focus) ? [{ type: "focus-strip-tab" as const, sessionKey: key, tabID: focus }] : []),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -902,24 +982,28 @@ function paneState(
|
|||
? moved(attachment, event.state) ? undefined : attachment.failure
|
||||
: { id: state.issued + 1, code: event.error, action: undefined }
|
||||
|
||||
return put(
|
||||
state,
|
||||
// The strip gets the inventory's tabs first, so a kept request selects a tab the strip already has.
|
||||
return settle(
|
||||
put(
|
||||
state,
|
||||
key,
|
||||
{
|
||||
...attachment,
|
||||
phase: { status: "ready", attempt: phase.attempt },
|
||||
browser: event.state,
|
||||
unseen: attachment.unseen.filter(id => event.state?.tabs.some(tab => tab.id === id)),
|
||||
failure,
|
||||
strip: mirrored.strip,
|
||||
addressFocus: follow(attachment.addressFocus, event.state),
|
||||
},
|
||||
[
|
||||
...(phase.status === "registering" ? [{ type: "cancel-register-timeout" as const, sessionKey: key }] : []),
|
||||
...mirrored.effects,
|
||||
...(event.state ? [{ type: "record-history" as const, sessionKey: key }] : []),
|
||||
],
|
||||
failure === attachment.failure ? state.issued : state.issued + 1,
|
||||
),
|
||||
key,
|
||||
{
|
||||
...attachment,
|
||||
phase: { status: "ready", attempt: phase.attempt },
|
||||
browser: event.state,
|
||||
unseen: attachment.unseen.filter(id => event.state?.tabs.some(tab => tab.id === id)),
|
||||
failure,
|
||||
strip: mirrored.strip,
|
||||
addressFocus: follow(attachment.addressFocus, event.state),
|
||||
},
|
||||
[
|
||||
...(phase.status === "registering" ? [{ type: "cancel-register-timeout" as const, sessionKey: key }] : []),
|
||||
...mirrored.effects,
|
||||
...(event.state ? [{ type: "record-history" as const, sessionKey: key }] : []),
|
||||
],
|
||||
failure === attachment.failure ? state.issued : state.issued + 1,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -338,8 +338,9 @@ export function createModel(ctx: SetupContext<typeof definition>) {
|
|||
if (event.type === "focus") return dispatch({ type: "pane.focus", sessionKey, attempt, tabID: event.tabID })
|
||||
|
||||
if (event.type === "activity" || event.type === "preview") {
|
||||
// On screen means the person can see the session now: it is routed, in a window that is neither hidden nor minimized.
|
||||
const presentation = { sessionKey, attempt, enabled: ctx.stores.preferences.value.agentPages !== false,
|
||||
onScreen: sessions.current()?.key === sessionKey, room: !layout.narrow() && builtinContext(ctx).layout.fitsSide(), opened: layout.side.opened(drive.ref) }
|
||||
onScreen: sessions.current()?.key === sessionKey && document.visibilityState === "visible", room: !layout.narrow() && builtinContext(ctx).layout.fitsSide(), opened: layout.side.opened(drive.ref) }
|
||||
|
||||
if (event.type === "preview") return dispatch({ ...presentation, type: "pane.file", path: event.path })
|
||||
|
||||
|
|
|
|||
|
|
@ -877,7 +877,7 @@ export function createBrowserPane(input: {
|
|||
const popup = create(binding, { initialize: false, popupOptions, activity, opener: id })
|
||||
|
||||
if (activityOwner(activity) === "agent") {
|
||||
announce(binding, popup.state().id, false, !background)
|
||||
announce(binding, popup.state().id, "none", !background)
|
||||
|
||||
return popup.contents
|
||||
}
|
||||
|
|
@ -979,12 +979,12 @@ export function createBrowserPane(input: {
|
|||
}
|
||||
|
||||
/** Reports the page's state after a command, which may have changed it without a page event yet. */
|
||||
function announce(binding: string, tabID: Browser.TabID, reveal: boolean, active: boolean) {
|
||||
function announce(binding: string, tabID: Browser.TabID, reveal: "none" | "pane" | "tab", active: boolean) {
|
||||
if (active) dispatchBinding(binding, { type: "tab.active", tabID })
|
||||
const handle = handles.get(binding)
|
||||
|
||||
if (handle && !handle.win.isDestroyed() && handle.win.isVisible() && !handle.win.isMinimized())
|
||||
emit(binding, { type: "activity", tabID, reveal: reveal && !handle.background.has(tabID) })
|
||||
// A hidden or minimized window hears it too: its model selects the tab, so the page shows when the person returns.
|
||||
if (handle) emit(binding, { type: "activity", tabID, reveal: handle.background.has(tabID) ? "none" : reveal })
|
||||
}
|
||||
|
||||
function refresh(binding: string, tabID: Browser.TabID, page: BrowserPage) {
|
||||
|
|
@ -997,7 +997,7 @@ export function createBrowserPane(input: {
|
|||
async function execute(binding: string, command: Browser.Command, signal: AbortSignal, origin: "agent" | "user", intent: "present" | "new" = "new", inherited?: TabActivity, created?: (id: Browser.TabID) => void): Promise<Browser.Result> {
|
||||
const action = command.action
|
||||
|
||||
const present = (tabID: Browser.TabID, reveal = false, active = true) => {
|
||||
const present = (tabID: Browser.TabID, reveal: "none" | "pane" | "tab" = "none", active = true) => {
|
||||
if (origin === "user") return dispatchBinding(binding, { type: "tab.focused", tabID })
|
||||
announce(binding, tabID, reveal, active)
|
||||
}
|
||||
|
|
@ -1054,7 +1054,8 @@ export function createBrowserPane(input: {
|
|||
if (!existing) opening.defer(() => { if (page(binding, tabID) === tab) dispatchBinding(binding, { type: "tab.closed", tabID }) })
|
||||
await tab.execute({ action: { type: "navigate", tabID, url }, files: [] }, signal, origin)
|
||||
refresh(binding, tabID, tab)
|
||||
present(tabID, true)
|
||||
// A preview means "show this to the person": it takes the pane even when another tab is selected there.
|
||||
present(tabID, "tab")
|
||||
opening.move()
|
||||
|
||||
return { value: { path: action.path, tabID, url: tab.state().url }, files: [] }
|
||||
|
|
@ -1119,7 +1120,7 @@ export function createBrowserPane(input: {
|
|||
await opened.execute({ action: { type: "navigate", tabID, url: action.url }, files: [] }, signal, origin)
|
||||
refresh(binding, tabID, opened)
|
||||
|
||||
if (origin === "agent") present(tabID, action.focus === true, action.focus !== false)
|
||||
if (origin === "agent") present(tabID, action.focus === true ? "pane" : "none", action.focus !== false)
|
||||
opening.move()
|
||||
|
||||
return { value: opened.state(), files: [] }
|
||||
|
|
@ -1171,7 +1172,7 @@ export function createBrowserPane(input: {
|
|||
const result = await target.execute(command, signal, origin)
|
||||
refresh(binding, action.tabID, target)
|
||||
|
||||
if (origin === "agent" && action.type === "navigate") present(action.tabID, false, false)
|
||||
if (origin === "agent" && action.type === "navigate") present(action.tabID, "none", false)
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1592,7 +1592,7 @@ export function mountBrowserRegion(input: RegionHost) {
|
|||
<button onClick={() => {
|
||||
const binding = latest()?.binding
|
||||
|
||||
if (binding) listeners.forEach(listener => listener({ binding, event: { type: "activity", tabID, reveal: true } }))
|
||||
if (binding) listeners.forEach(listener => listener({ binding, event: { type: "activity", tabID, reveal: "pane" } }))
|
||||
}}>Agent show request</button>
|
||||
<output>Plugin closed: {apiResult()}</output>
|
||||
<button
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue