@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.5
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/CHANGELOG.md +32 -0
- package/README.md +102 -18
- package/README.zh.md +102 -18
- package/assets/agent-bot.ico +0 -0
- package/assets/roboto-mono-OFL.txt +93 -0
- package/assets/roboto-mono-latin.woff2 +0 -0
- package/assets/workspace-drafts.js +88 -0
- package/assets/workspace-sessions.js +2676 -243
- package/assets/workspace.css +553 -44
- package/assets/workspace.js +3429 -327
- package/dist/cli/SelfUpdateObserver.js +124 -0
- package/dist/cli/SelfUpdateObserver.js.map +1 -0
- package/dist/cli/SelfUpdateRunner.js +267 -70
- package/dist/cli/SelfUpdateRunner.js.map +1 -1
- package/dist/cli/SelfUpdater.js +54 -15
- package/dist/cli/SelfUpdater.js.map +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +6 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +85 -6
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexEventMapper.js +29 -5
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +3 -0
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/feishu/CardRenderer.js +45 -13
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/ConsoleFeishuClient.js +4 -0
- package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +2 -14
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +9 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +51 -22
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +47 -12
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +11 -6
- package/dist/local-files/DiagramPreview.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +106 -14
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LiveMarkup.js +104 -0
- package/dist/local-files/LiveMarkup.js.map +1 -0
- package/dist/local-files/LocalFileViewerServer.js +141 -122
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownExport.js +54 -0
- package/dist/local-files/MarkdownExport.js.map +1 -0
- package/dist/local-files/PreviewCodeFont.js +11 -0
- package/dist/local-files/PreviewCodeFont.js.map +1 -0
- package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
- package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
- package/dist/local-files/ToolCommandDisplay.js +111 -0
- package/dist/local-files/ToolCommandDisplay.js.map +1 -0
- package/dist/local-files/TurnPreviewPage.js +53 -276
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WorkspaceFileEvents.js +206 -0
- package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +79 -3
- package/dist/local-files/WorkspaceFiles.js.map +1 -1
- package/dist/local-files/WorkspaceImages.js +43 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +24 -6
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +1153 -104
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +129 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +15 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +31 -22
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +335 -113
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/proxy/TaskMetadata.js +86 -0
- package/dist/proxy/TaskMetadata.js.map +1 -0
- package/dist/scheduling/ScheduleCards.js +10 -4
- package/dist/scheduling/ScheduleCards.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +4 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduledTaskStore.js +53 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +19 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +213 -23
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +157 -39
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/TurnToolText.js +172 -0
- package/dist/state/TurnToolText.js.map +1 -0
- package/dist/state/migrations.js +4 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +9 -6
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/terminal/TerminalPage.js +5 -0
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/updates/AutomaticUpdatePreparer.js +63 -12
- package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
- package/dist/updates/ManualUpdateController.js +7 -2
- package/dist/updates/ManualUpdateController.js.map +1 -1
- package/dist/utils/promptAttachments.js +22 -0
- package/dist/utils/promptAttachments.js.map +1 -0
- package/dist/utils/promptQuotes.js +47 -0
- package/dist/utils/promptQuotes.js.map +1 -0
- package/dist/utils/toolTimestamp.js +6 -0
- package/dist/utils/toolTimestamp.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +23 -2
- package/src/cli/SelfUpdateObserver.ts +111 -0
- package/src/cli/SelfUpdateRunner.ts +271 -85
- package/src/cli/SelfUpdater.ts +53 -16
- package/src/cli/controlProtocol.ts +1 -0
- package/src/cli/help.ts +6 -0
- package/src/cli.ts +71 -5
- package/src/codex/CodexEventMapper.ts +25 -5
- package/src/codex/CodexRuntime.ts +4 -0
- package/src/feishu/CardRenderer.ts +48 -13
- package/src/feishu/ConsoleFeishuClient.ts +6 -1
- package/src/feishu/FeishuMarkdown.ts +2 -14
- package/src/feishu/FeishuMessageClient.ts +10 -0
- package/src/feishu/FeishuTurnPresenter.ts +49 -16
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +47 -12
- package/src/local-files/DiagramPreview.ts +11 -6
- package/src/local-files/GitDiffPreview.ts +107 -15
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +128 -125
- package/src/local-files/MarkdownExport.ts +54 -0
- package/src/local-files/PreviewCodeFont.ts +12 -0
- package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
- package/src/local-files/ToolCommandDisplay.ts +104 -0
- package/src/local-files/TurnPreviewPage.ts +58 -261
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +35 -0
- package/src/local-files/WorkspacePage.ts +24 -6
- package/src/local-files/WorkspaceSessions.ts +1057 -111
- package/src/local-files/WorkspaceTimeline.ts +135 -0
- package/src/presentation/OutboundRouter.ts +18 -4
- package/src/presentation/TurnStateReducer.ts +30 -19
- package/src/presentation/turnViewTypes.ts +3 -1
- package/src/proxy/ProxySessionController.ts +336 -96
- package/src/proxy/TaskMetadata.ts +81 -0
- package/src/runtime/types.ts +2 -1
- package/src/scheduling/ScheduleCards.ts +10 -4
- package/src/scheduling/ScheduleCommand.ts +4 -0
- package/src/scheduling/ScheduledTaskStore.ts +56 -9
- package/src/scheduling/types.ts +27 -4
- package/src/state/StateStore.ts +227 -24
- package/src/state/TurnPreviewJournal.ts +155 -38
- package/src/state/TurnToolText.ts +156 -0
- package/src/state/migrations.ts +4 -0
- package/src/supervision/SafeRestartNotifier.ts +9 -6
- package/src/terminal/TerminalPage.ts +5 -0
- package/src/updates/AutomaticUpdatePreparer.ts +52 -11
- package/src/updates/ManualUpdateController.ts +8 -3
- package/src/utils/promptAttachments.ts +27 -0
- package/src/utils/promptQuotes.ts +48 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -17,13 +17,16 @@ import { formatGroupNameDate, formatNewGroupName, parseTaskNameFromGroupName, }
|
|
|
17
17
|
import { normalizeFeishuPostText } from "../feishu/InboundText.js";
|
|
18
18
|
import { RECENT_CONTEXT_LIMIT, RECENT_CONTEXT_IMAGE_LIMIT, RECENT_CONTEXT_TEXT_LIMIT, recentContextPrompt } from "../feishu/RecentMessageContext.js";
|
|
19
19
|
import { allowsFeishuUser } from "../feishu/ownerAccess.js";
|
|
20
|
-
import { scheduleCommandSchema } from "../scheduling/types.js";
|
|
20
|
+
import { scheduleCommandSchema, scheduleDisplayPrompt } from "../scheduling/types.js";
|
|
21
|
+
import { appendPromptQuotes, promptQuoteInstruction } from "../utils/promptQuotes.js";
|
|
22
|
+
import { appendDownloadedFiles, defaultResourcePromptFromCounts, queuedPromptContent } from "../utils/promptAttachments.js";
|
|
21
23
|
import { renderSettingsCard } from "../feishu/SettingsCard.js";
|
|
22
24
|
import { renderSchedule, renderScheduleList, renderScheduleForm } from "../scheduling/ScheduleCards.js";
|
|
23
25
|
import { classifyFileContent } from "../local-files/LocalFileViewerServer.js";
|
|
24
26
|
import { errorLogValue } from "../logging/errorLogValue.js";
|
|
25
27
|
import { createTurnViewState, hydrateTurnViewState } from "../presentation/TurnStateReducer.js";
|
|
26
28
|
import { buildTurnGraphRows } from "../presentation/turnGraph.js";
|
|
29
|
+
import { splitMarkdown } from "../presentation/splitMarkdown.js";
|
|
27
30
|
import { displayRuntimeError, isResponseContinuationError } from "../runtime/responseErrors.js";
|
|
28
31
|
import { TurnNotSubmittedError, TurnStoppedBeforeSubmissionError } from "../runtime/submissionErrors.js";
|
|
29
32
|
import { isActiveShellCommandJob, ShellCommandJobManager, } from "../shell/ShellCommandJobManager.js";
|
|
@@ -326,10 +329,13 @@ export class ProxySessionController {
|
|
|
326
329
|
const currentId = this.store.getUserContext(message.contextKey)?.currentSessionId;
|
|
327
330
|
if (!this.store.inboundMessages.claim(message, currentId, currentId ? this.store.executionGeneration(currentId) : 0))
|
|
328
331
|
return;
|
|
329
|
-
if (this.
|
|
332
|
+
if (!this.acceptingInboundMessages)
|
|
330
333
|
return;
|
|
331
334
|
await this.processAcceptedMessage(message);
|
|
332
335
|
}
|
|
336
|
+
get acceptingInboundMessages() {
|
|
337
|
+
return !this.inboundPaused && !this.recoveryClosed;
|
|
338
|
+
}
|
|
333
339
|
get pendingInboundMessages() {
|
|
334
340
|
return this.inboundInFlight.size + this.inboundActionsInFlight;
|
|
335
341
|
}
|
|
@@ -1208,38 +1214,49 @@ export class ProxySessionController {
|
|
|
1208
1214
|
: undefined;
|
|
1209
1215
|
return { session, snapshot, remote };
|
|
1210
1216
|
}
|
|
1211
|
-
async controlSetTaskTitle(localSessionId, title) {
|
|
1217
|
+
async controlSetTaskTitle(localSessionId, title, source = "cli") {
|
|
1212
1218
|
const normalizedTitle = normalizeTaskTitle(title);
|
|
1213
1219
|
if (!normalizedTitle)
|
|
1214
1220
|
throw new Error("The task title cannot be empty.");
|
|
1215
1221
|
const record = this.store.getSession(localSessionId);
|
|
1216
|
-
if (!record || record.status === "closed")
|
|
1222
|
+
if (!record || (record.status === "closed" && source === "cli"))
|
|
1217
1223
|
throw new Error(`Task not found: ${localSessionId}`);
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1224
|
+
if (record.status !== "closed") {
|
|
1225
|
+
const loaded = await this.loadSession(record);
|
|
1226
|
+
if (loaded.runtime.setTitle)
|
|
1227
|
+
await loaded.runtime.setTitle(record.localSessionId, normalizedTitle);
|
|
1228
|
+
else
|
|
1229
|
+
loaded.session.title = normalizedTitle;
|
|
1230
|
+
}
|
|
1223
1231
|
this.store.updateRuntimeSession(record.localSessionId, { title: normalizedTitle });
|
|
1224
1232
|
this.outbound.updateSessionTitle(record.localSessionId, normalizedTitle);
|
|
1225
1233
|
this.store.audit(record.contextKey, "session_title_changed", {
|
|
1226
1234
|
localSessionId: record.localSessionId,
|
|
1227
1235
|
title: normalizedTitle,
|
|
1228
|
-
source
|
|
1236
|
+
source,
|
|
1229
1237
|
});
|
|
1230
1238
|
return `Task title changed to: ${normalizedTitle}`;
|
|
1231
1239
|
}
|
|
1232
1240
|
async controlSendTaskPrompt(localSessionId, text, workspace) {
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1241
|
+
const images = workspace?.localImagePaths;
|
|
1242
|
+
const files = workspace?.files;
|
|
1243
|
+
const quotes = workspace?.quotes;
|
|
1244
|
+
const queued = workspace?.queuedPrompt;
|
|
1245
|
+
const promptText = queued ? queued.displayPrompt ?? queued.text
|
|
1246
|
+
: text.trim() || promptQuoteInstruction(quotes) || (files?.length ? defaultResourcePromptFromCounts(images?.length ?? 0, files.length) : "");
|
|
1247
|
+
const modelPrompt = queued?.text ?? appendPromptQuotes(promptText, quotes);
|
|
1248
|
+
const echoedPrompt = files?.length ? `${promptText}\n\n附件:${files.map((file) => file.fileName).join("、")}` : promptText;
|
|
1249
|
+
if (!modelPrompt.trim() && !images?.length)
|
|
1235
1250
|
throw new Error("The Prompt cannot be empty.");
|
|
1236
1251
|
const record = this.store.getSession(localSessionId);
|
|
1237
1252
|
if (!record || record.status === "closed")
|
|
1238
1253
|
throw new Error(`Task not found: ${localSessionId}`);
|
|
1239
1254
|
const runtime = this.runtimes.forAgent(record.agentName);
|
|
1240
1255
|
const activeTurnId = runtime.getSession(localSessionId)?.activeTurnId;
|
|
1256
|
+
const expectedTurnId = workspace?.expectedTurnId;
|
|
1257
|
+
assertWorkspaceSteerTurn(expectedTurnId, activeTurnId);
|
|
1241
1258
|
const routedContextKey = this.outbound.getSessionContextKey(localSessionId);
|
|
1242
|
-
const responseContextKey = (activeTurnId ? this.store.getTurnContextKey(activeTurnId) ?? routedContextKey : undefined)
|
|
1259
|
+
const responseContextKey = queued?.contextKey ?? (activeTurnId ? this.store.getTurnContextKey(activeTurnId) ?? routedContextKey : undefined)
|
|
1243
1260
|
?? (record.lastTurnId ? this.store.getTurnContextKey(record.lastTurnId) : undefined)
|
|
1244
1261
|
?? routedContextKey
|
|
1245
1262
|
?? record.contextKey;
|
|
@@ -1250,35 +1267,48 @@ export class ProxySessionController {
|
|
|
1250
1267
|
? turnViewSnapshot(this.store.getTurnSnapshot(activeTurnId))
|
|
1251
1268
|
: undefined;
|
|
1252
1269
|
const routedReplyTarget = this.outbound.getSessionReplyTarget(localSessionId);
|
|
1253
|
-
const existingReplyTarget =
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1270
|
+
const existingReplyTarget = queued ? (queued.replyMessageId ? { messageId: queued.replyMessageId, replyInThread: true } : undefined)
|
|
1271
|
+
: activeSnapshot?.replyTarget
|
|
1272
|
+
?? (activeTurnId ? routedReplyTarget : undefined)
|
|
1273
|
+
?? lastSnapshot?.replyTarget
|
|
1274
|
+
?? routedReplyTarget;
|
|
1275
|
+
const threaded = isThreadContextKey(responseContextKey);
|
|
1276
|
+
if (threaded && !existingReplyTarget && !workspace) {
|
|
1258
1277
|
throw new Error("Could not resolve the target task's thread reply location. The Prompt was not sent.");
|
|
1259
1278
|
}
|
|
1260
1279
|
const scopedRecord = this.store.getSessionForContext(localSessionId, responseContextKey)
|
|
1261
1280
|
?? { ...record, contextKey: responseContextKey };
|
|
1262
1281
|
const previous = this.messageQueues.get(responseContextKey) ?? Promise.resolve();
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1282
|
+
const send = async () => {
|
|
1283
|
+
if (queued) {
|
|
1284
|
+
const current = this.store.getQueuedPrompt(localSessionId, queued.promptId);
|
|
1285
|
+
if (!current || current.text !== queued.text || current.displayPrompt !== queued.displayPrompt) {
|
|
1286
|
+
throw new TurnNotSubmittedError("排队消息已被修改或离开队列。");
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
this.outbound.registerSession(scopedRecord.localSessionId, responseContextKey, scopedRecord.title, scopedRecord.cwd, this.agentLabel(scopedRecord.agentName), scopedRecord.model, scopedRecord.modelProvider, scopedRecord.reasoningEffort);
|
|
1265
1290
|
if (workspace && this.store.getSession(localSessionId)?.status === "closed")
|
|
1266
1291
|
throw new Error("任务已归档。");
|
|
1267
|
-
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
|
|
1292
|
+
assertWorkspaceSteerTurn(expectedTurnId, runtime.getSession(localSessionId)?.activeTurnId);
|
|
1293
|
+
const post = () => this.outbound.withReplyTarget(responseContextKey, existingReplyTarget, () => images?.length
|
|
1294
|
+
? this.outbound.sendPromptImages(responseContextKey, echoedPrompt, images)
|
|
1295
|
+
: this.outbound.sendText(responseContextKey, echoedPrompt));
|
|
1296
|
+
const promptMessageId = workspace ? undefined : await post();
|
|
1297
|
+
const turnReplyTarget = threaded
|
|
1271
1298
|
? promptMessageId
|
|
1272
1299
|
? { messageId: promptMessageId, replyInThread: true }
|
|
1273
1300
|
: existingReplyTarget
|
|
1274
1301
|
: undefined;
|
|
1275
|
-
await this.promptSession(scopedRecord, responseContextKey,
|
|
1302
|
+
await this.promptSession(scopedRecord, responseContextKey, !queued && files?.length ? appendDownloadedFiles(modelPrompt, files) : modelPrompt, queued?.messageId, turnReplyTarget, images, queued?.displayPrompt ?? (files?.length || quotes?.length ? promptText : undefined), workspace);
|
|
1303
|
+
if (workspace && !queued?.messageId)
|
|
1304
|
+
this.deliverWorkspacePrompt(post, localSessionId, workspace, !threaded || Boolean(existingReplyTarget));
|
|
1276
1305
|
this.store.audit(responseContextKey, "task_prompt_sent", {
|
|
1277
1306
|
localSessionId,
|
|
1278
1307
|
source: workspace ? "workspace" : "cli",
|
|
1279
1308
|
requestId: workspace?.requestId,
|
|
1280
1309
|
});
|
|
1281
|
-
}
|
|
1310
|
+
};
|
|
1311
|
+
const next = previous.catch(() => undefined).then(() => queued ? this.serializeQueuedPromptStart(localSessionId, send) : send());
|
|
1282
1312
|
this.messageQueues.set(responseContextKey, next);
|
|
1283
1313
|
try {
|
|
1284
1314
|
await next;
|
|
@@ -1287,7 +1317,64 @@ export class ProxySessionController {
|
|
|
1287
1317
|
if (this.messageQueues.get(responseContextKey) === next)
|
|
1288
1318
|
this.messageQueues.delete(responseContextKey);
|
|
1289
1319
|
}
|
|
1290
|
-
|
|
1320
|
+
const target = record.title ?? record.remoteSessionId ?? record.localSessionId;
|
|
1321
|
+
return workspace ? `The Prompt was submitted to the task: ${target}`
|
|
1322
|
+
: `The Prompt was posted to the original chat and submitted to the task: ${target}`;
|
|
1323
|
+
}
|
|
1324
|
+
async controlSendWorkspaceQueuedPrompt(prompt, submission) {
|
|
1325
|
+
const scheduled = this.store.schedules.getRun(prompt.promptId);
|
|
1326
|
+
const requestId = prompt.promptId.startsWith("workspace:") ? prompt.promptId.slice("workspace:".length)
|
|
1327
|
+
: scheduled ? scheduled.id.slice("schedule_run_".length) : submission.requestId;
|
|
1328
|
+
let claimed = false, submitting = false;
|
|
1329
|
+
let finishDispatch;
|
|
1330
|
+
try {
|
|
1331
|
+
await this.controlSendTaskPrompt(prompt.localSessionId, prompt.displayPrompt ?? prompt.text, {
|
|
1332
|
+
...submission, requestId, queuedPrompt: prompt, localImagePaths: prompt.localImagePaths,
|
|
1333
|
+
onClaim: () => {
|
|
1334
|
+
if (claimed)
|
|
1335
|
+
return;
|
|
1336
|
+
if (scheduled)
|
|
1337
|
+
this.assertScheduleTarget(this.store.schedules.require(scheduled.jobId));
|
|
1338
|
+
if (!this.store.claimQueuedPromptForImmediateSend(prompt))
|
|
1339
|
+
throw new TurnNotSubmittedError("排队消息已被修改或离开队列。");
|
|
1340
|
+
claimed = true;
|
|
1341
|
+
finishDispatch = this.store.trackQueuedPromptDispatch(prompt);
|
|
1342
|
+
},
|
|
1343
|
+
onSubmitting: () => {
|
|
1344
|
+
submitting = true;
|
|
1345
|
+
submission.onSubmitting();
|
|
1346
|
+
},
|
|
1347
|
+
});
|
|
1348
|
+
if (scheduled)
|
|
1349
|
+
this.store.schedules.finish(scheduled.id, "cancelled", "本次排队消息已改为手动发送。");
|
|
1350
|
+
}
|
|
1351
|
+
catch (error) {
|
|
1352
|
+
const known = error instanceof TurnNotSubmittedError ? error
|
|
1353
|
+
: error instanceof Error && error.cause instanceof TurnNotSubmittedError ? new TurnNotSubmittedError(error.message) : undefined;
|
|
1354
|
+
if (claimed && (!submitting || known))
|
|
1355
|
+
this.store.restoreQueuedPromptAfterImmediateSend(prompt);
|
|
1356
|
+
else if (claimed && scheduled)
|
|
1357
|
+
this.store.schedules.finish(scheduled.id, "unknown", "手动发送的提交结果待核实。");
|
|
1358
|
+
throw known ?? error;
|
|
1359
|
+
}
|
|
1360
|
+
finally {
|
|
1361
|
+
finishDispatch?.();
|
|
1362
|
+
if (claimed)
|
|
1363
|
+
void this.refreshPromptQueueCards(prompt.localSessionId).catch(error => {
|
|
1364
|
+
this.logger.warn({ error, promptId: prompt.promptId }, "Failed to refresh the prompt queue after an immediate send.");
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
deliverWorkspacePrompt(post, sessionId, request, routed) {
|
|
1369
|
+
const details = { sessionId, requestId: request.requestId };
|
|
1370
|
+
if (!routed) {
|
|
1371
|
+
this.logger.warn(details, "Workspace Prompt submitted locally without a Feishu thread reply target.");
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
this.inboundActionsInFlight += 1;
|
|
1375
|
+
void Promise.resolve().then(post).then(() => request.onPosted()).catch((error) => {
|
|
1376
|
+
this.logger.warn({ ...details, error }, "Failed to deliver a Workspace Prompt to Feishu.");
|
|
1377
|
+
}).finally(() => { this.inboundActionsInFlight -= 1; });
|
|
1291
1378
|
}
|
|
1292
1379
|
async controlCreateTaskGroup(localSessionId, requestedTitle, userOpenId, requestedProjectCwd, forceProjectless = false, requestedAgentName) {
|
|
1293
1380
|
const source = this.store.getSession(localSessionId);
|
|
@@ -1373,6 +1460,33 @@ export class ProxySessionController {
|
|
|
1373
1460
|
: {};
|
|
1374
1461
|
return this.outbound.withReplyTarget(contextKey, replyTarget, () => this.createSession(contextKey, agentName, cwd, true, false, undefined, undefined, requestedTitle, settings));
|
|
1375
1462
|
}
|
|
1463
|
+
controlWorkspaceAgents() {
|
|
1464
|
+
const agents = Object.entries(this.config.agents).filter(([, agent]) => agent.kind === "app-server")
|
|
1465
|
+
.map(([name, agent]) => ({ name, title: agent.title }));
|
|
1466
|
+
return { agents, defaultAgent: agents.find(({ name }) => name === this.config.defaults.agent)?.name ?? agents[0]?.name };
|
|
1467
|
+
}
|
|
1468
|
+
async controlWorkspaceDraftSettings(agentName) {
|
|
1469
|
+
const agent = this.ensureAgent(agentName);
|
|
1470
|
+
if (agent.kind !== "app-server")
|
|
1471
|
+
throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1472
|
+
const { model, modelProvider, reasoningEffort } = agent.defaults ?? {};
|
|
1473
|
+
const models = await this.runtimes.forAgent(agentName).listModels(modelProvider, model);
|
|
1474
|
+
return { model, provider: modelProvider, thinking: reasoningEffort, models };
|
|
1475
|
+
}
|
|
1476
|
+
controlCreateWorkspaceTask(localSessionId, owner, title, agentName, cwd, model, reasoningEffort) {
|
|
1477
|
+
const agent = this.ensureAgent(agentName);
|
|
1478
|
+
if (agent.kind !== "app-server")
|
|
1479
|
+
throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1480
|
+
const settings = model
|
|
1481
|
+
? { ...agent.defaults, model, reasoningEffort }
|
|
1482
|
+
: mergeExecutionSettings(agent.defaults ?? {}, { reasoningEffort });
|
|
1483
|
+
const initialTitle = normalizeTaskTitle(title);
|
|
1484
|
+
const contextKey = `open_id:${owner}`;
|
|
1485
|
+
const root = cwd ?? createProjectlessWorkspace({ prompt: initialTitle }).cwd;
|
|
1486
|
+
this.store.createSession({ localSessionId, contextKey, agentName, cwd: root, status: "ready" });
|
|
1487
|
+
this.store.updateRuntimeSession(localSessionId, { ...settings, title: initialTitle, runtimeKind: this.runtimes.forAgent(agentName).kind });
|
|
1488
|
+
return this.store.getSession(localSessionId);
|
|
1489
|
+
}
|
|
1376
1490
|
async controlForkTask(localSessionId) {
|
|
1377
1491
|
const source = this.requireControlSession(localSessionId);
|
|
1378
1492
|
const contextKey = this.controlSessionContextKey(source);
|
|
@@ -1391,6 +1505,14 @@ export class ProxySessionController {
|
|
|
1391
1505
|
task: this.store.getSession(forked.record.localSessionId) ?? forked.record,
|
|
1392
1506
|
};
|
|
1393
1507
|
}
|
|
1508
|
+
async controlForkWorkspaceTask(localSessionId, turnId) {
|
|
1509
|
+
const source = this.requireControlSession(localSessionId);
|
|
1510
|
+
const plan = this.prepareForkSessionFromTurn(source, turnId, undefined, "当前任务");
|
|
1511
|
+
const origin = this.store.getTurnRuntimeOrigin(turnId);
|
|
1512
|
+
if (origin?.agentName === source.agentName)
|
|
1513
|
+
plan.remoteSessionId = origin.remoteSessionId;
|
|
1514
|
+
return (await this.forkSessionIntoContext(this.controlSessionContextKey(source), plan, false)).record;
|
|
1515
|
+
}
|
|
1394
1516
|
async controlSwitchTask(localSessionId, targetLocalSessionId, previous = false) {
|
|
1395
1517
|
const anchor = this.requireControlSession(localSessionId);
|
|
1396
1518
|
const contextKey = this.controlSessionContextKey(anchor);
|
|
@@ -1404,9 +1526,21 @@ export class ProxySessionController {
|
|
|
1404
1526
|
return;
|
|
1405
1527
|
await this.scheduleNextQueuedPrompt(localSessionId);
|
|
1406
1528
|
}
|
|
1407
|
-
async notifySchedule(job, text) {
|
|
1529
|
+
async notifySchedule(job, text, images) {
|
|
1408
1530
|
const target = job.replyMessageId ? { messageId: job.replyMessageId, replyInThread: true } : undefined;
|
|
1409
|
-
await this.outbound.withReplyTarget(job.contextKey, target, () =>
|
|
1531
|
+
await this.outbound.withReplyTarget(job.contextKey, target, async () => {
|
|
1532
|
+
const parts = splitMarkdown(text);
|
|
1533
|
+
if (images?.length) {
|
|
1534
|
+
const last = parts.pop() ?? "";
|
|
1535
|
+
for (const part of parts)
|
|
1536
|
+
await this.outbound.sendText(job.contextKey, part);
|
|
1537
|
+
await this.outbound.sendPromptImages(job.contextKey, last, images);
|
|
1538
|
+
}
|
|
1539
|
+
else {
|
|
1540
|
+
for (const part of parts)
|
|
1541
|
+
await this.outbound.sendText(job.contextKey, part);
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1410
1544
|
}
|
|
1411
1545
|
async controlSchedule(command, localSessionId) {
|
|
1412
1546
|
command = scheduleCommandSchema.parse(command);
|
|
@@ -1440,17 +1574,10 @@ export class ProxySessionController {
|
|
|
1440
1574
|
await this.outbound.withReplyTarget(job.contextKey, target, () => this.showSchedule(updated));
|
|
1441
1575
|
return updated;
|
|
1442
1576
|
}
|
|
1443
|
-
if (command.operation === "run") {
|
|
1444
|
-
this.
|
|
1445
|
-
const run = this.store.schedules.dispatch(job, Date.now(), Date.now(), { manual: true });
|
|
1446
|
-
await this.drainScheduledPrompts(job.localSessionId);
|
|
1447
|
-
return run;
|
|
1577
|
+
if (command.operation === "run" || command.operation === "resume" || command.operation === "pause" || command.operation === "delete") {
|
|
1578
|
+
return this.controlWorkspaceScheduleAction(job, command.operation);
|
|
1448
1579
|
}
|
|
1449
|
-
|
|
1450
|
-
throw new Error("无效的定时任务操作。");
|
|
1451
|
-
if (command.operation === "resume")
|
|
1452
|
-
this.assertScheduleTarget(job);
|
|
1453
|
-
return this.store.schedules.change(job.id, job.revision, command.operation);
|
|
1580
|
+
throw new Error("无效的定时任务操作。");
|
|
1454
1581
|
}
|
|
1455
1582
|
requireSettingsOwner(userId) {
|
|
1456
1583
|
if (!this.config.feishu.userOpenId || userId !== this.config.feishu.userOpenId) {
|
|
@@ -1519,13 +1646,33 @@ export class ProxySessionController {
|
|
|
1519
1646
|
}
|
|
1520
1647
|
await this.outbound.updateInteractiveCard(action.contextKey, messageId, renderSettingsCard(snapshot, action.contextKey, notice));
|
|
1521
1648
|
}
|
|
1522
|
-
|
|
1649
|
+
controlCreateWorkspaceSchedule(localSessionId, input, request, upload) {
|
|
1650
|
+
const task = this.requireControlSession(localSessionId);
|
|
1651
|
+
return this.createSchedule(input, localSessionId, this.controlSessionContextKey(task), this.controlSessionReplyTarget(task)?.messageId, request, upload);
|
|
1652
|
+
}
|
|
1653
|
+
controlEditWorkspaceSchedule(job, input) {
|
|
1654
|
+
this.assertScheduleTarget(job);
|
|
1655
|
+
const status = job.status === "paused" || job.status === "draft" ? job.status : "enabled";
|
|
1656
|
+
return this.store.schedules.edit(job.id, job.revision, input, undefined, status);
|
|
1657
|
+
}
|
|
1658
|
+
async controlWorkspaceScheduleAction(job, action) {
|
|
1659
|
+
if (action === "confirm" || action === "resume" || action === "run")
|
|
1660
|
+
this.assertScheduleTarget(job);
|
|
1661
|
+
if (action !== "run")
|
|
1662
|
+
return this.store.schedules.change(job.id, job.revision, action);
|
|
1663
|
+
const run = this.store.schedules.dispatch(job, Date.now(), Date.now(), { manual: true });
|
|
1664
|
+
await this.drainScheduledPrompts(job.localSessionId);
|
|
1665
|
+
return run;
|
|
1666
|
+
}
|
|
1667
|
+
createSchedule(input, localSessionId, contextKey, replyMessageId, enableRequest, upload) {
|
|
1523
1668
|
if (!this.config.feishu.userOpenId)
|
|
1524
1669
|
throw new Error("请先配置 Agent Bot 所有者,才能创建定时任务。");
|
|
1525
1670
|
this.requireSession(contextKey, localSessionId);
|
|
1526
1671
|
if (isThreadContextKey(contextKey) && !replyMessageId)
|
|
1527
1672
|
throw new Error("缺少话题回复位置,请在原话题中创建计划。");
|
|
1528
|
-
|
|
1673
|
+
if (enableRequest && !this.outbound.canRoute(contextKey))
|
|
1674
|
+
throw new Error("任务的原始会话不可用,无法创建定时计划。");
|
|
1675
|
+
return this.store.schedules.create(input, { localSessionId, contextKey, replyMessageId, ownerId: this.config.feishu.userOpenId }, undefined, enableRequest, upload);
|
|
1529
1676
|
}
|
|
1530
1677
|
assertScheduleTarget(job) {
|
|
1531
1678
|
if (job.ownerId !== this.config.feishu.userOpenId)
|
|
@@ -1598,7 +1745,11 @@ export class ProxySessionController {
|
|
|
1598
1745
|
const string = (key) => typeof form[key] === "string" ? form[key] : "";
|
|
1599
1746
|
const input = { name: string("name"), prompt: string("prompt"), timeZone: string("timeZone"),
|
|
1600
1747
|
maxDelayMinutes: Number(string("maxDelayMinutes")), catchUpMinutes: Number(string("catchUpMinutes")),
|
|
1748
|
+
...(string("startsAt").trim() ? { startsAt: string("startsAt") } : {}),
|
|
1749
|
+
...(string("endsAt").trim() ? { endsAt: string("endsAt") } : {}),
|
|
1601
1750
|
...(string("cron").trim() ? { cron: string("cron") } : {}), ...(string("at").trim() ? { at: string("at") } : {}) };
|
|
1751
|
+
if (job?.spec.prompt && job.spec.prompt.length > 1000 && !input.prompt.trim())
|
|
1752
|
+
input.prompt = job.spec.prompt;
|
|
1602
1753
|
const updated = job ? this.store.schedules.edit(job.id, job.revision, input)
|
|
1603
1754
|
: this.createSchedule(input, String(action.value.sessionId ?? ""), action.contextKey, replyTarget?.messageId);
|
|
1604
1755
|
return this.showSchedule(updated, messageId);
|
|
@@ -1616,23 +1767,48 @@ export class ProxySessionController {
|
|
|
1616
1767
|
const updated = this.store.schedules.change(job.id, job.revision, operation);
|
|
1617
1768
|
await this.showSchedule(updated, messageId);
|
|
1618
1769
|
}
|
|
1619
|
-
async controlQueueTaskPrompt(localSessionId, text) {
|
|
1620
|
-
const promptText = text.trim();
|
|
1621
|
-
|
|
1770
|
+
async controlQueueTaskPrompt(localSessionId, text, localImagePaths, workspaceRequestId, files, quotes) {
|
|
1771
|
+
const promptText = text.trim() || promptQuoteInstruction(quotes) || (files?.length ? defaultResourcePromptFromCounts(localImagePaths?.length ?? 0, files.length) : "");
|
|
1772
|
+
const modelPrompt = appendPromptQuotes(promptText, quotes);
|
|
1773
|
+
if (!promptText && !localImagePaths?.length)
|
|
1622
1774
|
throw new Error("The queued Prompt cannot be empty.");
|
|
1623
1775
|
const record = this.requireControlSession(localSessionId);
|
|
1624
1776
|
const contextKey = this.controlSessionContextKey(record);
|
|
1625
1777
|
const replyTarget = this.controlSessionReplyTarget(record);
|
|
1626
|
-
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey,
|
|
1778
|
+
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, files?.length ? appendDownloadedFiles(modelPrompt, files) : modelPrompt, {
|
|
1779
|
+
replyTarget, localImagePaths, promptId: workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined,
|
|
1780
|
+
displayPrompt: files?.length || quotes?.length ? promptText : undefined,
|
|
1781
|
+
});
|
|
1627
1782
|
this.store.audit(contextKey, "queued_prompt_added", {
|
|
1628
1783
|
promptId: queued.promptId,
|
|
1629
1784
|
localSessionId: record.localSessionId,
|
|
1630
|
-
source: "cli",
|
|
1785
|
+
source: workspaceRequestId ? "workspace" : "cli",
|
|
1631
1786
|
});
|
|
1632
1787
|
const queuedCount = this.store.countQueuedPrompts(record.localSessionId);
|
|
1633
1788
|
await this.scheduleNextQueuedPrompt(record.localSessionId);
|
|
1789
|
+
if (this.store.hasQueuedPrompt(queued.promptId))
|
|
1790
|
+
await this.refreshPromptQueueCards(record.localSessionId);
|
|
1634
1791
|
return { promptId: queued.promptId, queued: queuedCount };
|
|
1635
1792
|
}
|
|
1793
|
+
async controlCancelWorkspaceQueue(localSessionId, promptId, request) {
|
|
1794
|
+
const task = this.requireControlSession(localSessionId);
|
|
1795
|
+
const { cancelled, prompt } = this.store.cancelWorkspaceQueuedPrompt(promptId, localSessionId, request);
|
|
1796
|
+
if (prompt)
|
|
1797
|
+
await this.finishQueuedPromptCancellation(prompt, this.controlSessionContextKey(task)).catch(error => {
|
|
1798
|
+
this.logger.warn({ error, localSessionId, promptId }, "Failed to refresh a cancelled Workspace prompt.");
|
|
1799
|
+
});
|
|
1800
|
+
return cancelled;
|
|
1801
|
+
}
|
|
1802
|
+
async controlEditWorkspaceQueue(prompt, content) {
|
|
1803
|
+
this.requireControlSession(prompt.localSessionId);
|
|
1804
|
+
if (!this.store.updateQueuedPrompt(prompt, content))
|
|
1805
|
+
return false;
|
|
1806
|
+
this.store.audit(prompt.contextKey, "queued_prompt_edited", {
|
|
1807
|
+
promptId: prompt.promptId, localSessionId: prompt.localSessionId, source: "workspace",
|
|
1808
|
+
});
|
|
1809
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
1810
|
+
return true;
|
|
1811
|
+
}
|
|
1636
1812
|
controlTaskAgent(localSessionId, agentName) {
|
|
1637
1813
|
const record = this.requireControlSession(localSessionId);
|
|
1638
1814
|
const contextKey = this.controlSessionContextKey(record);
|
|
@@ -1646,7 +1822,7 @@ export class ProxySessionController {
|
|
|
1646
1822
|
agents: Object.entries(this.config.agents).map(([name, agent]) => ({ name, title: agent.title })),
|
|
1647
1823
|
};
|
|
1648
1824
|
}
|
|
1649
|
-
async controlTaskSettings(localSessionId, setting, value) {
|
|
1825
|
+
async controlTaskSettings(localSessionId, setting, value, options = {}) {
|
|
1650
1826
|
const record = this.requireControlSession(localSessionId);
|
|
1651
1827
|
if (setting && !value?.trim())
|
|
1652
1828
|
throw new Error(`task ${setting} requires a value.`);
|
|
@@ -1654,17 +1830,17 @@ export class ProxySessionController {
|
|
|
1654
1830
|
if (setting && nextValue) {
|
|
1655
1831
|
const contextKey = this.controlSessionContextKey(record);
|
|
1656
1832
|
await this.outbound.withReplyTarget(contextKey, this.controlSessionReplyTarget(record), async () => {
|
|
1657
|
-
const
|
|
1833
|
+
const target = { sessionId: record.localSessionId, quiet: options.quiet };
|
|
1658
1834
|
if (setting === "provider")
|
|
1659
|
-
await this.selectProvider(contextKey, nextValue,
|
|
1835
|
+
await this.selectProvider(contextKey, nextValue, target);
|
|
1660
1836
|
else if (setting === "model")
|
|
1661
|
-
await this.model(contextKey, nextValue,
|
|
1837
|
+
await this.model(contextKey, nextValue, target);
|
|
1662
1838
|
else if (setting === "thinking")
|
|
1663
|
-
await this.thinking(contextKey, nextValue,
|
|
1839
|
+
await this.thinking(contextKey, nextValue, target);
|
|
1664
1840
|
else {
|
|
1665
1841
|
if (nextValue !== "auto" && nextValue !== "confirm")
|
|
1666
1842
|
throw new Error("task permissions accepts auto or confirm.");
|
|
1667
|
-
await this.permissions(contextKey, nextValue,
|
|
1843
|
+
await this.permissions(contextKey, nextValue, target);
|
|
1668
1844
|
}
|
|
1669
1845
|
});
|
|
1670
1846
|
}
|
|
@@ -1748,11 +1924,12 @@ export class ProxySessionController {
|
|
|
1748
1924
|
}),
|
|
1749
1925
|
};
|
|
1750
1926
|
}
|
|
1751
|
-
async controlResetTaskToTurn(localSessionId, turnId) {
|
|
1927
|
+
async controlResetTaskToTurn(localSessionId, turnId, options) {
|
|
1752
1928
|
const record = this.requireControlSession(localSessionId);
|
|
1753
1929
|
const contextKey = this.controlSessionContextKey(record);
|
|
1754
1930
|
await this.runSessionReset(record.localSessionId, async () => {
|
|
1755
|
-
|
|
1931
|
+
if (!options?.quiet)
|
|
1932
|
+
await this.outbound.sendText(contextKey, TURN_RESET_STARTED_MESSAGE);
|
|
1756
1933
|
await this.performSessionReset(contextKey, record, turnId, false);
|
|
1757
1934
|
});
|
|
1758
1935
|
return this.store.getSession(record.localSessionId) ?? record;
|
|
@@ -2063,7 +2240,7 @@ export class ProxySessionController {
|
|
|
2063
2240
|
: context.contextKey;
|
|
2064
2241
|
if (!this.outbound.canRoute(turnContextKey))
|
|
2065
2242
|
continue;
|
|
2066
|
-
this.outbound.registerSession(session.localSessionId, turnContextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
2243
|
+
this.outbound.registerSession(session.localSessionId, turnContextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
2067
2244
|
if (!session.lastTurnId)
|
|
2068
2245
|
continue;
|
|
2069
2246
|
void this.outbound.resumeDelivery(session.localSessionId, turnContextKey, session.lastTurnId).catch((error) => {
|
|
@@ -2092,19 +2269,26 @@ export class ProxySessionController {
|
|
|
2092
2269
|
});
|
|
2093
2270
|
}
|
|
2094
2271
|
}
|
|
2095
|
-
async recoverInterruptedTasks() {
|
|
2272
|
+
async recoverInterruptedTasks(updateRecoveryAttemptIds = []) {
|
|
2096
2273
|
if (this.startupRecovery)
|
|
2097
2274
|
return this.startupRecovery;
|
|
2098
|
-
const recovery = this.runStartupRecovery();
|
|
2275
|
+
const recovery = this.runStartupRecovery(new Set(updateRecoveryAttemptIds));
|
|
2099
2276
|
this.startupRecovery = recovery;
|
|
2100
2277
|
return recovery;
|
|
2101
2278
|
}
|
|
2102
|
-
async runStartupRecovery() {
|
|
2279
|
+
async runStartupRecovery(updateRecoveryAttempts) {
|
|
2103
2280
|
await this.recoverUnprocessedMessages();
|
|
2104
2281
|
await this.finishPersistedCancellationRequests();
|
|
2105
2282
|
await this.recoverShellCommandJobs();
|
|
2106
2283
|
const recoveryCutoff = Date.now() - RECOVERY_ACTIVITY_WINDOW_MS;
|
|
2107
2284
|
const cutoff = new Date(recoveryCutoff).toISOString();
|
|
2285
|
+
for (const attemptId of updateRecoveryAttempts) {
|
|
2286
|
+
const attempt = this.store.getTurnAttempt(attemptId);
|
|
2287
|
+
const session = attempt && this.store.getSession(attempt.localSessionId);
|
|
2288
|
+
if (attempt && session && this.canContinueAfterRestart(attempt, session)) {
|
|
2289
|
+
this.store.prepareInterruptedTurnAttemptRecovery(attemptId, new Date(0).toISOString());
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2108
2292
|
for (const attempt of this.store.listRecentlyInterruptedTurnAttempts(cutoff)) {
|
|
2109
2293
|
const session = this.store.getSession(attempt.localSessionId);
|
|
2110
2294
|
if (session && this.canContinueAfterRestart(attempt, session)) {
|
|
@@ -2113,12 +2297,12 @@ export class ProxySessionController {
|
|
|
2113
2297
|
}
|
|
2114
2298
|
this.backfillTurnAttemptsForUpgrade();
|
|
2115
2299
|
const attempts = this.store.listIncompleteTurnAttempts();
|
|
2116
|
-
const recentAttempts = attempts.filter((attempt) => isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2300
|
+
const recentAttempts = attempts.filter((attempt) => updateRecoveryAttempts.has(attempt.attemptId) || isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2117
2301
|
if (recentAttempts.length > 0) {
|
|
2118
2302
|
this.logger.warn({ attemptIds: recentAttempts.map((attempt) => attempt.attemptId) }, "Recovering unfinished Agent Bot tasks after startup.");
|
|
2119
2303
|
}
|
|
2120
2304
|
for (const attempt of attempts) {
|
|
2121
|
-
if (!isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2305
|
+
if (!updateRecoveryAttempts.has(attempt.attemptId) && !isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2122
2306
|
await this.expireStaleTurnAttempt(attempt);
|
|
2123
2307
|
continue;
|
|
2124
2308
|
}
|
|
@@ -2216,7 +2400,7 @@ export class ProxySessionController {
|
|
|
2216
2400
|
continue;
|
|
2217
2401
|
}
|
|
2218
2402
|
if (session) {
|
|
2219
|
-
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
2403
|
+
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
2220
2404
|
}
|
|
2221
2405
|
try {
|
|
2222
2406
|
if (!session?.remoteSessionId)
|
|
@@ -2435,7 +2619,7 @@ export class ProxySessionController {
|
|
|
2435
2619
|
const replyTarget = attempt.replyMessageId
|
|
2436
2620
|
? { messageId: attempt.replyMessageId, replyInThread: true }
|
|
2437
2621
|
: undefined;
|
|
2438
|
-
this.outbound.registerSession(session.localSessionId, contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
2622
|
+
this.outbound.registerSession(session.localSessionId, contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
2439
2623
|
if (announce) {
|
|
2440
2624
|
await this.outbound.withReplyTarget(contextKey, replyTarget, () => this.outbound.sendText(contextKey, "检测到重启前存在未完成任务,正在核对远端执行状态并尝试恢复。")).catch((error) => {
|
|
2441
2625
|
this.logger.warn({ error, attemptId: attempt.attemptId, contextKey }, "Failed to send the task recovery notification.");
|
|
@@ -2601,7 +2785,7 @@ export class ProxySessionController {
|
|
|
2601
2785
|
this.store.schedules.finish(attempt.attemptId, "unknown", message);
|
|
2602
2786
|
if (!session || session.status === "closed")
|
|
2603
2787
|
return;
|
|
2604
|
-
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
2788
|
+
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd, this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
2605
2789
|
const active = this.runtimes.forAgent(session.agentName).getSession(session.localSessionId)?.activeTurnId;
|
|
2606
2790
|
if (!session.lastTurnId || session.lastTurnId === turnId || session.lastTurnId === attempt.recoveredFromTurnId
|
|
2607
2791
|
|| (!attempt.turnId && !active)) {
|
|
@@ -2797,15 +2981,22 @@ export class ProxySessionController {
|
|
|
2797
2981
|
}
|
|
2798
2982
|
await this.promptSession(record, contextKey, text, messageId, replyTarget, localImagePaths, displayPrompt);
|
|
2799
2983
|
}
|
|
2800
|
-
async promptSession(record, contextKey, text, messageId, replyTarget, localImagePaths, displayPrompt) {
|
|
2984
|
+
async promptSession(record, contextKey, text, messageId, replyTarget, localImagePaths, displayPrompt, workspace) {
|
|
2801
2985
|
this.recoverySupersededSessions.add(record.localSessionId);
|
|
2802
2986
|
const executionGeneration = this.store.executionGeneration(record.localSessionId);
|
|
2987
|
+
const workspaceRequestId = workspace?.requestId;
|
|
2988
|
+
const workspaceMessageId = workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined;
|
|
2989
|
+
const startOptions = { messageId, displayPrompt, executionGeneration, workspaceRequestId,
|
|
2990
|
+
onWorkspaceClaim: workspace?.onClaim, onWorkspaceSubmitting: workspace?.onSubmitting };
|
|
2803
2991
|
if (this.llmRetryingSessions.has(record.localSessionId) || this.planHandoffs.has(record.localSessionId)) {
|
|
2992
|
+
if (workspace?.queuedPrompt)
|
|
2993
|
+
throw new TurnNotSubmittedError("当前任务正在重试或切换,请稍后再发送。");
|
|
2804
2994
|
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, text, {
|
|
2805
2995
|
localImagePaths,
|
|
2806
2996
|
messageId,
|
|
2807
2997
|
replyTarget,
|
|
2808
2998
|
displayPrompt,
|
|
2999
|
+
promptId: workspaceMessageId,
|
|
2809
3000
|
});
|
|
2810
3001
|
this.store.audit(contextKey, "queued_prompt_added_during_llm_retry", {
|
|
2811
3002
|
promptId: queued.promptId,
|
|
@@ -2816,8 +3007,8 @@ export class ProxySessionController {
|
|
|
2816
3007
|
}
|
|
2817
3008
|
const configuredRuntime = this.runtimes.forAgent(record.agentName);
|
|
2818
3009
|
if (!configuredRuntime.getSession(record.localSessionId)) {
|
|
2819
|
-
this.outbound.registerSession(record.localSessionId, contextKey, record.title, record.cwd, this.agentLabel(record.agentName), record.model, record.modelProvider);
|
|
2820
|
-
await this.outbound.startPendingTurn(record.localSessionId, contextKey, record.title, replyTarget, displayPrompt ?? text, localImagePaths);
|
|
3010
|
+
this.outbound.registerSession(record.localSessionId, contextKey, record.title, record.cwd, this.agentLabel(record.agentName), record.model, record.modelProvider, record.reasoningEffort);
|
|
3011
|
+
await this.outbound.startPendingTurn(record.localSessionId, contextKey, record.title, replyTarget, displayPrompt ?? text, localImagePaths, workspaceRequestId, Boolean(workspace));
|
|
2821
3012
|
}
|
|
2822
3013
|
let loaded;
|
|
2823
3014
|
try {
|
|
@@ -2847,25 +3038,31 @@ export class ProxySessionController {
|
|
|
2847
3038
|
}
|
|
2848
3039
|
}
|
|
2849
3040
|
this.assertExecutionGeneration(record.localSessionId, executionGeneration);
|
|
2850
|
-
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
2851
3041
|
const activeTurnId = loaded.session.activeTurnId;
|
|
3042
|
+
assertWorkspaceSteerTurn(workspace?.expectedTurnId, activeTurnId);
|
|
3043
|
+
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
2852
3044
|
if (activeTurnId) {
|
|
2853
3045
|
const activeContextKey = this.store.getTurnContextKey(activeTurnId);
|
|
2854
3046
|
const notificationTurn = Boolean(turnViewSnapshot(this.store.getTurnSnapshot(activeTurnId))?.taskNotificationCard);
|
|
2855
3047
|
if ((activeContextKey && activeContextKey !== contextKey) || notificationTurn) {
|
|
3048
|
+
if (workspace?.queuedPrompt)
|
|
3049
|
+
throw new TurnNotSubmittedError("当前轮次无法接收这条消息,可在会话空闲后再发送。");
|
|
2856
3050
|
this.persistQueuedPrompt(record.localSessionId, contextKey, text, {
|
|
2857
3051
|
localImagePaths,
|
|
2858
3052
|
messageId,
|
|
2859
3053
|
replyTarget,
|
|
2860
3054
|
displayPrompt,
|
|
3055
|
+
promptId: workspaceMessageId,
|
|
2861
3056
|
});
|
|
2862
3057
|
if (notificationTurn)
|
|
2863
3058
|
await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
2864
3059
|
return;
|
|
2865
3060
|
}
|
|
2866
3061
|
try {
|
|
3062
|
+
workspace?.onClaim?.();
|
|
3063
|
+
workspace?.onSubmitting();
|
|
2867
3064
|
await loaded.runtime.steerTurn(record.localSessionId, activeTurnId, runtimePrompt(text, localImagePaths));
|
|
2868
|
-
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, messageId, localImagePaths);
|
|
3065
|
+
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, workspaceMessageId ?? messageId, localImagePaths);
|
|
2869
3066
|
if (messageId)
|
|
2870
3067
|
await this.bindMessageReactionToTurn(messageId, record.localSessionId, activeTurnId);
|
|
2871
3068
|
return;
|
|
@@ -2874,6 +3071,8 @@ export class ProxySessionController {
|
|
|
2874
3071
|
if (!(error instanceof TurnNotSubmittedError)) {
|
|
2875
3072
|
throw new Error("追加消息的提交结果待核实,未自动重发或入队。请检查执行记录后继续。", { cause: error });
|
|
2876
3073
|
}
|
|
3074
|
+
if (workspace?.expectedTurnId || workspace?.queuedPrompt)
|
|
3075
|
+
throw error;
|
|
2877
3076
|
this.logger.debug({ error, sessionId: record.localSessionId, activeTurnId }, "Steering failed; reconciling the App Server thread.");
|
|
2878
3077
|
let current = loaded.runtime.getSession(record.localSessionId);
|
|
2879
3078
|
try {
|
|
@@ -2883,7 +3082,7 @@ export class ProxySessionController {
|
|
|
2883
3082
|
this.logger.warn({ error: syncError, sessionId: record.localSessionId }, "Failed to synchronize after steering failure.");
|
|
2884
3083
|
}
|
|
2885
3084
|
if (!current?.activeTurnId) {
|
|
2886
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3085
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
2887
3086
|
if (messageId)
|
|
2888
3087
|
await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
2889
3088
|
return;
|
|
@@ -2892,8 +3091,9 @@ export class ProxySessionController {
|
|
|
2892
3091
|
if (current.activeTurnId !== activeTurnId && !notificationTurn) {
|
|
2893
3092
|
try {
|
|
2894
3093
|
this.assertExecutionGeneration(record.localSessionId, executionGeneration);
|
|
3094
|
+
workspace?.onSubmitting();
|
|
2895
3095
|
await loaded.runtime.steerTurn(record.localSessionId, current.activeTurnId, runtimePrompt(text, localImagePaths));
|
|
2896
|
-
await this.presentSteerMessage(record.localSessionId, current.activeTurnId, displayPrompt ?? text, messageId, localImagePaths);
|
|
3096
|
+
await this.presentSteerMessage(record.localSessionId, current.activeTurnId, displayPrompt ?? text, workspaceMessageId ?? messageId, localImagePaths);
|
|
2897
3097
|
if (messageId)
|
|
2898
3098
|
await this.bindMessageReactionToTurn(messageId, record.localSessionId, current.activeTurnId);
|
|
2899
3099
|
return;
|
|
@@ -2910,13 +3110,14 @@ export class ProxySessionController {
|
|
|
2910
3110
|
messageId,
|
|
2911
3111
|
replyTarget,
|
|
2912
3112
|
displayPrompt,
|
|
3113
|
+
promptId: workspaceMessageId,
|
|
2913
3114
|
});
|
|
2914
3115
|
if (notificationTurn)
|
|
2915
3116
|
await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
2916
3117
|
return;
|
|
2917
3118
|
}
|
|
2918
3119
|
}
|
|
2919
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3120
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
2920
3121
|
if (messageId)
|
|
2921
3122
|
await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
2922
3123
|
}
|
|
@@ -2941,7 +3142,7 @@ export class ProxySessionController {
|
|
|
2941
3142
|
}
|
|
2942
3143
|
persistQueuedPrompt(localSessionId, contextKey, text, options = {}) {
|
|
2943
3144
|
return this.store.enqueuePrompt({
|
|
2944
|
-
promptId: createId("prompt"),
|
|
3145
|
+
promptId: options.promptId ?? createId("prompt"),
|
|
2945
3146
|
localSessionId,
|
|
2946
3147
|
contextKey,
|
|
2947
3148
|
text,
|
|
@@ -2960,15 +3161,16 @@ export class ProxySessionController {
|
|
|
2960
3161
|
if (action.messageId)
|
|
2961
3162
|
this.rememberPromptQueueCard(sessionId, action.contextKey, action.messageId);
|
|
2962
3163
|
const cancelled = this.store.cancelQueuedPrompt(promptId, sessionId);
|
|
2963
|
-
if (cancelled
|
|
2964
|
-
await this.
|
|
2965
|
-
|
|
2966
|
-
this.
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
3164
|
+
if (cancelled)
|
|
3165
|
+
await this.finishQueuedPromptCancellation(cancelled, action.contextKey);
|
|
3166
|
+
else
|
|
3167
|
+
await this.refreshPromptQueueCards(sessionId);
|
|
3168
|
+
}
|
|
3169
|
+
async finishQueuedPromptCancellation(prompt, contextKey) {
|
|
3170
|
+
if (prompt.messageId)
|
|
3171
|
+
await this.finalizeStandaloneMessageReaction(prompt.messageId, "cancelled");
|
|
3172
|
+
this.store.audit(contextKey, "queued_prompt_cancelled", { promptId: prompt.promptId, localSessionId: prompt.localSessionId });
|
|
3173
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
2972
3174
|
}
|
|
2973
3175
|
async presentPromptQueueCard(localSessionId, contextKey) {
|
|
2974
3176
|
await this.serializePromptQueueCardWrite(localSessionId, async () => {
|
|
@@ -3013,6 +3215,7 @@ export class ProxySessionController {
|
|
|
3013
3215
|
prompts: this.store.listQueuedPrompts(localSessionId).map((prompt) => ({
|
|
3014
3216
|
id: prompt.promptId,
|
|
3015
3217
|
text: prompt.displayPrompt ?? prompt.text,
|
|
3218
|
+
hasImages: Boolean(prompt.localImagePaths?.length),
|
|
3016
3219
|
})),
|
|
3017
3220
|
});
|
|
3018
3221
|
}
|
|
@@ -3190,7 +3393,7 @@ export class ProxySessionController {
|
|
|
3190
3393
|
permissionMode: source.permissionMode ?? "auto",
|
|
3191
3394
|
});
|
|
3192
3395
|
this.store.setCurrentSession(message.contextKey, localSessionId);
|
|
3193
|
-
this.outbound.registerSession(localSessionId, message.contextKey, forkTitle, source.cwd, this.agentLabel(source.agentName), source.model, source.modelProvider);
|
|
3396
|
+
this.outbound.registerSession(localSessionId, message.contextKey, forkTitle, source.cwd, this.agentLabel(source.agentName), source.model, source.modelProvider, source.reasoningEffort);
|
|
3194
3397
|
try {
|
|
3195
3398
|
const forked = await runtime.forkSession({
|
|
3196
3399
|
localSessionId,
|
|
@@ -3453,7 +3656,7 @@ export class ProxySessionController {
|
|
|
3453
3656
|
forkedFromHistoricalTurn: sourceWasRunning && source.lastTurnId !== lastTurnId,
|
|
3454
3657
|
};
|
|
3455
3658
|
}
|
|
3456
|
-
async forkSessionIntoContext(contextKey, plan) {
|
|
3659
|
+
async forkSessionIntoContext(contextKey, plan, activate = true) {
|
|
3457
3660
|
const localSessionId = createId("sess");
|
|
3458
3661
|
const record = this.store.createSession({
|
|
3459
3662
|
localSessionId,
|
|
@@ -3488,7 +3691,7 @@ export class ProxySessionController {
|
|
|
3488
3691
|
lastTurnId: plan.lastTurnId,
|
|
3489
3692
|
lastTurnStatus: plan.lastTurnStatus,
|
|
3490
3693
|
});
|
|
3491
|
-
this.outbound.registerSession(localSessionId, contextKey, forked.title ?? plan.forkTitle, plan.cwd, this.agentLabel(plan.agentName), forked.model ?? plan.model, forked.modelProvider ?? plan.modelProvider);
|
|
3694
|
+
this.outbound.registerSession(localSessionId, contextKey, forked.title ?? plan.forkTitle, plan.cwd, this.agentLabel(plan.agentName), forked.model ?? plan.model, forked.modelProvider ?? plan.modelProvider, forked.reasoningEffort ?? plan.reasoningEffort);
|
|
3492
3695
|
this.store.audit(contextKey, "session_forked", {
|
|
3493
3696
|
sourceLocalSessionId: plan.source?.localSessionId,
|
|
3494
3697
|
sourceRemoteSessionId: plan.remoteSessionId,
|
|
@@ -3500,7 +3703,8 @@ export class ProxySessionController {
|
|
|
3500
3703
|
forkedLocalSessionId: localSessionId,
|
|
3501
3704
|
forkedRemoteSessionId: forked.remoteSessionId,
|
|
3502
3705
|
});
|
|
3503
|
-
|
|
3706
|
+
if (activate)
|
|
3707
|
+
this.store.setCurrentSession(contextKey, localSessionId);
|
|
3504
3708
|
return {
|
|
3505
3709
|
record: this.store.getSession(localSessionId) ?? record,
|
|
3506
3710
|
session: forked,
|
|
@@ -3870,7 +4074,7 @@ export class ProxySessionController {
|
|
|
3870
4074
|
messageId: options.messageId,
|
|
3871
4075
|
replyMessageId: replyTarget?.messageId,
|
|
3872
4076
|
executionGeneration,
|
|
3873
|
-
});
|
|
4077
|
+
}, options.onWorkspaceClaim);
|
|
3874
4078
|
}
|
|
3875
4079
|
let turnId;
|
|
3876
4080
|
let runtimeText = text;
|
|
@@ -3893,8 +4097,8 @@ export class ProxySessionController {
|
|
|
3893
4097
|
let pendingTurnId;
|
|
3894
4098
|
try {
|
|
3895
4099
|
const session = loaded.runtime.getSession(loaded.record.localSessionId) ?? loaded.session;
|
|
3896
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
3897
|
-
pendingTurnId = await this.outbound.startPendingTurn(loaded.record.localSessionId, loaded.record.contextKey, title, replyTarget, cardPrompt, localImagePaths);
|
|
4100
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4101
|
+
pendingTurnId = await this.outbound.startPendingTurn(loaded.record.localSessionId, loaded.record.contextKey, title, replyTarget, cardPrompt, localImagePaths, options.workspaceRequestId, Boolean(options.onWorkspaceSubmitting));
|
|
3898
4102
|
}
|
|
3899
4103
|
catch (error) {
|
|
3900
4104
|
if (options.scheduleRunId) {
|
|
@@ -3939,6 +4143,7 @@ export class ProxySessionController {
|
|
|
3939
4143
|
this.store.schedules.saveRun({ ...run, status: "submitting" });
|
|
3940
4144
|
}
|
|
3941
4145
|
this.store.beginTurnAttemptSubmission(attemptId, recordSubmission);
|
|
4146
|
+
options.onWorkspaceSubmitting?.();
|
|
3942
4147
|
turnId = await loaded.runtime.startTurn(loaded.record.localSessionId, options.approvedPlanTurnId
|
|
3943
4148
|
? { text: runtimeText, collaborationMode: "default" }
|
|
3944
4149
|
: runtimePrompt(runtimeText, localImagePaths));
|
|
@@ -4081,7 +4286,7 @@ export class ProxySessionController {
|
|
|
4081
4286
|
}
|
|
4082
4287
|
if (activate)
|
|
4083
4288
|
this.store.setCurrentSession(contextKey, localSessionId);
|
|
4084
|
-
this.outbound.registerSession(localSessionId, contextKey, initialTitle, sessionCwd, this.agentLabel(agentName), resolvedExecutionSettings.model, resolvedExecutionSettings.modelProvider);
|
|
4289
|
+
this.outbound.registerSession(localSessionId, contextKey, initialTitle, sessionCwd, this.agentLabel(agentName), resolvedExecutionSettings.model, resolvedExecutionSettings.modelProvider, resolvedExecutionSettings.reasoningEffort);
|
|
4085
4290
|
const runtime = this.runtimes.forAgent(agentName);
|
|
4086
4291
|
try {
|
|
4087
4292
|
if (prepareTurn) {
|
|
@@ -4098,7 +4303,7 @@ export class ProxySessionController {
|
|
|
4098
4303
|
permissionMode: resolvedExecutionSettings.permissionMode ?? "auto",
|
|
4099
4304
|
});
|
|
4100
4305
|
this.persistRuntimeSession(record, session, session.activeTurnId ? "running" : "ready");
|
|
4101
|
-
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider);
|
|
4306
|
+
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4102
4307
|
const saved = this.store.getSession(localSessionId) ?? record;
|
|
4103
4308
|
if (prepareTurn)
|
|
4104
4309
|
this.assertExecutionGeneration(localSessionId, executionGeneration);
|
|
@@ -4215,7 +4420,7 @@ export class ProxySessionController {
|
|
|
4215
4420
|
// A live Turn keeps its original delivery route. The new group's next Turn
|
|
4216
4421
|
// establishes its own route through startPendingTurn.
|
|
4217
4422
|
if (task.status !== "running" && !runtime.getSession(task.localSessionId)?.activeTurnId) {
|
|
4218
|
-
this.outbound.registerSession(task.localSessionId, group.contextKey, task.title, task.cwd, this.agentLabel(agentName), task.model, task.modelProvider);
|
|
4423
|
+
this.outbound.registerSession(task.localSessionId, group.contextKey, task.title, task.cwd, this.agentLabel(agentName), task.model, task.modelProvider, task.reasoningEffort);
|
|
4219
4424
|
}
|
|
4220
4425
|
this.store.audit(sourceContextKey, "session_switch_group", {
|
|
4221
4426
|
localSessionId: task.localSessionId, remoteSessionId, groupContextKey: group.contextKey,
|
|
@@ -4442,7 +4647,7 @@ export class ProxySessionController {
|
|
|
4442
4647
|
return this.loadSession(record, forSettings);
|
|
4443
4648
|
}
|
|
4444
4649
|
}
|
|
4445
|
-
this.outbound.registerSession(record.localSessionId, record.contextKey, record.title, record.cwd, this.agentLabel(record.agentName), record.model, record.modelProvider);
|
|
4650
|
+
this.outbound.registerSession(record.localSessionId, record.contextKey, record.title, record.cwd, this.agentLabel(record.agentName), record.model, record.modelProvider, record.reasoningEffort);
|
|
4446
4651
|
const loading = this.sessionHydrationOperations.run(record.localSessionId, async () => {
|
|
4447
4652
|
const latest = this.store.getSession(record.localSessionId);
|
|
4448
4653
|
if (latest)
|
|
@@ -4888,8 +5093,11 @@ export class ProxySessionController {
|
|
|
4888
5093
|
clearTimeout(retryTimer);
|
|
4889
5094
|
this.queuedPromptRetryTimers.delete(sessionId);
|
|
4890
5095
|
}
|
|
5096
|
+
return this.serializeQueuedPromptStart(sessionId, () => this.startNextQueuedPromptIfIdle(sessionId));
|
|
5097
|
+
}
|
|
5098
|
+
serializeQueuedPromptStart(sessionId, start) {
|
|
4891
5099
|
const previous = this.queuedPromptStarts.get(sessionId) ?? Promise.resolve();
|
|
4892
|
-
const next = previous.catch(() => undefined).then(
|
|
5100
|
+
const next = previous.catch(() => undefined).then(start);
|
|
4893
5101
|
this.queuedPromptStarts.set(sessionId, next);
|
|
4894
5102
|
return next.finally(() => {
|
|
4895
5103
|
if (this.queuedPromptStarts.get(sessionId) === next)
|
|
@@ -4936,6 +5144,7 @@ export class ProxySessionController {
|
|
|
4936
5144
|
if (!baseRecord || baseRecord.status === "closed")
|
|
4937
5145
|
return;
|
|
4938
5146
|
let prompt;
|
|
5147
|
+
let finishDispatch;
|
|
4939
5148
|
try {
|
|
4940
5149
|
let loaded = await this.loadSession(baseRecord, Boolean(this.store.getPendingProviderSettings(sessionId)));
|
|
4941
5150
|
const remoteActivity = await this.assertSessionTurnOwnership(loaded.record, loaded.runtime);
|
|
@@ -4951,7 +5160,9 @@ export class ProxySessionController {
|
|
|
4951
5160
|
prompt = this.store.takeNextQueuedPrompt(sessionId);
|
|
4952
5161
|
if (!prompt)
|
|
4953
5162
|
return;
|
|
5163
|
+
finishDispatch = this.store.trackQueuedPromptDispatch(prompt);
|
|
4954
5164
|
const scheduledRun = this.store.schedules.getRun(prompt.promptId);
|
|
5165
|
+
let workspaceRequestId = prompt.promptId.startsWith("workspace:") ? prompt.promptId.slice("workspace:".length) : undefined;
|
|
4955
5166
|
const record = this.store.getSessionForContext(sessionId, prompt.contextKey) ?? baseRecord;
|
|
4956
5167
|
loaded = { ...loaded, record };
|
|
4957
5168
|
await this.refreshPromptQueueCards(sessionId);
|
|
@@ -4960,23 +5171,33 @@ export class ProxySessionController {
|
|
|
4960
5171
|
|| this.lifecycle?.canStartScheduledTasks?.() === false)
|
|
4961
5172
|
throw new Error("定时任务已取消、过期或正在安全重启。");
|
|
4962
5173
|
const job = this.store.schedules.require(scheduledRun.jobId);
|
|
5174
|
+
if (job.attachments?.files.length || job.attachments?.quotes?.length)
|
|
5175
|
+
workspaceRequestId = scheduledRun.id.slice("schedule_run_".length);
|
|
4963
5176
|
this.assertScheduleTarget(job);
|
|
5177
|
+
let missingAttachment = false;
|
|
4964
5178
|
try {
|
|
4965
|
-
|
|
5179
|
+
const attachmentPaths = [...(job.attachments?.images ?? []), ...(job.attachments?.files.map(file => file.filePath) ?? [])];
|
|
5180
|
+
const available = await Promise.all(attachmentPaths.map(async (file) => (await fs.stat(file).catch(() => undefined))?.isFile()));
|
|
5181
|
+
missingAttachment = available.some(value => !value);
|
|
5182
|
+
if (missingAttachment)
|
|
5183
|
+
throw new Error("定时任务的附件已不可用。");
|
|
5184
|
+
await this.notifySchedule(job, scheduleDisplayPrompt(job, queuedPromptContent(prompt, job.attachments?.quotes).text), prompt.localImagePaths);
|
|
4966
5185
|
}
|
|
4967
5186
|
catch (error) {
|
|
5187
|
+
const reason = missingAttachment ? "定时任务的附件已不可用" : "原会话的 Prompt 发送失败";
|
|
4968
5188
|
const currentJob = this.store.schedules.get(job.id);
|
|
4969
5189
|
if (currentJob?.status === "enabled") {
|
|
4970
5190
|
const paused = this.store.schedules.change(job.id, currentJob.revision, "pause");
|
|
4971
|
-
this.store.schedules.update({ ...paused, notice:
|
|
5191
|
+
this.store.schedules.update({ ...paused, notice: `${reason},计划已暂停。请修复后恢复。` });
|
|
4972
5192
|
}
|
|
4973
|
-
this.store.schedules.finish(scheduledRun.id, "failed", "无法向原会话发送 Prompt,未提交模型。");
|
|
5193
|
+
this.store.schedules.finish(scheduledRun.id, "failed", missingAttachment ? `${reason},未提交模型。` : "无法向原会话发送 Prompt,未提交模型。");
|
|
4974
5194
|
this.store.updateTurnAttempt(scheduledRun.id, { status: "failed" });
|
|
4975
5195
|
throw error;
|
|
4976
5196
|
}
|
|
4977
5197
|
}
|
|
4978
5198
|
const turnId = await this.startTurnNow(loaded, prompt.text, prompt.replyMessageId ? { messageId: prompt.replyMessageId, replyInThread: true } : undefined, prompt.localImagePaths, { messageId: prompt.messageId, displayPrompt: prompt.displayPrompt, executionGeneration,
|
|
4979
5199
|
trigger: scheduledRun ? "schedule" : "queue", instructionId: prompt.promptId,
|
|
5200
|
+
workspaceRequestId,
|
|
4980
5201
|
...(scheduledRun ? { attemptId: prompt.promptId, scheduleRunId: prompt.promptId } : {}) });
|
|
4981
5202
|
if (prompt.messageId)
|
|
4982
5203
|
await this.bindMessageReactionToTurn(prompt.messageId, sessionId, turnId);
|
|
@@ -5017,6 +5238,9 @@ export class ProxySessionController {
|
|
|
5017
5238
|
queueMicrotask(() => void this.scheduleNextQueuedPrompt(sessionId));
|
|
5018
5239
|
}
|
|
5019
5240
|
}
|
|
5241
|
+
finally {
|
|
5242
|
+
finishDispatch?.();
|
|
5243
|
+
}
|
|
5020
5244
|
}
|
|
5021
5245
|
completedParentTurnId(source) {
|
|
5022
5246
|
if (!source?.lastTurnId)
|
|
@@ -5375,7 +5599,7 @@ export class ProxySessionController {
|
|
|
5375
5599
|
lastTurnId: turnId,
|
|
5376
5600
|
lastTurnStatus: "completed",
|
|
5377
5601
|
});
|
|
5378
|
-
this.outbound.registerSession(current.localSessionId, contextKey, forked.title ?? current.title, current.cwd, this.agentLabel(current.agentName), forked.model ?? current.model, forked.modelProvider ?? current.modelProvider);
|
|
5602
|
+
this.outbound.registerSession(current.localSessionId, contextKey, forked.title ?? current.title, current.cwd, this.agentLabel(current.agentName), forked.model ?? current.model, forked.modelProvider ?? current.modelProvider, forked.reasoningEffort ?? current.reasoningEffort);
|
|
5379
5603
|
this.store.audit(contextKey, "session_reset_to_turn", {
|
|
5380
5604
|
localSessionId: current.localSessionId,
|
|
5381
5605
|
previousRemoteSessionId,
|
|
@@ -5665,7 +5889,7 @@ export class ProxySessionController {
|
|
|
5665
5889
|
const session = await loaded.runtime.setExecutionSettings(loaded.record.localSessionId, settings, persist);
|
|
5666
5890
|
loaded.record = this.store.getSession(loaded.record.localSessionId) ?? loaded.record;
|
|
5667
5891
|
this.settingsOnlySessions.delete(loaded.record.localSessionId);
|
|
5668
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
5892
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
5669
5893
|
return session;
|
|
5670
5894
|
}
|
|
5671
5895
|
async reconcilePreparedSettingsSession(loaded) {
|
|
@@ -5709,7 +5933,7 @@ export class ProxySessionController {
|
|
|
5709
5933
|
if (options.updateMessageId) {
|
|
5710
5934
|
await this.openExecutionSettingsNow(contextKey, activeTab, options);
|
|
5711
5935
|
}
|
|
5712
|
-
else {
|
|
5936
|
+
else if (!options.quiet) {
|
|
5713
5937
|
await this.outbound.sendText(contextKey, this.pendingProviderNotice(pending).replaceAll("`", ""));
|
|
5714
5938
|
}
|
|
5715
5939
|
}
|
|
@@ -5738,7 +5962,7 @@ export class ProxySessionController {
|
|
|
5738
5962
|
if (rolledBack) {
|
|
5739
5963
|
loaded.session = restored;
|
|
5740
5964
|
this.store.deletePendingProviderSettings(pending.localSessionId);
|
|
5741
|
-
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider);
|
|
5965
|
+
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider, previous.reasoningEffort);
|
|
5742
5966
|
notice = `切换到 Provider ${cardCode(pending.settings.modelProvider)}、模型 ${cardCode(pending.settings.model)} 失败:${runtimeErrorMessage(error)} 已回退到 Provider ${cardCode(previous.modelProvider ?? "Agent 默认")}、模型 ${cardCode(previous.model ?? "默认")},后续轮次继续使用原设置。`;
|
|
5743
5967
|
}
|
|
5744
5968
|
else {
|
|
@@ -5876,7 +6100,7 @@ export class ProxySessionController {
|
|
|
5876
6100
|
await loaded.runtime.setReasoningEffort(loaded.record.localSessionId, nextEffort);
|
|
5877
6101
|
}
|
|
5878
6102
|
this.store.updateRuntimeSession(loaded.record.localSessionId, { model, reasoningEffort: nextEffort });
|
|
5879
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider);
|
|
6103
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider, nextEffort);
|
|
5880
6104
|
});
|
|
5881
6105
|
const effortMessage = nextEffort && nextEffort !== currentEffort
|
|
5882
6106
|
? `,思考强度已自动调整为 ${nextEffort}`
|
|
@@ -5889,6 +6113,8 @@ export class ProxySessionController {
|
|
|
5889
6113
|
});
|
|
5890
6114
|
return;
|
|
5891
6115
|
}
|
|
6116
|
+
if (options.quiet)
|
|
6117
|
+
return;
|
|
5892
6118
|
await this.outbound.sendText(contextKey, `模型已切换为 ${model}${effortMessage},只影响当前任务,从下一次请求生效。`);
|
|
5893
6119
|
}
|
|
5894
6120
|
async goal(contextKey, command) {
|
|
@@ -6291,6 +6517,8 @@ export class ProxySessionController {
|
|
|
6291
6517
|
});
|
|
6292
6518
|
return;
|
|
6293
6519
|
}
|
|
6520
|
+
if (options.quiet)
|
|
6521
|
+
return;
|
|
6294
6522
|
await this.outbound.sendText(contextKey, `思考强度已切换为 ${effort},只影响当前任务,从下一次请求生效。`);
|
|
6295
6523
|
}
|
|
6296
6524
|
async permissions(contextKey, mode, options = {}) {
|
|
@@ -7214,7 +7442,7 @@ export class ProxySessionController {
|
|
|
7214
7442
|
await this.assertSessionTurnOwnership(existing, runtime);
|
|
7215
7443
|
this.store.attachSessionToContext(contextKey, existing.localSessionId);
|
|
7216
7444
|
this.store.setCurrentSession(contextKey, existing.localSessionId);
|
|
7217
|
-
this.outbound.registerSession(existing.localSessionId, contextKey, existing.title, existing.cwd, this.agentLabel(existing.agentName), existing.model, existing.modelProvider);
|
|
7445
|
+
this.outbound.registerSession(existing.localSessionId, contextKey, existing.title, existing.cwd, this.agentLabel(existing.agentName), existing.model, existing.modelProvider, existing.reasoningEffort);
|
|
7218
7446
|
await this.outbound.sendText(contextKey, `已切换到任务:${existing.title ?? existing.remoteSessionId ?? taskId}`);
|
|
7219
7447
|
return;
|
|
7220
7448
|
}
|
|
@@ -7241,7 +7469,7 @@ export class ProxySessionController {
|
|
|
7241
7469
|
lastTurnStatus: mapRemoteTurnStatus(remote.lastTurnStatus),
|
|
7242
7470
|
});
|
|
7243
7471
|
this.store.setCurrentSession(contextKey, localSessionId);
|
|
7244
|
-
this.outbound.registerSession(localSessionId, contextKey, remote.title ?? remote.preview, remote.cwd, this.agentLabel(agentName), remote.model, remote.modelProvider);
|
|
7472
|
+
this.outbound.registerSession(localSessionId, contextKey, remote.title ?? remote.preview, remote.cwd, this.agentLabel(agentName), remote.model, remote.modelProvider, remote.reasoningEffort);
|
|
7245
7473
|
await this.outbound.sendText(contextKey, `已切换到任务:${remote.title ?? remote.preview ?? remote.id}。历史消息不会重新发送。`);
|
|
7246
7474
|
}
|
|
7247
7475
|
async stopSessionReference(contextKey, taskId) {
|
|
@@ -8795,6 +9023,10 @@ function latestRemoteTimestamp(...values) {
|
|
|
8795
9023
|
.map(normalizeRemoteTimestamp);
|
|
8796
9024
|
return timestamps.length > 0 ? Math.max(...timestamps) : undefined;
|
|
8797
9025
|
}
|
|
9026
|
+
function assertWorkspaceSteerTurn(expected, active) {
|
|
9027
|
+
if (expected && expected !== active)
|
|
9028
|
+
throw new TurnNotSubmittedError("原轮次已结束或切换,未追加消息。");
|
|
9029
|
+
}
|
|
8798
9030
|
function isTurnStillRunning(status) {
|
|
8799
9031
|
return status === "starting"
|
|
8800
9032
|
|| status === "running"
|
|
@@ -9081,19 +9313,9 @@ function renderLocalTurnReference(snapshot, messageKind) {
|
|
|
9081
9313
|
? `[消息类型:AgentBot 思考卡片]\n${truncateMiddle(content, 48_000)}`
|
|
9082
9314
|
: undefined;
|
|
9083
9315
|
}
|
|
9084
|
-
function appendDownloadedFiles(prompt, files) {
|
|
9085
|
-
return `${prompt}\n\n参考文件(已下载到本地):\n${files.map((file, index) => `[文件 ${index + 1}:${file.fileName}] ${file.filePath}`).join("\n")}`;
|
|
9086
|
-
}
|
|
9087
9316
|
function defaultResourcePrompt(message) {
|
|
9088
9317
|
return defaultResourcePromptFromCounts(message.images?.length ?? 0, message.files?.length ?? 0);
|
|
9089
9318
|
}
|
|
9090
|
-
function defaultResourcePromptFromCounts(imageCount, fileCount) {
|
|
9091
|
-
if (imageCount > 0 && fileCount > 0)
|
|
9092
|
-
return "请查看附带的图片和文件";
|
|
9093
|
-
if (fileCount > 0)
|
|
9094
|
-
return fileCount === 1 ? "请查看这个文件" : "请查看这些文件";
|
|
9095
|
-
return imageCount === 1 ? "请查看这张图片" : "请查看这些图片";
|
|
9096
|
-
}
|
|
9097
9319
|
function isCommandMessage(message) {
|
|
9098
9320
|
const text = normalizeFeishuPostText(message.text).trimStart();
|
|
9099
9321
|
return text.startsWith("/") || text.startsWith("!");
|