@stackfactor/agent-utils 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,9 @@
18
18
  // generates without it.
19
19
  //
20
20
  // A reference points at the content and never copies it: the passage is
21
- // searched again, under the reader's own access, whenever it is used. It is
21
+ // searched again, under the reader's own access, whenever it is used. Its
22
+ // `url` is the document's page at its source (GitHub, Confluence…), when the
23
+ // platform knows it, so a person can open what was cited. It is
22
24
  // EDIT-only (`visibility: "EDIT"`): the platform strips it from what is
23
25
  // published, so a knowledge base's titles never reach a learner; agents read
24
26
  // it from the draft.
@@ -45,6 +47,8 @@ const CONCURRENCY = 4;
45
47
  /** Statuses that mean the person may not read the knowledge base, or it is gone. */
46
48
  const NO_ACCESS = new Set([401, 403, 404]);
47
49
  const text = (value) => (typeof value === "string" ? value.trim() : "");
50
+ /** An http(s) address, or null: a reference's url lands in an `href`. */
51
+ const webUrl = (value) => (/^https?:\/\//i.test(text(value)) ? text(value) : null);
48
52
  const id = (value) => typeof value === "string" ? value.trim() : value != null && typeof value === "object" ? String(value) : "";
49
53
  /**
50
54
  * The knowledge bases, and the documents in them, that a list of references
@@ -195,6 +199,7 @@ export const retrievePassages = async (options) => {
195
199
  chunkId,
196
200
  documentId: id(chunk.documentId),
197
201
  documentName: text(chunk.documentName) || null,
202
+ documentUrl: webUrl(chunk.documentUrl),
198
203
  knowledgeBaseId: id(chunk.knowledgeBaseId) || knowledgeBaseId,
199
204
  pageNumber: typeof chunk.pageNumber === "number" ? chunk.pageNumber : null,
200
205
  score: typeof chunk.score === "number" ? chunk.score : null,
@@ -222,7 +227,8 @@ export const passagesForPrompt = (passages) => (Array.isArray(passages) ? passag
222
227
  /**
223
228
  * STACKFACTOR references for passages: one per passage, in their order, with no
224
229
  * cap. With `tags`, only the passages the model cited by tag (any tag it made
225
- * up is passed over); without, every passage.
230
+ * up is passed over); without, every passage. Each links to its document's
231
+ * page at the source (`url`) when the passage has one.
226
232
  * @param passages From `retrievePassages`
227
233
  * @param tags The tags the model cited ("k3", "K3" and " k3 " alike)
228
234
  * @returns The references, ready for a skill's, a microskill's or a question's `references`
@@ -234,24 +240,28 @@ export const referencesFor = (passages, tags) => {
234
240
  : null;
235
241
  return list
236
242
  .filter((passage) => !cited || cited.has(passage.tag.toLowerCase()))
237
- .map((passage) => ({
238
- description: passage.sectionTitle,
239
- kind: STACKFACTOR_REFERENCE.KIND,
240
- knowledgeBase: {
241
- chunkId: passage.chunkId,
242
- documentId: passage.documentId,
243
- knowledgeBaseId: passage.knowledgeBaseId,
244
- sectionTitle: passage.sectionTitle,
245
- },
246
- origin: STACKFACTOR_REFERENCE.ORIGIN,
247
- target: {
248
- elementId: passage.documentId,
249
- elementType: STACKFACTOR_REFERENCE.TARGET_ELEMENT_TYPE,
250
- parentId: passage.knowledgeBaseId,
251
- },
252
- title: passage.documentName || passage.sectionTitle || "Knowledge base document",
253
- visibility: STACKFACTOR_REFERENCE.VISIBILITY,
254
- }));
243
+ .map((passage) => {
244
+ const url = webUrl(passage.documentUrl);
245
+ return {
246
+ description: passage.sectionTitle,
247
+ kind: STACKFACTOR_REFERENCE.KIND,
248
+ knowledgeBase: {
249
+ chunkId: passage.chunkId,
250
+ documentId: passage.documentId,
251
+ knowledgeBaseId: passage.knowledgeBaseId,
252
+ sectionTitle: passage.sectionTitle,
253
+ },
254
+ origin: STACKFACTOR_REFERENCE.ORIGIN,
255
+ target: {
256
+ elementId: passage.documentId,
257
+ elementType: STACKFACTOR_REFERENCE.TARGET_ELEMENT_TYPE,
258
+ parentId: passage.knowledgeBaseId,
259
+ },
260
+ title: passage.documentName || passage.sectionTitle || "Knowledge base document",
261
+ ...(url ? { url } : {}),
262
+ visibility: STACKFACTOR_REFERENCE.VISIBILITY,
263
+ };
264
+ });
255
265
  };
256
266
  export default {
257
267
  DEFAULT_TOP_K,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.9.0",
6
+ "version": "1.11.0",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",