@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
@@ -0,0 +1,287 @@
1
+ import { computed, watch, type ComputedRef, type Ref } from 'vue';
2
+ import {
3
+ type FileEntry,
4
+ type FileRegistry,
5
+ type FileSnapshot,
6
+ type Workspace,
7
+ type WorkspaceAdapter,
8
+ type WorkspaceLayout,
9
+ type WorkspaceSession,
10
+ } from '@tano/protocol';
11
+ import type { createDataTableController } from '../data-tables/data-table-controller';
12
+ import { isTableTab, tableFileId, tableTabId } from '../data-tables/data-tables';
13
+ import type { useDocumentIndex } from '../documents/document-index';
14
+ import { documentDirty as dirty, type OpenDocument } from '../documents/document-session';
15
+ import { layoutPanes, restoreLayout } from '../shell/pane-layout';
16
+ import { SessionJournal } from '../shell/session-journal';
17
+ import type { createWorkspaceTabsLayout } from './workspace-tabs-layout';
18
+ import type { Activity, WorkspaceLoadingState } from './workspace-types';
19
+
20
+ export interface WorkspaceSessionDeps {
21
+ adapter: WorkspaceAdapter;
22
+ workspace: Ref<Workspace | null>;
23
+ fileRegistry: Ref<FileRegistry | null>;
24
+ documents: Ref<OpenDocument[]>;
25
+ documentIndex: ReturnType<typeof useDocumentIndex>;
26
+ dataTables: ReturnType<typeof createDataTableController>;
27
+ tabsLayout: ReturnType<typeof createWorkspaceTabsLayout>;
28
+ tabIds: Ref<string[]>;
29
+ tabAliases: Ref<Map<string, string>>;
30
+ activeId: Ref<string>;
31
+ workspaceLoading: Ref<WorkspaceLoadingState>;
32
+ restoringDocuments: Ref<Record<string, string>>;
33
+ sessionError: Ref<string>;
34
+ dataTableFileId: (id: string) => string;
35
+ loadWorkspacePart: (part: keyof WorkspaceLoadingState, load: () => Promise<unknown>) => Promise<void>;
36
+ readOpenDocument: (file: FileEntry) => Promise<OpenDocument>;
37
+ openInternal: (file: FileEntry, replaceId?: string, current?: () => boolean) => Promise<void>;
38
+ hydrateDocumentLayout: (doc: OpenDocument) => Promise<void>;
39
+ reconcile: (doc: OpenDocument, snapshot: FileSnapshot) => Promise<void>;
40
+ saveInternal: (doc: OpenDocument) => Promise<void>;
41
+ activity: (label: string, detail: string, kind: Activity['kind'], change?: Activity['change']) => void;
42
+ report: (error: unknown) => void;
43
+ }
44
+
45
+ export function createWorkspaceSession(deps: WorkspaceSessionDeps) {
46
+ const {
47
+ adapter,
48
+ workspace,
49
+ fileRegistry,
50
+ documents,
51
+ documentIndex,
52
+ dataTables,
53
+ tabsLayout,
54
+ tabIds,
55
+ tabAliases,
56
+ activeId,
57
+ workspaceLoading,
58
+ restoringDocuments,
59
+ sessionError,
60
+ dataTableFileId,
61
+ loadWorkspacePart,
62
+ readOpenDocument,
63
+ openInternal,
64
+ hydrateDocumentLayout,
65
+ reconcile,
66
+ saveInternal,
67
+ activity,
68
+ report,
69
+ } = deps;
70
+
71
+ let sessionReady = false;
72
+ let sessionBlocked = false;
73
+
74
+ const journal = new SessionJournal(
75
+ (id, session) => adapter.saveSession!(id, session),
76
+ (error) => {
77
+ sessionError.value =
78
+ error === undefined
79
+ ? ''
80
+ : `恢复草稿未写入:${String(error)}。文档仍会尝试正常保存。`;
81
+ },
82
+ );
83
+
84
+ // Track only recoverable fields. Saving/error flags, undo stacks and plugin
85
+ // state must not traverse/rewrite every open document on the input path.
86
+ const recoveryDocuments = new WeakMap<
87
+ OpenDocument,
88
+ ComputedRef<WorkspaceSession['documents'][number]>
89
+ >();
90
+ const mainTabIds = computed(() =>
91
+ layoutPanes(tabsLayout.layout.value).flatMap((pane) => pane.tabs),
92
+ );
93
+ const sessionDocuments = computed(() =>
94
+ documents.value
95
+ .filter((doc) => mainTabIds.value.some((id) => tabsLayout.tabTarget(id) === doc.id))
96
+ .map((doc) => {
97
+ let snapshot = recoveryDocuments.get(doc);
98
+ if (!snapshot) {
99
+ snapshot = computed(() => ({
100
+ id: doc.id,
101
+ path: doc.path,
102
+ ...(dirty(doc) ? { draft: { content: doc.content, base: { ...doc.base } } } : {}),
103
+ }));
104
+ recoveryDocuments.set(doc, snapshot);
105
+ }
106
+ return snapshot.value;
107
+ }),
108
+ );
109
+ const sessionTables = computed(() =>
110
+ dataTables
111
+ .drafts()
112
+ .filter((draft) =>
113
+ mainTabIds.value.some(
114
+ (id) => tableFileId(tabsLayout.tabTarget(id)) === (draft.fileId ?? draft.id),
115
+ ),
116
+ ),
117
+ );
118
+ const sessionLayout = computed(
119
+ () => JSON.parse(JSON.stringify(tabsLayout.layout.value)) as WorkspaceLayout,
120
+ );
121
+ const sessionPayload = computed<WorkspaceSession>(() => ({
122
+ version: 1,
123
+ activeId:
124
+ layoutPanes(tabsLayout.layout.value).find(
125
+ (pane) => pane.id === tabsLayout.windowLayouts.value.main.activePaneId,
126
+ )?.activeId ?? '',
127
+ tabs: [...new Set(mainTabIds.value.map(tabsLayout.tabTarget))],
128
+ layout: sessionLayout.value,
129
+ dataTables: sessionTables.value,
130
+ documents: sessionDocuments.value,
131
+ }));
132
+
133
+ function queueSession() {
134
+ if (!sessionReady || sessionBlocked || !workspace.value || !adapter.saveSession) return;
135
+ journal.enqueue(workspace.value.id, sessionPayload.value);
136
+ }
137
+
138
+ const stopSessionWatch = watch(sessionPayload, queueSession, {
139
+ flush: 'sync',
140
+ });
141
+
142
+ async function openInitialDocument(file: FileEntry) {
143
+ restoringDocuments.value = { ...restoringDocuments.value, [file.id]: file.path };
144
+ tabIds.value = [file.id];
145
+ activeId.value = file.id;
146
+ workspaceLoading.value.session = false;
147
+ try {
148
+ await openInternal(file);
149
+ } finally {
150
+ delete restoringDocuments.value[file.id];
151
+ }
152
+ }
153
+
154
+ async function restoreSession(
155
+ saved: WorkspaceSession,
156
+ tablesReady: Promise<void>,
157
+ objectsReady: Promise<void>,
158
+ ) {
159
+ tabAliases.value = new Map();
160
+ const remapped = new Map<string, string>();
161
+ const pendingDocs = saved.documents.flatMap((tab) => {
162
+ const file = fileRegistry.value?.get(tab.id) ?? fileRegistry.value?.at(tab.path);
163
+ if (!file && !tab.draft) return [];
164
+ const id = file?.id ?? tab.id;
165
+ remapped.set(tab.id, id);
166
+ return [{ tab, file, id }];
167
+ });
168
+ restoringDocuments.value = Object.fromEntries(
169
+ pendingDocs.map(({ tab, file, id }) => [id, file?.path ?? tab.path]),
170
+ );
171
+ const planned = new Set(pendingDocs.map(({ id }) => id));
172
+ const requested = (saved.tabs ?? []).map((id) => remapped.get(id) ?? id);
173
+ tabIds.value = [
174
+ ...new Set([
175
+ ...requested.filter(
176
+ (id) =>
177
+ planned.has(id) ||
178
+ tabsLayout.isUtilityTab(id) ||
179
+ id.startsWith('plugin:'),
180
+ ),
181
+ ...planned,
182
+ ]),
183
+ ];
184
+ const restoredActive = remapped.get(saved.activeId) ?? saved.activeId;
185
+ tabsLayout.layout.value = restoreLayout(saved.layout, tabIds.value, remapped);
186
+ tabsLayout.activePaneId.value =
187
+ tabsLayout.panes.value.find((pane) => pane.tabs.includes(restoredActive))?.id ??
188
+ tabsLayout.panes.value[0].id;
189
+ activeId.value = tabIds.value.includes(restoredActive)
190
+ ? restoredActive
191
+ : (tabIds.value[0] ?? '');
192
+ workspaceLoading.value.session = false;
193
+
194
+ const visible = new Set(tabsLayout.panes.value.map((pane) => pane.activeId));
195
+ const tableRecovery = (async () => {
196
+ await tablesReady;
197
+ if (saved.dataTables?.length) {
198
+ workspaceLoading.value.tables = true;
199
+ await loadWorkspacePart('tables', () => dataTables.restore(saved.dataTables!));
200
+ }
201
+ })();
202
+
203
+ const restoreDocument = async ({ tab, file, id }: (typeof pendingDocs)[number]) => {
204
+ try {
205
+ if (!tab.draft) {
206
+ if (file) {
207
+ const doc = await readOpenDocument(file);
208
+ if (!documentIndex.byId.value.has(id)) documents.value.push(doc);
209
+ }
210
+ return;
211
+ }
212
+ const doc: OpenDocument = {
213
+ id: file?.id ?? tab.id,
214
+ path: file?.path ?? tab.path,
215
+ content: tab.draft.content,
216
+ base: tab.draft.base,
217
+ saving: false,
218
+ creating: file?.pendingCreation,
219
+ missing: !file,
220
+ };
221
+ if (!doc.creating) await hydrateDocumentLayout(doc);
222
+ documents.value.push(doc);
223
+ activity('已恢复未保存草稿', doc.path, 'file');
224
+ if (file) {
225
+ try {
226
+ if (!doc.creating) await reconcile(doc, await adapter.read(file.path));
227
+ await saveInternal(documentIndex.byId.value.get(doc.id)!);
228
+ } catch (error) {
229
+ doc.error = String(error);
230
+ report(error);
231
+ }
232
+ } else doc.error = '原文件已不存在,恢复草稿已保留,请另存副本';
233
+ } catch (error) {
234
+ report(error);
235
+ } finally {
236
+ delete restoringDocuments.value[id];
237
+ }
238
+ };
239
+
240
+ const priority = (id: string) => (id === restoredActive ? 2 : Number(visible.has(id)));
241
+ const queue = [...pendingDocs].sort((a, b) => priority(b.id) - priority(a.id));
242
+ const worker = async () => {
243
+ for (let next = queue.shift(); next; next = queue.shift()) await restoreDocument(next);
244
+ };
245
+ await Promise.all([
246
+ tableRecovery,
247
+ objectsReady,
248
+ ...Array.from({ length: Math.min(4, queue.length) }, worker),
249
+ ]);
250
+
251
+ for (const id of saved.tabs ?? [])
252
+ if (isTableTab(id))
253
+ remapped.set(id, tableTabId(dataTableFileId(tableFileId(id))));
254
+ const byId = new Map(documents.value.map((doc) => [doc.id, doc]));
255
+ documents.value = pendingDocs
256
+ .map(({ id }) => byId.get(id))
257
+ .filter((doc): doc is OpenDocument => !!doc);
258
+ const restored = saved.tabs
259
+ ?.map((id) => remapped.get(id) ?? id)
260
+ .filter(
261
+ (id) =>
262
+ tabsLayout.isUtilityTab(id) || documents.value.some((doc) => doc.id === id),
263
+ );
264
+ tabIds.value = [...new Set([...(restored ?? []), ...documents.value.map((doc) => doc.id)])];
265
+ const currentActive = remapped.get(activeId.value) ?? activeId.value;
266
+ tabsLayout.layout.value = restoreLayout(tabsLayout.layout.value, tabIds.value, remapped);
267
+ tabsLayout.activePaneId.value =
268
+ tabsLayout.panes.value.find((pane) => pane.tabs.includes(currentActive))?.id ??
269
+ tabsLayout.panes.value[0].id;
270
+ activeId.value = tabIds.value.includes(currentActive)
271
+ ? currentActive
272
+ : (tabIds.value[0] ?? '');
273
+ for (const tabId of tabIds.value) tabsLayout.ensureTabNavigation(tabId, tabId);
274
+ tabsLayout.touchNavigation();
275
+ }
276
+
277
+ return {
278
+ journal,
279
+ isReady: () => sessionReady,
280
+ setReady: (ready: boolean) => { sessionReady = ready; },
281
+ setBlocked: (blocked: boolean) => { sessionBlocked = blocked; },
282
+ queueSession,
283
+ stopSessionWatch,
284
+ openInitialDocument,
285
+ restoreSession,
286
+ };
287
+ }
@@ -28,7 +28,7 @@ import {
28
28
  type WindowLayouts,
29
29
  } from '../windows/layout';
30
30
  import { PLUGINS_TAB_ID, type InstalledObjectPlugin } from '../plugins/workspace-plugins';
31
- import type { DocumentTab } from './workspace';
31
+ import type { DocumentTab } from './workspace-types';
32
32
 
33
33
  export interface WorkspaceTabsLayoutDeps {
34
34
  workspace: Ref<Workspace | null>;
@@ -0,0 +1,50 @@
1
+ import type { FileEntry, PluginManifest } from '@tano/protocol';
2
+ import type { OpenDocument } from '../documents/document-session';
3
+ import type { PluginWorkbenchView } from '../plugins/workbench';
4
+ import type { WorkbenchViewTab } from '../runtime';
5
+
6
+ export type { OpenDocument } from '../documents/document-session';
7
+
8
+ export interface DocumentTab {
9
+ id: string;
10
+ path: string;
11
+ blank: boolean;
12
+ graph: boolean;
13
+ plugins: boolean;
14
+ calendar: boolean;
15
+ view?: WorkbenchViewTab;
16
+ directory?: { path: string; name: string; missing: boolean };
17
+ pluginView?: PluginWorkbenchView;
18
+ pluginDetail?: PluginManifest;
19
+ document?: OpenDocument;
20
+ attachmentPreview: boolean;
21
+ attachment?: FileEntry;
22
+ dataTable?: { name: string; dirty: boolean; icon?: string };
23
+ }
24
+
25
+ export interface Activity {
26
+ id: string;
27
+ label: string;
28
+ detail: string;
29
+ time: number;
30
+ kind: 'external' | 'save' | 'conflict' | 'file';
31
+ change?: { before: string; after: string };
32
+ }
33
+
34
+ export interface WorkspaceLoadingState {
35
+ files: boolean;
36
+ session: boolean;
37
+ settings: boolean;
38
+ tables: boolean;
39
+ plugins: boolean;
40
+ objects: boolean;
41
+ relations: boolean;
42
+ capabilities: boolean;
43
+ }
44
+
45
+ export interface WorkspaceLifecycleHooks {
46
+ beforeSwitch?: () => Promise<void>;
47
+ beforeWorkspaceChange?: () => Promise<void>;
48
+ afterSwitch?: () => Promise<void>;
49
+ beforeCloseDocument?: (id: string) => Promise<void>;
50
+ }