-
Notifications
You must be signed in to change notification settings - Fork 49
feat: store and expose hostContext in App class #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
Fixes #129 - The App class now stores the initial hostContext received during initialization and exposes it via getHostContext(). Changes: - Add _hostContext private property to App class - Store result.hostContext in connect() method - Add getHostContext() getter method (parallel to getHostCapabilities()) - Update onhostcontextchanged setter to merge partial updates into stored context - Add default notification handler to update context even when user hasn't set onhostcontextchanged This enables apps to: - Access toolInfo immediately after connection (only in initial context) - Render with correct theme/locale without waiting for first notification - Synchronously access viewport, timezone, and other initial state 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
36aa8a8 to
1a95181
Compare
src/app-bridge.test.ts
Outdated
| it("getHostContext accumulates multiple partial updates", async () => { | ||
| // Need fresh transports for new bridge | ||
| const [newAppTransport, newBridgeTransport] = | ||
| InMemoryTransport.createLinkedPair(); | ||
|
|
||
| const initialContext = { | ||
| theme: "light" as const, | ||
| locale: "en-US", | ||
| viewport: { width: 800, height: 600 }, | ||
| }; | ||
| const newBridge = new AppBridge( | ||
| createMockClient() as Client, | ||
| testHostInfo, | ||
| testHostCapabilities, | ||
| { hostContext: initialContext }, | ||
| ); | ||
| const newApp = new App(testAppInfo, {}, { autoResize: false }); | ||
|
|
||
| await newBridge.connect(newBridgeTransport); | ||
| await newApp.connect(newAppTransport); | ||
|
|
||
| // Update only theme | ||
| newBridge.setHostContext({ ...initialContext, theme: "dark" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misunderstanding, but is this actually testing getHostContext accumulates multiple partial updates? Or should we omit ...initialContext here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops good catch, thanks, fixed
src/app-bridge.test.ts
Outdated
| // Update only theme | ||
| newBridge.setHostContext({ ...initialContext, theme: "dark" }); | ||
| await flush(); | ||
|
|
||
| // Update viewport | ||
| newBridge.setHostContext({ | ||
| theme: "dark", | ||
| locale: "en-US", | ||
| viewport: { width: 1024, height: 768 }, | ||
| }); | ||
| await flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two newBridge.setHostContext() calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to address intent:
// Send partial update: only theme changes
newBridge.sendHostContextChange({ theme: "dark" });
await flush();
// Send another partial update: only viewport changes
newBridge.sendHostContextChange({ viewport: { width: 1024, height: 768 } });
await flush();
// getHostContext should have accumulated all updates:
// - locale from initial (unchanged)
// - theme from first partial update
// - viewport from second partial update
const context = newApp.getHostContext();
expect(context?.theme).toBe("dark");
expect(context?.locale).toBe("en-US");
expect(context?.viewport).toEqual({ width: 1024, height: 768 });Address PR review feedback: The test was using setHostContext with full context spreads which didn't clearly demonstrate partial update accumulation. Now uses sendHostContextChange directly to send truly partial updates (only theme, then only viewport), making it clear the App correctly merges multiple partial notifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
Fixes #129 - The
Appclass now stores the initialhostContextreceived during initialization and exposes it viagetHostContext()._hostContextprivate property toAppclassresult.hostContextinconnect()methodgetHostContext()getter method (parallel togetHostCapabilities())onhostcontextchangedsetter to merge partial updates into stored contextonhostcontextchangedThis enables apps to:
toolInfoimmediately after connection (only available in initial context)Test plan
App receives initial hostContext after connectgetHostContext returns undefined before connectgetHostContext merges updates from onhostcontextchangedgetHostContext updates even without user setting onhostcontextchangedgetHostContext accumulates multiple partial updates🤖 Generated with Claude Code