Telegram dropped every incoming photo, document, video and audio message: the default handler required message text, and nothing on the turn path knew media existed. The receiving path now closes the gap end to end. - telegram: extract the attachment from the update (largest photo, plus document, video, video-note, audio and voice kinds), download its bytes on the turn lane through getFile + the Bot API file link with a 20 MB gate, submit the turn with the attachment, and answer unsupported content kinds (sticker, location, contact, poll) with a clear notice instead of silence - messaging: Inbound carries turn-scoped transport media and MediaAttachment a Data field for in-process bytes; Message gains Media attachment metadata which stores persist (Postgres jsonb via migration 0020, memory store) with Data stripped at the persist boundary, and pb.Message carries the metadata on the gateway wire - gateway: TurnModelRequest threads the turn's media to the model seam - archied: the chat turn model merges the attachments into the final user message as ai-sdk image/file part entries, so vision-capable models see the file for the turn it arrived in; stored history keeps the placeholder note plus caption Session log: messages carry what was sent as data (the attachment metadata), not just prose. Transcript rendering of attachments and a re-look capability are tracked as archie-core-jaba.
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
)
|
|
|
|
// TestTurnRunnerGivesInboundMediaToTheModelRequest pins the handoff point
|
|
// between the adapter and the model seam: media a channel attached to an
|
|
// inbound message must reach the model request, or the channel's work is
|
|
// lost and the turn answers on caption text alone.
|
|
func TestTurnRunnerGivesInboundMediaToTheModelRequest(t *testing.T) {
|
|
store := NewSessionStoreMemory()
|
|
router := NewRouter(nil, nil, "telegram")
|
|
router.Identity = "archie"
|
|
router.InitSessions(store)
|
|
|
|
prepared := &turnTestPreparedModel{reply: "answer"}
|
|
model := &turnTestModel{prepared: prepared}
|
|
runner := NewTurnRunner(TurnRunnerConfig{
|
|
Router: router,
|
|
Sessions: store,
|
|
Models: &fakeModelManager{models: []string{"test/model"}, activeModel: "test/model"},
|
|
Personas: NewPersonaRegistry(DefaultPersonas()),
|
|
Model: model,
|
|
BotUser: "archie",
|
|
Channel: "telegram",
|
|
Operator: "Sam",
|
|
Log: slog.New(slog.DiscardHandler),
|
|
})
|
|
|
|
media := []messaging.MediaAttachment{{Type: "image", MIMEType: "image/png", Data: []byte("png-bytes")}}
|
|
_, err := runner.Run(context.Background(), Inbound{
|
|
Message: messaging.Message{
|
|
SourceID: "src-media",
|
|
ConversationID: messaging.ConversationID{ChannelID: "chat-media"},
|
|
Sender: "user",
|
|
Role: messaging.RoleUser,
|
|
Text: "look at this",
|
|
},
|
|
Media: media,
|
|
}, DeltaFunc(func(string) {}))
|
|
if err != nil {
|
|
t.Fatalf("Run() error = %v", err)
|
|
}
|
|
if len(prepared.lastRequest.Media) != 1 {
|
|
t.Fatalf("model request media = %#v, want the one inbound attachment", prepared.lastRequest.Media)
|
|
}
|
|
if !reflect.DeepEqual(prepared.lastRequest.Media, media) {
|
|
t.Errorf("model request media = %#v, want %#v", prepared.lastRequest.Media, media)
|
|
}
|
|
}
|