@leoustc/ai-runner-codex 0.1.3 → 0.1.4
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/package.json +1 -1
- package/src/login.js +40 -6
package/package.json
CHANGED
package/src/login.js
CHANGED
|
@@ -106,13 +106,21 @@ function loginStatusMessage(status, text) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
function parseLoginInfo(text) {
|
|
109
|
-
const
|
|
109
|
+
const clean = stripAnsi(text);
|
|
110
|
+
const url = clean.match(/https?:\/\/[^\s"'<>]+/)?.[0]?.replace(/[),.;]+$/, "") ?? "";
|
|
111
|
+
const withoutUrls = clean.replace(/https?:\/\/[^\s"'<>]+/g, " ");
|
|
110
112
|
const labelledDeviceId =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
firstDeviceCode([
|
|
114
|
+
...withoutUrls.matchAll(
|
|
115
|
+
/(?:device|user|login|verification|authorization)\s*(?:id|code)(?:\s+(?:is|:)|\s*[:=])\s*([A-Z0-9][A-Z0-9-]{4,})/gi,
|
|
116
|
+
),
|
|
117
|
+
].map((match) => match[1])) ?? "";
|
|
118
|
+
const fallbackCode =
|
|
119
|
+
firstDeviceCode([
|
|
120
|
+
...withoutUrls.matchAll(/\b[A-Z0-9]{4,}(?:-[A-Z0-9]{4,})+\b/g),
|
|
121
|
+
...withoutUrls.matchAll(/\b[A-Z0-9]{8,}\b/g),
|
|
122
|
+
].map((match) => match[0])) ?? "";
|
|
123
|
+
const deviceId = labelledDeviceId || fallbackCode;
|
|
116
124
|
|
|
117
125
|
return {
|
|
118
126
|
code: deviceId,
|
|
@@ -121,6 +129,32 @@ function parseLoginInfo(text) {
|
|
|
121
129
|
};
|
|
122
130
|
}
|
|
123
131
|
|
|
132
|
+
function stripAnsi(text) {
|
|
133
|
+
return String(text).replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function firstDeviceCode(candidates) {
|
|
137
|
+
return candidates
|
|
138
|
+
.map((candidate) => String(candidate || "").trim().replace(/[),.;]+$/, ""))
|
|
139
|
+
.find((candidate) => isDeviceCode(candidate));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isDeviceCode(candidate) {
|
|
143
|
+
if (!candidate || candidate.length < 6) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!/^[A-Z0-9-]+$/.test(candidate)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!/[0-9]/.test(candidate) && !candidate.includes("-")) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return !/^(AUTHORIZATION|VERIFICATION|DEVICE|LOGIN|OPENAI|CODEX)$/i.test(candidate);
|
|
156
|
+
}
|
|
157
|
+
|
|
124
158
|
function splitCommand(command) {
|
|
125
159
|
const matches = command.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
|
|
126
160
|
return matches.map((part) => {
|