@anuma/sdk 2.7.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-TCRDSUC6.mjs → chunk-22CSPJLL.mjs} +164 -891
- package/dist/expo/index.cjs +1812 -1112
- package/dist/expo/index.d.mts +226 -12
- package/dist/expo/index.d.ts +226 -12
- package/dist/expo/index.mjs +1558 -68
- package/dist/expo/{recall-FQU3NUTL.mjs → recall-LICO3TJ7.mjs} +1 -1
- package/dist/index.cjs +418 -395
- package/dist/index.mjs +415 -392
- package/dist/react/{chunk-ZXS3KOY4.mjs → chunk-FD5MB73N.mjs} +158 -1030
- package/dist/react/index.cjs +1839 -1742
- package/dist/react/index.d.mts +150 -14
- package/dist/react/index.d.ts +150 -14
- package/dist/react/index.mjs +1235 -229
- package/dist/react/{recall-PV7L3SN3.mjs → recall-FPACUZGD.mjs} +1 -1
- package/dist/server/{chunk-Z6II54I7.mjs → chunk-RKUNGNBF.mjs} +163 -842
- package/dist/server/index.cjs +392 -970
- package/dist/server/index.d.mts +170 -14
- package/dist/server/index.d.ts +170 -14
- package/dist/server/index.mjs +198 -27
- package/dist/server/{recall-CQT24XLH.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
|
@@ -15242,6 +15242,15 @@ async function encryptData(plaintext, address) {
|
|
|
15242
15242
|
const key = await getEncryptionKey(address);
|
|
15243
15243
|
return encryptDataWithKey(plaintext, key);
|
|
15244
15244
|
}
|
|
15245
|
+
async function encryptDataBytes(plaintext, address) {
|
|
15246
|
+
if (!isValidWalletAddress(address)) {
|
|
15247
|
+
throw new Error(
|
|
15248
|
+
`Invalid wallet address: ${address}. Address must start with 0x and be 42 characters (0x + 40 hex characters).`
|
|
15249
|
+
);
|
|
15250
|
+
}
|
|
15251
|
+
const key = await getEncryptionKey(address);
|
|
15252
|
+
return encryptBytesWithKey(plaintext, key);
|
|
15253
|
+
}
|
|
15245
15254
|
async function decryptData(encryptedHex, address, version = "v3") {
|
|
15246
15255
|
const key = await getEncryptionKey(address, version);
|
|
15247
15256
|
return decryptDataWithKey(encryptedHex, key);
|
|
@@ -15261,6 +15270,20 @@ async function decryptDataBytes(encryptedHex, address, version = "v3") {
|
|
|
15261
15270
|
);
|
|
15262
15271
|
return new Uint8Array(decryptedData);
|
|
15263
15272
|
}
|
|
15273
|
+
async function decryptDataBytesFromBytes(encrypted, address, version = "v3") {
|
|
15274
|
+
const key = await getEncryptionKey(address, version);
|
|
15275
|
+
const iv = encrypted.subarray(0, 12);
|
|
15276
|
+
const encryptedData = encrypted.subarray(12);
|
|
15277
|
+
const decryptedData = await crypto.subtle.decrypt(
|
|
15278
|
+
{
|
|
15279
|
+
name: "AES-GCM",
|
|
15280
|
+
iv
|
|
15281
|
+
},
|
|
15282
|
+
key,
|
|
15283
|
+
encryptedData
|
|
15284
|
+
);
|
|
15285
|
+
return new Uint8Array(decryptedData);
|
|
15286
|
+
}
|
|
15264
15287
|
function hasEncryptionKey(address) {
|
|
15265
15288
|
return getStoredKey(address) !== null;
|
|
15266
15289
|
}
|
|
@@ -15954,6 +15977,67 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
|
|
|
15954
15977
|
}
|
|
15955
15978
|
return baseMessage;
|
|
15956
15979
|
}
|
|
15980
|
+
function rawDate(value) {
|
|
15981
|
+
return new Date(typeof value === "number" ? value : 0);
|
|
15982
|
+
}
|
|
15983
|
+
function messageRawToStoredRaw(raw, projection) {
|
|
15984
|
+
const parseJsonField = (rawValue) => {
|
|
15985
|
+
if (!rawValue) return void 0;
|
|
15986
|
+
if (typeof rawValue === "string") {
|
|
15987
|
+
if (rawValue.startsWith("enc:")) return rawValue;
|
|
15988
|
+
try {
|
|
15989
|
+
return JSON.parse(rawValue);
|
|
15990
|
+
} catch {
|
|
15991
|
+
return void 0;
|
|
15992
|
+
}
|
|
15993
|
+
}
|
|
15994
|
+
return rawValue;
|
|
15995
|
+
};
|
|
15996
|
+
const skipEmbeddings = projection?.skipEmbeddings === true;
|
|
15997
|
+
const vectorRaw = skipEmbeddings ? null : raw.vector;
|
|
15998
|
+
const chunksRaw = skipEmbeddings ? null : raw.chunks;
|
|
15999
|
+
return {
|
|
16000
|
+
uniqueId: raw.id,
|
|
16001
|
+
messageId: raw.message_id,
|
|
16002
|
+
conversationId: raw.conversation_id ?? "",
|
|
16003
|
+
role: raw.role ?? "",
|
|
16004
|
+
content: raw.content ?? "",
|
|
16005
|
+
model: raw.model,
|
|
16006
|
+
imageModel: raw.image_model,
|
|
16007
|
+
files: parseJsonField(raw.files),
|
|
16008
|
+
fileIds: parseJsonField(raw.file_ids),
|
|
16009
|
+
createdAt: rawDate(raw.created_at),
|
|
16010
|
+
updatedAt: rawDate(raw.updated_at),
|
|
16011
|
+
vector: skipEmbeddings ? void 0 : parseJsonField(vectorRaw),
|
|
16012
|
+
embeddingModel: raw.embedding_model,
|
|
16013
|
+
chunks: skipEmbeddings ? void 0 : parseJsonField(chunksRaw),
|
|
16014
|
+
usage: parseJsonField(raw.usage),
|
|
16015
|
+
sources: parseJsonField(raw.sources),
|
|
16016
|
+
responseDuration: raw.response_duration,
|
|
16017
|
+
// `was_stopped` is an OPTIONAL boolean: an unset row sanitizes to null, and the Model path
|
|
16018
|
+
// (message.wasStopped) returns that null verbatim. Preserve it (don't collapse to false) so the
|
|
16019
|
+
// raw path is byte-identical. When set, coerce SQLite 0/1 and LokiJS true/false alike.
|
|
16020
|
+
wasStopped: raw.was_stopped === null || raw.was_stopped === void 0 ? raw.was_stopped : raw.was_stopped === true || raw.was_stopped === 1,
|
|
16021
|
+
error: raw.error,
|
|
16022
|
+
thoughtProcess: parseJsonField(raw.thought_process),
|
|
16023
|
+
thinking: raw.thinking,
|
|
16024
|
+
parentMessageId: raw.parent_message_id,
|
|
16025
|
+
feedback: raw.feedback || null,
|
|
16026
|
+
toolCallEvents: parseJsonField(raw.tool_call_events)
|
|
16027
|
+
};
|
|
16028
|
+
}
|
|
16029
|
+
async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
|
|
16030
|
+
const baseMessage = messageRawToStoredRaw(raw, projection);
|
|
16031
|
+
if (walletAddress) {
|
|
16032
|
+
return await decryptMessageFields(
|
|
16033
|
+
baseMessage,
|
|
16034
|
+
walletAddress,
|
|
16035
|
+
signMessage,
|
|
16036
|
+
embeddedWalletSigner
|
|
16037
|
+
);
|
|
16038
|
+
}
|
|
16039
|
+
return baseMessage;
|
|
16040
|
+
}
|
|
15957
16041
|
function conversationToStoredRaw(conversation) {
|
|
15958
16042
|
return {
|
|
15959
16043
|
uniqueId: conversation.id,
|
|
@@ -15978,6 +16062,33 @@ async function conversationToStored(conversation, walletAddress, signMessage, em
|
|
|
15978
16062
|
}
|
|
15979
16063
|
return baseConversation;
|
|
15980
16064
|
}
|
|
16065
|
+
function conversationRawToStoredRaw(raw) {
|
|
16066
|
+
const pinnedAt = raw.pinned_at;
|
|
16067
|
+
return {
|
|
16068
|
+
uniqueId: raw.id,
|
|
16069
|
+
conversationId: raw.conversation_id ?? "",
|
|
16070
|
+
title: raw.title ?? "",
|
|
16071
|
+
projectId: raw.project_id,
|
|
16072
|
+
createdAt: rawDate(raw.created_at),
|
|
16073
|
+
updatedAt: rawDate(raw.updated_at),
|
|
16074
|
+
// SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
|
|
16075
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
16076
|
+
// @date maps a non-number raw column (incl. an explicit unpin null) to null; a number → Date.
|
|
16077
|
+
pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
|
|
16078
|
+
};
|
|
16079
|
+
}
|
|
16080
|
+
async function conversationRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner) {
|
|
16081
|
+
const baseConversation = conversationRawToStoredRaw(raw);
|
|
16082
|
+
if (walletAddress) {
|
|
16083
|
+
return await decryptConversationFields(
|
|
16084
|
+
baseConversation,
|
|
16085
|
+
walletAddress,
|
|
16086
|
+
signMessage,
|
|
16087
|
+
embeddedWalletSigner
|
|
16088
|
+
);
|
|
16089
|
+
}
|
|
16090
|
+
return baseConversation;
|
|
16091
|
+
}
|
|
15981
16092
|
async function createConversationOp(ctx, opts, defaultTitle = "New Conversation") {
|
|
15982
16093
|
const convId = opts?.conversationId || generateConversationId();
|
|
15983
16094
|
const title = opts?.title || defaultTitle;
|
|
@@ -16017,36 +16128,51 @@ async function getConversationOp(ctx, id) {
|
|
|
16017
16128
|
) : null;
|
|
16018
16129
|
}
|
|
16019
16130
|
async function getConversationsOp(ctx) {
|
|
16020
|
-
const results = await ctx.conversationsCollection.query(import_watermelondb14.Q.where("is_deleted", false), import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)).
|
|
16131
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb14.Q.where("is_deleted", false), import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)).unsafeFetchRaw();
|
|
16021
16132
|
return Promise.all(
|
|
16022
16133
|
results.map(
|
|
16023
|
-
(
|
|
16134
|
+
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
16024
16135
|
)
|
|
16025
16136
|
);
|
|
16026
16137
|
}
|
|
16027
|
-
function
|
|
16138
|
+
function conversationRawToLazyStored(raw) {
|
|
16139
|
+
const pinnedAt = raw.pinned_at;
|
|
16028
16140
|
return {
|
|
16029
|
-
uniqueId:
|
|
16030
|
-
conversationId:
|
|
16031
|
-
encryptedTitle:
|
|
16032
|
-
projectId:
|
|
16033
|
-
createdAt:
|
|
16034
|
-
updatedAt:
|
|
16035
|
-
isDeleted:
|
|
16036
|
-
pinnedAt:
|
|
16141
|
+
uniqueId: raw.id,
|
|
16142
|
+
conversationId: raw.conversation_id ?? "",
|
|
16143
|
+
encryptedTitle: raw.title ?? "",
|
|
16144
|
+
projectId: raw.project_id,
|
|
16145
|
+
createdAt: rawDate(raw.created_at),
|
|
16146
|
+
updatedAt: rawDate(raw.updated_at),
|
|
16147
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
16148
|
+
pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
|
|
16037
16149
|
};
|
|
16038
16150
|
}
|
|
16039
16151
|
async function getConversationsLazyOp(ctx) {
|
|
16040
|
-
const results = await ctx.conversationsCollection.query(import_watermelondb14.Q.where("is_deleted", false), import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)).
|
|
16041
|
-
return results.map(
|
|
16152
|
+
const results = await ctx.conversationsCollection.query(import_watermelondb14.Q.where("is_deleted", false), import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)).unsafeFetchRaw();
|
|
16153
|
+
return results.map(conversationRawToLazyStored);
|
|
16154
|
+
}
|
|
16155
|
+
async function getConversationsPageOp(ctx, options) {
|
|
16156
|
+
const limit = Math.floor(options?.limit ?? 200);
|
|
16157
|
+
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
16158
|
+
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
16159
|
+
const clauses = [import_watermelondb14.Q.where("is_deleted", false)];
|
|
16160
|
+
if (options?.before !== void 0) {
|
|
16161
|
+
clauses.push(
|
|
16162
|
+
exclude.size > 0 ? import_watermelondb14.Q.where("created_at", import_watermelondb14.Q.lte(options.before)) : import_watermelondb14.Q.where("created_at", import_watermelondb14.Q.lt(options.before))
|
|
16163
|
+
);
|
|
16164
|
+
}
|
|
16165
|
+
const fetched = await ctx.conversationsCollection.query(...clauses, import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc), import_watermelondb14.Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
16166
|
+
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
16167
|
+
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
16042
16168
|
}
|
|
16043
16169
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
16044
16170
|
const results = await ctx.conversationsCollection.query(
|
|
16045
16171
|
import_watermelondb14.Q.where("project_id", projectId === null ? "" : projectId),
|
|
16046
16172
|
import_watermelondb14.Q.where("is_deleted", false),
|
|
16047
16173
|
import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)
|
|
16048
|
-
).
|
|
16049
|
-
return results.map(
|
|
16174
|
+
).unsafeFetchRaw();
|
|
16175
|
+
return results.map(conversationRawToLazyStored);
|
|
16050
16176
|
}
|
|
16051
16177
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
16052
16178
|
const results = await ctx.conversationsCollection.query(import_watermelondb14.Q.where("conversation_id", id), import_watermelondb14.Q.where("is_deleted", false)).fetch();
|
|
@@ -16096,18 +16222,18 @@ async function getConversationsByProjectOp(ctx, projectId) {
|
|
|
16096
16222
|
import_watermelondb14.Q.where("project_id", projectId === null ? "" : projectId),
|
|
16097
16223
|
import_watermelondb14.Q.where("is_deleted", false),
|
|
16098
16224
|
import_watermelondb14.Q.sortBy("created_at", import_watermelondb14.Q.desc)
|
|
16099
|
-
).
|
|
16225
|
+
).unsafeFetchRaw();
|
|
16100
16226
|
return Promise.all(
|
|
16101
16227
|
results.map(
|
|
16102
|
-
(
|
|
16228
|
+
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
16103
16229
|
)
|
|
16104
16230
|
);
|
|
16105
16231
|
}
|
|
16106
16232
|
async function getMessagesOp(ctx, convId) {
|
|
16107
|
-
const results = await ctx.messagesCollection.query(import_watermelondb14.Q.where("conversation_id", convId), import_watermelondb14.Q.sortBy("message_id", import_watermelondb14.Q.asc)).
|
|
16233
|
+
const results = await ctx.messagesCollection.query(import_watermelondb14.Q.where("conversation_id", convId), import_watermelondb14.Q.sortBy("message_id", import_watermelondb14.Q.asc)).unsafeFetchRaw();
|
|
16108
16234
|
return Promise.all(
|
|
16109
16235
|
results.map(
|
|
16110
|
-
(
|
|
16236
|
+
(raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
16111
16237
|
)
|
|
16112
16238
|
);
|
|
16113
16239
|
}
|
|
@@ -17603,896 +17729,6 @@ var init_chunking = __esm({
|
|
|
17603
17729
|
}
|
|
17604
17730
|
});
|
|
17605
17731
|
|
|
17606
|
-
// src/client/core/bodySerializer.gen.ts
|
|
17607
|
-
var jsonBodySerializer;
|
|
17608
|
-
var init_bodySerializer_gen = __esm({
|
|
17609
|
-
"src/client/core/bodySerializer.gen.ts"() {
|
|
17610
|
-
"use strict";
|
|
17611
|
-
jsonBodySerializer = {
|
|
17612
|
-
bodySerializer: (body) => JSON.stringify(
|
|
17613
|
-
body,
|
|
17614
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
17615
|
-
)
|
|
17616
|
-
};
|
|
17617
|
-
}
|
|
17618
|
-
});
|
|
17619
|
-
|
|
17620
|
-
// src/client/core/serverSentEvents.gen.ts
|
|
17621
|
-
var createSseClient;
|
|
17622
|
-
var init_serverSentEvents_gen = __esm({
|
|
17623
|
-
"src/client/core/serverSentEvents.gen.ts"() {
|
|
17624
|
-
"use strict";
|
|
17625
|
-
createSseClient = ({
|
|
17626
|
-
onRequest,
|
|
17627
|
-
onSseError,
|
|
17628
|
-
onSseEvent,
|
|
17629
|
-
responseTransformer,
|
|
17630
|
-
responseValidator,
|
|
17631
|
-
sseDefaultRetryDelay,
|
|
17632
|
-
sseMaxRetryAttempts,
|
|
17633
|
-
sseMaxRetryDelay,
|
|
17634
|
-
sseSleepFn,
|
|
17635
|
-
url,
|
|
17636
|
-
...options
|
|
17637
|
-
}) => {
|
|
17638
|
-
let lastEventId;
|
|
17639
|
-
const sleep4 = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
17640
|
-
const createStream = async function* () {
|
|
17641
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
17642
|
-
let attempt = 0;
|
|
17643
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
17644
|
-
while (true) {
|
|
17645
|
-
if (signal.aborted) break;
|
|
17646
|
-
attempt++;
|
|
17647
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
17648
|
-
if (lastEventId !== void 0) {
|
|
17649
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
17650
|
-
}
|
|
17651
|
-
try {
|
|
17652
|
-
const requestInit = {
|
|
17653
|
-
redirect: "follow",
|
|
17654
|
-
...options,
|
|
17655
|
-
body: options.serializedBody,
|
|
17656
|
-
headers,
|
|
17657
|
-
signal
|
|
17658
|
-
};
|
|
17659
|
-
let request = new Request(url, requestInit);
|
|
17660
|
-
if (onRequest) {
|
|
17661
|
-
request = await onRequest(url, requestInit);
|
|
17662
|
-
}
|
|
17663
|
-
const _fetch = options.fetch ?? globalThis.fetch;
|
|
17664
|
-
const response = await _fetch(request);
|
|
17665
|
-
if (!response.ok)
|
|
17666
|
-
throw new Error(
|
|
17667
|
-
`SSE failed: ${response.status} ${response.statusText}`
|
|
17668
|
-
);
|
|
17669
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
17670
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
17671
|
-
let buffer = "";
|
|
17672
|
-
const abortHandler = () => {
|
|
17673
|
-
try {
|
|
17674
|
-
reader.cancel();
|
|
17675
|
-
} catch {
|
|
17676
|
-
}
|
|
17677
|
-
};
|
|
17678
|
-
signal.addEventListener("abort", abortHandler);
|
|
17679
|
-
try {
|
|
17680
|
-
while (true) {
|
|
17681
|
-
const { done, value } = await reader.read();
|
|
17682
|
-
if (done) break;
|
|
17683
|
-
buffer += value;
|
|
17684
|
-
const chunks = buffer.split("\n\n");
|
|
17685
|
-
buffer = chunks.pop() ?? "";
|
|
17686
|
-
for (const chunk of chunks) {
|
|
17687
|
-
const lines = chunk.split("\n");
|
|
17688
|
-
const dataLines = [];
|
|
17689
|
-
let eventName;
|
|
17690
|
-
for (const line of lines) {
|
|
17691
|
-
if (line.startsWith("data:")) {
|
|
17692
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
17693
|
-
} else if (line.startsWith("event:")) {
|
|
17694
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
17695
|
-
} else if (line.startsWith("id:")) {
|
|
17696
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
17697
|
-
} else if (line.startsWith("retry:")) {
|
|
17698
|
-
const parsed = Number.parseInt(
|
|
17699
|
-
line.replace(/^retry:\s*/, ""),
|
|
17700
|
-
10
|
|
17701
|
-
);
|
|
17702
|
-
if (!Number.isNaN(parsed)) {
|
|
17703
|
-
retryDelay = parsed;
|
|
17704
|
-
}
|
|
17705
|
-
}
|
|
17706
|
-
}
|
|
17707
|
-
let data;
|
|
17708
|
-
let parsedJson = false;
|
|
17709
|
-
if (dataLines.length) {
|
|
17710
|
-
const rawData = dataLines.join("\n");
|
|
17711
|
-
try {
|
|
17712
|
-
data = JSON.parse(rawData);
|
|
17713
|
-
parsedJson = true;
|
|
17714
|
-
} catch {
|
|
17715
|
-
data = rawData;
|
|
17716
|
-
}
|
|
17717
|
-
}
|
|
17718
|
-
if (parsedJson) {
|
|
17719
|
-
if (responseValidator) {
|
|
17720
|
-
await responseValidator(data);
|
|
17721
|
-
}
|
|
17722
|
-
if (responseTransformer) {
|
|
17723
|
-
data = await responseTransformer(data);
|
|
17724
|
-
}
|
|
17725
|
-
}
|
|
17726
|
-
onSseEvent?.({
|
|
17727
|
-
data,
|
|
17728
|
-
event: eventName,
|
|
17729
|
-
id: lastEventId,
|
|
17730
|
-
retry: retryDelay
|
|
17731
|
-
});
|
|
17732
|
-
if (dataLines.length) {
|
|
17733
|
-
yield data;
|
|
17734
|
-
}
|
|
17735
|
-
}
|
|
17736
|
-
}
|
|
17737
|
-
} finally {
|
|
17738
|
-
signal.removeEventListener("abort", abortHandler);
|
|
17739
|
-
reader.releaseLock();
|
|
17740
|
-
}
|
|
17741
|
-
break;
|
|
17742
|
-
} catch (error) {
|
|
17743
|
-
onSseError?.(error);
|
|
17744
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
17745
|
-
break;
|
|
17746
|
-
}
|
|
17747
|
-
const backoff = Math.min(
|
|
17748
|
-
retryDelay * 2 ** (attempt - 1),
|
|
17749
|
-
sseMaxRetryDelay ?? 3e4
|
|
17750
|
-
);
|
|
17751
|
-
await sleep4(backoff);
|
|
17752
|
-
}
|
|
17753
|
-
}
|
|
17754
|
-
};
|
|
17755
|
-
const stream = createStream();
|
|
17756
|
-
return { stream };
|
|
17757
|
-
};
|
|
17758
|
-
}
|
|
17759
|
-
});
|
|
17760
|
-
|
|
17761
|
-
// src/client/core/pathSerializer.gen.ts
|
|
17762
|
-
var separatorArrayExplode, separatorArrayNoExplode, separatorObjectExplode, serializeArrayParam, serializePrimitiveParam, serializeObjectParam;
|
|
17763
|
-
var init_pathSerializer_gen = __esm({
|
|
17764
|
-
"src/client/core/pathSerializer.gen.ts"() {
|
|
17765
|
-
"use strict";
|
|
17766
|
-
separatorArrayExplode = (style) => {
|
|
17767
|
-
switch (style) {
|
|
17768
|
-
case "label":
|
|
17769
|
-
return ".";
|
|
17770
|
-
case "matrix":
|
|
17771
|
-
return ";";
|
|
17772
|
-
case "simple":
|
|
17773
|
-
return ",";
|
|
17774
|
-
default:
|
|
17775
|
-
return "&";
|
|
17776
|
-
}
|
|
17777
|
-
};
|
|
17778
|
-
separatorArrayNoExplode = (style) => {
|
|
17779
|
-
switch (style) {
|
|
17780
|
-
case "form":
|
|
17781
|
-
return ",";
|
|
17782
|
-
case "pipeDelimited":
|
|
17783
|
-
return "|";
|
|
17784
|
-
case "spaceDelimited":
|
|
17785
|
-
return "%20";
|
|
17786
|
-
default:
|
|
17787
|
-
return ",";
|
|
17788
|
-
}
|
|
17789
|
-
};
|
|
17790
|
-
separatorObjectExplode = (style) => {
|
|
17791
|
-
switch (style) {
|
|
17792
|
-
case "label":
|
|
17793
|
-
return ".";
|
|
17794
|
-
case "matrix":
|
|
17795
|
-
return ";";
|
|
17796
|
-
case "simple":
|
|
17797
|
-
return ",";
|
|
17798
|
-
default:
|
|
17799
|
-
return "&";
|
|
17800
|
-
}
|
|
17801
|
-
};
|
|
17802
|
-
serializeArrayParam = ({
|
|
17803
|
-
allowReserved,
|
|
17804
|
-
explode,
|
|
17805
|
-
name,
|
|
17806
|
-
style,
|
|
17807
|
-
value
|
|
17808
|
-
}) => {
|
|
17809
|
-
if (!explode) {
|
|
17810
|
-
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
17811
|
-
switch (style) {
|
|
17812
|
-
case "label":
|
|
17813
|
-
return `.${joinedValues2}`;
|
|
17814
|
-
case "matrix":
|
|
17815
|
-
return `;${name}=${joinedValues2}`;
|
|
17816
|
-
case "simple":
|
|
17817
|
-
return joinedValues2;
|
|
17818
|
-
default:
|
|
17819
|
-
return `${name}=${joinedValues2}`;
|
|
17820
|
-
}
|
|
17821
|
-
}
|
|
17822
|
-
const separator = separatorArrayExplode(style);
|
|
17823
|
-
const joinedValues = value.map((v) => {
|
|
17824
|
-
if (style === "label" || style === "simple") {
|
|
17825
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
17826
|
-
}
|
|
17827
|
-
return serializePrimitiveParam({
|
|
17828
|
-
allowReserved,
|
|
17829
|
-
name,
|
|
17830
|
-
value: v
|
|
17831
|
-
});
|
|
17832
|
-
}).join(separator);
|
|
17833
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
17834
|
-
};
|
|
17835
|
-
serializePrimitiveParam = ({
|
|
17836
|
-
allowReserved,
|
|
17837
|
-
name,
|
|
17838
|
-
value
|
|
17839
|
-
}) => {
|
|
17840
|
-
if (value === void 0 || value === null) {
|
|
17841
|
-
return "";
|
|
17842
|
-
}
|
|
17843
|
-
if (typeof value === "object") {
|
|
17844
|
-
throw new Error(
|
|
17845
|
-
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
17846
|
-
);
|
|
17847
|
-
}
|
|
17848
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
17849
|
-
};
|
|
17850
|
-
serializeObjectParam = ({
|
|
17851
|
-
allowReserved,
|
|
17852
|
-
explode,
|
|
17853
|
-
name,
|
|
17854
|
-
style,
|
|
17855
|
-
value,
|
|
17856
|
-
valueOnly
|
|
17857
|
-
}) => {
|
|
17858
|
-
if (value instanceof Date) {
|
|
17859
|
-
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
17860
|
-
}
|
|
17861
|
-
if (style !== "deepObject" && !explode) {
|
|
17862
|
-
let values = [];
|
|
17863
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
17864
|
-
values = [
|
|
17865
|
-
...values,
|
|
17866
|
-
key,
|
|
17867
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
17868
|
-
];
|
|
17869
|
-
});
|
|
17870
|
-
const joinedValues2 = values.join(",");
|
|
17871
|
-
switch (style) {
|
|
17872
|
-
case "form":
|
|
17873
|
-
return `${name}=${joinedValues2}`;
|
|
17874
|
-
case "label":
|
|
17875
|
-
return `.${joinedValues2}`;
|
|
17876
|
-
case "matrix":
|
|
17877
|
-
return `;${name}=${joinedValues2}`;
|
|
17878
|
-
default:
|
|
17879
|
-
return joinedValues2;
|
|
17880
|
-
}
|
|
17881
|
-
}
|
|
17882
|
-
const separator = separatorObjectExplode(style);
|
|
17883
|
-
const joinedValues = Object.entries(value).map(
|
|
17884
|
-
([key, v]) => serializePrimitiveParam({
|
|
17885
|
-
allowReserved,
|
|
17886
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
17887
|
-
value: v
|
|
17888
|
-
})
|
|
17889
|
-
).join(separator);
|
|
17890
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
17891
|
-
};
|
|
17892
|
-
}
|
|
17893
|
-
});
|
|
17894
|
-
|
|
17895
|
-
// src/client/core/utils.gen.ts
|
|
17896
|
-
function getValidRequestBody(options) {
|
|
17897
|
-
const hasBody = options.body !== void 0;
|
|
17898
|
-
const isSerializedBody = hasBody && options.bodySerializer;
|
|
17899
|
-
if (isSerializedBody) {
|
|
17900
|
-
if ("serializedBody" in options) {
|
|
17901
|
-
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
17902
|
-
return hasSerializedBody ? options.serializedBody : null;
|
|
17903
|
-
}
|
|
17904
|
-
return options.body !== "" ? options.body : null;
|
|
17905
|
-
}
|
|
17906
|
-
if (hasBody) {
|
|
17907
|
-
return options.body;
|
|
17908
|
-
}
|
|
17909
|
-
return void 0;
|
|
17910
|
-
}
|
|
17911
|
-
var init_utils_gen = __esm({
|
|
17912
|
-
"src/client/core/utils.gen.ts"() {
|
|
17913
|
-
"use strict";
|
|
17914
|
-
}
|
|
17915
|
-
});
|
|
17916
|
-
|
|
17917
|
-
// src/client/core/auth.gen.ts
|
|
17918
|
-
var getAuthToken;
|
|
17919
|
-
var init_auth_gen = __esm({
|
|
17920
|
-
"src/client/core/auth.gen.ts"() {
|
|
17921
|
-
"use strict";
|
|
17922
|
-
getAuthToken = async (auth, callback) => {
|
|
17923
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
17924
|
-
if (!token) {
|
|
17925
|
-
return;
|
|
17926
|
-
}
|
|
17927
|
-
if (auth.scheme === "bearer") {
|
|
17928
|
-
return `Bearer ${token}`;
|
|
17929
|
-
}
|
|
17930
|
-
if (auth.scheme === "basic") {
|
|
17931
|
-
return `Basic ${btoa(token)}`;
|
|
17932
|
-
}
|
|
17933
|
-
return token;
|
|
17934
|
-
};
|
|
17935
|
-
}
|
|
17936
|
-
});
|
|
17937
|
-
|
|
17938
|
-
// src/client/client/utils.gen.ts
|
|
17939
|
-
var PATH_PARAM_RE, defaultPathSerializer, createQuerySerializer, getParseAs, checkForExistence, setAuthParams, buildUrl, getUrl, mergeConfigs, headersEntries, mergeHeaders, Interceptors, createInterceptors, defaultQuerySerializer, defaultHeaders, createConfig;
|
|
17940
|
-
var init_utils_gen2 = __esm({
|
|
17941
|
-
"src/client/client/utils.gen.ts"() {
|
|
17942
|
-
"use strict";
|
|
17943
|
-
init_auth_gen();
|
|
17944
|
-
init_bodySerializer_gen();
|
|
17945
|
-
init_pathSerializer_gen();
|
|
17946
|
-
PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
17947
|
-
defaultPathSerializer = ({ path, url: _url }) => {
|
|
17948
|
-
let url = _url;
|
|
17949
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
17950
|
-
if (matches) {
|
|
17951
|
-
for (const match of matches) {
|
|
17952
|
-
let explode = false;
|
|
17953
|
-
let name = match.substring(1, match.length - 1);
|
|
17954
|
-
let style = "simple";
|
|
17955
|
-
if (name.endsWith("*")) {
|
|
17956
|
-
explode = true;
|
|
17957
|
-
name = name.substring(0, name.length - 1);
|
|
17958
|
-
}
|
|
17959
|
-
if (name.startsWith(".")) {
|
|
17960
|
-
name = name.substring(1);
|
|
17961
|
-
style = "label";
|
|
17962
|
-
} else if (name.startsWith(";")) {
|
|
17963
|
-
name = name.substring(1);
|
|
17964
|
-
style = "matrix";
|
|
17965
|
-
}
|
|
17966
|
-
const value = path[name];
|
|
17967
|
-
if (value === void 0 || value === null) {
|
|
17968
|
-
continue;
|
|
17969
|
-
}
|
|
17970
|
-
if (Array.isArray(value)) {
|
|
17971
|
-
url = url.replace(
|
|
17972
|
-
match,
|
|
17973
|
-
serializeArrayParam({ explode, name, style, value })
|
|
17974
|
-
);
|
|
17975
|
-
continue;
|
|
17976
|
-
}
|
|
17977
|
-
if (typeof value === "object") {
|
|
17978
|
-
url = url.replace(
|
|
17979
|
-
match,
|
|
17980
|
-
serializeObjectParam({
|
|
17981
|
-
explode,
|
|
17982
|
-
name,
|
|
17983
|
-
style,
|
|
17984
|
-
value,
|
|
17985
|
-
valueOnly: true
|
|
17986
|
-
})
|
|
17987
|
-
);
|
|
17988
|
-
continue;
|
|
17989
|
-
}
|
|
17990
|
-
if (style === "matrix") {
|
|
17991
|
-
url = url.replace(
|
|
17992
|
-
match,
|
|
17993
|
-
`;${serializePrimitiveParam({
|
|
17994
|
-
name,
|
|
17995
|
-
value
|
|
17996
|
-
})}`
|
|
17997
|
-
);
|
|
17998
|
-
continue;
|
|
17999
|
-
}
|
|
18000
|
-
const replaceValue = encodeURIComponent(
|
|
18001
|
-
style === "label" ? `.${value}` : value
|
|
18002
|
-
);
|
|
18003
|
-
url = url.replace(match, replaceValue);
|
|
18004
|
-
}
|
|
18005
|
-
}
|
|
18006
|
-
return url;
|
|
18007
|
-
};
|
|
18008
|
-
createQuerySerializer = ({
|
|
18009
|
-
parameters = {},
|
|
18010
|
-
...args
|
|
18011
|
-
} = {}) => {
|
|
18012
|
-
const querySerializer = (queryParams) => {
|
|
18013
|
-
const search = [];
|
|
18014
|
-
if (queryParams && typeof queryParams === "object") {
|
|
18015
|
-
for (const name in queryParams) {
|
|
18016
|
-
const value = queryParams[name];
|
|
18017
|
-
if (value === void 0 || value === null) {
|
|
18018
|
-
continue;
|
|
18019
|
-
}
|
|
18020
|
-
const options = parameters[name] || args;
|
|
18021
|
-
if (Array.isArray(value)) {
|
|
18022
|
-
const serializedArray = serializeArrayParam({
|
|
18023
|
-
allowReserved: options.allowReserved,
|
|
18024
|
-
explode: true,
|
|
18025
|
-
name,
|
|
18026
|
-
style: "form",
|
|
18027
|
-
value,
|
|
18028
|
-
...options.array
|
|
18029
|
-
});
|
|
18030
|
-
if (serializedArray) search.push(serializedArray);
|
|
18031
|
-
} else if (typeof value === "object") {
|
|
18032
|
-
const serializedObject = serializeObjectParam({
|
|
18033
|
-
allowReserved: options.allowReserved,
|
|
18034
|
-
explode: true,
|
|
18035
|
-
name,
|
|
18036
|
-
style: "deepObject",
|
|
18037
|
-
value,
|
|
18038
|
-
...options.object
|
|
18039
|
-
});
|
|
18040
|
-
if (serializedObject) search.push(serializedObject);
|
|
18041
|
-
} else {
|
|
18042
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
18043
|
-
allowReserved: options.allowReserved,
|
|
18044
|
-
name,
|
|
18045
|
-
value
|
|
18046
|
-
});
|
|
18047
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
18048
|
-
}
|
|
18049
|
-
}
|
|
18050
|
-
}
|
|
18051
|
-
return search.join("&");
|
|
18052
|
-
};
|
|
18053
|
-
return querySerializer;
|
|
18054
|
-
};
|
|
18055
|
-
getParseAs = (contentType) => {
|
|
18056
|
-
if (!contentType) {
|
|
18057
|
-
return "stream";
|
|
18058
|
-
}
|
|
18059
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
18060
|
-
if (!cleanContent) {
|
|
18061
|
-
return;
|
|
18062
|
-
}
|
|
18063
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
18064
|
-
return "json";
|
|
18065
|
-
}
|
|
18066
|
-
if (cleanContent === "multipart/form-data") {
|
|
18067
|
-
return "formData";
|
|
18068
|
-
}
|
|
18069
|
-
if (["application/", "audio/", "image/", "video/"].some(
|
|
18070
|
-
(type) => cleanContent.startsWith(type)
|
|
18071
|
-
)) {
|
|
18072
|
-
return "blob";
|
|
18073
|
-
}
|
|
18074
|
-
if (cleanContent.startsWith("text/")) {
|
|
18075
|
-
return "text";
|
|
18076
|
-
}
|
|
18077
|
-
return;
|
|
18078
|
-
};
|
|
18079
|
-
checkForExistence = (options, name) => {
|
|
18080
|
-
if (!name) {
|
|
18081
|
-
return false;
|
|
18082
|
-
}
|
|
18083
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
18084
|
-
return true;
|
|
18085
|
-
}
|
|
18086
|
-
return false;
|
|
18087
|
-
};
|
|
18088
|
-
setAuthParams = async ({
|
|
18089
|
-
security,
|
|
18090
|
-
...options
|
|
18091
|
-
}) => {
|
|
18092
|
-
for (const auth of security) {
|
|
18093
|
-
if (checkForExistence(options, auth.name)) {
|
|
18094
|
-
continue;
|
|
18095
|
-
}
|
|
18096
|
-
const token = await getAuthToken(auth, options.auth);
|
|
18097
|
-
if (!token) {
|
|
18098
|
-
continue;
|
|
18099
|
-
}
|
|
18100
|
-
const name = auth.name ?? "Authorization";
|
|
18101
|
-
switch (auth.in) {
|
|
18102
|
-
case "query":
|
|
18103
|
-
if (!options.query) {
|
|
18104
|
-
options.query = {};
|
|
18105
|
-
}
|
|
18106
|
-
options.query[name] = token;
|
|
18107
|
-
break;
|
|
18108
|
-
case "cookie":
|
|
18109
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
18110
|
-
break;
|
|
18111
|
-
case "header":
|
|
18112
|
-
default:
|
|
18113
|
-
options.headers.set(name, token);
|
|
18114
|
-
break;
|
|
18115
|
-
}
|
|
18116
|
-
}
|
|
18117
|
-
};
|
|
18118
|
-
buildUrl = (options) => {
|
|
18119
|
-
const url = getUrl({
|
|
18120
|
-
baseUrl: options.baseUrl,
|
|
18121
|
-
path: options.path,
|
|
18122
|
-
query: options.query,
|
|
18123
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
18124
|
-
url: options.url
|
|
18125
|
-
});
|
|
18126
|
-
return url;
|
|
18127
|
-
};
|
|
18128
|
-
getUrl = ({
|
|
18129
|
-
baseUrl,
|
|
18130
|
-
path,
|
|
18131
|
-
query,
|
|
18132
|
-
querySerializer,
|
|
18133
|
-
url: _url
|
|
18134
|
-
}) => {
|
|
18135
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
18136
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
18137
|
-
if (path) {
|
|
18138
|
-
url = defaultPathSerializer({ path, url });
|
|
18139
|
-
}
|
|
18140
|
-
let search = query ? querySerializer(query) : "";
|
|
18141
|
-
if (search.startsWith("?")) {
|
|
18142
|
-
search = search.substring(1);
|
|
18143
|
-
}
|
|
18144
|
-
if (search) {
|
|
18145
|
-
url += `?${search}`;
|
|
18146
|
-
}
|
|
18147
|
-
return url;
|
|
18148
|
-
};
|
|
18149
|
-
mergeConfigs = (a, b) => {
|
|
18150
|
-
const config = { ...a, ...b };
|
|
18151
|
-
if (config.baseUrl?.endsWith("/")) {
|
|
18152
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
18153
|
-
}
|
|
18154
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
18155
|
-
return config;
|
|
18156
|
-
};
|
|
18157
|
-
headersEntries = (headers) => {
|
|
18158
|
-
const entries = [];
|
|
18159
|
-
headers.forEach((value, key) => {
|
|
18160
|
-
entries.push([key, value]);
|
|
18161
|
-
});
|
|
18162
|
-
return entries;
|
|
18163
|
-
};
|
|
18164
|
-
mergeHeaders = (...headers) => {
|
|
18165
|
-
const mergedHeaders = new Headers();
|
|
18166
|
-
for (const header of headers) {
|
|
18167
|
-
if (!header || typeof header !== "object") {
|
|
18168
|
-
continue;
|
|
18169
|
-
}
|
|
18170
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
18171
|
-
for (const [key, value] of iterator) {
|
|
18172
|
-
if (value === null) {
|
|
18173
|
-
mergedHeaders.delete(key);
|
|
18174
|
-
} else if (Array.isArray(value)) {
|
|
18175
|
-
for (const v of value) {
|
|
18176
|
-
mergedHeaders.append(key, v);
|
|
18177
|
-
}
|
|
18178
|
-
} else if (value !== void 0) {
|
|
18179
|
-
mergedHeaders.set(
|
|
18180
|
-
key,
|
|
18181
|
-
typeof value === "object" ? JSON.stringify(value) : value
|
|
18182
|
-
);
|
|
18183
|
-
}
|
|
18184
|
-
}
|
|
18185
|
-
}
|
|
18186
|
-
return mergedHeaders;
|
|
18187
|
-
};
|
|
18188
|
-
Interceptors = class {
|
|
18189
|
-
constructor() {
|
|
18190
|
-
this.fns = [];
|
|
18191
|
-
}
|
|
18192
|
-
clear() {
|
|
18193
|
-
this.fns = [];
|
|
18194
|
-
}
|
|
18195
|
-
eject(id) {
|
|
18196
|
-
const index = this.getInterceptorIndex(id);
|
|
18197
|
-
if (this.fns[index]) {
|
|
18198
|
-
this.fns[index] = null;
|
|
18199
|
-
}
|
|
18200
|
-
}
|
|
18201
|
-
exists(id) {
|
|
18202
|
-
const index = this.getInterceptorIndex(id);
|
|
18203
|
-
return Boolean(this.fns[index]);
|
|
18204
|
-
}
|
|
18205
|
-
getInterceptorIndex(id) {
|
|
18206
|
-
if (typeof id === "number") {
|
|
18207
|
-
return this.fns[id] ? id : -1;
|
|
18208
|
-
}
|
|
18209
|
-
return this.fns.indexOf(id);
|
|
18210
|
-
}
|
|
18211
|
-
update(id, fn) {
|
|
18212
|
-
const index = this.getInterceptorIndex(id);
|
|
18213
|
-
if (this.fns[index]) {
|
|
18214
|
-
this.fns[index] = fn;
|
|
18215
|
-
return id;
|
|
18216
|
-
}
|
|
18217
|
-
return false;
|
|
18218
|
-
}
|
|
18219
|
-
use(fn) {
|
|
18220
|
-
this.fns.push(fn);
|
|
18221
|
-
return this.fns.length - 1;
|
|
18222
|
-
}
|
|
18223
|
-
};
|
|
18224
|
-
createInterceptors = () => ({
|
|
18225
|
-
error: new Interceptors(),
|
|
18226
|
-
request: new Interceptors(),
|
|
18227
|
-
response: new Interceptors()
|
|
18228
|
-
});
|
|
18229
|
-
defaultQuerySerializer = createQuerySerializer({
|
|
18230
|
-
allowReserved: false,
|
|
18231
|
-
array: {
|
|
18232
|
-
explode: true,
|
|
18233
|
-
style: "form"
|
|
18234
|
-
},
|
|
18235
|
-
object: {
|
|
18236
|
-
explode: true,
|
|
18237
|
-
style: "deepObject"
|
|
18238
|
-
}
|
|
18239
|
-
});
|
|
18240
|
-
defaultHeaders = {
|
|
18241
|
-
"Content-Type": "application/json"
|
|
18242
|
-
};
|
|
18243
|
-
createConfig = (override = {}) => ({
|
|
18244
|
-
...jsonBodySerializer,
|
|
18245
|
-
headers: defaultHeaders,
|
|
18246
|
-
parseAs: "auto",
|
|
18247
|
-
querySerializer: defaultQuerySerializer,
|
|
18248
|
-
...override
|
|
18249
|
-
});
|
|
18250
|
-
}
|
|
18251
|
-
});
|
|
18252
|
-
|
|
18253
|
-
// src/client/client/client.gen.ts
|
|
18254
|
-
var createClient;
|
|
18255
|
-
var init_client_gen = __esm({
|
|
18256
|
-
"src/client/client/client.gen.ts"() {
|
|
18257
|
-
"use strict";
|
|
18258
|
-
init_serverSentEvents_gen();
|
|
18259
|
-
init_utils_gen();
|
|
18260
|
-
init_utils_gen2();
|
|
18261
|
-
createClient = (config = {}) => {
|
|
18262
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
18263
|
-
const getConfig = () => ({ ..._config });
|
|
18264
|
-
const setConfig = (config2) => {
|
|
18265
|
-
_config = mergeConfigs(_config, config2);
|
|
18266
|
-
return getConfig();
|
|
18267
|
-
};
|
|
18268
|
-
const interceptors = createInterceptors();
|
|
18269
|
-
const beforeRequest = async (options) => {
|
|
18270
|
-
const opts = {
|
|
18271
|
-
..._config,
|
|
18272
|
-
...options,
|
|
18273
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18274
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
18275
|
-
serializedBody: void 0
|
|
18276
|
-
};
|
|
18277
|
-
if (opts.security) {
|
|
18278
|
-
await setAuthParams({
|
|
18279
|
-
...opts,
|
|
18280
|
-
security: opts.security
|
|
18281
|
-
});
|
|
18282
|
-
}
|
|
18283
|
-
if (opts.requestValidator) {
|
|
18284
|
-
await opts.requestValidator(opts);
|
|
18285
|
-
}
|
|
18286
|
-
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
18287
|
-
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
18288
|
-
}
|
|
18289
|
-
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
18290
|
-
opts.headers.delete("Content-Type");
|
|
18291
|
-
}
|
|
18292
|
-
const url = buildUrl(opts);
|
|
18293
|
-
return { opts, url };
|
|
18294
|
-
};
|
|
18295
|
-
const request = async (options) => {
|
|
18296
|
-
const { opts, url } = await beforeRequest(options);
|
|
18297
|
-
for (const fn of interceptors.request.fns) {
|
|
18298
|
-
if (fn) {
|
|
18299
|
-
await fn(opts);
|
|
18300
|
-
}
|
|
18301
|
-
}
|
|
18302
|
-
const _fetch = opts.fetch;
|
|
18303
|
-
const requestInit = {
|
|
18304
|
-
...opts,
|
|
18305
|
-
body: getValidRequestBody(opts)
|
|
18306
|
-
};
|
|
18307
|
-
let response = await _fetch(url, requestInit);
|
|
18308
|
-
for (const fn of interceptors.response.fns) {
|
|
18309
|
-
if (fn) {
|
|
18310
|
-
response = await fn(response, opts);
|
|
18311
|
-
}
|
|
18312
|
-
}
|
|
18313
|
-
const result = {
|
|
18314
|
-
response
|
|
18315
|
-
};
|
|
18316
|
-
if (response.ok) {
|
|
18317
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
18318
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
18319
|
-
let emptyData;
|
|
18320
|
-
switch (parseAs) {
|
|
18321
|
-
case "arrayBuffer":
|
|
18322
|
-
case "blob":
|
|
18323
|
-
case "text":
|
|
18324
|
-
emptyData = await response[parseAs]();
|
|
18325
|
-
break;
|
|
18326
|
-
case "formData":
|
|
18327
|
-
emptyData = new FormData();
|
|
18328
|
-
break;
|
|
18329
|
-
case "stream":
|
|
18330
|
-
emptyData = response.body;
|
|
18331
|
-
break;
|
|
18332
|
-
case "json":
|
|
18333
|
-
default:
|
|
18334
|
-
emptyData = {};
|
|
18335
|
-
break;
|
|
18336
|
-
}
|
|
18337
|
-
return {
|
|
18338
|
-
data: emptyData,
|
|
18339
|
-
...result
|
|
18340
|
-
};
|
|
18341
|
-
}
|
|
18342
|
-
let data;
|
|
18343
|
-
switch (parseAs) {
|
|
18344
|
-
case "arrayBuffer":
|
|
18345
|
-
case "blob":
|
|
18346
|
-
case "formData":
|
|
18347
|
-
case "json":
|
|
18348
|
-
case "text":
|
|
18349
|
-
data = await response[parseAs]();
|
|
18350
|
-
break;
|
|
18351
|
-
case "stream":
|
|
18352
|
-
return {
|
|
18353
|
-
data: response.body,
|
|
18354
|
-
...result
|
|
18355
|
-
};
|
|
18356
|
-
}
|
|
18357
|
-
if (parseAs === "json") {
|
|
18358
|
-
if (opts.responseValidator) {
|
|
18359
|
-
await opts.responseValidator(data);
|
|
18360
|
-
}
|
|
18361
|
-
if (opts.responseTransformer) {
|
|
18362
|
-
data = await opts.responseTransformer(data);
|
|
18363
|
-
}
|
|
18364
|
-
}
|
|
18365
|
-
return {
|
|
18366
|
-
data,
|
|
18367
|
-
...result
|
|
18368
|
-
};
|
|
18369
|
-
}
|
|
18370
|
-
const textError = await response.text();
|
|
18371
|
-
let jsonError;
|
|
18372
|
-
try {
|
|
18373
|
-
jsonError = JSON.parse(textError);
|
|
18374
|
-
} catch {
|
|
18375
|
-
}
|
|
18376
|
-
const error = jsonError ?? textError;
|
|
18377
|
-
let finalError = error;
|
|
18378
|
-
for (const fn of interceptors.error.fns) {
|
|
18379
|
-
if (fn) {
|
|
18380
|
-
finalError = await fn(error, response, opts);
|
|
18381
|
-
}
|
|
18382
|
-
}
|
|
18383
|
-
finalError = finalError || {};
|
|
18384
|
-
if (opts.throwOnError) {
|
|
18385
|
-
throw finalError;
|
|
18386
|
-
}
|
|
18387
|
-
return {
|
|
18388
|
-
error: finalError,
|
|
18389
|
-
...result
|
|
18390
|
-
};
|
|
18391
|
-
};
|
|
18392
|
-
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
18393
|
-
const makeSseFn = (method) => async (options) => {
|
|
18394
|
-
const { opts, url } = await beforeRequest(options);
|
|
18395
|
-
return createSseClient({
|
|
18396
|
-
...opts,
|
|
18397
|
-
body: opts.body,
|
|
18398
|
-
headers: opts.headers,
|
|
18399
|
-
method,
|
|
18400
|
-
onRequest: async (url2, init) => {
|
|
18401
|
-
let request2 = new Request(url2, init);
|
|
18402
|
-
const requestInit = {
|
|
18403
|
-
...init,
|
|
18404
|
-
method: init.method,
|
|
18405
|
-
url: url2
|
|
18406
|
-
};
|
|
18407
|
-
for (const fn of interceptors.request.fns) {
|
|
18408
|
-
if (fn) {
|
|
18409
|
-
await fn(requestInit);
|
|
18410
|
-
request2 = new Request(requestInit.url, requestInit);
|
|
18411
|
-
}
|
|
18412
|
-
}
|
|
18413
|
-
return request2;
|
|
18414
|
-
},
|
|
18415
|
-
url
|
|
18416
|
-
});
|
|
18417
|
-
};
|
|
18418
|
-
return {
|
|
18419
|
-
buildUrl,
|
|
18420
|
-
connect: makeMethodFn("CONNECT"),
|
|
18421
|
-
delete: makeMethodFn("DELETE"),
|
|
18422
|
-
get: makeMethodFn("GET"),
|
|
18423
|
-
getConfig,
|
|
18424
|
-
head: makeMethodFn("HEAD"),
|
|
18425
|
-
interceptors,
|
|
18426
|
-
options: makeMethodFn("OPTIONS"),
|
|
18427
|
-
patch: makeMethodFn("PATCH"),
|
|
18428
|
-
post: makeMethodFn("POST"),
|
|
18429
|
-
put: makeMethodFn("PUT"),
|
|
18430
|
-
request,
|
|
18431
|
-
setConfig,
|
|
18432
|
-
sse: {
|
|
18433
|
-
connect: makeSseFn("CONNECT"),
|
|
18434
|
-
delete: makeSseFn("DELETE"),
|
|
18435
|
-
get: makeSseFn("GET"),
|
|
18436
|
-
head: makeSseFn("HEAD"),
|
|
18437
|
-
options: makeSseFn("OPTIONS"),
|
|
18438
|
-
patch: makeSseFn("PATCH"),
|
|
18439
|
-
post: makeSseFn("POST"),
|
|
18440
|
-
put: makeSseFn("PUT"),
|
|
18441
|
-
trace: makeSseFn("TRACE")
|
|
18442
|
-
},
|
|
18443
|
-
trace: makeMethodFn("TRACE")
|
|
18444
|
-
};
|
|
18445
|
-
};
|
|
18446
|
-
}
|
|
18447
|
-
});
|
|
18448
|
-
|
|
18449
|
-
// src/client/client/index.ts
|
|
18450
|
-
var init_client = __esm({
|
|
18451
|
-
"src/client/client/index.ts"() {
|
|
18452
|
-
"use strict";
|
|
18453
|
-
init_client_gen();
|
|
18454
|
-
init_utils_gen2();
|
|
18455
|
-
}
|
|
18456
|
-
});
|
|
18457
|
-
|
|
18458
|
-
// src/client/client.gen.ts
|
|
18459
|
-
var client;
|
|
18460
|
-
var init_client_gen2 = __esm({
|
|
18461
|
-
"src/client/client.gen.ts"() {
|
|
18462
|
-
"use strict";
|
|
18463
|
-
init_client();
|
|
18464
|
-
init_clientConfig();
|
|
18465
|
-
client = createClient(createClientConfig(createConfig()));
|
|
18466
|
-
}
|
|
18467
|
-
});
|
|
18468
|
-
|
|
18469
|
-
// src/client/sdk.gen.ts
|
|
18470
|
-
var postApiV1Embeddings;
|
|
18471
|
-
var init_sdk_gen = __esm({
|
|
18472
|
-
"src/client/sdk.gen.ts"() {
|
|
18473
|
-
"use strict";
|
|
18474
|
-
init_client_gen2();
|
|
18475
|
-
postApiV1Embeddings = (options) => {
|
|
18476
|
-
return (options.client ?? client).post({
|
|
18477
|
-
url: "/api/v1/embeddings",
|
|
18478
|
-
...options,
|
|
18479
|
-
headers: {
|
|
18480
|
-
"Content-Type": "application/json",
|
|
18481
|
-
...options.headers
|
|
18482
|
-
}
|
|
18483
|
-
});
|
|
18484
|
-
};
|
|
18485
|
-
}
|
|
18486
|
-
});
|
|
18487
|
-
|
|
18488
|
-
// src/client/index.ts
|
|
18489
|
-
var init_client2 = __esm({
|
|
18490
|
-
"src/client/index.ts"() {
|
|
18491
|
-
"use strict";
|
|
18492
|
-
init_sdk_gen();
|
|
18493
|
-
}
|
|
18494
|
-
});
|
|
18495
|
-
|
|
18496
17732
|
// src/lib/memoryEngine/constants.ts
|
|
18497
17733
|
var DEFAULT_API_EMBEDDING_MODEL;
|
|
18498
17734
|
var init_constants = __esm({
|
|
@@ -18502,7 +17738,7 @@ var init_constants = __esm({
|
|
|
18502
17738
|
}
|
|
18503
17739
|
});
|
|
18504
17740
|
|
|
18505
|
-
// src/lib/memoryEngine/
|
|
17741
|
+
// src/lib/memoryEngine/generate.ts
|
|
18506
17742
|
async function withEmbeddingRetry(call) {
|
|
18507
17743
|
let last;
|
|
18508
17744
|
let lastThrown;
|
|
@@ -18538,7 +17774,7 @@ async function generateEmbedding(text12, options) {
|
|
|
18538
17774
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
18539
17775
|
if (cache) {
|
|
18540
17776
|
const cached = cache.get(text12);
|
|
18541
|
-
if (cached) return cached;
|
|
17777
|
+
if (cached) return Array.from(cached);
|
|
18542
17778
|
}
|
|
18543
17779
|
let headers;
|
|
18544
17780
|
if (apiKey) {
|
|
@@ -18553,7 +17789,7 @@ async function generateEmbedding(text12, options) {
|
|
|
18553
17789
|
throw new Error("Either apiKey or getToken must be provided");
|
|
18554
17790
|
}
|
|
18555
17791
|
const response = await withEmbeddingRetry(
|
|
18556
|
-
() => postApiV1Embeddings({
|
|
17792
|
+
() => (0, import_client.postApiV1Embeddings)({
|
|
18557
17793
|
baseUrl,
|
|
18558
17794
|
body: {
|
|
18559
17795
|
// Mask PII from the request body only — the cache above still keys on
|
|
@@ -18577,14 +17813,15 @@ async function generateEmbedding(text12, options) {
|
|
|
18577
17813
|
totalTokens: response.data.usage.total_tokens ?? 0
|
|
18578
17814
|
});
|
|
18579
17815
|
}
|
|
17816
|
+
const f32Embedding = Float32Array.from(embedding);
|
|
18580
17817
|
if (cache) {
|
|
18581
|
-
cache.set(text12,
|
|
17818
|
+
cache.set(text12, f32Embedding);
|
|
18582
17819
|
}
|
|
18583
|
-
return
|
|
17820
|
+
return Array.from(f32Embedding);
|
|
18584
17821
|
}
|
|
18585
17822
|
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput) {
|
|
18586
17823
|
const response = await withEmbeddingRetry(
|
|
18587
|
-
() => postApiV1Embeddings({
|
|
17824
|
+
() => (0, import_client.postApiV1Embeddings)({
|
|
18588
17825
|
baseUrl,
|
|
18589
17826
|
// Mask PII from the request body only; cache/order still key on originals.
|
|
18590
17827
|
body: { input: maskInput ? texts.map(maskInput) : texts, model },
|
|
@@ -18616,7 +17853,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
18616
17853
|
if (cache) {
|
|
18617
17854
|
const cached = cache.get(texts[i]);
|
|
18618
17855
|
if (cached) {
|
|
18619
|
-
results[i] = cached;
|
|
17856
|
+
results[i] = Array.from(cached);
|
|
18620
17857
|
continue;
|
|
18621
17858
|
}
|
|
18622
17859
|
}
|
|
@@ -18677,13 +17914,35 @@ async function generateEmbeddings(texts, options) {
|
|
|
18677
17914
|
newEmbeddings = allEmbeddings.flat();
|
|
18678
17915
|
}
|
|
18679
17916
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
18680
|
-
|
|
17917
|
+
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
17918
|
+
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
18681
17919
|
if (cache) {
|
|
18682
|
-
cache.set(uncachedTexts[i],
|
|
17920
|
+
cache.set(uncachedTexts[i], f32Embedding);
|
|
18683
17921
|
}
|
|
18684
17922
|
}
|
|
18685
17923
|
return results;
|
|
18686
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
|
|
18687
17946
|
async function embedMessage(ctx, messageId, options) {
|
|
18688
17947
|
let message;
|
|
18689
17948
|
const conversations = await getConversationsOp(ctx);
|
|
@@ -18839,27 +18098,17 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
18839
18098
|
}
|
|
18840
18099
|
return embeddedCount;
|
|
18841
18100
|
}
|
|
18842
|
-
var DEFAULT_MIN_CONTENT_LENGTH
|
|
18101
|
+
var DEFAULT_MIN_CONTENT_LENGTH;
|
|
18843
18102
|
var init_embeddings = __esm({
|
|
18844
18103
|
"src/lib/memoryEngine/embeddings.ts"() {
|
|
18845
18104
|
"use strict";
|
|
18846
|
-
init_client2();
|
|
18847
|
-
init_clientConfig();
|
|
18848
18105
|
init_operations();
|
|
18849
18106
|
init_logger();
|
|
18850
18107
|
init_chunking();
|
|
18851
18108
|
init_constants();
|
|
18109
|
+
init_generate();
|
|
18110
|
+
init_generate();
|
|
18852
18111
|
DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
18853
|
-
EMBED_MAX_ATTEMPTS = 4;
|
|
18854
|
-
EmbeddingHttpError = class extends Error {
|
|
18855
|
-
constructor(message, status) {
|
|
18856
|
-
super(message);
|
|
18857
|
-
this.name = "EmbeddingHttpError";
|
|
18858
|
-
this.status = status;
|
|
18859
|
-
}
|
|
18860
|
-
};
|
|
18861
|
-
DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
18862
|
-
DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
18863
18112
|
}
|
|
18864
18113
|
});
|
|
18865
18114
|
|
|
@@ -21955,6 +21204,7 @@ __export(index_exports, {
|
|
|
21955
21204
|
decryptData: () => decryptData,
|
|
21956
21205
|
decryptDataBatch: () => decryptDataBatch,
|
|
21957
21206
|
decryptDataBytes: () => decryptDataBytes,
|
|
21207
|
+
decryptDataBytesFromBytes: () => decryptDataBytesFromBytes,
|
|
21958
21208
|
decryptDataWithKey: () => decryptDataWithKey,
|
|
21959
21209
|
defaultServerToolsFilter: () => defaultServerToolsFilter,
|
|
21960
21210
|
deleteAllVaultMemoriesForUserOp: () => deleteAllVaultMemoriesForUserOp,
|
|
@@ -21973,6 +21223,7 @@ __export(index_exports, {
|
|
|
21973
21223
|
embedMessage: () => embedMessage,
|
|
21974
21224
|
encryptData: () => encryptData,
|
|
21975
21225
|
encryptDataBatch: () => encryptDataBatch,
|
|
21226
|
+
encryptDataBytes: () => encryptDataBytes,
|
|
21976
21227
|
encryptDataWithKey: () => encryptDataWithKey,
|
|
21977
21228
|
ensureDefaultFoldersOp: () => ensureDefaultFoldersOp,
|
|
21978
21229
|
estimateMessagesTokens: () => estimateMessagesTokens,
|
|
@@ -22001,6 +21252,7 @@ __export(index_exports, {
|
|
|
22001
21252
|
getConversationsByProjectOp: () => getConversationsByProjectOp,
|
|
22002
21253
|
getConversationsLazyOp: () => getConversationsLazyOp,
|
|
22003
21254
|
getConversationsOp: () => getConversationsOp,
|
|
21255
|
+
getConversationsPageOp: () => getConversationsPageOp,
|
|
22004
21256
|
getDocumentsOp: () => getDocumentsOp,
|
|
22005
21257
|
getEncryptionKey: () => getEncryptionKey,
|
|
22006
21258
|
getImagesOp: () => getImagesOp,
|
|
@@ -23850,17 +23102,17 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
23850
23102
|
}
|
|
23851
23103
|
case "sql": {
|
|
23852
23104
|
if (this._pgSchema !== "public" && this.pool.connect) {
|
|
23853
|
-
const
|
|
23105
|
+
const client = await this.pool.connect();
|
|
23854
23106
|
try {
|
|
23855
|
-
await
|
|
23856
|
-
await
|
|
23857
|
-
await
|
|
23858
|
-
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");
|
|
23859
23111
|
} catch (err) {
|
|
23860
|
-
await
|
|
23112
|
+
await client.query("ROLLBACK");
|
|
23861
23113
|
throw err;
|
|
23862
23114
|
} finally {
|
|
23863
|
-
|
|
23115
|
+
client.release();
|
|
23864
23116
|
}
|
|
23865
23117
|
} else {
|
|
23866
23118
|
await this.pool.query(step.sql);
|
|
@@ -24006,16 +23258,16 @@ var _PostgreSQLAdapter = class _PostgreSQLAdapter {
|
|
|
24006
23258
|
}
|
|
24007
23259
|
};
|
|
24008
23260
|
if (this.pool.connect) {
|
|
24009
|
-
const
|
|
23261
|
+
const client = await this.pool.connect();
|
|
24010
23262
|
try {
|
|
24011
|
-
await
|
|
24012
|
-
await runOps(
|
|
24013
|
-
await
|
|
23263
|
+
await client.query("BEGIN");
|
|
23264
|
+
await runOps(client);
|
|
23265
|
+
await client.query("COMMIT");
|
|
24014
23266
|
} catch (err) {
|
|
24015
|
-
await
|
|
23267
|
+
await client.query("ROLLBACK");
|
|
24016
23268
|
throw err;
|
|
24017
23269
|
} finally {
|
|
24018
|
-
|
|
23270
|
+
client.release();
|
|
24019
23271
|
}
|
|
24020
23272
|
} else {
|
|
24021
23273
|
await runOps(this.pool);
|
|
@@ -26883,8 +26135,12 @@ init_recall();
|
|
|
26883
26135
|
|
|
26884
26136
|
// src/lib/memory/recallTool.ts
|
|
26885
26137
|
init_recall();
|
|
26138
|
+
|
|
26139
|
+
// src/lib/memory/recallConstants.ts
|
|
26886
26140
|
var RECALL_TOOL_NAME = "recall_memory";
|
|
26887
26141
|
var RECALL_MAX_LIMIT = 50;
|
|
26142
|
+
|
|
26143
|
+
// src/lib/memory/recallTool.ts
|
|
26888
26144
|
var DEFAULT_LIMIT2 = 8;
|
|
26889
26145
|
var DEFAULT_BUDGET2 = "low";
|
|
26890
26146
|
function formatEventTime(start, end, kind) {
|
|
@@ -27411,7 +26667,7 @@ WORKFLOW:
|
|
|
27411
26667
|
|
|
27412
26668
|
// src/lib/tools/serverTools.ts
|
|
27413
26669
|
init_logger();
|
|
27414
|
-
|
|
26670
|
+
init_generate();
|
|
27415
26671
|
init_vector();
|
|
27416
26672
|
var DEFAULT_CACHE_EXPIRATION_MS = 24 * 60 * 60 * 1e3;
|
|
27417
26673
|
var SERVER_TOOLS_CACHE_KEY = "sdk_server_tools_cache";
|
|
@@ -27458,7 +26714,7 @@ function getCachedServerTools() {
|
|
|
27458
26714
|
if (!cached) return null;
|
|
27459
26715
|
const parsed = JSON.parse(cached);
|
|
27460
26716
|
if (parsed.version !== CACHE_VERSION) {
|
|
27461
|
-
|
|
26717
|
+
removeLocalStorageCache();
|
|
27462
26718
|
return null;
|
|
27463
26719
|
}
|
|
27464
26720
|
return parsed;
|
|
@@ -27470,37 +26726,45 @@ function isCacheExpired(cache, expirationMs = DEFAULT_CACHE_EXPIRATION_MS) {
|
|
|
27470
26726
|
if (!cache) return true;
|
|
27471
26727
|
return Date.now() - cache.timestamp > expirationMs;
|
|
27472
26728
|
}
|
|
27473
|
-
function
|
|
27474
|
-
|
|
27475
|
-
const cacheData = {
|
|
26729
|
+
function buildCacheEntry(tools, checksum) {
|
|
26730
|
+
return {
|
|
27476
26731
|
tools,
|
|
27477
26732
|
timestamp: Date.now(),
|
|
27478
26733
|
version: CACHE_VERSION,
|
|
27479
26734
|
...checksum && { checksum }
|
|
27480
26735
|
};
|
|
26736
|
+
}
|
|
26737
|
+
function writeLocalStorageCache(entry) {
|
|
26738
|
+
if (typeof localStorage === "undefined") return;
|
|
27481
26739
|
try {
|
|
27482
|
-
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(
|
|
26740
|
+
localStorage.setItem(SERVER_TOOLS_CACHE_KEY, JSON.stringify(entry));
|
|
27483
26741
|
} catch (error) {
|
|
27484
26742
|
getLogger().warn("[serverTools] Failed to cache tools:", error);
|
|
27485
26743
|
}
|
|
27486
26744
|
}
|
|
27487
|
-
function
|
|
26745
|
+
function removeLocalStorageCache() {
|
|
27488
26746
|
if (typeof localStorage === "undefined") return;
|
|
27489
26747
|
localStorage.removeItem(SERVER_TOOLS_CACHE_KEY);
|
|
27490
26748
|
}
|
|
27491
|
-
|
|
27492
|
-
|
|
27493
|
-
|
|
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;
|
|
27494
26760
|
}
|
|
27495
|
-
function shouldRefreshTools(responseChecksum) {
|
|
26761
|
+
function shouldRefreshTools(responseChecksum, cache = localStorageToolsCache) {
|
|
27496
26762
|
if (!responseChecksum) {
|
|
27497
26763
|
return false;
|
|
27498
26764
|
}
|
|
27499
|
-
const
|
|
27500
|
-
|
|
27501
|
-
|
|
27502
|
-
}
|
|
27503
|
-
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);
|
|
27504
26768
|
}
|
|
27505
26769
|
async function fetchServerToolsFromApi(baseUrl, token) {
|
|
27506
26770
|
const response = await fetch(`${baseUrl}/api/v1/tools`, {
|
|
@@ -27522,9 +26786,23 @@ async function getServerTools(options) {
|
|
|
27522
26786
|
cacheExpirationMs = DEFAULT_CACHE_EXPIRATION_MS,
|
|
27523
26787
|
forceRefresh = false,
|
|
27524
26788
|
getToken,
|
|
27525
|
-
apiKey
|
|
26789
|
+
apiKey,
|
|
26790
|
+
cache = localStorageToolsCache
|
|
27526
26791
|
} = options;
|
|
27527
|
-
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;
|
|
27528
26806
|
const cacheValid = !isCacheExpired(cached, cacheExpirationMs);
|
|
27529
26807
|
if (cached && cacheValid && !forceRefresh) {
|
|
27530
26808
|
return cached.tools;
|
|
@@ -27545,7 +26823,7 @@ async function getServerTools(options) {
|
|
|
27545
26823
|
}
|
|
27546
26824
|
const data = await response.json();
|
|
27547
26825
|
const { tools: tools2, checksum: checksum2 } = convertServerToolsResponse(data);
|
|
27548
|
-
|
|
26826
|
+
await persistCache(buildCacheEntry(tools2, checksum2));
|
|
27549
26827
|
return tools2;
|
|
27550
26828
|
}
|
|
27551
26829
|
if (!getToken) {
|
|
@@ -27558,7 +26836,7 @@ async function getServerTools(options) {
|
|
|
27558
26836
|
return cached?.tools ?? [];
|
|
27559
26837
|
}
|
|
27560
26838
|
const { tools, checksum } = await fetchServerToolsFromApi(effectiveBaseUrl, token);
|
|
27561
|
-
|
|
26839
|
+
await persistCache(buildCacheEntry(tools, checksum));
|
|
27562
26840
|
return tools;
|
|
27563
26841
|
} catch (error) {
|
|
27564
26842
|
getLogger().error("[serverTools] Failed to fetch server tools:", error);
|
|
@@ -27942,13 +27220,14 @@ async function selectServerToolsForPrompt(options) {
|
|
|
27942
27220
|
baseUrl,
|
|
27943
27221
|
embeddingModel,
|
|
27944
27222
|
cacheExpirationMs,
|
|
27223
|
+
cache,
|
|
27945
27224
|
deferLoading
|
|
27946
27225
|
} = options;
|
|
27947
27226
|
if (serverToolsFilter === void 0) return [];
|
|
27948
27227
|
if (Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) return [];
|
|
27949
27228
|
let allServerTools;
|
|
27950
27229
|
try {
|
|
27951
|
-
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken });
|
|
27230
|
+
allServerTools = await getServerTools({ baseUrl, cacheExpirationMs, getToken, cache });
|
|
27952
27231
|
} catch {
|
|
27953
27232
|
return [];
|
|
27954
27233
|
}
|
|
@@ -28489,6 +27768,7 @@ var WalletPoller = class {
|
|
|
28489
27768
|
init_logger();
|
|
28490
27769
|
|
|
28491
27770
|
// src/lib/processors/encoding.ts
|
|
27771
|
+
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
28492
27772
|
async function dataUrlToArrayBuffer(dataUrl) {
|
|
28493
27773
|
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
28494
27774
|
const response = await fetch(dataUrl);
|
|
@@ -28511,11 +27791,16 @@ function uint8ArrayToBase64(data) {
|
|
|
28511
27791
|
if (typeof Buffer !== "undefined") {
|
|
28512
27792
|
return Buffer.from(data).toString("base64");
|
|
28513
27793
|
}
|
|
28514
|
-
let
|
|
28515
|
-
for (let i = 0; i < data.length; i
|
|
28516
|
-
|
|
27794
|
+
let base64 = "";
|
|
27795
|
+
for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
|
|
27796
|
+
const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
|
|
27797
|
+
let binary = "";
|
|
27798
|
+
for (let j = 0; j < slice.length; j++) {
|
|
27799
|
+
binary += String.fromCharCode(slice[j]);
|
|
27800
|
+
}
|
|
27801
|
+
base64 += btoa(binary);
|
|
28517
27802
|
}
|
|
28518
|
-
return
|
|
27803
|
+
return base64;
|
|
28519
27804
|
}
|
|
28520
27805
|
|
|
28521
27806
|
// src/lib/processors/ExcelProcessor.ts
|
|
@@ -29300,8 +28585,142 @@ function createCryptoPricePreProcessor(options = {}) {
|
|
|
29300
28585
|
// src/lib/chat/resumeStream.ts
|
|
29301
28586
|
init_clientConfig();
|
|
29302
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
|
+
|
|
29303
28723
|
// src/lib/chat/toolLoop.ts
|
|
29304
|
-
init_serverSentEvents_gen();
|
|
29305
28724
|
init_clientConfig();
|
|
29306
28725
|
init_embeddings();
|
|
29307
28726
|
init_redactor();
|
|
@@ -32986,6 +32405,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
32986
32405
|
decryptData,
|
|
32987
32406
|
decryptDataBatch,
|
|
32988
32407
|
decryptDataBytes,
|
|
32408
|
+
decryptDataBytesFromBytes,
|
|
32989
32409
|
decryptDataWithKey,
|
|
32990
32410
|
defaultServerToolsFilter,
|
|
32991
32411
|
deleteAllVaultMemoriesForUserOp,
|
|
@@ -33004,6 +32424,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
33004
32424
|
embedMessage,
|
|
33005
32425
|
encryptData,
|
|
33006
32426
|
encryptDataBatch,
|
|
32427
|
+
encryptDataBytes,
|
|
33007
32428
|
encryptDataWithKey,
|
|
33008
32429
|
ensureDefaultFoldersOp,
|
|
33009
32430
|
estimateMessagesTokens,
|
|
@@ -33032,6 +32453,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
33032
32453
|
getConversationsByProjectOp,
|
|
33033
32454
|
getConversationsLazyOp,
|
|
33034
32455
|
getConversationsOp,
|
|
32456
|
+
getConversationsPageOp,
|
|
33035
32457
|
getDocumentsOp,
|
|
33036
32458
|
getEncryptionKey,
|
|
33037
32459
|
getImagesOp,
|