feat(dingtalk): stabilize multimodal answer workflows

This commit is contained in:
姚章浩
2026-09-09 13:57:43 +08:00
parent 18c81232ce
commit 0798a2dac7
46 changed files with 2309 additions and 195 deletions
@@ -2,6 +2,7 @@ package postgres
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
@@ -82,6 +83,7 @@ func (r *QuestionTableExportRepository) Claim(ctx context.Context, limit int, ma
cl.attempts,
t.question,
t.answer,
t.question_image_urls_json,
m.created_at,
COALESCE(m.actor_name_snapshot, '') AS actor_name_snapshot,
COALESCE(m.actor_union_id_snapshot, '') AS actor_union_id_snapshot,
@@ -109,6 +111,7 @@ func (r *QuestionTableExportRepository) Claim(ctx context.Context, limit int, ma
attempts int
question string
answer string
imageURLsJSON []byte
askedTime time.Time
actorNameSnapshot string
actorUnionIDSnapshot string
@@ -117,25 +120,32 @@ func (r *QuestionTableExportRepository) Claim(ctx context.Context, limit int, ma
regionSnap string
)
if err := rows.Scan(&exportID, &attempts,
&question, &answer,
&question, &answer, &imageURLsJSON,
&askedTime,
&actorNameSnapshot, &actorUnionIDSnapshot,
&triggerPersonSnap, &departmentSnap, &regionSnap); err != nil {
rows.Close()
return nil, fmt.Errorf("questiontable export claim scan: %w", err)
}
var imageURLs []string
if len(imageURLsJSON) > 0 {
if err := json.Unmarshal(imageURLsJSON, &imageURLs); err != nil {
imageURLs = nil
}
}
exports = append(exports, questiontable.PendingExport{
ExportID: exportID,
Attempts: attempts,
Row: questiontable.Row{
Question: question,
Answer: answer,
AskedTime: askedTime,
AskerName: actorNameSnapshot,
AskerUnionID: actorUnionIDSnapshot,
TriggerPerson: triggerPersonSnap,
Department: departmentSnap,
Region: regionSnap,
Question: question,
Answer: answer,
AskedTime: askedTime,
AskerName: actorNameSnapshot,
AskerUnionID: actorUnionIDSnapshot,
TriggerPerson: triggerPersonSnap,
Department: departmentSnap,
Region: regionSnap,
QuestionImageURLs: imageURLs,
},
})
}
+13 -5
View File
@@ -56,6 +56,14 @@ func (s *Store) BeginTurn(ctx context.Context, turn core.Turn) (core.Turn, bool,
if err != nil {
return core.Turn{}, false, err
}
imageURLs := turn.QuestionImageURLs
if imageURLs == nil {
imageURLs = []string{}
}
imageURLsJSON, err := json.Marshal(imageURLs)
if err != nil {
return core.Turn{}, false, err
}
tx, err := s.pool.BeginTx(ctx, pgx.TxOptions{})
if err != nil {
return core.Turn{}, false, err
@@ -106,10 +114,10 @@ func (s *Store) BeginTurn(ctx context.Context, turn core.Turn) (core.Turn, bool,
}
command, err := tx.Exec(ctx, `INSERT INTO turns
(id,tenant_key,channel,external_message_id,session_key,question,status,media_json,request_message_id,agent_id)
VALUES($1,$2,$3,$4,$5,$6,'processing',$7,$8,$9) ON CONFLICT DO NOTHING`,
(id,tenant_key,channel,external_message_id,session_key,question,status,media_json,request_message_id,agent_id,question_image_urls_json)
VALUES($1,$2,$3,$4,$5,$6,'processing',$7,$8,$9,$10) ON CONFLICT DO NOTHING`,
turn.ID, turn.TenantKey, turn.Channel, turn.ExternalMessageID, turn.SessionKey, turn.Question,
mediaJSON, turn.RequestMessageID, turn.AgentID)
mediaJSON, turn.RequestMessageID, turn.AgentID, imageURLsJSON)
if err != nil {
return core.Turn{}, false, err
}
@@ -240,9 +248,9 @@ func (s *Store) FinishTurn(ctx context.Context, turn core.Turn) error {
}
}
}
_, err = tx.Exec(ctx, `UPDATE turns SET weknora_session_id=$2,weknora_request_id=$3,answer=$4,references_json=$5,media_json=$6,status=$7,error_message=$8,answer_message_id=COALESCE($9::TEXT,answer_message_id),updated_at=NOW() WHERE id=$1`,
_, err = tx.Exec(ctx, `UPDATE turns SET weknora_session_id=$2,weknora_request_id=$3,answer=$4,references_json=$5,media_json=$6,status=$7,error_message=$8,answer_message_id=COALESCE($9::TEXT,answer_message_id),knowledge_searched=$10,updated_at=NOW() WHERE id=$1`,
turn.ID, turn.WeKnoraSessionID, turn.WeKnoraRequestID, turn.Answer, references, mediaJSON,
turn.Status, turn.ErrorMessage, answerMessageID)
turn.Status, turn.ErrorMessage, answerMessageID, turn.KnowledgeSearched)
if err != nil {
return err
}