@anuma/sdk 3.6.2 → 3.6.3
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-7TATXBC5.mjs → chunk-FKACNV6X.mjs} +809 -3
- package/dist/expo/index.cjs +909 -823
- package/dist/expo/index.mjs +7 -798
- package/dist/expo/{recall-IO4KJ5W7.mjs → recall-VZHV7ILE.mjs} +1 -1
- package/dist/react/{chunk-DDHTJGZN.mjs → chunk-ZGMHRWOR.mjs} +895 -3
- package/dist/react/index.cjs +1999 -1905
- package/dist/react/index.mjs +22 -869
- package/dist/react/{recall-OPKHWKZX.mjs → recall-JOLS3V4B.mjs} +1 -1
- package/dist/server/{chunk-V7SVKIXQ.mjs → chunk-66UWDXS3.mjs} +794 -3
- package/dist/server/index.cjs +886 -144
- package/dist/server/index.mjs +2 -128
- package/dist/server/{recall-IWY2MYHR.mjs → recall-UTVH2XPK.mjs} +1 -1
- package/dist/tools/selection/index.cjs +793 -3
- package/dist/tools/selection/index.mjs +791 -3
- package/package.json +2 -2
package/dist/server/index.cjs
CHANGED
|
@@ -17918,6 +17918,874 @@ var init_constants = __esm({
|
|
|
17918
17918
|
}
|
|
17919
17919
|
});
|
|
17920
17920
|
|
|
17921
|
+
// src/client/core/bodySerializer.gen.ts
|
|
17922
|
+
var jsonBodySerializer;
|
|
17923
|
+
var init_bodySerializer_gen = __esm({
|
|
17924
|
+
"src/client/core/bodySerializer.gen.ts"() {
|
|
17925
|
+
"use strict";
|
|
17926
|
+
jsonBodySerializer = {
|
|
17927
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
17928
|
+
};
|
|
17929
|
+
}
|
|
17930
|
+
});
|
|
17931
|
+
|
|
17932
|
+
// src/client/core/serverSentEvents.gen.ts
|
|
17933
|
+
function createSseClient({
|
|
17934
|
+
onRequest,
|
|
17935
|
+
onSseError,
|
|
17936
|
+
onSseEvent,
|
|
17937
|
+
responseTransformer,
|
|
17938
|
+
responseValidator,
|
|
17939
|
+
sseDefaultRetryDelay,
|
|
17940
|
+
sseMaxRetryAttempts,
|
|
17941
|
+
sseMaxRetryDelay,
|
|
17942
|
+
sseSleepFn,
|
|
17943
|
+
url,
|
|
17944
|
+
...options
|
|
17945
|
+
}) {
|
|
17946
|
+
let lastEventId;
|
|
17947
|
+
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
17948
|
+
const createStream = async function* () {
|
|
17949
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
17950
|
+
let attempt = 0;
|
|
17951
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
17952
|
+
while (true) {
|
|
17953
|
+
if (signal.aborted) break;
|
|
17954
|
+
attempt++;
|
|
17955
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
17956
|
+
if (lastEventId !== void 0) {
|
|
17957
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
17958
|
+
}
|
|
17959
|
+
try {
|
|
17960
|
+
const requestInit = {
|
|
17961
|
+
redirect: "follow",
|
|
17962
|
+
...options,
|
|
17963
|
+
body: options.serializedBody,
|
|
17964
|
+
headers,
|
|
17965
|
+
signal
|
|
17966
|
+
};
|
|
17967
|
+
let request = new Request(url, requestInit);
|
|
17968
|
+
if (onRequest) {
|
|
17969
|
+
request = await onRequest(url, requestInit);
|
|
17970
|
+
}
|
|
17971
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
17972
|
+
const response = await _fetch(request);
|
|
17973
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
17974
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
17975
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
17976
|
+
let buffer = "";
|
|
17977
|
+
const abortHandler = () => {
|
|
17978
|
+
try {
|
|
17979
|
+
reader.cancel();
|
|
17980
|
+
} catch {
|
|
17981
|
+
}
|
|
17982
|
+
};
|
|
17983
|
+
signal.addEventListener("abort", abortHandler);
|
|
17984
|
+
try {
|
|
17985
|
+
while (true) {
|
|
17986
|
+
const { done, value } = await reader.read();
|
|
17987
|
+
if (done) break;
|
|
17988
|
+
buffer += value;
|
|
17989
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
17990
|
+
const chunks = buffer.split("\n\n");
|
|
17991
|
+
buffer = chunks.pop() ?? "";
|
|
17992
|
+
for (const chunk of chunks) {
|
|
17993
|
+
const lines = chunk.split("\n");
|
|
17994
|
+
const dataLines = [];
|
|
17995
|
+
let eventName;
|
|
17996
|
+
for (const line of lines) {
|
|
17997
|
+
if (line.startsWith("data:")) {
|
|
17998
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
17999
|
+
} else if (line.startsWith("event:")) {
|
|
18000
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
18001
|
+
} else if (line.startsWith("id:")) {
|
|
18002
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
18003
|
+
} else if (line.startsWith("retry:")) {
|
|
18004
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
18005
|
+
if (!Number.isNaN(parsed)) {
|
|
18006
|
+
retryDelay = parsed;
|
|
18007
|
+
}
|
|
18008
|
+
}
|
|
18009
|
+
}
|
|
18010
|
+
let data;
|
|
18011
|
+
let parsedJson = false;
|
|
18012
|
+
if (dataLines.length) {
|
|
18013
|
+
const rawData = dataLines.join("\n");
|
|
18014
|
+
try {
|
|
18015
|
+
data = JSON.parse(rawData);
|
|
18016
|
+
parsedJson = true;
|
|
18017
|
+
} catch {
|
|
18018
|
+
data = rawData;
|
|
18019
|
+
}
|
|
18020
|
+
}
|
|
18021
|
+
if (parsedJson) {
|
|
18022
|
+
if (responseValidator) {
|
|
18023
|
+
await responseValidator(data);
|
|
18024
|
+
}
|
|
18025
|
+
if (responseTransformer) {
|
|
18026
|
+
data = await responseTransformer(data);
|
|
18027
|
+
}
|
|
18028
|
+
}
|
|
18029
|
+
onSseEvent?.({
|
|
18030
|
+
data,
|
|
18031
|
+
event: eventName,
|
|
18032
|
+
id: lastEventId,
|
|
18033
|
+
retry: retryDelay
|
|
18034
|
+
});
|
|
18035
|
+
if (dataLines.length) {
|
|
18036
|
+
yield data;
|
|
18037
|
+
}
|
|
18038
|
+
}
|
|
18039
|
+
}
|
|
18040
|
+
} finally {
|
|
18041
|
+
signal.removeEventListener("abort", abortHandler);
|
|
18042
|
+
reader.releaseLock();
|
|
18043
|
+
}
|
|
18044
|
+
break;
|
|
18045
|
+
} catch (error) {
|
|
18046
|
+
onSseError?.(error);
|
|
18047
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
18048
|
+
break;
|
|
18049
|
+
}
|
|
18050
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
18051
|
+
await sleep4(backoff);
|
|
18052
|
+
}
|
|
18053
|
+
}
|
|
18054
|
+
};
|
|
18055
|
+
const stream = createStream();
|
|
18056
|
+
return { stream };
|
|
18057
|
+
}
|
|
18058
|
+
var init_serverSentEvents_gen = __esm({
|
|
18059
|
+
"src/client/core/serverSentEvents.gen.ts"() {
|
|
18060
|
+
"use strict";
|
|
18061
|
+
}
|
|
18062
|
+
});
|
|
18063
|
+
|
|
18064
|
+
// src/client/core/pathSerializer.gen.ts
|
|
18065
|
+
var separatorArrayExplode, separatorArrayNoExplode, separatorObjectExplode, serializeArrayParam, serializePrimitiveParam, serializeObjectParam;
|
|
18066
|
+
var init_pathSerializer_gen = __esm({
|
|
18067
|
+
"src/client/core/pathSerializer.gen.ts"() {
|
|
18068
|
+
"use strict";
|
|
18069
|
+
separatorArrayExplode = (style) => {
|
|
18070
|
+
switch (style) {
|
|
18071
|
+
case "label":
|
|
18072
|
+
return ".";
|
|
18073
|
+
case "matrix":
|
|
18074
|
+
return ";";
|
|
18075
|
+
case "simple":
|
|
18076
|
+
return ",";
|
|
18077
|
+
default:
|
|
18078
|
+
return "&";
|
|
18079
|
+
}
|
|
18080
|
+
};
|
|
18081
|
+
separatorArrayNoExplode = (style) => {
|
|
18082
|
+
switch (style) {
|
|
18083
|
+
case "form":
|
|
18084
|
+
return ",";
|
|
18085
|
+
case "pipeDelimited":
|
|
18086
|
+
return "|";
|
|
18087
|
+
case "spaceDelimited":
|
|
18088
|
+
return "%20";
|
|
18089
|
+
default:
|
|
18090
|
+
return ",";
|
|
18091
|
+
}
|
|
18092
|
+
};
|
|
18093
|
+
separatorObjectExplode = (style) => {
|
|
18094
|
+
switch (style) {
|
|
18095
|
+
case "label":
|
|
18096
|
+
return ".";
|
|
18097
|
+
case "matrix":
|
|
18098
|
+
return ";";
|
|
18099
|
+
case "simple":
|
|
18100
|
+
return ",";
|
|
18101
|
+
default:
|
|
18102
|
+
return "&";
|
|
18103
|
+
}
|
|
18104
|
+
};
|
|
18105
|
+
serializeArrayParam = ({
|
|
18106
|
+
allowReserved,
|
|
18107
|
+
explode,
|
|
18108
|
+
name,
|
|
18109
|
+
style,
|
|
18110
|
+
value
|
|
18111
|
+
}) => {
|
|
18112
|
+
if (!explode) {
|
|
18113
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
18114
|
+
switch (style) {
|
|
18115
|
+
case "label":
|
|
18116
|
+
return `.${joinedValues2}`;
|
|
18117
|
+
case "matrix":
|
|
18118
|
+
return `;${name}=${joinedValues2}`;
|
|
18119
|
+
case "simple":
|
|
18120
|
+
return joinedValues2;
|
|
18121
|
+
default:
|
|
18122
|
+
return `${name}=${joinedValues2}`;
|
|
18123
|
+
}
|
|
18124
|
+
}
|
|
18125
|
+
const separator = separatorArrayExplode(style);
|
|
18126
|
+
const joinedValues = value.map((v) => {
|
|
18127
|
+
if (style === "label" || style === "simple") {
|
|
18128
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
18129
|
+
}
|
|
18130
|
+
return serializePrimitiveParam({
|
|
18131
|
+
allowReserved,
|
|
18132
|
+
name,
|
|
18133
|
+
value: v
|
|
18134
|
+
});
|
|
18135
|
+
}).join(separator);
|
|
18136
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
18137
|
+
};
|
|
18138
|
+
serializePrimitiveParam = ({
|
|
18139
|
+
allowReserved,
|
|
18140
|
+
name,
|
|
18141
|
+
value
|
|
18142
|
+
}) => {
|
|
18143
|
+
if (value === void 0 || value === null) {
|
|
18144
|
+
return "";
|
|
18145
|
+
}
|
|
18146
|
+
if (typeof value === "object") {
|
|
18147
|
+
throw new Error(
|
|
18148
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
18149
|
+
);
|
|
18150
|
+
}
|
|
18151
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
18152
|
+
};
|
|
18153
|
+
serializeObjectParam = ({
|
|
18154
|
+
allowReserved,
|
|
18155
|
+
explode,
|
|
18156
|
+
name,
|
|
18157
|
+
style,
|
|
18158
|
+
value,
|
|
18159
|
+
valueOnly
|
|
18160
|
+
}) => {
|
|
18161
|
+
if (value instanceof Date) {
|
|
18162
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
18163
|
+
}
|
|
18164
|
+
if (style !== "deepObject" && !explode) {
|
|
18165
|
+
let values = [];
|
|
18166
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
18167
|
+
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
18168
|
+
});
|
|
18169
|
+
const joinedValues2 = values.join(",");
|
|
18170
|
+
switch (style) {
|
|
18171
|
+
case "form":
|
|
18172
|
+
return `${name}=${joinedValues2}`;
|
|
18173
|
+
case "label":
|
|
18174
|
+
return `.${joinedValues2}`;
|
|
18175
|
+
case "matrix":
|
|
18176
|
+
return `;${name}=${joinedValues2}`;
|
|
18177
|
+
default:
|
|
18178
|
+
return joinedValues2;
|
|
18179
|
+
}
|
|
18180
|
+
}
|
|
18181
|
+
const separator = separatorObjectExplode(style);
|
|
18182
|
+
const joinedValues = Object.entries(value).map(
|
|
18183
|
+
([key, v]) => serializePrimitiveParam({
|
|
18184
|
+
allowReserved,
|
|
18185
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
18186
|
+
value: v
|
|
18187
|
+
})
|
|
18188
|
+
).join(separator);
|
|
18189
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
18190
|
+
};
|
|
18191
|
+
}
|
|
18192
|
+
});
|
|
18193
|
+
|
|
18194
|
+
// src/client/core/utils.gen.ts
|
|
18195
|
+
function getValidRequestBody(options) {
|
|
18196
|
+
const hasBody = options.body !== void 0;
|
|
18197
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
18198
|
+
if (isSerializedBody) {
|
|
18199
|
+
if ("serializedBody" in options) {
|
|
18200
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
18201
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
18202
|
+
}
|
|
18203
|
+
return options.body !== "" ? options.body : null;
|
|
18204
|
+
}
|
|
18205
|
+
if (hasBody) {
|
|
18206
|
+
return options.body;
|
|
18207
|
+
}
|
|
18208
|
+
return void 0;
|
|
18209
|
+
}
|
|
18210
|
+
var init_utils_gen = __esm({
|
|
18211
|
+
"src/client/core/utils.gen.ts"() {
|
|
18212
|
+
"use strict";
|
|
18213
|
+
}
|
|
18214
|
+
});
|
|
18215
|
+
|
|
18216
|
+
// src/client/core/auth.gen.ts
|
|
18217
|
+
var getAuthToken;
|
|
18218
|
+
var init_auth_gen = __esm({
|
|
18219
|
+
"src/client/core/auth.gen.ts"() {
|
|
18220
|
+
"use strict";
|
|
18221
|
+
getAuthToken = async (auth, callback) => {
|
|
18222
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
18223
|
+
if (!token) {
|
|
18224
|
+
return;
|
|
18225
|
+
}
|
|
18226
|
+
if (auth.scheme === "bearer") {
|
|
18227
|
+
return `Bearer ${token}`;
|
|
18228
|
+
}
|
|
18229
|
+
if (auth.scheme === "basic") {
|
|
18230
|
+
return `Basic ${btoa(token)}`;
|
|
18231
|
+
}
|
|
18232
|
+
return token;
|
|
18233
|
+
};
|
|
18234
|
+
}
|
|
18235
|
+
});
|
|
18236
|
+
|
|
18237
|
+
// src/client/client/utils.gen.ts
|
|
18238
|
+
async function setAuthParams(options) {
|
|
18239
|
+
for (const auth of options.security ?? []) {
|
|
18240
|
+
if (checkForExistence(options, auth.name)) {
|
|
18241
|
+
continue;
|
|
18242
|
+
}
|
|
18243
|
+
const token = await getAuthToken(auth, options.auth);
|
|
18244
|
+
if (!token) {
|
|
18245
|
+
continue;
|
|
18246
|
+
}
|
|
18247
|
+
const name = auth.name ?? "Authorization";
|
|
18248
|
+
switch (auth.in) {
|
|
18249
|
+
case "query":
|
|
18250
|
+
if (!options.query) {
|
|
18251
|
+
options.query = {};
|
|
18252
|
+
}
|
|
18253
|
+
options.query[name] = token;
|
|
18254
|
+
break;
|
|
18255
|
+
case "cookie":
|
|
18256
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
18257
|
+
break;
|
|
18258
|
+
case "header":
|
|
18259
|
+
default:
|
|
18260
|
+
options.headers.set(name, token);
|
|
18261
|
+
break;
|
|
18262
|
+
}
|
|
18263
|
+
}
|
|
18264
|
+
}
|
|
18265
|
+
var PATH_PARAM_RE, defaultPathSerializer, createQuerySerializer, getParseAs, checkForExistence, buildUrl, getUrl, mergeConfigs, headersEntries, mergeHeaders, Interceptors, createInterceptors, defaultQuerySerializer, defaultHeaders, createConfig;
|
|
18266
|
+
var init_utils_gen2 = __esm({
|
|
18267
|
+
"src/client/client/utils.gen.ts"() {
|
|
18268
|
+
"use strict";
|
|
18269
|
+
init_auth_gen();
|
|
18270
|
+
init_bodySerializer_gen();
|
|
18271
|
+
init_pathSerializer_gen();
|
|
18272
|
+
PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
18273
|
+
defaultPathSerializer = ({ path, url: _url }) => {
|
|
18274
|
+
let url = _url;
|
|
18275
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
18276
|
+
if (matches) {
|
|
18277
|
+
for (const match of matches) {
|
|
18278
|
+
let explode = false;
|
|
18279
|
+
let name = match.substring(1, match.length - 1);
|
|
18280
|
+
let style = "simple";
|
|
18281
|
+
if (name.endsWith("*")) {
|
|
18282
|
+
explode = true;
|
|
18283
|
+
name = name.substring(0, name.length - 1);
|
|
18284
|
+
}
|
|
18285
|
+
if (name.startsWith(".")) {
|
|
18286
|
+
name = name.substring(1);
|
|
18287
|
+
style = "label";
|
|
18288
|
+
} else if (name.startsWith(";")) {
|
|
18289
|
+
name = name.substring(1);
|
|
18290
|
+
style = "matrix";
|
|
18291
|
+
}
|
|
18292
|
+
const value = path[name];
|
|
18293
|
+
if (value === void 0 || value === null) {
|
|
18294
|
+
continue;
|
|
18295
|
+
}
|
|
18296
|
+
if (Array.isArray(value)) {
|
|
18297
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
18298
|
+
continue;
|
|
18299
|
+
}
|
|
18300
|
+
if (typeof value === "object") {
|
|
18301
|
+
url = url.replace(
|
|
18302
|
+
match,
|
|
18303
|
+
serializeObjectParam({
|
|
18304
|
+
explode,
|
|
18305
|
+
name,
|
|
18306
|
+
style,
|
|
18307
|
+
value,
|
|
18308
|
+
valueOnly: true
|
|
18309
|
+
})
|
|
18310
|
+
);
|
|
18311
|
+
continue;
|
|
18312
|
+
}
|
|
18313
|
+
if (style === "matrix") {
|
|
18314
|
+
url = url.replace(
|
|
18315
|
+
match,
|
|
18316
|
+
`;${serializePrimitiveParam({
|
|
18317
|
+
name,
|
|
18318
|
+
value
|
|
18319
|
+
})}`
|
|
18320
|
+
);
|
|
18321
|
+
continue;
|
|
18322
|
+
}
|
|
18323
|
+
const replaceValue = encodeURIComponent(
|
|
18324
|
+
style === "label" ? `.${value}` : value
|
|
18325
|
+
);
|
|
18326
|
+
url = url.replace(match, replaceValue);
|
|
18327
|
+
}
|
|
18328
|
+
}
|
|
18329
|
+
return url;
|
|
18330
|
+
};
|
|
18331
|
+
createQuerySerializer = ({
|
|
18332
|
+
parameters = {},
|
|
18333
|
+
...args
|
|
18334
|
+
} = {}) => {
|
|
18335
|
+
const querySerializer = (queryParams) => {
|
|
18336
|
+
const search = [];
|
|
18337
|
+
if (queryParams && typeof queryParams === "object") {
|
|
18338
|
+
for (const name in queryParams) {
|
|
18339
|
+
const value = queryParams[name];
|
|
18340
|
+
if (value === void 0 || value === null) {
|
|
18341
|
+
continue;
|
|
18342
|
+
}
|
|
18343
|
+
const options = parameters[name] || args;
|
|
18344
|
+
if (Array.isArray(value)) {
|
|
18345
|
+
const serializedArray = serializeArrayParam({
|
|
18346
|
+
allowReserved: options.allowReserved,
|
|
18347
|
+
explode: true,
|
|
18348
|
+
name,
|
|
18349
|
+
style: "form",
|
|
18350
|
+
value,
|
|
18351
|
+
...options.array
|
|
18352
|
+
});
|
|
18353
|
+
if (serializedArray) search.push(serializedArray);
|
|
18354
|
+
} else if (typeof value === "object") {
|
|
18355
|
+
const serializedObject = serializeObjectParam({
|
|
18356
|
+
allowReserved: options.allowReserved,
|
|
18357
|
+
explode: true,
|
|
18358
|
+
name,
|
|
18359
|
+
style: "deepObject",
|
|
18360
|
+
value,
|
|
18361
|
+
...options.object
|
|
18362
|
+
});
|
|
18363
|
+
if (serializedObject) search.push(serializedObject);
|
|
18364
|
+
} else {
|
|
18365
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
18366
|
+
allowReserved: options.allowReserved,
|
|
18367
|
+
name,
|
|
18368
|
+
value
|
|
18369
|
+
});
|
|
18370
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
18371
|
+
}
|
|
18372
|
+
}
|
|
18373
|
+
}
|
|
18374
|
+
return search.join("&");
|
|
18375
|
+
};
|
|
18376
|
+
return querySerializer;
|
|
18377
|
+
};
|
|
18378
|
+
getParseAs = (contentType) => {
|
|
18379
|
+
if (!contentType) {
|
|
18380
|
+
return "stream";
|
|
18381
|
+
}
|
|
18382
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
18383
|
+
if (!cleanContent) {
|
|
18384
|
+
return;
|
|
18385
|
+
}
|
|
18386
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
18387
|
+
return "json";
|
|
18388
|
+
}
|
|
18389
|
+
if (cleanContent === "multipart/form-data") {
|
|
18390
|
+
return "formData";
|
|
18391
|
+
}
|
|
18392
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
18393
|
+
return "blob";
|
|
18394
|
+
}
|
|
18395
|
+
if (cleanContent.startsWith("text/")) {
|
|
18396
|
+
return "text";
|
|
18397
|
+
}
|
|
18398
|
+
return;
|
|
18399
|
+
};
|
|
18400
|
+
checkForExistence = (options, name) => {
|
|
18401
|
+
if (!name) {
|
|
18402
|
+
return false;
|
|
18403
|
+
}
|
|
18404
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
18405
|
+
return true;
|
|
18406
|
+
}
|
|
18407
|
+
return false;
|
|
18408
|
+
};
|
|
18409
|
+
buildUrl = (options) => {
|
|
18410
|
+
const url = getUrl({
|
|
18411
|
+
baseUrl: options.baseUrl,
|
|
18412
|
+
path: options.path,
|
|
18413
|
+
query: options.query,
|
|
18414
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
18415
|
+
url: options.url
|
|
18416
|
+
});
|
|
18417
|
+
return url;
|
|
18418
|
+
};
|
|
18419
|
+
getUrl = ({
|
|
18420
|
+
baseUrl,
|
|
18421
|
+
path,
|
|
18422
|
+
query,
|
|
18423
|
+
querySerializer,
|
|
18424
|
+
url: _url
|
|
18425
|
+
}) => {
|
|
18426
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
18427
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
18428
|
+
if (path) {
|
|
18429
|
+
url = defaultPathSerializer({ path, url });
|
|
18430
|
+
}
|
|
18431
|
+
let search = query ? querySerializer(query) : "";
|
|
18432
|
+
if (search.startsWith("?")) {
|
|
18433
|
+
search = search.substring(1);
|
|
18434
|
+
}
|
|
18435
|
+
if (search) {
|
|
18436
|
+
url += `?${search}`;
|
|
18437
|
+
}
|
|
18438
|
+
return url;
|
|
18439
|
+
};
|
|
18440
|
+
mergeConfigs = (a, b) => {
|
|
18441
|
+
const config = { ...a, ...b };
|
|
18442
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
18443
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
18444
|
+
}
|
|
18445
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
18446
|
+
return config;
|
|
18447
|
+
};
|
|
18448
|
+
headersEntries = (headers) => {
|
|
18449
|
+
const entries = [];
|
|
18450
|
+
headers.forEach((value, key) => {
|
|
18451
|
+
entries.push([key, value]);
|
|
18452
|
+
});
|
|
18453
|
+
return entries;
|
|
18454
|
+
};
|
|
18455
|
+
mergeHeaders = (...headers) => {
|
|
18456
|
+
const mergedHeaders = new Headers();
|
|
18457
|
+
for (const header of headers) {
|
|
18458
|
+
if (!header || typeof header !== "object") {
|
|
18459
|
+
continue;
|
|
18460
|
+
}
|
|
18461
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
18462
|
+
for (const [key, value] of iterator) {
|
|
18463
|
+
if (value === null) {
|
|
18464
|
+
mergedHeaders.delete(key);
|
|
18465
|
+
} else if (Array.isArray(value)) {
|
|
18466
|
+
for (const v of value) {
|
|
18467
|
+
mergedHeaders.append(key, v);
|
|
18468
|
+
}
|
|
18469
|
+
} else if (value !== void 0) {
|
|
18470
|
+
mergedHeaders.set(
|
|
18471
|
+
key,
|
|
18472
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
18473
|
+
);
|
|
18474
|
+
}
|
|
18475
|
+
}
|
|
18476
|
+
}
|
|
18477
|
+
return mergedHeaders;
|
|
18478
|
+
};
|
|
18479
|
+
Interceptors = class {
|
|
18480
|
+
constructor() {
|
|
18481
|
+
this.fns = [];
|
|
18482
|
+
}
|
|
18483
|
+
clear() {
|
|
18484
|
+
this.fns = [];
|
|
18485
|
+
}
|
|
18486
|
+
eject(id) {
|
|
18487
|
+
const index = this.getInterceptorIndex(id);
|
|
18488
|
+
if (this.fns[index]) {
|
|
18489
|
+
this.fns[index] = null;
|
|
18490
|
+
}
|
|
18491
|
+
}
|
|
18492
|
+
exists(id) {
|
|
18493
|
+
const index = this.getInterceptorIndex(id);
|
|
18494
|
+
return Boolean(this.fns[index]);
|
|
18495
|
+
}
|
|
18496
|
+
getInterceptorIndex(id) {
|
|
18497
|
+
if (typeof id === "number") {
|
|
18498
|
+
return this.fns[id] ? id : -1;
|
|
18499
|
+
}
|
|
18500
|
+
return this.fns.indexOf(id);
|
|
18501
|
+
}
|
|
18502
|
+
update(id, fn) {
|
|
18503
|
+
const index = this.getInterceptorIndex(id);
|
|
18504
|
+
if (this.fns[index]) {
|
|
18505
|
+
this.fns[index] = fn;
|
|
18506
|
+
return id;
|
|
18507
|
+
}
|
|
18508
|
+
return false;
|
|
18509
|
+
}
|
|
18510
|
+
use(fn) {
|
|
18511
|
+
this.fns.push(fn);
|
|
18512
|
+
return this.fns.length - 1;
|
|
18513
|
+
}
|
|
18514
|
+
};
|
|
18515
|
+
createInterceptors = () => ({
|
|
18516
|
+
error: new Interceptors(),
|
|
18517
|
+
request: new Interceptors(),
|
|
18518
|
+
response: new Interceptors()
|
|
18519
|
+
});
|
|
18520
|
+
defaultQuerySerializer = createQuerySerializer({
|
|
18521
|
+
allowReserved: false,
|
|
18522
|
+
array: {
|
|
18523
|
+
explode: true,
|
|
18524
|
+
style: "form"
|
|
18525
|
+
},
|
|
18526
|
+
object: {
|
|
18527
|
+
explode: true,
|
|
18528
|
+
style: "deepObject"
|
|
18529
|
+
}
|
|
18530
|
+
});
|
|
18531
|
+
defaultHeaders = {
|
|
18532
|
+
"Content-Type": "application/json"
|
|
18533
|
+
};
|
|
18534
|
+
createConfig = (override = {}) => ({
|
|
18535
|
+
...jsonBodySerializer,
|
|
18536
|
+
headers: defaultHeaders,
|
|
18537
|
+
parseAs: "auto",
|
|
18538
|
+
querySerializer: defaultQuerySerializer,
|
|
18539
|
+
...override
|
|
18540
|
+
});
|
|
18541
|
+
}
|
|
18542
|
+
});
|
|
18543
|
+
|
|
18544
|
+
// src/client/client/client.gen.ts
|
|
18545
|
+
var createClient;
|
|
18546
|
+
var init_client_gen = __esm({
|
|
18547
|
+
"src/client/client/client.gen.ts"() {
|
|
18548
|
+
"use strict";
|
|
18549
|
+
init_serverSentEvents_gen();
|
|
18550
|
+
init_utils_gen();
|
|
18551
|
+
init_utils_gen2();
|
|
18552
|
+
createClient = (config = {}) => {
|
|
18553
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
18554
|
+
const getConfig = () => ({ ..._config });
|
|
18555
|
+
const setConfig = (config2) => {
|
|
18556
|
+
_config = mergeConfigs(_config, config2);
|
|
18557
|
+
return getConfig();
|
|
18558
|
+
};
|
|
18559
|
+
const interceptors = createInterceptors();
|
|
18560
|
+
const beforeRequest = async (options) => {
|
|
18561
|
+
const opts = {
|
|
18562
|
+
..._config,
|
|
18563
|
+
...options,
|
|
18564
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18565
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
18566
|
+
serializedBody: void 0
|
|
18567
|
+
};
|
|
18568
|
+
if (opts.security) {
|
|
18569
|
+
await setAuthParams(opts);
|
|
18570
|
+
}
|
|
18571
|
+
if (opts.requestValidator) {
|
|
18572
|
+
await opts.requestValidator(opts);
|
|
18573
|
+
}
|
|
18574
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
18575
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
18576
|
+
}
|
|
18577
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
18578
|
+
opts.headers.delete("Content-Type");
|
|
18579
|
+
}
|
|
18580
|
+
const resolvedOpts = opts;
|
|
18581
|
+
const url = buildUrl(resolvedOpts);
|
|
18582
|
+
return { opts: resolvedOpts, url };
|
|
18583
|
+
};
|
|
18584
|
+
const request = async (options) => {
|
|
18585
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
18586
|
+
let response;
|
|
18587
|
+
try {
|
|
18588
|
+
const { opts, url } = await beforeRequest(options);
|
|
18589
|
+
for (const fn of interceptors.request.fns) {
|
|
18590
|
+
if (fn) {
|
|
18591
|
+
await fn(opts);
|
|
18592
|
+
}
|
|
18593
|
+
}
|
|
18594
|
+
const _fetch = opts.fetch;
|
|
18595
|
+
const requestInit = {
|
|
18596
|
+
...opts,
|
|
18597
|
+
body: getValidRequestBody(opts)
|
|
18598
|
+
};
|
|
18599
|
+
response = await _fetch(url, requestInit);
|
|
18600
|
+
for (const fn of interceptors.response.fns) {
|
|
18601
|
+
if (fn) {
|
|
18602
|
+
response = await fn(response, opts);
|
|
18603
|
+
}
|
|
18604
|
+
}
|
|
18605
|
+
const result = {
|
|
18606
|
+
response
|
|
18607
|
+
};
|
|
18608
|
+
if (response.ok) {
|
|
18609
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
18610
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
18611
|
+
let emptyData;
|
|
18612
|
+
switch (parseAs) {
|
|
18613
|
+
case "arrayBuffer":
|
|
18614
|
+
case "blob":
|
|
18615
|
+
case "text":
|
|
18616
|
+
emptyData = await response[parseAs]();
|
|
18617
|
+
break;
|
|
18618
|
+
case "formData":
|
|
18619
|
+
emptyData = new FormData();
|
|
18620
|
+
break;
|
|
18621
|
+
case "stream":
|
|
18622
|
+
emptyData = response.body;
|
|
18623
|
+
break;
|
|
18624
|
+
case "json":
|
|
18625
|
+
default:
|
|
18626
|
+
emptyData = {};
|
|
18627
|
+
break;
|
|
18628
|
+
}
|
|
18629
|
+
return {
|
|
18630
|
+
data: emptyData,
|
|
18631
|
+
...result
|
|
18632
|
+
};
|
|
18633
|
+
}
|
|
18634
|
+
let data;
|
|
18635
|
+
switch (parseAs) {
|
|
18636
|
+
case "arrayBuffer":
|
|
18637
|
+
case "blob":
|
|
18638
|
+
case "formData":
|
|
18639
|
+
case "text":
|
|
18640
|
+
data = await response[parseAs]();
|
|
18641
|
+
break;
|
|
18642
|
+
case "json": {
|
|
18643
|
+
const text12 = await response.text();
|
|
18644
|
+
data = text12 ? JSON.parse(text12) : {};
|
|
18645
|
+
break;
|
|
18646
|
+
}
|
|
18647
|
+
case "stream":
|
|
18648
|
+
return {
|
|
18649
|
+
data: response.body,
|
|
18650
|
+
...result
|
|
18651
|
+
};
|
|
18652
|
+
}
|
|
18653
|
+
if (parseAs === "json") {
|
|
18654
|
+
if (opts.responseValidator) {
|
|
18655
|
+
await opts.responseValidator(data);
|
|
18656
|
+
}
|
|
18657
|
+
if (opts.responseTransformer) {
|
|
18658
|
+
data = await opts.responseTransformer(data);
|
|
18659
|
+
}
|
|
18660
|
+
}
|
|
18661
|
+
return {
|
|
18662
|
+
data,
|
|
18663
|
+
...result
|
|
18664
|
+
};
|
|
18665
|
+
}
|
|
18666
|
+
const textError = await response.text();
|
|
18667
|
+
let jsonError;
|
|
18668
|
+
try {
|
|
18669
|
+
jsonError = JSON.parse(textError);
|
|
18670
|
+
} catch {
|
|
18671
|
+
}
|
|
18672
|
+
throw jsonError ?? textError;
|
|
18673
|
+
} catch (error) {
|
|
18674
|
+
let finalError = error;
|
|
18675
|
+
for (const fn of interceptors.error.fns) {
|
|
18676
|
+
if (fn) {
|
|
18677
|
+
finalError = await fn(finalError, response, options);
|
|
18678
|
+
}
|
|
18679
|
+
}
|
|
18680
|
+
finalError = finalError || {};
|
|
18681
|
+
if (throwOnError) {
|
|
18682
|
+
throw finalError;
|
|
18683
|
+
}
|
|
18684
|
+
return {
|
|
18685
|
+
error: finalError,
|
|
18686
|
+
response
|
|
18687
|
+
};
|
|
18688
|
+
}
|
|
18689
|
+
};
|
|
18690
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
18691
|
+
const makeSseFn = (method) => async (options) => {
|
|
18692
|
+
const { opts, url } = await beforeRequest(options);
|
|
18693
|
+
return createSseClient({
|
|
18694
|
+
...opts,
|
|
18695
|
+
body: opts.body,
|
|
18696
|
+
method,
|
|
18697
|
+
onRequest: async (url2, init) => {
|
|
18698
|
+
let request2 = new Request(url2, init);
|
|
18699
|
+
const requestInit = { ...init, url: url2 };
|
|
18700
|
+
for (const fn of interceptors.request.fns) {
|
|
18701
|
+
if (fn) {
|
|
18702
|
+
await fn(requestInit);
|
|
18703
|
+
request2 = new Request(requestInit.url, requestInit);
|
|
18704
|
+
}
|
|
18705
|
+
}
|
|
18706
|
+
return request2;
|
|
18707
|
+
},
|
|
18708
|
+
serializedBody: getValidRequestBody(opts),
|
|
18709
|
+
url
|
|
18710
|
+
});
|
|
18711
|
+
};
|
|
18712
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
18713
|
+
return {
|
|
18714
|
+
buildUrl: _buildUrl,
|
|
18715
|
+
connect: makeMethodFn("CONNECT"),
|
|
18716
|
+
delete: makeMethodFn("DELETE"),
|
|
18717
|
+
get: makeMethodFn("GET"),
|
|
18718
|
+
getConfig,
|
|
18719
|
+
head: makeMethodFn("HEAD"),
|
|
18720
|
+
interceptors,
|
|
18721
|
+
options: makeMethodFn("OPTIONS"),
|
|
18722
|
+
patch: makeMethodFn("PATCH"),
|
|
18723
|
+
post: makeMethodFn("POST"),
|
|
18724
|
+
put: makeMethodFn("PUT"),
|
|
18725
|
+
request,
|
|
18726
|
+
setConfig,
|
|
18727
|
+
sse: {
|
|
18728
|
+
connect: makeSseFn("CONNECT"),
|
|
18729
|
+
delete: makeSseFn("DELETE"),
|
|
18730
|
+
get: makeSseFn("GET"),
|
|
18731
|
+
head: makeSseFn("HEAD"),
|
|
18732
|
+
options: makeSseFn("OPTIONS"),
|
|
18733
|
+
patch: makeSseFn("PATCH"),
|
|
18734
|
+
post: makeSseFn("POST"),
|
|
18735
|
+
put: makeSseFn("PUT"),
|
|
18736
|
+
trace: makeSseFn("TRACE")
|
|
18737
|
+
},
|
|
18738
|
+
trace: makeMethodFn("TRACE")
|
|
18739
|
+
};
|
|
18740
|
+
};
|
|
18741
|
+
}
|
|
18742
|
+
});
|
|
18743
|
+
|
|
18744
|
+
// src/client/client/index.ts
|
|
18745
|
+
var init_client = __esm({
|
|
18746
|
+
"src/client/client/index.ts"() {
|
|
18747
|
+
"use strict";
|
|
18748
|
+
init_client_gen();
|
|
18749
|
+
init_utils_gen2();
|
|
18750
|
+
}
|
|
18751
|
+
});
|
|
18752
|
+
|
|
18753
|
+
// src/client/client.gen.ts
|
|
18754
|
+
var client;
|
|
18755
|
+
var init_client_gen2 = __esm({
|
|
18756
|
+
"src/client/client.gen.ts"() {
|
|
18757
|
+
"use strict";
|
|
18758
|
+
init_clientConfig();
|
|
18759
|
+
init_client();
|
|
18760
|
+
client = createClient(createClientConfig(createConfig()));
|
|
18761
|
+
}
|
|
18762
|
+
});
|
|
18763
|
+
|
|
18764
|
+
// src/client/sdk.gen.ts
|
|
18765
|
+
var postApiV1Embeddings;
|
|
18766
|
+
var init_sdk_gen = __esm({
|
|
18767
|
+
"src/client/sdk.gen.ts"() {
|
|
18768
|
+
"use strict";
|
|
18769
|
+
init_client_gen2();
|
|
18770
|
+
postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
18771
|
+
url: "/api/v1/embeddings",
|
|
18772
|
+
...options,
|
|
18773
|
+
headers: {
|
|
18774
|
+
"Content-Type": "application/json",
|
|
18775
|
+
...options.headers
|
|
18776
|
+
}
|
|
18777
|
+
});
|
|
18778
|
+
}
|
|
18779
|
+
});
|
|
18780
|
+
|
|
18781
|
+
// src/client/index.ts
|
|
18782
|
+
var init_client2 = __esm({
|
|
18783
|
+
"src/client/index.ts"() {
|
|
18784
|
+
"use strict";
|
|
18785
|
+
init_sdk_gen();
|
|
18786
|
+
}
|
|
18787
|
+
});
|
|
18788
|
+
|
|
17921
18789
|
// src/lib/memoryEngine/generate.ts
|
|
17922
18790
|
async function withEmbeddingRetry(call) {
|
|
17923
18791
|
let last;
|
|
@@ -17972,7 +18840,7 @@ async function generateEmbedding(text12, options) {
|
|
|
17972
18840
|
throw new Error("Either apiKey or getToken must be provided");
|
|
17973
18841
|
}
|
|
17974
18842
|
const response = await withEmbeddingRetry(
|
|
17975
|
-
() =>
|
|
18843
|
+
() => postApiV1Embeddings({
|
|
17976
18844
|
baseUrl,
|
|
17977
18845
|
body: {
|
|
17978
18846
|
// Mask PII from the request body only — the cache above still keys on
|
|
@@ -18004,7 +18872,7 @@ async function generateEmbedding(text12, options) {
|
|
|
18004
18872
|
}
|
|
18005
18873
|
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput) {
|
|
18006
18874
|
const response = await withEmbeddingRetry(
|
|
18007
|
-
() =>
|
|
18875
|
+
() => postApiV1Embeddings({
|
|
18008
18876
|
baseUrl,
|
|
18009
18877
|
// Mask PII from the request body only; cache/order still key on originals.
|
|
18010
18878
|
body: { input: maskInput ? texts.map(maskInput) : texts, model },
|
|
@@ -18105,11 +18973,11 @@ async function generateEmbeddings(texts, options) {
|
|
|
18105
18973
|
}
|
|
18106
18974
|
return results;
|
|
18107
18975
|
}
|
|
18108
|
-
var
|
|
18976
|
+
var EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
|
|
18109
18977
|
var init_generate = __esm({
|
|
18110
18978
|
"src/lib/memoryEngine/generate.ts"() {
|
|
18111
18979
|
"use strict";
|
|
18112
|
-
|
|
18980
|
+
init_client2();
|
|
18113
18981
|
init_clientConfig();
|
|
18114
18982
|
init_constants();
|
|
18115
18983
|
EMBED_MAX_ATTEMPTS = 4;
|
|
@@ -23724,17 +24592,17 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
23724
24592
|
}
|
|
23725
24593
|
case "sql": {
|
|
23726
24594
|
if (this._pgSchema !== "public" && this.pool.connect) {
|
|
23727
|
-
const
|
|
24595
|
+
const client2 = await this.pool.connect();
|
|
23728
24596
|
try {
|
|
23729
|
-
await
|
|
23730
|
-
await
|
|
23731
|
-
await
|
|
23732
|
-
await
|
|
24597
|
+
await client2.query("BEGIN");
|
|
24598
|
+
await client2.query(`SET LOCAL search_path TO "${this._pgSchema}", public`);
|
|
24599
|
+
await client2.query(step.sql);
|
|
24600
|
+
await client2.query("COMMIT");
|
|
23733
24601
|
} catch (err) {
|
|
23734
|
-
await
|
|
24602
|
+
await client2.query("ROLLBACK");
|
|
23735
24603
|
throw err;
|
|
23736
24604
|
} finally {
|
|
23737
|
-
|
|
24605
|
+
client2.release();
|
|
23738
24606
|
}
|
|
23739
24607
|
} else {
|
|
23740
24608
|
await this.pool.query(step.sql);
|
|
@@ -23880,16 +24748,16 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
23880
24748
|
}
|
|
23881
24749
|
};
|
|
23882
24750
|
if (this.pool.connect) {
|
|
23883
|
-
const
|
|
24751
|
+
const client2 = await this.pool.connect();
|
|
23884
24752
|
try {
|
|
23885
|
-
await
|
|
23886
|
-
await runOps(
|
|
23887
|
-
await
|
|
24753
|
+
await client2.query("BEGIN");
|
|
24754
|
+
await runOps(client2);
|
|
24755
|
+
await client2.query("COMMIT");
|
|
23888
24756
|
} catch (err) {
|
|
23889
|
-
await
|
|
24757
|
+
await client2.query("ROLLBACK");
|
|
23890
24758
|
throw err;
|
|
23891
24759
|
} finally {
|
|
23892
|
-
|
|
24760
|
+
client2.release();
|
|
23893
24761
|
}
|
|
23894
24762
|
} else {
|
|
23895
24763
|
await runOps(this.pool);
|
|
@@ -30410,134 +31278,8 @@ function createCryptoPricePreProcessor(options = {}) {
|
|
|
30410
31278
|
// src/lib/chat/resumeStream.ts
|
|
30411
31279
|
init_clientConfig();
|
|
30412
31280
|
|
|
30413
|
-
// src/client/core/serverSentEvents.gen.ts
|
|
30414
|
-
function createSseClient({
|
|
30415
|
-
onRequest,
|
|
30416
|
-
onSseError,
|
|
30417
|
-
onSseEvent,
|
|
30418
|
-
responseTransformer,
|
|
30419
|
-
responseValidator,
|
|
30420
|
-
sseDefaultRetryDelay,
|
|
30421
|
-
sseMaxRetryAttempts,
|
|
30422
|
-
sseMaxRetryDelay,
|
|
30423
|
-
sseSleepFn,
|
|
30424
|
-
url,
|
|
30425
|
-
...options
|
|
30426
|
-
}) {
|
|
30427
|
-
let lastEventId;
|
|
30428
|
-
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
30429
|
-
const createStream = async function* () {
|
|
30430
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
30431
|
-
let attempt = 0;
|
|
30432
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
30433
|
-
while (true) {
|
|
30434
|
-
if (signal.aborted) break;
|
|
30435
|
-
attempt++;
|
|
30436
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
30437
|
-
if (lastEventId !== void 0) {
|
|
30438
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
30439
|
-
}
|
|
30440
|
-
try {
|
|
30441
|
-
const requestInit = {
|
|
30442
|
-
redirect: "follow",
|
|
30443
|
-
...options,
|
|
30444
|
-
body: options.serializedBody,
|
|
30445
|
-
headers,
|
|
30446
|
-
signal
|
|
30447
|
-
};
|
|
30448
|
-
let request = new Request(url, requestInit);
|
|
30449
|
-
if (onRequest) {
|
|
30450
|
-
request = await onRequest(url, requestInit);
|
|
30451
|
-
}
|
|
30452
|
-
const _fetch = options.fetch ?? globalThis.fetch;
|
|
30453
|
-
const response = await _fetch(request);
|
|
30454
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
30455
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
30456
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
30457
|
-
let buffer = "";
|
|
30458
|
-
const abortHandler = () => {
|
|
30459
|
-
try {
|
|
30460
|
-
reader.cancel();
|
|
30461
|
-
} catch {
|
|
30462
|
-
}
|
|
30463
|
-
};
|
|
30464
|
-
signal.addEventListener("abort", abortHandler);
|
|
30465
|
-
try {
|
|
30466
|
-
while (true) {
|
|
30467
|
-
const { done, value } = await reader.read();
|
|
30468
|
-
if (done) break;
|
|
30469
|
-
buffer += value;
|
|
30470
|
-
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
30471
|
-
const chunks = buffer.split("\n\n");
|
|
30472
|
-
buffer = chunks.pop() ?? "";
|
|
30473
|
-
for (const chunk of chunks) {
|
|
30474
|
-
const lines = chunk.split("\n");
|
|
30475
|
-
const dataLines = [];
|
|
30476
|
-
let eventName;
|
|
30477
|
-
for (const line of lines) {
|
|
30478
|
-
if (line.startsWith("data:")) {
|
|
30479
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
30480
|
-
} else if (line.startsWith("event:")) {
|
|
30481
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
30482
|
-
} else if (line.startsWith("id:")) {
|
|
30483
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
30484
|
-
} else if (line.startsWith("retry:")) {
|
|
30485
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
30486
|
-
if (!Number.isNaN(parsed)) {
|
|
30487
|
-
retryDelay = parsed;
|
|
30488
|
-
}
|
|
30489
|
-
}
|
|
30490
|
-
}
|
|
30491
|
-
let data;
|
|
30492
|
-
let parsedJson = false;
|
|
30493
|
-
if (dataLines.length) {
|
|
30494
|
-
const rawData = dataLines.join("\n");
|
|
30495
|
-
try {
|
|
30496
|
-
data = JSON.parse(rawData);
|
|
30497
|
-
parsedJson = true;
|
|
30498
|
-
} catch {
|
|
30499
|
-
data = rawData;
|
|
30500
|
-
}
|
|
30501
|
-
}
|
|
30502
|
-
if (parsedJson) {
|
|
30503
|
-
if (responseValidator) {
|
|
30504
|
-
await responseValidator(data);
|
|
30505
|
-
}
|
|
30506
|
-
if (responseTransformer) {
|
|
30507
|
-
data = await responseTransformer(data);
|
|
30508
|
-
}
|
|
30509
|
-
}
|
|
30510
|
-
onSseEvent?.({
|
|
30511
|
-
data,
|
|
30512
|
-
event: eventName,
|
|
30513
|
-
id: lastEventId,
|
|
30514
|
-
retry: retryDelay
|
|
30515
|
-
});
|
|
30516
|
-
if (dataLines.length) {
|
|
30517
|
-
yield data;
|
|
30518
|
-
}
|
|
30519
|
-
}
|
|
30520
|
-
}
|
|
30521
|
-
} finally {
|
|
30522
|
-
signal.removeEventListener("abort", abortHandler);
|
|
30523
|
-
reader.releaseLock();
|
|
30524
|
-
}
|
|
30525
|
-
break;
|
|
30526
|
-
} catch (error) {
|
|
30527
|
-
onSseError?.(error);
|
|
30528
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
30529
|
-
break;
|
|
30530
|
-
}
|
|
30531
|
-
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
30532
|
-
await sleep4(backoff);
|
|
30533
|
-
}
|
|
30534
|
-
}
|
|
30535
|
-
};
|
|
30536
|
-
const stream = createStream();
|
|
30537
|
-
return { stream };
|
|
30538
|
-
}
|
|
30539
|
-
|
|
30540
31281
|
// src/lib/chat/toolLoop.ts
|
|
31282
|
+
init_serverSentEvents_gen();
|
|
30541
31283
|
init_clientConfig();
|
|
30542
31284
|
init_embeddings();
|
|
30543
31285
|
init_redactor();
|