@xiongtao.xt/tau-plugins 0.54.0 → 0.56.0
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 +12 -0
- package/docs/README.md +87 -21
- package/docs/ai.md +17 -14
- package/docs/app-surfaces.md +267 -0
- package/docs/document-body.md +126 -0
- package/docs/editor-collaboration.md +135 -49
- package/docs/editor-export.md +154 -0
- package/docs/editor-interactions.md +254 -0
- package/docs/editor-source-media.md +397 -0
- package/docs/editor.md +68 -523
- package/docs/excerpts.md +22 -6
- package/docs/flashcards.md +18 -5
- package/docs/getting-started.md +80 -30
- package/docs/mcp.md +26 -11
- package/docs/notifications-and-voice.md +219 -0
- package/docs/pages.md +374 -0
- package/docs/permissions.md +126 -0
- package/docs/plugin-basics.md +67 -52
- package/docs/plugin-content.md +263 -0
- package/docs/portability.md +50 -28
- package/docs/providers/README.md +153 -41
- package/docs/providers/asr.md +104 -11
- package/docs/providers/embeddings.md +3 -7
- package/docs/providers/images.md +3 -3
- package/docs/providers/publish.md +48 -10
- package/docs/providers/sync.md +5 -64
- package/docs/providers/tts.md +2 -2
- package/docs/providers/upload.md +4 -59
- package/docs/providers/video.md +37 -6
- package/docs/references.md +183 -0
- package/docs/release.md +21 -16
- package/docs/settings-and-commands.md +168 -0
- package/docs/skills.md +14 -7
- package/docs/storage-and-network.md +4 -5
- package/docs/ui-components.md +92 -0
- package/docs/ui.md +24 -762
- package/docs/user-data.md +64 -623
- package/docs/whiteboard.md +110 -32
- package/package.json +1 -1
- package/types/packages/asr/src/types.d.ts +2 -0
- package/types/packages/plugins/src/contract.d.ts +3 -0
- package/types/packages/plugins/src/environment.d.ts +3 -0
- package/types/packages/plugins/src/excerpts.d.ts +3 -0
- package/types/packages/plugins/src/foreground-host.d.ts +8 -0
- package/types/packages/plugins/src/index.d.ts +1 -0
- package/types/packages/plugins/src/notebooks.d.ts +98 -0
- package/types/packages/plugins/src/publish-data.d.ts +4 -0
package/docs/whiteboard.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 白板扩展
|
|
2
2
|
|
|
3
|
-
在 Tau
|
|
3
|
+
在 Tau 的白板上加一种自己的元素(图形、图表、组件),以及在工具栏里创建它的工具。元素随白板保存、同步和协作,复制、导出图片时也会带上。白板扩展只能在桌面使用,各平台能用哪些接口见[多端适配](portability.md#各平台可用的接口)。
|
|
4
4
|
|
|
5
5
|
白板扩展分为两部分:
|
|
6
6
|
|
|
@@ -11,13 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
### 1. 在 manifest 中声明
|
|
13
13
|
|
|
14
|
+
`categories` 里加上 `"whiteboard"`,插件中心会把它归到「白板」分类:
|
|
15
|
+
|
|
14
16
|
```json
|
|
15
17
|
{
|
|
16
|
-
"categories": ["whiteboard"]
|
|
17
|
-
"targets": { "desktop": { "minAppVersion": "0.59.5" } }
|
|
18
|
+
"categories": ["whiteboard"]
|
|
18
19
|
}
|
|
19
20
|
```
|
|
20
21
|
|
|
22
|
+
`targets` 里只列 `desktop`,写法见[多端适配 · 声明支持的平台](portability.md#声明支持的平台)。
|
|
23
|
+
|
|
21
24
|
### 2. 定义扩展
|
|
22
25
|
|
|
23
26
|
```tsx
|
|
@@ -99,7 +102,7 @@ export default definePlugin({
|
|
|
99
102
|
|
|
100
103
|
### 3. 构建、安装、重启
|
|
101
104
|
|
|
102
|
-
白板扩展在 Tau 启动时装配,启用、停用和更新都要**完全退出并重新打开 Tau**
|
|
105
|
+
白板扩展在 Tau 启动时装配,启用、停用和更新都要**完全退出并重新打开 Tau** 才生效。之后打开白板,在「扩展工具」菜单中就能找到「方块」,在画布上拖出一个方块。
|
|
103
106
|
|
|
104
107
|
## 命名规则
|
|
105
108
|
|
|
@@ -123,25 +126,33 @@ export default definePlugin({
|
|
|
123
126
|
| `create` | 可选。创建方式,声明后才能注册创建型工具,见[创建工具](#创建工具) |
|
|
124
127
|
| `interaction` | 可选。缩放手柄与连接点,见下文 |
|
|
125
128
|
| `schema` | 可选。约束 `data` 结构的 [Standard Schema](https://standardschema.dev),必须同步校验 |
|
|
126
|
-
| `dataVersion` | `data` 结构的版本,正整数,从 `1`
|
|
129
|
+
| `dataVersion` | `data` 结构的版本,正整数,从 `1` 开始,与插件的版本号无关,见[数据版本](#数据版本) |
|
|
127
130
|
| `collaboration.textFields` | 可选。`data` 里需要多人同时编辑的顶层字符串字段,修改方式见[文本字段](#文本字段) |
|
|
128
131
|
| `resources` | 可选。`data` 里的图片、附件地址字段,复制和导出时 Tau 据此找到资源 |
|
|
129
132
|
| `previousVersions` | 可选。旧版本的元素声明,见[数据版本](#数据版本) |
|
|
130
133
|
| `sketch` | 可选。为 `true` 时元素支持手绘画风,见[手绘画风](#手绘画风) |
|
|
131
134
|
| `schematic` | 可选。简略预览,见[简略预览](#简略预览) |
|
|
132
135
|
|
|
133
|
-
用 `defineElement<TData>` 声明 `data` 的类型,或者传入 `schema`
|
|
136
|
+
用 `defineElement<TData>` 声明 `data` 的类型,或者传入 `schema` 让类型自动推断。下面的便签把文字存在 `data.text`,后文的[文本字段](#文本字段)接着用它:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { defineElement } from "@tau/plugins/whiteboard";
|
|
140
|
+
|
|
141
|
+
declare const __PLUGIN_META__: { id: string; name: string; version: string };
|
|
134
142
|
|
|
135
|
-
```ts
|
|
136
143
|
interface StickyData {
|
|
137
144
|
text: string;
|
|
138
145
|
}
|
|
139
146
|
|
|
140
|
-
defineElement<StickyData>({
|
|
147
|
+
const sticky = defineElement<StickyData>({
|
|
141
148
|
type: `${__PLUGIN_META__.id}.sticky`,
|
|
142
149
|
dataVersion: 1,
|
|
143
150
|
collaboration: { textFields: ["text"] },
|
|
144
|
-
render: ({ element }) =>
|
|
151
|
+
render: ({ element }) => (
|
|
152
|
+
<text x={element.x} y={element.y}>
|
|
153
|
+
{element.data.text}
|
|
154
|
+
</text>
|
|
155
|
+
),
|
|
145
156
|
});
|
|
146
157
|
```
|
|
147
158
|
|
|
@@ -164,32 +175,35 @@ interaction: {
|
|
|
164
175
|
|
|
165
176
|
### 数据版本
|
|
166
177
|
|
|
167
|
-
`data` 的结构有不兼容的变化(字段改名、文本字段变了)时,把 `dataVersion` 加一,并把上一版的声明放进 `previousVersions`:
|
|
178
|
+
`data` 的结构有不兼容的变化(字段改名、文本字段变了)时,把 `dataVersion` 加一,并把上一版的声明放进 `previousVersions`。比如便签把文字字段从 `text` 改名为 `content`:
|
|
168
179
|
|
|
169
|
-
```
|
|
170
|
-
const
|
|
171
|
-
type: `${__PLUGIN_META__.id}.
|
|
172
|
-
dataVersion: 1,
|
|
173
|
-
collaboration: { textFields: ["source"] },
|
|
174
|
-
render: () => null,
|
|
175
|
-
});
|
|
176
|
-
const sourceV2 = defineElement({
|
|
177
|
-
...sourceV1,
|
|
180
|
+
```tsx
|
|
181
|
+
const stickyV2 = defineElement<{ content: string }>({
|
|
182
|
+
type: `${__PLUGIN_META__.id}.sticky`,
|
|
178
183
|
dataVersion: 2,
|
|
179
|
-
collaboration: { textFields: ["
|
|
180
|
-
|
|
184
|
+
collaboration: { textFields: ["content"] },
|
|
185
|
+
render: ({ element }) => (
|
|
186
|
+
<text x={element.x} y={element.y}>
|
|
187
|
+
{element.data.content}
|
|
188
|
+
</text>
|
|
189
|
+
),
|
|
190
|
+
// 上文的 sticky 就是第 1 版
|
|
191
|
+
previousVersions: [{ element: sticky, access: "read" }],
|
|
181
192
|
});
|
|
182
193
|
```
|
|
183
194
|
|
|
184
195
|
- Tau 不会转换已有的数据。旧白板里的元素仍按保存时的版本、用旧声明渲染;新创建的元素用当前版本。
|
|
185
196
|
- `access` 为 `edit` 时旧元素可以继续编辑,`read` 只能看,`none` 只保留数据。没有列进 `previousVersions` 的旧版本,显示为占位,数据原样保留,仍可移动、复制、删除。
|
|
197
|
+
- `elements` 里只注册当前版本,旧版本通过 `previousVersions` 带上。
|
|
186
198
|
- 只改渲染或新增可选字段时,不需要提高版本。
|
|
187
199
|
|
|
200
|
+
编辑器块的数据版本规则相同,见[块的数据版本与协作](editor-collaboration.md#修改数据结构)。
|
|
201
|
+
|
|
188
202
|
## 创建工具
|
|
189
203
|
|
|
190
204
|
### 创建型工具
|
|
191
205
|
|
|
192
|
-
元素声明了 `create` 后,注册一个 `element`
|
|
206
|
+
元素声明了 `create` 后,注册一个 `element` 指向它的工具,用户就能在画布上用手势创建元素,如上文的方块。
|
|
193
207
|
|
|
194
208
|
| `create` 字段 | 说明 |
|
|
195
209
|
| ------------- | -------------------------------------------------------------------------------------------------------- |
|
|
@@ -218,7 +232,7 @@ const sourceV2 = defineElement({
|
|
|
218
232
|
|
|
219
233
|
### 创建前选择参数
|
|
220
234
|
|
|
221
|
-
工具可以提供 `panel
|
|
235
|
+
工具可以提供 `panel`,让用户先选好参数再执行。给方块工具加上颜色选择:
|
|
222
236
|
|
|
223
237
|
```tsx
|
|
224
238
|
panel: ({ run }) => (
|
|
@@ -267,7 +281,7 @@ panel: ({ run }) => (
|
|
|
267
281
|
|
|
268
282
|
元素组件里用 `useWhiteboardAPI()` 拿到所属扩展的 `api`。
|
|
269
283
|
|
|
270
|
-
`submit` 接收一组命令,全部成功才生效,有一条失败就都不写入,返回新建元素的 `createdIds
|
|
284
|
+
`submit` 接收一组命令,全部成功才生效,有一条失败就都不写入,返回新建元素的 `createdIds`。比如在命令里放一个方块:
|
|
271
285
|
|
|
272
286
|
```ts
|
|
273
287
|
const pageId = api.getSnapshot().pageId;
|
|
@@ -300,24 +314,86 @@ api.updateElementData(createdIds[0], { label: "方块" });
|
|
|
300
314
|
|
|
301
315
|
### 文本字段
|
|
302
316
|
|
|
303
|
-
`collaboration.textFields` 里的字段要通过文本句柄修改,不要用 `updateElementData`
|
|
317
|
+
`collaboration.textFields` 里的字段要通过文本句柄修改,不要用 `updateElementData` 整段覆盖,这样两人同时编辑时会按字符合并。便签的编辑框:
|
|
304
318
|
|
|
305
319
|
```tsx
|
|
306
|
-
|
|
320
|
+
import { useEffect, useState } from "react";
|
|
321
|
+
import {
|
|
322
|
+
useWhiteboardAPI,
|
|
323
|
+
type TypedBoardElement,
|
|
324
|
+
} from "@tau/plugins/whiteboard";
|
|
325
|
+
|
|
326
|
+
interface StickyData {
|
|
327
|
+
text: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 只把改动的那一段交给句柄,两人同时编辑时才能按字符合并
|
|
331
|
+
function diff(before: string, after: string) {
|
|
332
|
+
let start = 0;
|
|
333
|
+
while (start < before.length && before[start] === after[start]) start++;
|
|
334
|
+
let end = 0;
|
|
335
|
+
while (
|
|
336
|
+
end < before.length - start &&
|
|
337
|
+
before[before.length - 1 - end] === after[after.length - 1 - end]
|
|
338
|
+
)
|
|
339
|
+
end++;
|
|
340
|
+
return {
|
|
341
|
+
offset: start,
|
|
342
|
+
remove: before.length - start - end,
|
|
343
|
+
text: after.slice(start, after.length - end),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function StickyEditor({
|
|
348
|
+
element,
|
|
349
|
+
}: {
|
|
350
|
+
element: TypedBoardElement<StickyData>;
|
|
351
|
+
}) {
|
|
307
352
|
const api = useWhiteboardAPI();
|
|
308
353
|
const [binding] = useState(() => api.getTextBinding(element.id, "text"));
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
354
|
+
const [draft, setDraft] = useState(() => binding.getSnapshot().value);
|
|
355
|
+
const [error, setError] = useState<string | null>(null);
|
|
356
|
+
|
|
357
|
+
// 协作者的修改到达时刷新显示;卸载时释放句柄
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
const stop = binding.subscribe(() => setDraft(binding.getSnapshot().value));
|
|
360
|
+
return () => {
|
|
361
|
+
stop();
|
|
362
|
+
binding.dispose();
|
|
363
|
+
};
|
|
364
|
+
}, [binding]);
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<>
|
|
368
|
+
<textarea
|
|
369
|
+
value={draft}
|
|
370
|
+
readOnly={api.readonly}
|
|
371
|
+
onChange={(event) => {
|
|
372
|
+
const next = event.target.value;
|
|
373
|
+
const { value, revision } = binding.getSnapshot();
|
|
374
|
+
setDraft(next);
|
|
375
|
+
try {
|
|
376
|
+
binding.edit({ ...diff(value, next), revision });
|
|
377
|
+
setError(null);
|
|
378
|
+
} catch {
|
|
379
|
+
// 版本过期或已变成只读:保留用户的输入,不要用新值覆盖
|
|
380
|
+
setError("修改没有保存");
|
|
381
|
+
}
|
|
382
|
+
}}
|
|
383
|
+
/>
|
|
384
|
+
{error && <p role="alert">{error}</p>}
|
|
385
|
+
</>
|
|
386
|
+
);
|
|
312
387
|
}
|
|
313
388
|
```
|
|
314
389
|
|
|
390
|
+
- `binding.getSnapshot()` 读取 `{ value, revision }`,`binding.subscribe(listener)` 监听变化,`binding.edit({ offset, remove, text, revision })` 按位置修改。
|
|
315
391
|
- 在组件里取一次句柄并复用,卸载时调用 `dispose`。页面隐藏后组件的 effect 会清理,句柄随之失效,再次显示时重新取。
|
|
316
392
|
- 修改时带上读取时的 `revision`。版本过期或文档变成只读时,修改会被拒绝;这时保留用户的输入,不要读取新值后直接覆盖。
|
|
317
393
|
|
|
318
394
|
### 异步操作
|
|
319
395
|
|
|
320
|
-
|
|
396
|
+
插件停用、切换资料库、画布关闭或变成只读后,迟到的修改会被拒绝。异步操作开始前调用 `api.captureSubmission(elementId)`,它返回一个检查函数;`await` 结束后先调用它,返回 `false` 就放弃这次结果:
|
|
321
397
|
|
|
322
398
|
```ts
|
|
323
399
|
const stillValid = api.captureSubmission(element.id);
|
|
@@ -337,6 +413,8 @@ api.updateElementData(element.id, { title });
|
|
|
337
413
|
- `usePageSketch()` 读取所在页面的画风;`sketch.hashSeed(text)` 为预览生成稳定的随机种子。
|
|
338
414
|
- 属性面板可以使用 `AttrPopover`、`AttrToggle`、`OptionGrid`、`Seg` 组件,`SketchPopover` 提供与 Tau 一致的笔触设置。
|
|
339
415
|
|
|
416
|
+
这些都从 `@tau/plugins/whiteboard` 导入。
|
|
417
|
+
|
|
340
418
|
## 简略预览
|
|
341
419
|
|
|
342
420
|
`schematic(element, { dark })` 返回一组简单图元(矩形、路径等,类型见 `SchematicShape`),用于白板列表和导出弹窗里的缩略预览:
|
|
@@ -370,14 +448,14 @@ defineWhiteboardExtension({
|
|
|
370
448
|
});
|
|
371
449
|
```
|
|
372
450
|
|
|
373
|
-
-
|
|
451
|
+
- 存储按插件和资料库隔离,与 `context.storage` 是同一份数据。它保存的是插件偏好,不随白板同步给协作者。
|
|
374
452
|
- 只在交互贡献、工具面板、属性面板和 `create.build` 中使用。元素的 `render` 和 `schematic` 只能依据元素数据,不能读存储。
|
|
375
453
|
- 读取失败时不要当成空数据再写回,否则会覆盖用户原有的偏好。
|
|
376
454
|
|
|
377
455
|
## 样式
|
|
378
456
|
|
|
379
457
|
- 颜色使用 Tau 的主题变量(如 `var(--tau-accent)`),这样会跟随明暗主题。
|
|
380
|
-
- 需要 Tailwind 工具类时,可以导入 `@tau/plugins/tailwind.css`,它提供 Tau
|
|
458
|
+
- 需要 Tailwind 工具类时,可以导入 `@tau/plugins/tailwind.css`,它提供 Tau 语义类到主题变量的映射。类名要加插件专属前缀,见[用 Tailwind 时加前缀](ui-components.md#用-tailwind-时加前缀)。
|
|
381
459
|
|
|
382
460
|
## 停用与卸载
|
|
383
461
|
|
package/package.json
CHANGED
|
@@ -32,6 +32,8 @@ export interface ASRAudioFile {
|
|
|
32
32
|
name: string;
|
|
33
33
|
mimeType: string;
|
|
34
34
|
sizeBytes: number;
|
|
35
|
+
/** 同一份音频的公网可下载地址;宿主有远程副本时提供,提供方可直接交给云端服务下载 */
|
|
36
|
+
url?: string;
|
|
35
37
|
open(signal: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
36
38
|
}
|
|
37
39
|
export interface ASRRequest {
|
|
@@ -21,6 +21,7 @@ import type { PluginSidebar } from "./sidebar";
|
|
|
21
21
|
import type { PluginHome } from "./home";
|
|
22
22
|
import type { PluginActions } from "./actions";
|
|
23
23
|
import type { PluginViews } from "./views";
|
|
24
|
+
import type { PluginNotebooks } from "./notebooks";
|
|
24
25
|
import type { PluginExcerpts, PluginMaterials } from "./excerpts";
|
|
25
26
|
import type { PluginMCP } from "./mcp";
|
|
26
27
|
import type { PluginChat } from "./chat";
|
|
@@ -82,6 +83,8 @@ export interface PluginContext {
|
|
|
82
83
|
readonly actions: PluginActions;
|
|
83
84
|
/** 卡片、文章、项目文档详情里的区块 */
|
|
84
85
|
readonly views: PluginViews;
|
|
86
|
+
/** Notebook 的生成菜单里加产物;只在桌面主窗口 */
|
|
87
|
+
readonly notebooks: PluginNotebooks;
|
|
85
88
|
readonly excerpts: PluginExcerpts;
|
|
86
89
|
readonly materials: PluginMaterials;
|
|
87
90
|
readonly fetch: typeof globalThis.fetch;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
export { APP_FOREGROUND_EVENT, APP_BACKGROUND_EVENT } from "./foreground-host";
|
|
2
3
|
export interface PluginEnvironment {
|
|
3
4
|
readonly platform: "desktop" | "android" | "ios" | "web";
|
|
4
5
|
/** WebView 报告的可用指针精度,不代表当前输入设备或悬停能力。 */
|
|
@@ -18,6 +19,8 @@ export declare function createPluginEnvironmentStore(initial: PluginEnvironment)
|
|
|
18
19
|
}>;
|
|
19
20
|
/** 平台由宿主提供,输入信息来自媒体查询。 */
|
|
20
21
|
export declare function createBrowserPluginEnvironment(platform: PluginEnvironment["platform"], viewport: Window): {
|
|
22
|
+
notifyForeground: (force?: boolean) => void | undefined;
|
|
23
|
+
notifyBackground: () => void | undefined;
|
|
21
24
|
connect(): () => void;
|
|
22
25
|
getSnapshot: () => PluginEnvironment;
|
|
23
26
|
subscribe: (listener: () => void) => () => void;
|
|
@@ -3,6 +3,8 @@ import type { Disposable, JsonValue } from "./contract";
|
|
|
3
3
|
export interface PluginMaterialRef {
|
|
4
4
|
readonly kind: string;
|
|
5
5
|
readonly id: number;
|
|
6
|
+
/** 宿主签发的稳定身份,必须与整个引用一起原样传回。 */
|
|
7
|
+
readonly identity: string;
|
|
6
8
|
}
|
|
7
9
|
/** 摘录来源:一本书、一个网页、一篇文献 */
|
|
8
10
|
export interface PluginExcerptSource {
|
|
@@ -83,6 +85,7 @@ export interface PluginExcerpts {
|
|
|
83
85
|
export interface PluginMaterialAction {
|
|
84
86
|
id: string;
|
|
85
87
|
label: string;
|
|
88
|
+
/** 动作结果由宿主统一提示,插件不重复提示。 */
|
|
86
89
|
run(): Promise<void>;
|
|
87
90
|
}
|
|
88
91
|
export interface PluginMaterials {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const APP_FOREGROUND_EVENT = "tau:app-foreground";
|
|
2
|
+
export declare const APP_BACKGROUND_EVENT = "tau:app-background";
|
|
3
|
+
/** 应用生命周期与页面保活分开;原生恢复不依赖 WebView 是否补发可见性事件。 */
|
|
4
|
+
export declare function createAppForegroundBridge(viewport: Window, debounceMs?: number): {
|
|
5
|
+
resume: (force?: boolean) => void;
|
|
6
|
+
background: () => void;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
};
|
|
@@ -31,6 +31,7 @@ export type * from "./home";
|
|
|
31
31
|
export type * from "./actions";
|
|
32
32
|
export { PLUGIN_ACTION_TARGET_KINDS } from "./actions";
|
|
33
33
|
export type * from "./views";
|
|
34
|
+
export type * from "./notebooks";
|
|
34
35
|
export { PLUGIN_ENTITY_PANEL_KINDS } from "./views";
|
|
35
36
|
export type * from "./excerpts";
|
|
36
37
|
export type * from "./data";
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { Disposable, PluginContext } from "./contract";
|
|
3
|
+
import type { PluginIcon } from "./icons";
|
|
4
|
+
import type { JsonValue } from "./json";
|
|
5
|
+
import type { PluginOwnEntity } from "./entities";
|
|
6
|
+
/**
|
|
7
|
+
* Notebook 输出:插件在 Notebook 的「生成」菜单里加一种产物。对话框、资料勾选、AI 生成与执行过程页
|
|
8
|
+
* 都由 Tau 负责,AI 走 Notebook 已有的生成流程与资料检索;插件只说明要什么(prepare),
|
|
9
|
+
* 拿到生成的正文后自己处理(complete)。
|
|
10
|
+
*/
|
|
11
|
+
/** 用户勾选的一份资料(只有名称,插件读不到资料内容) */
|
|
12
|
+
export interface PluginNotebookOutputResource {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PluginNotebookOutputTarget {
|
|
17
|
+
notebook: {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
};
|
|
21
|
+
resources: readonly PluginNotebookOutputResource[];
|
|
22
|
+
}
|
|
23
|
+
/** 插件在对话框中间放的选项区:value 由插件定义,宿主原样保存并在 prepare 时交回 */
|
|
24
|
+
export interface PluginNotebookOutputOptionsProps {
|
|
25
|
+
readonly context: PluginContext;
|
|
26
|
+
readonly target: PluginNotebookOutputTarget;
|
|
27
|
+
readonly value: JsonValue | undefined;
|
|
28
|
+
onChange(value: JsonValue): void;
|
|
29
|
+
/** 传入原因时「开始生成」不可用,并在对话框底部显示原因;null 解除 */
|
|
30
|
+
setBlocker(reason: string | null): void;
|
|
31
|
+
}
|
|
32
|
+
export interface PluginNotebookOutputPrepareInput extends PluginNotebookOutputTarget {
|
|
33
|
+
/** 用户在「额外要求」里写的话,可能为空 */
|
|
34
|
+
userPrompt: string;
|
|
35
|
+
options: JsonValue | undefined;
|
|
36
|
+
signal: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
/** 交给 AI 的任务说明;资料清单、检索工具与通用生成规则由 Tau 补上 */
|
|
39
|
+
export interface PluginNotebookOutputPlan {
|
|
40
|
+
/** 这一次产物的插件实体 ID(插件先建好占位),类型须为 registerOutput 声明的 kind */
|
|
41
|
+
entity: string;
|
|
42
|
+
/** 执行过程页显示的标题 */
|
|
43
|
+
title: string;
|
|
44
|
+
/** 任务要求与输出格式:写什么、怎么写、最终只输出什么 */
|
|
45
|
+
instructions: string;
|
|
46
|
+
/** 补充提醒,按条列出 */
|
|
47
|
+
reminders?: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
/** complete 期间向执行过程页报告进度 */
|
|
50
|
+
export interface PluginNotebookOutputTask {
|
|
51
|
+
/** 当前阶段的一句话,如「合成语音」 */
|
|
52
|
+
phase(text: string): void;
|
|
53
|
+
/** 分步进度;total 为 0 时不显示进度条 */
|
|
54
|
+
progress(done: number, total: number): void;
|
|
55
|
+
}
|
|
56
|
+
export interface PluginNotebookOutputCompleteInput {
|
|
57
|
+
entity: string;
|
|
58
|
+
/** AI 最终输出的正文 */
|
|
59
|
+
text: string;
|
|
60
|
+
task: PluginNotebookOutputTask;
|
|
61
|
+
signal: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
export interface PluginNotebookOutputFailInput {
|
|
64
|
+
entity: string;
|
|
65
|
+
/** cancelled:用户停止;failed:生成或 complete 出错 */
|
|
66
|
+
reason: "cancelled" | "failed";
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
/** 产物在 Notebook 阅读区里的显示 */
|
|
70
|
+
export interface PluginNotebookOutputViewProps {
|
|
71
|
+
readonly context: PluginContext;
|
|
72
|
+
readonly entity: PluginOwnEntity;
|
|
73
|
+
readonly notebook: {
|
|
74
|
+
id: string;
|
|
75
|
+
title: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export interface PluginNotebookOutputDefinition {
|
|
79
|
+
/** 插件内唯一 */
|
|
80
|
+
id: string;
|
|
81
|
+
/** 菜单与执行过程页里的名称,如「播客」 */
|
|
82
|
+
title: string;
|
|
83
|
+
icon?: PluginIcon;
|
|
84
|
+
/** 一句话说明,显示在对话框标题下 */
|
|
85
|
+
description?: string;
|
|
86
|
+
/** 产物对应的插件实体类型(须先 entities.registerKind) */
|
|
87
|
+
kind: string;
|
|
88
|
+
options?: ComponentType<PluginNotebookOutputOptionsProps>;
|
|
89
|
+
view: ComponentType<PluginNotebookOutputViewProps>;
|
|
90
|
+
prepare(input: PluginNotebookOutputPrepareInput): Promise<PluginNotebookOutputPlan>;
|
|
91
|
+
complete(input: PluginNotebookOutputCompleteInput): Promise<void>;
|
|
92
|
+
/** 生成失败、complete 抛错或用户停止时调用;插件据此清理占位或标为失败 */
|
|
93
|
+
fail?(input: PluginNotebookOutputFailInput): Promise<void> | void;
|
|
94
|
+
}
|
|
95
|
+
export interface PluginNotebooks {
|
|
96
|
+
/** 只在主窗口的 Notebook 里出现;目前只有桌面支持 */
|
|
97
|
+
registerOutput(definition: PluginNotebookOutputDefinition): Disposable;
|
|
98
|
+
}
|