@bastani/pi-ai 0.9.40 → 0.9.41-alpha.2

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 (129) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +42 -2
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +7 -10
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/azure-openai-responses.js +2 -2
  7. package/dist/api/azure-openai-responses.js.map +1 -1
  8. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  9. package/dist/api/bedrock-converse-stream.js +12 -0
  10. package/dist/api/bedrock-converse-stream.js.map +1 -1
  11. package/dist/api/classifier-shared.d.ts.map +1 -1
  12. package/dist/api/classifier-shared.js +4 -3
  13. package/dist/api/classifier-shared.js.map +1 -1
  14. package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -1
  15. package/dist/api/cloudflare-workers-ai-system-one.js +8 -0
  16. package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -1
  17. package/dist/api/google-generative-ai.js +4 -4
  18. package/dist/api/google-generative-ai.js.map +1 -1
  19. package/dist/api/google-vertex.d.ts.map +1 -1
  20. package/dist/api/google-vertex.js +9 -9
  21. package/dist/api/google-vertex.js.map +1 -1
  22. package/dist/api/llama-cpp-classify.d.ts.map +1 -1
  23. package/dist/api/llama-cpp-classify.js +2 -1
  24. package/dist/api/llama-cpp-classify.js.map +1 -1
  25. package/dist/api/mistral-conversations.js +2 -2
  26. package/dist/api/mistral-conversations.js.map +1 -1
  27. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  28. package/dist/api/openai-codex-responses.js +12 -9
  29. package/dist/api/openai-codex-responses.js.map +1 -1
  30. package/dist/api/openai-completions.d.ts.map +1 -1
  31. package/dist/api/openai-completions.js +4 -4
  32. package/dist/api/openai-completions.js.map +1 -1
  33. package/dist/api/openai-responses.d.ts.map +1 -1
  34. package/dist/api/openai-responses.js +15 -7
  35. package/dist/api/openai-responses.js.map +1 -1
  36. package/dist/api/openrouter-images.d.ts.map +1 -1
  37. package/dist/api/openrouter-images.js +4 -3
  38. package/dist/api/openrouter-images.js.map +1 -1
  39. package/dist/api/pi-messages.d.ts.map +1 -1
  40. package/dist/api/pi-messages.js +3 -3
  41. package/dist/api/pi-messages.js.map +1 -1
  42. package/dist/api/simple-options.d.ts.map +1 -1
  43. package/dist/api/simple-options.js +1 -0
  44. package/dist/api/simple-options.js.map +1 -1
  45. package/dist/api/system-one-shared.d.ts +20 -4
  46. package/dist/api/system-one-shared.d.ts.map +1 -1
  47. package/dist/api/system-one-shared.js +49 -19
  48. package/dist/api/system-one-shared.js.map +1 -1
  49. package/dist/api/typesafe-system-one.d.ts.map +1 -1
  50. package/dist/api/typesafe-system-one.js +10 -3
  51. package/dist/api/typesafe-system-one.js.map +1 -1
  52. package/dist/auth/oauth/anthropic.d.ts.map +1 -1
  53. package/dist/auth/oauth/anthropic.js +15 -2
  54. package/dist/auth/oauth/anthropic.js.map +1 -1
  55. package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
  56. package/dist/auth/oauth/github-copilot.js +7 -2
  57. package/dist/auth/oauth/github-copilot.js.map +1 -1
  58. package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
  59. package/dist/auth/oauth/kimi-coding.js +24 -21
  60. package/dist/auth/oauth/kimi-coding.js.map +1 -1
  61. package/dist/auth/oauth/meta.d.ts.map +1 -1
  62. package/dist/auth/oauth/meta.js +7 -2
  63. package/dist/auth/oauth/meta.js.map +1 -1
  64. package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -1
  65. package/dist/auth/oauth/openai-chatgpt.js +10 -0
  66. package/dist/auth/oauth/openai-chatgpt.js.map +1 -1
  67. package/dist/auth/oauth/openai-codex.d.ts.map +1 -1
  68. package/dist/auth/oauth/openai-codex.js +11 -2
  69. package/dist/auth/oauth/openai-codex.js.map +1 -1
  70. package/dist/auth/oauth/radius.d.ts.map +1 -1
  71. package/dist/auth/oauth/radius.js +24 -8
  72. package/dist/auth/oauth/radius.js.map +1 -1
  73. package/dist/auth/oauth/xai.d.ts.map +1 -1
  74. package/dist/auth/oauth/xai.js +11 -0
  75. package/dist/auth/oauth/xai.js.map +1 -1
  76. package/dist/auth/oauth-refresh-errors.d.ts +46 -0
  77. package/dist/auth/oauth-refresh-errors.d.ts.map +1 -0
  78. package/dist/auth/oauth-refresh-errors.js +150 -0
  79. package/dist/auth/oauth-refresh-errors.js.map +1 -0
  80. package/dist/auth/resolve.d.ts +23 -0
  81. package/dist/auth/resolve.d.ts.map +1 -1
  82. package/dist/auth/resolve.js +194 -5
  83. package/dist/auth/resolve.js.map +1 -1
  84. package/dist/index.d.ts +3 -0
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +3 -0
  87. package/dist/index.js.map +1 -1
  88. package/dist/models.d.ts +4 -1
  89. package/dist/models.d.ts.map +1 -1
  90. package/dist/models.js +15 -4
  91. package/dist/models.js.map +1 -1
  92. package/dist/providers/compat-schema.d.ts +18 -0
  93. package/dist/providers/compat-schema.d.ts.map +1 -1
  94. package/dist/providers/compat-schema.js +10 -0
  95. package/dist/providers/compat-schema.js.map +1 -1
  96. package/dist/providers/data/.manifest.json +1 -1
  97. package/dist/providers/data/amazon-bedrock.json +1 -1
  98. package/dist/providers/data/baseten.json +1 -1
  99. package/dist/providers/data/cerebras.json +1 -1
  100. package/dist/providers/data/cloudflare-workers-ai.json +1 -1
  101. package/dist/providers/data/github-copilot.json +1 -1
  102. package/dist/providers/data/groq.json +1 -1
  103. package/dist/providers/data/huggingface.json +1 -1
  104. package/dist/providers/data/nvidia.json +1 -1
  105. package/dist/providers/data/opencode.json +1 -1
  106. package/dist/providers/data/openrouter.json +1 -1
  107. package/dist/providers/data/radius.json +1 -1
  108. package/dist/providers/data/together.json +1 -1
  109. package/dist/providers/data/typesafe.json +1 -1
  110. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  111. package/dist/types.d.ts +10 -2
  112. package/dist/types.d.ts.map +1 -1
  113. package/dist/types.js.map +1 -1
  114. package/dist/utils/identity.d.ts +65 -0
  115. package/dist/utils/identity.d.ts.map +1 -0
  116. package/dist/utils/identity.js +142 -0
  117. package/dist/utils/identity.js.map +1 -0
  118. package/dist/utils/retry.d.ts.map +1 -1
  119. package/dist/utils/retry.js +9 -8
  120. package/dist/utils/retry.js.map +1 -1
  121. package/dist/utils/version.d.ts +2 -0
  122. package/dist/utils/version.d.ts.map +1 -0
  123. package/dist/utils/version.js +3 -0
  124. package/dist/utils/version.js.map +1 -0
  125. package/package.json +2 -2
  126. package/dist/utils/pi-user-agent.d.ts +0 -2
  127. package/dist/utils/pi-user-agent.d.ts.map +0 -1
  128. package/dist/utils/pi-user-agent.js +0 -12
  129. package/dist/utils/pi-user-agent.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,41 @@ 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.2] - 2026-10-22
8
+
9
+ ### Added
10
+
11
+ - 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>`.
12
+ - 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.
13
+ - Added the `@cf/cloudflare/clef-omni` and `typesafe/jev-1.14.0` classifier models to `cloudflare-workers-ai`.
14
+
15
+ ### Fixed
16
+
17
+ - 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.
18
+
19
+ ## [0.9.41-alpha.1] - 2026-10-21
20
+
21
+ ### Breaking Changes
22
+
23
+ - The default `User-Agent` is now `pi/<version> (<platform>; <runtime>; <arch>)` instead of `pi (<platform> <release>; <arch>)`, and `@bastani/pi-ai/utils/pi-user-agent` (`getPiUserAgent()`) is removed; use `formatUserAgent()`.
24
+
25
+ ### Added
26
+
27
+ - Added client identity configuration: an `identity` request option and `createModels({ identity })` default choose the `User-Agent` (`"detailed"` with a version, `"short"`, or custom) and provider attribution headers for OpenRouter, NVIDIA NIM, and OpenCode from `attribution: { name, url, categories? }`. `withClientIdentity()` applies an identity to a `Models` or `MutableModels` a library receives from its host. `formatUserAgent()`, `getIdentityHeaders()`, `getOpenCodeSessionHeaders()`, `mergeClientIdentity()`, `PI_ATTRIBUTION`, and `PI_AI_VERSION` are exported. Attribution matches OpenRouter by its exact `openrouter.ai` host, so a custom endpoint that merely contains that name is not attributed.
28
+ - Bedrock, OpenRouter image generation, pi-messages, and classifier requests now send pi's `User-Agent` too.
29
+ - `Models` requests with a `sessionId` to custom providers pointing at OpenCode (`opencode.ai`) now send the `x-opencode-session` header too, like the built-in OpenCode providers.
30
+
31
+ ### Fixed
32
+
33
+ - `refreshStoredOAuthCredential()` no longer aborts a token exchange when its caller stops waiting. A token rotation that completes after the 60-second refresh timeout is now saved instead of leaving the replaced refresh token stored. The refresh keeps the credential lock until the exchange settles, for up to `OAUTH_REFRESH_LOCK_HOLD_MS`, so no other refresh presents the token it may already have rotated. When the provider rejects a refresh, it returns a newer credential that another process has saved. A refresh rejected with `invalid_grant` reports only the provider's error code and description, never request URLs, bodies, or tokens, followed by an instruction to run `/login <provider>`. `OAUTH_REFRESH_TIMEOUT_MS` and `OAUTH_REFRESH_LOCK_HOLD_MS` are exported.
34
+ - Anthropic OAuth no longer cuts off a token refresh request after 30 seconds, because the provider may already have rotated the refresh token. The 30-second limit still applies to the login code exchange.
35
+ - Kimi Code OAuth no longer cuts off a token refresh request after 30 seconds. It also no longer sends the same refresh token again after an attempt that may have reached the server (a timeout, an abort, a connection lost mid-request, or an HTTP 429 or 5xx response), because the server may already have rotated that token. A refresh is retried only when the connection was never made. The 30-second limit still applies to device login.
36
+ - A refresh rejected because the stored login is revoked or expired now tells you to run `/login <provider>` for more cases than a literal `invalid_grant`. This includes OpenAI's `refresh_token_expired`, `refresh_token_invalidated` and `refresh_token_reused` codes (also in a nested `error.code`), any HTTP 401 from a token endpoint, Kimi Code's 401 and 403 responses, Meta's expired session, and a revoked GitHub Copilot login. Built-in refreshers throw the new exported `OAuthRefreshRejectedError`, which carries only the HTTP status and the provider's error code and description. Custom refreshers can throw it too, and `refreshStoredOAuthCredential()` maps it to the `/login <provider>` message. The description is dropped when it contains the presented token or a URL. Kimi Code's own refresh errors no longer include the provider's raw error description. `isOAuthRefreshRejectedError`, `isPermanentRefreshRejection`, `parseOAuthErrorBody` and the `OAuthRefreshRejection` and `OAuthErrorDetail` types are exported alongside it.
37
+ - A token rotation that completes after its caller stopped waiting is no longer lost when the process exits. The new `drainPendingOAuthRotations(timeoutMs = OAUTH_SHUTDOWN_DRAIN_MS)` waits, for at most `OAUTH_SHUTDOWN_DRAIN_MS` (3 seconds) by default, until every token exchange that has started settles and its result is saved. It resolves `true` when none is left and `false` when the bound passes first, and never rejects. Hosts call it before a graceful exit. A process killed or crashing mid-exchange still cannot save a rotation it never received; `/login <provider>` signs in again. If a late rotation succeeds but saving it fails, the next refresh failure for that provider adds that an earlier refresh succeeded but its new login could not be saved, with only the save error's code or name (for example `ELOCKED`).
38
+ - Sign in with ChatGPT: a ChatGPT Business workspace usage-limit error (`subscription_sharing_workplace_individual_usage_limit_exceeded`) is no longer classified as a transient error to retry, and its message now tells you to ask your workspace admin to increase the limit.
39
+ - Fixed automatic retry not triggering for `stream disconnected before completion` errors relayed by proxies that wrap the Codex CLI ([#11057](https://github.com/earendil-works/pi/issues/11057))
40
+ - Fixed automatic retry treating digits inside request ids or other numbers (for example `req_011CU503xyz` or `5242880 bytes`) as retryable HTTP status codes. Status codes 429, 500, 502-504 and 520-524 now match only as standalone numbers ([#11057](https://github.com/earendil-works/pi/issues/11057))
41
+
7
42
  ## [0.9.40] - 2026-10-20
8
43
 
9
44
  ### Breaking Changes
package/README.md CHANGED
@@ -22,6 +22,7 @@ Unified LLM API with provider collections, automatic auth resolution, token and
22
22
  - [Auth](#auth)
23
23
  - [How Auth Resolves](#how-auth-resolves)
24
24
  - [Transforming Request Headers](#transforming-request-headers)
25
+ - [Client Identity](#client-identity)
25
26
  - [Credential Store](#credential-store)
26
27
  - [Environment Variables](#environment-variables)
27
28
  - [Tools](#tools)
@@ -432,6 +433,33 @@ Header names are merged case-insensitively. Explicit headers override auth/model
432
433
 
433
434
  `transformHeaders` belongs to `Models`, not `Provider`. A `Models` implementation must consume it and remove it before calling `Provider.stream*()`. Provider implementations continue receiving ordinary `ApiStreamOptions` or `SimpleStreamOptions` and never handle the transform themselves. Use this option instead of calling `getAuth(model)` before `stream*()`, which would resolve request auth twice.
434
435
 
436
+ ### Client Identity
437
+
438
+ `identity` controls how requests identify the calling app to providers. Set it on `createModels()` as a default, or per request; a request's fields override the `Models` default field by field:
439
+
440
+ ```typescript
441
+ const models = createModels({
442
+ identity: {
443
+ userAgent: 'detailed',
444
+ version: '2.1.0',
445
+ attribution: { name: 'my-app', url: 'https://my-app.example', categories: ['cloud-agent'] },
446
+ },
447
+ });
448
+
449
+ await models.completeSimple(model, context, { identity: { attribution: null } });
450
+ ```
451
+
452
+ - `userAgent`: `"detailed"` (default) sends `pi/<version> (<platform>; <runtime>; <arch>)`, `"short"` sends `pi`, and `{ custom: "..." }` sends the given value. On Bedrock the value is appended to the AWS SDK user agent.
453
+ - `version`: the version in the detailed `User-Agent`. Default: the pi-ai version.
454
+ - `attribution`: provider attribution headers. Absent (default) or `null` sends none; `null` also turns off attribution from a merged identity. `{ name, url, categories? }` maps to each provider's headers:
455
+ - OpenRouter: `HTTP-Referer: <url>` (the app's identity in OpenRouter's rankings, grouped by origin), `X-OpenRouter-Title: <name>`, and `X-OpenRouter-Categories` (comma-separated).
456
+ - NVIDIA NIM: `X-BILLING-INVOKE-ORIGIN: <name>` with its first letter upper-cased.
457
+ - OpenCode: `x-opencode-client: <name>`.
458
+
459
+ `PI_ATTRIBUTION` is pi's: `{ name: "pi", url: "https://pi.dev", categories: ["cli-agent"] }`.
460
+
461
+ Identity headers are defaults below provider, model, and request headers, so configured headers win and a `null` request header removes one. Providers that send a fixed client identity, such as GitHub Copilot and Anthropic OAuth, keep it. `withClientIdentity(models, identity)` returns a wrapper of a `Models` (or `MutableModels`) whose requests use `identity` over the one the `Models` was created with, for libraries that receive a `Models` from their host. `identity` is plain JSON, so it can be persisted with other request options.
462
+
435
463
  ### Credential Store
436
464
 
437
465
  Stored credentials (API keys entered interactively, OAuth tokens) live in a `CredentialStore` — one type-tagged credential per provider. pi-ai ships an in-memory default; apps inject persistent storage:
@@ -907,8 +935,8 @@ Classifier models consume structured JSON state and answer one or more typed que
907
935
  | Provider | Model IDs | Auth |
908
936
  | --- | --- | --- |
909
937
  | `typesafe` | `jev-latest` | `TYPESAFE_API_KEY` |
910
- | `openrouter` | `typesafe/jev-1.13`, `~typesafe/jev-latest` | `OPENROUTER_API_KEY` or OpenRouter OAuth |
911
- | `cloudflare-workers-ai` | `typesafe/jev`, `@cf/cloudflare/clef`, `@cf/cloudflare/clef-flash` | `CLOUDFLARE_API_KEY` and `CLOUDFLARE_ACCOUNT_ID` |
938
+ | `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 |
939
+ | `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` |
912
940
  | `vercel-ai-gateway` | `typesafe-ai/jev` | `AI_GATEWAY_API_KEY` |
913
941
  | `opencode` | `jev-1.13`, `jev-1.13-free` | `OPENCODE_API_KEY` |
914
942
 
@@ -950,6 +978,18 @@ System One results include `usage` when the service reports input or output toke
950
978
 
951
979
  `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.
952
980
 
981
+ ### System One images
982
+
983
+ `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:
984
+
985
+ - **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.
986
+ - **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.
987
+ - **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.
988
+
989
+ 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.
990
+
991
+ Vercel AI Gateway and OpenCode list their Jev models with text input only.
992
+
953
993
  ### Chat models on llama.cpp
954
994
 
955
995
  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,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAOb,MAAM,aAAa,CAAC;AAwKrB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAmPhE,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;AAgSD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAwZzE,CAAC;AA4BF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAgDlF,CAAC"}
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,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAOb,MAAM,aAAa,CAAC;AAwKrB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAmPhE,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"}
@@ -5,8 +5,8 @@ import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
5
5
  import { assertSupportedDocumentMimeType } from "../utils/document-input.js";
6
6
  import { AssistantMessageEventStream } from "../utils/event-stream.js";
7
7
  import { headersToRecord } from "../utils/headers.js";
8
+ import { getIdentityHeaders } from "../utils/identity.js";
8
9
  import { parseJsonWithRepair, parseStreamingJson, parseToolCallArguments } from "../utils/json-parse.js";
9
- import { getPiUserAgent } from "../utils/pi-user-agent.js";
10
10
  import { getProviderEnvValue } from "../utils/provider-env.js";
11
11
  import { retryProviderRequest } from "../utils/provider-retry.js";
12
12
  import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
@@ -330,9 +330,6 @@ function mergeHeaders(...headerSources) {
330
330
  }
331
331
  return merged;
332
332
  }
333
- function mergeClientHeaders(...headerSources) {
334
- return mergeHeaders({ "User-Agent": getPiUserAgent() }, ...headerSources);
335
- }
336
333
  function hasHeader(headers, name) {
337
334
  if (!headers)
338
335
  return false;
@@ -606,7 +603,7 @@ export const stream = (model, context, options) => {
606
603
  const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
607
604
  const created = createClient(model, apiKey, model.reasoning && options?.thinkingEnabled === true && (options.interleavedThinking ?? true), shouldUseFineGrainedToolStreamingBeta(model, context), shouldUseServerSideFallbackBeta(model), options?.headers, options?.fetch, copilotDynamicHeaders, cacheSessionId, getAnthropicCompat(model).supportsMidConvoToolChanges &&
608
605
  getAnthropicCompat(model).supportsMidConvoSystemMessages &&
609
- (getInitialSystemMessage(normalizedContext.messages)?.toolsAdded?.length ?? 0) > 0, federation);
606
+ (getInitialSystemMessage(normalizedContext.messages)?.toolsAdded?.length ?? 0) > 0, federation, options?.identity);
610
607
  client = created.client;
611
608
  isOAuth = created.isOAuthToken;
612
609
  }
@@ -993,7 +990,7 @@ export const streamSimple = (model, context, options) => {
993
990
  function isOAuthToken(apiKey) {
994
991
  return apiKey.includes("sk-ant-oat");
995
992
  }
996
- function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStreamingBeta, useServerSideFallbackBeta, optionsHeaders, fetch, dynamicHeaders, sessionId, useNativeToolChanges = false, federation) {
993
+ function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStreamingBeta, useServerSideFallbackBeta, optionsHeaders, fetch, dynamicHeaders, sessionId, useNativeToolChanges = false, federation, identity) {
997
994
  // Adaptive thinking models have interleaved thinking built in, so skip the beta header.
998
995
  const needsInterleavedBeta = interleavedThinking && model.compat?.forceAdaptiveThinking !== true;
999
996
  const betaFeatures = [];
@@ -1025,7 +1022,7 @@ function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStre
1025
1022
  baseURL: model.baseUrl,
1026
1023
  dangerouslyAllowBrowser: true,
1027
1024
  fetch,
1028
- defaultHeaders: mergeClientHeaders({
1025
+ defaultHeaders: mergeHeaders(getIdentityHeaders(model, identity), {
1029
1026
  accept: "application/json",
1030
1027
  "anthropic-dangerous-direct-browser-access": "true",
1031
1028
  ...(uniqueBetaFeatures.length > 0 ? { "anthropic-beta": uniqueBetaFeatures.join(",") } : {}),
@@ -1033,7 +1030,7 @@ function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStre
1033
1030
  });
1034
1031
  return { client, isOAuthToken: false };
1035
1032
  }
1036
- // OAuth: Bearer auth, Claude Code identity headers
1033
+ // OAuth: Bearer auth, Claude Code identity headers instead of the client identity.
1037
1034
  if (apiKey && isOAuthToken(apiKey)) {
1038
1035
  const client = new AtomicAnthropic({
1039
1036
  apiKey: null,
@@ -1041,7 +1038,7 @@ function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStre
1041
1038
  baseURL: model.baseUrl,
1042
1039
  dangerouslyAllowBrowser: true,
1043
1040
  fetch,
1044
- defaultHeaders: mergeClientHeaders({
1041
+ defaultHeaders: mergeHeaders({
1045
1042
  accept: "application/json",
1046
1043
  "anthropic-dangerous-direct-browser-access": "true",
1047
1044
  "anthropic-beta": ["claude-code-20250219", "oauth-2025-04-20", ...uniqueBetaFeatures].join(","),
@@ -1058,7 +1055,7 @@ function createClient(model, apiKey, interleavedThinking, useFineGrainedToolStre
1058
1055
  const header = compat.sessionAffinityFormat === "openrouter" ? "x-session-id" : "x-session-affinity";
1059
1056
  sessionAffinityHeaders[header] = sessionId;
1060
1057
  }
1061
- const defaultHeaders = mergeClientHeaders({
1058
+ const defaultHeaders = mergeHeaders(getIdentityHeaders(model, identity), {
1062
1059
  accept: "application/json",
1063
1060
  "anthropic-dangerous-direct-browser-access": "true",
1064
1061
  ...(uniqueBetaFeatures.length > 0 ? { "anthropic-beta": uniqueBetaFeatures.join(",") } : {}),