@shop-os/modelkit 0.2.12 → 0.2.14

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/CHANGELOG.md CHANGED
@@ -9,6 +9,25 @@ header in the release PR.
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.2.14] - Unreleased
13
+
14
+ - Keep AI SDK 6 and its compatible provider packages, including Bedrock and usage tracking.
15
+ - Add per-call media retry limits so durable workflow controllers can own retries without duplicate provider submissions.
16
+
17
+
18
+ ## [0.2.13] - 2026-09-18
19
+
20
+ ### Added
21
+ - `dataOnlyCapable(row)`: reports whether a database catalog row would be served by a generic path, a hard-coded kind, or a valid `inputSpec`. The modality check is derived from the adapter's `generateImage` / `generateVideo` / `generateAudio` / `languageModel` surface, so a wrong-modality row reports `ok: false`. Replicate video and audio rows also need a known kind or a valid `inputSpec`.
22
+ - `providerOptions.modelkit.inputSpec`: per-row Replicate video and audio field mapping (`fields`, `values`, `static`) with the shared `applyInputSpec` mapper, read by the Replicate adapter only. Video rows use `VIDEO_INPUT_SPEC_KEYS`; audio rows use `AUDIO_INPUT_SPEC_KEYS` (`prompt`, `durationSeconds`, `seed`, `negativePrompt`, `references`, `sourceVideo`, `instrumental`).
23
+ - `validateInputSpec(raw, row)`: the shared Replicate-only `inputSpec` contract (schema, values-need-fields entries, no duplicate provider names, `constraints.supports` cross-check including `instrumental`, video/audio modality check) used by the write schema, `dataOnlyCapable`, and the Replicate mapper.
24
+ - `PrimeCatalogResult.droppedRows`: count of catalog rows dropped by the per-row quarantine on the read path.
25
+
26
+ ### Changed
27
+ - Replicate and fal video or audio ids with no input mapper now throw `unsupported_option` instead of using a default mapper.
28
+ - Higgsfield Kling rows with an absolute-URL `providerModelId` are rejected with `unsupported_option`; the id must be a platform path.
29
+ - The catalog read path drops invalid rows with one warning each instead of rejecting the whole envelope.
30
+
12
31
  ## [0.2.12] - 2026-09-17
13
32
 
14
33
  ### Changed
package/README.md CHANGED
@@ -110,11 +110,40 @@ for a model the catalog does not carry yet; the next step is a catalog row.
110
110
  | `experimental_generateSpeech`, `transcribe`, `embed`, `embedMany`, `rerank`, agents, UI streams | Re-exported from `ai` unchanged; the catalog has no rows for them. |
111
111
 
112
112
  An optional second `CallContext` argument selects enterprise keys, adds cancellation
113
- (combined with `abortSignal`), and sets `onUnsupported`. Package-level functions read
113
+ (combined with `abortSignal`), sets media `maxRetries`, and sets `onUnsupported`. Package-level functions read
114
114
  keys from the environment; a configured kit adds routing, catalog overrides, custom
115
115
  fetch, provider endpoint overrides (`endpoints.ark` for the Ark base url), logging, and
116
116
  the `onUsage` sink.
117
117
 
118
+ ### Durable media execution
119
+
120
+ Goal Mode owns technical recovery. Every image, video, audio, and media-preparation
121
+ call in that host must pass `{ maxRetries: 0 }` as the second argument:
122
+
123
+ ```ts
124
+ const result = await kit.generateImage(
125
+ { model: "gpt-image-2", prompt: "A product photo" },
126
+ { maxRetries: 0, signal },
127
+ );
128
+ ```
129
+
130
+ `maxRetries` counts retries after the first request. Zero disables adapter and SDK
131
+ retries, failed status-read retries, and Google's Files-to-inline fallback. Successful
132
+ pending-job responses still poll the same job. Unset retains existing adapter defaults.
133
+ An explicit nonzero limit allows bounded submission retries; a later read failure never
134
+ resubmits an already-created fal job. Text calls instead use AI SDK's first-argument
135
+ `maxRetries: 0` option.
136
+
137
+ Replicate 1.x has no retry switch. fal 1.x queue methods override its client retry
138
+ setting. With an explicit limit, ModelKit uses their REST prediction/queue endpoints
139
+ and owns retries itself; the usual SDK paths remain when the option is unset. Google
140
+ models and Google Interactions have separate retry controls, both disabled beneath
141
+ ModelKit's policy. SDK image/video model instances also receive the explicit limit.
142
+ The fal Cloudflare passthrough sets `cf-aig-max-attempts: 1` with an explicit limit,
143
+ using [Cloudflare request handling](https://developers.cloudflare.com/ai-gateway/configuration/request-handling/)
144
+ headers so gateway retries do not multiply local attempts. Custom adapters and custom
145
+ provider instances must honor their own retry contract.
146
+
118
147
  `providerOptions` on `generateImage`/`generateVideo` reach the provider only for
119
148
  pass-through instances; catalog rows carry their own and the caller's are dropped
120
149
  with an `option_ignored` warning.
@@ -165,6 +194,18 @@ The Bedrock model id is `<routing.bedrockProfile>.anthropic.<providerModelId>`
165
194
  breaks the pattern sets `providerOptions.modelkit.bedrockModelId` on its row.
166
195
  See the CHANGELOG entry for the caller-visible Bedrock limits.
167
196
 
197
+ A Replicate video or audio row for a new model carries `providerOptions.modelkit.inputSpec`
198
+ instead of a kit change. It is read by the Replicate adapter only. `fields` maps a canonical key to the provider field name,
199
+ `values` remaps canonical values per key, and `static` merges literal provider fields
200
+ last. Video rows use `VIDEO_INPUT_SPEC_KEYS` (`prompt`, `durationSeconds`,
201
+ `aspectRatio`, `resolution`, `firstFrame`, `lastFrame`, `seed`, `negativePrompt`,
202
+ `generateAudio`, `cfgScale`, `promptExpansion`, `referenceImages`); audio rows use
203
+ `AUDIO_INPUT_SPEC_KEYS` (`prompt`, `durationSeconds`, `seed`, `negativePrompt`,
204
+ `references`, `sourceVideo`, `instrumental`). `aspectRatio: "adaptive"` is omitted.
205
+ `validateInputSpec` is the shared contract the write schema, `dataOnlyCapable`, and
206
+ the Replicate mapper all check. `dataOnlyCapable(row)` reports whether such a row would
207
+ be served.
208
+
168
209
  ```ts
169
210
  import { defaultProvider } from "@aws-sdk/credential-provider-node";
170
211
  import { createDefaultModelKit, keysFromEnv } from "@shop-os/modelkit";
@@ -201,7 +242,7 @@ const defaultKit = createDefaultModelKit({ keys: { pro: keysFromEnv(process.env)
201
242
  | Options | Image tiers are `512` (Gemini 3.1 Flash only), `1K`, `2K`, `4K`. `resolveOptions` fills catalog defaults, errors on an unsupported aspect ratio, size, resolution or duration (`onUnsupported: "coerce"` snaps to the nearest supported value with a warning instead; since 0.1.6 ratio and duration honour this too, so pass `"coerce"` where the old code snapped silently), trims references (audio first, then video), and drops options the model ignores with a warning. Audio requests go through the same resolver and take `abortSignal` (a row without `supports` supports nothing). `aspectRatio: "adaptive"` means "send no ratio": it is never coerced or replaced by the row default, and Gemini, Muse, Kling and Kling O1 omit the field so the model infers it from the references. Every coercion is also logged once per call through `logger.warn`. Gemini image `safetySettings` and `temperature` are sent only when the caller passes them. A reference with a `label` gets a text part with that label right before the image on Gemini image and Omni ("Image 2:", "Here is the brand logo:"). Topaz takes `upscale` (`enhanceModel`, `subjectDetection`, `faceEnhancement` and its creativity/strength) next to `scaleFactor`/`outputFormat`; Seedance takes `watermark`; MiniMax takes `lastFrame` and `safetyChecker`; Seedream 4.5 goes to `4K` and `9:21`. |
202
243
  | Keys | Enterprise keys win only when every key the adapter (and its route, e.g. the cloudflare token for a vendor that really goes through the gateway) needs is set on the enterprise tier; a fallback to pro keys is logged once per call. |
203
244
  | Routing | Cloudflare AI Gateway for text only. Never for Gemini images or Omni. fal passthrough for geo-blocked regions; the fal direct route submits to the queue and polls, so `job.result({ timeoutMs, signal })` is live. |
204
- | Retry | One classifier, one policy. Never on content blocks, aborts, or 4xx except 429; SDKs with their own retry (Replicate) run under a single kit attempt; a 429 on a status poll keeps polling. |
245
+ | Retry | One classifier, one policy. Never on content blocks, aborts, or 4xx except 429; SDKs with their own retry (Replicate) run under a single kit attempt; a 429 on a status poll keeps polling unless `CallContext.maxRetries` is `0`. See durable media execution above. |
205
246
  | Errors | `ModelKitError` with `code`, `provider`, `status`, `body`. Gemini `blockReason` and fal `body.detail` are lifted into `body`. A throw with no HTTP status (fetch failed, reset, DNS) is a retryable `network` error on every adapter. |
206
247
  | Usage | One event per call with the canonical model id and the row's `usage.unit` (adapters supply the quantity in that unit). Gemini image events carry the token counts too (`inputTokens`/`outputTokens`); Google's raw `usageMetadata` rides on `raw.providerMetadata.google`. Video usage is emitted on completion; Seedance keeps `usage`, `duration`, `framespersecond` and `resolution` from the poll on `raw`. Audio: Lyria 3 returns no duration, so it emits `unit: "images", quantity: 1` (token counts ride along as `inputTokens`/`outputTokens`); Replicate audio (Lyria 2, MMAudio) emits `unit: "compute_seconds"` with the prediction time. |
207
248
  | Media parts | `prepareMediaPart` turns a `MediaRef` into an AI SDK file part. Google inlines bytes up to 20 MB and uploads larger payloads through the Files API; call the returned `cleanup` after the request. Other providers get the reference inline. |