@absolutejs/absolute 0.19.0-beta.442 → 0.19.0-beta.443
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/angular/index.js +2 -2
- package/dist/angular/index.js.map +1 -1
- 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/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/src/svelte/ai/createAIStream.d.ts +1 -0
- package/dist/src/svelte/ai/createRAG.d.ts +117 -0
- package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +11 -0
- package/dist/src/svelte/ai/createRAGCitations.d.ts +8 -0
- package/dist/src/svelte/ai/createRAGDocuments.d.ts +10 -0
- package/dist/src/svelte/ai/createRAGIndexAdmin.d.ts +30 -0
- package/dist/src/svelte/ai/createRAGIngest.d.ts +10 -2
- package/dist/src/svelte/ai/createRAGSearch.d.ts +3 -0
- package/dist/src/svelte/ai/createRAGSources.d.ts +9 -0
- package/dist/src/svelte/ai/createRAGStatus.d.ts +1 -0
- package/dist/src/svelte/ai/createRAGStream.d.ts +24 -1
- package/dist/src/svelte/ai/index.d.ts +6 -0
- package/dist/svelte/ai/index.js +486 -18
- package/dist/svelte/ai/index.js.map +15 -7
- package/package.json +1 -1
package/dist/svelte/ai/index.js
CHANGED
|
@@ -648,6 +648,7 @@ var serializeAIMessage = (msg) => JSON.stringify(msg);
|
|
|
648
648
|
var createAIStream = (path, conversationId) => {
|
|
649
649
|
const connection = createAIConnection(path);
|
|
650
650
|
const store = createAIMessageStore();
|
|
651
|
+
const subscribers = new Set;
|
|
651
652
|
let currentError = null;
|
|
652
653
|
let currentIsStreaming = false;
|
|
653
654
|
let currentMessages = [];
|
|
@@ -660,6 +661,7 @@ var createAIStream = (path, conversationId) => {
|
|
|
660
661
|
currentError = snapshot.error;
|
|
661
662
|
currentIsStreaming = snapshot.isStreaming;
|
|
662
663
|
currentMessages = conversation?.messages ?? [];
|
|
664
|
+
subscribers.forEach((callback) => callback());
|
|
663
665
|
};
|
|
664
666
|
const unsubscribeStore = store.subscribe(syncState);
|
|
665
667
|
const unsubscribeConnection = connection.subscribe((msg) => {
|
|
@@ -714,6 +716,12 @@ var createAIStream = (path, conversationId) => {
|
|
|
714
716
|
cancel,
|
|
715
717
|
destroy,
|
|
716
718
|
send,
|
|
719
|
+
subscribe(callback) {
|
|
720
|
+
subscribers.add(callback);
|
|
721
|
+
return () => {
|
|
722
|
+
subscribers.delete(callback);
|
|
723
|
+
};
|
|
724
|
+
},
|
|
717
725
|
get error() {
|
|
718
726
|
return currentError;
|
|
719
727
|
},
|
|
@@ -725,7 +733,7 @@ var createAIStream = (path, conversationId) => {
|
|
|
725
733
|
}
|
|
726
734
|
};
|
|
727
735
|
};
|
|
728
|
-
// src/svelte/ai/
|
|
736
|
+
// src/svelte/ai/createRAGChunkPreview.ts
|
|
729
737
|
import { writable } from "svelte/store";
|
|
730
738
|
|
|
731
739
|
// src/ai/client/ragClient.ts
|
|
@@ -885,13 +893,221 @@ var createRAGClient = (options) => {
|
|
|
885
893
|
};
|
|
886
894
|
};
|
|
887
895
|
|
|
896
|
+
// src/svelte/ai/createRAGChunkPreview.ts
|
|
897
|
+
var createRAGChunkPreview = (path) => {
|
|
898
|
+
const client = createRAGClient({ path });
|
|
899
|
+
const preview = writable(null);
|
|
900
|
+
const error = writable(null);
|
|
901
|
+
const isLoading = writable(false);
|
|
902
|
+
const inspect = async (id) => {
|
|
903
|
+
isLoading.set(true);
|
|
904
|
+
error.set(null);
|
|
905
|
+
try {
|
|
906
|
+
const response = await client.documentChunks(id);
|
|
907
|
+
if (!response.ok) {
|
|
908
|
+
throw new Error(response.error);
|
|
909
|
+
}
|
|
910
|
+
preview.set(response);
|
|
911
|
+
return response;
|
|
912
|
+
} catch (caught) {
|
|
913
|
+
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
914
|
+
throw caught;
|
|
915
|
+
} finally {
|
|
916
|
+
isLoading.set(false);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
const clear = () => {
|
|
920
|
+
error.set(null);
|
|
921
|
+
isLoading.set(false);
|
|
922
|
+
preview.set(null);
|
|
923
|
+
};
|
|
924
|
+
return {
|
|
925
|
+
clear,
|
|
926
|
+
error,
|
|
927
|
+
inspect,
|
|
928
|
+
isLoading,
|
|
929
|
+
preview
|
|
930
|
+
};
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
// src/svelte/ai/createRAGCitations.ts
|
|
934
|
+
import { derived } from "svelte/store";
|
|
935
|
+
|
|
936
|
+
// src/ai/rag/presentation.ts
|
|
937
|
+
var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.chunkId;
|
|
938
|
+
var buildSourceLabel = (source) => source.source ?? source.title ?? source.chunkId;
|
|
939
|
+
var getLatestAssistantMessage = (messages) => {
|
|
940
|
+
for (let index = messages.length - 1;index >= 0; index -= 1) {
|
|
941
|
+
const message = messages[index];
|
|
942
|
+
if (message?.role === "assistant") {
|
|
943
|
+
return message;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return;
|
|
947
|
+
};
|
|
948
|
+
var getLatestRAGSources = (messages) => getLatestAssistantMessage(messages)?.sources ?? [];
|
|
949
|
+
var getLatestRetrievedMessage = (messages) => {
|
|
950
|
+
for (let index = messages.length - 1;index >= 0; index -= 1) {
|
|
951
|
+
const message = messages[index];
|
|
952
|
+
if (message?.role === "assistant" && (message.sources?.length ?? 0) > 0) {
|
|
953
|
+
return message;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return;
|
|
957
|
+
};
|
|
958
|
+
var buildRAGSourceGroups = (sources) => {
|
|
959
|
+
const groups = new Map;
|
|
960
|
+
for (const source of sources) {
|
|
961
|
+
const key = buildSourceGroupKey(source);
|
|
962
|
+
const existing = groups.get(key);
|
|
963
|
+
if (existing) {
|
|
964
|
+
existing.bestScore = Math.max(existing.bestScore, source.score);
|
|
965
|
+
existing.count += 1;
|
|
966
|
+
existing.chunks.push(source);
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
groups.set(key, {
|
|
970
|
+
bestScore: source.score,
|
|
971
|
+
chunks: [source],
|
|
972
|
+
count: 1,
|
|
973
|
+
key,
|
|
974
|
+
label: buildSourceLabel(source),
|
|
975
|
+
source: source.source,
|
|
976
|
+
title: source.title
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
return [...groups.values()].sort((left, right) => {
|
|
980
|
+
if (right.bestScore !== left.bestScore) {
|
|
981
|
+
return right.bestScore - left.bestScore;
|
|
982
|
+
}
|
|
983
|
+
return left.label.localeCompare(right.label);
|
|
984
|
+
});
|
|
985
|
+
};
|
|
986
|
+
var buildRAGCitations = (sources) => {
|
|
987
|
+
const unique = new Map;
|
|
988
|
+
for (const source of sources) {
|
|
989
|
+
const key = source.chunkId;
|
|
990
|
+
const existing = unique.get(key);
|
|
991
|
+
if (existing && existing.score >= source.score) {
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
unique.set(key, {
|
|
995
|
+
chunkId: source.chunkId,
|
|
996
|
+
key,
|
|
997
|
+
label: buildSourceLabel(source),
|
|
998
|
+
metadata: source.metadata,
|
|
999
|
+
score: source.score,
|
|
1000
|
+
source: source.source,
|
|
1001
|
+
text: source.text,
|
|
1002
|
+
title: source.title
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
return [...unique.values()].sort((left, right) => {
|
|
1006
|
+
if (right.score !== left.score) {
|
|
1007
|
+
return right.score - left.score;
|
|
1008
|
+
}
|
|
1009
|
+
return left.label.localeCompare(right.label);
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
1012
|
+
var buildRAGRetrievedState = (messages) => {
|
|
1013
|
+
const message = getLatestRetrievedMessage(messages);
|
|
1014
|
+
if (!message) {
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
const sources = message.sources ?? [];
|
|
1018
|
+
return {
|
|
1019
|
+
citations: buildRAGCitations(sources),
|
|
1020
|
+
conversationId: message.conversationId,
|
|
1021
|
+
messageId: message.id,
|
|
1022
|
+
retrievedAt: message.retrievedAt,
|
|
1023
|
+
sourceGroups: buildRAGSourceGroups(sources),
|
|
1024
|
+
sources
|
|
1025
|
+
};
|
|
1026
|
+
};
|
|
1027
|
+
var resolveRAGStreamStage = ({
|
|
1028
|
+
error,
|
|
1029
|
+
isStreaming,
|
|
1030
|
+
messages
|
|
1031
|
+
}) => {
|
|
1032
|
+
if (error) {
|
|
1033
|
+
return "error";
|
|
1034
|
+
}
|
|
1035
|
+
const assistantMessage = getLatestAssistantMessage(messages);
|
|
1036
|
+
if (!assistantMessage) {
|
|
1037
|
+
return isStreaming ? "submitting" : "idle";
|
|
1038
|
+
}
|
|
1039
|
+
if (!isStreaming) {
|
|
1040
|
+
return "complete";
|
|
1041
|
+
}
|
|
1042
|
+
const hasSources = (assistantMessage.sources?.length ?? 0) > 0;
|
|
1043
|
+
const hasContent = assistantMessage.content.trim().length > 0 || assistantMessage.thinking?.trim().length || (assistantMessage.toolCalls?.length ?? 0) > 0 || (assistantMessage.images?.length ?? 0) > 0;
|
|
1044
|
+
if (hasSources && !hasContent) {
|
|
1045
|
+
return "retrieved";
|
|
1046
|
+
}
|
|
1047
|
+
return "streaming";
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
// src/svelte/ai/createRAGCitations.ts
|
|
1051
|
+
var createRAGCitations = (sources) => {
|
|
1052
|
+
const citations = derived(sources, ($sources) => buildRAGCitations($sources));
|
|
1053
|
+
const sourceGroups = derived(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
1054
|
+
const hasCitations = derived(citations, ($citations) => $citations.length > 0);
|
|
1055
|
+
return {
|
|
1056
|
+
citations,
|
|
1057
|
+
hasCitations,
|
|
1058
|
+
sourceGroups
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
// src/svelte/ai/createRAGDocuments.ts
|
|
1063
|
+
import { writable as writable2 } from "svelte/store";
|
|
1064
|
+
var createRAGDocuments = (path) => {
|
|
1065
|
+
const client = createRAGClient({ path });
|
|
1066
|
+
const documents = writable2([]);
|
|
1067
|
+
const error = writable2(null);
|
|
1068
|
+
const isLoading = writable2(false);
|
|
1069
|
+
const lastResponse = writable2(null);
|
|
1070
|
+
const load = async (kind) => {
|
|
1071
|
+
isLoading.set(true);
|
|
1072
|
+
error.set(null);
|
|
1073
|
+
try {
|
|
1074
|
+
const response = await client.documents(kind);
|
|
1075
|
+
documents.set(response.documents);
|
|
1076
|
+
lastResponse.set(response);
|
|
1077
|
+
return response;
|
|
1078
|
+
} catch (caught) {
|
|
1079
|
+
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
1080
|
+
throw caught;
|
|
1081
|
+
} finally {
|
|
1082
|
+
isLoading.set(false);
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
const reset = () => {
|
|
1086
|
+
documents.set([]);
|
|
1087
|
+
error.set(null);
|
|
1088
|
+
isLoading.set(false);
|
|
1089
|
+
lastResponse.set(null);
|
|
1090
|
+
};
|
|
1091
|
+
return {
|
|
1092
|
+
documents,
|
|
1093
|
+
error,
|
|
1094
|
+
isLoading,
|
|
1095
|
+
lastResponse,
|
|
1096
|
+
load,
|
|
1097
|
+
reset
|
|
1098
|
+
};
|
|
1099
|
+
};
|
|
1100
|
+
|
|
888
1101
|
// src/svelte/ai/createRAGIngest.ts
|
|
1102
|
+
import { writable as writable3 } from "svelte/store";
|
|
889
1103
|
var createRAGIngest = (path) => {
|
|
890
1104
|
const client = createRAGClient({ path });
|
|
891
|
-
const error =
|
|
892
|
-
const isIngesting =
|
|
893
|
-
const lastIngestCount =
|
|
894
|
-
const
|
|
1105
|
+
const error = writable3(null);
|
|
1106
|
+
const isIngesting = writable3(false);
|
|
1107
|
+
const lastIngestCount = writable3(null);
|
|
1108
|
+
const lastDocumentCount = writable3(null);
|
|
1109
|
+
const lastResponse = writable3(null);
|
|
1110
|
+
const ingestChunks = async (chunks) => {
|
|
895
1111
|
isIngesting.set(true);
|
|
896
1112
|
error.set(null);
|
|
897
1113
|
try {
|
|
@@ -900,6 +1116,27 @@ var createRAGIngest = (path) => {
|
|
|
900
1116
|
throw new Error(response.error ?? "RAG ingest failed");
|
|
901
1117
|
}
|
|
902
1118
|
lastIngestCount.set(response.count ?? chunks.length);
|
|
1119
|
+
lastDocumentCount.set(null);
|
|
1120
|
+
lastResponse.set(response);
|
|
1121
|
+
return response;
|
|
1122
|
+
} catch (caught) {
|
|
1123
|
+
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
1124
|
+
throw caught;
|
|
1125
|
+
} finally {
|
|
1126
|
+
isIngesting.set(false);
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const ingestDocuments = async (input) => {
|
|
1130
|
+
isIngesting.set(true);
|
|
1131
|
+
error.set(null);
|
|
1132
|
+
try {
|
|
1133
|
+
const response = await client.ingestDocuments(input);
|
|
1134
|
+
if (!response.ok) {
|
|
1135
|
+
throw new Error(response.error ?? "RAG document ingest failed");
|
|
1136
|
+
}
|
|
1137
|
+
lastDocumentCount.set(response.documentCount ?? input.documents.length);
|
|
1138
|
+
lastIngestCount.set(response.count ?? null);
|
|
1139
|
+
lastResponse.set(response);
|
|
903
1140
|
return response;
|
|
904
1141
|
} catch (caught) {
|
|
905
1142
|
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
@@ -908,26 +1145,140 @@ var createRAGIngest = (path) => {
|
|
|
908
1145
|
isIngesting.set(false);
|
|
909
1146
|
}
|
|
910
1147
|
};
|
|
1148
|
+
const clearIndex = async () => {
|
|
1149
|
+
isIngesting.set(true);
|
|
1150
|
+
error.set(null);
|
|
1151
|
+
try {
|
|
1152
|
+
return await client.clearIndex();
|
|
1153
|
+
} catch (caught) {
|
|
1154
|
+
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
1155
|
+
throw caught;
|
|
1156
|
+
} finally {
|
|
1157
|
+
isIngesting.set(false);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
const reset = () => {
|
|
1161
|
+
error.set(null);
|
|
1162
|
+
isIngesting.set(false);
|
|
1163
|
+
lastDocumentCount.set(null);
|
|
1164
|
+
lastIngestCount.set(null);
|
|
1165
|
+
lastResponse.set(null);
|
|
1166
|
+
};
|
|
911
1167
|
return {
|
|
1168
|
+
clearIndex,
|
|
912
1169
|
error,
|
|
913
|
-
ingest,
|
|
1170
|
+
ingest: ingestChunks,
|
|
1171
|
+
ingestChunks,
|
|
1172
|
+
ingestDocuments,
|
|
914
1173
|
isIngesting,
|
|
915
|
-
|
|
1174
|
+
lastDocumentCount,
|
|
1175
|
+
lastIngestCount,
|
|
1176
|
+
lastResponse,
|
|
1177
|
+
reset
|
|
1178
|
+
};
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// src/svelte/ai/createRAGIndexAdmin.ts
|
|
1182
|
+
import { writable as writable4 } from "svelte/store";
|
|
1183
|
+
var createRAGIndexAdmin = (path) => {
|
|
1184
|
+
const client = createRAGClient({ path });
|
|
1185
|
+
const isLoading = writable4(false);
|
|
1186
|
+
const error = writable4(null);
|
|
1187
|
+
const lastMutation = writable4(null);
|
|
1188
|
+
const backends = writable4(null);
|
|
1189
|
+
const run = async (operation) => {
|
|
1190
|
+
isLoading.set(true);
|
|
1191
|
+
error.set(null);
|
|
1192
|
+
try {
|
|
1193
|
+
return await operation();
|
|
1194
|
+
} catch (caught) {
|
|
1195
|
+
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
1196
|
+
throw caught;
|
|
1197
|
+
} finally {
|
|
1198
|
+
isLoading.set(false);
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
const createDocument = async (input) => run(async () => {
|
|
1202
|
+
const response = await client.createDocument(input);
|
|
1203
|
+
lastMutation.set(response);
|
|
1204
|
+
if (!response.ok) {
|
|
1205
|
+
throw new Error(response.error ?? "Failed to create document");
|
|
1206
|
+
}
|
|
1207
|
+
return response;
|
|
1208
|
+
});
|
|
1209
|
+
const deleteDocument = async (id) => run(async () => {
|
|
1210
|
+
const response = await client.deleteDocument(id);
|
|
1211
|
+
lastMutation.set(response);
|
|
1212
|
+
if (!response.ok) {
|
|
1213
|
+
throw new Error(response.error ?? "Failed to delete document");
|
|
1214
|
+
}
|
|
1215
|
+
return response;
|
|
1216
|
+
});
|
|
1217
|
+
const reseed = async () => run(async () => {
|
|
1218
|
+
const response = await client.reseed();
|
|
1219
|
+
lastMutation.set(response);
|
|
1220
|
+
if (!response.ok) {
|
|
1221
|
+
throw new Error(response.error ?? "Failed to reseed index");
|
|
1222
|
+
}
|
|
1223
|
+
return response;
|
|
1224
|
+
});
|
|
1225
|
+
const reset = async () => run(async () => {
|
|
1226
|
+
const response = await client.reset();
|
|
1227
|
+
lastMutation.set(response);
|
|
1228
|
+
if (!response.ok) {
|
|
1229
|
+
throw new Error(response.error ?? "Failed to reset index");
|
|
1230
|
+
}
|
|
1231
|
+
return response;
|
|
1232
|
+
});
|
|
1233
|
+
const loadBackends = async () => run(async () => {
|
|
1234
|
+
const response = await client.backends();
|
|
1235
|
+
backends.set(response);
|
|
1236
|
+
return response;
|
|
1237
|
+
});
|
|
1238
|
+
const clearIndex = async () => run(async () => {
|
|
1239
|
+
const response = await client.clearIndex();
|
|
1240
|
+
const mutation = { ok: response.ok };
|
|
1241
|
+
lastMutation.set(mutation);
|
|
1242
|
+
return mutation;
|
|
1243
|
+
});
|
|
1244
|
+
const resetState = () => {
|
|
1245
|
+
backends.set(null);
|
|
1246
|
+
error.set(null);
|
|
1247
|
+
isLoading.set(false);
|
|
1248
|
+
lastMutation.set(null);
|
|
1249
|
+
};
|
|
1250
|
+
return {
|
|
1251
|
+
backends,
|
|
1252
|
+
clearIndex,
|
|
1253
|
+
createDocument,
|
|
1254
|
+
deleteDocument,
|
|
1255
|
+
error,
|
|
1256
|
+
isLoading,
|
|
1257
|
+
lastMutation,
|
|
1258
|
+
loadBackends,
|
|
1259
|
+
reseed,
|
|
1260
|
+
reset,
|
|
1261
|
+
resetState
|
|
916
1262
|
};
|
|
917
1263
|
};
|
|
1264
|
+
|
|
918
1265
|
// src/svelte/ai/createRAGSearch.ts
|
|
919
|
-
import { writable as
|
|
1266
|
+
import { writable as writable5 } from "svelte/store";
|
|
920
1267
|
var createRAGSearch = (path) => {
|
|
921
1268
|
const client = createRAGClient({ path });
|
|
922
|
-
const results =
|
|
923
|
-
const error =
|
|
924
|
-
const isSearching =
|
|
1269
|
+
const results = writable5([]);
|
|
1270
|
+
const error = writable5(null);
|
|
1271
|
+
const isSearching = writable5(false);
|
|
1272
|
+
const hasSearched = writable5(false);
|
|
1273
|
+
const lastRequest = writable5(null);
|
|
925
1274
|
const search = async (input) => {
|
|
926
1275
|
isSearching.set(true);
|
|
927
1276
|
error.set(null);
|
|
1277
|
+
lastRequest.set(input);
|
|
928
1278
|
try {
|
|
929
1279
|
const nextResults = await client.search(input);
|
|
930
1280
|
results.set(nextResults);
|
|
1281
|
+
hasSearched.set(true);
|
|
931
1282
|
return nextResults;
|
|
932
1283
|
} catch (caught) {
|
|
933
1284
|
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
@@ -936,21 +1287,47 @@ var createRAGSearch = (path) => {
|
|
|
936
1287
|
isSearching.set(false);
|
|
937
1288
|
}
|
|
938
1289
|
};
|
|
1290
|
+
const reset = () => {
|
|
1291
|
+
error.set(null);
|
|
1292
|
+
hasSearched.set(false);
|
|
1293
|
+
isSearching.set(false);
|
|
1294
|
+
lastRequest.set(null);
|
|
1295
|
+
results.set([]);
|
|
1296
|
+
};
|
|
939
1297
|
return {
|
|
940
1298
|
error,
|
|
1299
|
+
hasSearched,
|
|
941
1300
|
isSearching,
|
|
1301
|
+
lastRequest,
|
|
1302
|
+
reset,
|
|
942
1303
|
results,
|
|
943
1304
|
search
|
|
944
1305
|
};
|
|
945
1306
|
};
|
|
1307
|
+
|
|
1308
|
+
// src/svelte/ai/createRAGSources.ts
|
|
1309
|
+
import { derived as derived2 } from "svelte/store";
|
|
1310
|
+
var createRAGSources = (messages) => {
|
|
1311
|
+
const latestAssistantMessage = derived2(messages, ($messages) => getLatestAssistantMessage($messages));
|
|
1312
|
+
const sources = derived2(messages, ($messages) => getLatestRAGSources($messages));
|
|
1313
|
+
const sourceGroups = derived2(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
1314
|
+
const hasSources = derived2(sources, ($sources) => $sources.length > 0);
|
|
1315
|
+
return {
|
|
1316
|
+
hasSources,
|
|
1317
|
+
latestAssistantMessage,
|
|
1318
|
+
sourceGroups,
|
|
1319
|
+
sources
|
|
1320
|
+
};
|
|
1321
|
+
};
|
|
1322
|
+
|
|
946
1323
|
// src/svelte/ai/createRAGStatus.ts
|
|
947
|
-
import { writable as
|
|
1324
|
+
import { writable as writable6 } from "svelte/store";
|
|
948
1325
|
var createRAGStatus = (path, autoLoad = true) => {
|
|
949
1326
|
const client = createRAGClient({ path });
|
|
950
|
-
const status =
|
|
951
|
-
const capabilities =
|
|
952
|
-
const error =
|
|
953
|
-
const isLoading =
|
|
1327
|
+
const status = writable6(undefined);
|
|
1328
|
+
const capabilities = writable6(undefined);
|
|
1329
|
+
const error = writable6(null);
|
|
1330
|
+
const isLoading = writable6(autoLoad);
|
|
954
1331
|
const refresh = async () => {
|
|
955
1332
|
isLoading.set(true);
|
|
956
1333
|
error.set(null);
|
|
@@ -966,6 +1343,12 @@ var createRAGStatus = (path, autoLoad = true) => {
|
|
|
966
1343
|
isLoading.set(false);
|
|
967
1344
|
}
|
|
968
1345
|
};
|
|
1346
|
+
const reset = () => {
|
|
1347
|
+
capabilities.set(undefined);
|
|
1348
|
+
error.set(null);
|
|
1349
|
+
isLoading.set(false);
|
|
1350
|
+
status.set(undefined);
|
|
1351
|
+
};
|
|
969
1352
|
if (autoLoad) {
|
|
970
1353
|
refresh();
|
|
971
1354
|
} else {
|
|
@@ -976,16 +1359,101 @@ var createRAGStatus = (path, autoLoad = true) => {
|
|
|
976
1359
|
error,
|
|
977
1360
|
isLoading,
|
|
978
1361
|
refresh,
|
|
1362
|
+
reset,
|
|
979
1363
|
status
|
|
980
1364
|
};
|
|
981
1365
|
};
|
|
1366
|
+
|
|
1367
|
+
// src/svelte/ai/createRAGStream.ts
|
|
1368
|
+
import { derived as derived3, readable } from "svelte/store";
|
|
1369
|
+
var createRAGStream = (path, conversationId) => {
|
|
1370
|
+
const stream = createAIStream(path, conversationId);
|
|
1371
|
+
const messages = readable(stream.messages, (set) => {
|
|
1372
|
+
set(stream.messages);
|
|
1373
|
+
return stream.subscribe(() => set(stream.messages));
|
|
1374
|
+
});
|
|
1375
|
+
const error = readable(stream.error, (set) => {
|
|
1376
|
+
set(stream.error);
|
|
1377
|
+
return stream.subscribe(() => set(stream.error));
|
|
1378
|
+
});
|
|
1379
|
+
const isStreaming = readable(stream.isStreaming, (set) => {
|
|
1380
|
+
set(stream.isStreaming);
|
|
1381
|
+
return stream.subscribe(() => set(stream.isStreaming));
|
|
1382
|
+
});
|
|
1383
|
+
const latestAssistantMessage = derived3(messages, ($messages) => getLatestAssistantMessage($messages));
|
|
1384
|
+
const sources = derived3(messages, ($messages) => getLatestRAGSources($messages));
|
|
1385
|
+
const sourceGroups = derived3(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
1386
|
+
const citations = derived3(sources, ($sources) => buildRAGCitations($sources));
|
|
1387
|
+
const retrieval = derived3(messages, ($messages) => buildRAGRetrievedState($messages));
|
|
1388
|
+
const stage = derived3([messages, error, isStreaming], ([$messages, $error, $isStreaming]) => resolveRAGStreamStage({
|
|
1389
|
+
error: $error,
|
|
1390
|
+
isStreaming: $isStreaming,
|
|
1391
|
+
messages: $messages
|
|
1392
|
+
}));
|
|
1393
|
+
const hasRetrieved = derived3(retrieval, ($retrieval) => ($retrieval?.sources.length ?? 0) > 0);
|
|
1394
|
+
const hasSources = derived3(sources, ($sources) => $sources.length > 0);
|
|
1395
|
+
const isRetrieving = derived3(stage, ($stage) => $stage === "submitting" || $stage === "retrieved");
|
|
1396
|
+
const isAnswerStreaming = derived3(stage, ($stage) => $stage === "streaming");
|
|
1397
|
+
const isComplete = derived3(stage, ($stage) => $stage === "complete");
|
|
1398
|
+
const query = (content, attachments) => {
|
|
1399
|
+
stream.send(content, attachments);
|
|
1400
|
+
};
|
|
1401
|
+
return {
|
|
1402
|
+
...stream,
|
|
1403
|
+
citations,
|
|
1404
|
+
error,
|
|
1405
|
+
hasRetrieved,
|
|
1406
|
+
hasSources,
|
|
1407
|
+
isAnswerStreaming,
|
|
1408
|
+
isComplete,
|
|
1409
|
+
isRetrieving,
|
|
1410
|
+
isStreaming,
|
|
1411
|
+
latestAssistantMessage,
|
|
1412
|
+
messages,
|
|
1413
|
+
query,
|
|
1414
|
+
retrieval,
|
|
1415
|
+
sourceGroups,
|
|
1416
|
+
sources,
|
|
1417
|
+
stage
|
|
1418
|
+
};
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
// src/svelte/ai/createRAG.ts
|
|
1422
|
+
var createRAG = (path, options = {}) => {
|
|
1423
|
+
const search = createRAGSearch(path);
|
|
1424
|
+
const ingest = createRAGIngest(path);
|
|
1425
|
+
const status = createRAGStatus(path, options.autoLoadStatus ?? true);
|
|
1426
|
+
const documents = createRAGDocuments(path);
|
|
1427
|
+
const chunkPreview = createRAGChunkPreview(path);
|
|
1428
|
+
const index = createRAGIndexAdmin(path);
|
|
1429
|
+
const stream = createRAGStream(options.streamPath ?? path, options.conversationId);
|
|
1430
|
+
const sources = createRAGSources(stream.messages);
|
|
1431
|
+
const citations = createRAGCitations(sources.sources);
|
|
1432
|
+
return {
|
|
1433
|
+
citations,
|
|
1434
|
+
chunkPreview,
|
|
1435
|
+
documents,
|
|
1436
|
+
ingest,
|
|
1437
|
+
index,
|
|
1438
|
+
search,
|
|
1439
|
+
sources,
|
|
1440
|
+
status,
|
|
1441
|
+
stream
|
|
1442
|
+
};
|
|
1443
|
+
};
|
|
982
1444
|
export {
|
|
983
|
-
|
|
1445
|
+
createRAGStream,
|
|
984
1446
|
createRAGStatus,
|
|
1447
|
+
createRAGSources,
|
|
985
1448
|
createRAGSearch,
|
|
986
1449
|
createRAGIngest,
|
|
1450
|
+
createRAGIndexAdmin,
|
|
1451
|
+
createRAGDocuments,
|
|
1452
|
+
createRAGCitations,
|
|
1453
|
+
createRAGChunkPreview,
|
|
1454
|
+
createRAG,
|
|
987
1455
|
createAIStream
|
|
988
1456
|
};
|
|
989
1457
|
|
|
990
|
-
//# debugId=
|
|
1458
|
+
//# debugId=B44067D7D4FBEF1464756E2164756E21
|
|
991
1459
|
//# sourceMappingURL=index.js.map
|