@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,50 +1,59 @@
1
1
  import { computed, onScopeDispose, ref, shallowRef, watch, type Ref } from 'vue';
2
2
  import type { WorkspaceCapabilities } from '@tano/editor/runtime';
3
- import { mergeMarkdown } from '@tano/markdown';
4
3
  import {
5
4
  FileRegistry,
6
5
  isMarkdown,
7
6
  isWorkspaceInternalPath,
8
- objectDirectory,
9
- parseObject,
10
7
  parsePluginConnectionInput,
11
- pluginRecord,
12
- referenceKey,
13
- validateObjectProperties,
14
- validatePath,
15
- validateRelation,
16
8
  type FileEntry,
17
9
  type FileSnapshot,
18
10
  type PluginConnectionInput,
11
+ type PluginHostEnvironment,
19
12
  type PluginOAuthInput,
20
13
  type ReferenceTarget,
21
14
  type RelationTypeDefinition,
22
15
  type Workspace,
23
16
  type WorkspaceAdapter,
17
+ type WorkspacePersonalPluginPolicy,
24
18
  type WorkspaceRelation,
25
19
  } from '@tano/protocol';
26
- import { assistantHash } from '../assistant/hash';
27
- import { nativeAttachments } from '../files/attachments';
20
+ import workbenchPackage from '../../package.json';
28
21
  import type { useDocumentIndex } from '../documents/document-index';
29
- import { documentDirty as dirty, type OpenDocument } from '../documents/document-session';
22
+ import type { OpenDocument } from '../documents/document-session';
30
23
  import { t } from '../i18n/i18n';
31
24
  import { PluginAttachmentReader } from '../plugins/attachment-reader';
25
+ import { listActivePluginContextProviders } from '../plugins/assistant-bridge';
32
26
  import { PluginQueryPager, pluginChanges } from '../plugins/data';
33
27
  import type { PluginDevelopmentState } from '../plugins/development';
34
28
  import type { PluginRuntimeState } from '../plugins/host';
35
29
  import { canManageWorkspacePlugins } from '../plugins/policy';
36
- import { queryPluginData } from '../plugins/queries';
30
+ import {
31
+ dispatchPluginRpcCall,
32
+ type PluginAiRunner,
33
+ type PluginEditorBridge,
34
+ } from '../plugins/plugin-rpc-router';
35
+ import {
36
+ createPluginUiDialogs,
37
+ type PluginUiDialogRequest,
38
+ type PluginUiToastItem,
39
+ } from '../plugins/plugin-ui-dialogs';
37
40
  import {
38
41
  pluginViewKey,
42
+ pluginWorkbenchCodeBlockRenderers,
39
43
  pluginWorkbenchCommands,
44
+ pluginWorkbenchDecorations,
45
+ pluginWorkbenchFileHandlers,
46
+ pluginWorkbenchSlashCommands,
47
+ pluginWorkbenchStatusBarItems,
40
48
  pluginWorkbenchViews,
41
49
  type PluginInteraction,
42
50
  } from '../plugins/workbench';
43
- import type { WorkbenchRuntime } from '../runtime';
44
- import { mergeObject, saveObject, type ObjectRecord } from '../objects/workspace-objects';
51
+ import { resolveOverlayExtension, type WorkbenchOverlaySnapshot, type WorkbenchRuntime } from '../runtime';
52
+ import type { ObjectRecord } from '../objects/workspace-objects';
45
53
  import { WorkspacePluginRuntime } from '../plugins/workspace-plugin-runtime';
46
54
  import { PLUGINS_TAB_ID, type InstalledObjectPlugin } from '../plugins/workspace-plugins';
47
- import { saveRelationChange } from '../objects/workspace-relations';
55
+
56
+ export type { PluginUiDialogRequest, PluginUiToastItem, PluginEditorBridge };
48
57
 
49
58
  export interface WorkspacePluginsStateDeps {
50
59
  adapter: WorkspaceAdapter;
@@ -104,7 +113,8 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
104
113
  } = deps;
105
114
 
106
115
  const pluginAttachmentReader = new PluginAttachmentReader();
107
- let pluginEditorEdit: ((id: string, before: string, after: string) => Promise<boolean>) | undefined;
116
+ let pluginEditorBridge: PluginEditorBridge | undefined;
117
+ let pluginAiRunner: PluginAiRunner | undefined;
108
118
  const pluginRuntime = shallowRef<PluginRuntimeState[]>([]);
109
119
  watch(
110
120
  [
@@ -118,7 +128,11 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
118
128
  () => !!workspace.value && canManageWorkspacePlugins(adapter, workspace.value),
119
129
  );
120
130
  const pluginStorageChanged = (event: StorageEvent) => {
121
- if (event.key?.startsWith('tano.object-plugins.v1.') || event.key?.startsWith('tano.plugin-'))
131
+ if (
132
+ event.key?.startsWith('tano.object-plugins.v1.') ||
133
+ event.key?.startsWith('tano.plugin-') ||
134
+ event.key?.startsWith('tano.user-plugins.v1.')
135
+ )
122
136
  scheduleRefresh();
123
137
  };
124
138
  if (typeof window !== 'undefined') window.addEventListener('storage', pluginStorageChanged);
@@ -127,14 +141,85 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
127
141
  });
128
142
 
129
143
  const installedPluginWorkspace = ref('');
144
+ const personalCodePluginPolicy = ref<WorkspacePersonalPluginPolicy>('allow');
145
+ const overlayExtension = () => resolveOverlayExtension(runtime);
146
+ const overlaySnapshot = computed<WorkbenchOverlaySnapshot>(
147
+ () => overlayExtension()?.snapshot ?? { safeMode: false },
148
+ );
130
149
  const pluginDevelopment = shallowRef<PluginDevelopmentState>({
131
150
  pluginId: '',
132
151
  active: false,
133
152
  message: '',
134
153
  });
154
+ const pluginHostEnvironment: PluginHostEnvironment = runtime.plugins?.host ?? {
155
+ coreVersion: workbenchPackage.version,
156
+ platform: runtime.mobile
157
+ ? 'mobile'
158
+ : adapter.mode === 'desktop'
159
+ ? 'desktop-local'
160
+ : runtime.native
161
+ ? 'desktop-online'
162
+ : 'web',
163
+ };
164
+
165
+ const uiDialogs = createPluginUiDialogs();
166
+ const {
167
+ activePluginDialog,
168
+ pluginToasts,
169
+ cancelActivePluginDialog,
170
+ resolvePluginDialog,
171
+ dismissPluginToast,
172
+ clearPluginToasts,
173
+ showPluginToast,
174
+ openPluginDialog,
175
+ } = uiDialogs;
176
+
177
+ const pluginCall = (
178
+ method: string,
179
+ params: Record<string, unknown>,
180
+ assertInstance: () => void,
181
+ ) =>
182
+ dispatchPluginRpcCall(
183
+ {
184
+ adapter,
185
+ runtime,
186
+ workspace,
187
+ fileRegistry,
188
+ documents,
189
+ documentIndex,
190
+ capabilities,
191
+ objects,
192
+ relations,
193
+ relationError,
194
+ getRelationBase,
195
+ relationDefinitions,
196
+ referenceTargets,
197
+ pluginAttachmentReader,
198
+ pluginQueryPager,
199
+ getPluginEditorBridge: () => pluginEditorBridge,
200
+ getPluginAiRunner: () => pluginAiRunner,
201
+ openPluginDialog,
202
+ showPluginToast,
203
+ openPluginView,
204
+ serial,
205
+ writable,
206
+ refreshObjects,
207
+ openInternal,
208
+ saveInternal,
209
+ ensureTabNavigation,
210
+ touchNavigation,
211
+ },
212
+ method,
213
+ params,
214
+ assertInstance,
215
+ );
216
+
135
217
  const pluginServices = new WorkspacePluginRuntime({
136
218
  adapter,
137
- services: runtime.plugins,
219
+ services: {
220
+ ...runtime.plugins,
221
+ host: pluginHostEnvironment,
222
+ },
138
223
  serial,
139
224
  refresh: refreshObjects,
140
225
  call: pluginCall,
@@ -156,6 +241,19 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
156
241
 
157
242
  const pluginViews = computed(() => pluginWorkbenchViews(installedPlugins.value));
158
243
  const pluginCommands = computed(() => pluginWorkbenchCommands(pluginRuntime.value));
244
+ const pluginFileHandlers = computed(() =>
245
+ pluginWorkbenchFileHandlers(installedPlugins.value, pluginRuntime.value),
246
+ );
247
+ const pluginSlashCommands = computed(() =>
248
+ pluginWorkbenchSlashCommands(installedPlugins.value, pluginRuntime.value),
249
+ );
250
+ const pluginCodeBlockRenderers = computed(() =>
251
+ pluginWorkbenchCodeBlockRenderers(installedPlugins.value, pluginRuntime.value),
252
+ );
253
+ const pluginDecorationsFor = (fileId: string) =>
254
+ pluginWorkbenchDecorations(pluginRuntime.value, fileId);
255
+ const pluginStatusBarItems = computed(() => pluginWorkbenchStatusBarItems(pluginRuntime.value));
256
+ const activeDocumentPluginSidebar = ref('');
159
257
  const pluginSettingsRequest = shallowRef<{ key: string; sequence: number }>();
160
258
  const pluginSettingsPages = computed(() =>
161
259
  pluginViews.value
@@ -172,7 +270,38 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
172
270
  () => workspace.value?.id,
173
271
  () => {
174
272
  activePluginSidebar.value = '';
273
+ activeDocumentPluginSidebar.value = '';
175
274
  pluginSettingsRequest.value = undefined;
275
+ cancelActivePluginDialog('工作区已切换');
276
+ clearPluginToasts();
277
+ },
278
+ );
279
+ watch(pluginViews, (views) => {
280
+ if (
281
+ activeDocumentPluginSidebar.value &&
282
+ !views.some(
283
+ (view) => view.location === 'documentSidebar' && view.key === activeDocumentPluginSidebar.value,
284
+ )
285
+ ) {
286
+ activeDocumentPluginSidebar.value = '';
287
+ }
288
+ });
289
+ watch(
290
+ () => {
291
+ const id = activeId.value;
292
+ const entry = id ? fileRegistry.value?.get(id) : undefined;
293
+ return entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : '';
294
+ },
295
+ (docId, prevDocId) => {
296
+ if (!docId || docId === prevDocId || !workspace.value) return;
297
+ for (const view of pluginViews.value) {
298
+ if (view.location === 'documentHeader' || view.location === 'documentFooter') {
299
+ if (pluginRuntime.value.some((rt) => rt.id === view.pluginId && rt.status === 'idle')) {
300
+ void pluginExecutor.ensureActivated(view.pluginId).catch(() => {});
301
+ }
302
+ }
303
+ }
304
+ pluginExecutor.notify({ type: 'workspace.changed', fileId: docId });
176
305
  },
177
306
  );
178
307
 
@@ -246,13 +375,37 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
246
375
  { immediate: true },
247
376
  );
248
377
 
378
+ watch(
379
+ () => (workspace.value ? ([workspace.value.id, overlaySnapshot.value.safeMode] as const) : null),
380
+ (current, previous) => {
381
+ if (current && previous && current[0] === previous[0] && current[1] !== previous[1] && workspace.value) {
382
+ pluginExecutor.sync(workspace.value, installedPlugins.value, current[1]);
383
+ }
384
+ },
385
+ );
386
+
387
+ watch(
388
+ () => {
389
+ const id = activeId.value;
390
+ const entry = id ? fileRegistry.value?.get(id) : undefined;
391
+ return entry && !isWorkspaceInternalPath(entry.path) ? entry.path : '';
392
+ },
393
+ (docPath) => {
394
+ if (workspace.value) overlayExtension()?.syncContext?.(workspace.value.id, docPath);
395
+ },
396
+ { immediate: true },
397
+ );
398
+
249
399
  async function refreshPlugins(current: Workspace) {
250
400
  try {
251
- const installed = await pluginHost.loadWorkspace(adapter, current);
401
+ const activeEntry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
402
+ overlayExtension()?.syncContext?.(current.id, activeEntry?.path ?? '');
403
+ const installed = await pluginHost.loadWorkspace(adapter, current, runtime.plugins?.repository);
252
404
  if (workspace.value?.id !== current.id) return;
253
405
  installedPlugins.value = installed;
254
406
  installedPluginWorkspace.value = current.id;
255
- pluginExecutor.sync(current, installedPlugins.value);
407
+ personalCodePluginPolicy.value = pluginHost.personalCodePluginPolicy();
408
+ pluginExecutor.sync(current, installedPlugins.value, overlaySnapshot.value.safeMode);
256
409
  pluginError.value = '';
257
410
  } catch (error) {
258
411
  pluginExecutor.dispose();
@@ -265,13 +418,19 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
265
418
  function openPluginView(pluginId: string, viewId: string) {
266
419
  const view = pluginViews.value.find((view) => view.key === pluginViewKey(pluginId, viewId));
267
420
  if (!workspace.value || !view) throw new Error('插件视图已停用或不存在');
268
- if (view.location === 'tab') {
421
+ if (pluginRuntime.value.some((rt) => rt.id === pluginId && rt.status === 'idle')) {
422
+ void pluginExecutor.ensureActivated(pluginId).catch(() => {});
423
+ }
424
+ if (view.location === 'tab' || view.location === 'homeTab' || view.location === 'newTab') {
269
425
  if (!tabIds.value.includes(view.key)) tabIds.value.push(view.key);
270
426
  activeId.value = view.key;
271
427
  ensureTabNavigation(view.key);
272
428
  touchNavigation();
273
429
  } else if (view.location === 'sidebar') activePluginSidebar.value = view.key;
274
- else if (view.location === 'settings')
430
+ else if (view.location === 'documentSidebar') activeDocumentPluginSidebar.value = view.key;
431
+ else if (view.location === 'documentHeader' || view.location === 'documentFooter') {
432
+ // Document header/footer slots render automatically on the active document.
433
+ } else if (view.location === 'settings')
275
434
  pluginSettingsRequest.value = {
276
435
  key: view.key,
277
436
  sequence: (pluginSettingsRequest.value?.sequence ?? 0) + 1,
@@ -284,6 +443,46 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
284
443
  }
285
444
  }
286
445
 
446
+ const pluginContextProviders = computed(() =>
447
+ listActivePluginContextProviders(installedPlugins.value, pluginRuntime.value),
448
+ );
449
+ const pluginHomeTabView = computed(() => {
450
+ if (overlaySnapshot.value.safeMode) return null;
451
+ const pinnedKey = overlaySnapshot.value.homeTabViewKey;
452
+ if (pinnedKey) {
453
+ return pluginViews.value.find((view) => view.key === pinnedKey && view.location === 'homeTab') ?? null;
454
+ }
455
+ return pluginViews.value.find((view) => view.location === 'homeTab') ?? null;
456
+ });
457
+ const pluginNewTabView = computed(() => {
458
+ if (overlaySnapshot.value.safeMode) return null;
459
+ const pinnedKey = overlaySnapshot.value.newTabViewKey;
460
+ if (pinnedKey) {
461
+ return pluginViews.value.find((view) => view.key === pinnedKey && view.location === 'newTab') ?? null;
462
+ }
463
+ return pluginViews.value.find((view) => view.location === 'newTab') ?? null;
464
+ });
465
+
466
+ function invokePluginAssistantTool(pluginId: string, toolName: string, args: Record<string, unknown>) {
467
+ if (!workspace.value) return Promise.reject(new Error('请先打开工作区'));
468
+ const entry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
469
+ const activeFileId = entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : undefined;
470
+ return pluginExecutor.invokeAssistantTool(pluginId, toolName, args, {
471
+ workspaceId: workspace.value.id,
472
+ ...(activeFileId ? { activeFileId } : {}),
473
+ });
474
+ }
475
+
476
+ function queryPluginAssistantContext(pluginId: string, providerId: string, query: string) {
477
+ if (!workspace.value) return Promise.reject(new Error('请先打开工作区'));
478
+ const entry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
479
+ const activeFileId = entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : undefined;
480
+ return pluginExecutor.queryAssistantContext(pluginId, providerId, query, {
481
+ workspaceId: workspace.value.id,
482
+ ...(activeFileId ? { activeFileId } : {}),
483
+ });
484
+ }
485
+
287
486
  function interactWithPlugin(interaction: PluginInteraction) {
288
487
  if (workspace.value?.id !== interaction.workspaceId)
289
488
  return Promise.reject(new Error('工作区已切换,请重新打开插件界面'));
@@ -296,241 +495,6 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
296
495
  );
297
496
  }
298
497
 
299
- async function pluginCall(
300
- method: string,
301
- params: Record<string, unknown>,
302
- assertInstance: () => void,
303
- ): Promise<unknown> {
304
- const expected = workspace.value?.id;
305
- return serial(async () => {
306
- const assertCurrent = () => {
307
- assertInstance();
308
- if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
309
- };
310
- assertCurrent();
311
- if (method === 'attachments.read')
312
- return pluginAttachmentReader.read(
313
- workspace.value!,
314
- params,
315
- runtime.attachments ??
316
- (runtime.native && adapter.mode === 'desktop' ? nativeAttachments : undefined),
317
- assertCurrent,
318
- );
319
- workspace.value = await adapter.refresh();
320
- await refreshObjects();
321
- assertCurrent();
322
- const current = workspace.value!;
323
- if (method === 'views.open') {
324
- await openPluginView(String(params.pluginId), String(params.viewId));
325
- return null;
326
- }
327
- if (method.endsWith('.query') || method === 'documents.search')
328
- return queryPluginData(method, params, pluginQueryPager, {
329
- workspace: current,
330
- objects: objects.value,
331
- relations: relations.value,
332
- drafts: documents.value,
333
- read: (path) => adapter.read(path),
334
- assertCurrent,
335
- });
336
- const file = () => {
337
- const entry = fileRegistry.value?.get(String(params.fileId));
338
- if (!entry || !isMarkdown(entry.path) || isWorkspaceInternalPath(entry.path))
339
- throw new Error('文档不存在或不可访问');
340
- return entry;
341
- };
342
- const text = (value: unknown) => {
343
- if (typeof value !== 'string' || value.length > 512000)
344
- throw new Error('插件文档内容无效或过大');
345
- return value;
346
- };
347
- if (method === 'documents.list')
348
- return current.files
349
- .filter(
350
- (row) =>
351
- row.kind === 'file' && isMarkdown(row.path) && !isWorkspaceInternalPath(row.path),
352
- )
353
- .map(({ id, path, name, readOnly }) => ({
354
- id,
355
- path,
356
- name,
357
- readOnly: current.readOnly || readOnly || false,
358
- }));
359
- if (method === 'documents.read') {
360
- const entry = file();
361
- const disk = await adapter.read(entry.path);
362
- const doc = documentIndex.byId.value.get(entry.id);
363
- if (doc?.conflict || doc?.missing) throw new Error('文档存在冲突,请先处理');
364
- const content = text(doc?.content ?? disk.content);
365
- return { id: entry.id, path: entry.path, content, hash: await assistantHash(content) };
366
- }
367
- if (method === 'documents.open') {
368
- await openInternal(file());
369
- ensureTabNavigation(String(params.fileId), String(params.fileId));
370
- touchNavigation();
371
- return null;
372
- }
373
- if (method === 'objects.list')
374
- return objects.value.map((record) => ({
375
- id: record.object.id,
376
- object: JSON.parse(JSON.stringify(record.object)),
377
- hash: record.snapshot.hash,
378
- }));
379
- if (method === 'objects.read') {
380
- const record = objects.value.find((row) => row.object.id === params.objectId);
381
- if (!record) throw new Error('对象不存在或不可访问');
382
- return {
383
- id: record.object.id,
384
- object: JSON.parse(JSON.stringify(record.object)),
385
- hash: record.snapshot.hash,
386
- };
387
- }
388
- if (method === 'relations.list') return JSON.parse(JSON.stringify(relations.value));
389
- writable();
390
- if (method === 'documents.create') {
391
- const path = text(params.path);
392
- if (!isMarkdown(path) || validatePath(path)) throw new Error('新文档路径无效');
393
- assertCurrent();
394
- await adapter.create(path, text(params.content));
395
- workspace.value = await adapter.refresh();
396
- const entry = fileRegistry.value?.at(path)!;
397
- return { id: entry.id, path };
398
- }
399
- if (method === 'documents.write') {
400
- const entry = file();
401
- if (entry.readOnly) throw new Error('你对这篇文档只有阅读权限');
402
- if (!pluginRecord(params.base) || params.base.id !== entry.id)
403
- throw new Error('文档版本无效');
404
- const base = text(params.base.content);
405
- const desired = text(params.content);
406
- const disk = await adapter.read(entry.path);
407
- const doc = documentIndex.byId.value.get(entry.id);
408
- if (doc?.conflict || doc?.missing) throw new Error('请先处理文档已有冲突');
409
- const live = doc
410
- ? mergeMarkdown(doc.base.content, doc.content, disk.content)
411
- : { clean: true, content: disk.content };
412
- const merged = mergeMarkdown(base, desired, live.content);
413
- if (!live.clean || !merged.clean) {
414
- const copyPath = entry.path.replace(
415
- /\.(md|markdown)$/i,
416
- `.plugin-conflict-${crypto.randomUUID().slice(0, 8)}.md`,
417
- );
418
- assertCurrent();
419
- await adapter.create(copyPath, desired);
420
- throw new Error(t('文档有重叠修改,插件版本已保存在 {0}', [copyPath]));
421
- }
422
- const editing = runtime.extensions?.()?.editing;
423
- if (editing?.isManaging(entry.id)) {
424
- if (!editing.applyPluginEdit)
425
- throw new Error('当前协作会话不支持插件编辑,请退出协作后重试');
426
- assertCurrent();
427
- const applied = await editing.applyPluginEdit(entry.id, live.content, merged.content);
428
- assertCurrent();
429
- return {
430
- id: entry.id,
431
- hash: await assistantHash(applied ?? merged.content),
432
- status: 'applied',
433
- };
434
- }
435
- if (doc && pluginEditorEdit && (await pluginEditorEdit(entry.id, doc.content, merged.content))) {
436
- return { id: entry.id, hash: await assistantHash(doc.content), status: 'applied' };
437
- }
438
- if (doc) {
439
- // The editor observes this value and applies a transaction through its existing bridge.
440
- doc.content = merged.content;
441
- doc.base = disk;
442
- assertCurrent();
443
- await saveInternal(doc);
444
- if (doc.error || doc.conflict || dirty(doc))
445
- throw new Error(doc.error ?? '插件修改已保留为草稿,请处理冲突后保存');
446
- return { id: entry.id, hash: await assistantHash(doc.content), status: 'saved' };
447
- }
448
- assertCurrent();
449
- const result = await adapter.write(entry.path, merged.content, disk.hash);
450
- if (result.status !== 'saved') {
451
- const copyPath = entry.path.replace(
452
- /\.(md|markdown)$/i,
453
- `.plugin-conflict-${crypto.randomUUID().slice(0, 8)}.md`,
454
- );
455
- await adapter.create(copyPath, desired);
456
- throw new Error(t('保存时文件发生变化,插件版本已保存在 {0}', [copyPath]));
457
- }
458
- return { id: entry.id, hash: await assistantHash(result.snapshot.content), status: 'saved' };
459
- }
460
- if (!capabilities.value.features.objectReferences) throw new Error('工作区对象功能已关闭');
461
- if (method === 'objects.create' || method === 'objects.update') {
462
- if (!pluginRecord(params.object)) throw new Error('对象无效');
463
- const draft = JSON.parse(JSON.stringify(params.object));
464
- if (method === 'objects.create') {
465
- if (!adapter.reserveObjectId) throw new Error('存储适配器不支持对象身份分配');
466
- const id = await adapter.reserveObjectId(objects.value.map((row) => row.object.id));
467
- const object = parseObject(JSON.stringify({ ...draft, version: 1, id }));
468
- validateObjectProperties(object.type, object.properties);
469
- assertCurrent();
470
- await adapter.create(
471
- `${objectDirectory}/${id}.tano.json`,
472
- JSON.stringify(object, null, 2) + '\n',
473
- );
474
- workspace.value = await adapter.refresh();
475
- await refreshObjects();
476
- return object;
477
- }
478
- if (!pluginRecord(params.base) || !pluginRecord(params.base.object))
479
- throw new Error('对象版本无效');
480
- const record = objects.value.find((row) => row.object.id === draft.id);
481
- if (!record) throw new Error('对象不存在');
482
- if (current.files.find((row) => row.path === record.path)?.readOnly)
483
- throw new Error('对象只读');
484
- const object = parseObject(JSON.stringify(draft));
485
- validateObjectProperties(object.type, object.properties);
486
- const merged = mergeObject(
487
- parseObject(JSON.stringify(params.base.object)),
488
- object,
489
- record.object,
490
- );
491
- const preserve = async () => {
492
- const path = `.tano/conflicts/plugin-object-${crypto.randomUUID()}.json`;
493
- assertCurrent();
494
- await adapter.create(
495
- path,
496
- JSON.stringify({ version: 1, pluginProposal: object, base: params.base }, null, 2) + '\n',
497
- );
498
- return path;
499
- };
500
- if (!merged)
501
- throw new Error(t('对象已有重叠修改,插件版本已保存在 {0}', [await preserve()]));
502
- let saved: ObjectRecord;
503
- try {
504
- assertCurrent();
505
- saved = await saveObject(adapter, record, merged);
506
- } catch (error) {
507
- throw new Error(t('{0} 插件版本已保存在 {1}', [String(error), await preserve()]));
508
- }
509
- workspace.value = await adapter.refresh();
510
- await refreshObjects();
511
- return saved.object;
512
- }
513
- if (method === 'relations.add' || method === 'relations.remove') {
514
- if (relationError.value) throw new Error(relationError.value);
515
- const relation = params.relation as WorkspaceRelation;
516
- validateRelation(relation, relationDefinitions.value);
517
- for (const endpoint of [relation.source, relation.target])
518
- if (!referenceTargets.value.some((target) => referenceKey(target) === referenceKey(endpoint)))
519
- throw new Error('关系端点不存在或不可访问');
520
- assertCurrent();
521
- await saveRelationChange(
522
- adapter,
523
- getRelationBase(),
524
- method === 'relations.add' ? { add: relation } : { remove: relation },
525
- );
526
- workspace.value = await adapter.refresh();
527
- await refreshObjects();
528
- return null;
529
- }
530
- throw new Error('不支持此插件 API');
531
- });
532
- }
533
-
534
498
  // OAuth, connections & package repository helpers
535
499
  async function startPluginOAuth(
536
500
  workspaceId: string,
@@ -626,17 +590,26 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
626
590
  }
627
591
 
628
592
  function disposePlugins() {
593
+ cancelActivePluginDialog('工作区已关闭');
594
+ clearPluginToasts();
629
595
  pluginAttachmentReader.clear();
630
596
  clearTimeout(pluginEventTimer);
597
+ overlayExtension()?.dispose?.();
631
598
  pluginServices.dispose();
632
599
  if (typeof window !== 'undefined') window.removeEventListener('storage', pluginStorageChanged);
633
600
  }
634
601
 
635
602
  return {
636
603
  pluginRuntime,
604
+ pluginHostEnvironment,
637
605
  canManagePlugins,
638
606
  installedPlugins,
639
607
  installedPluginWorkspace,
608
+ personalCodePluginPolicy,
609
+ overlaySnapshot,
610
+ setSafeMode: (enabled: boolean) => overlayExtension()?.setSafeMode(enabled),
611
+ pluginHomeTabView,
612
+ pluginNewTabView,
640
613
  pluginDevelopment,
641
614
  pluginServices,
642
615
  pluginHost,
@@ -644,13 +617,29 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
644
617
  pluginDeveloper,
645
618
  pluginViews,
646
619
  pluginCommands,
620
+ pluginFileHandlers,
621
+ pluginSlashCommands,
622
+ pluginCodeBlockRenderers,
623
+ pluginDecorationsFor,
624
+ pluginStatusBarItems,
625
+ pluginContextProviders,
647
626
  activePluginSidebar,
627
+ activeDocumentPluginSidebar,
628
+ activePluginDialog,
629
+ resolvePluginDialog,
630
+ pluginToasts,
631
+ dismissPluginToast,
648
632
  pluginSettingsRequest,
649
633
  pluginSettingsPages,
650
634
  pluginError,
651
635
  refreshPlugins,
652
636
  openPluginView,
653
637
  interactWithPlugin,
638
+ invokePluginAssistantTool,
639
+ queryPluginAssistantContext,
640
+ setPluginAiRunner: (runner?: PluginAiRunner) => {
641
+ pluginAiRunner = runner;
642
+ },
654
643
  startPluginOAuth,
655
644
  loadPluginConnections,
656
645
  savePluginConnection,
@@ -658,8 +647,14 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
658
647
  removePluginPackage,
659
648
  loadPluginPackageUsage,
660
649
  clearPluginLogs: (id: string) => pluginExecutor.clearLogs(id),
661
- setPluginEditor: (apply?: (id: string, before: string, after: string) => Promise<boolean>) => {
662
- pluginEditorEdit = apply;
650
+ userPluginIntegrities: () => pluginHost.userPluginIntegrities(),
651
+ setPluginEditor: (
652
+ bridge?:
653
+ | PluginEditorBridge
654
+ | ((id: string, before: string, after: string) => Promise<boolean>),
655
+ ) => {
656
+ pluginEditorBridge =
657
+ typeof bridge === 'function' ? { applyEdit: bridge } : bridge;
663
658
  },
664
659
  disposePlugins,
665
660
  };