@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.
- package/LICENSE +21 -0
- package/dist/cli/commands/agent/agent-runtime.utils.d.ts +15 -0
- package/dist/cli/commands/agent/agent-runtime.utils.js +85 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.d.ts +21 -0
- package/dist/cli/commands/agent/cli-agent-runner.utils.js +89 -0
- package/dist/cli/commands/agent/index.d.ts +3 -0
- package/dist/cli/commands/agent/index.js +3 -0
- package/dist/cli/commands/agent/services/agent-commands.service.d.ts +17 -0
- package/dist/cli/commands/agent/services/agent-commands.service.js +112 -0
- package/dist/cli/commands/companion/index.d.ts +15 -0
- package/dist/cli/commands/companion/index.js +24 -0
- package/dist/cli/commands/companion/services/companion-process.service.d.ts +17 -0
- package/dist/cli/commands/companion/services/companion-process.service.js +49 -0
- package/dist/cli/commands/config/index.d.ts +2 -0
- package/dist/cli/commands/config/index.js +2 -0
- package/dist/cli/commands/config/services/config-commands.service.d.ts +18 -0
- package/dist/cli/commands/config/services/config-commands.service.js +133 -0
- package/dist/cli/commands/cron/index.d.ts +2 -0
- package/dist/cli/commands/cron/index.js +2 -0
- package/dist/cli/commands/cron/services/cron-commands.service.d.ts +22 -0
- package/dist/cli/commands/cron/services/cron-commands.service.js +107 -0
- package/dist/cli/commands/cron/services/cron-local.service.d.ts +25 -0
- package/dist/cli/commands/cron/services/cron-local.service.js +95 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.d.ts +31 -0
- package/dist/cli/commands/cron/utils/cron-job.utils.js +15 -0
- package/dist/cli/commands/diagnostics/index.d.ts +2 -0
- package/dist/cli/commands/diagnostics/index.js +2 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.d.ts +22 -0
- package/dist/cli/commands/diagnostics/services/diagnostics-commands.service.js +319 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.d.ts +23 -0
- package/dist/cli/commands/diagnostics/utils/diagnostics-render.utils.js +66 -0
- package/dist/cli/commands/gateway/index.d.ts +14 -0
- package/dist/cli/commands/gateway/index.js +15 -0
- package/dist/cli/commands/logs/index.d.ts +12 -0
- package/dist/cli/commands/logs/index.js +29 -0
- package/dist/cli/commands/mcp/index.d.ts +14 -0
- package/dist/cli/commands/mcp/index.js +193 -0
- package/dist/cli/commands/restart/index.d.ts +20 -0
- package/dist/cli/commands/restart/index.js +88 -0
- package/dist/cli/commands/secrets/index.d.ts +22 -0
- package/dist/cli/commands/secrets/index.js +280 -0
- package/dist/cli/commands/serve/index.d.ts +14 -0
- package/dist/cli/commands/serve/index.js +19 -0
- package/dist/cli/commands/skills/index.d.ts +26 -0
- package/dist/cli/commands/skills/index.js +147 -0
- package/dist/cli/commands/skills/marketplace-client.d.ts +31 -0
- package/dist/cli/commands/skills/marketplace-client.js +84 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.d.ts +25 -0
- package/dist/cli/commands/skills/marketplace-command-options.utils.js +31 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.d.ts +14 -0
- package/dist/cli/commands/skills/marketplace-identity.utils.js +77 -0
- package/dist/cli/commands/skills/marketplace-network-retry.d.ts +4 -0
- package/dist/cli/commands/skills/marketplace-network-retry.js +32 -0
- package/dist/cli/commands/skills/marketplace.metadata.d.ts +29 -0
- package/dist/cli/commands/skills/marketplace.metadata.js +158 -0
- package/dist/cli/commands/skills/marketplace.service.d.ts +46 -0
- package/dist/cli/commands/skills/marketplace.service.js +238 -0
- package/dist/cli/commands/skills/skills-query.service.d.ts +141 -0
- package/dist/cli/commands/skills/skills-query.service.js +212 -0
- package/dist/cli/commands/start/index.d.ts +18 -0
- package/dist/cli/commands/start/index.js +25 -0
- package/dist/cli/commands/stop/index.d.ts +12 -0
- package/dist/cli/commands/stop/index.js +11 -0
- package/dist/cli/commands/ui/index.d.ts +14 -0
- package/dist/cli/commands/ui/index.js +17 -0
- package/dist/cli/commands/usage/index.d.ts +2 -0
- package/dist/cli/commands/usage/index.js +2 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.d.ts +22 -0
- package/dist/cli/commands/usage/services/llm-usage-command.service.js +160 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.d.ts +43 -0
- package/dist/cli/commands/usage/services/llm-usage-query.service.js +85 -0
- package/dist/commands/channel/channel-config-view.d.ts +7 -0
- package/dist/commands/channel/channel-config-view.js +7 -0
- package/dist/commands/channel/index.d.ts +28 -0
- package/dist/commands/channel/index.js +224 -0
- package/dist/commands/platform-auth/index.d.ts +2 -0
- package/dist/commands/platform-auth/index.js +2 -0
- package/dist/commands/platform-auth/services/account-status.service.d.ts +18 -0
- package/dist/commands/platform-auth/services/account-status.service.js +34 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.d.ts +77 -0
- package/dist/commands/platform-auth/services/platform-auth-commands.service.js +295 -0
- package/dist/commands/platform-auth/utils/payload.utils.d.ts +28 -0
- package/dist/commands/platform-auth/utils/payload.utils.js +87 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.d.ts +18 -0
- package/dist/commands/plugin/development-source/dev-plugin-overrides.utils.js +111 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.d.ts +9 -0
- package/dist/commands/plugin/development-source/first-party-plugin-load-paths.js +183 -0
- package/dist/commands/plugin/index.d.ts +30 -0
- package/dist/commands/plugin/index.js +266 -0
- package/dist/commands/plugin/plugin-command-utils.d.ts +13 -0
- package/dist/commands/plugin/plugin-command-utils.js +37 -0
- package/dist/commands/plugin/plugin-extension-registry.d.ts +10 -0
- package/dist/commands/plugin/plugin-extension-registry.js +35 -0
- package/dist/commands/plugin/plugin-mutation-actions.d.ts +15 -0
- package/dist/commands/plugin/plugin-mutation-actions.js +162 -0
- package/dist/commands/plugin/plugin-registry-loader.d.ts +15 -0
- package/dist/commands/plugin/plugin-registry-loader.js +43 -0
- package/dist/commands/plugin/plugin-reload.d.ts +13 -0
- package/dist/commands/plugin/plugin-reload.js +42 -0
- package/dist/commands/remote/index.d.ts +47 -0
- package/dist/commands/remote/index.js +174 -0
- package/dist/commands/remote/services/remote-access-host.service.d.ts +41 -0
- package/dist/commands/remote/services/remote-access-host.service.js +126 -0
- package/dist/commands/remote/services/remote-runtime-support.service.d.ts +15 -0
- package/dist/commands/remote/services/remote-runtime-support.service.js +79 -0
- package/dist/commands/remote/services/remote-service-control.service.d.ts +33 -0
- package/dist/commands/remote/services/remote-service-control.service.js +188 -0
- package/dist/commands/remote/utils/platform-api-base.utils.d.ts +14 -0
- package/dist/commands/remote/utils/platform-api-base.utils.js +39 -0
- package/dist/commands/service/index.d.ts +16 -0
- package/dist/commands/service/index.js +31 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.d.ts +29 -0
- package/dist/commands/service/services/autostart/host-autostart-command.service.js +158 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.d.ts +23 -0
- package/dist/commands/service/services/autostart/host-autostart-runtime.service.js +53 -0
- package/dist/commands/service/services/autostart/host-autostart.service.d.ts +41 -0
- package/dist/commands/service/services/autostart/host-autostart.service.js +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.d.ts +48 -0
- package/dist/commands/service/services/autostart/linux-systemd-autostart.service.js +433 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/macos-launch-agent-autostart.service.js +405 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.d.ts +54 -0
- package/dist/commands/service/services/autostart/windows-task-autostart.service.js +403 -0
- package/dist/commands/service/types/autostart/host-autostart.types.d.ts +64 -0
- package/dist/commands/service/types/autostart/host-autostart.types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.d.ts +23 -0
- package/dist/launcher/npm-runtime-bundle-layout.store.js +37 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.d.ts +9 -0
- package/dist/launcher/npm-runtime-bundle-manifest.service.js +39 -0
- package/dist/launcher/npm-runtime-bundle.service.d.ts +47 -0
- package/dist/launcher/npm-runtime-bundle.service.js +150 -0
- package/dist/launcher/npm-runtime-bundle.types.d.ts +49 -0
- package/dist/launcher/npm-runtime-bundle.types.js +1 -0
- package/dist/launcher/npm-runtime-launcher.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-launcher.service.js +57 -0
- package/dist/launcher/npm-runtime-update-command.service.d.ts +12 -0
- package/dist/launcher/npm-runtime-update-command.service.js +87 -0
- package/dist/launcher/npm-runtime-update-source.service.d.ts +19 -0
- package/dist/launcher/npm-runtime-update-source.service.js +57 -0
- package/dist/launcher/npm-runtime-update-state.store.d.ts +17 -0
- package/dist/launcher/npm-runtime-update-state.store.js +92 -0
- package/dist/launcher/npm-runtime-update.manager.d.ts +42 -0
- package/dist/launcher/npm-runtime-update.manager.js +179 -0
- package/dist/launcher/npm-runtime-update.service.d.ts +54 -0
- package/dist/launcher/npm-runtime-update.service.js +183 -0
- package/dist/service-runtime.service.d.ts +91 -0
- package/dist/service-runtime.service.js +392 -0
- package/dist/shared/controllers/gateway.controller.d.ts +61 -0
- package/dist/shared/controllers/gateway.controller.js +318 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.d.ts +56 -0
- package/dist/shared/services/extensions/extension-lifecycle.service.js +143 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.d.ts +51 -0
- package/dist/shared/services/extensions/service-extension-runtime.service.js +338 -0
- package/dist/shared/services/gateway/cron-job-handler.service.d.ts +26 -0
- package/dist/shared/services/gateway/cron-job-handler.service.js +100 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.d.ts +12 -0
- package/dist/shared/services/gateway/gateway-restart-wake.service.js +91 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.d.ts +37 -0
- package/dist/shared/services/gateway/managers/gateway-plugin.manager.js +218 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.d.ts +20 -0
- package/dist/shared/services/gateway/managers/gateway-remote.manager.js +25 -0
- package/dist/shared/services/gateway/nextclaw-app.service.d.ts +22 -0
- package/dist/shared/services/gateway/nextclaw-app.service.js +53 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.d.ts +89 -0
- package/dist/shared/services/gateway/nextclaw-gateway-runtime.service.js +337 -0
- package/dist/shared/services/gateway/service-bootstrap-status.d.ts +33 -0
- package/dist/shared/services/gateway/service-bootstrap-status.js +152 -0
- package/dist/shared/services/gateway/service-startup-support.service.d.ts +42 -0
- package/dist/shared/services/gateway/service-startup-support.service.js +96 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.d.ts +9 -0
- package/dist/shared/services/gateway/utils/gateway-runtime-lifecycle.utils.js +10 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.d.ts +31 -0
- package/dist/shared/services/marketplace/service-marketplace-installer.service.js +99 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.d.ts +39 -0
- package/dist/shared/services/marketplace/service-mcp-marketplace-ops.js +67 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.d.ts +24 -0
- package/dist/shared/services/plugin/utils/plugin-dev-hot-reload.utils.js +117 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.d.ts +6 -0
- package/dist/shared/services/plugin/utils/plugin-runtime-bridge.utils.js +96 -0
- package/dist/shared/services/restart/restart-coordinator.service.d.ts +30 -0
- package/dist/shared/services/restart/restart-coordinator.service.js +51 -0
- package/dist/shared/services/restart/restart-sentinel.service.d.ts +39 -0
- package/dist/shared/services/restart/restart-sentinel.service.js +88 -0
- package/dist/shared/services/restart/runtime-restart-request.service.d.ts +24 -0
- package/dist/shared/services/restart/runtime-restart-request.service.js +42 -0
- package/dist/shared/services/runtime/runtime-command.service.d.ts +37 -0
- package/dist/shared/services/runtime/runtime-command.service.js +163 -0
- package/dist/shared/services/runtime/runtime-config-init.service.d.ts +4 -0
- package/dist/shared/services/runtime/runtime-config-init.service.js +10 -0
- package/dist/shared/services/runtime/service-managed-startup.service.d.ts +146 -0
- package/dist/shared/services/runtime/service-managed-startup.service.js +426 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.d.ts +53 -0
- package/dist/shared/services/runtime/service-remote-runtime.service.js +173 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.d.ts +12 -0
- package/dist/shared/services/runtime/utils/skills-loader.utils.js +9 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.d.ts +14 -0
- package/dist/shared/services/session/service-deferred-ncp-agent.service.js +85 -0
- package/dist/shared/services/ui/companion-runtime.service.d.ts +33 -0
- package/dist/shared/services/ui/companion-runtime.service.js +145 -0
- package/dist/shared/services/ui/local-ui-discovery.service.d.ts +19 -0
- package/dist/shared/services/ui/local-ui-discovery.service.js +41 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.d.ts +40 -0
- package/dist/shared/services/ui/npm-runtime-update-host.service.js +181 -0
- package/dist/shared/services/ui/runtime-control-host.service.d.ts +28 -0
- package/dist/shared/services/ui/runtime-control-host.service.js +89 -0
- package/dist/shared/services/ui/service-remote-access.service.d.ts +25 -0
- package/dist/shared/services/ui/service-remote-access.service.js +38 -0
- package/dist/shared/services/ui/ui-bridge-api.service.d.ts +16 -0
- package/dist/shared/services/ui/ui-bridge-api.service.js +43 -0
- package/dist/shared/services/workspace/workspace-manager.service.d.ts +19 -0
- package/dist/shared/services/workspace/workspace-manager.service.js +135 -0
- package/dist/shared/stores/companion-runtime.store.d.ts +15 -0
- package/dist/shared/stores/companion-runtime.store.js +27 -0
- package/dist/shared/stores/local-ui-runtime.store.d.ts +25 -0
- package/dist/shared/stores/local-ui-runtime.store.js +54 -0
- package/dist/shared/stores/managed-service-state.store.d.ts +28 -0
- package/dist/shared/stores/managed-service-state.store.js +38 -0
- package/dist/shared/stores/pending-restart.store.d.ts +21 -0
- package/dist/shared/stores/pending-restart.store.js +35 -0
- package/dist/shared/types/cli.types.d.ts +295 -0
- package/dist/shared/types/cli.types.js +1 -0
- package/dist/shared/utils/cli.utils.d.ts +34 -0
- package/dist/shared/utils/cli.utils.js +262 -0
- package/dist/shared/utils/config-path.d.ts +15 -0
- package/dist/shared/utils/config-path.js +167 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.d.ts +16 -0
- package/dist/shared/utils/marketplace/cli-subcommand-launch.utils.js +46 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.d.ts +9 -0
- package/dist/shared/utils/marketplace/service-marketplace-helpers.utils.js +33 -0
- package/dist/shared/utils/package/package-manifest.utils.d.ts +8 -0
- package/dist/shared/utils/package/package-manifest.utils.js +48 -0
- package/dist/shared/utils/runtime-helpers.d.ts +14 -0
- package/dist/shared/utils/runtime-helpers.js +26 -0
- package/dist/shared/utils/service-port-probe.utils.d.ts +41 -0
- package/dist/shared/utils/service-port-probe.utils.js +164 -0
- package/dist/shared/utils/startup-trace.d.ts +7 -0
- package/dist/shared/utils/startup-trace.js +37 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.d.ts +4 -0
- package/dist/shared/utils/top-level-nextclaw-command-env.utils.js +10 -0
- package/package.json +68 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { LocalizedTextMap } from "./marketplace.metadata.js";
|
|
2
|
+
import { SkillScope } from "@nextclaw/core";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/commands/skills/skills-query.service.d.ts
|
|
5
|
+
type MarketplaceSkillSort = "relevance" | "updated";
|
|
6
|
+
type MarketplaceSkillInstallKind = "builtin" | "marketplace";
|
|
7
|
+
type MarketplaceInstallSpec = {
|
|
8
|
+
kind: MarketplaceSkillInstallKind;
|
|
9
|
+
spec: string;
|
|
10
|
+
command: string;
|
|
11
|
+
};
|
|
12
|
+
type MarketplaceSkillItemSummary = {
|
|
13
|
+
id: string;
|
|
14
|
+
slug: string;
|
|
15
|
+
type: "skill";
|
|
16
|
+
name: string;
|
|
17
|
+
summary: string;
|
|
18
|
+
summaryI18n: LocalizedTextMap;
|
|
19
|
+
tags: string[];
|
|
20
|
+
author: string;
|
|
21
|
+
install: MarketplaceInstallSpec;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
};
|
|
24
|
+
type MarketplaceSkillItemView = MarketplaceSkillItemSummary & {
|
|
25
|
+
description?: string;
|
|
26
|
+
descriptionI18n?: LocalizedTextMap;
|
|
27
|
+
sourceRepo?: string;
|
|
28
|
+
homepage?: string;
|
|
29
|
+
publishedAt: string;
|
|
30
|
+
};
|
|
31
|
+
type MarketplaceSkillContentView = {
|
|
32
|
+
type: "skill";
|
|
33
|
+
slug: string;
|
|
34
|
+
name: string;
|
|
35
|
+
install: MarketplaceInstallSpec;
|
|
36
|
+
source: "builtin" | "marketplace" | "remote";
|
|
37
|
+
raw: string;
|
|
38
|
+
metadataRaw?: string;
|
|
39
|
+
bodyRaw: string;
|
|
40
|
+
sourceUrl?: string;
|
|
41
|
+
};
|
|
42
|
+
type MarketplaceSkillListView = {
|
|
43
|
+
total: number;
|
|
44
|
+
page: number;
|
|
45
|
+
pageSize: number;
|
|
46
|
+
totalPages: number;
|
|
47
|
+
sort: MarketplaceSkillSort;
|
|
48
|
+
query?: string;
|
|
49
|
+
items: MarketplaceSkillItemSummary[];
|
|
50
|
+
};
|
|
51
|
+
type MarketplaceSkillRecommendationView = {
|
|
52
|
+
type: "skill";
|
|
53
|
+
sceneId: string;
|
|
54
|
+
title: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
total: number;
|
|
57
|
+
items: MarketplaceSkillItemSummary[];
|
|
58
|
+
};
|
|
59
|
+
type InstalledSkillSummaryView = {
|
|
60
|
+
ref: string;
|
|
61
|
+
name: string;
|
|
62
|
+
path: string;
|
|
63
|
+
relativePath: string | null;
|
|
64
|
+
scope: SkillScope;
|
|
65
|
+
source: SkillScope;
|
|
66
|
+
summary: string | null;
|
|
67
|
+
summaryI18n: LocalizedTextMap | null;
|
|
68
|
+
description: string | null;
|
|
69
|
+
descriptionI18n: LocalizedTextMap | null;
|
|
70
|
+
author: string | null;
|
|
71
|
+
tags: string[];
|
|
72
|
+
always: boolean;
|
|
73
|
+
};
|
|
74
|
+
type InstalledSkillDetailView = InstalledSkillSummaryView & {
|
|
75
|
+
metadata: Record<string, string> | null;
|
|
76
|
+
raw: string;
|
|
77
|
+
bodyRaw: string;
|
|
78
|
+
};
|
|
79
|
+
type InstalledSkillsListView = {
|
|
80
|
+
workspace: string;
|
|
81
|
+
total: number;
|
|
82
|
+
skills: InstalledSkillSummaryView[];
|
|
83
|
+
};
|
|
84
|
+
type MarketplaceSkillsSearchView = MarketplaceSkillListView & {
|
|
85
|
+
apiBaseUrl: string;
|
|
86
|
+
};
|
|
87
|
+
type MarketplaceSkillInfoView = {
|
|
88
|
+
apiBaseUrl: string;
|
|
89
|
+
item: MarketplaceSkillItemView;
|
|
90
|
+
content: MarketplaceSkillContentView | null;
|
|
91
|
+
contentUnavailableReason: string | null;
|
|
92
|
+
};
|
|
93
|
+
type MarketplaceSkillsRecommendationResultView = MarketplaceSkillRecommendationView & {
|
|
94
|
+
apiBaseUrl: string;
|
|
95
|
+
};
|
|
96
|
+
declare class SkillsQueryService {
|
|
97
|
+
listInstalled: (params: {
|
|
98
|
+
workdir: string;
|
|
99
|
+
query?: string;
|
|
100
|
+
scope?: string;
|
|
101
|
+
}) => InstalledSkillsListView;
|
|
102
|
+
getInstalledInfo: (params: {
|
|
103
|
+
workdir: string;
|
|
104
|
+
selector: string;
|
|
105
|
+
}) => InstalledSkillDetailView;
|
|
106
|
+
searchMarketplaceSkills: (params: {
|
|
107
|
+
apiBaseUrl?: string;
|
|
108
|
+
query?: string;
|
|
109
|
+
tag?: string;
|
|
110
|
+
sort?: string;
|
|
111
|
+
page?: string | number;
|
|
112
|
+
pageSize?: string | number;
|
|
113
|
+
}) => Promise<MarketplaceSkillsSearchView>;
|
|
114
|
+
getMarketplaceSkillInfo: (params: {
|
|
115
|
+
apiBaseUrl?: string;
|
|
116
|
+
slug: string;
|
|
117
|
+
}) => Promise<MarketplaceSkillInfoView>;
|
|
118
|
+
recommendMarketplaceSkills: (params: {
|
|
119
|
+
apiBaseUrl?: string;
|
|
120
|
+
scene?: string;
|
|
121
|
+
limit?: string | number;
|
|
122
|
+
}) => Promise<MarketplaceSkillsRecommendationResultView>;
|
|
123
|
+
private buildInstalledSkillSummary;
|
|
124
|
+
private buildInstalledSkillDetail;
|
|
125
|
+
private matchesInstalledSkillQuery;
|
|
126
|
+
private stripFrontmatter;
|
|
127
|
+
private readAlwaysFlag;
|
|
128
|
+
private buildRelativePath;
|
|
129
|
+
private normalizeMarketplaceSummary;
|
|
130
|
+
private normalizeMarketplaceItem;
|
|
131
|
+
private normalizeMarketplaceContent;
|
|
132
|
+
private normalizeMarketplaceInstallSpec;
|
|
133
|
+
private normalizeInstalledScope;
|
|
134
|
+
private normalizeMarketplaceSort;
|
|
135
|
+
private normalizePositiveInteger;
|
|
136
|
+
private normalizeRequiredString;
|
|
137
|
+
private normalizeOptionalString;
|
|
138
|
+
private fetchMarketplaceView;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { InstalledSkillDetailView, InstalledSkillSummaryView, InstalledSkillsListView, MarketplaceSkillInfoView, MarketplaceSkillsRecommendationResultView, MarketplaceSkillsSearchView, SkillsQueryService };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { parseSkillFrontmatter } from "./marketplace.metadata.js";
|
|
2
|
+
import { runWithMarketplaceNetworkRetry } from "./marketplace-network-retry.js";
|
|
3
|
+
import { readMarketplaceEnvelope, resolveMarketplaceApiBase } from "./marketplace-client.js";
|
|
4
|
+
import { relative, resolve } from "node:path";
|
|
5
|
+
import { SkillsLoader } from "@nextclaw/core";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
//#region src/cli/commands/skills/skills-query.service.ts
|
|
8
|
+
var SkillsQueryService = class {
|
|
9
|
+
listInstalled = (params) => {
|
|
10
|
+
const workspace = resolve(params.workdir);
|
|
11
|
+
const loader = new SkillsLoader(workspace);
|
|
12
|
+
const scope = this.normalizeInstalledScope(params.scope);
|
|
13
|
+
const normalizedQuery = this.normalizeOptionalString(params.query)?.toLowerCase() ?? null;
|
|
14
|
+
const skills = loader.listSkills(false).map((skill) => this.buildInstalledSkillSummary(skill, loader, workspace)).filter((skill) => scope === "all" || skill.scope === scope).filter((skill) => this.matchesInstalledSkillQuery(skill, normalizedQuery));
|
|
15
|
+
return {
|
|
16
|
+
workspace,
|
|
17
|
+
total: skills.length,
|
|
18
|
+
skills
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
getInstalledInfo = (params) => {
|
|
22
|
+
const workspace = resolve(params.workdir);
|
|
23
|
+
const loader = new SkillsLoader(workspace);
|
|
24
|
+
const skill = loader.getSkillInfo(params.selector);
|
|
25
|
+
if (!skill) throw new Error(`Installed skill not found: ${params.selector}`);
|
|
26
|
+
return this.buildInstalledSkillDetail(skill, loader, workspace);
|
|
27
|
+
};
|
|
28
|
+
searchMarketplaceSkills = async (params) => {
|
|
29
|
+
const apiBaseUrl = resolveMarketplaceApiBase(params.apiBaseUrl);
|
|
30
|
+
const result = await this.fetchMarketplaceView({
|
|
31
|
+
apiBaseUrl,
|
|
32
|
+
path: "/api/v1/skills/items",
|
|
33
|
+
query: {
|
|
34
|
+
q: this.normalizeOptionalString(params.query) ?? void 0,
|
|
35
|
+
tag: this.normalizeOptionalString(params.tag) ?? void 0,
|
|
36
|
+
sort: this.normalizeMarketplaceSort(params.sort),
|
|
37
|
+
page: this.normalizePositiveInteger(params.page),
|
|
38
|
+
pageSize: this.normalizePositiveInteger(params.pageSize)
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
apiBaseUrl,
|
|
43
|
+
...result,
|
|
44
|
+
items: result.items.map((item) => this.normalizeMarketplaceSummary(item))
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
getMarketplaceSkillInfo = async (params) => {
|
|
48
|
+
const slug = this.normalizeRequiredString(params.slug, "skill slug");
|
|
49
|
+
const apiBaseUrl = resolveMarketplaceApiBase(params.apiBaseUrl);
|
|
50
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
51
|
+
const item = await this.fetchMarketplaceView({
|
|
52
|
+
apiBaseUrl,
|
|
53
|
+
path: `/api/v1/skills/items/${encodedSlug}`
|
|
54
|
+
});
|
|
55
|
+
let content = null;
|
|
56
|
+
let contentUnavailableReason = null;
|
|
57
|
+
try {
|
|
58
|
+
content = this.normalizeMarketplaceContent(await this.fetchMarketplaceView({
|
|
59
|
+
apiBaseUrl,
|
|
60
|
+
path: `/api/v1/skills/items/${encodedSlug}/content`
|
|
61
|
+
}));
|
|
62
|
+
} catch (error) {
|
|
63
|
+
contentUnavailableReason = error instanceof Error ? error.message : String(error);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
apiBaseUrl,
|
|
67
|
+
item: this.normalizeMarketplaceItem(item),
|
|
68
|
+
content,
|
|
69
|
+
contentUnavailableReason
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
recommendMarketplaceSkills = async (params) => {
|
|
73
|
+
const apiBaseUrl = resolveMarketplaceApiBase(params.apiBaseUrl);
|
|
74
|
+
const result = await this.fetchMarketplaceView({
|
|
75
|
+
apiBaseUrl,
|
|
76
|
+
path: "/api/v1/skills/recommendations",
|
|
77
|
+
query: {
|
|
78
|
+
scene: this.normalizeOptionalString(params.scene) ?? void 0,
|
|
79
|
+
limit: this.normalizePositiveInteger(params.limit)
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
apiBaseUrl,
|
|
84
|
+
...result,
|
|
85
|
+
items: result.items.map((item) => this.normalizeMarketplaceSummary(item))
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
buildInstalledSkillSummary = (skill, loader, workspace) => {
|
|
89
|
+
const raw = readFileSync(skill.path, "utf8");
|
|
90
|
+
const metadata = loader.getSkillMetadata(skill);
|
|
91
|
+
const frontmatter = parseSkillFrontmatter(raw);
|
|
92
|
+
return {
|
|
93
|
+
ref: skill.ref,
|
|
94
|
+
name: skill.name,
|
|
95
|
+
path: skill.path,
|
|
96
|
+
relativePath: this.buildRelativePath(workspace, skill.path),
|
|
97
|
+
scope: skill.scope,
|
|
98
|
+
source: skill.source,
|
|
99
|
+
summary: frontmatter.summary ?? null,
|
|
100
|
+
summaryI18n: frontmatter.summaryI18n ?? null,
|
|
101
|
+
description: frontmatter.description ?? metadata?.description ?? null,
|
|
102
|
+
descriptionI18n: frontmatter.descriptionI18n ?? null,
|
|
103
|
+
author: frontmatter.author ?? null,
|
|
104
|
+
tags: frontmatter.tags ?? [],
|
|
105
|
+
always: this.readAlwaysFlag(metadata)
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
buildInstalledSkillDetail = (skill, loader, workspace) => {
|
|
109
|
+
const summary = this.buildInstalledSkillSummary(skill, loader, workspace);
|
|
110
|
+
const raw = readFileSync(skill.path, "utf8");
|
|
111
|
+
return {
|
|
112
|
+
...summary,
|
|
113
|
+
metadata: loader.getSkillMetadata(skill),
|
|
114
|
+
raw,
|
|
115
|
+
bodyRaw: this.stripFrontmatter(raw)
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
matchesInstalledSkillQuery = (skill, query) => {
|
|
119
|
+
if (!query) return true;
|
|
120
|
+
return [
|
|
121
|
+
skill.ref,
|
|
122
|
+
skill.name,
|
|
123
|
+
skill.path,
|
|
124
|
+
skill.relativePath ?? "",
|
|
125
|
+
skill.scope,
|
|
126
|
+
skill.source,
|
|
127
|
+
skill.summary ?? "",
|
|
128
|
+
skill.description ?? "",
|
|
129
|
+
skill.author ?? "",
|
|
130
|
+
...skill.tags,
|
|
131
|
+
...Object.values(skill.summaryI18n ?? {}),
|
|
132
|
+
...Object.values(skill.descriptionI18n ?? {})
|
|
133
|
+
].some((value) => value.toLowerCase().includes(query));
|
|
134
|
+
};
|
|
135
|
+
stripFrontmatter = (raw) => {
|
|
136
|
+
const normalized = raw.replace(/\r\n/g, "\n");
|
|
137
|
+
const match = normalized.match(/^---\n[\s\S]*?\n---\n?/);
|
|
138
|
+
if (!match) return normalized.trim();
|
|
139
|
+
return normalized.slice(match[0].length).trim();
|
|
140
|
+
};
|
|
141
|
+
readAlwaysFlag = (metadata) => {
|
|
142
|
+
if (metadata?.always === "true") return true;
|
|
143
|
+
const raw = metadata?.metadata;
|
|
144
|
+
if (!raw) return false;
|
|
145
|
+
try {
|
|
146
|
+
return JSON.parse(raw).nextclaw?.always === true;
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
buildRelativePath = (workspace, absolutePath) => {
|
|
152
|
+
const relativePath = relative(workspace, absolutePath).replace(/\\/g, "/");
|
|
153
|
+
return relativePath.startsWith("..") ? null : relativePath;
|
|
154
|
+
};
|
|
155
|
+
normalizeMarketplaceSummary = (item) => ({
|
|
156
|
+
...item,
|
|
157
|
+
install: this.normalizeMarketplaceInstallSpec(item.install, item.slug)
|
|
158
|
+
});
|
|
159
|
+
normalizeMarketplaceItem = (item) => ({
|
|
160
|
+
...item,
|
|
161
|
+
install: this.normalizeMarketplaceInstallSpec(item.install, item.slug)
|
|
162
|
+
});
|
|
163
|
+
normalizeMarketplaceContent = (content) => ({
|
|
164
|
+
...content,
|
|
165
|
+
install: this.normalizeMarketplaceInstallSpec(content.install, content.slug)
|
|
166
|
+
});
|
|
167
|
+
normalizeMarketplaceInstallSpec = (install, slug) => ({
|
|
168
|
+
...install,
|
|
169
|
+
command: `nextclaw marketplace skills install ${slug}`
|
|
170
|
+
});
|
|
171
|
+
normalizeInstalledScope = (value) => {
|
|
172
|
+
const normalized = this.normalizeOptionalString(value);
|
|
173
|
+
if (!normalized || normalized === "all") return "all";
|
|
174
|
+
if (normalized === "builtin" || normalized === "project" || normalized === "workspace") return normalized;
|
|
175
|
+
throw new Error(`Invalid skill scope: ${value}. Expected all, builtin, project, or workspace.`);
|
|
176
|
+
};
|
|
177
|
+
normalizeMarketplaceSort = (value) => {
|
|
178
|
+
const normalized = this.normalizeOptionalString(value);
|
|
179
|
+
if (!normalized) return;
|
|
180
|
+
if (normalized === "relevance" || normalized === "updated") return normalized;
|
|
181
|
+
throw new Error(`Invalid marketplace sort: ${value}. Expected relevance or updated.`);
|
|
182
|
+
};
|
|
183
|
+
normalizePositiveInteger = (value) => {
|
|
184
|
+
if (value === void 0) return;
|
|
185
|
+
const parsed = Number(value);
|
|
186
|
+
if (!Number.isFinite(parsed) || parsed <= 0) throw new Error(`Expected a positive integer, received: ${String(value)}`);
|
|
187
|
+
return String(Math.floor(parsed));
|
|
188
|
+
};
|
|
189
|
+
normalizeRequiredString = (value, label) => {
|
|
190
|
+
const normalized = this.normalizeOptionalString(value);
|
|
191
|
+
if (!normalized) throw new Error(`Missing ${label}`);
|
|
192
|
+
return normalized;
|
|
193
|
+
};
|
|
194
|
+
normalizeOptionalString = (value) => {
|
|
195
|
+
if (typeof value !== "string") return null;
|
|
196
|
+
const trimmed = value.trim();
|
|
197
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
198
|
+
};
|
|
199
|
+
fetchMarketplaceView = async (params) => {
|
|
200
|
+
const url = new URL(params.path, `${params.apiBaseUrl}/`);
|
|
201
|
+
for (const [key, value] of Object.entries(params.query ?? {})) if (typeof value === "string" && value.length > 0) url.searchParams.set(key, value);
|
|
202
|
+
const response = await runWithMarketplaceNetworkRetry(async () => await fetch(url.toString(), { headers: { Accept: "application/json" } }));
|
|
203
|
+
const payload = await readMarketplaceEnvelope(response);
|
|
204
|
+
if (!payload.ok || !payload.data) {
|
|
205
|
+
const message = payload.error?.message || `marketplace request failed: ${response.status}`;
|
|
206
|
+
throw new Error(message);
|
|
207
|
+
}
|
|
208
|
+
return payload.data;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
export { SkillsQueryService };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StartCommandOptions } from "../../../shared/types/cli.types.js";
|
|
2
|
+
import { RuntimeCommandService } from "../../../shared/services/runtime/runtime-command.service.js";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/commands/start/index.d.ts
|
|
5
|
+
declare class StartCommands {
|
|
6
|
+
private readonly deps;
|
|
7
|
+
constructor(deps: {
|
|
8
|
+
runtimeCommandService: RuntimeCommandService;
|
|
9
|
+
forcedPublicHost: string;
|
|
10
|
+
init: (params: {
|
|
11
|
+
source: string;
|
|
12
|
+
auto: boolean;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
});
|
|
15
|
+
run: (opts: StartCommandOptions) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { StartCommands };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { parseStartTimeoutMs, resolveManagedServiceUiOverrides } from "../../../shared/utils/runtime-helpers.js";
|
|
2
|
+
//#region src/cli/commands/start/index.ts
|
|
3
|
+
var StartCommands = class {
|
|
4
|
+
constructor(deps) {
|
|
5
|
+
this.deps = deps;
|
|
6
|
+
}
|
|
7
|
+
run = async (opts) => {
|
|
8
|
+
const startupTimeoutMs = parseStartTimeoutMs(opts.startTimeout);
|
|
9
|
+
await this.deps.init({
|
|
10
|
+
source: "start",
|
|
11
|
+
auto: true
|
|
12
|
+
});
|
|
13
|
+
const uiOverrides = resolveManagedServiceUiOverrides({
|
|
14
|
+
uiPort: opts.uiPort,
|
|
15
|
+
forcedPublicHost: this.deps.forcedPublicHost
|
|
16
|
+
});
|
|
17
|
+
await this.deps.runtimeCommandService.startService({
|
|
18
|
+
uiOverrides,
|
|
19
|
+
open: Boolean(opts.open),
|
|
20
|
+
startupTimeoutMs
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { StartCommands };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RuntimeCommandService } from "../../../shared/services/runtime/runtime-command.service.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/commands/stop/index.d.ts
|
|
4
|
+
declare class StopCommands {
|
|
5
|
+
private readonly deps;
|
|
6
|
+
constructor(deps: {
|
|
7
|
+
runtimeCommandService: RuntimeCommandService;
|
|
8
|
+
});
|
|
9
|
+
run: () => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { StopCommands };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UiCommandOptions } from "../../../shared/types/cli.types.js";
|
|
2
|
+
import { RuntimeCommandService } from "../../../shared/services/runtime/runtime-command.service.js";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/commands/ui/index.d.ts
|
|
5
|
+
declare class UiCommands {
|
|
6
|
+
private readonly deps;
|
|
7
|
+
constructor(deps: {
|
|
8
|
+
runtimeCommandService: RuntimeCommandService;
|
|
9
|
+
forcedPublicHost: string;
|
|
10
|
+
});
|
|
11
|
+
run: (opts: UiCommandOptions) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { UiCommands };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/cli/commands/ui/index.ts
|
|
2
|
+
var UiCommands = class {
|
|
3
|
+
constructor(deps) {
|
|
4
|
+
this.deps = deps;
|
|
5
|
+
}
|
|
6
|
+
run = async (opts) => {
|
|
7
|
+
const uiOverrides = {
|
|
8
|
+
enabled: true,
|
|
9
|
+
host: this.deps.forcedPublicHost,
|
|
10
|
+
open: Boolean(opts.open)
|
|
11
|
+
};
|
|
12
|
+
if (opts.port) uiOverrides.port = Number(opts.port);
|
|
13
|
+
await this.deps.runtimeCommandService.startGateway({ uiOverrides });
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { UiCommands };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UsageCommandOptions } from "../../../../shared/types/cli.types.js";
|
|
2
|
+
import { LlmUsageQueryService } from "./llm-usage-query.service.js";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/commands/usage/services/llm-usage-command.service.d.ts
|
|
5
|
+
declare class LlmUsageCommandService {
|
|
6
|
+
private readonly deps;
|
|
7
|
+
constructor(deps?: {
|
|
8
|
+
queryService?: LlmUsageQueryService;
|
|
9
|
+
});
|
|
10
|
+
readonly show: (opts?: UsageCommandOptions) => Promise<void>;
|
|
11
|
+
private get queryService();
|
|
12
|
+
private readonly showSnapshot;
|
|
13
|
+
private readonly showHistory;
|
|
14
|
+
private readonly showStats;
|
|
15
|
+
private readonly renderSnapshot;
|
|
16
|
+
private readonly renderHistory;
|
|
17
|
+
private readonly renderStats;
|
|
18
|
+
private readonly resolveLimit;
|
|
19
|
+
private readonly toPercent;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { LlmUsageCommandService };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { llmUsageQueryService } from "./llm-usage-query.service.js";
|
|
2
|
+
//#region src/cli/commands/usage/services/llm-usage-command.service.ts
|
|
3
|
+
var LlmUsageCommandService = class {
|
|
4
|
+
constructor(deps = {}) {
|
|
5
|
+
this.deps = deps;
|
|
6
|
+
}
|
|
7
|
+
show = async (opts = {}) => {
|
|
8
|
+
if (opts.history && opts.stats) {
|
|
9
|
+
console.error("Choose only one usage mode: `--history` or `--stats`.");
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (opts.history) {
|
|
14
|
+
this.showHistory(opts);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (opts.stats) {
|
|
18
|
+
this.showStats(opts);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.showSnapshot(opts);
|
|
22
|
+
};
|
|
23
|
+
get queryService() {
|
|
24
|
+
return this.deps.queryService ?? llmUsageQueryService;
|
|
25
|
+
}
|
|
26
|
+
showSnapshot = (opts) => {
|
|
27
|
+
const snapshot = this.queryService.getSnapshot();
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
console.log(JSON.stringify({
|
|
30
|
+
ok: Boolean(snapshot),
|
|
31
|
+
mode: "snapshot",
|
|
32
|
+
path: this.queryService.snapshotPath,
|
|
33
|
+
snapshot
|
|
34
|
+
}, null, 2));
|
|
35
|
+
process.exitCode = 0;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!snapshot) {
|
|
39
|
+
console.log([
|
|
40
|
+
"No LLM usage snapshot recorded yet.",
|
|
41
|
+
`Snapshot path: ${this.queryService.snapshotPath}`,
|
|
42
|
+
"Run `nextclaw agent -m \"ping\"` or use the local UI once, then retry `nextclaw usage`."
|
|
43
|
+
].join("\n"));
|
|
44
|
+
process.exitCode = 0;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.log(this.renderSnapshot(snapshot));
|
|
48
|
+
process.exitCode = 0;
|
|
49
|
+
};
|
|
50
|
+
showHistory = (opts) => {
|
|
51
|
+
const records = this.queryService.getHistory(opts.limit);
|
|
52
|
+
if (opts.json) {
|
|
53
|
+
console.log(JSON.stringify({
|
|
54
|
+
ok: records.length > 0,
|
|
55
|
+
mode: "history",
|
|
56
|
+
path: this.queryService.historyPath,
|
|
57
|
+
limit: this.resolveLimit(opts.limit),
|
|
58
|
+
records
|
|
59
|
+
}, null, 2));
|
|
60
|
+
process.exitCode = 0;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (records.length === 0) {
|
|
64
|
+
console.log([
|
|
65
|
+
"No LLM usage history recorded yet.",
|
|
66
|
+
`History path: ${this.queryService.historyPath}`,
|
|
67
|
+
"Run `nextclaw agent -m \"ping\"` or use the local UI once, then retry `nextclaw usage --history`."
|
|
68
|
+
].join("\n"));
|
|
69
|
+
process.exitCode = 0;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
console.log(this.renderHistory(records));
|
|
73
|
+
process.exitCode = 0;
|
|
74
|
+
};
|
|
75
|
+
showStats = (opts) => {
|
|
76
|
+
const stats = this.queryService.getStats();
|
|
77
|
+
if (opts.json) {
|
|
78
|
+
console.log(JSON.stringify({
|
|
79
|
+
ok: stats.totalRecords > 0,
|
|
80
|
+
mode: "stats",
|
|
81
|
+
path: this.queryService.historyPath,
|
|
82
|
+
stats
|
|
83
|
+
}, null, 2));
|
|
84
|
+
process.exitCode = 0;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (stats.totalRecords === 0) {
|
|
88
|
+
console.log([
|
|
89
|
+
"No LLM usage history recorded yet.",
|
|
90
|
+
`History path: ${this.queryService.historyPath}`,
|
|
91
|
+
"Run `nextclaw agent -m \"ping\"` or use the local UI once, then retry `nextclaw usage --stats`."
|
|
92
|
+
].join("\n"));
|
|
93
|
+
process.exitCode = 0;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.log(this.renderStats(stats));
|
|
97
|
+
process.exitCode = 0;
|
|
98
|
+
};
|
|
99
|
+
renderSnapshot = (snapshot) => {
|
|
100
|
+
const lines = [
|
|
101
|
+
"Latest LLM usage snapshot",
|
|
102
|
+
`Observed at: ${snapshot.observedAt}`,
|
|
103
|
+
`Source: ${snapshot.source}`,
|
|
104
|
+
`Model: ${snapshot.model ?? "unknown"}`,
|
|
105
|
+
`Prompt tokens: ${snapshot.summary.promptTokens}`,
|
|
106
|
+
`Completion tokens: ${snapshot.summary.completionTokens}`,
|
|
107
|
+
`Total tokens: ${snapshot.summary.totalTokens}`,
|
|
108
|
+
`Cached tokens: ${snapshot.summary.cachedTokens}`,
|
|
109
|
+
`Cache hit: ${snapshot.summary.cacheHit ? "yes" : "no"}`,
|
|
110
|
+
`Snapshot path: ${this.queryService.snapshotPath}`
|
|
111
|
+
];
|
|
112
|
+
if (snapshot.summary.cacheMetricKeys.length > 0) lines.push(`Cache metric keys: ${snapshot.summary.cacheMetricKeys.join(", ")}`);
|
|
113
|
+
if (Object.keys(snapshot.usage).length > 0) lines.push("", "Raw usage:", JSON.stringify(snapshot.usage, null, 2));
|
|
114
|
+
return lines.join("\n");
|
|
115
|
+
};
|
|
116
|
+
renderHistory = (records) => {
|
|
117
|
+
const lines = [
|
|
118
|
+
"Recent LLM usage history",
|
|
119
|
+
`History path: ${this.queryService.historyPath}`,
|
|
120
|
+
`Showing: ${records.length} record(s)`,
|
|
121
|
+
""
|
|
122
|
+
];
|
|
123
|
+
for (const [index, record] of records.entries()) lines.push(`${index + 1}. ${record.observedAt} | source=${record.source} | model=${record.model ?? "unknown"} | total=${record.summary.totalTokens} | cached=${record.summary.cachedTokens} | cache-hit=${record.summary.cacheHit ? "yes" : "no"}`);
|
|
124
|
+
return lines.join("\n");
|
|
125
|
+
};
|
|
126
|
+
renderStats = (stats) => {
|
|
127
|
+
const lines = [
|
|
128
|
+
"LLM usage history stats",
|
|
129
|
+
`History path: ${this.queryService.historyPath}`,
|
|
130
|
+
`Records: ${stats.totalRecords}`,
|
|
131
|
+
`Usage records: ${stats.usageRecordCount}`,
|
|
132
|
+
`Empty usage records: ${stats.emptyUsageRecordCount}`,
|
|
133
|
+
`Prompt-bearing records: ${stats.promptTokenRecordCount}`,
|
|
134
|
+
`Oldest observed at: ${stats.oldestObservedAt ?? "n/a"}`,
|
|
135
|
+
`Latest observed at: ${stats.latestObservedAt ?? "n/a"}`,
|
|
136
|
+
`Prompt tokens: ${stats.totalPromptTokens}`,
|
|
137
|
+
`Completion tokens: ${stats.totalCompletionTokens}`,
|
|
138
|
+
`Total tokens: ${stats.totalTokens}`,
|
|
139
|
+
`Cached tokens: ${stats.totalCachedTokens}`,
|
|
140
|
+
`Cache hit records: ${stats.cacheHitRecords}/${stats.promptTokenRecordCount} (${this.toPercent(stats.cacheHitRate)})`,
|
|
141
|
+
`Cache token rate: ${this.toPercent(stats.tokenCacheRate)}`
|
|
142
|
+
];
|
|
143
|
+
if (stats.sources.length > 0) lines.push(`Sources: ${stats.sources.map((item) => `${item.value}=${item.count}`).join(", ")}`);
|
|
144
|
+
if (stats.models.length > 0) lines.push(`Models: ${stats.models.map((item) => `${item.value}=${item.count}`).join(", ")}`);
|
|
145
|
+
return lines.join("\n");
|
|
146
|
+
};
|
|
147
|
+
resolveLimit = (value) => {
|
|
148
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
|
|
149
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
150
|
+
const parsed = Number(value);
|
|
151
|
+
if (Number.isFinite(parsed) && parsed > 0) return Math.floor(parsed);
|
|
152
|
+
}
|
|
153
|
+
return 10;
|
|
154
|
+
};
|
|
155
|
+
toPercent = (value) => {
|
|
156
|
+
return `${(value * 100).toFixed(1)}%`;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
//#endregion
|
|
160
|
+
export { LlmUsageCommandService };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LlmUsageRecord, LlmUsageStore } from "@nextclaw/kernel";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/commands/usage/services/llm-usage-query.service.d.ts
|
|
4
|
+
type LlmUsageStats = {
|
|
5
|
+
totalRecords: number;
|
|
6
|
+
usageRecordCount: number;
|
|
7
|
+
emptyUsageRecordCount: number;
|
|
8
|
+
promptTokenRecordCount: number;
|
|
9
|
+
oldestObservedAt: string | null;
|
|
10
|
+
latestObservedAt: string | null;
|
|
11
|
+
totalPromptTokens: number;
|
|
12
|
+
totalCompletionTokens: number;
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
totalCachedTokens: number;
|
|
15
|
+
cacheHitRecords: number;
|
|
16
|
+
cacheHitRate: number;
|
|
17
|
+
tokenCacheRate: number;
|
|
18
|
+
sources: Array<{
|
|
19
|
+
value: string;
|
|
20
|
+
count: number;
|
|
21
|
+
}>;
|
|
22
|
+
models: Array<{
|
|
23
|
+
value: string;
|
|
24
|
+
count: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
declare class LlmUsageQueryService {
|
|
28
|
+
private readonly store;
|
|
29
|
+
constructor(deps?: {
|
|
30
|
+
store?: LlmUsageStore;
|
|
31
|
+
});
|
|
32
|
+
get snapshotPath(): string;
|
|
33
|
+
get historyPath(): string;
|
|
34
|
+
readonly getSnapshot: () => LlmUsageRecord | null;
|
|
35
|
+
readonly getHistory: (limit?: string | number) => LlmUsageRecord[];
|
|
36
|
+
readonly getStats: () => LlmUsageStats;
|
|
37
|
+
private readonly resolveLimit;
|
|
38
|
+
private readonly bumpCounter;
|
|
39
|
+
private readonly toSortedCounts;
|
|
40
|
+
}
|
|
41
|
+
declare const llmUsageQueryService: LlmUsageQueryService;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { LlmUsageQueryService, LlmUsageStats, llmUsageQueryService };
|