@absolutejs/rag 0.17.0 → 0.18.1

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 (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -0
  3. package/RESEARCH.md +268 -0
  4. package/changelog.json +262 -235
  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 +125286 -0
  16. package/dist/research/index.js.map +369 -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/schema.d.ts +8 -0
  31. package/dist/src/research/store.d.ts +29 -0
  32. package/dist/src/research/types.d.ts +96 -0
  33. package/dist/src/research/workflows.d.ts +96 -0
  34. package/dist/src/svelte/createResearch.d.ts +9 -0
  35. package/dist/src/svelte/index.d.ts +1 -0
  36. package/dist/src/vue/index.d.ts +1 -0
  37. package/dist/src/vue/useResearch.d.ts +9 -0
  38. package/dist/svelte/index.js +164 -2
  39. package/dist/svelte/index.js.map +6 -4
  40. package/dist/vue/index.js +164 -2
  41. package/dist/vue/index.js.map +6 -4
  42. package/package.json +24 -6
@@ -0,0 +1,9 @@
1
+ export declare const createResearchStore: (path?: string) => {
2
+ state: import("svelte/store").Readable<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
+ };
@@ -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";
@@ -15,3 +15,4 @@ export { useRAGStreamProgress } from "./useRAGStreamProgress";
15
15
  export type { UseRAGStreamResult } from "./useRAGStream";
16
16
  export { useRAGSources } from "./useRAGSources";
17
17
  export { useRAGStatus } from "./useRAGStatus";
18
+ export * from "./useResearch";
@@ -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
+ };
@@ -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=404BF31250240B0064756E2164756E21
5166
+ //# debugId=C9A33C19D3BE985B64756E2164756E21
5005
5167
  //# sourceMappingURL=index.js.map