@xiongtao.xt/tau-plugins 0.60.0 → 0.62.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 (39) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/client/chunk-UGYIAPAN.js +869 -0
  3. package/docs/README.md +1 -0
  4. package/docs/backend.md +4 -10
  5. package/docs/blog-templates.md +7 -6
  6. package/docs/document-body.md +2 -0
  7. package/docs/getting-started.md +2 -14
  8. package/docs/plugin-basics.md +1 -1
  9. package/docs/portability.md +25 -2
  10. package/docs/skills.md +10 -12
  11. package/docs/task-data.md +389 -0
  12. package/docs/user-data.md +31 -24
  13. package/package.js +1 -1
  14. package/package.json +5 -1
  15. package/portable.js +3 -2
  16. package/publish-artifacts.js +36 -19
  17. package/types/packages/plugins/src/data-changes.d.ts +51 -0
  18. package/types/packages/plugins/src/data.d.ts +122 -7
  19. package/types/packages/plugins/src/errors.d.ts +7 -0
  20. package/types/packages/plugins/src/events.d.ts +17 -12
  21. package/types/packages/plugins/src/index.d.ts +2 -2
  22. package/types/packages/plugins/src/package.d.ts +7 -2
  23. package/types/packages/plugins/src/portable.d.ts +5 -2
  24. package/types/packages/plugins/src/skills.d.ts +16 -0
  25. package/types/packages/plugins/src/template.d.ts +101 -0
  26. package/types/packages/plugins/src/unified.d.ts +60 -0
  27. package/types/packages/plugins/src/version.d.ts +5 -0
  28. package/types/packages/shared/src/task-assistant/contracts.d.ts +15 -0
  29. package/types/packages/shared/src/task-assistant/directories.d.ts +15 -0
  30. package/types/packages/shared/src/task-assistant/directory-colors.d.ts +2 -0
  31. package/types/packages/shared/src/task-assistant/occurrence-state.d.ts +7 -0
  32. package/types/packages/shared/src/task-assistant/schema.d.ts +3 -0
  33. package/types/packages/shared/task-assistant.d.ts +2 -0
  34. package/types/packages/ui/src/hooks/useEdgeFade.d.ts +1 -1
  35. package/types/packages/ui/src/primitives/AnchoredPanel.d.ts +3 -1
  36. package/types/packages/ui/src/primitives/anchoredPosition.d.ts +8 -0
  37. package/unified.js +21 -0
  38. package/client/chunk-6XAEU7BJ.js +0 -330
  39. package/client/chunk-PRE35AOA.js +0 -185
package/docs/user-data.md CHANGED
@@ -139,25 +139,16 @@ const chats = await context.data.chats.query({ updatedAfter: weekAgo });
139
139
 
140
140
  ### 待办与日程
141
141
 
142
+ `context.data.todos` 读取普通待办、重复系列和正文里的勾选项,`context.data.calendar` 读取日程。两者都提供 get 和分页 query;目录、提醒、重复规则、实例状态及备注的完整用法见[待办与日程](task-data.md)。
143
+
142
144
  ```ts
143
145
  const todos = await context.data.todos.query({ completed: false, limit: 20 });
144
- const events = await context.data.calendar.query({ start: "2026-10-19", end: "2026-10-26" });
146
+ const events = await context.data.calendar.query({ start: "2026-12-01", end: "2026-12-07" });
145
147
  ```
146
148
 
147
- `todos.query` 的参数:
148
-
149
- | 参数 | 说明 |
150
- | ----------------- | ----------------------------------------------------------------------------------------------- |
151
- | `view` | `tasks`(默认)返回待办与周期系列;`occurrences` 返回周期待办的每一次,必须同时给 `start`、`end` |
152
- | `source` | `all`(默认)、`todo`(独立的待办)、`document`(正文里的勾选项) |
153
- | `completed` | 按完成状态筛选 |
154
- | `keyword` | 按关键词筛选 |
155
- | `start`、`end` | 按截止日期筛选,格式 `YYYY-MM-DD` |
156
- | `limit`、`cursor` | 分页,每页最多 100 条,默认 50 |
149
+ ### 按游标读取变化
157
150
 
158
- - 来自正文勾选项的待办带有 `source`,指明它在哪篇卡片、文章、项目文档或日记里。用户在 Tau 里把勾选项排除出待办、或提升为独立待办后,它不再作为正文待办返回;对正文待办的修改会回到原文的那一行,不会另建一条独立待办。
159
- - 周期待办用 `view: "occurrences"` 查询时,返回的每一项是某一天的那一次,`id` 固定对应那一天,改期后也不变,不要解析或自己拼接它。对这一次可以标记完成、改期(`dueAt: null` 取消改期)和删除(即跳过这一次),都只影响这一次,不会改动整个系列。标题跟随系列,要改标题用 `view: "tasks"` 返回的系列 ID。周期规则本身由用户在 Tau 中设置,插件不能创建或修改。
160
- - `calendar.query` 的 `start`、`end` 必填,可以是 `YYYY-MM-DD` 或带时区的 ISO 时间,每页最多 100 条。由待办安排出的日程带 `todoId`。
151
+ 需要离线续读或发现删除时,使用 `context.data.changes.query`。处理成功后再保存游标,完整流程和失败处理见[待办与日程 · 按游标读取变化](task-data.md#按游标读取变化)。
161
152
 
162
153
  ## 修改与删除
163
154
 
@@ -185,9 +176,9 @@ try {
185
176
  | `documents.move(id, { projectId, from, to, index }, ...)` | 在同一项目内移动,见[项目目录](#项目目录) |
186
177
  | `whiteboards.create` / `whiteboards.update` | `title`(新建时必填)、`description`、`tags`;新建的白板带一张空白画板页 |
187
178
  | `projects.create` / `projects.update` | 新建:`title`(必填),得到空项目;修改:`title`、`archived`、`pinned` |
188
- | `todos.create` / `todos.update` | `title`、`dueAt`(`YYYY-MM-DD`、带时区的 ISO 时间或 `null`) |
179
+ | `todos.create` / `todos.update` | 标题、截止日期、待办项目与提醒,见[待办与日程](task-data.md#创建带提醒的待办) |
189
180
  | `todos.setCompleted(id, completed, ...)` | 标记完成或未完成 |
190
- | `calendar.create` / `calendar.update` | `title`、`start`、`end`、`allDay`、`calendarId`(省略时为默认日历) |
181
+ | `calendar.create` / `calendar.update` | 时段、日历、提醒与备注,见[安排日程与编辑备注](task-data.md#安排日程与编辑备注) |
191
182
  | `*.delete(id, ...)` | 删除卡片、文章、白板、项目、项目文档、待办、日程,限制见下 |
192
183
 
193
184
  - `content` 是新建时的正文,写法见[正文输入](document-body.md#正文输入);修改已有正文用 [`context.content.edit`](document-body.md#修改)。
@@ -195,11 +186,15 @@ try {
195
186
  - 有截止日期的待办会在日历里显示为一条日程。这类日程只能通过待办接口修改:`calendar.update` 不能改它的标题,也不能把它移到别的日历。
196
187
  - 全天日程的 `start`、`end` 用 `YYYY-MM-DD`,且 `end` 不包含当天:一个只占 10 月 21 日的全天日程,`end` 是 `2026-10-22`。定时日程用带时区的 ISO 时间。
197
188
 
189
+ ### 待办项目、日历与完整字段
190
+
191
+ 待办项目、日历发现、提醒、重复与实例、日程备注以及创建请求重试,见[待办与日程](task-data.md)。
192
+
198
193
  ### 用 revision 避免覆盖别人的修改
199
194
 
200
195
  每一项数据都带有 `revision`。修改和删除时必须把读到的 `revision` 作为 `expectedRevision` 传回。如果这期间用户或其他插件改过这一项,调用会抛出 `PluginConflictError`,而不是悄悄覆盖。遇到冲突时重新读取,再决定是否重试。修改返回的新对象带有新的 `revision`,连续修改时用它。
201
196
 
202
- 修改正文不会改变实体的 `revision`,正文有自己的版本,见[正文](document-body.md#修改)。
197
+ 卡片、文章和项目文档的正文有独立版本,修改正文不改变它们的元数据 revision,见[正文](document-body.md#修改)。日程的聚合 revision 还覆盖备注正文和完整提醒列表;版本只用于比较相等,不能按大小或时间戳选择覆盖哪一方。
203
198
 
204
199
  ### 写入后
205
200
 
@@ -215,11 +210,18 @@ try {
215
210
  回顾页面开着时,用户在别处改了卡片或待办,页面应该跟着刷新:
216
211
 
217
212
  ```ts
218
- context.events.on(["card.created", "card.updated", "card.deleted", "todos.changed"], () => {
219
- void loadWeek().then(render);
220
- });
213
+ import type { PluginContext } from "@tau/plugins";
214
+
215
+ function watchReviewLists(context: PluginContext, refresh: (id: string) => void) {
216
+ return context.events.on(
217
+ ["todo-list.created", "todo-list.updated", "todo-list.deleted"],
218
+ event => refresh(event.id),
219
+ );
220
+ }
221
221
  ```
222
222
 
223
+ 所有业务对象使用同一套 created / updated / deleted 事件,回调带稳定字符串 id,与相应 get 使用的 ID 一致。 type 区分对象和动作,at 是通知送出时间,不能作为修改版本;名称、颜色等当前值通过 get 读取。订阅时写完整事件名,不传 `*`。返回句柄的 dispose() 可取消订阅。
224
+
223
225
  | 事件 | 说明 |
224
226
  | ---------------------------------------------- | ---------------------------------------------------------------------------- |
225
227
  | `card.created`、`card.updated`、`card.deleted` | 带 `id`。正文修改也算 `updated` |
@@ -229,14 +231,19 @@ context.events.on(["card.created", "card.updated", "card.deleted", "todos.change
229
231
  | `material.*`、`chat.*` | 同上。划线删除算 `deleted`;对话收到新消息也算 `updated` |
230
232
  | `entity.*` | 本插件的内容,带 `id` 和 `kind`,见[插件内容](plugin-content.md#插件内容) |
231
233
  | `record.*` | 本插件的记录,带 `id` 和 `collection`,见[插件记录](plugin-content.md#插件记录) |
232
- | `todos.changed`、`calendar.changed` | 待办、日程有变化,不带 `id`,需要时重新查询 |
234
+ | `todo.*` | 待办变化,带 todos.get 使用的 ID;重复任务实例变化通知系列根对象 |
235
+ | `event.*` | 真实日程变化,带 calendar.get 使用的 ID,不展开虚拟任务标记 |
236
+ | `todo-list.*` | 待办项目创建、改名、颜色或其他元数据变化,带 todoLists.get 使用的 ID |
237
+ | `calendar.*` | 日历目录变化,带 calendars.get 使用的 ID |
233
238
  | `workspace.reset` | 资料库被整个替换(例如从云端恢复),应全部重新读取 |
234
239
 
235
- - 事件只说明哪一项变了,不携带数据,需要时用 `context.data` 重新读取。
236
- - `origin` 表示变化的来源:`{ kind: "plugin", pluginId }` 表示由插件写入,可以用它忽略自己写入引起的事件;其他情况是 `{ kind: "app" }`。待办与日程的事件总是 `app`。
237
- - 同一项在短时间内的多次变化会合并成一次;用户持续输入时,最多每 2 秒一次。
240
+ - 事件在提交后送出,回滚的修改不送出。通知只说明哪一项变了,不携带完整数据或旧值,需要时用 `context.data` 重新读取;读取时可能已有更新、恢复或权限变化。
241
+ - `origin` 表示变化的来源:`{ kind: "plugin", pluginId }` 表示由插件写入,可以用它忽略自己写入引起的事件;其他情况是 `{ kind: "app" }`。待办、日程及两类目录事件不提供精确写入方,总是 `app`,应比较已处理状态避免循环。
242
+ - 通知可能延迟、合并或重复;批量变化仍保留各个对象身份,不是逐次操作审计。workspace.reset 是资料库级例外,不携带对象 ID;它也用于提示事件历史已经不足。
243
+ - 事件不承担离线历史。需要可靠同步时,启动、恢复前台和收到通知后使用[按游标读取变化](task-data.md#按游标读取变化)补读;这是数据查询接口,订阅仍只使用 context.events.on。
238
244
  - 接收事件需要对应的读取权限(`entity.*`、`record.*` 与 `workspace.reset` 除外)。还没获得授权时事件不会送达,也不会因此弹窗。
239
245
  - `entity.created`、`entity.updated`、`entity.deleted` 只发给创建这项内容的插件,不需要权限。正文修改也算 `updated`;`kind` 是内容类型,删除后 `get` 读不到时可以据此判断是哪类内容。从「最近删除」恢复、卸载后重新安装找回,都算 `created`。适合在其他设备同步过来或 AI 通过 MCP 写入后刷新页面。
246
+ - 同一订阅按顺序处理回调,可以使用异步函数;回调失败不会阻断后续通知。耗时同步适合由回调唤醒自己的任务队列。
240
247
  - 订阅在插件停用时自动注销。
241
248
 
242
249
  要读改正文或在页面里嵌入编辑器,接着读[正文](document-body.md)。
package/package.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  isPluginPermission,
13
13
  validateBackendManifest,
14
14
  validatePluginManifest
15
- } from "./client/chunk-6XAEU7BJ.js";
15
+ } from "./client/chunk-UGYIAPAN.js";
16
16
  import "./client/chunk-UTVEXGFI.js";
17
17
  export {
18
18
  PLUGIN_AI_CAPABILITIES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.60.0",
3
+ "version": "0.62.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,6 +26,10 @@
26
26
  "types": "./types/packages/plugins/src/portable.d.ts",
27
27
  "default": "./portable.js"
28
28
  },
29
+ "./unified": {
30
+ "types": "./types/packages/plugins/src/unified.d.ts",
31
+ "default": "./unified.js"
32
+ },
29
33
  "./backend": {
30
34
  "types": "./types/packages/plugins/src/backend.d.ts",
31
35
  "default": "./runtime.js"
package/portable.js CHANGED
@@ -7,12 +7,12 @@ import {
7
7
  MOBILE_SPEECH_PERMISSIONS,
8
8
  PORTABLE_PLATFORMS,
9
9
  PORTABLE_SHARED_MODULES,
10
+ assertMobilePermissions,
10
11
  assertPortablePluginCompatibility,
11
12
  buildPortablePluginManifest,
12
13
  validatePortableDistributionManifest,
13
14
  validatePortablePluginManifest
14
- } from "./client/chunk-PRE35AOA.js";
15
- import "./client/chunk-6XAEU7BJ.js";
15
+ } from "./client/chunk-UGYIAPAN.js";
16
16
  import "./client/chunk-UTVEXGFI.js";
17
17
  export {
18
18
  MOBILE_AI_MIN_VERSION,
@@ -23,6 +23,7 @@ export {
23
23
  MOBILE_SPEECH_PERMISSIONS,
24
24
  PORTABLE_PLATFORMS,
25
25
  PORTABLE_SHARED_MODULES,
26
+ assertMobilePermissions,
26
27
  assertPortablePluginCompatibility,
27
28
  buildPortablePluginManifest,
28
29
  validatePortableDistributionManifest,
@@ -1,11 +1,9 @@
1
- import {
2
- PORTABLE_SHARED_MODULES,
3
- validatePortablePluginManifest
4
- } from "./client/chunk-PRE35AOA.js";
5
1
  import {
6
2
  PLUGIN_SHARED_MODULES,
7
- validatePluginManifest
8
- } from "./client/chunk-6XAEU7BJ.js";
3
+ PORTABLE_SHARED_MODULES,
4
+ isWebPluginManifest,
5
+ readApplicationPluginManifest
6
+ } from "./client/chunk-UGYIAPAN.js";
9
7
  import {
10
8
  __commonJS,
11
9
  __toESM
@@ -5395,7 +5393,7 @@ function useScrollState(el) {
5395
5393
  const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measureOnRaf);
5396
5394
  resizeObserver?.observe(el);
5397
5395
  const mutationObserver = typeof MutationObserver === "undefined" ? null : new MutationObserver(measureOnRaf);
5398
- mutationObserver?.observe(el, { childList: true, subtree: true });
5396
+ mutationObserver?.observe(el, { childList: true, subtree: true, characterData: true });
5399
5397
  return () => {
5400
5398
  cancelAnimationFrame(rafId);
5401
5399
  el.removeEventListener("scroll", measureSync);
@@ -7090,6 +7088,16 @@ var VIEWPORT_PAD = 8;
7090
7088
  var ARROW_MARGIN = 10;
7091
7089
  var ARROW_SIZE = 8;
7092
7090
  var ARROW_TIP_OFFSET = 5;
7091
+ function fitVerticalPreview(anchor, placement, viewportHeight, gap = 8) {
7092
+ if (!placement.startsWith("top") && !placement.startsWith("bottom")) return;
7093
+ const above = anchor.top - VIEWPORT_PAD - gap;
7094
+ const below = viewportHeight - VIEWPORT_PAD - gap - anchor.bottom;
7095
+ const side = above === below ? placement.split("-")[0] : above > below ? "top" : "bottom";
7096
+ return {
7097
+ placement: placement.replace(/^(top|bottom)/, side),
7098
+ maxHeight: Math.max(0, Math.floor(Math.max(above, below)))
7099
+ };
7100
+ }
7093
7101
  function computeAnchoredPosition(anchor, pop, placement, opts) {
7094
7102
  const GAP2 = opts?.gap ?? 8;
7095
7103
  const [side0, align = "center"] = placement.split("-");
@@ -7204,6 +7212,7 @@ function useAnchoredPosition({
7204
7212
  popRef,
7205
7213
  placement,
7206
7214
  gap,
7215
+ fitVerticalSpace = false,
7207
7216
  pollAnchor = false,
7208
7217
  onPlace
7209
7218
  }) {
@@ -7215,13 +7224,16 @@ function useAnchoredPosition({
7215
7224
  if (!open) return;
7216
7225
  const pop = popRef.current;
7217
7226
  if (!pop) return;
7227
+ const originalMaxHeight = pop.style.maxHeight;
7218
7228
  const place = () => {
7219
7229
  const anchor = getAnchorRef.current();
7220
7230
  if (!anchor) return;
7231
+ const fit = fitVerticalSpace && fitVerticalPreview(anchor, placement, window.innerHeight, gap);
7232
+ if (fit) pop.style.maxHeight = `${fit.maxHeight}px`;
7221
7233
  const pos = computeAnchoredPosition(
7222
7234
  anchor,
7223
7235
  pop,
7224
- placement,
7236
+ fit ? fit.placement : placement,
7225
7237
  gap !== void 0 ? { gap } : void 0
7226
7238
  );
7227
7239
  pop.style.left = `${pos.x}px`;
@@ -7230,12 +7242,11 @@ function useAnchoredPosition({
7230
7242
  };
7231
7243
  place();
7232
7244
  place();
7233
- let queued = false;
7245
+ let frame = 0;
7234
7246
  const schedule = () => {
7235
- if (queued) return;
7236
- queued = true;
7237
- requestAnimationFrame(() => {
7238
- queued = false;
7247
+ if (frame) return;
7248
+ frame = requestAnimationFrame(() => {
7249
+ frame = 0;
7239
7250
  place();
7240
7251
  });
7241
7252
  };
@@ -7261,9 +7272,11 @@ function useAnchoredPosition({
7261
7272
  window.removeEventListener("scroll", schedule, true);
7262
7273
  window.removeEventListener("resize", schedule);
7263
7274
  ro?.disconnect();
7275
+ cancelAnimationFrame(frame);
7276
+ if (fitVerticalSpace) pop.style.maxHeight = originalMaxHeight;
7264
7277
  cancelAnimationFrame(raf);
7265
7278
  };
7266
- }, [open, placement, gap, pollAnchor]);
7279
+ }, [open, placement, gap, pollAnchor, fitVerticalSpace]);
7267
7280
  }
7268
7281
 
7269
7282
  // packages/ui/src/primitives/Tooltip.tsx
@@ -7601,6 +7614,7 @@ function MenuSurface({
7601
7614
  "aria-activedescendant": nav.current ?? void 0,
7602
7615
  "data-open": open,
7603
7616
  onKeyDown,
7617
+ onClick: (e2) => e2.stopPropagation(),
7604
7618
  className: cn(
7605
7619
  "bg-surface border-line-1 shadow-float rounded-tau-lg border p-[6px]",
7606
7620
  "fixed left-0 top-0 z-[250] flex w-max min-w-[160px] max-w-[min(320px,calc(100vw-16px))] flex-col overflow-hidden",
@@ -7956,6 +7970,7 @@ var PanelHasHeaderContext = (0, import_react32.createContext)(null);
7956
7970
  function AnchoredPanel({
7957
7971
  anchor,
7958
7972
  placement = "bottom-start",
7973
+ fitVerticalSpace = false,
7959
7974
  open,
7960
7975
  arrow = false,
7961
7976
  className,
@@ -7971,6 +7986,7 @@ function AnchoredPanel({
7971
7986
  getAnchor: () => anchor?.getBoundingClientRect() ?? null,
7972
7987
  popRef,
7973
7988
  placement,
7989
+ fitVerticalSpace,
7974
7990
  onPlace: (pos, pop) => {
7975
7991
  pop.dataset.side = pos.side;
7976
7992
  if (arrow) applyArrowPosition(pos, pop);
@@ -7993,6 +8009,7 @@ function AnchoredPanel({
7993
8009
  !visible && "data-[side=top]:-translate-y-[4px]",
7994
8010
  !visible && "data-[side=left]:-translate-x-[4px]",
7995
8011
  !visible && "data-[side=right]:translate-x-[4px]",
8012
+ fitVerticalSpace && "overflow-y-auto",
7996
8013
  className
7997
8014
  ),
7998
8015
  children: [
@@ -9412,11 +9429,11 @@ function normalizePluginEditorExtension(extension) {
9412
9429
  // packages/plugins/src/rendering.ts
9413
9430
  var PLUGIN_RENDER_VERSION = 1;
9414
9431
  function readPublishedPluginManifest(value) {
9415
- return value?.formatVersion === 3 ? validatePortablePluginManifest(value) : validatePluginManifest(value);
9432
+ return readApplicationPluginManifest(value);
9416
9433
  }
9417
9434
  function evaluatePublishedPluginPackage(artifact, modules) {
9418
9435
  const manifest = readPublishedPluginManifest(artifact.manifest);
9419
- if (manifest.formatVersion !== 3)
9436
+ if (!isWebPluginManifest(manifest))
9420
9437
  return evaluatePluginPackage({ ...artifact, manifest }, modules);
9421
9438
  if (!manifest.targets.desktop) throw new Error("\u535A\u5BA2\u6E32\u67D3\u9700\u8981\u684C\u9762\u76EE\u6807");
9422
9439
  const definition = evaluateModule(manifest, artifact.code, modules, PORTABLE_SHARED_MODULES);
@@ -9428,7 +9445,7 @@ function evaluatePluginPackage(artifact, modules) {
9428
9445
  manifest,
9429
9446
  artifact.code,
9430
9447
  modules,
9431
- manifest.formatVersion === 3 ? PORTABLE_SHARED_MODULES : PLUGIN_SHARED_MODULES
9448
+ isWebPluginManifest(manifest) ? PORTABLE_SHARED_MODULES : PLUGIN_SHARED_MODULES
9432
9449
  );
9433
9450
  }
9434
9451
  function evaluateModule(manifest, code, modules, allowed) {
@@ -9453,9 +9470,9 @@ function evaluateModule(manifest, code, modules, allowed) {
9453
9470
  function validatePluginDefinition(manifest, definition) {
9454
9471
  if (!definition || typeof definition.create !== "function" || definition.id !== manifest.id || definition.name !== manifest.name || definition.version !== manifest.version || definition.apiVersion !== manifest.apiVersion)
9455
9472
  throw new Error("\u63D2\u4EF6\u5165\u53E3\u5B9A\u4E49\u4E0E\u6E05\u5355\u4E0D\u4E00\u81F4");
9456
- if (manifest.formatVersion !== 3 && Boolean(definition.editorExtensions?.length) !== Boolean(manifest.editor))
9473
+ if (manifest.formatVersion === 2 && Boolean(definition.editorExtensions?.length) !== Boolean(manifest.editor))
9457
9474
  throw new Error("\u7F16\u8F91\u5668\u8D21\u732E\u5FC5\u987B\u4E0E manifest.editor \u58F0\u660E\u4E00\u81F4");
9458
- if (manifest.formatVersion !== 3 && Boolean(definition.whiteboardExtensions?.length) !== Boolean(manifest.whiteboard))
9475
+ if (manifest.formatVersion === 2 && Boolean(definition.whiteboardExtensions?.length) !== Boolean(manifest.whiteboard))
9459
9476
  throw new Error("\u767D\u677F\u8D21\u732E\u5FC5\u987B\u4E0E manifest.whiteboard \u58F0\u660E\u4E00\u81F4");
9460
9477
  definition = {
9461
9478
  ...definition,
@@ -0,0 +1,51 @@
1
+ export declare const DATA_CHANGE_DOMAINS: readonly ["todo", "todo-list", "event", "calendar"];
2
+ export type PluginChangeDomain = (typeof DATA_CHANGE_DOMAINS)[number];
3
+ export interface PluginChangesQuery {
4
+ domains: PluginChangeDomain[];
5
+ /** 缺省只读独立待办;all 包含正文待办。 */
6
+ todoSource?: "todo" | "document" | "all";
7
+ cursor?: string;
8
+ limit?: number;
9
+ }
10
+ export interface PluginDataChange {
11
+ domain: PluginChangeDomain;
12
+ id: string;
13
+ operation: "upsert" | "delete";
14
+ }
15
+ export interface PluginChangesPage {
16
+ mode: "snapshot" | "changes";
17
+ items: PluginDataChange[];
18
+ cursor: string;
19
+ hasMore: boolean;
20
+ /** 只在本轮完整结束时提供;插件处理成功后才能保存。 */
21
+ checkpoint?: string;
22
+ }
23
+ /** 宿主数据层原语;每次调用在一个短事务内返回水位与分页结果。 */
24
+ export interface DataChangesReadRequest {
25
+ todoSource?: "todo" | "document" | "all";
26
+ phase: "snapshot" | "changes";
27
+ domains: PluginChangeDomain[];
28
+ afterDomain: string;
29
+ afterKey: number;
30
+ afterSeq: number;
31
+ through?: number;
32
+ limit: number;
33
+ }
34
+ export interface DataChangesReadPage {
35
+ todoSource?: "todo" | "document" | "all";
36
+ scope: string;
37
+ protocol: number;
38
+ head: number;
39
+ floor: number;
40
+ through: number;
41
+ items: (PluginDataChange & {
42
+ key?: number;
43
+ seq?: number;
44
+ })[];
45
+ hasMore: boolean;
46
+ }
47
+ export declare function normalizeChangesQuery(query: PluginChangesQuery): PluginChangesQuery & {
48
+ limit: number;
49
+ };
50
+ /** 两端共用状态机;SQL、连接、清理和本机代次由各自数据层负责。 */
51
+ export declare function queryDataChanges(query: PluginChangesQuery, ownerBinding: string, read: (request: DataChangesReadRequest) => Promise<DataChangesReadPage>): Promise<PluginChangesPage>;
@@ -1,8 +1,11 @@
1
+ import type { PluginChangesQuery, PluginChangesPage } from "./data-changes";
2
+ export type { PluginChangesQuery, PluginChangesPage, PluginDataChange, PluginChangeDomain, } from "./data-changes";
1
3
  /**
2
4
  * 业务数据接口。ID 与 ContentRef 都是不透明字符串:只用于传回宿主,不要解析其格式。
3
5
  * 每次调用前宿主按 manifest.permissions 与用户授权校验,未获准抛出 PluginPermissionError。
4
6
  * 修改与删除要传读到的 revision,数据已被别处修改时抛出 PluginConflictError。
5
7
  */
8
+ import type { TaskRecurrenceRule, TaskRecurrenceSegment, TaskOccurrenceState } from "../../shared/task-assistant";
6
9
  import type { Descendant } from "slate";
7
10
  import type { PluginContentInput } from "./content-input";
8
11
  import type { PluginEntityRef } from "./app";
@@ -223,12 +226,72 @@ export interface PluginEntityWriter<T, Input, Patch> extends PluginEntityReader<
223
226
  update(id: string, patch: Patch, options: PluginWriteOptions): Promise<T>;
224
227
  delete(id: string, options: PluginWriteOptions): Promise<void>;
225
228
  }
229
+ export interface PluginCreateOptions {
230
+ /** 同一插件内稳定的创建请求 ID;重试复用,同 ID 不得更换参数。 */
231
+ requestId?: string;
232
+ }
233
+ export interface PluginDirectoryQuery {
234
+ archived?: boolean;
235
+ limit?: number;
236
+ cursor?: string;
237
+ }
238
+ export type { DirectoryColor as PluginDirectoryColor, TodoListInput as PluginTodoListInput, TodoListPatch as PluginTodoListPatch, CalendarDirectoryInput as PluginCalendarDirectoryInput, CalendarDirectoryPatch as PluginCalendarDirectoryPatch, } from "../../shared/task-assistant";
239
+ import type { TodoListInput, TodoListPatch, CalendarDirectoryInput, CalendarDirectoryPatch } from "../../shared/task-assistant";
240
+ export interface PluginTodoList {
241
+ /** 旧宿主不提供时表示尚不能判断目录编辑资格。 */
242
+ editable?: boolean;
243
+ editReadonlyReason?: string;
244
+ color?: string | null;
245
+ id: string;
246
+ revision: string;
247
+ title: string;
248
+ archived: boolean;
249
+ writable: boolean;
250
+ readonlyReason?: string;
251
+ }
252
+ export interface PluginCalendar extends PluginTodoList {
253
+ color: string;
254
+ visible: boolean;
255
+ }
256
+ export interface PluginReminder {
257
+ /** 基准时刻减提醒时刻,单位毫秒;全天日程的基准为当天零点。 */
258
+ offsetMs: number;
259
+ }
260
+ export type PluginTodoReminder = PluginReminder | {
261
+ at: string;
262
+ };
263
+ export interface PluginTodoRecurrenceChange {
264
+ effectiveFrom: string;
265
+ rule: TaskRecurrenceRule | null;
266
+ }
267
+ export interface PluginTodoOccurrencePatch {
268
+ completed?: boolean;
269
+ skipped?: boolean;
270
+ scheduledAt?: string | null;
271
+ }
272
+ export interface PluginTodoOccurrenceQuery {
273
+ taskId: string;
274
+ limit?: number;
275
+ cursor?: string;
276
+ }
277
+ export interface PluginTodoOccurrenceState {
278
+ taskId: string;
279
+ seriesId: string;
280
+ originalDate: string;
281
+ state: TaskOccurrenceState;
282
+ active: boolean;
283
+ }
284
+ export type PluginTodoOccurrencePage = PluginPage<PluginTodoOccurrenceState> & {
285
+ taskRevision: string;
286
+ };
226
287
  export interface PluginTodoQuery {
227
288
  /** tasks 返回系列/普通任务;occurrences 返回原始日期标识的周期实例,须给 start/end。 */
228
289
  view?: "tasks" | "occurrences";
229
290
  /** 缺省为全部:独立待办与正文里的勾选项 */
230
291
  source?: "all" | "todo" | "document";
231
292
  completed?: boolean;
293
+ archived?: boolean;
294
+ listId?: string;
232
295
  keyword?: string;
233
296
  /** YYYY-MM-DD,按截止日期筛选 */
234
297
  start?: string;
@@ -238,6 +301,20 @@ export interface PluginTodoQuery {
238
301
  cursor?: string;
239
302
  }
240
303
  export interface PluginTodo {
304
+ listId: string | null;
305
+ /** null 表示此来源尚未开放提醒列表;空数组才表示没有提醒。 */
306
+ reminders: PluginTodoReminder[] | null;
307
+ recurrence: {
308
+ segments: TaskRecurrenceSegment[];
309
+ } | null;
310
+ occurrence?: {
311
+ taskId: string;
312
+ seriesId: string;
313
+ originalDate: string;
314
+ state: TaskOccurrenceState;
315
+ };
316
+ writable: boolean;
317
+ readonlyReason?: string;
241
318
  id: string;
242
319
  revision: string;
243
320
  title: string;
@@ -253,14 +330,22 @@ export interface PluginTodo {
253
330
  };
254
331
  }
255
332
  export interface PluginCalendarQuery {
256
- /** YYYY-MM-DD 或带时区的 ISO 时间,必填 */
257
- start: string;
258
- end: string;
333
+ /** YYYY-MM-DD 或带时区的 ISO 时间;display 查询必填,stored 可省略。 */
334
+ start?: string;
335
+ end?: string;
336
+ /** display(默认)须给时间窗口;stored 只列真实持久日程,可不提供窗口。 */
337
+ view?: "display" | "stored";
338
+ calendarIds?: string[];
259
339
  /** 1–100,默认 50 */
260
340
  limit?: number;
261
341
  cursor?: string;
262
342
  }
263
343
  export interface PluginCalendarEvent {
344
+ reminders: PluginReminder[];
345
+ notesRef: PluginContentRef | null;
346
+ kind: "event" | "todo-schedule" | "virtual";
347
+ writable: boolean;
348
+ readonlyReason?: string;
264
349
  id: string;
265
350
  revision: string;
266
351
  title: string;
@@ -272,15 +357,22 @@ export interface PluginCalendarEvent {
272
357
  todoId?: string;
273
358
  }
274
359
  export interface PluginTodoInput {
360
+ recurrence?: TaskRecurrenceRule;
361
+ listId?: string;
362
+ reminders?: PluginTodoReminder[];
275
363
  title: string;
276
364
  /** YYYY-MM-DD 或带时区的 ISO 时间 */
277
365
  dueAt?: string | null;
278
366
  }
279
367
  export interface PluginTodoPatch {
368
+ listId?: string;
369
+ reminders?: PluginTodoReminder[];
280
370
  title?: string;
281
371
  dueAt?: string | null;
282
372
  }
283
373
  export interface PluginCalendarInput {
374
+ notes?: PluginContentInput;
375
+ reminders?: PluginReminder[];
284
376
  title: string;
285
377
  /** 全天日程用 YYYY-MM-DD,结束日期不含当天(当天全天的 end 为次日);定时日程用带时区的 ISO 时间 */
286
378
  start: string;
@@ -289,8 +381,11 @@ export interface PluginCalendarInput {
289
381
  /** 缺省为默认日历 */
290
382
  calendarId?: string;
291
383
  }
292
- export type PluginCalendarPatch = Partial<PluginCalendarInput>;
384
+ export type PluginCalendarPatch = Partial<Omit<PluginCalendarInput, "notes">>;
293
385
  export interface PluginData {
386
+ readonly changes: {
387
+ query(query: PluginChangesQuery): Promise<PluginChangesPage>;
388
+ };
294
389
  readonly cards: PluginEntityWriter<PluginCard, PluginCardInput, PluginCardPatch>;
295
390
  readonly articles: PluginEntityWriter<PluginArticle, PluginArticleInput, PluginArticlePatch>;
296
391
  /** 白板的信息;画板内容不开放读写,用户在 Tau 中编辑 */
@@ -328,17 +423,38 @@ export interface PluginData {
328
423
  readonly materials: PluginEntityReader<PluginMaterial>;
329
424
  /** AI 对话的信息,不含消息内容;query 不支持 tag */
330
425
  readonly chats: PluginEntityReader<PluginChatSession>;
426
+ readonly todoLists: {
427
+ create(input: TodoListInput, options?: PluginCreateOptions): Promise<PluginTodoList>;
428
+ update(id: string, patch: TodoListPatch, options: PluginWriteOptions): Promise<PluginTodoList>;
429
+ get(id: string): Promise<PluginTodoList | null>;
430
+ query(query?: PluginDirectoryQuery): Promise<PluginPage<PluginTodoList>>;
431
+ };
432
+ readonly calendars: {
433
+ create(input: CalendarDirectoryInput, options?: PluginCreateOptions): Promise<PluginCalendar>;
434
+ update(id: string, patch: CalendarDirectoryPatch, options: PluginWriteOptions): Promise<PluginCalendar>;
435
+ get(id: string): Promise<PluginCalendar | null>;
436
+ query(query?: PluginDirectoryQuery): Promise<PluginPage<PluginCalendar>>;
437
+ };
331
438
  readonly todos: {
439
+ setRecurrence(id: string, change: PluginTodoRecurrenceChange, options: PluginWriteOptions): Promise<PluginTodo>;
440
+ setOccurrenceState(id: string, patch: PluginTodoOccurrencePatch, options: PluginWriteOptions): Promise<PluginTodo>;
441
+ readonly occurrenceStates: {
442
+ query(query: PluginTodoOccurrenceQuery): Promise<PluginTodoOccurrencePage>;
443
+ };
444
+ get(id: string): Promise<PluginTodo | null>;
332
445
  query(query?: PluginTodoQuery): Promise<PluginPage<PluginTodo>>;
333
- create(input: PluginTodoInput): Promise<PluginTodo>;
446
+ create(input: PluginTodoInput, options?: PluginCreateOptions): Promise<PluginTodo>;
334
447
  update(id: string, patch: PluginTodoPatch, options: PluginWriteOptions): Promise<PluginTodo>;
335
448
  setCompleted(id: string, completed: boolean, options: PluginWriteOptions): Promise<PluginTodo>;
336
449
  /** 有子待办时拒绝删除 */
337
450
  delete(id: string, options: PluginWriteOptions): Promise<void>;
338
451
  };
339
452
  readonly calendar: {
453
+ /** 为尚无备注的日程建立空正文;已有备注保持原样。 */
454
+ ensureNotes(id: string, options: PluginWriteOptions): Promise<PluginCalendarEvent>;
455
+ get(id: string): Promise<PluginCalendarEvent | null>;
340
456
  query(query: PluginCalendarQuery): Promise<PluginPage<PluginCalendarEvent>>;
341
- create(input: PluginCalendarInput): Promise<PluginCalendarEvent>;
457
+ create(input: PluginCalendarInput, options?: PluginCreateOptions): Promise<PluginCalendarEvent>;
342
458
  update(id: string, patch: PluginCalendarPatch, options: PluginWriteOptions): Promise<PluginCalendarEvent>;
343
459
  delete(id: string, options: PluginWriteOptions): Promise<void>;
344
460
  };
@@ -391,4 +507,3 @@ export interface PluginContent {
391
507
  revision: string;
392
508
  }>;
393
509
  }
394
- export {};
@@ -3,3 +3,10 @@ export declare class PluginConflictError extends Error {
3
3
  readonly name = "PluginConflictError";
4
4
  constructor(message?: string);
5
5
  }
6
+ export type PluginSyncResetReason = "invalid-cursor" | "query-changed" | "scope-changed" | "history-expired" | "history-replaced" | "protocol-changed";
7
+ /** 游标不再覆盖当前数据范围;保留映射并重新全量,不能将失败当作空结果。 */
8
+ export declare class PluginSyncResetRequiredError extends Error {
9
+ readonly reason: PluginSyncResetReason;
10
+ readonly name = "PluginSyncResetRequiredError";
11
+ constructor(reason: PluginSyncResetReason);
12
+ }
@@ -3,34 +3,39 @@ import type { PluginPermission } from "./permissions";
3
3
  /**
4
4
  * 业务数据变更事件。事件只说明「哪一项变了」,不携带数据:需要时用 context.data 重新读取。
5
5
  * 正文修改计入所属卡片、文章、项目文档或插件实体的 updated;Notebook 资料的增删改计入所属
6
- * Notebook 的 updated;待办与日程只给出集合级变化。entity.* 与 record.* 是本插件实体
6
+ * Notebook 的 updated;待办、日程和目录使用相同的对象动作事件。entity.* 与 record.* 是本插件实体
7
7
  * (context.entities)与记录(context.records)的变化,只发给拥有它的插件。
8
8
  */
9
- export declare const PLUGIN_EVENT_TYPES: readonly ["card.created", "card.updated", "card.deleted", "article.created", "article.updated", "article.deleted", "document.created", "document.updated", "document.deleted", "whiteboard.created", "whiteboard.updated", "whiteboard.deleted", "project.created", "project.updated", "project.deleted", "notebook.created", "notebook.updated", "notebook.deleted", "material.created", "material.updated", "material.deleted", "chat.created", "chat.updated", "chat.deleted", "entity.created", "entity.updated", "entity.deleted", "record.created", "record.updated", "record.deleted", "todos.changed", "calendar.changed", "workspace.reset"];
9
+ export declare const PLUGIN_EVENT_TYPES: readonly ["card.created", "card.updated", "card.deleted", "article.created", "article.updated", "article.deleted", "document.created", "document.updated", "document.deleted", "whiteboard.created", "whiteboard.updated", "whiteboard.deleted", "project.created", "project.updated", "project.deleted", "notebook.created", "notebook.updated", "notebook.deleted", "material.created", "material.updated", "material.deleted", "chat.created", "chat.updated", "chat.deleted", "entity.created", "entity.updated", "entity.deleted", "record.created", "record.updated", "record.deleted", "todo.created", "todo.updated", "todo.deleted", "event.created", "event.updated", "event.deleted", "todo-list.created", "todo-list.updated", "todo-list.deleted", "calendar.created", "calendar.updated", "calendar.deleted", "workspace.reset"];
10
10
  export type PluginEventType = (typeof PLUGIN_EVENT_TYPES)[number];
11
- /** 变化来自哪里:插件经 context.data / context.content 写入时为 plugin,其余(用户、同步、AI 等)为 app */
11
+ /** 能识别插件写入方时提供 pluginId;app 也包含不能细分写入方的通知。 */
12
12
  export type PluginEventOrigin = {
13
13
  kind: "plugin";
14
14
  pluginId: string;
15
15
  } | {
16
16
  kind: "app";
17
17
  };
18
- export interface PluginDomainEvent {
19
- type: PluginEventType;
20
- /** 实体事件给出与 context.data / context.entities 相同的 ID;集合级事件没有 */
21
- id?: string;
22
- /** entity.* 事件给出实体类型(registerKind 声明的 kind);删除后读不到实体时据此区分 */
18
+ interface PluginEventFields {
23
19
  kind?: string;
24
- /** record.* 事件给出记录所在的集合 */
25
20
  collection?: string;
26
- /** 宿主发出事件的时间(毫秒) */
21
+ /** 宿主送出通知的时间(毫秒),不是业务版本。 */
27
22
  at: number;
28
- /** 用来忽略自己写入引起的事件;待办与日程的集合级事件恒为 app */
23
+ /** 待办、日程、目录事件不提供精确写入方,固定为 app。 */
29
24
  origin: PluginEventOrigin;
30
25
  }
26
+ export type PluginEvent<T extends PluginEventType = PluginEventType> = T extends "workspace.reset" ? PluginEventFields & {
27
+ type: T;
28
+ id?: never;
29
+ } : PluginEventFields & {
30
+ type: T;
31
+ id: string;
32
+ };
33
+ export type PluginDomainEvent = PluginEvent;
31
34
  /** 接收事件需要对应数据的读取权限;未获准时事件不送达,也不会弹窗询问 */
32
35
  export declare const PLUGIN_EVENT_PERMISSIONS: Record<PluginEventType, PluginPermission | null>;
33
36
  export declare const isPluginEventType: (value: unknown) => value is PluginEventType;
34
37
  export interface PluginEvents {
35
- on(types: PluginEventType | readonly PluginEventType[], listener: (event: PluginDomainEvent) => void): Disposable;
38
+ /** 同一订阅按序处理;异步回调等待完成,返回值不作为结果。 */
39
+ on<T extends PluginEventType>(types: T | readonly T[], listener: (event: PluginEvent<T>) => void): Disposable;
36
40
  }
41
+ export {};