opencode-bedrock-1m 1.0.1 → 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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-bedrock-1m",
3
- "version": "1.0.1",
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",
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",