Skip to content

Commit 3643a0b

Browse files
committed
fix(voice-call): expose Twilio's configured streaming path
Keep realtime routes under the public webhook prefix they advertise, while mounting streaming.streamPath exactly as Twilio emits it. This preserves the canonical public-to-local route list without expanding the provider API outside the scoped repair.
1 parent 33ad5e0 commit 3643a0b

4 files changed

Lines changed: 61 additions & 51 deletions

File tree

‎extensions/voice-call/src/cli.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ describe("voice-call CLI status fallback", () => {
209209
localUrl: "http://127.0.0.1:4444/voice/stream/realtime",
210210
},
211211
{
212-
path: "/edge/voice/stream",
212+
path: "/voice/stream",
213213
localUrl: "http://127.0.0.1:4444/voice/stream",
214214
},
215215
],
216216
});
217217
expect(JSON.parse(capturer.output())).toMatchObject({
218218
localUrl: "http://127.0.0.1:4444/custom/webhook",
219-
streamPaths: ["/edge/voice/stream/realtime", "/edge/voice/stream"],
219+
streamPaths: ["/edge/voice/stream/realtime", "/voice/stream"],
220220
});
221221
});
222222

‎extensions/voice-call/src/config.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ describe("resolveVoiceCallStreamExposurePaths", () => {
886886
localPath: "/voice/stream/realtime",
887887
publicPath: "/edge/voice/stream/realtime",
888888
},
889-
{ localPath: "/voice/stream", publicPath: "/edge/voice/stream" },
889+
{ localPath: "/voice/stream", publicPath: "/voice/stream" },
890890
]);
891891
});
892892
});

‎extensions/voice-call/src/config.ts‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -548,32 +548,37 @@ export function resolveVoiceCallPublicPathPrefix(
548548
publicWebhookPath: string,
549549
localWebhookPath: string,
550550
): string {
551-
const normalizedPublicPath = normalizeWebhookPath(publicWebhookPath);
552-
const normalizedLocalPath = normalizeWebhookPath(localWebhookPath);
553-
const localPathIndex = normalizedPublicPath.indexOf(normalizedLocalPath);
554-
return localPathIndex > 0 ? normalizedPublicPath.slice(0, localPathIndex) : "";
551+
const publicPath = normalizeWebhookPath(publicWebhookPath);
552+
const localPathIndex = publicPath.indexOf(normalizeWebhookPath(localWebhookPath));
553+
return localPathIndex > 0 ? publicPath.slice(0, localPathIndex) : "";
555554
}
556555

557556
export function resolveVoiceCallStreamExposurePaths(
558557
config: VoiceCallConfig,
559558
webhookPaths: { publicWebhookPath?: string; localWebhookPath?: string } = {},
560559
): VoiceCallStreamExposurePath[] {
561-
const streamPaths: string[] = [];
560+
const exposurePaths: VoiceCallStreamExposurePath[] = [];
561+
const localWebhookPath = webhookPaths.localWebhookPath ?? config.serve.path;
562+
const publicWebhookPath = webhookPaths.publicWebhookPath ?? config.tailscale.path;
563+
const publicPathPrefix = resolveVoiceCallPublicPathPrefix(publicWebhookPath, localWebhookPath);
562564
if (config.realtime.enabled) {
563-
streamPaths.push(
565+
const localPath = normalizeWebhookPath(
564566
config.realtime.streamPath ?? defaultRealtimeStreamPathForServePath(config.serve.path),
565567
);
568+
exposurePaths.push({
569+
localPath,
570+
publicPath: `${publicPathPrefix}${localPath}`,
571+
});
566572
}
567573
if (config.streaming.enabled) {
568-
streamPaths.push(config.streaming.streamPath);
574+
const localPath = normalizeWebhookPath(config.streaming.streamPath);
575+
if (
576+
!exposurePaths.some((path) => path.localPath === localPath && path.publicPath === localPath)
577+
) {
578+
exposurePaths.push({ localPath, publicPath: localPath });
579+
}
569580
}
570-
const localWebhookPath = webhookPaths.localWebhookPath ?? config.serve.path;
571-
const publicWebhookPath = webhookPaths.publicWebhookPath ?? config.tailscale.path;
572-
const publicPathPrefix = resolveVoiceCallPublicPathPrefix(publicWebhookPath, localWebhookPath);
573-
return [...new Set(streamPaths.map((path) => normalizeWebhookPath(path)))].map((localPath) => ({
574-
localPath,
575-
publicPath: `${publicPathPrefix}${localPath}`,
576-
}));
581+
return exposurePaths;
577582
}
578583

579584
function normalizeVoiceCallTtsConfig(

‎extensions/voice-call/src/webhook/tailscale.test.ts‎

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,48 +181,53 @@ describe("voice-call tailscale helpers", () => {
181181
name: "realtime",
182182
config: { realtime: { enabled: true, streamPath: "/voice/stream/realtime" } },
183183
streamPath: "/voice/stream/realtime",
184+
publicStreamPath: "/edge/voice/stream/realtime",
184185
},
185186
{
186187
name: "streaming",
187188
config: { streaming: { enabled: true, streamPath: "/voice/stream" } },
188189
streamPath: "/voice/stream",
190+
publicStreamPath: "/voice/stream",
189191
},
190-
])("mounts and cleans up the enabled $name stream path", async ({ config, streamPath }) => {
191-
runCommandMock.mockImplementation(async (command: string[]) =>
192-
command[1] === "status"
193-
? commandResult({
194-
stdout: JSON.stringify({ Self: { DNSName: "bot.example.ts.net." } }),
195-
})
196-
: commandResult(),
197-
);
198-
const voiceCallConfig = {
199-
tailscale: { mode: "funnel", path: "/edge/voice/webhook" },
200-
serve: { port: 8787, path: "/voice/webhook" },
201-
realtime: { enabled: false },
202-
streaming: { enabled: false },
203-
...config,
204-
} as never;
192+
])(
193+
"mounts and cleans up the enabled $name stream path",
194+
async ({ config, streamPath, publicStreamPath }) => {
195+
runCommandMock.mockImplementation(async (command: string[]) =>
196+
command[1] === "status"
197+
? commandResult({
198+
stdout: JSON.stringify({ Self: { DNSName: "bot.example.ts.net." } }),
199+
})
200+
: commandResult(),
201+
);
202+
const voiceCallConfig = {
203+
tailscale: { mode: "funnel", path: "/edge/voice/webhook" },
204+
serve: { port: 8787, path: "/voice/webhook" },
205+
realtime: { enabled: false },
206+
streaming: { enabled: false },
207+
...config,
208+
} as never;
205209

206-
await setupTailscaleExposure(voiceCallConfig);
207-
await cleanupTailscaleExposure(voiceCallConfig);
210+
await setupTailscaleExposure(voiceCallConfig);
211+
await cleanupTailscaleExposure(voiceCallConfig);
208212

209-
expect(runCommandMock).toHaveBeenCalledWith(
210-
[
211-
"tailscale",
212-
"funnel",
213-
"--bg",
214-
"--yes",
215-
"--set-path",
216-
`/edge${streamPath}`,
217-
`http://127.0.0.1:8787${streamPath}`,
218-
],
219-
expect.any(Object),
220-
);
221-
expect(runCommandMock).toHaveBeenCalledWith(
222-
["tailscale", "funnel", "off", `/edge${streamPath}`],
223-
expect.any(Object),
224-
);
225-
});
213+
expect(runCommandMock).toHaveBeenCalledWith(
214+
[
215+
"tailscale",
216+
"funnel",
217+
"--bg",
218+
"--yes",
219+
"--set-path",
220+
publicStreamPath,
221+
`http://127.0.0.1:8787${streamPath}`,
222+
],
223+
expect.any(Object),
224+
);
225+
expect(runCommandMock).toHaveBeenCalledWith(
226+
["tailscale", "funnel", "off", publicStreamPath],
227+
expect.any(Object),
228+
);
229+
},
230+
);
226231

227232
it("deduplicates equal realtime and streaming paths", async () => {
228233
runCommandMock.mockImplementation(async (command: string[]) =>

0 commit comments

Comments
 (0)