@copilotkit/runtime
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
47 lines (45 loc) • 1.38 kB
JavaScript
import "reflect-metadata";
import { resolveAgents } from "../core/runtime.mjs";
import { EventType } from "@ag-ui/client";
//#region src/v2/runtime/handlers/handle-stop.ts
async function handleStopAgent({ runtime, request, agentId, threadId }) {
try {
if (!(await resolveAgents(runtime.agents, request))[agentId]) return new Response(JSON.stringify({
error: "Agent not found",
message: `Agent '${agentId}' does not exist`
}), {
status: 404,
headers: { "Content-Type": "application/json" }
});
if (!await runtime.runner.stop({ threadId })) return new Response(JSON.stringify({
stopped: false,
message: `No active run for thread '${threadId}'.`
}), {
status: 200,
headers: { "Content-Type": "application/json" }
});
return new Response(JSON.stringify({
stopped: true,
interrupt: {
type: EventType.RUN_ERROR,
message: "Run stopped by user",
code: "STOPPED"
}
}), {
status: 200,
headers: { "Content-Type": "application/json" }
});
} catch (error) {
console.error("Error stopping agent run:", error);
return new Response(JSON.stringify({
error: "Failed to stop agent",
message: error instanceof Error ? error.message : "Unknown error"
}), {
status: 500,
headers: { "Content-Type": "application/json" }
});
}
}
//#endregion
export { handleStopAgent };
//# sourceMappingURL=handle-stop.mjs.map