feat(ai): add general action mode

This commit is contained in:
lexmin0412 authored and GitHub committed 2026-07-08 19:31:19 +08:00
1 parent dafa3e0f79
commit ac4b98c97c
13 files changed
+172 -27

No files matched your search

@@ -3,13 +3,12 @@ import { ASK_ACTIONS, AGENT_ACTIONS, defaultActionForMode, isValidActionForMode
describe("AI action mode mapping", () => {
describe("defaultActionForMode", () => {
it("defaults Ask to generate", () => {
expect(defaultActionForMode("ask")).toBe("generate");
it("defaults Ask to general", () => {
expect(defaultActionForMode("ask")).toBe("general");
});
it("defaults Agent to query (not generate)", () => {
// The whole point of the feature: Agent mode must not default to SQL generation.
expect(defaultActionForMode("agent")).toBe("query");
it("defaults Agent to general", () => {
expect(defaultActionForMode("agent")).toBe("general");
});
});
@@ -47,15 +46,15 @@ describe("AI action mode mapping", () => {
});
describe("action sets", () => {
it("Ask menu keeps the SQL-producing actions", () => {
expect(ASK_ACTIONS).toEqual(["generate", "explain", "optimize", "fix", "convert", "sampleData"]);
it("Ask menu starts with general, then SQL-producing actions", () => {
expect(ASK_ACTIONS).toEqual(["general", "generate", "explain", "optimize", "fix", "convert", "sampleData"]);
});
it("Agent menu is task-oriented, starts with query, and still offers generate", () => {
expect(AGENT_ACTIONS[0]).toBe("query");
// generate is shared so users can still request SQL-only output ("生成但不执行").
it("Agent menu starts with general, then task-oriented actions", () => {
expect(AGENT_ACTIONS[0]).toBe("general");
// generate is shared so users can still request SQL-only output.
expect(AGENT_ACTIONS).toContain("generate");
expect(AGENT_ACTIONS).toEqual(["query", "exploreSchema", "executeAndExplain", "generate"]);
expect(AGENT_ACTIONS).toEqual(["general", "query", "exploreSchema", "executeAndExplain", "generate"]);
});
});
});
+5 -5
View File
@@ -32,20 +32,20 @@ function dbLabel(dbType: DatabaseType): string {
return labels[dbType] || dbType;
}
export type AiAction = "generate" | "explain" | "optimize" | "fix" | "convert" | "sampleData" | "query" | "exploreSchema" | "executeAndExplain";
export type AiAction = "general" | "generate" | "explain" | "optimize" | "fix" | "convert" | "sampleData" | "query" | "exploreSchema" | "executeAndExplain";
export type AiAssistantMode = "ask" | "agent";
/** Actions shown in the Ask mode menu: SQL-producing, never auto-run. */
export const ASK_ACTIONS: AiAction[] = ["generate", "explain", "optimize", "fix", "convert", "sampleData"];
export const ASK_ACTIONS: AiAction[] = ["general", "generate", "explain", "optimize", "fix", "convert", "sampleData"];
/**
* Actions shown in the Agent mode menu: task-oriented, drive tool use.
* `generate` is shared with Ask so users can still request SQL-only output without execution.
*/
export const AGENT_ACTIONS: AiAction[] = ["query", "exploreSchema", "executeAndExplain", "generate"];
export const AGENT_ACTIONS: AiAction[] = ["general", "query", "exploreSchema", "executeAndExplain", "generate"];
export function defaultActionForMode(mode: AiAssistantMode): AiAction {
return mode === "agent" ? "query" : "generate";
export function defaultActionForMode(_mode: AiAssistantMode): AiAction {
return "general";
}
export function isValidActionForMode(action: AiAction, mode: AiAssistantMode): boolean {
+22
View File
@@ -25,6 +25,28 @@ export interface AiSkillDefinition {
}
export const AI_SKILL_DEFINITIONS: AiSkillDefinition[] = [
{
id: "general",
action: "general",
title: {
en: "General",
zh: "通用问答",
},
riskPolicy: "readonly",
contextNeeds: [],
userInstruction: {
en: "Answer the user's question directly and naturally. Use your general knowledge and the database schema context when relevant.",
zh: "直接、自然地回答用户的问题。使用你的通用知识,涉及数据库时可参考 Schema 上下文。",
},
systemRules: {
en: ["Answer naturally and helpfully. Adapt to the user's intent — whether that's a greeting, a conceptual question, or a database-related inquiry."],
zh: ["自然、有帮助地回答。根据用户意图灵活应对——无论是问候、概念性问题还是数据库相关咨询。"],
},
outputContract: {
en: ["Provide a clear, helpful answer adapted to the user's question."],
zh: ["根据用户问题提供清晰、有帮助的回答。"],
},
},
{
id: "generate_sql",
action: "generate",