@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
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
isDataTableFilePath,
|
|
4
|
+
type AssistantProposal,
|
|
5
|
+
type AssistantSession,
|
|
6
|
+
type AssistantTransport,
|
|
7
|
+
} from '@tano/protocol';
|
|
8
|
+
import { uiLocale } from '../i18n/i18n';
|
|
9
|
+
import { canPluginToolExecute } from '../plugins/assistant-bridge';
|
|
10
|
+
import { resolveAssistantExtension, type useWorkbenchRuntime } from '../runtime';
|
|
11
|
+
import { useSuggestionStore } from '../stores/suggestions';
|
|
12
|
+
import type { useWorkspaceStore } from '../stores/workspace';
|
|
13
|
+
import type { AssistantExecutionResult } from './execution';
|
|
14
|
+
import { assistantCopy, formatAssistantText } from './language';
|
|
15
|
+
|
|
16
|
+
export interface AssistantScopeSnapshot {
|
|
17
|
+
id: string;
|
|
18
|
+
path: string;
|
|
19
|
+
epoch: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AssistantProposalActionDeps {
|
|
23
|
+
workspace: ReturnType<typeof useWorkspaceStore>;
|
|
24
|
+
runtime: ReturnType<typeof useWorkbenchRuntime>;
|
|
25
|
+
transport: AssistantTransport | undefined;
|
|
26
|
+
guard?: () => Promise<void>;
|
|
27
|
+
busy: Ref<boolean>;
|
|
28
|
+
applying: Ref<boolean>;
|
|
29
|
+
error: Ref<string>;
|
|
30
|
+
progress: Ref<string>;
|
|
31
|
+
session: Ref<AssistantSession | null>;
|
|
32
|
+
scope: () => AssistantScopeSnapshot;
|
|
33
|
+
persist: (target?: AssistantSession | null) => Promise<void>;
|
|
34
|
+
isManaged: (fileId: string) => boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createAssistantProposalActions(deps: AssistantProposalActionDeps) {
|
|
38
|
+
const { workspace, runtime, transport, guard, busy, applying, error, progress, session, scope, persist, isManaged } = deps;
|
|
39
|
+
|
|
40
|
+
async function executeChange(
|
|
41
|
+
proposal: AssistantProposal,
|
|
42
|
+
target: AssistantSession,
|
|
43
|
+
expected: AssistantScopeSnapshot,
|
|
44
|
+
signal: AbortSignal,
|
|
45
|
+
): Promise<AssistantExecutionResult> {
|
|
46
|
+
let submitted = false;
|
|
47
|
+
applying.value = true;
|
|
48
|
+
const assertCurrent = () => {
|
|
49
|
+
signal.throwIfAborted();
|
|
50
|
+
if (workspace.workspace?.id !== expected.id || workspace.workspace.path !== expected.path || workspace.assistantEpoch !== expected.epoch)
|
|
51
|
+
throw new Error('工作区已切换,停止执行');
|
|
52
|
+
if (proposal.fileId && isManaged(proposal.fileId)) throw new Error('此文档正由协作会话管理,暂时不能直接修改');
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
await guard?.();
|
|
56
|
+
assertCurrent();
|
|
57
|
+
if (target.messages.some(message => message.proposals?.some(item => item.id !== proposal.id &&
|
|
58
|
+
['unknown', 'applying'].includes(item.status) && (item.path === proposal.path || (!!proposal.fileId && item.fileId === proposal.fileId)))))
|
|
59
|
+
throw new Error('此目标有结果待核对的操作,请先核对,不自动重试');
|
|
60
|
+
progress.value = formatAssistantText(assistantCopy(uiLocale.value).progress.executing, [proposal.path]);
|
|
61
|
+
const preview = await workspace.reviewAssistantProposal(expected, proposal, undefined, true, signal);
|
|
62
|
+
if (preview.status === 'saved') {
|
|
63
|
+
proposal.applied = preview.applied; proposal.status = 'applied';
|
|
64
|
+
} else {
|
|
65
|
+
proposal.preview = preview.preview;
|
|
66
|
+
if (preview.status !== 'preview' || !preview.preview) {
|
|
67
|
+
proposal.status = preview.status === 'conflict' ? 'conflicted' : 'ready';
|
|
68
|
+
throw new Error('修改存在冲突或文档已变化,已暂停此项操作,请核对原文与建议');
|
|
69
|
+
}
|
|
70
|
+
proposal.status = 'applying';
|
|
71
|
+
await persist(target); // A crash must leave a durable intent, never an invisible write.
|
|
72
|
+
await guard?.();
|
|
73
|
+
assertCurrent();
|
|
74
|
+
submitted = true;
|
|
75
|
+
const result = await workspace.reviewAssistantProposal(expected, proposal, proposal.preview, true, signal);
|
|
76
|
+
if (result.status === 'saved') {
|
|
77
|
+
proposal.applied = result.applied; proposal.status = 'applied'; proposal.error = undefined;
|
|
78
|
+
} else {
|
|
79
|
+
proposal.preview = result.preview;
|
|
80
|
+
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
81
|
+
proposal.error = '执行前文档发生变化,已暂停此项操作,请核对后处理';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
await persist(target);
|
|
85
|
+
} catch (reason) {
|
|
86
|
+
if (proposal.applied) {
|
|
87
|
+
proposal.status = 'applied';
|
|
88
|
+
proposal.error = `修改已完成,记录或刷新失败:${String(reason)}`;
|
|
89
|
+
} else {
|
|
90
|
+
if (proposal.status === 'applying') proposal.status = submitted ? 'unknown' : 'ready';
|
|
91
|
+
proposal.error = String(reason);
|
|
92
|
+
}
|
|
93
|
+
try { await persist(target); } catch { /* Preserve the in-memory outcome; never retry the write. */ }
|
|
94
|
+
} finally { applying.value = false; }
|
|
95
|
+
const written = proposal.status === 'applied' ? true : proposal.status === 'unknown' ? null : false;
|
|
96
|
+
const result: AssistantExecutionResult = { status: proposal.status, written, ...(proposal.error ? { error: proposal.error } : {}) };
|
|
97
|
+
if (written && proposal.applied) {
|
|
98
|
+
result.fileId = proposal.applied.fileId;
|
|
99
|
+
result.path = proposal.preview?.destination ?? proposal.preview?.path ?? proposal.path;
|
|
100
|
+
// Return committed bytes as a new immutable source; never widen an original selection.
|
|
101
|
+
if (['edit', 'create', 'rename', 'move'].includes(proposal.kind) && !target.messages.some(message => message.id === proposal.runId &&
|
|
102
|
+
message.sources?.some(source => source.fileId === proposal.fileId && source.selection))) {
|
|
103
|
+
result.source = {
|
|
104
|
+
id: '', workspaceId: expected.id, fileId: result.fileId, path: result.path,
|
|
105
|
+
content: proposal.applied.after, hash: proposal.applied.hash, origin: 'disk',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function review(proposal: AssistantProposal, apply = false) {
|
|
113
|
+
if (busy.value || applying.value || !transport) return;
|
|
114
|
+
if (proposal.suggestionGroupId) { error.value = '此提案已转为文档建议,请在文档中逐项审阅'; return; }
|
|
115
|
+
const expected = scope();
|
|
116
|
+
if (proposal.status === 'applied' || proposal.status === 'rejected') return;
|
|
117
|
+
if (proposal.status === 'unknown' || proposal.status === 'applying') { error.value = '请先核对待确认的写入结果'; return; }
|
|
118
|
+
if (proposal.fileId && isManaged(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂时只能进行问答'; return; }
|
|
119
|
+
applying.value = true; error.value = '';
|
|
120
|
+
const target = session.value;
|
|
121
|
+
const originalStatus = proposal.status;
|
|
122
|
+
let submitting = false;
|
|
123
|
+
try {
|
|
124
|
+
if (proposal.kind === 'extension') {
|
|
125
|
+
const extAction = proposal.extensionAction;
|
|
126
|
+
if (!extAction) throw new Error('扩展操作元数据缺失');
|
|
127
|
+
if (!apply) {
|
|
128
|
+
proposal.preview = { before: '', after: proposal.content, diskHash: null, path: proposal.path };
|
|
129
|
+
proposal.status = 'ready';
|
|
130
|
+
await persist(target);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const assistantExtension = resolveAssistantExtension(runtime);
|
|
134
|
+
if (!assistantExtension?.applyProposal) throw new Error('当前宿主未注册该扩展操作处理器');
|
|
135
|
+
proposal.status = 'applying';
|
|
136
|
+
await persist(target);
|
|
137
|
+
submitting = true;
|
|
138
|
+
const extApplied = await assistantExtension.applyProposal(proposal, extAction.payload);
|
|
139
|
+
if (!extApplied) throw new Error('当前宿主不支持执行此扩展操作');
|
|
140
|
+
proposal.applied = {
|
|
141
|
+
before: extApplied.before ?? '',
|
|
142
|
+
after: extApplied.after,
|
|
143
|
+
hash: extApplied.hash,
|
|
144
|
+
fileId: extApplied.fileId,
|
|
145
|
+
...(extApplied.undoSnapshot !== undefined ? { undoSnapshot: extApplied.undoSnapshot } : {}),
|
|
146
|
+
};
|
|
147
|
+
proposal.status = 'applied';
|
|
148
|
+
proposal.error = undefined;
|
|
149
|
+
await persist(target);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (proposal.kind === 'plugin') {
|
|
153
|
+
const action = proposal.pluginAction;
|
|
154
|
+
if (!action) throw new Error('插件操作元数据缺失');
|
|
155
|
+
if (!apply) {
|
|
156
|
+
proposal.preview = { before: '', after: proposal.content, diskHash: null, path: proposal.path };
|
|
157
|
+
proposal.status = 'ready';
|
|
158
|
+
await persist(target);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const parsedArgs = JSON.parse(proposal.content) as Record<string, unknown>;
|
|
162
|
+
const assistantExtension = resolveAssistantExtension(runtime);
|
|
163
|
+
if (assistantExtension?.applyProposal) {
|
|
164
|
+
proposal.status = 'applying';
|
|
165
|
+
await persist(target);
|
|
166
|
+
submitting = true;
|
|
167
|
+
const extApplied = await assistantExtension.applyProposal(proposal, parsedArgs);
|
|
168
|
+
if (extApplied) {
|
|
169
|
+
proposal.applied = {
|
|
170
|
+
before: extApplied.before ?? '',
|
|
171
|
+
after: extApplied.after,
|
|
172
|
+
hash: extApplied.hash,
|
|
173
|
+
fileId: extApplied.fileId,
|
|
174
|
+
...(extApplied.undoSnapshot !== undefined ? { undoSnapshot: extApplied.undoSnapshot } : {}),
|
|
175
|
+
};
|
|
176
|
+
proposal.status = 'applied';
|
|
177
|
+
proposal.error = undefined;
|
|
178
|
+
await persist(target);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
submitting = false;
|
|
182
|
+
}
|
|
183
|
+
const installation = workspace.installedPlugins.find(item => item.manifest.id === action.pluginId);
|
|
184
|
+
const toolDef =
|
|
185
|
+
installation?.manifest.manifestVersion === 2
|
|
186
|
+
? installation.manifest.assistantTools?.find(tool => tool.name === action.toolName)
|
|
187
|
+
: undefined;
|
|
188
|
+
if (!installation || !toolDef || !canPluginToolExecute(installation, toolDef, !!workspace.workspace?.readOnly))
|
|
189
|
+
throw new Error('插件已停用、未授权或受当前工作区策略限制,无法执行此操作');
|
|
190
|
+
proposal.status = 'applying';
|
|
191
|
+
await persist(target);
|
|
192
|
+
submitting = true;
|
|
193
|
+
const output = await workspace.invokePluginAssistantTool(action.pluginId, action.toolName, parsedArgs);
|
|
194
|
+
proposal.applied = {
|
|
195
|
+
before: '',
|
|
196
|
+
after: JSON.stringify(output ?? null, null, 2),
|
|
197
|
+
hash: action.toolName,
|
|
198
|
+
fileId: action.pluginId,
|
|
199
|
+
};
|
|
200
|
+
proposal.status = 'applied';
|
|
201
|
+
proposal.error = undefined;
|
|
202
|
+
await persist(target);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const acceptance = apply ? proposal.preview : undefined;
|
|
206
|
+
if (apply && !acceptance) throw new Error('请先查看最新差异');
|
|
207
|
+
if (apply) {
|
|
208
|
+
proposal.status = 'applying';
|
|
209
|
+
await persist(target);
|
|
210
|
+
submitting = true;
|
|
211
|
+
}
|
|
212
|
+
const result = await workspace.reviewAssistantProposal(expected, proposal, acceptance, false, undefined, !!target?.external);
|
|
213
|
+
if (result.status === 'saved') {
|
|
214
|
+
proposal.status = 'applied'; proposal.applied = result.applied; proposal.error = undefined;
|
|
215
|
+
} else {
|
|
216
|
+
proposal.preview = result.preview;
|
|
217
|
+
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
218
|
+
proposal.error = result.status === 'stale' ? (result.preview ? '文档已变化,请审阅更新后的差异再应用' : '文档在保存时变化,请重新查看差异')
|
|
219
|
+
: result.status === 'conflict' ? '修改存在重叠,原文与建议均已保留' : undefined;
|
|
220
|
+
}
|
|
221
|
+
await persist(target);
|
|
222
|
+
if (target?.external && proposal.id === target.id) await transport.recordExternalResult?.(target);
|
|
223
|
+
} catch (reason) {
|
|
224
|
+
if (proposal.applied) {
|
|
225
|
+
proposal.status = 'applied';
|
|
226
|
+
proposal.error = `内容已保存,会话记录保存失败:${String(reason)}`;
|
|
227
|
+
} else {
|
|
228
|
+
proposal.status = submitting ? 'unknown' : originalStatus;
|
|
229
|
+
proposal.error = String(reason);
|
|
230
|
+
}
|
|
231
|
+
error.value = proposal.error;
|
|
232
|
+
try { await persist(target); } catch { /* Keep the in-memory result visible. */ }
|
|
233
|
+
} finally { applying.value = false; }
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function publishSuggestions(proposal: AssistantProposal) {
|
|
237
|
+
if (busy.value || applying.value || proposal.kind !== 'edit' || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
238
|
+
if (isDataTableFilePath(proposal.path)) { error.value = '数据表修改请在助手中查看差异并应用'; return; }
|
|
239
|
+
if (proposal.fileId && isManaged(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂不支持建议模式'; return; }
|
|
240
|
+
applying.value = true;
|
|
241
|
+
const target = session.value;
|
|
242
|
+
try {
|
|
243
|
+
await useSuggestionStore().publish(proposal);
|
|
244
|
+
proposal.suggestionGroupId = proposal.id;
|
|
245
|
+
await persist(target);
|
|
246
|
+
error.value = '';
|
|
247
|
+
} catch (reason) { error.value = String(reason); }
|
|
248
|
+
finally { applying.value = false; }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function verify(proposal: AssistantProposal) {
|
|
252
|
+
if (applying.value || busy.value || !proposal.preview) return;
|
|
253
|
+
applying.value = true; error.value = '';
|
|
254
|
+
const target = session.value;
|
|
255
|
+
try {
|
|
256
|
+
const expected = scope();
|
|
257
|
+
if (expected.id !== proposal.workspaceId) throw new Error('工作区已切换');
|
|
258
|
+
const current = await runtime.adapter.refresh();
|
|
259
|
+
if (current.id !== expected.id || current.path !== expected.path) throw new Error('工作区已切换');
|
|
260
|
+
if (['delete', 'rename', 'move'].includes(proposal.kind)) {
|
|
261
|
+
const file = current.files.find(file => file.id === proposal.fileId);
|
|
262
|
+
if (!file) throw new Error('原文件已不存在,无法确认是否由此次操作移除;请核对回收站,保留此记录');
|
|
263
|
+
const disk = await runtime.adapter.read(file.path);
|
|
264
|
+
if (proposal.kind !== 'delete' && file.path === proposal.preview.destination && disk.hash === proposal.preview.diskHash) {
|
|
265
|
+
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
266
|
+
proposal.status = 'applied'; proposal.error = undefined;
|
|
267
|
+
} else if (file.path === proposal.preview.path && disk.hash === proposal.preview.diskHash) {
|
|
268
|
+
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次文件操作,请重新审阅';
|
|
269
|
+
} else throw new Error('文件位置或内容已变化,请人工核对;不自动重试');
|
|
270
|
+
await persist(target);
|
|
271
|
+
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const file = current.files.find(file => proposal.kind === 'edit' ? file.id === proposal.fileId : file.path === proposal.path);
|
|
275
|
+
if (!file || current.id !== expected.id || current.path !== expected.path) throw new Error('原目标不存在,请保留建议并核对工作区');
|
|
276
|
+
const disk = await runtime.adapter.read(file.path);
|
|
277
|
+
if (disk.content === proposal.preview.after) {
|
|
278
|
+
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
279
|
+
proposal.status = 'applied'; proposal.error = undefined;
|
|
280
|
+
} else if (proposal.kind === 'edit' && disk.hash === proposal.preview.diskHash) {
|
|
281
|
+
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次写入,请重新审阅';
|
|
282
|
+
} else throw new Error('磁盘内容与写入前后均不同,请打开文档人工核对;不自动重试');
|
|
283
|
+
await persist(target);
|
|
284
|
+
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
285
|
+
} catch (reason) { error.value = String(reason); }
|
|
286
|
+
finally { applying.value = false; }
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function reject(proposal: AssistantProposal) {
|
|
290
|
+
if (applying.value || busy.value || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
291
|
+
proposal.status = 'rejected';
|
|
292
|
+
const target = session.value;
|
|
293
|
+
try { await persist(target); if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target); }
|
|
294
|
+
catch (reason) { error.value = String(reason); }
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function undo(proposal: AssistantProposal) {
|
|
298
|
+
if (!proposal.applied || applying.value || busy.value) return;
|
|
299
|
+
if (proposal.kind === 'extension' || proposal.kind === 'plugin') {
|
|
300
|
+
const undoExt = resolveAssistantExtension(runtime)?.undoProposal;
|
|
301
|
+
if (!undoExt) return;
|
|
302
|
+
applying.value = true;
|
|
303
|
+
error.value = '';
|
|
304
|
+
try {
|
|
305
|
+
await undoExt(proposal);
|
|
306
|
+
} catch (reason) {
|
|
307
|
+
error.value = String(reason);
|
|
308
|
+
} finally {
|
|
309
|
+
applying.value = false;
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (!['edit', 'create'].includes(proposal.kind)) return;
|
|
314
|
+
if (proposal.kind === 'create' && isDataTableFilePath(proposal.path)) return;
|
|
315
|
+
const reply = session.value?.messages.find(message => message.id === proposal.runId);
|
|
316
|
+
if (!reply) return;
|
|
317
|
+
const reversed: AssistantProposal = {
|
|
318
|
+
id: crypto.randomUUID(), runId: reply.id, workspaceId: proposal.workspaceId,
|
|
319
|
+
kind: 'edit', fileId: proposal.applied.fileId, path: proposal.path, base: proposal.applied.after,
|
|
320
|
+
content: proposal.applied.before, reason: `撤回内容:${proposal.reason}`, status: 'ready',
|
|
321
|
+
};
|
|
322
|
+
reply.proposals!.push(reversed);
|
|
323
|
+
const current = reply.proposals!.at(-1)!;
|
|
324
|
+
current.execution = 'direct';
|
|
325
|
+
await executeChange(current, session.value!, scope(), new AbortController().signal);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
executeChange,
|
|
330
|
+
review,
|
|
331
|
+
publishSuggestions,
|
|
332
|
+
verify,
|
|
333
|
+
reject,
|
|
334
|
+
undo,
|
|
335
|
+
};
|
|
336
|
+
}
|
package/src/assistant/results.ts
CHANGED
|
@@ -1,92 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
assistantAnswerText,
|
|
3
|
+
assistantDisplayParts,
|
|
4
|
+
assistantHistory,
|
|
5
|
+
assistantMessageParts,
|
|
6
|
+
type AssistantDisplayPart,
|
|
7
|
+
} from '@tano/protocol/assistant-history';
|
|
8
|
+
import { t, uiLocale } from '../i18n/i18n';
|
|
9
|
+
import { resolveAssistantExtension, useWorkbenchRuntime } from '../runtime';
|
|
3
10
|
import { assistantCopy } from './language';
|
|
4
11
|
|
|
5
|
-
export function assistantMessageParts(message: AssistantMessage) {
|
|
6
|
-
const parts: ({ kind: 'text'; content: string } | { kind: 'input'; input: AssistantUserInput })[] = [];
|
|
7
|
-
let offset = 0;
|
|
8
|
-
for (const input of message.userInputs ?? []) {
|
|
9
|
-
if (input.contentOffset > offset) parts.push({ kind: 'text', content: message.content.slice(offset, input.contentOffset) });
|
|
10
|
-
parts.push({ kind: 'input', input });
|
|
11
|
-
offset = input.contentOffset;
|
|
12
|
-
}
|
|
13
|
-
if (offset < message.content.length) parts.push({ kind: 'text', content: message.content.slice(offset) });
|
|
14
|
-
return parts;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type AssistantDisplayPart =
|
|
18
|
-
| { kind: 'text'; content: string; key: string }
|
|
19
|
-
| { kind: 'input'; input: AssistantUserInput; key: string }
|
|
20
|
-
| { kind: 'tool'; tool: Extract<AssistantActivity, { kind: 'tool' }>; result?: AssistantToolResult; key: string };
|
|
21
|
-
|
|
22
|
-
export function assistantDisplayParts(message: AssistantMessage) {
|
|
23
|
-
const process: AssistantDisplayPart[] = [], answer: AssistantDisplayPart[] = [];
|
|
24
|
-
const unfinished = !!message.state && ['failed', 'cancelled', 'interrupted'].includes(message.state);
|
|
25
|
-
if (!message.activity) {
|
|
26
|
-
(unfinished ? process : answer).push(...assistantMessageParts(message).map((part, index) => ({ ...part, key: `legacy-${index}` })));
|
|
27
|
-
return { process, answer };
|
|
28
|
-
}
|
|
29
|
-
for (const [index, item] of message.activity.entries()) {
|
|
30
|
-
const key = `activity-${index}`;
|
|
31
|
-
if (item.kind === 'text') {
|
|
32
|
-
const content = message.content.slice(item.start, item.end);
|
|
33
|
-
const live = message.state === 'running' || message.state === 'waiting';
|
|
34
|
-
if (content.trim()) (unfinished || item.phase === 'working' || (item.phase === 'pending' && !live) ? process : answer).push({ kind: 'text', content, key });
|
|
35
|
-
} else if (item.kind === 'tool') {
|
|
36
|
-
process.push({ kind: 'tool', tool: item, key, result: message.toolResults?.[item.resultIndex!] });
|
|
37
|
-
} else {
|
|
38
|
-
const input = message.userInputs?.find(input => input.id === item.inputId);
|
|
39
|
-
if (input) process.push({ kind: 'input', input, key });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return { process, answer };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Copy/export only the final (or currently streaming) answer, never the work log. */
|
|
46
|
-
export function assistantAnswerText(message: AssistantMessage): string {
|
|
47
|
-
if (message.state && !['running', 'waiting', 'completed'].includes(message.state)) return '';
|
|
48
|
-
if (!message.activity) return message.content;
|
|
49
|
-
return message.activity.filter(item => item.kind === 'text' && item.phase === 'answer')
|
|
50
|
-
.map(item => item.kind === 'text' ? message.content.slice(item.start, item.end) : '').join('\n\n');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Keep the model's prose separate from the application's current review state. */
|
|
54
|
-
export function assistantHistory(messages: readonly AssistantMessage[]): AssistantWireMessage[] {
|
|
55
|
-
return messages.slice(-16).flatMap<AssistantWireMessage>(message => {
|
|
56
|
-
if (message.role === 'user') return [{ role: 'user', content: message.attachments?.length
|
|
57
|
-
? `${message.content}\nPrevious clipboard attachment names (contents no longer supplied): ${JSON.stringify(message.attachments)}`
|
|
58
|
-
: message.content }];
|
|
59
|
-
const history: AssistantWireMessage[] = [];
|
|
60
|
-
for (const part of assistantMessageParts(message)) {
|
|
61
|
-
if (part.kind === 'text') history.push({ role: 'assistant', content: part.content });
|
|
62
|
-
else if (part.input.status === 'answered') history.push({ role: 'user', content: JSON.stringify({
|
|
63
|
-
questions: part.input.questions, answers: part.input.answers,
|
|
64
|
-
}) });
|
|
65
|
-
}
|
|
66
|
-
// Include actual operation receipts even when a message only asked questions.
|
|
67
|
-
const last = history.at(-1);
|
|
68
|
-
const answer = last?.role === 'assistant' ? history.pop()!.content : '';
|
|
69
|
-
history.push({ role: 'assistant', content: JSON.stringify({ answer, execution: {
|
|
70
|
-
state: message.state ?? 'unknown',
|
|
71
|
-
...(message.termination ? { termination: message.termination.reason } : {}),
|
|
72
|
-
...(message.error ? { error: message.error.slice(0, 2000) } : {}),
|
|
73
|
-
// Null distinguishes old conversations without receipts from a verified empty list.
|
|
74
|
-
tools: message.toolResults ?? null,
|
|
75
|
-
proposals: (message.proposals ?? []).map(proposal => ({
|
|
76
|
-
id: proposal.id, kind: proposal.kind, path: proposal.path, status: proposal.status,
|
|
77
|
-
...(proposal.execution ? { execution: proposal.execution } : {}),
|
|
78
|
-
...(proposal.destination ? { destination: proposal.destination } : {}),
|
|
79
|
-
review: proposal.suggestionGroupId ? 'document' : 'conversation',
|
|
80
|
-
written: proposal.suggestionGroupId || ['applying', 'unknown'].includes(proposal.status)
|
|
81
|
-
? null : proposal.status === 'applied',
|
|
82
|
-
})),
|
|
83
|
-
} }) });
|
|
84
|
-
return history;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
12
|
export function assistantToolLabel(name: string) {
|
|
89
13
|
const copy = assistantCopy(uiLocale.value);
|
|
90
14
|
const toolLabels: Record<string, string> = copy.tools;
|
|
91
|
-
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(toolLabels, name)) return toolLabels[name];
|
|
16
|
+
if (name === 'inspect_plugins') return t('查看已启用插件');
|
|
17
|
+
if (name === 'inspect_plugin_logs') return t('查看插件运行日志');
|
|
18
|
+
if (name === 'open_plugin_view') return t('打开插件视图');
|
|
19
|
+
try {
|
|
20
|
+
const customLabel = resolveAssistantExtension(useWorkbenchRuntime())?.toolLabel?.(name);
|
|
21
|
+
if (customLabel) return customLabel;
|
|
22
|
+
} catch {
|
|
23
|
+
/* outside Pinia runtime */
|
|
24
|
+
}
|
|
25
|
+
return name;
|
|
92
26
|
}
|