@langchain/langgraph-sdk 0.0.39 → 0.0.41

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/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { Client } from "./client.js";
2
- export { overrideFetchImplementation } from "./singletons/fetch.js";
package/dist/schema.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._getFetchImplementation = exports.overrideFetchImplementation = void 0;
4
- // Wrap the default fetch call due to issues with illegal invocations
5
- // in some environments:
6
- // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
7
- // @ts-expect-error Broad typing to support a range of fetch implementations
8
- const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
9
- const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("lg:fetch_implementation");
10
- /**
11
- * Overrides the fetch implementation used for LangSmith calls.
12
- * You should use this if you need to use an implementation of fetch
13
- * other than the default global (e.g. for dealing with proxies).
14
- * @param fetch The new fetch function to use.
15
- */
16
- const overrideFetchImplementation = (fetch) => {
17
- globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
18
- };
19
- exports.overrideFetchImplementation = overrideFetchImplementation;
20
- /**
21
- * @internal
22
- */
23
- const _getFetchImplementation = () => {
24
- return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
25
- DEFAULT_FETCH_IMPLEMENTATION);
26
- };
27
- exports._getFetchImplementation = _getFetchImplementation;
@@ -1,11 +0,0 @@
1
- /**
2
- * Overrides the fetch implementation used for LangSmith calls.
3
- * You should use this if you need to use an implementation of fetch
4
- * other than the default global (e.g. for dealing with proxies).
5
- * @param fetch The new fetch function to use.
6
- */
7
- export declare const overrideFetchImplementation: (fetch: (...args: any[]) => any) => void;
8
- /**
9
- * @internal
10
- */
11
- export declare const _getFetchImplementation: () => (...args: any[]) => any;
@@ -1,22 +0,0 @@
1
- // Wrap the default fetch call due to issues with illegal invocations
2
- // in some environments:
3
- // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
4
- // @ts-expect-error Broad typing to support a range of fetch implementations
5
- const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
6
- const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("lg:fetch_implementation");
7
- /**
8
- * Overrides the fetch implementation used for LangSmith calls.
9
- * You should use this if you need to use an implementation of fetch
10
- * other than the default global (e.g. for dealing with proxies).
11
- * @param fetch The new fetch function to use.
12
- */
13
- export const overrideFetchImplementation = (fetch) => {
14
- globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
15
- };
16
- /**
17
- * @internal
18
- */
19
- export const _getFetchImplementation = () => {
20
- return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
21
- DEFAULT_FETCH_IMPLEMENTATION);
22
- };
package/dist/types.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/types.d.ts DELETED
@@ -1,141 +0,0 @@
1
- import { Checkpoint, Config, Metadata } from "./schema.js";
2
- import { StreamMode } from "./types.stream.js";
3
- export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
4
- export type OnConflictBehavior = "raise" | "do_nothing";
5
- export type OnCompletionBehavior = "complete" | "continue";
6
- export type DisconnectMode = "cancel" | "continue";
7
- export type StreamEvent = "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | "messages" | (string & {});
8
- export interface Send {
9
- node: string;
10
- input: Record<string, unknown> | null;
11
- }
12
- export interface Command {
13
- /**
14
- * An object to update the thread state with.
15
- */
16
- update?: Record<string, unknown> | [string, unknown][] | null;
17
- /**
18
- * The value to return from an `interrupt` function call.
19
- */
20
- resume?: unknown;
21
- /**
22
- * Determine the next node to navigate to. Can be one of the following:
23
- * - Name(s) of the node names to navigate to next.
24
- * - `Send` command(s) to execute node(s) with provided input.
25
- */
26
- goto?: Send | Send[] | string | string[];
27
- }
28
- interface RunsInvokePayload {
29
- /**
30
- * Input to the run. Pass `null` to resume from the current state of the thread.
31
- */
32
- input?: Record<string, unknown> | null;
33
- /**
34
- * Metadata for the run.
35
- */
36
- metadata?: Metadata;
37
- /**
38
- * Additional configuration for the run.
39
- */
40
- config?: Config;
41
- /**
42
- * Checkpoint ID for when creating a new run.
43
- */
44
- checkpointId?: string;
45
- /**
46
- * Checkpoint for when creating a new run.
47
- */
48
- checkpoint?: Omit<Checkpoint, "thread_id">;
49
- /**
50
- * Interrupt execution before entering these nodes.
51
- */
52
- interruptBefore?: "*" | string[];
53
- /**
54
- * Interrupt execution after leaving these nodes.
55
- */
56
- interruptAfter?: "*" | string[];
57
- /**
58
- * Strategy to handle concurrent runs on the same thread. Only relevant if
59
- * there is a pending/inflight run on the same thread. One of:
60
- * - "reject": Reject the new run.
61
- * - "interrupt": Interrupt the current run, keeping steps completed until now,
62
- and start a new one.
63
- * - "rollback": Cancel and delete the existing run, rolling back the thread to
64
- the state before it had started, then start the new run.
65
- * - "enqueue": Queue up the new run to start after the current run finishes.
66
- */
67
- multitaskStrategy?: MultitaskStrategy;
68
- /**
69
- * Abort controller signal to cancel the run.
70
- */
71
- signal?: AbortController["signal"];
72
- /**
73
- * Behavior to handle run completion. Only relevant if
74
- * there is a pending/inflight run on the same thread. One of:
75
- * - "complete": Complete the run.
76
- * - "continue": Continue the run.
77
- */
78
- onCompletion?: OnCompletionBehavior;
79
- /**
80
- * Webhook to call when the run is complete.
81
- */
82
- webhook?: string;
83
- /**
84
- * Behavior to handle disconnection. Only relevant if
85
- * there is a pending/inflight run on the same thread. One of:
86
- * - "cancel": Cancel the run.
87
- * - "continue": Continue the run.
88
- */
89
- onDisconnect?: DisconnectMode;
90
- /**
91
- * The number of seconds to wait before starting the run.
92
- * Use to schedule future runs.
93
- */
94
- afterSeconds?: number;
95
- /**
96
- * Behavior if the specified run doesn't exist. Defaults to "reject".
97
- */
98
- ifNotExists?: "create" | "reject";
99
- /**
100
- * One or more commands to invoke the graph with.
101
- */
102
- command?: Command;
103
- }
104
- export interface RunsStreamPayload<TStreamMode extends StreamMode | StreamMode[] = [], TSubgraphs extends boolean = false> extends RunsInvokePayload {
105
- /**
106
- * One of `"values"`, `"messages"`, `"messages-tuple"`, `"updates"`, `"events"`, `"debug"`, `"custom"`.
107
- */
108
- streamMode?: TStreamMode;
109
- /**
110
- * Stream output from subgraphs. By default, streams only the top graph.
111
- */
112
- streamSubgraphs?: TSubgraphs;
113
- /**
114
- * Pass one or more feedbackKeys if you want to request short-lived signed URLs
115
- * for submitting feedback to LangSmith with this key for this run.
116
- */
117
- feedbackKeys?: string[];
118
- }
119
- export interface RunsCreatePayload extends RunsInvokePayload {
120
- /**
121
- * One of `"values"`, `"messages"`, `"messages-tuple"`, `"updates"`, `"events"`, `"debug"`, `"custom"`.
122
- */
123
- streamMode?: StreamMode | Array<StreamMode>;
124
- /**
125
- * Stream output from subgraphs. By default, streams only the top graph.
126
- */
127
- streamSubgraphs?: boolean;
128
- }
129
- export interface CronsCreatePayload extends RunsCreatePayload {
130
- /**
131
- * Schedule for running the Cron Job
132
- */
133
- schedule: string;
134
- }
135
- export interface RunsWaitPayload extends RunsStreamPayload {
136
- /**
137
- * Raise errors returned by the run. Default is `true`.
138
- */
139
- raiseError?: boolean;
140
- }
141
- export {};
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,88 +0,0 @@
1
- type ImageDetail = "auto" | "low" | "high";
2
- type MessageContentImageUrl = {
3
- type: "image_url";
4
- image_url: string | {
5
- url: string;
6
- detail?: ImageDetail | undefined;
7
- };
8
- };
9
- type MessageContentText = {
10
- type: "text";
11
- text: string;
12
- };
13
- type MessageContentComplex = MessageContentText | MessageContentImageUrl;
14
- type MessageContent = string | MessageContentComplex[];
15
- /**
16
- * Model-specific additional kwargs, which is passed back to the underlying LLM.
17
- */
18
- type MessageAdditionalKwargs = Record<string, unknown>;
19
- export type HumanMessage = {
20
- type: "human";
21
- id?: string | undefined;
22
- content: MessageContent;
23
- };
24
- export type AIMessage = {
25
- type: "ai";
26
- id?: string | undefined;
27
- content: MessageContent;
28
- tool_calls?: {
29
- name: string;
30
- args: {
31
- [x: string]: {
32
- [x: string]: any;
33
- };
34
- };
35
- id?: string | undefined;
36
- type?: "tool_call" | undefined;
37
- }[] | undefined;
38
- invalid_tool_calls?: {
39
- name?: string | undefined;
40
- args?: string | undefined;
41
- id?: string | undefined;
42
- error?: string | undefined;
43
- type?: "invalid_tool_call" | undefined;
44
- }[] | undefined;
45
- usage_metadata?: {
46
- input_tokens: number;
47
- output_tokens: number;
48
- total_tokens: number;
49
- input_token_details?: {
50
- audio?: number | undefined;
51
- cache_read?: number | undefined;
52
- cache_creation?: number | undefined;
53
- } | undefined;
54
- output_token_details?: {
55
- audio?: number | undefined;
56
- reasoning?: number | undefined;
57
- } | undefined;
58
- } | undefined;
59
- additional_kwargs?: MessageAdditionalKwargs | undefined;
60
- response_metadata?: Record<string, unknown> | undefined;
61
- };
62
- export type ToolMessage = {
63
- type: "tool";
64
- name?: string | undefined;
65
- id?: string | undefined;
66
- content: MessageContent;
67
- status?: "error" | "success" | undefined;
68
- tool_call_id: string;
69
- additional_kwargs?: MessageAdditionalKwargs | undefined;
70
- response_metadata?: Record<string, unknown> | undefined;
71
- };
72
- export type SystemMessage = {
73
- type: "system";
74
- id?: string | undefined;
75
- content: MessageContent;
76
- };
77
- export type FunctionMessage = {
78
- type: "function";
79
- id?: string | undefined;
80
- content: MessageContent;
81
- };
82
- export type RemoveMessage = {
83
- type: "remove";
84
- id: string;
85
- content: MessageContent;
86
- };
87
- export type Message = HumanMessage | AIMessage | ToolMessage | SystemMessage | FunctionMessage | RemoveMessage;
88
- export {};
@@ -1,156 +0,0 @@
1
- import type { Message } from "./types.messages.js";
2
- /**
3
- * Stream modes
4
- * - "values": Stream only the state values.
5
- * - "messages": Stream complete messages.
6
- * - "messages-tuple": Stream (message chunk, metadata) tuples.
7
- * - "updates": Stream updates to the state.
8
- * - "events": Stream events occurring during execution.
9
- * - "debug": Stream detailed debug information.
10
- * - "custom": Stream custom events.
11
- */
12
- export type StreamMode = "values" | "messages" | "updates" | "events" | "debug" | "custom" | "messages-tuple";
13
- type MessageTupleMetadata = {
14
- tags: string[];
15
- [key: string]: unknown;
16
- };
17
- type AsSubgraph<TEvent extends {
18
- event: string;
19
- data: unknown;
20
- }> = {
21
- event: TEvent["event"] | `${TEvent["event"]}|${string}`;
22
- data: TEvent["data"];
23
- };
24
- /**
25
- * Stream event with values after completion of each step.
26
- */
27
- export type ValuesStreamEvent<StateType> = {
28
- event: "values";
29
- data: StateType;
30
- };
31
- /** @internal */
32
- export type SubgraphValuesStreamEvent<StateType> = AsSubgraph<ValuesStreamEvent<StateType>>;
33
- /**
34
- * Stream event with message chunks coming from LLM invocations inside nodes.
35
- */
36
- export type MessagesTupleStreamEvent = {
37
- event: "messages";
38
- data: [message: Message, config: MessageTupleMetadata];
39
- };
40
- /** @internal */
41
- export type SubgraphMessagesTupleStreamEvent = AsSubgraph<MessagesTupleStreamEvent>;
42
- /**
43
- * Metadata stream event with information about the run and thread
44
- */
45
- export type MetadataStreamEvent = {
46
- event: "metadata";
47
- data: {
48
- run_id: string;
49
- thread_id: string;
50
- };
51
- };
52
- /**
53
- * Stream event with error information.
54
- */
55
- export type ErrorStreamEvent = {
56
- event: "error";
57
- data: {
58
- error: string;
59
- message: string;
60
- };
61
- };
62
- /** @internal */
63
- export type SubgraphErrorStreamEvent = AsSubgraph<ErrorStreamEvent>;
64
- /**
65
- * Stream event with updates to the state after each step.
66
- * The streamed outputs include the name of the node that
67
- * produced the update as well as the update.
68
- */
69
- export type UpdatesStreamEvent<UpdateType> = {
70
- event: "updates";
71
- data: {
72
- [node: string]: UpdateType;
73
- };
74
- };
75
- /** @internal */
76
- export type SubgraphUpdatesStreamEvent<UpdateType> = AsSubgraph<UpdatesStreamEvent<UpdateType>>;
77
- /**
78
- * Streaming custom data from inside the nodes.
79
- */
80
- export type CustomStreamEvent<T> = {
81
- event: "custom";
82
- data: T;
83
- };
84
- /** @internal */
85
- export type SubgraphCustomStreamEvent<T> = AsSubgraph<CustomStreamEvent<T>>;
86
- type MessagesMetadataStreamEvent = {
87
- event: "messages/metadata";
88
- data: {
89
- [messageId: string]: {
90
- metadata: unknown;
91
- };
92
- };
93
- };
94
- type MessagesCompleteStreamEvent = {
95
- event: "messages/complete";
96
- data: Message[];
97
- };
98
- type MessagesPartialStreamEvent = {
99
- event: "messages/partial";
100
- data: Message[];
101
- };
102
- /**
103
- * Message stream event specific to LangGraph Server.
104
- * @deprecated Use `streamMode: "messages-tuple"` instead.
105
- */
106
- export type MessagesStreamEvent = MessagesMetadataStreamEvent | MessagesCompleteStreamEvent | MessagesPartialStreamEvent;
107
- /** @internal */
108
- export type SubgraphMessagesStreamEvent = AsSubgraph<MessagesMetadataStreamEvent> | AsSubgraph<MessagesCompleteStreamEvent> | AsSubgraph<MessagesPartialStreamEvent>;
109
- /**
110
- * Stream event with detailed debug information.
111
- */
112
- export type DebugStreamEvent = {
113
- event: "debug";
114
- data: unknown;
115
- };
116
- /** @internal */
117
- export type SubgraphDebugStreamEvent = AsSubgraph<DebugStreamEvent>;
118
- /**
119
- * Stream event with events occurring during execution.
120
- */
121
- export type EventsStreamEvent = {
122
- event: "events";
123
- data: unknown;
124
- };
125
- /** @internal */
126
- export type SubgraphEventsStreamEvent = AsSubgraph<EventsStreamEvent>;
127
- /**
128
- * Stream event with a feedback key to signed URL map. Set `feedbackKeys` in
129
- * the `RunsStreamPayload` to receive this event.
130
- */
131
- export type FeedbackStreamEvent = {
132
- event: "feedback";
133
- data: {
134
- [feedbackKey: string]: string;
135
- };
136
- };
137
- type GetStreamModeMap<TStreamMode extends StreamMode | StreamMode[], TStateType = unknown, TUpdateType = TStateType, TCustomType = unknown> = {
138
- values: ValuesStreamEvent<TStateType>;
139
- updates: UpdatesStreamEvent<TUpdateType>;
140
- custom: CustomStreamEvent<TCustomType>;
141
- debug: DebugStreamEvent;
142
- messages: MessagesStreamEvent;
143
- "messages-tuple": MessagesTupleStreamEvent;
144
- events: EventsStreamEvent;
145
- }[TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode] | ErrorStreamEvent | MetadataStreamEvent | FeedbackStreamEvent;
146
- type GetSubgraphsStreamModeMap<TStreamMode extends StreamMode | StreamMode[], TStateType = unknown, TUpdateType = TStateType, TCustomType = unknown> = {
147
- values: SubgraphValuesStreamEvent<TStateType>;
148
- updates: SubgraphUpdatesStreamEvent<TUpdateType>;
149
- custom: SubgraphCustomStreamEvent<TCustomType>;
150
- debug: SubgraphDebugStreamEvent;
151
- messages: SubgraphMessagesStreamEvent;
152
- "messages-tuple": SubgraphMessagesTupleStreamEvent;
153
- events: SubgraphEventsStreamEvent;
154
- }[TStreamMode extends StreamMode[] ? TStreamMode[number] : TStreamMode] | SubgraphErrorStreamEvent | MetadataStreamEvent | FeedbackStreamEvent;
155
- export type TypedAsyncGenerator<TStreamMode extends StreamMode | StreamMode[] = [], TSubgraphs extends boolean = false, TStateType = unknown, TUpdateType = TStateType, TCustomType = unknown> = AsyncGenerator<TSubgraphs extends true ? GetSubgraphsStreamModeMap<TStreamMode, TStateType, TUpdateType, TCustomType> : GetStreamModeMap<TStreamMode, TStateType, TUpdateType, TCustomType>>;
156
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,197 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AsyncCaller = void 0;
7
- const p_retry_1 = __importDefault(require("p-retry"));
8
- const p_queue_1 = __importDefault(require("p-queue"));
9
- const fetch_js_1 = require("../singletons/fetch.cjs");
10
- const STATUS_NO_RETRY = [
11
- 400, // Bad Request
12
- 401, // Unauthorized
13
- 402, // Payment required
14
- 403, // Forbidden
15
- 404, // Not Found
16
- 405, // Method Not Allowed
17
- 406, // Not Acceptable
18
- 407, // Proxy Authentication Required
19
- 408, // Request Timeout
20
- 422, // Unprocessable Entity
21
- ];
22
- const STATUS_IGNORE = [
23
- 409, // Conflict
24
- ];
25
- /**
26
- * Do not rely on globalThis.Response, rather just
27
- * do duck typing
28
- */
29
- function isResponse(x) {
30
- if (x == null || typeof x !== "object")
31
- return false;
32
- return "status" in x && "statusText" in x && "text" in x;
33
- }
34
- /**
35
- * Utility error to properly handle failed requests
36
- */
37
- class HTTPError extends Error {
38
- constructor(status, message, response) {
39
- super(`HTTP ${status}: ${message}`);
40
- Object.defineProperty(this, "status", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: void 0
45
- });
46
- Object.defineProperty(this, "text", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: void 0
51
- });
52
- Object.defineProperty(this, "response", {
53
- enumerable: true,
54
- configurable: true,
55
- writable: true,
56
- value: void 0
57
- });
58
- this.status = status;
59
- this.text = message;
60
- this.response = response;
61
- }
62
- static async fromResponse(response, options) {
63
- try {
64
- return new HTTPError(response.status, await response.text(), options?.includeResponse ? response : undefined);
65
- }
66
- catch {
67
- return new HTTPError(response.status, response.statusText, options?.includeResponse ? response : undefined);
68
- }
69
- }
70
- }
71
- /**
72
- * A class that can be used to make async calls with concurrency and retry logic.
73
- *
74
- * This is useful for making calls to any kind of "expensive" external resource,
75
- * be it because it's rate-limited, subject to network issues, etc.
76
- *
77
- * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
78
- * to `Infinity`. This means that by default, all calls will be made in parallel.
79
- *
80
- * Retries are limited by the `maxRetries` parameter, which defaults to 5. This
81
- * means that by default, each call will be retried up to 5 times, with an
82
- * exponential backoff between each attempt.
83
- */
84
- class AsyncCaller {
85
- constructor(params) {
86
- Object.defineProperty(this, "maxConcurrency", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: void 0
91
- });
92
- Object.defineProperty(this, "maxRetries", {
93
- enumerable: true,
94
- configurable: true,
95
- writable: true,
96
- value: void 0
97
- });
98
- Object.defineProperty(this, "queue", {
99
- enumerable: true,
100
- configurable: true,
101
- writable: true,
102
- value: void 0
103
- });
104
- Object.defineProperty(this, "onFailedResponseHook", {
105
- enumerable: true,
106
- configurable: true,
107
- writable: true,
108
- value: void 0
109
- });
110
- Object.defineProperty(this, "customFetch", {
111
- enumerable: true,
112
- configurable: true,
113
- writable: true,
114
- value: void 0
115
- });
116
- this.maxConcurrency = params.maxConcurrency ?? Infinity;
117
- this.maxRetries = params.maxRetries ?? 4;
118
- if ("default" in p_queue_1.default) {
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- this.queue = new p_queue_1.default.default({
121
- concurrency: this.maxConcurrency,
122
- });
123
- }
124
- else {
125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
- this.queue = new p_queue_1.default({ concurrency: this.maxConcurrency });
127
- }
128
- this.onFailedResponseHook = params?.onFailedResponseHook;
129
- this.customFetch = params.fetch;
130
- }
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- call(callable, ...args) {
133
- const onFailedResponseHook = this.onFailedResponseHook;
134
- return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch(async (error) => {
135
- // eslint-disable-next-line no-instanceof/no-instanceof
136
- if (error instanceof Error) {
137
- throw error;
138
- }
139
- else if (isResponse(error)) {
140
- throw await HTTPError.fromResponse(error, {
141
- includeResponse: !!onFailedResponseHook,
142
- });
143
- }
144
- else {
145
- throw new Error(error);
146
- }
147
- }), {
148
- async onFailedAttempt(error) {
149
- if (error.message.startsWith("Cancel") ||
150
- error.message.startsWith("TimeoutError") ||
151
- error.message.startsWith("AbortError")) {
152
- throw error;
153
- }
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- if (error?.code === "ECONNABORTED") {
156
- throw error;
157
- }
158
- if (error instanceof HTTPError) {
159
- if (STATUS_NO_RETRY.includes(error.status)) {
160
- throw error;
161
- }
162
- else if (STATUS_IGNORE.includes(error.status)) {
163
- return;
164
- }
165
- if (onFailedResponseHook && error.response) {
166
- await onFailedResponseHook(error.response);
167
- }
168
- }
169
- },
170
- // If needed we can change some of the defaults here,
171
- // but they're quite sensible.
172
- retries: this.maxRetries,
173
- randomize: true,
174
- }), { throwOnTimeout: true });
175
- }
176
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
- callWithOptions(options, callable, ...args) {
178
- // Note this doesn't cancel the underlying request,
179
- // when available prefer to use the signal option of the underlying call
180
- if (options.signal) {
181
- return Promise.race([
182
- this.call(callable, ...args),
183
- new Promise((_, reject) => {
184
- options.signal?.addEventListener("abort", () => {
185
- reject(new Error("AbortError"));
186
- });
187
- }),
188
- ]);
189
- }
190
- return this.call(callable, ...args);
191
- }
192
- fetch(...args) {
193
- const fetchFn = this.customFetch ?? (0, fetch_js_1._getFetchImplementation)();
194
- return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))));
195
- }
196
- }
197
- exports.AsyncCaller = AsyncCaller;