mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-08 10:09:52 -04:00
refactor(core): clarify provider form selection
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { Effect } from "effect"
|
||||
import { define } from "@opencode-ai/plugin/effect/plugin"
|
||||
import type { Form } from "@opencode-ai/schema/form"
|
||||
import { Provider } from "../../provider"
|
||||
import type { DeepMutable } from "../../schema"
|
||||
import { iife } from "../../util/iife"
|
||||
import { configuredSettings } from "./configured"
|
||||
|
||||
function selectLanguage(sdk: any, modelID: string, useChat: boolean) {
|
||||
@@ -15,24 +18,25 @@ export const AzurePlugin = define({
|
||||
id: "opencode.provider.azure",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const configured = yield* configuredSettings(Provider.ID.azure)
|
||||
const forms = iife((): DeepMutable<Form.Fields> | undefined => {
|
||||
if (resolveResourceName(configured) || typeof configured?.baseURL === "string") return
|
||||
return [
|
||||
{
|
||||
type: "string",
|
||||
key: "resourceName",
|
||||
title: "Enter Azure Resource Name",
|
||||
placeholder: "e.g. my-models",
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
})
|
||||
yield* ctx.integration.transform((draft) => {
|
||||
draft.method.update({
|
||||
integrationID: Provider.ID.azure,
|
||||
method: {
|
||||
type: "key",
|
||||
label: "API key",
|
||||
forms:
|
||||
resolveResourceName(configured) || typeof configured?.baseURL === "string"
|
||||
? undefined
|
||||
: [
|
||||
{
|
||||
type: "string",
|
||||
key: "resourceName",
|
||||
title: "Enter Azure Resource Name",
|
||||
placeholder: "e.g. my-models",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
forms,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,7 +2,10 @@ import os from "os"
|
||||
import { App } from "../../app"
|
||||
import { Effect, Option, Schema } from "effect"
|
||||
import { define } from "@opencode-ai/plugin/effect/plugin"
|
||||
import type { Form } from "@opencode-ai/schema/form"
|
||||
import { Provider } from "../../provider"
|
||||
import type { DeepMutable } from "../../schema"
|
||||
import { iife } from "../../util/iife"
|
||||
import { configuredSettings } from "./configured"
|
||||
|
||||
const providerID = Provider.ID.make("cloudflare-ai-gateway")
|
||||
@@ -11,44 +14,39 @@ export const CloudflareAIGatewayPlugin = define({
|
||||
id: "opencode.provider.cloudflare-ai-gateway",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const configured = yield* configuredSettings(providerID)
|
||||
const hasBaseURL = typeof configured?.baseURL === "string"
|
||||
yield* ctx.integration.transform((draft) => {
|
||||
const hasAccountId =
|
||||
hasBaseURL || Boolean(process.env.CLOUDFLARE_ACCOUNT_ID || stringOption(configured ?? {}, "accountId"))
|
||||
const hasGatewayId =
|
||||
hasBaseURL ||
|
||||
Boolean(
|
||||
process.env.CLOUDFLARE_GATEWAY_ID ||
|
||||
stringOption(configured ?? {}, "gatewayId") ||
|
||||
stringOption(configured ?? {}, "gateway"),
|
||||
)
|
||||
const forms = iife((): DeepMutable<Form.Fields> | undefined => {
|
||||
if (typeof configured?.baseURL === "string") return
|
||||
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID || stringOption(configured ?? {}, "accountId")
|
||||
const gatewayId =
|
||||
process.env.CLOUDFLARE_GATEWAY_ID ||
|
||||
stringOption(configured ?? {}, "gatewayId") ||
|
||||
stringOption(configured ?? {}, "gateway")
|
||||
if (accountId && gatewayId) return
|
||||
const accountIdForm = {
|
||||
type: "string" as const,
|
||||
type: "string",
|
||||
key: "accountId",
|
||||
title: "Enter your Cloudflare Account ID",
|
||||
placeholder: "e.g. 1234567890abcdef1234567890abcdef",
|
||||
required: true,
|
||||
}
|
||||
} satisfies DeepMutable<Form.Field>
|
||||
const gatewayIdForm = {
|
||||
type: "string" as const,
|
||||
type: "string",
|
||||
key: "gatewayId",
|
||||
title: "Enter your Cloudflare AI Gateway ID",
|
||||
placeholder: "e.g. my-gateway",
|
||||
required: true,
|
||||
}
|
||||
} satisfies DeepMutable<Form.Field>
|
||||
if (accountId) return [gatewayIdForm]
|
||||
if (gatewayId) return [accountIdForm]
|
||||
return [accountIdForm, gatewayIdForm]
|
||||
})
|
||||
yield* ctx.integration.transform((draft) => {
|
||||
draft.method.update({
|
||||
integrationID: providerID,
|
||||
method: {
|
||||
type: "key",
|
||||
label: "Gateway API token",
|
||||
forms:
|
||||
!hasAccountId && !hasGatewayId
|
||||
? [accountIdForm, gatewayIdForm]
|
||||
: !hasAccountId
|
||||
? [accountIdForm]
|
||||
: !hasGatewayId
|
||||
? [gatewayIdForm]
|
||||
: undefined,
|
||||
forms,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,7 +2,10 @@ import os from "os"
|
||||
import { App } from "../../app"
|
||||
import { Effect } from "effect"
|
||||
import { define } from "@opencode-ai/plugin/effect/plugin"
|
||||
import type { Form } from "@opencode-ai/schema/form"
|
||||
import { Provider } from "../../provider"
|
||||
import type { DeepMutable } from "../../schema"
|
||||
import { iife } from "../../util/iife"
|
||||
import { configuredSettings } from "./configured"
|
||||
|
||||
const providerID = Provider.ID.make("cloudflare-workers-ai")
|
||||
@@ -11,24 +14,25 @@ export const CloudflareWorkersAIPlugin = define({
|
||||
id: "opencode.provider.cloudflare-workers-ai",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const configured = yield* configuredSettings(providerID)
|
||||
const forms = iife((): DeepMutable<Form.Fields> | undefined => {
|
||||
if (typeof configured?.baseURL === "string" || resolveAccountId(configured ?? {})) return
|
||||
return [
|
||||
{
|
||||
type: "string",
|
||||
key: "accountId",
|
||||
title: "Enter your Cloudflare Account ID",
|
||||
placeholder: "e.g. 1234567890abcdef1234567890abcdef",
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
})
|
||||
yield* ctx.integration.transform((draft) => {
|
||||
draft.method.update({
|
||||
integrationID: providerID,
|
||||
method: {
|
||||
type: "key",
|
||||
label: "API key",
|
||||
forms:
|
||||
typeof configured?.baseURL === "string" || resolveAccountId(configured ?? {})
|
||||
? undefined
|
||||
: [
|
||||
{
|
||||
type: "string",
|
||||
key: "accountId",
|
||||
title: "Enter your Cloudflare Account ID",
|
||||
placeholder: "e.g. 1234567890abcdef1234567890abcdef",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
forms,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user