opencode-copilot-account-switcher 0.14.13 → 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 CHANGED
@@ -1,3 +1,4 @@
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";
@@ -5,6 +6,7 @@ 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";
7
8
  import { connectOrSpawnBroker } from "./wechat/broker-launcher.js";
9
+ import { brokerStartupDiagnosticsPath, ensureWechatStateLayout } from "./wechat/state-paths.js";
8
10
  import { createCodexMenuAdapter } from "./providers/codex-menu-adapter.js";
9
11
  import { createCopilotMenuAdapter } from "./providers/copilot-menu-adapter.js";
10
12
  import { createProviderRegistry } from "./providers/registry.js";
@@ -15,6 +17,43 @@ import { readAuth, readStore, writeStore } from "./store.js";
15
17
  function now() {
16
18
  return Date.now();
17
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
+ }
18
57
  function toSharedRuntimeAction(action) {
19
58
  if (action.type === "cancel")
20
59
  return { type: "cancel" };
@@ -196,9 +235,16 @@ async function createAccountSwitcherPlugin(input, provider) {
196
235
  const directory = input.directory;
197
236
  const serverUrl = input.serverUrl;
198
237
  const ensureWechatBrokerStarted = input.ensureWechatBrokerStarted ?? (async () => connectOrSpawnBroker());
238
+ const diagnosticsPath = brokerStartupDiagnosticsPath();
239
+ const showToast = input.client?.tui?.showToast;
199
240
  void Promise.resolve()
200
241
  .then(() => ensureWechatBrokerStarted())
201
- .catch(() => { });
242
+ .catch((error) => recordBrokerStartupFailure({
243
+ provider,
244
+ diagnosticsPath,
245
+ error,
246
+ showToast,
247
+ }));
202
248
  const persistStore = (store, meta) => writeStore(store, { debug: meta });
203
249
  const codexClient = {
204
250
  auth: {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-copilot-account-switcher",
3
- "version": "0.14.13",
3
+ "version": "0.14.14",
4
4
  "description": "GitHub Copilot account switcher plugin for OpenCode",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",