{"version":3,"file":"handle-stop.cjs","names":["EventType"],"sources":["../../../../src/v2/runtime/handlers/handle-stop.ts"],"sourcesContent":["import type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { EventType } from \"@ag-ui/client\";\n\ninterface StopAgentParameters {\n  request: Request;\n  runtime: CopilotRuntimeLike;\n  agentId: string;\n  threadId: string;\n}\n\nexport async function handleStopAgent({\n  runtime,\n  request,\n  agentId,\n  threadId,\n}: StopAgentParameters) {\n  try {\n    const agents = await runtime.agents;\n\n    if (!agents[agentId]) {\n      return new Response(\n        JSON.stringify({\n          error: \"Agent not found\",\n          message: `Agent '${agentId}' does not exist`,\n        }),\n        {\n          status: 404,\n          headers: { \"Content-Type\": \"application/json\" },\n        },\n      );\n    }\n\n    const stopped = await runtime.runner.stop({ threadId });\n\n    if (!stopped) {\n      return new Response(\n        JSON.stringify({\n          stopped: false,\n          message: `No active run for thread '${threadId}'.`,\n        }),\n        {\n          status: 200,\n          headers: { \"Content-Type\": \"application/json\" },\n        },\n      );\n    }\n\n    return new Response(\n      JSON.stringify({\n        stopped: true,\n        interrupt: {\n          type: EventType.RUN_ERROR,\n          message: \"Run stopped by user\",\n          code: \"STOPPED\",\n        },\n      }),\n      {\n        status: 200,\n        headers: { \"Content-Type\": \"application/json\" },\n      },\n    );\n  } catch (error) {\n    console.error(\"Error stopping agent run:\", error);\n\n    return new Response(\n      JSON.stringify({\n        error: \"Failed to stop agent\",\n        message: error instanceof Error ? error.message : \"Unknown error\",\n      }),\n      {\n        status: 500,\n        headers: { \"Content-Type\": \"application/json\" },\n      },\n    );\n  }\n}\n"],"mappings":";;;;;AAUA,eAAsB,gBAAgB,EACpC,SACA,SACA,SACA,YACsB;AACtB,KAAI;AAGF,MAAI,EAFW,MAAM,QAAQ,QAEjB,SACV,QAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,UAAU,QAAQ;GAC5B,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAKH,MAAI,CAFY,MAAM,QAAQ,OAAO,KAAK,EAAE,UAAU,CAAC,CAGrD,QAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,SAAS,6BAA6B,SAAS;GAChD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;AAGH,SAAO,IAAI,SACT,KAAK,UAAU;GACb,SAAS;GACT,WAAW;IACT,MAAMA,wBAAU;IAChB,SAAS;IACT,MAAM;IACP;GACF,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF;UACM,OAAO;AACd,UAAQ,MAAM,6BAA6B,MAAM;AAEjD,SAAO,IAAI,SACT,KAAK,UAAU;GACb,OAAO;GACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACnD,CAAC,EACF;GACE,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAChD,CACF"}