@opencode-ai/ai
Advanced tools
@@ -342,18 +342,15 @@ import { Effect, Schema } from "effect"; | ||
| }; | ||
| // AWS Bedrock Converse reports `inputTokens` (inclusive total) with | ||
| // `cacheReadInputTokens` and `cacheWriteInputTokens` as subsets. Pass | ||
| // the total through and derive the non-cached breakdown. Bedrock does | ||
| // not break reasoning out of `outputTokens` for any current model. | ||
| // AWS reports inputTokens separately from cache reads and writes. | ||
| // Bedrock does not break reasoning out of outputTokens for current models. | ||
| const mapUsage = (usage) => { | ||
| if (!usage) | ||
| return undefined; | ||
| const cacheTotal = (usage.cacheReadInputTokens ?? 0) + (usage.cacheWriteInputTokens ?? 0); | ||
| const nonCached = ProviderShared.subtractTokens(usage.inputTokens, cacheTotal); | ||
| const inputTokens = ProviderShared.sumTokens(usage.inputTokens, usage.cacheReadInputTokens, usage.cacheWriteInputTokens); | ||
| return new Usage({ | ||
| inputTokens: usage.inputTokens, | ||
| inputTokens, | ||
| outputTokens: usage.outputTokens, | ||
| nonCachedInputTokens: nonCached, | ||
| nonCachedInputTokens: usage.inputTokens, | ||
| cacheReadInputTokens: usage.cacheReadInputTokens, | ||
| cacheWriteInputTokens: usage.cacheWriteInputTokens, | ||
| totalTokens: ProviderShared.totalTokens(usage.inputTokens, usage.outputTokens, usage.totalTokens), | ||
| totalTokens: ProviderShared.totalTokens(inputTokens, usage.outputTokens, usage.totalTokens), | ||
| providerMetadata: { bedrock: usage }, | ||
@@ -360,0 +357,0 @@ }); |
@@ -237,5 +237,5 @@ import { Schema } from "effect"; | ||
| readonly service_tier?: string | null | undefined; | ||
| readonly incomplete_details?: Schema.Struct.ReadonlySide<{ | ||
| readonly reason: Schema.String; | ||
| }, "Type"> | null | undefined; | ||
| readonly incomplete_details?: { | ||
| readonly reason?: string | undefined; | ||
| } | null | undefined; | ||
| } | undefined; | ||
@@ -242,0 +242,0 @@ readonly message?: string | undefined; |
@@ -197,3 +197,3 @@ import { Effect, Encoding, Schema } from "effect"; | ||
| service_tier: optionalNull(Schema.String), | ||
| incomplete_details: optionalNull(Schema.Struct({ reason: Schema.String })), | ||
| incomplete_details: optionalNull(Schema.Struct({ reason: Schema.optional(Schema.String) })), | ||
| usage: optionalNull(OpenAIResponsesUsage), | ||
@@ -493,3 +493,3 @@ error: optionalNull(OpenAIResponsesErrorPayload), | ||
| if (reason === undefined || reason === null) | ||
| return hasFunctionCall ? "tool-calls" : "stop"; | ||
| return hasFunctionCall ? "tool-calls" : event.type === "response.incomplete" ? "unknown" : "stop"; | ||
| if (reason === "max_output_tokens") | ||
@@ -496,0 +496,0 @@ return "length"; |
@@ -36,7 +36,8 @@ import { Schema } from "effect"; | ||
| * | ||
| * - OpenAI Chat / Responses / Gemini / Bedrock: provider reports inclusive | ||
| * - OpenAI Chat / Responses / Gemini: provider reports inclusive | ||
| * `inputTokens` and an inclusive `outputTokens`; mapper subtracts to | ||
| * derive the breakdown. | ||
| * - Anthropic: provider reports the breakdown natively (`input_tokens` is | ||
| * non-cached only); mapper sums to derive the inclusive `inputTokens`. | ||
| * - Anthropic and Bedrock report the input breakdown natively: Anthropic's | ||
| * `input_tokens` and Bedrock's `inputTokens` are non-cached only. Their | ||
| * mappers sum the breakdown to derive the inclusive `inputTokens`. | ||
| * Anthropic does *not* break extended-thinking out of `output_tokens`, so | ||
@@ -43,0 +44,0 @@ * `reasoningTokens` is `undefined` and `outputTokens` carries the |
+3
-3
| { | ||
| "$schema": "https://json.schemastore.org/package.json", | ||
| "version": "0.0.0-next-16048", | ||
| "version": "0.0.0-next-16052", | ||
| "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-16048", | ||
| "@opencode-ai/http-recorder": "0.0.0-next-16052", | ||
| "@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-16048", | ||
| "@opencode-ai/schema": "0.0.0-next-16052", | ||
| "aws4fetch": "1.0.20", | ||
@@ -42,0 +42,0 @@ "effect": "4.0.0-beta.98", |
Sorry, the diff of this file is too big to display
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.
1037508
021796
0+ Added
- Removed