pi-web-ui 0.114.1 → 0.114.3
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/CHANGELOG.md +39 -0
- package/README.md +187 -187
- package/README.zh-CN.md +227 -227
- package/README.zh-TW.md +227 -227
- package/bin/device-hub-cli.mjs +577 -577
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -9
- package/bin/pi-web-ui.mjs +4081 -4081
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service.js +88 -15
- package/dist/server/attachments.js +6 -6
- package/dist/server/canvas/canvas-orchestrator.js +3 -3
- package/dist/server/communicate-tool.js +37 -11
- package/dist/server/compaction-instructions.js +8 -8
- package/dist/server/context-usage.js +105 -0
- package/dist/server/device-center/desktop-page.js +228 -228
- package/dist/server/device-center/hub-page.js +64 -64
- package/dist/server/device-center/native-desktop/macos.js +190 -190
- package/dist/server/device-center/native-desktop/windows.js +116 -116
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/durable/durable-event-projector.js +19 -3
- package/dist/server/durable/durable-models.js +134 -65
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/model-resolver.js +4 -1
- package/dist/server/patch-bash-process.js +89 -89
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +39 -39
- package/dist/server/schedule-agent-tool.js +11 -6
- package/dist/server/scheduler-tasks.js +84 -2
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/setup-page.js +620 -620
- package/dist/server/universal/universal-session.js +19 -18
- package/dist/server/vision-bridge.js +18 -18
- package/docs/device-center.md +148 -148
- package/docs/device-desktop.md +48 -48
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +1 -1
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -698
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -225
- package/themes/aetheris.css +501 -501
- package/themes/ayu-light.css +116 -116
- package/themes/bases/flow-base.css +1357 -1357
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -112
- package/themes/bases/zhujian-base.css +688 -688
- package/themes/bases/zhupi-base.css +660 -660
- package/themes/catppuccin-latte.css +119 -119
- package/themes/catppuccin.css +116 -116
- package/themes/claude-code-dark.css +147 -147
- package/themes/codex.css +114 -114
- package/themes/cyberpunk.css +50 -50
- package/themes/dark-teal.css +264 -264
- package/themes/dazzle.css +38 -38
- package/themes/everforest-light.css +115 -115
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -114
- package/themes/gruvbox-light.css +115 -115
- package/themes/kanagawa-lotus.css +115 -115
- package/themes/md-preview.css +24 -24
- package/themes/mist.css +166 -166
- package/themes/nord.css +107 -107
- package/themes/one-dark.css +106 -106
- package/themes/paper.css +174 -174
- package/themes/rose-pine-dawn.css +114 -114
- package/themes/sakura.css +166 -166
- package/themes/solarized-light.css +114 -114
- package/themes/tokyo-night.css +115 -115
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -164
- package/themes/zhujian-dark.css +115 -115
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -115
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BvnUHjFe.js} +1 -1
- package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-DSC8ncW3.js} +1 -1
- package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-BSg9ghPV.js} +2 -2
- package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-DxW7C3Sz.js} +2 -2
- package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-Bmgr-Bwm.js} +1 -1
- package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-Cl9MBXaH.js} +1 -1
- package/web/dist/assets/{DeviceGroups-D2rogxEN.js → DeviceGroups-aeLD2msl.js} +1 -1
- package/web/dist/assets/{Dropdown-ZLS04O8p.js → Dropdown-D1Jl35dw.js} +1 -1
- package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-6CqoDF_P.js} +1 -1
- package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-CJa27G_Q.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-CJX35rZL.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CMW0xz0P.js} +1 -1
- package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-Cq4daBFb.js} +1 -1
- package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DoELa83U.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-DDZccDYt.js → ModelConfigModal-Bp7tfKYh.js} +1 -1
- package/web/dist/assets/{PiSetupModal-DHbqfx8T.js → PiSetupModal-DD8srwBJ.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-C-MK36Dk.js → ProviderOAuthControls-C6tfXb88.js} +1 -1
- package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-CghgsyBN.js} +1 -1
- package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-D8-8aqwC.js} +1 -1
- package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-BbBe2rYo.js} +1 -1
- package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-qETiVPKj.js} +1 -1
- package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-Da-Xs4Wk.js} +1 -1
- package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DnS4tFQO.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-CGyGkKYl.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-CpBKjG6x.js} +1 -1
- package/web/dist/assets/{desktop-YguLbrX1.js → desktop-7EvUHhKQ.js} +1 -1
- package/web/dist/assets/{fi-DaSO0Q-m.js → fi-NyN-ZrgD.js} +2 -2
- package/web/dist/assets/{index-D6u8xH0o.js → index-DK3F5ZJo.js} +50 -50
- package/web/dist/assets/{index-BPvpea8t.js → index-DQMii2he.js} +50 -50
- package/web/dist/assets/index-vwBnwzkr.css +1 -0
- package/web/dist/assets/{plugin-host-BRBg6zmQ.js → plugin-host-BCnX3P8U.js} +1 -1
- package/web/dist/assets/{theme-DDl-Oy1b.js → theme-D2DMH6tH.js} +1 -1
- package/web/dist/index.html +35 -35
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/web/dist/assets/index-DDZMv6LO.css +0 -1
package/plugin-sdk/index.d.ts
CHANGED
|
@@ -1,698 +1,698 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pi-web-ui 插件 SDK 类型(starter,自包含,不引用 server/ 目录)。
|
|
3
|
-
* 与 server/plugins.ts 的 PluginHost 同语义的精简版:写插件时抄 autocomplete 用,
|
|
4
|
-
* 运行时以宿主实际注入为准(宿主 API 版本见 PLUGIN_API_VERSION)。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export type PluginPermissionFamily =
|
|
8
|
-
| "fs"
|
|
9
|
-
| "fs:read"
|
|
10
|
-
| "fs:write"
|
|
11
|
-
| "ui"
|
|
12
|
-
| "tools"
|
|
13
|
-
| "http"
|
|
14
|
-
| "chat"
|
|
15
|
-
| "net"
|
|
16
|
-
| "llm"
|
|
17
|
-
| "dom"
|
|
18
|
-
| "dom:anchor"
|
|
19
|
-
| "notify"
|
|
20
|
-
| "storage"
|
|
21
|
-
| "secrets";
|
|
22
|
-
|
|
23
|
-
export interface WsEntry {
|
|
24
|
-
name: string;
|
|
25
|
-
type: "file" | "dir";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface WsStat extends WsEntry {
|
|
29
|
-
/** 字节数(目录为 0)。 */
|
|
30
|
-
size: number;
|
|
31
|
-
/** 修改时间毫秒时间戳。 */
|
|
32
|
-
mtime: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface UiSelectOption {
|
|
36
|
-
value: string;
|
|
37
|
-
label?: string;
|
|
38
|
-
labelEn?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** 插件注册的内联状态标记(Inline Marker)。 */
|
|
42
|
-
export interface PluginMarkerDef<State = unknown> {
|
|
43
|
-
name: string;
|
|
44
|
-
label?: string;
|
|
45
|
-
guidance: string[];
|
|
46
|
-
getGuidance?: (lang: "zh" | "en") => string[];
|
|
47
|
-
apply: (token: any, ctx: any, state: State, lang?: any) => Promise<any> | any;
|
|
48
|
-
overlay?: (state: State, ctx: any) => any;
|
|
49
|
-
init?: () => State;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type UiItemKind =
|
|
53
|
-
"view" | "action" | "badge" | "menu" | "page" | "organizer" | "divider" | "toggle" | "input" | "progress" | "select";
|
|
54
|
-
|
|
55
|
-
export interface UiContribution {
|
|
56
|
-
id: string;
|
|
57
|
-
slot?: string;
|
|
58
|
-
label: string;
|
|
59
|
-
labelEn?: string;
|
|
60
|
-
icon?: string;
|
|
61
|
-
hint?: string;
|
|
62
|
-
hintEn?: string;
|
|
63
|
-
kind?: UiItemKind;
|
|
64
|
-
children?: UiContribution[];
|
|
65
|
-
order?: number;
|
|
66
|
-
align?: "start" | "center" | "end";
|
|
67
|
-
group?: string;
|
|
68
|
-
hidden?: boolean;
|
|
69
|
-
action?: string;
|
|
70
|
-
view?: string;
|
|
71
|
-
when?: string[];
|
|
72
|
-
badge?: string;
|
|
73
|
-
checked?: boolean;
|
|
74
|
-
value?: string;
|
|
75
|
-
progress?: number;
|
|
76
|
-
options?: UiSelectOption[];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface PluginAgentTool {
|
|
80
|
-
name: string;
|
|
81
|
-
label?: string;
|
|
82
|
-
description: string;
|
|
83
|
-
promptSnippet?: string;
|
|
84
|
-
promptGuidelines?: string[];
|
|
85
|
-
parameters?: Record<string, unknown>;
|
|
86
|
-
execute(
|
|
87
|
-
toolCallId: string,
|
|
88
|
-
params: Record<string, unknown>,
|
|
89
|
-
signal?: AbortSignal,
|
|
90
|
-
onUpdate?: (partial: unknown) => void,
|
|
91
|
-
): Promise<unknown>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface PluginCommandDef {
|
|
95
|
-
name: string;
|
|
96
|
-
description?: string;
|
|
97
|
-
descriptionEn?: string;
|
|
98
|
-
argumentHint?: string;
|
|
99
|
-
argumentHintEn?: string;
|
|
100
|
-
run(args: string, ctx: { clientId?: string }): unknown | Promise<unknown>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** host.requestPermission:运行时申请能力范围(net 补主机,llm 限模型作用域)。
|
|
104
|
-
* 基础族必须已声明;用户逐条确认(可记住),无浏览器/拒绝一律 false。 */
|
|
105
|
-
export interface PluginPermissionRequest {
|
|
106
|
-
family: "net" | "llm";
|
|
107
|
-
hosts?: string[];
|
|
108
|
-
models?: string[];
|
|
109
|
-
reason?: string;
|
|
110
|
-
}
|
|
111
|
-
/** host.schedule:定时任务(毫秒间隔或 5 字段 cron)。persistent 落盘,重启后重调即重建。 */
|
|
112
|
-
export interface PluginHostScheduleOptions {
|
|
113
|
-
/** 持久任务的稳定 id(必填且合法,重启后靠它重建;每次 activate 都要重调)。 */
|
|
114
|
-
id?: string;
|
|
115
|
-
/** 重启不丢(声明 + lastRun 落盘;停止=删声明)。持久任务毫秒底线 60s。 */
|
|
116
|
-
persistent?: boolean;
|
|
117
|
-
/** 重启发现漏跑:"skip"(缺省)跳过,"once" 补跑一次(15s 缓冲)。 */
|
|
118
|
-
catchUp?: "skip" | "once";
|
|
119
|
-
/** 后台面板显示名(缺省 id)。 */
|
|
120
|
-
label?: string;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** host.fs:工作区相对方法 + 跨目录 *Path 方法(后者需用户授权)。 */
|
|
124
|
-
export interface PluginHostFs {
|
|
125
|
-
list(relDir?: string): Promise<WsEntry[]>;
|
|
126
|
-
read(relPath: string): Promise<Buffer>;
|
|
127
|
-
readText(relPath: string, maxBytes?: number): Promise<string>;
|
|
128
|
-
write(relPath: string, data: string | Uint8Array): Promise<void>;
|
|
129
|
-
remove(relPath: string): Promise<void>;
|
|
130
|
-
stat(relPath: string): Promise<WsStat>;
|
|
131
|
-
mkdir(relDir: string): Promise<void>;
|
|
132
|
-
append(relPath: string, data: string | Uint8Array): Promise<void>;
|
|
133
|
-
glob(pattern: string, relDir?: string): Promise<string[]>;
|
|
134
|
-
requestAccess(dir: string, reason?: string): Promise<boolean>;
|
|
135
|
-
authorizedDirs(): string[];
|
|
136
|
-
listPath(absDir: string): Promise<WsEntry[]>;
|
|
137
|
-
readPath(absPath: string): Promise<Buffer>;
|
|
138
|
-
readTextPath(absPath: string, maxBytes?: number): Promise<string>;
|
|
139
|
-
writePath(absPath: string, data: string | Uint8Array): Promise<void>;
|
|
140
|
-
removePath(absPath: string): Promise<void>;
|
|
141
|
-
statPath(absPath: string): Promise<WsStat>;
|
|
142
|
-
mkdirPath(absDir: string): Promise<void>;
|
|
143
|
-
appendPath(absPath: string, data: string | Uint8Array): Promise<void>;
|
|
144
|
-
globPath(absDir: string, pattern: string): Promise<string[]>;
|
|
145
|
-
watch(relPath: string, handler: (ev: { type: string; path: string }) => void): () => void;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** host.ui:运行时 UI 条目管理(manifest "ui" 是声明式基线)。 */
|
|
149
|
-
export interface PluginHostUi {
|
|
150
|
-
register(items: unknown[] | unknown): () => void;
|
|
151
|
-
update(id: string, patch: Record<string, unknown>): void;
|
|
152
|
-
remove(id: string): void;
|
|
153
|
-
arrange(ops: unknown[] | unknown): void;
|
|
154
|
-
list(): { items: UiContribution[]; arrange: unknown[] };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** host.llm.complete:孤立无工具的一次性补全(不建对话、不进历史)。
|
|
158
|
-
* 需要 manifest.permissions 含 "llm"(花用户自己的模型额度)。 */
|
|
159
|
-
export interface PluginHostLlm {
|
|
160
|
-
complete(req: { prompt: string; system?: string; model?: string; maxChars?: number; timeoutMs?: number }): Promise<{
|
|
161
|
-
ok: boolean;
|
|
162
|
-
text?: string;
|
|
163
|
-
model?: string;
|
|
164
|
-
usage?: { input: number; output: number };
|
|
165
|
-
error?: string;
|
|
166
|
-
}>;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** 工具拦截守卫看到的 pre 请求(只对 bash/read 生效,全量见 server/plugin-tool-guard.ts)。 */
|
|
170
|
-
export interface ToolGuardPreRequest {
|
|
171
|
-
toolName: "bash" | "read";
|
|
172
|
-
params: unknown;
|
|
173
|
-
conversationId?: string;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** 工具 pre 决策:allow 放行 / deny 拒绝 / ask 待确认(暂按拒绝执行)。 */
|
|
177
|
-
export type ToolGuardPreDecision =
|
|
178
|
-
| { decision: "allow" }
|
|
179
|
-
| { decision: "deny"; reason?: string; reasonEn?: string }
|
|
180
|
-
| { decision: "ask"; reason?: string; reasonEn?: string };
|
|
181
|
-
|
|
182
|
-
export interface PluginChatAttachment {
|
|
183
|
-
path: string;
|
|
184
|
-
mode?: "reference" | "inline";
|
|
185
|
-
name?: string;
|
|
186
|
-
mimeType?: string;
|
|
187
|
-
imageData?: string;
|
|
188
|
-
fileData?: string;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export interface PluginChatRequest {
|
|
192
|
-
text: string;
|
|
193
|
-
accountId?: string;
|
|
194
|
-
conversationId?: string;
|
|
195
|
-
cwd?: string;
|
|
196
|
-
model?: string;
|
|
197
|
-
thinkingLevel?: string;
|
|
198
|
-
/** Up to 8 attachments, 10 MiB each and 20 MiB total. Images use imageData (base64). */
|
|
199
|
-
attachments?: PluginChatAttachment[];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** 插件服务端入口拿到的宿主接口(精简:全量见 server/plugins.ts PluginHost)。 */
|
|
203
|
-
export interface PluginHost {
|
|
204
|
-
broadcast(payload: unknown): void;
|
|
205
|
-
notify(level: "info" | "warning" | "error", text: string, textEn?: string): void;
|
|
206
|
-
onMessage(handler: (payload: unknown, from?: string) => void): () => void;
|
|
207
|
-
/** 注册客户端上行消息处理器(RPC 模式):回调提供 (msg, reply),调用 reply(payload) 可直接向来源客户端回包。 */
|
|
208
|
-
onClientMessage(handler: (msg: unknown, reply: (payload: unknown) => void) => void | Promise<void>): () => void;
|
|
209
|
-
sendTo(clientId: string, payload: unknown): void;
|
|
210
|
-
onAttach(handler: (clientId: string) => void): () => void;
|
|
211
|
-
onToolEvent(handler: (ev: unknown) => void): () => void;
|
|
212
|
-
/** 注册工具 pre 拦截守卫(只对 bash/read 生效;要 "tools" 能力)。 */
|
|
213
|
-
onToolPre(
|
|
214
|
-
handler: (req: ToolGuardPreRequest) => ToolGuardPreDecision | void | Promise<ToolGuardPreDecision | void>,
|
|
215
|
-
): () => void;
|
|
216
|
-
/** 注册工具 post 编辑守卫(只对 bash/read 生效;要 "tools" 能力)。 */
|
|
217
|
-
onToolPost(handler: (req: unknown) => unknown): () => void;
|
|
218
|
-
onRunEvent(handler: (ev: unknown) => void): () => void;
|
|
219
|
-
/** 读对话快照。传 `{clientId}` = 该标签页正在看的对话;不传 = 最近活跃的非子代理会话。 */
|
|
220
|
-
getActiveConversation(options?: { clientId?: string; fallback?: "latest-non-subagent" }): unknown;
|
|
221
|
-
onConversationChanged(handler: () => void): () => void;
|
|
222
|
-
/** 订阅模型切换成功(回调带 clientId / conversationId / model / isSubagent… 的快照)。 */
|
|
223
|
-
onClientModelChanged(handler: (snap: unknown) => void): () => void;
|
|
224
|
-
registerAgentTool(tool: PluginAgentTool): () => void;
|
|
225
|
-
/** 注册一个内联标记(Inline Marker)。 */
|
|
226
|
-
registerMarker<State = unknown>(marker: any): () => void;
|
|
227
|
-
/** 注册一个供 AI 调用的工具(单参数 execute(args) 兼容接口,内部适配并转调 registerAgentTool)。 */
|
|
228
|
-
registerTool(tool: {
|
|
229
|
-
name: string;
|
|
230
|
-
description: string;
|
|
231
|
-
label?: string;
|
|
232
|
-
promptSnippet?: string;
|
|
233
|
-
promptGuidelines?: string[];
|
|
234
|
-
parameters?: Record<string, unknown>;
|
|
235
|
-
execute(args: Record<string, unknown>): Promise<unknown>;
|
|
236
|
-
}): () => void;
|
|
237
|
-
/** 注册一个内联标记(Inline Marker),如 [[name:op:body]]。 */
|
|
238
|
-
registerMarker<State = unknown>(marker: PluginMarkerDef<State>): () => void;
|
|
239
|
-
dir: string;
|
|
240
|
-
dataDir: string;
|
|
241
|
-
readonly cwd: string;
|
|
242
|
-
onCwdChange(handler: (cwd: string) => void): () => void;
|
|
243
|
-
registerCommand(cmd: PluginCommandDef): () => void;
|
|
244
|
-
/** 执行已注册的插件斜杠命令(如 /todo, /note 等);返回结果或错误。 */
|
|
245
|
-
execCommand?(
|
|
246
|
-
name: string,
|
|
247
|
-
args: string,
|
|
248
|
-
context?: { clientId?: string },
|
|
249
|
-
): Promise<{ ok: boolean; result?: string; error?: string }>;
|
|
250
|
-
/** 获取当前系统注册的全部插件命令列表。 */
|
|
251
|
-
getPluginCommands?(): PluginCommandDef[];
|
|
252
|
-
/** 获取最近项目路径列表。 */
|
|
253
|
-
listProjects?(): string[];
|
|
254
|
-
/** 调起系统级目录浏览器弹窗选择文件夹。 */
|
|
255
|
-
pickDirectory?(opts?: {
|
|
256
|
-
initialPath?: string;
|
|
257
|
-
title?: string;
|
|
258
|
-
}): Promise<{ ok: boolean; path?: string; canceled?: boolean; error?: string }>;
|
|
259
|
-
/** 调起系统级模型选择器弹窗选择模型。 */
|
|
260
|
-
pickModel?(opts?: {
|
|
261
|
-
currentModelId?: string | null;
|
|
262
|
-
title?: string;
|
|
263
|
-
}): Promise<{ ok: boolean; modelId?: string; name?: string; provider?: string; canceled?: boolean; error?: string }>;
|
|
264
|
-
/** 挂载 HTTP 路由(实际暴露为 /plugins-api/<id><path>;要 "http" 能力;返回注销函数)。 */
|
|
265
|
-
route(
|
|
266
|
-
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
267
|
-
path: string,
|
|
268
|
-
handler: (req: unknown, res: unknown) => void,
|
|
269
|
-
): () => void;
|
|
270
|
-
/** 注册通用反向代理前缀(子路径去前缀透传到 127.0.0.1:port;要 "http" 能力;返回注销函数)。 */
|
|
271
|
-
registerProxy(prefix: string, target: number | { port: number; host?: string }): () => void;
|
|
272
|
-
ui: PluginHostUi;
|
|
273
|
-
llm: PluginHostLlm;
|
|
274
|
-
storage: {
|
|
275
|
-
get<T>(key: string, fallback?: T): T | undefined;
|
|
276
|
-
set(key: string, value: unknown): void;
|
|
277
|
-
delete(key: string): void;
|
|
278
|
-
has(key: string): boolean;
|
|
279
|
-
keys(): string[];
|
|
280
|
-
clear(preserveSettings?: boolean): void;
|
|
281
|
-
all(): Record<string, unknown>;
|
|
282
|
-
};
|
|
283
|
-
/** 插件间服务总线(Service Registry / Bus):跨插件服务发布与获取。 */
|
|
284
|
-
services: {
|
|
285
|
-
provide<T>(name: string, service: T): () => void;
|
|
286
|
-
get<T>(name: string): T | undefined;
|
|
287
|
-
has(name: string): boolean;
|
|
288
|
-
list(): Array<{ name: string; pluginId: string }>;
|
|
289
|
-
on<T>(name: string, handler: (service: T | undefined) => void): () => void;
|
|
290
|
-
};
|
|
291
|
-
provide<T>(name: string, service: T): () => void;
|
|
292
|
-
get<T>(name: string): T | undefined;
|
|
293
|
-
onService<T>(name: string, handler: (service: T | undefined) => void): () => void;
|
|
294
|
-
secrets: {
|
|
295
|
-
set(name: string, value: string): void;
|
|
296
|
-
get(name: string): string | undefined;
|
|
297
|
-
has(name: string): boolean;
|
|
298
|
-
delete(name: string): void;
|
|
299
|
-
list(): string[];
|
|
300
|
-
getAll(): Record<string, string>;
|
|
301
|
-
};
|
|
302
|
-
ensureDeps(specs: string[], opts?: { onProgress?: (msg: string) => void }): Promise<boolean>;
|
|
303
|
-
fs: PluginHostFs;
|
|
304
|
-
schedule(spec: string | number, fn: () => void, opts?: PluginHostScheduleOptions): () => void;
|
|
305
|
-
assets: {
|
|
306
|
-
ensure(spec: any, opts?: any): Promise<{ ok: boolean; ready?: boolean; error?: string; path?: string }>;
|
|
307
|
-
status(spec: any): { ready: boolean; downloading?: boolean; error?: string };
|
|
308
|
-
};
|
|
309
|
-
requestPermission(req: PluginPermissionRequest): Promise<boolean>;
|
|
310
|
-
getSettings(): Record<string, unknown>;
|
|
311
|
-
onSettingsChanged(handler: (values: Record<string, unknown>) => void): () => void;
|
|
312
|
-
/** 分级运行时日志:host.log(level?, ...args)(level 缺省 "info")。
|
|
313
|
-
* 首参是 "debug"|"info"|"warn"|"error" 之一即当级别,老写法的
|
|
314
|
-
* host.log(...args) 照旧按 info 走。全部进宿主内存环形缓冲(每插件最近
|
|
315
|
-
* 200 条,单条截断 500 字符,不落盘);error 级同时走 console.error。
|
|
316
|
-
* 用户在设置面板“界面插件”页点某插件的“日志”按需查看(级别过滤 + 清空)。 */
|
|
317
|
-
log(level?: "debug" | "info" | "warn" | "error", ...args: unknown[]): void;
|
|
318
|
-
/** 登记一条**自建**的可逆副作用(自建 setInterval / event 监听 / WebSocket…):
|
|
319
|
-
* 返回的注销函数与插件反激活**都会**调 dispose。宿主自己的每个注册面已在内部
|
|
320
|
-
* 走同一个 effect 栈,这里只用于「宿主管不到的那些」—— 挂进来就不怕漏注销
|
|
321
|
-
* (热重载后定时器叠加、监听器堆积都是这个漏法的症状)。dispose 请写成幂等的。 */
|
|
322
|
-
effect(label: string, dispose: () => void): () => void;
|
|
323
|
-
/** 安全解析工作区相对/绝对路径:落在工作区或额外根内放行,越界抛带 statusCode=403 的错误。 */
|
|
324
|
-
resolveInWorkspace(relOrAbsPath: string): string;
|
|
325
|
-
/** 带有默认超时(默认 30s)与插件生命周期绑定的安全 fetch。 */
|
|
326
|
-
fetch(input: string | URL | Request, init?: RequestInit & { timeoutMs?: number }): Promise<Response>;
|
|
327
|
-
/** 宿主重资产流水线(Heavy Asset Pipeline)。 */
|
|
328
|
-
assets: {
|
|
329
|
-
ensure(
|
|
330
|
-
spec: {
|
|
331
|
-
id: string;
|
|
332
|
-
targetDir: string;
|
|
333
|
-
urls: string[];
|
|
334
|
-
sha256?: string;
|
|
335
|
-
testFile?: string;
|
|
336
|
-
size?: number;
|
|
337
|
-
description?: string;
|
|
338
|
-
},
|
|
339
|
-
opts?: {
|
|
340
|
-
onProgress?: (progress: { downloaded: number; total: number; percent: number; url: string }) => void;
|
|
341
|
-
timeoutMs?: number;
|
|
342
|
-
},
|
|
343
|
-
): Promise<{ ok: boolean; targetDir: string; cached?: boolean; sha256?: string; error?: string }>;
|
|
344
|
-
status(spec: {
|
|
345
|
-
id: string;
|
|
346
|
-
targetDir: string;
|
|
347
|
-
urls: string[];
|
|
348
|
-
sha256?: string;
|
|
349
|
-
testFile?: string;
|
|
350
|
-
size?: number;
|
|
351
|
-
description?: string;
|
|
352
|
-
}): {
|
|
353
|
-
ready: boolean;
|
|
354
|
-
downloading: boolean;
|
|
355
|
-
progress: number;
|
|
356
|
-
downloaded: number;
|
|
357
|
-
total: number;
|
|
358
|
-
error: string | null;
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
/** 无头调用:把外部通道文本投给 agent(要 "chat" 能力;宿主未接 chatProvider
|
|
362
|
-
* 时 reject(由 chatWait 包成 {ok:false},插件侧用 chatWait 更省心)。 */
|
|
363
|
-
chat(req: PluginChatRequest): Promise<{
|
|
364
|
-
/** Present only on mock hosts or older integrations; real failures reject. */
|
|
365
|
-
ok?: boolean;
|
|
366
|
-
conversationId: string;
|
|
367
|
-
clientId: string;
|
|
368
|
-
runId?: string;
|
|
369
|
-
}>;
|
|
370
|
-
/** 等待无头调用的运行结束(默认 120s 超时;无注入/超时/失败一律回 {ok:false},绝不抛错)。 */
|
|
371
|
-
chatWait(
|
|
372
|
-
req: PluginChatRequest,
|
|
373
|
-
opts?: { timeoutMs?: number },
|
|
374
|
-
): Promise<{ ok: boolean; conversationId?: string; error?: string }>;
|
|
375
|
-
/** 对话读写:无注入时 list/search 回 []、get 回 null,绝不抛错。 */
|
|
376
|
-
conversations: {
|
|
377
|
-
list(): Array<{ id: string; title: string }> | Promise<Array<{ id: string; title: string }>>;
|
|
378
|
-
get(id: string): unknown;
|
|
379
|
-
search(
|
|
380
|
-
query: string,
|
|
381
|
-
limit?: number,
|
|
382
|
-
): Array<{ id: string; title: string }> | Promise<Array<{ id: string; title: string }>>;
|
|
383
|
-
};
|
|
384
|
-
/** 向指定对话发一条用户消息(无注入回 {ok:false},绝不抛错)。 */
|
|
385
|
-
prompt(
|
|
386
|
-
conversationId: string,
|
|
387
|
-
req: { text: string; attachments?: Array<{ path: string; mode?: string }> },
|
|
388
|
-
): Promise<{ ok: boolean; error?: string }>;
|
|
389
|
-
/** 插队指定对话的当前运行(无注入回 {ok:false},绝不抛错)。 */
|
|
390
|
-
steer(conversationId: string, text: string): Promise<{ ok: boolean; error?: string }>;
|
|
391
|
-
/** Abort by stable plugin runId (pr- prefix, survives takeover), or legacy local conversationId. */
|
|
392
|
-
abortRun(conversationId: string): Promise<{ ok: boolean; error?: string }>;
|
|
393
|
-
/** 项目组装:在已授权目录里建目录/clone 仓库/写文件(失败回 {ok:false,error},不留半成品)。 */
|
|
394
|
-
project: {
|
|
395
|
-
create(spec: { dir: string; [key: string]: unknown }): Promise<{
|
|
396
|
-
ok: boolean;
|
|
397
|
-
dir: string;
|
|
398
|
-
log: string[];
|
|
399
|
-
error?: string;
|
|
400
|
-
}>;
|
|
401
|
-
};
|
|
402
|
-
/** P3:左栏「运行的对话」里的插件运行条目(仅展示,需要能力 "ui")。setRunning 整体替换本插件的
|
|
403
|
-
* 条目,同时作为心跳:超过 ttlMs(缺省 60 秒,夹取 5 秒–1 小时)没有再次调用就整组自动清空;
|
|
404
|
-
* clear() 立即清空;反激活时自动清空。item.action 点击时交给本插件浏览器 bundle 的 onUiAction。 */
|
|
405
|
-
leftPanel: {
|
|
406
|
-
setRunning(
|
|
407
|
-
items: Array<{
|
|
408
|
-
id: string;
|
|
409
|
-
title: string;
|
|
410
|
-
hint?: string;
|
|
411
|
-
status?: "running" | "done" | "error";
|
|
412
|
-
icon?: string;
|
|
413
|
-
action?: string;
|
|
414
|
-
}>,
|
|
415
|
-
opts?: { ttlMs?: number },
|
|
416
|
-
): void;
|
|
417
|
-
clear(): void;
|
|
418
|
-
};
|
|
419
|
-
/** 常驻后台任务(顶栏「后台任务」面板;返回 update/unregister)。支持心跳探活回调 check 与间隔 intervalMs。 */
|
|
420
|
-
registerBackgroundTask(task: {
|
|
421
|
-
id: string;
|
|
422
|
-
label: string;
|
|
423
|
-
stop?: () => void;
|
|
424
|
-
status?: string;
|
|
425
|
-
check?: () =>
|
|
426
|
-
boolean | { alive: boolean; status?: string } | Promise<boolean | { alive: boolean; status?: string }>;
|
|
427
|
-
intervalMs?: number;
|
|
428
|
-
maxFailures?: number;
|
|
429
|
-
onDead?: (reason?: string) => void;
|
|
430
|
-
}): {
|
|
431
|
-
update(next: Partial<{ label: string; status: string; stop: () => void }>): void;
|
|
432
|
-
unregister(): void;
|
|
433
|
-
};
|
|
434
|
-
/** 插件可见的模型列表(无注入回 [])。 */
|
|
435
|
-
models: {
|
|
436
|
-
list(): Array<{ id: string; [key: string]: unknown }> | Promise<Array<{ id: string; [key: string]: unknown }>>;
|
|
437
|
-
};
|
|
438
|
-
/** MCP 服务器检测与便捷安装接口(list/check 只读免权限;install 要 "tools";promptInstall 要 "chat" 或 "tools")。 */
|
|
439
|
-
mcp: {
|
|
440
|
-
list(): Promise<Array<{ name: string; scope: "global" | "project"; status: string; [key: string]: unknown }>>;
|
|
441
|
-
check(query: string): Promise<{
|
|
442
|
-
installed: boolean;
|
|
443
|
-
running: boolean;
|
|
444
|
-
enabled: boolean;
|
|
445
|
-
server: Record<string, unknown> | null;
|
|
446
|
-
matches: Array<Record<string, unknown>>;
|
|
447
|
-
tools: Array<{ name: string; description?: string }>;
|
|
448
|
-
}>;
|
|
449
|
-
install(spec: {
|
|
450
|
-
name?: string;
|
|
451
|
-
package?: string;
|
|
452
|
-
command?: string;
|
|
453
|
-
args?: string[];
|
|
454
|
-
cwd?: string;
|
|
455
|
-
env?: Record<string, string>;
|
|
456
|
-
url?: string;
|
|
457
|
-
headers?: Record<string, string>;
|
|
458
|
-
type?: "stdio" | "http" | "streamable-http";
|
|
459
|
-
timeout?: number;
|
|
460
|
-
description?: string;
|
|
461
|
-
scope?: "global" | "project";
|
|
462
|
-
enabled?: boolean;
|
|
463
|
-
}): Promise<{
|
|
464
|
-
ok: boolean;
|
|
465
|
-
name?: string;
|
|
466
|
-
scope?: "global" | "project";
|
|
467
|
-
status?: string;
|
|
468
|
-
tools?: Array<{ name: string; description?: string }>;
|
|
469
|
-
server?: Record<string, unknown>;
|
|
470
|
-
error?: string;
|
|
471
|
-
}>;
|
|
472
|
-
promptInstall(
|
|
473
|
-
target: string | Record<string, unknown>,
|
|
474
|
-
opts?: { conversationId?: string; scope?: "global" | "project" },
|
|
475
|
-
): Promise<{ ok: boolean; conversationId?: string; error?: string }>;
|
|
476
|
-
};
|
|
477
|
-
/** 会话统计 / 流式增量订阅(返回注销函数)。 */
|
|
478
|
-
onStats(handler: (s: unknown) => void): () => void;
|
|
479
|
-
onStreaming(handler: (ev: { conversationId?: string; delta: string }) => void): () => void;
|
|
480
|
-
/** 出站网络(要 "net" 能力 + 主机白名单;失败一律 {ok:false,error},绝不抛错)。 */
|
|
481
|
-
net: {
|
|
482
|
-
fetch(
|
|
483
|
-
url: string,
|
|
484
|
-
init?: { method?: string; body?: string; headers?: Record<string, string> },
|
|
485
|
-
): Promise<{ ok: boolean; status?: number; text?: string; error?: string }>;
|
|
486
|
-
};
|
|
487
|
-
/** 插件间事件总线(emit 回填 from;on 返回取消函数)。 */
|
|
488
|
-
events: {
|
|
489
|
-
emit(topic: string, payload?: unknown): void;
|
|
490
|
-
on(topic: string, handler: (ev: unknown) => void): () => void;
|
|
491
|
-
};
|
|
492
|
-
/** 只读 git 查询(失败回 {ok:false,error} 对象而非抛错)。 */
|
|
493
|
-
scm: {
|
|
494
|
-
status(): Promise<unknown>;
|
|
495
|
-
log(path?: string, limit?: number): Promise<unknown>;
|
|
496
|
-
};
|
|
497
|
-
/** 受限 shell(cwd 缺省当前工作区;默认超时 60s;要 "tools" 能力)。 */
|
|
498
|
-
bash(
|
|
499
|
-
cmd: string,
|
|
500
|
-
opts?: { cwd?: string; timeoutMs?: number },
|
|
501
|
-
): Promise<{
|
|
502
|
-
ok: boolean;
|
|
503
|
-
output: string;
|
|
504
|
-
exitCode?: number;
|
|
505
|
-
error?: string;
|
|
506
|
-
}>;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
/** 插件服务端入口形状(activate 必填,deactivate 可选)。 */
|
|
510
|
-
export interface PluginModule {
|
|
511
|
-
activate(host: PluginHost): void | Promise<void>;
|
|
512
|
-
deactivate?: () => void;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/** 插件宿主动作桥(window.__piWebUiHost,client bundle 用)。版本号见 PLUGIN_HOST_API_VERSION。 */
|
|
516
|
-
export interface PluginHostBridge {
|
|
517
|
-
version: number;
|
|
518
|
-
setView(view: string): void;
|
|
519
|
-
/** 打开一个 `modal.dialog` 槽位的条目(全局 id `<pluginId>:<itemId>`;
|
|
520
|
-
* 不存在/被隐藏返回 false,同一时刻只开一个)。 */
|
|
521
|
-
openModal(id: string): boolean;
|
|
522
|
-
/** 关掉当前弹窗(幂等)。 */
|
|
523
|
-
closeModal(): boolean;
|
|
524
|
-
onUiAction(action: string, handler: (itemId: string, value?: string) => void): () => void;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/** 插件视图入口形状(client/entry.mjs 默认导出)。 */
|
|
528
|
-
export interface PluginViewModule {
|
|
529
|
-
mount(el: HTMLElement, ctx: PluginViewContext): void | (() => void);
|
|
530
|
-
cleanup?: () => void;
|
|
531
|
-
renderers?: Record<string, (code: string, ctx: PluginViewContext) => HTMLElement | null>;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
/** 视图 ctx(窄通道:只依赖 send/onData;动作回调走 window.__piWebUiHost.onUiAction,见 sdk onUiAction)。 */
|
|
535
|
-
export interface PluginViewContext {
|
|
536
|
-
send(payload: unknown): void;
|
|
537
|
-
onData(handler: (payload: unknown) => void): () => void;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
export declare function definePlugin(def: PluginModule): PluginModule;
|
|
541
|
-
export declare function defineView(view: PluginViewModule): PluginViewModule;
|
|
542
|
-
export declare function defineRenderer(
|
|
543
|
-
renderers: Record<string, (code: string, ctx: PluginViewContext) => HTMLElement | null>,
|
|
544
|
-
): Pick<PluginViewModule, "renderers">;
|
|
545
|
-
export declare function actionHandler(
|
|
546
|
-
map: Record<string, (value?: string) => void>,
|
|
547
|
-
): (itemId: string, value?: string) => void;
|
|
548
|
-
export declare function onUiAction(action: string, handler: (itemId: string, value?: string) => void): () => void;
|
|
549
|
-
export declare function getSetting<T>(host: PluginHost, key: string, fallback: T): T;
|
|
550
|
-
export declare function selectOptions(list: Array<string | UiSelectOption>): UiSelectOption[];
|
|
551
|
-
|
|
552
|
-
/** SDK 版本(与 plugin-sdk/package.json 的 version 保持一致,单测锁定)。 */
|
|
553
|
-
export declare const SDK_VERSION: string;
|
|
554
|
-
|
|
555
|
-
/** createMockHost 的一条调用记录(method 如 "ui.register"、"fs.readText";log 也记)。 */
|
|
556
|
-
export interface MockHostCall {
|
|
557
|
-
method: string;
|
|
558
|
-
args: unknown[];
|
|
559
|
-
/** 本次记录窗口内的序号(0 起;reset() 后新记录重新从 0 开始)。 */
|
|
560
|
-
seq: number;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/** createMockHost 的一条分级日志(log 被 overrides 整体替换时不再写这里)。 */
|
|
564
|
-
export interface MockHostLogEntry {
|
|
565
|
-
level: "debug" | "info" | "warn" | "error";
|
|
566
|
-
text: string;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/** createMockHost(overrides?):settings/cwd/dir/dataDir 是专用键;命名空间键
|
|
570
|
-
* (fs/ui/llm/conversations/scm/net/events/models/storage/secrets/project/dialogs/
|
|
571
|
-
* shortcuts/searchProviders/composerProviders/assets)传对象 = 按子键合并覆盖;其余键整体
|
|
572
|
-
* 替换对应方法(仍进 calls 记录)。`calls`/`logs`/`mock`/`reset` 不可覆盖。 */
|
|
573
|
-
export interface MockHostOverrides {
|
|
574
|
-
settings?: Record<string, unknown>;
|
|
575
|
-
cwd?: string;
|
|
576
|
-
dir?: string;
|
|
577
|
-
dataDir?: string;
|
|
578
|
-
[key: string]: unknown;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
/** mock 命名空间:handlers 活视图 + emit/emitAsync/setSettings/emitSettings 驱动器
|
|
582
|
-
* + calls 过滤 + 注册表活视图(agentTools/commands/routes/schedules)+ fireSchedules。 */
|
|
583
|
-
export interface MockHostControls {
|
|
584
|
-
/** 方法名 → 已注册 handler 数组(活引用,与注销函数联动)。 */
|
|
585
|
-
handlers: Record<string, Array<(...args: any[]) => unknown>>;
|
|
586
|
-
/** 主动触发某订阅方法的 handlers(错误直接抛给测试,不吞)。 */
|
|
587
|
-
emit(method: string, ...args: unknown[]): void;
|
|
588
|
-
/** 异步版:按注册顺序依次 await,返回各 handler 返回值(抛错即 reject,不吞)。 */
|
|
589
|
-
emitAsync(method: string, ...args: unknown[]): Promise<unknown[]>;
|
|
590
|
-
/** 按方法名过滤调用记录(不传即全部拷贝)。 */
|
|
591
|
-
calls(method?: string): MockHostCall[];
|
|
592
|
-
/** 合并 settings 预设(返回同一引用,getSettings() 读到的就是它)。 */
|
|
593
|
-
setSettings(next: Record<string, unknown>): Record<string, unknown>;
|
|
594
|
-
/** 合并预设 + 触发 onSettingsChanged(模拟用户在设置面板保存)。 */
|
|
595
|
-
emitSettings(next?: Record<string, unknown>): Record<string, unknown>;
|
|
596
|
-
/** 已注册的 Agent 工具定义(活数组,注销即摘除;工具的 execute 可直接调)。 */
|
|
597
|
-
agentTools: Array<PluginAgentTool>;
|
|
598
|
-
/** 已注册的内联标记定义(活数组,注销即摘除)。 */
|
|
599
|
-
markers: Array<PluginMarkerDef<unknown>>;
|
|
600
|
-
/** 已注册的斜杠命令定义(活数组,注销即摘除)。 */
|
|
601
|
-
commands: Array<PluginCommandDef>;
|
|
602
|
-
/** 已挂载的路由表(活数组,注销即摘除)。 */
|
|
603
|
-
routes: Array<{ method: string; path: string; handler: (req: unknown, res: unknown) => void }>;
|
|
604
|
-
/** 已注册的代理前缀(活数组,注销即摘除)。 */
|
|
605
|
-
proxies: Array<{ prefix: string; target: number | { port: number; host?: string } }>;
|
|
606
|
-
/** 已登记的定时任务(活数组 {spec, fn, opts};schedule() 不设真定时器,注销即摘除)。 */
|
|
607
|
-
schedules: Array<{ spec: string | number; fn: () => void; opts?: PluginHostScheduleOptions }>;
|
|
608
|
-
/** 依次触发全部已登记的定时回调(返回各回调返回值;抛错即 reject)。 */
|
|
609
|
-
fireSchedules(): Promise<unknown[]>;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/** 浏览器桥兼容(client 侧逻辑单测也能用同一个 mock):无注入回退语义。 */
|
|
613
|
-
export interface MockHostDialogs {
|
|
614
|
-
select(opts: {
|
|
615
|
-
title?: string;
|
|
616
|
-
options?: unknown;
|
|
617
|
-
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
618
|
-
[key: string]: unknown;
|
|
619
|
-
}): Promise<{
|
|
620
|
-
ok: boolean;
|
|
621
|
-
selected?: string[];
|
|
622
|
-
error?: string;
|
|
623
|
-
}>;
|
|
624
|
-
confirm(opts: {
|
|
625
|
-
title?: string;
|
|
626
|
-
text?: string;
|
|
627
|
-
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
628
|
-
[key: string]: unknown;
|
|
629
|
-
}): Promise<boolean>;
|
|
630
|
-
input(opts: {
|
|
631
|
-
title?: string;
|
|
632
|
-
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
633
|
-
[key: string]: unknown;
|
|
634
|
-
}): Promise<{ ok: boolean; value?: string }>;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/** createMockHost 返回的 mock host(PluginHost 全量 + harness 字段 + 桥兼容)。 */
|
|
638
|
-
export interface MockHost extends PluginHost {
|
|
639
|
-
/** 全量调用记录({method, args},含 log/storage 等)。 */
|
|
640
|
-
calls: MockHostCall[];
|
|
641
|
-
/** 分级日志条目。 */
|
|
642
|
-
logs: MockHostLogEntry[];
|
|
643
|
-
/** 测试驱动器(handlers/emit/setSettings/emitSettings)。 */
|
|
644
|
-
mock: MockHostControls;
|
|
645
|
-
/** 清空 calls + logs(原地;settings/handlers/注册表这些 fake 状态保留,
|
|
646
|
-
* 要全新状态就重新 createMockHost())。 */
|
|
647
|
-
reset(): void;
|
|
648
|
-
dialogs: MockHostDialogs;
|
|
649
|
-
notifyAction(opts: { text: string; actions: Array<{ id: string; label: string }> }): Promise<string | null>;
|
|
650
|
-
shortcuts: {
|
|
651
|
-
register(shortcut: string, handler: () => void): () => void;
|
|
652
|
-
};
|
|
653
|
-
searchProviders: {
|
|
654
|
-
register(provider: {
|
|
655
|
-
id: string;
|
|
656
|
-
label: string;
|
|
657
|
-
search: (q: string) => Promise<Array<{ title: string; hint?: string; action: string }>>;
|
|
658
|
-
}): () => void;
|
|
659
|
-
list(): Array<{ id: string; label: string }>;
|
|
660
|
-
};
|
|
661
|
-
composerProviders: {
|
|
662
|
-
register(provider: {
|
|
663
|
-
id: string;
|
|
664
|
-
label: string;
|
|
665
|
-
search: (q: string) => Promise<Array<{ title: string; hint?: string; text?: string }>>;
|
|
666
|
-
}): () => void;
|
|
667
|
-
list(): Array<{ id: string; label: string }>;
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
export declare function createMockHost(overrides?: MockHostOverrides): MockHost;
|
|
672
|
-
|
|
673
|
-
/** 安全 HTML 实体转义。 */
|
|
674
|
-
export declare function esc(s: unknown): string;
|
|
675
|
-
|
|
676
|
-
/** 安全取用 window.__piWebUiHost 宿主桥接 API。 */
|
|
677
|
-
export declare function hostApi(): any;
|
|
678
|
-
|
|
679
|
-
/** 获取插件服务端路由的统一根路径。 */
|
|
680
|
-
export declare function apiBase(pluginId: string): string;
|
|
681
|
-
|
|
682
|
-
/** 格式化字节大小为人类可读字符串(B / KB / MB / GB)。 */
|
|
683
|
-
export declare function formatBytes(bytes: number | unknown, decimals?: number): string;
|
|
684
|
-
|
|
685
|
-
/** 为异步操作施加超时限制。 */
|
|
686
|
-
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMsg?: string): Promise<T>;
|
|
687
|
-
|
|
688
|
-
/** 生成随机 UUID。 */
|
|
689
|
-
export declare function uuid(): string;
|
|
690
|
-
|
|
691
|
-
/** 归一化相对路径(反斜杠转斜杠、去除首尾多余斜杠与 "./")。 */
|
|
692
|
-
export declare function normalizeRel(p: string): string;
|
|
693
|
-
|
|
694
|
-
/** 计算安全的截断位置,避免割裂 UTF-16 代理对。 */
|
|
695
|
-
export declare function safeSliceIndex(value: string, limit: number): number;
|
|
696
|
-
|
|
697
|
-
/** 结构感知 Markdown 分块工具(保护代码围栏不跨块破坏)。 */
|
|
698
|
-
export declare function chunkMarkdownText(text: string, limit?: number): string[];
|
|
1
|
+
/**
|
|
2
|
+
* pi-web-ui 插件 SDK 类型(starter,自包含,不引用 server/ 目录)。
|
|
3
|
+
* 与 server/plugins.ts 的 PluginHost 同语义的精简版:写插件时抄 autocomplete 用,
|
|
4
|
+
* 运行时以宿主实际注入为准(宿主 API 版本见 PLUGIN_API_VERSION)。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type PluginPermissionFamily =
|
|
8
|
+
| "fs"
|
|
9
|
+
| "fs:read"
|
|
10
|
+
| "fs:write"
|
|
11
|
+
| "ui"
|
|
12
|
+
| "tools"
|
|
13
|
+
| "http"
|
|
14
|
+
| "chat"
|
|
15
|
+
| "net"
|
|
16
|
+
| "llm"
|
|
17
|
+
| "dom"
|
|
18
|
+
| "dom:anchor"
|
|
19
|
+
| "notify"
|
|
20
|
+
| "storage"
|
|
21
|
+
| "secrets";
|
|
22
|
+
|
|
23
|
+
export interface WsEntry {
|
|
24
|
+
name: string;
|
|
25
|
+
type: "file" | "dir";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WsStat extends WsEntry {
|
|
29
|
+
/** 字节数(目录为 0)。 */
|
|
30
|
+
size: number;
|
|
31
|
+
/** 修改时间毫秒时间戳。 */
|
|
32
|
+
mtime: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface UiSelectOption {
|
|
36
|
+
value: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
labelEn?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 插件注册的内联状态标记(Inline Marker)。 */
|
|
42
|
+
export interface PluginMarkerDef<State = unknown> {
|
|
43
|
+
name: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
guidance: string[];
|
|
46
|
+
getGuidance?: (lang: "zh" | "en") => string[];
|
|
47
|
+
apply: (token: any, ctx: any, state: State, lang?: any) => Promise<any> | any;
|
|
48
|
+
overlay?: (state: State, ctx: any) => any;
|
|
49
|
+
init?: () => State;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type UiItemKind =
|
|
53
|
+
"view" | "action" | "badge" | "menu" | "page" | "organizer" | "divider" | "toggle" | "input" | "progress" | "select";
|
|
54
|
+
|
|
55
|
+
export interface UiContribution {
|
|
56
|
+
id: string;
|
|
57
|
+
slot?: string;
|
|
58
|
+
label: string;
|
|
59
|
+
labelEn?: string;
|
|
60
|
+
icon?: string;
|
|
61
|
+
hint?: string;
|
|
62
|
+
hintEn?: string;
|
|
63
|
+
kind?: UiItemKind;
|
|
64
|
+
children?: UiContribution[];
|
|
65
|
+
order?: number;
|
|
66
|
+
align?: "start" | "center" | "end";
|
|
67
|
+
group?: string;
|
|
68
|
+
hidden?: boolean;
|
|
69
|
+
action?: string;
|
|
70
|
+
view?: string;
|
|
71
|
+
when?: string[];
|
|
72
|
+
badge?: string;
|
|
73
|
+
checked?: boolean;
|
|
74
|
+
value?: string;
|
|
75
|
+
progress?: number;
|
|
76
|
+
options?: UiSelectOption[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface PluginAgentTool {
|
|
80
|
+
name: string;
|
|
81
|
+
label?: string;
|
|
82
|
+
description: string;
|
|
83
|
+
promptSnippet?: string;
|
|
84
|
+
promptGuidelines?: string[];
|
|
85
|
+
parameters?: Record<string, unknown>;
|
|
86
|
+
execute(
|
|
87
|
+
toolCallId: string,
|
|
88
|
+
params: Record<string, unknown>,
|
|
89
|
+
signal?: AbortSignal,
|
|
90
|
+
onUpdate?: (partial: unknown) => void,
|
|
91
|
+
): Promise<unknown>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PluginCommandDef {
|
|
95
|
+
name: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
descriptionEn?: string;
|
|
98
|
+
argumentHint?: string;
|
|
99
|
+
argumentHintEn?: string;
|
|
100
|
+
run(args: string, ctx: { clientId?: string }): unknown | Promise<unknown>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** host.requestPermission:运行时申请能力范围(net 补主机,llm 限模型作用域)。
|
|
104
|
+
* 基础族必须已声明;用户逐条确认(可记住),无浏览器/拒绝一律 false。 */
|
|
105
|
+
export interface PluginPermissionRequest {
|
|
106
|
+
family: "net" | "llm";
|
|
107
|
+
hosts?: string[];
|
|
108
|
+
models?: string[];
|
|
109
|
+
reason?: string;
|
|
110
|
+
}
|
|
111
|
+
/** host.schedule:定时任务(毫秒间隔或 5 字段 cron)。persistent 落盘,重启后重调即重建。 */
|
|
112
|
+
export interface PluginHostScheduleOptions {
|
|
113
|
+
/** 持久任务的稳定 id(必填且合法,重启后靠它重建;每次 activate 都要重调)。 */
|
|
114
|
+
id?: string;
|
|
115
|
+
/** 重启不丢(声明 + lastRun 落盘;停止=删声明)。持久任务毫秒底线 60s。 */
|
|
116
|
+
persistent?: boolean;
|
|
117
|
+
/** 重启发现漏跑:"skip"(缺省)跳过,"once" 补跑一次(15s 缓冲)。 */
|
|
118
|
+
catchUp?: "skip" | "once";
|
|
119
|
+
/** 后台面板显示名(缺省 id)。 */
|
|
120
|
+
label?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** host.fs:工作区相对方法 + 跨目录 *Path 方法(后者需用户授权)。 */
|
|
124
|
+
export interface PluginHostFs {
|
|
125
|
+
list(relDir?: string): Promise<WsEntry[]>;
|
|
126
|
+
read(relPath: string): Promise<Buffer>;
|
|
127
|
+
readText(relPath: string, maxBytes?: number): Promise<string>;
|
|
128
|
+
write(relPath: string, data: string | Uint8Array): Promise<void>;
|
|
129
|
+
remove(relPath: string): Promise<void>;
|
|
130
|
+
stat(relPath: string): Promise<WsStat>;
|
|
131
|
+
mkdir(relDir: string): Promise<void>;
|
|
132
|
+
append(relPath: string, data: string | Uint8Array): Promise<void>;
|
|
133
|
+
glob(pattern: string, relDir?: string): Promise<string[]>;
|
|
134
|
+
requestAccess(dir: string, reason?: string): Promise<boolean>;
|
|
135
|
+
authorizedDirs(): string[];
|
|
136
|
+
listPath(absDir: string): Promise<WsEntry[]>;
|
|
137
|
+
readPath(absPath: string): Promise<Buffer>;
|
|
138
|
+
readTextPath(absPath: string, maxBytes?: number): Promise<string>;
|
|
139
|
+
writePath(absPath: string, data: string | Uint8Array): Promise<void>;
|
|
140
|
+
removePath(absPath: string): Promise<void>;
|
|
141
|
+
statPath(absPath: string): Promise<WsStat>;
|
|
142
|
+
mkdirPath(absDir: string): Promise<void>;
|
|
143
|
+
appendPath(absPath: string, data: string | Uint8Array): Promise<void>;
|
|
144
|
+
globPath(absDir: string, pattern: string): Promise<string[]>;
|
|
145
|
+
watch(relPath: string, handler: (ev: { type: string; path: string }) => void): () => void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** host.ui:运行时 UI 条目管理(manifest "ui" 是声明式基线)。 */
|
|
149
|
+
export interface PluginHostUi {
|
|
150
|
+
register(items: unknown[] | unknown): () => void;
|
|
151
|
+
update(id: string, patch: Record<string, unknown>): void;
|
|
152
|
+
remove(id: string): void;
|
|
153
|
+
arrange(ops: unknown[] | unknown): void;
|
|
154
|
+
list(): { items: UiContribution[]; arrange: unknown[] };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** host.llm.complete:孤立无工具的一次性补全(不建对话、不进历史)。
|
|
158
|
+
* 需要 manifest.permissions 含 "llm"(花用户自己的模型额度)。 */
|
|
159
|
+
export interface PluginHostLlm {
|
|
160
|
+
complete(req: { prompt: string; system?: string; model?: string; maxChars?: number; timeoutMs?: number }): Promise<{
|
|
161
|
+
ok: boolean;
|
|
162
|
+
text?: string;
|
|
163
|
+
model?: string;
|
|
164
|
+
usage?: { input: number; output: number };
|
|
165
|
+
error?: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 工具拦截守卫看到的 pre 请求(只对 bash/read 生效,全量见 server/plugin-tool-guard.ts)。 */
|
|
170
|
+
export interface ToolGuardPreRequest {
|
|
171
|
+
toolName: "bash" | "read";
|
|
172
|
+
params: unknown;
|
|
173
|
+
conversationId?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** 工具 pre 决策:allow 放行 / deny 拒绝 / ask 待确认(暂按拒绝执行)。 */
|
|
177
|
+
export type ToolGuardPreDecision =
|
|
178
|
+
| { decision: "allow" }
|
|
179
|
+
| { decision: "deny"; reason?: string; reasonEn?: string }
|
|
180
|
+
| { decision: "ask"; reason?: string; reasonEn?: string };
|
|
181
|
+
|
|
182
|
+
export interface PluginChatAttachment {
|
|
183
|
+
path: string;
|
|
184
|
+
mode?: "reference" | "inline";
|
|
185
|
+
name?: string;
|
|
186
|
+
mimeType?: string;
|
|
187
|
+
imageData?: string;
|
|
188
|
+
fileData?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface PluginChatRequest {
|
|
192
|
+
text: string;
|
|
193
|
+
accountId?: string;
|
|
194
|
+
conversationId?: string;
|
|
195
|
+
cwd?: string;
|
|
196
|
+
model?: string;
|
|
197
|
+
thinkingLevel?: string;
|
|
198
|
+
/** Up to 8 attachments, 10 MiB each and 20 MiB total. Images use imageData (base64). */
|
|
199
|
+
attachments?: PluginChatAttachment[];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** 插件服务端入口拿到的宿主接口(精简:全量见 server/plugins.ts PluginHost)。 */
|
|
203
|
+
export interface PluginHost {
|
|
204
|
+
broadcast(payload: unknown): void;
|
|
205
|
+
notify(level: "info" | "warning" | "error", text: string, textEn?: string): void;
|
|
206
|
+
onMessage(handler: (payload: unknown, from?: string) => void): () => void;
|
|
207
|
+
/** 注册客户端上行消息处理器(RPC 模式):回调提供 (msg, reply),调用 reply(payload) 可直接向来源客户端回包。 */
|
|
208
|
+
onClientMessage(handler: (msg: unknown, reply: (payload: unknown) => void) => void | Promise<void>): () => void;
|
|
209
|
+
sendTo(clientId: string, payload: unknown): void;
|
|
210
|
+
onAttach(handler: (clientId: string) => void): () => void;
|
|
211
|
+
onToolEvent(handler: (ev: unknown) => void): () => void;
|
|
212
|
+
/** 注册工具 pre 拦截守卫(只对 bash/read 生效;要 "tools" 能力)。 */
|
|
213
|
+
onToolPre(
|
|
214
|
+
handler: (req: ToolGuardPreRequest) => ToolGuardPreDecision | void | Promise<ToolGuardPreDecision | void>,
|
|
215
|
+
): () => void;
|
|
216
|
+
/** 注册工具 post 编辑守卫(只对 bash/read 生效;要 "tools" 能力)。 */
|
|
217
|
+
onToolPost(handler: (req: unknown) => unknown): () => void;
|
|
218
|
+
onRunEvent(handler: (ev: unknown) => void): () => void;
|
|
219
|
+
/** 读对话快照。传 `{clientId}` = 该标签页正在看的对话;不传 = 最近活跃的非子代理会话。 */
|
|
220
|
+
getActiveConversation(options?: { clientId?: string; fallback?: "latest-non-subagent" }): unknown;
|
|
221
|
+
onConversationChanged(handler: () => void): () => void;
|
|
222
|
+
/** 订阅模型切换成功(回调带 clientId / conversationId / model / isSubagent… 的快照)。 */
|
|
223
|
+
onClientModelChanged(handler: (snap: unknown) => void): () => void;
|
|
224
|
+
registerAgentTool(tool: PluginAgentTool): () => void;
|
|
225
|
+
/** 注册一个内联标记(Inline Marker)。 */
|
|
226
|
+
registerMarker<State = unknown>(marker: any): () => void;
|
|
227
|
+
/** 注册一个供 AI 调用的工具(单参数 execute(args) 兼容接口,内部适配并转调 registerAgentTool)。 */
|
|
228
|
+
registerTool(tool: {
|
|
229
|
+
name: string;
|
|
230
|
+
description: string;
|
|
231
|
+
label?: string;
|
|
232
|
+
promptSnippet?: string;
|
|
233
|
+
promptGuidelines?: string[];
|
|
234
|
+
parameters?: Record<string, unknown>;
|
|
235
|
+
execute(args: Record<string, unknown>): Promise<unknown>;
|
|
236
|
+
}): () => void;
|
|
237
|
+
/** 注册一个内联标记(Inline Marker),如 [[name:op:body]]。 */
|
|
238
|
+
registerMarker<State = unknown>(marker: PluginMarkerDef<State>): () => void;
|
|
239
|
+
dir: string;
|
|
240
|
+
dataDir: string;
|
|
241
|
+
readonly cwd: string;
|
|
242
|
+
onCwdChange(handler: (cwd: string) => void): () => void;
|
|
243
|
+
registerCommand(cmd: PluginCommandDef): () => void;
|
|
244
|
+
/** 执行已注册的插件斜杠命令(如 /todo, /note 等);返回结果或错误。 */
|
|
245
|
+
execCommand?(
|
|
246
|
+
name: string,
|
|
247
|
+
args: string,
|
|
248
|
+
context?: { clientId?: string },
|
|
249
|
+
): Promise<{ ok: boolean; result?: string; error?: string }>;
|
|
250
|
+
/** 获取当前系统注册的全部插件命令列表。 */
|
|
251
|
+
getPluginCommands?(): PluginCommandDef[];
|
|
252
|
+
/** 获取最近项目路径列表。 */
|
|
253
|
+
listProjects?(): string[];
|
|
254
|
+
/** 调起系统级目录浏览器弹窗选择文件夹。 */
|
|
255
|
+
pickDirectory?(opts?: {
|
|
256
|
+
initialPath?: string;
|
|
257
|
+
title?: string;
|
|
258
|
+
}): Promise<{ ok: boolean; path?: string; canceled?: boolean; error?: string }>;
|
|
259
|
+
/** 调起系统级模型选择器弹窗选择模型。 */
|
|
260
|
+
pickModel?(opts?: {
|
|
261
|
+
currentModelId?: string | null;
|
|
262
|
+
title?: string;
|
|
263
|
+
}): Promise<{ ok: boolean; modelId?: string; name?: string; provider?: string; canceled?: boolean; error?: string }>;
|
|
264
|
+
/** 挂载 HTTP 路由(实际暴露为 /plugins-api/<id><path>;要 "http" 能力;返回注销函数)。 */
|
|
265
|
+
route(
|
|
266
|
+
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
267
|
+
path: string,
|
|
268
|
+
handler: (req: unknown, res: unknown) => void,
|
|
269
|
+
): () => void;
|
|
270
|
+
/** 注册通用反向代理前缀(子路径去前缀透传到 127.0.0.1:port;要 "http" 能力;返回注销函数)。 */
|
|
271
|
+
registerProxy(prefix: string, target: number | { port: number; host?: string }): () => void;
|
|
272
|
+
ui: PluginHostUi;
|
|
273
|
+
llm: PluginHostLlm;
|
|
274
|
+
storage: {
|
|
275
|
+
get<T>(key: string, fallback?: T): T | undefined;
|
|
276
|
+
set(key: string, value: unknown): void;
|
|
277
|
+
delete(key: string): void;
|
|
278
|
+
has(key: string): boolean;
|
|
279
|
+
keys(): string[];
|
|
280
|
+
clear(preserveSettings?: boolean): void;
|
|
281
|
+
all(): Record<string, unknown>;
|
|
282
|
+
};
|
|
283
|
+
/** 插件间服务总线(Service Registry / Bus):跨插件服务发布与获取。 */
|
|
284
|
+
services: {
|
|
285
|
+
provide<T>(name: string, service: T): () => void;
|
|
286
|
+
get<T>(name: string): T | undefined;
|
|
287
|
+
has(name: string): boolean;
|
|
288
|
+
list(): Array<{ name: string; pluginId: string }>;
|
|
289
|
+
on<T>(name: string, handler: (service: T | undefined) => void): () => void;
|
|
290
|
+
};
|
|
291
|
+
provide<T>(name: string, service: T): () => void;
|
|
292
|
+
get<T>(name: string): T | undefined;
|
|
293
|
+
onService<T>(name: string, handler: (service: T | undefined) => void): () => void;
|
|
294
|
+
secrets: {
|
|
295
|
+
set(name: string, value: string): void;
|
|
296
|
+
get(name: string): string | undefined;
|
|
297
|
+
has(name: string): boolean;
|
|
298
|
+
delete(name: string): void;
|
|
299
|
+
list(): string[];
|
|
300
|
+
getAll(): Record<string, string>;
|
|
301
|
+
};
|
|
302
|
+
ensureDeps(specs: string[], opts?: { onProgress?: (msg: string) => void }): Promise<boolean>;
|
|
303
|
+
fs: PluginHostFs;
|
|
304
|
+
schedule(spec: string | number, fn: () => void, opts?: PluginHostScheduleOptions): () => void;
|
|
305
|
+
assets: {
|
|
306
|
+
ensure(spec: any, opts?: any): Promise<{ ok: boolean; ready?: boolean; error?: string; path?: string }>;
|
|
307
|
+
status(spec: any): { ready: boolean; downloading?: boolean; error?: string };
|
|
308
|
+
};
|
|
309
|
+
requestPermission(req: PluginPermissionRequest): Promise<boolean>;
|
|
310
|
+
getSettings(): Record<string, unknown>;
|
|
311
|
+
onSettingsChanged(handler: (values: Record<string, unknown>) => void): () => void;
|
|
312
|
+
/** 分级运行时日志:host.log(level?, ...args)(level 缺省 "info")。
|
|
313
|
+
* 首参是 "debug"|"info"|"warn"|"error" 之一即当级别,老写法的
|
|
314
|
+
* host.log(...args) 照旧按 info 走。全部进宿主内存环形缓冲(每插件最近
|
|
315
|
+
* 200 条,单条截断 500 字符,不落盘);error 级同时走 console.error。
|
|
316
|
+
* 用户在设置面板“界面插件”页点某插件的“日志”按需查看(级别过滤 + 清空)。 */
|
|
317
|
+
log(level?: "debug" | "info" | "warn" | "error", ...args: unknown[]): void;
|
|
318
|
+
/** 登记一条**自建**的可逆副作用(自建 setInterval / event 监听 / WebSocket…):
|
|
319
|
+
* 返回的注销函数与插件反激活**都会**调 dispose。宿主自己的每个注册面已在内部
|
|
320
|
+
* 走同一个 effect 栈,这里只用于「宿主管不到的那些」—— 挂进来就不怕漏注销
|
|
321
|
+
* (热重载后定时器叠加、监听器堆积都是这个漏法的症状)。dispose 请写成幂等的。 */
|
|
322
|
+
effect(label: string, dispose: () => void): () => void;
|
|
323
|
+
/** 安全解析工作区相对/绝对路径:落在工作区或额外根内放行,越界抛带 statusCode=403 的错误。 */
|
|
324
|
+
resolveInWorkspace(relOrAbsPath: string): string;
|
|
325
|
+
/** 带有默认超时(默认 30s)与插件生命周期绑定的安全 fetch。 */
|
|
326
|
+
fetch(input: string | URL | Request, init?: RequestInit & { timeoutMs?: number }): Promise<Response>;
|
|
327
|
+
/** 宿主重资产流水线(Heavy Asset Pipeline)。 */
|
|
328
|
+
assets: {
|
|
329
|
+
ensure(
|
|
330
|
+
spec: {
|
|
331
|
+
id: string;
|
|
332
|
+
targetDir: string;
|
|
333
|
+
urls: string[];
|
|
334
|
+
sha256?: string;
|
|
335
|
+
testFile?: string;
|
|
336
|
+
size?: number;
|
|
337
|
+
description?: string;
|
|
338
|
+
},
|
|
339
|
+
opts?: {
|
|
340
|
+
onProgress?: (progress: { downloaded: number; total: number; percent: number; url: string }) => void;
|
|
341
|
+
timeoutMs?: number;
|
|
342
|
+
},
|
|
343
|
+
): Promise<{ ok: boolean; targetDir: string; cached?: boolean; sha256?: string; error?: string }>;
|
|
344
|
+
status(spec: {
|
|
345
|
+
id: string;
|
|
346
|
+
targetDir: string;
|
|
347
|
+
urls: string[];
|
|
348
|
+
sha256?: string;
|
|
349
|
+
testFile?: string;
|
|
350
|
+
size?: number;
|
|
351
|
+
description?: string;
|
|
352
|
+
}): {
|
|
353
|
+
ready: boolean;
|
|
354
|
+
downloading: boolean;
|
|
355
|
+
progress: number;
|
|
356
|
+
downloaded: number;
|
|
357
|
+
total: number;
|
|
358
|
+
error: string | null;
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
/** 无头调用:把外部通道文本投给 agent(要 "chat" 能力;宿主未接 chatProvider
|
|
362
|
+
* 时 reject(由 chatWait 包成 {ok:false},插件侧用 chatWait 更省心)。 */
|
|
363
|
+
chat(req: PluginChatRequest): Promise<{
|
|
364
|
+
/** Present only on mock hosts or older integrations; real failures reject. */
|
|
365
|
+
ok?: boolean;
|
|
366
|
+
conversationId: string;
|
|
367
|
+
clientId: string;
|
|
368
|
+
runId?: string;
|
|
369
|
+
}>;
|
|
370
|
+
/** 等待无头调用的运行结束(默认 120s 超时;无注入/超时/失败一律回 {ok:false},绝不抛错)。 */
|
|
371
|
+
chatWait(
|
|
372
|
+
req: PluginChatRequest,
|
|
373
|
+
opts?: { timeoutMs?: number },
|
|
374
|
+
): Promise<{ ok: boolean; conversationId?: string; error?: string }>;
|
|
375
|
+
/** 对话读写:无注入时 list/search 回 []、get 回 null,绝不抛错。 */
|
|
376
|
+
conversations: {
|
|
377
|
+
list(): Array<{ id: string; title: string }> | Promise<Array<{ id: string; title: string }>>;
|
|
378
|
+
get(id: string): unknown;
|
|
379
|
+
search(
|
|
380
|
+
query: string,
|
|
381
|
+
limit?: number,
|
|
382
|
+
): Array<{ id: string; title: string }> | Promise<Array<{ id: string; title: string }>>;
|
|
383
|
+
};
|
|
384
|
+
/** 向指定对话发一条用户消息(无注入回 {ok:false},绝不抛错)。 */
|
|
385
|
+
prompt(
|
|
386
|
+
conversationId: string,
|
|
387
|
+
req: { text: string; attachments?: Array<{ path: string; mode?: string }> },
|
|
388
|
+
): Promise<{ ok: boolean; error?: string }>;
|
|
389
|
+
/** 插队指定对话的当前运行(无注入回 {ok:false},绝不抛错)。 */
|
|
390
|
+
steer(conversationId: string, text: string): Promise<{ ok: boolean; error?: string }>;
|
|
391
|
+
/** Abort by stable plugin runId (pr- prefix, survives takeover), or legacy local conversationId. */
|
|
392
|
+
abortRun(conversationId: string): Promise<{ ok: boolean; error?: string }>;
|
|
393
|
+
/** 项目组装:在已授权目录里建目录/clone 仓库/写文件(失败回 {ok:false,error},不留半成品)。 */
|
|
394
|
+
project: {
|
|
395
|
+
create(spec: { dir: string; [key: string]: unknown }): Promise<{
|
|
396
|
+
ok: boolean;
|
|
397
|
+
dir: string;
|
|
398
|
+
log: string[];
|
|
399
|
+
error?: string;
|
|
400
|
+
}>;
|
|
401
|
+
};
|
|
402
|
+
/** P3:左栏「运行的对话」里的插件运行条目(仅展示,需要能力 "ui")。setRunning 整体替换本插件的
|
|
403
|
+
* 条目,同时作为心跳:超过 ttlMs(缺省 60 秒,夹取 5 秒–1 小时)没有再次调用就整组自动清空;
|
|
404
|
+
* clear() 立即清空;反激活时自动清空。item.action 点击时交给本插件浏览器 bundle 的 onUiAction。 */
|
|
405
|
+
leftPanel: {
|
|
406
|
+
setRunning(
|
|
407
|
+
items: Array<{
|
|
408
|
+
id: string;
|
|
409
|
+
title: string;
|
|
410
|
+
hint?: string;
|
|
411
|
+
status?: "running" | "done" | "error";
|
|
412
|
+
icon?: string;
|
|
413
|
+
action?: string;
|
|
414
|
+
}>,
|
|
415
|
+
opts?: { ttlMs?: number },
|
|
416
|
+
): void;
|
|
417
|
+
clear(): void;
|
|
418
|
+
};
|
|
419
|
+
/** 常驻后台任务(顶栏「后台任务」面板;返回 update/unregister)。支持心跳探活回调 check 与间隔 intervalMs。 */
|
|
420
|
+
registerBackgroundTask(task: {
|
|
421
|
+
id: string;
|
|
422
|
+
label: string;
|
|
423
|
+
stop?: () => void;
|
|
424
|
+
status?: string;
|
|
425
|
+
check?: () =>
|
|
426
|
+
boolean | { alive: boolean; status?: string } | Promise<boolean | { alive: boolean; status?: string }>;
|
|
427
|
+
intervalMs?: number;
|
|
428
|
+
maxFailures?: number;
|
|
429
|
+
onDead?: (reason?: string) => void;
|
|
430
|
+
}): {
|
|
431
|
+
update(next: Partial<{ label: string; status: string; stop: () => void }>): void;
|
|
432
|
+
unregister(): void;
|
|
433
|
+
};
|
|
434
|
+
/** 插件可见的模型列表(无注入回 [])。 */
|
|
435
|
+
models: {
|
|
436
|
+
list(): Array<{ id: string; [key: string]: unknown }> | Promise<Array<{ id: string; [key: string]: unknown }>>;
|
|
437
|
+
};
|
|
438
|
+
/** MCP 服务器检测与便捷安装接口(list/check 只读免权限;install 要 "tools";promptInstall 要 "chat" 或 "tools")。 */
|
|
439
|
+
mcp: {
|
|
440
|
+
list(): Promise<Array<{ name: string; scope: "global" | "project"; status: string; [key: string]: unknown }>>;
|
|
441
|
+
check(query: string): Promise<{
|
|
442
|
+
installed: boolean;
|
|
443
|
+
running: boolean;
|
|
444
|
+
enabled: boolean;
|
|
445
|
+
server: Record<string, unknown> | null;
|
|
446
|
+
matches: Array<Record<string, unknown>>;
|
|
447
|
+
tools: Array<{ name: string; description?: string }>;
|
|
448
|
+
}>;
|
|
449
|
+
install(spec: {
|
|
450
|
+
name?: string;
|
|
451
|
+
package?: string;
|
|
452
|
+
command?: string;
|
|
453
|
+
args?: string[];
|
|
454
|
+
cwd?: string;
|
|
455
|
+
env?: Record<string, string>;
|
|
456
|
+
url?: string;
|
|
457
|
+
headers?: Record<string, string>;
|
|
458
|
+
type?: "stdio" | "http" | "streamable-http";
|
|
459
|
+
timeout?: number;
|
|
460
|
+
description?: string;
|
|
461
|
+
scope?: "global" | "project";
|
|
462
|
+
enabled?: boolean;
|
|
463
|
+
}): Promise<{
|
|
464
|
+
ok: boolean;
|
|
465
|
+
name?: string;
|
|
466
|
+
scope?: "global" | "project";
|
|
467
|
+
status?: string;
|
|
468
|
+
tools?: Array<{ name: string; description?: string }>;
|
|
469
|
+
server?: Record<string, unknown>;
|
|
470
|
+
error?: string;
|
|
471
|
+
}>;
|
|
472
|
+
promptInstall(
|
|
473
|
+
target: string | Record<string, unknown>,
|
|
474
|
+
opts?: { conversationId?: string; scope?: "global" | "project" },
|
|
475
|
+
): Promise<{ ok: boolean; conversationId?: string; error?: string }>;
|
|
476
|
+
};
|
|
477
|
+
/** 会话统计 / 流式增量订阅(返回注销函数)。 */
|
|
478
|
+
onStats(handler: (s: unknown) => void): () => void;
|
|
479
|
+
onStreaming(handler: (ev: { conversationId?: string; delta: string }) => void): () => void;
|
|
480
|
+
/** 出站网络(要 "net" 能力 + 主机白名单;失败一律 {ok:false,error},绝不抛错)。 */
|
|
481
|
+
net: {
|
|
482
|
+
fetch(
|
|
483
|
+
url: string,
|
|
484
|
+
init?: { method?: string; body?: string; headers?: Record<string, string> },
|
|
485
|
+
): Promise<{ ok: boolean; status?: number; text?: string; error?: string }>;
|
|
486
|
+
};
|
|
487
|
+
/** 插件间事件总线(emit 回填 from;on 返回取消函数)。 */
|
|
488
|
+
events: {
|
|
489
|
+
emit(topic: string, payload?: unknown): void;
|
|
490
|
+
on(topic: string, handler: (ev: unknown) => void): () => void;
|
|
491
|
+
};
|
|
492
|
+
/** 只读 git 查询(失败回 {ok:false,error} 对象而非抛错)。 */
|
|
493
|
+
scm: {
|
|
494
|
+
status(): Promise<unknown>;
|
|
495
|
+
log(path?: string, limit?: number): Promise<unknown>;
|
|
496
|
+
};
|
|
497
|
+
/** 受限 shell(cwd 缺省当前工作区;默认超时 60s;要 "tools" 能力)。 */
|
|
498
|
+
bash(
|
|
499
|
+
cmd: string,
|
|
500
|
+
opts?: { cwd?: string; timeoutMs?: number },
|
|
501
|
+
): Promise<{
|
|
502
|
+
ok: boolean;
|
|
503
|
+
output: string;
|
|
504
|
+
exitCode?: number;
|
|
505
|
+
error?: string;
|
|
506
|
+
}>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** 插件服务端入口形状(activate 必填,deactivate 可选)。 */
|
|
510
|
+
export interface PluginModule {
|
|
511
|
+
activate(host: PluginHost): void | Promise<void>;
|
|
512
|
+
deactivate?: () => void;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** 插件宿主动作桥(window.__piWebUiHost,client bundle 用)。版本号见 PLUGIN_HOST_API_VERSION。 */
|
|
516
|
+
export interface PluginHostBridge {
|
|
517
|
+
version: number;
|
|
518
|
+
setView(view: string): void;
|
|
519
|
+
/** 打开一个 `modal.dialog` 槽位的条目(全局 id `<pluginId>:<itemId>`;
|
|
520
|
+
* 不存在/被隐藏返回 false,同一时刻只开一个)。 */
|
|
521
|
+
openModal(id: string): boolean;
|
|
522
|
+
/** 关掉当前弹窗(幂等)。 */
|
|
523
|
+
closeModal(): boolean;
|
|
524
|
+
onUiAction(action: string, handler: (itemId: string, value?: string) => void): () => void;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** 插件视图入口形状(client/entry.mjs 默认导出)。 */
|
|
528
|
+
export interface PluginViewModule {
|
|
529
|
+
mount(el: HTMLElement, ctx: PluginViewContext): void | (() => void);
|
|
530
|
+
cleanup?: () => void;
|
|
531
|
+
renderers?: Record<string, (code: string, ctx: PluginViewContext) => HTMLElement | null>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** 视图 ctx(窄通道:只依赖 send/onData;动作回调走 window.__piWebUiHost.onUiAction,见 sdk onUiAction)。 */
|
|
535
|
+
export interface PluginViewContext {
|
|
536
|
+
send(payload: unknown): void;
|
|
537
|
+
onData(handler: (payload: unknown) => void): () => void;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare function definePlugin(def: PluginModule): PluginModule;
|
|
541
|
+
export declare function defineView(view: PluginViewModule): PluginViewModule;
|
|
542
|
+
export declare function defineRenderer(
|
|
543
|
+
renderers: Record<string, (code: string, ctx: PluginViewContext) => HTMLElement | null>,
|
|
544
|
+
): Pick<PluginViewModule, "renderers">;
|
|
545
|
+
export declare function actionHandler(
|
|
546
|
+
map: Record<string, (value?: string) => void>,
|
|
547
|
+
): (itemId: string, value?: string) => void;
|
|
548
|
+
export declare function onUiAction(action: string, handler: (itemId: string, value?: string) => void): () => void;
|
|
549
|
+
export declare function getSetting<T>(host: PluginHost, key: string, fallback: T): T;
|
|
550
|
+
export declare function selectOptions(list: Array<string | UiSelectOption>): UiSelectOption[];
|
|
551
|
+
|
|
552
|
+
/** SDK 版本(与 plugin-sdk/package.json 的 version 保持一致,单测锁定)。 */
|
|
553
|
+
export declare const SDK_VERSION: string;
|
|
554
|
+
|
|
555
|
+
/** createMockHost 的一条调用记录(method 如 "ui.register"、"fs.readText";log 也记)。 */
|
|
556
|
+
export interface MockHostCall {
|
|
557
|
+
method: string;
|
|
558
|
+
args: unknown[];
|
|
559
|
+
/** 本次记录窗口内的序号(0 起;reset() 后新记录重新从 0 开始)。 */
|
|
560
|
+
seq: number;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** createMockHost 的一条分级日志(log 被 overrides 整体替换时不再写这里)。 */
|
|
564
|
+
export interface MockHostLogEntry {
|
|
565
|
+
level: "debug" | "info" | "warn" | "error";
|
|
566
|
+
text: string;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** createMockHost(overrides?):settings/cwd/dir/dataDir 是专用键;命名空间键
|
|
570
|
+
* (fs/ui/llm/conversations/scm/net/events/models/storage/secrets/project/dialogs/
|
|
571
|
+
* shortcuts/searchProviders/composerProviders/assets)传对象 = 按子键合并覆盖;其余键整体
|
|
572
|
+
* 替换对应方法(仍进 calls 记录)。`calls`/`logs`/`mock`/`reset` 不可覆盖。 */
|
|
573
|
+
export interface MockHostOverrides {
|
|
574
|
+
settings?: Record<string, unknown>;
|
|
575
|
+
cwd?: string;
|
|
576
|
+
dir?: string;
|
|
577
|
+
dataDir?: string;
|
|
578
|
+
[key: string]: unknown;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** mock 命名空间:handlers 活视图 + emit/emitAsync/setSettings/emitSettings 驱动器
|
|
582
|
+
* + calls 过滤 + 注册表活视图(agentTools/commands/routes/schedules)+ fireSchedules。 */
|
|
583
|
+
export interface MockHostControls {
|
|
584
|
+
/** 方法名 → 已注册 handler 数组(活引用,与注销函数联动)。 */
|
|
585
|
+
handlers: Record<string, Array<(...args: any[]) => unknown>>;
|
|
586
|
+
/** 主动触发某订阅方法的 handlers(错误直接抛给测试,不吞)。 */
|
|
587
|
+
emit(method: string, ...args: unknown[]): void;
|
|
588
|
+
/** 异步版:按注册顺序依次 await,返回各 handler 返回值(抛错即 reject,不吞)。 */
|
|
589
|
+
emitAsync(method: string, ...args: unknown[]): Promise<unknown[]>;
|
|
590
|
+
/** 按方法名过滤调用记录(不传即全部拷贝)。 */
|
|
591
|
+
calls(method?: string): MockHostCall[];
|
|
592
|
+
/** 合并 settings 预设(返回同一引用,getSettings() 读到的就是它)。 */
|
|
593
|
+
setSettings(next: Record<string, unknown>): Record<string, unknown>;
|
|
594
|
+
/** 合并预设 + 触发 onSettingsChanged(模拟用户在设置面板保存)。 */
|
|
595
|
+
emitSettings(next?: Record<string, unknown>): Record<string, unknown>;
|
|
596
|
+
/** 已注册的 Agent 工具定义(活数组,注销即摘除;工具的 execute 可直接调)。 */
|
|
597
|
+
agentTools: Array<PluginAgentTool>;
|
|
598
|
+
/** 已注册的内联标记定义(活数组,注销即摘除)。 */
|
|
599
|
+
markers: Array<PluginMarkerDef<unknown>>;
|
|
600
|
+
/** 已注册的斜杠命令定义(活数组,注销即摘除)。 */
|
|
601
|
+
commands: Array<PluginCommandDef>;
|
|
602
|
+
/** 已挂载的路由表(活数组,注销即摘除)。 */
|
|
603
|
+
routes: Array<{ method: string; path: string; handler: (req: unknown, res: unknown) => void }>;
|
|
604
|
+
/** 已注册的代理前缀(活数组,注销即摘除)。 */
|
|
605
|
+
proxies: Array<{ prefix: string; target: number | { port: number; host?: string } }>;
|
|
606
|
+
/** 已登记的定时任务(活数组 {spec, fn, opts};schedule() 不设真定时器,注销即摘除)。 */
|
|
607
|
+
schedules: Array<{ spec: string | number; fn: () => void; opts?: PluginHostScheduleOptions }>;
|
|
608
|
+
/** 依次触发全部已登记的定时回调(返回各回调返回值;抛错即 reject)。 */
|
|
609
|
+
fireSchedules(): Promise<unknown[]>;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** 浏览器桥兼容(client 侧逻辑单测也能用同一个 mock):无注入回退语义。 */
|
|
613
|
+
export interface MockHostDialogs {
|
|
614
|
+
select(opts: {
|
|
615
|
+
title?: string;
|
|
616
|
+
options?: unknown;
|
|
617
|
+
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
618
|
+
[key: string]: unknown;
|
|
619
|
+
}): Promise<{
|
|
620
|
+
ok: boolean;
|
|
621
|
+
selected?: string[];
|
|
622
|
+
error?: string;
|
|
623
|
+
}>;
|
|
624
|
+
confirm(opts: {
|
|
625
|
+
title?: string;
|
|
626
|
+
text?: string;
|
|
627
|
+
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
628
|
+
[key: string]: unknown;
|
|
629
|
+
}): Promise<boolean>;
|
|
630
|
+
input(opts: {
|
|
631
|
+
title?: string;
|
|
632
|
+
code?: { content: string; language?: string; hasRisk?: boolean };
|
|
633
|
+
[key: string]: unknown;
|
|
634
|
+
}): Promise<{ ok: boolean; value?: string }>;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** createMockHost 返回的 mock host(PluginHost 全量 + harness 字段 + 桥兼容)。 */
|
|
638
|
+
export interface MockHost extends PluginHost {
|
|
639
|
+
/** 全量调用记录({method, args},含 log/storage 等)。 */
|
|
640
|
+
calls: MockHostCall[];
|
|
641
|
+
/** 分级日志条目。 */
|
|
642
|
+
logs: MockHostLogEntry[];
|
|
643
|
+
/** 测试驱动器(handlers/emit/setSettings/emitSettings)。 */
|
|
644
|
+
mock: MockHostControls;
|
|
645
|
+
/** 清空 calls + logs(原地;settings/handlers/注册表这些 fake 状态保留,
|
|
646
|
+
* 要全新状态就重新 createMockHost())。 */
|
|
647
|
+
reset(): void;
|
|
648
|
+
dialogs: MockHostDialogs;
|
|
649
|
+
notifyAction(opts: { text: string; actions: Array<{ id: string; label: string }> }): Promise<string | null>;
|
|
650
|
+
shortcuts: {
|
|
651
|
+
register(shortcut: string, handler: () => void): () => void;
|
|
652
|
+
};
|
|
653
|
+
searchProviders: {
|
|
654
|
+
register(provider: {
|
|
655
|
+
id: string;
|
|
656
|
+
label: string;
|
|
657
|
+
search: (q: string) => Promise<Array<{ title: string; hint?: string; action: string }>>;
|
|
658
|
+
}): () => void;
|
|
659
|
+
list(): Array<{ id: string; label: string }>;
|
|
660
|
+
};
|
|
661
|
+
composerProviders: {
|
|
662
|
+
register(provider: {
|
|
663
|
+
id: string;
|
|
664
|
+
label: string;
|
|
665
|
+
search: (q: string) => Promise<Array<{ title: string; hint?: string; text?: string }>>;
|
|
666
|
+
}): () => void;
|
|
667
|
+
list(): Array<{ id: string; label: string }>;
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export declare function createMockHost(overrides?: MockHostOverrides): MockHost;
|
|
672
|
+
|
|
673
|
+
/** 安全 HTML 实体转义。 */
|
|
674
|
+
export declare function esc(s: unknown): string;
|
|
675
|
+
|
|
676
|
+
/** 安全取用 window.__piWebUiHost 宿主桥接 API。 */
|
|
677
|
+
export declare function hostApi(): any;
|
|
678
|
+
|
|
679
|
+
/** 获取插件服务端路由的统一根路径。 */
|
|
680
|
+
export declare function apiBase(pluginId: string): string;
|
|
681
|
+
|
|
682
|
+
/** 格式化字节大小为人类可读字符串(B / KB / MB / GB)。 */
|
|
683
|
+
export declare function formatBytes(bytes: number | unknown, decimals?: number): string;
|
|
684
|
+
|
|
685
|
+
/** 为异步操作施加超时限制。 */
|
|
686
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMsg?: string): Promise<T>;
|
|
687
|
+
|
|
688
|
+
/** 生成随机 UUID。 */
|
|
689
|
+
export declare function uuid(): string;
|
|
690
|
+
|
|
691
|
+
/** 归一化相对路径(反斜杠转斜杠、去除首尾多余斜杠与 "./")。 */
|
|
692
|
+
export declare function normalizeRel(p: string): string;
|
|
693
|
+
|
|
694
|
+
/** 计算安全的截断位置,避免割裂 UTF-16 代理对。 */
|
|
695
|
+
export declare function safeSliceIndex(value: string, limit: number): number;
|
|
696
|
+
|
|
697
|
+
/** 结构感知 Markdown 分块工具(保护代码围栏不跨块破坏)。 */
|
|
698
|
+
export declare function chunkMarkdownText(text: string, limit?: number): string[];
|