@absolutejs/rag 0.16.0 → 0.18.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/CHANGELOG.md +16 -0
- package/README.md +6 -0
- package/RESEARCH.md +269 -0
- package/changelog.json +27 -0
- package/dist/angular/index.js +174 -2
- package/dist/angular/index.js.map +6 -4
- package/dist/client/index.js +149 -1
- package/dist/client/index.js.map +5 -4
- package/dist/client/research.js +223 -0
- package/dist/client/research.js.map +10 -0
- package/dist/manifest.js +3722 -269
- package/dist/manifest.js.map +29 -3
- package/dist/react/index.js +158 -2
- package/dist/react/index.js.map +6 -4
- package/dist/research/index.js +125277 -0
- package/dist/research/index.js.map +368 -0
- package/dist/src/angular/index.d.ts +1 -0
- package/dist/src/angular/research.service.d.ts +12 -0
- package/dist/src/client/index.d.ts +1 -0
- package/dist/src/client/research.d.ts +30 -0
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/useResearch.d.ts +9 -0
- package/dist/src/research/budget.d.ts +26 -0
- package/dist/src/research/evaluation.d.ts +42 -0
- package/dist/src/research/evidence.d.ts +21 -0
- package/dist/src/research/index.d.ts +9 -0
- package/dist/src/research/manifest.d.ts +18 -0
- package/dist/src/research/plugin.d.ts +230 -0
- package/dist/src/research/runtime.d.ts +2 -0
- package/dist/src/research/store.d.ts +29 -0
- package/dist/src/research/types.d.ts +95 -0
- package/dist/src/research/workflows.d.ts +96 -0
- package/dist/src/svelte/createResearch.d.ts +9 -0
- package/dist/src/svelte/index.d.ts +1 -0
- package/dist/src/vue/index.d.ts +1 -0
- package/dist/src/vue/useResearch.d.ts +9 -0
- package/dist/src/web/index.d.ts +1 -0
- package/dist/src/web/remote.d.ts +30 -0
- package/dist/svelte/index.js +164 -2
- package/dist/svelte/index.js.map +6 -4
- package/dist/vue/index.js +164 -2
- package/dist/vue/index.js.map +6 -4
- package/dist/web/index.js +116 -79
- package/dist/web/index.js.map +6 -5
- package/dist/web/playwright.js +38 -79
- package/dist/web/playwright.js.map +3 -3
- package/package.json +199 -182
|
@@ -15,3 +15,4 @@ export { createRAGStream } from "./createRAGStream";
|
|
|
15
15
|
export { createRAGStreamProgress } from "./createRAGStreamProgress";
|
|
16
16
|
export type { CreateRAGWorkflowResult } from "./createRAGWorkflow";
|
|
17
17
|
export type { CreateRAGStreamResult } from "./createRAGStream";
|
|
18
|
+
export * from "./createResearch";
|
package/dist/src/vue/index.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const useResearch: (path?: string) => {
|
|
2
|
+
state: import("vue").ShallowRef<import("../client").ResearchState, import("../client").ResearchState>;
|
|
3
|
+
run: (input: import("../client").ResearchRequest) => Promise<import("../research").ResearchResult>;
|
|
4
|
+
cancel: () => void;
|
|
5
|
+
getSnapshot: () => import("../client").ResearchState;
|
|
6
|
+
subscribe: (listener: () => void) => () => void;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
dispose: () => void;
|
|
9
|
+
};
|
package/dist/src/web/index.d.ts
CHANGED
|
@@ -50,3 +50,4 @@ export type ReadWebpageOptions = {
|
|
|
50
50
|
/** Read prepared evidence, escalating thin HTML shells to a host-supplied browser. */
|
|
51
51
|
export declare const readRAGWebpage: (options: ReadWebpageOptions) => Promise<WebReadResult>;
|
|
52
52
|
export { readRAGWebsite } from "./website";
|
|
53
|
+
export { createWebsiteReaderClient, parseWebsiteServiceResult, type WebsiteServiceResult, } from "./remote";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Typed boundary for a host-managed isolated website reader. The service URL is
|
|
2
|
+
* trusted host configuration; public destination validation stays in the reader. */
|
|
3
|
+
export type WebsiteServiceResult = Record<string, unknown> & {
|
|
4
|
+
status: "ok" | "partial" | "error";
|
|
5
|
+
text: string;
|
|
6
|
+
limitations?: string[];
|
|
7
|
+
sources?: {
|
|
8
|
+
url: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
citation?: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export declare const parseWebsiteServiceResult: (value: unknown) => WebsiteServiceResult;
|
|
14
|
+
export declare const createWebsiteReaderClient: (options: {
|
|
15
|
+
endpoint: string;
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
fallbackReserveMs?: number;
|
|
19
|
+
fallback: (input: {
|
|
20
|
+
url: string;
|
|
21
|
+
maxPages: number;
|
|
22
|
+
mode: "auto" | "browser";
|
|
23
|
+
signal: AbortSignal;
|
|
24
|
+
}) => Promise<WebsiteServiceResult>;
|
|
25
|
+
}) => (input: {
|
|
26
|
+
url: string;
|
|
27
|
+
maxPages?: number;
|
|
28
|
+
mode?: "auto" | "browser";
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}) => Promise<WebsiteServiceResult>;
|
package/dist/svelte/index.js
CHANGED
|
@@ -68,6 +68,153 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
68
68
|
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
// src/client/research.ts
|
|
72
|
+
var createResearchClient = (options = {}) => {
|
|
73
|
+
let state = {
|
|
74
|
+
status: "idle",
|
|
75
|
+
result: null,
|
|
76
|
+
progress: null,
|
|
77
|
+
error: null
|
|
78
|
+
};
|
|
79
|
+
let active;
|
|
80
|
+
let generation = 0;
|
|
81
|
+
const listeners = new Set;
|
|
82
|
+
const publish = (next) => {
|
|
83
|
+
state = next;
|
|
84
|
+
listeners.forEach((listener) => listener());
|
|
85
|
+
};
|
|
86
|
+
const cancel = () => {
|
|
87
|
+
generation++;
|
|
88
|
+
active?.abort();
|
|
89
|
+
active = undefined;
|
|
90
|
+
if (state.status === "running")
|
|
91
|
+
publish({ ...state, status: "cancelled" });
|
|
92
|
+
};
|
|
93
|
+
const run = async (input) => {
|
|
94
|
+
active?.abort();
|
|
95
|
+
const id = ++generation;
|
|
96
|
+
const controller = new AbortController;
|
|
97
|
+
active = controller;
|
|
98
|
+
publish({ status: "running", result: null, progress: null, error: null });
|
|
99
|
+
let reader;
|
|
100
|
+
try {
|
|
101
|
+
const headers = new Headers(options.headers?.());
|
|
102
|
+
headers.set("content-type", "application/json");
|
|
103
|
+
const response = await (options.fetch ?? fetch)(`${options.path ?? "/research"}/stream`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
body: JSON.stringify(input),
|
|
106
|
+
headers,
|
|
107
|
+
credentials: "same-origin",
|
|
108
|
+
signal: controller.signal
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok || !response.body)
|
|
111
|
+
throw new Error(`Research request failed (${response.status})`);
|
|
112
|
+
reader = response.body.getReader();
|
|
113
|
+
const decoder = new TextDecoder;
|
|
114
|
+
let pending = "";
|
|
115
|
+
let result;
|
|
116
|
+
const processLine = (line) => {
|
|
117
|
+
if (!line.trim())
|
|
118
|
+
return;
|
|
119
|
+
const event = JSON.parse(line);
|
|
120
|
+
if (event.type === "error")
|
|
121
|
+
throw new Error("Research request failed");
|
|
122
|
+
if (event.type === "result") {
|
|
123
|
+
if (!event.result || !["reviewed", "partial", "empty", "unavailable"].includes(event.result.status) || !Array.isArray(event.result.fields) || !Array.isArray(event.result.sources))
|
|
124
|
+
throw new Error("Invalid research result");
|
|
125
|
+
result = event.result;
|
|
126
|
+
}
|
|
127
|
+
if (event.type === "progress" && id === generation)
|
|
128
|
+
publish({ ...state, progress: event.progress });
|
|
129
|
+
};
|
|
130
|
+
while (true) {
|
|
131
|
+
controller.signal.throwIfAborted();
|
|
132
|
+
const chunk = await reader.read();
|
|
133
|
+
pending += decoder.decode(chunk.value, { stream: !chunk.done });
|
|
134
|
+
if (pending.length > 4000000)
|
|
135
|
+
throw new Error("Research response too large");
|
|
136
|
+
let newline;
|
|
137
|
+
while ((newline = pending.indexOf(`
|
|
138
|
+
`)) >= 0) {
|
|
139
|
+
processLine(pending.slice(0, newline));
|
|
140
|
+
pending = pending.slice(newline + 1);
|
|
141
|
+
}
|
|
142
|
+
if (chunk.done)
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (pending)
|
|
146
|
+
processLine(pending);
|
|
147
|
+
controller.signal.throwIfAborted();
|
|
148
|
+
if (!result)
|
|
149
|
+
throw new Error("Research stream ended without a result");
|
|
150
|
+
if (id === generation)
|
|
151
|
+
publish({ ...state, status: "complete", result });
|
|
152
|
+
return result;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (id === generation)
|
|
155
|
+
publish({
|
|
156
|
+
...state,
|
|
157
|
+
status: controller.signal.aborted ? "cancelled" : "error",
|
|
158
|
+
error: controller.signal.aborted ? null : error instanceof Error ? error.message : "Research request failed"
|
|
159
|
+
});
|
|
160
|
+
throw error;
|
|
161
|
+
} finally {
|
|
162
|
+
await reader?.cancel().catch(() => {
|
|
163
|
+
return;
|
|
164
|
+
});
|
|
165
|
+
reader?.releaseLock();
|
|
166
|
+
if (id === generation)
|
|
167
|
+
active = undefined;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
run,
|
|
172
|
+
cancel,
|
|
173
|
+
getSnapshot: () => state,
|
|
174
|
+
subscribe: (listener) => {
|
|
175
|
+
listeners.add(listener);
|
|
176
|
+
return () => {
|
|
177
|
+
listeners.delete(listener);
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
reset: () => {
|
|
181
|
+
cancel();
|
|
182
|
+
publish({ status: "idle", result: null, progress: null, error: null });
|
|
183
|
+
},
|
|
184
|
+
dispose: () => {
|
|
185
|
+
cancel();
|
|
186
|
+
listeners.clear();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
var bindResearchForm = (form, output, options = {}) => {
|
|
191
|
+
const client = createResearchClient(options);
|
|
192
|
+
const unsubscribe = client.subscribe(() => {
|
|
193
|
+
const state = client.getSnapshot();
|
|
194
|
+
output.setAttribute("aria-busy", String(state.status === "running"));
|
|
195
|
+
output.textContent = state.result ? JSON.stringify(state.result, null, 2) : state.error ?? state.status;
|
|
196
|
+
});
|
|
197
|
+
const submit = (event) => {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
const data = new FormData(form);
|
|
200
|
+
client.run({
|
|
201
|
+
query: String(data.get("query") ?? ""),
|
|
202
|
+
...data.get("task") ? { task: String(data.get("task")) } : {}
|
|
203
|
+
}).catch(() => {
|
|
204
|
+
return;
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
form.addEventListener("submit", submit);
|
|
208
|
+
return {
|
|
209
|
+
...client,
|
|
210
|
+
dispose: () => {
|
|
211
|
+
form.removeEventListener("submit", submit);
|
|
212
|
+
unsubscribe();
|
|
213
|
+
client.dispose();
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
|
|
71
218
|
// src/svelte/createRAGChunkPreview.ts
|
|
72
219
|
import { derived, writable } from "svelte/store";
|
|
73
220
|
|
|
@@ -4983,6 +5130,20 @@ var createRAG = (path, options = {}) => {
|
|
|
4983
5130
|
workflow
|
|
4984
5131
|
};
|
|
4985
5132
|
};
|
|
5133
|
+
// src/svelte/createResearch.ts
|
|
5134
|
+
import { readable as readable2 } from "svelte/store";
|
|
5135
|
+
var createResearchStore = (path = "/research") => {
|
|
5136
|
+
const client = createResearchClient({ path });
|
|
5137
|
+
const state = readable2(client.getSnapshot(), (set) => {
|
|
5138
|
+
set(client.getSnapshot());
|
|
5139
|
+
const unsubscribe = client.subscribe(() => set(client.getSnapshot()));
|
|
5140
|
+
return () => {
|
|
5141
|
+
unsubscribe();
|
|
5142
|
+
client.cancel();
|
|
5143
|
+
};
|
|
5144
|
+
});
|
|
5145
|
+
return { ...client, state };
|
|
5146
|
+
};
|
|
4986
5147
|
export {
|
|
4987
5148
|
createRAG,
|
|
4988
5149
|
createRAGChunkPreview,
|
|
@@ -4998,8 +5159,9 @@ export {
|
|
|
4998
5159
|
createRAGStatus,
|
|
4999
5160
|
createRAGStream,
|
|
5000
5161
|
createRAGStreamProgress,
|
|
5001
|
-
createRAGWorkflow
|
|
5162
|
+
createRAGWorkflow,
|
|
5163
|
+
createResearchStore
|
|
5002
5164
|
};
|
|
5003
5165
|
|
|
5004
|
-
//# debugId=
|
|
5166
|
+
//# debugId=C9A33C19D3BE985B64756E2164756E21
|
|
5005
5167
|
//# sourceMappingURL=index.js.map
|