Compare commits
7 commits
dev
...
brendan/ef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2f6135daf |
||
|
|
3c74c0db30 |
||
|
|
1fa55dcca7 |
||
|
|
ad0ff9b651 |
||
|
|
9ef9fac6db |
||
|
|
ef2faaac4c |
||
|
|
e74c99320f |
7 changed files with 1103 additions and 1074 deletions
|
|
@ -1161,13 +1161,17 @@ export namespace Config {
|
|||
}),
|
||||
)
|
||||
|
||||
export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Auth.Service | Account.Service> =
|
||||
Layer.effect(
|
||||
export const layer: Layer.Layer<
|
||||
Service,
|
||||
never,
|
||||
AppFileSystem.Service | Auth.Service | Account.Service | Env.Service
|
||||
> = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const authSvc = yield* Auth.Service
|
||||
const accountSvc = yield* Account.Service
|
||||
const env = yield* Env.Service
|
||||
|
||||
const readConfigFile = Effect.fnUntraced(function* (filepath: string) {
|
||||
return yield* fs.readFileString(filepath).pipe(
|
||||
|
|
@ -1187,10 +1191,7 @@ export namespace Config {
|
|||
const source = "path" in options ? options.path : options.source
|
||||
const isFile = "path" in options
|
||||
const data = yield* Effect.promise(() =>
|
||||
ConfigPaths.parseText(
|
||||
text,
|
||||
"path" in options ? options.path : { source: options.source, dir: options.dir },
|
||||
),
|
||||
ConfigPaths.parseText(text, "path" in options ? options.path : { source: options.source, dir: options.dir }),
|
||||
)
|
||||
|
||||
const normalized = (() => {
|
||||
|
|
@ -1358,11 +1359,7 @@ export namespace Config {
|
|||
return "global"
|
||||
})
|
||||
|
||||
const track = Effect.fnUntraced(function* (
|
||||
source: string,
|
||||
list: PluginSpec[] | undefined,
|
||||
kind?: PluginScope,
|
||||
) {
|
||||
const track = Effect.fnUntraced(function* (source: string, list: PluginSpec[] | undefined, kind?: PluginScope) {
|
||||
if (!list?.length) return
|
||||
const hit = kind ?? (yield* scope(source))
|
||||
const plugins = deduplicatePluginOrigins([
|
||||
|
|
@ -1482,7 +1479,7 @@ export namespace Config {
|
|||
)
|
||||
if (Option.isSome(tokenOpt)) {
|
||||
process.env["OPENCODE_CONSOLE_TOKEN"] = tokenOpt.value
|
||||
Env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
|
||||
yield* env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
|
||||
}
|
||||
|
||||
activeOrgName = activeOrg.org.name
|
||||
|
|
@ -1659,5 +1656,6 @@ export namespace Config {
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(Auth.defaultLayer),
|
||||
Layer.provide(Account.defaultLayer),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
60
packages/opencode/src/env/index.ts
vendored
60
packages/opencode/src/env/index.ts
vendored
|
|
@ -1,28 +1,54 @@
|
|||
import { Instance } from "../project/instance"
|
||||
import { InstanceState } from "@/effect/instance-state"
|
||||
import { makeRuntime } from "@/effect/run-service"
|
||||
import { Context, Effect, Layer } from "effect"
|
||||
|
||||
export namespace Env {
|
||||
const state = Instance.state(() => {
|
||||
type State = Record<string, string | undefined>
|
||||
|
||||
export interface Interface {
|
||||
readonly get: (key: string) => Effect.Effect<string | undefined>
|
||||
readonly all: () => Effect.Effect<State>
|
||||
readonly set: (key: string, value: string) => Effect.Effect<void>
|
||||
readonly remove: (key: string) => Effect.Effect<void>
|
||||
}
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/Env") {}
|
||||
|
||||
export const layer = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const state = yield* InstanceState.make<State>(
|
||||
Effect.fn("Env.state")(() =>
|
||||
Effect.succeed(
|
||||
// Create a shallow copy to isolate environment per instance
|
||||
// Prevents parallel tests from interfering with each other's env vars
|
||||
return { ...process.env } as Record<string, string | undefined>
|
||||
{ ...process.env } as State,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
const get = Effect.fn("Env.get")((key: string) => InstanceState.use(state, (env) => env[key]))
|
||||
|
||||
const all = Effect.fn("Env.all")(() => InstanceState.get(state))
|
||||
|
||||
const set = Effect.fn("Env.set")(function* (key: string, value: string) {
|
||||
const env = yield* InstanceState.get(state)
|
||||
env[key] = value
|
||||
})
|
||||
|
||||
export function get(key: string) {
|
||||
const env = state()
|
||||
return env[key]
|
||||
}
|
||||
const remove = Effect.fn("Env.remove")(function* (key: string) {
|
||||
const env = yield* InstanceState.get(state)
|
||||
delete env[key]
|
||||
})
|
||||
|
||||
export function all() {
|
||||
return state()
|
||||
}
|
||||
return Service.of({ get, all, set, remove })
|
||||
}),
|
||||
)
|
||||
|
||||
export const defaultLayer = layer
|
||||
const rt = makeRuntime(Service, layer)
|
||||
|
||||
export function set(key: string, value: string) {
|
||||
const env = state()
|
||||
env[key] = value
|
||||
}
|
||||
|
||||
export function remove(key: string) {
|
||||
const env = state()
|
||||
delete env[key]
|
||||
return rt.runSync((svc) => svc.set(key, value))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ export namespace Provider {
|
|||
})
|
||||
}
|
||||
|
||||
function e2eURL() {
|
||||
const url = Env.get("OPENCODE_E2E_LLM_URL")
|
||||
function e2eURL(env: Record<string, string | undefined>) {
|
||||
const url = env["OPENCODE_E2E_LLM_URL"]
|
||||
if (typeof url !== "string" || url === "") return
|
||||
return url
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ export namespace Provider {
|
|||
return sdk.responses === undefined && sdk.chat === undefined
|
||||
}
|
||||
|
||||
function custom(dep: CustomDep): Record<string, CustomLoader> {
|
||||
function custom(dep: CustomDep, env: Env.Interface): Record<string, CustomLoader> {
|
||||
return {
|
||||
anthropic: () =>
|
||||
Effect.succeed({
|
||||
|
|
@ -184,9 +184,9 @@ export namespace Provider {
|
|||
},
|
||||
}),
|
||||
opencode: Effect.fnUntraced(function* (input: Info) {
|
||||
const env = Env.all()
|
||||
const vals = yield* env.all()
|
||||
const hasKey = iife(() => {
|
||||
if (input.env.some((item) => env[item])) return true
|
||||
if (input.env.some((item) => vals[item])) return true
|
||||
return false
|
||||
})
|
||||
const ok =
|
||||
|
|
@ -231,14 +231,13 @@ export namespace Provider {
|
|||
},
|
||||
options: {},
|
||||
}),
|
||||
azure: (provider) => {
|
||||
const resource = iife(() => {
|
||||
const name = provider.options?.resourceName
|
||||
if (typeof name === "string" && name.trim() !== "") return name
|
||||
return Env.get("AZURE_RESOURCE_NAME")
|
||||
})
|
||||
azure: Effect.fnUntraced(function* (provider: Info) {
|
||||
const resource =
|
||||
typeof provider.options?.resourceName === "string" && provider.options.resourceName.trim() !== ""
|
||||
? provider.options.resourceName
|
||||
: yield* env.get("AZURE_RESOURCE_NAME")
|
||||
|
||||
return Effect.succeed({
|
||||
return {
|
||||
autoload: false,
|
||||
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
|
||||
if (useLanguageModel(sdk)) return sdk.languageModel(modelID)
|
||||
|
|
@ -254,11 +253,11 @@ export namespace Provider {
|
|||
...(resource && { AZURE_RESOURCE_NAME: resource }),
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
"azure-cognitive-services": () => {
|
||||
const resourceName = Env.get("AZURE_COGNITIVE_SERVICES_RESOURCE_NAME")
|
||||
return Effect.succeed({
|
||||
}
|
||||
}),
|
||||
"azure-cognitive-services": Effect.fnUntraced(function* () {
|
||||
const resource = yield* env.get("AZURE_COGNITIVE_SERVICES_RESOURCE_NAME")
|
||||
return {
|
||||
autoload: false,
|
||||
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
|
||||
if (useLanguageModel(sdk)) return sdk.languageModel(modelID)
|
||||
|
|
@ -269,25 +268,25 @@ export namespace Provider {
|
|||
}
|
||||
},
|
||||
options: {
|
||||
baseURL: resourceName ? `https://${resourceName}.cognitiveservices.azure.com/openai` : undefined,
|
||||
},
|
||||
})
|
||||
baseURL: resource ? `https://${resource}.cognitiveservices.azure.com/openai` : undefined,
|
||||
},
|
||||
}
|
||||
}),
|
||||
"amazon-bedrock": Effect.fnUntraced(function* () {
|
||||
const providerConfig = (yield* dep.config()).provider?.["amazon-bedrock"]
|
||||
const auth = yield* dep.auth("amazon-bedrock")
|
||||
|
||||
// Region precedence: 1) config file, 2) env var, 3) default
|
||||
const configRegion = providerConfig?.options?.region
|
||||
const envRegion = Env.get("AWS_REGION")
|
||||
const envRegion = yield* env.get("AWS_REGION")
|
||||
const defaultRegion = configRegion ?? envRegion ?? "us-east-1"
|
||||
|
||||
// Profile: config file takes precedence over env var
|
||||
const configProfile = providerConfig?.options?.profile
|
||||
const envProfile = Env.get("AWS_PROFILE")
|
||||
const envProfile = yield* env.get("AWS_PROFILE")
|
||||
const profile = configProfile ?? envProfile
|
||||
|
||||
const awsAccessKeyId = Env.get("AWS_ACCESS_KEY_ID")
|
||||
const awsAccessKeyId = yield* env.get("AWS_ACCESS_KEY_ID")
|
||||
|
||||
// TODO: Using process.env directly because Env.set only updates a process.env shallow copy,
|
||||
// until the scope of the Env API is clarified (test only or runtime?)
|
||||
|
|
@ -301,7 +300,7 @@ export namespace Provider {
|
|||
return undefined
|
||||
})
|
||||
|
||||
const awsWebIdentityTokenFile = Env.get("AWS_WEB_IDENTITY_TOKEN_FILE")
|
||||
const awsWebIdentityTokenFile = yield* env.get("AWS_WEB_IDENTITY_TOKEN_FILE")
|
||||
|
||||
const containerCreds = Boolean(
|
||||
process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI,
|
||||
|
|
@ -439,24 +438,24 @@ export namespace Provider {
|
|||
},
|
||||
},
|
||||
}),
|
||||
"google-vertex": (provider) => {
|
||||
"google-vertex": Effect.fnUntraced(function* (provider: Info) {
|
||||
const project =
|
||||
provider.options?.project ??
|
||||
Env.get("GOOGLE_CLOUD_PROJECT") ??
|
||||
Env.get("GCP_PROJECT") ??
|
||||
Env.get("GCLOUD_PROJECT")
|
||||
(yield* env.get("GOOGLE_CLOUD_PROJECT")) ??
|
||||
(yield* env.get("GCP_PROJECT")) ??
|
||||
(yield* env.get("GCLOUD_PROJECT"))
|
||||
|
||||
const location = String(
|
||||
provider.options?.location ??
|
||||
Env.get("GOOGLE_VERTEX_LOCATION") ??
|
||||
Env.get("GOOGLE_CLOUD_LOCATION") ??
|
||||
Env.get("VERTEX_LOCATION") ??
|
||||
(yield* env.get("GOOGLE_VERTEX_LOCATION")) ??
|
||||
(yield* env.get("GOOGLE_CLOUD_LOCATION")) ??
|
||||
(yield* env.get("VERTEX_LOCATION")) ??
|
||||
"us-central1",
|
||||
)
|
||||
|
||||
const autoload = Boolean(project)
|
||||
if (!autoload) return Effect.succeed({ autoload: false })
|
||||
return Effect.succeed({
|
||||
if (!autoload) return { autoload: false }
|
||||
return {
|
||||
autoload: true,
|
||||
vars(_options: Record<string, any>) {
|
||||
const endpoint =
|
||||
|
|
@ -485,14 +484,17 @@ export namespace Provider {
|
|||
const id = String(modelID).trim()
|
||||
return sdk.languageModel(id)
|
||||
},
|
||||
})
|
||||
},
|
||||
"google-vertex-anthropic": () => {
|
||||
const project = Env.get("GOOGLE_CLOUD_PROJECT") ?? Env.get("GCP_PROJECT") ?? Env.get("GCLOUD_PROJECT")
|
||||
const location = Env.get("GOOGLE_CLOUD_LOCATION") ?? Env.get("VERTEX_LOCATION") ?? "global"
|
||||
}
|
||||
}),
|
||||
"google-vertex-anthropic": Effect.fnUntraced(function* () {
|
||||
const project =
|
||||
(yield* env.get("GOOGLE_CLOUD_PROJECT")) ??
|
||||
(yield* env.get("GCP_PROJECT")) ??
|
||||
(yield* env.get("GCLOUD_PROJECT"))
|
||||
const location = (yield* env.get("GOOGLE_CLOUD_LOCATION")) ?? (yield* env.get("VERTEX_LOCATION")) ?? "global"
|
||||
const autoload = Boolean(project)
|
||||
if (!autoload) return Effect.succeed({ autoload: false })
|
||||
return Effect.succeed({
|
||||
if (!autoload) return { autoload: false }
|
||||
return {
|
||||
autoload: true,
|
||||
options: {
|
||||
project,
|
||||
|
|
@ -502,8 +504,8 @@ export namespace Provider {
|
|||
const id = String(modelID).trim()
|
||||
return sdk.languageModel(id)
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
}),
|
||||
"sap-ai-core": Effect.fnUntraced(function* () {
|
||||
const auth = yield* dep.auth("sap-ai-core")
|
||||
// TODO: Using process.env directly because Env.set only updates a shallow copy (not process.env),
|
||||
|
|
@ -539,14 +541,11 @@ export namespace Provider {
|
|||
},
|
||||
}),
|
||||
gitlab: Effect.fnUntraced(function* (input: Info) {
|
||||
const instanceUrl = Env.get("GITLAB_INSTANCE_URL") || "https://gitlab.com"
|
||||
const instanceUrl = (yield* env.get("GITLAB_INSTANCE_URL")) || "https://gitlab.com"
|
||||
|
||||
const auth = yield* dep.auth(input.id)
|
||||
const apiKey = yield* Effect.sync(() => {
|
||||
if (auth?.type === "oauth") return auth.access
|
||||
if (auth?.type === "api") return auth.key
|
||||
return Env.get("GITLAB_TOKEN")
|
||||
})
|
||||
const apiKey =
|
||||
auth?.type === "oauth" ? auth.access : auth?.type === "api" ? auth.key : yield* env.get("GITLAB_TOKEN")
|
||||
|
||||
const providerConfig = (yield* dep.config()).provider?.["gitlab"]
|
||||
|
||||
|
|
@ -682,7 +681,7 @@ export namespace Provider {
|
|||
|
||||
const auth = yield* dep.auth(input.id)
|
||||
const accountId =
|
||||
Env.get("CLOUDFLARE_ACCOUNT_ID") || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
||||
(yield* env.get("CLOUDFLARE_ACCOUNT_ID")) || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
||||
if (!accountId)
|
||||
return {
|
||||
autoload: false,
|
||||
|
|
@ -694,7 +693,7 @@ export namespace Provider {
|
|||
}
|
||||
|
||||
const apiKey = yield* Effect.gen(function* () {
|
||||
const envToken = Env.get("CLOUDFLARE_API_KEY")
|
||||
const envToken = yield* env.get("CLOUDFLARE_API_KEY")
|
||||
if (envToken) return envToken
|
||||
if (auth?.type === "api") return auth.key
|
||||
return undefined
|
||||
|
|
@ -724,9 +723,9 @@ export namespace Provider {
|
|||
|
||||
const auth = yield* dep.auth(input.id)
|
||||
const accountId =
|
||||
Env.get("CLOUDFLARE_ACCOUNT_ID") || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
||||
(yield* env.get("CLOUDFLARE_ACCOUNT_ID")) || (auth?.type === "api" ? auth.metadata?.accountId : undefined)
|
||||
const gateway =
|
||||
Env.get("CLOUDFLARE_GATEWAY_ID") || (auth?.type === "api" ? auth.metadata?.gatewayId : undefined)
|
||||
(yield* env.get("CLOUDFLARE_GATEWAY_ID")) || (auth?.type === "api" ? auth.metadata?.gatewayId : undefined)
|
||||
|
||||
if (!accountId || !gateway) {
|
||||
const missing = [
|
||||
|
|
@ -745,7 +744,7 @@ export namespace Provider {
|
|||
|
||||
// Get API token from env or auth - required for authenticated gateways
|
||||
const apiToken = yield* Effect.gen(function* () {
|
||||
const envToken = Env.get("CLOUDFLARE_API_TOKEN") || Env.get("CF_AIG_TOKEN")
|
||||
const envToken = (yield* env.get("CLOUDFLARE_API_TOKEN")) || (yield* env.get("CF_AIG_TOKEN"))
|
||||
if (envToken) return envToken
|
||||
if (auth?.type === "api") return auth.key
|
||||
return undefined
|
||||
|
|
@ -1030,14 +1029,18 @@ export namespace Provider {
|
|||
}
|
||||
}
|
||||
|
||||
const layer: Layer.Layer<Service, never, Config.Service | Auth.Service | Plugin.Service | AppFileSystem.Service> =
|
||||
Layer.effect(
|
||||
const layer: Layer.Layer<
|
||||
Service,
|
||||
never,
|
||||
Config.Service | Auth.Service | Plugin.Service | AppFileSystem.Service | Env.Service
|
||||
> = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* AppFileSystem.Service
|
||||
const config = yield* Config.Service
|
||||
const auth = yield* Auth.Service
|
||||
const plugin = yield* Plugin.Service
|
||||
const env = yield* Env.Service
|
||||
|
||||
const state = yield* InstanceState.make<State>(() =>
|
||||
Effect.gen(function* () {
|
||||
|
|
@ -1142,20 +1145,13 @@ export namespace Provider {
|
|||
pdf: model.modalities?.input?.includes("pdf") ?? existingModel?.capabilities.input.pdf ?? false,
|
||||
},
|
||||
output: {
|
||||
text:
|
||||
model.modalities?.output?.includes("text") ?? existingModel?.capabilities.output.text ?? true,
|
||||
text: model.modalities?.output?.includes("text") ?? existingModel?.capabilities.output.text ?? true,
|
||||
audio:
|
||||
model.modalities?.output?.includes("audio") ??
|
||||
existingModel?.capabilities.output.audio ??
|
||||
false,
|
||||
model.modalities?.output?.includes("audio") ?? existingModel?.capabilities.output.audio ?? false,
|
||||
image:
|
||||
model.modalities?.output?.includes("image") ??
|
||||
existingModel?.capabilities.output.image ??
|
||||
false,
|
||||
model.modalities?.output?.includes("image") ?? existingModel?.capabilities.output.image ?? false,
|
||||
video:
|
||||
model.modalities?.output?.includes("video") ??
|
||||
existingModel?.capabilities.output.video ??
|
||||
false,
|
||||
model.modalities?.output?.includes("video") ?? existingModel?.capabilities.output.video ?? false,
|
||||
pdf: model.modalities?.output?.includes("pdf") ?? existingModel?.capabilities.output.pdf ?? false,
|
||||
},
|
||||
interleaved: model.interleaved ?? false,
|
||||
|
|
@ -1190,11 +1186,11 @@ export namespace Provider {
|
|||
}
|
||||
|
||||
// load env
|
||||
const env = Env.all()
|
||||
const vals = yield* env.all()
|
||||
for (const [id, provider] of Object.entries(database)) {
|
||||
const providerID = ProviderID.make(id)
|
||||
if (disabled.has(providerID)) continue
|
||||
const apiKey = provider.env.map((item) => env[item]).find(Boolean)
|
||||
const apiKey = provider.env.map((item) => vals[item]).find(Boolean)
|
||||
if (!apiKey) continue
|
||||
mergeProvider(providerID, {
|
||||
source: "env",
|
||||
|
|
@ -1228,20 +1224,16 @@ export namespace Provider {
|
|||
const options = yield* Effect.promise(() =>
|
||||
plugin.auth!.loader!(
|
||||
() =>
|
||||
Effect.runPromise(
|
||||
auth.get(providerID).pipe(Effect.orDie, Effect.provide(EffectLogger.layer)),
|
||||
) as any,
|
||||
Effect.runPromise(auth.get(providerID).pipe(Effect.orDie, Effect.provide(EffectLogger.layer))) as any,
|
||||
database[plugin.auth!.provider],
|
||||
),
|
||||
)
|
||||
const opts = options ?? {}
|
||||
const patch: Partial<Info> = providers[providerID]
|
||||
? { options: opts }
|
||||
: { source: "custom", options: opts }
|
||||
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
|
||||
mergeProvider(providerID, patch)
|
||||
}
|
||||
|
||||
for (const [id, fn] of Object.entries(custom(dep))) {
|
||||
for (const [id, fn] of Object.entries(custom(dep, env))) {
|
||||
const providerID = ProviderID.make(id)
|
||||
if (disabled.has(providerID)) continue
|
||||
const data = database[providerID]
|
||||
|
|
@ -1331,8 +1323,7 @@ export namespace Provider {
|
|||
(providerID === ProviderID.openrouter && modelID === "openai/gpt-5-chat")
|
||||
)
|
||||
delete provider.models[modelID]
|
||||
if (model.status === "alpha" && !Flag.OPENCODE_ENABLE_EXPERIMENTAL_MODELS)
|
||||
delete provider.models[modelID]
|
||||
if (model.status === "alpha" && !Flag.OPENCODE_ENABLE_EXPERIMENTAL_MODELS) delete provider.models[modelID]
|
||||
if (model.status === "deprecated") delete provider.models[modelID]
|
||||
if (
|
||||
(configProvider?.blacklist && configProvider.blacklist.includes(modelID)) ||
|
||||
|
|
@ -1372,7 +1363,7 @@ export namespace Provider {
|
|||
|
||||
const list = Effect.fn("Provider.list")(() => InstanceState.use(state, (s) => s.providers))
|
||||
|
||||
async function resolveSDK(model: Model, s: State) {
|
||||
async function resolveSDK(model: Model, s: State, envs: Record<string, string | undefined>) {
|
||||
try {
|
||||
using _ = log.time("getSDK", {
|
||||
providerID: model.providerID,
|
||||
|
|
@ -1403,7 +1394,7 @@ export namespace Provider {
|
|||
}
|
||||
|
||||
url = url.replace(/\$\{([^}]+)\}/g, (item, key) => {
|
||||
const val = Env.get(String(key))
|
||||
const val = envs[String(key)]
|
||||
return val ?? item
|
||||
})
|
||||
return url
|
||||
|
|
@ -1443,8 +1434,7 @@ export namespace Provider {
|
|||
if (options["timeout"] !== undefined && options["timeout"] !== null && options["timeout"] !== false)
|
||||
signals.push(AbortSignal.timeout(options["timeout"]))
|
||||
|
||||
const combined =
|
||||
signals.length === 0 ? null : signals.length === 1 ? signals[0] : AbortSignal.any(signals)
|
||||
const combined = signals.length === 0 ? null : signals.length === 1 ? signals[0] : AbortSignal.any(signals)
|
||||
if (combined) opts.signal = combined
|
||||
|
||||
// Strip openai itemId metadata following what codex does
|
||||
|
|
@ -1536,9 +1526,10 @@ export namespace Provider {
|
|||
const s = yield* InstanceState.get(state)
|
||||
const key = `${model.providerID}/${model.id}`
|
||||
if (s.models.has(key)) return s.models.get(key)!
|
||||
const vals = yield* env.all()
|
||||
|
||||
return yield* Effect.promise(async () => {
|
||||
const url = e2eURL()
|
||||
const url = e2eURL(vals)
|
||||
if (url) {
|
||||
const language = createOpenAICompatible({
|
||||
name: model.providerID,
|
||||
|
|
@ -1550,7 +1541,7 @@ export namespace Provider {
|
|||
}
|
||||
|
||||
const provider = s.providers[model.providerID]
|
||||
const sdk = await resolveSDK(model, s)
|
||||
const sdk = await resolveSDK(model, s, vals)
|
||||
|
||||
try {
|
||||
const language = s.modelLoaders[model.providerID]
|
||||
|
|
@ -1688,6 +1679,7 @@ export namespace Provider {
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(Config.defaultLayer),
|
||||
Layer.provide(Auth.defaultLayer),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provide(Plugin.defaultLayer),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ export namespace ToolRegistry {
|
|||
| Ripgrep.Service
|
||||
| Format.Service
|
||||
| Truncate.Service
|
||||
| Env.Service
|
||||
> = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
|
|
@ -103,6 +104,7 @@ export namespace ToolRegistry {
|
|||
const agents = yield* Agent.Service
|
||||
const skill = yield* Skill.Service
|
||||
const truncate = yield* Truncate.Service
|
||||
const env = yield* Env.Service
|
||||
|
||||
const invalid = yield* InvalidTool
|
||||
const task = yield* TaskTool
|
||||
|
|
@ -272,13 +274,14 @@ export namespace ToolRegistry {
|
|||
})
|
||||
|
||||
const tools: Interface["tools"] = Effect.fn("ToolRegistry.tools")(function* (input) {
|
||||
const e2e = !!(yield* env.get("OPENCODE_E2E_LLM_URL"))
|
||||
const filtered = (yield* all()).filter((tool) => {
|
||||
if (tool.id === CodeSearchTool.id || tool.id === WebSearchTool.id) {
|
||||
return input.providerID === ProviderID.opencode || Flag.OPENCODE_ENABLE_EXA
|
||||
}
|
||||
|
||||
const usePatch =
|
||||
!!Env.get("OPENCODE_E2E_LLM_URL") ||
|
||||
e2e ||
|
||||
(input.modelID.includes("gpt-") && !input.modelID.includes("oss") && !input.modelID.includes("gpt-4"))
|
||||
if (tool.id === ApplyPatchTool.id) return usePatch
|
||||
if (tool.id === EditTool.id || tool.id === WriteTool.id) return !usePatch
|
||||
|
|
@ -342,6 +345,7 @@ export namespace ToolRegistry {
|
|||
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
||||
Layer.provide(Ripgrep.defaultLayer),
|
||||
Layer.provide(Truncate.defaultLayer),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { test, expect, describe, mock, afterEach, beforeEach, spyOn } from "bun:
|
|||
import { Deferred, Effect, Fiber, Layer, Option } from "effect"
|
||||
import { NodeFileSystem, NodePath } from "@effect/platform-node"
|
||||
import { Config } from "../../src/config/config"
|
||||
import { Env } from "../../src/env"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { Auth } from "../../src/auth"
|
||||
import { AccessToken, Account, AccountID, OrgID } from "../../src/account"
|
||||
|
|
@ -37,6 +38,7 @@ const layer = Config.layer.pipe(
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(emptyAuth),
|
||||
Layer.provide(emptyAccount),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provideMerge(infra),
|
||||
)
|
||||
|
||||
|
|
@ -334,6 +336,7 @@ test("resolves env templates in account config with account token", async () =>
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(emptyAuth),
|
||||
Layer.provide(fakeAccount),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provideMerge(infra),
|
||||
)
|
||||
|
||||
|
|
@ -1826,6 +1829,7 @@ test("project config overrides remote well-known config", async () => {
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(fakeAuth),
|
||||
Layer.provide(emptyAccount),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provideMerge(infra),
|
||||
)
|
||||
|
||||
|
|
@ -1881,6 +1885,7 @@ test("wellknown URL with trailing slash is normalized", async () => {
|
|||
Layer.provide(AppFileSystem.defaultLayer),
|
||||
Layer.provide(fakeAuth),
|
||||
Layer.provide(emptyAccount),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provideMerge(infra),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Agent as AgentSvc } from "../../src/agent/agent"
|
|||
import { Bus } from "../../src/bus"
|
||||
import { Command } from "../../src/command"
|
||||
import { Config } from "../../src/config/config"
|
||||
import { Env } from "../../src/env"
|
||||
import { FileTime } from "../../src/file/time"
|
||||
import { LSP } from "../../src/lsp"
|
||||
import { MCP } from "../../src/mcp"
|
||||
|
|
@ -183,6 +184,7 @@ function makeHttp() {
|
|||
const todo = Todo.layer.pipe(Layer.provideMerge(deps))
|
||||
const registry = ToolRegistry.layer.pipe(
|
||||
Layer.provide(Skill.defaultLayer),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provide(FetchHttpClient.layer),
|
||||
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
||||
Layer.provide(Ripgrep.defaultLayer),
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import { Agent as AgentSvc } from "../../src/agent/agent"
|
|||
import { Bus } from "../../src/bus"
|
||||
import { Command } from "../../src/command"
|
||||
import { Config } from "../../src/config/config"
|
||||
import { Env } from "../../src/env"
|
||||
import { FileTime } from "../../src/file/time"
|
||||
import { LSP } from "../../src/lsp"
|
||||
import { MCP } from "../../src/mcp"
|
||||
|
|
@ -137,6 +138,7 @@ function makeHttp() {
|
|||
const todo = Todo.layer.pipe(Layer.provideMerge(deps))
|
||||
const registry = ToolRegistry.layer.pipe(
|
||||
Layer.provide(Skill.defaultLayer),
|
||||
Layer.provide(Env.defaultLayer),
|
||||
Layer.provide(FetchHttpClient.layer),
|
||||
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
||||
Layer.provide(Ripgrep.defaultLayer),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue