Add audius.comms() host function to QuickJS sandbox#27
Add audius.comms() host function to QuickJS sandbox#27glassBead-tc wants to merge 1 commit intomainfrom
Conversation
Expose commsRequest bridge in the sandbox so LLM-generated code can call Audius comms/messaging endpoints via audius.comms(method, path, options). Extracts shared bridgeHostFn helper to eliminate duplication between request and comms host functions. Adds commsRequest stub to AudiusClient interface (real implementation comes from Unit 2A). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR adds an Key changes:
The refactor is structurally sound: the Confidence Score: 5/5Safe to merge; all remaining findings are P2 style/documentation suggestions with no blocking correctness issues. The code change is a clean refactor (extracting No files require special attention; Important Files Changed
Sequence DiagramsequenceDiagram
participant VM as QuickJS VM (user code)
participant Bridge as bridgeHostFn (Sandbox.ts)
participant Effect as Effect.runPromise
participant Client as AudiusClient
VM->>Bridge: audius.request(method, path, opts)
Bridge->>Bridge: ctx.newPromise() → deferred
Bridge->>Effect: runPromise(audiusClient.request(...))
Effect->>Client: request(method, path, opts)
Client-->>Effect: JSON response
Effect-->>Bridge: resolve(JSON.stringify(result))
Bridge->>Bridge: deferred.resolve(strHandle)
Bridge->>VM: executePendingJobs()
VM-->>VM: .then(JSON.parse) → parsed result
VM->>Bridge: audius.comms(method, path, opts)
Bridge->>Bridge: ctx.newPromise() → deferred
Bridge->>Effect: runPromise(audiusClient.commsRequest(...))
Effect->>Client: commsRequest (stub → Effect.fail)
Client-->>Effect: Error("Comms not implemented")
Effect-->>Bridge: reject handler fires
Bridge->>Bridge: deferred.resolve({error: "Comms not implemented"})
Bridge->>VM: executePendingJobs()
VM-->>VM: .then(JSON.parse) → {error: "..."}
|
| const commsRequest = (_method: string, _path: string, _options?: RequestOptions): Effect.Effect<unknown, Error> => | ||
| Effect.fail(new Error("Comms not implemented - see Unit 2A")) |
There was a problem hiding this comment.
Reminder: Unit 2A implementation will need SSRF path validation
The request function guards against SSRF on line 49–51 (path.startsWith("/") and !path.includes("@")). When Unit 2A replaces this stub with a real implementation targeting a different base URL (e.g. comms endpoint), it should include equivalent path validation to maintain the same security boundary.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/api/AudiusClient.ts
Line: 102-103
Comment:
**Reminder: Unit 2A implementation will need SSRF path validation**
The `request` function guards against SSRF on line 49–51 (`path.startsWith("/")` and `!path.includes("@")`). When Unit 2A replaces this stub with a real implementation targeting a different base URL (e.g. comms endpoint), it should include equivalent path validation to maintain the same security boundary.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df91a36de4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const commsRequest = (_method: string, _path: string, _options?: RequestOptions): Effect.Effect<unknown, Error> => | ||
| Effect.fail(new Error("Comms not implemented - see Unit 2A")) |
There was a problem hiding this comment.
Implement commsRequest or keep comms host disabled
This commit exposes audius.comms(...) in the sandbox, but commsRequest is hardcoded to fail for every invocation, so any comms call will never hit a real endpoint and always returns the placeholder error path. In production, this makes the newly added host function non-functional until a follow-up change lands; shipping the API surface before the implementation will break any workflow that starts using audius.comms.
Useful? React with 👍 / 👎.
Summary
audius.comms(method, path, options)host function to the QuickJS WASM sandbox, bridging toaudiusClient.commsRequest()for comms/messaging endpointsbridgeHostFnhelper to eliminate duplication betweenrequestandcommshost functionscommsRequestto theAudiusClientinterface with a stub implementation (real implementation comes from Unit 2A)Test plan
pnpm build)pnpm testpassescommsRequestimplementation)🤖 Generated with Claude Code