@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.
- package/package.json +21 -8
- package/src/App.vue +76 -17
- package/src/appearance/appearance.ts +14 -4
- package/src/appearance/components/ThemePresetPreview.vue +52 -8
- package/src/appearance/interface-font.ts +99 -0
- package/src/appearance/theme.ts +26 -10
- package/src/appearance/use-interface-font.ts +30 -0
- package/src/assets/mail-provider-icons/NOTICE.txt +27 -0
- package/src/assets/mail-provider-icons/aliyun-mail.svg +3 -0
- package/src/assets/mail-provider-icons/gmail.svg +1 -0
- package/src/assets/mail-provider-icons/icloud.svg +12 -0
- package/src/assets/mail-provider-icons/netease-126.svg +5 -0
- package/src/assets/mail-provider-icons/netease-163.svg +5 -0
- package/src/assets/mail-provider-icons/qq.svg +9 -0
- package/src/assets/mail-provider-icons/tencent-exmail.svg +4 -0
- package/src/assistant/components/AssistantChangeList.vue +98 -21
- package/src/assistant/components/AssistantPanel.vue +424 -7
- package/src/assistant/components/PluginToolProposalCard.vue +235 -0
- package/src/assistant/engine.ts +56 -3
- package/src/assistant/files.ts +5 -13
- package/src/assistant/inbox.ts +1 -148
- package/src/assistant/locales/de-DE.json +4 -1
- package/src/assistant/locales/en-US.json +4 -1
- package/src/assistant/locales/es-ES.json +4 -1
- package/src/assistant/locales/ja-JP.json +4 -1
- package/src/assistant/locales/zh-CN.json +4 -1
- package/src/assistant/locales/zh-TW.json +4 -1
- package/src/assistant/mention-autocomplete.ts +69 -0
- package/src/assistant/prompts.ts +7 -0
- package/src/assistant/results.ts +20 -86
- package/src/assistant/store.ts +319 -12
- package/src/assistant/structures.ts +7 -5
- package/src/assistant/tasks.ts +3 -5
- package/src/assistant/workspace-bridge.ts +1 -1
- package/src/composables/use-document-actions.ts +38 -20
- package/src/composables/use-file-tree-controller.ts +7 -12
- package/src/composables/use-workbench-history.ts +2 -4
- package/src/composables/use-workbench-modals.ts +6 -1
- package/src/composables/use-workbench-outline.ts +0 -5
- package/src/composables/use-workbench-shortcuts.ts +26 -22
- package/src/data-tables/data-tables.ts +1 -2
- package/src/documents/components/DocumentHistoryPanel.vue +3 -1
- package/src/features.ts +1 -0
- package/src/fonts/Inter-Latin-Italic.woff2 +0 -0
- package/src/fonts/Inter-Latin.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Bold.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Medium.woff2 +0 -0
- package/src/fonts/TanoUISansSC-Regular.woff2 +0 -0
- package/src/help/help-milestones.ts +3 -5
- package/src/i18n/locales/de-DE.json +349 -3
- package/src/i18n/locales/en-US.json +349 -2
- package/src/i18n/locales/es-ES.json +349 -3
- package/src/i18n/locales/ja-JP.json +348 -2
- package/src/i18n/locales/zh-TW.json +348 -2
- package/src/mail/components/MailAccountDialog.vue +449 -0
- package/src/mail/components/MailComposerDialog.vue +325 -0
- package/src/mail/components/MailProviderIcon.vue +30 -0
- package/src/mail/components/MailWorkspaceView.vue +820 -0
- package/src/mail/components/SidebarMail.vue +133 -0
- package/src/mail/mail-avatar.ts +17 -0
- package/src/mail/mail-bridge.ts +68 -0
- package/src/mail/mail-calendar.ts +208 -0
- package/src/mail/mail-markdown.ts +195 -0
- package/src/mail/types.ts +226 -0
- package/src/objects/components/ObjectDetailModal.vue +1001 -0
- package/src/objects/workspace-objects.ts +1 -1
- package/src/plan-sync/types.ts +6 -3
- package/src/plans/calendar-interaction.ts +194 -0
- package/src/plans/calendar.ts +63 -7
- package/src/plans/components/CalendarDayPopover.vue +172 -39
- package/src/plans/components/CalendarView.vue +1736 -276
- package/src/plans/components/PlanArchiveDialog.vue +295 -0
- package/src/plans/components/PlanDateField.vue +6 -4
- package/src/plans/components/PlanDetailPanel.vue +227 -32
- package/src/plans/components/PlanEventList.vue +16 -4
- package/src/plans/components/SidebarPlan.vue +22 -15
- package/src/plans/components/TaskRepeatControls.vue +169 -30
- package/src/plans/local-reminders.ts +149 -0
- package/src/plans/personal-plans.ts +10 -1
- package/src/plans/plan-date.ts +8 -1
- package/src/plans/plan-migration.ts +95 -0
- package/src/plans/recurrence.ts +95 -0
- package/src/plans/task-repeat.ts +8 -8
- package/src/plans/timeline-layout.ts +92 -0
- package/src/plugins/assistant-bridge.ts +520 -0
- package/src/plugins/attachment-reader.ts +3 -1
- package/src/plugins/cache-storage.ts +42 -2
- package/src/plugins/components/PluginAutomations.vue +3 -3
- package/src/plugins/components/PluginCatalogBrowser.vue +17 -8
- package/src/plugins/components/PluginChangeSummary.vue +16 -3
- package/src/plugins/components/PluginConnections.vue +1 -1
- package/src/plugins/components/PluginCustomView.vue +2 -2
- package/src/plugins/components/PluginDetailPage.vue +129 -54
- package/src/plugins/components/PluginDocumentSlot.vue +63 -0
- package/src/plugins/components/PluginExplorer.vue +15 -21
- package/src/plugins/components/PluginImportDialog.vue +410 -0
- package/src/plugins/components/PluginInstaller.vue +39 -145
- package/src/plugins/components/PluginListItem.vue +3 -0
- package/src/plugins/components/PluginMaintenance.vue +21 -6
- package/src/plugins/components/PluginRuntimePanel.vue +3 -3
- package/src/plugins/components/PluginSettingsForm.vue +111 -0
- package/src/plugins/components/PluginStatusBar.vue +161 -0
- package/src/plugins/components/PluginSurface.vue +18 -6
- package/src/plugins/components/PluginUiDialog.vue +452 -0
- package/src/plugins/excalidraw/bundle.tano-plugin.json +1 -1
- package/src/plugins/excalidraw/manifest.json +12 -1
- package/src/plugins/host.ts +662 -43
- package/src/plugins/native.ts +2 -10
- package/src/plugins/overlay-mapping.ts +125 -0
- package/src/plugins/packages.ts +73 -1
- package/src/plugins/plugin-permissions.ts +57 -0
- package/src/plugins/plugin-sdk.ts +174 -8
- package/src/plugins/policy.ts +53 -3
- package/src/plugins/presentation-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/presentation-preview/manifest.json +2 -1
- package/src/plugins/queries.ts +3 -1
- package/src/plugins/sandbox.ts +15 -1
- package/src/plugins/use-plugin-actions.ts +67 -20
- package/src/plugins/user-plugins.ts +254 -0
- package/src/plugins/word-preview/bundle.tano-plugin.json +1 -1
- package/src/plugins/word-preview/manifest.json +13 -1
- package/src/plugins/workbench.ts +175 -2
- package/src/plugins/worker.js +105 -8
- package/src/plugins/workspace-plugin-runtime.ts +23 -7
- package/src/plugins/workspace-plugins.ts +212 -21
- package/src/runtime.ts +101 -3
- package/src/settings/components/SettingsAppearancePage.vue +46 -0
- package/src/settings/components/SettingsDocumentsPage.vue +0 -1
- package/src/settings/components/settings-search.ts +2 -3
- package/src/shell/components/SidebarNavigation.vue +22 -2
- package/src/shell/components/WorkbenchContextMenus.vue +21 -8
- package/src/shell/components/WorkbenchModals.vue +27 -46
- package/src/shell/components/WorkbenchPanes.vue +267 -84
- package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
- package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
- package/src/shell/use-workbench.ts +116 -145
- package/src/shell/workbench-async-components.ts +14 -5
- package/src/stores/mail.ts +414 -0
- package/src/stores/plan-sync.ts +2 -1
- package/src/stores/plans.ts +2 -9
- package/src/stores/workspace-knowledge.ts +1 -113
- package/src/stores/workspace-plugins-state.ts +537 -14
- package/src/stores/workspace-tabs-layout.ts +5 -43
- package/src/stores/workspace.ts +69 -66
- package/src/styles/agent-diff-modals.css +0 -7
- package/src/styles/dark-theme.css +3 -3
- package/src/styles/inspector.css +0 -59
- package/src/styles/layout-themes.css +346 -0
- package/src/styles/mail.css +1568 -0
- package/src/styles/mobile.css +2 -2
- package/src/styles/recent-and-media.css +0 -17
- package/src/styles/theme-contract.css +3 -3
- package/src/styles/workbench-shell.css +110 -17
- package/src/styles/workspace-states.css +9 -33
- package/src/styles.css +1 -1
- package/src/tabs/components/DesktopTabs.vue +0 -3
- package/src/tabs/components/NewTabPicker.vue +10 -4
- package/src/tabs/tab-label.ts +0 -1
- package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
- package/src/workspace/components/WorkspaceIconPicker.vue +28 -6
- package/src/workspace/workspace-comments.ts +11 -151
- package/src/workspace/workspace-welcome.ts +1 -1
- package/src/documents/components/FormulaMenu.vue +0 -50
- package/src/files/components/FileDatabasePage.vue +0 -152
- package/src/files/components/FolderHomeIcon.vue +0 -12
- package/src/objects/components/ObjectDatabasePage.vue +0 -100
- package/src/objects/components/ObjectPanel.vue +0 -554
- package/src/plans/components/PersonalPlanDialog.vue +0 -105
- package/src/shell/components/WorkspaceViewPage.vue +0 -127
- package/src/shell/components/WorkspaceViewTab.vue +0 -24
- package/src/styles/object-panel.css +0 -163
- package/src/workspace/components/GitInspectionPanel.vue +0 -35
- package/src/workspace/components/WorkspaceSyncPanel.vue +0 -50
- package/src/workspace/welcome-slogans.ts +0 -11
- package/src/workspace/workspace-git.ts +0 -35
- package/src/workspace/workspace-sync.ts +0 -46
- package/src/workspace/workspace-views.ts +0 -48
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
FileRegistry,
|
|
6
6
|
isMarkdown,
|
|
7
7
|
isWorkspaceInternalPath,
|
|
8
|
+
matchesPluginPathScopes,
|
|
8
9
|
objectDirectory,
|
|
9
10
|
parseObject,
|
|
11
|
+
parsePluginAttachmentWrite,
|
|
10
12
|
parsePluginConnectionInput,
|
|
11
13
|
pluginRecord,
|
|
12
14
|
referenceKey,
|
|
@@ -16,19 +18,33 @@ import {
|
|
|
16
18
|
type FileEntry,
|
|
17
19
|
type FileSnapshot,
|
|
18
20
|
type PluginConnectionInput,
|
|
21
|
+
type PluginHostEnvironment,
|
|
19
22
|
type PluginOAuthInput,
|
|
23
|
+
type PluginUiConfirmOptions,
|
|
24
|
+
type PluginUiPickOptions,
|
|
25
|
+
type PluginUiPromptOptions,
|
|
26
|
+
type PluginUiTone,
|
|
20
27
|
type ReferenceTarget,
|
|
21
28
|
type RelationTypeDefinition,
|
|
22
29
|
type Workspace,
|
|
23
30
|
type WorkspaceAdapter,
|
|
31
|
+
type WorkspacePersonalPluginPolicy,
|
|
24
32
|
type WorkspaceRelation,
|
|
25
33
|
} from '@tano/protocol';
|
|
34
|
+
import workbenchPackage from '../../package.json';
|
|
26
35
|
import { assistantHash } from '../assistant/hash';
|
|
27
36
|
import { nativeAttachments } from '../files/attachments';
|
|
28
37
|
import type { useDocumentIndex } from '../documents/document-index';
|
|
29
38
|
import { documentDirty as dirty, type OpenDocument } from '../documents/document-session';
|
|
30
39
|
import { t } from '../i18n/i18n';
|
|
31
40
|
import { PluginAttachmentReader } from '../plugins/attachment-reader';
|
|
41
|
+
import { listActivePluginContextProviders } from '../plugins/assistant-bridge';
|
|
42
|
+
import type {
|
|
43
|
+
PluginAiCompleteRequest,
|
|
44
|
+
PluginAiCompleteResult,
|
|
45
|
+
PluginAiStructuredRequest,
|
|
46
|
+
PluginAiStructuredResult,
|
|
47
|
+
} from '@tano/protocol';
|
|
32
48
|
import { PluginQueryPager, pluginChanges } from '../plugins/data';
|
|
33
49
|
import type { PluginDevelopmentState } from '../plugins/development';
|
|
34
50
|
import type { PluginRuntimeState } from '../plugins/host';
|
|
@@ -36,16 +52,65 @@ import { canManageWorkspacePlugins } from '../plugins/policy';
|
|
|
36
52
|
import { queryPluginData } from '../plugins/queries';
|
|
37
53
|
import {
|
|
38
54
|
pluginViewKey,
|
|
55
|
+
pluginWorkbenchCodeBlockRenderers,
|
|
39
56
|
pluginWorkbenchCommands,
|
|
57
|
+
pluginWorkbenchDecorations,
|
|
58
|
+
pluginWorkbenchFileHandlers,
|
|
59
|
+
pluginWorkbenchSlashCommands,
|
|
60
|
+
pluginWorkbenchStatusBarItems,
|
|
40
61
|
pluginWorkbenchViews,
|
|
41
62
|
type PluginInteraction,
|
|
42
63
|
} from '../plugins/workbench';
|
|
43
|
-
import type
|
|
64
|
+
import { resolveOverlayExtension, type WorkbenchOverlaySnapshot, type WorkbenchRuntime } from '../runtime';
|
|
44
65
|
import { mergeObject, saveObject, type ObjectRecord } from '../objects/workspace-objects';
|
|
45
66
|
import { WorkspacePluginRuntime } from '../plugins/workspace-plugin-runtime';
|
|
46
67
|
import { PLUGINS_TAB_ID, type InstalledObjectPlugin } from '../plugins/workspace-plugins';
|
|
47
68
|
import { saveRelationChange } from '../objects/workspace-relations';
|
|
48
69
|
|
|
70
|
+
export type PluginUiDialogRequest =
|
|
71
|
+
| {
|
|
72
|
+
id: string;
|
|
73
|
+
kind: 'pick';
|
|
74
|
+
pluginId: string;
|
|
75
|
+
pluginName: string;
|
|
76
|
+
options: PluginUiPickOptions;
|
|
77
|
+
}
|
|
78
|
+
| {
|
|
79
|
+
id: string;
|
|
80
|
+
kind: 'prompt';
|
|
81
|
+
pluginId: string;
|
|
82
|
+
pluginName: string;
|
|
83
|
+
options: PluginUiPromptOptions;
|
|
84
|
+
}
|
|
85
|
+
| {
|
|
86
|
+
id: string;
|
|
87
|
+
kind: 'confirm';
|
|
88
|
+
pluginId: string;
|
|
89
|
+
pluginName: string;
|
|
90
|
+
options: PluginUiConfirmOptions;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export interface PluginUiToastItem {
|
|
94
|
+
id: string;
|
|
95
|
+
pluginId: string;
|
|
96
|
+
pluginName: string;
|
|
97
|
+
message: string;
|
|
98
|
+
tone: PluginUiTone;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PluginEditorBridge {
|
|
102
|
+
applyEdit(id: string, before: string, after: string): Promise<boolean>;
|
|
103
|
+
activeEditor?(): {
|
|
104
|
+
fileId: string;
|
|
105
|
+
mode: 'rich' | 'source';
|
|
106
|
+
readOnly: boolean;
|
|
107
|
+
selection: { from: number; to: number; empty: boolean };
|
|
108
|
+
selectedText: string;
|
|
109
|
+
blockType?: string;
|
|
110
|
+
} | null;
|
|
111
|
+
applySelectionEdit?(id: string, text: string, mode: 'insert' | 'replace'): Promise<boolean>;
|
|
112
|
+
}
|
|
113
|
+
|
|
49
114
|
export interface WorkspacePluginsStateDeps {
|
|
50
115
|
adapter: WorkspaceAdapter;
|
|
51
116
|
runtime: WorkbenchRuntime;
|
|
@@ -104,7 +169,7 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
104
169
|
} = deps;
|
|
105
170
|
|
|
106
171
|
const pluginAttachmentReader = new PluginAttachmentReader();
|
|
107
|
-
let
|
|
172
|
+
let pluginEditorBridge: PluginEditorBridge | undefined;
|
|
108
173
|
const pluginRuntime = shallowRef<PluginRuntimeState[]>([]);
|
|
109
174
|
watch(
|
|
110
175
|
[
|
|
@@ -118,7 +183,11 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
118
183
|
() => !!workspace.value && canManageWorkspacePlugins(adapter, workspace.value),
|
|
119
184
|
);
|
|
120
185
|
const pluginStorageChanged = (event: StorageEvent) => {
|
|
121
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
event.key?.startsWith('tano.object-plugins.v1.') ||
|
|
188
|
+
event.key?.startsWith('tano.plugin-') ||
|
|
189
|
+
event.key?.startsWith('tano.user-plugins.v1.')
|
|
190
|
+
)
|
|
122
191
|
scheduleRefresh();
|
|
123
192
|
};
|
|
124
193
|
if (typeof window !== 'undefined') window.addEventListener('storage', pluginStorageChanged);
|
|
@@ -127,14 +196,40 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
127
196
|
});
|
|
128
197
|
|
|
129
198
|
const installedPluginWorkspace = ref('');
|
|
199
|
+
const personalCodePluginPolicy = ref<WorkspacePersonalPluginPolicy>('allow');
|
|
200
|
+
const overlayExtension = () => resolveOverlayExtension(runtime);
|
|
201
|
+
const overlaySnapshot = computed<WorkbenchOverlaySnapshot>(
|
|
202
|
+
() => overlayExtension()?.snapshot ?? { safeMode: false },
|
|
203
|
+
);
|
|
204
|
+
type PluginAiRunner = (options: {
|
|
205
|
+
pluginId: string;
|
|
206
|
+
pluginName: string;
|
|
207
|
+
structured: boolean;
|
|
208
|
+
request: PluginAiCompleteRequest | PluginAiStructuredRequest;
|
|
209
|
+
signal: AbortSignal;
|
|
210
|
+
}) => Promise<PluginAiCompleteResult | PluginAiStructuredResult>;
|
|
211
|
+
let pluginAiRunner: PluginAiRunner | undefined;
|
|
130
212
|
const pluginDevelopment = shallowRef<PluginDevelopmentState>({
|
|
131
213
|
pluginId: '',
|
|
132
214
|
active: false,
|
|
133
215
|
message: '',
|
|
134
216
|
});
|
|
217
|
+
const pluginHostEnvironment: PluginHostEnvironment = runtime.plugins?.host ?? {
|
|
218
|
+
coreVersion: workbenchPackage.version,
|
|
219
|
+
platform: runtime.mobile
|
|
220
|
+
? 'mobile'
|
|
221
|
+
: adapter.mode === 'desktop'
|
|
222
|
+
? 'desktop-local'
|
|
223
|
+
: runtime.native
|
|
224
|
+
? 'desktop-online'
|
|
225
|
+
: 'web',
|
|
226
|
+
};
|
|
135
227
|
const pluginServices = new WorkspacePluginRuntime({
|
|
136
228
|
adapter,
|
|
137
|
-
services:
|
|
229
|
+
services: {
|
|
230
|
+
...runtime.plugins,
|
|
231
|
+
host: pluginHostEnvironment,
|
|
232
|
+
},
|
|
138
233
|
serial,
|
|
139
234
|
refresh: refreshObjects,
|
|
140
235
|
call: pluginCall,
|
|
@@ -156,6 +251,122 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
156
251
|
|
|
157
252
|
const pluginViews = computed(() => pluginWorkbenchViews(installedPlugins.value));
|
|
158
253
|
const pluginCommands = computed(() => pluginWorkbenchCommands(pluginRuntime.value));
|
|
254
|
+
const pluginFileHandlers = computed(() =>
|
|
255
|
+
pluginWorkbenchFileHandlers(installedPlugins.value, pluginRuntime.value),
|
|
256
|
+
);
|
|
257
|
+
const pluginSlashCommands = computed(() =>
|
|
258
|
+
pluginWorkbenchSlashCommands(installedPlugins.value, pluginRuntime.value),
|
|
259
|
+
);
|
|
260
|
+
const pluginCodeBlockRenderers = computed(() =>
|
|
261
|
+
pluginWorkbenchCodeBlockRenderers(installedPlugins.value, pluginRuntime.value),
|
|
262
|
+
);
|
|
263
|
+
const pluginDecorationsFor = (fileId: string) =>
|
|
264
|
+
pluginWorkbenchDecorations(pluginRuntime.value, fileId);
|
|
265
|
+
const pluginStatusBarItems = computed(() => pluginWorkbenchStatusBarItems(pluginRuntime.value));
|
|
266
|
+
const activeDocumentPluginSidebar = ref('');
|
|
267
|
+
const activePluginDialog = shallowRef<PluginUiDialogRequest | null>(null);
|
|
268
|
+
const pluginToasts = shallowRef<PluginUiToastItem[]>([]);
|
|
269
|
+
const toastTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
270
|
+
let activeDialogControl: {
|
|
271
|
+
id: string;
|
|
272
|
+
resolve: (value: string | boolean | null) => void;
|
|
273
|
+
reject: (error: Error) => void;
|
|
274
|
+
cleanup: () => void;
|
|
275
|
+
} | null = null;
|
|
276
|
+
function cancelActivePluginDialog(reason = '插件交互已取消') {
|
|
277
|
+
const current = activeDialogControl;
|
|
278
|
+
if (!current) return;
|
|
279
|
+
activeDialogControl = null;
|
|
280
|
+
activePluginDialog.value = null;
|
|
281
|
+
current.cleanup();
|
|
282
|
+
current.reject(new Error(reason));
|
|
283
|
+
}
|
|
284
|
+
function resolvePluginDialog(id: string, value: string | boolean | null) {
|
|
285
|
+
const current = activeDialogControl;
|
|
286
|
+
if (!current || current.id !== id) return;
|
|
287
|
+
activeDialogControl = null;
|
|
288
|
+
activePluginDialog.value = null;
|
|
289
|
+
current.cleanup();
|
|
290
|
+
current.resolve(value);
|
|
291
|
+
}
|
|
292
|
+
function dismissPluginToast(id: string) {
|
|
293
|
+
const timer = toastTimers.get(id);
|
|
294
|
+
if (timer) {
|
|
295
|
+
clearTimeout(timer);
|
|
296
|
+
toastTimers.delete(id);
|
|
297
|
+
}
|
|
298
|
+
pluginToasts.value = pluginToasts.value.filter((item) => item.id !== id);
|
|
299
|
+
}
|
|
300
|
+
function showPluginToast(params: Record<string, unknown>) {
|
|
301
|
+
const id = crypto.randomUUID();
|
|
302
|
+
const item: PluginUiToastItem = {
|
|
303
|
+
id,
|
|
304
|
+
pluginId: String(params.pluginId ?? ''),
|
|
305
|
+
pluginName: String(params.pluginName ?? ''),
|
|
306
|
+
message: String(params.message ?? ''),
|
|
307
|
+
tone: (params.tone as PluginUiTone | undefined) ?? 'info',
|
|
308
|
+
};
|
|
309
|
+
const next = [...pluginToasts.value, item];
|
|
310
|
+
while (next.length > 3) {
|
|
311
|
+
const removed = next.shift();
|
|
312
|
+
if (removed) {
|
|
313
|
+
const timer = toastTimers.get(removed.id);
|
|
314
|
+
if (timer) {
|
|
315
|
+
clearTimeout(timer);
|
|
316
|
+
toastTimers.delete(removed.id);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
pluginToasts.value = next;
|
|
321
|
+
toastTimers.set(
|
|
322
|
+
id,
|
|
323
|
+
setTimeout(() => dismissPluginToast(id), 4500),
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
function openPluginDialog(
|
|
327
|
+
method: 'ui.pick' | 'ui.prompt' | 'ui.confirm',
|
|
328
|
+
params: Record<string, unknown>,
|
|
329
|
+
): Promise<string | boolean | null> {
|
|
330
|
+
if (activeDialogControl) {
|
|
331
|
+
return Promise.reject(new Error('当前已有插件交互弹窗正在等待响应,请稍后重试'));
|
|
332
|
+
}
|
|
333
|
+
const id = crypto.randomUUID();
|
|
334
|
+
const signal = params.signal instanceof AbortSignal ? params.signal : undefined;
|
|
335
|
+
if (signal?.aborted) return Promise.reject(new Error('插件已停止'));
|
|
336
|
+
return new Promise<string | boolean | null>((resolve, reject) => {
|
|
337
|
+
const onAbort = () => cancelActivePluginDialog('插件已停止');
|
|
338
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
339
|
+
const cleanup = () => signal?.removeEventListener('abort', onAbort);
|
|
340
|
+
activeDialogControl = { id, resolve, reject, cleanup };
|
|
341
|
+
const pluginId = String(params.pluginId ?? '');
|
|
342
|
+
const pluginName = String(params.pluginName ?? '');
|
|
343
|
+
if (method === 'ui.pick') {
|
|
344
|
+
activePluginDialog.value = {
|
|
345
|
+
id,
|
|
346
|
+
kind: 'pick',
|
|
347
|
+
pluginId,
|
|
348
|
+
pluginName,
|
|
349
|
+
options: params.options as PluginUiPickOptions,
|
|
350
|
+
};
|
|
351
|
+
} else if (method === 'ui.prompt') {
|
|
352
|
+
activePluginDialog.value = {
|
|
353
|
+
id,
|
|
354
|
+
kind: 'prompt',
|
|
355
|
+
pluginId,
|
|
356
|
+
pluginName,
|
|
357
|
+
options: params.options as PluginUiPromptOptions,
|
|
358
|
+
};
|
|
359
|
+
} else {
|
|
360
|
+
activePluginDialog.value = {
|
|
361
|
+
id,
|
|
362
|
+
kind: 'confirm',
|
|
363
|
+
pluginId,
|
|
364
|
+
pluginName,
|
|
365
|
+
options: params.options as PluginUiConfirmOptions,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
159
370
|
const pluginSettingsRequest = shallowRef<{ key: string; sequence: number }>();
|
|
160
371
|
const pluginSettingsPages = computed(() =>
|
|
161
372
|
pluginViews.value
|
|
@@ -172,7 +383,40 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
172
383
|
() => workspace.value?.id,
|
|
173
384
|
() => {
|
|
174
385
|
activePluginSidebar.value = '';
|
|
386
|
+
activeDocumentPluginSidebar.value = '';
|
|
175
387
|
pluginSettingsRequest.value = undefined;
|
|
388
|
+
cancelActivePluginDialog('工作区已切换');
|
|
389
|
+
for (const timer of toastTimers.values()) clearTimeout(timer);
|
|
390
|
+
toastTimers.clear();
|
|
391
|
+
pluginToasts.value = [];
|
|
392
|
+
},
|
|
393
|
+
);
|
|
394
|
+
watch(pluginViews, (views) => {
|
|
395
|
+
if (
|
|
396
|
+
activeDocumentPluginSidebar.value &&
|
|
397
|
+
!views.some(
|
|
398
|
+
(view) => view.location === 'documentSidebar' && view.key === activeDocumentPluginSidebar.value,
|
|
399
|
+
)
|
|
400
|
+
) {
|
|
401
|
+
activeDocumentPluginSidebar.value = '';
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
watch(
|
|
405
|
+
() => {
|
|
406
|
+
const id = activeId.value;
|
|
407
|
+
const entry = id ? fileRegistry.value?.get(id) : undefined;
|
|
408
|
+
return entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : '';
|
|
409
|
+
},
|
|
410
|
+
(docId, prevDocId) => {
|
|
411
|
+
if (!docId || docId === prevDocId || !workspace.value) return;
|
|
412
|
+
for (const view of pluginViews.value) {
|
|
413
|
+
if (view.location === 'documentHeader' || view.location === 'documentFooter') {
|
|
414
|
+
if (pluginRuntime.value.some((rt) => rt.id === view.pluginId && rt.status === 'idle')) {
|
|
415
|
+
void pluginExecutor.ensureActivated(view.pluginId).catch(() => {});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
pluginExecutor.notify({ type: 'workspace.changed', fileId: docId });
|
|
176
420
|
},
|
|
177
421
|
);
|
|
178
422
|
|
|
@@ -246,13 +490,37 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
246
490
|
{ immediate: true },
|
|
247
491
|
);
|
|
248
492
|
|
|
493
|
+
watch(
|
|
494
|
+
() => (workspace.value ? ([workspace.value.id, overlaySnapshot.value.safeMode] as const) : null),
|
|
495
|
+
(current, previous) => {
|
|
496
|
+
if (current && previous && current[0] === previous[0] && current[1] !== previous[1] && workspace.value) {
|
|
497
|
+
pluginExecutor.sync(workspace.value, installedPlugins.value, current[1]);
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
watch(
|
|
503
|
+
() => {
|
|
504
|
+
const id = activeId.value;
|
|
505
|
+
const entry = id ? fileRegistry.value?.get(id) : undefined;
|
|
506
|
+
return entry && !isWorkspaceInternalPath(entry.path) ? entry.path : '';
|
|
507
|
+
},
|
|
508
|
+
(docPath) => {
|
|
509
|
+
if (workspace.value) overlayExtension()?.syncContext?.(workspace.value.id, docPath);
|
|
510
|
+
},
|
|
511
|
+
{ immediate: true },
|
|
512
|
+
);
|
|
513
|
+
|
|
249
514
|
async function refreshPlugins(current: Workspace) {
|
|
250
515
|
try {
|
|
251
|
-
const
|
|
516
|
+
const activeEntry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
|
|
517
|
+
overlayExtension()?.syncContext?.(current.id, activeEntry?.path ?? '');
|
|
518
|
+
const installed = await pluginHost.loadWorkspace(adapter, current, runtime.plugins?.repository);
|
|
252
519
|
if (workspace.value?.id !== current.id) return;
|
|
253
520
|
installedPlugins.value = installed;
|
|
254
521
|
installedPluginWorkspace.value = current.id;
|
|
255
|
-
|
|
522
|
+
personalCodePluginPolicy.value = pluginHost.personalCodePluginPolicy();
|
|
523
|
+
pluginExecutor.sync(current, installedPlugins.value, overlaySnapshot.value.safeMode);
|
|
256
524
|
pluginError.value = '';
|
|
257
525
|
} catch (error) {
|
|
258
526
|
pluginExecutor.dispose();
|
|
@@ -265,13 +533,19 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
265
533
|
function openPluginView(pluginId: string, viewId: string) {
|
|
266
534
|
const view = pluginViews.value.find((view) => view.key === pluginViewKey(pluginId, viewId));
|
|
267
535
|
if (!workspace.value || !view) throw new Error('插件视图已停用或不存在');
|
|
268
|
-
if (
|
|
536
|
+
if (pluginRuntime.value.some((rt) => rt.id === pluginId && rt.status === 'idle')) {
|
|
537
|
+
void pluginExecutor.ensureActivated(pluginId).catch(() => {});
|
|
538
|
+
}
|
|
539
|
+
if (view.location === 'tab' || view.location === 'homeTab' || view.location === 'newTab') {
|
|
269
540
|
if (!tabIds.value.includes(view.key)) tabIds.value.push(view.key);
|
|
270
541
|
activeId.value = view.key;
|
|
271
542
|
ensureTabNavigation(view.key);
|
|
272
543
|
touchNavigation();
|
|
273
544
|
} else if (view.location === 'sidebar') activePluginSidebar.value = view.key;
|
|
274
|
-
else if (view.location === '
|
|
545
|
+
else if (view.location === 'documentSidebar') activeDocumentPluginSidebar.value = view.key;
|
|
546
|
+
else if (view.location === 'documentHeader' || view.location === 'documentFooter') {
|
|
547
|
+
// Document header/footer slots render automatically on the active document.
|
|
548
|
+
} else if (view.location === 'settings')
|
|
275
549
|
pluginSettingsRequest.value = {
|
|
276
550
|
key: view.key,
|
|
277
551
|
sequence: (pluginSettingsRequest.value?.sequence ?? 0) + 1,
|
|
@@ -284,6 +558,44 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
284
558
|
}
|
|
285
559
|
}
|
|
286
560
|
|
|
561
|
+
const pluginContextProviders = computed(() =>
|
|
562
|
+
listActivePluginContextProviders(installedPlugins.value, pluginRuntime.value),
|
|
563
|
+
);
|
|
564
|
+
const pluginHomeTabView = computed(() => {
|
|
565
|
+
if (overlaySnapshot.value.safeMode) return null;
|
|
566
|
+
const pinnedKey = overlaySnapshot.value.homeTabViewKey;
|
|
567
|
+
if (pinnedKey) {
|
|
568
|
+
return pluginViews.value.find((view) => view.key === pinnedKey && view.location === 'homeTab') ?? null;
|
|
569
|
+
}
|
|
570
|
+
return pluginViews.value.find((view) => view.location === 'homeTab') ?? null;
|
|
571
|
+
});
|
|
572
|
+
const pluginNewTabView = computed(() => {
|
|
573
|
+
if (overlaySnapshot.value.safeMode) return null;
|
|
574
|
+
const pinnedKey = overlaySnapshot.value.newTabViewKey;
|
|
575
|
+
if (pinnedKey) {
|
|
576
|
+
return pluginViews.value.find((view) => view.key === pinnedKey && view.location === 'newTab') ?? null;
|
|
577
|
+
}
|
|
578
|
+
return pluginViews.value.find((view) => view.location === 'newTab') ?? null;
|
|
579
|
+
});
|
|
580
|
+
function invokePluginAssistantTool(pluginId: string, toolName: string, args: Record<string, unknown>) {
|
|
581
|
+
if (!workspace.value) return Promise.reject(new Error('请先打开工作区'));
|
|
582
|
+
const entry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
|
|
583
|
+
const activeFileId = entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : undefined;
|
|
584
|
+
return pluginExecutor.invokeAssistantTool(pluginId, toolName, args, {
|
|
585
|
+
workspaceId: workspace.value.id,
|
|
586
|
+
...(activeFileId ? { activeFileId } : {}),
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
function queryPluginAssistantContext(pluginId: string, providerId: string, query: string) {
|
|
590
|
+
if (!workspace.value) return Promise.reject(new Error('请先打开工作区'));
|
|
591
|
+
const entry = activeId.value ? fileRegistry.value?.get(activeId.value) : undefined;
|
|
592
|
+
const activeFileId = entry && isMarkdown(entry.path) && !isWorkspaceInternalPath(entry.path) ? entry.id : undefined;
|
|
593
|
+
return pluginExecutor.queryAssistantContext(pluginId, providerId, query, {
|
|
594
|
+
workspaceId: workspace.value.id,
|
|
595
|
+
...(activeFileId ? { activeFileId } : {}),
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
287
599
|
function interactWithPlugin(interaction: PluginInteraction) {
|
|
288
600
|
if (workspace.value?.id !== interaction.workspaceId)
|
|
289
601
|
return Promise.reject(new Error('工作区已切换,请重新打开插件界面'));
|
|
@@ -302,20 +614,126 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
302
614
|
assertInstance: () => void,
|
|
303
615
|
): Promise<unknown> {
|
|
304
616
|
const expected = workspace.value?.id;
|
|
617
|
+
if (method === 'ui.pick' || method === 'ui.prompt' || method === 'ui.confirm') {
|
|
618
|
+
assertInstance();
|
|
619
|
+
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
620
|
+
return openPluginDialog(method, params);
|
|
621
|
+
}
|
|
622
|
+
if (method === 'ui.toast') {
|
|
623
|
+
assertInstance();
|
|
624
|
+
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
625
|
+
showPluginToast(params);
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
if (method === 'ai.complete' || method === 'ai.structured') {
|
|
629
|
+
assertInstance();
|
|
630
|
+
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
631
|
+
if (!pluginAiRunner) throw new Error('当前环境尚未配置同页助手模型连接');
|
|
632
|
+
const signal = params.signal instanceof AbortSignal ? params.signal : new AbortController().signal;
|
|
633
|
+
return pluginAiRunner({
|
|
634
|
+
pluginId: String(params.pluginId ?? ''),
|
|
635
|
+
pluginName: String(params.pluginName ?? ''),
|
|
636
|
+
structured: method === 'ai.structured',
|
|
637
|
+
request: params.request as PluginAiCompleteRequest | PluginAiStructuredRequest,
|
|
638
|
+
signal,
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
const pathScopes = Array.isArray(params.pathScopes) ? (params.pathScopes as string[]) : undefined;
|
|
642
|
+
if (method === 'editor.active') {
|
|
643
|
+
assertInstance();
|
|
644
|
+
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
645
|
+
const snapshot = pluginEditorBridge?.activeEditor?.();
|
|
646
|
+
if (!snapshot) return null;
|
|
647
|
+
const entry = fileRegistry.value?.get(snapshot.fileId);
|
|
648
|
+
if (!entry || !isMarkdown(entry.path) || isWorkspaceInternalPath(entry.path)) return null;
|
|
649
|
+
if (!matchesPluginPathScopes(entry.path, pathScopes)) return null;
|
|
650
|
+
const doc = documentIndex.byId.value.get(entry.id);
|
|
651
|
+
const content = doc ? doc.content : (await adapter.read(entry.path)).content;
|
|
652
|
+
assertInstance();
|
|
653
|
+
return {
|
|
654
|
+
fileId: entry.id,
|
|
655
|
+
path: entry.path,
|
|
656
|
+
mode: snapshot.mode,
|
|
657
|
+
readOnly: !!(workspace.value?.readOnly || entry.readOnly || snapshot.readOnly),
|
|
658
|
+
selection: snapshot.selection,
|
|
659
|
+
selectedText: snapshot.selectedText,
|
|
660
|
+
...(snapshot.blockType ? { blockType: snapshot.blockType } : {}),
|
|
661
|
+
hash: await assistantHash(content),
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
if (method === 'editor.insert' || method === 'editor.replaceSelection') {
|
|
665
|
+
return serial(async () => {
|
|
666
|
+
assertInstance();
|
|
667
|
+
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
668
|
+
writable();
|
|
669
|
+
const snapshot = pluginEditorBridge?.activeEditor?.();
|
|
670
|
+
if (!snapshot || !pluginEditorBridge?.applySelectionEdit)
|
|
671
|
+
throw new Error('当前没有可编辑的活动文档');
|
|
672
|
+
const entry = fileRegistry.value?.get(snapshot.fileId);
|
|
673
|
+
if (!entry || !isMarkdown(entry.path) || isWorkspaceInternalPath(entry.path))
|
|
674
|
+
throw new Error('当前没有可编辑的活动文档');
|
|
675
|
+
if (!matchesPluginPathScopes(entry.path, pathScopes))
|
|
676
|
+
throw new Error('文档路径不在插件授权目录范围内');
|
|
677
|
+
if (entry.readOnly || snapshot.readOnly) throw new Error('你对这篇文档只有阅读权限');
|
|
678
|
+
const doc = documentIndex.byId.value.get(entry.id);
|
|
679
|
+
if (doc?.conflict || doc?.missing) throw new Error('请先处理文档已有冲突');
|
|
680
|
+
const editing = runtime.extensions?.()?.editing;
|
|
681
|
+
if (editing?.isManaging(entry.id)) {
|
|
682
|
+
throw new Error('当前协作会话暂不支持直接插入选区,请使用 documents.edit');
|
|
683
|
+
}
|
|
684
|
+
const ok = await pluginEditorBridge.applySelectionEdit(
|
|
685
|
+
entry.id,
|
|
686
|
+
String(params.text ?? ''),
|
|
687
|
+
method === 'editor.insert' ? 'insert' : 'replace',
|
|
688
|
+
);
|
|
689
|
+
if (!ok) throw new Error('当前编辑器无法应用选区修改');
|
|
690
|
+
assertInstance();
|
|
691
|
+
const updated = documentIndex.byId.value.get(entry.id);
|
|
692
|
+
const content = updated ? updated.content : (await adapter.read(entry.path)).content;
|
|
693
|
+
return {
|
|
694
|
+
fileId: entry.id,
|
|
695
|
+
hash: await assistantHash(content),
|
|
696
|
+
status: 'applied',
|
|
697
|
+
};
|
|
698
|
+
});
|
|
699
|
+
}
|
|
305
700
|
return serial(async () => {
|
|
306
701
|
const assertCurrent = () => {
|
|
307
702
|
assertInstance();
|
|
308
703
|
if (!expected || workspace.value?.id !== expected) throw new Error(t('工作区已切换'));
|
|
309
704
|
};
|
|
310
705
|
assertCurrent();
|
|
706
|
+
const attachmentService =
|
|
707
|
+
runtime.attachments ??
|
|
708
|
+
(runtime.native && adapter.mode === 'desktop' ? nativeAttachments : undefined);
|
|
311
709
|
if (method === 'attachments.read')
|
|
312
710
|
return pluginAttachmentReader.read(
|
|
313
711
|
workspace.value!,
|
|
314
712
|
params,
|
|
315
|
-
|
|
316
|
-
(runtime.native && adapter.mode === 'desktop' ? nativeAttachments : undefined),
|
|
713
|
+
attachmentService,
|
|
317
714
|
assertCurrent,
|
|
318
715
|
);
|
|
716
|
+
if (method === 'attachments.write') {
|
|
717
|
+
writable();
|
|
718
|
+
if (!attachmentService?.importAttachment)
|
|
719
|
+
throw new Error('当前宿主不支持写入附件');
|
|
720
|
+
const parsed = parsePluginAttachmentWrite(params.request);
|
|
721
|
+
const targetDocPath = parsed.documentPath || (pathScopes?.length ? `${pathScopes[0]!}note.md` : '');
|
|
722
|
+
if (pathScopes?.length && !matchesPluginPathScopes(targetDocPath, pathScopes))
|
|
723
|
+
throw new Error('附件目标目录不在插件授权目录范围内');
|
|
724
|
+
const fileBytes = new Uint8Array(parsed.bytes);
|
|
725
|
+
const uploadFile = new File([fileBytes], parsed.name, { type: parsed.mimeType });
|
|
726
|
+
assertCurrent();
|
|
727
|
+
const imported = await attachmentService.importAttachment(
|
|
728
|
+
workspace.value!.id,
|
|
729
|
+
targetDocPath,
|
|
730
|
+
uploadFile,
|
|
731
|
+
parsed.image,
|
|
732
|
+
);
|
|
733
|
+
assertCurrent();
|
|
734
|
+
workspace.value = await adapter.refresh();
|
|
735
|
+
return imported;
|
|
736
|
+
}
|
|
319
737
|
workspace.value = await adapter.refresh();
|
|
320
738
|
await refreshObjects();
|
|
321
739
|
assertCurrent();
|
|
@@ -337,6 +755,8 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
337
755
|
const entry = fileRegistry.value?.get(String(params.fileId));
|
|
338
756
|
if (!entry || !isMarkdown(entry.path) || isWorkspaceInternalPath(entry.path))
|
|
339
757
|
throw new Error('文档不存在或不可访问');
|
|
758
|
+
if (!matchesPluginPathScopes(entry.path, pathScopes))
|
|
759
|
+
throw new Error('文档路径不在插件授权目录范围内');
|
|
340
760
|
return entry;
|
|
341
761
|
};
|
|
342
762
|
const text = (value: unknown) => {
|
|
@@ -348,7 +768,10 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
348
768
|
return current.files
|
|
349
769
|
.filter(
|
|
350
770
|
(row) =>
|
|
351
|
-
row.kind === 'file' &&
|
|
771
|
+
row.kind === 'file' &&
|
|
772
|
+
isMarkdown(row.path) &&
|
|
773
|
+
!isWorkspaceInternalPath(row.path) &&
|
|
774
|
+
matchesPluginPathScopes(row.path, pathScopes),
|
|
352
775
|
)
|
|
353
776
|
.map(({ id, path, name, readOnly }) => ({
|
|
354
777
|
id,
|
|
@@ -390,12 +813,79 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
390
813
|
if (method === 'documents.create') {
|
|
391
814
|
const path = text(params.path);
|
|
392
815
|
if (!isMarkdown(path) || validatePath(path)) throw new Error('新文档路径无效');
|
|
816
|
+
if (!matchesPluginPathScopes(path, pathScopes))
|
|
817
|
+
throw new Error('新文档路径不在插件授权目录范围内');
|
|
393
818
|
assertCurrent();
|
|
394
819
|
await adapter.create(path, text(params.content));
|
|
395
820
|
workspace.value = await adapter.refresh();
|
|
396
821
|
const entry = fileRegistry.value?.at(path)!;
|
|
397
822
|
return { id: entry.id, path };
|
|
398
823
|
}
|
|
824
|
+
if (method === 'documents.move') {
|
|
825
|
+
const entry = file();
|
|
826
|
+
if (entry.readOnly) throw new Error('你对这篇文档只有阅读权限');
|
|
827
|
+
const destination = text(params.destination);
|
|
828
|
+
if (!isMarkdown(destination) || validatePath(destination) || isWorkspaceInternalPath(destination))
|
|
829
|
+
throw new Error('目标文档路径无效');
|
|
830
|
+
if (!matchesPluginPathScopes(destination, pathScopes))
|
|
831
|
+
throw new Error('目标路径不在插件授权目录范围内');
|
|
832
|
+
if (destination === entry.path) return { id: entry.id, path: entry.path };
|
|
833
|
+
if (current.files.some((row) => row.path === destination))
|
|
834
|
+
throw new Error('目标路径已存在同名文件');
|
|
835
|
+
if (!pluginRecord(params.base) || params.base.id !== entry.id || typeof params.base.content !== 'string')
|
|
836
|
+
throw new Error('文档版本无效');
|
|
837
|
+
const doc = documentIndex.byId.value.get(entry.id);
|
|
838
|
+
if (doc?.conflict || doc?.missing) throw new Error('请先处理文档已有冲突');
|
|
839
|
+
if (doc && dirty(doc)) throw new Error('文档存在未保存修改,请先保存后再移动');
|
|
840
|
+
const disk = await adapter.read(entry.path);
|
|
841
|
+
if (disk.content !== params.base.content)
|
|
842
|
+
throw new Error('文档内容已变化,请重新读取后再移动');
|
|
843
|
+
assertCurrent();
|
|
844
|
+
if (adapter.changeFile) {
|
|
845
|
+
const result = await adapter.changeFile({
|
|
846
|
+
workspaceId: current.id,
|
|
847
|
+
fileId: entry.id,
|
|
848
|
+
path: entry.path,
|
|
849
|
+
expectedHash: disk.hash,
|
|
850
|
+
destination,
|
|
851
|
+
});
|
|
852
|
+
if (result.status !== 'saved') throw new Error('文档内容已变化或不存在,请重新读取后再移动');
|
|
853
|
+
} else {
|
|
854
|
+
await adapter.move(entry.path, destination, 'file');
|
|
855
|
+
}
|
|
856
|
+
assertCurrent();
|
|
857
|
+
workspace.value = await adapter.refresh();
|
|
858
|
+
if (doc) doc.path = destination;
|
|
859
|
+
return { id: entry.id, path: destination };
|
|
860
|
+
}
|
|
861
|
+
if (method === 'documents.trash') {
|
|
862
|
+
const entry = file();
|
|
863
|
+
if (entry.readOnly) throw new Error('你对这篇文档只有阅读权限');
|
|
864
|
+
if (!pluginRecord(params.base) || params.base.id !== entry.id || typeof params.base.content !== 'string')
|
|
865
|
+
throw new Error('文档版本无效');
|
|
866
|
+
const doc = documentIndex.byId.value.get(entry.id);
|
|
867
|
+
if (doc?.conflict || doc?.missing) throw new Error('请先处理文档已有冲突');
|
|
868
|
+
if (doc && dirty(doc)) throw new Error('文档存在未保存修改,请先保存后再移入回收站');
|
|
869
|
+
const disk = await adapter.read(entry.path);
|
|
870
|
+
if (disk.content !== params.base.content)
|
|
871
|
+
throw new Error('文档内容已变化,请重新读取后再移入回收站');
|
|
872
|
+
assertCurrent();
|
|
873
|
+
if (adapter.changeFile) {
|
|
874
|
+
const result = await adapter.changeFile({
|
|
875
|
+
workspaceId: current.id,
|
|
876
|
+
fileId: entry.id,
|
|
877
|
+
path: entry.path,
|
|
878
|
+
expectedHash: disk.hash,
|
|
879
|
+
});
|
|
880
|
+
if (result.status !== 'saved') throw new Error('文档内容已变化或不存在,请重新读取后再移入回收站');
|
|
881
|
+
} else {
|
|
882
|
+
await adapter.remove(entry.path);
|
|
883
|
+
}
|
|
884
|
+
assertCurrent();
|
|
885
|
+
workspace.value = await adapter.refresh();
|
|
886
|
+
if (doc) doc.missing = true;
|
|
887
|
+
return { id: entry.id, path: entry.path, trashed: true };
|
|
888
|
+
}
|
|
399
889
|
if (method === 'documents.write') {
|
|
400
890
|
const entry = file();
|
|
401
891
|
if (entry.readOnly) throw new Error('你对这篇文档只有阅读权限');
|
|
@@ -432,7 +922,7 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
432
922
|
status: 'applied',
|
|
433
923
|
};
|
|
434
924
|
}
|
|
435
|
-
if (doc &&
|
|
925
|
+
if (doc && pluginEditorBridge && (await pluginEditorBridge.applyEdit(entry.id, doc.content, merged.content))) {
|
|
436
926
|
return { id: entry.id, hash: await assistantHash(doc.content), status: 'applied' };
|
|
437
927
|
}
|
|
438
928
|
if (doc) {
|
|
@@ -626,17 +1116,28 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
626
1116
|
}
|
|
627
1117
|
|
|
628
1118
|
function disposePlugins() {
|
|
1119
|
+
cancelActivePluginDialog('工作区已关闭');
|
|
1120
|
+
for (const timer of toastTimers.values()) clearTimeout(timer);
|
|
1121
|
+
toastTimers.clear();
|
|
1122
|
+
pluginToasts.value = [];
|
|
629
1123
|
pluginAttachmentReader.clear();
|
|
630
1124
|
clearTimeout(pluginEventTimer);
|
|
1125
|
+
overlayExtension()?.dispose?.();
|
|
631
1126
|
pluginServices.dispose();
|
|
632
1127
|
if (typeof window !== 'undefined') window.removeEventListener('storage', pluginStorageChanged);
|
|
633
1128
|
}
|
|
634
1129
|
|
|
635
1130
|
return {
|
|
636
1131
|
pluginRuntime,
|
|
1132
|
+
pluginHostEnvironment,
|
|
637
1133
|
canManagePlugins,
|
|
638
1134
|
installedPlugins,
|
|
639
1135
|
installedPluginWorkspace,
|
|
1136
|
+
personalCodePluginPolicy,
|
|
1137
|
+
overlaySnapshot,
|
|
1138
|
+
setSafeMode: (enabled: boolean) => overlayExtension()?.setSafeMode(enabled),
|
|
1139
|
+
pluginHomeTabView,
|
|
1140
|
+
pluginNewTabView,
|
|
640
1141
|
pluginDevelopment,
|
|
641
1142
|
pluginServices,
|
|
642
1143
|
pluginHost,
|
|
@@ -644,13 +1145,29 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
644
1145
|
pluginDeveloper,
|
|
645
1146
|
pluginViews,
|
|
646
1147
|
pluginCommands,
|
|
1148
|
+
pluginFileHandlers,
|
|
1149
|
+
pluginSlashCommands,
|
|
1150
|
+
pluginCodeBlockRenderers,
|
|
1151
|
+
pluginDecorationsFor,
|
|
1152
|
+
pluginStatusBarItems,
|
|
1153
|
+
pluginContextProviders,
|
|
647
1154
|
activePluginSidebar,
|
|
1155
|
+
activeDocumentPluginSidebar,
|
|
1156
|
+
activePluginDialog,
|
|
1157
|
+
resolvePluginDialog,
|
|
1158
|
+
pluginToasts,
|
|
1159
|
+
dismissPluginToast,
|
|
648
1160
|
pluginSettingsRequest,
|
|
649
1161
|
pluginSettingsPages,
|
|
650
1162
|
pluginError,
|
|
651
1163
|
refreshPlugins,
|
|
652
1164
|
openPluginView,
|
|
653
1165
|
interactWithPlugin,
|
|
1166
|
+
invokePluginAssistantTool,
|
|
1167
|
+
queryPluginAssistantContext,
|
|
1168
|
+
setPluginAiRunner: (runner?: PluginAiRunner) => {
|
|
1169
|
+
pluginAiRunner = runner;
|
|
1170
|
+
},
|
|
654
1171
|
startPluginOAuth,
|
|
655
1172
|
loadPluginConnections,
|
|
656
1173
|
savePluginConnection,
|
|
@@ -658,8 +1175,14 @@ export function createWorkspacePluginsState(deps: WorkspacePluginsStateDeps) {
|
|
|
658
1175
|
removePluginPackage,
|
|
659
1176
|
loadPluginPackageUsage,
|
|
660
1177
|
clearPluginLogs: (id: string) => pluginExecutor.clearLogs(id),
|
|
661
|
-
|
|
662
|
-
|
|
1178
|
+
userPluginIntegrities: () => pluginHost.userPluginIntegrities(),
|
|
1179
|
+
setPluginEditor: (
|
|
1180
|
+
bridge?:
|
|
1181
|
+
| PluginEditorBridge
|
|
1182
|
+
| ((id: string, before: string, after: string) => Promise<boolean>),
|
|
1183
|
+
) => {
|
|
1184
|
+
pluginEditorBridge =
|
|
1185
|
+
typeof bridge === 'function' ? { applyEdit: bridge } : bridge;
|
|
663
1186
|
},
|
|
664
1187
|
disposePlugins,
|
|
665
1188
|
};
|