@tano.page/protocol 0.14.0 → 0.16.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/manifest.schema.json +448 -0
  2. package/package.json +21 -4
  3. package/src/appearance.ts +19 -4
  4. package/src/assistant.ts +35 -4
  5. package/src/domain/agent-identities.ts +110 -0
  6. package/src/domain/agent-inbox.ts +148 -0
  7. package/src/domain/assistant-completion.ts +61 -0
  8. package/src/domain/assistant-engine.ts +614 -0
  9. package/src/domain/assistant-execution.ts +43 -0
  10. package/src/domain/assistant-files.ts +19 -0
  11. package/src/domain/assistant-history.ts +90 -0
  12. package/src/domain/assistant-language.ts +112 -0
  13. package/src/domain/assistant-prompts.ts +70 -0
  14. package/src/domain/assistant-structures.ts +179 -0
  15. package/src/domain/assistant-task-prompts.json +39 -0
  16. package/src/domain/assistant-tasks.ts +114 -0
  17. package/src/domain/locales/de-DE.json +129 -0
  18. package/src/domain/locales/en-US.json +129 -0
  19. package/src/domain/locales/es-ES.json +129 -0
  20. package/src/domain/locales/ja-JP.json +129 -0
  21. package/src/domain/locales/zh-CN.json +129 -0
  22. package/src/domain/locales/zh-TW.json +129 -0
  23. package/src/domain/plugin-data.ts +175 -0
  24. package/src/domain/plugin-sdk.ts +300 -0
  25. package/src/domain/untrusted-data.ts +17 -0
  26. package/src/domain/workspace-comments.ts +148 -0
  27. package/src/extensions.ts +1100 -19
  28. package/src/frontmatter.ts +60 -1
  29. package/src/index.ts +3 -0
  30. package/src/object-types.ts +30 -20
  31. package/src/objects.ts +3 -4
  32. package/src/plan-item.ts +78 -0
  33. package/src/plugin-archive.ts +395 -0
  34. package/src/plugin-compat.ts +156 -0
  35. package/src/plugins.ts +12 -0
  36. package/src/relations.ts +1 -5
  37. package/src/task-repeat.ts +55 -8
  38. package/src/task-review.ts +11 -2
  39. package/src/view-engine.ts +1 -1
@@ -0,0 +1,448 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://tano.page/schemas/manifest.schema.json",
4
+ "title": "Tano Plugin Manifest",
5
+ "description": "Official JSON Schema for Tano (同页) declarative (manifestVersion 1) and executable code (manifestVersion 2) plugin manifests across Phases 0–4.",
6
+ "oneOf": [
7
+ { "$ref": "#/$defs/declarativeManifest" },
8
+ { "$ref": "#/$defs/executableManifest" }
9
+ ],
10
+ "$defs": {
11
+ "pluginId": {
12
+ "type": "string",
13
+ "pattern": "^[a-z][a-z0-9-]{0,39}$",
14
+ "description": "Lowercase plugin identifier (1–40 chars)."
15
+ },
16
+ "pluginKey": {
17
+ "type": "string",
18
+ "pattern": "^[a-z][a-z0-9.-]{0,79}$"
19
+ },
20
+ "assistantToolName": {
21
+ "type": "string",
22
+ "pattern": "^[a-z][a-z0-9_-]{0,47}$"
23
+ },
24
+ "assistantContextId": {
25
+ "type": "string",
26
+ "pattern": "^[a-z][a-z0-9_-]{0,31}$"
27
+ },
28
+ "serviceName": {
29
+ "type": "string",
30
+ "pattern": "^[a-z][a-z0-9_.-]{0,47}$"
31
+ },
32
+ "semver": {
33
+ "type": "string",
34
+ "pattern": "^\\d+\\.\\d+\\.\\d+$"
35
+ },
36
+ "platform": {
37
+ "type": "string",
38
+ "enum": ["desktop-local", "desktop-online", "web", "mobile"]
39
+ },
40
+ "engines": {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "properties": {
44
+ "tano": {
45
+ "type": "string",
46
+ "pattern": "^>=\\d+\\.\\d+\\.\\d+$",
47
+ "description": "Minimum supported Tano Core semver, e.g. \">=0.15.0\"."
48
+ }
49
+ }
50
+ },
51
+ "permission": {
52
+ "type": "string",
53
+ "enum": [
54
+ "attachments.read",
55
+ "attachments.write",
56
+ "documents.read",
57
+ "documents.write",
58
+ "documents.move",
59
+ "documents.trash",
60
+ "objects.read",
61
+ "objects.write",
62
+ "relations.read",
63
+ "relations.write",
64
+ "storage",
65
+ "network",
66
+ "connections",
67
+ "native",
68
+ "ui",
69
+ "ai.invoke"
70
+ ]
71
+ },
72
+ "menuLocation": {
73
+ "type": "string",
74
+ "enum": ["workspace", "document", "file"]
75
+ },
76
+ "viewLocation": {
77
+ "type": "string",
78
+ "enum": [
79
+ "panel",
80
+ "tab",
81
+ "sidebar",
82
+ "settings",
83
+ "documentSidebar",
84
+ "documentHeader",
85
+ "documentFooter",
86
+ "homeTab",
87
+ "newTab"
88
+ ]
89
+ },
90
+ "viewLayout": {
91
+ "type": "string",
92
+ "enum": ["contained", "fill"]
93
+ },
94
+ "commandDefinition": {
95
+ "type": "object",
96
+ "additionalProperties": false,
97
+ "required": ["id", "label"],
98
+ "properties": {
99
+ "id": { "$ref": "#/$defs/pluginKey" },
100
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
101
+ "shortcut": { "type": "string", "minLength": 1, "maxLength": 40 },
102
+ "menus": {
103
+ "type": "array",
104
+ "items": { "$ref": "#/$defs/menuLocation" },
105
+ "uniqueItems": true
106
+ }
107
+ }
108
+ },
109
+ "slashCommandDefinition": {
110
+ "type": "object",
111
+ "additionalProperties": false,
112
+ "required": ["id", "label", "command"],
113
+ "properties": {
114
+ "id": { "$ref": "#/$defs/pluginKey" },
115
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
116
+ "command": { "$ref": "#/$defs/pluginKey" },
117
+ "description": { "type": "string", "minLength": 1, "maxLength": 120 },
118
+ "keywords": {
119
+ "type": "array",
120
+ "maxItems": 10,
121
+ "uniqueItems": true,
122
+ "items": { "type": "string", "minLength": 1, "maxLength": 40 }
123
+ }
124
+ }
125
+ },
126
+ "viewDefinition": {
127
+ "type": "object",
128
+ "additionalProperties": false,
129
+ "required": ["id", "label"],
130
+ "properties": {
131
+ "id": { "$ref": "#/$defs/pluginKey" },
132
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
133
+ "location": { "$ref": "#/$defs/viewLocation" },
134
+ "layout": { "$ref": "#/$defs/viewLayout" }
135
+ }
136
+ },
137
+ "codeBlockRendererDefinition": {
138
+ "type": "object",
139
+ "additionalProperties": false,
140
+ "required": ["languages", "view"],
141
+ "properties": {
142
+ "languages": {
143
+ "type": "array",
144
+ "minItems": 1,
145
+ "maxItems": 8,
146
+ "uniqueItems": true,
147
+ "items": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,31}$" }
148
+ },
149
+ "view": { "$ref": "#/$defs/pluginKey" },
150
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
151
+ "height": { "type": "integer", "minimum": 120, "maximum": 720 }
152
+ }
153
+ },
154
+ "fileHandlerDefinition": {
155
+ "type": "object",
156
+ "additionalProperties": false,
157
+ "required": ["extensions", "mode", "view", "command"],
158
+ "properties": {
159
+ "extensions": {
160
+ "type": "array",
161
+ "minItems": 1,
162
+ "maxItems": 16,
163
+ "uniqueItems": true,
164
+ "items": { "type": "string", "pattern": "^\\.[a-z0-9][a-z0-9.-]{0,39}$" }
165
+ },
166
+ "mode": { "type": "string", "enum": ["preview", "editor"] },
167
+ "view": { "$ref": "#/$defs/pluginKey" },
168
+ "command": { "$ref": "#/$defs/pluginKey" }
169
+ }
170
+ },
171
+ "assistantToolDefinition": {
172
+ "type": "object",
173
+ "additionalProperties": false,
174
+ "required": ["name", "label", "description", "effect", "parameters"],
175
+ "properties": {
176
+ "name": { "$ref": "#/$defs/assistantToolName" },
177
+ "label": { "type": "string", "minLength": 1, "maxLength": 60 },
178
+ "description": { "type": "string", "minLength": 1, "maxLength": 300 },
179
+ "effect": { "type": "string", "enum": ["read", "write", "external"] },
180
+ "parameters": { "type": "object" }
181
+ }
182
+ },
183
+ "assistantContextProviderDefinition": {
184
+ "type": "object",
185
+ "additionalProperties": false,
186
+ "required": ["id", "label", "description"],
187
+ "properties": {
188
+ "id": { "$ref": "#/$defs/assistantContextId" },
189
+ "label": { "type": "string", "minLength": 1, "maxLength": 60 },
190
+ "description": { "type": "string", "minLength": 1, "maxLength": 200 },
191
+ "maxBytes": { "type": "integer", "minimum": 256, "maximum": 16000 }
192
+ }
193
+ },
194
+ "serviceDefinition": {
195
+ "type": "object",
196
+ "additionalProperties": false,
197
+ "required": ["name", "description"],
198
+ "properties": {
199
+ "name": { "$ref": "#/$defs/serviceName" },
200
+ "description": { "type": "string", "minLength": 1, "maxLength": 240 },
201
+ "parameters": { "type": "object" },
202
+ "returns": { "type": "object" }
203
+ }
204
+ },
205
+ "serviceDependency": {
206
+ "type": "object",
207
+ "additionalProperties": false,
208
+ "required": ["pluginId", "service"],
209
+ "properties": {
210
+ "pluginId": { "$ref": "#/$defs/pluginKey" },
211
+ "service": { "$ref": "#/$defs/serviceName" },
212
+ "optional": { "type": "boolean" }
213
+ }
214
+ },
215
+ "settingField": {
216
+ "type": "object",
217
+ "additionalProperties": false,
218
+ "required": ["key", "label", "type"],
219
+ "properties": {
220
+ "key": { "$ref": "#/$defs/pluginKey" },
221
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
222
+ "description": { "type": "string", "minLength": 1, "maxLength": 200 },
223
+ "type": { "type": "string", "enum": ["string", "number", "boolean", "select"] },
224
+ "default": { "type": ["string", "number", "boolean"] },
225
+ "options": {
226
+ "type": "array",
227
+ "minItems": 1,
228
+ "maxItems": 30,
229
+ "items": {
230
+ "type": "object",
231
+ "additionalProperties": false,
232
+ "required": ["value", "label"],
233
+ "properties": {
234
+ "value": { "type": "string", "minLength": 1, "maxLength": 100 },
235
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 }
236
+ }
237
+ }
238
+ },
239
+ "min": { "type": "number" },
240
+ "max": { "type": "number" },
241
+ "required": { "type": "boolean" }
242
+ }
243
+ },
244
+ "activationEvent": {
245
+ "type": "string",
246
+ "pattern": "^(onStartup|onCommand:[a-z][a-z0-9.-]{0,79}|onView:[a-z][a-z0-9.-]{0,79}|onFile:\\.[a-z0-9][a-z0-9.-]{0,39}|onAssistantTool:[a-z][a-z0-9_-]{0,47}|onAssistantContext:[a-z][a-z0-9_-]{0,31}|onService:[a-z][a-z0-9_.-]{0,47})$"
247
+ },
248
+ "automationDefinition": {
249
+ "type": "object",
250
+ "additionalProperties": false,
251
+ "required": ["id", "label"],
252
+ "properties": {
253
+ "id": { "$ref": "#/$defs/pluginKey" },
254
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 }
255
+ }
256
+ },
257
+ "objectTypeDefinition": {
258
+ "type": "object",
259
+ "required": ["type", "label", "fields"],
260
+ "properties": {
261
+ "type": { "type": "string", "minLength": 1, "maxLength": 80 },
262
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 },
263
+ "fields": { "type": "array" }
264
+ }
265
+ },
266
+ "relationTypeDefinition": {
267
+ "type": "object",
268
+ "required": ["type", "label"],
269
+ "properties": {
270
+ "type": { "type": "string", "minLength": 1, "maxLength": 80 },
271
+ "label": { "type": "string", "minLength": 1, "maxLength": 80 }
272
+ }
273
+ },
274
+ "declarativeManifest": {
275
+ "type": "object",
276
+ "additionalProperties": false,
277
+ "required": [
278
+ "manifestVersion",
279
+ "id",
280
+ "name",
281
+ "version",
282
+ "description",
283
+ "objectTypes",
284
+ "relationTypes"
285
+ ],
286
+ "properties": {
287
+ "$schema": { "type": "string" },
288
+ "manifestVersion": { "const": 1 },
289
+ "id": { "$ref": "#/$defs/pluginId" },
290
+ "name": { "type": "string", "minLength": 1, "maxLength": 80 },
291
+ "version": { "$ref": "#/$defs/semver" },
292
+ "description": { "type": "string", "maxLength": 2000 },
293
+ "engines": { "$ref": "#/$defs/engines" },
294
+ "platforms": {
295
+ "type": "array",
296
+ "minItems": 1,
297
+ "uniqueItems": true,
298
+ "items": { "$ref": "#/$defs/platform" }
299
+ },
300
+ "appearance": { "type": "object" },
301
+ "objectTypes": {
302
+ "type": "array",
303
+ "maxItems": 50,
304
+ "items": { "$ref": "#/$defs/objectTypeDefinition" }
305
+ },
306
+ "relationTypes": {
307
+ "type": "array",
308
+ "maxItems": 100,
309
+ "items": { "$ref": "#/$defs/relationTypeDefinition" }
310
+ }
311
+ }
312
+ },
313
+ "executableManifest": {
314
+ "type": "object",
315
+ "additionalProperties": false,
316
+ "required": [
317
+ "manifestVersion",
318
+ "apiVersion",
319
+ "id",
320
+ "name",
321
+ "version",
322
+ "description",
323
+ "objectTypes",
324
+ "relationTypes",
325
+ "permissions",
326
+ "networkOrigins",
327
+ "nativeCommands",
328
+ "commands",
329
+ "views"
330
+ ],
331
+ "properties": {
332
+ "$schema": { "type": "string" },
333
+ "manifestVersion": { "const": 2 },
334
+ "apiVersion": { "const": 1 },
335
+ "id": { "$ref": "#/$defs/pluginId" },
336
+ "name": { "type": "string", "minLength": 1, "maxLength": 80 },
337
+ "version": { "$ref": "#/$defs/semver" },
338
+ "description": { "type": "string", "maxLength": 2000 },
339
+ "engines": { "$ref": "#/$defs/engines" },
340
+ "platforms": {
341
+ "type": "array",
342
+ "minItems": 1,
343
+ "uniqueItems": true,
344
+ "items": { "$ref": "#/$defs/platform" }
345
+ },
346
+ "appearance": { "type": "object" },
347
+ "objectTypes": {
348
+ "type": "array",
349
+ "maxItems": 50,
350
+ "items": { "$ref": "#/$defs/objectTypeDefinition" }
351
+ },
352
+ "relationTypes": {
353
+ "type": "array",
354
+ "maxItems": 100,
355
+ "items": { "$ref": "#/$defs/relationTypeDefinition" }
356
+ },
357
+ "permissions": {
358
+ "type": "array",
359
+ "uniqueItems": true,
360
+ "items": { "$ref": "#/$defs/permission" }
361
+ },
362
+ "networkOrigins": {
363
+ "type": "array",
364
+ "maxItems": 50,
365
+ "uniqueItems": true,
366
+ "items": { "type": "string", "format": "uri", "pattern": "^https://" }
367
+ },
368
+ "nativeCommands": {
369
+ "type": "array",
370
+ "maxItems": 50,
371
+ "uniqueItems": true,
372
+ "items": { "$ref": "#/$defs/pluginKey" }
373
+ },
374
+ "commands": {
375
+ "type": "array",
376
+ "maxItems": 50,
377
+ "items": { "$ref": "#/$defs/commandDefinition" }
378
+ },
379
+ "slashCommands": {
380
+ "type": "array",
381
+ "minItems": 1,
382
+ "maxItems": 20,
383
+ "items": { "$ref": "#/$defs/slashCommandDefinition" }
384
+ },
385
+ "views": {
386
+ "type": "array",
387
+ "maxItems": 10,
388
+ "items": { "$ref": "#/$defs/viewDefinition" }
389
+ },
390
+ "codeBlockRenderers": {
391
+ "type": "array",
392
+ "minItems": 1,
393
+ "maxItems": 10,
394
+ "items": { "$ref": "#/$defs/codeBlockRendererDefinition" }
395
+ },
396
+ "fileHandlers": {
397
+ "type": "array",
398
+ "minItems": 1,
399
+ "maxItems": 10,
400
+ "items": { "$ref": "#/$defs/fileHandlerDefinition" }
401
+ },
402
+ "assistantTools": {
403
+ "type": "array",
404
+ "minItems": 1,
405
+ "maxItems": 16,
406
+ "items": { "$ref": "#/$defs/assistantToolDefinition" }
407
+ },
408
+ "assistantContextProviders": {
409
+ "type": "array",
410
+ "minItems": 1,
411
+ "maxItems": 8,
412
+ "items": { "$ref": "#/$defs/assistantContextProviderDefinition" }
413
+ },
414
+ "services": {
415
+ "type": "array",
416
+ "minItems": 1,
417
+ "maxItems": 16,
418
+ "items": { "$ref": "#/$defs/serviceDefinition" }
419
+ },
420
+ "usesServices": {
421
+ "type": "array",
422
+ "minItems": 1,
423
+ "maxItems": 20,
424
+ "items": { "$ref": "#/$defs/serviceDependency" }
425
+ },
426
+ "settingsSchema": {
427
+ "type": "array",
428
+ "minItems": 1,
429
+ "maxItems": 30,
430
+ "items": { "$ref": "#/$defs/settingField" }
431
+ },
432
+ "activationEvents": {
433
+ "type": "array",
434
+ "minItems": 1,
435
+ "maxItems": 20,
436
+ "uniqueItems": true,
437
+ "items": { "$ref": "#/$defs/activationEvent" }
438
+ },
439
+ "automations": {
440
+ "type": "array",
441
+ "minItems": 1,
442
+ "maxItems": 10,
443
+ "items": { "$ref": "#/$defs/automationDefinition" }
444
+ }
445
+ }
446
+ }
447
+ }
448
+ }
package/package.json CHANGED
@@ -1,16 +1,33 @@
1
1
  {
2
2
  "name": "@tano.page/protocol",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
7
+ "./agent-identities": "./src/domain/agent-identities.ts",
8
+ "./agent-inbox": "./src/domain/agent-inbox.ts",
9
+ "./assistant-completion": "./src/domain/assistant-completion.ts",
10
+ "./assistant-engine": "./src/domain/assistant-engine.ts",
11
+ "./assistant-execution": "./src/domain/assistant-execution.ts",
12
+ "./assistant-files": "./src/domain/assistant-files.ts",
13
+ "./assistant-history": "./src/domain/assistant-history.ts",
14
+ "./assistant-language": "./src/domain/assistant-language.ts",
15
+ "./assistant-prompts": "./src/domain/assistant-prompts.ts",
16
+ "./assistant-structures": "./src/domain/assistant-structures.ts",
17
+ "./assistant-tasks": "./src/domain/assistant-tasks.ts",
7
18
  "./features": "./src/features.ts",
8
19
  "./frontmatter": "./src/frontmatter.ts",
9
- "./markdown-file-metadata": "./src/markdown-file-metadata.ts"
20
+ "./markdown-file-metadata": "./src/markdown-file-metadata.ts",
21
+ "./plugin-data": "./src/domain/plugin-data.ts",
22
+ "./plugin-sdk": "./src/domain/plugin-sdk.ts",
23
+ "./untrusted-data": "./src/domain/untrusted-data.ts",
24
+ "./workspace-comments": "./src/domain/workspace-comments.ts",
25
+ "./manifest.schema.json": "./manifest.schema.json"
10
26
  },
11
27
  "license": "MIT",
12
28
  "files": [
13
29
  "src",
30
+ "manifest.schema.json",
14
31
  "LICENSE"
15
32
  ],
16
33
  "dependencies": {
@@ -25,8 +42,8 @@
25
42
  "url": "git+https://github.com/Dramwig/Tano.git"
26
43
  },
27
44
  "tanoCore": {
28
- "sourceCommit": "b29ddb71202c3b993965e52a1459eea3b0cc42b7",
29
- "version": "0.14.0",
45
+ "sourceCommit": "0eead85177b8d5010d0daea26f1995a27f9270a9",
46
+ "version": "0.16.0",
30
47
  "importName": "@tano/protocol"
31
48
  }
32
49
  }
package/src/appearance.ts CHANGED
@@ -54,10 +54,17 @@ export interface FileIconTheme {
54
54
  folderNames?: Readonly<Record<string, string>>;
55
55
  folderNamesExpanded?: Readonly<Record<string, string>>;
56
56
  }
57
+ export interface FileIconThemeRef {
58
+ id: string;
59
+ label: string;
60
+ notice?: string;
61
+ }
57
62
  export interface PluginAppearance {
58
63
  version: typeof appearanceVersion;
59
64
  colors?: ColorThemeDefinition[];
60
65
  icons?: FileIconTheme[];
66
+ /** Lightweight metadata for heavy raster icon themes stored in PluginPackage.assets.icons. */
67
+ iconRefs?: FileIconThemeRef[];
61
68
  layouts?: LayoutThemeDefinition[];
62
69
  shapes?: ShapeThemeDefinition[];
63
70
  presets?: ThemePresetDefinition[];
@@ -184,7 +191,7 @@ export function parseFileIconTheme(value: unknown): FileIconTheme {
184
191
  return result as unknown as FileIconTheme;
185
192
  }
186
193
  export function parsePluginAppearance(value: unknown): PluginAppearance {
187
- keys(value, ['version', 'colors', 'icons', 'layouts', 'shapes', 'presets']);
194
+ keys(value, ['version', 'colors', 'icons', 'iconRefs', 'layouts', 'shapes', 'presets']);
188
195
  if (value.version !== appearanceVersion) throw new Error('不支持此主题契约版本');
189
196
  const parseList = <T extends { id: string }>(input: unknown, parse: (value: unknown) => T): T[] => {
190
197
  if (!Array.isArray(input) || input.length > 12) throw new Error('主题列表无效');
@@ -211,6 +218,14 @@ export function parsePluginAppearance(value: unknown): PluginAppearance {
211
218
  return { id: item.id, label: item.label, tokens: parseThemeTokens(item.tokens) };
212
219
  });
213
220
  const icons = value.icons === undefined ? undefined : parseList(value.icons, parseFileIconTheme);
221
+ const iconRefs = value.iconRefs === undefined ? undefined : parseList<FileIconThemeRef>(value.iconRefs, item => {
222
+ keys(item, ['id', 'label', 'notice']); id(item.id); label(item.label);
223
+ if (item.notice !== undefined && (typeof item.notice !== 'string' || item.notice.length > 4096 || /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(item.notice)))
224
+ throw new Error('图标许可声明无效');
225
+ return { id: item.id, label: item.label, ...(item.notice === undefined ? {} : { notice: item.notice }) };
226
+ });
227
+ const allIconChoices = [...(icons ?? []), ...(iconRefs ?? [])];
228
+ if (new Set(allIconChoices.map(item => item.id)).size !== allIconChoices.length) throw new Error('主题 ID 重复');
214
229
  const layouts = value.layouts === undefined ? undefined : parseList(value.layouts, item => {
215
230
  keys(item, ['id', 'label', 'structure', 'surface', 'gap', 'pageWidth']); id(item.id); label(item.label);
216
231
  // The skeuomorphic notebook structure was retired in favour of the calmer paper document.
@@ -232,8 +247,8 @@ export function parsePluginAppearance(value: unknown): PluginAppearance {
232
247
  return { [key]: target };
233
248
  };
234
249
  if (['color', 'icons', 'layout', 'shape'].every(key => item[key] === undefined)) throw new Error('主题预设至少需要指定一项');
235
- return { id: item.id, label: item.label, ...reference('color', colors), ...reference('icons', icons), ...reference('layout', layouts), ...reference('shape', shapes) };
250
+ return { id: item.id, label: item.label, ...reference('color', colors), ...reference('icons', allIconChoices.length ? allIconChoices : undefined), ...reference('layout', layouts), ...reference('shape', shapes) };
236
251
  });
237
- if (!colors?.length && !icons?.length && !layouts?.length && !shapes?.length && !presets?.length) throw new Error('主题包至少需要一套配色、图标、布局、形态或预设');
238
- return { version: value.version, ...(colors ? { colors } : {}), ...(icons ? { icons } : {}), ...(layouts ? { layouts } : {}), ...(shapes ? { shapes } : {}), ...(presets ? { presets } : {}) };
252
+ if (!colors?.length && !icons?.length && !iconRefs?.length && !layouts?.length && !shapes?.length && !presets?.length) throw new Error('主题包至少需要一套配色、图标、布局、形态或预设');
253
+ return { version: value.version, ...(colors ? { colors } : {}), ...(icons ? { icons } : {}), ...(iconRefs ? { iconRefs } : {}), ...(layouts ? { layouts } : {}), ...(shapes ? { shapes } : {}), ...(presets ? { presets } : {}) };
239
254
  }
package/src/assistant.ts CHANGED
@@ -69,11 +69,25 @@ export interface AssistantPreview {
69
69
  path: string;
70
70
  destination?: string;
71
71
  }
72
+ export interface AssistantProposalPluginAction {
73
+ pluginId: string;
74
+ pluginName: string;
75
+ toolName: string;
76
+ label?: string;
77
+ effect: 'write' | 'external';
78
+ }
79
+ export interface AssistantProposalExtensionAction {
80
+ namespace: string;
81
+ action: string;
82
+ label?: string;
83
+ effect: 'write' | 'external';
84
+ payload: Record<string, unknown>;
85
+ }
72
86
  export interface AssistantProposal {
73
87
  id: string;
74
88
  runId: string;
75
89
  workspaceId: string;
76
- kind: 'edit' | 'create' | 'delete' | 'rename' | 'move' | 'object' | 'relation';
90
+ kind: 'edit' | 'create' | 'delete' | 'rename' | 'move' | 'object' | 'relation' | 'plugin' | 'extension';
77
91
  fileId?: string;
78
92
  path: string;
79
93
  destination?: string;
@@ -84,10 +98,14 @@ export interface AssistantProposal {
84
98
  /** Omitted on legacy and manually reviewed proposals. */
85
99
  execution?: 'direct';
86
100
  preview?: AssistantPreview;
87
- applied?: { before: string; after: string; hash: string; fileId: string };
101
+ applied?: { before: string; after: string; hash: string; fileId: string; undoSnapshot?: string };
88
102
  error?: string;
89
103
  /** Once published, per-edit review belongs to the portable document records. */
90
104
  suggestionGroupId?: string;
105
+ /** Present only when kind === 'plugin' (write/external plugin tool awaiting confirmation). */
106
+ pluginAction?: AssistantProposalPluginAction;
107
+ /** Present only when kind === 'extension' (host extension action awaiting confirmation). */
108
+ extensionAction?: AssistantProposalExtensionAction;
91
109
  }
92
110
 
93
111
  /** Application-recorded receipts; never inferred from the model's answer. */
@@ -373,11 +391,23 @@ export function parseAssistantSession(value: unknown): AssistantSession {
373
391
  }
374
392
  for (const proposal of message.proposals ?? []) {
375
393
  if (!proposal || proposal.workspaceId !== session.workspaceId || !text(proposal.id, 80) ||
376
- !text(proposal.runId, 80) || !['edit', 'create', 'delete', 'rename', 'move', 'object', 'relation'].includes(proposal.kind) ||
394
+ !text(proposal.runId, 80) || !['edit', 'create', 'delete', 'rename', 'move', 'object', 'relation', 'plugin', 'extension'].includes(proposal.kind) ||
377
395
  !['ready', 'applying', 'applied', 'rejected', 'conflicted', 'unknown'].includes(proposal.status) ||
378
396
  (proposal.execution !== undefined && proposal.execution !== 'direct') ||
379
397
  !text(proposal.path, 220) || !text(proposal.base, 512_000) || !text(proposal.content, 512_000) ||
380
398
  !text(proposal.reason, 4000) || (proposal.suggestionGroupId !== undefined && (proposal.kind !== 'edit' || !text(proposal.suggestionGroupId, 80))) || ((['edit', 'delete', 'rename', 'move'].includes(proposal.kind) || (proposal.kind === 'object' && proposal.base !== '')) && !text(proposal.fileId, 80)) ||
399
+ (proposal.kind === 'plugin'
400
+ ? (!proposal.pluginAction || !text(proposal.pluginAction.pluginId, 80) || !text(proposal.pluginAction.pluginName, 120) ||
401
+ !text(proposal.pluginAction.toolName, 80) || !['write', 'external'].includes(proposal.pluginAction.effect) ||
402
+ (proposal.pluginAction.label !== undefined && !text(proposal.pluginAction.label, 80)))
403
+ : proposal.pluginAction !== undefined) ||
404
+ (proposal.kind === 'extension'
405
+ ? (!proposal.extensionAction || !text(proposal.extensionAction.namespace, 80) || !proposal.extensionAction.namespace.trim() ||
406
+ !text(proposal.extensionAction.action, 80) || !proposal.extensionAction.action.trim() ||
407
+ !['write', 'external'].includes(proposal.extensionAction.effect) ||
408
+ (proposal.extensionAction.label !== undefined && !text(proposal.extensionAction.label, 80)) ||
409
+ !proposal.extensionAction.payload || typeof proposal.extensionAction.payload !== 'object' || Array.isArray(proposal.extensionAction.payload))
410
+ : proposal.extensionAction !== undefined) ||
381
411
  (['rename', 'move'].includes(proposal.kind) ? !text(proposal.destination, 220) || !proposal.destination : proposal.destination !== undefined) ||
382
412
  (proposal.preview && (!text(proposal.preview.before, 512_000) ||
383
413
  !text(proposal.preview.after, 512_000) || !text(proposal.preview.path, 220) ||
@@ -385,7 +415,8 @@ export function parseAssistantSession(value: unknown): AssistantSession {
385
415
  (proposal.preview.diskHash !== null && !text(proposal.preview.diskHash, 128)))) ||
386
416
  (proposal.applied && (!text(proposal.applied.before, 512_000) ||
387
417
  !text(proposal.applied.after, 512_000) || !text(proposal.applied.hash, 128) ||
388
- !text(proposal.applied.fileId, 80))))
418
+ !text(proposal.applied.fileId, 80) ||
419
+ (proposal.applied.undoSnapshot !== undefined && !text(proposal.applied.undoSnapshot, 512_000)))))
389
420
  throw new Error('助手修改记录格式无效,原记录已保留');
390
421
  }
391
422
  }