@absolutejs/rag 0.22.6 → 0.22.8

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.
@@ -15,6 +15,7 @@ export declare const researchPlugin: (options: ResearchPluginOptions) => import(
15
15
  body: {
16
16
  task?: string | undefined;
17
17
  freshness?: string | undefined;
18
+ queryMode?: "search" | "task" | undefined;
18
19
  query: string;
19
20
  };
20
21
  params: {};
@@ -43,6 +44,7 @@ export declare const researchPlugin: (options: ResearchPluginOptions) => import(
43
44
  body: {
44
45
  task?: string | undefined;
45
46
  freshness?: string | undefined;
47
+ queryMode?: "search" | "task" | undefined;
46
48
  query: string;
47
49
  };
48
50
  params: {};
@@ -68,6 +70,7 @@ export declare const researchPlugin: (options: ResearchPluginOptions) => import(
68
70
  }, import("elysia/types").DefaultEphemeral, import("elysia/types").DefaultEphemeral, "post", `${string}/stream`, import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{
69
71
  body: import("typebox").TObject<{
70
72
  query: import("typebox").TString;
73
+ queryMode: import("typebox").TOptional<import("typebox").TUnion<[import("typebox").TLiteral<"search">, import("typebox").TLiteral<"task">]>>;
71
74
  task: import("typebox").TOptional<import("typebox").TString>;
72
75
  freshness: import("typebox").TOptional<import("typebox").TString>;
73
76
  }>;
@@ -75,6 +78,7 @@ export declare const researchPlugin: (options: ResearchPluginOptions) => import(
75
78
  body: {
76
79
  task?: string | undefined;
77
80
  freshness?: string | undefined;
81
+ queryMode?: "search" | "task" | undefined;
78
82
  query: string;
79
83
  };
80
84
  query: Record<string, string | undefined>;
@@ -216,6 +220,7 @@ export declare const researchPlugin: (options: ResearchPluginOptions) => import(
216
220
  defer: (fn: import("elysia/types").AfterResponseHandler<NoInfer<import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{
217
221
  body: import("typebox").TObject<{
218
222
  query: import("typebox").TString;
223
+ queryMode: import("typebox").TOptional<import("typebox").TUnion<[import("typebox").TLiteral<"search">, import("typebox").TLiteral<"task">]>>;
219
224
  task: import("typebox").TOptional<import("typebox").TString>;
220
225
  freshness: import("typebox").TOptional<import("typebox").TString>;
221
226
  }>;
@@ -49,6 +49,8 @@ export type ResearchTask<S extends ResearchSchema = ResearchSchema> = {
49
49
  instructions?: string;
50
50
  };
51
51
  export type ResearchInput = {
52
+ /** Tasks may contain instructions/JSON; quotes are not literal search filters. */
53
+ queryMode?: "search" | "task";
52
54
  queries?: string[];
53
55
  requiredPhrases?: string[];
54
56
  query: string;
@@ -122733,9 +122733,10 @@ ${prompt}`,
122733
122733
  return generated.object;
122734
122734
  };
122735
122735
  const normalize = (text) => text.normalize("NFKC").toLowerCase().replace(/\s+/gu, " ").trim();
122736
- const requiredPhrases = input.requiredPhrases ?? [...input.query.matchAll(/"([^"\n]+)"/gu)].map((match) => match[1]);
122736
+ const requiredPhrases = input.requiredPhrases ?? (input.queryMode === "task" ? [] : [...input.query.matchAll(/"([^"\n]+)"/gu)].map((match) => match[1]));
122737
122737
  const urls = new Set;
122738
122738
  const queries = new Set;
122739
+ const discoveredLinks = new Map;
122739
122740
  let evidenceChars = 0;
122740
122741
  const sourceText = new Map;
122741
122742
  const rebalanceEvidence = () => {
@@ -122807,7 +122808,7 @@ ${prompt}`,
122807
122808
  const doRead = async (url) => {
122808
122809
  if (urls.has(url) || urls.size >= limits.reads)
122809
122810
  return;
122810
- if (!result.searches.some((search) => search.sources.some((source) => source.url === url)))
122811
+ if (!discoveredLinks.has(url) && !result.searches.some((search) => search.sources.some((source) => source.url === url)))
122811
122812
  return;
122812
122813
  urls.add(url);
122813
122814
  const page = await operate("read", () => (config.reader ?? readRAGWebpage)({
@@ -122820,6 +122821,16 @@ ${prompt}`,
122820
122821
  if (page.status !== "ok")
122821
122822
  result.limitations.push(`Page read ${page.status}: ${url}`);
122822
122823
  if (page.text && page.status !== "error") {
122824
+ for (const link of page.evidence.links) {
122825
+ if (discoveredLinks.size >= 64)
122826
+ break;
122827
+ try {
122828
+ const target = validatePublicWebUrl(new URL(link.url, page.finalUrl).href);
122829
+ target.hash = "";
122830
+ if (!discoveredLinks.has(target.href))
122831
+ discoveredLinks.set(target.href, { url: target.href, label: link.label.slice(0, 200), discoveredOn: page.finalUrl });
122832
+ } catch {}
122833
+ }
122823
122834
  const prior = result.sources.find((source) => source.url === url);
122824
122835
  if (prior) {
122825
122836
  sourceText.set(prior.url, page.text.slice(0, limits.evidenceChars));
@@ -122840,18 +122851,30 @@ ${prompt}`,
122840
122851
  }
122841
122852
  };
122842
122853
  try {
122843
- for (const query of input.queries ?? [input.query])
122844
- await doSearch(query);
122845
- for (let round = 0;round < limits.rounds; round++) {
122854
+ const needsInitialPlan = !input.queries && (input.queryMode === "task" || boundedQueries(input.query).length > 1) && limits.rounds > 0;
122855
+ if (needsInitialPlan) {
122856
+ const initial = await generate("plan", PlanSchema, "Turn the research task into concise search-engine queries. Preserve the requested company identity and target criteria, but never copy instructions, JSON, internal markers, or the whole brief into a query. Prioritize the most useful query first. Return at most remainingSearches queries. Return no URLs: source URLs must be discovered rather than invented.", {
122857
+ query: input.query,
122858
+ instructions: task.instructions,
122859
+ remainingSearches: limits.searches
122860
+ });
122861
+ for (const query of initial.queries)
122862
+ await doSearch(query);
122863
+ } else {
122864
+ for (const query of input.queries ?? [input.query])
122865
+ await doSearch(query);
122866
+ }
122867
+ for (let round = needsInitialPlan ? 1 : 0;round < limits.rounds; round++) {
122846
122868
  if (!result.sources.length && queries.size >= limits.searches)
122847
122869
  break;
122848
122870
  let plan;
122849
122871
  try {
122850
- plan = await generate("plan", PlanSchema, "Select follow-up searches for missing evidence and primary-source URLs to read. For current people or roles, seek the organization\u2019s own leadership/about/team pages; testimonials, package authors, and job listings are not staff identity evidence. For policies, read the full policy or agreement to preserve section scope and exceptions. URLs must come from the supplied search results. done means available evidence addresses the requested schema, not merely that some results exist. Return no actions if further work is not useful.", {
122872
+ plan = await generate("plan", PlanSchema, "Select follow-up searches for missing evidence and primary-source URLs to read. For current people or roles, seek the organization\u2019s own leadership/about/team pages; testimonials, package authors, and job listings are not staff identity evidence. For policies, read the full policy or agreement to preserve section scope and exceptions. URLs must come from the supplied search results or discoveredLinks. Discovered links are unread navigation hints, not evidence; read relevant product, pricing, checkout or policy details before concluding information is absent. done means available evidence addresses the requested schema, not merely that some results exist. Return no actions if further work is not useful.", {
122851
122873
  query: input.query,
122852
122874
  schema: task.schema,
122853
122875
  instructions: task.instructions,
122854
122876
  sources: result.sources,
122877
+ discoveredLinks: [...discoveredLinks.values()].filter((link) => !urls.has(link.url)),
122855
122878
  searched: [...queries],
122856
122879
  read: [...urls],
122857
122880
  remainingSearches: limits.searches - queries.size,
@@ -123027,5 +123050,5 @@ export {
123027
123050
  webIndexPostgresSchemaSql
123028
123051
  };
123029
123052
 
123030
- //# debugId=FAEEE7AE83FFF95664756E2164756E21
123053
+ //# debugId=FF54FBCBBDBC8F3C64756E2164756E21
123031
123054
  //# sourceMappingURL=index.js.map