@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.4
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 +18 -0
- package/README.md +77 -12
- package/README.zh.md +77 -12
- 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 +1935 -232
- package/assets/workspace.css +360 -35
- package/assets/workspace.js +2115 -249
- 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 +26 -14
- 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 +40 -10
- 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 +133 -117
- 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 +23 -269
- 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 +15 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +20 -5
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +881 -79
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +105 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +13 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +28 -21
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +229 -92
- 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 +51 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +18 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +145 -19
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +143 -36
- 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 +20 -0
- package/dist/utils/promptAttachments.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 +22 -8
- 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 +38 -10
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +120 -120
- 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 +23 -254
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +10 -0
- package/src/local-files/WorkspacePage.ts +20 -5
- package/src/local-files/WorkspaceSessions.ts +811 -82
- package/src/local-files/WorkspaceTimeline.ts +109 -0
- package/src/presentation/OutboundRouter.ts +15 -4
- package/src/presentation/TurnStateReducer.ts +27 -18
- package/src/presentation/turnViewTypes.ts +2 -0
- package/src/proxy/ProxySessionController.ts +226 -77
- 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 +54 -9
- package/src/scheduling/types.ts +24 -4
- package/src/state/StateStore.ts +157 -20
- package/src/state/TurnPreviewJournal.ts +138 -34
- 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 +24 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -53,7 +53,8 @@ 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 { appendDownloadedFiles, defaultResourcePromptFromCounts, queuedPromptContent } from "../utils/promptAttachments.js";
|
|
57
58
|
import type { SettingsCatalog, SettingsSnapshot, SettingsStore } from "../config/SettingsStore.js";
|
|
58
59
|
import { renderSettingsCard } from "../feishu/SettingsCard.js";
|
|
59
60
|
import { renderSchedule, renderScheduleList, renderScheduleForm } from "../scheduling/ScheduleCards.js";
|
|
@@ -63,6 +64,7 @@ import type { OutboundRouter } from "../presentation/OutboundRouter.js";
|
|
|
63
64
|
import type { TurnActivity, TurnViewState } from "../presentation/turnViewTypes.js";
|
|
64
65
|
import { createTurnViewState, hydrateTurnViewState } from "../presentation/TurnStateReducer.js";
|
|
65
66
|
import { buildTurnGraphRows } from "../presentation/turnGraph.js";
|
|
67
|
+
import { splitMarkdown } from "../presentation/splitMarkdown.js";
|
|
66
68
|
import type { AgentRuntimeRegistry } from "../runtime/AgentRuntimeRegistry.js";
|
|
67
69
|
import { displayRuntimeError, isResponseContinuationError } from "../runtime/responseErrors.js";
|
|
68
70
|
import { TurnNotSubmittedError, TurnStoppedBeforeSubmissionError } from "../runtime/submissionErrors.js";
|
|
@@ -132,6 +134,7 @@ interface StartTurnOptions {
|
|
|
132
134
|
attemptId?: string;
|
|
133
135
|
messageId?: string;
|
|
134
136
|
displayPrompt?: string;
|
|
137
|
+
workspaceRequestId?: string;
|
|
135
138
|
preserveAttemptOnFailure?: boolean;
|
|
136
139
|
approvedPlanTurnId?: string;
|
|
137
140
|
responseContinuationTurnId?: string;
|
|
@@ -441,6 +444,7 @@ interface ModelCardOptions {
|
|
|
441
444
|
expectedProvider?: string;
|
|
442
445
|
sessionId?: string;
|
|
443
446
|
updateMessageId?: string;
|
|
447
|
+
quiet?: boolean;
|
|
444
448
|
}
|
|
445
449
|
|
|
446
450
|
interface ThinkingCardOptions extends ModelCardOptions {
|
|
@@ -670,10 +674,14 @@ export class ProxySessionController {
|
|
|
670
674
|
}
|
|
671
675
|
const currentId = this.store.getUserContext(message.contextKey)?.currentSessionId;
|
|
672
676
|
if (!this.store.inboundMessages.claim(message, currentId, currentId ? this.store.executionGeneration(currentId) : 0)) return;
|
|
673
|
-
if (this.
|
|
677
|
+
if (!this.acceptingInboundMessages) return;
|
|
674
678
|
await this.processAcceptedMessage(message);
|
|
675
679
|
}
|
|
676
680
|
|
|
681
|
+
get acceptingInboundMessages(): boolean {
|
|
682
|
+
return !this.inboundPaused && !this.recoveryClosed;
|
|
683
|
+
}
|
|
684
|
+
|
|
677
685
|
get pendingInboundMessages(): number {
|
|
678
686
|
return this.inboundInFlight.size + this.inboundActionsInFlight;
|
|
679
687
|
}
|
|
@@ -1650,14 +1658,20 @@ export class ProxySessionController {
|
|
|
1650
1658
|
}
|
|
1651
1659
|
|
|
1652
1660
|
async controlSendTaskPrompt(localSessionId: string, text: string, workspace?: {
|
|
1653
|
-
requestId: string;
|
|
1661
|
+
requestId: string; expectedTurnId?: string; localImagePaths?: string[]; files?: Array<{ fileName: string; filePath: string }>;
|
|
1662
|
+
onPosting(): void; onPosted(): void;
|
|
1654
1663
|
}): Promise<string> {
|
|
1655
|
-
const
|
|
1656
|
-
|
|
1664
|
+
const images = workspace?.localImagePaths;
|
|
1665
|
+
const files = workspace?.files;
|
|
1666
|
+
const promptText = text.trim() || (files?.length ? defaultResourcePromptFromCounts(images?.length ?? 0, files.length) : "");
|
|
1667
|
+
const echoedPrompt = files?.length ? `${promptText}\n\n附件:${files.map((file) => file.fileName).join("、")}` : promptText;
|
|
1668
|
+
if (!promptText && !images?.length) throw new Error("The Prompt cannot be empty.");
|
|
1657
1669
|
const record = this.store.getSession(localSessionId);
|
|
1658
1670
|
if (!record || record.status === "closed") throw new Error(`Task not found: ${localSessionId}`);
|
|
1659
1671
|
const runtime = this.runtimes.forAgent(record.agentName);
|
|
1660
1672
|
const activeTurnId = runtime.getSession(localSessionId)?.activeTurnId;
|
|
1673
|
+
const expectedTurnId = workspace?.expectedTurnId;
|
|
1674
|
+
assertWorkspaceSteerTurn(expectedTurnId, activeTurnId);
|
|
1661
1675
|
const routedContextKey = this.outbound.getSessionContextKey(localSessionId);
|
|
1662
1676
|
const responseContextKey = (activeTurnId ? this.store.getTurnContextKey(activeTurnId) ?? routedContextKey : undefined)
|
|
1663
1677
|
?? (record.lastTurnId ? this.store.getTurnContextKey(record.lastTurnId) : undefined)
|
|
@@ -1689,21 +1703,32 @@ export class ProxySessionController {
|
|
|
1689
1703
|
this.agentLabel(scopedRecord.agentName),
|
|
1690
1704
|
scopedRecord.model,
|
|
1691
1705
|
scopedRecord.modelProvider,
|
|
1706
|
+
scopedRecord.reasoningEffort,
|
|
1692
1707
|
);
|
|
1693
1708
|
if (workspace && this.store.getSession(localSessionId)?.status === "closed") throw new Error("任务已归档。");
|
|
1694
|
-
|
|
1709
|
+
assertWorkspaceSteerTurn(expectedTurnId, runtime.getSession(localSessionId)?.activeTurnId);
|
|
1710
|
+
const executionGeneration = expectedTurnId ? this.store.executionGeneration(localSessionId) : undefined;
|
|
1695
1711
|
const promptMessageId = await this.outbound.withReplyTarget(
|
|
1696
1712
|
responseContextKey,
|
|
1697
1713
|
existingReplyTarget,
|
|
1698
|
-
() =>
|
|
1714
|
+
() => {
|
|
1715
|
+
if (images?.length) return this.outbound.sendPromptImages(responseContextKey, echoedPrompt, images, () => workspace?.onPosting());
|
|
1716
|
+
workspace?.onPosting();
|
|
1717
|
+
return this.outbound.sendText(responseContextKey, echoedPrompt);
|
|
1718
|
+
},
|
|
1699
1719
|
);
|
|
1700
1720
|
workspace?.onPosted();
|
|
1721
|
+
if (executionGeneration !== undefined) {
|
|
1722
|
+
this.assertExecutionGeneration(localSessionId, executionGeneration);
|
|
1723
|
+
assertWorkspaceSteerTurn(expectedTurnId, runtime.getSession(localSessionId)?.activeTurnId);
|
|
1724
|
+
}
|
|
1701
1725
|
const turnReplyTarget = isThreadContextKey(responseContextKey)
|
|
1702
1726
|
? promptMessageId
|
|
1703
1727
|
? { messageId: promptMessageId, replyInThread: true as const }
|
|
1704
1728
|
: existingReplyTarget
|
|
1705
1729
|
: undefined;
|
|
1706
|
-
await this.promptSession(scopedRecord, responseContextKey, promptText,
|
|
1730
|
+
await this.promptSession(scopedRecord, responseContextKey, files?.length ? appendDownloadedFiles(promptText, files) : promptText,
|
|
1731
|
+
undefined, turnReplyTarget, images, files?.length ? promptText : undefined, workspace);
|
|
1707
1732
|
this.store.audit(responseContextKey, "task_prompt_sent", {
|
|
1708
1733
|
localSessionId,
|
|
1709
1734
|
source: workspace ? "workspace" : "cli",
|
|
@@ -1856,6 +1881,35 @@ export class ProxySessionController {
|
|
|
1856
1881
|
));
|
|
1857
1882
|
}
|
|
1858
1883
|
|
|
1884
|
+
controlWorkspaceAgents() {
|
|
1885
|
+
const agents = Object.entries(this.config.agents).filter(([, agent]) => agent.kind === "app-server")
|
|
1886
|
+
.map(([name, agent]) => ({ name, title: agent.title }));
|
|
1887
|
+
return { agents, defaultAgent: agents.find(({ name }) => name === this.config.defaults.agent)?.name ?? agents[0]?.name };
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
async controlWorkspaceDraftSettings(agentName: string) {
|
|
1891
|
+
const agent = this.ensureAgent(agentName);
|
|
1892
|
+
if (agent.kind !== "app-server") throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1893
|
+
const { model, modelProvider, reasoningEffort } = agent.defaults ?? {};
|
|
1894
|
+
const models = await this.runtimes.forAgent(agentName).listModels(modelProvider, model);
|
|
1895
|
+
return { model, provider: modelProvider, thinking: reasoningEffort, models };
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
controlCreateWorkspaceTask(localSessionId: string, owner: string, title: string, agentName: string, cwd?: string,
|
|
1899
|
+
model?: string, reasoningEffort?: string): SessionRecord {
|
|
1900
|
+
const agent = this.ensureAgent(agentName);
|
|
1901
|
+
if (agent.kind !== "app-server") throw new Error("请选择支持 Workspace 的 App Server Agent。");
|
|
1902
|
+
const settings = model
|
|
1903
|
+
? { ...agent.defaults, model, reasoningEffort }
|
|
1904
|
+
: mergeExecutionSettings(agent.defaults ?? {}, { reasoningEffort });
|
|
1905
|
+
const initialTitle = normalizeTaskTitle(title);
|
|
1906
|
+
const contextKey = `open_id:${owner}`;
|
|
1907
|
+
const root = cwd ?? createProjectlessWorkspace({ prompt: initialTitle }).cwd;
|
|
1908
|
+
this.store.createSession({ localSessionId, contextKey, agentName, cwd: root, status: "ready" });
|
|
1909
|
+
this.store.updateRuntimeSession(localSessionId, { ...settings, title: initialTitle, runtimeKind: this.runtimes.forAgent(agentName).kind });
|
|
1910
|
+
return this.store.getSession(localSessionId)!;
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1859
1913
|
async controlForkTask(localSessionId: string): Promise<{
|
|
1860
1914
|
sourceLocalSessionId: string;
|
|
1861
1915
|
sourceTurnId: string;
|
|
@@ -1884,6 +1938,14 @@ export class ProxySessionController {
|
|
|
1884
1938
|
};
|
|
1885
1939
|
}
|
|
1886
1940
|
|
|
1941
|
+
async controlForkWorkspaceTask(localSessionId: string, turnId: string): Promise<SessionRecord> {
|
|
1942
|
+
const source = this.requireControlSession(localSessionId);
|
|
1943
|
+
const plan = this.prepareForkSessionFromTurn(source, turnId, undefined, "当前任务");
|
|
1944
|
+
const origin = this.store.getTurnRuntimeOrigin(turnId);
|
|
1945
|
+
if (origin?.agentName === source.agentName) plan.remoteSessionId = origin.remoteSessionId;
|
|
1946
|
+
return (await this.forkSessionIntoContext(this.controlSessionContextKey(source), plan, false)).record;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1887
1949
|
async controlSwitchTask(
|
|
1888
1950
|
localSessionId: string,
|
|
1889
1951
|
targetLocalSessionId?: string,
|
|
@@ -1902,9 +1964,18 @@ export class ProxySessionController {
|
|
|
1902
1964
|
await this.scheduleNextQueuedPrompt(localSessionId);
|
|
1903
1965
|
}
|
|
1904
1966
|
|
|
1905
|
-
async notifySchedule(job: ScheduledJob, text: string): Promise<void> {
|
|
1967
|
+
async notifySchedule(job: ScheduledJob, text: string, images?: string[]): Promise<void> {
|
|
1906
1968
|
const target = job.replyMessageId ? { messageId: job.replyMessageId, replyInThread: true as const } : undefined;
|
|
1907
|
-
await this.outbound.withReplyTarget(job.contextKey, target, () =>
|
|
1969
|
+
await this.outbound.withReplyTarget(job.contextKey, target, async () => {
|
|
1970
|
+
const parts = splitMarkdown(text);
|
|
1971
|
+
if (images?.length) {
|
|
1972
|
+
const last = parts.pop() ?? "";
|
|
1973
|
+
for (const part of parts) await this.outbound.sendText(job.contextKey, part);
|
|
1974
|
+
await this.outbound.sendPromptImages(job.contextKey, last, images);
|
|
1975
|
+
} else {
|
|
1976
|
+
for (const part of parts) await this.outbound.sendText(job.contextKey, part);
|
|
1977
|
+
}
|
|
1978
|
+
});
|
|
1908
1979
|
}
|
|
1909
1980
|
|
|
1910
1981
|
async controlSchedule(command: ScheduleCommand, localSessionId?: string): Promise<unknown> {
|
|
@@ -1932,15 +2003,10 @@ export class ProxySessionController {
|
|
|
1932
2003
|
await this.outbound.withReplyTarget(job.contextKey, target, () => this.showSchedule(updated));
|
|
1933
2004
|
return updated;
|
|
1934
2005
|
}
|
|
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;
|
|
2006
|
+
if (command.operation === "run" || command.operation === "resume" || command.operation === "pause" || command.operation === "delete") {
|
|
2007
|
+
return this.controlWorkspaceScheduleAction(job, command.operation);
|
|
1940
2008
|
}
|
|
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");
|
|
2009
|
+
throw new Error("无效的定时任务操作。");
|
|
1944
2010
|
}
|
|
1945
2011
|
|
|
1946
2012
|
private requireSettingsOwner(userId?: string): SettingsStore {
|
|
@@ -2009,11 +2075,33 @@ export class ProxySessionController {
|
|
|
2009
2075
|
await this.outbound.updateInteractiveCard(action.contextKey, messageId, renderSettingsCard(snapshot, action.contextKey, notice));
|
|
2010
2076
|
}
|
|
2011
2077
|
|
|
2012
|
-
|
|
2078
|
+
controlCreateWorkspaceSchedule(localSessionId: string, input: ScheduleInput, request: string,
|
|
2079
|
+
upload?: { attachments?: ScheduledJob["attachments"]; fingerprint: string }): ScheduledJob {
|
|
2080
|
+
const task = this.requireControlSession(localSessionId);
|
|
2081
|
+
return this.createSchedule(input, localSessionId, this.controlSessionContextKey(task), this.controlSessionReplyTarget(task)?.messageId, request, upload);
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
controlEditWorkspaceSchedule(job: ScheduledJob, input: ScheduleInput): ScheduledJob {
|
|
2085
|
+
this.assertScheduleTarget(job);
|
|
2086
|
+
const status = job.status === "paused" || job.status === "draft" ? job.status : "enabled";
|
|
2087
|
+
return this.store.schedules.edit(job.id, job.revision, input, undefined, status);
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
async controlWorkspaceScheduleAction(job: ScheduledJob, action: "confirm" | "pause" | "resume" | "delete" | "run") {
|
|
2091
|
+
if (action === "confirm" || action === "resume" || action === "run") this.assertScheduleTarget(job);
|
|
2092
|
+
if (action !== "run") return this.store.schedules.change(job.id, job.revision, action);
|
|
2093
|
+
const run = this.store.schedules.dispatch(job, Date.now(), Date.now(), { manual: true });
|
|
2094
|
+
await this.drainScheduledPrompts(job.localSessionId);
|
|
2095
|
+
return run;
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
private createSchedule(input: ScheduleInput, localSessionId: string, contextKey: string, replyMessageId?: string, enableRequest?: string,
|
|
2099
|
+
upload?: { attachments?: ScheduledJob["attachments"]; fingerprint: string }): ScheduledJob {
|
|
2013
2100
|
if (!this.config.feishu.userOpenId) throw new Error("请先配置 Agent Bot 所有者,才能创建定时任务。");
|
|
2014
2101
|
this.requireSession(contextKey, localSessionId);
|
|
2015
2102
|
if (isThreadContextKey(contextKey) && !replyMessageId) throw new Error("缺少话题回复位置,请在原话题中创建计划。");
|
|
2016
|
-
|
|
2103
|
+
if (enableRequest && !this.outbound.canRoute(contextKey)) throw new Error("任务的原始会话不可用,无法创建定时计划。");
|
|
2104
|
+
return this.store.schedules.create(input, { localSessionId, contextKey, replyMessageId, ownerId: this.config.feishu.userOpenId }, undefined, enableRequest, upload);
|
|
2017
2105
|
}
|
|
2018
2106
|
|
|
2019
2107
|
private assertScheduleTarget(job: ScheduledJob): void {
|
|
@@ -2074,7 +2162,10 @@ export class ProxySessionController {
|
|
|
2074
2162
|
const string = (key: string) => typeof form[key] === "string" ? form[key] as string : "";
|
|
2075
2163
|
const input: ScheduleInput = { name: string("name"), prompt: string("prompt"), timeZone: string("timeZone"),
|
|
2076
2164
|
maxDelayMinutes: Number(string("maxDelayMinutes")), catchUpMinutes: Number(string("catchUpMinutes")),
|
|
2165
|
+
...(string("startsAt").trim() ? { startsAt: string("startsAt") } : {}),
|
|
2166
|
+
...(string("endsAt").trim() ? { endsAt: string("endsAt") } : {}),
|
|
2077
2167
|
...(string("cron").trim() ? { cron: string("cron") } : {}), ...(string("at").trim() ? { at: string("at") } : {}) };
|
|
2168
|
+
if (job?.spec.prompt && job.spec.prompt.length > 1000 && !input.prompt.trim()) input.prompt = job.spec.prompt;
|
|
2078
2169
|
const updated = job ? this.store.schedules.edit(job.id, job.revision, input)
|
|
2079
2170
|
: this.createSchedule(input, String(action.value.sessionId ?? ""), action.contextKey, replyTarget?.messageId);
|
|
2080
2171
|
return this.showSchedule(updated, messageId);
|
|
@@ -2090,23 +2181,47 @@ export class ProxySessionController {
|
|
|
2090
2181
|
await this.showSchedule(updated, messageId);
|
|
2091
2182
|
}
|
|
2092
2183
|
|
|
2093
|
-
async controlQueueTaskPrompt(localSessionId: string, text: string
|
|
2094
|
-
|
|
2095
|
-
|
|
2184
|
+
async controlQueueTaskPrompt(localSessionId: string, text: string, localImagePaths?: string[], workspaceRequestId?: string,
|
|
2185
|
+
files?: Array<{ fileName: string; filePath: string }>): Promise<{ promptId: string; queued: number }> {
|
|
2186
|
+
const promptText = text.trim() || (files?.length ? defaultResourcePromptFromCounts(localImagePaths?.length ?? 0, files.length) : "");
|
|
2187
|
+
if (!promptText && !localImagePaths?.length) throw new Error("The queued Prompt cannot be empty.");
|
|
2096
2188
|
const record = this.requireControlSession(localSessionId);
|
|
2097
2189
|
const contextKey = this.controlSessionContextKey(record);
|
|
2098
2190
|
const replyTarget = this.controlSessionReplyTarget(record);
|
|
2099
|
-
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, promptText,
|
|
2191
|
+
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, files?.length ? appendDownloadedFiles(promptText, files) : promptText, {
|
|
2192
|
+
replyTarget, localImagePaths, promptId: workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined,
|
|
2193
|
+
displayPrompt: files?.length ? promptText : undefined,
|
|
2194
|
+
});
|
|
2100
2195
|
this.store.audit(contextKey, "queued_prompt_added", {
|
|
2101
2196
|
promptId: queued.promptId,
|
|
2102
2197
|
localSessionId: record.localSessionId,
|
|
2103
|
-
source: "cli",
|
|
2198
|
+
source: workspaceRequestId ? "workspace" : "cli",
|
|
2104
2199
|
});
|
|
2105
2200
|
const queuedCount = this.store.countQueuedPrompts(record.localSessionId);
|
|
2106
2201
|
await this.scheduleNextQueuedPrompt(record.localSessionId);
|
|
2202
|
+
if (this.store.hasQueuedPrompt(queued.promptId)) await this.refreshPromptQueueCards(record.localSessionId);
|
|
2107
2203
|
return { promptId: queued.promptId, queued: queuedCount };
|
|
2108
2204
|
}
|
|
2109
2205
|
|
|
2206
|
+
async controlCancelWorkspaceQueue(localSessionId: string, promptId: string, request: string): Promise<boolean> {
|
|
2207
|
+
const task = this.requireControlSession(localSessionId);
|
|
2208
|
+
const { cancelled, prompt } = this.store.cancelWorkspaceQueuedPrompt(promptId, localSessionId, request);
|
|
2209
|
+
if (prompt) await this.finishQueuedPromptCancellation(prompt, this.controlSessionContextKey(task)).catch(error => {
|
|
2210
|
+
this.logger.warn({ error, localSessionId, promptId }, "Failed to refresh a cancelled Workspace prompt.");
|
|
2211
|
+
});
|
|
2212
|
+
return cancelled;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
async controlEditWorkspaceQueue(prompt: QueuedPromptRecord, content: Pick<QueuedPromptRecord, "text" | "displayPrompt">): Promise<boolean> {
|
|
2216
|
+
this.requireControlSession(prompt.localSessionId);
|
|
2217
|
+
if (!this.store.updateQueuedPrompt(prompt, content)) return false;
|
|
2218
|
+
this.store.audit(prompt.contextKey, "queued_prompt_edited", {
|
|
2219
|
+
promptId: prompt.promptId, localSessionId: prompt.localSessionId, source: "workspace",
|
|
2220
|
+
});
|
|
2221
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
2222
|
+
return true;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2110
2225
|
controlTaskAgent(localSessionId: string, agentName?: string): {
|
|
2111
2226
|
current: string;
|
|
2112
2227
|
agents: Array<{ name: string; title: string }>;
|
|
@@ -2128,6 +2243,7 @@ export class ProxySessionController {
|
|
|
2128
2243
|
localSessionId: string,
|
|
2129
2244
|
setting?: "provider" | "model" | "thinking" | "permissions",
|
|
2130
2245
|
value?: string,
|
|
2246
|
+
options: { quiet?: boolean } = {},
|
|
2131
2247
|
): Promise<{
|
|
2132
2248
|
session: SessionRecord;
|
|
2133
2249
|
providers: Awaited<ReturnType<NonNullable<AgentRuntime["listModelProviders"]>>>;
|
|
@@ -2142,13 +2258,13 @@ export class ProxySessionController {
|
|
|
2142
2258
|
if (setting && nextValue) {
|
|
2143
2259
|
const contextKey = this.controlSessionContextKey(record);
|
|
2144
2260
|
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,
|
|
2261
|
+
const target = { sessionId: record.localSessionId, quiet: options.quiet };
|
|
2262
|
+
if (setting === "provider") await this.selectProvider(contextKey, nextValue, target);
|
|
2263
|
+
else if (setting === "model") await this.model(contextKey, nextValue, target);
|
|
2264
|
+
else if (setting === "thinking") await this.thinking(contextKey, nextValue, target);
|
|
2149
2265
|
else {
|
|
2150
2266
|
if (nextValue !== "auto" && nextValue !== "confirm") throw new Error("task permissions accepts auto or confirm.");
|
|
2151
|
-
await this.permissions(contextKey, nextValue,
|
|
2267
|
+
await this.permissions(contextKey, nextValue, target);
|
|
2152
2268
|
}
|
|
2153
2269
|
});
|
|
2154
2270
|
}
|
|
@@ -2244,11 +2360,11 @@ export class ProxySessionController {
|
|
|
2244
2360
|
};
|
|
2245
2361
|
}
|
|
2246
2362
|
|
|
2247
|
-
async controlResetTaskToTurn(localSessionId: string, turnId: string): Promise<SessionRecord> {
|
|
2363
|
+
async controlResetTaskToTurn(localSessionId: string, turnId: string, options?: { quiet?: boolean }): Promise<SessionRecord> {
|
|
2248
2364
|
const record = this.requireControlSession(localSessionId);
|
|
2249
2365
|
const contextKey = this.controlSessionContextKey(record);
|
|
2250
2366
|
await this.runSessionReset(record.localSessionId, async () => {
|
|
2251
|
-
await this.outbound.sendText(contextKey, TURN_RESET_STARTED_MESSAGE);
|
|
2367
|
+
if (!options?.quiet) await this.outbound.sendText(contextKey, TURN_RESET_STARTED_MESSAGE);
|
|
2252
2368
|
await this.performSessionReset(contextKey, record, turnId, false);
|
|
2253
2369
|
});
|
|
2254
2370
|
return this.store.getSession(record.localSessionId) ?? record;
|
|
@@ -2608,6 +2724,7 @@ export class ProxySessionController {
|
|
|
2608
2724
|
this.agentLabel(session.agentName),
|
|
2609
2725
|
session.model,
|
|
2610
2726
|
session.modelProvider,
|
|
2727
|
+
session.reasoningEffort,
|
|
2611
2728
|
);
|
|
2612
2729
|
if (!session.lastTurnId) continue;
|
|
2613
2730
|
void this.outbound.resumeDelivery(session.localSessionId, turnContextKey, session.lastTurnId).catch((error: unknown) => {
|
|
@@ -2638,19 +2755,26 @@ export class ProxySessionController {
|
|
|
2638
2755
|
}
|
|
2639
2756
|
}
|
|
2640
2757
|
|
|
2641
|
-
async recoverInterruptedTasks(): Promise<void> {
|
|
2758
|
+
async recoverInterruptedTasks(updateRecoveryAttemptIds: readonly string[] = []): Promise<void> {
|
|
2642
2759
|
if (this.startupRecovery) return this.startupRecovery;
|
|
2643
|
-
const recovery = this.runStartupRecovery();
|
|
2760
|
+
const recovery = this.runStartupRecovery(new Set(updateRecoveryAttemptIds));
|
|
2644
2761
|
this.startupRecovery = recovery;
|
|
2645
2762
|
return recovery;
|
|
2646
2763
|
}
|
|
2647
2764
|
|
|
2648
|
-
private async runStartupRecovery(): Promise<void> {
|
|
2765
|
+
private async runStartupRecovery(updateRecoveryAttempts: ReadonlySet<string>): Promise<void> {
|
|
2649
2766
|
await this.recoverUnprocessedMessages();
|
|
2650
2767
|
await this.finishPersistedCancellationRequests();
|
|
2651
2768
|
await this.recoverShellCommandJobs();
|
|
2652
2769
|
const recoveryCutoff = Date.now() - RECOVERY_ACTIVITY_WINDOW_MS;
|
|
2653
2770
|
const cutoff = new Date(recoveryCutoff).toISOString();
|
|
2771
|
+
for (const attemptId of updateRecoveryAttempts) {
|
|
2772
|
+
const attempt = this.store.getTurnAttempt(attemptId);
|
|
2773
|
+
const session = attempt && this.store.getSession(attempt.localSessionId);
|
|
2774
|
+
if (attempt && session && this.canContinueAfterRestart(attempt, session)) {
|
|
2775
|
+
this.store.prepareInterruptedTurnAttemptRecovery(attemptId, new Date(0).toISOString());
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2654
2778
|
for (const attempt of this.store.listRecentlyInterruptedTurnAttempts(cutoff)) {
|
|
2655
2779
|
const session = this.store.getSession(attempt.localSessionId);
|
|
2656
2780
|
if (session && this.canContinueAfterRestart(attempt, session)) {
|
|
@@ -2659,7 +2783,7 @@ export class ProxySessionController {
|
|
|
2659
2783
|
}
|
|
2660
2784
|
this.backfillTurnAttemptsForUpgrade();
|
|
2661
2785
|
const attempts = this.store.listIncompleteTurnAttempts();
|
|
2662
|
-
const recentAttempts = attempts.filter((attempt) => isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2786
|
+
const recentAttempts = attempts.filter((attempt) => updateRecoveryAttempts.has(attempt.attemptId) || isRecoveryAttemptRecent(attempt, recoveryCutoff));
|
|
2663
2787
|
if (recentAttempts.length > 0) {
|
|
2664
2788
|
this.logger.warn(
|
|
2665
2789
|
{ attemptIds: recentAttempts.map((attempt) => attempt.attemptId) },
|
|
@@ -2667,7 +2791,7 @@ export class ProxySessionController {
|
|
|
2667
2791
|
);
|
|
2668
2792
|
}
|
|
2669
2793
|
for (const attempt of attempts) {
|
|
2670
|
-
if (!isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2794
|
+
if (!updateRecoveryAttempts.has(attempt.attemptId) && !isRecoveryAttemptRecent(attempt, recoveryCutoff)) {
|
|
2671
2795
|
await this.expireStaleTurnAttempt(attempt);
|
|
2672
2796
|
continue;
|
|
2673
2797
|
}
|
|
@@ -2769,6 +2893,7 @@ export class ProxySessionController {
|
|
|
2769
2893
|
this.agentLabel(session.agentName),
|
|
2770
2894
|
session.model,
|
|
2771
2895
|
session.modelProvider,
|
|
2896
|
+
session.reasoningEffort,
|
|
2772
2897
|
);
|
|
2773
2898
|
}
|
|
2774
2899
|
try {
|
|
@@ -2990,6 +3115,7 @@ export class ProxySessionController {
|
|
|
2990
3115
|
this.agentLabel(session.agentName),
|
|
2991
3116
|
session.model,
|
|
2992
3117
|
session.modelProvider,
|
|
3118
|
+
session.reasoningEffort,
|
|
2993
3119
|
);
|
|
2994
3120
|
if (announce) {
|
|
2995
3121
|
await this.outbound.withReplyTarget(contextKey, replyTarget, () =>
|
|
@@ -3168,7 +3294,7 @@ export class ProxySessionController {
|
|
|
3168
3294
|
if (this.store.schedules.getRun(attempt.attemptId)) this.store.schedules.finish(attempt.attemptId, "unknown", message);
|
|
3169
3295
|
if (!session || session.status === "closed") return;
|
|
3170
3296
|
this.outbound.registerSession(session.localSessionId, attempt.contextKey, session.title, session.cwd,
|
|
3171
|
-
this.agentLabel(session.agentName), session.model, session.modelProvider);
|
|
3297
|
+
this.agentLabel(session.agentName), session.model, session.modelProvider, session.reasoningEffort);
|
|
3172
3298
|
const active = this.runtimes.forAgent(session.agentName).getSession(session.localSessionId)?.activeTurnId;
|
|
3173
3299
|
if (!session.lastTurnId || session.lastTurnId === turnId || session.lastTurnId === attempt.recoveredFromTurnId
|
|
3174
3300
|
|| (!attempt.turnId && !active)) {
|
|
@@ -3418,15 +3544,20 @@ export class ProxySessionController {
|
|
|
3418
3544
|
replyTarget?: MessageReplyTarget,
|
|
3419
3545
|
localImagePaths?: string[],
|
|
3420
3546
|
displayPrompt?: string,
|
|
3547
|
+
workspace?: { requestId: string; expectedTurnId?: string },
|
|
3421
3548
|
): Promise<void> {
|
|
3422
3549
|
this.recoverySupersededSessions.add(record.localSessionId);
|
|
3423
3550
|
const executionGeneration = this.store.executionGeneration(record.localSessionId);
|
|
3551
|
+
const workspaceRequestId = workspace?.requestId;
|
|
3552
|
+
const workspaceMessageId = workspaceRequestId ? `workspace:${workspaceRequestId}` : undefined;
|
|
3553
|
+
const startOptions = { messageId, displayPrompt, executionGeneration, workspaceRequestId };
|
|
3424
3554
|
if (this.llmRetryingSessions.has(record.localSessionId) || this.planHandoffs.has(record.localSessionId)) {
|
|
3425
3555
|
const queued = this.persistQueuedPrompt(record.localSessionId, contextKey, text, {
|
|
3426
3556
|
localImagePaths,
|
|
3427
3557
|
messageId,
|
|
3428
3558
|
replyTarget,
|
|
3429
3559
|
displayPrompt,
|
|
3560
|
+
promptId: workspaceMessageId,
|
|
3430
3561
|
});
|
|
3431
3562
|
this.store.audit(contextKey, "queued_prompt_added_during_llm_retry", {
|
|
3432
3563
|
promptId: queued.promptId,
|
|
@@ -3445,6 +3576,7 @@ export class ProxySessionController {
|
|
|
3445
3576
|
this.agentLabel(record.agentName),
|
|
3446
3577
|
record.model,
|
|
3447
3578
|
record.modelProvider,
|
|
3579
|
+
record.reasoningEffort,
|
|
3448
3580
|
);
|
|
3449
3581
|
await this.outbound.startPendingTurn(
|
|
3450
3582
|
record.localSessionId,
|
|
@@ -3453,6 +3585,7 @@ export class ProxySessionController {
|
|
|
3453
3585
|
replyTarget,
|
|
3454
3586
|
displayPrompt ?? text,
|
|
3455
3587
|
localImagePaths,
|
|
3588
|
+
workspaceRequestId,
|
|
3456
3589
|
);
|
|
3457
3590
|
}
|
|
3458
3591
|
let loaded: LoadedSession;
|
|
@@ -3480,8 +3613,9 @@ export class ProxySessionController {
|
|
|
3480
3613
|
}
|
|
3481
3614
|
}
|
|
3482
3615
|
this.assertExecutionGeneration(record.localSessionId, executionGeneration);
|
|
3483
|
-
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
3484
3616
|
const activeTurnId = loaded.session.activeTurnId;
|
|
3617
|
+
assertWorkspaceSteerTurn(workspace?.expectedTurnId, activeTurnId);
|
|
3618
|
+
this.store.acknowledgeUnknownTurnAttempts(record.localSessionId);
|
|
3485
3619
|
if (activeTurnId) {
|
|
3486
3620
|
const activeContextKey = this.store.getTurnContextKey(activeTurnId);
|
|
3487
3621
|
const notificationTurn = Boolean(turnViewSnapshot(this.store.getTurnSnapshot(activeTurnId))?.taskNotificationCard);
|
|
@@ -3491,19 +3625,21 @@ export class ProxySessionController {
|
|
|
3491
3625
|
messageId,
|
|
3492
3626
|
replyTarget,
|
|
3493
3627
|
displayPrompt,
|
|
3628
|
+
promptId: workspaceMessageId,
|
|
3494
3629
|
});
|
|
3495
3630
|
if (notificationTurn) await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
3496
3631
|
return;
|
|
3497
3632
|
}
|
|
3498
3633
|
try {
|
|
3499
3634
|
await loaded.runtime.steerTurn(record.localSessionId, activeTurnId, runtimePrompt(text, localImagePaths));
|
|
3500
|
-
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, messageId, localImagePaths);
|
|
3635
|
+
await this.presentSteerMessage(record.localSessionId, activeTurnId, displayPrompt ?? text, workspaceMessageId ?? messageId, localImagePaths);
|
|
3501
3636
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, activeTurnId);
|
|
3502
3637
|
return;
|
|
3503
3638
|
} catch (error) {
|
|
3504
3639
|
if (!(error instanceof TurnNotSubmittedError)) {
|
|
3505
3640
|
throw new Error("追加消息的提交结果待核实,未自动重发或入队。请检查执行记录后继续。", { cause: error });
|
|
3506
3641
|
}
|
|
3642
|
+
if (workspace?.expectedTurnId) throw error;
|
|
3507
3643
|
this.logger.debug({ error, sessionId: record.localSessionId, activeTurnId }, "Steering failed; reconciling the App Server thread.");
|
|
3508
3644
|
let current = loaded.runtime.getSession(record.localSessionId);
|
|
3509
3645
|
try {
|
|
@@ -3512,7 +3648,7 @@ export class ProxySessionController {
|
|
|
3512
3648
|
this.logger.warn({ error: syncError, sessionId: record.localSessionId }, "Failed to synchronize after steering failure.");
|
|
3513
3649
|
}
|
|
3514
3650
|
if (!current?.activeTurnId) {
|
|
3515
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3651
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
3516
3652
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
3517
3653
|
return;
|
|
3518
3654
|
}
|
|
@@ -3529,7 +3665,7 @@ export class ProxySessionController {
|
|
|
3529
3665
|
record.localSessionId,
|
|
3530
3666
|
current.activeTurnId,
|
|
3531
3667
|
displayPrompt ?? text,
|
|
3532
|
-
messageId,
|
|
3668
|
+
workspaceMessageId ?? messageId,
|
|
3533
3669
|
localImagePaths,
|
|
3534
3670
|
);
|
|
3535
3671
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, current.activeTurnId);
|
|
@@ -3549,12 +3685,13 @@ export class ProxySessionController {
|
|
|
3549
3685
|
messageId,
|
|
3550
3686
|
replyTarget,
|
|
3551
3687
|
displayPrompt,
|
|
3688
|
+
promptId: workspaceMessageId,
|
|
3552
3689
|
});
|
|
3553
3690
|
if (notificationTurn) await this.presentPromptQueueCard(record.localSessionId, contextKey);
|
|
3554
3691
|
return;
|
|
3555
3692
|
}
|
|
3556
3693
|
}
|
|
3557
|
-
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths,
|
|
3694
|
+
const turnId = await this.startTurn(loaded, text, replyTarget, localImagePaths, startOptions);
|
|
3558
3695
|
if (messageId) await this.bindMessageReactionToTurn(messageId, record.localSessionId, turnId);
|
|
3559
3696
|
}
|
|
3560
3697
|
|
|
@@ -3602,10 +3739,11 @@ export class ProxySessionController {
|
|
|
3602
3739
|
messageId?: string;
|
|
3603
3740
|
replyTarget?: MessageReplyTarget;
|
|
3604
3741
|
displayPrompt?: string;
|
|
3742
|
+
promptId?: string;
|
|
3605
3743
|
} = {},
|
|
3606
3744
|
): QueuedPromptRecord {
|
|
3607
3745
|
return this.store.enqueuePrompt({
|
|
3608
|
-
promptId: createId("prompt"),
|
|
3746
|
+
promptId: options.promptId ?? createId("prompt"),
|
|
3609
3747
|
localSessionId,
|
|
3610
3748
|
contextKey,
|
|
3611
3749
|
text,
|
|
@@ -3623,14 +3761,14 @@ export class ProxySessionController {
|
|
|
3623
3761
|
this.requireSession(action.contextKey, sessionId);
|
|
3624
3762
|
if (action.messageId) this.rememberPromptQueueCard(sessionId, action.contextKey, action.messageId);
|
|
3625
3763
|
const cancelled = this.store.cancelQueuedPrompt(promptId, sessionId);
|
|
3626
|
-
if (cancelled
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
}
|
|
3633
|
-
await this.refreshPromptQueueCards(
|
|
3764
|
+
if (cancelled) await this.finishQueuedPromptCancellation(cancelled, action.contextKey);
|
|
3765
|
+
else await this.refreshPromptQueueCards(sessionId);
|
|
3766
|
+
}
|
|
3767
|
+
|
|
3768
|
+
private async finishQueuedPromptCancellation(prompt: QueuedPromptRecord, contextKey: string): Promise<void> {
|
|
3769
|
+
if (prompt.messageId) await this.finalizeStandaloneMessageReaction(prompt.messageId, "cancelled");
|
|
3770
|
+
this.store.audit(contextKey, "queued_prompt_cancelled", { promptId: prompt.promptId, localSessionId: prompt.localSessionId });
|
|
3771
|
+
await this.refreshPromptQueueCards(prompt.localSessionId);
|
|
3634
3772
|
}
|
|
3635
3773
|
|
|
3636
3774
|
private async presentPromptQueueCard(localSessionId: string, contextKey: string): Promise<void> {
|
|
@@ -3691,6 +3829,7 @@ export class ProxySessionController {
|
|
|
3691
3829
|
prompts: this.store.listQueuedPrompts(localSessionId).map((prompt) => ({
|
|
3692
3830
|
id: prompt.promptId,
|
|
3693
3831
|
text: prompt.displayPrompt ?? prompt.text,
|
|
3832
|
+
hasImages: Boolean(prompt.localImagePaths?.length),
|
|
3694
3833
|
})),
|
|
3695
3834
|
});
|
|
3696
3835
|
}
|
|
@@ -3886,6 +4025,7 @@ export class ProxySessionController {
|
|
|
3886
4025
|
this.agentLabel(source.agentName),
|
|
3887
4026
|
source.model,
|
|
3888
4027
|
source.modelProvider,
|
|
4028
|
+
source.reasoningEffort,
|
|
3889
4029
|
);
|
|
3890
4030
|
|
|
3891
4031
|
try {
|
|
@@ -4205,6 +4345,7 @@ export class ProxySessionController {
|
|
|
4205
4345
|
private async forkSessionIntoContext(
|
|
4206
4346
|
contextKey: string,
|
|
4207
4347
|
plan: ForkSessionPlan,
|
|
4348
|
+
activate = true,
|
|
4208
4349
|
): Promise<ForkSessionResult> {
|
|
4209
4350
|
const localSessionId = createId("sess");
|
|
4210
4351
|
const record = this.store.createSession({
|
|
@@ -4249,6 +4390,7 @@ export class ProxySessionController {
|
|
|
4249
4390
|
this.agentLabel(plan.agentName),
|
|
4250
4391
|
forked.model ?? plan.model,
|
|
4251
4392
|
forked.modelProvider ?? plan.modelProvider,
|
|
4393
|
+
forked.reasoningEffort ?? plan.reasoningEffort,
|
|
4252
4394
|
);
|
|
4253
4395
|
this.store.audit(contextKey, "session_forked", {
|
|
4254
4396
|
sourceLocalSessionId: plan.source?.localSessionId,
|
|
@@ -4261,7 +4403,7 @@ export class ProxySessionController {
|
|
|
4261
4403
|
forkedLocalSessionId: localSessionId,
|
|
4262
4404
|
forkedRemoteSessionId: forked.remoteSessionId,
|
|
4263
4405
|
});
|
|
4264
|
-
this.store.setCurrentSession(contextKey, localSessionId);
|
|
4406
|
+
if (activate) this.store.setCurrentSession(contextKey, localSessionId);
|
|
4265
4407
|
return {
|
|
4266
4408
|
record: this.store.getSession(localSessionId) ?? record,
|
|
4267
4409
|
session: forked,
|
|
@@ -4698,7 +4840,7 @@ export class ProxySessionController {
|
|
|
4698
4840
|
let pendingTurnId: string | undefined;
|
|
4699
4841
|
try {
|
|
4700
4842
|
const session = loaded.runtime.getSession(loaded.record.localSessionId) ?? loaded.session;
|
|
4701
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
4843
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4702
4844
|
pendingTurnId = await this.outbound.startPendingTurn(
|
|
4703
4845
|
loaded.record.localSessionId,
|
|
4704
4846
|
loaded.record.contextKey,
|
|
@@ -4706,6 +4848,7 @@ export class ProxySessionController {
|
|
|
4706
4848
|
replyTarget,
|
|
4707
4849
|
cardPrompt,
|
|
4708
4850
|
localImagePaths,
|
|
4851
|
+
options.workspaceRequestId,
|
|
4709
4852
|
);
|
|
4710
4853
|
} catch (error) {
|
|
4711
4854
|
if (options.scheduleRunId) {
|
|
@@ -4909,6 +5052,7 @@ export class ProxySessionController {
|
|
|
4909
5052
|
this.agentLabel(agentName),
|
|
4910
5053
|
resolvedExecutionSettings.model,
|
|
4911
5054
|
resolvedExecutionSettings.modelProvider,
|
|
5055
|
+
resolvedExecutionSettings.reasoningEffort,
|
|
4912
5056
|
);
|
|
4913
5057
|
const runtime = this.runtimes.forAgent(agentName);
|
|
4914
5058
|
try {
|
|
@@ -4926,7 +5070,7 @@ export class ProxySessionController {
|
|
|
4926
5070
|
permissionMode: resolvedExecutionSettings.permissionMode ?? "auto",
|
|
4927
5071
|
});
|
|
4928
5072
|
this.persistRuntimeSession(record, session, session.activeTurnId ? "running" : "ready");
|
|
4929
|
-
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider);
|
|
5073
|
+
this.outbound.updateSessionModel(localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
4930
5074
|
const saved = this.store.getSession(localSessionId) ?? record;
|
|
4931
5075
|
if (prepareTurn) this.assertExecutionGeneration(localSessionId, executionGeneration);
|
|
4932
5076
|
if (announce) {
|
|
@@ -5063,7 +5207,7 @@ export class ProxySessionController {
|
|
|
5063
5207
|
// A live Turn keeps its original delivery route. The new group's next Turn
|
|
5064
5208
|
// establishes its own route through startPendingTurn.
|
|
5065
5209
|
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);
|
|
5210
|
+
this.outbound.registerSession(task.localSessionId, group.contextKey, task.title, task.cwd, this.agentLabel(agentName), task.model, task.modelProvider, task.reasoningEffort);
|
|
5067
5211
|
}
|
|
5068
5212
|
this.store.audit(sourceContextKey, "session_switch_group", {
|
|
5069
5213
|
localSessionId: task.localSessionId, remoteSessionId, groupContextKey: group.contextKey,
|
|
@@ -5409,6 +5553,7 @@ export class ProxySessionController {
|
|
|
5409
5553
|
this.agentLabel(record.agentName),
|
|
5410
5554
|
record.model,
|
|
5411
5555
|
record.modelProvider,
|
|
5556
|
+
record.reasoningEffort,
|
|
5412
5557
|
);
|
|
5413
5558
|
const loading = this.sessionHydrationOperations.run(record.localSessionId, async (): Promise<LoadedSession> => {
|
|
5414
5559
|
const latest = this.store.getSession(record.localSessionId);
|
|
@@ -5934,6 +6079,7 @@ export class ProxySessionController {
|
|
|
5934
6079
|
prompt = this.store.takeNextQueuedPrompt(sessionId);
|
|
5935
6080
|
if (!prompt) return;
|
|
5936
6081
|
const scheduledRun = this.store.schedules.getRun(prompt.promptId);
|
|
6082
|
+
let workspaceRequestId = prompt.promptId.startsWith("workspace:") ? prompt.promptId.slice("workspace:".length) : undefined;
|
|
5937
6083
|
const record = this.store.getSessionForContext(sessionId, prompt.contextKey) ?? baseRecord;
|
|
5938
6084
|
loaded = { ...loaded, record };
|
|
5939
6085
|
await this.refreshPromptQueueCards(sessionId);
|
|
@@ -5941,16 +6087,23 @@ export class ProxySessionController {
|
|
|
5941
6087
|
if (!this.store.schedules.canSubmit(scheduledRun.id)
|
|
5942
6088
|
|| this.lifecycle?.canStartScheduledTasks?.() === false) throw new Error("定时任务已取消、过期或正在安全重启。");
|
|
5943
6089
|
const job = this.store.schedules.require(scheduledRun.jobId);
|
|
6090
|
+
if (job.attachments?.files.length) workspaceRequestId = scheduledRun.id.slice("schedule_run_".length);
|
|
5944
6091
|
this.assertScheduleTarget(job);
|
|
6092
|
+
let missingAttachment = false;
|
|
5945
6093
|
try {
|
|
5946
|
-
|
|
6094
|
+
const attachmentPaths = [...(job.attachments?.images ?? []), ...(job.attachments?.files.map(file => file.filePath) ?? [])];
|
|
6095
|
+
const available = await Promise.all(attachmentPaths.map(async file => (await fs.stat(file).catch(() => undefined))?.isFile()));
|
|
6096
|
+
missingAttachment = available.some(value => !value);
|
|
6097
|
+
if (missingAttachment) throw new Error("定时任务的附件已不可用。");
|
|
6098
|
+
await this.notifySchedule(job, scheduleDisplayPrompt(job, queuedPromptContent(prompt).text), prompt.localImagePaths);
|
|
5947
6099
|
} catch (error) {
|
|
6100
|
+
const reason = missingAttachment ? "定时任务的附件已不可用" : "原会话的 Prompt 发送失败";
|
|
5948
6101
|
const currentJob = this.store.schedules.get(job.id);
|
|
5949
6102
|
if (currentJob?.status === "enabled") {
|
|
5950
6103
|
const paused = this.store.schedules.change(job.id, currentJob.revision, "pause");
|
|
5951
|
-
this.store.schedules.update({ ...paused, notice:
|
|
6104
|
+
this.store.schedules.update({ ...paused, notice: `${reason},计划已暂停。请修复后恢复。` });
|
|
5952
6105
|
}
|
|
5953
|
-
this.store.schedules.finish(scheduledRun.id, "failed", "无法向原会话发送 Prompt,未提交模型。");
|
|
6106
|
+
this.store.schedules.finish(scheduledRun.id, "failed", missingAttachment ? `${reason},未提交模型。` : "无法向原会话发送 Prompt,未提交模型。");
|
|
5954
6107
|
this.store.updateTurnAttempt(scheduledRun.id, { status: "failed" });
|
|
5955
6108
|
throw error;
|
|
5956
6109
|
}
|
|
@@ -5962,6 +6115,7 @@ export class ProxySessionController {
|
|
|
5962
6115
|
prompt.localImagePaths,
|
|
5963
6116
|
{ messageId: prompt.messageId, displayPrompt: prompt.displayPrompt, executionGeneration,
|
|
5964
6117
|
trigger: scheduledRun ? "schedule" : "queue", instructionId: prompt.promptId,
|
|
6118
|
+
workspaceRequestId,
|
|
5965
6119
|
...(scheduledRun ? { attemptId: prompt.promptId, scheduleRunId: prompt.promptId } : {}) },
|
|
5966
6120
|
);
|
|
5967
6121
|
if (prompt.messageId) await this.bindMessageReactionToTurn(prompt.messageId, sessionId, turnId);
|
|
@@ -6411,6 +6565,7 @@ export class ProxySessionController {
|
|
|
6411
6565
|
this.agentLabel(current.agentName),
|
|
6412
6566
|
forked.model ?? current.model,
|
|
6413
6567
|
forked.modelProvider ?? current.modelProvider,
|
|
6568
|
+
forked.reasoningEffort ?? current.reasoningEffort,
|
|
6414
6569
|
);
|
|
6415
6570
|
this.store.audit(contextKey, "session_reset_to_turn", {
|
|
6416
6571
|
localSessionId: current.localSessionId,
|
|
@@ -6766,7 +6921,7 @@ export class ProxySessionController {
|
|
|
6766
6921
|
const session = await loaded.runtime.setExecutionSettings(loaded.record.localSessionId, settings, persist);
|
|
6767
6922
|
loaded.record = this.store.getSession(loaded.record.localSessionId) ?? loaded.record;
|
|
6768
6923
|
this.settingsOnlySessions.delete(loaded.record.localSessionId);
|
|
6769
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider);
|
|
6924
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, session.model, session.modelProvider, session.reasoningEffort);
|
|
6770
6925
|
return session;
|
|
6771
6926
|
}
|
|
6772
6927
|
|
|
@@ -6815,7 +6970,7 @@ export class ProxySessionController {
|
|
|
6815
6970
|
}
|
|
6816
6971
|
if (options.updateMessageId) {
|
|
6817
6972
|
await this.openExecutionSettingsNow(contextKey, activeTab, options);
|
|
6818
|
-
} else {
|
|
6973
|
+
} else if (!options.quiet) {
|
|
6819
6974
|
await this.outbound.sendText(contextKey, this.pendingProviderNotice(pending).replaceAll("`", ""));
|
|
6820
6975
|
}
|
|
6821
6976
|
}
|
|
@@ -6841,7 +6996,7 @@ export class ProxySessionController {
|
|
|
6841
6996
|
if (rolledBack) {
|
|
6842
6997
|
loaded.session = restored!;
|
|
6843
6998
|
this.store.deletePendingProviderSettings(pending.localSessionId);
|
|
6844
|
-
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider);
|
|
6999
|
+
this.outbound.updateSessionModel(pending.localSessionId, previous.model, previous.modelProvider, previous.reasoningEffort);
|
|
6845
7000
|
notice = `切换到 Provider ${cardCode(pending.settings.modelProvider)}、模型 ${cardCode(pending.settings.model)} 失败:${runtimeErrorMessage(error)} 已回退到 Provider ${cardCode(previous.modelProvider ?? "Agent 默认")}、模型 ${cardCode(previous.model ?? "默认")},后续轮次继续使用原设置。`;
|
|
6846
7001
|
} else {
|
|
6847
7002
|
failure = error;
|
|
@@ -6984,7 +7139,7 @@ export class ProxySessionController {
|
|
|
6984
7139
|
await loaded.runtime.setReasoningEffort(loaded.record.localSessionId, nextEffort);
|
|
6985
7140
|
}
|
|
6986
7141
|
this.store.updateRuntimeSession(loaded.record.localSessionId, { model, reasoningEffort: nextEffort });
|
|
6987
|
-
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider);
|
|
7142
|
+
this.outbound.updateSessionModel(loaded.record.localSessionId, model, loaded.session.modelProvider, nextEffort);
|
|
6988
7143
|
});
|
|
6989
7144
|
const effortMessage = nextEffort && nextEffort !== currentEffort
|
|
6990
7145
|
? `,思考强度已自动调整为 ${nextEffort}`
|
|
@@ -6997,6 +7152,7 @@ export class ProxySessionController {
|
|
|
6997
7152
|
});
|
|
6998
7153
|
return;
|
|
6999
7154
|
}
|
|
7155
|
+
if (options.quiet) return;
|
|
7000
7156
|
await this.outbound.sendText(
|
|
7001
7157
|
contextKey,
|
|
7002
7158
|
`模型已切换为 ${model}${effortMessage},只影响当前任务,从下一次请求生效。`,
|
|
@@ -7449,6 +7605,7 @@ export class ProxySessionController {
|
|
|
7449
7605
|
});
|
|
7450
7606
|
return;
|
|
7451
7607
|
}
|
|
7608
|
+
if (options.quiet) return;
|
|
7452
7609
|
await this.outbound.sendText(
|
|
7453
7610
|
contextKey,
|
|
7454
7611
|
`思考强度已切换为 ${effort},只影响当前任务,从下一次请求生效。`,
|
|
@@ -8429,6 +8586,7 @@ export class ProxySessionController {
|
|
|
8429
8586
|
this.agentLabel(existing.agentName),
|
|
8430
8587
|
existing.model,
|
|
8431
8588
|
existing.modelProvider,
|
|
8589
|
+
existing.reasoningEffort,
|
|
8432
8590
|
);
|
|
8433
8591
|
await this.outbound.sendText(contextKey, `已切换到任务:${existing.title ?? existing.remoteSessionId ?? taskId}`);
|
|
8434
8592
|
return;
|
|
@@ -8464,6 +8622,7 @@ export class ProxySessionController {
|
|
|
8464
8622
|
this.agentLabel(agentName),
|
|
8465
8623
|
remote.model,
|
|
8466
8624
|
remote.modelProvider,
|
|
8625
|
+
remote.reasoningEffort,
|
|
8467
8626
|
);
|
|
8468
8627
|
await this.outbound.sendText(
|
|
8469
8628
|
contextKey,
|
|
@@ -10307,6 +10466,10 @@ function latestRemoteTimestamp(...values: Array<number | undefined>): number | u
|
|
|
10307
10466
|
return timestamps.length > 0 ? Math.max(...timestamps) : undefined;
|
|
10308
10467
|
}
|
|
10309
10468
|
|
|
10469
|
+
function assertWorkspaceSteerTurn(expected: string | undefined, active: string | undefined): void {
|
|
10470
|
+
if (expected && expected !== active) throw new TurnNotSubmittedError("原轮次已结束或切换,未追加消息。");
|
|
10471
|
+
}
|
|
10472
|
+
|
|
10310
10473
|
function isTurnStillRunning(status?: string): boolean {
|
|
10311
10474
|
return status === "starting"
|
|
10312
10475
|
|| status === "running"
|
|
@@ -10617,24 +10780,10 @@ function renderLocalTurnReference(
|
|
|
10617
10780
|
: undefined;
|
|
10618
10781
|
}
|
|
10619
10782
|
|
|
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
10783
|
function defaultResourcePrompt(message: IncomingMessage): string {
|
|
10629
10784
|
return defaultResourcePromptFromCounts(message.images?.length ?? 0, message.files?.length ?? 0);
|
|
10630
10785
|
}
|
|
10631
10786
|
|
|
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
10787
|
function isCommandMessage(message: IncomingMessage): boolean {
|
|
10639
10788
|
const text = normalizeFeishuPostText(message.text).trimStart();
|
|
10640
10789
|
return text.startsWith("/") || text.startsWith("!");
|