Skip to content

Commit 2d5c49b

Browse files
committed
fix(knowledge): 优化quiet和format参数的输出逻辑
- 在file-get命令中,quiet模式下仅输出fileId,避免了多余的结果格式化 - 在kb-info命令中,quiet模式仅输出id,格式化输出逻辑得到简化 - 在kb-stats命令中,去除了quiet判断,确保非"text"格式下正确输出结果 - 在service-get命令中,quiet模式下只输出agent_id,格式化部分调整为独立判断 - 统一了各命令中针对quiet和format参数的处理流程,提升代码一致性和可读性
1 parent 9bd8b60 commit 2d5c49b

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

packages/commands/src/commands/knowledge/file-get.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ export default defineCommand({
4545
});
4646

4747
const file = response.data;
48-
if (settings.quiet || format !== "text") {
49-
emitResult(response, format === "text" ? "json" : format);
48+
if (settings.quiet) {
49+
emitBare(file?.fileId ?? "");
50+
return;
51+
}
52+
if (format !== "text") {
53+
emitResult(response, format);
5054
return;
5155
}
5256
emitBare(`id: ${file?.fileId ?? "-"}`);

packages/commands/src/commands/knowledge/kb-info.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ export default defineCommand({
9292

9393
const row = await fetchIndexDetail(ctx.client, workspaceId, flags.indexId);
9494

95-
if (settings.quiet || format !== "text") {
96-
emitResult(row, format === "text" ? "json" : format);
95+
if (settings.quiet) {
96+
emitBare(row.id ?? "");
97+
return;
98+
}
99+
if (format !== "text") {
100+
emitResult(row, format);
97101
return;
98102
}
99103

packages/commands/src/commands/knowledge/kb-stats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export default defineCommand({
102102
body,
103103
});
104104

105-
if (settings.quiet || format !== "text") {
106-
emitResult(response, format === "text" ? "json" : format);
105+
if (format !== "text") {
106+
emitResult(response, format);
107107
return;
108108
}
109109
if (clampedEnd) {

packages/commands/src/commands/knowledge/service-get.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ export default defineCommand({
7777
});
7878

7979
const data = response.data;
80-
if (settings.quiet || format !== "text") {
81-
emitResult(response, format === "text" ? "json" : format);
80+
if (settings.quiet) {
81+
emitBare(data?.agent_id ?? "");
82+
return;
83+
}
84+
if (format !== "text") {
85+
emitResult(response, format);
8286
return;
8387
}
8488
emitBare("Basic:");

0 commit comments

Comments
 (0)