-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(cli): add experimental voice gateway #8429
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
85ec008
feat(cli): add experimental voice gateway
jyaunches 19db569
test(cli): keep voice gateway tests linear
jyaunches b84e049
test(voice-gateway): keep listener fake linear
jyaunches f1df57c
merge: sync voice gateway branch with main
jyaunches 8c5759b
chore(architecture): reconcile voice command fan-in budget
jyaunches 402cdd2
fix(voice-gateway): guard premature request close
jyaunches c71a4fa
fix(voice-gateway): reject BSD credential symlinks
jyaunches 5cb4bb0
test(voice-gateway): make WebSocket fake linear
jyaunches 6f5b73a
test(voice-gateway): assert active turn revocation
jyaunches 79b1425
fix(voice-gateway): centralize turn transport cleanup
jyaunches 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { Flags } from "@oclif/core"; | ||
|
|
||
| import { | ||
| assertVoiceGatewayEnabled, | ||
| runVoiceGatewayServe, | ||
| } from "../../../lib/actions/voice-gateway/serve"; | ||
| import { DEFAULT_VOICE_GATEWAY_LISTEN_PORT } from "../../../lib/voice-gateway/contracts"; | ||
| import { NemoClawCommand } from "../../../lib/cli/nemoclaw-oclif-command"; | ||
|
|
||
| export default class InternalVoiceGatewayServeCommand extends NemoClawCommand { | ||
| static hidden = true; | ||
| static strict = true; | ||
| static summary = "Internal: serve the experimental voice gateway"; | ||
| static description = | ||
| "Serve one authenticated runtime session through a private loopback HTTP and NDJSON adapter."; | ||
| static usage = [ | ||
| "internal voice-gateway serve --deployment-credential-file <path> --openclaw-credential-file <path> --gateway-url <url> --runtime-identity <id> --runtime-profile <id> --sandbox <name> --agent <id> [--listen-port <port>]", | ||
| ]; | ||
| static flags = { | ||
| "deployment-credential-file": Flags.string({ | ||
| description: "Absolute path to the owner-only deployment bearer file", | ||
| required: true, | ||
| }), | ||
| "openclaw-credential-file": Flags.string({ | ||
| description: "Absolute path to the owner-only OpenClaw credential file", | ||
| required: true, | ||
| }), | ||
| "gateway-url": Flags.string({ | ||
| description: "Fixed loopback OpenClaw WebSocket URL", | ||
| required: true, | ||
| }), | ||
| "runtime-identity": Flags.string({ | ||
| description: "Trusted local runtime deployment identity", | ||
| required: true, | ||
| }), | ||
| "runtime-profile": Flags.string({ | ||
| description: "Operator-selected runtime profile", | ||
| required: true, | ||
| }), | ||
| sandbox: Flags.string({ | ||
| description: "Operator-selected sandbox", | ||
| required: true, | ||
| }), | ||
| agent: Flags.string({ | ||
| description: "Operator-selected OpenClaw agent", | ||
| required: true, | ||
| }), | ||
| "listen-port": Flags.integer({ | ||
| default: DEFAULT_VOICE_GATEWAY_LISTEN_PORT, | ||
| description: "Loopback port for the private runtime adapter", | ||
| min: 1024, | ||
| max: 65_535, | ||
| }), | ||
| }; | ||
|
|
||
| public async run(): Promise<void> { | ||
| assertVoiceGatewayEnabled(); | ||
| const { flags } = await this.parse(InternalVoiceGatewayServeCommand); | ||
| await runVoiceGatewayServe({ | ||
| deploymentCredentialFile: flags["deployment-credential-file"], | ||
| openClawCredentialFile: flags["openclaw-credential-file"], | ||
| gatewayUrl: flags["gateway-url"], | ||
| runtimeIdentity: flags["runtime-identity"], | ||
| runtimeProfile: flags["runtime-profile"], | ||
| sandbox: flags.sandbox, | ||
| agent: flags.agent, | ||
| listenPort: flags["listen-port"], | ||
| }); | ||
| } | ||
| } |
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,131 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { EventEmitter } from "node:events"; | ||
| import type { Server } from "node:http"; | ||
|
|
||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { | ||
| assertVoiceGatewayEnabled, | ||
| runVoiceGatewayServe, | ||
| validateOpenClawGatewayUrl, | ||
| } from "./serve"; | ||
|
|
||
| const OPTIONS = { | ||
| deploymentCredentialFile: "/run/voice/deployment", | ||
| openClawCredentialFile: "/run/voice/openclaw", | ||
| gatewayUrl: "ws://127.0.0.1:18789/ws", | ||
| runtimeIdentity: "voiceclaw-local", | ||
| runtimeProfile: "voiceclaw-pinned", | ||
| sandbox: "demo-sandbox", | ||
| agent: "main", | ||
| }; | ||
|
|
||
| describe("experimental voice gateway service gate", () => { | ||
| it.each([undefined, "", "0", "true", "01"])("rejects feature value %s", (value) => { | ||
| expect(() => | ||
| assertVoiceGatewayEnabled({ | ||
| NEMOCLAW_EXPERIMENTAL_VOICE_GATEWAY: value, | ||
| }), | ||
| ).toThrow("disabled"); | ||
| }); | ||
|
|
||
| it("checks the exact feature gate before reading either credential (#8378)", async () => { | ||
| const readBearerFile = vi.fn(); | ||
| const createServer = vi.fn(); | ||
|
|
||
| await expect( | ||
| runVoiceGatewayServe(OPTIONS, { | ||
| env: { | ||
| NEMOCLAW_EXPERIMENTAL_OTHER_CAPABILITY: "1", | ||
| NEMOCLAW_EXPERIMENTAL_VOICE_GATEWAY: "0", | ||
| }, | ||
| readBearerFile, | ||
| createServer, | ||
| }), | ||
| ).rejects.toThrow("disabled"); | ||
| expect(readBearerFile).not.toHaveBeenCalled(); | ||
| expect(createServer).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("voice gateway destination validation", () => { | ||
| it("accepts only a fixed credential-free loopback WebSocket URL", () => { | ||
| expect(validateOpenClawGatewayUrl("ws://127.0.0.1:18789/ws")).toBe("ws://127.0.0.1:18789/ws"); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "wss://127.0.0.1:18789/ws", | ||
| "ws://localhost:18789/ws", | ||
| "ws://10.0.0.2:18789/ws", | ||
| "ws://user:secret@127.0.0.1:18789/ws", | ||
| "ws://127.0.0.1:18789/other", | ||
| "ws://127.0.0.1:18789/ws?target=other", | ||
| "ws://127.0.0.1/ws", | ||
| ])("rejects untrusted or ambiguous destination %s (#8378)", (value) => { | ||
| expect(() => validateOpenClawGatewayUrl(value)).toThrow("must be"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("voice gateway listener lifetime", () => { | ||
| it("binds loopback, logs only trusted labels, and closes on SIGTERM (#8378)", async () => { | ||
| class FakeServer extends EventEmitter { | ||
| listening = false; | ||
| listenArgs: unknown[] = []; | ||
|
|
||
| listen(...args: unknown[]): this { | ||
| this.listenArgs = args.slice(0, 2); | ||
| this.listening = true; | ||
| const callback = args.at(-1) as () => void; | ||
| callback(); | ||
| return this; | ||
| } | ||
|
|
||
| close(callback?: (error?: Error) => void): this { | ||
| this.listening = false; | ||
| callback?.(); | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| const server = new FakeServer(); | ||
| const processEvents = new EventEmitter(); | ||
| const log = vi.fn(); | ||
| const readBearerFile = vi | ||
| .fn() | ||
| .mockReturnValueOnce("deployment-secret") | ||
| .mockReturnValueOnce("openclaw-secret"); | ||
| const createServer = vi.fn(() => server as unknown as Server); | ||
|
|
||
| const running = runVoiceGatewayServe(OPTIONS, { | ||
| env: { NEMOCLAW_EXPERIMENTAL_VOICE_GATEWAY: "1" }, | ||
| readBearerFile, | ||
| createServer, | ||
| processEvents, | ||
| log, | ||
| }); | ||
| await vi.waitFor(() => expect(log).toHaveBeenCalledTimes(1)); | ||
|
|
||
| expect(server.listenArgs).toEqual([18800, "127.0.0.1"]); | ||
| expect(createServer).toHaveBeenCalledWith({ | ||
| deploymentCredential: "deployment-secret", | ||
| service: expect.anything(), | ||
| }); | ||
| expect(log).toHaveBeenCalledWith({ | ||
| event: "voice_gateway", | ||
| state: "listening", | ||
| runtimeIdentity: "voiceclaw-local", | ||
| runtimeProfile: "voiceclaw-pinned", | ||
| sandbox: "demo-sandbox", | ||
| agent: "main", | ||
| }); | ||
|
|
||
| processEvents.emit("SIGTERM"); | ||
| await running; | ||
|
|
||
| expect(server.listening).toBe(false); | ||
| expect(log).toHaveBeenLastCalledWith(expect.objectContaining({ state: "stopped" })); | ||
| expect(JSON.stringify(log.mock.calls)).not.toContain("secret"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.