osborn 0.9.274 → 0.9.276
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/meetings/SKILL.md +1 -1
- package/dist/claude-auth.d.ts +93 -6
- package/dist/claude-auth.js +241 -27
- package/dist/claude-llm.d.ts +31 -1
- package/dist/claude-llm.js +147 -10
- package/dist/data-sender-auth.d.ts +1 -0
- package/dist/data-sender-auth.js +4 -0
- package/dist/duck.d.ts +8 -0
- package/dist/duck.js +59 -0
- package/dist/index.js +468 -123
- package/dist/lib/safe-artifact-path.d.ts +17 -0
- package/dist/lib/safe-artifact-path.js +129 -0
- package/dist/meeting-tts.d.ts +35 -0
- package/dist/meeting-tts.js +161 -0
- package/dist/pipeline-direct-llm.d.ts +36 -1
- package/dist/pipeline-direct-llm.js +110 -24
- package/dist/pipeline-fastbrain.d.ts +14 -0
- package/dist/pipeline-fastbrain.js +5 -3
- package/dist/prompts/direct-mode-research.md +2 -0
- package/dist/prompts.d.ts +1 -1
- package/dist/prompts.js +3 -0
- package/dist/session-switch.d.ts +151 -0
- package/dist/session-switch.js +188 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ArtifactRoot = 'osb' | 'osbornSessions' | 'osbornResearch' | 'plans';
|
|
2
|
+
/**
|
|
3
|
+
* Default root set for the session-workspace read + write gates. Mirrors the
|
|
4
|
+
* roots the old substring checks intended: the per-session `/osb/` workspace
|
|
5
|
+
* plus the two legacy `.osborn/` locations. (`plans` is opt-in — only the plan
|
|
6
|
+
* read handler allows it.)
|
|
7
|
+
*/
|
|
8
|
+
export declare const WORKSPACE_ROOTS: ArtifactRoot[];
|
|
9
|
+
/**
|
|
10
|
+
* True iff `filePath` resolves to a location strictly inside one of the
|
|
11
|
+
* `allowed` roots. Rejects null bytes, `..` traversal and absolute escapes
|
|
12
|
+
* implicitly via the resolve()+canonicalize()+prefix test — never a substring.
|
|
13
|
+
*
|
|
14
|
+
* @param filePath caller-supplied path (may be relative or not-yet-existing)
|
|
15
|
+
* @param allowed which roots to accept (defaults to the workspace roots)
|
|
16
|
+
*/
|
|
17
|
+
export declare function isSafeArtifactPath(filePath: string, allowed?: ArtifactRoot[]): boolean;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Robust path validation for the artifact read gate and the write /
|
|
3
|
+
* auto-approve permission gates.
|
|
4
|
+
*
|
|
5
|
+
* ── Why this exists ─────────────────────────────────────────────────────────
|
|
6
|
+
* The pre-existing gates tested membership with a SUBSTRING check, e.g.
|
|
7
|
+
* filePath.includes('/osb/')
|
|
8
|
+
* filePath.includes('.osborn/sessions/')
|
|
9
|
+
* filePath.includes('.osborn/research/')
|
|
10
|
+
* filePath.includes('.claude/plans/')
|
|
11
|
+
* A substring test is trivially defeated by `..` traversal: a path like
|
|
12
|
+
* /workspace/osb/../../../etc/passwd
|
|
13
|
+
* /tmp/osb/../../etc/passwd
|
|
14
|
+
* contains the literal substring "/osb/" yet RESOLVES to a file outside the
|
|
15
|
+
* workspace. The `get_research_artifact` / `get_plan_file` data-channel
|
|
16
|
+
* handlers are read-only and un-gated by owner/controller, so ANY room
|
|
17
|
+
* participant could use them to read + exfiltrate arbitrary files off the
|
|
18
|
+
* machine. The same weak test also gated write auto-approval, so a traversal
|
|
19
|
+
* path could widen which writes got approved without a prompt.
|
|
20
|
+
*
|
|
21
|
+
* ── The fix ─────────────────────────────────────────────────────────────────
|
|
22
|
+
* 1. resolve() the path — collapses `..`/`.` and makes it absolute.
|
|
23
|
+
* 2. Canonicalize symlinks on the deepest EXISTING ancestor (defeats a
|
|
24
|
+
* symlinked parent dir used to escape a root) while still accepting a
|
|
25
|
+
* not-yet-existing leaf (needed by the write/auto-approve gates, where the
|
|
26
|
+
* target file is about to be created).
|
|
27
|
+
* 3. Require the result to sit INSIDE an allowed root as a true path PREFIX
|
|
28
|
+
* (`resolved === root || resolved.startsWith(root + sep)`) — never a
|
|
29
|
+
* substring. `..`, absolute escapes and null bytes are rejected.
|
|
30
|
+
*/
|
|
31
|
+
import { realpathSync } from 'node:fs';
|
|
32
|
+
import { resolve, join, sep, dirname, basename, relative } from 'node:path';
|
|
33
|
+
import { homedir } from 'node:os';
|
|
34
|
+
/**
|
|
35
|
+
* Default root set for the session-workspace read + write gates. Mirrors the
|
|
36
|
+
* roots the old substring checks intended: the per-session `/osb/` workspace
|
|
37
|
+
* plus the two legacy `.osborn/` locations. (`plans` is opt-in — only the plan
|
|
38
|
+
* read handler allows it.)
|
|
39
|
+
*/
|
|
40
|
+
export const WORKSPACE_ROOTS = ['osb', 'osbornSessions', 'osbornResearch'];
|
|
41
|
+
function claudeConfigDir() {
|
|
42
|
+
return process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
|
|
43
|
+
}
|
|
44
|
+
function osbornHomeDir() {
|
|
45
|
+
// Matches how the rest of the agent locates ~/.osborn (homedir, with an
|
|
46
|
+
// OSBORN_HOME override). The legacy `.osborn/sessions|research` roots live
|
|
47
|
+
// here; no active code writes to them, but we honor the location for parity.
|
|
48
|
+
return (process.env.OSBORN_HOME || '').trim() || join(homedir(), '.osborn');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Canonicalize an already-absolute path. realpath the deepest existing
|
|
52
|
+
* ancestor (so a symlinked parent dir cannot be used to escape a root), then
|
|
53
|
+
* re-append the trailing not-yet-existing segments verbatim. Those trailing
|
|
54
|
+
* segments came out of resolve(), so they contain no `..` or `.` to re-open a
|
|
55
|
+
* traversal. On total failure returns the input unchanged (still absolute).
|
|
56
|
+
*/
|
|
57
|
+
function canonicalize(absPath) {
|
|
58
|
+
let cur = absPath;
|
|
59
|
+
const suffix = [];
|
|
60
|
+
// Bounded loop — dirname() strictly converges to the filesystem root.
|
|
61
|
+
for (let i = 0; i < 4096; i++) {
|
|
62
|
+
try {
|
|
63
|
+
const real = realpathSync(cur);
|
|
64
|
+
return suffix.length ? join(real, ...suffix) : real;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
const parent = dirname(cur);
|
|
68
|
+
if (parent === cur)
|
|
69
|
+
return absPath; // reached root, nothing resolved
|
|
70
|
+
suffix.unshift(basename(cur));
|
|
71
|
+
cur = parent;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return absPath;
|
|
75
|
+
}
|
|
76
|
+
/** True iff `resolved` (already canonical) is inside the canonicalized `root`. */
|
|
77
|
+
function isInside(resolved, root) {
|
|
78
|
+
const r = canonicalize(resolve(root));
|
|
79
|
+
return resolved === r || resolved.startsWith(r + sep);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* True iff `filePath` resolves to a location strictly inside one of the
|
|
83
|
+
* `allowed` roots. Rejects null bytes, `..` traversal and absolute escapes
|
|
84
|
+
* implicitly via the resolve()+canonicalize()+prefix test — never a substring.
|
|
85
|
+
*
|
|
86
|
+
* @param filePath caller-supplied path (may be relative or not-yet-existing)
|
|
87
|
+
* @param allowed which roots to accept (defaults to the workspace roots)
|
|
88
|
+
*/
|
|
89
|
+
export function isSafeArtifactPath(filePath, allowed = WORKSPACE_ROOTS) {
|
|
90
|
+
if (!filePath || typeof filePath !== 'string')
|
|
91
|
+
return false;
|
|
92
|
+
if (filePath.includes('\0'))
|
|
93
|
+
return false; // null byte — reject outright
|
|
94
|
+
let resolved;
|
|
95
|
+
try {
|
|
96
|
+
resolved = canonicalize(resolve(filePath));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
for (const root of allowed) {
|
|
102
|
+
if (root === 'osb') {
|
|
103
|
+
// ~/.claude/projects/<slug>/osb/<sessionId>/... (and the session-sharing
|
|
104
|
+
// index layout ~/.claude/projects/osb/<slug>/...). Require containment
|
|
105
|
+
// under ~/.claude/projects AND a real `osb` path COMPONENT — a `..` that
|
|
106
|
+
// climbed out of projects fails the prefix test; `osb` as a substring of
|
|
107
|
+
// some other name (e.g. `osbornish`) is not a component and fails too.
|
|
108
|
+
const projectsRoot = canonicalize(resolve(join(claudeConfigDir(), 'projects')));
|
|
109
|
+
if (resolved === projectsRoot || resolved.startsWith(projectsRoot + sep)) {
|
|
110
|
+
const rel = relative(projectsRoot, resolved);
|
|
111
|
+
if (rel && !rel.startsWith('..') && rel.split(sep).includes('osb'))
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (root === 'osbornSessions') {
|
|
116
|
+
if (isInside(resolved, join(osbornHomeDir(), 'sessions')))
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
else if (root === 'osbornResearch') {
|
|
120
|
+
if (isInside(resolved, join(osbornHomeDir(), 'research')))
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
else if (root === 'plans') {
|
|
124
|
+
if (isInside(resolved, join(claudeConfigDir(), 'plans')))
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type MeetingTtsProvider = 'soniox' | 'openai';
|
|
2
|
+
export type SniffedAudioFormat = 'mp3' | 'wav' | 'unknown';
|
|
3
|
+
export interface MeetingAudio {
|
|
4
|
+
audio: Buffer;
|
|
5
|
+
contentType: string;
|
|
6
|
+
format: 'mp3';
|
|
7
|
+
provider: MeetingTtsProvider;
|
|
8
|
+
}
|
|
9
|
+
export interface SynthOptions {
|
|
10
|
+
/** Voice override. Applied ONLY to the provider whose voice set it belongs to
|
|
11
|
+
* (an OpenAI voice name → openai, anything else → soniox); never to the other. */
|
|
12
|
+
voice?: string;
|
|
13
|
+
/** Total budget across all providers (default TOTAL_DEADLINE_MS). */
|
|
14
|
+
deadlineMs?: number;
|
|
15
|
+
env?: NodeJS.ProcessEnv;
|
|
16
|
+
fetchImpl?: typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
export declare const MEETING_AUDIO_CONTENT_TYPE = "audio/mpeg";
|
|
19
|
+
export declare const SONIOX_TTS_URL = "https://tts-rt.soniox.com/tts";
|
|
20
|
+
export declare const OPENAI_TTS_URL = "https://api.openai.com/v1/audio/speech";
|
|
21
|
+
export declare const SONIOX_TIMEOUT_MS = 8000;
|
|
22
|
+
export declare const TOTAL_DEADLINE_MS = 11000;
|
|
23
|
+
/** Identify audio by magic bytes: ID3 tag or an MPEG frame sync → mp3, RIFF → wav. */
|
|
24
|
+
export declare function sniffAudioFormat(buf: Buffer): SniffedAudioFormat;
|
|
25
|
+
/** Ordered list of providers to try, given the env. Empty → no voice. */
|
|
26
|
+
export declare function selectMeetingTtsProviders(env?: NodeJS.ProcessEnv): MeetingTtsProvider[];
|
|
27
|
+
/** Which provider a `?voice=` override is meant for. */
|
|
28
|
+
export declare function voiceOverrideTarget(voice: string): MeetingTtsProvider;
|
|
29
|
+
/**
|
|
30
|
+
* Synthesize `text` as MP3 for the meeting. Tries providers in
|
|
31
|
+
* selectMeetingTtsProviders order within a shared deadline. Never throws;
|
|
32
|
+
* returns null when no key is configured, every provider failed, or the
|
|
33
|
+
* deadline ran out.
|
|
34
|
+
*/
|
|
35
|
+
export declare function synthMeetingAudio(text: string, opts?: SynthOptions): Promise<MeetingAudio | null>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Meeting TTS — one-shot text → audio for the meeting bot.
|
|
2
|
+
//
|
|
3
|
+
// Two consumers:
|
|
4
|
+
// - synthMp3 (index.ts) → Recall native output_audio, which REQUIRES mp3.
|
|
5
|
+
// - GET /tts (index.ts) → meeting canvas, which decodes the bytes with
|
|
6
|
+
// AudioContext.decodeAudioData (mp3 is fine there too).
|
|
7
|
+
// So every provider is asked for MP3, and the returned bytes are sniffed: a
|
|
8
|
+
// response that is not actually MP3 counts as a failure (next provider).
|
|
9
|
+
//
|
|
10
|
+
// Provider order: Soniox REST (the main pipeline's default TTS) when
|
|
11
|
+
// SONIOX_API_KEY is set, then OpenAI only if OPENAI_API_KEY is set, then null.
|
|
12
|
+
// An explicit OSBORN_TTS_PROVIDER (soniox | openai) moves that provider to the
|
|
13
|
+
// front; the other one stays as a fallback so the meeting never goes silent
|
|
14
|
+
// just because the preferred provider is out of credit.
|
|
15
|
+
//
|
|
16
|
+
// Timing: Soniox gets at most SONIOX_TIMEOUT_MS, and the whole chain shares a
|
|
17
|
+
// TOTAL_DEADLINE_MS budget — the canvas aborts its /tts fetch at 12s.
|
|
18
|
+
export const MEETING_AUDIO_CONTENT_TYPE = 'audio/mpeg';
|
|
19
|
+
export const SONIOX_TTS_URL = 'https://tts-rt.soniox.com/tts';
|
|
20
|
+
export const OPENAI_TTS_URL = 'https://api.openai.com/v1/audio/speech';
|
|
21
|
+
export const SONIOX_TIMEOUT_MS = 8000;
|
|
22
|
+
export const TOTAL_DEADLINE_MS = 11000;
|
|
23
|
+
// Fallbacks when the pipeline TTS is not Soniox (mirrors config.ts defaults).
|
|
24
|
+
const SONIOX_DEFAULT_MODEL = 'tts-rt-v1';
|
|
25
|
+
const SONIOX_DEFAULT_VOICE = 'Victoria';
|
|
26
|
+
// Same speed as the pipeline's soniox.TTS (voice-io.ts) so both sound alike.
|
|
27
|
+
const SONIOX_SPEED = 0.9;
|
|
28
|
+
const OPENAI_DEFAULT_MODEL = 'tts-1-hd';
|
|
29
|
+
const OPENAI_DEFAULT_VOICE = 'fable';
|
|
30
|
+
const OPENAI_VOICES = new Set(['alloy', 'ash', 'ballad', 'coral', 'echo', 'fable', 'onyx', 'nova', 'sage', 'shimmer', 'verse']);
|
|
31
|
+
// Cloudflare in front of tts-rt.soniox.com rejects some default client UAs (error 1010).
|
|
32
|
+
const USER_AGENT = 'osborn-agent';
|
|
33
|
+
/** Identify audio by magic bytes: ID3 tag or an MPEG frame sync → mp3, RIFF → wav. */
|
|
34
|
+
export function sniffAudioFormat(buf) {
|
|
35
|
+
if (!buf || buf.length < 4)
|
|
36
|
+
return 'unknown';
|
|
37
|
+
if (buf[0] === 0x49 && buf[1] === 0x44 && buf[2] === 0x33)
|
|
38
|
+
return 'mp3'; // "ID3"
|
|
39
|
+
if (buf[0] === 0xff && (buf[1] & 0xe0) === 0xe0)
|
|
40
|
+
return 'mp3'; // frame sync 0xFFE?/0xFFF?
|
|
41
|
+
if (buf.subarray(0, 4).toString('latin1') === 'RIFF')
|
|
42
|
+
return 'wav';
|
|
43
|
+
return 'unknown';
|
|
44
|
+
}
|
|
45
|
+
/** Ordered list of providers to try, given the env. Empty → no voice. */
|
|
46
|
+
export function selectMeetingTtsProviders(env = process.env) {
|
|
47
|
+
const available = [];
|
|
48
|
+
if (env.SONIOX_API_KEY)
|
|
49
|
+
available.push('soniox');
|
|
50
|
+
if (env.OPENAI_API_KEY)
|
|
51
|
+
available.push('openai');
|
|
52
|
+
const preferred = env.OSBORN_TTS_PROVIDER;
|
|
53
|
+
if (preferred && available.includes(preferred)) {
|
|
54
|
+
return [preferred, ...available.filter((p) => p !== preferred)];
|
|
55
|
+
}
|
|
56
|
+
return available;
|
|
57
|
+
}
|
|
58
|
+
/** Which provider a `?voice=` override is meant for. */
|
|
59
|
+
export function voiceOverrideTarget(voice) {
|
|
60
|
+
return OPENAI_VOICES.has(voice.trim().toLowerCase()) ? 'openai' : 'soniox';
|
|
61
|
+
}
|
|
62
|
+
function sonioxModelVoice(env) {
|
|
63
|
+
// When the pipeline TTS is Soniox (the default), use the same OSBORN_TTS_*
|
|
64
|
+
// overrides getDirectConfig uses, so the bot sounds identical in both places.
|
|
65
|
+
if (!env.OSBORN_TTS_PROVIDER || env.OSBORN_TTS_PROVIDER === 'soniox') {
|
|
66
|
+
return { model: env.OSBORN_TTS_MODEL || SONIOX_DEFAULT_MODEL, voice: env.OSBORN_TTS_VOICE || SONIOX_DEFAULT_VOICE };
|
|
67
|
+
}
|
|
68
|
+
return { model: SONIOX_DEFAULT_MODEL, voice: SONIOX_DEFAULT_VOICE };
|
|
69
|
+
}
|
|
70
|
+
function openaiModelVoice(env) {
|
|
71
|
+
if (env.OSBORN_TTS_PROVIDER === 'openai') {
|
|
72
|
+
return { model: env.OSBORN_TTS_MODEL || OPENAI_DEFAULT_MODEL, voice: env.OSBORN_TTS_VOICE || OPENAI_DEFAULT_VOICE };
|
|
73
|
+
}
|
|
74
|
+
return { model: OPENAI_DEFAULT_MODEL, voice: OPENAI_DEFAULT_VOICE };
|
|
75
|
+
}
|
|
76
|
+
function buildRequest(provider, text, env, voiceOverride) {
|
|
77
|
+
if (provider === 'soniox') {
|
|
78
|
+
const { model, voice: def } = sonioxModelVoice(env);
|
|
79
|
+
const voice = voiceOverride || def;
|
|
80
|
+
return {
|
|
81
|
+
url: SONIOX_TTS_URL,
|
|
82
|
+
headers: { 'Authorization': `Bearer ${env.SONIOX_API_KEY}`, 'Content-Type': 'application/json', 'User-Agent': USER_AGENT },
|
|
83
|
+
body: { model, language: 'en', voice, speed: SONIOX_SPEED, audio_format: 'mp3', text },
|
|
84
|
+
label: `soniox ${model}/${voice}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const { model, voice: def } = openaiModelVoice(env);
|
|
88
|
+
const voice = voiceOverride || def;
|
|
89
|
+
return {
|
|
90
|
+
url: OPENAI_TTS_URL,
|
|
91
|
+
headers: { 'Authorization': `Bearer ${env.OPENAI_API_KEY}`, 'Content-Type': 'application/json' },
|
|
92
|
+
body: { model, voice, input: text, response_format: 'mp3' },
|
|
93
|
+
label: `openai ${model}/${voice}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function tryProvider(req, timeoutMs, f) {
|
|
97
|
+
const t0 = Date.now();
|
|
98
|
+
try {
|
|
99
|
+
const r = await f(req.url, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: req.headers,
|
|
102
|
+
body: JSON.stringify(req.body),
|
|
103
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
104
|
+
});
|
|
105
|
+
if (!r.ok) {
|
|
106
|
+
const e = await r.text().catch(() => '');
|
|
107
|
+
console.warn(`⚠️ meeting tts ${req.label} ${r.status}: ${e.slice(0, 160)}`);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const buf = Buffer.from(await r.arrayBuffer());
|
|
111
|
+
if (buf.length === 0) {
|
|
112
|
+
console.warn(`⚠️ meeting tts ${req.label}: empty body`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const fmt = sniffAudioFormat(buf);
|
|
116
|
+
if (fmt !== 'mp3') {
|
|
117
|
+
// Recall output_audio only accepts mp3 — a mislabelled body is a failure.
|
|
118
|
+
console.warn(`⚠️ meeting tts ${req.label}: expected mp3, got ${fmt} (${buf.length}b)`);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
console.log(`🗣️ meeting tts ${req.label} ${buf.length}b in ${Date.now() - t0}ms`);
|
|
122
|
+
return buf;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.warn(`⚠️ meeting tts ${req.label}: ${e.message}`);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Synthesize `text` as MP3 for the meeting. Tries providers in
|
|
131
|
+
* selectMeetingTtsProviders order within a shared deadline. Never throws;
|
|
132
|
+
* returns null when no key is configured, every provider failed, or the
|
|
133
|
+
* deadline ran out.
|
|
134
|
+
*/
|
|
135
|
+
export async function synthMeetingAudio(text, opts = {}) {
|
|
136
|
+
const env = opts.env ?? process.env;
|
|
137
|
+
const f = opts.fetchImpl ?? fetch;
|
|
138
|
+
const input = (typeof text === 'string' ? text : '').slice(0, 4000);
|
|
139
|
+
if (!input.trim())
|
|
140
|
+
return null;
|
|
141
|
+
const order = selectMeetingTtsProviders(env);
|
|
142
|
+
if (order.length === 0) {
|
|
143
|
+
console.warn('⚠️ meeting tts: no SONIOX_API_KEY or OPENAI_API_KEY — meeting has no voice');
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const voiceTarget = opts.voice ? voiceOverrideTarget(opts.voice) : null;
|
|
147
|
+
const deadline = Date.now() + (opts.deadlineMs ?? TOTAL_DEADLINE_MS);
|
|
148
|
+
for (const provider of order) {
|
|
149
|
+
const remaining = deadline - Date.now();
|
|
150
|
+
if (remaining <= 0) {
|
|
151
|
+
console.warn(`⚠️ meeting tts: deadline reached before ${provider}`);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
const timeoutMs = provider === 'soniox' ? Math.min(SONIOX_TIMEOUT_MS, remaining) : remaining;
|
|
155
|
+
const req = buildRequest(provider, input, env, voiceTarget === provider ? opts.voice : undefined);
|
|
156
|
+
const audio = await tryProvider(req, timeoutMs, f);
|
|
157
|
+
if (audio)
|
|
158
|
+
return { audio, contentType: MEETING_AUDIO_CONTENT_TYPE, format: 'mp3', provider };
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Phase 2 (future): Gemini speaks first, Claude suppressed when Gemini has HIGH confidence
|
|
10
10
|
*/
|
|
11
11
|
import { llm, type APIConnectOptions } from '@livekit/agents';
|
|
12
|
-
import { type ClaudeLLMOptions } from './claude-llm.js';
|
|
12
|
+
import { ClaudeLLM, type ClaudeLLMOptions } from './claude-llm.js';
|
|
13
|
+
import { type AgentControlCallbacks } from './pipeline-fastbrain.js';
|
|
13
14
|
import { EventEmitter } from 'events';
|
|
14
15
|
export declare const SESSION_TAIL_DEFAULT_ROWS = 200;
|
|
15
16
|
export declare const SESSION_TAIL_DEFAULT_MAX_CHARS = 16000;
|
|
@@ -78,9 +79,27 @@ export declare class PipelineDirectLLM extends llm.LLM {
|
|
|
78
79
|
get model(): string;
|
|
79
80
|
get isResumingSession(): boolean;
|
|
80
81
|
label(): string;
|
|
82
|
+
get inner(): ClaudeLLM;
|
|
83
|
+
swapInner(newInner: ClaudeLLM): ClaudeLLM;
|
|
84
|
+
setWorkingContext({ workingDirectory, sessionBaseDir }: {
|
|
85
|
+
workingDirectory: string;
|
|
86
|
+
sessionBaseDir?: string;
|
|
87
|
+
}): void;
|
|
88
|
+
hasSession(): boolean;
|
|
81
89
|
setResumeSessionId(id: string | null): void;
|
|
82
90
|
setContinueSession(e: boolean): void;
|
|
83
91
|
resetForSessionSwitch(): void;
|
|
92
|
+
setWorkingDirectory(path: string): void;
|
|
93
|
+
get workingDirectory(): string | undefined;
|
|
94
|
+
get spawnedResumeId(): string | null;
|
|
95
|
+
busyState(): {
|
|
96
|
+
turnInFlight: boolean;
|
|
97
|
+
runningTasks: number;
|
|
98
|
+
compacting: boolean;
|
|
99
|
+
interruptPending: boolean;
|
|
100
|
+
permissionPending: boolean;
|
|
101
|
+
idle: boolean;
|
|
102
|
+
};
|
|
84
103
|
respondToPermission(allow: boolean, msg?: string): void;
|
|
85
104
|
hasPendingPermission(): boolean;
|
|
86
105
|
getPendingPermission(): {
|
|
@@ -120,4 +139,20 @@ export declare class PipelineDirectLLM extends llm.LLM {
|
|
|
120
139
|
abortController?: AbortController;
|
|
121
140
|
}): llm.LLMStream;
|
|
122
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Fast-brain agentControl bound to the inner ClaudeLLM a turn started on. Every
|
|
144
|
+
* callback is a no-op once the wrapper's current inner is no longer `inner` (after
|
|
145
|
+
* swapInner), so an emergency_stop from a pre-swap turn can't interrupt/re-prompt the
|
|
146
|
+
* promoted session. Deliberately NOT gated on the turn's abort signal: a newer user
|
|
147
|
+
* turn aborts it, and a "stop" followed quickly by more speech must still let the
|
|
148
|
+
* earlier turn's emergency_stop act on the same session (pre-swap behavior).
|
|
149
|
+
*/
|
|
150
|
+
export declare function buildGuardedAgentControl(args: {
|
|
151
|
+
inner: ClaudeLLM;
|
|
152
|
+
getCurrentInner: () => ClaudeLLM;
|
|
153
|
+
getChatHistory: () => {
|
|
154
|
+
role: string;
|
|
155
|
+
content: string;
|
|
156
|
+
}[];
|
|
157
|
+
}): AgentControlCallbacks;
|
|
123
158
|
export declare function createPipelineDirectLLM(opts: PipelineDirectOptions): PipelineDirectLLM;
|
|
@@ -179,12 +179,61 @@ export class PipelineDirectLLM extends llm.LLM {
|
|
|
179
179
|
get model() { return this.#claudeLLM.model; }
|
|
180
180
|
get isResumingSession() { return this.#claudeLLM.isResumingSession; }
|
|
181
181
|
label() { return 'pipeline-direct'; }
|
|
182
|
+
// ── Instance swap (foreground ⇄ background handoff) ──────────────────────────
|
|
183
|
+
// The voice AgentSession binds THIS wrapper for the whole session; chat() routes
|
|
184
|
+
// to #claudeLLM. swapInner() hot-swaps the inner ClaudeLLM so the voice can move
|
|
185
|
+
// to an already-running subprocess without tearing down the AgentSession. The
|
|
186
|
+
// caller owns moving voice event listeners between the old and new inner's emitter.
|
|
187
|
+
// Not wired by any caller yet (swap port step 1: guards + surface only).
|
|
188
|
+
get inner() { return this.#claudeLLM; }
|
|
189
|
+
swapInner(newInner) {
|
|
190
|
+
const prev = this.#claudeLLM;
|
|
191
|
+
// Cancel any in-flight fast-brain turn bound to the OLD inner so its agentControl
|
|
192
|
+
// closures can't fire interrupt/sendPrompt into the newly promoted session.
|
|
193
|
+
// Clear per-turn flags so the new inner starts clean.
|
|
194
|
+
try {
|
|
195
|
+
this.#turnAbort?.abort();
|
|
196
|
+
}
|
|
197
|
+
catch { }
|
|
198
|
+
this.#turnAbort = null;
|
|
199
|
+
this.#postCompactionTailPending = false;
|
|
200
|
+
this.#claudeLLM = newInner;
|
|
201
|
+
console.log('🔁 [pipeline] swapped inner ClaudeLLM (voice handoff)');
|
|
202
|
+
return prev;
|
|
203
|
+
}
|
|
204
|
+
// After a swap, point the dir-derived work (fast brain, session-tail) at the promoted
|
|
205
|
+
// session's working dir; otherwise #opts stays bound to the pre-swap session.
|
|
206
|
+
setWorkingContext({ workingDirectory, sessionBaseDir }) {
|
|
207
|
+
this.#opts = { ...this.#opts, workingDirectory, sessionBaseDir: sessionBaseDir ?? workingDirectory };
|
|
208
|
+
}
|
|
209
|
+
hasSession() { return this.#claudeLLM.hasSession(); }
|
|
182
210
|
// Proxy all methods
|
|
183
211
|
setResumeSessionId(id) { this.#claudeLLM.setResumeSessionId(id); }
|
|
184
212
|
setContinueSession(e) { this.#claudeLLM.setContinueSession(e); }
|
|
185
213
|
resetForSessionSwitch() {
|
|
214
|
+
// Mirror swapInner's per-turn cleanup (#74): a fast-brain turn bound to the
|
|
215
|
+
// closed session must not report or re-prompt into the next one, the
|
|
216
|
+
// compaction-tail seam belongs to the old session, and a meeting chunk's
|
|
217
|
+
// TTS gate must not outlive its turn.
|
|
218
|
+
try {
|
|
219
|
+
this.#turnAbort?.abort();
|
|
220
|
+
}
|
|
221
|
+
catch { }
|
|
222
|
+
this.#turnAbort = null;
|
|
223
|
+
this.#postCompactionTailPending = false;
|
|
224
|
+
this.suppressMeetingTTS = false;
|
|
186
225
|
this.#claudeLLM.resetForSessionSwitch();
|
|
187
226
|
}
|
|
227
|
+
// Cross-project switch/resume (#74): the inner's cwd drives the SDK query; the
|
|
228
|
+
// wrapper's drives the fast brain + session tail. Both must move together.
|
|
229
|
+
// (Was missing: resume_session's cross-slug branch threw a TypeError here.)
|
|
230
|
+
setWorkingDirectory(path) {
|
|
231
|
+
this.#claudeLLM.setWorkingDirectory(path);
|
|
232
|
+
this.setWorkingContext({ workingDirectory: path });
|
|
233
|
+
}
|
|
234
|
+
get workingDirectory() { return this.#opts.workingDirectory; }
|
|
235
|
+
get spawnedResumeId() { return this.#claudeLLM.spawnedResumeId; }
|
|
236
|
+
busyState() { return this.#claudeLLM.busyState(); }
|
|
188
237
|
respondToPermission(allow, msg) { this.#claudeLLM.respondToPermission(allow, msg); }
|
|
189
238
|
hasPendingPermission() { return this.#claudeLLM.hasPendingPermission(); }
|
|
190
239
|
getPendingPermission() { return this.#claudeLLM.getPendingPermission(); }
|
|
@@ -451,21 +500,24 @@ export class PipelineDirectLLM extends llm.LLM {
|
|
|
451
500
|
this.#turnAbort.abort();
|
|
452
501
|
this.#turnAbort = new AbortController();
|
|
453
502
|
const signal = this.#turnAbort.signal;
|
|
503
|
+
// Bind this turn to the inner it started on. After swapInner() the closures
|
|
504
|
+
// below must not reach the newly promoted session (see buildGuardedAgentControl).
|
|
505
|
+
const inner = this.#claudeLLM;
|
|
454
506
|
const startMs = Date.now();
|
|
455
507
|
// Wait for SDK to assign session ID — listen for event instead of polling
|
|
456
508
|
// Large sessions (22MB+) can take 10-15s for SDK to replay JSONL
|
|
457
|
-
let sessionId =
|
|
509
|
+
let sessionId = inner.sessionId;
|
|
458
510
|
if (!sessionId) {
|
|
459
511
|
sessionId = await new Promise((resolve) => {
|
|
460
512
|
// Listen for the session_id event from SDK
|
|
461
513
|
const onSessionId = (data) => {
|
|
462
514
|
resolve(data.sessionId);
|
|
463
515
|
};
|
|
464
|
-
|
|
516
|
+
inner.events.once('session_id', onSessionId);
|
|
465
517
|
// Safety timeout — don't wait forever
|
|
466
518
|
setTimeout(() => {
|
|
467
|
-
|
|
468
|
-
resolve(
|
|
519
|
+
inner.events.removeListener('session_id', onSessionId);
|
|
520
|
+
resolve(inner.sessionId || 'pending');
|
|
469
521
|
}, 15000);
|
|
470
522
|
});
|
|
471
523
|
}
|
|
@@ -481,26 +533,11 @@ export class PipelineDirectLLM extends llm.LLM {
|
|
|
481
533
|
chatHistory: this.#opts.getChatHistory?.() || [],
|
|
482
534
|
researchContext: this.#opts.getResearchContext?.(),
|
|
483
535
|
sessionBaseDir,
|
|
484
|
-
agentControl: {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const history = this.#opts.getChatHistory?.() || [];
|
|
490
|
-
return history
|
|
491
|
-
.filter(t => t.role === 'user')
|
|
492
|
-
.slice(-count)
|
|
493
|
-
.map(t => t.content);
|
|
494
|
-
},
|
|
495
|
-
sendPrompt: (prompt) => {
|
|
496
|
-
// Direct call to ClaudeLLM.chat() — event listeners (tts_say, tool_use, etc.) still attached
|
|
497
|
-
// skipTTSQueue mode: tts_say events → index.ts → session.say() — works independently
|
|
498
|
-
console.log(`🧠⚡ [control] Sending new prompt to Claude (${prompt.length} chars)`);
|
|
499
|
-
const chatCtx = new llm.ChatContext();
|
|
500
|
-
chatCtx.addMessage({ role: 'user', content: prompt });
|
|
501
|
-
this.#claudeLLM.chat({ chatCtx });
|
|
502
|
-
},
|
|
503
|
-
},
|
|
536
|
+
agentControl: buildGuardedAgentControl({
|
|
537
|
+
inner,
|
|
538
|
+
getCurrentInner: () => this.#claudeLLM,
|
|
539
|
+
getChatHistory: () => this.#opts.getChatHistory?.() || [],
|
|
540
|
+
}),
|
|
504
541
|
});
|
|
505
542
|
if (signal.aborted)
|
|
506
543
|
return;
|
|
@@ -526,6 +563,55 @@ export class PipelineDirectLLM extends llm.LLM {
|
|
|
526
563
|
}
|
|
527
564
|
}
|
|
528
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Fast-brain agentControl bound to the inner ClaudeLLM a turn started on. Every
|
|
568
|
+
* callback is a no-op once the wrapper's current inner is no longer `inner` (after
|
|
569
|
+
* swapInner), so an emergency_stop from a pre-swap turn can't interrupt/re-prompt the
|
|
570
|
+
* promoted session. Deliberately NOT gated on the turn's abort signal: a newer user
|
|
571
|
+
* turn aborts it, and a "stop" followed quickly by more speech must still let the
|
|
572
|
+
* earlier turn's emergency_stop act on the same session (pre-swap behavior).
|
|
573
|
+
*/
|
|
574
|
+
export function buildGuardedAgentControl(args) {
|
|
575
|
+
const { inner, getCurrentInner, getChatHistory } = args;
|
|
576
|
+
const stale = () => inner !== getCurrentInner();
|
|
577
|
+
return {
|
|
578
|
+
interrupt: async () => {
|
|
579
|
+
if (stale())
|
|
580
|
+
return false;
|
|
581
|
+
return inner.interruptQuery();
|
|
582
|
+
},
|
|
583
|
+
abort: () => {
|
|
584
|
+
if (stale())
|
|
585
|
+
return;
|
|
586
|
+
inner.abortQuery();
|
|
587
|
+
},
|
|
588
|
+
hasActiveAgent: () => {
|
|
589
|
+
if (stale())
|
|
590
|
+
return false;
|
|
591
|
+
return inner.hasActiveQuery();
|
|
592
|
+
},
|
|
593
|
+
getRecentUserMessages: (count) => {
|
|
594
|
+
if (stale())
|
|
595
|
+
return [];
|
|
596
|
+
return getChatHistory()
|
|
597
|
+
.filter(t => t.role === 'user')
|
|
598
|
+
.slice(-count)
|
|
599
|
+
.map(t => t.content);
|
|
600
|
+
},
|
|
601
|
+
sendPrompt: (prompt) => {
|
|
602
|
+
if (stale()) {
|
|
603
|
+
console.log('🧠⚡ [control] Dropped stale sendPrompt (inner swapped)');
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
// Direct call to ClaudeLLM.chat() — event listeners (tts_say, tool_use, etc.) still attached
|
|
607
|
+
// skipTTSQueue mode: tts_say events → index.ts → session.say() — works independently
|
|
608
|
+
console.log(`🧠⚡ [control] Sending new prompt to Claude (${prompt.length} chars)`);
|
|
609
|
+
const chatCtx = new llm.ChatContext();
|
|
610
|
+
chatCtx.addMessage({ role: 'user', content: prompt });
|
|
611
|
+
inner.chat({ chatCtx });
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
}
|
|
529
615
|
// Deferred stream returned while the noise gate triages an utterance. Satisfies
|
|
530
616
|
// the synchronous chat() → llm.LLMStream contract (LiveKit); run() resolves the
|
|
531
617
|
// verdict and either drops (tombstoned by the gate) or re-enters chat() with the
|
|
@@ -33,6 +33,20 @@ export interface AgentControlCallbacks {
|
|
|
33
33
|
getRecentUserMessages: (count: number) => string[];
|
|
34
34
|
sendPrompt: (prompt: string) => void;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Per-call provider resolution for the HOUSE DEMO PASS. When the user has no
|
|
38
|
+
* Claude auth, applyAuthFallback() sets OSBORN_DEMO_PASS='zai' - the whole
|
|
39
|
+
* model layer (main agent AND this fast brain) then rides the shared z.ai GLM
|
|
40
|
+
* subscription instead of pay-per-use Fireworks/OpenRouter. Checked per call
|
|
41
|
+
* (not module-load) because applyAuthFallback runs after this module loads, and
|
|
42
|
+
* because a mid-session real-Claude login clears the flag via clearAuthFallback.
|
|
43
|
+
* Returns null on the normal (user pays their own providers) path.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveFastBrainProvider(): {
|
|
46
|
+
url: string;
|
|
47
|
+
model: string;
|
|
48
|
+
name: string;
|
|
49
|
+
} | null;
|
|
36
50
|
export declare function clearPipelineFastBrainSession(): void;
|
|
37
51
|
export declare function prewarmBM25Index(_sessionId: string, _workingDir: string): Promise<void>;
|
|
38
52
|
export declare function askPipelineFastBrain(workingDir: string, sessionId: string, question: string, opts?: PipelineFastBrainOptions): Promise<PipelineFastBrainResult>;
|
|
@@ -41,15 +41,17 @@ const MAX_TOOL_ROUNDS = 4;
|
|
|
41
41
|
* because a mid-session real-Claude login clears the flag via clearAuthFallback.
|
|
42
42
|
* Returns null on the normal (user pays their own providers) path.
|
|
43
43
|
*/
|
|
44
|
-
function resolveFastBrainProvider() {
|
|
44
|
+
export function resolveFastBrainProvider() {
|
|
45
45
|
if (process.env.OSBORN_DEMO_PASS !== 'zai')
|
|
46
46
|
return null;
|
|
47
47
|
const zaiKey = process.env.Z_AI_PERSONAL_API_KEY || process.env.ZAI_API_KEY;
|
|
48
48
|
if (!zaiKey)
|
|
49
49
|
return null;
|
|
50
50
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// Coding Plan endpoint - the standard /api/paas/v4 bills the pay-as-you-go
|
|
52
|
+
// wallet instead of the GLM Coding Plan quota.
|
|
53
|
+
url: 'https://api.z.ai/api/coding/paas/v4/chat/completions',
|
|
54
|
+
model: process.env.OSBORN_DEMO_FAST_MODEL || 'glm-5.3-flash', // fast/cheap tier of the pass
|
|
53
55
|
name: 'z.ai (demo pass)',
|
|
54
56
|
};
|
|
55
57
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<context>
|
|
2
2
|
You are Osborn, a voice AI engineer and thinking partner. Your text output is read aloud by a TTS engine — every word you write is spoken to a user listening through speakers or headphones. You also have a session workspace where you can write detailed reference files that the user sees in a side panel.
|
|
3
3
|
|
|
4
|
+
You are Osborn and nothing else — if asked what model, AI, company, or provider is behind you, never name, guess, or speculate about any underlying model or provider; say only that you are Osborn.
|
|
5
|
+
|
|
4
6
|
You are a peer on a voice call who thinks out loud with the user, grounds yourself with cheap reads, proposes specific approaches before acting, and uses every moment of long-running work as an opportunity to gather steering signal that makes the eventual output better than autonomous execution would produce.
|
|
5
7
|
|
|
6
8
|
The conversation IS the work. Your dialogue with the user is what makes Osborn's output more useful than pure autonomous execution. Without the conversation, you are just a vending machine.
|