Skip to content

Commit 1f251e3

Browse files
authored
feat: add copy btn for every code block and show sql result (#112)
* feat: add copy btn for every code block * feat: show sql result (backend) * feat: add show sql result in frontend
1 parent 15c136c commit 1f251e3

5 files changed

Lines changed: 377 additions & 2 deletions

File tree

‎spring-ai-alibaba-data-agent-chat/src/main/java/com/alibaba/cloud/ai/enums/TextType.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public enum TextType {
3333

3434
MARK_DOWN("```", "```"),
3535

36+
RESULT_SET("```result_set", "```"),
37+
3638
TEXT(null, null);
3739

3840
private final String startSign;

‎spring-ai-alibaba-data-agent-chat/src/main/java/com/alibaba/cloud/ai/node/SqlExecuteNode.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,17 @@ private Map<String, Object> executeSqlQuery(OverAllState state, Integer currentS
210210

211211
// Create display flux for user experience only
212212
Flux<ChatResponse> displayFlux = Flux.create(emitter -> {
213+
// todo: 先返回Flux流,再去执行SQL查询
213214
emitter.next(ChatResponseUtil.createResponse("开始执行SQL..."));
214215
emitter.next(ChatResponseUtil.createResponse("执行SQL查询"));
215216
emitter.next(ChatResponseUtil.createPureResponse(TextType.SQL.getStartSign()));
216217
emitter.next(ChatResponseUtil.createResponse(sqlQuery));
217218
emitter.next(ChatResponseUtil.createPureResponse(TextType.SQL.getEndSign()));
218219
emitter.next(ChatResponseUtil.createResponse("执行SQL完成"));
219-
// todo: 输出SQL执行结果
220+
emitter.next(ChatResponseUtil.createResponse("SQL查询结果:"));
221+
emitter.next(ChatResponseUtil.createPureResponse(TextType.RESULT_SET.getStartSign()));
222+
emitter.next(ChatResponseUtil.createPureResponse(jsonStr));
223+
emitter.next(ChatResponseUtil.createPureResponse(TextType.RESULT_SET.getEndSign()));
220224
emitter.complete();
221225
});
222226

‎spring-ai-alibaba-data-agent-frontend/src/services/graph.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export enum TextType {
4141
SQL = 'SQL',
4242
HTML = 'HTML',
4343
MARK_DOWN = 'MARK_DOWN',
44+
RESULT_SET = 'RESULT_SET',
4445
TEXT = 'TEXT',
4546
}
4647

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* 结果集数据结构
19+
*/
20+
export interface ResultSetData {
21+
column: string[];
22+
data: Array<Record<string, string>>;
23+
errorMsg?: string;
24+
}
25+
26+
/**
27+
* 分页配置
28+
*/
29+
export interface PaginationConfig {
30+
currentPage: number;
31+
pageSize: number;
32+
total: number;
33+
}
34+
35+
/**
36+
* 结果集显示配置
37+
*/
38+
export interface ResultSetDisplayConfig {
39+
showSqlResults: boolean;
40+
pageSize: number;
41+
}

0 commit comments

Comments
 (0)