@opencode-ai/ai
Advanced tools
@@ -232,2 +232,3 @@ import { Effect, Schema } from "effect"; | ||
| readonly cached_tokens: Schema.optional<Schema.Number>; | ||
| readonly cache_write_tokens: Schema.optional<Schema.Number>; | ||
| }>>>; | ||
@@ -501,2 +502,3 @@ readonly output_tokens: Schema.optional<Schema.Number>; | ||
| readonly cached_tokens?: number | undefined; | ||
| readonly cache_write_tokens?: number | undefined; | ||
| } | null | undefined; | ||
@@ -503,0 +505,0 @@ readonly output_tokens_details?: { |
@@ -124,3 +124,6 @@ import { Effect, Schema } from "effect"; | ||
| input_tokens: Schema.optional(Schema.Number), | ||
| input_tokens_details: optionalNull(Schema.Struct({ cached_tokens: Schema.optional(Schema.Number) })), | ||
| input_tokens_details: optionalNull(Schema.Struct({ | ||
| cached_tokens: Schema.optional(Schema.Number), | ||
| cache_write_tokens: Schema.optional(Schema.Number), | ||
| })), | ||
| output_tokens: Schema.optional(Schema.Number), | ||
@@ -403,4 +406,4 @@ output_tokens_details: optionalNull(Schema.Struct({ reasoning_tokens: Schema.optional(Schema.Number) })), | ||
| // Responses APIs report `input_tokens` (inclusive total) with a | ||
| // `cached_tokens` subset, and `output_tokens` (inclusive total) with a | ||
| // `reasoning_tokens` subset. Pass the totals through and derive the | ||
| // cached-read and cache-write subsets, and `output_tokens` (inclusive total) | ||
| // with a `reasoning_tokens` subset. Pass the totals through and derive the | ||
| // non-cached breakdown. | ||
@@ -411,4 +414,5 @@ const mapUsage = (usage, providerMetadataKey) => { | ||
| const cached = usage.input_tokens_details?.cached_tokens; | ||
| const cacheWrite = usage.input_tokens_details?.cache_write_tokens; | ||
| const reasoning = usage.output_tokens_details?.reasoning_tokens; | ||
| const nonCached = ProviderShared.subtractTokens(usage.input_tokens, cached); | ||
| const nonCached = ProviderShared.subtractTokens(usage.input_tokens, ProviderShared.sumTokens(cached, cacheWrite)); | ||
| return new Usage({ | ||
@@ -419,2 +423,3 @@ inputTokens: usage.input_tokens, | ||
| cacheReadInputTokens: cached, | ||
| cacheWriteInputTokens: cacheWrite, | ||
| reasoningTokens: reasoning, | ||
@@ -421,0 +426,0 @@ totalTokens: ProviderShared.totalTokens(usage.input_tokens, usage.output_tokens, usage.total_tokens), |
@@ -165,2 +165,3 @@ import { Schema } from "effect"; | ||
| readonly cached_tokens: Schema.optional<Schema.Number>; | ||
| readonly cache_write_tokens: Schema.optional<Schema.Number>; | ||
| }>>>; | ||
@@ -275,2 +276,3 @@ readonly completion_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{ | ||
| readonly cached_tokens?: number | undefined; | ||
| readonly cache_write_tokens?: number | undefined; | ||
| } | null | undefined; | ||
@@ -277,0 +279,0 @@ readonly completion_tokens_details?: { |
@@ -103,2 +103,3 @@ import { Effect, Schema } from "effect"; | ||
| cached_tokens: Schema.optional(Schema.Number), | ||
| cache_write_tokens: Schema.optional(Schema.Number), | ||
| })), | ||
@@ -377,5 +378,5 @@ completion_tokens_details: optionalNull(Schema.Struct({ | ||
| // OpenAI Chat reports `prompt_tokens` (inclusive total) with a | ||
| // `cached_tokens` subset, and `completion_tokens` (inclusive total) with | ||
| // a `reasoning_tokens` subset. We pass the inclusive totals through and | ||
| // derive the non-cached breakdown so the `LLM.Usage` contract is | ||
| // cached-read and cache-write subsets, and `completion_tokens` (inclusive | ||
| // total) with a `reasoning_tokens` subset. We pass the inclusive totals | ||
| // through and derive the non-cached breakdown so the `LLM.Usage` contract is | ||
| // satisfied on both sides. | ||
@@ -386,4 +387,5 @@ const mapUsage = (usage) => { | ||
| const cached = usage.prompt_tokens_details?.cached_tokens; | ||
| const cacheWrite = usage.prompt_tokens_details?.cache_write_tokens; | ||
| const reasoning = usage.completion_tokens_details?.reasoning_tokens; | ||
| const nonCached = ProviderShared.subtractTokens(usage.prompt_tokens, cached); | ||
| const nonCached = ProviderShared.subtractTokens(usage.prompt_tokens, ProviderShared.sumTokens(cached, cacheWrite)); | ||
| return new Usage({ | ||
@@ -394,2 +396,3 @@ inputTokens: usage.prompt_tokens, | ||
| cacheReadInputTokens: cached, | ||
| cacheWriteInputTokens: cacheWrite, | ||
| reasoningTokens: reasoning, | ||
@@ -396,0 +399,0 @@ totalTokens: ProviderShared.totalTokens(usage.prompt_tokens, usage.completion_tokens, usage.total_tokens), |
@@ -226,2 +226,3 @@ import { Schema } from "effect"; | ||
| readonly cached_tokens?: number | undefined; | ||
| readonly cache_write_tokens?: number | undefined; | ||
| } | null | undefined; | ||
@@ -228,0 +229,0 @@ readonly output_tokens_details?: { |
@@ -166,2 +166,3 @@ import { Schema } from "effect"; | ||
| readonly cached_tokens?: number | undefined; | ||
| readonly cache_write_tokens?: number | undefined; | ||
| } | null | undefined; | ||
@@ -168,0 +169,0 @@ readonly completion_tokens_details?: { |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-next-16171", | ||
| "version": "0.0.0-next-16173", | ||
| "name": "@opencode-ai/ai", | ||
@@ -29,3 +29,3 @@ "type": "module", | ||
| "@effect/platform-node": "4.0.0-beta.98", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16171", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16173", | ||
| "@tsconfig/bun": "1.0.9", | ||
@@ -39,3 +39,3 @@ "@types/bun": "1.3.13", | ||
| "@smithy/util-utf8": "4.2.2", | ||
| "@opencode-ai/schema": "0.0.0-next-16171", | ||
| "@opencode-ai/schema": "0.0.0-next-16173", | ||
| "aws4fetch": "1.0.20", | ||
@@ -42,0 +42,0 @@ "effect": "4.0.0-beta.98", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
1090820
0.08%22905
0.06%+ Added
- Removed