Skip to content

Commit 636a4bb

Browse files
Merge remote-tracking branch 'origin/main' into pr-124303-prep
2 parents 08195f5 + 0a4e81e commit 636a4bb

120 files changed

Lines changed: 4261 additions & 1328 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17893,24 +17893,28 @@ public struct ExecApprovalsSnapshot: Codable, Sendable {
1789317893
public let exists: Bool
1789417894
public let hash: String
1789517895
public let file: [String: AnyCodable]
17896+
public let resolveddefaults: [String: AnyCodable]?
1789617897

1789717898
public init(
1789817899
path: String,
1789917900
exists: Bool,
1790017901
hash: String,
17901-
file: [String: AnyCodable])
17902+
file: [String: AnyCodable],
17903+
resolveddefaults: [String: AnyCodable]? = nil)
1790217904
{
1790317905
self.path = path
1790417906
self.exists = exists
1790517907
self.hash = hash
1790617908
self.file = file
17909+
self.resolveddefaults = resolveddefaults
1790717910
}
1790817911

1790917912
private enum CodingKeys: String, CodingKey {
1791017913
case path
1791117914
case exists
1791217915
case hash
1791317916
case file
17917+
case resolveddefaults = "resolvedDefaults"
1791417918
}
1791517919
}
1791617920

‎docs/cli/tui.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Aliases: `openclaw chat` and `openclaw terminal` invoke this command with
6969
- With no URL/host target or explicit `--url`, `tui` resolves configured Gateway
7070
auth SecretRefs for token/password auth when possible (`env`/`file`/`exec`/`store`
7171
providers).
72+
- When the configured remote Gateway is behind an identity-aware proxy, `tui`
73+
resolves `gateway.remote.edgeAuth` SecretInputs and sends those headers only
74+
to that configured Gateway scope. URL or host targets for other origins never
75+
inherit them.
7276
- With no explicit URL or port, `tui` follows the active local Gateway port
7377
recorded by the running Gateway. Explicit `--url`, `OPENCLAW_GATEWAY_URL`,
7478
`OPENCLAW_GATEWAY_PORT`, and remote Gateway config keep precedence.
@@ -94,6 +98,7 @@ Aliases: `openclaw chat` and `openclaw terminal` invoke this command with
9498
| The Gateway predates short-link resolution | Copy the full session key from that Gateway's Control UI. |
9599
| Session missing or short ref ambiguous | For the configured/local Gateway, run `openclaw sessions list`; for a URL/host target, choose a longer or full key in that Gateway's Control UI. |
96100
| Gateway unreachable | The error names the selected origin. For a `*.ts.net` host, connect Tailscale and confirm the Gateway is reachable on the tailnet. |
101+
| Identity-aware proxy rejected the upgrade | Configure `gateway.remote.edgeAuth` for the configured remote Gateway; the error includes the relevant remote-access docs link. |
97102
| Stored device token revoked or rotated | Rotate it with `openclaw devices rotate --device <deviceId> --role operator`, then reconnect. |
98103
| TLS certificate pin mismatch | The original TLS fingerprint error passes through unchanged; verify the configured or explicit pin before retrying. |
99104

‎docs/gateway/remote.md‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,87 @@ For a Gateway already reachable on a trusted LAN or Tailnet, use direct mode:
9191
}
9292
```
9393

94+
## Gateway behind an identity-aware proxy
95+
96+
Use `gateway.remote.edgeAuth` when an identity-aware proxy must authenticate the
97+
WebSocket upgrade before traffic reaches the Gateway. Header values are
98+
`SecretInput` fields, so they can come from `env`, `file`, `exec`, or `store`
99+
secret providers without placing credentials directly in the config.
100+
101+
For Cloudflare Access, a generic exec secret provider can obtain a short-lived
102+
application token from an operator-installed `cloudflared` binary:
103+
104+
```json5
105+
{
106+
secrets: {
107+
providers: {
108+
"cloudflare-access": {
109+
source: "exec",
110+
command: "/usr/local/bin/cloudflared",
111+
args: ["access", "token", "-app=https://gateway.example"],
112+
jsonOnly: false,
113+
trustedDirs: ["/usr/local/bin"],
114+
},
115+
},
116+
},
117+
gateway: {
118+
mode: "remote",
119+
remote: {
120+
url: "wss://gateway.example",
121+
edgeAuth: {
122+
"Cf-Access-Token": {
123+
source: "exec",
124+
provider: "cloudflare-access",
125+
id: "token",
126+
},
127+
},
128+
},
129+
},
130+
}
131+
```
132+
133+
`secrets.providers.*.command` must be an absolute path; replace
134+
`/usr/local/bin/cloudflared` with the real, non-symlink install location on your
135+
host, such as the resolved executable under a Homebrew prefix.
136+
137+
For a Cloudflare Access service token, provide the two fixed headers from any
138+
supported secret provider. This example reads them from environment-backed
139+
SecretRefs:
140+
141+
```json5
142+
{
143+
secrets: {
144+
providers: {
145+
default: { source: "env" },
146+
},
147+
},
148+
gateway: {
149+
mode: "remote",
150+
remote: {
151+
url: "wss://gateway.example",
152+
edgeAuth: {
153+
"CF-Access-Client-Id": {
154+
source: "env",
155+
provider: "default",
156+
id: "CF_ACCESS_CLIENT_ID",
157+
},
158+
"CF-Access-Client-Secret": {
159+
source: "env",
160+
provider: "default",
161+
id: "CF_ACCESS_CLIENT_SECRET",
162+
},
163+
},
164+
},
165+
},
166+
}
167+
```
168+
169+
OpenClaw's Gateway connection code never runs `cloudflared` itself and has no
170+
Cloudflare dependency or login flow. Only the generic exec secret provider
171+
invokes the exact command an operator configures. Resolved edge-auth headers are
172+
sent only when the target matches the configured `gateway.remote.url` scope,
173+
only over `wss://`, and never across redirects.
174+
94175
## Credential precedence
95176

96177
Gateway credential resolution follows one shared contract across call/probe/status paths and Discord exec-approval monitoring. Node-host uses the same contract with one local-mode exception (it ignores `gateway.remote.*`).

‎extensions/elevenlabs/speech-provider.test.ts‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ function parseRequestBody(init: RequestInit | undefined): Record<string, unknown
3535
return body as Record<string, unknown>;
3636
}
3737

38+
const OUTPUT_FORMAT_CASES = [
39+
{ outputFormat: "pcm_44100", fileExtension: ".pcm", voiceCompatible: false },
40+
{ outputFormat: "OPUS_48000_64", fileExtension: ".opus", voiceCompatible: true },
41+
{ outputFormat: "mp3_44100_128", fileExtension: ".mp3", voiceCompatible: false },
42+
{ outputFormat: "ulaw_8000", fileExtension: ".ulaw", voiceCompatible: false },
43+
{ outputFormat: "alaw_8000", fileExtension: ".alaw", voiceCompatible: false },
44+
{ outputFormat: "wav_44100", fileExtension: ".wav", voiceCompatible: false },
45+
{ outputFormat: "future_123", fileExtension: ".bin", voiceCompatible: false },
46+
] as const;
47+
3848
describe("elevenlabs speech provider", () => {
3949
const originalFetch = globalThis.fetch;
4050

@@ -311,4 +321,77 @@ describe("elevenlabs speech provider", () => {
311321

312322
expect(fetchMock).toHaveBeenCalledTimes(1);
313323
});
324+
325+
it.each(OUTPUT_FORMAT_CASES)(
326+
"returns truthful $outputFormat metadata for a voice-note override",
327+
async ({ outputFormat, fileExtension, voiceCompatible }) => {
328+
const fetchMock = vi.fn(async (url: string) => {
329+
expect(new URL(url).searchParams.get("output_format")).toBe(outputFormat);
330+
return new Response(new Uint8Array([1, 2, 3]), {
331+
headers: { "content-type": "audio/mpeg" },
332+
});
333+
});
334+
globalThis.fetch = fetchMock as unknown as typeof fetch;
335+
336+
const result = await buildElevenLabsSpeechProvider().synthesize({
337+
text: "hello",
338+
target: "voice-note",
339+
cfg: {} as never,
340+
providerConfig: { apiKey: "xi-test" },
341+
providerOverrides: { outputFormat },
342+
timeoutMs: 1_000,
343+
});
344+
345+
expect(result).toEqual({
346+
audioBuffer: Buffer.from([1, 2, 3]),
347+
outputFormat,
348+
fileExtension,
349+
voiceCompatible,
350+
});
351+
expect(fetchMock).toHaveBeenCalledTimes(1);
352+
},
353+
);
354+
355+
it("returns truthful stream metadata for an output override and releases the stream once", async () => {
356+
const cancel = vi.fn();
357+
const fetchMock = vi.fn(async (url: string) => {
358+
expect(new URL(url).searchParams.get("output_format")).toBe("pcm_44100");
359+
return new Response(
360+
new ReadableStream<Uint8Array>({
361+
start(controller) {
362+
controller.enqueue(new Uint8Array([1, 2, 3]));
363+
},
364+
cancel,
365+
}),
366+
{ headers: { "content-type": "audio/mpeg" } },
367+
);
368+
});
369+
globalThis.fetch = fetchMock as unknown as typeof fetch;
370+
371+
const result = await buildElevenLabsSpeechProvider().streamSynthesize?.({
372+
text: "hello",
373+
target: "voice-note",
374+
cfg: {} as never,
375+
providerConfig: { apiKey: "xi-test" },
376+
providerOverrides: { outputFormat: "pcm_44100" },
377+
timeoutMs: 1_000,
378+
});
379+
if (!result) {
380+
throw new Error("streamSynthesize is unavailable");
381+
}
382+
383+
expect(result).toMatchObject({
384+
outputFormat: "pcm_44100",
385+
fileExtension: ".pcm",
386+
voiceCompatible: false,
387+
});
388+
if (!result.release) {
389+
throw new Error("stream release is unavailable");
390+
}
391+
expect(cancel).not.toHaveBeenCalled();
392+
await result.release();
393+
await result.release();
394+
expect(cancel).toHaveBeenCalledTimes(1);
395+
expect(fetchMock).toHaveBeenCalledTimes(1);
396+
});
314397
});

‎extensions/elevenlabs/speech-provider.ts‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ function normalizeElevenLabsLatencyTier(value: unknown): number | undefined {
109109
: undefined;
110110
}
111111

112+
const ELEVENLABS_OUTPUT_FAMILIES = new Set(["opus", "mp3", "pcm", "ulaw", "alaw", "wav"]);
113+
114+
function resolveElevenLabsOutputPlan(req: SpeechSynthesisRequest): {
115+
outputFormat: string;
116+
fileExtension: string;
117+
voiceCompatible: boolean;
118+
} {
119+
const outputFormat =
120+
trimToUndefined(req.providerOverrides?.outputFormat) ??
121+
(req.target === "voice-note" ? "opus_48000_64" : "mp3_44100_128");
122+
const family = outputFormat.trim().toLowerCase().split("_", 1)[0];
123+
return {
124+
outputFormat,
125+
fileExtension: family && ELEVENLABS_OUTPUT_FAMILIES.has(family) ? `.${family}` : ".bin",
126+
voiceCompatible: family === "opus",
127+
};
128+
}
129+
112130
function normalizeVoiceSettings(
113131
rawVoiceSettings: Record<string, unknown> | undefined,
114132
): Partial<ElevenLabsProviderConfig["voiceSettings"]> {
@@ -549,38 +567,30 @@ export function buildElevenLabsSpeechProvider(): SpeechProviderPlugin {
549567
Boolean(resolveElevenLabsApiKey(readElevenLabsProviderConfig(providerConfig).apiKey)),
550568
synthesize: async (req) => {
551569
const overrides = req.providerOverrides ?? {};
552-
const outputFormat =
553-
trimToUndefined(overrides.outputFormat) ??
554-
(req.target === "voice-note" ? "opus_48000_64" : "mp3_44100_128");
570+
const outputPlan = resolveElevenLabsOutputPlan(req);
555571
const audioBuffer = await elevenLabsTTS(
556572
resolveElevenLabsTtsRequest(req, {
557-
outputFormat,
573+
outputFormat: outputPlan.outputFormat,
558574
latencyTier: normalizeElevenLabsLatencyTier(overrides.latencyTier),
559575
}),
560576
);
561577
return {
562578
audioBuffer,
563-
outputFormat,
564-
fileExtension: req.target === "voice-note" ? ".opus" : ".mp3",
565-
voiceCompatible: req.target === "voice-note",
579+
...outputPlan,
566580
};
567581
},
568582
streamSynthesize: async (req) => {
569583
const overrides = req.providerOverrides ?? {};
570-
const outputFormat =
571-
trimToUndefined(overrides.outputFormat) ??
572-
(req.target === "voice-note" ? "opus_48000_64" : "mp3_44100_128");
584+
const outputPlan = resolveElevenLabsOutputPlan(req);
573585
const stream = await elevenLabsTTSStream(
574586
resolveElevenLabsTtsRequest(req, {
575-
outputFormat,
587+
outputFormat: outputPlan.outputFormat,
576588
latencyTier: normalizeElevenLabsLatencyTier(overrides.latencyTier),
577589
}),
578590
);
579591
return {
580592
audioStream: stream.audioStream,
581-
outputFormat,
582-
fileExtension: req.target === "voice-note" ? ".opus" : ".mp3",
583-
voiceCompatible: req.target === "voice-note",
593+
...outputPlan,
584594
release: stream.release,
585595
};
586596
},

‎extensions/tts-local-cli/speech-provider-stream-error.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ import { buildCliSpeechProvider } from "./speech-provider.js";
1717

1818
const TEST_CFG = {} as OpenClawConfig;
1919
const MIB = 1024 * 1024;
20+
const WAV_AUDIO = Buffer.concat([Buffer.from("RIFF"), Buffer.alloc(4), Buffer.from("WAVEaudio")]);
2021

2122
function commandResult(overrides: Record<string, unknown> = {}) {
2223
return {
2324
code: 0,
2425
signal: null,
2526
killed: false,
2627
termination: "exit",
27-
stdout: Buffer.from("audio"),
28+
stdout: WAV_AUDIO,
2829
stderr: Buffer.alloc(0),
2930
...overrides,
3031
};
@@ -53,7 +54,7 @@ describe("CLI TTS process wrapper", () => {
5354
});
5455

5556
it("uses Execa input, timeout, escalation, and asymmetric byte caps", async () => {
56-
await expect(synthesize()).resolves.toMatchObject({ audioBuffer: Buffer.from("audio") });
57+
await expect(synthesize()).resolves.toMatchObject({ audioBuffer: WAV_AUDIO });
5758

5859
expect(runCommandBufferedMock).toHaveBeenCalledWith(
5960
["/fake/tts", "--voice", "test"],
@@ -103,7 +104,7 @@ describe("CLI TTS process wrapper", () => {
103104
await expect(synthesize()).rejects.toThrow("CLI TTS failed: stdout stream failed");
104105

105106
runCommandBufferedMock.mockImplementationOnce(async (argv: string[]) => {
106-
writeFileSync(argv[1]!, Buffer.from("file-audio"));
107+
writeFileSync(argv[1]!, WAV_AUDIO);
107108
return commandResult({
108109
code: 0,
109110
error: streamError,
@@ -112,20 +113,20 @@ describe("CLI TTS process wrapper", () => {
112113
});
113114
});
114115
await expect(synthesize(["{{OutputPath}}"])).resolves.toMatchObject({
115-
audioBuffer: Buffer.from("file-audio"),
116+
audioBuffer: WAV_AUDIO,
116117
});
117118

118119
runCommandBufferedMock.mockResolvedValueOnce(
119120
commandResult({
120121
code: 0,
121122
error: new Error("stderr stream failed"),
122123
errorStream: "stderr",
123-
stdout: Buffer.from("stdout-audio"),
124+
stdout: WAV_AUDIO,
124125
termination: "error",
125126
}),
126127
);
127128
await expect(synthesize()).resolves.toMatchObject({
128-
audioBuffer: Buffer.from("stdout-audio"),
129+
audioBuffer: WAV_AUDIO,
129130
});
130131
});
131132
});

0 commit comments

Comments
 (0)