@tano.page/workbench 0.15.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 (118) hide show
  1. package/package.json +35 -14
  2. package/src/App.vue +68 -797
  3. package/src/assistant/agent-identities.ts +1 -97
  4. package/src/assistant/agent-task-context.ts +1 -54
  5. package/src/assistant/attachments.ts +1 -1
  6. package/src/assistant/completion.ts +1 -61
  7. package/src/assistant/components/AssistantPanel.vue +1 -1
  8. package/src/assistant/connection-actions.ts +237 -0
  9. package/src/assistant/document-mentions.ts +1 -33
  10. package/src/assistant/engine.ts +1 -585
  11. package/src/assistant/execution.ts +6 -33
  12. package/src/assistant/hash.ts +1 -4
  13. package/src/assistant/language.ts +10 -37
  14. package/src/assistant/plugin-bridge-builder.ts +146 -0
  15. package/src/assistant/prompts.ts +1 -65
  16. package/src/assistant/proposal-actions.ts +336 -0
  17. package/src/assistant/store.ts +87 -554
  18. package/src/assistant/structures.ts +1 -157
  19. package/src/assistant/tasks.ts +8 -94
  20. package/src/assistant/tool-rules.ts +1 -7
  21. package/src/composables/use-workbench-help.ts +177 -0
  22. package/src/composables/use-workbench-lifecycle.ts +249 -0
  23. package/src/composables/use-workbench-settings.ts +185 -0
  24. package/src/composables/use-workbench-shortcuts.ts +37 -1022
  25. package/src/composables/use-workbench-views.ts +325 -0
  26. package/src/documents/components/DocumentActionMenu.vue +279 -0
  27. package/src/documents/components/DocumentInspector.vue +168 -0
  28. package/src/documents/components/DocumentPane.vue +482 -0
  29. package/src/documents/description-merge.ts +1 -9
  30. package/src/files/components/FileMetadataPanel.vue +49 -15
  31. package/src/i18n/locale-catalogs.ts +7 -6
  32. package/src/i18n/locale-registry.ts +8 -6
  33. package/src/i18n/locales/de-DE.json +23 -1
  34. package/src/i18n/locales/en-US.json +23 -1
  35. package/src/i18n/locales/es-ES.json +23 -1
  36. package/src/i18n/locales/ja-JP.json +23 -1
  37. package/src/i18n/locales/zh-TW.json +23 -1
  38. package/src/mail/components/MailAccountDialog.vue +1 -0
  39. package/src/mail/components/MailComposerDialog.vue +1 -0
  40. package/src/mail/components/MailWorkspaceView.vue +1 -0
  41. package/src/mail/components/SidebarMail.vue +1 -0
  42. package/src/objects/content-references.ts +6 -56
  43. package/src/objects/wiki-links.ts +1 -48
  44. package/src/objects/workspace-objects.ts +2 -3
  45. package/src/plans/calendar.ts +2 -2
  46. package/src/plans/components/CalendarAgendaView.vue +165 -0
  47. package/src/plans/components/CalendarFilterBar.vue +128 -0
  48. package/src/plans/components/CalendarMonthView.vue +224 -0
  49. package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
  50. package/src/plans/components/CalendarTimelineView.vue +517 -0
  51. package/src/plans/components/CalendarTopbarControls.vue +101 -0
  52. package/src/plans/components/CalendarView.vue +162 -2106
  53. package/src/plans/components/CalendarYearView.vue +138 -0
  54. package/src/plans/components/PlanConnectionsDialog.vue +1 -1
  55. package/src/plans/components/calendar-shared.css +192 -0
  56. package/src/plans/composables/use-calendar-interactions.ts +396 -0
  57. package/src/plans/composables/use-calendar-scroll.ts +420 -0
  58. package/src/plugins/components/PluginDetailPage.vue +10 -6
  59. package/src/plugins/components/PluginDeveloperArea.vue +192 -0
  60. package/src/plugins/components/PluginExplorer.vue +6 -4
  61. package/src/plugins/components/PluginImportDialog.vue +1 -1
  62. package/src/plugins/components/PluginInstaller.vue +269 -178
  63. package/src/plugins/components/PluginMaintenance.vue +37 -49
  64. package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
  65. package/src/plugins/components/PluginSettingsForm.vue +2 -1
  66. package/src/plugins/components/PluginsTabPage.vue +61 -0
  67. package/src/plugins/components/plugin-center.css +5 -0
  68. package/src/plugins/data.ts +9 -86
  69. package/src/plugins/editor-plugin-adapters.ts +169 -0
  70. package/src/plugins/plugin-data.ts +2 -3
  71. package/src/plugins/plugin-rpc-router.ts +558 -0
  72. package/src/plugins/plugin-sdk.ts +1 -260
  73. package/src/plugins/plugin-ui-dialogs.ts +167 -0
  74. package/src/plugins/queries.ts +1 -75
  75. package/src/plugins/view-header.ts +2 -7
  76. package/src/runtime.ts +3 -2
  77. package/src/settings/components/SettingsPanel.vue +8 -3
  78. package/src/settings/components/WorkbenchSettings.vue +20 -7
  79. package/src/settings/components/settings-context.ts +1 -1
  80. package/src/settings/settings-tab.ts +1 -0
  81. package/src/shell/command-palette.ts +3 -3
  82. package/src/shell/components/EditorToolbar.vue +8 -9
  83. package/src/shell/components/EditorTools.vue +1 -5
  84. package/src/shell/components/PaneTopbar.vue +393 -0
  85. package/src/shell/components/SelectionToolbar.vue +0 -2
  86. package/src/shell/components/WorkbenchContextMenus.vue +37 -26
  87. package/src/shell/components/WorkbenchModals.vue +22 -18
  88. package/src/shell/components/WorkbenchPanes.vue +358 -1512
  89. package/src/shell/components/WorkbenchSidebar.vue +486 -0
  90. package/src/shell/pane-registry.ts +69 -0
  91. package/src/shell/use-surface-dismissal.ts +219 -0
  92. package/src/shell/use-workbench-commands.ts +599 -0
  93. package/src/shell/use-workbench-keybindings.ts +337 -0
  94. package/src/shell/use-workbench.ts +488 -1081
  95. package/src/shell/workbench-context.ts +30 -3
  96. package/src/stores/workspace-document-io.ts +807 -0
  97. package/src/stores/workspace-file-ops.ts +1 -1
  98. package/src/stores/workspace-knowledge.ts +1 -1
  99. package/src/stores/workspace-lifecycle.ts +459 -0
  100. package/src/stores/workspace-plugins-state.ts +71 -599
  101. package/src/stores/workspace-session.ts +287 -0
  102. package/src/stores/workspace-tabs-layout.ts +1 -1
  103. package/src/stores/workspace-types.ts +50 -0
  104. package/src/stores/workspace.ts +163 -1345
  105. package/src/styles.css +0 -1
  106. package/src/tabs/components/DesktopTabs.vue +19 -11
  107. package/src/windows/AuxiliaryWindows.vue +2 -2
  108. package/src/windows/use-window-event-bridge.ts +152 -0
  109. package/src/workspace/components/TemplateLibrary.vue +1 -1
  110. package/src/workspace/components/WorkspaceIconPicker.vue +5 -4
  111. package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
  112. package/src/assistant/locales/de-DE.json +0 -129
  113. package/src/assistant/locales/en-US.json +0 -129
  114. package/src/assistant/locales/es-ES.json +0 -129
  115. package/src/assistant/locales/ja-JP.json +0 -129
  116. package/src/assistant/locales/zh-CN.json +0 -129
  117. package/src/assistant/locales/zh-TW.json +0 -129
  118. package/src/assistant/task-prompts.json +0 -39
@@ -23,7 +23,7 @@ import { t } from '../i18n/i18n';
23
23
  import type { FileMutationPreview, optimisticFiles } from '../files/optimistic-files';
24
24
  import { writeWorkspaceImport } from '../workspace/workspace-import';
25
25
  import type { WorkspaceSettings } from '../workspace/workspace-settings';
26
- import type { Activity } from './workspace';
26
+ import type { Activity } from './workspace-types';
27
27
 
28
28
  export interface WorkspaceFileOpsDeps {
29
29
  adapter: WorkspaceAdapter;
@@ -40,7 +40,7 @@ import { loadObjects, saveObject, type ObjectRecord } from '../objects/workspace
40
40
  import type { InstalledObjectPlugin } from '../plugins/workspace-plugins';
41
41
  import { loadRelations, saveRelationChange, type RelationChange } from '../objects/workspace-relations';
42
42
  import { loadTemplates, saveTemplate, type DocumentTemplate } from '../workspace/workspace-templates';
43
- import type { Activity } from './workspace';
43
+ import type { Activity } from './workspace-types';
44
44
 
45
45
  export interface WorkspaceKnowledgeDeps {
46
46
  adapter: WorkspaceAdapter;
@@ -0,0 +1,459 @@
1
+ import type { Ref } from 'vue';
2
+ import {
3
+ basename,
4
+ isMarkdown,
5
+ isWorkspaceInternalPath,
6
+ type FileRegistry,
7
+ type FileSnapshot,
8
+ type RecentWorkspace,
9
+ type Workspace,
10
+ type WorkspaceAdapter,
11
+ type WorkspaceSession,
12
+ } from '@tano/protocol';
13
+ import type { createWorkspaceAssistantBridge } from '../assistant/workspace-bridge';
14
+ import type { createDataTableController } from '../data-tables/data-table-controller';
15
+ import type { OpenDocument } from '../documents/document-session';
16
+ import type { InstalledObjectPlugin } from '../plugins/workspace-plugins';
17
+ import { layoutDirty } from '../workspace/workspace-document-layout';
18
+ import type { WorkspaceLifecycle } from '../workspace/workspace-lifecycle';
19
+ import { readStartupWorkspace, rememberStartupWorkspace } from '../workspace/workspace-startup';
20
+ import { addWorkspaceWelcome, workspaceWelcomePath } from '../workspace/workspace-welcome';
21
+ import type { createWorkspaceKnowledge } from './workspace-knowledge';
22
+ import type { createWorkspacePluginsState } from './workspace-plugins-state';
23
+ import type { createWorkspacePolicy } from './workspace-policy';
24
+ import type { createWorkspaceSession } from './workspace-session';
25
+ import type { createWorkspaceTabsLayout } from './workspace-tabs-layout';
26
+ import type { Activity, WorkspaceLifecycleHooks, WorkspaceLoadingState } from './workspace-types';
27
+
28
+ export interface WorkspaceLifecycleDeps {
29
+ adapter: WorkspaceAdapter;
30
+ isDemo: boolean;
31
+ isWeb: boolean;
32
+ remembersStartupWorkspace: boolean;
33
+ workspace: Ref<Workspace | null>;
34
+ fileRegistry: Ref<FileRegistry | null>;
35
+ documents: Ref<OpenDocument[]>;
36
+ tabIds: Ref<string[]>;
37
+ tabAliases: Ref<Map<string, string>>;
38
+ activeId: Ref<string>;
39
+ installedPlugins: Ref<InstalledObjectPlugin[]>;
40
+ busy: Ref<boolean>;
41
+ openingWorkspace: Ref<boolean>;
42
+ workspaceLoading: Ref<WorkspaceLoadingState>;
43
+ restoringDocuments: Ref<Record<string, string>>;
44
+ openingDocuments: Ref<Record<string, { request: number; tabId: string }>>;
45
+ activities: Ref<Activity[]>;
46
+ fatal: Ref<string>;
47
+ recent: Ref<RecentWorkspace[]>;
48
+ sessionError: Ref<string>;
49
+ workspaceLifecycle: WorkspaceLifecycle;
50
+ stopWatching: () => void;
51
+ dataTables: ReturnType<typeof createDataTableController>;
52
+ policy: ReturnType<typeof createWorkspacePolicy>;
53
+ knowledge: ReturnType<typeof createWorkspaceKnowledge>;
54
+ plugins: ReturnType<typeof createWorkspacePluginsState>;
55
+ tabsLayout: ReturnType<typeof createWorkspaceTabsLayout>;
56
+ assistantBridge: ReturnType<typeof createWorkspaceAssistantBridge>;
57
+ session: ReturnType<typeof createWorkspaceSession>;
58
+ hooks: WorkspaceLifecycleHooks;
59
+ serial: <T>(task: () => Promise<T>) => Promise<T>;
60
+ activity: (label: string, detail: string, kind: Activity['kind'], change?: Activity['change']) => void;
61
+ report: (error: unknown) => void;
62
+ loadWorkspacePart: (part: keyof WorkspaceLoadingState, load: () => Promise<unknown>) => Promise<void>;
63
+ flush: () => Promise<boolean>;
64
+ reconcile: (doc: OpenDocument, snapshot: FileSnapshot) => Promise<void>;
65
+ saveInternal: (doc: OpenDocument) => Promise<void>;
66
+ hydrateDocumentLayout: (doc: OpenDocument) => Promise<void>;
67
+ saveTableLayout: (doc: OpenDocument) => Promise<void>;
68
+ }
69
+
70
+ export function createWorkspaceLifecycle(deps: WorkspaceLifecycleDeps) {
71
+ const {
72
+ adapter,
73
+ isDemo,
74
+ isWeb,
75
+ remembersStartupWorkspace,
76
+ workspace,
77
+ fileRegistry,
78
+ documents,
79
+ tabIds,
80
+ tabAliases,
81
+ activeId,
82
+ installedPlugins,
83
+ busy,
84
+ openingWorkspace,
85
+ workspaceLoading,
86
+ restoringDocuments,
87
+ openingDocuments,
88
+ activities,
89
+ fatal,
90
+ recent,
91
+ sessionError,
92
+ workspaceLifecycle,
93
+ stopWatching,
94
+ dataTables,
95
+ policy,
96
+ knowledge,
97
+ plugins,
98
+ tabsLayout,
99
+ assistantBridge,
100
+ session,
101
+ hooks,
102
+ serial,
103
+ activity,
104
+ report,
105
+ loadWorkspacePart,
106
+ flush,
107
+ reconcile,
108
+ saveInternal,
109
+ hydrateDocumentLayout,
110
+ saveTableLayout,
111
+ } = deps;
112
+
113
+ async function refreshWorkspaces() {
114
+ if (!adapter.recent) return false;
115
+ try {
116
+ recent.value = policy.decorateRecent(await adapter.recent());
117
+ return true;
118
+ } catch (error) {
119
+ report(error);
120
+ return false;
121
+ }
122
+ }
123
+
124
+ async function initialize(requestedWorkspace?: string) {
125
+ if (isDemo || isWeb) {
126
+ await openWorkspace(requestedWorkspace);
127
+ if (!workspace.value && requestedWorkspace) await openWorkspace();
128
+ if (isWeb) await refreshWorkspaces();
129
+ } else if (requestedWorkspace) {
130
+ await openWorkspace(requestedWorkspace);
131
+ } else if (adapter.recent && (await refreshWorkspaces())) {
132
+ const savedId = readStartupWorkspace();
133
+ const previous =
134
+ savedId === undefined
135
+ ? recent.value.reduce<RecentWorkspace | undefined>(
136
+ (latest, item) => (!latest || item.openedAt > latest.openedAt ? item : latest),
137
+ undefined,
138
+ )
139
+ : recent.value.find((item) => item.id === savedId);
140
+ if (previous) await openWorkspace(previous.path);
141
+ else if (savedId) rememberStartupWorkspace(null);
142
+ }
143
+ }
144
+
145
+ async function openWorkspace(path?: string, newName?: string) {
146
+ if (busy.value) return;
147
+ busy.value = true;
148
+ let switching = false;
149
+ let pendingWorkspaceLoads: Promise<unknown>[] = [];
150
+ try {
151
+ if (path === undefined && newName === undefined && adapter.selectWorkspacePath) {
152
+ const selected = await adapter.selectWorkspacePath();
153
+ if (selected === null) return;
154
+ path = selected;
155
+ }
156
+ openingWorkspace.value = true;
157
+ for (const part of Object.keys(
158
+ workspaceLoading.value,
159
+ ) as (keyof WorkspaceLoadingState)[])
160
+ workspaceLoading.value[part] = true;
161
+ switching = true;
162
+ workspaceLifecycle.pause();
163
+ if (!(await flush())) {
164
+ report('还有未保存的修改。请先处理保存错误,再切换工作空间。');
165
+ return;
166
+ }
167
+ await hooks.beforeSwitch?.();
168
+ await hooks.beforeWorkspaceChange?.();
169
+ await serial(async () => {
170
+ const previousReady = session.isReady();
171
+ session.setReady(false);
172
+ let next: Workspace | null;
173
+ try {
174
+ if (newName !== undefined && !adapter.createWorkspace)
175
+ throw new Error('此平台不能直接创建工作空间');
176
+ next =
177
+ newName === undefined
178
+ ? await adapter.open(path)
179
+ : await adapter.createWorkspace!(newName);
180
+ } catch (error) {
181
+ session.setReady(previousReady);
182
+ throw error;
183
+ }
184
+ if (!next) {
185
+ session.setReady(previousReady);
186
+ return;
187
+ }
188
+ const accountTabs = tabIds.value.filter(
189
+ (id) => tabsLayout.views.value.get(id)?.scope === 'account',
190
+ );
191
+ const accountActive = accountTabs.includes(activeId.value) ? activeId.value : undefined;
192
+ stopWatching();
193
+ plugins.pluginExecutor.dispose();
194
+ fatal.value = '';
195
+ if (next.reinitialized) {
196
+ report('.tano 已删除,工作区已重新初始化。旧对象已丢失,文档和附件保留。');
197
+ }
198
+ if (newName !== undefined || next.newlyCreated) {
199
+ try {
200
+ next = await addWorkspaceWelcome(adapter, next);
201
+ } catch (error) {
202
+ report(`工作区已创建,但入门文档未能添加:${String(error)}。可以继续新建文档。`);
203
+ }
204
+ }
205
+ policy.resetPolicy(false);
206
+ workspace.value = next;
207
+ documents.value = [];
208
+ tabIds.value = [];
209
+ activeId.value = '';
210
+ openingDocuments.value = {};
211
+ restoringDocuments.value = {};
212
+ tabsLayout.resetTabNavigation();
213
+ if (remembersStartupWorkspace) rememberStartupWorkspace(next.id);
214
+ knowledge.resetKnowledge(false);
215
+ dataTables.reset();
216
+ installedPlugins.value = [];
217
+ workspaceLoading.value.files = false;
218
+
219
+ const settingsReady = loadWorkspacePart('settings', policy.refreshWorkspaceSettings);
220
+ const tablesReady = loadWorkspacePart('tables', () => dataTables.reload());
221
+ const objectsReady = knowledge.refreshObjects().catch(report);
222
+ const capabilitiesReady = loadWorkspacePart('capabilities', policy.refreshCapabilities);
223
+ pendingWorkspaceLoads = [settingsReady, tablesReady, objectsReady, capabilitiesReady];
224
+ assistantBridge.resetForWorkspaceChange();
225
+ activities.value = [];
226
+ sessionError.value = '';
227
+ session.setBlocked(false);
228
+ const watcherReady = workspaceLifecycle.start().catch(report);
229
+ pendingWorkspaceLoads.push(watcherReady);
230
+
231
+ let saved: WorkspaceSession | null = null;
232
+ if (adapter.loadSession) {
233
+ try {
234
+ saved = await adapter.loadSession(next.id);
235
+ } catch (error) {
236
+ session.setBlocked(true);
237
+ sessionError.value = `${String(error)}。本次不覆盖恢复记录。`;
238
+ }
239
+ }
240
+ if (saved) await session.restoreSession(saved, tablesReady, objectsReady);
241
+ else await settingsReady;
242
+
243
+ const first =
244
+ next.files.find(
245
+ (f) =>
246
+ f.id === policy.workspaceSettings.value.homePageId &&
247
+ f.kind === 'file' &&
248
+ isMarkdown(f.path),
249
+ ) ??
250
+ next.files.find((f) => f.path === workspaceWelcomePath) ??
251
+ next.files.find((f) => /^readme\.md$/i.test(f.path)) ??
252
+ next.files.find(
253
+ (f) => f.kind === 'file' && isMarkdown(f.path) && !isWorkspaceInternalPath(f.path),
254
+ );
255
+ if (!saved && first) {
256
+ try {
257
+ await session.openInitialDocument(first);
258
+ tabsLayout.ensureTabNavigation(activeId.value, activeId.value);
259
+ tabsLayout.touchNavigation();
260
+ } catch (error) {
261
+ report(error);
262
+ }
263
+ }
264
+ workspaceLoading.value.session = false;
265
+ {
266
+ for (const id of accountTabs) {
267
+ if (!tabIds.value.includes(id)) tabIds.value.push(id);
268
+ tabsLayout.ensureTabNavigation(id);
269
+ }
270
+ if (accountActive) activeId.value = accountActive;
271
+ tabsLayout.touchNavigation();
272
+ }
273
+ await Promise.all([
274
+ settingsReady,
275
+ tablesReady,
276
+ objectsReady,
277
+ capabilitiesReady,
278
+ watcherReady,
279
+ ]);
280
+ session.setReady(true);
281
+ session.queueSession();
282
+ if (adapter.recent) recent.value = policy.decorateRecentNames(await adapter.recent());
283
+ activity(isDemo ? '演示工作空间已就绪' : '工作空间已打开', next.name, 'file');
284
+ });
285
+ } catch (error) {
286
+ if (path && recent.value.some((item) => item.path === path)) {
287
+ await refreshWorkspaces();
288
+ if (!recent.value.some((item) => item.path === path)) {
289
+ fatal.value = '';
290
+ return;
291
+ }
292
+ }
293
+ report(error);
294
+ } finally {
295
+ await Promise.allSettled(pendingWorkspaceLoads);
296
+ openingWorkspace.value = false;
297
+ for (const part of Object.keys(
298
+ workspaceLoading.value,
299
+ ) as (keyof WorkspaceLoadingState)[])
300
+ workspaceLoading.value[part] = false;
301
+ busy.value = false;
302
+ if (switching) {
303
+ workspaceLifecycle.resume();
304
+ try {
305
+ await hooks.afterSwitch?.();
306
+ } catch (error) {
307
+ report(error);
308
+ }
309
+ }
310
+ }
311
+ }
312
+
313
+ function createWorkspace(name?: string) {
314
+ if (name === undefined) {
315
+ const spaces = [...recent.value, ...(workspace.value ? [workspace.value] : [])];
316
+ const occupied = new Set(
317
+ spaces.flatMap((space) => [space.name, basename(space.path.replace(/\\/g, '/'))]),
318
+ );
319
+ name = '新工作区';
320
+ for (let suffix = 2; occupied.has(name); suffix++) name = `新工作区 ${suffix}`;
321
+ }
322
+ return openWorkspace(undefined, name);
323
+ }
324
+
325
+ async function exitWorkspace(deleteId?: string): Promise<boolean> {
326
+ if (busy.value || !workspace.value) return false;
327
+ busy.value = true;
328
+ try {
329
+ const assertDeletion = () => {
330
+ if (deleteId === undefined) return;
331
+ if (workspace.value?.id !== deleteId) throw new Error('工作区已切换,请重新确认删除');
332
+ if (!adapter.deleteWorkspace || !workspace.value.canDelete)
333
+ throw new Error(
334
+ isWeb ? '仅工作区所有者可以删除工作区' : '此平台暂不支持删除本地工作区注册',
335
+ );
336
+ };
337
+ assertDeletion();
338
+ if (!(await flush())) {
339
+ report(
340
+ `还有未保存的修改。请先处理保存错误,再${deleteId === undefined ? '退出' : '删除'}工作区。`,
341
+ );
342
+ return false;
343
+ }
344
+ await hooks.beforeSwitch?.();
345
+ await hooks.beforeWorkspaceChange?.();
346
+ await serial(async () => {
347
+ assertDeletion();
348
+ const current = workspace.value;
349
+ if (!current) return;
350
+ session.queueSession();
351
+ await session.journal.flush();
352
+ if (deleteId !== undefined) await adapter.deleteWorkspace!(deleteId);
353
+ else await adapter.close?.(current.id);
354
+ if (remembersStartupWorkspace) rememberStartupWorkspace(null);
355
+ session.setReady(false);
356
+ stopWatching();
357
+ plugins.pluginHost.dispose();
358
+ plugins.pluginExecutor.dispose();
359
+ workspace.value = null;
360
+ dataTables.reset();
361
+ policy.resetPolicy(true);
362
+ assistantBridge.resetForWorkspaceChange();
363
+ documents.value = [];
364
+ tabIds.value = [];
365
+ tabAliases.value = new Map();
366
+ activeId.value = '';
367
+ tabsLayout.resetTabNavigation();
368
+ knowledge.resetKnowledge(true);
369
+ installedPlugins.value = [];
370
+ plugins.pluginError.value = '';
371
+ activities.value = [];
372
+ sessionError.value = '';
373
+ session.setBlocked(false);
374
+ fatal.value = '';
375
+ if (deleteId !== undefined) {
376
+ policy.forgetWorkspaceName(deleteId);
377
+ recent.value = recent.value.filter((item) => item.id !== deleteId);
378
+ knowledge.referenceDocumentCache.clear();
379
+ }
380
+ });
381
+ await refreshWorkspaces();
382
+ return true;
383
+ } catch (error) {
384
+ report(error);
385
+ return false;
386
+ } finally {
387
+ busy.value = false;
388
+ try {
389
+ await hooks.afterSwitch?.();
390
+ } catch (error) {
391
+ report(error);
392
+ }
393
+ }
394
+ }
395
+
396
+ function leaveWorkspace(): Promise<boolean> {
397
+ return exitWorkspace();
398
+ }
399
+
400
+ function deleteWorkspace(workspaceId: string): Promise<boolean> {
401
+ return exitWorkspace(workspaceId);
402
+ }
403
+
404
+ async function refresh() {
405
+ if (!workspace.value) return;
406
+ const expectedId = workspace.value.id;
407
+ const expectedPath = workspace.value.path;
408
+ try {
409
+ await serial(async () => {
410
+ if (workspace.value?.id !== expectedId || workspace.value.path !== expectedPath) return;
411
+ workspace.value = await adapter.refresh();
412
+ await policy.refreshCapabilities();
413
+ await policy.refreshWorkspaceSettings();
414
+ await knowledge.refreshObjects();
415
+ await dataTables.reload();
416
+ for (const doc of documents.value) {
417
+ if (doc.creating) continue;
418
+ const entry = fileRegistry.value?.get(doc.id);
419
+ if (!entry) {
420
+ if (!doc.missing) activity('文件已在外部移除', doc.path, 'external');
421
+ doc.missing = true;
422
+ continue;
423
+ }
424
+ if (doc.path !== entry.path) {
425
+ activity('文件已在外部重命名', `${doc.path} → ${entry.path}`, 'external');
426
+ doc.path = entry.path;
427
+ }
428
+ doc.missing = false;
429
+ await reconcile(doc, await adapter.read(doc.path));
430
+ await saveInternal(doc);
431
+ if (doc.tableLayout && !layoutDirty(doc.tableLayout)) await hydrateDocumentLayout(doc);
432
+ await saveTableLayout(doc);
433
+ }
434
+ });
435
+ } catch (error) {
436
+ knowledge.clearRevokedReferences(error);
437
+ report(error);
438
+ }
439
+ }
440
+
441
+ async function reveal() {
442
+ try {
443
+ await adapter.reveal();
444
+ } catch (e) {
445
+ report(e);
446
+ }
447
+ }
448
+
449
+ return {
450
+ initialize,
451
+ refreshWorkspaces,
452
+ openWorkspace,
453
+ createWorkspace,
454
+ leaveWorkspace,
455
+ deleteWorkspace,
456
+ refresh,
457
+ reveal,
458
+ };
459
+ }