Skip to content

Commit 4f9b50b

Browse files
committed
feat(chat): 接入虚拟列表并实现历史分页
1 parent ba6ba68 commit 4f9b50b

26 files changed

Lines changed: 1154 additions & 1126 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target
2222
.vscode
2323
target
2424
bin
25+
.serena
2526

2627
# Editor directories and files
2728
.vscode/*

crates/agent-gateway/internal/proto/v1/gateway.pb.go

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/agent-gateway/internal/proto/v1/gateway_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/agent-gateway/internal/server/websocket.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type websocketConnection struct {
8484
}
8585

8686
const recentActiveChatRetention = 5 * time.Second
87+
const maxHistoryListLimit = 200
8788

8889
func NewWebSocketServer(cfg *config.Config, sm *session.Manager) http.Handler {
8990
server := &websocket.Server{
@@ -486,23 +487,35 @@ func (c *websocketConnection) handleFsListDirs(req websocketRequest) {
486487

487488
func (c *websocketConnection) handleHistoryList(req websocketRequest) {
488489
type payload struct {
489-
Limit int `json:"limit"`
490-
Offset int `json:"offset"`
490+
Page int `json:"page"`
491+
PageSize int `json:"page_size"`
491492
}
492493

493494
var body payload
494495
if err := decodeWebSocketPayload(req.Payload, &body); err != nil {
495496
_ = c.writeError(req.ID, "invalid history.list payload")
496497
return
497498
}
499+
page := body.Page
500+
if page <= 0 {
501+
_ = c.writeError(req.ID, "history.list page must be greater than 0")
502+
return
503+
}
504+
pageSize := body.PageSize
505+
if pageSize <= 0 {
506+
_ = c.writeError(req.ID, "history.list page_size must be greater than 0")
507+
return
508+
} else if pageSize > maxHistoryListLimit {
509+
pageSize = maxHistoryListLimit
510+
}
498511

499512
response, err := c.awaitAgentResponse(req.ID, &gatewayv1.GatewayEnvelope{
500513
RequestId: req.ID,
501514
Timestamp: time.Now().Unix(),
502515
Payload: &gatewayv1.GatewayEnvelope_HistoryList{
503516
HistoryList: &gatewayv1.HistoryListRequest{
504-
Limit: int32(body.Limit),
505-
Offset: int32(body.Offset),
517+
Page: int32(page),
518+
PageSize: int32(pageSize),
506519
},
507520
},
508521
})
@@ -528,7 +541,7 @@ func (c *websocketConnection) handleHistoryList(req websocketRequest) {
528541

529542
_ = c.writeResponse(req.ID, map[string]any{
530543
"conversations": conversations,
531-
"total": resp.GetTotal(),
544+
"total_count": resp.GetTotalCount(),
532545
"running_conversation_ids": c.sm.ActiveChatRunConversationIDs(),
533546
})
534547
}

crates/agent-gateway/proto/v1/gateway.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ message CronManageResponse {
191191
}
192192

193193
message HistoryListRequest {
194-
int32 limit = 1;
195-
int32 offset = 2;
194+
int32 page = 1;
195+
int32 page_size = 2;
196196
}
197197

198198
message HistoryListResponse {
199199
repeated ConversationSummary conversations = 1;
200-
int32 total = 2;
200+
int32 total_count = 2;
201201
}
202202

203203
message ConversationSummary {

crates/agent-gateway/test/websocket/chat_bridge_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,23 +830,23 @@ func TestWebSocketForwardsHistorySettingsAndFsRPCs(t *testing.T) {
830830
}
831831

832832
sendEnvelope(t, conn, "history-1", "history.list", map[string]any{
833-
"limit": 25,
834-
"offset": 5,
833+
"page": 2,
834+
"page_size": 25,
835835
})
836836
historyOutbound := readOutboundEnvelope(t, agentSession)
837837
historyReq := historyOutbound.GetHistoryList()
838838
if historyReq == nil {
839839
t.Fatalf("history outbound payload = %T, want HistoryListRequest", historyOutbound.GetPayload())
840840
}
841-
if historyReq.GetLimit() != 25 || historyReq.GetOffset() != 5 {
841+
if historyReq.GetPage() != 2 || historyReq.GetPageSize() != 25 {
842842
t.Fatalf("history list request = %#v", historyReq)
843843
}
844844
sm.DispatchFromAgent(&gatewayv1.AgentEnvelope{
845845
RequestId: historyOutbound.GetRequestId(),
846846
Timestamp: time.Now().Unix(),
847847
Payload: &gatewayv1.AgentEnvelope_HistoryListResp{
848848
HistoryListResp: &gatewayv1.HistoryListResponse{
849-
Total: 1,
849+
TotalCount: 1,
850850
Conversations: []*gatewayv1.ConversationSummary{
851851
{
852852
Id: "conversation-1",
@@ -874,7 +874,7 @@ func TestWebSocketForwardsHistorySettingsAndFsRPCs(t *testing.T) {
874874
if err := json.Unmarshal(historyResponse.Payload, &historyPayload); err != nil {
875875
t.Fatalf("decode history response: %v", err)
876876
}
877-
if historyPayload["total"] != float64(1) {
877+
if historyPayload["total_count"] != float64(1) {
878878
t.Fatalf("history payload = %#v", historyPayload)
879879
}
880880
runningConversationIDs, ok := historyPayload["running_conversation_ids"].([]any)

crates/agent-gateway/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@streamdown/code": "^1.1.1",
1919
"@streamdown/math": "^1.0.2",
2020
"@streamdown/mermaid": "^1.0.2",
21+
"@tanstack/react-virtual": "^3.13.25",
2122
"class-variance-authority": "^0.7.1",
2223
"clsx": "^2.1.1",
2324
"katex": "^0.16.45",

crates/agent-gateway/web/pnpm-lock.yaml

Lines changed: 25 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)