@livekit/agents 1.0.48 → 1.1.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.cjs +27 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +9 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -1
- package/dist/inference/api_protos.d.cts +71 -71
- package/dist/inference/api_protos.d.ts +71 -71
- package/dist/inference/interruption/defaults.cjs +81 -0
- package/dist/inference/interruption/defaults.cjs.map +1 -0
- package/dist/inference/interruption/defaults.d.cts +19 -0
- package/dist/inference/interruption/defaults.d.ts +19 -0
- package/dist/inference/interruption/defaults.d.ts.map +1 -0
- package/dist/inference/interruption/defaults.js +46 -0
- package/dist/inference/interruption/defaults.js.map +1 -0
- package/dist/inference/interruption/errors.cjs +44 -0
- package/dist/inference/interruption/errors.cjs.map +1 -0
- package/dist/inference/interruption/errors.d.cts +12 -0
- package/dist/inference/interruption/errors.d.ts +12 -0
- package/dist/inference/interruption/errors.d.ts.map +1 -0
- package/dist/inference/interruption/errors.js +20 -0
- package/dist/inference/interruption/errors.js.map +1 -0
- package/dist/inference/interruption/http_transport.cjs +147 -0
- package/dist/inference/interruption/http_transport.cjs.map +1 -0
- package/dist/inference/interruption/http_transport.d.cts +63 -0
- package/dist/inference/interruption/http_transport.d.ts +63 -0
- package/dist/inference/interruption/http_transport.d.ts.map +1 -0
- package/dist/inference/interruption/http_transport.js +121 -0
- package/dist/inference/interruption/http_transport.js.map +1 -0
- package/dist/inference/interruption/interruption_cache_entry.cjs +58 -0
- package/dist/inference/interruption/interruption_cache_entry.cjs.map +1 -0
- package/dist/inference/interruption/interruption_cache_entry.d.cts +30 -0
- package/dist/inference/interruption/interruption_cache_entry.d.ts +30 -0
- package/dist/inference/interruption/interruption_cache_entry.d.ts.map +1 -0
- package/dist/inference/interruption/interruption_cache_entry.js +34 -0
- package/dist/inference/interruption/interruption_cache_entry.js.map +1 -0
- package/dist/inference/interruption/interruption_detector.cjs +181 -0
- package/dist/inference/interruption/interruption_detector.cjs.map +1 -0
- package/dist/inference/interruption/interruption_detector.d.cts +59 -0
- package/dist/inference/interruption/interruption_detector.d.ts +59 -0
- package/dist/inference/interruption/interruption_detector.d.ts.map +1 -0
- package/dist/inference/interruption/interruption_detector.js +147 -0
- package/dist/inference/interruption/interruption_detector.js.map +1 -0
- package/dist/inference/interruption/interruption_stream.cjs +368 -0
- package/dist/inference/interruption/interruption_stream.cjs.map +1 -0
- package/dist/inference/interruption/interruption_stream.d.cts +46 -0
- package/dist/inference/interruption/interruption_stream.d.ts +46 -0
- package/dist/inference/interruption/interruption_stream.d.ts.map +1 -0
- package/dist/inference/interruption/interruption_stream.js +344 -0
- package/dist/inference/interruption/interruption_stream.js.map +1 -0
- package/dist/inference/interruption/types.cjs +17 -0
- package/dist/inference/interruption/types.cjs.map +1 -0
- package/dist/inference/interruption/types.d.cts +66 -0
- package/dist/inference/interruption/types.d.ts +66 -0
- package/dist/inference/interruption/types.d.ts.map +1 -0
- package/dist/inference/interruption/types.js +1 -0
- package/dist/inference/interruption/types.js.map +1 -0
- package/dist/inference/interruption/utils.cjs +130 -0
- package/dist/inference/interruption/utils.cjs.map +1 -0
- package/dist/inference/interruption/utils.d.cts +41 -0
- package/dist/inference/interruption/utils.d.ts +41 -0
- package/dist/inference/interruption/utils.d.ts.map +1 -0
- package/dist/inference/interruption/utils.js +105 -0
- package/dist/inference/interruption/utils.js.map +1 -0
- package/dist/inference/interruption/utils.test.cjs +105 -0
- package/dist/inference/interruption/utils.test.cjs.map +1 -0
- package/dist/inference/interruption/utils.test.js +104 -0
- package/dist/inference/interruption/utils.test.js.map +1 -0
- package/dist/inference/interruption/ws_transport.cjs +329 -0
- package/dist/inference/interruption/ws_transport.cjs.map +1 -0
- package/dist/inference/interruption/ws_transport.d.cts +33 -0
- package/dist/inference/interruption/ws_transport.d.ts +33 -0
- package/dist/inference/interruption/ws_transport.d.ts.map +1 -0
- package/dist/inference/interruption/ws_transport.js +295 -0
- package/dist/inference/interruption/ws_transport.js.map +1 -0
- package/dist/inference/llm.cjs +14 -10
- package/dist/inference/llm.cjs.map +1 -1
- package/dist/inference/llm.d.cts +2 -1
- package/dist/inference/llm.d.ts +2 -1
- package/dist/inference/llm.d.ts.map +1 -1
- package/dist/inference/llm.js +8 -10
- package/dist/inference/llm.js.map +1 -1
- package/dist/inference/stt.cjs +7 -2
- package/dist/inference/stt.cjs.map +1 -1
- package/dist/inference/stt.d.cts +2 -0
- package/dist/inference/stt.d.ts +2 -0
- package/dist/inference/stt.d.ts.map +1 -1
- package/dist/inference/stt.js +8 -3
- package/dist/inference/stt.js.map +1 -1
- package/dist/inference/tts.cjs +7 -2
- package/dist/inference/tts.cjs.map +1 -1
- package/dist/inference/tts.d.cts +2 -0
- package/dist/inference/tts.d.ts +2 -0
- package/dist/inference/tts.d.ts.map +1 -1
- package/dist/inference/tts.js +8 -3
- package/dist/inference/tts.js.map +1 -1
- package/dist/inference/utils.cjs +26 -7
- package/dist/inference/utils.cjs.map +1 -1
- package/dist/inference/utils.d.cts +13 -0
- package/dist/inference/utils.d.ts +13 -0
- package/dist/inference/utils.d.ts.map +1 -1
- package/dist/inference/utils.js +18 -2
- package/dist/inference/utils.js.map +1 -1
- package/dist/llm/chat_context.cjs +20 -2
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +19 -1
- package/dist/llm/chat_context.d.ts +19 -1
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +20 -2
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/index.cjs.map +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/llm.cjs +16 -1
- package/dist/llm/llm.cjs.map +1 -1
- package/dist/llm/llm.d.cts +9 -0
- package/dist/llm/llm.d.ts +9 -0
- package/dist/llm/llm.d.ts.map +1 -1
- package/dist/llm/llm.js +16 -1
- package/dist/llm/llm.js.map +1 -1
- package/dist/llm/realtime.cjs +3 -0
- package/dist/llm/realtime.cjs.map +1 -1
- package/dist/llm/realtime.d.cts +1 -0
- package/dist/llm/realtime.d.ts +1 -0
- package/dist/llm/realtime.d.ts.map +1 -1
- package/dist/llm/realtime.js +3 -0
- package/dist/llm/realtime.js.map +1 -1
- package/dist/metrics/base.cjs.map +1 -1
- package/dist/metrics/base.d.cts +45 -1
- package/dist/metrics/base.d.ts +45 -1
- package/dist/metrics/base.d.ts.map +1 -1
- package/dist/metrics/index.cjs +5 -0
- package/dist/metrics/index.cjs.map +1 -1
- package/dist/metrics/index.d.cts +2 -1
- package/dist/metrics/index.d.ts +2 -1
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +6 -0
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/model_usage.cjs +189 -0
- package/dist/metrics/model_usage.cjs.map +1 -0
- package/dist/metrics/model_usage.d.cts +92 -0
- package/dist/metrics/model_usage.d.ts +92 -0
- package/dist/metrics/model_usage.d.ts.map +1 -0
- package/dist/metrics/model_usage.js +164 -0
- package/dist/metrics/model_usage.js.map +1 -0
- package/dist/metrics/model_usage.test.cjs +474 -0
- package/dist/metrics/model_usage.test.cjs.map +1 -0
- package/dist/metrics/model_usage.test.js +476 -0
- package/dist/metrics/model_usage.test.js.map +1 -0
- package/dist/metrics/usage_collector.cjs +3 -0
- package/dist/metrics/usage_collector.cjs.map +1 -1
- package/dist/metrics/usage_collector.d.cts +9 -0
- package/dist/metrics/usage_collector.d.ts +9 -0
- package/dist/metrics/usage_collector.d.ts.map +1 -1
- package/dist/metrics/usage_collector.js +3 -0
- package/dist/metrics/usage_collector.js.map +1 -1
- package/dist/metrics/utils.cjs +9 -0
- package/dist/metrics/utils.cjs.map +1 -1
- package/dist/metrics/utils.d.ts.map +1 -1
- package/dist/metrics/utils.js +9 -0
- package/dist/metrics/utils.js.map +1 -1
- package/dist/stream/multi_input_stream.test.cjs +4 -0
- package/dist/stream/multi_input_stream.test.cjs.map +1 -1
- package/dist/stream/multi_input_stream.test.js +5 -1
- package/dist/stream/multi_input_stream.test.js.map +1 -1
- package/dist/stream/stream_channel.cjs +31 -0
- package/dist/stream/stream_channel.cjs.map +1 -1
- package/dist/stream/stream_channel.d.cts +4 -2
- package/dist/stream/stream_channel.d.ts +4 -2
- package/dist/stream/stream_channel.d.ts.map +1 -1
- package/dist/stream/stream_channel.js +31 -0
- package/dist/stream/stream_channel.js.map +1 -1
- package/dist/stt/stt.cjs +34 -2
- package/dist/stt/stt.cjs.map +1 -1
- package/dist/stt/stt.d.cts +22 -0
- package/dist/stt/stt.d.ts +22 -0
- package/dist/stt/stt.d.ts.map +1 -1
- package/dist/stt/stt.js +34 -2
- package/dist/stt/stt.js.map +1 -1
- package/dist/telemetry/otel_http_exporter.cjs +24 -5
- package/dist/telemetry/otel_http_exporter.cjs.map +1 -1
- package/dist/telemetry/otel_http_exporter.d.cts +1 -0
- package/dist/telemetry/otel_http_exporter.d.ts +1 -0
- package/dist/telemetry/otel_http_exporter.d.ts.map +1 -1
- package/dist/telemetry/otel_http_exporter.js +24 -5
- package/dist/telemetry/otel_http_exporter.js.map +1 -1
- package/dist/telemetry/trace_types.cjs +5 -5
- package/dist/telemetry/trace_types.cjs.map +1 -1
- package/dist/telemetry/trace_types.d.cts +9 -5
- package/dist/telemetry/trace_types.d.ts +9 -5
- package/dist/telemetry/trace_types.d.ts.map +1 -1
- package/dist/telemetry/trace_types.js +5 -5
- package/dist/telemetry/trace_types.js.map +1 -1
- package/dist/telemetry/traces.cjs +47 -8
- package/dist/telemetry/traces.cjs.map +1 -1
- package/dist/telemetry/traces.d.ts.map +1 -1
- package/dist/telemetry/traces.js +47 -8
- package/dist/telemetry/traces.js.map +1 -1
- package/dist/tts/tts.cjs +64 -2
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.d.cts +34 -0
- package/dist/tts/tts.d.ts +34 -0
- package/dist/tts/tts.d.ts.map +1 -1
- package/dist/tts/tts.js +64 -2
- package/dist/tts/tts.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/voice/agent.cjs +25 -4
- package/dist/voice/agent.cjs.map +1 -1
- package/dist/voice/agent.d.cts +10 -2
- package/dist/voice/agent.d.ts +10 -2
- package/dist/voice/agent.d.ts.map +1 -1
- package/dist/voice/agent.js +25 -4
- package/dist/voice/agent.js.map +1 -1
- package/dist/voice/agent_activity.cjs +261 -36
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +20 -6
- package/dist/voice/agent_activity.d.ts +20 -6
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +262 -37
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +105 -48
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +90 -20
- package/dist/voice/agent_session.d.ts +90 -20
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +105 -46
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/audio_recognition.cjs +287 -6
- package/dist/voice/audio_recognition.cjs.map +1 -1
- package/dist/voice/audio_recognition.d.cts +42 -3
- package/dist/voice/audio_recognition.d.ts +42 -3
- package/dist/voice/audio_recognition.d.ts.map +1 -1
- package/dist/voice/audio_recognition.js +289 -7
- package/dist/voice/audio_recognition.js.map +1 -1
- package/dist/voice/client_events.cjs +554 -0
- package/dist/voice/client_events.cjs.map +1 -0
- package/dist/voice/client_events.d.cts +195 -0
- package/dist/voice/client_events.d.ts +195 -0
- package/dist/voice/client_events.d.ts.map +1 -0
- package/dist/voice/client_events.js +548 -0
- package/dist/voice/client_events.js.map +1 -0
- package/dist/voice/events.cjs +1 -0
- package/dist/voice/events.cjs.map +1 -1
- package/dist/voice/events.d.cts +8 -5
- package/dist/voice/events.d.ts +8 -5
- package/dist/voice/events.d.ts.map +1 -1
- package/dist/voice/events.js +1 -0
- package/dist/voice/events.js.map +1 -1
- package/dist/voice/generation.cjs +43 -8
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.cts +3 -3
- package/dist/voice/generation.d.ts +3 -3
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js +43 -8
- package/dist/voice/generation.js.map +1 -1
- package/dist/voice/index.cjs +1 -0
- package/dist/voice/index.cjs.map +1 -1
- package/dist/voice/index.d.cts +1 -0
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -0
- package/dist/voice/index.js.map +1 -1
- package/dist/voice/report.cjs +20 -8
- package/dist/voice/report.cjs.map +1 -1
- package/dist/voice/report.d.cts +5 -0
- package/dist/voice/report.d.ts +5 -0
- package/dist/voice/report.d.ts.map +1 -1
- package/dist/voice/report.js +20 -8
- package/dist/voice/report.js.map +1 -1
- package/dist/voice/report.test.cjs +106 -0
- package/dist/voice/report.test.cjs.map +1 -0
- package/dist/voice/report.test.js +105 -0
- package/dist/voice/report.test.js.map +1 -0
- package/dist/voice/room_io/room_io.cjs +5 -39
- package/dist/voice/room_io/room_io.cjs.map +1 -1
- package/dist/voice/room_io/room_io.d.cts +4 -9
- package/dist/voice/room_io/room_io.d.ts +4 -9
- package/dist/voice/room_io/room_io.d.ts.map +1 -1
- package/dist/voice/room_io/room_io.js +5 -40
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/turn_config/endpointing.cjs +33 -0
- package/dist/voice/turn_config/endpointing.cjs.map +1 -0
- package/dist/voice/turn_config/endpointing.d.cts +30 -0
- package/dist/voice/turn_config/endpointing.d.ts +30 -0
- package/dist/voice/turn_config/endpointing.d.ts.map +1 -0
- package/dist/voice/turn_config/endpointing.js +9 -0
- package/dist/voice/turn_config/endpointing.js.map +1 -0
- package/dist/voice/turn_config/interruption.cjs +37 -0
- package/dist/voice/turn_config/interruption.cjs.map +1 -0
- package/dist/voice/turn_config/interruption.d.cts +53 -0
- package/dist/voice/turn_config/interruption.d.ts +53 -0
- package/dist/voice/turn_config/interruption.d.ts.map +1 -0
- package/dist/voice/turn_config/interruption.js +13 -0
- package/dist/voice/turn_config/interruption.js.map +1 -0
- package/dist/voice/turn_config/turn_handling.cjs +35 -0
- package/dist/voice/turn_config/turn_handling.cjs.map +1 -0
- package/dist/voice/turn_config/turn_handling.d.cts +36 -0
- package/dist/voice/turn_config/turn_handling.d.ts +36 -0
- package/dist/voice/turn_config/turn_handling.d.ts.map +1 -0
- package/dist/voice/turn_config/turn_handling.js +11 -0
- package/dist/voice/turn_config/turn_handling.js.map +1 -0
- package/dist/voice/turn_config/utils.cjs +97 -0
- package/dist/voice/turn_config/utils.cjs.map +1 -0
- package/dist/voice/turn_config/utils.d.cts +25 -0
- package/dist/voice/turn_config/utils.d.ts +25 -0
- package/dist/voice/turn_config/utils.d.ts.map +1 -0
- package/dist/voice/turn_config/utils.js +73 -0
- package/dist/voice/turn_config/utils.js.map +1 -0
- package/dist/voice/turn_config/utils.test.cjs +86 -0
- package/dist/voice/turn_config/utils.test.cjs.map +1 -0
- package/dist/voice/turn_config/utils.test.js +85 -0
- package/dist/voice/turn_config/utils.test.js.map +1 -0
- package/dist/voice/wire_format.cjs +798 -0
- package/dist/voice/wire_format.cjs.map +1 -0
- package/dist/voice/wire_format.d.cts +5503 -0
- package/dist/voice/wire_format.d.ts +5503 -0
- package/dist/voice/wire_format.d.ts.map +1 -0
- package/dist/voice/wire_format.js +728 -0
- package/dist/voice/wire_format.js.map +1 -0
- package/package.json +2 -1
- package/src/constants.ts +13 -0
- package/src/inference/interruption/defaults.ts +51 -0
- package/src/inference/interruption/errors.ts +25 -0
- package/src/inference/interruption/http_transport.ts +187 -0
- package/src/inference/interruption/interruption_cache_entry.ts +50 -0
- package/src/inference/interruption/interruption_detector.ts +188 -0
- package/src/inference/interruption/interruption_stream.ts +467 -0
- package/src/inference/interruption/types.ts +84 -0
- package/src/inference/interruption/utils.test.ts +132 -0
- package/src/inference/interruption/utils.ts +137 -0
- package/src/inference/interruption/ws_transport.ts +402 -0
- package/src/inference/llm.ts +9 -12
- package/src/inference/stt.ts +10 -3
- package/src/inference/tts.ts +10 -3
- package/src/inference/utils.ts +29 -1
- package/src/llm/chat_context.ts +40 -2
- package/src/llm/index.ts +1 -0
- package/src/llm/llm.ts +16 -0
- package/src/llm/realtime.ts +4 -0
- package/src/metrics/base.ts +48 -1
- package/src/metrics/index.ts +11 -0
- package/src/metrics/model_usage.test.ts +545 -0
- package/src/metrics/model_usage.ts +262 -0
- package/src/metrics/usage_collector.ts +11 -0
- package/src/metrics/utils.ts +11 -0
- package/src/stream/multi_input_stream.test.ts +6 -1
- package/src/stream/stream_channel.ts +34 -2
- package/src/stt/stt.ts +38 -0
- package/src/telemetry/otel_http_exporter.ts +28 -5
- package/src/telemetry/trace_types.ts +11 -8
- package/src/telemetry/traces.ts +111 -54
- package/src/tts/tts.ts +69 -1
- package/src/voice/agent.ts +30 -3
- package/src/voice/agent_activity.ts +327 -28
- package/src/voice/agent_session.ts +207 -59
- package/src/voice/audio_recognition.ts +385 -9
- package/src/voice/client_events.ts +838 -0
- package/src/voice/events.ts +14 -4
- package/src/voice/generation.ts +52 -9
- package/src/voice/index.ts +1 -0
- package/src/voice/report.test.ts +117 -0
- package/src/voice/report.ts +29 -6
- package/src/voice/room_io/room_io.ts +7 -61
- package/src/voice/turn_config/endpointing.ts +33 -0
- package/src/voice/turn_config/interruption.ts +56 -0
- package/src/voice/turn_config/turn_handling.ts +45 -0
- package/src/voice/turn_config/utils.test.ts +100 -0
- package/src/voice/turn_config/utils.ts +103 -0
- package/src/voice/wire_format.ts +827 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var http_transport_exports = {};
|
|
20
|
+
__export(http_transport_exports, {
|
|
21
|
+
createHttpTransport: () => createHttpTransport,
|
|
22
|
+
predictEndpointResponseSchema: () => predictEndpointResponseSchema,
|
|
23
|
+
predictHTTP: () => predictHTTP
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(http_transport_exports);
|
|
26
|
+
var import_ofetch = require("ofetch");
|
|
27
|
+
var import_web = require("stream/web");
|
|
28
|
+
var import_zod = require("zod");
|
|
29
|
+
var import_log = require("../../log.cjs");
|
|
30
|
+
var import_utils = require("../utils.cjs");
|
|
31
|
+
var import_defaults = require("./defaults.cjs");
|
|
32
|
+
var import_interruption_cache_entry = require("./interruption_cache_entry.cjs");
|
|
33
|
+
const predictEndpointResponseSchema = import_zod.z.object({
|
|
34
|
+
created_at: import_zod.z.number(),
|
|
35
|
+
is_bargein: import_zod.z.boolean(),
|
|
36
|
+
probabilities: import_zod.z.array(import_zod.z.number())
|
|
37
|
+
});
|
|
38
|
+
async function predictHTTP(data, predictOptions, options) {
|
|
39
|
+
const createdAt = performance.now();
|
|
40
|
+
const url = new URL(`/bargein`, options.baseUrl);
|
|
41
|
+
url.searchParams.append("threshold", predictOptions.threshold.toString());
|
|
42
|
+
url.searchParams.append("min_frames", predictOptions.minFrames.toFixed());
|
|
43
|
+
url.searchParams.append("created_at", createdAt.toFixed());
|
|
44
|
+
let retryCount = 0;
|
|
45
|
+
const response = await (0, import_ofetch.ofetch)(url.toString(), {
|
|
46
|
+
retry: options.maxRetries ?? 3,
|
|
47
|
+
retryDelay: () => {
|
|
48
|
+
const delay = (0, import_defaults.intervalForRetry)(retryCount);
|
|
49
|
+
retryCount++;
|
|
50
|
+
return delay;
|
|
51
|
+
},
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/octet-stream",
|
|
54
|
+
Authorization: `Bearer ${options.token}`
|
|
55
|
+
},
|
|
56
|
+
signal: options.signal,
|
|
57
|
+
timeout: options.timeout,
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: data
|
|
60
|
+
});
|
|
61
|
+
const { created_at, is_bargein, probabilities } = predictEndpointResponseSchema.parse(response);
|
|
62
|
+
return {
|
|
63
|
+
createdAt: created_at,
|
|
64
|
+
isBargein: is_bargein,
|
|
65
|
+
probabilities,
|
|
66
|
+
predictionDurationInS: (performance.now() - createdAt) / 1e3
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function createHttpTransport(options, getState, setState, updateUserSpeakingSpan, getAndResetNumRequests) {
|
|
70
|
+
const logger = (0, import_log.log)();
|
|
71
|
+
return new import_web.TransformStream(
|
|
72
|
+
{
|
|
73
|
+
async transform(chunk, controller) {
|
|
74
|
+
if (!(chunk instanceof Int16Array)) {
|
|
75
|
+
controller.enqueue(chunk);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const state = getState();
|
|
79
|
+
const overlapSpeechStartedAt = state.overlapSpeechStartedAt;
|
|
80
|
+
if (overlapSpeechStartedAt === void 0 || !state.overlapSpeechStarted) return;
|
|
81
|
+
try {
|
|
82
|
+
const resp = await predictHTTP(
|
|
83
|
+
chunk,
|
|
84
|
+
{ threshold: options.threshold, minFrames: options.minFrames },
|
|
85
|
+
{
|
|
86
|
+
baseUrl: options.baseUrl,
|
|
87
|
+
timeout: options.timeout,
|
|
88
|
+
maxRetries: options.maxRetries,
|
|
89
|
+
token: await (0, import_utils.createAccessToken)(options.apiKey, options.apiSecret)
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
const { createdAt, isBargein, probabilities, predictionDurationInS } = resp;
|
|
93
|
+
const entry = state.cache.setOrUpdate(
|
|
94
|
+
createdAt,
|
|
95
|
+
() => new import_interruption_cache_entry.InterruptionCacheEntry({ createdAt }),
|
|
96
|
+
{
|
|
97
|
+
probabilities,
|
|
98
|
+
isInterruption: isBargein,
|
|
99
|
+
speechInput: chunk,
|
|
100
|
+
totalDurationInS: (performance.now() - createdAt) / 1e3,
|
|
101
|
+
detectionDelayInS: (Date.now() - overlapSpeechStartedAt) / 1e3,
|
|
102
|
+
predictionDurationInS
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
if (state.overlapSpeechStarted && entry.isInterruption) {
|
|
106
|
+
if (updateUserSpeakingSpan) {
|
|
107
|
+
updateUserSpeakingSpan(entry);
|
|
108
|
+
}
|
|
109
|
+
const event = {
|
|
110
|
+
type: "user_overlapping_speech",
|
|
111
|
+
timestamp: Date.now(),
|
|
112
|
+
overlapStartedAt: overlapSpeechStartedAt,
|
|
113
|
+
isInterruption: entry.isInterruption,
|
|
114
|
+
speechInput: entry.speechInput,
|
|
115
|
+
probabilities: entry.probabilities,
|
|
116
|
+
totalDurationInS: entry.totalDurationInS,
|
|
117
|
+
predictionDurationInS: entry.predictionDurationInS,
|
|
118
|
+
detectionDelayInS: entry.detectionDelayInS,
|
|
119
|
+
probability: entry.probability,
|
|
120
|
+
numRequests: (getAndResetNumRequests == null ? void 0 : getAndResetNumRequests()) ?? 0
|
|
121
|
+
};
|
|
122
|
+
logger.debug(
|
|
123
|
+
{
|
|
124
|
+
detectionDelayInS: entry.detectionDelayInS,
|
|
125
|
+
totalDurationInS: entry.totalDurationInS
|
|
126
|
+
},
|
|
127
|
+
"interruption detected"
|
|
128
|
+
);
|
|
129
|
+
setState({ overlapSpeechStarted: false });
|
|
130
|
+
controller.enqueue(event);
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
logger.error({ err }, "Failed to send audio data over HTTP");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{ highWaterMark: 2 },
|
|
138
|
+
{ highWaterMark: 2 }
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
+
0 && (module.exports = {
|
|
143
|
+
createHttpTransport,
|
|
144
|
+
predictEndpointResponseSchema,
|
|
145
|
+
predictHTTP
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=http_transport.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/http_transport.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ofetch } from 'ofetch';\nimport { TransformStream } from 'stream/web';\nimport { z } from 'zod';\nimport { log } from '../../log.js';\nimport { createAccessToken } from '../utils.js';\nimport { intervalForRetry } from './defaults.js';\nimport { InterruptionCacheEntry } from './interruption_cache_entry.js';\nimport type { OverlappingSpeechEvent } from './types.js';\nimport type { BoundedCache } from './utils.js';\n\nexport interface PostOptions {\n baseUrl: string;\n token: string;\n signal?: AbortSignal;\n timeout?: number;\n maxRetries?: number;\n}\n\nexport interface PredictOptions {\n threshold: number;\n minFrames: number;\n}\n\nexport const predictEndpointResponseSchema = z.object({\n created_at: z.number(),\n is_bargein: z.boolean(),\n probabilities: z.array(z.number()),\n});\n\nexport type PredictEndpointResponse = z.infer<typeof predictEndpointResponseSchema>;\n\nexport interface PredictResponse {\n createdAt: number;\n isBargein: boolean;\n probabilities: number[];\n predictionDurationInS: number;\n}\n\nexport async function predictHTTP(\n data: Int16Array,\n predictOptions: PredictOptions,\n options: PostOptions,\n): Promise<PredictResponse> {\n const createdAt = performance.now();\n const url = new URL(`/bargein`, options.baseUrl);\n url.searchParams.append('threshold', predictOptions.threshold.toString());\n url.searchParams.append('min_frames', predictOptions.minFrames.toFixed());\n url.searchParams.append('created_at', createdAt.toFixed());\n\n let retryCount = 0;\n const response = await ofetch(url.toString(), {\n retry: options.maxRetries ?? 3,\n retryDelay: () => {\n const delay = intervalForRetry(retryCount);\n retryCount++;\n return delay;\n },\n headers: {\n 'Content-Type': 'application/octet-stream',\n Authorization: `Bearer ${options.token}`,\n },\n signal: options.signal,\n timeout: options.timeout,\n method: 'POST',\n body: data,\n });\n const { created_at, is_bargein, probabilities } = predictEndpointResponseSchema.parse(response);\n\n return {\n createdAt: created_at,\n isBargein: is_bargein,\n probabilities,\n predictionDurationInS: (performance.now() - createdAt) / 1000,\n };\n}\n\nexport interface HttpTransportOptions {\n baseUrl: string;\n apiKey: string;\n apiSecret: string;\n threshold: number;\n minFrames: number;\n timeout: number;\n maxRetries?: number;\n}\n\nexport interface HttpTransportState {\n overlapSpeechStarted: boolean;\n overlapSpeechStartedAt: number | undefined;\n cache: BoundedCache<number, InterruptionCacheEntry>;\n}\n\n/**\n * Creates an HTTP transport TransformStream for interruption detection.\n *\n * This transport receives Int16Array audio slices and outputs InterruptionEvents.\n * Each audio slice triggers an HTTP POST request.\n *\n * @param options - Transport options object. This is read on each request, so mutations\n * to threshold/minFrames will be picked up dynamically.\n */\nexport function createHttpTransport(\n options: HttpTransportOptions,\n getState: () => HttpTransportState,\n setState: (partial: Partial<HttpTransportState>) => void,\n updateUserSpeakingSpan?: (entry: InterruptionCacheEntry) => void,\n getAndResetNumRequests?: () => number,\n): TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent> {\n const logger = log();\n\n return new TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent>(\n {\n async transform(chunk, controller) {\n if (!(chunk instanceof Int16Array)) {\n controller.enqueue(chunk);\n return;\n }\n\n const state = getState();\n const overlapSpeechStartedAt = state.overlapSpeechStartedAt;\n if (overlapSpeechStartedAt === undefined || !state.overlapSpeechStarted) return;\n\n try {\n const resp = await predictHTTP(\n chunk,\n { threshold: options.threshold, minFrames: options.minFrames },\n {\n baseUrl: options.baseUrl,\n timeout: options.timeout,\n maxRetries: options.maxRetries,\n token: await createAccessToken(options.apiKey, options.apiSecret),\n },\n );\n\n const { createdAt, isBargein, probabilities, predictionDurationInS } = resp;\n const entry = state.cache.setOrUpdate(\n createdAt,\n () => new InterruptionCacheEntry({ createdAt }),\n {\n probabilities,\n isInterruption: isBargein,\n speechInput: chunk,\n totalDurationInS: (performance.now() - createdAt) / 1000,\n detectionDelayInS: (Date.now() - overlapSpeechStartedAt) / 1000,\n predictionDurationInS,\n },\n );\n\n if (state.overlapSpeechStarted && entry.isInterruption) {\n if (updateUserSpeakingSpan) {\n updateUserSpeakingSpan(entry);\n }\n const event: OverlappingSpeechEvent = {\n type: 'user_overlapping_speech',\n timestamp: Date.now(),\n overlapStartedAt: overlapSpeechStartedAt,\n isInterruption: entry.isInterruption,\n speechInput: entry.speechInput,\n probabilities: entry.probabilities,\n totalDurationInS: entry.totalDurationInS,\n predictionDurationInS: entry.predictionDurationInS,\n detectionDelayInS: entry.detectionDelayInS,\n probability: entry.probability,\n numRequests: getAndResetNumRequests?.() ?? 0,\n };\n logger.debug(\n {\n detectionDelayInS: entry.detectionDelayInS,\n totalDurationInS: entry.totalDurationInS,\n },\n 'interruption detected',\n );\n setState({ overlapSpeechStarted: false });\n controller.enqueue(event);\n }\n } catch (err) {\n logger.error({ err }, 'Failed to send audio data over HTTP');\n }\n },\n },\n { highWaterMark: 2 },\n { highWaterMark: 2 },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuB;AACvB,iBAAgC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AM;AAAA,cAC1B;AAAA,cACA;AAAA,YACF;AACA,qBAAS,EAAE,sBAAsB,MAAM,CAAC;AACxC,uBAAW,QAAQ,KAAK;AAAA,UAC1B;AAAA,QACF,SAAS,KAAK;AACZ,iBAAO,MAAM,EAAE,IAAI,GAAG,qCAAqC;AAAA,QAC7D;AAAA,MACF;AAAA,IACF;AAAA,IACA,EAAE,eAAe,EAAE;AAAA,IACnB,EAAE,eAAe,EAAE;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { TransformStream } from 'stream/web';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { InterruptionCacheEntry } from './interruption_cache_entry.js';
|
|
5
|
+
import type { OverlappingSpeechEvent } from './types.js';
|
|
6
|
+
import type { BoundedCache } from './utils.js';
|
|
7
|
+
export interface PostOptions {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
token: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface PredictOptions {
|
|
15
|
+
threshold: number;
|
|
16
|
+
minFrames: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const predictEndpointResponseSchema: z.ZodObject<{
|
|
19
|
+
created_at: z.ZodNumber;
|
|
20
|
+
is_bargein: z.ZodBoolean;
|
|
21
|
+
probabilities: z.ZodArray<z.ZodNumber, "many">;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
created_at: number;
|
|
24
|
+
is_bargein: boolean;
|
|
25
|
+
probabilities: number[];
|
|
26
|
+
}, {
|
|
27
|
+
created_at: number;
|
|
28
|
+
is_bargein: boolean;
|
|
29
|
+
probabilities: number[];
|
|
30
|
+
}>;
|
|
31
|
+
export type PredictEndpointResponse = z.infer<typeof predictEndpointResponseSchema>;
|
|
32
|
+
export interface PredictResponse {
|
|
33
|
+
createdAt: number;
|
|
34
|
+
isBargein: boolean;
|
|
35
|
+
probabilities: number[];
|
|
36
|
+
predictionDurationInS: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function predictHTTP(data: Int16Array, predictOptions: PredictOptions, options: PostOptions): Promise<PredictResponse>;
|
|
39
|
+
export interface HttpTransportOptions {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
apiKey: string;
|
|
42
|
+
apiSecret: string;
|
|
43
|
+
threshold: number;
|
|
44
|
+
minFrames: number;
|
|
45
|
+
timeout: number;
|
|
46
|
+
maxRetries?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface HttpTransportState {
|
|
49
|
+
overlapSpeechStarted: boolean;
|
|
50
|
+
overlapSpeechStartedAt: number | undefined;
|
|
51
|
+
cache: BoundedCache<number, InterruptionCacheEntry>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates an HTTP transport TransformStream for interruption detection.
|
|
55
|
+
*
|
|
56
|
+
* This transport receives Int16Array audio slices and outputs InterruptionEvents.
|
|
57
|
+
* Each audio slice triggers an HTTP POST request.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Transport options object. This is read on each request, so mutations
|
|
60
|
+
* to threshold/minFrames will be picked up dynamically.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createHttpTransport(options: HttpTransportOptions, getState: () => HttpTransportState, setState: (partial: Partial<HttpTransportState>) => void, updateUserSpeakingSpan?: (entry: InterruptionCacheEntry) => void, getAndResetNumRequests?: () => number): TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent>;
|
|
63
|
+
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { TransformStream } from 'stream/web';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { InterruptionCacheEntry } from './interruption_cache_entry.js';
|
|
5
|
+
import type { OverlappingSpeechEvent } from './types.js';
|
|
6
|
+
import type { BoundedCache } from './utils.js';
|
|
7
|
+
export interface PostOptions {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
token: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface PredictOptions {
|
|
15
|
+
threshold: number;
|
|
16
|
+
minFrames: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const predictEndpointResponseSchema: z.ZodObject<{
|
|
19
|
+
created_at: z.ZodNumber;
|
|
20
|
+
is_bargein: z.ZodBoolean;
|
|
21
|
+
probabilities: z.ZodArray<z.ZodNumber, "many">;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
created_at: number;
|
|
24
|
+
is_bargein: boolean;
|
|
25
|
+
probabilities: number[];
|
|
26
|
+
}, {
|
|
27
|
+
created_at: number;
|
|
28
|
+
is_bargein: boolean;
|
|
29
|
+
probabilities: number[];
|
|
30
|
+
}>;
|
|
31
|
+
export type PredictEndpointResponse = z.infer<typeof predictEndpointResponseSchema>;
|
|
32
|
+
export interface PredictResponse {
|
|
33
|
+
createdAt: number;
|
|
34
|
+
isBargein: boolean;
|
|
35
|
+
probabilities: number[];
|
|
36
|
+
predictionDurationInS: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function predictHTTP(data: Int16Array, predictOptions: PredictOptions, options: PostOptions): Promise<PredictResponse>;
|
|
39
|
+
export interface HttpTransportOptions {
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
apiKey: string;
|
|
42
|
+
apiSecret: string;
|
|
43
|
+
threshold: number;
|
|
44
|
+
minFrames: number;
|
|
45
|
+
timeout: number;
|
|
46
|
+
maxRetries?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface HttpTransportState {
|
|
49
|
+
overlapSpeechStarted: boolean;
|
|
50
|
+
overlapSpeechStartedAt: number | undefined;
|
|
51
|
+
cache: BoundedCache<number, InterruptionCacheEntry>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates an HTTP transport TransformStream for interruption detection.
|
|
55
|
+
*
|
|
56
|
+
* This transport receives Int16Array audio slices and outputs InterruptionEvents.
|
|
57
|
+
* Each audio slice triggers an HTTP POST request.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Transport options object. This is read on each request, so mutations
|
|
60
|
+
* to threshold/minFrames will be picked up dynamically.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createHttpTransport(options: HttpTransportOptions, getState: () => HttpTransportState, setState: (partial: Partial<HttpTransportState>) => void, updateUserSpeakingSpan?: (entry: InterruptionCacheEntry) => void, getAndResetNumRequests?: () => number): TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent>;
|
|
63
|
+
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../src/inference/interruption/http_transport.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,6BAA6B;;;;;;;;;;;;EAIxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GA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|
|
4
|
+
import { log } from "../../log.js";
|
|
5
|
+
import { createAccessToken } from "../utils.js";
|
|
6
|
+
import { intervalForRetry } from "./defaults.js";
|
|
7
|
+
import { InterruptionCacheEntry } from "./interruption_cache_entry.js";
|
|
8
|
+
const predictEndpointResponseSchema = z.object({
|
|
9
|
+
created_at: z.number(),
|
|
10
|
+
is_bargein: z.boolean(),
|
|
11
|
+
probabilities: z.array(z.number())
|
|
12
|
+
});
|
|
13
|
+
async function predictHTTP(data, predictOptions, options) {
|
|
14
|
+
const createdAt = performance.now();
|
|
15
|
+
const url = new URL(`/bargein`, options.baseUrl);
|
|
16
|
+
url.searchParams.append("threshold", predictOptions.threshold.toString());
|
|
17
|
+
url.searchParams.append("min_frames", predictOptions.minFrames.toFixed());
|
|
18
|
+
url.searchParams.append("created_at", createdAt.toFixed());
|
|
19
|
+
let retryCount = 0;
|
|
20
|
+
const response = await ofetch(url.toString(), {
|
|
21
|
+
retry: options.maxRetries ?? 3,
|
|
22
|
+
retryDelay: () => {
|
|
23
|
+
const delay = intervalForRetry(retryCount);
|
|
24
|
+
retryCount++;
|
|
25
|
+
return delay;
|
|
26
|
+
},
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/octet-stream",
|
|
29
|
+
Authorization: `Bearer ${options.token}`
|
|
30
|
+
},
|
|
31
|
+
signal: options.signal,
|
|
32
|
+
timeout: options.timeout,
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: data
|
|
35
|
+
});
|
|
36
|
+
const { created_at, is_bargein, probabilities } = predictEndpointResponseSchema.parse(response);
|
|
37
|
+
return {
|
|
38
|
+
createdAt: created_at,
|
|
39
|
+
isBargein: is_bargein,
|
|
40
|
+
probabilities,
|
|
41
|
+
predictionDurationInS: (performance.now() - createdAt) / 1e3
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createHttpTransport(options, getState, setState, updateUserSpeakingSpan, getAndResetNumRequests) {
|
|
45
|
+
const logger = log();
|
|
46
|
+
return new TransformStream(
|
|
47
|
+
{
|
|
48
|
+
async transform(chunk, controller) {
|
|
49
|
+
if (!(chunk instanceof Int16Array)) {
|
|
50
|
+
controller.enqueue(chunk);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const state = getState();
|
|
54
|
+
const overlapSpeechStartedAt = state.overlapSpeechStartedAt;
|
|
55
|
+
if (overlapSpeechStartedAt === void 0 || !state.overlapSpeechStarted) return;
|
|
56
|
+
try {
|
|
57
|
+
const resp = await predictHTTP(
|
|
58
|
+
chunk,
|
|
59
|
+
{ threshold: options.threshold, minFrames: options.minFrames },
|
|
60
|
+
{
|
|
61
|
+
baseUrl: options.baseUrl,
|
|
62
|
+
timeout: options.timeout,
|
|
63
|
+
maxRetries: options.maxRetries,
|
|
64
|
+
token: await createAccessToken(options.apiKey, options.apiSecret)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
const { createdAt, isBargein, probabilities, predictionDurationInS } = resp;
|
|
68
|
+
const entry = state.cache.setOrUpdate(
|
|
69
|
+
createdAt,
|
|
70
|
+
() => new InterruptionCacheEntry({ createdAt }),
|
|
71
|
+
{
|
|
72
|
+
probabilities,
|
|
73
|
+
isInterruption: isBargein,
|
|
74
|
+
speechInput: chunk,
|
|
75
|
+
totalDurationInS: (performance.now() - createdAt) / 1e3,
|
|
76
|
+
detectionDelayInS: (Date.now() - overlapSpeechStartedAt) / 1e3,
|
|
77
|
+
predictionDurationInS
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
if (state.overlapSpeechStarted && entry.isInterruption) {
|
|
81
|
+
if (updateUserSpeakingSpan) {
|
|
82
|
+
updateUserSpeakingSpan(entry);
|
|
83
|
+
}
|
|
84
|
+
const event = {
|
|
85
|
+
type: "user_overlapping_speech",
|
|
86
|
+
timestamp: Date.now(),
|
|
87
|
+
overlapStartedAt: overlapSpeechStartedAt,
|
|
88
|
+
isInterruption: entry.isInterruption,
|
|
89
|
+
speechInput: entry.speechInput,
|
|
90
|
+
probabilities: entry.probabilities,
|
|
91
|
+
totalDurationInS: entry.totalDurationInS,
|
|
92
|
+
predictionDurationInS: entry.predictionDurationInS,
|
|
93
|
+
detectionDelayInS: entry.detectionDelayInS,
|
|
94
|
+
probability: entry.probability,
|
|
95
|
+
numRequests: (getAndResetNumRequests == null ? void 0 : getAndResetNumRequests()) ?? 0
|
|
96
|
+
};
|
|
97
|
+
logger.debug(
|
|
98
|
+
{
|
|
99
|
+
detectionDelayInS: entry.detectionDelayInS,
|
|
100
|
+
totalDurationInS: entry.totalDurationInS
|
|
101
|
+
},
|
|
102
|
+
"interruption detected"
|
|
103
|
+
);
|
|
104
|
+
setState({ overlapSpeechStarted: false });
|
|
105
|
+
controller.enqueue(event);
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
logger.error({ err }, "Failed to send audio data over HTTP");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{ highWaterMark: 2 },
|
|
113
|
+
{ highWaterMark: 2 }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
createHttpTransport,
|
|
118
|
+
predictEndpointResponseSchema,
|
|
119
|
+
predictHTTP
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=http_transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/http_transport.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ofetch } from 'ofetch';\nimport { TransformStream } from 'stream/web';\nimport { z } from 'zod';\nimport { log } from '../../log.js';\nimport { createAccessToken } from '../utils.js';\nimport { intervalForRetry } from './defaults.js';\nimport { InterruptionCacheEntry } from './interruption_cache_entry.js';\nimport type { OverlappingSpeechEvent } from './types.js';\nimport type { BoundedCache } from './utils.js';\n\nexport interface PostOptions {\n baseUrl: string;\n token: string;\n signal?: AbortSignal;\n timeout?: number;\n maxRetries?: number;\n}\n\nexport interface PredictOptions {\n threshold: number;\n minFrames: number;\n}\n\nexport const predictEndpointResponseSchema = z.object({\n created_at: z.number(),\n is_bargein: z.boolean(),\n probabilities: z.array(z.number()),\n});\n\nexport type PredictEndpointResponse = z.infer<typeof predictEndpointResponseSchema>;\n\nexport interface PredictResponse {\n createdAt: number;\n isBargein: boolean;\n probabilities: number[];\n predictionDurationInS: number;\n}\n\nexport async function predictHTTP(\n data: Int16Array,\n predictOptions: PredictOptions,\n options: PostOptions,\n): Promise<PredictResponse> {\n const createdAt = performance.now();\n const url = new URL(`/bargein`, options.baseUrl);\n url.searchParams.append('threshold', predictOptions.threshold.toString());\n url.searchParams.append('min_frames', predictOptions.minFrames.toFixed());\n url.searchParams.append('created_at', createdAt.toFixed());\n\n let retryCount = 0;\n const response = await ofetch(url.toString(), {\n retry: options.maxRetries ?? 3,\n retryDelay: () => {\n const delay = intervalForRetry(retryCount);\n retryCount++;\n return delay;\n },\n headers: {\n 'Content-Type': 'application/octet-stream',\n Authorization: `Bearer ${options.token}`,\n },\n signal: options.signal,\n timeout: options.timeout,\n method: 'POST',\n body: data,\n });\n const { created_at, is_bargein, probabilities } = predictEndpointResponseSchema.parse(response);\n\n return {\n createdAt: created_at,\n isBargein: is_bargein,\n probabilities,\n predictionDurationInS: (performance.now() - createdAt) / 1000,\n };\n}\n\nexport interface HttpTransportOptions {\n baseUrl: string;\n apiKey: string;\n apiSecret: string;\n threshold: number;\n minFrames: number;\n timeout: number;\n maxRetries?: number;\n}\n\nexport interface HttpTransportState {\n overlapSpeechStarted: boolean;\n overlapSpeechStartedAt: number | undefined;\n cache: BoundedCache<number, InterruptionCacheEntry>;\n}\n\n/**\n * Creates an HTTP transport TransformStream for interruption detection.\n *\n * This transport receives Int16Array audio slices and outputs InterruptionEvents.\n * Each audio slice triggers an HTTP POST request.\n *\n * @param options - Transport options object. This is read on each request, so mutations\n * to threshold/minFrames will be picked up dynamically.\n */\nexport function createHttpTransport(\n options: HttpTransportOptions,\n getState: () => HttpTransportState,\n setState: (partial: Partial<HttpTransportState>) => void,\n updateUserSpeakingSpan?: (entry: InterruptionCacheEntry) => void,\n getAndResetNumRequests?: () => number,\n): TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent> {\n const logger = log();\n\n return new TransformStream<Int16Array | OverlappingSpeechEvent, OverlappingSpeechEvent>(\n {\n async transform(chunk, controller) {\n if (!(chunk instanceof Int16Array)) {\n controller.enqueue(chunk);\n return;\n }\n\n const state = getState();\n const overlapSpeechStartedAt = state.overlapSpeechStartedAt;\n if (overlapSpeechStartedAt === undefined || !state.overlapSpeechStarted) return;\n\n try {\n const resp = await predictHTTP(\n chunk,\n { threshold: options.threshold, minFrames: options.minFrames },\n {\n baseUrl: options.baseUrl,\n timeout: options.timeout,\n maxRetries: options.maxRetries,\n token: await createAccessToken(options.apiKey, options.apiSecret),\n },\n );\n\n const { createdAt, isBargein, probabilities, predictionDurationInS } = resp;\n const entry = state.cache.setOrUpdate(\n createdAt,\n () => new InterruptionCacheEntry({ createdAt }),\n {\n probabilities,\n isInterruption: isBargein,\n speechInput: chunk,\n totalDurationInS: (performance.now() - createdAt) / 1000,\n detectionDelayInS: (Date.now() - overlapSpeechStartedAt) / 1000,\n predictionDurationInS,\n },\n );\n\n if (state.overlapSpeechStarted && entry.isInterruption) {\n if (updateUserSpeakingSpan) {\n updateUserSpeakingSpan(entry);\n }\n const event: OverlappingSpeechEvent = {\n type: 'user_overlapping_speech',\n timestamp: Date.now(),\n overlapStartedAt: overlapSpeechStartedAt,\n isInterruption: entry.isInterruption,\n speechInput: entry.speechInput,\n probabilities: entry.probabilities,\n totalDurationInS: entry.totalDurationInS,\n predictionDurationInS: entry.predictionDurationInS,\n detectionDelayInS: entry.detectionDelayInS,\n probability: entry.probability,\n numRequests: getAndResetNumRequests?.() ?? 0,\n };\n logger.debug(\n {\n detectionDelayInS: entry.detectionDelayInS,\n totalDurationInS: entry.totalDurationInS,\n },\n 'interruption detected',\n );\n setState({ overlapSpeechStarted: false });\n controller.enqueue(event);\n }\n } catch (err) {\n logger.error({ err }, 'Failed to send audio data over HTTP');\n }\n },\n },\n { highWaterMark: 2 },\n { highWaterMark: 2 },\n );\n}\n"],"mappings":"AAGA,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAClB,SAAS,WAAW;AACpB,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AAiBhC,MAAM,gCAAgC,EAAE,OAAO;AAAA,EACpD,YAAY,EAAE,OAAO;AAAA,EACrB,YAAY,EAAE,QAAQ;AAAA,EACtB,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC;AACnC,CAAC;AAWD,eAAsB,YACpB,MACA,gBACA,SAC0B;AAC1B,QAAM,YAAY,YAAY,IAAI;AAClC,QAAM,MAAM,IAAI,IAAI,YAAY,QAAQ,OAAO;AAC/C,MAAI,aAAa,OAAO,aAAa,eAAe,UAAU,SAAS,CAAC;AACxE,MAAI,aAAa,OAAO,cAAc,eAAe,UAAU,QAAQ,CAAC;AACxE,MAAI,aAAa,OAAO,cAAc,UAAU,QAAQ,CAAC;AAEzD,MAAI,aAAa;AACjB,QAAM,WAAW,MAAM,OAAO,IAAI,SAAS,GAAG;AAAA,IAC5C,OAAO,QAAQ,cAAc;AAAA,IAC7B,YAAY,MAAM;AAChB,YAAM,QAAQ,iBAAiB,UAAU;AACzC;AACA,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,eAAe,UAAU,QAAQ,KAAK;AAAA,IACxC;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB,SAAS,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,MAAM;AAAA,EACR,CAAC;AACD,QAAM,EAAE,YAAY,YAAY,cAAc,IAAI,8BAA8B,MAAM,QAAQ;AAE9F,SAAO;AAAA,IACL,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,IACA,wBAAwB,YA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BAAkB,MAAM;AAAA,cACxB,uBAAuB,MAAM;AAAA,cAC7B,mBAAmB,MAAM;AAAA,cACzB,aAAa,MAAM;AAAA,cACnB,cAAa,uEAA8B;AAAA,YAC7C;AACA,mBAAO;AAAA,cACL;AAAA,gBACE,mBAAmB,MAAM;AAAA,gBACzB,kBAAkB,MAAM;AAAA,cAC1B;AAAA,cACA;AAAA,YACF;AACA,qBAAS,EAAE,sBAAsB,MAAM,CAAC;AACxC,uBAAW,QAAQ,KAAK;AAAA,UAC1B;AAAA,QACF,SAAS,KAAK;AACZ,iBAAO,MAAM,EAAE,IAAI,GAAG,qCAAqC;AAAA,QAC7D;AAAA,MACF;AAAA,IACF;AAAA,IACA,EAAE,eAAe,EAAE;AAAA,IACnB,EAAE,eAAe,EAAE;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var interruption_cache_entry_exports = {};
|
|
20
|
+
__export(interruption_cache_entry_exports, {
|
|
21
|
+
InterruptionCacheEntry: () => InterruptionCacheEntry
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(interruption_cache_entry_exports);
|
|
24
|
+
var import_utils = require("./utils.cjs");
|
|
25
|
+
class InterruptionCacheEntry {
|
|
26
|
+
createdAt;
|
|
27
|
+
requestStartedAt;
|
|
28
|
+
totalDurationInS;
|
|
29
|
+
predictionDurationInS;
|
|
30
|
+
detectionDelayInS;
|
|
31
|
+
speechInput;
|
|
32
|
+
probabilities;
|
|
33
|
+
isInterruption;
|
|
34
|
+
constructor(params) {
|
|
35
|
+
this.createdAt = params.createdAt;
|
|
36
|
+
this.requestStartedAt = params.requestStartedAt;
|
|
37
|
+
this.totalDurationInS = params.totalDurationInS ?? 0;
|
|
38
|
+
this.predictionDurationInS = params.predictionDurationInS ?? 0;
|
|
39
|
+
this.detectionDelayInS = params.detectionDelayInS ?? 0;
|
|
40
|
+
this.speechInput = params.speechInput;
|
|
41
|
+
this.probabilities = params.probabilities;
|
|
42
|
+
this.isInterruption = params.isInterruption;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The conservative estimated probability of the interruption event.
|
|
46
|
+
*/
|
|
47
|
+
get probability() {
|
|
48
|
+
return this.probabilities ? (0, import_utils.estimateProbability)(this.probabilities) : 0;
|
|
49
|
+
}
|
|
50
|
+
static default() {
|
|
51
|
+
return new InterruptionCacheEntry({ createdAt: 0 });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
InterruptionCacheEntry
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=interruption_cache_entry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/interruption_cache_entry.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { estimateProbability } from './utils.js';\n\n/**\n * Typed cache entry for interruption inference results.\n * Mutable to support setOrUpdate pattern from Python's _BoundedCache.\n */\nexport class InterruptionCacheEntry {\n createdAt: number;\n requestStartedAt?: number;\n totalDurationInS: number;\n predictionDurationInS: number;\n detectionDelayInS: number;\n speechInput?: Int16Array;\n probabilities?: number[];\n isInterruption?: boolean;\n\n constructor(params: {\n createdAt: number;\n requestStartedAt?: number;\n speechInput?: Int16Array;\n totalDurationInS?: number;\n predictionDurationInS?: number;\n detectionDelayInS?: number;\n probabilities?: number[];\n isInterruption?: boolean;\n }) {\n this.createdAt = params.createdAt;\n this.requestStartedAt = params.requestStartedAt;\n this.totalDurationInS = params.totalDurationInS ?? 0;\n this.predictionDurationInS = params.predictionDurationInS ?? 0;\n this.detectionDelayInS = params.detectionDelayInS ?? 0;\n this.speechInput = params.speechInput;\n this.probabilities = params.probabilities;\n this.isInterruption = params.isInterruption;\n }\n\n /**\n * The conservative estimated probability of the interruption event.\n */\n get probability(): number {\n return this.probabilities ? estimateProbability(this.probabilities) : 0;\n }\n\n static default(): InterruptionCacheEntry {\n return new InterruptionCacheEntry({ createdAt: 0 });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAoC;AAM7B,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,QAST;AACD,SAAK,YAAY,OAAO;AACxB,SAAK,mBAAmB,OAAO;AAC/B,SAAK,mBAAmB,OAAO,oBAAoB;AACnD,SAAK,wBAAwB,OAAO,yBAAyB;AAC7D,SAAK,oBAAoB,OAAO,qBAAqB;AACrD,SAAK,cAAc,OAAO;AAC1B,SAAK,gBAAgB,OAAO;AAC5B,SAAK,iBAAiB,OAAO;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,cAAsB;AACxB,WAAO,KAAK,oBAAgB,kCAAoB,KAAK,aAAa,IAAI;AAAA,EACxE;AAAA,EAEA,OAAO,UAAkC;AACvC,WAAO,IAAI,uBAAuB,EAAE,WAAW,EAAE,CAAC;AAAA,EACpD;AACF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed cache entry for interruption inference results.
|
|
3
|
+
* Mutable to support setOrUpdate pattern from Python's _BoundedCache.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InterruptionCacheEntry {
|
|
6
|
+
createdAt: number;
|
|
7
|
+
requestStartedAt?: number;
|
|
8
|
+
totalDurationInS: number;
|
|
9
|
+
predictionDurationInS: number;
|
|
10
|
+
detectionDelayInS: number;
|
|
11
|
+
speechInput?: Int16Array;
|
|
12
|
+
probabilities?: number[];
|
|
13
|
+
isInterruption?: boolean;
|
|
14
|
+
constructor(params: {
|
|
15
|
+
createdAt: number;
|
|
16
|
+
requestStartedAt?: number;
|
|
17
|
+
speechInput?: Int16Array;
|
|
18
|
+
totalDurationInS?: number;
|
|
19
|
+
predictionDurationInS?: number;
|
|
20
|
+
detectionDelayInS?: number;
|
|
21
|
+
probabilities?: number[];
|
|
22
|
+
isInterruption?: boolean;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The conservative estimated probability of the interruption event.
|
|
26
|
+
*/
|
|
27
|
+
get probability(): number;
|
|
28
|
+
static default(): InterruptionCacheEntry;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=interruption_cache_entry.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed cache entry for interruption inference results.
|
|
3
|
+
* Mutable to support setOrUpdate pattern from Python's _BoundedCache.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InterruptionCacheEntry {
|
|
6
|
+
createdAt: number;
|
|
7
|
+
requestStartedAt?: number;
|
|
8
|
+
totalDurationInS: number;
|
|
9
|
+
predictionDurationInS: number;
|
|
10
|
+
detectionDelayInS: number;
|
|
11
|
+
speechInput?: Int16Array;
|
|
12
|
+
probabilities?: number[];
|
|
13
|
+
isInterruption?: boolean;
|
|
14
|
+
constructor(params: {
|
|
15
|
+
createdAt: number;
|
|
16
|
+
requestStartedAt?: number;
|
|
17
|
+
speechInput?: Int16Array;
|
|
18
|
+
totalDurationInS?: number;
|
|
19
|
+
predictionDurationInS?: number;
|
|
20
|
+
detectionDelayInS?: number;
|
|
21
|
+
probabilities?: number[];
|
|
22
|
+
isInterruption?: boolean;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* The conservative estimated probability of the interruption event.
|
|
26
|
+
*/
|
|
27
|
+
get probability(): number;
|
|
28
|
+
static default(): InterruptionCacheEntry;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=interruption_cache_entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interruption_cache_entry.d.ts","sourceRoot":"","sources":["../../../src/inference/interruption/interruption_cache_entry.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,qBAAa,sBAAsB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;gBAEb,MAAM,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,UAAU,CAAC;QACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;QACzB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B;IAWD;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,MAAM,CAAC,OAAO,IAAI,sBAAsB;CAGzC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { estimateProbability } from "./utils.js";
|
|
2
|
+
class InterruptionCacheEntry {
|
|
3
|
+
createdAt;
|
|
4
|
+
requestStartedAt;
|
|
5
|
+
totalDurationInS;
|
|
6
|
+
predictionDurationInS;
|
|
7
|
+
detectionDelayInS;
|
|
8
|
+
speechInput;
|
|
9
|
+
probabilities;
|
|
10
|
+
isInterruption;
|
|
11
|
+
constructor(params) {
|
|
12
|
+
this.createdAt = params.createdAt;
|
|
13
|
+
this.requestStartedAt = params.requestStartedAt;
|
|
14
|
+
this.totalDurationInS = params.totalDurationInS ?? 0;
|
|
15
|
+
this.predictionDurationInS = params.predictionDurationInS ?? 0;
|
|
16
|
+
this.detectionDelayInS = params.detectionDelayInS ?? 0;
|
|
17
|
+
this.speechInput = params.speechInput;
|
|
18
|
+
this.probabilities = params.probabilities;
|
|
19
|
+
this.isInterruption = params.isInterruption;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The conservative estimated probability of the interruption event.
|
|
23
|
+
*/
|
|
24
|
+
get probability() {
|
|
25
|
+
return this.probabilities ? estimateProbability(this.probabilities) : 0;
|
|
26
|
+
}
|
|
27
|
+
static default() {
|
|
28
|
+
return new InterruptionCacheEntry({ createdAt: 0 });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
InterruptionCacheEntry
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=interruption_cache_entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/interruption_cache_entry.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { estimateProbability } from './utils.js';\n\n/**\n * Typed cache entry for interruption inference results.\n * Mutable to support setOrUpdate pattern from Python's _BoundedCache.\n */\nexport class InterruptionCacheEntry {\n createdAt: number;\n requestStartedAt?: number;\n totalDurationInS: number;\n predictionDurationInS: number;\n detectionDelayInS: number;\n speechInput?: Int16Array;\n probabilities?: number[];\n isInterruption?: boolean;\n\n constructor(params: {\n createdAt: number;\n requestStartedAt?: number;\n speechInput?: Int16Array;\n totalDurationInS?: number;\n predictionDurationInS?: number;\n detectionDelayInS?: number;\n probabilities?: number[];\n isInterruption?: boolean;\n }) {\n this.createdAt = params.createdAt;\n this.requestStartedAt = params.requestStartedAt;\n this.totalDurationInS = params.totalDurationInS ?? 0;\n this.predictionDurationInS = params.predictionDurationInS ?? 0;\n this.detectionDelayInS = params.detectionDelayInS ?? 0;\n this.speechInput = params.speechInput;\n this.probabilities = params.probabilities;\n this.isInterruption = params.isInterruption;\n }\n\n /**\n * The conservative estimated probability of the interruption event.\n */\n get probability(): number {\n return this.probabilities ? estimateProbability(this.probabilities) : 0;\n }\n\n static default(): InterruptionCacheEntry {\n return new InterruptionCacheEntry({ createdAt: 0 });\n }\n}\n"],"mappings":"AAGA,SAAS,2BAA2B;AAM7B,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,QAST;AACD,SAAK,YAAY,OAAO;AACxB,SAAK,mBAAmB,OAAO;AAC/B,SAAK,mBAAmB,OAAO,oBAAoB;AACnD,SAAK,wBAAwB,OAAO,yBAAyB;AAC7D,SAAK,oBAAoB,OAAO,qBAAqB;AACrD,SAAK,cAAc,OAAO;AAC1B,SAAK,gBAAgB,OAAO;AAC5B,SAAK,iBAAiB,OAAO;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,cAAsB;AACxB,WAAO,KAAK,gBAAgB,oBAAoB,KAAK,aAAa,IAAI;AAAA,EACxE;AAAA,EAEA,OAAO,UAAkC;AACvC,WAAO,IAAI,uBAAuB,EAAE,WAAW,EAAE,CAAC;AAAA,EACpD;AACF;","names":[]}
|