beautx-cli 1.0.6-beta.1 → 1.0.6-beta.2

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 (53) hide show
  1. package/README.md +17 -16
  2. package/dist/{analyze-Djk9ehcL.mjs → analyze-0SATHpUC.mjs} +6 -6
  3. package/dist/{api-BxZ6RH9a.mjs → api-D3JyDoiw.mjs} +2 -2
  4. package/dist/{audio-CTEQazMK.mjs → audio-BfNibfXF.mjs} +3 -3
  5. package/dist/{beauty-plan-T6oPTu3Y.mjs → beauty-plan-DQl_OJNK.mjs} +4 -4
  6. package/dist/cli.mjs +19 -7636
  7. package/dist/config-C8aqUXV7.mjs +14 -0
  8. package/dist/{consultant-B7GAFHWs.mjs → consultant-DbYBzHqQ.mjs} +1 -1
  9. package/dist/{content-B4D6j0vv.mjs → content-BTHG2DCs.mjs} +3 -3
  10. package/dist/{current-BeoE1SK9.mjs → current-BDH1xER9.mjs} +3 -3
  11. package/dist/{customer-DqDTvC1N.mjs → customer-D04eXm64.mjs} +1 -1
  12. package/dist/{deal-analysis-CwUKL9Ji.mjs → deal-analysis-Dpg9VGjK.mjs} +4 -4
  13. package/dist/{doc-D6G4Z_rv.mjs → doc-CWgdZ_Eh.mjs} +3 -3
  14. package/dist/env-callback-CIXEvt0i.mjs +349 -0
  15. package/dist/env-vars-CXEHR_mk.mjs +231 -0
  16. package/dist/{fields-DJeLpaGd.mjs → fields-D-iEk93w.mjs} +4 -4
  17. package/dist/{focus-LvkCcszr.mjs → focus-BMcnVGqT.mjs} +1 -1
  18. package/dist/format-9T59sVxH.mjs +7253 -0
  19. package/dist/{get-BBOaM5KU.mjs → get-BLdqZ3XJ.mjs} +3 -3
  20. package/dist/{kb-Bhd58evq.mjs → kb-BPy6E_uX.mjs} +2 -2
  21. package/dist/{list-CabGBbim.mjs → list-BMbWa85R.mjs} +5 -5
  22. package/dist/{list-B5DASwyK.mjs → list-C73pWNBd.mjs} +2 -2
  23. package/dist/{list-DIiYjEZk.mjs → list-CB7YZTB4.mjs} +5 -5
  24. package/dist/{list-tnh01ZMo.mjs → list-Ck_kx-iC.mjs} +5 -5
  25. package/dist/{list-CuINauZ_.mjs → list-DIvD8BvI.mjs} +5 -5
  26. package/dist/{list-utR_LRZN.mjs → list-DqXRvhfS.mjs} +5 -5
  27. package/dist/{list-C7Vq9L7R.mjs → list-DyePBi8K.mjs} +5 -5
  28. package/dist/list-FCCClcl-.mjs +64 -0
  29. package/dist/{list-B5hx_XTf.mjs → list-JL2fmylz.mjs} +5 -5
  30. package/dist/{mcp-args-Cop-Gaha.mjs → mcp-args-CYOCdClW.mjs} +1 -1
  31. package/dist/{mcp-client-BadcKqv9.mjs → mcp-client-OuKd8iir.mjs} +76 -37
  32. package/dist/{mcp-result-CBq8FqvE.mjs → mcp-result-B5HHO7ap.mjs} +2 -2
  33. package/dist/{portrait-tags-DvTmM5jj.mjs → portrait-tags-DRQi5JcR.mjs} +4 -4
  34. package/dist/{project-BnO3fpfa.mjs → project-CEmZCvSp.mjs} +3 -3
  35. package/dist/{project-access-fgfgvJTL.mjs → project-access-O-VSqqVC.mjs} +30 -20
  36. package/dist/project-store-DHqT0-nk.mjs +55 -0
  37. package/dist/{qa-BY3EqJQm.mjs → qa-B7WbwUts.mjs} +6 -6
  38. package/dist/{resistance-DTXXWAm5.mjs → resistance-FtBtoEDl.mjs} +1 -1
  39. package/dist/{search-B9MphR3s.mjs → search-BuMtyCiU.mjs} +6 -6
  40. package/dist/{summary-C3ll-30H.mjs → summary-Cg79V9oz.mjs} +5 -5
  41. package/dist/{text--mtegj9C.mjs → text-CGOU6uh9.mjs} +5 -5
  42. package/dist/{use-xg62A9ri.mjs → use-Bzhvb9I3.mjs} +6 -8
  43. package/dist/{visit-evaluate-C23CuEiJ.mjs → visit-evaluate-BQIyxZeM.mjs} +4 -4
  44. package/dist/{visit-query-args-CZogADi5.mjs → visit-query-args-CDDQ9JJ8.mjs} +3 -3
  45. package/dist/{visit-l8rrEEtj.mjs → visit-vaoFdiLr.mjs} +2 -2
  46. package/package.json +1 -1
  47. package/dist/config-Bp7zHinN.mjs +0 -15
  48. package/dist/doctor-RwDPp4y3.mjs +0 -37
  49. package/dist/list-yupPP25S.mjs +0 -83
  50. package/dist/project-access-BeRtEUkG.mjs +0 -2
  51. package/dist/project-store-8Cl4Sv5d.mjs +0 -2
  52. package/dist/project-store-CA7tRioX.mjs +0 -424
  53. /package/dist/{util-Bko-nm_R.mjs → util-BtgWHKWv.mjs} +0 -0
@@ -1,6 +1,6 @@
1
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
2
- import { n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
3
- import { n as writeMcpDataResult } from "./mcp-result-CBq8FqvE.mjs";
1
+ import { n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
3
+ import { n as writeMcpDataResult } from "./mcp-result-B5HHO7ap.mjs";
4
4
  import { defineCommand } from "citty";
5
5
  //#region src/commands/kb/doc/get.ts
6
6
  /**
@@ -6,8 +6,8 @@ var kb_default = defineCommand({
6
6
  description: "知识库检索与文档查询"
7
7
  },
8
8
  subCommands: {
9
- search: () => import("./search-B9MphR3s.mjs").then((m) => m.default),
10
- doc: () => import("./doc-D6G4Z_rv.mjs").then((m) => m.default)
9
+ search: () => import("./search-BuMtyCiU.mjs").then((m) => m.default),
10
+ doc: () => import("./doc-CWgdZ_Eh.mjs").then((m) => m.default)
11
11
  }
12
12
  });
13
13
  //#endregion
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
4
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
5
- import { i as toLocalDateTime } from "./util-Bko-nm_R.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
3
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
4
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { i as toLocalDateTime } from "./util-BtgWHKWv.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/customer/list.ts
8
8
  /**
@@ -1,5 +1,5 @@
1
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
2
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
3
3
  import { defineCommand } from "citty";
4
4
  //#region src/commands/project/list.ts
5
5
  /**
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
4
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
5
- import { i as toLocalDateTime } from "./util-Bko-nm_R.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
3
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
4
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { i as toLocalDateTime } from "./util-BtgWHKWv.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/visit/list.ts
8
8
  /**
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
4
- import { i as tenantIdCliArg, n as resolveProjectId, r as resolveTenantId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
5
- import { n as writeMcpDataResult } from "./mcp-result-CBq8FqvE.mjs";
1
+ import { n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
3
+ import { i as tenantIdCliArg, n as resolveProjectId, r as resolveTenantId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
4
+ import { n as writeMcpDataResult } from "./mcp-result-B5HHO7ap.mjs";
5
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/kb/doc/list.ts
8
8
  /**
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
4
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
5
- import { i as toLocalDateTime, t as csvToArray } from "./util-Bko-nm_R.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
3
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
4
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { i as toLocalDateTime, t as csvToArray } from "./util-BtgWHKWv.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/resistance/list.ts
8
8
  /**
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
4
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
5
- import { n as writeMcpDataResult } from "./mcp-result-CBq8FqvE.mjs";
1
+ import { n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
3
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
4
+ import { n as writeMcpDataResult } from "./mcp-result-B5HHO7ap.mjs";
5
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/consultant/list.ts
8
8
  /**
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
4
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
5
- import { i as toLocalDateTime, r as mergeUserIds, t as csvToArray } from "./util-Bko-nm_R.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
3
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
4
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { i as toLocalDateTime, r as mergeUserIds, t as csvToArray } from "./util-BtgWHKWv.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/audio/list.ts
8
8
  /**
@@ -0,0 +1,64 @@
1
+ import { c as readCredentials, d as resolveEndpoints, i as isEnvInjectedByHost, l as readEnv, r as credentialStatus, t as ENV_KEYS } from "./env-vars-CXEHR_mk.mjs";
2
+ import { a as debugLogPath, o as isVerboseDebugEnabled } from "./env-callback-CIXEvt0i.mjs";
3
+ import { n as writeError, r as writeResult, t as formatCliArg } from "./format-9T59sVxH.mjs";
4
+ import { n as isProjectSwitchAllowed, r as loadActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { defineCommand } from "citty";
6
+ //#region src/commands/config/list.ts
7
+ /**
8
+ * `beautx-cli config list` — agent-facing env diagnostics (secrets redacted).
9
+ */
10
+ var list_default = defineCommand({
11
+ meta: {
12
+ name: "list",
13
+ description: "列出当前配置(脱敏,含凭据过期时间)"
14
+ },
15
+ args: { format: formatCliArg },
16
+ async run({ args }) {
17
+ try {
18
+ const endpoints = resolveEndpoints();
19
+ const creds = readCredentials();
20
+ const accessView = credentialStatus(creds);
21
+ const refreshConfigured = Boolean(creds.refreshToken);
22
+ const active = await loadActiveProject();
23
+ writeResult({
24
+ env: endpoints.env,
25
+ deploymentEnvManagedByHost: true,
26
+ envInjectedByHost: isEnvInjectedByHost(),
27
+ projectUseAllowed: isProjectSwitchAllowed(),
28
+ gatewayUrl: endpoints.gatewayUrl,
29
+ authUrl: endpoints.authUrl,
30
+ callbackBaseUrl: endpoints.callbackBaseUrl,
31
+ urlProfileSource: "src/core/endpoints.ts",
32
+ configSource: "environment",
33
+ credentialsManagedBy: "host",
34
+ credentials: {
35
+ accessToken: accessView,
36
+ refreshToken: { configured: refreshConfigured }
37
+ },
38
+ user: {
39
+ userId: readEnv(ENV_KEYS.USER_ID) || null,
40
+ userName: readEnv(ENV_KEYS.USER_NAME) || null
41
+ },
42
+ activeProject: active ? {
43
+ configured: true,
44
+ tenantId: active.tenantId,
45
+ tenantName: active.tenantName,
46
+ projectId: active.projectId,
47
+ projectName: active.projectName,
48
+ source: active.source
49
+ } : { configured: false },
50
+ xbAppId: readEnv(ENV_KEYS.XB_APP_ID) || null,
51
+ debugLog: {
52
+ path: debugLogPath(),
53
+ errorsAlwaysLogged: true,
54
+ verboseTracing: isVerboseDebugEnabled()
55
+ }
56
+ }, args.format);
57
+ } catch (err) {
58
+ writeError(err, args.format);
59
+ process.exit(1);
60
+ }
61
+ }
62
+ });
63
+ //#endregion
64
+ export { list_default as default };
@@ -1,8 +1,8 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
4
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
5
- import { i as toLocalDateTime, t as csvToArray } from "./util-Bko-nm_R.mjs";
1
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
2
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
3
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
4
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
5
+ import { i as toLocalDateTime, t as csvToArray } from "./util-BtgWHKWv.mjs";
6
6
  import { defineCommand } from "citty";
7
7
  //#region src/commands/focus/list.ts
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { _ as readEnv, u as ENV_KEYS } from "./project-store-CA7tRioX.mjs";
1
+ import { l as readEnv, t as ENV_KEYS } from "./env-vars-CXEHR_mk.mjs";
2
2
  //#region src/core/mcp-args.ts
3
3
  /**
4
4
  * Shared MCP argument helpers — align CLI flags with BFF tool schemas.
@@ -1,7 +1,65 @@
1
1
  import { n as __exportAll } from "./rolldown-runtime-YLnNgb9a.mjs";
2
- import { C as MissingAccessTokenError, _ as readEnv, d as assertEndpointsValid, u as ENV_KEYS, w as MissingGatewayError, y as resolveEndpoints } from "./project-store-CA7tRioX.mjs";
3
- import { a as debugLogInfo, i as debugLogError, l as ensureAuth } from "./cli.mjs";
2
+ import { _ as MissingGatewayError, a as isTokenExpired, c as readCredentials, d as resolveEndpoints, g as MissingAccessTokenError, l as readEnv, n as assertEndpointsValid, o as needsRefresh, p as AccessTokenExpiredError, t as ENV_KEYS, v as MissingRefreshTokenError, y as RefreshFailedError } from "./env-vars-CXEHR_mk.mjs";
3
+ import { t as invalidateProjectAccessCache } from "./project-access-O-VSqqVC.mjs";
4
+ import { i as debugLogInfo, n as persistTokensToHost, r as debugLogError } from "./env-callback-CIXEvt0i.mjs";
4
5
  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
5
63
  //#region src/core/config.ts
6
64
  /**
7
65
  * MCP gateway configuration — env-only resolution.
@@ -24,21 +82,16 @@ async function resolveMcpConfig() {
24
82
  /**
25
83
  * Normalize MCP tools/call arguments before they hit the gateway wire.
26
84
  *
27
- * - {@code project-list}: always attach default {@code project_id} (gateway billing),
85
+ * - project-list: always attach Host ESTATE_ID as project_id for gateway billing,
28
86
  * ignoring any CLI-supplied value.
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).
87
+ * - Other tools: attach project_id from Host env when callers omit it, so gateway
88
+ * audit / billing can see the active project even if the application ignores it.
33
89
  */
34
- function augmentMcpWireArguments(toolName, args, defaultProjectId) {
35
- const estateId = defaultProjectId?.trim() || "";
90
+ function augmentMcpWireArguments(toolName, args) {
91
+ const estateId = readEnv(ENV_KEYS.ESTATE_ID)?.trim();
36
92
  if (toolName === "project-list") {
37
- if (!estateId) {
38
- const { project_id: _drop, ...rest } = args;
39
- return rest;
40
- }
41
93
  const { project_id: _drop, ...rest } = args;
94
+ if (!estateId) return rest;
42
95
  return {
43
96
  ...rest,
44
97
  project_id: estateId
@@ -64,7 +117,6 @@ var mcp_client_exports = /* @__PURE__ */ __exportAll({
64
117
  MCP_CALL_SOURCE: () => MCP_CALL_SOURCE,
65
118
  MCP_SERVICE_CODE: () => MCP_SERVICE_CODE,
66
119
  McpGatewayError: () => McpGatewayError,
67
- buildMcpHttpHeaders: () => buildMcpHttpHeaders,
68
120
  mcpCall: () => mcpCall,
69
121
  unwrapMcpToolEnvelope: () => unwrapMcpToolEnvelope
70
122
  });
@@ -98,9 +150,9 @@ function unwrapMcpToolEnvelope(mcpResult) {
98
150
  return {};
99
151
  }
100
152
  const ERROR_HINTS = {
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",
153
+ TOKEN_MISSING: "由 Host 注入 MCP_TOKEN",
154
+ TOKEN_INVALID: "由 Host 重新换票后更新 MCP_TOKEN",
155
+ TOKEN_EXPIRED: "由 Host 重新换票后更新 MCP_TOKEN / REFRESH_TOKEN",
104
156
  TOKEN_AUD_MISMATCH: "确认 token 为 MCP 网关签发且 scope 含 mcp:invoke",
105
157
  POLICY_DENIED: "无权访问该服务,请联系管理员确认 serviceCode 权限",
106
158
  SERVICE_NOT_FOUND: "serviceCode 不存在,请确认网关侧已注册",
@@ -119,29 +171,12 @@ var McpGatewayError = class extends Error {
119
171
  this.hint = ERROR_HINTS[code] ?? `MCP 网关错误: ${code}`;
120
172
  }
121
173
  };
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
- }
137
174
  async function mcpCall(toolName, opts) {
138
- const { loadActiveProject } = await import("./project-store-8Cl4Sv5d.mjs");
139
- const active = await loadActiveProject();
140
- const wireArguments = augmentMcpWireArguments(toolName, opts.arguments ?? {}, active?.projectId);
175
+ const wireArguments = augmentMcpWireArguments(toolName, opts.arguments ?? {});
141
176
  if (toolName !== "project-list") {
142
177
  const rawProjectId = wireArguments.project_id;
143
178
  if (rawProjectId != null && String(rawProjectId).trim()) {
144
- const { assertProjectAllowed } = await import("./project-access-BeRtEUkG.mjs");
179
+ const { assertProjectAllowed } = await import("./project-access-O-VSqqVC.mjs").then((n) => n.n);
145
180
  await assertProjectAllowed(String(rawProjectId).trim());
146
181
  }
147
182
  }
@@ -169,7 +204,11 @@ async function mcpCallOnce(toolName, opts, retriedAfterRefresh) {
169
204
  });
170
205
  const resp = await fetch(url, {
171
206
  method: "POST",
172
- headers: buildMcpHttpHeaders(config.token),
207
+ headers: {
208
+ Accept: "application/json, text/event-stream",
209
+ "Content-Type": "application/json",
210
+ Authorization: `Bearer ${config.token}`
211
+ },
173
212
  body,
174
213
  signal: AbortSignal.timeout(opts.timeoutMs ?? 3e4)
175
214
  });
@@ -1,5 +1,5 @@
1
- import { n as writeError, r as writeResult } from "./cli.mjs";
2
- import { i as unwrapMcpToolEnvelope, n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
1
+ import { i as unwrapMcpToolEnvelope, n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, r as writeResult } from "./format-9T59sVxH.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 { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError } from "./cli.mjs";
3
- import { t as mcpCallPage } from "./mcp-result-CBq8FqvE.mjs";
4
- import { n as visitBatchQueryCliArgs, t as buildVisitBatchQueryArgs } from "./visit-query-args-CZogADi5.mjs";
1
+ import { n as writeError } from "./format-9T59sVxH.mjs";
2
+ import { t as mcpCallPage } from "./mcp-result-B5HHO7ap.mjs";
3
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
4
+ import { n as visitBatchQueryCliArgs, t as buildVisitBatchQueryArgs } from "./visit-query-args-CDDQ9JJ8.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-B5DASwyK.mjs").then((m) => m.default),
10
- use: () => import("./use-xg62A9ri.mjs").then((m) => m.default),
11
- current: () => import("./current-BeoE1SK9.mjs").then((m) => m.default)
9
+ list: () => import("./list-C73pWNBd.mjs").then((m) => m.default),
10
+ use: () => import("./use-Bzhvb9I3.mjs").then((m) => m.default),
11
+ current: () => import("./current-BDH1xER9.mjs").then((m) => m.default)
12
12
  }
13
13
  });
14
14
  //#endregion
@@ -1,4 +1,5 @@
1
- import { S as ConfigInvalidError, _ as readEnv, o as loadActiveProject, s as peekCachedActiveProject, u as ENV_KEYS, v as requireUserId, y as resolveEndpoints } from "./project-store-CA7tRioX.mjs";
1
+ import { n as __exportAll } from "./rolldown-runtime-YLnNgb9a.mjs";
2
+ import { d as resolveEndpoints, l as readEnv, m as ConfigInvalidError, s as readActiveProject, t as ENV_KEYS, u as requireUserId } from "./env-vars-CXEHR_mk.mjs";
2
3
  var InsufficientCreditError = class extends Error {
3
4
  code = "INSUFFICIENT_CREDIT";
4
5
  hint = "(该项目下)用户积分余额不足,无法继续查询;请告知用户联系管理员充值";
@@ -40,7 +41,7 @@ async function assertCreditRemaining(projectId) {
40
41
  }
41
42
  async function fetchCreditRemaining(userId, projectId) {
42
43
  const { callbackBaseUrl } = resolveEndpoints();
43
- const url = new URL(`/api/wang-claw/out/v2/credit/users/${encodeURIComponent(userId)}/remaining`, callbackBaseUrl);
44
+ const url = new URL(`/api/wang-claw/out/credit/users/${encodeURIComponent(userId)}/remaining`, callbackBaseUrl);
44
45
  url.searchParams.set("projectId", projectId);
45
46
  let resp;
46
47
  try {
@@ -81,6 +82,13 @@ function extractEnvelopeMessage(body) {
81
82
  * Allowed estate (project) guard for CLI — validates project_id against
82
83
  * {@code project-list} before MCP calls (in-process TTL cache).
83
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
+ });
84
92
  const PROJECT_ACCESS_TTL_MS = 300 * 1e3;
85
93
  const PROJECT_LIST_PAGE_SIZE = 100;
86
94
  let cache = null;
@@ -100,7 +108,7 @@ function invalidateProjectAccessCache() {
100
108
  function resolveCacheTenantId() {
101
109
  const fromEnv = readEnv(ENV_KEYS.TENANT_ID);
102
110
  if (fromEnv) return fromEnv;
103
- return peekCachedActiveProject()?.tenantId?.trim() ?? "";
111
+ return readActiveProject()?.tenantId?.trim() ?? "";
104
112
  }
105
113
  function cacheIsValid(state, tenantId) {
106
114
  return state.tenantId === tenantId && Date.now() - state.fetchedAt < 3e5;
@@ -131,9 +139,9 @@ function finalizeResolvedProject(partial) {
131
139
  projectName: partial.projectName?.trim() ?? ""
132
140
  };
133
141
  }
134
- function isCachedActiveEstate(projectId) {
135
- const active = peekCachedActiveProject();
136
- return Boolean(active?.projectId && active.projectId === projectId);
142
+ function isHostActiveEstate(projectId) {
143
+ const activeEstateId = readEnv(ENV_KEYS.ESTATE_ID)?.trim();
144
+ return Boolean(activeEstateId && activeEstateId === projectId);
137
145
  }
138
146
  /**
139
147
  * Ensure {@code projectId} is in the gateway project-list roster.
@@ -142,7 +150,7 @@ function isCachedActiveEstate(projectId) {
142
150
  async function assertProjectAllowed(projectId) {
143
151
  const id = projectId?.trim();
144
152
  if (!id) return;
145
- if (!isCachedActiveEstate(id)) {
153
+ if (!isHostActiveEstate(id)) {
146
154
  const tenantId = resolveCacheTenantId();
147
155
  if (cache && cacheIsValid(cache, tenantId)) {
148
156
  if (!cache.allowedEstateIds.has(id)) {
@@ -155,20 +163,22 @@ async function assertProjectAllowed(projectId) {
155
163
  }
156
164
  /**
157
165
  * Resolve tenant/project metadata for {@code project use} from project-list.
158
- * Names are display-only; IDs come from the roster row.
166
+ * Names are display-only (Host env); IDs come from the roster row.
159
167
  */
160
168
  async function resolveProjectForUse(projectId) {
161
169
  const id = projectId?.trim();
162
170
  if (!id) throw new ConfigInvalidError("缺少 project_id", "运行 `beautx-cli project list` 选择项目");
163
- const active = await loadActiveProject();
164
- if (active?.projectId === id) {
165
- await assertCreditRemaining(id);
166
- return finalizeResolvedProject({
167
- tenantId: active.tenantId,
168
- tenantName: active.tenantName,
169
- projectId: id,
170
- projectName: active.projectName
171
- });
171
+ if (isHostActiveEstate(id)) {
172
+ const active = readActiveProject();
173
+ if (active?.projectId === id) {
174
+ await assertCreditRemaining(id);
175
+ return finalizeResolvedProject({
176
+ tenantId: active.tenantId,
177
+ tenantName: active.tenantName,
178
+ projectId: id,
179
+ projectName: active.projectName
180
+ });
181
+ }
172
182
  }
173
183
  const row = await lookupProjectRow(id);
174
184
  await assertCreditRemaining(id);
@@ -227,14 +237,14 @@ function normalizeProjectListPage(page) {
227
237
  };
228
238
  }
229
239
  async function fetchProjectListPage(page, size) {
230
- const { mcpCall, unwrapMcpToolEnvelope } = await import("./mcp-client-BadcKqv9.mjs").then((n) => n.r);
240
+ const { mcpCall, unwrapMcpToolEnvelope } = await import("./mcp-client-OuKd8iir.mjs").then((n) => n.r);
231
241
  const result = await mcpCall("project-list", { arguments: {
232
242
  page,
233
243
  size
234
244
  } });
235
245
  if (!result.ok) {
236
246
  const detail = extractMcpFailureDetail(result.data);
237
- throw new ConfigInvalidError(detail ? `无法拉取项目列表以校验 project_id: ${detail}` : "无法拉取项目列表以校验 project_id", "检查 MCP 网关与 token 是否正常;大租户可先由平台预置当前项目");
247
+ throw new ConfigInvalidError(detail ? `无法拉取项目列表以校验 project_id: ${detail}` : "无法拉取项目列表以校验 project_id", "检查 MCP 网关与 token 是否正常;大租户可先用 Host 预置当前项目");
238
248
  }
239
249
  const envelope = unwrapMcpToolEnvelope(result.data);
240
250
  const code = envelope.code;
@@ -261,4 +271,4 @@ function extractMcpFailureDetail(data) {
261
271
  }
262
272
  }
263
273
  //#endregion
264
- export { resolveProjectForUse as a, invalidateProjectAccessCache as i, ProjectNotAllowedError as n, assertProjectAllowed as r, PROJECT_ACCESS_TTL_MS as t };
274
+ export { project_access_exports as n, resolveProjectForUse as r, invalidateProjectAccessCache as t };
@@ -0,0 +1,55 @@
1
+ import { l as readEnv, s as readActiveProject, t as ENV_KEYS } from "./env-vars-CXEHR_mk.mjs";
2
+ import { t as persistActiveProjectToHost } from "./env-callback-CIXEvt0i.mjs";
3
+ //#region src/core/project-store.ts
4
+ /**
5
+ * Active project — env-only; Host is the persistence layer via callback.
6
+ */
7
+ async function loadActiveProject() {
8
+ return readActiveProject();
9
+ }
10
+ async function switchActiveProjectViaCallback(p) {
11
+ await persistActiveProjectToHost({
12
+ tenantId: p.tenantId,
13
+ tenantName: p.tenantName,
14
+ projectId: p.projectId,
15
+ projectName: p.projectName
16
+ });
17
+ return {
18
+ ...p,
19
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
20
+ source: "env"
21
+ };
22
+ }
23
+ var NoActiveProjectError = class extends Error {
24
+ code = "NO_ACTIVE_PROJECT";
25
+ hint = "先用 `beautx-cli project list [--keyword <kw>]` 查看可选项目,再用 `beautx-cli project use --project-id <id>` 激活;或由 Host 预置当前项目。";
26
+ constructor() {
27
+ super("当前未设置激活项目");
28
+ this.name = "NoActiveProjectError";
29
+ }
30
+ };
31
+ async function requireActiveProject() {
32
+ const p = await loadActiveProject();
33
+ if (!p?.projectId) throw new NoActiveProjectError();
34
+ return p;
35
+ }
36
+ /**
37
+ * Project switching is blocked only in the aike app (XB_APP_ID=aike).
38
+ */
39
+ var ProjectSwitchNotAllowedError = class extends Error {
40
+ code = "PROJECT_SWITCH_NOT_ALLOWED";
41
+ hint = "当前应用(XB_APP_ID=aike)不允许通过 CLI 切换项目,请使用 UI 切换。";
42
+ constructor() {
43
+ super("无法切换项目:不允许在当前应用下切换");
44
+ this.name = "ProjectSwitchNotAllowedError";
45
+ }
46
+ };
47
+ function assertProjectSwitchAllowed() {
48
+ if (!isProjectSwitchAllowed()) throw new ProjectSwitchNotAllowedError();
49
+ }
50
+ /** Whether CLI may run `project use` (false only when XB_APP_ID=aike). */
51
+ function isProjectSwitchAllowed() {
52
+ return readEnv(ENV_KEYS.XB_APP_ID).toLowerCase() !== "aike";
53
+ }
54
+ //#endregion
55
+ export { switchActiveProjectViaCallback as a, requireActiveProject as i, isProjectSwitchAllowed as n, loadActiveProject as r, assertProjectSwitchAllowed as t };
@@ -1,9 +1,9 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
4
- import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
5
- import { n as writeMcpDataResult } from "./mcp-result-CBq8FqvE.mjs";
6
- import { t as csvToArray } from "./util-Bko-nm_R.mjs";
1
+ import { n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
3
+ import { n as resolveProjectId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
4
+ import { n as writeMcpDataResult } from "./mcp-result-B5HHO7ap.mjs";
5
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
6
+ import { t as csvToArray } from "./util-BtgWHKWv.mjs";
7
7
  import { defineCommand } from "citty";
8
8
  //#region src/commands/qa.ts
9
9
  /**
@@ -5,7 +5,7 @@ var resistance_default = defineCommand({
5
5
  name: "resistance",
6
6
  description: "客户抗性点标签分页查询"
7
7
  },
8
- subCommands: { list: () => import("./list-CuINauZ_.mjs").then((m) => m.default) }
8
+ subCommands: { list: () => import("./list-DIvD8BvI.mjs").then((m) => m.default) }
9
9
  });
10
10
  //#endregion
11
11
  export { resistance_default as default };
@@ -1,9 +1,9 @@
1
- import { c as requireActiveProject } from "./project-store-CA7tRioX.mjs";
2
- import { n as writeError, t as formatCliArg } from "./cli.mjs";
3
- import { n as mcpCall } from "./mcp-client-BadcKqv9.mjs";
4
- import { i as tenantIdCliArg, n as resolveProjectId, r as resolveTenantId, t as projectIdCliArg } from "./mcp-args-Cop-Gaha.mjs";
5
- import { n as writeMcpDataResult } from "./mcp-result-CBq8FqvE.mjs";
6
- import { t as csvToArray } from "./util-Bko-nm_R.mjs";
1
+ import { n as mcpCall } from "./mcp-client-OuKd8iir.mjs";
2
+ import { n as writeError, t as formatCliArg } from "./format-9T59sVxH.mjs";
3
+ import { i as tenantIdCliArg, n as resolveProjectId, r as resolveTenantId, t as projectIdCliArg } from "./mcp-args-CYOCdClW.mjs";
4
+ import { n as writeMcpDataResult } from "./mcp-result-B5HHO7ap.mjs";
5
+ import { i as requireActiveProject } from "./project-store-DHqT0-nk.mjs";
6
+ import { t as csvToArray } from "./util-BtgWHKWv.mjs";
7
7
  import { defineCommand } from "citty";
8
8
  //#region src/commands/kb/search.ts
9
9
  /**