@tano.page/workbench 0.15.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 +35 -14
- package/src/App.vue +68 -797
- 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/AssistantPanel.vue +1 -1
- package/src/assistant/connection-actions.ts +237 -0
- package/src/assistant/document-mentions.ts +1 -33
- package/src/assistant/engine.ts +1 -585
- package/src/assistant/execution.ts +6 -33
- package/src/assistant/hash.ts +1 -4
- package/src/assistant/language.ts +10 -37
- package/src/assistant/plugin-bridge-builder.ts +146 -0
- package/src/assistant/prompts.ts +1 -65
- package/src/assistant/proposal-actions.ts +336 -0
- package/src/assistant/store.ts +87 -554
- package/src/assistant/structures.ts +1 -157
- package/src/assistant/tasks.ts +8 -94
- package/src/assistant/tool-rules.ts +1 -7
- package/src/composables/use-workbench-help.ts +177 -0
- package/src/composables/use-workbench-lifecycle.ts +249 -0
- package/src/composables/use-workbench-settings.ts +185 -0
- package/src/composables/use-workbench-shortcuts.ts +37 -1022
- package/src/composables/use-workbench-views.ts +325 -0
- package/src/documents/components/DocumentActionMenu.vue +279 -0
- 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/files/components/FileMetadataPanel.vue +49 -15
- package/src/i18n/locale-catalogs.ts +7 -6
- package/src/i18n/locale-registry.ts +8 -6
- package/src/i18n/locales/de-DE.json +23 -1
- package/src/i18n/locales/en-US.json +23 -1
- package/src/i18n/locales/es-ES.json +23 -1
- package/src/i18n/locales/ja-JP.json +23 -1
- package/src/i18n/locales/zh-TW.json +23 -1
- package/src/mail/components/MailAccountDialog.vue +1 -0
- package/src/mail/components/MailComposerDialog.vue +1 -0
- package/src/mail/components/MailWorkspaceView.vue +1 -0
- package/src/mail/components/SidebarMail.vue +1 -0
- package/src/objects/content-references.ts +6 -56
- package/src/objects/wiki-links.ts +1 -48
- package/src/objects/workspace-objects.ts +2 -3
- package/src/plans/calendar.ts +2 -2
- package/src/plans/components/CalendarAgendaView.vue +165 -0
- 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 +162 -2106
- package/src/plans/components/CalendarYearView.vue +138 -0
- package/src/plans/components/PlanConnectionsDialog.vue +1 -1
- 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/plugins/components/PluginDetailPage.vue +10 -6
- package/src/plugins/components/PluginDeveloperArea.vue +192 -0
- package/src/plugins/components/PluginExplorer.vue +6 -4
- package/src/plugins/components/PluginImportDialog.vue +1 -1
- package/src/plugins/components/PluginInstaller.vue +269 -178
- package/src/plugins/components/PluginMaintenance.vue +37 -49
- package/src/plugins/components/PluginRepositoryStorage.vue +4 -2
- package/src/plugins/components/PluginSettingsForm.vue +2 -1
- 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/plugin-data.ts +2 -3
- package/src/plugins/plugin-rpc-router.ts +558 -0
- package/src/plugins/plugin-sdk.ts +1 -260
- package/src/plugins/plugin-ui-dialogs.ts +167 -0
- package/src/plugins/queries.ts +1 -75
- package/src/plugins/view-header.ts +2 -7
- package/src/runtime.ts +3 -2
- 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/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/WorkbenchContextMenus.vue +37 -26
- package/src/shell/components/WorkbenchModals.vue +22 -18
- package/src/shell/components/WorkbenchPanes.vue +358 -1512
- package/src/shell/components/WorkbenchSidebar.vue +486 -0
- 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 +488 -1081
- package/src/shell/workbench-context.ts +30 -3
- package/src/stores/workspace-document-io.ts +807 -0
- package/src/stores/workspace-file-ops.ts +1 -1
- package/src/stores/workspace-knowledge.ts +1 -1
- package/src/stores/workspace-lifecycle.ts +459 -0
- package/src/stores/workspace-plugins-state.ts +71 -599
- package/src/stores/workspace-session.ts +287 -0
- package/src/stores/workspace-tabs-layout.ts +1 -1
- package/src/stores/workspace-types.ts +50 -0
- package/src/stores/workspace.ts +163 -1345
- package/src/styles.css +0 -1
- package/src/tabs/components/DesktopTabs.vue +19 -11
- 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/WorkspaceIconPicker.vue +5 -4
- package/src/workspace/components/WorkspacePickerMenu.vue +317 -0
- package/src/assistant/locales/de-DE.json +0 -129
- package/src/assistant/locales/en-US.json +0 -129
- package/src/assistant/locales/es-ES.json +0 -129
- package/src/assistant/locales/ja-JP.json +0 -129
- package/src/assistant/locales/zh-CN.json +0 -129
- package/src/assistant/locales/zh-TW.json +0 -129
- package/src/assistant/task-prompts.json +0 -39
package/src/assistant/store.ts
CHANGED
|
@@ -2,37 +2,31 @@ import { computed, onScopeDispose, ref, shallowRef, watch } from 'vue';
|
|
|
2
2
|
import { defineStore } from 'pinia';
|
|
3
3
|
import {
|
|
4
4
|
isAssistantModelId,
|
|
5
|
-
isAssistantReasoningSelection,
|
|
6
5
|
parseAssistantSession,
|
|
7
6
|
parseAssistantAnswers,
|
|
8
|
-
isDataTableFilePath,
|
|
9
7
|
} from '@tano/protocol';
|
|
10
8
|
import type { AssistantQuestion, AssistantQuestionAnswer, AssistantUserInput } from '@tano/protocol';
|
|
11
9
|
import type { AssistantActivity, AssistantConnection, AssistantQuotaResult, AssistantMessage, AssistantProposal, AssistantReasoningSelection, AssistantSession, AssistantSource } from '@tano/protocol';
|
|
12
|
-
import type { AssistantExecutionResult } from './execution';
|
|
13
10
|
import { useWorkspaceStore } from '../stores/workspace';
|
|
14
11
|
import { recordHelpCompleted } from '../help/help-checklist';
|
|
15
|
-
import {
|
|
12
|
+
import { useWorkbenchRuntime } from '../runtime';
|
|
16
13
|
import { demoAssistantTransport, nativeAssistantTransport } from './transport';
|
|
17
14
|
import { runAssistant, AssistantWaitingError } from './engine';
|
|
18
15
|
import { AssistantRunError } from './completion';
|
|
19
16
|
import type { AssistantTextPhase } from './completion';
|
|
20
17
|
import { assistantHistory, assistantToolLabel } from './results';
|
|
21
|
-
import { useSuggestionStore } from '../stores/suggestions';
|
|
22
18
|
import { t, uiLocale } from '../i18n/i18n';
|
|
23
19
|
import { isFeatureEnabled } from '../features';
|
|
24
20
|
import { assistantCopy, assistantTaskPrompts, formatAssistantText } from './language';
|
|
25
21
|
import { assistantAttachmentBytes, describeAssistantAttachment, maxAssistantAttachments, readAssistantAttachments } from './attachments';
|
|
26
22
|
import type { AssistantDraftAttachment } from './attachments';
|
|
27
23
|
import {
|
|
28
|
-
canPluginToolExecute,
|
|
29
|
-
compilePluginAssistantTools,
|
|
30
|
-
createPluginToolProposal,
|
|
31
|
-
describeInstalledPluginsForAssistant,
|
|
32
24
|
extractPluginContextMentions,
|
|
33
25
|
runPluginAiCompletion,
|
|
34
|
-
wrapUntrustedPluginData,
|
|
35
26
|
} from '../plugins/assistant-bridge';
|
|
27
|
+
import { createAssistantConnectionActions } from './connection-actions';
|
|
28
|
+
import { buildAssistantPluginBridge } from './plugin-bridge-builder';
|
|
29
|
+
import { createAssistantProposalActions } from './proposal-actions';
|
|
36
30
|
|
|
37
31
|
export type AssistantConnectionCheck = { fingerprint: string; elapsedMs?: number; checkedAt?: number; message: string; failed: boolean };
|
|
38
32
|
|
|
@@ -151,7 +145,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
151
145
|
const replyTarget = shallowRef<{ label: string; draft: (body: string) => Promise<void> } | null>(null);
|
|
152
146
|
const connection = computed(() => connections.value.find(item => item.id === connectionId.value));
|
|
153
147
|
let controller: AbortController | undefined;
|
|
154
|
-
let modelController: AbortController | undefined;
|
|
155
148
|
let generation = 0;
|
|
156
149
|
let persistTask = Promise.resolve();
|
|
157
150
|
let managed: (fileId: string) => boolean = () => false;
|
|
@@ -159,18 +152,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
159
152
|
if (!workspace.workspace) throw new Error('请先打开工作区');
|
|
160
153
|
return { id: workspace.workspace.id, path: workspace.workspace.path, epoch: workspace.assistantEpoch };
|
|
161
154
|
};
|
|
162
|
-
function stop() { controller?.abort(); }
|
|
163
|
-
async function settle() {
|
|
164
|
-
stop(); modelController?.abort();
|
|
165
|
-
if (busy.value || applying.value) {
|
|
166
|
-
await new Promise<void>(resolve => {
|
|
167
|
-
const unwatch = watch([busy, applying], ([running, writing]) => {
|
|
168
|
-
if (!running && !writing) { unwatch(); resolve(); }
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
await persistTask.catch(() => {});
|
|
173
|
-
}
|
|
174
155
|
function newSession() {
|
|
175
156
|
if (busy.value || applying.value) return;
|
|
176
157
|
const now = Date.now();
|
|
@@ -198,132 +179,80 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
198
179
|
persistTask = saved;
|
|
199
180
|
await saved;
|
|
200
181
|
}
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (connection.value?.kind === 'codex-cli') session.value.reasoningEffort = reasoningEffort.value;
|
|
274
|
-
else delete session.value.reasoningEffort;
|
|
275
|
-
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
|
+
});
|
|
276
254
|
}
|
|
277
|
-
|
|
278
|
-
async function selectModel(id: string) {
|
|
279
|
-
if (busy.value || applying.value || loading.value) return;
|
|
280
|
-
const selected = id.trim();
|
|
281
|
-
if (!connection.value) throw new Error('请先选择模型连接');
|
|
282
|
-
if (!isAssistantModelId(selected)) throw new Error('模型 ID 无效');
|
|
283
|
-
if (!session.value) newSession();
|
|
284
|
-
modelId.value = selected; session.value!.model = selected; session.value!.connectionId = connectionId.value;
|
|
285
|
-
await persist();
|
|
286
|
-
}
|
|
287
|
-
function restoreModelSelection(target: AssistantSession | null) {
|
|
288
|
-
connectionId.value = target?.connectionId ?? (connections.value.length === 1 ? connections.value[0].id : '');
|
|
289
|
-
const previous = target ? [...target.messages].reverse().find(message => message.role === 'assistant' && message.model)?.model : undefined;
|
|
290
|
-
modelId.value = target?.model ?? (isAssistantModelId(previous) ? previous : '');
|
|
291
|
-
reasoningEffort.value = target?.reasoningEffort ?? connection.value?.reasoningEffort ?? (target ? 'cli-default' : 'medium');
|
|
292
|
-
}
|
|
293
|
-
async function selectReasoningEffort(value: AssistantReasoningSelection) {
|
|
294
|
-
if (busy.value || applying.value || loading.value) return;
|
|
295
|
-
if (connection.value?.kind !== 'codex-cli') throw new Error('当前连接不支持选择推理强度');
|
|
296
|
-
if (!isAssistantReasoningSelection(value)) throw new Error('推理强度无效');
|
|
297
|
-
if (!session.value) newSession();
|
|
298
|
-
reasoningEffort.value = value;
|
|
299
|
-
session.value!.reasoningEffort = value;
|
|
300
|
-
session.value!.connectionId = connectionId.value;
|
|
301
|
-
await persist();
|
|
302
|
-
}
|
|
303
|
-
async function saveConnection(config: Omit<AssistantConnection, 'hasKey'>, key?: string) {
|
|
304
|
-
if (!transport || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
305
|
-
const previous = connections.value.find(item => item.id === config.id);
|
|
306
|
-
if (!canConfigure || config.platformProvider || previous?.platformProvider) throw new Error('此模型连接由平台管理员配置');
|
|
307
|
-
await transport.saveConnection(config, key);
|
|
308
|
-
recordHelpCompleted('assistant-connection');
|
|
309
|
-
await reloadConnections(); await selectConnection(config.id, previous?.endpoint !== config.endpoint ||
|
|
310
|
-
(previous?.kind ?? 'api') !== (config.kind ?? 'api') || previous?.cliPath !== config.cliPath);
|
|
311
|
-
}
|
|
312
|
-
const canImportCcSwitch = canConfigure && !!transport?.scanCcSwitch && !!transport?.importCcSwitch;
|
|
313
|
-
async function scanCcSwitch(path?: string) {
|
|
314
|
-
if (!canImportCcSwitch) throw new Error('当前环境不支持从 CC Switch 导入');
|
|
315
|
-
return transport!.scanCcSwitch!(path);
|
|
316
|
-
}
|
|
317
|
-
async function importCcSwitch(ids: string[], path?: string) {
|
|
318
|
-
if (!canImportCcSwitch || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
319
|
-
await transport!.importCcSwitch!(ids, path);
|
|
320
|
-
await reloadConnections();
|
|
321
|
-
}
|
|
322
|
-
async function removeConnection(id: string) {
|
|
323
|
-
if (!transport || busy.value || applying.value || loading.value) throw new Error('请先等待当前任务完成');
|
|
324
|
-
if (!canConfigure || connections.value.find(item => item.id === id)?.platformProvider) throw new Error('此模型连接由平台管理员配置');
|
|
325
|
-
await transport.removeConnection(id);
|
|
326
|
-
await reloadConnections();
|
|
255
|
+
await persistTask.catch(() => {});
|
|
327
256
|
}
|
|
328
257
|
function open(fileId?: string, selected?: { text: string; from?: number; to?: number }) {
|
|
329
258
|
if (!available) return;
|
|
@@ -486,128 +415,14 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
486
415
|
target.updatedAt = now; prompt.value = '';
|
|
487
416
|
await persist(target);
|
|
488
417
|
if (epoch === generation) { attachments.value = []; pluginContextKeys.value = []; }
|
|
489
|
-
const assistantExtension =
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const extensionToolNames = new Set(extensionTools.map(tool => tool.function.name));
|
|
498
|
-
const compiledPlugins = compilePluginAssistantTools(
|
|
499
|
-
workspace.installedPlugins ?? [],
|
|
500
|
-
workspace.pluginRuntime ?? [],
|
|
501
|
-
!!workspace.workspace?.readOnly,
|
|
502
|
-
);
|
|
503
|
-
const combinedExtraTools = [...extensionTools, ...compiledPlugins.tools];
|
|
504
|
-
const extensionPromptHints =
|
|
505
|
-
assistantExtension?.promptHints?.({ workspaceReadOnly: !!workspace.workspace?.readOnly }) ?? [];
|
|
506
|
-
const pluginBridge = combinedExtraTools.length || extensionPromptHints.length
|
|
507
|
-
? {
|
|
508
|
-
tools: combinedExtraTools,
|
|
509
|
-
...(extensionPromptHints.length ? { promptHints: extensionPromptHints } : {}),
|
|
510
|
-
isPluginTool: (name: string) =>
|
|
511
|
-
name === 'inspect_plugins' ||
|
|
512
|
-
name === 'inspect_plugin_logs' ||
|
|
513
|
-
name === 'open_plugin_view' ||
|
|
514
|
-
extensionToolNames.has(name) ||
|
|
515
|
-
compiledPlugins.pluginTools.has(name),
|
|
516
|
-
executeTool: async (call: import('@tano/protocol').AssistantToolCall, signal: AbortSignal) => {
|
|
517
|
-
signal.throwIfAborted();
|
|
518
|
-
if (workspace.workspace?.id !== expected.id || workspace.workspace.path !== expected.path)
|
|
519
|
-
throw new Error('工作区已切换');
|
|
520
|
-
const parsedArgs: unknown = JSON.parse(call.function.arguments || '{}');
|
|
521
|
-
if (!parsedArgs || typeof parsedArgs !== 'object' || Array.isArray(parsedArgs))
|
|
522
|
-
throw new Error('插件工具参数必须为对象');
|
|
523
|
-
const args = parsedArgs as Record<string, unknown>;
|
|
524
|
-
if (assistantExtension && extensionToolNames.has(call.function.name)) {
|
|
525
|
-
const extResult = await assistantExtension.executeTool(call.function.name, args, {
|
|
526
|
-
workspaceId: expected.id,
|
|
527
|
-
workspacePath: expected.path,
|
|
528
|
-
runId: reply!.id,
|
|
529
|
-
activeDocumentId: workspace.active?.id,
|
|
530
|
-
signal,
|
|
531
|
-
});
|
|
532
|
-
if (extResult) return extResult;
|
|
533
|
-
}
|
|
534
|
-
if (call.function.name === 'inspect_plugins') {
|
|
535
|
-
if (Object.keys(args).length) throw new Error('inspect_plugins 不接受参数');
|
|
536
|
-
return {
|
|
537
|
-
kind: 'result' as const,
|
|
538
|
-
data: {
|
|
539
|
-
plugins: describeInstalledPluginsForAssistant(
|
|
540
|
-
workspace.installedPlugins,
|
|
541
|
-
workspace.pluginRuntime,
|
|
542
|
-
!!workspace.workspace?.readOnly,
|
|
543
|
-
),
|
|
544
|
-
},
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
if (call.function.name === 'inspect_plugin_logs') {
|
|
548
|
-
if (Object.keys(args).some(key => key !== 'pluginId' && key !== 'limit'))
|
|
549
|
-
throw new Error('inspect_plugin_logs 参数无效');
|
|
550
|
-
const pluginId = typeof args.pluginId === 'string' ? args.pluginId.trim() : '';
|
|
551
|
-
if (!pluginId) throw new Error('inspect_plugin_logs 缺少有效的 pluginId');
|
|
552
|
-
let limit = 20;
|
|
553
|
-
if (args.limit !== undefined) {
|
|
554
|
-
if (typeof args.limit !== 'number' || !Number.isInteger(args.limit) || args.limit < 1 || args.limit > 50)
|
|
555
|
-
throw new Error('inspect_plugin_logs 的 limit 必须为 1 至 50 的整数');
|
|
556
|
-
limit = args.limit;
|
|
557
|
-
}
|
|
558
|
-
const installation = workspace.installedPlugins.find(item => item.manifest.id === pluginId);
|
|
559
|
-
const runtimeState = workspace.pluginRuntime.find(item => item.id === pluginId);
|
|
560
|
-
if (!installation && !runtimeState) throw new Error('未找到指定已安装插件');
|
|
561
|
-
const logs = (runtimeState?.logs ?? []).slice(-limit);
|
|
562
|
-
return {
|
|
563
|
-
kind: 'result' as const,
|
|
564
|
-
data: {
|
|
565
|
-
pluginId,
|
|
566
|
-
pluginName: installation?.manifest.name ?? runtimeState?.name ?? pluginId,
|
|
567
|
-
enabled: installation?.enabled ?? false,
|
|
568
|
-
authorized: installation?.authorized ?? false,
|
|
569
|
-
status: runtimeState?.status ?? 'idle',
|
|
570
|
-
logCount: logs.length,
|
|
571
|
-
untrustedPluginData: wrapUntrustedPluginData(pluginId, 'runtime:logs', {
|
|
572
|
-
status: runtimeState?.status ?? 'idle',
|
|
573
|
-
message: runtimeState?.message ?? '',
|
|
574
|
-
logs,
|
|
575
|
-
}),
|
|
576
|
-
},
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
if (call.function.name === 'open_plugin_view') {
|
|
580
|
-
if (typeof args.pluginId !== 'string' || typeof args.viewId !== 'string' || Object.keys(args).length !== 2)
|
|
581
|
-
throw new Error('open_plugin_view 参数无效');
|
|
582
|
-
workspace.openPluginView(args.pluginId, args.viewId);
|
|
583
|
-
return { kind: 'result' as const, data: { opened: true, pluginId: args.pluginId, viewId: args.viewId } };
|
|
584
|
-
}
|
|
585
|
-
const compiled = compiledPlugins.pluginTools.get(call.function.name);
|
|
586
|
-
if (!compiled) throw new Error('插件工具不可用或未授权');
|
|
587
|
-
const installation = workspace.installedPlugins.find(item => item.manifest.id === compiled.pluginId);
|
|
588
|
-
if (!installation || !canPluginToolExecute(installation, compiled.tool, !!workspace.workspace?.readOnly))
|
|
589
|
-
throw new Error('当前工作区权限或策略不允许执行此插件工具');
|
|
590
|
-
if (compiled.tool.effect === 'read') {
|
|
591
|
-
const raw = await workspace.invokePluginAssistantTool(compiled.pluginId, compiled.tool.name, args);
|
|
592
|
-
return {
|
|
593
|
-
kind: 'result' as const,
|
|
594
|
-
data: {
|
|
595
|
-
untrustedPluginData: wrapUntrustedPluginData(compiled.pluginId, `tool:${compiled.tool.name}`, raw),
|
|
596
|
-
},
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
kind: 'proposal' as const,
|
|
601
|
-
proposal: createPluginToolProposal({
|
|
602
|
-
workspaceId: expected.id,
|
|
603
|
-
runId: reply!.id,
|
|
604
|
-
compiled,
|
|
605
|
-
rawArgs: args,
|
|
606
|
-
}),
|
|
607
|
-
};
|
|
608
|
-
},
|
|
609
|
-
}
|
|
610
|
-
: undefined;
|
|
418
|
+
const { assistantExtension, pluginBridge } = buildAssistantPluginBridge({
|
|
419
|
+
runtime,
|
|
420
|
+
workspace,
|
|
421
|
+
expected,
|
|
422
|
+
runId: reply.id,
|
|
423
|
+
inline: !!inline,
|
|
424
|
+
background: !!background,
|
|
425
|
+
});
|
|
611
426
|
let structureSnapshot: Awaited<ReturnType<typeof workspace.assistantStructures>> | undefined;
|
|
612
427
|
let structureChanged = false;
|
|
613
428
|
let responseActivity: Extract<AssistantActivity, { kind: 'text' }> | undefined;
|
|
@@ -723,288 +538,6 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
723
538
|
if (epoch === generation) { busy.value = false; progress.value = ''; controller = undefined; }
|
|
724
539
|
}
|
|
725
540
|
}
|
|
726
|
-
async function executeChange(proposal: AssistantProposal, target: AssistantSession, expected: ReturnType<typeof scope>, signal: AbortSignal): Promise<AssistantExecutionResult> {
|
|
727
|
-
let submitted = false;
|
|
728
|
-
applying.value = true;
|
|
729
|
-
const assertCurrent = () => {
|
|
730
|
-
signal.throwIfAborted();
|
|
731
|
-
if (workspace.workspace?.id !== expected.id || workspace.workspace.path !== expected.path || workspace.assistantEpoch !== expected.epoch)
|
|
732
|
-
throw new Error('工作区已切换,停止执行');
|
|
733
|
-
if (proposal.fileId && managed(proposal.fileId)) throw new Error('此文档正由协作会话管理,暂时不能直接修改');
|
|
734
|
-
};
|
|
735
|
-
try {
|
|
736
|
-
await background?.guard();
|
|
737
|
-
assertCurrent();
|
|
738
|
-
if (target.messages.some(message => message.proposals?.some(item => item.id !== proposal.id &&
|
|
739
|
-
['unknown', 'applying'].includes(item.status) && (item.path === proposal.path || !!proposal.fileId && item.fileId === proposal.fileId))))
|
|
740
|
-
throw new Error('此目标有结果待核对的操作,请先核对,不自动重试');
|
|
741
|
-
progress.value = formatAssistantText(assistantCopy(uiLocale.value).progress.executing, [proposal.path]);
|
|
742
|
-
const preview = await workspace.reviewAssistantProposal(expected, proposal, undefined, true, signal);
|
|
743
|
-
if (preview.status === 'saved') {
|
|
744
|
-
proposal.applied = preview.applied; proposal.status = 'applied';
|
|
745
|
-
} else {
|
|
746
|
-
proposal.preview = preview.preview;
|
|
747
|
-
if (preview.status !== 'preview' || !preview.preview) {
|
|
748
|
-
proposal.status = preview.status === 'conflict' ? 'conflicted' : 'ready';
|
|
749
|
-
throw new Error('修改存在冲突或文档已变化,已暂停此项操作,请核对原文与建议');
|
|
750
|
-
}
|
|
751
|
-
proposal.status = 'applying';
|
|
752
|
-
await persist(target); // A crash must leave a durable intent, never an invisible write.
|
|
753
|
-
await background?.guard();
|
|
754
|
-
assertCurrent();
|
|
755
|
-
submitted = true;
|
|
756
|
-
const result = await workspace.reviewAssistantProposal(expected, proposal, proposal.preview, true, signal);
|
|
757
|
-
if (result.status === 'saved') {
|
|
758
|
-
proposal.applied = result.applied; proposal.status = 'applied'; proposal.error = undefined;
|
|
759
|
-
} else {
|
|
760
|
-
proposal.preview = result.preview;
|
|
761
|
-
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
762
|
-
proposal.error = '执行前文档发生变化,已暂停此项操作,请核对后处理';
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
await persist(target);
|
|
766
|
-
} catch (reason) {
|
|
767
|
-
if (proposal.applied) {
|
|
768
|
-
proposal.status = 'applied';
|
|
769
|
-
proposal.error = `修改已完成,记录或刷新失败:${String(reason)}`;
|
|
770
|
-
} else {
|
|
771
|
-
if (proposal.status === 'applying') proposal.status = submitted ? 'unknown' : 'ready';
|
|
772
|
-
proposal.error = String(reason);
|
|
773
|
-
}
|
|
774
|
-
try { await persist(target); } catch { /* Preserve the in-memory outcome; never retry the write. */ }
|
|
775
|
-
} finally { applying.value = false; }
|
|
776
|
-
const written = proposal.status === 'applied' ? true : proposal.status === 'unknown' ? null : false;
|
|
777
|
-
const result: AssistantExecutionResult = { status: proposal.status, written, ...(proposal.error ? { error: proposal.error } : {}) };
|
|
778
|
-
if (written && proposal.applied) {
|
|
779
|
-
result.fileId = proposal.applied.fileId;
|
|
780
|
-
result.path = proposal.preview?.destination ?? proposal.preview?.path ?? proposal.path;
|
|
781
|
-
// Return committed bytes as a new immutable source; never widen an original selection.
|
|
782
|
-
if (['edit', 'create', 'rename', 'move'].includes(proposal.kind) && !target.messages.some(message => message.id === proposal.runId &&
|
|
783
|
-
message.sources?.some(source => source.fileId === proposal.fileId && source.selection)))
|
|
784
|
-
result.source = { id: '', workspaceId: expected.id, fileId: result.fileId, path: result.path,
|
|
785
|
-
content: proposal.applied.after, hash: proposal.applied.hash, origin: 'disk' };
|
|
786
|
-
}
|
|
787
|
-
return result;
|
|
788
|
-
}
|
|
789
|
-
async function review(proposal: AssistantProposal, apply = false) {
|
|
790
|
-
if (busy.value || applying.value || !transport) return;
|
|
791
|
-
if (proposal.suggestionGroupId) { error.value = '此提案已转为文档建议,请在文档中逐项审阅'; return; }
|
|
792
|
-
const expected = scope();
|
|
793
|
-
if (proposal.status === 'applied' || proposal.status === 'rejected') return;
|
|
794
|
-
if (proposal.status === 'unknown' || proposal.status === 'applying') { error.value = '请先核对待确认的写入结果'; return; }
|
|
795
|
-
if (proposal.fileId && managed(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂时只能进行问答'; return; }
|
|
796
|
-
applying.value = true; error.value = '';
|
|
797
|
-
const target = session.value;
|
|
798
|
-
const originalStatus = proposal.status;
|
|
799
|
-
let submitting = false;
|
|
800
|
-
try {
|
|
801
|
-
if (proposal.kind === 'extension') {
|
|
802
|
-
const extAction = proposal.extensionAction;
|
|
803
|
-
if (!extAction) throw new Error('扩展操作元数据缺失');
|
|
804
|
-
if (!apply) {
|
|
805
|
-
proposal.preview = {
|
|
806
|
-
before: '',
|
|
807
|
-
after: proposal.content,
|
|
808
|
-
diskHash: null,
|
|
809
|
-
path: proposal.path,
|
|
810
|
-
};
|
|
811
|
-
proposal.status = 'ready';
|
|
812
|
-
await persist(target);
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
const assistantExtension = resolveAssistantExtension(runtime);
|
|
816
|
-
if (!assistantExtension?.applyProposal) throw new Error('当前宿主未注册该扩展操作处理器');
|
|
817
|
-
proposal.status = 'applying';
|
|
818
|
-
await persist(target);
|
|
819
|
-
submitting = true;
|
|
820
|
-
const extApplied = await assistantExtension.applyProposal(proposal, extAction.payload);
|
|
821
|
-
if (!extApplied) throw new Error('当前宿主不支持执行此扩展操作');
|
|
822
|
-
proposal.applied = {
|
|
823
|
-
before: extApplied.before ?? '',
|
|
824
|
-
after: extApplied.after,
|
|
825
|
-
hash: extApplied.hash,
|
|
826
|
-
fileId: extApplied.fileId,
|
|
827
|
-
...(extApplied.undoSnapshot !== undefined ? { undoSnapshot: extApplied.undoSnapshot } : {}),
|
|
828
|
-
};
|
|
829
|
-
proposal.status = 'applied';
|
|
830
|
-
proposal.error = undefined;
|
|
831
|
-
await persist(target);
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
if (proposal.kind === 'plugin') {
|
|
835
|
-
const action = proposal.pluginAction;
|
|
836
|
-
if (!action) throw new Error('插件操作元数据缺失');
|
|
837
|
-
if (!apply) {
|
|
838
|
-
proposal.preview = {
|
|
839
|
-
before: '',
|
|
840
|
-
after: proposal.content,
|
|
841
|
-
diskHash: null,
|
|
842
|
-
path: proposal.path,
|
|
843
|
-
};
|
|
844
|
-
proposal.status = 'ready';
|
|
845
|
-
await persist(target);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
const parsedArgs = JSON.parse(proposal.content) as Record<string, unknown>;
|
|
849
|
-
const assistantExtension = resolveAssistantExtension(runtime);
|
|
850
|
-
if (assistantExtension?.applyProposal) {
|
|
851
|
-
proposal.status = 'applying';
|
|
852
|
-
await persist(target);
|
|
853
|
-
submitting = true;
|
|
854
|
-
const extApplied = await assistantExtension.applyProposal(proposal, parsedArgs);
|
|
855
|
-
if (extApplied) {
|
|
856
|
-
proposal.applied = {
|
|
857
|
-
before: extApplied.before ?? '',
|
|
858
|
-
after: extApplied.after,
|
|
859
|
-
hash: extApplied.hash,
|
|
860
|
-
fileId: extApplied.fileId,
|
|
861
|
-
...(extApplied.undoSnapshot !== undefined ? { undoSnapshot: extApplied.undoSnapshot } : {}),
|
|
862
|
-
};
|
|
863
|
-
proposal.status = 'applied';
|
|
864
|
-
proposal.error = undefined;
|
|
865
|
-
await persist(target);
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
submitting = false;
|
|
869
|
-
}
|
|
870
|
-
const installation = workspace.installedPlugins.find(item => item.manifest.id === action.pluginId);
|
|
871
|
-
const toolDef =
|
|
872
|
-
installation?.manifest.manifestVersion === 2
|
|
873
|
-
? installation.manifest.assistantTools?.find(tool => tool.name === action.toolName)
|
|
874
|
-
: undefined;
|
|
875
|
-
if (!installation || !toolDef || !canPluginToolExecute(installation, toolDef, !!workspace.workspace?.readOnly))
|
|
876
|
-
throw new Error('插件已停用、未授权或受当前工作区策略限制,无法执行此操作');
|
|
877
|
-
proposal.status = 'applying';
|
|
878
|
-
await persist(target);
|
|
879
|
-
submitting = true;
|
|
880
|
-
const output = await workspace.invokePluginAssistantTool(action.pluginId, action.toolName, parsedArgs);
|
|
881
|
-
proposal.applied = {
|
|
882
|
-
before: '',
|
|
883
|
-
after: JSON.stringify(output ?? null, null, 2),
|
|
884
|
-
hash: action.toolName,
|
|
885
|
-
fileId: action.pluginId,
|
|
886
|
-
};
|
|
887
|
-
proposal.status = 'applied';
|
|
888
|
-
proposal.error = undefined;
|
|
889
|
-
await persist(target);
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
const acceptance = apply ? proposal.preview : undefined;
|
|
893
|
-
if (apply && !acceptance) throw new Error('请先查看最新差异');
|
|
894
|
-
if (apply) {
|
|
895
|
-
proposal.status = 'applying';
|
|
896
|
-
await persist(target);
|
|
897
|
-
submitting = true;
|
|
898
|
-
}
|
|
899
|
-
const result = await workspace.reviewAssistantProposal(expected, proposal, acceptance, false, undefined, !!target?.external);
|
|
900
|
-
if (result.status === 'saved') {
|
|
901
|
-
proposal.status = 'applied'; proposal.applied = result.applied; proposal.error = undefined;
|
|
902
|
-
} else {
|
|
903
|
-
proposal.preview = result.preview;
|
|
904
|
-
proposal.status = result.status === 'conflict' ? 'conflicted' : 'ready';
|
|
905
|
-
proposal.error = result.status === 'stale' ? (result.preview ? '文档已变化,请审阅更新后的差异再应用' : '文档在保存时变化,请重新查看差异')
|
|
906
|
-
: result.status === 'conflict' ? '修改存在重叠,原文与建议均已保留' : undefined;
|
|
907
|
-
}
|
|
908
|
-
await persist(target);
|
|
909
|
-
if (target?.external && proposal.id === target.id) await transport.recordExternalResult?.(target);
|
|
910
|
-
} catch (reason) {
|
|
911
|
-
if (proposal.applied) {
|
|
912
|
-
proposal.status = 'applied';
|
|
913
|
-
proposal.error = `内容已保存,会话记录保存失败:${String(reason)}`;
|
|
914
|
-
} else {
|
|
915
|
-
proposal.status = submitting ? 'unknown' : originalStatus;
|
|
916
|
-
proposal.error = String(reason);
|
|
917
|
-
}
|
|
918
|
-
error.value = proposal.error;
|
|
919
|
-
try { await persist(target); } catch { /* Keep the in-memory result visible. */ }
|
|
920
|
-
} finally { applying.value = false; }
|
|
921
|
-
}
|
|
922
|
-
async function publishSuggestions(proposal: AssistantProposal) {
|
|
923
|
-
if (busy.value || applying.value || proposal.kind !== 'edit' || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
924
|
-
if (isDataTableFilePath(proposal.path)) { error.value = '数据表修改请在助手中查看差异并应用'; return; }
|
|
925
|
-
if (proposal.fileId && managed(proposal.fileId)) { error.value = '此文档正由协作会话管理,暂不支持建议模式'; return; }
|
|
926
|
-
applying.value = true;
|
|
927
|
-
const target = session.value;
|
|
928
|
-
try {
|
|
929
|
-
await useSuggestionStore().publish(proposal);
|
|
930
|
-
proposal.suggestionGroupId = proposal.id;
|
|
931
|
-
await persist(target);
|
|
932
|
-
error.value = '';
|
|
933
|
-
} catch (reason) { error.value = String(reason); }
|
|
934
|
-
finally { applying.value = false; }
|
|
935
|
-
}
|
|
936
|
-
async function verify(proposal: AssistantProposal) {
|
|
937
|
-
if (applying.value || busy.value || !proposal.preview) return;
|
|
938
|
-
applying.value = true; error.value = '';
|
|
939
|
-
const target = session.value;
|
|
940
|
-
try {
|
|
941
|
-
const expected = scope();
|
|
942
|
-
if (expected.id !== proposal.workspaceId) throw new Error('工作区已切换');
|
|
943
|
-
const current = await runtime.adapter.refresh();
|
|
944
|
-
if (current.id !== expected.id || current.path !== expected.path) throw new Error('工作区已切换');
|
|
945
|
-
if (['delete', 'rename', 'move'].includes(proposal.kind)) {
|
|
946
|
-
const file = current.files.find(file => file.id === proposal.fileId);
|
|
947
|
-
if (!file) throw new Error('原文件已不存在,无法确认是否由此次操作移除;请核对回收站,保留此记录');
|
|
948
|
-
const disk = await runtime.adapter.read(file.path);
|
|
949
|
-
if (proposal.kind !== 'delete' && file.path === proposal.preview.destination && disk.hash === proposal.preview.diskHash) {
|
|
950
|
-
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
951
|
-
proposal.status = 'applied'; proposal.error = undefined;
|
|
952
|
-
} else if (file.path === proposal.preview.path && disk.hash === proposal.preview.diskHash) {
|
|
953
|
-
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次文件操作,请重新审阅';
|
|
954
|
-
} else throw new Error('文件位置或内容已变化,请人工核对;不自动重试');
|
|
955
|
-
await persist(target);
|
|
956
|
-
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
957
|
-
return;
|
|
958
|
-
}
|
|
959
|
-
const file = current.files.find(file => proposal.kind === 'edit' ? file.id === proposal.fileId : file.path === proposal.path);
|
|
960
|
-
if (!file || current.id !== expected.id || current.path !== expected.path) throw new Error('原目标不存在,请保留建议并核对工作区');
|
|
961
|
-
const disk = await runtime.adapter.read(file.path);
|
|
962
|
-
if (disk.content === proposal.preview.after) {
|
|
963
|
-
proposal.applied = { before: proposal.preview.before, after: disk.content, hash: disk.hash, fileId: file.id };
|
|
964
|
-
proposal.status = 'applied'; proposal.error = undefined;
|
|
965
|
-
} else if (proposal.kind === 'edit' && disk.hash === proposal.preview.diskHash) {
|
|
966
|
-
proposal.status = 'ready'; proposal.preview = undefined; proposal.error = '未发现此次写入,请重新审阅';
|
|
967
|
-
} else throw new Error('磁盘内容与写入前后均不同,请打开文档人工核对;不自动重试');
|
|
968
|
-
await persist(target);
|
|
969
|
-
if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target);
|
|
970
|
-
} catch (reason) { error.value = String(reason); }
|
|
971
|
-
finally { applying.value = false; }
|
|
972
|
-
}
|
|
973
|
-
async function reject(proposal: AssistantProposal) {
|
|
974
|
-
if (applying.value || busy.value || !['ready', 'conflicted'].includes(proposal.status)) return;
|
|
975
|
-
proposal.status = 'rejected';
|
|
976
|
-
const target = session.value;
|
|
977
|
-
try { await persist(target); if (target?.external && proposal.id === target.id) await transport?.recordExternalResult?.(target); }
|
|
978
|
-
catch (reason) { error.value = String(reason); }
|
|
979
|
-
}
|
|
980
|
-
async function undo(proposal: AssistantProposal) {
|
|
981
|
-
if (!proposal.applied || applying.value || busy.value) return;
|
|
982
|
-
if (proposal.kind === 'extension' || proposal.kind === 'plugin') {
|
|
983
|
-
const undoExt = resolveAssistantExtension(runtime)?.undoProposal;
|
|
984
|
-
if (!undoExt) return;
|
|
985
|
-
applying.value = true;
|
|
986
|
-
error.value = '';
|
|
987
|
-
try {
|
|
988
|
-
await undoExt(proposal);
|
|
989
|
-
} catch (reason) {
|
|
990
|
-
error.value = String(reason);
|
|
991
|
-
} finally {
|
|
992
|
-
applying.value = false;
|
|
993
|
-
}
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
|
-
if (!['edit', 'create'].includes(proposal.kind)) return;
|
|
997
|
-
if (proposal.kind === 'create' && isDataTableFilePath(proposal.path)) return;
|
|
998
|
-
const reply = session.value?.messages.find(message => message.id === proposal.runId);
|
|
999
|
-
if (!reply) return;
|
|
1000
|
-
const reversed: AssistantProposal = { id: crypto.randomUUID(), runId: reply.id, workspaceId: proposal.workspaceId,
|
|
1001
|
-
kind: 'edit', fileId: proposal.applied.fileId, path: proposal.path, base: proposal.applied.after,
|
|
1002
|
-
content: proposal.applied.before, reason: `撤回内容:${proposal.reason}`, status: 'ready' };
|
|
1003
|
-
reply.proposals!.push(reversed);
|
|
1004
|
-
const current = reply.proposals!.at(-1)!;
|
|
1005
|
-
current.execution = 'direct';
|
|
1006
|
-
await executeChange(current, session.value!, scope(), new AbortController().signal);
|
|
1007
|
-
}
|
|
1008
541
|
async function deleteSession(id: string) {
|
|
1009
542
|
if (!transport || busy.value || applying.value) return;
|
|
1010
543
|
await persistTask.catch(() => {});
|
|
@@ -1040,7 +573,7 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
1040
573
|
externalSessions.value = externalSessions.value.filter(item => item.id !== target.id);
|
|
1041
574
|
}
|
|
1042
575
|
watch(() => workspace.workspace ? `${workspace.workspace.id}:${workspace.workspace.path}:${workspace.assistantEpoch}` : '', async key => {
|
|
1043
|
-
stop();
|
|
576
|
+
stop(); abortModels(); const epoch = ++generation;
|
|
1044
577
|
if (displayMode.value === 'fullscreen') setDisplayMode('sidebar');
|
|
1045
578
|
busy.value = false; prompt.value = ''; files.value = []; attachments.value = []; pluginContextKeys.value = []; selection.value = null; session.value = null; sessions.value = [];
|
|
1046
579
|
replyTarget.value = null;
|
|
@@ -1101,7 +634,7 @@ export function createAssistantState(inline = false, background?: BackgroundAssi
|
|
|
1101
634
|
onScopeDispose(() => {
|
|
1102
635
|
if (!inline && !background) workspace.setPluginAiRunner?.(undefined);
|
|
1103
636
|
stop();
|
|
1104
|
-
|
|
637
|
+
abortModels();
|
|
1105
638
|
});
|
|
1106
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,
|
|
1107
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,
|