Repository navigation
feat(app): demo voice message architecture (upstream #54426) #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ivanmilevtues
wants to merge
1
commit into
dev
Choose a base branch
from
demo-voice-messages
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/app/src/session/timeline/voice-delegation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an iOS voice follow-up arrives while the Session is busy, it can remain in
SessionQueuePanel; that panel obtains its label throughqueuedPromptText(queue.ts:389-393), which returns the rawpayload.textwhen the iOS message has nodisplayTextmetadata. Because voice parsing is applied only to delivered timeline rows here, the queued row exposes the full delegation header, JSON, and transcript instead of the framing or instruction until delivery. Apply the same presentation parsing to queued prompts.AGENTS.md reference: AGENTS.md:L184-L184
Useful? React with 👍 / 👎.