@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
@@ -1,4 +1,3 @@
1
- import { openWorkspaceSync } from '../workspace/workspace-sync';
2
1
  import { nativeInvoke as invoke } from '../platform/native-bridge';
3
2
  import { parsePluginConnectionInput, parsePluginConnectionRequest, pluginConnectionOrigin, type PluginConnectionProvider, type PluginConnection, type PluginOAuthFlow, type PluginOAuthProvider, type PluginOAuthStatus } from '@tano/protocol';
4
3
  import type { PluginNativeContext, PluginRuntimeServices } from './host';
@@ -19,15 +18,8 @@ export function createNativePluginServices(): NonNullable<PluginRuntimeServices[
19
18
  return result;
20
19
  } finally { context.signal.removeEventListener('abort', cancel); }
21
20
  }
22
- return { ...Object.fromEntries(['git.status', 'git.diff', 'git.log'].map(command => [command,
23
- (args: unknown, context: PluginNativeContext) => request(command, args, context)])),
24
- 'sync.open': async (args: unknown, context: PluginNativeContext) => {
25
- context.signal.throwIfAborted();
26
- if (args !== undefined && JSON.stringify(args) !== '{}') throw new Error('同步入口不接受操作参数');
27
- openWorkspaceSync(context.workspaceId);
28
- return { opened: true };
29
- },
30
- };
21
+ return Object.fromEntries(['git.status', 'git.diff', 'git.log'].map(command => [command,
22
+ (args: unknown, context: PluginNativeContext) => request(command, args, context)]));
31
23
  }
32
24
 
33
25
  /** OS-user credentials for a local desktop workspace, separate from cloud accounts. */
@@ -0,0 +1,125 @@
1
+ import type { PluginWorkbenchView } from './workbench';
2
+
3
+ const WORKSPACE_VIEW_OVERLAY_MAP: Record<string, readonly string[]> = {
4
+ repository: ['files'],
5
+ events: ['tasks', 'calendar'],
6
+ 'plugin-views': ['plugins'],
7
+ };
8
+
9
+ const SIDEBAR_NAV_OVERLAY_MAP: Record<string, readonly string[]> = {
10
+ plan: ['calendar', 'tasks'],
11
+ mail: ['mail'],
12
+ 'view:mail': ['mail'],
13
+ search: ['search'],
14
+ graph: ['graph'],
15
+ files: ['files'],
16
+ objects: ['objects'],
17
+ relations: ['relations'],
18
+ plugins: ['plugins'],
19
+ };
20
+
21
+ function mappedOverlayIds(
22
+ itemId: string,
23
+ table: Record<string, readonly string[]>,
24
+ ): readonly string[] {
25
+ if (itemId in table) return table[itemId];
26
+ const stripped = itemId.startsWith('view:') ? itemId.slice(5) : itemId;
27
+ if (stripped in table) return table[stripped];
28
+ return [];
29
+ }
30
+
31
+ /**
32
+ * Checks whether a home sidebar navigation item or sidebar header button is hidden
33
+ * by an optional host-provided WorkbenchOverlayExtension.
34
+ */
35
+ export function isOverlaySidebarNavHidden(
36
+ itemId: string,
37
+ hidden?: readonly string[],
38
+ ): boolean {
39
+ if (!hidden?.length) return false;
40
+ const mapped = mappedOverlayIds(itemId, SIDEBAR_NAV_OVERLAY_MAP);
41
+ if (!mapped.length) return false;
42
+ if (itemId === 'plan') {
43
+ return hidden.includes('calendar') || hidden.includes('tasks');
44
+ }
45
+ return mapped.some((id) => hidden.includes(id));
46
+ }
47
+
48
+ /**
49
+ * Computes CSS flex `order` style for a home sidebar navigation button when
50
+ * sidebar ordering is provided by an optional host WorkbenchOverlayExtension.
51
+ */
52
+ export function overlaySidebarNavOrderStyle(
53
+ itemId: string,
54
+ order?: readonly string[],
55
+ ): { order: number } | undefined {
56
+ if (!order?.length) return undefined;
57
+ const mapped = mappedOverlayIds(itemId, SIDEBAR_NAV_OVERLAY_MAP);
58
+ if (!mapped.length) return undefined;
59
+ let best = Number.POSITIVE_INFINITY;
60
+ for (const key of mapped) {
61
+ const idx = order.indexOf(key);
62
+ if (idx >= 0 && idx < best) best = idx;
63
+ }
64
+ return Number.isFinite(best) ? { order: best } : undefined;
65
+ }
66
+
67
+ /**
68
+ * Applies optional overlay `hiddenSidebarItems` and `sidebarOrder` to the workspace sidebar
69
+ * view tabs (`repository`, `events`, `assistant`, `plugin-views`, `plugin-sidebar:*`).
70
+ * Always keeps at least one tab visible so the workspace sidebar can never become empty.
71
+ */
72
+ export function applyOverlayToWorkspaceViews<T extends { id: string }>(
73
+ views: readonly T[],
74
+ hidden?: readonly string[],
75
+ order?: readonly string[],
76
+ ): T[] {
77
+ const hiddenSet = new Set(hidden ?? []);
78
+ let filtered = views.filter((view) => {
79
+ const mapped = WORKSPACE_VIEW_OVERLAY_MAP[view.id];
80
+ if (!mapped?.length) return true;
81
+ return !mapped.some((key) => hiddenSet.has(key));
82
+ });
83
+ if (!filtered.length && views.length) {
84
+ filtered = [views[0]];
85
+ }
86
+ if (!order?.length || filtered.length <= 1) return filtered;
87
+
88
+ const rankOf = (viewId: string): number => {
89
+ const mapped = WORKSPACE_VIEW_OVERLAY_MAP[viewId];
90
+ if (!mapped?.length) return Number.POSITIVE_INFINITY;
91
+ let best = Number.POSITIVE_INFINITY;
92
+ for (const key of mapped) {
93
+ const idx = order.indexOf(key);
94
+ if (idx >= 0 && idx < best) best = idx;
95
+ }
96
+ return best;
97
+ };
98
+
99
+ return filtered
100
+ .map((view, index) => ({ view, index, rank: rankOf(view.id) }))
101
+ .sort((a, b) => (a.rank !== b.rank ? a.rank - b.rank : a.index - b.index))
102
+ .map((entry) => entry.view);
103
+ }
104
+
105
+ /**
106
+ * Resolves which Tier 2 custom plugin view (if any) replaces `<EmptyEditor>` inside
107
+ * `.workspace-no-tabs` for the current pane.
108
+ * - Blank new tab (`blank:*`) -> `newTabView`
109
+ * - Empty workspace (no active tab) -> `homeTabView`
110
+ * - Safe Mode always disables custom tab replacement and returns `null`.
111
+ */
112
+ export function resolveOverlayTabView(
113
+ activeTabId: string,
114
+ options: {
115
+ safeMode?: boolean;
116
+ homeTabView?: PluginWorkbenchView | null;
117
+ newTabView?: PluginWorkbenchView | null;
118
+ },
119
+ ): PluginWorkbenchView | null {
120
+ if (options.safeMode) return null;
121
+ if (activeTabId.startsWith('blank:')) {
122
+ return options.newTabView ?? null;
123
+ }
124
+ return options.homeTabView ?? null;
125
+ }
@@ -16,17 +16,89 @@ export function pluginApplicationStorage(): Pick<Storage, 'getItem' | 'setItem'>
16
16
  return { getItem: key => memory.get(key) ?? null, setItem: (key, value) => { memory.set(key, value); } };
17
17
  }
18
18
 
19
+ export const PLUGIN_BINARY_ASSET_LIMIT = 1024 * 1024;
20
+ export const PLUGIN_BINARY_ASSETS_TOTAL_LIMIT = 4 * 1024 * 1024;
21
+
22
+ export interface PluginBinaryAssetReadResult {
23
+ path: string;
24
+ bytes: number;
25
+ base64: string;
26
+ }
27
+
28
+ function normalizeBinaryAssetPath(raw: string): string {
29
+ if (typeof raw !== 'string') throw new Error('插件资产路径无效');
30
+ const normalized = raw.trim().replaceAll('\\', '/').replace(/^assets\/bin\//, '');
31
+ if (
32
+ !normalized ||
33
+ normalized.length > 240 ||
34
+ normalized.startsWith('/') ||
35
+ normalized.endsWith('/') ||
36
+ normalized.includes('//') ||
37
+ /[\u0000-\u001f]/.test(normalized) ||
38
+ normalized.split('/').some((seg) => !seg || seg === '.' || seg === '..')
39
+ ) {
40
+ throw new Error(`插件资产路径无效:${raw}`);
41
+ }
42
+ return normalized;
43
+ }
44
+
45
+ function bytesToBase64(bytes: Uint8Array): string {
46
+ let binary = '';
47
+ const chunkSize = 0x8000;
48
+ for (let i = 0; i < bytes.length; i += chunkSize) {
49
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
50
+ }
51
+ return btoa(binary);
52
+ }
53
+
19
54
  /** Content-addressed application cache; no executable code is written to the workspace. */
20
55
  export class PluginPackageCache {
21
56
  private cache: PluginCacheStorage;
22
57
  constructor(storage: Pick<Storage, 'getItem' | 'setItem'> = pluginApplicationStorage()) { this.cache = new PluginCacheStorage(storage); }
23
- async put(pkg: PluginPackage) {
58
+ async put(pkg: PluginPackage, binaryAssets?: Record<string, Uint8Array>) {
24
59
  const parsed = parsePluginPackage(JSON.stringify(pkg));
25
60
  const integrity = await pluginIntegrity(parsed);
26
61
  const content = canonicalPluginJson(parsed);
27
62
  await this.cache.put({ integrity, pluginId: parsed.manifest.id, version: parsed.manifest.version, bytes: new TextEncoder().encode(content).length, savedAt: new Date().toISOString() }, content);
63
+ if (binaryAssets && Object.keys(binaryAssets).length) {
64
+ await this.putBinaryAssets(integrity, binaryAssets);
65
+ }
28
66
  return integrity;
29
67
  }
68
+ async putBinaryAssets(integrity: string, binaryAssets: Record<string, Uint8Array>) {
69
+ const encoded: Record<string, { bytes: number; base64: string }> = {};
70
+ let total = 0;
71
+ for (const [rawPath, bytes] of Object.entries(binaryAssets)) {
72
+ const path = normalizeBinaryAssetPath(rawPath);
73
+ if (!(bytes instanceof Uint8Array)) throw new Error(`插件资产 ${path} 必须为二进制字节`);
74
+ if (bytes.byteLength > PLUGIN_BINARY_ASSET_LIMIT) {
75
+ throw new Error(`单个插件二进制资产不能超过 1 MiB:${path}`);
76
+ }
77
+ total += bytes.byteLength;
78
+ if (total > PLUGIN_BINARY_ASSETS_TOTAL_LIMIT) {
79
+ throw new Error('插件二进制资产总大小不能超过 4 MiB');
80
+ }
81
+ encoded[path] = { bytes: bytes.byteLength, base64: bytesToBase64(bytes) };
82
+ }
83
+ await this.cache.putAssets(integrity, JSON.stringify({ version: 1, assets: encoded }));
84
+ }
85
+ async listBinaryAssets(integrity: string): Promise<string[]> {
86
+ const raw = await this.cache.getAssets(integrity);
87
+ if (!raw) return [];
88
+ const parsed = JSON.parse(raw) as { version?: number; assets?: Record<string, { bytes: number; base64: string }> };
89
+ if (parsed.version !== 1 || !parsed.assets || typeof parsed.assets !== 'object') return [];
90
+ return Object.keys(parsed.assets).sort();
91
+ }
92
+ async getBinaryAsset(integrity: string, rawPath: string): Promise<PluginBinaryAssetReadResult | null> {
93
+ const path = normalizeBinaryAssetPath(rawPath);
94
+ const raw = await this.cache.getAssets(integrity);
95
+ if (!raw) return null;
96
+ const parsed = JSON.parse(raw) as { version?: number; assets?: Record<string, { bytes: number; base64: string }> };
97
+ if (parsed.version !== 1 || !parsed.assets || !Object.hasOwn(parsed.assets, path)) return null;
98
+ const entry = parsed.assets[path];
99
+ if (!entry || typeof entry.base64 !== 'string' || typeof entry.bytes !== 'number') return null;
100
+ return { path, bytes: entry.bytes, base64: entry.base64 };
101
+ }
30
102
  async get(integrity: string) {
31
103
  const content = await this.cache.get(integrity);
32
104
  if (!content) return null;
@@ -1,4 +1,3 @@
1
1
  /** Host-side pure data helpers shared by foreground and server plugin runtimes. */
2
- export { applyPluginTextEdits, PluginQueryPager } from './data';
3
- export { queryPluginData, type PluginQueryContext } from './queries';
4
- export { mergeObject } from '../objects/workspace-objects';
2
+ export { applyPluginTextEdits, PluginQueryPager, queryPluginData, type PluginQueryContext } from '@tano/protocol/plugin-data';
3
+ export { mergeObject } from '@tano/editor/workspace-objects';
@@ -0,0 +1,57 @@
1
+ import type { PluginPermission } from '@tano/protocol';
2
+ import { t } from '../i18n/i18n';
3
+
4
+ export const pluginPermissionLabels: Record<PluginPermission, string> = {
5
+ get 'attachments.read'() {
6
+ return t('只读访问工作区附件');
7
+ },
8
+ get 'attachments.write'() {
9
+ return t('受限写入工作区附件');
10
+ },
11
+ get 'documents.read'() {
12
+ return t('读取与打开文档');
13
+ },
14
+ get 'documents.write'() {
15
+ return t('创建与修改文档');
16
+ },
17
+ get 'documents.move'() {
18
+ return t('移动与重命名文档');
19
+ },
20
+ get 'documents.trash'() {
21
+ return t('将文档移入回收站');
22
+ },
23
+ get 'objects.read'() {
24
+ return t('读取对象');
25
+ },
26
+ get 'objects.write'() {
27
+ return t('创建与修改对象');
28
+ },
29
+ get 'relations.read'() {
30
+ return t('读取关系');
31
+ },
32
+ get 'relations.write'() {
33
+ return t('修改关系');
34
+ },
35
+ get storage() {
36
+ return t('保存插件本机状态');
37
+ },
38
+ get network() {
39
+ return t('访问指定网络来源');
40
+ },
41
+ get connections() {
42
+ return t('使用单独授权的服务凭据');
43
+ },
44
+ get native() {
45
+ return t('调用指定本机能力');
46
+ },
47
+ get ui() {
48
+ return t('运行隔离的自定义界面');
49
+ },
50
+ get 'ai.invoke'() {
51
+ return t('调用同页助手模型推理(不接触密钥)');
52
+ },
53
+ };
54
+
55
+ export function pluginPermissionLabel(permission: string): string {
56
+ return (pluginPermissionLabels as Record<string, string>)[permission] ?? permission;
57
+ }