osborn 0.9.281 → 0.9.283
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/agent-store.d.ts +5 -3
- package/dist/agent-store.js +11 -9
- package/dist/bridge-llm.d.ts +22 -0
- package/dist/bridge-llm.js +39 -0
- package/dist/claude-llm.js +10 -11
- package/dist/codex-handler.d.ts +38 -0
- package/dist/codex-handler.js +83 -0
- package/dist/codex-llm.d.ts +40 -0
- package/dist/codex-llm.js +144 -0
- package/dist/data-sender-auth.d.ts +1 -1
- package/dist/data-sender-auth.js +5 -1
- package/dist/fast-brain.d.ts +176 -0
- package/dist/fast-brain.js +1887 -0
- package/dist/index-3-2-26-legacy.d.ts +1 -0
- package/dist/index-3-2-26-legacy.js +2233 -0
- package/dist/index.js +175 -78
- package/dist/leagcyprompts2.d.ts +0 -0
- package/dist/leagcyprompts2.js +573 -0
- package/dist/pipeline-fastbrain.js +6 -47
- package/dist/prompts/pipeline-fast-brain.md +43 -0
- package/dist/prompts/steward.md +20 -6
- package/dist/prompts-2-25-26.d.ts +0 -0
- package/dist/prompts-2-25-26.js +518 -0
- package/dist/prompts-3-2-26.d.ts +78 -0
- package/dist/prompts-3-2-26.js +1319 -0
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.js +4 -0
- package/dist/pushover.d.ts +5 -0
- package/dist/pushover.js +41 -40
- package/dist/steward-verdict.js +1 -1
- package/dist/store-catalog.d.ts +5 -0
- package/dist/store-catalog.js +29 -9
- package/dist/store-name.js +5 -1
- package/dist/summary-index.d.ts +90 -0
- package/dist/summary-index.js +585 -0
- package/package.json +1 -1
- package/scripts/review.ts +6 -66
package/dist/agent-store.d.ts
CHANGED
|
@@ -117,9 +117,10 @@ export declare function describeAgents(core: CoreAgents, user: Record<string, Ag
|
|
|
117
117
|
* page, voice-native.com, or the frontend the agent is configured with. No Origin = not a
|
|
118
118
|
* browser cross-site request. Also decides which origin the write routes' CORS echoes. */
|
|
119
119
|
export declare function storeWriteOriginAllowed(origin: string | undefined, frontendUrl: string): boolean;
|
|
120
|
-
/** Refusal for a store
|
|
121
|
-
* without one, only this machine's own pages may
|
|
122
|
-
* address, and every write must be JSON
|
|
120
|
+
/** Refusal for a store request, or null. With a token, unauthorized() has already checked it;
|
|
121
|
+
* without one, only this machine's own pages may use the store (reads carry the core prompts
|
|
122
|
+
* and the user's skills), never a public or tunnelled address, and every write must be JSON
|
|
123
|
+
* (no other site's form or text/plain POST). */
|
|
123
124
|
export declare function storeWriteRefusal(r: {
|
|
124
125
|
hasToken: boolean;
|
|
125
126
|
publicDeploy: boolean;
|
|
@@ -129,6 +130,7 @@ export declare function storeWriteRefusal(r: {
|
|
|
129
130
|
origin?: string;
|
|
130
131
|
contentType?: string;
|
|
131
132
|
frontendUrl: string;
|
|
133
|
+
read?: boolean;
|
|
132
134
|
}): {
|
|
133
135
|
status: number;
|
|
134
136
|
error: string;
|
package/dist/agent-store.js
CHANGED
|
@@ -71,7 +71,7 @@ function roleBehaviours(role, isCore) {
|
|
|
71
71
|
return out;
|
|
72
72
|
}
|
|
73
73
|
// ── Definitions shared with the frontend and the user_agents SQL checks ───────
|
|
74
|
-
// (migrations 004/015/016/
|
|
74
|
+
// (migrations 004/015/016/018; agent/tests/user-agents-migrations.test.ts keeps them equal)
|
|
75
75
|
export const AGENT_MODELS = ['inherit', 'sonnet', 'opus', 'haiku', 'fable'];
|
|
76
76
|
export const isAgentModel = (m) => typeof m === 'string' && (AGENT_MODELS.includes(m) || /^claude-/.test(m));
|
|
77
77
|
export const AGENT_LIMITS = { name: 40, description: 500, prompt: 20000 };
|
|
@@ -126,7 +126,8 @@ export function parseUserAgents(rows, core) {
|
|
|
126
126
|
// Only a built-in parent matters to the role and grounding; a catalog origin names none.
|
|
127
127
|
const from = storeName(rawFrom);
|
|
128
128
|
roles[name] = resolveRole({ role: r.role, forkedFrom: from }, core);
|
|
129
|
-
const
|
|
129
|
+
const listed = Array.isArray(r.tools) ? r.tools.map((t) => String(t).trim()).filter(Boolean) : []; // ' Edit ' is Edit
|
|
130
|
+
const tools = listed.length ? listed : undefined;
|
|
130
131
|
agents[name] = {
|
|
131
132
|
description,
|
|
132
133
|
prompt,
|
|
@@ -182,19 +183,20 @@ export function storeWriteOriginAllowed(origin, frontendUrl) {
|
|
|
182
183
|
catch { /* none configured */ }
|
|
183
184
|
return LOOPBACK_HOST.test(u.host) || /^https:\/\/(www\.)?voice-native\.com$/.test(u.origin) || u.origin === configured;
|
|
184
185
|
}
|
|
185
|
-
/** Refusal for a store
|
|
186
|
-
* without one, only this machine's own pages may
|
|
187
|
-
* address, and every write must be JSON
|
|
186
|
+
/** Refusal for a store request, or null. With a token, unauthorized() has already checked it;
|
|
187
|
+
* without one, only this machine's own pages may use the store (reads carry the core prompts
|
|
188
|
+
* and the user's skills), never a public or tunnelled address, and every write must be JSON
|
|
189
|
+
* (no other site's form or text/plain POST). */
|
|
188
190
|
export function storeWriteRefusal(r) {
|
|
189
191
|
if (!r.hasToken) {
|
|
190
192
|
if (r.publicDeploy || r.forwarded || !LOOPBACK_HOST.test(r.host || ''))
|
|
191
|
-
return { status: 403, error: 'this machine is reachable from outside: set OSBORN_SYNC_TOKEN to
|
|
193
|
+
return { status: 403, error: 'this machine is reachable from outside: set OSBORN_SYNC_TOKEN to use the store' };
|
|
192
194
|
if (!LOOPBACK_ADDR.test(r.remote || ''))
|
|
193
|
-
return { status: 403, error: 'store
|
|
195
|
+
return { status: 403, error: 'the store needs the sync token or a request from this machine' };
|
|
194
196
|
if (!storeWriteOriginAllowed(r.origin, r.frontendUrl))
|
|
195
|
-
return { status: 403, error: 'store
|
|
197
|
+
return { status: 403, error: 'the store is refused from this site' };
|
|
196
198
|
}
|
|
197
|
-
if (!/^application\/json\b/i.test(r.contentType || ''))
|
|
199
|
+
if (!r.read && !/^application\/json\b/i.test(r.contentType || ''))
|
|
198
200
|
return { status: 415, error: 'send JSON (Content-Type: application/json)' };
|
|
199
201
|
return null;
|
|
200
202
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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/claude-llm.js
CHANGED
|
@@ -1017,19 +1017,19 @@ export function decideWrite(role, filePath) {
|
|
|
1017
1017
|
const rule = role ? ROLES[role].write : 'workspace';
|
|
1018
1018
|
if (rule === 'anywhere')
|
|
1019
1019
|
return { decision: 'defer' };
|
|
1020
|
+
// Fail closed for every limited role: an edit with no path is denied.
|
|
1021
|
+
if (!filePath)
|
|
1022
|
+
return { decision: 'deny', reason: 'Write denied: could not determine target file path. Failing closed.' };
|
|
1020
1023
|
if (rule === 'workspace') {
|
|
1021
|
-
if (
|
|
1024
|
+
if (!isWorkspacePath(filePath)) {
|
|
1022
1025
|
return { decision: 'deny', reason: 'Research mode: writes restricted to session workspace.' };
|
|
1023
1026
|
}
|
|
1024
1027
|
return { decision: 'allow' };
|
|
1025
1028
|
}
|
|
1026
|
-
// Extension whitelist
|
|
1027
|
-
const target = rule.matchBasename ?
|
|
1028
|
-
if (!
|
|
1029
|
-
|
|
1030
|
-
? `Write denied: ${filePath} is not a ${rule.label} file. This agent may only write ${rule.label} files.`
|
|
1031
|
-
: 'Write denied: could not determine target file path. Failing closed.';
|
|
1032
|
-
return { decision: 'deny', reason };
|
|
1029
|
+
// Extension whitelist.
|
|
1030
|
+
const target = rule.matchBasename ? basename(resolve(filePath)) : filePath;
|
|
1031
|
+
if (!rule.extensions.test(target)) {
|
|
1032
|
+
return { decision: 'deny', reason: `Write denied: ${filePath} is not a ${rule.label} file. This agent may only write ${rule.label} files.` };
|
|
1033
1033
|
}
|
|
1034
1034
|
return { decision: 'defer' };
|
|
1035
1035
|
}
|
|
@@ -2546,7 +2546,6 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2546
2546
|
if (gate.decision !== 'allow')
|
|
2547
2547
|
this.#eventEmitter.emit('steward_gate', { decision: gate.decision, message: gate.message });
|
|
2548
2548
|
if (gate.decision === 'deny') {
|
|
2549
|
-
this.#eventEmitter.emit('tool_blocked', { name: toolName, reason: gate.message });
|
|
2550
2549
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny' }, reason: gate.message };
|
|
2551
2550
|
}
|
|
2552
2551
|
if (gate.decision === 'advise')
|
|
@@ -2574,13 +2573,13 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2574
2573
|
`Then re-attempt this edit. (One-time reminder this turn; new files are exempt.)`,
|
|
2575
2574
|
].join('\n');
|
|
2576
2575
|
console.log(`🏛️ Writer provenance reminder: nudging before ${base} (first edit of an existing file this turn)`);
|
|
2577
|
-
this.#eventEmitter.emit('tool_blocked', { name: toolName, reason: `Review ${base}'s git history first (one-time provenance reminder)
|
|
2576
|
+
this.#eventEmitter.emit('tool_blocked', { name: toolName, reason: `Review ${base}'s git history first (one-time provenance reminder).`, kind: 'reminder' });
|
|
2578
2577
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny' }, reason: gateReason };
|
|
2579
2578
|
}
|
|
2580
2579
|
const { decision, reason } = decideWrite(role, filePath);
|
|
2581
2580
|
console.log(`🔎 Write gate: agent=${agentType ?? 'main'} role=${role ?? '-'} path="${filePath || '(none)'}" → ${decision}`);
|
|
2582
2581
|
if (decision === 'deny') {
|
|
2583
|
-
this.#eventEmitter.emit('tool_blocked', { name: toolName, reason });
|
|
2582
|
+
this.#eventEmitter.emit('tool_blocked', { name: toolName, reason, agent: agentType ?? 'main', role, path: filePath });
|
|
2584
2583
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny' }, reason };
|
|
2585
2584
|
}
|
|
2586
2585
|
if (decision === 'defer') {
|
|
@@ -0,0 +1,38 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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;
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* favorite_changed
|
|
24
24
|
* Open (read-only, listed in READ_ONLY_MESSAGE_TYPES):
|
|
25
25
|
* get_current_session, get_session_artifacts, get_plan_file,
|
|
26
|
-
* get_research_artifact, get_mcp_status, get_skills, skill_get
|
|
26
|
+
* get_research_artifact, get_mcp_status, get_skills, skill_get, get_busy
|
|
27
27
|
* list_sessions / list_slots / list_processes are read-only but return session
|
|
28
28
|
* and process ids that the gated commands (dispatch_background etc.) take as
|
|
29
29
|
* targets, so they are gated too.
|
package/dist/data-sender-auth.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* favorite_changed
|
|
24
24
|
* Open (read-only, listed in READ_ONLY_MESSAGE_TYPES):
|
|
25
25
|
* get_current_session, get_session_artifacts, get_plan_file,
|
|
26
|
-
* get_research_artifact, get_mcp_status, get_skills, skill_get
|
|
26
|
+
* get_research_artifact, get_mcp_status, get_skills, skill_get, get_busy
|
|
27
27
|
* list_sessions / list_slots / list_processes are read-only but return session
|
|
28
28
|
* and process ids that the gated commands (dispatch_background etc.) take as
|
|
29
29
|
* targets, so they are gated too.
|
|
@@ -49,6 +49,8 @@ export const CONTROL_MESSAGE_TYPES = new Set([
|
|
|
49
49
|
'switch_session',
|
|
50
50
|
// Cancels a deferred switch (#74) — state-changing, controller-only.
|
|
51
51
|
'cancel_session_switch',
|
|
52
|
+
// Keeps the agent working after the hang-up — state-changing, controller-only.
|
|
53
|
+
'keep_working',
|
|
52
54
|
'session_selected',
|
|
53
55
|
'mcp_toggle',
|
|
54
56
|
'set_agents',
|
|
@@ -82,6 +84,8 @@ export const READ_ONLY_MESSAGE_TYPES = new Set([
|
|
|
82
84
|
'get_mcp_status',
|
|
83
85
|
'get_skills',
|
|
84
86
|
'skill_get',
|
|
87
|
+
// End asks whether the agent is mid-task before offering keep-working.
|
|
88
|
+
'get_busy',
|
|
85
89
|
]);
|
|
86
90
|
/** Identity prefix /api/token gives every user participant. */
|
|
87
91
|
export const USER_IDENTITY_PREFIX = 'user-';
|