dsh-cliproxyapi-pro 1.9.0 → 1.9.1

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.en.md +23 -407
  3. package/README.md +23 -407
  4. package/lib/client.js +46 -20
  5. package/lib/host/accounts.js +176 -0
  6. package/lib/host/apply/agent-tool.js +406 -0
  7. package/lib/host/apply/commands.js +122 -0
  8. package/lib/host/apply/controller.js +105 -0
  9. package/lib/host/apply/http-routes.js +273 -0
  10. package/lib/host/apply/image-jobs.js +171 -0
  11. package/lib/host/apply/index.js +41 -0
  12. package/lib/host/apply/interpret.js +72 -0
  13. package/lib/host/apply/lifecycle.js +34 -0
  14. package/lib/host/apply/media-failures.js +68 -0
  15. package/lib/host/apply/media-service.js +202 -0
  16. package/lib/host/apply/quota-service.js +42 -0
  17. package/lib/host/apply/references.js +43 -0
  18. package/lib/host/apply/session-status.js +104 -0
  19. package/lib/host/apply/state.js +78 -0
  20. package/lib/host/apply/updates.js +55 -0
  21. package/lib/host/apply/video-command.js +152 -0
  22. package/lib/host/apply/video-edit.js +253 -0
  23. package/lib/host/apply/video-jobs.js +206 -0
  24. package/lib/host/apply-utils.js +39 -0
  25. package/lib/host/config.js +205 -0
  26. package/lib/host/controller.js +435 -0
  27. package/lib/host/discovery.js +295 -0
  28. package/lib/host/http-gate.js +144 -0
  29. package/lib/host/models.js +102 -0
  30. package/lib/host/mount-guard.js +56 -0
  31. package/lib/host/routes.js +165 -0
  32. package/lib/host/runtime.js +445 -0
  33. package/lib/host/state-store.js +39 -0
  34. package/lib/host/status-text.js +93 -0
  35. package/lib/index.js +17 -4417
  36. package/lib/media/agent-tool.js +255 -0
  37. package/lib/media/choice.js +83 -0
  38. package/lib/media/classify.js +65 -0
  39. package/lib/media/codec/fit.js +76 -0
  40. package/lib/media/codec/jpeg.js +158 -0
  41. package/lib/media/codec/png.js +102 -0
  42. package/lib/media/commands/parsing.js +269 -0
  43. package/lib/media/constants.js +46 -0
  44. package/lib/media/diagnose.js +134 -0
  45. package/lib/media/images.js +165 -0
  46. package/lib/media/index.js +29 -0
  47. package/lib/media/interpret.js +126 -0
  48. package/lib/media/job-store.js +99 -0
  49. package/lib/media/mp4.js +44 -0
  50. package/lib/media/output-files.js +59 -0
  51. package/lib/media/session-store.js +293 -0
  52. package/lib/media/settings.js +255 -0
  53. package/lib/media/util.js +45 -0
  54. package/lib/media/video.js +326 -0
  55. package/lib/quota/auth-state.js +33 -0
  56. package/lib/quota/constants.js +86 -0
  57. package/lib/quota/controller.js +467 -0
  58. package/lib/quota/helpers.js +325 -0
  59. package/lib/quota/index.js +19 -0
  60. package/lib/quota/management.js +216 -0
  61. package/lib/quota/matching.js +143 -0
  62. package/lib/quota/parsers.js +352 -0
  63. package/lib/quota/probes/billing.js +80 -0
  64. package/lib/quota/probes/google.js +120 -0
  65. package/lib/quota/probes/oauth.js +27 -0
  66. package/lib/quota/probes/plugin.js +18 -0
  67. package/lib/updater/constants.js +23 -0
  68. package/lib/updater/errors.js +8 -0
  69. package/lib/updater/index.js +11 -0
  70. package/lib/updater/registry.js +83 -0
  71. package/lib/updater/settings.js +45 -0
  72. package/lib/updater/store.js +23 -0
  73. package/lib/updater/updater.js +148 -0
  74. package/lib/updater/verify.js +110 -0
  75. package/lib/updater/version.js +31 -0
  76. package/locale/en.json +1 -1
  77. package/locale/zh.json +1 -1
  78. package/package.json +6 -9
  79. package/lib/media.js +0 -2542
  80. package/lib/quota.js +0 -1748
  81. package/lib/updater.js +0 -443
@@ -0,0 +1,93 @@
1
+ // Human-readable account discovery and quota status for slash commands.
2
+
3
+ import { DEFAULT_REFRESH_INTERVAL_SECONDS, PROTOCOLS } from "./config.js";
4
+
5
+ export function renderAccountStatus(account) {
6
+ const { config: cfg, credential: keyInfo, status } = account;
7
+ const selectedMode =
8
+ cfg.selectionSaved === false
9
+ ? "Selected Filter: not chosen yet (the first successful probe checks the newest model of each family)"
10
+ : Array.isArray(cfg.selectedModels) && cfg.selectedModels.length > 0
11
+ ? `Selected Filter: ${cfg.selectedModels.length} model(s) checked`
12
+ : "Selected Filter: All models (no selection filter active)";
13
+ const modelListPreview =
14
+ Array.isArray(status.models) && status.models.length > 0
15
+ ? `Active Models in Picker: ${status.models
16
+ .slice(0, 12)
17
+ .map((m) => m.id)
18
+ .join(", ")}${status.models.length > 12 ? ` ... (+${status.models.length - 12} more)` : ""}`
19
+ : undefined;
20
+ const media = (status.allModels ?? []).filter((m) => m.kind === "image" || m.kind === "video");
21
+ const mediaLine =
22
+ media.length > 0
23
+ ? `Media Models (not in the picker): ${media.filter((m) => m.kind === "image").length} image, ${media.filter((m) => m.kind === "video").length} video`
24
+ : undefined;
25
+ const counts = status.protocolCounts ?? {};
26
+ const protocolLine =
27
+ cfg.protocolMode === "fixed"
28
+ ? `Protocol: ${cfg.protocol} (fixed for every model)`
29
+ : `Protocol: native per model (${PROTOCOLS.filter((p) => counts[p])
30
+ .map((p) => `${p}: ${counts[p]}`)
31
+ .join(", ") || "none synced yet"})`;
32
+ const lines = [
33
+ `Account "${cfg.displayName}" [id: ${account.id}] — ${cfg.enabled ? "enabled" : "disabled"}`,
34
+ `CLIProxyAPI Status: ${status.state}`,
35
+ `Provider Routes: ${(status.state === "connected" && status.routes ? status.routes : [cfg.provider]).join(", ")}`,
36
+ protocolLine,
37
+ `Configured Base URL: ${cfg.baseURL || "(auto-discover / inherited)"}`,
38
+ ...(status.endpoint ? [`Active Endpoint: ${status.endpoint}`] : []),
39
+ `API Key Reference: ${keyInfo.ref} (${keyInfo.configured ? "configured" : "not set"})`,
40
+ selectedMode,
41
+ `Synchronized Models: ${status.modelCount}${
42
+ status.totalDiscovered ? ` (of ${status.totalDiscovered} discovered)` : ""
43
+ }`,
44
+ ...(modelListPreview ? [modelListPreview] : []),
45
+ ...(mediaLine ? [mediaLine] : []),
46
+ ...(status.refreshedAt ? [`Last Refreshed: ${status.refreshedAt}`] : []),
47
+ ...(status.error ? [`Error: ${status.error}`] : []),
48
+ ];
49
+ return lines.join("\n");
50
+ }
51
+
52
+ /** One line per account: management key, quota state and what the picker models map to. Never includes keys. */
53
+ export function renderQuotaText(snapshot, onlyAccountId) {
54
+ const accounts = (snapshot?.accounts ?? []).filter((a) => onlyAccountId === undefined || a.accountId === onlyAccountId);
55
+ if (accounts.length === 0) return "";
56
+ const lines = ["Quota (CPA management API):"];
57
+ for (const a of accounts) {
58
+ if (!a.keyConfigured) {
59
+ lines.push(`- ${a.displayName} [${a.accountId}]: no management key (${a.keyRef})`);
60
+ continue;
61
+ }
62
+ const creds = Array.isArray(a.credentials) ? a.credentials : [];
63
+ const state = a.state + (a.errorCode ? ` (${a.errorCode}${a.errorStatus ? ` ${a.errorStatus}` : ""})` : "") +
64
+ (Number.isInteger(a.authFailures) && a.authFailures > 0
65
+ ? `, key rejected ${a.authFailures}/${a.authFailureLimit}${a.authPaused ? ", automatic checks stopped until a new management key is saved" : ""}`
66
+ : "") +
67
+ (a.refreshing ? ", refreshing" : "");
68
+ lines.push(`- ${a.displayName} [${a.accountId}]: ${state}; ${creds.length} credential(s)${a.fetchedAt ? `; fetched ${a.fetchedAt}` : ""}; routes ${(a.routes ?? []).join(", ") || "none"}`);
69
+ for (const m of a.pickerModels ?? []) {
70
+ const ids = a.modelIndex?.[m.id] ?? [];
71
+ const names = ids.map((id) => {
72
+ const c = creds.find((x) => x.id === id);
73
+ if (!c) return id;
74
+ const pct = (c.windows ?? []).map((w) => w.remainingPercent).filter((v) => typeof v === "number");
75
+ return `${c.provider}:${c.label || c.id}${pct.length ? ` ${Math.round(Math.min(...pct))}%` : ""}${c.status === "active" ? "" : ` (${c.status})`}`;
76
+ });
77
+ lines.push(` ${m.route}/${m.id} -> ${names.length ? names.join(", ") : "no credential"} [${a.modelMatch?.[m.id] ?? "none"}]`);
78
+ }
79
+ }
80
+ return lines.join("\n");
81
+ }
82
+
83
+ export function renderStatusText(payload, onlyAccountId) {
84
+ const accounts = payload.accounts ?? [];
85
+ if (accounts.length === 0) {
86
+ return "No CLIProxyAPI account is configured. Add one in Settings → CLIProxyAPI.";
87
+ }
88
+ const shown =
89
+ onlyAccountId === undefined ? accounts : accounts.filter((a) => a.id === onlyAccountId);
90
+ const enabled = accounts.filter((a) => a.config.enabled).length;
91
+ const header = `CLIProxyAPI accounts: ${accounts.length} (${enabled} enabled); auto refresh every ${payload.global?.refreshIntervalSeconds ?? DEFAULT_REFRESH_INTERVAL_SECONDS}s`;
92
+ return [header, ...shown.map(renderAccountStatus)].join("\n\n");
93
+ }