dsh-use-chatgpt 1.0.0 → 1.0.2
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/README.md +3 -1
- package/dist/client.js +446 -229
- package/dist/index.js +107 -57
- package/docs/images/chatgpt-settings.png +0 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -24561,23 +24561,27 @@ var AccountStore = class {
|
|
|
24561
24561
|
async #load(save) {
|
|
24562
24562
|
const record = await readRecord(join(this.directory, authFile));
|
|
24563
24563
|
if (record === void 0) return newState();
|
|
24564
|
+
let state2 = record;
|
|
24564
24565
|
if (record?.version === 3) {
|
|
24565
24566
|
if (record.provider !== this.encryption.id) throw new ChatGPTError("storage_provider_mismatch", "\u8BF7\u4F7F\u7528\u4FDD\u5B58\u8FD9\u4E9B\u51ED\u636E\u7684\u7CFB\u7EDF\u52A0\u5BC6\u670D\u52A1\u3002");
|
|
24566
24567
|
await this.#requireEncryption();
|
|
24567
24568
|
try {
|
|
24568
24569
|
const bytes = Buffer.from(record.ciphertext, "base64");
|
|
24569
24570
|
if (!bytes.length || bytes.toString("base64") !== record.ciphertext) throw invalid2();
|
|
24570
|
-
|
|
24571
|
+
state2 = checkState(JSON.parse(await this.encryption.decrypt(bytes)));
|
|
24571
24572
|
} catch {
|
|
24572
24573
|
throw new ChatGPTError("storage_decryption_failed", "\u65E0\u6CD5\u89E3\u5BC6\u73B0\u6709\u51ED\u636E\u3002\u8BF7\u68C0\u67E5\u94A5\u5319\u4E32\u6216 Windows \u7528\u6237\u540E\u91CD\u8BD5\u3002", true);
|
|
24573
24574
|
}
|
|
24575
|
+
if (!state2.profiles.some((profile) => profile.status === "disconnected")) return state2;
|
|
24576
|
+
} else {
|
|
24577
|
+
if (record?.version === 1) {
|
|
24578
|
+
const id = randomUUID();
|
|
24579
|
+
state2 = { ...newState(), activeProfileId: id, profiles: [{ ...record, id, label: "Connection 1", requiresNewRegistration: true }] };
|
|
24580
|
+
}
|
|
24581
|
+
checkState(state2);
|
|
24574
24582
|
}
|
|
24575
|
-
|
|
24576
|
-
if (
|
|
24577
|
-
const id = randomUUID();
|
|
24578
|
-
state2 = { ...newState(), activeProfileId: id, profiles: [{ ...record, id, label: "Connection 1", requiresNewRegistration: true }] };
|
|
24579
|
-
}
|
|
24580
|
-
checkState(state2);
|
|
24583
|
+
state2.profiles = state2.profiles.filter((profile) => profile.status !== "disconnected");
|
|
24584
|
+
if (!state2.profiles.some((profile) => profile.id === state2.activeProfileId)) delete state2.activeProfileId;
|
|
24581
24585
|
await save(state2);
|
|
24582
24586
|
return state2;
|
|
24583
24587
|
}
|
|
@@ -24593,6 +24597,9 @@ var cancelled2 = () => new ChatGPTError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u
|
|
|
24593
24597
|
var missingAccount = () => new ChatGPTError("profile_not_found", "\u627E\u4E0D\u5230\u9009\u5B9A\u7684\u8D26\u53F7\u3002");
|
|
24594
24598
|
var connected = (profile) => profile?.status === "connected" && Boolean(profile.credentials);
|
|
24595
24599
|
var sharing = (profile) => connected(profile) && profile.scopes.includes(planScope2);
|
|
24600
|
+
function isAddingAccount(session, options) {
|
|
24601
|
+
return session?.status === "connected" && Boolean(session.profileId) && !options.reconsent && (options.newProfile === true || Boolean(options.profileId) && options.profileId !== session.profileId);
|
|
24602
|
+
}
|
|
24596
24603
|
function publicIdentity(identity2) {
|
|
24597
24604
|
if (!identity2) return {};
|
|
24598
24605
|
const fields = {};
|
|
@@ -24613,11 +24620,11 @@ function sessionFor(state2) {
|
|
|
24613
24620
|
...profile.pendingRefresh ? { error: identityVerificationUnavailable().toJSON() } : {}
|
|
24614
24621
|
};
|
|
24615
24622
|
}
|
|
24616
|
-
function
|
|
24623
|
+
function requireNewSignIn(profile) {
|
|
24617
24624
|
delete profile.credentials;
|
|
24618
24625
|
delete profile.profileIdToken;
|
|
24619
24626
|
delete profile.pendingRefresh;
|
|
24620
|
-
Object.assign(profile, { status, scopes: [], savedAt: now() });
|
|
24627
|
+
Object.assign(profile, { status: "reauth_required", scopes: [], savedAt: now() });
|
|
24621
24628
|
}
|
|
24622
24629
|
function availableLabel(state2, requested) {
|
|
24623
24630
|
const labels = new Set([...state2.profiles, ...state2.pendingRegistrations].map((profile) => profile.label));
|
|
@@ -24657,14 +24664,17 @@ function createChatGPT(config) {
|
|
|
24657
24664
|
return structuredClone(session);
|
|
24658
24665
|
}
|
|
24659
24666
|
function idle({ modelRequest = false } = {}) {
|
|
24660
|
-
|
|
24667
|
+
const loginBlocksRequest = login && (!modelRequest || !login.addingAccount);
|
|
24668
|
+
if (updating || loginBlocksRequest || signingOutProfile && !modelRequest) {
|
|
24669
|
+
throw new ChatGPTError("connection_busy", "\u8BF7\u5148\u5B8C\u6210\u5F53\u524D\u7684\u8D26\u53F7\u64CD\u4F5C\u3002");
|
|
24670
|
+
}
|
|
24661
24671
|
}
|
|
24662
24672
|
function invalidate() {
|
|
24663
24673
|
generation.abort();
|
|
24664
24674
|
generation = new AbortController();
|
|
24665
24675
|
}
|
|
24666
24676
|
async function getSession() {
|
|
24667
|
-
if (updating || login) return structuredClone(displayed);
|
|
24677
|
+
if (updating || login && !login.addingAccount) return structuredClone(displayed);
|
|
24668
24678
|
const beforeRead = generation;
|
|
24669
24679
|
try {
|
|
24670
24680
|
const latest = await store.transaction(({ state: state2 }) => sessionFor(state2));
|
|
@@ -24698,7 +24708,7 @@ function createChatGPT(config) {
|
|
|
24698
24708
|
} catch (error) {
|
|
24699
24709
|
const typed = asError(error);
|
|
24700
24710
|
if (requiresReauthentication(typed) || ["invalid_id_token", "invalid_token_response", "account_mismatch"].includes(typed.code)) {
|
|
24701
|
-
|
|
24711
|
+
requireNewSignIn(profile);
|
|
24702
24712
|
await save();
|
|
24703
24713
|
}
|
|
24704
24714
|
throw typed;
|
|
@@ -24724,13 +24734,18 @@ function createChatGPT(config) {
|
|
|
24724
24734
|
async function signIn(options = {}) {
|
|
24725
24735
|
idle();
|
|
24726
24736
|
if (options.newProfile && options.profileId) throw new ChatGPTError("invalid_profile", "\u8BF7\u6307\u5B9A\u4E00\u4E2A\u767B\u5F55\u65B9\u5F0F\u3002");
|
|
24727
|
-
|
|
24728
|
-
const
|
|
24737
|
+
const addingAccount = isAddingAccount(displayed, options);
|
|
24738
|
+
const sourceProfileId = displayed.profileId;
|
|
24739
|
+
const attempt = { controller: new AbortController(), addingAccount };
|
|
24729
24740
|
login = attempt;
|
|
24730
|
-
const
|
|
24741
|
+
const timeout = AbortSignal.timeout(3 * 6e4);
|
|
24742
|
+
const signals = [attempt.controller.signal, timeout];
|
|
24731
24743
|
if (options.signal) signals.push(options.signal);
|
|
24732
24744
|
const signal = AbortSignal.any(signals);
|
|
24733
|
-
|
|
24745
|
+
if (!addingAccount) {
|
|
24746
|
+
invalidate();
|
|
24747
|
+
publish({ ...displayed, status: "connecting", sharing: false, error: void 0 });
|
|
24748
|
+
}
|
|
24734
24749
|
try {
|
|
24735
24750
|
let inspect = function(state2) {
|
|
24736
24751
|
signal.throwIfAborted();
|
|
@@ -24744,6 +24759,7 @@ function createChatGPT(config) {
|
|
|
24744
24759
|
const pending = state2.pendingRegistrations.find((item) => item.id === id);
|
|
24745
24760
|
if (options.profileId && !profile && !pending) throw missingAccount();
|
|
24746
24761
|
if (profile?.requiresNewRegistration) throw new ChatGPTError("registration_upgrade_required", "\u8BF7\u6DFB\u52A0\u8D26\u53F7\u4EE5\u5B8C\u6210\u65B0\u7248\u672C\u6388\u6743\u3002");
|
|
24762
|
+
if (addingAccount && state2.activeProfileId !== sourceProfileId) throw changed();
|
|
24747
24763
|
return { id, profile, pending, activeId: state2.activeProfileId, host: await hostId() };
|
|
24748
24764
|
}, signal);
|
|
24749
24765
|
let previous = original.profile ?? original.pending;
|
|
@@ -24769,7 +24785,7 @@ function createChatGPT(config) {
|
|
|
24769
24785
|
previous ??= { clientId: registeredClientId };
|
|
24770
24786
|
verified = await interact();
|
|
24771
24787
|
}
|
|
24772
|
-
|
|
24788
|
+
return await store.transaction(async ({ state: state2, save }) => {
|
|
24773
24789
|
const { profile, pending } = inspect(state2);
|
|
24774
24790
|
if ((profile ?? pending)?.clientId !== verified.clientId) throw changed();
|
|
24775
24791
|
const completed = { ...verified, id: original.id, label: (profile ?? pending).label };
|
|
@@ -24778,14 +24794,18 @@ function createChatGPT(config) {
|
|
|
24778
24794
|
state2.pendingRegistrations = state2.pendingRegistrations.filter((item) => item.id !== original.id);
|
|
24779
24795
|
state2.activeProfileId = original.id;
|
|
24780
24796
|
await save();
|
|
24781
|
-
|
|
24797
|
+
if (addingAccount) invalidate();
|
|
24798
|
+
return publish(sessionFor(state2));
|
|
24782
24799
|
}, signal);
|
|
24783
|
-
signal.throwIfAborted();
|
|
24784
|
-
return publish(session);
|
|
24785
24800
|
} catch (error) {
|
|
24786
|
-
|
|
24801
|
+
let failure = asError(error);
|
|
24802
|
+
if (signal.aborted) {
|
|
24803
|
+
failure = timeout.aborted && signal.reason === timeout.reason ? new ChatGPTError("authorization_timeout", "\u6388\u6743\u5DF2\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5\u3002", true) : cancelled2();
|
|
24804
|
+
}
|
|
24787
24805
|
const restored = await store.transaction(({ state: state2 }) => sessionFor(state2)).catch(() => disconnected());
|
|
24788
|
-
if (login === attempt && !updating)
|
|
24806
|
+
if (login === attempt && !updating) {
|
|
24807
|
+
publish(addingAccount || failure.code === "cancelled" ? restored : { ...restored, error: failure.toJSON() });
|
|
24808
|
+
}
|
|
24789
24809
|
throw failure;
|
|
24790
24810
|
} finally {
|
|
24791
24811
|
if (login === attempt) login = void 0;
|
|
@@ -24812,7 +24832,7 @@ function createChatGPT(config) {
|
|
|
24812
24832
|
signingOutProfile = profileId;
|
|
24813
24833
|
updating = !profileId || profileId === displayed.profileId;
|
|
24814
24834
|
if (updating) invalidate();
|
|
24815
|
-
if (!profileId) login?.abort();
|
|
24835
|
+
if (!profileId) login?.controller.abort();
|
|
24816
24836
|
try {
|
|
24817
24837
|
const { session, revocation } = await store.transaction(async ({ state: state2, save }) => {
|
|
24818
24838
|
const profile = profileId ? state2.profiles.find((item) => item.id === profileId) : active(state2);
|
|
@@ -24832,10 +24852,10 @@ function createChatGPT(config) {
|
|
|
24832
24852
|
revocation2 = new ChatGPTError("revocation_failed", "\u672C\u673A\u5DF2\u9000\u51FA\uFF0C\u672A\u786E\u8BA4\u8FDC\u7AEF\u64A4\u9500\u3002\u53EF\u524D\u5F80 ChatGPT \u8BBE\u7F6E\u65AD\u5F00\u6B64\u5E94\u7528\u3002", true);
|
|
24833
24853
|
}
|
|
24834
24854
|
}
|
|
24835
|
-
|
|
24836
|
-
if (
|
|
24837
|
-
const next = state2.profiles.find(sharing) ?? state2.profiles.find(connected);
|
|
24838
|
-
|
|
24855
|
+
state2.profiles = state2.profiles.filter((item) => item.id !== profile.id);
|
|
24856
|
+
if (profile.id === state2.activeProfileId) {
|
|
24857
|
+
const next = chooseNext ? state2.profiles.find(sharing) ?? state2.profiles.find(connected) : void 0;
|
|
24858
|
+
state2.activeProfileId = next?.id;
|
|
24839
24859
|
}
|
|
24840
24860
|
await save();
|
|
24841
24861
|
}
|
|
@@ -24860,7 +24880,7 @@ function createChatGPT(config) {
|
|
|
24860
24880
|
await endConnection({ profileId });
|
|
24861
24881
|
},
|
|
24862
24882
|
cancelSignIn() {
|
|
24863
|
-
login?.abort();
|
|
24883
|
+
login?.controller.abort();
|
|
24864
24884
|
},
|
|
24865
24885
|
listProfiles() {
|
|
24866
24886
|
return store.transaction(({ state: state2 }) => [
|
|
@@ -25427,6 +25447,13 @@ function createProvider(client, getSession, lifetime, {
|
|
|
25427
25447
|
const entries = await loadModels(session, false);
|
|
25428
25448
|
return entries.find((entry) => entry.id === model) ?? modelInfo(model);
|
|
25429
25449
|
}
|
|
25450
|
+
async function listVisibleModels(session) {
|
|
25451
|
+
const models = await loadModels(session, false);
|
|
25452
|
+
session.accountSignal?.throwIfAborted();
|
|
25453
|
+
if (!session.profileId || models.length === 0) return models;
|
|
25454
|
+
const hidden = getHiddenModels(session.profileId);
|
|
25455
|
+
return models.filter((model) => !hidden.has(model.id));
|
|
25456
|
+
}
|
|
25430
25457
|
return {
|
|
25431
25458
|
providerInfo: (id) => ({ id, name: "ChatGPT \u5957\u9910" }),
|
|
25432
25459
|
providerRetryPolicy: () => void 0,
|
|
@@ -25438,11 +25465,17 @@ function createProvider(client, getSession, lifetime, {
|
|
|
25438
25465
|
}),
|
|
25439
25466
|
async listModels() {
|
|
25440
25467
|
const session = await getSession();
|
|
25441
|
-
|
|
25442
|
-
|
|
25443
|
-
|
|
25444
|
-
|
|
25445
|
-
|
|
25468
|
+
try {
|
|
25469
|
+
return await listVisibleModels(session);
|
|
25470
|
+
} catch (error) {
|
|
25471
|
+
if (error?.code !== "network_error") throw error;
|
|
25472
|
+
lifetime.throwIfAborted();
|
|
25473
|
+
session.accountSignal?.throwIfAborted();
|
|
25474
|
+
return [];
|
|
25475
|
+
}
|
|
25476
|
+
},
|
|
25477
|
+
async listSelectableModels() {
|
|
25478
|
+
return listVisibleModels(await getSession());
|
|
25446
25479
|
},
|
|
25447
25480
|
async listPlanModels(force = false) {
|
|
25448
25481
|
return loadModels(await getSession(), force);
|
|
@@ -25660,7 +25693,8 @@ async function modelCatalog({ adapter, getSession, usageStore, onCatalogChange }
|
|
|
25660
25693
|
if (writing && (!body || typeof body !== "object" || Array.isArray(body) || Object.keys(body).some((key) => !["profileId", "model", "enabled"].includes(key)) || typeof body.profileId !== "string" || typeof body.model !== "string" || !body.model.length || typeof body.enabled !== "boolean")) return fail("\u65E0\u6548\u7684\u6A21\u578B\u663E\u793A\u8BBE\u7F6E\u3002", 400);
|
|
25661
25694
|
const expected = writing ? body.profileId : params.get("profileId");
|
|
25662
25695
|
if (expected !== null && expected !== profileId) return fail("\u5F53\u524D ChatGPT \u8D26\u53F7\u5DF2\u66F4\u6539\uFF0C\u8BF7\u5237\u65B0\u91CD\u8BD5\u3002", 409);
|
|
25663
|
-
const
|
|
25696
|
+
const refreshing = !writing && params.get("refresh") === "1";
|
|
25697
|
+
const models = await adapter.listPlanModels(refreshing);
|
|
25664
25698
|
const current = await getSession();
|
|
25665
25699
|
request.signal?.throwIfAborted();
|
|
25666
25700
|
accountSignal?.throwIfAborted();
|
|
@@ -25674,6 +25708,7 @@ async function modelCatalog({ adapter, getSession, usageStore, onCatalogChange }
|
|
|
25674
25708
|
return json({ model: body.model, enabled: body.enabled });
|
|
25675
25709
|
}
|
|
25676
25710
|
const hidden = usageStore.hiddenModels(profileId);
|
|
25711
|
+
if (refreshing) onCatalogChange();
|
|
25677
25712
|
return json({ models: models.map((model) => ({ ...model, enabled: !hidden.has(model.id) })) });
|
|
25678
25713
|
}
|
|
25679
25714
|
async function selectChatModel(ctx, { adapter, getSession, usageStore }, request, session) {
|
|
@@ -25689,7 +25724,7 @@ async function selectChatModel(ctx, { adapter, getSession, usageStore }, request
|
|
|
25689
25724
|
const agents = ctx.get?.("agents");
|
|
25690
25725
|
const agent = agents?.get(sessionId);
|
|
25691
25726
|
if (!agent) return fail("DSH \u4F1A\u8BDD\u672A\u6253\u5F00\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u4F1A\u8BDD\u3002", 409);
|
|
25692
|
-
const available = (await adapter.
|
|
25727
|
+
const available = (await adapter.listSelectableModels()).find((entry) => entry.id === model);
|
|
25693
25728
|
signal.throwIfAborted();
|
|
25694
25729
|
if (!available || reasoningEffort !== void 0 && !available.reasoning?.efforts.some((effort) => effort.id === reasoningEffort)) {
|
|
25695
25730
|
return fail("\u5F53\u524D ChatGPT \u8D26\u53F7\u4E0D\u652F\u6301\u6B64\u6A21\u578B\u6216\u63A8\u7406\u5F3A\u5EA6\u3002", 400);
|
|
@@ -26158,7 +26193,7 @@ function createPreferences(storageDir) {
|
|
|
26158
26193
|
// package.json
|
|
26159
26194
|
var package_default = {
|
|
26160
26195
|
name: "dsh-use-chatgpt",
|
|
26161
|
-
version: "1.0.
|
|
26196
|
+
version: "1.0.2",
|
|
26162
26197
|
description: "ChatGPT plan model provider for a local DeepSeek Harness desktop instance",
|
|
26163
26198
|
type: "module",
|
|
26164
26199
|
engines: { node: "^22.19.0 || >=24.0.0" },
|
|
@@ -26172,7 +26207,7 @@ var package_default = {
|
|
|
26172
26207
|
"./client": "./dist/client.js",
|
|
26173
26208
|
"./package.json": "./package.json"
|
|
26174
26209
|
},
|
|
26175
|
-
files: ["dist", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
26210
|
+
files: ["dist", "docs/images/chatgpt-settings.png", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
26176
26211
|
dsh: {
|
|
26177
26212
|
bundle: { patch: "./cordis.patch.yml" },
|
|
26178
26213
|
client: {
|
|
@@ -26360,16 +26395,23 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26360
26395
|
function locallySignedOut(profileId) {
|
|
26361
26396
|
return signedOutUnknownProfile || signedOutProfiles.has(profileId);
|
|
26362
26397
|
}
|
|
26398
|
+
function accountBlocked() {
|
|
26399
|
+
return transition && !transition.preparing && !transition.addingAccount;
|
|
26400
|
+
}
|
|
26401
|
+
function invalidateAccount() {
|
|
26402
|
+
account.abort();
|
|
26403
|
+
account = new AbortController();
|
|
26404
|
+
}
|
|
26363
26405
|
function visibleSession(current) {
|
|
26364
26406
|
if (!available || disposed) return disconnected2;
|
|
26365
26407
|
if (transition?.kind === "disconnect") return { ...current, ...disconnected2 };
|
|
26366
|
-
if (
|
|
26408
|
+
if (accountBlocked()) return { ...current, status: "connecting", sharing: false, error: void 0 };
|
|
26367
26409
|
if (locallySignedOut(current.profileId)) return { ...current, ...disconnected2 };
|
|
26368
26410
|
return current;
|
|
26369
26411
|
}
|
|
26370
26412
|
async function getSession() {
|
|
26371
26413
|
const { signal: accountSignal } = account;
|
|
26372
|
-
if (available && !disposed && !
|
|
26414
|
+
if (available && !disposed && !accountBlocked()) {
|
|
26373
26415
|
const current = await client.getSession();
|
|
26374
26416
|
if (accountSignal.aborted) return { ...disconnected2, accountSignal };
|
|
26375
26417
|
session = current;
|
|
@@ -26398,6 +26440,9 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26398
26440
|
registration.replace(next === void 0 ? [] : [providerId]);
|
|
26399
26441
|
}
|
|
26400
26442
|
const unsubscribe = client.subscribe((current) => {
|
|
26443
|
+
if (transition?.addingAccount && session.profileId !== current.profileId) {
|
|
26444
|
+
invalidateAccount();
|
|
26445
|
+
}
|
|
26401
26446
|
session = current;
|
|
26402
26447
|
refreshCatalog(current);
|
|
26403
26448
|
});
|
|
@@ -26414,9 +26459,8 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26414
26459
|
if (signingOutProfile || previous && !(kind === "disconnect" && previous.kind === "sign-in")) {
|
|
26415
26460
|
throw pluginError("connection_busy", "\u8BF7\u5148\u5B8C\u6210\u6216\u53D6\u6D88\u5F53\u524D\u8D26\u53F7\u64CD\u4F5C\u3002");
|
|
26416
26461
|
}
|
|
26417
|
-
transition = { kind };
|
|
26418
|
-
|
|
26419
|
-
account = new AbortController();
|
|
26462
|
+
transition = { kind, preparing: kind === "sign-in" };
|
|
26463
|
+
if (accountBlocked()) invalidateAccount();
|
|
26420
26464
|
refreshCatalog(session);
|
|
26421
26465
|
return { current: transition, previous };
|
|
26422
26466
|
}
|
|
@@ -26426,17 +26470,26 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26426
26470
|
refreshCatalog(session);
|
|
26427
26471
|
}
|
|
26428
26472
|
async function signIn(request, reconsent) {
|
|
26429
|
-
|
|
26430
|
-
const source = !reconsent && (options.newProfile || options.profileId) ? await getSession() : void 0;
|
|
26431
|
-
if (source?.accountSignal.aborted) throw pluginError("connection_busy", "\u8D26\u53F7\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
26473
|
+
request.signal.throwIfAborted();
|
|
26432
26474
|
const { current: attempt } = beginTransition("sign-in");
|
|
26433
|
-
if (source?.status === "connected" && source.profileId && source.profileId !== options.profileId) {
|
|
26434
|
-
attempt.addingFrom = source;
|
|
26435
|
-
}
|
|
26436
26475
|
const controller = new AbortController();
|
|
26437
|
-
const signal = AbortSignal.any([controller.signal, request.signal, lifetime.signal]);
|
|
26438
26476
|
attempt.controller = controller;
|
|
26439
26477
|
attempt.promise = (async () => {
|
|
26478
|
+
const options = await profileInput(request, { allowNew: !reconsent });
|
|
26479
|
+
controller.signal.throwIfAborted();
|
|
26480
|
+
const source = !reconsent && (options.newProfile || options.profileId) ? await getSession() : void 0;
|
|
26481
|
+
controller.signal.throwIfAborted();
|
|
26482
|
+
if (source?.accountSignal.aborted) throw pluginError("connection_busy", "\u8D26\u53F7\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
26483
|
+
attempt.addingAccount = isAddingAccount(source, options);
|
|
26484
|
+
attempt.preparing = false;
|
|
26485
|
+
if (!attempt.addingAccount) {
|
|
26486
|
+
invalidateAccount();
|
|
26487
|
+
refreshCatalog(session);
|
|
26488
|
+
}
|
|
26489
|
+
const signals = [controller.signal, lifetime.signal];
|
|
26490
|
+
if (!attempt.addingAccount) signals.push(request.signal);
|
|
26491
|
+
const signal = AbortSignal.any(signals);
|
|
26492
|
+
signal.throwIfAborted();
|
|
26440
26493
|
if (!await credentialEncryption.isAvailable()) {
|
|
26441
26494
|
throw pluginError("storage_encryption_unavailable", "\u65E0\u6CD5\u8BBF\u95EE\u7CFB\u7EDF\u51ED\u636E\u5B58\u50A8\uFF0C\u8BF7\u68C0\u67E5\u5F53\u524D\u7CFB\u7EDF\u8D26\u53F7\u540E\u91CD\u8BD5\u3002");
|
|
26442
26495
|
}
|
|
@@ -26444,7 +26497,6 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26444
26497
|
session = await client.signIn({ ...options, signal, reconsent });
|
|
26445
26498
|
signedOutUnknownProfile = false;
|
|
26446
26499
|
signedOutProfiles.delete(session.profileId);
|
|
26447
|
-
signal.throwIfAborted();
|
|
26448
26500
|
})();
|
|
26449
26501
|
try {
|
|
26450
26502
|
await attempt.promise;
|
|
@@ -26455,7 +26507,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26455
26507
|
async function cancel() {
|
|
26456
26508
|
const attempt = transition;
|
|
26457
26509
|
if (attempt?.kind === "sign-in") {
|
|
26458
|
-
attempt.controller.abort();
|
|
26510
|
+
attempt.controller.abort(pluginError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
|
|
26459
26511
|
await attempt.promise.catch(() => void 0);
|
|
26460
26512
|
}
|
|
26461
26513
|
}
|
|
@@ -26475,7 +26527,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26475
26527
|
const { current, previous } = beginTransition("disconnect");
|
|
26476
26528
|
try {
|
|
26477
26529
|
if (previous) {
|
|
26478
|
-
previous.controller.abort();
|
|
26530
|
+
previous.controller.abort(pluginError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
|
|
26479
26531
|
await previous.promise.catch(() => void 0);
|
|
26480
26532
|
}
|
|
26481
26533
|
await client.disconnect({ expectedProfileId: profileId });
|
|
@@ -26499,8 +26551,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26499
26551
|
const alreadySignedOut = signedOutProfiles.has(profileId);
|
|
26500
26552
|
signedOutProfiles.add(profileId);
|
|
26501
26553
|
if (session.profileId === profileId) {
|
|
26502
|
-
|
|
26503
|
-
account = new AbortController();
|
|
26554
|
+
invalidateAccount();
|
|
26504
26555
|
refreshCatalog(session);
|
|
26505
26556
|
}
|
|
26506
26557
|
try {
|
|
@@ -26530,8 +26581,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26530
26581
|
const current = await getSession();
|
|
26531
26582
|
const saved = available && !disposed ? await client.listProfiles().catch(() => []) : [];
|
|
26532
26583
|
if (!disposed && (current.accountSignal.aborted || pending !== transition)) continue;
|
|
26533
|
-
const { status, sharing: sharing2, error } = current;
|
|
26534
|
-
const { identity: identity2, profileId, profileLabel } = pending?.addingFrom ?? current;
|
|
26584
|
+
const { status, sharing: sharing2, error, identity: identity2, profileId, profileLabel } = current;
|
|
26535
26585
|
const profiles = saved.map((profile) => {
|
|
26536
26586
|
const signedOut = locallySignedOut(profile.id);
|
|
26537
26587
|
return {
|
|
@@ -26544,7 +26594,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26544
26594
|
requiresNewRegistration: profile.requiresNewRegistration
|
|
26545
26595
|
};
|
|
26546
26596
|
});
|
|
26547
|
-
return { status, sharing: sharing2, available, addingAccount: Boolean(pending?.
|
|
26597
|
+
return { status, sharing: sharing2, available, addingAccount: Boolean(pending?.addingAccount), identity: publicIdentity2(identity2), profileId, profileLabel, profiles, features, error: error ? publicError(error) : void 0 };
|
|
26548
26598
|
}
|
|
26549
26599
|
}
|
|
26550
26600
|
const actions = {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-use-chatgpt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "ChatGPT plan model provider for a local DeepSeek Harness desktop instance",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": { "node": "^22.19.0 || >=24.0.0" },
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"./client": "./dist/client.js",
|
|
15
15
|
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
-
"files": ["dist", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
17
|
+
"files": ["dist", "docs/images/chatgpt-settings.png", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
18
18
|
"dsh": {
|
|
19
19
|
"bundle": { "patch": "./cordis.patch.yml" },
|
|
20
20
|
"client": {
|