osborn 0.9.264 → 0.9.266
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/config.js +9 -2
- package/dist/embedder.js +19 -6
- package/dist/env-keys.js +1 -0
- package/dist/index.js +73 -27
- package/dist/pipeline-fastbrain.js +15 -4
- package/package.json +1 -1
- package/dist/bridge-llm.d.ts +0 -22
- package/dist/bridge-llm.js +0 -39
- package/dist/codex-handler.d.ts +0 -38
- package/dist/codex-handler.js +0 -83
- package/dist/codex-llm.d.ts +0 -40
- package/dist/codex-llm.js +0 -144
- package/dist/fast-brain.d.ts +0 -176
- package/dist/fast-brain.js +0 -1887
- package/dist/index-3-2-26-legacy.d.ts +0 -1
- package/dist/index-3-2-26-legacy.js +0 -2233
- package/dist/leagcyprompts2.d.ts +0 -0
- package/dist/leagcyprompts2.js +0 -573
- package/dist/prompts-2-25-26.d.ts +0 -0
- package/dist/prompts-2-25-26.js +0 -518
- package/dist/prompts-3-2-26.d.ts +0 -78
- package/dist/prompts-3-2-26.js +0 -1319
- package/dist/summary-index.d.ts +0 -90
- package/dist/summary-index.js +0 -585
package/dist/config.js
CHANGED
|
@@ -1212,8 +1212,15 @@ function scanDirForArtifacts(dir) {
|
|
|
1212
1212
|
scan(fullPath);
|
|
1213
1213
|
}
|
|
1214
1214
|
else {
|
|
1215
|
-
// Skip internal index files
|
|
1216
|
-
|
|
1215
|
+
// Skip internal index files, hidden files, and the session
|
|
1216
|
+
// transcript / recall store (JSONL + sqlite .db/-wal/-shm + subagent
|
|
1217
|
+
// .meta.json). These are NOT user-facing artifacts and were the bulk
|
|
1218
|
+
// of the 452-file resume payload that blew past the 49KB data-channel
|
|
1219
|
+
// limit (silently dropped). User research outputs — plans, diagrams,
|
|
1220
|
+
// notes, images, html, summaries — still pass through.
|
|
1221
|
+
if (entry.startsWith('search-index') || entry.startsWith('.'))
|
|
1222
|
+
continue;
|
|
1223
|
+
if (/\.(jsonl|db|db-wal|db-shm|sqlite)$/i.test(entry) || entry.endsWith('.meta.json'))
|
|
1217
1224
|
continue;
|
|
1218
1225
|
results.push({
|
|
1219
1226
|
fileName: entry,
|
package/dist/embedder.js
CHANGED
|
@@ -21,8 +21,19 @@
|
|
|
21
21
|
* API honors the `dimensions` passthrough.
|
|
22
22
|
*/
|
|
23
23
|
import { EMBED_DIM, EMBED_MODEL } from './session-store.js';
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Provider switch: Fireworks when FIREWORKS_API_KEY is set, else OpenRouter.
|
|
25
|
+
// Fireworks hosts the SAME qwen3-embedding-8b model, so vectors land in the same
|
|
26
|
+
// space as previously-embedded rows — no re-embed. EMBED_MODEL stays the store's
|
|
27
|
+
// model IDENTITY (the cache-invalidation key in session-store); only the
|
|
28
|
+
// per-provider API id differs, mapped here.
|
|
29
|
+
const FIREWORKS = !!process.env.FIREWORKS_API_KEY;
|
|
30
|
+
const EMBED_URL = process.env.OPENROUTER_EMBED_URL ||
|
|
31
|
+
(FIREWORKS
|
|
32
|
+
? 'https://api.fireworks.ai/inference/v1/embeddings'
|
|
33
|
+
: 'https://openrouter.ai/api/v1/embeddings');
|
|
34
|
+
const MODEL_ID = FIREWORKS && EMBED_MODEL === 'qwen/qwen3-embedding-8b'
|
|
35
|
+
? 'accounts/fireworks/models/qwen3-embedding-8b'
|
|
36
|
+
: EMBED_MODEL;
|
|
26
37
|
const MAX_BATCH = 64; // inputs per request (OpenAI-compatible arrays)
|
|
27
38
|
const REQUEST_TIMEOUT_MS = Number(process.env.OSBORN_EMBED_TIMEOUT_MS || 20_000);
|
|
28
39
|
let lastEmbedWarn = 0;
|
|
@@ -36,7 +47,9 @@ function embedWarn(msg) {
|
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
function apiKey() {
|
|
39
|
-
return process.env.
|
|
50
|
+
return (process.env.FIREWORKS_API_KEY ||
|
|
51
|
+
process.env.OPENROUTER_API_KEY ||
|
|
52
|
+
process.env.OPENROUTER_WORKSPACE_API_KEY);
|
|
40
53
|
}
|
|
41
54
|
/**
|
|
42
55
|
* L2-normalize the first EMBED_DIM components of a float embedding, then quantize to
|
|
@@ -65,7 +78,7 @@ async function embedBatch(inputs, key, timeoutMs) {
|
|
|
65
78
|
const controller = new AbortController();
|
|
66
79
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
67
80
|
try {
|
|
68
|
-
const res = await fetch(
|
|
81
|
+
const res = await fetch(EMBED_URL, {
|
|
69
82
|
method: 'POST',
|
|
70
83
|
headers: {
|
|
71
84
|
Authorization: `Bearer ${key}`,
|
|
@@ -83,7 +96,7 @@ async function embedBatch(inputs, key, timeoutMs) {
|
|
|
83
96
|
});
|
|
84
97
|
if (!res.ok) {
|
|
85
98
|
const body = await res.text().catch(() => '');
|
|
86
|
-
embedWarn(
|
|
99
|
+
embedWarn(`${FIREWORKS ? "Fireworks" : "OpenRouter"} ${res.status} ${res.statusText}: ${body.slice(0, 200)}`);
|
|
87
100
|
return null;
|
|
88
101
|
}
|
|
89
102
|
const json = await res.json();
|
|
@@ -130,7 +143,7 @@ export async function getEmbedder(timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
|
130
143
|
// fresh per request — kept working. Re-reading recovers as soon as the key lands.
|
|
131
144
|
const key = apiKey();
|
|
132
145
|
if (!key) {
|
|
133
|
-
embedWarn('no OPENROUTER_API_KEY in env yet — keyword-only for this call');
|
|
146
|
+
embedWarn('no FIREWORKS_API_KEY/OPENROUTER_API_KEY in env yet — keyword-only for this call');
|
|
134
147
|
return null;
|
|
135
148
|
}
|
|
136
149
|
const embed = async (texts) => {
|
package/dist/env-keys.js
CHANGED
|
@@ -21,6 +21,7 @@ export const AGENT_ENV_KEYS = [
|
|
|
21
21
|
{ key: 'DEEPGRAM_API_KEY', required: true, explicit: false, description: 'Deepgram STT (LiveKit plugin).' },
|
|
22
22
|
{ key: 'SONIOX_API_KEY', required: false, explicit: false, description: 'Soniox STT (LiveKit plugin).' },
|
|
23
23
|
{ key: 'GROQ_API_KEY', required: false, explicit: true, description: 'Groq fast-brain inference.' },
|
|
24
|
+
{ key: 'FIREWORKS_API_KEY', required: false, explicit: true, description: 'Fireworks AI — fast-brain inference + embeddings (preferred over OpenRouter when set).' },
|
|
24
25
|
{ key: 'OPENAI_API_KEY', required: true, explicit: true, description: 'OpenAI realtime + pipeline.' },
|
|
25
26
|
{ key: 'GOOGLE_API_KEY', required: false, explicit: false, description: 'Google Gemini realtime (plugin).' },
|
|
26
27
|
// LLM auth (Claude vs OpenRouter switch)
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ import { statusManager } from './status-manager.js';
|
|
|
44
44
|
import { createSmitheryProxy, destroySmitheryProxy, parseSmitheryUrl, isSmitheryUrl, SmitheryAuthorizationError } from './smithery-proxy.js';
|
|
45
45
|
import { DIRECT_MODE_PROMPT } from './prompts.js';
|
|
46
46
|
import { MCP_CATALOG } from './config.js';
|
|
47
|
+
import { storeExists, openStore, recentRows } from './session-store.js';
|
|
47
48
|
import { getRecallClient } from './recall-client.js';
|
|
48
49
|
import { MeetingTranscriptPoller } from './meeting-transcript-poller.js';
|
|
49
50
|
import { missingRequiredEnv } from './env-keys.js';
|
|
@@ -5229,38 +5230,83 @@ async function main() {
|
|
|
5229
5230
|
if (currentLLM) {
|
|
5230
5231
|
currentLLM.setResumeSessionId(preSelectedSessionId);
|
|
5231
5232
|
console.log(`🔄 Session resume configured: ${preSelectedSessionId}`);
|
|
5232
|
-
//
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
const preArtifacts = listWorkspaceArtifacts(workingDir, preSelectedSessionId);
|
|
5241
|
-
if (preArtifacts.length > 0) {
|
|
5242
|
-
console.log(`📁 Sending ${preArtifacts.length} workspace artifacts to frontend`);
|
|
5243
|
-
await sendToFrontend({
|
|
5244
|
-
type: 'session_artifacts',
|
|
5245
|
-
sessionId: preSelectedSessionId,
|
|
5246
|
-
artifacts: preArtifacts.map(a => ({
|
|
5247
|
-
filePath: a.filePath,
|
|
5248
|
-
fileName: a.fileName,
|
|
5249
|
-
type: a.type,
|
|
5250
|
-
updatedAt: a.updatedAt,
|
|
5251
|
-
}))
|
|
5252
|
-
});
|
|
5233
|
+
// DEAD-AIR FIX (0.9.264): greet IMMEDIATELY — the greeting is a static
|
|
5234
|
+
// string that needs nothing from the resume-prep. Previously it was
|
|
5235
|
+
// awaited AFTER getSessionSummary (slow on a 323MB session) + a 452-
|
|
5236
|
+
// artifact enumeration, so the user heard silence for ~13.7s after the
|
|
5237
|
+
// screen connected (measured). Now the first words play at session-
|
|
5238
|
+
// ready (~2s); the prep runs in the background and never blocks voice.
|
|
5239
|
+
try {
|
|
5240
|
+
await session.say("Welcome back! Ready to continue our previous conversation.");
|
|
5253
5241
|
}
|
|
5254
|
-
|
|
5255
|
-
|
|
5242
|
+
catch (err) {
|
|
5243
|
+
console.log('⚠️ Pre-selected session greeting failed:', err);
|
|
5244
|
+
}
|
|
5245
|
+
// Resume-prep in the BACKGROUND: session summary → index injection +
|
|
5246
|
+
// artifact list to the UI. None of this gates the greeting or the
|
|
5247
|
+
// user's first turn (the real context comes from the primed JSONL
|
|
5248
|
+
// resume). Best-effort; failures are non-fatal.
|
|
5249
|
+
void (async () => {
|
|
5256
5250
|
try {
|
|
5257
|
-
|
|
5251
|
+
// OPTIMISTIC UX (0.9.265): push the last ~20 messages straight from
|
|
5252
|
+
// the per-session recall store (SQLite) so the UI can show prior
|
|
5253
|
+
// conversation during the connect wait instead of an empty orb.
|
|
5254
|
+
// recentRows reads the DB directly — NO JSONL replay. Best-effort.
|
|
5255
|
+
try {
|
|
5256
|
+
const dbPath = storeExists(preSelectedSessionId, workingDir);
|
|
5257
|
+
if (dbPath) {
|
|
5258
|
+
const db = openStore(dbPath, { readonly: true });
|
|
5259
|
+
try {
|
|
5260
|
+
const rows = recentRows(db, 20, ['user', 'assistant']); // newest-first
|
|
5261
|
+
const priorMessages = rows
|
|
5262
|
+
.reverse() // → chronological
|
|
5263
|
+
.map(r => ({ role: r.msgType === 'assistant' ? 'assistant' : 'user', content: (r.text || '').slice(0, 800) }))
|
|
5264
|
+
.filter(m => m.content.trim().length > 0);
|
|
5265
|
+
if (priorMessages.length > 0) {
|
|
5266
|
+
await sendToFrontend({ type: 'prior_messages', sessionId: preSelectedSessionId, messages: priorMessages });
|
|
5267
|
+
console.log(`💬 Sent ${priorMessages.length} prior messages from DB for optimistic UI`);
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
finally {
|
|
5271
|
+
try {
|
|
5272
|
+
db.close();
|
|
5273
|
+
}
|
|
5274
|
+
catch { }
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
catch (e) {
|
|
5279
|
+
console.warn('⚠️ prior_messages (optimistic) failed:', e instanceof Error ? e.message : e);
|
|
5280
|
+
}
|
|
5281
|
+
const summary = await getSessionSummary(preSelectedSessionId, workingDir);
|
|
5282
|
+
await sendToFrontend({
|
|
5283
|
+
type: 'session_resume_set',
|
|
5284
|
+
sessionId: preSelectedSessionId,
|
|
5285
|
+
success: true,
|
|
5286
|
+
});
|
|
5287
|
+
const preArtifacts = listWorkspaceArtifacts(workingDir, preSelectedSessionId);
|
|
5288
|
+
if (preArtifacts.length > 0) {
|
|
5289
|
+
// Cap at 120 so the payload stays under the 49KB data-channel
|
|
5290
|
+
// limit (452 artifacts = 106KB was silently dropped before).
|
|
5291
|
+
console.log(`📁 Sending ${Math.min(preArtifacts.length, 120)}/${preArtifacts.length} workspace artifacts to frontend`);
|
|
5292
|
+
await sendToFrontend({
|
|
5293
|
+
type: 'session_artifacts',
|
|
5294
|
+
sessionId: preSelectedSessionId,
|
|
5295
|
+
artifacts: preArtifacts.slice(0, 120).map(a => ({
|
|
5296
|
+
filePath: a.filePath,
|
|
5297
|
+
fileName: a.fileName,
|
|
5298
|
+
type: a.type,
|
|
5299
|
+
updatedAt: a.updatedAt,
|
|
5300
|
+
})),
|
|
5301
|
+
});
|
|
5302
|
+
}
|
|
5303
|
+
if (summary)
|
|
5304
|
+
injectSessionIndexIntoChatCtx(currentAgent, preSelectedSessionId, workingDir);
|
|
5258
5305
|
}
|
|
5259
5306
|
catch (err) {
|
|
5260
|
-
console.
|
|
5307
|
+
console.warn('⚠️ resume-prep (background) failed:', err instanceof Error ? err.message : err);
|
|
5261
5308
|
}
|
|
5262
|
-
|
|
5263
|
-
}
|
|
5309
|
+
})();
|
|
5264
5310
|
}
|
|
5265
5311
|
}
|
|
5266
5312
|
else if (!preSelectedSessionId && hasRecentSession) {
|
|
@@ -17,8 +17,19 @@
|
|
|
17
17
|
// ============================================================
|
|
18
18
|
// Model reads from env var (set by main process from getInferenceConfig) or DEFAULT_CONFIG default.
|
|
19
19
|
// To switch model: update DEFAULT_CONFIG.inference.fastBrainModel in config.ts, or set OSBORN_FAST_BRAIN_MODEL env var.
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// Provider switch: Fireworks (OpenAI-compatible) when FIREWORKS_API_KEY is set, else
|
|
21
|
+
// OpenRouter. Default Fireworks model: gpt-oss-120b — $0.15/M (docs.fireworks.ai/
|
|
22
|
+
// serverless/pricing, verified 2026-10-22), strictly cheaper than the old OpenRouter
|
|
23
|
+
// deepseek-chat ($0.257/M in, $1.029/M out) on BOTH input and output, with strong
|
|
24
|
+
// OpenAI-style function calling (the fast brain is a tool loop). Same-price alternate:
|
|
25
|
+
// accounts/fireworks/models/glm-5p3-flash ($0.15/M) via OSBORN_FAST_BRAIN_MODEL.
|
|
26
|
+
const FIREWORKS = !!process.env.FIREWORKS_API_KEY;
|
|
27
|
+
const PROVIDER_NAME = FIREWORKS ? 'Fireworks' : 'OpenRouter';
|
|
28
|
+
const OPENROUTER_MODEL = process.env.OSBORN_FAST_BRAIN_MODEL ||
|
|
29
|
+
(FIREWORKS ? 'accounts/fireworks/models/gpt-oss-120b' : 'deepseek/deepseek-chat');
|
|
30
|
+
const OPENROUTER_URL = FIREWORKS
|
|
31
|
+
? 'https://api.fireworks.ai/inference/v1/chat/completions'
|
|
32
|
+
: 'https://openrouter.ai/api/v1/chat/completions';
|
|
22
33
|
const TIMEOUT_MS = 20_000;
|
|
23
34
|
const MAX_TOOL_ROUNDS = 4;
|
|
24
35
|
// ============================================================
|
|
@@ -317,7 +328,7 @@ async function callOpenRouter(messages, tools, apiKey) {
|
|
|
317
328
|
});
|
|
318
329
|
if (!resp.ok) {
|
|
319
330
|
const body = await resp.text().catch(() => '');
|
|
320
|
-
throw new Error(
|
|
331
|
+
throw new Error(`${PROVIDER_NAME} ${resp.status}: ${body.substring(0, 200)}`);
|
|
321
332
|
}
|
|
322
333
|
return resp.json();
|
|
323
334
|
}
|
|
@@ -328,7 +339,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
|
|
|
328
339
|
if (!sessionId || sessionId === 'pending') {
|
|
329
340
|
return { script: 'Session is still initializing.', type: 'acknowledgment', toolsUsed: [] };
|
|
330
341
|
}
|
|
331
|
-
const apiKey = process.env.OPENROUTER_API_KEY;
|
|
342
|
+
const apiKey = process.env.FIREWORKS_API_KEY || process.env.OPENROUTER_API_KEY;
|
|
332
343
|
if (!apiKey) {
|
|
333
344
|
return { script: 'Search system not available right now.', type: 'acknowledgment', toolsUsed: [] };
|
|
334
345
|
}
|
package/package.json
CHANGED
package/dist/bridge-llm.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bridge LLM Module - Creates LLM instances for pipelined voice sessions
|
|
3
|
-
*
|
|
4
|
-
* In pipelined mode, we use a separate LLM (Gemini or GPT-4o) as the
|
|
5
|
-
* "conversation manager" that handles voice I/O and routes to Claude Code.
|
|
6
|
-
*/
|
|
7
|
-
import * as google from '@livekit/agents-plugin-google';
|
|
8
|
-
import * as openai from '@livekit/agents-plugin-openai';
|
|
9
|
-
export interface BridgeLLMConfig {
|
|
10
|
-
provider: 'gemini-pro' | 'gemini-flash' | 'gpt-4o' | 'gpt-4o-mini';
|
|
11
|
-
model?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create Bridge LLM instance for pipelined voice sessions
|
|
15
|
-
*
|
|
16
|
-
* Options:
|
|
17
|
-
* - gemini-pro: Gemini 2.5 Pro (smart, good reasoning)
|
|
18
|
-
* - gemini-flash: Gemini 2.0 Flash (faster, cheaper)
|
|
19
|
-
* - gpt-4o: GPT-4o (alternative if OpenAI preferred)
|
|
20
|
-
* - gpt-4o-mini: GPT-4o Mini (faster, cheaper)
|
|
21
|
-
*/
|
|
22
|
-
export declare function createBridgeLLM(config: BridgeLLMConfig): google.LLM | openai.LLM;
|
package/dist/bridge-llm.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bridge LLM Module - Creates LLM instances for pipelined voice sessions
|
|
3
|
-
*
|
|
4
|
-
* In pipelined mode, we use a separate LLM (Gemini or GPT-4o) as the
|
|
5
|
-
* "conversation manager" that handles voice I/O and routes to Claude Code.
|
|
6
|
-
*/
|
|
7
|
-
import * as google from '@livekit/agents-plugin-google';
|
|
8
|
-
import * as openai from '@livekit/agents-plugin-openai';
|
|
9
|
-
/**
|
|
10
|
-
* Create Bridge LLM instance for pipelined voice sessions
|
|
11
|
-
*
|
|
12
|
-
* Options:
|
|
13
|
-
* - gemini-pro: Gemini 2.5 Pro (smart, good reasoning)
|
|
14
|
-
* - gemini-flash: Gemini 2.0 Flash (faster, cheaper)
|
|
15
|
-
* - gpt-4o: GPT-4o (alternative if OpenAI preferred)
|
|
16
|
-
* - gpt-4o-mini: GPT-4o Mini (faster, cheaper)
|
|
17
|
-
*/
|
|
18
|
-
export function createBridgeLLM(config) {
|
|
19
|
-
switch (config.provider) {
|
|
20
|
-
case 'gemini-pro':
|
|
21
|
-
return new google.LLM({
|
|
22
|
-
model: config.model || 'gemini-2.5-pro',
|
|
23
|
-
});
|
|
24
|
-
case 'gemini-flash':
|
|
25
|
-
return new google.LLM({
|
|
26
|
-
model: config.model || 'gemini-2.0-flash',
|
|
27
|
-
});
|
|
28
|
-
case 'gpt-4o':
|
|
29
|
-
return new openai.LLM({
|
|
30
|
-
model: config.model || 'gpt-4o',
|
|
31
|
-
});
|
|
32
|
-
case 'gpt-4o-mini':
|
|
33
|
-
return new openai.LLM({
|
|
34
|
-
model: config.model || 'gpt-4o-mini',
|
|
35
|
-
});
|
|
36
|
-
default:
|
|
37
|
-
throw new Error(`Unknown Bridge LLM provider: ${config.provider}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
package/dist/codex-handler.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
type SandboxMode = 'workspace-write' | 'danger-full-access';
|
|
3
|
-
type ApprovalPolicy = 'on-failure' | 'on-request' | 'never';
|
|
4
|
-
interface CodexHandlerOptions {
|
|
5
|
-
workingDirectory?: string;
|
|
6
|
-
skipGitRepoCheck?: boolean;
|
|
7
|
-
sandboxMode?: SandboxMode;
|
|
8
|
-
approvalPolicy?: ApprovalPolicy;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Codex Handler using the official OpenAI Codex SDK
|
|
12
|
-
*
|
|
13
|
-
* Features:
|
|
14
|
-
* - Thread persistence (reuses same thread for context)
|
|
15
|
-
* - Built-in coding tools (file operations, terminal commands)
|
|
16
|
-
* - Hooks for observability
|
|
17
|
-
*
|
|
18
|
-
* Requirements:
|
|
19
|
-
* - Codex CLI must be installed (npm install -g @openai/codex or use npx)
|
|
20
|
-
* - Must be authenticated via: codex login (ChatGPT) or OPENAI_API_KEY env var
|
|
21
|
-
*
|
|
22
|
-
* Sandbox/Approval modes are configured via:
|
|
23
|
-
* - ~/.codex/config.yaml for global settings
|
|
24
|
-
* - CLI flags: --sandbox, --approval-policy
|
|
25
|
-
*
|
|
26
|
-
* Note: The SDK spawns the CLI binary, so authentication must be done beforehand.
|
|
27
|
-
*/
|
|
28
|
-
export declare class CodexHandler extends EventEmitter {
|
|
29
|
-
private codex;
|
|
30
|
-
private thread;
|
|
31
|
-
private options;
|
|
32
|
-
constructor(options?: CodexHandlerOptions);
|
|
33
|
-
run(prompt: string): Promise<string>;
|
|
34
|
-
getThreadId(): string | null;
|
|
35
|
-
clearThread(): void;
|
|
36
|
-
}
|
|
37
|
-
export declare function askCodex(prompt: string, cwd?: string): Promise<string>;
|
|
38
|
-
export {};
|
package/dist/codex-handler.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Codex } from '@openai/codex-sdk';
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
/**
|
|
4
|
-
* Codex Handler using the official OpenAI Codex SDK
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - Thread persistence (reuses same thread for context)
|
|
8
|
-
* - Built-in coding tools (file operations, terminal commands)
|
|
9
|
-
* - Hooks for observability
|
|
10
|
-
*
|
|
11
|
-
* Requirements:
|
|
12
|
-
* - Codex CLI must be installed (npm install -g @openai/codex or use npx)
|
|
13
|
-
* - Must be authenticated via: codex login (ChatGPT) or OPENAI_API_KEY env var
|
|
14
|
-
*
|
|
15
|
-
* Sandbox/Approval modes are configured via:
|
|
16
|
-
* - ~/.codex/config.yaml for global settings
|
|
17
|
-
* - CLI flags: --sandbox, --approval-policy
|
|
18
|
-
*
|
|
19
|
-
* Note: The SDK spawns the CLI binary, so authentication must be done beforehand.
|
|
20
|
-
*/
|
|
21
|
-
export class CodexHandler extends EventEmitter {
|
|
22
|
-
codex;
|
|
23
|
-
thread = null;
|
|
24
|
-
options;
|
|
25
|
-
constructor(options = {}) {
|
|
26
|
-
super();
|
|
27
|
-
this.options = {
|
|
28
|
-
workingDirectory: options.workingDirectory || process.cwd(),
|
|
29
|
-
skipGitRepoCheck: options.skipGitRepoCheck ?? true,
|
|
30
|
-
};
|
|
31
|
-
// Initialize Codex (inherits process env by default)
|
|
32
|
-
this.codex = new Codex();
|
|
33
|
-
}
|
|
34
|
-
async run(prompt) {
|
|
35
|
-
try {
|
|
36
|
-
// Create or reuse thread
|
|
37
|
-
if (!this.thread) {
|
|
38
|
-
console.log('🆕 Starting new Codex thread');
|
|
39
|
-
this.thread = this.codex.startThread({
|
|
40
|
-
workingDirectory: this.options.workingDirectory,
|
|
41
|
-
skipGitRepoCheck: this.options.skipGitRepoCheck,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log('🔄 Continuing Codex thread');
|
|
46
|
-
}
|
|
47
|
-
console.log(`📁 CWD: ${this.options.workingDirectory}`);
|
|
48
|
-
this.emit('thinking', prompt);
|
|
49
|
-
// Run the prompt and get the Turn result
|
|
50
|
-
const turn = await this.thread.run(prompt);
|
|
51
|
-
// Extract the final response text
|
|
52
|
-
const result = turn.finalResponse || '';
|
|
53
|
-
this.emit('result', result);
|
|
54
|
-
console.log(`✅ Codex done. Length: ${result.length}`);
|
|
55
|
-
// Log tool usage if any
|
|
56
|
-
if (turn.items && turn.items.length > 0) {
|
|
57
|
-
for (const item of turn.items) {
|
|
58
|
-
this.emit('tool_use', item);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return result || 'Task completed.';
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error('❌ Codex SDK error:', error);
|
|
65
|
-
this.emit('error', error);
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
getThreadId() {
|
|
70
|
-
// Codex threads have IDs but they may not be directly exposed
|
|
71
|
-
// Check the thread object for an id property
|
|
72
|
-
return this.thread?.id || null;
|
|
73
|
-
}
|
|
74
|
-
clearThread() {
|
|
75
|
-
this.thread = null;
|
|
76
|
-
console.log('🗑️ Codex thread cleared');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Quick utility for one-off queries
|
|
80
|
-
export async function askCodex(prompt, cwd) {
|
|
81
|
-
const handler = new CodexHandler({ workingDirectory: cwd });
|
|
82
|
-
return handler.run(prompt);
|
|
83
|
-
}
|
package/dist/codex-llm.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codex LLM Wrapper for LiveKit Agents
|
|
3
|
-
*
|
|
4
|
-
* Wraps the Codex Agent SDK (@openai/codex-sdk) to work
|
|
5
|
-
* with LiveKit's AgentSession as an LLM provider.
|
|
6
|
-
*
|
|
7
|
-
* Flow: User speaks → STT → CodexLLM (Agent SDK) → TTS → User hears
|
|
8
|
-
*/
|
|
9
|
-
import { llm, type APIConnectOptions } from '@livekit/agents';
|
|
10
|
-
import { Codex } from '@openai/codex-sdk';
|
|
11
|
-
import { EventEmitter } from 'events';
|
|
12
|
-
export interface CodexLLMOptions {
|
|
13
|
-
workingDirectory?: string;
|
|
14
|
-
skipGitRepoCheck?: boolean;
|
|
15
|
-
/** Event emitter for tool_use, progress updates */
|
|
16
|
-
eventEmitter?: EventEmitter;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Codex LLM - Wraps Codex Agent SDK for LiveKit
|
|
20
|
-
*/
|
|
21
|
-
export declare class CodexLLM extends llm.LLM {
|
|
22
|
-
#private;
|
|
23
|
-
constructor(opts?: CodexLLMOptions);
|
|
24
|
-
label(): string;
|
|
25
|
-
get model(): string;
|
|
26
|
-
get events(): EventEmitter;
|
|
27
|
-
get thread(): ReturnType<Codex['startThread']> | null;
|
|
28
|
-
chat({ chatCtx, toolCtx, connOptions, }: {
|
|
29
|
-
chatCtx: llm.ChatContext;
|
|
30
|
-
toolCtx?: llm.ToolContext;
|
|
31
|
-
connOptions?: APIConnectOptions;
|
|
32
|
-
parallelToolCalls?: boolean;
|
|
33
|
-
toolChoice?: llm.ToolChoice;
|
|
34
|
-
extraKwargs?: Record<string, unknown>;
|
|
35
|
-
}): llm.LLMStream;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a CodexLLM instance
|
|
39
|
-
*/
|
|
40
|
-
export declare function createCodexLLM(opts?: CodexLLMOptions): CodexLLM;
|
package/dist/codex-llm.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codex LLM Wrapper for LiveKit Agents
|
|
3
|
-
*
|
|
4
|
-
* Wraps the Codex Agent SDK (@openai/codex-sdk) to work
|
|
5
|
-
* with LiveKit's AgentSession as an LLM provider.
|
|
6
|
-
*
|
|
7
|
-
* Flow: User speaks → STT → CodexLLM (Agent SDK) → TTS → User hears
|
|
8
|
-
*/
|
|
9
|
-
import { llm, shortuuid, DEFAULT_API_CONNECT_OPTIONS } from '@livekit/agents';
|
|
10
|
-
import { Codex } from '@openai/codex-sdk';
|
|
11
|
-
import { EventEmitter } from 'events';
|
|
12
|
-
/**
|
|
13
|
-
* Codex LLM - Wraps Codex Agent SDK for LiveKit
|
|
14
|
-
*/
|
|
15
|
-
export class CodexLLM extends llm.LLM {
|
|
16
|
-
#opts;
|
|
17
|
-
#codex;
|
|
18
|
-
#thread = null;
|
|
19
|
-
#eventEmitter;
|
|
20
|
-
constructor(opts = {}) {
|
|
21
|
-
super();
|
|
22
|
-
this.#opts = {
|
|
23
|
-
workingDirectory: opts.workingDirectory || process.cwd(),
|
|
24
|
-
skipGitRepoCheck: opts.skipGitRepoCheck ?? true,
|
|
25
|
-
};
|
|
26
|
-
this.#codex = new Codex();
|
|
27
|
-
this.#eventEmitter = opts.eventEmitter || new EventEmitter();
|
|
28
|
-
console.log('🟣 CodexLLM initialized (Codex Agent SDK)');
|
|
29
|
-
console.log(` 📁 Working dir: ${this.#opts.workingDirectory}`);
|
|
30
|
-
}
|
|
31
|
-
label() {
|
|
32
|
-
return 'codex.agent-sdk';
|
|
33
|
-
}
|
|
34
|
-
get model() {
|
|
35
|
-
return 'codex';
|
|
36
|
-
}
|
|
37
|
-
get events() {
|
|
38
|
-
return this.#eventEmitter;
|
|
39
|
-
}
|
|
40
|
-
get thread() {
|
|
41
|
-
return this.#thread;
|
|
42
|
-
}
|
|
43
|
-
chat({ chatCtx, toolCtx, connOptions = DEFAULT_API_CONNECT_OPTIONS, }) {
|
|
44
|
-
return new CodexLLMStream(this, {
|
|
45
|
-
chatCtx,
|
|
46
|
-
toolCtx,
|
|
47
|
-
connOptions,
|
|
48
|
-
opts: this.#opts,
|
|
49
|
-
codex: this.#codex,
|
|
50
|
-
thread: this.#thread,
|
|
51
|
-
onThread: (t) => { this.#thread = t; },
|
|
52
|
-
eventEmitter: this.#eventEmitter,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Codex LLM Stream - Runs Codex Agent SDK and streams results
|
|
58
|
-
*/
|
|
59
|
-
class CodexLLMStream extends llm.LLMStream {
|
|
60
|
-
#opts;
|
|
61
|
-
#codex;
|
|
62
|
-
#thread;
|
|
63
|
-
#onThread;
|
|
64
|
-
#eventEmitter;
|
|
65
|
-
constructor(llmInstance, { chatCtx, toolCtx, connOptions, opts, codex, thread, onThread, eventEmitter, }) {
|
|
66
|
-
super(llmInstance, { chatCtx, toolCtx, connOptions });
|
|
67
|
-
this.#opts = opts;
|
|
68
|
-
this.#codex = codex;
|
|
69
|
-
this.#thread = thread;
|
|
70
|
-
this.#onThread = onThread;
|
|
71
|
-
this.#eventEmitter = eventEmitter;
|
|
72
|
-
}
|
|
73
|
-
async run() {
|
|
74
|
-
const requestId = `codex_${shortuuid()}`;
|
|
75
|
-
try {
|
|
76
|
-
// Extract user's message from chat context
|
|
77
|
-
// ChatContext has .items which are ChatItem[] (ChatMessage | FunctionCall | FunctionCallOutput)
|
|
78
|
-
const items = this.chatCtx.items;
|
|
79
|
-
// Find the last user message
|
|
80
|
-
let userText = '';
|
|
81
|
-
for (let i = items.length - 1; i >= 0; i--) {
|
|
82
|
-
const item = items[i];
|
|
83
|
-
if (item.type === 'message' && item.role === 'user') {
|
|
84
|
-
// Content is ChatContent[] = (ImageContent | AudioContent | string)[]
|
|
85
|
-
if (Array.isArray(item.content)) {
|
|
86
|
-
userText = item.content
|
|
87
|
-
.filter((c) => typeof c === 'string')
|
|
88
|
-
.join('\n');
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (!userText.trim()) {
|
|
94
|
-
this.queue.put({
|
|
95
|
-
id: requestId,
|
|
96
|
-
delta: { role: 'assistant', content: "I didn't catch that. Could you repeat?" },
|
|
97
|
-
});
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
console.log(`🎤 User (${userText.length} chars): "${userText}"`);
|
|
101
|
-
// Create or reuse thread
|
|
102
|
-
if (!this.#thread) {
|
|
103
|
-
console.log('🆕 Starting new Codex thread');
|
|
104
|
-
this.#thread = this.#codex.startThread({
|
|
105
|
-
workingDirectory: this.#opts.workingDirectory,
|
|
106
|
-
skipGitRepoCheck: this.#opts.skipGitRepoCheck,
|
|
107
|
-
});
|
|
108
|
-
this.#onThread(this.#thread);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
console.log('🔄 Continuing Codex thread');
|
|
112
|
-
}
|
|
113
|
-
// Run Codex and get result
|
|
114
|
-
const turn = await this.#thread.run(userText);
|
|
115
|
-
// Emit tool usage events
|
|
116
|
-
if (turn.items && turn.items.length > 0) {
|
|
117
|
-
for (const item of turn.items) {
|
|
118
|
-
console.log(`🔧 Codex: ${item.type || 'action'}`);
|
|
119
|
-
this.#eventEmitter.emit('tool_use', item);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// Send response to TTS
|
|
123
|
-
const result = turn.finalResponse || 'Done.';
|
|
124
|
-
this.queue.put({
|
|
125
|
-
id: requestId,
|
|
126
|
-
delta: { role: 'assistant', content: result },
|
|
127
|
-
});
|
|
128
|
-
console.log('✅ Codex response complete');
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
console.error('❌ Codex Agent SDK error:', error);
|
|
132
|
-
this.queue.put({
|
|
133
|
-
id: requestId,
|
|
134
|
-
delta: { role: 'assistant', content: 'Sorry, I encountered an error.' },
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Create a CodexLLM instance
|
|
141
|
-
*/
|
|
142
|
-
export function createCodexLLM(opts) {
|
|
143
|
-
return new CodexLLM(opts);
|
|
144
|
-
}
|