mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-03 23:02:31 +08:00
Compare commits
1 Commits
fix/move-u
...
refactor/e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dbda5ba8e |
24
.github/ISSUE_TEMPLATE/enhancement.md
vendored
24
.github/ISSUE_TEMPLATE/enhancement.md
vendored
@@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
name: Enhancement
|
|
||||||
about: Suggest an improvement to existing functionality
|
|
||||||
title: '[Enhancement] '
|
|
||||||
labels: enhancement
|
|
||||||
assignees: ''
|
|
||||||
---
|
|
||||||
|
|
||||||
> **Note**: This template is just a guide. Feel free to ignore the format entirely - any feedback is welcome! Don't let the template stop you from sharing your ideas.
|
|
||||||
|
|
||||||
## Current Behavior
|
|
||||||
Describe how the feature currently works.
|
|
||||||
|
|
||||||
## Proposed Enhancement
|
|
||||||
How you'd like this to be improved.
|
|
||||||
|
|
||||||
## Motivation
|
|
||||||
Why this enhancement would be beneficial.
|
|
||||||
|
|
||||||
## Screenshots / Mockups
|
|
||||||
If applicable, add screenshots or mockups to illustrate the proposed changes.
|
|
||||||
|
|
||||||
## Additional Context
|
|
||||||
Any other information about the enhancement request.
|
|
||||||
20
.github/workflows/auto-format.yml
vendored
20
.github/workflows/auto-format.yml
vendored
@@ -12,13 +12,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.head_ref }}
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
|
|
||||||
@@ -37,21 +37,11 @@ jobs:
|
|||||||
echo "has_changes=true" >> $GITHUB_OUTPUT
|
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For fork PRs, just fail if formatting is needed (can't push to forks)
|
|
||||||
- name: Fail if fork PR needs formatting
|
|
||||||
if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name != github.repository
|
|
||||||
run: |
|
|
||||||
echo "::error::This PR has formatting issues. Please run 'npx @biomejs/biome check --write .' locally and push the changes."
|
|
||||||
git diff --stat
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
# For same-repo PRs, commit and push the changes
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository
|
if: steps.changes.outputs.has_changes == 'true'
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
|
|
||||||
git add .
|
git add .
|
||||||
git commit -m "style: auto-format with Biome"
|
git commit -m "style: auto-format with Biome"
|
||||||
git push origin HEAD:${{ github.head_ref }}
|
git push
|
||||||
|
|||||||
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@@ -1,44 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v6
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
cache: 'npm'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Type check
|
|
||||||
run: npx tsc --noEmit
|
|
||||||
|
|
||||||
- name: Lint check
|
|
||||||
run: npm run check
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: npm run build
|
|
||||||
|
|
||||||
- name: Security audit
|
|
||||||
run: npm audit --audit-level=high --omit=dev
|
|
||||||
4
.github/workflows/docker-build.yml
vendored
4
.github/workflows/docker-build.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -69,7 +69,7 @@ jobs:
|
|||||||
# Push to AWS ECR for App Runner auto-deploy
|
# Push to AWS ECR for App Runner auto-deploy
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
||||||
uses: aws-actions/configure-aws-credentials@v5
|
uses: aws-actions/configure-aws-credentials@v4
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
|||||||
4
.github/workflows/electron-release.yml
vendored
4
.github/workflows/electron-release.yml
vendored
@@ -29,10 +29,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|||||||
@@ -242,11 +242,6 @@ Or you can deploy by this button.
|
|||||||
|
|
||||||
Be sure to **set the environment variables** in the Vercel dashboard as you did in your local `.env.local` file.
|
Be sure to **set the environment variables** in the Vercel dashboard as you did in your local `.env.local` file.
|
||||||
|
|
||||||
## Deploy on Cloudflare Workers
|
|
||||||
|
|
||||||
[Go to Cloudflare Deploy Guide](./docs/Cloudflare_Deploy.md)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Multi-Provider Support
|
## Multi-Provider Support
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { usePathname, useRouter } from "next/navigation"
|
|
||||||
import { useCallback, useEffect, useRef, useState } from "react"
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
import { DrawIoEmbed } from "react-drawio"
|
import { DrawIoEmbed } from "react-drawio"
|
||||||
import type { ImperativePanelHandle } from "react-resizable-panels"
|
import type { ImperativePanelHandle } from "react-resizable-panels"
|
||||||
@@ -11,7 +10,6 @@ import {
|
|||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "@/components/ui/resizable"
|
} from "@/components/ui/resizable"
|
||||||
import { useDiagram } from "@/contexts/diagram-context"
|
import { useDiagram } from "@/contexts/diagram-context"
|
||||||
import { i18n, type Locale } from "@/lib/i18n/config"
|
|
||||||
|
|
||||||
const drawioBaseUrl =
|
const drawioBaseUrl =
|
||||||
process.env.NEXT_PUBLIC_DRAWIO_BASE_URL || "https://embed.diagrams.net"
|
process.env.NEXT_PUBLIC_DRAWIO_BASE_URL || "https://embed.diagrams.net"
|
||||||
@@ -26,8 +24,6 @@ export default function Home() {
|
|||||||
showSaveDialog,
|
showSaveDialog,
|
||||||
setShowSaveDialog,
|
setShowSaveDialog,
|
||||||
} = useDiagram()
|
} = useDiagram()
|
||||||
const router = useRouter()
|
|
||||||
const pathname = usePathname()
|
|
||||||
const [isMobile, setIsMobile] = useState(false)
|
const [isMobile, setIsMobile] = useState(false)
|
||||||
const [isChatVisible, setIsChatVisible] = useState(true)
|
const [isChatVisible, setIsChatVisible] = useState(true)
|
||||||
const [drawioUi, setDrawioUi] = useState<"min" | "sketch">("min")
|
const [drawioUi, setDrawioUi] = useState<"min" | "sketch">("min")
|
||||||
@@ -62,18 +58,6 @@ export default function Home() {
|
|||||||
|
|
||||||
// Load preferences from localStorage after mount
|
// Load preferences from localStorage after mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Restore saved locale and redirect if needed
|
|
||||||
const savedLocale = localStorage.getItem("next-ai-draw-io-locale")
|
|
||||||
if (savedLocale && i18n.locales.includes(savedLocale as Locale)) {
|
|
||||||
const pathParts = pathname.split("/").filter(Boolean)
|
|
||||||
const currentLocale = pathParts[0]
|
|
||||||
if (currentLocale !== savedLocale) {
|
|
||||||
pathParts[0] = savedLocale
|
|
||||||
router.replace(`/${pathParts.join("/")}`)
|
|
||||||
return // Wait for redirect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const savedUi = localStorage.getItem("drawio-theme")
|
const savedUi = localStorage.getItem("drawio-theme")
|
||||||
if (savedUi === "min" || savedUi === "sketch") {
|
if (savedUi === "min" || savedUi === "sketch") {
|
||||||
setDrawioUi(savedUi)
|
setDrawioUi(savedUi)
|
||||||
@@ -100,7 +84,7 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsLoaded(true)
|
setIsLoaded(true)
|
||||||
}, [pathname, router])
|
}, [])
|
||||||
|
|
||||||
const handleDarkModeChange = async () => {
|
const handleDarkModeChange = async () => {
|
||||||
await saveDiagramToStorage()
|
await saveDiagramToStorage()
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import {
|
|||||||
wrapWithObserve,
|
wrapWithObserve,
|
||||||
} from "@/lib/langfuse"
|
} from "@/lib/langfuse"
|
||||||
import { getSystemPrompt } from "@/lib/system-prompts"
|
import { getSystemPrompt } from "@/lib/system-prompts"
|
||||||
import { getUserIdFromRequest } from "@/lib/user-id"
|
|
||||||
|
|
||||||
export const maxDuration = 120
|
export const maxDuration = 120
|
||||||
|
|
||||||
@@ -168,8 +167,13 @@ async function handleChatRequest(req: Request): Promise<Response> {
|
|||||||
|
|
||||||
const { messages, xml, previousXml, sessionId } = await req.json()
|
const { messages, xml, previousXml, sessionId } = await req.json()
|
||||||
|
|
||||||
// Get user ID for Langfuse tracking and quota
|
// Get user IP for Langfuse tracking (hashed for privacy)
|
||||||
const userId = getUserIdFromRequest(req)
|
const forwardedFor = req.headers.get("x-forwarded-for")
|
||||||
|
const rawIp = forwardedFor?.split(",")[0]?.trim() || "anonymous"
|
||||||
|
const userId =
|
||||||
|
rawIp === "anonymous"
|
||||||
|
? rawIp
|
||||||
|
: `user-${Buffer.from(rawIp).toString("base64url").slice(0, 8)}`
|
||||||
|
|
||||||
// Validate sessionId for Langfuse (must be string, max 200 chars)
|
// Validate sessionId for Langfuse (must be string, max 200 chars)
|
||||||
const validSessionId =
|
const validSessionId =
|
||||||
@@ -609,22 +613,14 @@ Operations:
|
|||||||
|
|
||||||
For update/add, new_xml must be a complete mxCell element including mxGeometry.
|
For update/add, new_xml must be a complete mxCell element including mxGeometry.
|
||||||
|
|
||||||
⚠️ JSON ESCAPING: Every " inside new_xml MUST be escaped as \\". Example: id=\\"5\\" value=\\"Label\\"
|
⚠️ JSON ESCAPING: Every " inside new_xml MUST be escaped as \\". Example: id=\\"5\\" value=\\"Label\\"`,
|
||||||
|
|
||||||
Example - Add a rectangle:
|
|
||||||
{"operations": [{"operation": "add", "cell_id": "rect-1", "new_xml": "<mxCell id=\\"rect-1\\" value=\\"Hello\\" style=\\"rounded=0;\\" vertex=\\"1\\" parent=\\"1\\"><mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/></mxCell>"}]}
|
|
||||||
|
|
||||||
Example - Delete a cell:
|
|
||||||
{"operations": [{"operation": "delete", "cell_id": "rect-1"}]}`,
|
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
operations: z
|
operations: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
operation: z
|
type: z
|
||||||
.enum(["update", "add", "delete"])
|
.enum(["update", "add", "delete"])
|
||||||
.describe(
|
.describe("Operation type"),
|
||||||
"Operation to perform: add, update, or delete",
|
|
||||||
),
|
|
||||||
cell_id: z
|
cell_id: z
|
||||||
.string()
|
.string()
|
||||||
.describe(
|
.describe(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { randomUUID } from "crypto"
|
import { randomUUID } from "crypto"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { getLangfuseClient } from "@/lib/langfuse"
|
import { getLangfuseClient } from "@/lib/langfuse"
|
||||||
import { getUserIdFromRequest } from "@/lib/user-id"
|
|
||||||
|
|
||||||
const feedbackSchema = z.object({
|
const feedbackSchema = z.object({
|
||||||
messageId: z.string().min(1).max(200),
|
messageId: z.string().min(1).max(200),
|
||||||
@@ -33,8 +32,13 @@ export async function POST(req: Request) {
|
|||||||
return Response.json({ success: true, logged: false })
|
return Response.json({ success: true, logged: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user ID for tracking
|
// Get user IP for tracking (hashed for privacy)
|
||||||
const userId = getUserIdFromRequest(req)
|
const forwardedFor = req.headers.get("x-forwarded-for")
|
||||||
|
const rawIp = forwardedFor?.split(",")[0]?.trim() || "anonymous"
|
||||||
|
const userId =
|
||||||
|
rawIp === "anonymous"
|
||||||
|
? rawIp
|
||||||
|
: `user-${Buffer.from(rawIp).toString("base64url").slice(0, 8)}`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find the most recent chat trace for this session to attach the score to
|
// Find the most recent chat trace for this session to attach the score to
|
||||||
|
|||||||
@@ -66,22 +66,8 @@ export const ModelSelectorInput = ({
|
|||||||
|
|
||||||
export type ModelSelectorListProps = ComponentProps<typeof CommandList>
|
export type ModelSelectorListProps = ComponentProps<typeof CommandList>
|
||||||
|
|
||||||
export const ModelSelectorList = ({
|
export const ModelSelectorList = (props: ModelSelectorListProps) => (
|
||||||
className,
|
<CommandList {...props} />
|
||||||
...props
|
|
||||||
}: ModelSelectorListProps) => (
|
|
||||||
<div className="relative">
|
|
||||||
<CommandList
|
|
||||||
className={cn(
|
|
||||||
// Hide scrollbar on all platforms
|
|
||||||
"[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
{/* Bottom shadow indicator for scrollable content */}
|
|
||||||
<div className="pointer-events-none absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-muted/80 via-muted/40 to-transparent" />
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export type ModelSelectorEmptyProps = ComponentProps<typeof CommandEmpty>
|
export type ModelSelectorEmptyProps = ComponentProps<typeof CommandEmpty>
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { Image as ImageIcon, Loader2, Send, Trash2 } from "lucide-react"
|
import {
|
||||||
|
Download,
|
||||||
|
History,
|
||||||
|
Image as ImageIcon,
|
||||||
|
Loader2,
|
||||||
|
Send,
|
||||||
|
Trash2,
|
||||||
|
} from "lucide-react"
|
||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { useCallback, useEffect, useRef, useState } from "react"
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { ButtonWithTooltip } from "@/components/button-with-tooltip"
|
import { ButtonWithTooltip } from "@/components/button-with-tooltip"
|
||||||
import { ErrorToast } from "@/components/error-toast"
|
import { ErrorToast } from "@/components/error-toast"
|
||||||
|
import { HistoryDialog } from "@/components/history-dialog"
|
||||||
import { ModelSelector } from "@/components/model-selector"
|
import { ModelSelector } from "@/components/model-selector"
|
||||||
import { ResetWarningModal } from "@/components/reset-warning-modal"
|
import { ResetWarningModal } from "@/components/reset-warning-modal"
|
||||||
|
import { SaveDialog } from "@/components/save-dialog"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Switch } from "@/components/ui/switch"
|
import { Switch } from "@/components/ui/switch"
|
||||||
import { Textarea } from "@/components/ui/textarea"
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
@@ -18,7 +25,7 @@ import {
|
|||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip"
|
} from "@/components/ui/tooltip"
|
||||||
|
import { useDiagram } from "@/contexts/diagram-context"
|
||||||
import { useDictionary } from "@/hooks/use-dictionary"
|
import { useDictionary } from "@/hooks/use-dictionary"
|
||||||
import { formatMessage } from "@/lib/i18n/utils"
|
import { formatMessage } from "@/lib/i18n/utils"
|
||||||
import { isPdfFile, isTextFile } from "@/lib/pdf-utils"
|
import { isPdfFile, isTextFile } from "@/lib/pdf-utils"
|
||||||
@@ -145,7 +152,8 @@ interface ChatInputProps {
|
|||||||
File,
|
File,
|
||||||
{ text: string; charCount: number; isExtracting: boolean }
|
{ text: string; charCount: number; isExtracting: boolean }
|
||||||
>
|
>
|
||||||
|
showHistory?: boolean
|
||||||
|
onToggleHistory?: (show: boolean) => void
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
error?: Error | null
|
error?: Error | null
|
||||||
minimalStyle?: boolean
|
minimalStyle?: boolean
|
||||||
@@ -154,7 +162,6 @@ interface ChatInputProps {
|
|||||||
models?: FlattenedModel[]
|
models?: FlattenedModel[]
|
||||||
selectedModelId?: string
|
selectedModelId?: string
|
||||||
onModelSelect?: (modelId: string | undefined) => void
|
onModelSelect?: (modelId: string | undefined) => void
|
||||||
showUnvalidatedModels?: boolean
|
|
||||||
onConfigureModels?: () => void
|
onConfigureModels?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,18 +174,24 @@ export function ChatInput({
|
|||||||
files = [],
|
files = [],
|
||||||
onFileChange = () => {},
|
onFileChange = () => {},
|
||||||
pdfData = new Map(),
|
pdfData = new Map(),
|
||||||
|
showHistory = false,
|
||||||
|
onToggleHistory = () => {},
|
||||||
|
sessionId,
|
||||||
error = null,
|
error = null,
|
||||||
minimalStyle = false,
|
minimalStyle = false,
|
||||||
onMinimalStyleChange = () => {},
|
onMinimalStyleChange = () => {},
|
||||||
models = [],
|
models = [],
|
||||||
selectedModelId,
|
selectedModelId,
|
||||||
onModelSelect = () => {},
|
onModelSelect = () => {},
|
||||||
showUnvalidatedModels = false,
|
|
||||||
onConfigureModels = () => {},
|
onConfigureModels = () => {},
|
||||||
}: ChatInputProps) {
|
}: ChatInputProps) {
|
||||||
const dict = useDictionary()
|
const dict = useDictionary()
|
||||||
|
const {
|
||||||
|
diagramHistory,
|
||||||
|
saveDiagramToFile,
|
||||||
|
showSaveDialog,
|
||||||
|
setShowSaveDialog,
|
||||||
|
} = useDiagram()
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
const [isDragging, setIsDragging] = useState(false)
|
const [isDragging, setIsDragging] = useState(false)
|
||||||
@@ -371,6 +384,11 @@ export function ChatInput({
|
|||||||
onClear={handleClear}
|
onClear={handleClear}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<HistoryDialog
|
||||||
|
showHistory={showHistory}
|
||||||
|
onToggleHistory={onToggleHistory}
|
||||||
|
/>
|
||||||
|
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
@@ -401,7 +419,41 @@ export function ChatInput({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-1 overflow-hidden justify-end">
|
<div className="flex items-center gap-1 overflow-hidden justify-end">
|
||||||
<div className="flex items-center gap-1 overflow-x-hidden">
|
<ButtonWithTooltip
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => onToggleHistory(true)}
|
||||||
|
disabled={isDisabled || diagramHistory.length === 0}
|
||||||
|
tooltipContent={dict.chat.diagramHistory}
|
||||||
|
className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground"
|
||||||
|
>
|
||||||
|
<History className="h-4 w-4" />
|
||||||
|
</ButtonWithTooltip>
|
||||||
|
|
||||||
|
<ButtonWithTooltip
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setShowSaveDialog(true)}
|
||||||
|
disabled={isDisabled}
|
||||||
|
tooltipContent={dict.chat.saveDiagram}
|
||||||
|
className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground"
|
||||||
|
>
|
||||||
|
<Download className="h-4 w-4" />
|
||||||
|
</ButtonWithTooltip>
|
||||||
|
|
||||||
|
<SaveDialog
|
||||||
|
open={showSaveDialog}
|
||||||
|
onOpenChange={setShowSaveDialog}
|
||||||
|
onSave={(filename, format) =>
|
||||||
|
saveDiagramToFile(filename, format, sessionId)
|
||||||
|
}
|
||||||
|
defaultFilename={`diagram-${new Date()
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 10)}`}
|
||||||
|
/>
|
||||||
|
|
||||||
<ButtonWithTooltip
|
<ButtonWithTooltip
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -423,16 +475,17 @@ export function ChatInput({
|
|||||||
multiple
|
multiple
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<ModelSelector
|
<ModelSelector
|
||||||
models={models}
|
models={models}
|
||||||
selectedModelId={selectedModelId}
|
selectedModelId={selectedModelId}
|
||||||
onSelect={onModelSelect}
|
onSelect={onModelSelect}
|
||||||
onConfigure={onConfigureModels}
|
onConfigure={onConfigureModels}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
showUnvalidatedModels={showUnvalidatedModels}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="w-px h-5 bg-border mx-1" />
|
<div className="w-px h-5 bg-border mx-1" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isDisabled || !input.trim()}
|
disabled={isDisabled || !input.trim()}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import ExamplePanel from "./chat-example-panel"
|
|||||||
import { CodeBlock } from "./code-block"
|
import { CodeBlock } from "./code-block"
|
||||||
|
|
||||||
interface DiagramOperation {
|
interface DiagramOperation {
|
||||||
operation: "update" | "add" | "delete"
|
type: "update" | "add" | "delete"
|
||||||
cell_id: string
|
cell_id: string
|
||||||
new_xml?: string
|
new_xml?: string
|
||||||
}
|
}
|
||||||
@@ -53,12 +53,12 @@ function getCompleteOperations(
|
|||||||
return operations.filter(
|
return operations.filter(
|
||||||
(op) =>
|
(op) =>
|
||||||
op &&
|
op &&
|
||||||
typeof op.operation === "string" &&
|
typeof op.type === "string" &&
|
||||||
["update", "add", "delete"].includes(op.operation) &&
|
["update", "add", "delete"].includes(op.type) &&
|
||||||
typeof op.cell_id === "string" &&
|
typeof op.cell_id === "string" &&
|
||||||
op.cell_id.length > 0 &&
|
op.cell_id.length > 0 &&
|
||||||
// delete doesn't need new_xml, update/add do
|
// delete doesn't need new_xml, update/add do
|
||||||
(op.operation === "delete" || typeof op.new_xml === "string"),
|
(op.type === "delete" || typeof op.new_xml === "string"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,20 +79,20 @@ function OperationsDisplay({ operations }: { operations: DiagramOperation[] }) {
|
|||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{operations.map((op, index) => (
|
{operations.map((op, index) => (
|
||||||
<div
|
<div
|
||||||
key={`${op.operation}-${op.cell_id}-${index}`}
|
key={`${op.type}-${op.cell_id}-${index}`}
|
||||||
className="rounded-lg border border-border/50 overflow-hidden bg-background/50"
|
className="rounded-lg border border-border/50 overflow-hidden bg-background/50"
|
||||||
>
|
>
|
||||||
<div className="px-3 py-1.5 bg-muted/40 border-b border-border/30 flex items-center gap-2">
|
<div className="px-3 py-1.5 bg-muted/40 border-b border-border/30 flex items-center gap-2">
|
||||||
<span
|
<span
|
||||||
className={`text-[10px] font-medium uppercase tracking-wide ${
|
className={`text-[10px] font-medium uppercase tracking-wide ${
|
||||||
op.operation === "delete"
|
op.type === "delete"
|
||||||
? "text-red-600"
|
? "text-red-600"
|
||||||
: op.operation === "add"
|
: op.type === "add"
|
||||||
? "text-green-600"
|
? "text-green-600"
|
||||||
: "text-blue-600"
|
: "text-blue-600"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{op.operation}
|
{op.type}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
cell_id: {op.cell_id}
|
cell_id: {op.cell_id}
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ export default function ChatPanel({
|
|||||||
// File processing using extracted hook
|
// File processing using extracted hook
|
||||||
const { files, pdfData, handleFileChange, setFiles } = useFileProcessor()
|
const { files, pdfData, handleFileChange, setFiles } = useFileProcessor()
|
||||||
|
|
||||||
|
const [showHistory, setShowHistory] = useState(false)
|
||||||
const [showSettingsDialog, setShowSettingsDialog] = useState(false)
|
const [showSettingsDialog, setShowSettingsDialog] = useState(false)
|
||||||
const [showModelConfigDialog, setShowModelConfigDialog] = useState(false)
|
const [showModelConfigDialog, setShowModelConfigDialog] = useState(false)
|
||||||
|
|
||||||
@@ -942,11 +943,7 @@ export default function ChatPanel({
|
|||||||
<div className="flex items-center gap-2 overflow-x-hidden">
|
<div className="flex items-center gap-2 overflow-x-hidden">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Image
|
<Image
|
||||||
src={
|
src="/favicon.ico"
|
||||||
darkMode
|
|
||||||
? "/favicon-white.svg"
|
|
||||||
: "/favicon.ico"
|
|
||||||
}
|
|
||||||
alt="Next AI Drawio"
|
alt="Next AI Drawio"
|
||||||
width={isMobile ? 24 : 28}
|
width={isMobile ? 24 : 28}
|
||||||
height={isMobile ? 24 : 28}
|
height={isMobile ? 24 : 28}
|
||||||
@@ -1065,6 +1062,8 @@ export default function ChatPanel({
|
|||||||
files={files}
|
files={files}
|
||||||
onFileChange={handleFileChange}
|
onFileChange={handleFileChange}
|
||||||
pdfData={pdfData}
|
pdfData={pdfData}
|
||||||
|
showHistory={showHistory}
|
||||||
|
onToggleHistory={setShowHistory}
|
||||||
sessionId={sessionId}
|
sessionId={sessionId}
|
||||||
error={error}
|
error={error}
|
||||||
minimalStyle={minimalStyle}
|
minimalStyle={minimalStyle}
|
||||||
@@ -1072,7 +1071,6 @@ export default function ChatPanel({
|
|||||||
models={modelConfig.models}
|
models={modelConfig.models}
|
||||||
selectedModelId={modelConfig.selectedModelId}
|
selectedModelId={modelConfig.selectedModelId}
|
||||||
onModelSelect={modelConfig.setSelectedModelId}
|
onModelSelect={modelConfig.setSelectedModelId}
|
||||||
showUnvalidatedModels={modelConfig.showUnvalidatedModels}
|
|
||||||
onConfigureModels={() => setShowModelConfigDialog(true)}
|
onConfigureModels={() => setShowModelConfigDialog(true)}
|
||||||
/>
|
/>
|
||||||
</footer>
|
</footer>
|
||||||
@@ -1085,7 +1083,6 @@ export default function ChatPanel({
|
|||||||
onToggleDrawioUi={onToggleDrawioUi}
|
onToggleDrawioUi={onToggleDrawioUi}
|
||||||
darkMode={darkMode}
|
darkMode={darkMode}
|
||||||
onToggleDarkMode={onToggleDarkMode}
|
onToggleDarkMode={onToggleDarkMode}
|
||||||
sessionId={sessionId}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ModelConfigDialog
|
<ModelConfigDialog
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import { Switch } from "@/components/ui/switch"
|
|
||||||
import { useDictionary } from "@/hooks/use-dictionary"
|
import { useDictionary } from "@/hooks/use-dictionary"
|
||||||
import type { UseModelConfigReturn } from "@/hooks/use-model-config"
|
import type { UseModelConfigReturn } from "@/hooks/use-model-config"
|
||||||
import { formatMessage } from "@/lib/i18n/utils"
|
import { formatMessage } from "@/lib/i18n/utils"
|
||||||
@@ -413,7 +412,11 @@ export function ModelConfigDialog({
|
|||||||
setSelectedProviderId(
|
setSelectedProviderId(
|
||||||
provider.id,
|
provider.id,
|
||||||
)
|
)
|
||||||
setValidationStatus("idle")
|
setValidationStatus(
|
||||||
|
provider.validated
|
||||||
|
? "success"
|
||||||
|
: "idle",
|
||||||
|
)
|
||||||
setShowApiKey(false)
|
setShowApiKey(false)
|
||||||
}}
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -501,7 +504,7 @@ export function ModelConfigDialog({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Provider Details (Right Panel) */}
|
{/* Provider Details (Right Panel) */}
|
||||||
<div className="flex-1 min-w-0 flex flex-col overflow-auto [&::-webkit-scrollbar]:hidden ">
|
<div className="flex-1 min-w-0 flex flex-col overflow-hidden">
|
||||||
{selectedProvider ? (
|
{selectedProvider ? (
|
||||||
<>
|
<>
|
||||||
<ScrollArea className="flex-1" ref={scrollRef}>
|
<ScrollArea className="flex-1" ref={scrollRef}>
|
||||||
@@ -552,20 +555,6 @@ export function ModelConfigDialog({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() =>
|
|
||||||
setDeleteConfirmOpen(true)
|
|
||||||
}
|
|
||||||
className="text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
||||||
>
|
|
||||||
<Trash2 className="h-4 w-4 mr-1.5" />
|
|
||||||
{
|
|
||||||
dict.modelConfig
|
|
||||||
.deleteProvider
|
|
||||||
}
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Configuration Section */}
|
{/* Configuration Section */}
|
||||||
@@ -1427,6 +1416,24 @@ export function ModelConfigDialog({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ConfigSection>
|
</ConfigSection>
|
||||||
|
|
||||||
|
{/* Danger Zone */}
|
||||||
|
<div className="pt-4">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
setDeleteConfirmOpen(true)
|
||||||
|
}
|
||||||
|
className="text-muted-foreground hover:text-destructive hover:bg-destructive/5 rounded-xl"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4 mr-2" />
|
||||||
|
{
|
||||||
|
dict.modelConfig
|
||||||
|
.deleteProvider
|
||||||
|
}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</>
|
</>
|
||||||
@@ -1448,24 +1455,11 @@ export function ModelConfigDialog({
|
|||||||
|
|
||||||
{/* Footer */}
|
{/* Footer */}
|
||||||
<div className="px-6 py-3 border-t border-border-subtle bg-surface-1/30 shrink-0">
|
<div className="px-6 py-3 border-t border-border-subtle bg-surface-1/30 shrink-0">
|
||||||
<div className="flex items-center justify-between">
|
<p className="text-xs text-muted-foreground text-center flex items-center justify-center gap-1.5">
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Switch
|
|
||||||
checked={modelConfig.showUnvalidatedModels}
|
|
||||||
onCheckedChange={
|
|
||||||
modelConfig.setShowUnvalidatedModels
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Label className="text-xs text-muted-foreground cursor-pointer">
|
|
||||||
{dict.modelConfig.showUnvalidatedModels}
|
|
||||||
</Label>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-muted-foreground flex items-center gap-1.5">
|
|
||||||
<Key className="h-3 w-3" />
|
<Key className="h-3 w-3" />
|
||||||
{dict.modelConfig.apiKeyStored}
|
{dict.modelConfig.apiKeyStored}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
{/* Delete Confirmation Dialog */}
|
{/* Delete Confirmation Dialog */}
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import {
|
import { Bot, Check, ChevronDown, Server, Settings2 } from "lucide-react"
|
||||||
AlertTriangle,
|
|
||||||
Bot,
|
|
||||||
Check,
|
|
||||||
ChevronDown,
|
|
||||||
Server,
|
|
||||||
Settings2,
|
|
||||||
} from "lucide-react"
|
|
||||||
import { useMemo, useState } from "react"
|
import { useMemo, useState } from "react"
|
||||||
import {
|
import {
|
||||||
ModelSelectorContent,
|
ModelSelectorContent,
|
||||||
@@ -33,7 +26,6 @@ interface ModelSelectorProps {
|
|||||||
onSelect: (modelId: string | undefined) => void
|
onSelect: (modelId: string | undefined) => void
|
||||||
onConfigure: () => void
|
onConfigure: () => void
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
showUnvalidatedModels?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map our provider names to models.dev logo names
|
// Map our provider names to models.dev logo names
|
||||||
@@ -75,20 +67,17 @@ export function ModelSelector({
|
|||||||
onSelect,
|
onSelect,
|
||||||
onConfigure,
|
onConfigure,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
showUnvalidatedModels = false,
|
|
||||||
}: ModelSelectorProps) {
|
}: ModelSelectorProps) {
|
||||||
const dict = useDictionary()
|
const dict = useDictionary()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
// Filter models based on showUnvalidatedModels setting
|
// Only show validated models in the selector
|
||||||
const displayModels = useMemo(() => {
|
const validatedModels = useMemo(
|
||||||
if (showUnvalidatedModels) {
|
() => models.filter((m) => m.validated === true),
|
||||||
return models
|
[models],
|
||||||
}
|
)
|
||||||
return models.filter((m) => m.validated === true)
|
|
||||||
}, [models, showUnvalidatedModels])
|
|
||||||
const groupedModels = useMemo(
|
const groupedModels = useMemo(
|
||||||
() => groupModelsByProvider(displayModels),
|
() => groupModelsByProvider(validatedModels),
|
||||||
[displayModels],
|
[validatedModels],
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find selected model for display
|
// Find selected model for display
|
||||||
@@ -135,9 +124,9 @@ export function ModelSelector({
|
|||||||
<ModelSelectorInput
|
<ModelSelectorInput
|
||||||
placeholder={dict.modelConfig.searchModels}
|
placeholder={dict.modelConfig.searchModels}
|
||||||
/>
|
/>
|
||||||
<ModelSelectorList className="[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
|
<ModelSelectorList>
|
||||||
<ModelSelectorEmpty>
|
<ModelSelectorEmpty>
|
||||||
{displayModels.length === 0 && models.length > 0
|
{validatedModels.length === 0 && models.length > 0
|
||||||
? dict.modelConfig.noVerifiedModels
|
? dict.modelConfig.noVerifiedModels
|
||||||
: dict.modelConfig.noModelsFound}
|
: dict.modelConfig.noModelsFound}
|
||||||
</ModelSelectorEmpty>
|
</ModelSelectorEmpty>
|
||||||
@@ -202,16 +191,6 @@ export function ModelSelector({
|
|||||||
<ModelSelectorName>
|
<ModelSelectorName>
|
||||||
{model.modelId}
|
{model.modelId}
|
||||||
</ModelSelectorName>
|
</ModelSelectorName>
|
||||||
{model.validated !== true && (
|
|
||||||
<span
|
|
||||||
title={
|
|
||||||
dict.modelConfig
|
|
||||||
.unvalidatedModelWarning
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<AlertTriangle className="ml-auto h-3 w-3 text-warning" />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</ModelSelectorItem>
|
</ModelSelectorItem>
|
||||||
))}
|
))}
|
||||||
</ModelSelectorGroup>
|
</ModelSelectorGroup>
|
||||||
@@ -234,9 +213,7 @@ export function ModelSelector({
|
|||||||
</ModelSelectorGroup>
|
</ModelSelectorGroup>
|
||||||
{/* Info text */}
|
{/* Info text */}
|
||||||
<div className="px-3 py-2 text-xs text-muted-foreground border-t">
|
<div className="px-3 py-2 text-xs text-muted-foreground border-t">
|
||||||
{showUnvalidatedModels
|
{dict.modelConfig.onlyVerifiedShown}
|
||||||
? dict.modelConfig.allModelsShown
|
|
||||||
: dict.modelConfig.onlyVerifiedShown}
|
|
||||||
</div>
|
</div>
|
||||||
</ModelSelectorList>
|
</ModelSelectorList>
|
||||||
</ModelSelectorContent>
|
</ModelSelectorContent>
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { Download, History, Moon, Sun } from "lucide-react"
|
import { Moon, Sun } from "lucide-react"
|
||||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||||
import { Suspense, useEffect, useState } from "react"
|
import { Suspense, useEffect, useState } from "react"
|
||||||
import { HistoryDialog } from "@/components/history-dialog"
|
|
||||||
import { type ExportFormat, SaveDialog } from "@/components/save-dialog"
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -23,7 +21,6 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import { Switch } from "@/components/ui/switch"
|
import { Switch } from "@/components/ui/switch"
|
||||||
import { useDiagram } from "@/contexts/diagram-context"
|
|
||||||
import { useDictionary } from "@/hooks/use-dictionary"
|
import { useDictionary } from "@/hooks/use-dictionary"
|
||||||
import { getApiEndpoint } from "@/lib/base-path"
|
import { getApiEndpoint } from "@/lib/base-path"
|
||||||
import { i18n, type Locale } from "@/lib/i18n/config"
|
import { i18n, type Locale } from "@/lib/i18n/config"
|
||||||
@@ -68,7 +65,6 @@ interface SettingsDialogProps {
|
|||||||
onToggleDrawioUi: () => void
|
onToggleDrawioUi: () => void
|
||||||
darkMode: boolean
|
darkMode: boolean
|
||||||
onToggleDarkMode: () => void
|
onToggleDarkMode: () => void
|
||||||
sessionId?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const STORAGE_ACCESS_CODE_KEY = "next-ai-draw-io-access-code"
|
export const STORAGE_ACCESS_CODE_KEY = "next-ai-draw-io-access-code"
|
||||||
@@ -90,7 +86,6 @@ function SettingsContent({
|
|||||||
onToggleDrawioUi,
|
onToggleDrawioUi,
|
||||||
darkMode,
|
darkMode,
|
||||||
onToggleDarkMode,
|
onToggleDarkMode,
|
||||||
sessionId,
|
|
||||||
}: SettingsDialogProps) {
|
}: SettingsDialogProps) {
|
||||||
const dict = useDictionary()
|
const dict = useDictionary()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -100,21 +95,11 @@ function SettingsContent({
|
|||||||
const [closeProtection, setCloseProtection] = useState(true)
|
const [closeProtection, setCloseProtection] = useState(true)
|
||||||
const [isVerifying, setIsVerifying] = useState(false)
|
const [isVerifying, setIsVerifying] = useState(false)
|
||||||
const [error, setError] = useState("")
|
const [error, setError] = useState("")
|
||||||
const [showHistory, setShowHistory] = useState(false)
|
|
||||||
const [showSaveDialog, setShowSaveDialog] = useState(false)
|
|
||||||
const [accessCodeRequired, setAccessCodeRequired] = useState(
|
const [accessCodeRequired, setAccessCodeRequired] = useState(
|
||||||
() => getStoredAccessCodeRequired() ?? false,
|
() => getStoredAccessCodeRequired() ?? false,
|
||||||
)
|
)
|
||||||
const [currentLang, setCurrentLang] = useState("en")
|
const [currentLang, setCurrentLang] = useState("en")
|
||||||
|
|
||||||
// Get diagram context
|
|
||||||
const { diagramHistory, saveDiagramToFile } = useDiagram()
|
|
||||||
|
|
||||||
// Handler for saving diagram (RENAMED to avoid conflict)
|
|
||||||
const handleDiagramSave = (filename: string, format: ExportFormat) => {
|
|
||||||
saveDiagramToFile(filename, format, sessionId)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only fetch if not cached in localStorage
|
// Only fetch if not cached in localStorage
|
||||||
if (getStoredAccessCodeRequired() !== null) return
|
if (getStoredAccessCodeRequired() !== null) return
|
||||||
@@ -166,9 +151,6 @@ function SettingsContent({
|
|||||||
}, [open])
|
}, [open])
|
||||||
|
|
||||||
const changeLanguage = (lang: string) => {
|
const changeLanguage = (lang: string) => {
|
||||||
// Save locale to localStorage for persistence across restarts
|
|
||||||
localStorage.setItem("next-ai-draw-io-locale", lang)
|
|
||||||
|
|
||||||
const parts = pathname.split("/")
|
const parts = pathname.split("/")
|
||||||
if (parts.length > 1 && i18n.locales.includes(parts[1] as Locale)) {
|
if (parts.length > 1 && i18n.locales.includes(parts[1] as Locale)) {
|
||||||
parts[1] = lang
|
parts[1] = lang
|
||||||
@@ -221,7 +203,6 @@ function SettingsContent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<DialogContent className="sm:max-w-lg p-0 gap-0">
|
<DialogContent className="sm:max-w-lg p-0 gap-0">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<DialogHeader className="px-6 pt-6 pb-4">
|
<DialogHeader className="px-6 pt-6 pb-4">
|
||||||
@@ -265,9 +246,7 @@ function SettingsContent({
|
|||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSave}
|
onClick={handleSave}
|
||||||
disabled={
|
disabled={isVerifying || !accessCode.trim()}
|
||||||
isVerifying || !accessCode.trim()
|
|
||||||
}
|
|
||||||
className="h-9 px-4 rounded-xl"
|
className="h-9 px-4 rounded-xl"
|
||||||
>
|
>
|
||||||
{isVerifying ? "..." : dict.common.save}
|
{isVerifying ? "..." : dict.common.save}
|
||||||
@@ -351,9 +330,7 @@ function SettingsContent({
|
|||||||
{/* Close Protection */}
|
{/* Close Protection */}
|
||||||
<SettingItem
|
<SettingItem
|
||||||
label={dict.settings.closeProtection}
|
label={dict.settings.closeProtection}
|
||||||
description={
|
description={dict.settings.closeProtectionDescription}
|
||||||
dict.settings.closeProtectionDescription
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
id="close-protection"
|
id="close-protection"
|
||||||
@@ -368,38 +345,6 @@ function SettingsContent({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
{/* Diagram Actions */}
|
|
||||||
<SettingItem
|
|
||||||
label={dict.settings.diagramActions}
|
|
||||||
description={
|
|
||||||
dict.settings.diagramActionsDescription
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
id="history-button"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => setShowHistory(true)}
|
|
||||||
disabled={diagramHistory.length === 0}
|
|
||||||
className="h-9 rounded-xl border-border-subtle hover:bg-interactive-hover"
|
|
||||||
>
|
|
||||||
<History className="h-4 w-4 mr-1.5" />
|
|
||||||
{dict.settings.history}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
id="download-button"
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => setShowSaveDialog(true)}
|
|
||||||
className="h-9 rounded-xl border-border-subtle hover:bg-interactive-hover"
|
|
||||||
>
|
|
||||||
<Download className="h-4 w-4 mr-1.5" />
|
|
||||||
{dict.settings.download}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</SettingItem>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -410,22 +355,6 @@ function SettingsContent({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
;(
|
|
||||||
<HistoryDialog
|
|
||||||
showHistory={showHistory}
|
|
||||||
onToggleHistory={setShowHistory}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
<SaveDialog
|
|
||||||
open={showSaveDialog}
|
|
||||||
onOpenChange={setShowSaveDialog}
|
|
||||||
onSave={handleDiagramSave}
|
|
||||||
defaultFilename={`diagram-${new Date()
|
|
||||||
.toISOString()
|
|
||||||
.slice(0, 10)}
|
|
||||||
`}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,267 +0,0 @@
|
|||||||
# Deploy on Cloudflare Workers
|
|
||||||
|
|
||||||
This project can be deployed as a **Cloudflare Worker** using the **OpenNext adapter**, giving you:
|
|
||||||
|
|
||||||
- Global edge deployment
|
|
||||||
- Very low latency
|
|
||||||
- Free `workers.dev` hosting
|
|
||||||
- Full Next.js ISR support via R2 (optional)
|
|
||||||
|
|
||||||
> **Important Windows Note:** OpenNext and Wrangler are **not fully reliable on native Windows**. Recommended options:
|
|
||||||
>
|
|
||||||
> - Use **GitHub Codespaces** (works perfectly)
|
|
||||||
> - OR use **WSL (Linux)**
|
|
||||||
>
|
|
||||||
> Pure Windows builds may fail due to WASM file path issues.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
1. A **Cloudflare account** (free tier works for basic deployment)
|
|
||||||
2. **Node.js 18+**
|
|
||||||
3. **Wrangler CLI** installed (dev dependency is fine):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install -D wrangler
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Cloudflare login:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx wrangler login
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Note:** A payment method is only required if you want to enable R2 for ISR caching. Basic Workers deployment is free.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 1 — Install dependencies
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 2 — Configure environment variables
|
|
||||||
|
|
||||||
Cloudflare uses a different file for local testing.
|
|
||||||
|
|
||||||
### 1) Create `.dev.vars` (for Cloudflare local + deploy)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cp env.example .dev.vars
|
|
||||||
```
|
|
||||||
|
|
||||||
Fill in your API keys and configuration.
|
|
||||||
|
|
||||||
### 2) Make sure `.env.local` also exists (for regular Next.js dev)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cp env.example .env.local
|
|
||||||
```
|
|
||||||
|
|
||||||
Fill in the same values there.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 3 — Choose your deployment type
|
|
||||||
|
|
||||||
### Option A: Deploy WITHOUT R2 (Simple, Free)
|
|
||||||
|
|
||||||
If you don't need ISR caching, you can deploy without R2:
|
|
||||||
|
|
||||||
**1. Use simple `open-next.config.ts`:**
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config"
|
|
||||||
|
|
||||||
export default defineCloudflareConfig({})
|
|
||||||
```
|
|
||||||
|
|
||||||
**2. Use simple `wrangler.jsonc` (without r2_buckets):**
|
|
||||||
|
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
"$schema": "node_modules/wrangler/config-schema.json",
|
|
||||||
"main": ".open-next/worker.js",
|
|
||||||
"name": "next-ai-draw-io-worker",
|
|
||||||
"compatibility_date": "2025-12-08",
|
|
||||||
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
|
|
||||||
"assets": {
|
|
||||||
"directory": ".open-next/assets",
|
|
||||||
"binding": "ASSETS"
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"binding": "WORKER_SELF_REFERENCE",
|
|
||||||
"service": "next-ai-draw-io-worker"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Skip to **Step 4**.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Option B: Deploy WITH R2 (Full ISR Support)
|
|
||||||
|
|
||||||
R2 enables **Incremental Static Regeneration (ISR)** caching. Requires a payment method on your Cloudflare account.
|
|
||||||
|
|
||||||
**1. Create an R2 bucket** in the Cloudflare Dashboard:
|
|
||||||
|
|
||||||
- Go to **Storage & Databases → R2**
|
|
||||||
- Click **Create bucket**
|
|
||||||
- Name it: `next-inc-cache`
|
|
||||||
|
|
||||||
**2. Configure `open-next.config.ts`:**
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config"
|
|
||||||
import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache"
|
|
||||||
|
|
||||||
export default defineCloudflareConfig({
|
|
||||||
incrementalCache: r2IncrementalCache,
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
**3. Configure `wrangler.jsonc` (with R2):**
|
|
||||||
|
|
||||||
```jsonc
|
|
||||||
{
|
|
||||||
"$schema": "node_modules/wrangler/config-schema.json",
|
|
||||||
"main": ".open-next/worker.js",
|
|
||||||
"name": "next-ai-draw-io-worker",
|
|
||||||
"compatibility_date": "2025-12-08",
|
|
||||||
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
|
|
||||||
"assets": {
|
|
||||||
"directory": ".open-next/assets",
|
|
||||||
"binding": "ASSETS"
|
|
||||||
},
|
|
||||||
"r2_buckets": [
|
|
||||||
{
|
|
||||||
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
|
||||||
"bucket_name": "next-inc-cache"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"binding": "WORKER_SELF_REFERENCE",
|
|
||||||
"service": "next-ai-draw-io-worker"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Important:** The `bucket_name` must exactly match the name you created in the Cloudflare dashboard.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 4 — Register a workers.dev subdomain (first-time only)
|
|
||||||
|
|
||||||
Before your first deployment, you need a workers.dev subdomain.
|
|
||||||
|
|
||||||
**Option 1: Via Cloudflare Dashboard (Recommended)**
|
|
||||||
|
|
||||||
Visit: https://dash.cloudflare.com → Workers & Pages → Overview → Set up a subdomain
|
|
||||||
|
|
||||||
**Option 2: During deploy**
|
|
||||||
|
|
||||||
When you run `npm run deploy`, Wrangler may prompt:
|
|
||||||
|
|
||||||
```
|
|
||||||
Would you like to register a workers.dev subdomain? (Y/n)
|
|
||||||
```
|
|
||||||
|
|
||||||
Type `Y` and choose a subdomain name.
|
|
||||||
|
|
||||||
> **Note:** In CI/CD or non-interactive environments, the prompt won't appear. Register via the dashboard first.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 5 — Deploy to Cloudflare
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run deploy
|
|
||||||
```
|
|
||||||
|
|
||||||
What the script does:
|
|
||||||
|
|
||||||
- Builds the Next.js app
|
|
||||||
- Converts it to a Cloudflare Worker via OpenNext
|
|
||||||
- Uploads static assets
|
|
||||||
- Publishes the Worker
|
|
||||||
|
|
||||||
Your app will be available at:
|
|
||||||
|
|
||||||
```
|
|
||||||
https://<worker-name>.<your-subdomain>.workers.dev
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Common issues & fixes
|
|
||||||
|
|
||||||
### `You need to register a workers.dev subdomain`
|
|
||||||
|
|
||||||
**Cause:** No workers.dev subdomain registered for your account.
|
|
||||||
|
|
||||||
**Fix:** Go to https://dash.cloudflare.com → Workers & Pages → Set up a subdomain.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### `Please enable R2 through the Cloudflare Dashboard`
|
|
||||||
|
|
||||||
**Cause:** R2 is configured in wrangler.jsonc but not enabled on your account.
|
|
||||||
|
|
||||||
**Fix:** Either enable R2 (requires payment method) or use Option A (deploy without R2).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### `No R2 binding "NEXT_INC_CACHE_R2_BUCKET" found`
|
|
||||||
|
|
||||||
**Cause:** `r2_buckets` is missing from `wrangler.jsonc`.
|
|
||||||
|
|
||||||
**Fix:** Add the `r2_buckets` section or switch to Option A (without R2).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### `Can't set compatibility date in the future`
|
|
||||||
|
|
||||||
**Cause:** `compatibility_date` in wrangler config is set to a future date.
|
|
||||||
|
|
||||||
**Fix:** Change `compatibility_date` to today or an earlier date.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Windows error: `resvg.wasm?module` (ENOENT)
|
|
||||||
|
|
||||||
**Cause:** Windows filenames cannot include `?`, but a wasm asset uses `?module` in its filename.
|
|
||||||
|
|
||||||
**Fix:** Build/deploy on Linux (WSL, Codespaces, or CI).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Optional: Preview locally
|
|
||||||
|
|
||||||
Preview the Worker locally before deploying:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run preview
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Summary
|
|
||||||
|
|
||||||
| Feature | Without R2 | With R2 |
|
|
||||||
|---------|------------|---------|
|
|
||||||
| Cost | Free | Requires payment method |
|
|
||||||
| ISR Caching | No | Yes |
|
|
||||||
| Static Pages | Yes | Yes |
|
|
||||||
| API Routes | Yes | Yes |
|
|
||||||
| Setup Complexity | Simple | Moderate |
|
|
||||||
|
|
||||||
Choose **without R2** for testing or simple apps. Choose **with R2** for production apps that need ISR caching.
|
|
||||||
@@ -33,7 +33,7 @@ services:
|
|||||||
| Scenario | URL Value |
|
| Scenario | URL Value |
|
||||||
|----------|-----------|
|
|----------|-----------|
|
||||||
| Localhost | `http://localhost:8080` |
|
| Localhost | `http://localhost:8080` |
|
||||||
| Remote/Server | `http://YOUR_SERVER_IP:8080` |
|
| Remote/Server | `http://YOUR_SERVER_IP:8080` or `https://drawio.your-domain.com` |
|
||||||
|
|
||||||
**Do NOT use** internal Docker aliases like `http://drawio:8080`; the browser cannot resolve them.
|
**Do NOT use** internal Docker aliases like `http://drawio:8080`; the browser cannot resolve them.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.alibaba_cloud.{shape};fillColor=#FF6A00;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.alibaba_cloud.{shape};fillColor=#FF6A00;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="image;aspect=fixed;image=img/lib/atlassian/Jira_Logo.svg;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="image;aspect=fixed;image=img/lib/atlassian/Jira_Logo.svg;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.{shape};fillColor=#ED7100;strokeColor=#ffffff;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.{shape};fillColor=#ED7100;strokeColor=#ffffff;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="image;aspect=fixed;image=img/lib/azure2/compute/Virtual_Machine.svg;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="image;aspect=fixed;image=img/lib/azure2/compute/Virtual_Machine.svg;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.cisco19.rect;prIcon={shape};fillColor=#00bceb;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.cisco19.rect;prIcon={shape};fillColor=#00bceb;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.citrix.{shape};fillColor=#00A4E4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.citrix.{shape};fillColor=#00A4E4;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.gcp2.{shape};fillColor=#4285F4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.gcp2.{shape};fillColor=#4285F4;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.kubernetes.icon;prIcon={shape};fillColor=#326CE5;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.kubernetes.icon;prIcon={shape};fillColor=#326CE5;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.mscae.cloud.azure;fillColor=#0078D4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.mscae.cloud.azure;fillColor=#0078D4;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.networks.server;fillColor=#29AAE1;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.networks.server;fillColor=#29AAE1;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.openstack.{shape};fillColor=#3F51B5;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.openstack.{shape};fillColor=#3F51B5;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.salesforce.analytics;fillColor=#7f8de1;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.salesforce.analytics;fillColor=#7f8de1;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="image;aspect=fixed;image=img/lib/sap/SAP_Logo.svg;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="image;aspect=fixed;image=img/lib/sap/SAP_Logo.svg;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.vvd.{shape};fillColor=#00AEEF;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.vvd.{shape};fillColor=#00AEEF;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<mxCell value="label" style="shape=mxgraph.webicons.{shape};fillColor=#3b5998;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.webicons.{shape};fillColor=#3b5998;strokeColor=none;" vertex="1" parent="1">
|
||||||
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
<mxGeometry x="0" y="0" width="60" height="60" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ import { app } from "electron"
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Port configuration
|
* Port configuration
|
||||||
* Using fixed ports to preserve localStorage across restarts
|
|
||||||
* (localStorage is origin-specific, so changing ports loses all saved data)
|
|
||||||
*/
|
*/
|
||||||
const PORT_CONFIG = {
|
const PORT_CONFIG = {
|
||||||
// Development mode uses fixed port for hot reload compatibility
|
// Development mode uses fixed port for hot reload compatibility
|
||||||
development: 6002,
|
development: 6002,
|
||||||
// Production mode uses fixed port (61337) to preserve localStorage
|
// Production mode port range (will find first available)
|
||||||
// Falls back to sequential ports if unavailable
|
production: {
|
||||||
production: 61337,
|
min: 10000,
|
||||||
// Maximum attempts to find an available port (fallback)
|
max: 65535,
|
||||||
|
},
|
||||||
|
// Maximum attempts to find an available port
|
||||||
maxAttempts: 100,
|
maxAttempts: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,11 +36,19 @@ export function isPortAvailable(port: number): Promise<boolean> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random port within the production range
|
||||||
|
*/
|
||||||
|
function getRandomPort(): number {
|
||||||
|
const { min, max } = PORT_CONFIG.production
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an available port
|
* Find an available port
|
||||||
* - In development: uses fixed port (6002)
|
* - In development: uses fixed port (6002)
|
||||||
* - In production: uses fixed port (61337) to preserve localStorage
|
* - In production: finds a random available port
|
||||||
* - Falls back to sequential ports if preferred port is unavailable
|
* - If a port was previously allocated, verifies it's still available
|
||||||
*
|
*
|
||||||
* @param reuseExisting If true, try to reuse the previously allocated port
|
* @param reuseExisting If true, try to reuse the previously allocated port
|
||||||
* @returns Promise<number> The available port
|
* @returns Promise<number> The available port
|
||||||
@@ -48,9 +56,6 @@ export function isPortAvailable(port: number): Promise<boolean> {
|
|||||||
*/
|
*/
|
||||||
export async function findAvailablePort(reuseExisting = true): Promise<number> {
|
export async function findAvailablePort(reuseExisting = true): Promise<number> {
|
||||||
const isDev = !app.isPackaged
|
const isDev = !app.isPackaged
|
||||||
const preferredPort = isDev
|
|
||||||
? PORT_CONFIG.development
|
|
||||||
: PORT_CONFIG.production
|
|
||||||
|
|
||||||
// Try to reuse cached port if requested and available
|
// Try to reuse cached port if requested and available
|
||||||
if (reuseExisting && allocatedPort !== null) {
|
if (reuseExisting && allocatedPort !== null) {
|
||||||
@@ -64,22 +69,29 @@ export async function findAvailablePort(reuseExisting = true): Promise<number> {
|
|||||||
allocatedPort = null
|
allocatedPort = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try preferred port first
|
if (isDev) {
|
||||||
if (await isPortAvailable(preferredPort)) {
|
// Development mode: use fixed port
|
||||||
allocatedPort = preferredPort
|
const port = PORT_CONFIG.development
|
||||||
return preferredPort
|
const available = await isPortAvailable(port)
|
||||||
|
if (available) {
|
||||||
|
allocatedPort = port
|
||||||
|
return port
|
||||||
|
}
|
||||||
|
console.warn(
|
||||||
|
`Development port ${port} is in use, finding alternative...`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.warn(
|
// Production mode or dev port unavailable: find random available port
|
||||||
`Preferred port ${preferredPort} is in use, finding alternative...`,
|
for (let attempt = 0; attempt < PORT_CONFIG.maxAttempts; attempt++) {
|
||||||
)
|
const port = isDev
|
||||||
|
? PORT_CONFIG.development + attempt + 1
|
||||||
|
: getRandomPort()
|
||||||
|
|
||||||
// Fallback: try sequential ports starting from preferred + 1
|
const available = await isPortAvailable(port)
|
||||||
for (let attempt = 1; attempt <= PORT_CONFIG.maxAttempts; attempt++) {
|
if (available) {
|
||||||
const port = preferredPort + attempt
|
|
||||||
if (await isPortAvailable(port)) {
|
|
||||||
allocatedPort = port
|
allocatedPort = port
|
||||||
console.log(`Allocated fallback port: ${port}`)
|
console.log(`Allocated port: ${port}`)
|
||||||
return port
|
return port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="deprecation-notice">
|
|
||||||
<strong>⚠️ Deprecation Notice</strong>
|
|
||||||
<p>This settings panel will be removed in a future update.</p>
|
|
||||||
<p>Please use the <strong>AI Model Configuration</strong> button (left of the Send button in the chat panel) to configure your AI providers. Your settings there will persist across updates.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h1>Configuration Presets</h1>
|
<h1>Configuration Presets</h1>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
|
|||||||
@@ -24,39 +24,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.deprecation-notice {
|
|
||||||
background-color: #fff3cd;
|
|
||||||
border: 1px solid #ffc107;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 16px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.deprecation-notice strong {
|
|
||||||
color: #856404;
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.deprecation-notice p {
|
|
||||||
color: #856404;
|
|
||||||
font-size: 13px;
|
|
||||||
margin: 4px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
.deprecation-notice {
|
|
||||||
background-color: #332701;
|
|
||||||
border-color: #665200;
|
|
||||||
}
|
|
||||||
|
|
||||||
.deprecation-notice strong,
|
|
||||||
.deprecation-notice p {
|
|
||||||
color: #ffc107;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type AddToolOutputParams = AddToolOutputSuccess | AddToolOutputError
|
|||||||
type AddToolOutputFn = (params: AddToolOutputParams) => void
|
type AddToolOutputFn = (params: AddToolOutputParams) => void
|
||||||
|
|
||||||
interface DiagramOperation {
|
interface DiagramOperation {
|
||||||
operation: "update" | "add" | "delete"
|
type: "update" | "add" | "delete"
|
||||||
cell_id: string
|
cell_id: string
|
||||||
new_xml?: string
|
new_xml?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,11 +109,9 @@ export interface UseModelConfigReturn {
|
|||||||
models: FlattenedModel[]
|
models: FlattenedModel[]
|
||||||
selectedModel: FlattenedModel | undefined
|
selectedModel: FlattenedModel | undefined
|
||||||
selectedModelId: string | undefined
|
selectedModelId: string | undefined
|
||||||
showUnvalidatedModels: boolean
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
setSelectedModelId: (modelId: string | undefined) => void
|
setSelectedModelId: (modelId: string | undefined) => void
|
||||||
setShowUnvalidatedModels: (show: boolean) => void
|
|
||||||
addProvider: (provider: ProviderName) => ProviderConfig
|
addProvider: (provider: ProviderName) => ProviderConfig
|
||||||
updateProvider: (
|
updateProvider: (
|
||||||
providerId: string,
|
providerId: string,
|
||||||
@@ -162,13 +160,6 @@ export function useModelConfig(): UseModelConfigReturn {
|
|||||||
}))
|
}))
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const setShowUnvalidatedModels = useCallback((show: boolean) => {
|
|
||||||
setConfig((prev) => ({
|
|
||||||
...prev,
|
|
||||||
showUnvalidatedModels: show,
|
|
||||||
}))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const addProvider = useCallback(
|
const addProvider = useCallback(
|
||||||
(provider: ProviderName): ProviderConfig => {
|
(provider: ProviderName): ProviderConfig => {
|
||||||
const newProvider = createProviderConfig(provider)
|
const newProvider = createProviderConfig(provider)
|
||||||
@@ -287,9 +278,7 @@ export function useModelConfig(): UseModelConfigReturn {
|
|||||||
models,
|
models,
|
||||||
selectedModel,
|
selectedModel,
|
||||||
selectedModelId: config.selectedModelId,
|
selectedModelId: config.selectedModelId,
|
||||||
showUnvalidatedModels: config.showUnvalidatedModels ?? false,
|
|
||||||
setSelectedModelId,
|
setSelectedModelId,
|
||||||
setShowUnvalidatedModels,
|
|
||||||
addProvider,
|
addProvider,
|
||||||
updateProvider,
|
updateProvider,
|
||||||
deleteProvider,
|
deleteProvider,
|
||||||
|
|||||||
@@ -14,14 +14,22 @@ export function register() {
|
|||||||
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
||||||
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
||||||
baseUrl: process.env.LANGFUSE_BASEURL,
|
baseUrl: process.env.LANGFUSE_BASEURL,
|
||||||
// Whitelist approach: only export AI-related spans
|
// Filter out Next.js HTTP request spans so AI SDK spans become root traces
|
||||||
shouldExportSpan: ({ otelSpan }) => {
|
shouldExportSpan: ({ otelSpan }) => {
|
||||||
const spanName = otelSpan.name
|
const spanName = otelSpan.name
|
||||||
// Only export AI SDK spans (ai.*) and our explicit "chat" wrapper
|
// Skip Next.js HTTP infrastructure spans
|
||||||
if (spanName === "chat" || spanName.startsWith("ai.")) {
|
if (
|
||||||
return true
|
spanName.startsWith("POST") ||
|
||||||
}
|
spanName.startsWith("GET") ||
|
||||||
|
spanName.startsWith("RSC") ||
|
||||||
|
spanName.includes("BaseServer") ||
|
||||||
|
spanName.includes("handleRequest") ||
|
||||||
|
spanName.includes("resolve page") ||
|
||||||
|
spanName.includes("start response")
|
||||||
|
) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,31 +9,6 @@ import {
|
|||||||
// OSS users who don't need quota tracking can simply not set this env var
|
// OSS users who don't need quota tracking can simply not set this env var
|
||||||
const TABLE = process.env.DYNAMODB_QUOTA_TABLE
|
const TABLE = process.env.DYNAMODB_QUOTA_TABLE
|
||||||
const DYNAMODB_REGION = process.env.DYNAMODB_REGION || "ap-northeast-1"
|
const DYNAMODB_REGION = process.env.DYNAMODB_REGION || "ap-northeast-1"
|
||||||
// Timezone for daily quota reset (e.g., "Asia/Tokyo" for JST midnight reset)
|
|
||||||
// Defaults to UTC if not set
|
|
||||||
let QUOTA_TIMEZONE = process.env.QUOTA_TIMEZONE || "UTC"
|
|
||||||
|
|
||||||
// Validate timezone at module load
|
|
||||||
try {
|
|
||||||
new Intl.DateTimeFormat("en-CA", { timeZone: QUOTA_TIMEZONE }).format(
|
|
||||||
new Date(),
|
|
||||||
)
|
|
||||||
} catch {
|
|
||||||
console.warn(
|
|
||||||
`[quota] Invalid QUOTA_TIMEZONE "${QUOTA_TIMEZONE}", using UTC`,
|
|
||||||
)
|
|
||||||
QUOTA_TIMEZONE = "UTC"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get today's date string in the configured timezone (YYYY-MM-DD format)
|
|
||||||
* This is used as the Sort Key (SK) for per-day tracking
|
|
||||||
*/
|
|
||||||
function getTodayInTimezone(): string {
|
|
||||||
return new Intl.DateTimeFormat("en-CA", {
|
|
||||||
timeZone: QUOTA_TIMEZONE,
|
|
||||||
}).format(new Date())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only create client if quota is enabled
|
// Only create client if quota is enabled
|
||||||
const client = TABLE ? new DynamoDBClient({ region: DYNAMODB_REGION }) : null
|
const client = TABLE ? new DynamoDBClient({ region: DYNAMODB_REGION }) : null
|
||||||
@@ -62,8 +37,8 @@ interface QuotaCheckResult {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check all quotas and increment request count atomically.
|
* Check all quotas and increment request count atomically.
|
||||||
* Uses composite key (PK=user, SK=date) for per-day tracking.
|
* Uses ConditionExpression to prevent race conditions.
|
||||||
* Each day automatically gets a new item - no explicit reset needed.
|
* Returns which limit was exceeded if any.
|
||||||
*/
|
*/
|
||||||
export async function checkAndIncrementRequest(
|
export async function checkAndIncrementRequest(
|
||||||
ip: string,
|
ip: string,
|
||||||
@@ -74,33 +49,42 @@ export async function checkAndIncrementRequest(
|
|||||||
return { allowed: true }
|
return { allowed: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
const pk = ip // User identifier (base64 IP)
|
const today = new Date().toISOString().split("T")[0]
|
||||||
const sk = getTodayInTimezone() // Date as sort key (YYYY-MM-DD)
|
|
||||||
const currentMinute = Math.floor(Date.now() / 60000).toString()
|
const currentMinute = Math.floor(Date.now() / 60000).toString()
|
||||||
|
const ttl = Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Single atomic update - handles creation AND increment
|
// Atomic check-and-increment with ConditionExpression
|
||||||
// New day automatically creates new item (different SK)
|
// This prevents race conditions by failing if limits are exceeded
|
||||||
// Note: lastMinute/tpmCount are managed by recordTokenUsage only
|
|
||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: {
|
Key: { PK: { S: `IP#${ip}` } },
|
||||||
PK: { S: pk },
|
// Reset counts if new day/minute, then increment request count
|
||||||
SK: { S: sk },
|
UpdateExpression: `
|
||||||
},
|
SET lastResetDate = :today,
|
||||||
UpdateExpression: "ADD reqCount :one",
|
dailyReqCount = if_not_exists(dailyReqCount, :zero) + :one,
|
||||||
// Check all limits before allowing increment
|
dailyTokenCount = if_not_exists(dailyTokenCount, :zero),
|
||||||
// TPM check: allow if new minute OR under limit
|
lastMinute = :minute,
|
||||||
|
tpmCount = if_not_exists(tpmCount, :zero),
|
||||||
|
#ttl = :ttl
|
||||||
|
`,
|
||||||
|
// Atomic condition: only succeed if ALL limits pass
|
||||||
|
// Uses attribute_not_exists for new items, then checks limits for existing items
|
||||||
ConditionExpression: `
|
ConditionExpression: `
|
||||||
(attribute_not_exists(reqCount) OR reqCount < :reqLimit) AND
|
(attribute_not_exists(lastResetDate) OR lastResetDate < :today OR
|
||||||
(attribute_not_exists(tokenCount) OR tokenCount < :tokenLimit) AND
|
((attribute_not_exists(dailyReqCount) OR dailyReqCount < :reqLimit) AND
|
||||||
|
(attribute_not_exists(dailyTokenCount) OR dailyTokenCount < :tokenLimit))) AND
|
||||||
(attribute_not_exists(lastMinute) OR lastMinute <> :minute OR
|
(attribute_not_exists(lastMinute) OR lastMinute <> :minute OR
|
||||||
attribute_not_exists(tpmCount) OR tpmCount < :tpmLimit)
|
attribute_not_exists(tpmCount) OR tpmCount < :tpmLimit)
|
||||||
`,
|
`,
|
||||||
|
ExpressionAttributeNames: { "#ttl": "ttl" },
|
||||||
ExpressionAttributeValues: {
|
ExpressionAttributeValues: {
|
||||||
|
":today": { S: today },
|
||||||
|
":zero": { N: "0" },
|
||||||
":one": { N: "1" },
|
":one": { N: "1" },
|
||||||
":minute": { S: currentMinute },
|
":minute": { S: currentMinute },
|
||||||
|
":ttl": { N: String(ttl) },
|
||||||
":reqLimit": { N: String(limits.requests || 999999) },
|
":reqLimit": { N: String(limits.requests || 999999) },
|
||||||
":tokenLimit": { N: String(limits.tokens || 999999) },
|
":tokenLimit": { N: String(limits.tokens || 999999) },
|
||||||
":tpmLimit": { N: String(limits.tpm || 999999) },
|
":tpmLimit": { N: String(limits.tpm || 999999) },
|
||||||
@@ -117,39 +101,42 @@ export async function checkAndIncrementRequest(
|
|||||||
const getResult = await client.send(
|
const getResult = await client.send(
|
||||||
new GetItemCommand({
|
new GetItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: {
|
Key: { PK: { S: `IP#${ip}` } },
|
||||||
PK: { S: pk },
|
|
||||||
SK: { S: sk },
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const item = getResult.Item
|
const item = getResult.Item
|
||||||
|
const storedDate = item?.lastResetDate?.S
|
||||||
const storedMinute = item?.lastMinute?.S
|
const storedMinute = item?.lastMinute?.S
|
||||||
|
const isNewDay = !storedDate || storedDate < today
|
||||||
|
|
||||||
const reqCount = Number(item?.reqCount?.N || 0)
|
const dailyReqCount = isNewDay
|
||||||
const tokenCount = Number(item?.tokenCount?.N || 0)
|
? 0
|
||||||
|
: Number(item?.dailyReqCount?.N || 0)
|
||||||
|
const dailyTokenCount = isNewDay
|
||||||
|
? 0
|
||||||
|
: Number(item?.dailyTokenCount?.N || 0)
|
||||||
const tpmCount =
|
const tpmCount =
|
||||||
storedMinute !== currentMinute
|
storedMinute !== currentMinute
|
||||||
? 0
|
? 0
|
||||||
: Number(item?.tpmCount?.N || 0)
|
: Number(item?.tpmCount?.N || 0)
|
||||||
|
|
||||||
// Determine which limit was exceeded
|
// Determine which limit was exceeded
|
||||||
if (limits.requests > 0 && reqCount >= limits.requests) {
|
if (limits.requests > 0 && dailyReqCount >= limits.requests) {
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
type: "request",
|
type: "request",
|
||||||
error: "Daily request limit exceeded",
|
error: "Daily request limit exceeded",
|
||||||
used: reqCount,
|
used: dailyReqCount,
|
||||||
limit: limits.requests,
|
limit: limits.requests,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (limits.tokens > 0 && tokenCount >= limits.tokens) {
|
if (limits.tokens > 0 && dailyTokenCount >= limits.tokens) {
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
type: "token",
|
type: "token",
|
||||||
error: "Daily token limit exceeded",
|
error: "Daily token limit exceeded",
|
||||||
used: tokenCount,
|
used: dailyTokenCount,
|
||||||
limit: limits.tokens,
|
limit: limits.tokens,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +151,7 @@ export async function checkAndIncrementRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Condition failed but no limit clearly exceeded - race condition edge case
|
// Condition failed but no limit clearly exceeded - race condition edge case
|
||||||
// Fail safe by allowing (could be a TPM reset race)
|
// Fail safe by allowing (could be a reset race)
|
||||||
console.warn(
|
console.warn(
|
||||||
`[quota] Condition failed but no limit exceeded for IP prefix: ${ip.slice(0, 8)}...`,
|
`[quota] Condition failed but no limit exceeded for IP prefix: ${ip.slice(0, 8)}...`,
|
||||||
)
|
)
|
||||||
@@ -187,7 +174,7 @@ export async function checkAndIncrementRequest(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Record token usage after response completes.
|
* Record token usage after response completes.
|
||||||
* Uses composite key (PK=user, SK=date) for per-day tracking.
|
* Uses atomic operations to update both daily token count and TPM count.
|
||||||
* Handles minute boundaries atomically to prevent race conditions.
|
* Handles minute boundaries atomically to prevent race conditions.
|
||||||
*/
|
*/
|
||||||
export async function recordTokenUsage(
|
export async function recordTokenUsage(
|
||||||
@@ -198,27 +185,24 @@ export async function recordTokenUsage(
|
|||||||
if (!client || !TABLE) return
|
if (!client || !TABLE) return
|
||||||
if (!Number.isFinite(tokens) || tokens <= 0) return
|
if (!Number.isFinite(tokens) || tokens <= 0) return
|
||||||
|
|
||||||
const pk = ip // User identifier (base64 IP)
|
|
||||||
const sk = getTodayInTimezone() // Date as sort key (YYYY-MM-DD)
|
|
||||||
const currentMinute = Math.floor(Date.now() / 60000).toString()
|
const currentMinute = Math.floor(Date.now() / 60000).toString()
|
||||||
|
const ttl = Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to update for same minute OR new item (most common cases)
|
// Try to update assuming same minute (most common case)
|
||||||
// Handles: 1) new item (no lastMinute), 2) same minute (lastMinute matches)
|
// Uses condition to ensure we're in the same minute
|
||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: {
|
Key: { PK: { S: `IP#${ip}` } },
|
||||||
PK: { S: pk },
|
|
||||||
SK: { S: sk },
|
|
||||||
},
|
|
||||||
UpdateExpression:
|
UpdateExpression:
|
||||||
"SET lastMinute = if_not_exists(lastMinute, :minute) ADD tokenCount :tokens, tpmCount :tokens",
|
"SET #ttl = :ttl ADD dailyTokenCount :tokens, tpmCount :tokens",
|
||||||
ConditionExpression:
|
ConditionExpression: "lastMinute = :minute",
|
||||||
"attribute_not_exists(lastMinute) OR lastMinute = :minute",
|
ExpressionAttributeNames: { "#ttl": "ttl" },
|
||||||
ExpressionAttributeValues: {
|
ExpressionAttributeValues: {
|
||||||
":minute": { S: currentMinute },
|
":minute": { S: currentMinute },
|
||||||
":tokens": { N: String(tokens) },
|
":tokens": { N: String(tokens) },
|
||||||
|
":ttl": { N: String(ttl) },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -229,15 +213,14 @@ export async function recordTokenUsage(
|
|||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: {
|
Key: { PK: { S: `IP#${ip}` } },
|
||||||
PK: { S: pk },
|
|
||||||
SK: { S: sk },
|
|
||||||
},
|
|
||||||
UpdateExpression:
|
UpdateExpression:
|
||||||
"SET lastMinute = :minute, tpmCount = :tokens ADD tokenCount :tokens",
|
"SET lastMinute = :minute, tpmCount = :tokens, #ttl = :ttl ADD dailyTokenCount :tokens",
|
||||||
|
ExpressionAttributeNames: { "#ttl": "ttl" },
|
||||||
ExpressionAttributeValues: {
|
ExpressionAttributeValues: {
|
||||||
":minute": { S: currentMinute },
|
":minute": { S: currentMinute },
|
||||||
":tokens": { N: String(tokens) },
|
":tokens": { N: String(tokens) },
|
||||||
|
":ttl": { N: String(ttl) },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -98,11 +98,7 @@
|
|||||||
"minimal": "Minimal",
|
"minimal": "Minimal",
|
||||||
"sketch": "Sketch",
|
"sketch": "Sketch",
|
||||||
"closeProtection": "Close Protection",
|
"closeProtection": "Close Protection",
|
||||||
"closeProtectionDescription": "Show confirmation when leaving the page.",
|
"closeProtectionDescription": "Show confirmation when leaving the page."
|
||||||
"diagramActions": "Diagram Actions",
|
|
||||||
"diagramActionsDescription": "Manage diagram history and exports",
|
|
||||||
"history": "History",
|
|
||||||
"download": "Download"
|
|
||||||
},
|
},
|
||||||
"save": {
|
"save": {
|
||||||
"title": "Save Diagram",
|
"title": "Save Diagram",
|
||||||
@@ -247,9 +243,6 @@
|
|||||||
"default": "Default",
|
"default": "Default",
|
||||||
"serverDefault": "Server Default",
|
"serverDefault": "Server Default",
|
||||||
"configureModels": "Configure Models...",
|
"configureModels": "Configure Models...",
|
||||||
"onlyVerifiedShown": "Only verified models are shown",
|
"onlyVerifiedShown": "Only verified models are shown"
|
||||||
"showUnvalidatedModels": "Show unvalidated models",
|
|
||||||
"allModelsShown": "All models are shown (including unvalidated)",
|
|
||||||
"unvalidatedModelWarning": "This model has not been validated"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,11 +98,7 @@
|
|||||||
"minimal": "ミニマル",
|
"minimal": "ミニマル",
|
||||||
"sketch": "スケッチ",
|
"sketch": "スケッチ",
|
||||||
"closeProtection": "ページ離脱確認",
|
"closeProtection": "ページ離脱確認",
|
||||||
"closeProtectionDescription": "ページを離れる際に確認を表示します。",
|
"closeProtectionDescription": "ページを離れる際に確認を表示します。"
|
||||||
"diagramActions": "ダイアグラム操作",
|
|
||||||
"diagramActionsDescription": "ダイアグラムの履歴とエクスポートを管理",
|
|
||||||
"history": "履歴",
|
|
||||||
"download": "ダウンロード"
|
|
||||||
},
|
},
|
||||||
"save": {
|
"save": {
|
||||||
"title": "ダイアグラムを保存",
|
"title": "ダイアグラムを保存",
|
||||||
@@ -247,9 +243,6 @@
|
|||||||
"default": "デフォルト",
|
"default": "デフォルト",
|
||||||
"serverDefault": "サーバーデフォルト",
|
"serverDefault": "サーバーデフォルト",
|
||||||
"configureModels": "モデルを設定...",
|
"configureModels": "モデルを設定...",
|
||||||
"onlyVerifiedShown": "検証済みのモデルのみ表示",
|
"onlyVerifiedShown": "検証済みのモデルのみ表示"
|
||||||
"showUnvalidatedModels": "未検証のモデルを表示",
|
|
||||||
"allModelsShown": "すべてのモデルを表示(未検証を含む)",
|
|
||||||
"unvalidatedModelWarning": "このモデルは検証されていません"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,11 +98,7 @@
|
|||||||
"minimal": "简约",
|
"minimal": "简约",
|
||||||
"sketch": "草图",
|
"sketch": "草图",
|
||||||
"closeProtection": "关闭确认",
|
"closeProtection": "关闭确认",
|
||||||
"closeProtectionDescription": "离开页面时显示确认。",
|
"closeProtectionDescription": "离开页面时显示确认。"
|
||||||
"diagramActions": "图表操作",
|
|
||||||
"diagramActionsDescription": "管理图表历史记录和导出",
|
|
||||||
"history": "历史记录",
|
|
||||||
"download": "下载"
|
|
||||||
},
|
},
|
||||||
"save": {
|
"save": {
|
||||||
"title": "保存图表",
|
"title": "保存图表",
|
||||||
@@ -247,9 +243,6 @@
|
|||||||
"default": "默认",
|
"default": "默认",
|
||||||
"serverDefault": "服务器默认",
|
"serverDefault": "服务器默认",
|
||||||
"configureModels": "配置模型...",
|
"configureModels": "配置模型...",
|
||||||
"onlyVerifiedShown": "仅显示已验证的模型",
|
"onlyVerifiedShown": "仅显示已验证的模型"
|
||||||
"showUnvalidatedModels": "显示未验证的模型",
|
|
||||||
"allModelsShown": "显示所有模型(包括未验证的)",
|
|
||||||
"unvalidatedModelWarning": "此模型尚未验证"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,9 +99,9 @@ When using edit_diagram tool:
|
|||||||
- For update/add: provide cell_id and complete new_xml (full mxCell element including mxGeometry)
|
- For update/add: provide cell_id and complete new_xml (full mxCell element including mxGeometry)
|
||||||
- For delete: only cell_id is needed
|
- For delete: only cell_id is needed
|
||||||
- Find the cell_id from "Current diagram XML" in system context
|
- Find the cell_id from "Current diagram XML" in system context
|
||||||
- Example update: {"operations": [{"operation": "update", "cell_id": "3", "new_xml": "<mxCell id=\\"3\\" value=\\"New Label\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
- Example update: {"operations": [{"type": "update", "cell_id": "3", "new_xml": "<mxCell id=\\"3\\" value=\\"New Label\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
||||||
- Example delete: {"operations": [{"operation": "delete", "cell_id": "5"}]}
|
- Example delete: {"operations": [{"type": "delete", "cell_id": "5"}]}
|
||||||
- Example add: {"operations": [{"operation": "add", "cell_id": "new1", "new_xml": "<mxCell id=\\"new1\\" value=\\"New Box\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"400\\" y=\\"200\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
- Example add: {"operations": [{"type": "add", "cell_id": "new1", "new_xml": "<mxCell id=\\"new1\\" value=\\"New Box\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"400\\" y=\\"200\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
||||||
|
|
||||||
⚠️ JSON ESCAPING: Every " inside new_xml MUST be escaped as \\". Example: id=\\"5\\" value=\\"Label\\"
|
⚠️ JSON ESCAPING: Every " inside new_xml MUST be escaped as \\". Example: id=\\"5\\" value=\\"Label\\"
|
||||||
|
|
||||||
@@ -282,9 +282,9 @@ edit_diagram uses ID-based operations to modify cells directly by their id attri
|
|||||||
\`\`\`json
|
\`\`\`json
|
||||||
{
|
{
|
||||||
"operations": [
|
"operations": [
|
||||||
{"operation": "update", "cell_id": "3", "new_xml": "<mxCell ...complete element...>"},
|
{"type": "update", "cell_id": "3", "new_xml": "<mxCell ...complete element...>"},
|
||||||
{"operation": "add", "cell_id": "new1", "new_xml": "<mxCell ...new element...>"},
|
{"type": "add", "cell_id": "new1", "new_xml": "<mxCell ...new element...>"},
|
||||||
{"operation": "delete", "cell_id": "5"}
|
{"type": "delete", "cell_id": "5"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
@@ -293,17 +293,17 @@ edit_diagram uses ID-based operations to modify cells directly by their id attri
|
|||||||
|
|
||||||
Change label:
|
Change label:
|
||||||
\`\`\`json
|
\`\`\`json
|
||||||
{"operations": [{"operation": "update", "cell_id": "3", "new_xml": "<mxCell id=\\"3\\" value=\\"New Label\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
{"operations": [{"type": "update", "cell_id": "3", "new_xml": "<mxCell id=\\"3\\" value=\\"New Label\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
Add new shape:
|
Add new shape:
|
||||||
\`\`\`json
|
\`\`\`json
|
||||||
{"operations": [{"operation": "add", "cell_id": "new1", "new_xml": "<mxCell id=\\"new1\\" value=\\"New Box\\" style=\\"rounded=1;fillColor=#dae8fc;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"400\\" y=\\"200\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
{"operations": [{"type": "add", "cell_id": "new1", "new_xml": "<mxCell id=\\"new1\\" value=\\"New Box\\" style=\\"rounded=1;fillColor=#dae8fc;\\" vertex=\\"1\\" parent=\\"1\\">\\n <mxGeometry x=\\"400\\" y=\\"200\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/>\\n</mxCell>"}]}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
Delete cell:
|
Delete cell:
|
||||||
\`\`\`json
|
\`\`\`json
|
||||||
{"operations": [{"operation": "delete", "cell_id": "5"}]}
|
{"operations": [{"type": "delete", "cell_id": "5"}]}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
**Error Recovery:**
|
**Error Recovery:**
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ export interface MultiModelConfig {
|
|||||||
version: 1
|
version: 1
|
||||||
providers: ProviderConfig[]
|
providers: ProviderConfig[]
|
||||||
selectedModelId?: string // Currently selected model's UUID
|
selectedModelId?: string // Currently selected model's UUID
|
||||||
showUnvalidatedModels?: boolean // Show models that haven't been validated
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flattened model for dropdown display
|
// Flattened model for dropdown display
|
||||||
@@ -84,24 +83,22 @@ export const PROVIDER_INFO: Record<
|
|||||||
// Suggested models per provider for quick add
|
// Suggested models per provider for quick add
|
||||||
export const SUGGESTED_MODELS: Record<ProviderName, string[]> = {
|
export const SUGGESTED_MODELS: Record<ProviderName, string[]> = {
|
||||||
openai: [
|
openai: [
|
||||||
"gpt-5.2-pro",
|
// GPT-4o series (latest)
|
||||||
"gpt-5.2-chat-latest",
|
|
||||||
"gpt-5.2",
|
|
||||||
"gpt-5.1-codex-mini",
|
|
||||||
"gpt-5.1-codex",
|
|
||||||
"gpt-5.1-chat-latest",
|
|
||||||
"gpt-5.1",
|
|
||||||
"gpt-5-pro",
|
|
||||||
"gpt-5",
|
|
||||||
"gpt-5-mini",
|
|
||||||
"gpt-5-nano",
|
|
||||||
"gpt-5-codex",
|
|
||||||
"gpt-5-chat-latest",
|
|
||||||
"gpt-4.1",
|
|
||||||
"gpt-4.1-mini",
|
|
||||||
"gpt-4.1-nano",
|
|
||||||
"gpt-4o",
|
"gpt-4o",
|
||||||
"gpt-4o-mini",
|
"gpt-4o-mini",
|
||||||
|
"gpt-4o-2024-11-20",
|
||||||
|
// GPT-4 Turbo
|
||||||
|
"gpt-4-turbo",
|
||||||
|
"gpt-4-turbo-preview",
|
||||||
|
// o1/o3 reasoning models
|
||||||
|
"o1",
|
||||||
|
"o1-mini",
|
||||||
|
"o1-preview",
|
||||||
|
"o3-mini",
|
||||||
|
// GPT-4
|
||||||
|
"gpt-4",
|
||||||
|
// GPT-3.5
|
||||||
|
"gpt-3.5-turbo",
|
||||||
],
|
],
|
||||||
anthropic: [
|
anthropic: [
|
||||||
// Claude 4.5 series (latest)
|
// Claude 4.5 series (latest)
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Generate a userId from request for tracking purposes.
|
|
||||||
* Uses base64url encoding of IP for URL-safe identifier.
|
|
||||||
* Note: base64 is reversible - this is NOT privacy protection.
|
|
||||||
*/
|
|
||||||
export function getUserIdFromRequest(req: Request): string {
|
|
||||||
const forwardedFor = req.headers.get("x-forwarded-for")
|
|
||||||
const rawIp = forwardedFor?.split(",")[0]?.trim() || "anonymous"
|
|
||||||
return rawIp === "anonymous"
|
|
||||||
? rawIp
|
|
||||||
: `user-${Buffer.from(rawIp).toString("base64url")}`
|
|
||||||
}
|
|
||||||
@@ -455,7 +455,7 @@ export function replaceNodes(currentXML: string, nodes: string): string {
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
export interface DiagramOperation {
|
export interface DiagramOperation {
|
||||||
operation: "update" | "add" | "delete"
|
type: "update" | "add" | "delete"
|
||||||
cell_id: string
|
cell_id: string
|
||||||
new_xml?: string
|
new_xml?: string
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Process each operation
|
// Process each operation
|
||||||
for (const op of operations) {
|
for (const op of operations) {
|
||||||
if (op.operation === "update") {
|
if (op.type === "update") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
@@ -580,7 +580,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Update the map with the new element
|
// Update the map with the new element
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "add") {
|
} else if (op.type === "add") {
|
||||||
// Check if ID already exists
|
// Check if ID already exists
|
||||||
if (cellMap.has(op.cell_id)) {
|
if (cellMap.has(op.cell_id)) {
|
||||||
errors.push({
|
errors.push({
|
||||||
@@ -632,7 +632,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Add to map
|
// Add to map
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "delete") {
|
} else if (op.type === "delete") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
|
|||||||
@@ -17,13 +17,3 @@ const nextConfig: NextConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default nextConfig
|
export default nextConfig
|
||||||
|
|
||||||
// Initialize OpenNext Cloudflare for local development only
|
|
||||||
// This must be a dynamic import to avoid loading workerd binary during builds
|
|
||||||
if (process.env.NODE_ENV === "development") {
|
|
||||||
import("@opennextjs/cloudflare").then(
|
|
||||||
({ initOpenNextCloudflareForDev }) => {
|
|
||||||
initOpenNextCloudflareForDev()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
// default open-next.config.ts file created by @opennextjs/cloudflare
|
|
||||||
import { defineCloudflareConfig } from "@opennextjs/cloudflare/config"
|
|
||||||
import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache"
|
|
||||||
|
|
||||||
export default defineCloudflareConfig({
|
|
||||||
incrementalCache: r2IncrementalCache,
|
|
||||||
})
|
|
||||||
9853
package-lock.json
generated
9853
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-ai-draw-io",
|
"name": "next-ai-draw-io",
|
||||||
"version": "0.4.7",
|
"version": "0.4.6",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "dist-electron/main/index.js",
|
"main": "dist-electron/main/index.js",
|
||||||
@@ -12,10 +12,6 @@
|
|||||||
"format": "biome check --write .",
|
"format": "biome check --write .",
|
||||||
"check": "biome ci",
|
"check": "biome ci",
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
|
|
||||||
"deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
|
|
||||||
"upload": "opennextjs-cloudflare build && opennextjs-cloudflare upload",
|
|
||||||
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
|
|
||||||
"electron:dev": "node scripts/electron-dev.mjs",
|
"electron:dev": "node scripts/electron-dev.mjs",
|
||||||
"electron:build": "npm run build && npm run electron:compile",
|
"electron:build": "npm run build && npm run electron:compile",
|
||||||
"electron:compile": "npx esbuild electron/main/index.ts electron/preload/index.ts electron/preload/settings.ts --bundle --platform=node --outdir=dist-electron --external:electron --sourcemap --packages=external && npx shx cp -r electron/settings dist-electron/",
|
"electron:compile": "npx esbuild electron/main/index.ts electron/preload/index.ts electron/preload/settings.ts --bundle --platform=node --outdir=dist-electron --external:electron --sourcemap --packages=external && npx shx cp -r electron/settings dist-electron/",
|
||||||
@@ -43,7 +39,6 @@
|
|||||||
"@langfuse/otel": "^4.4.4",
|
"@langfuse/otel": "^4.4.4",
|
||||||
"@langfuse/tracing": "^4.4.9",
|
"@langfuse/tracing": "^4.4.9",
|
||||||
"@next/third-parties": "^16.0.6",
|
"@next/third-parties": "^16.0.6",
|
||||||
"@opennextjs/cloudflare": "1.14.7",
|
|
||||||
"@openrouter/ai-sdk-provider": "^1.5.4",
|
"@openrouter/ai-sdk-provider": "^1.5.4",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.208.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.208.0",
|
||||||
"@opentelemetry/sdk-trace-node": "^2.2.0",
|
"@opentelemetry/sdk-trace-node": "^2.2.0",
|
||||||
@@ -67,7 +62,7 @@
|
|||||||
"js-tiktoken": "^1.0.21",
|
"js-tiktoken": "^1.0.21",
|
||||||
"jsdom": "^26.0.0",
|
"jsdom": "^26.0.0",
|
||||||
"jsonrepair": "^3.13.1",
|
"jsonrepair": "^3.13.1",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.483.0",
|
||||||
"motion": "^12.23.25",
|
"motion": "^12.23.25",
|
||||||
"negotiator": "^1.0.0",
|
"negotiator": "^1.0.0",
|
||||||
"next": "^16.0.7",
|
"next": "^16.0.7",
|
||||||
@@ -109,15 +104,14 @@
|
|||||||
"electron": "^39.2.7",
|
"electron": "^39.2.7",
|
||||||
"electron-builder": "^26.0.12",
|
"electron-builder": "^26.0.12",
|
||||||
"esbuild": "^0.27.2",
|
"esbuild": "^0.27.2",
|
||||||
"eslint": "9.39.2",
|
"eslint": "9.39.1",
|
||||||
"eslint-config-next": "16.1.1",
|
"eslint-config-next": "16.0.5",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"lint-staged": "^16.2.7",
|
"lint-staged": "^16.2.7",
|
||||||
"shx": "^0.4.0",
|
"shx": "^0.4.0",
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"typescript": "^5",
|
"typescript": "^5",
|
||||||
"wait-on": "^9.0.3",
|
"wait-on": "^9.0.3"
|
||||||
"wrangler": "4.54.0"
|
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@openrouter/ai-sdk-provider": {
|
"@openrouter/ai-sdk-provider": {
|
||||||
|
|||||||
12
packages/mcp-server/package-lock.json
generated
12
packages/mcp-server/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@next-ai-drawio/mcp-server",
|
"name": "@next-ai-drawio/mcp-server",
|
||||||
"version": "0.1.6",
|
"version": "0.1.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@next-ai-drawio/mcp-server",
|
"name": "@next-ai-drawio/mcp-server",
|
||||||
"version": "0.1.6",
|
"version": "0.1.5",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.0.4",
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
||||||
@@ -481,9 +481,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@modelcontextprotocol/sdk": {
|
"node_modules/@modelcontextprotocol/sdk": {
|
||||||
"version": "1.25.1",
|
"version": "1.25.0",
|
||||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.25.1.tgz",
|
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.25.0.tgz",
|
||||||
"integrity": "sha512-yO28oVFFC7EBoiKdAn+VqRm+plcfv4v0xp6osG/VsCB0NlPZWi87ajbCZZ8f/RvOFLEu7//rSRmuZZ7lMoe3gQ==",
|
"integrity": "sha512-z0Zhn/LmQ3yz91dEfd5QgS7DpSjA4pk+3z2++zKgn5L6iDFM9QapsVoAQSbKLvlrFsZk9+ru6yHHWNq2lCYJKQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hono/node-server": "^1.19.7",
|
"@hono/node-server": "^1.19.7",
|
||||||
@@ -1034,7 +1034,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
|
||||||
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "^2.0.0",
|
"accepts": "^2.0.0",
|
||||||
"body-parser": "^2.2.1",
|
"body-parser": "^2.2.1",
|
||||||
@@ -2028,7 +2027,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@next-ai-drawio/mcp-server",
|
"name": "@next-ai-drawio/mcp-server",
|
||||||
"version": "0.1.6",
|
"version": "0.1.5",
|
||||||
"description": "MCP server for Next AI Draw.io - AI-powered diagram generation with real-time browser preview",
|
"description": "MCP server for Next AI Draw.io - AI-powered diagram generation with real-time browser preview",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export interface DiagramOperation {
|
export interface DiagramOperation {
|
||||||
operation: "update" | "add" | "delete"
|
type: "update" | "add" | "delete"
|
||||||
cell_id: string
|
cell_id: string
|
||||||
new_xml?: string
|
new_xml?: string
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Process each operation
|
// Process each operation
|
||||||
for (const op of operations) {
|
for (const op of operations) {
|
||||||
if (op.operation === "update") {
|
if (op.type === "update") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
@@ -129,7 +129,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Update the map with the new element
|
// Update the map with the new element
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "add") {
|
} else if (op.type === "add") {
|
||||||
// Check if ID already exists
|
// Check if ID already exists
|
||||||
if (cellMap.has(op.cell_id)) {
|
if (cellMap.has(op.cell_id)) {
|
||||||
errors.push({
|
errors.push({
|
||||||
@@ -181,7 +181,7 @@ export function applyDiagramOperations(
|
|||||||
|
|
||||||
// Add to map
|
// Add to map
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "delete") {
|
} else if (op.type === "delete") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
|
|||||||
@@ -265,22 +265,14 @@ server.registerTool(
|
|||||||
"- add: Add a new cell. Provide cell_id (new unique id) and new_xml.\n" +
|
"- add: Add a new cell. Provide cell_id (new unique id) and new_xml.\n" +
|
||||||
"- update: Replace an existing cell by its id. Provide cell_id and complete new_xml.\n" +
|
"- update: Replace an existing cell by its id. Provide cell_id and complete new_xml.\n" +
|
||||||
"- delete: Remove a cell by its id. Only cell_id is needed.\n\n" +
|
"- delete: Remove a cell by its id. Only cell_id is needed.\n\n" +
|
||||||
"For add/update, new_xml must be a complete mxCell element including mxGeometry.\n\n" +
|
"For add/update, new_xml must be a complete mxCell element including mxGeometry.",
|
||||||
"Example - Add a rectangle:\n" +
|
|
||||||
'{"operations": [{"operation": "add", "cell_id": "rect-1", "new_xml": "<mxCell id=\\"rect-1\\" value=\\"Hello\\" style=\\"rounded=0;\\" vertex=\\"1\\" parent=\\"1\\"><mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/></mxCell>"}]}\n\n' +
|
|
||||||
"Example - Update a cell:\n" +
|
|
||||||
'{"operations": [{"operation": "update", "cell_id": "3", "new_xml": "<mxCell id=\\"3\\" value=\\"New Label\\" style=\\"rounded=1;\\" vertex=\\"1\\" parent=\\"1\\"><mxGeometry x=\\"100\\" y=\\"100\\" width=\\"120\\" height=\\"60\\" as=\\"geometry\\"/></mxCell>"}]}\n\n' +
|
|
||||||
"Example - Delete a cell:\n" +
|
|
||||||
'{"operations": [{"operation": "delete", "cell_id": "rect-1"}]}',
|
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
operations: z
|
operations: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
operation: z
|
type: z
|
||||||
.enum(["update", "add", "delete"])
|
.enum(["update", "add", "delete"])
|
||||||
.describe(
|
.describe("Operation type"),
|
||||||
"Operation to perform: add, update, or delete",
|
|
||||||
),
|
|
||||||
cell_id: z.string().describe("The id of the mxCell"),
|
cell_id: z.string().describe("The id of the mxCell"),
|
||||||
new_xml: z
|
new_xml: z
|
||||||
.string()
|
.string()
|
||||||
@@ -364,13 +356,13 @@ server.registerTool(
|
|||||||
)
|
)
|
||||||
if (fixed) {
|
if (fixed) {
|
||||||
log.info(
|
log.info(
|
||||||
`Operation ${op.operation} ${op.cell_id}: XML auto-fixed: ${fixes.join(", ")}`,
|
`Operation ${op.type} ${op.cell_id}: XML auto-fixed: ${fixes.join(", ")}`,
|
||||||
)
|
)
|
||||||
return { ...op, new_xml: fixed }
|
return { ...op, new_xml: fixed }
|
||||||
}
|
}
|
||||||
if (!valid && error) {
|
if (!valid && error) {
|
||||||
log.warn(
|
log.warn(
|
||||||
`Operation ${op.operation} ${op.cell_id}: XML validation failed: ${error}`,
|
`Operation ${op.type} ${op.cell_id}: XML validation failed: ${error}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
/_next/static/*
|
|
||||||
Cache-Control: public,max-age=31536000,immutable
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?>
|
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
|
||||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
|
||||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="1536.000000pt" height="1536.000000pt" viewBox="0 0 1536.000000 1536.000000"
|
|
||||||
preserveAspectRatio="xMidYMid meet">
|
|
||||||
<g transform="translate(0.000000,1536.000000) scale(0.100000,-0.100000)"
|
|
||||||
fill="#ffffff" stroke="none">
|
|
||||||
<path d="M2765 14404 c-100 -29 -181 -58 -225 -82 -227 -125 -359 -296 -431
|
|
||||||
-560 -19 -70 -19 -108 -19 -1175 0 -1068 1 -1104 20 -1172 58 -206 159 -356
|
|
||||||
319 -474 71 -53 199 -121 226 -121 9 0 26 -5 38 -12 12 -6 62 -19 112 -29 85
|
|
||||||
-17 207 -18 2219 -19 1172 0 2133 -3 2138 -8 4 -4 7 -246 6 -538 l-3 -529
|
|
||||||
-2330 -5 c-2506 -6 -2373 -3 -2470 -54 -61 -31 -150 -113 -194 -178 -87 -128
|
|
||||||
-82 -77 -90 -1025 l-6 -838 -360 -6 c-292 -4 -368 -8 -405 -21 -194 -68 -303
|
|
||||||
-177 -373 -372 l-22 -61 1 -2887 c1 -2716 2 -2890 18 -2935 56 -153 161 -276
|
|
||||||
286 -334 126 -59 0 -54 1400 -54 1394 0 1290 -4 1410 53 95 45 198 148 242
|
|
||||||
241 62 133 58 -93 58 3026 0 2992 1 2883 -40 2990 -59 156 -183 272 -360 337
|
|
||||||
-25 9 -146 14 -440 18 l-405 5 0 540 0 540 2020 3 c1111 1 2030 0 2043 -3 l22
|
|
||||||
-5 -2 -538 -3 -537 -380 -6 c-312 -4 -388 -8 -426 -21 -195 -68 -326 -204
|
|
||||||
-383 -399 -15 -51 -16 -295 -16 -2921 0 -2778 1 -2867 19 -2920 36 -104 72
|
|
||||||
-167 134 -230 75 -78 115 -105 222 -151 l50 -22 1219 -3 c672 -1 1255 1 1300
|
|
||||||
6 109 12 217 63 298 140 73 69 107 118 144 208 l29 69 3 2880 c2 2687 1 2884
|
|
||||||
-15 2945 -48 183 -188 332 -373 398 -37 13 -114 17 -430 21 l-385 6 -3 534
|
|
||||||
c-2 421 0 536 10 543 7 4 925 8 2039 8 1718 0 2028 -2 2038 -14 8 -10 11 -154
|
|
||||||
11 -531 -1 -284 -4 -523 -7 -531 -4 -12 -69 -14 -392 -14 -354 0 -391 -2 -448
|
|
||||||
-20 -168 -52 -282 -148 -353 -295 -22 -45 -40 -91 -40 -103 0 -11 -5 -33 -10
|
|
||||||
-47 -7 -18 -10 -988 -10 -2875 0 -2393 2 -2858 14 -2902 43 -167 148 -298 293
|
|
||||||
-369 57 -27 107 -44 151 -50 88 -11 2429 -11 2508 0 210 31 416 238 445 450 6
|
|
||||||
39 8 1245 7 2926 -3 2713 -4 2862 -21 2900 -41 93 -74 150 -110 191 -46 52
|
|
||||||
-149 134 -169 134 -8 0 -19 5 -24 10 -6 6 -42 19 -80 30 -63 18 -100 20 -415
|
|
||||||
20 -307 0 -348 2 -353 16 -3 9 -6 390 -6 848 0 797 -1 834 -19 886 -31 87 -50
|
|
||||||
118 -111 183 -66 70 -141 119 -221 144 -50 16 -228 18 -2389 23 l-2335 5 0
|
|
||||||
535 0 535 2165 5 c1191 3 2170 8 2176 12 6 4 35 12 65 17 201 35 435 198 539
|
|
||||||
376 55 93 82 153 110 245 19 63 20 94 20 1167 0 1047 -1 1106 -19 1180 -70
|
|
||||||
290 -275 523 -539 613 -160 54 232 50 -5028 49 -4182 0 -4856 -2 -4899 -15z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.4 KiB |
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": ["config:recommended"],
|
|
||||||
"schedule": ["after 10am on saturday"],
|
|
||||||
"timezone": "Asia/Tokyo",
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchUpdateTypes": ["minor", "patch"],
|
|
||||||
"matchPackagePatterns": ["*"],
|
|
||||||
"groupName": "minor and patch dependencies",
|
|
||||||
"automerge": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchUpdateTypes": ["major"],
|
|
||||||
"matchPackagePatterns": ["*"],
|
|
||||||
"automerge": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["@ai-sdk/*"],
|
|
||||||
"groupName": "AI SDK packages"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["@radix-ui/*"],
|
|
||||||
"groupName": "Radix UI packages"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["electron", "electron-builder"],
|
|
||||||
"groupName": "Electron packages",
|
|
||||||
"automerge": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["@ai-sdk/*", "ai", "next"],
|
|
||||||
"groupName": "Core framework packages",
|
|
||||||
"automerge": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"vulnerabilityAlerts": {
|
|
||||||
"enabled": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
result: xmlContent,
|
result: xmlContent,
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: "",
|
cellId: "",
|
||||||
message: `XML parse error: ${parseError.textContent}`,
|
message: `XML parse error: ${parseError.textContent}`,
|
||||||
},
|
},
|
||||||
@@ -36,7 +36,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
result: xmlContent,
|
result: xmlContent,
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: "",
|
cellId: "",
|
||||||
message: "Could not find <root> element in XML",
|
message: "Could not find <root> element in XML",
|
||||||
},
|
},
|
||||||
@@ -51,11 +51,11 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for (const op of operations) {
|
for (const op of operations) {
|
||||||
if (op.operation === "update") {
|
if (op.type === "update") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: `Cell with id="${op.cell_id}" not found`,
|
message: `Cell with id="${op.cell_id}" not found`,
|
||||||
})
|
})
|
||||||
@@ -63,7 +63,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
}
|
}
|
||||||
if (!op.new_xml) {
|
if (!op.new_xml) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: "new_xml is required for update operation",
|
message: "new_xml is required for update operation",
|
||||||
})
|
})
|
||||||
@@ -76,7 +76,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const newCell = newDoc.querySelector("mxCell")
|
const newCell = newDoc.querySelector("mxCell")
|
||||||
if (!newCell) {
|
if (!newCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: "new_xml must contain an mxCell element",
|
message: "new_xml must contain an mxCell element",
|
||||||
})
|
})
|
||||||
@@ -85,7 +85,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const newCellId = newCell.getAttribute("id")
|
const newCellId = newCell.getAttribute("id")
|
||||||
if (newCellId !== op.cell_id) {
|
if (newCellId !== op.cell_id) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "update",
|
type: "update",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: `ID mismatch: cell_id is "${op.cell_id}" but new_xml has id="${newCellId}"`,
|
message: `ID mismatch: cell_id is "${op.cell_id}" but new_xml has id="${newCellId}"`,
|
||||||
})
|
})
|
||||||
@@ -94,10 +94,10 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const importedNode = doc.importNode(newCell, true)
|
const importedNode = doc.importNode(newCell, true)
|
||||||
existingCell.parentNode?.replaceChild(importedNode, existingCell)
|
existingCell.parentNode?.replaceChild(importedNode, existingCell)
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "add") {
|
} else if (op.type === "add") {
|
||||||
if (cellMap.has(op.cell_id)) {
|
if (cellMap.has(op.cell_id)) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "add",
|
type: "add",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: `Cell with id="${op.cell_id}" already exists`,
|
message: `Cell with id="${op.cell_id}" already exists`,
|
||||||
})
|
})
|
||||||
@@ -105,7 +105,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
}
|
}
|
||||||
if (!op.new_xml) {
|
if (!op.new_xml) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "add",
|
type: "add",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: "new_xml is required for add operation",
|
message: "new_xml is required for add operation",
|
||||||
})
|
})
|
||||||
@@ -118,7 +118,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const newCell = newDoc.querySelector("mxCell")
|
const newCell = newDoc.querySelector("mxCell")
|
||||||
if (!newCell) {
|
if (!newCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "add",
|
type: "add",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: "new_xml must contain an mxCell element",
|
message: "new_xml must contain an mxCell element",
|
||||||
})
|
})
|
||||||
@@ -127,7 +127,7 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const newCellId = newCell.getAttribute("id")
|
const newCellId = newCell.getAttribute("id")
|
||||||
if (newCellId !== op.cell_id) {
|
if (newCellId !== op.cell_id) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "add",
|
type: "add",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: `ID mismatch: cell_id is "${op.cell_id}" but new_xml has id="${newCellId}"`,
|
message: `ID mismatch: cell_id is "${op.cell_id}" but new_xml has id="${newCellId}"`,
|
||||||
})
|
})
|
||||||
@@ -136,11 +136,11 @@ function applyDiagramOperations(xmlContent, operations) {
|
|||||||
const importedNode = doc.importNode(newCell, true)
|
const importedNode = doc.importNode(newCell, true)
|
||||||
root.appendChild(importedNode)
|
root.appendChild(importedNode)
|
||||||
cellMap.set(op.cell_id, importedNode)
|
cellMap.set(op.cell_id, importedNode)
|
||||||
} else if (op.operation === "delete") {
|
} else if (op.type === "delete") {
|
||||||
const existingCell = cellMap.get(op.cell_id)
|
const existingCell = cellMap.get(op.cell_id)
|
||||||
if (!existingCell) {
|
if (!existingCell) {
|
||||||
errors.push({
|
errors.push({
|
||||||
operation: "delete",
|
type: "delete",
|
||||||
cellId: op.cell_id,
|
cellId: op.cell_id,
|
||||||
message: `Cell with id="${op.cell_id}" not found`,
|
message: `Cell with id="${op.cell_id}" not found`,
|
||||||
})
|
})
|
||||||
@@ -201,7 +201,7 @@ function assert(condition, message) {
|
|||||||
test("Update operation changes cell value", () => {
|
test("Update operation changes cell value", () => {
|
||||||
const { result, errors } = applyDiagramOperations(sampleXml, [
|
const { result, errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cell_id: "2",
|
cell_id: "2",
|
||||||
new_xml:
|
new_xml:
|
||||||
'<mxCell id="2" value="Updated Box A" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="100" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
'<mxCell id="2" value="Updated Box A" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="100" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
||||||
@@ -224,7 +224,7 @@ test("Update operation changes cell value", () => {
|
|||||||
test("Update operation fails for non-existent cell", () => {
|
test("Update operation fails for non-existent cell", () => {
|
||||||
const { errors } = applyDiagramOperations(sampleXml, [
|
const { errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cell_id: "999",
|
cell_id: "999",
|
||||||
new_xml: '<mxCell id="999" value="Test"/>',
|
new_xml: '<mxCell id="999" value="Test"/>',
|
||||||
},
|
},
|
||||||
@@ -239,7 +239,7 @@ test("Update operation fails for non-existent cell", () => {
|
|||||||
test("Update operation fails on ID mismatch", () => {
|
test("Update operation fails on ID mismatch", () => {
|
||||||
const { errors } = applyDiagramOperations(sampleXml, [
|
const { errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cell_id: "2",
|
cell_id: "2",
|
||||||
new_xml: '<mxCell id="WRONG" value="Test"/>',
|
new_xml: '<mxCell id="WRONG" value="Test"/>',
|
||||||
},
|
},
|
||||||
@@ -254,7 +254,7 @@ test("Update operation fails on ID mismatch", () => {
|
|||||||
test("Add operation creates new cell", () => {
|
test("Add operation creates new cell", () => {
|
||||||
const { result, errors } = applyDiagramOperations(sampleXml, [
|
const { result, errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "add",
|
type: "add",
|
||||||
cell_id: "new1",
|
cell_id: "new1",
|
||||||
new_xml:
|
new_xml:
|
||||||
'<mxCell id="new1" value="New Box" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="500" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
'<mxCell id="new1" value="New Box" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="500" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
||||||
@@ -274,7 +274,7 @@ test("Add operation creates new cell", () => {
|
|||||||
test("Add operation fails for duplicate ID", () => {
|
test("Add operation fails for duplicate ID", () => {
|
||||||
const { errors } = applyDiagramOperations(sampleXml, [
|
const { errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "add",
|
type: "add",
|
||||||
cell_id: "2",
|
cell_id: "2",
|
||||||
new_xml: '<mxCell id="2" value="Duplicate"/>',
|
new_xml: '<mxCell id="2" value="Duplicate"/>',
|
||||||
},
|
},
|
||||||
@@ -289,7 +289,7 @@ test("Add operation fails for duplicate ID", () => {
|
|||||||
test("Add operation fails on ID mismatch", () => {
|
test("Add operation fails on ID mismatch", () => {
|
||||||
const { errors } = applyDiagramOperations(sampleXml, [
|
const { errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "add",
|
type: "add",
|
||||||
cell_id: "new1",
|
cell_id: "new1",
|
||||||
new_xml: '<mxCell id="WRONG" value="Test"/>',
|
new_xml: '<mxCell id="WRONG" value="Test"/>',
|
||||||
},
|
},
|
||||||
@@ -303,7 +303,7 @@ test("Add operation fails on ID mismatch", () => {
|
|||||||
|
|
||||||
test("Delete operation removes cell", () => {
|
test("Delete operation removes cell", () => {
|
||||||
const { result, errors } = applyDiagramOperations(sampleXml, [
|
const { result, errors } = applyDiagramOperations(sampleXml, [
|
||||||
{ operation: "delete", cell_id: "3" },
|
{ type: "delete", cell_id: "3" },
|
||||||
])
|
])
|
||||||
assert(
|
assert(
|
||||||
errors.length === 0,
|
errors.length === 0,
|
||||||
@@ -315,7 +315,7 @@ test("Delete operation removes cell", () => {
|
|||||||
|
|
||||||
test("Delete operation fails for non-existent cell", () => {
|
test("Delete operation fails for non-existent cell", () => {
|
||||||
const { errors } = applyDiagramOperations(sampleXml, [
|
const { errors } = applyDiagramOperations(sampleXml, [
|
||||||
{ operation: "delete", cell_id: "999" },
|
{ type: "delete", cell_id: "999" },
|
||||||
])
|
])
|
||||||
assert(errors.length === 1, "Should have one error")
|
assert(errors.length === 1, "Should have one error")
|
||||||
assert(
|
assert(
|
||||||
@@ -327,18 +327,18 @@ test("Delete operation fails for non-existent cell", () => {
|
|||||||
test("Multiple operations in sequence", () => {
|
test("Multiple operations in sequence", () => {
|
||||||
const { result, errors } = applyDiagramOperations(sampleXml, [
|
const { result, errors } = applyDiagramOperations(sampleXml, [
|
||||||
{
|
{
|
||||||
operation: "update",
|
type: "update",
|
||||||
cell_id: "2",
|
cell_id: "2",
|
||||||
new_xml:
|
new_xml:
|
||||||
'<mxCell id="2" value="Updated" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="100" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
'<mxCell id="2" value="Updated" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="100" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
operation: "add",
|
type: "add",
|
||||||
cell_id: "new1",
|
cell_id: "new1",
|
||||||
new_xml:
|
new_xml:
|
||||||
'<mxCell id="new1" value="Added" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="500" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
'<mxCell id="new1" value="Added" style="rounded=1;" vertex="1" parent="1"><mxGeometry x="500" y="100" width="120" height="60" as="geometry"/></mxCell>',
|
||||||
},
|
},
|
||||||
{ operation: "delete", cell_id: "3" },
|
{ type: "delete", cell_id: "3" },
|
||||||
])
|
])
|
||||||
assert(
|
assert(
|
||||||
errors.length === 0,
|
errors.length === 0,
|
||||||
@@ -354,14 +354,14 @@ test("Multiple operations in sequence", () => {
|
|||||||
|
|
||||||
test("Invalid XML returns parse error", () => {
|
test("Invalid XML returns parse error", () => {
|
||||||
const { errors } = applyDiagramOperations("<not valid xml", [
|
const { errors } = applyDiagramOperations("<not valid xml", [
|
||||||
{ operation: "delete", cell_id: "1" },
|
{ type: "delete", cell_id: "1" },
|
||||||
])
|
])
|
||||||
assert(errors.length === 1, "Should have one error")
|
assert(errors.length === 1, "Should have one error")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Missing root element returns error", () => {
|
test("Missing root element returns error", () => {
|
||||||
const { errors } = applyDiagramOperations("<mxfile></mxfile>", [
|
const { errors } = applyDiagramOperations("<mxfile></mxfile>", [
|
||||||
{ operation: "delete", cell_id: "1" },
|
{ type: "delete", cell_id: "1" },
|
||||||
])
|
])
|
||||||
assert(errors.length === 1, "Should have one error")
|
assert(errors.length === 1, "Should have one error")
|
||||||
assert(
|
assert(
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "node_modules/wrangler/config-schema.json",
|
|
||||||
"main": ".open-next/worker.js",
|
|
||||||
"name": "next-ai-draw-io-worker",
|
|
||||||
"compatibility_date": "2025-12-08", // must be a today or past compatibility_date
|
|
||||||
"compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
|
|
||||||
"assets": {
|
|
||||||
"directory": ".open-next/assets",
|
|
||||||
"binding": "ASSETS"
|
|
||||||
},
|
|
||||||
"r2_buckets": [
|
|
||||||
{
|
|
||||||
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
|
||||||
"bucket_name": "next-inc-cache"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"binding": "WORKER_SELF_REFERENCE",
|
|
||||||
"service": "next-ai-draw-io-worker"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user