@exulu/backend 5.17.0 → 5.17.2

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.
@@ -669,7 +669,7 @@ var ExuluTool = class _ExuluTool {
669
669
  if (!agent) {
670
670
  throw new Error("Agent not found.");
671
671
  }
672
- const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-BCHKS5CK.js");
672
+ const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-6GKOSRRE.js");
673
673
  const tools = await convertExuluToolsToAiSdkTools2(
674
674
  [this],
675
675
  [],
@@ -1570,6 +1570,36 @@ forms \u2014 the bare number on its own, and each individual part when a multi-p
1570
1570
  is referenced (e.g. "ISO 8100-1-2" must yield "8100-1" AND "8100-2").
1571
1571
  Do NOT include generic single words on their own.
1572
1572
  If the question references none, return hasMatches false and an empty array.`;
1573
+ var alnumRuns = (text) => text.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
1574
+ function identifiersInQuestion(matches, question) {
1575
+ const words = alnumRuns(question);
1576
+ const joinedWords = words.join("");
1577
+ const inQuestion = (part) => words.some((word) => word.includes(part) || isTypoOf(word, part));
1578
+ return matches.filter((match) => {
1579
+ const parts = alnumRuns(match);
1580
+ const long = parts.filter((part) => part.length >= 2);
1581
+ if (long.length === 0) return false;
1582
+ if (long.every(inQuestion)) return true;
1583
+ return parts.length >= 2 && joinedWords.includes(parts.join(""));
1584
+ });
1585
+ }
1586
+ function isTypoOf(word, part) {
1587
+ if (part.length < 3 || word === part) return false;
1588
+ if (Math.abs(word.length - part.length) > 1) return false;
1589
+ if (word.length === part.length) {
1590
+ const diff = [];
1591
+ for (let i2 = 0; i2 < part.length; i2++) if (word[i2] !== part[i2]) diff.push(i2);
1592
+ if (diff.length === 2 && diff[1] === diff[0] + 1) {
1593
+ return word[diff[0]] === part[diff[1]] && word[diff[1]] === part[diff[0]];
1594
+ }
1595
+ return part.length >= 5 && diff.length === 1;
1596
+ }
1597
+ if (part.length < 5) return false;
1598
+ const [short, longer] = word.length < part.length ? [word, part] : [part, word];
1599
+ let i = 0;
1600
+ while (i < short.length && short[i] === longer[i]) i++;
1601
+ return short.slice(i) === longer.slice(i + 1);
1602
+ }
1573
1603
  async function resolveIdentifierPins({
1574
1604
  question,
1575
1605
  identifierSets,
@@ -1595,7 +1625,14 @@ async function resolveIdentifierPins({
1595
1625
  })
1596
1626
  });
1597
1627
  if (!output?.hasMatches || !output.matches?.length) return;
1598
- steps.push({ text: `Detected ${set.name} in the question: ${output.matches.join(", ")}` });
1628
+ const matches = identifiersInQuestion(output.matches, question);
1629
+ if (!matches.length) {
1630
+ steps.push({
1631
+ text: `Ignored ${set.name} that are not in the question: ${output.matches.join(", ")}`
1632
+ });
1633
+ return;
1634
+ }
1635
+ steps.push({ text: `Detected ${set.name} in the question: ${matches.join(", ")}` });
1599
1636
  await Promise.all(
1600
1637
  set.contexts.map(async (ctxId) => {
1601
1638
  const ctx = contextsById.get(ctxId);
@@ -1606,9 +1643,9 @@ async function resolveIdentifierPins({
1606
1643
  fields: ["name", "id", "external_id"],
1607
1644
  normalize: (item) => item.external_id ? normalizeFileName(item.external_id) : item.name
1608
1645
  };
1609
- const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: output.matches }) : await fuzzyPrefilter({
1646
+ const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: matches }) : await fuzzyPrefilter({
1610
1647
  ...common,
1611
- relevantKeywords: output.matches,
1648
+ relevantKeywords: matches,
1612
1649
  cutoff: DEFAULT_PREFILTER_CUTOFF,
1613
1650
  // Identifier pins are a hard id-whitelist over filenames,
1614
1651
  // which is exactly the case the supplement exists for.
@@ -3,7 +3,7 @@ import {
3
3
  OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS,
4
4
  convertExuluToolsToAiSdkTools,
5
5
  hydrateVariables
6
- } from "./chunk-ZNG2HEDN.js";
6
+ } from "./chunk-PNBVWUEA.js";
7
7
  import "./chunk-NBAFO66K.js";
8
8
  import "./chunk-F534XOQR.js";
9
9
  import "./chunk-6URU62NI.js";
package/dist/index.cjs CHANGED
@@ -20979,6 +20979,35 @@ async function fuzzyPrefilter({
20979
20979
  );
20980
20980
  return prefiltered;
20981
20981
  }
20982
+ function identifiersInQuestion(matches, question) {
20983
+ const words = alnumRuns(question);
20984
+ const joinedWords = words.join("");
20985
+ const inQuestion = (part) => words.some((word) => word.includes(part) || isTypoOf(word, part));
20986
+ return matches.filter((match) => {
20987
+ const parts = alnumRuns(match);
20988
+ const long = parts.filter((part) => part.length >= 2);
20989
+ if (long.length === 0) return false;
20990
+ if (long.every(inQuestion)) return true;
20991
+ return parts.length >= 2 && joinedWords.includes(parts.join(""));
20992
+ });
20993
+ }
20994
+ function isTypoOf(word, part) {
20995
+ if (part.length < 3 || word === part) return false;
20996
+ if (Math.abs(word.length - part.length) > 1) return false;
20997
+ if (word.length === part.length) {
20998
+ const diff = [];
20999
+ for (let i2 = 0; i2 < part.length; i2++) if (word[i2] !== part[i2]) diff.push(i2);
21000
+ if (diff.length === 2 && diff[1] === diff[0] + 1) {
21001
+ return word[diff[0]] === part[diff[1]] && word[diff[1]] === part[diff[0]];
21002
+ }
21003
+ return part.length >= 5 && diff.length === 1;
21004
+ }
21005
+ if (part.length < 5) return false;
21006
+ const [short, longer] = word.length < part.length ? [word, part] : [part, word];
21007
+ let i = 0;
21008
+ while (i < short.length && short[i] === longer[i]) i++;
21009
+ return short.slice(i) === longer.slice(i + 1);
21010
+ }
20982
21011
  async function resolveIdentifierPins({
20983
21012
  question,
20984
21013
  identifierSets,
@@ -21004,7 +21033,14 @@ async function resolveIdentifierPins({
21004
21033
  })
21005
21034
  });
21006
21035
  if (!output?.hasMatches || !output.matches?.length) return;
21007
- steps.push({ text: `Detected ${set.name} in the question: ${output.matches.join(", ")}` });
21036
+ const matches = identifiersInQuestion(output.matches, question);
21037
+ if (!matches.length) {
21038
+ steps.push({
21039
+ text: `Ignored ${set.name} that are not in the question: ${output.matches.join(", ")}`
21040
+ });
21041
+ return;
21042
+ }
21043
+ steps.push({ text: `Detected ${set.name} in the question: ${matches.join(", ")}` });
21008
21044
  await Promise.all(
21009
21045
  set.contexts.map(async (ctxId) => {
21010
21046
  const ctx = contextsById.get(ctxId);
@@ -21015,9 +21051,9 @@ async function resolveIdentifierPins({
21015
21051
  fields: ["name", "id", "external_id"],
21016
21052
  normalize: (item) => item.external_id ? normalizeFileName(item.external_id) : item.name
21017
21053
  };
21018
- const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: output.matches }) : await fuzzyPrefilter({
21054
+ const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: matches }) : await fuzzyPrefilter({
21019
21055
  ...common,
21020
- relevantKeywords: output.matches,
21056
+ relevantKeywords: matches,
21021
21057
  cutoff: DEFAULT_PREFILTER_CUTOFF,
21022
21058
  // Identifier pins are a hard id-whitelist over filenames,
21023
21059
  // which is exactly the case the supplement exists for.
@@ -21048,7 +21084,7 @@ async function resolveIdentifierPins({
21048
21084
  );
21049
21085
  return { pinsByContext, exactPinsByContext, steps };
21050
21086
  }
21051
- var import_fuse, import_zod21, SUPPLEMENT_MIN_TOKEN_LENGTH, SUPPLEMENT_BUDGET, SUPPLEMENT_BUDGET_WIDE, itemCaches, ensureItemsCache, FUZZY_EXTRACTION_PROMPT, EXACT_EXTRACTION_PROMPT;
21087
+ var import_fuse, import_zod21, SUPPLEMENT_MIN_TOKEN_LENGTH, SUPPLEMENT_BUDGET, SUPPLEMENT_BUDGET_WIDE, itemCaches, ensureItemsCache, FUZZY_EXTRACTION_PROMPT, EXACT_EXTRACTION_PROMPT, alnumRuns;
21052
21088
  var init_prefilter = __esm({
21053
21089
  "ee/agentic-retrieval/pipeline/prefilter.ts"() {
21054
21090
  "use strict";
@@ -21109,6 +21145,7 @@ forms \u2014 the bare number on its own, and each individual part when a multi-p
21109
21145
  is referenced (e.g. "ISO 8100-1-2" must yield "8100-1" AND "8100-2").
21110
21146
  Do NOT include generic single words on their own.
21111
21147
  If the question references none, return hasMatches false and an empty array.`;
21148
+ alnumRuns = (text) => text.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
21112
21149
  }
21113
21150
  });
21114
21151
 
@@ -39522,7 +39559,7 @@ function describeRequestError(err4) {
39522
39559
  init_cjs_shims();
39523
39560
  var import_ai16 = require("ai");
39524
39561
  var import_ajv = __toESM(require("ajv"), 1);
39525
- var import__ = __toESM(require("ajv/dist/2020"), 1);
39562
+ var import__ = __toESM(require("ajv/dist/2020.js"), 1);
39526
39563
  var import_ajv_formats = __toESM(require("ajv-formats"), 1);
39527
39564
  var OUTPUT_SCHEMA_MAX_BYTES = 32 * 1024;
39528
39565
  var SUBMIT_TOOL = "submit_output";
package/dist/index.js CHANGED
@@ -246,7 +246,7 @@ import {
246
246
  willEmbedOnQueue,
247
247
  withRunSession,
248
248
  workflowTemplatesSchema
249
- } from "./chunk-ZNG2HEDN.js";
249
+ } from "./chunk-PNBVWUEA.js";
250
250
  import {
251
251
  LITELLM_UI_PATH,
252
252
  ResolveModelError,
@@ -16154,7 +16154,7 @@ function describeRequestError(err2) {
16154
16154
  // src/exulu/output-schema.ts
16155
16155
  import { generateText as generateText7, jsonSchema, tool as tool2 } from "ai";
16156
16156
  import Ajv from "ajv";
16157
- import Ajv2020 from "ajv/dist/2020";
16157
+ import Ajv2020 from "ajv/dist/2020.js";
16158
16158
  import addFormats from "ajv-formats";
16159
16159
  var OUTPUT_SCHEMA_MAX_BYTES = 32 * 1024;
16160
16160
  var SUBMIT_TOOL = "submit_output";
@@ -1,4 +1,10 @@
1
- import { fuzzyPrefilter, exactTokenPrefilter, resolveIdentifierPins, clearPrefilterCaches } from "./prefilter";
1
+ import {
2
+ fuzzyPrefilter,
3
+ exactTokenPrefilter,
4
+ resolveIdentifierPins,
5
+ clearPrefilterCaches,
6
+ identifiersInQuestion,
7
+ } from "./prefilter";
2
8
 
3
9
  jest.mock("ai", () => ({
4
10
  ...jest.requireActual("ai"),
@@ -247,3 +253,94 @@ describe("resolveIdentifierPins", () => {
247
253
  expect([...(r.exactPinsByContext.get("docs") ?? [])]).toContain("3");
248
254
  });
249
255
  });
256
+
257
+ describe("identifiersInQuestion", () => {
258
+ const keep = (matches: string[], question: string) => identifiersInQuestion(matches, question);
259
+
260
+ it("drops identifiers the question does not contain (the instruction's own example echoed back)", () => {
261
+ expect(keep(["FST", "FST-3"], "Ziehl-Abegg 4C Frequenzumrichter Fehler E 533")).toEqual([]);
262
+ expect(keep(["FST", "FST-2XT"], "Ziehl-Abegg 4C Frequenzumrichter Fehler E 533")).toEqual([]);
263
+ });
264
+
265
+ it("keeps the stem and the full form of an identifier that is in the question", () => {
266
+ expect(keep(["FST", "FST-2XT"], "Wie stelle ich die Türzeiten an der FST-2XT ein?")).toEqual(["FST", "FST-2XT"]);
267
+ expect(keep(["ZADyn", "ZADyn 4CA"], "Kann ich den Umrichter ZADyn 4CA mit 3x230V betreiben?")).toEqual([
268
+ "ZADyn",
269
+ "ZADyn 4CA",
270
+ ]);
271
+ expect(keep(["L1000A", "L1000"], "Fehler E 201 am Yaskawa L1000A")).toEqual(["L1000A", "L1000"]);
272
+ });
273
+
274
+ it("ignores case and how the parts are separated", () => {
275
+ expect(keep(["FST-2XT"], "türzeiten fst2xt")).toEqual(["FST-2XT"]);
276
+ expect(keep(["FST-2XT"], "Türzeiten FST 2 XT")).toEqual(["FST-2XT"]);
277
+ expect(keep(["TFT3-CAN"], "tft3 can anschließen")).toEqual(["TFT3-CAN"]);
278
+ });
279
+
280
+ it("keeps partial forms of a multi-part identifier", () => {
281
+ expect(keep(["8100-1", "8100-2", "ISO 8100-1-2"], "Was regelt die ISO 8100-1-2?")).toEqual([
282
+ "8100-1",
283
+ "8100-2",
284
+ "ISO 8100-1-2",
285
+ ]);
286
+ });
287
+
288
+ it("keeps the identifiers that are there when others are not", () => {
289
+ expect(keep(["CBM", "CBM-2", "FST"], "Bremsentest beim CBM-2")).toEqual(["CBM", "CBM-2"]);
290
+ });
291
+
292
+ it("keeps an identifier the model corrected from a typo in the question", () => {
293
+ expect(keep(["FST", "FST-2XT"], "Wie stelle ich die Türzeiten an der FTS-2XT ein?")).toEqual(["FST", "FST-2XT"]);
294
+ expect(keep(["FST", "FST"], "Fehler 131 an der FTS")).toEqual(["FST", "FST"]);
295
+ expect(keep(["CBM", "CBM-2"], "Bremsentest CMB-2")).toEqual(["CBM", "CBM-2"]);
296
+ expect(keep(["ZADyn", "ZADyn 4CA"], "Umrichter ZAdin 4CA an 3x230V")).toEqual(["ZADyn", "ZADyn 4CA"]);
297
+ expect(keep(["ELEVISION"], "Wie melde ich mich in Elevison an?")).toEqual(["ELEVISION"]);
298
+ });
299
+
300
+ it("does not take an ordinary word one letter away from a short name for a typo", () => {
301
+ expect(keep(["FST"], "Was ist der Fehler E 533?")).toEqual([]);
302
+ expect(keep(["ECO"], "Welches Eck ist gemeint?")).toEqual([]);
303
+ expect(keep(["PAM"], "Wie viel Platz am Schacht?")).toEqual([]);
304
+ });
305
+
306
+ it("does not let letters from neighbouring words stand in for a name", () => {
307
+ expect(keep(["ECO"], "wie code ich das")).toEqual([]);
308
+ });
309
+
310
+ it("drops empty and single-character matches", () => {
311
+ expect(keep(["", " ", "-", "S"], "S 2 Box")).toEqual([]);
312
+ });
313
+ });
314
+
315
+ describe("resolveIdentifierPins grounding", () => {
316
+ const set = { name: "Product names", description: "", examples: ["FST"], strategy: "fuzzy" as const, contexts: ["docs"] };
317
+
318
+ it("pins nothing, and says so, when the extraction names a product the question lacks", async () => {
319
+ (generateText as jest.Mock).mockResolvedValue({ output: { hasMatches: true, matches: ["FST", "FST-2XT"] } });
320
+ const c = ctx("docs");
321
+ const r = await resolveIdentifierPins({
322
+ question: "Ziehl-Abegg 4C Frequenzumrichter Fehler E 533",
323
+ identifierSets: [set],
324
+ contextsById: new Map([["docs", c]]),
325
+ kbKindById: new Map([["docs", "documents"]]),
326
+ model: {},
327
+ });
328
+ expect(r.pinsByContext.size).toBe(0);
329
+ expect(c.getItems).not.toHaveBeenCalled();
330
+ expect(r.steps.map((s) => s.text).join("\n")).not.toMatch(/Detected|Limiting/);
331
+ expect(r.steps.map((s) => s.text).join("\n")).toMatch(/Ignored.*FST, FST-2XT/);
332
+ });
333
+
334
+ it("pins from the identifiers that are in the question only", async () => {
335
+ (generateText as jest.Mock).mockResolvedValue({ output: { hasMatches: true, matches: ["ECO", "FST", "FST-2XT"] } });
336
+ const r = await resolveIdentifierPins({
337
+ question: "Wie sperre ich die Tür beim FST-2XT?",
338
+ identifierSets: [set],
339
+ contextsById: new Map([["docs", ctx("docs")]]),
340
+ kbKindById: new Map([["docs", "documents"]]),
341
+ model: {},
342
+ });
343
+ expect([...(r.pinsByContext.get("docs") ?? [])]).toEqual(["1"]);
344
+ expect(r.steps[0].text).toBe("Detected Product names in the question: FST, FST-2XT");
345
+ });
346
+ });
@@ -403,6 +403,61 @@ If the question references none, return hasMatches false and an empty array.`;
403
403
  // Config-driven identifier-pin resolution
404
404
  // ---------------------------------------------------------------------------
405
405
 
406
+ const alnumRuns = (text: string): string[] =>
407
+ text.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
408
+
409
+ /**
410
+ * The extracted identifiers that the question actually contains.
411
+ *
412
+ * The extraction model sometimes answers with an identifier from its own instruction
413
+ * (the configured examples) for a question that names none of them. Pins are a hard
414
+ * whitelist over file names, so one such answer hides every other document of the
415
+ * knowledge base. An identifier therefore only counts when its parts are in the question:
416
+ * each part of two or more characters inside one of the question's words, or — for
417
+ * identifiers written apart in the question ("FST 2 XT" for "FST-2XT") — the parts joined
418
+ * inside the question's words joined. Case and separators do not matter.
419
+ *
420
+ * The model also corrects typos ("FTS-2XT" → "FST-2XT"), and those corrections are wanted.
421
+ * A part therefore also counts when a word of the question is a typo of it (see isTypoOf).
422
+ */
423
+ export function identifiersInQuestion(matches: string[], question: string): string[] {
424
+ const words = alnumRuns(question);
425
+ const joinedWords = words.join("");
426
+ const inQuestion = (part: string) =>
427
+ words.some((word) => word.includes(part) || isTypoOf(word, part));
428
+ return matches.filter((match) => {
429
+ const parts = alnumRuns(match);
430
+ const long = parts.filter((part) => part.length >= 2);
431
+ if (long.length === 0) return false;
432
+ if (long.every(inQuestion)) return true;
433
+ return parts.length >= 2 && joinedWords.includes(parts.join(""));
434
+ });
435
+ }
436
+
437
+ /**
438
+ * Whether `word` is `part` with one typing slip. Short names are one substituted letter
439
+ * away from ordinary words ("FST" / "ist"), so below five characters only two swapped
440
+ * neighbouring letters count ("FTS"); from five on, any single slip does (one letter
441
+ * swapped with its neighbour, missing, extra or wrong).
442
+ */
443
+ function isTypoOf(word: string, part: string): boolean {
444
+ if (part.length < 3 || word === part) return false;
445
+ if (Math.abs(word.length - part.length) > 1) return false;
446
+ if (word.length === part.length) {
447
+ const diff: number[] = [];
448
+ for (let i = 0; i < part.length; i++) if (word[i] !== part[i]) diff.push(i);
449
+ if (diff.length === 2 && diff[1] === diff[0]! + 1) {
450
+ return word[diff[0]!] === part[diff[1]!] && word[diff[1]!] === part[diff[0]!];
451
+ }
452
+ return part.length >= 5 && diff.length === 1;
453
+ }
454
+ if (part.length < 5) return false;
455
+ const [short, longer] = word.length < part.length ? [word, part] : [part, word];
456
+ let i = 0;
457
+ while (i < short.length && short[i] === longer[i]) i++;
458
+ return short.slice(i) === longer.slice(i + 1);
459
+ }
460
+
406
461
  export async function resolveIdentifierPins({
407
462
  question,
408
463
  identifierSets,
@@ -442,7 +497,14 @@ export async function resolveIdentifierPins({
442
497
  }),
443
498
  });
444
499
  if (!output?.hasMatches || !output.matches?.length) return;
445
- steps.push({ text: `Detected ${set.name} in the question: ${output.matches.join(", ")}` });
500
+ const matches = identifiersInQuestion(output.matches, question);
501
+ if (!matches.length) {
502
+ steps.push({
503
+ text: `Ignored ${set.name} that are not in the question: ${output.matches.join(", ")}`,
504
+ });
505
+ return;
506
+ }
507
+ steps.push({ text: `Detected ${set.name} in the question: ${matches.join(", ")}` });
446
508
 
447
509
  await Promise.all(
448
510
  set.contexts.map(async (ctxId) => {
@@ -457,10 +519,10 @@ export async function resolveIdentifierPins({
457
519
  };
458
520
  const matched =
459
521
  set.strategy === "exact"
460
- ? await exactTokenPrefilter({ ...common, tokens: output.matches! })
522
+ ? await exactTokenPrefilter({ ...common, tokens: matches })
461
523
  : await fuzzyPrefilter({
462
524
  ...common,
463
- relevantKeywords: output.matches!,
525
+ relevantKeywords: matches,
464
526
  cutoff: DEFAULT_PREFILTER_CUTOFF,
465
527
  // Identifier pins are a hard id-whitelist over filenames,
466
528
  // which is exactly the case the supplement exists for.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exulu/backend",
3
3
  "author": "Qventu B.V.",
4
- "version": "5.17.0",
4
+ "version": "5.17.2",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
7
7
  "publishConfig": {