fix(bb-agent): widen UseChatOptions.api sendMessage/resume return types to Promise<unknown> - #515
Open
sharonyajain wants to merge 1 commit into
Open
fix(bb-agent): widen UseChatOptions.api sendMessage/resume return types to Promise<unknown>#515sharonyajain wants to merge 1 commit into
sharonyajain wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 12d197c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…es to Promise<unknown>
useChat awaits and discards the results of api.sendMessage and api.resume,
but the members were typed Promise<void>, which rejects the natural backend
shapes (agent.stream() -> { channelId }, resume wrappers -> { ok: true }) with
TS2322 and forces customers into an await-and-discard wrapper. Promise<unknown>
is assignable-from both object results and void, so existing void-returning
backends keep compiling while natural-shape backends now wire up directly.
Also updates the README backend example to return the natural { channelId }
shape, since the clean frontend wiring now compiles.
sharonyajain
force-pushed
the
fix/usechat-api-return-types-promise-unknown
branch
from
September 8, 2026 14:04
9755e1f to
12d197c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
useChat'sUseChatOptions.apitypessendMessageandresumeasPromise<void>, but the natural backend methods return objects —agent.stream()resolves to{ channelId }and theresumewrappers to{ ok: true }.Promise<{ channelId }>is not assignable toPromise<void>(TS2322:'{ channelId: string; }' is not assignable to 'void'), so a customer with a natural backend is forced into an await-and-discard wrapper:useChatawaits both calls purely for completion and discards the resolved value (index.hooks.ts—await options.api.sendMessage(...)andawait options.api.resume(...)), so the strictPromise<void>is unnecessarily narrow and buys nothing.The README backend example currently dodges this by having
sendMessagereturnvoid(it awaitsagent.stream()without returning{ channelId }) — the very workaround this change removes. The comprehensive test-app'sagentStreamreturns{ channelId }andagentResumereturns{ ok: true }, the natural shapes that hit the friction.Issue #, if available:
no linked issue: reported via bug bash, no issue was filed.
Changes
packages/bb-agent/src/index.hooks.ts: widenUseChatOptions.api.sendMessageandresume?return types fromPromise<void>toPromise<unknown>.unknownis assignable-from both{ ... }results andvoid, and since the hook discards the value this only widens what callers may return — no runtime behavior change, and existingvoid-returning backends keep compiling (backward compatible).packages/bb-agent/README.md: simplify the backendsendMessageexample toreturn { channelId }, showing the natural, more useful shape now that the clean frontend wiring compiles.The public
ChatInstance.sendMessage/respondToInterruptstayPromise<void>— those genuinely surface no value to the UI consumer. The change is scoped to the boundary where customer backends plug in.Validation
TS2322(Promise<{ channelId: string; }>not assignable toPromise<void>) and thatPromise<unknown>accepts both a natural{ channelId }/{ ok }backend and an existingvoidbackend, confirming the fix works and is backward compatible.index.hooks.tsin isolation (it only imports./types.js) — clean.API.mdis generated by API Extractor fromdist/index.aws.d.ts(the CDK/server entry point);UseChatOptionslives in the client entry pointindex.hooks.tsand does not appear inAPI.md, so no regeneration is needed.Manual verification
N/A — type-only change plus a doc example; unit-level type assertions cover the behavior.
Checklist