@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;" />
48 lines (46 loc) • 1.51 kB
JavaScript
require("reflect-metadata");
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_runtime$1 = require('../core/runtime.cjs');
let _ag_ui_client = require("@ag-ui/client");
//#region src/v2/runtime/handlers/handle-stop.ts
async function handleStopAgent({ runtime, request, agentId, threadId }) {
try {
if (!(await require_runtime$1.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: _ag_ui_client.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
exports.handleStopAgent = handleStopAgent;
//# sourceMappingURL=handle-stop.cjs.map