mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-22 00:35:27 -04:00
fix: empty flow assistant logs when no updates occur
- Added a mechanism to track updates in the flow assistant log worker. - Implemented a new database function to delete flow assistant logs if no updates are made during processing. - Updated the querier interface to include the new delete function. - Enhanced SQL model to support the deletion of flow assistant logs.
This commit is contained in:
@@ -292,6 +292,7 @@ func (aslw *flowAssistantLogWorker) workerMsgUpdater(
|
||||
contentBuf := bytes.NewBuffer(contentData)
|
||||
thinkingData := make([]byte, 0, defaultMaxMessageLength)
|
||||
thinkingBuf := bytes.NewBuffer(thinkingData)
|
||||
wasUpdated := false // track if we actually updated the record
|
||||
|
||||
msgLog, err := aslw.db.GetFlowAssistantLog(ctx, msgID)
|
||||
if err != nil {
|
||||
@@ -336,15 +337,18 @@ func (aslw *flowAssistantLogWorker) workerMsgUpdater(
|
||||
ID: msgID,
|
||||
})
|
||||
if err == nil {
|
||||
wasUpdated = true
|
||||
aslw.pub.AssistantLogUpdated(ctx, msgLog, false)
|
||||
}
|
||||
|
||||
case providers.StreamMessageChunkTypeContent:
|
||||
contentBuf.WriteString(chunk.Content)
|
||||
wasUpdated = true
|
||||
aslw.pub.AssistantLogUpdated(ctx, newLog(chunk.MsgType, chunk.Content, ""), true)
|
||||
|
||||
case providers.StreamMessageChunkTypeThinking:
|
||||
thinkingBuf.WriteString(aslw.getThinkingString(chunk.Thinking))
|
||||
wasUpdated = true
|
||||
aslw.pub.AssistantLogUpdated(ctx, newLog(chunk.MsgType, "", aslw.getThinkingString(chunk.Thinking)), true)
|
||||
|
||||
case providers.StreamMessageChunkTypeResult:
|
||||
@@ -360,6 +364,7 @@ func (aslw *flowAssistantLogWorker) workerMsgUpdater(
|
||||
ID: msgID,
|
||||
})
|
||||
if err == nil {
|
||||
wasUpdated = true
|
||||
aslw.pub.AssistantLogUpdated(ctx, msgLog, false)
|
||||
}
|
||||
}
|
||||
@@ -375,7 +380,10 @@ func (aslw *flowAssistantLogWorker) workerMsgUpdater(
|
||||
processChunk(<-ch)
|
||||
}
|
||||
|
||||
if msgLog, err = aslw.db.GetFlowAssistantLog(ctx, msgID); err == nil {
|
||||
// If record was never updated, delete it (empty message case)
|
||||
if !wasUpdated {
|
||||
_ = aslw.db.DeleteFlowAssistantLog(ctx, msgID)
|
||||
} else if msgLog, err = aslw.db.GetFlowAssistantLog(ctx, msgID); err == nil {
|
||||
content, thinking := contentBuf.String(), thinkingBuf.String()
|
||||
_, _ = aslw.db.UpdateAssistantLog(ctx, database.UpdateAssistantLogParams{
|
||||
Type: msgLog.Type,
|
||||
|
||||
@@ -106,6 +106,16 @@ func (q *Queries) CreateResultAssistantLog(ctx context.Context, arg CreateResult
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteFlowAssistantLog = `-- name: DeleteFlowAssistantLog :exec
|
||||
DELETE FROM assistantlogs
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteFlowAssistantLog(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteFlowAssistantLog, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getFlowAssistantLog = `-- name: GetFlowAssistantLog :one
|
||||
SELECT
|
||||
al.id, al.type, al.message, al.result, al.result_format, al.flow_id, al.assistant_id, al.created_at, al.thinking
|
||||
|
||||
@@ -36,6 +36,7 @@ type Querier interface {
|
||||
DeleteAssistant(ctx context.Context, id int64) (Assistant, error)
|
||||
DeleteFavoriteFlow(ctx context.Context, arg DeleteFavoriteFlowParams) (UserPreference, error)
|
||||
DeleteFlow(ctx context.Context, id int64) (Flow, error)
|
||||
DeleteFlowAssistantLog(ctx context.Context, id int64) error
|
||||
DeletePrompt(ctx context.Context, id int64) error
|
||||
DeleteProvider(ctx context.Context, id int64) (Provider, error)
|
||||
DeleteSubtask(ctx context.Context, id int64) error
|
||||
|
||||
@@ -280,7 +280,7 @@ func (ce *customExecutor) Execute(
|
||||
|
||||
var err error
|
||||
msgID, msg := int64(0), ce.getMessage(args)
|
||||
if msg != "" {
|
||||
if strings.Trim(msg, " \t\n\r") != "" {
|
||||
msgType := getMessageType(name)
|
||||
msgID, err = ce.mlp.PutMsg(ctx, msgType, ce.taskID, ce.subtaskID, streamID, thinking, msg)
|
||||
if err != nil {
|
||||
|
||||
@@ -70,3 +70,7 @@ UPDATE assistantlogs
|
||||
SET result = $1, result_format = $2
|
||||
WHERE id = $3
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteFlowAssistantLog :exec
|
||||
DELETE FROM assistantlogs
|
||||
WHERE id = $1;
|
||||
|
||||
Reference in New Issue
Block a user