johns-harness 2026.10.21 → 2026.10.22

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 (72) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +3 -0
  3. package/dist/auth-profiles-5CHn7vq1.js +4 -2
  4. package/dist/compact-B247y5Qt.js +28 -69
  5. package/dist/config-koj5M_EO.js +4 -2
  6. package/dist/daemon-cli.js +4 -2
  7. package/dist/model-selection-BGlGpPgM.js +4 -2
  8. package/dist/model-selection-BU6wl1le.js +4 -2
  9. package/dist/model-selection-L7RMwsG-.js +4 -2
  10. package/dist/pi-embedded-C6ITuRXf.js +29 -84
  11. package/dist/pi-embedded-DoQsYfIY.js +29 -84
  12. package/dist/plugin-sdk/bluebubbles.js +2 -1
  13. package/dist/plugin-sdk/config/types.models.d.ts +1 -0
  14. package/dist/plugin-sdk/config/zod-schema.core.d.ts +3 -0
  15. package/dist/plugin-sdk/config/zod-schema.d.ts +1 -0
  16. package/dist/plugin-sdk/config-4Fgm-yEH.js +4 -2
  17. package/dist/plugin-sdk/config-Di-lyCdh.js +4 -2
  18. package/dist/plugin-sdk/discord.js +4 -2
  19. package/dist/plugin-sdk/dispatch-BP0viZiL.js +29 -84
  20. package/dist/plugin-sdk/dispatch-CQsjmw7g.js +29 -84
  21. package/dist/plugin-sdk/dispatch-Cerq29sy.js +29 -84
  22. package/dist/plugin-sdk/dispatch-Cndjtt0g.js +29 -84
  23. package/dist/plugin-sdk/dispatch-UogiJYul.js +29 -84
  24. package/dist/plugin-sdk/feishu.js +2 -1
  25. package/dist/plugin-sdk/googlechat.js +2 -1
  26. package/dist/plugin-sdk/imessage.js +2 -1
  27. package/dist/plugin-sdk/model-auth-CX9cPHdC.js +4 -2
  28. package/dist/plugin-sdk/model-auth-Ciehz0x5.js +4 -2
  29. package/dist/plugin-sdk/model-auth-DVyo6JSX.js +4 -2
  30. package/dist/plugin-sdk/model-auth-kiHYHGrs.js +4 -2
  31. package/dist/plugin-sdk/model-selection-Dbj4jDYM.js +4 -2
  32. package/dist/plugin-sdk/nostr.js +2 -1
  33. package/dist/plugin-sdk/reply-DbZnH8-h.js +29 -84
  34. package/dist/plugin-sdk/signal.js +2 -1
  35. package/dist/plugin-sdk/slack.js +2 -1
  36. package/dist/plugin-sdk/telegram.js +2 -1
  37. package/dist/plugin-sdk/tlon.js +2 -1
  38. package/dist/plugin-sdk/twitch.js +2 -1
  39. package/dist/plugin-sdk/utils/usage-format.d.ts +1 -0
  40. package/dist/plugin-sdk/voice-call.js +2 -1
  41. package/dist/plugin-sdk/zalo.js +2 -1
  42. package/dist/plugin-sdk/zalouser.js +2 -1
  43. package/dist/reply-C5LKjXcC.js +28 -69
  44. package/dist/session-cost-usage-5CCZbVhO.js +4 -19
  45. package/dist/session-cost-usage-CkCo2kVx.js +4 -19
  46. package/dist/usage-billing.js +88 -0
  47. package/dist/usage-format-CNGi1eHQ.js +6 -11
  48. package/dist/usage-format-CvaU1ntA.js +6 -11
  49. package/docs/PATCHES.md +13 -1
  50. package/docs/providers/anthropic.md +8 -2
  51. package/docs/reference/token-use.md +11 -1
  52. package/models/models.json +33 -33
  53. package/node_modules/@mariozechner/pi-ai/dist/models.d.ts +1 -0
  54. package/node_modules/@mariozechner/pi-ai/dist/models.generated.js +32 -32
  55. package/node_modules/@mariozechner/pi-ai/dist/models.js +16 -5
  56. package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
  57. package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +1 -1
  58. package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +1 -1
  59. package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
  60. package/node_modules/@mariozechner/pi-ai/dist/types.d.ts +3 -0
  61. package/node_modules/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
  62. package/package.json +1 -1
  63. package/scripts/models-sync.mjs +1 -0
  64. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.d.ts +25 -0
  65. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.generated.js +32 -32
  66. package/vendor/patched-deps/@mariozechner/pi-ai/dist/models.js +16 -5
  67. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/anthropic.js +15 -0
  68. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google-vertex.js +371 -0
  69. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/google.js +1 -1
  70. package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/openai-completions.js +5 -5
  71. package/vendor/patched-deps/@mariozechner/pi-ai/dist/types.d.ts +282 -0
  72. package/vendor/patched-deps/@mariozechner/pi-coding-agent/dist/core/model-registry.js +3 -0
@@ -108,6 +108,7 @@ export function validateMaster(master) {
108
108
  // Upstream pi-ai marks router-priced entries (openrouter/auto) with a negative sentinel cost.
109
109
  if (!cost || ["input", "output", "cacheRead", "cacheWrite"].some((k) => typeof cost[k] !== "number" || !Number.isFinite(cost[k]))) problems.push(`${ref}: cost needs numeric input/output/cacheRead/cacheWrite`);
110
110
  if ("id" in entry || "provider" in entry) problems.push(`${ref}: id/provider come from the keys; remove them from the entry`);
111
+ if (cost?.cacheWrite1h !== undefined && (typeof cost.cacheWrite1h !== "number" || !Number.isFinite(cost.cacheWrite1h) || cost.cacheWrite1h < 0)) problems.push(`${ref}: cost.cacheWrite1h must be a nonnegative price`);
111
112
  const h = entry.harness;
112
113
  if (h !== undefined) {
113
114
  if (h?.image !== undefined) {
@@ -0,0 +1,25 @@
1
+ import { MODELS } from "./models.generated.js";
2
+ import type { Api, KnownProvider, Model, Usage } from "./types.js";
3
+ type ModelApi<TProvider extends KnownProvider, TModelId extends keyof (typeof MODELS)[TProvider]> = (typeof MODELS)[TProvider][TModelId] extends {
4
+ api: infer TApi;
5
+ } ? (TApi extends Api ? TApi : never) : never;
6
+ export declare function getModel<TProvider extends KnownProvider, TModelId extends keyof (typeof MODELS)[TProvider]>(provider: TProvider, modelId: TModelId): Model<ModelApi<TProvider, TModelId>>;
7
+ export declare function getProviders(): KnownProvider[];
8
+ export declare function getModels<TProvider extends KnownProvider>(provider: TProvider): Model<ModelApi<TProvider, keyof (typeof MODELS)[TProvider]>>[];
9
+ export declare function calculateCost<TApi extends Api>(model: Model<TApi>, usage: Usage): Usage["cost"];
10
+ export declare function johnnessUsageCost(usage: Partial<Usage>, rates: Model<Api>["cost"]): Usage["cost"] | undefined;
11
+ /**
12
+ * Check if a model supports xhigh thinking level.
13
+ *
14
+ * Supported today:
15
+ * - GPT-5.2 / GPT-5.3 model families
16
+ * - Anthropic Messages API Opus 4.6 models (xhigh maps to adaptive effort "max")
17
+ */
18
+ export declare function supportsXhigh<TApi extends Api>(model: Model<TApi>): boolean;
19
+ /**
20
+ * Check if two models are equal by comparing both their id and provider.
21
+ * Returns false if either model is null or undefined.
22
+ */
23
+ export declare function modelsAreEqual<TApi extends Api>(a: Model<TApi> | null | undefined, b: Model<TApi> | null | undefined): boolean;
24
+ export {};
25
+ //# sourceMappingURL=models.d.ts.map
@@ -13742,38 +13742,38 @@ const JOHNNESS_MODELS_MASTER = {
13742
13742
  "zai.glm-4.7-flash":{"id":"zai.glm-4.7-flash","name":"GLM-4.7-Flash","api":"bedrock-converse-stream","provider":"amazon-bedrock","baseUrl":"https://bedrock-runtime.us-east-1.amazonaws.com","reasoning":true,"input":["text"],"cost":{"input":0.07,"output":0.4,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":131072},
13743
13743
  },
13744
13744
  "anthropic": {
13745
- "claude-3-5-haiku-20241022":{"id":"claude-3-5-haiku-20241022","name":"Claude Haiku 3.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.8,"output":4,"cacheRead":0.08,"cacheWrite":1},"contextWindow":200000,"maxTokens":8192},
13746
- "claude-3-5-haiku-latest":{"id":"claude-3-5-haiku-latest","name":"Claude Haiku 3.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.8,"output":4,"cacheRead":0.08,"cacheWrite":1},"contextWindow":200000,"maxTokens":8192},
13747
- "claude-3-5-sonnet-20240620":{"id":"claude-3-5-sonnet-20240620","name":"Claude Sonnet 3.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":8192},
13748
- "claude-3-5-sonnet-20241022":{"id":"claude-3-5-sonnet-20241022","name":"Claude Sonnet 3.5 v2","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":8192},
13749
- "claude-3-7-sonnet-20250219":{"id":"claude-3-7-sonnet-20250219","name":"Claude Sonnet 3.7","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13750
- "claude-3-7-sonnet-latest":{"id":"claude-3-7-sonnet-latest","name":"Claude Sonnet 3.7 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13751
- "claude-3-haiku-20240307":{"id":"claude-3-haiku-20240307","name":"Claude Haiku 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.25,"output":1.25,"cacheRead":0.03,"cacheWrite":0.3},"contextWindow":200000,"maxTokens":4096},
13752
- "claude-3-opus-20240229":{"id":"claude-3-opus-20240229","name":"Claude Opus 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75},"contextWindow":200000,"maxTokens":4096},
13753
- "claude-3-sonnet-20240229":{"id":"claude-3-sonnet-20240229","name":"Claude Sonnet 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0.3},"contextWindow":200000,"maxTokens":4096},
13754
- "claude-fable-5-1":{"id":"claude-fable-5-1","name":"Claude Fable 5.1","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":10,"output":50,"cacheRead":0.25,"cacheWrite":12.5},"contextWindow":300000,"maxTokens":128000},
13755
- "claude-sonnet-5-5":{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":2,"output":10,"cacheRead":0.1,"cacheWrite":2.5},"contextWindow":1000000,"maxTokens":128000},
13756
- "claude-opus-5-5":{"id":"claude-opus-5-5","name":"Claude Opus 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":4,"output":20,"cacheRead":0.2,"cacheWrite":5},"contextWindow":500000,"maxTokens":128000},
13757
- "claude-haiku-5-5":{"id":"claude-haiku-5-5","name":"Claude Haiku 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":0.1,"output":0.5,"cacheRead":0.01,"cacheWrite":0.125},"contextWindow":1000000,"maxTokens":128000},
13758
- "claude-opus-5":{"id":"claude-opus-5","name":"Claude Opus 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":300000,"maxTokens":128000},
13759
- "claude-sonnet-5":{"id":"claude-sonnet-5","name":"Claude Sonnet 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"contextWindow":1000000,"maxTokens":128000},
13760
- "claude-fable-5":{"id":"claude-fable-5","name":"Claude Fable 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5},"contextWindow":300000,"maxTokens":128000},
13761
- "claude-opus-4-8":{"id":"claude-opus-4-8","name":"Claude Opus 4.8","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":300000,"maxTokens":32000},
13762
- "claude-opus-4-7":{"id":"claude-opus-4-7","name":"Claude Opus 4.7","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":200000,"maxTokens":32000},
13763
- "claude-haiku-4-5":{"id":"claude-haiku-4-5","name":"Claude Haiku 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25},"contextWindow":200000,"maxTokens":64000},
13764
- "claude-haiku-4-5-20251001":{"id":"claude-haiku-4-5-20251001","name":"Claude Haiku 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25},"contextWindow":200000,"maxTokens":64000},
13765
- "claude-opus-4-0":{"id":"claude-opus-4-0","name":"Claude Opus 4 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75},"contextWindow":200000,"maxTokens":32000},
13766
- "claude-opus-4-1":{"id":"claude-opus-4-1","name":"Claude Opus 4.1 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75},"contextWindow":200000,"maxTokens":32000},
13767
- "claude-opus-4-1-20250805":{"id":"claude-opus-4-1-20250805","name":"Claude Opus 4.1","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75},"contextWindow":200000,"maxTokens":32000},
13768
- "claude-opus-4-20250514":{"id":"claude-opus-4-20250514","name":"Claude Opus 4","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75},"contextWindow":200000,"maxTokens":32000},
13769
- "claude-opus-4-5":{"id":"claude-opus-4-5","name":"Claude Opus 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":200000,"maxTokens":64000},
13770
- "claude-opus-4-5-20251101":{"id":"claude-opus-4-5-20251101","name":"Claude Opus 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":200000,"maxTokens":64000},
13771
- "claude-opus-4-6":{"id":"claude-opus-4-6","name":"Claude Opus 4.6","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"contextWindow":200000,"maxTokens":128000},
13772
- "claude-sonnet-4-0":{"id":"claude-sonnet-4-0","name":"Claude Sonnet 4 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13773
- "claude-sonnet-4-20250514":{"id":"claude-sonnet-4-20250514","name":"Claude Sonnet 4","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13774
- "claude-sonnet-4-5":{"id":"claude-sonnet-4-5","name":"Claude Sonnet 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13775
- "claude-sonnet-4-5-20250929":{"id":"claude-sonnet-4-5-20250929","name":"Claude Sonnet 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":200000,"maxTokens":64000},
13776
- "claude-sonnet-4-6":{"id":"claude-sonnet-4-6","name":"Claude Sonnet 4.6","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75},"contextWindow":1000000,"maxTokens":64000},
13745
+ "claude-3-5-haiku-20241022":{"id":"claude-3-5-haiku-20241022","name":"Claude Haiku 3.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.8,"output":4,"cacheRead":0.08,"cacheWrite":1,"cacheWrite1h":1.6},"contextWindow":200000,"maxTokens":8192},
13746
+ "claude-3-5-haiku-latest":{"id":"claude-3-5-haiku-latest","name":"Claude Haiku 3.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.8,"output":4,"cacheRead":0.08,"cacheWrite":1,"cacheWrite1h":1.6},"contextWindow":200000,"maxTokens":8192},
13747
+ "claude-3-5-sonnet-20240620":{"id":"claude-3-5-sonnet-20240620","name":"Claude Sonnet 3.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":8192},
13748
+ "claude-3-5-sonnet-20241022":{"id":"claude-3-5-sonnet-20241022","name":"Claude Sonnet 3.5 v2","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":8192},
13749
+ "claude-3-7-sonnet-20250219":{"id":"claude-3-7-sonnet-20250219","name":"Claude Sonnet 3.7","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13750
+ "claude-3-7-sonnet-latest":{"id":"claude-3-7-sonnet-latest","name":"Claude Sonnet 3.7 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13751
+ "claude-3-haiku-20240307":{"id":"claude-3-haiku-20240307","name":"Claude Haiku 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":0.25,"output":1.25,"cacheRead":0.03,"cacheWrite":0.3,"cacheWrite1h":0.5},"contextWindow":200000,"maxTokens":4096},
13752
+ "claude-3-opus-20240229":{"id":"claude-3-opus-20240229","name":"Claude Opus 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75,"cacheWrite1h":30},"contextWindow":200000,"maxTokens":4096},
13753
+ "claude-3-sonnet-20240229":{"id":"claude-3-sonnet-20240229","name":"Claude Sonnet 3","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":0.3,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":4096},
13754
+ "claude-fable-5-1":{"id":"claude-fable-5-1","name":"Claude Fable 5.1","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":10,"output":50,"cacheRead":0.25,"cacheWrite":12.5,"cacheWrite1h":20},"contextWindow":300000,"maxTokens":128000},
13755
+ "claude-sonnet-5-5":{"id":"claude-sonnet-5-5","name":"Claude Sonnet 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":2,"output":10,"cacheRead":0.1,"cacheWrite":2.5,"cacheWrite1h":4},"contextWindow":1000000,"maxTokens":128000},
13756
+ "claude-opus-5-5":{"id":"claude-opus-5-5","name":"Claude Opus 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":4,"output":20,"cacheRead":0.2,"cacheWrite":5,"cacheWrite1h":8},"contextWindow":500000,"maxTokens":128000},
13757
+ "claude-haiku-5-5":{"id":"claude-haiku-5-5","name":"Claude Haiku 5.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":0.1,"output":0.5,"cacheRead":0.01,"cacheWrite":0.125,"cacheWrite1h":0.2},"contextWindow":1000000,"maxTokens":128000},
13758
+ "claude-opus-5":{"id":"claude-opus-5","name":"Claude Opus 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":300000,"maxTokens":128000},
13759
+ "claude-sonnet-5":{"id":"claude-sonnet-5","name":"Claude Sonnet 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5,"cacheWrite1h":4},"contextWindow":1000000,"maxTokens":128000},
13760
+ "claude-fable-5":{"id":"claude-fable-5","name":"Claude Fable 5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":10,"output":50,"cacheRead":1,"cacheWrite":12.5,"cacheWrite1h":20},"contextWindow":300000,"maxTokens":128000},
13761
+ "claude-opus-4-8":{"id":"claude-opus-4-8","name":"Claude Opus 4.8","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":300000,"maxTokens":32000},
13762
+ "claude-opus-4-7":{"id":"claude-opus-4-7","name":"Claude Opus 4.7","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":false,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":200000,"maxTokens":32000},
13763
+ "claude-haiku-4-5":{"id":"claude-haiku-4-5","name":"Claude Haiku 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25,"cacheWrite1h":2},"contextWindow":200000,"maxTokens":64000},
13764
+ "claude-haiku-4-5-20251001":{"id":"claude-haiku-4-5-20251001","name":"Claude Haiku 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":1,"output":5,"cacheRead":0.1,"cacheWrite":1.25,"cacheWrite1h":2},"contextWindow":200000,"maxTokens":64000},
13765
+ "claude-opus-4-0":{"id":"claude-opus-4-0","name":"Claude Opus 4 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75,"cacheWrite1h":30},"contextWindow":200000,"maxTokens":32000},
13766
+ "claude-opus-4-1":{"id":"claude-opus-4-1","name":"Claude Opus 4.1 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75,"cacheWrite1h":30},"contextWindow":200000,"maxTokens":32000},
13767
+ "claude-opus-4-1-20250805":{"id":"claude-opus-4-1-20250805","name":"Claude Opus 4.1","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75,"cacheWrite1h":30},"contextWindow":200000,"maxTokens":32000},
13768
+ "claude-opus-4-20250514":{"id":"claude-opus-4-20250514","name":"Claude Opus 4","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":15,"output":75,"cacheRead":1.5,"cacheWrite":18.75,"cacheWrite1h":30},"contextWindow":200000,"maxTokens":32000},
13769
+ "claude-opus-4-5":{"id":"claude-opus-4-5","name":"Claude Opus 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":200000,"maxTokens":64000},
13770
+ "claude-opus-4-5-20251101":{"id":"claude-opus-4-5-20251101","name":"Claude Opus 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":200000,"maxTokens":64000},
13771
+ "claude-opus-4-6":{"id":"claude-opus-4-6","name":"Claude Opus 4.6","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25,"cacheWrite1h":10},"contextWindow":200000,"maxTokens":128000},
13772
+ "claude-sonnet-4-0":{"id":"claude-sonnet-4-0","name":"Claude Sonnet 4 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13773
+ "claude-sonnet-4-20250514":{"id":"claude-sonnet-4-20250514","name":"Claude Sonnet 4","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13774
+ "claude-sonnet-4-5":{"id":"claude-sonnet-4-5","name":"Claude Sonnet 4.5 (latest)","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13775
+ "claude-sonnet-4-5-20250929":{"id":"claude-sonnet-4-5-20250929","name":"Claude Sonnet 4.5","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":200000,"maxTokens":64000},
13776
+ "claude-sonnet-4-6":{"id":"claude-sonnet-4-6","name":"Claude Sonnet 4.6","api":"anthropic-messages","provider":"anthropic","baseUrl":"https://api.anthropic.com","reasoning":true,"input":["text","image"],"cost":{"input":3,"output":15,"cacheRead":0.3,"cacheWrite":3.75,"cacheWrite1h":6},"contextWindow":1000000,"maxTokens":64000},
13777
13777
  },
13778
13778
  "azure-openai-responses": {
13779
13779
  "codex-mini-latest":{"id":"codex-mini-latest","name":"Codex Mini","api":"azure-openai-responses","provider":"azure-openai-responses","baseUrl":"","reasoning":true,"input":["text"],"cost":{"input":1.5,"output":6,"cacheRead":0.375,"cacheWrite":0},"contextWindow":200000,"maxTokens":100000},
@@ -52,12 +52,23 @@ export function getModels(provider) {
52
52
  const models = modelRegistry.get(provider);
53
53
  return models ? Array.from(models.values()) : [];
54
54
  }
55
+ // JOHNNESS_PATCH_USAGE_BILLING_91: disjoint token buckets, with native cache TTLs.
56
+ export function johnnessUsageCost(usage, rates) {
57
+ if (!usage || !rates) return undefined;
58
+ const n = v => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : 0;
59
+ const long = Math.min(n(usage.cacheWrite), n(usage.cacheWrite1h));
60
+ const cost = {
61
+ input: n(usage.input) * rates.input / 1e6,
62
+ output: n(usage.output) * rates.output / 1e6,
63
+ cacheRead: n(usage.cacheRead) * rates.cacheRead / 1e6,
64
+ cacheWrite: ((n(usage.cacheWrite) - long) * rates.cacheWrite + long * (rates.cacheWrite1h ?? rates.input * 2)) / 1e6,
65
+ };
66
+ if (Object.values(cost).some(v => !Number.isFinite(v) || v < 0)) return undefined;
67
+ cost.total = cost.input + cost.output + cost.cacheRead + cost.cacheWrite;
68
+ return cost;
69
+ }
55
70
  export function calculateCost(model, usage) {
56
- usage.cost.input = (model.cost.input / 1000000) * usage.input;
57
- usage.cost.output = (model.cost.output / 1000000) * usage.output;
58
- usage.cost.cacheRead = (model.cost.cacheRead / 1000000) * usage.cacheRead;
59
- usage.cost.cacheWrite = (model.cost.cacheWrite / 1000000) * usage.cacheWrite;
60
- usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
71
+ Object.assign(usage.cost, johnnessUsageCost(usage, model.cost));
61
72
  return usage.cost;
62
73
  }
63
74
  /**
@@ -238,6 +238,13 @@ export const streamAnthropic = (model, context, options) => {
238
238
  output.usage.output = event.message.usage.output_tokens || 0;
239
239
  output.usage.cacheRead = event.message.usage.cache_read_input_tokens || 0;
240
240
  output.usage.cacheWrite = event.message.usage.cache_creation_input_tokens || 0;
241
+ // JOHNNESS_PATCH_USAGE_BILLING_91: the response is authoritative for mixed TTLs.
242
+ output.usage.cacheWrite5m = event.message.usage.cache_creation?.ephemeral_5m_input_tokens ?? 0;
243
+ output.usage.cacheWrite1h = event.message.usage.cache_creation?.ephemeral_1h_input_tokens ?? 0;
244
+ if (!event.message.usage.cache_creation) {
245
+ const long = getCacheControl(model.baseUrl, options?.cacheRetention, model.provider).cacheControl?.ttl === "1h";
246
+ output.usage[long ? "cacheWrite1h" : "cacheWrite5m"] = output.usage.cacheWrite;
247
+ }
241
248
  // Anthropic doesn't provide total_tokens, compute from components
242
249
  output.usage.totalTokens =
243
250
  output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
@@ -390,6 +397,14 @@ export const streamAnthropic = (model, context, options) => {
390
397
  if (event.usage.cache_creation_input_tokens != null) {
391
398
  output.usage.cacheWrite = event.usage.cache_creation_input_tokens;
392
399
  }
400
+ if (event.usage.cache_creation) {
401
+ output.usage.cacheWrite5m = event.usage.cache_creation.ephemeral_5m_input_tokens ?? 0;
402
+ output.usage.cacheWrite1h = event.usage.cache_creation.ephemeral_1h_input_tokens ?? 0;
403
+ } else if (event.usage.cache_creation_input_tokens != null && output.usage.cacheWrite5m + output.usage.cacheWrite1h !== output.usage.cacheWrite) {
404
+ const long = getCacheControl(model.baseUrl, options?.cacheRetention, model.provider).cacheControl?.ttl === "1h";
405
+ output.usage.cacheWrite5m = long ? 0 : output.usage.cacheWrite;
406
+ output.usage.cacheWrite1h = long ? output.usage.cacheWrite : 0;
407
+ }
393
408
  // Anthropic doesn't provide total_tokens, compute from components
394
409
  output.usage.totalTokens =
395
410
  output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
@@ -0,0 +1,371 @@
1
+ import { GoogleGenAI, ThinkingLevel, } from "@google/genai";
2
+ import { calculateCost } from "../models.js";
3
+ import { AssistantMessageEventStream } from "../utils/event-stream.js";
4
+ import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
5
+ import { convertMessages, convertTools, isThinkingPart, mapStopReason, mapToolChoice, retainThoughtSignature, } from "./google-shared.js";
6
+ import { buildBaseOptions, clampReasoning } from "./simple-options.js";
7
+ const API_VERSION = "v1";
8
+ const THINKING_LEVEL_MAP = {
9
+ THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,
10
+ MINIMAL: ThinkingLevel.MINIMAL,
11
+ LOW: ThinkingLevel.LOW,
12
+ MEDIUM: ThinkingLevel.MEDIUM,
13
+ HIGH: ThinkingLevel.HIGH,
14
+ };
15
+ // Counter for generating unique tool call IDs
16
+ let toolCallCounter = 0;
17
+ export const streamGoogleVertex = (model, context, options) => {
18
+ const stream = new AssistantMessageEventStream();
19
+ (async () => {
20
+ const output = {
21
+ role: "assistant",
22
+ content: [],
23
+ api: "google-vertex",
24
+ provider: model.provider,
25
+ model: model.id,
26
+ usage: {
27
+ input: 0,
28
+ output: 0,
29
+ cacheRead: 0,
30
+ cacheWrite: 0,
31
+ totalTokens: 0,
32
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
33
+ },
34
+ stopReason: "stop",
35
+ timestamp: Date.now(),
36
+ };
37
+ try {
38
+ const project = resolveProject(options);
39
+ const location = resolveLocation(options);
40
+ const client = createClient(model, project, location, options?.headers);
41
+ const params = buildParams(model, context, options);
42
+ options?.onPayload?.(params);
43
+ const googleStream = await client.models.generateContentStream(params);
44
+ stream.push({ type: "start", partial: output });
45
+ let currentBlock = null;
46
+ const blocks = output.content;
47
+ const blockIndex = () => blocks.length - 1;
48
+ for await (const chunk of googleStream) {
49
+ const candidate = chunk.candidates?.[0];
50
+ if (candidate?.content?.parts) {
51
+ for (const part of candidate.content.parts) {
52
+ if (part.text !== undefined) {
53
+ const isThinking = isThinkingPart(part);
54
+ if (!currentBlock ||
55
+ (isThinking && currentBlock.type !== "thinking") ||
56
+ (!isThinking && currentBlock.type !== "text")) {
57
+ if (currentBlock) {
58
+ if (currentBlock.type === "text") {
59
+ stream.push({
60
+ type: "text_end",
61
+ contentIndex: blocks.length - 1,
62
+ content: currentBlock.text,
63
+ partial: output,
64
+ });
65
+ }
66
+ else {
67
+ stream.push({
68
+ type: "thinking_end",
69
+ contentIndex: blockIndex(),
70
+ content: currentBlock.thinking,
71
+ partial: output,
72
+ });
73
+ }
74
+ }
75
+ if (isThinking) {
76
+ currentBlock = { type: "thinking", thinking: "", thinkingSignature: undefined };
77
+ output.content.push(currentBlock);
78
+ stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
79
+ }
80
+ else {
81
+ currentBlock = { type: "text", text: "" };
82
+ output.content.push(currentBlock);
83
+ stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
84
+ }
85
+ }
86
+ if (currentBlock.type === "thinking") {
87
+ currentBlock.thinking += part.text;
88
+ currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
89
+ stream.push({
90
+ type: "thinking_delta",
91
+ contentIndex: blockIndex(),
92
+ delta: part.text,
93
+ partial: output,
94
+ });
95
+ }
96
+ else {
97
+ currentBlock.text += part.text;
98
+ currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
99
+ stream.push({
100
+ type: "text_delta",
101
+ contentIndex: blockIndex(),
102
+ delta: part.text,
103
+ partial: output,
104
+ });
105
+ }
106
+ }
107
+ if (part.functionCall) {
108
+ if (currentBlock) {
109
+ if (currentBlock.type === "text") {
110
+ stream.push({
111
+ type: "text_end",
112
+ contentIndex: blockIndex(),
113
+ content: currentBlock.text,
114
+ partial: output,
115
+ });
116
+ }
117
+ else {
118
+ stream.push({
119
+ type: "thinking_end",
120
+ contentIndex: blockIndex(),
121
+ content: currentBlock.thinking,
122
+ partial: output,
123
+ });
124
+ }
125
+ currentBlock = null;
126
+ }
127
+ const providedId = part.functionCall.id;
128
+ const needsNewId = !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
129
+ const toolCallId = needsNewId
130
+ ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`
131
+ : providedId;
132
+ const toolCall = {
133
+ type: "toolCall",
134
+ id: toolCallId,
135
+ name: part.functionCall.name || "",
136
+ arguments: part.functionCall.args ?? {},
137
+ ...(part.thoughtSignature && { thoughtSignature: part.thoughtSignature }),
138
+ };
139
+ output.content.push(toolCall);
140
+ stream.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
141
+ stream.push({
142
+ type: "toolcall_delta",
143
+ contentIndex: blockIndex(),
144
+ delta: JSON.stringify(toolCall.arguments),
145
+ partial: output,
146
+ });
147
+ stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
148
+ }
149
+ }
150
+ }
151
+ if (candidate?.finishReason) {
152
+ output.stopReason = mapStopReason(candidate.finishReason);
153
+ if (output.content.some((b) => b.type === "toolCall")) {
154
+ output.stopReason = "toolUse";
155
+ }
156
+ }
157
+ if (chunk.usageMetadata) {
158
+ output.usage = {
159
+ input: Math.max(0, (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0)), // JOHNNESS_PATCH_USAGE_BILLING_91
160
+ output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
161
+ cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
162
+ cacheWrite: 0,
163
+ totalTokens: chunk.usageMetadata.totalTokenCount || 0,
164
+ cost: {
165
+ input: 0,
166
+ output: 0,
167
+ cacheRead: 0,
168
+ cacheWrite: 0,
169
+ total: 0,
170
+ },
171
+ };
172
+ calculateCost(model, output.usage);
173
+ }
174
+ }
175
+ if (currentBlock) {
176
+ if (currentBlock.type === "text") {
177
+ stream.push({
178
+ type: "text_end",
179
+ contentIndex: blockIndex(),
180
+ content: currentBlock.text,
181
+ partial: output,
182
+ });
183
+ }
184
+ else {
185
+ stream.push({
186
+ type: "thinking_end",
187
+ contentIndex: blockIndex(),
188
+ content: currentBlock.thinking,
189
+ partial: output,
190
+ });
191
+ }
192
+ }
193
+ if (options?.signal?.aborted) {
194
+ throw new Error("Request was aborted");
195
+ }
196
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
197
+ throw new Error("An unknown error occurred");
198
+ }
199
+ stream.push({ type: "done", reason: output.stopReason, message: output });
200
+ stream.end();
201
+ }
202
+ catch (error) {
203
+ // Remove internal index property used during streaming
204
+ for (const block of output.content) {
205
+ if ("index" in block) {
206
+ delete block.index;
207
+ }
208
+ }
209
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
210
+ output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
211
+ stream.push({ type: "error", reason: output.stopReason, error: output });
212
+ stream.end();
213
+ }
214
+ })();
215
+ return stream;
216
+ };
217
+ export const streamSimpleGoogleVertex = (model, context, options) => {
218
+ const base = buildBaseOptions(model, options, undefined);
219
+ if (!options?.reasoning) {
220
+ return streamGoogleVertex(model, context, {
221
+ ...base,
222
+ thinking: { enabled: false },
223
+ });
224
+ }
225
+ const effort = clampReasoning(options.reasoning);
226
+ const geminiModel = model;
227
+ if (isGemini3ProModel(geminiModel) || isGemini3FlashModel(geminiModel)) {
228
+ return streamGoogleVertex(model, context, {
229
+ ...base,
230
+ thinking: {
231
+ enabled: true,
232
+ level: getGemini3ThinkingLevel(effort, geminiModel),
233
+ },
234
+ });
235
+ }
236
+ return streamGoogleVertex(model, context, {
237
+ ...base,
238
+ thinking: {
239
+ enabled: true,
240
+ budgetTokens: getGoogleBudget(geminiModel, effort, options.thinkingBudgets),
241
+ },
242
+ });
243
+ };
244
+ function createClient(model, project, location, optionsHeaders) {
245
+ const httpOptions = {};
246
+ if (model.headers || optionsHeaders) {
247
+ httpOptions.headers = { ...model.headers, ...optionsHeaders };
248
+ }
249
+ const hasHttpOptions = Object.values(httpOptions).some(Boolean);
250
+ return new GoogleGenAI({
251
+ vertexai: true,
252
+ project,
253
+ location,
254
+ apiVersion: API_VERSION,
255
+ httpOptions: hasHttpOptions ? httpOptions : undefined,
256
+ });
257
+ }
258
+ function resolveProject(options) {
259
+ const project = options?.project || process.env.GOOGLE_CLOUD_PROJECT || process.env.GCLOUD_PROJECT;
260
+ if (!project) {
261
+ throw new Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");
262
+ }
263
+ return project;
264
+ }
265
+ function resolveLocation(options) {
266
+ const location = options?.location || process.env.GOOGLE_CLOUD_LOCATION;
267
+ if (!location) {
268
+ throw new Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");
269
+ }
270
+ return location;
271
+ }
272
+ function buildParams(model, context, options = {}) {
273
+ const contents = convertMessages(model, context);
274
+ const generationConfig = {};
275
+ if (options.temperature !== undefined) {
276
+ generationConfig.temperature = options.temperature;
277
+ }
278
+ if (options.maxTokens !== undefined) {
279
+ generationConfig.maxOutputTokens = options.maxTokens;
280
+ }
281
+ const config = {
282
+ ...(Object.keys(generationConfig).length > 0 && generationConfig),
283
+ ...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),
284
+ ...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),
285
+ };
286
+ if (context.tools && context.tools.length > 0 && options.toolChoice) {
287
+ config.toolConfig = {
288
+ functionCallingConfig: {
289
+ mode: mapToolChoice(options.toolChoice),
290
+ },
291
+ };
292
+ }
293
+ else {
294
+ config.toolConfig = undefined;
295
+ }
296
+ if (options.thinking?.enabled && model.reasoning) {
297
+ const thinkingConfig = { includeThoughts: true };
298
+ if (options.thinking.level !== undefined) {
299
+ thinkingConfig.thinkingLevel = THINKING_LEVEL_MAP[options.thinking.level];
300
+ }
301
+ else if (options.thinking.budgetTokens !== undefined) {
302
+ thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
303
+ }
304
+ config.thinkingConfig = thinkingConfig;
305
+ }
306
+ if (options.signal) {
307
+ if (options.signal.aborted) {
308
+ throw new Error("Request aborted");
309
+ }
310
+ config.abortSignal = options.signal;
311
+ }
312
+ const params = {
313
+ model: model.id,
314
+ contents,
315
+ config,
316
+ };
317
+ return params;
318
+ }
319
+ function isGemini3ProModel(model) {
320
+ return model.id.includes("3-pro");
321
+ }
322
+ function isGemini3FlashModel(model) {
323
+ return model.id.includes("3-flash");
324
+ }
325
+ function getGemini3ThinkingLevel(effort, model) {
326
+ if (isGemini3ProModel(model)) {
327
+ switch (effort) {
328
+ case "minimal":
329
+ case "low":
330
+ return "LOW";
331
+ case "medium":
332
+ case "high":
333
+ return "HIGH";
334
+ }
335
+ }
336
+ switch (effort) {
337
+ case "minimal":
338
+ return "MINIMAL";
339
+ case "low":
340
+ return "LOW";
341
+ case "medium":
342
+ return "MEDIUM";
343
+ case "high":
344
+ return "HIGH";
345
+ }
346
+ }
347
+ function getGoogleBudget(model, effort, customBudgets) {
348
+ if (customBudgets?.[effort] !== undefined) {
349
+ return customBudgets[effort];
350
+ }
351
+ if (model.id.includes("2.5-pro")) {
352
+ const budgets = {
353
+ minimal: 128,
354
+ low: 2048,
355
+ medium: 8192,
356
+ high: 32768,
357
+ };
358
+ return budgets[effort];
359
+ }
360
+ if (model.id.includes("2.5-flash")) {
361
+ const budgets = {
362
+ minimal: 128,
363
+ low: 2048,
364
+ medium: 8192,
365
+ high: 24576,
366
+ };
367
+ return budgets[effort];
368
+ }
369
+ return -1;
370
+ }
371
+ //# sourceMappingURL=google-vertex.js.map
@@ -182,7 +182,7 @@ export const streamGoogle = (model, context, options) => {
182
182
  }
183
183
  if (chunk.usageMetadata) {
184
184
  output.usage = {
185
- input: chunk.usageMetadata.promptTokenCount || 0,
185
+ input: Math.max(0, (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0)), // JOHNNESS_PATCH_USAGE_BILLING_91
186
186
  output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
187
187
  cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
188
188
  cacheWrite: 0,
@@ -105,18 +105,18 @@ export const streamOpenAICompletions = (model, context, options) => {
105
105
  };
106
106
  for await (const chunk of openaiStream) {
107
107
  if (chunk.usage) {
108
- const cachedTokens = chunk.usage.prompt_tokens_details?.cached_tokens || 0;
108
+ const cachedTokens = chunk.usage.prompt_tokens_details?.cached_tokens ?? chunk.usage.prompt_cache_hit_tokens ?? 0; // JOHNNESS_PATCH_USAGE_BILLING_91
109
109
  const reasoningTokens = chunk.usage.completion_tokens_details?.reasoning_tokens || 0;
110
- const input = (chunk.usage.prompt_tokens || 0) - cachedTokens;
111
- const outputTokens = (chunk.usage.completion_tokens || 0) + reasoningTokens;
110
+ const input = Math.max(0, (chunk.usage.prompt_tokens || 0) - cachedTokens);
111
+ // OpenAI-compatible completion_tokens includes reasoning. Groq reports it separately.
112
+ const outputTokens = (chunk.usage.completion_tokens || 0) + (model.provider === "groq" ? reasoningTokens : 0);
112
113
  output.usage = {
113
114
  // OpenAI includes cached tokens in prompt_tokens, so subtract to get non-cached input
114
115
  input,
115
116
  output: outputTokens,
116
117
  cacheRead: cachedTokens,
117
118
  cacheWrite: 0,
118
- // Compute totalTokens ourselves since we add reasoning_tokens to output
119
- // and some providers (e.g., Groq) don't include them in total_tokens
119
+ // Compute totalTokens from disjoint buckets (Groq reasoning is separate).
120
120
  totalTokens: input + outputTokens + cachedTokens,
121
121
  cost: {
122
122
  input: 0,