@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
|
@@ -3,8 +3,7 @@ import {
|
|
|
3
3
|
getLogger
|
|
4
4
|
} from "./chunk-DFVCS3QQ.mjs";
|
|
5
5
|
import {
|
|
6
|
-
BASE_URL
|
|
7
|
-
createClientConfig
|
|
6
|
+
BASE_URL
|
|
8
7
|
} from "./chunk-GYKJOWEO.mjs";
|
|
9
8
|
|
|
10
9
|
// src/lib/db/chat/operations.ts
|
|
@@ -847,6 +846,12 @@ function getToolCallEvents(r) {
|
|
|
847
846
|
}
|
|
848
847
|
return r.tool_call_events;
|
|
849
848
|
}
|
|
849
|
+
function getToolsChecksum(r) {
|
|
850
|
+
if (isChatCompletionResponse(r)) {
|
|
851
|
+
return r.portal?.tools_checksum ?? r.tools_checksum;
|
|
852
|
+
}
|
|
853
|
+
return r.tools_checksum;
|
|
854
|
+
}
|
|
850
855
|
function getCostMicroUsd(r) {
|
|
851
856
|
if (isChatCompletionResponse(r)) {
|
|
852
857
|
return r.portal?.cost_micro_usd ?? r.usage?.cost_micro_usd;
|
|
@@ -1041,6 +1046,67 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
|
|
|
1041
1046
|
}
|
|
1042
1047
|
return baseMessage;
|
|
1043
1048
|
}
|
|
1049
|
+
function rawDate(value) {
|
|
1050
|
+
return new Date(typeof value === "number" ? value : 0);
|
|
1051
|
+
}
|
|
1052
|
+
function messageRawToStoredRaw(raw, projection) {
|
|
1053
|
+
const parseJsonField = (rawValue) => {
|
|
1054
|
+
if (!rawValue) return void 0;
|
|
1055
|
+
if (typeof rawValue === "string") {
|
|
1056
|
+
if (rawValue.startsWith("enc:")) return rawValue;
|
|
1057
|
+
try {
|
|
1058
|
+
return JSON.parse(rawValue);
|
|
1059
|
+
} catch {
|
|
1060
|
+
return void 0;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return rawValue;
|
|
1064
|
+
};
|
|
1065
|
+
const skipEmbeddings = projection?.skipEmbeddings === true;
|
|
1066
|
+
const vectorRaw = skipEmbeddings ? null : raw.vector;
|
|
1067
|
+
const chunksRaw = skipEmbeddings ? null : raw.chunks;
|
|
1068
|
+
return {
|
|
1069
|
+
uniqueId: raw.id,
|
|
1070
|
+
messageId: raw.message_id,
|
|
1071
|
+
conversationId: raw.conversation_id ?? "",
|
|
1072
|
+
role: raw.role ?? "",
|
|
1073
|
+
content: raw.content ?? "",
|
|
1074
|
+
model: raw.model,
|
|
1075
|
+
imageModel: raw.image_model,
|
|
1076
|
+
files: parseJsonField(raw.files),
|
|
1077
|
+
fileIds: parseJsonField(raw.file_ids),
|
|
1078
|
+
createdAt: rawDate(raw.created_at),
|
|
1079
|
+
updatedAt: rawDate(raw.updated_at),
|
|
1080
|
+
vector: skipEmbeddings ? void 0 : parseJsonField(vectorRaw),
|
|
1081
|
+
embeddingModel: raw.embedding_model,
|
|
1082
|
+
chunks: skipEmbeddings ? void 0 : parseJsonField(chunksRaw),
|
|
1083
|
+
usage: parseJsonField(raw.usage),
|
|
1084
|
+
sources: parseJsonField(raw.sources),
|
|
1085
|
+
responseDuration: raw.response_duration,
|
|
1086
|
+
// `was_stopped` is an OPTIONAL boolean: an unset row sanitizes to null, and the Model path
|
|
1087
|
+
// (message.wasStopped) returns that null verbatim. Preserve it (don't collapse to false) so the
|
|
1088
|
+
// raw path is byte-identical. When set, coerce SQLite 0/1 and LokiJS true/false alike.
|
|
1089
|
+
wasStopped: raw.was_stopped === null || raw.was_stopped === void 0 ? raw.was_stopped : raw.was_stopped === true || raw.was_stopped === 1,
|
|
1090
|
+
error: raw.error,
|
|
1091
|
+
thoughtProcess: parseJsonField(raw.thought_process),
|
|
1092
|
+
thinking: raw.thinking,
|
|
1093
|
+
parentMessageId: raw.parent_message_id,
|
|
1094
|
+
feedback: raw.feedback || null,
|
|
1095
|
+
toolCallEvents: parseJsonField(raw.tool_call_events)
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
|
|
1099
|
+
const baseMessage = messageRawToStoredRaw(raw, projection);
|
|
1100
|
+
if (walletAddress) {
|
|
1101
|
+
return await decryptMessageFields(
|
|
1102
|
+
baseMessage,
|
|
1103
|
+
walletAddress,
|
|
1104
|
+
signMessage,
|
|
1105
|
+
embeddedWalletSigner
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
return baseMessage;
|
|
1109
|
+
}
|
|
1044
1110
|
function conversationToStoredRaw(conversation) {
|
|
1045
1111
|
return {
|
|
1046
1112
|
uniqueId: conversation.id,
|
|
@@ -1065,6 +1131,33 @@ async function conversationToStored(conversation, walletAddress, signMessage, em
|
|
|
1065
1131
|
}
|
|
1066
1132
|
return baseConversation;
|
|
1067
1133
|
}
|
|
1134
|
+
function conversationRawToStoredRaw(raw) {
|
|
1135
|
+
const pinnedAt = raw.pinned_at;
|
|
1136
|
+
return {
|
|
1137
|
+
uniqueId: raw.id,
|
|
1138
|
+
conversationId: raw.conversation_id ?? "",
|
|
1139
|
+
title: raw.title ?? "",
|
|
1140
|
+
projectId: raw.project_id,
|
|
1141
|
+
createdAt: rawDate(raw.created_at),
|
|
1142
|
+
updatedAt: rawDate(raw.updated_at),
|
|
1143
|
+
// SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
|
|
1144
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
1145
|
+
// @date maps a non-number raw column (incl. an explicit unpin null) to null; a number → Date.
|
|
1146
|
+
pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
async function conversationRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner) {
|
|
1150
|
+
const baseConversation = conversationRawToStoredRaw(raw);
|
|
1151
|
+
if (walletAddress) {
|
|
1152
|
+
return await decryptConversationFields(
|
|
1153
|
+
baseConversation,
|
|
1154
|
+
walletAddress,
|
|
1155
|
+
signMessage,
|
|
1156
|
+
embeddedWalletSigner
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
return baseConversation;
|
|
1160
|
+
}
|
|
1068
1161
|
async function createConversationOp(ctx, opts, defaultTitle = "New Conversation") {
|
|
1069
1162
|
const convId = opts?.conversationId || generateConversationId();
|
|
1070
1163
|
const title = opts?.title || defaultTitle;
|
|
@@ -1104,36 +1197,51 @@ async function getConversationOp(ctx, id) {
|
|
|
1104
1197
|
) : null;
|
|
1105
1198
|
}
|
|
1106
1199
|
async function getConversationsOp(ctx) {
|
|
1107
|
-
const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).
|
|
1200
|
+
const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).unsafeFetchRaw();
|
|
1108
1201
|
return Promise.all(
|
|
1109
1202
|
results.map(
|
|
1110
|
-
(
|
|
1203
|
+
(raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
1111
1204
|
)
|
|
1112
1205
|
);
|
|
1113
1206
|
}
|
|
1114
|
-
function
|
|
1207
|
+
function conversationRawToLazyStored(raw) {
|
|
1208
|
+
const pinnedAt = raw.pinned_at;
|
|
1115
1209
|
return {
|
|
1116
|
-
uniqueId:
|
|
1117
|
-
conversationId:
|
|
1118
|
-
encryptedTitle:
|
|
1119
|
-
projectId:
|
|
1120
|
-
createdAt:
|
|
1121
|
-
updatedAt:
|
|
1122
|
-
isDeleted:
|
|
1123
|
-
pinnedAt:
|
|
1210
|
+
uniqueId: raw.id,
|
|
1211
|
+
conversationId: raw.conversation_id ?? "",
|
|
1212
|
+
encryptedTitle: raw.title ?? "",
|
|
1213
|
+
projectId: raw.project_id,
|
|
1214
|
+
createdAt: rawDate(raw.created_at),
|
|
1215
|
+
updatedAt: rawDate(raw.updated_at),
|
|
1216
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
1217
|
+
pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
|
|
1124
1218
|
};
|
|
1125
1219
|
}
|
|
1126
1220
|
async function getConversationsLazyOp(ctx) {
|
|
1127
|
-
const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).
|
|
1128
|
-
return results.map(
|
|
1221
|
+
const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).unsafeFetchRaw();
|
|
1222
|
+
return results.map(conversationRawToLazyStored);
|
|
1223
|
+
}
|
|
1224
|
+
async function getConversationsPageOp(ctx, options) {
|
|
1225
|
+
const limit = Math.floor(options?.limit ?? 200);
|
|
1226
|
+
if (!Number.isFinite(limit) || limit < 1) return [];
|
|
1227
|
+
const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
|
|
1228
|
+
const clauses = [Q.where("is_deleted", false)];
|
|
1229
|
+
if (options?.before !== void 0) {
|
|
1230
|
+
clauses.push(
|
|
1231
|
+
exclude.size > 0 ? Q.where("created_at", Q.lte(options.before)) : Q.where("created_at", Q.lt(options.before))
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
const fetched = await ctx.conversationsCollection.query(...clauses, Q.sortBy("created_at", Q.desc), Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
1235
|
+
const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
|
|
1236
|
+
return results.slice(0, limit).map(conversationRawToLazyStored);
|
|
1129
1237
|
}
|
|
1130
1238
|
async function getConversationsByProjectLazyOp(ctx, projectId) {
|
|
1131
1239
|
const results = await ctx.conversationsCollection.query(
|
|
1132
1240
|
Q.where("project_id", projectId === null ? "" : projectId),
|
|
1133
1241
|
Q.where("is_deleted", false),
|
|
1134
1242
|
Q.sortBy("created_at", Q.desc)
|
|
1135
|
-
).
|
|
1136
|
-
return results.map(
|
|
1243
|
+
).unsafeFetchRaw();
|
|
1244
|
+
return results.map(conversationRawToLazyStored);
|
|
1137
1245
|
}
|
|
1138
1246
|
async function updateConversationTitleOp(ctx, id, title) {
|
|
1139
1247
|
const results = await ctx.conversationsCollection.query(Q.where("conversation_id", id), Q.where("is_deleted", false)).fetch();
|
|
@@ -1179,10 +1287,10 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
|
|
|
1179
1287
|
return false;
|
|
1180
1288
|
}
|
|
1181
1289
|
async function getMessagesOp(ctx, convId) {
|
|
1182
|
-
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).
|
|
1290
|
+
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).unsafeFetchRaw();
|
|
1183
1291
|
return Promise.all(
|
|
1184
1292
|
results.map(
|
|
1185
|
-
(
|
|
1293
|
+
(raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
1186
1294
|
)
|
|
1187
1295
|
);
|
|
1188
1296
|
}
|
|
@@ -1199,39 +1307,40 @@ async function getMessagesPageOp(ctx, convId, opts) {
|
|
|
1199
1307
|
exclude.size > 0 ? Q.where("message_id", Q.lte(opts.beforeMessageId)) : Q.where("message_id", Q.lt(opts.beforeMessageId))
|
|
1200
1308
|
);
|
|
1201
1309
|
}
|
|
1202
|
-
const fetched = await ctx.messagesCollection.query(...clauses, Q.sortBy("message_id", Q.desc), Q.take(limit + exclude.size)).
|
|
1203
|
-
const results = (exclude.size > 0 ? fetched.filter((
|
|
1310
|
+
const fetched = await ctx.messagesCollection.query(...clauses, Q.sortBy("message_id", Q.desc), Q.take(limit + exclude.size)).unsafeFetchRaw();
|
|
1311
|
+
const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
|
|
1204
1312
|
results.reverse();
|
|
1205
1313
|
return Promise.all(
|
|
1206
1314
|
results.map(
|
|
1207
|
-
(
|
|
1315
|
+
(raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner, {
|
|
1208
1316
|
skipEmbeddings: true
|
|
1209
1317
|
})
|
|
1210
1318
|
)
|
|
1211
1319
|
);
|
|
1212
1320
|
}
|
|
1213
1321
|
async function getMessageSkeletonsOp(ctx, convId) {
|
|
1214
|
-
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).
|
|
1322
|
+
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).unsafeFetchRaw();
|
|
1215
1323
|
const roleById = /* @__PURE__ */ new Map();
|
|
1216
|
-
for (const
|
|
1217
|
-
roleById.set(
|
|
1218
|
-
}
|
|
1219
|
-
const skeletons = results.map((
|
|
1220
|
-
uniqueId:
|
|
1221
|
-
messageId:
|
|
1222
|
-
conversationId:
|
|
1223
|
-
role:
|
|
1224
|
-
createdAt:
|
|
1324
|
+
for (const raw of results) {
|
|
1325
|
+
roleById.set(raw.id, raw.role);
|
|
1326
|
+
}
|
|
1327
|
+
const skeletons = results.map((raw) => ({
|
|
1328
|
+
uniqueId: raw.id,
|
|
1329
|
+
messageId: raw.message_id,
|
|
1330
|
+
conversationId: raw.conversation_id ?? "",
|
|
1331
|
+
role: raw.role ?? "",
|
|
1332
|
+
createdAt: rawDate(raw.created_at),
|
|
1225
1333
|
// WatermelonDB surfaces unset text columns as null at runtime — normalize
|
|
1226
1334
|
// to undefined so `parentMessageId ?? undefined` keying works everywhere.
|
|
1227
|
-
parentMessageId:
|
|
1228
|
-
model:
|
|
1335
|
+
parentMessageId: raw.parent_message_id ?? void 0,
|
|
1336
|
+
model: raw.model ?? void 0
|
|
1229
1337
|
}));
|
|
1230
1338
|
const artifactIndices = [];
|
|
1231
1339
|
for (let i = 0; i < results.length; i++) {
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
if (
|
|
1340
|
+
const raw = results[i];
|
|
1341
|
+
const parentMessageId = raw.parent_message_id;
|
|
1342
|
+
if (raw.role !== "user" || !parentMessageId) continue;
|
|
1343
|
+
if (roleById.get(parentMessageId) === "user") {
|
|
1235
1344
|
artifactIndices.push(i);
|
|
1236
1345
|
}
|
|
1237
1346
|
}
|
|
@@ -2463,845 +2572,6 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
|
|
|
2463
2572
|
// src/lib/memoryEngine/constants.ts
|
|
2464
2573
|
var DEFAULT_API_EMBEDDING_MODEL = "qwen/qwen3-embedding-8b";
|
|
2465
2574
|
|
|
2466
|
-
// src/client/core/bodySerializer.gen.ts
|
|
2467
|
-
var jsonBodySerializer = {
|
|
2468
|
-
bodySerializer: (body) => JSON.stringify(
|
|
2469
|
-
body,
|
|
2470
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
2471
|
-
)
|
|
2472
|
-
};
|
|
2473
|
-
|
|
2474
|
-
// src/client/core/serverSentEvents.gen.ts
|
|
2475
|
-
var createSseClient = ({
|
|
2476
|
-
onRequest,
|
|
2477
|
-
onSseError,
|
|
2478
|
-
onSseEvent,
|
|
2479
|
-
responseTransformer,
|
|
2480
|
-
responseValidator,
|
|
2481
|
-
sseDefaultRetryDelay,
|
|
2482
|
-
sseMaxRetryAttempts,
|
|
2483
|
-
sseMaxRetryDelay,
|
|
2484
|
-
sseSleepFn,
|
|
2485
|
-
url,
|
|
2486
|
-
...options
|
|
2487
|
-
}) => {
|
|
2488
|
-
let lastEventId;
|
|
2489
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
2490
|
-
const createStream = async function* () {
|
|
2491
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
2492
|
-
let attempt = 0;
|
|
2493
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
2494
|
-
while (true) {
|
|
2495
|
-
if (signal.aborted) break;
|
|
2496
|
-
attempt++;
|
|
2497
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
2498
|
-
if (lastEventId !== void 0) {
|
|
2499
|
-
headers.set("Last-Event-ID", lastEventId);
|
|
2500
|
-
}
|
|
2501
|
-
try {
|
|
2502
|
-
const requestInit = {
|
|
2503
|
-
redirect: "follow",
|
|
2504
|
-
...options,
|
|
2505
|
-
body: options.serializedBody,
|
|
2506
|
-
headers,
|
|
2507
|
-
signal
|
|
2508
|
-
};
|
|
2509
|
-
let request = new Request(url, requestInit);
|
|
2510
|
-
if (onRequest) {
|
|
2511
|
-
request = await onRequest(url, requestInit);
|
|
2512
|
-
}
|
|
2513
|
-
const _fetch = options.fetch ?? globalThis.fetch;
|
|
2514
|
-
const response = await _fetch(request);
|
|
2515
|
-
if (!response.ok)
|
|
2516
|
-
throw new Error(
|
|
2517
|
-
`SSE failed: ${response.status} ${response.statusText}`
|
|
2518
|
-
);
|
|
2519
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
2520
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
2521
|
-
let buffer = "";
|
|
2522
|
-
const abortHandler = () => {
|
|
2523
|
-
try {
|
|
2524
|
-
reader.cancel();
|
|
2525
|
-
} catch {
|
|
2526
|
-
}
|
|
2527
|
-
};
|
|
2528
|
-
signal.addEventListener("abort", abortHandler);
|
|
2529
|
-
try {
|
|
2530
|
-
while (true) {
|
|
2531
|
-
const { done, value } = await reader.read();
|
|
2532
|
-
if (done) break;
|
|
2533
|
-
buffer += value;
|
|
2534
|
-
const chunks = buffer.split("\n\n");
|
|
2535
|
-
buffer = chunks.pop() ?? "";
|
|
2536
|
-
for (const chunk of chunks) {
|
|
2537
|
-
const lines = chunk.split("\n");
|
|
2538
|
-
const dataLines = [];
|
|
2539
|
-
let eventName;
|
|
2540
|
-
for (const line of lines) {
|
|
2541
|
-
if (line.startsWith("data:")) {
|
|
2542
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
2543
|
-
} else if (line.startsWith("event:")) {
|
|
2544
|
-
eventName = line.replace(/^event:\s*/, "");
|
|
2545
|
-
} else if (line.startsWith("id:")) {
|
|
2546
|
-
lastEventId = line.replace(/^id:\s*/, "");
|
|
2547
|
-
} else if (line.startsWith("retry:")) {
|
|
2548
|
-
const parsed = Number.parseInt(
|
|
2549
|
-
line.replace(/^retry:\s*/, ""),
|
|
2550
|
-
10
|
|
2551
|
-
);
|
|
2552
|
-
if (!Number.isNaN(parsed)) {
|
|
2553
|
-
retryDelay = parsed;
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
let data;
|
|
2558
|
-
let parsedJson = false;
|
|
2559
|
-
if (dataLines.length) {
|
|
2560
|
-
const rawData = dataLines.join("\n");
|
|
2561
|
-
try {
|
|
2562
|
-
data = JSON.parse(rawData);
|
|
2563
|
-
parsedJson = true;
|
|
2564
|
-
} catch {
|
|
2565
|
-
data = rawData;
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
if (parsedJson) {
|
|
2569
|
-
if (responseValidator) {
|
|
2570
|
-
await responseValidator(data);
|
|
2571
|
-
}
|
|
2572
|
-
if (responseTransformer) {
|
|
2573
|
-
data = await responseTransformer(data);
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
onSseEvent?.({
|
|
2577
|
-
data,
|
|
2578
|
-
event: eventName,
|
|
2579
|
-
id: lastEventId,
|
|
2580
|
-
retry: retryDelay
|
|
2581
|
-
});
|
|
2582
|
-
if (dataLines.length) {
|
|
2583
|
-
yield data;
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
} finally {
|
|
2588
|
-
signal.removeEventListener("abort", abortHandler);
|
|
2589
|
-
reader.releaseLock();
|
|
2590
|
-
}
|
|
2591
|
-
break;
|
|
2592
|
-
} catch (error) {
|
|
2593
|
-
onSseError?.(error);
|
|
2594
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
2595
|
-
break;
|
|
2596
|
-
}
|
|
2597
|
-
const backoff = Math.min(
|
|
2598
|
-
retryDelay * 2 ** (attempt - 1),
|
|
2599
|
-
sseMaxRetryDelay ?? 3e4
|
|
2600
|
-
);
|
|
2601
|
-
await sleep(backoff);
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
};
|
|
2605
|
-
const stream = createStream();
|
|
2606
|
-
return { stream };
|
|
2607
|
-
};
|
|
2608
|
-
|
|
2609
|
-
// src/client/core/pathSerializer.gen.ts
|
|
2610
|
-
var separatorArrayExplode = (style) => {
|
|
2611
|
-
switch (style) {
|
|
2612
|
-
case "label":
|
|
2613
|
-
return ".";
|
|
2614
|
-
case "matrix":
|
|
2615
|
-
return ";";
|
|
2616
|
-
case "simple":
|
|
2617
|
-
return ",";
|
|
2618
|
-
default:
|
|
2619
|
-
return "&";
|
|
2620
|
-
}
|
|
2621
|
-
};
|
|
2622
|
-
var separatorArrayNoExplode = (style) => {
|
|
2623
|
-
switch (style) {
|
|
2624
|
-
case "form":
|
|
2625
|
-
return ",";
|
|
2626
|
-
case "pipeDelimited":
|
|
2627
|
-
return "|";
|
|
2628
|
-
case "spaceDelimited":
|
|
2629
|
-
return "%20";
|
|
2630
|
-
default:
|
|
2631
|
-
return ",";
|
|
2632
|
-
}
|
|
2633
|
-
};
|
|
2634
|
-
var separatorObjectExplode = (style) => {
|
|
2635
|
-
switch (style) {
|
|
2636
|
-
case "label":
|
|
2637
|
-
return ".";
|
|
2638
|
-
case "matrix":
|
|
2639
|
-
return ";";
|
|
2640
|
-
case "simple":
|
|
2641
|
-
return ",";
|
|
2642
|
-
default:
|
|
2643
|
-
return "&";
|
|
2644
|
-
}
|
|
2645
|
-
};
|
|
2646
|
-
var serializeArrayParam = ({
|
|
2647
|
-
allowReserved,
|
|
2648
|
-
explode,
|
|
2649
|
-
name,
|
|
2650
|
-
style,
|
|
2651
|
-
value
|
|
2652
|
-
}) => {
|
|
2653
|
-
if (!explode) {
|
|
2654
|
-
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
2655
|
-
switch (style) {
|
|
2656
|
-
case "label":
|
|
2657
|
-
return `.${joinedValues2}`;
|
|
2658
|
-
case "matrix":
|
|
2659
|
-
return `;${name}=${joinedValues2}`;
|
|
2660
|
-
case "simple":
|
|
2661
|
-
return joinedValues2;
|
|
2662
|
-
default:
|
|
2663
|
-
return `${name}=${joinedValues2}`;
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
const separator = separatorArrayExplode(style);
|
|
2667
|
-
const joinedValues = value.map((v) => {
|
|
2668
|
-
if (style === "label" || style === "simple") {
|
|
2669
|
-
return allowReserved ? v : encodeURIComponent(v);
|
|
2670
|
-
}
|
|
2671
|
-
return serializePrimitiveParam({
|
|
2672
|
-
allowReserved,
|
|
2673
|
-
name,
|
|
2674
|
-
value: v
|
|
2675
|
-
});
|
|
2676
|
-
}).join(separator);
|
|
2677
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
2678
|
-
};
|
|
2679
|
-
var serializePrimitiveParam = ({
|
|
2680
|
-
allowReserved,
|
|
2681
|
-
name,
|
|
2682
|
-
value
|
|
2683
|
-
}) => {
|
|
2684
|
-
if (value === void 0 || value === null) {
|
|
2685
|
-
return "";
|
|
2686
|
-
}
|
|
2687
|
-
if (typeof value === "object") {
|
|
2688
|
-
throw new Error(
|
|
2689
|
-
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
2690
|
-
);
|
|
2691
|
-
}
|
|
2692
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
2693
|
-
};
|
|
2694
|
-
var serializeObjectParam = ({
|
|
2695
|
-
allowReserved,
|
|
2696
|
-
explode,
|
|
2697
|
-
name,
|
|
2698
|
-
style,
|
|
2699
|
-
value,
|
|
2700
|
-
valueOnly
|
|
2701
|
-
}) => {
|
|
2702
|
-
if (value instanceof Date) {
|
|
2703
|
-
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
2704
|
-
}
|
|
2705
|
-
if (style !== "deepObject" && !explode) {
|
|
2706
|
-
let values = [];
|
|
2707
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
2708
|
-
values = [
|
|
2709
|
-
...values,
|
|
2710
|
-
key,
|
|
2711
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
2712
|
-
];
|
|
2713
|
-
});
|
|
2714
|
-
const joinedValues2 = values.join(",");
|
|
2715
|
-
switch (style) {
|
|
2716
|
-
case "form":
|
|
2717
|
-
return `${name}=${joinedValues2}`;
|
|
2718
|
-
case "label":
|
|
2719
|
-
return `.${joinedValues2}`;
|
|
2720
|
-
case "matrix":
|
|
2721
|
-
return `;${name}=${joinedValues2}`;
|
|
2722
|
-
default:
|
|
2723
|
-
return joinedValues2;
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
const separator = separatorObjectExplode(style);
|
|
2727
|
-
const joinedValues = Object.entries(value).map(
|
|
2728
|
-
([key, v]) => serializePrimitiveParam({
|
|
2729
|
-
allowReserved,
|
|
2730
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
2731
|
-
value: v
|
|
2732
|
-
})
|
|
2733
|
-
).join(separator);
|
|
2734
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
2735
|
-
};
|
|
2736
|
-
|
|
2737
|
-
// src/client/core/utils.gen.ts
|
|
2738
|
-
function getValidRequestBody(options) {
|
|
2739
|
-
const hasBody = options.body !== void 0;
|
|
2740
|
-
const isSerializedBody = hasBody && options.bodySerializer;
|
|
2741
|
-
if (isSerializedBody) {
|
|
2742
|
-
if ("serializedBody" in options) {
|
|
2743
|
-
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
2744
|
-
return hasSerializedBody ? options.serializedBody : null;
|
|
2745
|
-
}
|
|
2746
|
-
return options.body !== "" ? options.body : null;
|
|
2747
|
-
}
|
|
2748
|
-
if (hasBody) {
|
|
2749
|
-
return options.body;
|
|
2750
|
-
}
|
|
2751
|
-
return void 0;
|
|
2752
|
-
}
|
|
2753
|
-
|
|
2754
|
-
// src/client/core/auth.gen.ts
|
|
2755
|
-
var getAuthToken = async (auth, callback) => {
|
|
2756
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
2757
|
-
if (!token) {
|
|
2758
|
-
return;
|
|
2759
|
-
}
|
|
2760
|
-
if (auth.scheme === "bearer") {
|
|
2761
|
-
return `Bearer ${token}`;
|
|
2762
|
-
}
|
|
2763
|
-
if (auth.scheme === "basic") {
|
|
2764
|
-
return `Basic ${btoa(token)}`;
|
|
2765
|
-
}
|
|
2766
|
-
return token;
|
|
2767
|
-
};
|
|
2768
|
-
|
|
2769
|
-
// src/client/client/utils.gen.ts
|
|
2770
|
-
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
2771
|
-
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
2772
|
-
let url = _url;
|
|
2773
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
2774
|
-
if (matches) {
|
|
2775
|
-
for (const match of matches) {
|
|
2776
|
-
let explode = false;
|
|
2777
|
-
let name = match.substring(1, match.length - 1);
|
|
2778
|
-
let style = "simple";
|
|
2779
|
-
if (name.endsWith("*")) {
|
|
2780
|
-
explode = true;
|
|
2781
|
-
name = name.substring(0, name.length - 1);
|
|
2782
|
-
}
|
|
2783
|
-
if (name.startsWith(".")) {
|
|
2784
|
-
name = name.substring(1);
|
|
2785
|
-
style = "label";
|
|
2786
|
-
} else if (name.startsWith(";")) {
|
|
2787
|
-
name = name.substring(1);
|
|
2788
|
-
style = "matrix";
|
|
2789
|
-
}
|
|
2790
|
-
const value = path[name];
|
|
2791
|
-
if (value === void 0 || value === null) {
|
|
2792
|
-
continue;
|
|
2793
|
-
}
|
|
2794
|
-
if (Array.isArray(value)) {
|
|
2795
|
-
url = url.replace(
|
|
2796
|
-
match,
|
|
2797
|
-
serializeArrayParam({ explode, name, style, value })
|
|
2798
|
-
);
|
|
2799
|
-
continue;
|
|
2800
|
-
}
|
|
2801
|
-
if (typeof value === "object") {
|
|
2802
|
-
url = url.replace(
|
|
2803
|
-
match,
|
|
2804
|
-
serializeObjectParam({
|
|
2805
|
-
explode,
|
|
2806
|
-
name,
|
|
2807
|
-
style,
|
|
2808
|
-
value,
|
|
2809
|
-
valueOnly: true
|
|
2810
|
-
})
|
|
2811
|
-
);
|
|
2812
|
-
continue;
|
|
2813
|
-
}
|
|
2814
|
-
if (style === "matrix") {
|
|
2815
|
-
url = url.replace(
|
|
2816
|
-
match,
|
|
2817
|
-
`;${serializePrimitiveParam({
|
|
2818
|
-
name,
|
|
2819
|
-
value
|
|
2820
|
-
})}`
|
|
2821
|
-
);
|
|
2822
|
-
continue;
|
|
2823
|
-
}
|
|
2824
|
-
const replaceValue = encodeURIComponent(
|
|
2825
|
-
style === "label" ? `.${value}` : value
|
|
2826
|
-
);
|
|
2827
|
-
url = url.replace(match, replaceValue);
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
return url;
|
|
2831
|
-
};
|
|
2832
|
-
var createQuerySerializer = ({
|
|
2833
|
-
parameters = {},
|
|
2834
|
-
...args
|
|
2835
|
-
} = {}) => {
|
|
2836
|
-
const querySerializer = (queryParams) => {
|
|
2837
|
-
const search = [];
|
|
2838
|
-
if (queryParams && typeof queryParams === "object") {
|
|
2839
|
-
for (const name in queryParams) {
|
|
2840
|
-
const value = queryParams[name];
|
|
2841
|
-
if (value === void 0 || value === null) {
|
|
2842
|
-
continue;
|
|
2843
|
-
}
|
|
2844
|
-
const options = parameters[name] || args;
|
|
2845
|
-
if (Array.isArray(value)) {
|
|
2846
|
-
const serializedArray = serializeArrayParam({
|
|
2847
|
-
allowReserved: options.allowReserved,
|
|
2848
|
-
explode: true,
|
|
2849
|
-
name,
|
|
2850
|
-
style: "form",
|
|
2851
|
-
value,
|
|
2852
|
-
...options.array
|
|
2853
|
-
});
|
|
2854
|
-
if (serializedArray) search.push(serializedArray);
|
|
2855
|
-
} else if (typeof value === "object") {
|
|
2856
|
-
const serializedObject = serializeObjectParam({
|
|
2857
|
-
allowReserved: options.allowReserved,
|
|
2858
|
-
explode: true,
|
|
2859
|
-
name,
|
|
2860
|
-
style: "deepObject",
|
|
2861
|
-
value,
|
|
2862
|
-
...options.object
|
|
2863
|
-
});
|
|
2864
|
-
if (serializedObject) search.push(serializedObject);
|
|
2865
|
-
} else {
|
|
2866
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
2867
|
-
allowReserved: options.allowReserved,
|
|
2868
|
-
name,
|
|
2869
|
-
value
|
|
2870
|
-
});
|
|
2871
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
2872
|
-
}
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
return search.join("&");
|
|
2876
|
-
};
|
|
2877
|
-
return querySerializer;
|
|
2878
|
-
};
|
|
2879
|
-
var getParseAs = (contentType) => {
|
|
2880
|
-
if (!contentType) {
|
|
2881
|
-
return "stream";
|
|
2882
|
-
}
|
|
2883
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
2884
|
-
if (!cleanContent) {
|
|
2885
|
-
return;
|
|
2886
|
-
}
|
|
2887
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
2888
|
-
return "json";
|
|
2889
|
-
}
|
|
2890
|
-
if (cleanContent === "multipart/form-data") {
|
|
2891
|
-
return "formData";
|
|
2892
|
-
}
|
|
2893
|
-
if (["application/", "audio/", "image/", "video/"].some(
|
|
2894
|
-
(type) => cleanContent.startsWith(type)
|
|
2895
|
-
)) {
|
|
2896
|
-
return "blob";
|
|
2897
|
-
}
|
|
2898
|
-
if (cleanContent.startsWith("text/")) {
|
|
2899
|
-
return "text";
|
|
2900
|
-
}
|
|
2901
|
-
return;
|
|
2902
|
-
};
|
|
2903
|
-
var checkForExistence = (options, name) => {
|
|
2904
|
-
if (!name) {
|
|
2905
|
-
return false;
|
|
2906
|
-
}
|
|
2907
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
2908
|
-
return true;
|
|
2909
|
-
}
|
|
2910
|
-
return false;
|
|
2911
|
-
};
|
|
2912
|
-
var setAuthParams = async ({
|
|
2913
|
-
security,
|
|
2914
|
-
...options
|
|
2915
|
-
}) => {
|
|
2916
|
-
for (const auth of security) {
|
|
2917
|
-
if (checkForExistence(options, auth.name)) {
|
|
2918
|
-
continue;
|
|
2919
|
-
}
|
|
2920
|
-
const token = await getAuthToken(auth, options.auth);
|
|
2921
|
-
if (!token) {
|
|
2922
|
-
continue;
|
|
2923
|
-
}
|
|
2924
|
-
const name = auth.name ?? "Authorization";
|
|
2925
|
-
switch (auth.in) {
|
|
2926
|
-
case "query":
|
|
2927
|
-
if (!options.query) {
|
|
2928
|
-
options.query = {};
|
|
2929
|
-
}
|
|
2930
|
-
options.query[name] = token;
|
|
2931
|
-
break;
|
|
2932
|
-
case "cookie":
|
|
2933
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
2934
|
-
break;
|
|
2935
|
-
case "header":
|
|
2936
|
-
default:
|
|
2937
|
-
options.headers.set(name, token);
|
|
2938
|
-
break;
|
|
2939
|
-
}
|
|
2940
|
-
}
|
|
2941
|
-
};
|
|
2942
|
-
var buildUrl = (options) => {
|
|
2943
|
-
const url = getUrl({
|
|
2944
|
-
baseUrl: options.baseUrl,
|
|
2945
|
-
path: options.path,
|
|
2946
|
-
query: options.query,
|
|
2947
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
2948
|
-
url: options.url
|
|
2949
|
-
});
|
|
2950
|
-
return url;
|
|
2951
|
-
};
|
|
2952
|
-
var getUrl = ({
|
|
2953
|
-
baseUrl,
|
|
2954
|
-
path,
|
|
2955
|
-
query,
|
|
2956
|
-
querySerializer,
|
|
2957
|
-
url: _url
|
|
2958
|
-
}) => {
|
|
2959
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
2960
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
2961
|
-
if (path) {
|
|
2962
|
-
url = defaultPathSerializer({ path, url });
|
|
2963
|
-
}
|
|
2964
|
-
let search = query ? querySerializer(query) : "";
|
|
2965
|
-
if (search.startsWith("?")) {
|
|
2966
|
-
search = search.substring(1);
|
|
2967
|
-
}
|
|
2968
|
-
if (search) {
|
|
2969
|
-
url += `?${search}`;
|
|
2970
|
-
}
|
|
2971
|
-
return url;
|
|
2972
|
-
};
|
|
2973
|
-
var mergeConfigs = (a, b) => {
|
|
2974
|
-
const config = { ...a, ...b };
|
|
2975
|
-
if (config.baseUrl?.endsWith("/")) {
|
|
2976
|
-
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
2977
|
-
}
|
|
2978
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
2979
|
-
return config;
|
|
2980
|
-
};
|
|
2981
|
-
var headersEntries = (headers) => {
|
|
2982
|
-
const entries = [];
|
|
2983
|
-
headers.forEach((value, key) => {
|
|
2984
|
-
entries.push([key, value]);
|
|
2985
|
-
});
|
|
2986
|
-
return entries;
|
|
2987
|
-
};
|
|
2988
|
-
var mergeHeaders = (...headers) => {
|
|
2989
|
-
const mergedHeaders = new Headers();
|
|
2990
|
-
for (const header of headers) {
|
|
2991
|
-
if (!header || typeof header !== "object") {
|
|
2992
|
-
continue;
|
|
2993
|
-
}
|
|
2994
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
2995
|
-
for (const [key, value] of iterator) {
|
|
2996
|
-
if (value === null) {
|
|
2997
|
-
mergedHeaders.delete(key);
|
|
2998
|
-
} else if (Array.isArray(value)) {
|
|
2999
|
-
for (const v of value) {
|
|
3000
|
-
mergedHeaders.append(key, v);
|
|
3001
|
-
}
|
|
3002
|
-
} else if (value !== void 0) {
|
|
3003
|
-
mergedHeaders.set(
|
|
3004
|
-
key,
|
|
3005
|
-
typeof value === "object" ? JSON.stringify(value) : value
|
|
3006
|
-
);
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
return mergedHeaders;
|
|
3011
|
-
};
|
|
3012
|
-
var Interceptors = class {
|
|
3013
|
-
constructor() {
|
|
3014
|
-
this.fns = [];
|
|
3015
|
-
}
|
|
3016
|
-
clear() {
|
|
3017
|
-
this.fns = [];
|
|
3018
|
-
}
|
|
3019
|
-
eject(id) {
|
|
3020
|
-
const index = this.getInterceptorIndex(id);
|
|
3021
|
-
if (this.fns[index]) {
|
|
3022
|
-
this.fns[index] = null;
|
|
3023
|
-
}
|
|
3024
|
-
}
|
|
3025
|
-
exists(id) {
|
|
3026
|
-
const index = this.getInterceptorIndex(id);
|
|
3027
|
-
return Boolean(this.fns[index]);
|
|
3028
|
-
}
|
|
3029
|
-
getInterceptorIndex(id) {
|
|
3030
|
-
if (typeof id === "number") {
|
|
3031
|
-
return this.fns[id] ? id : -1;
|
|
3032
|
-
}
|
|
3033
|
-
return this.fns.indexOf(id);
|
|
3034
|
-
}
|
|
3035
|
-
update(id, fn) {
|
|
3036
|
-
const index = this.getInterceptorIndex(id);
|
|
3037
|
-
if (this.fns[index]) {
|
|
3038
|
-
this.fns[index] = fn;
|
|
3039
|
-
return id;
|
|
3040
|
-
}
|
|
3041
|
-
return false;
|
|
3042
|
-
}
|
|
3043
|
-
use(fn) {
|
|
3044
|
-
this.fns.push(fn);
|
|
3045
|
-
return this.fns.length - 1;
|
|
3046
|
-
}
|
|
3047
|
-
};
|
|
3048
|
-
var createInterceptors = () => ({
|
|
3049
|
-
error: new Interceptors(),
|
|
3050
|
-
request: new Interceptors(),
|
|
3051
|
-
response: new Interceptors()
|
|
3052
|
-
});
|
|
3053
|
-
var defaultQuerySerializer = createQuerySerializer({
|
|
3054
|
-
allowReserved: false,
|
|
3055
|
-
array: {
|
|
3056
|
-
explode: true,
|
|
3057
|
-
style: "form"
|
|
3058
|
-
},
|
|
3059
|
-
object: {
|
|
3060
|
-
explode: true,
|
|
3061
|
-
style: "deepObject"
|
|
3062
|
-
}
|
|
3063
|
-
});
|
|
3064
|
-
var defaultHeaders = {
|
|
3065
|
-
"Content-Type": "application/json"
|
|
3066
|
-
};
|
|
3067
|
-
var createConfig = (override = {}) => ({
|
|
3068
|
-
...jsonBodySerializer,
|
|
3069
|
-
headers: defaultHeaders,
|
|
3070
|
-
parseAs: "auto",
|
|
3071
|
-
querySerializer: defaultQuerySerializer,
|
|
3072
|
-
...override
|
|
3073
|
-
});
|
|
3074
|
-
|
|
3075
|
-
// src/client/client/client.gen.ts
|
|
3076
|
-
var createClient = (config = {}) => {
|
|
3077
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
3078
|
-
const getConfig = () => ({ ..._config });
|
|
3079
|
-
const setConfig = (config2) => {
|
|
3080
|
-
_config = mergeConfigs(_config, config2);
|
|
3081
|
-
return getConfig();
|
|
3082
|
-
};
|
|
3083
|
-
const interceptors = createInterceptors();
|
|
3084
|
-
const beforeRequest = async (options) => {
|
|
3085
|
-
const opts = {
|
|
3086
|
-
..._config,
|
|
3087
|
-
...options,
|
|
3088
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
3089
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
3090
|
-
serializedBody: void 0
|
|
3091
|
-
};
|
|
3092
|
-
if (opts.security) {
|
|
3093
|
-
await setAuthParams({
|
|
3094
|
-
...opts,
|
|
3095
|
-
security: opts.security
|
|
3096
|
-
});
|
|
3097
|
-
}
|
|
3098
|
-
if (opts.requestValidator) {
|
|
3099
|
-
await opts.requestValidator(opts);
|
|
3100
|
-
}
|
|
3101
|
-
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
3102
|
-
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
3103
|
-
}
|
|
3104
|
-
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
3105
|
-
opts.headers.delete("Content-Type");
|
|
3106
|
-
}
|
|
3107
|
-
const url = buildUrl(opts);
|
|
3108
|
-
return { opts, url };
|
|
3109
|
-
};
|
|
3110
|
-
const request = async (options) => {
|
|
3111
|
-
const { opts, url } = await beforeRequest(options);
|
|
3112
|
-
for (const fn of interceptors.request.fns) {
|
|
3113
|
-
if (fn) {
|
|
3114
|
-
await fn(opts);
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
const _fetch = opts.fetch;
|
|
3118
|
-
const requestInit = {
|
|
3119
|
-
...opts,
|
|
3120
|
-
body: getValidRequestBody(opts)
|
|
3121
|
-
};
|
|
3122
|
-
let response = await _fetch(url, requestInit);
|
|
3123
|
-
for (const fn of interceptors.response.fns) {
|
|
3124
|
-
if (fn) {
|
|
3125
|
-
response = await fn(response, opts);
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
3128
|
-
const result = {
|
|
3129
|
-
response
|
|
3130
|
-
};
|
|
3131
|
-
if (response.ok) {
|
|
3132
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
3133
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
3134
|
-
let emptyData;
|
|
3135
|
-
switch (parseAs) {
|
|
3136
|
-
case "arrayBuffer":
|
|
3137
|
-
case "blob":
|
|
3138
|
-
case "text":
|
|
3139
|
-
emptyData = await response[parseAs]();
|
|
3140
|
-
break;
|
|
3141
|
-
case "formData":
|
|
3142
|
-
emptyData = new FormData();
|
|
3143
|
-
break;
|
|
3144
|
-
case "stream":
|
|
3145
|
-
emptyData = response.body;
|
|
3146
|
-
break;
|
|
3147
|
-
case "json":
|
|
3148
|
-
default:
|
|
3149
|
-
emptyData = {};
|
|
3150
|
-
break;
|
|
3151
|
-
}
|
|
3152
|
-
return {
|
|
3153
|
-
data: emptyData,
|
|
3154
|
-
...result
|
|
3155
|
-
};
|
|
3156
|
-
}
|
|
3157
|
-
let data;
|
|
3158
|
-
switch (parseAs) {
|
|
3159
|
-
case "arrayBuffer":
|
|
3160
|
-
case "blob":
|
|
3161
|
-
case "formData":
|
|
3162
|
-
case "json":
|
|
3163
|
-
case "text":
|
|
3164
|
-
data = await response[parseAs]();
|
|
3165
|
-
break;
|
|
3166
|
-
case "stream":
|
|
3167
|
-
return {
|
|
3168
|
-
data: response.body,
|
|
3169
|
-
...result
|
|
3170
|
-
};
|
|
3171
|
-
}
|
|
3172
|
-
if (parseAs === "json") {
|
|
3173
|
-
if (opts.responseValidator) {
|
|
3174
|
-
await opts.responseValidator(data);
|
|
3175
|
-
}
|
|
3176
|
-
if (opts.responseTransformer) {
|
|
3177
|
-
data = await opts.responseTransformer(data);
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
return {
|
|
3181
|
-
data,
|
|
3182
|
-
...result
|
|
3183
|
-
};
|
|
3184
|
-
}
|
|
3185
|
-
const textError = await response.text();
|
|
3186
|
-
let jsonError;
|
|
3187
|
-
try {
|
|
3188
|
-
jsonError = JSON.parse(textError);
|
|
3189
|
-
} catch {
|
|
3190
|
-
}
|
|
3191
|
-
const error = jsonError ?? textError;
|
|
3192
|
-
let finalError = error;
|
|
3193
|
-
for (const fn of interceptors.error.fns) {
|
|
3194
|
-
if (fn) {
|
|
3195
|
-
finalError = await fn(error, response, opts);
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
finalError = finalError || {};
|
|
3199
|
-
if (opts.throwOnError) {
|
|
3200
|
-
throw finalError;
|
|
3201
|
-
}
|
|
3202
|
-
return {
|
|
3203
|
-
error: finalError,
|
|
3204
|
-
...result
|
|
3205
|
-
};
|
|
3206
|
-
};
|
|
3207
|
-
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
3208
|
-
const makeSseFn = (method) => async (options) => {
|
|
3209
|
-
const { opts, url } = await beforeRequest(options);
|
|
3210
|
-
return createSseClient({
|
|
3211
|
-
...opts,
|
|
3212
|
-
body: opts.body,
|
|
3213
|
-
headers: opts.headers,
|
|
3214
|
-
method,
|
|
3215
|
-
onRequest: async (url2, init) => {
|
|
3216
|
-
let request2 = new Request(url2, init);
|
|
3217
|
-
const requestInit = {
|
|
3218
|
-
...init,
|
|
3219
|
-
method: init.method,
|
|
3220
|
-
url: url2
|
|
3221
|
-
};
|
|
3222
|
-
for (const fn of interceptors.request.fns) {
|
|
3223
|
-
if (fn) {
|
|
3224
|
-
await fn(requestInit);
|
|
3225
|
-
request2 = new Request(requestInit.url, requestInit);
|
|
3226
|
-
}
|
|
3227
|
-
}
|
|
3228
|
-
return request2;
|
|
3229
|
-
},
|
|
3230
|
-
url
|
|
3231
|
-
});
|
|
3232
|
-
};
|
|
3233
|
-
return {
|
|
3234
|
-
buildUrl,
|
|
3235
|
-
connect: makeMethodFn("CONNECT"),
|
|
3236
|
-
delete: makeMethodFn("DELETE"),
|
|
3237
|
-
get: makeMethodFn("GET"),
|
|
3238
|
-
getConfig,
|
|
3239
|
-
head: makeMethodFn("HEAD"),
|
|
3240
|
-
interceptors,
|
|
3241
|
-
options: makeMethodFn("OPTIONS"),
|
|
3242
|
-
patch: makeMethodFn("PATCH"),
|
|
3243
|
-
post: makeMethodFn("POST"),
|
|
3244
|
-
put: makeMethodFn("PUT"),
|
|
3245
|
-
request,
|
|
3246
|
-
setConfig,
|
|
3247
|
-
sse: {
|
|
3248
|
-
connect: makeSseFn("CONNECT"),
|
|
3249
|
-
delete: makeSseFn("DELETE"),
|
|
3250
|
-
get: makeSseFn("GET"),
|
|
3251
|
-
head: makeSseFn("HEAD"),
|
|
3252
|
-
options: makeSseFn("OPTIONS"),
|
|
3253
|
-
patch: makeSseFn("PATCH"),
|
|
3254
|
-
post: makeSseFn("POST"),
|
|
3255
|
-
put: makeSseFn("PUT"),
|
|
3256
|
-
trace: makeSseFn("TRACE")
|
|
3257
|
-
},
|
|
3258
|
-
trace: makeMethodFn("TRACE")
|
|
3259
|
-
};
|
|
3260
|
-
};
|
|
3261
|
-
|
|
3262
|
-
// src/client/client.gen.ts
|
|
3263
|
-
var client = createClient(createClientConfig(createConfig()));
|
|
3264
|
-
|
|
3265
|
-
// src/client/sdk.gen.ts
|
|
3266
|
-
var getApiV1CreditsBalance = (options) => {
|
|
3267
|
-
return (options?.client ?? client).get({
|
|
3268
|
-
url: "/api/v1/credits/balance",
|
|
3269
|
-
...options
|
|
3270
|
-
});
|
|
3271
|
-
};
|
|
3272
|
-
var getApiV1CreditsPacks = (options) => {
|
|
3273
|
-
return (options?.client ?? client).get({
|
|
3274
|
-
url: "/api/v1/credits/packs",
|
|
3275
|
-
...options
|
|
3276
|
-
});
|
|
3277
|
-
};
|
|
3278
|
-
var postApiV1CreditsPurchase = (options) => {
|
|
3279
|
-
return (options.client ?? client).post({
|
|
3280
|
-
url: "/api/v1/credits/purchase",
|
|
3281
|
-
...options,
|
|
3282
|
-
headers: {
|
|
3283
|
-
"Content-Type": "application/json",
|
|
3284
|
-
...options.headers
|
|
3285
|
-
}
|
|
3286
|
-
});
|
|
3287
|
-
};
|
|
3288
|
-
var postApiV1Embeddings = (options) => {
|
|
3289
|
-
return (options.client ?? client).post({
|
|
3290
|
-
url: "/api/v1/embeddings",
|
|
3291
|
-
...options,
|
|
3292
|
-
headers: {
|
|
3293
|
-
"Content-Type": "application/json",
|
|
3294
|
-
...options.headers
|
|
3295
|
-
}
|
|
3296
|
-
});
|
|
3297
|
-
};
|
|
3298
|
-
var getApiV1Models = (options) => {
|
|
3299
|
-
return (options?.client ?? client).get({
|
|
3300
|
-
url: "/api/v1/models",
|
|
3301
|
-
...options
|
|
3302
|
-
});
|
|
3303
|
-
};
|
|
3304
|
-
|
|
3305
2575
|
// src/lib/memoryEngine/chunking.ts
|
|
3306
2576
|
var DEFAULT_CHUNK_SIZE = 400;
|
|
3307
2577
|
var DEFAULT_CHUNK_OVERLAP = 50;
|
|
@@ -3437,8 +2707,8 @@ function shouldChunkMessage(content, chunkSize = DEFAULT_CHUNK_SIZE) {
|
|
|
3437
2707
|
return content.length > chunkSize;
|
|
3438
2708
|
}
|
|
3439
2709
|
|
|
3440
|
-
// src/lib/memoryEngine/
|
|
3441
|
-
|
|
2710
|
+
// src/lib/memoryEngine/generate.ts
|
|
2711
|
+
import { postApiV1Embeddings } from "@anuma/sdk";
|
|
3442
2712
|
var EMBED_MAX_ATTEMPTS = 4;
|
|
3443
2713
|
async function withEmbeddingRetry(call) {
|
|
3444
2714
|
let last;
|
|
@@ -3482,7 +2752,7 @@ async function generateEmbedding(text, options) {
|
|
|
3482
2752
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
3483
2753
|
if (cache) {
|
|
3484
2754
|
const cached = cache.get(text);
|
|
3485
|
-
if (cached) return cached;
|
|
2755
|
+
if (cached) return Array.from(cached);
|
|
3486
2756
|
}
|
|
3487
2757
|
let headers;
|
|
3488
2758
|
if (apiKey) {
|
|
@@ -3521,10 +2791,11 @@ async function generateEmbedding(text, options) {
|
|
|
3521
2791
|
totalTokens: response.data.usage.total_tokens ?? 0
|
|
3522
2792
|
});
|
|
3523
2793
|
}
|
|
2794
|
+
const f32Embedding = Float32Array.from(embedding);
|
|
3524
2795
|
if (cache) {
|
|
3525
|
-
cache.set(text,
|
|
2796
|
+
cache.set(text, f32Embedding);
|
|
3526
2797
|
}
|
|
3527
|
-
return
|
|
2798
|
+
return Array.from(f32Embedding);
|
|
3528
2799
|
}
|
|
3529
2800
|
var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
3530
2801
|
var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
@@ -3562,7 +2833,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
3562
2833
|
if (cache) {
|
|
3563
2834
|
const cached = cache.get(texts[i]);
|
|
3564
2835
|
if (cached) {
|
|
3565
|
-
results[i] = cached;
|
|
2836
|
+
results[i] = Array.from(cached);
|
|
3566
2837
|
continue;
|
|
3567
2838
|
}
|
|
3568
2839
|
}
|
|
@@ -3623,13 +2894,17 @@ async function generateEmbeddings(texts, options) {
|
|
|
3623
2894
|
newEmbeddings = allEmbeddings.flat();
|
|
3624
2895
|
}
|
|
3625
2896
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
3626
|
-
|
|
2897
|
+
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
2898
|
+
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
3627
2899
|
if (cache) {
|
|
3628
|
-
cache.set(uncachedTexts[i],
|
|
2900
|
+
cache.set(uncachedTexts[i], f32Embedding);
|
|
3629
2901
|
}
|
|
3630
2902
|
}
|
|
3631
2903
|
return results;
|
|
3632
2904
|
}
|
|
2905
|
+
|
|
2906
|
+
// src/lib/memoryEngine/embeddings.ts
|
|
2907
|
+
var DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
3633
2908
|
async function embedMessage(ctx, messageId, options) {
|
|
3634
2909
|
let message;
|
|
3635
2910
|
const conversations = await getConversationsOp(ctx);
|
|
@@ -5049,7 +4324,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
5049
4324
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
5050
4325
|
);
|
|
5051
4326
|
}
|
|
5052
|
-
const { recall: recall2 } = await import("./recall-
|
|
4327
|
+
const { recall: recall2 } = await import("./recall-LICO3TJ7.mjs");
|
|
5053
4328
|
const result = await recall2(
|
|
5054
4329
|
query,
|
|
5055
4330
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -5669,11 +4944,6 @@ function toChunkMemory(r) {
|
|
|
5669
4944
|
}
|
|
5670
4945
|
|
|
5671
4946
|
export {
|
|
5672
|
-
createSseClient,
|
|
5673
|
-
getApiV1CreditsBalance,
|
|
5674
|
-
getApiV1CreditsPacks,
|
|
5675
|
-
postApiV1CreditsPurchase,
|
|
5676
|
-
getApiV1Models,
|
|
5677
4947
|
onClearAllEncryptionState,
|
|
5678
4948
|
onKeyAvailable,
|
|
5679
4949
|
clearEncryptionKey,
|
|
@@ -5689,6 +4959,7 @@ export {
|
|
|
5689
4959
|
encryptJsonField,
|
|
5690
4960
|
decryptJsonField,
|
|
5691
4961
|
getToolCallEvents,
|
|
4962
|
+
getToolsChecksum,
|
|
5692
4963
|
getImageModel,
|
|
5693
4964
|
extractAssistantText,
|
|
5694
4965
|
stripToolCalls,
|
|
@@ -5701,6 +4972,7 @@ export {
|
|
|
5701
4972
|
getConversationOp,
|
|
5702
4973
|
getConversationsOp,
|
|
5703
4974
|
getConversationsLazyOp,
|
|
4975
|
+
getConversationsPageOp,
|
|
5704
4976
|
getConversationsByProjectLazyOp,
|
|
5705
4977
|
updateConversationTitleOp,
|
|
5706
4978
|
deleteConversationOp,
|
|
@@ -5713,6 +4985,7 @@ export {
|
|
|
5713
4985
|
createMessageOp,
|
|
5714
4986
|
upsertMessageOp,
|
|
5715
4987
|
updateMessageEmbeddingOp,
|
|
4988
|
+
updateMessageChunksOp,
|
|
5716
4989
|
updateMessageErrorOp,
|
|
5717
4990
|
searchChunksOp,
|
|
5718
4991
|
makeSyntheticStoredMessage,
|
|
@@ -5723,9 +4996,9 @@ export {
|
|
|
5723
4996
|
chunkText,
|
|
5724
4997
|
shouldChunkMessage,
|
|
5725
4998
|
DEFAULT_API_EMBEDDING_MODEL,
|
|
5726
|
-
DEFAULT_MIN_CONTENT_LENGTH,
|
|
5727
4999
|
generateEmbedding,
|
|
5728
5000
|
generateEmbeddings,
|
|
5001
|
+
DEFAULT_MIN_CONTENT_LENGTH,
|
|
5729
5002
|
embedMessage,
|
|
5730
5003
|
embedAllMessages,
|
|
5731
5004
|
chunkAndEmbedMessage,
|