fix(httpapi): omit absent optional response fields (#25214)

This commit is contained in:
Kit Langton
2026-04-30 22:38:32 -04:00
committed by GitHub
parent 4c70ea28d2
commit 3c24d22d42
4 changed files with 118 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ import { Auth } from "@/auth"
import { InstanceState } from "@/effect/instance-state"
import { zod } from "@/util/effect-zod"
import { namedSchemaError } from "@/util/named-schema-error"
import { withStatics } from "@/util/schema"
import { optionalOmitUndefined, withStatics } from "@/util/schema"
import { Plugin } from "../plugin"
import { ProviderID } from "./schema"
import { Array as Arr, Effect, Layer, Record, Result, Context, Schema } from "effect"
@@ -18,14 +18,14 @@ const TextPrompt = Schema.Struct({
type: Schema.Literal("text"),
key: Schema.String,
message: Schema.String,
placeholder: Schema.optional(Schema.String),
when: Schema.optional(When),
placeholder: optionalOmitUndefined(Schema.String),
when: optionalOmitUndefined(When),
})
const SelectOption = Schema.Struct({
label: Schema.String,
value: Schema.String,
hint: Schema.optional(Schema.String),
hint: optionalOmitUndefined(Schema.String),
})
const SelectPrompt = Schema.Struct({
@@ -33,7 +33,7 @@ const SelectPrompt = Schema.Struct({
key: Schema.String,
message: Schema.String,
options: Schema.Array(SelectOption),
when: Schema.optional(When),
when: optionalOmitUndefined(When),
})
const Prompt = Schema.Union([TextPrompt, SelectPrompt])
@@ -41,7 +41,7 @@ const Prompt = Schema.Union([TextPrompt, SelectPrompt])
export class Method extends Schema.Class<Method>("ProviderAuthMethod")({
type: Schema.Literals(["oauth", "api"]),
label: Schema.String,
prompts: Schema.optional(Schema.Array(Prompt)),
prompts: optionalOmitUndefined(Schema.Array(Prompt)),
}) {
static readonly zod = zod(this)
}
@@ -135,23 +135,25 @@ export const layer: Layer.Layer<Service, never, Auth.Service | Plugin.Service> =
item.methods.map((method) => ({
type: method.type,
label: method.label,
prompts: method.prompts?.map((prompt) => {
if (prompt.type === "select") {
...(method.prompts && {
prompts: method.prompts.map((prompt) => {
if (prompt.type === "select") {
return {
type: "select" as const,
key: prompt.key,
message: prompt.message,
options: prompt.options,
...(prompt.when && { when: prompt.when }),
}
}
return {
type: "select" as const,
type: "text" as const,
key: prompt.key,
message: prompt.message,
options: prompt.options,
when: prompt.when,
...(prompt.placeholder && { placeholder: prompt.placeholder }),
...(prompt.when && { when: prompt.when }),
}
}
return {
type: "text" as const,
key: prompt.key,
message: prompt.message,
placeholder: prompt.placeholder,
when: prompt.when,
}
}),
}),
})),
),

View File

@@ -24,7 +24,7 @@ import { EffectBridge } from "@/effect/bridge"
import { InstanceState } from "@/effect/instance-state"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { isRecord } from "@/util/record"
import { withStatics } from "@/util/schema"
import { optionalOmitUndefined, withStatics } from "@/util/schema"
import * as ProviderTransform from "./transform"
import { ModelID, ProviderID } from "./schema"
@@ -875,7 +875,7 @@ const ProviderCost = Schema.Struct({
input: Schema.Finite,
output: Schema.Finite,
cache: ProviderCacheCost,
experimentalOver200K: Schema.optional(
experimentalOver200K: optionalOmitUndefined(
Schema.Struct({
input: Schema.Finite,
output: Schema.Finite,
@@ -886,7 +886,7 @@ const ProviderCost = Schema.Struct({
const ProviderLimit = Schema.Struct({
context: Schema.Finite,
input: Schema.optional(Schema.Finite),
input: optionalOmitUndefined(Schema.Finite),
output: Schema.Finite,
})
@@ -895,7 +895,7 @@ export const Model = Schema.Struct({
providerID: ProviderID,
api: ProviderApiInfo,
name: Schema.String,
family: Schema.optional(Schema.String),
family: optionalOmitUndefined(Schema.String),
capabilities: ProviderCapabilities,
cost: ProviderCost,
limit: ProviderLimit,
@@ -903,7 +903,7 @@ export const Model = Schema.Struct({
options: Schema.Record(Schema.String, Schema.Any),
headers: Schema.Record(Schema.String, Schema.String),
release_date: Schema.String,
variants: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Any))),
variants: optionalOmitUndefined(Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Any))),
})
.annotate({ identifier: "Model" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
@@ -914,7 +914,7 @@ export const Info = Schema.Struct({
name: Schema.String,
source: Schema.Literals(["env", "config", "custom", "api"]),
env: Schema.Array(Schema.String),
key: Schema.optional(Schema.String),
key: optionalOmitUndefined(Schema.String),
options: Schema.Record(Schema.String, Schema.Any),
models: Schema.Record(Schema.String, Model),
})