batchwork 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -6
- package/dist/batch.d.ts +179 -9
- package/dist/batch.d.ts.map +1 -1
- package/dist/body.d.ts +30 -1
- package/dist/body.d.ts.map +1 -1
- package/dist/{chunk-3yqs6x71.js → chunk-9cwfwzm4.js} +40 -10
- package/dist/{chunk-3yqs6x71.js.map → chunk-9cwfwzm4.js.map} +3 -3
- package/dist/{chunk-h2he3d16.js → chunk-gwa0dkhj.js} +139 -26
- package/dist/chunk-gwa0dkhj.js.map +27 -0
- package/dist/{chunk-bjkbtj1q.js → chunk-qqz5h9v6.js} +337 -14
- package/dist/chunk-qqz5h9v6.js.map +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/job.d.ts.map +1 -1
- package/dist/model.d.ts +50 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/next/index.d.ts +4 -3
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +11 -15
- package/dist/next/index.js.map +3 -3
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/mistral.d.ts.map +1 -1
- package/dist/providers/openai-compatible.d.ts +5 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -1
- package/dist/providers/shared.d.ts +16 -1
- package/dist/providers/shared.d.ts.map +1 -1
- package/dist/providers/together.d.ts.map +1 -1
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/poller.d.ts.map +1 -1
- package/dist/types.d.ts +209 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -15
- package/dist/chunk-bjkbtj1q.js.map +0 -12
- package/dist/chunk-h2he3d16.js.map +0 -27
package/dist/index.js
CHANGED
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
getBatch,
|
|
7
7
|
getBatchResults,
|
|
8
8
|
resolveModel
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-qqz5h9v6.js";
|
|
10
10
|
import {
|
|
11
11
|
BatchJob,
|
|
12
12
|
BatchworkError,
|
|
13
13
|
MissingDependencyError,
|
|
14
14
|
UnsupportedProviderError,
|
|
15
15
|
isTerminalStatus
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-gwa0dkhj.js";
|
|
17
17
|
import"./chunk-v0bahtg2.js";
|
|
18
18
|
export {
|
|
19
19
|
resolveModel,
|
package/dist/job.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,WAAW,EACZ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,WAAW,EACZ,MAAM,SAAS,CAAC;AAYjB,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,WAAY,WAAW,KAAG,OACxB,CAAC;AAwBhC;;;GAGG;AACH,qBAAa,QAAQ;;IACnB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAMpB,YACE,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,mBAAmB,EAChC,QAAQ,EAAE,aAAa,EAOxB;IAED,yCAAyC;IACzC,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,sDAAsD;IACtD,IAAI,aAAa,IAAI,kBAAkB,CAEtC;IAED,2CAA2C;IAC3C,IAAI,QAAQ,IAAI,aAAa,CAE5B;IAED,wEAAwE;IAClE,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CAGnC;IAED,gFAAgF;IAC1E,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CA0B5D;IAED,2EAA2E;IAC3E,OAAO,IAAI,cAAc,CAAC,WAAW,CAAC,CAErC;IAED,8DAA8D;IACxD,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAMtC;IAED,iDAAiD;IAC3C,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,CAGrC;CACF"}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { EmbeddingModel, ImageModel, LanguageModel } from "ai";
|
|
1
|
+
import type { EmbeddingModel, ImageModel, LanguageModel, TranscriptionModel } from "ai";
|
|
2
2
|
import { UnsupportedProviderError } from "./errors";
|
|
3
|
-
import type { BatchProvider, ProviderCredentials } from "./types";
|
|
3
|
+
import type { BatchProvider, ProviderCredentials, VideoModel } from "./types";
|
|
4
4
|
/** A fetch implementation compatible with the AI SDK provider `fetch` option. */
|
|
5
5
|
export type CapturingFetch = typeof globalThis.fetch;
|
|
6
6
|
/** OpenAI exposes several request shapes; we mirror the one the model implies. */
|
|
@@ -17,7 +17,7 @@ export interface ResolvedModel {
|
|
|
17
17
|
* shape. Gateway/registry model objects whose `modelId` is itself
|
|
18
18
|
* `"provider/model"` are also handled.
|
|
19
19
|
*/
|
|
20
|
-
export declare const resolveModel: (model: LanguageModel | EmbeddingModel | ImageModel) => ResolvedModel;
|
|
20
|
+
export declare const resolveModel: (model: LanguageModel | EmbeddingModel | ImageModel | TranscriptionModel | VideoModel) => ResolvedModel;
|
|
21
21
|
/**
|
|
22
22
|
* Import the `@ai-sdk/*` package for a provider, translating a missing optional
|
|
23
23
|
* dependency into a `MissingDependencyError`. The importer is injectable (like
|
|
@@ -43,6 +43,53 @@ export declare const unsupportedEmbeddingProvider: (provider: BatchProvider) =>
|
|
|
43
43
|
* a network call. Throws for providers without an embedding model.
|
|
44
44
|
*/
|
|
45
45
|
export declare const createCaptureEmbeddingModel: (resolved: ResolvedModel, credentials: ProviderCredentials, fetchImpl: CapturingFetch) => Promise<EmbeddingModel>;
|
|
46
|
+
/**
|
|
47
|
+
* Providers whose batch API accepts image editing. OpenAI and xAI both expose
|
|
48
|
+
* `/v1/images/edits` as a batch endpoint (JSON bodies with asset references —
|
|
49
|
+
* OpenAI takes uploaded file ids or image URLs plus an optional mask; xAI
|
|
50
|
+
* takes image URLs only). Google's Gemini batch has no edit endpoint.
|
|
51
|
+
*/
|
|
52
|
+
export declare const IMAGE_EDIT_PROVIDERS: Set<BatchProvider>;
|
|
53
|
+
export declare const unsupportedImageEditProvider: (provider: BatchProvider) => UnsupportedProviderError;
|
|
54
|
+
/**
|
|
55
|
+
* Providers whose batch API accepts video generation. xAI exposes
|
|
56
|
+
* `/v1/videos/generations` (plus `/edits` and `/extensions`) as batch
|
|
57
|
+
* endpoints for Grok Imagine. OpenAI's Videos API (Sora) is deprecated and
|
|
58
|
+
* shuts down 2026-09-24, so it is deliberately not supported; Google's Veo
|
|
59
|
+
* models are not batch-compatible.
|
|
60
|
+
*/
|
|
61
|
+
export declare const VIDEO_PROVIDERS: Set<BatchProvider>;
|
|
62
|
+
export declare const unsupportedVideoProvider: (provider: BatchProvider) => UnsupportedProviderError;
|
|
63
|
+
/**
|
|
64
|
+
* Construct an AI SDK video model wired to a capturing `fetch`, used to derive
|
|
65
|
+
* the provider video request body for each batch item without making a network
|
|
66
|
+
* call. Throws for providers without batch video support.
|
|
67
|
+
*/
|
|
68
|
+
export declare const createCaptureVideoModel: (resolved: ResolvedModel, credentials: ProviderCredentials, fetchImpl: CapturingFetch) => Promise<VideoModel>;
|
|
69
|
+
/**
|
|
70
|
+
* Providers whose batch API accepts audio translation (Whisper's
|
|
71
|
+
* translate-to-English task). Groq and Together expose
|
|
72
|
+
* `/v1/audio/translations` as a batch endpoint; Mistral batches
|
|
73
|
+
* transcriptions but not translations.
|
|
74
|
+
*/
|
|
75
|
+
export declare const TRANSLATION_PROVIDERS: Set<BatchProvider>;
|
|
76
|
+
export declare const unsupportedTranslationProvider: (provider: BatchProvider) => UnsupportedProviderError;
|
|
77
|
+
/**
|
|
78
|
+
* Providers whose batch API accepts moderation. OpenAI exposes
|
|
79
|
+
* `/v1/moderations` as a batch endpoint (omni moderation, text + images);
|
|
80
|
+
* Mistral runs its moderation models through the same batch job flow
|
|
81
|
+
* (text-only). No other provider has a standalone moderation API.
|
|
82
|
+
*/
|
|
83
|
+
export declare const MODERATION_PROVIDERS: Set<BatchProvider>;
|
|
84
|
+
export declare const unsupportedModerationProvider: (provider: BatchProvider) => UnsupportedProviderError;
|
|
85
|
+
/**
|
|
86
|
+
* Providers whose batch API accepts audio transcription. Groq, Mistral, and
|
|
87
|
+
* Together expose `/v1/audio/transcriptions` as a batch endpoint; OpenAI's
|
|
88
|
+
* batch API does not accept audio endpoints, and the remaining providers have
|
|
89
|
+
* no standalone transcription API.
|
|
90
|
+
*/
|
|
91
|
+
export declare const TRANSCRIPTION_PROVIDERS: Set<BatchProvider>;
|
|
92
|
+
export declare const unsupportedTranscriptionProvider: (provider: BatchProvider) => UnsupportedProviderError;
|
|
46
93
|
/**
|
|
47
94
|
* Providers whose batch API accepts image generation. OpenAI and xAI expose
|
|
48
95
|
* `/v1/images/generations` as a batch endpoint; Google runs Gemini image models
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,cAAc,EACd,UAA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;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,oBAAkC,CAAC;AAE/D,eAAO,MAAM,wBAAwB,aACzB,aAAa,KACtB,wBAIA,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,aACxB,aAAa,eACV,mBAAmB,aACrB,cAAc,KACxB,OAAO,CAAC,UAAU,CAWpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,oBAGhC,CAAC;AAEH,eAAO,MAAM,8BAA8B,aAC/B,aAAa,KACtB,wBAIA,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,oBAG/B,CAAC;AAEH,eAAO,MAAM,6BAA6B,aAC9B,aAAa,KACtB,wBAIA,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,oBAIlC,CAAC;AAEH,eAAO,MAAM,gCAAgC,aACjC,aAAa,KACtB,wBAIA,CAAC;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,oBAI1B,CAAC;AAEH,eAAO,MAAM,wBAAwB,aACzB,aAAa,KACtB,wBAIA,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,aACxB,aAAa,eACV,mBAAmB,aACrB,cAAc,KACxB,OAAO,CAAC,UAAU,CA0BpB,CAAC"}
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { CredentialResolver, TrackTarget } from "../server/poller";
|
|
2
|
-
import { createMemoryStore } from "../server/store";
|
|
3
2
|
import type { BatchStore, BatchWebhookEvent, TrackedBatch } from "../server/types";
|
|
4
3
|
import type { BatchResult } from "../types";
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
4
|
+
export type { TrackTarget } from "../server/poller";
|
|
5
|
+
export { createMemoryStore } from "../server/store";
|
|
6
|
+
export type { BatchStore, BatchWebhookEvent, TrackedBatch, } from "../server/types";
|
|
7
|
+
export type { BatchResult } from "../types";
|
|
7
8
|
/**
|
|
8
9
|
* Invoked once per batch when it reaches a terminal status. Persist the results
|
|
9
10
|
* to your database here. `results` streams the parsed result lines for a
|
package/dist/next/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAiB,WAAW,EAAuB,MAAM,UAAU,CAAC;AAEhF,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,KAChC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,UAAU,CAAC;IAClB,6DAA6D;IAC7D,UAAU,EAAE,eAAe,CAAC;IAC5B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,mEAAmE;IACnE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,6EAA6E;IAC7E,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D;AAED,MAAM,WAAW,WAAW;IAC1B,wEAAwE;IACxE,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,8EAA8E;IAC9E,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/C,4EAA4E;IAC5E,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CACvD;AAQD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,YAAa,kBAAkB,KAAG,WAuD/D,CAAC"}
|
package/dist/next/index.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getBatchResults
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-qqz5h9v6.js";
|
|
4
4
|
import {
|
|
5
5
|
createBatchPoller,
|
|
6
6
|
createMemoryStore,
|
|
7
7
|
toEvent
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import"../chunk-
|
|
8
|
+
} from "../chunk-9cwfwzm4.js";
|
|
9
|
+
import"../chunk-gwa0dkhj.js";
|
|
10
10
|
import"../chunk-v0bahtg2.js";
|
|
11
11
|
|
|
12
12
|
// src/next/index.ts
|
|
13
|
-
|
|
14
|
-
[Symbol.asyncIterator]: () => ({
|
|
15
|
-
next: () => Promise.resolve({ done: true, value: undefined })
|
|
16
|
-
})
|
|
17
|
-
};
|
|
13
|
+
async function* emptyResults() {}
|
|
18
14
|
var createBatchRoutes = (options) => {
|
|
19
15
|
const resolveCredentials = (provider) => {
|
|
20
16
|
if (typeof options.credentials === "function") {
|
|
@@ -28,7 +24,7 @@ var createBatchRoutes = (options) => {
|
|
|
28
24
|
id: record.id,
|
|
29
25
|
provider: record.provider,
|
|
30
26
|
...resolveCredentials(record.provider)
|
|
31
|
-
}) :
|
|
27
|
+
}) : emptyResults();
|
|
32
28
|
await options.onComplete(event, results);
|
|
33
29
|
};
|
|
34
30
|
const poller = createBatchPoller({
|
|
@@ -37,17 +33,17 @@ var createBatchRoutes = (options) => {
|
|
|
37
33
|
onError: (record, error) => options.onError?.(record, error),
|
|
38
34
|
store: options.store
|
|
39
35
|
});
|
|
40
|
-
const
|
|
36
|
+
const handleCronTick = async (request) => {
|
|
41
37
|
if (!(options.cronSecret || options.allowUnauthenticatedCron)) {
|
|
42
|
-
return
|
|
38
|
+
return new Response("unauthorized", { status: 401 });
|
|
43
39
|
}
|
|
44
40
|
if (options.cronSecret && request.headers.get("authorization") !== `Bearer ${options.cronSecret}`) {
|
|
45
|
-
return
|
|
41
|
+
return new Response("unauthorized", { status: 401 });
|
|
46
42
|
}
|
|
47
|
-
return
|
|
43
|
+
return Response.json(await poller.tick());
|
|
48
44
|
};
|
|
49
45
|
const track = (target) => poller.track(target, {});
|
|
50
|
-
const routes = { GET, track };
|
|
46
|
+
const routes = { GET: handleCronTick, track };
|
|
51
47
|
if (options.openaiSigningSecret) {
|
|
52
48
|
routes.POST = poller.openaiWebhookHandler({
|
|
53
49
|
signingSecret: options.openaiSigningSecret
|
|
@@ -60,5 +56,5 @@ export {
|
|
|
60
56
|
createBatchRoutes
|
|
61
57
|
};
|
|
62
58
|
|
|
63
|
-
//# debugId=
|
|
59
|
+
//# debugId=50B909DB46860B1964756E2164756E21
|
|
64
60
|
//# sourceMappingURL=index.js.map
|
package/dist/next/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/next/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { getBatchResults } from \"../batch\";\nimport { toEvent } from \"../server/events\";\nimport { createBatchPoller } from \"../server/poller\";\nimport type {\n CompletionSink,\n CredentialResolver,\n TrackTarget,\n} from \"../server/poller\";\nimport
|
|
5
|
+
"import { getBatchResults } from \"../batch\";\nimport { toEvent } from \"../server/events\";\nimport { createBatchPoller } from \"../server/poller\";\nimport type {\n CompletionSink,\n CredentialResolver,\n TrackTarget,\n} from \"../server/poller\";\nimport type {\n BatchStore,\n BatchWebhookEvent,\n TrackedBatch,\n} from \"../server/types\";\nimport type { BatchProvider, BatchResult, ProviderCredentials } from \"../types\";\n\nexport type { TrackTarget } from \"../server/poller\";\nexport { createMemoryStore } from \"../server/store\";\nexport type {\n BatchStore,\n BatchWebhookEvent,\n TrackedBatch,\n} from \"../server/types\";\nexport type { BatchResult } from \"../types\";\n\n/**\n * Invoked once per batch when it reaches a terminal status. Persist the results\n * to your database here. `results` streams the parsed result lines for a\n * completed batch and is empty for failure events (`batch.failed` /\n * `batch.expired` / `batch.cancelled`) — inspect `event.type`.\n *\n * May fire more than once for the same batch (a cron tick racing the OpenAI\n * native webhook, or a retry after a partial save), so make persistence\n * idempotent — upsert keyed by `(provider, batchId, customId)`.\n */\nexport type OnBatchComplete = (\n event: BatchWebhookEvent,\n results: AsyncIterable<BatchResult>\n) => void | Promise<void>;\n\nexport interface BatchRoutesOptions {\n store: BatchStore;\n /** Called when each batch finishes; persist results here. */\n onComplete: OnBatchComplete;\n /** Falls back to provider env vars (e.g. `OPENAI_API_KEY`) when omitted. */\n credentials?: CredentialResolver;\n /** Requires `Authorization: Bearer <cronSecret>` on the cron `GET`. */\n cronSecret?: string;\n /** Allow unauthenticated cron ticks. Intended only for private/local routes. */\n allowUnauthenticatedCron?: boolean;\n /** When set, mounts an OpenAI native-webhook handler on `POST`. */\n openaiSigningSecret?: string;\n /** Observe per-batch processing errors during a tick; the tick continues. */\n onError?: (record: TrackedBatch, error: unknown) => void;\n}\n\nexport interface BatchRoutes {\n /** Cron-triggered poll tick. Wire to Vercel Cron (or any scheduler). */\n GET: (request: Request) => Promise<Response>;\n /** OpenAI native-webhook handler. Present only with `openaiSigningSecret`. */\n POST?: (request: Request) => Promise<Response>;\n /** Register a submitted batch so the cron polls it (a `BatchJob` works). */\n track: (target: TrackTarget) => Promise<TrackedBatch>;\n}\n\n/** An already-exhausted result stream, for non-completed events. */\n// oxlint-disable-next-line func-style, require-yield -- generators cannot be arrow functions; this one is intentionally empty.\nasync function* emptyResults(): AsyncGenerator<BatchResult> {\n // Failure events carry no results.\n}\n\n/**\n * Build Next.js App Router route handlers that poll your in-flight batches on a\n * cron tick and invoke `onComplete` directly when each finishes — persist\n * results to your DB without round-tripping an HTTP webhook back to your app.\n *\n * @example\n * import { createBatchRoutes, createMemoryStore } from \"batchwork/next\";\n *\n * export const { GET, POST } = createBatchRoutes({\n * store: createMemoryStore(),\n * cronSecret: process.env.CRON_SECRET,\n * openaiSigningSecret: process.env.OPENAI_WEBHOOK_SECRET,\n * onComplete: async (event, results) => {\n * for await (const r of results) {\n * await db.insert({ id: r.customId, status: r.status, text: r.text });\n * }\n * },\n * });\n */\nexport const createBatchRoutes = (options: BatchRoutesOptions): BatchRoutes => {\n const resolveCredentials = (provider: BatchProvider): ProviderCredentials => {\n if (typeof options.credentials === \"function\") {\n return options.credentials(provider);\n }\n return options.credentials ?? {};\n };\n\n const sink: CompletionSink = async (record, snapshot) => {\n const event = toEvent(record.provider, snapshot);\n // Only completed batches have results to fetch — the adapter throws when a\n // terminal batch has no output/error file (failed/expired/cancelled).\n const results =\n event.type === \"batch.completed\"\n ? getBatchResults({\n id: record.id,\n provider: record.provider,\n ...resolveCredentials(record.provider),\n })\n : emptyResults();\n await options.onComplete(event, results);\n };\n\n const poller = createBatchPoller({\n credentials: options.credentials,\n onComplete: sink,\n // Always supply an `onError` so one failing batch can't abort the whole\n // tick; forward to the caller's handler when they provided one.\n onError: (record, error) => options.onError?.(record, error),\n store: options.store,\n });\n\n const handleCronTick = async (request: Request): Promise<Response> => {\n if (!(options.cronSecret || options.allowUnauthenticatedCron)) {\n return new Response(\"unauthorized\", { status: 401 });\n }\n if (\n options.cronSecret &&\n request.headers.get(\"authorization\") !== `Bearer ${options.cronSecret}`\n ) {\n return new Response(\"unauthorized\", { status: 401 });\n }\n return Response.json(await poller.tick());\n };\n\n const track = (target: TrackTarget): Promise<TrackedBatch> =>\n poller.track(target, {});\n\n const routes: BatchRoutes = { GET: handleCronTick, track };\n if (options.openaiSigningSecret) {\n routes.POST = poller.openaiWebhookHandler({\n signingSecret: options.openaiSigningSecret,\n });\n }\n return routes;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;AAkEA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;AAkEA,gBAAgB,YAAY,GAAgC;AAuBrD,IAAM,oBAAoB,CAAC,YAA6C;AAAA,EAC7E,MAAM,qBAAqB,CAAC,aAAiD;AAAA,IAC3E,IAAI,OAAO,QAAQ,gBAAgB,YAAY;AAAA,MAC7C,OAAO,QAAQ,YAAY,QAAQ;AAAA,IACrC;AAAA,IACA,OAAO,QAAQ,eAAe,CAAC;AAAA;AAAA,EAGjC,MAAM,OAAuB,OAAO,QAAQ,aAAa;AAAA,IACvD,MAAM,QAAQ,QAAQ,OAAO,UAAU,QAAQ;AAAA,IAG/C,MAAM,UACJ,MAAM,SAAS,oBACX,gBAAgB;AAAA,MACd,IAAI,OAAO;AAAA,MACX,UAAU,OAAO;AAAA,SACd,mBAAmB,OAAO,QAAQ;AAAA,IACvC,CAAC,IACD,aAAa;AAAA,IACnB,MAAM,QAAQ,WAAW,OAAO,OAAO;AAAA;AAAA,EAGzC,MAAM,SAAS,kBAAkB;AAAA,IAC/B,aAAa,QAAQ;AAAA,IACrB,YAAY;AAAA,IAGZ,SAAS,CAAC,QAAQ,UAAU,QAAQ,UAAU,QAAQ,KAAK;AAAA,IAC3D,OAAO,QAAQ;AAAA,EACjB,CAAC;AAAA,EAED,MAAM,iBAAiB,OAAO,YAAwC;AAAA,IACpE,IAAI,EAAE,QAAQ,cAAc,QAAQ,2BAA2B;AAAA,MAC7D,OAAO,IAAI,SAAS,gBAAgB,EAAE,QAAQ,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,IACE,QAAQ,cACR,QAAQ,QAAQ,IAAI,eAAe,MAAM,UAAU,QAAQ,cAC3D;AAAA,MACA,OAAO,IAAI,SAAS,gBAAgB,EAAE,QAAQ,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,OAAO,SAAS,KAAK,MAAM,OAAO,KAAK,CAAC;AAAA;AAAA,EAG1C,MAAM,QAAQ,CAAC,WACb,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,EAEzB,MAAM,SAAsB,EAAE,KAAK,gBAAgB,MAAM;AAAA,EACzD,IAAI,QAAQ,qBAAqB;AAAA,IAC/B,OAAO,OAAO,OAAO,qBAAqB;AAAA,MACxC,eAAe,QAAQ;AAAA,IACzB,CAAC;AAAA,EACH;AAAA,EACA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "50B909DB46860B1964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAiO3D,eAAO,MAAM,gBAAgB,EAAE,YAM9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAgT3D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,YAM3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../src/providers/mistral.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../src/providers/mistral.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAuJ3D;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,YAM5B,CAAC"}
|
|
@@ -30,6 +30,11 @@ export interface OpenAICompatibleConfig {
|
|
|
30
30
|
* (OpenAI, Groq); `body-only` writes `{ custom_id, body }` (Together).
|
|
31
31
|
*/
|
|
32
32
|
lineFormat?: BatchLineFormat;
|
|
33
|
+
/**
|
|
34
|
+
* Extra fields merged into each `body-only` line for a given endpoint
|
|
35
|
+
* (e.g. Together audio lines require `method: "FILE"`).
|
|
36
|
+
*/
|
|
37
|
+
lineExtras?: (endpoint: string) => Record<string, unknown> | undefined;
|
|
33
38
|
/**
|
|
34
39
|
* Map the captured endpoint path to the value the provider expects in the
|
|
35
40
|
* batch `url`/`endpoint` field (e.g. Groq serves under `/openai/v1` but its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-compatible.d.ts","sourceRoot":"","sources":["../../src/providers/openai-compatible.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,aAAa,EAKd,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAK3D,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,YAAY,CAAC;AAEzD,MAAM,WA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B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACvE;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD;AAgDD,eAAO,MAAM,6BAA6B,WAChC,sBAAsB,KAC7B,YAmHF,CAAC"}
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* JSONL keyed by `custom_id`, and shape each result line like OpenAI's
|
|
5
5
|
* (`{ custom_id, response: { status_code, body }, error }`).
|
|
6
6
|
*/
|
|
7
|
-
import type { BatchImage, BatchResult, BatchUsage, ProviderCredentials } from "../types";
|
|
7
|
+
import type { BatchImage, BatchModeration, BatchResult, BatchTranscriptionSegment, BatchUsage, ProviderCredentials } from "../types";
|
|
8
8
|
/** Resolve an API key from credentials or the provider's env var, or throw. */
|
|
9
9
|
export declare const resolveApiKey: (credentials: ProviderCredentials, envVar: string, label: string) => string;
|
|
10
10
|
export declare const textFromBody: (body: unknown) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Read timestamped segments from a transcription-shaped response body
|
|
13
|
+
* (`{ text, segments: [{ text, start, end }] }`, Groq `verbose_json` and
|
|
14
|
+
* Mistral alike). Returns undefined when the body carries no segments, so
|
|
15
|
+
* chat/embedding/image results are unaffected.
|
|
16
|
+
*/
|
|
17
|
+
export declare const segmentsFromBody: (body: unknown) => BatchTranscriptionSegment[] | undefined;
|
|
11
18
|
/** Read the embedding vector from an OpenAI-shaped embeddings response body. */
|
|
12
19
|
export declare const embeddingFromBody: (body: unknown) => number[] | undefined;
|
|
13
20
|
/**
|
|
@@ -16,6 +23,14 @@ export declare const embeddingFromBody: (body: unknown) => number[] | undefined;
|
|
|
16
23
|
* carries no image data, so chat/embedding results are unaffected.
|
|
17
24
|
*/
|
|
18
25
|
export declare const imagesFromBody: (body: unknown) => BatchImage[] | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Read the verdict from a moderation-shaped response body
|
|
28
|
+
* (`{ results: [{ flagged?, categories, category_scores }] }`, OpenAI and
|
|
29
|
+
* Mistral alike). Mistral reports no `flagged`, so it falls back to "any
|
|
30
|
+
* category flagged". Returns undefined when the body carries no categories, so
|
|
31
|
+
* other result shapes are unaffected.
|
|
32
|
+
*/
|
|
33
|
+
export declare const moderationFromBody: (body: unknown) => BatchModeration | undefined;
|
|
19
34
|
export declare const usageFromBody: (body: unknown) => BatchUsage | undefined;
|
|
20
35
|
/** Normalize an OpenAI-shaped result line into a {@link BatchResult}. */
|
|
21
36
|
export declare const normalizeOpenAIResult: (line: unknown) => BatchResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/providers/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EAEX,UAAU,EACV,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAMlB,+EAA+E;AAC/E,eAAO,MAAM,aAAa,gBACX,mBAAmB,UACxB,MAAM,SACP,MAAM,KACZ,MAQF,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,OAAO,KAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/providers/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,WAAW,EAEX,yBAAyB,EACzB,UAAU,EACV,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAMlB,+EAA+E;AAC/E,eAAO,MAAM,aAAa,gBACX,mBAAmB,UACxB,MAAM,SACP,MAAM,KACZ,MAQF,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,OAAO,KAAG,MAAM,GAAG,SAWrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,SACrB,OAAO,KACZ,yBAAyB,EAAE,GAAG,SAkBhC,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,SAAU,OAAO,KAAG,MAAM,EAAE,GAAG,SAM5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,SAAU,OAAO,KAAG,UAAU,EAAE,GAAG,SAW7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,SACvB,OAAO,KACZ,eAAe,GAAG,SA2BpB,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,OAAO,KAAG,UAAU,GAAG,SAmB1D,CAAC;AAaF,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,SAAU,OAAO,KAAG,WAsCrD,CAAC;AAGF,eAAO,MAAM,eAAe,UACnB,MAAM,WACJ,MAAM,WACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YACtB;IAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,KACnC,OAAO,CAAC,MAAM,CAkBhB,CAAC;AAEF;;;;GAIG;AAEH,wBAAuB,gBAAgB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,cAAc,CAAC,WAAW,CAAC,CAQ7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../src/providers/together.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../src/providers/together.ts"],"names":[],"mappings":"AAiKA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,kCAY1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAsP3D;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,YAMxB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../src/server/poller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAGlB,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAExD,6EAA6E;AAC7E,MAAM,MAAM,kBAAkB,GAC1B,mBAAmB,GACnB,CAAC,CAAC,QAAQ,EAAE,aAAa,KAAK,mBAAmB,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,aAAa,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,UAAU,CAAC;IAClB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,8DAA8D;IAC9D,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,6EAA6E;IAC7E,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY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MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7E,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,oBAAoB,EAAE,CACpB,OAAO,EAAE,oBAAoB,KAC1B,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC9C;AAqLD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,YAAa,kBAAkB,KAAG,WAiI/D,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type { EmbeddingModel, ImageModel, JSONValue, LanguageModel, ModelMessage, ToolChoice, ToolSet } from "ai";
|
|
1
|
+
import type { EmbeddingModel, experimental_generateVideo, ImageModel, JSONValue, LanguageModel, ModelMessage, ToolChoice, ToolSet, TranscriptionModel } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* The `model` argument of the AI SDK's `experimental_generateVideo` — a video
|
|
4
|
+
* model object or a `"provider/model"` string. Derived from the function
|
|
5
|
+
* signature because the AI SDK does not export a video model type yet.
|
|
6
|
+
*/
|
|
7
|
+
export type VideoModel = Parameters<typeof experimental_generateVideo>[0]["model"];
|
|
2
8
|
/** Providers with a batch adapter. */
|
|
3
9
|
export type BatchProvider = "anthropic" | "google" | "groq" | "mistral" | "openai" | "together" | "xai";
|
|
4
10
|
/**
|
|
@@ -65,8 +71,8 @@ export interface BatchImage {
|
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
67
73
|
* A single image-generation request within a batch. One `prompt` produces one
|
|
68
|
-
* or more images, correlated to its result by `customId`.
|
|
69
|
-
* image
|
|
74
|
+
* or more images, correlated to its result by `customId`. For editing an
|
|
75
|
+
* existing image, use `batch.images.edit` with a {@link BatchImageEditRequest}.
|
|
70
76
|
*/
|
|
71
77
|
export interface BatchImageRequest {
|
|
72
78
|
/** Aspect ratio, `"{width}:{height}"` (e.g. Gemini image models). */
|
|
@@ -86,6 +92,143 @@ export interface BatchImageRequest {
|
|
|
86
92
|
}
|
|
87
93
|
/** Defaults merged into every image request; request-level values take precedence. */
|
|
88
94
|
export type BatchImageDefaults = Partial<Omit<BatchImageRequest, "customId" | "prompt">>;
|
|
95
|
+
/**
|
|
96
|
+
* Reference to an input image asset: an already-uploaded provider file id
|
|
97
|
+
* (OpenAI Files API), or a hosted image URL (data URIs also work). Batch
|
|
98
|
+
* requests are JSON, so raw image uploads aren't possible — stage assets ahead
|
|
99
|
+
* of time.
|
|
100
|
+
*/
|
|
101
|
+
export type BatchImageRef = {
|
|
102
|
+
fileId: string;
|
|
103
|
+
} | {
|
|
104
|
+
imageUrl: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* A single image-edit request within a batch. One `prompt` applied to one or
|
|
108
|
+
* more source `images` produces one or more edited images, correlated to its
|
|
109
|
+
* result by `customId`.
|
|
110
|
+
*/
|
|
111
|
+
export interface BatchImageEditRequest {
|
|
112
|
+
/** Correlates this request to its result. Auto-generated when omitted. */
|
|
113
|
+
customId?: string;
|
|
114
|
+
/** Source image(s) to edit. xAI accepts URL references only (no file ids). */
|
|
115
|
+
images: BatchImageRef[];
|
|
116
|
+
/**
|
|
117
|
+
* Mask whose transparent areas indicate where to edit (OpenAI only; xAI
|
|
118
|
+
* throws before submitting).
|
|
119
|
+
*/
|
|
120
|
+
mask?: BatchImageRef;
|
|
121
|
+
/** Number of edited images to generate. Defaults to 1. */
|
|
122
|
+
n?: number;
|
|
123
|
+
/** The text prompt describing the edit. */
|
|
124
|
+
prompt: string;
|
|
125
|
+
/** Forwarded to the provider edit call (e.g. `{ openai: { quality } }`). */
|
|
126
|
+
providerOptions?: ProviderOptions;
|
|
127
|
+
/** Output size, `"{width}x{height}"` (OpenAI; xAI uses `providerOptions`). */
|
|
128
|
+
size?: `${number}x${number}`;
|
|
129
|
+
}
|
|
130
|
+
/** Defaults merged into every image-edit request; request-level values win. */
|
|
131
|
+
export type BatchImageEditDefaults = Partial<Omit<BatchImageEditRequest, "customId" | "images" | "prompt">>;
|
|
132
|
+
/**
|
|
133
|
+
* A single audio-transcription request within a batch. Batch audio endpoints
|
|
134
|
+
* accept hosted audio only (no file uploads): the provider fetches `audioUrl`
|
|
135
|
+
* while processing, so the URL must stay reachable until the batch completes.
|
|
136
|
+
*/
|
|
137
|
+
export interface BatchTranscriptionRequest {
|
|
138
|
+
/** Publicly reachable URL of the audio file to transcribe. */
|
|
139
|
+
audioUrl: string;
|
|
140
|
+
/** Correlates this request to its result. Auto-generated when omitted. */
|
|
141
|
+
customId?: string;
|
|
142
|
+
/** Language of the audio, as an ISO-639-1 code (e.g. `"en"`). */
|
|
143
|
+
language?: string;
|
|
144
|
+
/** Merged into the provider request body (e.g. `{ groq: { prompt } }`). */
|
|
145
|
+
providerOptions?: ProviderOptions;
|
|
146
|
+
/** Timestamp detail to request; populates `segments` on the result. */
|
|
147
|
+
timestampGranularities?: ("segment" | "word")[];
|
|
148
|
+
}
|
|
149
|
+
/** Defaults merged into every transcription request; request-level values win. */
|
|
150
|
+
export type BatchTranscriptionDefaults = Partial<Omit<BatchTranscriptionRequest, "customId" | "audioUrl">>;
|
|
151
|
+
/** A timestamped span of a transcript. */
|
|
152
|
+
export interface BatchTranscriptionSegment {
|
|
153
|
+
endSecond?: number;
|
|
154
|
+
startSecond?: number;
|
|
155
|
+
text: string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A single audio-translation request within a batch: the audio at `audioUrl`
|
|
159
|
+
* is translated into English text (Whisper's translate task — English is the
|
|
160
|
+
* only target, so there is no language field). Same URL rules as
|
|
161
|
+
* {@link BatchTranscriptionRequest}.
|
|
162
|
+
*/
|
|
163
|
+
export type BatchTranslationRequest = Omit<BatchTranscriptionRequest, "language">;
|
|
164
|
+
/** Defaults merged into every translation request; request-level values win. */
|
|
165
|
+
export type BatchTranslationDefaults = Partial<Omit<BatchTranslationRequest, "customId" | "audioUrl">>;
|
|
166
|
+
/**
|
|
167
|
+
* A single video-generation request within a batch. One `prompt` produces one
|
|
168
|
+
* video, correlated to its result by `customId`. Editing and extending an
|
|
169
|
+
* existing video route through `providerOptions` (e.g. xAI's
|
|
170
|
+
* `{ xai: { videoUrl } }` for edits, `{ xai: { mode: "extend-video", videoUrl } }`
|
|
171
|
+
* to extend), mirroring the AI SDK's `generateVideo`.
|
|
172
|
+
*/
|
|
173
|
+
export interface BatchVideoRequest {
|
|
174
|
+
/** Aspect ratio, `"{width}:{height}"` (e.g. `"16:9"`). */
|
|
175
|
+
aspectRatio?: `${number}:${number}`;
|
|
176
|
+
/** Correlates this request to its result. Auto-generated when omitted. */
|
|
177
|
+
customId?: string;
|
|
178
|
+
/** Clip length in seconds, where the model supports it. */
|
|
179
|
+
duration?: number;
|
|
180
|
+
/** The text prompt describing the video to generate. */
|
|
181
|
+
prompt: string;
|
|
182
|
+
/** Forwarded to the provider video call (e.g. `{ xai: { videoUrl } }`). */
|
|
183
|
+
providerOptions?: ProviderOptions;
|
|
184
|
+
/** Resolution, `"{width}x{height}"` (e.g. `"1280x720"`). */
|
|
185
|
+
resolution?: `${number}x${number}`;
|
|
186
|
+
}
|
|
187
|
+
/** Defaults merged into every video request; request-level values take precedence. */
|
|
188
|
+
export type BatchVideoDefaults = Partial<Omit<BatchVideoRequest, "customId" | "prompt">>;
|
|
189
|
+
/**
|
|
190
|
+
* A generated video. Returned as a hosted `url` — xAI batch signs URLs that
|
|
191
|
+
* expire ~1h after completion, so download promptly.
|
|
192
|
+
*/
|
|
193
|
+
export interface BatchVideo {
|
|
194
|
+
/** Video length in seconds, when the provider reports it. */
|
|
195
|
+
durationSeconds?: number;
|
|
196
|
+
/** Hosted video URL. */
|
|
197
|
+
url?: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A single moderation request within a batch. Provide `value` (text),
|
|
201
|
+
* `imageUrls` (OpenAI omni moderation only), or both; each request produces
|
|
202
|
+
* one verdict, correlated by `customId`.
|
|
203
|
+
*/
|
|
204
|
+
export interface BatchModerationRequest {
|
|
205
|
+
/** Correlates this request to its result. Auto-generated when omitted. */
|
|
206
|
+
customId?: string;
|
|
207
|
+
/**
|
|
208
|
+
* Image URLs to moderate alongside (or instead of) `value`. Supported by
|
|
209
|
+
* OpenAI omni moderation models only; Mistral moderation is text-only.
|
|
210
|
+
*/
|
|
211
|
+
imageUrls?: string[];
|
|
212
|
+
/** Merged into the provider request body. */
|
|
213
|
+
providerOptions?: ProviderOptions;
|
|
214
|
+
/** The text to moderate. */
|
|
215
|
+
value?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A normalized moderation verdict. Category names are provider-native (e.g.
|
|
219
|
+
* OpenAI `"hate/threatening"`, Mistral `"hate_and_discrimination"`).
|
|
220
|
+
*/
|
|
221
|
+
export interface BatchModeration {
|
|
222
|
+
/** Per-category boolean flags. */
|
|
223
|
+
categories: Record<string, boolean>;
|
|
224
|
+
/** Per-category confidence scores. */
|
|
225
|
+
categoryScores: Record<string, number>;
|
|
226
|
+
/**
|
|
227
|
+
* True when the input was flagged: the provider's own flag (OpenAI), or any
|
|
228
|
+
* category flag when the provider reports none (Mistral).
|
|
229
|
+
*/
|
|
230
|
+
flagged: boolean;
|
|
231
|
+
}
|
|
89
232
|
/** Normalized batch lifecycle status, unified across providers. */
|
|
90
233
|
export type BatchStatus = "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
|
|
91
234
|
/** Normalized per-request tallies. `completed` = succeeded, `failed` = errored. */
|
|
@@ -118,12 +261,18 @@ export interface BatchResult {
|
|
|
118
261
|
error?: BatchResultError;
|
|
119
262
|
/** Generated images, when the request produced images. */
|
|
120
263
|
images?: BatchImage[];
|
|
264
|
+
/** Normalized moderation verdict, when the request produced one. */
|
|
265
|
+
moderation?: BatchModeration;
|
|
121
266
|
/** Raw provider response body (OpenAI `response.body` / Anthropic message). */
|
|
122
267
|
response?: unknown;
|
|
268
|
+
/** Timestamped transcript segments, when requested via `timestampGranularities`. */
|
|
269
|
+
segments?: BatchTranscriptionSegment[];
|
|
123
270
|
status: BatchResultStatus;
|
|
124
|
-
/** Normalized text output, when the request produced a message. */
|
|
271
|
+
/** Normalized text output, when the request produced a message or transcript. */
|
|
125
272
|
text?: string;
|
|
126
273
|
usage?: BatchUsage;
|
|
274
|
+
/** Generated videos, when the request produced videos. */
|
|
275
|
+
videos?: BatchVideo[];
|
|
127
276
|
}
|
|
128
277
|
/** A point-in-time, normalized view of a batch's status. */
|
|
129
278
|
export interface BatchSnapshot {
|
|
@@ -173,6 +322,62 @@ export interface BatchImageOptions extends ProviderCredentials {
|
|
|
173
322
|
model: ImageModel;
|
|
174
323
|
requests: BatchImageRequest[];
|
|
175
324
|
}
|
|
325
|
+
/** Input to `batch.moderations()`. */
|
|
326
|
+
export interface BatchModerationOptions extends ProviderCredentials {
|
|
327
|
+
limits?: BatchLimits;
|
|
328
|
+
metadata?: Record<string, string>;
|
|
329
|
+
/**
|
|
330
|
+
* A `"provider/model"` string (e.g. `"openai/omni-moderation-latest"` or
|
|
331
|
+
* `"mistral/mistral-moderation-latest"`) — the AI SDK has no moderation
|
|
332
|
+
* model type.
|
|
333
|
+
*/
|
|
334
|
+
model: string;
|
|
335
|
+
requests: BatchModerationRequest[];
|
|
336
|
+
}
|
|
337
|
+
/** Input to `batch.images.edit()`. */
|
|
338
|
+
export interface BatchImageEditOptions extends ProviderCredentials {
|
|
339
|
+
defaults?: BatchImageEditDefaults;
|
|
340
|
+
limits?: BatchLimits;
|
|
341
|
+
metadata?: Record<string, string>;
|
|
342
|
+
model: ImageModel;
|
|
343
|
+
requests: BatchImageEditRequest[];
|
|
344
|
+
}
|
|
345
|
+
/** Input to `batch.translations()`. */
|
|
346
|
+
export interface BatchTranslationOptions extends ProviderCredentials {
|
|
347
|
+
defaults?: BatchTranslationDefaults;
|
|
348
|
+
limits?: BatchLimits;
|
|
349
|
+
metadata?: Record<string, string>;
|
|
350
|
+
/**
|
|
351
|
+
* A transcription model object (e.g. `groq.transcription("whisper-large-v3")`)
|
|
352
|
+
* or a `"provider/model"` string (e.g. `"together/openai/whisper-large-v3"`).
|
|
353
|
+
*/
|
|
354
|
+
model: TranscriptionModel;
|
|
355
|
+
requests: BatchTranslationRequest[];
|
|
356
|
+
}
|
|
357
|
+
/** Input to `batch.videos()`. */
|
|
358
|
+
export interface BatchVideoOptions extends ProviderCredentials {
|
|
359
|
+
defaults?: BatchVideoDefaults;
|
|
360
|
+
limits?: BatchLimits;
|
|
361
|
+
metadata?: Record<string, string>;
|
|
362
|
+
/**
|
|
363
|
+
* A video model object (e.g. `xai.video("grok-imagine-video")`) or a
|
|
364
|
+
* `"provider/model"` string.
|
|
365
|
+
*/
|
|
366
|
+
model: VideoModel;
|
|
367
|
+
requests: BatchVideoRequest[];
|
|
368
|
+
}
|
|
369
|
+
/** Input to `batch.transcriptions()`. */
|
|
370
|
+
export interface BatchTranscriptionOptions extends ProviderCredentials {
|
|
371
|
+
defaults?: BatchTranscriptionDefaults;
|
|
372
|
+
limits?: BatchLimits;
|
|
373
|
+
metadata?: Record<string, string>;
|
|
374
|
+
/**
|
|
375
|
+
* A transcription model object (e.g. `groq.transcription("whisper-large-v3")`)
|
|
376
|
+
* or a `"provider/model"` string (e.g. `"mistral/voxtral-mini-latest"`).
|
|
377
|
+
*/
|
|
378
|
+
model: TranscriptionModel;
|
|
379
|
+
requests: BatchTranscriptionRequest[];
|
|
380
|
+
}
|
|
176
381
|
/**
|
|
177
382
|
* Reference to an existing batch, used to rehydrate a handle. Identify the
|
|
178
383
|
* provider with either `model` or `provider` (e.g. from a webhook event).
|