From 24398b1b28bff16a465ca2384a1277c306520325 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 20 May 2026 14:19:33 -0400 Subject: [PATCH] fix(sdk): unbreak typecheck on dev after v2 error widening MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two problems surfaced when #28495 + the follow-up `chore: generate` populated previously-empty v2 error response unions. 1. `@hey-api/openapi-ts` codegen passes the endpoint's `TError` into the second generic of `ServerSentEventsResult`, which is the underlying `AsyncGenerator`'s `TReturn` slot — not an error channel. The SSE implementation's own signature uses `ServerSentEventsResult`, so it's only the public `SseFn` wrapper that's wrong. Latent for ~9 months; harmless while error unions were unknown, but breaks every `.return(undefined)` call and every mock async generator the moment an SSE endpoint declares a concrete error response. Patch the generated `client/types.gen.ts` and add a post-gen step in `script/build.ts` so every future `chore: generate` reapplies it. 2. `experimental.workspace.warp` now returns `InvalidRequestError` in its 400 union, which uses `_tag` rather than `name` as its discriminator. Narrow the error before reading `.name` in `dialog-workspace-create.tsx`. Verified end-to-end: `bun run build` in `packages/sdk/js` wipes and regenerates v2/gen, then re-applies the SseFn patch automatically; full monorepo typecheck and stream.transport tests are green. --- .../tui/component/dialog-workspace-create.tsx | 2 +- packages/sdk/js/script/build.ts | 18 ++++++++++++++++++ packages/sdk/js/src/v2/gen/client/types.gen.ts | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/dialog-workspace-create.tsx b/packages/opencode/src/cli/cmd/tui/component/dialog-workspace-create.tsx index 538428e8f187..b22930bc6c1a 100644 --- a/packages/opencode/src/cli/cmd/tui/component/dialog-workspace-create.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/dialog-workspace-create.tsx @@ -108,7 +108,7 @@ export async function warpWorkspaceSession(input: { }) .catch(() => undefined) if (!result?.data) { - if (result?.error?.name === "VcsApplyError") { + if (result?.error && "name" in result.error && result.error.name === "VcsApplyError") { await DialogAlert.show( input.dialog, "Unable to Warp Session", diff --git a/packages/sdk/js/script/build.ts b/packages/sdk/js/script/build.ts index b3f74a1bf695..72f4e3f3e993 100755 --- a/packages/sdk/js/script/build.ts +++ b/packages/sdk/js/script/build.ts @@ -40,6 +40,24 @@ await createClient({ ], }) +// Patch a @hey-api/openapi-ts codegen bug: SseFn incorrectly passes the +// endpoint's TError into the second generic of ServerSentEventsResult, which +// is the AsyncGenerator's TReturn slot. Iterator return values have nothing +// to do with HTTP errors, and any consumer that calls `.return()` or returns +// from a mock generator gets type-checked against the wrong shape. Drop the +// arg so TReturn defaults to void. +const sseTypesPath = "./src/v2/gen/client/types.gen.ts" +const sseTypesFile = Bun.file(sseTypesPath) +const sseTypesSource = await sseTypesFile.text() +const sseTypesPatched = sseTypesSource.replace( + "=> Promise>", + "=> Promise>", +) +if (sseTypesPatched === sseTypesSource) { + throw new Error(`SseFn patch did not apply; @hey-api/openapi-ts output may have changed (${sseTypesPath})`) +} +await Bun.write(sseTypesPath, sseTypesPatched) + await $`bun prettier --write src/gen` await $`bun prettier --write src/v2` await $`rm -rf dist` diff --git a/packages/sdk/js/src/v2/gen/client/types.gen.ts b/packages/sdk/js/src/v2/gen/client/types.gen.ts index e053aa40662c..99d7e7f8f2e8 100644 --- a/packages/sdk/js/src/v2/gen/client/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/client/types.gen.ts @@ -144,7 +144,7 @@ type SseFn = < TResponseStyle extends ResponseStyle = "fields", >( options: Omit, "method">, -) => Promise> +) => Promise> type RequestFn = < TData = unknown,