fix: await async assemblyApi() factory with lazy init pattern#1130
fix: await async assemblyApi() factory with lazy init pattern#1130foleyatwork merged 2 commits intofeature/client-associationfrom
Conversation
The @assembly-js/node-sdk assemblyApi() factory is async and returns a Promise<AssemblyAPI>, but was being assigned synchronously in the constructor. This caused all SDK method calls to operate on a Promise object instead of the resolved client. Uses lazy init (store the promise, await in each method) to fix this with zero changes to external call sites. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@rrojan @arpandhakal My apologies, I was so focused on the token logic I completely forgot about this other necessary change to make |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where the assemblyApi() async factory function from @assembly-js/node-sdk was being assigned synchronously, causing all SDK method calls to operate on an unresolved Promise instead of the actual client. The fix implements a lazy initialization pattern that maintains the existing synchronous constructor interface while properly handling async initialization.
Changes:
- Implemented lazy initialization pattern: store the Promise in the constructor, await it in each method
- Renamed internal variable from
this.copilottoassemblyto reflect the company rebrand - Updated comment on line 79 to reference "assembly request token" instead of "copilot request token"
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| yarn.lock | Added lockfile entry for copilot-node-sdk package dependency resolution |
| src/utils/CopilotAPI.ts | Implemented lazy initialization pattern for async factory and renamed internal references from copilot to assembly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use ReturnType<typeof assemblyApi> instead of explicit Promise<SDK> so the type stays correct regardless of whether the SDK exports a sync or async factory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
@assembly-js/node-sdkassemblyApi()factory isasyncand returnsPromise<AssemblyAPI>, but was being assigned synchronously in theCopilotAPIconstructor — causing all SDK method calls to operate on a Promise object instead of the resolved client.awaitit in each method. Zero changes to external call sites (new CopilotAPI(token)still works as before).this.copilotreferences toassemblyto reflect the company rename.Test plan
🤖 Generated with Claude Code