mirror of
https://github.com/ZSeven-W/openpencil.git
synced 2026-06-01 03:14:29 +07:00
- Add agent settings dialog to connect local Claude Code and Codex CLI - Connect button fetches real models from Agent SDK / Codex models cache - Provider logos (Claude, OpenAI) as React icon components in top-bar and dialog - Model selector in AI chat panel grouped by provider with logos and Best badge - MCP CLI integration toggles (Claude Code, Codex, Gemini, OpenCode, Kiro) - Persist agent settings to localStorage with hydrate on mount - Redesign AI chat panel: header, empty state pills, input area, color layering - Add shadcn Switch component, agent-settings types and Zustand store
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { defineEventHandler } from 'h3'
|
|
|
|
interface ModelInfo {
|
|
value: string
|
|
displayName: string
|
|
description: string
|
|
}
|
|
|
|
let cachedModels: ModelInfo[] | null = null
|
|
|
|
/**
|
|
* Returns the list of available AI models via Claude Agent SDK.
|
|
* Used as a fallback when no providers are explicitly connected.
|
|
*/
|
|
export default defineEventHandler(async () => {
|
|
if (cachedModels) {
|
|
return { models: cachedModels }
|
|
}
|
|
|
|
try {
|
|
const { query } = await import('@anthropic-ai/claude-agent-sdk')
|
|
|
|
const env = { ...process.env } as Record<string, string | undefined>
|
|
delete env.CLAUDECODE
|
|
|
|
const q = query({
|
|
prompt: '',
|
|
options: {
|
|
model: 'claude-sonnet-4-6',
|
|
maxTurns: 1,
|
|
tools: [],
|
|
permissionMode: 'plan',
|
|
persistSession: false,
|
|
env,
|
|
},
|
|
})
|
|
|
|
const models = await q.supportedModels()
|
|
cachedModels = models
|
|
q.close()
|
|
|
|
return { models }
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
return { models: [], error: message }
|
|
}
|
|
})
|