mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(app): show a prompt sent while agents and models load in the timeline at once (#62025)
This commit is contained in:
committed by
GitHub
Unverified
parent
926b2af0cc
commit
6bd47192ac
@@ -170,6 +170,7 @@ async function openQueue(
|
||||
revert?: string,
|
||||
status: "idle" | "running" = "running",
|
||||
model = { id: "queue-model", name: "Queue Model" },
|
||||
config: Pick<MockServerConfig, "beforeAgentsResponse"> = {},
|
||||
) {
|
||||
const options: Parameters<typeof openSession>[1] = {
|
||||
name: "SessionQueueRegression",
|
||||
@@ -191,6 +192,7 @@ async function openQueue(
|
||||
onBackground: mock.onBackground,
|
||||
shellCommands: () => mock.shells,
|
||||
events: mock.events,
|
||||
...config,
|
||||
}
|
||||
|
||||
if (followUpBehavior) options.seed = { settings: { general: { followUpBehavior } } }
|
||||
@@ -339,6 +341,37 @@ test("a steer shows as pending in the timeline as the composer clears, before th
|
||||
await expect(prompt.locator('[data-component="user-message"]')).toHaveAttribute("data-pending", "true")
|
||||
})
|
||||
|
||||
test("a prompt sent while the session's agents and models load shows as pending at once and sends once they load", async ({
|
||||
page,
|
||||
}) => {
|
||||
const mock = createQueueMock(
|
||||
[],
|
||||
[{ id: "msg_queue_delivered", type: "user", text: "First prompt", time: { created: 1 } }],
|
||||
)
|
||||
|
||||
// The Location's agents load only once released, so the composer has no agent or model to send with yet.
|
||||
const agents = Promise.withResolvers<void>()
|
||||
|
||||
const view = await openQueue(page, mock, "steer", undefined, "idle", undefined, {
|
||||
beforeAgentsResponse: () => agents.promise,
|
||||
})
|
||||
|
||||
const prompt = page.locator('[data-timeline-virtual-content] [data-timeline-row="UserMessage"]', {
|
||||
hasText: "read the deploy logs",
|
||||
})
|
||||
|
||||
await expect(userRow(page, "msg_queue_delivered")).toContainText("First prompt")
|
||||
await view.input.fill("read the deploy logs")
|
||||
await view.input.press("Enter")
|
||||
await expect(prompt.locator('[data-component="user-message"]')).toHaveAttribute("data-pending", "true")
|
||||
await expect(view.input).toHaveText("")
|
||||
expect(mock.prompts).toEqual([])
|
||||
|
||||
agents.resolve()
|
||||
await expect.poll(() => mock.prompts.map((item) => item.text)).toEqual(["read the deploy logs"])
|
||||
await expect(prompt).toHaveCount(1)
|
||||
})
|
||||
|
||||
for (const row of [
|
||||
{ case: "a missed admission echo", reconnect: false },
|
||||
{ case: "an event stream reconnect", reconnect: true },
|
||||
|
||||
@@ -93,6 +93,7 @@ export interface MockServerConfig {
|
||||
// `directory` is the requested `location[directory]`, such as an untracked folder the review opened.
|
||||
vcsDiff?: unknown[] | ((input: { mode?: string; directory: string }) => unknown[])
|
||||
beforeMessagesResponse?: (input: { sessionID: string; before?: string }) => Promise<void>
|
||||
beforeAgentsResponse?: () => Promise<void>
|
||||
onMessages?: (input: { sessionID: string; before?: string; phase: "start" | "end" }) => void
|
||||
message?: (sessionID: string, messageID: string) => SessionMessageInfo | undefined
|
||||
onMessage?: (input: { sessionID: string; messageID: string }) => void
|
||||
@@ -777,20 +778,23 @@ function mockHandlers(
|
||||
}),
|
||||
config: () => Effect.succeed(configEntries),
|
||||
reference: () => Effect.succeed({ location: location(config), data: [] }),
|
||||
// `beforeAgentsResponse` holds the Location's agent list, as a cold Location does while its plugins activate.
|
||||
agent: (ctx) =>
|
||||
Effect.succeed({
|
||||
location: location(config, requestDirectory(config, ctx.request)),
|
||||
data: [
|
||||
{
|
||||
id: "build",
|
||||
name: "Build",
|
||||
mode: "primary",
|
||||
hidden: false,
|
||||
request: { settings: {}, headers: {}, body: {} },
|
||||
permissions: [],
|
||||
},
|
||||
],
|
||||
}),
|
||||
Effect.promise(async () => config.beforeAgentsResponse?.()).pipe(
|
||||
Effect.as({
|
||||
location: location(config, requestDirectory(config, ctx.request)),
|
||||
data: [
|
||||
{
|
||||
id: "build",
|
||||
name: "Build",
|
||||
mode: "primary",
|
||||
hidden: false,
|
||||
request: { settings: {}, headers: {}, body: {} },
|
||||
permissions: [],
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
provider: () =>
|
||||
Effect.succeed({ location: location(config), data: currentProviders(resolve(config.provider)) }),
|
||||
model: () => Effect.succeed({ location: location(config), data: currentModels(resolve(config.provider)) }),
|
||||
|
||||
@@ -56,9 +56,11 @@ export type ComposerQueue = {
|
||||
export type ComposerSession = {
|
||||
id: string
|
||||
directory: string
|
||||
// The timeline's optimistic prompt: shown on `set`, held after `settle` until its admission echo, removed on `clear`.
|
||||
// The timeline's optimistic prompt: shown on `set` (or `hold` while the send waits for the Location's agents and models),
|
||||
// held after `settle` until its admission echo, removed on `clear`.
|
||||
handoff: {
|
||||
set: (handoff: SessionMessageHandoff) => void
|
||||
hold: (handoff: SessionMessageHandoff) => void
|
||||
settle: (messageID: string) => void
|
||||
clear: (messageID: string) => void
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ const image: ImageAttachmentPart = {
|
||||
const session: ComposerSession = {
|
||||
id: "session-1",
|
||||
directory: "C:/repo",
|
||||
handoff: { set() {}, settle() {}, clear() {} },
|
||||
handoff: { set() {}, hold() {}, settle() {}, clear() {} },
|
||||
api: {
|
||||
command: async () => undefined,
|
||||
shell: async () => undefined,
|
||||
@@ -81,6 +81,7 @@ function snapshot(
|
||||
commands: [],
|
||||
clientCommand: undefined,
|
||||
comments: [],
|
||||
session: undefined,
|
||||
...input,
|
||||
}
|
||||
}
|
||||
@@ -121,6 +122,7 @@ const started = (attempt: number): ComposerSubmitEvent => ({
|
||||
|
||||
const states = {
|
||||
held: replay([{ type: "submit", snapshot: snapshot({ selection: undefined, loading: true }), done }]).state,
|
||||
shown: replay([{ type: "submit", snapshot: snapshot({ selection: undefined, loading: true, session }), done }]).state,
|
||||
running: replay([{ type: "submit", snapshot: snapshot({ clientCommand: () => undefined }), done }]).state,
|
||||
preparing: replay([{ type: "submit", snapshot: snapshot(), done }]).state,
|
||||
"handing-off": replay([{ type: "submit", snapshot: snapshot(), done }, started(1)]).state,
|
||||
@@ -202,7 +204,7 @@ describe("composer submit machine", () => {
|
||||
test("holds a send while the Location loads, until stopped, edited, unmounted or loaded", () => {
|
||||
const held = states.held
|
||||
|
||||
expect(held).toMatchObject({ type: "held", attempt: 1, draft: JSON.stringify(snapshot().draft.prompt) })
|
||||
expect(held).toMatchObject({ type: "held", attempt: 1, shown: undefined })
|
||||
expect(composerSubmitView(held)).toEqual({ held: true, busy: true, canSubmit: false })
|
||||
|
||||
const cancelled: ComposerSubmitTransition = {
|
||||
@@ -213,7 +215,7 @@ describe("composer submit machine", () => {
|
||||
expect(transitionComposerSubmit(held, { type: "stop" })).toEqual(cancelled)
|
||||
expect(transitionComposerSubmit(held, { type: "unmounted" })).toEqual(cancelled)
|
||||
expect(transitionComposerSubmit(held, { type: "hold.changed", attempt: 1 })).toEqual(cancelled)
|
||||
expect(transitionComposerSubmit(held, { type: "hold.loaded", attempt: 1 })).toEqual({
|
||||
expect(transitionComposerSubmit(held, { type: "hold.loaded", attempt: 1, selection, commands: [] })).toEqual({
|
||||
state: { type: "idle", attempt: 1 },
|
||||
effects: [{ type: "submit.retry", alternate: false, done }],
|
||||
})
|
||||
@@ -229,12 +231,109 @@ describe("composer submit machine", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("a prompt held while a Session's Location loads shows in its timeline at once and sends once it loads", () => {
|
||||
const held = snapshot({ selection: undefined, loading: true, session })
|
||||
const cleared: Prompt = [{ type: "text", content: "", start: 0, end: 0 }]
|
||||
|
||||
// Enter shows the prompt and clears the composer before the agents and models load, with no request in flight.
|
||||
const shown = replay([
|
||||
{ type: "submit", snapshot: held, done },
|
||||
{ type: "hold.cleared", attempt: 1, cleared },
|
||||
// A new draft typed meanwhile is the user's, so it no longer cancels the send.
|
||||
{ type: "hold.changed", attempt: 1 },
|
||||
])
|
||||
|
||||
expect(shown.effects).toEqual([{ type: "hold.show", attempt: 1, session, snapshot: held }])
|
||||
expect(shown.state).toMatchObject({ type: "held", attempt: 1, shown: { session, cleared } })
|
||||
expect(composerSubmitView(shown.state)).toEqual({ held: true, busy: true, canSubmit: false })
|
||||
|
||||
const sent = replay(
|
||||
[
|
||||
{ type: "hold.loaded", attempt: 1, selection, commands: [{ name: "review" }] },
|
||||
started(1),
|
||||
{ type: "handoff.ready", attempt: 1, prompt: undefined },
|
||||
],
|
||||
shown.state,
|
||||
)
|
||||
|
||||
// The send keeps the shown message's ID, records no second history entry, and leaves the new draft alone.
|
||||
expect(sent.effects.map((effect) => effect.type)).toEqual(["session.start", "handoff", "composer.clear", "done"])
|
||||
expect(sent.effects[0]).toMatchObject({ value: { id: held.id, selection, text: "ship it" } })
|
||||
expect(sent.effects[2]).toMatchObject({ type: "composer.clear", cleared, value: { id: held.id } })
|
||||
expect(sent.effects[3]).toEqual({ type: "done", done, sent: true })
|
||||
})
|
||||
|
||||
test.each([
|
||||
{ name: "Stop", event: { type: "stop" } },
|
||||
{ name: "unmounting", event: { type: "unmounted" } },
|
||||
] satisfies { name: string; event: ComposerSubmitEvent }[])(
|
||||
"$name cancels a shown hold and returns its prompt to the composer",
|
||||
(row) => {
|
||||
const held = snapshot({ selection: undefined, loading: true, session })
|
||||
const cleared: Prompt = [{ type: "text", content: "", start: 0, end: 0 }]
|
||||
|
||||
const result = replay([
|
||||
{ type: "submit", snapshot: held, done },
|
||||
{ type: "hold.cleared", attempt: 1, cleared },
|
||||
row.event,
|
||||
{ type: "hold.loaded", attempt: 1, selection, commands: [] },
|
||||
])
|
||||
|
||||
expect(result.state).toEqual({ type: "idle", attempt: 1 })
|
||||
expect(result.effects.slice(1)).toEqual([
|
||||
{ type: "hold.cancel", session, snapshot: held, cleared },
|
||||
{ type: "done", done, sent: false },
|
||||
])
|
||||
},
|
||||
)
|
||||
|
||||
test("a shown hold whose Location loads without a model returns its prompt and asks for one", () => {
|
||||
const held = snapshot({ selection: undefined, loading: true, session })
|
||||
|
||||
const result = replay([
|
||||
{ type: "submit", snapshot: held, done },
|
||||
{ type: "hold.loaded", attempt: 1, selection: undefined, commands: [] },
|
||||
])
|
||||
|
||||
expect(result.state).toEqual({ type: "idle", attempt: 1 })
|
||||
expect(result.effects.slice(1)).toEqual([
|
||||
{ type: "notify.missing-selection" },
|
||||
{ type: "hold.cancel", session, snapshot: held, cleared: undefined },
|
||||
{ type: "done", done, sent: false },
|
||||
])
|
||||
})
|
||||
|
||||
test.each([
|
||||
{ name: "a slash command", input: { text: "/review" } },
|
||||
{ name: "a shell command", input: { mode: "shell" } },
|
||||
{ name: "a queued prompt", input: { delivery: "queue" } },
|
||||
{ name: "a new-session draft", input: { session: undefined } },
|
||||
] satisfies { name: string; input: Partial<SubmitSnapshot> }[])(
|
||||
"$name held while the Location loads waits in the composer",
|
||||
(row) => {
|
||||
const result = replay([
|
||||
{ type: "submit", snapshot: snapshot({ selection: undefined, loading: true, session, ...row.input }), done },
|
||||
])
|
||||
|
||||
expect(result).toMatchObject({ state: { type: "held", shown: undefined }, effects: [] })
|
||||
},
|
||||
)
|
||||
|
||||
test.each([
|
||||
{
|
||||
name: "a late load after Stop",
|
||||
events: [{ type: "stop" }, { type: "hold.loaded", attempt: 1 }],
|
||||
events: [{ type: "stop" }, { type: "hold.loaded", attempt: 1, selection, commands: [] }],
|
||||
from: "held",
|
||||
},
|
||||
{
|
||||
name: "a late clear or load after a shown hold is stopped",
|
||||
events: [
|
||||
{ type: "stop" },
|
||||
{ type: "hold.cleared", attempt: 1, cleared: [] },
|
||||
{ type: "hold.loaded", attempt: 1, selection, commands: [] },
|
||||
],
|
||||
from: "shown",
|
||||
},
|
||||
{
|
||||
name: "a start after an aborted one",
|
||||
events: [{ type: "submit.aborted", attempt: 1 }, started(1)],
|
||||
|
||||
@@ -45,13 +45,19 @@ export type PromptSend = { settled: (restore: () => boolean) => Promise<boolean>
|
||||
/** Settles the caller of `submit` or `submitQuote`; `sent` is false when nothing was sent. */
|
||||
export type SubmitDone = (sent: boolean) => void
|
||||
|
||||
/** A held prompt that already shows in its Session's timeline; `cleared` is the composer it left, once cleared. */
|
||||
export type ShownHold = { session: ComposerSession; cleared: Prompt | undefined }
|
||||
|
||||
export type ComposerSubmitState =
|
||||
| { type: "idle"; attempt: number }
|
||||
// A send pressed while a cold Location loads its agents and models; it goes through once they load.
|
||||
| { type: "held"; attempt: number; draft: string; alternate: boolean; done: SubmitDone }
|
||||
// A send pressed while a cold Location loads its agents and models; it goes through once they load. A prompt to a
|
||||
// Session shows in its timeline at once and leaves the composer (`shown`); any other send waits in the composer,
|
||||
// where an edit cancels it.
|
||||
| { type: "held"; attempt: number; snapshot: SubmitSnapshot; shown: ShownHold | undefined; done: SubmitDone }
|
||||
// A client command or a quote runs; neither takes the draft, but the composer submits nothing else meanwhile.
|
||||
| { type: "running"; attempt: number; done: SubmitDone }
|
||||
// Image attachments resolve and, for a new Session, the Session starts. Nothing is sent yet.
|
||||
// Image attachments resolve and, for a new Session, the Session starts. Nothing is sent yet. `cleared` is the
|
||||
// composer a shown hold already cleared.
|
||||
| {
|
||||
type: "preparing"
|
||||
attempt: number
|
||||
@@ -59,6 +65,7 @@ export type ComposerSubmitState =
|
||||
value: ComposerSubmission
|
||||
kind: SubmissionKind
|
||||
comments: PromptHistoryComment[]
|
||||
cleared: Prompt | undefined
|
||||
done: SubmitDone
|
||||
}
|
||||
// The Session exists and a prompt is in flight; the draft stays until the Session's composer is ready to clear.
|
||||
@@ -69,6 +76,7 @@ export type ComposerSubmitState =
|
||||
value: ComposerSubmission
|
||||
kind: SubmissionKind
|
||||
comments: PromptHistoryComment[]
|
||||
cleared: Prompt | undefined
|
||||
session: ComposerSession
|
||||
done: SubmitDone
|
||||
}
|
||||
@@ -88,6 +96,8 @@ export type SubmitSnapshot = {
|
||||
commands: readonly { name: string }[] | undefined
|
||||
clientCommand: (() => void | Promise<void>) | undefined
|
||||
comments: PromptHistoryComment[]
|
||||
/** The active Session, whose timeline can show a held prompt; a new-session draft has none yet. */
|
||||
session: ComposerSession | undefined
|
||||
}
|
||||
|
||||
export type QuoteSnapshot = {
|
||||
@@ -106,7 +116,14 @@ export type ComposerSubmitEvent =
|
||||
| { type: "stop" }
|
||||
| { type: "unmounted" }
|
||||
| { type: "hold.changed"; attempt: number }
|
||||
| { type: "hold.loaded"; attempt: number }
|
||||
| { type: "hold.cleared"; attempt: number; cleared: Prompt }
|
||||
/** The Location's agents and models loaded; `selection` is what the composer resolved from them. */
|
||||
| {
|
||||
type: "hold.loaded"
|
||||
attempt: number
|
||||
selection: ComposerSelection | undefined
|
||||
commands: readonly { name: string }[] | undefined
|
||||
}
|
||||
| { type: "run.settled"; attempt: number; sent: boolean }
|
||||
| {
|
||||
type: "session.started"
|
||||
@@ -126,6 +143,10 @@ export type ComposerSubmitEffect =
|
||||
| { type: "notify.unqueueable" }
|
||||
| { type: "interrupt" }
|
||||
| { type: "submit.retry"; alternate: boolean; done: SubmitDone }
|
||||
/** Shows a held prompt in its Session's timeline and clears the composer it came from. */
|
||||
| { type: "hold.show"; attempt: number; session: ComposerSession; snapshot: SubmitSnapshot }
|
||||
/** Removes a cancelled held prompt from the timeline and returns it to the composer it left. */
|
||||
| { type: "hold.cancel"; session: ComposerSession; snapshot: SubmitSnapshot; cleared: Prompt | undefined }
|
||||
| { type: "command.run"; attempt: number; prompt: Prompt; run: () => void | Promise<void> }
|
||||
| {
|
||||
type: "quote.send"
|
||||
@@ -162,6 +183,8 @@ export type ComposerSubmitEffect =
|
||||
comments: PromptHistoryComment[]
|
||||
session: ComposerSession
|
||||
prompt: PromptSend | undefined
|
||||
/** Set when a shown hold already cleared the composer, which may hold a new draft by now. */
|
||||
cleared: Prompt | undefined
|
||||
}
|
||||
|
||||
export type ComposerSubmitTransition = { state: ComposerSubmitState; effects: ComposerSubmitEffect[] }
|
||||
@@ -180,21 +203,40 @@ export function transitionComposerSubmit(
|
||||
|
||||
// Stopping a held send cancels it and leaves the prompt in the composer.
|
||||
if (event.type === "stop")
|
||||
return state.type === "held" ? settle(state, false, []) : { state, effects: [{ type: "interrupt" }] }
|
||||
return state.type === "held" ? cancelHold(state, []) : { state, effects: [{ type: "interrupt" }] }
|
||||
|
||||
// A promoted new-session composer unmounts while its first prompt hands off, so only a held send ends here.
|
||||
if (event.type === "unmounted") return state.type === "held" ? settle(state, false, []) : unchanged(state)
|
||||
if (event.type === "unmounted") return state.type === "held" ? cancelHold(state, []) : unchanged(state)
|
||||
|
||||
// Only a prompt still in the composer cancels on an edit; a shown one left it, so the composer holds a new draft.
|
||||
if (event.type === "hold.changed")
|
||||
return current(state, "held", event.attempt) ? settle(state, false, []) : unchanged(state)
|
||||
return current(state, "held", event.attempt) && !state.shown ? settle(state, false, []) : unchanged(state)
|
||||
|
||||
if (event.type === "hold.cleared") {
|
||||
if (!current(state, "held", event.attempt) || !state.shown) return unchanged(state)
|
||||
|
||||
return { state: { ...state, shown: { ...state.shown, cleared: event.cleared } }, effects: [] }
|
||||
}
|
||||
|
||||
if (event.type === "hold.loaded") {
|
||||
if (!current(state, "held", event.attempt)) return unchanged(state)
|
||||
|
||||
return {
|
||||
state: { type: "idle", attempt: state.attempt },
|
||||
effects: [{ type: "submit.retry", alternate: state.alternate, done: state.done }],
|
||||
}
|
||||
if (!state.shown)
|
||||
return {
|
||||
state: { type: "idle", attempt: state.attempt },
|
||||
effects: [{ type: "submit.retry", alternate: state.snapshot.alternate, done: state.done }],
|
||||
}
|
||||
|
||||
// The composer already cleared, so the send goes on from what was captured at Enter.
|
||||
if (!event.selection) return cancelHold(state, [{ type: "notify.missing-selection" }])
|
||||
|
||||
return prepare(
|
||||
state.attempt,
|
||||
{ ...state.snapshot, selection: event.selection, commands: event.commands, loading: false },
|
||||
event.selection,
|
||||
state.done,
|
||||
state.shown.cleared,
|
||||
)
|
||||
}
|
||||
|
||||
if (event.type === "run.settled") {
|
||||
@@ -210,7 +252,8 @@ export function transitionComposerSubmit(
|
||||
return {
|
||||
state: { ...state, type: "handing-off", value, session: event.session },
|
||||
effects: [
|
||||
{ type: "history.record", prompt: value.prompt, mode: value.mode },
|
||||
// A shown hold recorded it when it left the composer.
|
||||
...(state.cleared ? [] : [{ type: "history.record" as const, prompt: value.prompt, mode: value.mode }]),
|
||||
{
|
||||
type: "handoff",
|
||||
attempt: state.attempt,
|
||||
@@ -254,6 +297,7 @@ export function transitionComposerSubmit(
|
||||
comments: state.comments,
|
||||
session: state.session,
|
||||
prompt: event.prompt,
|
||||
cleared: state.cleared,
|
||||
},
|
||||
])
|
||||
}
|
||||
@@ -286,11 +330,16 @@ function submit(state: ComposerSubmitState, snapshot: SubmitSnapshot, done: Subm
|
||||
|
||||
if (!snapshot.selection) {
|
||||
// A cold Location lists its agents and models only after its plugins activate, so hold the send until then.
|
||||
if (snapshot.loading)
|
||||
if (snapshot.loading) {
|
||||
// A prompt that steers a Session shows in its timeline at once, like any sent prompt. A slash command, a shell
|
||||
// command or a queued prompt has no timeline row before the server takes it, so it waits in the composer.
|
||||
const session = snapshot.session && showsWhileHeld(snapshot) ? snapshot.session : undefined
|
||||
|
||||
return {
|
||||
state: { type: "held", attempt, draft: snapshot.serialized, alternate: snapshot.alternate, done },
|
||||
effects: [],
|
||||
state: { type: "held", attempt, snapshot, shown: session && { session, cleared: undefined }, done },
|
||||
effects: session ? [{ type: "hold.show", attempt, session, snapshot }] : [],
|
||||
}
|
||||
}
|
||||
|
||||
return { state, effects: [{ type: "notify.missing-selection" }, { type: "done", done, sent: false }] }
|
||||
}
|
||||
@@ -299,6 +348,16 @@ function submit(state: ComposerSubmitState, snapshot: SubmitSnapshot, done: Subm
|
||||
if (snapshot.mode === "shell" && snapshot.delivery === "queue")
|
||||
return { state, effects: [{ type: "notify.unqueueable" }, { type: "done", done, sent: false }] }
|
||||
|
||||
return prepare(attempt, snapshot, snapshot.selection, done, undefined)
|
||||
}
|
||||
|
||||
function prepare(
|
||||
attempt: number,
|
||||
snapshot: SubmitSnapshot,
|
||||
selection: ComposerSelection,
|
||||
done: SubmitDone,
|
||||
cleared: Prompt | undefined,
|
||||
): ComposerSubmitTransition {
|
||||
// Capture command intent before starting a session in a worktree whose catalog has not loaded.
|
||||
const command = snapshot.mode === "normal" ? findCommand(snapshot.commands, snapshot.text) : undefined
|
||||
|
||||
@@ -311,7 +370,7 @@ function submit(state: ComposerSubmitState, snapshot: SubmitSnapshot, done: Subm
|
||||
context: snapshot.draft.context,
|
||||
text: snapshot.text,
|
||||
images: snapshot.draft.prompt.filter((part): part is ImageAttachmentPart => part.type === "image"),
|
||||
selection: snapshot.selection,
|
||||
selection,
|
||||
delivery: snapshot.delivery,
|
||||
}
|
||||
|
||||
@@ -322,11 +381,34 @@ function submit(state: ComposerSubmitState, snapshot: SubmitSnapshot, done: Subm
|
||||
}
|
||||
|
||||
return {
|
||||
state: { type: "preparing", attempt, draft: snapshot.draft, value, kind, comments: snapshot.comments, done },
|
||||
state: {
|
||||
type: "preparing",
|
||||
attempt,
|
||||
draft: snapshot.draft,
|
||||
value,
|
||||
kind,
|
||||
comments: snapshot.comments,
|
||||
cleared,
|
||||
done,
|
||||
},
|
||||
effects: [{ type: "session.start", attempt, target: snapshot.draft.target, value }],
|
||||
}
|
||||
}
|
||||
|
||||
function showsWhileHeld(snapshot: SubmitSnapshot) {
|
||||
return snapshot.mode === "normal" && snapshot.delivery === "steer" && !parseSlashCommand(snapshot.text)
|
||||
}
|
||||
|
||||
// A shown hold returns its prompt to the composer it left and removes it from the timeline.
|
||||
function cancelHold(state: Extract<ComposerSubmitState, { type: "held" }>, effects: ComposerSubmitEffect[]) {
|
||||
if (!state.shown) return settle(state, false, effects)
|
||||
|
||||
return settle(state, false, [
|
||||
...effects,
|
||||
{ type: "hold.cancel", session: state.shown.session, snapshot: state.snapshot, cleared: state.shown.cleared },
|
||||
])
|
||||
}
|
||||
|
||||
function quote(state: ComposerSubmitState, snapshot: QuoteSnapshot, done: SubmitDone): ComposerSubmitTransition {
|
||||
if (state.type !== "idle" || !snapshot.quote) return { state, effects: [{ type: "done", done, sent: false }] }
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ function session(input: {
|
||||
id: `session-${++sessions.count}`,
|
||||
background: input.background,
|
||||
directory: "C:/repo",
|
||||
handoff: input.handoff ?? { set() {}, settle() {}, clear() {} },
|
||||
handoff: input.handoff ?? { set() {}, hold() {}, settle() {}, clear() {} },
|
||||
current: input.current ?? (() => undefined),
|
||||
admitted: input.admitted ?? (() => false),
|
||||
api: {
|
||||
@@ -238,7 +238,7 @@ describe("Composer submission", () => {
|
||||
const submission = submitInput({
|
||||
...active(
|
||||
state,
|
||||
session({ calls, handoff: { set: (handoff) => handoffs.push(handoff), settle() {}, clear() {} } }),
|
||||
session({ calls, handoff: { set: (handoff) => handoffs.push(handoff), hold() {}, settle() {}, clear() {} } }),
|
||||
),
|
||||
beforeSubmit: () => calls.push("keep-preview"),
|
||||
})
|
||||
@@ -676,7 +676,7 @@ describe("Composer submission", () => {
|
||||
|
||||
const target = session({
|
||||
calls,
|
||||
handoff: { set: (value) => handoffs.push(value), settle() {}, clear() {} },
|
||||
handoff: { set: (value) => handoffs.push(value), hold() {}, settle() {}, clear() {} },
|
||||
prompt: async (value) => admitted.resolve(value),
|
||||
})
|
||||
|
||||
@@ -707,7 +707,7 @@ describe("Composer submission", () => {
|
||||
const target = session({
|
||||
calls: [],
|
||||
statuses,
|
||||
handoff: { set: (handoff) => handoffs.push(handoff), settle() {}, clear() {} },
|
||||
handoff: { set: (handoff) => handoffs.push(handoff), hold() {}, settle() {}, clear() {} },
|
||||
switchModel: async () => committed.promise,
|
||||
})
|
||||
|
||||
@@ -1222,7 +1222,7 @@ describe("Composer submission", () => {
|
||||
|
||||
const target = session({
|
||||
calls: [],
|
||||
handoff: { set: handedOff.resolve, settle() {}, clear() {} },
|
||||
handoff: { set: handedOff.resolve, hold() {}, settle() {}, clear() {} },
|
||||
prompt: async () => admitted.resolve(),
|
||||
})
|
||||
|
||||
@@ -1264,6 +1264,7 @@ describe("Composer submission", () => {
|
||||
admitted: () => row.admitted,
|
||||
handoff: {
|
||||
set: (value) => handoff.push(`set:${value.message.id}`),
|
||||
hold: (value) => handoff.push(`hold:${value.message.id}`),
|
||||
settle: (id) => {
|
||||
handoff.push(`settle:${id}`)
|
||||
ended.resolve()
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SessionMessageUser } from "@opencode/client/promise"
|
||||
import { createEffect, createSignal, onCleanup, untrack, type Accessor } from "solid-js"
|
||||
import type { PromptComment } from "./comment-note"
|
||||
import type { PromptHistoryComment } from "./history/entry"
|
||||
import { isCommentItem, type ContextItem, type Prompt } from "./state"
|
||||
import { isCommentItem, type ContextItem, type ImageAttachmentPart, type Prompt } from "./state"
|
||||
import { appendPrompt, clonePrompt, isAttachment, promptLength, serializePrompt } from "./prompt-parts"
|
||||
import type {
|
||||
ComposerAdapter,
|
||||
@@ -94,6 +94,39 @@ export function createComposerSubmit(input: ComposerSubmitInput) {
|
||||
if (effect.type === "submit.retry")
|
||||
return dispatch({ type: "submit", snapshot: snapshot(input, effect.alternate), done: effect.done })
|
||||
|
||||
if (effect.type === "hold.show") {
|
||||
input.adapter.beforeSubmit?.()
|
||||
effect.session.handoff.hold({
|
||||
message: handoffMessage({
|
||||
id: effect.snapshot.id,
|
||||
prompt: effect.snapshot.draft.prompt,
|
||||
context: effect.snapshot.draft.context,
|
||||
images: effect.snapshot.draft.prompt.filter((part): part is ImageAttachmentPart => part.type === "image"),
|
||||
}),
|
||||
})
|
||||
input.addToHistory(effect.snapshot.draft.prompt, effect.snapshot.mode)
|
||||
input.resetHistory()
|
||||
|
||||
return dispatch({
|
||||
type: "hold.cleared",
|
||||
attempt: effect.attempt,
|
||||
cleared: clearComposer(input, effect.snapshot.draft, "prompt").cleared,
|
||||
})
|
||||
}
|
||||
|
||||
if (effect.type === "hold.cancel") {
|
||||
effect.session.handoff.clear(effect.snapshot.id)
|
||||
|
||||
if (!effect.cleared) return
|
||||
restoreDraft(
|
||||
input,
|
||||
{ draft: effect.snapshot.draft, mode: effect.snapshot.mode, comments: effect.snapshot.comments },
|
||||
afterHold(effect.snapshot.draft, effect.cleared),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (effect.type === "command.run") {
|
||||
input.adapter.beforeSubmit?.()
|
||||
void runClientCommand(input, effect.prompt, effect.run).then(
|
||||
@@ -198,17 +231,25 @@ export function createComposerSubmit(input: ComposerSubmitInput) {
|
||||
clearSubmission(input, effect)
|
||||
}
|
||||
|
||||
// A held send goes through once the Location's agents and models load, and ends if the draft changes first.
|
||||
// A held send goes through once the Location's agents and models load. One still in the composer ends if the draft
|
||||
// changes first; a shown one already left it.
|
||||
createEffect(() => {
|
||||
const current = state()
|
||||
|
||||
if (current.type !== "held") return
|
||||
|
||||
if (JSON.stringify(input.adapter.state.current()) !== current.draft)
|
||||
if (!current.shown && JSON.stringify(input.adapter.state.current()) !== current.snapshot.serialized)
|
||||
return untrack(() => dispatch({ type: "hold.changed", attempt: current.attempt }))
|
||||
|
||||
if (!input.adapter.controls().model.loading)
|
||||
untrack(() => dispatch({ type: "hold.loaded", attempt: current.attempt }))
|
||||
untrack(() =>
|
||||
dispatch({
|
||||
type: "hold.loaded",
|
||||
attempt: current.attempt,
|
||||
selection: currentSelection(input),
|
||||
commands: input.commands(),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
onCleanup(() => dispatch({ type: "unmounted" }))
|
||||
@@ -291,6 +332,7 @@ function snapshot(input: ComposerSubmitInput, alternate: boolean): SubmitSnapsho
|
||||
commands: input.commands(),
|
||||
clientCommand: mode === "normal" ? input.clientCommand?.(text) : undefined,
|
||||
comments: input.comments.capture(),
|
||||
session: input.adapter.kind === "active-session" ? input.adapter.session() : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,40 +371,22 @@ async function startSession(
|
||||
return started && { ...started, images }
|
||||
}
|
||||
|
||||
// The composer clears its captured draft once the Session's composer is ready; then the send settles.
|
||||
// The composer clears its captured draft once the Session's composer is ready; then the send settles. A shown hold
|
||||
// cleared it already, and the composer may hold a new draft since.
|
||||
function clearSubmission(
|
||||
input: ComposerSubmitInput,
|
||||
effect: Extract<ComposerSubmitEffect, { type: "composer.clear" }>,
|
||||
) {
|
||||
const target = effect.draft.target
|
||||
input.adapter.submitted()
|
||||
const held = effect.cleared
|
||||
const clear = held ? undefined : clearComposer(input, effect.draft, effect.kind.type)
|
||||
|
||||
if (effect.kind.type === "prompt") {
|
||||
// Like the TUI, sent context goes with the prompt rather than riding along on the next one.
|
||||
effect.draft.context.forEach((item) => target.context.remove(item.key))
|
||||
input.comments.clear()
|
||||
// A held prompt cleared the composer at Enter, so what it goes back to is read only once the send fails.
|
||||
const restore = () => {
|
||||
const back = clear ?? (held && afterHold(effect.draft, held))
|
||||
|
||||
return !!back && restoreSubmission(input, effect, back)
|
||||
}
|
||||
|
||||
if (effect.draft.initial !== target) effect.draft.initial.reset()
|
||||
|
||||
// A preparing session may already have an unsent follow-up in its promoted composer.
|
||||
const following =
|
||||
effect.draft.initial !== target &&
|
||||
effect.draft.preserveDraft &&
|
||||
target.current().some((part) => isAttachment(part) || part.content.length > 0)
|
||||
? clonePrompt(target.current())
|
||||
: undefined
|
||||
|
||||
if (!following) target.reset()
|
||||
const cleared = target.current()
|
||||
// The ID went with this send; a failure arms it again for this payload when it restores the draft.
|
||||
target.retry.clear()
|
||||
target.mode.set("normal")
|
||||
input.closePopover()
|
||||
|
||||
if (window.matchMedia("(max-width: 767px)").matches) input.editor()?.blur()
|
||||
const restore = () => restoreSubmission(input, effect, cleared, following)
|
||||
|
||||
if (effect.prompt) return void effect.prompt.settled(restore)
|
||||
|
||||
if (effect.kind.type === "shell")
|
||||
@@ -379,6 +403,49 @@ function clearSubmission(
|
||||
).catch((error) => failSubmission(input, effect.session, "command", error, restore, effect.value.id))
|
||||
}
|
||||
|
||||
// Returns the cleared composer, which a failed send restores only while it is unchanged, and any follow-up already
|
||||
// typed into a promoted new-session composer.
|
||||
function clearComposer(input: ComposerSubmitInput, draft: CapturedDraft, kind: SubmissionKind["type"]) {
|
||||
const target = draft.target
|
||||
input.adapter.submitted()
|
||||
|
||||
if (kind === "prompt") {
|
||||
// Like the TUI, sent context goes with the prompt rather than riding along on the next one.
|
||||
draft.context.forEach((item) => target.context.remove(item.key))
|
||||
input.comments.clear()
|
||||
}
|
||||
|
||||
if (draft.initial !== target) draft.initial.reset()
|
||||
|
||||
// A preparing session may already have an unsent follow-up in its promoted composer.
|
||||
const following =
|
||||
draft.initial !== target &&
|
||||
draft.preserveDraft &&
|
||||
target.current().some((part) => isAttachment(part) || part.content.length > 0)
|
||||
? clonePrompt(target.current())
|
||||
: undefined
|
||||
|
||||
if (!following) target.reset()
|
||||
const cleared = target.current()
|
||||
// The ID went with this send; a failure arms it again for this payload when it restores the draft.
|
||||
target.retry.clear()
|
||||
target.mode.set("normal")
|
||||
input.closePopover()
|
||||
|
||||
if (window.matchMedia("(max-width: 767px)").matches) input.editor()?.blur()
|
||||
|
||||
return { cleared, following, edited: !!following } satisfies ClearedComposer
|
||||
}
|
||||
|
||||
// A held prompt left the composer before it was sent, so a draft typed since follows it back rather than keeping it out.
|
||||
function afterHold(draft: CapturedDraft, cleared: Prompt): ClearedComposer {
|
||||
const current = draft.target.current()
|
||||
const edited = current !== cleared
|
||||
const typed = edited && current.some((part) => isAttachment(part) || part.content.length > 0)
|
||||
|
||||
return { cleared: current, following: typed ? clonePrompt(current) : undefined, edited }
|
||||
}
|
||||
|
||||
function clearClientCommand(input: ComposerSubmitInput, prompt: Prompt) {
|
||||
input.adapter.state.set([{ type: "text", content: "", start: 0, end: 0 }, ...prompt.filter(isAttachment)], 0)
|
||||
input.adapter.state.mode.set("normal")
|
||||
@@ -397,7 +464,10 @@ function submissionText(prompt: Prompt) {
|
||||
return prompt.map((part) => ("content" in part ? part.content : "")).join("")
|
||||
}
|
||||
|
||||
function handoffMessage(value: ComposerSubmission): SessionMessageUser {
|
||||
// A held prompt has no agent or model until its Location's catalog loads.
|
||||
function handoffMessage(
|
||||
value: Pick<ComposerSubmission, "id" | "prompt" | "context" | "images"> & { selection?: ComposerSelection },
|
||||
): SessionMessageUser {
|
||||
const text = submissionText(serializePrompt(value.prompt))
|
||||
|
||||
return {
|
||||
@@ -433,8 +503,7 @@ function handoffMessage(value: ComposerSubmission): SessionMessageUser {
|
||||
},
|
||||
]
|
||||
}),
|
||||
agent: value.selection.agent,
|
||||
model: selectionModel(value.selection),
|
||||
...(value.selection && { agent: value.selection.agent, model: selectionModel(value.selection) }),
|
||||
},
|
||||
time: { created: Date.now() },
|
||||
}
|
||||
@@ -515,6 +584,12 @@ function updateStatus(session: ComposerSession, event: PromptStatusEvent) {
|
||||
result.effects.forEach((effect) => session.data.session.setStatus(session.id, effect.status))
|
||||
}
|
||||
|
||||
/**
|
||||
* The composer a restore goes back to: the prompt it was cleared to, a follow-up typed into it since, and whether it
|
||||
* was edited since, which keeps the comments added meanwhile.
|
||||
*/
|
||||
type ClearedComposer = { cleared: Prompt; following: Prompt | undefined; edited: boolean }
|
||||
|
||||
// Puts a failed submission back, unless the composer changed since it cleared: then the edit is the user's.
|
||||
function restoreSubmission(
|
||||
input: ComposerSubmitInput,
|
||||
@@ -524,22 +599,40 @@ function restoreSubmission(
|
||||
kind: SubmissionKind
|
||||
comments: PromptHistoryComment[]
|
||||
},
|
||||
cleared: Prompt,
|
||||
following: Prompt | undefined,
|
||||
back: ClearedComposer,
|
||||
) {
|
||||
const target = submission.draft.target
|
||||
const value = submission.value
|
||||
|
||||
if (target.current() !== cleared) return false
|
||||
if (!restoreDraft(input, { ...submission, mode: value.mode }, back)) return false
|
||||
|
||||
// Only a prompt was admitted under its ID. A recovered follow-up changes the payload, so it needs a new one.
|
||||
if (submission.kind.type === "prompt" && !back.following)
|
||||
submission.draft.target.retry.set({ id: value.id, fingerprint: retryFingerprint(value) })
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Puts a cleared draft back, unless the composer changed since it cleared: then the edit is the user's.
|
||||
function restoreDraft(
|
||||
input: ComposerSubmitInput,
|
||||
submission: { draft: CapturedDraft; mode: "normal" | "shell"; comments: PromptHistoryComment[] },
|
||||
back: ClearedComposer,
|
||||
) {
|
||||
const target = submission.draft.target
|
||||
const following = back.following
|
||||
|
||||
if (target.current() !== back.cleared) return false
|
||||
const kept = back.edited ? input.comments.capture() : []
|
||||
const prompt = following ? appendPrompt(submission.draft.prompt, following) : submission.draft.prompt
|
||||
// The prompt is back in the composer; its history entry would only keep attachments referenced.
|
||||
input.removeFromHistory(value.prompt, value.mode, submission.comments)
|
||||
input.removeFromHistory(submission.draft.prompt, submission.mode, submission.comments)
|
||||
target.set(prompt, promptLength(prompt))
|
||||
target.mode.set(value.mode)
|
||||
target.mode.set(submission.mode)
|
||||
const sent = new Set(submission.draft.context.map((item) => item.key))
|
||||
|
||||
// In the order it was sent: an unedited resend must send the same request, which the retry ID's fingerprint names.
|
||||
// Files listed since the send stay after it; comments the draft gained since are replaced, as before.
|
||||
// Files listed since the send stay after it. Comments the draft gained since are replaced, as before, unless they
|
||||
// were added to a draft typed since, which keeps them.
|
||||
target.context.replace([
|
||||
...submission.draft.context.map((item): ContextItem => {
|
||||
if (item.type === "quote")
|
||||
@@ -578,24 +671,23 @@ function restoreSubmission(
|
||||
description: item.description,
|
||||
}
|
||||
}),
|
||||
...target.context.items().filter((item) => !isCommentItem(item) && !sent.has(item.key)),
|
||||
...target.context.items().filter((item) => (back.edited || !isCommentItem(item)) && !sent.has(item.key)),
|
||||
])
|
||||
submission.draft.sources.forEach((item) => target.quoteSource.add(item.key, item.source))
|
||||
|
||||
// Only a prompt was admitted under its ID. A recovered follow-up changes the payload, so it needs a new one.
|
||||
if (submission.kind.type === "prompt" && !following)
|
||||
target.retry.set({ id: value.id, fingerprint: retryFingerprint(value) })
|
||||
|
||||
if (target !== input.adapter.state) return true
|
||||
|
||||
input.comments.restore(submission.comments)
|
||||
input.comments.restore([
|
||||
...submission.comments,
|
||||
...kept.filter((item) => !submission.comments.some((comment) => comment.id === item.id)),
|
||||
])
|
||||
input.closePopover()
|
||||
requestAnimationFrame(() => {
|
||||
const editor = input.editor()
|
||||
|
||||
if (!editor) return
|
||||
editor.focus()
|
||||
setCursorPosition(editor, promptLength(value.prompt))
|
||||
setCursorPosition(editor, promptLength(submission.draft.prompt))
|
||||
input.queueScroll()
|
||||
})
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { setCursorPosition } from "@/composer/editor/dom"
|
||||
import { promptLength } from "@/composer/prompt-parts"
|
||||
import { useCommand } from "@/shell/commands/command"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import { useData } from "@/runtime/server/current"
|
||||
import { useData, useServer } from "@/runtime/server/current"
|
||||
import { useServerSDK } from "@/runtime/server/client"
|
||||
import { showToast } from "@/shell/notifications/toast"
|
||||
import { errorMessage } from "@/shell/layout/helpers"
|
||||
@@ -293,8 +293,12 @@ export function createActiveSessionRegion(input: {
|
||||
showToast({ title: language.t("common.requestFailed") })
|
||||
}
|
||||
|
||||
const handoffs = useServer().ctx.handoff
|
||||
|
||||
const pendingSteer: TimelinePendingActions = {
|
||||
status: (sessionID, messageID) => data.session.pending.status(sessionID, messageID),
|
||||
// A prompt held for its Location's agents and models shows as sending until it has a server row.
|
||||
status: (sessionID, messageID) =>
|
||||
handoffs.held(sessionID, messageID) ? "sending" : data.session.pending.status(sessionID, messageID),
|
||||
queue: ({ sessionID, messageID }) =>
|
||||
server.api.session.inbox
|
||||
.update({ sessionID, inboxID: messageID, delivery: "queue" })
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
HANDOFF_SEND_TIMEOUT_MS,
|
||||
HANDOFF_SYNC_TIMEOUT_MS,
|
||||
selectSessionHandoff,
|
||||
selectSessionHandoffHeld,
|
||||
transitionSessionHandoff,
|
||||
type SessionHandoffEvent,
|
||||
type SessionHandoffState,
|
||||
@@ -91,6 +92,39 @@ describe("transitionSessionHandoff", () => {
|
||||
expect(last(steps).effects).toEqual([])
|
||||
})
|
||||
|
||||
test("a prompt held for its Location shows with no timer until its send replaces it", () => {
|
||||
const hold: SessionHandoffEvent = { type: "handoff.held", sessionID: "ses_1", handoff: handoff("msg_1") }
|
||||
|
||||
const steps = replay([
|
||||
hold,
|
||||
// Nothing is in flight, so a dropped stream or a settled send for it changes nothing.
|
||||
{ type: "connection.changed", connected: false },
|
||||
{ type: "connection.changed", connected: true },
|
||||
{ type: "prompt.settled", sessionID: "ses_1", messageID: "msg_1" },
|
||||
set("msg_1"),
|
||||
])
|
||||
|
||||
expect(steps.map((step) => held(step.state)?.phase)).toEqual(["held", "held", "held", "held", "sending"])
|
||||
expect(steps.slice(0, 4).flatMap((step) => step.effects)).toEqual([])
|
||||
expect(selectSessionHandoffHeld(steps[0].state, "ses_1", "msg_1")).toBe(true)
|
||||
expect(selectSessionHandoffHeld(steps[0].state, "ses_1", "msg_2")).toBe(false)
|
||||
expect(selectSessionHandoffHeld(last(steps).state, "ses_1", "msg_1")).toBe(false)
|
||||
expect(last(steps).effects).toEqual([
|
||||
{ type: "timer.set", sessionID: "ses_1", timer: "sending", attempt: 2, delayMs: HANDOFF_SEND_TIMEOUT_MS },
|
||||
])
|
||||
|
||||
// A cancelled hold clears it, and holding over a sending prompt stops that prompt's timer.
|
||||
expect(
|
||||
held(
|
||||
transitionSessionHandoff(steps[0].state, { type: "handoff.cleared", sessionID: "ses_1", messageID: "msg_1" })
|
||||
.state,
|
||||
),
|
||||
).toBeUndefined()
|
||||
expect(transitionSessionHandoff(last(steps).state, hold).effects).toEqual([
|
||||
{ type: "timer.cancel", sessionID: "ses_1" },
|
||||
])
|
||||
})
|
||||
|
||||
test("a connection change without a due echo writes only the connection", () => {
|
||||
const sending = transitionSessionHandoff(createSessionHandoffState(), set("msg_1")).state
|
||||
const result = transitionSessionHandoff(sending, { type: "connection.changed", connected: false })
|
||||
|
||||
@@ -9,20 +9,23 @@ export const HANDOFF_SEND_TIMEOUT_MS = 30_000
|
||||
/** The bound on the sync that replaces a missed admission echo. */
|
||||
export const HANDOFF_SYNC_TIMEOUT_MS = 10_000
|
||||
|
||||
// A submitted prompt the timeline shows before the server admits it, with the agent and model it was sent with.
|
||||
// A submitted prompt the timeline shows before the server admits it, with the agent and model it was sent with. A
|
||||
// prompt held for its Location's agents and models has no selection yet.
|
||||
export type SessionMessageHandoff = {
|
||||
readonly message: SessionMessageUser
|
||||
readonly selection: { readonly agent: string; readonly model: ModelRef }
|
||||
readonly selection?: { readonly agent: string; readonly model: ModelRef }
|
||||
}
|
||||
|
||||
/**
|
||||
* One session's optimistic prompt, held until the server's admission echo.
|
||||
* - `held`: the composer waits for the Location's agents and models before it sends; no request is in flight, so
|
||||
* nothing times out. Its send replaces it with `sending`, and a cancelled hold clears it.
|
||||
* - `sending`: the selection, a staged revert and the admission are still in flight.
|
||||
* - `awaiting-echo`: the send settled as admitted; the echo is due on the event stream, or after it reconnects.
|
||||
* - `syncing`: the echo was missed; the session, its inbox and its messages reload before the handoff ends.
|
||||
*/
|
||||
export type HeldSessionHandoff = {
|
||||
readonly phase: "sending" | "awaiting-echo" | "syncing"
|
||||
readonly phase: "held" | "sending" | "awaiting-echo" | "syncing"
|
||||
readonly attempt: number
|
||||
readonly handoff: SessionMessageHandoff
|
||||
}
|
||||
@@ -39,6 +42,7 @@ export type SessionHandoffState =
|
||||
|
||||
export type SessionHandoffEvent =
|
||||
| { readonly type: "handoff.set"; readonly sessionID: string; readonly handoff: SessionMessageHandoff }
|
||||
| { readonly type: "handoff.held"; readonly sessionID: string; readonly handoff: SessionMessageHandoff }
|
||||
| { readonly type: "prompt.settled"; readonly sessionID: string; readonly messageID: string }
|
||||
| { readonly type: "handoff.cleared"; readonly sessionID: string; readonly messageID: string }
|
||||
| { readonly type: "session.reverted"; readonly sessionID: string; readonly boundary: string }
|
||||
@@ -105,6 +109,19 @@ export function transitionSessionHandoff(
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === "handoff.held") {
|
||||
const attempt = state.issued + 1
|
||||
|
||||
return {
|
||||
state: {
|
||||
...state,
|
||||
issued: attempt,
|
||||
entries: { ...state.entries, [event.sessionID]: { phase: "held", attempt, handoff: event.handoff } },
|
||||
},
|
||||
effects: entry ? [{ type: "timer.cancel", sessionID: event.sessionID }] : [],
|
||||
}
|
||||
}
|
||||
|
||||
if (!entry) return { state, effects: [] }
|
||||
|
||||
const messageID = entry.handoff.message.id
|
||||
@@ -165,6 +182,14 @@ export function selectSessionHandoff(state: SessionHandoffState, sessionID: stri
|
||||
return state.entries[sessionID]?.handoff
|
||||
}
|
||||
|
||||
/** Whether a session's optimistic prompt is still held, unsent, for its Location's agents and models. */
|
||||
export function selectSessionHandoffHeld(state: SessionHandoffState, sessionID: string, messageID: string) {
|
||||
if (state.status !== "active") return false
|
||||
const entry = state.entries[sessionID]
|
||||
|
||||
return entry?.phase === "held" && entry.handoff.message.id === messageID
|
||||
}
|
||||
|
||||
function changeConnection(
|
||||
state: Extract<SessionHandoffState, { status: "active" }>,
|
||||
connected: boolean,
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { ServerSDK } from "@/runtime/server/client"
|
||||
import {
|
||||
createSessionHandoffState,
|
||||
selectSessionHandoff,
|
||||
selectSessionHandoffHeld,
|
||||
transitionSessionHandoff,
|
||||
type SessionHandoffEffect,
|
||||
type SessionHandoffEvent,
|
||||
@@ -99,8 +100,11 @@ export function createSessionMessageHandoffs(input: {
|
||||
return {
|
||||
/** The prompt a session's timeline shows before the server admits it. Reactive. */
|
||||
get: (sessionID: string | undefined) => selectSessionHandoff(state(), sessionID),
|
||||
/** Whether the prompt is held, unsent, for its Location's agents and models. Reactive. */
|
||||
held: (sessionID: string, messageID: string) => selectSessionHandoffHeld(state(), sessionID, messageID),
|
||||
forSession: (sessionID: string) => ({
|
||||
set: (handoff: SessionMessageHandoff) => dispatch({ type: "handoff.set", sessionID, handoff }),
|
||||
hold: (handoff: SessionMessageHandoff) => dispatch({ type: "handoff.held", sessionID, handoff }),
|
||||
settle: (messageID: string) => dispatch({ type: "prompt.settled", sessionID, messageID }),
|
||||
clear: (messageID: string) => dispatch({ type: "handoff.cleared", sessionID, messageID }),
|
||||
}),
|
||||
|
||||
@@ -33,6 +33,9 @@ function handoffNotices(
|
||||
const time = { created: handoff.message.time.created }
|
||||
const selection = handoff.selection
|
||||
|
||||
// A held prompt switches nothing until its Location's agents and models load.
|
||||
if (!selection) return []
|
||||
|
||||
return [
|
||||
...(session?.agent && session.agent !== selection.agent
|
||||
? [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { createRoot, createSignal } from "solid-js"
|
||||
import type { ActiveComposerAdapter, ComposerSession } from "@/composer/adapter"
|
||||
import { createMemoryComposerState } from "@/composer/state"
|
||||
import { createMemoryComposerState, type Prompt } from "@/composer/state"
|
||||
import { composerSubmitView } from "@/composer/machine"
|
||||
import { createComposerSubmit } from "@/composer/submit"
|
||||
import type { ModelSelection } from "@/providers/models/selection"
|
||||
@@ -29,21 +29,105 @@ const selection = {
|
||||
},
|
||||
} satisfies ModelSelection
|
||||
|
||||
test.each([
|
||||
{ name: "a send asks for a selection only once loading finds none", agent: "", toasts: ["missing"], left: "ship it" },
|
||||
{ name: "editing a held send cancels it and keeps the edit", edit: "ship i", toasts: [], left: "ship i" },
|
||||
{ name: "clearing a held send cancels it", edit: "", toasts: [], left: "" },
|
||||
{ name: "stopping a held send cancels it and keeps the prompt", stop: true, toasts: [], left: "ship it" },
|
||||
test.each<{
|
||||
name: string
|
||||
mode?: "shell"
|
||||
agent?: string
|
||||
edit?: string
|
||||
stop?: boolean
|
||||
toasts: string[]
|
||||
sent: string[]
|
||||
left: string
|
||||
timeline: string[]
|
||||
history: string[]
|
||||
}>([
|
||||
{
|
||||
name: "a held prompt shows in the session at once and sends once the Location loads, keeping a new draft",
|
||||
edit: "next",
|
||||
toasts: [],
|
||||
sent: ["ship it"],
|
||||
left: "next",
|
||||
timeline: ["hold:ship it", "set:ship it"],
|
||||
history: ["add:ship it"],
|
||||
},
|
||||
{
|
||||
name: "a held prompt whose Location loads without an agent returns to the composer and asks for one",
|
||||
agent: "",
|
||||
toasts: ["missing"],
|
||||
sent: [],
|
||||
left: "ship it",
|
||||
timeline: ["hold:ship it", "clear"],
|
||||
history: ["add:ship it", "remove:ship it"],
|
||||
},
|
||||
{
|
||||
name: "stopping a held prompt cancels it and returns it to the composer",
|
||||
stop: true,
|
||||
toasts: [],
|
||||
sent: [],
|
||||
left: "ship it",
|
||||
timeline: ["hold:ship it", "clear"],
|
||||
history: ["add:ship it", "remove:ship it"],
|
||||
},
|
||||
// A draft typed while the prompt waited is the user's too, so the prompt goes back in front of it.
|
||||
{
|
||||
name: "stopping a held prompt after typing a new draft puts it back in front of the draft",
|
||||
edit: "next",
|
||||
stop: true,
|
||||
toasts: [],
|
||||
sent: [],
|
||||
left: "ship it\n\nnext",
|
||||
timeline: ["hold:ship it", "clear"],
|
||||
history: ["add:ship it", "remove:ship it"],
|
||||
},
|
||||
{
|
||||
name: "a held prompt whose Location loads without an agent goes back in front of a draft typed since",
|
||||
agent: "",
|
||||
edit: "next",
|
||||
toasts: ["missing"],
|
||||
sent: [],
|
||||
left: "ship it\n\nnext",
|
||||
timeline: ["hold:ship it", "clear"],
|
||||
history: ["add:ship it", "remove:ship it"],
|
||||
},
|
||||
{
|
||||
name: "editing a held shell command cancels it and keeps the edit",
|
||||
mode: "shell",
|
||||
edit: "ship i",
|
||||
toasts: [],
|
||||
sent: [],
|
||||
left: "ship i",
|
||||
timeline: [],
|
||||
history: [],
|
||||
},
|
||||
{
|
||||
name: "clearing a held shell command cancels it",
|
||||
mode: "shell",
|
||||
edit: "",
|
||||
toasts: [],
|
||||
sent: [],
|
||||
left: "",
|
||||
timeline: [],
|
||||
history: [],
|
||||
},
|
||||
])("$name", async (row) => {
|
||||
const state = createMemoryComposerState({ prompt: "ship it" }).capture()
|
||||
const sent: string[] = []
|
||||
const toasts: string[] = []
|
||||
const timeline: string[] = []
|
||||
const history: string[] = []
|
||||
const statuses: string[] = []
|
||||
const prompted = Promise.withResolvers<void>()
|
||||
const [agent, setAgent] = createSignal<string>()
|
||||
|
||||
const session: ComposerSession = {
|
||||
id: "session-1",
|
||||
directory: "/repo",
|
||||
handoff: { set() {}, settle() {}, clear() {} },
|
||||
handoff: {
|
||||
set: (handoff) => void timeline.push(`set:${handoff.message.text}`),
|
||||
hold: (handoff) => void timeline.push(`hold:${handoff.message.text}`),
|
||||
settle() {},
|
||||
clear: () => void timeline.push("clear"),
|
||||
},
|
||||
current: () => undefined,
|
||||
admitted: () => true,
|
||||
api: {
|
||||
@@ -58,6 +142,7 @@ test.each([
|
||||
session: {
|
||||
prompt: async (value) => {
|
||||
sent.push(value.text)
|
||||
prompted.resolve()
|
||||
|
||||
return {
|
||||
id: value.id ?? "msg_admitted",
|
||||
@@ -68,7 +153,7 @@ test.each([
|
||||
delivery: value.delivery ?? "steer",
|
||||
}
|
||||
},
|
||||
setStatus() {},
|
||||
setStatus: (_id, status) => void statuses.push(status),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -92,12 +177,12 @@ test.each([
|
||||
await createRoot(async (dispose) => {
|
||||
const submission = createComposerSubmit({
|
||||
adapter,
|
||||
mode: () => "normal",
|
||||
mode: () => row.mode ?? "normal",
|
||||
commands: () => [],
|
||||
editor: () => undefined,
|
||||
queueScroll() {},
|
||||
addToHistory() {},
|
||||
removeFromHistory() {},
|
||||
addToHistory: (prompt) => void history.push(`add:${promptText(prompt)}`),
|
||||
removeFromHistory: (prompt) => void history.push(`remove:${promptText(prompt)}`),
|
||||
resetHistory() {},
|
||||
closePopover() {},
|
||||
notify: { missingSelection: () => void toasts.push("missing"), unqueueable() {}, failed() {} },
|
||||
@@ -110,13 +195,15 @@ test.each([
|
||||
|
||||
expect(composerSubmitView(submission.state()).held).toBe(true)
|
||||
expect(toasts).toEqual([])
|
||||
// A prompt shows in the session and leaves the composer at once; a shell command waits in the composer.
|
||||
expect(text(state)).toBe(row.mode ? "ship it" : "")
|
||||
|
||||
if (row.edit !== undefined) state.set([{ type: "text", content: row.edit, start: 0, end: row.edit.length }])
|
||||
|
||||
if (row.stop) await submission.stop()
|
||||
|
||||
// A cancelled hold settles before loading finishes, and loading afterwards sends nothing.
|
||||
if (row.agent === undefined) {
|
||||
if (row.edit !== undefined && row.mode) {
|
||||
await held
|
||||
expect(composerSubmitView(submission.state()).held).toBe(false)
|
||||
}
|
||||
@@ -124,17 +211,24 @@ test.each([
|
||||
setAgent(row.agent ?? "build")
|
||||
await held
|
||||
|
||||
if (row.sent.length > 0) await prompted.promise
|
||||
|
||||
expect(composerSubmitView(submission.state()).held).toBe(false)
|
||||
expect(toasts).toEqual(row.toasts)
|
||||
expect(sent).toEqual([])
|
||||
expect(sent).toEqual(row.sent)
|
||||
expect(text(state)).toBe(row.left)
|
||||
expect(timeline).toEqual(row.timeline)
|
||||
expect(history).toEqual(row.history)
|
||||
// A held prompt marks the Session running only once it is dispatched, like any prompt into an idle Session.
|
||||
expect(statuses).toEqual(row.sent.length > 0 ? ["running"] : [])
|
||||
dispose()
|
||||
})
|
||||
})
|
||||
|
||||
function text(state: ReturnType<ReturnType<typeof createMemoryComposerState>["capture"]>) {
|
||||
return state
|
||||
.current()
|
||||
.map((part) => ("content" in part ? part.content : ""))
|
||||
.join("")
|
||||
return promptText(state.current())
|
||||
}
|
||||
|
||||
function promptText(prompt: Prompt) {
|
||||
return prompt.map((part) => ("content" in part ? part.content : "")).join("")
|
||||
}
|
||||
|
||||
@@ -206,14 +206,17 @@ story("marks pending metadata without badging delivered, starting, or queued pro
|
||||
const indicator = timeline.locator('[data-slot="user-message-meta"] [data-slot="user-message-pending"]')
|
||||
const text = timeline.locator('[data-slot="user-message-text"]')
|
||||
|
||||
for (const status of ["steering", "stranded", "starting", "queued", "delivered"]) {
|
||||
for (const status of ["steering", "stranded", "sending", "starting", "queued", "delivered"]) {
|
||||
await timeline.getByLabel("Delivery state").selectOption(status)
|
||||
const pending = status === "steering" || status === "stranded"
|
||||
const pending = status === "steering" || status === "stranded" || status === "sending"
|
||||
|
||||
if (pending) await expect(indicator).toBeVisible()
|
||||
|
||||
if (!pending) await expect(indicator).toBeHidden()
|
||||
|
||||
// A prompt still sending has no server row, so it offers no action until the server has it.
|
||||
await expect(timeline.locator('[data-slot="user-message-actions"]')).toHaveCount(status === "sending" ? 0 : 1)
|
||||
|
||||
const colors = await timeline.evaluate((element, pending) => {
|
||||
const probe = document.createElement("span")
|
||||
probe.style.color = `var(--v2-text-text-${pending ? "muted" : "base"})`
|
||||
|
||||
@@ -44,9 +44,10 @@ export type SessionUserActions = {
|
||||
/**
|
||||
* An input the server has not delivered yet. Like the TUI, a pending steer can move to the queue or be deleted;
|
||||
* it shows as waiting only while `steering` behind delivered work or `stranded` by an execution that ended.
|
||||
* `sending` is a prompt this client shows before it can send it; it waits without actions until the server has it.
|
||||
*/
|
||||
pending?: {
|
||||
status: (messageID: string) => "starting" | "steering" | "stranded" | "queued" | undefined
|
||||
status: (messageID: string) => "starting" | "steering" | "stranded" | "queued" | "sending" | undefined
|
||||
queue: (input: { sessionID: string; messageID: string }) => Promise<void>
|
||||
remove: (input: { sessionID: string; messageID: string }) => Promise<void>
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ type MetaItem = { label: string; variant?: boolean }
|
||||
function modelItems(data: ReturnType<typeof useData>, model: SessionMessageAssistant["model"]): MetaItem[] {
|
||||
const name = data.store.provider?.all?.get(model.providerID)?.models?.[model.id]?.name ?? model.id
|
||||
|
||||
// A prompt held for its Location's catalog names no model yet.
|
||||
if (!name) return []
|
||||
|
||||
if (!model.variant || model.variant === "default") return [{ label: name }]
|
||||
|
||||
return [{ label: name }, { label: model.variant[0]?.toUpperCase() + model.variant.slice(1), variant: true }]
|
||||
@@ -264,8 +267,10 @@ export function CurrentUserMessageDisplay(props: {
|
||||
const setExpanded = fold.setOpen
|
||||
|
||||
const status = createMemo(() => props.actions?.pending?.status(props.message.id))
|
||||
const pending = createMemo(() => status() !== undefined && status() !== "queued")
|
||||
const waiting = createMemo(() => status() === "steering" || status() === "stranded")
|
||||
// A prompt still `sending` has no server row yet, so nothing can move, delete, revert or fork it.
|
||||
const sending = createMemo(() => status() === "sending")
|
||||
const pending = createMemo(() => status() !== undefined && status() !== "queued" && !sending())
|
||||
const waiting = createMemo(() => status() === "steering" || status() === "stranded" || sending())
|
||||
// SAFETY: opted-in reads leave stored files as `media:` refs, a PromptAttachment variant the generated message type does not list.
|
||||
const files = createMemo(() => (props.message.files ?? []) as PromptAttachment[])
|
||||
const attachments = createMemo(() => files().filter(attached))
|
||||
@@ -394,87 +399,89 @@ export function CurrentUserMessageDisplay(props: {
|
||||
onCleanup(() => dispatch({ type: "disposed" }))
|
||||
|
||||
const renderActions = () => (
|
||||
<span data-slot="user-message-actions">
|
||||
<Show when={props.actions?.pending}>
|
||||
<UserMessageTransition active={pending()}>
|
||||
<MessageActionButton
|
||||
icon="arrow-down-to-line"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.moveToQueue")}
|
||||
disabled={actionView().disabled.queue}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("queue")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.moveToQueue")}
|
||||
/>
|
||||
<MessageActionButton
|
||||
icon="outline-trash"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.deletePending")}
|
||||
disabled={actionView().disabled.remove}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("remove")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.deletePending")}
|
||||
/>
|
||||
</UserMessageTransition>
|
||||
</Show>
|
||||
<Show when={props.actions?.revert}>
|
||||
<UserMessageTransition active={!pending()}>
|
||||
<MessageActionButton
|
||||
icon="reset"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.revertMessage")}
|
||||
disabled={actionView().disabled.revert}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("revert")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.revertMessage")}
|
||||
/>
|
||||
</UserMessageTransition>
|
||||
</Show>
|
||||
<Menu gutter={4} placement="bottom-end">
|
||||
<Tooltip appearance="compact" value={i18n.t("ui.message.moreActions")} placement="top" gutter={4}>
|
||||
<Menu.Trigger
|
||||
as={IconButton}
|
||||
icon={<Icon name="outline-dots" size="small" />}
|
||||
size="small"
|
||||
variant="ghost-muted"
|
||||
onMouseDown={(event: MouseEvent) => event.preventDefault()}
|
||||
onClick={(event: MouseEvent) => event.stopPropagation()}
|
||||
aria-label={i18n.t("ui.message.moreActions")}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Menu.Portal>
|
||||
<Menu.Content>
|
||||
<Menu.Group>
|
||||
<Menu.GroupLabel>
|
||||
<time dateTime={new Date(props.message.time.created).toISOString()}>{sent()}</time>
|
||||
</Menu.GroupLabel>
|
||||
</Menu.Group>
|
||||
<Menu.Separator />
|
||||
<Menu.Item disabled={actionView().disabled.fork} onSelect={() => request("fork")}>
|
||||
{i18n.t("ui.message.forkMessage")}
|
||||
</Menu.Item>
|
||||
<Menu.Item disabled={!props.text} onSelect={() => void writeClipboard(props.text)}>
|
||||
{i18n.t("ui.message.copyMessage")}
|
||||
</Menu.Item>
|
||||
{/* Like the iOS app, a Voice message also offers the full prompt the session received. */}
|
||||
<Show when={props.voice}>
|
||||
<Menu.Item onSelect={() => void writeClipboard(props.message.text)}>
|
||||
{i18n.t("ui.message.copyFullMessage")}
|
||||
<Show when={!sending()}>
|
||||
<span data-slot="user-message-actions">
|
||||
<Show when={props.actions?.pending}>
|
||||
<UserMessageTransition active={pending()}>
|
||||
<MessageActionButton
|
||||
icon="arrow-down-to-line"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.moveToQueue")}
|
||||
disabled={actionView().disabled.queue}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("queue")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.moveToQueue")}
|
||||
/>
|
||||
<MessageActionButton
|
||||
icon="outline-trash"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.deletePending")}
|
||||
disabled={actionView().disabled.remove}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("remove")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.deletePending")}
|
||||
/>
|
||||
</UserMessageTransition>
|
||||
</Show>
|
||||
<Show when={props.actions?.revert}>
|
||||
<UserMessageTransition active={!pending()}>
|
||||
<MessageActionButton
|
||||
icon="reset"
|
||||
size="small"
|
||||
label={i18n.t("ui.message.revertMessage")}
|
||||
disabled={actionView().disabled.revert}
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
request("revert")
|
||||
}}
|
||||
aria-label={i18n.t("ui.message.revertMessage")}
|
||||
/>
|
||||
</UserMessageTransition>
|
||||
</Show>
|
||||
<Menu gutter={4} placement="bottom-end">
|
||||
<Tooltip appearance="compact" value={i18n.t("ui.message.moreActions")} placement="top" gutter={4}>
|
||||
<Menu.Trigger
|
||||
as={IconButton}
|
||||
icon={<Icon name="outline-dots" size="small" />}
|
||||
size="small"
|
||||
variant="ghost-muted"
|
||||
onMouseDown={(event: MouseEvent) => event.preventDefault()}
|
||||
onClick={(event: MouseEvent) => event.stopPropagation()}
|
||||
aria-label={i18n.t("ui.message.moreActions")}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Menu.Portal>
|
||||
<Menu.Content>
|
||||
<Menu.Group>
|
||||
<Menu.GroupLabel>
|
||||
<time dateTime={new Date(props.message.time.created).toISOString()}>{sent()}</time>
|
||||
</Menu.GroupLabel>
|
||||
</Menu.Group>
|
||||
<Menu.Separator />
|
||||
<Menu.Item disabled={actionView().disabled.fork} onSelect={() => request("fork")}>
|
||||
{i18n.t("ui.message.forkMessage")}
|
||||
</Menu.Item>
|
||||
</Show>
|
||||
</Menu.Content>
|
||||
</Menu.Portal>
|
||||
</Menu>
|
||||
</span>
|
||||
<Menu.Item disabled={!props.text} onSelect={() => void writeClipboard(props.text)}>
|
||||
{i18n.t("ui.message.copyMessage")}
|
||||
</Menu.Item>
|
||||
{/* Like the iOS app, a Voice message also offers the full prompt the session received. */}
|
||||
<Show when={props.voice}>
|
||||
<Menu.Item onSelect={() => void writeClipboard(props.message.text)}>
|
||||
{i18n.t("ui.message.copyFullMessage")}
|
||||
</Menu.Item>
|
||||
</Show>
|
||||
</Menu.Content>
|
||||
</Menu.Portal>
|
||||
</Menu>
|
||||
</span>
|
||||
</Show>
|
||||
)
|
||||
|
||||
const renderAttachments = () => (
|
||||
|
||||
@@ -14,7 +14,7 @@ export default {
|
||||
|
||||
export const Pending = {
|
||||
render: () => {
|
||||
const statuses = ["delivered", "starting", "steering", "stranded", "queued"] as const
|
||||
const statuses = ["delivered", "starting", "steering", "stranded", "queued", "sending"] as const
|
||||
|
||||
const [state, setState] = createStore<{
|
||||
status: (typeof statuses)[number]
|
||||
|
||||
@@ -167,7 +167,7 @@ export function createSessionTimelineRowRenderer(input: {
|
||||
const presentation = input.presentation(message)
|
||||
|
||||
return {
|
||||
kind: status === "steering" || status === "stranded" ? "pending" : "sent",
|
||||
kind: status === "steering" || status === "stranded" || status === "sending" ? "pending" : "sent",
|
||||
agent: user.agent,
|
||||
model: user.model,
|
||||
text: !!(presentation?.displayText ?? message.text),
|
||||
|
||||
@@ -51,7 +51,8 @@ const fallbackData = {
|
||||
|
||||
const fallbackHandoff = {
|
||||
get: () => undefined,
|
||||
forSession: () => ({ set() {}, settle() {}, clear() {} }),
|
||||
held: () => false,
|
||||
forSession: () => ({ set() {}, hold() {}, settle() {}, clear() {} }),
|
||||
}
|
||||
|
||||
type ActiveServerValue = {
|
||||
|
||||
Reference in New Issue
Block a user