@opencode/ai 0.0.0-dev-551 → 0.0.0-dev-552
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.
|
@@ -109,6 +109,7 @@ declare const GeminiUsage: Schema.Struct<{
|
|
|
109
109
|
readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
110
110
|
readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
111
111
|
readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
112
|
+
readonly toolUsePromptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
112
113
|
readonly candidatesTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
113
114
|
readonly totalTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
|
|
114
115
|
}>;
|
|
@@ -264,6 +265,7 @@ export declare const protocol: Protocol<{
|
|
|
264
265
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
265
266
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
266
267
|
readonly promptTokenCount?: number | null | undefined;
|
|
268
|
+
readonly toolUsePromptTokenCount?: number | null | undefined;
|
|
267
269
|
readonly candidatesTokenCount?: number | null | undefined;
|
|
268
270
|
readonly totalTokenCount?: number | null | undefined;
|
|
269
271
|
} | null | undefined;
|
|
@@ -292,6 +294,7 @@ export declare const protocol: Protocol<{
|
|
|
292
294
|
readonly cachedContentTokenCount?: number | null | undefined;
|
|
293
295
|
readonly thoughtsTokenCount?: number | null | undefined;
|
|
294
296
|
readonly promptTokenCount?: number | null | undefined;
|
|
297
|
+
readonly toolUsePromptTokenCount?: number | null | undefined;
|
|
295
298
|
readonly candidatesTokenCount?: number | null | undefined;
|
|
296
299
|
readonly totalTokenCount?: number | null | undefined;
|
|
297
300
|
} | null | undefined;
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -157,6 +157,7 @@ const GeminiUsage = Schema.Struct({
|
|
|
157
157
|
cachedContentTokenCount: optionalNull(Schema.Number),
|
|
158
158
|
thoughtsTokenCount: optionalNull(Schema.Number),
|
|
159
159
|
promptTokenCount: optionalNull(Schema.Number),
|
|
160
|
+
toolUsePromptTokenCount: optionalNull(Schema.Number),
|
|
160
161
|
candidatesTokenCount: optionalNull(Schema.Number),
|
|
161
162
|
totalTokenCount: optionalNull(Schema.Number),
|
|
162
163
|
...ProviderShared.ReportedBilling.fields,
|
|
@@ -388,8 +389,8 @@ const fromRequest = Effect.fn("Gemini.fromRequest")(function* (request) {
|
|
|
388
389
|
// =============================================================================
|
|
389
390
|
// Stream Parsing
|
|
390
391
|
// =============================================================================
|
|
391
|
-
// Gemini reports `promptTokenCount`
|
|
392
|
-
// `
|
|
392
|
+
// Gemini reports `promptTokenCount` with a `cachedContentTokenCount` subset;
|
|
393
|
+
// `toolUsePromptTokenCount` is additional billed input. `candidatesTokenCount` is *exclusive*
|
|
393
394
|
// of `thoughtsTokenCount` — visible-only, not a total — so we sum the two
|
|
394
395
|
// to produce the inclusive `outputTokens` the rest of the contract expects.
|
|
395
396
|
const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
@@ -397,7 +398,7 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
397
398
|
return undefined;
|
|
398
399
|
// Explicit provider nulls decode as `null`; normalize to `undefined` so the
|
|
399
400
|
// token arithmetic below treats them like absent counts.
|
|
400
|
-
const promptTokens = usage.promptTokenCount ?? undefined;
|
|
401
|
+
const promptTokens = ProviderShared.sumTokens(usage.promptTokenCount ?? undefined, usage.toolUsePromptTokenCount ?? undefined);
|
|
401
402
|
const cached = usage.cachedContentTokenCount ?? undefined;
|
|
402
403
|
const thoughts = usage.thoughtsTokenCount ?? undefined;
|
|
403
404
|
const visible = usage.candidatesTokenCount ?? undefined;
|
|
@@ -418,13 +419,13 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
|
|
|
418
419
|
providerMetadata: providerMetadata(metadataKey, metadata),
|
|
419
420
|
});
|
|
420
421
|
};
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
// remain in provider metadata.
|
|
422
|
+
// Continued requests retain the first request's input instead of summing re-billed prompts.
|
|
423
|
+
// Complete billed counts, including tool-use prompts from later requests, remain in provider metadata.
|
|
424
424
|
const mapContinuedUsage = (requests, metadataKey) => {
|
|
425
425
|
const sum = (field) => ProviderShared.sumTokens(...requests.map((usage) => usage[field] ?? undefined));
|
|
426
426
|
return mapUsage({
|
|
427
427
|
promptTokenCount: requests[0].promptTokenCount,
|
|
428
|
+
toolUsePromptTokenCount: requests[0].toolUsePromptTokenCount,
|
|
428
429
|
cachedContentTokenCount: requests[0].cachedContentTokenCount,
|
|
429
430
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
430
431
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
|
@@ -432,6 +433,7 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
432
433
|
cost: sum("cost"),
|
|
433
434
|
}, metadataKey, {
|
|
434
435
|
promptTokenCount: sum("promptTokenCount"),
|
|
436
|
+
toolUsePromptTokenCount: sum("toolUsePromptTokenCount"),
|
|
435
437
|
cachedContentTokenCount: sum("cachedContentTokenCount"),
|
|
436
438
|
candidatesTokenCount: sum("candidatesTokenCount"),
|
|
437
439
|
thoughtsTokenCount: sum("thoughtsTokenCount"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-552",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -520,7 +520,7 @@
|
|
|
520
520
|
"devDependencies": {
|
|
521
521
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
522
522
|
"@effect/platform-node": "4.1.0",
|
|
523
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
523
|
+
"@opencode/http-recorder": "0.0.0-dev-552",
|
|
524
524
|
"@tsconfig/bun": "1.0.9",
|
|
525
525
|
"@types/bun": "1.4.3",
|
|
526
526
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -530,7 +530,7 @@
|
|
|
530
530
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
531
531
|
"@smithy/eventstream-codec": "4.2.14",
|
|
532
532
|
"@smithy/util-utf8": "4.2.2",
|
|
533
|
-
"@opencode/schema": "0.0.0-dev-
|
|
533
|
+
"@opencode/schema": "0.0.0-dev-552",
|
|
534
534
|
"aws4fetch": "1.0.20",
|
|
535
535
|
"effect": "4.1.0",
|
|
536
536
|
"google-auth-library": "10.5.0"
|