@tano.page/workbench 0.14.0 → 0.15.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 (177) hide show
  1. package/package.json +21 -8
  2. package/src/App.vue +76 -17
  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/components/AssistantChangeList.vue +98 -21
  17. package/src/assistant/components/AssistantPanel.vue +424 -7
  18. package/src/assistant/components/PluginToolProposalCard.vue +235 -0
  19. package/src/assistant/engine.ts +56 -3
  20. package/src/assistant/files.ts +5 -13
  21. package/src/assistant/inbox.ts +1 -148
  22. package/src/assistant/locales/de-DE.json +4 -1
  23. package/src/assistant/locales/en-US.json +4 -1
  24. package/src/assistant/locales/es-ES.json +4 -1
  25. package/src/assistant/locales/ja-JP.json +4 -1
  26. package/src/assistant/locales/zh-CN.json +4 -1
  27. package/src/assistant/locales/zh-TW.json +4 -1
  28. package/src/assistant/mention-autocomplete.ts +69 -0
  29. package/src/assistant/prompts.ts +7 -0
  30. package/src/assistant/results.ts +20 -86
  31. package/src/assistant/store.ts +319 -12
  32. package/src/assistant/structures.ts +7 -5
  33. package/src/assistant/tasks.ts +3 -5
  34. package/src/assistant/workspace-bridge.ts +1 -1
  35. package/src/composables/use-document-actions.ts +38 -20
  36. package/src/composables/use-file-tree-controller.ts +7 -12
  37. package/src/composables/use-workbench-history.ts +2 -4
  38. package/src/composables/use-workbench-modals.ts +6 -1
  39. package/src/composables/use-workbench-outline.ts +0 -5
  40. package/src/composables/use-workbench-shortcuts.ts +26 -22
  41. package/src/data-tables/data-tables.ts +1 -2
  42. package/src/documents/components/DocumentHistoryPanel.vue +3 -1
  43. package/src/features.ts +1 -0
  44. package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
  45. package/src/fonts/Inter-Latin.woff2 +0 -0
  46. package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
  47. package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
  48. package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
  49. package/src/help/help-milestones.ts +3 -5
  50. package/src/i18n/locales/de-DE.json +349 -3
  51. package/src/i18n/locales/en-US.json +349 -2
  52. package/src/i18n/locales/es-ES.json +349 -3
  53. package/src/i18n/locales/ja-JP.json +348 -2
  54. package/src/i18n/locales/zh-TW.json +348 -2
  55. package/src/mail/components/MailAccountDialog.vue +449 -0
  56. package/src/mail/components/MailComposerDialog.vue +325 -0
  57. package/src/mail/components/MailProviderIcon.vue +30 -0
  58. package/src/mail/components/MailWorkspaceView.vue +820 -0
  59. package/src/mail/components/SidebarMail.vue +133 -0
  60. package/src/mail/mail-avatar.ts +17 -0
  61. package/src/mail/mail-bridge.ts +68 -0
  62. package/src/mail/mail-calendar.ts +208 -0
  63. package/src/mail/mail-markdown.ts +195 -0
  64. package/src/mail/types.ts +226 -0
  65. package/src/objects/components/ObjectDetailModal.vue +1001 -0
  66. package/src/objects/workspace-objects.ts +1 -1
  67. package/src/plan-sync/types.ts +6 -3
  68. package/src/plans/calendar-interaction.ts +194 -0
  69. package/src/plans/calendar.ts +63 -7
  70. package/src/plans/components/CalendarDayPopover.vue +172 -39
  71. package/src/plans/components/CalendarView.vue +1736 -276
  72. package/src/plans/components/PlanArchiveDialog.vue +295 -0
  73. package/src/plans/components/PlanDateField.vue +6 -4
  74. package/src/plans/components/PlanDetailPanel.vue +227 -32
  75. package/src/plans/components/PlanEventList.vue +16 -4
  76. package/src/plans/components/SidebarPlan.vue +22 -15
  77. package/src/plans/components/TaskRepeatControls.vue +169 -30
  78. package/src/plans/local-reminders.ts +149 -0
  79. package/src/plans/personal-plans.ts +10 -1
  80. package/src/plans/plan-date.ts +8 -1
  81. package/src/plans/plan-migration.ts +95 -0
  82. package/src/plans/recurrence.ts +95 -0
  83. package/src/plans/task-repeat.ts +8 -8
  84. package/src/plans/timeline-layout.ts +92 -0
  85. package/src/plugins/assistant-bridge.ts +520 -0
  86. package/src/plugins/attachment-reader.ts +3 -1
  87. package/src/plugins/cache-storage.ts +42 -2
  88. package/src/plugins/components/PluginAutomations.vue +3 -3
  89. package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
  90. package/src/plugins/components/PluginChangeSummary.vue +16 -3
  91. package/src/plugins/components/PluginConnections.vue +1 -1
  92. package/src/plugins/components/PluginCustomView.vue +2 -2
  93. package/src/plugins/components/PluginDetailPage.vue +129 -54
  94. package/src/plugins/components/PluginDocumentSlot.vue +63 -0
  95. package/src/plugins/components/PluginExplorer.vue +15 -21
  96. package/src/plugins/components/PluginImportDialog.vue +410 -0
  97. package/src/plugins/components/PluginInstaller.vue +39 -145
  98. package/src/plugins/components/PluginListItem.vue +3 -0
  99. package/src/plugins/components/PluginMaintenance.vue +21 -6
  100. package/src/plugins/components/PluginRuntimePanel.vue +3 -3
  101. package/src/plugins/components/PluginSettingsForm.vue +111 -0
  102. package/src/plugins/components/PluginStatusBar.vue +161 -0
  103. package/src/plugins/components/PluginSurface.vue +18 -6
  104. package/src/plugins/components/PluginUiDialog.vue +452 -0
  105. package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
  106. package/src/plugins/excalidraw/manifest.json +12 -1
  107. package/src/plugins/host.ts +662 -43
  108. package/src/plugins/native.ts +2 -10
  109. package/src/plugins/overlay-mapping.ts +125 -0
  110. package/src/plugins/packages.ts +73 -1
  111. package/src/plugins/plugin-permissions.ts +57 -0
  112. package/src/plugins/plugin-sdk.ts +174 -8
  113. package/src/plugins/policy.ts +53 -3
  114. package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
  115. package/src/plugins/presentation-preview/manifest.json +2 -1
  116. package/src/plugins/queries.ts +3 -1
  117. package/src/plugins/sandbox.ts +15 -1
  118. package/src/plugins/use-plugin-actions.ts +67 -20
  119. package/src/plugins/user-plugins.ts +254 -0
  120. package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
  121. package/src/plugins/word-preview/manifest.json +13 -1
  122. package/src/plugins/workbench.ts +175 -2
  123. package/src/plugins/worker.js +105 -8
  124. package/src/plugins/workspace-plugin-runtime.ts +23 -7
  125. package/src/plugins/workspace-plugins.ts +212 -21
  126. package/src/runtime.ts +101 -3
  127. package/src/settings/components/SettingsAppearancePage.vue +46 -0
  128. package/src/settings/components/SettingsDocumentsPage.vue +0 -1
  129. package/src/settings/components/settings-search.ts +2 -3
  130. package/src/shell/components/SidebarNavigation.vue +22 -2
  131. package/src/shell/components/WorkbenchContextMenus.vue +21 -8
  132. package/src/shell/components/WorkbenchModals.vue +27 -46
  133. package/src/shell/components/WorkbenchPanes.vue +267 -84
  134. package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
  135. package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
  136. package/src/shell/use-workbench.ts +116 -145
  137. package/src/shell/workbench-async-components.ts +14 -5
  138. package/src/stores/mail.ts +414 -0
  139. package/src/stores/plan-sync.ts +2 -1
  140. package/src/stores/plans.ts +2 -9
  141. package/src/stores/workspace-knowledge.ts +1 -113
  142. package/src/stores/workspace-plugins-state.ts +537 -14
  143. package/src/stores/workspace-tabs-layout.ts +5 -43
  144. package/src/stores/workspace.ts +69 -66
  145. package/src/styles/agent-diff-modals.css +0 -7
  146. package/src/styles/dark-theme.css +3 -3
  147. package/src/styles/inspector.css +0 -59
  148. package/src/styles/layout-themes.css +346 -0
  149. package/src/styles/mail.css +1568 -0
  150. package/src/styles/mobile.css +2 -2
  151. package/src/styles/recent-and-media.css +0 -17
  152. package/src/styles/theme-contract.css +3 -3
  153. package/src/styles/workbench-shell.css +110 -17
  154. package/src/styles/workspace-states.css +9 -33
  155. package/src/styles.css +1 -1
  156. package/src/tabs/components/DesktopTabs.vue +0 -3
  157. package/src/tabs/components/NewTabPicker.vue +10 -4
  158. package/src/tabs/tab-label.ts +0 -1
  159. package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
  160. package/src/workspace/components/WorkspaceIconPicker.vue +28 -6
  161. package/src/workspace/workspace-comments.ts +11 -151
  162. package/src/workspace/workspace-welcome.ts +1 -1
  163. package/src/documents/components/FormulaMenu.vue +0 -50
  164. package/src/files/components/FileDatabasePage.vue +0 -152
  165. package/src/files/components/FolderHomeIcon.vue +0 -12
  166. package/src/objects/components/ObjectDatabasePage.vue +0 -100
  167. package/src/objects/components/ObjectPanel.vue +0 -554
  168. package/src/plans/components/PersonalPlanDialog.vue +0 -105
  169. package/src/shell/components/WorkspaceViewPage.vue +0 -127
  170. package/src/shell/components/WorkspaceViewTab.vue +0 -24
  171. package/src/styles/object-panel.css +0 -163
  172. package/src/workspace/components/GitInspectionPanel.vue +0 -35
  173. package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
  174. package/src/workspace/welcome-slogans.ts +0 -11
  175. package/src/workspace/workspace-git.ts +0 -35
  176. package/src/workspace/workspace-sync.ts +0 -46
  177. package/src/workspace/workspace-views.ts +0 -48
@@ -23,7 +23,19 @@
23
23
  {
24
24
  "id": "document",
25
25
  "label": "Word 文档预览",
26
- "location": "tab"
26
+ "location": "tab",
27
+ "layout": "fill"
28
+ }
29
+ ],
30
+ "fileHandlers": [
31
+ {
32
+ "extensions": [
33
+ ".doc",
34
+ ".docx"
35
+ ],
36
+ "mode": "preview",
37
+ "view": "document",
38
+ "command": "open"
27
39
  }
28
40
  ]
29
41
  }
@@ -1,5 +1,18 @@
1
1
  import { isElement } from '@tano/editor/dom-realm';
2
- import type { PluginCommandDefinition, PluginViewDefinition } from '@tano/protocol';
2
+ import {
3
+ isDataTableFilePath,
4
+ isWorkspaceInternalPath,
5
+ matchPluginFileExtension,
6
+ type PluginCodeBlockRendererDefinition,
7
+ type PluginCommandDefinition,
8
+ type PluginEditorDecoration,
9
+ type PluginFileHandlerDefinition,
10
+ type PluginFileHandlerMode,
11
+ type PluginSlashCommandDefinition,
12
+ type PluginStatusBarItem,
13
+ type PluginUiBundle,
14
+ type PluginViewDefinition,
15
+ } from '@tano/protocol';
3
16
  import type { InstalledObjectPlugin } from './workspace-plugins';
4
17
  import type { PluginRuntimeState } from './host';
5
18
  import { shortcutBindingFromEvent, shortcutKeys, shortcutDefinitions, type ShortcutBindings } from '../shell/shortcuts';
@@ -10,6 +23,21 @@ export interface PluginWorkbenchView extends PluginViewDefinition {
10
23
  export interface PluginWorkbenchCommand extends PluginCommandDefinition {
11
24
  key: string; pluginId: string; pluginName: string; instanceId: string;
12
25
  }
26
+ export interface PluginWorkbenchFileHandler extends PluginFileHandlerDefinition {
27
+ pluginId: string; pluginName: string; system: boolean; viewKey: string;
28
+ }
29
+ export interface PluginWorkbenchStatusBarItem extends PluginStatusBarItem {
30
+ key: string; pluginId: string; pluginName: string; instanceId: string;
31
+ }
32
+ export interface PluginWorkbenchSlashCommand extends PluginSlashCommandDefinition {
33
+ key: string; pluginId: string; pluginName: string; instanceId: string;
34
+ }
35
+ export interface PluginWorkbenchCodeBlockRenderer extends PluginCodeBlockRendererDefinition {
36
+ key: string; pluginId: string; pluginName: string; instanceId: string; bundle: PluginUiBundle;
37
+ }
38
+ export interface PluginWorkbenchDecoration extends PluginEditorDecoration {
39
+ key: string; pluginId: string; pluginName: string; instanceId: string;
40
+ }
13
41
  export interface PluginInteraction {
14
42
  workspaceId: string; pluginId: string; instanceId: string; kind: 'command' | 'action' | 'message' | 'diagnostic'; name: string; payload?: unknown;
15
43
  }
@@ -22,10 +50,155 @@ export function pluginWorkbenchViews(installations: InstalledObjectPlugin[]): Pl
22
50
  ? manifest.views.map(view => ({ ...view, key: pluginViewKey(manifest.id, view.id), pluginId: manifest.id, pluginName: manifest.name })) : []);
23
51
  }
24
52
  export function pluginWorkbenchCommands(states: PluginRuntimeState[]): PluginWorkbenchCommand[] {
25
- return states.filter(state => state.status === 'running').flatMap(state => state.commands.map(command => ({
53
+ return states.filter(state => state.status === 'running' || state.status === 'idle').flatMap(state => state.commands.map(command => ({
26
54
  ...command, key: `plugin:${state.id}:${command.id}`, pluginId: state.id, pluginName: state.name, instanceId: state.instanceId,
27
55
  })));
28
56
  }
57
+ export function pluginWorkbenchStatusBarItems(states: PluginRuntimeState[]): PluginWorkbenchStatusBarItem[] {
58
+ return states
59
+ .filter(state => state.status === 'running')
60
+ .flatMap(state =>
61
+ (state.statusBar ?? []).map(item => ({
62
+ ...item,
63
+ key: `plugin:${state.id}:status:${item.id}`,
64
+ pluginId: state.id,
65
+ pluginName: state.name,
66
+ instanceId: state.instanceId,
67
+ })),
68
+ )
69
+ .sort((left, right) =>
70
+ (right.priority ?? 0) - (left.priority ?? 0) ||
71
+ left.pluginId.localeCompare(right.pluginId) ||
72
+ left.id.localeCompare(right.id),
73
+ );
74
+ }
75
+ export function pluginWorkbenchSlashCommands(
76
+ installations: InstalledObjectPlugin[],
77
+ states: PluginRuntimeState[],
78
+ ): PluginWorkbenchSlashCommand[] {
79
+ const active = new Map(
80
+ states.filter(state => state.status === 'running' || state.status === 'idle').map(state => [state.id, state]),
81
+ );
82
+ return installations.flatMap(item => {
83
+ const { manifest } = item;
84
+ if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.slashCommands?.length) return [];
85
+ const runtime = active.get(manifest.id);
86
+ if (!runtime) return [];
87
+ const registered = new Set(runtime.commands.map(command => command.id));
88
+ return manifest.slashCommands
89
+ .filter(slash => registered.has(slash.command))
90
+ .map(slash => ({
91
+ ...slash,
92
+ key: `plugin:${manifest.id}:slash:${slash.id}`,
93
+ pluginId: manifest.id,
94
+ pluginName: manifest.name,
95
+ instanceId: runtime.instanceId,
96
+ }));
97
+ });
98
+ }
99
+ export function pluginWorkbenchCodeBlockRenderers(
100
+ installations: InstalledObjectPlugin[],
101
+ states: PluginRuntimeState[],
102
+ ): PluginWorkbenchCodeBlockRenderer[] {
103
+ const running = new Map(states.filter(state => state.status === 'running').map(state => [state.id, state]));
104
+ return installations.flatMap(item => {
105
+ const { manifest } = item;
106
+ if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.codeBlockRenderers?.length) return [];
107
+ const runtime = running.get(manifest.id);
108
+ if (!runtime?.uiBundles) return [];
109
+ return manifest.codeBlockRenderers.flatMap(renderer => {
110
+ const bundle = Object.hasOwn(runtime.uiBundles!, renderer.view) ? runtime.uiBundles![renderer.view] : undefined;
111
+ if (!bundle) return [];
112
+ return [
113
+ {
114
+ ...renderer,
115
+ key: `plugin:${manifest.id}:codeblock:${renderer.view}`,
116
+ pluginId: manifest.id,
117
+ pluginName: manifest.name,
118
+ instanceId: runtime.instanceId,
119
+ bundle,
120
+ },
121
+ ];
122
+ });
123
+ });
124
+ }
125
+ export function pluginWorkbenchDecorations(
126
+ states: PluginRuntimeState[],
127
+ fileId: string,
128
+ ): PluginWorkbenchDecoration[] {
129
+ if (!fileId) return [];
130
+ return states
131
+ .filter(state => state.status === 'running')
132
+ .flatMap(state =>
133
+ (state.decorations?.[fileId] ?? []).map((item, index) => ({
134
+ ...item,
135
+ key: `plugin:${state.id}:deco:${fileId}:${item.id ?? index}`,
136
+ pluginId: state.id,
137
+ pluginName: state.name,
138
+ instanceId: state.instanceId,
139
+ })),
140
+ );
141
+ }
142
+ export function pluginWorkbenchFileHandlers(
143
+ installations: InstalledObjectPlugin[],
144
+ states: PluginRuntimeState[],
145
+ ): PluginWorkbenchFileHandler[] {
146
+ const active = new Map(states.filter(state => state.status === 'running' || state.status === 'idle').map(state => [state.id, state]));
147
+ return installations.flatMap(item => {
148
+ const { manifest } = item;
149
+ if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.fileHandlers?.length) return [];
150
+ const runtime = active.get(manifest.id);
151
+ if (!runtime) return [];
152
+ const registered = new Set(runtime.commands.map(command => command.id));
153
+ return manifest.fileHandlers
154
+ .filter(handler => registered.has(handler.command))
155
+ .map(handler => ({
156
+ ...handler,
157
+ pluginId: manifest.id,
158
+ pluginName: manifest.name,
159
+ system: !!item.system,
160
+ viewKey: pluginViewKey(manifest.id, handler.view),
161
+ }));
162
+ });
163
+ }
164
+ export function resolvePluginFileHandler(
165
+ path: string,
166
+ mode: PluginFileHandlerMode,
167
+ handlers: readonly PluginWorkbenchFileHandler[],
168
+ ): PluginWorkbenchFileHandler | undefined {
169
+ if (!path || isWorkspaceInternalPath(path) || isDataTableFilePath(path)) return undefined;
170
+ let bestLength = 0;
171
+ let matches: PluginWorkbenchFileHandler[] = [];
172
+ for (const handler of handlers) {
173
+ if (handler.mode !== mode) continue;
174
+ let longest = 0;
175
+ for (const ext of handler.extensions) {
176
+ if (matchPluginFileExtension(path, ext) && ext.length > longest) longest = ext.length;
177
+ }
178
+ if (!longest) continue;
179
+ if (longest > bestLength) {
180
+ bestLength = longest;
181
+ matches = [handler];
182
+ } else if (longest === bestLength) {
183
+ matches.push(handler);
184
+ }
185
+ }
186
+ if (matches.length === 1) return matches[0];
187
+ if (matches.length > 1) {
188
+ const systemMatches = matches.filter(item => item.system);
189
+ if (systemMatches.length === 1) return systemMatches[0];
190
+ }
191
+ return undefined;
192
+ }
193
+ export function isPluginPreviewTab(tabId: string, installations: readonly InstalledObjectPlugin[]): boolean {
194
+ return installations.some(item =>
195
+ item.enabled &&
196
+ item.manifest.manifestVersion === 2 &&
197
+ !!item.manifest.fileHandlers?.some(
198
+ handler => handler.mode === 'preview' && pluginViewKey(item.manifest.id, handler.view) === tabId,
199
+ ),
200
+ );
201
+ }
29
202
  // Host/editor bindings win. Ambiguous plugin bindings never trigger either command.
30
203
  // Formatting/navigation and browser reserved keys must remain available to the host.
31
204
  const reserved = new Set(['Mod+B', 'Mod+I', 'Mod+U', 'Mod+Z', 'Mod+Y', 'Mod+Shift+Z', 'Mod+A', 'Mod+C', 'Mod+V', 'Mod+X', 'Mod+L', 'Mod+R', 'Mod+W', 'Mod+T', 'Mod+P', 'F5', 'F12']);
@@ -3,7 +3,11 @@ const pending = new Map();
3
3
  const commands = new Map();
4
4
  const actions = new Map();
5
5
  const viewMessages = new Map();
6
+ const assistantTools = new Map();
7
+ const assistantContextProviders = new Map();
8
+ const services = new Map();
6
9
  const listeners = new Set();
10
+ const deactivators = new Set();
7
11
  for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
8
12
  console[level] = (...values) => {
9
13
  const message = values.map(value => { try { return value instanceof Error ? value.stack || String(value) : typeof value === 'string' ? value : JSON.stringify(value); } catch { return String(value); } }).join(' ').slice(0, 1500);
@@ -12,16 +16,31 @@ for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
12
16
  }
13
17
  addEventListener('unhandledrejection', event => { console.error(event.reason); event.preventDefault(); });
14
18
  let sequence = 0;
15
- const call = (method, params = {}) => new Promise((resolve, reject) => {
19
+ const call = (method, params = {}, timeoutMs = 30000) => new Promise((resolve, reject) => {
16
20
  if (pending.size >= 32) return reject(new Error('插件请求过多'));
17
21
  const id = ++sequence;
18
- const timer = setTimeout(() => { pending.delete(id); reject(new Error('插件请求超时')); }, 30000);
22
+ const timer = setTimeout(() => { pending.delete(id); reject(new Error('插件请求超时')); }, timeoutMs);
19
23
  pending.set(id, { resolve, reject, timer });
20
24
  postMessage({ type: 'call', id, method, params });
21
25
  });
22
26
  const tano = Object.freeze({
23
27
  context: () => call('context'),
24
- attachments: Object.freeze({ read: (fileId, offset = 0, revision) => call('attachments.read', { fileId, offset, revision }) }),
28
+ hostInfo: () => call('hostInfo'),
29
+ lifecycle: Object.freeze({
30
+ onDeactivate: handler => {
31
+ if (typeof handler !== 'function') throw new Error('卸载回调必须提供处理函数');
32
+ deactivators.add(handler);
33
+ return () => deactivators.delete(handler);
34
+ },
35
+ }),
36
+ assets: Object.freeze({
37
+ list: () => call('assets.list'),
38
+ read: path => call('assets.read', { path }),
39
+ }),
40
+ attachments: Object.freeze({
41
+ read: (fileId, offset = 0, revision) => call('attachments.read', { fileId, offset, revision }),
42
+ write: request => call('attachments.write', { request }),
43
+ }),
25
44
  documents: Object.freeze({
26
45
  list: () => call('documents.list'),
27
46
  query: options => call('documents.query', { options }),
@@ -30,7 +49,20 @@ const tano = Object.freeze({
30
49
  write: (fileId, content, baseHash) => call('documents.write', { fileId, content, baseHash }),
31
50
  edit: (fileId, edits, baseHash) => call('documents.edit', { fileId, edits, baseHash }),
32
51
  create: (path, content) => call('documents.create', { path, content }),
52
+ move: (fileId, destination, baseHash) => call('documents.move', { fileId, destination, baseHash }),
53
+ trash: (fileId, baseHash) => call('documents.trash', { fileId, baseHash }),
33
54
  open: fileId => call('documents.open', { fileId }),
55
+ frontmatter: Object.freeze({
56
+ read: fileId => call('documents.frontmatter.read', { fileId }),
57
+ update: (fileId, patch, baseHash) => call('documents.frontmatter.update', { fileId, patch, baseHash }),
58
+ }),
59
+ }),
60
+ editor: Object.freeze({
61
+ active: () => call('editor.active'),
62
+ insert: text => call('editor.insert', { text }),
63
+ replaceSelection: text => call('editor.replaceSelection', { text }),
64
+ setDecorations: (fileId, decorations) => call('editor.setDecorations', { fileId, decorations }),
65
+ clearDecorations: fileId => call('editor.clearDecorations', fileId === undefined ? {} : { fileId }),
34
66
  }),
35
67
  objects: Object.freeze({ list: () => call('objects.list'), query: options => call('objects.query', { options }), read: objectId => call('objects.read', { objectId }), create: object => call('objects.create', { object }),
36
68
  update: (object, baseHash) => call('objects.update', { object, baseHash }) }),
@@ -50,6 +82,39 @@ const tano = Object.freeze({
50
82
  open: id => call('views.open', { id }),
51
83
  onMessage: (id, handler) => { viewMessages.set(id, handler); return () => viewMessages.delete(id); },
52
84
  onAction: (id, handler) => { actions.set(id, handler); return () => actions.delete(id); } }),
85
+ ui: Object.freeze({
86
+ pick: options => call('ui.pick', { options }, 300000),
87
+ prompt: options => call('ui.prompt', { options }, 300000),
88
+ confirm: options => call('ui.confirm', { options }, 300000),
89
+ toast: (message, tone) => call('ui.toast', tone === undefined ? { message } : { message, tone }),
90
+ setStatusBar: item => call('ui.setStatusBar', { item }),
91
+ removeStatusBar: id => call('ui.removeStatusBar', { id }),
92
+ }),
93
+ ai: Object.freeze({
94
+ complete: request => call('ai.complete', { request }, 65000),
95
+ structured: request => call('ai.structured', { request }, 65000),
96
+ }),
97
+ assistant: Object.freeze({
98
+ registerTool: async (name, handler) => {
99
+ if (typeof handler !== 'function') throw new Error('助手工具必须提供处理函数');
100
+ assistantTools.set(name, handler);
101
+ await call('assistant.registerTool', { name });
102
+ },
103
+ registerContextProvider: async (id, handler) => {
104
+ if (typeof handler !== 'function') throw new Error('助手上下文提供者必须提供处理函数');
105
+ assistantContextProviders.set(id, handler);
106
+ await call('assistant.registerContextProvider', { id });
107
+ },
108
+ }),
109
+ services: Object.freeze({
110
+ register: async (name, handler) => {
111
+ if (typeof handler !== 'function') throw new Error('插件服务必须提供处理函数');
112
+ services.set(name, handler);
113
+ await call('services.register', { name });
114
+ },
115
+ call: (pluginId, service, payload = null) => call('services.call', { pluginId, service, payload }, 20000),
116
+ available: (pluginId, service) => call('services.available', { pluginId, service }),
117
+ }),
53
118
  events: Object.freeze({ subscribe: (handler, options = {}) => {
54
119
  if (typeof handler !== 'function') throw new Error('事件必须提供处理函数');
55
120
  const listener = event => {
@@ -70,13 +135,45 @@ onmessage = async ({ data }) => {
70
135
  const request = pending.get(data.id);
71
136
  if (!request) return;
72
137
  clearTimeout(request.timer); pending.delete(data.id);
73
- if (data.error) request.reject(new Error(data.error)); else request.resolve(data.result);
138
+ if (data.error) {
139
+ const error = new Error(data.error);
140
+ if (typeof data.code === 'string') {
141
+ error.name = 'TanoPluginError';
142
+ error.code = data.code;
143
+ error.retryable = !!data.retryable;
144
+ }
145
+ request.reject(error);
146
+ } else request.resolve(data.result);
147
+ } else if (data?.type === 'deactivate') {
148
+ (async () => {
149
+ for (const handler of [...deactivators]) {
150
+ try { await handler(); } catch (error) { postMessage({ type: 'log', level: 'warn', error: String(error) }); }
151
+ }
152
+ deactivators.clear();
153
+ })().finally(() => postMessage({ type: 'deactivated' }));
74
154
  } else if (data?.type === 'invoke') {
75
155
  try {
76
- const handler = data.kind === 'command' ? commands.get(data.name) : data.kind === 'message' ? viewMessages.get(data.name) : actions.get(data.name);
77
- if (!handler) throw new Error('插件处理函数尚未注册');
78
- await handler(data.payload);
79
- postMessage({ type: 'invoked', id: data.id });
156
+ if (data.kind === 'assistant-tool') {
157
+ const handler = assistantTools.get(data.name);
158
+ if (!handler) throw new Error('插件助手工具处理函数尚未注册');
159
+ const result = await handler(data.payload?.args ?? {}, data.payload?.context ?? {});
160
+ postMessage({ type: 'invoked', id: data.id, result });
161
+ } else if (data.kind === 'assistant-context') {
162
+ const handler = assistantContextProviders.get(data.name);
163
+ if (!handler) throw new Error('插件助手上下文提供者尚未注册');
164
+ const result = await handler(data.payload?.query ?? '', data.payload?.context ?? {});
165
+ postMessage({ type: 'invoked', id: data.id, result });
166
+ } else if (data.kind === 'service') {
167
+ const handler = services.get(data.name);
168
+ if (!handler) throw new Error('插件服务处理函数尚未注册');
169
+ const result = await handler(data.payload?.args ?? null, { pluginId: data.payload?.callerPluginId ?? '' });
170
+ postMessage({ type: 'invoked', id: data.id, result });
171
+ } else {
172
+ const handler = data.kind === 'command' ? commands.get(data.name) : data.kind === 'message' ? viewMessages.get(data.name) : actions.get(data.name);
173
+ if (!handler) throw new Error('插件处理函数尚未注册');
174
+ await handler(data.payload);
175
+ postMessage({ type: 'invoked', id: data.id });
176
+ }
80
177
  } catch (error) { postMessage({ type: 'invoked', id: data.id, error: String(error) }); }
81
178
  } else if (data?.type === 'event') {
82
179
  for (const listener of listeners) Promise.resolve().then(() => listener(data.event)).catch(error => postMessage({ type: 'log', error: String(error) }));
@@ -71,10 +71,15 @@ export class WorkspacePluginRuntime {
71
71
  signal.throwIfAborted();
72
72
  return parsePluginCatalog(JSON.stringify(value));
73
73
  }
74
- installCatalogRelease = async (release: PluginCatalogRelease, expectedWorkspace: string, signal: AbortSignal) => {
74
+ installCatalogRelease = async (
75
+ release: PluginCatalogRelease,
76
+ expectedWorkspace: string,
77
+ signal: AbortSignal,
78
+ scope: 'workspace' | 'user' = 'workspace',
79
+ ) => {
75
80
  const assertCurrent = () => {
76
81
  signal.throwIfAborted();
77
- this.assertWorkspace(expectedWorkspace, true);
82
+ this.assertWorkspace(expectedWorkspace, scope === 'workspace');
78
83
  };
79
84
  assertCurrent();
80
85
  if (!this.host.services?.catalog || release.status !== 'published') throw new Error('此目录版本不可安装');
@@ -84,21 +89,32 @@ export class WorkspacePluginRuntime {
84
89
  await verifyCatalogPackage(release, pkg); assertCurrent();
85
90
  return this.host.serial(async () => {
86
91
  assertCurrent(); await this.refresh(); assertCurrent();
87
- await this.policy.changeWorkspace(this.host.adapter, this.host.workspace()!, { install: pkg.manifest, package: pkg, sourceUrl: downloaded.sourceUrl }, assertCurrent, this.host.services?.repository);
92
+ await this.policy.changeWorkspace(
93
+ this.host.adapter,
94
+ this.host.workspace()!,
95
+ { install: pkg.manifest, package: pkg, sourceUrl: downloaded.sourceUrl, scope },
96
+ assertCurrent,
97
+ scope === 'workspace' ? this.host.services?.repository : undefined,
98
+ );
88
99
  assertCurrent(); await this.refresh();
89
100
  });
90
101
  }
91
- authorizePlugin = async (id: string, integrity: string | undefined, expectedWorkspace: string) => {
102
+ authorizePlugin = async (
103
+ id: string,
104
+ integrity: string | undefined,
105
+ expectedWorkspace: string,
106
+ options?: { allWorkspaces?: boolean },
107
+ ) => {
92
108
  if (!integrity && this.host.workspace()?.id === expectedWorkspace && this.developmentState.pluginId === id) this.developer.stop();
93
109
  return this.host.serial(async () => {
94
110
  this.assertWorkspace(expectedWorkspace);
95
- this.policy.authorize(expectedWorkspace, id, integrity);
111
+ this.policy.authorize(expectedWorkspace, id, integrity, undefined, options);
96
112
  await this.host.refresh();
97
113
  });
98
114
  }
99
- cachePluginPackage = async (content: string) => {
115
+ cachePluginPackage = async (content: string, binaryAssets?: Record<string, Uint8Array>) => {
100
116
  const pkg = parsePluginPackage(content);
101
- const integrity = await new PluginPackageCache().put(pkg);
117
+ const integrity = await new PluginPackageCache().put(pkg, binaryAssets);
102
118
  this.executor.invalidate(pkg.manifest.id);
103
119
  return integrity;
104
120
  }