feat: add in retry logic
All checks were successful
Dependabot Auto-Merge / dependabot (pull_request) Has been skipped
Dependabot Auto-Merge / devopsbot (pull_request) Has been skipped
Dependabot Auto-Merge / rennovatebot (pull_request) Has been skipped
Unit Tests / unittest (pull_request) Successful in 40s
COMMIT LINT / commitlint (pull_request) Successful in 1m49s
All checks were successful
Dependabot Auto-Merge / dependabot (pull_request) Has been skipped
Dependabot Auto-Merge / devopsbot (pull_request) Has been skipped
Dependabot Auto-Merge / rennovatebot (pull_request) Has been skipped
Unit Tests / unittest (pull_request) Successful in 40s
COMMIT LINT / commitlint (pull_request) Successful in 1m49s
This commit is contained in:
124
dist/index.js
vendored
124
dist/index.js
vendored
@@ -32845,7 +32845,7 @@ const debug = (core.getInput("debug") || "false").toLowerCase() === "true";
|
|||||||
|
|
||||||
const repoFull = process.env.GITHUB_REPOSITORY;
|
const repoFull = process.env.GITHUB_REPOSITORY;
|
||||||
const [owner, repo] = repoFull.split("/");
|
const [owner, repo] = repoFull.split("/");
|
||||||
const segment_id = ["docs", owner, repo].join(".");
|
const segment_id = ["docs", owner].join(".");
|
||||||
|
|
||||||
const serverUrl = (
|
const serverUrl = (
|
||||||
process.env.GITHUB_SERVER_URL ||
|
process.env.GITHUB_SERVER_URL ||
|
||||||
@@ -32868,49 +32868,95 @@ if (apiToken) {
|
|||||||
headers.Apitoken = apiToken;
|
headers.Apitoken = apiToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function post(requestPayload, retries=0) {
|
||||||
|
try{
|
||||||
|
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}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
core.info(`Agent response: ${responseText}`);
|
||||||
|
}
|
||||||
|
} catch(e){
|
||||||
|
if(retries < 5){
|
||||||
|
return post(requestPayload, retries-1)
|
||||||
|
}
|
||||||
|
core.setFailed(`Error sending task to agent: ${error}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const file of markdownFiles) {
|
for (const file of markdownFiles) {
|
||||||
const content = fs.readFileSync(file, "utf8");
|
const content = fs.readFileSync(file, "utf8").trim();
|
||||||
|
const lines = content.split(/\r?\n/);
|
||||||
|
const h1Line = lines.find((line) => /^#\s+/.test(line)) || "";
|
||||||
|
|
||||||
const requestPayload = {
|
const chunks = [];
|
||||||
type: "input",
|
let current = [];
|
||||||
route,
|
|
||||||
argumentId: "plain",
|
|
||||||
force: true,
|
|
||||||
instanceId: null,
|
|
||||||
inputs: {
|
|
||||||
method,
|
|
||||||
inputs: {
|
|
||||||
segment_id,
|
|
||||||
document_id: file,
|
|
||||||
embed_text: content,
|
|
||||||
store_text: content,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (debug) {
|
for (const line of lines) {
|
||||||
core.info(`API URL: ${apiUrl}`);
|
if (/^##\s+/.test(line)) {
|
||||||
core.info(`Route: ${route}`);
|
if (current.length) {
|
||||||
core.info(`Server URL: ${serverUrl}`);
|
chunks.push(current.join("\n").trim());
|
||||||
core.info(`Using auth: ${Boolean(apiToken)}`);
|
}
|
||||||
core.info(`Request payload: ${JSON.stringify(requestPayload)}`);
|
current = [line];
|
||||||
|
} else {
|
||||||
|
current.push(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(apiUrl, {
|
if (current.length) {
|
||||||
method: "POST",
|
chunks.push(current.join("\n").trim());
|
||||||
headers,
|
}
|
||||||
body: JSON.stringify(requestPayload),
|
|
||||||
})
|
const normalizedChunks =
|
||||||
.then((response) => {
|
chunks.length > 0
|
||||||
if (!response.ok) {
|
? chunks.map((chunk) => {
|
||||||
core.setFailed(
|
let chunkLines = chunk.split(/\r?\n/);
|
||||||
`Agent API request failed (${response.status}): ${responseText}`,
|
if (h1Line && chunkLines[0] === h1Line) {
|
||||||
);
|
chunkLines = chunkLines.slice(1);
|
||||||
} else {
|
}
|
||||||
core.info(`Agent response: ${response.text()}`);
|
const body = chunkLines.join("\n").trim();
|
||||||
}
|
return [h1Line, body].filter(Boolean).join("\n");
|
||||||
})
|
})
|
||||||
.catch((error) => core.setFailed(`Error sending task to agent: ${error}`));
|
: [content];
|
||||||
|
|
||||||
|
normalizedChunks.forEach((chunk, index) => {
|
||||||
|
const requestPayload = {
|
||||||
|
type: "input",
|
||||||
|
route,
|
||||||
|
argumentId: "plain",
|
||||||
|
force: true,
|
||||||
|
instanceId: null,
|
||||||
|
inputs: {
|
||||||
|
method,
|
||||||
|
inputs: {
|
||||||
|
segment_id,
|
||||||
|
document_id: [repo, file.replace(".", ""), `part${index + 1}`].join(
|
||||||
|
".",
|
||||||
|
),
|
||||||
|
embed_text: chunk,
|
||||||
|
store_text: chunk,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
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)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
post(requestPayload);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = __webpack_exports__;
|
module.exports = __webpack_exports__;
|
||||||
|
|||||||
122
index.js
122
index.js
@@ -13,7 +13,7 @@ const debug = (core.getInput("debug") || "false").toLowerCase() === "true";
|
|||||||
|
|
||||||
const repoFull = process.env.GITHUB_REPOSITORY;
|
const repoFull = process.env.GITHUB_REPOSITORY;
|
||||||
const [owner, repo] = repoFull.split("/");
|
const [owner, repo] = repoFull.split("/");
|
||||||
const segment_id = ["docs", owner, repo].join(".");
|
const segment_id = ["docs", owner].join(".");
|
||||||
|
|
||||||
const serverUrl = (
|
const serverUrl = (
|
||||||
process.env.GITHUB_SERVER_URL ||
|
process.env.GITHUB_SERVER_URL ||
|
||||||
@@ -36,47 +36,93 @@ if (apiToken) {
|
|||||||
headers.Apitoken = apiToken;
|
headers.Apitoken = apiToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function post(requestPayload, retries=0) {
|
||||||
|
try{
|
||||||
|
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}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
core.info(`Agent response: ${responseText}`);
|
||||||
|
}
|
||||||
|
} catch(e){
|
||||||
|
if(retries < 5){
|
||||||
|
return post(requestPayload, retries-1)
|
||||||
|
}
|
||||||
|
core.setFailed(`Error sending task to agent: ${error}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const file of markdownFiles) {
|
for (const file of markdownFiles) {
|
||||||
const content = fs.readFileSync(file, "utf8").trim();
|
const content = fs.readFileSync(file, "utf8").trim();
|
||||||
|
const lines = content.split(/\r?\n/);
|
||||||
|
const h1Line = lines.find((line) => /^#\s+/.test(line)) || "";
|
||||||
|
|
||||||
const requestPayload = {
|
const chunks = [];
|
||||||
type: "input",
|
let current = [];
|
||||||
route,
|
|
||||||
argumentId: "plain",
|
|
||||||
force: true,
|
|
||||||
instanceId: null,
|
|
||||||
inputs: {
|
|
||||||
method,
|
|
||||||
inputs: {
|
|
||||||
segment_id,
|
|
||||||
document_id: file,
|
|
||||||
embed_text: content,
|
|
||||||
store_text: content,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (debug) {
|
for (const line of lines) {
|
||||||
core.info(`API URL: ${apiUrl}`);
|
if (/^##\s+/.test(line)) {
|
||||||
core.info(`Route: ${route}`);
|
if (current.length) {
|
||||||
core.info(`Server URL: ${serverUrl}`);
|
chunks.push(current.join("\n").trim());
|
||||||
core.info(`Using auth: ${Boolean(apiToken)}`);
|
}
|
||||||
core.info(`Request payload: ${JSON.stringify(requestPayload)}`);
|
current = [line];
|
||||||
|
} else {
|
||||||
|
current.push(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(apiUrl, {
|
if (current.length) {
|
||||||
method: "POST",
|
chunks.push(current.join("\n").trim());
|
||||||
headers,
|
}
|
||||||
body: JSON.stringify(requestPayload),
|
|
||||||
})
|
const normalizedChunks =
|
||||||
.then((response) => {
|
chunks.length > 0
|
||||||
if (!response.ok) {
|
? chunks.map((chunk) => {
|
||||||
core.setFailed(
|
let chunkLines = chunk.split(/\r?\n/);
|
||||||
`Agent API request failed (${response.status}): ${responseText}`,
|
if (h1Line && chunkLines[0] === h1Line) {
|
||||||
);
|
chunkLines = chunkLines.slice(1);
|
||||||
} else {
|
}
|
||||||
core.info(`Agent response: ${response.text()}`);
|
const body = chunkLines.join("\n").trim();
|
||||||
}
|
return [h1Line, body].filter(Boolean).join("\n");
|
||||||
})
|
})
|
||||||
.catch((error) => core.setFailed(`Error sending task to agent: ${error}`));
|
: [content];
|
||||||
|
|
||||||
|
normalizedChunks.forEach((chunk, index) => {
|
||||||
|
const requestPayload = {
|
||||||
|
type: "input",
|
||||||
|
route,
|
||||||
|
argumentId: "plain",
|
||||||
|
force: true,
|
||||||
|
instanceId: null,
|
||||||
|
inputs: {
|
||||||
|
method,
|
||||||
|
inputs: {
|
||||||
|
segment_id,
|
||||||
|
document_id: [repo, file.replace(".", ""), `part${index + 1}`].join(
|
||||||
|
".",
|
||||||
|
),
|
||||||
|
embed_text: chunk,
|
||||||
|
store_text: chunk,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
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)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
post(requestPayload);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user