@absolutejs/rag 0.22.12 → 0.22.13
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.
- package/CHANGELOG.md +10 -0
- package/changelog.json +21 -0
- package/dist/research/index.js +93 -12
- package/dist/research/index.js.map +4 -4
- package/dist/src/research/types.d.ts +16 -0
- package/dist/web/index.js +2 -2
- package/dist/web/index.js.map +3 -3
- package/dist/web-index/index.js +93 -12
- package/dist/web-index/index.js.map +4 -4
- package/package.json +1 -1
package/dist/web-index/index.js
CHANGED
|
@@ -123063,7 +123063,7 @@ var createWebpageReaderClient = (options) => {
|
|
|
123063
123063
|
});
|
|
123064
123064
|
if (result.status === "error") {
|
|
123065
123065
|
const error = result.error;
|
|
123066
|
-
throw new
|
|
123066
|
+
throw new WebReadError(error?.code ?? "reader_unavailable", error?.message ?? "Isolated page read failed");
|
|
123067
123067
|
}
|
|
123068
123068
|
const documents = result.documents;
|
|
123069
123069
|
const sources = result.sources;
|
|
@@ -123402,6 +123402,8 @@ var createResearch = (config) => {
|
|
|
123402
123402
|
const extract = async (task, input) => {
|
|
123403
123403
|
if (!input.query.trim() || input.query.length > 8000)
|
|
123404
123404
|
throw new Error("Research query must contain 1\u20138000 characters");
|
|
123405
|
+
if (task.collection && (!/^\/(?:[^~]|~[01])+$/.test(task.collection.path) || !Number.isSafeInteger(task.collection.minimum) || task.collection.minimum < 1 || !task.collection.requiredFields.length || task.collection.requiredFields.some((key) => !key || key.includes("/"))))
|
|
123406
|
+
throw new Error("Invalid research collection requirement");
|
|
123405
123407
|
const signal = AbortSignal.any([
|
|
123406
123408
|
AbortSignal.timeout(limits.timeoutMs),
|
|
123407
123409
|
...input.signal ? [input.signal] : []
|
|
@@ -123415,7 +123417,14 @@ var createResearch = (config) => {
|
|
|
123415
123417
|
searches: [],
|
|
123416
123418
|
limitations: [],
|
|
123417
123419
|
generatedAt: new Date().toISOString(),
|
|
123418
|
-
operations: []
|
|
123420
|
+
operations: [],
|
|
123421
|
+
...task.collection ? {
|
|
123422
|
+
coverage: {
|
|
123423
|
+
requested: task.collection.minimum,
|
|
123424
|
+
supported: 0,
|
|
123425
|
+
complete: false
|
|
123426
|
+
}
|
|
123427
|
+
} : {}
|
|
123419
123428
|
};
|
|
123420
123429
|
const operationLimit = limits.searches + limits.reads + limits.rounds + 2 + 2 * validationRepairs;
|
|
123421
123430
|
const operate = async (kind, call, usage = () => ({})) => {
|
|
@@ -123588,16 +123597,68 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123588
123597
|
if (!discoveredLinks.has(url) && !result.searches.some((search) => search.sources.some((source) => source.url === url)))
|
|
123589
123598
|
return;
|
|
123590
123599
|
urls.add(url);
|
|
123591
|
-
const page = await operate("read", () =>
|
|
123592
|
-
|
|
123593
|
-
|
|
123594
|
-
|
|
123595
|
-
|
|
123596
|
-
|
|
123600
|
+
const page = await operate("read", async () => {
|
|
123601
|
+
try {
|
|
123602
|
+
return await (config.reader ?? readRAGWebpage)({
|
|
123603
|
+
url,
|
|
123604
|
+
signal,
|
|
123605
|
+
render: config.render,
|
|
123606
|
+
maxChars: Math.min(limits.evidenceChars, 24000)
|
|
123607
|
+
});
|
|
123608
|
+
} catch (error) {
|
|
123609
|
+
signal.throwIfAborted();
|
|
123610
|
+
const messages = {
|
|
123611
|
+
access_blocked: "Website blocked automated access",
|
|
123612
|
+
authentication_required: "Page requires sign-in",
|
|
123613
|
+
http_error: "Page returned an HTTP error",
|
|
123614
|
+
reader_unavailable: "Website reader unavailable",
|
|
123615
|
+
fetch_failed: "Page could not be retrieved",
|
|
123616
|
+
timeout: "Page retrieval timed out"
|
|
123617
|
+
};
|
|
123618
|
+
if (!(error instanceof WebReadError) || !messages[error.code])
|
|
123619
|
+
throw error;
|
|
123620
|
+
return {
|
|
123621
|
+
status: "error",
|
|
123622
|
+
url,
|
|
123623
|
+
finalUrl: url,
|
|
123624
|
+
title: null,
|
|
123625
|
+
text: "",
|
|
123626
|
+
method: "http",
|
|
123627
|
+
truncated: false,
|
|
123628
|
+
attempts: [],
|
|
123629
|
+
fetchedAt: new Date().toISOString(),
|
|
123630
|
+
redirects: [],
|
|
123631
|
+
evidence: { links: [], images: [], media: [], canonicalUrl: null },
|
|
123632
|
+
limitations: [],
|
|
123633
|
+
error: { code: error.code, message: messages[error.code] }
|
|
123634
|
+
};
|
|
123635
|
+
}
|
|
123636
|
+
});
|
|
123637
|
+
if (page.status === "error") {
|
|
123638
|
+
const code = page.error?.code ?? "read_failed";
|
|
123639
|
+
if ([
|
|
123640
|
+
"unsafe_url",
|
|
123641
|
+
"blocked_address",
|
|
123642
|
+
"blocked_url",
|
|
123643
|
+
"invalid_url"
|
|
123644
|
+
].includes(code))
|
|
123645
|
+
throw new WebReadError(code, "Unsafe research source URL");
|
|
123646
|
+
const message = "Source unavailable (" + code + ")";
|
|
123647
|
+
(result.sourceFailures ??= []).push({ url, code, message });
|
|
123648
|
+
result.limitations.push(`${message}: ${url}`);
|
|
123649
|
+
try {
|
|
123650
|
+
config.onError?.({
|
|
123651
|
+
runId: result.id,
|
|
123652
|
+
phase: "read",
|
|
123653
|
+
error: new WebReadError(code, message)
|
|
123654
|
+
});
|
|
123655
|
+
} catch {}
|
|
123656
|
+
return;
|
|
123657
|
+
}
|
|
123597
123658
|
result.limitations.push(...page.limitations);
|
|
123598
123659
|
if (page.status !== "ok")
|
|
123599
123660
|
result.limitations.push(`Page read ${page.status}: ${url}`);
|
|
123600
|
-
if (page.text
|
|
123661
|
+
if (page.text) {
|
|
123601
123662
|
for (const link of page.evidence.links) {
|
|
123602
123663
|
if (discoveredLinks.size >= 64)
|
|
123603
123664
|
break;
|
|
@@ -123634,7 +123695,7 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123634
123695
|
try {
|
|
123635
123696
|
const needsInitialPlan = !input.queries && (input.queryMode === "task" || boundedQueries(input.query).length > 1) && limits.rounds > 0;
|
|
123636
123697
|
if (needsInitialPlan) {
|
|
123637
|
-
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.", {
|
|
123698
|
+
const initial = await generate("plan", PlanSchema, "Turn the research task into concise search-engine queries. Search for the requested answer entities, not merely the client named in the brief. For new partners, pursue external candidate companies across the requested categories; client background and existing partnerships do not fulfill that task. 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.", {
|
|
123638
123699
|
query: input.query,
|
|
123639
123700
|
instructions: task.instructions,
|
|
123640
123701
|
remainingSearches: limits.searches
|
|
@@ -123700,12 +123761,32 @@ Correct the previous schema-invalid response using the validation diagnostics. T
|
|
|
123700
123761
|
instructions: task.instructions,
|
|
123701
123762
|
schema: task.schema,
|
|
123702
123763
|
fields: leaves,
|
|
123703
|
-
sources: reviewSources
|
|
123764
|
+
sources: reviewSources.map(({ passages, ...source }) => ({
|
|
123765
|
+
...source,
|
|
123766
|
+
passages: passages.map(({ id, text }) => ({ id, text }))
|
|
123767
|
+
}))
|
|
123704
123768
|
});
|
|
123705
123769
|
result.fields = bindResearchReview(leaves, reviewed.fields.map((field) => ({
|
|
123706
123770
|
...field,
|
|
123707
123771
|
citations: resolveResearchPassages(field.citations, reviewSources)
|
|
123708
123772
|
})), result.sources);
|
|
123773
|
+
if (task.collection) {
|
|
123774
|
+
const { path, minimum, requiredFields } = task.collection;
|
|
123775
|
+
const indices = new Set(result.fields.flatMap((field) => {
|
|
123776
|
+
if (!field.path.startsWith(path + "/"))
|
|
123777
|
+
return [];
|
|
123778
|
+
const index = field.path.slice(path.length + 1).split("/")[0];
|
|
123779
|
+
return /^\d+$/.test(index) ? [index] : [];
|
|
123780
|
+
}));
|
|
123781
|
+
const supported = [...indices].filter((index) => requiredFields.every((key) => result.fields.some((field) => field.path === `${path}/${index}/${key}` && field.verdict === "supported" && field.value !== null && field.value !== ""))).length;
|
|
123782
|
+
result.coverage = {
|
|
123783
|
+
requested: minimum,
|
|
123784
|
+
supported,
|
|
123785
|
+
complete: supported >= minimum
|
|
123786
|
+
};
|
|
123787
|
+
if (!result.coverage.complete)
|
|
123788
|
+
result.limitations.push(`Requested ${minimum} evidence-backed items; established ${supported}.`);
|
|
123789
|
+
}
|
|
123709
123790
|
const complete = result.fields.length > 0 && result.fields.every((field) => field.verdict === "supported");
|
|
123710
123791
|
result.data = complete ? data : null;
|
|
123711
123792
|
result.status = complete && !result.limitations.length ? "reviewed" : "partial";
|
|
@@ -123837,5 +123918,5 @@ export {
|
|
|
123837
123918
|
webIndexPostgresSchemaSql
|
|
123838
123919
|
};
|
|
123839
123920
|
|
|
123840
|
-
//# debugId=
|
|
123921
|
+
//# debugId=7BD42C26110FB33364756E2164756E21
|
|
123841
123922
|
//# sourceMappingURL=index.js.map
|