@dexto/core 1.6.15 → 1.6.16
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var codex_app_server_exports = {};
|
|
20
30
|
__export(codex_app_server_exports, {
|
|
@@ -22,10 +32,13 @@ __export(codex_app_server_exports, {
|
|
|
22
32
|
createCodexLanguageModel: () => createCodexLanguageModel
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(codex_app_server_exports);
|
|
35
|
+
var fs = __toESM(require("node:fs"), 1);
|
|
25
36
|
var import_node_child_process = require("node:child_process");
|
|
37
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
26
38
|
var import_node_readline = require("node:readline");
|
|
27
39
|
var import_DextoRuntimeError = require("../../errors/DextoRuntimeError.js");
|
|
28
40
|
var import_types = require("../../errors/types.js");
|
|
41
|
+
var import_path = require("../../utils/path.js");
|
|
29
42
|
var import_safe_stringify = require("../../utils/safe-stringify.js");
|
|
30
43
|
var import_error_codes = require("../error-codes.js");
|
|
31
44
|
var import_errors = require("../errors.js");
|
|
@@ -66,6 +79,7 @@ const DEFAULT_CLIENT_INFO = {
|
|
|
66
79
|
title: "Dexto",
|
|
67
80
|
version: "1.0.0"
|
|
68
81
|
};
|
|
82
|
+
const MANAGED_CODEX_BINARY = process.platform === "win32" ? "codex.cmd" : "codex";
|
|
69
83
|
const CODEX_DEVELOPER_INSTRUCTIONS = [
|
|
70
84
|
"You are providing model responses for a host application.",
|
|
71
85
|
"Treat the provided input as the full conversation transcript.",
|
|
@@ -98,6 +112,39 @@ function getArray(value) {
|
|
|
98
112
|
function normalizeError(error) {
|
|
99
113
|
return error instanceof Error ? error : createCodexClientRuntimeError(String(error));
|
|
100
114
|
}
|
|
115
|
+
function isMissingCodexCliError(error) {
|
|
116
|
+
const missingCodexError = error;
|
|
117
|
+
if (missingCodexError.isMissingCodexError === true) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
const code = missingCodexError.code;
|
|
121
|
+
return error.message.includes("Codex CLI not found on PATH") || code === "ENOENT" && (error.message.includes("spawn codex ENOENT") || error.message.includes("Codex CLI command '"));
|
|
122
|
+
}
|
|
123
|
+
function normalizeCodexStartupError(error, command) {
|
|
124
|
+
const normalized = normalizeError(error);
|
|
125
|
+
const errno = normalized;
|
|
126
|
+
if (errno.code !== "ENOENT" || !normalized.message.includes(`spawn ${command} ENOENT`)) {
|
|
127
|
+
return normalized;
|
|
128
|
+
}
|
|
129
|
+
const message = command === "codex" ? "Codex CLI not found on PATH. Install Codex to use ChatGPT Login in Dexto." : `Codex CLI command '${command}' not found on PATH. Install Codex to use ChatGPT Login in Dexto.`;
|
|
130
|
+
const startupError = new Error(message);
|
|
131
|
+
startupError.code = "ENOENT";
|
|
132
|
+
startupError.isMissingCodexError = true;
|
|
133
|
+
return startupError;
|
|
134
|
+
}
|
|
135
|
+
function getManagedCodexCommand() {
|
|
136
|
+
try {
|
|
137
|
+
const candidate = import_node_path.default.join(
|
|
138
|
+
(0, import_path.getDextoGlobalPath)("deps"),
|
|
139
|
+
"node_modules",
|
|
140
|
+
".bin",
|
|
141
|
+
MANAGED_CODEX_BINARY
|
|
142
|
+
);
|
|
143
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
144
|
+
} catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
101
148
|
function parseCodexAccount(value) {
|
|
102
149
|
if (!isRecord(value)) {
|
|
103
150
|
return null;
|
|
@@ -543,7 +590,7 @@ function toCodexFailureMessage(error, modelId) {
|
|
|
543
590
|
return error;
|
|
544
591
|
}
|
|
545
592
|
const normalized = normalizeError(error);
|
|
546
|
-
if (normalized
|
|
593
|
+
if (isMissingCodexCliError(normalized)) {
|
|
547
594
|
return import_errors.LLMError.missingConfig(
|
|
548
595
|
"openai-compatible",
|
|
549
596
|
"the Codex CLI on PATH (install Codex to use ChatGPT Login in Dexto)"
|
|
@@ -632,7 +679,7 @@ class CodexAppServerClient {
|
|
|
632
679
|
started = false;
|
|
633
680
|
closed = false;
|
|
634
681
|
constructor(options = {}) {
|
|
635
|
-
this.command = options.command ?? "codex";
|
|
682
|
+
this.command = options.command ?? getManagedCodexCommand() ?? "codex";
|
|
636
683
|
this.cwd = options.cwd;
|
|
637
684
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
638
685
|
this.clientInfo = options.clientInfo ?? DEFAULT_CLIENT_INFO;
|
|
@@ -848,7 +895,7 @@ class CodexAppServerClient {
|
|
|
848
895
|
const drainStderr = () => void 0;
|
|
849
896
|
child.stderr.on("data", drainStderr);
|
|
850
897
|
child.on("error", (error) => {
|
|
851
|
-
this.rejectPending(error);
|
|
898
|
+
this.rejectPending(normalizeCodexStartupError(error, this.command));
|
|
852
899
|
});
|
|
853
900
|
child.on("exit", (code, signal) => {
|
|
854
901
|
const wasClosed = this.closed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-app-server.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/codex-app-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-app-server.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/codex-app-server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,WAAW,EACX,eAAe,EAOlB,MAAM,kBAAkB,CAAC;AAU1B,KAAK,oBAAoB,GAAG,MAAM,GAAG,MAAM,CAAC;AAO5C,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F,KAAK,wBAAwB,GAAG;IAC5B,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,KAAK,kBAAkB,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEpC,KAAK,gBAAgB,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,MAAM,MAAM,cAAc,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,C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,EAAE,oBAAoB,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAOvE,mBAAmB,CAAC,EAAE,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAe,GAAG,IAAI;IAU3F,OAAO,CAAC,KAAK;IAQb,OAAO,CAAC,aAAa;CASxB;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAClE,GAAG,eAAe,CAielB"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import "../../chunk-PTJYTZNU.js";
|
|
2
|
+
import * as fs from "node:fs";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
import { createInterface } from "node:readline";
|
|
4
6
|
import { DextoRuntimeError } from "../../errors/DextoRuntimeError.js";
|
|
5
7
|
import { ErrorScope, ErrorType } from "../../errors/types.js";
|
|
8
|
+
import { getDextoGlobalPath } from "../../utils/path.js";
|
|
6
9
|
import { safeStringify } from "../../utils/safe-stringify.js";
|
|
7
10
|
import { LLMErrorCode } from "../error-codes.js";
|
|
8
11
|
import { LLMError } from "../errors.js";
|
|
@@ -43,6 +46,7 @@ const DEFAULT_CLIENT_INFO = {
|
|
|
43
46
|
title: "Dexto",
|
|
44
47
|
version: "1.0.0"
|
|
45
48
|
};
|
|
49
|
+
const MANAGED_CODEX_BINARY = process.platform === "win32" ? "codex.cmd" : "codex";
|
|
46
50
|
const CODEX_DEVELOPER_INSTRUCTIONS = [
|
|
47
51
|
"You are providing model responses for a host application.",
|
|
48
52
|
"Treat the provided input as the full conversation transcript.",
|
|
@@ -75,6 +79,39 @@ function getArray(value) {
|
|
|
75
79
|
function normalizeError(error) {
|
|
76
80
|
return error instanceof Error ? error : createCodexClientRuntimeError(String(error));
|
|
77
81
|
}
|
|
82
|
+
function isMissingCodexCliError(error) {
|
|
83
|
+
const missingCodexError = error;
|
|
84
|
+
if (missingCodexError.isMissingCodexError === true) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const code = missingCodexError.code;
|
|
88
|
+
return error.message.includes("Codex CLI not found on PATH") || code === "ENOENT" && (error.message.includes("spawn codex ENOENT") || error.message.includes("Codex CLI command '"));
|
|
89
|
+
}
|
|
90
|
+
function normalizeCodexStartupError(error, command) {
|
|
91
|
+
const normalized = normalizeError(error);
|
|
92
|
+
const errno = normalized;
|
|
93
|
+
if (errno.code !== "ENOENT" || !normalized.message.includes(`spawn ${command} ENOENT`)) {
|
|
94
|
+
return normalized;
|
|
95
|
+
}
|
|
96
|
+
const message = command === "codex" ? "Codex CLI not found on PATH. Install Codex to use ChatGPT Login in Dexto." : `Codex CLI command '${command}' not found on PATH. Install Codex to use ChatGPT Login in Dexto.`;
|
|
97
|
+
const startupError = new Error(message);
|
|
98
|
+
startupError.code = "ENOENT";
|
|
99
|
+
startupError.isMissingCodexError = true;
|
|
100
|
+
return startupError;
|
|
101
|
+
}
|
|
102
|
+
function getManagedCodexCommand() {
|
|
103
|
+
try {
|
|
104
|
+
const candidate = path.join(
|
|
105
|
+
getDextoGlobalPath("deps"),
|
|
106
|
+
"node_modules",
|
|
107
|
+
".bin",
|
|
108
|
+
MANAGED_CODEX_BINARY
|
|
109
|
+
);
|
|
110
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
78
115
|
function parseCodexAccount(value) {
|
|
79
116
|
if (!isRecord(value)) {
|
|
80
117
|
return null;
|
|
@@ -520,7 +557,7 @@ function toCodexFailureMessage(error, modelId) {
|
|
|
520
557
|
return error;
|
|
521
558
|
}
|
|
522
559
|
const normalized = normalizeError(error);
|
|
523
|
-
if (normalized
|
|
560
|
+
if (isMissingCodexCliError(normalized)) {
|
|
524
561
|
return LLMError.missingConfig(
|
|
525
562
|
"openai-compatible",
|
|
526
563
|
"the Codex CLI on PATH (install Codex to use ChatGPT Login in Dexto)"
|
|
@@ -609,7 +646,7 @@ class CodexAppServerClient {
|
|
|
609
646
|
started = false;
|
|
610
647
|
closed = false;
|
|
611
648
|
constructor(options = {}) {
|
|
612
|
-
this.command = options.command ?? "codex";
|
|
649
|
+
this.command = options.command ?? getManagedCodexCommand() ?? "codex";
|
|
613
650
|
this.cwd = options.cwd;
|
|
614
651
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
615
652
|
this.clientInfo = options.clientInfo ?? DEFAULT_CLIENT_INFO;
|
|
@@ -825,7 +862,7 @@ class CodexAppServerClient {
|
|
|
825
862
|
const drainStderr = () => void 0;
|
|
826
863
|
child.stderr.on("data", drainStderr);
|
|
827
864
|
child.on("error", (error) => {
|
|
828
|
-
this.rejectPending(error);
|
|
865
|
+
this.rejectPending(normalizeCodexStartupError(error, this.command));
|
|
829
866
|
});
|
|
830
867
|
child.on("exit", (code, signal) => {
|
|
831
868
|
const wasClosed = this.closed;
|