@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +6 -0
  3. package/RESEARCH.md +269 -0
  4. package/changelog.json +27 -0
  5. package/dist/angular/index.js +174 -2
  6. package/dist/angular/index.js.map +6 -4
  7. package/dist/client/index.js +149 -1
  8. package/dist/client/index.js.map +5 -4
  9. package/dist/client/research.js +223 -0
  10. package/dist/client/research.js.map +10 -0
  11. package/dist/manifest.js +3722 -269
  12. package/dist/manifest.js.map +29 -3
  13. package/dist/react/index.js +158 -2
  14. package/dist/react/index.js.map +6 -4
  15. package/dist/research/index.js +125277 -0
  16. package/dist/research/index.js.map +368 -0
  17. package/dist/src/angular/index.d.ts +1 -0
  18. package/dist/src/angular/research.service.d.ts +12 -0
  19. package/dist/src/client/index.d.ts +1 -0
  20. package/dist/src/client/research.d.ts +30 -0
  21. package/dist/src/react/index.d.ts +1 -0
  22. package/dist/src/react/useResearch.d.ts +9 -0
  23. package/dist/src/research/budget.d.ts +26 -0
  24. package/dist/src/research/evaluation.d.ts +42 -0
  25. package/dist/src/research/evidence.d.ts +21 -0
  26. package/dist/src/research/index.d.ts +9 -0
  27. package/dist/src/research/manifest.d.ts +18 -0
  28. package/dist/src/research/plugin.d.ts +230 -0
  29. package/dist/src/research/runtime.d.ts +2 -0
  30. package/dist/src/research/store.d.ts +29 -0
  31. package/dist/src/research/types.d.ts +95 -0
  32. package/dist/src/research/workflows.d.ts +96 -0
  33. package/dist/src/svelte/createResearch.d.ts +9 -0
  34. package/dist/src/svelte/index.d.ts +1 -0
  35. package/dist/src/vue/index.d.ts +1 -0
  36. package/dist/src/vue/useResearch.d.ts +9 -0
  37. package/dist/src/web/index.d.ts +1 -0
  38. package/dist/src/web/remote.d.ts +30 -0
  39. package/dist/svelte/index.js +164 -2
  40. package/dist/svelte/index.js.map +6 -4
  41. package/dist/vue/index.js +164 -2
  42. package/dist/vue/index.js.map +6 -4
  43. package/dist/web/index.js +116 -79
  44. package/dist/web/index.js.map +6 -5
  45. package/dist/web/playwright.js +38 -79
  46. package/dist/web/playwright.js.map +3 -3
  47. 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=12932D0A8C5BB3FA64756E2164756E21
5141
+ //# debugId=311224046610761D64756E2164756E21
4980
5142
  //# sourceMappingURL=index.js.map