@vetta-org/plugin-sdk 0.0.2 → 0.0.4

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.
Files changed (77) hide show
  1. package/dist/activity-tab.d.ts +18 -0
  2. package/dist/activity-tab.d.ts.map +1 -0
  3. package/dist/activity-tab.js +12 -0
  4. package/dist/activity-tab.js.map +1 -0
  5. package/dist/agent.d.ts +206 -0
  6. package/dist/agent.d.ts.map +1 -0
  7. package/dist/agent.js +2 -0
  8. package/dist/agent.js.map +1 -0
  9. package/dist/app-actions.d.ts +63 -0
  10. package/dist/app-actions.d.ts.map +1 -0
  11. package/dist/app-actions.js +12 -0
  12. package/dist/app-actions.js.map +1 -0
  13. package/dist/command.d.ts +25 -0
  14. package/dist/command.d.ts.map +1 -0
  15. package/dist/command.js +2 -0
  16. package/dist/command.js.map +1 -0
  17. package/dist/context.d.ts +45 -0
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +4 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/conversation.d.ts +50 -0
  22. package/dist/conversation.d.ts.map +1 -0
  23. package/dist/conversation.js +2 -0
  24. package/dist/conversation.js.map +1 -0
  25. package/dist/disposable.d.ts +4 -0
  26. package/dist/disposable.d.ts.map +1 -0
  27. package/dist/disposable.js +2 -0
  28. package/dist/disposable.js.map +1 -0
  29. package/dist/fs.d.ts +34 -0
  30. package/dist/fs.d.ts.map +1 -0
  31. package/dist/fs.js +2 -0
  32. package/dist/fs.js.map +1 -0
  33. package/dist/hooks.d.ts +39 -0
  34. package/dist/hooks.d.ts.map +1 -0
  35. package/dist/hooks.js +41 -0
  36. package/dist/hooks.js.map +1 -0
  37. package/dist/host-bridge.d.ts +14 -0
  38. package/dist/host-bridge.d.ts.map +1 -0
  39. package/dist/host-bridge.js +12 -0
  40. package/dist/host-bridge.js.map +1 -0
  41. package/dist/i18n.d.ts +35 -0
  42. package/dist/i18n.d.ts.map +1 -0
  43. package/dist/i18n.js +29 -0
  44. package/dist/i18n.js.map +1 -0
  45. package/dist/images.d.ts +58 -0
  46. package/dist/images.d.ts.map +1 -0
  47. package/dist/images.js +2 -0
  48. package/dist/images.js.map +1 -0
  49. package/dist/index.d.ts +29 -885
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +12 -88
  52. package/dist/index.js.map +1 -1
  53. package/dist/manifest.d.ts +57 -0
  54. package/dist/manifest.d.ts.map +1 -0
  55. package/dist/manifest.js +2 -0
  56. package/dist/manifest.js.map +1 -0
  57. package/dist/official.d.ts +520 -0
  58. package/dist/official.d.ts.map +1 -0
  59. package/dist/official.js +2 -0
  60. package/dist/official.js.map +1 -0
  61. package/dist/permissions.d.ts +2 -0
  62. package/dist/permissions.d.ts.map +1 -0
  63. package/dist/permissions.js +2 -0
  64. package/dist/permissions.js.map +1 -0
  65. package/dist/scenario.d.ts +9 -0
  66. package/dist/scenario.d.ts.map +1 -0
  67. package/dist/scenario.js +2 -0
  68. package/dist/scenario.js.map +1 -0
  69. package/dist/settings.d.ts +13 -0
  70. package/dist/settings.d.ts.map +1 -0
  71. package/dist/settings.js +2 -0
  72. package/dist/settings.js.map +1 -0
  73. package/dist/ui.d.ts +338 -0
  74. package/dist/ui.d.ts.map +1 -0
  75. package/dist/ui.js +2 -0
  76. package/dist/ui.js.map +1 -0
  77. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,888 +1,32 @@
1
- import type { ComponentType, ReactNode } from "react";
2
1
  /**
3
- * 对话场景 slug——决定一个工具 / 会话页插槽在哪些类型的会话里激活或可见。
2
+ * @vetta-org/plugin-sdk public surface.
4
3
  *
5
- * 本类型在 plugin-sdk 内本地定义(SDK 零依赖,不引入宿主包),与宿主
6
- * `@vetta/coding-agent` 的 `ConversationScenario` 保持一一对应;任一侧增删场景时两边须同步,
7
- * 否则宿主回传的 scenario 与此 union 不一致会触发编译错误(即为期望的漂移护栏)。
8
- */
9
- export type ConversationScenario = "im-claw" | "conversation" | "project" | "batch" | "automation" | "kb-processing" | "cli";
10
- export type PluginPermission = "ui.slot.global" | "ui.slot.file-preview" | "ui.slot.activity-tab" | "ui.slot.input-action" | "ui.slot.message" | "ui.slot.tool-call" | "ui.slot.turn-card" | "agent.session.read" | "agent.session.write" | "agent.command.run" | "agent.systemPrompt.read" | "agent.systemPrompt.write" | "agent.systemPrompt.fullControl" | "agent.skills.control" | "agent.mcp.control" | "agent.tools.control" | "agent.tools.register" | "agent.toolHandler.execute" | "agent.state.read" | "agent.state.write" | "agent.continuation.register" | "agent.runtime.configure" | "fs.read" | "fs.write" | "network.fetch" | "images.generate" | "settings.read" | "settings.write";
11
- /**
12
- * MCP server config declared inside a plugin (stdio or http). Relative paths in
13
- * stdio `command`/`args`/`cwd` are resolved against the plugin root at contribute time.
14
- */
15
- export type PluginMcpServerConfig = {
16
- type?: "stdio";
17
- command: string;
18
- args?: string[];
19
- env?: Record<string, string>;
20
- cwd?: string;
21
- disabled?: boolean;
22
- autoApprove?: string[];
23
- startupTimeout?: number;
24
- debug?: boolean;
25
- displayName?: string;
26
- description?: string;
27
- } | {
28
- type: "http";
29
- url: string;
30
- headers?: Record<string, string>;
31
- oauthClientId?: string;
32
- oauthDeviceFlow?: boolean;
33
- oauthScopes?: string;
34
- disabled?: boolean;
35
- autoApprove?: string[];
36
- startupTimeout?: number;
37
- debug?: boolean;
38
- displayName?: string;
39
- description?: string;
40
- };
41
- export interface PluginAgentManifest {
42
- systemPrompt?: {
43
- /**
44
- * Plugin-packaged prompt contribution file paths. Main-process aggregation
45
- * resolves these relative to the installed plugin root.
46
- */
47
- promptPaths?: string[];
48
- };
49
- /** Plugin-packaged skill files or directories to add to the agent resource graph. */
50
- skillPaths?: string[];
51
- /**
52
- * Plugin-scoped MCP servers. Either a relative path to `.mcp.json`
53
- * (shape `{ mcpServers: { ... } }`) or an inline map of server configs.
54
- * Requires permission `agent.mcp.control`. Never written into user mcp.json.
55
- */
56
- mcpServers?: string | Record<string, PluginMcpServerConfig>;
57
- /** Declarative tool visibility policy. Names are tool ids after registration. */
58
- toolPolicy?: {
59
- allow?: string[];
60
- deny?: string[];
61
- };
62
- }
63
- export interface Disposable {
64
- dispose(): void;
65
- }
66
- export interface PluginGlobalSlotContribution {
67
- id: string;
68
- component: ComponentType;
69
- }
70
- export interface PluginAudioMetadata {
71
- /** Embedded title; preview renderers should fall back to file.name. */
72
- title?: string;
73
- artist?: string;
74
- /** Embedded cover art as a Data URL when available. */
75
- coverDataUrl?: string;
76
- }
77
- export interface PluginPreviewUrlOptions {
78
- /** Optional media hint for ambiguous containers such as webm. */
79
- mediaKind?: "audio" | "video";
80
- }
81
- /**
82
- * The file handed to a file-preview plugin component. The host does NOT
83
- * pre-read or guess encoding — the plugin decides whether to read text or
84
- * bytes. `path` is also exposed for plugins that prefer native fetch.
85
- */
86
- export interface PluginPreviewFile {
87
- path: string | null;
88
- name: string;
89
- extension: string;
90
- mime: string;
91
- size: number;
92
- /** Read the file as a UTF-8 string. */
93
- readText(): Promise<string>;
94
- /** Read the raw file bytes. */
95
- readBytes(): Promise<ArrayBuffer>;
96
- /** A fetchable streaming URL for the file (Range-capable). */
97
- getUrl(options?: PluginPreviewUrlOptions): string;
98
- /**
99
- * Subscribe to on-disk changes of this file. The listener fires (debounced
100
- * by the host) whenever the file's contents change, letting previews update
101
- * live. Returns a Disposable; call dispose() to stop watching. A no-op for
102
- * files without a real path (url-only sources).
103
- */
104
- watch(listener: () => void): Disposable;
105
- /**
106
- * Host-provided audio metadata for local media files. Returns null when the
107
- * host cannot provide metadata, e.g. url-only sources or unsupported files.
108
- */
109
- getAudioMetadata?(): Promise<PluginAudioMetadata | null>;
110
- }
111
- export interface PluginFilePreviewProps {
112
- file: PluginPreviewFile;
113
- }
114
- export interface PluginFilePreviewContribution {
115
- /** Lower-case extensions without the dot, e.g. ["svg"]. */
116
- extensions: string[];
117
- component: ComponentType<PluginFilePreviewProps>;
118
- }
119
- /**
120
- * An activity-panel tab contributed by a plugin. Registering only adds the
121
- * tab to the "addable pool" — it renders only after the user attaches it in
122
- * the activity panel (scoped by session cwd).
123
- */
124
- export interface PluginActivityTabContribution {
125
- id: string;
126
- label: string;
127
- /** Tab icon as a React node (not an iconify class string). */
128
- icon?: ReactNode;
129
- component: ComponentType;
130
- /**
131
- * 允许该标签卡出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:
132
- * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如
133
- * `["project", "conversation"]`)。会话页插槽据此随对话类型显隐。
134
- */
135
- scope_use?: readonly ConversationScenario[];
136
- }
137
- /** Options for {@link PluginUiApi.openActivityTab}. */
138
- export interface PluginOpenActivityTabOptions {
139
- /**
140
- * Desired panel width as it opens: a pixel number, or `"max"` for the widest
141
- * the current window allows. The host clamps to its min/max bounds. Omit to
142
- * keep the user's current width.
143
- */
144
- width?: number | "max";
145
- }
146
- /**
147
- * A reference to an image produced out-of-band by the host (e.g. an image
148
- * tool's result). The bytes are NOT carried inline — `url` is a host media
149
- * URL (Range-capable, usable directly as an `<img src>`).
150
- */
151
- export interface PluginImageRef {
152
- id: string;
153
- url: string;
154
- mimeType?: string;
155
- /**
156
- * The edit-lineage root id this image belongs to (base image + all its edits
157
- * share one rootId). Lets the host dedup per-message previews — only the
158
- * latest message producing a given rootId renders the version swiper.
159
- */
160
- rootId?: string;
161
- }
162
- /**
163
- * Decoration a plugin contributes to the next outgoing prompt while its input
164
- * action is active. `metadata` is shallow-merged into the prompt request's
165
- * `metadata` bag, which the agent turn can read (e.g. `{ imageMode: true }`).
166
- */
167
- export interface PluginPromptDecoration {
168
- metadata?: Record<string, unknown>;
169
- }
170
- /**
171
- * An action button shown in a row beneath the AI input bar. Rendered as a
172
- * toggle: clicking activates, clicking again deactivates. While active, the
173
- * host calls `decoratePrompt()` before each send and merges the returned
174
- * metadata into the outgoing prompt request. The plugin owns any side state
175
- * (it is the same Module Federation instance as its other slots).
176
- */
177
- export interface PluginInputActionContribution {
178
- id: string;
179
- label: string;
180
- /** Button icon as a React node (not an iconify class string). */
181
- icon?: ReactNode;
182
- /** Whether the action begins in the active state. Defaults to false. */
183
- defaultActive?: boolean;
184
- /**
185
- * 该输入动作所依赖的 agent 工具名。设置后,仅当该工具在当前会话处于激活(按工具的
186
- * scope_use 解析)时才显示这个 badge——避免在工具被场景屏蔽(如批量任务)时仍显示一个
187
- * 点了也无效的开关。不设则始终显示。例如「图像生成」设为 "generate_image"。
188
- */
189
- requiresActiveTool?: string;
190
- /**
191
- * 允许该 toggle 出现的对话场景 slug 列表(镜像工具的 scope_use)。**fail-closed**:
192
- * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现。与 `requiresActiveTool`
193
- * 取「与」:两者都满足才显示。
194
- */
195
- scope_use?: readonly ConversationScenario[];
196
- /**
197
- * When true, this plugin's agent contributions (tools / skills / MCP /
198
- * systemPrompt) and Activity Tabs are hard-isolated: inactive until this
199
- * toggle is on (ADR-0041, knowledgeMode-style). Default false.
200
- */
201
- hardIsolation?: boolean;
202
- /**
203
- * Fired when the user toggles the action; `active` is the new state. Return
204
- * `false` when `active` is true to VETO the activation (e.g. the plugin needs
205
- * configuration first) — the toggle stays off. Deactivation can't be vetoed.
206
- */
207
- onToggle?(active: boolean): boolean | void;
208
- /**
209
- * Called by the host before sending while the action is active. The
210
- * returned metadata is merged into the outgoing prompt request.
211
- */
212
- decoratePrompt?(): PluginPromptDecoration | void;
213
- }
214
- /**
215
- * A declarative, serializable descriptor for one card rendered beneath a
216
- * message. `type` selects a registered card renderer; `key` drives cross-turn
217
- * dedup (same key across turns = one logical card, shown only under its latest
218
- * anchor); `payload` carries STABLE REFERENCES (e.g. image ids), not a content
219
- * snapshot — the renderer resolves live state from it. `title`/`icon` label the
220
- * card's tab (override the renderer's registration defaults). Rides a tool
221
- * result's out-of-band `details.cards`; crosses the agent→host boundary, so
222
- * `icon` is an icon-symbol string, not a node.
223
- */
224
- export interface CardDescriptor {
225
- type: string;
226
- key?: string;
227
- payload?: unknown;
228
- title?: string;
229
- icon?: string;
230
- }
231
- /** A pending (in-flight) tool call handed to a renderer's `pendingFor`. */
232
- export interface PluginPendingToolCall {
233
- toolName: string;
234
- args: Record<string, unknown>;
235
- }
236
- /**
237
- * Props for a card renderer. `descriptor` is the card's data; `pending` is true
238
- * while it was synthesized from an in-flight tool (render a skeleton); `message`
239
- * is the anchoring conversation message.
240
- */
241
- export interface PluginCardProps {
242
- descriptor: CardDescriptor;
243
- pending: boolean;
244
- message: ConversationMessage;
245
- }
246
- /**
247
- * A card renderer registered by a plugin, keyed by `type`. A descriptor whose
248
- * `type` matches is rendered by `component`. `title`/`icon` are the default tab
249
- * label/icon (a descriptor may override `title`). `pendingFor`, given an
250
- * in-flight tool call, returns a provisional descriptor so a skeleton card
251
- * appears (and claims a tab) before the tool's result lands — or null when this
252
- * renderer doesn't handle that tool. The `type` must be globally unique across
253
- * plugins (convention: prefix with the plugin id, e.g. "image-gen:preview").
254
- */
255
- export interface PluginCardRendererContribution {
256
- type: string;
257
- component: ComponentType<PluginCardProps>;
258
- title?: string;
259
- /** Default tab icon as a React node (not an iconify class string). */
260
- icon?: ReactNode;
261
- pendingFor?: (toolCall: PluginPendingToolCall) => CardDescriptor | null;
262
- }
263
- /** A tool call handed to a tool-call slot renderer. */
264
- export interface PluginToolCallSlotToolCall {
265
- toolCallId: string;
266
- toolName: string;
267
- args: Record<string, unknown>;
268
- status: "pending" | "success" | "error";
269
- result?: string;
270
- isError?: boolean;
271
- }
272
- export interface PluginToolCallSlotProps {
273
- toolCall: PluginToolCallSlotToolCall;
274
- }
275
- /**
276
- * A component that **replaces the host's default inline transcript rendering**
277
- * for a specific tool (matched by `toolName`; first registered renderer wins).
278
- * This is how a plugin renders rich UI for its OWN agent tool's output — plugin
279
- * tools cannot emit `details.cards`, so the message card system (registerCardRenderer)
280
- * does not serve them; the tool-call slot does.
281
- */
282
- export interface PluginToolCallSlotContribution {
283
- id: string;
284
- toolName: string;
285
- component: ComponentType<PluginToolCallSlotProps>;
286
- }
287
- /**
288
- * A card rendered at the bottom of the message list for the LATEST turn — NOT
289
- * bound to a tool call. The host mounts `component` in the footer slot and
290
- * re-mounts it each session/turn; the plugin owns visibility entirely (it reads
291
- * live state via SDK hooks — `useActiveConversation`, `useConversationMessages`,
292
- * `ctx.conversation.on("turn-end")` — and returns `null` to render nothing,
293
- * e.g. git renders only inside a repo that has changes). `scope_use` gates which
294
- * conversation scenarios it may appear in (**fail-closed**, mirrors the other
295
- * slots). `id` must be unique within the plugin.
296
- */
297
- export interface PluginTurnCardContribution {
298
- id: string;
299
- component: ComponentType;
300
- /**
301
- * 允许该 turn 卡出现的对话场景 slug 列表(镜像其它插槽的 scope_use)。**fail-closed**:
302
- * 未声明/空数组 = 任何会话都不显示;声明后仅在列出的场景里出现(如 `["project"]`)。
303
- */
304
- scope_use?: readonly ConversationScenario[];
305
- }
306
- export interface PluginUiApi {
307
- registerGlobalSlot(contribution: PluginGlobalSlotContribution): Disposable;
308
- /**
309
- * Register a preview component keyed by file extension. The host dispatches
310
- * registered extensions before its built-in fallback renderers; first
311
- * registrant wins on conflict.
312
- */
313
- registerFilePreview(contribution: PluginFilePreviewContribution): Disposable;
314
- /**
315
- * Register an activity-panel tab into the addable pool. The user attaches
316
- * it manually via the panel's "+" picker; attach records are keyed by the
317
- * session cwd.
318
- */
319
- registerActivityTab(contribution: PluginActivityTabContribution): Disposable;
320
- /**
321
- * Register a toggle action shown beneath the AI input bar. While active,
322
- * its `decoratePrompt()` annotates the next outgoing prompt.
323
- */
324
- registerInputAction(contribution: PluginInputActionContribution): Disposable;
325
- /**
326
- * Register a card renderer keyed by `type`. Cards rendered beneath a message
327
- * come from tool results' out-of-band `details.cards` (or `pendingFor` for
328
- * in-flight tools); the host resolves each card's `type` to a registered
329
- * renderer. Multiple cards under one message are shown as a tab-switcher
330
- * ("收纳") or a flat list.
331
- */
332
- registerCardRenderer(contribution: PluginCardRendererContribution): Disposable;
333
- /**
334
- * Register a renderer that replaces the host's default inline transcript UI
335
- * for a tool call (matched by `toolName`). The complement to card renderers:
336
- * use it to render UI for a plugin's own agent tool output.
337
- */
338
- registerToolCallSlot(contribution: PluginToolCallSlotContribution): Disposable;
339
- /**
340
- * Register a card rendered at the bottom of the message list for the latest
341
- * turn — NOT bound to a tool call. The host mounts the component in the
342
- * footer slot; the plugin owns visibility (return `null` to render nothing,
343
- * e.g. git renders only in a repo with changes). Gated by `scope_use`
344
- * (fail-closed). Needs the `ui.slot.turn-card` permission.
345
- */
346
- registerTurnCard(contribution: PluginTurnCardContribution): Disposable;
347
- /**
348
- * Programmatically attach (if needed) and activate one of this plugin's
349
- * own activity tabs in the current conversation's activity panel. `tabId`
350
- * is the contribution id passed to registerActivityTab. Any payload (e.g.
351
- * which image to edit) is passed via the plugin's own in-memory state.
352
- *
353
- * Pass `options.width` to size the panel as it opens — a pixel number, or
354
- * `"max"` to expand it to the widest the current window allows (the host
355
- * still clamps to its min/max and auto-hides the sidebar when needed). Omit
356
- * to leave the user's current width untouched.
357
- */
358
- openActivityTab(tabId: string, options?: PluginOpenActivityTabOptions): void;
359
- /**
360
- * Bind (or clear, with `null`) an image as the "edit target" for the next
361
- * outgoing prompt. The host renders it as a thumbnail capsule in the AI input
362
- * bar's top capsule strip and, at send time, injects `metadata.editImageId`
363
- * (the ref's id) so this turn edits that image. One-shot: cleared after the
364
- * prompt is sent (or when the user closes the capsule). Only the image
365
- * reference (id/url) crosses over — bytes stay out-of-band.
366
- */
367
- setEditImageAttachment(ref: PluginImageRef | null): void;
368
- /**
369
- * Open the host's global full-screen image previewer for the given image.
370
- * Only the image reference (id/url) crosses over — bytes stay out-of-band.
371
- *
372
- * Pass `group` (e.g. all images of the message) to open as an image group:
373
- * the previewer shows a thumbnail strip + arrows and starts at `ref`.
374
- */
375
- previewImage(ref: PluginImageRef, group?: PluginImageRef[]): void;
376
- /**
377
- * Open the app settings, scrolled to and highlighting THIS plugin's own
378
- * settings section (e.g. so the user can fill in a required API key/model).
379
- * The host owns the navigation; the plugin only asks to jump there.
380
- */
381
- openPluginSettings(): void;
382
- /**
383
- * Show a global toast in the host UI (bottom-right). No permission required.
384
- * Prefer this over swallowing errors into opaque UI copy: pass `error` so
385
- * the host attaches a one-click "copy stack" action for the user.
386
- *
387
- * Capture `ctx.ui.notify` in `activate` if React components need it
388
- * (components do not receive `ctx`).
389
- */
390
- notify(options: PluginNotifyOptions): void;
391
- }
392
- /**
393
- * Options for {@link PluginUiApi.notify}. Surfaces a host toast so users can
394
- * see plugin failures without opening DevTools.
395
- */
396
- export interface PluginNotifyOptions {
397
- /** Toast body. Required even when `error` is set (user-facing summary). */
398
- message: string;
399
- /** Defaults to plugin display name when omitted. */
400
- title?: string;
401
- /** Defaults to `"info"`; when `error` is set and variant omitted, host uses `"error"`. */
402
- variant?: "info" | "success" | "warning" | "error";
403
- /**
404
- * Optional failure cause. Host formats message + stack and adds a
405
- * "复制堆栈" action so the user can paste it into bug reports / chat.
406
- */
407
- error?: unknown;
408
- /**
409
- * Auto-dismiss delay in ms. `0` keeps the toast until dismissed.
410
- * Defaults: sticky (`0`) when `error` is present, otherwise host default (~4s).
411
- */
412
- durationMs?: number;
413
- }
414
- export interface ConversationState {
415
- /** Active session runtimeId, or null when no conversation is active. */
416
- id: string | null;
417
- cwd: string | null;
418
- sessionPath: string | null;
419
- model: string | null;
420
- isStreaming: boolean;
421
- }
422
- export interface ConversationMessage {
423
- id: string;
424
- role: "user" | "assistant" | "compaction";
425
- text: string;
426
- timestamp?: number;
427
- }
428
- export type ConversationEvent = {
429
- type: "turn-start";
430
- } | {
431
- type: "turn-end";
432
- stopReason: string;
433
- } | {
434
- type: "message-added";
435
- message: ConversationMessage;
436
- } | {
437
- type: "message-updated";
438
- delta: string;
439
- } | {
440
- type: "tool-call-start";
441
- toolCallId: string;
442
- toolName: string;
443
- } | {
444
- type: "tool-call-end";
445
- toolCallId: string;
446
- toolName: string;
447
- isError: boolean;
448
- } | {
449
- type: "conversation-changed";
450
- conversation: ConversationState;
451
- };
452
- export interface PluginConversationApi {
453
- /** Send a prompt into the active conversation (renders as a user turn). */
454
- sendPrompt(text: string): Promise<void>;
455
- /** Fill the input bar without sending; the user can edit and send. */
456
- insertText(text: string): void;
457
- /** Abort the active conversation's current turn. */
458
- abort(): Promise<void>;
459
- /** Subscribe to real-time conversation events. */
460
- on(listener: (event: ConversationEvent) => void): Disposable;
461
- }
462
- export type PluginJsonSchema = object;
463
- export interface PluginAgentToolApi {
464
- fs: PluginFsApi;
465
- conversation: PluginConversationApi;
466
- }
467
- export interface PluginAgentToolRegistration<TInput = unknown> {
468
- id: string;
469
- name?: string;
470
- label?: string;
471
- description: string;
472
- parameters: PluginJsonSchema;
473
- timeoutMs?: number;
474
- /**
475
- * 允许该工具出现的对话场景 slug 列表。**fail-closed**:未声明/空数组 = 所有场景都不激活。
476
- * 插件须显式声明。
477
- */
478
- scope_use?: readonly ConversationScenario[];
479
- /** 需要的会话能力 slug(如 "knowledge");全满足才激活。一般插件无需设置。 */
480
- requires?: string[];
481
- context?: {
482
- conversation?: "summary" | "messages";
483
- };
484
- handler: PluginAgentToolHandler<TInput>;
485
- }
486
- export interface PluginSystemPromptBlock {
487
- id: string;
488
- content: string;
489
- priority?: number;
490
- enabled?: boolean;
491
- }
492
- export type PluginDynamicSystemPromptOperation = {
493
- type: "addBlock";
494
- block: PluginSystemPromptBlock;
495
- } | {
496
- type: "replaceBlock";
497
- blockId: string;
498
- block: Omit<PluginSystemPromptBlock, "id">;
499
- } | {
500
- type: "updateBlock";
501
- blockId: string;
502
- patch: Partial<Pick<PluginSystemPromptBlock, "content" | "priority" | "enabled">>;
503
- } | {
504
- type: "removeBlock";
505
- blockId: string;
506
- } | {
507
- type: "setBlockEnabled";
508
- blockId: string;
509
- enabled: boolean;
510
- } | {
511
- type: "setToolEnabled";
512
- toolName: string;
513
- enabled: boolean;
514
- } | {
515
- type: "requestContinuation";
516
- result: PluginContinuationResult;
517
- };
518
- export interface PluginSystemPromptMessage {
519
- role: string;
520
- text: string;
521
- timestamp?: number;
522
- toolName?: string;
523
- }
524
- export interface PluginSystemPromptProviderContext {
525
- plugin: {
526
- id: string;
527
- providerId: string;
528
- settings: Readonly<Record<string, unknown>>;
529
- };
530
- session: {
531
- id: string;
532
- cwd: string;
533
- scenario: ConversationScenario;
534
- };
535
- model: {
536
- provider: string;
537
- id: string;
538
- api: string;
539
- input: readonly string[];
540
- contextWindow?: number;
541
- maxTokens?: number;
542
- };
543
- conversation: {
544
- messages: readonly PluginSystemPromptMessage[];
545
- messageCount: number;
546
- };
547
- runtime: {
548
- activeToolNames: readonly string[];
549
- availableToolNames: readonly string[];
550
- runIndex: number;
551
- };
552
- trigger: {
553
- kind: "agent-run";
554
- timestamp: number;
555
- };
556
- systemPrompt?: {
557
- base: {
558
- blocks?: readonly PluginSystemPromptBlockView[];
559
- rendered?: string;
560
- };
561
- current: {
562
- blocks?: readonly PluginSystemPromptBlockView[];
563
- rendered?: string;
564
- };
565
- };
566
- }
567
- export interface PluginSystemPromptBlockView extends PluginSystemPromptBlock {
568
- type: string;
569
- source: {
570
- kind: "core" | "plugin";
571
- pluginId?: string;
572
- };
573
- priority: number;
574
- enabled: boolean;
575
- }
576
- export interface PluginAgentActions {
577
- systemPrompt: {
578
- addBlock(block: PluginSystemPromptBlock): void;
579
- replaceBlock(blockId: string, block: Omit<PluginSystemPromptBlock, "id">): void;
580
- updateBlock(blockId: string, patch: Partial<Pick<PluginSystemPromptBlock, "content" | "priority" | "enabled">>): void;
581
- removeBlock(blockId: string): void;
582
- setBlockEnabled(blockId: string, enabled: boolean): void;
583
- };
584
- tools: {
585
- setEnabled(toolName: string, enabled: boolean): void;
586
- enable(toolName: string): void;
587
- disable(toolName: string): void;
588
- };
589
- continuation: {
590
- request(result: PluginContinuationResult): void;
591
- };
592
- }
593
- export interface PluginAgentHandlerContext<TTrigger> {
594
- invocationId: string;
595
- plugin: {
596
- id: string;
597
- contributionId: string;
598
- settings: Readonly<Record<string, unknown>>;
599
- };
600
- session: PluginSystemPromptProviderContext["session"];
601
- model: PluginSystemPromptProviderContext["model"];
602
- conversation: PluginSystemPromptProviderContext["conversation"];
603
- runtime: PluginSystemPromptProviderContext["runtime"];
604
- trigger: TTrigger;
605
- systemPrompt?: PluginSystemPromptProviderContext["systemPrompt"];
606
- actions: PluginAgentActions;
607
- host: PluginAgentToolApi;
608
- }
609
- export type PluginAgentToolHandler<TInput = unknown> = (context: PluginAgentHandlerContext<{
610
- kind: "tool-call";
611
- timestamp: number;
612
- toolCallId: string;
613
- toolId: string;
614
- toolName: string;
615
- input: TInput;
616
- }>) => unknown | Promise<unknown>;
617
- export type PluginSystemPromptProviderHandler = (context: PluginAgentHandlerContext<{
618
- kind: "agent-run";
619
- timestamp: number;
620
- }>) => void | PluginDynamicSystemPromptOperation[] | Promise<void | PluginDynamicSystemPromptOperation[]>;
621
- export interface PluginSystemPromptProviderRegistration {
622
- id: string;
623
- timeoutMs?: number;
624
- /**
625
- * Large context is opt-in. Omitted fields are not serialized across the
626
- * host/renderer boundary.
627
- */
628
- context?: {
629
- systemPrompt?: "none" | "blocks" | "rendered" | "full";
630
- conversation?: "summary" | "messages";
631
- };
632
- handler: PluginSystemPromptProviderHandler;
633
- }
634
- export interface PluginAgentApi {
635
- registerTool<TInput = unknown>(registration: PluginAgentToolRegistration<TInput>): Disposable;
636
- /** Register a provider evaluated before every Agent run. */
637
- registerSystemPromptProvider(registration: PluginSystemPromptProviderRegistration): Disposable;
638
- /**
639
- * Register a policy consulted when the agent reaches a natural stopping point.
640
- * Return null to allow the agent to stop, or a message to continue with another turn.
641
- */
642
- registerContinuationProvider(registration: PluginContinuationRegistration): Disposable;
643
- }
644
- export interface PluginContinuationResult {
645
- text: string;
646
- /** Stable key used by the host to suppress duplicate continuations in a session. */
647
- idempotencyKey?: string;
648
- }
649
- export type PluginContinuationHandler = (context: PluginAgentHandlerContext<{
650
- kind: "continuation";
651
- timestamp: number;
652
- }>) => PluginContinuationResult | null | Promise<PluginContinuationResult | null>;
653
- export interface PluginContinuationRegistration {
654
- id: string;
655
- timeoutMs?: number;
656
- context?: {
657
- conversation?: "summary" | "messages";
658
- };
659
- handler: PluginContinuationHandler;
660
- }
661
- export interface PluginFsEntry {
662
- name: string;
663
- path: string;
664
- isDirectory: boolean;
665
- size: number;
666
- modifiedAt: number;
667
- }
668
- export interface PluginFsFileRef {
669
- name: string;
670
- path: string;
671
- relPath: string;
672
- }
673
- export interface PluginFsStatResult {
674
- size: number;
675
- modifiedAt: number;
676
- createdAt: number;
677
- }
678
- export interface PluginFsReadResult {
679
- content: string;
680
- encoding: "utf8" | "base64";
681
- }
682
- export interface PluginFsApi {
683
- readDir(dirPath: string): Promise<PluginFsEntry[]>;
684
- readFile(filePath: string): Promise<PluginFsReadResult>;
685
- /** Pass `encoding: "base64"` to write binary payloads (decoded from base64 text). */
686
- writeFile(filePath: string, content: string, encoding?: "utf8" | "base64"): Promise<void>;
687
- stat(filePath: string): Promise<PluginFsStatResult | null>;
688
- rename(oldPath: string, newPath: string): Promise<void>;
689
- delete(targetPath: string): Promise<void>;
690
- move(sourcePath: string, destDir: string): Promise<void>;
691
- createDirectory(dirPath: string): Promise<void>;
692
- listFilesRecursive(rootPath: string): Promise<PluginFsFileRef[]>;
693
- }
694
- export interface PluginCommandRunOptions {
695
- /** Working directory. Must resolve inside a host-allowed root (e.g. a project). */
696
- cwd?: string;
697
- /** Extra environment entries, merged over the host process env (PATH preserved). */
698
- env?: Record<string, string>;
699
- /** Hard timeout in ms; the host clamps to its own maximum. */
700
- timeoutMs?: number;
701
- }
702
- export interface PluginCommandRunResult {
703
- stdout: string;
704
- stderr: string;
705
- /** Process exit code; null when the process was killed by a signal/timeout. */
706
- exitCode: number | null;
707
- }
708
- /**
709
- * Run an allowed host command (e.g. `git`). execFile semantics — NO shell, args
710
- * are passed as an array (no string splitting, no injection). The executable
711
- * must be declared in plugin.json's `commands` and currently enabled by the
712
- * user; otherwise the call is rejected (and the host notifies the user). Needs
713
- * the `agent.command.run` permission.
714
- */
715
- export interface PluginCommandApi {
716
- run(file: string, args?: string[], options?: PluginCommandRunOptions): Promise<PluginCommandRunResult>;
717
- }
718
- export interface PluginPermissionApi {
719
- has(permission: PluginPermission): boolean;
720
- require(permission: PluginPermission): void;
721
- }
722
- export interface PluginGenerateImageInput {
723
- prompt: string;
724
- /** Output size (e.g. "1024x1024"), decided by the agent and forwarded to the model. */
725
- size?: string;
726
- /** Optional reference id for grouping (e.g. the conversation/session). */
727
- sessionId?: string;
728
- }
729
- export interface PluginEditImageInput {
730
- prompt: string;
731
- /**
732
- * Source image to edit. Either an existing host image id (continue a
733
- * lineage) or raw base64 bytes (e.g. a user upload).
734
- */
735
- source: {
736
- imageId: string;
737
- } | {
738
- data: string;
739
- mimeType: string;
740
- };
741
- sessionId?: string;
742
- }
743
- /**
744
- * Image generation, routed to the host's main-process image service (single
745
- * implementation shared with the agent's built-in image tool). Bytes are
746
- * stored out-of-band; results are returned as host media references.
747
- */
748
- export interface PluginImagesApi {
749
- /** Text-to-image. Resolves to the produced image reference(s). */
750
- generate(input: PluginGenerateImageInput): Promise<PluginImageRef[]>;
751
- /** Image-to-image edit, producing the next version in a lineage. */
752
- edit(input: PluginEditImageInput): Promise<PluginImageRef[]>;
753
- /** The edit lineage (base image + its edits, oldest first) for an image. */
754
- lineage(imageId: string): Promise<PluginImageRef[]>;
755
- /**
756
- * Every edit lineage the given session touched (generated or edited a version
757
- * in), newest lineage first; each lineage's versions oldest → newest. The
758
- * sessionId is the agent session id — derive it from the active conversation's
759
- * `sessionPath` (the UUID embedded in the session file name).
760
- */
761
- sessionLineages(sessionId: string): Promise<PluginImageRef[][]>;
762
- }
763
- /**
764
- * Read-side access to this plugin's settings (the values configured against
765
- * the `contributes.settings` schema declared in plugin.json, namespaced by
766
- * plugin id). Writes go through the host's settings UI, not the plugin.
767
- */
768
- export interface PluginSettingsApi {
769
- get<T = unknown>(key: string): T | undefined;
770
- getAll(): Record<string, unknown>;
771
- /** Fired when any of this plugin's setting values change. */
772
- onChange(listener: (values: Record<string, unknown>) => void): Disposable;
773
- }
774
- /** A flat catalog: translation key → localized string. */
775
- export type PluginLocaleCatalog = Record<string, string>;
776
- /** Every catalog a plugin ships, keyed by locale code (e.g. "zh", "en"). */
777
- export type PluginLocales = Record<string, PluginLocaleCatalog>;
778
- /** Replace `{{name}}` placeholders in a resolved string with `params`. */
779
- export declare function interpolatePluginText(text: string, params?: Record<string, string | number>): string;
780
- /**
781
- * Resolve a bare catalog key against a plugin's catalogs. Fallback chain:
782
- * current-locale catalog → the plugin's `defaultLocale` catalog → the bare key
783
- * itself (a dev signal for a missing translation). Then interpolate `{{params}}`.
784
- */
785
- export declare function resolveCatalogKey(key: string, locales: PluginLocales, currentLocale: string, defaultLocale: string, params?: Record<string, string | number>): string;
786
- /**
787
- * Resolve a host-rendered plugin string. A value of the exact form `%key%` is a
788
- * catalog key (resolved via {@link resolveCatalogKey}); any other string is a
789
- * literal and returned unchanged — backwards compatible with bare strings.
790
- */
791
- export declare function resolvePluginText(raw: string, locales: PluginLocales, currentLocale: string, defaultLocale: string, params?: Record<string, string | number>): string;
792
- export type PluginTranslate = (key: string, params?: Record<string, string | number>) => string;
793
- /**
794
- * This plugin's i18n surface on the context. `locale` always equals the host's
795
- * current language; `t` resolves a BARE catalog key (no `%...%` wrapper) against
796
- * this plugin's catalogs at the current locale. Imperative — for plugin React
797
- * components prefer the reactive {@link useTranslation} hook.
798
- */
799
- export interface PluginI18nApi {
800
- /** The host's current locale code (e.g. "zh"). */
801
- readonly locale: string;
802
- /** Resolve a bare catalog key at the current locale, with optional `{{params}}`. */
803
- t: PluginTranslate;
804
- /** Fired when the host language changes. */
805
- onChange(listener: (locale: string) => void): Disposable;
806
- }
807
- export interface PluginContext {
808
- plugin: {
809
- id: string;
810
- version: string;
811
- };
812
- permissions: PluginPermissionApi;
813
- ui: PluginUiApi;
814
- conversation: PluginConversationApi;
815
- agent: PluginAgentApi;
816
- fs: PluginFsApi;
817
- command: PluginCommandApi;
818
- images: PluginImagesApi;
819
- settings: PluginSettingsApi;
820
- i18n: PluginI18nApi;
821
- }
822
- export interface PluginDefinition {
823
- activate(ctx: PluginContext): void | Promise<void>;
824
- deactivate?(): void | Promise<void>;
825
- }
826
- export declare function definePlugin(plugin: PluginDefinition): PluginDefinition;
827
- export interface PluginHostBridge {
828
- useActiveConversation(): ConversationState;
829
- useConversationMessages(): ConversationMessage[];
830
- useEditImageAttachment(): PluginImageRef | null;
831
- /** Reactive: the host's current locale code (e.g. "zh"). */
832
- useLocale(): string;
833
- conversation: PluginConversationApi;
834
- }
835
- export declare function __setPluginHostBridge(bridge: PluginHostBridge): void;
836
- export interface ActivityTabContextValue {
837
- /**
838
- * The cwd scope of the activity panel this tab is rendered in — the same
839
- * key the attach record uses. Do NOT substitute useActiveConversation().cwd:
840
- * on the project detail page the panel cwd is the project's, while the
841
- * active conversation may belong to another project (or be null).
842
- */
843
- cwd: string | null;
844
- }
845
- /**
846
- * Internal: the host wraps attached activity-tab components in this context's
847
- * Provider. Module Federation shares this single SDK instance, so the value
848
- * the host provides is visible to plugin components.
849
- */
850
- export declare const __ActivityTabContext: import("react").Context<ActivityTabContextValue>;
851
- /** The panel scope of the activity tab this component is rendered in. */
852
- export declare function useActivityTab(): ActivityTabContextValue;
853
- export interface PluginI18nContextValue {
854
- /** This plugin's catalogs, keyed by locale code. */
855
- locales: PluginLocales;
856
- /** Fallback locale when a key is missing in the current locale. */
857
- defaultLocale: string;
858
- }
859
- /**
860
- * Internal: the host wraps plugin-rendered components in this context's Provider,
861
- * carrying THIS plugin's catalogs. Module Federation shares this single SDK
862
- * instance, so the value the host provides is visible to {@link useTranslation}.
863
- */
864
- export declare const __PluginI18nContext: import("react").Context<PluginI18nContextValue>;
865
- export interface PluginTranslation {
866
- /** The host's current locale code (e.g. "zh"). */
867
- locale: string;
868
- /** Resolve a bare catalog key at the current locale, with optional `{{params}}`. */
869
- t: PluginTranslate;
870
- }
871
- /**
872
- * Reactive translation for plugin React components — re-renders when the host
873
- * language changes. `t` resolves a BARE catalog key (no `%...%` wrapper) against
874
- * THIS plugin's catalogs; the host provides them via __PluginI18nContext.
875
- */
876
- export declare function useTranslation(): PluginTranslation;
877
- /** Reactive: the currently-active conversation's state. */
878
- export declare function useActiveConversation(): ConversationState;
879
- /** Reactive: the active conversation's messages. */
880
- export declare function useConversationMessages(): ConversationMessage[];
881
- /**
882
- * Reactive: the image currently bound as the edit target via
883
- * `ui.setEditImageAttachment` (or null). Single source of truth for the
884
- * "selected for edit" highlight — clears automatically when the host drops the
885
- * attachment (send, capsule close, or session switch).
886
- */
887
- export declare function useEditImageAttachment(): PluginImageRef | null;
4
+ * Implementation is split by domain under `src/*.ts`; this barrel re-exports
5
+ * the stable package API. Prefer importing from `@vetta-org/plugin-sdk` rather
6
+ * than deep paths.
7
+ */
8
+ export type { ConversationScenario } from "./scenario.js";
9
+ export type { PluginPermission } from "./permissions.js";
10
+ export type { Disposable } from "./disposable.js";
11
+ export type { PluginMcpServerConfig, PluginAgentManifest } from "./manifest.js";
12
+ export type { ConversationState, ConversationMessage, ConversationEvent, PluginConversationApi, } from "./conversation.js";
13
+ export type { PluginGlobalSlotContribution, PluginAudioMetadata, PluginPreviewUrlOptions, PluginPreviewFile, PluginFilePreviewProps, PluginFilePreviewContribution, PluginActivityTabContribution, PluginOpenActivityTabOptions, PluginPromptDecoration, PluginInputActionContribution, CardDescriptor, PluginPendingToolCall, PluginCardProps, PluginCardRendererContribution, PluginToolCallSlotToolCall, PluginToolCallSlotProps, PluginToolCallSlotContribution, PluginTurnCardContribution, PluginNotifyOptions, PluginUiApi, } from "./ui.js";
14
+ export type { PluginJsonSchema, PluginAgentToolApi, PluginAgentToolRegistration, PluginSystemPromptBlock, PluginDynamicSystemPromptOperation, PluginSystemPromptMessage, PluginSystemPromptProviderContext, PluginSystemPromptBlockView, PluginAgentActions, PluginAgentHandlerContext, PluginAgentToolHandler, PluginSystemPromptProviderHandler, PluginSystemPromptProviderRegistration, PluginContinuationResult, PluginContinuationHandler, PluginContinuationRegistration, PluginAgentApi, } from "./agent.js";
15
+ export type { PluginAppActionEffect, PluginAppActionExample, PluginAppActionHandlerContext, PluginAppActionHandler, PluginAppActionReadyHandler, PluginAppActionApprovalPresentation, PluginAppActionApproval, PluginAppActionRegistration, PluginAppActionsApi, } from "./app-actions.js";
16
+ export { PluginAppActionError } from "./app-actions.js";
17
+ export type { PluginOfficialGeneralSettings, PluginOfficialGeneralSettingsUpdate, PluginOfficialExperimentalSettings, PluginOfficialDownloadItem, PluginOfficialUpdaterState, PluginOfficialWebhookKind, PluginOfficialWebhookEndpoint, PluginOfficialWebhookProvider, PluginOfficialWebhookCreateInput, PluginOfficialWebhookUpdateInput, PluginOfficialWebhookMessage, PluginOfficialWebhookSendResult, PluginOfficialSkillInfo, PluginOfficialInstalledSkill, PluginOfficialShortcutBinding, PluginOfficialQuickPanelSettings, PluginOfficialImStatus, PluginOfficialImLog, PluginOfficialMcpServerSummary, PluginOfficialMcpServerDetail, PluginOfficialMcpUpsertData, PluginOfficialExecutionMode, PluginOfficialSelectedSkill, PluginOfficialBatchProjectCreateData, PluginOfficialBatchProjectUpdateData, PluginOfficialSchedulerTaskCreateData, PluginOfficialSchedulerTaskUpdateData, PluginOfficialModelSummary, PluginOfficialProviderSummary, PluginOfficialProviderDetail, PluginOfficialProviderUpsertData, PluginOfficialProjectEntry, PluginOfficialPluginSummary, PluginOfficialKnowledgeBase, PluginOfficialKnowledgeProcessingSettings, PluginOfficialApi, } from "./official.js";
18
+ export type { PluginFsEntry, PluginFsFileRef, PluginFsStatResult, PluginFsReadResult, PluginFsApi, } from "./fs.js";
19
+ export type { PluginCommandRunOptions, PluginCommandRunResult, PluginCommandApi, } from "./command.js";
20
+ export type { PluginImageRef, PluginGenerateImageInput, PluginEditImageInput, PluginImagesApi, } from "./images.js";
21
+ export type { PluginSettingsApi } from "./settings.js";
22
+ export type { PluginLocaleCatalog, PluginLocales, PluginTranslate, PluginI18nApi, } from "./i18n.js";
23
+ export { interpolatePluginText, resolveCatalogKey, resolvePluginText } from "./i18n.js";
24
+ export type { PluginPermissionApi, AgentMode, PluginContext, PluginDefinition } from "./context.js";
25
+ export { definePlugin } from "./context.js";
26
+ export type { PluginHostBridge } from "./host-bridge.js";
27
+ export { __setPluginHostBridge } from "./host-bridge.js";
28
+ export type { ActivityTabContextValue } from "./activity-tab.js";
29
+ export { __ActivityTabContext, useActivityTab } from "./activity-tab.js";
30
+ export type { PluginI18nContextValue, PluginTranslation } from "./hooks.js";
31
+ export { __PluginI18nContext, useTranslation, useActiveConversation, useConversationMessages, useEditImageAttachment, } from "./hooks.js";
888
32
  //# sourceMappingURL=index.d.ts.map