@xiongtao.xt/tau-plugins 0.47.0 → 0.49.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/client/{chunk-M3YEVDN4.js → chunk-CQ3UMKDY.js} +2 -3
  3. package/client/{chunk-X6MBLKAL.js → chunk-MNFXOBPW.js} +3 -8
  4. package/docs/README.md +26 -31
  5. package/docs/ai.md +12 -8
  6. package/docs/backend.md +15 -6
  7. package/docs/editor-collaboration.md +96 -130
  8. package/docs/editor.md +95 -29
  9. package/docs/excerpts.md +28 -9
  10. package/docs/flashcards.md +23 -6
  11. package/docs/getting-started.md +58 -26
  12. package/docs/mcp.md +18 -6
  13. package/docs/plugin-basics.md +51 -47
  14. package/docs/portability.md +92 -73
  15. package/docs/providers/README.md +22 -17
  16. package/docs/providers/asr.md +111 -20
  17. package/docs/providers/embeddings.md +77 -0
  18. package/docs/providers/images.md +17 -5
  19. package/docs/providers/publish.md +20 -7
  20. package/docs/providers/sync.md +26 -11
  21. package/docs/providers/tts.md +22 -8
  22. package/docs/providers/upload.md +30 -15
  23. package/docs/providers/video.md +19 -7
  24. package/docs/release.md +9 -9
  25. package/docs/services.md +19 -9
  26. package/docs/site-data.md +4 -4
  27. package/docs/skills.md +2 -1
  28. package/docs/storage-and-network.md +32 -7
  29. package/docs/ui.md +171 -92
  30. package/docs/user-data.md +95 -38
  31. package/docs/whiteboard.md +105 -53
  32. package/package.js +1 -1
  33. package/package.json +3 -2
  34. package/portable.js +2 -4
  35. package/publish-artifacts.js +15 -17
  36. package/types/packages/collaboration/src/document-adapter.d.ts +7 -0
  37. package/types/packages/collaboration/src/document-installation.d.ts +15 -0
  38. package/types/packages/collaboration/src/document-operations.d.ts +37 -0
  39. package/types/packages/collaboration/src/document-protocol.d.ts +41 -0
  40. package/types/packages/collaboration/src/document-sync.d.ts +62 -0
  41. package/types/packages/collaboration/src/document-version.d.ts +13 -0
  42. package/types/packages/collaboration/src/document-write-queue.d.ts +10 -0
  43. package/types/packages/collaboration/src/encoding.d.ts +2 -0
  44. package/types/packages/collaboration/src/index.d.ts +26 -0
  45. package/types/packages/collaboration/src/model-limits.d.ts +22 -0
  46. package/types/packages/collaboration/src/node-document.d.ts +21 -0
  47. package/types/packages/collaboration/src/node-tree-history.d.ts +34 -0
  48. package/types/packages/collaboration/src/node-tree.d.ts +107 -0
  49. package/types/packages/collaboration/src/palette.d.ts +4 -0
  50. package/types/packages/collaboration/src/presence-budget.d.ts +2 -0
  51. package/types/packages/collaboration/src/protocol.d.ts +0 -5
  52. package/types/packages/collaboration/src/resource-policy.d.ts +1 -0
  53. package/types/packages/collaboration/src/shared-values.d.ts +4 -0
  54. package/types/packages/collaboration/src/text-segments.d.ts +52 -0
  55. package/types/packages/collaboration/src/whiteboard-baseline.d.ts +7 -0
  56. package/types/packages/collaboration/src/whiteboard-document.d.ts +7 -0
  57. package/types/packages/collaboration/src/whiteboard-model.d.ts +85 -0
  58. package/types/packages/collaboration/src/whiteboard-presence.d.ts +28 -0
  59. package/types/packages/collaboration/src/whiteboard-presentation.d.ts +21 -0
  60. package/types/packages/collaboration/src/whiteboard-relations.d.ts +11 -0
  61. package/types/packages/collaboration/src/whiteboard-transfer.d.ts +27 -0
  62. package/types/packages/db-schema/data-versions.d.ts +0 -5
  63. package/types/packages/editor/contracts.d.ts +1 -1
  64. package/types/packages/editor/src/core/CoreEditor.d.ts +2 -2
  65. package/types/packages/editor/src/core/api/extension.d.ts +14 -4
  66. package/types/packages/editor/src/core/api/index.d.ts +0 -1
  67. package/types/packages/editor/src/core/index.d.ts +1 -1
  68. package/types/packages/editor/src/core/kit/EditorKit.d.ts +3 -4
  69. package/types/packages/editor/src/core/kit/ExtensionAssembly.d.ts +1 -2
  70. package/types/packages/editor/src/core/kit/context.d.ts +2 -2
  71. package/types/packages/editor/src/extensions/diagram/src/types/index.d.ts +1 -2
  72. package/types/packages/editor/src/extensions/media/src/types/element/image.d.ts +1 -8
  73. package/types/packages/editor/src/extensions/tabs/src/types.d.ts +0 -11
  74. package/types/packages/editor/src/presets/default.d.ts +2 -2
  75. package/types/packages/plugins/src/contract.d.ts +3 -0
  76. package/types/packages/plugins/src/embeddings.d.ts +16 -0
  77. package/types/packages/plugins/src/index.d.ts +2 -1
  78. package/types/packages/plugins/src/package.d.ts +2 -2
  79. package/types/packages/plugins/src/portable.d.ts +4 -10
  80. package/types/packages/plugins/src/provider-form.d.ts +35 -1
  81. package/types/packages/plugins/src/render-artifact.d.ts +2 -2
  82. package/types/packages/plugins/src/rendering.d.ts +4 -4
  83. package/types/packages/plugins/src/settings.d.ts +8 -5
  84. package/types/packages/ui/src/primitives/ResizableAndHideableSidebar.d.ts +0 -4
  85. package/types/packages/whiteboard/src/Board.d.ts +3 -1
  86. package/types/packages/whiteboard/src/WhiteBoard.d.ts +2 -0
  87. package/types/packages/whiteboard/src/collaboration/presence.d.ts +23 -0
  88. package/types/packages/whiteboard/src/constants/text-style.d.ts +5 -7
  89. package/types/packages/whiteboard/src/context.d.ts +23 -0
  90. package/types/packages/whiteboard/src/document.d.ts +8 -1
  91. package/types/packages/whiteboard/src/extensions/api.d.ts +4 -7
  92. package/types/packages/whiteboard/src/extensions/authorTypes.d.ts +2 -4
  93. package/types/packages/whiteboard/src/extensions/runtime.d.ts +1 -1
  94. package/types/packages/whiteboard/src/plugins/RichTextPlugin.d.ts +0 -4
  95. package/types/packages/whiteboard/src/transforms/ViewPortTransforms.d.ts +1 -0
  96. package/types/packages/whiteboard/src/utils/index.d.ts +0 -1
  97. package/docs/api-support.md +0 -95
  98. package/docs/content-metrics.md +0 -45
  99. package/docs/websocket.md +0 -39
  100. package/docs/whiteboard-collaboration.md +0 -67
  101. package/types/packages/editor/src/core/api/legacy.d.ts +0 -10
  102. package/types/packages/editor/src/extensions/diagram/src/types/typst.d.ts +0 -9
  103. package/types/packages/whiteboard/src/utils/Constraints.d.ts +0 -6
package/docs/editor.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # 编辑器扩展
2
2
 
3
- 编辑器扩展让你在 Tau 文档中添加自定义块。跨端使用静态 editorExtensions/editorCodecs,移动普通正文提供触摸插入、标准块操作与源码编辑;动态 context.editor.register 只在桌面工作台适用。桌面拖拽和旧内容插件博客发布不能推断为格式 3 移动长按拖拽或博客分发已经接入,详见 [API 支持矩阵](api-support.md)。
4
-
5
- 这一篇先用一个完整的例子走一遍,再逐项介绍扩展能声明的内容。
3
+ 在 Tau 的文档里加一种自己的块:图表、公式、乐谱、可交互的组件。块的数据随文档保存、同步和发布,桌面、手机和用户发布的博客使用同一份渲染代码。
6
4
 
7
5
  ## 第一个块:计数器
8
6
 
9
- 正文节点在 editorExtensions 中注册,Markdown 转换在 editorCodecs 中注册。宿主据此装配正文、源码编辑和样式编译;manifest 不重复登记节点、等级或能力。targets 只声明已完整适配的平台及最低客户端版本。
10
-
11
7
  ### 1. 定义节点和扩展
12
8
 
13
9
  ```tsx
14
10
  import { useState } from "react";
15
- import { definePlugin, defineEditorElement, defineEditorExtension } from "@tau/plugins";
11
+ import {
12
+ definePlugin,
13
+ defineEditorElement,
14
+ defineEditorExtension,
15
+ } from "@tau/plugins";
16
16
 
17
17
  declare const __PLUGIN_META__: { id: string; name: string; version: string };
18
18
 
@@ -34,7 +34,10 @@ function Counter({ initial }: { initial: number }) {
34
34
  const [count, setCount] = useState(initial);
35
35
  return (
36
36
  <div className="yourname-counter" contentEditable={false}>
37
- <button onMouseDown={event => event.preventDefault()} onClick={() => setCount(n => n + 1)}>
37
+ <button
38
+ onMouseDown={(event) => event.preventDefault()}
39
+ onClick={() => setCount((n) => n + 1)}
40
+ >
38
41
  计数:{count}
39
42
  </button>
40
43
  </div>
@@ -81,7 +84,7 @@ export default definePlugin({
81
84
  title: "计数器",
82
85
  keywords: ["counter", "计数"],
83
86
  description: "一个可以点击计数的块",
84
- onClick: editor =>
87
+ onClick: (editor) =>
85
88
  editor.insertNode({
86
89
  type: "yourname.counter",
87
90
  initial: 0,
@@ -156,7 +159,7 @@ function Counter({ element }: { element: CounterElement }) {
156
159
  const { update } = useElement(element);
157
160
  return (
158
161
  <button
159
- onMouseDown={event => event.preventDefault()}
162
+ onMouseDown={(event) => event.preventDefault()}
160
163
  onClick={() => update({ initial: element.initial + 1 })}
161
164
  >
162
165
  计数:{element.initial}
@@ -206,7 +209,12 @@ defineEditorElement({
206
209
  选中块后浮在块上方的属性条,用 `BlockToolbar`、`BlockToolbarButton`、`BlockToolbarGap` 组成,外观和 Tau 自带的图片块一致。上方放不下时自动翻到下方,点击按钮不会让编辑器失去光标。
207
210
 
208
211
  ```tsx
209
- import { BlockToolbar, BlockToolbarButton, BlockToolbarGap, useElement } from "@tau/plugins";
212
+ import {
213
+ BlockToolbar,
214
+ BlockToolbarButton,
215
+ BlockToolbarGap,
216
+ useElement,
217
+ } from "@tau/plugins";
210
218
 
211
219
  function Chart({ element }: { element: ChartElement }) {
212
220
  const { selected, readOnly, update, openMenu } = useElement(element);
@@ -224,7 +232,7 @@ function Chart({ element }: { element: ChartElement }) {
224
232
  <BlockToolbarButton
225
233
  title="更多"
226
234
  icon={<MoreHorizontal size={15} />}
227
- onClick={event => {
235
+ onClick={(event) => {
228
236
  const rect = event.currentTarget.getBoundingClientRect();
229
237
  openMenu({ x: rect.left, y: rect.bottom + 6 });
230
238
  }}
@@ -292,7 +300,13 @@ defineEditorExtension({
292
300
  },
293
301
  ],
294
302
  hotkeys: [{ key: "mod+shift+0", command: "yourname.counter.reset" }],
295
- menu: [{ id: "yourname.counter.reset", title: "重置计数", command: "yourname.counter.reset" }],
303
+ menu: [
304
+ {
305
+ id: "yourname.counter.reset",
306
+ title: "重置计数",
307
+ command: "yourname.counter.reset",
308
+ },
309
+ ],
296
310
  });
297
311
  ```
298
312
 
@@ -358,12 +372,10 @@ behaviorsFor: {
358
372
 
359
373
  ## 块会在哪里显示
360
374
 
361
- 你的块会出现在两个地方:
362
-
363
- - **Tau 桌面端**的编辑器。
375
+ - **Tau 桌面端和手机**的编辑器。插件声明了 `android`、`ios` 时,手机上安装插件后就能插入和编辑你的块,触摸上的适配见[多端适配 · 编辑器块](portability.md#编辑器块)。
364
376
  - **用户发布的博客**。博客使用同一个 `render` 组件,你不需要另写一份。
365
377
 
366
- 移动端和浏览器扩展不运行插件,遇到你的块时保留数据,并显示一个通用的占位。
378
+ 没有安装插件的设备和浏览器扩展里,块的数据原样保留,显示为一个通用的占位。
367
379
 
368
380
  因为同一份代码要在博客里运行,渲染相关的代码需要满足:
369
381
 
@@ -404,10 +416,13 @@ export default definePlugin({
404
416
  type: "yourname.counter",
405
417
  isVoid: true,
406
418
  // 导出:节点 → Markdown
407
- serializer: { toMarkdown: element => `::yourname-counter{initial=${element.initial}}` },
419
+ serializer: {
420
+ toMarkdown: (element) =>
421
+ `::yourname-counter{initial=${element.initial}}`,
422
+ },
408
423
  // 导入:Markdown → 节点
409
424
  directives: {
410
- "yourname-counter": attributes => ({
425
+ "yourname-counter": (attributes) => ({
411
426
  type: "yourname.counter",
412
427
  initial: Number(attributes.initial) || 0,
413
428
  children: [{ type: "formatted", text: "" }],
@@ -444,9 +459,21 @@ interface DiagramElement {
444
459
  children: { type: "formatted"; text: string }[];
445
460
  }
446
461
 
447
- function DiagramBlock({ element, children }: { element: DiagramElement; children: ReactNode }) {
462
+ function DiagramBlock({
463
+ element,
464
+ children,
465
+ }: {
466
+ element: DiagramElement;
467
+ children: ReactNode;
468
+ }) {
448
469
  return (
449
- <SourceBlockEditor element={element} field="content" mode="javascript" title="图表" icon={Code}>
470
+ <SourceBlockEditor
471
+ element={element}
472
+ field="content"
473
+ mode="javascript"
474
+ title="图表"
475
+ icon={Code}
476
+ >
450
477
  <DiagramPreview source={element.content} />
451
478
  {children}
452
479
  </SourceBlockEditor>
@@ -460,7 +487,7 @@ export const diagramElement = defineEditorElement<DiagramElement>({
460
487
  collaboration: { textFields: ["content"] },
461
488
  kind: "block",
462
489
  isVoid: true,
463
- render: props => <DiagramBlock {...props} />,
490
+ render: (props) => <DiagramBlock {...props} />,
464
491
  });
465
492
  ```
466
493
 
@@ -504,7 +531,7 @@ export const diagramElement = defineEditorElement<DiagramElement>({
504
531
 
505
532
  ## 图片、视频与音频
506
533
 
507
- 节点里存的图片、视频、音频地址可能是本地路径、远程地址或共享文档里的资源,不能直接交给 `<img>`。用宿主的媒体组件显示,解析方式与 Tau 自带的图片块相同:本地路径转成可加载的地址,远程资源按用户的缓存设置下载,共享文档里的资源经协作服务解析。
534
+ 节点里存的图片、视频、音频地址可能是本地路径、远程地址或共享文档里的资源,不能直接交给 `<img>`。用 Tau 提供的媒体组件显示,解析方式与 Tau 自带的图片块相同:本地路径转成可加载的地址,远程资源按用户的缓存设置下载,共享文档里的资源经协作服务解析。
508
535
 
509
536
  ```tsx
510
537
  import { MediaImage, useMediaAppearance } from "@tau/plugins";
@@ -512,7 +539,10 @@ import { MediaImage, useMediaAppearance } from "@tau/plugins";
512
539
  function Photo({ element }: { element: PhotoElement }) {
513
540
  const appearance = useMediaAppearance();
514
541
  return (
515
- <figure contentEditable={false} data-radius={element.borderRadius ?? appearance?.borderRadius}>
542
+ <figure
543
+ contentEditable={false}
544
+ data-radius={element.borderRadius ?? appearance?.borderRadius}
545
+ >
516
546
  <MediaImage url={element.url} alt={element.caption} />
517
547
  </figure>
518
548
  );
@@ -522,7 +552,7 @@ function Photo({ element }: { element: PhotoElement }) {
522
552
  | 接口 | 用途 |
523
553
  | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
524
554
  | `MediaImage` | 显示图片,参数为 `url`、`alt`、`className`、`style`、`loading`、`onLoadError` 等 |
525
- | `MediaVideo` / `MediaAudio` | 宿主的视频、音频播放器,参数为 `src` 与原生媒体属性 |
555
+ | `MediaVideo` / `MediaAudio` | Tau 的视频、音频播放器,参数为 `src` 与原生媒体属性 |
526
556
  | `useResource(url, { kind })` | 自己绘制时使用:返回 `src`、`status`(`loading` / `ready` / `error`)与 `retry()`,元素加载失败时调用 `retry` 重新解析 |
527
557
  | `useResourceUpload()` | 返回上传函数,把用户选的文件存进当前的资源存储并返回可写入节点的地址;只读编辑器和博客里为 `undefined` |
528
558
  | `useMediaAppearance()` | 用户设置的媒体默认圆角与阴影(`none` / `sm` / `md` / `lg`);博客里取发布设置。节点自己有设置时以节点为准 |
@@ -548,7 +578,9 @@ defineEditorElement({
548
578
  kind: "block",
549
579
  isVoid: true,
550
580
  render: Gallery,
551
- resources: [{ path: "images[].url", kind: "image", alt: "desc", caption: "desc" }],
581
+ resources: [
582
+ { path: "images[].url", kind: "image", alt: "desc", caption: "desc" },
583
+ ],
552
584
  });
553
585
  ```
554
586
 
@@ -564,7 +596,7 @@ defineEditorElement({
564
596
 
565
597
  ### 完整示例:图册
566
598
 
567
- [图册插件](https://github.com/LastKnightCoder/tau-plugin-image-gallery)把这一篇里的能力组合成了一个完整的媒体块,可以对照它的源码写自己的块:
599
+ [图册插件](https://github.com/LastKnightCoder/tau-plugin-image-gallery)把下面这些能力组合成了一个完整的媒体块,可以对照它的源码写自己的块:
568
600
 
569
601
  | 需要 | 图册的做法 |
570
602
  | ------------------------ | ------------------------------------------------------------------------------------------------------- |
@@ -622,7 +654,7 @@ defineEditorExtension({
622
654
  htmlSerializers: [
623
655
  {
624
656
  type: "yourname.counter",
625
- toHtml: element => `<p>计数:${Number(element.initial)}</p>`,
657
+ toHtml: (element) => `<p>计数:${Number(element.initial)}</p>`,
626
658
  },
627
659
  ],
628
660
  });
@@ -630,6 +662,40 @@ defineEditorExtension({
630
662
 
631
663
  `toHtml` 返回 HTML 字符串,文本内容要自己转义。它只用于静态导出,博客里的显示仍然使用 `render`。
632
664
 
633
- ## 正文字数与空文档
665
+ ## 字数统计
666
+
667
+ Tau 统计正文字数时,会自动计入普通段落和 `children` 里的文字。块的文字存在自定义字段里(如题目、源码)时,在插件定义上用 `editorMetrics` 声明哪些字段计入字数:
668
+
669
+ ```ts
670
+ import type { EditorMetricRule } from "@tau/plugins";
671
+
672
+ const editorMetrics = [
673
+ { type: "yourname.quiz", textFields: ["question", "answers[].text"] },
674
+ { type: "yourname.photo", textFields: [] },
675
+ ] as const satisfies readonly EditorMetricRule[];
676
+
677
+ export default definePlugin({
678
+ ...__PLUGIN_META__,
679
+ editorExtensions,
680
+ editorMetrics,
681
+ });
682
+ ```
683
+
684
+ - `textFields` 里写字段路径,`answers[].text` 表示 `answers` 数组每一项的 `text`。缺失或不是字符串的字段不计数。题目「天空是什么颜色」、答案「蓝色」合计 9 字。
685
+ - 只声明正文,不声明 ID、地址、编译结果这类字段。纯图片这类没有文字的块写 `textFields: []`。
686
+ - `children` 里的文字已经自动计入,不要再声明 `children[].text`,否则会重复统计。
687
+ - 只能声明本插件的节点类型,每个类型声明一次。规则是纯数据,不能写函数。
688
+
689
+ 正文不在 `children` 里、而在别的字段里放着一组子节点时(如折叠列表把隐藏的内容放在 `allContent`),用 `additionalChildren` 告诉 Tau 去哪里找:
690
+
691
+ ```ts
692
+ {
693
+ type: "yourname.folded-list",
694
+ textFields: [],
695
+ additionalChildren: [{ path: "allContent", when: "isFold", skip: 1 }],
696
+ }
697
+ ```
698
+
699
+ `path` 是子节点或子节点数组所在的字段;`when` 指定一个布尔字段,为 `true` 时才计入;`skip` 跳过开头几项。新设计的块尽量把正文都放进 `children`,用不到这项。
634
700
 
635
- 自定义节点通过 SDK 0.44.0 的 `editorMetrics` 声明哪些字段参与统计,与 `editorExtensions`、`editorCodecs` 一起静态导出。代码示例、数组字段、容器遍历与空文档边界见[正文字数协议](content-metrics.md)。
701
+ 字数为 0 不代表文档是空的:只有图片、分割线的文档字数也是 0。不要用字数判断一篇正文能否删除或复用。块内按退格、方向键时怎样算「空块」,由节点声明的 `isEmpty` 决定,与字数统计无关。
package/docs/excerpts.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 摘录
2
2
 
3
- 如果你的插件从外部服务读取划线、批注或收藏(读书笔记、网页高亮、文献批注等),可以把它们写成 Tau 的**摘录**。写入后,用户能在全局搜索和 AI 对话中找到它们,在文档中引用,也能把它们转为卡片或问题。
3
+ 如果你的插件从外部服务读取划线、批注或收藏(读书笔记、网页高亮、文献批注等),可以把它们写成 Tau 的**摘录**(仅桌面)。写入后,用户能在全局搜索和 AI 对话中找到它们,在文档中引用,也能把它们转为卡片或问题。
4
4
 
5
5
  摘录属于用户:插件停用或卸载后,已经写入的摘录和引用都会保留。
6
6
 
@@ -18,7 +18,8 @@ const bookPage = context.pages.register({
18
18
 
19
19
  context.excerpts.register({
20
20
  label: "我的读书笔记",
21
- open: ({ sourceKey, externalId }) => bookPage.open({ bookId: sourceKey, noteId: externalId }),
21
+ open: ({ sourceKey, externalId }) =>
22
+ bookPage.open({ bookId: sourceKey, noteId: externalId }),
22
23
  });
23
24
  ```
24
25
 
@@ -34,7 +35,11 @@ context.excerpts.register({
34
35
  摘录按**来源**分组写入,一个来源可以是一本书、一个网页或一篇文献。写入有两种方式:
35
36
 
36
37
  ```ts
37
- const source = { key: "book-42", title: "设计心理学", url: "https://example.com/books/42" };
38
+ const source = {
39
+ key: "book-42",
40
+ title: "设计心理学",
41
+ url: "https://example.com/books/42",
42
+ };
38
43
 
39
44
  // 全量:以这批条目为准,不在其中的已有条目会被移除
40
45
  await context.excerpts.replace(source, [
@@ -44,7 +49,11 @@ await context.excerpts.replace(source, [
44
49
  location: "第 1 章",
45
50
  time: 1760000000000,
46
51
  },
47
- { externalId: "n2", quote: "示能决定了可能的操作。", note: "和交互设计课的观点一致" },
52
+ {
53
+ externalId: "n2",
54
+ quote: "示能决定了可能的操作。",
55
+ note: "和交互设计课的观点一致",
56
+ },
48
57
  ]);
49
58
 
50
59
  // 增量:只新增、更新或移除指定条目
@@ -104,16 +113,26 @@ const entries = await context.excerpts.items("book-42");
104
113
  ```tsx
105
114
  import { useEffect, useState } from "react";
106
115
  import { Button } from "@tau/ui";
107
- import type { PluginContext, PluginMaterialAction, PluginMaterialRef } from "@tau/plugins";
108
-
109
- function NoteActions({ context, target }: { context: PluginContext; target: PluginMaterialRef }) {
116
+ import type {
117
+ PluginContext,
118
+ PluginMaterialAction,
119
+ PluginMaterialRef,
120
+ } from "@tau/plugins";
121
+
122
+ function NoteActions({
123
+ context,
124
+ target,
125
+ }: {
126
+ context: PluginContext;
127
+ target: PluginMaterialRef;
128
+ }) {
110
129
  const [actions, setActions] = useState<PluginMaterialAction[]>([]);
111
130
  useEffect(() => {
112
- void context.materials.actions(target).then(list => {
131
+ void context.materials.actions(target).then((list) => {
113
132
  if (!context.signal.aborted) setActions(list);
114
133
  });
115
134
  }, [context, target]);
116
- return actions.map(action => (
135
+ return actions.map((action) => (
117
136
  <Button key={action.id} variant="ghost" onClick={() => void action.run()}>
118
137
  {action.label}
119
138
  </Button>
@@ -1,6 +1,6 @@
1
1
  # 闪卡
2
2
 
3
- 插件可以帮用户创建闪卡。有三种方式,从轻到重:
3
+ 插件可以帮用户创建闪卡(仅桌面)。按插件介入的多少,从轻到重有这些方式:
4
4
 
5
5
  | 方式 | 适合 | 需要的权限 |
6
6
  | ------------------------------- | ----------------------------------------- | ------------------------------------------------------- |
@@ -11,7 +11,13 @@
11
11
  在 manifest 中声明用到的权限:
12
12
 
13
13
  ```json
14
- { "permissions": ["flashcards:read", "flashcards:write", "ai:flashcardGeneration"] }
14
+ {
15
+ "permissions": [
16
+ "flashcards:read",
17
+ "flashcards:write",
18
+ "ai:flashcardGeneration"
19
+ ]
20
+ }
15
21
  ```
16
22
 
17
23
  AI 制卡沿用用户在 Tau 中为「闪卡制作」分配的模型,不需要插件另外配置。用量、额度与授权方式和 [AI](ai.md#使用-tau-已有的模型分配) 中的 `requestCapability` 相同,用户撤销授权会取消进行中的生成。
@@ -52,7 +58,9 @@ const result = await context.flashcards.openCreate({
52
58
  await context.flashcards.openCreate({
53
59
  mode: "ai",
54
60
  content: snapshot.markdown,
55
- references: [{ refType: "content", contentRef: card.contentRef, title: card.title }],
61
+ references: [
62
+ { refType: "content", contentRef: card.contentRef, title: card.title },
63
+ ],
56
64
  });
57
65
  ```
58
66
 
@@ -62,13 +70,19 @@ await context.flashcards.openCreate({
62
70
 
63
71
  ```ts
64
72
  const decks = await context.flashcards.listDecks();
65
- const deck = await context.flashcards.createDeck({ name: "力学", description: "基础概念" });
73
+ const deck = await context.flashcards.createDeck({
74
+ name: "力学",
75
+ description: "基础概念",
76
+ });
66
77
 
67
78
  const card = await context.flashcards.createCard({
68
79
  deckId: deck.id,
69
80
  type: "qa",
70
81
  prompt: [
71
- { type: "paragraph", children: [{ type: "formatted", text: "牛顿第二定律的表达式是什么?" }] },
82
+ {
83
+ type: "paragraph",
84
+ children: [{ type: "formatted", text: "牛顿第二定律的表达式是什么?" }],
85
+ },
72
86
  ],
73
87
  data: { answer: "F = ma" },
74
88
  tags: ["力学"],
@@ -104,7 +118,10 @@ const card = await context.flashcards.createCard({
104
118
 
105
119
  ```ts
106
120
  // 只生成草稿,插件可以先筛选,再逐张 createCard
107
- const drafts = await context.flashcards.generate({ content: "需要学习的内容", title: "资料" });
121
+ const drafts = await context.flashcards.generate({
122
+ content: "需要学习的内容",
123
+ title: "资料",
124
+ });
108
125
 
109
126
  // 生成后直接保存,跳过用户预览
110
127
  const result = await context.flashcards.generateAndSave({
@@ -1,46 +1,78 @@
1
1
  # 快速开始
2
2
 
3
- 模板使用同一套 SDK:`@tau/plugins` 为 npm 别名 @xiongtao.xt/tau-plugins 0.47.0,`@tau/ui` 为 @xiongtao.xt/tau-ui 0.5.0。移动正式安装要求 Android/iOS 客户端至少 0.2.4;具体支持范围先看 [API 矩阵](api-support.md)。
3
+ 模板自带一个能直接运行的计数器插件。先把它构建出来、装进 Tau 跑通,再改成你自己的插件。
4
4
 
5
- ## 准备与构建
5
+ ## 准备环境
6
6
 
7
- 1. 安装 Node.js 22+ 与 pnpm 11.9.0,复制本版本模板到独立目录。
8
- 2. 安装已锁定的 npm 依赖并构建:
7
+ - Node.js 22 或更高版本。
8
+ - pnpm 11.9.0(`npm install -g pnpm@11.9.0`)。
9
+ - 在 GitHub 上用 [插件模板](https://github.com/LastKnightCoder/tau-plugin-template) 创建自己的仓库(「Use this template」),再克隆到本地。
10
+
11
+ ## 构建
9
12
 
10
13
  ```sh
11
14
  pnpm install --frozen-lockfile
12
15
  pnpm build
13
16
  ```
14
17
 
15
- 模板通过 npm 别名固定 SDK 0.47.0,并使用正式依赖与锁文件,直接执行上述冻结安装和构建命令。SDK 发布不代表插件或 APP 已发布;客户端要求以清单和支持矩阵为准。
18
+ 构建成功后,`dist/` 下会生成 `<插件ID>-<版本>.zip`,这就是要安装和发布的插件包。
16
19
 
17
- 3. 构建生成 `dist/<插件ID>-<版本>.zip`;再次安装可用 `pnpm install --frozen-lockfile`。
18
- 4. 在目标宿主验证后按发布指南上传待审;格式 3 普通提交人工审核,具审核权限的作者本人通过已绑定仓库 CI 发布可自动批准。移动用户从应用内中心安装,首次安装保存启用意图,重开应用生效;桌面 0.59.1 支持格式 3 中心安装,首次安装后需在已安装页启用并重启。install:local 不把格式 3 写进旧桌面正式目录。
20
+ `pnpm build` 会先做类型检查,再打包并校验 manifest。构建通过只说明代码能编译、包格式正确,功能是否正常要装进 Tau 里试。
19
21
 
20
- 仅调试未发布 SDK 时运行 `node use-local-sdk.mjs /path/to/plugins.tgz /path/to/ui.tgz` 切换到本地 file 依赖,并重新生成开发锁文件;恢复正式 npm 依赖后重建发布锁文件。不提交 .sdk、node_modules 或 dist,不用旧 tarball 冒充新版 npm 内容。
22
+ ## 模板里有什么
21
23
 
22
- ## 模板结构
24
+ | 文件 | 用途 |
25
+ | --------------------------------------- | --------------------------------------------------------------------------------- |
26
+ | `manifest.json` | 插件的身份、支持的平台和最低客户端版本,见[插件的组成](plugin-basics.md#manifest) |
27
+ | `src/index.tsx` | 插件入口:一个计数器页面、功能入口、设置和一条命令 |
28
+ | `src/styles.css`、`src/CounterIcon.tsx` | 样式和图标 |
29
+ | `examples/editor.tsx` | 一个最小的编辑器块示例,见[编辑器扩展](editor.md) |
30
+ | `build.mjs` | 构建脚本:类型检查、打包、校验 manifest、生成 ZIP |
31
+ | `README.md`、`CHANGELOG.md` | 写给使用者的说明和更新日志,会显示在插件详情页 |
32
+ | `AGENTS.md` | 给 AI 编程助手的项目指引 |
33
+ | `.github/workflows/release.yml` | 推送版本 tag 后自动发布,见[发布与更新](release.md) |
23
34
 
24
- | 文件 | 用途 |
25
- | ----------------------------------- | ------------------------------------------- |
26
- | manifest.json | 身份、平台、版本与能力声明 |
27
- | src/index.tsx | 共用计数器、页面、功能入口、通用设置/Dialog |
28
- | src/styles.css、src/CounterIcon.tsx | 样式和图标 |
29
- | build.mjs | 依赖检查、清单校验、暂存产物与 ZIP |
30
- | use-local-sdk.mjs | 准备未发布的 SDK/UI 输入 |
31
- | README.md | 给使用者的说明 |
35
+ 计数器点击「增加并保存」后把数字存进当前工作区,下次打开继续使用。它同时声明了桌面、Android 和 iOS 三个平台,是一个最小的多端插件。
32
36
 
33
- 计数按工作区保存。跨端页面注册与入口分离;设置与 Dialog 属于公共基础,直接使用。布局使用 CSS 容器查询;只有特殊交互才读取平台或输入,不解析 User-Agent。
37
+ ## 在 Tau 里调试
34
38
 
35
- ## 改成自己的插件
39
+ 正式版 Tau 只安装插件中心审核通过的插件。开发阶段要在**从源码运行的 Tau 开发版**里安装自己构建的 ZIP。
40
+
41
+ ### 桌面
42
+
43
+ 1. 克隆 [Tau 源码](https://github.com/LastKnightCoder/editor),在仓库根目录运行 `pnpm install`,再运行 `pnpm dev` 启动开发版。
44
+ 2. 打开侧边栏的「插件」,点右上角的「⋯」,选择「从 ZIP 安装…」,选中 `dist/` 下的 ZIP。
45
+ 3. 从 ZIP 安装的插件默认停用。在「已安装」里打开它的开关。
46
+ 4. 改完代码后重新 `pnpm build`,再用「从 ZIP 安装…」装一次即可覆盖旧版本。
47
+
48
+ 带[编辑器扩展](editor.md)或[白板扩展](whiteboard.md)的插件,安装、启停和更新后要完全退出并重新打开 Tau 才生效;只有页面、命令、设置的插件即时生效。
49
+
50
+ 开发版和正式版共用 `~/.editor` 下的数据。调试会读写真实的笔记库,建议先新建一个工作区专门用来测试。
36
51
 
37
- 1. 修改 manifest 的 id/name/description/version,package.json 版本保持一致。发布后插件 ID 不变。
38
- 2. 先逐项核对 [API 支持矩阵](api-support.md),再声明 targets、最低版本、必需/可选能力。移动 permissions 必须为空;没有 Node 不等于移动完整兼容。
39
- 3. 共用逻辑和模型,差异明显时拆视图,保持节点类型与字段一致。
40
- 4. 更新 README,构建后在目标宿主验收启用、保存、停用与恢复。
52
+ ### Android 与 iOS
41
53
 
42
- 契约见[跨端开发](portability.md),生命周期见[插件组成](plugin-basics.md)。仓库外构建只证明作者闭环,不替代宿主和真机验收。
54
+ 在 Tau 源码的 `apps/mobile` 下运行 `pnpm dev:android` 或 `pnpm dev:ios` 启动开发版。开发版的「我的 › 插件中心 › 已安装」底部有「受控开发安装」,粘贴一段包描述即可安装:
55
+
56
+ ```json
57
+ {
58
+ "id": "example.external-counter",
59
+ "version": "1.2.3",
60
+ "url": "http://127.0.0.1:8000/example.external-counter-1.2.3.zip",
61
+ "sha256": "<ZIP 的 SHA-256>",
62
+ "size": 12345
63
+ }
64
+ ```
65
+
66
+ - `url` 必须是 HTTPS,或者本机的 `http://127.0.0.1` / `localhost`。可以在 `dist/` 下运行 `python3 -m http.server 8000` 提供文件;Android 模拟器或真机先执行 `adb reverse tcp:8000 tcp:8000`。
67
+ - `sha256` 和 `size` 是 ZIP 的摘要和字节数,用 `shasum -a 256 <文件>` 和 `wc -c < <文件>` 得到。
68
+ - 开发安装的插件默认停用。在「已安装」里启用后,重新打开应用生效。
69
+
70
+ ## 改成自己的插件
43
71
 
44
- ## 开发语音识别插件
72
+ 1. 修改 `manifest.json` 的 `id`、`name`、`description` 和 `version`,并让 `package.json` 的 `version` 与它一致。插件 ID 一旦发布就不要再改,改了 ID 用户的数据就找不回来了。
73
+ 2. 读一遍[多端适配](portability.md),确认你要用的接口在哪些平台可用,再决定 `targets` 里保留哪些平台。比如用到了[用户数据](user-data.md),就只保留 `desktop`。
74
+ 3. 改写 `src/index.tsx`。各项能力的写法见[文档首页](README.md#我想)的对照表。
75
+ 4. 重写 `README.md`,写给第一次使用这个插件的用户:能做什么、怎么开始、常见问题。
76
+ 5. 构建并在 Tau 里验证:启用、使用每项功能、保存数据、停用、重启后再用。
45
77
 
46
- ASR 与标准 WebSocket 需要 SDK 0.43.0、桌面 0.59.5 或移动 0.2.7。模板使用 SDK 0.47.0;冻结安装和构建后再在目标宿主验证。接口见 [语音识别](providers/asr.md) 与 [WebSocket](websocket.md)。SDK 可安装不代表客户端已经发行,最低客户端版本与平台分发仍由插件清单控制。
78
+ 准备好之后,按[发布与更新](release.md)发布到插件中心。
package/docs/mcp.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MCP 工具
2
2
 
3
- 通过 `context.mcp.register`,你可以给 Tau 的 AI 助手提供工具。用户和 AI 对话时,AI 会按需调用这些工具,比如查询插件里的数据、在插件里执行操作。
3
+ 通过 `context.mcp.register`,你可以给 Tau 的 AI 助手提供工具(仅桌面)。用户和 AI 对话时,AI 会按需调用这些工具,比如查询插件里的数据、在插件里执行操作。
4
4
 
5
5
  注册的工具会出现在 Tau 的 MCP 页面和聊天的快捷面板里,用户可以整组或逐个开关工具。插件不需要自己做管理界面。
6
6
 
@@ -30,7 +30,9 @@ context.mcp.register({
30
30
  if (typeof args.key !== "string") throw new Error("请提供笔记的键");
31
31
  const note = await context.storage.get(args.key);
32
32
  signal.throwIfAborted();
33
- return { content: note === undefined ? "未找到笔记" : JSON.stringify(note) };
33
+ return {
34
+ content: note === undefined ? "未找到笔记" : JSON.stringify(note),
35
+ };
34
36
  },
35
37
  },
36
38
  ],
@@ -69,7 +71,10 @@ context.mcp.register({
69
71
  context.mcp.register({
70
72
  id: "remote",
71
73
  name: "知识服务",
72
- transport: { type: "streamable-http", url: "https://your-service.example/mcp" },
74
+ transport: {
75
+ type: "streamable-http",
76
+ url: "https://your-service.example/mcp",
77
+ },
73
78
  });
74
79
  ```
75
80
 
@@ -83,7 +88,9 @@ context.mcp.register({
83
88
  {
84
89
  "backend": {
85
90
  "systemAccess": ["process"],
86
- "tools": [{ "id": "mcp", "command": "node", "args": ["/path/to/your-server.mjs"] }]
91
+ "tools": [
92
+ { "id": "mcp", "command": "node", "args": ["/path/to/your-server.mjs"] }
93
+ ]
87
94
  }
88
95
  }
89
96
  ```
@@ -94,7 +101,11 @@ context.mcp.register({
94
101
  context.mcp.register({
95
102
  id: "local-server",
96
103
  name: "本地 MCP 服务",
97
- transport: { type: "stdio", command: "node", args: ["/path/to/your-server.mjs"] },
104
+ transport: {
105
+ type: "stdio",
106
+ command: "node",
107
+ args: ["/path/to/your-server.mjs"],
108
+ },
98
109
  });
99
110
  ```
100
111
 
@@ -143,7 +154,8 @@ await context.chat.registerToolRenderer({
143
154
  mcpId: "books",
144
155
  toolName: "search_books",
145
156
  component: ({ execution, data, dataVersion, renderDefault }) => {
146
- if (execution.status !== "success" || dataVersion !== 1) return renderDefault();
157
+ if (execution.status !== "success" || dataVersion !== 1)
158
+ return renderDefault();
147
159
  return <BookList books={(data as { books: Book[] }).books} />;
148
160
  },
149
161
  });