@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/login.js +40 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leoustc/ai-runner-codex",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "Codex app-server backed Agent Runner Hub CLI connector",
6
6
  "license": "MIT",
package/src/login.js CHANGED
@@ -106,13 +106,21 @@ function loginStatusMessage(status, text) {
106
106
  }
107
107
 
108
108
  function parseLoginInfo(text) {
109
- const url = text.match(/https?:\/\/[^\s"'<>]+/)?.[0]?.replace(/[),.;]+$/, "") ?? "";
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
- text.match(/(?:device|user|login|verification)?\s*(?:id|code)(?:\s+is)?\s*[:=]?\s*([A-Z0-9][A-Z0-9-]{4,})/i)?.[1] ?? "";
112
- const labelledCode =
113
- text.match(/(?:user|device|login|verification)?\s*code(?:\s+is)?\s*[:=]?\s*([A-Z0-9][A-Z0-9-]{4,})/i)?.[1] ?? "";
114
- const fallbackCode = text.match(/\b[A-Z0-9]{4}-[A-Z0-9]{4}\b/i)?.[0] ?? "";
115
- const deviceId = labelledDeviceId || labelledCode || fallbackCode;
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) => {