GeezerVison is showing github.com — feat(opencode): add external browser OAuth for snowflake cortex provi… · rodboev/opencode@3f17453
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider/snowflake-cortex.ts +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,14 +70,17 @@ export const SnowflakeCortexPlugin = PluginV2.define({ | 70 | 70 | return { | 71 | 71 | "aisdk.sdk": Effect.fn(function* (evt) { | 72 | 72 | if (evt.model.providerID !== ProviderV2.ID.make("snowflake-cortex")) return | 73 | | - const pat = | 74 | | - process.env.SNOWFLAKE_CORTEX_PAT ?? (typeof evt.options.apiKey === "string" ? evt.options.apiKey : undefined) | | 73 | + const token = | | 74 | + process.env.SNOWFLAKE_CORTEX_TOKEN ?? | | 75 | + process.env.SNOWFLAKE_CORTEX_PAT ?? | | 76 | + (typeof evt.options.token === "string" ? evt.options.token : undefined) ?? | | 77 | + (typeof evt.options.apiKey === "string" ? evt.options.apiKey : undefined) | 75 | 78 | const upstream = typeof evt.options.fetch === "function" ? (evt.options.fetch as FetchLike) : undefined | 76 | 79 | if (evt.options.includeUsage !== false) evt.options.includeUsage = true | 77 | 80 | const mod = yield* Effect.promise(() => import("@ai-sdk/openai-compatible")) | 78 | 81 | evt.sdk = mod.createOpenAICompatible({ | 79 | 82 | ...evt.options, | 80 | | - ...(pat ? { apiKey: pat } : {}), | | 83 | + ...(token ? { apiKey: token } : {}), | 81 | 84 | fetch: cortexFetch(upstream) as typeof fetch, | 82 | 85 | } as any) | 83 | 86 | }), | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/plugin/provider-snowflake-cortex.test.ts +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,6 +72,48 @@ describe("SnowflakeCortexPlugin", () => { | 72 | 72 | ), | 73 | 73 | ) | 74 | 74 |
| | 75 | + it.effect("uses SNOWFLAKE_CORTEX_TOKEN env var", () => | | 76 | + withEnv({ SNOWFLAKE_CORTEX_TOKEN: "oauth-token", SNOWFLAKE_CORTEX_PAT: undefined }, () => | | 77 | + Effect.gen(function* () { | | 78 | + const plugin = yield* PluginV2.Service | | 79 | + yield* plugin.add(SnowflakeCortexPlugin) | | 80 | + const result = yield* plugin.trigger( | | 81 | + "aisdk.sdk", | | 82 | + { | | 83 | + model: model("snowflake-cortex", "claude-sonnet-4-6"), | | 84 | + package: "@ai-sdk/openai-compatible", | | 85 | + options: { name: "snowflake-cortex", baseURL: "https://test.snowflakecomputing.com/api/v2/cortex/v1" }, | | 86 | + }, | | 87 | + {}, | | 88 | + ) | | 89 | + expect(result.sdk).toBeDefined() | | 90 | + }), | | 91 | + ), | | 92 | + ) | | 93 | + | | 94 | + it.effect("falls back to options.token when no Snowflake env token is set", () => | | 95 | + withEnv({ SNOWFLAKE_CORTEX_TOKEN: undefined, SNOWFLAKE_CORTEX_PAT: undefined }, () => | | 96 | + Effect.gen(function* () { | | 97 | + const plugin = yield* PluginV2.Service | | 98 | + yield* plugin.add(SnowflakeCortexPlugin) | | 99 | + const result = yield* plugin.trigger( | | 100 | + "aisdk.sdk", | | 101 | + { | | 102 | + model: model("snowflake-cortex", "claude-sonnet-4-6"), | | 103 | + package: "@ai-sdk/openai-compatible", | | 104 | + options: { | | 105 | + name: "snowflake-cortex", | | 106 | + baseURL: "https://test.snowflakecomputing.com/api/v2/cortex/v1", | | 107 | + token: "options-token", | | 108 | + }, | | 109 | + }, | | 110 | + {}, | | 111 | + ) | | 112 | + expect(result.sdk).toBeDefined() | | 113 | + }), | | 114 | + ), | | 115 | + ) | | 116 | + | 75 | 117 | it.effect("sets includeUsage on the SDK options", () => | 76 | 118 | withEnv({ SNOWFLAKE_CORTEX_PAT: "test-pat" }, () => | 77 | 119 | Effect.gen(function* () { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/providers.ts -19Lines changed: 0 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -477,25 +477,6 @@ export const ProvidersLoginCommand = effectCmd({ | 477 | 477 | ) | 478 | 478 | } | 479 | 479 |
| 480 | | - if (provider === "snowflake-cortex") { | 481 | | - const account = yield* promptValue( | 482 | | - yield* Prompt.text({ | 483 | | - message: "Snowflake Account Identifier", | 484 | | - placeholder: "xy12345.us-east-1", | 485 | | - validate: (x) => (x && x.length > 0 ? undefined : "Required"), | 486 | | - }), | 487 | | - ) | 488 | | - const pat = yield* promptValue( | 489 | | - yield* Prompt.password({ | 490 | | - message: "Programmatic Access Token (PAT)", | 491 | | - validate: (x) => (x && x.length > 0 ? undefined : "Required"), | 492 | | - }), | 493 | | - ) | 494 | | - yield* Effect.orDie(authSvc.set(provider, { type: "api", key: pat, metadata: { account } })) | 495 | | - yield* Prompt.outro("Done") | 496 | | - return | 497 | | - } | 498 | | - | 499 | 480 | const key = yield* Prompt.password({ | 500 | 481 | message: "Enter your API key", | 501 | 482 | validate: (x) => (x && x.length > 0 ? undefined : "Required"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/index.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cl | 19 | 19 | import { AzureAuthPlugin } from "./azure" | 20 | 20 | import { DigitalOceanAuthPlugin } from "./digitalocean" | 21 | 21 | import { XaiAuthPlugin } from "./xai" | | 22 | +import { SnowflakeCortexAuthPlugin } from "./snowflake-cortex" | 22 | 23 | import { Effect, Layer, Context } from "effect" | 23 | 24 | import { EffectBridge } from "@/effect/bridge" | 24 | 25 | import { InstanceState } from "@/effect/instance-state" | @@ -75,6 +76,7 @@ function internalPlugins(flags: RuntimeFlags.Info): PluginInstance[] { | 75 | 76 | CloudflareAIGatewayAuthPlugin, | 76 | 77 | AzureAuthPlugin, | 77 | 78 | DigitalOceanAuthPlugin, | | 79 | + SnowflakeCortexAuthPlugin, | 78 | 80 | XaiAuthPlugin, | 79 | 81 | ] | 80 | 82 | } | |
|