Skip to content

Commit 41367fa

Browse files
committed
refactor: use Schema.Finite instead of Schema.Number for OpenAPI-facing schemas
Schema.Number emits anyOf:[number, string enum(Infinity/-Infinity/NaN)] in OpenAPI because JS numbers include non-finite values. Schema.Finite adds an isFinite check so the OpenAPI output is just {type:"number"}, eliminating the need for post-hoc normalization in public.ts.
1 parent 97caa6b commit 41367fa

19 files changed

Lines changed: 99 additions & 99 deletions

File tree

packages/opencode/src/agent/agent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export const Info = Schema.Struct({
3131
mode: Schema.Literals(["subagent", "primary", "all"]),
3232
native: Schema.optional(Schema.Boolean),
3333
hidden: Schema.optional(Schema.Boolean),
34-
topP: Schema.optional(Schema.Number),
35-
temperature: Schema.optional(Schema.Number),
34+
topP: Schema.optional(Schema.Finite),
35+
temperature: Schema.optional(Schema.Finite),
3636
color: Schema.optional(Schema.String),
3737
permission: Permission.Ruleset,
3838
model: Schema.optional(
@@ -44,7 +44,7 @@ export const Info = Schema.Struct({
4444
variant: Schema.optional(Schema.String),
4545
prompt: Schema.optional(Schema.String),
4646
options: Schema.Record(Schema.String, Schema.Unknown),
47-
steps: Schema.optional(Schema.Number),
47+
steps: Schema.optional(Schema.Finite),
4848
})
4949
.annotate({ identifier: "Agent" })
5050
.pipe(withStatics((s) => ({ zod: zod(s) })))

packages/opencode/src/auth/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Oauth extends Schema.Class<Oauth>("OAuth")({
1414
type: Schema.Literal("oauth"),
1515
refresh: Schema.String,
1616
access: Schema.String,
17-
expires: Schema.Number,
17+
expires: Schema.Finite,
1818
accountId: Schema.optional(Schema.String),
1919
enterpriseUrl: Schema.optional(Schema.String),
2020
}) {}

packages/opencode/src/cli/cmd/tui/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const TuiEvent = {
3838
title: Schema.optional(Schema.String),
3939
message: Schema.String,
4040
variant: Schema.Literals(["info", "success", "warning", "error"]),
41-
duration: Schema.Number.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_TOAST_DURATION))).annotate({
41+
duration: Schema.Finite.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_TOAST_DURATION))).annotate({
4242
description: "Duration in milliseconds",
4343
}),
4444
}),

packages/opencode/src/config/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const AgentSchema = Schema.StructWithRest(
2626
variant: Schema.optional(Schema.String).annotate({
2727
description: "Default model variant for this agent (applies only when using the agent's configured model).",
2828
}),
29-
temperature: Schema.optional(Schema.Number),
30-
top_p: Schema.optional(Schema.Number),
29+
temperature: Schema.optional(Schema.Finite),
30+
top_p: Schema.optional(Schema.Finite),
3131
prompt: Schema.optional(Schema.String),
3232
tools: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)).annotate({
3333
description: "@deprecated Use 'permission' field instead",

packages/opencode/src/config/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Local = Schema.Struct({
1313
enabled: Schema.optional(Schema.Boolean).annotate({
1414
description: "Enable or disable the MCP server on startup",
1515
}),
16-
timeout: Schema.optional(Schema.Number).annotate({
16+
timeout: Schema.optional(Schema.Finite).annotate({
1717
description: "Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified.",
1818
}),
1919
})
@@ -49,7 +49,7 @@ export const Remote = Schema.Struct({
4949
oauth: Schema.optional(Schema.Union([OAuth, Schema.Literal(false)])).annotate({
5050
description: "OAuth authentication configuration for the MCP server. Set to false to disable OAuth auto-detection.",
5151
}),
52-
timeout: Schema.optional(Schema.Number).annotate({
52+
timeout: Schema.optional(Schema.Finite).annotate({
5353
description: "Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified.",
5454
}),
5555
})

packages/opencode/src/lsp/lsp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const Event = {
2323
}
2424

2525
const Position = Schema.Struct({
26-
line: Schema.Number,
27-
character: Schema.Number,
26+
line: Schema.Finite,
27+
character: Schema.Finite,
2828
})
2929

3030
export const Range = Schema.Struct({

packages/opencode/src/project/project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ const ProjectCommands = Schema.Struct({
3535
})
3636

3737
const ProjectTime = Schema.Struct({
38-
created: Schema.Number,
39-
updated: Schema.Number,
40-
initialized: Schema.optional(Schema.Number),
38+
created: Schema.Finite,
39+
updated: Schema.Finite,
40+
initialized: Schema.optional(Schema.Finite),
4141
})
4242

4343
export const Info = Schema.Struct({

packages/opencode/src/project/vcs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export type Info = Schema.Schema.Type<typeof Info>
125125
export const FileDiff = Schema.Struct({
126126
file: Schema.String,
127127
patch: Schema.String,
128-
additions: Schema.Number,
129-
deletions: Schema.Number,
128+
additions: Schema.Finite,
129+
deletions: Schema.Finite,
130130
status: Schema.optional(Schema.Literals(["added", "deleted", "modified"])),
131131
})
132132
.annotate({ identifier: "VcsFileDiff" })

packages/opencode/src/provider/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ export class Authorization extends Schema.Class<Authorization>("ProviderAuthAuth
5858
}
5959

6060
export const AuthorizeInput = Schema.Struct({
61-
method: Schema.Number.annotate({ description: "Auth method index" }),
61+
method: Schema.Finite.annotate({ description: "Auth method index" }),
6262
inputs: Schema.optional(Schema.Record(Schema.String, Schema.String)).annotate({ description: "Prompt inputs" }),
6363
}).pipe(withStatics((s) => ({ zod: zod(s) })))
6464
export type AuthorizeInput = Schema.Schema.Type<typeof AuthorizeInput>
6565

6666
export const CallbackInput = Schema.Struct({
67-
method: Schema.Number.annotate({ description: "Auth method index" }),
67+
method: Schema.Finite.annotate({ description: "Auth method index" }),
6868
code: Schema.optional(Schema.String).annotate({ description: "OAuth authorization code" }),
6969
}).pipe(withStatics((s) => ({ zod: zod(s) })))
7070
export type CallbackInput = Schema.Schema.Type<typeof CallbackInput>

packages/opencode/src/provider/models.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ const filepath = path.join(
2222
const ttl = 5 * 60 * 1000
2323

2424
const Cost = Schema.Struct({
25-
input: Schema.Number,
26-
output: Schema.Number,
27-
cache_read: Schema.optional(Schema.Number),
28-
cache_write: Schema.optional(Schema.Number),
25+
input: Schema.Finite,
26+
output: Schema.Finite,
27+
cache_read: Schema.optional(Schema.Finite),
28+
cache_write: Schema.optional(Schema.Finite),
2929
context_over_200k: Schema.optional(
3030
Schema.Struct({
31-
input: Schema.Number,
32-
output: Schema.Number,
33-
cache_read: Schema.optional(Schema.Number),
34-
cache_write: Schema.optional(Schema.Number),
31+
input: Schema.Finite,
32+
output: Schema.Finite,
33+
cache_read: Schema.optional(Schema.Finite),
34+
cache_write: Schema.optional(Schema.Finite),
3535
}),
3636
),
3737
})
@@ -55,9 +55,9 @@ export const Model = Schema.Struct({
5555
),
5656
cost: Schema.optional(Cost),
5757
limit: Schema.Struct({
58-
context: Schema.Number,
59-
input: Schema.optional(Schema.Number),
60-
output: Schema.Number,
58+
context: Schema.Finite,
59+
input: Schema.optional(Schema.Finite),
60+
output: Schema.Finite,
6161
}),
6262
modalities: Schema.optional(
6363
Schema.Struct({

0 commit comments

Comments
 (0)