@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
|
@@ -53,7 +53,9 @@ import { normalizeFeishuPostText } from "../feishu/InboundText.js";
|
|
|
53
53
|
import { RECENT_CONTEXT_LIMIT, RECENT_CONTEXT_IMAGE_LIMIT, RECENT_CONTEXT_TEXT_LIMIT, recentContextPrompt } from "../feishu/RecentMessageContext.js";
|
|
54
54
|
import { allowsFeishuUser } from "../feishu/ownerAccess.js";
|
|
55
55
|
import type { ScheduleCommand, ScheduledJob, ScheduleInput } from "../scheduling/types.js";
|
|
56
|
-
import { scheduleCommandSchema } from "../scheduling/types.js";
|
|
56
|
+
import { scheduleCommandSchema, scheduleDisplayPrompt } from "../scheduling/types.js";
|
|
57
|
+
import { appendPromptQuotes, promptQuoteInstruction, type PromptQuote } from "../utils/promptQuotes.js";
|
|
58
|
+
import { appendDownloadedFiles, defaultResourcePromptFromCounts, queuedPromptContent } from "../utils/promptAttachments.js";
|
|
57
59
|
import type { SettingsCatalog, SettingsSnapshot, SettingsStore } from "../config/SettingsStore.js";
|
|
58
60
|
import { renderSettingsCard } from "../feishu/SettingsCard.js";
|
|
59
61
|
import { renderSchedule, renderScheduleList, renderScheduleForm } from "../scheduling/ScheduleCards.js";
|
|
@@ -63,6 +65,7 @@ import type { OutboundRouter } from "../presentation/OutboundRouter.js";
|
|
|
63
65
|
import type { TurnActivity, TurnViewState } from "../presentation/turnViewTypes.js";
|
|
64
66
|
import { createTurnViewState, hydrateTurnViewState } from "../presentation/TurnStateReducer.js";
|
|
65
67
|
import { buildTurnGraphRows } from "../presentation/turnGraph.js";
|
|
68
|
+
import { splitMarkdown } from "../presentation/splitMarkdown.js";
|
|
66
69
|
import type { AgentRuntimeRegistry } from "../runtime/AgentRuntimeRegistry.js";
|
|
67
70
|
import { displayRuntimeError, isResponseContinuationError } from "../runtime/responseErrors.js";
|
|
68
71
|
import { TurnNotSubmittedError, TurnStoppedBeforeSubmissionError } from "../runtime/submissionErrors.js";
|
|
@@ -132,12 +135,27 @@ interface StartTurnOptions {
|
|
|
132
135
|
attemptId?: string;
|
|
133
136
|
messageId?: string;
|
|
134
137
|
displayPrompt?: string;
|
|
138
|
+
workspaceRequestId?: string;
|
|
139
|
+
onWorkspaceClaim?: () => void;
|
|
140
|
+
onWorkspaceSubmitting?: () => void;
|
|
135
141
|
preserveAttemptOnFailure?: boolean;
|
|
136
142
|
approvedPlanTurnId?: string;
|
|
137
143
|
responseContinuationTurnId?: string;
|
|
138
144
|
recoveryContinuationTurnId?: string;
|
|
139
145
|
}
|
|
140
146
|
|
|
147
|
+
interface WorkspacePromptSubmission {
|
|
148
|
+
requestId: string;
|
|
149
|
+
expectedTurnId?: string;
|
|
150
|
+
localImagePaths?: string[];
|
|
151
|
+
files?: Array<{ fileName: string; filePath: string }>;
|
|
152
|
+
quotes?: PromptQuote[];
|
|
153
|
+
queuedPrompt?: QueuedPromptRecord;
|
|
154
|
+
onClaim?: () => void;
|
|
155
|
+
onSubmitting(): void;
|
|
156
|
+
onPosted(): void;
|
|
157
|
+
}
|
|
158
|
+
|
|
141
159
|
interface PendingMessageReference {
|
|
142
160
|
contextKey: string;
|
|
143
161
|
userId?: string;
|
|
@@ -441,6 +459,7 @@ interface ModelCardOptions {
|
|
|
441
459
|
expectedProvider?: string;
|
|
442
460
|
sessionId?: string;
|
|
443
461
|
updateMessageId?: string;
|
|
462
|
+
quiet?: boolean;
|
|
444
463
|
}
|
|
445
464
|
|
|
446
465
|
interface ThinkingCardOptions extends ModelCardOptions {
|
|
@@ -670,10 +689,14 @@ export class ProxySessionController {
|
|
|
670
689
|
}
|
|
671
690
|
const currentId = this.store.getUserContext(message.contextKey)?.currentSessionId;
|
|
672
691
|
if (!this.store.inboundMessages.claim(message, currentId, currentId ? this.store.executionGeneration(currentId) : 0)) return;
|
|
673
|
-
if (this.
|
|
692
|
+
if (!this.acceptingInboundMessages) return;
|
|
674
693
|
await this.processAcceptedMessage(message);
|
|
675
694
|
}
|
|
676
695
|
|
|
696
|
+
get acceptingInboundMessages(): boolean {
|
|
697
|
+
return !this.inboundPaused && !this.recoveryClosed;
|
|
698
|
+
}
|
|
699
|
+
|
|
677
700
|
get pendingInboundMessages(): number {
|
|
678
701
|
return this.inboundInFlight.size + this.inboundActionsInFlight;
|
|
679
702
|
}
|
|
@@ -1631,35 +1654,44 @@ export class ProxySessionController {
|
|
|
1631
1654
|
return { session, snapshot, remote };
|
|
1632
1655
|
}
|
|
1633
1656
|
|
|
1634
|
-
async controlSetTaskTitle(localSessionId: string, title: string): Promise<string> {
|
|
1657
|
+
async controlSetTaskTitle(localSessionId: string, title: string, source: "cli" | "workspace" = "cli"): Promise<string> {
|
|
1635
1658
|
const normalizedTitle = normalizeTaskTitle(title);
|
|
1636
1659
|
if (!normalizedTitle) throw new Error("The task title cannot be empty.");
|
|
1637
1660
|
const record = this.store.getSession(localSessionId);
|
|
1638
|
-
if (!record || record.status === "closed") throw new Error(`Task not found: ${localSessionId}`);
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1661
|
+
if (!record || (record.status === "closed" && source === "cli")) throw new Error(`Task not found: ${localSessionId}`);
|
|
1662
|
+
if (record.status !== "closed") {
|
|
1663
|
+
const loaded = await this.loadSession(record);
|
|
1664
|
+
if (loaded.runtime.setTitle) await loaded.runtime.setTitle(record.localSessionId, normalizedTitle);
|
|
1665
|
+
else loaded.session.title = normalizedTitle;
|
|
1666
|
+
}
|
|
1642
1667
|
this.store.updateRuntimeSession(record.localSessionId, { title: normalizedTitle });
|
|
1643
1668
|
this.outbound.updateSessionTitle(record.localSessionId, normalizedTitle);
|
|
1644
1669
|
this.store.audit(record.contextKey, "session_title_changed", {
|
|
1645
1670
|
localSessionId: record.localSessionId,
|
|
1646
1671
|
title: normalizedTitle,
|
|
1647
|
-
source
|
|
1672
|
+
source,
|
|
1648
1673
|
});
|
|
1649
1674
|
return `Task title changed to: ${normalizedTitle}`;
|
|
1650
1675
|
}
|
|
1651
1676
|
|
|
1652
|
-
async controlSendTaskPrompt(localSessionId: string, text: string, workspace?: {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
const
|
|
1656
|
-
|
|
1677
|
+
async controlSendTaskPrompt(localSessionId: string, text: string, workspace?: WorkspacePromptSubmission): Promise<string> {
|
|
1678
|
+
const images = workspace?.localImagePaths;
|
|
1679
|
+
const files = workspace?.files;
|
|
1680
|
+
const quotes = workspace?.quotes;
|
|
1681
|
+
const queued = workspace?.queuedPrompt;
|
|
1682
|
+
const promptText = queued ? queued.displayPrompt ?? queued.text
|
|
1683
|
+
: text.trim() || promptQuoteInstruction(quotes) || (files?.length ? defaultResourcePromptFromCounts(images?.length ?? 0, files.length) : "");
|
|
1684
|
+
const modelPrompt = queued?.text ?? appendPromptQuotes(promptText, quotes);
|
|
1685
|
+
const echoedPrompt = files?.length ? `${promptText}\n\n附件:${files.map((file) => file.fileName).join("、")}` : promptText;
|
|
1686
|
+
if (!modelPrompt.trim() && !images?.length) throw new Error("The Prompt cannot be empty.");
|
|
1657
1687
|
const record = this.store.getSession(localSessionId);
|
|
1658
1688
|
if (!record || record.status === "closed") throw new Error(`Task not found: ${localSessionId}`);
|
|
1659
1689
|
const runtime = this.runtimes.forAgent(record.agentName);
|
|
1660
1690
|
const activeTurnId = runtime.getSession(localSessionId)?.activeTurnId;
|
|
1691
|
+
const expectedTurnId = workspace?.expectedTurnId;
|
|
1692
|
+
assertWorkspaceSteerTurn(expectedTurnId, activeTurnId);
|
|
1661
1693
|
const routedContextKey = this.outbound.getSessionContextKey(localSessionId);
|
|
1662
|
-
const responseContextKey = (activeTurnId ? this.store.getTurnContextKey(activeTurnId) ?? routedContextKey : undefined)
|
|
1694
|
+
const responseContextKey = queued?.contextKey ?? (activeTurnId ? this.store.getTurnContextKey(activeTurnId) ?? routedContextKey : undefined)
|
|
1663
1695
|
?? (record.lastTurnId ? this.store.getTurnContextKey(record.lastTurnId) : undefined)
|
|
1664
1696
|
?? routedContextKey
|
|
1665
1697
|
?? record.contextKey;
|
|
@@ -1670,17 +1702,25 @@ export class ProxySessionController {
|
|
|
1670
1702
|
? turnViewSnapshot(this.store.getTurnSnapshot(activeTurnId))
|
|
1671
1703
|
: undefined;
|
|
1672
1704
|
const routedReplyTarget = this.outbound.getSessionReplyTarget(localSessionId);
|
|
1673
|
-
const existingReplyTarget =
|
|
1705
|
+
const existingReplyTarget = queued ? (queued.replyMessageId ? { messageId: queued.replyMessageId, replyInThread: true as const } : undefined)
|
|
1706
|
+
: activeSnapshot?.replyTarget
|
|
1674
1707
|
?? (activeTurnId ? routedReplyTarget : undefined)
|
|
1675
1708
|
?? lastSnapshot?.replyTarget
|
|
1676
1709
|
?? routedReplyTarget;
|
|
1677
|
-
|
|
1710
|
+
const threaded = isThreadContextKey(responseContextKey);
|
|
1711
|
+
if (threaded && !existingReplyTarget && !workspace) {
|
|
1678
1712
|
throw new Error("Could not resolve the target task's thread reply location. The Prompt was not sent.");
|
|
1679
1713
|
}
|
|
1680
1714
|
const scopedRecord = this.store.getSessionForContext(localSessionId, responseContextKey)
|
|
1681
1715
|
?? { ...record, contextKey: responseContextKey };
|
|
1682
1716
|
const previous = this.messageQueues.get(responseContextKey) ?? Promise.resolve();
|
|
1683
|
-
const
|
|
1717
|
+
const send = async () => {
|
|
1718
|
+
if (queued) {
|
|
1719
|
+
const current = this.store.getQueuedPrompt(localSessionId, queued.promptId);
|
|
1720
|
+
if (!current || current.text !== queued.text || current.displayPrompt !== queued.displayPrompt) {
|
|
1721
|
+
throw new TurnNotSubmittedError("排队消息已被修改或离开队列。");
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1684
1724
|
this.outbound.registerSession(
|
|
1685
1725
|
scopedRecord.localSessionId,
|
|
1686
1726
|
responseContextKey,
|
|
@@ -1689,34 +1729,92 @@ export class ProxySessionController {
|
|
|
1689
1729
|
this.agentLabel(scopedRecord.agentName),
|
|
1690
1730
|
scopedRecord.model,
|
|
1691
1731
|
scopedRecord.modelProvider,
|
|
1732
|
+
scopedRecord.reasoningEffort,
|
|
1692
1733
|
);
|
|
1693
1734
|
if (workspace && this.store.getSession(localSessionId)?.status === "closed") throw new Error("任务已归档。");
|
|
1694
|
-
|
|
1695
|
-
const
|
|
1735
|
+
assertWorkspaceSteerTurn(expectedTurnId, runtime.getSession(localSessionId)?.activeTurnId);
|
|
1736
|
+
const post = () => this.outbound.withReplyTarget(
|
|
1696
1737
|
responseContextKey,
|
|
1697
1738
|
existingReplyTarget,
|
|
1698
|
-
() =>
|
|
1739
|
+
() => images?.length
|
|
1740
|
+
? this.outbound.sendPromptImages(responseContextKey, echoedPrompt, images)
|
|
1741
|
+
: this.outbound.sendText(responseContextKey, echoedPrompt),
|
|
1699
1742
|
);
|
|
1700
|
-
workspace
|
|
1701
|
-
const turnReplyTarget =
|
|
1743
|
+
const promptMessageId = workspace ? undefined : await post();
|
|
1744
|
+
const turnReplyTarget = threaded
|
|
1702
1745
|
? promptMessageId
|
|
1703
1746
|
? { messageId: promptMessageId, replyInThread: true as const }
|
|
1704
1747
|
: existingReplyTarget
|
|
1705
1748
|
: undefined;
|
|
1706
|
-
await this.promptSession(scopedRecord, responseContextKey,
|
|
1749
|
+
await this.promptSession(scopedRecord, responseContextKey, !queued && files?.length ? appendDownloadedFiles(modelPrompt, files) : modelPrompt,
|
|
1750
|
+
queued?.messageId, turnReplyTarget, images, queued?.displayPrompt ?? (files?.length || quotes?.length ? promptText : undefined), workspace);
|
|
1751
|
+
if (workspace && !queued?.messageId) this.deliverWorkspacePrompt(post, localSessionId, workspace, !threaded || Boolean(existingReplyTarget));
|
|
1707
1752
|
this.store.audit(responseContextKey, "task_prompt_sent", {
|
|
1708
1753
|
localSessionId,
|
|
1709
1754
|
source: workspace ? "workspace" : "cli",
|
|
1710
1755
|
requestId: workspace?.requestId,
|
|
1711
1756
|
});
|
|
1712
|
-
}
|
|
1757
|
+
};
|
|
1758
|
+
const next = previous.catch(() => undefined).then(() => queued ? this.serializeQueuedPromptStart(localSessionId, send) : send());
|
|
1713
1759
|
this.messageQueues.set(responseContextKey, next);
|
|
1714
1760
|
try {
|
|
1715
1761
|
await next;
|
|
1716
1762
|
} finally {
|
|
1717
1763
|
if (this.messageQueues.get(responseContextKey) === next) this.messageQueues.delete(responseContextKey);
|
|
1718
1764
|
}
|
|
1719
|
-
|
|
1765
|
+
const target = record.title ?? record.remoteSessionId ?? record.localSessionId;
|
|
1766
|
+
return workspace ? `The Prompt was submitted to the task: ${target}`
|
|
1767
|
+
: `The Prompt was posted to the original chat and submitted to the task: ${target}`;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
async controlSendWorkspaceQueuedPrompt(prompt: QueuedPromptRecord, submission: Pick<WorkspacePromptSubmission, "requestId" | "onSubmitting" | "onPosted">): Promise<void> {
|
|
1771
|
+
const scheduled = this.store.schedules.getRun(prompt.promptId);
|
|
1772
|
+
const requestId = prompt.promptId.startsWith("workspace:") ? prompt.promptId.slice("workspace:".length)
|
|
1773
|
+
: scheduled ? scheduled.id.slice("schedule_run_".length) : submission.requestId;
|
|
1774
|
+
let claimed = false, submitting = false;
|
|
1775
|
+
let finishDispatch: (() => void) | undefined;
|
|
1776
|
+
try {
|
|
1777
|
+
await this.controlSendTaskPrompt(prompt.localSessionId, prompt.displayPrompt ?? prompt.text, {
|
|
1778
|
+
...submission, requestId, queuedPrompt: prompt, localImagePaths: prompt.localImagePaths,
|
|
1779
|
+
onClaim: () => {
|
|
1780
|
+
if (claimed) return;
|
|
1781
|
+
if (scheduled) this.assertScheduleTarget(this.store.schedules.require(scheduled.jobId));
|
|
1782
|
+
if (!this.store.claimQueuedPromptForImmediateSend(prompt)) throw new TurnNotSubmittedError("排队消息已被修改或离开队列。");
|
|
1783
|
+
claimed = true;
|
|
1784
|
+
finishDispatch = this.store.trackQueuedPromptDispatch(prompt);
|
|
1785
|
+
},
|
|
1786
|
+
onSubmitting: () => {
|
|
1787
|
+
submitting = true;
|
|
1788
|
+
submission.onSubmitting();
|
|
1789
|
+
},
|
|
1790
|
+
});
|
|
1791
|
+
if (scheduled) this.store.schedules.finish(scheduled.id, "cancelled", "本次排队消息已改为手动发送。");
|
|
1792
|
+
} catch (error) {
|
|
1793
|
+
const known = error instanceof TurnNotSubmittedError ? error
|
|
1794
|
+
: error instanceof Error && error.cause instanceof TurnNotSubmittedError ? new TurnNotSubmittedError(error.message) : undefined;
|
|
1795
|
+
if (claimed && (!submitting || known)) this.store.restoreQueuedPromptAfterImmediateSend(prompt);
|
|
1796
|
+
else if (claimed && scheduled) this.store.schedules.finish(scheduled.id, "unknown", "手动发送的提交结果待核实。");
|
|
1797
|
+
throw known ?? error;
|
|
1798
|
+
} finally {
|
|
1799
|
+
finishDispatch?.();
|
|
1800
|
+
if (claimed) void this.refreshPromptQueueCards(prompt.localSessionId).catch(error => {
|
|
1801
|
+
this.logger.warn({ error, promptId: prompt.promptId }, "Failed to refresh the prompt queue after an immediate send.");
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
private deliverWorkspacePrompt(
|
|
1807
|
+
post: () => Promise<string | undefined>, sessionId: string, request: { requestId: string; onPosted(): void }, routed: boolean,
|
|
1808
|
+
): void {
|
|
1809
|
+
const details = { sessionId, requestId: request.requestId };
|
|
1810
|
+
if (!routed) {
|
|
1811
|
+
this.logger.warn(details, "Workspace Prompt submitted locally without a Feishu thread reply target.");
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
this.inboundActionsInFlight += 1;
|
|
1815
|
+
void Promise.resolve().then(post).then(() => request.onPosted()).catch((error: unknown) => {
|
|
1816
|
+
this.logger.warn({ ...details, error }, "Failed to deliver a Workspace Prompt to Feishu.");
|
|
1817
|
+
}).finally(() => { this.inboundActionsInFlight -= 1; });
|
|
1720
1818
|
}
|
|
1721
1819
|
|
|
1722
1820
|
async controlCreateTaskGroup(
|
|
@@ -1856,6 +1954,35 @@ export class ProxySessionController {
|
|
|
1856
1954
|
));
|
|
1857
1955
|
}
|
|
1858
1956
|
|
|
1957
|
+
controlWorkspaceAgents() {
|
|
1958
|
+
const agents = Object.entries(this.config.agents).filter(([, agent]) => agent.kind === "app-server")
|
|
1959
|
+
.map(([name, agent]) => ({ name, title: agent.title }));
|
|
1960
|
+
return { agents, defaultAgent: agents.find(({ name }) => name === this.config.defaults.agent)?.name ?? agents[0]?.name };
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
async controlWorkspaceDraftSettings(agentName: string) {
|
|
1964
|
+
const agent = this.ensureAgent(agentName);
|
|
1965
|
+
if (agent.kind !== "app-server") throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1966
|
+
const { model, modelProvider, reasoningEffort } = agent.defaults ?? {};
|
|
1967
|
+
const models = await this.runtimes.forAgent(agentName).listModels(modelProvider, model);
|
|
1968
|
+
return { model, provider: modelProvider, thinking: reasoningEffort, models };
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
controlCreateWorkspaceTask(localSessionId: string, owner: string, title: string, agentName: string, cwd?: string,
|
|
1972
|
+
model?: string, reasoningEffort?: string): SessionRecord {
|
|
1973
|
+
const agent = this.ensureAgent(agentName);
|
|
1974
|
+
if (agent.kind !== "app-server") throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1975
|
+
const settings = model
|
|
1976
|
+
? { ...agent.defaults, model, reasoningEffort }
|
|
1977
|
+
: mergeExecutionSettings(agent.defaults ?? {}, { reasoningEffort });
|
|
1978
|
+
const initialTitle = normalizeTaskTitle(title);
|
|
1979
|
+
const contextKey = `open_id:${owner}`;
|
|
1980
|
+
const root = cwd ?? createProjectlessWorkspace({ prompt: initialTitle }).cwd;
|
|
1981
|
+
this.store.createSession({ localSessionId, contextKey, agentName, cwd: root, status: "ready" });
|
|
1982
|
+
this.store.updateRuntimeSession(localSessionId, { ...settings, title: initialTitle, runtimeKind: this.runtimes.forAgent(agentName).kind });
|
|
1983
|
+
return this.store.getSession(localSessionId)!;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1859
1986
|
async controlForkTask(localSessionId: string): Promise<{
|
|
1860
1987
|
sourceLocalSessionId: string;
|
|
1861
1988
|
sourceTurnId: string;
|
|
@@ -1884,6 +2011,14 @@ export class ProxySessionController {
|
|
|
1884
2011
|
};
|
|
1885
2012
|
}
|
|
1886
2013
|
|
|
2014
|
+
async controlForkWorkspaceTask(localSessionId: string, turnId: string): Promise<SessionRecord> {
|
|
2015
|
+
const source = this.requireControlSession(localSessionId);
|
|
2016
|
+
const plan = this.prepareForkSessionFromTurn(source, turnId, undefined, "当前任务");
|
|
2017
|
+
const origin = this.store.getTurnRuntimeOrigin(turnId);
|
|
2018
|
+
if (origin?.agentName === source.agentName) plan.remoteSessionId = origin.remoteSessionId;
|
|
2019
|
+
return (await this.forkSessionIntoContext(this.controlSessionContextKey(source), plan, false)).record;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
1887
2022
|
async controlSwitchTask(
|
|
1888
2023
|
localSessionId: string,
|
|
1889
2024
|
targetLocalSessionId?: string,
|
|
@@ -1902,9 +2037,18 @@ export class ProxySessionController {
|
|
|
1902
2037
|
await this.scheduleNextQueuedPrompt(localSessionId);
|
|
1903
2038
|
}
|
|
1904
2039
|
|
|
1905
|
-
async notifySchedule(job: ScheduledJob, text: string): Promise<void> {
|
|
2040
|
+
async notifySchedule(job: ScheduledJob, text: string, images?: string[]): Promise<void> {
|
|
1906
2041
|
const target = job.replyMessageId ? { messageId: job.replyMessageId, replyInThread: true as const } : undefined;
|
|
1907
|
-
await this.outbound.withReplyTarget(job.contextKey, target, () =>
|
|
2042
|
+
await this.outbound.withReplyTarget(job.contextKey, target, async () => {
|
|
2043
|
+
const parts = splitMarkdown(text);
|
|
2044
|
+
if (images?.length) {
|
|
2045
|
+
const last = parts.pop() ?? "";
|
|
2046
|
+
for (const part of parts) await this.outbound.sendText(job.contextKey, part);
|
|
2047
|
+
await this.outbound.sendPromptImages(job.contextKey, last, images);
|
|
2048
|
+
} else {
|
|
2049
|
+
for (const part of parts) await this.outbound.sendText(job.contextKey, part);
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
1908
2052
|
}
|
|
1909
2053
|
|
|
1910
2054
|
async controlSchedule(command: ScheduleCommand, localSessionId?: string): Promise<unknown> {
|
|
@@ -1932,15 +2076,10 @@ export class ProxySessionController {
|
|
|
1932
2076
|
await this.outbound.withReplyTarget(job.contextKey, target, () => this.showSchedule(updated));
|
|
1933
2077
|
return updated;
|
|
1934
2078
|
}
|
|
1935
|
-
if (command.operation === "run") {
|
|
1936
|
-
this.
|
|
1937
|
-
const run = this.store.schedules.dispatch(job, Date.now(), Date.now(), { manual: true });
|
|
1938
|
-
await this.drainScheduledPrompts(job.localSessionId);
|
|
1939
|
-
return run;
|
|
2079
|
+
if (command.operation === "run" || command.operation === "resume" || command.operation === "pause" || command.operation === "delete") {
|
|
2080
|
+
return this.controlWorkspaceScheduleAction(job, command.operation);
|
|
1940
2081
|
}
|
|
1941
|
-
|
|
1942
|
-
if (command.operation === "resume") this.assertScheduleTarget(job);
|
|
1943
|
-
return this.store.schedules.change(job.id, job.revision, command.operation as "pause" | "resume" | "delete");
|
|
2082
|
+
throw new Error("无效的定时任务操作。");
|
|
1944
2083
|
}
|
|
1945
2084
|
|
|
1946
2085
|
private requireSettingsOwner(userId?: string): SettingsStore {
|
|
@@ -2009,11 +2148,33 @@ export class ProxySessionController {
|
|
|
2009
2148
|
await this.outbound.updateInteractiveCard(action.contextKey, messageId, renderSettingsCard(snapshot, action.contextKey, notice));
|
|
2010
2149
|
}
|
|
2011
2150
|
|
|
2012
|
-
|
|
2151
|
+
controlCreateWorkspaceSchedule(localSessionId: string, input: ScheduleInput, request: string,
|
|
2152
|
+
upload?: { attachments?: ScheduledJob["attachments"]; fingerprint: string }): ScheduledJob {
|
|
2153
|
+
const task = this.requireControlSession(localSessionId);
|
|
2154
|
+
return this.createSchedule(input, localSessionId, this.controlSessionContextKey(task), this.controlSessionReplyTarget(task)?.messageId, request, upload);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
controlEditWorkspaceSchedule(job: ScheduledJob, input: ScheduleInput): ScheduledJob {
|
|
2158
|
+
this.assertScheduleTarget(job);
|
|
2159
|
+
const status = job.status === "paused" || job.status === "draft" ? job.status : "enabled";
|
|
2160
|
+
return this.store.schedules.edit(job.id, job.revision, input, undefined, status);
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
async controlWorkspaceScheduleAction(job: ScheduledJob, action: "confirm" | "pause" | "resume" | "delete" | "run") {
|
|
2164
|
+
if (action === "confirm" || action === "resume" || action === "run") this.assertScheduleTarget(job);
|
|
2165
|
+
if (action !== "run") return this.store.schedules.change(job.id, job.revision, action);
|
|
2166
|
+
const run = this.store.schedules.dispatch(job, Date.now(), Date.now(), { manual: true });
|
|
2167
|
+
await this.drainScheduledPrompts(job.localSessionId);
|
|
2168
|
+
return run;
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
private createSchedule(input: ScheduleInput, localSessionId: string, contextKey: string, replyMessageId?: string, enableRequest?: string,
|
|
2172
|
+
upload?: { attachments?: ScheduledJob["attachments"]; fingerprint: string }): ScheduledJob {
|
|
2013
2173
|
if (!this.config.feishu.userOpenId) throw new Error("请先配置 Agent Bot 所有者,才能创建定时任务。");
|
|
2014
2174
|
this.requireSession(contextKey, localSessionId);
|
|
2015
2175
|
if (isThreadContextKey(contextKey) && !replyMessageId) throw new Error("缺少话题回复位置,请在原话题中创建计划。");
|
|
2016
|
-
|
|
2176
|
+
if (enableRequest && !this.outbound.canRoute(contextKey)) throw new Error("任务的原始会话不可用,无法创建定时计划。");
|
|
2177
|
+
return this.store.schedules.create(input, { localSessionId, contextKey, replyMessageId, ownerId: this.config.feishu.userOpenId }, undefined, enableRequest, upload);
|
|
2017
2178
|
}
|
|
2018
2179
|
|
|
2019
2180
|
private assertScheduleTarget(job: ScheduledJob): void {
|
|
@@ -2074,7 +2235,10 @@ export class ProxySessionController {
|
|
|
2074
2235
|
const string = (key: string) => typeof form[key] === "string" ? form[key] as string : "";
|
|
2075
2236
|
const input: ScheduleInput = { name: string("name"), prompt: string("prompt"), timeZone: string("timeZone"),
|
|
2076
2237
|
maxDelayMinutes: Number(string("maxDelayMinutes")), catchUpMinutes: Number(string("catchUpMinutes")),
|
|
2238
|
+
...(string("startsAt").trim() ? { startsAt: string("startsAt") } : {}),
|
|
2239
|
+
...(string("endsAt").trim() ? { endsAt: string("endsAt") } : {}),
|
|
2077
2240
|
...(string("cron").trim() ? { cron: string("cron") } : {}), ...(string("at").trim() ? { at: string("at") } : {}) };
|
|
2241
|
+
if (job?.spec.prompt && job.spec.prompt.length > 1000 && !input.prompt.trim()) input.prompt = job.spec.prompt;
|
|
2078
2242
|
const updated = job ? this.store.schedules.edit(job.id, job.revision, input)
|
|
2079
2243
|
: this.createSchedule(input, String(action.value.sessionId ?? ""), action.contextKey, replyTarget?.messageId);
|
|
2080
2244
|
return this.showSchedule(updated, messageId);
|
|
@@ -2090,23 +2254,48 @@ export class ProxySessionController {
|
|
|
2090
2254
|
await this.showSchedule(updated, messageId);
|
|
2091
2255
|
}
|
|
2092
2256
|
|
|
2093
|
-
async controlQueueTaskPrompt(localSessionId: string, text: string
|
|
2094
|
-
|
|
2095
|
-
|
|
2257
|
+
async controlQueueTaskPrompt(localSessionId: string, text: string, localImagePaths?: string[], workspaceRequestId?: string,
|
|
2258
|
+
files?: Array<{ fileName: string; filePath: string }>, quotes?: PromptQuote[]): Promise<{ promptId: string; queued: number }> {
|
|
2259
|
+
const promptText = text.trim() || promptQuoteInstruction(quotes) || (files?.length ? defaultResourcePromptFromCounts(localImagePaths?.length ?? 0, files.length) : "");
|
|
2260
|
+
const modelPrompt = appendPromptQuotes(promptText, quotes);
|
|
2261
|
+
if (!promptText && !localImagePaths?.length) throw new Error("The queued Prompt cannot be empty.");
|
|
2096
2262
|
const record = this.requireControlSession(localSessionId);
|
|
2097
2263
|
const contextKey = this.controlSessionContextKey(record);
|
|
2098
2264
|
const replyTarget = this.controlSessionReplyTarget(record);
|
|
2099
|
-
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey,
|
|
2265
|
+
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, files?.length ? appendDownloadedFiles(modelPrompt, files) : modelPrompt, {
|
|
2266
|
+
replyTarget, localImagePaths, promptId: workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined,
|
|
2267
|
+
displayPrompt: files?.length || quotes?.length ? promptText : undefined,
|
|
2268
|
+
});
|
|
2100
2269
|
this.store.audit(contextKey, "queued_prompt_added", {
|
|
2101
2270
|
promptId: queued.promptId,
|
|
2102
2271
|
localSessionId: record.localSessionId,
|
|
2103
|
-
source: "cli",
|
|
2272
|
+
source: workspaceRequestId ? "workspace" : "cli",
|
|
2104
2273
|
});
|
|
2105
2274
|
const queuedCount = this.store.countQueuedPrompts(record.localSessionId);
|
|
2106
2275
|
await this.scheduleNextQueuedPrompt(record.localSessionId);
|
|
2276
|
+
if (this.store.hasQueuedPrompt(queued.promptId)) await this.refreshPromptQueueCards(record.localSessionId);
|
|
2107
2277
|
return { promptId: queued.promptId, queued: queuedCount };
|
|
2108
2278
|
}
|
|
2109
2279
|
|
|
2280
|
+
async controlCancelWorkspaceQueue(localSessionId: string, promptId: string, request: string): Promise<boolean> {
|
|
2281
|
+
const task = this.requireControlSession(localSessionId);
|
|
2282
|
+
const { cancelled, prompt } = this.store.cancelWorkspaceQueuedPrompt(promptId, localSessionId, request);
|
|
2283
|
+
if (prompt) await this.finishQueuedPromptCancellation(prompt, this.controlSessionContextKey(task)).catch(error => {
|
|
2284
|
+
this.logger.warn({ error, localSessionId, promptId }, "Failed to refresh a cancelled Workspace prompt.");
|
|
2285
|
+
});
|
|
2286
|
+
return cancelled;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
async controlEditWorkspaceQueue(prompt: QueuedPromptRecord, content: Pick<QueuedPromptRecord, "text" | "displayPrompt">): Promise<boolean> {
|
|
2290
|
+
this.requireControlSession(prompt.localSessionId);
|
|
2291
|
+
if (!this.store.updateQueuedPrompt(prompt, content)) return false;
|
|
2292
|
+
this.store.audit(prompt.contextKey, "queued_prompt_edited", {
|
|
2293
|
+
promptId: prompt.promptId, localSessionId: prompt.localSessionId, source: "workspace",
|
|
2294
|
+
});
|
|
2295
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
2296
|
+
return true;
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2110
2299
|
controlTaskAgent(localSessionId: string, agentName?: string): {
|
|
2111
2300
|
current: string;
|
|
2112
2301
|
agents: Array<{ name: string; title: string }>;
|
|
@@ -2128,6 +2317,7 @@ export class ProxySessionController {
|
|
|
2128
2317
|
localSessionId: string,
|
|
2129
2318
|
setting?: "provider" | "model" | "thinking" | "permissions",
|
|
2130
2319
|
value?: string,
|
|
2320
|
+
options: { quiet?: boolean } = {},
|
|
2131
2321
|
): Promise<{
|
|
2132
2322
|
session: SessionRecord;
|
|
2133
2323
|
providers: Awaited<ReturnType<NonNullable<AgentRuntime["listModelProviders"]>>>;
|
|
@@ -2142,13 +2332,13 @@ export class ProxySessionController {
|
|
|
2142
2332
|
if (setting && nextValue) {
|
|
2143
2333
|
const contextKey = this.controlSessionContextKey(record);
|
|
2144
2334
|
await this.outbound.withReplyTarget(contextKey, this.controlSessionReplyTarget(record), async () => {
|
|
2145
|
-
const
|
|
2146
|
-
if (setting === "provider") await this.selectProvider(contextKey, nextValue,
|
|
2147
|
-
else if (setting === "model") await this.model(contextKey, nextValue,
|
|
2148
|
-
else if (setting === "thinking") await this.thinking(contextKey, nextValue,
|
|
2335
|
+
const target = { sessionId: record.localSessionId, quiet: options.quiet };
|
|
2336
|
+
if (setting === "provider") await this.selectProvider(contextKey, nextValue, target);
|
|
2337
|
+
else if (setting === "model") await this.model(contextKey, nextValue, target);
|
|
2338
|
+
else if (setting === "thinking") await this.thinking(contextKey, nextValue, target);
|
|
2149
2339
|
else {
|
|
2150
2340
|
if (nextValue !== "auto" && nextValue !== "confirm") throw new Error("task permissions accepts auto or confirm.");
|
|
2151
|
-
await this.permissions(contextKey, nextValue,
|
|
2341
|
+
await this.permissions(contextKey, nextValue, target);
|
|
2152
2342
|
}
|
|
2153
2343
|
});
|
|
2154
2344
|
}
|
|
@@ -2244,11 +2434,11 @@ export class ProxySessionController {
|
|
|
2244
2434
|
};
|
|
2245
2435
|
}
|
|
2246
2436
|
|
|
2247
|
-
async controlResetTaskToTurn(localSessionId: string, turnId: string): Promise<SessionRecord> {
|
|
2437
|
+
async controlResetTaskToTurn(localSessionId: string, turnId: string, options?: { quiet?: boolean }): Promise<SessionRecord> {
|
|
2248
2438
|
const record = this.requireControlSession(localSessionId);
|
|
2249
2439
|
const contextKey = this.controlSessionContextKey(record);
|
|
2250
2440
|
await this.runSessionReset(record.localSessionId, async () => {
|
|
2251
|
-
await this.outbound.sendText(contextKey, TURN_RESET_STARTED_MESSAGE);
|
|
2441
|
+
if (!options?.quiet) await this.outbound.sendText(contextKey, TURN_RESET_STARTED_MESSAGE);
|
|
2252
2442
|
await this.performSessionReset(contextKey, record, turnId, false);
|
|
2253
2443
|
});
|
|
2254
2444
|
return this.store.getSession(record.localSessionId) ?? record;
|
|
@@ -2608,6 +2798,7 @@ export class ProxySessionController {
|
|
|
2608
2798
|
this.agentLabel(session.agentName),
|
|
2609
2799
|
session.model,
|
|
2610
2800
|
session.modelProvider,
|
|
2801
|
+
session.reasoningEffort,
|
|
2611
2802
|
);
|
|
2612
2803
|
if (!session.lastTurnId) continue;
|
|
2613
2804
|
void this.outbound.resumeDelivery(session.localSessionId, turnContextKey, session.lastTurnId).catch((error: unknown) => {
|
|
@@ -2638,19 +2829,26 @@ export class ProxySessionController {
|
|
|
2638
2829
|
}
|
|
2639
2830
|
}
|
|
2640
2831
|
|
|
2641
|
-
async recoverInterruptedTasks(): Promise<void> {
|
|
2832
|
+
async recoverInterruptedTasks(updateRecoveryAttemptIds: readonly string[] = []): Promise<void> {
|
|
2642
2833
|
if (this.startupRecovery) return this.startupRecovery;
|
|
2643
|
-
const recovery = this.runStartupRecovery();
|
|
2834
|
+
const recovery = this.runStartupRecovery(new Set(updateRecoveryAttemptIds));
|
|
2644
2835
|
this.startupRecovery = recovery;
|
|
2645
2836
|
return recovery;
|
|
2646
2837
|
}
|
|
2647
2838
|
|
|
2648
|
-
private async runStartupRecovery(): Promise<void> {
|
|
2839
|
+
private async runStartupRecovery(updateRecoveryAttempts: ReadonlySet<string>): Promise<void> {
|
|
2649
2840
|
await this.recoverUnprocessedMessages();
|
|
2650
2841
|
await this.finishPersistedCancellationRequests();
|
|
2651
2842
|
await this.recoverShellCommandJobs();
|
|
2652
2843
|
const recoveryCutoff = Date.now() - RECOVERY_ACTIVITY_WINDOW_MS;
|
|
2653
2844
|
const cutoff = new Date(recoveryCutoff).toISOString();
|
|
2845
|
+
for (const attemptId of updateRecoveryAttempts) {
|
|
2846
|
+
const attempt = this.store.getTurnAttempt(attemptId);
|
|
2847
|
+
const session = attempt && this.store.getSession(attempt.localSessionId);
|
|
2848
|
+
if (attempt && session && this.canContinueAfterRestart(attempt, session)) {
|
|
2849
|
+
this.store.prepareInterruptedTurnAttemptRecovery(attemptId, new Date(0).toISOString());
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2654
2852
|
for (const attempt of this.store.listRecentlyInterruptedTurnAttempts(cutoff)) {
|
|
2655
2853
|
const session = this.store.getSession(attempt.localSessionId);
|
|
2656
2854
|
if (session && this.canContinueAfterRestart(attempt, session)) {
|
|
@@ -2659,7 +2857,7 @@ export class ProxySessionController {
|
|
|
2659
2857
|
}
|
|
2660
2858
|
this.backfillTurnAttemptsForUpgrade();
|
|
2661
2859
|
const attempts = this.store.listIncompleteTurnAttempts();
|
|
2662
|
-
const recentAttempts = attempts.filter((attempt) => isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2860
|
+
const recentAttempts = attempts.filter((attempt) => updateRecoveryAttempts.has(attempt.attemptId) || isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2663
2861
|
if (recentAttempts.length > 0) {
|
|
2664
2862
|
this.logger.warn(
|
|
2665
2863
|
{ attemptIds: recentAttempts.map((attempt) => attempt.attemptId) },
|
|
@@ -2667,7 +2865,7 @@ export class ProxySessionController {
|
|
|
2667
2865
|
);
|
|
2668
2866
|
}
|
|
2669
2867
|
for (const attempt of attempts) {
|
|
2670
|
-
if (!isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2868
|
+
if (!updateRecoveryAttempts.has(attempt.attemptId) && !isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2671
2869
|
await this.expireStaleTurnAttempt(attempt);
|
|
2672
2870
|
continue;
|
|
2673
2871
|
}
|
|
@@ -2769,6 +2967,7 @@ export class ProxySessionController {
|
|
|
2769
2967
|
this.agentLabel(session.agentName),
|
|
2770
2968
|
session.model,
|
|
2771
2969
|
session.modelProvider,
|
|
2970
|
+
session.reasoningEffort,
|
|
2772
2971
|
);
|
|
2773
2972
|
}
|
|
2774
2973
|
try {
|
|
@@ -2990,6 +3189,7 @@ export class ProxySessionController {
|
|
|
2990
3189
|
this.agentLabel(session.agentName),
|
|
2991
3190
|
session.model,
|
|
2992
3191
|
session.modelProvider,
|
|
3192
|
+
session.reasoningEffort,
|
|
2993
3193
|
);
|
|
2994
3194
|
if (announce) {
|
|
2995
3195
|
await this.outbound.withReplyTarget(contextKey, replyTarget, () =>
|
|
@@ -3168,7 +3368,7 @@ export class ProxySessionController {
|
|
|
3168
3368
|
if (this.store.schedules.getRun(attempt.attemptId)) this.store.schedules.finish(attempt.attemptId, "unknown", message);
|
|
3169
3369
|
if (!session || session.status === "closed") return;
|
|
3170
3370
|
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd,
|
|
3171
|
-
this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
3371
|
+
this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
3172
3372
|
const active = this.runtimes.forAgent(session.agentName).getSession(session.localSessionId)?.activeTurnId;
|
|
3173
3373
|
if (!session.lastTurnId || session.lastTurnId === turnId || session.lastTurnId === attempt.recoveredFromTurnId
|
|
3174
3374
|
|| (!attempt.turnId && !active)) {
|
|
@@ -3418,15 +3618,22 @@ export class ProxySessionController {
|
|
|
3418
3618
|
replyTarget?: MessageReplyTarget,
|
|
3419
3619
|
localImagePaths?: string[],
|
|
3420
3620
|
displayPrompt?: string,
|
|
3621
|
+
workspace?: Pick<WorkspacePromptSubmission, "requestId" | "expectedTurnId" | "onClaim" | "onSubmitting" | "queuedPrompt">,
|
|
3421
3622
|
): Promise<void> {
|
|
3422
3623
|
this.recoverySupersededSessions.add(record.localSessionId);
|
|
3423
3624
|
const executionGeneration = this.store.executionGeneration(record.localSessionId);
|
|
3625
|
+
const workspaceRequestId = workspace?.requestId;
|
|
3626
|
+
const workspaceMessageId = workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined;
|
|
3627
|
+
const startOptions = { messageId, displayPrompt, executionGeneration, workspaceRequestId,
|
|
3628
|
+
onWorkspaceClaim: workspace?.onClaim, onWorkspaceSubmitting: workspace?.onSubmitting };
|
|
3424
3629
|
if (this.llmRetryingSessions.has(record.localSessionId) || this.planHandoffs.has(record.localSessionId)) {
|
|
3630
|
+
if (workspace?.queuedPrompt) throw new TurnNotSubmittedError("当前任务正在重试或切换,请稍后再发送。");
|
|
3425
3631
|
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, text, {
|
|
3426
3632
|
localImagePaths,
|
|
3427
3633
|
messageId,
|
|
3428
3634
|
replyTarget,
|
|
3429
3635
|
displayPrompt,
|
|
3636
|
+
promptId: workspaceMessageId,
|
|
3430
3637
|
});
|
|
3431
3638
|
this.store.audit(contextKey, "queued_prompt_added_during_llm_retry", {
|
|
3432
3639
|
promptId: queued.promptId,
|
|
@@ -3445,6 +3652,7 @@ export class ProxySessionController {
|
|
|
3445
3652
|
this.agentLabel(record.agentName),
|
|
3446
3653
|
record.model,
|
|
3447
3654
|
record.modelProvider,
|
|
3655
|
+
record.reasoningEffort,
|
|
3448
3656
|
);
|
|
3449
3657
|
await this.outbound.startPendingTurn(
|
|
3450
3658
|
record.localSessionId,
|
|
@@ -3453,6 +3661,8 @@ export class ProxySessionController {
|
|
|
3453
3661
|
replyTarget,
|
|
3454
3662
|
displayPrompt ?? text,
|
|
3455
3663
|
localImagePaths,
|
|
3664
|
+
workspaceRequestId,
|
|
3665
|
+
Boolean(workspace),
|
|
3456
3666
|
);
|
|
3457
3667
|
}
|
|
3458
3668
|
let loaded: LoadedSession;
|
|
@@ -3480,30 +3690,36 @@ export class ProxySessionController {
|
|
|
3480
3690
|
}
|
|
3481
3691
|
}
|
|
3482
3692
|
this.assertExecutionGeneration(record.localSessionId, executionGeneration);
|
|
3483
|
-
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
3484
3693
|
const activeTurnId = loaded.session.activeTurnId;
|
|
3694
|
+
assertWorkspaceSteerTurn(workspace?.expectedTurnId, activeTurnId);
|
|
3695
|
+
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
3485
3696
|
if (activeTurnId) {
|
|
3486
3697
|
const activeContextKey = this.store.getTurnContextKey(activeTurnId);
|
|
3487
3698
|
const notificationTurn = Boolean(turnViewSnapshot(this.store.getTurnSnapshot(activeTurnId))?.taskNotificationCard);
|
|
3488
3699
|
if ((activeContextKey && activeContextKey !== contextKey) || notificationTurn) {
|
|
3700
|
+
if (workspace?.queuedPrompt) throw new TurnNotSubmittedError("当前轮次无法接收这条消息,可在会话空闲后再发送。");
|
|
3489
3701
|
this.persistQueuedPrompt(record.localSessionId, contextKey, text, {
|
|
3490
3702
|
localImagePaths,
|
|
3491
3703
|
messageId,
|
|
3492
3704
|
replyTarget,
|
|
3493
3705
|
displayPrompt,
|
|
3706
|
+
promptId: workspaceMessageId,
|
|
3494
3707
|
});
|
|
3495
3708
|
if (notificationTurn) await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
3496
3709
|
return;
|
|
3497
3710
|
}
|
|
3498
3711
|
try {
|
|
3712
|
+
workspace?.onClaim?.();
|
|
3713
|
+
workspace?.onSubmitting();
|
|
3499
3714
|
await loaded.runtime.steerTurn(record.localSessionId, activeTurnId, runtimePrompt(text, localImagePaths));
|
|
3500
|
-
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, messageId, localImagePaths);
|
|
3715
|
+
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, workspaceMessageId ?? messageId, localImagePaths);
|
|
3501
3716
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, activeTurnId);
|
|
3502
3717
|
return;
|
|
3503
3718
|
} catch (error) {
|
|
3504
3719
|
if (!(error instanceof TurnNotSubmittedError)) {
|
|
3505
3720
|
throw new Error("追加消息的提交结果待核实,未自动重发或入队。请检查执行记录后继续。", { cause: error });
|
|
3506
3721
|
}
|
|
3722
|
+
if (workspace?.expectedTurnId || workspace?.queuedPrompt) throw error;
|
|
3507
3723
|
this.logger.debug({ error, sessionId: record.localSessionId, activeTurnId }, "Steering failed; reconciling the App Server thread.");
|
|
3508
3724
|
let current = loaded.runtime.getSession(record.localSessionId);
|
|
3509
3725
|
try {
|
|
@@ -3512,7 +3728,7 @@ export class ProxySessionController {
|
|
|
3512
3728
|
this.logger.warn({ error: syncError, sessionId: record.localSessionId }, "Failed to synchronize after steering failure.");
|
|
3513
3729
|
}
|
|
3514
3730
|
if (!current?.activeTurnId) {
|
|
3515
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3731
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
3516
3732
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
3517
3733
|
return;
|
|
3518
3734
|
}
|
|
@@ -3520,6 +3736,7 @@ export class ProxySessionController {
|
|
|
3520
3736
|
if (current.activeTurnId !== activeTurnId && !notificationTurn) {
|
|
3521
3737
|
try {
|
|
3522
3738
|
this.assertExecutionGeneration(record.localSessionId, executionGeneration);
|
|
3739
|
+
workspace?.onSubmitting();
|
|
3523
3740
|
await loaded.runtime.steerTurn(
|
|
3524
3741
|
record.localSessionId,
|
|
3525
3742
|
current.activeTurnId,
|
|
@@ -3529,7 +3746,7 @@ export class ProxySessionController {
|
|
|
3529
3746
|
record.localSessionId,
|
|
3530
3747
|
current.activeTurnId,
|
|
3531
3748
|
displayPrompt ?? text,
|
|
3532
|
-
messageId,
|
|
3749
|
+
workspaceMessageId ?? messageId,
|
|
3533
3750
|
localImagePaths,
|
|
3534
3751
|
);
|
|
3535
3752
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, current.activeTurnId);
|
|
@@ -3549,12 +3766,13 @@ export class ProxySessionController {
|
|
|
3549
3766
|
messageId,
|
|
3550
3767
|
replyTarget,
|
|
3551
3768
|
displayPrompt,
|
|
3769
|
+
promptId: workspaceMessageId,
|
|
3552
3770
|
});
|
|
3553
3771
|
if (notificationTurn) await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
3554
3772
|
return;
|
|
3555
3773
|
}
|
|
3556
3774
|
}
|
|
3557
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3775
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
3558
3776
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
3559
3777
|
}
|
|
3560
3778
|
|
|
@@ -3602,10 +3820,11 @@ export class ProxySessionController {
|
|
|
3602
3820
|
messageId?: string;
|
|
3603
3821
|
replyTarget?: MessageReplyTarget;
|
|
3604
3822
|
displayPrompt?: string;
|
|
3823
|
+
promptId?: string;
|
|
3605
3824
|
} = {},
|
|
3606
3825
|
): QueuedPromptRecord {
|
|
3607
3826
|
return this.store.enqueuePrompt({
|
|
3608
|
-
promptId: createId("prompt"),
|
|
3827
|
+
promptId: options.promptId ?? createId("prompt"),
|
|
3609
3828
|
localSessionId,
|
|
3610
3829
|
contextKey,
|
|
3611
3830
|
text,
|
|
@@ -3623,14 +3842,14 @@ export class ProxySessionController {
|
|
|
3623
3842
|
this.requireSession(action.contextKey, sessionId);
|
|
3624
3843
|
if (action.messageId) this.rememberPromptQueueCard(sessionId, action.contextKey, action.messageId);
|
|
3625
3844
|
const cancelled = this.store.cancelQueuedPrompt(promptId, sessionId);
|
|
3626
|
-
if (cancelled
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
}
|
|
3633
|
-
await this.refreshPromptQueueCards(
|
|
3845
|
+
if (cancelled) await this.finishQueuedPromptCancellation(cancelled, action.contextKey);
|
|
3846
|
+
else await this.refreshPromptQueueCards(sessionId);
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
private async finishQueuedPromptCancellation(prompt: QueuedPromptRecord, contextKey: string): Promise<void> {
|
|
3850
|
+
if (prompt.messageId) await this.finalizeStandaloneMessageReaction(prompt.messageId, "cancelled");
|
|
3851
|
+
this.store.audit(contextKey, "queued_prompt_cancelled", { promptId: prompt.promptId, localSessionId: prompt.localSessionId });
|
|
3852
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
3634
3853
|
}
|
|
3635
3854
|
|
|
3636
3855
|
private async presentPromptQueueCard(localSessionId: string, contextKey: string): Promise<void> {
|
|
@@ -3691,6 +3910,7 @@ export class ProxySessionController {
|
|
|
3691
3910
|
prompts: this.store.listQueuedPrompts(localSessionId).map((prompt) => ({
|
|
3692
3911
|
id: prompt.promptId,
|
|
3693
3912
|
text: prompt.displayPrompt ?? prompt.text,
|
|
3913
|
+
hasImages: Boolean(prompt.localImagePaths?.length),
|
|
3694
3914
|
})),
|
|
3695
3915
|
});
|
|
3696
3916
|
}
|
|
@@ -3886,6 +4106,7 @@ export class ProxySessionController {
|
|
|
3886
4106
|
this.agentLabel(source.agentName),
|
|
3887
4107
|
source.model,
|
|
3888
4108
|
source.modelProvider,
|
|
4109
|
+
source.reasoningEffort,
|
|
3889
4110
|
);
|
|
3890
4111
|
|
|
3891
4112
|
try {
|
|
@@ -4205,6 +4426,7 @@ export class ProxySessionController {
|
|
|
4205
4426
|
private async forkSessionIntoContext(
|
|
4206
4427
|
contextKey: string,
|
|
4207
4428
|
plan: ForkSessionPlan,
|
|
4429
|
+
activate = true,
|
|
4208
4430
|
): Promise<ForkSessionResult> {
|
|
4209
4431
|
const localSessionId = createId("sess");
|
|
4210
4432
|
const record = this.store.createSession({
|
|
@@ -4249,6 +4471,7 @@ export class ProxySessionController {
|
|
|
4249
4471
|
this.agentLabel(plan.agentName),
|
|
4250
4472
|
forked.model ?? plan.model,
|
|
4251
4473
|
forked.modelProvider ?? plan.modelProvider,
|
|
4474
|
+
forked.reasoningEffort ?? plan.reasoningEffort,
|
|
4252
4475
|
);
|
|
4253
4476
|
this.store.audit(contextKey, "session_forked", {
|
|
4254
4477
|
sourceLocalSessionId: plan.source?.localSessionId,
|
|
@@ -4261,7 +4484,7 @@ export class ProxySessionController {
|
|
|
4261
4484
|
forkedLocalSessionId: localSessionId,
|
|
4262
4485
|
forkedRemoteSessionId: forked.remoteSessionId,
|
|
4263
4486
|
});
|
|
4264
|
-
this.store.setCurrentSession(contextKey, localSessionId);
|
|
4487
|
+
if (activate) this.store.setCurrentSession(contextKey, localSessionId);
|
|
4265
4488
|
return {
|
|
4266
4489
|
record: this.store.getSession(localSessionId) ?? record,
|
|
4267
4490
|
session: forked,
|
|
@@ -4675,7 +4898,7 @@ export class ProxySessionController {
|
|
|
4675
4898
|
messageId: options.messageId,
|
|
4676
4899
|
replyMessageId: replyTarget?.messageId,
|
|
4677
4900
|
executionGeneration,
|
|
4678
|
-
});
|
|
4901
|
+
}, options.onWorkspaceClaim);
|
|
4679
4902
|
}
|
|
4680
4903
|
let turnId: string;
|
|
4681
4904
|
let runtimeText = text;
|
|
@@ -4698,7 +4921,7 @@ export class ProxySessionController {
|
|
|
4698
4921
|
let pendingTurnId: string | undefined;
|
|
4699
4922
|
try {
|
|
4700
4923
|
const session = loaded.runtime.getSession(loaded.record.localSessionId) ?? loaded.session;
|
|
4701
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
4924
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4702
4925
|
pendingTurnId = await this.outbound.startPendingTurn(
|
|
4703
4926
|
loaded.record.localSessionId,
|
|
4704
4927
|
loaded.record.contextKey,
|
|
@@ -4706,6 +4929,8 @@ export class ProxySessionController {
|
|
|
4706
4929
|
replyTarget,
|
|
4707
4930
|
cardPrompt,
|
|
4708
4931
|
localImagePaths,
|
|
4932
|
+
options.workspaceRequestId,
|
|
4933
|
+
Boolean(options.onWorkspaceSubmitting),
|
|
4709
4934
|
);
|
|
4710
4935
|
} catch (error) {
|
|
4711
4936
|
if (options.scheduleRunId) {
|
|
@@ -4748,6 +4973,7 @@ export class ProxySessionController {
|
|
|
4748
4973
|
this.store.schedules.saveRun({ ...run!, status: "submitting" });
|
|
4749
4974
|
}
|
|
4750
4975
|
this.store.beginTurnAttemptSubmission(attemptId, recordSubmission);
|
|
4976
|
+
options.onWorkspaceSubmitting?.();
|
|
4751
4977
|
turnId = await loaded.runtime.startTurn(
|
|
4752
4978
|
loaded.record.localSessionId,
|
|
4753
4979
|
options.approvedPlanTurnId
|
|
@@ -4909,6 +5135,7 @@ export class ProxySessionController {
|
|
|
4909
5135
|
this.agentLabel(agentName),
|
|
4910
5136
|
resolvedExecutionSettings.model,
|
|
4911
5137
|
resolvedExecutionSettings.modelProvider,
|
|
5138
|
+
resolvedExecutionSettings.reasoningEffort,
|
|
4912
5139
|
);
|
|
4913
5140
|
const runtime = this.runtimes.forAgent(agentName);
|
|
4914
5141
|
try {
|
|
@@ -4926,7 +5153,7 @@ export class ProxySessionController {
|
|
|
4926
5153
|
permissionMode: resolvedExecutionSettings.permissionMode ?? "auto",
|
|
4927
5154
|
});
|
|
4928
5155
|
this.persistRuntimeSession(record, session, session.activeTurnId ? "running" : "ready");
|
|
4929
|
-
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider);
|
|
5156
|
+
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4930
5157
|
const saved = this.store.getSession(localSessionId) ?? record;
|
|
4931
5158
|
if (prepareTurn) this.assertExecutionGeneration(localSessionId, executionGeneration);
|
|
4932
5159
|
if (announce) {
|
|
@@ -5063,7 +5290,7 @@ export class ProxySessionController {
|
|
|
5063
5290
|
// A live Turn keeps its original delivery route. The new group's next Turn
|
|
5064
5291
|
// establishes its own route through startPendingTurn.
|
|
5065
5292
|
if (task.status !== "running" && !runtime.getSession(task.localSessionId)?.activeTurnId) {
|
|
5066
|
-
this.outbound.registerSession(task.localSessionId, group.contextKey, task.title, task.cwd, this.agentLabel(agentName), task.model, task.modelProvider);
|
|
5293
|
+
this.outbound.registerSession(task.localSessionId, group.contextKey, task.title, task.cwd, this.agentLabel(agentName), task.model, task.modelProvider, task.reasoningEffort);
|
|
5067
5294
|
}
|
|
5068
5295
|
this.store.audit(sourceContextKey, "session_switch_group", {
|
|
5069
5296
|
localSessionId: task.localSessionId, remoteSessionId, groupContextKey: group.contextKey,
|
|
@@ -5409,6 +5636,7 @@ export class ProxySessionController {
|
|
|
5409
5636
|
this.agentLabel(record.agentName),
|
|
5410
5637
|
record.model,
|
|
5411
5638
|
record.modelProvider,
|
|
5639
|
+
record.reasoningEffort,
|
|
5412
5640
|
);
|
|
5413
5641
|
const loading = this.sessionHydrationOperations.run(record.localSessionId, async (): Promise<LoadedSession> => {
|
|
5414
5642
|
const latest = this.store.getSession(record.localSessionId);
|
|
@@ -5877,8 +6105,12 @@ export class ProxySessionController {
|
|
|
5877
6105
|
clearTimeout(retryTimer);
|
|
5878
6106
|
this.queuedPromptRetryTimers.delete(sessionId);
|
|
5879
6107
|
}
|
|
6108
|
+
return this.serializeQueuedPromptStart(sessionId, () => this.startNextQueuedPromptIfIdle(sessionId));
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
private serializeQueuedPromptStart(sessionId: string, start: () => Promise<void>): Promise<void> {
|
|
5880
6112
|
const previous = this.queuedPromptStarts.get(sessionId) ?? Promise.resolve();
|
|
5881
|
-
const next = previous.catch(() => undefined).then(
|
|
6113
|
+
const next = previous.catch(() => undefined).then(start);
|
|
5882
6114
|
this.queuedPromptStarts.set(sessionId, next);
|
|
5883
6115
|
return next.finally(() => {
|
|
5884
6116
|
if (this.queuedPromptStarts.get(sessionId) === next) this.queuedPromptStarts.delete(sessionId);
|
|
@@ -5920,6 +6152,7 @@ export class ProxySessionController {
|
|
|
5920
6152
|
const baseRecord = this.store.getSession(sessionId);
|
|
5921
6153
|
if (!baseRecord || baseRecord.status === "closed") return;
|
|
5922
6154
|
let prompt: QueuedPromptRecord | undefined;
|
|
6155
|
+
let finishDispatch: (() => void) | undefined;
|
|
5923
6156
|
try {
|
|
5924
6157
|
let loaded = await this.loadSession(baseRecord, Boolean(this.store.getPendingProviderSettings(sessionId)));
|
|
5925
6158
|
const remoteActivity = await this.assertSessionTurnOwnership(loaded.record, loaded.runtime);
|
|
@@ -5933,7 +6166,9 @@ export class ProxySessionController {
|
|
|
5933
6166
|
this.assertExecutionGeneration(sessionId, executionGeneration);
|
|
5934
6167
|
prompt = this.store.takeNextQueuedPrompt(sessionId);
|
|
5935
6168
|
if (!prompt) return;
|
|
6169
|
+
finishDispatch = this.store.trackQueuedPromptDispatch(prompt);
|
|
5936
6170
|
const scheduledRun = this.store.schedules.getRun(prompt.promptId);
|
|
6171
|
+
let workspaceRequestId = prompt.promptId.startsWith("workspace:") ? prompt.promptId.slice("workspace:".length) : undefined;
|
|
5937
6172
|
const record = this.store.getSessionForContext(sessionId, prompt.contextKey) ?? baseRecord;
|
|
5938
6173
|
loaded = { ...loaded, record };
|
|
5939
6174
|
await this.refreshPromptQueueCards(sessionId);
|
|
@@ -5941,16 +6176,23 @@ export class ProxySessionController {
|
|
|
5941
6176
|
if (!this.store.schedules.canSubmit(scheduledRun.id)
|
|
5942
6177
|
|| this.lifecycle?.canStartScheduledTasks?.() === false) throw new Error("定时任务已取消、过期或正在安全重启。");
|
|
5943
6178
|
const job = this.store.schedules.require(scheduledRun.jobId);
|
|
6179
|
+
if (job.attachments?.files.length || job.attachments?.quotes?.length) workspaceRequestId = scheduledRun.id.slice("schedule_run_".length);
|
|
5944
6180
|
this.assertScheduleTarget(job);
|
|
6181
|
+
let missingAttachment = false;
|
|
5945
6182
|
try {
|
|
5946
|
-
|
|
6183
|
+
const attachmentPaths = [...(job.attachments?.images ?? []), ...(job.attachments?.files.map(file => file.filePath) ?? [])];
|
|
6184
|
+
const available = await Promise.all(attachmentPaths.map(async file => (await fs.stat(file).catch(() => undefined))?.isFile()));
|
|
6185
|
+
missingAttachment = available.some(value => !value);
|
|
6186
|
+
if (missingAttachment) throw new Error("定时任务的附件已不可用。");
|
|
6187
|
+
await this.notifySchedule(job, scheduleDisplayPrompt(job, queuedPromptContent(prompt, job.attachments?.quotes).text), prompt.localImagePaths);
|
|
5947
6188
|
} catch (error) {
|
|
6189
|
+
const reason = missingAttachment ? "定时任务的附件已不可用" : "原会话的 Prompt 发送失败";
|
|
5948
6190
|
const currentJob = this.store.schedules.get(job.id);
|
|
5949
6191
|
if (currentJob?.status === "enabled") {
|
|
5950
6192
|
const paused = this.store.schedules.change(job.id, currentJob.revision, "pause");
|
|
5951
|
-
this.store.schedules.update({ ...paused, notice:
|
|
6193
|
+
this.store.schedules.update({ ...paused, notice: `${reason},计划已暂停。请修复后恢复。` });
|
|
5952
6194
|
}
|
|
5953
|
-
this.store.schedules.finish(scheduledRun.id, "failed", "无法向原会话发送 Prompt,未提交模型。");
|
|
6195
|
+
this.store.schedules.finish(scheduledRun.id, "failed", missingAttachment ? `${reason},未提交模型。` : "无法向原会话发送 Prompt,未提交模型。");
|
|
5954
6196
|
this.store.updateTurnAttempt(scheduledRun.id, { status: "failed" });
|
|
5955
6197
|
throw error;
|
|
5956
6198
|
}
|
|
@@ -5962,6 +6204,7 @@ export class ProxySessionController {
|
|
|
5962
6204
|
prompt.localImagePaths,
|
|
5963
6205
|
{ messageId: prompt.messageId, displayPrompt: prompt.displayPrompt, executionGeneration,
|
|
5964
6206
|
trigger: scheduledRun ? "schedule" : "queue", instructionId: prompt.promptId,
|
|
6207
|
+
workspaceRequestId,
|
|
5965
6208
|
...(scheduledRun ? { attemptId: prompt.promptId, scheduleRunId: prompt.promptId } : {}) },
|
|
5966
6209
|
);
|
|
5967
6210
|
if (prompt.messageId) await this.bindMessageReactionToTurn(prompt.messageId, sessionId, turnId);
|
|
@@ -6002,6 +6245,8 @@ export class ProxySessionController {
|
|
|
6002
6245
|
if (this.store.countQueuedPrompts(sessionId) > 0) {
|
|
6003
6246
|
queueMicrotask(() => void this.scheduleNextQueuedPrompt(sessionId));
|
|
6004
6247
|
}
|
|
6248
|
+
} finally {
|
|
6249
|
+
finishDispatch?.();
|
|
6005
6250
|
}
|
|
6006
6251
|
}
|
|
6007
6252
|
|
|
@@ -6411,6 +6656,7 @@ export class ProxySessionController {
|
|
|
6411
6656
|
this.agentLabel(current.agentName),
|
|
6412
6657
|
forked.model ?? current.model,
|
|
6413
6658
|
forked.modelProvider ?? current.modelProvider,
|
|
6659
|
+
forked.reasoningEffort ?? current.reasoningEffort,
|
|
6414
6660
|
);
|
|
6415
6661
|
this.store.audit(contextKey, "session_reset_to_turn", {
|
|
6416
6662
|
localSessionId: current.localSessionId,
|
|
@@ -6766,7 +7012,7 @@ export class ProxySessionController {
|
|
|
6766
7012
|
const session = await loaded.runtime.setExecutionSettings(loaded.record.localSessionId, settings, persist);
|
|
6767
7013
|
loaded.record = this.store.getSession(loaded.record.localSessionId) ?? loaded.record;
|
|
6768
7014
|
this.settingsOnlySessions.delete(loaded.record.localSessionId);
|
|
6769
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
7015
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
6770
7016
|
return session;
|
|
6771
7017
|
}
|
|
6772
7018
|
|
|
@@ -6815,7 +7061,7 @@ export class ProxySessionController {
|
|
|
6815
7061
|
}
|
|
6816
7062
|
if (options.updateMessageId) {
|
|
6817
7063
|
await this.openExecutionSettingsNow(contextKey, activeTab, options);
|
|
6818
|
-
} else {
|
|
7064
|
+
} else if (!options.quiet) {
|
|
6819
7065
|
await this.outbound.sendText(contextKey, this.pendingProviderNotice(pending).replaceAll("`", ""));
|
|
6820
7066
|
}
|
|
6821
7067
|
}
|
|
@@ -6841,7 +7087,7 @@ export class ProxySessionController {
|
|
|
6841
7087
|
if (rolledBack) {
|
|
6842
7088
|
loaded.session = restored!;
|
|
6843
7089
|
this.store.deletePendingProviderSettings(pending.localSessionId);
|
|
6844
|
-
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider);
|
|
7090
|
+
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider, previous.reasoningEffort);
|
|
6845
7091
|
notice = `切换到 Provider ${cardCode(pending.settings.modelProvider)}、模型 ${cardCode(pending.settings.model)} 失败:${runtimeErrorMessage(error)} 已回退到 Provider ${cardCode(previous.modelProvider ?? "Agent 默认")}、模型 ${cardCode(previous.model ?? "默认")},后续轮次继续使用原设置。`;
|
|
6846
7092
|
} else {
|
|
6847
7093
|
failure = error;
|
|
@@ -6984,7 +7230,7 @@ export class ProxySessionController {
|
|
|
6984
7230
|
await loaded.runtime.setReasoningEffort(loaded.record.localSessionId, nextEffort);
|
|
6985
7231
|
}
|
|
6986
7232
|
this.store.updateRuntimeSession(loaded.record.localSessionId, { model, reasoningEffort: nextEffort });
|
|
6987
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider);
|
|
7233
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider, nextEffort);
|
|
6988
7234
|
});
|
|
6989
7235
|
const effortMessage = nextEffort && nextEffort !== currentEffort
|
|
6990
7236
|
? `,思考强度已自动调整为 ${nextEffort}`
|
|
@@ -6997,6 +7243,7 @@ export class ProxySessionController {
|
|
|
6997
7243
|
});
|
|
6998
7244
|
return;
|
|
6999
7245
|
}
|
|
7246
|
+
if (options.quiet) return;
|
|
7000
7247
|
await this.outbound.sendText(
|
|
7001
7248
|
contextKey,
|
|
7002
7249
|
`模型已切换为 ${model}${effortMessage},只影响当前任务,从下一次请求生效。`,
|
|
@@ -7449,6 +7696,7 @@ export class ProxySessionController {
|
|
|
7449
7696
|
});
|
|
7450
7697
|
return;
|
|
7451
7698
|
}
|
|
7699
|
+
if (options.quiet) return;
|
|
7452
7700
|
await this.outbound.sendText(
|
|
7453
7701
|
contextKey,
|
|
7454
7702
|
`思考强度已切换为 ${effort},只影响当前任务,从下一次请求生效。`,
|
|
@@ -8429,6 +8677,7 @@ export class ProxySessionController {
|
|
|
8429
8677
|
this.agentLabel(existing.agentName),
|
|
8430
8678
|
existing.model,
|
|
8431
8679
|
existing.modelProvider,
|
|
8680
|
+
existing.reasoningEffort,
|
|
8432
8681
|
);
|
|
8433
8682
|
await this.outbound.sendText(contextKey, `已切换到任务:${existing.title ?? existing.remoteSessionId ?? taskId}`);
|
|
8434
8683
|
return;
|
|
@@ -8464,6 +8713,7 @@ export class ProxySessionController {
|
|
|
8464
8713
|
this.agentLabel(agentName),
|
|
8465
8714
|
remote.model,
|
|
8466
8715
|
remote.modelProvider,
|
|
8716
|
+
remote.reasoningEffort,
|
|
8467
8717
|
);
|
|
8468
8718
|
await this.outbound.sendText(
|
|
8469
8719
|
contextKey,
|
|
@@ -10307,6 +10557,10 @@ function latestRemoteTimestamp(...values: Array<number | undefined>): number | u
|
|
|
10307
10557
|
return timestamps.length > 0 ? Math.max(...timestamps) : undefined;
|
|
10308
10558
|
}
|
|
10309
10559
|
|
|
10560
|
+
function assertWorkspaceSteerTurn(expected: string | undefined, active: string | undefined): void {
|
|
10561
|
+
if (expected && expected !== active) throw new TurnNotSubmittedError("原轮次已结束或切换,未追加消息。");
|
|
10562
|
+
}
|
|
10563
|
+
|
|
10310
10564
|
function isTurnStillRunning(status?: string): boolean {
|
|
10311
10565
|
return status === "starting"
|
|
10312
10566
|
|| status === "running"
|
|
@@ -10617,24 +10871,10 @@ function renderLocalTurnReference(
|
|
|
10617
10871
|
: undefined;
|
|
10618
10872
|
}
|
|
10619
10873
|
|
|
10620
|
-
function appendDownloadedFiles(
|
|
10621
|
-
prompt: string,
|
|
10622
|
-
files: Array<{ fileName: string; filePath: string }>,
|
|
10623
|
-
): string {
|
|
10624
|
-
return `${prompt}\n\n参考文件(已下载到本地):\n${files.map((file, index) =>
|
|
10625
|
-
`[文件 ${index + 1}:${file.fileName}] ${file.filePath}`).join("\n")}`;
|
|
10626
|
-
}
|
|
10627
|
-
|
|
10628
10874
|
function defaultResourcePrompt(message: IncomingMessage): string {
|
|
10629
10875
|
return defaultResourcePromptFromCounts(message.images?.length ?? 0, message.files?.length ?? 0);
|
|
10630
10876
|
}
|
|
10631
10877
|
|
|
10632
|
-
function defaultResourcePromptFromCounts(imageCount: number, fileCount: number): string {
|
|
10633
|
-
if (imageCount > 0 && fileCount > 0) return "请查看附带的图片和文件";
|
|
10634
|
-
if (fileCount > 0) return fileCount === 1 ? "请查看这个文件" : "请查看这些文件";
|
|
10635
|
-
return imageCount === 1 ? "请查看这张图片" : "请查看这些图片";
|
|
10636
|
-
}
|
|
10637
|
-
|
|
10638
10878
|
function isCommandMessage(message: IncomingMessage): boolean {
|
|
10639
10879
|
const text = normalizeFeishuPostText(message.text).trimStart();
|
|
10640
10880
|
return text.startsWith("/") || text.startsWith("!");
|