@harars/opencode-switch-openai-auth-plugin 0.1.5 → 0.1.6
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/dist/index.js +15 -4
- package/dist/tui.js +15 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -86,6 +86,17 @@ function detail(err) {
|
|
|
86
86
|
return String(err);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
function explain(err) {
|
|
90
|
+
const msg = detail(err);
|
|
91
|
+
const port = msg.match(/port\s+(\d+)\s+in use/i)?.[1];
|
|
92
|
+
if (port) {
|
|
93
|
+
return `Browser login could not start because local port ${port} is already in use. Close the other OpenCode login window or finish the other browser login first.`;
|
|
94
|
+
}
|
|
95
|
+
if (msg.includes("this.client") || msg.includes("\u672A\u5B9A\u4E49\u7684\u4E0D\u662F\u4E00\u4E2Aobject")) {
|
|
96
|
+
return "Browser login callback failed inside OpenCode. Update the plugin to the latest version and retry.";
|
|
97
|
+
}
|
|
98
|
+
return msg;
|
|
99
|
+
}
|
|
89
100
|
async function runOAuthCallback(callback, input) {
|
|
90
101
|
try {
|
|
91
102
|
const res = await callback(input);
|
|
@@ -697,7 +708,7 @@ async function code(api, index, method, authz) {
|
|
|
697
708
|
if (!ok.ok) {
|
|
698
709
|
api.ui.toast({
|
|
699
710
|
variant: "error",
|
|
700
|
-
message: `Login failed: ${
|
|
711
|
+
message: `Login failed: ${explain(ok.error)}`
|
|
701
712
|
});
|
|
702
713
|
return false;
|
|
703
714
|
}
|
|
@@ -716,7 +727,7 @@ async function auto(api, index, method, authz) {
|
|
|
716
727
|
if (!ok.ok) {
|
|
717
728
|
api.ui.toast({
|
|
718
729
|
variant: "error",
|
|
719
|
-
message: `Login failed: ${
|
|
730
|
+
message: `Login failed: ${explain(ok.error)}`
|
|
720
731
|
});
|
|
721
732
|
return false;
|
|
722
733
|
}
|
|
@@ -763,7 +774,7 @@ async function loginOpenAI(api) {
|
|
|
763
774
|
if (!authz.ok) {
|
|
764
775
|
api.ui.toast({
|
|
765
776
|
variant: "error",
|
|
766
|
-
message: `Login failed: ${
|
|
777
|
+
message: `Login failed: ${explain(authz.error)}`
|
|
767
778
|
});
|
|
768
779
|
return false;
|
|
769
780
|
}
|
|
@@ -779,7 +790,7 @@ async function loginOpenAI(api) {
|
|
|
779
790
|
} catch (err) {
|
|
780
791
|
api.ui.toast({
|
|
781
792
|
variant: "error",
|
|
782
|
-
message: `Login failed: ${
|
|
793
|
+
message: `Login failed: ${explain(err)}`
|
|
783
794
|
});
|
|
784
795
|
return false;
|
|
785
796
|
}
|
package/dist/tui.js
CHANGED
|
@@ -86,6 +86,17 @@ function detail(err) {
|
|
|
86
86
|
return String(err);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
function explain(err) {
|
|
90
|
+
const msg = detail(err);
|
|
91
|
+
const port = msg.match(/port\s+(\d+)\s+in use/i)?.[1];
|
|
92
|
+
if (port) {
|
|
93
|
+
return `Browser login could not start because local port ${port} is already in use. Close the other OpenCode login window or finish the other browser login first.`;
|
|
94
|
+
}
|
|
95
|
+
if (msg.includes("this.client") || msg.includes("\u672A\u5B9A\u4E49\u7684\u4E0D\u662F\u4E00\u4E2Aobject")) {
|
|
96
|
+
return "Browser login callback failed inside OpenCode. Update the plugin to the latest version and retry.";
|
|
97
|
+
}
|
|
98
|
+
return msg;
|
|
99
|
+
}
|
|
89
100
|
async function runOAuthCallback(callback, input) {
|
|
90
101
|
try {
|
|
91
102
|
const res = await callback(input);
|
|
@@ -697,7 +708,7 @@ async function code(api, index, method, authz) {
|
|
|
697
708
|
if (!ok.ok) {
|
|
698
709
|
api.ui.toast({
|
|
699
710
|
variant: "error",
|
|
700
|
-
message: `Login failed: ${
|
|
711
|
+
message: `Login failed: ${explain(ok.error)}`
|
|
701
712
|
});
|
|
702
713
|
return false;
|
|
703
714
|
}
|
|
@@ -716,7 +727,7 @@ async function auto(api, index, method, authz) {
|
|
|
716
727
|
if (!ok.ok) {
|
|
717
728
|
api.ui.toast({
|
|
718
729
|
variant: "error",
|
|
719
|
-
message: `Login failed: ${
|
|
730
|
+
message: `Login failed: ${explain(ok.error)}`
|
|
720
731
|
});
|
|
721
732
|
return false;
|
|
722
733
|
}
|
|
@@ -763,7 +774,7 @@ async function loginOpenAI(api) {
|
|
|
763
774
|
if (!authz.ok) {
|
|
764
775
|
api.ui.toast({
|
|
765
776
|
variant: "error",
|
|
766
|
-
message: `Login failed: ${
|
|
777
|
+
message: `Login failed: ${explain(authz.error)}`
|
|
767
778
|
});
|
|
768
779
|
return false;
|
|
769
780
|
}
|
|
@@ -779,7 +790,7 @@ async function loginOpenAI(api) {
|
|
|
779
790
|
} catch (err) {
|
|
780
791
|
api.ui.toast({
|
|
781
792
|
variant: "error",
|
|
782
|
-
message: `Login failed: ${
|
|
793
|
+
message: `Login failed: ${explain(err)}`
|
|
783
794
|
});
|
|
784
795
|
return false;
|
|
785
796
|
}
|