opencode-copilot-account-switcher 0.14.12 → 0.14.14
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/plugin.js +52 -0
- package/dist/wechat/state-paths.d.ts +1 -0
- package/dist/wechat/state-paths.js +3 -0
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { appendFile } from "node:fs/promises";
|
|
1
2
|
import { normalizeDomain } from "./copilot-api-helpers.js";
|
|
2
3
|
import { listAssignableAccountsForModel, listKnownCopilotModels, rewriteModelAccountAssignments, } from "./model-account-map.js";
|
|
3
4
|
import { runProviderMenu } from "./menu-runtime.js";
|
|
4
5
|
import { persistAccountSwitch } from "./plugin-actions.js";
|
|
5
6
|
import { buildPluginHooks } from "./plugin-hooks.js";
|
|
6
7
|
import { readCommonSettingsStore, readCommonSettingsStoreSync, writeCommonSettingsStore, } from "./common-settings-store.js";
|
|
8
|
+
import { connectOrSpawnBroker } from "./wechat/broker-launcher.js";
|
|
9
|
+
import { brokerStartupDiagnosticsPath, ensureWechatStateLayout } from "./wechat/state-paths.js";
|
|
7
10
|
import { createCodexMenuAdapter } from "./providers/codex-menu-adapter.js";
|
|
8
11
|
import { createCopilotMenuAdapter } from "./providers/copilot-menu-adapter.js";
|
|
9
12
|
import { createProviderRegistry } from "./providers/registry.js";
|
|
@@ -14,6 +17,43 @@ import { readAuth, readStore, writeStore } from "./store.js";
|
|
|
14
17
|
function now() {
|
|
15
18
|
return Date.now();
|
|
16
19
|
}
|
|
20
|
+
function formatBrokerStartupError(error) {
|
|
21
|
+
if (error instanceof Error) {
|
|
22
|
+
return error.stack ?? `${error.name}: ${error.message}`;
|
|
23
|
+
}
|
|
24
|
+
if (typeof error === "string")
|
|
25
|
+
return error;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.stringify(error);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return String(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function recordBrokerStartupFailure(input) {
|
|
34
|
+
const reason = formatBrokerStartupError(input.error);
|
|
35
|
+
const line = JSON.stringify({
|
|
36
|
+
at: new Date().toISOString(),
|
|
37
|
+
provider: input.provider,
|
|
38
|
+
reason,
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
await ensureWechatStateLayout();
|
|
42
|
+
await appendFile(input.diagnosticsPath, `${line}\n`, "utf8");
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await input.showToast?.({
|
|
48
|
+
body: {
|
|
49
|
+
message: `Wechat broker 启动失败,已写入诊断文件:${input.diagnosticsPath}`,
|
|
50
|
+
variant: "warning",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
17
57
|
function toSharedRuntimeAction(action) {
|
|
18
58
|
if (action.type === "cancel")
|
|
19
59
|
return { type: "cancel" };
|
|
@@ -194,6 +234,17 @@ async function createAccountSwitcherPlugin(input, provider) {
|
|
|
194
234
|
const client = input.client;
|
|
195
235
|
const directory = input.directory;
|
|
196
236
|
const serverUrl = input.serverUrl;
|
|
237
|
+
const ensureWechatBrokerStarted = input.ensureWechatBrokerStarted ?? (async () => connectOrSpawnBroker());
|
|
238
|
+
const diagnosticsPath = brokerStartupDiagnosticsPath();
|
|
239
|
+
const showToast = input.client?.tui?.showToast;
|
|
240
|
+
void Promise.resolve()
|
|
241
|
+
.then(() => ensureWechatBrokerStarted())
|
|
242
|
+
.catch((error) => recordBrokerStartupFailure({
|
|
243
|
+
provider,
|
|
244
|
+
diagnosticsPath,
|
|
245
|
+
error,
|
|
246
|
+
showToast,
|
|
247
|
+
}));
|
|
197
248
|
const persistStore = (store, meta) => writeStore(store, { debug: meta });
|
|
198
249
|
const codexClient = {
|
|
199
250
|
auth: {
|
|
@@ -379,6 +430,7 @@ async function createAccountSwitcherPlugin(input, provider) {
|
|
|
379
430
|
client,
|
|
380
431
|
directory,
|
|
381
432
|
serverUrl,
|
|
433
|
+
ensureWechatBrokerStarted: async () => { },
|
|
382
434
|
loadCommonSettings: readCommonSettingsStore,
|
|
383
435
|
loadCommonSettingsSync: readCommonSettingsStoreSync,
|
|
384
436
|
});
|
|
@@ -4,6 +4,7 @@ export type WechatRequestKind = "question" | "permission";
|
|
|
4
4
|
export declare function wechatStateRoot(): string;
|
|
5
5
|
export declare function brokerStatePath(): string;
|
|
6
6
|
export declare function wechatStatusRuntimeDiagnosticsPath(stateRoot?: string): string;
|
|
7
|
+
export declare function brokerStartupDiagnosticsPath(stateRoot?: string): string;
|
|
7
8
|
export declare function launchLockPath(): string;
|
|
8
9
|
export declare function operatorStatePath(): string;
|
|
9
10
|
export declare function instancesDir(): string;
|
|
@@ -12,6 +12,9 @@ export function brokerStatePath() {
|
|
|
12
12
|
export function wechatStatusRuntimeDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
13
13
|
return path.join(stateRoot, "wechat-status-runtime.diagnostics.jsonl");
|
|
14
14
|
}
|
|
15
|
+
export function brokerStartupDiagnosticsPath(stateRoot = wechatStateRoot()) {
|
|
16
|
+
return path.join(stateRoot, "broker-startup.diagnostics.log");
|
|
17
|
+
}
|
|
15
18
|
export function launchLockPath() {
|
|
16
19
|
return path.join(wechatStateRoot(), "launch.lock");
|
|
17
20
|
}
|