Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
feat: add Altimate provider with /login command and credential valida…#606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
22c693b
feat: add altimate-backend TUI connect flow with credential validation
suryaiyer95 d27f30d
Merge branch 'main' into feat/login-auto-model-v2
anandgupta42 d7197a8
fix: address CodeRabbit review feedback on Altimate provider PR
anandgupta42 3c5450b
fix: guard `Auth.remove()` calls and add empty-string env var test
anandgupta42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { Hooks, PluginInput } from "@opencode-ai/plugin" | ||
| export async function AltimateAuthPlugin(_input: PluginInput): Promise<Hooks> { | ||
| return { | ||
| auth: { | ||
| provider: "altimate-backend", | ||
| methods: [ | ||
| { | ||
| type: "api", | ||
| label: "Connect to Altimate", | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47 packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ import { iife } from "@/util/iife" | ||
| import { Global } from "../global" | ||
| import path from "path" | ||
| import { Filesystem } from "../util/filesystem" | ||
| import { AltimateApi } from "../altimate/api/client" | ||
| // Direct imports for bundled providers | ||
| import { createAmazonBedrock, type AmazonBedrockProviderSettings } from "@ai-sdk/amazon-bedrock" | ||
| @@ -181,6 +182,51 @@ export namespace Provider { | ||
| options: hasKey ? {} : { apiKey: "public" }, | ||
| } | ||
| }, | ||
| // altimate_change start — Altimate backend provider: ~/.altimate/altimate.json first, auth store (TUI-configured) as fallback | ||
| "altimate-backend": async () => { | ||
| // Path 1: ~/.altimate/altimate.json (primary — manual file or env-var substitution, never overwritten) | ||
| const isConfigured = await AltimateApi.isConfigured() | ||
| if (isConfigured) { | ||
| try { | ||
| const creds = await AltimateApi.getCredentials() | ||
| return { | ||
| autoload: true, | ||
| options: { | ||
| baseURL: `${creds.altimateUrl.replace(/\/+$/, "")}/agents/v1`, | ||
| apiKey: creds.altimateApiKey, | ||
| headers: { | ||
| "x-tenant": creds.altimateInstanceName, | ||
| }, | ||
| }, | ||
| } | ||
| } catch { | ||
| // Suppress stale auth so the generic Auth.all() merge doesn't leave an invalid provider | ||
| await Auth.remove(ProviderID.make("altimate-backend")).catch(() => {}) | ||
| return { autoload: false } | ||
| } | ||
| } | ||
| // Path 2: auth store (populated by TUI entry, file not yet written) | ||
| const auth = await Auth.get(ProviderID.make("altimate-backend")) | ||
| if (auth?.type === "api") { | ||
| const parsed = AltimateApi.parseAltimateKey(auth.key) | ||
| if (parsed) { | ||
| return { | ||
| autoload: true, | ||
| options: { | ||
| baseURL: `${parsed.altimateUrl.replace(/\/+$/, "")}/agents/v1`, | ||
| apiKey: parsed.altimateApiKey, | ||
| headers: { | ||
| "x-tenant": parsed.altimateInstanceName, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| // Invalid key format — remove stale auth entry | ||
| await Auth.remove(ProviderID.make("altimate-backend")).catch(() => {}) | ||
| } | ||
| return { autoload: false } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }, | ||
| // altimate_change end | ||
| openai: async () => { | ||
| return { | ||
| autoload: false, | ||
| @@ -973,6 +1019,45 @@ export namespace Provider { | ||
| } | ||
| // altimate_change end | ||
| // altimate_change start — register altimate-backend as an OpenAI-compatible provider | ||
| if (!database["altimate-backend"]) { | ||
| const backendModels: Record<string, Model> = { | ||
| "altimate-default": { | ||
| id: ModelID.make("altimate-default"), | ||
| providerID: ProviderID.make("altimate-backend"), | ||
| name: "Altimate AI", | ||
| family: "openai", | ||
| api: { id: "altimate-default", url: "", npm: "@ai-sdk/openai-compatible" }, | ||
| status: "active", | ||
| headers: {}, | ||
| options: {}, | ||
| cost: { input: 0, output: 0, cache: { read: 0, write: 0 } }, | ||
| limit: { context: 200000, output: 128000 }, | ||
| capabilities: { | ||
| temperature: true, | ||
| reasoning: false, | ||
| attachment: false, | ||
| toolcall: true, | ||
| input: { text: true, audio: false, image: true, video: false, pdf: false }, | ||
| output: { text: true, audio: false, image: false, video: false, pdf: false }, | ||
| interleaved: false, | ||
| }, | ||
| release_date: "2025-01-01", | ||
| variants: {}, | ||
| }, | ||
| } | ||
| database["altimate-backend"] = { | ||
| id: ProviderID.make("altimate-backend"), | ||
| name: "Altimate", | ||
| source: "custom", | ||
| env: [], | ||
| options: {}, | ||
| models: backendModels, | ||
| } | ||
| } | ||
| // altimate_change end | ||
| function mergeProvider(providerID: ProviderID, provider: Partial<Info>) { | ||
| const existing = providers[providerID] | ||
| if (existing) { | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.