@shop-os/modelkit 0.1.2 → 0.1.4
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 +27 -21
- package/dist/index.cjs +408 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +408 -179
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,21 +81,27 @@ await generateText({ model: openai("gpt-4o"), prompt }); // pass-through: the SD
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
A pass-through model has no catalog row, so it gets no defaults and no key resolution,
|
|
84
|
-
and usage is attributed to its own `provider` and `modelId`.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
| `
|
|
93
|
-
|
|
|
84
|
+
and usage is attributed to its own `provider` and `modelId`. The kit still translates
|
|
85
|
+
the shared request into what `ai` accepts — image references ride inside the prompt and
|
|
86
|
+
`exactSize` becomes the SDK's `size`; video frames become `frameImages`, references
|
|
87
|
+
become `inputReferences`, and `generateAudio` passes through. Anything the SDK call
|
|
88
|
+
cannot express (image `quality`/`outputFormat`, video `sourceVideo`, tiered
|
|
89
|
+
`resolution`, ...) is dropped with an `option_ignored` warning, never silently. Use it
|
|
90
|
+
for a model the catalog does not carry yet; the next step is a catalog row.
|
|
91
|
+
|
|
92
|
+
| `ai` function | Here |
|
|
93
|
+
| ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
94
|
+
| `generateText`, `streamText` | Same. Catalog `providerOptions` are merged under the caller's; `prepareStep` model switches resolve through the catalog; usage per step. |
|
|
95
|
+
| `generateObject`, `streamObject` | Same, including `output: "array" \| "enum" \| "no-schema"`. |
|
|
96
|
+
| `generateImage` | Takes `n`, `size: "WxH"`, `aspectRatio`, `seed`, `abortSignal`, `providerOptions` plus the kit's `references`, `size: "2K"`, `quality`, `outputFormat`, `scaleFactor` (upscalers). Returns `image` and `images` with `uint8Array`, `base64`, `mediaType` next to `bytes`, `mime`; `outputUrl` when the provider hands back a URL. |
|
|
97
|
+
| `experimental_generateVideo` | The kit's `generateVideo` returns a job; `duration` is an alias of `durationSeconds`. An `ai` video model instance is wrapped as a settled job. The `ai` function is also re-exported as-is. |
|
|
98
|
+
| `experimental_generateSpeech`, `transcribe`, `embed`, `embedMany`, `rerank`, agents, UI streams | Re-exported from `ai` unchanged; the catalog has no rows for them. |
|
|
94
99
|
|
|
95
100
|
An optional second `CallContext` argument selects enterprise keys, adds cancellation
|
|
96
101
|
(combined with `abortSignal`), and sets `onUnsupported`. Package-level functions read
|
|
97
102
|
keys from the environment; a configured kit adds routing, catalog overrides, custom
|
|
98
|
-
fetch,
|
|
103
|
+
fetch, provider endpoint overrides (`endpoints.ark` for the Ark base url), logging, and
|
|
104
|
+
the `onUsage` sink.
|
|
99
105
|
|
|
100
106
|
`providerOptions` on `generateImage`/`generateVideo` reach the provider only for
|
|
101
107
|
pass-through instances; catalog rows carry their own and the caller's are dropped
|
|
@@ -111,16 +117,16 @@ The kit keeps its `Warning` type for coercions; the SDK's warning type is `AiWar
|
|
|
111
117
|
|
|
112
118
|
## What the package owns
|
|
113
119
|
|
|
114
|
-
| Concern | Rule
|
|
115
|
-
| ----------- |
|
|
116
|
-
| Ids | `id` is the pro-backend pricing key. Every historical id (`nb-pro`, `veo-3.1-generate-001`, `kling-v2.5-turbo-pro`) is an alias.
|
|
117
|
-
| Options | `resolveOptions` fills catalog defaults, coerces aspect ratio to the nearest supported one, errors on unsupported size or resolution (`onUnsupported: "coerce"` snaps down instead), clamps duration, trims references (audio first, then video), and drops options the model ignores with a warning.
|
|
118
|
-
| Keys | Enterprise keys win only when every key the adapter needs is set on the enterprise tier.
|
|
119
|
-
| Routing | Cloudflare AI Gateway for text only. Never for Gemini images or Omni. fal passthrough for geo-blocked regions. OpenRouter optional for text.
|
|
120
|
-
| Retry | One classifier. Never on content blocks or 4xx except 429.
|
|
121
|
-
| Errors | `ModelKitError` with `code`, `provider`, `status`, `body`. Gemini `blockReason` and fal `body.detail` are lifted into `body`.
|
|
122
|
-
| Usage | One event per call with the canonical model id. Video usage is emitted on completion. 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. |
|
|
123
|
-
| 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.
|
|
120
|
+
| Concern | Rule |
|
|
121
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
122
|
+
| Ids | `id` is the pro-backend pricing key. Every historical id (`nb-pro`, `veo-3.1-generate-001`, `kling-v2.5-turbo-pro`) is an alias. |
|
|
123
|
+
| Options | Image tiers are `512` (Gemini 3.1 Flash only), `1K`, `2K`, `4K`. `resolveOptions` fills catalog defaults, coerces aspect ratio to the nearest supported one, errors on unsupported size or resolution (`onUnsupported: "coerce"` snaps down instead), clamps duration, trims references (audio first, then video), and drops options the model ignores with a warning. |
|
|
124
|
+
| Keys | Enterprise keys win only when every key the adapter (and its route, e.g. the cloudflare token for gateway-routed text) needs is set on the enterprise tier. |
|
|
125
|
+
| Routing | Cloudflare AI Gateway for text only. Never for Gemini images or Omni. fal passthrough for geo-blocked regions. OpenRouter optional for text. |
|
|
126
|
+
| Retry | One classifier. Never on content blocks or 4xx except 429. |
|
|
127
|
+
| Errors | `ModelKitError` with `code`, `provider`, `status`, `body`. Gemini `blockReason` and fal `body.detail` are lifted into `body`. |
|
|
128
|
+
| Usage | One event per call with the canonical model id. 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. 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. |
|
|
129
|
+
| 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. |
|
|
124
130
|
|
|
125
131
|
## Add a model
|
|
126
132
|
|