@shop-os/modelkit 0.2.13 → 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,12 @@ 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
+
12
18
  ## [0.2.13] - 2026-09-18
13
19
 
14
20
  ### Added
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.
@@ -213,7 +242,7 @@ const defaultKit = createDefaultModelKit({ keys: { pro: keysFromEnv(process.env)
213
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`. |
214
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. |
215
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. |
216
- | 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. |
217
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. |
218
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. |
219
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. |
package/dist/catalog.cjs CHANGED
@@ -180,7 +180,9 @@ function normalizeExposure(value) {
180
180
  if (value === "catalog") return ["cowork", "space_builder"];
181
181
  if (value === "internal") return [];
182
182
  if (Array.isArray(value)) {
183
- if (value.every((entry) => SURFACES.includes(entry))) {
183
+ if (value.every(
184
+ (entry) => SURFACES.includes(entry)
185
+ )) {
184
186
  const present = new Set(value);
185
187
  return SURFACES.filter((surface) => present.has(surface));
186
188
  }