batchwork 0.0.0 → 1.0.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/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/batch.d.ts +27 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/body.d.ts +19 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/chunk-e6qn48qa.js +301 -0
- package/dist/chunk-e6qn48qa.js.map +13 -0
- package/dist/chunk-g481f961.js +1212 -0
- package/dist/chunk-g481f961.js.map +26 -0
- package/dist/chunk-m4n610nm.js +338 -0
- package/dist/chunk-m4n610nm.js.map +12 -0
- package/dist/chunk-v0bahtg2.js +7 -0
- package/dist/chunk-v0bahtg2.js.map +9 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/http.d.ts +5 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +9 -0
- package/dist/job.d.ts +31 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/jsonl.d.ts +7 -0
- package/dist/jsonl.d.ts.map +1 -0
- package/dist/limits.d.ts +12 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/model.d.ts +32 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/next/index.d.ts +61 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +64 -0
- package/dist/next/index.js.map +10 -0
- package/dist/postgres/batch-store.d.ts +19 -0
- package/dist/postgres/batch-store.d.ts.map +1 -0
- package/dist/postgres/index.d.ts +6 -0
- package/dist/postgres/index.d.ts.map +1 -0
- package/dist/postgres/index.js +101 -0
- package/dist/postgres/index.js.map +12 -0
- package/dist/postgres/migrate.d.ts +15 -0
- package/dist/postgres/migrate.d.ts.map +1 -0
- package/dist/postgres/types.d.ts +26 -0
- package/dist/postgres/types.d.ts.map +1 -0
- package/dist/providers/adapter.d.ts +25 -0
- package/dist/providers/adapter.d.ts.map +1 -0
- package/dist/providers/anthropic.d.ts +3 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/google.d.ts +8 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/groq.d.ts +8 -0
- package/dist/providers/groq.d.ts.map +1 -0
- package/dist/providers/ids.d.ts +3 -0
- package/dist/providers/ids.d.ts.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/mistral.d.ts +8 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/openai-compatible.d.ts +41 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai.d.ts +7 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/shared.d.ts +23 -0
- package/dist/providers/shared.d.ts.map +1 -0
- package/dist/providers/together.d.ts +8 -0
- package/dist/providers/together.d.ts.map +1 -0
- package/dist/providers/xai.d.ts +8 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/redis/batch-store.d.ts +15 -0
- package/dist/redis/batch-store.d.ts.map +1 -0
- package/dist/redis/index.d.ts +4 -0
- package/dist/redis/index.d.ts.map +1 -0
- package/dist/redis/index.js +55 -0
- package/dist/redis/index.js.map +11 -0
- package/dist/redis/types.d.ts +19 -0
- package/dist/redis/types.d.ts.map +1 -0
- package/dist/server/events.d.ts +5 -0
- package/dist/server/events.d.ts.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +19 -0
- package/dist/server/index.js.map +9 -0
- package/dist/server/poller.d.ts +63 -0
- package/dist/server/poller.d.ts.map +1 -0
- package/dist/server/signing.d.ts +27 -0
- package/dist/server/signing.d.ts.map +1 -0
- package/dist/server/store.d.ts +4 -0
- package/dist/server/store.d.ts.map +1 -0
- package/dist/server/types.d.ts +37 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/util.d.ts +10 -0
- package/dist/util.d.ts.map +1 -0
- package/package.json +119 -7
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The minimal slice of a Postgres client batchwork's adapters use: a
|
|
3
|
+
* node-postgres-style `query(text, params)` returning `{ rows }`. This is
|
|
4
|
+
* deliberately structural so you can pass a `pg.Pool`/`pg.Client`, a
|
|
5
|
+
* `@neondatabase/serverless` client, or any thin wrapper that exposes `query` —
|
|
6
|
+
* batchwork never imports a driver, so it adds no dependency of its own.
|
|
7
|
+
*/
|
|
8
|
+
export interface SqlExecutor {
|
|
9
|
+
query: <Row = Record<string, unknown>>(text: string, params?: unknown[]) => Promise<{
|
|
10
|
+
rows: Row[];
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/** Options for the Postgres-backed batch store. */
|
|
14
|
+
export interface PostgresStoreOptions {
|
|
15
|
+
/** A `pg.Pool`-compatible client (anything with `query(text, params)`). */
|
|
16
|
+
client: SqlExecutor;
|
|
17
|
+
}
|
|
18
|
+
/** Table name defaults to this; override for a custom schema. */
|
|
19
|
+
export declare const DEFAULT_BATCH_TABLE = "batchwork_batches";
|
|
20
|
+
/**
|
|
21
|
+
* Guard against SQL injection through a caller-supplied table name: identifiers
|
|
22
|
+
* can't be parameterized, so they're interpolated directly and must be a plain
|
|
23
|
+
* unquoted identifier (optionally schema-qualified).
|
|
24
|
+
*/
|
|
25
|
+
export declare const assertSafeTable: (table: string) => string;
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/postgres/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,EAAE,KACf,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/B;AAED,mDAAmD;AACnD,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,KAAG,MAS/C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BuiltRequest } from "../body";
|
|
2
|
+
import type { BatchLimits, BatchProvider, BatchResult, BatchSnapshot, ProviderCredentials } from "../types";
|
|
3
|
+
export interface SubmitInput {
|
|
4
|
+
built: BuiltRequest[];
|
|
5
|
+
credentials: ProviderCredentials;
|
|
6
|
+
/** Endpoint path the captured requests target (e.g. `/v1/chat/completions`). */
|
|
7
|
+
endpoint: string;
|
|
8
|
+
limits?: BatchLimits;
|
|
9
|
+
metadata?: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Resolved model id. Needed by providers that set the model on the batch/job
|
|
12
|
+
* (Gemini puts it in the create URL, Mistral on the job); ignored by providers
|
|
13
|
+
* that carry the model in each request line (OpenAI, Anthropic).
|
|
14
|
+
*/
|
|
15
|
+
modelId: string;
|
|
16
|
+
}
|
|
17
|
+
/** A provider's batch lifecycle: submit, poll, stream results, cancel. */
|
|
18
|
+
export interface BatchAdapter {
|
|
19
|
+
cancel: (id: string, credentials: ProviderCredentials) => Promise<void>;
|
|
20
|
+
readonly id: BatchProvider;
|
|
21
|
+
results: (id: string, credentials: ProviderCredentials) => AsyncGenerator<BatchResult>;
|
|
22
|
+
retrieve: (id: string, credentials: ProviderCredentials) => Promise<BatchSnapshot>;
|
|
23
|
+
submit: (input: SubmitInput) => Promise<BatchSnapshot>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/providers/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,WAAW,EAAE,mBAAmB,CAAC;IACjC,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;IAC3B,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,mBAAmB,KAC7B,cAAc,CAAC,WAAW,CAAC,CAAC;IACjC,QAAQ,EAAE,CACR,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,mBAAmB,KAC7B,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAyN3D,eAAO,MAAM,gBAAgB,EAAE,YAM9B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BatchAdapter } from "./adapter";
|
|
2
|
+
/**
|
|
3
|
+
* Google Gemini (Developer API) batch adapter: submits inline requests via
|
|
4
|
+
* `:batchGenerateContent`, polls the returned long-running operation, then reads
|
|
5
|
+
* the inline responses keyed by each request's `metadata.key`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const googleAdapter: BatchAdapter;
|
|
8
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AA+O3D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,YAM3B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groq batch adapter. Groq's batch API is OpenAI-compatible (Files API +
|
|
3
|
+
* `/batches`), so it reuses the OpenAI-compatible flow. Groq is served under
|
|
4
|
+
* `/openai/v1`, but its batch `url` must be `/v1/chat/completions`, so the
|
|
5
|
+
* captured endpoint's `/openai` prefix is stripped.
|
|
6
|
+
*/
|
|
7
|
+
export declare const groqAdapter: import("./adapter").BatchAdapter;
|
|
8
|
+
//# sourceMappingURL=groq.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groq.d.ts","sourceRoot":"","sources":["../../src/providers/groq.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,kCAOtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/providers/ids.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,UAAW,MAAM,MAAM,MAAM,KAAG,MAKlE,CAAC;AAEF,eAAO,MAAM,wBAAwB,UAC5B,MAAM,MACT,MAAM,UACF,MAAM,KACb,MAWF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BatchProvider } from "../types";
|
|
2
|
+
import type { BatchAdapter } from "./adapter";
|
|
3
|
+
export declare const getAdapter: (provider: BatchProvider) => BatchAdapter;
|
|
4
|
+
export type { BatchAdapter, SubmitInput } from "./adapter";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAmB9C,eAAO,MAAM,UAAU,aAAc,aAAa,KAAG,YACjC,CAAC;AAErB,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BatchAdapter } from "./adapter";
|
|
2
|
+
/**
|
|
3
|
+
* Mistral batch adapter: uploads JSONL (`purpose=batch`), creates a job with the
|
|
4
|
+
* model/endpoint set on the job, polls `status`, then downloads the OpenAI-shaped
|
|
5
|
+
* output/error files.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mistralAdapter: BatchAdapter;
|
|
8
|
+
//# sourceMappingURL=mistral.d.ts.map
|
|
@@ -0,0 +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;AAqJ3D;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,YAM5B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for OpenAI-compatible batch adapters. OpenAI, Groq, and Together AI
|
|
3
|
+
* all share the same lifecycle — upload JSONL via the Files API, create a batch
|
|
4
|
+
* referencing the file, poll a `status` field, then download output/error files
|
|
5
|
+
* — differing only in base URL, credentials, and minor request-line shape.
|
|
6
|
+
*/
|
|
7
|
+
import type { BatchProvider } from "../types";
|
|
8
|
+
import type { BatchAdapter } from "./adapter";
|
|
9
|
+
export type BatchLineFormat = "body-only" | "method-url";
|
|
10
|
+
export interface OpenAICompatibleConfig {
|
|
11
|
+
apiKeyEnv: string;
|
|
12
|
+
apiKeyLabel: string;
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
completionWindow?: string;
|
|
15
|
+
filePurpose?: string;
|
|
16
|
+
id: BatchProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Override the JSONL upload. Defaults to a direct multipart POST to the Files
|
|
19
|
+
* API (OpenAI, Groq); Together replaces it with its presigned-URL flow.
|
|
20
|
+
* Returns the uploaded file id.
|
|
21
|
+
*/
|
|
22
|
+
uploadFile?: (args: {
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
jsonl: string;
|
|
26
|
+
purpose: string;
|
|
27
|
+
}) => Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Input-line shape. `method-url` writes `{ custom_id, method, url, body }`
|
|
30
|
+
* (OpenAI, Groq); `body-only` writes `{ custom_id, body }` (Together).
|
|
31
|
+
*/
|
|
32
|
+
lineFormat?: BatchLineFormat;
|
|
33
|
+
/**
|
|
34
|
+
* Map the captured endpoint path to the value the provider expects in the
|
|
35
|
+
* batch `url`/`endpoint` field (e.g. Groq serves under `/openai/v1` but its
|
|
36
|
+
* batch `url` must be `/v1/chat/completions`).
|
|
37
|
+
*/
|
|
38
|
+
normalizeEndpoint?: (endpoint: string) => string;
|
|
39
|
+
}
|
|
40
|
+
export declare const createOpenAICompatibleAdapter: (config: OpenAICompatibleConfig) => BatchAdapter;
|
|
41
|
+
//# sourceMappingURL=openai-compatible.d.ts.map
|
|
@@ -0,0 +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,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAEhB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,aAAa,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,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;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CAClD;AAgDD,eAAO,MAAM,6BAA6B,WAChC,sBAAsB,KAC7B,YA+GF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI batch adapter: builds JSONL, uploads it via the Files API
|
|
3
|
+
* (`purpose=batch`), creates the batch, polls `status`, then downloads and
|
|
4
|
+
* parses the output and error files.
|
|
5
|
+
*/
|
|
6
|
+
export declare const openaiAdapter: import("./adapter").BatchAdapter;
|
|
7
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,aAAa,kCAMxB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers shared across the OpenAI-shaped adapters (OpenAI, Groq, Together,
|
|
3
|
+
* Mistral). These providers all upload JSONL via a Files API, return results as
|
|
4
|
+
* JSONL keyed by `custom_id`, and shape each result line like OpenAI's
|
|
5
|
+
* (`{ custom_id, response: { status_code, body }, error }`).
|
|
6
|
+
*/
|
|
7
|
+
import type { BatchResult, BatchUsage, ProviderCredentials } from "../types";
|
|
8
|
+
/** Resolve an API key from credentials or the provider's env var, or throw. */
|
|
9
|
+
export declare const resolveApiKey: (credentials: ProviderCredentials, envVar: string, label: string) => string;
|
|
10
|
+
export declare const textFromBody: (body: unknown) => string | undefined;
|
|
11
|
+
export declare const usageFromBody: (body: unknown) => BatchUsage | undefined;
|
|
12
|
+
/** Normalize an OpenAI-shaped result line into a {@link BatchResult}. */
|
|
13
|
+
export declare const normalizeOpenAIResult: (line: unknown) => BatchResult;
|
|
14
|
+
export declare const uploadInputFile: (jsonl: string, baseUrl: string, headers: Record<string, string>, options?: {
|
|
15
|
+
purpose?: string | null;
|
|
16
|
+
}) => Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Stream a JSONL result file's content as normalized OpenAI-shaped results.
|
|
19
|
+
*
|
|
20
|
+
* @yields {BatchResult} the normalized result for each line.
|
|
21
|
+
*/
|
|
22
|
+
export declare function streamResultFile(fileId: string, baseUrl: string, headers: Record<string, string>): AsyncGenerator<BatchResult>;
|
|
23
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/providers/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,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,SAUrD,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,OAAO,KAAG,UAAU,GAAG,SAmB1D,CAAC;AAaF,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,SAAU,OAAO,KAAG,WAkCrD,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,CAiBhB,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,CAO7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Together AI batch adapter. Together's batch API mirrors OpenAI's (Files API +
|
|
3
|
+
* `/batches`) but uses the leaner `{ custom_id, body }` input-line shape, with
|
|
4
|
+
* the endpoint declared on the batch rather than per line, and a presigned-URL
|
|
5
|
+
* file upload in place of OpenAI's direct multipart POST.
|
|
6
|
+
*/
|
|
7
|
+
export declare const togetherAdapter: import("./adapter").BatchAdapter;
|
|
8
|
+
//# sourceMappingURL=together.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../src/providers/together.ts"],"names":[],"mappings":"AAyIA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,kCAQ1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BatchAdapter } from "./adapter";
|
|
2
|
+
/**
|
|
3
|
+
* xAI (Grok) batch adapter. Uses xAI's OpenAI-compatible file-upload path
|
|
4
|
+
* (`/v1/files` + `/v1/batches` with `input_file_id`), but its status, paginated
|
|
5
|
+
* `/results`, and `:cancel` shapes are proprietary.
|
|
6
|
+
*/
|
|
7
|
+
export declare const xaiAdapter: BatchAdapter;
|
|
8
|
+
//# sourceMappingURL=xai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAgL3D;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,YAMxB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BatchStore } from "../server/types";
|
|
2
|
+
import type { RedisStoreOptions } from "./types";
|
|
3
|
+
/** Options for {@link createRedisStore}. */
|
|
4
|
+
export type RedisBatchStoreOptions = RedisStoreOptions;
|
|
5
|
+
/**
|
|
6
|
+
* A Redis-backed {@link BatchStore} for the poller, over `@upstash/redis`. Each
|
|
7
|
+
* tracked batch is a JSON value at `{prefix}:batch:{id}`, with a set index at
|
|
8
|
+
* `{prefix}:batches` so `list` can enumerate them.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { Redis } from "@upstash/redis";
|
|
12
|
+
* const store = createRedisStore({ redis: Redis.fromEnv() });
|
|
13
|
+
*/
|
|
14
|
+
export declare const createRedisStore: (options: RedisBatchStoreOptions) => BatchStore;
|
|
15
|
+
//# sourceMappingURL=batch-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-store.d.ts","sourceRoot":"","sources":["../../src/redis/batch-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,4CAA4C;AAC5C,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAEvD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,YAClB,sBAAsB,KAC9B,UAsCF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import"../chunk-v0bahtg2.js";
|
|
2
|
+
|
|
3
|
+
// src/redis/types.ts
|
|
4
|
+
var DEFAULT_PREFIX = "batchwork";
|
|
5
|
+
var coerce = (value) => {
|
|
6
|
+
if (value === null || value === undefined) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return typeof value === "string" ? JSON.parse(value) : value;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/redis/batch-store.ts
|
|
13
|
+
var createRedisStore = (options) => {
|
|
14
|
+
const { redis } = options;
|
|
15
|
+
const prefix = options.prefix ?? DEFAULT_PREFIX;
|
|
16
|
+
const batchKey = (id) => `${prefix}:batch:${id}`;
|
|
17
|
+
const indexKey = `${prefix}:batches`;
|
|
18
|
+
return {
|
|
19
|
+
delete: async (id) => {
|
|
20
|
+
await redis.del(batchKey(id));
|
|
21
|
+
await redis.srem(indexKey, id);
|
|
22
|
+
},
|
|
23
|
+
get: async (id) => coerce(await redis.get(batchKey(id))),
|
|
24
|
+
list: async (filter) => {
|
|
25
|
+
const ids = await redis.smembers(indexKey);
|
|
26
|
+
if (ids.length === 0) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const raws = await redis.mget(...ids.map(batchKey));
|
|
30
|
+
const records = [];
|
|
31
|
+
for (const raw of raws) {
|
|
32
|
+
const record = coerce(raw);
|
|
33
|
+
if (record) {
|
|
34
|
+
records.push(record);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (filter?.delivered === undefined) {
|
|
38
|
+
return records;
|
|
39
|
+
}
|
|
40
|
+
const { delivered } = filter;
|
|
41
|
+
return records.filter((record) => record.deliveredAt !== undefined === delivered);
|
|
42
|
+
},
|
|
43
|
+
set: async (record) => {
|
|
44
|
+
await redis.set(batchKey(record.id), JSON.stringify(record));
|
|
45
|
+
await redis.sadd(indexKey, record.id);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
createRedisStore,
|
|
51
|
+
DEFAULT_PREFIX
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//# debugId=80E91990D446837F64756E2164756E21
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/redis/types.ts", "../src/redis/batch-store.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { Redis } from \"@upstash/redis\";\n\n/** The Upstash Redis client batchwork's adapters drive. */\nexport type RedisClient = Redis;\n\n/** Options for the Redis-backed batch store. */\nexport interface RedisStoreOptions {\n /** A connected `@upstash/redis` client. */\n redis: Redis;\n /** Key namespace, so one Redis can back many apps. Defaults to `batchwork`. */\n prefix?: string;\n}\n\nexport const DEFAULT_PREFIX = \"batchwork\";\n\n/**\n * Read a stored value back into a record. `@upstash/redis` may or may not\n * auto-deserialize depending on the client's config, and values returned from\n * Lua (`eval`) are always raw strings — so tolerate both an object and a JSON\n * string, and treat a missing key as `null`.\n */\nexport const coerce = <T>(value: unknown): T | null => {\n if (value === null || value === undefined) {\n return null;\n }\n return (typeof value === \"string\" ? JSON.parse(value) : value) as T;\n};\n",
|
|
6
|
+
"import type { BatchStore, TrackedBatch } from \"../server/types\";\nimport { coerce, DEFAULT_PREFIX } from \"./types\";\nimport type { RedisStoreOptions } from \"./types\";\n\n/** Options for {@link createRedisStore}. */\nexport type RedisBatchStoreOptions = RedisStoreOptions;\n\n/**\n * A Redis-backed {@link BatchStore} for the poller, over `@upstash/redis`. Each\n * tracked batch is a JSON value at `{prefix}:batch:{id}`, with a set index at\n * `{prefix}:batches` so `list` can enumerate them.\n *\n * @example\n * import { Redis } from \"@upstash/redis\";\n * const store = createRedisStore({ redis: Redis.fromEnv() });\n */\nexport const createRedisStore = (\n options: RedisBatchStoreOptions\n): BatchStore => {\n const { redis } = options;\n const prefix = options.prefix ?? DEFAULT_PREFIX;\n const batchKey = (id: string): string => `${prefix}:batch:${id}`;\n const indexKey = `${prefix}:batches`;\n\n return {\n delete: async (id) => {\n await redis.del(batchKey(id));\n await redis.srem(indexKey, id);\n },\n get: async (id) => coerce<TrackedBatch>(await redis.get(batchKey(id))),\n list: async (filter) => {\n const ids = await redis.smembers(indexKey);\n if (ids.length === 0) {\n return [];\n }\n const raws = await redis.mget<unknown[]>(...ids.map(batchKey));\n const records: TrackedBatch[] = [];\n for (const raw of raws) {\n const record = coerce<TrackedBatch>(raw);\n if (record) {\n records.push(record);\n }\n }\n if (filter?.delivered === undefined) {\n return records;\n }\n const { delivered } = filter;\n return records.filter(\n (record) => (record.deliveredAt !== undefined) === delivered\n );\n },\n set: async (record) => {\n await redis.set(batchKey(record.id), JSON.stringify(record));\n await redis.sadd(indexKey, record.id);\n },\n };\n};\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;AAaO,IAAM,iBAAiB;AAQvB,IAAM,SAAS,CAAI,UAA6B;AAAA,EACrD,IAAI,UAAU,QAAQ,UAAU,WAAW;AAAA,IACzC,OAAO;AAAA,EACT;AAAA,EACA,OAAQ,OAAO,UAAU,WAAW,KAAK,MAAM,K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
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Redis } from "@upstash/redis";
|
|
2
|
+
/** The Upstash Redis client batchwork's adapters drive. */
|
|
3
|
+
export type RedisClient = Redis;
|
|
4
|
+
/** Options for the Redis-backed batch store. */
|
|
5
|
+
export interface RedisStoreOptions {
|
|
6
|
+
/** A connected `@upstash/redis` client. */
|
|
7
|
+
redis: Redis;
|
|
8
|
+
/** Key namespace, so one Redis can back many apps. Defaults to `batchwork`. */
|
|
9
|
+
prefix?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_PREFIX = "batchwork";
|
|
12
|
+
/**
|
|
13
|
+
* Read a stored value back into a record. `@upstash/redis` may or may not
|
|
14
|
+
* auto-deserialize depending on the client's config, and values returned from
|
|
15
|
+
* Lua (`eval`) are always raw strings — so tolerate both an object and a JSON
|
|
16
|
+
* string, and treat a missing key as `null`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const coerce: <T>(value: unknown) => T | null;
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/redis/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,2DAA2D;AAC3D,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC;AAEhC,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,KAAK,EAAE,KAAK,CAAC;IACb,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,KAAG,CAAC,GAAG,IAK9C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BatchProvider, BatchSnapshot } from "../types";
|
|
2
|
+
import type { BatchWebhookEvent } from "./types";
|
|
3
|
+
/** Map a terminal snapshot to the unified webhook event batchwork delivers. */
|
|
4
|
+
export declare const toEvent: (provider: BatchProvider, snapshot: BatchSnapshot) => BatchWebhookEvent;
|
|
5
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/server/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAe,MAAM,UAAU,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAyB,MAAM,SAAS,CAAC;AASxE,+EAA+E;AAC/E,eAAO,MAAM,OAAO,aACR,aAAa,YACb,aAAa,KACtB,iBAOD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createBatchPoller } from "./poller";
|
|
2
|
+
export type { BatchPoller, BatchPollerOptions, CompletionSink, CredentialResolver, OpenAIWebhookOptions, TickResult, TrackOptions, TrackTarget, WebhookUrlValidator, } from "./poller";
|
|
3
|
+
export { signWebhook, verifyBatchWebhook, verifyWebhook } from "./signing";
|
|
4
|
+
export type { VerifiedWebhook, VerifyWebhookOptions, WebhookReplayStore, } from "./signing";
|
|
5
|
+
export { createMemoryStore } from "./store";
|
|
6
|
+
export type { BatchStore, BatchWebhookEvent, BatchWebhookEventType, TrackedBatch, } from "./types";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC3E,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,GACb,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBatchPoller,
|
|
3
|
+
createMemoryStore,
|
|
4
|
+
signWebhook,
|
|
5
|
+
verifyBatchWebhook,
|
|
6
|
+
verifyWebhook
|
|
7
|
+
} from "../chunk-e6qn48qa.js";
|
|
8
|
+
import"../chunk-g481f961.js";
|
|
9
|
+
import"../chunk-v0bahtg2.js";
|
|
10
|
+
export {
|
|
11
|
+
verifyWebhook,
|
|
12
|
+
verifyBatchWebhook,
|
|
13
|
+
signWebhook,
|
|
14
|
+
createMemoryStore,
|
|
15
|
+
createBatchPoller
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//# debugId=C585C9F747001A8C64756E2164756E21
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { BatchProvider, BatchSnapshot, BatchStatus, ProviderCredentials } from "../types";
|
|
2
|
+
import type { BatchStore, TrackedBatch } from "./types";
|
|
3
|
+
/** Credentials for polling: a fixed config, or one resolved per provider. */
|
|
4
|
+
export type CredentialResolver = ProviderCredentials | ((provider: BatchProvider) => ProviderCredentials);
|
|
5
|
+
/**
|
|
6
|
+
* Handles a batch reaching a terminal status. Replaces the default signed
|
|
7
|
+
* webhook delivery — e.g. to invoke a callback instead (see `batchwork/next`).
|
|
8
|
+
*/
|
|
9
|
+
export type CompletionSink = (record: TrackedBatch, snapshot: BatchSnapshot) => Promise<void>;
|
|
10
|
+
export type WebhookUrlValidator = (url: URL) => void | Promise<void>;
|
|
11
|
+
export interface BatchPollerOptions {
|
|
12
|
+
store: BatchStore;
|
|
13
|
+
/** Falls back to provider env vars (e.g. `OPENAI_API_KEY`) when omitted. */
|
|
14
|
+
credentials?: CredentialResolver;
|
|
15
|
+
/** Replaces signed-webhook delivery when a batch finishes. */
|
|
16
|
+
onComplete?: CompletionSink;
|
|
17
|
+
/** Override the default webhook URL policy with an application allowlist. */
|
|
18
|
+
validateWebhookUrl?: WebhookUrlValidator;
|
|
19
|
+
/**
|
|
20
|
+
* Called when processing a single batch throws during `tick`. When provided,
|
|
21
|
+
* the tick reports the error and continues to the next batch; when omitted,
|
|
22
|
+
* the error propagates out of `tick`.
|
|
23
|
+
*/
|
|
24
|
+
onError?: (record: TrackedBatch, error: unknown) => void;
|
|
25
|
+
}
|
|
26
|
+
export interface TrackTarget {
|
|
27
|
+
id: string;
|
|
28
|
+
provider: BatchProvider;
|
|
29
|
+
status?: BatchStatus;
|
|
30
|
+
}
|
|
31
|
+
export interface TrackOptions {
|
|
32
|
+
/** Where to POST the completion webhook. Omit for callback-based delivery. */
|
|
33
|
+
webhookUrl?: string;
|
|
34
|
+
/** Signs the outbound webhook (Standard Webhooks HMAC) when provided. */
|
|
35
|
+
secret?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TickResult {
|
|
38
|
+
checked: number;
|
|
39
|
+
delivered: string[];
|
|
40
|
+
/** Batches whose processing threw this tick (only when `onError` is set). */
|
|
41
|
+
failed?: {
|
|
42
|
+
id: string;
|
|
43
|
+
error: string;
|
|
44
|
+
}[];
|
|
45
|
+
}
|
|
46
|
+
export interface OpenAIWebhookOptions {
|
|
47
|
+
/** The OpenAI webhook signing secret (`whsec_…`). */
|
|
48
|
+
signingSecret: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BatchPoller {
|
|
51
|
+
track: (target: TrackTarget, options: TrackOptions) => Promise<TrackedBatch>;
|
|
52
|
+
tick: () => Promise<TickResult>;
|
|
53
|
+
deliver: (record: TrackedBatch, snapshot: BatchSnapshot) => Promise<void>;
|
|
54
|
+
openaiWebhookHandler: (options: OpenAIWebhookOptions) => (request: Request) => Promise<Response>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a managed poller: register submitted batches with `track`, then run
|
|
58
|
+
* `tick` on a schedule (cron) to poll open batches and deliver one unified,
|
|
59
|
+
* signed webhook per batch when it finishes. For OpenAI, mount
|
|
60
|
+
* `openaiWebhookHandler` to skip polling and react to native webhooks instead.
|
|
61
|
+
*/
|
|
62
|
+
export declare const createBatchPoller: (options: BatchPollerOptions) => BatchPoller;
|
|
63
|
+
//# sourceMappingURL=poller.d.ts.map
|
|
@@ -0,0 +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;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ookReplayStore {
|
|
3
|
+
get: (id: string) => number | Promise<number | undefined> | undefined;
|
|
4
|
+
set: (id: string, expiresAt: number) => Promise<void> | void;
|
|
5
|
+
}
|
|
6
|
+
export interface VerifyWebhookOptions {
|
|
7
|
+
replayStore?: WebhookReplayStore;
|
|
8
|
+
}
|
|
9
|
+
/** Build Standard Webhooks signature headers for an outbound delivery. */
|
|
10
|
+
export declare const signWebhook: (secret: string, id: string, body: string, timestampSeconds: number) => Promise<Record<string, string>>;
|
|
11
|
+
export interface VerifiedWebhook {
|
|
12
|
+
id: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
body: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Verify a Standard Webhooks-signed request and return its raw body. Throws if
|
|
18
|
+
* headers are missing, the timestamp is outside tolerance, or no signature
|
|
19
|
+
* matches. Consumes the request body.
|
|
20
|
+
*/
|
|
21
|
+
export declare const verifyWebhook: (request: Request, secret: string, options?: VerifyWebhookOptions) => Promise<VerifiedWebhook>;
|
|
22
|
+
/**
|
|
23
|
+
* Verify and parse a batchwork webhook on your receiving endpoint. Returns the
|
|
24
|
+
* unified {@link BatchWebhookEvent}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const verifyBatchWebhook: (request: Request, secret: string, options?: VerifyWebhookOptions) => Promise<BatchWebhookEvent>;
|
|
27
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/server/signing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAWjD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IACtE,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAsFD,0EAA0E;AAC1E,eAAO,MAAM,WAAW,WACd,MAAM,MACV,MAAM,QACJ,MAAM,oBACM,MAAM,KACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQhC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,YACf,OAAO,UACR,MAAM,YACJ,oBAAoB,KAC7B,OAAO,CAAC,eAAe,CA8CzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,YACpB,OAAO,UACR,MAAM,YACJ,oBAAoB,KAC7B,OAAO,CAAC,iBAAiB,CAG3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/server/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAC;AAExD,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAO,UAwBpC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BatchProvider, BatchRequestCounts, BatchStatus } from "../types";
|
|
2
|
+
/** The unified webhook event batchwork delivers when a batch finishes. */
|
|
3
|
+
export type BatchWebhookEventType = "batch.completed" | "batch.failed" | "batch.expired" | "batch.cancelled";
|
|
4
|
+
export interface BatchWebhookEvent {
|
|
5
|
+
type: BatchWebhookEventType;
|
|
6
|
+
id: string;
|
|
7
|
+
provider: BatchProvider;
|
|
8
|
+
requestCounts: BatchRequestCounts;
|
|
9
|
+
createdAt?: string;
|
|
10
|
+
completedAt?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A batch being watched by the poller, plus its delivery target. */
|
|
13
|
+
export interface TrackedBatch {
|
|
14
|
+
id: string;
|
|
15
|
+
provider: BatchProvider;
|
|
16
|
+
/** Where to POST the completion webhook. Omitted for callback-based flows. */
|
|
17
|
+
webhookUrl?: string;
|
|
18
|
+
webhookSecret?: string;
|
|
19
|
+
status: BatchStatus;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
/** Set once the completion webhook has been delivered. */
|
|
22
|
+
deliveredAt?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Persistence for tracked batches. Implement against any KV/DB (Vercel KV,
|
|
26
|
+
* Upstash Redis, Cloudflare KV, Postgres). `createMemoryStore` is provided for
|
|
27
|
+
* development and single-process use.
|
|
28
|
+
*/
|
|
29
|
+
export interface BatchStore {
|
|
30
|
+
get: (id: string) => Promise<TrackedBatch | null>;
|
|
31
|
+
set: (record: TrackedBatch) => Promise<void>;
|
|
32
|
+
delete: (id: string) => Promise<void>;
|
|
33
|
+
list: (filter?: {
|
|
34
|
+
delivered?: boolean;
|
|
35
|
+
}) => Promise<TrackedBatch[]>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE/E,0EAA0E;AAC1E,MAAM,MAAM,qBAAqB,GAC7B,iBAAiB,GACjB,cAAc,GACd,eAAe,GACf,iBAAiB,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,kBAAkB,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC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