Image input
This commit is contained in:
+15
-4
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +15,7 @@ type QueuedTurn struct {
|
||||
Vendor api.AgentSessionVendor
|
||||
Actor string
|
||||
Text string
|
||||
Images []string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
@@ -44,16 +46,20 @@ func (s *Store) CountRunning(ctx context.Context) (map[api.AgentSessionVendor]in
|
||||
}
|
||||
|
||||
func (s *Store) EnqueueTurn(ctx context.Context, q QueuedTurn) error {
|
||||
images, err := json.Marshal(append([]string{}, q.Images...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `INSERT INTO turn_queue (session_id, actor, text, created_at) VALUES (?, ?, ?, ?)`,
|
||||
q.SessionID, q.Actor, q.Text, formatTime(q.CreatedAt))
|
||||
_, err := tx.ExecContext(ctx, `INSERT INTO turn_queue (session_id, actor, text, images, created_at) VALUES (?, ?, ?, ?, ?)`,
|
||||
q.SessionID, q.Actor, q.Text, string(images), formatTime(q.CreatedAt))
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) QueuedTurns(ctx context.Context) ([]QueuedTurn, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `
|
||||
SELECT q.session_id, s.vendor, q.actor, q.text, q.created_at
|
||||
SELECT q.session_id, s.vendor, q.actor, q.text, q.images, q.created_at
|
||||
FROM turn_queue q JOIN agent_sessions s ON s.id = q.session_id
|
||||
ORDER BY q.created_at
|
||||
`)
|
||||
@@ -66,8 +72,13 @@ func (s *Store) QueuedTurns(ctx context.Context) ([]QueuedTurn, error) {
|
||||
for rows.Next() {
|
||||
q := QueuedTurn{}
|
||||
vendor := ""
|
||||
images := ""
|
||||
createdAt := ""
|
||||
err = rows.Scan(&q.SessionID, &vendor, &q.Actor, &q.Text, &createdAt)
|
||||
err = rows.Scan(&q.SessionID, &vendor, &q.Actor, &q.Text, &images, &createdAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(images), &q.Images)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user