Skip to content

Commit debcfb7

Browse files
committed
fix: add modalities support for input/output in configuration and improve toast notifications in plugin
1 parent 17a0e15 commit debcfb7

3 files changed

Lines changed: 59 additions & 44 deletions

File tree

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,65 @@ Open the **same config file** you created in Step 1 (`~/.config/opencode/opencod
6868
"limit": {
6969
"context": 1048576,
7070
"output": 65535
71+
},
72+
"modalities": {
73+
"input": ["text", "image", "pdf"],
74+
"output": ["text"]
7175
}
7276
},
7377
"gemini-3-pro-low": {
7478
"name": "Gemini 3 Pro Low (Antigravity)",
7579
"limit": {
7680
"context": 1048576,
7781
"output": 65535
82+
},
83+
"modalities": {
84+
"input": ["text", "image", "pdf"],
85+
"output": ["text"]
7886
}
7987
},
8088
"claude-sonnet-4-5": {
8189
"name": "Claude Sonnet 4.5 (Antigravity)",
8290
"limit": {
8391
"context": 200000,
8492
"output": 64000
93+
},
94+
"modalities": {
95+
"input": ["text", "image", "pdf"],
96+
"output": ["text"]
8597
}
8698
},
8799
"claude-sonnet-4-5-thinking": {
88100
"name": "Claude Sonnet 4.5 Thinking (Antigravity)",
89101
"limit": {
90102
"context": 200000,
91103
"output": 64000
104+
},
105+
"modalities": {
106+
"input": ["text", "image", "pdf"],
107+
"output": ["text"]
92108
}
93109
},
94110
"claude-opus-4-5-thinking": {
95111
"name": "Claude Opus 4.5 Thinking (Antigravity)",
96112
"limit": {
97113
"context": 200000,
98114
"output": 64000
115+
},
116+
"modalities": {
117+
"input": ["text", "image", "pdf"],
118+
"output": ["text"]
99119
}
100120
},
101121
"gpt-oss-120b-medium": {
102122
"name": "GPT-OSS 120B Medium (Antigravity)",
103123
"limit": {
104124
"context": 131072,
105125
"output": 32768
126+
},
127+
"modalities": {
128+
"input": ["text", "image", "pdf"],
129+
"output": ["text"]
106130
}
107131
}
108132
}
@@ -111,7 +135,7 @@ Open the **same config file** you created in Step 1 (`~/.config/opencode/opencod
111135
}
112136
```
113137

114-
> **Tip:** You only need to add the models you plan to use. The example above includes all available models, but you can remove any you don't need.
138+
> **Tip:** You only need to add the models you plan to use. The example above includes all available models, but you can remove any you don't need. The `modalities` field enables image and PDF support in the TUI.
115139
116140
### Step 4: Use a model
117141

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencode-antigravity-auth",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Google Antigravity IDE OAuth auth plugin for Opencode - access Gemini 3 Pro and Claude 4.5 using Google credentials",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/plugin.ts

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ export const createAntigravityPlugin = (providerId: string) => async (
243243
auth: {
244244
provider: providerId,
245245
loader: async (getAuth: GetAuth, provider: Provider): Promise<LoaderResult | Record<string, unknown>> => {
246-
// Track which account was used in the previous request for detecting switches
247-
let previousAccountIndex: number | null = null;
248246
const auth = await getAuth();
249247

250248
// If OpenCode has no valid OAuth auth, clear any stale account storage
@@ -334,10 +332,36 @@ export const createAntigravityPlugin = (providerId: string) => async (
334332
let lastFailure: FailureContext | null = null;
335333
let lastError: Error | null = null;
336334
const abortSignal = init?.signal ?? undefined;
335+
336+
// Track which account was used in this request for detecting switches
337+
// This is scoped to the fetch call so it resets per-request
338+
let previousAccountIndex: number | null = null;
339+
340+
// Helper to check if request was aborted
341+
const checkAborted = () => {
342+
if (abortSignal?.aborted) {
343+
throw abortSignal.reason instanceof Error ? abortSignal.reason : new Error("Aborted");
344+
}
345+
};
346+
347+
// Helper to show toast without blocking on abort
348+
const showToast = async (message: string, variant: "info" | "warning" | "success" | "error") => {
349+
if (abortSignal?.aborted) return;
350+
try {
351+
await client.tui.showToast({
352+
body: { message, variant },
353+
});
354+
} catch {
355+
// TUI may not be available
356+
}
357+
};
337358

338359
// Use while(true) loop to handle rate limits with backoff
339360
// This ensures we wait and retry when all accounts are rate-limited
340361
while (true) {
362+
// Check for abort at the start of each iteration
363+
checkAborted();
364+
341365
const accountCount = accountManager.getAccountCount();
342366

343367
if (accountCount === 0) {
@@ -351,16 +375,7 @@ export const createAntigravityPlugin = (providerId: string) => async (
351375
const waitMs = accountManager.getMinWaitTimeMs() || 60_000;
352376
const waitSec = Math.max(1, Math.ceil(waitMs / 1000));
353377

354-
try {
355-
await client.tui.showToast({
356-
body: {
357-
message: `All ${accountCount} account(s) rate-limited. Waiting ${waitSec}s...`,
358-
variant: "warning",
359-
},
360-
});
361-
} catch {
362-
// TUI may not be available
363-
}
378+
await showToast(`All ${accountCount} account(s) rate-limited. Waiting ${waitSec}s...`, "warning");
364379

365380
// Wait for the cooldown to expire
366381
await sleep(waitMs, abortSignal);
@@ -371,16 +386,10 @@ export const createAntigravityPlugin = (providerId: string) => async (
371386
const isAccountSwitch = previousAccountIndex !== null && previousAccountIndex !== account.index;
372387
if (isAccountSwitch || previousAccountIndex === null) {
373388
const accountLabel = account.email || `Account ${account.index + 1}`;
374-
try {
375-
await client.tui.showToast({
376-
body: {
377-
message: `Using ${accountLabel}${accountCount > 1 ? ` (${account.index + 1}/${accountCount})` : ""}`,
378-
variant: "info",
379-
},
380-
});
381-
} catch {
382-
// TUI may not be available
383-
}
389+
await showToast(
390+
`Using ${accountLabel}${accountCount > 1 ? ` (${account.index + 1}/${accountCount})` : ""}`,
391+
"info"
392+
);
384393
}
385394
previousAccountIndex = account.index;
386395

@@ -515,16 +524,7 @@ export const createAntigravityPlugin = (providerId: string) => async (
515524

516525
if (accountManager.getAccountCount() > 1) {
517526
// Multiple accounts - switch to next
518-
try {
519-
await client.tui.showToast({
520-
body: {
521-
message: `Rate limited on ${accountLabel}. Switching...`,
522-
variant: "warning",
523-
},
524-
});
525-
} catch {
526-
// TUI may not be available
527-
}
527+
await showToast(`Rate limited on ${accountLabel}. Switching...`, "warning");
528528

529529
lastFailure = {
530530
response,
@@ -543,16 +543,7 @@ export const createAntigravityPlugin = (providerId: string) => async (
543543
} else {
544544
// Single account - wait and retry
545545
const waitSec = Math.max(1, Math.ceil(retryAfterMs / 1000));
546-
try {
547-
await client.tui.showToast({
548-
body: {
549-
message: `Rate limited. Waiting ${waitSec}s...`,
550-
variant: "warning",
551-
},
552-
});
553-
} catch {
554-
// TUI may not be available
555-
}
546+
await showToast(`Rate limited. Waiting ${waitSec}s...`, "warning");
556547

557548
lastFailure = {
558549
response,

0 commit comments

Comments
 (0)