refactor(voice-call): share path normalization · openclaw/openclaw@905c975
vincentkoc
·
2026-06-22
·
via Recent Commits to openclaw:main
File tree
extensions/voice-call/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import {
|
9 | 9 | import { z } from "zod"; |
10 | 10 | import { TtsConfigSchema } from "../api.js"; |
11 | 11 | import { deepMergeDefined } from "./deep-merge.js"; |
| 12 | +import { normalizePath } from "./path-utils.js"; |
12 | 13 | import { DEFAULT_VOICE_CALL_REALTIME_INSTRUCTIONS } from "./realtime-defaults.js"; |
13 | 14 | |
14 | 15 | // ----------------------------------------------------------------------------- |
@@ -521,20 +522,8 @@ function cloneDefaultVoiceCallConfig(): VoiceCallConfig {
|
521 | 522 | return structuredClone(DEFAULT_VOICE_CALL_CONFIG); |
522 | 523 | } |
523 | 524 | |
524 | | -function normalizeWebhookLikePath(pathname: string): string { |
525 | | -const trimmed = pathname.trim(); |
526 | | -if (!trimmed) { |
527 | | -return "/"; |
528 | | -} |
529 | | -const prefixed = trimmed.startsWith("/") ? trimmed : `/${trimmed}`; |
530 | | -if (prefixed === "/") { |
531 | | -return prefixed; |
532 | | -} |
533 | | -return prefixed.endsWith("/") ? prefixed.slice(0, -1) : prefixed; |
534 | | -} |
535 | | - |
536 | 525 | function defaultRealtimeStreamPathForServePath(servePath: string): string { |
537 | | -const normalized = normalizeWebhookLikePath(servePath); |
| 526 | +const normalized = normalizePath(servePath); |
538 | 527 | if (normalized.endsWith("/webhook")) { |
539 | 528 | return `${normalized.slice(0, -"/webhook".length)}/stream/realtime`; |
540 | 529 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Voice Call plugin module implements shared path normalization. |
| 2 | +export function normalizePath(pathname: string): string { |
| 3 | +const trimmed = pathname.trim(); |
| 4 | +if (!trimmed) { |
| 5 | +return "/"; |
| 6 | +} |
| 7 | +const prefixed = trimmed.startsWith("/") ? trimmed : `/${trimmed}`; |
| 8 | +if (prefixed === "/") { |
| 9 | +return prefixed; |
| 10 | +} |
| 11 | +return prefixed.endsWith("/") ? prefixed.slice(0, -1) : prefixed; |
| 12 | +} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -30,6 +30,7 @@ import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
|
30 | 30 | import WebSocket, { WebSocketServer } from "ws"; |
31 | 31 | import type { VoiceCallRealtimeConfig } from "../config.js"; |
32 | 32 | import type { CallManager } from "../manager.js"; |
| 33 | +import { normalizePath } from "../path-utils.js"; |
33 | 34 | import type { VoiceCallProvider } from "../providers/base.js"; |
34 | 35 | import type { CallRecord, NormalizedEvent } from "../types.js"; |
35 | 36 | import type { WebhookResponsePayload } from "../webhook.types.js"; |
@@ -64,18 +65,6 @@ const RECENT_FINAL_USER_TRANSCRIPT_TTL_MS = 2_000;
|
64 | 65 | const BARGE_IN_REQUIRED_LOUD_CHUNKS = 2; |
65 | 66 | const logger = createSubsystemLogger("voice-call/realtime"); |
66 | 67 | |
67 | | -function normalizePath(pathname: string): string { |
68 | | -const trimmed = pathname.trim(); |
69 | | -if (!trimmed) { |
70 | | -return "/"; |
71 | | -} |
72 | | -const prefixed = trimmed.startsWith("/") ? trimmed : `/${trimmed}`; |
73 | | -if (prefixed === "/") { |
74 | | -return prefixed; |
75 | | -} |
76 | | -return prefixed.endsWith("/") ? prefixed.slice(0, -1) : prefixed; |
77 | | -} |
78 | | - |
79 | 68 | function buildGreetingInstructions( |
80 | 69 | baseInstructions: string | undefined, |
81 | 70 | greeting: string | undefined, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。