@absolutejs/absolute 0.19.0-beta.432 → 0.19.0-beta.434
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/dist/ai/index.js +95 -1
- package/dist/ai/index.js.map +5 -4
- package/dist/ai-client/react/ai/index.js +252 -10
- package/dist/angular/index.js +7 -3
- package/dist/angular/index.js.map +3 -3
- package/dist/angular/server.js +2 -2
- package/dist/angular/server.js.map +1 -1
- package/dist/build.js +2 -2
- package/dist/build.js.map +1 -1
- package/dist/client/index.js +6 -2
- package/dist/client/index.js.map +3 -3
- package/dist/index.js +7 -3
- package/dist/index.js.map +3 -3
- package/dist/react/ai/index.js +253 -11
- package/dist/react/ai/index.js.map +11 -7
- package/dist/react/index.js +6 -2
- package/dist/react/index.js.map +3 -3
- package/dist/src/ai/client/actions.d.ts +1 -1
- package/dist/src/ai/index.d.ts +2 -2
- package/dist/src/ai/rag/index.d.ts +1 -0
- package/dist/src/ai/rag/presentation.d.ts +10 -0
- package/dist/src/ai/rag/types.d.ts +1 -1
- package/dist/src/react/ai/index.d.ts +3 -0
- package/dist/src/react/ai/useRAG.d.ts +64 -0
- package/dist/src/react/ai/useRAGCitations.d.ts +7 -0
- package/dist/src/react/ai/useRAGIngest.d.ts +8 -2
- package/dist/src/react/ai/useRAGSearch.d.ts +3 -0
- package/dist/src/react/ai/useRAGSources.d.ts +8 -0
- package/dist/src/react/ai/useRAGStatus.d.ts +1 -0
- package/dist/src/react/ai/useRAGStream.d.ts +9 -1
- package/dist/svelte/index.js +6 -2
- package/dist/svelte/index.js.map +3 -3
- package/dist/types/ai.d.ts +20 -0
- package/dist/vue/components/index.js +20 -3
- package/dist/vue/components/index.js.map +3 -3
- package/dist/vue/index.js +27 -6
- package/dist/vue/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -629,8 +629,115 @@ var useAIStream = (path, conversationId) => {
|
|
|
629
629
|
send
|
|
630
630
|
};
|
|
631
631
|
};
|
|
632
|
+
// src/react/ai/useRAG.ts
|
|
633
|
+
import { useMemo as useMemo7 } from "react";
|
|
634
|
+
|
|
635
|
+
// src/react/ai/useRAGCitations.ts
|
|
636
|
+
import { useMemo } from "react";
|
|
637
|
+
|
|
638
|
+
// src/ai/rag/presentation.ts
|
|
639
|
+
var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
|
|
640
|
+
var buildSourceLabel = (source) => source.source ?? source.title ?? source.chunkId;
|
|
641
|
+
var getLatestAssistantMessage = (messages) => {
|
|
642
|
+
for (let index = messages.length - 1;index >= 0; index -= 1) {
|
|
643
|
+
const message = messages[index];
|
|
644
|
+
if (message?.role === "assistant") {
|
|
645
|
+
return message;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
};
|
|
650
|
+
var getLatestRAGSources = (messages) => getLatestAssistantMessage(messages)?.sources ?? [];
|
|
651
|
+
var buildRAGSourceGroups = (sources) => {
|
|
652
|
+
const groups = new Map;
|
|
653
|
+
for (const source of sources) {
|
|
654
|
+
const key = buildSourceGroupKey(source);
|
|
655
|
+
const existing = groups.get(key);
|
|
656
|
+
if (existing) {
|
|
657
|
+
existing.bestScore = Math.max(existing.bestScore, source.score);
|
|
658
|
+
existing.count += 1;
|
|
659
|
+
existing.chunks.push(source);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
groups.set(key, {
|
|
663
|
+
bestScore: source.score,
|
|
664
|
+
chunks: [source],
|
|
665
|
+
count: 1,
|
|
666
|
+
key,
|
|
667
|
+
label: buildSourceLabel(source),
|
|
668
|
+
source: source.source,
|
|
669
|
+
title: source.title
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
return [...groups.values()].sort((left, right) => {
|
|
673
|
+
if (right.bestScore !== left.bestScore) {
|
|
674
|
+
return right.bestScore - left.bestScore;
|
|
675
|
+
}
|
|
676
|
+
return left.label.localeCompare(right.label);
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
var buildRAGCitations = (sources) => {
|
|
680
|
+
const unique = new Map;
|
|
681
|
+
for (const source of sources) {
|
|
682
|
+
const key = source.chunkId;
|
|
683
|
+
const existing = unique.get(key);
|
|
684
|
+
if (existing && existing.score >= source.score) {
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
unique.set(key, {
|
|
688
|
+
chunkId: source.chunkId,
|
|
689
|
+
key,
|
|
690
|
+
label: buildSourceLabel(source),
|
|
691
|
+
metadata: source.metadata,
|
|
692
|
+
score: source.score,
|
|
693
|
+
source: source.source,
|
|
694
|
+
text: source.text,
|
|
695
|
+
title: source.title
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
return [...unique.values()].sort((left, right) => {
|
|
699
|
+
if (right.score !== left.score) {
|
|
700
|
+
return right.score - left.score;
|
|
701
|
+
}
|
|
702
|
+
return left.label.localeCompare(right.label);
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
var resolveRAGStreamStage = ({
|
|
706
|
+
error,
|
|
707
|
+
isStreaming,
|
|
708
|
+
messages
|
|
709
|
+
}) => {
|
|
710
|
+
if (error) {
|
|
711
|
+
return "error";
|
|
712
|
+
}
|
|
713
|
+
const assistantMessage = getLatestAssistantMessage(messages);
|
|
714
|
+
if (!assistantMessage) {
|
|
715
|
+
return isStreaming ? "submitting" : "idle";
|
|
716
|
+
}
|
|
717
|
+
if (!isStreaming) {
|
|
718
|
+
return "complete";
|
|
719
|
+
}
|
|
720
|
+
const hasSources = (assistantMessage.sources?.length ?? 0) > 0;
|
|
721
|
+
const hasContent = assistantMessage.content.trim().length > 0 || assistantMessage.thinking?.trim().length || (assistantMessage.toolCalls?.length ?? 0) > 0 || (assistantMessage.images?.length ?? 0) > 0;
|
|
722
|
+
if (hasSources && !hasContent) {
|
|
723
|
+
return "retrieved";
|
|
724
|
+
}
|
|
725
|
+
return "streaming";
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// src/react/ai/useRAGCitations.ts
|
|
729
|
+
var useRAGCitations = (sources) => {
|
|
730
|
+
const citations = useMemo(() => buildRAGCitations(sources), [sources]);
|
|
731
|
+
const sourceGroups = useMemo(() => buildRAGSourceGroups(sources), [sources]);
|
|
732
|
+
return {
|
|
733
|
+
citations,
|
|
734
|
+
hasCitations: citations.length > 0,
|
|
735
|
+
sourceGroups
|
|
736
|
+
};
|
|
737
|
+
};
|
|
738
|
+
|
|
632
739
|
// src/react/ai/useRAGIngest.ts
|
|
633
|
-
import { useCallback as useCallback2, useMemo, useState } from "react";
|
|
740
|
+
import { useCallback as useCallback2, useMemo as useMemo2, useState } from "react";
|
|
634
741
|
|
|
635
742
|
// src/ai/client/ragClient.ts
|
|
636
743
|
var jsonHeaders = {
|
|
@@ -718,11 +825,13 @@ var createRAGClient = (options) => {
|
|
|
718
825
|
|
|
719
826
|
// src/react/ai/useRAGIngest.ts
|
|
720
827
|
var useRAGIngest = (path) => {
|
|
721
|
-
const client =
|
|
828
|
+
const client = useMemo2(() => createRAGClient({ path }), [path]);
|
|
722
829
|
const [error, setError] = useState(null);
|
|
723
830
|
const [isIngesting, setIsIngesting] = useState(false);
|
|
724
831
|
const [lastIngestCount, setLastIngestCount] = useState(null);
|
|
725
|
-
const
|
|
832
|
+
const [lastDocumentCount, setLastDocumentCount] = useState(null);
|
|
833
|
+
const [lastResponse, setLastResponse] = useState(null);
|
|
834
|
+
const ingestChunks = useCallback2(async (chunks) => {
|
|
726
835
|
setIsIngesting(true);
|
|
727
836
|
setError(null);
|
|
728
837
|
try {
|
|
@@ -731,6 +840,8 @@ var useRAGIngest = (path) => {
|
|
|
731
840
|
throw new Error(response.error ?? "RAG ingest failed");
|
|
732
841
|
}
|
|
733
842
|
setLastIngestCount(response.count ?? chunks.length);
|
|
843
|
+
setLastDocumentCount(null);
|
|
844
|
+
setLastResponse(response);
|
|
734
845
|
return response;
|
|
735
846
|
} catch (caught) {
|
|
736
847
|
const message = caught instanceof Error ? caught.message : String(caught);
|
|
@@ -740,26 +851,79 @@ var useRAGIngest = (path) => {
|
|
|
740
851
|
setIsIngesting(false);
|
|
741
852
|
}
|
|
742
853
|
}, [client]);
|
|
854
|
+
const ingestDocuments = useCallback2(async (input) => {
|
|
855
|
+
setIsIngesting(true);
|
|
856
|
+
setError(null);
|
|
857
|
+
try {
|
|
858
|
+
const response = await client.ingestDocuments(input);
|
|
859
|
+
if (!response.ok) {
|
|
860
|
+
throw new Error(response.error ?? "RAG ingest failed");
|
|
861
|
+
}
|
|
862
|
+
setLastIngestCount(response.count ?? null);
|
|
863
|
+
setLastDocumentCount(response.documentCount ?? input.documents.length);
|
|
864
|
+
setLastResponse(response);
|
|
865
|
+
return response;
|
|
866
|
+
} catch (caught) {
|
|
867
|
+
const message = caught instanceof Error ? caught.message : String(caught);
|
|
868
|
+
setError(message);
|
|
869
|
+
throw caught;
|
|
870
|
+
} finally {
|
|
871
|
+
setIsIngesting(false);
|
|
872
|
+
}
|
|
873
|
+
}, [client]);
|
|
874
|
+
const clearIndex = useCallback2(async () => {
|
|
875
|
+
setIsIngesting(true);
|
|
876
|
+
setError(null);
|
|
877
|
+
try {
|
|
878
|
+
await client.clearIndex();
|
|
879
|
+
setLastIngestCount(0);
|
|
880
|
+
setLastDocumentCount(0);
|
|
881
|
+
setLastResponse(null);
|
|
882
|
+
} catch (caught) {
|
|
883
|
+
const message = caught instanceof Error ? caught.message : String(caught);
|
|
884
|
+
setError(message);
|
|
885
|
+
throw caught;
|
|
886
|
+
} finally {
|
|
887
|
+
setIsIngesting(false);
|
|
888
|
+
}
|
|
889
|
+
}, [client]);
|
|
890
|
+
const reset = useCallback2(() => {
|
|
891
|
+
setError(null);
|
|
892
|
+
setLastDocumentCount(null);
|
|
893
|
+
setLastIngestCount(null);
|
|
894
|
+
setLastResponse(null);
|
|
895
|
+
}, []);
|
|
743
896
|
return {
|
|
897
|
+
clearIndex,
|
|
744
898
|
error,
|
|
745
|
-
ingest,
|
|
899
|
+
ingest: ingestChunks,
|
|
900
|
+
ingestChunks,
|
|
901
|
+
ingestDocuments,
|
|
746
902
|
isIngesting,
|
|
747
|
-
|
|
903
|
+
lastDocumentCount,
|
|
904
|
+
lastIngestCount,
|
|
905
|
+
lastResponse,
|
|
906
|
+
reset
|
|
748
907
|
};
|
|
749
908
|
};
|
|
909
|
+
|
|
750
910
|
// src/react/ai/useRAGSearch.ts
|
|
751
|
-
import { useCallback as useCallback3, useMemo as
|
|
911
|
+
import { useCallback as useCallback3, useMemo as useMemo3, useState as useState2 } from "react";
|
|
752
912
|
var useRAGSearch = (path) => {
|
|
753
|
-
const client =
|
|
913
|
+
const client = useMemo3(() => createRAGClient({ path }), [path]);
|
|
754
914
|
const [results, setResults] = useState2([]);
|
|
755
915
|
const [error, setError] = useState2(null);
|
|
756
916
|
const [isSearching, setIsSearching] = useState2(false);
|
|
917
|
+
const [hasSearched, setHasSearched] = useState2(false);
|
|
918
|
+
const [lastRequest, setLastRequest] = useState2(null);
|
|
757
919
|
const search = useCallback3(async (input) => {
|
|
758
920
|
setIsSearching(true);
|
|
759
921
|
setError(null);
|
|
922
|
+
setLastRequest(input);
|
|
760
923
|
try {
|
|
761
924
|
const nextResults = await client.search(input);
|
|
762
925
|
setResults(nextResults);
|
|
926
|
+
setHasSearched(true);
|
|
763
927
|
return nextResults;
|
|
764
928
|
} catch (caught) {
|
|
765
929
|
const message = caught instanceof Error ? caught.message : String(caught);
|
|
@@ -769,18 +933,42 @@ var useRAGSearch = (path) => {
|
|
|
769
933
|
setIsSearching(false);
|
|
770
934
|
}
|
|
771
935
|
}, [client]);
|
|
936
|
+
const reset = useCallback3(() => {
|
|
937
|
+
setError(null);
|
|
938
|
+
setHasSearched(false);
|
|
939
|
+
setLastRequest(null);
|
|
940
|
+
setResults([]);
|
|
941
|
+
}, []);
|
|
772
942
|
return {
|
|
773
943
|
error,
|
|
944
|
+
hasSearched,
|
|
774
945
|
isSearching,
|
|
946
|
+
lastRequest,
|
|
947
|
+
reset,
|
|
775
948
|
results,
|
|
776
949
|
search,
|
|
777
950
|
setResults
|
|
778
951
|
};
|
|
779
952
|
};
|
|
953
|
+
|
|
954
|
+
// src/react/ai/useRAGSources.ts
|
|
955
|
+
import { useMemo as useMemo4 } from "react";
|
|
956
|
+
var useRAGSources = (messages) => {
|
|
957
|
+
const latestAssistantMessage = useMemo4(() => getLatestAssistantMessage(messages), [messages]);
|
|
958
|
+
const sources = useMemo4(() => getLatestRAGSources(messages), [messages]);
|
|
959
|
+
const sourceGroups = useMemo4(() => buildRAGSourceGroups(sources), [sources]);
|
|
960
|
+
return {
|
|
961
|
+
hasSources: sources.length > 0,
|
|
962
|
+
latestAssistantMessage,
|
|
963
|
+
sourceGroups,
|
|
964
|
+
sources
|
|
965
|
+
};
|
|
966
|
+
};
|
|
967
|
+
|
|
780
968
|
// src/react/ai/useRAGStatus.ts
|
|
781
|
-
import { useCallback as useCallback4, useEffect as useEffect3, useMemo as
|
|
969
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
782
970
|
var useRAGStatus = (path, autoLoad = true) => {
|
|
783
|
-
const client =
|
|
971
|
+
const client = useMemo5(() => createRAGClient({ path }), [path]);
|
|
784
972
|
const [status, setStatus] = useState3();
|
|
785
973
|
const [capabilities, setCapabilities] = useState3();
|
|
786
974
|
const [error, setError] = useState3(null);
|
|
@@ -801,6 +989,12 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
801
989
|
setIsLoading(false);
|
|
802
990
|
}
|
|
803
991
|
}, [client]);
|
|
992
|
+
const reset = useCallback4(() => {
|
|
993
|
+
setCapabilities(undefined);
|
|
994
|
+
setError(null);
|
|
995
|
+
setIsLoading(false);
|
|
996
|
+
setStatus(undefined);
|
|
997
|
+
}, []);
|
|
804
998
|
useEffect3(() => {
|
|
805
999
|
if (!autoLoad) {
|
|
806
1000
|
setIsLoading(false);
|
|
@@ -813,16 +1007,64 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
813
1007
|
error,
|
|
814
1008
|
isLoading,
|
|
815
1009
|
refresh,
|
|
1010
|
+
reset,
|
|
816
1011
|
status
|
|
817
1012
|
};
|
|
818
1013
|
};
|
|
1014
|
+
|
|
819
1015
|
// src/react/ai/useRAGStream.ts
|
|
820
|
-
|
|
1016
|
+
import { useCallback as useCallback5, useMemo as useMemo6 } from "react";
|
|
1017
|
+
var useRAGStream = (path, conversationId) => {
|
|
1018
|
+
const stream = useAIStream(path, conversationId);
|
|
1019
|
+
const latestAssistantMessage = useMemo6(() => getLatestAssistantMessage(stream.messages), [stream.messages]);
|
|
1020
|
+
const sources = useMemo6(() => getLatestRAGSources(stream.messages), [stream.messages]);
|
|
1021
|
+
const sourceGroups = useMemo6(() => buildRAGSourceGroups(sources), [sources]);
|
|
1022
|
+
const citations = useMemo6(() => buildRAGCitations(sources), [sources]);
|
|
1023
|
+
const stage = useMemo6(() => resolveRAGStreamStage({
|
|
1024
|
+
error: stream.error,
|
|
1025
|
+
isStreaming: stream.isStreaming,
|
|
1026
|
+
messages: stream.messages
|
|
1027
|
+
}), [stream.error, stream.isStreaming, stream.messages]);
|
|
1028
|
+
const query = useCallback5((content, attachments) => {
|
|
1029
|
+
stream.send(content, attachments);
|
|
1030
|
+
}, [stream]);
|
|
1031
|
+
return {
|
|
1032
|
+
...stream,
|
|
1033
|
+
citations,
|
|
1034
|
+
hasSources: sources.length > 0,
|
|
1035
|
+
latestAssistantMessage,
|
|
1036
|
+
query,
|
|
1037
|
+
sourceGroups,
|
|
1038
|
+
sources,
|
|
1039
|
+
stage
|
|
1040
|
+
};
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
// src/react/ai/useRAG.ts
|
|
1044
|
+
var useRAG = (path, options = {}) => {
|
|
1045
|
+
const search = useRAGSearch(path);
|
|
1046
|
+
const ingest = useRAGIngest(path);
|
|
1047
|
+
const status = useRAGStatus(path, options.autoLoadStatus ?? true);
|
|
1048
|
+
const stream = useRAGStream(options.streamPath ?? path, options.conversationId);
|
|
1049
|
+
const sources = useRAGSources(stream.messages);
|
|
1050
|
+
const citations = useRAGCitations(sources.sources);
|
|
1051
|
+
return useMemo7(() => ({
|
|
1052
|
+
citations,
|
|
1053
|
+
ingest,
|
|
1054
|
+
search,
|
|
1055
|
+
sources,
|
|
1056
|
+
status,
|
|
1057
|
+
stream
|
|
1058
|
+
}), [citations, ingest, search, sources, status, stream]);
|
|
1059
|
+
};
|
|
821
1060
|
export {
|
|
822
1061
|
useRAGStream,
|
|
823
1062
|
useRAGStatus,
|
|
1063
|
+
useRAGSources,
|
|
824
1064
|
useRAGSearch,
|
|
825
1065
|
useRAGIngest,
|
|
1066
|
+
useRAGCitations,
|
|
1067
|
+
useRAG,
|
|
826
1068
|
useAIStream,
|
|
827
1069
|
AIStreamProvider
|
|
828
1070
|
};
|
package/dist/angular/index.js
CHANGED
|
@@ -169199,7 +169199,7 @@ ${registrations}
|
|
|
169199
169199
|
({ tsLibDir } = cached);
|
|
169200
169200
|
cached.lastUsed = Date.now();
|
|
169201
169201
|
} else {
|
|
169202
|
-
const tsPath = __require.resolve("typescript");
|
|
169202
|
+
const tsPath = __require.resolve("/home/alexkahn/abs/absolutejs/node_modules/typescript/lib/typescript.js");
|
|
169203
169203
|
const tsRootDir = dirname(tsPath);
|
|
169204
169204
|
tsLibDir = tsRootDir.endsWith("lib") ? tsRootDir : resolve(tsRootDir, "lib");
|
|
169205
169205
|
const config = readConfiguration("./tsconfig.json");
|
|
@@ -180720,7 +180720,7 @@ var streamSwapRuntime = () => {
|
|
|
180720
180720
|
return;
|
|
180721
180721
|
}
|
|
180722
180722
|
}
|
|
180723
|
-
if (isAngularDeferPayload(payload)
|
|
180723
|
+
if (isAngularDeferPayload(payload)) {
|
|
180724
180724
|
pending[id] = payload;
|
|
180725
180725
|
return;
|
|
180726
180726
|
}
|
|
@@ -180734,6 +180734,10 @@ var streamSwapRuntime = () => {
|
|
|
180734
180734
|
window.dispatchEvent(new CustomEvent(SLOT_PATCH_EVENT, {
|
|
180735
180735
|
detail: { html, id, payload }
|
|
180736
180736
|
}));
|
|
180737
|
+
if (isVueSuspensePayload(payload)) {
|
|
180738
|
+
pending[id] = payload;
|
|
180739
|
+
return;
|
|
180740
|
+
}
|
|
180737
180741
|
delete pending[id];
|
|
180738
180742
|
};
|
|
180739
180743
|
const flush = () => {
|
|
@@ -181936,5 +181940,5 @@ export {
|
|
|
181936
181940
|
DeferErrorTemplateDirective
|
|
181937
181941
|
};
|
|
181938
181942
|
|
|
181939
|
-
//# debugId=
|
|
181943
|
+
//# debugId=0C67DBD8EAFD44E764756E2164756E21
|
|
181940
181944
|
//# sourceMappingURL=index.js.map
|