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.
fix(voice): copy a Live document's playground images in from the Computer
LeoXing25842bf044d1
diff --git a/apps/teamhub/internal/voice/voice_live_documents.go b/apps/teamhub/internal/voice/voice_live_documents.goindex e9fe72e2..62edded7 100644--- a/apps/teamhub/internal/voice/voice_live_documents.go+++ b/apps/teamhub/internal/voice/voice_live_documents.go@@ -39,7 +39,11 @@ func (s *Service) runVoiceLiveDocumentTool(ctx context.Context, session voicelivif !ok || utf8.RuneCountInString(args.Content) > voicelive.MaxCreateDocumentRunes {return "", voicelive.ErrInvalid}- created, output, err := s.openVoiceLiveCanvas(ctx, session, request, title, strings.TrimSpace(args.Content), "invalid_document")+ content, output, err := s.inlineVoiceLiveImages(ctx, session, strings.TrimSpace(args.Content))+ if output != "" || err != nil {+ return output, err+ }+ created, output, err := s.openVoiceLiveCanvas(ctx, session, request, title, content, "invalid_document")if output != "" || err != nil {return output, err}diff --git a/apps/teamhub/internal/voice/voice_live_files.go b/apps/teamhub/internal/voice/voice_live_files.goindex 6288739a..c7a1d8e9 100644--- a/apps/teamhub/internal/voice/voice_live_files.go+++ b/apps/teamhub/internal/voice/voice_live_files.go@@ -1,12 +1,14 @@package voiceimport (+ "bytes""context""encoding/base64""encoding/json""errors""fmt""io"+ "net/http""slices""strconv""strings"@@ -387,3 +389,40 @@ func remarshal(value any, target any) error {}return json.Unmarshal(raw, target)}++// voiceLiveImageTypes are the image types a Document embeds.+var voiceLiveImageTypes = []string{"image/png", "image/jpeg", "image/gif", "image/webp"}++// inlineVoiceLiveImages embeds the ./playground images a new document shows,+// read from the user's Computer, as the Document import takes them. output+// is what the live model is told, naming the image, when one cannot be used.+func (s *Service) inlineVoiceLiveImages(ctx context.Context, session voicelive.Session, markdown string) (string, string, error) {+ uris := map[string]string{}+ for _, image := range voicelive.PlaygroundImages(markdown) {+ folder, inside, output, err := s.voiceLiveFilePath(ctx, session, image)+ if err != nil {+ return "", "", err+ }+ if output == "" {+ var content bytes.Buffer+ if readErr := s.readVoiceLiveFileWhole(ctx, session, folder, inside, &content); readErr != nil {+ if output, err = voiceLiveFileError(readErr); err != nil {+ return "", "", err+ }+ } else if mediaType := http.DetectContentType(content.Bytes()); !slices.Contains(voiceLiveImageTypes, mediaType) {+ output = voicelive.ErrorOutput("not_an_image")+ } else {+ uris[image] = "data:" + mediaType + ";base64," + base64.StdEncoding.EncodeToString(content.Bytes())+ }+ }+ if output != "" {+ var fields map[string]any+ if err := json.Unmarshal([]byte(output), &fields); err != nil {+ return "", "", err+ }+ fields["image"] = image+ return "", voicelive.Output(fields), nil+ }+ }+ return voicelive.InlineImages(markdown, uris), "", nil+}diff --git a/apps/teamhub/internal/voicelive/document_images.go b/apps/teamhub/internal/voicelive/document_images.gonew file mode 100644index 00000000..d83df068--- /dev/null+++ b/apps/teamhub/internal/voicelive/document_images.go@@ -0,0 +1,42 @@+package voicelive++import (+ "slices"+ "strings"++ "github.com/yuin/goldmark"+ "github.com/yuin/goldmark/ast"+ "github.com/yuin/goldmark/extension"+ goldmarktext "github.com/yuin/goldmark/text"+)++// PlaygroundImages returns the files under ./playground that Markdown shows+// as images, each once, as written. Other images, such as web links, are+// left to the Document import.+func PlaygroundImages(markdown string) []string {+ source := []byte(markdown)+ root := goldmark.New(goldmark.WithExtensions(extension.GFM)).Parser().Parse(goldmarktext.NewReader(source))+ var found []string+ _ = ast.Walk(root, func(node ast.Node, entering bool) (ast.WalkStatus, error) {+ image, ok := node.(*ast.Image)+ if !entering || !ok {+ return ast.WalkContinue, nil+ }+ destination := string(image.Destination)+ parsed, ok := ParsePlaygroundPath(destination)+ if ok && parsed.Folder != "" && parsed.Inside != "" && !slices.Contains(found, destination) {+ found = append(found, destination)+ }+ return ast.WalkContinue, nil+ })+ return found+}++// InlineImages points each image at the data URI given for its destination.+func InlineImages(markdown string, uris map[string]string) string {+ pairs := make([]string, 0, 2*len(uris))+ for destination, uri := range uris {+ pairs = append(pairs, "]("+destination, "]("+uri)+ }+ return strings.NewReplacer(pairs...).Replace(markdown)+}diff --git a/apps/teamhub/internal/voicelive/documents.go b/apps/teamhub/internal/voicelive/documents.goindex 68a61ce6..b9539f32 100644--- a/apps/teamhub/internal/voicelive/documents.go+++ b/apps/teamhub/internal/voicelive/documents.go@@ -34,6 +34,7 @@ var DocumentTools = []Tool{Name: ToolCreateDocument,Description: "Create a new document in this room and open it beside the chat, such as meeting notes, a plan, a checklist or a draft the user asks for (“make a doc”, “write this up”). " +"title is one line; content is the whole body in Markdown, written only from what the user said and this conversation; never invent facts, names or numbers. An empty content makes an empty document. " ++ "To show an image from the user's computer, such as one a task made, write  with its path as ls prints it; it is copied into the document. An error with image names the one to fix, and nothing was created. " +"It returns document_id and revision_id. Then say in one short sentence what you wrote and that it is open beside the chat. Change it later with edit_document, replace_document_text or rename_document. " +"An email is open_email_canvas; research and long reports are start_task.",Parameters: objectSchema([]string{"title"}, map[string]any{diff --git a/apps/teamhub/internal/voicelive/playground_test.go b/apps/teamhub/internal/voicelive/playground_test.goindex d1228658..b759b5c2 100644--- a/apps/teamhub/internal/voicelive/playground_test.go+++ b/apps/teamhub/internal/voicelive/playground_test.go@@ -2,6 +2,7 @@ package voiceliveimport ("encoding/json"+ "slices""strings""testing""time"@@ -69,3 +70,19 @@ func TestEveryToolSchemaHasARequiredList(t *testing.T) {}}}++func TestPlaygroundImagesInlineOnlyPlaygroundFiles(t *testing.T) {+ markdown := "# Title\n\n\n\n\n\n" ++ " \n\n" ++ "```\n\n```\n\n \n"+ images := PlaygroundImages(markdown)+ if want := []string{"./playground/workitem_1/a.png", "playground/room_1/c.jpg"}; !slices.Equal(images, want) {+ t.Fatalf("images=%q, want %q", images, want)+ }+ inlined := InlineImages(markdown, map[string]string{images[0]: "data:image/png;base64,QQ==", images[1]: "data:image/jpeg;base64,Qg=="})+ for _, want := range []string{"", "", "", ""} {+ if !strings.Contains(inlined, want) {+ t.Fatalf("inlined lacks %q:\n%s", want, inlined)+ }+ }+}diff --git a/apps/teamhub/tests/integration/voice_live_test.go b/apps/teamhub/tests/integration/voice_live_test.goindex a85761e3..a4113b72 100644--- a/apps/teamhub/tests/integration/voice_live_test.go+++ b/apps/teamhub/tests/integration/voice_live_test.go@@ -583,7 +583,7 @@ func TestVoiceLiveProgressAndTodayRecallReadOnlyWhatTheHumanCanSee(t *testing.T)func TestVoiceLiveTasksReportResultsAndWhatTheyWaitFor(t *testing.T) {allowParallelIntegrationTest(t)- env, alice, _, sessionID := newVoiceLiveRoom(t)+ env, alice, roomID, sessionID := newVoiceLiveRoom(t)tool := func(turnID, callID, name string, arguments map[string]any) map[string]any {encoded, _ := json.Marshal(arguments)var result teamhubinternal.VoiceLiveToolResult@@ -738,6 +738,15 @@ func TestVoiceLiveTasksReportResultsAndWhatTheyWaitFor(t *testing.T) {if countRows(t, env, `SELECT count(*) FROM voice_live_report_deliveries WHERE voice_session_id=$1`, sessionID) != 0 {t.Fatal("a card that was not posted marked its report delivered")}+ // A new document's images under ./playground come from the Computer too;+ // one that cannot be read names itself, and nothing is created.+ image := folder + "strawberry.png"+ if output := tool("lt_doc", "doc-1", "create_document", map[string]any{"title": "Strawberries", "content": "# Strawberries\n\n\n"}); output["error"] != "computer_offline" || output["image"] != image {+ t.Fatalf("create_document with an unreadable image=%v", output)+ }+ if countRows(t, env, `SELECT count(*) FROM messages WHERE room_id=$1 AND segments @> '[{"presentation":"canvas"}]'`, roomID) != 0 {+ t.Fatal("a document whose image was not read was opened")+ }decode(t, voiceRuntimeCall(t, env, http.MethodGet, "/internal/v1/voice/sessions/"+sessionID+"/live-tasks", nil, http.StatusOK), &tasks)if len(tasks.Tasks) != 2 || tasks.Tasks[0].TaskId != first["task_id"] || *tasks.Tasks[0].Replies[0].Delivered {t.Fatalf("live tasks after an unposted card: %+v", tasks.Tasks)