@bastani/pi-ai 0.9.41-alpha.1 → 0.9.41-alpha.3

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +16 -2
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +2 -0
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -1
  7. package/dist/api/cloudflare-workers-ai-system-one.js +8 -0
  8. package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -1
  9. package/dist/api/openai-responses-shared.d.ts.map +1 -1
  10. package/dist/api/openai-responses-shared.js +1 -0
  11. package/dist/api/openai-responses-shared.js.map +1 -1
  12. package/dist/api/openrouter-images.js +1 -0
  13. package/dist/api/openrouter-images.js.map +1 -1
  14. package/dist/api/system-one-shared.d.ts +20 -4
  15. package/dist/api/system-one-shared.d.ts.map +1 -1
  16. package/dist/api/system-one-shared.js +49 -19
  17. package/dist/api/system-one-shared.js.map +1 -1
  18. package/dist/api/typesafe-system-one.d.ts.map +1 -1
  19. package/dist/api/typesafe-system-one.js +10 -3
  20. package/dist/api/typesafe-system-one.js.map +1 -1
  21. package/dist/models.d.ts.map +1 -1
  22. package/dist/models.js +1 -0
  23. package/dist/models.js.map +1 -1
  24. package/dist/providers/compat-schema.d.ts +18 -0
  25. package/dist/providers/compat-schema.d.ts.map +1 -1
  26. package/dist/providers/compat-schema.js +10 -0
  27. package/dist/providers/compat-schema.js.map +1 -1
  28. package/dist/providers/data/.manifest.json +1 -1
  29. package/dist/providers/data/cloudflare-workers-ai.json +1 -1
  30. package/dist/providers/data/opencode-go.json +1 -1
  31. package/dist/providers/data/opencode.json +1 -1
  32. package/dist/providers/data/openrouter.json +1 -1
  33. package/dist/providers/data/typesafe.json +1 -1
  34. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  35. package/dist/types.d.ts +6 -2
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/dist/utils/version.d.ts +1 -1
  39. package/dist/utils/version.js +1 -1
  40. package/dist/utils/version.js.map +1 -1
  41. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ This package is a Bastani fork of `@earendil-works/pi-ai`. Upstream history at t
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.9.41-alpha.3] - 2026-10-22
8
+
9
+ ### Added
10
+
11
+ - Added `Usage.cost.totalFromProvider`. It is `true` when `cost.total` is the billed cost reported by the provider and `false` when the total is estimated from the model's catalog rates, as `calculateCost()` and the image generators now record. A missing value, as in sessions recorded before this field existed, means `false`.
12
+
13
+ ## [0.9.41-alpha.2] - 2026-10-22
14
+
15
+ ### Added
16
+
17
+ - Added image input to more System One classifiers: `ClassifierContext.images` now also works with Jev and Clef on `cloudflare-workers-ai` and with OpenRouter decision models whose catalog lists image input, next to Jev on `typesafe`. Each service gets its own wire form: TypeSafe `assets` (PNG and JPEG) with the `TypeSafe-Danger-Zone-Images` opt-in header, Clef `images` data URLs (PNG, JPEG, and WebP, at most four), or OpenRouter `image_url` parts in the state. A text-only model's error now names the model: `System One API does not support image input for <model>`.
18
+ - Added `compat` to System One classifier models (`SystemOneCompat`, with `imageInput` and `sendImageOptInHeader`). Built-in catalog entries set it explicitly; models without it detect the form from the provider, `baseUrl`, and model ID.
19
+ - Added the `@cf/cloudflare/clef-omni` and `typesafe/jev-1.14.0` classifier models to `cloudflare-workers-ai`.
20
+
21
+ ### Fixed
22
+
23
+ - Fixed Cloudflare Workers AI classifier catalog data: Clef Flash now costs $0.038 per million input tokens with a 24,576-token context window, and Jev costs $0.042 per million input tokens instead of being listed as free.
24
+
7
25
  ## [0.9.41-alpha.1] - 2026-10-21
8
26
 
9
27
  ### Breaking Changes
package/README.md CHANGED
@@ -236,6 +236,8 @@ for (const block of response.content) {
236
236
  }
237
237
  ```
238
238
 
239
+ `usage.cost.totalFromProvider` is `true` when `usage.cost.total` is the billed cost reported by the provider and `false` when it is estimated from the model's catalog rates. A missing value, as in sessions recorded before this field existed, also means `false`.
240
+
239
241
  Snippets in the rest of this README assume a `models` collection set up like this (with the relevant providers registered).
240
242
 
241
243
  ## Providers and Models
@@ -935,8 +937,8 @@ Classifier models consume structured JSON state and answer one or more typed que
935
937
  | Provider | Model IDs | Auth |
936
938
  | --- | --- | --- |
937
939
  | `typesafe` | `jev-latest` | `TYPESAFE_API_KEY` |
938
- | `openrouter` | `typesafe/jev-1.13`, `~typesafe/jev-latest` | `OPENROUTER_API_KEY` or OpenRouter OAuth |
939
- | `cloudflare-workers-ai` | `typesafe/jev`, `@cf/cloudflare/clef`, `@cf/cloudflare/clef-flash` | `CLOUDFLARE_API_KEY` and `CLOUDFLARE_ACCOUNT_ID` |
940
+ | `openrouter` | `typesafe/jev-1.13`, `typesafe/jev-1.14`, `~typesafe/jev-latest`, `cloudflare/clef`, `cloudflare/clef-flash`, `cloudflare/clef-omni` | `OPENROUTER_API_KEY` or OpenRouter OAuth |
941
+ | `cloudflare-workers-ai` | `typesafe/jev`, `typesafe/jev-1.14.0`, `@cf/cloudflare/clef`, `@cf/cloudflare/clef-flash`, `@cf/cloudflare/clef-omni` | `CLOUDFLARE_API_KEY` and `CLOUDFLARE_ACCOUNT_ID` |
940
942
  | `vercel-ai-gateway` | `typesafe-ai/jev` | `AI_GATEWAY_API_KEY` |
941
943
  | `opencode` | `jev-1.13`, `jev-1.13-free` | `OPENCODE_API_KEY` |
942
944
 
@@ -978,6 +980,18 @@ System One results include `usage` when the service reports input or output toke
978
980
 
979
981
  `ClassifierOptions.temperature` divides the answer logits by the given value before they are normalized; values above 1 soften the distribution. APIs that cannot apply it, such as System One, ignore it.
980
982
 
983
+ ### System One images
984
+
985
+ `ClassifierContext.images` holds image blocks (`{ type: "image", data, mimeType }`) judged together with the state. Only models whose `input` includes `"image"` accept them; `classify()` returns an error result for other models. System One services take images in three forms. The model's `compat.imageInput` chooses the form (`"assets"`, `"images"`, or `"state-image-urls"`), and `compat.sendImageOptInHeader` controls TypeSafe's opt-in header:
986
+
987
+ - **TypeSafe** (`typesafe`, and Jev on Workers AI) takes PNG and JPEG images as `assets`, each under a fresh UUID reference that is also listed in order under `state.images`, so a state with its own `images` field cannot send images. Images are experimental on TypeSafe's own API and need the `TypeSafe-Danger-Zone-Images: true` header, which the API sends with requests that carry images.
988
+ - **Clef on Workers AI** takes up to four PNG, JPEG, or WebP images as an `images` list of data URLs, next to the unchanged state.
989
+ - **OpenRouter** takes images as `{ type: "image_url", image_url: { url } }` parts before the state: `[part, ..., state]`. It answers requests with `assets` but drops the images, without an error.
990
+
991
+ Built-in catalog entries set `compat` explicitly, so they keep their form when `baseUrl` points at a proxy. For models without it, the APIs detect the form: OpenRouter by provider `openrouter` or a `baseUrl` containing `openrouter.ai`, Clef by a model ID starting with `@cf/cloudflare/clef`, and TypeSafe's form with the opt-in header otherwise. A custom provider that reaches OpenRouter through a proxy matches neither check and must set `compat.imageInput: "state-image-urls"` and `compat.sendImageOptInHeader: false`; otherwise OpenRouter drops its images.
992
+
993
+ Vercel AI Gateway and OpenCode list their Jev models with text input only.
994
+
981
995
  ### Chat models on llama.cpp
982
996
 
983
997
  The `llama-cpp-classify` API turns a chat model served by llama.cpp's `llama-server` into a classifier. Each question becomes one chat prompt: the state, every question of the request, the state again, and the question with its answers under single-token labels (letters for a choice, `Yes`/`No` for a bool, digits for a score). The prompt up to the final question is shared by all questions of a request, so the server's prompt cache evaluates the state once per request. The server returns the log-probabilities of the next token, and the answer is the softmax over the label tokens. Choices support up to 62 options and scores up to 10 levels. The model's `baseUrl` is the server URL; a trailing `/v1` is ignored. In router mode, the model ID selects the model.
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAiC,MAAM,mBAAmB,CAAC;AAiBlE,OAAO,KA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AwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAqPhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AA4RD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAyZzE,CAAC;AA4BF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAgDlF,CAAC"}
@@ -156,6 +156,7 @@ function applyFastModePricing(usage) {
156
156
  usage.cost.cacheRead *= FAST_MODE_PRICE_MULTIPLIER;
157
157
  usage.cost.cacheWrite *= FAST_MODE_PRICE_MULTIPLIER;
158
158
  usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
159
+ usage.cost.totalFromProvider = false;
159
160
  }
160
161
  /**
161
162
  * Reject a payload hook that rewrote a field the model's fast route owns.
@@ -304,6 +305,7 @@ function addEarlierAttemptCosts(output, model, servingModel, event) {
304
305
  output.usage.cost.cacheRead += attemptUsage.cost.cacheRead;
305
306
  output.usage.cost.cacheWrite += attemptUsage.cost.cacheWrite;
306
307
  output.usage.cost.total += attemptUsage.cost.total;
308
+ output.usage.cost.totalFromProvider = false;
307
309
  }
308
310
  }
309
311
  function getAnthropicCompat(model) {