mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-03 23:02:31 +08:00
Compare commits
1 Commits
feat/tool-
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
015537e97d |
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"next/core-web-vitals",
|
|
||||||
"next/typescript"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
22
.github/workflows/claude-code.yml
vendored
22
.github/workflows/claude-code.yml
vendored
@@ -77,15 +77,14 @@ jobs:
|
|||||||
- Vercel AI SDK (streamText, useChat, tool calling)
|
- Vercel AI SDK (streamText, useChat, tool calling)
|
||||||
- Multiple AI providers: Bedrock, Anthropic, OpenAI, Google, Azure, OpenRouter, Ollama
|
- Multiple AI providers: Bedrock, Anthropic, OpenAI, Google, Azure, OpenRouter, Ollama
|
||||||
|
|
||||||
STEP 1: Check existing comments to avoid duplicates.
|
First, check previous review comments from github-actions bot using `gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments`.
|
||||||
Run: `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:
|
||||||
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 } } }'`
|
`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
|
Get the thread ID from the comment's node_id field.
|
||||||
|
- If the issue still exists, leave it alone
|
||||||
|
|
||||||
STEP 2: Review the diff for issues, but SKIP any file:line that already has a comment.
|
Then review the current diff for NEW issues only:
|
||||||
|
|
||||||
Review this PR for these issues (report ALL that apply):
|
Review this PR for these issues (report ALL that apply):
|
||||||
1. Bugs that would cause runtime errors or broken functionality
|
1. Bugs that would cause runtime errors or broken functionality
|
||||||
@@ -109,10 +108,7 @@ jobs:
|
|||||||
- Code style preferences (unless clearly wrong)
|
- Code style preferences (unless clearly wrong)
|
||||||
- Type annotations that don't affect functionality
|
- Type annotations that don't affect functionality
|
||||||
|
|
||||||
IMPORTANT:
|
Use `mcp__github_inline_comment__create_inline_comment` for inline comments.
|
||||||
- NEVER create a comment on a file:line that already has a comment - this causes duplicates
|
Report ALL issues found - create multiple inline comments if needed. Only say "LGTM" if there are truly no issues.
|
||||||
- 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: |
|
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)"
|
--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)"
|
||||||
|
|||||||
@@ -120,14 +120,13 @@ ${lastMessageText}
|
|||||||
console.log("Enhanced messages:", enhancedMessages);
|
console.log("Enhanced messages:", enhancedMessages);
|
||||||
|
|
||||||
// Get AI model from environment configuration
|
// Get AI model from environment configuration
|
||||||
const { model, providerOptions, headers } = getAIModel();
|
const { model, providerOptions } = getAIModel();
|
||||||
|
|
||||||
const result = streamText({
|
const result = streamText({
|
||||||
model,
|
model,
|
||||||
system: systemMessage,
|
system: systemMessage,
|
||||||
messages: enhancedMessages,
|
messages: enhancedMessages,
|
||||||
...(providerOptions && { providerOptions }),
|
...(providerOptions && { providerOptions }),
|
||||||
...(headers && { headers }),
|
|
||||||
tools: {
|
tools: {
|
||||||
// Client-side tool that will be executed on the client
|
// Client-side tool that will be executed on the client
|
||||||
display_diagram: {
|
display_diagram: {
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import type React from "react";
|
||||||
import { useRef, useEffect, useState, useCallback } from "react";
|
import { useRef, useEffect, useState, useCallback } from "react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||||
import ExamplePanel from "./chat-example-panel";
|
import ExamplePanel from "./chat-example-panel";
|
||||||
import { UIMessage } from "ai";
|
import { UIMessage } from "ai";
|
||||||
import { convertToLegalXml, replaceNodes } from "@/lib/utils";
|
import { convertToLegalXml, replaceNodes } from "@/lib/utils";
|
||||||
import { Copy, Check, X } from "lucide-react";
|
|
||||||
|
|
||||||
import { useDiagram } from "@/contexts/diagram-context";
|
import { useDiagram } from "@/contexts/diagram-context";
|
||||||
|
|
||||||
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");
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ChatMessageDisplayProps {
|
interface ChatMessageDisplayProps {
|
||||||
messages: UIMessage[];
|
messages: UIMessage[];
|
||||||
error?: Error | null;
|
error?: Error | null;
|
||||||
@@ -38,21 +30,6 @@ export function ChatMessageDisplay({
|
|||||||
const [expandedTools, setExpandedTools] = useState<Record<string, boolean>>(
|
const [expandedTools, setExpandedTools] = useState<Record<string, boolean>>(
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
const [copiedMessageId, setCopiedMessageId] = useState<string | null>(null);
|
|
||||||
const [copyFailedMessageId, setCopyFailedMessageId] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const copyMessageToClipboard = async (messageId: string, text: string) => {
|
|
||||||
try {
|
|
||||||
await navigator.clipboard.writeText(text);
|
|
||||||
setCopiedMessageId(messageId);
|
|
||||||
setTimeout(() => setCopiedMessageId(null), 2000);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Failed to copy message:", err);
|
|
||||||
setCopyFailedMessageId(messageId);
|
|
||||||
setTimeout(() => setCopyFailedMessageId(null), 2000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDisplayChart = useCallback(
|
const handleDisplayChart = useCallback(
|
||||||
(xml: string) => {
|
(xml: string) => {
|
||||||
const currentXml = xml || "";
|
const currentXml = xml || "";
|
||||||
@@ -183,30 +160,16 @@ export function ChatMessageDisplay({
|
|||||||
{messages.length === 0 ? (
|
{messages.length === 0 ? (
|
||||||
<ExamplePanel setInput={setInput} setFiles={setFiles} />
|
<ExamplePanel setInput={setInput} setFiles={setFiles} />
|
||||||
) : (
|
) : (
|
||||||
messages.map((message) => {
|
messages.map((message) => (
|
||||||
const userMessageText = message.role === "user" ? getMessageTextContent(message) : "";
|
|
||||||
return (
|
|
||||||
<div
|
<div
|
||||||
key={message.id}
|
key={message.id}
|
||||||
className={`mb-4 flex ${message.role === "user" ? "justify-end" : "justify-start"}`}
|
className={`mb-4 ${
|
||||||
|
message.role === "user" ? "text-right" : "text-left"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{message.role === "user" && userMessageText && (
|
|
||||||
<button
|
|
||||||
onClick={() => copyMessageToClipboard(message.id, userMessageText)}
|
|
||||||
className="p-1 text-gray-400 hover:text-gray-600 transition-colors self-center mr-1"
|
|
||||||
title={copiedMessageId === message.id ? "Copied!" : copyFailedMessageId === message.id ? "Failed to copy" : "Copy message"}
|
|
||||||
>
|
|
||||||
{copiedMessageId === message.id ? (
|
|
||||||
<Check className="h-3.5 w-3.5 text-green-500" />
|
|
||||||
) : copyFailedMessageId === message.id ? (
|
|
||||||
<X className="h-3.5 w-3.5 text-red-500" />
|
|
||||||
) : (
|
|
||||||
<Copy className="h-3.5 w-3.5" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className={`px-4 py-2 whitespace-pre-wrap text-sm rounded-lg max-w-[85%] break-words ${message.role === "user"
|
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-primary text-primary-foreground"
|
||||||
: "bg-muted text-muted-foreground"
|
: "bg-muted text-muted-foreground"
|
||||||
}`}
|
}`}
|
||||||
@@ -241,8 +204,7 @@ export function ChatMessageDisplay({
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
))
|
||||||
})
|
|
||||||
)}
|
)}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="text-red-500 text-sm mt-2">
|
<div className="text-red-500 text-sm mt-2">
|
||||||
|
|||||||
@@ -18,19 +18,15 @@ export type ProviderName =
|
|||||||
interface ModelConfig {
|
interface ModelConfig {
|
||||||
model: any;
|
model: any;
|
||||||
providerOptions?: any;
|
providerOptions?: any;
|
||||||
headers?: Record<string, string>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bedrock provider options for Anthropic beta features
|
// Anthropic beta headers for fine-grained tool streaming
|
||||||
const BEDROCK_ANTHROPIC_BETA = {
|
const ANTHROPIC_BETA_OPTIONS = {
|
||||||
bedrock: {
|
anthropic: {
|
||||||
anthropicBeta: ['fine-grained-tool-streaming-2025-05-14'],
|
additionalModelRequestFields: {
|
||||||
},
|
anthropic_beta: ['fine-grained-tool-streaming-2025-05-14']
|
||||||
};
|
}
|
||||||
|
}
|
||||||
// Direct Anthropic API headers for beta features
|
|
||||||
const ANTHROPIC_BETA_HEADERS = {
|
|
||||||
'anthropic-beta': 'fine-grained-tool-streaming-2025-05-14',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,14 +87,13 @@ export function getAIModel(): ModelConfig {
|
|||||||
|
|
||||||
let model: any;
|
let model: any;
|
||||||
let providerOptions: any = undefined;
|
let providerOptions: any = undefined;
|
||||||
let headers: Record<string, string> | undefined = undefined;
|
|
||||||
|
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case 'bedrock':
|
case 'bedrock':
|
||||||
model = bedrock(modelId);
|
model = bedrock(modelId);
|
||||||
// Add Anthropic beta options if using Claude models via Bedrock
|
// Add Anthropic beta headers if using Claude models via Bedrock
|
||||||
if (modelId.includes('anthropic.claude')) {
|
if (modelId.includes('anthropic.claude')) {
|
||||||
providerOptions = BEDROCK_ANTHROPIC_BETA;
|
providerOptions = ANTHROPIC_BETA_OPTIONS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -117,7 +112,7 @@ export function getAIModel(): ModelConfig {
|
|||||||
case 'anthropic':
|
case 'anthropic':
|
||||||
model = anthropic(modelId);
|
model = anthropic(modelId);
|
||||||
// Add beta headers for fine-grained tool streaming
|
// Add beta headers for fine-grained tool streaming
|
||||||
headers = ANTHROPIC_BETA_HEADERS;
|
providerOptions = ANTHROPIC_BETA_OPTIONS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'google':
|
case 'google':
|
||||||
@@ -145,10 +140,10 @@ export function getAIModel(): ModelConfig {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log if provider options or headers are being applied
|
// Log if provider options are being applied
|
||||||
if (providerOptions || headers) {
|
if (providerOptions) {
|
||||||
console.log('[AI Provider] Applying provider-specific options/headers');
|
console.log('[AI Provider] Applying provider-specific options');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { model, providerOptions, headers };
|
return { model, providerOptions };
|
||||||
}
|
}
|
||||||
|
|||||||
4753
package-lock.json
generated
4753
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ai-sdk/amazon-bedrock": "^3.0.62",
|
"@ai-sdk/amazon-bedrock": "^3.0.52",
|
||||||
"@ai-sdk/anthropic": "^2.0.44",
|
"@ai-sdk/anthropic": "^2.0.44",
|
||||||
"@ai-sdk/azure": "^2.0.69",
|
"@ai-sdk/azure": "^2.0.69",
|
||||||
"@ai-sdk/google": "^2.0.0",
|
"@ai-sdk/google": "^2.0.0",
|
||||||
@@ -46,8 +46,6 @@
|
|||||||
"@types/pako": "^2.0.3",
|
"@types/pako": "^2.0.3",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
"eslint": "9.39.1",
|
|
||||||
"eslint-config-next": "16.0.5",
|
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user