feat: adding in repository location so we dont lose it
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
COMMIT LINT / commitlint (pull_request) Successful in 38s
Unit Tests / unittest (pull_request) Successful in 1m19s
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
COMMIT LINT / commitlint (pull_request) Successful in 38s
Unit Tests / unittest (pull_request) Successful in 1m19s
This commit is contained in:
32797
dist/index.js
vendored
32797
dist/index.js
vendored
File diff suppressed because one or more lines are too long
13
index.js
13
index.js
@@ -61,6 +61,16 @@ function sanitizeDocumentId(value) {
|
|||||||
return value.replace(/[^A-Za-z0-9.]/g, "");
|
return value.replace(/[^A-Za-z0-9.]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildStoreText({ owner, repo, file, content }) {
|
||||||
|
return [
|
||||||
|
`repo_name: ${repo}`,
|
||||||
|
`repo_owner: ${owner}`,
|
||||||
|
`path: ${file}`,
|
||||||
|
"",
|
||||||
|
content,
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
function buildRequestPayload({
|
function buildRequestPayload({
|
||||||
route,
|
route,
|
||||||
method,
|
method,
|
||||||
@@ -82,7 +92,7 @@ function buildRequestPayload({
|
|||||||
segment_id: segmentId,
|
segment_id: segmentId,
|
||||||
document_id: sanitizeDocumentId([owner, repo, file].join(".")),
|
document_id: sanitizeDocumentId([owner, repo, file].join(".")),
|
||||||
embed_text: "",
|
embed_text: "",
|
||||||
store_text: content,
|
store_text: buildStoreText({ owner, repo, file, content }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -165,6 +175,7 @@ async function main({
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
buildRequestPayload,
|
buildRequestPayload,
|
||||||
|
buildStoreText,
|
||||||
getConfig,
|
getConfig,
|
||||||
listMarkdownFiles,
|
listMarkdownFiles,
|
||||||
main,
|
main,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const assert = require("node:assert/strict");
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
buildRequestPayload,
|
buildRequestPayload,
|
||||||
|
buildStoreText,
|
||||||
getConfig,
|
getConfig,
|
||||||
main,
|
main,
|
||||||
sanitizeDocumentId,
|
sanitizeDocumentId,
|
||||||
@@ -35,7 +36,22 @@ test("sanitizeDocumentId removes special characters and preserves periods", () =
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("buildRequestPayload sends the full document in store_text and an empty embed_text", () => {
|
test("buildStoreText prefixes repository metadata before the markdown content", () => {
|
||||||
|
const content = "# Title\n\n## First\nalpha\n\n## Second\nbeta\n";
|
||||||
|
const storeText = buildStoreText({
|
||||||
|
owner: "acme",
|
||||||
|
repo: "docs-repo",
|
||||||
|
file: "guides/setup.md",
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
storeText,
|
||||||
|
"repo_name: docs-repo\nrepo_owner: acme\npath: guides/setup.md\n\n# Title\n\n## First\nalpha\n\n## Second\nbeta\n",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("buildRequestPayload sends metadata-prefixed store_text and an empty embed_text", () => {
|
||||||
const content = "# Title\n\n## First\nalpha\n\n## Second\nbeta\n";
|
const content = "# Title\n\n## First\nalpha\n\n## Second\nbeta\n";
|
||||||
const payload = buildRequestPayload({
|
const payload = buildRequestPayload({
|
||||||
route: "agent-lake",
|
route: "agent-lake",
|
||||||
@@ -48,7 +64,10 @@ test("buildRequestPayload sends the full document in store_text and an empty emb
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(payload.inputs.inputs.embed_text, "");
|
assert.equal(payload.inputs.inputs.embed_text, "");
|
||||||
assert.equal(payload.inputs.inputs.store_text, content);
|
assert.equal(
|
||||||
|
payload.inputs.inputs.store_text,
|
||||||
|
"repo_name: docs-repo\nrepo_owner: acme\npath: guides/setup.md\n\n# Title\n\n## First\nalpha\n\n## Second\nbeta\n",
|
||||||
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
payload.inputs.inputs.document_id,
|
payload.inputs.inputs.document_id,
|
||||||
"acme.docsrepo.guidessetup.md",
|
"acme.docsrepo.guidessetup.md",
|
||||||
@@ -117,7 +136,10 @@ test("main sends one request per file even when the document contains multiple s
|
|||||||
assert.equal(calls.length, 1);
|
assert.equal(calls.length, 1);
|
||||||
assert.equal(calls[0].url, "https://agents.example/api");
|
assert.equal(calls[0].url, "https://agents.example/api");
|
||||||
assert.equal(calls[0].body.inputs.inputs.embed_text, "");
|
assert.equal(calls[0].body.inputs.inputs.embed_text, "");
|
||||||
assert.equal(calls[0].body.inputs.inputs.store_text, content);
|
assert.equal(
|
||||||
|
calls[0].body.inputs.inputs.store_text,
|
||||||
|
"repo_name: docs-repo\nrepo_owner: acme\npath: README.md\n\n# Title\n\n## First\nalpha\n\n## Second\nbeta\n",
|
||||||
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
calls[0].body.inputs.inputs.document_id,
|
calls[0].body.inputs.inputs.document_id,
|
||||||
"acme.docsrepo.README.md",
|
"acme.docsrepo.README.md",
|
||||||
|
|||||||
Reference in New Issue
Block a user