batchwork 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/body.d.ts +2 -2
  2. package/dist/body.d.ts.map +1 -1
  3. package/dist/chunk-6jgvqdpc.js +52 -0
  4. package/dist/chunk-6jgvqdpc.js.map +11 -0
  5. package/dist/{chunk-n50t31ca.js → chunk-7y95mhvm.js} +118 -139
  6. package/dist/chunk-7y95mhvm.js.map +27 -0
  7. package/dist/{chunk-mathjpg6.js → chunk-k7n7k3et.js} +46 -41
  8. package/dist/chunk-k7n7k3et.js.map +13 -0
  9. package/dist/{chunk-14qcscwd.js → chunk-zss8h417.js} +203 -191
  10. package/dist/chunk-zss8h417.js.map +12 -0
  11. package/dist/guards.d.ts +5 -0
  12. package/dist/guards.d.ts.map +1 -0
  13. package/dist/http.d.ts +3 -2
  14. package/dist/http.d.ts.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +27 -28
  18. package/dist/index.js.map +1 -1
  19. package/dist/jsonl.d.ts +3 -2
  20. package/dist/jsonl.d.ts.map +1 -1
  21. package/dist/model.d.ts +48 -1
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/next/index.d.ts +1 -1
  24. package/dist/next/index.d.ts.map +1 -1
  25. package/dist/next/index.js +14 -20
  26. package/dist/next/index.js.map +3 -3
  27. package/dist/postgres/batch-store.d.ts.map +1 -1
  28. package/dist/postgres/index.js +22 -15
  29. package/dist/postgres/index.js.map +4 -4
  30. package/dist/postgres/types.d.ts +1 -1
  31. package/dist/postgres/types.d.ts.map +1 -1
  32. package/dist/providers/anthropic.d.ts.map +1 -1
  33. package/dist/providers/azure.d.ts.map +1 -1
  34. package/dist/providers/google.d.ts.map +1 -1
  35. package/dist/providers/mistral.d.ts.map +1 -1
  36. package/dist/providers/openai-compatible.d.ts +2 -2
  37. package/dist/providers/openai-compatible.d.ts.map +1 -1
  38. package/dist/providers/shared.d.ts +8 -8
  39. package/dist/providers/shared.d.ts.map +1 -1
  40. package/dist/providers/xai.d.ts.map +1 -1
  41. package/dist/redis/index.js +40 -6
  42. package/dist/redis/index.js.map +4 -4
  43. package/dist/redis/types.d.ts +18 -5
  44. package/dist/redis/types.d.ts.map +1 -1
  45. package/dist/server/index.js +13 -14
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/server/poller.d.ts +6 -4
  48. package/dist/server/poller.d.ts.map +1 -1
  49. package/dist/server/signing.d.ts.map +1 -1
  50. package/dist/types.d.ts +16 -2
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/util.d.ts +16 -7
  53. package/dist/util.d.ts.map +1 -1
  54. package/package.json +19 -19
  55. package/dist/chunk-14qcscwd.js.map +0 -12
  56. package/dist/chunk-mathjpg6.js.map +0 -13
  57. package/dist/chunk-n50t31ca.js.map +0 -28
  58. package/dist/chunk-v0bahtg2.js +0 -7
  59. package/dist/chunk-v0bahtg2.js.map +0 -9
@@ -1,16 +1,18 @@
1
1
  import {
2
- BatchJob,
3
- BatchworkError,
4
- MissingDependencyError,
5
- UnsupportedProviderError,
6
- assertByteLength,
7
- getAdapter,
2
+ BatchworkError2,
3
+ UnsupportedProviderError2,
4
+ MissingDependencyError2,
8
5
  resolveBatchLimits,
9
- trimTrailingSlashes
10
- } from "./chunk-n50t31ca.js";
6
+ assertByteLength,
7
+ BatchJob2,
8
+ getAdapter
9
+ } from "./chunk-7y95mhvm.js";
11
10
  import {
12
- __require
13
- } from "./chunk-v0bahtg2.js";
11
+ isString,
12
+ trimTrailingSlashes,
13
+ isJsonObject,
14
+ parseJson
15
+ } from "./chunk-6jgvqdpc.js";
14
16
 
15
17
  // src/model.ts
16
18
  var CAPTURE_API_KEY = "batchwork-capture";
@@ -37,21 +39,21 @@ var PACKAGE_BY_PROVIDER = {
37
39
  together: { label: "Together AI", specifier: "@ai-sdk/togetherai" },
38
40
  xai: { label: "xAI", specifier: "@ai-sdk/xai" }
39
41
  };
40
- var PROVIDER_BY_FAMILY = {
41
- anthropic: "anthropic",
42
- azure: "azure",
43
- google: "google",
44
- groq: "groq",
45
- mistral: "mistral",
46
- openai: "openai",
47
- together: "together",
48
- togetherai: "together",
49
- xai: "xai"
50
- };
51
- var PROVIDER_BY_ALIAS = {
42
+ var PROVIDER_BY_FAMILY = new Map([
43
+ ["anthropic", "anthropic"],
44
+ ["azure", "azure"],
45
+ ["google", "google"],
46
+ ["groq", "groq"],
47
+ ["mistral", "mistral"],
48
+ ["openai", "openai"],
49
+ ["together", "together"],
50
+ ["togetherai", "together"],
51
+ ["xai", "xai"]
52
+ ]);
53
+ var PROVIDER_BY_ALIAS = new Map([
52
54
  ...PROVIDER_BY_FAMILY,
53
- gemini: "google"
54
- };
55
+ ["gemini", "google"]
56
+ ]);
55
57
  var splitOnce = (value, separator) => {
56
58
  const index = value.indexOf(separator);
57
59
  if (index === -1) {
@@ -71,20 +73,20 @@ var openaiKind = (suffix) => {
71
73
  var resolveModelString = (value) => {
72
74
  const [providerId, modelId] = splitOnce(value, "/");
73
75
  if (modelId === "") {
74
- throw new UnsupportedProviderError(value);
76
+ throw new UnsupportedProviderError2(value);
75
77
  }
76
- const provider = PROVIDER_BY_ALIAS[providerId];
78
+ const provider = PROVIDER_BY_ALIAS.get(providerId);
77
79
  if (!provider) {
78
- throw new UnsupportedProviderError(providerId);
80
+ throw new UnsupportedProviderError2(providerId);
79
81
  }
80
82
  return { kind: "chat", modelId, provider };
81
83
  };
82
- var resolveModel = (model) => {
83
- if (typeof model === "string") {
84
+ var resolveModel2 = (model) => {
85
+ if (isString(model)) {
84
86
  return resolveModelString(model);
85
87
  }
86
88
  const [family, suffix] = splitOnce(model.provider, ".");
87
- const provider = PROVIDER_BY_FAMILY[family];
89
+ const provider = PROVIDER_BY_FAMILY.get(family);
88
90
  if (provider === "openai" || provider === "azure") {
89
91
  return { kind: openaiKind(suffix), modelId: model.modelId, provider };
90
92
  }
@@ -94,48 +96,34 @@ var resolveModel = (model) => {
94
96
  if (model.modelId.includes("/")) {
95
97
  return resolveModelString(model.modelId);
96
98
  }
97
- throw new UnsupportedProviderError(model.provider);
99
+ throw new UnsupportedProviderError2(model.provider);
100
+ };
101
+ var importers = {
102
+ anthropic: () => import("@ai-sdk/anthropic"),
103
+ azure: () => import("@ai-sdk/azure"),
104
+ google: () => import("@ai-sdk/google"),
105
+ groq: () => import("@ai-sdk/groq"),
106
+ mistral: () => import("@ai-sdk/mistral"),
107
+ openai: () => import("@ai-sdk/openai"),
108
+ together: () => import("@ai-sdk/togetherai"),
109
+ xai: () => import("@ai-sdk/xai")
98
110
  };
99
111
  var importProvider = (provider) => {
100
- switch (provider) {
101
- case "anthropic": {
102
- return import("@ai-sdk/anthropic");
103
- }
104
- case "azure": {
105
- return import("@ai-sdk/azure");
106
- }
107
- case "google": {
108
- return import("@ai-sdk/google");
109
- }
110
- case "groq": {
111
- return import("@ai-sdk/groq");
112
- }
113
- case "mistral": {
114
- return import("@ai-sdk/mistral");
115
- }
116
- case "openai": {
117
- return import("@ai-sdk/openai");
118
- }
119
- case "together": {
120
- return import("@ai-sdk/togetherai");
121
- }
122
- case "xai": {
123
- return import("@ai-sdk/xai");
124
- }
125
- default: {
126
- return Promise.reject(new UnsupportedProviderError(provider));
127
- }
112
+ const importer = importers[provider];
113
+ if (importer === undefined) {
114
+ return Promise.reject(new UnsupportedProviderError2(provider));
128
115
  }
116
+ return importer();
129
117
  };
130
118
  var loadProvider = async (provider, load = importProvider) => {
131
119
  try {
132
120
  return await load(provider);
133
121
  } catch (error) {
134
- if (error instanceof UnsupportedProviderError) {
122
+ if (error instanceof UnsupportedProviderError2) {
135
123
  throw error;
136
124
  }
137
125
  const { specifier, label } = PACKAGE_BY_PROVIDER[provider];
138
- throw new MissingDependencyError(specifier, label);
126
+ throw new MissingDependencyError2(specifier, label);
139
127
  }
140
128
  };
141
129
  var createCaptureModel = async (resolved, credentials, fetchImpl) => {
@@ -196,7 +184,7 @@ var createCaptureModel = async (resolved, credentials, fetchImpl) => {
196
184
  return createTogetherAI(settings).languageModel(resolved.modelId);
197
185
  }
198
186
  default: {
199
- throw new UnsupportedProviderError(resolved.provider);
187
+ throw new UnsupportedProviderError2(resolved.provider);
200
188
  }
201
189
  }
202
190
  };
@@ -205,7 +193,7 @@ var EMBEDDING_PROVIDERS = new Set([
205
193
  "mistral",
206
194
  "openai"
207
195
  ]);
208
- var unsupportedEmbeddingProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch embeddings. Embeddings are supported for: openai, mistral, google.`);
196
+ var unsupportedEmbeddingProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch embeddings. Embeddings are supported for: openai, mistral, google.`);
209
197
  var createCaptureEmbeddingModel = async (resolved, credentials, fetchImpl) => {
210
198
  const settings = {
211
199
  apiKey: credentials.apiKey ?? CAPTURE_API_KEY,
@@ -232,9 +220,9 @@ var createCaptureEmbeddingModel = async (resolved, credentials, fetchImpl) => {
232
220
  }
233
221
  };
234
222
  var IMAGE_EDIT_PROVIDERS = new Set(["openai", "xai"]);
235
- var unsupportedImageEditProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch image editing. Image edits are supported for: openai, xai.`);
223
+ var unsupportedImageEditProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch image editing. Image edits are supported for: openai, xai.`);
236
224
  var VIDEO_PROVIDERS = new Set(["xai"]);
237
- var unsupportedVideoProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch video generation. Videos are supported for: xai.`);
225
+ var unsupportedVideoProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch video generation. Videos are supported for: xai.`);
238
226
  var createCaptureVideoModel = async (resolved, credentials, fetchImpl) => {
239
227
  if (resolved.provider !== "xai") {
240
228
  throw unsupportedVideoProvider(resolved.provider);
@@ -251,24 +239,24 @@ var TRANSLATION_PROVIDERS = new Set([
251
239
  "groq",
252
240
  "together"
253
241
  ]);
254
- var unsupportedTranslationProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch translation. Translations are supported for: groq, together.`);
242
+ var unsupportedTranslationProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch translation. Translations are supported for: groq, together.`);
255
243
  var MODERATION_PROVIDERS = new Set([
256
244
  "mistral",
257
245
  "openai"
258
246
  ]);
259
- var unsupportedModerationProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch moderation. Moderations are supported for: openai, mistral.`);
247
+ var unsupportedModerationProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch moderation. Moderations are supported for: openai, mistral.`);
260
248
  var TRANSCRIPTION_PROVIDERS = new Set([
261
249
  "groq",
262
250
  "mistral",
263
251
  "together"
264
252
  ]);
265
- var unsupportedTranscriptionProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch transcription. Transcriptions are supported for: groq, mistral, together.`);
253
+ var unsupportedTranscriptionProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch transcription. Transcriptions are supported for: groq, mistral, together.`);
266
254
  var IMAGE_PROVIDERS = new Set([
267
255
  "google",
268
256
  "openai",
269
257
  "xai"
270
258
  ]);
271
- var unsupportedImageProvider = (provider) => new UnsupportedProviderError(provider, `batchwork: provider "${provider}" does not offer batch image generation. Image batches are supported for: openai, google, xai.`);
259
+ var unsupportedImageProvider = (provider) => new UnsupportedProviderError2(provider, `batchwork: provider "${provider}" does not offer batch image generation. Image batches are supported for: openai, google, xai.`);
272
260
  var createCaptureImageModel = async (resolved, credentials, fetchImpl) => {
273
261
  const settings = {
274
262
  apiKey: credentials.apiKey ?? CAPTURE_API_KEY,
@@ -316,35 +304,36 @@ class CaptureSignalError extends Error {
316
304
  }
317
305
  }
318
306
  var resolveUrl = (input) => {
319
- if (typeof input === "string") {
320
- return input;
321
- }
322
307
  if (input instanceof URL) {
323
308
  return input.toString();
324
309
  }
325
- return input.url;
310
+ if (input instanceof Request) {
311
+ return input.url;
312
+ }
313
+ return input;
326
314
  };
327
315
  var extractBody = (init) => {
328
316
  const body = init?.body;
329
- if (typeof body === "string") {
317
+ if (isString(body)) {
330
318
  return body;
331
319
  }
332
320
  if (body instanceof Uint8Array) {
333
321
  return new TextDecoder().decode(body);
334
322
  }
335
- throw new BatchworkError("batchwork: unable to read the provider request body during capture.");
323
+ throw new BatchworkError2("batchwork: unable to read the provider request body during capture.");
336
324
  };
337
- var captureFetch = (input, init) => Promise.reject(new CaptureSignalError(resolveUrl(input), extractBody(init)));
338
- var findCapture = (error) => {
339
- let current = error;
340
- let depth = 0;
341
- while (current && depth < MAX_CAUSE_DEPTH) {
342
- if (current instanceof CaptureSignalError) {
343
- return current;
344
- }
345
- current = current.cause;
346
- depth += 1;
325
+ var captureFetch = Object.assign((input, init) => Promise.reject(new CaptureSignalError(resolveUrl(input), extractBody(init))), {
326
+ preconnect: () => {}
327
+ });
328
+ var hasCause = (value) => typeof value === "object" && value !== null && ("cause" in value);
329
+ var findCapture = (cause, depth = 0) => {
330
+ if (depth >= MAX_CAUSE_DEPTH) {
331
+ return;
332
+ }
333
+ if (cause instanceof CaptureSignalError) {
334
+ return cause;
347
335
  }
336
+ return hasCause(cause) ? findCapture(cause.cause, depth + 1) : undefined;
348
337
  };
349
338
  var endpointFromUrl = (url) => {
350
339
  try {
@@ -377,25 +366,25 @@ var toGenerateInput = (model, request) => ({
377
366
  topK: request.topK,
378
367
  topP: request.topP
379
368
  });
380
- var bodyFromCapture = (error, customId, maxRequestBytes) => {
381
- const capture = findCapture(error);
382
- if (capture) {
383
- assertByteLength(`request "${customId}"`, capture.rawBody, maxRequestBytes);
384
- return {
385
- body: JSON.parse(capture.rawBody),
386
- customId,
387
- endpoint: endpointFromUrl(capture.url)
388
- };
369
+ var bodyFromCapture = (capture, customId, maxRequestBytes) => {
370
+ assertByteLength(`request "${customId}"`, capture.rawBody, maxRequestBytes);
371
+ const body = parseJson(capture.rawBody);
372
+ if (!isJsonObject(body)) {
373
+ throw new BatchworkError2(`batchwork: the captured body for request "${customId}" is not a JSON object.`);
389
374
  }
390
- throw error;
375
+ return { body, customId, endpoint: endpointFromUrl(capture.url) };
391
376
  };
392
377
  var captureOne = async (model, request, customId, maxRequestBytes) => {
393
378
  try {
394
379
  await generateText(toGenerateInput(model, request));
395
380
  } catch (error) {
396
- return bodyFromCapture(error, customId, maxRequestBytes);
381
+ const capture = findCapture(error);
382
+ if (!capture) {
383
+ throw error;
384
+ }
385
+ return bodyFromCapture(capture, customId, maxRequestBytes);
397
386
  }
398
- throw new BatchworkError("batchwork: the request was not intercepted while building the batch body.");
387
+ throw new BatchworkError2("batchwork: the request was not intercepted while building the batch body.");
399
388
  };
400
389
  var captureEmbeddingOne = async (model, request, customId, maxRequestBytes) => {
401
390
  try {
@@ -406,9 +395,13 @@ var captureEmbeddingOne = async (model, request, customId, maxRequestBytes) => {
406
395
  value: request.value
407
396
  });
408
397
  } catch (error) {
409
- return bodyFromCapture(error, customId, maxRequestBytes);
398
+ const capture = findCapture(error);
399
+ if (!capture) {
400
+ throw error;
401
+ }
402
+ return bodyFromCapture(capture, customId, maxRequestBytes);
410
403
  }
411
- throw new BatchworkError("batchwork: the request was not intercepted while building the embedding body.");
404
+ throw new BatchworkError2("batchwork: the request was not intercepted while building the embedding body.");
412
405
  };
413
406
  var captureImageOne = async (model, request, customId, maxRequestBytes) => {
414
407
  try {
@@ -424,16 +417,20 @@ var captureImageOne = async (model, request, customId, maxRequestBytes) => {
424
417
  size: request.size
425
418
  });
426
419
  } catch (error) {
427
- return bodyFromCapture(error, customId, maxRequestBytes);
420
+ const capture = findCapture(error);
421
+ if (!capture) {
422
+ throw error;
423
+ }
424
+ return bodyFromCapture(capture, customId, maxRequestBytes);
428
425
  }
429
- throw new BatchworkError("batchwork: the request was not intercepted while building the image body.");
426
+ throw new BatchworkError2("batchwork: the request was not intercepted while building the image body.");
430
427
  };
431
428
  var assignCustomIds = (requests) => {
432
429
  const seen = new Set;
433
430
  return requests.map((request, index) => {
434
431
  const customId = request.customId ?? `request-${index}`;
435
432
  if (seen.has(customId)) {
436
- throw new BatchworkError(`batchwork: duplicate customId "${customId}". customId values must be unique within a batch.`);
433
+ throw new BatchworkError2(`batchwork: duplicate customId "${customId}". customId values must be unique within a batch.`);
437
434
  }
438
435
  seen.add(customId);
439
436
  return { customId, request };
@@ -442,7 +439,7 @@ var assignCustomIds = (requests) => {
442
439
  var buildRequestBodies = async (resolved, requests, defaults, credentials, rawLimits) => {
443
440
  const limits = resolveBatchLimits(rawLimits);
444
441
  if (requests.length > limits.maxRequests) {
445
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
442
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
446
443
  }
447
444
  const model = await createCaptureModel(resolved, credentials, captureFetch);
448
445
  const items = assignCustomIds(requests);
@@ -455,7 +452,7 @@ var buildRequestBodies = async (resolved, requests, defaults, credentials, rawLi
455
452
  var buildEmbeddingBodies = async (resolved, requests, credentials, rawLimits) => {
456
453
  const limits = resolveBatchLimits(rawLimits);
457
454
  if (requests.length > limits.maxRequests) {
458
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
455
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
459
456
  }
460
457
  const model = await createCaptureEmbeddingModel(resolved, credentials, captureFetch);
461
458
  const items = assignCustomIds(requests);
@@ -466,40 +463,39 @@ var buildEmbeddingBodies = async (resolved, requests, credentials, rawLimits) =>
466
463
  }, { concurrency: limits.captureConcurrency });
467
464
  };
468
465
  var MODERATION_ENDPOINT = "/v1/moderations";
469
- var moderationInput = (request) => {
470
- const imageUrls = request.imageUrls ?? [];
471
- if (imageUrls.length === 0) {
472
- return request.value;
466
+ var moderationParts = (value, imageUrls) => {
467
+ const parts = [];
468
+ if (value !== undefined) {
469
+ parts.push({ text: value, type: "text" });
473
470
  }
474
- return [
475
- ...request.value === undefined ? [] : [{ text: request.value, type: "text" }],
476
- ...imageUrls.map((url) => ({ image_url: { url }, type: "image_url" }))
477
- ];
471
+ for (const url of imageUrls) {
472
+ parts.push({ image_url: { url }, type: "image_url" });
473
+ }
474
+ return parts;
478
475
  };
479
476
  var moderationBody = (resolved, request, customId) => {
480
- if (request.value === undefined && !request.imageUrls?.length) {
481
- throw new BatchworkError(`batchwork: moderation request "${customId}" needs \`value\` or \`imageUrls\`.`);
477
+ const { value } = request;
478
+ const imageUrls = request.imageUrls ?? [];
479
+ if (value === undefined && imageUrls.length === 0) {
480
+ throw new BatchworkError2(`batchwork: moderation request "${customId}" needs \`value\` or \`imageUrls\`.`);
482
481
  }
483
482
  const options = request.providerOptions?.[resolved.provider];
484
483
  if (resolved.provider === "openai") {
485
- return {
486
- input: moderationInput(request),
487
- model: resolved.modelId,
488
- ...options
489
- };
484
+ const input = imageUrls.length === 0 && value !== undefined ? value : moderationParts(value, imageUrls);
485
+ return { input, model: resolved.modelId, ...options };
490
486
  }
491
487
  if (resolved.provider === "mistral") {
492
- if (request.imageUrls?.length) {
493
- throw new BatchworkError(`batchwork: moderation request "${customId}" has \`imageUrls\`, but Mistral moderation is text-only.`);
488
+ if (imageUrls.length > 0) {
489
+ throw new BatchworkError2(`batchwork: moderation request "${customId}" has \`imageUrls\`, but Mistral moderation is text-only.`);
494
490
  }
495
- return { input: request.value, model: resolved.modelId, ...options };
491
+ return { input: value ?? "", model: resolved.modelId, ...options };
496
492
  }
497
493
  throw unsupportedModerationProvider(resolved.provider);
498
494
  };
499
495
  var buildModerationBodies = (resolved, requests, rawLimits) => {
500
496
  const limits = resolveBatchLimits(rawLimits);
501
497
  if (requests.length > limits.maxRequests) {
502
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
498
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
503
499
  }
504
500
  return assignCustomIds(requests).map((item) => {
505
501
  const body = moderationBody(resolved, item.request, item.customId);
@@ -508,17 +504,26 @@ var buildModerationBodies = (resolved, requests, rawLimits) => {
508
504
  });
509
505
  };
510
506
  var TRANSCRIPTION_ENDPOINT = "/v1/audio/transcriptions";
507
+ var audioOptions = (request, verboseTimestamps) => {
508
+ const fields = {};
509
+ if (request.language) {
510
+ fields.language = request.language;
511
+ }
512
+ if (request.timestampGranularities) {
513
+ if (verboseTimestamps) {
514
+ fields.response_format = "verbose_json";
515
+ }
516
+ fields.timestamp_granularities = request.timestampGranularities;
517
+ }
518
+ return fields;
519
+ };
511
520
  var transcriptionBody = (resolved, request) => {
512
521
  const options = request.providerOptions?.[resolved.provider];
513
522
  if (resolved.provider === "groq") {
514
523
  return {
515
524
  model: resolved.modelId,
516
525
  url: request.audioUrl,
517
- ...request.language ? { language: request.language } : {},
518
- ...request.timestampGranularities ? {
519
- response_format: "verbose_json",
520
- timestamp_granularities: request.timestampGranularities
521
- } : {},
526
+ ...audioOptions(request, true),
522
527
  ...options
523
528
  };
524
529
  }
@@ -526,8 +531,7 @@ var transcriptionBody = (resolved, request) => {
526
531
  return {
527
532
  file_url: request.audioUrl,
528
533
  model: resolved.modelId,
529
- ...request.language ? { language: request.language } : {},
530
- ...request.timestampGranularities ? { timestamp_granularities: request.timestampGranularities } : {},
534
+ ...audioOptions(request, false),
531
535
  ...options
532
536
  };
533
537
  }
@@ -535,11 +539,7 @@ var transcriptionBody = (resolved, request) => {
535
539
  return {
536
540
  file: request.audioUrl,
537
541
  model: resolved.modelId,
538
- ...request.language ? { language: request.language } : {},
539
- ...request.timestampGranularities ? {
540
- response_format: "verbose_json",
541
- timestamp_granularities: request.timestampGranularities
542
- } : {},
542
+ ...audioOptions(request, true),
543
543
  ...options
544
544
  };
545
545
  }
@@ -548,7 +548,7 @@ var transcriptionBody = (resolved, request) => {
548
548
  var buildAudioBodies = (resolved, requests, defaults, endpoint, rawLimits) => {
549
549
  const limits = resolveBatchLimits(rawLimits);
550
550
  if (requests.length > limits.maxRequests) {
551
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
551
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
552
552
  }
553
553
  return assignCustomIds(requests).map((item) => {
554
554
  const body = transcriptionBody(resolved, mergeDefaults(item.request, defaults));
@@ -561,7 +561,7 @@ var buildTranslationBodies = (resolved, requests, defaults, rawLimits) => buildA
561
561
  var buildImageBodies = async (resolved, requests, defaults, credentials, rawLimits) => {
562
562
  const limits = resolveBatchLimits(rawLimits);
563
563
  if (requests.length > limits.maxRequests) {
564
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
564
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
565
565
  }
566
566
  const model = await createCaptureImageModel(resolved, credentials, captureFetch);
567
567
  const items = assignCustomIds(requests);
@@ -575,47 +575,55 @@ var IMAGE_EDIT_ENDPOINT = "/v1/images/edits";
575
575
  var openaiImageRef = (ref) => ("fileId" in ref) ? { file_id: ref.fileId } : { image_url: ref.imageUrl };
576
576
  var imageEditBody = (resolved, request, customId) => {
577
577
  if (request.images.length === 0) {
578
- throw new BatchworkError(`batchwork: image-edit request "${customId}" needs at least one entry in \`images\`.`);
578
+ throw new BatchworkError2(`batchwork: image-edit request "${customId}" needs at least one entry in \`images\`.`);
579
579
  }
580
580
  const options = request.providerOptions?.[resolved.provider];
581
581
  if (resolved.provider === "openai") {
582
- return {
582
+ const body = {
583
583
  images: request.images.map(openaiImageRef),
584
584
  model: resolved.modelId,
585
- prompt: request.prompt,
586
- ...request.mask ? { mask: openaiImageRef(request.mask) } : {},
587
- ...request.n === undefined ? {} : { n: request.n },
588
- ...request.size ? { size: request.size } : {},
589
- ...options
585
+ prompt: request.prompt
590
586
  };
587
+ if (request.mask) {
588
+ body.mask = openaiImageRef(request.mask);
589
+ }
590
+ if (request.n !== undefined) {
591
+ body.n = request.n;
592
+ }
593
+ if (request.size) {
594
+ body.size = request.size;
595
+ }
596
+ return { ...body, ...options };
591
597
  }
592
598
  if (resolved.provider === "xai") {
593
599
  if (request.mask) {
594
- throw new BatchworkError(`batchwork: image-edit request "${customId}" has a \`mask\`, but xAI image edits do not support masks.`);
600
+ throw new BatchworkError2(`batchwork: image-edit request "${customId}" has a \`mask\`, but xAI image edits do not support masks.`);
595
601
  }
596
602
  if (request.size) {
597
- throw new BatchworkError(`batchwork: image-edit request "${customId}" has \`size\`, but xAI image edits take \`providerOptions.xai.aspect_ratio\` instead.`);
603
+ throw new BatchworkError2(`batchwork: image-edit request "${customId}" has \`size\`, but xAI image edits take \`providerOptions.xai.aspect_ratio\` instead.`);
598
604
  }
599
605
  const urls = request.images.map((ref) => {
600
606
  if ("fileId" in ref) {
601
- throw new BatchworkError(`batchwork: image-edit request "${customId}" uses a \`fileId\` reference, but xAI image edits accept image URLs only.`);
607
+ throw new BatchworkError2(`batchwork: image-edit request "${customId}" uses a \`fileId\` reference, but xAI image edits accept image URLs only.`);
602
608
  }
603
609
  return ref.imageUrl;
604
610
  });
605
- return {
611
+ const body = {
606
612
  model: resolved.modelId,
607
613
  prompt: request.prompt,
608
- ...urls.length === 1 ? { image: { url: urls[0] } } : { images: urls.map((url) => ({ url })) },
609
- ...request.n === undefined ? {} : { n: request.n },
610
- ...options
614
+ ...urls.length === 1 ? { image: { url: urls[0] } } : { images: urls.map((url) => ({ url })) }
611
615
  };
616
+ if (request.n !== undefined) {
617
+ body.n = request.n;
618
+ }
619
+ return { ...body, ...options };
612
620
  }
613
621
  throw unsupportedImageEditProvider(resolved.provider);
614
622
  };
615
623
  var buildImageEditBodies = (resolved, requests, defaults, rawLimits) => {
616
624
  const limits = resolveBatchLimits(rawLimits);
617
625
  if (requests.length > limits.maxRequests) {
618
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
626
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
619
627
  }
620
628
  return assignCustomIds(requests).map((item) => {
621
629
  const body = imageEditBody(resolved, mergeDefaults(item.request, defaults), item.customId);
@@ -635,14 +643,18 @@ var captureVideoOne = async (model, request, customId, maxRequestBytes) => {
635
643
  resolution: request.resolution
636
644
  });
637
645
  } catch (error) {
638
- return bodyFromCapture(error, customId, maxRequestBytes);
646
+ const capture = findCapture(error);
647
+ if (!capture) {
648
+ throw error;
649
+ }
650
+ return bodyFromCapture(capture, customId, maxRequestBytes);
639
651
  }
640
- throw new BatchworkError("batchwork: the request was not intercepted while building the video body.");
652
+ throw new BatchworkError2("batchwork: the request was not intercepted while building the video body.");
641
653
  };
642
654
  var buildVideoBodies = async (resolved, requests, defaults, credentials, rawLimits) => {
643
655
  const limits = resolveBatchLimits(rawLimits);
644
656
  if (requests.length > limits.maxRequests) {
645
- throw new BatchworkError(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
657
+ throw new BatchworkError2(`batchwork: requests length ${requests.length} exceeds the ${limits.maxRequests} request limit.`);
646
658
  }
647
659
  const model = await createCaptureVideoModel(resolved, credentials, captureFetch);
648
660
  const items = assignCustomIds(requests);
@@ -665,15 +677,15 @@ var providerFromRef = (ref) => {
665
677
  return ref.provider;
666
678
  }
667
679
  if (ref.model !== undefined) {
668
- return resolveModel(ref.model).provider;
680
+ return resolveModel2(ref.model).provider;
669
681
  }
670
- throw new BatchworkError("batchwork: provide `provider` or `model` to identify the batch.");
682
+ throw new BatchworkError2("batchwork: provide `provider` or `model` to identify the batch.");
671
683
  };
672
684
  var submitText = async (options) => {
673
685
  if (options.requests.length === 0) {
674
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
686
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
675
687
  }
676
- const resolved = resolveModel(options.model);
688
+ const resolved = resolveModel2(options.model);
677
689
  const credentials = pickCredentials(options);
678
690
  const limits = resolveBatchLimits(options.limits);
679
691
  const adapter = getAdapter(resolved.provider);
@@ -686,13 +698,13 @@ var submitText = async (options) => {
686
698
  metadata: options.metadata,
687
699
  modelId: resolved.modelId
688
700
  });
689
- return new BatchJob(adapter, credentials, snapshot);
701
+ return new BatchJob2(adapter, credentials, snapshot);
690
702
  };
691
703
  var submitEmbeddings = async (options) => {
692
704
  if (options.requests.length === 0) {
693
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
705
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
694
706
  }
695
- const resolved = resolveModel(options.model);
707
+ const resolved = resolveModel2(options.model);
696
708
  if (!EMBEDDING_PROVIDERS.has(resolved.provider)) {
697
709
  throw unsupportedEmbeddingProvider(resolved.provider);
698
710
  }
@@ -708,13 +720,13 @@ var submitEmbeddings = async (options) => {
708
720
  metadata: options.metadata,
709
721
  modelId: resolved.modelId
710
722
  });
711
- return new BatchJob(adapter, credentials, snapshot);
723
+ return new BatchJob2(adapter, credentials, snapshot);
712
724
  };
713
725
  var submitImages = async (options) => {
714
726
  if (options.requests.length === 0) {
715
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
727
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
716
728
  }
717
- const resolved = resolveModel(options.model);
729
+ const resolved = resolveModel2(options.model);
718
730
  if (!IMAGE_PROVIDERS.has(resolved.provider)) {
719
731
  throw unsupportedImageProvider(resolved.provider);
720
732
  }
@@ -730,13 +742,13 @@ var submitImages = async (options) => {
730
742
  metadata: options.metadata,
731
743
  modelId: resolved.modelId
732
744
  });
733
- return new BatchJob(adapter, credentials, snapshot);
745
+ return new BatchJob2(adapter, credentials, snapshot);
734
746
  };
735
747
  var submitImageEdits = async (options) => {
736
748
  if (options.requests.length === 0) {
737
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
749
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
738
750
  }
739
- const resolved = resolveModel(options.model);
751
+ const resolved = resolveModel2(options.model);
740
752
  if (!IMAGE_EDIT_PROVIDERS.has(resolved.provider)) {
741
753
  throw unsupportedImageEditProvider(resolved.provider);
742
754
  }
@@ -752,13 +764,13 @@ var submitImageEdits = async (options) => {
752
764
  metadata: options.metadata,
753
765
  modelId: resolved.modelId
754
766
  });
755
- return new BatchJob(adapter, credentials, snapshot);
767
+ return new BatchJob2(adapter, credentials, snapshot);
756
768
  };
757
769
  var submitModerations = async (options) => {
758
770
  if (options.requests.length === 0) {
759
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
771
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
760
772
  }
761
- const resolved = resolveModel(options.model);
773
+ const resolved = resolveModel2(options.model);
762
774
  if (!MODERATION_PROVIDERS.has(resolved.provider)) {
763
775
  throw unsupportedModerationProvider(resolved.provider);
764
776
  }
@@ -774,13 +786,13 @@ var submitModerations = async (options) => {
774
786
  metadata: options.metadata,
775
787
  modelId: resolved.modelId
776
788
  });
777
- return new BatchJob(adapter, credentials, snapshot);
789
+ return new BatchJob2(adapter, credentials, snapshot);
778
790
  };
779
791
  var submitTranscriptions = async (options) => {
780
792
  if (options.requests.length === 0) {
781
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
793
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
782
794
  }
783
- const resolved = resolveModel(options.model);
795
+ const resolved = resolveModel2(options.model);
784
796
  if (!TRANSCRIPTION_PROVIDERS.has(resolved.provider)) {
785
797
  throw unsupportedTranscriptionProvider(resolved.provider);
786
798
  }
@@ -796,13 +808,13 @@ var submitTranscriptions = async (options) => {
796
808
  metadata: options.metadata,
797
809
  modelId: resolved.modelId
798
810
  });
799
- return new BatchJob(adapter, credentials, snapshot);
811
+ return new BatchJob2(adapter, credentials, snapshot);
800
812
  };
801
813
  var submitVideos = async (options) => {
802
814
  if (options.requests.length === 0) {
803
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
815
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
804
816
  }
805
- const resolved = resolveModel(options.model);
817
+ const resolved = resolveModel2(options.model);
806
818
  if (!VIDEO_PROVIDERS.has(resolved.provider)) {
807
819
  throw unsupportedVideoProvider(resolved.provider);
808
820
  }
@@ -818,13 +830,13 @@ var submitVideos = async (options) => {
818
830
  metadata: options.metadata,
819
831
  modelId: resolved.modelId
820
832
  });
821
- return new BatchJob(adapter, credentials, snapshot);
833
+ return new BatchJob2(adapter, credentials, snapshot);
822
834
  };
823
835
  var submitTranslations = async (options) => {
824
836
  if (options.requests.length === 0) {
825
- throw new BatchworkError(EMPTY_REQUESTS_MESSAGE);
837
+ throw new BatchworkError2(EMPTY_REQUESTS_MESSAGE);
826
838
  }
827
- const resolved = resolveModel(options.model);
839
+ const resolved = resolveModel2(options.model);
828
840
  if (!TRANSLATION_PROVIDERS.has(resolved.provider)) {
829
841
  throw unsupportedTranslationProvider(resolved.provider);
830
842
  }
@@ -840,9 +852,9 @@ var submitTranslations = async (options) => {
840
852
  metadata: options.metadata,
841
853
  modelId: resolved.modelId
842
854
  });
843
- return new BatchJob(adapter, credentials, snapshot);
855
+ return new BatchJob2(adapter, credentials, snapshot);
844
856
  };
845
- var batch = Object.assign(submitText, {
857
+ var batch2 = Object.assign(submitText, {
846
858
  embeddings: submitEmbeddings,
847
859
  images: Object.assign(submitImages, {
848
860
  create: submitImages,
@@ -854,24 +866,24 @@ var batch = Object.assign(submitText, {
854
866
  translations: submitTranslations,
855
867
  videos: submitVideos
856
868
  });
857
- var batchEmbeddings = submitEmbeddings;
858
- var batchImages = submitImages;
859
- var getBatch = async (ref) => {
869
+ var batchEmbeddings2 = submitEmbeddings;
870
+ var batchImages2 = submitImages;
871
+ var getBatch2 = async (ref) => {
860
872
  const adapter = getAdapter(providerFromRef(ref));
861
873
  const credentials = pickCredentials(ref);
862
874
  const snapshot = await adapter.retrieve(ref.id, credentials);
863
- return new BatchJob(adapter, credentials, snapshot);
875
+ return new BatchJob2(adapter, credentials, snapshot);
864
876
  };
865
- var getBatchResults = (ref) => {
877
+ var getBatchResults2 = (ref) => {
866
878
  const adapter = getAdapter(providerFromRef(ref));
867
879
  return adapter.results(ref.id, pickCredentials(ref));
868
880
  };
869
- var cancelBatch = async (ref) => {
881
+ var cancelBatch2 = async (ref) => {
870
882
  const adapter = getAdapter(providerFromRef(ref));
871
883
  await adapter.cancel(ref.id, pickCredentials(ref));
872
884
  };
873
885
 
874
- export { resolveModel, batch, batchEmbeddings, batchImages, getBatch, getBatchResults, cancelBatch };
886
+ export { resolveModel2, batch2, batchEmbeddings2, batchImages2, getBatch2, getBatchResults2, cancelBatch2 };
875
887
 
876
- //# debugId=BF4E08ACD1170D0064756E2164756E21
877
- //# sourceMappingURL=chunk-14qcscwd.js.map
888
+ //# debugId=555DA8E4F0C86CA964756E2164756E21
889
+ //# sourceMappingURL=chunk-zss8h417.js.map