@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.
- package/CHANGELOG.md +12 -0
- package/client/chunk-UGYIAPAN.js +869 -0
- package/docs/README.md +1 -0
- package/docs/backend.md +4 -10
- package/docs/blog-templates.md +7 -6
- package/docs/document-body.md +2 -0
- package/docs/getting-started.md +2 -14
- package/docs/plugin-basics.md +1 -1
- package/docs/portability.md +25 -2
- package/docs/skills.md +10 -12
- package/docs/task-data.md +338 -0
- package/docs/user-data.md +12 -17
- package/package.js +1 -1
- package/package.json +5 -1
- package/portable.js +3 -2
- package/publish-artifacts.js +36 -19
- package/types/packages/plugins/src/data-changes.d.ts +51 -0
- package/types/packages/plugins/src/data.d.ts +112 -7
- package/types/packages/plugins/src/errors.d.ts +7 -0
- package/types/packages/plugins/src/index.d.ts +1 -1
- package/types/packages/plugins/src/package.d.ts +7 -2
- package/types/packages/plugins/src/portable.d.ts +5 -2
- package/types/packages/plugins/src/skills.d.ts +16 -0
- package/types/packages/plugins/src/template.d.ts +101 -0
- package/types/packages/plugins/src/unified.d.ts +60 -0
- package/types/packages/plugins/src/version.d.ts +5 -0
- package/types/packages/shared/src/task-assistant/contracts.d.ts +15 -0
- package/types/packages/shared/src/task-assistant/occurrence-state.d.ts +7 -0
- package/types/packages/shared/src/task-assistant/schema.d.ts +3 -0
- package/types/packages/shared/task-assistant.d.ts +1 -0
- package/types/packages/ui/src/hooks/useEdgeFade.d.ts +1 -1
- package/types/packages/ui/src/primitives/AnchoredPanel.d.ts +3 -1
- package/types/packages/ui/src/primitives/anchoredPosition.d.ts +8 -0
- package/unified.js +21 -0
- package/client/chunk-6XAEU7BJ.js +0 -330
- package/client/chunk-PRE35AOA.js +0 -185
|
@@ -0,0 +1,869 @@
|
|
|
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-targets.ts
|
|
262
|
+
var PACKAGE_PLATFORMS = ["desktop", "android", "ios"];
|
|
263
|
+
function readPackageTargets(value) {
|
|
264
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
265
|
+
throw new Error("\u76EE\u6807\u5E73\u53F0\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
266
|
+
const targets = {};
|
|
267
|
+
for (const platform of PACKAGE_PLATFORMS) {
|
|
268
|
+
if (!Object.hasOwn(value, platform)) continue;
|
|
269
|
+
const target = value[platform];
|
|
270
|
+
if (!target || typeof target !== "object" || Array.isArray(target) || typeof target.minAppVersion !== "string")
|
|
271
|
+
throw new Error("\u5E73\u53F0\u7F3A\u5C11\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C");
|
|
272
|
+
const minimum = target.minAppVersion;
|
|
273
|
+
comparePluginVersions(minimum, minimum);
|
|
274
|
+
targets[platform] = Object.freeze({ minAppVersion: minimum });
|
|
275
|
+
}
|
|
276
|
+
if (!Object.keys(targets).length) throw new Error("\u9700\u8981\u81F3\u5C11\u4E00\u4E2A\u652F\u6301\u7684\u76EE\u6807\u5E73\u53F0");
|
|
277
|
+
return Object.freeze(targets);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// packages/plugins/src/template.ts
|
|
281
|
+
var DISTRIBUTION_LIMITS = {
|
|
282
|
+
zipBytes: 16 * 1024 * 1024,
|
|
283
|
+
expandedBytes: 32 * 1024 * 1024,
|
|
284
|
+
entries: 512
|
|
285
|
+
};
|
|
286
|
+
function assertPackagePath(value) {
|
|
287
|
+
if (typeof value !== "string" || !value || /[\\:%?#]/.test(value) || [...value].some((char) => char.charCodeAt(0) < 32) || value.split("/").some((part) => !part || part === "." || part === ".."))
|
|
288
|
+
throw new Error("\u63D2\u4EF6\u8D44\u6E90\u8DEF\u5F84\u65E0\u6548");
|
|
289
|
+
}
|
|
290
|
+
function assertPublishPath(value) {
|
|
291
|
+
assertPackagePath(value);
|
|
292
|
+
if (value.split("/").some((part) => part.toLowerCase() === ".git"))
|
|
293
|
+
throw new Error("\u53D1\u5E03\u6587\u4EF6\u4E0D\u80FD\u8986\u76D6 Git \u5143\u6570\u636E");
|
|
294
|
+
}
|
|
295
|
+
var SITE_FIELD_TYPES = /* @__PURE__ */ new Set(["text", "textarea", "url", "select", "switch"]);
|
|
296
|
+
var optionalText = (value, name) => {
|
|
297
|
+
if (value === void 0) return void 0;
|
|
298
|
+
if (typeof value !== "string") throw new Error(`\u7AD9\u70B9\u5B57\u6BB5${name}\u65E0\u6548`);
|
|
299
|
+
return value;
|
|
300
|
+
};
|
|
301
|
+
var requiredText = (value, name) => {
|
|
302
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`\u7AD9\u70B9\u5B57\u6BB5${name}\u65E0\u6548`);
|
|
303
|
+
return value;
|
|
304
|
+
};
|
|
305
|
+
function readSiteFields(value) {
|
|
306
|
+
if (value === void 0) return void 0;
|
|
307
|
+
if (!Array.isArray(value)) throw new Error("\u7AD9\u70B9\u5B57\u6BB5\u5FC5\u987B\u662F\u6570\u7EC4");
|
|
308
|
+
const keys = /* @__PURE__ */ new Set();
|
|
309
|
+
const fields = value.map((raw) => {
|
|
310
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error("\u7AD9\u70B9\u5B57\u6BB5\u65E0\u6548");
|
|
311
|
+
const item = raw;
|
|
312
|
+
if (typeof item.key !== "string" || !/^[a-zA-Z][a-zA-Z0-9_]*$/.test(item.key))
|
|
313
|
+
throw new Error("\u7AD9\u70B9\u5B57\u6BB5 key \u53EA\u80FD\u7531\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u4E0B\u5212\u7EBF\u7EC4\u6210\uFF0C\u4E14\u4EE5\u5B57\u6BCD\u5F00\u5934");
|
|
314
|
+
if (keys.has(item.key)) throw new Error(`\u7AD9\u70B9\u5B57\u6BB5 key \u91CD\u590D\uFF1A${item.key}`);
|
|
315
|
+
keys.add(item.key);
|
|
316
|
+
if (typeof item.type !== "string" || !SITE_FIELD_TYPES.has(item.type))
|
|
317
|
+
throw new Error(`\u7AD9\u70B9\u5B57\u6BB5\u7C7B\u578B\u4E0D\u652F\u6301\uFF1A${String(item.type)}`);
|
|
318
|
+
const base = {
|
|
319
|
+
key: item.key,
|
|
320
|
+
label: requiredText(item.label, "\u540D\u79F0"),
|
|
321
|
+
...item.description === void 0 ? {} : { description: optionalText(item.description, "\u8BF4\u660E") }
|
|
322
|
+
};
|
|
323
|
+
if (item.type === "switch") {
|
|
324
|
+
if (item.default !== void 0 && typeof item.default !== "boolean")
|
|
325
|
+
throw new Error("\u5F00\u5173\u5B57\u6BB5\u9ED8\u8BA4\u503C\u5FC5\u987B\u662F\u5E03\u5C14\u503C");
|
|
326
|
+
return Object.freeze({
|
|
327
|
+
...base,
|
|
328
|
+
type: "switch",
|
|
329
|
+
...item.default === void 0 ? {} : { default: item.default }
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
const fallback = optionalText(item.default, "\u9ED8\u8BA4\u503C");
|
|
333
|
+
if (item.type === "select") {
|
|
334
|
+
if (!Array.isArray(item.options) || !item.options.length) throw new Error("\u4E0B\u62C9\u5B57\u6BB5\u9009\u9879\u65E0\u6548");
|
|
335
|
+
const options = item.options.map((option) => {
|
|
336
|
+
const entry = option ?? {};
|
|
337
|
+
return Object.freeze({
|
|
338
|
+
value: requiredText(entry.value, "\u9009\u9879\u503C"),
|
|
339
|
+
label: requiredText(entry.label, "\u9009\u9879\u540D\u79F0")
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
if (new Set(options.map((option) => option.value)).size !== options.length)
|
|
343
|
+
throw new Error("\u4E0B\u62C9\u5B57\u6BB5\u9009\u9879\u503C\u91CD\u590D");
|
|
344
|
+
if (fallback !== void 0 && !options.some((option) => option.value === fallback))
|
|
345
|
+
throw new Error("\u4E0B\u62C9\u5B57\u6BB5\u9ED8\u8BA4\u503C\u4E0D\u5728\u9009\u9879\u4E2D");
|
|
346
|
+
return Object.freeze({
|
|
347
|
+
...base,
|
|
348
|
+
type: "select",
|
|
349
|
+
options: Object.freeze(options),
|
|
350
|
+
...fallback === void 0 ? {} : { default: fallback }
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
const placeholder = optionalText(item.placeholder, "\u5360\u4F4D\u6587\u5B57");
|
|
354
|
+
return Object.freeze({
|
|
355
|
+
...base,
|
|
356
|
+
type: item.type,
|
|
357
|
+
...placeholder === void 0 ? {} : { placeholder },
|
|
358
|
+
...fallback === void 0 ? {} : { default: fallback }
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
return Object.freeze(fields);
|
|
362
|
+
}
|
|
363
|
+
function isTemplateManifest(value) {
|
|
364
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && "template" in value;
|
|
365
|
+
}
|
|
366
|
+
function readStaticIdentity(item) {
|
|
367
|
+
const identity = readPluginIdentity(item);
|
|
368
|
+
if (item.minAppVersion !== void 0) {
|
|
369
|
+
if (typeof item.minAppVersion !== "string") throw new Error("\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C\u65E0\u6548");
|
|
370
|
+
comparePluginVersions(item.minAppVersion, item.minAppVersion);
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
...identity,
|
|
374
|
+
...typeof item.minAppVersion === "string" ? { minAppVersion: item.minAppVersion } : {}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function validateSkillPackageManifest(value) {
|
|
378
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
379
|
+
throw new Error("Skill \u5305\u6E05\u5355\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
380
|
+
const item = value;
|
|
381
|
+
if (item.formatVersion === 4) {
|
|
382
|
+
const manifest = validateUnifiedPackageManifest(item);
|
|
383
|
+
if (manifest.kind !== "skills") throw new Error("\u5305\u7C7B\u578B\u4E0D\u662F\u72EC\u7ACB Skill");
|
|
384
|
+
return manifest;
|
|
385
|
+
}
|
|
386
|
+
if (item.formatVersion !== 1 || item.apiVersion !== 1 || !["desktop", "portable"].includes(String(item.platform)))
|
|
387
|
+
throw new Error("Skill \u5305\u683C\u5F0F\u3001API \u7248\u672C\u6216\u5E73\u53F0\u4E0D\u517C\u5BB9");
|
|
388
|
+
const codeFields = item.platform === "portable" ? ["main", "format", "profile", "styles", "backend", "template"] : ["main", "template"];
|
|
389
|
+
if (codeFields.some((field) => Object.hasOwn(item, field)))
|
|
390
|
+
throw new Error("\u72EC\u7ACB Skill \u5305\u4E0D\u80FD\u5305\u542B\u4EE3\u7801\u5165\u53E3\u6216\u6A21\u677F\u5B57\u6BB5");
|
|
391
|
+
const skills = readSkillsField(item.skills);
|
|
392
|
+
if (!skills) throw new Error("Skill \u5305\u81F3\u5C11\u58F0\u660E\u4E00\u4E2A Skill");
|
|
393
|
+
if (!item.integrity || typeof item.integrity !== "object" || Array.isArray(item.integrity))
|
|
394
|
+
throw new Error("Skill \u5305\u7F3A\u5C11\u6458\u8981\u6E05\u5355");
|
|
395
|
+
const integrity = readSkillFiles(skills, item.integrity);
|
|
396
|
+
if (Object.keys(integrity).length !== Object.keys(item.integrity).length)
|
|
397
|
+
throw new Error("Skill \u5305\u53EA\u80FD\u5305\u542B\u5DF2\u58F0\u660E Skill \u76EE\u5F55\u5185\u7684\u6587\u4EF6");
|
|
398
|
+
const common = {
|
|
399
|
+
formatVersion: 1,
|
|
400
|
+
apiVersion: 1,
|
|
401
|
+
...readPluginIdentity(item),
|
|
402
|
+
...readCatalogFields(item),
|
|
403
|
+
skills,
|
|
404
|
+
integrity: Object.freeze(integrity)
|
|
405
|
+
};
|
|
406
|
+
return item.platform === "portable" ? Object.freeze({
|
|
407
|
+
...common,
|
|
408
|
+
platform: "portable",
|
|
409
|
+
targets: readPackageTargets(item.targets)
|
|
410
|
+
}) : Object.freeze({ ...common, ...readStaticIdentity(item), platform: "desktop" });
|
|
411
|
+
}
|
|
412
|
+
function validateDistributionManifest(value) {
|
|
413
|
+
if (value && typeof value === "object" && "formatVersion" in value) {
|
|
414
|
+
if (value.formatVersion === 4) return validateUnifiedPackageManifest(value);
|
|
415
|
+
if (value.formatVersion === 3) return validatePortablePluginManifest(value);
|
|
416
|
+
}
|
|
417
|
+
if (value && typeof value === "object" && "skills" in value && !("template" in value) && !("main" in value))
|
|
418
|
+
return validateSkillPackageManifest(value);
|
|
419
|
+
if (!value || typeof value !== "object" || !("template" in value))
|
|
420
|
+
return validatePluginManifest(value);
|
|
421
|
+
const item = value;
|
|
422
|
+
const template = item.template;
|
|
423
|
+
if (item.formatVersion !== 1 || item.apiVersion !== 1 || item.platform !== "desktop" || !template || template.protocolVersion !== 1)
|
|
424
|
+
throw new Error("\u6A21\u677F\u534F\u8BAE\u7248\u672C\u4E0D\u517C\u5BB9");
|
|
425
|
+
const identity = readStaticIdentity(item);
|
|
426
|
+
assertPackagePath(template.root);
|
|
427
|
+
if (!Array.isArray(template.entries) || !template.entries.length || new Set(template.entries).size !== template.entries.length)
|
|
428
|
+
throw new Error("\u6A21\u677F\u5165\u53E3\u65E0\u6548");
|
|
429
|
+
const entries = template.entries.map((entry) => {
|
|
430
|
+
assertPackagePath(entry);
|
|
431
|
+
if (!entry.endsWith(".html")) throw new Error("\u6A21\u677F\u5165\u53E3\u5FC5\u987B\u662F\u5DF2\u6709 HTML");
|
|
432
|
+
return entry;
|
|
433
|
+
});
|
|
434
|
+
if (!item.integrity || typeof item.integrity !== "object" || Array.isArray(item.integrity))
|
|
435
|
+
throw new Error("\u6A21\u677F\u8D44\u6E90\u7F3A\u5C11\u6458\u8981\u6E05\u5355");
|
|
436
|
+
const integrity = /* @__PURE__ */ Object.create(null);
|
|
437
|
+
for (const [name, digest] of Object.entries(item.integrity)) {
|
|
438
|
+
assertPackagePath(name);
|
|
439
|
+
if (!name.startsWith(template.root + "/") || typeof digest !== "string" || !/^[a-f0-9]{64}$/.test(digest))
|
|
440
|
+
throw new Error("\u6A21\u677F\u8D44\u4EA7\u8DEF\u5F84\u6216\u6458\u8981\u65E0\u6548");
|
|
441
|
+
assertPublishPath(name.slice(template.root.length + 1));
|
|
442
|
+
integrity[name] = digest;
|
|
443
|
+
}
|
|
444
|
+
for (const entry of entries)
|
|
445
|
+
if (!integrity[template.root + "/" + entry]) throw new Error("\u6A21\u677F\u5165\u53E3\u672A\u5305\u542B\u5728\u6458\u8981\u6E05\u5355");
|
|
446
|
+
const siteFields = readSiteFields(template.siteFields);
|
|
447
|
+
const catalog = readCatalogFields(item);
|
|
448
|
+
return Object.freeze({
|
|
449
|
+
formatVersion: 1,
|
|
450
|
+
apiVersion: 1,
|
|
451
|
+
platform: "desktop",
|
|
452
|
+
...identity,
|
|
453
|
+
...catalog,
|
|
454
|
+
template: Object.freeze({
|
|
455
|
+
protocolVersion: 1,
|
|
456
|
+
root: template.root,
|
|
457
|
+
entries: Object.freeze(entries),
|
|
458
|
+
...siteFields ? { siteFields } : {}
|
|
459
|
+
}),
|
|
460
|
+
integrity: Object.freeze(integrity)
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// packages/plugins/src/unified.ts
|
|
465
|
+
var PACKAGE_FORMAT_MIN_VERSIONS = {
|
|
466
|
+
desktop: "0.66.3",
|
|
467
|
+
android: "0.5.1",
|
|
468
|
+
ios: "0.5.1"
|
|
469
|
+
};
|
|
470
|
+
function record(value) {
|
|
471
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
472
|
+
throw new Error("\u5305\u6E05\u5355\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
function readUnifiedHeader(item) {
|
|
476
|
+
if (item.formatVersion !== 4 || item.apiVersion !== 1 || item.platform !== "portable")
|
|
477
|
+
throw new Error("\u5305\u683C\u5F0F\u6216 API \u7248\u672C\u4E0D\u517C\u5BB9");
|
|
478
|
+
const targets = readPackageTargets(item.targets);
|
|
479
|
+
for (const platform of ["desktop", "android", "ios"]) {
|
|
480
|
+
const target = targets[platform];
|
|
481
|
+
if (target && comparePluginVersions(target.minAppVersion, PACKAGE_FORMAT_MIN_VERSIONS[platform]) < 0)
|
|
482
|
+
throw new Error(
|
|
483
|
+
`\u683C\u5F0F 4 \u5728 ${platform} \u8981\u6C42\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C ${PACKAGE_FORMAT_MIN_VERSIONS[platform]}`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
formatVersion: 4,
|
|
488
|
+
platform: "portable",
|
|
489
|
+
targets,
|
|
490
|
+
...typeof item.description === "string" ? { description: item.description } : {}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function validateUnifiedPluginManifest(value) {
|
|
494
|
+
const item = record(value);
|
|
495
|
+
const header = readUnifiedHeader(item);
|
|
496
|
+
if (item.kind !== "plugin" || item.format !== "cjs")
|
|
497
|
+
throw new Error("\u5E94\u7528\u63D2\u4EF6\u7C7B\u578B\u6216\u5165\u53E3\u683C\u5F0F\u4E0D\u517C\u5BB9");
|
|
498
|
+
if (item.profile !== "web-v1" && item.profile !== "desktop-v1")
|
|
499
|
+
throw new Error("\u63D2\u4EF6\u8FD0\u884C\u914D\u7F6E\u4E0D\u517C\u5BB9");
|
|
500
|
+
const metadata = readPluginMetadata(item);
|
|
501
|
+
const main = readPluginFilePath(item.main, ".js");
|
|
502
|
+
const styles = item.styles === void 0 ? void 0 : readPluginFilePath(item.styles, ".css");
|
|
503
|
+
const backend = item.backend === void 0 ? void 0 : validateBackendManifest(item.backend);
|
|
504
|
+
if (item.profile === "web-v1" && backend) throw new Error("Web \u8FD0\u884C\u914D\u7F6E\u4E0D\u80FD\u5305\u542B\u672C\u673A\u540E\u53F0");
|
|
505
|
+
if (item.profile === "desktop-v1" && (!backend || !header.targets.desktop || header.targets.android || header.targets.ios))
|
|
506
|
+
throw new Error("\u672C\u673A\u540E\u53F0\u5FC5\u987B\u58F0\u660E\u684C\u9762\u76EE\u6807\uFF0C\u4E0D\u80FD\u58F0\u660E\u79FB\u52A8\u76EE\u6807");
|
|
507
|
+
if (backend?.entry === main) throw new Error("\u540E\u53F0\u5165\u53E3\u4E0D\u80FD\u4E0E\u6E32\u67D3\u5165\u53E3\u76F8\u540C");
|
|
508
|
+
const files = readPluginFiles(item, [
|
|
509
|
+
main,
|
|
510
|
+
...styles ? [styles] : [],
|
|
511
|
+
...backend ? [backend.entry] : []
|
|
512
|
+
]);
|
|
513
|
+
if (Object.keys(item.integrity).some(
|
|
514
|
+
(file) => !Object.hasOwn(files.integrity, file)
|
|
515
|
+
))
|
|
516
|
+
throw new Error("\u63D2\u4EF6\u5305\u5305\u542B\u672A\u58F0\u660E\u6587\u4EF6");
|
|
517
|
+
const common = {
|
|
518
|
+
...metadata,
|
|
519
|
+
...header,
|
|
520
|
+
apiVersion: 1,
|
|
521
|
+
kind: "plugin",
|
|
522
|
+
format: "cjs",
|
|
523
|
+
main,
|
|
524
|
+
...styles ? { styles } : {},
|
|
525
|
+
...files
|
|
526
|
+
};
|
|
527
|
+
if (backend) return Object.freeze({ ...common, profile: "desktop-v1", backend });
|
|
528
|
+
return Object.freeze({ ...common, profile: "web-v1" });
|
|
529
|
+
}
|
|
530
|
+
function validateUnifiedPackageManifest(value) {
|
|
531
|
+
const item = record(value);
|
|
532
|
+
const header = readUnifiedHeader(item);
|
|
533
|
+
if (item.kind === "plugin") return validateUnifiedPluginManifest(item);
|
|
534
|
+
if (item.kind === "skills") {
|
|
535
|
+
const parsed = validateSkillPackageManifest({
|
|
536
|
+
...item,
|
|
537
|
+
formatVersion: 1,
|
|
538
|
+
platform: "portable"
|
|
539
|
+
});
|
|
540
|
+
if (parsed.platform !== "portable") throw new Error("Skill \u5305\u7F3A\u5C11\u76EE\u6807\u5E73\u53F0");
|
|
541
|
+
return Object.freeze({ ...parsed, ...header, kind: "skills" });
|
|
542
|
+
}
|
|
543
|
+
if (item.kind === "template") {
|
|
544
|
+
if (!header.targets.desktop || header.targets.android || header.targets.ios)
|
|
545
|
+
throw new Error("\u6A21\u677F\u4EC5\u652F\u6301\u684C\u9762\u76EE\u6807");
|
|
546
|
+
const parsed = validateDistributionManifest({
|
|
547
|
+
...item,
|
|
548
|
+
formatVersion: 1,
|
|
549
|
+
platform: "desktop",
|
|
550
|
+
minAppVersion: header.targets.desktop.minAppVersion
|
|
551
|
+
});
|
|
552
|
+
if (!isTemplateManifest(parsed)) throw new Error("\u6A21\u677F\u6E05\u5355\u65E0\u6548");
|
|
553
|
+
const { id, name, version, apiVersion, template, integrity, categories, keywords } = parsed;
|
|
554
|
+
return Object.freeze({
|
|
555
|
+
id,
|
|
556
|
+
name,
|
|
557
|
+
version,
|
|
558
|
+
apiVersion,
|
|
559
|
+
...header,
|
|
560
|
+
kind: "template",
|
|
561
|
+
template,
|
|
562
|
+
integrity,
|
|
563
|
+
...categories ? { categories } : {},
|
|
564
|
+
...keywords ? { keywords } : {}
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
throw new Error("\u5305\u7C7B\u578B\u65E0\u6548");
|
|
568
|
+
}
|
|
569
|
+
function buildUnifiedPluginManifest(value, output) {
|
|
570
|
+
const item = record(value);
|
|
571
|
+
if (item.kind !== void 0 && item.kind !== "plugin") throw new Error("\u4EE3\u7801\u5165\u53E3\u4E0E\u5305\u7C7B\u578B\u4E0D\u5339\u914D");
|
|
572
|
+
const manifest = validateUnifiedPluginManifest({
|
|
573
|
+
...item,
|
|
574
|
+
...output,
|
|
575
|
+
formatVersion: 4,
|
|
576
|
+
platform: "portable",
|
|
577
|
+
apiVersion: 1,
|
|
578
|
+
kind: "plugin",
|
|
579
|
+
format: "cjs",
|
|
580
|
+
profile: item.backend ? "desktop-v1" : "web-v1",
|
|
581
|
+
targets: authorTargets(item)
|
|
582
|
+
});
|
|
583
|
+
assertMobilePermissions(manifest);
|
|
584
|
+
return manifest;
|
|
585
|
+
}
|
|
586
|
+
function authorTargets(item) {
|
|
587
|
+
const targets = readPackageTargets(
|
|
588
|
+
item.targets ?? (typeof item.minAppVersion === "string" ? { desktop: { minAppVersion: item.minAppVersion } } : void 0)
|
|
589
|
+
);
|
|
590
|
+
return Object.fromEntries(
|
|
591
|
+
Object.entries(targets).map(([platform, target]) => [
|
|
592
|
+
platform,
|
|
593
|
+
{
|
|
594
|
+
minAppVersion: comparePluginVersions(
|
|
595
|
+
target.minAppVersion,
|
|
596
|
+
PACKAGE_FORMAT_MIN_VERSIONS[platform]
|
|
597
|
+
) < 0 ? PACKAGE_FORMAT_MIN_VERSIONS[platform] : target.minAppVersion
|
|
598
|
+
}
|
|
599
|
+
])
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
function buildUnifiedPackageManifest(value, output) {
|
|
603
|
+
const item = record(value);
|
|
604
|
+
if (output.main) return buildUnifiedPluginManifest(item, { ...output, main: output.main });
|
|
605
|
+
return validateUnifiedPackageManifest({
|
|
606
|
+
...item,
|
|
607
|
+
...output,
|
|
608
|
+
formatVersion: 4,
|
|
609
|
+
platform: "portable",
|
|
610
|
+
apiVersion: 1,
|
|
611
|
+
kind: item.kind ?? (item.template ? "template" : "skills"),
|
|
612
|
+
targets: authorTargets(item)
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
function packageTargets(manifest) {
|
|
616
|
+
return manifest.platform === "portable" ? manifest.targets ?? {} : { desktop: { minAppVersion: manifest.minAppVersion ?? "0.0.0" } };
|
|
617
|
+
}
|
|
618
|
+
function isWebPluginManifest(manifest) {
|
|
619
|
+
return "profile" in manifest && manifest.profile === "web-v1";
|
|
620
|
+
}
|
|
621
|
+
function readApplicationPluginManifest(value) {
|
|
622
|
+
const item = record(value);
|
|
623
|
+
if (item.formatVersion === 4) return validateUnifiedPluginManifest(item);
|
|
624
|
+
if (item.formatVersion === 3) return validatePortablePluginManifest(item);
|
|
625
|
+
return validatePluginManifest(item);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// packages/plugins/src/package.ts
|
|
629
|
+
var PLUGIN_SHARED_MODULES = [
|
|
630
|
+
"@tau/plugins",
|
|
631
|
+
"@tau/plugins/whiteboard",
|
|
632
|
+
"@tau/plugins/sync",
|
|
633
|
+
"@tau/ui",
|
|
634
|
+
"react",
|
|
635
|
+
"react-dom",
|
|
636
|
+
"react-dom/client",
|
|
637
|
+
"react/jsx-runtime",
|
|
638
|
+
"react/jsx-dev-runtime"
|
|
639
|
+
];
|
|
640
|
+
function validatePluginManifest(value) {
|
|
641
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
642
|
+
throw new Error("\u63D2\u4EF6\u6E05\u5355\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
643
|
+
const item = value;
|
|
644
|
+
if (item.formatVersion === 4) {
|
|
645
|
+
const manifest = validateUnifiedPluginManifest(item);
|
|
646
|
+
if (manifest.profile !== "desktop-v1") throw new Error("\u63D2\u4EF6\u672A\u58F0\u660E\u684C\u9762\u540E\u53F0\u8FD0\u884C\u914D\u7F6E");
|
|
647
|
+
return manifest;
|
|
648
|
+
}
|
|
649
|
+
if (item.formatVersion !== 2 || item.apiVersion !== 1 || item.platform !== "desktop" || item.format !== "cjs")
|
|
650
|
+
throw new Error("\u63D2\u4EF6\u5305\u683C\u5F0F\u3001API \u7248\u672C\u6216\u5E73\u53F0\u4E0D\u517C\u5BB9");
|
|
651
|
+
const metadata = readPluginMetadata(item);
|
|
652
|
+
const main = readPluginFilePath(item.main, ".js");
|
|
653
|
+
const backend = item.backend === void 0 ? void 0 : validateBackendManifest(item.backend);
|
|
654
|
+
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");
|
|
655
|
+
if (backend?.entry === main) throw new Error("\u540E\u53F0\u5165\u53E3\u4E0D\u80FD\u4E0E\u6E32\u67D3\u5165\u53E3\u76F8\u540C");
|
|
656
|
+
if (backend && typeof item.minAppVersion !== "string")
|
|
657
|
+
throw new Error("\u540E\u53F0\u63D2\u4EF6\u5FC5\u987B\u58F0\u660E\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C");
|
|
658
|
+
if (item.minAppVersion !== void 0) {
|
|
659
|
+
if (typeof item.minAppVersion !== "string") throw new Error("\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C\u65E0\u6548");
|
|
660
|
+
comparePluginVersions(item.minAppVersion, item.minAppVersion);
|
|
661
|
+
}
|
|
662
|
+
const styles = item.styles === void 0 ? void 0 : readPluginFilePath(item.styles, ".css");
|
|
663
|
+
const files = readPluginFiles(item, [
|
|
664
|
+
main,
|
|
665
|
+
...styles ? [styles] : [],
|
|
666
|
+
...backend ? [backend.entry] : []
|
|
667
|
+
]);
|
|
668
|
+
return Object.freeze({
|
|
669
|
+
formatVersion: item.formatVersion,
|
|
670
|
+
...metadata,
|
|
671
|
+
...typeof item.minAppVersion === "string" ? { minAppVersion: item.minAppVersion } : {},
|
|
672
|
+
apiVersion: 1,
|
|
673
|
+
platform: "desktop",
|
|
674
|
+
format: "cjs",
|
|
675
|
+
main,
|
|
676
|
+
...backend ? { backend } : {},
|
|
677
|
+
...item.editor === true ? { editor: true } : {},
|
|
678
|
+
...item.whiteboard === true ? { whiteboard: true } : {},
|
|
679
|
+
...files,
|
|
680
|
+
...styles === void 0 ? {} : { styles }
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
var isContentPlugin = (manifest) => manifest.editor === true || manifest.whiteboard === true;
|
|
684
|
+
|
|
685
|
+
// packages/plugins/src/portable.ts
|
|
686
|
+
var MOBILE_DATA_MIN_VERSION = "0.2.13";
|
|
687
|
+
var MOBILE_AI_MIN_VERSION = "0.2.13";
|
|
688
|
+
var MOBILE_AI_PERMISSIONS = Object.freeze(
|
|
689
|
+
Object.keys(PLUGIN_AI_CAPABILITIES).map(
|
|
690
|
+
(capability) => `ai:${capability}`
|
|
691
|
+
)
|
|
692
|
+
);
|
|
693
|
+
var MOBILE_DATA_PERMISSIONS = [
|
|
694
|
+
"cards:read",
|
|
695
|
+
"cards:write",
|
|
696
|
+
"cards:delete",
|
|
697
|
+
"articles:read",
|
|
698
|
+
"articles:write",
|
|
699
|
+
"articles:delete",
|
|
700
|
+
"projects:read",
|
|
701
|
+
"projects:write",
|
|
702
|
+
"projects:delete",
|
|
703
|
+
"documents:read",
|
|
704
|
+
"documents:write",
|
|
705
|
+
"documents:delete",
|
|
706
|
+
"todos:read",
|
|
707
|
+
"todos:write",
|
|
708
|
+
"todos:delete",
|
|
709
|
+
"calendar:read",
|
|
710
|
+
"calendar:write",
|
|
711
|
+
"calendar:delete",
|
|
712
|
+
"flashcards:read",
|
|
713
|
+
"flashcards:write"
|
|
714
|
+
];
|
|
715
|
+
var MOBILE_SPEECH_MIN_VERSION = "0.2.16";
|
|
716
|
+
var MOBILE_SPEECH_PERMISSIONS = ["speech:input"];
|
|
717
|
+
function assertMobilePermissions(manifest) {
|
|
718
|
+
if (!manifest.permissions?.length) return;
|
|
719
|
+
for (const platform of ["android", "ios"]) {
|
|
720
|
+
const target = manifest.targets[platform];
|
|
721
|
+
if (!target) continue;
|
|
722
|
+
if (manifest.permissions.some(
|
|
723
|
+
(permission) => !MOBILE_DATA_PERMISSIONS.includes(permission) && !MOBILE_AI_PERMISSIONS.includes(permission) && !MOBILE_SPEECH_PERMISSIONS.includes(permission)
|
|
724
|
+
))
|
|
725
|
+
throw new Error("\u79FB\u52A8\u7AEF\u5C1A\u672A\u5F00\u653E\u6B64\u4E1A\u52A1\u6743\u9650");
|
|
726
|
+
if (manifest.permissions.some(
|
|
727
|
+
(permission) => MOBILE_DATA_PERMISSIONS.includes(permission)
|
|
728
|
+
) && comparePluginVersions(target.minAppVersion, MOBILE_DATA_MIN_VERSION) < 0)
|
|
729
|
+
throw new Error(`\u79FB\u52A8\u7AEF\u4E1A\u52A1\u6570\u636E\u6388\u6743\u8981\u6C42\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C ${MOBILE_DATA_MIN_VERSION}`);
|
|
730
|
+
if (manifest.permissions.some(
|
|
731
|
+
(permission) => MOBILE_AI_PERMISSIONS.includes(permission)
|
|
732
|
+
) && comparePluginVersions(target.minAppVersion, MOBILE_AI_MIN_VERSION) < 0)
|
|
733
|
+
throw new Error(`\u79FB\u52A8\u7AEF AI \u6388\u6743\u8981\u6C42\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C ${MOBILE_AI_MIN_VERSION}`);
|
|
734
|
+
if (manifest.permissions.some(
|
|
735
|
+
(permission) => MOBILE_SPEECH_PERMISSIONS.includes(permission)
|
|
736
|
+
) && comparePluginVersions(target.minAppVersion, MOBILE_SPEECH_MIN_VERSION) < 0)
|
|
737
|
+
throw new Error(`\u79FB\u52A8\u7AEF\u8BED\u97F3\u8F93\u5165\u6388\u6743\u8981\u6C42\u6700\u4F4E\u5BA2\u6237\u7AEF\u7248\u672C ${MOBILE_SPEECH_MIN_VERSION}`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
var PORTABLE_PLATFORMS = PACKAGE_PLATFORMS;
|
|
741
|
+
var PORTABLE_SHARED_MODULES = [
|
|
742
|
+
"@tau/plugins",
|
|
743
|
+
"@tau/plugins/whiteboard",
|
|
744
|
+
"@tau/ui",
|
|
745
|
+
"react",
|
|
746
|
+
"react-dom",
|
|
747
|
+
"react-dom/client",
|
|
748
|
+
"react/jsx-runtime",
|
|
749
|
+
"react/jsx-dev-runtime"
|
|
750
|
+
];
|
|
751
|
+
function buildPortablePluginManifest(value, output) {
|
|
752
|
+
const item = record2(value, "\u4F5C\u8005\u6E05\u5355");
|
|
753
|
+
const files = record2(output, "\u6784\u5EFA\u6587\u4EF6\u4FE1\u606F");
|
|
754
|
+
return validatePortableDistributionManifest({
|
|
755
|
+
id: item.id,
|
|
756
|
+
name: item.name,
|
|
757
|
+
version: item.version,
|
|
758
|
+
description: item.description,
|
|
759
|
+
categories: item.categories,
|
|
760
|
+
keywords: item.keywords,
|
|
761
|
+
permissions: item.permissions,
|
|
762
|
+
formatVersion: 3,
|
|
763
|
+
apiVersion: 1,
|
|
764
|
+
platform: "portable",
|
|
765
|
+
profile: "web-v1",
|
|
766
|
+
format: "cjs",
|
|
767
|
+
main: files.main,
|
|
768
|
+
styles: files.styles,
|
|
769
|
+
skills: files.skills,
|
|
770
|
+
integrity: files.integrity,
|
|
771
|
+
targets: item.targets
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
function record2(value, label) {
|
|
775
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
776
|
+
throw new Error(`${label}\u5FC5\u987B\u662F\u5BF9\u8C61`);
|
|
777
|
+
return value;
|
|
778
|
+
}
|
|
779
|
+
function validatePortableDistributionManifest(value) {
|
|
780
|
+
const manifest = validatePortablePluginManifest(value);
|
|
781
|
+
assertMobilePermissions(manifest);
|
|
782
|
+
return manifest;
|
|
783
|
+
}
|
|
784
|
+
function validatePortablePluginManifest(value) {
|
|
785
|
+
const item = record2(value, "\u8DE8\u7AEF\u6E05\u5355");
|
|
786
|
+
if (item.formatVersion === 4) {
|
|
787
|
+
const manifest = validateUnifiedPluginManifest(item);
|
|
788
|
+
if (manifest.profile !== "web-v1") throw new Error("\u5F53\u524D\u5BBF\u4E3B\u4E0D\u652F\u6301\u672C\u673A\u540E\u53F0\u8FD0\u884C\u914D\u7F6E");
|
|
789
|
+
return manifest;
|
|
790
|
+
}
|
|
791
|
+
if (item.formatVersion !== 3 || item.platform !== "portable" || item.profile !== "web-v1")
|
|
792
|
+
throw new Error("\u8DE8\u7AEF\u5305\u683C\u5F0F\u6216\u8FD0\u884C\u914D\u7F6E\u4E0D\u517C\u5BB9");
|
|
793
|
+
if (item.apiVersion !== 1 || item.format !== "cjs") throw new Error("\u63D2\u4EF6 API \u6216\u5165\u53E3\u683C\u5F0F\u4E0D\u517C\u5BB9");
|
|
794
|
+
const metadata = readPluginMetadata(item);
|
|
795
|
+
const main = readPluginFilePath(item.main, ".js");
|
|
796
|
+
const styles = item.styles === void 0 ? void 0 : readPluginFilePath(item.styles, ".css");
|
|
797
|
+
const files = readPluginFiles(item, [main, ...styles ? [styles] : []]);
|
|
798
|
+
const targets = readPackageTargets(item.targets);
|
|
799
|
+
const declaredFiles = item.integrity;
|
|
800
|
+
if (Object.keys(declaredFiles).some((file) => !Object.hasOwn(files.integrity, file)))
|
|
801
|
+
throw new Error("\u8DE8\u7AEF\u5305\u5305\u542B\u672A\u58F0\u660E\u6587\u4EF6");
|
|
802
|
+
for (const file of Object.keys(files.integrity)) {
|
|
803
|
+
if (file === main || file === styles) continue;
|
|
804
|
+
if (!file.endsWith(".md") || file.split("/").includes("scripts") || file.includes("\\"))
|
|
805
|
+
throw new Error("\u8DE8\u7AEF Skill \u4EC5\u652F\u6301\u7EAF Markdown \u6587\u6863\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u9644\u4EF6");
|
|
806
|
+
}
|
|
807
|
+
return Object.freeze({
|
|
808
|
+
...metadata,
|
|
809
|
+
apiVersion: 1,
|
|
810
|
+
format: "cjs",
|
|
811
|
+
main,
|
|
812
|
+
...styles ? { styles } : {},
|
|
813
|
+
...files,
|
|
814
|
+
formatVersion: 3,
|
|
815
|
+
platform: "portable",
|
|
816
|
+
profile: "web-v1",
|
|
817
|
+
...typeof item.description === "string" ? { description: item.description } : {},
|
|
818
|
+
targets: Object.freeze(targets)
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
function assertPortablePluginCompatibility(manifest, host) {
|
|
822
|
+
if (!host.profiles.includes(manifest.profile)) throw new Error("\u5BBF\u4E3B\u672A\u63A5\u5165\u8DE8\u7AEF\u8FD0\u884C\u914D\u7F6E");
|
|
823
|
+
const platform = host.environment.platform;
|
|
824
|
+
if (!PORTABLE_PLATFORMS.some((value) => value === platform))
|
|
825
|
+
throw new Error("\u5F53\u524D\u5E73\u53F0\u4E0D\u80FD\u6FC0\u6D3B\u8DE8\u7AEF\u5E94\u7528\u63D2\u4EF6");
|
|
826
|
+
const target = manifest.targets[platform];
|
|
827
|
+
if (!target) throw new Error("\u63D2\u4EF6\u4E0D\u652F\u6301\u5F53\u524D\u5E73\u53F0");
|
|
828
|
+
if (platform === "android" || platform === "ios") assertMobilePermissions(manifest);
|
|
829
|
+
if (comparePluginVersions(host.appVersion, target.minAppVersion) < 0)
|
|
830
|
+
throw new Error("\u5BA2\u6237\u7AEF\u7248\u672C\u4F4E\u4E8E\u63D2\u4EF6\u8981\u6C42");
|
|
831
|
+
return target;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
export {
|
|
835
|
+
assertLocalId,
|
|
836
|
+
comparePluginVersions,
|
|
837
|
+
PLUGIN_SYSTEM_ACCESS,
|
|
838
|
+
validateBackendManifest,
|
|
839
|
+
PLUGIN_CATEGORIES,
|
|
840
|
+
isPluginCategory,
|
|
841
|
+
PLUGIN_AI_CAPABILITIES,
|
|
842
|
+
isPluginAICapability,
|
|
843
|
+
PLUGIN_PERMISSIONS,
|
|
844
|
+
isPluginPermission,
|
|
845
|
+
MOBILE_DATA_MIN_VERSION,
|
|
846
|
+
MOBILE_AI_MIN_VERSION,
|
|
847
|
+
MOBILE_AI_PERMISSIONS,
|
|
848
|
+
MOBILE_DATA_PERMISSIONS,
|
|
849
|
+
MOBILE_SPEECH_MIN_VERSION,
|
|
850
|
+
MOBILE_SPEECH_PERMISSIONS,
|
|
851
|
+
assertMobilePermissions,
|
|
852
|
+
PORTABLE_PLATFORMS,
|
|
853
|
+
PORTABLE_SHARED_MODULES,
|
|
854
|
+
buildPortablePluginManifest,
|
|
855
|
+
validatePortableDistributionManifest,
|
|
856
|
+
validatePortablePluginManifest,
|
|
857
|
+
assertPortablePluginCompatibility,
|
|
858
|
+
PACKAGE_FORMAT_MIN_VERSIONS,
|
|
859
|
+
validateUnifiedPluginManifest,
|
|
860
|
+
validateUnifiedPackageManifest,
|
|
861
|
+
buildUnifiedPluginManifest,
|
|
862
|
+
buildUnifiedPackageManifest,
|
|
863
|
+
packageTargets,
|
|
864
|
+
isWebPluginManifest,
|
|
865
|
+
readApplicationPluginManifest,
|
|
866
|
+
PLUGIN_SHARED_MODULES,
|
|
867
|
+
validatePluginManifest,
|
|
868
|
+
isContentPlugin
|
|
869
|
+
};
|