@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,5 +5,6 @@
|
|
|
5
5
|
"objectTypes": [], "relationTypes": [], "permissions": ["attachments.read", "ui"],
|
|
6
6
|
"networkOrigins": [], "nativeCommands": [],
|
|
7
7
|
"commands": [{ "id": "open", "label": "演示文稿:打开预览" }],
|
|
8
|
-
"views": [{ "id": "slides", "label": "演示文稿预览", "location": "tab" }]
|
|
8
|
+
"views": [{ "id": "slides", "label": "演示文稿预览", "location": "tab", "layout": "fill" }],
|
|
9
|
+
"fileHandlers": [{ "extensions": [".ppt", ".pptx"], "mode": "preview", "view": "slides", "command": "open" }]
|
|
9
10
|
}
|
package/src/plugins/queries.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { canonicalPluginJson, isMarkdown, isWorkspaceInternalPath, pluginRecord } from '@tano/protocol';
|
|
1
|
+
import { canonicalPluginJson, isMarkdown, isWorkspaceInternalPath, matchesPluginPathScopes, pluginRecord } from '@tano/protocol';
|
|
2
2
|
import type { Workspace, WorkspaceRelation, WorkspaceObject } from '@tano/protocol';
|
|
3
3
|
import type { PluginDocumentEntry, PluginPageOptions } from './plugin-sdk';
|
|
4
4
|
import { assistantHash } from '../assistant/hash';
|
|
@@ -17,12 +17,14 @@ export interface PluginQueryContext {
|
|
|
17
17
|
export async function queryPluginData(method: string, params: Record<string, unknown>, pager: PluginQueryPager, context: PluginQueryContext) {
|
|
18
18
|
const { workspace, objects, relations, drafts, assertCurrent } = context;
|
|
19
19
|
const scope = `${workspace.id}:${String(params.queryScope)}`;
|
|
20
|
+
const pathScopes = Array.isArray(params.pathScopes) ? (params.pathScopes as string[]) : undefined;
|
|
20
21
|
if (method === 'documents.query' || method === 'documents.search') {
|
|
21
22
|
const options = pluginQueryOptions(params.options, method === 'documents.search' ? ['query', 'pathPrefix', 'readOnly'] : ['query', 'pathPrefix', 'readOnly', 'sort']);
|
|
22
23
|
const query = queryText(options.query) ?? '', prefix = queryText(options.pathPrefix, 1000) ?? '', readOnly = queryBoolean(options.readOnly);
|
|
23
24
|
if (options.sort !== undefined && !['path', 'name', 'modified'].includes(String(options.sort))) throw new Error('文档排序字段无效');
|
|
24
25
|
if (method === 'documents.search' && !query.trim()) throw new Error('请输入搜索文本');
|
|
25
26
|
const rows = workspace.files.filter(row => row.kind === 'file' && isMarkdown(row.path) && !isWorkspaceInternalPath(row.path) &&
|
|
27
|
+
matchesPluginPathScopes(row.path, pathScopes) &&
|
|
26
28
|
row.path.startsWith(prefix) && (readOnly === undefined || !!(workspace.readOnly || row.readOnly) === readOnly) &&
|
|
27
29
|
(method === 'documents.search' || `${row.path}\n${row.name}`.toLowerCase().includes(query.toLowerCase())));
|
|
28
30
|
const sort = String(options.sort ?? 'path'), direction = options.direction === 'desc' ? -1 : 1;
|
package/src/plugins/sandbox.ts
CHANGED
|
@@ -4,6 +4,7 @@ import workerSource from './worker.js?raw';
|
|
|
4
4
|
export interface PluginSandbox {
|
|
5
5
|
send(message: unknown): void;
|
|
6
6
|
dispose(): void;
|
|
7
|
+
gracefulDispose?(timeoutMs?: number): void;
|
|
7
8
|
}
|
|
8
9
|
export type PluginSandboxFactory = (source: string, receive: (message: unknown) => void, failed: (error: string) => void) => PluginSandbox;
|
|
9
10
|
|
|
@@ -40,11 +41,24 @@ export const createPluginSandbox: PluginSandboxFactory = (source, receive, faile
|
|
|
40
41
|
// There are no plugin-controlled URLs or HTML in this document.
|
|
41
42
|
frame.srcdoc = `<!doctype html><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-HqAH3w25zKsq8qlxnq/FqwEwwxm4jFIT+lkTXMahrdU=' blob:; worker-src blob:; connect-src 'none'; child-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'"><script>${sandboxBootstrap}</script>`;
|
|
42
43
|
document.body.append(frame);
|
|
44
|
+
const teardown = () => {
|
|
45
|
+
channel.port1.close(); channel.port2.close(); frame.remove();
|
|
46
|
+
};
|
|
43
47
|
return {
|
|
44
48
|
send(message) { if (!disposed) channel.port1.postMessage(message); },
|
|
45
49
|
dispose() {
|
|
46
50
|
if (disposed) return;
|
|
47
|
-
disposed = true;
|
|
51
|
+
disposed = true; teardown();
|
|
52
|
+
},
|
|
53
|
+
gracefulDispose(timeoutMs = 800) {
|
|
54
|
+
if (disposed) return;
|
|
55
|
+
disposed = true;
|
|
56
|
+
const timer = setTimeout(teardown, timeoutMs);
|
|
57
|
+
channel.port1.onmessage = event => {
|
|
58
|
+
if (event.data?.type === 'deactivated') { clearTimeout(timer); teardown(); }
|
|
59
|
+
};
|
|
60
|
+
try { channel.port1.postMessage({ type: 'deactivate' }); }
|
|
61
|
+
catch { clearTimeout(timer); teardown(); }
|
|
48
62
|
},
|
|
49
63
|
};
|
|
50
64
|
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { computed, ref, watch, type Ref } from 'vue';
|
|
2
2
|
import { t } from '../i18n/i18n';
|
|
3
3
|
import { useWorkspaceStore } from '../stores/workspace';
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
parsePluginPathScopes,
|
|
6
|
+
validatePluginSettingsAgainstSchema,
|
|
7
|
+
type PluginManifest,
|
|
8
|
+
type PluginMode,
|
|
9
|
+
} from '@tano/protocol';
|
|
5
10
|
import type { PluginChange } from './workspace-plugins';
|
|
6
11
|
import { bundledPluginCatalog, type PluginCatalogEntry } from './plugin-catalog';
|
|
7
12
|
export function matchesPlugin(plugin: PluginManifest, query: string) {
|
|
@@ -23,13 +28,15 @@ export function usePluginActions(
|
|
|
23
28
|
const busy = computed(() => !!pending.value);
|
|
24
29
|
const policyMode = ref<PluginMode>('recommended'),
|
|
25
30
|
settingsText = ref('{}'),
|
|
26
|
-
sourceUrl = ref('')
|
|
31
|
+
sourceUrl = ref(''),
|
|
32
|
+
pathScopesText = ref('');
|
|
27
33
|
watch(
|
|
28
34
|
selectedInstallation,
|
|
29
35
|
(item) => {
|
|
30
36
|
policyMode.value = item?.rule?.mode ?? 'recommended';
|
|
31
37
|
settingsText.value = JSON.stringify(item?.rule?.settings ?? {}, null, 2);
|
|
32
38
|
sourceUrl.value = item?.rule?.sourceUrl ?? '';
|
|
39
|
+
pathScopesText.value = (item?.pathScopes ?? item?.rule?.pathScopes ?? []).join('\n');
|
|
33
40
|
},
|
|
34
41
|
{ immediate: true },
|
|
35
42
|
);
|
|
@@ -40,11 +47,11 @@ export function usePluginActions(
|
|
|
40
47
|
status.value = '';
|
|
41
48
|
},
|
|
42
49
|
);
|
|
43
|
-
async function installFromCatalog(manifest: PluginManifest) {
|
|
44
|
-
if (busy.value || !store.workspace || !store.canManagePlugins) return;
|
|
50
|
+
async function installFromCatalog(manifest: PluginManifest, scope: 'workspace' | 'user' = 'workspace') {
|
|
51
|
+
if (busy.value || !store.workspace || (scope === 'workspace' && !store.canManagePlugins)) return;
|
|
45
52
|
const entry = catalog().find((item) => item.manifest.id === manifest.id);
|
|
46
53
|
if (!entry?.loadPackage) {
|
|
47
|
-
await change({ install: manifest, ...(entry?.package ? { package: entry.package } : {}) });
|
|
54
|
+
await change({ install: manifest, ...(entry?.package ? { package: entry.package } : {}), scope });
|
|
48
55
|
return;
|
|
49
56
|
}
|
|
50
57
|
const workspace = store.workspace.id;
|
|
@@ -55,7 +62,7 @@ export function usePluginActions(
|
|
|
55
62
|
const pkg = await entry.loadPackage();
|
|
56
63
|
if (store.workspace?.id !== workspace) return;
|
|
57
64
|
pending.value = '';
|
|
58
|
-
await change({ install: manifest, package: pkg });
|
|
65
|
+
await change({ install: manifest, package: pkg, scope });
|
|
59
66
|
} catch (cause) {
|
|
60
67
|
if (store.workspace?.id === workspace) error.value = String(cause);
|
|
61
68
|
} finally {
|
|
@@ -66,24 +73,36 @@ export function usePluginActions(
|
|
|
66
73
|
if (busy.value || !store.workspace) return;
|
|
67
74
|
const workspace = store.workspace.id;
|
|
68
75
|
pending.value =
|
|
69
|
-
'
|
|
76
|
+
'personalCodePlugins' in value
|
|
77
|
+
? '__workspace-policy__'
|
|
78
|
+
: 'install' in value
|
|
79
|
+
? value.install.id
|
|
80
|
+
: 'uninstall' in value
|
|
81
|
+
? value.uninstall
|
|
82
|
+
: value.id;
|
|
70
83
|
error.value = '';
|
|
71
84
|
status.value = '';
|
|
72
85
|
try {
|
|
73
86
|
await store.changePlugin(value, workspace);
|
|
74
87
|
if (store.workspace?.id === workspace) {
|
|
75
88
|
status.value =
|
|
76
|
-
'
|
|
77
|
-
? t('
|
|
78
|
-
: '
|
|
79
|
-
?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
'personalCodePlugins' in value
|
|
90
|
+
? t('已更新工作区个人代码插件策略')
|
|
91
|
+
: 'install' in value
|
|
92
|
+
? value.scope === 'user'
|
|
93
|
+
? t('{0} 已安装为全局插件', [value.install.name])
|
|
94
|
+
: t('{0} 已安装并启用', [value.install.name])
|
|
95
|
+
: 'uninstall' in value
|
|
96
|
+
? t('插件已卸载,对象和关系文件已保留')
|
|
97
|
+
: 'mode' in value
|
|
98
|
+
? t('工作区插件规则已保存')
|
|
99
|
+
: 'settings' in value
|
|
100
|
+
? t('全局插件设置已保存')
|
|
101
|
+
: 'forgetVersion' in value
|
|
102
|
+
? t('已移除历史版本引用')
|
|
103
|
+
: value.enabled
|
|
104
|
+
? t('插件已启用')
|
|
105
|
+
: t('插件已停用,对象和关系文件已保留');
|
|
87
106
|
}
|
|
88
107
|
} catch (cause) {
|
|
89
108
|
if (store.workspace?.id === workspace) error.value = String(cause);
|
|
@@ -91,26 +110,52 @@ export function usePluginActions(
|
|
|
91
110
|
pending.value = '';
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
|
-
async function authorize(allowed: boolean) {
|
|
113
|
+
async function authorize(allowed: boolean, options?: { allWorkspaces?: boolean }) {
|
|
95
114
|
if (!detail.value || !store.workspace) return;
|
|
96
115
|
try {
|
|
97
116
|
await store.authorizePlugin(
|
|
98
117
|
detail.value.id,
|
|
99
118
|
allowed ? selectedInstallation.value?.rule?.integrity : undefined,
|
|
100
119
|
store.workspace.id,
|
|
120
|
+
options,
|
|
101
121
|
);
|
|
102
122
|
} catch (cause) {
|
|
103
123
|
error.value = String(cause);
|
|
104
124
|
}
|
|
105
125
|
}
|
|
126
|
+
function parsedPathScopes(): string[] {
|
|
127
|
+
const lines = pathScopesText.value
|
|
128
|
+
.split(/[\r\n,]+/)
|
|
129
|
+
.map((item) => item.trim())
|
|
130
|
+
.filter(Boolean);
|
|
131
|
+
return parsePluginPathScopes(lines) ?? [];
|
|
132
|
+
}
|
|
106
133
|
async function savePolicy() {
|
|
107
134
|
if (!detail.value) return;
|
|
108
135
|
try {
|
|
136
|
+
const schema = detail.value.manifestVersion === 2 ? detail.value.settingsSchema : undefined;
|
|
137
|
+
const settings = validatePluginSettingsAgainstSchema(JSON.parse(settingsText.value), schema);
|
|
109
138
|
await change({
|
|
110
139
|
id: detail.value.id,
|
|
111
140
|
mode: policyMode.value,
|
|
112
|
-
settings
|
|
141
|
+
settings,
|
|
113
142
|
sourceUrl: sourceUrl.value,
|
|
143
|
+
...(detail.value.manifestVersion === 2 ? { pathScopes: parsedPathScopes() } : {}),
|
|
144
|
+
});
|
|
145
|
+
} catch (cause) {
|
|
146
|
+
error.value = String(cause);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function saveUserSettings() {
|
|
150
|
+
if (!detail.value) return;
|
|
151
|
+
try {
|
|
152
|
+
const schema = detail.value.manifestVersion === 2 ? detail.value.settingsSchema : undefined;
|
|
153
|
+
const settings = validatePluginSettingsAgainstSchema(JSON.parse(settingsText.value), schema);
|
|
154
|
+
await change({
|
|
155
|
+
id: detail.value.id,
|
|
156
|
+
settings,
|
|
157
|
+
...(detail.value.manifestVersion === 2 ? { pathScopes: parsedPathScopes() } : {}),
|
|
158
|
+
scope: 'user',
|
|
114
159
|
});
|
|
115
160
|
} catch (cause) {
|
|
116
161
|
error.value = String(cause);
|
|
@@ -125,10 +170,12 @@ export function usePluginActions(
|
|
|
125
170
|
policyMode,
|
|
126
171
|
settingsText,
|
|
127
172
|
sourceUrl,
|
|
173
|
+
pathScopesText,
|
|
128
174
|
selectedInstallation,
|
|
129
175
|
change,
|
|
130
176
|
authorize,
|
|
131
177
|
savePolicy,
|
|
178
|
+
saveUserSettings,
|
|
132
179
|
installFromCatalog,
|
|
133
180
|
};
|
|
134
181
|
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalPluginJson,
|
|
3
|
+
parsePluginManifest,
|
|
4
|
+
parsePluginPackage,
|
|
5
|
+
parsePluginPathScopes,
|
|
6
|
+
parsePluginSettings,
|
|
7
|
+
pluginRecord,
|
|
8
|
+
pluginText,
|
|
9
|
+
type PluginManifest,
|
|
10
|
+
type PluginPackage,
|
|
11
|
+
} from '@tano/protocol';
|
|
12
|
+
import type { PluginStorage } from './cache-storage';
|
|
13
|
+
import { PluginPackageCache, pluginApplicationStorage } from './packages';
|
|
14
|
+
|
|
15
|
+
export type PluginInstallScope = 'system' | 'workspace' | 'user';
|
|
16
|
+
|
|
17
|
+
/** Lightweight per-principal index stored in application storage; full package bytes live in PluginPackageCache. */
|
|
18
|
+
export interface UserPluginRecord {
|
|
19
|
+
id: string;
|
|
20
|
+
integrity: string;
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
settings: Record<string, unknown>;
|
|
23
|
+
/** Optional directory prefix allowlist restricting document/attachment access. */
|
|
24
|
+
pathScopes?: string[];
|
|
25
|
+
sourceUrl?: string;
|
|
26
|
+
/** Exact SHA-256 authorized by the user across owned/local workspaces. */
|
|
27
|
+
authorizedIntegrity?: string;
|
|
28
|
+
installedAt: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ResolvedUserPlugin {
|
|
32
|
+
record: UserPluginRecord;
|
|
33
|
+
pkg: PluginPackage;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const userPluginsKey = (principal: string) =>
|
|
37
|
+
`tano.user-plugins.v1.${encodeURIComponent(principal)}`;
|
|
38
|
+
|
|
39
|
+
function validateSourceUrl(value: unknown): string | undefined {
|
|
40
|
+
if (value === undefined) return undefined;
|
|
41
|
+
if (!pluginText(value, 2048)) throw new Error('插件下载地址无效');
|
|
42
|
+
const url = new URL(value);
|
|
43
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.hash)
|
|
44
|
+
throw new Error('插件下载地址必须为 HTTPS');
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function readUserPlugins(
|
|
49
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
50
|
+
principal = 'device',
|
|
51
|
+
): UserPluginRecord[] {
|
|
52
|
+
const raw = storage.getItem(userPluginsKey(principal));
|
|
53
|
+
if (!raw) return [];
|
|
54
|
+
const data = JSON.parse(raw);
|
|
55
|
+
if (!pluginRecord(data) || data.version !== 1 || !Array.isArray(data.plugins) || data.plugins.length > 100)
|
|
56
|
+
throw new Error('全局插件记录损坏,原记录已保留');
|
|
57
|
+
const ids = new Set<string>();
|
|
58
|
+
return data.plugins.map((item): UserPluginRecord => {
|
|
59
|
+
if (
|
|
60
|
+
!pluginRecord(item) ||
|
|
61
|
+
typeof item.id !== 'string' ||
|
|
62
|
+
!/^[a-z][a-z0-9-]{0,39}$/.test(item.id) ||
|
|
63
|
+
ids.has(item.id) ||
|
|
64
|
+
typeof item.integrity !== 'string' ||
|
|
65
|
+
!/^[a-f0-9]{64}$/.test(item.integrity) ||
|
|
66
|
+
typeof item.enabled !== 'boolean' ||
|
|
67
|
+
!pluginText(item.installedAt, 40) ||
|
|
68
|
+
!Number.isFinite(Date.parse(item.installedAt))
|
|
69
|
+
)
|
|
70
|
+
throw new Error('全局插件记录无效或重复');
|
|
71
|
+
if (
|
|
72
|
+
item.authorizedIntegrity !== undefined &&
|
|
73
|
+
(typeof item.authorizedIntegrity !== 'string' || !/^[a-f0-9]{64}$/.test(item.authorizedIntegrity))
|
|
74
|
+
)
|
|
75
|
+
throw new Error('全局插件授权摘要无效');
|
|
76
|
+
ids.add(item.id);
|
|
77
|
+
const sourceUrl = validateSourceUrl(item.sourceUrl);
|
|
78
|
+
const pathScopes = item.pathScopes === undefined ? undefined : parsePluginPathScopes(item.pathScopes);
|
|
79
|
+
return {
|
|
80
|
+
id: item.id,
|
|
81
|
+
integrity: item.integrity,
|
|
82
|
+
enabled: item.enabled,
|
|
83
|
+
settings: parsePluginSettings(item.settings ?? {}),
|
|
84
|
+
...(pathScopes?.length ? { pathScopes } : {}),
|
|
85
|
+
...(sourceUrl ? { sourceUrl } : {}),
|
|
86
|
+
...(item.authorizedIntegrity ? { authorizedIntegrity: item.authorizedIntegrity } : {}),
|
|
87
|
+
installedAt: item.installedAt,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function writeUserPlugins(
|
|
93
|
+
records: readonly UserPluginRecord[],
|
|
94
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
95
|
+
principal = 'device',
|
|
96
|
+
) {
|
|
97
|
+
if (records.length > 100) throw new Error('全局插件不能超过 100 个');
|
|
98
|
+
storage.setItem(userPluginsKey(principal), JSON.stringify({ version: 1, plugins: records }));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function userScopeUnsupportedReason(manifest: PluginManifest): string | undefined {
|
|
102
|
+
if (manifest.manifestVersion !== 2) return undefined;
|
|
103
|
+
if (
|
|
104
|
+
manifest.permissions.includes('connections') ||
|
|
105
|
+
manifest.permissions.includes('native') ||
|
|
106
|
+
(manifest.automations?.length ?? 0) > 0
|
|
107
|
+
)
|
|
108
|
+
return '包含服务连接、本机能力或后台自动化的插件目前仅支持安装到工作区';
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function installUserPlugin(
|
|
113
|
+
manifestInput: PluginManifest,
|
|
114
|
+
pkgInput: PluginPackage | undefined,
|
|
115
|
+
options: {
|
|
116
|
+
storage?: PluginStorage;
|
|
117
|
+
principal?: string;
|
|
118
|
+
sourceUrl?: string;
|
|
119
|
+
binaryAssets?: Record<string, Uint8Array>;
|
|
120
|
+
} = {},
|
|
121
|
+
): Promise<UserPluginRecord> {
|
|
122
|
+
const storage = options.storage ?? pluginApplicationStorage();
|
|
123
|
+
const principal = options.principal ?? 'device';
|
|
124
|
+
const manifest = parsePluginManifest(manifestInput);
|
|
125
|
+
const unsupported = userScopeUnsupportedReason(manifest);
|
|
126
|
+
if (unsupported) throw new Error(unsupported);
|
|
127
|
+
const pkg: PluginPackage =
|
|
128
|
+
manifest.manifestVersion === 2
|
|
129
|
+
? (() => {
|
|
130
|
+
if (!pkgInput || canonicalPluginJson(pkgInput.manifest) !== canonicalPluginJson(manifest))
|
|
131
|
+
throw new Error('请导入包含此版本脚本的插件包');
|
|
132
|
+
return parsePluginPackage(JSON.stringify(pkgInput));
|
|
133
|
+
})()
|
|
134
|
+
: parsePluginPackage(
|
|
135
|
+
JSON.stringify(
|
|
136
|
+
pkgInput && canonicalPluginJson(pkgInput.manifest) === canonicalPluginJson(manifest)
|
|
137
|
+
? pkgInput
|
|
138
|
+
: { packageVersion: 1, manifest },
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
const sourceUrl = validateSourceUrl(options.sourceUrl);
|
|
142
|
+
const cache = new PluginPackageCache(storage);
|
|
143
|
+
const integrity = await cache.put(pkg, options.binaryAssets);
|
|
144
|
+
const existing = readUserPlugins(storage, principal);
|
|
145
|
+
const prior = existing.find((row) => row.id === manifest.id);
|
|
146
|
+
const record: UserPluginRecord = {
|
|
147
|
+
id: manifest.id,
|
|
148
|
+
integrity,
|
|
149
|
+
enabled: prior?.enabled ?? true,
|
|
150
|
+
settings: prior?.settings ?? {},
|
|
151
|
+
...(sourceUrl ? { sourceUrl } : prior?.sourceUrl ? { sourceUrl: prior.sourceUrl } : {}),
|
|
152
|
+
...(prior?.authorizedIntegrity === integrity ? { authorizedIntegrity: integrity } : {}),
|
|
153
|
+
installedAt: new Date().toISOString(),
|
|
154
|
+
};
|
|
155
|
+
writeUserPlugins([...existing.filter((row) => row.id !== manifest.id), record], storage, principal);
|
|
156
|
+
return record;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function uninstallUserPlugin(
|
|
160
|
+
id: string,
|
|
161
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
162
|
+
principal = 'device',
|
|
163
|
+
) {
|
|
164
|
+
const existing = readUserPlugins(storage, principal);
|
|
165
|
+
writeUserPlugins(existing.filter((row) => row.id !== id), storage, principal);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function setUserPluginEnabled(
|
|
169
|
+
id: string,
|
|
170
|
+
enabled: boolean,
|
|
171
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
172
|
+
principal = 'device',
|
|
173
|
+
) {
|
|
174
|
+
const existing = readUserPlugins(storage, principal);
|
|
175
|
+
if (!existing.some((row) => row.id === id)) throw new Error('插件已被卸载,请刷新后重试');
|
|
176
|
+
writeUserPlugins(
|
|
177
|
+
existing.map((row) => (row.id === id ? { ...row, enabled } : row)),
|
|
178
|
+
storage,
|
|
179
|
+
principal,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function setUserPluginSettings(
|
|
184
|
+
id: string,
|
|
185
|
+
settings: Record<string, unknown>,
|
|
186
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
187
|
+
principal = 'device',
|
|
188
|
+
pathScopes?: string[],
|
|
189
|
+
) {
|
|
190
|
+
const parsed = parsePluginSettings(settings);
|
|
191
|
+
const parsedScopes = pathScopes === undefined ? undefined : parsePluginPathScopes(pathScopes);
|
|
192
|
+
const existing = readUserPlugins(storage, principal);
|
|
193
|
+
if (!existing.some((row) => row.id === id)) throw new Error('插件已被卸载,请刷新后重试');
|
|
194
|
+
writeUserPlugins(
|
|
195
|
+
existing.map((row) => {
|
|
196
|
+
if (row.id !== id) return row;
|
|
197
|
+
const next = { ...row, settings: parsed };
|
|
198
|
+
if (pathScopes !== undefined) {
|
|
199
|
+
if (parsedScopes?.length) next.pathScopes = parsedScopes;
|
|
200
|
+
else delete next.pathScopes;
|
|
201
|
+
}
|
|
202
|
+
return next;
|
|
203
|
+
}),
|
|
204
|
+
storage,
|
|
205
|
+
principal,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function setUserPluginGlobalAuthorization(
|
|
210
|
+
id: string,
|
|
211
|
+
integrity: string | undefined,
|
|
212
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
213
|
+
principal = 'device',
|
|
214
|
+
) {
|
|
215
|
+
const existing = readUserPlugins(storage, principal);
|
|
216
|
+
const target = existing.find((row) => row.id === id);
|
|
217
|
+
if (!target) throw new Error('全局插件不存在或已卸载');
|
|
218
|
+
if (integrity && target.integrity !== integrity)
|
|
219
|
+
throw new Error('插件版本已变化,请重新查看权限');
|
|
220
|
+
writeUserPlugins(
|
|
221
|
+
existing.map((row) => {
|
|
222
|
+
if (row.id !== id) return row;
|
|
223
|
+
const { authorizedIntegrity: _previous, ...rest } = row;
|
|
224
|
+
return integrity ? { ...rest, authorizedIntegrity: integrity } : rest;
|
|
225
|
+
}),
|
|
226
|
+
storage,
|
|
227
|
+
principal,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export async function resolveUserPlugins(
|
|
232
|
+
storage: PluginStorage = pluginApplicationStorage(),
|
|
233
|
+
principal = 'device',
|
|
234
|
+
): Promise<ResolvedUserPlugin[]> {
|
|
235
|
+
const records = readUserPlugins(storage, principal);
|
|
236
|
+
if (!records.length) return [];
|
|
237
|
+
const cache = new PluginPackageCache(storage);
|
|
238
|
+
const resolved: ResolvedUserPlugin[] = [];
|
|
239
|
+
for (const record of records) {
|
|
240
|
+
const pkg = await cache.get(record.integrity).catch(() => null);
|
|
241
|
+
if (!pkg || pkg.manifest.id !== record.id) continue;
|
|
242
|
+
resolved.push({ record, pkg });
|
|
243
|
+
}
|
|
244
|
+
return resolved;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function isAppearanceOnlyPlugin(manifest: PluginManifest): boolean {
|
|
248
|
+
return (
|
|
249
|
+
manifest.manifestVersion === 1 &&
|
|
250
|
+
!!manifest.appearance &&
|
|
251
|
+
manifest.objectTypes.length === 0 &&
|
|
252
|
+
manifest.relationTypes.length === 0
|
|
253
|
+
);
|
|
254
|
+
}
|