@anuma/sdk 3.0.0 → 3.1.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/dist/expo/{chunk-IY7NNIYM.mjs → chunk-22CSPJLL.mjs} +16 -850
- package/dist/expo/index.cjs +1663 -1071
- package/dist/expo/index.d.mts +179 -10
- package/dist/expo/index.d.ts +179 -10
- package/dist/expo/index.mjs +1556 -68
- package/dist/expo/{recall-DJ5LD5WJ.mjs → recall-LICO3TJ7.mjs} +1 -1
- package/dist/index.cjs +415 -394
- package/dist/index.mjs +412 -391
- package/dist/react/{chunk-OSDVRDLI.mjs → chunk-FD5MB73N.mjs} +8 -987
- package/dist/react/index.cjs +1687 -1712
- package/dist/react/index.d.mts +103 -12
- package/dist/react/index.d.ts +103 -12
- package/dist/react/index.mjs +1209 -219
- package/dist/react/{recall-3BDCIEQF.mjs → recall-FPACUZGD.mjs} +1 -1
- package/dist/server/{chunk-QQOIC37O.mjs → chunk-RKUNGNBF.mjs} +7 -817
- package/dist/server/index.cjs +223 -941
- package/dist/server/index.d.mts +95 -12
- package/dist/server/index.d.ts +95 -12
- package/dist/server/index.mjs +182 -23
- package/dist/server/{recall-6QLUEYB7.mjs → recall-WT5HY2IA.mjs} +1 -1
- package/dist/tools/selection/chunk-4ETHWSXJ.mjs +25 -0
- package/dist/tools/selection/clientConfig-WITO4T6L.mjs +12 -0
- package/dist/tools/selection/index.cjs +1977 -0
- package/dist/tools/selection/index.d.mts +1380 -0
- package/dist/tools/selection/index.d.ts +1380 -0
- package/dist/tools/selection/index.mjs +1859 -0
- package/package.json +8 -1
package/dist/server/index.cjs
CHANGED
|
@@ -17729,896 +17729,6 @@ var init_chunking = __esm({
|
|
|
17729
17729
|
}
|
|
17730
17730
|
});
|
|
17731
17731
|
|
|
17732
|
-
// src/client/core/bodySerializer.gen.ts
|
|
17733
|
-
var jsonBodySerializer;
|
|
17734
|
-
var init_bodySerializer_gen = __esm({
|
|
17735
|
-
"src/client/core/bodySerializer.gen.ts"() {
|
|
17736
|
-
"use strict";
|
|
17737
|
-
jsonBodySerializer = {
|
|
17738
|
-
bodySerializer: (body) => JSON.stringify(
|
|
17739
|
-
body,
|
|
17740
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
17741
|
-
)
|
|
17742
|
-
};
|
|
17743
|
-
}
|
|
17744
|
-
});
|
|
17745
|
-
|
|
17746
|
-
// src/client/core/serverSentEvents.gen.ts
|
|
17747
|
-
var createSseClient;
|
|
17748
|
-
var init_serverSentEvents_gen = __esm({
|
|
17749
|
-
"src/client/core/serverSentEvents.gen.ts"() {
|
|
17750
|
-
"use strict";
|
|
17751
|
-
createSseClient = ({
|
|
17752
|
-
onRequest,
|
|
17753
|
-
onSseError,
|
|
17754
|
-
onSseEvent,
|
|
17755
|
-
responseTransformer,
|
|
17756
|
-
responseValidator,
|
|
17757
|
-
sseDefaultRetryDelay,
|
|
17758
|
-
sseMaxRetryAttempts,
|
|
17759
|
-
sseMaxRetryDelay,
|
|
17760
|
-
sseSleepFn,
|
|
17761
|
-
url,
|
|
17762
|
-
...options
|
|
17763
|
-
}) => {
|
|
17764
|
-
let lastEventId;
|
|
17765
|
-
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
17766
|
-
const createStream = async function* () {
|
|
17767
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
17768
|
-
let attempt = 0;
|
|
17769
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
17770
|
-
while (true) {
|
|
17771
|
-
if (signal.aborted) break;
|
|
17772
|
-
attempt++;
|
|
17773
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
17774
|
-
if (lastEventId !== void 0) {
|
|
17775
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
17776
|
-
}
|
|
17777
|
-
try {
|
|
17778
|
-
const requestInit = {
|
|
17779
|
-
redirect: "follow",
|
|
17780
|
-
...options,
|
|
17781
|
-
body: options.serializedBody,
|
|
17782
|
-
headers,
|
|
17783
|
-
signal
|
|
17784
|
-
};
|
|
17785
|
-
let request = new Request(url, requestInit);
|
|
17786
|
-
if (onRequest) {
|
|
17787
|
-
request = await onRequest(url, requestInit);
|
|
17788
|
-
}
|
|
17789
|
-
const _fetch = options.fetch ?? globalThis.fetch;
|
|
17790
|
-
const response = await _fetch(request);
|
|
17791
|
-
if (!response.ok)
|
|
17792
|
-
throw new Error(
|
|
17793
|
-
`SSE failed: ${response.status} ${response.statusText}`
|
|
17794
|
-
);
|
|
17795
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
17796
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
17797
|
-
let buffer = "";
|
|
17798
|
-
const abortHandler = () => {
|
|
17799
|
-
try {
|
|
17800
|
-
reader.cancel();
|
|
17801
|
-
} catch {
|
|
17802
|
-
}
|
|
17803
|
-
};
|
|
17804
|
-
signal.addEventListener("abort", abortHandler);
|
|
17805
|
-
try {
|
|
17806
|
-
while (true) {
|
|
17807
|
-
const { done, value } = await reader.read();
|
|
17808
|
-
if (done) break;
|
|
17809
|
-
buffer += value;
|
|
17810
|
-
const chunks = buffer.split("\n\n");
|
|
17811
|
-
buffer = chunks.pop() ?? "";
|
|
17812
|
-
for (const chunk of chunks) {
|
|
17813
|
-
const lines = chunk.split("\n");
|
|
17814
|
-
const dataLines = [];
|
|
17815
|
-
let eventName;
|
|
17816
|
-
for (const line of lines) {
|
|
17817
|
-
if (line.startsWith("data:")) {
|
|
17818
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
17819
|
-
} else if (line.startsWith("event:")) {
|
|
17820
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
17821
|
-
} else if (line.startsWith("id:")) {
|
|
17822
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
17823
|
-
} else if (line.startsWith("retry:")) {
|
|
17824
|
-
const parsed = Number.parseInt(
|
|
17825
|
-
line.replace(/^retry:\s*/, ""),
|
|
17826
|
-
10
|
|
17827
|
-
);
|
|
17828
|
-
if (!Number.isNaN(parsed)) {
|
|
17829
|
-
retryDelay = parsed;
|
|
17830
|
-
}
|
|
17831
|
-
}
|
|
17832
|
-
}
|
|
17833
|
-
let data;
|
|
17834
|
-
let parsedJson = false;
|
|
17835
|
-
if (dataLines.length) {
|
|
17836
|
-
const rawData = dataLines.join("\n");
|
|
17837
|
-
try {
|
|
17838
|
-
data = JSON.parse(rawData);
|
|
17839
|
-
parsedJson = true;
|
|
17840
|
-
} catch {
|
|
17841
|
-
data = rawData;
|
|
17842
|
-
}
|
|
17843
|
-
}
|
|
17844
|
-
if (parsedJson) {
|
|
17845
|
-
if (responseValidator) {
|
|
17846
|
-
await responseValidator(data);
|
|
17847
|
-
}
|
|
17848
|
-
if (responseTransformer) {
|
|
17849
|
-
data = await responseTransformer(data);
|
|
17850
|
-
}
|
|
17851
|
-
}
|
|
17852
|
-
onSseEvent?.({
|
|
17853
|
-
data,
|
|
17854
|
-
event: eventName,
|
|
17855
|
-
id: lastEventId,
|
|
17856
|
-
retry: retryDelay
|
|
17857
|
-
});
|
|
17858
|
-
if (dataLines.length) {
|
|
17859
|
-
yield data;
|
|
17860
|
-
}
|
|
17861
|
-
}
|
|
17862
|
-
}
|
|
17863
|
-
} finally {
|
|
17864
|
-
signal.removeEventListener("abort", abortHandler);
|
|
17865
|
-
reader.releaseLock();
|
|
17866
|
-
}
|
|
17867
|
-
break;
|
|
17868
|
-
} catch (error) {
|
|
17869
|
-
onSseError?.(error);
|
|
17870
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
17871
|
-
break;
|
|
17872
|
-
}
|
|
17873
|
-
const backoff = Math.min(
|
|
17874
|
-
retryDelay * 2 ** (attempt - 1),
|
|
17875
|
-
sseMaxRetryDelay ?? 3e4
|
|
17876
|
-
);
|
|
17877
|
-
await sleep4(backoff);
|
|
17878
|
-
}
|
|
17879
|
-
}
|
|
17880
|
-
};
|
|
17881
|
-
const stream = createStream();
|
|
17882
|
-
return { stream };
|
|
17883
|
-
};
|
|
17884
|
-
}
|
|
17885
|
-
});
|
|
17886
|
-
|
|
17887
|
-
// src/client/core/pathSerializer.gen.ts
|
|
17888
|
-
var separatorArrayExplode, separatorArrayNoExplode, separatorObjectExplode, serializeArrayParam, serializePrimitiveParam, serializeObjectParam;
|
|
17889
|
-
var init_pathSerializer_gen = __esm({
|
|
17890
|
-
"src/client/core/pathSerializer.gen.ts"() {
|
|
17891
|
-
"use strict";
|
|
17892
|
-
separatorArrayExplode = (style) => {
|
|
17893
|
-
switch (style) {
|
|
17894
|
-
case "label":
|
|
17895
|
-
return ".";
|
|
17896
|
-
case "matrix":
|
|
17897
|
-
return ";";
|
|
17898
|
-
case "simple":
|
|
17899
|
-
return ",";
|
|
17900
|
-
default:
|
|
17901
|
-
return "&";
|
|
17902
|
-
}
|
|
17903
|
-
};
|
|
17904
|
-
separatorArrayNoExplode = (style) => {
|
|
17905
|
-
switch (style) {
|
|
17906
|
-
case "form":
|
|
17907
|
-
return ",";
|
|
17908
|
-
case "pipeDelimited":
|
|
17909
|
-
return "|";
|
|
17910
|
-
case "spaceDelimited":
|
|
17911
|
-
return "%20";
|
|
17912
|
-
default:
|
|
17913
|
-
return ",";
|
|
17914
|
-
}
|
|
17915
|
-
};
|
|
17916
|
-
separatorObjectExplode = (style) => {
|
|
17917
|
-
switch (style) {
|
|
17918
|
-
case "label":
|
|
17919
|
-
return ".";
|
|
17920
|
-
case "matrix":
|
|
17921
|
-
return ";";
|
|
17922
|
-
case "simple":
|
|
17923
|
-
return ",";
|
|
17924
|
-
default:
|
|
17925
|
-
return "&";
|
|
17926
|
-
}
|
|
17927
|
-
};
|
|
17928
|
-
serializeArrayParam = ({
|
|
17929
|
-
allowReserved,
|
|
17930
|
-
explode,
|
|
17931
|
-
name,
|
|
17932
|
-
style,
|
|
17933
|
-
value
|
|
17934
|
-
}) => {
|
|
17935
|
-
if (!explode) {
|
|
17936
|
-
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
17937
|
-
switch (style) {
|
|
17938
|
-
case "label":
|
|
17939
|
-
return `.${joinedValues2}`;
|
|
17940
|
-
case "matrix":
|
|
17941
|
-
return `;${name}=${joinedValues2}`;
|
|
17942
|
-
case "simple":
|
|
17943
|
-
return joinedValues2;
|
|
17944
|
-
default:
|
|
17945
|
-
return `${name}=${joinedValues2}`;
|
|
17946
|
-
}
|
|
17947
|
-
}
|
|
17948
|
-
const separator = separatorArrayExplode(style);
|
|
17949
|
-
const joinedValues = value.map((v) => {
|
|
17950
|
-
if (style === "label" || style === "simple") {
|
|
17951
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
17952
|
-
}
|
|
17953
|
-
return serializePrimitiveParam({
|
|
17954
|
-
allowReserved,
|
|
17955
|
-
name,
|
|
17956
|
-
value: v
|
|
17957
|
-
});
|
|
17958
|
-
}).join(separator);
|
|
17959
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
17960
|
-
};
|
|
17961
|
-
serializePrimitiveParam = ({
|
|
17962
|
-
allowReserved,
|
|
17963
|
-
name,
|
|
17964
|
-
value
|
|
17965
|
-
}) => {
|
|
17966
|
-
if (value === void 0 || value === null) {
|
|
17967
|
-
return "";
|
|
17968
|
-
}
|
|
17969
|
-
if (typeof value === "object") {
|
|
17970
|
-
throw new Error(
|
|
17971
|
-
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
17972
|
-
);
|
|
17973
|
-
}
|
|
17974
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
17975
|
-
};
|
|
17976
|
-
serializeObjectParam = ({
|
|
17977
|
-
allowReserved,
|
|
17978
|
-
explode,
|
|
17979
|
-
name,
|
|
17980
|
-
style,
|
|
17981
|
-
value,
|
|
17982
|
-
valueOnly
|
|
17983
|
-
}) => {
|
|
17984
|
-
if (value instanceof Date) {
|
|
17985
|
-
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
17986
|
-
}
|
|
17987
|
-
if (style !== "deepObject" && !explode) {
|
|
17988
|
-
let values = [];
|
|
17989
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
17990
|
-
values = [
|
|
17991
|
-
...values,
|
|
17992
|
-
key,
|
|
17993
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
17994
|
-
];
|
|
17995
|
-
});
|
|
17996
|
-
const joinedValues2 = values.join(",");
|
|
17997
|
-
switch (style) {
|
|
17998
|
-
case "form":
|
|
17999
|
-
return `${name}=${joinedValues2}`;
|
|
18000
|
-
case "label":
|
|
18001
|
-
return `.${joinedValues2}`;
|
|
18002
|
-
case "matrix":
|
|
18003
|
-
return `;${name}=${joinedValues2}`;
|
|
18004
|
-
default:
|
|
18005
|
-
return joinedValues2;
|
|
18006
|
-
}
|
|
18007
|
-
}
|
|
18008
|
-
const separator = separatorObjectExplode(style);
|
|
18009
|
-
const joinedValues = Object.entries(value).map(
|
|
18010
|
-
([key, v]) => serializePrimitiveParam({
|
|
18011
|
-
allowReserved,
|
|
18012
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
18013
|
-
value: v
|
|
18014
|
-
})
|
|
18015
|
-
).join(separator);
|
|
18016
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
18017
|
-
};
|
|
18018
|
-
}
|
|
18019
|
-
});
|
|
18020
|
-
|
|
18021
|
-
// src/client/core/utils.gen.ts
|
|
18022
|
-
function getValidRequestBody(options) {
|
|
18023
|
-
const hasBody = options.body !== void 0;
|
|
18024
|
-
const isSerializedBody = hasBody && options.bodySerializer;
|
|
18025
|
-
if (isSerializedBody) {
|
|
18026
|
-
if ("serializedBody" in options) {
|
|
18027
|
-
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
18028
|
-
return hasSerializedBody ? options.serializedBody : null;
|
|
18029
|
-
}
|
|
18030
|
-
return options.body !== "" ? options.body : null;
|
|
18031
|
-
}
|
|
18032
|
-
if (hasBody) {
|
|
18033
|
-
return options.body;
|
|
18034
|
-
}
|
|
18035
|
-
return void 0;
|
|
18036
|
-
}
|
|
18037
|
-
var init_utils_gen = __esm({
|
|
18038
|
-
"src/client/core/utils.gen.ts"() {
|
|
18039
|
-
"use strict";
|
|
18040
|
-
}
|
|
18041
|
-
});
|
|
18042
|
-
|
|
18043
|
-
// src/client/core/auth.gen.ts
|
|
18044
|
-
var getAuthToken;
|
|
18045
|
-
var init_auth_gen = __esm({
|
|
18046
|
-
"src/client/core/auth.gen.ts"() {
|
|
18047
|
-
"use strict";
|
|
18048
|
-
getAuthToken = async (auth, callback) => {
|
|
18049
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
18050
|
-
if (!token) {
|
|
18051
|
-
return;
|
|
18052
|
-
}
|
|
18053
|
-
if (auth.scheme === "bearer") {
|
|
18054
|
-
return `Bearer ${token}`;
|
|
18055
|
-
}
|
|
18056
|
-
if (auth.scheme === "basic") {
|
|
18057
|
-
return `Basic ${btoa(token)}`;
|
|
18058
|
-
}
|
|
18059
|
-
return token;
|
|
18060
|
-
};
|
|
18061
|
-
}
|
|
18062
|
-
});
|
|
18063
|
-
|
|
18064
|
-
// src/client/client/utils.gen.ts
|
|
18065
|
-
var PATH_PARAM_RE, defaultPathSerializer, createQuerySerializer, getParseAs, checkForExistence, setAuthParams, buildUrl, getUrl, mergeConfigs, headersEntries, mergeHeaders, Interceptors, createInterceptors, defaultQuerySerializer, defaultHeaders, createConfig;
|
|
18066
|
-
var init_utils_gen2 = __esm({
|
|
18067
|
-
"src/client/client/utils.gen.ts"() {
|
|
18068
|
-
"use strict";
|
|
18069
|
-
init_auth_gen();
|
|
18070
|
-
init_bodySerializer_gen();
|
|
18071
|
-
init_pathSerializer_gen();
|
|
18072
|
-
PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
18073
|
-
defaultPathSerializer = ({ path, url: _url }) => {
|
|
18074
|
-
let url = _url;
|
|
18075
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
18076
|
-
if (matches) {
|
|
18077
|
-
for (const match of matches) {
|
|
18078
|
-
let explode = false;
|
|
18079
|
-
let name = match.substring(1, match.length - 1);
|
|
18080
|
-
let style = "simple";
|
|
18081
|
-
if (name.endsWith("*")) {
|
|
18082
|
-
explode = true;
|
|
18083
|
-
name = name.substring(0, name.length - 1);
|
|
18084
|
-
}
|
|
18085
|
-
if (name.startsWith(".")) {
|
|
18086
|
-
name = name.substring(1);
|
|
18087
|
-
style = "label";
|
|
18088
|
-
} else if (name.startsWith(";")) {
|
|
18089
|
-
name = name.substring(1);
|
|
18090
|
-
style = "matrix";
|
|
18091
|
-
}
|
|
18092
|
-
const value = path[name];
|
|
18093
|
-
if (value === void 0 || value === null) {
|
|
18094
|
-
continue;
|
|
18095
|
-
}
|
|
18096
|
-
if (Array.isArray(value)) {
|
|
18097
|
-
url = url.replace(
|
|
18098
|
-
match,
|
|
18099
|
-
serializeArrayParam({ explode, name, style, value })
|
|
18100
|
-
);
|
|
18101
|
-
continue;
|
|
18102
|
-
}
|
|
18103
|
-
if (typeof value === "object") {
|
|
18104
|
-
url = url.replace(
|
|
18105
|
-
match,
|
|
18106
|
-
serializeObjectParam({
|
|
18107
|
-
explode,
|
|
18108
|
-
name,
|
|
18109
|
-
style,
|
|
18110
|
-
value,
|
|
18111
|
-
valueOnly: true
|
|
18112
|
-
})
|
|
18113
|
-
);
|
|
18114
|
-
continue;
|
|
18115
|
-
}
|
|
18116
|
-
if (style === "matrix") {
|
|
18117
|
-
url = url.replace(
|
|
18118
|
-
match,
|
|
18119
|
-
`;${serializePrimitiveParam({
|
|
18120
|
-
name,
|
|
18121
|
-
value
|
|
18122
|
-
})}`
|
|
18123
|
-
);
|
|
18124
|
-
continue;
|
|
18125
|
-
}
|
|
18126
|
-
const replaceValue = encodeURIComponent(
|
|
18127
|
-
style === "label" ? `.${value}` : value
|
|
18128
|
-
);
|
|
18129
|
-
url = url.replace(match, replaceValue);
|
|
18130
|
-
}
|
|
18131
|
-
}
|
|
18132
|
-
return url;
|
|
18133
|
-
};
|
|
18134
|
-
createQuerySerializer = ({
|
|
18135
|
-
parameters = {},
|
|
18136
|
-
...args
|
|
18137
|
-
} = {}) => {
|
|
18138
|
-
const querySerializer = (queryParams) => {
|
|
18139
|
-
const search = [];
|
|
18140
|
-
if (queryParams && typeof queryParams === "object") {
|
|
18141
|
-
for (const name in queryParams) {
|
|
18142
|
-
const value = queryParams[name];
|
|
18143
|
-
if (value === void 0 || value === null) {
|
|
18144
|
-
continue;
|
|
18145
|
-
}
|
|
18146
|
-
const options = parameters[name] || args;
|
|
18147
|
-
if (Array.isArray(value)) {
|
|
18148
|
-
const serializedArray = serializeArrayParam({
|
|
18149
|
-
allowReserved: options.allowReserved,
|
|
18150
|
-
explode: true,
|
|
18151
|
-
name,
|
|
18152
|
-
style: "form",
|
|
18153
|
-
value,
|
|
18154
|
-
...options.array
|
|
18155
|
-
});
|
|
18156
|
-
if (serializedArray) search.push(serializedArray);
|
|
18157
|
-
} else if (typeof value === "object") {
|
|
18158
|
-
const serializedObject = serializeObjectParam({
|
|
18159
|
-
allowReserved: options.allowReserved,
|
|
18160
|
-
explode: true,
|
|
18161
|
-
name,
|
|
18162
|
-
style: "deepObject",
|
|
18163
|
-
value,
|
|
18164
|
-
...options.object
|
|
18165
|
-
});
|
|
18166
|
-
if (serializedObject) search.push(serializedObject);
|
|
18167
|
-
} else {
|
|
18168
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
18169
|
-
allowReserved: options.allowReserved,
|
|
18170
|
-
name,
|
|
18171
|
-
value
|
|
18172
|
-
});
|
|
18173
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
18174
|
-
}
|
|
18175
|
-
}
|
|
18176
|
-
}
|
|
18177
|
-
return search.join("&");
|
|
18178
|
-
};
|
|
18179
|
-
return querySerializer;
|
|
18180
|
-
};
|
|
18181
|
-
getParseAs = (contentType) => {
|
|
18182
|
-
if (!contentType) {
|
|
18183
|
-
return "stream";
|
|
18184
|
-
}
|
|
18185
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
18186
|
-
if (!cleanContent) {
|
|
18187
|
-
return;
|
|
18188
|
-
}
|
|
18189
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
18190
|
-
return "json";
|
|
18191
|
-
}
|
|
18192
|
-
if (cleanContent === "multipart/form-data") {
|
|
18193
|
-
return "formData";
|
|
18194
|
-
}
|
|
18195
|
-
if (["application/", "audio/", "image/", "video/"].some(
|
|
18196
|
-
(type) => cleanContent.startsWith(type)
|
|
18197
|
-
)) {
|
|
18198
|
-
return "blob";
|
|
18199
|
-
}
|
|
18200
|
-
if (cleanContent.startsWith("text/")) {
|
|
18201
|
-
return "text";
|
|
18202
|
-
}
|
|
18203
|
-
return;
|
|
18204
|
-
};
|
|
18205
|
-
checkForExistence = (options, name) => {
|
|
18206
|
-
if (!name) {
|
|
18207
|
-
return false;
|
|
18208
|
-
}
|
|
18209
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
18210
|
-
return true;
|
|
18211
|
-
}
|
|
18212
|
-
return false;
|
|
18213
|
-
};
|
|
18214
|
-
setAuthParams = async ({
|
|
18215
|
-
security,
|
|
18216
|
-
...options
|
|
18217
|
-
}) => {
|
|
18218
|
-
for (const auth of security) {
|
|
18219
|
-
if (checkForExistence(options, auth.name)) {
|
|
18220
|
-
continue;
|
|
18221
|
-
}
|
|
18222
|
-
const token = await getAuthToken(auth, options.auth);
|
|
18223
|
-
if (!token) {
|
|
18224
|
-
continue;
|
|
18225
|
-
}
|
|
18226
|
-
const name = auth.name ?? "Authorization";
|
|
18227
|
-
switch (auth.in) {
|
|
18228
|
-
case "query":
|
|
18229
|
-
if (!options.query) {
|
|
18230
|
-
options.query = {};
|
|
18231
|
-
}
|
|
18232
|
-
options.query[name] = token;
|
|
18233
|
-
break;
|
|
18234
|
-
case "cookie":
|
|
18235
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
18236
|
-
break;
|
|
18237
|
-
case "header":
|
|
18238
|
-
default:
|
|
18239
|
-
options.headers.set(name, token);
|
|
18240
|
-
break;
|
|
18241
|
-
}
|
|
18242
|
-
}
|
|
18243
|
-
};
|
|
18244
|
-
buildUrl = (options) => {
|
|
18245
|
-
const url = getUrl({
|
|
18246
|
-
baseUrl: options.baseUrl,
|
|
18247
|
-
path: options.path,
|
|
18248
|
-
query: options.query,
|
|
18249
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
18250
|
-
url: options.url
|
|
18251
|
-
});
|
|
18252
|
-
return url;
|
|
18253
|
-
};
|
|
18254
|
-
getUrl = ({
|
|
18255
|
-
baseUrl,
|
|
18256
|
-
path,
|
|
18257
|
-
query,
|
|
18258
|
-
querySerializer,
|
|
18259
|
-
url: _url
|
|
18260
|
-
}) => {
|
|
18261
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
18262
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
18263
|
-
if (path) {
|
|
18264
|
-
url = defaultPathSerializer({ path, url });
|
|
18265
|
-
}
|
|
18266
|
-
let search = query ? querySerializer(query) : "";
|
|
18267
|
-
if (search.startsWith("?")) {
|
|
18268
|
-
search = search.substring(1);
|
|
18269
|
-
}
|
|
18270
|
-
if (search) {
|
|
18271
|
-
url += `?${search}`;
|
|
18272
|
-
}
|
|
18273
|
-
return url;
|
|
18274
|
-
};
|
|
18275
|
-
mergeConfigs = (a, b) => {
|
|
18276
|
-
const config = { ...a, ...b };
|
|
18277
|
-
if (config.baseUrl?.endsWith("/")) {
|
|
18278
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
18279
|
-
}
|
|
18280
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
18281
|
-
return config;
|
|
18282
|
-
};
|
|
18283
|
-
headersEntries = (headers) => {
|
|
18284
|
-
const entries = [];
|
|
18285
|
-
headers.forEach((value, key) => {
|
|
18286
|
-
entries.push([key, value]);
|
|
18287
|
-
});
|
|
18288
|
-
return entries;
|
|
18289
|
-
};
|
|
18290
|
-
mergeHeaders = (...headers) => {
|
|
18291
|
-
const mergedHeaders = new Headers();
|
|
18292
|
-
for (const header of headers) {
|
|
18293
|
-
if (!header || typeof header !== "object") {
|
|
18294
|
-
continue;
|
|
18295
|
-
}
|
|
18296
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
18297
|
-
for (const [key, value] of iterator) {
|
|
18298
|
-
if (value === null) {
|
|
18299
|
-
mergedHeaders.delete(key);
|
|
18300
|
-
} else if (Array.isArray(value)) {
|
|
18301
|
-
for (const v of value) {
|
|
18302
|
-
mergedHeaders.append(key, v);
|
|
18303
|
-
}
|
|
18304
|
-
} else if (value !== void 0) {
|
|
18305
|
-
mergedHeaders.set(
|
|
18306
|
-
key,
|
|
18307
|
-
typeof value === "object" ? JSON.stringify(value) : value
|
|
18308
|
-
);
|
|
18309
|
-
}
|
|
18310
|
-
}
|
|
18311
|
-
}
|
|
18312
|
-
return mergedHeaders;
|
|
18313
|
-
};
|
|
18314
|
-
Interceptors = class {
|
|
18315
|
-
constructor() {
|
|
18316
|
-
this.fns = [];
|
|
18317
|
-
}
|
|
18318
|
-
clear() {
|
|
18319
|
-
this.fns = [];
|
|
18320
|
-
}
|
|
18321
|
-
eject(id) {
|
|
18322
|
-
const index = this.getInterceptorIndex(id);
|
|
18323
|
-
if (this.fns[index]) {
|
|
18324
|
-
this.fns[index] = null;
|
|
18325
|
-
}
|
|
18326
|
-
}
|
|
18327
|
-
exists(id) {
|
|
18328
|
-
const index = this.getInterceptorIndex(id);
|
|
18329
|
-
return Boolean(this.fns[index]);
|
|
18330
|
-
}
|
|
18331
|
-
getInterceptorIndex(id) {
|
|
18332
|
-
if (typeof id === "number") {
|
|
18333
|
-
return this.fns[id] ? id : -1;
|
|
18334
|
-
}
|
|
18335
|
-
return this.fns.indexOf(id);
|
|
18336
|
-
}
|
|
18337
|
-
update(id, fn) {
|
|
18338
|
-
const index = this.getInterceptorIndex(id);
|
|
18339
|
-
if (this.fns[index]) {
|
|
18340
|
-
this.fns[index] = fn;
|
|
18341
|
-
return id;
|
|
18342
|
-
}
|
|
18343
|
-
return false;
|
|
18344
|
-
}
|
|
18345
|
-
use(fn) {
|
|
18346
|
-
this.fns.push(fn);
|
|
18347
|
-
return this.fns.length - 1;
|
|
18348
|
-
}
|
|
18349
|
-
};
|
|
18350
|
-
createInterceptors = () => ({
|
|
18351
|
-
error: new Interceptors(),
|
|
18352
|
-
request: new Interceptors(),
|
|
18353
|
-
response: new Interceptors()
|
|
18354
|
-
});
|
|
18355
|
-
defaultQuerySerializer = createQuerySerializer({
|
|
18356
|
-
allowReserved: false,
|
|
18357
|
-
array: {
|
|
18358
|
-
explode: true,
|
|
18359
|
-
style: "form"
|
|
18360
|
-
},
|
|
18361
|
-
object: {
|
|
18362
|
-
explode: true,
|
|
18363
|
-
style: "deepObject"
|
|
18364
|
-
}
|
|
18365
|
-
});
|
|
18366
|
-
defaultHeaders = {
|
|
18367
|
-
"Content-Type": "application/json"
|
|
18368
|
-
};
|
|
18369
|
-
createConfig = (override = {}) => ({
|
|
18370
|
-
...jsonBodySerializer,
|
|
18371
|
-
headers: defaultHeaders,
|
|
18372
|
-
parseAs: "auto",
|
|
18373
|
-
querySerializer: defaultQuerySerializer,
|
|
18374
|
-
...override
|
|
18375
|
-
});
|
|
18376
|
-
}
|
|
18377
|
-
});
|
|
18378
|
-
|
|
18379
|
-
// src/client/client/client.gen.ts
|
|
18380
|
-
var createClient;
|
|
18381
|
-
var init_client_gen = __esm({
|
|
18382
|
-
"src/client/client/client.gen.ts"() {
|
|
18383
|
-
"use strict";
|
|
18384
|
-
init_serverSentEvents_gen();
|
|
18385
|
-
init_utils_gen();
|
|
18386
|
-
init_utils_gen2();
|
|
18387
|
-
createClient = (config = {}) => {
|
|
18388
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
18389
|
-
const getConfig = () => ({ ..._config });
|
|
18390
|
-
const setConfig = (config2) => {
|
|
18391
|
-
_config = mergeConfigs(_config, config2);
|
|
18392
|
-
return getConfig();
|
|
18393
|
-
};
|
|
18394
|
-
const interceptors = createInterceptors();
|
|
18395
|
-
const beforeRequest = async (options) => {
|
|
18396
|
-
const opts = {
|
|
18397
|
-
..._config,
|
|
18398
|
-
...options,
|
|
18399
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18400
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
18401
|
-
serializedBody: void 0
|
|
18402
|
-
};
|
|
18403
|
-
if (opts.security) {
|
|
18404
|
-
await setAuthParams({
|
|
18405
|
-
...opts,
|
|
18406
|
-
security: opts.security
|
|
18407
|
-
});
|
|
18408
|
-
}
|
|
18409
|
-
if (opts.requestValidator) {
|
|
18410
|
-
await opts.requestValidator(opts);
|
|
18411
|
-
}
|
|
18412
|
-
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
18413
|
-
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
18414
|
-
}
|
|
18415
|
-
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
18416
|
-
opts.headers.delete("Content-Type");
|
|
18417
|
-
}
|
|
18418
|
-
const url = buildUrl(opts);
|
|
18419
|
-
return { opts, url };
|
|
18420
|
-
};
|
|
18421
|
-
const request = async (options) => {
|
|
18422
|
-
const { opts, url } = await beforeRequest(options);
|
|
18423
|
-
for (const fn of interceptors.request.fns) {
|
|
18424
|
-
if (fn) {
|
|
18425
|
-
await fn(opts);
|
|
18426
|
-
}
|
|
18427
|
-
}
|
|
18428
|
-
const _fetch = opts.fetch;
|
|
18429
|
-
const requestInit = {
|
|
18430
|
-
...opts,
|
|
18431
|
-
body: getValidRequestBody(opts)
|
|
18432
|
-
};
|
|
18433
|
-
let response = await _fetch(url, requestInit);
|
|
18434
|
-
for (const fn of interceptors.response.fns) {
|
|
18435
|
-
if (fn) {
|
|
18436
|
-
response = await fn(response, opts);
|
|
18437
|
-
}
|
|
18438
|
-
}
|
|
18439
|
-
const result = {
|
|
18440
|
-
response
|
|
18441
|
-
};
|
|
18442
|
-
if (response.ok) {
|
|
18443
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
18444
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
18445
|
-
let emptyData;
|
|
18446
|
-
switch (parseAs) {
|
|
18447
|
-
case "arrayBuffer":
|
|
18448
|
-
case "blob":
|
|
18449
|
-
case "text":
|
|
18450
|
-
emptyData = await response[parseAs]();
|
|
18451
|
-
break;
|
|
18452
|
-
case "formData":
|
|
18453
|
-
emptyData = new FormData();
|
|
18454
|
-
break;
|
|
18455
|
-
case "stream":
|
|
18456
|
-
emptyData = response.body;
|
|
18457
|
-
break;
|
|
18458
|
-
case "json":
|
|
18459
|
-
default:
|
|
18460
|
-
emptyData = {};
|
|
18461
|
-
break;
|
|
18462
|
-
}
|
|
18463
|
-
return {
|
|
18464
|
-
data: emptyData,
|
|
18465
|
-
...result
|
|
18466
|
-
};
|
|
18467
|
-
}
|
|
18468
|
-
let data;
|
|
18469
|
-
switch (parseAs) {
|
|
18470
|
-
case "arrayBuffer":
|
|
18471
|
-
case "blob":
|
|
18472
|
-
case "formData":
|
|
18473
|
-
case "json":
|
|
18474
|
-
case "text":
|
|
18475
|
-
data = await response[parseAs]();
|
|
18476
|
-
break;
|
|
18477
|
-
case "stream":
|
|
18478
|
-
return {
|
|
18479
|
-
data: response.body,
|
|
18480
|
-
...result
|
|
18481
|
-
};
|
|
18482
|
-
}
|
|
18483
|
-
if (parseAs === "json") {
|
|
18484
|
-
if (opts.responseValidator) {
|
|
18485
|
-
await opts.responseValidator(data);
|
|
18486
|
-
}
|
|
18487
|
-
if (opts.responseTransformer) {
|
|
18488
|
-
data = await opts.responseTransformer(data);
|
|
18489
|
-
}
|
|
18490
|
-
}
|
|
18491
|
-
return {
|
|
18492
|
-
data,
|
|
18493
|
-
...result
|
|
18494
|
-
};
|
|
18495
|
-
}
|
|
18496
|
-
const textError = await response.text();
|
|
18497
|
-
let jsonError;
|
|
18498
|
-
try {
|
|
18499
|
-
jsonError = JSON.parse(textError);
|
|
18500
|
-
} catch {
|
|
18501
|
-
}
|
|
18502
|
-
const error = jsonError ?? textError;
|
|
18503
|
-
let finalError = error;
|
|
18504
|
-
for (const fn of interceptors.error.fns) {
|
|
18505
|
-
if (fn) {
|
|
18506
|
-
finalError = await fn(error, response, opts);
|
|
18507
|
-
}
|
|
18508
|
-
}
|
|
18509
|
-
finalError = finalError || {};
|
|
18510
|
-
if (opts.throwOnError) {
|
|
18511
|
-
throw finalError;
|
|
18512
|
-
}
|
|
18513
|
-
return {
|
|
18514
|
-
error: finalError,
|
|
18515
|
-
...result
|
|
18516
|
-
};
|
|
18517
|
-
};
|
|
18518
|
-
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
18519
|
-
const makeSseFn = (method) => async (options) => {
|
|
18520
|
-
const { opts, url } = await beforeRequest(options);
|
|
18521
|
-
return createSseClient({
|
|
18522
|
-
...opts,
|
|
18523
|
-
body: opts.body,
|
|
18524
|
-
headers: opts.headers,
|
|
18525
|
-
method,
|
|
18526
|
-
onRequest: async (url2, init) => {
|
|
18527
|
-
let request2 = new Request(url2, init);
|
|
18528
|
-
const requestInit = {
|
|
18529
|
-
...init,
|
|
18530
|
-
method: init.method,
|
|
18531
|
-
url: url2
|
|
18532
|
-
};
|
|
18533
|
-
for (const fn of interceptors.request.fns) {
|
|
18534
|
-
if (fn) {
|
|
18535
|
-
await fn(requestInit);
|
|
18536
|
-
request2 = new Request(requestInit.url, requestInit);
|
|
18537
|
-
}
|
|
18538
|
-
}
|
|
18539
|
-
return request2;
|
|
18540
|
-
},
|
|
18541
|
-
url
|
|
18542
|
-
});
|
|
18543
|
-
};
|
|
18544
|
-
return {
|
|
18545
|
-
buildUrl,
|
|
18546
|
-
connect: makeMethodFn("CONNECT"),
|
|
18547
|
-
delete: makeMethodFn("DELETE"),
|
|
18548
|
-
get: makeMethodFn("GET"),
|
|
18549
|
-
getConfig,
|
|
18550
|
-
head: makeMethodFn("HEAD"),
|
|
18551
|
-
interceptors,
|
|
18552
|
-
options: makeMethodFn("OPTIONS"),
|
|
18553
|
-
patch: makeMethodFn("PATCH"),
|
|
18554
|
-
post: makeMethodFn("POST"),
|
|
18555
|
-
put: makeMethodFn("PUT"),
|
|
18556
|
-
request,
|
|
18557
|
-
setConfig,
|
|
18558
|
-
sse: {
|
|
18559
|
-
connect: makeSseFn("CONNECT"),
|
|
18560
|
-
delete: makeSseFn("DELETE"),
|
|
18561
|
-
get: makeSseFn("GET"),
|
|
18562
|
-
head: makeSseFn("HEAD"),
|
|
18563
|
-
options: makeSseFn("OPTIONS"),
|
|
18564
|
-
patch: makeSseFn("PATCH"),
|
|
18565
|
-
post: makeSseFn("POST"),
|
|
18566
|
-
put: makeSseFn("PUT"),
|
|
18567
|
-
trace: makeSseFn("TRACE")
|
|
18568
|
-
},
|
|
18569
|
-
trace: makeMethodFn("TRACE")
|
|
18570
|
-
};
|
|
18571
|
-
};
|
|
18572
|
-
}
|
|
18573
|
-
});
|
|
18574
|
-
|
|
18575
|
-
// src/client/client/index.ts
|
|
18576
|
-
var init_client = __esm({
|
|
18577
|
-
"src/client/client/index.ts"() {
|
|
18578
|
-
"use strict";
|
|
18579
|
-
init_client_gen();
|
|
18580
|
-
init_utils_gen2();
|
|
18581
|
-
}
|
|
18582
|
-
});
|
|
18583
|
-
|
|
18584
|
-
// src/client/client.gen.ts
|
|
18585
|
-
var client;
|
|
18586
|
-
var init_client_gen2 = __esm({
|
|
18587
|
-
"src/client/client.gen.ts"() {
|
|
18588
|
-
"use strict";
|
|
18589
|
-
init_client();
|
|
18590
|
-
init_clientConfig();
|
|
18591
|
-
client = createClient(createClientConfig(createConfig()));
|
|
18592
|
-
}
|
|
18593
|
-
});
|
|
18594
|
-
|
|
18595
|
-
// src/client/sdk.gen.ts
|
|
18596
|
-
var postApiV1Embeddings;
|
|
18597
|
-
var init_sdk_gen = __esm({
|
|
18598
|
-
"src/client/sdk.gen.ts"() {
|
|
18599
|
-
"use strict";
|
|
18600
|
-
init_client_gen2();
|
|
18601
|
-
postApiV1Embeddings = (options) => {
|
|
18602
|
-
return (options.client ?? client).post({
|
|
18603
|
-
url: "/api/v1/embeddings",
|
|
18604
|
-
...options,
|
|
18605
|
-
headers: {
|
|
18606
|
-
"Content-Type": "application/json",
|
|
18607
|
-
...options.headers
|
|
18608
|
-
}
|
|
18609
|
-
});
|
|
18610
|
-
};
|
|
18611
|
-
}
|
|
18612
|
-
});
|
|
18613
|
-
|
|
18614
|
-
// src/client/index.ts
|
|
18615
|
-
var init_client2 = __esm({
|
|
18616
|
-
"src/client/index.ts"() {
|
|
18617
|
-
"use strict";
|
|
18618
|
-
init_sdk_gen();
|
|
18619
|
-
}
|
|
18620
|
-
});
|
|
18621
|
-
|
|
18622
17732
|
// src/lib/memoryEngine/constants.ts
|
|
18623
17733
|
var DEFAULT_API_EMBEDDING_MODEL;
|
|
18624
17734
|
var init_constants = __esm({
|
|
@@ -18628,7 +17738,7 @@ var init_constants = __esm({
|
|
|
18628
17738
|
}
|
|
18629
17739
|
});
|
|
18630
17740
|
|
|
18631
|
-
// src/lib/memoryEngine/
|
|
17741
|
+
// src/lib/memoryEngine/generate.ts
|
|
18632
17742
|
async function withEmbeddingRetry(call) {
|
|
18633
17743
|
let last;
|
|
18634
17744
|
let lastThrown;
|
|
@@ -18679,7 +17789,7 @@ async function generateEmbedding(text12, options) {
|
|
|
18679
17789
|
throw new Error("Either apiKey or getToken must be provided");
|
|
18680
17790
|
}
|
|
18681
17791
|
const response = await withEmbeddingRetry(
|
|
18682
|
-
() => postApiV1Embeddings({
|
|
17792
|
+
() => (0, import_client.postApiV1Embeddings)({
|
|
18683
17793
|
baseUrl,
|
|
18684
17794
|
body: {
|
|
18685
17795
|
// Mask PII from the request body only — the cache above still keys on
|
|
@@ -18711,7 +17821,7 @@ async function generateEmbedding(text12, options) {
|
|
|
18711
17821
|
}
|
|
18712
17822
|
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput) {
|
|
18713
17823
|
const response = await withEmbeddingRetry(
|
|
18714
|
-
() => postApiV1Embeddings({
|
|
17824
|
+
() => (0, import_client.postApiV1Embeddings)({
|
|
18715
17825
|
baseUrl,
|
|
18716
17826
|
// Mask PII from the request body only; cache/order still key on originals.
|
|
18717
17827
|
body: { input: maskInput ? texts.map(maskInput) : texts, model },
|
|
@@ -18812,6 +17922,27 @@ async function generateEmbeddings(texts, options) {
|
|
|
18812
17922
|
}
|
|
18813
17923
|
return results;
|
|
18814
17924
|
}
|
|
17925
|
+
var import_client, EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
|
|
17926
|
+
var init_generate = __esm({
|
|
17927
|
+
"src/lib/memoryEngine/generate.ts"() {
|
|
17928
|
+
"use strict";
|
|
17929
|
+
import_client = require("@anuma/sdk");
|
|
17930
|
+
init_clientConfig();
|
|
17931
|
+
init_constants();
|
|
17932
|
+
EMBED_MAX_ATTEMPTS = 4;
|
|
17933
|
+
EmbeddingHttpError = class extends Error {
|
|
17934
|
+
constructor(message, status) {
|
|
17935
|
+
super(message);
|
|
17936
|
+
this.name = "EmbeddingHttpError";
|
|
17937
|
+
this.status = status;
|
|
17938
|
+
}
|
|
17939
|
+
};
|
|
17940
|
+
DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
17941
|
+
DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
17942
|
+
}
|
|
17943
|
+
});
|
|
17944
|
+
|
|
17945
|
+
// src/lib/memoryEngine/embeddings.ts
|
|
18815
17946
|
async function embedMessage(ctx, messageId, options) {
|
|
18816
17947
|
let message;
|
|
18817
17948
|
const conversations = await getConversationsOp(ctx);
|
|
@@ -18967,27 +18098,17 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
18967
18098
|
}
|
|
18968
18099
|
return embeddedCount;
|
|
18969
18100
|
}
|
|
18970
|
-
var DEFAULT_MIN_CONTENT_LENGTH
|
|
18101
|
+
var DEFAULT_MIN_CONTENT_LENGTH;
|
|
18971
18102
|
var init_embeddings = __esm({
|
|
18972
18103
|
"src/lib/memoryEngine/embeddings.ts"() {
|
|
18973
18104
|
"use strict";
|
|
18974
|
-
init_client2();
|
|
18975
|
-
init_clientConfig();
|
|
18976
18105
|
init_operations();
|
|
18977
18106
|
init_logger();
|
|
18978
18107
|
init_chunking();
|
|
18979
18108
|
init_constants();
|
|
18109
|
+
init_generate();
|
|
18110
|
+
init_generate();
|
|
18980
18111
|
DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
18981
|
-
EMBED_MAX_ATTEMPTS = 4;
|
|
18982
|
-
EmbeddingHttpError = class extends Error {
|
|
18983
|
-
constructor(message, status) {
|
|
18984
|
-
super(message);
|
|
18985
|
-
this.name = "EmbeddingHttpError";
|
|
18986
|
-
this.status = status;
|
|
18987
|
-
}
|
|
18988
|
-
};
|
|
18989
|
-
DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
18990
|
-
DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
18991
18112
|
}
|
|
18992
18113
|
});
|
|
18993
18114
|
|
|
@@ -23981,17 +23102,17 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
23981
23102
|
}
|
|
23982
23103
|
case "sql": {
|
|
23983
23104
|
if (this._pgSchema !== "public" && this.pool.connect) {
|
|
23984
|
-
const
|
|
23105
|
+
const client = await this.pool.connect();
|
|
23985
23106
|
try {
|
|
23986
|
-
await
|
|
23987
|
-
await
|
|
23988
|
-
await
|
|
23989
|
-
await
|
|
23107
|
+
await client.query("BEGIN");
|
|
23108
|
+
await client.query(`SET LOCAL search_path TO "${this._pgSchema}", public`);
|
|
23109
|
+
await client.query(step.sql);
|
|
23110
|
+
await client.query("COMMIT");
|
|
23990
23111
|
} catch (err) {
|
|
23991
|
-
await
|
|
23112
|
+
await client.query("ROLLBACK");
|
|
23992
23113
|
throw err;
|
|
23993
23114
|
} finally {
|
|
23994
|
-
|
|
23115
|
+
client.release();
|
|
23995
23116
|
}
|
|
23996
23117
|
} else {
|
|
23997
23118
|
await this.pool.query(step.sql);
|
|
@@ -24137,16 +23258,16 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
24137
23258
|
}
|
|
24138
23259
|
};
|
|
24139
23260
|
if (this.pool.connect) {
|
|
24140
|
-
const
|
|
23261
|
+
const client = await this.pool.connect();
|
|
24141
23262
|
try {
|
|
24142
|
-
await
|
|
24143
|
-
await runOps(
|
|
24144
|
-
await
|
|
23263
|
+
await client.query("BEGIN");
|
|
23264
|
+
await runOps(client);
|
|
23265
|
+
await client.query("COMMIT");
|
|
24145
23266
|
} catch (err) {
|
|
24146
|
-
await
|
|
23267
|
+
await client.query("ROLLBACK");
|
|
24147
23268
|
throw err;
|
|
24148
23269
|
} finally {
|
|
24149
|
-
|
|
23270
|
+
client.release();
|
|
24150
23271
|
}
|
|
24151
23272
|
} else {
|
|
24152
23273
|
await runOps(this.pool);
|
|
@@ -27014,8 +26135,12 @@ init_recall();
|
|
|
27014
26135
|
|
|
27015
26136
|
// src/lib/memory/recallTool.ts
|
|
27016
26137
|
init_recall();
|
|
26138
|
+
|
|
26139
|
+
// src/lib/memory/recallConstants.ts
|
|
27017
26140
|
var RECALL_TOOL_NAME = "recall_memory";
|
|
27018
26141
|
var RECALL_MAX_LIMIT = 50;
|
|
26142
|
+
|
|
26143
|
+
// src/lib/memory/recallTool.ts
|
|
27019
26144
|
var DEFAULT_LIMIT2 = 8;
|
|
27020
26145
|
var DEFAULT_BUDGET2 = "low";
|
|
27021
26146
|
function formatEventTime(start, end, kind) {
|
|
@@ -27542,7 +26667,7 @@ WORKFLOW:
|
|
|
27542
26667
|
|
|
27543
26668
|
// src/lib/tools/serverTools.ts
|
|
27544
26669
|
init_logger();
|
|
27545
|
-
|
|
26670
|
+
init_generate();
|
|
27546
26671
|
init_vector();
|
|
27547
26672
|
var DEFAULT_CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1e3;
|
|
27548
26673
|
var SERVER_TOOLS_CACHE_KEY = "sdk_server_tools_cache";
|
|
@@ -27589,7 +26714,7 @@ function getCachedServerTools() {
|
|
|
27589
26714
|
if (!cached) return null;
|
|
27590
26715
|
const parsed = JSON.parse(cached);
|
|
27591
26716
|
if (parsed.version !== CACHE_VERSION) {
|
|
27592
|
-
|
|
26717
|
+
removeLocalStorageCache();
|
|
27593
26718
|
return null;
|
|
27594
26719
|
}
|
|
27595
26720
|
return parsed;
|
|
@@ -27601,37 +26726,45 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
|
|
|
27601
26726
|
if (!cache) return true;
|
|
27602
26727
|
return Date.now() - cache.timestamp > expirationMs;
|
|
27603
26728
|
}
|
|
27604
|
-
function
|
|
27605
|
-
|
|
27606
|
-
const cacheData = {
|
|
26729
|
+
function buildCacheEntry(tools, checksum) {
|
|
26730
|
+
return {
|
|
27607
26731
|
tools,
|
|
27608
26732
|
timestamp: Date.now(),
|
|
27609
26733
|
version: CACHE_VERSION,
|
|
27610
26734
|
...checksum && { checksum }
|
|
27611
26735
|
};
|
|
26736
|
+
}
|
|
26737
|
+
function writeLocalStorageCache(entry) {
|
|
26738
|
+
if (typeof localStorage === "undefined") return;
|
|
27612
26739
|
try {
|
|
27613
|
-
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(
|
|
26740
|
+
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(entry));
|
|
27614
26741
|
} catch (error) {
|
|
27615
26742
|
getLogger().warn("[serverTools] Failed to cache tools:", error);
|
|
27616
26743
|
}
|
|
27617
26744
|
}
|
|
27618
|
-
function
|
|
26745
|
+
function removeLocalStorageCache() {
|
|
27619
26746
|
if (typeof localStorage === "undefined") return;
|
|
27620
26747
|
localStorage.removeItem(SERVER_TOOLS_CACHE_KEY);
|
|
27621
26748
|
}
|
|
27622
|
-
|
|
27623
|
-
|
|
27624
|
-
|
|
26749
|
+
var localStorageToolsCache = {
|
|
26750
|
+
get: getCachedServerTools,
|
|
26751
|
+
set: writeLocalStorageCache,
|
|
26752
|
+
clear: removeLocalStorageCache
|
|
26753
|
+
};
|
|
26754
|
+
function clearServerToolsCache(cache = localStorageToolsCache) {
|
|
26755
|
+
return cache.clear?.();
|
|
26756
|
+
}
|
|
26757
|
+
function getToolsChecksum(cache = localStorageToolsCache) {
|
|
26758
|
+
const cached = cache.get();
|
|
26759
|
+
return cached instanceof Promise ? cached.then((c) => c?.checksum) : cached?.checksum;
|
|
27625
26760
|
}
|
|
27626
|
-
function shouldRefreshTools(responseChecksum) {
|
|
26761
|
+
function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
|
|
27627
26762
|
if (!responseChecksum) {
|
|
27628
26763
|
return false;
|
|
27629
26764
|
}
|
|
27630
|
-
const
|
|
27631
|
-
|
|
27632
|
-
|
|
27633
|
-
}
|
|
27634
|
-
return cachedChecksum !== responseChecksum;
|
|
26765
|
+
const decide = (cachedChecksum2) => !cachedChecksum2 || cachedChecksum2 !== responseChecksum;
|
|
26766
|
+
const cachedChecksum = getToolsChecksum(cache);
|
|
26767
|
+
return cachedChecksum instanceof Promise ? cachedChecksum.then(decide) : decide(cachedChecksum);
|
|
27635
26768
|
}
|
|
27636
26769
|
async function fetchServerToolsFromApi(baseUrl, token) {
|
|
27637
26770
|
const response = await fetch(`${baseUrl}/api/v1/tools`, {
|
|
@@ -27653,9 +26786,23 @@ async function getServerTools(options) {
|
|
|
27653
26786
|
cacheExpirationMs = DEFAULT_CACHE_EXPIRATION_MS,
|
|
27654
26787
|
forceRefresh = false,
|
|
27655
26788
|
getToken,
|
|
27656
|
-
apiKey
|
|
26789
|
+
apiKey,
|
|
26790
|
+
cache = localStorageToolsCache
|
|
27657
26791
|
} = options;
|
|
27658
|
-
const
|
|
26792
|
+
const persistCache = async (entry) => {
|
|
26793
|
+
try {
|
|
26794
|
+
await cache.set(entry);
|
|
26795
|
+
} catch (error) {
|
|
26796
|
+
getLogger().warn("[serverTools] Cache write failed (non-fatal):", error);
|
|
26797
|
+
}
|
|
26798
|
+
};
|
|
26799
|
+
let rawCached = null;
|
|
26800
|
+
try {
|
|
26801
|
+
rawCached = await cache.get();
|
|
26802
|
+
} catch (error) {
|
|
26803
|
+
getLogger().warn("[serverTools] Cache read failed; falling through to server fetch:", error);
|
|
26804
|
+
}
|
|
26805
|
+
const cached = rawCached && rawCached.version === CACHE_VERSION ? rawCached : null;
|
|
27659
26806
|
const cacheValid = !isCacheExpired(cached, cacheExpirationMs);
|
|
27660
26807
|
if (cached && cacheValid && !forceRefresh) {
|
|
27661
26808
|
return cached.tools;
|
|
@@ -27676,7 +26823,7 @@ async function getServerTools(options) {
|
|
|
27676
26823
|
}
|
|
27677
26824
|
const data = await response.json();
|
|
27678
26825
|
const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
|
|
27679
|
-
|
|
26826
|
+
await persistCache(buildCacheEntry(tools2, checksum2));
|
|
27680
26827
|
return tools2;
|
|
27681
26828
|
}
|
|
27682
26829
|
if (!getToken) {
|
|
@@ -27689,7 +26836,7 @@ async function getServerTools(options) {
|
|
|
27689
26836
|
return cached?.tools ?? [];
|
|
27690
26837
|
}
|
|
27691
26838
|
const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
|
|
27692
|
-
|
|
26839
|
+
await persistCache(buildCacheEntry(tools, checksum));
|
|
27693
26840
|
return tools;
|
|
27694
26841
|
} catch (error) {
|
|
27695
26842
|
getLogger().error("[serverTools] Failed to fetch server tools:", error);
|
|
@@ -28073,13 +27220,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
28073
27220
|
baseUrl,
|
|
28074
27221
|
embeddingModel,
|
|
28075
27222
|
cacheExpirationMs,
|
|
27223
|
+
cache,
|
|
28076
27224
|
deferLoading
|
|
28077
27225
|
} = options;
|
|
28078
27226
|
if (serverToolsFilter === void 0) return [];
|
|
28079
27227
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
28080
27228
|
let allServerTools;
|
|
28081
27229
|
try {
|
|
28082
|
-
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken });
|
|
27230
|
+
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken, cache });
|
|
28083
27231
|
} catch {
|
|
28084
27232
|
return [];
|
|
28085
27233
|
}
|
|
@@ -29437,8 +28585,142 @@ function createCryptoPricePreProcessor(options = {}) {
|
|
|
29437
28585
|
// src/lib/chat/resumeStream.ts
|
|
29438
28586
|
init_clientConfig();
|
|
29439
28587
|
|
|
28588
|
+
// src/client/core/serverSentEvents.gen.ts
|
|
28589
|
+
var createSseClient = ({
|
|
28590
|
+
onRequest,
|
|
28591
|
+
onSseError,
|
|
28592
|
+
onSseEvent,
|
|
28593
|
+
responseTransformer,
|
|
28594
|
+
responseValidator,
|
|
28595
|
+
sseDefaultRetryDelay,
|
|
28596
|
+
sseMaxRetryAttempts,
|
|
28597
|
+
sseMaxRetryDelay,
|
|
28598
|
+
sseSleepFn,
|
|
28599
|
+
url,
|
|
28600
|
+
...options
|
|
28601
|
+
}) => {
|
|
28602
|
+
let lastEventId;
|
|
28603
|
+
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
28604
|
+
const createStream = async function* () {
|
|
28605
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
28606
|
+
let attempt = 0;
|
|
28607
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
28608
|
+
while (true) {
|
|
28609
|
+
if (signal.aborted) break;
|
|
28610
|
+
attempt++;
|
|
28611
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
28612
|
+
if (lastEventId !== void 0) {
|
|
28613
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
28614
|
+
}
|
|
28615
|
+
try {
|
|
28616
|
+
const requestInit = {
|
|
28617
|
+
redirect: "follow",
|
|
28618
|
+
...options,
|
|
28619
|
+
body: options.serializedBody,
|
|
28620
|
+
headers,
|
|
28621
|
+
signal
|
|
28622
|
+
};
|
|
28623
|
+
let request = new Request(url, requestInit);
|
|
28624
|
+
if (onRequest) {
|
|
28625
|
+
request = await onRequest(url, requestInit);
|
|
28626
|
+
}
|
|
28627
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
28628
|
+
const response = await _fetch(request);
|
|
28629
|
+
if (!response.ok)
|
|
28630
|
+
throw new Error(
|
|
28631
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
28632
|
+
);
|
|
28633
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
28634
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
28635
|
+
let buffer = "";
|
|
28636
|
+
const abortHandler = () => {
|
|
28637
|
+
try {
|
|
28638
|
+
reader.cancel();
|
|
28639
|
+
} catch {
|
|
28640
|
+
}
|
|
28641
|
+
};
|
|
28642
|
+
signal.addEventListener("abort", abortHandler);
|
|
28643
|
+
try {
|
|
28644
|
+
while (true) {
|
|
28645
|
+
const { done, value } = await reader.read();
|
|
28646
|
+
if (done) break;
|
|
28647
|
+
buffer += value;
|
|
28648
|
+
const chunks = buffer.split("\n\n");
|
|
28649
|
+
buffer = chunks.pop() ?? "";
|
|
28650
|
+
for (const chunk of chunks) {
|
|
28651
|
+
const lines = chunk.split("\n");
|
|
28652
|
+
const dataLines = [];
|
|
28653
|
+
let eventName;
|
|
28654
|
+
for (const line of lines) {
|
|
28655
|
+
if (line.startsWith("data:")) {
|
|
28656
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
28657
|
+
} else if (line.startsWith("event:")) {
|
|
28658
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
28659
|
+
} else if (line.startsWith("id:")) {
|
|
28660
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
28661
|
+
} else if (line.startsWith("retry:")) {
|
|
28662
|
+
const parsed = Number.parseInt(
|
|
28663
|
+
line.replace(/^retry:\s*/, ""),
|
|
28664
|
+
10
|
|
28665
|
+
);
|
|
28666
|
+
if (!Number.isNaN(parsed)) {
|
|
28667
|
+
retryDelay = parsed;
|
|
28668
|
+
}
|
|
28669
|
+
}
|
|
28670
|
+
}
|
|
28671
|
+
let data;
|
|
28672
|
+
let parsedJson = false;
|
|
28673
|
+
if (dataLines.length) {
|
|
28674
|
+
const rawData = dataLines.join("\n");
|
|
28675
|
+
try {
|
|
28676
|
+
data = JSON.parse(rawData);
|
|
28677
|
+
parsedJson = true;
|
|
28678
|
+
} catch {
|
|
28679
|
+
data = rawData;
|
|
28680
|
+
}
|
|
28681
|
+
}
|
|
28682
|
+
if (parsedJson) {
|
|
28683
|
+
if (responseValidator) {
|
|
28684
|
+
await responseValidator(data);
|
|
28685
|
+
}
|
|
28686
|
+
if (responseTransformer) {
|
|
28687
|
+
data = await responseTransformer(data);
|
|
28688
|
+
}
|
|
28689
|
+
}
|
|
28690
|
+
onSseEvent?.({
|
|
28691
|
+
data,
|
|
28692
|
+
event: eventName,
|
|
28693
|
+
id: lastEventId,
|
|
28694
|
+
retry: retryDelay
|
|
28695
|
+
});
|
|
28696
|
+
if (dataLines.length) {
|
|
28697
|
+
yield data;
|
|
28698
|
+
}
|
|
28699
|
+
}
|
|
28700
|
+
}
|
|
28701
|
+
} finally {
|
|
28702
|
+
signal.removeEventListener("abort", abortHandler);
|
|
28703
|
+
reader.releaseLock();
|
|
28704
|
+
}
|
|
28705
|
+
break;
|
|
28706
|
+
} catch (error) {
|
|
28707
|
+
onSseError?.(error);
|
|
28708
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
28709
|
+
break;
|
|
28710
|
+
}
|
|
28711
|
+
const backoff = Math.min(
|
|
28712
|
+
retryDelay * 2 ** (attempt - 1),
|
|
28713
|
+
sseMaxRetryDelay ?? 3e4
|
|
28714
|
+
);
|
|
28715
|
+
await sleep4(backoff);
|
|
28716
|
+
}
|
|
28717
|
+
}
|
|
28718
|
+
};
|
|
28719
|
+
const stream = createStream();
|
|
28720
|
+
return { stream };
|
|
28721
|
+
};
|
|
28722
|
+
|
|
29440
28723
|
// src/lib/chat/toolLoop.ts
|
|
29441
|
-
init_serverSentEvents_gen();
|
|
29442
28724
|
init_clientConfig();
|
|
29443
28725
|
init_embeddings();
|
|
29444
28726
|
init_redactor();
|