@vetta-org/plugin-sdk 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conversation.d.ts +11 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js.map +1 -1
- package/dist/generation-metrics.d.ts +102 -0
- package/dist/generation-metrics.d.ts.map +1 -0
- package/dist/generation-metrics.js +23 -0
- package/dist/generation-metrics.js.map +1 -0
- package/dist/hooks.d.ts +10 -0
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +18 -0
- package/dist/hooks.js.map +1 -1
- package/dist/host-bridge.d.ts +3 -0
- package/dist/host-bridge.d.ts.map +1 -1
- package/dist/host-bridge.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/manifest-schema.d.ts +2 -2
- package/dist/manifest-schema.d.ts.map +1 -1
- package/dist/official.d.ts +0 -7
- package/dist/official.d.ts.map +1 -1
- package/dist/official.js.map +1 -1
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +1 -0
- package/dist/permissions.js.map +1 -1
- package/dist/ui.d.ts +19 -4
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js.map +1 -1
- package/docs/README.md +1 -0
- package/docs/conversation-and-agent.md +63 -0
- package/docs/permissions.md +1 -0
- package/docs/styling-and-pitfalls.md +2 -1
- package/docs/ui-slots.md +4 -1
- package/package.json +1 -1
package/dist/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType, ReactNode } from \"react\";\nimport type { ConversationMessage } from \"./conversation.js\";\nimport type { Disposable } from \"./disposable.js\";\nimport type { PluginImageRef } from \"./images.js\";\nimport type { PluginPromptAttachment } from \"./prompt-attachment.js\";\nimport type { ConversationScenario } from \"./scenario.js\";\nimport type { PluginShortcutScopeContribution } from \"./shortcuts.js\";\n\nexport interface PluginGlobalSlotContribution {\n\tid: string;\n\tcomponent: ComponentType;\n}\n\nexport interface PluginAbilityDetailSlotProps {\n\tabilityId: string;\n\tinstalled: boolean;\n\tenabled: boolean;\n}\n\n/** Inline setup/status surface rendered near the top of one ability detail page. */\nexport interface PluginAbilityDetailSlotContribution {\n\tid: string;\n\tabilityId: string;\n\tcomponent: ComponentType<PluginAbilityDetailSlotProps>;\n}\n\n/**\n * Props handed to a workspace-view component. A workspace view owns the whole\n * content area, so unlike panel slots it is addressed by its own route and can\n * be deep-linked; the host passes back its identity so one component can serve\n * several registered views.\n */\nexport interface PluginWorkspaceViewProps {\n\t/** The contribution id as registered (NOT namespaced). */\n\tviewId: string;\n\t/** The owning plugin id. */\n\tpluginId: string;\n}\n\n/**\n * Badge tone. The host maps it to its own theme colors — a plugin cannot pick a\n * raw color, so badges stay consistent with the built-in navigation entries.\n */\nexport type PluginNavBadgeTone = \"accent\" | \"danger\" | \"default\" | \"warning\";\n\n/**\n * A badge on the plugin's sidebar navigation entry.\n *\n * `beta` is the host's own preset — it renders exactly like the built-in\n * 知识库 Beta 标识, wording included (and localized by the host), so plugins do\n * not have to spell \"Beta\" themselves in every locale.\n *\n * `count` renders `99+` past 99 and disappears at 0 — an unread badge showing\n * \"0\" is worse than no badge.\n */\nexport type PluginNavBadge =\n\t| { kind: \"beta\" }\n\t| { kind: \"text\"; text: string; tone?: PluginNavBadgeTone }\n\t| { kind: \"count\"; count: number; tone?: PluginNavBadgeTone }\n\t| { kind: \"dot\"; tone?: PluginNavBadgeTone };\n\n/**\n * A **workspace view**(工作区视图): a full-page surface a plugin contributes to\n * the host's primary navigation. It is the plugin counterpart of a built-in page\n * such as 自动化 / 知识库 — the host gives it its own route\n * (`/workspace/<pluginId>/<viewId>`) and a sidebar entry, and the plugin owns the\n * entire content area while it is open.\n *\n * Use it for standalone workbenches that are NOT bound to one conversation\n * (dashboards, boards, consoles). Conversation-scoped UI belongs in an\n * {@link PluginActivityTabContribution activity tab}; floating UI belongs in a\n * {@link PluginGlobalSlotContribution global slot}.\n */\nexport interface PluginWorkspaceViewContribution {\n\t/** Unique within the plugin; the host namespaces it as `${pluginId}:${id}`. */\n\tid: string;\n\t/** Sidebar entry label. Supports `%catalogKey%` i18n lookup. */\n\tlabel: string;\n\t/**\n\t * Sidebar entry icon as an **iconify class string** (e.g.\n\t * `\"icon-[solar--widget-5-linear]\"`) — NOT a React node, because the host\n\t * renders it inside its own nav button and persists nav layout by key.\n\t *\n\t * Omit it to inherit the plugin's own `plugin.json` icon: a packaged image\n\t * (svg / png / webp …) is masked with the theme's foreground color, so a plugin\n\t * that ships artwork does not have to find a lookalike in an icon set. Set\n\t * {@link PluginWorkspaceViewContribution.iconTint} to `false` to keep its colors.\n\t */\n\ticon?: string;\n\t/**\n\t * Whether an image icon is tinted with the theme's foreground color. Defaults to\n\t * `true`, which keeps the entry consistent with the built-in navigation and legible\n\t * in every theme.\n\t *\n\t * Pass `false` for a full-color logo. Weigh it first: the entry renders at 16px\n\t * beside monochrome built-ins, and a fixed-color image cannot follow the active\n\t * theme — a dark logo can disappear on a dark sidebar. Has no effect on Iconify\n\t * class icons, which are always tinted.\n\t */\n\ticonTint?: boolean;\n\t/** Optional one-line description; shown as the nav entry tooltip. */\n\tdescription?: string;\n\t/**\n\t * Initial badge on the sidebar entry. `{ kind: \"text\" }` supports the same\n\t * `%catalogKey%` i18n lookup as {@link label}. Update it at runtime with\n\t * {@link PluginUiApi.setWorkspaceViewBadge}.\n\t */\n\tbadge?: PluginNavBadge;\n\t/** Zero-props aside from {@link PluginWorkspaceViewProps}. */\n\tcomponent: ComponentType<PluginWorkspaceViewProps>;\n\t/** Sort hint among this plugin's own views (ascending). Defaults to 0. */\n\tnavOrder?: number;\n\t/**\n\t * Whether this view takes a sidebar entry. Defaults to `true`.\n\t *\n\t * Pass `false` for a surface users open occasionally — a setup page, a\n\t * diagnostics console. It then lives only under Settings → More options,\n\t * where the host lists every off-sidebar view and opens it inside the\n\t * settings shell, so switching between such pages stays one click.\n\t *\n\t * The sidebar is a scarce, user-curated space: a plugin that always claims a\n\t * slot pushes the entries someone actually uses into the overflow menu.\n\t */\n\tsidebar?: boolean;\n}\n\n/**\n * What a workspace view puts into the **host page header** — the window's top\n * bar that also carries the drag region, the macOS traffic-light gutter and the\n * sidebar trigger.\n *\n * Without this the header still renders, showing the app name above the\n * plugin's own toolbar — two stacked bars. Set `hideTitle` and move the view's\n * toolbar in here and the surface gets a single, host-consistent header.\n *\n * `left` / `right` are ReactNodes rendered by the host inside that bar (left:\n * right after the sidebar trigger; right: before the window controls). They are\n * rendered in the plugin's i18n + CSS scope, so `useTranslation()` and the\n * plugin's own classes work as usual. Pass fresh nodes whenever the view's\n * state changes — this is a live setter, not a one-time registration.\n */\nexport interface PluginWorkspaceViewHeader {\n\t/** Replaces the host title text. Supports `%catalogKey%` i18n lookup. */\n\ttitle?: string;\n\t/** Drop the host title entirely (use when {@link left} carries its own). */\n\thideTitle?: boolean;\n\t/** Rendered in the header's left cluster, after the sidebar trigger. */\n\tleft?: ReactNode;\n\t/** Rendered in the header's action cluster, before the window controls. */\n\tright?: ReactNode;\n\t/**\n\t * Float the host header OVER the view instead of stacking above it. The view\n\t * then owns the full content height, and its top `~44px` sit under the\n\t * transparent header strip (window drag region / traffic lights / sidebar\n\t * trigger all keep working on top). Use for immersive full-page surfaces\n\t * whose own hero starts at the very top; leave unset for toolbar-style\n\t * headers that need their own opaque row.\n\t */\n\timmersive?: boolean;\n}\n\nexport interface PluginAudioMetadata {\n\t/** Embedded title; preview renderers should fall back to file.name. */\n\ttitle?: string;\n\tartist?: string;\n\t/** Embedded cover art as a Data URL when available. */\n\tcoverDataUrl?: string;\n}\n\nexport interface PluginPreviewUrlOptions {\n\t/** Optional media hint for ambiguous containers such as webm. */\n\tmediaKind?: \"audio\" | \"video\";\n}\n\n/**\n * The file handed to a file-preview plugin component. The host does NOT\n * pre-read or guess encoding — the plugin decides whether to read text or\n * bytes. `path` is also exposed for plugins that prefer native fetch.\n */\nexport interface PluginPreviewFile {\n\tpath: string | null;\n\tname: string;\n\textension: string;\n\tmime: string;\n\tsize: number;\n\t/** Read the file as a UTF-8 string. */\n\treadText(): Promise<string>;\n\t/** Read the raw file bytes. */\n\treadBytes(): Promise<ArrayBuffer>;\n\t/** A fetchable streaming URL for the file (Range-capable). */\n\tgetUrl(options?: PluginPreviewUrlOptions): string;\n\t/**\n\t * Subscribe to on-disk changes of this file. The listener fires (debounced\n\t * by the host) whenever the file's contents change, letting previews update\n\t * live. Returns a Disposable; call dispose() to stop watching. A no-op for\n\t * files without a real path (url-only sources).\n\t */\n\twatch(listener: () => void): Disposable;\n\t/**\n\t * Host-provided audio metadata for local media files. Returns null when the\n\t * host cannot provide metadata, e.g. url-only sources or unsupported files.\n\t */\n\tgetAudioMetadata?(): Promise<PluginAudioMetadata | null>;\n}\n\nexport interface PluginFilePreviewProps {\n\tfile: PluginPreviewFile;\n}\n\n/**\n * A file handed to {@link PluginUiApi.previewFile} — the *opening* side of the\n * global previewer, the mirror image of {@link PluginPreviewFile} (which is the\n * *rendering* side). Bytes never cross over: the host reads the source itself.\n *\n * Exactly one of `path` (local absolute path) or `url` (host media / http URL)\n * must be given. `path` is the shape the host's own file tree uses, so the\n * previewer also offers \"在 Finder 中显示\" for it.\n */\nexport interface PluginPreviewFileRef {\n\t/** Local absolute path. Requires the `fs.read` permission. */\n\tpath?: string;\n\t/** Fetchable URL (host media URL or http/https). Requires `ui.slot.message`. */\n\turl?: string;\n\t/**\n\t * Display name **including the extension** — the previewer dispatches to a\n\t * renderer by this extension, not by `mimeType`. Optional for `path`\n\t * sources (the host falls back to the path's basename).\n\t */\n\tname?: string;\n\tmimeType?: string;\n\t/** Byte size, shown in the previewer's download detail when known. */\n\tsize?: number;\n}\n\nexport interface PluginFilePreviewContribution {\n\t/** Lower-case extensions without the dot, e.g. [\"svg\"]. */\n\textensions: string[];\n\tcomponent: ComponentType<PluginFilePreviewProps>;\n}\n\n/** Host residency policy for an activity-panel tab. */\nexport type PluginActivityTabRetention = \"active-only\" | \"warm\" | \"pinned\";\n\n/**\n * 活动面板标签卡此刻所在的工作空间。`cwd` 与面板自己的作用域一致(项目详情页是项目根,\n * 会话页是会话 cwd),插件据此判断这个工作空间该不该出现自己的标签卡。\n */\nexport interface PluginActivityTabScope {\n\treadonly cwd: string | null;\n}\n\n/**\n * 一帧的标签卡状态,由 {@link PluginActivityTabContribution.useMeta} 按当前工作空间返回。\n * 只影响「在不在栏上」这类摆放语义;名字与图标仍以注册时声明为默认值。\n */\nexport interface PluginActivityTabMeta {\n\t/** 覆盖注册时的 label(已本地化);省略时用注册值。 */\n\treadonly label?: string;\n\t/** 覆盖注册时的 icon;省略时用注册值(含 `plugin.json#icon` 回落)。 */\n\treadonly icon?: ReactNode;\n\t/** 标签卡角标;0 / 省略表示不显示。 */\n\treadonly badge?: number;\n\t/**\n\t * 固定上栏:只要本帧返回的 meta 非空且 `pinned` 为 true,标签卡就一直在标签栏里,\n\t * 用户无法用减号移除,也不受「+」可添加池与历史隐藏记录左右。适合「工作空间里有\n\t * 这个东西就必须看得到」的面板(如项目根存在 `.git` 的 Git 面板)。\n\t *\n\t * 省略 = 按用户的上栏记录 / `initiallyVisible` 决定,用户仍可移除。\n\t */\n\treadonly pinned?: boolean;\n}\n\n/** {@link PluginActivityTabContribution.useMeta} 的返回:null = 本帧不进入候选。 */\nexport type PluginActivityTabMetaResult = PluginActivityTabMeta | null;\n\nexport interface PluginActivityTabContribution {\n\t/**\n\t * 标签栏上的默认相对位置,越小越靠前;缺省 100(排在全部内置标签卡之后)。\n\t *\n\t * 内置的取值可作标尺:文件 0、批量 10、浏览器 15、计划 18、待办 20、后台任务 30。\n\t * 下限被宿主钳到 10,「文件」永远是第一枚;用户拖拽出来的顺序优先于这个值。\n\t */\n\torder?: number;\n\tid: string;\n\tlabel: string;\n\t/**\n\t * Tab icon as a React node (not an iconify class string).\n\t * Omit to inherit the host-resolved brand icon from `plugin.json#icon`\n\t * (`ctx.plugin.iconUrl`). Prefer omitting for package brand icons so the\n\t * plugin never loads assets via absolute `/…` paths or host protocols.\n\t */\n\ticon?: ReactNode;\n\tcomponent: ComponentType;\n\t/**\n\t * 允许该标签卡出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如\n\t * `[\"project\", \"conversation\"]`)。会话页插槽据此随对话类型显隐。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/**\n\t * 注册后是否默认在标签栏里(缺省 `true`)。声明 `false` 表示「出现条件由我\n\t * 自己决定」——注册只是入池,之后由 {@link PluginUiApi.setActivityTabVisible}\n\t * 或 {@link PluginUiApi.openActivityTab} 决定何时上栏(如 git 只在仓库目录、\n\t * 工作台跟随输入栏 toggle)。无论哪种,用户仍可用减号手动隐藏。\n\t */\n\tinitiallyVisible?: boolean;\n\t/**\n\t * Component residency while the tab is inactive. Defaults to `\"warm\"`:\n\t * visited tabs stay mounted in the host's bounded LRU cache. Use\n\t * `\"active-only\"` for cheap, stateless content and `\"pinned\"` for runtimes\n\t * that must never be evicted while available.\n\t */\n\tretention?: PluginActivityTabRetention;\n\t/**\n\t * @deprecated Use {@link PluginActivityTabContribution.retention}. `true`\n\t * maps to `\"pinned\"`; `false` maps to `\"active-only\"`.\n\t */\n\tkeepAliveWhenAvailable?: boolean;\n\t/**\n\t * 按当前工作面决定这一帧的 meta:返回 `null` 表示本帧不进入候选(既不上栏,也不在\n\t * 「+」里),返回 `{ pinned: true }` 表示固定上栏且不可移除。\n\t *\n\t * 这是一个 **React hook**:宿主每次解析标签栏时按「已注册定义」各调用一次,所以可以在\n\t * 里面用任意 hook(自己的缓存 store、`useTranslation`……)。约束:\n\t * - 渲染期必须是纯计算,探测一类的异步工作放进 `useEffect`,结果写回自己的 store;\n\t * - 抛错只会让这一项消失(与 `null` 同效),不影响其它标签卡;\n\t * - 省略时行为与本字段出现前一致:静态 label / icon / badge,按用户上栏记录显隐。\n\t */\n\tuseMeta?: (scope: PluginActivityTabScope) => PluginActivityTabMetaResult;\n}\n\n/**\n * 会话底部面板的组件贡献。\n *\n * 与 {@link PluginActivityTabContribution} 的分工:活动面板在右侧、一个贡献只有一个\n * 实例、适合「看某个东西的当前状态」;底部面板横跨会话页下沿、可分屏、**同一个贡献\n * 可以开多个实例**,适合终端、日志跟随这类长驻的工作面。\n *\n * meta 走命令式的 {@link PluginBottomPanelContextValue.setMeta} 而不是「每帧返回 meta\n * 的 hook」:多实例场景下 hook 拿不到实例身份,两套 meta 事实源会在改名后打架。\n */\nexport interface PluginBottomPanelContribution {\n\t/** Unique within the plugin; the host namespaces it as `plugin:<pluginId>:<id>`. */\n\tid: string;\n\t/** 「+」菜单里的名字,也是新实例的初始名。Supports `%catalogKey%` i18n lookup. */\n\tlabel: string;\n\t/**\n\t * Tab icon as a React node or an iconify class string.\n\t * Omit to inherit the host-resolved brand icon from `plugin.json#icon`.\n\t */\n\ticon?: ReactNode;\n\t/** Zero-props;实例上下文经 {@link useBottomPanel} 取。 */\n\tcomponent: ComponentType;\n\t/**\n\t * 允许出现的对话场景 slug 列表。**fail-closed**:未声明/空数组 = 任何会话都不出现。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/** 「+」菜单里的相对位置,越小越靠前;缺省 100(排在内置之后)。 */\n\torder?: number;\n\t/**\n\t * 同一会话里最多能开几个实例;缺省不限。单例面板给 1,终端一类不设。\n\t */\n\tmaxInstances?: number;\n}\n\n/** Explicit conversation scope for an activity-tab command. */\nexport interface PluginActivityTabTargetOptions {\n\t/**\n\t * Absolute cwd whose activity-tab state should be changed. Omit to target\n\t * the conversation currently displayed by the host. Tool handlers and\n\t * background work should pass the triggering session's cwd so a foreground\n\t * navigation change cannot redirect the command to another conversation.\n\t */\n\tcwd?: string;\n}\n\n/** Options for {@link PluginUiApi.openActivityTab}. */\nexport interface PluginOpenActivityTabOptions extends PluginActivityTabTargetOptions {\n\t/**\n\t * Desired panel width as it opens: a pixel number, or `\"max\"` to track the\n\t * widest the window allows — `\"max\"` keeps following window resizes until the\n\t * user drags the divider. The host clamps to its min/max bounds. Omit to keep\n\t * the user's current width.\n\t */\n\twidth?: number | \"max\";\n}\n\nexport interface PluginCaptureRegion {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Decoration a plugin contributes to the next outgoing prompt while its input\n * action is active. `metadata` is shallow-merged into the prompt request and\n * `instructions` are appended as hidden, model-visible guidance.\n */\nexport interface PluginPromptDecoration {\n\tmetadata?: Record<string, unknown>;\n\t/** Hidden plugin-owned instructions appended to the next agent turn. */\n\tinstructions?: string[];\n}\n\n/**\n * An action button shown in a row beneath the AI input bar. Rendered as a\n * toggle: clicking activates, clicking again deactivates. While active, the\n * host calls `decoratePrompt()` before each send and merges the returned\n * metadata into the outgoing prompt request. The plugin owns any side state\n * (it is the same Module Federation instance as its other slots).\n */\nexport interface PluginInputActionContribution {\n\tid: string;\n\tlabel: string;\n\t/** Button icon as a React node. Omit to inherit the plugin's `plugin.json#icon`. */\n\ticon?: ReactNode;\n\t/** Whether the action begins in the active state. Defaults to false. */\n\tdefaultActive?: boolean;\n\t/**\n\t * 该输入动作所依赖的 agent 工具名。设置后,仅当该工具在当前会话处于激活(按工具的\n\t * scope_use 解析)时才显示这个 badge——避免在工具被场景屏蔽(如批量任务)时仍显示一个\n\t * 点了也无效的开关。不设则始终显示。例如「图像生成」设为 \"generate_image\"。\n\t */\n\trequiresActiveTool?: string;\n\t/**\n\t * 允许该 toggle 出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现。与 `requiresActiveTool`\n\t * 取「与」:两者都满足才显示。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/**\n\t * When true, this plugin's agent contributions (tools / skills / MCP /\n\t * systemPrompt) and Activity Tabs are hard-isolated: inactive until this\n\t * toggle is on (ADR-0041, knowledgeMode-style). Default false.\n\t */\n\thardIsolation?: boolean;\n\t/**\n\t * Fired when the user toggles the action; `active` is the new state. Return\n\t * `false` when `active` is true to VETO the activation (e.g. the plugin needs\n\t * configuration first) — the toggle stays off. Deactivation can't be vetoed.\n\t */\n\tonToggle?(active: boolean): boolean | void;\n\t/**\n\t * Called by the host before sending while the action is active. The\n\t * returned metadata is merged into the outgoing prompt request.\n\t */\n\tdecoratePrompt?(): PluginPromptDecoration | void;\n}\n\n/**\n * A declarative, serializable descriptor for one card rendered beneath a\n * message. `type` selects a registered card renderer; `key` drives cross-turn\n * dedup (same key across turns = one logical card, shown only under its latest\n * anchor); `payload` carries STABLE REFERENCES (e.g. image ids), not a content\n * snapshot — the renderer resolves live state from it. `title`/`icon` label the\n * card's tab (override the renderer's registration defaults). Rides a tool\n * result's out-of-band `details.cards`; crosses the agent→host boundary, so\n * `icon` is an icon-symbol string, not a node.\n */\nexport interface CardDescriptor {\n\ttype: string;\n\tkey?: string;\n\tpayload?: unknown;\n\ttitle?: string;\n\ticon?: string;\n}\n\n/** A pending (in-flight) tool call handed to a renderer's `pendingFor`. */\nexport interface PluginPendingToolCall {\n\ttoolName: string;\n\targs: Record<string, unknown>;\n}\n\n/**\n * Props for a card renderer. `descriptor` is the card's data; `pending` is true\n * while it was synthesized from an in-flight tool (render a skeleton); `message`\n * is the anchoring conversation message.\n */\nexport interface PluginCardProps {\n\tdescriptor: CardDescriptor;\n\tpending: boolean;\n\tmessage: ConversationMessage;\n}\n\n/**\n * A card renderer registered by a plugin, keyed by `type`. A descriptor whose\n * `type` matches is rendered by `component`. `title`/`icon` are the default tab\n * label/icon (a descriptor may override either). `pendingFor`, given an\n * in-flight tool call, returns a provisional descriptor so a skeleton card\n * appears (and claims a tab) before the tool's result lands — or null when this\n * renderer doesn't handle that tool. The `type` must be globally unique across\n * plugins (convention: prefix with the plugin id, e.g. \"image-gen:preview\").\n */\nexport interface PluginCardRendererContribution {\n\ttype: string;\n\tcomponent: ComponentType<PluginCardProps>;\n\ttitle?: string;\n\t/** Default tab icon as a React node. Omit to inherit the plugin's `plugin.json#icon`. */\n\ticon?: ReactNode;\n\tpendingFor?: (toolCall: PluginPendingToolCall) => CardDescriptor | null;\n}\n\n/** A tool call handed to a tool-call slot renderer. */\nexport interface PluginToolCallSlotToolCall {\n\ttoolCallId: string;\n\ttoolName: string;\n\targs: Record<string, unknown>;\n\tstatus: \"pending\" | \"success\" | \"error\" | \"cancelled\";\n\tresult?: string;\n\tisError?: boolean;\n}\n\nexport interface PluginToolCallSlotProps {\n\ttoolCall: PluginToolCallSlotToolCall;\n}\n\n/**\n * A component that **replaces the host's default inline transcript rendering**\n * for a specific tool (matched by `toolName`; first registered renderer wins).\n * This is how a plugin renders rich UI for its OWN agent tool's output — plugin\n * tools cannot emit `details.cards`, so the message card system (registerCardRenderer)\n * does not serve them; the tool-call slot does.\n */\nexport interface PluginToolCallSlotContribution {\n\tid: string;\n\ttoolName: string;\n\tcomponent: ComponentType<PluginToolCallSlotProps>;\n}\n\n/**\n * A card rendered at the bottom of the message list for the LATEST turn — NOT\n * bound to a tool call. The host mounts `component` in the footer slot and\n * re-mounts it each session/turn; the plugin owns visibility entirely (it reads\n * live state via SDK hooks — `useActiveConversation`, `useConversationMessages`,\n * `ctx.conversation.on(\"turn-end\")` — and returns `null` to render nothing,\n * e.g. git renders only inside a repo that has changes). `scope_use` gates which\n * conversation scenarios it may appear in (**fail-closed**, mirrors the other\n * slots). `id` must be unique within the plugin.\n */\nexport interface PluginTurnCardContribution {\n\tid: string;\n\tcomponent: ComponentType;\n\t/**\n\t * 允许该 turn 卡出现的对话场景 slug 列表(镜像其它插槽的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如 `[\"project\"]`)。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n}\n\n/**\n * Options for {@link PluginUiApi.notify}. Surfaces a host toast so users can\n * see plugin failures without opening DevTools.\n */\nexport interface PluginNotifyOptions {\n\t/** Toast body. Required even when `error` is set (user-facing summary). */\n\tmessage: string;\n\t/** Defaults to plugin display name when omitted. */\n\ttitle?: string;\n\t/** Defaults to `\"info\"`; when `error` is set and variant omitted, host uses `\"error\"`. */\n\tvariant?: \"info\" | \"success\" | \"warning\" | \"error\";\n\t/**\n\t * Optional failure cause. Host formats message + stack and adds a\n\t * \"复制堆栈\" action so the user can paste it into bug reports / chat.\n\t */\n\terror?: unknown;\n\t/**\n\t * Auto-dismiss delay in ms. `0` keeps the toast until dismissed.\n\t * Defaults: sticky (`0`) when `error` is present, otherwise host default (~4s).\n\t */\n\tdurationMs?: number;\n}\n\n/**\n * 新会话上下文区的激活条件。**只能写本插件自己的东西**——填别人的 id 一律不生效。\n *\n * 这条限制是故意的:否则插件 A 可以声明「只要用户选了 B 的智能体我就上屏」,把别人的\n * 使用场景劫持过来。\n *\n * 各字段取并集:任意一条命中即激活。至少要声明一条——全空等于「任何新会话都上屏」,宿主拒掉。\n */\nexport interface PluginNewSessionContextActivation {\n\t/** 本插件在 manifest 里声明的智能体 id(不带 `plugin:` 前缀)。 */\n\tagents?: readonly string[];\n\t/** 本插件在 manifest 里声明的团队 id。省略则任意「含本插件成员的团队」都算命中。 */\n\tteams?: readonly string[];\n\t/** 本插件提供的 skill 名;用户在输入框里提到时命中。 */\n\tskills?: readonly string[];\n\t/** 本插件提供的 MCP server 名。 */\n\tmcpServers?: readonly string[];\n}\n\n/** 用户在新会话页当前选中的对话目标。 */\nexport interface PluginNewSessionTarget {\n\treadonly kind: \"agent\" | \"team\";\n\t/** Agent 档案 id 或团队 id。 */\n\treadonly id: string;\n\t/** 目标若由本插件贡献,这里给出 manifest 里的那个 id。 */\n\treadonly contributedId?: string;\n}\n\n/**\n * 渲染上下文。这是一个**会继续生长的对象**:后续新增字段不会破坏既有插件,所以按需\n * 解构、不要假定它只有这些键。\n */\nexport interface PluginNewSessionContext {\n\treadonly target: PluginNewSessionTarget | null;\n\t/** 输入框里提到的、属于本插件的能力。 */\n\treadonly mentionedAbilities: {\n\t\treadonly skills: readonly string[];\n\t\treadonly mcpServers: readonly string[];\n\t};\n\t/**\n\t * 输入框中尚未发送的文本。需要 `conversation.draft.read` 权限,未授予时恒为空串。\n\t *\n\t * 只在本贡献处于激活状态时提供——插件拿不到「用户随便打点什么」的全程流水。\n\t */\n\treadonly draft: string;\n\t/** 当前工作区目录;未选择项目时为 null。 */\n\treadonly cwd: string | null;\n\t/** 回写输入栏。刻意不提供「直接发送」:越过发送前这道关不属于本区职责。 */\n\treadonly composer: {\n\t\t/** 把资源挂成附件,随下一次发送带走。 */\n\t\tattach(attachment: PluginPromptAttachment): void;\n\t\t/**\n\t\t * 往草稿里插一段文本。始终是插入而非替换,免得抹掉用户已经打的内容。\n\t\t *\n\t\t * `position` 缺省为 `\"end\"`(光标处)。`\"start\"` 插到最前面,适合「先定题、细节\n\t\t * 由用户补」这类写法——用户点完多半光标并不在开头,位置只能由调用方定死。\n\t\t */\n\t\tinsertText(text: string, options?: { position?: \"start\" | \"end\" }): void;\n\t};\n}\n\n/**\n * 新会话页输入框下方的一块内容(`ui.slot.new-session-context`)。\n *\n * 与 input-action 的分工:那是发送前的开关,这是发送前的**上下文**——把用户接下来多半\n * 要用到的素材摆出来。激活与否由宿主按 {@link PluginNewSessionContextActivation} 裁决,\n * 插件只负责在被激活后渲染,因此拿不到用户逐键输入的全程内容。\n *\n * 同时有多个贡献上屏时,宿主会在该区域顶部出 tabbar;只有一个时直接渲染内容。\n */\nexport interface PluginNewSessionContextContribution {\n\tid: string;\n\t/** tabbar 上的标题;只有一个贡献上屏时不展示。 */\n\tlabel: string;\n\t/** tab 图标;省略时用插件自己的图标。 */\n\ticon?: ReactNode;\n\tactivateWhen: PluginNewSessionContextActivation;\n\t/**\n\t * 横向占位。`\"input\"`(默认)与输入框同宽,适合补充说明一类的窄内容;`\"wide\"` 铺满\n\t * 页面可用宽度,留给画廊、素材墙这类「内容本身就是主角」的东西——把它们压在输入框\n\t * 宽度里,每一项都会小到看不清。\n\t */\n\twidth?: \"input\" | \"wide\";\n\trender(context: PluginNewSessionContext): ReactNode;\n}\n\n/**\n * 顶栏动作的下拉菜单项。点击一项执行 `onSelect` 并关闭菜单(`checkbox` / `radio` 例外,见\n * {@link PluginHeaderActionMenuItemKind})。\n */\n/**\n * 菜单项的类型。省略即普通命令项;其余类型让「列表就是状态」的场景(分支列表、开关、\n * 加载中、空态)不必退化成纯文字:\n * - `checkbox` / `radio`:`checked` 决定勾选标记,点它触发 `onSelect` 后菜单不自动关(适合切换开关);\n * - `label`:分组标题,不可点;\n * - `loading` / `empty`:占位行,自动禁用、不可点;\n * - `submenu`:`children` 是下一级菜单项(只支持一层)。\n */\nexport type PluginHeaderActionMenuItemKind =\n\t| \"item\"\n\t| \"checkbox\"\n\t| \"radio\"\n\t| \"label\"\n\t| \"loading\"\n\t| \"empty\"\n\t| \"submenu\";\n\nexport interface PluginHeaderActionMenuItem {\n\t/** 项在菜单内唯一的 id。 */\n\tid: string;\n\t/** 默认 `item`。 */\n\tkind?: PluginHeaderActionMenuItemKind;\n\tlabel: string;\n\t/** 菜单项前的图标,16px 方框内显示。`checkbox` / `radio` 已选中时换成勾选标记。 */\n\ticon?: ReactNode;\n\t/** `submenu` 且给了 `children` 时可省略。 */\n\tonSelect?: () => void;\n\t/** `submenu` 的下一级菜单项。 */\n\tchildren?: readonly PluginHeaderActionMenuItem[];\n\t/** `checkbox` / `radio` 是否已选中。 */\n\tchecked?: boolean;\n\tdisabled?: boolean;\n\t/** 禁用原因:禁用时排在 `title` 之前显示,用户才知道为什么点不了。 */\n\tdisabledReason?: string;\n\t/** 危险操作(红色)。 */\n\tdestructive?: boolean;\n\t/** 在这一项之前画一条分隔线。 */\n\tseparatorBefore?: boolean;\n}\n\n/** 顶栏动作气泡里的内容组件拿到的 props。 */\nexport interface PluginHeaderActionPopoverProps {\n\t/** 关闭气泡(例如内容里点了「完成」)。 */\n\tclose: () => void;\n}\n\n/** 角标与图标的语义色,跟随宿主主题;`neutral` 为默认。 */\nexport type PluginHeaderActionTone = \"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n\n/** 气泡尺寸:`sm` 约 16rem,`md`(默认)约 24rem,`lg` 约 32rem。 */\nexport type PluginHeaderActionPopoverSize = \"sm\" | \"md\" | \"lg\";\n\n/**\n * 气泡的容器形态。默认 `popover`(贴着按钮的小浮层);内容是有输入框、列表等需要专注的界面时\n * 用 `dialog`(宿主居中对话框,带标题栏与关闭按钮,宽度由 `size` 决定)。\n */\nexport type PluginHeaderActionPopoverHost = \"popover\" | \"dialog\";\n\n/** 气泡声明:直接给组件,或给组件加容器参数。 */\nexport type PluginHeaderActionPopover =\n\t| ComponentType<PluginHeaderActionPopoverProps>\n\t| {\n\t\t\tcomponent: ComponentType<PluginHeaderActionPopoverProps>;\n\t\t\tsize?: PluginHeaderActionPopoverSize;\n\t\t\thost?: PluginHeaderActionPopoverHost;\n\t\t\ttitle?: string;\n\t };\n\n/** 顶栏动作此刻能拿到的上下文:它在哪个页面、当前工作目录是什么。 */\nexport interface PluginHeaderActionContext {\n\t/**\n\t * 当前页面。`conversation` = 会话页;`new-session` = 新会话页(还没有消息,\n\t * 顶栏只有置顶与活动面板开关)。\n\t */\n\tsurface: PluginHeaderActionSurface;\n\t/** 当前工作目录;没有项目(例如空白新会话)时为 `null`。 */\n\tcwd: string | null;\n}\n\n/** 顶栏动作可以出现的页面。 */\nexport type PluginHeaderActionSurface = \"conversation\" | \"new-session\";\n\n/**\n * 顶栏动作此刻的**声明**,由 {@link PluginHeaderActionContribution.useAction} 返回。\n *\n * 宿主用它统一渲染成与内置按钮完全一致的一格;插件能决定的只有下面这些字段,没有 `className`、\n * `style`,也无法替换按钮本身。默认**只有图标**,名称靠悬浮提示(`title`)显示;需要把状态\n * 写在脸上时用 `label`(宽屏才显示,窄了自动退回图标)。\n * `click` / `menuItems` / `popover` **三选一**:\n * 同时给多个时按 `menuItems` > `popover` > `onClick` 取第一个;一个都没有则该动作不显示。\n *\n * 宿主会校验并截断:`title` 最长 40 字、`label` 最长 24 字(超出截断),`menuItems` 最多\n * 20 项,`badge` 只接受数字(≥ 1,超过 99 显示 `99+`)或 `true`(红点)。\n */\nexport interface PluginHeaderActionState {\n\t/** 必填。悬浮提示、无障碍名称(按钮上不显示文字时,用户全靠它认出这个动作)。 */\n\ttitle: string;\n\t/**\n\t * 必填。图标节点,宿主放进 16px 的固定方框里并忽略指针事件,建议直接用\n\t * iconify 的 `<span className=\"icon-[solar--…]\" />`。\n\t */\n\ticon: ReactNode;\n\t/**\n\t * 图标右侧的文字,用于「状态本身就是文字」的动作(分支名、当前模型、同步落后数)。\n\t * 最长 24 字;顶栏有位置时显示,被收纳、页头挤窄、顶栏超过 4 格时自动退回纯图标。\n\t */\n\tlabel?: string;\n\t/** 角标:数字显示计数,`true` 显示红点。被收纳时宿主会把它汇总到收纳入口上。 */\n\tbadge?: number | boolean;\n\t/** 角标与图标的语义色,默认 `neutral`(灰色数字 / 本色图标)。 */\n\ttone?: PluginHeaderActionTone;\n\t/** 选中态(例如面板已打开)。 */\n\tactive?: boolean;\n\tdisabled?: boolean;\n\t/** 禁用原因:禁用时替代 `title` 显示,用户才知道为什么点不了。 */\n\tdisabledReason?: string;\n\t/**\n\t * 处于选中态时,即使被收纳也要在活动面板开关左侧露出来(例如「正在录制」这类必须可见的状态)。\n\t * 只在顶栏有活动面板开关的页面上生效。\n\t */\n\tpromoteWhenActive?: boolean;\n\t/** 点击直接执行。 */\n\tonClick?: () => void;\n\t/** 点击向下弹出下拉菜单。 */\n\tmenuItems?: readonly PluginHeaderActionMenuItem[];\n\t/**\n\t * 点击弹出气泡,内容是你自己的组件。气泡的背景、圆角、投影由宿主固定,宽高随内容自适应;\n\t * 被收纳时它会在收纳托盘里**内联展开**(宽约 260px),内容请能在这个宽度下正常显示。\n\t */\n\tpopover?: PluginHeaderActionPopover;\n}\n\n/**\n * 会话页与新会话页顶栏右侧按钮组里的一格(`ui.slot.header-action`)。\n *\n * 顶栏右侧是**宿主统一管理的一个按钮组**:内置按钮(导出 / 置顶 / 终端 / 底部面板)与所有插件\n * 贡献排在同一组里,外观由宿主决定,插件不能自定义样式。显示规则:\n * - 顶栏最多显示 7 格(不含最右侧固定的「活动面板」开关),内置与插件共用这 7 个名额;\n * - 超出的、以及用户主动收起的动作进入「收纳」托盘(悬浮在按钮组上时,组下方出现的小白条);\n * - 用户可以在托盘里拖动调整顺序、决定哪些在顶栏哪些收纳,这份布局按动作 id 记在本机;\n * - 新装插件的动作:顶栏还有空位就排进去,否则进收纳,不会挤走用户已有的布局;\n * - `pin: \"prefer\"` 只是「用户没调整过时优先上栏」的建议,仍然用户可以改、也不突破 7 格上限。\n * 所以插件**不能**假定自己一定在顶栏上,也不能依赖相邻的是谁。\n *\n * 出现页面由 `surfaces` 决定,默认只有会话页。\n */\nexport interface PluginHeaderActionContribution {\n\t/** 贡献 id,在本插件内唯一,最长 64 字符。用户的布局按 `${插件 id}:${id}` 记忆,请不要随意改名。 */\n\tid: string;\n\t/**\n\t * 默认排序权重,小的靠左。**只影响用户还没自己调整过时的初始位置**,省略按注册顺序排在最后;\n\t * 同值按插件 id、贡献 id 稳定排序。\n\t */\n\torder?: number;\n\t/** 出现在哪些页面,默认 `[\"conversation\"]`。 */\n\tsurfaces?: readonly PluginHeaderActionSurface[];\n\t/**\n\t * 初始布局建议。`\"prefer\"` 表示用户没调整过布局时优先占用顶栏的一个名额\n\t * (仍受 7 格上限与用户后来的调整约束);默认 `\"normal\"`,即先待在收纳托盘里。\n\t */\n\tpin?: \"normal\" | \"prefer\";\n\t/**\n\t * 返回动作此刻的声明,返回 `null` 表示当前不适用(例如没有项目目录),宿主不显示也不占位。\n\t *\n\t * 这是一个 **React hook**:宿主在对应页面顶栏挂载期间一直调用它,所以可以在里面用任意 hook\n\t * (`useActiveConversation()`、`useTranslation()`、你自己的 store……),数据变化时自然重新声明。\n\t * 入参给出当前页面与工作目录,可以据此决定是否出现、显示什么。\n\t * 约束:\n\t * - 渲染期必须是纯计算,不要在里面发请求、起定时器;这类副作用放进 `useEffect`;\n\t * - 抛错只会让这一项消失(错误边界隔离),不会影响其它动作;\n\t * - 每次渲染都可以返回新对象,宿主不依赖引用相等。\n\t */\n\tuseAction: (context: PluginHeaderActionContext) => PluginHeaderActionState | null;\n}\n\n/**\n * 宿主左侧侧边栏此刻的形态。给插件自适应布局用——尤其是沉浸式工作区视图:\n * 侧边栏收起时宿主页头会长出「展开侧边栏」按钮并占住左上角,视图自己画在那一带的\n * 东西需要让位。\n */\nexport interface PluginSidebarState {\n\t/** 用户手动收起了侧边栏。窄屏下这一位仍然只反映用户意愿,不受窗口宽度影响。 */\n\tcollapsed: boolean;\n\t/** 窗口窄到侧边栏改走悬浮覆盖,不再占据左侧一栏。 */\n\tnarrow: boolean;\n\t/** 侧边栏此刻是否实际占着左边那一栏。等价于 `!collapsed && !narrow`,多数自适应只需要这一位。 */\n\tvisible: boolean;\n}\n\nexport interface PluginUiApi {\n\tregisterGlobalSlot(contribution: PluginGlobalSlotContribution): Disposable;\n\tregisterAbilityDetailSlot(contribution: PluginAbilityDetailSlotContribution): Disposable;\n\t/** Render an opaque setup URL as a host-themed PNG data URL. */\n\tcreateQrCode(text: string): Promise<string>;\n\t/**\n\t * Register a **workspace view**(工作区视图)— a full-page surface with its own\n\t * route and sidebar entry, on par with the host's built-in pages. Needs the\n\t * `ui.slot.workspace-view` permission (missing permission = **warn+noop**).\n\t *\n\t * The entry lands in the sidebar's「更多」收纳 by default; the user can pin it\n\t * to the top region or reorder it, and that layout is remembered.\n\t */\n\tregisterWorkspaceView(contribution: PluginWorkspaceViewContribution): Disposable;\n\t/**\n\t * Register a **new-session context block** — content shown beneath the input\n\t * on the new-session page, surfaced only when the user's current selection or\n\t * draft matches {@link PluginNewSessionContextActivation}. Needs the\n\t * `ui.slot.new-session-context` permission (missing permission = **warn+noop**).\n\t */\n\tregisterNewSessionContext(contribution: PluginNewSessionContextContribution): Disposable;\n\t/**\n\t * Register a **header action** — one declarative slot in the conversation\n\t * page header's host-managed button group (icon / badge plus a click,\n\t * menu or popover; no custom styling — see\n\t * {@link PluginHeaderActionContribution}). The user decides, via the group's\n\t * overflow tray, which actions sit in the header (max 7 shared with the host's\n\t * own buttons) and in what order. Needs the `ui.slot.header-action`\n\t * permission (missing permission = **warn+noop**) and Plugin API `^2.9.0`.\n\t */\n\tregisterHeaderAction(contribution: PluginHeaderActionContribution): Disposable;\n\t/**\n\t * Navigate to one of this plugin's own workspace views. `viewId` is the\n\t * contribution id passed to {@link PluginUiApi.registerWorkspaceView}. No-op\n\t * when the view is not registered (e.g. permission missing).\n\t */\n\topenWorkspaceView(viewId: string): void;\n\t/**\n\t * Update (or clear, with `null`) the badge on one of this plugin's workspace\n\t * view entries. Re-registering the view is NOT a way to do this — it would\n\t * remount the whole surface — so live badges (unread counts, status dots)\n\t * must come through here.\n\t *\n\t * No-op when the view is not registered (e.g. permission missing).\n\t */\n\tsetWorkspaceViewBadge(viewId: string, badge: PluginNavBadge | null): void;\n\t/**\n\t * Fill (or clear, with `null`) the host page header while one of this\n\t * plugin's workspace views is open. Call it from the view component (an\n\t * effect that re-runs on state change) and clear it on unmount — the host\n\t * keeps the entry keyed by view, and only applies it on that view's route.\n\t *\n\t * The header itself is never removed: it owns the window drag region and the\n\t * macOS traffic-light gutter. This is how a view takes it over instead.\n\t *\n\t * No-op when the view is not registered (e.g. permission missing).\n\t */\n\tsetWorkspaceViewHeader(viewId: string, header: PluginWorkspaceViewHeader | null): void;\n\t/**\n\t * Register a preview component keyed by file extension. The host dispatches\n\t * registered extensions before its built-in fallback renderers; first\n\t * registrant wins on conflict.\n\t */\n\tregisterFilePreview(contribution: PluginFilePreviewContribution): Disposable;\n\t/**\n\t * Register an activity-panel tab into the addable pool. The user attaches\n\t * it manually via the panel's \"+\" picker; attach records are keyed by the\n\t * workspace cwd. A contribution that declares `useMeta` decides its own\n\t * availability per workspace (see {@link PluginActivityTabContribution.useMeta}).\n\t */\n\tregisterActivityTab(contribution: PluginActivityTabContribution): Disposable;\n\t/**\n\t * Register a component into the session's bottom panel addable pool. The user\n\t * opens instances from the panel's \"+\" menu; one contribution can have several\n\t * instances in the same session, and each instance renames itself through\n\t * {@link useBottomPanel}.\n\t */\n\tregisterBottomPanel(contribution: PluginBottomPanelContribution): Disposable;\n\t/**\n\t * Register a toggle action shown beneath the AI input bar. While active,\n\t * its `decoratePrompt()` annotates the next outgoing prompt.\n\t */\n\tregisterInputAction(contribution: PluginInputActionContribution): Disposable;\n\t/**\n\t * Register a card renderer keyed by `type`. Cards rendered beneath a message\n\t * come from tool results' out-of-band `details.cards` (or `pendingFor` for\n\t * in-flight tools); the host resolves each card's `type` to a registered\n\t * renderer. Multiple cards under one message are shown as a tab-switcher\n\t * (\"收纳\") or a flat list.\n\t */\n\tregisterCardRenderer(contribution: PluginCardRendererContribution): Disposable;\n\t/**\n\t * Register a renderer that replaces the host's default inline transcript UI\n\t * for a tool call (matched by `toolName`). The complement to card renderers:\n\t * use it to render UI for a plugin's own agent tool output.\n\t */\n\tregisterToolCallSlot(contribution: PluginToolCallSlotContribution): Disposable;\n\t/**\n\t * Register a card rendered at the bottom of the message list for the latest\n\t * turn — NOT bound to a tool call. The host mounts the component in the\n\t * footer slot; the plugin owns visibility (return `null` to render nothing,\n\t * e.g. git renders only in a repo with changes). Gated by `scope_use`\n\t * (fail-closed). Needs the `ui.slot.turn-card` permission.\n\t */\n\tregisterTurnCard(contribution: PluginTurnCardContribution): Disposable;\n\t/**\n\t * Register a keyboard shortcut scope on the host's shared ShortcutScopeStack\n\t * (same path as host UI: modal > overlay > surface > app). Needs\n\t * `ui.shortcuts.register`. Plugins cannot use kind `\"app\"` (reserved for\n\t * host-configurable global actions). Prefer {@link usePluginShortcutScope}\n\t * from React components with a module-captured `registerShortcutScope`.\n\t */\n\tregisterShortcutScope(contribution: PluginShortcutScopeContribution): Disposable;\n\t/**\n\t * Programmatically attach (if needed) and activate one of this plugin's\n\t * own activity tabs in a conversation's activity panel. `tabId`\n\t * is the contribution id passed to registerActivityTab. Any payload (e.g.\n\t * which image to edit) is passed via the plugin's own in-memory state.\n\t *\n\t * Pass `options.width` to size the panel as it opens — a pixel number, or\n\t * `\"max\"` to expand it to the widest the current window allows (the host\n\t * still clamps to its min/max and auto-hides the sidebar when needed). Omit\n\t * to leave the user's current width untouched.\n\t *\n\t * Omit `options.cwd` for the conversation currently displayed by the host.\n\t * Tool handlers and background work should pass their session cwd explicitly.\n\t */\n\topenActivityTab(tabId: string, options?: PluginOpenActivityTabOptions): void;\n\t/**\n\t * 把本插件的某个活动面板标签卡在目标会话里上栏 / 下栏,**不激活也不展开\n\t * 面板**——`openActivityTab` 是「用户此刻要看它」,这个是「它现在该不该在\n\t * 栏里」。配合 `initiallyVisible: false` 使用,插件即可完全掌握自己标签卡的\n\t * 出现条件(如 git 只在仓库目录里上栏、工作台跟随输入栏 toggle)。\n\t *\n\t * 上栏记录按会话 cwd 持久化(ADR-0026),所以只需在条件变化时调用一次;\n\t * 用户随后用减号手动隐藏的结果不会被重复调用覆盖。缺省作用于宿主当前显示的\n\t * 会话;工具 handler 与后台任务应通过 `options.cwd` 传入自己的会话 cwd。既没有\n\t * 显式 cwd、也没有活动会话时为 no-op(无处记录)。\n\t */\n\tsetActivityTabVisible(tabId: string, visible: boolean, options?: PluginActivityTabTargetOptions): void;\n\t/**\n\t * 直接设置活动面板宽度:像素值,或 `\"max\"` 表示「跟随窗口拉满」(宿主仍会夹到\n\t * 自己的 min/max 内,必要时自动收起侧边栏)。\n\t *\n\t * `\"max\"` 是一种持续状态而非一次性求值:窗口尺寸变化时面板跟着变宽变窄,直到\n\t * 用户拖动分隔条或有人写入具体像素为止。传数字则是一次性的固定宽度。\n\t *\n\t * 与 `openActivityTab(id, { width })` 的区别:那里的宽度只在标签卡首次 attach\n\t * 时生效(避免 activate 重放覆盖用户手拖的宽度);这个是命令式的,每次调用都\n\t * 生效,供插件在自己的标签卡被激活、进入某种视图时按需调整。用户随后仍可拖动。\n\t */\n\tsetActivityPanelWidth(width: number | \"max\"): void;\n\t/**\n\t * Bind or clear plugin-owned context for outgoing prompts. The host renders\n\t * its label/icon and carries a structured `context` as a versioned snapshot.\n\t * Attachments default to one-shot; `lifecycle: \"sticky\"` remains until the\n\t * plugin or user clears the capsule.\n\t */\n\tsetPromptAttachment(attachment: PluginPromptAttachment | null): void;\n\t/**\n\t * Open the host's global full-screen image previewer for the given image.\n\t * Only the image reference (id/url) crosses over — bytes stay out-of-band.\n\t *\n\t * Pass `group` (e.g. all images of the message) to open as an image group:\n\t * the previewer shows a thumbnail strip + arrows and starts at `ref`.\n\t */\n\tpreviewImage(ref: PluginImageRef, group?: PluginImageRef[]): void;\n\t/**\n\t * Open the host's global file previewer for any file — the general form of\n\t * {@link PluginUiApi.previewImage}, which only takes image URLs. Accepts a\n\t * local absolute `path` (the shape the host's own file tree uses) as well as\n\t * a `url`; the previewer dispatches by the file's extension, so a file type\n\t * some plugin registered via `registerFilePreview` lands in that renderer.\n\t *\n\t * Pass `group` (e.g. all outputs of one run) to open as a group: images get\n\t * the thumbnail strip + arrows, and the previewer starts at `file`.\n\t *\n\t * Permissions: `fs.read` as soon as any entry carries a `path` (it hands a\n\t * local file to the host to read); `ui.slot.message` for url-only calls,\n\t * same gate as `previewImage`.\n\t */\n\tpreviewFile(file: PluginPreviewFileRef, group?: PluginPreviewFileRef[]): void;\n\t/**\n\t * Capture a rectangle in the current Vetta window and open the host save\n\t * dialog. Coordinates use renderer DIP values such as getBoundingClientRect().\n\t * Requires `ui.slot.activity-tab`.\n\t */\n\tcaptureRegion(rect: PluginCaptureRegion, defaultFileName: string): Promise<string | null>;\n\t/**\n\t * Copy an image to the system clipboard. Takes a `data:image/...;base64,`\n\t * URL and goes through the native clipboard, so it does not depend on the\n\t * renderer's `ClipboardItem` support. No permission required — the plugin\n\t * can only write what it already rendered.\n\t */\n\tcopyImage(dataUrl: string): Promise<void>;\n\t/**\n\t * Hand a URL to the OS default browser (Electron `shell.openExternal`) —\n\t * NOT the in-app browser panel. Only `http:`/`https:` are accepted; the host\n\t * rejects every other protocol, so this cannot be used to launch arbitrary\n\t * schemes. Needs `shell.openExternal`.\n\t */\n\topenExternal(url: string): Promise<void>;\n\t/**\n\t * Show a global toast in the host UI (bottom-right). No permission required.\n\t * Prefer this over swallowing errors into opaque UI copy: pass `error` so\n\t * the host attaches a one-click \"copy stack\" action for the user.\n\t *\n\t * Capture `ctx.ui.notify` in `activate` if React components need it\n\t * (components do not receive `ctx`).\n\t */\n\tnotify(options: PluginNotifyOptions): void;\n\t/**\n\t * 读当前侧边栏形态。无需权限——这是纯布局信息,不含任何用户数据。\n\t *\n\t * React 组件请改用 `useSidebarState()`:它会在状态变化时重渲染,不必自己订阅。\n\t * 这一对只为拿不到 hook 的地方准备(`activate()` 内、工具处理器、命令式绘制的画布)。\n\t */\n\tgetSidebarState(): PluginSidebarState;\n\t/**\n\t * 订阅侧边栏形态变化——用户收起/展开侧边栏、或窗口跨过窄屏阈值时触发。\n\t * 返回 Disposable 取消订阅;请在插件失活时释放。\n\t *\n\t * 回调按值去重:拖窗口不会把它打成回调风暴,只有三元组真的变了才通知。\n\t */\n\tonSidebarStateChanged(listener: (state: PluginSidebarState) => void): Disposable;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType, ReactNode } from \"react\";\nimport type { ConversationMessage } from \"./conversation.js\";\nimport type { Disposable } from \"./disposable.js\";\nimport type { PluginImageRef } from \"./images.js\";\nimport type { PluginPromptAttachment } from \"./prompt-attachment.js\";\nimport type { ConversationScenario } from \"./scenario.js\";\nimport type { PluginShortcutScopeContribution } from \"./shortcuts.js\";\n\nexport interface PluginGlobalSlotContribution {\n\tid: string;\n\tcomponent: ComponentType;\n}\n\nexport interface PluginAbilityDetailSlotProps {\n\tabilityId: string;\n\tinstalled: boolean;\n\tenabled: boolean;\n}\n\n/** Inline setup/status surface rendered near the top of one ability detail page. */\nexport interface PluginAbilityDetailSlotContribution {\n\tid: string;\n\tabilityId: string;\n\tcomponent: ComponentType<PluginAbilityDetailSlotProps>;\n}\n\n/**\n * Props handed to a workspace-view component. A workspace view owns the whole\n * content area, so unlike panel slots it is addressed by its own route and can\n * be deep-linked; the host passes back its identity so one component can serve\n * several registered views.\n */\nexport interface PluginWorkspaceViewProps {\n\t/** The contribution id as registered (NOT namespaced). */\n\tviewId: string;\n\t/** The owning plugin id. */\n\tpluginId: string;\n}\n\n/**\n * Badge tone. The host maps it to its own theme colors — a plugin cannot pick a\n * raw color, so badges stay consistent with the built-in navigation entries.\n */\nexport type PluginNavBadgeTone = \"accent\" | \"danger\" | \"default\" | \"warning\";\n\n/**\n * A badge on the plugin's sidebar navigation entry.\n *\n * `beta` is the host's own preset — it renders exactly like the built-in\n * 知识库 Beta 标识, wording included (and localized by the host), so plugins do\n * not have to spell \"Beta\" themselves in every locale.\n *\n * `count` renders `99+` past 99 and disappears at 0 — an unread badge showing\n * \"0\" is worse than no badge.\n */\nexport type PluginNavBadge =\n\t| { kind: \"beta\" }\n\t| { kind: \"text\"; text: string; tone?: PluginNavBadgeTone }\n\t| { kind: \"count\"; count: number; tone?: PluginNavBadgeTone }\n\t| { kind: \"dot\"; tone?: PluginNavBadgeTone };\n\n/**\n * A **workspace view**(工作区视图): a full-page surface a plugin contributes to\n * the host's primary navigation. It is the plugin counterpart of a built-in page\n * such as 自动化 / 知识库 — the host gives it its own route\n * (`/workspace/<pluginId>/<viewId>`) and a sidebar entry, and the plugin owns the\n * entire content area while it is open.\n *\n * Use it for standalone workbenches that are NOT bound to one conversation\n * (dashboards, boards, consoles). Conversation-scoped UI belongs in an\n * {@link PluginActivityTabContribution activity tab}; floating UI belongs in a\n * {@link PluginGlobalSlotContribution global slot}.\n */\nexport interface PluginWorkspaceViewContribution {\n\t/** Unique within the plugin; the host namespaces it as `${pluginId}:${id}`. */\n\tid: string;\n\t/** Sidebar entry label. Supports `%catalogKey%` i18n lookup. */\n\tlabel: string;\n\t/**\n\t * Sidebar entry icon as an **iconify class string** (e.g.\n\t * `\"icon-[solar--widget-5-linear]\"`) — NOT a React node, because the host\n\t * renders it inside its own nav button and persists nav layout by key.\n\t *\n\t * Omit it to inherit the plugin's own `plugin.json` icon: a packaged image\n\t * (svg / png / webp …) is masked with the theme's foreground color, so a plugin\n\t * that ships artwork does not have to find a lookalike in an icon set. Set\n\t * {@link PluginWorkspaceViewContribution.iconTint} to `false` to keep its colors.\n\t */\n\ticon?: string;\n\t/**\n\t * Whether an image icon is tinted with the theme's foreground color. Defaults to\n\t * `true`, which keeps the entry consistent with the built-in navigation and legible\n\t * in every theme.\n\t *\n\t * Pass `false` for a full-color logo. Weigh it first: the entry renders at 16px\n\t * beside monochrome built-ins, and a fixed-color image cannot follow the active\n\t * theme — a dark logo can disappear on a dark sidebar. Has no effect on Iconify\n\t * class icons, which are always tinted.\n\t */\n\ticonTint?: boolean;\n\t/** Optional one-line description; shown as the nav entry tooltip. */\n\tdescription?: string;\n\t/**\n\t * Initial badge on the sidebar entry. `{ kind: \"text\" }` supports the same\n\t * `%catalogKey%` i18n lookup as {@link label}. Update it at runtime with\n\t * {@link PluginUiApi.setWorkspaceViewBadge}.\n\t */\n\tbadge?: PluginNavBadge;\n\t/** Zero-props aside from {@link PluginWorkspaceViewProps}. */\n\tcomponent: ComponentType<PluginWorkspaceViewProps>;\n\t/** Sort hint among this plugin's own views (ascending). Defaults to 0. */\n\tnavOrder?: number;\n\t/**\n\t * Whether this view takes a sidebar entry. Defaults to `true`.\n\t *\n\t * Pass `false` for a surface users open occasionally — a setup page, a\n\t * diagnostics console. It then lives only under Settings → More options,\n\t * where the host lists every off-sidebar view and opens it inside the\n\t * settings shell, so switching between such pages stays one click.\n\t *\n\t * The sidebar is a scarce, user-curated space: a plugin that always claims a\n\t * slot pushes the entries someone actually uses into the overflow menu.\n\t */\n\tsidebar?: boolean;\n}\n\n/**\n * What a workspace view puts into the **host page header** — the window's top\n * bar that also carries the drag region, the macOS traffic-light gutter and the\n * sidebar trigger.\n *\n * Without this the header still renders, showing the app name above the\n * plugin's own toolbar — two stacked bars. Set `hideTitle` and move the view's\n * toolbar in here and the surface gets a single, host-consistent header.\n *\n * `left` / `right` are ReactNodes rendered by the host inside that bar (left:\n * right after the sidebar trigger; right: before the window controls). They are\n * rendered in the plugin's i18n + CSS scope, so `useTranslation()` and the\n * plugin's own classes work as usual. Pass fresh nodes whenever the view's\n * state changes — this is a live setter, not a one-time registration.\n */\nexport interface PluginWorkspaceViewHeader {\n\t/** Replaces the host title text. Supports `%catalogKey%` i18n lookup. */\n\ttitle?: string;\n\t/** Drop the host title entirely (use when {@link left} carries its own). */\n\thideTitle?: boolean;\n\t/** Rendered in the header's left cluster, after the sidebar trigger. */\n\tleft?: ReactNode;\n\t/** Rendered in the header's action cluster, before the window controls. */\n\tright?: ReactNode;\n\t/**\n\t * Float the host header OVER the view instead of stacking above it. The view\n\t * then owns the full content height, and its top `~44px` sit under the\n\t * transparent header strip (window drag region / traffic lights / sidebar\n\t * trigger all keep working on top). Use for immersive full-page surfaces\n\t * whose own hero starts at the very top; leave unset for toolbar-style\n\t * headers that need their own opaque row.\n\t */\n\timmersive?: boolean;\n}\n\nexport interface PluginAudioMetadata {\n\t/** Embedded title; preview renderers should fall back to file.name. */\n\ttitle?: string;\n\tartist?: string;\n\t/** Embedded cover art as a Data URL when available. */\n\tcoverDataUrl?: string;\n}\n\nexport interface PluginPreviewUrlOptions {\n\t/** Optional media hint for ambiguous containers such as webm. */\n\tmediaKind?: \"audio\" | \"video\";\n}\n\n/**\n * The file handed to a file-preview plugin component. The host does NOT\n * pre-read or guess encoding — the plugin decides whether to read text or\n * bytes. `path` is also exposed for plugins that prefer native fetch.\n */\nexport interface PluginPreviewFile {\n\tpath: string | null;\n\tname: string;\n\textension: string;\n\tmime: string;\n\tsize: number;\n\t/** Read the file as a UTF-8 string. */\n\treadText(): Promise<string>;\n\t/** Read the raw file bytes. */\n\treadBytes(): Promise<ArrayBuffer>;\n\t/** A fetchable streaming URL for the file (Range-capable). */\n\tgetUrl(options?: PluginPreviewUrlOptions): string;\n\t/**\n\t * Subscribe to on-disk changes of this file. The listener fires (debounced\n\t * by the host) whenever the file's contents change, letting previews update\n\t * live. Returns a Disposable; call dispose() to stop watching. A no-op for\n\t * files without a real path (url-only sources).\n\t */\n\twatch(listener: () => void): Disposable;\n\t/**\n\t * Host-provided audio metadata for local media files. Returns null when the\n\t * host cannot provide metadata, e.g. url-only sources or unsupported files.\n\t */\n\tgetAudioMetadata?(): Promise<PluginAudioMetadata | null>;\n}\n\nexport interface PluginFilePreviewProps {\n\tfile: PluginPreviewFile;\n}\n\n/**\n * A file handed to {@link PluginUiApi.previewFile} — the *opening* side of the\n * global previewer, the mirror image of {@link PluginPreviewFile} (which is the\n * *rendering* side). Bytes never cross over: the host reads the source itself.\n *\n * Exactly one of `path` (local absolute path) or `url` (host media / http URL)\n * must be given. `path` is the shape the host's own file tree uses, so the\n * previewer also offers \"在 Finder 中显示\" for it.\n */\nexport interface PluginPreviewFileRef {\n\t/** Local absolute path. Requires the `fs.read` permission. */\n\tpath?: string;\n\t/** Fetchable URL (host media URL or http/https). Requires `ui.slot.message`. */\n\turl?: string;\n\t/**\n\t * Display name **including the extension** — the previewer dispatches to a\n\t * renderer by this extension, not by `mimeType`. Optional for `path`\n\t * sources (the host falls back to the path's basename).\n\t */\n\tname?: string;\n\tmimeType?: string;\n\t/** Byte size, shown in the previewer's download detail when known. */\n\tsize?: number;\n}\n\nexport interface PluginFilePreviewContribution {\n\t/** Lower-case extensions without the dot, e.g. [\"svg\"]. */\n\textensions: string[];\n\tcomponent: ComponentType<PluginFilePreviewProps>;\n}\n\n/** Host residency policy for an activity-panel tab. */\nexport type PluginActivityTabRetention = \"active-only\" | \"warm\" | \"pinned\";\n\n/**\n * 活动面板标签卡此刻所在的工作空间。`cwd` 与面板自己的作用域一致(项目详情页是项目根,\n * 会话页是会话 cwd),插件据此判断这个工作空间该不该出现自己的标签卡。\n */\nexport interface PluginActivityTabScope {\n\treadonly cwd: string | null;\n}\n\n/**\n * 一帧的标签卡状态,由 {@link PluginActivityTabContribution.useMeta} 按当前工作空间返回。\n * 只影响「在不在栏上」这类摆放语义;名字与图标仍以注册时声明为默认值。\n */\nexport interface PluginActivityTabMeta {\n\t/** 覆盖注册时的 label(已本地化);省略时用注册值。 */\n\treadonly label?: string;\n\t/** 覆盖注册时的 icon;省略时用注册值(含 `plugin.json#icon` 回落)。 */\n\treadonly icon?: ReactNode;\n\t/** 标签卡角标;0 / 省略表示不显示。 */\n\treadonly badge?: number;\n\t/**\n\t * 固定上栏:只要本帧返回的 meta 非空且 `pinned` 为 true,标签卡就一直在标签栏里,\n\t * 用户无法用减号移除,也不受「+」可添加池与历史隐藏记录左右。适合「工作空间里有\n\t * 这个东西就必须看得到」的面板(如项目根存在 `.git` 的 Git 面板)。\n\t *\n\t * 省略 = 按用户的上栏记录 / `initiallyVisible` 决定,用户仍可移除。\n\t */\n\treadonly pinned?: boolean;\n}\n\n/** {@link PluginActivityTabContribution.useMeta} 的返回:null = 本帧不进入候选。 */\nexport type PluginActivityTabMetaResult = PluginActivityTabMeta | null;\n\nexport interface PluginActivityTabContribution {\n\t/**\n\t * 标签栏上的默认相对位置,越小越靠前;缺省 100(排在全部内置标签卡之后)。\n\t *\n\t * 内置的取值可作标尺:文件 0、批量 10、浏览器 15、计划 18、待办 20、后台任务 30。\n\t * 下限被宿主钳到 10,「文件」永远是第一枚;用户拖拽出来的顺序优先于这个值。\n\t */\n\torder?: number;\n\tid: string;\n\tlabel: string;\n\t/**\n\t * Tab icon as a React node (not an iconify class string).\n\t * Omit to inherit the host-resolved brand icon from `plugin.json#icon`\n\t * (`ctx.plugin.iconUrl`). Prefer omitting for package brand icons so the\n\t * plugin never loads assets via absolute `/…` paths or host protocols.\n\t */\n\ticon?: ReactNode;\n\tcomponent: ComponentType;\n\t/**\n\t * 允许该标签卡出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如\n\t * `[\"project\", \"conversation\"]`)。会话页插槽据此随对话类型显隐。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/**\n\t * 注册后是否默认在标签栏里(缺省 `true`)。声明 `false` 表示「出现条件由我\n\t * 自己决定」——注册只是入池,之后由 {@link PluginUiApi.setActivityTabVisible}\n\t * 或 {@link PluginUiApi.openActivityTab} 决定何时上栏(如 git 只在仓库目录、\n\t * 工作台跟随输入栏 toggle)。无论哪种,用户仍可用减号手动隐藏。\n\t */\n\tinitiallyVisible?: boolean;\n\t/**\n\t * Component residency while the tab is inactive. Defaults to `\"warm\"`:\n\t * visited tabs stay mounted in the host's bounded LRU cache. Use\n\t * `\"active-only\"` for cheap, stateless content and `\"pinned\"` for runtimes\n\t * that must never be evicted while available.\n\t */\n\tretention?: PluginActivityTabRetention;\n\t/**\n\t * @deprecated Use {@link PluginActivityTabContribution.retention}. `true`\n\t * maps to `\"pinned\"`; `false` maps to `\"active-only\"`.\n\t */\n\tkeepAliveWhenAvailable?: boolean;\n\t/**\n\t * 按当前工作面决定这一帧的 meta:返回 `null` 表示本帧不进入候选(既不上栏,也不在\n\t * 「+」里),返回 `{ pinned: true }` 表示固定上栏且不可移除。\n\t *\n\t * 这是一个 **React hook**:宿主每次解析标签栏时按「已注册定义」各调用一次,所以可以在\n\t * 里面用任意 hook(自己的缓存 store、`useTranslation`……)。约束:\n\t * - 渲染期必须是纯计算,探测一类的异步工作放进 `useEffect`,结果写回自己的 store;\n\t * - 抛错只会让这一项消失(与 `null` 同效),不影响其它标签卡;\n\t * - 省略时行为与本字段出现前一致:静态 label / icon / badge,按用户上栏记录显隐。\n\t */\n\tuseMeta?: (scope: PluginActivityTabScope) => PluginActivityTabMetaResult;\n}\n\n/**\n * 会话底部面板的组件贡献。\n *\n * 与 {@link PluginActivityTabContribution} 的分工:活动面板在右侧、一个贡献只有一个\n * 实例、适合「看某个东西的当前状态」;底部面板横跨会话页下沿、可分屏、**同一个贡献\n * 可以开多个实例**,适合终端、日志跟随这类长驻的工作面。\n *\n * meta 走命令式的 {@link PluginBottomPanelContextValue.setMeta} 而不是「每帧返回 meta\n * 的 hook」:多实例场景下 hook 拿不到实例身份,两套 meta 事实源会在改名后打架。\n */\nexport interface PluginBottomPanelContribution {\n\t/** Unique within the plugin; the host namespaces it as `plugin:<pluginId>:<id>`. */\n\tid: string;\n\t/** 「+」菜单里的名字,也是新实例的初始名。Supports `%catalogKey%` i18n lookup. */\n\tlabel: string;\n\t/**\n\t * Tab icon as a React node or an iconify class string.\n\t * Omit to inherit the host-resolved brand icon from `plugin.json#icon`.\n\t */\n\ticon?: ReactNode;\n\t/** Zero-props;实例上下文经 {@link useBottomPanel} 取。 */\n\tcomponent: ComponentType;\n\t/**\n\t * 允许出现的对话场景 slug 列表。**fail-closed**:未声明/空数组 = 任何会话都不出现。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/** 「+」菜单里的相对位置,越小越靠前;缺省 100(排在内置之后)。 */\n\torder?: number;\n\t/**\n\t * 同一会话里最多能开几个实例;缺省不限。单例面板给 1,终端一类不设。\n\t */\n\tmaxInstances?: number;\n}\n\n/** Explicit conversation scope for an activity-tab command. */\nexport interface PluginActivityTabTargetOptions {\n\t/**\n\t * Absolute cwd whose activity-tab state should be changed. Omit to target\n\t * the conversation currently displayed by the host. Tool handlers and\n\t * background work should pass the triggering session's cwd so a foreground\n\t * navigation change cannot redirect the command to another conversation.\n\t */\n\tcwd?: string;\n}\n\n/** Options for {@link PluginUiApi.openActivityTab}. */\nexport interface PluginOpenActivityTabOptions extends PluginActivityTabTargetOptions {\n\t/**\n\t * Desired panel width as it opens: a pixel number, or `\"max\"` to track the\n\t * widest the window allows — `\"max\"` keeps following window resizes until the\n\t * user drags the divider. The host clamps to its min/max bounds. Omit to keep\n\t * the user's current width.\n\t *\n\t * Applied when the tab is attached for the first time, or when this call opens\n\t * a closed panel — the panel then slides in at this width in one motion.\n\t * Ignored when the panel is already open with the tab attached (the user's\n\t * width stands), and for calls made while `activate` is still running, since\n\t * those replay on every reload.\n\t */\n\twidth?: number | \"max\";\n}\n\nexport interface PluginCaptureRegion {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Decoration a plugin contributes to the next outgoing prompt while its input\n * action is active. `metadata` is shallow-merged into the prompt request and\n * `instructions` are appended as hidden, model-visible guidance.\n */\nexport interface PluginPromptDecoration {\n\tmetadata?: Record<string, unknown>;\n\t/** Hidden plugin-owned instructions appended to the next agent turn. */\n\tinstructions?: string[];\n}\n\n/**\n * An action button shown in a row beneath the AI input bar. Rendered as a\n * toggle: clicking activates, clicking again deactivates. While active, the\n * host calls `decoratePrompt()` before each send and merges the returned\n * metadata into the outgoing prompt request. The plugin owns any side state\n * (it is the same Module Federation instance as its other slots).\n */\nexport interface PluginInputActionContribution {\n\tid: string;\n\tlabel: string;\n\t/** Button icon as a React node. Omit to inherit the plugin's `plugin.json#icon`. */\n\ticon?: ReactNode;\n\t/** Whether the action begins in the active state. Defaults to false. */\n\tdefaultActive?: boolean;\n\t/**\n\t * 该输入动作所依赖的 agent 工具名。设置后,仅当该工具在当前会话处于激活(按工具的\n\t * scope_use 解析)时才显示这个 badge——避免在工具被场景屏蔽(如批量任务)时仍显示一个\n\t * 点了也无效的开关。不设则始终显示。例如「图像生成」设为 \"generate_image\"。\n\t */\n\trequiresActiveTool?: string;\n\t/**\n\t * 允许该 toggle 出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现。与 `requiresActiveTool`\n\t * 取「与」:两者都满足才显示。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n\t/**\n\t * When true, this plugin's agent contributions (tools / skills / MCP /\n\t * systemPrompt) and Activity Tabs are hard-isolated: inactive until this\n\t * toggle is on (ADR-0041, knowledgeMode-style). Default false.\n\t */\n\thardIsolation?: boolean;\n\t/**\n\t * Fired when the user toggles the action; `active` is the new state. Return\n\t * `false` when `active` is true to VETO the activation (e.g. the plugin needs\n\t * configuration first) — the toggle stays off. Deactivation can't be vetoed.\n\t */\n\tonToggle?(active: boolean): boolean | void;\n\t/**\n\t * Called by the host before sending while the action is active. The\n\t * returned metadata is merged into the outgoing prompt request.\n\t */\n\tdecoratePrompt?(): PluginPromptDecoration | void;\n}\n\n/**\n * A declarative, serializable descriptor for one card rendered beneath a\n * message. `type` selects a registered card renderer; `key` drives cross-turn\n * dedup (same key across turns = one logical card, shown only under its latest\n * anchor); `payload` carries STABLE REFERENCES (e.g. image ids), not a content\n * snapshot — the renderer resolves live state from it. `title`/`icon` label the\n * card's tab (override the renderer's registration defaults). Rides a tool\n * result's out-of-band `details.cards`; crosses the agent→host boundary, so\n * `icon` is an icon-symbol string, not a node.\n */\nexport interface CardDescriptor {\n\ttype: string;\n\tkey?: string;\n\tpayload?: unknown;\n\ttitle?: string;\n\ticon?: string;\n}\n\n/** A pending (in-flight) tool call handed to a renderer's `pendingFor`. */\nexport interface PluginPendingToolCall {\n\ttoolName: string;\n\targs: Record<string, unknown>;\n}\n\n/**\n * Props for a card renderer. `descriptor` is the card's data; `pending` is true\n * while it was synthesized from an in-flight tool (render a skeleton); `message`\n * is the anchoring conversation message.\n */\nexport interface PluginCardProps {\n\tdescriptor: CardDescriptor;\n\tpending: boolean;\n\tmessage: ConversationMessage;\n}\n\n/**\n * A card renderer registered by a plugin, keyed by `type`. A descriptor whose\n * `type` matches is rendered by `component`. `title`/`icon` are the default tab\n * label/icon (a descriptor may override either). `pendingFor`, given an\n * in-flight tool call, returns a provisional descriptor so a skeleton card\n * appears (and claims a tab) before the tool's result lands — or null when this\n * renderer doesn't handle that tool. The `type` must be globally unique across\n * plugins (convention: prefix with the plugin id, e.g. \"image-gen:preview\").\n */\nexport interface PluginCardRendererContribution {\n\ttype: string;\n\tcomponent: ComponentType<PluginCardProps>;\n\ttitle?: string;\n\t/** Default tab icon as a React node. Omit to inherit the plugin's `plugin.json#icon`. */\n\ticon?: ReactNode;\n\tpendingFor?: (toolCall: PluginPendingToolCall) => CardDescriptor | null;\n}\n\n/** A tool call handed to a tool-call slot renderer. */\nexport interface PluginToolCallSlotToolCall {\n\ttoolCallId: string;\n\ttoolName: string;\n\targs: Record<string, unknown>;\n\tstatus: \"pending\" | \"success\" | \"error\" | \"cancelled\";\n\tresult?: string;\n\tisError?: boolean;\n}\n\nexport interface PluginToolCallSlotProps {\n\ttoolCall: PluginToolCallSlotToolCall;\n}\n\n/**\n * A component that **replaces the host's default inline transcript rendering**\n * for a specific tool (matched by `toolName`; first registered renderer wins).\n * This is how a plugin renders rich UI for its OWN agent tool's output — plugin\n * tools cannot emit `details.cards`, so the message card system (registerCardRenderer)\n * does not serve them; the tool-call slot does.\n */\nexport interface PluginToolCallSlotContribution {\n\tid: string;\n\ttoolName: string;\n\tcomponent: ComponentType<PluginToolCallSlotProps>;\n}\n\n/**\n * A card rendered at the bottom of the message list for the LATEST turn — NOT\n * bound to a tool call. The host mounts `component` in the footer slot and\n * re-mounts it each session/turn; the plugin owns visibility entirely (it reads\n * live state via SDK hooks — `useActiveConversation`, `useConversationMessages`,\n * `ctx.conversation.on(\"turn-end\")` — and returns `null` to render nothing,\n * e.g. git renders only inside a repo that has changes). `scope_use` gates which\n * conversation scenarios it may appear in (**fail-closed**, mirrors the other\n * slots). `id` must be unique within the plugin.\n */\nexport interface PluginTurnCardContribution {\n\tid: string;\n\tcomponent: ComponentType;\n\t/**\n\t * 允许该 turn 卡出现的对话场景 slug 列表(镜像其它插槽的 scope_use)。**fail-closed**:\n\t * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如 `[\"project\"]`)。\n\t */\n\tscope_use?: readonly ConversationScenario[];\n}\n\n/**\n * Options for {@link PluginUiApi.notify}. Surfaces a host toast so users can\n * see plugin failures without opening DevTools.\n */\nexport interface PluginNotifyOptions {\n\t/** Toast body. Required even when `error` is set (user-facing summary). */\n\tmessage: string;\n\t/** Defaults to plugin display name when omitted. */\n\ttitle?: string;\n\t/** Defaults to `\"info\"`; when `error` is set and variant omitted, host uses `\"error\"`. */\n\tvariant?: \"info\" | \"success\" | \"warning\" | \"error\";\n\t/**\n\t * Optional failure cause. Host formats message + stack and adds a\n\t * \"复制堆栈\" action so the user can paste it into bug reports / chat.\n\t */\n\terror?: unknown;\n\t/**\n\t * Auto-dismiss delay in ms. `0` keeps the toast until dismissed.\n\t * Defaults: sticky (`0`) when `error` is present, otherwise host default (~4s).\n\t */\n\tdurationMs?: number;\n}\n\n/**\n * 新会话上下文区的激活条件。**只能写本插件自己的东西**——填别人的 id 一律不生效。\n *\n * 这条限制是故意的:否则插件 A 可以声明「只要用户选了 B 的智能体我就上屏」,把别人的\n * 使用场景劫持过来。\n *\n * 各字段取并集:任意一条命中即激活。至少要声明一条——全空等于「任何新会话都上屏」,宿主拒掉。\n */\nexport interface PluginNewSessionContextActivation {\n\t/** 本插件在 manifest 里声明的智能体 id(不带 `plugin:` 前缀)。 */\n\tagents?: readonly string[];\n\t/** 本插件在 manifest 里声明的团队 id。省略则任意「含本插件成员的团队」都算命中。 */\n\tteams?: readonly string[];\n\t/** 本插件提供的 skill 名;用户在输入框里提到时命中。 */\n\tskills?: readonly string[];\n\t/** 本插件提供的 MCP server 名。 */\n\tmcpServers?: readonly string[];\n}\n\n/** 用户在新会话页当前选中的对话目标。 */\nexport interface PluginNewSessionTarget {\n\treadonly kind: \"agent\" | \"team\";\n\t/** Agent 档案 id 或团队 id。 */\n\treadonly id: string;\n\t/** 目标若由本插件贡献,这里给出 manifest 里的那个 id。 */\n\treadonly contributedId?: string;\n}\n\n/**\n * 渲染上下文。这是一个**会继续生长的对象**:后续新增字段不会破坏既有插件,所以按需\n * 解构、不要假定它只有这些键。\n */\nexport interface PluginNewSessionContext {\n\treadonly target: PluginNewSessionTarget | null;\n\t/** 输入框里提到的、属于本插件的能力。 */\n\treadonly mentionedAbilities: {\n\t\treadonly skills: readonly string[];\n\t\treadonly mcpServers: readonly string[];\n\t};\n\t/**\n\t * 输入框中尚未发送的文本。需要 `conversation.draft.read` 权限,未授予时恒为空串。\n\t *\n\t * 只在本贡献处于激活状态时提供——插件拿不到「用户随便打点什么」的全程流水。\n\t */\n\treadonly draft: string;\n\t/** 当前工作区目录;未选择项目时为 null。 */\n\treadonly cwd: string | null;\n\t/** 回写输入栏。刻意不提供「直接发送」:越过发送前这道关不属于本区职责。 */\n\treadonly composer: {\n\t\t/** 把资源挂成附件,随下一次发送带走。 */\n\t\tattach(attachment: PluginPromptAttachment): void;\n\t\t/**\n\t\t * 往草稿里插一段文本。始终是插入而非替换,免得抹掉用户已经打的内容。\n\t\t *\n\t\t * `position` 缺省为 `\"end\"`(光标处)。`\"start\"` 插到最前面,适合「先定题、细节\n\t\t * 由用户补」这类写法——用户点完多半光标并不在开头,位置只能由调用方定死。\n\t\t */\n\t\tinsertText(text: string, options?: { position?: \"start\" | \"end\" }): void;\n\t};\n}\n\n/**\n * 新会话页输入框下方的一块内容(`ui.slot.new-session-context`)。\n *\n * 与 input-action 的分工:那是发送前的开关,这是发送前的**上下文**——把用户接下来多半\n * 要用到的素材摆出来。激活与否由宿主按 {@link PluginNewSessionContextActivation} 裁决,\n * 插件只负责在被激活后渲染,因此拿不到用户逐键输入的全程内容。\n *\n * 同时有多个贡献上屏时,宿主会在该区域顶部出 tabbar;只有一个时直接渲染内容。\n */\nexport interface PluginNewSessionContextContribution {\n\tid: string;\n\t/** tabbar 上的标题;只有一个贡献上屏时不展示。 */\n\tlabel: string;\n\t/** tab 图标;省略时用插件自己的图标。 */\n\ticon?: ReactNode;\n\tactivateWhen: PluginNewSessionContextActivation;\n\t/**\n\t * 横向占位。`\"input\"`(默认)与输入框同宽,适合补充说明一类的窄内容;`\"wide\"` 铺满\n\t * 页面可用宽度,留给画廊、素材墙这类「内容本身就是主角」的东西——把它们压在输入框\n\t * 宽度里,每一项都会小到看不清。\n\t */\n\twidth?: \"input\" | \"wide\";\n\trender(context: PluginNewSessionContext): ReactNode;\n}\n\n/**\n * 顶栏动作的下拉菜单项。点击一项执行 `onSelect` 并关闭菜单(`checkbox` / `radio` 例外,见\n * {@link PluginHeaderActionMenuItemKind})。\n */\n/**\n * 菜单项的类型。省略即普通命令项;其余类型让「列表就是状态」的场景(分支列表、开关、\n * 加载中、空态)不必退化成纯文字:\n * - `checkbox` / `radio`:`checked` 决定勾选标记,点它触发 `onSelect` 后菜单不自动关(适合切换开关);\n * - `label`:分组标题,不可点;\n * - `loading` / `empty`:占位行,自动禁用、不可点;\n * - `submenu`:`children` 是下一级菜单项(只支持一层)。\n */\nexport type PluginHeaderActionMenuItemKind =\n\t| \"item\"\n\t| \"checkbox\"\n\t| \"radio\"\n\t| \"label\"\n\t| \"loading\"\n\t| \"empty\"\n\t| \"submenu\";\n\nexport interface PluginHeaderActionMenuItem {\n\t/** 项在菜单内唯一的 id。 */\n\tid: string;\n\t/** 默认 `item`。 */\n\tkind?: PluginHeaderActionMenuItemKind;\n\tlabel: string;\n\t/** 菜单项前的图标,16px 方框内显示。`checkbox` / `radio` 已选中时换成勾选标记。 */\n\ticon?: ReactNode;\n\t/** `submenu` 且给了 `children` 时可省略。 */\n\tonSelect?: () => void;\n\t/** `submenu` 的下一级菜单项。 */\n\tchildren?: readonly PluginHeaderActionMenuItem[];\n\t/** `checkbox` / `radio` 是否已选中。 */\n\tchecked?: boolean;\n\tdisabled?: boolean;\n\t/** 禁用原因:禁用时排在 `title` 之前显示,用户才知道为什么点不了。 */\n\tdisabledReason?: string;\n\t/** 危险操作(红色)。 */\n\tdestructive?: boolean;\n\t/** 在这一项之前画一条分隔线。 */\n\tseparatorBefore?: boolean;\n}\n\n/** 顶栏动作气泡里的内容组件拿到的 props。 */\nexport interface PluginHeaderActionPopoverProps {\n\t/** 关闭气泡(例如内容里点了「完成」)。 */\n\tclose: () => void;\n}\n\n/** 角标与图标的语义色,跟随宿主主题;`neutral` 为默认。 */\nexport type PluginHeaderActionTone = \"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\";\n\n/** 气泡尺寸:`sm` 约 16rem,`md`(默认)约 24rem,`lg` 约 32rem。 */\nexport type PluginHeaderActionPopoverSize = \"sm\" | \"md\" | \"lg\";\n\n/**\n * 气泡的容器形态。默认 `popover`(贴着按钮的小浮层);内容是有输入框、列表等需要专注的界面时\n * 用 `dialog`(宿主居中对话框,带标题栏与关闭按钮,宽度由 `size` 决定)。\n */\nexport type PluginHeaderActionPopoverHost = \"popover\" | \"dialog\";\n\n/** 气泡声明:直接给组件,或给组件加容器参数。 */\nexport type PluginHeaderActionPopover =\n\t| ComponentType<PluginHeaderActionPopoverProps>\n\t| {\n\t\t\tcomponent: ComponentType<PluginHeaderActionPopoverProps>;\n\t\t\tsize?: PluginHeaderActionPopoverSize;\n\t\t\thost?: PluginHeaderActionPopoverHost;\n\t\t\ttitle?: string;\n\t };\n\n/** 顶栏动作此刻能拿到的上下文:它在哪个页面、当前工作目录是什么。 */\nexport interface PluginHeaderActionContext {\n\t/**\n\t * 当前页面。`conversation` = 会话页;`new-session` = 新会话页(还没有消息,\n\t * 顶栏只有置顶与活动面板开关)。\n\t */\n\tsurface: PluginHeaderActionSurface;\n\t/** 当前工作目录;没有项目(例如空白新会话)时为 `null`。 */\n\tcwd: string | null;\n}\n\n/** 顶栏动作可以出现的页面。 */\nexport type PluginHeaderActionSurface = \"conversation\" | \"new-session\";\n\n/**\n * 顶栏动作此刻的**声明**,由 {@link PluginHeaderActionContribution.useAction} 返回。\n *\n * 宿主用它统一渲染成与内置按钮完全一致的一格;插件能决定的只有下面这些字段,没有 `className`、\n * `style`,也无法替换按钮本身。默认**只有图标**,名称靠悬浮提示(`title`)显示;需要把状态\n * 写在脸上时用 `label`(宽屏才显示,窄了自动退回图标)。\n * `click` / `menuItems` / `popover` **三选一**:\n * 同时给多个时按 `menuItems` > `popover` > `onClick` 取第一个;一个都没有则该动作不显示。\n *\n * 宿主会校验并截断:`title` 最长 40 字、`label` 最长 24 字(超出截断),`menuItems` 最多\n * 20 项,`badge` 只接受数字(≥ 1,超过 99 显示 `99+`)或 `true`(红点)。\n */\nexport interface PluginHeaderActionState {\n\t/** 必填。悬浮提示、无障碍名称(按钮上不显示文字时,用户全靠它认出这个动作)。 */\n\ttitle: string;\n\t/**\n\t * 必填。图标节点,宿主放进 16px 的固定方框里并忽略指针事件,建议直接用\n\t * iconify 的 `<span className=\"icon-[solar--…]\" />`。\n\t */\n\ticon: ReactNode;\n\t/**\n\t * 图标右侧的文字,用于「状态本身就是文字」的动作(分支名、当前模型、同步落后数)。\n\t * 最长 24 字;顶栏有位置时显示,被收纳、页头挤窄、顶栏超过 4 格时自动退回纯图标\n\t * (`labelRole: \"readout\"` 不受 4 格限制,见下)。\n\t */\n\tlabel?: string;\n\t/**\n\t * 文字的角色。默认 `\"caption\"`:文字是按钮名称的补充,顶栏超过 4 格时收起。\n\t * `\"readout\"`:文字就是要展示的、随时间变化的状态值(如 `≈123 tok/s`),顶栏超过 4 格时仍显示,\n\t * 被 `promoteWhenActive` 露出时也显示;被收纳或页头挤窄时照样只剩图标,所以读数仍要写进 `title`。\n\t * 只给读数用,命令名称不要标成 readout。Plugin API `^2.13.0`;旧宿主忽略此字段,表现与 `\"caption\"` 相同。\n\t */\n\tlabelRole?: \"caption\" | \"readout\";\n\t/** 角标:数字显示计数,`true` 显示红点。被收纳时宿主会把它汇总到收纳入口上。 */\n\tbadge?: number | boolean;\n\t/** 角标与图标的语义色,默认 `neutral`(灰色数字 / 本色图标)。 */\n\ttone?: PluginHeaderActionTone;\n\t/** 选中态(例如面板已打开)。 */\n\tactive?: boolean;\n\tdisabled?: boolean;\n\t/** 禁用原因:禁用时替代 `title` 显示,用户才知道为什么点不了。 */\n\tdisabledReason?: string;\n\t/**\n\t * 处于选中态时,即使被收纳也要在活动面板开关左侧露出来(例如「正在录制」这类必须可见的状态)。\n\t * 只在顶栏有活动面板开关的页面上生效。\n\t */\n\tpromoteWhenActive?: boolean;\n\t/** 点击直接执行。 */\n\tonClick?: () => void;\n\t/** 点击向下弹出下拉菜单。 */\n\tmenuItems?: readonly PluginHeaderActionMenuItem[];\n\t/**\n\t * 点击弹出气泡,内容是你自己的组件。气泡的背景、圆角、投影由宿主固定,宽高随内容自适应;\n\t * 被收纳时它会在收纳托盘里**内联展开**(宽约 260px),内容请能在这个宽度下正常显示。\n\t */\n\tpopover?: PluginHeaderActionPopover;\n}\n\n/**\n * 会话页与新会话页顶栏右侧按钮组里的一格(`ui.slot.header-action`)。\n *\n * 顶栏右侧是**宿主统一管理的一个按钮组**:内置按钮(导出 / 置顶 / 终端 / 底部面板)与所有插件\n * 贡献排在同一组里,外观由宿主决定,插件不能自定义样式。显示规则:\n * - 顶栏最多显示 7 格(不含最右侧固定的「活动面板」开关),内置与插件共用这 7 个名额;\n * - 超出的、以及用户主动收起的动作进入「收纳」托盘(悬浮在按钮组上时,组下方出现的小白条);\n * - 用户可以在托盘里拖动调整顺序、决定哪些在顶栏哪些收纳,这份布局按动作 id 记在本机;\n * - 新装插件的动作:顶栏还有空位就排进去,否则进收纳,不会挤走用户已有的布局;\n * - `pin: \"prefer\"` 只是「用户没调整过时优先上栏」的建议,仍然用户可以改、也不突破 7 格上限。\n * 所以插件**不能**假定自己一定在顶栏上,也不能依赖相邻的是谁。\n *\n * 出现页面由 `surfaces` 决定,默认只有会话页。\n */\nexport interface PluginHeaderActionContribution {\n\t/** 贡献 id,在本插件内唯一,最长 64 字符。用户的布局按 `${插件 id}:${id}` 记忆,请不要随意改名。 */\n\tid: string;\n\t/**\n\t * 默认排序权重,小的靠左。**只影响用户还没自己调整过时的初始位置**,省略按注册顺序排在最后;\n\t * 同值按插件 id、贡献 id 稳定排序。\n\t */\n\torder?: number;\n\t/** 出现在哪些页面,默认 `[\"conversation\"]`。 */\n\tsurfaces?: readonly PluginHeaderActionSurface[];\n\t/**\n\t * 初始布局建议。`\"prefer\"` 表示用户没调整过布局时优先占用顶栏的一个名额\n\t * (仍受 7 格上限与用户后来的调整约束);默认 `\"normal\"`,即先待在收纳托盘里。\n\t */\n\tpin?: \"normal\" | \"prefer\";\n\t/**\n\t * 返回动作此刻的声明,返回 `null` 表示当前不适用(例如没有项目目录),宿主不显示也不占位。\n\t *\n\t * 这是一个 **React hook**:宿主在对应页面顶栏挂载期间一直调用它,所以可以在里面用任意 hook\n\t * (`useActiveConversation()`、`useTranslation()`、你自己的 store……),数据变化时自然重新声明。\n\t * 入参给出当前页面与工作目录,可以据此决定是否出现、显示什么。\n\t * 约束:\n\t * - 渲染期必须是纯计算,不要在里面发请求、起定时器;这类副作用放进 `useEffect`;\n\t * - 抛错只会让这一项消失(错误边界隔离),不会影响其它动作;\n\t * - 每次渲染都可以返回新对象,宿主不依赖引用相等。\n\t */\n\tuseAction: (context: PluginHeaderActionContext) => PluginHeaderActionState | null;\n}\n\n/**\n * 宿主左侧侧边栏此刻的形态。给插件自适应布局用——尤其是沉浸式工作区视图:\n * 侧边栏收起时宿主页头会长出「展开侧边栏」按钮并占住左上角,视图自己画在那一带的\n * 东西需要让位。\n */\nexport interface PluginSidebarState {\n\t/** 用户手动收起了侧边栏。窄屏下这一位仍然只反映用户意愿,不受窗口宽度影响。 */\n\tcollapsed: boolean;\n\t/** 窗口窄到侧边栏改走悬浮覆盖,不再占据左侧一栏。 */\n\tnarrow: boolean;\n\t/** 侧边栏此刻是否实际占着左边那一栏。等价于 `!collapsed && !narrow`,多数自适应只需要这一位。 */\n\tvisible: boolean;\n}\n\nexport interface PluginUiApi {\n\tregisterGlobalSlot(contribution: PluginGlobalSlotContribution): Disposable;\n\tregisterAbilityDetailSlot(contribution: PluginAbilityDetailSlotContribution): Disposable;\n\t/** Render an opaque setup URL as a host-themed PNG data URL. */\n\tcreateQrCode(text: string): Promise<string>;\n\t/**\n\t * Register a **workspace view**(工作区视图)— a full-page surface with its own\n\t * route and sidebar entry, on par with the host's built-in pages. Needs the\n\t * `ui.slot.workspace-view` permission (missing permission = **warn+noop**).\n\t *\n\t * The entry lands in the sidebar's「更多」收纳 by default; the user can pin it\n\t * to the top region or reorder it, and that layout is remembered.\n\t */\n\tregisterWorkspaceView(contribution: PluginWorkspaceViewContribution): Disposable;\n\t/**\n\t * Register a **new-session context block** — content shown beneath the input\n\t * on the new-session page, surfaced only when the user's current selection or\n\t * draft matches {@link PluginNewSessionContextActivation}. Needs the\n\t * `ui.slot.new-session-context` permission (missing permission = **warn+noop**).\n\t */\n\tregisterNewSessionContext(contribution: PluginNewSessionContextContribution): Disposable;\n\t/**\n\t * Register a **header action** — one declarative slot in the conversation\n\t * page header's host-managed button group (icon / badge plus a click,\n\t * menu or popover; no custom styling — see\n\t * {@link PluginHeaderActionContribution}). The user decides, via the group's\n\t * overflow tray, which actions sit in the header (max 7 shared with the host's\n\t * own buttons) and in what order. Needs the `ui.slot.header-action`\n\t * permission (missing permission = **warn+noop**) and Plugin API `^2.9.0`.\n\t */\n\tregisterHeaderAction(contribution: PluginHeaderActionContribution): Disposable;\n\t/**\n\t * Navigate to one of this plugin's own workspace views. `viewId` is the\n\t * contribution id passed to {@link PluginUiApi.registerWorkspaceView}. No-op\n\t * when the view is not registered (e.g. permission missing).\n\t */\n\topenWorkspaceView(viewId: string): void;\n\t/**\n\t * Update (or clear, with `null`) the badge on one of this plugin's workspace\n\t * view entries. Re-registering the view is NOT a way to do this — it would\n\t * remount the whole surface — so live badges (unread counts, status dots)\n\t * must come through here.\n\t *\n\t * No-op when the view is not registered (e.g. permission missing).\n\t */\n\tsetWorkspaceViewBadge(viewId: string, badge: PluginNavBadge | null): void;\n\t/**\n\t * Fill (or clear, with `null`) the host page header while one of this\n\t * plugin's workspace views is open. Call it from the view component (an\n\t * effect that re-runs on state change) and clear it on unmount — the host\n\t * keeps the entry keyed by view, and only applies it on that view's route.\n\t *\n\t * The header itself is never removed: it owns the window drag region and the\n\t * macOS traffic-light gutter. This is how a view takes it over instead.\n\t *\n\t * No-op when the view is not registered (e.g. permission missing).\n\t */\n\tsetWorkspaceViewHeader(viewId: string, header: PluginWorkspaceViewHeader | null): void;\n\t/**\n\t * Register a preview component keyed by file extension. The host dispatches\n\t * registered extensions before its built-in fallback renderers; first\n\t * registrant wins on conflict.\n\t */\n\tregisterFilePreview(contribution: PluginFilePreviewContribution): Disposable;\n\t/**\n\t * Register an activity-panel tab into the addable pool. The user attaches\n\t * it manually via the panel's \"+\" picker; attach records are keyed by the\n\t * workspace cwd. A contribution that declares `useMeta` decides its own\n\t * availability per workspace (see {@link PluginActivityTabContribution.useMeta}).\n\t */\n\tregisterActivityTab(contribution: PluginActivityTabContribution): Disposable;\n\t/**\n\t * Register a component into the session's bottom panel addable pool. The user\n\t * opens instances from the panel's \"+\" menu; one contribution can have several\n\t * instances in the same session, and each instance renames itself through\n\t * {@link useBottomPanel}.\n\t */\n\tregisterBottomPanel(contribution: PluginBottomPanelContribution): Disposable;\n\t/**\n\t * Register a toggle action shown beneath the AI input bar. While active,\n\t * its `decoratePrompt()` annotates the next outgoing prompt.\n\t */\n\tregisterInputAction(contribution: PluginInputActionContribution): Disposable;\n\t/**\n\t * Register a card renderer keyed by `type`. Cards rendered beneath a message\n\t * come from tool results' out-of-band `details.cards` (or `pendingFor` for\n\t * in-flight tools); the host resolves each card's `type` to a registered\n\t * renderer. Multiple cards under one message are shown as a tab-switcher\n\t * (\"收纳\") or a flat list.\n\t */\n\tregisterCardRenderer(contribution: PluginCardRendererContribution): Disposable;\n\t/**\n\t * Register a renderer that replaces the host's default inline transcript UI\n\t * for a tool call (matched by `toolName`). The complement to card renderers:\n\t * use it to render UI for a plugin's own agent tool output.\n\t */\n\tregisterToolCallSlot(contribution: PluginToolCallSlotContribution): Disposable;\n\t/**\n\t * Register a card rendered at the bottom of the message list for the latest\n\t * turn — NOT bound to a tool call. The host mounts the component in the\n\t * footer slot; the plugin owns visibility (return `null` to render nothing,\n\t * e.g. git renders only in a repo with changes). Gated by `scope_use`\n\t * (fail-closed). Needs the `ui.slot.turn-card` permission.\n\t */\n\tregisterTurnCard(contribution: PluginTurnCardContribution): Disposable;\n\t/**\n\t * Register a keyboard shortcut scope on the host's shared ShortcutScopeStack\n\t * (same path as host UI: modal > overlay > surface > app). Needs\n\t * `ui.shortcuts.register`. Plugins cannot use kind `\"app\"` (reserved for\n\t * host-configurable global actions). Prefer {@link usePluginShortcutScope}\n\t * from React components with a module-captured `registerShortcutScope`.\n\t */\n\tregisterShortcutScope(contribution: PluginShortcutScopeContribution): Disposable;\n\t/**\n\t * Programmatically attach (if needed) and activate one of this plugin's\n\t * own activity tabs in a conversation's activity panel. `tabId`\n\t * is the contribution id passed to registerActivityTab. Any payload (e.g.\n\t * which image to edit) is passed via the plugin's own in-memory state.\n\t *\n\t * Pass `options.width` to size the panel as it opens — a pixel number, or\n\t * `\"max\"` to expand it to the widest the current window allows (the host\n\t * still clamps to its min/max and auto-hides the sidebar when needed). Omit\n\t * to leave the user's current width untouched.\n\t *\n\t * Omit `options.cwd` for the conversation currently displayed by the host.\n\t * Tool handlers and background work should pass their session cwd explicitly.\n\t */\n\topenActivityTab(tabId: string, options?: PluginOpenActivityTabOptions): void;\n\t/**\n\t * 把本插件的某个活动面板标签卡在目标会话里上栏 / 下栏,**不激活也不展开\n\t * 面板**——`openActivityTab` 是「用户此刻要看它」,这个是「它现在该不该在\n\t * 栏里」。配合 `initiallyVisible: false` 使用,插件即可完全掌握自己标签卡的\n\t * 出现条件(如 git 只在仓库目录里上栏、工作台跟随输入栏 toggle)。\n\t *\n\t * 上栏记录按会话 cwd 持久化(ADR-0026),所以只需在条件变化时调用一次;\n\t * 用户随后用减号手动隐藏的结果不会被重复调用覆盖。缺省作用于宿主当前显示的\n\t * 会话;工具 handler 与后台任务应通过 `options.cwd` 传入自己的会话 cwd。既没有\n\t * 显式 cwd、也没有活动会话时为 no-op(无处记录)。\n\t */\n\tsetActivityTabVisible(tabId: string, visible: boolean, options?: PluginActivityTabTargetOptions): void;\n\t/**\n\t * 直接设置活动面板宽度:像素值,或 `\"max\"` 表示「跟随窗口拉满」(宿主仍会夹到\n\t * 自己的 min/max 内,必要时自动收起侧边栏)。\n\t *\n\t * `\"max\"` 是一种持续状态而非一次性求值:窗口尺寸变化时面板跟着变宽变窄,直到\n\t * 用户拖动分隔条或有人写入具体像素为止。传数字则是一次性的固定宽度。\n\t *\n\t * 与 `openActivityTab(id, { width })` 的区别:那里的宽度只在「标签卡首次 attach」\n\t * 或「把关着的面板翻开」时生效,且 activate 里的调用除外(避免重放覆盖用户手拖的\n\t * 宽度);这个是命令式的,每次调用都生效,供插件在自己的标签卡被激活、进入某种\n\t * 视图时按需调整。用户随后仍可拖动。\n\t */\n\tsetActivityPanelWidth(width: number | \"max\"): void;\n\t/**\n\t * Bind or clear plugin-owned context for outgoing prompts. The host renders\n\t * its label/icon and carries a structured `context` as a versioned snapshot.\n\t * Attachments default to one-shot; `lifecycle: \"sticky\"` remains until the\n\t * plugin or user clears the capsule.\n\t */\n\tsetPromptAttachment(attachment: PluginPromptAttachment | null): void;\n\t/**\n\t * Open the host's global full-screen image previewer for the given image.\n\t * Only the image reference (id/url) crosses over — bytes stay out-of-band.\n\t *\n\t * Pass `group` (e.g. all images of the message) to open as an image group:\n\t * the previewer shows a thumbnail strip + arrows and starts at `ref`.\n\t */\n\tpreviewImage(ref: PluginImageRef, group?: PluginImageRef[]): void;\n\t/**\n\t * Open the host's global file previewer for any file — the general form of\n\t * {@link PluginUiApi.previewImage}, which only takes image URLs. Accepts a\n\t * local absolute `path` (the shape the host's own file tree uses) as well as\n\t * a `url`; the previewer dispatches by the file's extension, so a file type\n\t * some plugin registered via `registerFilePreview` lands in that renderer.\n\t *\n\t * Pass `group` (e.g. all outputs of one run) to open as a group: images get\n\t * the thumbnail strip + arrows, and the previewer starts at `file`.\n\t *\n\t * Permissions: `fs.read` as soon as any entry carries a `path` (it hands a\n\t * local file to the host to read); `ui.slot.message` for url-only calls,\n\t * same gate as `previewImage`.\n\t */\n\tpreviewFile(file: PluginPreviewFileRef, group?: PluginPreviewFileRef[]): void;\n\t/**\n\t * Capture a rectangle in the current Vetta window and open the host save\n\t * dialog. Coordinates use renderer DIP values such as getBoundingClientRect().\n\t * Requires `ui.slot.activity-tab`.\n\t */\n\tcaptureRegion(rect: PluginCaptureRegion, defaultFileName: string): Promise<string | null>;\n\t/**\n\t * Copy an image to the system clipboard. Takes a `data:image/...;base64,`\n\t * URL and goes through the native clipboard, so it does not depend on the\n\t * renderer's `ClipboardItem` support. No permission required — the plugin\n\t * can only write what it already rendered.\n\t */\n\tcopyImage(dataUrl: string): Promise<void>;\n\t/**\n\t * Hand a URL to the OS default browser (Electron `shell.openExternal`) —\n\t * NOT the in-app browser panel. Only `http:`/`https:` are accepted; the host\n\t * rejects every other protocol, so this cannot be used to launch arbitrary\n\t * schemes. Needs `shell.openExternal`.\n\t */\n\topenExternal(url: string): Promise<void>;\n\t/**\n\t * Show a global toast in the host UI (bottom-right). No permission required.\n\t * Prefer this over swallowing errors into opaque UI copy: pass `error` so\n\t * the host attaches a one-click \"copy stack\" action for the user.\n\t *\n\t * Capture `ctx.ui.notify` in `activate` if React components need it\n\t * (components do not receive `ctx`).\n\t */\n\tnotify(options: PluginNotifyOptions): void;\n\t/**\n\t * 读当前侧边栏形态。无需权限——这是纯布局信息,不含任何用户数据。\n\t *\n\t * React 组件请改用 `useSidebarState()`:它会在状态变化时重渲染,不必自己订阅。\n\t * 这一对只为拿不到 hook 的地方准备(`activate()` 内、工具处理器、命令式绘制的画布)。\n\t */\n\tgetSidebarState(): PluginSidebarState;\n\t/**\n\t * 订阅侧边栏形态变化——用户收起/展开侧边栏、或窗口跨过窄屏阈值时触发。\n\t * 返回 Disposable 取消订阅;请在插件失活时释放。\n\t *\n\t * 回调按值去重:拖窗口不会把它打成回调风暴,只有三元组真的变了才通知。\n\t */\n\tonSidebarStateChanged(listener: (state: PluginSidebarState) => void): Disposable;\n}\n"]}
|
package/docs/README.md
CHANGED
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
| 本轮 Turn 卡 | `ctx.ui.registerTurnCard` | `ui.slot.turn-card` | [ui-slots](./ui-slots.md#本轮-turn-卡-registerturncard) |
|
|
73
73
|
| **键盘快捷键(宿主 scope 栈)** | `ctx.ui.registerShortcutScope` / `usePluginShortcutScope` | `ui.shortcuts.register` | [ui-slots](./ui-slots.md#键盘快捷键-registershortcutscope) |
|
|
74
74
|
| 读对话 / 事件 | hooks + `ctx.conversation.on` | `agent.session.read` | [conversation-and-agent](./conversation-and-agent.md#对话读状态) |
|
|
75
|
+
| 生成指标(tok/s、首字延迟、用量) | `useGenerationMetrics` / `ctx.conversation.onGenerationMetrics` | `agent.session.metrics` | [conversation-and-agent](./conversation-and-agent.md#生成指标) |
|
|
75
76
|
| 驾驶对话 | `ctx.conversation.sendPrompt/insertText/abort` | `agent.session.write` | [conversation-and-agent](./conversation-and-agent.md#对话驾驶) |
|
|
76
77
|
| 注册 Agent 工具 | `ctx.agent.registerTool` | `agent.tools.register` + `execute` | [conversation-and-agent](./conversation-and-agent.md#注册-agent-工具) |
|
|
77
78
|
| 注册 Coding Agent Hook | `ctx.agent.registerHook` | `agent.hooks.register` + `agent.hookHandler.execute` | [conversation-and-agent](./conversation-and-agent.md#注册-coding-agent-hook) |
|
|
@@ -59,6 +59,69 @@ const sub = ctx.conversation.on((event) => {
|
|
|
59
59
|
// 之后:sub.dispose();
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
## 生成指标
|
|
63
|
+
|
|
64
|
+
做 tok/s 读数、首字延迟、本轮用量这类插件时,**不要自己从 `message-updated` 数字符、打时间戳**:那样量到的是事件跨进程、批量派发的节奏,数字会抖,字符换算 token 中英文能差好几倍,而且 `message-updated` 只有正文,思考与工具参数的生成期间什么都收不到。宿主把这些算好了,插件只管展示。
|
|
65
|
+
|
|
66
|
+
- Plugin API:`^2.12.0`。**用 `useGenerationMetrics` 必须声明这一档**:插件运行时 import 的是宿主提供的 SDK 模块,旧宿主上没有这个导出,插件会整个加载失败;声明了 `^2.12.0`,旧宿主给出的才是明确的版本错误
|
|
67
|
+
- 权限:`agent.session.metrics`(只读速度与用量,看不到对话内容);已声明 `agent.session.read` 的插件不用再加
|
|
68
|
+
- 作用于当前活动会话;切会话时读数跟着换,切回来还能看到那个会话上一轮的结算
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { useGenerationMetrics } from "@vetta-org/plugin-sdk";
|
|
72
|
+
|
|
73
|
+
function useSpeedAction() {
|
|
74
|
+
const metrics = useGenerationMetrics();
|
|
75
|
+
if (!metrics.supported || !metrics.call) return null; // 团队会话、没有会话:不显示
|
|
76
|
+
const { recentTokensPerSecond, tokensPerSecond, estimated, status } = metrics.call;
|
|
77
|
+
// 生成中看最近 2 秒(停顿会掉到 0),结束后看整次调用的平均(此时已是真实值)。
|
|
78
|
+
const speed = status === "streaming" ? recentTokensPerSecond : tokensPerSecond;
|
|
79
|
+
const approx = status === "streaming" || estimated ? "≈" : "";
|
|
80
|
+
const text = speed === null ? "—" : `${approx}${speed.toFixed(0)} tok/s`;
|
|
81
|
+
return { title: `生成速度 ${text}`, label: text, active: status === "streaming", /* ... */ };
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
不在 React 里的逻辑用命令式接口。要兼容旧宿主(插件声明低于 `^2.12.0`)也只能走这条:旧宿主上这两个方法是 `undefined`,用前判断:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const snapshot = ctx.conversation.getGenerationMetrics();
|
|
89
|
+
const sub = ctx.conversation.onGenerationMetrics((snapshot) => { /* ... */ }); // 订阅即回放一次
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 快照里有什么
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
interface GenerationMetricsSnapshot {
|
|
96
|
+
supported: boolean; // false:没有活动会话 / 团队会话,其余字段为空
|
|
97
|
+
sampledAt: number; // 这份快照的计算时刻(ms),与其余时间戳同一时钟
|
|
98
|
+
sessionId: string | null; // 与 ConversationState.id 相同
|
|
99
|
+
phase: "idle" | "waiting" | "thinking" | "text" | "tool-args" | "between-calls";
|
|
100
|
+
call: GenerationCallMetrics | null; // 正在进行的模型调用;没有则为最近一次结束的
|
|
101
|
+
turn: GenerationTurnMetrics | null; // 正在进行的轮次;没有则为最近一次结束的
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- **`phase`**:`waiting` 是请求已发出、还没收到第一个增量;`between-calls` 是轮次进行中但模型没在生成(通常是工具在执行)。只有 `thinking` / `text` / `tool-args` 表示正在出字。
|
|
106
|
+
- **`call`**(一次模型调用;一轮里每次工具调用后模型会再被调一次):`status`(`streaming` / `done` / `error` / `aborted`)、`requestedAt` / `firstTokenAt` / `lastTokenAt` / `endedAt`、`timeToFirstTokenMs`、`outputTokens`、`tokensPerSecond`(首字以来的平均)、`recentTokensPerSecond`(最近 2 秒,只在生成中有值)、`estimated`、`usage`(provider 报回的 `input` / `output` / `cacheRead` / `cacheWrite`,生成中或 provider 不报时为 `null`)、`model`(`{ provider, id }`)。
|
|
107
|
+
- **`turn`**(一轮的汇总):`status`(`running` / `completed` / `cancelled` / `failed`)、`modelCalls`、`outputTokens`、`generationMs`、`tokensPerSecond`、`estimated`。
|
|
108
|
+
|
|
109
|
+
### 口径
|
|
110
|
+
|
|
111
|
+
- **时间戳来自运行时**,不是插件收到事件的时刻。
|
|
112
|
+
- **首字延迟** = 首个任何类型的增量(思考、正文、工具参数都算)− 请求发出。宿主没观察到请求发出(例如插件在生成中途才激活)时为 `null`。
|
|
113
|
+
- **生成速度** = 输出 token ÷(结束时刻,生成中为此刻 − 首字)。分母不含排队和首字前的等待;轮次的速度只累加各次调用「首字到结束」,不含工具执行。生成时长不到 250ms 时为 `null`,别显示成几千 tok/s。
|
|
114
|
+
- **近期速度** = 最近 2 秒内的输出 token ÷ 2 秒(首字后不足 2 秒按首字以来算,不足 250ms 为 `null`)。它反映「此刻」的快慢:模型停顿时降到 0,而平均速度只会慢慢往下掉。它始终是估算值,调用结束后为 `null`。实时读数用它,结算用 `tokensPerSecond`。
|
|
115
|
+
- **停顿了多久** = `sampledAt − lastTokenAt`。两者同一时钟,别拿插件自己的 `Date.now()` 去减。
|
|
116
|
+
- **估算与真实值**:生成中 provider 还没报 usage,`outputTokens` 按已收到的字符估算(中日韩文字约一字一 token,其余约四字一 token,并用同一会话上一次调用的真实值校准),`estimated: true`;调用结束后换成 provider 报的真实值。provider 不报 usage(报回 0)时一直保持估算。估算值建议加「≈」或「约」。
|
|
117
|
+
- **输出 token 包含思考**:provider 报的 output 通常含推理 token,速度也按它算。
|
|
118
|
+
|
|
119
|
+
### 刷新频率
|
|
120
|
+
|
|
121
|
+
首字之后、调用结束之前,宿主约每 250ms 推一次(hook 也按这个节奏重渲)。**模型停顿、没有新事件时也照推**,所以近期速度会自己降下来,插件不需要自己开定时器;连续 60 秒没有新增量时停止推送。阶段切换、调用结束、切会话时立即推。等首字阶段(`waiting`)读数不变,不推;要显示「已等待 3.2s」这类计时,请用 `requestedAt` 自己计时。插件**不需要也不应该**节流到更快;需要更慢(比如每秒刷新一次文字)在展示层做即可。
|
|
122
|
+
|
|
123
|
+
团队会话暂不提供指标(`supported: false`)。
|
|
124
|
+
|
|
62
125
|
## 对话:驾驶
|
|
63
126
|
|
|
64
127
|
需要 `agent.session.write`。
|
package/docs/permissions.md
CHANGED
|
@@ -53,6 +53,7 @@ ctx.permissions.require("fs.read"); // 缺则抛 Plugin permission denied: fs.r
|
|
|
53
53
|
| `ui.file-explorer.toolbar` | `ctx.fileExplorer.registerToolbarAction()` | [file-explorer](./file-explorer.md#工具栏动作) |
|
|
54
54
|
| `workspace.read` | 文件列表查询、定位、刷新与事件 | [file-explorer](./file-explorer.md#工作区选择与定位) |
|
|
55
55
|
| `agent.session.read` | `ctx.conversation.on()` + 对话 hook | [conversation-and-agent](./conversation-and-agent.md#对话读状态) |
|
|
56
|
+
| `agent.session.metrics` | `ctx.conversation.getGenerationMetrics()` / `onGenerationMetrics()` + `useGenerationMetrics`(只读速度与用量,看不到对话内容;已有 `agent.session.read` 则无需再声明) | [conversation-and-agent](./conversation-and-agent.md#生成指标) |
|
|
56
57
|
| `agent.session.write` | `sendPrompt` / `insertText` / `abort` | [conversation-and-agent](./conversation-and-agent.md#对话驾驶) |
|
|
57
58
|
| `agent.command.run` | `ctx.command.run` + 清单 `commands` | [conversation-and-agent](./conversation-and-agent.md#命令执行-command) |
|
|
58
59
|
| `agent.command.spawn` | `ctx.command.spawn`(长驻进程)+ 清单 `commands` | [conversation-and-agent](./conversation-and-agent.md#长驻进程-commandspawn) |
|
|
@@ -181,7 +181,7 @@ vettaPluginFederation({
|
|
|
181
181
|
| 组件 | 用途 |
|
|
182
182
|
| --- | --- |
|
|
183
183
|
| `Button` | 按钮。`variant`:`default` / `primary` / `outline` / `secondary` / `ghost` / `destructive` / `link`,以及 **`field`**(设置页里设置项右侧的操作按钮:muted 底、无边框、12px,与下拉 / 输入框同皮);`size`:`xs` / `sm` / `default` / `lg` / `icon-xs` / `icon-sm` / `icon` / `icon-lg` |
|
|
184
|
-
| `ButtonGroup` + `ButtonGroupItem` | **按钮组**:半透明胶囊里并排若干操作按钮,用于悬浮在内容之上的工具条(如页头右上角)。胶囊外缘用内阴影做出玻璃边:只在深色里上沿亮、下沿淡并带投影;浅色没有投影和高亮。没有跟随指针的高光。`ButtonGroup` 属性:`shape`(`"pill"` 胶囊,默认 / `"square"` 圆角方形)、`blur
|
|
184
|
+
| `ButtonGroup` + `ButtonGroupItem` | **按钮组**:半透明胶囊里并排若干操作按钮,用于悬浮在内容之上的工具条(如页头右上角)。胶囊外缘用内阴影做出玻璃边:只在深色里上沿亮、下沿淡并带投影;浅色没有投影和高亮。没有跟随指针的高光。`ButtonGroup` 属性:`shape`(`"pill"` 胶囊,默认 / `"square"` 圆角方形)、`variant`(`"glass"` 默认 / `"flat"` 只留半透明底,不加阴影和模糊 / `"ghost"` 不画容器底和分隔线;需要 Desktop 0.6.23+ 与 `@vetta-org/ui` `^0.1.2`)、`blur`(背景模糊,只对 `glass` 生效,默认开;贴在纯色背景上可关)。`ButtonGroupItem` 属性:`icon`、`label`(不传即纯图标按钮,须配 `title` / `aria-label`)、`badge`(数字计数,超过 99 显示 `99+`;`true` 为小红点;也可传节点)、`active`(选中态,同时设 `aria-pressed`),其余同原生 `button`。选中项两侧的分隔线会自动隐藏 |
|
|
185
185
|
| `SessionTopItem` / `SessionTopGroup` | 宿主内部用的顶栏按钮:`ButtonGroupItem` 外观,点击向下弹出气泡(`popoverContent`)或下拉菜单(`menuItems`)。插件**不用**它来做顶栏动作——`registerHeaderAction` 是声明式的,宿主统一渲染并管理收纳与排序,详见 [ui-slots](./ui-slots.md#会话页顶栏动作-registerheaderaction);它仍可用于你自己页面里的同款按钮 |
|
|
186
186
|
| `DropdownMenu*` | 菜单(`DropdownMenuTrigger` / `Content` / `Item` / `Separator` / `RadioGroup` / `Sub` …) |
|
|
187
187
|
| `Select*`、`SELECT_TRIGGER_CLASS`、`SELECT_PANEL_CLASS` | 下拉选择(Radix);后两个常量是设置页下拉的触发器 / 面板皮肤,自拼触发器时用 |
|
|
@@ -238,6 +238,7 @@ vettaPluginFederation({
|
|
|
238
238
|
| `SettingSection` | 设置分组卡片:可选标题 / 说明 + 圆角边框容器。`section` 传 `{ id, title? }`,`id` 用作锚点 |
|
|
239
239
|
| `SettingRow` | 分组卡片里的一行设置项卡片:左侧 `title` / `description`,右侧放控件(`children`);`border={false}` 去掉底部分隔线(最后一行) |
|
|
240
240
|
| `SettingHeading` | 与分组同款的 15px 小节标题。**必填 `section={{ id, title? }}`**(与 `SettingSection` 同形):只传 `title` 会在渲染期读 `section.id` 而抛错 |
|
|
241
|
+
| `SegmentedControl` | **分段控件**:胶囊里并排若干互斥选项,选中项带滑动指示器(弹簧动画),与宿主设置页、能力页同一套。`items` 传 `{ key, label, icon?, count?, badge? }[]`(`count` 是跟在标题后的灰字计数,0 不显示;`badge` 是红色未读徽标)、`value` / `onChange` 受控,泛型推断 `key` 联合类型;`className` 加在容器上,`suppressLayoutAnimation` 在容器尺寸动画期间关掉指示器滑动以免抖动。需要 Desktop 0.6.21+ 与 `@vetta-org/theme-ui` `^0.2.0` |
|
|
241
242
|
| `VettaKbd` | **快捷键键帽**:`keys` 传快捷键串(`"mod+shift+k"`)或键位数组,渲染成一组浮雕键帽,与设置页快捷键、应用快照的键盘预览同一套质感。`mod` 在 macOS 显示 ⌘、Windows 显示 Ctrl;`ctrl` 始终是物理 Control 键(mac 上 ⌃);需要完全分系统时把该项写成 `{ mac, windows, linux }`。另有 `size`(`xs` 默认 / `sm`)、`separator`(键之间显示 `+`)、`platform`(强制平台,缺省按窗口判断)。键帽整体带读屏文案(「⌘ K」读作「Command K」) |
|
|
242
243
|
|
|
243
244
|
```tsx
|
package/docs/ui-slots.md
CHANGED
|
@@ -739,7 +739,7 @@ interface PluginNewSessionContext {
|
|
|
739
739
|
|
|
740
740
|
- 权限:`ui.slot.header-action`(缺权限 = warn + noop)
|
|
741
741
|
- 需要 Plugin API `^2.9.0`;`label` / `tone` / `disabledReason` / `promoteWhenActive`、菜单项类型、
|
|
742
|
-
气泡尺寸与 `dialog` 容器、`surfaces`、`pin` 需要 `^2.11.0`
|
|
742
|
+
气泡尺寸与 `dialog` 容器、`surfaces`、`pin` 需要 `^2.11.0`;`labelRole` 需要 `^2.13.0`
|
|
743
743
|
- 出现在会话页与新会话页(由 `surfaces` 决定)
|
|
744
744
|
|
|
745
745
|
### 它是声明式的:你只决定「是什么」,不决定「长什么样」
|
|
@@ -751,6 +751,7 @@ interface PluginNewSessionContext {
|
|
|
751
751
|
| `title`(必填) | 悬浮提示与无障碍名称。**默认按钮上没有文字**,用户靠图标 + 这条提示认出它;最长 40 字,超出截断 |
|
|
752
752
|
| `icon`(必填) | 图标节点。宿主放进 16px 固定方框、忽略指针事件,建议用 iconify:`<span className="icon-[solar--folder-linear]" />` |
|
|
753
753
|
| `label` | 图标右侧的文字(最长 24 字)。给「状态本身就是文字」的动作用,比如分支名、落后几个提交。只在顶栏上、且顶栏不超过 4 格、页头不拥挤时显示;被收纳或挤窄时自动退回纯图标 |
|
|
754
|
+
| `labelRole` | `"caption"`(默认)/ `"readout"`。标成 `readout` 表示文字就是随时间变化的状态值(tok/s、费用、上下文占用),顶栏超过 4 格时仍显示,被 `promoteWhenActive` 露出时也显示;收纳与挤窄时照样只剩图标。**只给读数用**,把命令名称标成读数会挤占顶栏,用户会把你收起来 |
|
|
754
755
|
| `badge` | 数字(≥ 1,超过 99 显示 `99+`)或 `true`(红点);其它值被忽略 |
|
|
755
756
|
| `tone` | `neutral`(默认)/ `info` / `success` / `warning` / `danger`,作用于角标与图标颜色。**别把所有数字都染成红色**:红色留给真正需要人处理的状态(冲突、失败) |
|
|
756
757
|
| `active` / `disabled` | 选中态 / 禁用态 |
|
|
@@ -863,6 +864,8 @@ function useStatus({ cwd }) {
|
|
|
863
864
|
|
|
864
865
|
所以:不要依赖自己在顶栏上的位置,不要依赖相邻的是谁,也不要在文案里写「左边的按钮」。
|
|
865
866
|
|
|
867
|
+
**状态读数(tok/s、费用、上下文占用这类)**:给 `label` 配上 `labelRole: "readout"`,顶栏超过 4 格时读数也不会收起(宿主用等宽数字渲染,数字变化时按钮不抖)。读数没有个数限制,顶栏真放不下时整排收进「更多」,由用户自己决定收起哪些。被收纳或挤窄时仍只剩图标,所以读数要同时写进 `title`(悬浮提示和「更多」菜单里看得到),需要细节的放进 `popover`;想默认就被看见再加 `pin: "prefer"`。旧宿主(低于 2.13.0)忽略 `labelRole`,读数按普通文字处理。生成速度的数据源见 [生成指标](./conversation-and-agent.md#生成指标)。
|
|
868
|
+
|
|
866
869
|
官方示例:`packages/plugins/presets/open-in-app`(最小动作)与 `packages/plugins/presets/git`(状态 + 快捷操作气泡)。
|
|
867
870
|
|
|
868
871
|
## 工具行内渲染 registerToolCallSlot
|