@nextclaw/service 0.1.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 (242) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
  3. package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
  4. package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
  5. package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
  6. package/dist/cli/commands/agent/index.d.ts +3 -0
  7. package/dist/cli/commands/agent/index.js +3 -0
  8. package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
  9. package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
  10. package/dist/cli/commands/companion/index.d.ts +15 -0
  11. package/dist/cli/commands/companion/index.js +24 -0
  12. package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
  13. package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
  14. package/dist/cli/commands/config/index.d.ts +2 -0
  15. package/dist/cli/commands/config/index.js +2 -0
  16. package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
  17. package/dist/cli/commands/config/services/config-commands.service.js +133 -0
  18. package/dist/cli/commands/cron/index.d.ts +2 -0
  19. package/dist/cli/commands/cron/index.js +2 -0
  20. package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
  21. package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
  22. package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
  23. package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
  24. package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
  25. package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
  26. package/dist/cli/commands/diagnostics/index.d.ts +2 -0
  27. package/dist/cli/commands/diagnostics/index.js +2 -0
  28. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
  29. package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
  30. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
  31. package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
  32. package/dist/cli/commands/gateway/index.d.ts +14 -0
  33. package/dist/cli/commands/gateway/index.js +15 -0
  34. package/dist/cli/commands/logs/index.d.ts +12 -0
  35. package/dist/cli/commands/logs/index.js +29 -0
  36. package/dist/cli/commands/mcp/index.d.ts +14 -0
  37. package/dist/cli/commands/mcp/index.js +193 -0
  38. package/dist/cli/commands/restart/index.d.ts +20 -0
  39. package/dist/cli/commands/restart/index.js +88 -0
  40. package/dist/cli/commands/secrets/index.d.ts +22 -0
  41. package/dist/cli/commands/secrets/index.js +280 -0
  42. package/dist/cli/commands/serve/index.d.ts +14 -0
  43. package/dist/cli/commands/serve/index.js +19 -0
  44. package/dist/cli/commands/skills/index.d.ts +26 -0
  45. package/dist/cli/commands/skills/index.js +147 -0
  46. package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
  47. package/dist/cli/commands/skills/marketplace-client.js +84 -0
  48. package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
  49. package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
  50. package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
  51. package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
  52. package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
  53. package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
  54. package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
  55. package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
  56. package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
  57. package/dist/cli/commands/skills/marketplace.service.js +238 -0
  58. package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
  59. package/dist/cli/commands/skills/skills-query.service.js +212 -0
  60. package/dist/cli/commands/start/index.d.ts +18 -0
  61. package/dist/cli/commands/start/index.js +25 -0
  62. package/dist/cli/commands/stop/index.d.ts +12 -0
  63. package/dist/cli/commands/stop/index.js +11 -0
  64. package/dist/cli/commands/ui/index.d.ts +14 -0
  65. package/dist/cli/commands/ui/index.js +17 -0
  66. package/dist/cli/commands/usage/index.d.ts +2 -0
  67. package/dist/cli/commands/usage/index.js +2 -0
  68. package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
  69. package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
  70. package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
  71. package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
  72. package/dist/commands/channel/channel-config-view.d.ts +7 -0
  73. package/dist/commands/channel/channel-config-view.js +7 -0
  74. package/dist/commands/channel/index.d.ts +28 -0
  75. package/dist/commands/channel/index.js +224 -0
  76. package/dist/commands/platform-auth/index.d.ts +2 -0
  77. package/dist/commands/platform-auth/index.js +2 -0
  78. package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
  79. package/dist/commands/platform-auth/services/account-status.service.js +34 -0
  80. package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
  81. package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
  82. package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
  83. package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
  84. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
  85. package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
  86. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
  87. package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
  88. package/dist/commands/plugin/index.d.ts +30 -0
  89. package/dist/commands/plugin/index.js +266 -0
  90. package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
  91. package/dist/commands/plugin/plugin-command-utils.js +37 -0
  92. package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
  93. package/dist/commands/plugin/plugin-extension-registry.js +35 -0
  94. package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
  95. package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
  96. package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
  97. package/dist/commands/plugin/plugin-registry-loader.js +43 -0
  98. package/dist/commands/plugin/plugin-reload.d.ts +13 -0
  99. package/dist/commands/plugin/plugin-reload.js +42 -0
  100. package/dist/commands/remote/index.d.ts +47 -0
  101. package/dist/commands/remote/index.js +174 -0
  102. package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
  103. package/dist/commands/remote/services/remote-access-host.service.js +126 -0
  104. package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
  105. package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
  106. package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
  107. package/dist/commands/remote/services/remote-service-control.service.js +188 -0
  108. package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
  109. package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
  110. package/dist/commands/service/index.d.ts +16 -0
  111. package/dist/commands/service/index.js +31 -0
  112. package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
  113. package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
  114. package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
  115. package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
  116. package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
  117. package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
  118. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
  119. package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
  120. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
  121. package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
  122. package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
  123. package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
  124. package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
  125. package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
  126. package/dist/index.d.ts +4 -0
  127. package/dist/index.js +3 -0
  128. package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
  129. package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
  130. package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
  131. package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
  132. package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
  133. package/dist/launcher/npm-runtime-bundle.service.js +150 -0
  134. package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
  135. package/dist/launcher/npm-runtime-bundle.types.js +1 -0
  136. package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
  137. package/dist/launcher/npm-runtime-launcher.service.js +57 -0
  138. package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
  139. package/dist/launcher/npm-runtime-update-command.service.js +87 -0
  140. package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
  141. package/dist/launcher/npm-runtime-update-source.service.js +57 -0
  142. package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
  143. package/dist/launcher/npm-runtime-update-state.store.js +92 -0
  144. package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
  145. package/dist/launcher/npm-runtime-update.manager.js +179 -0
  146. package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
  147. package/dist/launcher/npm-runtime-update.service.js +183 -0
  148. package/dist/service-runtime.service.d.ts +91 -0
  149. package/dist/service-runtime.service.js +392 -0
  150. package/dist/shared/controllers/gateway.controller.d.ts +61 -0
  151. package/dist/shared/controllers/gateway.controller.js +318 -0
  152. package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
  153. package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
  154. package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
  155. package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
  156. package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
  157. package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
  158. package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
  159. package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
  160. package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
  161. package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
  162. package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
  163. package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
  164. package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
  165. package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
  166. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
  167. package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
  168. package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
  169. package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
  170. package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
  171. package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
  172. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
  173. package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
  174. package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
  175. package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
  176. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
  177. package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
  178. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
  179. package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
  180. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
  181. package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
  182. package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
  183. package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
  184. package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
  185. package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
  186. package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
  187. package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
  188. package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
  189. package/dist/shared/services/runtime/runtime-command.service.js +163 -0
  190. package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
  191. package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
  192. package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
  193. package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
  194. package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
  195. package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
  196. package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
  197. package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
  198. package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
  199. package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
  200. package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
  201. package/dist/shared/services/ui/companion-runtime.service.js +145 -0
  202. package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
  203. package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
  204. package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
  205. package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
  206. package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
  207. package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
  208. package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
  209. package/dist/shared/services/ui/service-remote-access.service.js +38 -0
  210. package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
  211. package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
  212. package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
  213. package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
  214. package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
  215. package/dist/shared/stores/companion-runtime.store.js +27 -0
  216. package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
  217. package/dist/shared/stores/local-ui-runtime.store.js +54 -0
  218. package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
  219. package/dist/shared/stores/managed-service-state.store.js +38 -0
  220. package/dist/shared/stores/pending-restart.store.d.ts +21 -0
  221. package/dist/shared/stores/pending-restart.store.js +35 -0
  222. package/dist/shared/types/cli.types.d.ts +295 -0
  223. package/dist/shared/types/cli.types.js +1 -0
  224. package/dist/shared/utils/cli.utils.d.ts +34 -0
  225. package/dist/shared/utils/cli.utils.js +262 -0
  226. package/dist/shared/utils/config-path.d.ts +15 -0
  227. package/dist/shared/utils/config-path.js +167 -0
  228. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
  229. package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
  230. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
  231. package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
  232. package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
  233. package/dist/shared/utils/package/package-manifest.utils.js +48 -0
  234. package/dist/shared/utils/runtime-helpers.d.ts +14 -0
  235. package/dist/shared/utils/runtime-helpers.js +26 -0
  236. package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
  237. package/dist/shared/utils/service-port-probe.utils.js +164 -0
  238. package/dist/shared/utils/startup-trace.d.ts +7 -0
  239. package/dist/shared/utils/startup-trace.js +37 -0
  240. package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
  241. package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
  242. package/package.json +68 -0
@@ -0,0 +1,85 @@
1
+ import { LlmUsageStore } from "@nextclaw/kernel";
2
+ //#region src/cli/commands/usage/services/llm-usage-query.service.ts
3
+ var LlmUsageQueryService = class {
4
+ store;
5
+ constructor(deps = {}) {
6
+ this.store = deps.store ?? new LlmUsageStore();
7
+ }
8
+ get snapshotPath() {
9
+ return this.store.snapshotPath;
10
+ }
11
+ get historyPath() {
12
+ return this.store.historyPath;
13
+ }
14
+ getSnapshot = () => {
15
+ return this.store.readSnapshot();
16
+ };
17
+ getHistory = (limit) => {
18
+ const records = this.store.listHistory();
19
+ const resolvedLimit = this.resolveLimit(limit);
20
+ return records.slice(-resolvedLimit).reverse();
21
+ };
22
+ getStats = () => {
23
+ const records = this.store.listHistory();
24
+ const sources = /* @__PURE__ */ new Map();
25
+ const models = /* @__PURE__ */ new Map();
26
+ let totalPromptTokens = 0;
27
+ let totalCompletionTokens = 0;
28
+ let totalTokens = 0;
29
+ let totalCachedTokens = 0;
30
+ let cacheHitRecords = 0;
31
+ let usageRecordCount = 0;
32
+ let promptTokenRecordCount = 0;
33
+ for (const record of records) {
34
+ if (Object.keys(record.usage).length > 0) usageRecordCount += 1;
35
+ totalPromptTokens += record.summary.promptTokens;
36
+ totalCompletionTokens += record.summary.completionTokens;
37
+ totalTokens += record.summary.totalTokens;
38
+ totalCachedTokens += record.summary.cachedTokens;
39
+ if (record.summary.promptTokens > 0) promptTokenRecordCount += 1;
40
+ if (record.summary.cacheHit) cacheHitRecords += 1;
41
+ this.bumpCounter(sources, record.source);
42
+ this.bumpCounter(models, record.model ?? "unknown");
43
+ }
44
+ return {
45
+ totalRecords: records.length,
46
+ usageRecordCount,
47
+ emptyUsageRecordCount: records.length - usageRecordCount,
48
+ promptTokenRecordCount,
49
+ oldestObservedAt: records[0]?.observedAt ?? null,
50
+ latestObservedAt: records.at(-1)?.observedAt ?? null,
51
+ totalPromptTokens,
52
+ totalCompletionTokens,
53
+ totalTokens,
54
+ totalCachedTokens,
55
+ cacheHitRecords,
56
+ cacheHitRate: promptTokenRecordCount > 0 ? cacheHitRecords / promptTokenRecordCount : 0,
57
+ tokenCacheRate: totalPromptTokens > 0 ? totalCachedTokens / totalPromptTokens : 0,
58
+ sources: this.toSortedCounts(sources),
59
+ models: this.toSortedCounts(models)
60
+ };
61
+ };
62
+ resolveLimit = (value) => {
63
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
64
+ if (typeof value === "string" && value.trim().length > 0) {
65
+ const parsed = Number(value);
66
+ if (Number.isFinite(parsed) && parsed > 0) return Math.floor(parsed);
67
+ }
68
+ return 10;
69
+ };
70
+ bumpCounter = (map, value) => {
71
+ map.set(value, (map.get(value) ?? 0) + 1);
72
+ };
73
+ toSortedCounts = (map) => {
74
+ return [...map.entries()].map(([value, count]) => ({
75
+ value,
76
+ count
77
+ })).sort((left, right) => {
78
+ if (right.count !== left.count) return right.count - left.count;
79
+ return left.value.localeCompare(right.value);
80
+ });
81
+ };
82
+ };
83
+ const llmUsageQueryService = new LlmUsageQueryService();
84
+ //#endregion
85
+ export { LlmUsageQueryService, llmUsageQueryService };
@@ -0,0 +1,7 @@
1
+ import { Config } from "@nextclaw/core";
2
+ import { PluginChannelBinding } from "@nextclaw/openclaw-compat";
3
+
4
+ //#region src/commands/channel/channel-config-view.d.ts
5
+ declare function resolveChannelConfigView(config: Config, bindings: PluginChannelBinding[]): Config;
6
+ //#endregion
7
+ export { resolveChannelConfigView };
@@ -0,0 +1,7 @@
1
+ import { toPluginConfigView } from "@nextclaw/openclaw-compat";
2
+ //#region src/commands/channel/channel-config-view.ts
3
+ function resolveChannelConfigView(config, bindings) {
4
+ return toPluginConfigView(config, bindings);
5
+ }
6
+ //#endregion
7
+ export { resolveChannelConfigView };
@@ -0,0 +1,28 @@
1
+ import { ChannelsAddOptions, ChannelsLoginOptions, RequestRestartParams } from "../../shared/types/cli.types.js";
2
+ import { resolveChannelConfigView } from "./channel-config-view.js";
3
+
4
+ //#region src/commands/channel/index.d.ts
5
+ declare class ChannelCommands {
6
+ private deps;
7
+ constructor(deps: {
8
+ logo: string;
9
+ getBridgeDir: () => string;
10
+ requestRestart: (params: RequestRestartParams) => Promise<void>;
11
+ });
12
+ status: () => void;
13
+ login: (opts?: ChannelsLoginOptions) => Promise<void>;
14
+ private runLegacyBridgeLogin;
15
+ private resolvePluginChannelContext;
16
+ private loginPluginChannel;
17
+ private clonePluginConfig;
18
+ private assertValidPluginLoginResult;
19
+ private buildNextConfigAfterChannelLogin;
20
+ private printPluginChannelLoginResult;
21
+ add: (opts: ChannelsAddOptions) => Promise<void>;
22
+ private requireChannelId;
23
+ private resolveRequiredChannelBinding;
24
+ private resolveRequiredChannelSetup;
25
+ private buildChannelSetupInput;
26
+ }
27
+ //#endregion
28
+ export { ChannelCommands, resolveChannelConfigView };
@@ -0,0 +1,224 @@
1
+ import { resolveChannelConfigView } from "./channel-config-view.js";
2
+ import { loadPluginRegistry, mergePluginConfigView, toPluginConfigView as toPluginConfigView$1 } from "../plugin/index.js";
3
+ import { spawnSync } from "node:child_process";
4
+ import { getWorkspacePath, loadConfig, saveConfig } from "@nextclaw/core";
5
+ import { buildPluginStatusReport, enablePluginInConfig, getPluginChannelBindings } from "@nextclaw/openclaw-compat";
6
+ import { BUILTIN_CHANNEL_PLUGIN_IDS, builtinProviderIds } from "@nextclaw/runtime";
7
+ //#region src/commands/channel/index.ts
8
+ const CHANNEL_LABELS = {
9
+ telegram: "Telegram",
10
+ whatsapp: "WhatsApp",
11
+ discord: "Discord",
12
+ feishu: "Feishu",
13
+ mochat: "Mochat",
14
+ dingtalk: "DingTalk",
15
+ wecom: "WeCom",
16
+ email: "Email",
17
+ slack: "Slack",
18
+ qq: "QQ",
19
+ weixin: "Weixin"
20
+ };
21
+ const RESERVED_PROVIDER_IDS = builtinProviderIds();
22
+ function resolveChannelBindings(pluginRegistry) {
23
+ return getPluginChannelBindings(pluginRegistry);
24
+ }
25
+ var ChannelCommands = class {
26
+ constructor(deps) {
27
+ this.deps = deps;
28
+ }
29
+ status = () => {
30
+ const config = loadConfig();
31
+ const workspaceDir = getWorkspacePath(config.agents.defaults.workspace);
32
+ const channelConfig = resolveChannelConfigView(config, resolveChannelBindings(loadPluginRegistry(config, workspaceDir)));
33
+ console.log("Channel Status");
34
+ const channels = channelConfig.channels;
35
+ for (const channelId of BUILTIN_CHANNEL_PLUGIN_IDS) {
36
+ const label = CHANNEL_LABELS[channelId] ?? channelId;
37
+ const enabled = channels[channelId]?.enabled === true;
38
+ console.log(`${label}: ${enabled ? "✓" : "✗"}`);
39
+ }
40
+ const pluginChannels = buildPluginStatusReport({
41
+ config,
42
+ workspaceDir,
43
+ reservedChannelIds: [],
44
+ reservedProviderIds: RESERVED_PROVIDER_IDS
45
+ }).plugins.filter((plugin) => plugin.status === "loaded" && plugin.channelIds.length > 0);
46
+ if (pluginChannels.length > 0) {
47
+ console.log("Plugin Channels:");
48
+ for (const plugin of pluginChannels) {
49
+ const channels = plugin.channelIds.join(", ");
50
+ console.log(`- ${channels} (plugin: ${plugin.id})`);
51
+ }
52
+ }
53
+ };
54
+ login = async (opts = {}) => {
55
+ const channelId = opts.channel?.trim();
56
+ if (!channelId) {
57
+ this.runLegacyBridgeLogin();
58
+ return;
59
+ }
60
+ const config = loadConfig();
61
+ const channelContext = this.resolvePluginChannelContext(config, channelId);
62
+ if (!channelContext) {
63
+ console.error(`No plugin channel found for: ${channelId}`);
64
+ process.exit(1);
65
+ }
66
+ const result = await this.loginPluginChannel(config, channelContext, opts);
67
+ if (!result) return;
68
+ saveConfig(this.buildNextConfigAfterChannelLogin(config, channelContext.binding, result));
69
+ this.printPluginChannelLoginResult(channelContext.binding, result);
70
+ await this.deps.requestRestart({
71
+ mode: "notify",
72
+ reason: `channel login via plugin: ${channelContext.binding.pluginId}`,
73
+ manualMessage: "渠道配置已保存,等待你手动重启后生效。"
74
+ });
75
+ };
76
+ runLegacyBridgeLogin = () => {
77
+ const bridgeDir = this.deps.getBridgeDir();
78
+ console.log(`${this.deps.logo} Starting bridge...`);
79
+ console.log("Scan the QR code to connect.\n");
80
+ const result = spawnSync("npm", ["start"], {
81
+ cwd: bridgeDir,
82
+ stdio: "inherit"
83
+ });
84
+ if (result.status !== 0) console.error(`Bridge failed: ${result.status ?? 1}`);
85
+ };
86
+ resolvePluginChannelContext = (config, channelId) => {
87
+ const bindings = resolveChannelBindings(loadPluginRegistry(config, getWorkspacePath(config.agents.defaults.workspace)));
88
+ const binding = bindings.find((entry) => entry.channelId === channelId || entry.pluginId === channelId);
89
+ if (!binding) return null;
90
+ return {
91
+ binding,
92
+ bindings
93
+ };
94
+ };
95
+ loginPluginChannel = async (config, channelContext, opts) => {
96
+ const { binding, bindings } = channelContext;
97
+ const login = binding.channel.auth?.login;
98
+ if (!login) {
99
+ if (binding.channelId === "whatsapp") {
100
+ this.runLegacyBridgeLogin();
101
+ return null;
102
+ }
103
+ console.error(`Channel "${binding.channelId}" does not support login.`);
104
+ process.exit(1);
105
+ }
106
+ const configView = resolveChannelConfigView(config, bindings);
107
+ const result = await login({
108
+ cfg: configView,
109
+ pluginId: binding.pluginId,
110
+ channelId: binding.channelId,
111
+ pluginConfig: this.clonePluginConfig(configView.channels?.[binding.channelId]),
112
+ accountId: opts.account?.trim() || null,
113
+ baseUrl: opts.url?.trim() || opts.httpUrl?.trim() || null,
114
+ verbose: Boolean(opts.verbose)
115
+ });
116
+ this.assertValidPluginLoginResult(result);
117
+ return result;
118
+ };
119
+ clonePluginConfig = (value) => {
120
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
121
+ return JSON.parse(JSON.stringify(value));
122
+ };
123
+ assertValidPluginLoginResult = (result) => {
124
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
125
+ console.error("Channel login returned an invalid result.");
126
+ process.exit(1);
127
+ }
128
+ const record = result;
129
+ if (!record.pluginConfig || typeof record.pluginConfig !== "object" || Array.isArray(record.pluginConfig)) {
130
+ console.error("Channel login returned an invalid plugin config.");
131
+ process.exit(1);
132
+ }
133
+ };
134
+ buildNextConfigAfterChannelLogin = (config, binding, result) => {
135
+ return enablePluginInConfig({
136
+ ...config,
137
+ channels: {
138
+ ...config.channels,
139
+ [binding.channelId]: result.pluginConfig
140
+ }
141
+ }, binding.pluginId);
142
+ };
143
+ printPluginChannelLoginResult = (binding, result) => {
144
+ console.log(`Logged into channel "${binding.channelId}" via plugin "${binding.pluginId}".`);
145
+ if (result.accountId) console.log(`Active account: ${result.accountId}`);
146
+ for (const note of result.notes ?? []) console.log(note);
147
+ };
148
+ add = async (opts) => {
149
+ const channelId = this.requireChannelId(opts);
150
+ const config = loadConfig();
151
+ const pluginRegistry = loadPluginRegistry(config, getWorkspacePath(config.agents.defaults.workspace));
152
+ const { binding, bindings } = this.resolveRequiredChannelBinding(pluginRegistry, channelId);
153
+ const setup = this.resolveRequiredChannelSetup(binding);
154
+ const input = this.buildChannelSetupInput(opts);
155
+ const currentView = toPluginConfigView$1(config, bindings);
156
+ const accountId = binding.channel.config?.defaultAccountId?.(currentView) ?? "default";
157
+ const validateError = setup.validateInput?.({
158
+ cfg: currentView,
159
+ input,
160
+ accountId
161
+ });
162
+ if (validateError) {
163
+ console.error(`Channel setup validation failed: ${validateError}`);
164
+ process.exit(1);
165
+ }
166
+ const nextView = setup.applyAccountConfig({
167
+ cfg: currentView,
168
+ input,
169
+ accountId
170
+ });
171
+ if (!nextView || typeof nextView !== "object" || Array.isArray(nextView)) {
172
+ console.error("Channel setup returned invalid config payload.");
173
+ process.exit(1);
174
+ }
175
+ let next = mergePluginConfigView(config, nextView, bindings);
176
+ next = enablePluginInConfig(next, binding.pluginId);
177
+ saveConfig(next);
178
+ console.log(`Configured channel "${binding.channelId}" via plugin "${binding.pluginId}".`);
179
+ await this.deps.requestRestart({
180
+ mode: "notify",
181
+ reason: `channel configured via plugin: ${binding.pluginId}`,
182
+ manualMessage: "渠道配置已保存,等待你手动重启后生效。"
183
+ });
184
+ };
185
+ requireChannelId = (opts) => {
186
+ const channelId = opts.channel?.trim();
187
+ if (!channelId) {
188
+ console.error("--channel is required");
189
+ process.exit(1);
190
+ }
191
+ return channelId;
192
+ };
193
+ resolveRequiredChannelBinding = (pluginRegistry, channelId) => {
194
+ const bindings = resolveChannelBindings(pluginRegistry);
195
+ const binding = bindings.find((entry) => entry.channelId === channelId || entry.pluginId === channelId);
196
+ if (!binding) {
197
+ console.error(`No plugin channel found for: ${channelId}`);
198
+ process.exit(1);
199
+ }
200
+ return {
201
+ binding,
202
+ bindings
203
+ };
204
+ };
205
+ resolveRequiredChannelSetup = (binding) => {
206
+ const setup = binding.channel.setup;
207
+ if (!setup?.applyAccountConfig) {
208
+ console.error(`Channel "${binding.channelId}" does not support setup.`);
209
+ process.exit(1);
210
+ }
211
+ return setup;
212
+ };
213
+ buildChannelSetupInput = (opts) => {
214
+ return {
215
+ name: opts.name,
216
+ token: opts.token,
217
+ code: opts.code,
218
+ url: opts.url,
219
+ httpUrl: opts.httpUrl
220
+ };
221
+ };
222
+ };
223
+ //#endregion
224
+ export { ChannelCommands, resolveChannelConfigView };
@@ -0,0 +1,2 @@
1
+ import { PlatformAuthCommands, PlatformBrowserAuthPollResult, PlatformBrowserAuthStartResult, PlatformLoginResult, PlatformMeResult, PlatformUserView } from "./services/platform-auth-commands.service.js";
2
+ export { PlatformAuthCommands, PlatformBrowserAuthPollResult, PlatformBrowserAuthStartResult, PlatformLoginResult, PlatformMeResult, PlatformUserView };
@@ -0,0 +1,2 @@
1
+ import { PlatformAuthCommands } from "./services/platform-auth-commands.service.js";
2
+ export { PlatformAuthCommands };
@@ -0,0 +1,18 @@
1
+ import { PlatformMeResult } from "./platform-auth-commands.service.js";
2
+ //#region src/commands/platform-auth/services/account-status.service.d.ts
3
+ type AccountStatusView = {
4
+ email: string;
5
+ role: string;
6
+ username: string | null;
7
+ platformBase: string;
8
+ v1Base: string;
9
+ publishReadiness: "ready" | "needs_username";
10
+ personalScope: string | null;
11
+ nextClawWebAccountUrl: string;
12
+ cliSetUsernameCommand: string;
13
+ };
14
+ declare function toAccountStatusView(result: PlatformMeResult): AccountStatusView;
15
+ declare function printAccountStatus(view: AccountStatusView): void;
16
+ declare function printUsernameUpdated(view: AccountStatusView): void;
17
+ //#endregion
18
+ export { AccountStatusView, printAccountStatus, printUsernameUpdated, toAccountStatusView };
@@ -0,0 +1,34 @@
1
+ //#region src/commands/platform-auth/services/account-status.service.ts
2
+ const NEXTCLAW_WEB_ACCOUNT_URL = "https://platform.nextclaw.io/account";
3
+ const ACCOUNT_SET_USERNAME_HELP = "nextclaw account set-username <username>";
4
+ function toAccountStatusView(result) {
5
+ const username = result.user.username?.trim() || null;
6
+ return {
7
+ email: result.user.email,
8
+ role: result.user.role,
9
+ username,
10
+ platformBase: result.platformBase,
11
+ v1Base: result.v1Base,
12
+ publishReadiness: username ? "ready" : "needs_username",
13
+ personalScope: username ? `@${username}/*` : null,
14
+ nextClawWebAccountUrl: NEXTCLAW_WEB_ACCOUNT_URL,
15
+ cliSetUsernameCommand: ACCOUNT_SET_USERNAME_HELP
16
+ };
17
+ }
18
+ function printAccountStatus(view) {
19
+ console.log("NextClaw account status");
20
+ console.log(`Email: ${view.email}`);
21
+ console.log(`Role: ${view.role}`);
22
+ console.log(`Username: ${view.username ?? "(not set)"}`);
23
+ console.log(`Publish readiness: ${view.publishReadiness === "ready" ? "ready" : "action required - username missing"}`);
24
+ console.log(`Personal scope: ${view.personalScope ?? "(blocked until username is set)"}`);
25
+ console.log(`NextClaw Web account settings: ${view.nextClawWebAccountUrl}`);
26
+ console.log(`CLI fallback: ${view.cliSetUsernameCommand}`);
27
+ }
28
+ function printUsernameUpdated(view) {
29
+ console.log(`✓ Username saved: ${view.username}`);
30
+ console.log(`✓ Personal publish scope: ${view.personalScope}`);
31
+ console.log(`✓ NextClaw Web account settings: ${view.nextClawWebAccountUrl}`);
32
+ }
33
+ //#endregion
34
+ export { printAccountStatus, printUsernameUpdated, toAccountStatusView };
@@ -0,0 +1,77 @@
1
+ import { AccountCommandOptions, AccountSetUsernameCommandOptions, LoginCommandOptions } from "../../../shared/types/cli.types.js";
2
+
3
+ //#region src/commands/platform-auth/services/platform-auth-commands.service.d.ts
4
+ type PlatformLoginResult = {
5
+ token: string;
6
+ role: string;
7
+ email: string;
8
+ platformBase: string;
9
+ v1Base: string;
10
+ };
11
+ type PlatformUserView = {
12
+ id: string;
13
+ email: string;
14
+ username: string | null;
15
+ role: string;
16
+ };
17
+ type PlatformMeResult = {
18
+ user: PlatformUserView;
19
+ token: string;
20
+ platformBase: string;
21
+ v1Base: string;
22
+ };
23
+ type PlatformBrowserAuthStartResult = {
24
+ sessionId: string;
25
+ verificationUri: string;
26
+ expiresAt: string;
27
+ intervalMs: number;
28
+ platformBase: string;
29
+ v1Base: string;
30
+ };
31
+ type PlatformBrowserAuthPollResult = {
32
+ status: "pending";
33
+ nextPollMs: number;
34
+ } | {
35
+ status: "authorized";
36
+ token: string;
37
+ role: string;
38
+ email: string;
39
+ platformBase: string;
40
+ v1Base: string;
41
+ } | {
42
+ status: "expired";
43
+ message: string;
44
+ };
45
+ declare class PlatformAuthCommands {
46
+ private shouldUseBrowserLogin;
47
+ private waitFor;
48
+ private formatLoginDeadline;
49
+ private printLoginSuccess;
50
+ private printBrowserLoginIntro;
51
+ private waitForBrowserLoginResult;
52
+ private loginWithBrowserResult;
53
+ private readStoredToken;
54
+ loginResult: (opts?: LoginCommandOptions) => Promise<PlatformLoginResult>;
55
+ startBrowserAuth: (opts?: Pick<LoginCommandOptions, "apiBase">) => Promise<PlatformBrowserAuthStartResult>;
56
+ pollBrowserAuth: (params: {
57
+ apiBase?: string;
58
+ sessionId: string;
59
+ }) => Promise<PlatformBrowserAuthPollResult>;
60
+ login: (opts?: LoginCommandOptions) => Promise<void>;
61
+ me: (params?: {
62
+ apiBase?: string;
63
+ }) => Promise<PlatformMeResult>;
64
+ updateProfile: (params: {
65
+ username: string;
66
+ apiBase?: string;
67
+ }) => Promise<PlatformMeResult>;
68
+ logout: () => {
69
+ cleared: boolean;
70
+ };
71
+ accountStatus: (opts?: AccountCommandOptions) => Promise<void>;
72
+ accountSetUsername: (opts: AccountSetUsernameCommandOptions & {
73
+ username: string;
74
+ }) => Promise<void>;
75
+ }
76
+ //#endregion
77
+ export { PlatformAuthCommands, PlatformBrowserAuthPollResult, PlatformBrowserAuthStartResult, PlatformLoginResult, PlatformMeResult, PlatformUserView };