import { Button, Input, Modal } from "antd"; import { useEffect, useState } from "react"; import { PLUGIN_TEMPLATES } from "@/services/api/model-plugin"; import type { ModelCapability } from "@/stores/use-config-store"; const capabilityLabels: Record = { image: "生图", video: "视频", text: "文本", audio: "音频" }; const variableHints = [ "input:本次请求的归一化输入(prompt / references / messages / params / body)", "config:{ baseUrl, apiKey, model, apiFormat, systemPrompt }", "http:{ url(path), post(path, body, opts), get(path, opts) },已绑定当前渠道", "poll(request, extract, { intervalMs, timeoutMs }):轮询直到 extract 返回真值", "sleep(ms)、signal:延时与取消信号;onDelta(text):推送流式文本(文本模型)", ]; export function ModelScriptEditor({ open, capability, modelName, value, onSave, onClose }: { open: boolean; capability: ModelCapability; modelName: string; value: string; onSave: (script: string) => void; onClose: () => void }) { const [draft, setDraft] = useState(value); useEffect(() => { if (open) setDraft(value); }, [open, value]); return (
调用脚本 · {modelName}
当前能力:{capabilityLabels[capability]}。留空则使用系统默认调用方式。
} width={720} centered onCancel={onClose} styles={{ body: { maxHeight: "64vh", overflowY: "auto" } }} footer={[ , , , , ]} >
可用变量(异步函数体,需 return 结果)
{variableHints.map((hint) => (
· {hint}
))}
setDraft(event.target.value)} autoSize={{ minRows: 12, maxRows: 24 }} spellCheck={false} placeholder="留空使用系统默认调用;点击“插入模板”查看示例。" style={{ fontFamily: "var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)", fontSize: 12 }} />
); }