@xiongtao.xt/tau-plugins 0.60.0 → 0.61.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 (36) hide show
  1. package/CHANGELOG.md +12 -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 +338 -0
  12. package/docs/user-data.md +12 -17
  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 +112 -7
  19. package/types/packages/plugins/src/errors.d.ts +7 -0
  20. package/types/packages/plugins/src/index.d.ts +1 -1
  21. package/types/packages/plugins/src/package.d.ts +7 -2
  22. package/types/packages/plugins/src/portable.d.ts +5 -2
  23. package/types/packages/plugins/src/skills.d.ts +16 -0
  24. package/types/packages/plugins/src/template.d.ts +101 -0
  25. package/types/packages/plugins/src/unified.d.ts +60 -0
  26. package/types/packages/plugins/src/version.d.ts +5 -0
  27. package/types/packages/shared/src/task-assistant/contracts.d.ts +15 -0
  28. package/types/packages/shared/src/task-assistant/occurrence-state.d.ts +7 -0
  29. package/types/packages/shared/src/task-assistant/schema.d.ts +3 -0
  30. package/types/packages/shared/task-assistant.d.ts +1 -0
  31. package/types/packages/ui/src/hooks/useEdgeFade.d.ts +1 -1
  32. package/types/packages/ui/src/primitives/AnchoredPanel.d.ts +3 -1
  33. package/types/packages/ui/src/primitives/anchoredPosition.d.ts +8 -0
  34. package/unified.js +21 -0
  35. package/client/chunk-6XAEU7BJ.js +0 -330
  36. package/client/chunk-PRE35AOA.js +0 -185
@@ -0,0 +1,101 @@
1
+ import { type PluginManifest } from "./package";
2
+ import { type PluginCatalogFields } from "./categories";
3
+ import type { JsonValue } from "./json";
4
+ import { type PackagePlatform, type PackageTargets, type PackageTarget } from "./package-targets";
5
+ import { type PortablePluginManifest } from "./portable";
6
+ import { type UnifiedTemplateManifest, type UnifiedSkillPackageManifest } from "./unified";
7
+ export { hasSkillScripts, SKILL_README, SKILL_ROOT } from "./skills";
8
+ interface SiteFieldBase {
9
+ /** 模板从 `site.fields[key]` 读取 */
10
+ key: string;
11
+ label: string;
12
+ description?: string;
13
+ }
14
+ /** 模板声明的站点字段,宿主据此渲染「博客模板」设置并在发布时按声明解析取值。 */
15
+ export type TemplateSiteField = (SiteFieldBase & {
16
+ type: "text" | "textarea" | "url";
17
+ placeholder?: string;
18
+ default?: string;
19
+ }) | (SiteFieldBase & {
20
+ type: "select";
21
+ options: {
22
+ value: string;
23
+ label: string;
24
+ }[];
25
+ default?: string;
26
+ }) | (SiteFieldBase & {
27
+ type: "switch";
28
+ default?: boolean;
29
+ });
30
+ export type SiteFieldValue = string | boolean;
31
+ export interface LegacyTemplateManifest extends PluginCatalogFields {
32
+ formatVersion: 1;
33
+ apiVersion: 1;
34
+ platform: "desktop";
35
+ id: string;
36
+ name: string;
37
+ version: string;
38
+ minAppVersion?: string;
39
+ template: {
40
+ protocolVersion: 1;
41
+ root: string;
42
+ entries: string[];
43
+ siteFields?: TemplateSiteField[];
44
+ };
45
+ integrity: Record<string, string>;
46
+ }
47
+ export type TemplateManifest = LegacyTemplateManifest | UnifiedTemplateManifest;
48
+ /** 独立 Skill 包:没有代码入口,只分发 `skills/<id>/` 目录,安装后即可在 Skill 页使用。 */
49
+ interface SkillPackageBase extends PluginCatalogFields {
50
+ formatVersion: 1;
51
+ apiVersion: 1;
52
+ id: string;
53
+ name: string;
54
+ version: string;
55
+ skills: readonly string[];
56
+ integrity: Record<string, string>;
57
+ }
58
+ export interface DesktopSkillPackageManifest extends SkillPackageBase {
59
+ platform: "desktop";
60
+ minAppVersion?: string;
61
+ }
62
+ export interface LegacyPortableSkillPackageManifest extends SkillPackageBase {
63
+ platform: "portable";
64
+ targets: PackageTargets;
65
+ minAppVersion?: never;
66
+ }
67
+ export type PortableSkillPackageManifest = LegacyPortableSkillPackageManifest | UnifiedSkillPackageManifest;
68
+ export type SkillPackageManifest = DesktopSkillPackageManifest | PortableSkillPackageManifest;
69
+ export type DistributionManifest = PluginManifest | PortablePluginManifest | TemplateManifest | SkillPackageManifest;
70
+ export declare const DISTRIBUTION_LIMITS: {
71
+ readonly zipBytes: number;
72
+ readonly expandedBytes: number;
73
+ readonly entries: 512;
74
+ };
75
+ /** 包文件路径只约束文件系统边界,不约束模板的公开 URL。 */
76
+ export declare function assertPackagePath(value: unknown): asserts value is string;
77
+ export declare function assertPublishPath(value: unknown): asserts value is string;
78
+ /** 按模板声明解析站点字段:只输出声明过的 key,类型不符或越界的存量值回落到默认值。 */
79
+ export declare function resolveSiteFields(fields: readonly TemplateSiteField[] | undefined, values: Record<string, JsonValue> | undefined): Record<string, SiteFieldValue>;
80
+ export declare function isTemplateManifest(value: unknown): value is TemplateManifest;
81
+ export declare function isSkillPackageManifest(value: unknown): value is SkillPackageManifest;
82
+ export declare function validateSkillPackageManifest(value: unknown): SkillPackageManifest;
83
+ export declare function validatePortableSkillPackageManifest(value: unknown): PortableSkillPackageManifest;
84
+ export type DistributionPackageKind = "plugin" | "skills" | "template";
85
+ export declare function distributionPackageKind(manifest: DistributionManifest | PortablePluginManifest): DistributionPackageKind;
86
+ export declare function assertSkillPackageCompatibility(manifest: SkillPackageManifest, host: {
87
+ platform: PackagePlatform;
88
+ appVersion: string;
89
+ }): PackageTarget;
90
+ export declare function validateMobilePackageManifest(value: unknown, host?: {
91
+ platform: "android" | "ios";
92
+ appVersion: string;
93
+ }): PortablePluginManifest | PortableSkillPackageManifest;
94
+ export declare function validateDistributionManifest(value: unknown): DistributionManifest;
95
+ /** 能在用户本机执行代码的版本(本机后台、带脚本的 Skill)必须经人工系统审核才能发布与安装。 */
96
+ export declare function requiresSystemReview(manifest: {
97
+ backend?: unknown;
98
+ skills?: readonly string[];
99
+ integrity?: Record<string, string>;
100
+ }): boolean;
101
+ export declare function distributionFiles(manifest: DistributionManifest): string[];
@@ -0,0 +1,60 @@
1
+ import { type LegacyPluginManifest, type PluginManifest } from "./package";
2
+ import { type PortablePluginManifest } from "./portable";
3
+ import { type PackageTargets } from "./package-targets";
4
+ import { type LegacyTemplateManifest, type LegacyPortableSkillPackageManifest } from "./template";
5
+ export declare const PACKAGE_FORMAT_MIN_VERSIONS: {
6
+ readonly desktop: "0.66.3";
7
+ readonly android: "0.5.1";
8
+ readonly ios: "0.5.1";
9
+ };
10
+ interface UnifiedPackageHeader {
11
+ readonly formatVersion: 4;
12
+ readonly platform: "portable";
13
+ readonly targets: PackageTargets;
14
+ readonly minAppVersion?: never;
15
+ readonly description?: string;
16
+ }
17
+ interface UnifiedPluginBase extends Omit<LegacyPluginManifest, "formatVersion" | "platform" | "minAppVersion" | "backend" | "editor" | "whiteboard">, UnifiedPackageHeader {
18
+ readonly kind: "plugin";
19
+ readonly editor?: never;
20
+ readonly whiteboard?: never;
21
+ }
22
+ export interface UnifiedWebPluginManifest extends UnifiedPluginBase {
23
+ readonly profile: "web-v1";
24
+ readonly backend?: never;
25
+ }
26
+ export interface UnifiedDesktopPluginManifest extends UnifiedPluginBase {
27
+ readonly profile: "desktop-v1";
28
+ readonly backend: NonNullable<LegacyPluginManifest["backend"]>;
29
+ }
30
+ export type UnifiedPluginManifest = UnifiedWebPluginManifest | UnifiedDesktopPluginManifest;
31
+ export interface UnifiedSkillPackageManifest extends Omit<LegacyPortableSkillPackageManifest, "formatVersion" | "platform" | "targets" | "minAppVersion">, UnifiedPackageHeader {
32
+ readonly kind: "skills";
33
+ }
34
+ export interface UnifiedTemplateManifest extends Omit<LegacyTemplateManifest, "formatVersion" | "platform" | "minAppVersion">, UnifiedPackageHeader {
35
+ readonly kind: "template";
36
+ }
37
+ export type UnifiedPackageManifest = UnifiedPluginManifest | UnifiedSkillPackageManifest | UnifiedTemplateManifest;
38
+ export declare function validateUnifiedPluginManifest(value: unknown): UnifiedPluginManifest;
39
+ /** 已发布格式的字节与摘要保持原样,只在读取边界共用字段校验。 */
40
+ export declare function validateUnifiedPackageManifest(value: unknown): UnifiedPackageManifest;
41
+ export declare function buildUnifiedPluginManifest(value: unknown, output: {
42
+ main: string;
43
+ styles?: string;
44
+ integrity: Readonly<Record<string, string>>;
45
+ skills?: readonly string[];
46
+ }): UnifiedPluginManifest;
47
+ export declare function buildUnifiedPackageManifest(value: unknown, output: {
48
+ main?: string;
49
+ styles?: string;
50
+ integrity: Readonly<Record<string, string>>;
51
+ skills?: readonly string[];
52
+ }): UnifiedPackageManifest;
53
+ export declare function packageTargets(manifest: {
54
+ platform: "desktop" | "portable";
55
+ targets?: PackageTargets;
56
+ minAppVersion?: string;
57
+ }): PackageTargets;
58
+ export declare function isWebPluginManifest(manifest: PluginManifest | PortablePluginManifest): manifest is PortablePluginManifest;
59
+ export declare function readApplicationPluginManifest(value: unknown): PluginManifest | PortablePluginManifest;
60
+ export {};
@@ -1,4 +1,9 @@
1
1
  export declare function comparePluginVersions(left: string, right: string): number;
2
2
  export declare function assertPluginCompatibility(manifest: {
3
3
  minAppVersion?: string;
4
+ targets?: {
5
+ desktop?: {
6
+ minAppVersion: string;
7
+ };
8
+ };
4
9
  }, clientVersion: string): void;
@@ -29,6 +29,7 @@ export interface TaskRecurrenceSegment {
29
29
  effectiveDate: string;
30
30
  rule: TaskRecurrenceRule | null;
31
31
  }
32
+ export declare function normalizeTaskRecurrenceRule(rule: TaskRecurrenceRule): TaskRecurrenceRule;
32
33
  export interface TaskOccurrenceState {
33
34
  completedAt?: number | null;
34
35
  skipped?: boolean;
@@ -48,6 +49,7 @@ export interface DocumentTaskAttributes {
48
49
  taskCompletedAt?: number | null;
49
50
  }
50
51
  export interface AssistantTask {
52
+ isSeries?: boolean;
51
53
  taskRef: TaskRef;
52
54
  revision: string;
53
55
  title: string;
@@ -63,6 +65,8 @@ export interface AssistantTask {
63
65
  documentRevision?: string;
64
66
  occurrence?: TaskOccurrenceRef;
65
67
  reminderAt?: string | null;
68
+ reminderOffsets?: number[];
69
+ occurrenceState?: TaskOccurrenceState;
66
70
  recurrence?: TaskRecurrenceSegment[];
67
71
  writable: boolean;
68
72
  readonlyReason?: string;
@@ -73,6 +77,11 @@ export interface AssistantCalendarEvent {
73
77
  revision: string;
74
78
  title: string;
75
79
  calendarId: number;
80
+ reminderOffsets?: number[];
81
+ notes?: {
82
+ contentId: number;
83
+ createdAt: number;
84
+ };
76
85
  start: string;
77
86
  end: string;
78
87
  allDay: boolean;
@@ -116,4 +125,10 @@ export declare class TaskAssistantError extends Error {
116
125
  constructor(code: string, message: string);
117
126
  }
118
127
  export declare function taskKey(ref: TaskRef): string;
128
+ export declare function encodeTaskIdComponent(value: string): string;
129
+ export declare function decodeTaskIdComponent(value: string): string;
130
+ export declare function parseTaskKey(value: string): {
131
+ taskRef: TaskRef;
132
+ occurrenceDate?: string;
133
+ } | null;
119
134
  export declare function occurrenceKey(ref: TaskOccurrenceRef): string;
@@ -0,0 +1,7 @@
1
+ import { type TaskOccurrenceState } from "./contracts";
2
+ export interface TaskOccurrencePatch {
3
+ completed?: boolean;
4
+ skipped?: boolean;
5
+ scheduledAt?: string | null;
6
+ }
7
+ export declare function patchOccurrenceState(state: TaskOccurrenceState, patch: TaskOccurrencePatch, now: number): TaskOccurrenceState;
@@ -29,8 +29,11 @@ export declare const TASK_WRITE_SCHEMAS: {
29
29
  };
30
30
  export type TaskWriteName = keyof typeof TASK_WRITE_SCHEMAS;
31
31
  export declare const TASK_READ_SCHEMAS: {
32
+ query_todo_occurrence_states: TaskSchema;
32
33
  query_todos: TaskSchema;
33
34
  query_calendar_events: TaskSchema;
35
+ query_task_directories: TaskSchema;
36
+ get_task_object: TaskSchema;
34
37
  query_task_operations: TaskSchema;
35
38
  };
36
39
  export type TaskReadName = keyof typeof TASK_READ_SCHEMAS;
@@ -1,3 +1,4 @@
1
1
  export * from "./src/task-assistant/contracts";
2
2
  export * from "./src/task-assistant/schema";
3
3
  export * from "./src/task-assistant/document-state";
4
+ export * from "./src/task-assistant/occurrence-state";
@@ -11,7 +11,7 @@ export type EdgeFadeOptions = {
11
11
  bottom?: boolean;
12
12
  };
13
13
  /** 滚动边缘状态:scroll 事件 + ResizeObserver(容器尺寸随窗口缩放/侧栏拖宽变化)+
14
- MutationObserver(列表数据异步到达撑高内容)三路监听,布尔翻转才 setState。
14
+ MutationObserver(节点增删与文字变化)三路监听,布尔翻转才 setState。
15
15
  useLayoutEffect 内完成首次测量,避免能滚页面首帧渐隐缺失的闪烁。
16
16
  参数是元素而非 RefObject:视图常有 loading 早退分支(容器晚于首帧挂载),
17
17
  配合 callback ref 的 setState 才能在挂载时重新接线 */
@@ -20,6 +20,8 @@ export interface AnchoredPanelProps extends Omit<HTMLAttributes<HTMLDivElement>,
20
20
  anchor: HTMLElement | null;
21
21
  /** 12 向全表(引擎 flip/shift 兜底),默认 bottom-start */
22
22
  placement?: AnchoredPlacement;
23
+ /** 让可滚动预览适应锚点一侧的可用高度。 */
24
+ fitVerticalSpace?: boolean;
23
25
  /** 显隐由宿主驱动;缺省锚点存在即显示(宿主托管用法) */
24
26
  open?: boolean;
25
27
  /** 8px 菱形箭头(随 flip 换边),默认关 */
@@ -30,7 +32,7 @@ export interface AnchoredPanelProps extends Omit<HTMLAttributes<HTMLDivElement>,
30
32
  /** 卡片 DOM 引用(AnchoredPanel 内部已占用一位做定位,此处合并外部引用) */
31
33
  ref?: Ref<HTMLDivElement>;
32
34
  }
33
- export declare function AnchoredPanel({ anchor, placement, open, arrow, className, children, ref: externalRef, ...cardProps }: AnchoredPanelProps): import("react").ReactPortal | null;
35
+ export declare function AnchoredPanel({ anchor, placement, fitVerticalSpace, open, arrow, className, children, ref: externalRef, ...cardProps }: AnchoredPanelProps): import("react").ReactPortal | null;
34
36
  export declare namespace AnchoredPanel {
35
37
  var Body: typeof AnchoredPanelBody;
36
38
  var Footer: typeof AnchoredPanelFooter;
@@ -15,6 +15,14 @@ export type AnchoredPlacement = AnchoredSide | `${AnchoredSide}-${AnchoredAlign}
15
15
  export interface AnchoredPositionOptions {
16
16
  gap?: number;
17
17
  }
18
+ /** 可滚动的正文预览固定在可用空间较大的一侧,内容异步长高也不盖住触发文字。 */
19
+ export declare function fitVerticalPreview(anchor: {
20
+ top: number;
21
+ bottom: number;
22
+ }, placement: AnchoredPlacement, viewportHeight: number, gap?: number): {
23
+ placement: AnchoredPlacement;
24
+ maxHeight: number;
25
+ } | undefined;
18
26
  export interface AnchoredPosition {
19
27
  x: number;
20
28
  y: number;
package/unified.js ADDED
@@ -0,0 +1,21 @@
1
+ import {
2
+ PACKAGE_FORMAT_MIN_VERSIONS,
3
+ buildUnifiedPackageManifest,
4
+ buildUnifiedPluginManifest,
5
+ isWebPluginManifest,
6
+ packageTargets,
7
+ readApplicationPluginManifest,
8
+ validateUnifiedPackageManifest,
9
+ validateUnifiedPluginManifest
10
+ } from "./client/chunk-UGYIAPAN.js";
11
+ import "./client/chunk-UTVEXGFI.js";
12
+ export {
13
+ PACKAGE_FORMAT_MIN_VERSIONS,
14
+ buildUnifiedPackageManifest,
15
+ buildUnifiedPluginManifest,
16
+ isWebPluginManifest,
17
+ packageTargets,
18
+ readApplicationPluginManifest,
19
+ validateUnifiedPackageManifest,
20
+ validateUnifiedPluginManifest
21
+ };
@@ -1,330 +0,0 @@
1
- // packages/plugins/src/ids.ts
2
- function assertLocalId(value) {
3
- if (typeof value !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(value)) {
4
- throw new Error("\u63D2\u4EF6\u6807\u8BC6\u5FC5\u987B\u4E3A 1 \u81F3 128 \u4F4D\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u70B9\u3001\u6A2A\u7EBF\u6216\u4E0B\u5212\u7EBF");
5
- }
6
- }
7
-
8
- // packages/plugins/src/version.ts
9
- function parseVersion(value) {
10
- const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(
11
- value
12
- );
13
- if (!match) throw new Error(`\u7248\u672C\u53F7\u65E0\u6548\uFF1A${value}`);
14
- const pre = match[4]?.split(".") ?? [];
15
- if (pre.some((part) => /^\d+$/.test(part) && part.length > 1 && part.startsWith("0")))
16
- throw new Error(`\u7248\u672C\u53F7\u65E0\u6548\uFF1A${value}`);
17
- return { core: match.slice(1, 4), pre };
18
- }
19
- function comparePluginVersions(left, right) {
20
- const a = parseVersion(left);
21
- const b = parseVersion(right);
22
- const numeric = (x, y) => BigInt(x) === BigInt(y) ? 0 : BigInt(x) > BigInt(y) ? 1 : -1;
23
- for (let index = 0; index < 3; index++) {
24
- const result = numeric(a.core[index], b.core[index]);
25
- if (result) return result;
26
- }
27
- if (!a.pre.length || !b.pre.length)
28
- return a.pre.length === b.pre.length ? 0 : a.pre.length ? -1 : 1;
29
- for (let index = 0; index < Math.max(a.pre.length, b.pre.length); index++) {
30
- const x = a.pre[index], y = b.pre[index];
31
- if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
32
- if (x === y) continue;
33
- const nx = /^\d+$/.test(x), ny = /^\d+$/.test(y);
34
- return nx && ny ? numeric(x, y) : nx !== ny ? nx ? -1 : 1 : x > y ? 1 : -1;
35
- }
36
- return 0;
37
- }
38
-
39
- // packages/plugins/src/backend-manifest.ts
40
- var PLUGIN_SYSTEM_ACCESS = ["filesystem", "network", "process"];
41
- function validateBackendManifest(value) {
42
- if (!value || typeof value !== "object" || Array.isArray(value))
43
- throw new Error("\u540E\u53F0\u58F0\u660E\u5FC5\u987B\u662F\u5BF9\u8C61");
44
- const item = value;
45
- if (typeof item.entry !== "string" || !/^[\w./-]+\.js$/.test(item.entry) || item.entry.split("/").some((part) => !part || part === "." || part === ".."))
46
- throw new Error("\u540E\u53F0\u5165\u53E3\u5FC5\u987B\u662F\u5305\u5185 JS \u6587\u4EF6");
47
- if (item.runtime !== "node" || item.apiVersion !== 1)
48
- throw new Error("\u540E\u53F0\u8FD0\u884C\u65F6\u6216\u534F\u8BAE\u7248\u672C\u4E0D\u517C\u5BB9");
49
- if (item.scope !== "application" && item.scope !== "workspace") throw new Error("\u540E\u53F0\u4F5C\u7528\u57DF\u65E0\u6548");
50
- if (item.activation !== "on-demand" && item.activation !== "app-ready" && item.activation !== "workspace-ready")
51
- throw new Error("\u540E\u53F0\u6FC0\u6D3B\u65F6\u673A\u65E0\u6548");
52
- if (item.activation !== "on-demand" && item.activation !== (item.scope === "application" ? "app-ready" : "workspace-ready"))
53
- throw new Error("\u540E\u53F0\u6FC0\u6D3B\u65F6\u673A\u4E0E\u4F5C\u7528\u57DF\u4E0D\u5339\u914D");
54
- if (item.lifetime !== "idle" && item.lifetime !== "persistent")
55
- throw new Error("\u540E\u53F0\u751F\u547D\u5468\u671F\u65E0\u6548");
56
- if (typeof item.reason !== "string" || !item.reason.trim()) throw new Error("\u540E\u53F0\u7528\u9014\u4E0D\u80FD\u4E3A\u7A7A");
57
- if (!Array.isArray(item.systemAccess) || item.systemAccess.some((value2) => !PLUGIN_SYSTEM_ACCESS.includes(value2)))
58
- throw new Error("\u540E\u53F0\u7CFB\u7EDF\u7528\u9014\u5206\u7C7B\u65E0\u6548");
59
- let tools;
60
- if (item.tools !== void 0) {
61
- if (!Array.isArray(item.tools) || !item.systemAccess.includes("process"))
62
- throw new Error("\u5916\u90E8\u5DE5\u5177\u987B\u58F0\u660E process \u7528\u9014");
63
- const ids = /* @__PURE__ */ new Set();
64
- tools = Object.freeze(
65
- item.tools.map((tool) => {
66
- if (!tool || typeof tool !== "object" || Array.isArray(tool))
67
- throw new Error("\u5916\u90E8\u5DE5\u5177\u58F0\u660E\u65E0\u6548");
68
- const value2 = tool;
69
- if (typeof value2.id !== "string" || !/^[a-z][\w.-]*$/.test(value2.id) || ids.has(value2.id) || typeof value2.command !== "string" || !value2.command.trim() || value2.command.includes("\0"))
70
- throw new Error("\u5916\u90E8\u5DE5\u5177\u8EAB\u4EFD\u6216\u547D\u4EE4\u65E0\u6548");
71
- ids.add(value2.id);
72
- if (value2.args !== void 0 && (!Array.isArray(value2.args) || value2.args.some((arg) => typeof arg !== "string" || arg.includes("\0"))))
73
- throw new Error("\u5916\u90E8\u5DE5\u5177\u53C2\u6570\u65E0\u6548");
74
- return Object.freeze({
75
- id: value2.id,
76
- command: value2.command,
77
- ...value2.args ? { args: Object.freeze([...value2.args]) } : {}
78
- });
79
- })
80
- );
81
- }
82
- return Object.freeze({
83
- ...tools ? { tools } : {},
84
- entry: item.entry,
85
- runtime: "node",
86
- apiVersion: 1,
87
- scope: item.scope,
88
- activation: item.activation,
89
- lifetime: item.lifetime,
90
- reason: item.reason.trim(),
91
- systemAccess: Object.freeze([...new Set(item.systemAccess)])
92
- });
93
- }
94
-
95
- // packages/plugins/src/categories.ts
96
- var PLUGIN_CATEGORIES = [
97
- { id: "sync", label: "\u540C\u6B65" },
98
- { id: "upload", label: "\u8D44\u6E90\u4E0A\u4F20" },
99
- { id: "editor", label: "\u7F16\u8F91\u5668" },
100
- { id: "whiteboard", label: "\u767D\u677F" },
101
- { id: "blog-template", label: "\u535A\u5BA2\u6A21\u677F" },
102
- { id: "blog-publish", label: "\u535A\u5BA2\u53D1\u5E03" },
103
- { id: "ai", label: "AI" },
104
- { id: "skill", label: "Skill" },
105
- { id: "voice", label: "\u8BED\u97F3" },
106
- { id: "video", label: "\u89C6\u9891" },
107
- { id: "page", label: "\u9875\u9762" }
108
- ];
109
- var categoryIds = new Set(PLUGIN_CATEGORIES.map((item) => item.id));
110
- var isPluginCategory = (value) => typeof value === "string" && categoryIds.has(value);
111
- function readCatalogFields(item) {
112
- const list = (value, name) => {
113
- if (value === void 0) return [];
114
- if (Array.isArray(value)) return value;
115
- throw new Error(`${name} \u5FC5\u987B\u662F\u6570\u7EC4`);
116
- };
117
- const categories = [];
118
- for (const value of list(item.categories, "categories")) {
119
- if (!isPluginCategory(value)) throw new Error(`\u672A\u77E5\u63D2\u4EF6\u5206\u7C7B\uFF1A${String(value)}`);
120
- else if (!categories.includes(value)) categories.push(value);
121
- }
122
- const keywords = [];
123
- for (const value of list(item.keywords, "keywords")) {
124
- const keyword = typeof value === "string" ? value.trim() : "";
125
- if (!keyword) throw new Error("\u5173\u952E\u8BCD\u5FC5\u987B\u662F\u975E\u7A7A\u6587\u672C");
126
- else if (!keywords.includes(keyword)) keywords.push(keyword);
127
- }
128
- return {
129
- ...categories.length ? { categories: Object.freeze(categories) } : {},
130
- ...keywords.length ? { keywords: Object.freeze(keywords) } : {}
131
- };
132
- }
133
-
134
- // packages/plugins/src/ai.ts
135
- var PLUGIN_AI_CAPABILITIES = {
136
- chat: { name: "\u5BF9\u8BDD\u529F\u80FD" },
137
- flashcardGeneration: { name: "\u95EA\u5361" }
138
- };
139
- var isPluginAICapability = (value) => typeof value === "string" && Object.hasOwn(PLUGIN_AI_CAPABILITIES, value);
140
-
141
- // packages/plugins/src/permissions.ts
142
- var aiPermissions = Object.keys(PLUGIN_AI_CAPABILITIES).map(
143
- (capability) => `ai:${capability}`
144
- );
145
- var PLUGIN_PERMISSIONS = [
146
- "cards:read",
147
- "cards:write",
148
- "cards:delete",
149
- "articles:read",
150
- "articles:write",
151
- "articles:delete",
152
- "documents:read",
153
- "documents:write",
154
- "documents:delete",
155
- "whiteboards:read",
156
- "whiteboards:write",
157
- "whiteboards:delete",
158
- "projects:read",
159
- "projects:write",
160
- "projects:delete",
161
- "todos:read",
162
- "todos:write",
163
- "todos:delete",
164
- "calendar:read",
165
- "calendar:write",
166
- "calendar:delete",
167
- "notebooks:read",
168
- "materials:read",
169
- "chats:read",
170
- "flashcards:read",
171
- "flashcards:write",
172
- "speech:input",
173
- "tts:synthesize",
174
- ...aiPermissions
175
- ];
176
- var permissionIds = new Set(PLUGIN_PERMISSIONS);
177
- var isPluginPermission = (value) => typeof value === "string" && permissionIds.has(value);
178
- function readPermissionsField(item) {
179
- if (item.permissions === void 0) return {};
180
- if (!Array.isArray(item.permissions)) {
181
- throw new Error("permissions \u5FC5\u987B\u662F\u6570\u7EC4");
182
- }
183
- const permissions = [];
184
- for (const value of item.permissions) {
185
- if (!isPluginPermission(value)) throw new Error(`\u672A\u77E5\u63D2\u4EF6\u6743\u9650\uFF1A${String(value)}`);
186
- else if (!permissions.includes(value)) permissions.push(value);
187
- }
188
- return permissions.length ? { permissions: Object.freeze(permissions) } : {};
189
- }
190
-
191
- // packages/plugins/src/skills.ts
192
- var SKILL_ROOT = "skills";
193
- var SKILL_README = "SKILL.md";
194
- var skillDirectory = (id) => `${SKILL_ROOT}/${id}`;
195
- function readSkillsField(value) {
196
- if (value === void 0) return void 0;
197
- if (!Array.isArray(value)) throw new Error("skills \u5FC5\u987B\u662F\u6570\u7EC4");
198
- const ids = /* @__PURE__ */ new Set();
199
- for (const id of value) {
200
- if (typeof id !== "string") throw new Error("Skill ID \u65E0\u6548");
201
- assertLocalId(id);
202
- ids.add(id);
203
- }
204
- return ids.size ? Object.freeze([...ids]) : void 0;
205
- }
206
- function readSkillFiles(skills, integrity) {
207
- const files = {};
208
- const declared = new Set(skills ?? []);
209
- for (const [name, hash] of Object.entries(integrity)) {
210
- if (!name.startsWith(SKILL_ROOT + "/")) continue;
211
- const [, id, ...rest] = name.split("/");
212
- if (!declared.has(id) || !rest.length || rest.some((part) => !part || part === "." || part === ".."))
213
- throw new Error(`Skill \u6587\u4EF6\u4E0D\u5C5E\u4E8E\u5DF2\u58F0\u660E\u7684 Skill\uFF1A${name}`);
214
- if (typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash))
215
- throw new Error("Skill \u6587\u4EF6\u7F3A\u5C11\u6709\u6548\u7684\u5B8C\u6574\u6027\u6458\u8981");
216
- files[name] = hash;
217
- }
218
- for (const id of declared)
219
- if (!files[`${skillDirectory(id)}/${SKILL_README}`])
220
- throw new Error(`Skill ${id} \u7F3A\u5C11 ${SKILL_README}`);
221
- return files;
222
- }
223
-
224
- // packages/plugins/src/package-fields.ts
225
- function readPluginIdentity(item) {
226
- const { id, name, version } = item;
227
- if (typeof id !== "string") throw new Error("\u63D2\u4EF6 ID \u65E0\u6548");
228
- assertLocalId(id);
229
- if (typeof name !== "string" || !name.trim() || typeof version !== "string")
230
- throw new Error("\u63D2\u4EF6\u540D\u79F0\u6216\u7248\u672C\u65E0\u6548");
231
- comparePluginVersions(version, version);
232
- return { id, name, version };
233
- }
234
- function readPluginMetadata(item) {
235
- return { ...readPluginIdentity(item), ...readCatalogFields(item), ...readPermissionsField(item) };
236
- }
237
- function readPluginFilePath(input, extension) {
238
- if (typeof input !== "string" || !/^[\w./-]+$/.test(input) || input.split("/").some((part) => !part || part === "." || part === "..") || !input.endsWith(extension))
239
- throw new Error("\u63D2\u4EF6\u5165\u53E3\u6216\u6837\u5F0F\u8DEF\u5F84\u65E0\u6548");
240
- return input;
241
- }
242
- function readPluginFiles(item, entries) {
243
- if (!item.integrity || typeof item.integrity !== "object" || Array.isArray(item.integrity))
244
- throw new Error("\u63D2\u4EF6\u4EA7\u7269\u7F3A\u5C11\u5B8C\u6574\u6027\u6458\u8981\u6E05\u5355");
245
- const source = item.integrity;
246
- const integrity = {};
247
- for (const name of entries) {
248
- const hash = source[name];
249
- if (typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash))
250
- throw new Error("\u63D2\u4EF6\u4EA7\u7269\u7F3A\u5C11\u6709\u6548\u7684\u5B8C\u6574\u6027\u6458\u8981");
251
- integrity[name] = hash;
252
- }
253
- const skills = readSkillsField(item.skills);
254
- Object.assign(integrity, readSkillFiles(skills, source));
255
- return {
256
- ...skills ? { skills } : {},
257
- integrity: Object.freeze(integrity)
258
- };
259
- }
260
-
261
- // packages/plugins/src/package.ts
262
- var PLUGIN_SHARED_MODULES = [
263
- "@tau/plugins",
264
- "@tau/plugins/whiteboard",
265
- "@tau/plugins/sync",
266
- "@tau/ui",
267
- "react",
268
- "react-dom",
269
- "react-dom/client",
270
- "react/jsx-runtime",
271
- "react/jsx-dev-runtime"
272
- ];
273
- function validatePluginManifest(value) {
274
- if (!value || typeof value !== "object" || Array.isArray(value))
275
- throw new Error("\u63D2\u4EF6\u6E05\u5355\u5FC5\u987B\u662F\u5BF9\u8C61");
276
- const item = value;
277
- if (item.formatVersion !== 2 || item.apiVersion !== 1 || item.platform !== "desktop" || item.format !== "cjs")
278
- throw new Error("\u63D2\u4EF6\u5305\u683C\u5F0F\u3001API \u7248\u672C\u6216\u5E73\u53F0\u4E0D\u517C\u5BB9");
279
- const metadata = readPluginMetadata(item);
280
- const main = readPluginFilePath(item.main, ".js");
281
- const backend = item.backend === void 0 ? void 0 : validateBackendManifest(item.backend);
282
- if (!backend) throw new Error("\u684C\u9762\u5305\u683C\u5F0F 2 \u5FC5\u987B\u58F0\u660E\u540E\u53F0\uFF0C\u666E\u901A\u63D2\u4EF6\u4F7F\u7528\u683C\u5F0F 3");
283
- if (backend?.entry === main) throw new Error("\u540E\u53F0\u5165\u53E3\u4E0D\u80FD\u4E0E\u6E32\u67D3\u5165\u53E3\u76F8\u540C");
284
- if (backend && typeof item.minAppVersion !== "string")
285
- throw new Error("\u540E\u53F0\u63D2\u4EF6\u5FC5\u987B\u58F0\u660E\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C");
286
- if (item.minAppVersion !== void 0) {
287
- if (typeof item.minAppVersion !== "string") throw new Error("\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C\u65E0\u6548");
288
- comparePluginVersions(item.minAppVersion, item.minAppVersion);
289
- }
290
- const styles = item.styles === void 0 ? void 0 : readPluginFilePath(item.styles, ".css");
291
- const files = readPluginFiles(item, [
292
- main,
293
- ...styles ? [styles] : [],
294
- ...backend ? [backend.entry] : []
295
- ]);
296
- return Object.freeze({
297
- formatVersion: item.formatVersion,
298
- ...metadata,
299
- ...typeof item.minAppVersion === "string" ? { minAppVersion: item.minAppVersion } : {},
300
- apiVersion: 1,
301
- platform: "desktop",
302
- format: "cjs",
303
- main,
304
- ...backend ? { backend } : {},
305
- ...item.editor === true ? { editor: true } : {},
306
- ...item.whiteboard === true ? { whiteboard: true } : {},
307
- ...files,
308
- ...styles === void 0 ? {} : { styles }
309
- });
310
- }
311
- var isContentPlugin = (manifest) => manifest.editor === true || manifest.whiteboard === true;
312
-
313
- export {
314
- assertLocalId,
315
- comparePluginVersions,
316
- PLUGIN_SYSTEM_ACCESS,
317
- validateBackendManifest,
318
- PLUGIN_CATEGORIES,
319
- isPluginCategory,
320
- PLUGIN_AI_CAPABILITIES,
321
- isPluginAICapability,
322
- PLUGIN_PERMISSIONS,
323
- isPluginPermission,
324
- readPluginMetadata,
325
- readPluginFilePath,
326
- readPluginFiles,
327
- PLUGIN_SHARED_MODULES,
328
- validatePluginManifest,
329
- isContentPlugin
330
- };