feat(agent): improve investigation contracts and runtime readiness
This commit is contained in:
@@ -332,7 +332,7 @@ export const streamPromptResponse = async ({
|
||||
emittedText = true;
|
||||
done = true;
|
||||
}
|
||||
} else await runtime.prompt(sessionId, message, toRuntimeModel(model));
|
||||
} else await runtime.prompt(sessionId, message, toRuntimeModel(model), undefined, signal);
|
||||
onPromptDispatched?.();
|
||||
})
|
||||
.then(() => {
|
||||
@@ -1048,7 +1048,7 @@ export const streamPromptResponse = async ({
|
||||
// the same managed session/lease, never create another task run.
|
||||
finalAnswer = undefined;
|
||||
sawResponseActivity = false;
|
||||
await runtime.prompt(sessionId, typeof idleDecision === "string" ? idleDecision : "请处理收信箱中新到达的调查协作消息,按需回复,然后完成本轮工作。", toRuntimeModel(model));
|
||||
await runtime.prompt(sessionId, typeof idleDecision === "string" ? idleDecision : "请处理收信箱中新到达的调查协作消息,按需回复,然后完成本轮工作。", toRuntimeModel(model), undefined, signal);
|
||||
continue;
|
||||
}
|
||||
if (waitForUserInput && await waitForUserInput()) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import { type FrontendActionCoordinator } from "../frontendAction/coordinator.js
|
||||
import { type LearningOrchestrator } from "../learning/orchestrator.js";
|
||||
import { logger } from "../logger.js";
|
||||
import { type MemoryStore } from "../memory/store.js";
|
||||
import { type OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
||||
import { McpPreparationError, type OpencodeRuntimeAdapter } from "../runtime/opencode.js";
|
||||
import {
|
||||
getRuntimeSessionContext,
|
||||
setRuntimeSessionContext,
|
||||
@@ -498,6 +498,11 @@ export const registerChatStreamRoute = (
|
||||
const taskContext = sessionPurpose === "task_collaboration"
|
||||
? resolvedTaskContext
|
||||
: null;
|
||||
const taskSource = z.object({ replay_context: z.record(z.unknown()).nullish() }).passthrough()
|
||||
.safeParse(resolvedTaskContext?.task.source);
|
||||
setRuntimeSessionContext({ ...getRuntimeSessionContext(binding.sessionId)!,
|
||||
taskWorkflow: resolvedTaskContext?.task.workflow,
|
||||
taskReplay: taskSource.success && !!taskSource.data.replay_context });
|
||||
if (taskContext) {
|
||||
const report = taskContext.selected_report ?? taskContext.task.latest_report;
|
||||
const reference = z.object({ revision: z.number().int().positive() }).passthrough().safeParse(report);
|
||||
@@ -1178,7 +1183,10 @@ export const registerChatStreamRoute = (
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
publish("error", { session_id: clientSessionId, message: abortController.signal.aborted ? "请求已中断" : "Agent response failed" });
|
||||
const preparationFailure = error instanceof McpPreparationError ? error : null;
|
||||
publish("error", { session_id: clientSessionId,
|
||||
message: abortController.signal.aborted ? "请求已中断" : preparationFailure?.message ?? "Agent response failed",
|
||||
...(preparationFailure && !abortController.signal.aborted ? { code: preparationFailure.code } : {}) });
|
||||
await stopTaskHeartbeat();
|
||||
if (
|
||||
sessionPurpose === "task_execution" &&
|
||||
@@ -1192,7 +1200,7 @@ export const registerChatStreamRoute = (
|
||||
activeSessionRecord.taskId,
|
||||
activeSessionRecord.runId,
|
||||
clientSessionId,
|
||||
abortController.signal.aborted ? "AGENT_ABORTED" : "AGENT_EXECUTION_ERROR",
|
||||
abortController.signal.aborted ? "AGENT_ABORTED" : preparationFailure?.code ?? "AGENT_EXECUTION_ERROR",
|
||||
abortController.signal.aborted
|
||||
? "Agent execution was aborted"
|
||||
: error instanceof Error ? error.message : "Agent execution failed",
|
||||
|
||||
Reference in New Issue
Block a user