551 lines
20 KiB
Go
551 lines
20 KiB
Go
package opencode
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
"sync"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// ErrPermissionUnsupported reports that the connected OpenCode backend does not
|
|
// expose the brokered approval surface. The native v1 serve translation returns
|
|
// it; callers treat it as a documented limitation rather than an operational
|
|
// failure, so a chat prompt does not emit a permission error frame on a backend
|
|
// that cannot answer one.
|
|
var ErrPermissionUnsupported = errors.New("OpenCode permission approval is not implemented for the native serve backend")
|
|
|
|
// Chat is the brokered OpenCode chat adapter (route B in the research): the
|
|
// Pipelines server owns the OpenCode endpoint and credentials and turns the v2
|
|
// HTTP API into protocol.ChatEventFrame frames. It reuses the owned-endpoint
|
|
// semantics, the session-id shape and the 64 KiB / 1 MiB bounds of Connection so
|
|
// no second transport or credential path is introduced.
|
|
type Chat struct {
|
|
conn *Connection
|
|
// mu serializes the adapter's HTTP calls. Connection records its last
|
|
// operation and status on the shared connection, so two calls must not
|
|
// overlap; the permission poller runs alongside the read loop's
|
|
// prompt/interrupt/reply calls.
|
|
mu sync.Mutex
|
|
}
|
|
|
|
// NewChat brokers chat for one owned OpenCode endpoint. The connection must be
|
|
// able to reach the /api HTTP surface: an owned serve connection (translated by
|
|
// Connection.Call) or a connection that already carries the v2 API URL.
|
|
func NewChat(conn *Connection) *Chat { return &Chat{conn: conn} }
|
|
|
|
// ValidSessionID reports whether id has the OpenCode session-id shape the
|
|
// native adapter already accepts. It is the single validation shared by the
|
|
// chat adapter and callers that must reject a request before any OpenCode call.
|
|
func ValidSessionID(id string) bool { return sessionID.MatchString(id) }
|
|
|
|
// call serializes the adapter's HTTP calls and forwards them through the shared
|
|
// Connection, so no second transport is introduced and Connection's recorded
|
|
// last operation/status is never written by two goroutines at once.
|
|
func (c *Chat) call(ctx context.Context, method, path string, body any) ([]byte, error) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
return c.conn.Call(ctx, method, path, body)
|
|
}
|
|
|
|
// Prompt forwards one chat prompt through the existing Call translation
|
|
// (authenticated, bounded, directory-scoped). The endpoint returns the inbox
|
|
// envelope immediately; the reply arrives on Stream.
|
|
func (c *Chat) Prompt(ctx context.Context, id, text string) error {
|
|
if !sessionID.MatchString(id) {
|
|
return fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
if strings.TrimSpace(text) == "" {
|
|
return fmt.Errorf("empty chat prompt")
|
|
}
|
|
body := map[string]any{"parts": []map[string]string{{"type": "text", "text": text}}}
|
|
if _, err := c.call(ctx, "post", "/api/session/"+id+"/prompt", body); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Interrupt aborts the session's active run, reusing the same translated surface.
|
|
func (c *Chat) Interrupt(ctx context.Context, id string) error {
|
|
if !sessionID.MatchString(id) {
|
|
return fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
if _, err := c.call(ctx, "post", "/api/session/"+id+"/interrupt", map[string]any{}); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Messages reads one session's stored turns. On the owned serve backend it
|
|
// reuses Connection.Messages, including its read-only OutputFormat readback
|
|
// fallback, instead of duplicating that path. It maps the verified assistant
|
|
// content parts (text | reasoning | tool) onto protocol.ChatMessage.
|
|
func (c *Chat) Messages(ctx context.Context, id string, limit int) ([]protocol.ChatMessage, error) {
|
|
if !sessionID.MatchString(id) {
|
|
return nil, fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
var data []byte
|
|
var err error
|
|
c.mu.Lock()
|
|
if c.conn.Backend == "v1" {
|
|
data, err = c.conn.Messages(ctx, id)
|
|
} else {
|
|
path := "/api/session/" + id + "/message"
|
|
if limit > 0 {
|
|
path += fmt.Sprintf("?limit=%d", limit)
|
|
}
|
|
data, err = c.conn.Call(ctx, "get", path, nil)
|
|
}
|
|
c.mu.Unlock()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return decodeChatMessages(id, data)
|
|
}
|
|
|
|
// Reply posts a permission decision, mirroring the documented endpoint.
|
|
func (c *Chat) Reply(ctx context.Context, request protocol.ChatReplyRequest) error {
|
|
if !sessionID.MatchString(request.SessionID) {
|
|
return fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
if request.RequestID == "" {
|
|
return fmt.Errorf("missing permission request id")
|
|
}
|
|
decision := request.Decision
|
|
if decision != protocol.ChatDecisionOnce && decision != protocol.ChatDecisionAlways && decision != protocol.ChatDecisionReject {
|
|
return fmt.Errorf("invalid permission decision %q", decision)
|
|
}
|
|
body := map[string]any{"decision": decision}
|
|
if request.Message != "" {
|
|
body["message"] = request.Message
|
|
}
|
|
path := "/api/session/" + request.SessionID + "/permission/" + request.RequestID + "/reply"
|
|
if _, err := c.call(ctx, "post", path, body); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Permissions lists the session's pending OpenCode approval requests, mirroring
|
|
// GET /api/permission/request. The endpoint is global, so the decoded list is
|
|
// filtered to sessionID; a malformed response is an error, never an empty
|
|
// success. It reuses Connection.Call so the request keeps the shared bounds,
|
|
// auth and translation, and reuses ValidSessionID for the same rejection the
|
|
// other chat calls apply.
|
|
func (c *Chat) Permissions(ctx context.Context, id string) ([]protocol.ChatPermissionFrame, error) {
|
|
if !sessionID.MatchString(id) {
|
|
return nil, fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
data, err := c.call(ctx, "get", "/api/permission/request", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return decodeChatPermissions(id, data)
|
|
}
|
|
|
|
// nativeChatPermission is one pending approval request matching the V2
|
|
// Permission.Request schema verified against the service's /openapi.json: id,
|
|
// sessionID, action and resources are required; save, metadata, source and
|
|
// message are optional, so the decoder tolerates any of them being absent.
|
|
type nativeChatPermission struct {
|
|
ID string `json:"id"`
|
|
SessionID string `json:"sessionID"`
|
|
Action string `json:"action"`
|
|
Resources []string `json:"resources"`
|
|
Save []string `json:"save"`
|
|
Metadata map[string]any `json:"metadata"`
|
|
Source *nativeChatPermissionSource `json:"source"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// nativeChatPermissionSource is the incoming Permission.Source union; its single
|
|
// (tool) member carries type plus the message id and call id (the protocol frame
|
|
// renames messageID to message_id).
|
|
type nativeChatPermissionSource struct {
|
|
Type string `json:"type"`
|
|
MessageID string `json:"messageID"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
// chatEnvelope unwraps the {"data":[...]} envelope the V2 HTTP API returns and
|
|
// reports whether the body was that envelope with a non-nil data array; a bare
|
|
// array or a malformed body returns ok=false. It is the single envelope rule the
|
|
// message and permission decoders share instead of each re-deriving it.
|
|
func chatEnvelope[T any](data []byte) ([]T, bool) {
|
|
var response struct {
|
|
Data []T `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(data, &response); err != nil || response.Data == nil {
|
|
return nil, false
|
|
}
|
|
return response.Data, true
|
|
}
|
|
|
|
// chatPermissionRecords reads the {"data":[...]} envelope the V2 endpoint
|
|
// returns. An unparseable body or a missing data array is an error, never an
|
|
// empty list.
|
|
func chatPermissionRecords(data []byte) ([]nativeChatPermission, error) {
|
|
records, ok := chatEnvelope[nativeChatPermission](data)
|
|
if !ok {
|
|
return nil, fmt.Errorf("invalid OpenCode permission response")
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
// decodeChatPermissions maps the pending-request list onto protocol frames,
|
|
// keeping only the requested session's requests (a request with no id cannot be
|
|
// answered and is dropped).
|
|
func decodeChatPermissions(sessionID string, data []byte) ([]protocol.ChatPermissionFrame, error) {
|
|
records, err := chatPermissionRecords(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
frames := make([]protocol.ChatPermissionFrame, 0, len(records))
|
|
for _, record := range records {
|
|
if record.SessionID != sessionID || record.ID == "" {
|
|
continue
|
|
}
|
|
frame := protocol.ChatPermissionFrame{
|
|
SessionID: sessionID,
|
|
RequestID: record.ID,
|
|
Action: record.Action,
|
|
Resources: record.Resources,
|
|
Save: record.Save,
|
|
Metadata: record.Metadata,
|
|
Message: record.Message,
|
|
}
|
|
if record.Source != nil {
|
|
frame.Source = &protocol.ChatPermissionSource{Type: record.Source.Type, MessageID: record.Source.MessageID, ID: record.Source.ID}
|
|
}
|
|
frames = append(frames, frame)
|
|
}
|
|
return frames, nil
|
|
}
|
|
|
|
// Stream subscribes to the OpenCode event firehose and invokes emit for every
|
|
// frame belonging to sessionID. It reads one bounded SSE frame at a time and
|
|
// never polls the per-session message log; the global firehose is the only
|
|
// source of token-level deltas on this build. ready, when non-nil, is called
|
|
// once the subscription is attached and before the first frame is read, so a
|
|
// caller can post its prompt only after the stream is listening (the firehose
|
|
// has no replay cursor). Canceling ctx cancels the subscription and returns
|
|
// without leaking a connection.
|
|
func (c *Chat) Stream(ctx context.Context, id string, ready func(), emit func(protocol.ChatEventFrame) error) error {
|
|
if !sessionID.MatchString(id) {
|
|
return fmt.Errorf("invalid OpenCode session id")
|
|
}
|
|
body, err := c.conn.EventStream(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer body.Close()
|
|
if ready != nil {
|
|
ready()
|
|
}
|
|
return scanChatEvents(ctx, body, id, emit)
|
|
}
|
|
|
|
// scanChatEvents turns an SSE body into protocol frames, one bounded frame at a
|
|
// time. Heartbeat comments, blank lines and unrelated event types are ignored;
|
|
// malformed JSON fails the stream instead of producing a malformed frame. The
|
|
// last assistant message id is retained so a later tool/step event that omits it
|
|
// still attributes every frame to a stable message.
|
|
func scanChatEvents(ctx context.Context, body io.Reader, sessionID string, emit func(protocol.ChatEventFrame) error) error {
|
|
scanner := bufio.NewScanner(body)
|
|
scanner.Buffer(make([]byte, 0, 64<<10), MaxResponse)
|
|
lastMessageID := ""
|
|
for scanner.Scan() {
|
|
if err := ctx.Err(); err != nil {
|
|
return err
|
|
}
|
|
line := bytes.TrimSpace(scanner.Bytes())
|
|
if !bytes.HasPrefix(line, []byte("data:")) {
|
|
continue
|
|
}
|
|
payload := bytes.TrimSpace(line[len("data:"):])
|
|
if len(payload) == 0 {
|
|
continue
|
|
}
|
|
frame, ok, err := NormalizeChatEvent(payload, sessionID, &lastMessageID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !ok {
|
|
continue
|
|
}
|
|
if frame.MessageID != "" {
|
|
lastMessageID = frame.MessageID
|
|
}
|
|
if err := emit(frame); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if err := scanner.Err(); err != nil {
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
return fmt.Errorf("OpenCode event stream read failed")
|
|
}
|
|
return ctx.Err()
|
|
}
|
|
|
|
// chatEvent is the subset of the verified firehose envelope this adapter reads:
|
|
// {"type":"session.text.delta","data":{...}}. Fields absent from a given event
|
|
// stay zero so one struct covers every type.
|
|
type chatEvent struct {
|
|
SessionID string `json:"sessionID"`
|
|
MessageID string `json:"assistantMessageID"`
|
|
MessageIDAlt string `json:"messageID"`
|
|
Delta string `json:"delta"`
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Input json.RawMessage `json:"input"`
|
|
Content []protocol.ChatToolContent `json:"content"`
|
|
Metadata map[string]any `json:"metadata"`
|
|
Error *protocol.ChatError `json:"error"`
|
|
Ordinal int `json:"ordinal"`
|
|
Index int `json:"index"`
|
|
Step int `json:"step"`
|
|
InputTokens int `json:"inputTokens"`
|
|
OutputTokens int `json:"outputTokens"`
|
|
Cost float64 `json:"cost"`
|
|
Tokens struct {
|
|
Input int `json:"input"`
|
|
Output int `json:"output"`
|
|
} `json:"tokens"`
|
|
}
|
|
|
|
// NormalizeChatEvent maps one OpenCode firehose `data:` payload to a
|
|
// protocol.ChatEventFrame. ok is false for an event type this adapter does not
|
|
// surface or one belonging to a different session, so the caller can skip it
|
|
// without emitting a frame. Malformed JSON returns an error and never a frame.
|
|
func NormalizeChatEvent(payload []byte, sessionID string, lastMessageID *string) (protocol.ChatEventFrame, bool, error) {
|
|
var outer struct {
|
|
Type string `json:"type"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(payload, &outer); err != nil {
|
|
return protocol.ChatEventFrame{}, false, fmt.Errorf("malformed OpenCode event: %w", err)
|
|
}
|
|
if outer.Type == "" || len(outer.Data) == 0 {
|
|
return protocol.ChatEventFrame{}, false, nil
|
|
}
|
|
var data chatEvent
|
|
if err := json.Unmarshal(outer.Data, &data); err != nil {
|
|
return protocol.ChatEventFrame{}, false, fmt.Errorf("malformed OpenCode event data: %w", err)
|
|
}
|
|
if data.SessionID != sessionID {
|
|
return protocol.ChatEventFrame{}, false, nil
|
|
}
|
|
messageID := data.MessageID
|
|
if messageID == "" {
|
|
messageID = data.MessageIDAlt
|
|
}
|
|
if messageID == "" && lastMessageID != nil {
|
|
messageID = *lastMessageID
|
|
}
|
|
// Every pushed frame must carry a stable message id so the client can
|
|
// attribute it; without one this is not a chat frame.
|
|
if messageID == "" {
|
|
return protocol.ChatEventFrame{}, false, nil
|
|
}
|
|
frame := protocol.ChatEventFrame{SessionID: sessionID, MessageID: messageID}
|
|
switch {
|
|
case outer.Type == "session.text.delta":
|
|
frame.Kind = protocol.ChatEventText
|
|
frame.Delta = data.Delta
|
|
frame.Part = &protocol.ChatPart{Type: protocol.ChatPartText, ID: fmt.Sprintf("%s#%d", messageID, data.Ordinal)}
|
|
case outer.Type == "session.reasoning.delta":
|
|
frame.Kind = protocol.ChatEventReasoning
|
|
frame.Delta = data.Delta
|
|
frame.Part = &protocol.ChatPart{Type: protocol.ChatPartReasoning, ID: fmt.Sprintf("%s#%d", messageID, data.Ordinal)}
|
|
case outer.Type == "session.step.started" || outer.Type == "session.step.streamed" || outer.Type == "session.step.ended":
|
|
frame.Kind = protocol.ChatEventStep
|
|
frame.Step = &protocol.ChatStep{Status: strings.TrimPrefix(outer.Type, "session.step."), Index: stepIndex(data)}
|
|
case strings.HasPrefix(outer.Type, "session.tool."):
|
|
status, ok := toolStatus(outer.Type)
|
|
if !ok {
|
|
return protocol.ChatEventFrame{}, false, nil
|
|
}
|
|
frame.Kind = protocol.ChatEventTool
|
|
state := &protocol.ChatToolState{Status: status, Input: data.Input, Content: data.Content, Metadata: data.Metadata, Error: data.Error}
|
|
frame.Part = &protocol.ChatPart{Type: protocol.ChatPartTool, ID: data.ID, Name: data.Name, State: state}
|
|
case outer.Type == "session.usage.updated":
|
|
frame.Kind = protocol.ChatEventUsage
|
|
input, output := data.InputTokens, data.OutputTokens
|
|
if data.Tokens.Input != 0 || data.Tokens.Output != 0 {
|
|
input, output = data.Tokens.Input, data.Tokens.Output
|
|
}
|
|
frame.Usage = &protocol.ChatUsage{InputTokens: input, OutputTokens: output, Cost: data.Cost}
|
|
default:
|
|
return protocol.ChatEventFrame{}, false, nil
|
|
}
|
|
return frame, true, nil
|
|
}
|
|
|
|
// toolStatus maps the verified tool event types onto the ToolState lifecycle.
|
|
func toolStatus(eventType string) (string, bool) {
|
|
switch eventType {
|
|
case "session.tool.input.started", "session.tool.input.ended":
|
|
return protocol.ChatToolStreaming, true
|
|
case "session.tool.called", "session.tool.progress":
|
|
return protocol.ChatToolRunning, true
|
|
case "session.tool.success":
|
|
return protocol.ChatToolCompleted, true
|
|
case "session.tool.failed":
|
|
return protocol.ChatToolError, true
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
func stepIndex(data chatEvent) int {
|
|
if data.Step > 0 {
|
|
return data.Step
|
|
}
|
|
return data.Index
|
|
}
|
|
|
|
// nativeChatMessage is one stored turn. The two surfaces return different
|
|
// envelopes for the same session and both decode into this one struct, so the
|
|
// mapping below reads whichever fields a record populated:
|
|
//
|
|
// - the V2 HTTP API (GET /api/session/{id}/message) puts id/type/agent/model,
|
|
// the timing and the parts array at the message top level, with the parts
|
|
// under "content" and a user turn's text as a bare string;
|
|
// - the native serve readback nests the same fields under "info" (role as
|
|
// "role", model as "modelID", timing as "created") with the parts under
|
|
// "parts".
|
|
type nativeChatMessage struct {
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
Agent string `json:"agent"`
|
|
Model nativeChatModel `json:"model"`
|
|
Time *protocol.ChatTime `json:"time"`
|
|
Text string `json:"text"`
|
|
Content []nativeChatPart `json:"content"`
|
|
Info struct {
|
|
ID string `json:"id"`
|
|
Role string `json:"role"`
|
|
ModelID string `json:"modelID"`
|
|
Agent string `json:"agent"`
|
|
CreatedAt int64 `json:"created"`
|
|
} `json:"info"`
|
|
Parts []nativeChatPart `json:"parts"`
|
|
}
|
|
|
|
// nativeChatModel is the nested Model.Ref a V2 turn carries ({id, providerID,
|
|
// variant}); only the model id is surfaced in the protocol message.
|
|
type nativeChatModel struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
// nativeChatPart is one content element shared by both message envelopes.
|
|
type nativeChatPart struct {
|
|
Type string `json:"type"`
|
|
ID string `json:"id"`
|
|
Text string `json:"text"`
|
|
Name string `json:"name"`
|
|
Executed bool `json:"executed"`
|
|
State *protocol.ChatToolState `json:"state"`
|
|
Time *protocol.ChatTime `json:"time"`
|
|
}
|
|
|
|
// role, parts and the accessor methods below read the V2 top-level fields first
|
|
// and fall back to the native serve "info"/"parts" fields, so one record maps
|
|
// regardless of which surface produced it.
|
|
|
|
func (m nativeChatMessage) role() string {
|
|
if m.Info.Role != "" {
|
|
return m.Info.Role
|
|
}
|
|
return m.Type
|
|
}
|
|
|
|
func (m nativeChatMessage) messageID() string {
|
|
if m.Info.ID != "" {
|
|
return m.Info.ID
|
|
}
|
|
return m.ID
|
|
}
|
|
|
|
func (m nativeChatMessage) modelID() string {
|
|
if m.Info.ModelID != "" {
|
|
return m.Info.ModelID
|
|
}
|
|
return m.Model.ID
|
|
}
|
|
|
|
func (m nativeChatMessage) agent() string {
|
|
if m.Info.Agent != "" {
|
|
return m.Info.Agent
|
|
}
|
|
return m.Agent
|
|
}
|
|
|
|
func (m nativeChatMessage) createdAt() int64 {
|
|
if m.Info.CreatedAt != 0 {
|
|
return m.Info.CreatedAt
|
|
}
|
|
if m.Time != nil {
|
|
return m.Time.Created
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (m nativeChatMessage) contentParts() []nativeChatPart {
|
|
if m.Parts != nil {
|
|
return m.Parts
|
|
}
|
|
return m.Content
|
|
}
|
|
|
|
// chatMessageRecords accepts both message envelopes the two surfaces return:
|
|
// the V2 HTTP API wraps them in {"data":[...]} while the native serve readback
|
|
// returns a bare array. An unrecognised body is an error, never empty history.
|
|
func chatMessageRecords(data []byte) ([]nativeChatMessage, error) {
|
|
if records, ok := chatEnvelope[nativeChatMessage](data); ok {
|
|
return records, nil
|
|
}
|
|
var records []nativeChatMessage
|
|
if err := json.Unmarshal(data, &records); err != nil {
|
|
return nil, fmt.Errorf("invalid OpenCode message response")
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
func decodeChatMessages(sessionID string, data []byte) ([]protocol.ChatMessage, error) {
|
|
records, err := chatMessageRecords(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
messages := make([]protocol.ChatMessage, 0, len(records))
|
|
for _, record := range records {
|
|
role := record.role()
|
|
if role != protocol.ChatRoleUser && role != protocol.ChatRoleAssistant {
|
|
continue
|
|
}
|
|
out := protocol.ChatMessage{ID: record.messageID(), SessionID: sessionID, Role: role, Model: record.modelID(), Agent: record.agent(), CreatedAt: record.createdAt()}
|
|
for _, part := range record.contentParts() {
|
|
switch part.Type {
|
|
case protocol.ChatPartText, protocol.ChatPartReasoning:
|
|
out.Parts = append(out.Parts, protocol.ChatPart{Type: part.Type, ID: part.ID, Text: part.Text})
|
|
case protocol.ChatPartTool:
|
|
out.Parts = append(out.Parts, protocol.ChatPart{Type: protocol.ChatPartTool, ID: part.ID, Name: part.Name, Executed: part.Executed, State: part.State, Time: part.Time})
|
|
}
|
|
}
|
|
// A V2 user turn carries its prompt text as a message-level string rather
|
|
// than a content array, so surface it as the turn's single text part.
|
|
if len(out.Parts) == 0 && role == protocol.ChatRoleUser && record.Text != "" {
|
|
out.Parts = append(out.Parts, protocol.ChatPart{Type: protocol.ChatPartText, Text: record.Text})
|
|
}
|
|
messages = append(messages, out)
|
|
}
|
|
return messages, nil
|
|
}
|