@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.
- package/package.json +50 -16
- package/src/App.vue +82 -752
- 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/agent-identities.ts +1 -97
- package/src/assistant/agent-task-context.ts +1 -54
- package/src/assistant/attachments.ts +1 -1
- package/src/assistant/completion.ts +1 -61
- package/src/assistant/components/AssistantChangeList.vue +98 -21
- package/src/assistant/components/AssistantPanel.vue +425 -8
- package/src/assistant/components/PluginToolProposalCard.vue +235 -0
- package/src/assistant/connection-actions.ts +237 -0
- package/src/assistant/document-mentions.ts +1 -33
- package/src/assistant/engine.ts +1 -532
- package/src/assistant/execution.ts +6 -33
- package/src/assistant/files.ts +5 -13
- package/src/assistant/hash.ts +1 -4
- package/src/assistant/inbox.ts +1 -148
- package/src/assistant/language.ts +10 -37
- package/src/assistant/mention-autocomplete.ts +69 -0
- package/src/assistant/plugin-bridge-builder.ts +146 -0
- package/src/assistant/prompts.ts +1 -58
- package/src/assistant/proposal-actions.ts +336 -0
- package/src/assistant/results.ts +20 -86
- package/src/assistant/store.ts +167 -327
- package/src/assistant/structures.ts +1 -155
- package/src/assistant/tasks.ts +8 -96
- package/src/assistant/tool-rules.ts +1 -7
- 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-help.ts +177 -0
- package/src/composables/use-workbench-history.ts +2 -4
- package/src/composables/use-workbench-lifecycle.ts +249 -0
- package/src/composables/use-workbench-modals.ts +6 -1
- package/src/composables/use-workbench-outline.ts +0 -5
- package/src/composables/use-workbench-settings.ts +185 -0
- package/src/composables/use-workbench-shortcuts.ts +40 -1021
- package/src/composables/use-workbench-views.ts +325 -0
- package/src/data-tables/data-tables.ts +1 -2
- package/src/documents/components/DocumentActionMenu.vue +279 -0
- package/src/documents/components/DocumentHistoryPanel.vue +3 -1
- package/src/documents/components/DocumentInspector.vue +168 -0
- package/src/documents/components/DocumentPane.vue +482 -0
- package/src/documents/description-merge.ts +1 -9
- package/src/features.ts +1 -0
- package/src/files/components/FileMetadataPanel.vue +49 -15
- 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/locale-catalogs.ts +7 -6
- package/src/i18n/locale-registry.ts +8 -6
- package/src/i18n/locales/de-DE.json +371 -3
- package/src/i18n/locales/en-US.json +371 -2
- package/src/i18n/locales/es-ES.json +371 -3
- package/src/i18n/locales/ja-JP.json +370 -2
- package/src/i18n/locales/zh-TW.json +370 -2
- package/src/mail/components/MailAccountDialog.vue +450 -0
- package/src/mail/components/MailComposerDialog.vue +326 -0
- package/src/mail/components/MailProviderIcon.vue +30 -0
- package/src/mail/components/MailWorkspaceView.vue +821 -0
- package/src/mail/components/SidebarMail.vue +134 -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/content-references.ts +6 -56
- package/src/objects/wiki-links.ts +1 -48
- package/src/objects/workspace-objects.ts +3 -4
- package/src/plan-sync/types.ts +6 -3
- package/src/plans/calendar-interaction.ts +194 -0
- package/src/plans/calendar.ts +65 -9
- package/src/plans/components/CalendarAgendaView.vue +165 -0
- package/src/plans/components/CalendarDayPopover.vue +172 -39
- package/src/plans/components/CalendarFilterBar.vue +128 -0
- package/src/plans/components/CalendarMonthView.vue +224 -0
- package/src/plans/components/CalendarQuickCreateDialog.vue +269 -0
- package/src/plans/components/CalendarTimelineView.vue +517 -0
- package/src/plans/components/CalendarTopbarControls.vue +101 -0
- package/src/plans/components/CalendarView.vue +264 -748
- package/src/plans/components/CalendarYearView.vue +138 -0
- package/src/plans/components/PlanArchiveDialog.vue +295 -0
- package/src/plans/components/PlanConnectionsDialog.vue +1 -1
- 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/components/calendar-shared.css +192 -0
- package/src/plans/composables/use-calendar-interactions.ts +396 -0
- package/src/plans/composables/use-calendar-scroll.ts +420 -0
- 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 +136 -57
- package/src/plugins/components/PluginDeveloperArea.vue +192 -0
- package/src/plugins/components/PluginDocumentSlot.vue +63 -0
- package/src/plugins/components/PluginExplorer.vue +21 -25
- package/src/plugins/components/PluginImportDialog.vue +410 -0
- package/src/plugins/components/PluginInstaller.vue +273 -288
- package/src/plugins/components/PluginListItem.vue +3 -0
- package/src/plugins/components/PluginMaintenance.vue +37 -34
- package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
- package/src/plugins/components/PluginRuntimePanel.vue +3 -3
- package/src/plugins/components/PluginSettingsForm.vue +112 -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/components/PluginsTabPage.vue +61 -0
- package/src/plugins/components/plugin-center.css +5 -0
- package/src/plugins/data.ts +9 -86
- package/src/plugins/editor-plugin-adapters.ts +169 -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-data.ts +2 -3
- package/src/plugins/plugin-permissions.ts +57 -0
- package/src/plugins/plugin-rpc-router.ts +558 -0
- package/src/plugins/plugin-sdk.ts +1 -94
- package/src/plugins/plugin-ui-dialogs.ts +167 -0
- 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 +1 -73
- 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/view-header.ts +2 -7
- 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 +103 -4
- package/src/settings/components/SettingsAppearancePage.vue +46 -0
- package/src/settings/components/SettingsDocumentsPage.vue +0 -1
- package/src/settings/components/SettingsPanel.vue +8 -3
- package/src/settings/components/WorkbenchSettings.vue +20 -7
- package/src/settings/components/settings-context.ts +1 -1
- package/src/settings/components/settings-search.ts +2 -3
- package/src/settings/settings-tab.ts +1 -0
- package/src/shell/command-palette.ts +3 -3
- package/src/shell/components/EditorToolbar.vue +8 -9
- package/src/shell/components/EditorTools.vue +1 -5
- package/src/shell/components/PaneTopbar.vue +393 -0
- package/src/shell/components/SelectionToolbar.vue +0 -2
- package/src/shell/components/SidebarNavigation.vue +22 -2
- package/src/shell/components/WorkbenchContextMenus.vue +58 -34
- package/src/shell/components/WorkbenchModals.vue +47 -62
- package/src/shell/components/WorkbenchPanes.vue +371 -1342
- package/src/shell/components/WorkbenchSidebar.vue +486 -0
- package/src/shell/components/WorkspaceBreadcrumb.vue +6 -14
- package/src/shell/components/WorkspaceViewSwitcher.vue +12 -7
- package/src/shell/pane-registry.ts +69 -0
- package/src/shell/use-surface-dismissal.ts +219 -0
- package/src/shell/use-workbench-commands.ts +599 -0
- package/src/shell/use-workbench-keybindings.ts +337 -0
- package/src/shell/use-workbench.ts +531 -1153
- package/src/shell/workbench-async-components.ts +14 -5
- package/src/shell/workbench-context.ts +30 -3
- 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-document-io.ts +807 -0
- package/src/stores/workspace-file-ops.ts +1 -1
- package/src/stores/workspace-knowledge.ts +2 -114
- package/src/stores/workspace-lifecycle.ts +459 -0
- package/src/stores/workspace-plugins-state.ts +254 -259
- package/src/stores/workspace-session.ts +287 -0
- package/src/stores/workspace-tabs-layout.ts +6 -44
- package/src/stores/workspace-types.ts +50 -0
- package/src/stores/workspace.ts +184 -1363
- 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 +0 -1
- package/src/tabs/components/DesktopTabs.vue +19 -14
- package/src/tabs/components/NewTabPicker.vue +10 -4
- package/src/tabs/tab-label.ts +0 -1
- package/src/windows/AuxiliaryWindows.vue +2 -2
- package/src/windows/use-window-event-bridge.ts +152 -0
- package/src/workspace/components/TemplateLibrary.vue +1 -1
- package/src/workspace/components/WorkspaceGeneralSettings.vue +0 -13
- package/src/workspace/components/WorkspaceIconPicker.vue +30 -7
- package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
- package/src/workspace/workspace-comments.ts +11 -151
- package/src/workspace/workspace-welcome.ts +1 -1
- package/src/assistant/locales/de-DE.json +0 -126
- package/src/assistant/locales/en-US.json +0 -126
- package/src/assistant/locales/es-ES.json +0 -126
- package/src/assistant/locales/ja-JP.json +0 -126
- package/src/assistant/locales/zh-CN.json +0 -126
- package/src/assistant/locales/zh-TW.json +0 -126
- package/src/assistant/task-prompts.json +0 -39
- 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
|
@@ -23,7 +23,19 @@
|
|
|
23
23
|
{
|
|
24
24
|
"id": "document",
|
|
25
25
|
"label": "Word 文档预览",
|
|
26
|
-
"location": "tab"
|
|
26
|
+
"location": "tab",
|
|
27
|
+
"layout": "fill"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"fileHandlers": [
|
|
31
|
+
{
|
|
32
|
+
"extensions": [
|
|
33
|
+
".doc",
|
|
34
|
+
".docx"
|
|
35
|
+
],
|
|
36
|
+
"mode": "preview",
|
|
37
|
+
"view": "document",
|
|
38
|
+
"command": "open"
|
|
27
39
|
}
|
|
28
40
|
]
|
|
29
41
|
}
|
package/src/plugins/workbench.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { isElement } from '@tano/editor/dom-realm';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
isDataTableFilePath,
|
|
4
|
+
isWorkspaceInternalPath,
|
|
5
|
+
matchPluginFileExtension,
|
|
6
|
+
type PluginCodeBlockRendererDefinition,
|
|
7
|
+
type PluginCommandDefinition,
|
|
8
|
+
type PluginEditorDecoration,
|
|
9
|
+
type PluginFileHandlerDefinition,
|
|
10
|
+
type PluginFileHandlerMode,
|
|
11
|
+
type PluginSlashCommandDefinition,
|
|
12
|
+
type PluginStatusBarItem,
|
|
13
|
+
type PluginUiBundle,
|
|
14
|
+
type PluginViewDefinition,
|
|
15
|
+
} from '@tano/protocol';
|
|
3
16
|
import type { InstalledObjectPlugin } from './workspace-plugins';
|
|
4
17
|
import type { PluginRuntimeState } from './host';
|
|
5
18
|
import { shortcutBindingFromEvent, shortcutKeys, shortcutDefinitions, type ShortcutBindings } from '../shell/shortcuts';
|
|
@@ -10,6 +23,21 @@ export interface PluginWorkbenchView extends PluginViewDefinition {
|
|
|
10
23
|
export interface PluginWorkbenchCommand extends PluginCommandDefinition {
|
|
11
24
|
key: string; pluginId: string; pluginName: string; instanceId: string;
|
|
12
25
|
}
|
|
26
|
+
export interface PluginWorkbenchFileHandler extends PluginFileHandlerDefinition {
|
|
27
|
+
pluginId: string; pluginName: string; system: boolean; viewKey: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PluginWorkbenchStatusBarItem extends PluginStatusBarItem {
|
|
30
|
+
key: string; pluginId: string; pluginName: string; instanceId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PluginWorkbenchSlashCommand extends PluginSlashCommandDefinition {
|
|
33
|
+
key: string; pluginId: string; pluginName: string; instanceId: string;
|
|
34
|
+
}
|
|
35
|
+
export interface PluginWorkbenchCodeBlockRenderer extends PluginCodeBlockRendererDefinition {
|
|
36
|
+
key: string; pluginId: string; pluginName: string; instanceId: string; bundle: PluginUiBundle;
|
|
37
|
+
}
|
|
38
|
+
export interface PluginWorkbenchDecoration extends PluginEditorDecoration {
|
|
39
|
+
key: string; pluginId: string; pluginName: string; instanceId: string;
|
|
40
|
+
}
|
|
13
41
|
export interface PluginInteraction {
|
|
14
42
|
workspaceId: string; pluginId: string; instanceId: string; kind: 'command' | 'action' | 'message' | 'diagnostic'; name: string; payload?: unknown;
|
|
15
43
|
}
|
|
@@ -22,10 +50,155 @@ export function pluginWorkbenchViews(installations: InstalledObjectPlugin[]): Pl
|
|
|
22
50
|
? manifest.views.map(view => ({ ...view, key: pluginViewKey(manifest.id, view.id), pluginId: manifest.id, pluginName: manifest.name })) : []);
|
|
23
51
|
}
|
|
24
52
|
export function pluginWorkbenchCommands(states: PluginRuntimeState[]): PluginWorkbenchCommand[] {
|
|
25
|
-
return states.filter(state => state.status === 'running').flatMap(state => state.commands.map(command => ({
|
|
53
|
+
return states.filter(state => state.status === 'running' || state.status === 'idle').flatMap(state => state.commands.map(command => ({
|
|
26
54
|
...command, key: `plugin:${state.id}:${command.id}`, pluginId: state.id, pluginName: state.name, instanceId: state.instanceId,
|
|
27
55
|
})));
|
|
28
56
|
}
|
|
57
|
+
export function pluginWorkbenchStatusBarItems(states: PluginRuntimeState[]): PluginWorkbenchStatusBarItem[] {
|
|
58
|
+
return states
|
|
59
|
+
.filter(state => state.status === 'running')
|
|
60
|
+
.flatMap(state =>
|
|
61
|
+
(state.statusBar ?? []).map(item => ({
|
|
62
|
+
...item,
|
|
63
|
+
key: `plugin:${state.id}:status:${item.id}`,
|
|
64
|
+
pluginId: state.id,
|
|
65
|
+
pluginName: state.name,
|
|
66
|
+
instanceId: state.instanceId,
|
|
67
|
+
})),
|
|
68
|
+
)
|
|
69
|
+
.sort((left, right) =>
|
|
70
|
+
(right.priority ?? 0) - (left.priority ?? 0) ||
|
|
71
|
+
left.pluginId.localeCompare(right.pluginId) ||
|
|
72
|
+
left.id.localeCompare(right.id),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
export function pluginWorkbenchSlashCommands(
|
|
76
|
+
installations: InstalledObjectPlugin[],
|
|
77
|
+
states: PluginRuntimeState[],
|
|
78
|
+
): PluginWorkbenchSlashCommand[] {
|
|
79
|
+
const active = new Map(
|
|
80
|
+
states.filter(state => state.status === 'running' || state.status === 'idle').map(state => [state.id, state]),
|
|
81
|
+
);
|
|
82
|
+
return installations.flatMap(item => {
|
|
83
|
+
const { manifest } = item;
|
|
84
|
+
if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.slashCommands?.length) return [];
|
|
85
|
+
const runtime = active.get(manifest.id);
|
|
86
|
+
if (!runtime) return [];
|
|
87
|
+
const registered = new Set(runtime.commands.map(command => command.id));
|
|
88
|
+
return manifest.slashCommands
|
|
89
|
+
.filter(slash => registered.has(slash.command))
|
|
90
|
+
.map(slash => ({
|
|
91
|
+
...slash,
|
|
92
|
+
key: `plugin:${manifest.id}:slash:${slash.id}`,
|
|
93
|
+
pluginId: manifest.id,
|
|
94
|
+
pluginName: manifest.name,
|
|
95
|
+
instanceId: runtime.instanceId,
|
|
96
|
+
}));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export function pluginWorkbenchCodeBlockRenderers(
|
|
100
|
+
installations: InstalledObjectPlugin[],
|
|
101
|
+
states: PluginRuntimeState[],
|
|
102
|
+
): PluginWorkbenchCodeBlockRenderer[] {
|
|
103
|
+
const running = new Map(states.filter(state => state.status === 'running').map(state => [state.id, state]));
|
|
104
|
+
return installations.flatMap(item => {
|
|
105
|
+
const { manifest } = item;
|
|
106
|
+
if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.codeBlockRenderers?.length) return [];
|
|
107
|
+
const runtime = running.get(manifest.id);
|
|
108
|
+
if (!runtime?.uiBundles) return [];
|
|
109
|
+
return manifest.codeBlockRenderers.flatMap(renderer => {
|
|
110
|
+
const bundle = Object.hasOwn(runtime.uiBundles!, renderer.view) ? runtime.uiBundles![renderer.view] : undefined;
|
|
111
|
+
if (!bundle) return [];
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
...renderer,
|
|
115
|
+
key: `plugin:${manifest.id}:codeblock:${renderer.view}`,
|
|
116
|
+
pluginId: manifest.id,
|
|
117
|
+
pluginName: manifest.name,
|
|
118
|
+
instanceId: runtime.instanceId,
|
|
119
|
+
bundle,
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
export function pluginWorkbenchDecorations(
|
|
126
|
+
states: PluginRuntimeState[],
|
|
127
|
+
fileId: string,
|
|
128
|
+
): PluginWorkbenchDecoration[] {
|
|
129
|
+
if (!fileId) return [];
|
|
130
|
+
return states
|
|
131
|
+
.filter(state => state.status === 'running')
|
|
132
|
+
.flatMap(state =>
|
|
133
|
+
(state.decorations?.[fileId] ?? []).map((item, index) => ({
|
|
134
|
+
...item,
|
|
135
|
+
key: `plugin:${state.id}:deco:${fileId}:${item.id ?? index}`,
|
|
136
|
+
pluginId: state.id,
|
|
137
|
+
pluginName: state.name,
|
|
138
|
+
instanceId: state.instanceId,
|
|
139
|
+
})),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
export function pluginWorkbenchFileHandlers(
|
|
143
|
+
installations: InstalledObjectPlugin[],
|
|
144
|
+
states: PluginRuntimeState[],
|
|
145
|
+
): PluginWorkbenchFileHandler[] {
|
|
146
|
+
const active = new Map(states.filter(state => state.status === 'running' || state.status === 'idle').map(state => [state.id, state]));
|
|
147
|
+
return installations.flatMap(item => {
|
|
148
|
+
const { manifest } = item;
|
|
149
|
+
if (!item.enabled || manifest.manifestVersion !== 2 || !manifest.fileHandlers?.length) return [];
|
|
150
|
+
const runtime = active.get(manifest.id);
|
|
151
|
+
if (!runtime) return [];
|
|
152
|
+
const registered = new Set(runtime.commands.map(command => command.id));
|
|
153
|
+
return manifest.fileHandlers
|
|
154
|
+
.filter(handler => registered.has(handler.command))
|
|
155
|
+
.map(handler => ({
|
|
156
|
+
...handler,
|
|
157
|
+
pluginId: manifest.id,
|
|
158
|
+
pluginName: manifest.name,
|
|
159
|
+
system: !!item.system,
|
|
160
|
+
viewKey: pluginViewKey(manifest.id, handler.view),
|
|
161
|
+
}));
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export function resolvePluginFileHandler(
|
|
165
|
+
path: string,
|
|
166
|
+
mode: PluginFileHandlerMode,
|
|
167
|
+
handlers: readonly PluginWorkbenchFileHandler[],
|
|
168
|
+
): PluginWorkbenchFileHandler | undefined {
|
|
169
|
+
if (!path || isWorkspaceInternalPath(path) || isDataTableFilePath(path)) return undefined;
|
|
170
|
+
let bestLength = 0;
|
|
171
|
+
let matches: PluginWorkbenchFileHandler[] = [];
|
|
172
|
+
for (const handler of handlers) {
|
|
173
|
+
if (handler.mode !== mode) continue;
|
|
174
|
+
let longest = 0;
|
|
175
|
+
for (const ext of handler.extensions) {
|
|
176
|
+
if (matchPluginFileExtension(path, ext) && ext.length > longest) longest = ext.length;
|
|
177
|
+
}
|
|
178
|
+
if (!longest) continue;
|
|
179
|
+
if (longest > bestLength) {
|
|
180
|
+
bestLength = longest;
|
|
181
|
+
matches = [handler];
|
|
182
|
+
} else if (longest === bestLength) {
|
|
183
|
+
matches.push(handler);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (matches.length === 1) return matches[0];
|
|
187
|
+
if (matches.length > 1) {
|
|
188
|
+
const systemMatches = matches.filter(item => item.system);
|
|
189
|
+
if (systemMatches.length === 1) return systemMatches[0];
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
export function isPluginPreviewTab(tabId: string, installations: readonly InstalledObjectPlugin[]): boolean {
|
|
194
|
+
return installations.some(item =>
|
|
195
|
+
item.enabled &&
|
|
196
|
+
item.manifest.manifestVersion === 2 &&
|
|
197
|
+
!!item.manifest.fileHandlers?.some(
|
|
198
|
+
handler => handler.mode === 'preview' && pluginViewKey(item.manifest.id, handler.view) === tabId,
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
29
202
|
// Host/editor bindings win. Ambiguous plugin bindings never trigger either command.
|
|
30
203
|
// Formatting/navigation and browser reserved keys must remain available to the host.
|
|
31
204
|
const reserved = new Set(['Mod+B', 'Mod+I', 'Mod+U', 'Mod+Z', 'Mod+Y', 'Mod+Shift+Z', 'Mod+A', 'Mod+C', 'Mod+V', 'Mod+X', 'Mod+L', 'Mod+R', 'Mod+W', 'Mod+T', 'Mod+P', 'F5', 'F12']);
|
package/src/plugins/worker.js
CHANGED
|
@@ -3,7 +3,11 @@ const pending = new Map();
|
|
|
3
3
|
const commands = new Map();
|
|
4
4
|
const actions = new Map();
|
|
5
5
|
const viewMessages = new Map();
|
|
6
|
+
const assistantTools = new Map();
|
|
7
|
+
const assistantContextProviders = new Map();
|
|
8
|
+
const services = new Map();
|
|
6
9
|
const listeners = new Set();
|
|
10
|
+
const deactivators = new Set();
|
|
7
11
|
for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
|
|
8
12
|
console[level] = (...values) => {
|
|
9
13
|
const message = values.map(value => { try { return value instanceof Error ? value.stack || String(value) : typeof value === 'string' ? value : JSON.stringify(value); } catch { return String(value); } }).join(' ').slice(0, 1500);
|
|
@@ -12,16 +16,31 @@ for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
|
|
|
12
16
|
}
|
|
13
17
|
addEventListener('unhandledrejection', event => { console.error(event.reason); event.preventDefault(); });
|
|
14
18
|
let sequence = 0;
|
|
15
|
-
const call = (method, params = {}) => new Promise((resolve, reject) => {
|
|
19
|
+
const call = (method, params = {}, timeoutMs = 30000) => new Promise((resolve, reject) => {
|
|
16
20
|
if (pending.size >= 32) return reject(new Error('插件请求过多'));
|
|
17
21
|
const id = ++sequence;
|
|
18
|
-
const timer = setTimeout(() => { pending.delete(id); reject(new Error('插件请求超时')); },
|
|
22
|
+
const timer = setTimeout(() => { pending.delete(id); reject(new Error('插件请求超时')); }, timeoutMs);
|
|
19
23
|
pending.set(id, { resolve, reject, timer });
|
|
20
24
|
postMessage({ type: 'call', id, method, params });
|
|
21
25
|
});
|
|
22
26
|
const tano = Object.freeze({
|
|
23
27
|
context: () => call('context'),
|
|
24
|
-
|
|
28
|
+
hostInfo: () => call('hostInfo'),
|
|
29
|
+
lifecycle: Object.freeze({
|
|
30
|
+
onDeactivate: handler => {
|
|
31
|
+
if (typeof handler !== 'function') throw new Error('卸载回调必须提供处理函数');
|
|
32
|
+
deactivators.add(handler);
|
|
33
|
+
return () => deactivators.delete(handler);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
assets: Object.freeze({
|
|
37
|
+
list: () => call('assets.list'),
|
|
38
|
+
read: path => call('assets.read', { path }),
|
|
39
|
+
}),
|
|
40
|
+
attachments: Object.freeze({
|
|
41
|
+
read: (fileId, offset = 0, revision) => call('attachments.read', { fileId, offset, revision }),
|
|
42
|
+
write: request => call('attachments.write', { request }),
|
|
43
|
+
}),
|
|
25
44
|
documents: Object.freeze({
|
|
26
45
|
list: () => call('documents.list'),
|
|
27
46
|
query: options => call('documents.query', { options }),
|
|
@@ -30,7 +49,20 @@ const tano = Object.freeze({
|
|
|
30
49
|
write: (fileId, content, baseHash) => call('documents.write', { fileId, content, baseHash }),
|
|
31
50
|
edit: (fileId, edits, baseHash) => call('documents.edit', { fileId, edits, baseHash }),
|
|
32
51
|
create: (path, content) => call('documents.create', { path, content }),
|
|
52
|
+
move: (fileId, destination, baseHash) => call('documents.move', { fileId, destination, baseHash }),
|
|
53
|
+
trash: (fileId, baseHash) => call('documents.trash', { fileId, baseHash }),
|
|
33
54
|
open: fileId => call('documents.open', { fileId }),
|
|
55
|
+
frontmatter: Object.freeze({
|
|
56
|
+
read: fileId => call('documents.frontmatter.read', { fileId }),
|
|
57
|
+
update: (fileId, patch, baseHash) => call('documents.frontmatter.update', { fileId, patch, baseHash }),
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
editor: Object.freeze({
|
|
61
|
+
active: () => call('editor.active'),
|
|
62
|
+
insert: text => call('editor.insert', { text }),
|
|
63
|
+
replaceSelection: text => call('editor.replaceSelection', { text }),
|
|
64
|
+
setDecorations: (fileId, decorations) => call('editor.setDecorations', { fileId, decorations }),
|
|
65
|
+
clearDecorations: fileId => call('editor.clearDecorations', fileId === undefined ? {} : { fileId }),
|
|
34
66
|
}),
|
|
35
67
|
objects: Object.freeze({ list: () => call('objects.list'), query: options => call('objects.query', { options }), read: objectId => call('objects.read', { objectId }), create: object => call('objects.create', { object }),
|
|
36
68
|
update: (object, baseHash) => call('objects.update', { object, baseHash }) }),
|
|
@@ -50,6 +82,39 @@ const tano = Object.freeze({
|
|
|
50
82
|
open: id => call('views.open', { id }),
|
|
51
83
|
onMessage: (id, handler) => { viewMessages.set(id, handler); return () => viewMessages.delete(id); },
|
|
52
84
|
onAction: (id, handler) => { actions.set(id, handler); return () => actions.delete(id); } }),
|
|
85
|
+
ui: Object.freeze({
|
|
86
|
+
pick: options => call('ui.pick', { options }, 300000),
|
|
87
|
+
prompt: options => call('ui.prompt', { options }, 300000),
|
|
88
|
+
confirm: options => call('ui.confirm', { options }, 300000),
|
|
89
|
+
toast: (message, tone) => call('ui.toast', tone === undefined ? { message } : { message, tone }),
|
|
90
|
+
setStatusBar: item => call('ui.setStatusBar', { item }),
|
|
91
|
+
removeStatusBar: id => call('ui.removeStatusBar', { id }),
|
|
92
|
+
}),
|
|
93
|
+
ai: Object.freeze({
|
|
94
|
+
complete: request => call('ai.complete', { request }, 65000),
|
|
95
|
+
structured: request => call('ai.structured', { request }, 65000),
|
|
96
|
+
}),
|
|
97
|
+
assistant: Object.freeze({
|
|
98
|
+
registerTool: async (name, handler) => {
|
|
99
|
+
if (typeof handler !== 'function') throw new Error('助手工具必须提供处理函数');
|
|
100
|
+
assistantTools.set(name, handler);
|
|
101
|
+
await call('assistant.registerTool', { name });
|
|
102
|
+
},
|
|
103
|
+
registerContextProvider: async (id, handler) => {
|
|
104
|
+
if (typeof handler !== 'function') throw new Error('助手上下文提供者必须提供处理函数');
|
|
105
|
+
assistantContextProviders.set(id, handler);
|
|
106
|
+
await call('assistant.registerContextProvider', { id });
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
services: Object.freeze({
|
|
110
|
+
register: async (name, handler) => {
|
|
111
|
+
if (typeof handler !== 'function') throw new Error('插件服务必须提供处理函数');
|
|
112
|
+
services.set(name, handler);
|
|
113
|
+
await call('services.register', { name });
|
|
114
|
+
},
|
|
115
|
+
call: (pluginId, service, payload = null) => call('services.call', { pluginId, service, payload }, 20000),
|
|
116
|
+
available: (pluginId, service) => call('services.available', { pluginId, service }),
|
|
117
|
+
}),
|
|
53
118
|
events: Object.freeze({ subscribe: (handler, options = {}) => {
|
|
54
119
|
if (typeof handler !== 'function') throw new Error('事件必须提供处理函数');
|
|
55
120
|
const listener = event => {
|
|
@@ -70,13 +135,45 @@ onmessage = async ({ data }) => {
|
|
|
70
135
|
const request = pending.get(data.id);
|
|
71
136
|
if (!request) return;
|
|
72
137
|
clearTimeout(request.timer); pending.delete(data.id);
|
|
73
|
-
if (data.error)
|
|
138
|
+
if (data.error) {
|
|
139
|
+
const error = new Error(data.error);
|
|
140
|
+
if (typeof data.code === 'string') {
|
|
141
|
+
error.name = 'TanoPluginError';
|
|
142
|
+
error.code = data.code;
|
|
143
|
+
error.retryable = !!data.retryable;
|
|
144
|
+
}
|
|
145
|
+
request.reject(error);
|
|
146
|
+
} else request.resolve(data.result);
|
|
147
|
+
} else if (data?.type === 'deactivate') {
|
|
148
|
+
(async () => {
|
|
149
|
+
for (const handler of [...deactivators]) {
|
|
150
|
+
try { await handler(); } catch (error) { postMessage({ type: 'log', level: 'warn', error: String(error) }); }
|
|
151
|
+
}
|
|
152
|
+
deactivators.clear();
|
|
153
|
+
})().finally(() => postMessage({ type: 'deactivated' }));
|
|
74
154
|
} else if (data?.type === 'invoke') {
|
|
75
155
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
156
|
+
if (data.kind === 'assistant-tool') {
|
|
157
|
+
const handler = assistantTools.get(data.name);
|
|
158
|
+
if (!handler) throw new Error('插件助手工具处理函数尚未注册');
|
|
159
|
+
const result = await handler(data.payload?.args ?? {}, data.payload?.context ?? {});
|
|
160
|
+
postMessage({ type: 'invoked', id: data.id, result });
|
|
161
|
+
} else if (data.kind === 'assistant-context') {
|
|
162
|
+
const handler = assistantContextProviders.get(data.name);
|
|
163
|
+
if (!handler) throw new Error('插件助手上下文提供者尚未注册');
|
|
164
|
+
const result = await handler(data.payload?.query ?? '', data.payload?.context ?? {});
|
|
165
|
+
postMessage({ type: 'invoked', id: data.id, result });
|
|
166
|
+
} else if (data.kind === 'service') {
|
|
167
|
+
const handler = services.get(data.name);
|
|
168
|
+
if (!handler) throw new Error('插件服务处理函数尚未注册');
|
|
169
|
+
const result = await handler(data.payload?.args ?? null, { pluginId: data.payload?.callerPluginId ?? '' });
|
|
170
|
+
postMessage({ type: 'invoked', id: data.id, result });
|
|
171
|
+
} else {
|
|
172
|
+
const handler = data.kind === 'command' ? commands.get(data.name) : data.kind === 'message' ? viewMessages.get(data.name) : actions.get(data.name);
|
|
173
|
+
if (!handler) throw new Error('插件处理函数尚未注册');
|
|
174
|
+
await handler(data.payload);
|
|
175
|
+
postMessage({ type: 'invoked', id: data.id });
|
|
176
|
+
}
|
|
80
177
|
} catch (error) { postMessage({ type: 'invoked', id: data.id, error: String(error) }); }
|
|
81
178
|
} else if (data?.type === 'event') {
|
|
82
179
|
for (const listener of listeners) Promise.resolve().then(() => listener(data.event)).catch(error => postMessage({ type: 'log', error: String(error) }));
|
|
@@ -71,10 +71,15 @@ export class WorkspacePluginRuntime {
|
|
|
71
71
|
signal.throwIfAborted();
|
|
72
72
|
return parsePluginCatalog(JSON.stringify(value));
|
|
73
73
|
}
|
|
74
|
-
installCatalogRelease = async (
|
|
74
|
+
installCatalogRelease = async (
|
|
75
|
+
release: PluginCatalogRelease,
|
|
76
|
+
expectedWorkspace: string,
|
|
77
|
+
signal: AbortSignal,
|
|
78
|
+
scope: 'workspace' | 'user' = 'workspace',
|
|
79
|
+
) => {
|
|
75
80
|
const assertCurrent = () => {
|
|
76
81
|
signal.throwIfAborted();
|
|
77
|
-
this.assertWorkspace(expectedWorkspace,
|
|
82
|
+
this.assertWorkspace(expectedWorkspace, scope === 'workspace');
|
|
78
83
|
};
|
|
79
84
|
assertCurrent();
|
|
80
85
|
if (!this.host.services?.catalog || release.status !== 'published') throw new Error('此目录版本不可安装');
|
|
@@ -84,21 +89,32 @@ export class WorkspacePluginRuntime {
|
|
|
84
89
|
await verifyCatalogPackage(release, pkg); assertCurrent();
|
|
85
90
|
return this.host.serial(async () => {
|
|
86
91
|
assertCurrent(); await this.refresh(); assertCurrent();
|
|
87
|
-
await this.policy.changeWorkspace(
|
|
92
|
+
await this.policy.changeWorkspace(
|
|
93
|
+
this.host.adapter,
|
|
94
|
+
this.host.workspace()!,
|
|
95
|
+
{ install: pkg.manifest, package: pkg, sourceUrl: downloaded.sourceUrl, scope },
|
|
96
|
+
assertCurrent,
|
|
97
|
+
scope === 'workspace' ? this.host.services?.repository : undefined,
|
|
98
|
+
);
|
|
88
99
|
assertCurrent(); await this.refresh();
|
|
89
100
|
});
|
|
90
101
|
}
|
|
91
|
-
authorizePlugin = async (
|
|
102
|
+
authorizePlugin = async (
|
|
103
|
+
id: string,
|
|
104
|
+
integrity: string | undefined,
|
|
105
|
+
expectedWorkspace: string,
|
|
106
|
+
options?: { allWorkspaces?: boolean },
|
|
107
|
+
) => {
|
|
92
108
|
if (!integrity && this.host.workspace()?.id === expectedWorkspace && this.developmentState.pluginId === id) this.developer.stop();
|
|
93
109
|
return this.host.serial(async () => {
|
|
94
110
|
this.assertWorkspace(expectedWorkspace);
|
|
95
|
-
this.policy.authorize(expectedWorkspace, id, integrity);
|
|
111
|
+
this.policy.authorize(expectedWorkspace, id, integrity, undefined, options);
|
|
96
112
|
await this.host.refresh();
|
|
97
113
|
});
|
|
98
114
|
}
|
|
99
|
-
cachePluginPackage = async (content: string) => {
|
|
115
|
+
cachePluginPackage = async (content: string, binaryAssets?: Record<string, Uint8Array>) => {
|
|
100
116
|
const pkg = parsePluginPackage(content);
|
|
101
|
-
const integrity = await new PluginPackageCache().put(pkg);
|
|
117
|
+
const integrity = await new PluginPackageCache().put(pkg, binaryAssets);
|
|
102
118
|
this.executor.invalidate(pkg.manifest.id);
|
|
103
119
|
return integrity;
|
|
104
120
|
}
|