getpatter 0.6.0 → 0.6.2

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.
@@ -0,0 +1,71 @@
1
+ import {
2
+ getLogger
3
+ } from "./chunk-MVOQFAEO.mjs";
4
+ import {
5
+ init_esm_shims
6
+ } from "./chunk-N565J3CF.mjs";
7
+
8
+ // src/services/barge-in-strategies.ts
9
+ init_esm_shims();
10
+ var MinWordsStrategy = class {
11
+ minWords;
12
+ useInterim;
13
+ constructor(options) {
14
+ if (!Number.isFinite(options.minWords) || options.minWords < 1) {
15
+ throw new Error(
16
+ `minWords must be >= 1 (got ${String(options.minWords)})`
17
+ );
18
+ }
19
+ this.minWords = Math.floor(options.minWords);
20
+ this.useInterim = options.useInterim ?? true;
21
+ }
22
+ evaluate(ctx) {
23
+ if (ctx.isInterim && !this.useInterim) {
24
+ return false;
25
+ }
26
+ const threshold = ctx.agentSpeaking ? this.minWords : 1;
27
+ const wordCount = (ctx.transcript ?? "").trim().split(/\s+/).filter(Boolean).length;
28
+ return wordCount >= threshold;
29
+ }
30
+ async reset() {
31
+ }
32
+ };
33
+ async function evaluateStrategies(strategies, ctx) {
34
+ if (!strategies || strategies.length === 0) {
35
+ return false;
36
+ }
37
+ const safeCtx = {
38
+ transcript: ctx.transcript ?? "",
39
+ isInterim: ctx.isInterim,
40
+ agentSpeaking: ctx.agentSpeaking
41
+ };
42
+ for (const strategy of strategies) {
43
+ try {
44
+ const result = await strategy.evaluate(safeCtx);
45
+ if (result === true) return true;
46
+ } catch (err) {
47
+ getLogger().warn(
48
+ `BargeInStrategy ${strategy.constructor?.name ?? "unknown"} threw; treating as 'do not confirm': ${String(err)}`
49
+ );
50
+ }
51
+ }
52
+ return false;
53
+ }
54
+ async function resetStrategies(strategies) {
55
+ for (const strategy of strategies) {
56
+ if (typeof strategy.reset !== "function") continue;
57
+ try {
58
+ await strategy.reset();
59
+ } catch (err) {
60
+ getLogger().debug(
61
+ `BargeInStrategy ${strategy.constructor?.name ?? "unknown"}.reset() threw: ${String(err)}`
62
+ );
63
+ }
64
+ }
65
+ }
66
+
67
+ export {
68
+ MinWordsStrategy,
69
+ evaluateStrategies,
70
+ resetStrategies
71
+ };