@absolutejs/rag 0.17.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 +6 -0
- package/README.md +4 -0
- package/RESEARCH.md +269 -0
- package/changelog.json +245 -235
- 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/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/package.json +21 -5
package/dist/angular/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/angular/ai-rag-workflow.service.ts
|
|
72
219
|
import { computed as computed2, Injectable as Injectable2 } from "@angular/core";
|
|
73
220
|
|
|
@@ -4448,11 +4595,36 @@ RAGClientService = __decorateElement(_init, 0, "RAGClientService", _dec, RAGClie
|
|
|
4448
4595
|
__runInitializers(_init, 1, RAGClientService);
|
|
4449
4596
|
__decoratorMetadata(_init, RAGClientService);
|
|
4450
4597
|
let _RAGClientService = RAGClientService;
|
|
4598
|
+
// src/angular/research.service.ts
|
|
4599
|
+
import { Injectable as Injectable4, signal } from "@angular/core";
|
|
4600
|
+
var _dec = [
|
|
4601
|
+
Injectable4({ providedIn: "root" })
|
|
4602
|
+
];
|
|
4603
|
+
var _init = __decoratorStart(undefined);
|
|
4604
|
+
|
|
4605
|
+
class ResearchService {
|
|
4606
|
+
connect(path = "/research", destroyRef) {
|
|
4607
|
+
const client = createResearchClient({ path });
|
|
4608
|
+
const state = signal(client.getSnapshot());
|
|
4609
|
+
const unsubscribe = client.subscribe(() => state.set(client.getSnapshot()));
|
|
4610
|
+
const dispose = () => {
|
|
4611
|
+
unsubscribe();
|
|
4612
|
+
client.dispose();
|
|
4613
|
+
};
|
|
4614
|
+
destroyRef?.onDestroy(dispose);
|
|
4615
|
+
return { ...client, state: state.asReadonly(), dispose };
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
ResearchService = __decorateElement(_init, 0, "ResearchService", _dec, ResearchService);
|
|
4619
|
+
__runInitializers(_init, 1, ResearchService);
|
|
4620
|
+
__decoratorMetadata(_init, ResearchService);
|
|
4621
|
+
let _ResearchService = ResearchService;
|
|
4451
4622
|
export {
|
|
4452
4623
|
RAGClientService,
|
|
4453
4624
|
RAGStreamService,
|
|
4454
|
-
RAGWorkflowService
|
|
4625
|
+
RAGWorkflowService,
|
|
4626
|
+
ResearchService
|
|
4455
4627
|
};
|
|
4456
4628
|
|
|
4457
|
-
//# debugId=
|
|
4629
|
+
//# debugId=920870B1BD340B7F64756E2164756E21
|
|
4458
4630
|
//# sourceMappingURL=index.js.map
|