osborn 0.9.270 → 0.9.272
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/claude-llm.js +16 -0
- package/dist/env-keys.js +10 -0
- package/dist/index.js +62 -1
- package/dist/pushover.d.ts +77 -0
- package/dist/pushover.js +276 -0
- package/dist/watch-gateway.d.ts +38 -0
- package/dist/watch-gateway.js +205 -0
- 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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* watch-gateway.ts — Track 2 watch bridge (native watchOS app ↔ LiveKit room).
|
|
3
|
+
*
|
|
4
|
+
* watchOS has no WKWebView and LiveKit's Swift SDK will not target it
|
|
5
|
+
* (client-sdk-swift #288), so the native watch app (frontend/native/watchos/)
|
|
6
|
+
* speaks a tiny WebSocket protocol to THIS gateway running on the user's own
|
|
7
|
+
* machine, which bridges into their LiveKit room via @livekit/rtc-node:
|
|
8
|
+
*
|
|
9
|
+
* watch ──WS JSON (control)──► gateway ──RTC data channel──► room
|
|
10
|
+
* watch ──WS binary (Int16LE PCM 24kHz mono)──► gateway ──resample 48k──► published mic track
|
|
11
|
+
* watch ◄──WS binary (Int16LE PCM 24kHz mono)── gateway ◄──decode+resample── subscribed agent track
|
|
12
|
+
*
|
|
13
|
+
* Protocol (see also GatewayLink.swift — the two must stay in sync):
|
|
14
|
+
* C→S text {"type":"hello","watchId":string} — first message; joins the ACTIVE room
|
|
15
|
+
* {"type":"answer","qid":string,"allow":boolean} — question sheet response
|
|
16
|
+
* {"type":"ping"}
|
|
17
|
+
* C→S bin raw Int16LE mono PCM frames @24kHz (no header)
|
|
18
|
+
* S→C text {"type":"state","agent":"idle|listening|thinking|speaking","room":string}
|
|
19
|
+
* {"type":"question","qid":string,"text":string}
|
|
20
|
+
* {"type":"joined","room":string} / {"type":"error","message":string} / {"type":"pong"}
|
|
21
|
+
* S→C bin raw Int16LE mono PCM frames @24kHz (announced by {"type":"audio","rate":24000})
|
|
22
|
+
*
|
|
23
|
+
* One watch connection = one rtc-node Room. The gateway is dormant unless
|
|
24
|
+
* started (index.ts gates on WATCH_GATEWAY=1).
|
|
25
|
+
*/
|
|
26
|
+
import { WebSocketServer, WebSocket } from 'ws';
|
|
27
|
+
import { Room, RoomEvent, AudioSource, AudioResampler, AudioStream, AudioFrame, LocalAudioTrack, TrackKind, TrackSource, TrackPublishOptions, } from '@livekit/rtc-node';
|
|
28
|
+
const WATCH_PCM_RATE = 24_000;
|
|
29
|
+
const ROOM_RATE = 48_000;
|
|
30
|
+
function wsSendJson(ws, obj) {
|
|
31
|
+
if (ws.readyState === WebSocket.OPEN)
|
|
32
|
+
ws.send(JSON.stringify(obj));
|
|
33
|
+
}
|
|
34
|
+
export function startWatchGateway(opts) {
|
|
35
|
+
const wss = new WebSocketServer({ port: opts.port });
|
|
36
|
+
const sessions = new Set();
|
|
37
|
+
console.log(`⌚️ Watch gateway listening on :${opts.port} (bridging to ${opts.livekitUrl})`);
|
|
38
|
+
wss.on('connection', (ws) => {
|
|
39
|
+
let session = null;
|
|
40
|
+
let helloDone = false;
|
|
41
|
+
ws.on('message', (data, isBinary) => {
|
|
42
|
+
if (isBinary) {
|
|
43
|
+
// Raw Int16LE PCM @24kHz from the watch mic → resample → publish.
|
|
44
|
+
if (!session)
|
|
45
|
+
return;
|
|
46
|
+
const pcm = new Int16Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
|
|
47
|
+
const frame = new AudioFrame(pcm, WATCH_PCM_RATE, 1, pcm.length);
|
|
48
|
+
for (const out of session.upResampler.push(frame)) {
|
|
49
|
+
void session.upSource.captureFrame(out).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let msg;
|
|
54
|
+
try {
|
|
55
|
+
msg = JSON.parse(data.toString());
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (msg.type === 'ping') {
|
|
61
|
+
wsSendJson(ws, { type: 'pong' });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!helloDone) {
|
|
65
|
+
if (msg.type !== 'hello') {
|
|
66
|
+
wsSendJson(ws, { type: 'error', message: 'expected hello first' });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
helloDone = true;
|
|
70
|
+
void handleHello(ws, String(msg.watchId || 'watch'), sessions).then((s) => {
|
|
71
|
+
session = s;
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Answers from the watch question sheet ride the room data channel with
|
|
76
|
+
// the same shape the web UI sends, so the agent needs no new handling.
|
|
77
|
+
if (msg.type === 'answer' && session) {
|
|
78
|
+
const payload = JSON.stringify({
|
|
79
|
+
type: 'permission_response',
|
|
80
|
+
response: msg.allow ? 'allow' : 'deny',
|
|
81
|
+
source: 'watch',
|
|
82
|
+
qid: msg.qid,
|
|
83
|
+
});
|
|
84
|
+
void session.room.localParticipant
|
|
85
|
+
?.publishData(new TextEncoder().encode(payload), { reliable: true })
|
|
86
|
+
.catch(() => { });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
ws.on('close', () => void teardown(session));
|
|
90
|
+
ws.on('error', () => void teardown(session));
|
|
91
|
+
async function teardown(s) {
|
|
92
|
+
if (!s)
|
|
93
|
+
return;
|
|
94
|
+
session = null;
|
|
95
|
+
sessions.delete(s);
|
|
96
|
+
s.downReader?.cancel().catch(() => { });
|
|
97
|
+
try {
|
|
98
|
+
await s.upTrack.close();
|
|
99
|
+
}
|
|
100
|
+
catch { /* already closed */ }
|
|
101
|
+
s.upResampler.close();
|
|
102
|
+
s.downResampler.close();
|
|
103
|
+
try {
|
|
104
|
+
await s.room.disconnect();
|
|
105
|
+
}
|
|
106
|
+
catch { /* already disconnected */ }
|
|
107
|
+
}
|
|
108
|
+
async function handleHello(ws, watchId, activeSessions) {
|
|
109
|
+
const activeRoom = opts.getActiveRoom();
|
|
110
|
+
if (!activeRoom) {
|
|
111
|
+
wsSendJson(ws, { type: 'error', message: 'no active session room — connect from the dashboard first' });
|
|
112
|
+
ws.close();
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const room = new Room();
|
|
116
|
+
const upSource = new AudioSource(ROOM_RATE, 1);
|
|
117
|
+
const upTrack = LocalAudioTrack.createAudioTrack(`watch-${watchId}-mic`, upSource);
|
|
118
|
+
const s = {
|
|
119
|
+
ws,
|
|
120
|
+
room,
|
|
121
|
+
upSource,
|
|
122
|
+
upTrack,
|
|
123
|
+
upResampler: new AudioResampler(WATCH_PCM_RATE, ROOM_RATE, 1),
|
|
124
|
+
downResampler: new AudioResampler(ROOM_RATE, WATCH_PCM_RATE, 1),
|
|
125
|
+
};
|
|
126
|
+
room
|
|
127
|
+
.on(RoomEvent.DataReceived, (payload) => {
|
|
128
|
+
// Room data (agent state, permission_request, …) → watch as JSON text.
|
|
129
|
+
try {
|
|
130
|
+
const text = new TextDecoder().decode(payload);
|
|
131
|
+
const parsed = JSON.parse(text);
|
|
132
|
+
if (parsed?.type === 'permission_request') {
|
|
133
|
+
// The watch shows a yes/no sheet for blocking questions.
|
|
134
|
+
wsSendJson(ws, {
|
|
135
|
+
type: 'question',
|
|
136
|
+
qid: parsed.toolUseId ?? parsed.toolName ?? 'perm',
|
|
137
|
+
text: parsed.description ?? `Use ${parsed.toolName}?`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else if (parsed?.type === 'agent_state' || parsed?.type === 'state') {
|
|
141
|
+
wsSendJson(ws, { type: 'state', agent: parsed.state ?? parsed.agent ?? 'idle', room: activeRoom });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch { /* non-JSON or non-object data — ignore */ }
|
|
145
|
+
})
|
|
146
|
+
.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
|
|
147
|
+
if (track.kind !== TrackKind.KIND_AUDIO)
|
|
148
|
+
return;
|
|
149
|
+
console.log(`⌚️ Watch gateway: subscribing agent audio (${publication.source}, ${participant.identity})`);
|
|
150
|
+
// Decode agent audio at room rate, resample down to 24k, ship to watch.
|
|
151
|
+
const stream = new AudioStream(track, ROOM_RATE, 1);
|
|
152
|
+
s.downStream = stream;
|
|
153
|
+
const reader = stream.getReader();
|
|
154
|
+
s.downReader = reader;
|
|
155
|
+
wsSendJson(ws, { type: 'audio', rate: WATCH_PCM_RATE });
|
|
156
|
+
void (async () => {
|
|
157
|
+
try {
|
|
158
|
+
for (;;) {
|
|
159
|
+
const { done, value } = await reader.read();
|
|
160
|
+
if (done)
|
|
161
|
+
break;
|
|
162
|
+
if (ws.readyState !== WebSocket.OPEN)
|
|
163
|
+
break;
|
|
164
|
+
for (const out of s.downResampler.push(value)) {
|
|
165
|
+
if (ws.readyState !== WebSocket.OPEN)
|
|
166
|
+
break;
|
|
167
|
+
ws.send(Buffer.from(out.data.buffer));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch { /* reader cancelled or stream ended */ }
|
|
172
|
+
})();
|
|
173
|
+
})
|
|
174
|
+
.on(RoomEvent.Disconnected, () => {
|
|
175
|
+
wsSendJson(ws, { type: 'error', message: 'room disconnected' });
|
|
176
|
+
void teardown(s);
|
|
177
|
+
});
|
|
178
|
+
try {
|
|
179
|
+
await room.connect(opts.livekitUrl, await opts.mintToken(activeRoom), {
|
|
180
|
+
autoSubscribe: true,
|
|
181
|
+
dynacast: false,
|
|
182
|
+
});
|
|
183
|
+
await room.localParticipant.publishTrack(upTrack, new TrackPublishOptions({ source: TrackSource.SOURCE_MICROPHONE }));
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
console.log('⌚️ Watch gateway: room connect failed:', e instanceof Error ? e.message : e);
|
|
187
|
+
wsSendJson(ws, { type: 'error', message: 'room connect failed' });
|
|
188
|
+
void teardown(s);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
activeSessions.add(s);
|
|
192
|
+
console.log(`⌚️ Watch gateway: watch ${watchId} joined room ${activeRoom}`);
|
|
193
|
+
wsSendJson(ws, { type: 'joined', room: activeRoom });
|
|
194
|
+
return s;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
wss,
|
|
199
|
+
close: () => {
|
|
200
|
+
for (const ws of wss.clients)
|
|
201
|
+
ws.terminate();
|
|
202
|
+
wss.close();
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
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
|
-
}
|