@lloyal-labs/rig 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/reranker.d.ts +22 -0
- package/dist/reranker.d.ts.map +1 -0
- package/dist/reranker.js +76 -0
- package/dist/reranker.js.map +1 -0
- package/dist/resources/files.d.ts +28 -0
- package/dist/resources/files.d.ts.map +1 -0
- package/dist/resources/files.js +98 -0
- package/dist/resources/files.js.map +1 -0
- package/dist/resources/index.d.ts +9 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +13 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/types.d.ts +39 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +3 -0
- package/dist/resources/types.js.map +1 -0
- package/dist/sources/corpus-research.md +14 -0
- package/dist/sources/corpus.d.ts +48 -0
- package/dist/sources/corpus.d.ts.map +1 -0
- package/dist/sources/corpus.js +91 -0
- package/dist/sources/corpus.js.map +1 -0
- package/dist/sources/extract.md +5 -0
- package/dist/sources/index.d.ts +10 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +14 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/search-extract.md +6 -0
- package/dist/sources/types.d.ts +28 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +3 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/sources/web-research.md +12 -0
- package/dist/sources/web.d.ts +78 -0
- package/dist/sources/web.d.ts.map +1 -0
- package/dist/sources/web.js +319 -0
- package/dist/sources/web.js.map +1 -0
- package/dist/tools/fetch-page.d.ts +26 -0
- package/dist/tools/fetch-page.d.ts.map +1 -0
- package/dist/tools/fetch-page.js +72 -0
- package/dist/tools/fetch-page.js.map +1 -0
- package/dist/tools/grep.d.ts +30 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +79 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +39 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +49 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/plan.d.ts +76 -0
- package/dist/tools/plan.d.ts.map +1 -0
- package/dist/tools/plan.js +98 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/read-file.d.ts +62 -0
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +123 -0
- package/dist/tools/read-file.js.map +1 -0
- package/dist/tools/report.d.ts +22 -0
- package/dist/tools/report.d.ts.map +1 -0
- package/dist/tools/report.js +26 -0
- package/dist/tools/report.js.map +1 -0
- package/dist/tools/research.d.ts +57 -0
- package/dist/tools/research.d.ts.map +1 -0
- package/dist/tools/research.js +117 -0
- package/dist/tools/research.js.map +1 -0
- package/dist/tools/search.d.ts +34 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +69 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/types.d.ts +84 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +3 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-research.d.ts +60 -0
- package/dist/tools/web-research.d.ts.map +1 -0
- package/dist/tools/web-research.js +136 -0
- package/dist/tools/web-research.js.map +1 -0
- package/dist/tools/web-search.d.ts +42 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +83 -0
- package/dist/tools/web-search.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebResearchTool = void 0;
|
|
4
|
+
const effection_1 = require("effection");
|
|
5
|
+
const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
6
|
+
/**
|
|
7
|
+
* Spawn parallel web-research sub-agents for a set of questions.
|
|
8
|
+
*
|
|
9
|
+
* Similar to {@link ResearchTool} but designed for web-source pipelines.
|
|
10
|
+
* Each question gets its own agent in a shared-root pool with access
|
|
11
|
+
* to web_search, fetch_page, and report tools. Hard-cut agents that
|
|
12
|
+
* exhaust their turns without reporting get a grammar-constrained
|
|
13
|
+
* scratchpad extraction via {@link generate} to recover partial findings.
|
|
14
|
+
*
|
|
15
|
+
* Must call {@link setToolkit} before the tool is executed.
|
|
16
|
+
*
|
|
17
|
+
* @category Rig
|
|
18
|
+
*/
|
|
19
|
+
class WebResearchTool extends lloyal_agents_1.Tool {
|
|
20
|
+
name;
|
|
21
|
+
description;
|
|
22
|
+
parameters = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
questions: {
|
|
26
|
+
type: "array",
|
|
27
|
+
items: { type: "string" },
|
|
28
|
+
description: "Sub-questions to research in parallel",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
required: ["questions"],
|
|
32
|
+
};
|
|
33
|
+
_systemPrompt;
|
|
34
|
+
_reporterPrompt;
|
|
35
|
+
_maxTurns;
|
|
36
|
+
_trace;
|
|
37
|
+
_pressure;
|
|
38
|
+
_toolkit = null;
|
|
39
|
+
constructor(opts) {
|
|
40
|
+
super();
|
|
41
|
+
this.name = opts.name ?? "research";
|
|
42
|
+
this.description =
|
|
43
|
+
opts.description ??
|
|
44
|
+
"Spawn parallel research agents to investigate sub-questions. Each question gets its own agent.";
|
|
45
|
+
this._systemPrompt = opts.systemPrompt;
|
|
46
|
+
this._reporterPrompt = opts.reporterPrompt;
|
|
47
|
+
this._maxTurns = opts.maxTurns ?? 20;
|
|
48
|
+
this._trace = opts.trace ?? false;
|
|
49
|
+
this._pressure = opts.pressure;
|
|
50
|
+
}
|
|
51
|
+
/** Inject the toolkit that sub-agents will use. Must be called before execute. */
|
|
52
|
+
setToolkit(toolkit) {
|
|
53
|
+
this._toolkit = toolkit;
|
|
54
|
+
}
|
|
55
|
+
*execute(args) {
|
|
56
|
+
const questions = args?.questions;
|
|
57
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
58
|
+
return {
|
|
59
|
+
error: "questions must be a non-empty array of strings",
|
|
60
|
+
example: '{"questions": ["q1", "q2"]}',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (!this._toolkit)
|
|
64
|
+
throw new Error("WebResearchTool: setToolkit() must be called before execute");
|
|
65
|
+
const tw = yield* lloyal_agents_1.Trace.expect();
|
|
66
|
+
const scope = (0, lloyal_agents_1.traceScope)(tw, null, 'webResearchTool', { questionCount: questions.length });
|
|
67
|
+
const toolkit = this._toolkit;
|
|
68
|
+
const systemPrompt = this._systemPrompt;
|
|
69
|
+
const reporterPrompt = this._reporterPrompt;
|
|
70
|
+
const maxTurns = this._maxTurns;
|
|
71
|
+
const trace = this._trace;
|
|
72
|
+
const pressure = this._pressure;
|
|
73
|
+
return yield* (0, lloyal_agents_1.withSharedRoot)({ systemPrompt, tools: toolkit.toolsJson }, function* (root) {
|
|
74
|
+
const pool = yield* (0, lloyal_agents_1.useAgentPool)({
|
|
75
|
+
tasks: questions.map((q) => ({
|
|
76
|
+
systemPrompt,
|
|
77
|
+
content: q,
|
|
78
|
+
tools: toolkit.toolsJson,
|
|
79
|
+
parent: root,
|
|
80
|
+
})),
|
|
81
|
+
tools: toolkit.toolMap,
|
|
82
|
+
terminalTool: "report",
|
|
83
|
+
maxTurns,
|
|
84
|
+
trace,
|
|
85
|
+
pressure,
|
|
86
|
+
});
|
|
87
|
+
// Scratchpad extraction for hard-cut agents — works under pressure
|
|
88
|
+
const hardCut = pool.agents.filter((a) => !a.findings && !a.branch.disposed);
|
|
89
|
+
if (hardCut.length > 0) {
|
|
90
|
+
for (const a of pool.agents) {
|
|
91
|
+
if (a.findings && !a.branch.disposed)
|
|
92
|
+
a.branch.pruneSync();
|
|
93
|
+
}
|
|
94
|
+
const ctx = yield* lloyal_agents_1.Ctx.expect();
|
|
95
|
+
const schema = {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: { findings: { type: "string" } },
|
|
98
|
+
required: ["findings"],
|
|
99
|
+
};
|
|
100
|
+
const grammar = yield* (0, effection_1.call)(() => ctx.jsonSchemaToGrammar(JSON.stringify(schema)));
|
|
101
|
+
const msgs = [
|
|
102
|
+
{ role: "system", content: reporterPrompt.system },
|
|
103
|
+
{ role: "user", content: reporterPrompt.user },
|
|
104
|
+
];
|
|
105
|
+
const { prompt } = ctx.formatChatSync(JSON.stringify(msgs), { enableThinking: false });
|
|
106
|
+
for (const a of hardCut) {
|
|
107
|
+
try {
|
|
108
|
+
const result = yield* (0, lloyal_agents_1.generate)({
|
|
109
|
+
prompt,
|
|
110
|
+
grammar,
|
|
111
|
+
parse: (o) => JSON.parse(o),
|
|
112
|
+
parent: a.branch,
|
|
113
|
+
});
|
|
114
|
+
if (result.parsed?.findings)
|
|
115
|
+
a.findings = result.parsed.findings;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* extraction failure non-fatal */
|
|
119
|
+
}
|
|
120
|
+
if (!a.branch.disposed)
|
|
121
|
+
a.branch.pruneSync();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const result = {
|
|
125
|
+
findings: pool.agents.map((a) => a.findings).filter(Boolean),
|
|
126
|
+
agentCount: pool.agents.length,
|
|
127
|
+
totalTokens: pool.totalTokens,
|
|
128
|
+
totalToolCalls: pool.totalToolCalls,
|
|
129
|
+
};
|
|
130
|
+
scope.close();
|
|
131
|
+
return result;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.WebResearchTool = WebResearchTool;
|
|
136
|
+
//# sourceMappingURL=web-research.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-research.js","sourceRoot":"","sources":["../../src/tools/web-research.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC,8DAQoC;AA6BpC;;;;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AC,CAAC,IAAA,wBAAQ,EAAuB;4BACnD,MAAM;4BACN,OAAO;4BACP,KAAK,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;4BACnC,MAAM,EAAE,CAAC,CAAC,MAAM;yBACjB,CAAC,CAAC;wBACH,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ;4BAAE,CAAC,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;oBACnE,CAAC;oBAAC,MAAM,CAAC;wBACP,kCAAkC;oBACpC,CAAC;oBACD,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ;wBAAE,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;gBAC/C,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAG;gBACb,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC5D,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,cAAc,EAAE,IAAI,CAAC,cAAc;aACpC,CAAC;YACF,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,OAAO,MAAM,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnID,0CAmIC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Operation } from 'effection';
|
|
2
|
+
import { Tool } from '@lloyal-labs/lloyal-agents';
|
|
3
|
+
import type { JsonSchema } from '@lloyal-labs/lloyal-agents';
|
|
4
|
+
import type { SearchProvider, SearchResult } from './types';
|
|
5
|
+
export type { SearchProvider, SearchResult };
|
|
6
|
+
/**
|
|
7
|
+
* {@link SearchProvider} implementation backed by the Tavily search API.
|
|
8
|
+
*
|
|
9
|
+
* Reads the API key from the constructor argument or the
|
|
10
|
+
* `TAVILY_API_KEY` environment variable. Throws at search time
|
|
11
|
+
* if no key is available.
|
|
12
|
+
*
|
|
13
|
+
* @category Rig
|
|
14
|
+
*/
|
|
15
|
+
export declare class TavilyProvider implements SearchProvider {
|
|
16
|
+
private _apiKey;
|
|
17
|
+
constructor(apiKey?: string);
|
|
18
|
+
search(query: string, maxResults: number): Promise<SearchResult[]>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Web search tool backed by a pluggable {@link SearchProvider}.
|
|
22
|
+
*
|
|
23
|
+
* Delegates to the provider's `search` method and returns an array
|
|
24
|
+
* of {@link SearchResult} objects. Use alongside {@link FetchPageTool}
|
|
25
|
+
* to let agents read full page content from promising results.
|
|
26
|
+
*
|
|
27
|
+
* @category Rig
|
|
28
|
+
*/
|
|
29
|
+
export declare class WebSearchTool extends Tool<{
|
|
30
|
+
query: string;
|
|
31
|
+
}> {
|
|
32
|
+
readonly name = "web_search";
|
|
33
|
+
readonly description = "Search the web. Returns results with titles, snippets, and URLs. Use fetch_page to read full content of promising results.";
|
|
34
|
+
readonly parameters: JsonSchema;
|
|
35
|
+
private _provider;
|
|
36
|
+
private _topN;
|
|
37
|
+
constructor(provider: SearchProvider, topN?: number);
|
|
38
|
+
execute(args: {
|
|
39
|
+
query: string;
|
|
40
|
+
}): Operation<unknown>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=web-search.d.ts.map
|
|
@@ -0,0 +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;gBAEZ,MAAM,CAAC,EAAE,MAAM;IAIrB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CAkBzE;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"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSearchTool = exports.TavilyProvider = void 0;
|
|
4
|
+
const effection_1 = require("effection");
|
|
5
|
+
const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
|
|
6
|
+
// ── Tavily provider (default) ───────────────────────────
|
|
7
|
+
/**
|
|
8
|
+
* {@link SearchProvider} implementation backed by the Tavily search API.
|
|
9
|
+
*
|
|
10
|
+
* Reads the API key from the constructor argument or the
|
|
11
|
+
* `TAVILY_API_KEY` environment variable. Throws at search time
|
|
12
|
+
* if no key is available.
|
|
13
|
+
*
|
|
14
|
+
* @category Rig
|
|
15
|
+
*/
|
|
16
|
+
class TavilyProvider {
|
|
17
|
+
_apiKey;
|
|
18
|
+
constructor(apiKey) {
|
|
19
|
+
this._apiKey = apiKey || process.env.TAVILY_API_KEY || '';
|
|
20
|
+
}
|
|
21
|
+
async search(query, maxResults) {
|
|
22
|
+
if (!this._apiKey)
|
|
23
|
+
throw new Error('TAVILY_API_KEY not set');
|
|
24
|
+
const res = await fetch('https://api.tavily.com/search', {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
'Authorization': `Bearer ${this._apiKey}`,
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ query, max_results: maxResults }),
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok)
|
|
33
|
+
throw new Error(`Tavily ${res.status}: ${await res.text()}`);
|
|
34
|
+
const data = await res.json();
|
|
35
|
+
return data.results.map(r => ({
|
|
36
|
+
title: r.title,
|
|
37
|
+
url: r.url,
|
|
38
|
+
snippet: r.content,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TavilyProvider = TavilyProvider;
|
|
43
|
+
// ── WebSearchTool ───────────────────────────────────────
|
|
44
|
+
/**
|
|
45
|
+
* Web search tool backed by a pluggable {@link SearchProvider}.
|
|
46
|
+
*
|
|
47
|
+
* Delegates to the provider's `search` method and returns an array
|
|
48
|
+
* of {@link SearchResult} objects. Use alongside {@link FetchPageTool}
|
|
49
|
+
* to let agents read full page content from promising results.
|
|
50
|
+
*
|
|
51
|
+
* @category Rig
|
|
52
|
+
*/
|
|
53
|
+
class WebSearchTool extends lloyal_agents_1.Tool {
|
|
54
|
+
name = 'web_search';
|
|
55
|
+
description = 'Search the web. Returns results with titles, snippets, and URLs. Use fetch_page to read full content of promising results.';
|
|
56
|
+
parameters = {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: { query: { type: 'string', description: 'Search query' } },
|
|
59
|
+
required: ['query'],
|
|
60
|
+
};
|
|
61
|
+
_provider;
|
|
62
|
+
_topN;
|
|
63
|
+
constructor(provider, topN = 8) {
|
|
64
|
+
super();
|
|
65
|
+
this._provider = provider;
|
|
66
|
+
this._topN = topN;
|
|
67
|
+
}
|
|
68
|
+
*execute(args) {
|
|
69
|
+
const query = args.query?.trim();
|
|
70
|
+
if (!query)
|
|
71
|
+
return { error: 'query must not be empty' };
|
|
72
|
+
const provider = this._provider;
|
|
73
|
+
const topN = this._topN;
|
|
74
|
+
try {
|
|
75
|
+
return yield* (0, effection_1.call)(() => provider.search(query, topN));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return { error: `Search failed: ${err.message}` };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.WebSearchTool = WebSearchTool;
|
|
83
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +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;IACjB,OAAO,CAAS;IAExB,YAAY,MAAe;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;IAC5D,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,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,eAAe,EAAE,UAAU,IAAI,CAAC,OAAO,EAAE;aAC1C;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;SACzD,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC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;YACH,OAAO,KAAK,CAAC,CAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,KAAK,EAAE,kBAAmB,GAAa,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/D,CAAC;IACH,CAAC;CACF;AA9BD,sCA8BC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lloyal-labs/rig",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Retrieval-Interleaved Generation for lloyal-agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/lloyal-ai/sdk.git",
|
|
13
|
+
"directory": "packages/rig"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/lloyal-ai/sdk/tree/main/packages/rig#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/lloyal-ai/sdk/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"llm",
|
|
21
|
+
"rig",
|
|
22
|
+
"retrieval-interleaved-generation",
|
|
23
|
+
"reranker",
|
|
24
|
+
"agents",
|
|
25
|
+
"tools"
|
|
26
|
+
],
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"type": "commonjs",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -b && mkdir -p dist/sources && cp src/sources/*.md dist/sources/"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@lloyal-labs/sdk": "*",
|
|
34
|
+
"@lloyal-labs/lloyal-agents": "*",
|
|
35
|
+
"effection": "^4.0.2",
|
|
36
|
+
"linkedom": "^0.18.12",
|
|
37
|
+
"@mozilla/readability": "^0.6.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@lloyal-labs/lloyal.node": "^2.0.2"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/"
|
|
44
|
+
]
|
|
45
|
+
}
|