@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
package/dist/vue/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/vue/useRAGChunkPreview.ts
|
|
72
219
|
import { computed, ref } from "vue";
|
|
73
220
|
|
|
@@ -4958,6 +5105,20 @@ var useRAG = (path, options = {}) => {
|
|
|
4958
5105
|
workflow
|
|
4959
5106
|
};
|
|
4960
5107
|
};
|
|
5108
|
+
// src/vue/useResearch.ts
|
|
5109
|
+
import { shallowRef, onScopeDispose } from "vue";
|
|
5110
|
+
var useResearch = (path = "/research") => {
|
|
5111
|
+
const client = createResearchClient({ path });
|
|
5112
|
+
const state = shallowRef(client.getSnapshot());
|
|
5113
|
+
const unsubscribe = client.subscribe(() => {
|
|
5114
|
+
state.value = client.getSnapshot();
|
|
5115
|
+
});
|
|
5116
|
+
onScopeDispose(() => {
|
|
5117
|
+
unsubscribe();
|
|
5118
|
+
client.dispose();
|
|
5119
|
+
});
|
|
5120
|
+
return { ...client, state };
|
|
5121
|
+
};
|
|
4961
5122
|
export {
|
|
4962
5123
|
useRAG,
|
|
4963
5124
|
useRAGChunkPreview,
|
|
@@ -4973,8 +5134,9 @@ export {
|
|
|
4973
5134
|
useRAGStatus,
|
|
4974
5135
|
useRAGStream,
|
|
4975
5136
|
useRAGStreamProgress,
|
|
4976
|
-
useRAGWorkflow
|
|
5137
|
+
useRAGWorkflow,
|
|
5138
|
+
useResearch
|
|
4977
5139
|
};
|
|
4978
5140
|
|
|
4979
|
-
//# debugId=
|
|
5141
|
+
//# debugId=311224046610761D64756E2164756E21
|
|
4980
5142
|
//# sourceMappingURL=index.js.map
|