osborn 0.9.255 → 0.9.256
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/noise-gate.d.ts +11 -0
- package/dist/noise-gate.js +69 -7
- package/package.json +1 -1
package/dist/noise-gate.d.ts
CHANGED
|
@@ -38,12 +38,23 @@ export interface GateDrop {
|
|
|
38
38
|
verdict: GateVerdict;
|
|
39
39
|
ts: number;
|
|
40
40
|
}
|
|
41
|
+
/** Parse the classifier's raw reply: "label" or "label | ambient tag". Pure +
|
|
42
|
+
* exported so the regression suite can pin it without network. Unknown labels
|
|
43
|
+
* fail open to 'directed' (and then any tag is ignored — never cache ambient
|
|
44
|
+
* context off a forwarded utterance). */
|
|
45
|
+
export declare function parseGateResponse(raw: string): {
|
|
46
|
+
verdict: GateVerdict;
|
|
47
|
+
tag?: string;
|
|
48
|
+
};
|
|
41
49
|
declare class NoiseGate extends EventEmitter {
|
|
42
50
|
#private;
|
|
43
51
|
enabled: boolean;
|
|
44
52
|
reason: 'ui' | 'meeting' | null;
|
|
45
53
|
/** Turn the gate on/off. reason 'ui' = button, 'meeting' = meeting-mode auto-engage. */
|
|
46
54
|
setEnabled(on: boolean, reason?: 'ui' | 'meeting' | 'silence'): void;
|
|
55
|
+
noteAmbient(tag: string): void;
|
|
56
|
+
/** Live (unexpired) ambient memos as a prompt block; '' when none. */
|
|
57
|
+
getAmbientBlock(ttlMs?: number): string;
|
|
47
58
|
allowOnce(text: string): void;
|
|
48
59
|
/** True when this utterance should be triaged. Bracket-prefixed texts are
|
|
49
60
|
* synthetic ([MEETING/[SYSTEM/[INTERRUPTED templates), never raw user voice. */
|
package/dist/noise-gate.js
CHANGED
|
@@ -49,8 +49,31 @@ const GATE_SYSTEM_PROMPT = [
|
|
|
49
49
|
'',
|
|
50
50
|
'Bias: when the utterance plausibly relates to the current work context, prefer directed.',
|
|
51
51
|
'Short backchannels ("yeah", "okay", "mhm") during active assistant work are directed.',
|
|
52
|
-
'
|
|
52
|
+
'',
|
|
53
|
+
'AMBIENT TAGGING: when the utterance is clearly ambient media or a recurring other-speaker',
|
|
54
|
+
'source — song lyrics, movie/TV dialogue, a lecture, a driver/cashier conversation — append',
|
|
55
|
+
'a short source tag after the label, separated by " | ". Examples:',
|
|
56
|
+
' side_talk | music lyrics',
|
|
57
|
+
' side_talk | movie or tv audio',
|
|
58
|
+
' side_talk | lecture',
|
|
59
|
+
'The tag is cached and shown to you on future utterances ("Known ambient context") so',
|
|
60
|
+
'recurring sources get easier to filter. Omit the tag when unsure.',
|
|
61
|
+
'',
|
|
62
|
+
'Reply with the label (optionally "label | tag") and NOTHING else.',
|
|
53
63
|
].join('\n');
|
|
64
|
+
/** Parse the classifier's raw reply: "label" or "label | ambient tag". Pure +
|
|
65
|
+
* exported so the regression suite can pin it without network. Unknown labels
|
|
66
|
+
* fail open to 'directed' (and then any tag is ignored — never cache ambient
|
|
67
|
+
* context off a forwarded utterance). */
|
|
68
|
+
export function parseGateResponse(raw) {
|
|
69
|
+
const [head, ...rest] = String(raw || '').split('|');
|
|
70
|
+
const h = head.toLowerCase();
|
|
71
|
+
const verdict = h.includes('side_talk') || h.includes('side talk')
|
|
72
|
+
? 'side_talk'
|
|
73
|
+
: h.includes('ambiguous') ? 'ambiguous' : 'directed';
|
|
74
|
+
const tag = rest.join('|').trim().toLowerCase().replace(/[^a-z0-9 /_-]/g, '').slice(0, 48);
|
|
75
|
+
return verdict !== 'directed' && tag ? { verdict, tag } : { verdict };
|
|
76
|
+
}
|
|
54
77
|
class NoiseGate extends EventEmitter {
|
|
55
78
|
enabled = false;
|
|
56
79
|
reason = null;
|
|
@@ -88,6 +111,37 @@ class NoiseGate extends EventEmitter {
|
|
|
88
111
|
this.emit('state', { enabled: on, reason: on ? this.reason : reason });
|
|
89
112
|
}
|
|
90
113
|
}
|
|
114
|
+
// ── Ambient memory ─────────────────────────────────────────────────────────
|
|
115
|
+
// Short-lived, self-updating scratchpad of ambient sources the classifier has
|
|
116
|
+
// tagged (music, movie/TV, lecture, a recurring other speaker). Carried into
|
|
117
|
+
// every classify prompt so recurring sources get easier to filter; entries
|
|
118
|
+
// expire AMBIENT_TTL after last sighting (the user can start/stop media any
|
|
119
|
+
// time), capped at 8 so the prompt stays tiny.
|
|
120
|
+
#ambient = new Map();
|
|
121
|
+
noteAmbient(tag) {
|
|
122
|
+
if (!tag)
|
|
123
|
+
return;
|
|
124
|
+
const e = this.#ambient.get(tag);
|
|
125
|
+
this.#ambient.set(tag, { count: (e?.count ?? 0) + 1, lastAt: Date.now() });
|
|
126
|
+
if (this.#ambient.size > 8) {
|
|
127
|
+
const oldest = [...this.#ambient.entries()].sort((a, b) => a[1].lastAt - b[1].lastAt)[0];
|
|
128
|
+
if (oldest)
|
|
129
|
+
this.#ambient.delete(oldest[0]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Live (unexpired) ambient memos as a prompt block; '' when none. */
|
|
133
|
+
getAmbientBlock(ttlMs = Number(process.env.OSBORN_GATE_AMBIENT_TTL_MS || 10 * 60_000)) {
|
|
134
|
+
const now = Date.now();
|
|
135
|
+
for (const [k, v] of this.#ambient)
|
|
136
|
+
if (now - v.lastAt > ttlMs)
|
|
137
|
+
this.#ambient.delete(k);
|
|
138
|
+
if (this.#ambient.size === 0)
|
|
139
|
+
return '';
|
|
140
|
+
const lines = [...this.#ambient.entries()]
|
|
141
|
+
.sort((a, b) => b[1].lastAt - a[1].lastAt)
|
|
142
|
+
.map(([tag, v]) => `- ${tag} (seen ${v.count}x, last ${Math.round((now - v.lastAt) / 1000)}s ago)`);
|
|
143
|
+
return `Known ambient context (recently observed around the user):\n${lines.join('\n')}`;
|
|
144
|
+
}
|
|
91
145
|
// One-shot allowlist for tombstone recovery ("send anyway"): the resent text
|
|
92
146
|
// must pass the gate exactly once without re-triage.
|
|
93
147
|
#allowOnce = new Set();
|
|
@@ -143,6 +197,12 @@ class NoiseGate extends EventEmitter {
|
|
|
143
197
|
.slice(-GATE_CONTEXT_TURNS)
|
|
144
198
|
.map(t => `${t.role === 'user' ? 'USER' : 'ASSISTANT'}: ${String(t.content).slice(0, 300)}`)
|
|
145
199
|
.join('\n');
|
|
200
|
+
// Gate's own short-term memory: live ambient memos + a digest of recent
|
|
201
|
+
// drops, so recurring sources (same song, same lecture) stay consistent.
|
|
202
|
+
const ambientBlock = this.getAmbientBlock();
|
|
203
|
+
const recentDrops = this.#dropped.slice(-6)
|
|
204
|
+
.map(d => `- "${d.text.slice(0, 80)}"`)
|
|
205
|
+
.join('\n');
|
|
146
206
|
const controller = new AbortController();
|
|
147
207
|
const to = setTimeout(() => controller.abort(), GATE_TIMEOUT_MS);
|
|
148
208
|
const resp = await fetch(OPENROUTER_URL, {
|
|
@@ -151,7 +211,7 @@ class NoiseGate extends EventEmitter {
|
|
|
151
211
|
signal: controller.signal,
|
|
152
212
|
body: JSON.stringify({
|
|
153
213
|
model: GATE_MODEL,
|
|
154
|
-
max_tokens:
|
|
214
|
+
max_tokens: 16,
|
|
155
215
|
temperature: 0,
|
|
156
216
|
messages: [
|
|
157
217
|
{ role: 'system', content: GATE_SYSTEM_PROMPT },
|
|
@@ -160,6 +220,8 @@ class NoiseGate extends EventEmitter {
|
|
|
160
220
|
content: [
|
|
161
221
|
`Current work with the assistant:\n${ctx.activeWork || '(none known)'}`,
|
|
162
222
|
``,
|
|
223
|
+
...(ambientBlock ? [ambientBlock, ``] : []),
|
|
224
|
+
...(recentDrops ? [`Recently filtered as side_talk:\n${recentDrops}`, ``] : []),
|
|
163
225
|
`Recent conversation:\n${recent || '(none)'}`,
|
|
164
226
|
``,
|
|
165
227
|
`New utterance heard by the microphone:\n"${text}"`,
|
|
@@ -174,11 +236,11 @@ class NoiseGate extends EventEmitter {
|
|
|
174
236
|
if (!resp.ok)
|
|
175
237
|
return 'directed';
|
|
176
238
|
const data = await resp.json();
|
|
177
|
-
const raw = String(data?.choices?.[0]?.message?.content || '')
|
|
178
|
-
const verdict =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
console.log(`🚪 [gate] verdict=${verdict} (${Date.now() - started}ms) "${text.slice(0, 60)}"`);
|
|
239
|
+
const raw = String(data?.choices?.[0]?.message?.content || '');
|
|
240
|
+
const { verdict, tag } = parseGateResponse(raw);
|
|
241
|
+
if (tag)
|
|
242
|
+
this.noteAmbient(tag);
|
|
243
|
+
console.log(`🚪 [gate] verdict=${verdict}${tag ? ` [ambient: ${tag}]` : ''} (${Date.now() - started}ms) "${text.slice(0, 60)}"`);
|
|
182
244
|
return verdict;
|
|
183
245
|
}
|
|
184
246
|
catch (err) {
|