Compare commits

..

33 Commits

Author SHA1 Message Date
Dayuan Jiang
73b1f6e8be Update components/chat-message-display.tsx
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-11-29 13:03:46 +09:00
Dayuan Jiang
1b7414d7a1 Update .github/workflows/claude-code.yml
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-11-29 13:03:27 +09:00
dayuan.jiang
2f01f016d9 fix: prevent duplicate PR review comments by tracking existing comments 2025-11-29 12:51:34 +09:00
dayuan.jiang
28258d19ca chore: trigger workflow re-run for suggestion syntax 2025-11-29 12:46:42 +09:00
dayuan.jiang
fc8c1b64c8 chore: trigger workflow re-run 2025-11-29 12:39:59 +09:00
dayuan.jiang
b396f07254 feat: add copy button to user messages in chat sidebar
- Add copy-to-clipboard functionality for user messages
- Support non-HTTPS environments with execCommand fallback
- Add visual feedback with check icon on successful copy
2025-11-29 12:19:14 +09:00
Dayuan Jiang
b87e3a2de9 feat: use pull_request_target to support fork PR reviews (#24) 2025-11-29 11:14:49 +09:00
Dayuan Jiang
b32d42d962 Merge pull request #23 from DayuanJiang/feature/claude-code-actions
Feature/claude code actions
2025-11-29 01:50:27 +09:00
dayuan.jiang
603865fdb0 fix: add reopened trigger for pr-review workflow 2025-11-29 01:45:44 +09:00
dayuan.jiang
4cb4e187b3 Trigger PR review 2025-11-29 01:40:13 +09:00
Dayuan Jiang
b4d0c6c18b Merge pull request #22 from DayuanJiang/feature/claude-code-actions
Add Claude Code GitHub Actions with Bedrock and auto PR review
2025-11-29 01:32:06 +09:00
dayuan.jiang
c03c41d320 Run PR review on both opened and synchronize events 2025-11-29 01:29:25 +09:00
dayuan.jiang
9d248e25ad Resolve/collapse comment threads when issues are fixed 2025-11-29 01:26:00 +09:00
dayuan.jiang
4f4aae0e39 Check previous comments and mark resolved if fixed 2025-11-29 01:25:15 +09:00
dayuan.jiang
b00579b257 Remove automatic comment cleanup - GitHub handles outdated comments 2025-11-29 01:23:01 +09:00
dayuan.jiang
caf7ffe56c Clean up outdated review comments before new review 2025-11-29 01:21:44 +09:00
dayuan.jiang
50d16cbe47 Allow Claude to fetch AI SDK docs during PR review 2025-11-29 01:20:20 +09:00
dayuan.jiang
56167d363c Add specific AI SDK patterns to PR review prompt 2025-11-29 01:18:25 +09:00
dayuan.jiang
3e2dbbb541 Improve PR review prompt: add project context, narrow scope to real bugs only 2025-11-29 01:14:36 +09:00
dayuan.jiang
efebcea3ba Fix PR review: use correct params and enable inline comments 2025-11-29 00:58:02 +09:00
dayuan.jiang
68824bc951 Enable inline code review comments like Vercel bot 2025-11-29 00:52:57 +09:00
dayuan.jiang
794826550d Use stable v1 instead of beta for claude-code-action 2025-11-29 00:44:58 +09:00
dayuan.jiang
de98cf60ae Add Claude Code GitHub Actions with Bedrock and auto PR review 2025-11-29 00:29:56 +09:00
Dayuan Jiang
b3fc624e13 Merge pull request #16 from ylxmf2005/main
feat: support OpenAI compatible llm
2025-11-22 09:52:30 +09:00
ylxmf
d2dd501f3f feat: support OpenAI compatible llm 2025-11-21 17:03:47 +08:00
Dayuan Jiang
5964deeff7 Merge pull request #15 from DayuanJiang/docs/update-examples
Docs/update examples
2025-11-17 20:47:00 +09:00
Dayuan Jiang
663e1c8c77 Update examples section in README.md 2025-11-17 19:35:55 +09:00
dayuan.jiang
455115935c fix: Remove conflicting width attribute from colspan cell in README table
The cell with colspan=2 should not have width=50% as it creates
a layout conflict causing horizontal table spanning on GitHub.
2025-11-17 19:07:43 +09:00
Dayuan Jiang
8d36e0dfb0 Merge pull request #14 from DayuanJiang/docs/update-examples
docs: Update examples with new prompts and demo images
2025-11-17 19:03:29 +09:00
Dayuan Jiang
60f4694752 Merge pull request #13 from DayuanJiang/fix/resize
fix: Preserve state when resizing window to mobile size
2025-11-17 18:59:07 +09:00
dayuan.jiang
aa330f74b3 fix: Preserve state when resizing window to mobile size
Change mobile warning from unmounting components to showing an overlay.
This prevents losing diagram and chat state when window is resized.
2025-11-17 15:18:29 +09:00
dayuan.jiang
7a6a7eaf7c docs: Update examples with new prompts and demo images
- Add Examples section to README with 2-column grid layout
- Include demo images for GCP, AWS, Azure, animated connectors, and cat
- Update example panel buttons with clearer labels
- Add animated connector example button
- Add instruction for animated connectors in chat route
2025-11-17 15:12:16 +09:00
Dayuan Jiang
7518285e98 Merge pull request #12 from DayuanJiang/chore/fix-readme
chore: Update README for demo site link and simplify multi-provider s…
2025-11-16 09:16:53 +09:00
14 changed files with 328 additions and 63 deletions

122
.github/workflows/claude-code.yml vendored Normal file
View File

@@ -0,0 +1,122 @@
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Run Claude Code
uses: anthropics/claude-code-action@v1
with:
use_bedrock: "true"
github_token: ${{ secrets.GITHUB_TOKEN }}
pr-review:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Run Claude Code PR Review
uses: anthropics/claude-code-action@v1
with:
use_bedrock: "true"
github_token: ${{ secrets.GITHUB_TOKEN }}
allowed_non_write_users: "*"
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
This is a personal project - an AI-powered draw.io diagram generator built with:
- Next.js 15 with React 19
- Multiple AI providers: Bedrock, Anthropic, OpenAI, Google, Azure, OpenRouter, Ollama
First, check previous review comments from github-actions bot using `gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments`.
For each previous comment:
- If the issue is fixed in the current code, resolve the comment thread using:
- Multiple AI providers: Bedrock, Anthropic, OpenAI, Google, Azure, OpenRouter, Ollama
STEP 1: Check existing comments to avoid duplicates.
Run: `gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments`
Build a list of files and line numbers that already have comments. For each existing comment:
- If the issue is FIXED in current code, resolve the thread using:
`gh api graphql -f query='mutation { resolveReviewThread(input: {threadId: "THREAD_ID"}) { thread { isResolved } } }'`
- If the issue still exists, remember this file:line - DO NOT create a new comment for it
STEP 2: Review the diff for issues, but SKIP any file:line that already has a comment.
Review this PR for these issues (report ALL that apply):
1. Bugs that would cause runtime errors or broken functionality
2. Security issues (exposed secrets, API key leaks)
3. AI SDK misuse - specifically check for:
- Client-side: Should use useChat/useCompletion/useObject hooks, NOT raw fetch()
- Server-side: Should use streamText/generateText/streamObject/generateObject
- Message handling: Access message.parts array, not legacy content property
- Tool definitions: Must use Zod schemas for inputSchema
- Status handling: Check status (submitted/streaming/ready/error) before actions
- Stream cleanup: Call stop() when aborting streams
4. Unrelated changes that should be in separate PRs (scope creep)
5. Suspicious .gitignore additions or accidentally committed files
6. UI/UX inconsistencies (e.g., alignment issues)
When reviewing AI SDK usage, fetch https://ai-sdk.dev/docs/ to verify correct patterns.
Key doc pages: /docs/ai-sdk-ui/chatbot, /docs/ai-sdk-core/generating-text, /docs/ai-sdk-core/tools-and-tool-calling
DO NOT comment on:
- Minor performance optimizations
- Code style preferences (unless clearly wrong)
- Type annotations that don't affect functionality
IMPORTANT:
- NEVER create a comment on a file:line that already has a comment - this causes duplicates
- For each NEW issue, use `mcp__github_inline_comment__create_inline_comment` to comment on the specific line
- ALWAYS include a suggested fix using GitHub's suggestion syntax: ```suggestion\n<fixed code>\n```
- Only say "LGTM" if there are truly ZERO new issues to report
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh api:*),WebFetch(domain:ai-sdk.dev)"

5
.gitignore vendored
View File

@@ -41,3 +41,8 @@ yarn-error.log*
next-env.d.ts
push-via-ec2.sh
.claude/settings.local.json
next
next-ai-draw-io@0.2.0
object
starting

View File

@@ -12,8 +12,48 @@ Demo site: [https://next-ai-draw-io.vercel.app](https://next-ai-draw-io.vercel.a
- **Image-Based Diagram Replication**: Upload existing diagrams or images and have the AI replicate and enhance them automatically
- **Diagram History**: Comprehensive version control that tracks all changes, allowing you to view and restore previous versions of your diagrams before the AI editing.
- **Interactive Chat Interface**: Communicate with AI to refine your diagrams in real-time
- **Smart Editing**: Modify existing diagrams using simple text prompts
- **Targeted XML Editing**: AI can now make precise edits to specific parts of diagrams without regenerating the entire XML, making updates faster and more efficient
- **AWS Architecture Diagram Support**: Specialized support for generating AWS architecture diagrams
- **Animated Connectors**: Create dynamic and animated connectors between diagram elements for better visualization
## **Examples**
Here are some example prompts and their generated diagrams:
<div align="center">
<table width="100%">
<tr>
<td width="50%" valign="top">
<strong>GCP architecture diagram</strong><br />
<p><strong>Prompt:</strong> Generate a GCP architecture diagram with **GCP icons**. In this diagram, users connect to a frontend hosted on an instance.</p>
<img src="./public/gcp_demo.svg" alt="GCP Architecture Diagram" width="480" />
</td>
<td width="50%" valign="top">
<strong>AWS architecture diagram</strong><br />
<p><strong>Prompt:</strong> Generate a AWS architecture diagram with **AWS icons**. In this diagram, users connect to a frontend hosted on an instance.</p>
<img src="./public/aws_demo.svg" alt="AWS Architecture Diagram" width="480" />
</td>
</tr>
<tr>
<td width="50%" valign="top">
<strong>Azure architecture diagram</strong><br />
<p><strong>Prompt:</strong> Generate a Azure architecture diagram with **Azure icons**. In this diagram, users connect to a frontend hosted on an instance.</p>
<img src="./public/azure_demo.svg" alt="Azure Architecture Diagram" width="480" />
</td>
<td width="50%" valign="top">
<strong>Animated transformer connectors</strong><br />
<p><strong>Prompt:</strong> Give me a **animated connector** diagram of transformer's architecture.</p>
<img src="./public/animated_connectors.svg" alt="Transformer Architecture with Animated Connectors" width="480" />
</td>
</tr>
<tr>
<td colspan="2" valign="top" align="center">
<strong>Cat sketch prompt</strong><br />
<p><strong>Prompt:</strong> Draw a cute cat for me.</p>
<img src="./public/cat_demo.svg" alt="Cat Drawing" width="260" />
</td>
</tr>
</table>
</div>
## How It Works
@@ -28,7 +68,7 @@ Diagrams are represented as XML that can be rendered in draw.io. The AI processe
## Multi-Provider Support
- AWS Bedrock (default)
- OpenAI
- OpenAI / OpenAI-compatible APIs (via `OPENAI_BASE_URL`)
- Anthropic
- Google AI
- Azure OpenAI

View File

@@ -141,6 +141,7 @@ ${lastMessageText}
</mxCell>
</root>
- Note that when you need to generate diagram about aws architecture, use **AWS 2025 icons**.
- If you are asked to generate animated connectors, make sure to include "flowAnimation=1" in the style of the connector elements.
`,
inputSchema: z.object({
xml: z.string().describe("XML string to be displayed on draw.io")

View File

@@ -40,20 +40,19 @@ export default function Home() {
};
}, []);
if (isMobile) {
return (
<div className="flex items-center justify-center h-screen bg-gray-100">
<div className="text-center p-8">
<h1 className="text-2xl font-semibold text-gray-800">
Please open this application on a desktop or laptop
</h1>
</div>
</div>
);
}
return (
<div className="flex h-screen bg-gray-100">
<div className="flex h-screen bg-gray-100 relative">
{/* Mobile warning overlay - keeps components mounted */}
{isMobile && (
<div className="absolute inset-0 z-50 flex items-center justify-center bg-gray-100">
<div className="text-center p-8">
<h1 className="text-2xl font-semibold text-gray-800">
Please open this application on a desktop or laptop
</h1>
</div>
</div>
)}
<div className={`${isChatVisible ? 'w-2/3' : 'w-full'} p-1 h-full relative transition-all duration-300 ease-in-out`}>
<DrawIoEmbed
ref={drawioRef}

View File

@@ -52,23 +52,29 @@ export default function ExamplePanel({
</p>
<p className="text-sm text-gray-500 mb-2">Try these examples:</p>
<div className="flex flex-wrap gap-5">
<button
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
onClick={() => setInput("Give me a **animated connector** diagram of transformer's architecture")}
>
Draw diagram with Animated Connectors
</button>
<button
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
onClick={handleReplicateArchitecture}
>
Create this diagram in aws style
Create AWS architecture
</button>
<button
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
onClick={handleReplicateFlowchart}
>
Replicate this flowchart
Replicate flowchart
</button>
<button
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
onClick={() => setInput("Draw a cat for me")}
>
Draw a cat for me
Draw a cat
</button>
</div>
</div>

View File

@@ -7,6 +7,7 @@ import { ScrollArea } from "@/components/ui/scroll-area";
import ExamplePanel from "./chat-example-panel";
import { UIMessage } from "ai";
import { convertToLegalXml, replaceNodes } from "@/lib/utils";
import { Copy, Check } from "lucide-react";
import { useDiagram } from "@/contexts/diagram-context";
@@ -30,6 +31,51 @@ export function ChatMessageDisplay({
const [expandedTools, setExpandedTools] = useState<Record<string, boolean>>(
{}
);
const [copiedMessageId, setCopiedMessageId] = useState<string | null>(null);
// 复制消息到剪贴板,支持非 HTTPS 环境的降级处理
const copyMessageToClipboard = async (messageId: string, text: string) => {
try {
// 优先使用 Clipboard API需要 HTTPS 或 localhost
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
} else {
// 降级方案:使用传统的 execCommand 方法(兼容 HTTP 环境)
const textArea = document.createElement("textarea");
textArea.value = text;
// 设置样式避免影响页面布局
textArea.style.position = "fixed";
// 降级方案:使用传统的 execCommand 方法(兼容 HTTP 环境)
// Fallback: Use textarea selection (works in most browsers)
textArea.style.top = "-9999px";
textArea.style.opacity = "0";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
const successful = document.execCommand("copy");
document.body.removeChild(textArea);
if (!successful) {
throw new Error("execCommand copy failed");
}
}
setCopiedMessageId(messageId);
setTimeout(() => {
setCopiedMessageId(null);
}, 2000);
} catch (err) {
console.error("Failed to copy message:", err);
}
};
const getMessageTextContent = (message: UIMessage): string => {
if (!message.parts) return "";
return message.parts
.filter((part: any) => part.type === "text")
.map((part: any) => part.text)
.join("\n");
};
const handleDisplayChart = useCallback(
(xml: string) => {
const currentXml = xml || "";
@@ -160,51 +206,67 @@ export function ChatMessageDisplay({
{messages.length === 0 ? (
<ExamplePanel setInput={setInput} setFiles={setFiles} />
) : (
messages.map((message) => (
<div
key={message.id}
className={`mb-4 ${
message.role === "user" ? "text-right" : "text-left"
}`}
>
messages.map((message) => {
const userMessageText = message.role === "user" ? getMessageTextContent(message) : "";
return (
<div
className={`inline-block px-4 py-2 whitespace-pre-wrap text-sm rounded-lg max-w-[85%] break-words ${
message.role === "user"
? "bg-primary text-primary-foreground"
: "bg-muted text-muted-foreground"
}`}
key={message.id}
className={`mb-4 ${message.role === "user" ? "text-right" : "text-left"
}`}
>
{message.parts?.map((part: any, index: number) => {
switch (part.type) {
case "text":
return (
<div key={index}>{part.text}</div>
);
case "file":
return (
<div key={index} className="mt-2">
<Image
src={part.url}
width={200}
height={200}
alt={`Uploaded diagram or image for AI analysis`}
className="rounded-md border"
style={{
objectFit: "contain",
}}
/>
</div>
);
default:
if (part.type?.startsWith("tool-")) {
return renderToolPart(part);
}
return null;
}
})}
<div
className={`inline-block px-4 py-2 whitespace-pre-wrap text-sm rounded-lg max-w-[85%] break-words ${message.role === "user"
? "bg-primary text-primary-foreground"
: "bg-muted text-muted-foreground"
}`}
>
{message.parts?.map((part: any, index: number) => {
switch (part.type) {
case "text":
return (
<div key={index}>{part.text}</div>
);
case "file":
return (
<div key={index} className="mt-2">
<Image
src={part.url}
width={200}
height={200}
alt={`Uploaded diagram or image for AI analysis`}
className="rounded-md border"
style={{
objectFit: "contain",
}}
/>
</div>
);
default:
if (part.type?.startsWith("tool-")) {
return renderToolPart(part);
}
return null;
}
})}
</div>
{userMessageText && (
<div className="flex justify-start mt-1">
<button
onClick={() => copyMessageToClipboard(message.id, userMessageText)}
className="p-1 text-gray-400 hover:text-gray-600 transition-colors"
title={copiedMessageId === message.id ? "Copied!" : "Copy message"}
>
{copiedMessageId === message.id ? (
<Check className="h-3.5 w-3.5 text-green-500" />
) : (
<Copy className="h-3.5 w-3.5" />
)}
</button>
</div>
)}
</div>
</div>
))
)
})
)}
{error && (
<div className="text-red-500 text-sm mt-2">

View File

@@ -14,6 +14,7 @@ AI_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0
# OpenAI Configuration
# OPENAI_API_KEY=sk-...
# OPENAI_BASE_URL=https://api.openai.com/v1 # Optional: Custom OpenAI-compatible endpoint
# OPENAI_ORGANIZATION=org-... # Optional
# OPENAI_PROJECT=proj_... # Optional

View File

@@ -1,5 +1,5 @@
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { openai } from '@ai-sdk/openai';
import { openai, createOpenAI } from '@ai-sdk/openai';
import { anthropic } from '@ai-sdk/anthropic';
import { google } from '@ai-sdk/google';
import { azure } from '@ai-sdk/azure';
@@ -61,6 +61,7 @@ function validateProviderCredentials(provider: ProviderName): void {
*
* Provider-specific env vars:
* - OPENAI_API_KEY: OpenAI API key
* - OPENAI_BASE_URL: Custom OpenAI-compatible endpoint (optional)
* - ANTHROPIC_API_KEY: Anthropic API key
* - GOOGLE_GENERATIVE_AI_API_KEY: Google API key
* - AZURE_RESOURCE_NAME, AZURE_API_KEY: Azure OpenAI credentials
@@ -97,7 +98,15 @@ export function getAIModel(): ModelConfig {
break;
case 'openai':
model = openai(modelId);
if (process.env.OPENAI_BASE_URL) {
const customOpenAI = createOpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL,
});
model = customOpenAI.chat(modelId);
} else {
model = openai(modelId);
}
break;
case 'anthropic':

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 261 KiB

4
public/aws_demo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 95 KiB

4
public/azure_demo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 88 KiB

4
public/cat_demo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 33 KiB

4
public/gcp_demo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 100 KiB