opencode-bedrock-1m 1.0.0 → 1.0.2

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 (3) hide show
  1. package/README.md +0 -13
  2. package/package.json +2 -2
  3. package/src/index.ts +19 -9
package/README.md CHANGED
@@ -8,8 +8,6 @@ Claude Opus 4.6 and Sonnet 4.6/4.5 support a 1M token context window, but AWS Be
8
8
 
9
9
  OpenCode currently sends this header only for `claude-sonnet-*` models. This plugin fixes the issue for all supported models and also surfaces Bedrock quota errors directly in the UI.
10
10
 
11
- Tracked in: [#12338](https://github.com/anomalyco/opencode/issues/12338), [#12452](https://github.com/anomalyco/opencode/issues/12452), [#12507](https://github.com/anomalyco/opencode/issues/12507)
12
-
13
11
  ## Features
14
12
 
15
13
  - Injects `anthropic-beta: context-1m-2025-08-07` for all supported Claude models on Bedrock
@@ -54,17 +52,6 @@ Since OpenCode may still display the wrong context limit in the UI, add these ov
54
52
  }
55
53
  ```
56
54
 
57
- ## AWS Bedrock quota notes
58
-
59
- Enabling the 1M context header moves your requests to the **1M Context Length** quota bucket:
60
-
61
- | Model | Standard RPM | 1M Context RPM | Standard tokens/day | 1M Context tokens/day |
62
- |-------|-------------|----------------|--------------------|-----------------------|
63
- | Opus 4.6 | 25 | 1 | 1,296,000 | 27,000,000 |
64
- | Sonnet 4.6 | 50 | 1 | 5,400,000 | 6,480,000 |
65
-
66
- The 1M context profile has a lower RPM (1 req/min) but a much higher daily token quota for Opus. For Sonnet, the daily advantage is marginal — consider only enabling 1M context for sessions that actually need it.
67
-
68
55
  ## License
69
56
 
70
57
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-bedrock-1m",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "OpenCode plugin that enables 1M context window for Claude models on AWS Bedrock via the context-1m-2025-08-07 beta header, with quota error reporting.",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "license": "MIT",
21
21
  "repository": {
22
22
  "type": "git",
23
- "url": "https://github.com/JAM-Development/opencode-bedrock-1m"
23
+ "url": "git+https://github.com/J-A-M-Development/opencode-bedrock-1m.git"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@opencode-ai/plugin": ">=1.0.0"
package/src/index.ts CHANGED
@@ -23,10 +23,12 @@ const QUOTA_MESSAGES: Record<string, string> = {
23
23
  "Too many tokens per day":
24
24
  "Bedrock daily token quota exhausted for this model. Switch to another region (EU/Global/US) or wait for the reset at midnight UTC.",
25
25
  "Too many requests":
26
- "Bedrock RPM quota exceeded. You are on the 1M context profile (1 RPM). Wait a moment before retrying.",
26
+ "Bedrock RPM quota exceeded. Wait a moment before retrying.",
27
27
  }
28
28
 
29
29
  export const BedrockContextPlugin: Plugin = async ({ client }) => {
30
+ const notified = new Set<string>()
31
+
30
32
  return {
31
33
  /**
32
34
  * Inject the 1M context beta header for supported Claude models on Bedrock.
@@ -51,24 +53,32 @@ export const BedrockContextPlugin: Plugin = async ({ client }) => {
51
53
  },
52
54
 
53
55
  /**
54
- * Intercept session errors and surface Bedrock quota errors as toasts.
56
+ * Intercept message updates to detect Bedrock quota errors and surface them as toasts.
57
+ * session.error is not triggered for retryable errors — message.updated is more reliable.
55
58
  */
56
- "session.error": async ({ error, sessionID }) => {
57
- if (!error) return
59
+ "message.updated": async ({ message }) => {
60
+ if (!message) return
61
+
62
+ const parts = (message as any).parts ?? []
63
+ for (const part of parts) {
64
+ const text: string = part?.text ?? part?.error ?? ""
65
+ if (!text) continue
66
+
67
+ for (const [pattern, userMessage] of Object.entries(QUOTA_MESSAGES)) {
68
+ if (!text.includes(pattern)) continue
58
69
 
59
- const message = typeof error === "string" ? error : (error as Error).message ?? ""
70
+ const key = `${message.id}:${pattern}`
71
+ if (notified.has(key)) break
72
+ notified.add(key)
60
73
 
61
- for (const [pattern, userMessage] of Object.entries(QUOTA_MESSAGES)) {
62
- if (message.includes(pattern)) {
63
74
  await client.app.log({
64
75
  body: {
65
76
  service: "opencode-bedrock-1m",
66
77
  level: "warn",
67
- message: `Bedrock quota error on session ${sessionID}: ${message}`,
78
+ message: `Bedrock quota error: ${text}`,
68
79
  },
69
80
  })
70
81
 
71
- // Surface to the user via toast
72
82
  await client.event.publish({
73
83
  body: {
74
84
  type: "tui.toast.show",