Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(voice): send a Gmail canvas when the user says to, without asking again

muterCdcdb4fbf92b1
diff --git a/apps/teamhub/AGENTS.md b/apps/teamhub/AGENTS.md
index b6293969..2f2764a5 100644
--- a/apps/teamhub/AGENTS.md
+++ b/apps/teamhub/AGENTS.md
@@ -68,6 +68,12 @@ Go service owning Human HTTP/SSE, Agent callbacks, and active product state.
still rendering these routes answer 503 with `Retry-After`.
- Live voice write tools that finish a send return a `next` asking the model
to say it was sent; a result without one can leave the voice silent.
+- Live voice writes need the user's yes from a turn after the question
+ (`voiceLiveConfirmed`), except `voicelive.DirectYesTools`: sending a Gmail
+ canvas, which is open beside the chat, runs when the user's own turn told
+ the model to send it and that turn neither asked about it nor wrote,
+ changed or attached to a canvas; otherwise the details are read back and
+ the yes comes in the user's next turn.
- A Room permits 100 Routines: recurring ones count while they exist, and
one-shot ones count until they fire. There is no separate one-shot limit.
diff --git a/apps/teamhub/internal/store/queries/voice_live.sql b/apps/teamhub/internal/store/queries/voice_live.sql
index e69f2c2e..479f09d9 100644
--- a/apps/teamhub/internal/store/queries/voice_live.sql
+++ b/apps/teamhub/internal/store/queries/voice_live.sql
@@ -218,6 +218,14 @@ SELECT count(*)::bigint FROM voice_live_tool_calls
WHERE voice_session_id=sqlc.arg(voice_session_id)::text
AND turn_id=sqlc.arg(turn_id)::text AND name=sqlc.arg(name)::text;
+-- name: CountVoiceLiveTurnCanvasChanges :one
+-- Whether a live turn wrote or changed a Gmail canvas: a send in that turn
+-- would go out before the user saw the change.
+SELECT count(*)::bigint FROM voice_live_tool_calls
+WHERE voice_session_id=sqlc.arg(voice_session_id)::text
+ AND turn_id=sqlc.arg(turn_id)::text
+ AND name IN ('open_email_canvas','edit_email_canvas','attach_email_file');
+
-- name: GetLatestVoiceLiveToolOutput :one
-- The newest output this session returned for the tool before the call that
-- asks, such as the page the browser showed last. The asking call is already
diff --git a/apps/teamhub/internal/store/queries/voice_live_tasks.sql b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
index 5e7999ce..3127f5e6 100644
--- a/apps/teamhub/internal/store/queries/voice_live_tasks.sql
+++ b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
@@ -97,6 +97,13 @@ INSERT INTO voice_live_confirmations(id,voice_session_id,turn_id,tool,arguments_
VALUES(sqlc.arg(id)::text,sqlc.arg(voice_session_id)::text,sqlc.arg(turn_id)::text,sqlc.arg(tool)::text,
sqlc.arg(arguments_hash)::text,sqlc.arg(goal)::text,sqlc.arg(surface)::text);
+-- name: CreateUsedVoiceLiveConfirmation :exec
+-- A yes the user gave in their own turn without a question first, used at
+-- once, so a retry within that turn is admitted like any used yes.
+INSERT INTO voice_live_confirmations(id,voice_session_id,turn_id,tool,arguments_hash,goal,surface,used_at,used_turn_id)
+VALUES(sqlc.arg(id)::text,sqlc.arg(voice_session_id)::text,sqlc.arg(turn_id)::text,sqlc.arg(tool)::text,
+ sqlc.arg(arguments_hash)::text,'','',clock_timestamp(),sqlc.arg(turn_id)::text);
+
-- name: GetVoiceLiveConfirmation :one
-- A confirmation still usable from this turn, without using it.
SELECT goal,surface FROM voice_live_confirmations
diff --git a/apps/teamhub/internal/store/voice_live.sql.go b/apps/teamhub/internal/store/voice_live.sql.go
index 2318bde6..2d539388 100644
--- a/apps/teamhub/internal/store/voice_live.sql.go
+++ b/apps/teamhub/internal/store/voice_live.sql.go
@@ -109,6 +109,27 @@ func (q *Queries) CompleteVoiceLiveToolCall(ctx context.Context, arg CompleteVoi
return err
}
+const countVoiceLiveTurnCanvasChanges = `-- name: CountVoiceLiveTurnCanvasChanges :one
+SELECT count(*)::bigint FROM voice_live_tool_calls
+WHERE voice_session_id=$1::text
+ AND turn_id=$2::text
+ AND name IN ('open_email_canvas','edit_email_canvas','attach_email_file')
+`
+
+type CountVoiceLiveTurnCanvasChangesParams struct {
+ VoiceSessionID string `json:"voice_session_id"`
+ TurnID string `json:"turn_id"`
+}
+
+// Whether a live turn wrote or changed a Gmail canvas: a send in that turn
+// would go out before the user saw the change.
+func (q *Queries) CountVoiceLiveTurnCanvasChanges(ctx context.Context, arg CountVoiceLiveTurnCanvasChangesParams) (int64, error) {
+ row := q.db.QueryRow(ctx, countVoiceLiveTurnCanvasChanges, arg.VoiceSessionID, arg.TurnID)
+ var column_1 int64
+ err := row.Scan(&column_1)
+ return column_1, err
+}
+
const countVoiceLiveTurnToolCalls = `-- name: CountVoiceLiveTurnToolCalls :one
SELECT count(*)::bigint FROM voice_live_tool_calls
WHERE voice_session_id=$1::text
diff --git a/apps/teamhub/internal/store/voice_live_tasks.sql.go b/apps/teamhub/internal/store/voice_live_tasks.sql.go
index 2ffa3b3e..a8352200 100644
--- a/apps/teamhub/internal/store/voice_live_tasks.sql.go
+++ b/apps/teamhub/internal/store/voice_live_tasks.sql.go
@@ -56,6 +56,33 @@ func (q *Queries) CountVoiceLiveTurnConfirmations(ctx context.Context, arg Count
return count, err
}
+const createUsedVoiceLiveConfirmation = `-- name: CreateUsedVoiceLiveConfirmation :exec
+INSERT INTO voice_live_confirmations(id,voice_session_id,turn_id,tool,arguments_hash,goal,surface,used_at,used_turn_id)
+VALUES($1::text,$2::text,$3::text,$4::text,
+ $5::text,'','',clock_timestamp(),$3::text)
+`
+
+type CreateUsedVoiceLiveConfirmationParams struct {
+ ID string `json:"id"`
+ VoiceSessionID string `json:"voice_session_id"`
+ TurnID string `json:"turn_id"`
+ Tool string `json:"tool"`
+ ArgumentsHash string `json:"arguments_hash"`
+}
+
+// A yes the user gave in their own turn without a question first, used at
+// once, so a retry within that turn is admitted like any used yes.
+func (q *Queries) CreateUsedVoiceLiveConfirmation(ctx context.Context, arg CreateUsedVoiceLiveConfirmationParams) error {
+ _, err := q.db.Exec(ctx, createUsedVoiceLiveConfirmation,
+ arg.ID,
+ arg.VoiceSessionID,
+ arg.TurnID,
+ arg.Tool,
+ arg.ArgumentsHash,
+ )
+ return err
+}
+
const createVoiceLiveConfirmation = `-- name: CreateVoiceLiveConfirmation :exec
INSERT INTO voice_live_confirmations(id,voice_session_id,turn_id,tool,arguments_hash,goal,surface)
VALUES($1::text,$2::text,$3::text,$4::text,
diff --git a/apps/teamhub/internal/voice/voice_live.go b/apps/teamhub/internal/voice/voice_live.go
index d2843754..914594f5 100644
--- a/apps/teamhub/internal/voice/voice_live.go
+++ b/apps/teamhub/internal/voice/voice_live.go
@@ -906,9 +906,10 @@ func (s *Service) voiceLiveDirectoryNames(ctx context.Context, session voicelive
return names
}
-// voiceLiveConfirmed admits a write the model marks confirmed only when the
-// user heard exactly this prompt in an earlier turn of the call, minutes
-// ago, and uses that confirmation up. Otherwise the prompt is recorded as
+// voiceLiveConfirmed admits a write the model marks confirmed when the user
+// heard exactly this prompt in an earlier turn of the call, minutes ago, and
+// uses that confirmation up; a DirectYesTools write is also admitted from the
+// user's own turn when that turn asked nothing. Otherwise the prompt is recorded as
// asked, so the user's yes in a later turn can confirm it.
func (s *Service) voiceLiveConfirmed(ctx context.Context, session voicelive.Session, request teamhubinternal.VoiceLiveToolCall, confirmed bool, prompt string) (bool, error) {
digest := sha256.Sum256([]byte(prompt))
@@ -921,6 +922,29 @@ func (s *Service) voiceLiveConfirmed(ctx context.Context, session voicelive.Sess
if err != nil || used > 0 {
return used > 0, err
}
+ if voicelive.DirectYesTools[request.Name] {
+ // The user, in their own turn, told the model to do it: with no
+ // question of this turn still open, that is their yes.
+ asked, err := s.queries.CountVoiceLiveTurnConfirmations(ctx, store.CountVoiceLiveTurnConfirmationsParams{
+ VoiceSessionID: session.ID, TurnID: request.TurnId, Tool: request.Name,
+ })
+ if err != nil {
+ return false, err
+ }
+ // A canvas written or changed in this same turn has not been seen
+ // yet, so its details are read back for a yes first.
+ changed, err := s.queries.CountVoiceLiveTurnCanvasChanges(ctx, store.CountVoiceLiveTurnCanvasChangesParams{
+ VoiceSessionID: session.ID, TurnID: request.TurnId,
+ })
+ if err != nil {
+ return false, err
+ }
+ if asked == 0 && changed == 0 && request.TurnId != "" {
+ return true, s.queries.CreateUsedVoiceLiveConfirmation(ctx, store.CreateUsedVoiceLiveConfirmationParams{
+ ID: idgen.New("confirm"), VoiceSessionID: session.ID, TurnID: request.TurnId, Tool: request.Name, ArgumentsHash: hash,
+ })
+ }
+ }
}
return false, s.queries.CreateVoiceLiveConfirmation(ctx, store.CreateVoiceLiveConfirmationParams{
ID: idgen.New("confirm"), VoiceSessionID: session.ID, TurnID: request.TurnId, Tool: request.Name, ArgumentsHash: hash,
diff --git a/apps/teamhub/internal/voicelive/apps.go b/apps/teamhub/internal/voicelive/apps.go
index 3e33e4e6..a146fb98 100644
--- a/apps/teamhub/internal/voicelive/apps.go
+++ b/apps/teamhub/internal/voicelive/apps.go
@@ -53,13 +53,13 @@ var AppTools = []Tool{
{
Name: ToolSendEmailCanvas,
Description: "Send a Gmail canvas in this room from the user's Gmail. It saves the canvas as a draft first, so what is sent is exactly the canvas; the canvas's file blocks go as attachments. " +
- "This cannot be undone: first call without confirmed; it returns needs_confirmation with who it goes to, the subject and any attachments: say that and that it cannot be undone, and ask the user. Only after they clearly say yes in their next turn, call again with the same document_id and confirmed=true. " +
- "A canvas changed after the question asks again. Say it was sent only when the result is sent; outcome_unknown means it may have gone out: never send again, ask the user to check their Sent folder. " +
+ "The canvas is open beside the chat, so the user has seen it: when the user tells you to send it, call with confirmed=true and it is sent, without asking again. When you are not sure they want it sent now, call without confirmed: it returns needs_confirmation with who it goes to, the subject and any attachments; say that and that it cannot be undone, ask, and after they say yes in their next turn call again with confirmed=true. " +
+ "Before the result, say only that you are sending it, never that it was sent. Say it was sent only when the result is sent; outcome_unknown means it may have gone out: never send again, ask the user to check their Sent folder. " +
"no_recipients: ask who it goes to and set them with edit_email_canvas first. " + accountChoice,
Parameters: objectSchema([]string{"document_id", "confirmed"}, map[string]any{
"document_id": stringProperty("The canvas, from open_email_canvas"),
"account": stringProperty("Optional Gmail address to send from"),
- "confirmed": map[string]any{"type": "boolean", "description": "Whether the user said yes to sending it, in their own next turn"},
+ "confirmed": map[string]any{"type": "boolean", "description": "true when the user, in their own latest turn, told you to send this email"},
}),
},
{
diff --git a/apps/teamhub/internal/voicelive/tools.go b/apps/teamhub/internal/voicelive/tools.go
index f4843325..a66937a6 100644
--- a/apps/teamhub/internal/voicelive/tools.go
+++ b/apps/teamhub/internal/voicelive/tools.go
@@ -341,6 +341,12 @@ func Output(value any) string {
return string(encoded)
}
+// DirectYesTools are writes whose content the user already sees, so the
+// user telling the model to do it in their own turn is their yes, unless that
+// turn asked about it or wrote the content; the others read their details
+// back for a yes first.
+var DirectYesTools = map[string]bool{ToolSendEmailCanvas: true}
+
// SentNext tells the live model to report a completed send: without it the
// model can take the result as context and stay silent.
const SentNext = "Tell the user now in one short sentence, in their language, that it was sent and to whom."
@@ -356,7 +362,7 @@ func ErrorOutput(code string) string {
func NeedsConfirmation(summary string) string {
return Output(map[string]string{
"status": "needs_confirmation", "summary": summary,
- "next": "Ask the user this now, once, and end your turn; never answer it for them. If the user already said yes to it while this call ran, do not ask again: call again with confirmed=true now. Otherwise call again with confirmed=true only after they say yes in their own next turn. As you call, say one short complete sentence in their language that you are doing it now, never a single word, since the action can take a few seconds.",
+ "next": "Ask the user this now, once, in your own words with these details, and end your turn; never answer it for them, and do not say you are doing it yet. If the user already said yes to it while this call ran, do not ask again: call again with confirmed=true now. Otherwise call again with confirmed=true only after they say yes in their own next turn, and as you make that call say in one short complete sentence that you are doing it now, since it can take a few seconds.",
})
}
diff --git a/apps/teamhub/tests/integration/voice_live_apps_test.go b/apps/teamhub/tests/integration/voice_live_apps_test.go
index 0198201f..d407747f 100644
--- a/apps/teamhub/tests/integration/voice_live_apps_test.go
+++ b/apps/teamhub/tests/integration/voice_live_apps_test.go
@@ -209,7 +209,8 @@ func TestVoiceLiveSendsAnEmailCanvasOnlyAfterTheUserSaidYes(t *testing.T) {
if saves, _, _ := gmail.counts(); saves != 1 {
t.Fatalf("saves of an unchanged canvas=%d", saves)
}
- // A canvas changed after the question asks again.
+ // A canvas changed after the question is asked about again when the
+ // model is not sure the user wants it sent.
edited := call("lt_edit", "edit-1", "edit_email_canvas", map[string]any{"document_id": documentID, "revision_id": "revision_unseen", "subject": "Wed afternoon pickup"})
if edited["status"] != "changed" {
t.Fatalf("edit=%v", edited)
@@ -221,9 +222,9 @@ func TestVoiceLiveSendsAnEmailCanvasOnlyAfterTheUserSaidYes(t *testing.T) {
gmail.mu.Lock()
gmail.gate = gate
gmail.mu.Unlock()
- if changed := call("lt_yes", "send-3", "send_email_canvas", map[string]any{"document_id": documentID, "confirmed": true}); changed["status"] != "needs_confirmation" ||
+ if changed := call("lt_recheck", "send-3", "send_email_canvas", map[string]any{"document_id": documentID, "confirmed": false}); changed["status"] != "needs_confirmation" ||
!strings.Contains(changed["summary"].(string), "Wed afternoon pickup") {
- t.Fatalf("yes to a changed canvas=%v", changed)
+ t.Fatalf("question about a changed canvas=%v", changed)
}
if saves, sends, _ := gmail.counts(); sends != 0 || saves != 1 {
t.Fatalf("the question waited for the draft: sends=%d saves=%d", sends, saves)
@@ -257,6 +258,47 @@ func TestVoiceLiveSendsAnEmailCanvasOnlyAfterTheUserSaidYes(t *testing.T) {
if countRows(t, env, `SELECT count(*) FROM documents WHERE id=$1 AND owner_actor_id='actor_acme_official'`, documentID) != 1 || roomID == "" {
t.Fatal("canvas missing")
}
+
+ // The canvas is open beside the chat: when the user says to send it, the
+ // first call sends it without asking again.
+ direct := call("lt_write_2", "email-2", "open_email_canvas", map[string]any{
+ "to": "[email protected]", "subject": "Thu pickup", "body": "Hi Amy,\n\nThu 9 am?",
+ })
+ directID, _ := direct["document_id"].(string)
+ if sent := call("lt_send_now", "send-6", "send_email_canvas", map[string]any{"document_id": directID, "confirmed": true}); sent["status"] != "sent" {
+ t.Fatalf("direct send=%v", sent)
+ }
+ if _, sends, _ := gmail.counts(); sends != 2 {
+ t.Fatalf("direct send sends=%d", sends)
+ }
+ // A canvas written or changed in the same turn has not been seen yet:
+ // sending it then reads the details back for a yes first.
+ same := call("lt_write_send", "email-3", "open_email_canvas", map[string]any{
+ "to": "[email protected]", "subject": "Fri pickup", "body": "Hi Amy,\n\nFri 9 am?",
+ })
+ sameID, _ := same["document_id"].(string)
+ savesBefore, _, _ := gmail.counts()
+ if asked := call("lt_write_send", "send-7", "send_email_canvas", map[string]any{"document_id": sameID, "confirmed": true}); asked["status"] != "needs_confirmation" {
+ t.Fatalf("send in the turn that wrote the canvas=%v", asked)
+ }
+ // The question saves its draft in the background; edit once it is done.
+ for deadline := time.Now().Add(10 * time.Second); ; time.Sleep(20 * time.Millisecond) {
+ if saves, _, _ := gmail.counts(); saves > savesBefore {
+ break
+ }
+ if time.Now().After(deadline) {
+ t.Fatal("the draft behind the question was never saved")
+ }
+ }
+ if edited := call("lt_edit_send", "edit-3", "edit_email_canvas", map[string]any{"document_id": sameID, "revision_id": same["revision_id"], "to": "[email protected]"}); edited["status"] != "changed" {
+ t.Fatalf("edit=%v", edited)
+ }
+ if asked := call("lt_edit_send", "send-8", "send_email_canvas", map[string]any{"document_id": sameID, "confirmed": true}); asked["status"] != "needs_confirmation" {
+ t.Fatalf("send in the turn that changed the canvas=%v", asked)
+ }
+ if _, sends, _ := gmail.counts(); sends != 2 {
+ t.Fatalf("a canvas sent before it was seen: sends=%d", sends)
+ }
}
// A canvas that carries a file keeps its Gmail draft saved ahead once it
@@ -338,7 +380,7 @@ func TestVoiceLiveSavesAnAttachedCanvasDraftAhead(t *testing.T) {
if methods := saved(2); methods[1] != http.MethodPut {
t.Fatalf("second draft save=%v", methods)
}
- asked := call("lt_ask", "send-1", "send_email_canvas", map[string]any{"document_id": documentID, "confirmed": true})
+ asked := call("lt_ask", "send-1", "send_email_canvas", map[string]any{"document_id": documentID, "confirmed": false})
if asked["status"] != "needs_confirmation" || !strings.Contains(asked["summary"].(string), "Pickup plan.md") {
t.Fatalf("ask=%v", asked)
}