Skip to content

fix(httpapi-codegen): emit flat Promise input field types - #58875

Merged
rekram1-node merged 1 commit into
devfrom
flat-query-types
Oct 26, 2026
Merged

rekram1-node merged 1 commit into
devfrom
flat-query-types

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Promise client generator typed each input field by indexing into its whole source struct, so every params, query, headers and payload field came out nested. Dev already has 372 of these in packages/client/src/promise/generated/types.ts:

-export type AgentGetInput = {
-  readonly agentID: { readonly agentID: string }["agentID"]
-  readonly location?: { readonly location?: { readonly directory?: string | undefined } | undefined }["location"]
-}
+export type AgentGetInput = {
+  readonly agentID: string
+  readonly location?: { readonly directory?: string | undefined } | undefined
+}

Structs with several fields repeated the whole struct once per field, which is why the file shrinks by about 2,500 lines.

Change

I render each field from its own property schema instead of (Struct)["field"]. Indexing an optional property adds undefined, so for optional fields whose schema leaves it out (for example optionalKey) I add | undefined to keep the type the same:

-  readonly id?: { readonly id?: string | null; ... }["id"]
+  readonly id?: string | null | undefined

The types only get flatter. I checked that all 134 generated *Input types are mutually assignable with the old ones. The Effect client already used this flat form, so its output does not change.

I added a generator test with an optional ArrayEnsure query field, like the one in #58864. Once that PR is rebased on this, its EventSubscribeInput comes out flat too.

Out of scope

Unwrapped outputs such as { data: SessionInfo }["data"] still use indexed access. That is a separate code path.


Added by the opencode bot (AI-generated).

Public API: flattens the generated Promise client *Input field types in @opencode/client; the shapes are the same, so it is backwards compatible

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks correct. I ran the new generator test against the base code and it fails, printing the nested ({ … })["field"] form; with this PR it passes. Re-running bun run generate in packages/client reproduces the committed types.ts exactly, and no nested input field types are left (the 33 remaining indexed types are the unwrapped outputs you mention as out of scope). The httpapi-codegen and client tests pass, and tsc is clean for httpapi-codegen, client and sdk.

Public API: the generated *Input types in @opencode/client are written in a flat form instead of (Struct)["field"]. They describe the same shapes, so this is backwards compatible and existing callers don't need to change.

No concerns.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This push is a rebase with the generated client rebuilt; the generator change and its test are unchanged. On the new base, bun run generate in packages/client reproduces the committed types.ts exactly, and no nested input field types are left (the base has 378). The httpapi-codegen and client tests pass, and tsc is clean for httpapi-codegen, client and sdk.

Public API: same as before. The generated *Input types in @opencode/client are written flat and describe the same shapes, so existing callers don't need to change.

No concerns.

@rekram1-node
rekram1-node merged commit ed74ec8 into dev Oct 26, 2026
19 checks passed
@rekram1-node
rekram1-node deleted the flat-query-types branch October 26, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant