@resolveio/server-lib 20.13.11 → 20.14.0

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.
Files changed (60) hide show
  1. package/collections/ai-terminal-conversation.collection.d.ts +2 -0
  2. package/collections/ai-terminal-conversation.collection.js +133 -0
  3. package/collections/ai-terminal-conversation.collection.js.map +1 -0
  4. package/collections/ai-terminal-message.collection.d.ts +2 -0
  5. package/collections/ai-terminal-message.collection.js +113 -0
  6. package/collections/ai-terminal-message.collection.js.map +1 -0
  7. package/collections/communication-metric.collection.d.ts +2 -0
  8. package/collections/communication-metric.collection.js +133 -0
  9. package/collections/communication-metric.collection.js.map +1 -0
  10. package/collections/openai-usage-ledger.collection.d.ts +2 -0
  11. package/collections/openai-usage-ledger.collection.js +120 -0
  12. package/collections/openai-usage-ledger.collection.js.map +1 -0
  13. package/managers/communication-metric.manager.d.ts +16 -0
  14. package/managers/communication-metric.manager.js +134 -0
  15. package/managers/communication-metric.manager.js.map +1 -0
  16. package/managers/method.manager.d.ts +2 -0
  17. package/managers/method.manager.js +162 -45
  18. package/managers/method.manager.js.map +1 -1
  19. package/managers/openai-usage-ledger.manager.d.ts +14 -0
  20. package/managers/openai-usage-ledger.manager.js +137 -0
  21. package/managers/openai-usage-ledger.manager.js.map +1 -0
  22. package/managers/subscription.manager.js +2 -0
  23. package/managers/subscription.manager.js.map +1 -1
  24. package/methods/ai-terminal.d.ts +1 -0
  25. package/methods/ai-terminal.js +1200 -0
  26. package/methods/ai-terminal.js.map +1 -0
  27. package/methods/report-builder.js +741 -0
  28. package/methods/report-builder.js.map +1 -1
  29. package/methods.ts +27 -0
  30. package/models/ai-terminal-conversation.model.d.ts +16 -0
  31. package/models/ai-terminal-conversation.model.js +4 -0
  32. package/models/ai-terminal-conversation.model.js.map +1 -0
  33. package/models/ai-terminal-message.model.d.ts +22 -0
  34. package/models/ai-terminal-message.model.js +4 -0
  35. package/models/ai-terminal-message.model.js.map +1 -0
  36. package/models/communication-metric.model.d.ts +20 -0
  37. package/models/communication-metric.model.js +4 -0
  38. package/models/communication-metric.model.js.map +1 -0
  39. package/models/openai-usage-ledger.model.d.ts +14 -0
  40. package/models/openai-usage-ledger.model.js +4 -0
  41. package/models/openai-usage-ledger.model.js.map +1 -0
  42. package/package.json +5 -1
  43. package/public_api.d.ts +13 -0
  44. package/public_api.js +13 -0
  45. package/public_api.js.map +1 -1
  46. package/publications/ai-terminal.d.ts +1 -0
  47. package/publications/ai-terminal.js +58 -0
  48. package/publications/ai-terminal.js.map +1 -0
  49. package/publications.ts +6 -0
  50. package/services/codex-client.d.ts +81 -0
  51. package/services/codex-client.js +991 -0
  52. package/services/codex-client.js.map +1 -0
  53. package/services/openai-client.d.ts +46 -0
  54. package/services/openai-client.js +315 -0
  55. package/services/openai-client.js.map +1 -0
  56. package/util/common.js +20 -53
  57. package/util/common.js.map +1 -1
  58. package/util/tokenizer.d.ts +5 -0
  59. package/util/tokenizer.js +35 -0
  60. package/util/tokenizer.js.map +1 -0
@@ -0,0 +1,991 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
50
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
51
+ var m = o[Symbol.asyncIterator], i;
52
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
53
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
54
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
55
+ };
56
+ var __read = (this && this.__read) || function (o, n) {
57
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
58
+ if (!m) return o;
59
+ var i = m.call(o), r, ar = [], e;
60
+ try {
61
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
62
+ }
63
+ catch (error) { e = { error: error }; }
64
+ finally {
65
+ try {
66
+ if (r && !r.done && (m = i["return"])) m.call(i);
67
+ }
68
+ finally { if (e) throw e.error; }
69
+ }
70
+ return ar;
71
+ };
72
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
+ if (ar || !(i in from)) {
75
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
+ ar[i] = from[i];
77
+ }
78
+ }
79
+ return to.concat(ar || Array.prototype.slice.call(from));
80
+ };
81
+ var __values = (this && this.__values) || function(o) {
82
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
83
+ if (m) return m.call(o);
84
+ if (o && typeof o.length === "number") return {
85
+ next: function () {
86
+ if (o && i >= o.length) o = void 0;
87
+ return { value: o && o[i++], done: !o };
88
+ }
89
+ };
90
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
91
+ };
92
+ Object.defineProperty(exports, "__esModule", { value: true });
93
+ exports.CodexClient = void 0;
94
+ var fs_1 = require("fs");
95
+ var os = require("os");
96
+ var path = require("path");
97
+ var promises_1 = require("timers/promises");
98
+ var CodexClient = /** @class */ (function () {
99
+ function CodexClient(config) {
100
+ this.codex = null;
101
+ this.codexInit = null;
102
+ this.threadCache = new Map();
103
+ this.debugEnabled = (process.env.AI_DASHBOARD_DEBUG || '').trim().toLowerCase() === 'true';
104
+ this.streamEnabled = this.resolveStreamEnabled();
105
+ this.cleanZdotdirEnabled = this.resolveCleanZdotdirEnabled();
106
+ this.zDotDir = null;
107
+ this.defaultTimeoutMs = this.resolveDefaultTimeoutMs();
108
+ this.defaultThreadOptions = this.resolveDefaultThreadOptions();
109
+ this.pingEnabled = this.resolvePingEnabled();
110
+ this.pingTimeoutMs = this.resolvePingTimeoutMs();
111
+ this.config = config;
112
+ if (!this.config.apiKey) {
113
+ throw new Error('OPENAI_API_KEY is required for CodexClient');
114
+ }
115
+ }
116
+ CodexClient.prototype.run = function (prompt, options) {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var maxRetries, retryDelayMs, attempt, lastError, error_1, message, delay;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ maxRetries = this.normalizeRetryCount(this.config.maxRetries);
123
+ retryDelayMs = this.normalizeRetryDelay(this.config.retryDelayMs);
124
+ attempt = 0;
125
+ lastError = null;
126
+ if (!(this.pingEnabled && !this.isPingPrompt(prompt))) return [3 /*break*/, 2];
127
+ return [4 /*yield*/, this.runPing(options === null || options === void 0 ? void 0 : options.threadOptions)];
128
+ case 1:
129
+ _a.sent();
130
+ _a.label = 2;
131
+ case 2:
132
+ if (!(attempt <= maxRetries)) return [3 /*break*/, 10];
133
+ _a.label = 3;
134
+ case 3:
135
+ _a.trys.push([3, 7, , 9]);
136
+ this.log("run attempt ".concat(attempt + 1, "/").concat(maxRetries + 1));
137
+ if (!(this.streamEnabled && !this.isPingPrompt(prompt))) return [3 /*break*/, 5];
138
+ return [4 /*yield*/, this.runStreamedOnce(prompt, options)];
139
+ case 4: return [2 /*return*/, _a.sent()];
140
+ case 5: return [4 /*yield*/, this.runOnce(prompt, options)];
141
+ case 6: return [2 /*return*/, _a.sent()];
142
+ case 7:
143
+ error_1 = _a.sent();
144
+ lastError = error_1;
145
+ message = error_1 instanceof Error ? error_1.message : String(error_1 || 'Unknown error');
146
+ this.log("run attempt ".concat(attempt + 1, " failed: ").concat(message));
147
+ if (attempt >= maxRetries || !this.isRetryableError(error_1)) {
148
+ return [3 /*break*/, 10];
149
+ }
150
+ delay = retryDelayMs * Math.pow(2, attempt);
151
+ return [4 /*yield*/, this.sleep(delay)];
152
+ case 8:
153
+ _a.sent();
154
+ attempt += 1;
155
+ return [3 /*break*/, 9];
156
+ case 9: return [3 /*break*/, 2];
157
+ case 10: throw lastError;
158
+ }
159
+ });
160
+ });
161
+ };
162
+ CodexClient.prototype.runStreamedOnce = function (prompt, options) {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var startedAt, thread, timeoutMs, controller, timeoutId, finalResponse, lastText, events, _a, events_1, events_1_1, event_1, error_2, message, e_1_1, error_3, message;
165
+ var _this = this;
166
+ var _b, e_1, _c, _d;
167
+ var _e, _f, _g;
168
+ return __generator(this, function (_h) {
169
+ switch (_h.label) {
170
+ case 0:
171
+ startedAt = Date.now();
172
+ this.log("runStreamed start (promptLength=".concat(prompt.length, ")"));
173
+ return [4 /*yield*/, this.startThread(options === null || options === void 0 ? void 0 : options.threadOptions, options === null || options === void 0 ? void 0 : options.threadKey, options === null || options === void 0 ? void 0 : options.reuseThread)];
174
+ case 1:
175
+ thread = _h.sent();
176
+ timeoutMs = (_e = options === null || options === void 0 ? void 0 : options.timeoutMs) !== null && _e !== void 0 ? _e : this.defaultTimeoutMs;
177
+ controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
178
+ timeoutId = controller
179
+ ? setTimeout(function () { return controller.abort(); }, timeoutMs)
180
+ : null;
181
+ finalResponse = '';
182
+ lastText = '';
183
+ _h.label = 2;
184
+ case 2:
185
+ _h.trys.push([2, 21, 22, 23]);
186
+ return [4 /*yield*/, thread.runStreamed(prompt, controller ? { signal: controller.signal } : undefined)];
187
+ case 3:
188
+ events = (_h.sent()).events;
189
+ _h.label = 4;
190
+ case 4:
191
+ _h.trys.push([4, 14, 15, 20]);
192
+ _a = true, events_1 = __asyncValues(events);
193
+ _h.label = 5;
194
+ case 5: return [4 /*yield*/, events_1.next()];
195
+ case 6:
196
+ if (!(events_1_1 = _h.sent(), _b = events_1_1.done, !_b)) return [3 /*break*/, 13];
197
+ _d = events_1_1.value;
198
+ _a = false;
199
+ event_1 = _d;
200
+ if (!(options === null || options === void 0 ? void 0 : options.onStreamEvent)) return [3 /*break*/, 10];
201
+ _h.label = 7;
202
+ case 7:
203
+ _h.trys.push([7, 9, , 10]);
204
+ return [4 /*yield*/, options.onStreamEvent(event_1)];
205
+ case 8:
206
+ _h.sent();
207
+ return [3 /*break*/, 10];
208
+ case 9:
209
+ error_2 = _h.sent();
210
+ message = error_2 instanceof Error ? error_2.message : String(error_2 || 'Unknown error');
211
+ this.log("onStreamEvent failed: ".concat(message));
212
+ return [3 /*break*/, 10];
213
+ case 10: return [4 /*yield*/, this.handleStreamEvent(event_1, function (text) { return __awaiter(_this, void 0, void 0, function () {
214
+ var next, delta, error_4, message;
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0:
218
+ next = text || '';
219
+ if (!next) {
220
+ return [2 /*return*/];
221
+ }
222
+ delta = next.startsWith(lastText) ? next.slice(lastText.length) : next;
223
+ if (!delta) return [3 /*break*/, 4];
224
+ this.logStreamText(delta);
225
+ if (!(options === null || options === void 0 ? void 0 : options.onStreamText)) return [3 /*break*/, 4];
226
+ _a.label = 1;
227
+ case 1:
228
+ _a.trys.push([1, 3, , 4]);
229
+ return [4 /*yield*/, options.onStreamText(delta, next)];
230
+ case 2:
231
+ _a.sent();
232
+ return [3 /*break*/, 4];
233
+ case 3:
234
+ error_4 = _a.sent();
235
+ message = error_4 instanceof Error ? error_4.message : String(error_4 || 'Unknown error');
236
+ this.log("onStreamText failed: ".concat(message));
237
+ return [3 /*break*/, 4];
238
+ case 4:
239
+ lastText = next;
240
+ finalResponse = next;
241
+ return [2 /*return*/];
242
+ }
243
+ });
244
+ }); })];
245
+ case 11:
246
+ _h.sent();
247
+ if ((event_1 === null || event_1 === void 0 ? void 0 : event_1.type) === 'turn.failed') {
248
+ throw new Error(((_f = event_1.error) === null || _f === void 0 ? void 0 : _f.message) || 'Codex turn failed.');
249
+ }
250
+ if ((event_1 === null || event_1 === void 0 ? void 0 : event_1.type) === 'error') {
251
+ throw new Error(event_1.message || 'Codex stream error.');
252
+ }
253
+ _h.label = 12;
254
+ case 12:
255
+ _a = true;
256
+ return [3 /*break*/, 5];
257
+ case 13: return [3 /*break*/, 20];
258
+ case 14:
259
+ e_1_1 = _h.sent();
260
+ e_1 = { error: e_1_1 };
261
+ return [3 /*break*/, 20];
262
+ case 15:
263
+ _h.trys.push([15, , 18, 19]);
264
+ if (!(!_a && !_b && (_c = events_1.return))) return [3 /*break*/, 17];
265
+ return [4 /*yield*/, _c.call(events_1)];
266
+ case 16:
267
+ _h.sent();
268
+ _h.label = 17;
269
+ case 17: return [3 /*break*/, 19];
270
+ case 18:
271
+ if (e_1) throw e_1.error;
272
+ return [7 /*endfinally*/];
273
+ case 19: return [7 /*endfinally*/];
274
+ case 20: return [3 /*break*/, 23];
275
+ case 21:
276
+ error_3 = _h.sent();
277
+ if ((_g = controller === null || controller === void 0 ? void 0 : controller.signal) === null || _g === void 0 ? void 0 : _g.aborted) {
278
+ this.log("runStreamed timed out (durationMs=".concat(Date.now() - startedAt, ")"));
279
+ throw new Error('Codex request timed out.');
280
+ }
281
+ message = error_3 instanceof Error ? error_3.message : String(error_3 || 'Unknown error');
282
+ this.log("runStreamed failed (durationMs=".concat(Date.now() - startedAt, "): ").concat(message));
283
+ throw error_3;
284
+ case 22:
285
+ if (timeoutId) {
286
+ clearTimeout(timeoutId);
287
+ }
288
+ return [7 /*endfinally*/];
289
+ case 23:
290
+ if (!finalResponse) {
291
+ throw new Error('Codex returned no completion content.');
292
+ }
293
+ this.log("runStreamed complete (contentLength=".concat(finalResponse.length, ", durationMs=").concat(Date.now() - startedAt, ")"));
294
+ return [2 /*return*/, finalResponse.trim()];
295
+ }
296
+ });
297
+ });
298
+ };
299
+ CodexClient.prototype.runOnce = function (prompt, options) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ var startedAt, thread, runPromise, timeoutMs, result, content, error_5, message;
302
+ var _a;
303
+ return __generator(this, function (_b) {
304
+ switch (_b.label) {
305
+ case 0:
306
+ startedAt = Date.now();
307
+ this.log("runOnce start (promptLength=".concat(prompt.length, ")"));
308
+ _b.label = 1;
309
+ case 1:
310
+ _b.trys.push([1, 4, , 5]);
311
+ return [4 /*yield*/, this.startThread(options === null || options === void 0 ? void 0 : options.threadOptions, options === null || options === void 0 ? void 0 : options.threadKey, options === null || options === void 0 ? void 0 : options.reuseThread)];
312
+ case 2:
313
+ thread = _b.sent();
314
+ runPromise = thread.run(prompt);
315
+ timeoutMs = (_a = options === null || options === void 0 ? void 0 : options.timeoutMs) !== null && _a !== void 0 ? _a : this.defaultTimeoutMs;
316
+ this.log("runOnce awaiting result (timeoutMs=".concat(timeoutMs, ")"));
317
+ return [4 /*yield*/, this.withTimeout(runPromise, timeoutMs)];
318
+ case 3:
319
+ result = _b.sent();
320
+ content = this.extractContent(result);
321
+ if (!content) {
322
+ throw new Error('Codex returned no completion content.');
323
+ }
324
+ this.log("runOnce complete (contentLength=".concat(content.length, ", durationMs=").concat(Date.now() - startedAt, ")"));
325
+ return [2 /*return*/, content];
326
+ case 4:
327
+ error_5 = _b.sent();
328
+ message = error_5 instanceof Error ? error_5.message : String(error_5 || 'Unknown error');
329
+ this.log("runOnce failed (durationMs=".concat(Date.now() - startedAt, "): ").concat(message));
330
+ throw error_5;
331
+ case 5: return [2 /*return*/];
332
+ }
333
+ });
334
+ });
335
+ };
336
+ CodexClient.prototype.startThread = function (threadOptions_1, threadKey_1) {
337
+ return __awaiter(this, arguments, void 0, function (threadOptions, threadKey, reuseThread) {
338
+ var mergedOptions, cacheKey, existing, thread_1, thread;
339
+ if (reuseThread === void 0) { reuseThread = true; }
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0: return [4 /*yield*/, this.ensureCodex()];
343
+ case 1:
344
+ _a.sent();
345
+ mergedOptions = this.mergeThreadOptions(threadOptions);
346
+ cacheKey = this.buildThreadCacheKey(threadKey, mergedOptions);
347
+ if (reuseThread && cacheKey) {
348
+ existing = this.threadCache.get(cacheKey);
349
+ if (existing && existing.optionsKey === this.buildThreadOptionsKey(mergedOptions)) {
350
+ this.log("startThread reuse (".concat(cacheKey, ")"));
351
+ return [2 /*return*/, existing.thread];
352
+ }
353
+ }
354
+ this.log("startThread (model=".concat(this.config.model || 'default', ")"));
355
+ if (mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.model) {
356
+ this.log("startThread options: ".concat(this.formatThreadOptions(mergedOptions)));
357
+ thread_1 = this.codex.startThread(mergedOptions);
358
+ this.log('startThread created with model override');
359
+ if (cacheKey) {
360
+ this.threadCache.set(cacheKey, { thread: thread_1, optionsKey: this.buildThreadOptionsKey(mergedOptions) });
361
+ }
362
+ return [2 /*return*/, thread_1];
363
+ }
364
+ if (mergedOptions && Object.keys(mergedOptions).length) {
365
+ this.log("startThread options: ".concat(this.formatThreadOptions(mergedOptions)));
366
+ }
367
+ thread = this.codex.startThread(mergedOptions);
368
+ this.log('startThread created');
369
+ if (cacheKey) {
370
+ this.threadCache.set(cacheKey, { thread: thread, optionsKey: this.buildThreadOptionsKey(mergedOptions) });
371
+ }
372
+ return [2 /*return*/, thread];
373
+ }
374
+ });
375
+ });
376
+ };
377
+ CodexClient.prototype.extractContent = function (result) {
378
+ var _this = this;
379
+ if (!result) {
380
+ return '';
381
+ }
382
+ if (typeof result.finalResponse === 'string') {
383
+ return result.finalResponse.trim();
384
+ }
385
+ if (typeof result === 'string') {
386
+ return result.trim();
387
+ }
388
+ if (Array.isArray(result.items)) {
389
+ var lastMessage = __spreadArray([], __read(result.items), false).reverse().find(function (item) { return (item === null || item === void 0 ? void 0 : item.type) === 'agent_message' && typeof item.text === 'string'; });
390
+ if (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.text) {
391
+ return lastMessage.text.trim();
392
+ }
393
+ }
394
+ if (typeof result.output_text === 'string') {
395
+ return result.output_text.trim();
396
+ }
397
+ if (typeof result.outputText === 'string') {
398
+ return result.outputText.trim();
399
+ }
400
+ if (typeof result.content === 'string') {
401
+ return result.content.trim();
402
+ }
403
+ if (typeof result.text === 'string') {
404
+ return result.text.trim();
405
+ }
406
+ if (Array.isArray(result.content)) {
407
+ var text = result.content
408
+ .map(function (part) { return _this.extractPartText(part); })
409
+ .join('')
410
+ .trim();
411
+ if (text) {
412
+ return text;
413
+ }
414
+ }
415
+ if (Array.isArray(result.output)) {
416
+ var text = result.output
417
+ .map(function (item) {
418
+ if (!item) {
419
+ return '';
420
+ }
421
+ if (typeof item === 'string') {
422
+ return item;
423
+ }
424
+ if (typeof item.text === 'string') {
425
+ return item.text;
426
+ }
427
+ if (typeof item.content === 'string') {
428
+ return item.content;
429
+ }
430
+ if (Array.isArray(item.content)) {
431
+ return item.content.map(function (part) { return _this.extractPartText(part); }).join('');
432
+ }
433
+ return '';
434
+ })
435
+ .join('')
436
+ .trim();
437
+ if (text) {
438
+ return text;
439
+ }
440
+ }
441
+ return '';
442
+ };
443
+ CodexClient.prototype.handleStreamEvent = function (event, onAgentMessage) {
444
+ return __awaiter(this, void 0, void 0, function () {
445
+ var _a;
446
+ return __generator(this, function (_b) {
447
+ switch (_b.label) {
448
+ case 0:
449
+ if (!event || !event.type) {
450
+ return [2 /*return*/];
451
+ }
452
+ _a = event.type;
453
+ switch (_a) {
454
+ case 'thread.started': return [3 /*break*/, 1];
455
+ case 'turn.started': return [3 /*break*/, 2];
456
+ case 'turn.completed': return [3 /*break*/, 3];
457
+ case 'item.started': return [3 /*break*/, 4];
458
+ case 'item.updated': return [3 /*break*/, 4];
459
+ case 'item.completed': return [3 /*break*/, 4];
460
+ }
461
+ return [3 /*break*/, 6];
462
+ case 1:
463
+ this.log("stream thread.started (id=".concat(event.thread_id || 'unknown', ")"));
464
+ return [3 /*break*/, 7];
465
+ case 2:
466
+ this.log('stream turn.started');
467
+ return [3 /*break*/, 7];
468
+ case 3:
469
+ this.log('stream turn.completed');
470
+ return [3 /*break*/, 7];
471
+ case 4: return [4 /*yield*/, this.handleStreamItem(event.item, onAgentMessage)];
472
+ case 5:
473
+ _b.sent();
474
+ return [3 /*break*/, 7];
475
+ case 6: return [3 /*break*/, 7];
476
+ case 7: return [2 /*return*/];
477
+ }
478
+ });
479
+ });
480
+ };
481
+ CodexClient.prototype.handleStreamItem = function (item, onAgentMessage) {
482
+ return __awaiter(this, void 0, void 0, function () {
483
+ var _a, output, summary, total, done, snippet;
484
+ var _b;
485
+ return __generator(this, function (_c) {
486
+ switch (_c.label) {
487
+ case 0:
488
+ if (!item || !item.type) {
489
+ return [2 /*return*/];
490
+ }
491
+ _a = item.type;
492
+ switch (_a) {
493
+ case 'agent_message': return [3 /*break*/, 1];
494
+ case 'command_execution': return [3 /*break*/, 3];
495
+ case 'file_change': return [3 /*break*/, 4];
496
+ case 'mcp_tool_call': return [3 /*break*/, 5];
497
+ case 'web_search': return [3 /*break*/, 6];
498
+ case 'todo_list': return [3 /*break*/, 7];
499
+ case 'reasoning': return [3 /*break*/, 8];
500
+ case 'error': return [3 /*break*/, 9];
501
+ }
502
+ return [3 /*break*/, 10];
503
+ case 1: return [4 /*yield*/, onAgentMessage(item.text || '')];
504
+ case 2:
505
+ _c.sent();
506
+ return [3 /*break*/, 11];
507
+ case 3:
508
+ if (item.command) {
509
+ this.log("stream command: ".concat(item.command, " (").concat(item.status || 'unknown', ")"));
510
+ }
511
+ if (item.aggregated_output) {
512
+ output = item.aggregated_output.length > 800
513
+ ? "".concat(item.aggregated_output.slice(0, 800), "...")
514
+ : item.aggregated_output;
515
+ this.log("stream command output: ".concat(output));
516
+ }
517
+ return [3 /*break*/, 11];
518
+ case 4:
519
+ if (Array.isArray(item.changes) && item.changes.length) {
520
+ summary = item.changes.map(function (change) { return "".concat(change.kind, ":").concat(change.path); }).join(', ');
521
+ this.log("stream file_change (".concat(item.status || 'unknown', "): ").concat(summary));
522
+ }
523
+ return [3 /*break*/, 11];
524
+ case 5:
525
+ if (item.tool) {
526
+ this.log("stream tool_call: ".concat(item.tool, " (").concat(item.status || 'unknown', ")"));
527
+ }
528
+ if ((_b = item.error) === null || _b === void 0 ? void 0 : _b.message) {
529
+ this.log("stream tool_call error: ".concat(item.error.message));
530
+ }
531
+ return [3 /*break*/, 11];
532
+ case 6:
533
+ if (item.query) {
534
+ this.log("stream web_search: ".concat(item.query));
535
+ }
536
+ return [3 /*break*/, 11];
537
+ case 7:
538
+ if (Array.isArray(item.items)) {
539
+ total = item.items.length;
540
+ done = item.items.filter(function (entry) { return entry === null || entry === void 0 ? void 0 : entry.completed; }).length;
541
+ this.log("stream todo_list: ".concat(done, "/").concat(total, " completed"));
542
+ }
543
+ return [3 /*break*/, 11];
544
+ case 8:
545
+ if (item.text) {
546
+ snippet = item.text.length > 200 ? "".concat(item.text.slice(0, 200), "...") : item.text;
547
+ this.log("stream reasoning: ".concat(snippet));
548
+ }
549
+ return [3 /*break*/, 11];
550
+ case 9:
551
+ if (item.message) {
552
+ this.log("stream error: ".concat(item.message));
553
+ }
554
+ return [3 /*break*/, 11];
555
+ case 10: return [3 /*break*/, 11];
556
+ case 11: return [2 /*return*/];
557
+ }
558
+ });
559
+ });
560
+ };
561
+ CodexClient.prototype.logStreamText = function (text) {
562
+ var e_2, _a;
563
+ if (!this.debugEnabled) {
564
+ return;
565
+ }
566
+ var lines = text.split(/\r?\n/);
567
+ try {
568
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
569
+ var line = lines_1_1.value;
570
+ this.log("stream: ".concat(line));
571
+ }
572
+ }
573
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
574
+ finally {
575
+ try {
576
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
577
+ }
578
+ finally { if (e_2) throw e_2.error; }
579
+ }
580
+ };
581
+ CodexClient.prototype.extractPartText = function (part) {
582
+ if (!part) {
583
+ return '';
584
+ }
585
+ if (typeof part === 'string') {
586
+ return part;
587
+ }
588
+ if (typeof part.text === 'string') {
589
+ return part.text;
590
+ }
591
+ if (typeof part.content === 'string') {
592
+ return part.content;
593
+ }
594
+ return '';
595
+ };
596
+ CodexClient.prototype.withTimeout = function (promise, timeoutMs) {
597
+ return __awaiter(this, void 0, void 0, function () {
598
+ var done, startedAt, heartbeatMs, timeoutPromise;
599
+ var _this = this;
600
+ return __generator(this, function (_a) {
601
+ switch (_a.label) {
602
+ case 0:
603
+ done = false;
604
+ startedAt = Date.now();
605
+ heartbeatMs = Math.max(10000, Math.min(30000, Math.floor(timeoutMs / 4)));
606
+ timeoutPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
607
+ var elapsed, remaining, currentElapsed, currentRemaining;
608
+ return __generator(this, function (_a) {
609
+ switch (_a.label) {
610
+ case 0:
611
+ if (!!done) return [3 /*break*/, 4];
612
+ elapsed = Date.now() - startedAt;
613
+ if (elapsed >= timeoutMs) {
614
+ throw new Error('Codex request timed out.');
615
+ }
616
+ remaining = timeoutMs - elapsed;
617
+ return [4 /*yield*/, (0, promises_1.setTimeout)(Math.min(heartbeatMs, remaining))];
618
+ case 1:
619
+ _a.sent();
620
+ if (!done) return [3 /*break*/, 3];
621
+ return [4 /*yield*/, promise];
622
+ case 2: return [2 /*return*/, _a.sent()];
623
+ case 3:
624
+ currentElapsed = Date.now() - startedAt;
625
+ if (currentElapsed >= timeoutMs) {
626
+ throw new Error('Codex request timed out.');
627
+ }
628
+ currentRemaining = Math.max(0, timeoutMs - currentElapsed);
629
+ this.log("runOnce waiting (elapsedMs=".concat(currentElapsed, ", remainingMs=").concat(currentRemaining, ")"));
630
+ return [3 /*break*/, 0];
631
+ case 4: return [4 /*yield*/, promise];
632
+ case 5: return [2 /*return*/, _a.sent()];
633
+ }
634
+ });
635
+ }); })();
636
+ _a.label = 1;
637
+ case 1:
638
+ _a.trys.push([1, , 3, 4]);
639
+ return [4 /*yield*/, Promise.race([promise, timeoutPromise])];
640
+ case 2: return [2 /*return*/, _a.sent()];
641
+ case 3:
642
+ done = true;
643
+ return [7 /*endfinally*/];
644
+ case 4: return [2 /*return*/];
645
+ }
646
+ });
647
+ });
648
+ };
649
+ CodexClient.prototype.normalizeRetryCount = function (value) {
650
+ if (typeof value !== 'number' || Number.isNaN(value)) {
651
+ return 2;
652
+ }
653
+ return Math.max(0, Math.floor(value));
654
+ };
655
+ CodexClient.prototype.normalizeRetryDelay = function (value) {
656
+ if (typeof value !== 'number' || Number.isNaN(value)) {
657
+ return 500;
658
+ }
659
+ return Math.max(100, Math.floor(value));
660
+ };
661
+ CodexClient.prototype.isRetryableError = function (error) {
662
+ var message = error instanceof Error ? error.message : String(error || '');
663
+ if (/Codex returned no completion content/i.test(message)) {
664
+ return true;
665
+ }
666
+ var statusMatch = message.match(/\\b(429|5\\d{2})\\b/);
667
+ if (statusMatch) {
668
+ return true;
669
+ }
670
+ return /ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|fetch failed|timed out|timeout/i.test(message);
671
+ };
672
+ CodexClient.prototype.sleep = function (ms) {
673
+ return __awaiter(this, void 0, void 0, function () {
674
+ return __generator(this, function (_a) {
675
+ switch (_a.label) {
676
+ case 0: return [4 /*yield*/, (0, promises_1.setTimeout)(ms)];
677
+ case 1:
678
+ _a.sent();
679
+ return [2 /*return*/];
680
+ }
681
+ });
682
+ });
683
+ };
684
+ CodexClient.prototype.ensureCodex = function () {
685
+ return __awaiter(this, void 0, void 0, function () {
686
+ var _this = this;
687
+ return __generator(this, function (_a) {
688
+ switch (_a.label) {
689
+ case 0:
690
+ if (this.codex) {
691
+ return [2 /*return*/];
692
+ }
693
+ if (!(this.codexInit !== null)) return [3 /*break*/, 2];
694
+ return [4 /*yield*/, this.codexInit];
695
+ case 1:
696
+ _a.sent();
697
+ return [2 /*return*/];
698
+ case 2:
699
+ this.codexInit = (function () { return __awaiter(_this, void 0, void 0, function () {
700
+ var importer, mod, CodexCtor, env;
701
+ var _a;
702
+ return __generator(this, function (_b) {
703
+ switch (_b.label) {
704
+ case 0:
705
+ this.log('Loading Codex SDK module...');
706
+ importer = new Function('specifier', 'return import(specifier)');
707
+ return [4 /*yield*/, importer('@openai/codex-sdk')];
708
+ case 1:
709
+ mod = _b.sent();
710
+ CodexCtor = (mod === null || mod === void 0 ? void 0 : mod.Codex) || ((_a = mod === null || mod === void 0 ? void 0 : mod.default) === null || _a === void 0 ? void 0 : _a.Codex) || (mod === null || mod === void 0 ? void 0 : mod.default) || mod;
711
+ if (!CodexCtor) {
712
+ throw new Error('Codex SDK export not found.');
713
+ }
714
+ this.log('Codex SDK module loaded.');
715
+ return [4 /*yield*/, this.buildCodexEnv()];
716
+ case 2:
717
+ env = _b.sent();
718
+ this.codex = new CodexCtor({
719
+ apiKey: this.config.apiKey,
720
+ baseUrl: this.config.baseUrl,
721
+ model: this.config.model,
722
+ env: env
723
+ });
724
+ this.log('Codex client initialized.');
725
+ return [2 /*return*/];
726
+ }
727
+ });
728
+ }); })();
729
+ return [4 /*yield*/, this.codexInit];
730
+ case 3:
731
+ _a.sent();
732
+ return [2 /*return*/];
733
+ }
734
+ });
735
+ });
736
+ };
737
+ CodexClient.prototype.log = function (message) {
738
+ if (!this.debugEnabled) {
739
+ return;
740
+ }
741
+ console.log("[AI-Dashboard][Codex] ".concat(message));
742
+ };
743
+ CodexClient.prototype.resolveDefaultTimeoutMs = function () {
744
+ var raw = Number(process.env.AI_DASHBOARD_CODEX_TIMEOUT_MS || process.env.AI_DASHBOARD_AGENT_TIMEOUT_MS);
745
+ if (Number.isFinite(raw) && raw > 0) {
746
+ return Math.floor(raw);
747
+ }
748
+ return 600000;
749
+ };
750
+ CodexClient.prototype.resolveStreamEnabled = function () {
751
+ var raw = (process.env.AI_DASHBOARD_CODEX_STREAM || '').trim().toLowerCase();
752
+ if (!raw) {
753
+ return this.debugEnabled;
754
+ }
755
+ if (['true', '1', 'yes', 'y', 'on'].includes(raw)) {
756
+ return true;
757
+ }
758
+ if (['false', '0', 'no', 'n', 'off'].includes(raw)) {
759
+ return false;
760
+ }
761
+ return this.debugEnabled;
762
+ };
763
+ CodexClient.prototype.resolveCleanZdotdirEnabled = function () {
764
+ var _a;
765
+ var raw = ((_a = process.env.AI_DASHBOARD_CODEX_CLEAN_ZDOTDIR) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
766
+ if (!raw) {
767
+ return true;
768
+ }
769
+ if (['false', '0', 'no', 'n', 'off'].includes(raw)) {
770
+ return false;
771
+ }
772
+ if (['true', '1', 'yes', 'y', 'on'].includes(raw)) {
773
+ return true;
774
+ }
775
+ return true;
776
+ };
777
+ CodexClient.prototype.buildCodexEnv = function () {
778
+ return __awaiter(this, void 0, void 0, function () {
779
+ var env, _a, _b, _c, key, value, _d;
780
+ var e_3, _e;
781
+ return __generator(this, function (_f) {
782
+ switch (_f.label) {
783
+ case 0:
784
+ env = {};
785
+ try {
786
+ for (_a = __values(Object.entries(process.env)), _b = _a.next(); !_b.done; _b = _a.next()) {
787
+ _c = __read(_b.value, 2), key = _c[0], value = _c[1];
788
+ if (typeof value === 'string') {
789
+ env[key] = value;
790
+ }
791
+ }
792
+ }
793
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
794
+ finally {
795
+ try {
796
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
797
+ }
798
+ finally { if (e_3) throw e_3.error; }
799
+ }
800
+ if (!this.cleanZdotdirEnabled) return [3 /*break*/, 2];
801
+ _d = env;
802
+ return [4 /*yield*/, this.ensureZdotdir()];
803
+ case 1:
804
+ _d.ZDOTDIR = _f.sent();
805
+ _f.label = 2;
806
+ case 2: return [2 /*return*/, env];
807
+ }
808
+ });
809
+ });
810
+ };
811
+ CodexClient.prototype.ensureZdotdir = function () {
812
+ return __awaiter(this, void 0, void 0, function () {
813
+ var override, dir;
814
+ return __generator(this, function (_a) {
815
+ switch (_a.label) {
816
+ case 0:
817
+ if (this.zDotDir) {
818
+ return [2 /*return*/, this.zDotDir];
819
+ }
820
+ override = (process.env.AI_DASHBOARD_CODEX_ZDOTDIR || '').trim();
821
+ dir = override || path.join(os.tmpdir(), 'codex-zdotdir');
822
+ return [4 /*yield*/, fs_1.promises.mkdir(dir, { recursive: true })];
823
+ case 1:
824
+ _a.sent();
825
+ this.zDotDir = dir;
826
+ return [2 /*return*/, dir];
827
+ }
828
+ });
829
+ });
830
+ };
831
+ CodexClient.prototype.resolvePingEnabled = function () {
832
+ return this.normalizeBoolean(process.env.AI_DASHBOARD_CODEX_PING, false);
833
+ };
834
+ CodexClient.prototype.resolvePingTimeoutMs = function () {
835
+ var raw = Number(process.env.AI_DASHBOARD_CODEX_PING_TIMEOUT_MS);
836
+ if (Number.isFinite(raw) && raw > 0) {
837
+ return Math.floor(raw);
838
+ }
839
+ return 10000;
840
+ };
841
+ CodexClient.prototype.resolveDefaultThreadOptions = function () {
842
+ var approvalPolicy = this.normalizeApprovalPolicy(process.env.AI_DASHBOARD_CODEX_APPROVAL_POLICY);
843
+ var sandboxMode = this.normalizeSandboxMode(process.env.AI_DASHBOARD_CODEX_SANDBOX_MODE, 'workspace-write');
844
+ var skipGitRepoCheck = this.normalizeBoolean(process.env.AI_DASHBOARD_CODEX_SKIP_GIT_CHECK, true);
845
+ var webSearchMode = this.normalizeWebSearchMode(process.env.AI_DASHBOARD_CODEX_WEB_SEARCH_MODE);
846
+ var webSearchEnabled = this.normalizeBoolean(process.env.AI_DASHBOARD_CODEX_WEB_SEARCH_ENABLED, false);
847
+ var networkAccessEnabled = this.normalizeBoolean(process.env.AI_DASHBOARD_CODEX_NETWORK_ACCESS_ENABLED, false);
848
+ var modelReasoningEffort = this.normalizeModelReasoningEffort(process.env.AI_DASHBOARD_CODEX_REASONING_EFFORT);
849
+ return {
850
+ model: this.config.model,
851
+ approvalPolicy: approvalPolicy,
852
+ sandboxMode: sandboxMode,
853
+ skipGitRepoCheck: skipGitRepoCheck,
854
+ webSearchMode: webSearchMode,
855
+ webSearchEnabled: webSearchEnabled,
856
+ networkAccessEnabled: networkAccessEnabled,
857
+ modelReasoningEffort: modelReasoningEffort
858
+ };
859
+ };
860
+ CodexClient.prototype.mergeThreadOptions = function (overrides) {
861
+ var merged = __assign(__assign({}, this.defaultThreadOptions), (overrides || {}));
862
+ var cleaned = Object.entries(merged).reduce(function (acc, _a) {
863
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
864
+ if (value === undefined || value === null || value === '') {
865
+ return acc;
866
+ }
867
+ acc[key] = value;
868
+ return acc;
869
+ }, {});
870
+ return Object.keys(cleaned).length ? cleaned : undefined;
871
+ };
872
+ CodexClient.prototype.normalizeApprovalPolicy = function (value) {
873
+ var normalized = (value || '').trim().toLowerCase();
874
+ if (normalized === 'never' || normalized === 'on-request' || normalized === 'on-failure' || normalized === 'untrusted') {
875
+ return normalized;
876
+ }
877
+ return 'never';
878
+ };
879
+ CodexClient.prototype.normalizeSandboxMode = function (value, fallback) {
880
+ if (fallback === void 0) { fallback = 'read-only'; }
881
+ var normalized = (value || '').trim().toLowerCase();
882
+ if (normalized === 'read-only' || normalized === 'workspace-write' || normalized === 'danger-full-access') {
883
+ return normalized;
884
+ }
885
+ return fallback;
886
+ };
887
+ CodexClient.prototype.normalizeWebSearchMode = function (value) {
888
+ var normalized = (value || '').trim().toLowerCase();
889
+ if (normalized === 'disabled' || normalized === 'cached' || normalized === 'live') {
890
+ return normalized;
891
+ }
892
+ return undefined;
893
+ };
894
+ CodexClient.prototype.normalizeModelReasoningEffort = function (value) {
895
+ var normalized = (value || '').trim().toLowerCase();
896
+ if (normalized === 'minimal' || normalized === 'low' || normalized === 'medium' || normalized === 'high' || normalized === 'xhigh') {
897
+ return normalized;
898
+ }
899
+ return undefined;
900
+ };
901
+ CodexClient.prototype.normalizeBoolean = function (value, fallback) {
902
+ if (!value) {
903
+ return fallback;
904
+ }
905
+ var normalized = value.trim().toLowerCase();
906
+ if (['true', '1', 'yes', 'y', 'on'].includes(normalized)) {
907
+ return true;
908
+ }
909
+ if (['false', '0', 'no', 'n', 'off'].includes(normalized)) {
910
+ return false;
911
+ }
912
+ return fallback;
913
+ };
914
+ CodexClient.prototype.formatThreadOptions = function (options) {
915
+ var summary = {};
916
+ Object.entries(options).forEach(function (_a) {
917
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
918
+ if (value === undefined || value === null) {
919
+ return;
920
+ }
921
+ summary[key] = String(value);
922
+ });
923
+ return JSON.stringify(summary);
924
+ };
925
+ CodexClient.prototype.buildThreadOptionsKey = function (options) {
926
+ if (!options) {
927
+ return '';
928
+ }
929
+ var ordered = {};
930
+ Object.keys(options)
931
+ .sort()
932
+ .forEach(function (key) {
933
+ var value = options[key];
934
+ if (value === undefined || value === null) {
935
+ return;
936
+ }
937
+ ordered[key] = Array.isArray(value) ? JSON.stringify(value) : String(value);
938
+ });
939
+ return JSON.stringify(ordered);
940
+ };
941
+ CodexClient.prototype.buildThreadCacheKey = function (threadKey, options) {
942
+ if (threadKey) {
943
+ return "thread:".concat(threadKey);
944
+ }
945
+ var model = (options === null || options === void 0 ? void 0 : options.model) || this.config.model;
946
+ var workingDirectory = options === null || options === void 0 ? void 0 : options.workingDirectory;
947
+ if (!model && !workingDirectory) {
948
+ return null;
949
+ }
950
+ return "thread:auto:".concat(model || 'default', ":").concat(workingDirectory || 'root');
951
+ };
952
+ CodexClient.prototype.isPingPrompt = function (prompt) {
953
+ return prompt.trim() === CodexClient.PING_PROMPT;
954
+ };
955
+ CodexClient.prototype.runPing = function (threadOptions) {
956
+ return __awaiter(this, void 0, void 0, function () {
957
+ var content, trimmed, preview, error_6, message;
958
+ return __generator(this, function (_a) {
959
+ switch (_a.label) {
960
+ case 0:
961
+ this.log("runPing start (timeoutMs=".concat(this.pingTimeoutMs, ")"));
962
+ _a.label = 1;
963
+ case 1:
964
+ _a.trys.push([1, 3, , 4]);
965
+ return [4 /*yield*/, this.runOnce(CodexClient.PING_PROMPT, {
966
+ timeoutMs: this.pingTimeoutMs,
967
+ threadOptions: threadOptions,
968
+ reuseThread: false
969
+ })];
970
+ case 2:
971
+ content = _a.sent();
972
+ trimmed = content.trim();
973
+ preview = trimmed.length > 80 ? "".concat(trimmed.slice(0, 80), "\u2026") : trimmed;
974
+ this.log("runPing response: ".concat(preview));
975
+ return [3 /*break*/, 4];
976
+ case 3:
977
+ error_6 = _a.sent();
978
+ message = error_6 instanceof Error ? error_6.message : String(error_6 || 'Unknown error');
979
+ this.log("runPing failed: ".concat(message));
980
+ throw error_6;
981
+ case 4: return [2 /*return*/];
982
+ }
983
+ });
984
+ });
985
+ };
986
+ CodexClient.PING_PROMPT = "Say 'pong'";
987
+ return CodexClient;
988
+ }());
989
+ exports.CodexClient = CodexClient;
990
+
991
+ //# sourceMappingURL=codex-client.js.map