mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-09 01:32:29 +08:00
Compare commits
10 Commits
remove-ele
...
18ab1bffa0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18ab1bffa0 | ||
|
|
467561df47 | ||
|
|
e67ab37383 | ||
|
|
31644dbcd8 | ||
|
|
067d309927 | ||
|
|
d1d0de3dea | ||
|
|
8c736cee0d | ||
|
|
c5a04c9e50 | ||
|
|
44c453403f | ||
|
|
9727aa5b39 |
16
.github/workflows/auto-format.yml
vendored
16
.github/workflows/auto-format.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -37,11 +37,21 @@ 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'
|
if: steps.changes.outputs.has_changes == 'true' && github.event.pull_request.head.repo.full_name == github.repository
|
||||||
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
|
git push origin HEAD:${{ github.head_ref }}
|
||||||
|
|||||||
44
.github/workflows/ci.yml
vendored
Normal file
44
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
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@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
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
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
"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"
|
||||||
@@ -10,6 +11,7 @@ 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"
|
||||||
@@ -24,6 +26,8 @@ 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")
|
||||||
@@ -58,6 +62,18 @@ 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)
|
||||||
@@ -84,7 +100,7 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsLoaded(true)
|
setIsLoaded(true)
|
||||||
}, [])
|
}, [pathname, router])
|
||||||
|
|
||||||
const handleDarkModeChange = async () => {
|
const handleDarkModeChange = async () => {
|
||||||
await saveDiagramToStorage()
|
await saveDiagramToStorage()
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +184,7 @@ export function ChatInput({
|
|||||||
models = [],
|
models = [],
|
||||||
selectedModelId,
|
selectedModelId,
|
||||||
onModelSelect = () => {},
|
onModelSelect = () => {},
|
||||||
|
showUnvalidatedModels = false,
|
||||||
onConfigureModels = () => {},
|
onConfigureModels = () => {},
|
||||||
}: ChatInputProps) {
|
}: ChatInputProps) {
|
||||||
const dict = useDictionary()
|
const dict = useDictionary()
|
||||||
@@ -482,6 +484,7 @@ export function ChatInput({
|
|||||||
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" />
|
||||||
|
|||||||
@@ -1071,6 +1071,7 @@ 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>
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ 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"
|
||||||
@@ -412,11 +413,7 @@ export function ModelConfigDialog({
|
|||||||
setSelectedProviderId(
|
setSelectedProviderId(
|
||||||
provider.id,
|
provider.id,
|
||||||
)
|
)
|
||||||
setValidationStatus(
|
setValidationStatus("idle")
|
||||||
provider.validated
|
|
||||||
? "success"
|
|
||||||
: "idle",
|
|
||||||
)
|
|
||||||
setShowApiKey(false)
|
setShowApiKey(false)
|
||||||
}}
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -555,6 +552,20 @@ 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 */}
|
||||||
@@ -1416,24 +1427,6 @@ 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>
|
||||||
</>
|
</>
|
||||||
@@ -1455,10 +1448,23 @@ 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">
|
||||||
<p className="text-xs text-muted-foreground text-center flex items-center justify-center gap-1.5">
|
<div className="flex items-center justify-between">
|
||||||
<Key className="h-3 w-3" />
|
<div className="flex items-center gap-2">
|
||||||
{dict.modelConfig.apiKeyStored}
|
<Switch
|
||||||
</p>
|
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" />
|
||||||
|
{dict.modelConfig.apiKeyStored}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { Bot, Check, ChevronDown, Server, Settings2 } from "lucide-react"
|
import {
|
||||||
|
AlertTriangle,
|
||||||
|
Bot,
|
||||||
|
Check,
|
||||||
|
ChevronDown,
|
||||||
|
Server,
|
||||||
|
Settings2,
|
||||||
|
} from "lucide-react"
|
||||||
import { useMemo, useState } from "react"
|
import { useMemo, useState } from "react"
|
||||||
import {
|
import {
|
||||||
ModelSelectorContent,
|
ModelSelectorContent,
|
||||||
@@ -26,6 +33,7 @@ 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
|
||||||
@@ -67,17 +75,20 @@ 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)
|
||||||
// Only show validated models in the selector
|
// Filter models based on showUnvalidatedModels setting
|
||||||
const validatedModels = useMemo(
|
const displayModels = useMemo(() => {
|
||||||
() => models.filter((m) => m.validated === true),
|
if (showUnvalidatedModels) {
|
||||||
[models],
|
return models
|
||||||
)
|
}
|
||||||
|
return models.filter((m) => m.validated === true)
|
||||||
|
}, [models, showUnvalidatedModels])
|
||||||
const groupedModels = useMemo(
|
const groupedModels = useMemo(
|
||||||
() => groupModelsByProvider(validatedModels),
|
() => groupModelsByProvider(displayModels),
|
||||||
[validatedModels],
|
[displayModels],
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find selected model for display
|
// Find selected model for display
|
||||||
@@ -126,7 +137,7 @@ export function ModelSelector({
|
|||||||
/>
|
/>
|
||||||
<ModelSelectorList className="[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
|
<ModelSelectorList className="[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
|
||||||
<ModelSelectorEmpty>
|
<ModelSelectorEmpty>
|
||||||
{validatedModels.length === 0 && models.length > 0
|
{displayModels.length === 0 && models.length > 0
|
||||||
? dict.modelConfig.noVerifiedModels
|
? dict.modelConfig.noVerifiedModels
|
||||||
: dict.modelConfig.noModelsFound}
|
: dict.modelConfig.noModelsFound}
|
||||||
</ModelSelectorEmpty>
|
</ModelSelectorEmpty>
|
||||||
@@ -191,6 +202,16 @@ 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>
|
||||||
@@ -213,7 +234,9 @@ 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">
|
||||||
{dict.modelConfig.onlyVerifiedShown}
|
{showUnvalidatedModels
|
||||||
|
? dict.modelConfig.allModelsShown
|
||||||
|
: dict.modelConfig.onlyVerifiedShown}
|
||||||
</div>
|
</div>
|
||||||
</ModelSelectorList>
|
</ModelSelectorList>
|
||||||
</ModelSelectorContent>
|
</ModelSelectorContent>
|
||||||
|
|||||||
@@ -151,6 +151,9 @@ 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
|
||||||
|
|||||||
@@ -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` or `https://drawio.your-domain.com` |
|
| Remote/Server | `http://YOUR_SERVER_IP:8080` |
|
||||||
|
|
||||||
**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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.alibaba_cloud.{shape};fillColor=#FF6A00;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="image;aspect=fixed;image=img/lib/atlassian/Jira_Logo.svg;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<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">
|
||||||
<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;" vertex="1" parent="1">
|
<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">
|
||||||
<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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.cisco19.rect;prIcon={shape};fillColor=#00bceb;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.citrix.{shape};fillColor=#00A4E4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.gcp2.{shape};fillColor=#4285F4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.kubernetes.icon;prIcon={shape};fillColor=#326CE5;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.mscae.cloud.azure;fillColor=#0078D4;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.networks.server;fillColor=#29AAE1;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.openstack.{shape};fillColor=#3F51B5;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.salesforce.analytics;fillColor=#7f8de1;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="image;aspect=fixed;image=img/lib/sap/SAP_Logo.svg;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.vvd.{shape};fillColor=#00AEEF;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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;" vertex="1" parent="1">
|
<mxCell value="label" style="shape=mxgraph.webicons.{shape};fillColor=#3b5998;strokeColor=none;verticalLabelPosition=bottom;verticalAlign=top;align=center;" 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 port range (will find first available)
|
// Production mode uses fixed port (61337) to preserve localStorage
|
||||||
production: {
|
// Falls back to sequential ports if unavailable
|
||||||
min: 10000,
|
production: 61337,
|
||||||
max: 65535,
|
// Maximum attempts to find an available port (fallback)
|
||||||
},
|
|
||||||
// Maximum attempts to find an available port
|
|
||||||
maxAttempts: 100,
|
maxAttempts: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,19 +36,11 @@ 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: finds a random available port
|
* - In production: uses fixed port (61337) to preserve localStorage
|
||||||
* - If a port was previously allocated, verifies it's still available
|
* - Falls back to sequential ports if preferred port is unavailable
|
||||||
*
|
*
|
||||||
* @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
|
||||||
@@ -56,6 +48,9 @@ function getRandomPort(): number {
|
|||||||
*/
|
*/
|
||||||
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) {
|
||||||
@@ -69,29 +64,22 @@ export async function findAvailablePort(reuseExisting = true): Promise<number> {
|
|||||||
allocatedPort = null
|
allocatedPort = null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDev) {
|
// Try preferred port first
|
||||||
// Development mode: use fixed port
|
if (await isPortAvailable(preferredPort)) {
|
||||||
const port = PORT_CONFIG.development
|
allocatedPort = preferredPort
|
||||||
const available = await isPortAvailable(port)
|
return preferredPort
|
||||||
if (available) {
|
|
||||||
allocatedPort = port
|
|
||||||
return port
|
|
||||||
}
|
|
||||||
console.warn(
|
|
||||||
`Development port ${port} is in use, finding alternative...`,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Production mode or dev port unavailable: find random available port
|
console.warn(
|
||||||
for (let attempt = 0; attempt < PORT_CONFIG.maxAttempts; attempt++) {
|
`Preferred port ${preferredPort} is in use, finding alternative...`,
|
||||||
const port = isDev
|
)
|
||||||
? PORT_CONFIG.development + attempt + 1
|
|
||||||
: getRandomPort()
|
|
||||||
|
|
||||||
const available = await isPortAvailable(port)
|
// Fallback: try sequential ports starting from preferred + 1
|
||||||
if (available) {
|
for (let attempt = 1; attempt <= PORT_CONFIG.maxAttempts; attempt++) {
|
||||||
|
const port = preferredPort + attempt
|
||||||
|
if (await isPortAvailable(port)) {
|
||||||
allocatedPort = port
|
allocatedPort = port
|
||||||
console.log(`Allocated port: ${port}`)
|
console.log(`Allocated fallback port: ${port}`)
|
||||||
return port
|
return port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,9 +109,11 @@ 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,
|
||||||
@@ -160,6 +162,13 @@ 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)
|
||||||
@@ -278,7 +287,9 @@ 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,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ try {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get today's date string in the configured timezone (YYYY-MM-DD format)
|
* 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 {
|
function getTodayInTimezone(): string {
|
||||||
return new Intl.DateTimeFormat("en-CA", {
|
return new Intl.DateTimeFormat("en-CA", {
|
||||||
@@ -61,8 +62,8 @@ interface QuotaCheckResult {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check all quotas and increment request count atomically.
|
* Check all quotas and increment request count atomically.
|
||||||
* Uses ConditionExpression to prevent race conditions.
|
* Uses composite key (PK=user, SK=date) for per-day tracking.
|
||||||
* Returns which limit was exceeded if any.
|
* Each day automatically gets a new item - no explicit reset needed.
|
||||||
*/
|
*/
|
||||||
export async function checkAndIncrementRequest(
|
export async function checkAndIncrementRequest(
|
||||||
ip: string,
|
ip: string,
|
||||||
@@ -73,77 +74,33 @@ export async function checkAndIncrementRequest(
|
|||||||
return { allowed: true }
|
return { allowed: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
const today = getTodayInTimezone()
|
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 {
|
||||||
// First, try to reset counts if it's a new day (atomic day reset)
|
// Single atomic update - handles creation AND increment
|
||||||
// This will succeed only if lastResetDate < today or doesn't exist
|
// New day automatically creates new item (different SK)
|
||||||
try {
|
// Note: lastMinute/tpmCount are managed by recordTokenUsage only
|
||||||
await client.send(
|
|
||||||
new UpdateItemCommand({
|
|
||||||
TableName: TABLE,
|
|
||||||
Key: { PK: { S: `IP#${ip}` } },
|
|
||||||
// Reset all counts to 1/0 for the new day
|
|
||||||
UpdateExpression: `
|
|
||||||
SET lastResetDate = :today,
|
|
||||||
dailyReqCount = :one,
|
|
||||||
dailyTokenCount = :zero,
|
|
||||||
lastMinute = :minute,
|
|
||||||
tpmCount = :zero,
|
|
||||||
#ttl = :ttl
|
|
||||||
`,
|
|
||||||
// Only succeed if it's a new day (or new item)
|
|
||||||
ConditionExpression: `
|
|
||||||
attribute_not_exists(lastResetDate) OR lastResetDate < :today
|
|
||||||
`,
|
|
||||||
ExpressionAttributeNames: { "#ttl": "ttl" },
|
|
||||||
ExpressionAttributeValues: {
|
|
||||||
":today": { S: today },
|
|
||||||
":zero": { N: "0" },
|
|
||||||
":one": { N: "1" },
|
|
||||||
":minute": { S: currentMinute },
|
|
||||||
":ttl": { N: String(ttl) },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
// New day reset successful
|
|
||||||
return { allowed: true }
|
|
||||||
} catch (resetError: any) {
|
|
||||||
// If condition failed, it's the same day - continue to increment logic
|
|
||||||
if (!(resetError instanceof ConditionalCheckFailedException)) {
|
|
||||||
throw resetError // Re-throw unexpected errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Same day - increment request count with limit checks
|
|
||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: { PK: { S: `IP#${ip}` } },
|
Key: {
|
||||||
// Increment request count, handle minute boundary for TPM
|
PK: { S: pk },
|
||||||
UpdateExpression: `
|
SK: { S: sk },
|
||||||
SET lastMinute = :minute,
|
},
|
||||||
tpmCount = if_not_exists(tpmCount, :zero),
|
UpdateExpression: "ADD reqCount :one",
|
||||||
#ttl = :ttl
|
|
||||||
ADD dailyReqCount :one
|
|
||||||
`,
|
|
||||||
// Check all limits before allowing increment
|
// Check all limits before allowing increment
|
||||||
|
// TPM check: allow if new minute OR under limit
|
||||||
ConditionExpression: `
|
ConditionExpression: `
|
||||||
lastResetDate = :today AND
|
(attribute_not_exists(reqCount) OR reqCount < :reqLimit) AND
|
||||||
(attribute_not_exists(dailyReqCount) OR dailyReqCount < :reqLimit) AND
|
(attribute_not_exists(tokenCount) OR tokenCount < :tokenLimit) 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) },
|
||||||
@@ -160,42 +117,39 @@ export async function checkAndIncrementRequest(
|
|||||||
const getResult = await client.send(
|
const getResult = await client.send(
|
||||||
new GetItemCommand({
|
new GetItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: { PK: { S: `IP#${ip}` } },
|
Key: {
|
||||||
|
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 dailyReqCount = isNewDay
|
const reqCount = Number(item?.reqCount?.N || 0)
|
||||||
? 0
|
const tokenCount = Number(item?.tokenCount?.N || 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 && dailyReqCount >= limits.requests) {
|
if (limits.requests > 0 && reqCount >= limits.requests) {
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
type: "request",
|
type: "request",
|
||||||
error: "Daily request limit exceeded",
|
error: "Daily request limit exceeded",
|
||||||
used: dailyReqCount,
|
used: reqCount,
|
||||||
limit: limits.requests,
|
limit: limits.requests,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (limits.tokens > 0 && dailyTokenCount >= limits.tokens) {
|
if (limits.tokens > 0 && tokenCount >= limits.tokens) {
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
type: "token",
|
type: "token",
|
||||||
error: "Daily token limit exceeded",
|
error: "Daily token limit exceeded",
|
||||||
used: dailyTokenCount,
|
used: tokenCount,
|
||||||
limit: limits.tokens,
|
limit: limits.tokens,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +164,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 reset race)
|
// Fail safe by allowing (could be a TPM 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)}...`,
|
||||||
)
|
)
|
||||||
@@ -233,7 +187,7 @@ export async function checkAndIncrementRequest(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Record token usage after response completes.
|
* Record token usage after response completes.
|
||||||
* Uses atomic operations to update both daily token count and TPM count.
|
* Uses composite key (PK=user, SK=date) for per-day tracking.
|
||||||
* Handles minute boundaries atomically to prevent race conditions.
|
* Handles minute boundaries atomically to prevent race conditions.
|
||||||
*/
|
*/
|
||||||
export async function recordTokenUsage(
|
export async function recordTokenUsage(
|
||||||
@@ -244,24 +198,27 @@ 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 assuming same minute (most common case)
|
// Try to update for same minute OR new item (most common cases)
|
||||||
// Uses condition to ensure we're in the same minute
|
// Handles: 1) new item (no lastMinute), 2) same minute (lastMinute matches)
|
||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: { PK: { S: `IP#${ip}` } },
|
Key: {
|
||||||
|
PK: { S: pk },
|
||||||
|
SK: { S: sk },
|
||||||
|
},
|
||||||
UpdateExpression:
|
UpdateExpression:
|
||||||
"SET #ttl = :ttl ADD dailyTokenCount :tokens, tpmCount :tokens",
|
"SET lastMinute = if_not_exists(lastMinute, :minute) ADD tokenCount :tokens, tpmCount :tokens",
|
||||||
ConditionExpression: "lastMinute = :minute",
|
ConditionExpression:
|
||||||
ExpressionAttributeNames: { "#ttl": "ttl" },
|
"attribute_not_exists(lastMinute) OR lastMinute = :minute",
|
||||||
ExpressionAttributeValues: {
|
ExpressionAttributeValues: {
|
||||||
":minute": { S: currentMinute },
|
":minute": { S: currentMinute },
|
||||||
":tokens": { N: String(tokens) },
|
":tokens": { N: String(tokens) },
|
||||||
":ttl": { N: String(ttl) },
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -272,14 +229,15 @@ export async function recordTokenUsage(
|
|||||||
await client.send(
|
await client.send(
|
||||||
new UpdateItemCommand({
|
new UpdateItemCommand({
|
||||||
TableName: TABLE,
|
TableName: TABLE,
|
||||||
Key: { PK: { S: `IP#${ip}` } },
|
Key: {
|
||||||
|
PK: { S: pk },
|
||||||
|
SK: { S: sk },
|
||||||
|
},
|
||||||
UpdateExpression:
|
UpdateExpression:
|
||||||
"SET lastMinute = :minute, tpmCount = :tokens, #ttl = :ttl ADD dailyTokenCount :tokens",
|
"SET lastMinute = :minute, tpmCount = :tokens ADD tokenCount :tokens",
|
||||||
ExpressionAttributeNames: { "#ttl": "ttl" },
|
|
||||||
ExpressionAttributeValues: {
|
ExpressionAttributeValues: {
|
||||||
":minute": { S: currentMinute },
|
":minute": { S: currentMinute },
|
||||||
":tokens": { N: String(tokens) },
|
":tokens": { N: String(tokens) },
|
||||||
":ttl": { N: String(ttl) },
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -243,6 +243,9 @@
|
|||||||
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,9 @@
|
|||||||
"default": "デフォルト",
|
"default": "デフォルト",
|
||||||
"serverDefault": "サーバーデフォルト",
|
"serverDefault": "サーバーデフォルト",
|
||||||
"configureModels": "モデルを設定...",
|
"configureModels": "モデルを設定...",
|
||||||
"onlyVerifiedShown": "検証済みのモデルのみ表示"
|
"onlyVerifiedShown": "検証済みのモデルのみ表示",
|
||||||
|
"showUnvalidatedModels": "未検証のモデルを表示",
|
||||||
|
"allModelsShown": "すべてのモデルを表示(未検証を含む)",
|
||||||
|
"unvalidatedModelWarning": "このモデルは検証されていません"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,9 @@
|
|||||||
"default": "默认",
|
"default": "默认",
|
||||||
"serverDefault": "服务器默认",
|
"serverDefault": "服务器默认",
|
||||||
"configureModels": "配置模型...",
|
"configureModels": "配置模型...",
|
||||||
"onlyVerifiedShown": "仅显示已验证的模型"
|
"onlyVerifiedShown": "仅显示已验证的模型",
|
||||||
|
"showUnvalidatedModels": "显示未验证的模型",
|
||||||
|
"allModelsShown": "显示所有模型(包括未验证的)",
|
||||||
|
"unvalidatedModelWarning": "此模型尚未验证"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ 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
|
||||||
@@ -83,22 +84,24 @@ 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-4o series (latest)
|
"gpt-5.2-pro",
|
||||||
|
"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)
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "next-ai-draw-io",
|
"name": "next-ai-draw-io",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "next-ai-draw-io",
|
"name": "next-ai-draw-io",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ai-sdk/amazon-bedrock": "^4.0.1",
|
"@ai-sdk/amazon-bedrock": "^4.0.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-ai-draw-io",
|
"name": "next-ai-draw-io",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "dist-electron/main/index.js",
|
"main": "dist-electron/main/index.js",
|
||||||
|
|||||||
40
renovate.json
Normal file
40
renovate.json
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"$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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user