feat: implement Story 3.1 — chat panel UI with streaming AI responses
Add AI copilot chat panel to the diagram editor with streaming responses, chat history persistence, and markdown rendering. Includes copilot API route, diagram-aware system prompt, and schema with 15 passing tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
55
packages/ai/src/modules/copilot/system-prompt.test.ts
Normal file
55
packages/ai/src/modules/copilot/system-prompt.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { buildCopilotSystemPrompt } from "./system-prompt";
|
||||
|
||||
import type { DiagramType } from "./types";
|
||||
|
||||
describe("buildCopilotSystemPrompt", () => {
|
||||
it("should include the diagram type in uppercase", () => {
|
||||
const prompt = buildCopilotSystemPrompt("bpmn");
|
||||
expect(prompt).toContain("BPMN");
|
||||
expect(prompt).toContain("Type: BPMN");
|
||||
});
|
||||
|
||||
it("should include diagram description for each type", () => {
|
||||
const types: DiagramType[] = [
|
||||
"bpmn",
|
||||
"er",
|
||||
"orgchart",
|
||||
"architecture",
|
||||
"sequence",
|
||||
"flowchart",
|
||||
];
|
||||
|
||||
for (const type of types) {
|
||||
const prompt = buildCopilotSystemPrompt(type);
|
||||
expect(prompt).toContain(`Type: ${type.toUpperCase()}`);
|
||||
expect(prompt).toContain("domaingraph AI copilot");
|
||||
expect(prompt).toContain("CHAT-ONLY mode");
|
||||
}
|
||||
});
|
||||
|
||||
it("should mention chat-only constraint", () => {
|
||||
const prompt = buildCopilotSystemPrompt("er");
|
||||
expect(prompt).toContain("CHAT-ONLY mode");
|
||||
expect(prompt).toContain("cannot modify the diagram directly");
|
||||
});
|
||||
|
||||
it("should include today's date", () => {
|
||||
const prompt = buildCopilotSystemPrompt("flowchart");
|
||||
const year = new Date().getFullYear().toString();
|
||||
expect(prompt).toContain(year);
|
||||
});
|
||||
|
||||
it("should include ER-specific description", () => {
|
||||
const prompt = buildCopilotSystemPrompt("er");
|
||||
expect(prompt).toContain("Entity-Relationship");
|
||||
expect(prompt).toContain("entities");
|
||||
});
|
||||
|
||||
it("should include architecture-specific description", () => {
|
||||
const prompt = buildCopilotSystemPrompt("architecture");
|
||||
expect(prompt).toContain("services");
|
||||
expect(prompt).toContain("databases");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user