dsh-codex-oauth 0.2.1 → 0.2.3
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/client.js +108 -13
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -1,14 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-codex-oauth",factory:(require)=>{var module={exports:{}};var exports=module.exports;
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
29
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
// client/index.jsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
apply: () => apply,
|
|
34
|
+
inject: () => inject,
|
|
35
|
+
name: () => name
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_react = __toESM(require("react"), 1);
|
|
39
|
+
var STATUS = "/plugins/dsh-codex-oauth/auth/status";
|
|
40
|
+
var LOGIN = "/plugins/dsh-codex-oauth/auth/login";
|
|
41
|
+
var LOGOUT = "/plugins/dsh-codex-oauth/auth/logout";
|
|
42
|
+
var h = import_react.default.createElement;
|
|
43
|
+
async function request(path, method = "GET") {
|
|
44
|
+
const response = await fetch(path, { method, credentials: "same-origin", headers: { accept: "application/json" } });
|
|
45
|
+
const value = await response.json().catch(() => ({}));
|
|
46
|
+
if (!response.ok) throw new Error(value.error || `HTTP ${response.status}`);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function CodexSettings() {
|
|
50
|
+
const [state, setState] = (0, import_react.useState)({ status: "loading" });
|
|
51
|
+
const [busy, setBusy] = (0, import_react.useState)(false);
|
|
52
|
+
const refresh = (0, import_react.useCallback)(() => request(STATUS).then(setState).catch((error) => setState({ status: "error", message: error.message })), []);
|
|
53
|
+
(0, import_react.useEffect)(() => {
|
|
54
|
+
refresh();
|
|
55
|
+
}, [refresh]);
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
if (state.status !== "signing-in") return void 0;
|
|
58
|
+
const timer = setInterval(refresh, 1e3);
|
|
59
|
+
return () => clearInterval(timer);
|
|
60
|
+
}, [refresh, state.status]);
|
|
61
|
+
const signIn = async () => {
|
|
62
|
+
setBusy(true);
|
|
63
|
+
setState({ status: "signing-in" });
|
|
64
|
+
const popup = window.open("about:blank", "_blank", "noopener,noreferrer");
|
|
65
|
+
try {
|
|
66
|
+
const challenge = await request(LOGIN, "POST");
|
|
67
|
+
if (!popup) throw new Error("Please allow popups to sign in");
|
|
68
|
+
popup.location.replace(challenge.url);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
popup?.close();
|
|
71
|
+
setState({ status: "error", message: error.message });
|
|
72
|
+
} finally {
|
|
73
|
+
setBusy(false);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const signOut = async () => {
|
|
77
|
+
setBusy(true);
|
|
78
|
+
try {
|
|
79
|
+
await request(LOGOUT, "POST");
|
|
80
|
+
setState({ status: "signed-out" });
|
|
81
|
+
} catch (error) {
|
|
82
|
+
setState({ status: "error", message: error.message });
|
|
83
|
+
} finally {
|
|
84
|
+
setBusy(false);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const signedIn = state.status === "signed-in";
|
|
88
|
+
const label = state.status === "signed-in" ? "\u5DF2\u767B\u5F55" : state.status === "signing-in" ? "\u7B49\u5F85\u6D4F\u89C8\u5668\u5B8C\u6210\u767B\u5F55\u2026" : state.status === "loading" ? "\u68C0\u67E5\u767B\u5F55\u72B6\u6001\u2026" : state.status === "error" ? "\u767B\u5F55\u5931\u8D25" : "\u672A\u767B\u5F55";
|
|
89
|
+
return h(
|
|
90
|
+
"section",
|
|
91
|
+
{ style: { display: "flex", flexDirection: "column", gap: 12, maxWidth: 640 } },
|
|
92
|
+
h("h2", { style: { margin: 0 } }, "OpenAI Codex"),
|
|
93
|
+
h("p", { style: { margin: 0, color: "var(--dsw-alias-label-secondary)" } }, "\u4F7F\u7528 ChatGPT Plus/Pro \u7684 Codex \u8BA2\u9605\uFF0C\u65E0\u9700 OpenAI API Key\u3002"),
|
|
94
|
+
h(
|
|
95
|
+
"div",
|
|
96
|
+
{ style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: 16, border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 10 } },
|
|
97
|
+
h("span", null, label),
|
|
98
|
+
state.status === "loading" ? null : h("button", { type: "button", disabled: busy || state.status === "signing-in", onClick: signedIn ? signOut : signIn }, signedIn ? "\u9000\u51FA\u767B\u5F55" : "\u4F7F\u7528 ChatGPT \u767B\u5F55")
|
|
99
|
+
),
|
|
100
|
+
state.status === "error" ? h("p", { style: { color: "var(--dsw-alias-state-error-primary)" } }, state.message) : null,
|
|
101
|
+
h("p", { style: { margin: 0, color: "var(--dsw-alias-label-secondary)", fontSize: 13 } }, "\u51ED\u636E\u4FDD\u5B58\u5728 DSH_HOME/.openai-codex-auth.json\uFF0C\u4E0D\u4F1A\u8BFB\u53D6 Pi \u6216 Codex CLI \u7684\u767B\u5F55\u6587\u4EF6\u3002")
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
var name = "dsh-codex-oauth-client";
|
|
105
|
+
var inject = ["slots"];
|
|
106
|
+
function apply(ctx) {
|
|
107
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({ name: "settings.section", id: "dsh-codex-oauth", order: 15, label: () => "OpenAI Codex" }, CodexSettings));
|
|
108
|
+
}
|
|
109
|
+
return module.exports;}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-codex-oauth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Use a ChatGPT Codex subscription in DeepSeek Harness through standalone OAuth",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"bin": { "dsh-openai-codex": "bin/dsh-openai-codex.js" },
|
|
19
|
-
"exports": { ".": "./lib/index.js", "./client": "./lib/client.js", "./cordis.patch.yml": "./cordis.patch.yml" },
|
|
19
|
+
"exports": { ".": "./lib/index.js", "./client": "./lib/client.js", "./cordis.patch.yml": "./cordis.patch.yml", "./package.json": "./package.json" },
|
|
20
20
|
"files": ["lib", "bin", "client", "cordis.patch.yml", "README.md", "README.zh.md", "SPEC.md", "LICENSE"],
|
|
21
21
|
"dsh": {
|
|
22
22
|
"bundle": { "patch": "./cordis.patch.yml" },
|