fix(agent): cancel vision failover when the task stops
This commit is contained in:
parent
ad25b4e17f
commit
f55d21968f
@ -169,7 +169,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
if (!model) throw new AgentRunError("Agent 模型暂不可用", 503);
|
if (!model) throw new AgentRunError("Agent 模型暂不可用", 503);
|
||||||
const visionModel = model;
|
const visionModel = model;
|
||||||
const withModel = createAgentVisionExecutor(candidates, agentModelCircuitStore, getLanguageModelById);
|
const executeVisionModel = createAgentVisionExecutor(candidates, agentModelCircuitStore, getLanguageModelById);
|
||||||
// Validate the user's image choice independently of the Agent planning model.
|
// Validate the user's image choice independently of the Agent planning model.
|
||||||
if (body.selectedImageModel) {
|
if (body.selectedImageModel) {
|
||||||
const images = await getStyleProImageModelEntries();
|
const images = await getStyleProImageModelEntries();
|
||||||
@ -269,7 +269,9 @@ export async function POST(request: Request) {
|
|||||||
const emit = (type: string, data: unknown) => writer.write({ type, data, ...(type === "data-canvasAgentRun" ? { transient: true } : {}) } as never);
|
const emit = (type: string, data: unknown) => writer.write({ type, data, ...(type === "data-canvasAgentRun" ? { transient: true } : {}) } as never);
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
let leaseLost = false;
|
let leaseLost = false;
|
||||||
let activeModelController: AbortController | null = null;
|
const activeModelController = new AbortController();
|
||||||
|
const withModel: typeof executeVisionModel = (execute, signal) => executeVisionModel(execute,
|
||||||
|
signal ? AbortSignal.any([signal, activeModelController.signal]) : activeModelController.signal);
|
||||||
const heartbeat = setInterval(() => {
|
const heartbeat = setInterval(() => {
|
||||||
void heartbeatAgentRun(run)
|
void heartbeatAgentRun(run)
|
||||||
.then((current) => {
|
.then((current) => {
|
||||||
@ -337,7 +339,6 @@ export async function POST(request: Request) {
|
|||||||
definitions: tools.definitions, executable: tools.executable, emit,
|
definitions: tools.definitions, executable: tools.executable, emit,
|
||||||
imagePreferences: snapshot.imagePreferences });
|
imagePreferences: snapshot.imagePreferences });
|
||||||
const gateway = await createZcodeModelGateway(configured, undefined, candidates);
|
const gateway = await createZcodeModelGateway(configured, undefined, candidates);
|
||||||
activeModelController = new AbortController();
|
|
||||||
const status = await runZcodeCanvasTask({
|
const status = await runZcodeCanvasTask({
|
||||||
runId: run.id, snapshot, definitions: tools.definitions,
|
runId: run.id, snapshot, definitions: tools.definitions,
|
||||||
instructions: (isVideo ? videoRuntimeSystemPrompt : canvasRuntimeSystemPrompt)(snapshot.objective, snapshot.summary, snapshot.inputs.map(input => input.text), context),
|
instructions: (isVideo ? videoRuntimeSystemPrompt : canvasRuntimeSystemPrompt)(snapshot.objective, snapshot.summary, snapshot.inputs.map(input => input.text), context),
|
||||||
@ -401,7 +402,8 @@ export async function POST(request: Request) {
|
|||||||
projectId,
|
projectId,
|
||||||
model: visionModel || model,
|
model: visionModel || model,
|
||||||
supportsVision: Boolean(visionModel),
|
supportsVision: Boolean(visionModel),
|
||||||
withModel,
|
withModel,
|
||||||
|
signal: activeModelController.signal,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const finalText = snapshot.message;
|
const finalText = snapshot.message;
|
||||||
|
|||||||
@ -108,6 +108,7 @@ export async function verifyCanvasAgentResults(params: {
|
|||||||
supportsVision: boolean;
|
supportsVision: boolean;
|
||||||
withModel?: AgentVisionExecutor;
|
withModel?: AgentVisionExecutor;
|
||||||
reviewPorts?: RuntimeReviewPorts;
|
reviewPorts?: RuntimeReviewPorts;
|
||||||
|
signal?: AbortSignal;
|
||||||
}) {
|
}) {
|
||||||
const { snapshot } = params;
|
const { snapshot } = params;
|
||||||
const calls = snapshot.calls;
|
const calls = snapshot.calls;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user