@yu_robotics/remote-cli 1.6.0 → 1.6.2
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/client/MessageHandler.d.ts +6 -3
- package/dist/client/MessageHandler.d.ts.map +1 -1
- package/dist/client/MessageHandler.js +116 -9
- package/dist/client/MessageHandler.js.map +1 -1
- package/dist/executor/CodexAppServerClient.d.ts +60 -0
- package/dist/executor/CodexAppServerClient.d.ts.map +1 -0
- package/dist/executor/CodexAppServerClient.js +267 -0
- package/dist/executor/CodexAppServerClient.js.map +1 -0
- package/dist/executor/CodexAppServerExecutor.d.ts +88 -0
- package/dist/executor/CodexAppServerExecutor.d.ts.map +1 -0
- package/dist/executor/CodexAppServerExecutor.js +752 -0
- package/dist/executor/CodexAppServerExecutor.js.map +1 -0
- package/dist/executor/CodexExecutor.d.ts +14 -1
- package/dist/executor/CodexExecutor.d.ts.map +1 -1
- package/dist/executor/CodexExecutor.js +94 -6
- package/dist/executor/CodexExecutor.js.map +1 -1
- package/dist/executor/IExecutor.d.ts +16 -1
- package/dist/executor/IExecutor.d.ts.map +1 -1
- package/dist/executor/index.d.ts +4 -3
- package/dist/executor/index.d.ts.map +1 -1
- package/dist/executor/index.js +20 -5
- package/dist/executor/index.js.map +1 -1
- package/dist/security/HooksConfigurator.d.ts.map +1 -1
- package/dist/security/HooksConfigurator.js +18 -9
- package/dist/security/HooksConfigurator.js.map +1 -1
- package/dist/thread/ThreadExecutorPool.d.ts +1 -1
- package/dist/thread/ThreadExecutorPool.d.ts.map +1 -1
- package/dist/thread/ThreadExecutorPool.js +4 -1
- package/dist/thread/ThreadExecutorPool.js.map +1 -1
- package/dist/thread/ThreadManager.d.ts +1 -1
- package/dist/thread/ThreadManager.d.ts.map +1 -1
- package/dist/thread/ThreadManager.js.map +1 -1
- package/dist/thread/types.d.ts +2 -0
- package/dist/thread/types.d.ts.map +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodexAppServerClient = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const string_decoder_1 = require("string_decoder");
|
|
6
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
7
|
+
const DEFAULT_KILL_ESCALATION_MS = 3_000;
|
|
8
|
+
const STDERR_TAIL_LIMIT = 4_000;
|
|
9
|
+
/**
|
|
10
|
+
* Minimal stdio JSON-RPC client for `codex app-server`.
|
|
11
|
+
*
|
|
12
|
+
* The protocol intentionally has no `jsonrpc` field. Each payload is encoded
|
|
13
|
+
* as one JSON object per line. Unknown notifications are forwarded to callers
|
|
14
|
+
* so newer Codex versions remain additive instead of breaking the transport.
|
|
15
|
+
*/
|
|
16
|
+
class CodexAppServerClient {
|
|
17
|
+
command;
|
|
18
|
+
cwd;
|
|
19
|
+
requestTimeoutMs;
|
|
20
|
+
killEscalationMs;
|
|
21
|
+
proc = null;
|
|
22
|
+
startPromise = null;
|
|
23
|
+
nextRequestId = 1;
|
|
24
|
+
pending = new Map();
|
|
25
|
+
handlers = new Set();
|
|
26
|
+
decoder = new string_decoder_1.StringDecoder('utf8');
|
|
27
|
+
stdoutBuffer = '';
|
|
28
|
+
stderrTail = '';
|
|
29
|
+
stopping = false;
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
this.command = options.command ?? 'codex';
|
|
32
|
+
this.cwd = options.cwd;
|
|
33
|
+
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
34
|
+
this.killEscalationMs = options.killEscalationMs ?? DEFAULT_KILL_ESCALATION_MS;
|
|
35
|
+
}
|
|
36
|
+
setWorkingDirectory(cwd) {
|
|
37
|
+
this.cwd = cwd;
|
|
38
|
+
}
|
|
39
|
+
isRunning() {
|
|
40
|
+
return this.proc !== null;
|
|
41
|
+
}
|
|
42
|
+
onMessage(handler) {
|
|
43
|
+
this.handlers.add(handler);
|
|
44
|
+
return () => this.handlers.delete(handler);
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
if (this.proc)
|
|
48
|
+
return;
|
|
49
|
+
if (this.startPromise)
|
|
50
|
+
return this.startPromise;
|
|
51
|
+
this.startPromise = this.startInternal();
|
|
52
|
+
try {
|
|
53
|
+
await this.startPromise;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
this.startPromise = null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async startInternal() {
|
|
60
|
+
this.stopping = false;
|
|
61
|
+
this.stdoutBuffer = '';
|
|
62
|
+
this.stderrTail = '';
|
|
63
|
+
this.decoder = new string_decoder_1.StringDecoder('utf8');
|
|
64
|
+
let proc;
|
|
65
|
+
try {
|
|
66
|
+
proc = (0, child_process_1.spawn)(this.command, ['app-server', '--stdio'], {
|
|
67
|
+
cwd: this.cwd,
|
|
68
|
+
env: { ...process.env },
|
|
69
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw this.friendlySpawnError(error);
|
|
74
|
+
}
|
|
75
|
+
this.proc = proc;
|
|
76
|
+
proc.stdout?.on('data', (data) => this.handleStdout(proc, data));
|
|
77
|
+
proc.stderr?.on('data', (data) => {
|
|
78
|
+
if (proc !== this.proc)
|
|
79
|
+
return;
|
|
80
|
+
this.stderrTail = (this.stderrTail + data.toString()).slice(-STDERR_TAIL_LIMIT);
|
|
81
|
+
});
|
|
82
|
+
proc.stdin?.on('error', (error) => {
|
|
83
|
+
if (proc === this.proc && !this.stopping) {
|
|
84
|
+
this.failAll(new Error(`Codex app-server stdin error: ${error.message}`));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
proc.on('error', (error) => {
|
|
88
|
+
if (proc !== this.proc)
|
|
89
|
+
return;
|
|
90
|
+
this.proc = null;
|
|
91
|
+
this.failAll(this.friendlySpawnError(error));
|
|
92
|
+
});
|
|
93
|
+
proc.on('close', (code, signal) => {
|
|
94
|
+
if (proc !== this.proc)
|
|
95
|
+
return;
|
|
96
|
+
this.stdoutBuffer += this.decoder.end();
|
|
97
|
+
if (this.stdoutBuffer.trim())
|
|
98
|
+
this.handleLine(this.stdoutBuffer);
|
|
99
|
+
this.stdoutBuffer = '';
|
|
100
|
+
this.proc = null;
|
|
101
|
+
if (!this.stopping) {
|
|
102
|
+
const tail = this.stderrTail.trim().slice(-500);
|
|
103
|
+
this.failAll(new Error(`Codex app-server exited unexpectedly (${code ?? signal ?? 'unknown'})${tail ? `: ${tail}` : ''}`));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
await this.requestRaw('initialize', {
|
|
108
|
+
clientInfo: {
|
|
109
|
+
name: 'remote_cli',
|
|
110
|
+
title: 'Remote CLI',
|
|
111
|
+
version: this.getClientVersion(),
|
|
112
|
+
},
|
|
113
|
+
capabilities: null,
|
|
114
|
+
});
|
|
115
|
+
this.notify('initialized');
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
await this.stop();
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async request(method, params, timeoutMs = this.requestTimeoutMs) {
|
|
123
|
+
await this.start();
|
|
124
|
+
return this.requestRaw(method, params, timeoutMs);
|
|
125
|
+
}
|
|
126
|
+
notify(method, params) {
|
|
127
|
+
const message = { method };
|
|
128
|
+
if (params !== undefined)
|
|
129
|
+
message.params = params;
|
|
130
|
+
this.write(message);
|
|
131
|
+
}
|
|
132
|
+
respond(id, result) {
|
|
133
|
+
this.write({ id, result });
|
|
134
|
+
}
|
|
135
|
+
respondError(id, message, code = -32601) {
|
|
136
|
+
this.write({ id, error: { code, message } });
|
|
137
|
+
}
|
|
138
|
+
async stop() {
|
|
139
|
+
const proc = this.proc;
|
|
140
|
+
this.startPromise = null;
|
|
141
|
+
this.stopping = true;
|
|
142
|
+
this.proc = null;
|
|
143
|
+
this.failAll(new Error('Codex app-server stopped'));
|
|
144
|
+
if (!proc)
|
|
145
|
+
return;
|
|
146
|
+
try {
|
|
147
|
+
proc.stdin?.end();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// The stream may already be closed.
|
|
151
|
+
}
|
|
152
|
+
let exited = false;
|
|
153
|
+
proc.once('exit', () => { exited = true; });
|
|
154
|
+
proc.kill();
|
|
155
|
+
const escalation = setTimeout(() => {
|
|
156
|
+
if (!exited)
|
|
157
|
+
proc.kill('SIGKILL');
|
|
158
|
+
}, this.killEscalationMs);
|
|
159
|
+
if (typeof escalation.unref === 'function')
|
|
160
|
+
escalation.unref();
|
|
161
|
+
}
|
|
162
|
+
requestRaw(method, params, timeoutMs = this.requestTimeoutMs) {
|
|
163
|
+
const id = this.nextRequestId++;
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const timer = setTimeout(() => {
|
|
166
|
+
this.pending.delete(id);
|
|
167
|
+
reject(new Error(`Codex app-server request timed out: ${method}`));
|
|
168
|
+
}, timeoutMs);
|
|
169
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
170
|
+
try {
|
|
171
|
+
const message = { id, method };
|
|
172
|
+
if (params !== undefined)
|
|
173
|
+
message.params = params;
|
|
174
|
+
this.write(message);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
this.pending.delete(id);
|
|
179
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
write(message) {
|
|
184
|
+
const stdin = this.proc?.stdin;
|
|
185
|
+
if (!stdin || stdin.destroyed || !stdin.writable) {
|
|
186
|
+
throw new Error('Codex app-server is not running');
|
|
187
|
+
}
|
|
188
|
+
stdin.write(`${JSON.stringify(message)}\n`);
|
|
189
|
+
}
|
|
190
|
+
handleStdout(proc, data) {
|
|
191
|
+
if (proc !== this.proc)
|
|
192
|
+
return;
|
|
193
|
+
this.stdoutBuffer += this.decoder.write(data);
|
|
194
|
+
const lines = this.stdoutBuffer.split('\n');
|
|
195
|
+
this.stdoutBuffer = lines.pop() ?? '';
|
|
196
|
+
for (const line of lines) {
|
|
197
|
+
if (line.trim())
|
|
198
|
+
this.handleLine(line);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
handleLine(line) {
|
|
202
|
+
let message;
|
|
203
|
+
try {
|
|
204
|
+
message = JSON.parse(line);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (message.id !== undefined && message.method === undefined) {
|
|
210
|
+
const pending = this.pending.get(message.id);
|
|
211
|
+
if (!pending)
|
|
212
|
+
return;
|
|
213
|
+
this.pending.delete(message.id);
|
|
214
|
+
clearTimeout(pending.timer);
|
|
215
|
+
if (message.error) {
|
|
216
|
+
const error = new Error(message.error.message ?? 'Codex app-server request failed');
|
|
217
|
+
Object.assign(error, { code: message.error.code, data: message.error.data });
|
|
218
|
+
pending.reject(error);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
pending.resolve(message.result);
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
for (const handler of this.handlers) {
|
|
226
|
+
try {
|
|
227
|
+
handler(message);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
console.error('[CodexAppServerClient] Message handler failed:', error);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
failAll(error) {
|
|
235
|
+
for (const pending of this.pending.values()) {
|
|
236
|
+
clearTimeout(pending.timer);
|
|
237
|
+
pending.reject(error);
|
|
238
|
+
}
|
|
239
|
+
this.pending.clear();
|
|
240
|
+
for (const handler of this.handlers) {
|
|
241
|
+
try {
|
|
242
|
+
handler({ method: 'client/disconnected', params: { error: error.message } });
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// A disconnect must continue notifying the remaining handlers.
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
friendlySpawnError(error) {
|
|
250
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
251
|
+
if (message.includes('ENOENT')) {
|
|
252
|
+
return new Error('Codex CLI (codex) is not installed or not found on PATH. Install it with `npm i -g @openai/codex`, or use /backend to switch to another backend.');
|
|
253
|
+
}
|
|
254
|
+
return new Error(`Failed to start Codex app-server: ${message}`);
|
|
255
|
+
}
|
|
256
|
+
getClientVersion() {
|
|
257
|
+
try {
|
|
258
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
259
|
+
return require('../../package.json').version ?? 'unknown';
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return 'unknown';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.CodexAppServerClient = CodexAppServerClient;
|
|
267
|
+
//# sourceMappingURL=CodexAppServerClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodexAppServerClient.js","sourceRoot":"","sources":["../../src/executor/CodexAppServerClient.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AACpD,mDAA+C;AAyB/C,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,0BAA0B,GAAG,KAAK,CAAC;AACzC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC;;;;;;GAMG;AACH,MAAa,oBAAoB;IACd,OAAO,CAAS;IACzB,GAAG,CAAU;IACJ,gBAAgB,CAAS;IACzB,gBAAgB,CAAS;IAClC,IAAI,GAAwB,IAAI,CAAC;IACjC,YAAY,GAAyB,IAAI,CAAC;IAC1C,aAAa,GAAG,CAAC,CAAC;IAClB,OAAO,GAAG,IAAI,GAAG,EAAmC,CAAC;IACrD,QAA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ACH,CAAC;CACF;AA7PD,oDA6PC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { DirectoryGuard } from '../security/DirectoryGuard';
|
|
2
|
+
import type { ExecuteOptions, ExecuteResult, ExecutorModelInfo, IExecutor } from './IExecutor';
|
|
3
|
+
import { AppServerMessage } from './CodexAppServerClient';
|
|
4
|
+
export interface CodexAppServerTransport {
|
|
5
|
+
start(): Promise<void>;
|
|
6
|
+
request(method: string, params?: any, timeoutMs?: number): Promise<any>;
|
|
7
|
+
respond(id: number | string, result: any): void;
|
|
8
|
+
respondError(id: number | string, message: string, code?: number): void;
|
|
9
|
+
onMessage(handler: (message: AppServerMessage) => void): () => void;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
isRunning(): boolean;
|
|
12
|
+
setWorkingDirectory(cwd: string): void;
|
|
13
|
+
}
|
|
14
|
+
export interface CodexAppServerExecutorOptions {
|
|
15
|
+
model?: string;
|
|
16
|
+
effort?: string;
|
|
17
|
+
autoApprove?: boolean;
|
|
18
|
+
initialWorkingDirectory?: string;
|
|
19
|
+
codexCommand?: string;
|
|
20
|
+
threadId?: string;
|
|
21
|
+
inactivityTimeoutMs?: number;
|
|
22
|
+
compactTimeoutMs?: number;
|
|
23
|
+
clientFactory?: (cwd: string) => CodexAppServerTransport;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Persistent Codex executor backed by the official app-server protocol.
|
|
27
|
+
* One instance is owned by one remote-cli thread, preserving the existing
|
|
28
|
+
* ThreadExecutorPool isolation model.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CodexAppServerExecutor implements IExecutor {
|
|
31
|
+
private readonly directoryGuard;
|
|
32
|
+
private currentWorkingDirectory;
|
|
33
|
+
private model?;
|
|
34
|
+
private effort?;
|
|
35
|
+
private readonly autoApprove;
|
|
36
|
+
private readonly remoteThreadId?;
|
|
37
|
+
private readonly sessionFilePath;
|
|
38
|
+
private readonly inactivityTimeoutMs;
|
|
39
|
+
private readonly compactTimeoutMs;
|
|
40
|
+
private readonly client;
|
|
41
|
+
private unsubscribeClient;
|
|
42
|
+
private codexThreadId;
|
|
43
|
+
private threadReady;
|
|
44
|
+
private activeTurn;
|
|
45
|
+
private compactWaiter;
|
|
46
|
+
private pendingUserInputs;
|
|
47
|
+
private inactivityTimer;
|
|
48
|
+
private destroyed;
|
|
49
|
+
constructor(directoryGuard: DirectoryGuard, options?: CodexAppServerExecutorOptions);
|
|
50
|
+
execute(prompt: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
51
|
+
getCurrentWorkingDirectory(): string;
|
|
52
|
+
setWorkingDirectory(targetPath: string): Promise<void>;
|
|
53
|
+
resetContext(): void;
|
|
54
|
+
abort(): Promise<boolean>;
|
|
55
|
+
destroy(): Promise<void>;
|
|
56
|
+
isProcessRunning(): boolean;
|
|
57
|
+
getSessionId(): string | null;
|
|
58
|
+
isWaitingInput(): boolean;
|
|
59
|
+
sendInput(input: string): boolean;
|
|
60
|
+
listModels(): Promise<ExecutorModelInfo[]>;
|
|
61
|
+
setModel(model: string): Promise<ExecuteResult>;
|
|
62
|
+
clearModel(): void;
|
|
63
|
+
setEffort(effort: string): Promise<ExecuteResult>;
|
|
64
|
+
compactWhenFull(_onStream?: (chunk: string) => void): Promise<ExecuteResult>;
|
|
65
|
+
deleteThreadData(_threadId: string): Promise<void>;
|
|
66
|
+
private ensureThread;
|
|
67
|
+
private handleMessage;
|
|
68
|
+
private handleServerRequest;
|
|
69
|
+
private handleItemStarted;
|
|
70
|
+
private handleItemCompleted;
|
|
71
|
+
private handleTurnCompleted;
|
|
72
|
+
private emitToolUse;
|
|
73
|
+
private completeActive;
|
|
74
|
+
private completeCompact;
|
|
75
|
+
private failAndRestart;
|
|
76
|
+
private armInactivityTimer;
|
|
77
|
+
private clearInactivityTimer;
|
|
78
|
+
private buildInput;
|
|
79
|
+
private cleanupTemporaryFiles;
|
|
80
|
+
private extensionForMimeType;
|
|
81
|
+
private loadThreadId;
|
|
82
|
+
private setThreadId;
|
|
83
|
+
private clearThreadId;
|
|
84
|
+
private extractErrorCode;
|
|
85
|
+
private stringifyResult;
|
|
86
|
+
private errorMessage;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=CodexAppServerExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodexAppServerExecutor.d.ts","sourceRoot":"","sources":["../../src/executor/CodexAppServerExecutor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAwB,MAAM,wBAAwB,CAAC;AAEhF,MAAM,WAAW,uBAAuB;IACtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IAChD,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,SAAS,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,SAAS,IAAI,OAAO,CAAC;IACrB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,C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