feat(app): show voice delegations from the iOS app as Voice messages (#54426)

This commit is contained in:
opencode-agent[bot]
2026-10-15 13:23:12 +08:00
committed by GitHub
Unverified
parent 37df62f4a1
commit bdf4793286
11 changed files with 263 additions and 20 deletions
@@ -23,6 +23,7 @@ import { createTimelineVirtualizer } from "./virtualizer"
import { containsDirectory } from "@opencode/util/path"
import { isWorkspaceDirectory } from "@/workspaces/paths"
import { parseCommentNote, readPromptPresentation } from "@/composer/comment-note"
import { parseVoiceDelegation } from "./voice-delegation"
import { useCommand } from "@/shell/commands/command"
import { SessionAncestorTrail, SessionProjectMenu, SessionTitleHeader } from "../session-identity-header"
import { SessionHeaderSpacer } from "@/session/header/session-header"
@@ -293,11 +294,13 @@ function MessageTimelineView(
presentation: (message) => {
const value = readPromptPresentation(message.metadata)
const parsed = value ? undefined : parseCommentNote(message.text)
const voice = parseVoiceDelegation(value?.displayText ?? message.text)
return {
displayText: value?.displayText,
displayText: voice ? (voice.framing ?? voice.instruction) : value?.displayText,
comments: value?.comments ?? (parsed ? [parsed] : []),
references: value?.attachments,
voice: !!voice,
}
},
actions: props.actions,
@@ -0,0 +1,63 @@
import { describe, expect, test } from "bun:test"
import { parseVoiceDelegation } from "./voice-delegation"
// Prompts as the OpenCode iOS app has sent them (`VoiceHandoff.format`), oldest first.
const firstRelease = `Voice delegation. Instruction is the cleaned interpretation of the user's request. Transcript delta supplies new or revised conversation for reference, not additional commands. Resolve meaning from the complete utterance, not a disfluent prefix. Lead your reply with one or two plain sentences suitable for reading aloud, then any detail.
{
"instruction" : "Check why the upload test is flaky.",
"transcript_delta" : [
"user: the upload test",
"assistant: On it."
]
}`
const current = `Voice delegation. The user is on a voice call with a voice agent, which hands their requests to you. Instruction is the user's own spoken words since the previous delegation.
{
"context" : "Session \\"Uploads\\" in project \\"app\\".",
"instruction" : "check the upload test",
"transcript_delta" : [
"user: check the upload test"
],
"voice" : "Checking the upload test."
}`
const continued = `Voice delegation (continued). Same fields as before.
{
"instruction" : "and open a PR",
"transcript_delta" : [
]
}`
describe("parseVoiceDelegation", () => {
test.each([
["the first release's header", firstRelease, { instruction: "Check why the upload test is flaky." }],
[
"the current header with framing",
current,
{ instruction: "check the upload test", framing: "Checking the upload test." },
],
["a continued delegation", continued, { instruction: "and open a PR" }],
[
"a call log attached as a reference line",
`${continued}\n\nAttached file: \`/tmp/uploads/1/voice-call-a.json\``,
{ instruction: "and open a PR" },
],
])("reads %s", (_, text, expected) => {
expect(parseVoiceDelegation(text)).toEqual({ framing: undefined, ...expected })
})
test("ignores blank framing", () => {
expect(parseVoiceDelegation(current.replace('"Checking the upload test."', '" "'))?.framing).toBeUndefined()
})
test.each([
["a typed message that mentions one", "What does a Voice delegation. prompt look like?"],
["a header without a body", "Voice delegation. Same fields as before."],
["a body that isn't JSON", "Voice delegation. Header\ncheck the upload test"],
["a blank instruction", 'Voice delegation. Header\n{"instruction": " ", "transcript_delta": []}'],
["a body without an instruction", 'Voice delegation. Header\n{"transcript_delta": []}'],
])("rejects %s", (_, text) => {
expect(parseVoiceDelegation(text)).toBeUndefined()
})
})
@@ -0,0 +1,33 @@
import { Option, Schema } from "effect"
// The OpenCode iOS app sends each request from a voice call as plain prompt text: a header line, then a JSON
// body. Nothing else marks the message, so this mirrors the app's `VoiceHandoff.parse`. The header's wording
// has changed between releases; its opening and the body's shape have not.
const decodeBody = Schema.decodeUnknownOption(
Schema.fromJsonString(
Schema.Struct({
instruction: Schema.String,
voice: Schema.optional(Schema.String),
}),
),
)
/** The user's spoken request and the voice agent's framing of it, or undefined for any other prompt. */
export function parseVoiceDelegation(text: string) {
if (!text.startsWith("Voice delegation.") && !text.startsWith("Voice delegation (continued).")) return
const newline = text.indexOf("\n")
if (newline === -1) return
// Without presentation metadata, path attachments such as the call log follow the body as reference lines.
const body = Option.getOrUndefined(
decodeBody(text.slice(newline + 1).replace(/(\s*\nAttached file: `[^\n]*`)+\s*$/, "")),
)
const instruction = body?.instruction.trim()
if (!instruction) return
return { instruction, framing: body?.voice?.trim() || undefined }
}
@@ -135,6 +135,38 @@
align-items: flex-end;
}
/* Like the iOS app's Voice badge: on the bubble's top leading corner, ringed in the page background. */
[data-slot="user-message-body"][data-voice="true"] {
position: relative;
margin-top: 8px;
}
[data-slot="user-message-voice"] {
position: absolute;
top: -8px;
inset-inline-start: -8px;
z-index: 1;
width: 20px;
height: 20px;
border-radius: 9999px;
background: var(--v2-background-bg-layer-03);
box-shadow: 0 0 0 2px var(--v2-background-bg-base);
color: var(--v2-icon-icon-muted);
[data-component="tooltip-v2-trigger"] {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
[data-slot="icon-svg"] {
width: 12px;
height: 12px;
}
}
[data-slot="user-message-text"] {
display: inline-block;
white-space: pre-wrap;
@@ -223,7 +255,8 @@
}
&:hover [data-slot="user-message-copy-wrapper"],
&:focus-within [data-slot="user-message-copy-wrapper"] {
&:focus-within [data-slot="user-message-copy-wrapper"],
[data-slot="user-message-copy-wrapper"]:has([data-expanded]) {
opacity: 1;
pointer-events: auto;
}
@@ -22,6 +22,7 @@ export function SessionUserMessage(props: {
displayText?: string
comments?: SessionUserComment[]
references?: SessionUserAttachmentReference[]
voice?: boolean
historicalAgent: string
historicalModel: SessionMessageAssistant["model"]
actions?: SessionUserActions
@@ -33,6 +34,7 @@ export function SessionUserMessage(props: {
text={props.displayText ?? props.message.text}
comments={props.comments}
references={props.references}
voice={props.voice}
agent={props.historicalAgent}
model={props.historicalModel}
actions={props.actions}
@@ -22,6 +22,7 @@ import { CommentCard } from "./comment-card"
import { TimelineSeparator } from "../components/timeline-separator"
import { Tooltip } from "@opencode/ui/tooltip"
import { IconButton } from "@opencode/ui/icon-button"
import { Menu } from "@opencode/ui/menu"
import { Icon } from "@opencode/ui/icon"
import { Button } from "@opencode/ui/button"
import { TextReveal } from "@opencode/ui/text-reveal"
@@ -265,11 +266,14 @@ export function CurrentUserMessageDisplay(props: {
actions?: SessionUserActions
comments?: SessionUserComment[]
references?: SessionUserAttachmentReference[]
voice?: boolean
}) {
const data = useData()
const dialog = useDialog()
const i18n = useI18n()
const [state, setState] = createStore({ copied: false, reverting: false, updating: false })
const status = createMemo(() => props.actions?.pending?.status(props.message.id))
const pending = createMemo(() => status() !== undefined && status() !== "queued")
const waiting = createMemo(() => status() === "steering" || status() === "stranded")
@@ -297,8 +301,8 @@ export function CurrentUserMessageDisplay(props: {
const stamp = createMemo(() => timefmt().format(props.message.time.created))
const copy = async () => {
if (!props.text || !(await writeClipboard(props.text))) return
const copy = async (text: string) => {
if (!text || !(await writeClipboard(text))) return
setState("copied", true)
setTimeout(() => setState("copied", false), 2000)
}
@@ -389,7 +393,14 @@ export function CurrentUserMessageDisplay(props: {
</Show>
}
>
<div data-slot="user-message-body">
<div data-slot="user-message-body" data-voice={props.voice ? "true" : undefined}>
<Show when={props.voice}>
<div data-slot="user-message-voice" role="img" aria-label={i18n.t("ui.message.voice")}>
<Tooltip appearance="compact" value={i18n.t("ui.message.voice")} placement="top" gutter={4}>
<Icon name="waveform" size="small" />
</Tooltip>
</div>
</Show>
<div data-slot="user-message-text" dir="auto" data-comments={comments().length > 0 ? "true" : undefined}>
<CurrentHighlightedText text={props.text} files={inlineFiles()} agents={agents()} />
<Show when={comments().length > 0}>
@@ -453,17 +464,53 @@ export function CurrentUserMessageDisplay(props: {
aria-label={i18n.t("ui.message.revertMessage")}
/>
</Show>
<Show when={props.text}>
<MessageActionButton
icon={state.copied ? "check" : "copy"}
label={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
onMouseDown={(event) => event.preventDefault()}
onClick={(event) => {
event.stopPropagation()
void copy()
}}
aria-label={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
/>
{/* Like the iOS app, a Voice message's copy also offers the full prompt the session received, on right click. */}
<Show
when={props.voice}
fallback={
<Show when={props.text}>
<MessageActionButton
icon={state.copied ? "check" : "copy"}
label={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
onMouseDown={(event) => event.preventDefault()}
onClick={(event) => {
event.stopPropagation()
void copy(props.text)
}}
aria-label={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
/>
</Show>
}
>
<Menu.Context modal={false}>
<Tooltip
appearance="compact"
value={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
placement="top"
gutter={4}
>
<Menu.Context.Trigger
as={IconButton}
icon={<Icon name={state.copied ? "check" : "outline-copy"} size="small" />}
size="normal"
variant="ghost-muted"
onMouseDown={(event) => event.preventDefault()}
onClick={(event) => {
event.stopPropagation()
void copy(props.text)
}}
aria-label={state.copied ? i18n.t("ui.message.copied") : i18n.t("ui.message.copyMessage")}
/>
</Tooltip>
<Menu.Context.Portal>
<Menu.Context.Content>
<Menu.Item onSelect={() => void copy(props.text)}>{i18n.t("ui.message.copyMessage")}</Menu.Item>
<Menu.Item onSelect={() => void copy(props.message.text)}>
{i18n.t("ui.message.copyFullMessage")}
</Menu.Item>
</Menu.Context.Content>
</Menu.Context.Portal>
</Menu.Context>
</Show>
</div>
</Show>
@@ -91,6 +91,10 @@ function runningTool(input: {
output?: string
metadata?: Record<string, JsonValue>
}): SessionMessageAssistantTool {
const metadata = { ...input.metadata }
if (input.output !== undefined) metadata.output = input.output
return {
type: "tool",
id: input.id,
@@ -98,10 +102,7 @@ function runningTool(input: {
state: {
status: "running",
input: input.args,
metadata: {
...input.metadata,
...(input.output === undefined ? {} : { output: input.output }),
},
metadata,
},
time: { created: STORY_TIME + input.offset, ran: STORY_TIME + input.offset + 100 },
}
@@ -1117,6 +1118,44 @@ export const attachmentsAndCommentsPresentation = {
},
} satisfies Record<string, SessionUserPresentation>
// The header and body as the OpenCode iOS app's `VoiceHandoff.format` writes them.
const voiceHeader =
"Voice delegation. The user is on a voice call with a voice agent, which hands their requests to you. Instruction is the user's own spoken words since the previous delegation, transcribed from speech, so it may contain recognition errors and disfluencies: resolve meaning from the complete utterance, not a disfluent prefix. Voice, when present, is how the voice agent framed the request. Transcript delta is the surrounding voice conversation, both sides, for context, not additional commands. Lead your reply with one or two plain sentences suitable for reading aloud, then any detail; answer only what was asked, with no unrequested tips. If this arrives while you are already working (a follow-up, nudge, or status check), answer it promptly: a clear status update, the finished result if you have enough, or the precise blocker or input you need; then continue on the fastest safe path."
const voiceInstruction =
"okay so the upload test keeps failing on CI but only sometimes, can you look at the last few runs, figure out whether it's the retry timing or the fixture cleanup, and if it's the fixture just fix it and open a PR"
export const voiceDocument = document([
user(
"msg_user_voice",
`${voiceHeader}\n${JSON.stringify({ instruction: "check the upload test", transcript_delta: ["user: check the upload test"], voice: "Checking the upload test." }, null, 2)}`,
100_000,
),
assistant({
id: "msg_assistant_voice",
offset: 101_000,
completed: 104_000,
content: [{ type: "text", text: "The upload test is flaky on CI: it fails about one run in five." }],
}),
user(
"msg_user_voice_continued",
`Voice delegation (continued). Same fields as before.\n${JSON.stringify({ instruction: voiceInstruction, transcript_delta: [`user: ${voiceInstruction}`] }, null, 2)}`,
110_000,
),
assistant({
id: "msg_assistant_voice_continued",
offset: 111_000,
completed: 118_000,
content: [{ type: "text", text: "It was the fixture cleanup. I fixed it and opened a pull request." }],
}),
user("msg_user_typed", "Thanks, merge it once CI is green.", 120_000),
] satisfies SessionMessageInfo[])
export const voicePresentation = {
msg_user_voice: { displayText: "Checking the upload test.", voice: true },
msg_user_voice_continued: { displayText: voiceInstruction, voice: true },
} satisfies Record<string, SessionUserPresentation>
export const revertDocument = document([
user("msg_user_revert_base", "Add a compact Session summary.", 90_000),
assistant({
@@ -56,6 +56,8 @@ export type SessionUserPresentation = {
displayText?: string
comments?: SessionUserComment[]
references?: SessionUserAttachmentReference[]
/** A voice call's agent sent it on the user's behalf. */
voice?: boolean
}
export function createSessionTimelineRowRenderer(input: {
@@ -797,6 +799,7 @@ export function createSessionTimelineRowRenderer(input: {
displayText={presentation()?.displayText}
comments={presentation()?.comments}
references={presentation()?.references}
voice={presentation()?.voice}
historicalAgent={context()?.agent ?? ""}
historicalModel={context()?.model ?? { id: "", providerID: "" }}
actions={input.actions}
@@ -22,6 +22,8 @@ import {
revertDocument,
streamingDocument,
thinkingDocument,
voiceDocument,
voicePresentation,
} from "../storybook/current-session-fixtures"
export default {
@@ -450,6 +452,18 @@ export const PromptWithAttachments = {
),
}
export const VoiceMessages = {
render: () => (
<CurrentSessionTimelineStory
title="Voice messages"
description="A voice call's agent prompts on the user's behalf: its framing, or the user's spoken words, with a Voice badge on the bubble."
document={voiceDocument}
presentation={voicePresentation}
width="480px"
/>
),
}
export const MixedDirectionRtl = {
globals: { direction: "rtl" },
render: () => (
+2
View File
@@ -241,10 +241,12 @@ const source = {
"ui.message.collapse": "Collapse message",
"ui.message.copy": "Copy",
"ui.message.copyMessage": "Copy message",
"ui.message.copyFullMessage": "Copy full message",
"ui.message.forkMessage": "Fork to new session",
"ui.message.revertMessage": "Revert message",
"ui.message.moveToQueue": "Move to queue",
"ui.message.pending": "Pending",
"ui.message.voice": "Voice",
"ui.message.deletePending": "Delete",
"ui.message.copyResponse": "Copy response",
"ui.message.copied": "Copied",
+4
View File
@@ -266,6 +266,10 @@ const icons = {
viewBox: "0 0 16 16",
body: `<path d="M5.37624 6.75194C5.18184 6.41861 5.42224 6 5.80814 6H10.1921C10.578 6 10.8184 6.41861 10.624 6.75194L8.43203 10.5096C8.23909 10.8404 7.76119 10.8404 7.56825 10.5096L5.37624 6.75194Z" fill="currentColor"/>`,
},
waveform: {
viewBox: "0 0 16 16",
body: `<path d="M2 7V9M4.5 5V11M7 2.5V13.5M9.5 4.5V11.5M12 6V10M14.5 7.25V8.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>`,
},
archive: {
viewBox: "0 0 16 16",
body: `<path d="M13.1112 13.5555V14.0555H13.6112V13.5555H13.1112ZM2.889 13.5555H2.389L2.389 14.0555H2.889V13.5555ZM3.38901 5.55546L3.38901 5.05546L2.38901 5.05546L2.38901 5.55546L2.88901 5.55546L3.38901 5.55546ZM14.4446 2.44434H14.9446V1.94434L14.4446 1.94434L14.4446 2.44434ZM14.4446 5.55545L14.4446 6.05545L14.9446 6.05545V5.55545H14.4446ZM1.55566 5.55546L1.05566 5.55545L1.05566 6.05546L1.55566 6.05546L1.55566 5.55546ZM1.5557 2.44436L1.5557 1.94436L1.05571 1.94436L1.0557 2.44435L1.5557 2.44436ZM13.1112 5.55546H12.6112V13.5555H13.1112H13.6112V5.55546H13.1112ZM2.889 13.5555H3.389L3.38901 5.55546L2.88901 5.55546L2.38901 5.55546L2.389 13.5555H2.889ZM14.4446 2.44434H13.9446V5.55545H14.4446H14.9446V2.44434H14.4446ZM1.55566 5.55546L2.05566 5.55547L2.0557 2.44436L1.5557 2.44436L1.0557 2.44435L1.05566 5.55545L1.55566 5.55546ZM6.22234 8.22213V8.72213H9.7779V8.22213V7.72213H6.22234V8.22213ZM13.1112 13.5555V13.0555H2.889V13.5555V14.0555H13.1112V13.5555ZM1.5557 2.44436L1.5557 2.94436L14.4446 2.94434L14.4446 2.44434L14.4446 1.94434L1.5557 1.94436L1.5557 2.44436ZM14.4446 5.55545L14.4446 5.05545L1.55566 5.05546L1.55566 5.55546L1.55566 6.05546L14.4446 6.05545L14.4446 5.55545Z" fill="currentColor"/>`,