@made-by-moonlight/athene-plugin-agent-codex 0.9.1
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/LICENSE +22 -0
- package/dist/app-server-client.d.ts +139 -0
- package/dist/app-server-client.d.ts.map +1 -0
- package/dist/app-server-client.js +360 -0
- package/dist/app-server-client.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +807 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Composio, Inc.
|
|
4
|
+
Copyright (c) 2026 slievr (Athene fork)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
/** JSON-RPC request sent from client to server */
|
|
3
|
+
export interface JsonRpcRequest {
|
|
4
|
+
jsonrpc: "2.0";
|
|
5
|
+
id: string;
|
|
6
|
+
method: string;
|
|
7
|
+
params: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** JSON-RPC response from server */
|
|
10
|
+
export interface JsonRpcResponse {
|
|
11
|
+
id: string;
|
|
12
|
+
result?: Record<string, unknown>;
|
|
13
|
+
error?: JsonRpcError;
|
|
14
|
+
}
|
|
15
|
+
/** JSON-RPC error object */
|
|
16
|
+
export interface JsonRpcError {
|
|
17
|
+
code: number;
|
|
18
|
+
message: string;
|
|
19
|
+
data?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** JSON-RPC notification from server (no id) */
|
|
22
|
+
export interface JsonRpcNotification {
|
|
23
|
+
method: string;
|
|
24
|
+
params: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Approval request from server (has id + method + params) */
|
|
27
|
+
export interface JsonRpcApprovalRequest {
|
|
28
|
+
id: string | number;
|
|
29
|
+
method: string;
|
|
30
|
+
params: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** Callback for server notifications */
|
|
33
|
+
export type NotificationHandler = (method: string, params: Record<string, unknown>) => void;
|
|
34
|
+
/** Callback for approval requests */
|
|
35
|
+
export type ApprovalHandler = (id: string | number, method: string, params: Record<string, unknown>) => Promise<ApprovalDecision>;
|
|
36
|
+
/** Approval decision values */
|
|
37
|
+
export type ApprovalDecision = "accept" | "acceptForSession" | "decline" | "cancel";
|
|
38
|
+
/** Options for creating a CodexAppServerClient */
|
|
39
|
+
export interface AppServerClientOptions {
|
|
40
|
+
/** Path to codex binary (default: "codex") */
|
|
41
|
+
binaryPath?: string;
|
|
42
|
+
/** Working directory for the app-server process */
|
|
43
|
+
cwd?: string;
|
|
44
|
+
/** Environment variables for the process */
|
|
45
|
+
env?: Record<string, string>;
|
|
46
|
+
/** Timeout for requests in ms (default: 60000) */
|
|
47
|
+
requestTimeout?: number;
|
|
48
|
+
/** Handler for server notifications */
|
|
49
|
+
onNotification?: NotificationHandler;
|
|
50
|
+
/** Handler for approval requests (auto-accepts if not provided) */
|
|
51
|
+
onApproval?: ApprovalHandler;
|
|
52
|
+
}
|
|
53
|
+
/** Thread start parameters */
|
|
54
|
+
export interface ThreadStartParams {
|
|
55
|
+
model?: string;
|
|
56
|
+
modelProvider?: string;
|
|
57
|
+
cwd?: string;
|
|
58
|
+
/** Codex approval policy: untrusted (ask for all), on-request, or never */
|
|
59
|
+
approvalPolicy?: "untrusted" | "on-request" | "never";
|
|
60
|
+
/** Codex sandbox mode */
|
|
61
|
+
sandbox?: "read-only" | "workspace-write" | "danger-full-access";
|
|
62
|
+
/** Personality/instruction preset */
|
|
63
|
+
personality?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Turn start parameters */
|
|
66
|
+
export interface TurnStartParams {
|
|
67
|
+
threadId: string;
|
|
68
|
+
input: string;
|
|
69
|
+
cwd?: string;
|
|
70
|
+
model?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* JSON-RPC client for Codex's app-server mode.
|
|
74
|
+
*
|
|
75
|
+
* Usage:
|
|
76
|
+
* ```ts
|
|
77
|
+
* const client = new CodexAppServerClient({ cwd: "/my/project" });
|
|
78
|
+
* await client.connect();
|
|
79
|
+
*
|
|
80
|
+
* const thread = await client.threadStart({ model: "o3-mini" });
|
|
81
|
+
* const turn = await client.turnStart({ threadId: thread.id, input: "Fix the bug" });
|
|
82
|
+
*
|
|
83
|
+
* await client.close();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class CodexAppServerClient extends EventEmitter {
|
|
87
|
+
private process;
|
|
88
|
+
private readline;
|
|
89
|
+
private pending;
|
|
90
|
+
private initialized;
|
|
91
|
+
private closed;
|
|
92
|
+
private connecting;
|
|
93
|
+
private readonly binaryPath;
|
|
94
|
+
private readonly cwd;
|
|
95
|
+
private readonly env;
|
|
96
|
+
private readonly requestTimeout;
|
|
97
|
+
private readonly onNotification;
|
|
98
|
+
private readonly onApproval;
|
|
99
|
+
constructor(options?: AppServerClientOptions);
|
|
100
|
+
/** Whether the client is connected and initialized */
|
|
101
|
+
get isConnected(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Spawn the app-server process and perform the initialization handshake.
|
|
104
|
+
* Must be called before any other method.
|
|
105
|
+
*/
|
|
106
|
+
connect(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Gracefully close the app-server process.
|
|
109
|
+
* Sends SIGTERM first, then SIGKILL after timeout.
|
|
110
|
+
*/
|
|
111
|
+
close(): Promise<void>;
|
|
112
|
+
/** Create a new conversation thread */
|
|
113
|
+
threadStart(params?: ThreadStartParams): Promise<Record<string, unknown>>;
|
|
114
|
+
/** Resume an existing conversation thread by ID */
|
|
115
|
+
threadResume(threadId: string): Promise<Record<string, unknown>>;
|
|
116
|
+
/** List threads (with optional cursor-based pagination) */
|
|
117
|
+
threadList(cursor?: string, limit?: number): Promise<Record<string, unknown>>;
|
|
118
|
+
/** Archive a thread */
|
|
119
|
+
threadArchive(threadId: string): Promise<Record<string, unknown>>;
|
|
120
|
+
/** Start a new turn (send a message to the agent) */
|
|
121
|
+
turnStart(params: TurnStartParams): Promise<Record<string, unknown>>;
|
|
122
|
+
/** Interrupt a running turn */
|
|
123
|
+
turnInterrupt(threadId: string, turnId: string): Promise<Record<string, unknown>>;
|
|
124
|
+
/** List available models */
|
|
125
|
+
modelList(cursor?: string, limit?: number): Promise<Record<string, unknown>>;
|
|
126
|
+
/** Send a JSON-RPC request and wait for the response */
|
|
127
|
+
sendRequest(method: string, params?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
128
|
+
/** Send a JSON-RPC notification (no response expected) */
|
|
129
|
+
sendNotification(method: string, params?: Record<string, unknown>): void;
|
|
130
|
+
/** Respond to an approval request from the server */
|
|
131
|
+
sendApprovalResponse(id: string | number, decision: ApprovalDecision): void;
|
|
132
|
+
private initialize;
|
|
133
|
+
private writeLine;
|
|
134
|
+
private handleLine;
|
|
135
|
+
private handleApprovalRequest;
|
|
136
|
+
private handleProcessExit;
|
|
137
|
+
private handleProcessError;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=app-server-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-server-client.d.ts","sourceRoot":"","sources":["../src/app-server-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,4BAA4B;AAC5B,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,gDAAgD;AAChD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,8DAA8D;AAC9D,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAA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ed methods
|
|
6
|
+
* for thread management, turn execution, and conversation resume.
|
|
7
|
+
*
|
|
8
|
+
* Protocol reference: Codex app-server developer guide
|
|
9
|
+
* Implementation reference: codex-autorunner integrations/app_server/client.py
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
import { createInterface } from "node:readline";
|
|
14
|
+
import { EventEmitter } from "node:events";
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// Client Implementation
|
|
17
|
+
// =============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* JSON-RPC client for Codex's app-server mode.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```ts
|
|
23
|
+
* const client = new CodexAppServerClient({ cwd: "/my/project" });
|
|
24
|
+
* await client.connect();
|
|
25
|
+
*
|
|
26
|
+
* const thread = await client.threadStart({ model: "o3-mini" });
|
|
27
|
+
* const turn = await client.turnStart({ threadId: thread.id, input: "Fix the bug" });
|
|
28
|
+
*
|
|
29
|
+
* await client.close();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class CodexAppServerClient extends EventEmitter {
|
|
33
|
+
process = null;
|
|
34
|
+
readline = null;
|
|
35
|
+
pending = new Map();
|
|
36
|
+
initialized = false;
|
|
37
|
+
closed = false;
|
|
38
|
+
connecting = false;
|
|
39
|
+
binaryPath;
|
|
40
|
+
cwd;
|
|
41
|
+
env;
|
|
42
|
+
requestTimeout;
|
|
43
|
+
onNotification;
|
|
44
|
+
onApproval;
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
super();
|
|
47
|
+
this.binaryPath = options.binaryPath ?? "codex";
|
|
48
|
+
this.cwd = options.cwd;
|
|
49
|
+
this.env = options.env;
|
|
50
|
+
this.requestTimeout = options.requestTimeout ?? 60_000;
|
|
51
|
+
this.onNotification = options.onNotification;
|
|
52
|
+
this.onApproval = options.onApproval;
|
|
53
|
+
}
|
|
54
|
+
/** Whether the client is connected and initialized */
|
|
55
|
+
get isConnected() {
|
|
56
|
+
return this.initialized && !this.closed && this.process !== null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Spawn the app-server process and perform the initialization handshake.
|
|
60
|
+
* Must be called before any other method.
|
|
61
|
+
*/
|
|
62
|
+
async connect() {
|
|
63
|
+
if (this.closed)
|
|
64
|
+
throw new Error("Client is closed");
|
|
65
|
+
if (this.initialized)
|
|
66
|
+
throw new Error("Client is already connected");
|
|
67
|
+
if (this.connecting)
|
|
68
|
+
throw new Error("Client is already connecting");
|
|
69
|
+
this.connecting = true;
|
|
70
|
+
try {
|
|
71
|
+
this.process = spawn(this.binaryPath, ["app-server"], {
|
|
72
|
+
cwd: this.cwd,
|
|
73
|
+
env: this.env ? { ...process.env, ...this.env } : undefined,
|
|
74
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
75
|
+
});
|
|
76
|
+
if (!this.process.stdout || !this.process.stdin) {
|
|
77
|
+
throw new Error("Failed to open stdio pipes for codex app-server");
|
|
78
|
+
}
|
|
79
|
+
// Drain stderr to prevent the child process from blocking when
|
|
80
|
+
// the pipe buffer fills up.
|
|
81
|
+
this.process.stderr?.resume();
|
|
82
|
+
// Set up line-based reading from stdout
|
|
83
|
+
this.readline = createInterface({ input: this.process.stdout });
|
|
84
|
+
this.readline.on("line", (line) => this.handleLine(line));
|
|
85
|
+
// Handle process exit
|
|
86
|
+
this.process.once("exit", (code, signal) => {
|
|
87
|
+
this.handleProcessExit(code, signal);
|
|
88
|
+
});
|
|
89
|
+
this.process.once("error", (err) => {
|
|
90
|
+
this.handleProcessError(err);
|
|
91
|
+
});
|
|
92
|
+
await this.initialize();
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
this.connecting = false;
|
|
96
|
+
await this.close();
|
|
97
|
+
// Reset closed flag so the client can retry connect() after a
|
|
98
|
+
// transient handshake failure. The guard on line 172 ensures
|
|
99
|
+
// this.closed is always false when we reach this point.
|
|
100
|
+
this.closed = false;
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
this.connecting = false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gracefully close the app-server process.
|
|
107
|
+
* Sends SIGTERM first, then SIGKILL after timeout.
|
|
108
|
+
*/
|
|
109
|
+
async close() {
|
|
110
|
+
if (this.closed)
|
|
111
|
+
return;
|
|
112
|
+
this.closed = true;
|
|
113
|
+
this.initialized = false;
|
|
114
|
+
// Reject all pending requests
|
|
115
|
+
for (const [id, pending] of this.pending) {
|
|
116
|
+
clearTimeout(pending.timer);
|
|
117
|
+
pending.reject(new Error("Client closed"));
|
|
118
|
+
this.pending.delete(id);
|
|
119
|
+
}
|
|
120
|
+
if (this.readline) {
|
|
121
|
+
this.readline.close();
|
|
122
|
+
this.readline = null;
|
|
123
|
+
}
|
|
124
|
+
if (this.process && this.process.exitCode === null) {
|
|
125
|
+
const proc = this.process;
|
|
126
|
+
await new Promise((resolve) => {
|
|
127
|
+
const killTimer = setTimeout(() => {
|
|
128
|
+
try {
|
|
129
|
+
proc.kill("SIGKILL");
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Already dead
|
|
133
|
+
}
|
|
134
|
+
resolve();
|
|
135
|
+
}, 5_000);
|
|
136
|
+
proc.once("exit", () => {
|
|
137
|
+
clearTimeout(killTimer);
|
|
138
|
+
resolve();
|
|
139
|
+
});
|
|
140
|
+
try {
|
|
141
|
+
proc.kill("SIGTERM");
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
clearTimeout(killTimer);
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
this.process = null;
|
|
150
|
+
}
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
// Thread Management
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
/** Create a new conversation thread */
|
|
155
|
+
async threadStart(params = {}) {
|
|
156
|
+
return this.sendRequest("thread/start", { ...params });
|
|
157
|
+
}
|
|
158
|
+
/** Resume an existing conversation thread by ID */
|
|
159
|
+
async threadResume(threadId) {
|
|
160
|
+
return this.sendRequest("thread/resume", { threadId });
|
|
161
|
+
}
|
|
162
|
+
/** List threads (with optional cursor-based pagination) */
|
|
163
|
+
async threadList(cursor, limit) {
|
|
164
|
+
const params = {};
|
|
165
|
+
if (cursor)
|
|
166
|
+
params["cursor"] = cursor;
|
|
167
|
+
if (limit !== undefined)
|
|
168
|
+
params["limit"] = limit;
|
|
169
|
+
return this.sendRequest("thread/list", params);
|
|
170
|
+
}
|
|
171
|
+
/** Archive a thread */
|
|
172
|
+
async threadArchive(threadId) {
|
|
173
|
+
return this.sendRequest("thread/archive", { threadId });
|
|
174
|
+
}
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// Turn Management
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
/** Start a new turn (send a message to the agent) */
|
|
179
|
+
async turnStart(params) {
|
|
180
|
+
return this.sendRequest("turn/start", {
|
|
181
|
+
threadId: params.threadId,
|
|
182
|
+
input: [{ type: "text", text: params.input }],
|
|
183
|
+
...(params.cwd ? { cwd: params.cwd } : {}),
|
|
184
|
+
...(params.model ? { model: params.model } : {}),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/** Interrupt a running turn */
|
|
188
|
+
async turnInterrupt(threadId, turnId) {
|
|
189
|
+
return this.sendRequest("turn/interrupt", { threadId, turnId });
|
|
190
|
+
}
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Model Discovery
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
/** List available models */
|
|
195
|
+
async modelList(cursor, limit) {
|
|
196
|
+
const params = {};
|
|
197
|
+
if (cursor)
|
|
198
|
+
params["cursor"] = cursor;
|
|
199
|
+
if (limit !== undefined)
|
|
200
|
+
params["limit"] = limit;
|
|
201
|
+
return this.sendRequest("model/list", params);
|
|
202
|
+
}
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Low-level Protocol
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
/** Send a JSON-RPC request and wait for the response */
|
|
207
|
+
async sendRequest(method, params = {}) {
|
|
208
|
+
if (!this.initialized && method !== "initialize") {
|
|
209
|
+
throw new Error("Client not initialized — call connect() first");
|
|
210
|
+
}
|
|
211
|
+
if (this.closed)
|
|
212
|
+
throw new Error("Client is closed");
|
|
213
|
+
if (!this.process?.stdin?.writable) {
|
|
214
|
+
throw new Error("stdin not writable — process may have exited");
|
|
215
|
+
}
|
|
216
|
+
const id = randomUUID();
|
|
217
|
+
const request = { jsonrpc: "2.0", id, method, params };
|
|
218
|
+
return new Promise((resolve, reject) => {
|
|
219
|
+
const timer = setTimeout(() => {
|
|
220
|
+
this.pending.delete(id);
|
|
221
|
+
reject(new Error(`Request ${method} timed out after ${this.requestTimeout}ms`));
|
|
222
|
+
}, this.requestTimeout);
|
|
223
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
224
|
+
this.writeLine(JSON.stringify(request));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/** Send a JSON-RPC notification (no response expected) */
|
|
228
|
+
sendNotification(method, params = {}) {
|
|
229
|
+
if (this.closed)
|
|
230
|
+
return;
|
|
231
|
+
if (!this.process?.stdin?.writable)
|
|
232
|
+
return;
|
|
233
|
+
this.writeLine(JSON.stringify({ jsonrpc: "2.0", method, params }));
|
|
234
|
+
}
|
|
235
|
+
/** Respond to an approval request from the server */
|
|
236
|
+
sendApprovalResponse(id, decision) {
|
|
237
|
+
if (this.closed)
|
|
238
|
+
return;
|
|
239
|
+
if (!this.process?.stdin?.writable)
|
|
240
|
+
return;
|
|
241
|
+
this.writeLine(JSON.stringify({ jsonrpc: "2.0", id, result: { decision } }));
|
|
242
|
+
}
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// Internal
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
async initialize() {
|
|
247
|
+
const result = await this.sendRequest("initialize", {
|
|
248
|
+
clientInfo: {
|
|
249
|
+
name: "ao-agent-codex",
|
|
250
|
+
title: "Athene — Codex Plugin",
|
|
251
|
+
version: "0.1.1",
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
// Send the initialized notification to complete the handshake
|
|
255
|
+
this.sendNotification("initialized", {});
|
|
256
|
+
this.initialized = true;
|
|
257
|
+
this.emit("connected", result);
|
|
258
|
+
}
|
|
259
|
+
writeLine(line) {
|
|
260
|
+
if (!this.process?.stdin?.writable)
|
|
261
|
+
return;
|
|
262
|
+
this.process.stdin.write(line + "\n");
|
|
263
|
+
}
|
|
264
|
+
handleLine(line) {
|
|
265
|
+
const trimmed = line.trim();
|
|
266
|
+
if (!trimmed)
|
|
267
|
+
return;
|
|
268
|
+
let msg;
|
|
269
|
+
try {
|
|
270
|
+
const parsed = JSON.parse(trimmed);
|
|
271
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
272
|
+
return;
|
|
273
|
+
msg = parsed;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Skip malformed lines
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
// Classify the message
|
|
280
|
+
if ("id" in msg && msg.id !== undefined) {
|
|
281
|
+
const id = String(msg.id);
|
|
282
|
+
// Check if this is a response to a pending request
|
|
283
|
+
const pending = this.pending.get(id);
|
|
284
|
+
if (pending) {
|
|
285
|
+
this.pending.delete(id);
|
|
286
|
+
clearTimeout(pending.timer);
|
|
287
|
+
if ("error" in msg && msg.error) {
|
|
288
|
+
pending.reject(new Error(`JSON-RPC error ${msg.error.code}: ${msg.error.message}`));
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
pending.resolve(msg.result ?? {});
|
|
292
|
+
}
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
// If not a pending response, it's a server-initiated request (approval)
|
|
296
|
+
if ("method" in msg && typeof msg.method === "string") {
|
|
297
|
+
this.handleApprovalRequest(msg);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Notification (no id, has method)
|
|
302
|
+
if ("method" in msg && typeof msg.method === "string" && !("id" in msg)) {
|
|
303
|
+
const notification = msg;
|
|
304
|
+
this.emit("notification", notification.method, notification.params);
|
|
305
|
+
if (this.onNotification) {
|
|
306
|
+
this.onNotification(notification.method, notification.params);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async handleApprovalRequest(request) {
|
|
311
|
+
try {
|
|
312
|
+
this.emit("approval", request.id, request.method, request.params);
|
|
313
|
+
if (this.onApproval) {
|
|
314
|
+
const decision = await this.onApproval(request.id, request.method, request.params);
|
|
315
|
+
this.sendApprovalResponse(request.id, decision);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
// Default: auto-accept all approvals
|
|
319
|
+
this.sendApprovalResponse(request.id, "accept");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// On any error (listener throw or handler rejection), decline the request
|
|
324
|
+
this.sendApprovalResponse(request.id, "decline");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
handleProcessExit(code, signal) {
|
|
328
|
+
this.initialized = false;
|
|
329
|
+
// Close readline to release the event listener on the closed stdout stream
|
|
330
|
+
if (this.readline) {
|
|
331
|
+
this.readline.close();
|
|
332
|
+
this.readline = null;
|
|
333
|
+
}
|
|
334
|
+
// Reject all pending requests
|
|
335
|
+
const exitMsg = `codex app-server exited (code=${code}, signal=${signal})`;
|
|
336
|
+
for (const [id, pending] of this.pending) {
|
|
337
|
+
clearTimeout(pending.timer);
|
|
338
|
+
pending.reject(new Error(exitMsg));
|
|
339
|
+
this.pending.delete(id);
|
|
340
|
+
}
|
|
341
|
+
this.emit("exit", code, signal);
|
|
342
|
+
}
|
|
343
|
+
handleProcessError(err) {
|
|
344
|
+
this.initialized = false;
|
|
345
|
+
// Close readline to release the event listener on the closed stdout stream
|
|
346
|
+
if (this.readline) {
|
|
347
|
+
this.readline.close();
|
|
348
|
+
this.readline = null;
|
|
349
|
+
}
|
|
350
|
+
// Reject all pending requests before emitting "error" — emit("error")
|
|
351
|
+
// with no listeners throws synchronously, which would skip cleanup.
|
|
352
|
+
for (const [id, pending] of this.pending) {
|
|
353
|
+
clearTimeout(pending.timer);
|
|
354
|
+
pending.reject(err);
|
|
355
|
+
this.pending.delete(id);
|
|
356
|
+
}
|
|
357
|
+
this.emit("error", err);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=app-server-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-server-client.js","sourceRoot":"","sources":["../src/app-server-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAuC,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAyG3C,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAC5C,OAAO,GAAwB,IAAI,CAAC;IACpC,QAAQ,GAA6B,IAAI,CAAC;IAC1C,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,WAAW,GAAG,KAAK,CAAC;IACpB,MAAM,GAAG,KAAK,CAAC;IACf,UAAU,GAAG,KAAK,CAAC;IAEV,UAAU,CAAS;IACnB,GAAG,CAAqB;IACxB,GAAG,CAAqC;IACxC,cAAc,CAAS;IACvB,cAAc,CAAkC;IAChD,UAAU,CAA8B;IAEzD,YAAY,UAAkC,EAAE;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,O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AAE,CAAC;YACzC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;IAEO,kBAAkB,CAAC,GAAU;QACnC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAEzB,2EAA2E;QAC3E,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;QAED,sEAAsE;QACtE,oEAAoE;QACpE,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Agent } from "@made-by-moonlight/athene-core";
|
|
2
|
+
export declare const manifest: {
|
|
3
|
+
name: string;
|
|
4
|
+
slot: "agent";
|
|
5
|
+
description: string;
|
|
6
|
+
version: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the Codex CLI binary path.
|
|
11
|
+
* Checks (in order): which, common fallback locations.
|
|
12
|
+
* Returns "codex" as final fallback (let the shell resolve it at runtime).
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveCodexBinary(): Promise<string>;
|
|
15
|
+
export declare function create(): Agent;
|
|
16
|
+
/** @internal Clear the session file cache. Exported for testing only. */
|
|
17
|
+
export declare function _resetSessionFileCache(): void;
|
|
18
|
+
export { CodexAppServerClient } from "./app-server-client.js";
|
|
19
|
+
export type { AppServerClientOptions, ThreadStartParams, TurnStartParams, NotificationHandler, ApprovalHandler, ApprovalDecision, } from "./app-server-client.js";
|
|
20
|
+
export declare function detect(): boolean;
|
|
21
|
+
declare const _default: {
|
|
22
|
+
manifest: {
|
|
23
|
+
name: string;
|
|
24
|
+
slot: "agent";
|
|
25
|
+
description: string;
|
|
26
|
+
version: string;
|
|
27
|
+
displayName: string;
|
|
28
|
+
};
|
|
29
|
+
create: typeof create;
|
|
30
|
+
detect: typeof detect;
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,KAAK,EAYX,MAAM,gCAAgC,CAAC;AAgBxC,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC;AAsWF;;;;GAIG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,CAkC1D;AA+eD,wBAAgB,MAAM,IAAI,KAAK,CAE9B;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,MAAM,IAAI,OAAO,CAWhC;;;;;;;;;;;;AAED,wBAA0E"}
|