- Update ConversationRecorder to include source and nodeId metadata in transcripts for better context tracking. - Introduce optional variable handling in DynamicVariableStore, allowing for unset variables to be rendered as empty without raising errors. - Refactor WorkflowBrain to apply turn configurations and manage interaction policies dynamically, improving agent responsiveness. - Implement tests to ensure proper handling of updated session variables and workflow metadata in various scenarios.
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import type { TurnConfig } from "@/lib/api";
|
|
|
|
export function defaultTurnConfig(): TurnConfig {
|
|
return {
|
|
bargeIn: { strategy: "vad" },
|
|
vad: {
|
|
confidence: 0.7,
|
|
startSecs: 0.2,
|
|
stopSecs: 0.2,
|
|
minVolume: 0.6,
|
|
},
|
|
turnDetection: {
|
|
strategy: "silence",
|
|
silenceTimeoutSecs: 0.6,
|
|
},
|
|
};
|
|
}
|
|
|
|
function record(value: unknown): Record<string, unknown> {
|
|
return value && typeof value === "object"
|
|
? (value as Record<string, unknown>)
|
|
: {};
|
|
}
|
|
|
|
function numberOr(value: unknown, fallback: number): number {
|
|
return typeof value === "number" && Number.isFinite(value)
|
|
? value
|
|
: fallback;
|
|
}
|
|
|
|
/** Fill settings introduced after the first Workflow release for old records. */
|
|
export function normalizeTurnConfig(value: unknown): TurnConfig {
|
|
const defaults = defaultTurnConfig();
|
|
const input = record(value);
|
|
const bargeIn = record(input.bargeIn);
|
|
const vad = record(input.vad);
|
|
const turnDetection = record(input.turnDetection);
|
|
|
|
return {
|
|
bargeIn: {
|
|
strategy:
|
|
bargeIn.strategy === "transcription" ? "transcription" : "vad",
|
|
},
|
|
vad: {
|
|
confidence: numberOr(vad.confidence, defaults.vad.confidence),
|
|
startSecs: numberOr(vad.startSecs, defaults.vad.startSecs),
|
|
stopSecs: numberOr(vad.stopSecs, defaults.vad.stopSecs),
|
|
minVolume: numberOr(vad.minVolume, defaults.vad.minVolume),
|
|
},
|
|
turnDetection: {
|
|
strategy:
|
|
turnDetection.strategy === "smart_turn" ? "smart_turn" : "silence",
|
|
silenceTimeoutSecs: numberOr(
|
|
turnDetection.silenceTimeoutSecs,
|
|
defaults.turnDetection.silenceTimeoutSecs,
|
|
),
|
|
},
|
|
};
|
|
}
|