@trigger.dev/core 4.2.0 → 4.3.1
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/commonjs/v3/apiClient/errors.d.ts +25 -0
- package/dist/commonjs/v3/apiClient/errors.js +29 -1
- package/dist/commonjs/v3/apiClient/errors.js.map +1 -1
- package/dist/commonjs/v3/apiClient/index.d.ts +54 -2
- package/dist/commonjs/v3/apiClient/index.js +280 -0
- package/dist/commonjs/v3/apiClient/index.js.map +1 -1
- package/dist/commonjs/v3/apiClient/streamBatchItems.test.d.ts +1 -0
- package/dist/commonjs/v3/apiClient/streamBatchItems.test.js +369 -0
- package/dist/commonjs/v3/apiClient/streamBatchItems.test.js.map +1 -0
- package/dist/commonjs/v3/idempotencyKeys.d.ts +5 -0
- package/dist/commonjs/v3/idempotencyKeys.js +10 -1
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
- package/dist/commonjs/v3/schemas/api.d.ts +403 -10
- package/dist/commonjs/v3/schemas/api.js +126 -5
- package/dist/commonjs/v3/schemas/api.js.map +1 -1
- package/dist/commonjs/v3/schemas/messages.d.ts +2 -2
- package/dist/commonjs/v3/schemas/runEngine.d.ts +1 -0
- package/dist/commonjs/v3/schemas/runEngine.js +1 -0
- package/dist/commonjs/v3/schemas/runEngine.js.map +1 -1
- package/dist/commonjs/v3/types/tasks.d.ts +53 -4
- package/dist/commonjs/v3/zodSocket.js +1 -1
- package/dist/commonjs/v3/zodSocket.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/apiClient/errors.d.ts +25 -0
- package/dist/esm/v3/apiClient/errors.js +27 -0
- package/dist/esm/v3/apiClient/errors.js.map +1 -1
- package/dist/esm/v3/apiClient/index.d.ts +54 -2
- package/dist/esm/v3/apiClient/index.js +282 -2
- package/dist/esm/v3/apiClient/index.js.map +1 -1
- package/dist/esm/v3/apiClient/streamBatchItems.test.d.ts +1 -0
- package/dist/esm/v3/apiClient/streamBatchItems.test.js +367 -0
- package/dist/esm/v3/apiClient/streamBatchItems.test.js.map +1 -0
- package/dist/esm/v3/idempotencyKeys.d.ts +5 -0
- package/dist/esm/v3/idempotencyKeys.js +9 -1
- package/dist/esm/v3/idempotencyKeys.js.map +1 -1
- package/dist/esm/v3/schemas/api.d.ts +403 -10
- package/dist/esm/v3/schemas/api.js +123 -2
- package/dist/esm/v3/schemas/api.js.map +1 -1
- package/dist/esm/v3/schemas/messages.d.ts +2 -2
- package/dist/esm/v3/schemas/runEngine.d.ts +1 -0
- package/dist/esm/v3/schemas/runEngine.js +1 -0
- package/dist/esm/v3/schemas/runEngine.js.map +1 -1
- package/dist/esm/v3/types/tasks.d.ts +53 -4
- package/dist/esm/v3/zodSocket.js +1 -1
- package/dist/esm/v3/zodSocket.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -52,3 +52,28 @@ export declare class ApiSchemaValidationError extends ApiError {
|
|
|
52
52
|
headers: APIHeaders | undefined;
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Error thrown when a batch stream completes but the batch was not sealed.
|
|
57
|
+
* This indicates that not all expected items were received by the server.
|
|
58
|
+
* The client should retry sending all items, or investigate the mismatch.
|
|
59
|
+
*/
|
|
60
|
+
export declare class BatchNotSealedError extends Error {
|
|
61
|
+
readonly name = "BatchNotSealedError";
|
|
62
|
+
/** The batch ID that was not sealed */
|
|
63
|
+
readonly batchId: string;
|
|
64
|
+
/** Number of items currently enqueued on the server */
|
|
65
|
+
readonly enqueuedCount: number;
|
|
66
|
+
/** Number of items expected to complete the batch */
|
|
67
|
+
readonly expectedCount: number;
|
|
68
|
+
/** Number of items accepted in this request */
|
|
69
|
+
readonly itemsAccepted: number;
|
|
70
|
+
/** Number of items deduplicated in this request */
|
|
71
|
+
readonly itemsDeduplicated: number;
|
|
72
|
+
constructor(options: {
|
|
73
|
+
batchId: string;
|
|
74
|
+
enqueuedCount: number;
|
|
75
|
+
expectedCount: number;
|
|
76
|
+
itemsAccepted: number;
|
|
77
|
+
itemsDeduplicated: number;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiSchemaValidationError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.ApiConnectionError = exports.ApiError = void 0;
|
|
3
|
+
exports.BatchNotSealedError = exports.ApiSchemaValidationError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.ApiConnectionError = exports.ApiError = void 0;
|
|
4
4
|
class ApiError extends Error {
|
|
5
5
|
status;
|
|
6
6
|
headers;
|
|
@@ -144,6 +144,34 @@ class ApiSchemaValidationError extends ApiError {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
exports.ApiSchemaValidationError = ApiSchemaValidationError;
|
|
147
|
+
/**
|
|
148
|
+
* Error thrown when a batch stream completes but the batch was not sealed.
|
|
149
|
+
* This indicates that not all expected items were received by the server.
|
|
150
|
+
* The client should retry sending all items, or investigate the mismatch.
|
|
151
|
+
*/
|
|
152
|
+
class BatchNotSealedError extends Error {
|
|
153
|
+
name = "BatchNotSealedError";
|
|
154
|
+
/** The batch ID that was not sealed */
|
|
155
|
+
batchId;
|
|
156
|
+
/** Number of items currently enqueued on the server */
|
|
157
|
+
enqueuedCount;
|
|
158
|
+
/** Number of items expected to complete the batch */
|
|
159
|
+
expectedCount;
|
|
160
|
+
/** Number of items accepted in this request */
|
|
161
|
+
itemsAccepted;
|
|
162
|
+
/** Number of items deduplicated in this request */
|
|
163
|
+
itemsDeduplicated;
|
|
164
|
+
constructor(options) {
|
|
165
|
+
const message = `Batch ${options.batchId} was not sealed: received ${options.enqueuedCount} of ${options.expectedCount} expected items (accepted: ${options.itemsAccepted}, deduplicated: ${options.itemsDeduplicated})`;
|
|
166
|
+
super(message);
|
|
167
|
+
this.batchId = options.batchId;
|
|
168
|
+
this.enqueuedCount = options.enqueuedCount;
|
|
169
|
+
this.expectedCount = options.expectedCount;
|
|
170
|
+
this.itemsAccepted = options.itemsAccepted;
|
|
171
|
+
this.itemsDeduplicated = options.itemsDeduplicated;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.BatchNotSealedError = BatchNotSealedError;
|
|
147
175
|
function castToError(err) {
|
|
148
176
|
if (err instanceof Error)
|
|
149
177
|
return err;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/v3/apiClient/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAS,SAAQ,KAAK;IACxB,MAAM,CAAqB;IAC3B,OAAO,CAAyB;IAChC,KAAK,CAAqB;IAE1B,IAAI,CAA4B;IAChC,KAAK,CAA4B;IACjC,IAAI,CAAqB;IAElC,YACE,MAA0B,EAC1B,KAAyB,EACzB,OAA2B,EAC3B,OAA+B;QAE/B,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,MAAM,IAAI,GAAG,KAA4B,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,C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AAiB,GAAG,CAAC;QACzN,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACrD,CAAC;CACF;AAlCD,kDAkCC;AAED,SAAS,WAAW,CAAC,GAAQ;IAC3B,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC;IACrC,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { AddTagsRequestBody, ApiDeploymentListOptions, BatchTaskRunExecutionResult, BatchTriggerTaskV3RequestBody, CompleteWaitpointTokenRequestBody, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateWaitpointTokenRequestBody, CreateWaitpointTokenResponseBody, ListQueueOptions, ListRunResponseItem, ListScheduleOptions, RescheduleRunRequestBody, RetrieveQueueParam, TaskRunExecutionResult, TriggerTaskRequestBody, UpdateEnvironmentVariableRequestBody, UpdateMetadataRequestBody, UpdateScheduleOptions, WaitForDurationRequestBody, WaitpointTokenItem } from "../schemas/index.js";
|
|
2
|
+
import { AddTagsRequestBody, ApiDeploymentListOptions, BatchItemNDJSON, BatchTaskRunExecutionResult, BatchTriggerTaskV3RequestBody, CompleteWaitpointTokenRequestBody, CreateBatchRequestBody, CreateBatchResponse, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateWaitpointTokenRequestBody, CreateWaitpointTokenResponseBody, ListQueueOptions, ListRunResponseItem, ListScheduleOptions, RescheduleRunRequestBody, RetrieveQueueParam, StreamBatchItemsResponse, TaskRunExecutionResult, TriggerTaskRequestBody, UpdateEnvironmentVariableRequestBody, UpdateMetadataRequestBody, UpdateScheduleOptions, WaitForDurationRequestBody, WaitpointTokenItem } from "../schemas/index.js";
|
|
3
3
|
import { AsyncIterableStream } from "../streams/asyncIterableStream.js";
|
|
4
4
|
import { AnyRunTypes, TriggerJwtOptions } from "../types/tasks.js";
|
|
5
5
|
import { Prettify } from "../types/utils.js";
|
|
@@ -10,6 +10,9 @@ import { ApiClientConfiguration } from "../apiClientManager-api.js";
|
|
|
10
10
|
export type CreateWaitpointTokenResponse = Prettify<CreateWaitpointTokenResponseBody & {
|
|
11
11
|
publicAccessToken: string;
|
|
12
12
|
}>;
|
|
13
|
+
export type CreateBatchApiResponse = Prettify<CreateBatchResponse & {
|
|
14
|
+
publicAccessToken: string;
|
|
15
|
+
}>;
|
|
13
16
|
export type { CreateEnvironmentVariableParams, ImportEnvironmentVariablesParams, SubscribeToRunsQueryParams, UpdateEnvironmentVariableParams, RealtimeRunSkipColumns, };
|
|
14
17
|
export type ClientTriggerOptions = {
|
|
15
18
|
spanParentAsLink?: boolean;
|
|
@@ -55,6 +58,43 @@ export declare class ApiClient {
|
|
|
55
58
|
id: string;
|
|
56
59
|
runCount: number;
|
|
57
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Phase 1 of 2-phase batch API: Create a batch
|
|
63
|
+
*
|
|
64
|
+
* Creates a new batch and returns its ID. For batchTriggerAndWait,
|
|
65
|
+
* the parent run is blocked immediately on batch creation.
|
|
66
|
+
*
|
|
67
|
+
* @param body - The batch creation parameters
|
|
68
|
+
* @param clientOptions - Options for trace context handling
|
|
69
|
+
* @param clientOptions.spanParentAsLink - If true, child runs will have separate trace IDs with a link to parent
|
|
70
|
+
* @param requestOptions - Optional request options
|
|
71
|
+
* @returns The created batch with ID and metadata
|
|
72
|
+
*/
|
|
73
|
+
createBatch(body: CreateBatchRequestBody, clientOptions?: ClientTriggerOptions, requestOptions?: TriggerRequestOptions): Promise<{
|
|
74
|
+
publicAccessToken: string;
|
|
75
|
+
id: string;
|
|
76
|
+
isCached: boolean;
|
|
77
|
+
runCount: number;
|
|
78
|
+
idempotencyKey?: string | undefined;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Phase 2 of 2-phase batch API: Stream batch items
|
|
82
|
+
*
|
|
83
|
+
* Streams batch items as NDJSON to the server. Each item is enqueued
|
|
84
|
+
* as it arrives. The batch is automatically sealed when the stream completes.
|
|
85
|
+
*
|
|
86
|
+
* Includes automatic retry with exponential backoff. Since items are deduplicated
|
|
87
|
+
* by index on the server, retrying the entire stream is safe.
|
|
88
|
+
*
|
|
89
|
+
* Uses ReadableStream.tee() for retry capability without buffering all items
|
|
90
|
+
* upfront - only items consumed before a failure are buffered for retry.
|
|
91
|
+
*
|
|
92
|
+
* @param batchId - The batch ID from createBatch
|
|
93
|
+
* @param items - Array or async iterable of batch items
|
|
94
|
+
* @param requestOptions - Optional request options
|
|
95
|
+
* @returns Summary of items accepted and deduplicated
|
|
96
|
+
*/
|
|
97
|
+
streamBatchItems(batchId: string, items: BatchItemNDJSON[] | AsyncIterable<BatchItemNDJSON>, requestOptions?: ApiRequestOptions): Promise<StreamBatchItemsResponse>;
|
|
58
98
|
createUploadPayloadUrl(filename: string, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
59
99
|
presignedUrl: string;
|
|
60
100
|
}>;
|
|
@@ -240,6 +280,9 @@ export declare class ApiClient {
|
|
|
240
280
|
cancelRun(runId: string, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
241
281
|
id: string;
|
|
242
282
|
}>;
|
|
283
|
+
resetIdempotencyKey(taskIdentifier: string, idempotencyKey: string, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
284
|
+
id: string;
|
|
285
|
+
}>;
|
|
243
286
|
rescheduleRun(runId: string, body: RescheduleRunRequestBody, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
244
287
|
status: "PENDING_VERSION" | "QUEUED" | "DEQUEUED" | "EXECUTING" | "WAITING" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
245
288
|
id: string;
|
|
@@ -842,12 +885,21 @@ export declare class ApiClient {
|
|
|
842
885
|
}>;
|
|
843
886
|
generateJWTClaims(requestOptions?: ZodFetchOptions): Promise<Record<string, any>>;
|
|
844
887
|
retrieveBatch(batchId: string, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
845
|
-
status: "COMPLETED" | "PENDING";
|
|
888
|
+
status: "COMPLETED" | "PENDING" | "PROCESSING" | "PARTIAL_FAILED" | "ABORTED";
|
|
846
889
|
id: string;
|
|
847
890
|
createdAt: Date;
|
|
848
891
|
updatedAt: Date;
|
|
849
892
|
runs: string[];
|
|
850
893
|
runCount: number;
|
|
894
|
+
processing: {
|
|
895
|
+
errors: {
|
|
896
|
+
error: string;
|
|
897
|
+
taskIdentifier: string;
|
|
898
|
+
index: number;
|
|
899
|
+
errorCode?: string | undefined;
|
|
900
|
+
}[];
|
|
901
|
+
completedAt?: Date | undefined;
|
|
902
|
+
};
|
|
851
903
|
idempotencyKey?: string | undefined;
|
|
852
904
|
}>;
|
|
853
905
|
}
|
|
@@ -24,6 +24,7 @@ const task_context_api_js_1 = require("../task-context-api.js");
|
|
|
24
24
|
const core_js_1 = require("./core.js");
|
|
25
25
|
Object.defineProperty(exports, "isRequestOptions", { enumerable: true, get: function () { return core_js_1.isRequestOptions; } });
|
|
26
26
|
const errors_js_1 = require("./errors.js");
|
|
27
|
+
const retries_js_1 = require("../utils/retries.js");
|
|
27
28
|
const runStream_js_1 = require("./runStream.js");
|
|
28
29
|
Object.defineProperty(exports, "SSEStreamSubscription", { enumerable: true, get: function () { return runStream_js_1.SSEStreamSubscription; } });
|
|
29
30
|
const version_js_2 = require("./version.js");
|
|
@@ -151,6 +152,165 @@ class ApiClient {
|
|
|
151
152
|
};
|
|
152
153
|
});
|
|
153
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Phase 1 of 2-phase batch API: Create a batch
|
|
157
|
+
*
|
|
158
|
+
* Creates a new batch and returns its ID. For batchTriggerAndWait,
|
|
159
|
+
* the parent run is blocked immediately on batch creation.
|
|
160
|
+
*
|
|
161
|
+
* @param body - The batch creation parameters
|
|
162
|
+
* @param clientOptions - Options for trace context handling
|
|
163
|
+
* @param clientOptions.spanParentAsLink - If true, child runs will have separate trace IDs with a link to parent
|
|
164
|
+
* @param requestOptions - Optional request options
|
|
165
|
+
* @returns The created batch with ID and metadata
|
|
166
|
+
*/
|
|
167
|
+
createBatch(body, clientOptions, requestOptions) {
|
|
168
|
+
return (0, core_js_1.zodfetch)(index_js_1.CreateBatchResponse, `${this.baseUrl}/api/v3/batches`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: this.#getHeaders(clientOptions?.spanParentAsLink ?? false),
|
|
171
|
+
body: JSON.stringify(body),
|
|
172
|
+
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions))
|
|
173
|
+
.withResponse()
|
|
174
|
+
.then(async ({ data, response }) => {
|
|
175
|
+
const claimsHeader = response.headers.get("x-trigger-jwt-claims");
|
|
176
|
+
const claims = claimsHeader ? JSON.parse(claimsHeader) : undefined;
|
|
177
|
+
const jwt = await (0, jwt_js_1.generateJWT)({
|
|
178
|
+
secretKey: this.accessToken,
|
|
179
|
+
payload: {
|
|
180
|
+
...claims,
|
|
181
|
+
scopes: [`read:batch:${data.id}`],
|
|
182
|
+
},
|
|
183
|
+
expirationTime: requestOptions?.publicAccessToken?.expirationTime ?? "1h",
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
...data,
|
|
187
|
+
publicAccessToken: jwt,
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Phase 2 of 2-phase batch API: Stream batch items
|
|
193
|
+
*
|
|
194
|
+
* Streams batch items as NDJSON to the server. Each item is enqueued
|
|
195
|
+
* as it arrives. The batch is automatically sealed when the stream completes.
|
|
196
|
+
*
|
|
197
|
+
* Includes automatic retry with exponential backoff. Since items are deduplicated
|
|
198
|
+
* by index on the server, retrying the entire stream is safe.
|
|
199
|
+
*
|
|
200
|
+
* Uses ReadableStream.tee() for retry capability without buffering all items
|
|
201
|
+
* upfront - only items consumed before a failure are buffered for retry.
|
|
202
|
+
*
|
|
203
|
+
* @param batchId - The batch ID from createBatch
|
|
204
|
+
* @param items - Array or async iterable of batch items
|
|
205
|
+
* @param requestOptions - Optional request options
|
|
206
|
+
* @returns Summary of items accepted and deduplicated
|
|
207
|
+
*/
|
|
208
|
+
async streamBatchItems(batchId, items, requestOptions) {
|
|
209
|
+
// Convert input to ReadableStream for uniform handling and tee() support
|
|
210
|
+
const stream = createNdjsonStream(items);
|
|
211
|
+
const retryOptions = {
|
|
212
|
+
...DEFAULT_STREAM_BATCH_RETRY_OPTIONS,
|
|
213
|
+
...requestOptions?.retry,
|
|
214
|
+
};
|
|
215
|
+
return this.#streamBatchItemsWithRetry(batchId, stream, retryOptions);
|
|
216
|
+
}
|
|
217
|
+
async #streamBatchItemsWithRetry(batchId, stream, retryOptions, attempt = 1) {
|
|
218
|
+
const headers = this.#getHeaders(false);
|
|
219
|
+
headers["Content-Type"] = "application/x-ndjson";
|
|
220
|
+
// Tee the stream: one branch for this attempt, one for potential retry
|
|
221
|
+
// tee() internally buffers data consumed from one branch for the other,
|
|
222
|
+
// so we only buffer what's been sent before a failure occurs
|
|
223
|
+
const [forRequest, forRetry] = stream.tee();
|
|
224
|
+
try {
|
|
225
|
+
const response = await fetch(`${this.baseUrl}/api/v3/batches/${batchId}/items`, {
|
|
226
|
+
method: "POST",
|
|
227
|
+
headers,
|
|
228
|
+
body: forRequest,
|
|
229
|
+
// @ts-expect-error - duplex is required for streaming body but not in types
|
|
230
|
+
duplex: "half",
|
|
231
|
+
});
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
const retryResult = shouldRetryStreamBatchItems(response, attempt, retryOptions);
|
|
234
|
+
if (retryResult.retry) {
|
|
235
|
+
// Cancel the request stream before retry to prevent tee() from buffering
|
|
236
|
+
await forRequest.cancel();
|
|
237
|
+
await sleep(retryResult.delay);
|
|
238
|
+
// Use the backup stream for retry
|
|
239
|
+
return this.#streamBatchItemsWithRetry(batchId, forRetry, retryOptions, attempt + 1);
|
|
240
|
+
}
|
|
241
|
+
// Not retrying - cancel the backup stream
|
|
242
|
+
await forRetry.cancel();
|
|
243
|
+
const errText = await response.text().catch((e) => e.message);
|
|
244
|
+
let errJSON;
|
|
245
|
+
try {
|
|
246
|
+
errJSON = JSON.parse(errText);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// ignore
|
|
250
|
+
}
|
|
251
|
+
const errMessage = errJSON ? undefined : errText;
|
|
252
|
+
const responseHeaders = Object.fromEntries(response.headers.entries());
|
|
253
|
+
throw errors_js_1.ApiError.generate(response.status, errJSON, errMessage, responseHeaders);
|
|
254
|
+
}
|
|
255
|
+
const result = await response.json();
|
|
256
|
+
const parsed = index_js_1.StreamBatchItemsResponse.safeParse(result);
|
|
257
|
+
if (!parsed.success) {
|
|
258
|
+
// Cancel backup stream since we're throwing
|
|
259
|
+
await forRetry.cancel();
|
|
260
|
+
throw new Error(`Invalid response from server for batch ${batchId}: ${parsed.error.message}`);
|
|
261
|
+
}
|
|
262
|
+
// Check if the batch was sealed
|
|
263
|
+
if (!parsed.data.sealed) {
|
|
264
|
+
// Not all items were received - treat as retryable condition
|
|
265
|
+
const delay = (0, retries_js_1.calculateNextRetryDelay)(retryOptions, attempt);
|
|
266
|
+
if (delay) {
|
|
267
|
+
// Cancel the request stream before retry to prevent tee() from buffering
|
|
268
|
+
await forRequest.cancel();
|
|
269
|
+
// Retry with the backup stream
|
|
270
|
+
await sleep(delay);
|
|
271
|
+
return this.#streamBatchItemsWithRetry(batchId, forRetry, retryOptions, attempt + 1);
|
|
272
|
+
}
|
|
273
|
+
// No more retries - cancel backup stream and throw descriptive error
|
|
274
|
+
await forRetry.cancel();
|
|
275
|
+
throw new errors_js_1.BatchNotSealedError({
|
|
276
|
+
batchId,
|
|
277
|
+
enqueuedCount: parsed.data.enqueuedCount ?? 0,
|
|
278
|
+
expectedCount: parsed.data.expectedCount ?? 0,
|
|
279
|
+
itemsAccepted: parsed.data.itemsAccepted,
|
|
280
|
+
itemsDeduplicated: parsed.data.itemsDeduplicated,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// Success - cancel the backup stream to release resources
|
|
284
|
+
await forRetry.cancel();
|
|
285
|
+
return parsed.data;
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
// Don't retry BatchNotSealedError (retries already exhausted)
|
|
289
|
+
if (error instanceof errors_js_1.BatchNotSealedError) {
|
|
290
|
+
throw error;
|
|
291
|
+
}
|
|
292
|
+
// Don't retry ApiErrors (already handled above with backup stream cancelled)
|
|
293
|
+
if (error instanceof errors_js_1.ApiError) {
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
// Retry connection errors using the backup stream
|
|
297
|
+
const delay = (0, retries_js_1.calculateNextRetryDelay)(retryOptions, attempt);
|
|
298
|
+
if (delay) {
|
|
299
|
+
// Cancel the request stream before retry to prevent tee() from buffering
|
|
300
|
+
await forRequest.cancel();
|
|
301
|
+
await sleep(delay);
|
|
302
|
+
return this.#streamBatchItemsWithRetry(batchId, forRetry, retryOptions, attempt + 1);
|
|
303
|
+
}
|
|
304
|
+
// No more retries - cancel the backup stream
|
|
305
|
+
await forRetry.cancel();
|
|
306
|
+
// Wrap in a more descriptive error
|
|
307
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
308
|
+
throw new errors_js_1.ApiConnectionError({
|
|
309
|
+
cause,
|
|
310
|
+
message: `Failed to stream batch items for batch ${batchId}: ${cause.message}`,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
154
314
|
createUploadPayloadUrl(filename, requestOptions) {
|
|
155
315
|
return (0, core_js_1.zodfetch)(index_js_1.CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
|
|
156
316
|
method: "PUT",
|
|
@@ -214,6 +374,13 @@ class ApiClient {
|
|
|
214
374
|
headers: this.#getHeaders(false),
|
|
215
375
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
216
376
|
}
|
|
377
|
+
resetIdempotencyKey(taskIdentifier, idempotencyKey, requestOptions) {
|
|
378
|
+
return (0, core_js_1.zodfetch)(index_js_1.ResetIdempotencyKeyResponse, `${this.baseUrl}/api/v1/idempotencyKeys/${encodeURIComponent(idempotencyKey)}/reset`, {
|
|
379
|
+
method: "POST",
|
|
380
|
+
headers: this.#getHeaders(false),
|
|
381
|
+
body: JSON.stringify({ taskIdentifier }),
|
|
382
|
+
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
383
|
+
}
|
|
217
384
|
rescheduleRun(runId, body, requestOptions) {
|
|
218
385
|
return (0, core_js_1.zodfetch)(index_js_1.RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
|
|
219
386
|
method: "POST",
|
|
@@ -741,6 +908,119 @@ function createSearchQueryForListWaitpointTokens(query) {
|
|
|
741
908
|
}
|
|
742
909
|
return searchParams;
|
|
743
910
|
}
|
|
911
|
+
// ============================================================================
|
|
912
|
+
// Stream Batch Items Retry Helpers
|
|
913
|
+
// ============================================================================
|
|
914
|
+
/**
|
|
915
|
+
* Default retry options for streaming batch items.
|
|
916
|
+
* Uses higher values than the default zodfetch retry since batch operations
|
|
917
|
+
* are more expensive to repeat from scratch.
|
|
918
|
+
*/
|
|
919
|
+
const DEFAULT_STREAM_BATCH_RETRY_OPTIONS = {
|
|
920
|
+
maxAttempts: 5,
|
|
921
|
+
factor: 2,
|
|
922
|
+
minTimeoutInMs: 1000,
|
|
923
|
+
maxTimeoutInMs: 30_000,
|
|
924
|
+
randomize: true,
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* Determines if a failed stream batch items request should be retried.
|
|
928
|
+
* Follows similar logic to zodfetch's shouldRetry but specific to batch streaming.
|
|
929
|
+
*/
|
|
930
|
+
function shouldRetryStreamBatchItems(response, attempt, retryOptions) {
|
|
931
|
+
function shouldRetryForOptions() {
|
|
932
|
+
const delay = (0, retries_js_1.calculateNextRetryDelay)(retryOptions, attempt);
|
|
933
|
+
if (delay) {
|
|
934
|
+
return { retry: true, delay };
|
|
935
|
+
}
|
|
936
|
+
return { retry: false };
|
|
937
|
+
}
|
|
938
|
+
// Check x-should-retry header - server can explicitly control retry behavior
|
|
939
|
+
const shouldRetryHeader = response.headers.get("x-should-retry");
|
|
940
|
+
if (shouldRetryHeader === "true")
|
|
941
|
+
return shouldRetryForOptions();
|
|
942
|
+
if (shouldRetryHeader === "false")
|
|
943
|
+
return { retry: false };
|
|
944
|
+
// Retry on request timeouts
|
|
945
|
+
if (response.status === 408)
|
|
946
|
+
return shouldRetryForOptions();
|
|
947
|
+
// Retry on lock timeouts
|
|
948
|
+
if (response.status === 409)
|
|
949
|
+
return shouldRetryForOptions();
|
|
950
|
+
// Retry on rate limits with special handling for Retry-After
|
|
951
|
+
if (response.status === 429) {
|
|
952
|
+
if (attempt >= retryOptions.maxAttempts) {
|
|
953
|
+
return { retry: false };
|
|
954
|
+
}
|
|
955
|
+
// x-ratelimit-reset is the unix timestamp in milliseconds when the rate limit will reset
|
|
956
|
+
const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
|
|
957
|
+
if (resetAtUnixEpochMs) {
|
|
958
|
+
const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
|
|
959
|
+
const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1000);
|
|
960
|
+
if (delay > 0) {
|
|
961
|
+
return { retry: true, delay };
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
// Fall back to Retry-After header (seconds)
|
|
965
|
+
const retryAfter = response.headers.get("retry-after");
|
|
966
|
+
if (retryAfter) {
|
|
967
|
+
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
968
|
+
if (!isNaN(retryAfterSeconds)) {
|
|
969
|
+
return { retry: true, delay: retryAfterSeconds * 1000 };
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return shouldRetryForOptions();
|
|
973
|
+
}
|
|
974
|
+
// Retry on server errors (5xx)
|
|
975
|
+
if (response.status >= 500)
|
|
976
|
+
return shouldRetryForOptions();
|
|
977
|
+
// Don't retry client errors (4xx) except those handled above
|
|
978
|
+
return { retry: false };
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Simple sleep utility for retry delays.
|
|
982
|
+
*/
|
|
983
|
+
function sleep(ms) {
|
|
984
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
985
|
+
}
|
|
986
|
+
// ============================================================================
|
|
987
|
+
// NDJSON Stream Helpers
|
|
988
|
+
// ============================================================================
|
|
989
|
+
/**
|
|
990
|
+
* Creates a ReadableStream that emits NDJSON (newline-delimited JSON) from items.
|
|
991
|
+
* Handles both arrays and async iterables for streaming large batches.
|
|
992
|
+
*/
|
|
993
|
+
function createNdjsonStream(items) {
|
|
994
|
+
const encoder = new TextEncoder();
|
|
995
|
+
// Check if items is an array
|
|
996
|
+
if (Array.isArray(items)) {
|
|
997
|
+
let index = 0;
|
|
998
|
+
return new ReadableStream({
|
|
999
|
+
pull(controller) {
|
|
1000
|
+
if (index >= items.length) {
|
|
1001
|
+
controller.close();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
const item = items[index++];
|
|
1005
|
+
const line = JSON.stringify(item) + "\n";
|
|
1006
|
+
controller.enqueue(encoder.encode(line));
|
|
1007
|
+
},
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
// Handle async iterable
|
|
1011
|
+
const iterator = items[Symbol.asyncIterator]();
|
|
1012
|
+
return new ReadableStream({
|
|
1013
|
+
async pull(controller) {
|
|
1014
|
+
const { value, done } = await iterator.next();
|
|
1015
|
+
if (done) {
|
|
1016
|
+
controller.close();
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const line = JSON.stringify(value) + "\n";
|
|
1020
|
+
controller.enqueue(encoder.encode(line));
|
|
1021
|
+
},
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
744
1024
|
function mergeRequestOptions(defaultOptions, options) {
|
|
745
1025
|
if (!options) {
|
|
746
1026
|
return defaultOptions;
|