This commit is contained in:
82
index.js
Normal file
82
index.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const { execSync } = require("child_process");
|
||||
const fs = require("fs");
|
||||
|
||||
const core = require("@actions/core");
|
||||
const github = require("@actions/github");
|
||||
|
||||
const apiUrl =
|
||||
core.getInput("api_url") || "http://agents-api.servc-agents:3000";
|
||||
const apiToken = core.getInput("api_token");
|
||||
const route = core.getInput("route") || "agent-lake";
|
||||
const method = core.getInput("method") || "embeddings_insert";
|
||||
const debug = (core.getInput("debug") || "false").toLowerCase() === "true";
|
||||
|
||||
const repoFull = process.env.GITHUB_REPOSITORY;
|
||||
const [owner, repo] = repoFull.split("/");
|
||||
const segment_id = ["docs", owner, repo].join(".");
|
||||
|
||||
const serverUrl = (
|
||||
process.env.GITHUB_SERVER_URL ||
|
||||
github.context.serverUrl ||
|
||||
"https://git.yusufali.ca"
|
||||
).replace(/\/$/, "");
|
||||
|
||||
const markdownFiles = execSync("git ls-files '*.md'", {
|
||||
encoding: "utf8",
|
||||
})
|
||||
.trim()
|
||||
.split("\n")
|
||||
.filter(Boolean);
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
if (apiToken) {
|
||||
headers.Apitoken = apiToken;
|
||||
}
|
||||
|
||||
for (const file of markdownFiles) {
|
||||
const content = fs.readFileSync(file, "utf8");
|
||||
|
||||
const requestPayload = {
|
||||
type: "input",
|
||||
route,
|
||||
argumentId: "plain",
|
||||
force: true,
|
||||
instanceId: null,
|
||||
inputs: {
|
||||
method,
|
||||
inputs: {
|
||||
segment_id,
|
||||
document_id: file,
|
||||
embed_text: content,
|
||||
store_text: content,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (debug) {
|
||||
core.info(`API URL: ${apiUrl}`);
|
||||
core.info(`Route: ${route}`);
|
||||
core.info(`Server URL: ${serverUrl}`);
|
||||
core.info(`Using auth: ${Boolean(apiToken)}`);
|
||||
core.info(`Request payload: ${JSON.stringify(requestPayload)}`);
|
||||
}
|
||||
|
||||
fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(requestPayload),
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
core.setFailed(
|
||||
`Agent API request failed (${response.status}): ${responseText}`,
|
||||
);
|
||||
} else {
|
||||
core.info(`Agent response: ${responseText}`);
|
||||
}
|
||||
})
|
||||
.catch((error) => core.setFailed(`Error sending task to agent: ${error}`));
|
||||
}
|
||||
Reference in New Issue
Block a user