@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
package/src/assistant/store.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { computed, onScopeDispose, ref, shallowRef, watch } from 'vue';
|
|
2
2
|
import { defineStore } from 'pinia';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isAssistantModelId,
|
|
5
|
+
parseAssistantSession,
|
|
6
|
+
parseAssistantAnswers,
|
|
7
|
+
} from '@tano/protocol';
|
|
4
8
|
import type { AssistantQuestion, AssistantQuestionAnswer, AssistantUserInput } from '@tano/protocol';
|
|
5
9
|
import type { AssistantActivity, AssistantConnection, AssistantQuotaResult, AssistantMessage, AssistantProposal, AssistantReasoningSelection, AssistantSession, AssistantSource } from '@tano/protocol';
|
|
6
|
-
import type { AssistantExecutionResult } from './execution';
|
|
7
10
|
import { useWorkspaceStore } from '../stores/workspace';
|
|
8
11
|
import { recordHelpCompleted } from '../help/help-checklist';
|
|
9
12
|
import { useWorkbenchRuntime } from '../runtime';
|
|
@@ -11,13 +14,19 @@ import { demoAssistantTransport, nativeAssistantTransport } from './transport';
|
|
|
11
14
|
import { runAssistant, AssistantWaitingError } from './engine';
|
|
12
15
|
import { AssistantRunError } from './completion';
|
|
13
16
|
import type { AssistantTextPhase } from './completion';
|
|
14
|
-
import { assistantHistory } from './results';
|
|
15
|
-
import { useSuggestionStore } from '../stores/suggestions';
|
|
17
|
+
import { assistantHistory, assistantToolLabel } from './results';
|
|
16
18
|
import { t, uiLocale } from '../i18n/i18n';
|
|
17
19
|
import { isFeatureEnabled } from '../features';
|
|
18
20
|
import { assistantCopy, assistantTaskPrompts, formatAssistantText } from './language';
|
|
19
21
|
import { assistantAttachmentBytes, describeAssistantAttachment, maxAssistantAttachments, readAssistantAttachments } from './attachments';
|
|
20
22
|
import type { AssistantDraftAttachment } from './attachments';
|
|
23
|
+
import {
|
|
24
|
+
extractPluginContextMentions,
|
|
25
|
+
runPluginAiCompletion,
|
|
26
|
+
} from '../plugins/assistant-bridge';
|
|
27
|
+
import { createAssistantConnectionActions } from './connection-actions';
|
|
28
|
+
import { buildAssistantPluginBridge } from './plugin-bridge-builder';
|
|
29
|
+
import { createAssistantProposalActions } from './proposal-actions';
|
|
21
30
|
|
|
22
31
|
export type AssistantConnectionCheck = { fingerprint: string; elapsedMs?: number; checkedAt?: number; message: string; failed: boolean };
|
|
23
32
|
|
|
@@ -84,6 +93,13 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
84
93
|
const externalSessions = ref<AssistantSession[]>([]);
|
|
85
94
|
const session = ref<AssistantSession | null>(null);
|
|
86
95
|
const files = ref<string[]>([]);
|
|
96
|
+
const pluginContextKeys = ref<string[]>([]);
|
|
97
|
+
function togglePluginContext(key: string) {
|
|
98
|
+
if (busy.value || loading.value || applying.value) return;
|
|
99
|
+
pluginContextKeys.value = pluginContextKeys.value.includes(key)
|
|
100
|
+
? pluginContextKeys.value.filter(item => item !== key)
|
|
101
|
+
: [...pluginContextKeys.value, key].slice(0, 4);
|
|
102
|
+
}
|
|
87
103
|
const attachmentsEnabled = !inline && !background && available && isFeatureEnabled('assistantClipboardAttachments');
|
|
88
104
|
const attachments = shallowRef<AssistantDraftAttachment[]>([]);
|
|
89
105
|
const selection = ref<{ fileId: string; text: string; from?: number; to?: number } | null>(null);
|
|
@@ -129,7 +145,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
129
145
|
const replyTarget = shallowRef<{ label: string; draft: (body: string) => Promise<void> } | null>(null);
|
|
130
146
|
const connection = computed(() => connections.value.find(item => item.id === connectionId.value));
|
|
131
147
|
let controller: AbortController | undefined;
|
|
132
|
-
let modelController: AbortController | undefined;
|
|
133
148
|
let generation = 0;
|
|
134
149
|
let persistTask = Promise.resolve();
|
|
135
150
|
let managed: (fileId: string) => boolean = () => false;
|
|
@@ -137,18 +152,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
137
152
|
if (!workspace.workspace) throw new Error('请先打开工作区');
|
|
138
153
|
return { id: workspace.workspace.id, path: workspace.workspace.path, epoch: workspace.assistantEpoch };
|
|
139
154
|
};
|
|
140
|
-
function stop() { controller?.abort(); }
|
|
141
|
-
async function settle() {
|
|
142
|
-
stop(); modelController?.abort();
|
|
143
|
-
if (busy.value || applying.value) {
|
|
144
|
-
await new Promise<void>(resolve => {
|
|
145
|
-
const unwatch = watch([busy, applying], ([running, writing]) => {
|
|
146
|
-
if (!running && !writing) { unwatch(); resolve(); }
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
await persistTask.catch(() => {});
|
|
151
|
-
}
|
|
152
155
|
function newSession() {
|
|
153
156
|
if (busy.value || applying.value) return;
|
|
154
157
|
const now = Date.now();
|
|
@@ -157,7 +160,7 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
157
160
|
...(connectionId.value ? { connectionId: connectionId.value } : {}),
|
|
158
161
|
...(modelId.value ? { model: modelId.value } : {}),
|
|
159
162
|
...(connection.value?.kind === 'codex-cli' ? { reasoningEffort: reasoningEffort.value } : {}) };
|
|
160
|
-
prompt.value = ''; attachments.value = []; error.value = '';
|
|
163
|
+
prompt.value = ''; attachments.value = []; pluginContextKeys.value = []; error.value = '';
|
|
161
164
|
replyTarget.value = null;
|
|
162
165
|
}
|
|
163
166
|
async function persist(target = session.value) {
|
|
@@ -176,132 +179,80 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
176
179
|
persistTask = saved;
|
|
177
180
|
await saved;
|
|
178
181
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (connection.value?.kind === 'codex-cli') session.value.reasoningEffort = reasoningEffort.value;
|
|
252
|
-
else delete session.value.reasoningEffort;
|
|
253
|
-
await persist();
|
|
182
|
+
const connectionActions = createAssistantConnectionActions({
|
|
183
|
+
transport,
|
|
184
|
+
canConfigure,
|
|
185
|
+
opened,
|
|
186
|
+
loading,
|
|
187
|
+
busy,
|
|
188
|
+
applying,
|
|
189
|
+
connections,
|
|
190
|
+
connectionId,
|
|
191
|
+
connection,
|
|
192
|
+
modelId,
|
|
193
|
+
reasoningEffort,
|
|
194
|
+
models,
|
|
195
|
+
modelsLoading,
|
|
196
|
+
modelsError,
|
|
197
|
+
session,
|
|
198
|
+
workspace,
|
|
199
|
+
getGeneration: () => generation,
|
|
200
|
+
newSession,
|
|
201
|
+
persist,
|
|
202
|
+
});
|
|
203
|
+
const {
|
|
204
|
+
abortModels,
|
|
205
|
+
canImportCcSwitch,
|
|
206
|
+
reloadConnections,
|
|
207
|
+
reloadModels,
|
|
208
|
+
refreshModels,
|
|
209
|
+
readConnectionKey,
|
|
210
|
+
queryQuota,
|
|
211
|
+
saveQuota,
|
|
212
|
+
checkConnection,
|
|
213
|
+
selectConnection,
|
|
214
|
+
selectModel,
|
|
215
|
+
restoreModelSelection,
|
|
216
|
+
selectReasoningEffort,
|
|
217
|
+
saveConnection,
|
|
218
|
+
scanCcSwitch,
|
|
219
|
+
importCcSwitch,
|
|
220
|
+
removeConnection,
|
|
221
|
+
} = connectionActions;
|
|
222
|
+
|
|
223
|
+
const {
|
|
224
|
+
executeChange,
|
|
225
|
+
review,
|
|
226
|
+
publishSuggestions,
|
|
227
|
+
verify,
|
|
228
|
+
reject,
|
|
229
|
+
undo,
|
|
230
|
+
} = createAssistantProposalActions({
|
|
231
|
+
workspace,
|
|
232
|
+
runtime,
|
|
233
|
+
transport,
|
|
234
|
+
guard: background?.guard,
|
|
235
|
+
busy,
|
|
236
|
+
applying,
|
|
237
|
+
error,
|
|
238
|
+
progress,
|
|
239
|
+
session,
|
|
240
|
+
scope,
|
|
241
|
+
persist,
|
|
242
|
+
isManaged: (fileId: string) => managed(fileId),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
function stop() { controller?.abort(); }
|
|
246
|
+
async function settle() {
|
|
247
|
+
stop(); abortModels();
|
|
248
|
+
if (busy.value || applying.value) {
|
|
249
|
+
await new Promise<void>(resolve => {
|
|
250
|
+
const unwatch = watch([busy, applying], ([running, writing]) => {
|
|
251
|
+
if (!running && !writing) { unwatch(); resolve(); }
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
async function selectModel(id: string) {
|
|
257
|
-
if (busy.value || applying.value || loading.value) return;
|
|
258
|
-
const selected = id.trim();
|
|
259
|
-
if (!connection.value) throw new Error('请先选择模型连接');
|
|
260
|
-
if (!isAssistantModelId(selected)) throw new Error('模型 ID 无效');
|
|
261
|
-
if (!session.value) newSession();
|
|
262
|
-
modelId.value = selected; session.value!.model = selected; session.value!.connectionId = connectionId.value;
|
|
263
|
-
await persist();
|
|
264
|
-
}
|
|
265
|
-
function restoreModelSelection(target: AssistantSession | null) {
|
|
266
|
-
connectionId.value = target?.connectionId ?? (connections.value.length === 1 ? connections.value[0].id : '');
|
|
267
|
-
const previous = target ? [...target.messages].reverse().find(message => message.role === 'assistant' && message.model)?.model : undefined;
|
|
268
|
-
modelId.value = target?.model ?? (isAssistantModelId(previous) ? previous : '');
|
|
269
|
-
reasoningEffort.value = target?.reasoningEffort ?? connection.value?.reasoningEffort ?? (target ? 'cli-default' : 'medium');
|
|
270
|
-
}
|
|
271
|
-
async function selectReasoningEffort(value: AssistantReasoningSelection) {
|
|
272
|
-
if (busy.value || applying.value || loading.value) return;
|
|
273
|
-
if (connection.value?.kind !== 'codex-cli') throw new Error('当前连接不支持选择推理强度');
|
|
274
|
-
if (!isAssistantReasoningSelection(value)) throw new Error('推理强度无效');
|
|
275
|
-
if (!session.value) newSession();
|
|
276
|
-
reasoningEffort.value = value;
|
|
277
|
-
session.value!.reasoningEffort = value;
|
|
278
|
-
session.value!.connectionId = connectionId.value;
|
|
279
|
-
await persist();
|
|
280
|
-
}
|
|
281
|
-
async function saveConnection(config: Omit<AssistantConnection, 'hasKey'>, key?: string) {
|
|
282
|
-
if (!transport || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
283
|
-
const previous = connections.value.find(item => item.id === config.id);
|
|
284
|
-
if (!canConfigure || config.platformProvider || previous?.platformProvider) throw new Error('此模型连接由平台管理员配置');
|
|
285
|
-
await transport.saveConnection(config, key);
|
|
286
|
-
recordHelpCompleted('assistant-connection');
|
|
287
|
-
await reloadConnections(); await selectConnection(config.id, previous?.endpoint !== config.endpoint ||
|
|
288
|
-
(previous?.kind ?? 'api') !== (config.kind ?? 'api') || previous?.cliPath !== config.cliPath);
|
|
289
|
-
}
|
|
290
|
-
const canImportCcSwitch = canConfigure && !!transport?.scanCcSwitch && !!transport?.importCcSwitch;
|
|
291
|
-
async function scanCcSwitch(path?: string) {
|
|
292
|
-
if (!canImportCcSwitch) throw new Error('当前环境不支持从 CC Switch 导入');
|
|
293
|
-
return transport!.scanCcSwitch!(path);
|
|
294
|
-
}
|
|
295
|
-
async function importCcSwitch(ids: string[], path?: string) {
|
|
296
|
-
if (!canImportCcSwitch || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
297
|
-
await transport!.importCcSwitch!(ids, path);
|
|
298
|
-
await reloadConnections();
|
|
299
|
-
}
|
|
300
|
-
async function removeConnection(id: string) {
|
|
301
|
-
if (!transport || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
302
|
-
if (!canConfigure || connections.value.find(item => item.id === id)?.platformProvider) throw new Error('此模型连接由平台管理员配置');
|
|
303
|
-
await transport.removeConnection(id);
|
|
304
|
-
await reloadConnections();
|
|
255
|
+
await persistTask.catch(() => {});
|
|
305
256
|
}
|
|
306
257
|
function open(fileId?: string, selected?: { text: string; from?: number; to?: number }) {
|
|
307
258
|
if (!available) return;
|
|
@@ -405,6 +356,29 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
405
356
|
kind => transport.supportsMediaAttachments?.(config, kind) ?? false, abort.signal) : undefined;
|
|
406
357
|
const sources: AssistantSource[] = [];
|
|
407
358
|
const rules = await workspace.assistantRules(expected);
|
|
359
|
+
const matchedProviders = extractPluginContextMentions(
|
|
360
|
+
question,
|
|
361
|
+
workspace.pluginContextProviders ?? [],
|
|
362
|
+
pluginContextKeys.value,
|
|
363
|
+
);
|
|
364
|
+
const pluginContext: {
|
|
365
|
+
pluginId: string;
|
|
366
|
+
pluginName: string;
|
|
367
|
+
providerId: string;
|
|
368
|
+
title: string;
|
|
369
|
+
content: string;
|
|
370
|
+
}[] = [];
|
|
371
|
+
for (const entry of matchedProviders) {
|
|
372
|
+
abort.signal.throwIfAborted();
|
|
373
|
+
const block = await workspace.queryPluginAssistantContext(entry.pluginId, entry.provider.id, question);
|
|
374
|
+
pluginContext.push({
|
|
375
|
+
pluginId: entry.pluginId,
|
|
376
|
+
pluginName: entry.pluginName,
|
|
377
|
+
providerId: entry.provider.id,
|
|
378
|
+
title: block.title,
|
|
379
|
+
content: block.content,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
408
382
|
for (const id of [...new Set(files.value)]) {
|
|
409
383
|
abort.signal.throwIfAborted();
|
|
410
384
|
const source = await workspace.assistantSnapshot(expected, id);
|
|
@@ -440,7 +414,15 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
440
414
|
target.title = (first.content || first.attachments?.[0]?.name || target.title).slice(0, 50);
|
|
441
415
|
target.updatedAt = now; prompt.value = '';
|
|
442
416
|
await persist(target);
|
|
443
|
-
if (epoch === generation) attachments.value = [];
|
|
417
|
+
if (epoch === generation) { attachments.value = []; pluginContextKeys.value = []; }
|
|
418
|
+
const { assistantExtension, pluginBridge } = buildAssistantPluginBridge({
|
|
419
|
+
runtime,
|
|
420
|
+
workspace,
|
|
421
|
+
expected,
|
|
422
|
+
runId: reply.id,
|
|
423
|
+
inline: !!inline,
|
|
424
|
+
background: !!background,
|
|
425
|
+
});
|
|
444
426
|
let structureSnapshot: Awaited<ReturnType<typeof workspace.assistantStructures>> | undefined;
|
|
445
427
|
let structureChanged = false;
|
|
446
428
|
let responseActivity: Extract<AssistantActivity, { kind: 'text' }> | undefined;
|
|
@@ -454,6 +436,8 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
454
436
|
reply.usage = await runAssistant({ transport: executionTransport, connectionId: config.id, model, reasoningEffort: effort, tools: config.tools,
|
|
455
437
|
mode: inline ? 'inline' : 'sidebar', locale: requestLocale, promptOrigin,
|
|
456
438
|
workspaceId: expected.id, runId: reply.id, sources: reply.sources!, history, rules, prompt: question, signal: abort.signal,
|
|
439
|
+
...(pluginContext.length ? { pluginContext } : {}),
|
|
440
|
+
...(pluginBridge ? { pluginBridge } : {}),
|
|
457
441
|
...(inputs ? { attachments: inputs } : {}),
|
|
458
442
|
...(inline ? {} : { askUser: (questions: AssistantQuestion[]) => askUser(questions, target, reply!, abort.signal) }),
|
|
459
443
|
execute: async (proposal: AssistantProposal) => {
|
|
@@ -507,8 +491,10 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
507
491
|
} else {
|
|
508
492
|
reply!.activity!.push({ kind: 'tool', name: event.name, status: 'running' });
|
|
509
493
|
toolActivity = reply!.activity!.at(-1) as typeof toolActivity;
|
|
510
|
-
|
|
511
|
-
|
|
494
|
+
const toolLabel = (assistantCopy(requestLocale).tools as Record<string, string>)[event.name]
|
|
495
|
+
?? assistantExtension?.toolLabel?.(event.name)
|
|
496
|
+
?? assistantToolLabel(event.name);
|
|
497
|
+
progress.value = formatAssistantText(assistantCopy(requestLocale).progress.executing, [toolLabel]);
|
|
512
498
|
}
|
|
513
499
|
},
|
|
514
500
|
proposal: proposal => { if (epoch === generation) reply!.proposals!.push(proposal); },
|
|
@@ -552,182 +538,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
552
538
|
if (epoch === generation) { busy.value = false; progress.value = ''; controller = undefined; }
|
|
553
539
|
}
|
|
554
540
|
}
|
|
555
|
-
async function executeChange(proposal: AssistantProposal, target: AssistantSession, expected: ReturnType<typeof scope>, signal: AbortSignal): Promise<AssistantExecutionResult> {
|
|
556
|
-
let submitted = false;
|
|
557
|
-
applying.value = true;
|
|
558
|
-
const assertCurrent = () => {
|
|
559
|
-
signal.throwIfAborted();
|
|
560
|
-
if (workspace.workspace?.id !== expected.id || workspace.workspace.path !== expected.path || workspace.assistantEpoch !== expected.epoch)
|
|
561
|
-
throw new Error('工作区已切换,停止执行');
|
|
562
|
-
if (proposal.fileId && managed(proposal.fileId)) throw new Error('此文档正由协作会话管理,暂时不能直接修改');
|
|
563
|
-
};
|
|
564
|
-
try {
|
|
565
|
-
await background?.guard();
|
|
566
|
-
assertCurrent();
|
|
567
|
-
if (target.messages.some(message => message.proposals?.some(item => item.id !== proposal.id &&
|
|
568
|
-
['unknown', 'applying'].includes(item.status) && (item.path === proposal.path || !!proposal.fileId && item.fileId === proposal.fileId))))
|
|
569
|
-
throw new Error('此目标有结果待核对的操作,请先核对,不自动重试');
|
|
570
|
-
progress.value = formatAssistantText(assistantCopy(uiLocale.value).progress.executing, [proposal.path]);
|
|
571
|
-
const preview = await workspace.reviewAssistantProposal(expected, proposal, undefined, true, signal);
|
|
572
|
-
if (preview.status === 'saved') {
|
|
573
|
-
proposal.applied = preview.applied; proposal.status = 'applied';
|
|
574
|
-
} else {
|
|
575
|
-
proposal.preview = preview.preview;
|
|
576
|
-
if (preview.status !== 'preview' || !preview.preview) {
|
|
577
|
-
proposal.status = preview.status === 'conflict' ? 'conflicted' : 'ready';
|
|
578
|
-
throw new Error('修改存在冲突或文档已变化,已暂停此项操作,请核对原文与建议');
|
|
579
|
-
}
|
|
580
|
-
proposal.status = 'applying';
|
|
581
|
-
await persist(target); // A crash must leave a durable intent, never an invisible write.
|
|
582
|
-
await background?.guard();
|
|
583
|
-
assertCurrent();
|
|
584
|
-
submitted = true;
|
|
585
|
-
const result = await workspace.reviewAssistantProposal(expected, proposal, proposal.preview, true, signal);
|
|
586
|
-
if (result.status === 'saved') {
|
|
587
|
-
proposal.applied = result.applied; proposal.status = 'applied'; proposal.error = undefined;
|
|
588
|
-
} else {
|
|
589
|
-
proposal.preview = result.preview;
|
|
590
|
-
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
591
|
-
proposal.error = '执行前文档发生变化,已暂停此项操作,请核对后处理';
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
await persist(target);
|
|
595
|
-
} catch (reason) {
|
|
596
|
-
if (proposal.applied) {
|
|
597
|
-
proposal.status = 'applied';
|
|
598
|
-
proposal.error = `修改已完成,记录或刷新失败:${String(reason)}`;
|
|
599
|
-
} else {
|
|
600
|
-
if (proposal.status === 'applying') proposal.status = submitted ? 'unknown' : 'ready';
|
|
601
|
-
proposal.error = String(reason);
|
|
602
|
-
}
|
|
603
|
-
try { await persist(target); } catch { /* Preserve the in-memory outcome; never retry the write. */ }
|
|
604
|
-
} finally { applying.value = false; }
|
|
605
|
-
const written = proposal.status === 'applied' ? true : proposal.status === 'unknown' ? null : false;
|
|
606
|
-
const result: AssistantExecutionResult = { status: proposal.status, written, ...(proposal.error ? { error: proposal.error } : {}) };
|
|
607
|
-
if (written && proposal.applied) {
|
|
608
|
-
result.fileId = proposal.applied.fileId;
|
|
609
|
-
result.path = proposal.preview?.destination ?? proposal.preview?.path ?? proposal.path;
|
|
610
|
-
// Return committed bytes as a new immutable source; never widen an original selection.
|
|
611
|
-
if (['edit', 'create', 'rename', 'move'].includes(proposal.kind) && !target.messages.some(message => message.id === proposal.runId &&
|
|
612
|
-
message.sources?.some(source => source.fileId === proposal.fileId && source.selection)))
|
|
613
|
-
result.source = { id: '', workspaceId: expected.id, fileId: result.fileId, path: result.path,
|
|
614
|
-
content: proposal.applied.after, hash: proposal.applied.hash, origin: 'disk' };
|
|
615
|
-
}
|
|
616
|
-
return result;
|
|
617
|
-
}
|
|
618
|
-
async function review(proposal: AssistantProposal, apply = false) {
|
|
619
|
-
if (busy.value || applying.value || !transport) return;
|
|
620
|
-
if (proposal.suggestionGroupId) { error.value = '此提案已转为文档建议,请在文档中逐项审阅'; return; }
|
|
621
|
-
const expected = scope();
|
|
622
|
-
if (proposal.status === 'applied' || proposal.status === 'rejected') return;
|
|
623
|
-
if (proposal.status === 'unknown' || proposal.status === 'applying') { error.value = '请先核对待确认的写入结果'; return; }
|
|
624
|
-
if (proposal.fileId && managed(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂时只能进行问答'; return; }
|
|
625
|
-
applying.value = true; error.value = '';
|
|
626
|
-
const target = session.value;
|
|
627
|
-
const originalStatus = proposal.status;
|
|
628
|
-
let submitting = false;
|
|
629
|
-
try {
|
|
630
|
-
const acceptance = apply ? proposal.preview : undefined;
|
|
631
|
-
if (apply && !acceptance) throw new Error('请先查看最新差异');
|
|
632
|
-
if (apply) {
|
|
633
|
-
proposal.status = 'applying';
|
|
634
|
-
await persist(target);
|
|
635
|
-
submitting = true;
|
|
636
|
-
}
|
|
637
|
-
const result = await workspace.reviewAssistantProposal(expected, proposal, acceptance, false, undefined, !!target?.external);
|
|
638
|
-
if (result.status === 'saved') {
|
|
639
|
-
proposal.status = 'applied'; proposal.applied = result.applied; proposal.error = undefined;
|
|
640
|
-
} else {
|
|
641
|
-
proposal.preview = result.preview;
|
|
642
|
-
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
643
|
-
proposal.error = result.status === 'stale' ? (result.preview ? '文档已变化,请审阅更新后的差异再应用' : '文档在保存时变化,请重新查看差异')
|
|
644
|
-
: result.status === 'conflict' ? '修改存在重叠,原文与建议均已保留' : undefined;
|
|
645
|
-
}
|
|
646
|
-
await persist(target);
|
|
647
|
-
if (target?.external && proposal.id === target.id) await transport.recordExternalResult?.(target);
|
|
648
|
-
} catch (reason) {
|
|
649
|
-
if (proposal.applied) {
|
|
650
|
-
proposal.status = 'applied';
|
|
651
|
-
proposal.error = `内容已保存,会话记录保存失败:${String(reason)}`;
|
|
652
|
-
} else {
|
|
653
|
-
proposal.status = submitting ? 'unknown' : originalStatus;
|
|
654
|
-
proposal.error = String(reason);
|
|
655
|
-
}
|
|
656
|
-
error.value = proposal.error;
|
|
657
|
-
try { await persist(target); } catch { /* Keep the in-memory result visible. */ }
|
|
658
|
-
} finally { applying.value = false; }
|
|
659
|
-
}
|
|
660
|
-
async function publishSuggestions(proposal: AssistantProposal) {
|
|
661
|
-
if (busy.value || applying.value || proposal.kind !== 'edit' || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
662
|
-
if (isDataTableFilePath(proposal.path)) { error.value = '数据表修改请在助手中查看差异并应用'; return; }
|
|
663
|
-
if (proposal.fileId && managed(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂不支持建议模式'; return; }
|
|
664
|
-
applying.value = true;
|
|
665
|
-
const target = session.value;
|
|
666
|
-
try {
|
|
667
|
-
await useSuggestionStore().publish(proposal);
|
|
668
|
-
proposal.suggestionGroupId = proposal.id;
|
|
669
|
-
await persist(target);
|
|
670
|
-
error.value = '';
|
|
671
|
-
} catch (reason) { error.value = String(reason); }
|
|
672
|
-
finally { applying.value = false; }
|
|
673
|
-
}
|
|
674
|
-
async function verify(proposal: AssistantProposal) {
|
|
675
|
-
if (applying.value || busy.value || !proposal.preview) return;
|
|
676
|
-
applying.value = true; error.value = '';
|
|
677
|
-
const target = session.value;
|
|
678
|
-
try {
|
|
679
|
-
const expected = scope();
|
|
680
|
-
if (expected.id !== proposal.workspaceId) throw new Error('工作区已切换');
|
|
681
|
-
const current = await runtime.adapter.refresh();
|
|
682
|
-
if (current.id !== expected.id || current.path !== expected.path) throw new Error('工作区已切换');
|
|
683
|
-
if (['delete', 'rename', 'move'].includes(proposal.kind)) {
|
|
684
|
-
const file = current.files.find(file => file.id === proposal.fileId);
|
|
685
|
-
if (!file) throw new Error('原文件已不存在,无法确认是否由此次操作移除;请核对回收站,保留此记录');
|
|
686
|
-
const disk = await runtime.adapter.read(file.path);
|
|
687
|
-
if (proposal.kind !== 'delete' && file.path === proposal.preview.destination && disk.hash === proposal.preview.diskHash) {
|
|
688
|
-
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
689
|
-
proposal.status = 'applied'; proposal.error = undefined;
|
|
690
|
-
} else if (file.path === proposal.preview.path && disk.hash === proposal.preview.diskHash) {
|
|
691
|
-
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次文件操作,请重新审阅';
|
|
692
|
-
} else throw new Error('文件位置或内容已变化,请人工核对;不自动重试');
|
|
693
|
-
await persist(target);
|
|
694
|
-
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
const file = current.files.find(file => proposal.kind === 'edit' ? file.id === proposal.fileId : file.path === proposal.path);
|
|
698
|
-
if (!file || current.id !== expected.id || current.path !== expected.path) throw new Error('原目标不存在,请保留建议并核对工作区');
|
|
699
|
-
const disk = await runtime.adapter.read(file.path);
|
|
700
|
-
if (disk.content === proposal.preview.after) {
|
|
701
|
-
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
702
|
-
proposal.status = 'applied'; proposal.error = undefined;
|
|
703
|
-
} else if (proposal.kind === 'edit' && disk.hash === proposal.preview.diskHash) {
|
|
704
|
-
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次写入,请重新审阅';
|
|
705
|
-
} else throw new Error('磁盘内容与写入前后均不同,请打开文档人工核对;不自动重试');
|
|
706
|
-
await persist(target);
|
|
707
|
-
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
708
|
-
} catch (reason) { error.value = String(reason); }
|
|
709
|
-
finally { applying.value = false; }
|
|
710
|
-
}
|
|
711
|
-
async function reject(proposal: AssistantProposal) {
|
|
712
|
-
if (applying.value || busy.value || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
713
|
-
proposal.status = 'rejected';
|
|
714
|
-
const target = session.value;
|
|
715
|
-
try { await persist(target); if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target); }
|
|
716
|
-
catch (reason) { error.value = String(reason); }
|
|
717
|
-
}
|
|
718
|
-
async function undo(proposal: AssistantProposal) {
|
|
719
|
-
if (!proposal.applied || applying.value || busy.value || !['edit', 'create'].includes(proposal.kind)) return;
|
|
720
|
-
if (proposal.kind === 'create' && isDataTableFilePath(proposal.path)) return;
|
|
721
|
-
const reply = session.value?.messages.find(message => message.id === proposal.runId);
|
|
722
|
-
if (!reply) return;
|
|
723
|
-
const reversed: AssistantProposal = { id: crypto.randomUUID(), runId: reply.id, workspaceId: proposal.workspaceId,
|
|
724
|
-
kind: 'edit', fileId: proposal.applied.fileId, path: proposal.path, base: proposal.applied.after,
|
|
725
|
-
content: proposal.applied.before, reason: `撤回内容:${proposal.reason}`, status: 'ready' };
|
|
726
|
-
reply.proposals!.push(reversed);
|
|
727
|
-
const current = reply.proposals!.at(-1)!;
|
|
728
|
-
current.execution = 'direct';
|
|
729
|
-
await executeChange(current, session.value!, scope(), new AbortController().signal);
|
|
730
|
-
}
|
|
731
541
|
async function deleteSession(id: string) {
|
|
732
542
|
if (!transport || busy.value || applying.value) return;
|
|
733
543
|
await persistTask.catch(() => {});
|
|
@@ -741,7 +551,7 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
741
551
|
if (busy.value || applying.value) return;
|
|
742
552
|
session.value = sessions.value.find(item => item.id === id) ?? null;
|
|
743
553
|
restoreModelSelection(session.value);
|
|
744
|
-
files.value = []; attachments.value = []; selection.value = null; prompt.value = ''; error.value = '';
|
|
554
|
+
files.value = []; attachments.value = []; pluginContextKeys.value = []; selection.value = null; prompt.value = ''; error.value = '';
|
|
745
555
|
replyTarget.value = null;
|
|
746
556
|
}
|
|
747
557
|
async function loadExternal() {
|
|
@@ -763,9 +573,9 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
763
573
|
externalSessions.value = externalSessions.value.filter(item => item.id !== target.id);
|
|
764
574
|
}
|
|
765
575
|
watch(() => workspace.workspace ? `${workspace.workspace.id}:${workspace.workspace.path}:${workspace.assistantEpoch}` : '', async key => {
|
|
766
|
-
stop();
|
|
576
|
+
stop(); abortModels(); const epoch = ++generation;
|
|
767
577
|
if (displayMode.value === 'fullscreen') setDisplayMode('sidebar');
|
|
768
|
-
busy.value = false; prompt.value = ''; files.value = []; attachments.value = []; selection.value = null; session.value = null; sessions.value = [];
|
|
578
|
+
busy.value = false; prompt.value = ''; files.value = []; attachments.value = []; pluginContextKeys.value = []; selection.value = null; session.value = null; sessions.value = [];
|
|
769
579
|
replyTarget.value = null;
|
|
770
580
|
connectionId.value = ''; modelId.value = ''; models.value = []; modelsError.value = ''; modelsLoading.value = false;
|
|
771
581
|
if (!key || !transport) return;
|
|
@@ -795,8 +605,38 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
795
605
|
if (fullscreenTabId.value && !ids.includes(fullscreenTabId.value)) setDisplayMode('sidebar');
|
|
796
606
|
});
|
|
797
607
|
watch([connection, opened], () => { void reloadModels(); });
|
|
798
|
-
|
|
608
|
+
if (!inline && !background && transport) {
|
|
609
|
+
workspace.setPluginAiRunner?.(async ({ structured, request, signal }) => {
|
|
610
|
+
let availableConnections = connections.value;
|
|
611
|
+
if (!availableConnections.length) {
|
|
612
|
+
await reloadConnections();
|
|
613
|
+
availableConnections = connections.value;
|
|
614
|
+
}
|
|
615
|
+
const selectedConn =
|
|
616
|
+
availableConnections.find(item => item.id === connectionId.value) ?? availableConnections[0];
|
|
617
|
+
if (!selectedConn) throw new Error('尚未配置同页助手模型连接,无法执行插件 AI 推理');
|
|
618
|
+
let targetModel = modelId.value;
|
|
619
|
+
if (!targetModel) {
|
|
620
|
+
const fetched = models.value.length ? models.value : await transport.models(selectedConn.id, signal);
|
|
621
|
+
targetModel = fetched.find(item => isAssistantModelId(item)) ?? '';
|
|
622
|
+
}
|
|
623
|
+
if (!targetModel) throw new Error('当前模型连接没有可用模型,请先在助手设置中选择模型');
|
|
624
|
+
return runPluginAiCompletion({
|
|
625
|
+
transport,
|
|
626
|
+
connectionId: selectedConn.id,
|
|
627
|
+
model: targetModel,
|
|
628
|
+
request,
|
|
629
|
+
structured,
|
|
630
|
+
signal,
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
onScopeDispose(() => {
|
|
635
|
+
if (!inline && !background) workspace.setPluginAiRunner?.(undefined);
|
|
636
|
+
stop();
|
|
637
|
+
abortModels();
|
|
638
|
+
});
|
|
799
639
|
return { connectionCheckResults, connectionQuotaResults, canImportCcSwitch, scanCcSwitch, importCcSwitch, available, demo, canConfigure, opened, displayMode, fullscreenTabId, fullscreenPaneId, isFullscreenTab, setDisplayMode, loading, busy, applying, connections, connectionId, connection, modelId, models, modelsLoading, modelsError, reloadModels, refreshModels, selectModel, selectConnection, sessions, session, externalSessions, loadExternal, importExternal,
|
|
800
|
-
files, attachmentsEnabled, attachments, addClipboardAttachments, removeAttachment, selection, prompt, hasDraft, setBuiltInPrompt, error, progress, pendingUserInput, startDocumentDraft, submitUserInput, reasoningEffort, selectReasoningEffort, replyTarget, open, stop, settle, send, newSession, selectSession, deleteSession, review, verify,
|
|
640
|
+
files, pluginContextKeys, togglePluginContext, attachmentsEnabled, attachments, addClipboardAttachments, removeAttachment, selection, prompt, hasDraft, setBuiltInPrompt, error, progress, pendingUserInput, startDocumentDraft, submitUserInput, reasoningEffort, selectReasoningEffort, replyTarget, open, stop, settle, send, newSession, selectSession, deleteSession, review, verify,
|
|
801
641
|
undo, reject, publishSuggestions, saveConnection, removeConnection, reloadConnections, checkConnection, readConnectionKey, queryQuota, saveQuota, setManaged: (check: (id: string) => boolean) => { managed = check; } };
|
|
802
642
|
}
|