Merge pull request 'feat: adding in repository location so we dont lose it' (#8) from ci into main
Reviewed-on: #8
This commit was merged in pull request #8.
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, "");
|
||||
}
|
||||
|
||||
function buildStoreText({ owner, repo, file, content }) {
|
||||
return [
|
||||
`repo_name: ${repo}`,
|
||||
`repo_owner: ${owner}`,
|
||||
`path: ${file}`,
|
||||
"",
|
||||
content,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function buildRequestPayload({
|
||||
route,
|
||||
method,
|
||||
@@ -82,7 +92,7 @@ function buildRequestPayload({
|
||||
segment_id: segmentId,
|
||||
document_id: sanitizeDocumentId([owner, repo, file].join(".")),
|
||||
embed_text: "",
|
||||
store_text: content,
|
||||
store_text: buildStoreText({ owner, repo, file, content }),
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -165,6 +175,7 @@ async function main({
|
||||
|
||||
module.exports = {
|
||||
buildRequestPayload,
|
||||
buildStoreText,
|
||||
getConfig,
|
||||
listMarkdownFiles,
|
||||
main,
|
||||
|
||||
@@ -3,6 +3,7 @@ const assert = require("node:assert/strict");
|
||||
|
||||
const {
|
||||
buildRequestPayload,
|
||||
buildStoreText,
|
||||
getConfig,
|
||||
main,
|
||||
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 payload = buildRequestPayload({
|
||||
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.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(
|
||||
payload.inputs.inputs.document_id,
|
||||
"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[0].url, "https://agents.example/api");
|
||||
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(
|
||||
calls[0].body.inputs.inputs.document_id,
|
||||
"acme.docsrepo.README.md",
|
||||
|
||||
Reference in New Issue
Block a user