|
|
@@ -0,0 +1,850 @@
|
|
|
+import { PackConfiguration } from "./pack-configuration"
|
|
|
+import { pluginRows } from "./extensions"
|
|
|
+import { For, Show, onMount, onCleanup } from "solid-js"
|
|
|
+import { createStore } from "solid-js/store"
|
|
|
+import { paasRecord, paasText, type PaasPlatform, type PackOptions } from "@/paas"
|
|
|
+import { ResearchIcon } from "./research-icon"
|
|
|
+
|
|
|
+export function PluginManager(props: {
|
|
|
+ api: PaasPlatform
|
|
|
+ agentID: string
|
|
|
+ name: string
|
|
|
+ initialTab?: string
|
|
|
+ projectID?: string
|
|
|
+ projectName?: string
|
|
|
+ canManage: boolean
|
|
|
+ onClose: () => void
|
|
|
+ onChanged: () => Promise<void>
|
|
|
+ onUse: (id: string, prompt?: string) => void
|
|
|
+}) {
|
|
|
+ const [state, setState] = createStore({
|
|
|
+ detail: {} as Record<string, unknown>,
|
|
|
+ busy: false,
|
|
|
+ needsReload: false,
|
|
|
+ retainSelection: false,
|
|
|
+ error: "",
|
|
|
+ notice: "",
|
|
|
+ tab: props.initialTab || "overview",
|
|
|
+ packID: "",
|
|
|
+ version: "1.0.0",
|
|
|
+ includeResources: false,
|
|
|
+ preview: undefined as Record<string, unknown> | undefined,
|
|
|
+ selectedVersion: "",
|
|
|
+ versionOptions: {} as PackOptions,
|
|
|
+ configurationIssue: "",
|
|
|
+ removal: "",
|
|
|
+ uninstall: false,
|
|
|
+ removed: false,
|
|
|
+ restore: "",
|
|
|
+ enabled: true,
|
|
|
+ inherit: true,
|
|
|
+ connections: [] as string[],
|
|
|
+ command: "",
|
|
|
+ values: {} as Record<string, string>,
|
|
|
+ localName: "",
|
|
|
+ executable: "",
|
|
|
+ args: "[]",
|
|
|
+ localID: "",
|
|
|
+ localEnabled: true,
|
|
|
+ envRows: [] as { name: string; value: string }[],
|
|
|
+ inspected: "",
|
|
|
+ localTools: [] as Record<string, unknown>[],
|
|
|
+ chosen: [] as string[],
|
|
|
+ })
|
|
|
+ let alive = true
|
|
|
+ onCleanup(() => {
|
|
|
+ alive = false
|
|
|
+ })
|
|
|
+ const revision = () => {
|
|
|
+ if (state.needsReload) throw new Error("请先重新读取配置,再进行修改。")
|
|
|
+ return paasText(state.detail.updated_at)
|
|
|
+ }
|
|
|
+ async function load() {
|
|
|
+ const detail = paasRecord(await props.api.request({ action: "plugin-detail", agentID: props.agentID })) || {}
|
|
|
+ if (!alive) return
|
|
|
+ const policy = paasRecord(paasRecord(detail.projects)?.[props.projectID || ""])
|
|
|
+ setState({
|
|
|
+ detail,
|
|
|
+ needsReload: false,
|
|
|
+ inherit: !policy,
|
|
|
+ enabled: policy?.enabled !== false,
|
|
|
+ connections: Array.isArray(policy?.connections)
|
|
|
+ ? (policy.connections as string[])
|
|
|
+ : Array.isArray(detail.connections)
|
|
|
+ ? (detail.connections as string[])
|
|
|
+ : [],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ async function perform(action: () => Promise<void>) {
|
|
|
+ if (state.busy) return
|
|
|
+ setState({ busy: true, error: "", notice: "" })
|
|
|
+ await action()
|
|
|
+ .catch((error: unknown) => {
|
|
|
+ if (alive) setState("error", error instanceof Error ? error.message : "操作未完成,请重试。")
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ if (alive) setState("busy", false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ async function changed(message: string) {
|
|
|
+ if (alive) setState("notice", message)
|
|
|
+ await load().catch(() => {
|
|
|
+ if (alive) setState({ needsReload: true, error: "配置已保存,但详情刷新失败。请重新读取配置,无需重复保存。" })
|
|
|
+ })
|
|
|
+ await props.onChanged().catch(() => {
|
|
|
+ if (alive) setState("error", "配置已保存,工作台列表刷新失败。无需重复保存。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const rows = (key: string) => pluginRows(state.detail, key)
|
|
|
+ const ui = () => paasRecord(state.detail.desktop_ui) || {}
|
|
|
+ const command = () => pluginRows(ui(), "commands").find((c) => c.id === state.command)
|
|
|
+ const argv = () => {
|
|
|
+ const args: unknown = JSON.parse(state.args)
|
|
|
+ if (!Array.isArray(args) || args.some((a) => typeof a !== "string") || !state.executable.trim())
|
|
|
+ throw new Error('请填写命令,参数使用字符串数组,例如 ["-y", "工具包名称"]。')
|
|
|
+ return [state.executable.trim(), ...(args as string[])]
|
|
|
+ }
|
|
|
+ const environment = () => {
|
|
|
+ const values: Record<string, string> = {}
|
|
|
+ for (const row of state.envRows) {
|
|
|
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(row.name) || row.name in values) throw new Error("环境变量名称无效或重复。")
|
|
|
+ values[row.name] = row.value
|
|
|
+ }
|
|
|
+ return values
|
|
|
+ }
|
|
|
+ onMount(() => {
|
|
|
+ void perform(load)
|
|
|
+ })
|
|
|
+ return (
|
|
|
+ <section class="paas-extension-detail paas-plugin-manager" aria-label="插件管理">
|
|
|
+ <header class="paas-extension-detail-heading">
|
|
|
+ <ResearchIcon kind="knowledge" />
|
|
|
+ <div>
|
|
|
+ <h2>{props.name}</h2>
|
|
|
+ <p>配置能力、管理版本,并选择在哪些项目中使用。</p>
|
|
|
+ </div>
|
|
|
+ <button onClick={props.onClose} disabled={state.busy}>
|
|
|
+ 关闭
|
|
|
+ </button>
|
|
|
+ </header>
|
|
|
+ <nav class="paas-extension-actions" aria-label="插件管理分类">
|
|
|
+ <For
|
|
|
+ each={[
|
|
|
+ ["overview", "应用入口"],
|
|
|
+ ["project", "当前项目"],
|
|
|
+ ["versions", "版本管理"],
|
|
|
+ ["export", "导出分享"],
|
|
|
+ ["local", "本地工具"],
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ {([id, title]) => (
|
|
|
+ <button aria-pressed={state.tab === id} onClick={() => setState("tab", id)}>
|
|
|
+ {title}
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </nav>
|
|
|
+ <Show when={state.busy}>
|
|
|
+ <p role="status">正在处理…</p>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.error}>
|
|
|
+ <div class="paas-extension-error">
|
|
|
+ <p role="alert">{state.error}</p>
|
|
|
+ <button
|
|
|
+ disabled={state.busy}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(
|
|
|
+ state.removed
|
|
|
+ ? async () => {
|
|
|
+ await props.onChanged()
|
|
|
+ props.onClose()
|
|
|
+ }
|
|
|
+ : load,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ {state.removed ? "刷新应用列表" : "重新读取配置"}
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.notice}>
|
|
|
+ <p role="status">{state.notice}</p>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.detail.inventory_warning}>
|
|
|
+ <p class="paas-muted">{paasText(state.detail.inventory_warning)}</p>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.removed}>
|
|
|
+ <p role="status">应用已移除,历史记录保留。无需重复移除,可刷新列表后返回。</p>
|
|
|
+ </Show>
|
|
|
+ <Show when={!state.removed}>
|
|
|
+ <Show when={state.tab === "overview"}>
|
|
|
+ <Show
|
|
|
+ when={state.detail.latest_version && state.detail.latest_version !== paasRecord(state.detail.pack)?.version}
|
|
|
+ >
|
|
|
+ <p role="status">
|
|
|
+ 已安装可切换版本 {paasText(state.detail.latest_version)}。
|
|
|
+ <button onClick={() => setState("tab", "versions")}>查看版本</button>
|
|
|
+ </p>
|
|
|
+ </Show>
|
|
|
+ <Show when={rows("resources").length}>
|
|
|
+ <details>
|
|
|
+ <summary>已绑定的资源</summary>
|
|
|
+ <ul>
|
|
|
+ <For each={rows("resources")}>
|
|
|
+ {(r) => (
|
|
|
+ <li>
|
|
|
+ {paasText(r.kind)} · {paasText(r.name)}
|
|
|
+ </li>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </ul>
|
|
|
+ </details>
|
|
|
+ </Show>
|
|
|
+
|
|
|
+ <For each={pluginRows(ui(), "panels")}>
|
|
|
+ {(panel) => (
|
|
|
+ <article class="paas-plugin-panel">
|
|
|
+ <h3>{paasText(panel.title)}</h3>
|
|
|
+ <p>{paasText(panel.text)}</p>
|
|
|
+ </article>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <Show
|
|
|
+ when={pluginRows(ui(), "commands").length}
|
|
|
+ fallback={<p class="paas-muted">此应用使用工作台通用会话和成果界面。插件可声明专用任务表单与说明面板。</p>}
|
|
|
+ >
|
|
|
+ <label>
|
|
|
+ 选择任务
|
|
|
+ <select value={state.command} onChange={(e) => setState({ command: e.currentTarget.value, values: {} })}>
|
|
|
+ <option value="">选择应用提供的任务</option>
|
|
|
+ <For each={pluginRows(ui(), "commands")}>
|
|
|
+ {(c) => <option value={paasText(c.id)}>{paasText(c.title)}</option>}
|
|
|
+ </For>
|
|
|
+ </select>
|
|
|
+ </label>
|
|
|
+ <Show when={command()}>
|
|
|
+ {(c) => (
|
|
|
+ <form
|
|
|
+ noValidate
|
|
|
+ onSubmit={(e) => {
|
|
|
+ e.preventDefault()
|
|
|
+ const fields = pluginRows(c(), "fields")
|
|
|
+ if (fields.some((f) => f.required && !state.values[paasText(f.id)]?.trim())) {
|
|
|
+ setState("error", "请填写必填内容。")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const prompt = paasText(c().prompt).replace(
|
|
|
+ /\{\{([a-z][a-z0-9_]*)\}\}/g,
|
|
|
+ (_match, id: string) => state.values[id] || "",
|
|
|
+ )
|
|
|
+ props.onUse(props.agentID, prompt)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <p>{paasText(c().description)}</p>
|
|
|
+ <For each={pluginRows(c(), "fields")}>
|
|
|
+ {(field) => (
|
|
|
+ <label>
|
|
|
+ {paasText(field.label)}
|
|
|
+ {field.required ? " *" : ""}
|
|
|
+ <Show
|
|
|
+ when={field.multiline}
|
|
|
+ fallback={
|
|
|
+ <input
|
|
|
+ value={state.values[paasText(field.id)] || ""}
|
|
|
+ placeholder={paasText(field.placeholder)}
|
|
|
+ onInput={(e) => setState("values", paasText(field.id), e.currentTarget.value)}
|
|
|
+ />
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <textarea
|
|
|
+ value={state.values[paasText(field.id)] || ""}
|
|
|
+ placeholder={paasText(field.placeholder)}
|
|
|
+ onInput={(e) => setState("values", paasText(field.id), e.currentTarget.value)}
|
|
|
+ />
|
|
|
+ </Show>
|
|
|
+ </label>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <button class="paas-primary">填入新会话</button>
|
|
|
+ <small class="paas-muted">先生成任务草稿,确认后再发送。</small>
|
|
|
+ </form>
|
|
|
+ )}
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.tab === "project"}>
|
|
|
+ <h3>{props.projectName || "当前项目"}的使用范围</h3>
|
|
|
+ <p class="paas-muted">仅影响此项目后续任务。正在运行的任务保留提交时的配置。</p>
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.inherit}
|
|
|
+ onChange={(e) => setState("inherit", e.currentTarget.checked)}
|
|
|
+ />
|
|
|
+ 沿用应用默认工具配置
|
|
|
+ </label>
|
|
|
+ <Show when={!state.inherit}>
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.enabled}
|
|
|
+ onChange={(e) => setState("enabled", e.currentTarget.checked)}
|
|
|
+ />
|
|
|
+ 在此项目启用应用
|
|
|
+ </label>
|
|
|
+ <p>允许使用的外部工具连接</p>
|
|
|
+ <For each={Array.isArray(state.detail.connections) ? (state.detail.connections as string[]) : []}>
|
|
|
+ {(id) => (
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.connections.includes(id)}
|
|
|
+ onChange={(e) =>
|
|
|
+ setState(
|
|
|
+ "connections",
|
|
|
+ e.currentTarget.checked
|
|
|
+ ? [...state.connections, id]
|
|
|
+ : state.connections.filter((v) => v !== id),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ {id}
|
|
|
+ </label>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <small class="paas-muted">
|
|
|
+ 限定范围后,不会自动接入范围以外的外部工具。内置文件和命令工具仍遵循项目目录与任务权限。
|
|
|
+ </small>
|
|
|
+ </Show>
|
|
|
+ <button
|
|
|
+ class="paas-primary"
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage || !props.projectID}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-project",
|
|
|
+ agentID: props.agentID,
|
|
|
+ projectID: props.projectID!,
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ enabled: state.enabled,
|
|
|
+ connections: [...state.connections],
|
|
|
+ inherit: state.inherit,
|
|
|
+ })
|
|
|
+ await changed("当前项目的使用范围已保存。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 保存项目范围
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.tab === "versions"}>
|
|
|
+ <details>
|
|
|
+ <summary>移除应用</summary>
|
|
|
+ <p>从工作台移除此应用,历史记录保留。可重新从插件包添加。</p>
|
|
|
+ <Show
|
|
|
+ when={state.uninstall}
|
|
|
+ fallback={
|
|
|
+ <button disabled={!props.canManage} onClick={() => setState("uninstall", true)}>
|
|
|
+ 移除应用…
|
|
|
+ </button>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({ action: "delete-agent", agentID: props.agentID })
|
|
|
+ setState("removed", true)
|
|
|
+ await props.onChanged()
|
|
|
+ props.onClose()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 确认移除应用
|
|
|
+ </button>
|
|
|
+ <button onClick={() => setState("uninstall", false)}>保留应用</button>
|
|
|
+ </Show>
|
|
|
+ </details>
|
|
|
+
|
|
|
+ <p>
|
|
|
+ 当前插件包:{paasText(paasRecord(state.detail.pack)?.version) || "未记录包版本"}。导入新版 ZIP
|
|
|
+ 后,可在这里升级;已有会话和成果保留。
|
|
|
+ </p>
|
|
|
+ <div class="paas-plugin-form-grid">
|
|
|
+ <label>
|
|
|
+ 已安装的插件版本
|
|
|
+ <select
|
|
|
+ value={state.selectedVersion}
|
|
|
+ onChange={(e) => setState("selectedVersion", e.currentTarget.value)}
|
|
|
+ >
|
|
|
+ <option value="">选择目标版本</option>
|
|
|
+ <For each={rows("installed_versions")}>
|
|
|
+ {(v) => <option value={paasText(v.version)}>{paasText(v.version)}</option>}
|
|
|
+ </For>
|
|
|
+ </select>
|
|
|
+ </label>
|
|
|
+ <button
|
|
|
+ disabled={
|
|
|
+ state.busy ||
|
|
|
+ state.needsReload ||
|
|
|
+ !props.canManage ||
|
|
|
+ !state.selectedVersion ||
|
|
|
+ !!state.configurationIssue
|
|
|
+ }
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({
|
|
|
+ ...state.versionOptions,
|
|
|
+ action: "plugin-version",
|
|
|
+ agentID: props.agentID,
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ version: state.selectedVersion,
|
|
|
+ })
|
|
|
+ await changed("版本已更新,后续任务使用新配置。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 确认切换版本
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ <Show when={state.selectedVersion} keyed>
|
|
|
+ {(version) => (
|
|
|
+ <PackConfiguration
|
|
|
+ api={props.api}
|
|
|
+ upgrading
|
|
|
+ currentBindings={(paasRecord(state.detail.bindings) || {}) as Record<string, Record<string, string>>}
|
|
|
+ pack={rows("installed_versions").find((v) => v.version === version) || {}}
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onChange={(options) => setState("versionOptions", options)}
|
|
|
+ onReady={(issue) => setState("configurationIssue", issue)}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </Show>
|
|
|
+ <Show when={state.configurationIssue}>
|
|
|
+ <p class="paas-muted">{state.configurationIssue}</p>
|
|
|
+ </Show>
|
|
|
+ <h3>配置历史</h3>
|
|
|
+ <div class="paas-plugin-version-list">
|
|
|
+ <For each={rows("versions")}>
|
|
|
+ {(v) => (
|
|
|
+ <div>
|
|
|
+ <span>
|
|
|
+ <strong>v{String(v.version)}</strong>{" "}
|
|
|
+ {v.is_current ? "当前使用" : paasText(v.changelog) || "配置保存"}
|
|
|
+ <small>{paasText(v.created_at)}</small>
|
|
|
+ </span>
|
|
|
+ <Show when={!v.is_current}>
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() => setState("restore", String(v.version))}
|
|
|
+ >
|
|
|
+ 恢复此配置
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </div>
|
|
|
+ <Show when={state.restore}>
|
|
|
+ <div class="paas-plugin-panel">
|
|
|
+ <p>恢复到配置 v{state.restore}?当前配置保留在历史中,已开始的任务不受影响。</p>
|
|
|
+ <div class="paas-extension-actions">
|
|
|
+ <button onClick={() => setState("restore", "")}>取消</button>
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-version",
|
|
|
+ agentID: props.agentID,
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ targetVersion: Number(state.restore),
|
|
|
+ })
|
|
|
+ setState("restore", "")
|
|
|
+ await changed("历史配置已恢复。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 确认恢复
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.tab === "export"}>
|
|
|
+ <p>导出可再次导入的 AgentPack。模型凭证、会话记录、项目目录和私有知识库不随包导出。</p>
|
|
|
+ <form
|
|
|
+ noValidate
|
|
|
+ onSubmit={(e) => {
|
|
|
+ e.preventDefault()
|
|
|
+ void perform(async () => {
|
|
|
+ setState(
|
|
|
+ "preview",
|
|
|
+ paasRecord(
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-export",
|
|
|
+ agentID: props.agentID,
|
|
|
+ packID: state.packID,
|
|
|
+ version: state.version,
|
|
|
+ includeResources: state.includeResources,
|
|
|
+ preview: true,
|
|
|
+ }),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div class="paas-plugin-form-grid">
|
|
|
+ <label>
|
|
|
+ 插件标识
|
|
|
+ <input
|
|
|
+ value={state.packID}
|
|
|
+ placeholder="例如 literature-assistant"
|
|
|
+ onInput={(e) => setState({ packID: e.currentTarget.value, preview: undefined })}
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ <label>
|
|
|
+ 版本
|
|
|
+ <input
|
|
|
+ value={state.version}
|
|
|
+ placeholder="1.0.0"
|
|
|
+ onInput={(e) => setState({ version: e.currentTarget.value, preview: undefined })}
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.includeResources}
|
|
|
+ onChange={(e) => setState({ includeResources: e.currentTarget.checked, preview: undefined })}
|
|
|
+ />
|
|
|
+ 包含已声明的 Skill 文件
|
|
|
+ </label>
|
|
|
+ <small class="paas-muted">
|
|
|
+ 分享前检查提示词和 Skill 是否含私有内容。接收者需绑定自己的模型、工具和知识库。
|
|
|
+ </small>
|
|
|
+ <button disabled={state.busy || state.needsReload || !props.canManage}>预览导出清单</button>
|
|
|
+ </form>
|
|
|
+ <Show when={state.preview}>
|
|
|
+ <div class="paas-plugin-panel">
|
|
|
+ <h3>即将导出的文件</h3>
|
|
|
+ <ul>
|
|
|
+ <For each={pluginRows(state.preview, "files")}>
|
|
|
+ {(f) => (
|
|
|
+ <li>
|
|
|
+ {paasText(f.name)} · {String(f.size)} 字节
|
|
|
+ </li>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </ul>
|
|
|
+ <button
|
|
|
+ class="paas-primary"
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ const result = paasRecord(
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-export",
|
|
|
+ agentID: props.agentID,
|
|
|
+ packID: state.packID,
|
|
|
+ version: state.version,
|
|
|
+ includeResources: state.includeResources,
|
|
|
+ preview: false,
|
|
|
+ expectedDigest: paasText(state.preview?.digest),
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ setState("notice", result?.saved ? "插件包已导出。" : "已取消导出。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 选择位置并导出
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ <Show when={state.tab === "local"}>
|
|
|
+ <p>接入标准 MCP stdio 本地工具。由你确认启动命令,工作台负责超时与进程清理。</p>
|
|
|
+ <For each={rows("local_tools")}>
|
|
|
+ {(t) => (
|
|
|
+ <div class="paas-plugin-panel">
|
|
|
+ <strong>{paasText(t.name)}</strong>
|
|
|
+ <small>{t.enabled === false ? "已停用" : "按需启动"}</small>
|
|
|
+ <div class="paas-extension-actions">
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-local-state",
|
|
|
+ agentID: props.agentID,
|
|
|
+ connectionID: paasText(t.id),
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ enabled: t.enabled === false,
|
|
|
+ })
|
|
|
+ await changed(t.enabled === false ? "已启用本地工具。" : "已停用本地工具。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ {t.enabled === false ? "启用" : "停用"}
|
|
|
+ </button>
|
|
|
+ <Show
|
|
|
+ when={state.removal === t.id}
|
|
|
+ fallback={
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() => setState("removal", paasText(t.id))}
|
|
|
+ >
|
|
|
+ 移除…
|
|
|
+ </button>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <button
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ await props.api.request({
|
|
|
+ action: "plugin-local-state",
|
|
|
+ agentID: props.agentID,
|
|
|
+ connectionID: paasText(t.id),
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ remove: true,
|
|
|
+ })
|
|
|
+ setState("removal", "")
|
|
|
+ await changed("本地工具连接已移除,软件包文件保留。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 确认移除连接
|
|
|
+ </button>
|
|
|
+ <button onClick={() => setState("removal", "")}>保留</button>
|
|
|
+ </Show>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <button
|
|
|
+ disabled={state.busy}
|
|
|
+ onClick={() =>
|
|
|
+ setState({
|
|
|
+ envRows: Object.keys(paasRecord(t.env_refs) || {}).map((name) => ({ name, value: "" })),
|
|
|
+ retainSelection: true,
|
|
|
+ chosen: Array.isArray(t.tools)
|
|
|
+ ? t.tools.filter((name): name is string => typeof name === "string")
|
|
|
+ : [],
|
|
|
+ localID: paasText(t.id),
|
|
|
+ localName: paasText(t.name),
|
|
|
+ executable: Array.isArray(t.command_argv) ? String(t.command_argv[0]) : "",
|
|
|
+ args: JSON.stringify(Array.isArray(t.command_argv) ? t.command_argv.slice(1) : []),
|
|
|
+ localEnabled: t.enabled !== false,
|
|
|
+ inspected: "",
|
|
|
+ localTools: [],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 管理此工具
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <Show when={state.localID}>
|
|
|
+ <div class="paas-extension-toolbar">
|
|
|
+ <p class="paas-muted">正在编辑已有连接,保存会更新此工具。</p>
|
|
|
+ <button
|
|
|
+ disabled={state.busy}
|
|
|
+ onClick={() =>
|
|
|
+ setState({
|
|
|
+ localID: "",
|
|
|
+ localName: "",
|
|
|
+ executable: "",
|
|
|
+ args: "[]",
|
|
|
+ envRows: [],
|
|
|
+ chosen: [],
|
|
|
+ localTools: [],
|
|
|
+ inspected: "",
|
|
|
+ localEnabled: true,
|
|
|
+ retainSelection: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 添加另一个本地工具
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </Show>
|
|
|
+ <form
|
|
|
+ noValidate
|
|
|
+ onSubmit={(e) => {
|
|
|
+ e.preventDefault()
|
|
|
+ void perform(async () => {
|
|
|
+ setState("inspected", "")
|
|
|
+ const commandArgv = argv()
|
|
|
+ const result = paasRecord(
|
|
|
+ await props.api.request({
|
|
|
+ action: "local-tool",
|
|
|
+ name: state.localName,
|
|
|
+ commandArgv,
|
|
|
+ environment: environment(),
|
|
|
+ agentID: props.agentID,
|
|
|
+ connectionID: state.localID,
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ const tools = pluginRows(result, "tools")
|
|
|
+ setState({
|
|
|
+ localTools: tools,
|
|
|
+ chosen: tools
|
|
|
+ .map((t) => paasText(t.name))
|
|
|
+ .filter((name) => !state.retainSelection || state.chosen.includes(name)),
|
|
|
+ retainSelection: true,
|
|
|
+ inspected: JSON.stringify(commandArgv),
|
|
|
+ notice: paasText(result?.message),
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <fieldset class="paas-plugin-fields" disabled={state.busy || !props.canManage}>
|
|
|
+ <div class="paas-plugin-form-grid">
|
|
|
+ <label>
|
|
|
+ 工具名称
|
|
|
+ <input
|
|
|
+ value={state.localName}
|
|
|
+ placeholder="例如本地文件检索"
|
|
|
+ onInput={(e) => setState("localName", e.currentTarget.value)}
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ <label>
|
|
|
+ 启动命令
|
|
|
+ <input
|
|
|
+ value={state.executable}
|
|
|
+ placeholder="例如 npx、uvx 或程序完整路径"
|
|
|
+ onInput={(e) => setState({ executable: e.currentTarget.value, inspected: "" })}
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ <label>
|
|
|
+ 参数数组
|
|
|
+ <textarea
|
|
|
+ value={state.args}
|
|
|
+ placeholder={'["-y", "工具包名称"]'}
|
|
|
+ onInput={(e) => setState({ args: e.currentTarget.value, inspected: "" })}
|
|
|
+ />
|
|
|
+ </label>
|
|
|
+ <small class="paas-muted">npx / uvx 可能下载并运行第三方软件,请核对来源。检测不会调用模型。</small>
|
|
|
+ <details>
|
|
|
+ <summary>环境变量与凭证(可选)</summary>
|
|
|
+ <p class="paas-muted">仅把这里指定的变量传给工具。保存后加密存储,重新管理时留空可沿用。</p>
|
|
|
+ <For each={state.envRows}>
|
|
|
+ {(row, index) => (
|
|
|
+ <div class="paas-plugin-env-row">
|
|
|
+ <input
|
|
|
+ aria-label={`变量名 ${index() + 1}`}
|
|
|
+ placeholder="例如 SERVICE_API_KEY"
|
|
|
+ value={row.name}
|
|
|
+ onInput={(e) => {
|
|
|
+ setState("envRows", index(), "name", e.currentTarget.value)
|
|
|
+ setState("inspected", "")
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <input
|
|
|
+ aria-label={`变量值 ${index() + 1}`}
|
|
|
+ type="password"
|
|
|
+ autocomplete="off"
|
|
|
+ placeholder="输入变量值或沿用已保存值"
|
|
|
+ value={row.value}
|
|
|
+ onInput={(e) => {
|
|
|
+ setState("envRows", index(), "value", e.currentTarget.value)
|
|
|
+ setState("inspected", "")
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => {
|
|
|
+ setState("envRows", (rows) => rows.filter((_, i) => i !== index()))
|
|
|
+ setState("inspected", "")
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 移除变量
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => {
|
|
|
+ setState("envRows", (rows) => [...rows, { name: "", value: "" }])
|
|
|
+ setState("inspected", "")
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 添加环境变量
|
|
|
+ </button>
|
|
|
+ </details>
|
|
|
+ <button disabled={state.busy || state.needsReload || !props.canManage || !state.localName}>
|
|
|
+ 启动检测并读取工具
|
|
|
+ </button>
|
|
|
+ </fieldset>
|
|
|
+ </form>
|
|
|
+ <Show when={state.inspected}>
|
|
|
+ <For each={state.localTools}>
|
|
|
+ {(t) => (
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.chosen.includes(paasText(t.name))}
|
|
|
+ onChange={(e) =>
|
|
|
+ setState(
|
|
|
+ "chosen",
|
|
|
+ e.currentTarget.checked
|
|
|
+ ? [...state.chosen, paasText(t.name)]
|
|
|
+ : state.chosen.filter((n) => n !== t.name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ {paasText(t.name)}
|
|
|
+ </label>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ <label class="paas-extension-checkbox">
|
|
|
+ <input
|
|
|
+ type="checkbox"
|
|
|
+ checked={state.localEnabled}
|
|
|
+ onChange={(e) => setState("localEnabled", e.currentTarget.checked)}
|
|
|
+ />
|
|
|
+ 后续任务启用此工具连接
|
|
|
+ </label>
|
|
|
+ <button
|
|
|
+ class="paas-primary"
|
|
|
+ disabled={state.busy || state.needsReload || !props.canManage || !state.chosen.length}
|
|
|
+ onClick={() =>
|
|
|
+ void perform(async () => {
|
|
|
+ if (JSON.stringify(argv()) !== state.inspected) throw new Error("命令已改变,请重新检测。")
|
|
|
+ await props.api.request({
|
|
|
+ action: "local-tool",
|
|
|
+ name: state.localName,
|
|
|
+ commandArgv: argv(),
|
|
|
+ environment: environment(),
|
|
|
+ save: true,
|
|
|
+ agentID: props.agentID,
|
|
|
+ connectionID: state.localID,
|
|
|
+ tools: [...state.chosen],
|
|
|
+ enabled: state.localEnabled,
|
|
|
+ expectedUpdatedAt: revision(),
|
|
|
+ })
|
|
|
+ setState({
|
|
|
+ inspected: "",
|
|
|
+ localID: "",
|
|
|
+ envRows: [],
|
|
|
+ localName: "",
|
|
|
+ executable: "",
|
|
|
+ args: "[]",
|
|
|
+ chosen: [],
|
|
|
+ localTools: [],
|
|
|
+ retainSelection: false,
|
|
|
+ })
|
|
|
+ await changed("本地工具已保存,任务调用时按需启动。")
|
|
|
+ })
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 确认并保存工具
|
|
|
+ </button>
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ </Show>
|
|
|
+ </section>
|
|
|
+ )
|
|
|
+}
|