Merge pull request #5238 from menloresearch/fix/hyper-link-playground

feat(local-api-server): add button to open API documentation and improve layout
This commit is contained in:
David 2025-06-11 11:53:33 +07:00 committed by GitHub
commit cfefcb00cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 11 deletions

View File

@ -2,9 +2,13 @@
"$schema": "../gen/schemas/desktop-schema.json", "$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default", "identifier": "default",
"description": "enables the default permissions", "description": "enables the default permissions",
"windows": ["main"], "windows": [
"main"
],
"remote": { "remote": {
"urls": ["http://*"] "urls": [
"http://*"
]
}, },
"permissions": [ "permissions": [
"core:default", "core:default",
@ -21,6 +25,7 @@
"dialog:default", "dialog:default",
"deep-link:default", "deep-link:default",
"core:webview:allow-create-webview-window", "core:webview:allow-create-webview-window",
"opener:allow-open-url",
{ {
"identifier": "http:default", "identifier": "http:default",
"allow": [ "allow": [
@ -73,6 +78,24 @@
} }
] ]
}, },
{
"identifier": "opener:allow-open-url",
"description": "opens the default permissions for the core module",
"windows": [
"*"
],
"allow": [
{
"url": "https://*"
},
{
"url": "http://127.0.0.1:*"
},
{
"url": "http://0.0.0.0:*"
}
]
},
"store:default" "store:default"
] ]
} }

View File

@ -14,10 +14,11 @@ import { useLocalApiServer } from '@/hooks/useLocalApiServer'
import { WebviewWindow } from '@tauri-apps/api/webviewWindow' import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
import { useAppState } from '@/hooks/useAppState' import { useAppState } from '@/hooks/useAppState'
import { windowKey } from '@/constants/windows' import { windowKey } from '@/constants/windows'
import { IconLogs } from '@tabler/icons-react' import { IconLogs, IconBook } from '@tabler/icons-react'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { ApiKeyInput } from '@/containers/ApiKeyInput' import { ApiKeyInput } from '@/containers/ApiKeyInput'
import { useState } from 'react' import { useState } from 'react'
import { openUrl } from '@tauri-apps/plugin-opener'
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
export const Route = createFileRoute(route.settings.local_api_server as any)({ export const Route = createFileRoute(route.settings.local_api_server as any)({
@ -130,6 +131,16 @@ function LocalAPIServer() {
} }
} }
const handleOpenAPIDocs = async () => {
const docsUrl = `http://${serverHost}:${serverPort}`
try {
console.log('Opening API documentation at:', docsUrl)
await openUrl(docsUrl)
} catch (error) {
console.error('Failed to open API documentation:', error)
}
}
const isServerRunning = serverStatus === 'running' const isServerRunning = serverStatus === 'running'
return ( return (
@ -151,6 +162,18 @@ function LocalAPIServer() {
Start an OpenAI-compatible local HTTP server. Start an OpenAI-compatible local HTTP server.
</p> </p>
</div> </div>
<div className="flex items-center gap-2">
{isServerRunning && (
<Button
onClick={handleOpenAPIDocs}
variant="default"
size="sm"
title="API Documentation"
>
<IconBook size={18} className="text-main-view-fg/50" />
<span>Open Docs</span>
</Button>
)}
<Button <Button
onClick={toggleAPIServer} onClick={toggleAPIServer}
variant={isServerRunning ? 'destructive' : 'default'} variant={isServerRunning ? 'destructive' : 'default'}
@ -159,6 +182,7 @@ function LocalAPIServer() {
{`${isServerRunning ? 'Stop' : 'Start'}`} Server {`${isServerRunning ? 'Stop' : 'Start'}`} Server
</Button> </Button>
</div> </div>
</div>
} }
> >
<CardItem <CardItem