neoagent 2.3.1-beta.13 → 2.3.1-beta.15
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/lib/manager.js +52 -13
- package/package.json +1 -1
- package/server/public/flutter_bootstrap.js +1 -1
package/lib/manager.js
CHANGED
|
@@ -752,17 +752,19 @@ async function cmdLogin(args = []) {
|
|
|
752
752
|
}
|
|
753
753
|
|
|
754
754
|
const data = await reqRes.json();
|
|
755
|
-
const {
|
|
755
|
+
const { device_auth_id, interval } = data;
|
|
756
756
|
const user_code = data.user_code || data.usercode;
|
|
757
757
|
const verification_uri = 'https://auth.openai.com/codex/device';
|
|
758
758
|
|
|
759
759
|
console.log(`\n ${COLORS.cyan}Please visit:${COLORS.reset} ${verification_uri}`);
|
|
760
760
|
console.log(` ${COLORS.cyan}And enter the code:${COLORS.reset} ${COLORS.bold}${user_code}${COLORS.reset}\n`);
|
|
761
|
-
|
|
761
|
+
|
|
762
762
|
logInfo('Waiting for authorization (timeout in 15m)...');
|
|
763
763
|
const startTime = Date.now();
|
|
764
764
|
const timeoutMs = 15 * 60 * 1000;
|
|
765
765
|
let currentPollInterval = (interval || 5) * 1000;
|
|
766
|
+
let authorizationCode = null;
|
|
767
|
+
let codeVerifier = null;
|
|
766
768
|
|
|
767
769
|
while (Date.now() - startTime < timeoutMs) {
|
|
768
770
|
await new Promise((r) => setTimeout(r, currentPollInterval));
|
|
@@ -770,30 +772,67 @@ async function cmdLogin(args = []) {
|
|
|
770
772
|
method: 'POST',
|
|
771
773
|
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
|
|
772
774
|
body: JSON.stringify({
|
|
773
|
-
device_auth_id:
|
|
775
|
+
device_auth_id: device_auth_id,
|
|
774
776
|
user_code: user_code
|
|
775
777
|
})
|
|
776
778
|
});
|
|
777
779
|
|
|
780
|
+
if (tokenRes.status === 403 || tokenRes.status === 404) {
|
|
781
|
+
// These statuses are returned by OpenAI while authorization is pending
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
|
|
778
785
|
if (!tokenRes.ok) {
|
|
779
786
|
const errorText = await tokenRes.text().catch(() => 'Unknown error');
|
|
780
787
|
throw new Error(`OpenAI token request failed: HTTP ${tokenRes.status} - ${errorText}`);
|
|
781
788
|
}
|
|
782
789
|
|
|
783
|
-
const
|
|
784
|
-
if (
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
} else if (
|
|
790
|
+
const pollData = await tokenRes.json();
|
|
791
|
+
if (pollData.authorization_code && pollData.code_verifier) {
|
|
792
|
+
authorizationCode = pollData.authorization_code;
|
|
793
|
+
codeVerifier = pollData.code_verifier;
|
|
794
|
+
break;
|
|
795
|
+
} else if (pollData.error === 'authorization_pending') {
|
|
789
796
|
// Continue polling
|
|
790
|
-
} else if (
|
|
797
|
+
} else if (pollData.error === 'slow_down') {
|
|
791
798
|
currentPollInterval += 5000;
|
|
792
|
-
} else if (
|
|
793
|
-
throw new Error(`Authentication failed: ${
|
|
799
|
+
} else if (pollData.error) {
|
|
800
|
+
throw new Error(`Authentication failed: ${pollData.error_description || pollData.error}`);
|
|
794
801
|
}
|
|
795
802
|
}
|
|
796
|
-
|
|
803
|
+
|
|
804
|
+
if (!authorizationCode || !codeVerifier) {
|
|
805
|
+
throw new Error('OpenAI authentication timed out after 15 minutes.');
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
logInfo('Exchanging authorization code for access token...');
|
|
809
|
+
const exchangeRes = await fetch('https://auth.openai.com/oauth/token', {
|
|
810
|
+
method: 'POST',
|
|
811
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
812
|
+
body: new URLSearchParams({
|
|
813
|
+
grant_type: 'authorization_code',
|
|
814
|
+
code: authorizationCode,
|
|
815
|
+
redirect_uri: 'https://auth.openai.com/deviceauth/callback',
|
|
816
|
+
client_id: clientId,
|
|
817
|
+
code_verifier: codeVerifier
|
|
818
|
+
})
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
if (!exchangeRes.ok) {
|
|
822
|
+
const errorText = await exchangeRes.text().catch(() => 'Unknown error');
|
|
823
|
+
throw new Error(`OpenAI token exchange failed: HTTP ${exchangeRes.status} - ${errorText}`);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
const exchangeData = await exchangeRes.json();
|
|
827
|
+
if (exchangeData.access_token) {
|
|
828
|
+
upsertEnvValue('OPENAI_CODEX_ACCESS_TOKEN', exchangeData.access_token);
|
|
829
|
+
if (exchangeData.refresh_token) {
|
|
830
|
+
upsertEnvValue('OPENAI_CODEX_REFRESH_TOKEN', exchangeData.refresh_token);
|
|
831
|
+
}
|
|
832
|
+
logOk('Successfully authenticated and saved OpenAI Codex tokens to .env');
|
|
833
|
+
} else {
|
|
834
|
+
throw new Error('OpenAI token exchange succeeded but did not return an access token.');
|
|
835
|
+
}
|
|
797
836
|
}
|
|
798
837
|
}
|
|
799
838
|
|
package/package.json
CHANGED
|
@@ -37,6 +37,6 @@ _flutter.buildConfig = {"engineRevision":"59aa584fdf100e6c78c785d8a5b565d1de4b48
|
|
|
37
37
|
|
|
38
38
|
_flutter.loader.load({
|
|
39
39
|
serviceWorkerSettings: {
|
|
40
|
-
serviceWorkerVersion: "
|
|
40
|
+
serviceWorkerVersion: "3977022641" /* Flutter's service worker is deprecated and will be removed in a future Flutter release. */
|
|
41
41
|
}
|
|
42
42
|
});
|