@tano.page/workbench 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 (248) hide show
  1. package/package.json +50 -16
  2. package/src/App.vue +82 -752
  3. package/src/appearance/appearance.ts +14 -4
  4. package/src/appearance/components/ThemePresetPreview.vue +52 -8
  5. package/src/appearance/interface-font.ts +99 -0
  6. package/src/appearance/theme.ts +26 -10
  7. package/src/appearance/use-interface-font.ts +30 -0
  8. package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
  9. package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
  10. package/src/assets/mail-provider-icons/gmail.svg +1 -0
  11. package/src/assets/mail-provider-icons/icloud.svg +12 -0
  12. package/src/assets/mail-provider-icons/netease-126.svg +5 -0
  13. package/src/assets/mail-provider-icons/netease-163.svg +5 -0
  14. package/src/assets/mail-provider-icons/qq.svg +9 -0
  15. package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
  16. package/src/assistant/agent-identities.ts +1 -97
  17. package/src/assistant/agent-task-context.ts +1 -54
  18. package/src/assistant/attachments.ts +1 -1
  19. package/src/assistant/completion.ts +1 -61
  20. package/src/assistant/components/AssistantChangeList.vue +98 -21
  21. package/src/assistant/components/AssistantPanel.vue +425 -8
  22. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  23. package/src/assistant/connection-actions.ts +237 -0
  24. package/src/assistant/document-mentions.ts +1 -33
  25. package/src/assistant/engine.ts +1 -532
  26. package/src/assistant/execution.ts +6 -33
  27. package/src/assistant/files.ts +5 -13
  28. package/src/assistant/hash.ts +1 -4
  29. package/src/assistant/inbox.ts +1 -148
  30. package/src/assistant/language.ts +10 -37
  31. package/src/assistant/mention-autocomplete.ts +69 -0
  32. package/src/assistant/plugin-bridge-builder.ts +146 -0
  33. package/src/assistant/prompts.ts +1 -58
  34. package/src/assistant/proposal-actions.ts +336 -0
  35. package/src/assistant/results.ts +20 -86
  36. package/src/assistant/store.ts +167 -327
  37. package/src/assistant/structures.ts +1 -155
  38. package/src/assistant/tasks.ts +8 -96
  39. package/src/assistant/tool-rules.ts +1 -7
  40. package/src/assistant/workspace-bridge.ts +1 -1
  41. package/src/composables/use-document-actions.ts +38 -20
  42. package/src/composables/use-file-tree-controller.ts +7 -12
  43. package/src/composables/use-workbench-help.ts +177 -0
  44. package/src/composables/use-workbench-history.ts +2 -4
  45. package/src/composables/use-workbench-lifecycle.ts +249 -0
  46. package/src/composables/use-workbench-modals.ts +6 -1
  47. package/src/composables/use-workbench-outline.ts +0 -5
  48. package/src/composables/use-workbench-settings.ts +185 -0
  49. package/src/composables/use-workbench-shortcuts.ts +40 -1021
  50. package/src/composables/use-workbench-views.ts +325 -0
  51. package/src/data-tables/data-tables.ts +1 -2
  52. package/src/documents/components/DocumentActionMenu.vue +279 -0
  53. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  54. package/src/documents/components/DocumentInspector.vue +168 -0
  55. package/src/documents/components/DocumentPane.vue +482 -0
  56. package/src/documents/description-merge.ts +1 -9
  57. package/src/features.ts +1 -0
  58. package/src/files/components/FileMetadataPanel.vue +49 -15
  59. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  60. package/src/fonts/Inter-Latin.woff2 +0 -0
  61. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  62. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  63. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  64. package/src/help/help-milestones.ts +3 -5
  65. package/src/i18n/locale-catalogs.ts +7 -6
  66. package/src/i18n/locale-registry.ts +8 -6
  67. package/src/i18n/locales/de-DE.json +371 -3
  68. package/src/i18n/locales/en-US.json +371 -2
  69. package/src/i18n/locales/es-ES.json +371 -3
  70. package/src/i18n/locales/ja-JP.json +370 -2
  71. package/src/i18n/locales/zh-TW.json +370 -2
  72. package/src/mail/components/MailAccountDialog.vue +450 -0
  73. package/src/mail/components/MailComposerDialog.vue +326 -0
  74. package/src/mail/components/MailProviderIcon.vue +30 -0
  75. package/src/mail/components/MailWorkspaceView.vue +821 -0
  76. package/src/mail/components/SidebarMail.vue +134 -0
  77. package/src/mail/mail-avatar.ts +17 -0
  78. package/src/mail/mail-bridge.ts +68 -0
  79. package/src/mail/mail-calendar.ts +208 -0
  80. package/src/mail/mail-markdown.ts +195 -0
  81. package/src/mail/types.ts +226 -0
  82. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  83. package/src/objects/content-references.ts +6 -56
  84. package/src/objects/wiki-links.ts +1 -48
  85. package/src/objects/workspace-objects.ts +3 -4
  86. package/src/plan-sync/types.ts +6 -3
  87. package/src/plans/calendar-interaction.ts +194 -0
  88. package/src/plans/calendar.ts +65 -9
  89. package/src/plans/components/CalendarAgendaView.vue +165 -0
  90. package/src/plans/components/CalendarDayPopover.vue +172 -39
  91. package/src/plans/components/CalendarFilterBar.vue +128 -0
  92. package/src/plans/components/CalendarMonthView.vue +224 -0
  93. package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
  94. package/src/plans/components/CalendarTimelineView.vue +517 -0
  95. package/src/plans/components/CalendarTopbarControls.vue +101 -0
  96. package/src/plans/components/CalendarView.vue +264 -748
  97. package/src/plans/components/CalendarYearView.vue +138 -0
  98. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  99. package/src/plans/components/PlanConnectionsDialog.vue +1 -1
  100. package/src/plans/components/PlanDateField.vue +6 -4
  101. package/src/plans/components/PlanDetailPanel.vue +227 -32
  102. package/src/plans/components/PlanEventList.vue +16 -4
  103. package/src/plans/components/SidebarPlan.vue +22 -15
  104. package/src/plans/components/TaskRepeatControls.vue +169 -30
  105. package/src/plans/components/calendar-shared.css +192 -0
  106. package/src/plans/composables/use-calendar-interactions.ts +396 -0
  107. package/src/plans/composables/use-calendar-scroll.ts +420 -0
  108. package/src/plans/local-reminders.ts +149 -0
  109. package/src/plans/personal-plans.ts +10 -1
  110. package/src/plans/plan-date.ts +8 -1
  111. package/src/plans/plan-migration.ts +95 -0
  112. package/src/plans/recurrence.ts +95 -0
  113. package/src/plans/task-repeat.ts +8 -8
  114. package/src/plans/timeline-layout.ts +92 -0
  115. package/src/plugins/assistant-bridge.ts +520 -0
  116. package/src/plugins/attachment-reader.ts +3 -1
  117. package/src/plugins/cache-storage.ts +42 -2
  118. package/src/plugins/components/PluginAutomations.vue +3 -3
  119. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  120. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  121. package/src/plugins/components/PluginConnections.vue +1 -1
  122. package/src/plugins/components/PluginCustomView.vue +2 -2
  123. package/src/plugins/components/PluginDetailPage.vue +136 -57
  124. package/src/plugins/components/PluginDeveloperArea.vue +192 -0
  125. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  126. package/src/plugins/components/PluginExplorer.vue +21 -25
  127. package/src/plugins/components/PluginImportDialog.vue +410 -0
  128. package/src/plugins/components/PluginInstaller.vue +273 -288
  129. package/src/plugins/components/PluginListItem.vue +3 -0
  130. package/src/plugins/components/PluginMaintenance.vue +37 -34
  131. package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
  132. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  133. package/src/plugins/components/PluginSettingsForm.vue +112 -0
  134. package/src/plugins/components/PluginStatusBar.vue +161 -0
  135. package/src/plugins/components/PluginSurface.vue +18 -6
  136. package/src/plugins/components/PluginUiDialog.vue +452 -0
  137. package/src/plugins/components/PluginsTabPage.vue +61 -0
  138. package/src/plugins/components/plugin-center.css +5 -0
  139. package/src/plugins/data.ts +9 -86
  140. package/src/plugins/editor-plugin-adapters.ts +169 -0
  141. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  142. package/src/plugins/excalidraw/manifest.json +12 -1
  143. package/src/plugins/host.ts +662 -43
  144. package/src/plugins/native.ts +2 -10
  145. package/src/plugins/overlay-mapping.ts +125 -0
  146. package/src/plugins/packages.ts +73 -1
  147. package/src/plugins/plugin-data.ts +2 -3
  148. package/src/plugins/plugin-permissions.ts +57 -0
  149. package/src/plugins/plugin-rpc-router.ts +558 -0
  150. package/src/plugins/plugin-sdk.ts +1 -94
  151. package/src/plugins/plugin-ui-dialogs.ts +167 -0
  152. package/src/plugins/policy.ts +53 -3
  153. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  154. package/src/plugins/presentation-preview/manifest.json +2 -1
  155. package/src/plugins/queries.ts +1 -73
  156. package/src/plugins/sandbox.ts +15 -1
  157. package/src/plugins/use-plugin-actions.ts +67 -20
  158. package/src/plugins/user-plugins.ts +254 -0
  159. package/src/plugins/view-header.ts +2 -7
  160. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  161. package/src/plugins/word-preview/manifest.json +13 -1
  162. package/src/plugins/workbench.ts +175 -2
  163. package/src/plugins/worker.js +105 -8
  164. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  165. package/src/plugins/workspace-plugins.ts +212 -21
  166. package/src/runtime.ts +103 -4
  167. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  168. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  169. package/src/settings/components/SettingsPanel.vue +8 -3
  170. package/src/settings/components/WorkbenchSettings.vue +20 -7
  171. package/src/settings/components/settings-context.ts +1 -1
  172. package/src/settings/components/settings-search.ts +2 -3
  173. package/src/settings/settings-tab.ts +1 -0
  174. package/src/shell/command-palette.ts +3 -3
  175. package/src/shell/components/EditorToolbar.vue +8 -9
  176. package/src/shell/components/EditorTools.vue +1 -5
  177. package/src/shell/components/PaneTopbar.vue +393 -0
  178. package/src/shell/components/SelectionToolbar.vue +0 -2
  179. package/src/shell/components/SidebarNavigation.vue +22 -2
  180. package/src/shell/components/WorkbenchContextMenus.vue +58 -34
  181. package/src/shell/components/WorkbenchModals.vue +47 -62
  182. package/src/shell/components/WorkbenchPanes.vue +371 -1342
  183. package/src/shell/components/WorkbenchSidebar.vue +486 -0
  184. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  185. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  186. package/src/shell/pane-registry.ts +69 -0
  187. package/src/shell/use-surface-dismissal.ts +219 -0
  188. package/src/shell/use-workbench-commands.ts +599 -0
  189. package/src/shell/use-workbench-keybindings.ts +337 -0
  190. package/src/shell/use-workbench.ts +531 -1153
  191. package/src/shell/workbench-async-components.ts +14 -5
  192. package/src/shell/workbench-context.ts +30 -3
  193. package/src/stores/mail.ts +414 -0
  194. package/src/stores/plan-sync.ts +2 -1
  195. package/src/stores/plans.ts +2 -9
  196. package/src/stores/workspace-document-io.ts +807 -0
  197. package/src/stores/workspace-file-ops.ts +1 -1
  198. package/src/stores/workspace-knowledge.ts +2 -114
  199. package/src/stores/workspace-lifecycle.ts +459 -0
  200. package/src/stores/workspace-plugins-state.ts +254 -259
  201. package/src/stores/workspace-session.ts +287 -0
  202. package/src/stores/workspace-tabs-layout.ts +6 -44
  203. package/src/stores/workspace-types.ts +50 -0
  204. package/src/stores/workspace.ts +184 -1363
  205. package/src/styles/agent-diff-modals.css +0 -7
  206. package/src/styles/dark-theme.css +3 -3
  207. package/src/styles/inspector.css +0 -59
  208. package/src/styles/layout-themes.css +346 -0
  209. package/src/styles/mail.css +1568 -0
  210. package/src/styles/mobile.css +2 -2
  211. package/src/styles/recent-and-media.css +0 -17
  212. package/src/styles/theme-contract.css +3 -3
  213. package/src/styles/workbench-shell.css +110 -17
  214. package/src/styles/workspace-states.css +9 -33
  215. package/src/styles.css +0 -1
  216. package/src/tabs/components/DesktopTabs.vue +19 -14
  217. package/src/tabs/components/NewTabPicker.vue +10 -4
  218. package/src/tabs/tab-label.ts +0 -1
  219. package/src/windows/AuxiliaryWindows.vue +2 -2
  220. package/src/windows/use-window-event-bridge.ts +152 -0
  221. package/src/workspace/components/TemplateLibrary.vue +1 -1
  222. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  223. package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
  224. package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
  225. package/src/workspace/workspace-comments.ts +11 -151
  226. package/src/workspace/workspace-welcome.ts +1 -1
  227. package/src/assistant/locales/de-DE.json +0 -126
  228. package/src/assistant/locales/en-US.json +0 -126
  229. package/src/assistant/locales/es-ES.json +0 -126
  230. package/src/assistant/locales/ja-JP.json +0 -126
  231. package/src/assistant/locales/zh-CN.json +0 -126
  232. package/src/assistant/locales/zh-TW.json +0 -126
  233. package/src/assistant/task-prompts.json +0 -39
  234. package/src/documents/components/FormulaMenu.vue +0 -50
  235. package/src/files/components/FileDatabasePage.vue +0 -152
  236. package/src/files/components/FolderHomeIcon.vue +0 -12
  237. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  238. package/src/objects/components/ObjectPanel.vue +0 -554
  239. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  240. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  241. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  242. package/src/styles/object-panel.css +0 -163
  243. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  244. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  245. package/src/workspace/welcome-slogans.ts +0 -11
  246. package/src/workspace/workspace-git.ts +0 -35
  247. package/src/workspace/workspace-sync.ts +0 -46
  248. package/src/workspace/workspace-views.ts +0 -48
@@ -5,5 +5,6 @@
5
5
  "objectTypes": [], "relationTypes": [], "permissions": ["attachments.read", "ui"],
6
6
  "networkOrigins": [], "nativeCommands": [],
7
7
  "commands": [{ "id": "open", "label": "演示文稿:打开预览" }],
8
- "views": [{ "id": "slides", "label": "演示文稿预览", "location": "tab" }]
8
+ "views": [{ "id": "slides", "label": "演示文稿预览", "location": "tab", "layout": "fill" }],
9
+ "fileHandlers": [{ "extensions": [".ppt", ".pptx"], "mode": "preview", "view": "slides", "command": "open" }]
9
10
  }
@@ -1,73 +1 @@
1
- import { canonicalPluginJson, isMarkdown, isWorkspaceInternalPath, pluginRecord } from '@tano/protocol';
2
- import type { Workspace, WorkspaceRelation, WorkspaceObject } from '@tano/protocol';
3
- import type { PluginDocumentEntry, PluginPageOptions } from './plugin-sdk';
4
- import { assistantHash } from '../assistant/hash';
5
- import { compareQueryText, PluginQueryPager, pluginQueryOptions, queryBoolean, queryText } from './data';
6
-
7
- export interface PluginQueryContext {
8
- workspace: Workspace;
9
- objects: { object: WorkspaceObject; snapshot: { hash: string } }[];
10
- relations: WorkspaceRelation[];
11
- drafts: { id: string; content: string; conflict?: unknown; missing: boolean }[];
12
- read(path: string): Promise<{ content: string }>;
13
- assertCurrent(): void;
14
- /** Host revision, for stores whose timestamp and size alone do not identify a content version. */
15
- revision?: unknown;
16
- }
17
- export async function queryPluginData(method: string, params: Record<string, unknown>, pager: PluginQueryPager, context: PluginQueryContext) {
18
- const { workspace, objects, relations, drafts, assertCurrent } = context;
19
- const scope = `${workspace.id}:${String(params.queryScope)}`;
20
- if (method === 'documents.query' || method === 'documents.search') {
21
- const options = pluginQueryOptions(params.options, method === 'documents.search' ? ['query', 'pathPrefix', 'readOnly'] : ['query', 'pathPrefix', 'readOnly', 'sort']);
22
- const query = queryText(options.query) ?? '', prefix = queryText(options.pathPrefix, 1000) ?? '', readOnly = queryBoolean(options.readOnly);
23
- if (options.sort !== undefined && !['path', 'name', 'modified'].includes(String(options.sort))) throw new Error('文档排序字段无效');
24
- if (method === 'documents.search' && !query.trim()) throw new Error('请输入搜索文本');
25
- const rows = workspace.files.filter(row => row.kind === 'file' && isMarkdown(row.path) && !isWorkspaceInternalPath(row.path) &&
26
- row.path.startsWith(prefix) && (readOnly === undefined || !!(workspace.readOnly || row.readOnly) === readOnly) &&
27
- (method === 'documents.search' || `${row.path}\n${row.name}`.toLowerCase().includes(query.toLowerCase())));
28
- const sort = String(options.sort ?? 'path'), direction = options.direction === 'desc' ? -1 : 1;
29
- rows.sort((a, b) => direction * ((sort === 'modified' ? a.modified - b.modified : compareQueryText(sort === 'name' ? a.name : a.path, sort === 'name' ? b.name : b.path)) || compareQueryText(a.id, b.id)));
30
- const metadata = (row: typeof rows[number]): PluginDocumentEntry => ({ id: row.id, name: row.name, path: row.path, readOnly: !!(workspace.readOnly || row.readOnly) });
31
- const revision = [context.revision ?? null, rows.map(row => [row.id, row.path, row.name, row.modified, row.size, metadata(row).readOnly]),
32
- method === 'documents.search' ? drafts.map(row => [row.id, row.content, !!row.conflict, row.missing]) : []];
33
- if (method === 'documents.query') return pager.page(scope, method, options as PluginPageOptions, revision, rows, async row => metadata(row), assertCurrent);
34
- const draftsById = new Map(drafts.map(draft => [draft.id, draft]));
35
- const skipped: string[] = [];
36
- const pattern = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'iu');
37
- const page = await pager.page(scope, method, options as PluginPageOptions, revision, rows, async row => {
38
- const draft = draftsById.get(row.id);
39
- if (draft?.conflict || draft?.missing || (!draft && row.size > 512000)) { skipped.push(row.id); return; }
40
- assertCurrent();
41
- const content = draft?.content ?? (await context.read(row.path)).content;
42
- assertCurrent();
43
- if (content.length > 512000) { skipped.push(row.id); return; }
44
- const match = pattern.exec(content);
45
- if (!match) return;
46
- return { ...metadata(row), snippet: content.slice(Math.max(0, match.index - 60), match.index + query.length + 120), offset: match.index, hash: await assistantHash(content) };
47
- }, assertCurrent, 25);
48
- return { ...page, skipped };
49
- }
50
- if (method === 'objects.query') {
51
- const options = pluginQueryOptions(params.options, ['query', 'type', 'archived', 'properties', 'sort']);
52
- const query = (queryText(options.query) ?? '').toLowerCase(), type = queryText(options.type), archived = queryBoolean(options.archived);
53
- if (options.sort !== undefined && !['name', 'type', 'id'].includes(String(options.sort))) throw new Error('对象排序字段无效');
54
- const properties = options.properties ?? {};
55
- if (!pluginRecord(properties) || Object.keys(properties).length > 10 || Object.entries(properties).some(([key, value]) => key.length > 100 ||
56
- (value !== null && !['string', 'number', 'boolean'].includes(typeof value)) || (typeof value === 'number' && !Number.isFinite(value)) ||
57
- (typeof value === 'string' && value.length > 200))) throw new Error('属性筛选只支持最多 10 个标量条件');
58
- const rows = objects.filter(({ object }) => (!type || object.type === type) && (archived === undefined || object.archived === archived) &&
59
- `${object.name}\n${object.description}`.toLowerCase().includes(query) && Object.entries(properties).every(([key, value]) => Object.hasOwn(object.properties, key) && object.properties[key] === value));
60
- const sort = (options.sort ?? 'name') as 'name' | 'type' | 'id', direction = options.direction === 'desc' ? -1 : 1;
61
- rows.sort((a, b) => direction * (compareQueryText(a.object[sort], b.object[sort]) || compareQueryText(a.object.id, b.object.id)));
62
- return pager.page(scope, method, options as PluginPageOptions, rows.map(row => [row.object.id, row.snapshot.hash]), rows,
63
- async row => ({ id: row.object.id, object: JSON.parse(JSON.stringify(row.object)), hash: row.snapshot.hash }), assertCurrent);
64
- }
65
- if (method === 'relations.query') {
66
- const options = pluginQueryOptions(params.options, ['type', 'sourceId', 'targetId']);
67
- const type = queryText(options.type), source = queryText(options.sourceId), target = queryText(options.targetId);
68
- const rows = relations.filter(row => (!type || row.type === type) && (!source || row.source.id === source) && (!target || row.target.id === target));
69
- rows.sort((a, b) => (options.direction === 'desc' ? -1 : 1) * compareQueryText(a.id, b.id));
70
- return pager.page(scope, method, options as PluginPageOptions, canonicalPluginJson(rows), rows, async row => JSON.parse(JSON.stringify(row)), assertCurrent);
71
- }
72
- throw new Error('不支持此查询');
73
- }
1
+ export { queryPluginData, type PluginQueryContext } from '@tano/protocol/plugin-data';
@@ -4,6 +4,7 @@ import workerSource from './worker.js?raw';
4
4
  export interface PluginSandbox {
5
5
  send(message: unknown): void;
6
6
  dispose(): void;
7
+ gracefulDispose?(timeoutMs?: number): void;
7
8
  }
8
9
  export type PluginSandboxFactory = (source: string, receive: (message: unknown) => void, failed: (error: string) => void) => PluginSandbox;
9
10
 
@@ -40,11 +41,24 @@ export const createPluginSandbox: PluginSandboxFactory = (source, receive, faile
40
41
  // There are no plugin-controlled URLs or HTML in this document.
41
42
  frame.srcdoc = `<!doctype html><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-HqAH3w25zKsq8qlxnq/FqwEwwxm4jFIT+lkTXMahrdU=' blob:; worker-src blob:; connect-src 'none'; child-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'"><script>${sandboxBootstrap}</script>`;
42
43
  document.body.append(frame);
44
+ const teardown = () => {
45
+ channel.port1.close(); channel.port2.close(); frame.remove();
46
+ };
43
47
  return {
44
48
  send(message) { if (!disposed) channel.port1.postMessage(message); },
45
49
  dispose() {
46
50
  if (disposed) return;
47
- disposed = true; channel.port1.close(); channel.port2.close(); frame.remove();
51
+ disposed = true; teardown();
52
+ },
53
+ gracefulDispose(timeoutMs = 800) {
54
+ if (disposed) return;
55
+ disposed = true;
56
+ const timer = setTimeout(teardown, timeoutMs);
57
+ channel.port1.onmessage = event => {
58
+ if (event.data?.type === 'deactivated') { clearTimeout(timer); teardown(); }
59
+ };
60
+ try { channel.port1.postMessage({ type: 'deactivate' }); }
61
+ catch { clearTimeout(timer); teardown(); }
48
62
  },
49
63
  };
50
64
  };
@@ -1,7 +1,12 @@
1
1
  import { computed, ref, watch, type Ref } from 'vue';
2
2
  import { t } from '../i18n/i18n';
3
3
  import { useWorkspaceStore } from '../stores/workspace';
4
- import type { PluginManifest, PluginMode } from '@tano/protocol';
4
+ import {
5
+ parsePluginPathScopes,
6
+ validatePluginSettingsAgainstSchema,
7
+ type PluginManifest,
8
+ type PluginMode,
9
+ } from '@tano/protocol';
5
10
  import type { PluginChange } from './workspace-plugins';
6
11
  import { bundledPluginCatalog, type PluginCatalogEntry } from './plugin-catalog';
7
12
  export function matchesPlugin(plugin: PluginManifest, query: string) {
@@ -23,13 +28,15 @@ export function usePluginActions(
23
28
  const busy = computed(() => !!pending.value);
24
29
  const policyMode = ref<PluginMode>('recommended'),
25
30
  settingsText = ref('{}'),
26
- sourceUrl = ref('');
31
+ sourceUrl = ref(''),
32
+ pathScopesText = ref('');
27
33
  watch(
28
34
  selectedInstallation,
29
35
  (item) => {
30
36
  policyMode.value = item?.rule?.mode ?? 'recommended';
31
37
  settingsText.value = JSON.stringify(item?.rule?.settings ?? {}, null, 2);
32
38
  sourceUrl.value = item?.rule?.sourceUrl ?? '';
39
+ pathScopesText.value = (item?.pathScopes ?? item?.rule?.pathScopes ?? []).join('\n');
33
40
  },
34
41
  { immediate: true },
35
42
  );
@@ -40,11 +47,11 @@ export function usePluginActions(
40
47
  status.value = '';
41
48
  },
42
49
  );
43
- async function installFromCatalog(manifest: PluginManifest) {
44
- if (busy.value || !store.workspace || !store.canManagePlugins) return;
50
+ async function installFromCatalog(manifest: PluginManifest, scope: 'workspace' | 'user' = 'workspace') {
51
+ if (busy.value || !store.workspace || (scope === 'workspace' && !store.canManagePlugins)) return;
45
52
  const entry = catalog().find((item) => item.manifest.id === manifest.id);
46
53
  if (!entry?.loadPackage) {
47
- await change({ install: manifest, ...(entry?.package ? { package: entry.package } : {}) });
54
+ await change({ install: manifest, ...(entry?.package ? { package: entry.package } : {}), scope });
48
55
  return;
49
56
  }
50
57
  const workspace = store.workspace.id;
@@ -55,7 +62,7 @@ export function usePluginActions(
55
62
  const pkg = await entry.loadPackage();
56
63
  if (store.workspace?.id !== workspace) return;
57
64
  pending.value = '';
58
- await change({ install: manifest, package: pkg });
65
+ await change({ install: manifest, package: pkg, scope });
59
66
  } catch (cause) {
60
67
  if (store.workspace?.id === workspace) error.value = String(cause);
61
68
  } finally {
@@ -66,24 +73,36 @@ export function usePluginActions(
66
73
  if (busy.value || !store.workspace) return;
67
74
  const workspace = store.workspace.id;
68
75
  pending.value =
69
- 'install' in value ? value.install.id : 'uninstall' in value ? value.uninstall : value.id;
76
+ 'personalCodePlugins' in value
77
+ ? '__workspace-policy__'
78
+ : 'install' in value
79
+ ? value.install.id
80
+ : 'uninstall' in value
81
+ ? value.uninstall
82
+ : value.id;
70
83
  error.value = '';
71
84
  status.value = '';
72
85
  try {
73
86
  await store.changePlugin(value, workspace);
74
87
  if (store.workspace?.id === workspace) {
75
88
  status.value =
76
- 'install' in value
77
- ? t('{0} 已安装并启用', [value.install.name])
78
- : 'uninstall' in value
79
- ? t('插件已卸载,对象和关系文件已保留')
80
- : 'mode' in value
81
- ? t('工作区插件规则已保存')
82
- : 'forgetVersion' in value
83
- ? t('已移除历史版本引用')
84
- : value.enabled
85
- ? t('插件已启用')
86
- : t('插件已停用,对象和关系文件已保留');
89
+ 'personalCodePlugins' in value
90
+ ? t('已更新工作区个人代码插件策略')
91
+ : 'install' in value
92
+ ? value.scope === 'user'
93
+ ? t('{0} 已安装为全局插件', [value.install.name])
94
+ : t('{0} 已安装并启用', [value.install.name])
95
+ : 'uninstall' in value
96
+ ? t('插件已卸载,对象和关系文件已保留')
97
+ : 'mode' in value
98
+ ? t('工作区插件规则已保存')
99
+ : 'settings' in value
100
+ ? t('全局插件设置已保存')
101
+ : 'forgetVersion' in value
102
+ ? t('已移除历史版本引用')
103
+ : value.enabled
104
+ ? t('插件已启用')
105
+ : t('插件已停用,对象和关系文件已保留');
87
106
  }
88
107
  } catch (cause) {
89
108
  if (store.workspace?.id === workspace) error.value = String(cause);
@@ -91,26 +110,52 @@ export function usePluginActions(
91
110
  pending.value = '';
92
111
  }
93
112
  }
94
- async function authorize(allowed: boolean) {
113
+ async function authorize(allowed: boolean, options?: { allWorkspaces?: boolean }) {
95
114
  if (!detail.value || !store.workspace) return;
96
115
  try {
97
116
  await store.authorizePlugin(
98
117
  detail.value.id,
99
118
  allowed ? selectedInstallation.value?.rule?.integrity : undefined,
100
119
  store.workspace.id,
120
+ options,
101
121
  );
102
122
  } catch (cause) {
103
123
  error.value = String(cause);
104
124
  }
105
125
  }
126
+ function parsedPathScopes(): string[] {
127
+ const lines = pathScopesText.value
128
+ .split(/[\r\n,]+/)
129
+ .map((item) => item.trim())
130
+ .filter(Boolean);
131
+ return parsePluginPathScopes(lines) ?? [];
132
+ }
106
133
  async function savePolicy() {
107
134
  if (!detail.value) return;
108
135
  try {
136
+ const schema = detail.value.manifestVersion === 2 ? detail.value.settingsSchema : undefined;
137
+ const settings = validatePluginSettingsAgainstSchema(JSON.parse(settingsText.value), schema);
109
138
  await change({
110
139
  id: detail.value.id,
111
140
  mode: policyMode.value,
112
- settings: JSON.parse(settingsText.value),
141
+ settings,
113
142
  sourceUrl: sourceUrl.value,
143
+ ...(detail.value.manifestVersion === 2 ? { pathScopes: parsedPathScopes() } : {}),
144
+ });
145
+ } catch (cause) {
146
+ error.value = String(cause);
147
+ }
148
+ }
149
+ async function saveUserSettings() {
150
+ if (!detail.value) return;
151
+ try {
152
+ const schema = detail.value.manifestVersion === 2 ? detail.value.settingsSchema : undefined;
153
+ const settings = validatePluginSettingsAgainstSchema(JSON.parse(settingsText.value), schema);
154
+ await change({
155
+ id: detail.value.id,
156
+ settings,
157
+ ...(detail.value.manifestVersion === 2 ? { pathScopes: parsedPathScopes() } : {}),
158
+ scope: 'user',
114
159
  });
115
160
  } catch (cause) {
116
161
  error.value = String(cause);
@@ -125,10 +170,12 @@ export function usePluginActions(
125
170
  policyMode,
126
171
  settingsText,
127
172
  sourceUrl,
173
+ pathScopesText,
128
174
  selectedInstallation,
129
175
  change,
130
176
  authorize,
131
177
  savePolicy,
178
+ saveUserSettings,
132
179
  installFromCatalog,
133
180
  };
134
181
  }
@@ -0,0 +1,254 @@
1
+ import {
2
+ canonicalPluginJson,
3
+ parsePluginManifest,
4
+ parsePluginPackage,
5
+ parsePluginPathScopes,
6
+ parsePluginSettings,
7
+ pluginRecord,
8
+ pluginText,
9
+ type PluginManifest,
10
+ type PluginPackage,
11
+ } from '@tano/protocol';
12
+ import type { PluginStorage } from './cache-storage';
13
+ import { PluginPackageCache, pluginApplicationStorage } from './packages';
14
+
15
+ export type PluginInstallScope = 'system' | 'workspace' | 'user';
16
+
17
+ /** Lightweight per-principal index stored in application storage; full package bytes live in PluginPackageCache. */
18
+ export interface UserPluginRecord {
19
+ id: string;
20
+ integrity: string;
21
+ enabled: boolean;
22
+ settings: Record<string, unknown>;
23
+ /** Optional directory prefix allowlist restricting document/attachment access. */
24
+ pathScopes?: string[];
25
+ sourceUrl?: string;
26
+ /** Exact SHA-256 authorized by the user across owned/local workspaces. */
27
+ authorizedIntegrity?: string;
28
+ installedAt: string;
29
+ }
30
+
31
+ export interface ResolvedUserPlugin {
32
+ record: UserPluginRecord;
33
+ pkg: PluginPackage;
34
+ }
35
+
36
+ export const userPluginsKey = (principal: string) =>
37
+ `tano.user-plugins.v1.${encodeURIComponent(principal)}`;
38
+
39
+ function validateSourceUrl(value: unknown): string | undefined {
40
+ if (value === undefined) return undefined;
41
+ if (!pluginText(value, 2048)) throw new Error('插件下载地址无效');
42
+ const url = new URL(value);
43
+ if (url.protocol !== 'https:' || url.username || url.password || url.hash)
44
+ throw new Error('插件下载地址必须为 HTTPS');
45
+ return value;
46
+ }
47
+
48
+ export function readUserPlugins(
49
+ storage: PluginStorage = pluginApplicationStorage(),
50
+ principal = 'device',
51
+ ): UserPluginRecord[] {
52
+ const raw = storage.getItem(userPluginsKey(principal));
53
+ if (!raw) return [];
54
+ const data = JSON.parse(raw);
55
+ if (!pluginRecord(data) || data.version !== 1 || !Array.isArray(data.plugins) || data.plugins.length > 100)
56
+ throw new Error('全局插件记录损坏,原记录已保留');
57
+ const ids = new Set<string>();
58
+ return data.plugins.map((item): UserPluginRecord => {
59
+ if (
60
+ !pluginRecord(item) ||
61
+ typeof item.id !== 'string' ||
62
+ !/^[a-z][a-z0-9-]{0,39}$/.test(item.id) ||
63
+ ids.has(item.id) ||
64
+ typeof item.integrity !== 'string' ||
65
+ !/^[a-f0-9]{64}$/.test(item.integrity) ||
66
+ typeof item.enabled !== 'boolean' ||
67
+ !pluginText(item.installedAt, 40) ||
68
+ !Number.isFinite(Date.parse(item.installedAt))
69
+ )
70
+ throw new Error('全局插件记录无效或重复');
71
+ if (
72
+ item.authorizedIntegrity !== undefined &&
73
+ (typeof item.authorizedIntegrity !== 'string' || !/^[a-f0-9]{64}$/.test(item.authorizedIntegrity))
74
+ )
75
+ throw new Error('全局插件授权摘要无效');
76
+ ids.add(item.id);
77
+ const sourceUrl = validateSourceUrl(item.sourceUrl);
78
+ const pathScopes = item.pathScopes === undefined ? undefined : parsePluginPathScopes(item.pathScopes);
79
+ return {
80
+ id: item.id,
81
+ integrity: item.integrity,
82
+ enabled: item.enabled,
83
+ settings: parsePluginSettings(item.settings ?? {}),
84
+ ...(pathScopes?.length ? { pathScopes } : {}),
85
+ ...(sourceUrl ? { sourceUrl } : {}),
86
+ ...(item.authorizedIntegrity ? { authorizedIntegrity: item.authorizedIntegrity } : {}),
87
+ installedAt: item.installedAt,
88
+ };
89
+ });
90
+ }
91
+
92
+ export function writeUserPlugins(
93
+ records: readonly UserPluginRecord[],
94
+ storage: PluginStorage = pluginApplicationStorage(),
95
+ principal = 'device',
96
+ ) {
97
+ if (records.length > 100) throw new Error('全局插件不能超过 100 个');
98
+ storage.setItem(userPluginsKey(principal), JSON.stringify({ version: 1, plugins: records }));
99
+ }
100
+
101
+ export function userScopeUnsupportedReason(manifest: PluginManifest): string | undefined {
102
+ if (manifest.manifestVersion !== 2) return undefined;
103
+ if (
104
+ manifest.permissions.includes('connections') ||
105
+ manifest.permissions.includes('native') ||
106
+ (manifest.automations?.length ?? 0) > 0
107
+ )
108
+ return '包含服务连接、本机能力或后台自动化的插件目前仅支持安装到工作区';
109
+ return undefined;
110
+ }
111
+
112
+ export async function installUserPlugin(
113
+ manifestInput: PluginManifest,
114
+ pkgInput: PluginPackage | undefined,
115
+ options: {
116
+ storage?: PluginStorage;
117
+ principal?: string;
118
+ sourceUrl?: string;
119
+ binaryAssets?: Record<string, Uint8Array>;
120
+ } = {},
121
+ ): Promise<UserPluginRecord> {
122
+ const storage = options.storage ?? pluginApplicationStorage();
123
+ const principal = options.principal ?? 'device';
124
+ const manifest = parsePluginManifest(manifestInput);
125
+ const unsupported = userScopeUnsupportedReason(manifest);
126
+ if (unsupported) throw new Error(unsupported);
127
+ const pkg: PluginPackage =
128
+ manifest.manifestVersion === 2
129
+ ? (() => {
130
+ if (!pkgInput || canonicalPluginJson(pkgInput.manifest) !== canonicalPluginJson(manifest))
131
+ throw new Error('请导入包含此版本脚本的插件包');
132
+ return parsePluginPackage(JSON.stringify(pkgInput));
133
+ })()
134
+ : parsePluginPackage(
135
+ JSON.stringify(
136
+ pkgInput && canonicalPluginJson(pkgInput.manifest) === canonicalPluginJson(manifest)
137
+ ? pkgInput
138
+ : { packageVersion: 1, manifest },
139
+ ),
140
+ );
141
+ const sourceUrl = validateSourceUrl(options.sourceUrl);
142
+ const cache = new PluginPackageCache(storage);
143
+ const integrity = await cache.put(pkg, options.binaryAssets);
144
+ const existing = readUserPlugins(storage, principal);
145
+ const prior = existing.find((row) => row.id === manifest.id);
146
+ const record: UserPluginRecord = {
147
+ id: manifest.id,
148
+ integrity,
149
+ enabled: prior?.enabled ?? true,
150
+ settings: prior?.settings ?? {},
151
+ ...(sourceUrl ? { sourceUrl } : prior?.sourceUrl ? { sourceUrl: prior.sourceUrl } : {}),
152
+ ...(prior?.authorizedIntegrity === integrity ? { authorizedIntegrity: integrity } : {}),
153
+ installedAt: new Date().toISOString(),
154
+ };
155
+ writeUserPlugins([...existing.filter((row) => row.id !== manifest.id), record], storage, principal);
156
+ return record;
157
+ }
158
+
159
+ export function uninstallUserPlugin(
160
+ id: string,
161
+ storage: PluginStorage = pluginApplicationStorage(),
162
+ principal = 'device',
163
+ ) {
164
+ const existing = readUserPlugins(storage, principal);
165
+ writeUserPlugins(existing.filter((row) => row.id !== id), storage, principal);
166
+ }
167
+
168
+ export function setUserPluginEnabled(
169
+ id: string,
170
+ enabled: boolean,
171
+ storage: PluginStorage = pluginApplicationStorage(),
172
+ principal = 'device',
173
+ ) {
174
+ const existing = readUserPlugins(storage, principal);
175
+ if (!existing.some((row) => row.id === id)) throw new Error('插件已被卸载,请刷新后重试');
176
+ writeUserPlugins(
177
+ existing.map((row) => (row.id === id ? { ...row, enabled } : row)),
178
+ storage,
179
+ principal,
180
+ );
181
+ }
182
+
183
+ export function setUserPluginSettings(
184
+ id: string,
185
+ settings: Record<string, unknown>,
186
+ storage: PluginStorage = pluginApplicationStorage(),
187
+ principal = 'device',
188
+ pathScopes?: string[],
189
+ ) {
190
+ const parsed = parsePluginSettings(settings);
191
+ const parsedScopes = pathScopes === undefined ? undefined : parsePluginPathScopes(pathScopes);
192
+ const existing = readUserPlugins(storage, principal);
193
+ if (!existing.some((row) => row.id === id)) throw new Error('插件已被卸载,请刷新后重试');
194
+ writeUserPlugins(
195
+ existing.map((row) => {
196
+ if (row.id !== id) return row;
197
+ const next = { ...row, settings: parsed };
198
+ if (pathScopes !== undefined) {
199
+ if (parsedScopes?.length) next.pathScopes = parsedScopes;
200
+ else delete next.pathScopes;
201
+ }
202
+ return next;
203
+ }),
204
+ storage,
205
+ principal,
206
+ );
207
+ }
208
+
209
+ export function setUserPluginGlobalAuthorization(
210
+ id: string,
211
+ integrity: string | undefined,
212
+ storage: PluginStorage = pluginApplicationStorage(),
213
+ principal = 'device',
214
+ ) {
215
+ const existing = readUserPlugins(storage, principal);
216
+ const target = existing.find((row) => row.id === id);
217
+ if (!target) throw new Error('全局插件不存在或已卸载');
218
+ if (integrity && target.integrity !== integrity)
219
+ throw new Error('插件版本已变化,请重新查看权限');
220
+ writeUserPlugins(
221
+ existing.map((row) => {
222
+ if (row.id !== id) return row;
223
+ const { authorizedIntegrity: _previous, ...rest } = row;
224
+ return integrity ? { ...rest, authorizedIntegrity: integrity } : rest;
225
+ }),
226
+ storage,
227
+ principal,
228
+ );
229
+ }
230
+
231
+ export async function resolveUserPlugins(
232
+ storage: PluginStorage = pluginApplicationStorage(),
233
+ principal = 'device',
234
+ ): Promise<ResolvedUserPlugin[]> {
235
+ const records = readUserPlugins(storage, principal);
236
+ if (!records.length) return [];
237
+ const cache = new PluginPackageCache(storage);
238
+ const resolved: ResolvedUserPlugin[] = [];
239
+ for (const record of records) {
240
+ const pkg = await cache.get(record.integrity).catch(() => null);
241
+ if (!pkg || pkg.manifest.id !== record.id) continue;
242
+ resolved.push({ record, pkg });
243
+ }
244
+ return resolved;
245
+ }
246
+
247
+ export function isAppearanceOnlyPlugin(manifest: PluginManifest): boolean {
248
+ return (
249
+ manifest.manifestVersion === 1 &&
250
+ !!manifest.appearance &&
251
+ manifest.objectTypes.length === 0 &&
252
+ manifest.relationTypes.length === 0
253
+ );
254
+ }
@@ -1,12 +1,7 @@
1
1
  import { pluginRecord, type PluginJson } from '@tano/protocol';
2
+ import type { PluginViewHeader } from '@tano/protocol/plugin-sdk';
2
3
  import type { PluginRuntimeState } from './host';
3
- export interface PluginViewHeader {
4
- title: string;
5
- status?: string;
6
- statusAfter?: string;
7
- previewInfo?: { label: string; detail: string };
8
- actions: { id: string; label: string; icon?: 'open' | 'previous' | 'next' | 'minus' | 'plus' | 'fit' | 'info'; disabled?: boolean; accept?: string; group?: string }[];
9
- }
4
+ export type { PluginViewHeader };
10
5
  export function parseViewHeader(value: PluginJson): PluginViewHeader {
11
6
  if (!pluginRecord(value) || typeof value.title !== 'string' || value.title.length > 200 ||
12
7
  (value.status !== undefined && (typeof value.status !== 'string' || value.status.length > 80)) ||