@opencode/ai 0.0.0-dev-21784 → 0.0.0-dev-21788

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.
@@ -1026,7 +1026,6 @@ const mergeUsage = (left, right, providerMetadataKey) => {
1026
1026
  reasoningTokens,
1027
1027
  totalTokens: ProviderShared.totalTokens(inputTokens, outputTokens, undefined),
1028
1028
  cost: right.cost ?? left.cost,
1029
- allowance: right.allowance ?? left.allowance,
1030
1029
  providerMetadata: {
1031
1030
  [providerMetadataKey]: mergeJsonRecords(left.providerMetadata?.[providerMetadataKey], right.providerMetadata?.[providerMetadataKey]) ??
1032
1031
  {},
@@ -106,9 +106,6 @@ declare const GeminiBody: Schema.Struct<{
106
106
  export type GeminiBody = Schema.Schema.Type<typeof GeminiBody>;
107
107
  declare const GeminiUsage: Schema.Struct<{
108
108
  readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
109
- readonly opencode: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Struct<{
110
- readonly allowance: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
111
- }>>, never>>;
112
109
  readonly cachedContentTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
113
110
  readonly thoughtsTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
114
111
  readonly promptTokenCount: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -264,9 +261,6 @@ export declare const protocol: Protocol<{
264
261
  } | null | undefined;
265
262
  readonly usageMetadata?: {
266
263
  readonly cost?: number | undefined;
267
- readonly opencode?: {
268
- readonly allowance?: number | undefined;
269
- } | undefined;
270
264
  readonly cachedContentTokenCount?: number | null | undefined;
271
265
  readonly thoughtsTokenCount?: number | null | undefined;
272
266
  readonly promptTokenCount?: number | null | undefined;
@@ -295,9 +289,6 @@ export declare const protocol: Protocol<{
295
289
  } | null | undefined;
296
290
  readonly usageMetadata?: {
297
291
  readonly cost?: number | undefined;
298
- readonly opencode?: {
299
- readonly allowance?: number | undefined;
300
- } | undefined;
301
292
  readonly cachedContentTokenCount?: number | null | undefined;
302
293
  readonly thoughtsTokenCount?: number | null | undefined;
303
294
  readonly promptTokenCount?: number | null | undefined;
@@ -433,7 +433,6 @@ const mapUsage = (usage, metadataKey, metadata = usage ?? {}) => {
433
433
  reasoningTokens: thoughts,
434
434
  totalTokens: ProviderShared.totalTokens(promptTokens, outputTokens, usage.totalTokenCount ?? undefined),
435
435
  cost: usage.cost,
436
- allowance: usage.opencode?.allowance,
437
436
  providerMetadata: providerMetadata(metadataKey, metadata),
438
437
  });
439
438
  };
@@ -449,7 +448,6 @@ const mapContinuedUsage = (requests, metadataKey) => {
449
448
  thoughtsTokenCount: sum("thoughtsTokenCount"),
450
449
  // Every continued request is billed on its own.
451
450
  cost: sum("cost"),
452
- opencode: { allowance: ProviderShared.sumTokens(...requests.map((usage) => usage.opencode?.allowance)) },
453
451
  }, metadataKey, {
454
452
  promptTokenCount: sum("promptTokenCount"),
455
453
  cachedContentTokenCount: sum("cachedContentTokenCount"),
@@ -13,20 +13,13 @@ export declare const optionalNull: <const S extends Schema.Top>(schema: S) => Sc
13
13
  export declare const optionalNullish: <const S extends Schema.Top>(schema: S) => Schema.decodeTo<Schema.optional<Schema.toType<S>>, Schema.optional<Schema.NullOr<S>>, never, never>;
14
14
  /** Optional field whose malformed value decodes to `undefined` instead of failing the enclosing struct. */
15
15
  export declare const lenient: <const S extends Schema.Top>(schema: S) => Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<S>, S["DecodingServices"]>>;
16
- /**
17
- * Billing an endpoint reports beside its token usage. `cost` is the USD it charged (OpenRouter, LiteLLM, OpenCode
18
- * Zen); OpenCode Go reports the subscription allowance a request used as `opencode.allowance`, also in USD.
19
- */
16
+ /** Billing an endpoint reports beside its token usage: `cost` is the USD it charged (OpenRouter, LiteLLM, OpenCode Zen). */
20
17
  export declare const ReportedBilling: Schema.Struct<{
21
18
  readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
22
- readonly opencode: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Struct<{
23
- readonly allowance: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
24
- }>>, never>>;
25
19
  }>;
26
20
  /** Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it. */
27
21
  export declare const reportedBilling: (usage: unknown) => {} | {
28
22
  cost: number | undefined;
29
- allowance: number | undefined;
30
23
  };
31
24
  /**
32
25
  * Accepts stream frames that carry no `type`, alongside the typed event schema. Gateways inject such frames as
@@ -19,18 +19,14 @@ export const optionalNullish = (schema) => Schema.optional(Schema.NullOr(schema)
19
19
  export const lenient = (schema) => Schema.optionalKey(Schema.UndefinedOr(schema).pipe(Schema.catchDecoding(() => Effect.succeed(Option.some(undefined)))));
20
20
  /** A billed amount in USD; a malformed or negative one decodes as absent. */
21
21
  const billedAmount = lenient(Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)));
22
- /**
23
- * Billing an endpoint reports beside its token usage. `cost` is the USD it charged (OpenRouter, LiteLLM, OpenCode
24
- * Zen); OpenCode Go reports the subscription allowance a request used as `opencode.allowance`, also in USD.
25
- */
22
+ /** Billing an endpoint reports beside its token usage: `cost` is the USD it charged (OpenRouter, LiteLLM, OpenCode Zen). */
26
23
  export const ReportedBilling = Schema.Struct({
27
24
  cost: billedAmount,
28
- opencode: lenient(Schema.Struct({ allowance: billedAmount })),
29
25
  });
30
26
  /** Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it. */
31
27
  export const reportedBilling = (usage) => Option.match(Schema.decodeUnknownOption(ReportedBilling)(usage), {
32
28
  onNone: () => ({}),
33
- onSome: (billing) => ({ cost: billing.cost, allowance: billing.opencode?.allowance }),
29
+ onSome: (billing) => ({ cost: billing.cost }),
34
30
  });
35
31
  /**
36
32
  * Accepts stream frames that carry no `type`, alongside the typed event schema. Gateways inject such frames as
@@ -50,6 +50,8 @@ const exclusions = [
50
50
  /too many requests/i,
51
51
  // Cohere reports an output limit above the model maximum as "too many tokens"; compaction cannot fix it.
52
52
  /max[_ ]tokens must be less than/i,
53
+ // Bedrock phrases throttling as "Too many tokens[, per day], please wait..."; it is a 429 to retry, not overflow.
54
+ /too many tokens(?: per day)?, please wait/i,
53
55
  ];
54
56
  export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
55
57
  (patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
@@ -21,8 +21,6 @@ declare const Usage_base: Schema.Class<Usage, Schema.Struct<{
21
21
  * tokens themselves.
22
22
  */
23
23
  readonly cost: Schema.optional<Schema.Number>;
24
- /** USD of subscription allowance the request used, as OpenCode Go reports it in `usage.opencode.allowance`. */
25
- readonly allowance: Schema.optional<Schema.Number>;
26
24
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
27
25
  }>, {}>;
28
26
  /**
@@ -67,8 +67,6 @@ export class Usage extends Schema.Class("AI.Usage")({
67
67
  * tokens themselves.
68
68
  */
69
69
  cost: Schema.optional(Schema.Number),
70
- /** USD of subscription allowance the request used, as OpenCode Go reports it in `usage.opencode.allowance`. */
71
- allowance: Schema.optional(Schema.Number),
72
70
  providerMetadata: Schema.optional(ProviderMetadata),
73
71
  }) {
74
72
  /**
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-21784",
3
+ "version": "0.0.0-dev-21788",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@clack/prompts": "1.0.0-alpha.1",
37
37
  "@effect/platform-node": "4.0.1",
38
- "@opencode/http-recorder": "0.0.0-dev-21784",
38
+ "@opencode/http-recorder": "0.0.0-dev-21788",
39
39
  "@tsconfig/bun": "1.0.9",
40
40
  "@types/bun": "1.4.3",
41
41
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -45,7 +45,7 @@
45
45
  "@aws-sdk/credential-providers": "3.1057.0",
46
46
  "@smithy/eventstream-codec": "4.2.14",
47
47
  "@smithy/util-utf8": "4.2.2",
48
- "@opencode/schema": "0.0.0-dev-21784",
48
+ "@opencode/schema": "0.0.0-dev-21788",
49
49
  "aws4fetch": "1.0.20",
50
50
  "effect": "4.0.1",
51
51
  "google-auth-library": "10.5.0"