Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54a20db

Browse files
committed
fix(coderd): avoid serializing null message content in postChatMessages
1 parentc35f43a commit54a20db

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

‎coderd/chat.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -316,30 +316,35 @@ You are running as an agent - please keep going until the user's query is comple
316316
return
317317
}
318318

319-
raw,err:=json.Marshal(acc.Messages())
320-
iferr!=nil {
321-
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
322-
Message:"Failed to marshal chat message",
323-
Detail:err.Error(),
324-
})
325-
return
326-
}
327-
messages=append(messages,acc.Messages()...)
319+
// acc.Messages() may sometimes return nil. Serializing this
320+
// will cause a pq error: "cannot extract elements from a scalar".
321+
newMessages:=append([]aisdk.Message{},acc.Messages()...)
322+
iflen(newMessages)>0 {
323+
raw,err:=json.Marshal(newMessages)
324+
iferr!=nil {
325+
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
326+
Message:"Failed to marshal chat message",
327+
Detail:err.Error(),
328+
})
329+
return
330+
}
331+
messages=append(messages,newMessages...)
328332

329-
// Insert these messages into the database!
330-
_,err=api.Database.InsertChatMessages(ctx, database.InsertChatMessagesParams{
331-
ChatID:chat.ID,
332-
CreatedAt:dbtime.Now(),
333-
Model:req.Model,
334-
Provider:provider.Provider,
335-
Content:raw,
336-
})
337-
iferr!=nil {
338-
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
339-
Message:"Failed to insert chat messages",
340-
Detail:err.Error(),
333+
// Insert these messages into the database!
334+
_,err=api.Database.InsertChatMessages(ctx, database.InsertChatMessagesParams{
335+
ChatID:chat.ID,
336+
CreatedAt:dbtime.Now(),
337+
Model:req.Model,
338+
Provider:provider.Provider,
339+
Content:raw,
341340
})
342-
return
341+
iferr!=nil {
342+
httpapi.Write(ctx,w,http.StatusInternalServerError, codersdk.Response{
343+
Message:"Failed to insert chat messages",
344+
Detail:err.Error(),
345+
})
346+
return
347+
}
343348
}
344349

345350
ifacc.FinishReason()==aisdk.FinishReasonToolCalls {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp