refactor(flags): route installation client through runtime flags (#27369)

This commit is contained in:
Shoubhit Dash
2026-05-14 00:10:31 +05:30
committed by GitHub
parent a4ebb07c25
commit 52f9bcbb82
3 changed files with 20 additions and 6 deletions

View File

@@ -5,7 +5,6 @@ import { ChildProcess } from "effect/unstable/process"
import { AppProcess } from "@opencode-ai/core/process"
import path from "path"
import { BusEvent } from "@/bus/bus-event"
import { Flag } from "@opencode-ai/core/flag/flag"
import * as Log from "@opencode-ai/core/util/log"
import { makeRuntime } from "@opencode-ai/core/effect/runtime"
import semver from "semver"
@@ -50,7 +49,11 @@ export const Info = Schema.Struct({
}).annotate({ identifier: "InstallationInfo" })
export type Info = Schema.Schema.Type<typeof Info>
export const USER_AGENT = `opencode/${InstallationChannel}/${InstallationVersion}/${Flag.OPENCODE_CLIENT}`
export function userAgent(client = "cli") {
return `opencode/${InstallationChannel}/${InstallationVersion}/${client}`
}
export const USER_AGENT = userAgent()
export function isPreview() {
return InstallationChannel !== "latest"

View File

@@ -9,6 +9,7 @@ import { Hash } from "@opencode-ai/core/util/hash"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { withTransientReadRetry } from "@/util/effect-http-client"
import { CatalogModelStatus } from "./model-status"
import { RuntimeFlags } from "@/effect/runtime-flags"
const CostTier = Schema.Struct({
input: Schema.Finite,
@@ -109,11 +110,14 @@ export interface Interface {
export class Service extends Context.Service<Service, Interface>()("@opencode/ModelsDev") {}
export const layer: Layer.Layer<Service, never, AppFileSystem.Service | HttpClient.HttpClient> = Layer.effect(
type Requirements = AppFileSystem.Service | HttpClient.HttpClient | RuntimeFlags.Service
export const layer: Layer.Layer<Service, never, Requirements> = Layer.effect(
Service,
Effect.gen(function* () {
const fs = yield* AppFileSystem.Service
const http = HttpClient.filterStatusOk(withTransientReadRetry(yield* HttpClient.HttpClient))
const flags = yield* RuntimeFlags.Service
const source = Flag.OPENCODE_MODELS_URL || "https://models.dev"
const filepath = path.join(
@@ -132,7 +136,7 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | HttpClie
const fetchApi = Effect.fn("ModelsDev.fetchApi")(function* () {
return yield* HttpClientRequest.get(`${source}/api.json`).pipe(
HttpClientRequest.setHeader("User-Agent", Installation.USER_AGENT),
HttpClientRequest.setHeader("User-Agent", Installation.userAgent(flags.client)),
http.execute,
Effect.flatMap((res) => res.text),
Effect.timeout("10 seconds"),
@@ -208,6 +212,7 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | HttpClie
export const defaultLayer: Layer.Layer<Service> = layer.pipe(
Layer.provide(FetchHttpClient.layer),
Layer.provide(AppFileSystem.defaultLayer),
Layer.provide(RuntimeFlags.defaultLayer),
)
export * as ModelsDev from "./models"