/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 730: /***/ ((module) => { module.exports = eval("require")("@actions/core"); /***/ }), /***/ 238: /***/ ((module) => { module.exports = eval("require")("@actions/github"); /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __nccwpck_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ var threw = true; /******/ try { /******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); /******/ threw = false; /******/ } finally { /******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ } /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; const core = __nccwpck_require__(730); const github = __nccwpck_require__(238); const sanitizeTask = (text) => (text || "").replace(/@bot\b[:]?\s*/gi, "").trim(); async function fetchFirstIssueComment( repoFullName, issueNumber, githubToken, serverUrl, ) { if (!repoFullName || !issueNumber) return null; const url = `${serverUrl}/api/v1/repos/${repoFullName}/issues/${issueNumber}/comments?limit=1`; const headers = { Accept: "application/vnd.github+json" }; if (githubToken) { headers.Authorization = `Bearer ${githubToken}`; } try { const response = await fetch(url, { headers }); if (!response.ok) { core.warning( `Failed to fetch issue comments (${response.status}): ${response.statusText}`, ); return null; } const comments = await response.json(); if (!Array.isArray(comments) || comments.length === 0) return null; return sanitizeTask(comments[0]?.body); } catch (error) { core.warning(`Error fetching issue comments: ${error}`); return null; } } async function run() { const apiUrl = core.getInput("api_url") || "http://agents-api.servc-nonprod:3000"; const apiToken = core.getInput("api_token"); const botRoute = core.getInput("bot_route") || "agent-bot"; const debug = (core.getInput("debug") || "false").toLowerCase() === "true"; const serverUrl = ( process.env.GITHUB_SERVER_URL || github.context.serverUrl || "https://git.yusufali.ca" ).replace(/\/$/, ""); const payload = github.context.payload; const commentBody = payload?.comment?.body || ""; const issueNumber = payload?.issue?.number; const repoName = payload?.repository?.full_name; const repoUrl = payload?.repository?.clone_url; const githubToken = process.env.GITHUB_TOKEN; if (!commentBody) { if (!debug) { core.setFailed("No comment body found in the event payload"); return; } core.info( "No comment body found in the event payload, continuing because debug is enabled", ); } let task = (await fetchFirstIssueComment( repoName, issueNumber, githubToken, serverUrl, )) || sanitizeTask(commentBody); if (!task) { if (!debug) { core.setFailed("Unable to determine the task to send to the agent"); return; } core.info("Unable to determine the task, using debug placeholder"); task = "[debug] empty task"; } const requestPayload = { type: "input", route: botRoute, argumentId: "plain", force: true, instanceId: null, inputs: { method: "start", inputs: { repo_name: repoName, repo_url: repoUrl, issue_number: String(issueNumber), task, }, }, }; if (debug) { core.info(`API URL: ${apiUrl}`); core.info(`Route: ${botRoute}`); core.info(`Server URL: ${serverUrl}`); core.info(`Using auth: ${Boolean(apiToken)}`); core.info(`Request payload: ${JSON.stringify(requestPayload)}`); } try { const headers = { "Content-Type": "application/json", }; if (apiToken) { headers.Apitoken = apiToken; } const response = await fetch(apiUrl, { method: "POST", headers, body: JSON.stringify(requestPayload), }); const responseText = await response.text(); if (!response.ok) { core.setFailed( `Agent API request failed (${response.status}): ${responseText}`, ); return; } core.info(`Agent response: ${responseText}`); } catch (error) { core.setFailed(`Error sending task to agent: ${error}`); } } run(); module.exports = __webpack_exports__; /******/ })() ;