mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-03 23:02:31 +08:00
Compare commits
24 Commits
fix/resize
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
015537e97d | ||
|
|
b758f63d7f | ||
|
|
603865fdb0 | ||
|
|
4cb4e187b3 | ||
|
|
c03c41d320 | ||
|
|
9d248e25ad | ||
|
|
4f4aae0e39 | ||
|
|
b00579b257 | ||
|
|
caf7ffe56c | ||
|
|
50d16cbe47 | ||
|
|
56167d363c | ||
|
|
3e2dbbb541 | ||
|
|
efebcea3ba | ||
|
|
68824bc951 | ||
|
|
794826550d | ||
|
|
de98cf60ae | ||
|
|
b3fc624e13 | ||
|
|
d2dd501f3f | ||
|
|
5964deeff7 | ||
|
|
663e1c8c77 | ||
|
|
455115935c | ||
|
|
8d36e0dfb0 | ||
|
|
60f4694752 | ||
|
|
7a6a7eaf7c |
114
.github/workflows/claude-code.yml
vendored
Normal file
114
.github/workflows/claude-code.yml
vendored
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
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
|
||||||
|
- Vercel AI SDK (streamText, useChat, tool calling)
|
||||||
|
- 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:
|
||||||
|
`gh api graphql -f query='mutation { resolveReviewThread(input: {threadId: "THREAD_ID"}) { thread { isResolved } } }'`
|
||||||
|
Get the thread ID from the comment's node_id field.
|
||||||
|
- If the issue still exists, leave it alone
|
||||||
|
|
||||||
|
Then review the current diff for NEW issues only:
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Use `mcp__github_inline_comment__create_inline_comment` for inline comments.
|
||||||
|
Report ALL issues found - create multiple inline comments if needed. Only say "LGTM" if there are truly no issues.
|
||||||
|
claude_args: |
|
||||||
|
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh api:*),WebFetch(domain:ai-sdk.dev)"
|
||||||
46
README.md
46
README.md
@@ -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
|
- **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.
|
- **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
|
- **Interactive Chat Interface**: Communicate with AI to refine your diagrams in real-time
|
||||||
- **Smart Editing**: Modify existing diagrams using simple text prompts
|
- **AWS Architecture Diagram Support**: Specialized support for generating AWS architecture diagrams
|
||||||
- **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
|
- **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
|
## 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
|
## Multi-Provider Support
|
||||||
|
|
||||||
- AWS Bedrock (default)
|
- AWS Bedrock (default)
|
||||||
- OpenAI
|
- OpenAI / OpenAI-compatible APIs (via `OPENAI_BASE_URL`)
|
||||||
- Anthropic
|
- Anthropic
|
||||||
- Google AI
|
- Google AI
|
||||||
- Azure OpenAI
|
- Azure OpenAI
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ ${lastMessageText}
|
|||||||
</mxCell>
|
</mxCell>
|
||||||
</root>
|
</root>
|
||||||
- Note that when you need to generate diagram about aws architecture, use **AWS 2025 icons**.
|
- 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({
|
inputSchema: z.object({
|
||||||
xml: z.string().describe("XML string to be displayed on draw.io")
|
xml: z.string().describe("XML string to be displayed on draw.io")
|
||||||
|
|||||||
@@ -52,23 +52,29 @@ export default function ExamplePanel({
|
|||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-500 mb-2">Try these examples:</p>
|
<p className="text-sm text-gray-500 mb-2">Try these examples:</p>
|
||||||
<div className="flex flex-wrap gap-5">
|
<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
|
<button
|
||||||
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
||||||
onClick={handleReplicateArchitecture}
|
onClick={handleReplicateArchitecture}
|
||||||
>
|
>
|
||||||
Create this diagram in aws style
|
Create AWS architecture
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
||||||
onClick={handleReplicateFlowchart}
|
onClick={handleReplicateFlowchart}
|
||||||
>
|
>
|
||||||
Replicate this flowchart
|
Replicate flowchart
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="text-xs bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium py-1 px-2 rounded"
|
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")}
|
onClick={() => setInput("Draw a cat for me")}
|
||||||
>
|
>
|
||||||
Draw a cat for me
|
Draw a cat
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ AI_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0
|
|||||||
|
|
||||||
# OpenAI Configuration
|
# OpenAI Configuration
|
||||||
# OPENAI_API_KEY=sk-...
|
# OPENAI_API_KEY=sk-...
|
||||||
|
# OPENAI_BASE_URL=https://api.openai.com/v1 # Optional: Custom OpenAI-compatible endpoint
|
||||||
# OPENAI_ORGANIZATION=org-... # Optional
|
# OPENAI_ORGANIZATION=org-... # Optional
|
||||||
# OPENAI_PROJECT=proj_... # Optional
|
# OPENAI_PROJECT=proj_... # Optional
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { bedrock } from '@ai-sdk/amazon-bedrock';
|
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 { anthropic } from '@ai-sdk/anthropic';
|
||||||
import { google } from '@ai-sdk/google';
|
import { google } from '@ai-sdk/google';
|
||||||
import { azure } from '@ai-sdk/azure';
|
import { azure } from '@ai-sdk/azure';
|
||||||
@@ -61,6 +61,7 @@ function validateProviderCredentials(provider: ProviderName): void {
|
|||||||
*
|
*
|
||||||
* Provider-specific env vars:
|
* Provider-specific env vars:
|
||||||
* - OPENAI_API_KEY: OpenAI API key
|
* - OPENAI_API_KEY: OpenAI API key
|
||||||
|
* - OPENAI_BASE_URL: Custom OpenAI-compatible endpoint (optional)
|
||||||
* - ANTHROPIC_API_KEY: Anthropic API key
|
* - ANTHROPIC_API_KEY: Anthropic API key
|
||||||
* - GOOGLE_GENERATIVE_AI_API_KEY: Google API key
|
* - GOOGLE_GENERATIVE_AI_API_KEY: Google API key
|
||||||
* - AZURE_RESOURCE_NAME, AZURE_API_KEY: Azure OpenAI credentials
|
* - AZURE_RESOURCE_NAME, AZURE_API_KEY: Azure OpenAI credentials
|
||||||
@@ -97,7 +98,15 @@ export function getAIModel(): ModelConfig {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'openai':
|
case 'openai':
|
||||||
|
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);
|
model = openai(modelId);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'anthropic':
|
case 'anthropic':
|
||||||
|
|||||||
4
public/animated_connectors.svg
Normal file
4
public/animated_connectors.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 261 KiB |
4
public/aws_demo.svg
Normal file
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
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
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
4
public/gcp_demo.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 100 KiB |
Reference in New Issue
Block a user