@langchain/langgraph-sdk 1.3.0 → 1.4.4
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/package.json +5 -5
- package/CHANGELOG.md +0 -275
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
- package/dist/auth/error.cjs +0 -79
- package/dist/auth/error.cjs.map +0 -1
- package/dist/auth/error.d.cts +0 -13
- package/dist/auth/error.d.cts.map +0 -1
- package/dist/auth/error.d.ts +0 -13
- package/dist/auth/error.d.ts.map +0 -1
- package/dist/auth/error.js +0 -78
- package/dist/auth/error.js.map +0 -1
- package/dist/auth/index.cjs +0 -39
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.d.cts +0 -31
- package/dist/auth/index.d.cts.map +0 -1
- package/dist/auth/index.d.ts +0 -31
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -37
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.d.cts +0 -294
- package/dist/auth/types.d.cts.map +0 -1
- package/dist/auth/types.d.ts +0 -294
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/client.cjs +0 -1193
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -780
- package/dist/client.d.cts.map +0 -1
- package/dist/client.d.ts +0 -780
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -1186
- package/dist/client.js.map +0 -1
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -4
- package/dist/logging/index.cjs +0 -35
- package/dist/logging/index.cjs.map +0 -1
- package/dist/logging/index.d.cts +0 -47
- package/dist/logging/index.d.cts.map +0 -1
- package/dist/logging/index.d.ts +0 -47
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/logging/index.js +0 -34
- package/dist/logging/index.js.map +0 -1
- package/dist/react/index.cjs +0 -5
- package/dist/react/index.d.cts +0 -4
- package/dist/react/index.d.ts +0 -4
- package/dist/react/index.js +0 -4
- package/dist/react/stream.cjs +0 -18
- package/dist/react/stream.cjs.map +0 -1
- package/dist/react/stream.custom.cjs +0 -129
- package/dist/react/stream.custom.cjs.map +0 -1
- package/dist/react/stream.custom.d.cts +0 -39
- package/dist/react/stream.custom.d.cts.map +0 -1
- package/dist/react/stream.custom.d.ts +0 -39
- package/dist/react/stream.custom.d.ts.map +0 -1
- package/dist/react/stream.custom.js +0 -127
- package/dist/react/stream.custom.js.map +0 -1
- package/dist/react/stream.d.cts +0 -73
- package/dist/react/stream.d.cts.map +0 -1
- package/dist/react/stream.d.ts +0 -73
- package/dist/react/stream.d.ts.map +0 -1
- package/dist/react/stream.js +0 -17
- package/dist/react/stream.js.map +0 -1
- package/dist/react/stream.lgp.cjs +0 -446
- package/dist/react/stream.lgp.cjs.map +0 -1
- package/dist/react/stream.lgp.js +0 -445
- package/dist/react/stream.lgp.js.map +0 -1
- package/dist/react/thread.cjs +0 -22
- package/dist/react/thread.cjs.map +0 -1
- package/dist/react/thread.js +0 -21
- package/dist/react/thread.js.map +0 -1
- package/dist/react/types.d.cts +0 -363
- package/dist/react/types.d.cts.map +0 -1
- package/dist/react/types.d.ts +0 -363
- package/dist/react/types.d.ts.map +0 -1
- package/dist/react-ui/client.cjs +0 -137
- package/dist/react-ui/client.cjs.map +0 -1
- package/dist/react-ui/client.d.cts +0 -90
- package/dist/react-ui/client.d.cts.map +0 -1
- package/dist/react-ui/client.d.ts +0 -90
- package/dist/react-ui/client.d.ts.map +0 -1
- package/dist/react-ui/client.js +0 -134
- package/dist/react-ui/client.js.map +0 -1
- package/dist/react-ui/index.cjs +0 -14
- package/dist/react-ui/index.cjs.map +0 -1
- package/dist/react-ui/index.d.cts +0 -3
- package/dist/react-ui/index.d.ts +0 -3
- package/dist/react-ui/index.js +0 -9
- package/dist/react-ui/index.js.map +0 -1
- package/dist/react-ui/server/index.cjs +0 -5
- package/dist/react-ui/server/index.d.cts +0 -3
- package/dist/react-ui/server/index.d.ts +0 -3
- package/dist/react-ui/server/index.js +0 -4
- package/dist/react-ui/server/server.cjs +0 -57
- package/dist/react-ui/server/server.cjs.map +0 -1
- package/dist/react-ui/server/server.d.cts +0 -55
- package/dist/react-ui/server/server.d.cts.map +0 -1
- package/dist/react-ui/server/server.d.ts +0 -55
- package/dist/react-ui/server/server.d.ts.map +0 -1
- package/dist/react-ui/server/server.js +0 -56
- package/dist/react-ui/server/server.js.map +0 -1
- package/dist/react-ui/types.cjs +0 -38
- package/dist/react-ui/types.cjs.map +0 -1
- package/dist/react-ui/types.d.cts +0 -25
- package/dist/react-ui/types.d.cts.map +0 -1
- package/dist/react-ui/types.d.ts +0 -25
- package/dist/react-ui/types.d.ts.map +0 -1
- package/dist/react-ui/types.js +0 -35
- package/dist/react-ui/types.js.map +0 -1
- package/dist/schema.d.cts +0 -284
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -284
- package/dist/schema.d.ts.map +0 -1
- package/dist/singletons/fetch.cjs +0 -24
- package/dist/singletons/fetch.cjs.map +0 -1
- package/dist/singletons/fetch.d.cts +0 -14
- package/dist/singletons/fetch.d.cts.map +0 -1
- package/dist/singletons/fetch.d.ts +0 -14
- package/dist/singletons/fetch.d.ts.map +0 -1
- package/dist/singletons/fetch.js +0 -22
- package/dist/singletons/fetch.js.map +0 -1
- package/dist/types.d.cts +0 -187
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -187
- package/dist/types.d.ts.map +0 -1
- package/dist/types.messages.d.cts +0 -91
- package/dist/types.messages.d.cts.map +0 -1
- package/dist/types.messages.d.ts +0 -91
- package/dist/types.messages.d.ts.map +0 -1
- package/dist/types.stream.d.cts +0 -235
- package/dist/types.stream.d.cts.map +0 -1
- package/dist/types.stream.d.ts +0 -235
- package/dist/types.stream.d.ts.map +0 -1
- package/dist/ui/branching.cjs +0 -153
- package/dist/ui/branching.cjs.map +0 -1
- package/dist/ui/branching.d.cts +0 -22
- package/dist/ui/branching.d.cts.map +0 -1
- package/dist/ui/branching.d.ts +0 -22
- package/dist/ui/branching.d.ts.map +0 -1
- package/dist/ui/branching.js +0 -152
- package/dist/ui/branching.js.map +0 -1
- package/dist/ui/errors.cjs +0 -15
- package/dist/ui/errors.cjs.map +0 -1
- package/dist/ui/errors.js +0 -14
- package/dist/ui/errors.js.map +0 -1
- package/dist/ui/manager.cjs +0 -182
- package/dist/ui/manager.cjs.map +0 -1
- package/dist/ui/manager.js +0 -182
- package/dist/ui/manager.js.map +0 -1
- package/dist/ui/messages.cjs +0 -70
- package/dist/ui/messages.cjs.map +0 -1
- package/dist/ui/messages.js +0 -68
- package/dist/ui/messages.js.map +0 -1
- package/dist/ui/utils.cjs +0 -14
- package/dist/ui/utils.cjs.map +0 -1
- package/dist/ui/utils.js +0 -12
- package/dist/ui/utils.js.map +0 -1
- package/dist/utils/async_caller.cjs +0 -111
- package/dist/utils/async_caller.cjs.map +0 -1
- package/dist/utils/async_caller.d.cts +0 -53
- package/dist/utils/async_caller.d.cts.map +0 -1
- package/dist/utils/async_caller.d.ts +0 -53
- package/dist/utils/async_caller.d.ts.map +0 -1
- package/dist/utils/async_caller.js +0 -110
- package/dist/utils/async_caller.js.map +0 -1
- package/dist/utils/env.cjs +0 -13
- package/dist/utils/env.cjs.map +0 -1
- package/dist/utils/env.js +0 -12
- package/dist/utils/env.js.map +0 -1
- package/dist/utils/signals.cjs +0 -20
- package/dist/utils/signals.cjs.map +0 -1
- package/dist/utils/signals.js +0 -19
- package/dist/utils/signals.js.map +0 -1
- package/dist/utils/sse.cjs +0 -124
- package/dist/utils/sse.cjs.map +0 -1
- package/dist/utils/sse.js +0 -122
- package/dist/utils/sse.js.map +0 -1
- package/dist/utils/stream.cjs +0 -91
- package/dist/utils/stream.cjs.map +0 -1
- package/dist/utils/stream.js +0 -90
- package/dist/utils/stream.js.map +0 -1
package/dist/ui/messages.cjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
|
|
3
|
-
|
|
4
|
-
//#region src/ui/messages.ts
|
|
5
|
-
function tryConvertToChunk(message) {
|
|
6
|
-
try {
|
|
7
|
-
if ((0, __langchain_core_messages.isBaseMessageChunk)(message)) return message;
|
|
8
|
-
return (0, __langchain_core_messages.convertToChunk)(message);
|
|
9
|
-
} catch {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function tryCoerceMessageLikeToMessage(message) {
|
|
14
|
-
if (message.type === "human" || message.type === "user") return new __langchain_core_messages.HumanMessageChunk(message);
|
|
15
|
-
if (message.type === "ai" || message.type === "assistant") return new __langchain_core_messages.AIMessageChunk(message);
|
|
16
|
-
if (message.type === "system") return new __langchain_core_messages.SystemMessageChunk(message);
|
|
17
|
-
if (message.type === "tool" && "tool_call_id" in message) return new __langchain_core_messages.ToolMessageChunk({
|
|
18
|
-
...message,
|
|
19
|
-
tool_call_id: message.tool_call_id
|
|
20
|
-
});
|
|
21
|
-
if (message.type === "remove" && message.id != null) return new __langchain_core_messages.RemoveMessage({
|
|
22
|
-
...message,
|
|
23
|
-
id: message.id
|
|
24
|
-
});
|
|
25
|
-
return (0, __langchain_core_messages.coerceMessageLikeToMessage)(message);
|
|
26
|
-
}
|
|
27
|
-
var MessageTupleManager = class {
|
|
28
|
-
chunks = {};
|
|
29
|
-
constructor() {
|
|
30
|
-
this.chunks = {};
|
|
31
|
-
}
|
|
32
|
-
add(serialized, metadata) {
|
|
33
|
-
if (serialized.type.endsWith("MessageChunk")) serialized.type = serialized.type.slice(0, -12).toLowerCase();
|
|
34
|
-
const message = tryCoerceMessageLikeToMessage(serialized);
|
|
35
|
-
const chunk = tryConvertToChunk(message);
|
|
36
|
-
const { id } = chunk ?? message;
|
|
37
|
-
if (!id) {
|
|
38
|
-
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
this.chunks[id] ??= {};
|
|
42
|
-
this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;
|
|
43
|
-
if (chunk) {
|
|
44
|
-
const prev = this.chunks[id].chunk;
|
|
45
|
-
this.chunks[id].chunk = ((0, __langchain_core_messages.isBaseMessageChunk)(prev) ? prev : null)?.concat(chunk) ?? chunk;
|
|
46
|
-
} else this.chunks[id].chunk = message;
|
|
47
|
-
return id;
|
|
48
|
-
}
|
|
49
|
-
clear() {
|
|
50
|
-
this.chunks = {};
|
|
51
|
-
}
|
|
52
|
-
get(id, defaultIndex) {
|
|
53
|
-
if (id == null) return null;
|
|
54
|
-
if (this.chunks[id] == null) return null;
|
|
55
|
-
if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;
|
|
56
|
-
return this.chunks[id];
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const toMessageDict = (chunk) => {
|
|
60
|
-
const { type, data } = chunk.toDict();
|
|
61
|
-
return {
|
|
62
|
-
...data,
|
|
63
|
-
type
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
exports.MessageTupleManager = MessageTupleManager;
|
|
69
|
-
exports.toMessageDict = toMessageDict;
|
|
70
|
-
//# sourceMappingURL=messages.cjs.map
|
package/dist/ui/messages.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.cjs","names":["HumanMessageChunk","AIMessageChunk","SystemMessageChunk","ToolMessageChunk","RemoveMessage"],"sources":["../../src/ui/messages.ts"],"sourcesContent":["import {\n type BaseMessage,\n BaseMessageChunk,\n RemoveMessage,\n convertToChunk,\n coerceMessageLikeToMessage,\n isBaseMessageChunk,\n HumanMessageChunk,\n SystemMessageChunk,\n AIMessageChunk,\n ToolMessageChunk,\n} from \"@langchain/core/messages\";\n\nimport type { Message } from \"../types.messages.js\";\n\nexport function tryConvertToChunk(\n message: BaseMessage | BaseMessageChunk\n): BaseMessageChunk | null {\n try {\n if (isBaseMessageChunk(message)) return message;\n return convertToChunk(message);\n } catch {\n return null;\n }\n}\n\nexport function tryCoerceMessageLikeToMessage(\n message: Omit<Message, \"type\"> & { type: string }\n): BaseMessage | BaseMessageChunk {\n if (message.type === \"human\" || message.type === \"user\") {\n return new HumanMessageChunk(message);\n }\n\n if (message.type === \"ai\" || message.type === \"assistant\") {\n return new AIMessageChunk(message);\n }\n\n if (message.type === \"system\") {\n return new SystemMessageChunk(message);\n }\n\n if (message.type === \"tool\" && \"tool_call_id\" in message) {\n return new ToolMessageChunk({\n ...message,\n tool_call_id: message.tool_call_id as string,\n });\n }\n\n if (message.type === \"remove\" && message.id != null) {\n return new RemoveMessage({ ...message, id: message.id });\n }\n\n return coerceMessageLikeToMessage(message);\n}\n\nexport class MessageTupleManager {\n chunks: Record<\n string,\n {\n chunk?: BaseMessageChunk | BaseMessage;\n metadata?: Record<string, unknown>;\n index?: number;\n }\n > = {};\n\n constructor() {\n this.chunks = {};\n }\n\n add(\n serialized: Message,\n metadata: Record<string, unknown> | undefined\n ): string | null {\n // TODO: this is sometimes sent from the API\n // figure out how to prevent this or move this to LC.js\n if (serialized.type.endsWith(\"MessageChunk\")) {\n // eslint-disable-next-line no-param-reassign\n serialized.type = serialized.type\n .slice(0, -\"MessageChunk\".length)\n .toLowerCase() as Message[\"type\"];\n }\n\n const message = tryCoerceMessageLikeToMessage(serialized);\n const chunk = tryConvertToChunk(message);\n\n const { id } = chunk ?? message;\n if (!id) {\n console.warn(\n \"No message ID found for chunk, ignoring in state\",\n serialized\n );\n return null;\n }\n\n this.chunks[id] ??= {};\n this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;\n if (chunk) {\n const prev = this.chunks[id].chunk;\n this.chunks[id].chunk =\n (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;\n } else {\n this.chunks[id].chunk = message;\n }\n\n return id;\n }\n\n clear() {\n this.chunks = {};\n }\n\n get(id: string | null | undefined, defaultIndex?: number) {\n if (id == null) return null;\n if (this.chunks[id] == null) return null;\n if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;\n return this.chunks[id];\n }\n}\n\nexport const toMessageDict = (chunk: BaseMessage): Message => {\n const { type, data } = chunk.toDict();\n return { ...data, type } as Message;\n};\n"],"mappings":";;;;AAeA,SAAgB,kBACd,SACyB;AACzB,KAAI;AACF,wDAAuB,SAAU,QAAO;AACxC,uDAAsB;SAChB;AACN,SAAO;;;AAIX,SAAgB,8BACd,SACgC;AAChC,KAAI,QAAQ,SAAS,WAAW,QAAQ,SAAS,OAC/C,QAAO,IAAIA,4CAAkB;AAG/B,KAAI,QAAQ,SAAS,QAAQ,QAAQ,SAAS,YAC5C,QAAO,IAAIC,yCAAe;AAG5B,KAAI,QAAQ,SAAS,SACnB,QAAO,IAAIC,6CAAmB;AAGhC,KAAI,QAAQ,SAAS,UAAU,kBAAkB,QAC/C,QAAO,IAAIC,2CAAiB;EAC1B,GAAG;EACH,cAAc,QAAQ;;AAI1B,KAAI,QAAQ,SAAS,YAAY,QAAQ,MAAM,KAC7C,QAAO,IAAIC,wCAAc;EAAE,GAAG;EAAS,IAAI,QAAQ;;AAGrD,kEAAkC;;AAGpC,IAAa,sBAAb,MAAiC;CAC/B,SAOI;CAEJ,cAAc;AACZ,OAAK,SAAS;;CAGhB,IACE,YACA,UACe;AAGf,MAAI,WAAW,KAAK,SAAS,gBAE3B,YAAW,OAAO,WAAW,KAC1B,MAAM,GAAG,KACT;EAGL,MAAM,UAAU,8BAA8B;EAC9C,MAAM,QAAQ,kBAAkB;EAEhC,MAAM,EAAE,OAAO,SAAS;AACxB,MAAI,CAAC,IAAI;AACP,WAAQ,KACN,oDACA;AAEF,UAAO;;AAGT,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,IAAI,WAAW,YAAY,KAAK,OAAO,IAAI;AACvD,MAAI,OAAO;GACT,MAAM,OAAO,KAAK,OAAO,IAAI;AAC7B,QAAK,OAAO,IAAI,2DACM,QAAQ,OAAO,OAAO,OAAO,UAAU;QAE7D,MAAK,OAAO,IAAI,QAAQ;AAG1B,SAAO;;CAGT,QAAQ;AACN,OAAK,SAAS;;CAGhB,IAAI,IAA+B,cAAuB;AACxD,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,KAAK,OAAO,OAAO,KAAM,QAAO;AACpC,MAAI,gBAAgB,KAAM,MAAK,OAAO,IAAI,UAAU;AACpD,SAAO,KAAK,OAAO;;;AAIvB,MAAa,iBAAiB,UAAgC;CAC5D,MAAM,EAAE,MAAM,SAAS,MAAM;AAC7B,QAAO;EAAE,GAAG;EAAM"}
|
package/dist/ui/messages.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { AIMessageChunk, HumanMessageChunk, RemoveMessage, SystemMessageChunk, ToolMessageChunk, coerceMessageLikeToMessage, convertToChunk, isBaseMessageChunk } from "@langchain/core/messages";
|
|
2
|
-
|
|
3
|
-
//#region src/ui/messages.ts
|
|
4
|
-
function tryConvertToChunk(message) {
|
|
5
|
-
try {
|
|
6
|
-
if (isBaseMessageChunk(message)) return message;
|
|
7
|
-
return convertToChunk(message);
|
|
8
|
-
} catch {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function tryCoerceMessageLikeToMessage(message) {
|
|
13
|
-
if (message.type === "human" || message.type === "user") return new HumanMessageChunk(message);
|
|
14
|
-
if (message.type === "ai" || message.type === "assistant") return new AIMessageChunk(message);
|
|
15
|
-
if (message.type === "system") return new SystemMessageChunk(message);
|
|
16
|
-
if (message.type === "tool" && "tool_call_id" in message) return new ToolMessageChunk({
|
|
17
|
-
...message,
|
|
18
|
-
tool_call_id: message.tool_call_id
|
|
19
|
-
});
|
|
20
|
-
if (message.type === "remove" && message.id != null) return new RemoveMessage({
|
|
21
|
-
...message,
|
|
22
|
-
id: message.id
|
|
23
|
-
});
|
|
24
|
-
return coerceMessageLikeToMessage(message);
|
|
25
|
-
}
|
|
26
|
-
var MessageTupleManager = class {
|
|
27
|
-
chunks = {};
|
|
28
|
-
constructor() {
|
|
29
|
-
this.chunks = {};
|
|
30
|
-
}
|
|
31
|
-
add(serialized, metadata) {
|
|
32
|
-
if (serialized.type.endsWith("MessageChunk")) serialized.type = serialized.type.slice(0, -12).toLowerCase();
|
|
33
|
-
const message = tryCoerceMessageLikeToMessage(serialized);
|
|
34
|
-
const chunk = tryConvertToChunk(message);
|
|
35
|
-
const { id } = chunk ?? message;
|
|
36
|
-
if (!id) {
|
|
37
|
-
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
this.chunks[id] ??= {};
|
|
41
|
-
this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;
|
|
42
|
-
if (chunk) {
|
|
43
|
-
const prev = this.chunks[id].chunk;
|
|
44
|
-
this.chunks[id].chunk = (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;
|
|
45
|
-
} else this.chunks[id].chunk = message;
|
|
46
|
-
return id;
|
|
47
|
-
}
|
|
48
|
-
clear() {
|
|
49
|
-
this.chunks = {};
|
|
50
|
-
}
|
|
51
|
-
get(id, defaultIndex) {
|
|
52
|
-
if (id == null) return null;
|
|
53
|
-
if (this.chunks[id] == null) return null;
|
|
54
|
-
if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;
|
|
55
|
-
return this.chunks[id];
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const toMessageDict = (chunk) => {
|
|
59
|
-
const { type, data } = chunk.toDict();
|
|
60
|
-
return {
|
|
61
|
-
...data,
|
|
62
|
-
type
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { MessageTupleManager, toMessageDict };
|
|
68
|
-
//# sourceMappingURL=messages.js.map
|
package/dist/ui/messages.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","names":[],"sources":["../../src/ui/messages.ts"],"sourcesContent":["import {\n type BaseMessage,\n BaseMessageChunk,\n RemoveMessage,\n convertToChunk,\n coerceMessageLikeToMessage,\n isBaseMessageChunk,\n HumanMessageChunk,\n SystemMessageChunk,\n AIMessageChunk,\n ToolMessageChunk,\n} from \"@langchain/core/messages\";\n\nimport type { Message } from \"../types.messages.js\";\n\nexport function tryConvertToChunk(\n message: BaseMessage | BaseMessageChunk\n): BaseMessageChunk | null {\n try {\n if (isBaseMessageChunk(message)) return message;\n return convertToChunk(message);\n } catch {\n return null;\n }\n}\n\nexport function tryCoerceMessageLikeToMessage(\n message: Omit<Message, \"type\"> & { type: string }\n): BaseMessage | BaseMessageChunk {\n if (message.type === \"human\" || message.type === \"user\") {\n return new HumanMessageChunk(message);\n }\n\n if (message.type === \"ai\" || message.type === \"assistant\") {\n return new AIMessageChunk(message);\n }\n\n if (message.type === \"system\") {\n return new SystemMessageChunk(message);\n }\n\n if (message.type === \"tool\" && \"tool_call_id\" in message) {\n return new ToolMessageChunk({\n ...message,\n tool_call_id: message.tool_call_id as string,\n });\n }\n\n if (message.type === \"remove\" && message.id != null) {\n return new RemoveMessage({ ...message, id: message.id });\n }\n\n return coerceMessageLikeToMessage(message);\n}\n\nexport class MessageTupleManager {\n chunks: Record<\n string,\n {\n chunk?: BaseMessageChunk | BaseMessage;\n metadata?: Record<string, unknown>;\n index?: number;\n }\n > = {};\n\n constructor() {\n this.chunks = {};\n }\n\n add(\n serialized: Message,\n metadata: Record<string, unknown> | undefined\n ): string | null {\n // TODO: this is sometimes sent from the API\n // figure out how to prevent this or move this to LC.js\n if (serialized.type.endsWith(\"MessageChunk\")) {\n // eslint-disable-next-line no-param-reassign\n serialized.type = serialized.type\n .slice(0, -\"MessageChunk\".length)\n .toLowerCase() as Message[\"type\"];\n }\n\n const message = tryCoerceMessageLikeToMessage(serialized);\n const chunk = tryConvertToChunk(message);\n\n const { id } = chunk ?? message;\n if (!id) {\n console.warn(\n \"No message ID found for chunk, ignoring in state\",\n serialized\n );\n return null;\n }\n\n this.chunks[id] ??= {};\n this.chunks[id].metadata = metadata ?? this.chunks[id].metadata;\n if (chunk) {\n const prev = this.chunks[id].chunk;\n this.chunks[id].chunk =\n (isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;\n } else {\n this.chunks[id].chunk = message;\n }\n\n return id;\n }\n\n clear() {\n this.chunks = {};\n }\n\n get(id: string | null | undefined, defaultIndex?: number) {\n if (id == null) return null;\n if (this.chunks[id] == null) return null;\n if (defaultIndex != null) this.chunks[id].index ??= defaultIndex;\n return this.chunks[id];\n }\n}\n\nexport const toMessageDict = (chunk: BaseMessage): Message => {\n const { type, data } = chunk.toDict();\n return { ...data, type } as Message;\n};\n"],"mappings":";;;AAeA,SAAgB,kBACd,SACyB;AACzB,KAAI;AACF,MAAI,mBAAmB,SAAU,QAAO;AACxC,SAAO,eAAe;SAChB;AACN,SAAO;;;AAIX,SAAgB,8BACd,SACgC;AAChC,KAAI,QAAQ,SAAS,WAAW,QAAQ,SAAS,OAC/C,QAAO,IAAI,kBAAkB;AAG/B,KAAI,QAAQ,SAAS,QAAQ,QAAQ,SAAS,YAC5C,QAAO,IAAI,eAAe;AAG5B,KAAI,QAAQ,SAAS,SACnB,QAAO,IAAI,mBAAmB;AAGhC,KAAI,QAAQ,SAAS,UAAU,kBAAkB,QAC/C,QAAO,IAAI,iBAAiB;EAC1B,GAAG;EACH,cAAc,QAAQ;;AAI1B,KAAI,QAAQ,SAAS,YAAY,QAAQ,MAAM,KAC7C,QAAO,IAAI,cAAc;EAAE,GAAG;EAAS,IAAI,QAAQ;;AAGrD,QAAO,2BAA2B;;AAGpC,IAAa,sBAAb,MAAiC;CAC/B,SAOI;CAEJ,cAAc;AACZ,OAAK,SAAS;;CAGhB,IACE,YACA,UACe;AAGf,MAAI,WAAW,KAAK,SAAS,gBAE3B,YAAW,OAAO,WAAW,KAC1B,MAAM,GAAG,KACT;EAGL,MAAM,UAAU,8BAA8B;EAC9C,MAAM,QAAQ,kBAAkB;EAEhC,MAAM,EAAE,OAAO,SAAS;AACxB,MAAI,CAAC,IAAI;AACP,WAAQ,KACN,oDACA;AAEF,UAAO;;AAGT,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,IAAI,WAAW,YAAY,KAAK,OAAO,IAAI;AACvD,MAAI,OAAO;GACT,MAAM,OAAO,KAAK,OAAO,IAAI;AAC7B,QAAK,OAAO,IAAI,SACb,mBAAmB,QAAQ,OAAO,OAAO,OAAO,UAAU;QAE7D,MAAK,OAAO,IAAI,QAAQ;AAG1B,SAAO;;CAGT,QAAQ;AACN,OAAK,SAAS;;CAGhB,IAAI,IAA+B,cAAuB;AACxD,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,KAAK,OAAO,OAAO,KAAM,QAAO;AACpC,MAAI,gBAAgB,KAAM,MAAK,OAAO,IAAI,UAAU;AACpD,SAAO,KAAK,OAAO;;;AAIvB,MAAa,iBAAiB,UAAgC;CAC5D,MAAM,EAAE,MAAM,SAAS,MAAM;AAC7B,QAAO;EAAE,GAAG;EAAM"}
|
package/dist/ui/utils.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/ui/utils.ts
|
|
3
|
-
function unique(array) {
|
|
4
|
-
return [...new Set(array)];
|
|
5
|
-
}
|
|
6
|
-
function findLast(array, predicate) {
|
|
7
|
-
for (let i = array.length - 1; i >= 0; i -= 1) if (predicate(array[i])) return array[i];
|
|
8
|
-
return void 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
exports.findLast = findLast;
|
|
13
|
-
exports.unique = unique;
|
|
14
|
-
//# sourceMappingURL=utils.cjs.map
|
package/dist/ui/utils.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";;AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;AAGrB,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,IAAK,QAAO,MAAM;AAExC,QAAO"}
|
package/dist/ui/utils.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/ui/utils.ts
|
|
2
|
-
function unique(array) {
|
|
3
|
-
return [...new Set(array)];
|
|
4
|
-
}
|
|
5
|
-
function findLast(array, predicate) {
|
|
6
|
-
for (let i = array.length - 1; i >= 0; i -= 1) if (predicate(array[i])) return array[i];
|
|
7
|
-
return void 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
export { findLast, unique };
|
|
12
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/ui/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;AAGrB,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,IAAK,QAAO,MAAM;AAExC,QAAO"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_fetch = require('../singletons/fetch.cjs');
|
|
3
|
-
const p_retry = require_rolldown_runtime.__toESM(require("p-retry"));
|
|
4
|
-
const p_queue = require_rolldown_runtime.__toESM(require("p-queue"));
|
|
5
|
-
|
|
6
|
-
//#region src/utils/async_caller.ts
|
|
7
|
-
const STATUS_NO_RETRY = [
|
|
8
|
-
400,
|
|
9
|
-
401,
|
|
10
|
-
402,
|
|
11
|
-
403,
|
|
12
|
-
404,
|
|
13
|
-
405,
|
|
14
|
-
406,
|
|
15
|
-
407,
|
|
16
|
-
408,
|
|
17
|
-
409,
|
|
18
|
-
422
|
|
19
|
-
];
|
|
20
|
-
/**
|
|
21
|
-
* Do not rely on globalThis.Response, rather just
|
|
22
|
-
* do duck typing
|
|
23
|
-
*/
|
|
24
|
-
function isResponse(x) {
|
|
25
|
-
if (x == null || typeof x !== "object") return false;
|
|
26
|
-
return "status" in x && "statusText" in x && "text" in x;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Utility error to properly handle failed requests
|
|
30
|
-
*/
|
|
31
|
-
var HTTPError = class HTTPError extends Error {
|
|
32
|
-
status;
|
|
33
|
-
text;
|
|
34
|
-
response;
|
|
35
|
-
constructor(status, message, response) {
|
|
36
|
-
super(`HTTP ${status}: ${message}`);
|
|
37
|
-
this.status = status;
|
|
38
|
-
this.text = message;
|
|
39
|
-
this.response = response;
|
|
40
|
-
}
|
|
41
|
-
static async fromResponse(response, options) {
|
|
42
|
-
try {
|
|
43
|
-
return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : void 0);
|
|
44
|
-
} catch {
|
|
45
|
-
return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : void 0);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
51
|
-
*
|
|
52
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
53
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
54
|
-
*
|
|
55
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
56
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
57
|
-
*
|
|
58
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 5. This
|
|
59
|
-
* means that by default, each call will be retried up to 5 times, with an
|
|
60
|
-
* exponential backoff between each attempt.
|
|
61
|
-
*/
|
|
62
|
-
var AsyncCaller = class {
|
|
63
|
-
maxConcurrency;
|
|
64
|
-
maxRetries;
|
|
65
|
-
queue;
|
|
66
|
-
onFailedResponseHook;
|
|
67
|
-
customFetch;
|
|
68
|
-
constructor(params) {
|
|
69
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
70
|
-
this.maxRetries = params.maxRetries ?? 4;
|
|
71
|
-
if ("default" in p_queue.default) this.queue = new p_queue.default.default({ concurrency: this.maxConcurrency });
|
|
72
|
-
else this.queue = new p_queue.default({ concurrency: this.maxConcurrency });
|
|
73
|
-
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
74
|
-
this.customFetch = params.fetch;
|
|
75
|
-
}
|
|
76
|
-
call(callable, ...args) {
|
|
77
|
-
const { onFailedResponseHook } = this;
|
|
78
|
-
return this.queue.add(() => (0, p_retry.default)(() => callable(...args).catch(async (error) => {
|
|
79
|
-
if (error instanceof Error) throw error;
|
|
80
|
-
else if (isResponse(error)) throw await HTTPError.fromResponse(error, { includeResponse: !!onFailedResponseHook });
|
|
81
|
-
else throw new Error(error);
|
|
82
|
-
}), {
|
|
83
|
-
async onFailedAttempt(error) {
|
|
84
|
-
if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.message.startsWith("AbortError")) throw error;
|
|
85
|
-
if (error?.code === "ECONNABORTED") throw error;
|
|
86
|
-
if (error instanceof HTTPError) {
|
|
87
|
-
if (STATUS_NO_RETRY.includes(error.status)) throw error;
|
|
88
|
-
if (onFailedResponseHook && error.response) await onFailedResponseHook(error.response);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
retries: this.maxRetries,
|
|
92
|
-
randomize: true
|
|
93
|
-
}), { throwOnTimeout: true });
|
|
94
|
-
}
|
|
95
|
-
callWithOptions(options, callable, ...args) {
|
|
96
|
-
if (options.signal) return Promise.race([this.call(callable, ...args), new Promise((_, reject) => {
|
|
97
|
-
options.signal?.addEventListener("abort", () => {
|
|
98
|
-
reject(/* @__PURE__ */ new Error("AbortError"));
|
|
99
|
-
});
|
|
100
|
-
})]);
|
|
101
|
-
return this.call(callable, ...args);
|
|
102
|
-
}
|
|
103
|
-
fetch(...args) {
|
|
104
|
-
const fetchFn = this.customFetch ?? require_fetch._getFetchImplementation();
|
|
105
|
-
return this.call(() => fetchFn(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
exports.AsyncCaller = AsyncCaller;
|
|
111
|
-
//# sourceMappingURL=async_caller.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.cjs","names":["PQueueMod","_getFetchImplementation"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n 409, // Conflict\n 422, // Unprocessable Entity\n];\n\ntype ResponseCallback = (response?: Response) => Promise<boolean>;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n\n onFailedResponseHook?: ResponseCallback;\n\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Do not rely on globalThis.Response, rather just\n * do duck typing\n */\nfunction isResponse(x: unknown): x is Response {\n if (x == null || typeof x !== \"object\") return false;\n return \"status\" in x && \"statusText\" in x && \"text\" in x;\n}\n\n/**\n * Utility error to properly handle failed requests\n */\nclass HTTPError extends Error {\n status: number;\n\n text: string;\n\n response?: Response;\n\n constructor(status: number, message: string, response?: Response) {\n super(`HTTP ${status}: ${message}`);\n this.status = status;\n this.text = message;\n this.response = response;\n }\n\n static async fromResponse(\n response: Response,\n options?: { includeResponse?: boolean }\n ): Promise<HTTPError> {\n try {\n return new HTTPError(\n response.status,\n await response.text(),\n options?.includeResponse ? response : undefined\n );\n } catch {\n return new HTTPError(\n response.status,\n response.statusText,\n options?.includeResponse ? response : undefined\n );\n }\n }\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n private onFailedResponseHook?: ResponseCallback;\n\n private customFetch?: typeof fetch;\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 4;\n\n if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod.default as any)({\n concurrency: this.maxConcurrency,\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n this.customFetch = params.fetch;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n const { onFailedResponseHook } = this;\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...(args as Parameters<T>)).catch(async (error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else if (isResponse(error)) {\n throw await HTTPError.fromResponse(error, {\n includeResponse: !!onFailedResponseHook,\n });\n } else {\n throw new Error(error);\n }\n }),\n {\n async onFailedAttempt(error) {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"TimeoutError\") ||\n error.message.startsWith(\"AbortError\")\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof HTTPError) {\n if (STATUS_NO_RETRY.includes(error.status)) {\n throw error;\n }\n if (onFailedResponseHook && error.response) {\n await onFailedResponseHook(error.response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n const fetchFn =\n this.customFetch ?? (_getFetchImplementation() as typeof fetch);\n return this.call(() =>\n fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;AAIA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAmCF,SAAS,WAAW,GAA2B;AAC7C,KAAI,KAAK,QAAQ,OAAO,MAAM,SAAU,QAAO;AAC/C,QAAO,YAAY,KAAK,gBAAgB,KAAK,UAAU;;;;;AAMzD,IAAM,YAAN,MAAM,kBAAkB,MAAM;CAC5B;CAEA;CAEA;CAEA,YAAY,QAAgB,SAAiB,UAAqB;AAChE,QAAM,QAAQ,OAAO,IAAI;AACzB,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,WAAW;;CAGlB,aAAa,aACX,UACA,SACoB;AACpB,MAAI;AACF,UAAO,IAAI,UACT,SAAS,QACT,MAAM,SAAS,QACf,SAAS,kBAAkB,WAAW;UAElC;AACN,UAAO,IAAI,UACT,SAAS,QACT,SAAS,YACT,SAAS,kBAAkB,WAAW;;;;;;;;;;;;;;;;;AAmB9C,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAQ;CAER,AAAQ;CAER,AAAQ;CAER,YAAY,QAA2B;AACrC,OAAK,iBAAiB,OAAO,kBAAkB;AAC/C,OAAK,aAAa,OAAO,cAAc;AAEvC,MAAI,aAAaA,gBAEf,MAAK,QAAQ,IAAKA,gBAAU,QAAgB,EAC1C,aAAa,KAAK;MAIpB,MAAK,QAAQ,IAAKA,gBAAkB,EAAE,aAAa,KAAK;AAE1D,OAAK,uBAAuB,QAAQ;AACpC,OAAK,cAAc,OAAO;;CAI5B,KACE,UACA,GAAG,MAC8B;EACjC,MAAM,EAAE,yBAAyB;AACjC,SAAO,KAAK,MAAM,qCAIV,SAAS,GAAI,MAAwB,MAAM,OAAO,UAAU;AAE1D,OAAI,iBAAiB,MACnB,OAAM;YACG,WAAW,OACpB,OAAM,MAAM,UAAU,aAAa,OAAO,EACxC,iBAAiB,CAAC,CAAC;OAGrB,OAAM,IAAI,MAAM;MAGtB;GACE,MAAM,gBAAgB,OAAO;AAC3B,QACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,mBACzB,MAAM,QAAQ,WAAW,cAEzB,OAAM;AAGR,QAAK,OAAe,SAAS,eAC3B,OAAM;AAIR,QAAI,iBAAiB,WAAW;AAC9B,SAAI,gBAAgB,SAAS,MAAM,QACjC,OAAM;AAER,SAAI,wBAAwB,MAAM,SAChC,OAAM,qBAAqB,MAAM;;;GAMvC,SAAS,KAAK;GACd,WAAW;MAGjB,EAAE,gBAAgB;;CAKtB,gBACE,SACA,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,OACV,QAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,OAC7B,IAAI,SAAgB,GAAG,WAAW;AAChC,WAAQ,QAAQ,iBAAiB,eAAe;AAC9C,2BAAO,IAAI,MAAM;;;AAKzB,SAAO,KAAK,KAAW,UAAU,GAAG;;CAGtC,MAAM,GAAG,MAA0D;EACjE,MAAM,UACJ,KAAK,eAAgBC;AACvB,SAAO,KAAK,WACV,QAAQ,GAAG,MAAM,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//#region src/utils/async_caller.d.ts
|
|
2
|
-
type ResponseCallback = (response?: Response) => Promise<boolean>;
|
|
3
|
-
interface AsyncCallerParams {
|
|
4
|
-
/**
|
|
5
|
-
* The maximum number of concurrent calls that can be made.
|
|
6
|
-
* Defaults to `Infinity`, which means no limit.
|
|
7
|
-
*/
|
|
8
|
-
maxConcurrency?: number;
|
|
9
|
-
/**
|
|
10
|
-
* The maximum number of retries that can be made for a single call,
|
|
11
|
-
* with an exponential backoff between each attempt. Defaults to 6.
|
|
12
|
-
*/
|
|
13
|
-
maxRetries?: number;
|
|
14
|
-
onFailedResponseHook?: ResponseCallback;
|
|
15
|
-
/**
|
|
16
|
-
* Specify a custom fetch implementation.
|
|
17
|
-
*
|
|
18
|
-
* By default we expect the `fetch` is available in the global scope.
|
|
19
|
-
*/
|
|
20
|
-
fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
21
|
-
}
|
|
22
|
-
interface AsyncCallerCallOptions {
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
27
|
-
*
|
|
28
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
29
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
30
|
-
*
|
|
31
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
32
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
33
|
-
*
|
|
34
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 5. This
|
|
35
|
-
* means that by default, each call will be retried up to 5 times, with an
|
|
36
|
-
* exponential backoff between each attempt.
|
|
37
|
-
*/
|
|
38
|
-
declare class AsyncCaller {
|
|
39
|
-
protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
|
|
40
|
-
protected maxRetries: AsyncCallerParams["maxRetries"];
|
|
41
|
-
private queue;
|
|
42
|
-
private onFailedResponseHook?;
|
|
43
|
-
private customFetch?;
|
|
44
|
-
constructor(params: AsyncCallerParams);
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
49
|
-
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
export { AsyncCaller, AsyncCallerParams };
|
|
53
|
-
//# sourceMappingURL=async_caller.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.d.cts","names":["ResponseCallback","Response","Promise","AsyncCallerParams","fetch","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","T","Parameters","ReturnType","Awaited"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["type ResponseCallback = (response?: Response) => Promise<boolean>;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n onFailedResponseHook?: ResponseCallback;\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n private queue;\n private onFailedResponseHook?;\n private customFetch?;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\nexport {};\n"],"mappings":";KAAKA,gBAAAA,eAA+BC,aAAaC;AAA5CF,UACYG,iBAAAA,CADI;EAAA;;;;EACJA,cAAAA,CAAAA,EAAAA,MAAiB;EAAA;;;;EAmBjBE,UAAAA,CAAAA,EAAAA,MAAAA;EAgBIE,oBAAW,CAAA,EAxBLP,gBAwBK;EAAA;;;;;OAQoBE,CAAAA,EAAAA,OA1BjCE,KA0BiCF,GAAAA,CAAAA,CAAAA,GAAAA,IAAAA,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,GAAAA,CAAAA,CAAAA,CAAAA;;AAA+CO,UAxBlFJ,sBAAAA,CAwBkFI;QAAXC,CAAAA,EAvB3EJ,WAuB2EI;;;;;;;;;;;;;;;AAGnDN,cAXhBG,WAAAA,CAWgBH;YAAlBM,cAAAA,EAVWP,iBAUXO,CAAAA,gBAAAA,CAAAA;YAA6CN,UAAAA,EATtCD,iBASsCC,CAAAA,YAAAA,CAAAA;UAAlBO,KAAAA;;;sBALtBR;;4CAEsBK,MAAMN,wBAAwBO,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;;uDAE1ED,MAAMN,uBAAuBG,kCAAkCI,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;iBAC5JC,kBAAkBN,SAASO,kBAAkBP"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//#region src/utils/async_caller.d.ts
|
|
2
|
-
type ResponseCallback = (response?: Response) => Promise<boolean>;
|
|
3
|
-
interface AsyncCallerParams {
|
|
4
|
-
/**
|
|
5
|
-
* The maximum number of concurrent calls that can be made.
|
|
6
|
-
* Defaults to `Infinity`, which means no limit.
|
|
7
|
-
*/
|
|
8
|
-
maxConcurrency?: number;
|
|
9
|
-
/**
|
|
10
|
-
* The maximum number of retries that can be made for a single call,
|
|
11
|
-
* with an exponential backoff between each attempt. Defaults to 6.
|
|
12
|
-
*/
|
|
13
|
-
maxRetries?: number;
|
|
14
|
-
onFailedResponseHook?: ResponseCallback;
|
|
15
|
-
/**
|
|
16
|
-
* Specify a custom fetch implementation.
|
|
17
|
-
*
|
|
18
|
-
* By default we expect the `fetch` is available in the global scope.
|
|
19
|
-
*/
|
|
20
|
-
fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
21
|
-
}
|
|
22
|
-
interface AsyncCallerCallOptions {
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
27
|
-
*
|
|
28
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
29
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
30
|
-
*
|
|
31
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
32
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
33
|
-
*
|
|
34
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 5. This
|
|
35
|
-
* means that by default, each call will be retried up to 5 times, with an
|
|
36
|
-
* exponential backoff between each attempt.
|
|
37
|
-
*/
|
|
38
|
-
declare class AsyncCaller {
|
|
39
|
-
protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
|
|
40
|
-
protected maxRetries: AsyncCallerParams["maxRetries"];
|
|
41
|
-
private queue;
|
|
42
|
-
private onFailedResponseHook?;
|
|
43
|
-
private customFetch?;
|
|
44
|
-
constructor(params: AsyncCallerParams);
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
49
|
-
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
|
-
export { AsyncCaller, AsyncCallerParams };
|
|
53
|
-
//# sourceMappingURL=async_caller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.d.ts","names":["ResponseCallback","Response","Promise","AsyncCallerParams","fetch","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","T","Parameters","ReturnType","Awaited"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["type ResponseCallback = (response?: Response) => Promise<boolean>;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n onFailedResponseHook?: ResponseCallback;\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n private queue;\n private onFailedResponseHook?;\n private customFetch?;\n constructor(params: AsyncCallerParams);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\nexport {};\n"],"mappings":";KAAKA,gBAAAA,eAA+BC,aAAaC;AAA5CF,UACYG,iBAAAA,CADI;EAAA;;;;EACJA,cAAAA,CAAAA,EAAAA,MAAiB;EAAA;;;;EAmBjBE,UAAAA,CAAAA,EAAAA,MAAAA;EAgBIE,oBAAW,CAAA,EAxBLP,gBAwBK;EAAA;;;;;OAQoBE,CAAAA,EAAAA,OA1BjCE,KA0BiCF,GAAAA,CAAAA,CAAAA,GAAAA,IAAAA,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,GAAAA,CAAAA,CAAAA,CAAAA;;AAA+CO,UAxBlFJ,sBAAAA,CAwBkFI;QAAXC,CAAAA,EAvB3EJ,WAuB2EI;;;;;;;;;;;;;;;AAGnDN,cAXhBG,WAAAA,CAWgBH;YAAlBM,cAAAA,EAVWP,iBAUXO,CAAAA,gBAAAA,CAAAA;YAA6CN,UAAAA,EATtCD,iBASsCC,CAAAA,YAAAA,CAAAA;UAAlBO,KAAAA;;;sBALtBR;;4CAEsBK,MAAMN,wBAAwBO,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;;uDAE1ED,MAAMN,uBAAuBG,kCAAkCI,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;iBAC5JC,kBAAkBN,SAASO,kBAAkBP"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { _getFetchImplementation } from "../singletons/fetch.js";
|
|
2
|
-
import pRetry from "p-retry";
|
|
3
|
-
import PQueueMod from "p-queue";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/async_caller.ts
|
|
6
|
-
const STATUS_NO_RETRY = [
|
|
7
|
-
400,
|
|
8
|
-
401,
|
|
9
|
-
402,
|
|
10
|
-
403,
|
|
11
|
-
404,
|
|
12
|
-
405,
|
|
13
|
-
406,
|
|
14
|
-
407,
|
|
15
|
-
408,
|
|
16
|
-
409,
|
|
17
|
-
422
|
|
18
|
-
];
|
|
19
|
-
/**
|
|
20
|
-
* Do not rely on globalThis.Response, rather just
|
|
21
|
-
* do duck typing
|
|
22
|
-
*/
|
|
23
|
-
function isResponse(x) {
|
|
24
|
-
if (x == null || typeof x !== "object") return false;
|
|
25
|
-
return "status" in x && "statusText" in x && "text" in x;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Utility error to properly handle failed requests
|
|
29
|
-
*/
|
|
30
|
-
var HTTPError = class HTTPError extends Error {
|
|
31
|
-
status;
|
|
32
|
-
text;
|
|
33
|
-
response;
|
|
34
|
-
constructor(status, message, response) {
|
|
35
|
-
super(`HTTP ${status}: ${message}`);
|
|
36
|
-
this.status = status;
|
|
37
|
-
this.text = message;
|
|
38
|
-
this.response = response;
|
|
39
|
-
}
|
|
40
|
-
static async fromResponse(response, options) {
|
|
41
|
-
try {
|
|
42
|
-
return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : void 0);
|
|
43
|
-
} catch {
|
|
44
|
-
return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : void 0);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
50
|
-
*
|
|
51
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
52
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
53
|
-
*
|
|
54
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
55
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
56
|
-
*
|
|
57
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 5. This
|
|
58
|
-
* means that by default, each call will be retried up to 5 times, with an
|
|
59
|
-
* exponential backoff between each attempt.
|
|
60
|
-
*/
|
|
61
|
-
var AsyncCaller = class {
|
|
62
|
-
maxConcurrency;
|
|
63
|
-
maxRetries;
|
|
64
|
-
queue;
|
|
65
|
-
onFailedResponseHook;
|
|
66
|
-
customFetch;
|
|
67
|
-
constructor(params) {
|
|
68
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
69
|
-
this.maxRetries = params.maxRetries ?? 4;
|
|
70
|
-
if ("default" in PQueueMod) this.queue = new PQueueMod.default({ concurrency: this.maxConcurrency });
|
|
71
|
-
else this.queue = new PQueueMod({ concurrency: this.maxConcurrency });
|
|
72
|
-
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
73
|
-
this.customFetch = params.fetch;
|
|
74
|
-
}
|
|
75
|
-
call(callable, ...args) {
|
|
76
|
-
const { onFailedResponseHook } = this;
|
|
77
|
-
return this.queue.add(() => pRetry(() => callable(...args).catch(async (error) => {
|
|
78
|
-
if (error instanceof Error) throw error;
|
|
79
|
-
else if (isResponse(error)) throw await HTTPError.fromResponse(error, { includeResponse: !!onFailedResponseHook });
|
|
80
|
-
else throw new Error(error);
|
|
81
|
-
}), {
|
|
82
|
-
async onFailedAttempt(error) {
|
|
83
|
-
if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.message.startsWith("AbortError")) throw error;
|
|
84
|
-
if (error?.code === "ECONNABORTED") throw error;
|
|
85
|
-
if (error instanceof HTTPError) {
|
|
86
|
-
if (STATUS_NO_RETRY.includes(error.status)) throw error;
|
|
87
|
-
if (onFailedResponseHook && error.response) await onFailedResponseHook(error.response);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
retries: this.maxRetries,
|
|
91
|
-
randomize: true
|
|
92
|
-
}), { throwOnTimeout: true });
|
|
93
|
-
}
|
|
94
|
-
callWithOptions(options, callable, ...args) {
|
|
95
|
-
if (options.signal) return Promise.race([this.call(callable, ...args), new Promise((_, reject) => {
|
|
96
|
-
options.signal?.addEventListener("abort", () => {
|
|
97
|
-
reject(/* @__PURE__ */ new Error("AbortError"));
|
|
98
|
-
});
|
|
99
|
-
})]);
|
|
100
|
-
return this.call(callable, ...args);
|
|
101
|
-
}
|
|
102
|
-
fetch(...args) {
|
|
103
|
-
const fetchFn = this.customFetch ?? _getFetchImplementation();
|
|
104
|
-
return this.call(() => fetchFn(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
export { AsyncCaller };
|
|
110
|
-
//# sourceMappingURL=async_caller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.js","names":[],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n 409, // Conflict\n 422, // Unprocessable Entity\n];\n\ntype ResponseCallback = (response?: Response) => Promise<boolean>;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n\n onFailedResponseHook?: ResponseCallback;\n\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Do not rely on globalThis.Response, rather just\n * do duck typing\n */\nfunction isResponse(x: unknown): x is Response {\n if (x == null || typeof x !== \"object\") return false;\n return \"status\" in x && \"statusText\" in x && \"text\" in x;\n}\n\n/**\n * Utility error to properly handle failed requests\n */\nclass HTTPError extends Error {\n status: number;\n\n text: string;\n\n response?: Response;\n\n constructor(status: number, message: string, response?: Response) {\n super(`HTTP ${status}: ${message}`);\n this.status = status;\n this.text = message;\n this.response = response;\n }\n\n static async fromResponse(\n response: Response,\n options?: { includeResponse?: boolean }\n ): Promise<HTTPError> {\n try {\n return new HTTPError(\n response.status,\n await response.text(),\n options?.includeResponse ? response : undefined\n );\n } catch {\n return new HTTPError(\n response.status,\n response.statusText,\n options?.includeResponse ? response : undefined\n );\n }\n }\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n private onFailedResponseHook?: ResponseCallback;\n\n private customFetch?: typeof fetch;\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 4;\n\n if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod.default as any)({\n concurrency: this.maxConcurrency,\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n this.customFetch = params.fetch;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n const { onFailedResponseHook } = this;\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...(args as Parameters<T>)).catch(async (error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else if (isResponse(error)) {\n throw await HTTPError.fromResponse(error, {\n includeResponse: !!onFailedResponseHook,\n });\n } else {\n throw new Error(error);\n }\n }),\n {\n async onFailedAttempt(error) {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"TimeoutError\") ||\n error.message.startsWith(\"AbortError\")\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof HTTPError) {\n if (STATUS_NO_RETRY.includes(error.status)) {\n throw error;\n }\n if (onFailedResponseHook && error.response) {\n await onFailedResponseHook(error.response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n const fetchFn =\n this.customFetch ?? (_getFetchImplementation() as typeof fetch);\n return this.call(() =>\n fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;AAIA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAmCF,SAAS,WAAW,GAA2B;AAC7C,KAAI,KAAK,QAAQ,OAAO,MAAM,SAAU,QAAO;AAC/C,QAAO,YAAY,KAAK,gBAAgB,KAAK,UAAU;;;;;AAMzD,IAAM,YAAN,MAAM,kBAAkB,MAAM;CAC5B;CAEA;CAEA;CAEA,YAAY,QAAgB,SAAiB,UAAqB;AAChE,QAAM,QAAQ,OAAO,IAAI;AACzB,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,WAAW;;CAGlB,aAAa,aACX,UACA,SACoB;AACpB,MAAI;AACF,UAAO,IAAI,UACT,SAAS,QACT,MAAM,SAAS,QACf,SAAS,kBAAkB,WAAW;UAElC;AACN,UAAO,IAAI,UACT,SAAS,QACT,SAAS,YACT,SAAS,kBAAkB,WAAW;;;;;;;;;;;;;;;;;AAmB9C,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAQ;CAER,AAAQ;CAER,AAAQ;CAER,YAAY,QAA2B;AACrC,OAAK,iBAAiB,OAAO,kBAAkB;AAC/C,OAAK,aAAa,OAAO,cAAc;AAEvC,MAAI,aAAa,UAEf,MAAK,QAAQ,IAAK,UAAU,QAAgB,EAC1C,aAAa,KAAK;MAIpB,MAAK,QAAQ,IAAK,UAAkB,EAAE,aAAa,KAAK;AAE1D,OAAK,uBAAuB,QAAQ;AACpC,OAAK,cAAc,OAAO;;CAI5B,KACE,UACA,GAAG,MAC8B;EACjC,MAAM,EAAE,yBAAyB;AACjC,SAAO,KAAK,MAAM,UAEd,aAEI,SAAS,GAAI,MAAwB,MAAM,OAAO,UAAU;AAE1D,OAAI,iBAAiB,MACnB,OAAM;YACG,WAAW,OACpB,OAAM,MAAM,UAAU,aAAa,OAAO,EACxC,iBAAiB,CAAC,CAAC;OAGrB,OAAM,IAAI,MAAM;MAGtB;GACE,MAAM,gBAAgB,OAAO;AAC3B,QACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,mBACzB,MAAM,QAAQ,WAAW,cAEzB,OAAM;AAGR,QAAK,OAAe,SAAS,eAC3B,OAAM;AAIR,QAAI,iBAAiB,WAAW;AAC9B,SAAI,gBAAgB,SAAS,MAAM,QACjC,OAAM;AAER,SAAI,wBAAwB,MAAM,SAChC,OAAM,qBAAqB,MAAM;;;GAMvC,SAAS,KAAK;GACd,WAAW;MAGjB,EAAE,gBAAgB;;CAKtB,gBACE,SACA,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,OACV,QAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,OAC7B,IAAI,SAAgB,GAAG,WAAW;AAChC,WAAQ,QAAQ,iBAAiB,eAAe;AAC9C,2BAAO,IAAI,MAAM;;;AAKzB,SAAO,KAAK,KAAW,UAAU,GAAG;;CAGtC,MAAM,GAAG,MAA0D;EACjE,MAAM,UACJ,KAAK,eAAgB;AACvB,SAAO,KAAK,WACV,QAAQ,GAAG,MAAM,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO"}
|
package/dist/utils/env.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/env.ts
|
|
3
|
-
function getEnvironmentVariable(name) {
|
|
4
|
-
try {
|
|
5
|
-
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
6
|
-
} catch (e) {
|
|
7
|
-
return void 0;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
exports.getEnvironmentVariable = getEnvironmentVariable;
|
|
13
|
-
//# sourceMappingURL=env.cjs.map
|
package/dist/utils/env.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.cjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export function getEnvironmentVariable(name: string): string | undefined {\n // Certain setups (Deno, frontend) will throw an error if you try to access environment variables\n try {\n return typeof process !== \"undefined\"\n ? // eslint-disable-next-line no-process-env\n process.env?.[name]\n : undefined;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":";;AAAA,SAAgB,uBAAuB,MAAkC;AAEvE,KAAI;AACF,SAAO,OAAO,YAAY,cAEtB,QAAQ,MAAM,QACd;UACG,GAAG;AACV,SAAO"}
|
package/dist/utils/env.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/utils/env.ts
|
|
2
|
-
function getEnvironmentVariable(name) {
|
|
3
|
-
try {
|
|
4
|
-
return typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
return void 0;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
export { getEnvironmentVariable };
|
|
12
|
-
//# sourceMappingURL=env.js.map
|
package/dist/utils/env.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["export function getEnvironmentVariable(name: string): string | undefined {\n // Certain setups (Deno, frontend) will throw an error if you try to access environment variables\n try {\n return typeof process !== \"undefined\"\n ? // eslint-disable-next-line no-process-env\n process.env?.[name]\n : undefined;\n } catch (e) {\n return undefined;\n }\n}\n"],"mappings":";AAAA,SAAgB,uBAAuB,MAAkC;AAEvE,KAAI;AACF,SAAO,OAAO,YAAY,cAEtB,QAAQ,MAAM,QACd;UACG,GAAG;AACV,SAAO"}
|