@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.
- package/CHANGELOG.md +12 -0
- package/README.md +4 -0
- package/RESEARCH.md +268 -0
- package/changelog.json +262 -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 +125286 -0
- package/dist/research/index.js.map +369 -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/schema.d.ts +8 -0
- package/dist/src/research/store.d.ts +29 -0
- package/dist/src/research/types.d.ts +96 -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 +24 -6
package/dist/client/index.js
CHANGED
|
@@ -12740,15 +12740,163 @@ var createRAGClient = (options) => {
|
|
|
12740
12740
|
}
|
|
12741
12741
|
};
|
|
12742
12742
|
};
|
|
12743
|
+
// src/client/research.ts
|
|
12744
|
+
var createResearchClient = (options = {}) => {
|
|
12745
|
+
let state = {
|
|
12746
|
+
status: "idle",
|
|
12747
|
+
result: null,
|
|
12748
|
+
progress: null,
|
|
12749
|
+
error: null
|
|
12750
|
+
};
|
|
12751
|
+
let active;
|
|
12752
|
+
let generation = 0;
|
|
12753
|
+
const listeners = new Set;
|
|
12754
|
+
const publish = (next) => {
|
|
12755
|
+
state = next;
|
|
12756
|
+
listeners.forEach((listener) => listener());
|
|
12757
|
+
};
|
|
12758
|
+
const cancel = () => {
|
|
12759
|
+
generation++;
|
|
12760
|
+
active?.abort();
|
|
12761
|
+
active = undefined;
|
|
12762
|
+
if (state.status === "running")
|
|
12763
|
+
publish({ ...state, status: "cancelled" });
|
|
12764
|
+
};
|
|
12765
|
+
const run = async (input) => {
|
|
12766
|
+
active?.abort();
|
|
12767
|
+
const id = ++generation;
|
|
12768
|
+
const controller = new AbortController;
|
|
12769
|
+
active = controller;
|
|
12770
|
+
publish({ status: "running", result: null, progress: null, error: null });
|
|
12771
|
+
let reader;
|
|
12772
|
+
try {
|
|
12773
|
+
const headers = new Headers(options.headers?.());
|
|
12774
|
+
headers.set("content-type", "application/json");
|
|
12775
|
+
const response = await (options.fetch ?? fetch)(`${options.path ?? "/research"}/stream`, {
|
|
12776
|
+
method: "POST",
|
|
12777
|
+
body: JSON.stringify(input),
|
|
12778
|
+
headers,
|
|
12779
|
+
credentials: "same-origin",
|
|
12780
|
+
signal: controller.signal
|
|
12781
|
+
});
|
|
12782
|
+
if (!response.ok || !response.body)
|
|
12783
|
+
throw new Error(`Research request failed (${response.status})`);
|
|
12784
|
+
reader = response.body.getReader();
|
|
12785
|
+
const decoder = new TextDecoder;
|
|
12786
|
+
let pending = "";
|
|
12787
|
+
let result;
|
|
12788
|
+
const processLine = (line) => {
|
|
12789
|
+
if (!line.trim())
|
|
12790
|
+
return;
|
|
12791
|
+
const event = JSON.parse(line);
|
|
12792
|
+
if (event.type === "error")
|
|
12793
|
+
throw new Error("Research request failed");
|
|
12794
|
+
if (event.type === "result") {
|
|
12795
|
+
if (!event.result || !["reviewed", "partial", "empty", "unavailable"].includes(event.result.status) || !Array.isArray(event.result.fields) || !Array.isArray(event.result.sources))
|
|
12796
|
+
throw new Error("Invalid research result");
|
|
12797
|
+
result = event.result;
|
|
12798
|
+
}
|
|
12799
|
+
if (event.type === "progress" && id === generation)
|
|
12800
|
+
publish({ ...state, progress: event.progress });
|
|
12801
|
+
};
|
|
12802
|
+
while (true) {
|
|
12803
|
+
controller.signal.throwIfAborted();
|
|
12804
|
+
const chunk = await reader.read();
|
|
12805
|
+
pending += decoder.decode(chunk.value, { stream: !chunk.done });
|
|
12806
|
+
if (pending.length > 4000000)
|
|
12807
|
+
throw new Error("Research response too large");
|
|
12808
|
+
let newline;
|
|
12809
|
+
while ((newline = pending.indexOf(`
|
|
12810
|
+
`)) >= 0) {
|
|
12811
|
+
processLine(pending.slice(0, newline));
|
|
12812
|
+
pending = pending.slice(newline + 1);
|
|
12813
|
+
}
|
|
12814
|
+
if (chunk.done)
|
|
12815
|
+
break;
|
|
12816
|
+
}
|
|
12817
|
+
if (pending)
|
|
12818
|
+
processLine(pending);
|
|
12819
|
+
controller.signal.throwIfAborted();
|
|
12820
|
+
if (!result)
|
|
12821
|
+
throw new Error("Research stream ended without a result");
|
|
12822
|
+
if (id === generation)
|
|
12823
|
+
publish({ ...state, status: "complete", result });
|
|
12824
|
+
return result;
|
|
12825
|
+
} catch (error) {
|
|
12826
|
+
if (id === generation)
|
|
12827
|
+
publish({
|
|
12828
|
+
...state,
|
|
12829
|
+
status: controller.signal.aborted ? "cancelled" : "error",
|
|
12830
|
+
error: controller.signal.aborted ? null : error instanceof Error ? error.message : "Research request failed"
|
|
12831
|
+
});
|
|
12832
|
+
throw error;
|
|
12833
|
+
} finally {
|
|
12834
|
+
await reader?.cancel().catch(() => {
|
|
12835
|
+
return;
|
|
12836
|
+
});
|
|
12837
|
+
reader?.releaseLock();
|
|
12838
|
+
if (id === generation)
|
|
12839
|
+
active = undefined;
|
|
12840
|
+
}
|
|
12841
|
+
};
|
|
12842
|
+
return {
|
|
12843
|
+
run,
|
|
12844
|
+
cancel,
|
|
12845
|
+
getSnapshot: () => state,
|
|
12846
|
+
subscribe: (listener) => {
|
|
12847
|
+
listeners.add(listener);
|
|
12848
|
+
return () => {
|
|
12849
|
+
listeners.delete(listener);
|
|
12850
|
+
};
|
|
12851
|
+
},
|
|
12852
|
+
reset: () => {
|
|
12853
|
+
cancel();
|
|
12854
|
+
publish({ status: "idle", result: null, progress: null, error: null });
|
|
12855
|
+
},
|
|
12856
|
+
dispose: () => {
|
|
12857
|
+
cancel();
|
|
12858
|
+
listeners.clear();
|
|
12859
|
+
}
|
|
12860
|
+
};
|
|
12861
|
+
};
|
|
12862
|
+
var bindResearchForm = (form, output, options = {}) => {
|
|
12863
|
+
const client = createResearchClient(options);
|
|
12864
|
+
const unsubscribe = client.subscribe(() => {
|
|
12865
|
+
const state = client.getSnapshot();
|
|
12866
|
+
output.setAttribute("aria-busy", String(state.status === "running"));
|
|
12867
|
+
output.textContent = state.result ? JSON.stringify(state.result, null, 2) : state.error ?? state.status;
|
|
12868
|
+
});
|
|
12869
|
+
const submit = (event) => {
|
|
12870
|
+
event.preventDefault();
|
|
12871
|
+
const data = new FormData(form);
|
|
12872
|
+
client.run({
|
|
12873
|
+
query: String(data.get("query") ?? ""),
|
|
12874
|
+
...data.get("task") ? { task: String(data.get("task")) } : {}
|
|
12875
|
+
}).catch(() => {
|
|
12876
|
+
return;
|
|
12877
|
+
});
|
|
12878
|
+
};
|
|
12879
|
+
form.addEventListener("submit", submit);
|
|
12880
|
+
return {
|
|
12881
|
+
...client,
|
|
12882
|
+
dispose: () => {
|
|
12883
|
+
form.removeEventListener("submit", submit);
|
|
12884
|
+
unsubscribe();
|
|
12885
|
+
client.dispose();
|
|
12886
|
+
}
|
|
12887
|
+
};
|
|
12888
|
+
};
|
|
12743
12889
|
export {
|
|
12890
|
+
bindResearchForm,
|
|
12744
12891
|
buildRAGEvaluationLeaderboard,
|
|
12745
12892
|
buildRAGMaintenanceOverview,
|
|
12746
12893
|
createRAGClient,
|
|
12747
12894
|
createRAGEvaluationSuite,
|
|
12748
12895
|
createAIStream2 as createRAGStream,
|
|
12749
12896
|
createRAGAnswerWorkflow as createRAGWorkflow,
|
|
12897
|
+
createResearchClient,
|
|
12750
12898
|
runRAGEvaluationSuite
|
|
12751
12899
|
};
|
|
12752
12900
|
|
|
12753
|
-
//# debugId=
|
|
12901
|
+
//# debugId=0FC3B8EC8BC5C82964756E2164756E21
|
|
12754
12902
|
//# sourceMappingURL=index.js.map
|