@lloyal-labs/rig 1.2.1 → 1.2.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.
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -4
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +5 -9
- package/dist/node.js.map +1 -1
- package/dist/sources/chunking.d.ts +23 -3
- package/dist/sources/chunking.d.ts.map +1 -1
- package/dist/sources/chunking.js +72 -3
- package/dist/sources/chunking.js.map +1 -1
- package/dist/sources/web.d.ts +7 -13
- package/dist/sources/web.d.ts.map +1 -1
- package/dist/sources/web.js +31 -174
- package/dist/sources/web.js.map +1 -1
- package/dist/tools/fetch-page.d.ts +22 -7
- package/dist/tools/fetch-page.d.ts.map +1 -1
- package/dist/tools/fetch-page.js +128 -13
- package/dist/tools/fetch-page.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.ts +6 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/web-search.d.ts +5 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +8 -2
- package/dist/tools/web-search.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rig — research infrastructure for the lloyal agent pipeline
|
|
3
3
|
*
|
|
4
|
-
* The default export is
|
|
5
|
-
*
|
|
4
|
+
* The default export is platform-agnostic. linkedom + @mozilla/readability
|
|
5
|
+
* are pure JS and work in both Node.js and React Native (Hermes).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Node-specific exports (createReranker, WebSource, CorpusSource,
|
|
8
|
+
* loadResources, chunkResources) require node:fs and are available
|
|
9
|
+
* via `@lloyal-labs/rig/node`.
|
|
9
10
|
*
|
|
10
11
|
* @packageDocumentation
|
|
11
12
|
* @category Rig
|
|
12
13
|
*/
|
|
13
|
-
export { createTools, reportTool, ResearchTool, WebSearchTool, TavilyProvider, WebResearchTool, PlanTool, } from './tools';
|
|
14
|
+
export { createTools, reportTool, ResearchTool, WebSearchTool, TavilyProvider, FetchPageTool, WebResearchTool, PlanTool, } from './tools';
|
|
14
15
|
export type { ResearchToolOpts, WebResearchToolOpts, PlanToolOpts, PlanResult, PlanQuestion, SearchProvider, SearchResult, Reranker, ScoredChunk, ScoredResult, } from './tools';
|
|
15
|
-
export { chunkFetchedPages } from './sources/chunking';
|
|
16
|
+
export { chunkFetchedPages, chunkHtml } from './sources/chunking';
|
|
16
17
|
export type { FetchedPage } from './sources/chunking';
|
|
17
18
|
export type { SourceContext } from './sources/types';
|
|
18
19
|
export type { Resource, Chunk } from './resources/types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,WAAW,EAAE,UAAU,EACvB,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAC1D,eAAe,EAAE,QAAQ,GAC1B,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,gBAAgB,EAAE,mBAAmB,EAAE,YAAY,EACnD,UAAU,EAAE,YAAY,EACxB,cAAc,EAAE,YAAY,EAC5B,QAAQ,EAAE,WAAW,EAAE,YAAY,GACpC,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,27 +2,30 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Rig — research infrastructure for the lloyal agent pipeline
|
|
4
4
|
*
|
|
5
|
-
* The default export is
|
|
6
|
-
*
|
|
5
|
+
* The default export is platform-agnostic. linkedom + @mozilla/readability
|
|
6
|
+
* are pure JS and work in both Node.js and React Native (Hermes).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Node-specific exports (createReranker, WebSource, CorpusSource,
|
|
9
|
+
* loadResources, chunkResources) require node:fs and are available
|
|
10
|
+
* via `@lloyal-labs/rig/node`.
|
|
10
11
|
*
|
|
11
12
|
* @packageDocumentation
|
|
12
13
|
* @category Rig
|
|
13
14
|
*/
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.chunkFetchedPages = exports.PlanTool = exports.WebResearchTool = exports.TavilyProvider = exports.WebSearchTool = exports.ResearchTool = exports.reportTool = exports.createTools = void 0;
|
|
16
|
-
// Tools (
|
|
16
|
+
exports.chunkHtml = exports.chunkFetchedPages = exports.PlanTool = exports.WebResearchTool = exports.FetchPageTool = exports.TavilyProvider = exports.WebSearchTool = exports.ResearchTool = exports.reportTool = exports.createTools = void 0;
|
|
17
|
+
// Tools (pure TS + Effection + linkedom — platform-agnostic)
|
|
17
18
|
var tools_1 = require("./tools");
|
|
18
19
|
Object.defineProperty(exports, "createTools", { enumerable: true, get: function () { return tools_1.createTools; } });
|
|
19
20
|
Object.defineProperty(exports, "reportTool", { enumerable: true, get: function () { return tools_1.reportTool; } });
|
|
20
21
|
Object.defineProperty(exports, "ResearchTool", { enumerable: true, get: function () { return tools_1.ResearchTool; } });
|
|
21
22
|
Object.defineProperty(exports, "WebSearchTool", { enumerable: true, get: function () { return tools_1.WebSearchTool; } });
|
|
22
23
|
Object.defineProperty(exports, "TavilyProvider", { enumerable: true, get: function () { return tools_1.TavilyProvider; } });
|
|
24
|
+
Object.defineProperty(exports, "FetchPageTool", { enumerable: true, get: function () { return tools_1.FetchPageTool; } });
|
|
23
25
|
Object.defineProperty(exports, "WebResearchTool", { enumerable: true, get: function () { return tools_1.WebResearchTool; } });
|
|
24
26
|
Object.defineProperty(exports, "PlanTool", { enumerable: true, get: function () { return tools_1.PlanTool; } });
|
|
25
|
-
// Chunking (
|
|
27
|
+
// Chunking (platform-agnostic — linkedom is pure JS)
|
|
26
28
|
var chunking_1 = require("./sources/chunking");
|
|
27
29
|
Object.defineProperty(exports, "chunkFetchedPages", { enumerable: true, get: function () { return chunking_1.chunkFetchedPages; } });
|
|
30
|
+
Object.defineProperty(exports, "chunkHtml", { enumerable: true, get: function () { return chunking_1.chunkHtml; } });
|
|
28
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,6DAA6D;AAC7D,iCAIiB;AAHf,oGAAA,WAAW,OAAA;AAAE,mGAAA,UAAU,OAAA;AACvB,qGAAA,YAAY,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,sGAAA,aAAa,OAAA;AAC1D,wGAAA,eAAe,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAS3B,qDAAqD;AACrD,+CAAkE;AAAzD,6GAAA,iBAAiB,OAAA;AAAE,qGAAA,SAAS,OAAA"}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Node.js-specific exports for @lloyal-labs/rig
|
|
3
3
|
*
|
|
4
|
-
* These require node:fs
|
|
5
|
-
*
|
|
6
|
-
* only in Node.js environments.
|
|
4
|
+
* These require node:fs and/or @lloyal-labs/lloyal.node.
|
|
5
|
+
* Import from `@lloyal-labs/rig/node` only in Node.js environments.
|
|
7
6
|
*
|
|
8
7
|
* @packageDocumentation
|
|
9
8
|
* @category Rig
|
|
@@ -12,6 +11,5 @@ export * from './index';
|
|
|
12
11
|
export { createReranker } from './reranker';
|
|
13
12
|
export { WebSource } from './sources/web';
|
|
14
13
|
export { CorpusSource } from './sources/corpus';
|
|
15
|
-
export { FetchPageTool } from './tools/fetch-page';
|
|
16
14
|
export { loadResources, chunkResources } from './resources';
|
|
17
15
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/node.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Node.js-specific exports for @lloyal-labs/rig
|
|
4
4
|
*
|
|
5
|
-
* These require node:fs
|
|
6
|
-
*
|
|
7
|
-
* only in Node.js environments.
|
|
5
|
+
* These require node:fs and/or @lloyal-labs/lloyal.node.
|
|
6
|
+
* Import from `@lloyal-labs/rig/node` only in Node.js environments.
|
|
8
7
|
*
|
|
9
8
|
* @packageDocumentation
|
|
10
9
|
* @category Rig
|
|
@@ -24,20 +23,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
24
23
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
24
|
};
|
|
26
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.chunkResources = exports.loadResources = exports.
|
|
28
|
-
// Re-export everything from the
|
|
26
|
+
exports.chunkResources = exports.loadResources = exports.CorpusSource = exports.WebSource = exports.createReranker = void 0;
|
|
27
|
+
// Re-export everything from the platform-agnostic barrel
|
|
29
28
|
__exportStar(require("./index"), exports);
|
|
30
29
|
// Node-only: Reranker factory (requires @lloyal-labs/lloyal.node)
|
|
31
30
|
var reranker_1 = require("./reranker");
|
|
32
31
|
Object.defineProperty(exports, "createReranker", { enumerable: true, get: function () { return reranker_1.createReranker; } });
|
|
33
|
-
// Node-only: Sources (require node:fs
|
|
32
|
+
// Node-only: Sources (require node:fs)
|
|
34
33
|
var web_1 = require("./sources/web");
|
|
35
34
|
Object.defineProperty(exports, "WebSource", { enumerable: true, get: function () { return web_1.WebSource; } });
|
|
36
35
|
var corpus_1 = require("./sources/corpus");
|
|
37
36
|
Object.defineProperty(exports, "CorpusSource", { enumerable: true, get: function () { return corpus_1.CorpusSource; } });
|
|
38
|
-
// Node-only: FetchPageTool (requires linkedom + @mozilla/readability)
|
|
39
|
-
var fetch_page_1 = require("./tools/fetch-page");
|
|
40
|
-
Object.defineProperty(exports, "FetchPageTool", { enumerable: true, get: function () { return fetch_page_1.FetchPageTool; } });
|
|
41
37
|
// Node-only: Resource loading (requires node:fs)
|
|
42
38
|
var resources_1 = require("./resources");
|
|
43
39
|
Object.defineProperty(exports, "loadResources", { enumerable: true, get: function () { return resources_1.loadResources; } });
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;AAEH,yDAAyD;AACzD,0CAAwB;AAExB,kEAAkE;AAClE,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AAEvB,uCAAuC;AACvC,qCAA0C;AAAjC,gGAAA,SAAS,OAAA;AAClB,2CAAgD;AAAvC,sGAAA,YAAY,OAAA;AAErB,iDAAiD;AACjD,yCAA4D;AAAnD,0GAAA,aAAa,OAAA;AAAE,2GAAA,cAAc,OAAA"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Chunking utilities for web page content
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Two strategies:
|
|
5
|
+
* - {@link chunkHtml} — structural splitting on HTML headings/paragraphs
|
|
6
|
+
* via linkedom. Used by FetchPageTool for per-tool reranking.
|
|
7
|
+
* - {@link chunkFetchedPages} — plain-text `\n\n` splitting for buffered
|
|
8
|
+
* content. Used for post-research passage reranking.
|
|
6
9
|
*
|
|
7
10
|
* @packageDocumentation
|
|
8
11
|
* @category Rig
|
|
@@ -38,4 +41,21 @@ export interface FetchedPage {
|
|
|
38
41
|
* @category Rig
|
|
39
42
|
*/
|
|
40
43
|
export declare function chunkFetchedPages(pages: FetchedPage[]): Chunk[];
|
|
44
|
+
/**
|
|
45
|
+
* Split article HTML into heading-delimited section chunks via linkedom
|
|
46
|
+
*
|
|
47
|
+
* Same structural strategy as `parseMarkdown` (md4c) uses for corpus files:
|
|
48
|
+
* headings are section boundaries, content between headings is accumulated
|
|
49
|
+
* into a single chunk with the heading as metadata.
|
|
50
|
+
*
|
|
51
|
+
* Falls back to `<p>`-level chunks for pages without headings.
|
|
52
|
+
*
|
|
53
|
+
* @param html - Article HTML from Readability's `article.content`
|
|
54
|
+
* @param url - Page URL (used as chunk `resource`)
|
|
55
|
+
* @param title - Page title (used as default heading)
|
|
56
|
+
* @returns Array of section-level chunks
|
|
57
|
+
*
|
|
58
|
+
* @category Rig
|
|
59
|
+
*/
|
|
60
|
+
export declare function chunkHtml(html: string, url: string, title: string): Promise<Chunk[]>;
|
|
41
61
|
//# sourceMappingURL=chunking.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../../src/sources/chunking.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../../src/sources/chunking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,CAkC/D;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAmD1F"}
|
package/dist/sources/chunking.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Chunking utilities for web page content
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Two strategies:
|
|
6
|
+
* - {@link chunkHtml} — structural splitting on HTML headings/paragraphs
|
|
7
|
+
* via linkedom. Used by FetchPageTool for per-tool reranking.
|
|
8
|
+
* - {@link chunkFetchedPages} — plain-text `\n\n` splitting for buffered
|
|
9
|
+
* content. Used for post-research passage reranking.
|
|
7
10
|
*
|
|
8
11
|
* @packageDocumentation
|
|
9
12
|
* @category Rig
|
|
10
13
|
*/
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.chunkFetchedPages = chunkFetchedPages;
|
|
16
|
+
exports.chunkHtml = chunkHtml;
|
|
13
17
|
/**
|
|
14
18
|
* Convert buffered web pages into {@link Chunk} instances for reranking
|
|
15
19
|
*
|
|
@@ -55,4 +59,69 @@ function chunkFetchedPages(pages) {
|
|
|
55
59
|
}
|
|
56
60
|
return chunks;
|
|
57
61
|
}
|
|
62
|
+
const HEADING_TAGS = new Set(['H1', 'H2', 'H3', 'H4', 'H5', 'H6']);
|
|
63
|
+
const TEXT_TAGS = new Set(['P', 'LI', 'BLOCKQUOTE', 'PRE', 'TD', 'TH', 'FIGCAPTION', 'DT', 'DD']);
|
|
64
|
+
/**
|
|
65
|
+
* Split article HTML into heading-delimited section chunks via linkedom
|
|
66
|
+
*
|
|
67
|
+
* Same structural strategy as `parseMarkdown` (md4c) uses for corpus files:
|
|
68
|
+
* headings are section boundaries, content between headings is accumulated
|
|
69
|
+
* into a single chunk with the heading as metadata.
|
|
70
|
+
*
|
|
71
|
+
* Falls back to `<p>`-level chunks for pages without headings.
|
|
72
|
+
*
|
|
73
|
+
* @param html - Article HTML from Readability's `article.content`
|
|
74
|
+
* @param url - Page URL (used as chunk `resource`)
|
|
75
|
+
* @param title - Page title (used as default heading)
|
|
76
|
+
* @returns Array of section-level chunks
|
|
77
|
+
*
|
|
78
|
+
* @category Rig
|
|
79
|
+
*/
|
|
80
|
+
async function chunkHtml(html, url, title) {
|
|
81
|
+
const { parseHTML } = await Promise.resolve().then(() => require('linkedom'));
|
|
82
|
+
const { document } = parseHTML(html);
|
|
83
|
+
const chunks = [];
|
|
84
|
+
let currentHeading = title;
|
|
85
|
+
let currentText = '';
|
|
86
|
+
let chunkIndex = 0;
|
|
87
|
+
function flushSection() {
|
|
88
|
+
const text = currentText.trim();
|
|
89
|
+
if (text.length > 40) {
|
|
90
|
+
chunks.push({
|
|
91
|
+
resource: url,
|
|
92
|
+
heading: currentHeading || title || url,
|
|
93
|
+
text,
|
|
94
|
+
tokens: [],
|
|
95
|
+
startLine: chunkIndex + 1,
|
|
96
|
+
endLine: chunkIndex + 1,
|
|
97
|
+
});
|
|
98
|
+
chunkIndex++;
|
|
99
|
+
}
|
|
100
|
+
currentText = '';
|
|
101
|
+
}
|
|
102
|
+
// Walk all elements in the article DOM
|
|
103
|
+
const elements = document.querySelectorAll('*');
|
|
104
|
+
for (const el of elements) {
|
|
105
|
+
const tag = el.tagName;
|
|
106
|
+
if (HEADING_TAGS.has(tag)) {
|
|
107
|
+
// Close current section, start new one with this heading
|
|
108
|
+
flushSection();
|
|
109
|
+
currentHeading = el.textContent?.trim() || title;
|
|
110
|
+
}
|
|
111
|
+
else if (TEXT_TAGS.has(tag)) {
|
|
112
|
+
// Accumulate text content — skip if this element is nested inside
|
|
113
|
+
// another TEXT_TAG (avoid double-counting nested <li> etc.)
|
|
114
|
+
const parentTag = el.parentElement?.tagName;
|
|
115
|
+
if (parentTag && TEXT_TAGS.has(parentTag))
|
|
116
|
+
continue;
|
|
117
|
+
const text = el.textContent?.trim();
|
|
118
|
+
if (text) {
|
|
119
|
+
currentText += (currentText ? '\n\n' : '') + text;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Flush final section
|
|
124
|
+
flushSection();
|
|
125
|
+
return chunks;
|
|
126
|
+
}
|
|
58
127
|
//# sourceMappingURL=chunking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunking.js","sourceRoot":"","sources":["../../src/sources/chunking.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"chunking.js","sourceRoot":"","sources":["../../src/sources/chunking.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAkC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BAAgB,CAAC,GAAG,CAAC,CAAC;IAChD,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC;QAEvB,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,yDAAyD;YACzD,YAAY,EAAE,CAAC;YACf,cAAc,GAAG,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC;QACnD,CAAC;aAAM,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,kEAAkE;YAClE,4DAA4D;YAC5D,MAAM,SAAS,GAAG,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC;YAC5C,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;gBAAE,SAAS;YAEpD,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;YACpC,IAAI,IAAI,EAAE,CAAC;gBACT,WAAW,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,YAAY,EAAE,CAAC;IAEf,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/sources/web.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { Operation } from "effection";
|
|
2
2
|
import { Source } from "@lloyal-labs/lloyal-agents";
|
|
3
|
-
import { Tool } from "@lloyal-labs/lloyal-agents";
|
|
3
|
+
import type { Tool } from "@lloyal-labs/lloyal-agents";
|
|
4
4
|
import type { Chunk } from "../resources/types";
|
|
5
5
|
import type { SourceContext } from "./types";
|
|
6
6
|
import type { SearchProvider } from "../tools/types";
|
|
7
7
|
export { chunkFetchedPages, type FetchedPage } from "./chunking";
|
|
8
8
|
/**
|
|
9
|
-
* Web-backed research source
|
|
9
|
+
* Web-backed research source
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* {@link Chunk} instances via {@link chunkFetchedPages} for reranker scoring.
|
|
11
|
+
* Agents search the web via {@link WebSearchTool} (returns titles, snippets,
|
|
12
|
+
* URLs), then fetch promising pages via {@link FetchPageTool} (returns
|
|
13
|
+
* reranked relevant chunks). Fetched content is buffered for post-research
|
|
14
|
+
* passage reranking via {@link getChunks}.
|
|
16
15
|
*
|
|
17
16
|
* @category Rig
|
|
18
17
|
*/
|
|
@@ -33,12 +32,7 @@ export declare class WebSource extends Source<SourceContext, Chunk> {
|
|
|
33
32
|
/** @inheritDoc */
|
|
34
33
|
get groundingTools(): Tool[];
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Resets the internal {@link FetchedPage} buffer on every call so
|
|
39
|
-
* prior-run content does not leak into a new research pass. Constructs
|
|
40
|
-
* the {@link WebResearchTool} on first bind only (toolkit is stateless
|
|
41
|
-
* once built).
|
|
35
|
+
* Wire reranker to FetchPageTool and build the research toolkit
|
|
42
36
|
*
|
|
43
37
|
* @inheritDoc
|
|
44
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/sources/web.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/sources/web.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAwB,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAmDjE;;;;;;;;;GASG;AACH,qBAAa,SAAU,SAAQ,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC;IACzD,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,aAAa,CAAgC;IAErD,kBAAkB;IAClB,QAAQ,CAAC,IAAI,SAAS;IAEtB;;OAEG;gBACS,QAAQ,EAAE,cAAc;IAOpC,kBAAkB;IAClB,IAAI,YAAY,IAAI,IAAI,CAIvB;IAED,kBAAkB;IAClB,IAAI,cAAc,IAAI,IAAI,EAAE,CAE3B;IAED;;;;OAIG;IACF,IAAI,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC;IAoC1C,kBAAkB;IAClB,SAAS,IAAI,KAAK,EAAE;CAGrB"}
|
package/dist/sources/web.js
CHANGED
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebSource = exports.chunkFetchedPages = void 0;
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
-
const effection_1 = require("effection");
|
|
7
6
|
const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
8
|
-
const lloyal_agents_2 = require("@lloyal-labs/lloyal-agents");
|
|
9
7
|
const web_search_1 = require("../tools/web-search");
|
|
10
8
|
const fetch_page_1 = require("../tools/fetch-page");
|
|
11
9
|
const web_research_1 = require("../tools/web-research");
|
|
@@ -25,185 +23,42 @@ function readTask(name) {
|
|
|
25
23
|
}
|
|
26
24
|
// ── BufferingFetchPage ───────────────────────────────────────────
|
|
27
25
|
/**
|
|
28
|
-
*
|
|
26
|
+
* Thin wrapper over {@link FetchPageTool} that buffers fetched content
|
|
27
|
+
* for post-research reranking via {@link WebSource.getChunks}.
|
|
29
28
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* post-research reranking. An attention scratchpad (forked from
|
|
33
|
-
* {@link ScratchpadParent}) then grammar-constrains a summary + links
|
|
34
|
-
* extraction, returning the compact result to the calling agent instead
|
|
35
|
-
* of the full page text. Falls back to the full result if extraction
|
|
36
|
-
* fails or no scratchpad parent is available.
|
|
29
|
+
* No scratchpad extraction. No content transformation. Just buffers
|
|
30
|
+
* the raw text alongside returning the reranked result to the agent.
|
|
37
31
|
*
|
|
38
32
|
* @category Rig
|
|
39
33
|
*/
|
|
40
|
-
class BufferingFetchPage extends
|
|
41
|
-
name = "fetch_page";
|
|
42
|
-
description = "Fetch a web page and extract its article content. Returns a summary and any links worth following. Use to read search results or follow links discovered in pages.";
|
|
43
|
-
parameters = {
|
|
44
|
-
type: "object",
|
|
45
|
-
properties: { url: { type: "string", description: "URL to fetch" } },
|
|
46
|
-
required: ["url"],
|
|
47
|
-
};
|
|
48
|
-
_inner;
|
|
34
|
+
class BufferingFetchPage extends fetch_page_1.FetchPageTool {
|
|
49
35
|
_buffer;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
super();
|
|
53
|
-
this._inner = new fetch_page_1.FetchPageTool(maxChars);
|
|
36
|
+
constructor(buffer, maxChars) {
|
|
37
|
+
super(maxChars);
|
|
54
38
|
this._buffer = buffer;
|
|
55
|
-
this._extractTask = extractTask;
|
|
56
39
|
}
|
|
57
40
|
*execute(args) {
|
|
58
|
-
const result = yield*
|
|
41
|
+
const result = yield* super.execute(args);
|
|
59
42
|
const r = result;
|
|
60
43
|
if (typeof r?.content === "string" &&
|
|
61
44
|
r.content !== "[Could not extract article content]") {
|
|
62
|
-
const content = r.content;
|
|
63
|
-
// Buffer full content for reranking
|
|
64
45
|
this._buffer.push({
|
|
65
46
|
url: r.url || args.url,
|
|
66
47
|
title: r.title || "",
|
|
67
|
-
text: content,
|
|
48
|
+
text: r.content,
|
|
68
49
|
});
|
|
69
|
-
// Attention scratchpad: fork from innermost active root, extract summary + links, prune
|
|
70
|
-
let parent;
|
|
71
|
-
try {
|
|
72
|
-
parent = yield* lloyal_agents_2.ScratchpadParent.expect();
|
|
73
|
-
}
|
|
74
|
-
catch { /* no parent — skip extraction */ }
|
|
75
|
-
if (!parent || parent.disposed)
|
|
76
|
-
return result;
|
|
77
|
-
const ctx = yield* lloyal_agents_2.Ctx.expect();
|
|
78
|
-
const schema = {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: {
|
|
81
|
-
summary: { type: "string" },
|
|
82
|
-
links: { type: "array", items: { type: "string" } },
|
|
83
|
-
},
|
|
84
|
-
required: ["summary", "links"],
|
|
85
|
-
};
|
|
86
|
-
const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(schema)));
|
|
87
|
-
const extractPrompt = this._extractTask.user
|
|
88
|
-
.replace("{{url}}", args.url)
|
|
89
|
-
.replace("{{title}}", r.title || "")
|
|
90
|
-
.replace("{{content}}", content);
|
|
91
|
-
const messages = [
|
|
92
|
-
{ role: "system", content: this._extractTask.system },
|
|
93
|
-
{ role: "user", content: extractPrompt },
|
|
94
|
-
];
|
|
95
|
-
const { prompt } = ctx.formatChatSync(JSON.stringify(messages), { enableThinking: false });
|
|
96
|
-
try {
|
|
97
|
-
const extracted = yield* (0, lloyal_agents_2.generate)({
|
|
98
|
-
prompt,
|
|
99
|
-
grammar,
|
|
100
|
-
params: { temperature: 0.3 },
|
|
101
|
-
parse: (o) => JSON.parse(o),
|
|
102
|
-
parent,
|
|
103
|
-
});
|
|
104
|
-
return {
|
|
105
|
-
url: r.url || args.url,
|
|
106
|
-
title: r.title || "",
|
|
107
|
-
summary: extracted.parsed?.summary || "",
|
|
108
|
-
links: extracted.parsed?.links || [],
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
return result; // fallback to full result on extraction failure
|
|
113
|
-
}
|
|
114
50
|
}
|
|
115
51
|
return result;
|
|
116
52
|
}
|
|
117
53
|
}
|
|
118
|
-
// ── BufferingWebSearch ────────────────────────────────────────────
|
|
119
|
-
/**
|
|
120
|
-
* Web-search wrapper that extracts a compact summary via attention scratchpad
|
|
121
|
-
*
|
|
122
|
-
* Wraps {@link WebSearchTool} and, when a {@link ScratchpadParent} is
|
|
123
|
-
* available, forks a grammar-constrained generation to distill raw search
|
|
124
|
-
* results into a list of promising URLs plus a brief summary. The compact
|
|
125
|
-
* output reduces KV pressure on the calling agent. Falls back to raw
|
|
126
|
-
* results if extraction fails or no scratchpad parent is available.
|
|
127
|
-
*
|
|
128
|
-
* @category Rig
|
|
129
|
-
*/
|
|
130
|
-
class BufferingWebSearch extends lloyal_agents_2.Tool {
|
|
131
|
-
name = "web_search";
|
|
132
|
-
description = "Search the web. Returns the most relevant URLs and a summary. Use fetch_page to read full content of promising results.";
|
|
133
|
-
parameters = {
|
|
134
|
-
type: "object",
|
|
135
|
-
properties: { query: { type: "string", description: "Search query" } },
|
|
136
|
-
required: ["query"],
|
|
137
|
-
};
|
|
138
|
-
_inner;
|
|
139
|
-
_extractTask;
|
|
140
|
-
constructor(provider, extractTask) {
|
|
141
|
-
super();
|
|
142
|
-
this._inner = new web_search_1.WebSearchTool(provider);
|
|
143
|
-
this._extractTask = extractTask;
|
|
144
|
-
}
|
|
145
|
-
*execute(args) {
|
|
146
|
-
const results = yield* this._inner.execute(args);
|
|
147
|
-
// If error or not an array, return as-is (no scratchpad needed)
|
|
148
|
-
if (!Array.isArray(results) || results.length === 0)
|
|
149
|
-
return results;
|
|
150
|
-
// Scratchpad: fork from innermost active root, extract URLs + summary
|
|
151
|
-
let parent;
|
|
152
|
-
try {
|
|
153
|
-
parent = yield* lloyal_agents_2.ScratchpadParent.expect();
|
|
154
|
-
}
|
|
155
|
-
catch { /* no parent — return raw */ }
|
|
156
|
-
if (!parent || parent.disposed)
|
|
157
|
-
return results;
|
|
158
|
-
const ctx = yield* lloyal_agents_2.Ctx.expect();
|
|
159
|
-
const schema = {
|
|
160
|
-
type: "object",
|
|
161
|
-
properties: {
|
|
162
|
-
urls: { type: "array", items: { type: "string" }, description: "URLs worth fetching" },
|
|
163
|
-
summary: { type: "string", description: "Brief summary of what the search found" },
|
|
164
|
-
},
|
|
165
|
-
required: ["urls", "summary"],
|
|
166
|
-
};
|
|
167
|
-
const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(schema)));
|
|
168
|
-
const resultsText = results
|
|
169
|
-
.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}\n ${r.snippet}`)
|
|
170
|
-
.join("\n\n");
|
|
171
|
-
const extractPrompt = this._extractTask.user
|
|
172
|
-
.replace("{{query}}", args.query)
|
|
173
|
-
.replace("{{results}}", resultsText);
|
|
174
|
-
const messages = [
|
|
175
|
-
{ role: "system", content: this._extractTask.system },
|
|
176
|
-
{ role: "user", content: extractPrompt },
|
|
177
|
-
];
|
|
178
|
-
const { prompt } = ctx.formatChatSync(JSON.stringify(messages), { enableThinking: false });
|
|
179
|
-
try {
|
|
180
|
-
const extracted = yield* (0, lloyal_agents_2.generate)({
|
|
181
|
-
prompt,
|
|
182
|
-
grammar,
|
|
183
|
-
params: { temperature: 0.3 },
|
|
184
|
-
parse: (o) => JSON.parse(o),
|
|
185
|
-
parent,
|
|
186
|
-
});
|
|
187
|
-
return {
|
|
188
|
-
urls: extracted.parsed?.urls || [],
|
|
189
|
-
summary: extracted.parsed?.summary || "",
|
|
190
|
-
resultCount: results.length,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
return results; // fallback to raw results on extraction failure
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
54
|
// ── WebSource ────────────────────────────────────────────────────
|
|
199
55
|
/**
|
|
200
|
-
* Web-backed research source
|
|
56
|
+
* Web-backed research source
|
|
201
57
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* {@link Chunk} instances via {@link chunkFetchedPages} for reranker scoring.
|
|
58
|
+
* Agents search the web via {@link WebSearchTool} (returns titles, snippets,
|
|
59
|
+
* URLs), then fetch promising pages via {@link FetchPageTool} (returns
|
|
60
|
+
* reranked relevant chunks). Fetched content is buffered for post-research
|
|
61
|
+
* passage reranking via {@link getChunks}.
|
|
207
62
|
*
|
|
208
63
|
* @category Rig
|
|
209
64
|
*/
|
|
@@ -220,11 +75,9 @@ class WebSource extends lloyal_agents_1.Source {
|
|
|
220
75
|
*/
|
|
221
76
|
constructor(provider) {
|
|
222
77
|
super();
|
|
223
|
-
const extractTask = readTask("extract");
|
|
224
|
-
const searchExtractTask = readTask("search-extract");
|
|
225
78
|
this._researchPrompt = readTask("web-research");
|
|
226
|
-
this._fetchPage = new BufferingFetchPage(this._buffer
|
|
227
|
-
this._webSearch = new
|
|
79
|
+
this._fetchPage = new BufferingFetchPage(this._buffer);
|
|
80
|
+
this._webSearch = new web_search_1.WebSearchTool(provider);
|
|
228
81
|
}
|
|
229
82
|
/** @inheritDoc */
|
|
230
83
|
get researchTool() {
|
|
@@ -233,22 +86,26 @@ class WebSource extends lloyal_agents_1.Source {
|
|
|
233
86
|
return this._researchTool;
|
|
234
87
|
}
|
|
235
88
|
/** @inheritDoc */
|
|
236
|
-
get groundingTools() {
|
|
89
|
+
get groundingTools() {
|
|
90
|
+
return [this._webSearch, this._fetchPage];
|
|
91
|
+
}
|
|
237
92
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* Resets the internal {@link FetchedPage} buffer on every call so
|
|
241
|
-
* prior-run content does not leak into a new research pass. Constructs
|
|
242
|
-
* the {@link WebResearchTool} on first bind only (toolkit is stateless
|
|
243
|
-
* once built).
|
|
93
|
+
* Wire reranker to FetchPageTool and build the research toolkit
|
|
244
94
|
*
|
|
245
95
|
* @inheritDoc
|
|
246
96
|
*/
|
|
247
97
|
*bind(ctx) {
|
|
248
98
|
this._buffer.length = 0;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
99
|
+
// Wire reranker to FetchPageTool for chunk scoring
|
|
100
|
+
this._fetchPage.setReranker(ctx.reranker);
|
|
101
|
+
const tw = yield* lloyal_agents_1.Trace.expect();
|
|
102
|
+
tw.write({
|
|
103
|
+
traceId: tw.nextId(),
|
|
104
|
+
parentTraceId: null,
|
|
105
|
+
ts: performance.now(),
|
|
106
|
+
type: "source:bind",
|
|
107
|
+
sourceName: this.name,
|
|
108
|
+
});
|
|
252
109
|
if (!this._researchTool) {
|
|
253
110
|
const webResearch = new web_research_1.WebResearchTool({
|
|
254
111
|
name: "web_research",
|
|
@@ -258,7 +115,7 @@ class WebSource extends lloyal_agents_1.Source {
|
|
|
258
115
|
maxTurns: ctx.maxTurns,
|
|
259
116
|
trace: ctx.trace,
|
|
260
117
|
});
|
|
261
|
-
const toolkit = (0,
|
|
118
|
+
const toolkit = (0, lloyal_agents_1.createToolkit)([
|
|
262
119
|
this._webSearch,
|
|
263
120
|
this._fetchPage,
|
|
264
121
|
ctx.reportTool,
|
package/dist/sources/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/sources/web.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/sources/web.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,kCAAkC;AAElC,8DAA0E;AAK1E,oDAAoD;AACpD,oDAAoD;AACpD,wDAAwD;AACxD,yCAA+C;AAG/C,wCAAwC;AACxC,uCAAiE;AAAxD,6GAAA,iBAAiB,OAAA;AAE1B,oEAAoE;AAEpE,SAAS,QAAQ,CAAC,IAAY;IAC5B,MAAM,GAAG,GAAG,EAAE;SACX,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,E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,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,WAAW,GAAG,IAAI,8BAAe,CAAC;gBACtC,IAAI,EAAE,cAAc;gBACpB,WAAW,EACT,2FAA2F;gBAC7F,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM;gBACzC,cAAc,EAAE,GAAG,CAAC,cAAc;gBAClC,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,KAAK,EAAE,GAAG,CAAC,KAAK;aACjB,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,IAAA,6BAAa,EAAC;gBAC5B,IAAI,CAAC,UAAU;gBACf,IAAI,CAAC,UAAU;gBACf,GAAG,CAAC,UAAU;gBACd,WAAW;aACZ,CAAC,CAAC;YACH,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAChC,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC;QACnC,CAAC;IACH,CAAC;IAED,kBAAkB;IAClB,SAAS;QACP,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AA7ED,8BA6EC"}
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import type { Operation } from 'effection';
|
|
2
2
|
import { Tool } from '@lloyal-labs/lloyal-agents';
|
|
3
|
-
import type { JsonSchema } from '@lloyal-labs/lloyal-agents';
|
|
3
|
+
import type { JsonSchema, ToolContext } from '@lloyal-labs/lloyal-agents';
|
|
4
|
+
import type { Reranker } from './types';
|
|
4
5
|
/**
|
|
5
6
|
* Fetch a web page and extract readable article content.
|
|
6
7
|
*
|
|
7
8
|
* Uses the Fetch API with a 10-second timeout, then extracts the
|
|
8
|
-
* article body via linkedom + Readability.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* article body via linkedom + Readability.
|
|
10
|
+
*
|
|
11
|
+
* When a reranker is set (via {@link setReranker}) and the agent provides
|
|
12
|
+
* a `query` argument, the article HTML is structurally chunked on heading
|
|
13
|
+
* boundaries (same pattern as corpus `parseMarkdown`) and scored against
|
|
14
|
+
* the query. Only the top-K most relevant verbatim chunks are returned —
|
|
15
|
+
* reducing KV pressure without lossy summarization. The reranker runs on
|
|
16
|
+
* its own `llama_context`, consuming zero inference KV.
|
|
17
|
+
*
|
|
18
|
+
* Without a reranker or query, returns the full content truncated to
|
|
19
|
+
* `maxChars` (default 6000). Fully backward compatible.
|
|
11
20
|
*
|
|
12
21
|
* @category Rig
|
|
13
22
|
*/
|
|
14
23
|
export declare class FetchPageTool extends Tool<{
|
|
15
24
|
url: string;
|
|
25
|
+
query?: string;
|
|
16
26
|
}> {
|
|
17
27
|
readonly name = "fetch_page";
|
|
18
|
-
readonly description = "Fetch a web page and extract its article content. Returns readable text with title and excerpt. Use to read search results or follow links discovered in pages.";
|
|
28
|
+
readonly description = "Fetch a web page and extract its article content. Returns readable text with title and excerpt. Use to read search results or follow links discovered in pages. Pass a query to get only the most relevant sections.";
|
|
19
29
|
readonly parameters: JsonSchema;
|
|
20
30
|
private _maxChars;
|
|
21
|
-
|
|
31
|
+
private _reranker;
|
|
32
|
+
private _topK;
|
|
33
|
+
constructor(maxChars?: number, topK?: number);
|
|
34
|
+
/** Inject reranker for chunk scoring. Call from Source.bind(). */
|
|
35
|
+
setReranker(reranker: Reranker): void;
|
|
22
36
|
execute(args: {
|
|
23
37
|
url: string;
|
|
24
|
-
|
|
38
|
+
query?: string;
|
|
39
|
+
}, context?: ToolContext): Operation<unknown>;
|
|
25
40
|
}
|
|
26
41
|
//# sourceMappingURL=fetch-page.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-page.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-page.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"fetch-page.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-page.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAS,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,SAAS,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,SAAQ,IAAI,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;IACtE,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,WAAW,0NAA0N;IAC9O,QAAQ,CAAC,UAAU,EAAE,UAAU,CAO7B;IAEF,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,KAAK,CAAS;gBAEV,QAAQ,SAAO,EAAE,IAAI,SAAI;IAMrC,kEAAkE;IAClE,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAIpC,OAAO,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC;CAgJ3F"}
|
package/dist/tools/fetch-page.js
CHANGED
|
@@ -3,40 +3,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FetchPageTool = void 0;
|
|
4
4
|
const effection_1 = require("effection");
|
|
5
5
|
const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
6
|
+
const chunking_1 = require("../sources/chunking");
|
|
6
7
|
/**
|
|
7
8
|
* Fetch a web page and extract readable article content.
|
|
8
9
|
*
|
|
9
10
|
* Uses the Fetch API with a 10-second timeout, then extracts the
|
|
10
|
-
* article body via linkedom + Readability.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* article body via linkedom + Readability.
|
|
12
|
+
*
|
|
13
|
+
* When a reranker is set (via {@link setReranker}) and the agent provides
|
|
14
|
+
* a `query` argument, the article HTML is structurally chunked on heading
|
|
15
|
+
* boundaries (same pattern as corpus `parseMarkdown`) and scored against
|
|
16
|
+
* the query. Only the top-K most relevant verbatim chunks are returned —
|
|
17
|
+
* reducing KV pressure without lossy summarization. The reranker runs on
|
|
18
|
+
* its own `llama_context`, consuming zero inference KV.
|
|
19
|
+
*
|
|
20
|
+
* Without a reranker or query, returns the full content truncated to
|
|
21
|
+
* `maxChars` (default 6000). Fully backward compatible.
|
|
13
22
|
*
|
|
14
23
|
* @category Rig
|
|
15
24
|
*/
|
|
16
25
|
class FetchPageTool extends lloyal_agents_1.Tool {
|
|
17
26
|
name = 'fetch_page';
|
|
18
|
-
description = 'Fetch a web page and extract its article content. Returns readable text with title and excerpt. Use to read search results or follow links discovered in pages.';
|
|
27
|
+
description = 'Fetch a web page and extract its article content. Returns readable text with title and excerpt. Use to read search results or follow links discovered in pages. Pass a query to get only the most relevant sections.';
|
|
19
28
|
parameters = {
|
|
20
29
|
type: 'object',
|
|
21
|
-
properties: {
|
|
30
|
+
properties: {
|
|
31
|
+
url: { type: 'string', description: 'URL to fetch' },
|
|
32
|
+
query: { type: 'string', description: 'What to look for in this page (optional — improves relevance of returned content)' },
|
|
33
|
+
},
|
|
22
34
|
required: ['url'],
|
|
23
35
|
};
|
|
24
36
|
_maxChars;
|
|
25
|
-
|
|
37
|
+
_reranker = null;
|
|
38
|
+
_topK;
|
|
39
|
+
constructor(maxChars = 6000, topK = 5) {
|
|
26
40
|
super();
|
|
27
41
|
this._maxChars = maxChars;
|
|
42
|
+
this._topK = topK;
|
|
28
43
|
}
|
|
29
|
-
|
|
44
|
+
/** Inject reranker for chunk scoring. Call from Source.bind(). */
|
|
45
|
+
setReranker(reranker) {
|
|
46
|
+
this._reranker = reranker;
|
|
47
|
+
}
|
|
48
|
+
*execute(args, context) {
|
|
30
49
|
const url = args.url?.trim();
|
|
31
50
|
if (!url)
|
|
32
51
|
return { error: 'url must not be empty' };
|
|
33
|
-
// Early reject PDF URLs
|
|
52
|
+
// Early reject PDF URLs
|
|
34
53
|
const lowerUrl = url.toLowerCase();
|
|
35
54
|
if (lowerUrl.endsWith('.pdf') || lowerUrl.includes('.pdf?') || lowerUrl.includes('.pdf#')) {
|
|
36
55
|
return { error: 'PDF documents cannot be extracted. Try searching for an HTML version of this content.', url };
|
|
37
56
|
}
|
|
38
57
|
const maxChars = this._maxChars;
|
|
39
|
-
|
|
58
|
+
const reranker = this._reranker;
|
|
59
|
+
const topK = this._topK;
|
|
60
|
+
// Step 1: Fetch + readability (async)
|
|
61
|
+
const fetched = yield* (0, effection_1.call)(async () => {
|
|
40
62
|
let res;
|
|
41
63
|
try {
|
|
42
64
|
res = await fetch(url, {
|
|
@@ -60,12 +82,105 @@ class FetchPageTool extends lloyal_agents_1.Tool {
|
|
|
60
82
|
const article = new Readability(document).parse();
|
|
61
83
|
if (!article)
|
|
62
84
|
return { url, content: '[Could not extract article content]' };
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
return {
|
|
86
|
+
url,
|
|
87
|
+
title: article.title ?? '',
|
|
88
|
+
content: article.textContent ?? '',
|
|
89
|
+
articleHtml: article.content ?? '',
|
|
90
|
+
excerpt: article.excerpt ?? '',
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
// Early return on error or no article
|
|
94
|
+
if ('error' in fetched)
|
|
95
|
+
return fetched;
|
|
96
|
+
if (!fetched.articleHtml) {
|
|
97
|
+
let content = fetched.content;
|
|
98
|
+
if (content.length > maxChars)
|
|
65
99
|
content = content.slice(0, maxChars) + '\n\n[truncated]';
|
|
100
|
+
return { url: fetched.url, title: fetched.title, content, excerpt: fetched.excerpt };
|
|
101
|
+
}
|
|
102
|
+
// Step 2: Reranker path — chunk HTML structurally, score, return top-K
|
|
103
|
+
if (reranker && args.query) {
|
|
104
|
+
const chunks = yield* (0, effection_1.call)(() => (0, chunking_1.chunkHtml)(fetched.articleHtml, url, fetched.title));
|
|
105
|
+
// Write chunks to trace for replay sufficiency
|
|
106
|
+
let tw;
|
|
107
|
+
try {
|
|
108
|
+
tw = yield* lloyal_agents_1.Trace.expect();
|
|
66
109
|
}
|
|
67
|
-
|
|
68
|
-
|
|
110
|
+
catch { /* no trace context */ }
|
|
111
|
+
const rerankT0 = performance.now();
|
|
112
|
+
if (tw) {
|
|
113
|
+
tw.write({
|
|
114
|
+
traceId: tw.nextId(),
|
|
115
|
+
parentTraceId: null,
|
|
116
|
+
ts: rerankT0,
|
|
117
|
+
type: 'rerank:start',
|
|
118
|
+
query: args.query,
|
|
119
|
+
chunkCount: chunks.length,
|
|
120
|
+
tool: 'fetch_page',
|
|
121
|
+
url,
|
|
122
|
+
chunks: chunks.map(c => ({ heading: c.heading, textLength: c.text.length, startLine: c.startLine })),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (chunks.length > 0) {
|
|
126
|
+
yield* (0, effection_1.call)(() => reranker.tokenizeChunks(chunks));
|
|
127
|
+
let scored = [];
|
|
128
|
+
yield* (0, effection_1.call)(async () => {
|
|
129
|
+
for await (const batch of reranker.score(args.query, chunks)) {
|
|
130
|
+
if (context?.onProgress)
|
|
131
|
+
context.onProgress({ filled: batch.filled, total: batch.total });
|
|
132
|
+
scored = batch.results;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
// Select top-K within token budget (tokens populated by tokenizeChunks)
|
|
136
|
+
const TOKEN_BUDGET = 2048;
|
|
137
|
+
const topChunks = [];
|
|
138
|
+
let tokenTotal = 0;
|
|
139
|
+
for (const sc of scored.slice(0, topK)) {
|
|
140
|
+
const chunk = chunks.find(c => c.resource === sc.file && c.startLine === sc.startLine);
|
|
141
|
+
if (!chunk?.text)
|
|
142
|
+
continue;
|
|
143
|
+
const chunkTokens = chunk.tokens.length || Math.ceil(chunk.text.length / 4);
|
|
144
|
+
if (topChunks.length > 0 && tokenTotal + chunkTokens > TOKEN_BUDGET)
|
|
145
|
+
break;
|
|
146
|
+
topChunks.push({ text: chunk.text, heading: sc.heading, score: sc.score });
|
|
147
|
+
tokenTotal += chunkTokens;
|
|
148
|
+
}
|
|
149
|
+
if (tw) {
|
|
150
|
+
tw.write({
|
|
151
|
+
traceId: tw.nextId(),
|
|
152
|
+
parentTraceId: null,
|
|
153
|
+
ts: performance.now(),
|
|
154
|
+
type: 'rerank:end',
|
|
155
|
+
topResults: topChunks.map(c => ({
|
|
156
|
+
file: url,
|
|
157
|
+
heading: c.heading,
|
|
158
|
+
score: c.score,
|
|
159
|
+
textPreview: c.text.slice(0, 200),
|
|
160
|
+
})),
|
|
161
|
+
selectedPassageCount: topChunks.length,
|
|
162
|
+
totalChars: topChunks.reduce((sum, c) => sum + c.text.length, 0),
|
|
163
|
+
durationMs: performance.now() - rerankT0,
|
|
164
|
+
tool: 'fetch_page',
|
|
165
|
+
url,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (topChunks.length > 0) {
|
|
169
|
+
return {
|
|
170
|
+
url,
|
|
171
|
+
title: fetched.title,
|
|
172
|
+
content: topChunks.map(c => c.text).join('\n\n---\n\n'),
|
|
173
|
+
chunks: topChunks.length,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Fallback: return full content, truncated
|
|
179
|
+
let content = fetched.content;
|
|
180
|
+
if (content.length > maxChars) {
|
|
181
|
+
content = content.slice(0, maxChars) + '\n\n[truncated]';
|
|
182
|
+
}
|
|
183
|
+
return { url, title: fetched.title, content, excerpt: fetched.excerpt };
|
|
69
184
|
}
|
|
70
185
|
}
|
|
71
186
|
exports.FetchPageTool = FetchPageTool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-page.js","sourceRoot":"","sources":["../../src/tools/fetch-page.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEj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AAE,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1E,CAAC;CACF;AA3KD,sCA2KC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ReportTool } from './report';
|
|
|
5
5
|
export { ResearchTool } from './research';
|
|
6
6
|
export type { ResearchToolOpts } from './research';
|
|
7
7
|
export { WebSearchTool, TavilyProvider } from './web-search';
|
|
8
|
+
export { FetchPageTool } from './fetch-page';
|
|
8
9
|
export type { SearchProvider, SearchResult, Reranker, ScoredChunk, ScoredResult } from './types';
|
|
9
10
|
export { WebResearchTool } from './web-research';
|
|
10
11
|
export type { WebResearchToolOpts } from './web-research';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEr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,EAAE,CAAC;IACtB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;CACpB,GAAG,OAAO,CAOV"}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reportTool = exports.PlanTool = exports.WebResearchTool = exports.TavilyProvider = exports.WebSearchTool = exports.ResearchTool = void 0;
|
|
3
|
+
exports.reportTool = exports.PlanTool = exports.WebResearchTool = exports.FetchPageTool = exports.TavilyProvider = exports.WebSearchTool = exports.ResearchTool = void 0;
|
|
4
4
|
exports.createTools = createTools;
|
|
5
5
|
const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
6
6
|
const search_1 = require("./search");
|
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "ResearchTool", { enumerable: true, get: function
|
|
|
12
12
|
var web_search_1 = require("./web-search");
|
|
13
13
|
Object.defineProperty(exports, "WebSearchTool", { enumerable: true, get: function () { return web_search_1.WebSearchTool; } });
|
|
14
14
|
Object.defineProperty(exports, "TavilyProvider", { enumerable: true, get: function () { return web_search_1.TavilyProvider; } });
|
|
15
|
+
var fetch_page_1 = require("./fetch-page");
|
|
16
|
+
Object.defineProperty(exports, "FetchPageTool", { enumerable: true, get: function () { return fetch_page_1.FetchPageTool; } });
|
|
15
17
|
var web_research_1 = require("./web-research");
|
|
16
18
|
Object.defineProperty(exports, "WebResearchTool", { enumerable: true, get: function () { return web_research_1.WebResearchTool; } });
|
|
17
19
|
var plan_1 = require("./plan");
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;AAwCA,kCAWC;AAnDD,8DAA2D;AAI3D,qCAAsC;AACtC,2CAA2C;AAC3C,iCAAkC;AAClC,qCAAsC;AAEtC,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AAErB,2CAA6D;AAApD,2GAAA,aAAa,OAAA;AAAE,4GAAA,cAAc,OAAA;AACtC,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAEtB,+CAAiD;AAAxC,+GAAA,eAAe,OAAA;AAExB,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AAGjB;;;;;;GAMG;AACU,QAAA,UAAU,GAAG,IAAI,mBAAU,EAAE,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,SAAgB,WAAW,CAAC,IAI3B;IACC,OAAO,IAAA,6BAAa,EAAC;QACnB,IAAI,mBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC;QAC1C,IAAI,wBAAY,CAAC,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,eAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;QAC5B,kBAAU;KACX,CAAC,CAAC;AACL,CAAC"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -66,6 +66,10 @@ export interface SearchResult {
|
|
|
66
66
|
url: string;
|
|
67
67
|
/** Excerpt or snippet from the page content */
|
|
68
68
|
snippet: string;
|
|
69
|
+
/** Full page content — markdown when provider supports it, plain text otherwise */
|
|
70
|
+
rawContent?: string;
|
|
71
|
+
/** Provider-side relevance score (higher = more relevant) */
|
|
72
|
+
score?: number;
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
75
|
* Adapter interface for web search backends
|
|
@@ -80,5 +84,7 @@ export interface SearchResult {
|
|
|
80
84
|
export interface SearchProvider {
|
|
81
85
|
/** Execute a web search and return ranked results */
|
|
82
86
|
search(query: string, maxResults: number): Promise<SearchResult[]>;
|
|
87
|
+
/** When true, rawContent on results is markdown with heading structure suitable for parseMarkdown chunking */
|
|
88
|
+
readonly returnsFullContentMarkdown: boolean;
|
|
83
89
|
}
|
|
84
90
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACvB,kEAAkE;IAClE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IACnE,uDAAuD;IACvD,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,iCAAiC;IACjC,OAAO,IAAI,IAAI,CAAC;CACjB;AAID;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KA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C;IACnE,8GAA8G;IAC9G,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC;CAC9C"}
|
|
@@ -13,8 +13,12 @@ export type { SearchProvider, SearchResult };
|
|
|
13
13
|
* @category Rig
|
|
14
14
|
*/
|
|
15
15
|
export declare class TavilyProvider implements SearchProvider {
|
|
16
|
+
readonly returnsFullContentMarkdown = false;
|
|
16
17
|
private _apiKey;
|
|
17
|
-
|
|
18
|
+
private _snippetMaxLength;
|
|
19
|
+
constructor(apiKey?: string, opts?: {
|
|
20
|
+
snippetMaxLength?: number;
|
|
21
|
+
});
|
|
18
22
|
search(query: string, maxResults: number): Promise<SearchResult[]>;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AAI7C;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,cAAc;IACnD,OAAO,CAAC,OAAO,CAAS;
|
|
1
|
+
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AAI7C;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,cAAc;IACnD,QAAQ,CAAC,0BAA0B,SAAS;IAC5C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE;IAK3D,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CAqBzE;AAID;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,IAAI,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;IACxD,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,WAAW,gIAAgI;IACpJ,QAAQ,CAAC,UAAU,EAAE,UAAU,CAI7B;IAEF,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,KAAK,CAAS;gBAEV,QAAQ,EAAE,cAAc,EAAE,IAAI,SAAI;IAM7C,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,OAAO,CAAC;CAYtD"}
|
package/dist/tools/web-search.js
CHANGED
|
@@ -14,9 +14,12 @@ const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
|
14
14
|
* @category Rig
|
|
15
15
|
*/
|
|
16
16
|
class TavilyProvider {
|
|
17
|
+
returnsFullContentMarkdown = false;
|
|
17
18
|
_apiKey;
|
|
18
|
-
|
|
19
|
+
_snippetMaxLength;
|
|
20
|
+
constructor(apiKey, opts) {
|
|
19
21
|
this._apiKey = apiKey || process.env.TAVILY_API_KEY || '';
|
|
22
|
+
this._snippetMaxLength = opts?.snippetMaxLength ?? 500;
|
|
20
23
|
}
|
|
21
24
|
async search(query, maxResults) {
|
|
22
25
|
if (!this._apiKey)
|
|
@@ -32,10 +35,13 @@ class TavilyProvider {
|
|
|
32
35
|
if (!res.ok)
|
|
33
36
|
throw new Error(`Tavily ${res.status}: ${await res.text()}`);
|
|
34
37
|
const data = await res.json();
|
|
38
|
+
const max = this._snippetMaxLength;
|
|
35
39
|
return data.results.map(r => ({
|
|
36
40
|
title: r.title,
|
|
37
41
|
url: r.url,
|
|
38
|
-
snippet: r.content
|
|
42
|
+
snippet: r.content.length > max
|
|
43
|
+
? r.content.slice(0, max) + ' [\u2026]'
|
|
44
|
+
: r.content,
|
|
39
45
|
}));
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC,8DAAkD;AAMlD,2DAA2D;AAE3D;;;;;;;;GAQG;AACH,MAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC,8DAAkD;AAMlD,2DAA2D;AAE3D;;;;;;;;GAQG;AACH,MAAa,cAAc;IAChB,0BAA0B,GAAG,KAAK,CAAC;IACpC,OAAO,CAAS;IAChB,iBAAiB,CAAS;IAElC,YAAY,MAAe,EAAE,IAAoC;QAC/D,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;QAC1D,IAAI,CAAC,iBAAiB,GAAG,IAAI,EAAE,gBAAgB,IAAI,GAAG,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,UAAkB;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC7D,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,+BAA+B,EAAE;YACvD,MAAM,EAA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