beautx-cli 1.0.6 → 1.0.7-beta.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/README.md +44 -15
- package/dist/{analyze-0SATHpUC.mjs → analyze-CcsdZtz9.mjs} +5 -5
- package/dist/{api-D3JyDoiw.mjs → api-B5nQypBz.mjs} +2 -2
- package/dist/{audio-BfNibfXF.mjs → audio-DVH0I5Zh.mjs} +3 -3
- package/dist/{beauty-plan-DQl_OJNK.mjs → beauty-plan-Cd88u5h0.mjs} +4 -4
- package/dist/cli.mjs +7651 -19
- package/dist/config-BOuRZAk1.mjs +15 -0
- package/dist/{consultant-DbYBzHqQ.mjs → consultant-C1uiuItn.mjs} +1 -1
- package/dist/{content-BTHG2DCs.mjs → content-CpFANyPe.mjs} +3 -3
- package/dist/{current-BDH1xER9.mjs → current--kwV_-9S.mjs} +3 -3
- package/dist/{customer-D04eXm64.mjs → customer-Chl1bGg9.mjs} +1 -1
- package/dist/{deal-analysis-Dpg9VGjK.mjs → deal-analysis-Bf6TwBmH.mjs} +4 -4
- package/dist/{doc-CWgdZ_Eh.mjs → doc-BtwmuoPs.mjs} +3 -3
- package/dist/doctor-DuGxP40X.mjs +37 -0
- package/dist/{env-vars-CXEHR_mk.mjs → env-vars-Dinhf5lt.mjs} +21 -40
- package/dist/{fields-D-iEk93w.mjs → fields-MsjROq8O.mjs} +4 -4
- package/dist/{focus-BMcnVGqT.mjs → focus-CM6mZYRj.mjs} +1 -1
- package/dist/{get-BLdqZ3XJ.mjs → get-Z_hTyubv.mjs} +3 -3
- package/dist/install-DP9xV1rY.mjs +50 -0
- package/dist/{kb-BPy6E_uX.mjs → kb-CjQXEOY5.mjs} +2 -2
- package/dist/{list-C73pWNBd.mjs → list-B84PLHzp.mjs} +2 -2
- package/dist/list-BNZV4wei.mjs +77 -0
- package/dist/{list-DyePBi8K.mjs → list-BSR3H7_0.mjs} +4 -4
- package/dist/{list-DqXRvhfS.mjs → list-BT0_KdNZ.mjs} +5 -5
- package/dist/{list-BMbWa85R.mjs → list-C0wn72hg.mjs} +4 -4
- package/dist/{list-DIvD8BvI.mjs → list-C6imhAfi.mjs} +4 -4
- package/dist/{list-Ck_kx-iC.mjs → list-CDi3ySyx.mjs} +5 -5
- package/dist/{list-JL2fmylz.mjs → list-CGJa9z3d.mjs} +4 -4
- package/dist/{list-CB7YZTB4.mjs → list-CJiei-hu.mjs} +4 -4
- package/dist/list-D809kN14.mjs +85 -0
- package/dist/{mcp-args-CYOCdClW.mjs → mcp-args-B8InvGQc.mjs} +1 -1
- package/dist/{mcp-client-OuKd8iir.mjs → mcp-client-aS31KU6J.mjs} +37 -76
- package/dist/{mcp-result-B5HHO7ap.mjs → mcp-result-Bl71pkOt.mjs} +2 -2
- package/dist/{portrait-tags-DRQi5JcR.mjs → portrait-tags-BYded-6k.mjs} +4 -4
- package/dist/{project-CEmZCvSp.mjs → project-DSO_7ofq.mjs} +3 -3
- package/dist/project-access-Cq8d1YTo.mjs +2 -0
- package/dist/{project-access-O-VSqqVC.mjs → project-access-DlypxnQF.mjs} +21 -30
- package/dist/project-store-CYuTFefu.mjs +2 -0
- package/dist/project-store-D0UuLan2.mjs +219 -0
- package/dist/{qa-B7WbwUts.mjs → qa-CqUiXIZn.mjs} +5 -5
- package/dist/{resistance-FtBtoEDl.mjs → resistance-DiDDixVq.mjs} +1 -1
- package/dist/{search-BuMtyCiU.mjs → search-sjRwA-la.mjs} +5 -5
- package/dist/skill-DBpgezPV.mjs +15 -0
- package/dist/skill-client-D4_QGDkj.mjs +171 -0
- package/dist/{summary-Cg79V9oz.mjs → summary-C7lrTImW.mjs} +4 -4
- package/dist/{text-CGOU6uh9.mjs → text-BZo7B8mz.mjs} +5 -5
- package/dist/upload-D4wSmRqs.mjs +76 -0
- package/dist/{use-Bzhvb9I3.mjs → use-DQ_M0FOH.mjs} +8 -6
- package/dist/{visit-vaoFdiLr.mjs → visit-CxAYV6z6.mjs} +2 -2
- package/dist/{visit-evaluate-BQIyxZeM.mjs → visit-evaluate-BTKqc8fd.mjs} +4 -4
- package/dist/{visit-query-args-CDDQ9JJ8.mjs → visit-query-args-BLwj26s6.mjs} +2 -2
- package/package.json +1 -1
- package/dist/config-C8aqUXV7.mjs +0 -14
- package/dist/env-callback-CIXEvt0i.mjs +0 -349
- package/dist/format-9T59sVxH.mjs +0 -7253
- package/dist/list-FCCClcl-.mjs +0 -64
- package/dist/project-store-DHqT0-nk.mjs +0 -55
|
@@ -1,65 +1,7 @@
|
|
|
1
1
|
import { n as __exportAll } from "./rolldown-runtime-YLnNgb9a.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { i as debugLogInfo, n as persistTokensToHost, r as debugLogError } from "./env-callback-CIXEvt0i.mjs";
|
|
2
|
+
import { c as readEnv, g as MissingGatewayError, h as MissingAccessTokenError, n as assertEndpointsValid, t as ENV_KEYS, u as resolveEndpoints } from "./env-vars-Dinhf5lt.mjs";
|
|
3
|
+
import { a as debugLogInfo, i as debugLogError, l as ensureAuth } from "./cli.mjs";
|
|
5
4
|
import { randomUUID } from "node:crypto";
|
|
6
|
-
//#region src/core/token-refresh.ts
|
|
7
|
-
/**
|
|
8
|
-
* Silent OAuth refresh_token grant — used by ensureAuth, not exposed as a command.
|
|
9
|
-
*/
|
|
10
|
-
async function refreshAccessToken(authUrl, refreshToken) {
|
|
11
|
-
const base = authUrl.replace(/\/$/, "");
|
|
12
|
-
const body = new URLSearchParams({
|
|
13
|
-
grant_type: "refresh_token",
|
|
14
|
-
refresh_token: refreshToken
|
|
15
|
-
});
|
|
16
|
-
const clientId = process.env.MCP_CLIENT_ID?.trim();
|
|
17
|
-
if (clientId) body.set("client_id", clientId);
|
|
18
|
-
const resp = await fetch(`${base}/oauth/token`, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
21
|
-
body: body.toString(),
|
|
22
|
-
signal: AbortSignal.timeout(3e4)
|
|
23
|
-
});
|
|
24
|
-
const parsed = await resp.json().catch(() => ({}));
|
|
25
|
-
if (!resp.ok) {
|
|
26
|
-
const msg = parsed.error_description ?? parsed.error ?? resp.statusText;
|
|
27
|
-
throw new RefreshFailedError(String(msg));
|
|
28
|
-
}
|
|
29
|
-
const access = parsed.access_token;
|
|
30
|
-
if (typeof access !== "string" || !access) throw new RefreshFailedError("响应缺少 access_token");
|
|
31
|
-
return {
|
|
32
|
-
access_token: access,
|
|
33
|
-
refresh_token: typeof parsed.refresh_token === "string" ? parsed.refresh_token : void 0,
|
|
34
|
-
expires_in: typeof parsed.expires_in === "number" ? parsed.expires_in : void 0,
|
|
35
|
-
scope: typeof parsed.scope === "string" ? parsed.scope : void 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/core/ensure-auth.ts
|
|
40
|
-
/**
|
|
41
|
-
* Pre-MCP auth guard — refresh tokens via Host callback when expiring soon.
|
|
42
|
-
*/
|
|
43
|
-
/**
|
|
44
|
-
* Ensure MCP_TOKEN is valid before an MCP call.
|
|
45
|
-
* Refreshes via OAuth + Host env callback when within REFRESH_BUFFER_MS of expiry.
|
|
46
|
-
*/
|
|
47
|
-
async function ensureAuth(opts = {}) {
|
|
48
|
-
const endpoints = resolveEndpoints();
|
|
49
|
-
const creds = readCredentials();
|
|
50
|
-
if (!(opts.force === true) && creds.accessToken && !isTokenExpired(creds.expiresAt) && !needsRefresh(creds.expiresAt)) return;
|
|
51
|
-
if (!creds.refreshToken) {
|
|
52
|
-
if (!creds.accessToken) throw new MissingAccessTokenError();
|
|
53
|
-
if (isTokenExpired(creds.expiresAt)) throw new AccessTokenExpiredError();
|
|
54
|
-
throw new MissingRefreshTokenError();
|
|
55
|
-
}
|
|
56
|
-
if (!endpoints.authUrl?.trim()) throw new RefreshFailedError("缺少 auth_url");
|
|
57
|
-
const tokens = await refreshAccessToken(endpoints.authUrl, creds.refreshToken);
|
|
58
|
-
const expiresAtMs = tokens.expires_in != null ? Date.now() + tokens.expires_in * 1e3 : Date.now() + 9e5;
|
|
59
|
-
await persistTokensToHost(tokens.access_token, tokens.refresh_token ?? creds.refreshToken, expiresAtMs);
|
|
60
|
-
invalidateProjectAccessCache();
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
5
|
//#region src/core/config.ts
|
|
64
6
|
/**
|
|
65
7
|
* MCP gateway configuration — env-only resolution.
|
|
@@ -82,16 +24,21 @@ async function resolveMcpConfig() {
|
|
|
82
24
|
/**
|
|
83
25
|
* Normalize MCP tools/call arguments before they hit the gateway wire.
|
|
84
26
|
*
|
|
85
|
-
* - project-list: always attach
|
|
27
|
+
* - {@code project-list}: always attach default {@code project_id} (gateway billing),
|
|
86
28
|
* ignoring any CLI-supplied value.
|
|
87
|
-
* -
|
|
88
|
-
* audit / billing
|
|
29
|
+
* - All other tools: attach {@code project_id} from default when callers omit it
|
|
30
|
+
* (audit / billing on gateway even when application ignores the field).
|
|
31
|
+
*
|
|
32
|
+
* {@code defaultProjectId} comes from QCA `/out/v2/current-project` (not process.env).
|
|
89
33
|
*/
|
|
90
|
-
function augmentMcpWireArguments(toolName, args) {
|
|
91
|
-
const estateId =
|
|
34
|
+
function augmentMcpWireArguments(toolName, args, defaultProjectId) {
|
|
35
|
+
const estateId = defaultProjectId?.trim() || "";
|
|
92
36
|
if (toolName === "project-list") {
|
|
37
|
+
if (!estateId) {
|
|
38
|
+
const { project_id: _drop, ...rest } = args;
|
|
39
|
+
return rest;
|
|
40
|
+
}
|
|
93
41
|
const { project_id: _drop, ...rest } = args;
|
|
94
|
-
if (!estateId) return rest;
|
|
95
42
|
return {
|
|
96
43
|
...rest,
|
|
97
44
|
project_id: estateId
|
|
@@ -117,6 +64,7 @@ var mcp_client_exports = /* @__PURE__ */ __exportAll({
|
|
|
117
64
|
MCP_CALL_SOURCE: () => MCP_CALL_SOURCE,
|
|
118
65
|
MCP_SERVICE_CODE: () => MCP_SERVICE_CODE,
|
|
119
66
|
McpGatewayError: () => McpGatewayError,
|
|
67
|
+
buildMcpHttpHeaders: () => buildMcpHttpHeaders,
|
|
120
68
|
mcpCall: () => mcpCall,
|
|
121
69
|
unwrapMcpToolEnvelope: () => unwrapMcpToolEnvelope
|
|
122
70
|
});
|
|
@@ -150,9 +98,9 @@ function unwrapMcpToolEnvelope(mcpResult) {
|
|
|
150
98
|
return {};
|
|
151
99
|
}
|
|
152
100
|
const ERROR_HINTS = {
|
|
153
|
-
TOKEN_MISSING: "
|
|
154
|
-
TOKEN_INVALID: "
|
|
155
|
-
TOKEN_EXPIRED: "
|
|
101
|
+
TOKEN_MISSING: "向 /out/v2/mcp-token 借 AT:确认 SANDBOX_*_SECRET 已注入且 PC/App 已完成 MCP 凭证初始化",
|
|
102
|
+
TOKEN_INVALID: "重新调用 CLI 向 Token Broker 借新 AT",
|
|
103
|
+
TOKEN_EXPIRED: "重新调用 CLI 向 Token Broker 借新 AT",
|
|
156
104
|
TOKEN_AUD_MISMATCH: "确认 token 为 MCP 网关签发且 scope 含 mcp:invoke",
|
|
157
105
|
POLICY_DENIED: "无权访问该服务,请联系管理员确认 serviceCode 权限",
|
|
158
106
|
SERVICE_NOT_FOUND: "serviceCode 不存在,请确认网关侧已注册",
|
|
@@ -171,12 +119,29 @@ var McpGatewayError = class extends Error {
|
|
|
171
119
|
this.hint = ERROR_HINTS[code] ?? `MCP 网关错误: ${code}`;
|
|
172
120
|
}
|
|
173
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Bearer token header stays live; the sandbox {@code SESSION_ID} (when present)
|
|
124
|
+
* is attached as {@code X-MCP-Session-Id} so the MCP gateway can correlate the
|
|
125
|
+
* originating session. Absent {@code SESSION_ID} → header omitted.
|
|
126
|
+
*/
|
|
127
|
+
function buildMcpHttpHeaders(token) {
|
|
128
|
+
const headers = {
|
|
129
|
+
Accept: "application/json, text/event-stream",
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
Authorization: `Bearer ${token}`
|
|
132
|
+
};
|
|
133
|
+
const sessionId = readEnv(ENV_KEYS.SESSION_ID)?.trim();
|
|
134
|
+
if (sessionId) headers["X-MCP-Session-Id"] = sessionId;
|
|
135
|
+
return headers;
|
|
136
|
+
}
|
|
174
137
|
async function mcpCall(toolName, opts) {
|
|
175
|
-
const
|
|
138
|
+
const { loadActiveProject } = await import("./project-store-CYuTFefu.mjs");
|
|
139
|
+
const active = await loadActiveProject();
|
|
140
|
+
const wireArguments = augmentMcpWireArguments(toolName, opts.arguments ?? {}, active?.projectId);
|
|
176
141
|
if (toolName !== "project-list") {
|
|
177
142
|
const rawProjectId = wireArguments.project_id;
|
|
178
143
|
if (rawProjectId != null && String(rawProjectId).trim()) {
|
|
179
|
-
const { assertProjectAllowed } = await import("./project-access-
|
|
144
|
+
const { assertProjectAllowed } = await import("./project-access-Cq8d1YTo.mjs");
|
|
180
145
|
await assertProjectAllowed(String(rawProjectId).trim());
|
|
181
146
|
}
|
|
182
147
|
}
|
|
@@ -204,11 +169,7 @@ async function mcpCallOnce(toolName, opts, retriedAfterRefresh) {
|
|
|
204
169
|
});
|
|
205
170
|
const resp = await fetch(url, {
|
|
206
171
|
method: "POST",
|
|
207
|
-
headers:
|
|
208
|
-
Accept: "application/json, text/event-stream",
|
|
209
|
-
"Content-Type": "application/json",
|
|
210
|
-
Authorization: `Bearer ${config.token}`
|
|
211
|
-
},
|
|
172
|
+
headers: buildMcpHttpHeaders(config.token),
|
|
212
173
|
body,
|
|
213
174
|
signal: AbortSignal.timeout(opts.timeoutMs ?? 3e4)
|
|
214
175
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as writeError, r as writeResult } from "./cli.mjs";
|
|
2
|
+
import { i as unwrapMcpToolEnvelope, n as mcpCall } from "./mcp-client-aS31KU6J.mjs";
|
|
3
3
|
//#region src/core/mcp-result.ts
|
|
4
4
|
/**
|
|
5
5
|
* Normalize MCP tool responses for agent-friendly stdout (TOON tabular arrays).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as visitBatchQueryCliArgs, t as buildVisitBatchQueryArgs } from "./visit-query-args-
|
|
1
|
+
import { c as requireActiveProject } from "./project-store-D0UuLan2.mjs";
|
|
2
|
+
import { n as writeError } from "./cli.mjs";
|
|
3
|
+
import { t as mcpCallPage } from "./mcp-result-Bl71pkOt.mjs";
|
|
4
|
+
import { n as visitBatchQueryCliArgs, t as buildVisitBatchQueryArgs } from "./visit-query-args-BLwj26s6.mjs";
|
|
5
5
|
import { defineCommand } from "citty";
|
|
6
6
|
//#region src/commands/portrait-tags/index.ts
|
|
7
7
|
/**
|
|
@@ -6,9 +6,9 @@ var project_default = defineCommand({
|
|
|
6
6
|
description: "查询 / 切换激活项目"
|
|
7
7
|
},
|
|
8
8
|
subCommands: {
|
|
9
|
-
list: () => import("./list-
|
|
10
|
-
use: () => import("./use-
|
|
11
|
-
current: () => import("./current-
|
|
9
|
+
list: () => import("./list-B84PLHzp.mjs").then((m) => m.default),
|
|
10
|
+
use: () => import("./use-DQ_M0FOH.mjs").then((m) => m.default),
|
|
11
|
+
current: () => import("./current--kwV_-9S.mjs").then((m) => m.default)
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as readEnv, l as requireUserId, p as ConfigInvalidError, t as ENV_KEYS, u as resolveEndpoints } from "./env-vars-Dinhf5lt.mjs";
|
|
2
|
+
import { o as loadActiveProject, s as peekCachedActiveProject } from "./project-store-D0UuLan2.mjs";
|
|
3
3
|
var InsufficientCreditError = class extends Error {
|
|
4
4
|
code = "INSUFFICIENT_CREDIT";
|
|
5
5
|
hint = "(该项目下)用户积分余额不足,无法继续查询;请告知用户联系管理员充值";
|
|
@@ -41,7 +41,7 @@ async function assertCreditRemaining(projectId) {
|
|
|
41
41
|
}
|
|
42
42
|
async function fetchCreditRemaining(userId, projectId) {
|
|
43
43
|
const { callbackBaseUrl } = resolveEndpoints();
|
|
44
|
-
const url = new URL(`/api/
|
|
44
|
+
const url = new URL(`/api/qca-wangclaw/out/v2/credit/users/${encodeURIComponent(userId)}/remaining`, callbackBaseUrl);
|
|
45
45
|
url.searchParams.set("projectId", projectId);
|
|
46
46
|
let resp;
|
|
47
47
|
try {
|
|
@@ -82,13 +82,6 @@ function extractEnvelopeMessage(body) {
|
|
|
82
82
|
* Allowed estate (project) guard for CLI — validates project_id against
|
|
83
83
|
* {@code project-list} before MCP calls (in-process TTL cache).
|
|
84
84
|
*/
|
|
85
|
-
var project_access_exports = /* @__PURE__ */ __exportAll({
|
|
86
|
-
PROJECT_ACCESS_TTL_MS: () => PROJECT_ACCESS_TTL_MS,
|
|
87
|
-
ProjectNotAllowedError: () => ProjectNotAllowedError,
|
|
88
|
-
assertProjectAllowed: () => assertProjectAllowed,
|
|
89
|
-
invalidateProjectAccessCache: () => invalidateProjectAccessCache,
|
|
90
|
-
resolveProjectForUse: () => resolveProjectForUse
|
|
91
|
-
});
|
|
92
85
|
const PROJECT_ACCESS_TTL_MS = 300 * 1e3;
|
|
93
86
|
const PROJECT_LIST_PAGE_SIZE = 100;
|
|
94
87
|
let cache = null;
|
|
@@ -108,7 +101,7 @@ function invalidateProjectAccessCache() {
|
|
|
108
101
|
function resolveCacheTenantId() {
|
|
109
102
|
const fromEnv = readEnv(ENV_KEYS.TENANT_ID);
|
|
110
103
|
if (fromEnv) return fromEnv;
|
|
111
|
-
return
|
|
104
|
+
return peekCachedActiveProject()?.tenantId?.trim() ?? "";
|
|
112
105
|
}
|
|
113
106
|
function cacheIsValid(state, tenantId) {
|
|
114
107
|
return state.tenantId === tenantId && Date.now() - state.fetchedAt < 3e5;
|
|
@@ -139,9 +132,9 @@ function finalizeResolvedProject(partial) {
|
|
|
139
132
|
projectName: partial.projectName?.trim() ?? ""
|
|
140
133
|
};
|
|
141
134
|
}
|
|
142
|
-
function
|
|
143
|
-
const
|
|
144
|
-
return Boolean(
|
|
135
|
+
function isCachedActiveEstate(projectId) {
|
|
136
|
+
const active = peekCachedActiveProject();
|
|
137
|
+
return Boolean(active?.projectId && active.projectId === projectId);
|
|
145
138
|
}
|
|
146
139
|
/**
|
|
147
140
|
* Ensure {@code projectId} is in the gateway project-list roster.
|
|
@@ -150,7 +143,7 @@ function isHostActiveEstate(projectId) {
|
|
|
150
143
|
async function assertProjectAllowed(projectId) {
|
|
151
144
|
const id = projectId?.trim();
|
|
152
145
|
if (!id) return;
|
|
153
|
-
if (!
|
|
146
|
+
if (!isCachedActiveEstate(id)) {
|
|
154
147
|
const tenantId = resolveCacheTenantId();
|
|
155
148
|
if (cache && cacheIsValid(cache, tenantId)) {
|
|
156
149
|
if (!cache.allowedEstateIds.has(id)) {
|
|
@@ -163,22 +156,20 @@ async function assertProjectAllowed(projectId) {
|
|
|
163
156
|
}
|
|
164
157
|
/**
|
|
165
158
|
* Resolve tenant/project metadata for {@code project use} from project-list.
|
|
166
|
-
* Names are display-only
|
|
159
|
+
* Names are display-only; IDs come from the roster row.
|
|
167
160
|
*/
|
|
168
161
|
async function resolveProjectForUse(projectId) {
|
|
169
162
|
const id = projectId?.trim();
|
|
170
163
|
if (!id) throw new ConfigInvalidError("缺少 project_id", "运行 `beautx-cli project list` 选择项目");
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
}
|
|
164
|
+
const active = await loadActiveProject();
|
|
165
|
+
if (active?.projectId === id) {
|
|
166
|
+
await assertCreditRemaining(id);
|
|
167
|
+
return finalizeResolvedProject({
|
|
168
|
+
tenantId: active.tenantId,
|
|
169
|
+
tenantName: active.tenantName,
|
|
170
|
+
projectId: id,
|
|
171
|
+
projectName: active.projectName
|
|
172
|
+
});
|
|
182
173
|
}
|
|
183
174
|
const row = await lookupProjectRow(id);
|
|
184
175
|
await assertCreditRemaining(id);
|
|
@@ -237,14 +228,14 @@ function normalizeProjectListPage(page) {
|
|
|
237
228
|
};
|
|
238
229
|
}
|
|
239
230
|
async function fetchProjectListPage(page, size) {
|
|
240
|
-
const { mcpCall, unwrapMcpToolEnvelope } = await import("./mcp-client-
|
|
231
|
+
const { mcpCall, unwrapMcpToolEnvelope } = await import("./mcp-client-aS31KU6J.mjs").then((n) => n.r);
|
|
241
232
|
const result = await mcpCall("project-list", { arguments: {
|
|
242
233
|
page,
|
|
243
234
|
size
|
|
244
235
|
} });
|
|
245
236
|
if (!result.ok) {
|
|
246
237
|
const detail = extractMcpFailureDetail(result.data);
|
|
247
|
-
throw new ConfigInvalidError(detail ? `无法拉取项目列表以校验 project_id: ${detail}` : "无法拉取项目列表以校验 project_id", "检查 MCP 网关与 token
|
|
238
|
+
throw new ConfigInvalidError(detail ? `无法拉取项目列表以校验 project_id: ${detail}` : "无法拉取项目列表以校验 project_id", "检查 MCP 网关与 token 是否正常;大租户可先由平台预置当前项目");
|
|
248
239
|
}
|
|
249
240
|
const envelope = unwrapMcpToolEnvelope(result.data);
|
|
250
241
|
const code = envelope.code;
|
|
@@ -271,4 +262,4 @@ function extractMcpFailureDetail(data) {
|
|
|
271
262
|
}
|
|
272
263
|
}
|
|
273
264
|
//#endregion
|
|
274
|
-
export {
|
|
265
|
+
export { resolveProjectForUse as a, invalidateProjectAccessCache as i, ProjectNotAllowedError as n, assertProjectAllowed as r, PROJECT_ACCESS_TTL_MS as t };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { c as readEnv, l as requireUserId, m as CurrentProjectFailedError, t as ENV_KEYS, u as resolveEndpoints } from "./env-vars-Dinhf5lt.mjs";
|
|
2
|
+
function requireTenantId() {
|
|
3
|
+
const tenantId = readEnv(ENV_KEYS.TENANT_ID);
|
|
4
|
+
if (!tenantId) throw new CurrentProjectFailedError("缺少 TENANT_ID 环境变量", { hint: "由 QCA 在沙箱启动时注入 TENANT_ID" });
|
|
5
|
+
return tenantId;
|
|
6
|
+
}
|
|
7
|
+
async function getCurrentProject(tenantId, wangId) {
|
|
8
|
+
return fetchCurrentProject((tenantId ?? requireTenantId()).trim(), (wangId ?? requireUserId()).trim());
|
|
9
|
+
}
|
|
10
|
+
async function setCurrentProject(input) {
|
|
11
|
+
const tid = (input.tenantId ?? requireTenantId()).trim();
|
|
12
|
+
const wid = (input.wangId ?? requireUserId()).trim();
|
|
13
|
+
const projectId = input.projectId?.trim();
|
|
14
|
+
if (!projectId) throw new CurrentProjectFailedError("projectId 不能为空");
|
|
15
|
+
return putCurrentProject(tid, wid, projectId, input.source?.trim() || "cli_project_use");
|
|
16
|
+
}
|
|
17
|
+
async function fetchCurrentProject(tenantId, wangId) {
|
|
18
|
+
const { callbackBaseUrl } = resolveEndpoints();
|
|
19
|
+
const url = new URL("/api/qca-wangclaw/out/v2/current-project", callbackBaseUrl);
|
|
20
|
+
url.searchParams.set("tenantId", tenantId);
|
|
21
|
+
url.searchParams.set("wangId", wangId);
|
|
22
|
+
let resp;
|
|
23
|
+
try {
|
|
24
|
+
resp = await fetch(url, {
|
|
25
|
+
method: "GET",
|
|
26
|
+
headers: { Accept: "application/json" },
|
|
27
|
+
signal: AbortSignal.timeout(1e4)
|
|
28
|
+
});
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw new CurrentProjectFailedError(`读取当前项目请求失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
}
|
|
32
|
+
if (resp.status === 404) return null;
|
|
33
|
+
const body = await readJsonBody(resp);
|
|
34
|
+
if (!resp.ok) throwCurrentProjectHttpError("读取当前项目失败", resp.status, body);
|
|
35
|
+
const data = unwrapData(body);
|
|
36
|
+
if (!data) return null;
|
|
37
|
+
return parseRecord(data, tenantId, wangId);
|
|
38
|
+
}
|
|
39
|
+
async function putCurrentProject(tenantId, wangId, projectId, source) {
|
|
40
|
+
const { callbackBaseUrl } = resolveEndpoints();
|
|
41
|
+
const url = new URL("/api/qca-wangclaw/out/v2/current-project", callbackBaseUrl);
|
|
42
|
+
let resp;
|
|
43
|
+
try {
|
|
44
|
+
resp = await fetch(url, {
|
|
45
|
+
method: "PUT",
|
|
46
|
+
headers: {
|
|
47
|
+
Accept: "application/json",
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
tenantId,
|
|
52
|
+
wangId,
|
|
53
|
+
projectId,
|
|
54
|
+
source
|
|
55
|
+
}),
|
|
56
|
+
signal: AbortSignal.timeout(1e4)
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw new CurrentProjectFailedError(`写入当前项目请求失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
|
+
}
|
|
61
|
+
const body = await readJsonBody(resp);
|
|
62
|
+
if (!resp.ok) throwCurrentProjectHttpError("写入当前项目失败", resp.status, body);
|
|
63
|
+
const data = unwrapData(body);
|
|
64
|
+
if (!data) throw new CurrentProjectFailedError("写入当前项目响应缺少 data");
|
|
65
|
+
return parseRecord(data, tenantId, wangId);
|
|
66
|
+
}
|
|
67
|
+
function unwrapData(body) {
|
|
68
|
+
if (!body || typeof body !== "object") return null;
|
|
69
|
+
const envelope = body;
|
|
70
|
+
if (String(envelope.code) === "404") return null;
|
|
71
|
+
if (envelope.code != null && String(envelope.code) !== "0") throw new CurrentProjectFailedError(envelope.msg ?? `当前项目业务错误: ${envelope.code}`, {
|
|
72
|
+
upstreamCode: String(envelope.code),
|
|
73
|
+
details: body
|
|
74
|
+
});
|
|
75
|
+
if (envelope.data == null) return null;
|
|
76
|
+
if (typeof envelope.data !== "object") return null;
|
|
77
|
+
return envelope.data;
|
|
78
|
+
}
|
|
79
|
+
function parseRecord(data, fallbackTenantId, fallbackWangId) {
|
|
80
|
+
const projectId = pickString(data, "projectId", "currentProjectId", "current_project_id");
|
|
81
|
+
if (!projectId) throw new CurrentProjectFailedError("当前项目响应缺少 projectId");
|
|
82
|
+
return {
|
|
83
|
+
tenantId: pickString(data, "tenantId", "tenant_id") || fallbackTenantId,
|
|
84
|
+
wangId: pickString(data, "wangId", "wang_id") || fallbackWangId,
|
|
85
|
+
projectId,
|
|
86
|
+
source: pickString(data, "source") || "",
|
|
87
|
+
createdAt: pickString(data, "createdAt", "created_at") || void 0,
|
|
88
|
+
updatedAt: pickString(data, "updatedAt", "updated_at") || void 0,
|
|
89
|
+
version: typeof data.version === "number" ? data.version : data.version != null ? Number(data.version) : void 0
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function pickString(obj, ...keys) {
|
|
93
|
+
for (const key of keys) {
|
|
94
|
+
const value = obj[key];
|
|
95
|
+
if (value != null && String(value).trim()) return String(value).trim();
|
|
96
|
+
}
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
async function readJsonBody(resp) {
|
|
100
|
+
try {
|
|
101
|
+
return await resp.json();
|
|
102
|
+
} catch {
|
|
103
|
+
throw new CurrentProjectFailedError(`当前项目接口返回非 JSON(HTTP ${resp.status})`, { status: resp.status });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function throwCurrentProjectHttpError(prefix, status, body) {
|
|
107
|
+
const msg = extractEnvelopeMessage(body) ?? "";
|
|
108
|
+
throw new CurrentProjectFailedError(msg ? `${prefix}(HTTP ${status}): ${msg}` : `${prefix}(HTTP ${status})`, {
|
|
109
|
+
status,
|
|
110
|
+
details: body
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function extractEnvelopeMessage(body) {
|
|
114
|
+
if (!body || typeof body !== "object") return void 0;
|
|
115
|
+
const msg = body.msg;
|
|
116
|
+
return typeof msg === "string" && msg.trim() ? msg.trim() : void 0;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/core/project-store.ts
|
|
120
|
+
/**
|
|
121
|
+
* Active project — QCA `/out/v2/current-project` is the only source of truth.
|
|
122
|
+
* Not written into process.env; agents inspect via `beautx-cli project current`.
|
|
123
|
+
*/
|
|
124
|
+
const CACHE_TTL_MS = 15e3;
|
|
125
|
+
let cache = null;
|
|
126
|
+
function invalidateActiveProjectCache() {
|
|
127
|
+
cache = null;
|
|
128
|
+
}
|
|
129
|
+
/** Warm-cache peek for guards (null if cold / expired). */
|
|
130
|
+
function peekCachedActiveProject() {
|
|
131
|
+
if (!cache) return null;
|
|
132
|
+
if (Date.now() - cache.fetchedAt >= CACHE_TTL_MS) return null;
|
|
133
|
+
return cache.project;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Load active project from QCA `/out/v2/current-project`.
|
|
137
|
+
* Returns null when no row exists (do not fall back to ESTATE_ID env).
|
|
138
|
+
*/
|
|
139
|
+
async function loadActiveProject() {
|
|
140
|
+
if (cache && Date.now() - cache.fetchedAt < CACHE_TTL_MS) return cache.project;
|
|
141
|
+
const remote = await getCurrentProject();
|
|
142
|
+
if (remote?.projectId) {
|
|
143
|
+
const project = toActiveProject(remote);
|
|
144
|
+
cache = {
|
|
145
|
+
project,
|
|
146
|
+
fetchedAt: Date.now()
|
|
147
|
+
};
|
|
148
|
+
return project;
|
|
149
|
+
}
|
|
150
|
+
cache = {
|
|
151
|
+
project: null,
|
|
152
|
+
fetchedAt: Date.now()
|
|
153
|
+
};
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
async function switchActiveProjectViaCallback(p) {
|
|
157
|
+
const tenantId = p.tenantId?.trim() || readEnv(ENV_KEYS.TENANT_ID);
|
|
158
|
+
await setCurrentProject({
|
|
159
|
+
tenantId,
|
|
160
|
+
projectId: p.projectId,
|
|
161
|
+
source: "cli_project_use"
|
|
162
|
+
});
|
|
163
|
+
const project = {
|
|
164
|
+
tenantId,
|
|
165
|
+
tenantName: p.tenantName ?? "",
|
|
166
|
+
projectId: p.projectId,
|
|
167
|
+
projectName: p.projectName ?? "",
|
|
168
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
169
|
+
source: "qca"
|
|
170
|
+
};
|
|
171
|
+
cache = {
|
|
172
|
+
project,
|
|
173
|
+
fetchedAt: Date.now()
|
|
174
|
+
};
|
|
175
|
+
return project;
|
|
176
|
+
}
|
|
177
|
+
var NoActiveProjectError = class extends Error {
|
|
178
|
+
code = "NO_ACTIVE_PROJECT";
|
|
179
|
+
hint = "先用 `beautx-cli project list [--keyword <kw>]` 查看可选项目,再用 `beautx-cli project use --project-id <id>` 激活;或由平台预置当前项目。查看当前项目:`beautx-cli project current`。";
|
|
180
|
+
constructor() {
|
|
181
|
+
super("当前未设置激活项目");
|
|
182
|
+
this.name = "NoActiveProjectError";
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
async function requireActiveProject() {
|
|
186
|
+
const p = await loadActiveProject();
|
|
187
|
+
if (!p?.projectId) throw new NoActiveProjectError();
|
|
188
|
+
return p;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Project switching is blocked only in the aike app (XB_APP_ID=aike).
|
|
192
|
+
*/
|
|
193
|
+
var ProjectSwitchNotAllowedError = class extends Error {
|
|
194
|
+
code = "PROJECT_SWITCH_NOT_ALLOWED";
|
|
195
|
+
hint = "当前应用(XB_APP_ID=aike)不允许通过 CLI 切换项目,请使用 UI 切换。";
|
|
196
|
+
constructor() {
|
|
197
|
+
super("无法切换项目:不允许在当前应用下切换");
|
|
198
|
+
this.name = "ProjectSwitchNotAllowedError";
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
function assertProjectSwitchAllowed() {
|
|
202
|
+
if (!isProjectSwitchAllowed()) throw new ProjectSwitchNotAllowedError();
|
|
203
|
+
}
|
|
204
|
+
/** Whether CLI may run `project use` (false only when XB_APP_ID=aike). */
|
|
205
|
+
function isProjectSwitchAllowed() {
|
|
206
|
+
return readEnv(ENV_KEYS.XB_APP_ID).toLowerCase() !== "aike";
|
|
207
|
+
}
|
|
208
|
+
function toActiveProject(remote) {
|
|
209
|
+
return {
|
|
210
|
+
tenantId: remote.tenantId || readEnv(ENV_KEYS.TENANT_ID),
|
|
211
|
+
tenantName: "",
|
|
212
|
+
projectId: remote.projectId,
|
|
213
|
+
projectName: "",
|
|
214
|
+
updatedAt: remote.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
215
|
+
source: "qca"
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { isProjectSwitchAllowed as a, requireActiveProject as c, invalidateActiveProjectCache as i, switchActiveProjectViaCallback as l, ProjectSwitchNotAllowedError as n, loadActiveProject as o, assertProjectSwitchAllowed as r, peekCachedActiveProject as s, NoActiveProjectError as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as writeError, t as formatCliArg } from "./
|
|
3
|
-
import { n as
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
1
|
+
import { c as requireActiveProject } from "./project-store-D0UuLan2.mjs";
|
|
2
|
+
import { n as writeError, t as formatCliArg } from "./cli.mjs";
|
|
3
|
+
import { n as mcpCall } from "./mcp-client-aS31KU6J.mjs";
|
|
4
|
+
import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-B8InvGQc.mjs";
|
|
5
|
+
import { n as writeMcpDataResult } from "./mcp-result-Bl71pkOt.mjs";
|
|
6
6
|
import { t as csvToArray } from "./util-BtgWHKWv.mjs";
|
|
7
7
|
import { defineCommand } from "citty";
|
|
8
8
|
//#region src/commands/qa.ts
|
|
@@ -5,7 +5,7 @@ var resistance_default = defineCommand({
|
|
|
5
5
|
name: "resistance",
|
|
6
6
|
description: "客户抗性点标签分页查询"
|
|
7
7
|
},
|
|
8
|
-
subCommands: { list: () => import("./list-
|
|
8
|
+
subCommands: { list: () => import("./list-C6imhAfi.mjs").then((m) => m.default) }
|
|
9
9
|
});
|
|
10
10
|
//#endregion
|
|
11
11
|
export { resistance_default as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as writeError, t as formatCliArg } from "./
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
1
|
+
import { c as requireActiveProject } from "./project-store-D0UuLan2.mjs";
|
|
2
|
+
import { n as writeError, t as formatCliArg } from "./cli.mjs";
|
|
3
|
+
import { n as mcpCall } from "./mcp-client-aS31KU6J.mjs";
|
|
4
|
+
import { i as tenantIdCliArg, n as resolveProjectId, r as resolveTenantId, t as projectIdCliArg } from "./mcp-args-B8InvGQc.mjs";
|
|
5
|
+
import { n as writeMcpDataResult } from "./mcp-result-Bl71pkOt.mjs";
|
|
6
6
|
import { t as csvToArray } from "./util-BtgWHKWv.mjs";
|
|
7
7
|
import { defineCommand } from "citty";
|
|
8
8
|
//#region src/commands/kb/search.ts
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
//#region src/commands/skill/index.ts
|
|
3
|
+
var skill_default = defineCommand({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "skill",
|
|
6
|
+
description: "Skill 中心:列表 / 安装 / 上传(REST,沙箱双凭证)"
|
|
7
|
+
},
|
|
8
|
+
subCommands: {
|
|
9
|
+
list: () => import("./list-BNZV4wei.mjs").then((m) => m.default),
|
|
10
|
+
install: () => import("./install-DP9xV1rY.mjs").then((m) => m.default),
|
|
11
|
+
upload: () => import("./upload-D4wSmRqs.mjs").then((m) => m.default)
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { skill_default as default };
|