-
Notifications
You must be signed in to change notification settings - Fork 1
feat(platform): serve Chat from a JS host as an optional capability #400
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
Open
filvecchiato
wants to merge
9
commits into
main
Choose a base branch
from
feat/chat-platform-js-host
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f42c11f
feat(platform): serve Chat from a JS host as an optional capability
filvecchiato cd0c683
Merge branch 'main' into feat/chat-platform-js-host
filvecchiato 7a2ea4c
Merge main into feat/chat-platform-js-host
filvecchiato 9ab4327
Merge remote-tracking branch 'origin/main' into feat/chat-platform-js…
filvecchiato 2b42f63
Merge branch 'main' into feat/chat-platform-js-host
filvecchiato b22b899
Merge remote-tracking branch 'origin/feat/chat-platform-js-host' into…
filvecchiato 1b097b5
Merge branch 'main' into feat/chat-platform-js-host
filvecchiato d408945
Merge branch 'main' into feat/chat-platform-js-host
filvecchiato 055f172
Merge branch 'main' into feat/chat-platform-js-host
filvecchiato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
|
|
||
| import { | ||
| createWorkerRawCallbacks, | ||
| startRawSubscription, | ||
| } from "./generated/worker-callbacks.js"; | ||
| import type { RawCallbacks } from "./generated/host-callbacks-adapter.js"; | ||
|
|
||
| // The worker proxies an optional capability only when the main thread reports | ||
| // the host serves it, so the core sees the same capability set on both sides of | ||
| // the boundary. Without that gate a worker host would always look chat-capable | ||
| // and the core would route chat calls at a host that cannot answer them. | ||
|
|
||
| function stubBridge() { | ||
| const requests: { name: string; args: readonly unknown[] }[] = []; | ||
| const subscriptions: { name: string; payload: Uint8Array | null }[] = []; | ||
| return { | ||
| requests, | ||
| subscriptions, | ||
| bridge: { | ||
| callbackRequest: async (name: string, args: readonly unknown[]) => { | ||
| requests.push({ name, args }); | ||
| return new Uint8Array(); | ||
| }, | ||
| startSubscription: (name: string, payload: Uint8Array | null) => { | ||
| subscriptions.push({ name, payload }); | ||
| return () => {}; | ||
| }, | ||
| chainConnect: async () => null, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe("worker raw callbacks", () => { | ||
| it("omits the chat proxies when no chat capability is reported", () => { | ||
| const { bridge } = stubBridge(); | ||
|
|
||
| const callbacks = createWorkerRawCallbacks( | ||
| bridge as unknown as Parameters<typeof createWorkerRawCallbacks>[0], | ||
| ); | ||
|
|
||
| expect(callbacks.createChatRoom).toBeUndefined(); | ||
| expect(callbacks.postChatMessage).toBeUndefined(); | ||
| expect(callbacks.subscribeChatRooms).toBeUndefined(); | ||
| expect(callbacks.subscribeTheme).toBeDefined(); | ||
| }); | ||
|
|
||
| it("proxies chat through the bridge when the capability is reported", async () => { | ||
| const { bridge, requests, subscriptions } = stubBridge(); | ||
|
|
||
| const callbacks = createWorkerRawCallbacks( | ||
| bridge as unknown as Parameters<typeof createWorkerRawCallbacks>[0], | ||
| { chat: true }, | ||
| ); | ||
|
|
||
| const product = new Uint8Array([1]); | ||
| await ( | ||
| callbacks.createChatRoom as ( | ||
| product: Uint8Array, | ||
| request: Uint8Array, | ||
| ) => Promise<unknown> | ||
| )(product, new Uint8Array([2])); | ||
| ( | ||
| callbacks.subscribeChatRooms as ( | ||
| product: Uint8Array, | ||
| sendItem: () => void, | ||
| sendError: () => void, | ||
| ) => void | ||
| )( | ||
| product, | ||
| () => {}, | ||
| () => {}, | ||
| ); | ||
|
|
||
| expect(requests.map((r) => r.name)).toContain("createChatRoom"); | ||
| expect(subscriptions).toEqual([ | ||
| { name: "subscribeChatRooms", payload: product }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("starts no chat room subscription when chat is absent", () => { | ||
| const { bridge, subscriptions } = stubBridge(); | ||
| const callbacks = createWorkerRawCallbacks( | ||
| bridge as unknown as Parameters<typeof createWorkerRawCallbacks>[0], | ||
| ) as RawCallbacks; | ||
|
|
||
| const stop = startRawSubscription( | ||
| callbacks, | ||
| "subscribeChatRooms", | ||
| new Uint8Array([1]), | ||
| () => {}, | ||
| () => {}, | ||
| ); | ||
|
|
||
| expect(stop).toBeUndefined(); | ||
| expect(subscriptions).toEqual([]); | ||
| }); | ||
| }); |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.