osborn 0.9.272 → 0.9.274
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/.claude/skills/browser-apply/SKILL.md +82 -30
- package/.claude/skills/browser-apply/candidate.example.env +16 -0
- package/.claude/skills/browser-apply/fill.mjs +294 -0
- package/Dockerfile +1 -1
- package/dist/claude-llm.d.ts +3 -0
- package/dist/claude-llm.js +84 -17
- package/dist/compaction-log.d.ts +67 -0
- package/dist/compaction-log.js +195 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.js +122 -65
- package/dist/content/transcript-sanitizer.d.ts +20 -6
- package/dist/content/transcript-sanitizer.js +66 -11
- package/dist/data-sender-auth.d.ts +90 -0
- package/dist/data-sender-auth.js +157 -0
- package/dist/env-keys.js +1 -0
- package/dist/index.js +350 -92
- package/dist/meeting-addressing.d.ts +176 -0
- package/dist/meeting-addressing.js +288 -0
- package/dist/pipeline-direct-llm.d.ts +27 -0
- package/dist/pipeline-direct-llm.js +117 -37
- package/dist/prompts/direct-mode-fallback.md +1 -1
- package/dist/prompts/direct-mode-research.md +2 -2
- package/dist/prompts.d.ts +1 -1
- package/dist/prompts.js +3 -3
- package/dist/recall-client.js +21 -2
- package/dist/session-store.d.ts +15 -5
- package/dist/session-store.js +37 -10
- package/dist/transcript-wiring.d.ts +121 -0
- package/dist/transcript-wiring.js +252 -0
- package/dist/voice-io.d.ts +0 -9
- package/dist/voice-io.js +5 -19
- package/package.json +1 -1
- package/scripts/review.ts +1 -1
package/dist/session-store.js
CHANGED
|
@@ -134,6 +134,7 @@ export function openStore(dbPath, opts) {
|
|
|
134
134
|
);
|
|
135
135
|
CREATE INDEX IF NOT EXISTS idx_content_source ON content(source);
|
|
136
136
|
CREATE INDEX IF NOT EXISTS idx_content_type ON content(msg_type);
|
|
137
|
+
CREATE INDEX IF NOT EXISTS idx_content_ts ON content(ts, id);
|
|
137
138
|
|
|
138
139
|
CREATE VIRTUAL TABLE IF NOT EXISTS fts USING fts5(text, content='');
|
|
139
140
|
|
|
@@ -181,6 +182,14 @@ function extractRecords(raw) {
|
|
|
181
182
|
// ── user (regular text OR tool_result wrapper) ──
|
|
182
183
|
if (type === 'user') {
|
|
183
184
|
const content = raw.message?.content;
|
|
185
|
+
// Plain-string content (CLI-typed prompts, SDK string-prompt turns, imported
|
|
186
|
+
// sessions) is a real user turn too; it used to be silently skipped, so those
|
|
187
|
+
// turns were missing from /session-messages and prior_messages (UI#11).
|
|
188
|
+
// Existing stores pick these up on their next rebuild (STORE_VERSION unchanged:
|
|
189
|
+
// a bump would wipe and re-embed every store).
|
|
190
|
+
if (typeof content === 'string') {
|
|
191
|
+
return content.trim() ? [{ msgType: 'user', model: null, toolName: null, text: content }] : [];
|
|
192
|
+
}
|
|
184
193
|
if (!Array.isArray(content))
|
|
185
194
|
return [];
|
|
186
195
|
if (content[0]?.type === 'tool_result') {
|
|
@@ -582,19 +591,37 @@ export async function recall(db, query, opts) {
|
|
|
582
591
|
return hits;
|
|
583
592
|
}
|
|
584
593
|
/**
|
|
585
|
-
* Return the most recent N content rows
|
|
586
|
-
*
|
|
587
|
-
*
|
|
594
|
+
* Return the most recent N content rows, newest first, as RecallHit-shaped objects.
|
|
595
|
+
* Powers fast-brain's "recent entries" path and the session tail. Encapsulates
|
|
596
|
+
* decompress so callers never touch the blob/compression.
|
|
588
597
|
* `msgTypes` optionally filters by msg_type IN SQL — so callers that only want
|
|
589
|
-
* user/assistant rows don't decompress rows they'd discard.
|
|
598
|
+
* user/assistant rows don't decompress rows they'd discard. `opts.sources`
|
|
599
|
+
* optionally restricts to given sources (e.g. ['main'] = the session's own JSONL,
|
|
600
|
+
* no sub-agent rows).
|
|
601
|
+
*
|
|
602
|
+
* Recency is by record TIMESTAMP (ts DESC), not insertion id: a backfill/reindex
|
|
603
|
+
* or a resume can insert older rows after newer ones, and "newest by id" then
|
|
604
|
+
* surfaced weeks-old turns (UI#16). id DESC breaks ties; rows with no ts sort
|
|
605
|
+
* last (SQLite NULLs are smallest). idx_content_ts(ts, id) serves the order. The ordering runs in a blob-free subquery so only the N kept rows
|
|
606
|
+
* carry their blob through the sort.
|
|
590
607
|
*/
|
|
591
|
-
export function recentRows(db, count, msgTypes) {
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
608
|
+
export function recentRows(db, count, msgTypes, opts) {
|
|
609
|
+
const where = [];
|
|
610
|
+
const params = [];
|
|
611
|
+
if (msgTypes && msgTypes.length) {
|
|
612
|
+
where.push(`msg_type IN (${msgTypes.map(() => '?').join(', ')})`);
|
|
613
|
+
params.push(...msgTypes);
|
|
614
|
+
}
|
|
615
|
+
if (opts?.sources && opts.sources.length) {
|
|
616
|
+
where.push(`source IN (${opts.sources.map(() => '?').join(', ')})`);
|
|
617
|
+
params.push(...opts.sources);
|
|
618
|
+
}
|
|
619
|
+
const filter = where.length ? `WHERE ${where.join(' AND ')}` : '';
|
|
620
|
+
params.push(Math.max(1, count));
|
|
621
|
+
const order = `ORDER BY ts DESC, id DESC`;
|
|
596
622
|
const rows = db.prepare(`SELECT id, source, line_num, byte_offset, ts, msg_type, model, git_branch, cwd, tool_name, blob
|
|
597
|
-
FROM content ${filter}
|
|
623
|
+
FROM content WHERE id IN (SELECT id FROM content ${filter} ${order} LIMIT ?)
|
|
624
|
+
${order}`).all(...params);
|
|
598
625
|
return rows.map((row) => ({
|
|
599
626
|
id: row.id,
|
|
600
627
|
source: row.source,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface SessionListSource {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
projectSlug: string;
|
|
4
|
+
projectPath: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
timestamp: Date;
|
|
7
|
+
lastMessage?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
messageCount: number;
|
|
10
|
+
firstTs?: string;
|
|
11
|
+
lastActivityAt?: string;
|
|
12
|
+
fileSize?: number;
|
|
13
|
+
}
|
|
14
|
+
/** The preview fields the dashboard / session browser receive per session. */
|
|
15
|
+
export declare function sessionListEntry(s: SessionListSource): {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
projectSlug: string;
|
|
18
|
+
projectPath: string;
|
|
19
|
+
cwd: string;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
lastMessage: string;
|
|
22
|
+
title: string;
|
|
23
|
+
messageCount: number;
|
|
24
|
+
firstTs: string;
|
|
25
|
+
lastActivityAt: string;
|
|
26
|
+
fileSize: number;
|
|
27
|
+
};
|
|
28
|
+
export interface HistoryRow {
|
|
29
|
+
msgType: string;
|
|
30
|
+
text: string;
|
|
31
|
+
ts?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface HistoryMessage {
|
|
34
|
+
role: 'user' | 'assistant';
|
|
35
|
+
content: string;
|
|
36
|
+
ts: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** Upper bound on rows read while topping up a page (sanitizer drops). */
|
|
39
|
+
export declare const HISTORY_MAX_FETCH = 2000;
|
|
40
|
+
/**
|
|
41
|
+
* Read up to `limit` clean messages, chronological. `fetchRows(n)` returns the
|
|
42
|
+
* newest `n` rows NEWEST-FIRST (recentRows' contract). Each row is sanitized
|
|
43
|
+
* with cleanTurnText first, then truncated to `maxChars`; dropped rows (pure
|
|
44
|
+
* notices, injected blocks, [SYSTEM] lines) are replaced by fetching more,
|
|
45
|
+
* starting at 3x and doubling, until the page is full, the store is exhausted
|
|
46
|
+
* (fewer rows than asked), or HISTORY_MAX_FETCH is reached.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cleanHistoryRows(fetchRows: (n: number) => HistoryRow[], limit: number, maxChars: number): HistoryMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* Echo-only guard: an injected open tag with no matching close after it is cut,
|
|
51
|
+
* together with everything after it to the end of the string. The shared
|
|
52
|
+
* sanitizer deliberately keeps an inline unterminated tag (a person can say
|
|
53
|
+
* "the <system-reminder> tag is noisy"), so this lives here, not in
|
|
54
|
+
* cleanTurnText: the echo is shown to everyone in the room and must never carry
|
|
55
|
+
* a half-injected block. Closed blocks are left for cleanTurnText.
|
|
56
|
+
*/
|
|
57
|
+
export declare function cutUnclosedInjected(text: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* The text to echo as `user_transcript`, or null to send nothing. Runs the
|
|
60
|
+
* shared sanitizer (drops [time:] tags, <session_tail>, [favorited] /
|
|
61
|
+
* [welcome-back] / [SCRIPT] / [PROACTIVE] / [NOTIFICATION] / [SYSTEM] notices,
|
|
62
|
+
* unwraps [INTERRUPTED]/[CONTEXT]), then the echo's own noise filters.
|
|
63
|
+
*/
|
|
64
|
+
export declare function userEchoText(raw: string, attachments?: string): string | null;
|
|
65
|
+
export interface TypedEcho {
|
|
66
|
+
/** The frontend's id for the optimistic bubble, when it sent one. */
|
|
67
|
+
clientMsgId?: string;
|
|
68
|
+
/** Attachment blocks the agent appended to the typed text ('' = none). */
|
|
69
|
+
attachments: string;
|
|
70
|
+
}
|
|
71
|
+
/** Valid clientMsgId or undefined (string, 1..200 chars). */
|
|
72
|
+
export declare function validClientMsgId(v: unknown): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Remembers typed messages (user_text) by their raw content so the session's
|
|
75
|
+
* echo of the same item (conversation_item_added → user_transcript) can carry
|
|
76
|
+
* the frontend's clientMsgId and keep its attachment blocks (the sanitizer
|
|
77
|
+
* strips trailing [File:]/[Image:] blocks, which the chat renders). Matches on
|
|
78
|
+
* the exact raw text first, then on the sanitized text. Entries expire after
|
|
79
|
+
* `ttlMs`; at most `max` are kept.
|
|
80
|
+
*/
|
|
81
|
+
export declare class TypedEchoTracker {
|
|
82
|
+
#private;
|
|
83
|
+
private ttlMs;
|
|
84
|
+
private max;
|
|
85
|
+
constructor(ttlMs?: number, max?: number);
|
|
86
|
+
register(rawContent: string, clientMsgId: unknown, attachments?: string, now?: number): void;
|
|
87
|
+
/** Consume and return the typed-message info for this echoed text, if any. */
|
|
88
|
+
take(rawEcho: string, now?: number): TypedEcho | undefined;
|
|
89
|
+
clear(): void;
|
|
90
|
+
get size(): number;
|
|
91
|
+
}
|
|
92
|
+
export interface FavoriteChange {
|
|
93
|
+
filePath: string;
|
|
94
|
+
fileName: string;
|
|
95
|
+
favorited: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Validate a favorite_changed payload; null when unusable. */
|
|
98
|
+
export declare function parseFavoriteChanged(data: any): FavoriteChange | null;
|
|
99
|
+
/**
|
|
100
|
+
* Backward compatibility: an older frontend sends the favorite as
|
|
101
|
+
* `user_text` "[time: …] [favorited] The user favorited the file NAME."
|
|
102
|
+
* Returns the change when `content` is exactly that notice, else null.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseLegacyFavoriteNotice(content: string): FavoriteChange | null;
|
|
105
|
+
/**
|
|
106
|
+
* Pending client notices for the agent, delivered as hidden context on the next
|
|
107
|
+
* real user turn (never as a user turn). Keyed by file path so a favorite then
|
|
108
|
+
* an unfavorite of the same file cancels out. The drained block is a
|
|
109
|
+
* <system-reminder>, which the shared sanitizer (lens-strip) removes from
|
|
110
|
+
* history, titles and echoes while keeping the user's own words.
|
|
111
|
+
*/
|
|
112
|
+
export declare class ClientNoteQueue {
|
|
113
|
+
#private;
|
|
114
|
+
private max;
|
|
115
|
+
constructor(max?: number);
|
|
116
|
+
favoriteChanged(raw: FavoriteChange): void;
|
|
117
|
+
get size(): number;
|
|
118
|
+
clear(): void;
|
|
119
|
+
/** Return the pending notes as one hidden-context block and clear them; '' when none. */
|
|
120
|
+
drain(): string;
|
|
121
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transcript-wiring.ts — pure helpers for the transcript paths in index.ts
|
|
3
|
+
* (lane L2b, agent side). Kept out of index.ts so they are unit-testable
|
|
4
|
+
* without booting the agent.
|
|
5
|
+
*
|
|
6
|
+
* - sessionListEntry: one mapping for `/sessions` and `sessions_list`
|
|
7
|
+
* (carries title / firstTs / lastActivityAt).
|
|
8
|
+
* - cleanHistoryRows: `/session-messages` + `prior_messages`: sanitize
|
|
9
|
+
* with cleanTurnText BEFORE truncating, over-fetch so
|
|
10
|
+
* rows dropped by the sanitizer do not shrink the page.
|
|
11
|
+
* - userEchoText: the user_transcript echo text, sanitized.
|
|
12
|
+
* - TypedEchoTracker: carries a typed message's clientMsgId onto its echo.
|
|
13
|
+
* - ClientNoteQueue: out-of-band client notices (favorite_changed) that
|
|
14
|
+
* ride the NEXT real user turn as hidden context
|
|
15
|
+
* instead of becoming a user turn themselves.
|
|
16
|
+
*/
|
|
17
|
+
import { cleanTurnText } from './content/transcript-sanitizer.js';
|
|
18
|
+
/** The preview fields the dashboard / session browser receive per session. */
|
|
19
|
+
export function sessionListEntry(s) {
|
|
20
|
+
return {
|
|
21
|
+
sessionId: s.sessionId,
|
|
22
|
+
projectSlug: s.projectSlug,
|
|
23
|
+
projectPath: s.projectPath,
|
|
24
|
+
cwd: s.cwd,
|
|
25
|
+
timestamp: s.timestamp.toISOString(),
|
|
26
|
+
lastMessage: s.lastMessage,
|
|
27
|
+
title: s.title,
|
|
28
|
+
messageCount: s.messageCount,
|
|
29
|
+
firstTs: s.firstTs,
|
|
30
|
+
lastActivityAt: s.lastActivityAt,
|
|
31
|
+
fileSize: s.fileSize,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Upper bound on rows read while topping up a page (sanitizer drops). */
|
|
35
|
+
export const HISTORY_MAX_FETCH = 2000;
|
|
36
|
+
/**
|
|
37
|
+
* Read up to `limit` clean messages, chronological. `fetchRows(n)` returns the
|
|
38
|
+
* newest `n` rows NEWEST-FIRST (recentRows' contract). Each row is sanitized
|
|
39
|
+
* with cleanTurnText first, then truncated to `maxChars`; dropped rows (pure
|
|
40
|
+
* notices, injected blocks, [SYSTEM] lines) are replaced by fetching more,
|
|
41
|
+
* starting at 3x and doubling, until the page is full, the store is exhausted
|
|
42
|
+
* (fewer rows than asked), or HISTORY_MAX_FETCH is reached.
|
|
43
|
+
*/
|
|
44
|
+
export function cleanHistoryRows(fetchRows, limit, maxChars) {
|
|
45
|
+
const want = Math.max(1, Math.floor(limit) || 1);
|
|
46
|
+
let n = Math.min(want * 3, HISTORY_MAX_FETCH);
|
|
47
|
+
for (;;) {
|
|
48
|
+
const rows = fetchRows(n);
|
|
49
|
+
const kept = [];
|
|
50
|
+
for (const r of rows) {
|
|
51
|
+
const role = r.msgType === 'assistant' ? 'assistant' : 'user';
|
|
52
|
+
const clean = cleanTurnText(r.text || '', role);
|
|
53
|
+
if (!clean)
|
|
54
|
+
continue;
|
|
55
|
+
kept.push({ role, content: clean.slice(0, maxChars), ts: r.ts || null });
|
|
56
|
+
if (kept.length >= want)
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
const exhausted = rows.length < n || n >= HISTORY_MAX_FETCH;
|
|
60
|
+
if (kept.length >= want || exhausted)
|
|
61
|
+
return kept.reverse(); // newest-first → chronological
|
|
62
|
+
n = Math.min(n * 2, HISTORY_MAX_FETCH);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// ── user_transcript echo ───────────────────────────────────────────────────
|
|
66
|
+
/** Injected-block tags whose UNCLOSED open tag must not reach the echo. */
|
|
67
|
+
const ECHO_INJECTED_TAGS = ['system-reminder', 'session_tail', 'task-notification', 'recalled_context', 'user-prompt-submit-hook'];
|
|
68
|
+
/**
|
|
69
|
+
* Echo-only guard: an injected open tag with no matching close after it is cut,
|
|
70
|
+
* together with everything after it to the end of the string. The shared
|
|
71
|
+
* sanitizer deliberately keeps an inline unterminated tag (a person can say
|
|
72
|
+
* "the <system-reminder> tag is noisy"), so this lives here, not in
|
|
73
|
+
* cleanTurnText: the echo is shown to everyone in the room and must never carry
|
|
74
|
+
* a half-injected block. Closed blocks are left for cleanTurnText.
|
|
75
|
+
*/
|
|
76
|
+
export function cutUnclosedInjected(text) {
|
|
77
|
+
let out = text;
|
|
78
|
+
for (let changed = true; changed;) {
|
|
79
|
+
changed = false;
|
|
80
|
+
for (const tag of ECHO_INJECTED_TAGS) {
|
|
81
|
+
const open = new RegExp(`<${tag}\\b[^>]*>`, 'gi');
|
|
82
|
+
let last = null;
|
|
83
|
+
for (let m = open.exec(out); m; m = open.exec(out))
|
|
84
|
+
last = m;
|
|
85
|
+
if (!last)
|
|
86
|
+
continue;
|
|
87
|
+
const rest = out.slice(last.index + last[0].length);
|
|
88
|
+
if (new RegExp(`</${tag}\\s*>`, 'i').test(rest))
|
|
89
|
+
continue;
|
|
90
|
+
out = out.slice(0, last.index);
|
|
91
|
+
changed = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The text to echo as `user_transcript`, or null to send nothing. Runs the
|
|
98
|
+
* shared sanitizer (drops [time:] tags, <session_tail>, [favorited] /
|
|
99
|
+
* [welcome-back] / [SCRIPT] / [PROACTIVE] / [NOTIFICATION] / [SYSTEM] notices,
|
|
100
|
+
* unwraps [INTERRUPTED]/[CONTEXT]), then the echo's own noise filters.
|
|
101
|
+
*/
|
|
102
|
+
export function userEchoText(raw, attachments = '') {
|
|
103
|
+
if (!raw || typeof raw !== 'string')
|
|
104
|
+
return null;
|
|
105
|
+
let clean = cleanTurnText(cutUnclosedInjected(raw), 'user');
|
|
106
|
+
if (clean) {
|
|
107
|
+
const normalized = clean.replace(/\s+/g, ' ');
|
|
108
|
+
if (clean.length < 3 || normalized === '<noise>' || normalized.toLowerCase() === 'thank you')
|
|
109
|
+
clean = null;
|
|
110
|
+
}
|
|
111
|
+
// A typed message keeps its attachment blocks (the chat renders them).
|
|
112
|
+
const att = attachments.trim();
|
|
113
|
+
if (att)
|
|
114
|
+
return clean ? `${clean}\n\n${att}` : att;
|
|
115
|
+
return clean;
|
|
116
|
+
}
|
|
117
|
+
/** Valid clientMsgId or undefined (string, 1..200 chars). */
|
|
118
|
+
export function validClientMsgId(v) {
|
|
119
|
+
return typeof v === 'string' && v.length > 0 && v.length <= 200 ? v : undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Remembers typed messages (user_text) by their raw content so the session's
|
|
123
|
+
* echo of the same item (conversation_item_added → user_transcript) can carry
|
|
124
|
+
* the frontend's clientMsgId and keep its attachment blocks (the sanitizer
|
|
125
|
+
* strips trailing [File:]/[Image:] blocks, which the chat renders). Matches on
|
|
126
|
+
* the exact raw text first, then on the sanitized text. Entries expire after
|
|
127
|
+
* `ttlMs`; at most `max` are kept.
|
|
128
|
+
*/
|
|
129
|
+
export class TypedEchoTracker {
|
|
130
|
+
ttlMs;
|
|
131
|
+
max;
|
|
132
|
+
#items = [];
|
|
133
|
+
constructor(ttlMs = 60_000, max = 20) {
|
|
134
|
+
this.ttlMs = ttlMs;
|
|
135
|
+
this.max = max;
|
|
136
|
+
}
|
|
137
|
+
register(rawContent, clientMsgId, attachments = '', now = Date.now()) {
|
|
138
|
+
const id = validClientMsgId(clientMsgId);
|
|
139
|
+
if (!id && !attachments.trim())
|
|
140
|
+
return;
|
|
141
|
+
this.#prune(now);
|
|
142
|
+
this.#items.push({
|
|
143
|
+
raw: rawContent,
|
|
144
|
+
clean: cleanTurnText(rawContent, 'user'),
|
|
145
|
+
echo: { ...(id ? { clientMsgId: id } : {}), attachments: attachments.trim() },
|
|
146
|
+
at: now,
|
|
147
|
+
});
|
|
148
|
+
if (this.#items.length > this.max)
|
|
149
|
+
this.#items.splice(0, this.#items.length - this.max);
|
|
150
|
+
}
|
|
151
|
+
/** Consume and return the typed-message info for this echoed text, if any. */
|
|
152
|
+
take(rawEcho, now = Date.now()) {
|
|
153
|
+
this.#prune(now);
|
|
154
|
+
let i = this.#items.findIndex((e) => e.raw === rawEcho);
|
|
155
|
+
if (i < 0) {
|
|
156
|
+
const clean = cleanTurnText(rawEcho, 'user');
|
|
157
|
+
if (clean)
|
|
158
|
+
i = this.#items.findIndex((e) => e.clean === clean);
|
|
159
|
+
}
|
|
160
|
+
if (i < 0)
|
|
161
|
+
return undefined;
|
|
162
|
+
const [hit] = this.#items.splice(i, 1);
|
|
163
|
+
return hit.echo;
|
|
164
|
+
}
|
|
165
|
+
clear() { this.#items = []; }
|
|
166
|
+
get size() { return this.#items.length; }
|
|
167
|
+
#prune(now) {
|
|
168
|
+
this.#items = this.#items.filter((e) => now - e.at <= this.ttlMs);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** Validate a favorite_changed payload; null when unusable. */
|
|
172
|
+
export function parseFavoriteChanged(data) {
|
|
173
|
+
if (!data || typeof data !== 'object')
|
|
174
|
+
return null;
|
|
175
|
+
const fileName = typeof data.fileName === 'string' ? data.fileName.trim().slice(0, 300) : '';
|
|
176
|
+
const filePath = typeof data.filePath === 'string' ? data.filePath.trim().slice(0, 1000) : '';
|
|
177
|
+
if (!fileName && !filePath)
|
|
178
|
+
return null;
|
|
179
|
+
if (typeof data.favorited !== 'boolean')
|
|
180
|
+
return null;
|
|
181
|
+
return { filePath: filePath || fileName, fileName: fileName || filePath.split('/').pop() || filePath, favorited: data.favorited };
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Backward compatibility: an older frontend sends the favorite as
|
|
185
|
+
* `user_text` "[time: …] [favorited] The user favorited the file NAME."
|
|
186
|
+
* Returns the change when `content` is exactly that notice, else null.
|
|
187
|
+
*/
|
|
188
|
+
export function parseLegacyFavoriteNotice(content) {
|
|
189
|
+
if (typeof content !== 'string')
|
|
190
|
+
return null;
|
|
191
|
+
const body = content.replace(/^\s*\[time:[^\]]*\]\s*/, '');
|
|
192
|
+
const m = body.match(/^\[favorited\]\s*The user favorited the file (.+?)\.?\s*$/s);
|
|
193
|
+
if (!m)
|
|
194
|
+
return null;
|
|
195
|
+
const name = m[1].trim();
|
|
196
|
+
if (!name || name.includes('\n'))
|
|
197
|
+
return null;
|
|
198
|
+
return { filePath: name, fileName: name, favorited: true };
|
|
199
|
+
}
|
|
200
|
+
/** A client string made safe to sit inside a <system-reminder> line: no `<`, `>`, CR or LF. */
|
|
201
|
+
function noteSafe(s) {
|
|
202
|
+
return typeof s === 'string' ? s.replace(/[<>\r\n]/g, '').trim() : '';
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Pending client notices for the agent, delivered as hidden context on the next
|
|
206
|
+
* real user turn (never as a user turn). Keyed by file path so a favorite then
|
|
207
|
+
* an unfavorite of the same file cancels out. The drained block is a
|
|
208
|
+
* <system-reminder>, which the shared sanitizer (lens-strip) removes from
|
|
209
|
+
* history, titles and echoes while keeping the user's own words.
|
|
210
|
+
*/
|
|
211
|
+
export class ClientNoteQueue {
|
|
212
|
+
max;
|
|
213
|
+
#favorites = new Map();
|
|
214
|
+
constructor(max = 20) {
|
|
215
|
+
this.max = max;
|
|
216
|
+
}
|
|
217
|
+
favoriteChanged(raw) {
|
|
218
|
+
// Client-supplied names land inside a <system-reminder> block: strip
|
|
219
|
+
// anything that could close/open a tag or start a new line.
|
|
220
|
+
const fileName = noteSafe(raw.fileName);
|
|
221
|
+
const filePath = noteSafe(raw.filePath) || fileName;
|
|
222
|
+
if (!filePath)
|
|
223
|
+
return;
|
|
224
|
+
const change = { filePath, fileName: fileName || filePath, favorited: raw.favorited };
|
|
225
|
+
this.#favorites.delete(change.filePath);
|
|
226
|
+
// Un-favoriting stays silent (as before): it only cancels a pending note.
|
|
227
|
+
if (!change.favorited)
|
|
228
|
+
return;
|
|
229
|
+
this.#favorites.set(change.filePath, change);
|
|
230
|
+
while (this.#favorites.size > this.max) {
|
|
231
|
+
const oldest = this.#favorites.keys().next().value;
|
|
232
|
+
if (oldest === undefined)
|
|
233
|
+
break;
|
|
234
|
+
this.#favorites.delete(oldest);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
get size() { return this.#favorites.size; }
|
|
238
|
+
clear() { this.#favorites.clear(); }
|
|
239
|
+
/** Return the pending notes as one hidden-context block and clear them; '' when none. */
|
|
240
|
+
drain() {
|
|
241
|
+
if (this.#favorites.size === 0)
|
|
242
|
+
return '';
|
|
243
|
+
const lines = [...this.#favorites.values()].map((f) => `[favorited] The user favorited the file ${f.fileName}${f.filePath !== f.fileName ? ` (${f.filePath})` : ''}.`);
|
|
244
|
+
this.#favorites.clear();
|
|
245
|
+
return [
|
|
246
|
+
'<system-reminder>',
|
|
247
|
+
'Client notices since the last turn (UI actions, not something the user said; no reply needed unless relevant):',
|
|
248
|
+
...lines,
|
|
249
|
+
'</system-reminder>',
|
|
250
|
+
].join('\n');
|
|
251
|
+
}
|
|
252
|
+
}
|
package/dist/voice-io.d.ts
CHANGED
|
@@ -32,12 +32,3 @@ export declare function createSTT(config: STTConfig): soniox.STT | deepgram.STT
|
|
|
32
32
|
* Create TTS (Text-to-Speech) instance based on config
|
|
33
33
|
*/
|
|
34
34
|
export declare function createTTS(config: TTSConfig): any;
|
|
35
|
-
/**
|
|
36
|
-
* Create VAD (Voice Activity Detection) for turn detection
|
|
37
|
-
*
|
|
38
|
-
* Tuned to prevent:
|
|
39
|
-
* - "Audio file is too short" errors from STT (OpenAI requires >= 0.1s)
|
|
40
|
-
* - Split sentences when user pauses briefly mid-speech
|
|
41
|
-
* - False triggers from ambient noise
|
|
42
|
-
*/
|
|
43
|
-
export declare function createVAD(): Promise<import("@livekit/agents").VAD>;
|
package/dist/voice-io.js
CHANGED
|
@@ -6,7 +6,6 @@ import * as deepgram from '@livekit/agents-plugin-deepgram';
|
|
|
6
6
|
import * as fishaudio from '@livekit/agents-plugin-fishaudio';
|
|
7
7
|
import * as openai from '@livekit/agents-plugin-openai';
|
|
8
8
|
import * as rime from '@livekit/agents-plugin-rime';
|
|
9
|
-
import * as silero from '@livekit/agents-plugin-silero';
|
|
10
9
|
import * as soniox from '@livekit/agents-plugin-soniox';
|
|
11
10
|
/**
|
|
12
11
|
* Create STT (Speech-to-Text) instance based on config
|
|
@@ -136,21 +135,8 @@ export function createTTS(config) {
|
|
|
136
135
|
}
|
|
137
136
|
return tts;
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* - Split sentences when user pauses briefly mid-speech
|
|
145
|
-
* - False triggers from ambient noise
|
|
146
|
-
*/
|
|
147
|
-
export async function createVAD() {
|
|
148
|
-
// VAD now only handles interruption detection — turn detection moved to Deepgram STT (server-side).
|
|
149
|
-
// Lighter settings = less local CPU from ONNX inference.
|
|
150
|
-
return silero.VAD.load({
|
|
151
|
-
minSpeechDuration: 0.4, // 400ms — quick interruption detection
|
|
152
|
-
minSilenceDuration: 1.2, // 1200ms — responsive
|
|
153
|
-
prefixPaddingDuration: 0.1,
|
|
154
|
-
activationThreshold: 0.85, // default — balanced for interruptions only
|
|
155
|
-
});
|
|
156
|
-
}
|
|
138
|
+
// createVAD (Silero ONNX) removed 2026-11-07 — it was DEAD CODE: zero call sites.
|
|
139
|
+
// The live website path uses Deepgram STT endpointing for turn detection AND
|
|
140
|
+
// interruption (see index.ts: "VAD (Silero ONNX) removed — caused 2-5s inference
|
|
141
|
+
// lag"); the meeting path uses the Recall speech webhook. The @livekit/agents-
|
|
142
|
+
// plugin-silero dep is kept only for the runtime version snapshot in index.ts.
|
package/package.json
CHANGED
package/scripts/review.ts
CHANGED
|
@@ -244,7 +244,7 @@ const brief = `# Osborn Prompt Review
|
|
|
244
244
|
|
|
245
245
|
## Raw session log
|
|
246
246
|
|
|
247
|
-
The following is the full untruncated terminal output from an \`npm run dev:logged\` session with Osborn, a voice AI
|
|
247
|
+
The following is the full untruncated terminal output from an \`npm run dev:logged\` session with Osborn, a voice AI engineer and thinking partner. Pattern guide:
|
|
248
248
|
|
|
249
249
|
- \`📝 User (conv_item, N chars): "..."\` / \`📝 Text (N chars): "..."\` — what the user said (voice) or typed (data channel)
|
|
250
250
|
- \`📥 [pipeline] chat() call #N (chars): "..."\` — pipeline-mode user turn entering the Claude SDK
|