@nextclaw/app-runtime 0.4.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ import { PermissionsCommand } from "./commands/permissions.controller.js";
31
31
  import { AppMarketplaceMetadata, AppPublishFile, AppPublishPayload, AppPublishResult, DEFAULT_APP_MARKETPLACE_API_BASE } from "./publish/app-publish.types.js";
32
32
  import { AppMarketplaceClientService } from "./publish/app-marketplace-client.service.js";
33
33
  import { AppMarketplaceMetadataService } from "./publish/app-marketplace-metadata.service.js";
34
+ import { PlatformAuthStateService, PlatformPublishAuthState } from "./publish/platform-auth-state.service.js";
34
35
  import { AppPublishService } from "./publish/app-publish.service.js";
35
36
  import { PublishCommand } from "./commands/publish.controller.js";
36
37
  import { RegistryCommand } from "./commands/registry.controller.js";
@@ -39,4 +40,4 @@ import { UpdateCommand } from "./commands/update.controller.js";
39
40
  import { UninstallCommand } from "./commands/uninstall.controller.js";
40
41
  import { AppHostHandle, AppHostService, AppHostStartOptions } from "./host/app-host.service.js";
41
42
  import { UiServerService } from "./ui/ui-server.service.js";
42
- export { AppBundleChecksums, AppBundleExtractResult, AppBundleMetadata, AppBundlePackResult, AppBundleService, AppDocumentAccessMode, AppDocumentAccessScope, AppDocumentGrantMap, AppDocumentGrantMutationResult, AppDocumentGrantState, AppGrantService, AppHomeService, AppHostHandle, AppHostService, AppHostStartOptions, AppInfoResult, AppInstallResult, AppInstallSourceKind, AppInstallationService, AppInstalledPermissionState, AppInstanceService, AppLaunchResolution, AppMainManifest, AppManifest, AppManifestBundle, AppManifestService, AppManifestSummary, AppMarketplaceClientService, AppMarketplaceMetadata, AppMarketplaceMetadataService, AppPermissionSummary, AppPermissions, AppPermissionsService, AppPublishFile, AppPublishPayload, AppPublishResult, AppPublishService, AppPublisher, AppRegistry, AppRegistryAppRecord, AppRegistryConfig, AppRegistryConfigService, AppRegistryConfigSnapshot, AppRegistryInstalledVersion, AppRegistryService, AppRemoteRegistryClientService, AppRemoteRegistryDocument, AppRemoteRegistryResolution, AppRemoteRegistryVersion, AppRunResult, AppRuntimeCliService, AppRuntimeOptionsService, AppUiManifest, AppUninstallResult, AppUpdateResult, CreateCliOptions, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCliOptions, GrantCommand, HostBridgeServer, InfoCommand, InstallCliOptions, InstallCommand, InstalledAppListItem, JsonOnlyCliOptions, ListCommand, MainRunRequest, MainRunResult, MainRunnerService, PackCliOptions, PackCommand, PermissionsCommand, PublishCliOptions, PublishCommand, RegistryCommand, ResolvedDocumentGrant, ResolvedPermissions, RevokeCliOptions, RevokeCommand, RuntimeCliOptions, UiServerService, UninstallCliOptions, UninstallCommand, UpdateCliOptions, UpdateCommand, WasmDocumentSummaryInput, WasmMainRunnerService, WasmSidecarClientService };
43
+ export { AppBundleChecksums, AppBundleExtractResult, AppBundleMetadata, AppBundlePackResult, AppBundleService, AppDocumentAccessMode, AppDocumentAccessScope, AppDocumentGrantMap, AppDocumentGrantMutationResult, AppDocumentGrantState, AppGrantService, AppHomeService, AppHostHandle, AppHostService, AppHostStartOptions, AppInfoResult, AppInstallResult, AppInstallSourceKind, AppInstallationService, AppInstalledPermissionState, AppInstanceService, AppLaunchResolution, AppMainManifest, AppManifest, AppManifestBundle, AppManifestService, AppManifestSummary, AppMarketplaceClientService, AppMarketplaceMetadata, AppMarketplaceMetadataService, AppPermissionSummary, AppPermissions, AppPermissionsService, AppPublishFile, AppPublishPayload, AppPublishResult, AppPublishService, AppPublisher, AppRegistry, AppRegistryAppRecord, AppRegistryConfig, AppRegistryConfigService, AppRegistryConfigSnapshot, AppRegistryInstalledVersion, AppRegistryService, AppRemoteRegistryClientService, AppRemoteRegistryDocument, AppRemoteRegistryResolution, AppRemoteRegistryVersion, AppRunResult, AppRuntimeCliService, AppRuntimeOptionsService, AppUiManifest, AppUninstallResult, AppUpdateResult, CreateCliOptions, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCliOptions, GrantCommand, HostBridgeServer, InfoCommand, InstallCliOptions, InstallCommand, InstalledAppListItem, JsonOnlyCliOptions, ListCommand, MainRunRequest, MainRunResult, MainRunnerService, PackCliOptions, PackCommand, PermissionsCommand, PlatformAuthStateService, PlatformPublishAuthState, PublishCliOptions, PublishCommand, RegistryCommand, ResolvedDocumentGrant, ResolvedPermissions, RevokeCliOptions, RevokeCommand, RuntimeCliOptions, UiServerService, UninstallCliOptions, UninstallCommand, UpdateCliOptions, UpdateCommand, WasmDocumentSummaryInput, WasmMainRunnerService, WasmSidecarClientService };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ import { PermissionsCommand } from "./commands/permissions.controller.js";
25
25
  import { DEFAULT_APP_MARKETPLACE_API_BASE } from "./publish/app-publish.types.js";
26
26
  import { AppMarketplaceClientService } from "./publish/app-marketplace-client.service.js";
27
27
  import { AppMarketplaceMetadataService } from "./publish/app-marketplace-metadata.service.js";
28
+ import { PlatformAuthStateService } from "./publish/platform-auth-state.service.js";
28
29
  import { AppPublishService } from "./publish/app-publish.service.js";
29
30
  import { PublishCommand } from "./commands/publish.controller.js";
30
31
  import { RegistryCommand } from "./commands/registry.controller.js";
@@ -33,4 +34,4 @@ import { UninstallCommand } from "./commands/uninstall.controller.js";
33
34
  import { UpdateCommand } from "./commands/update.controller.js";
34
35
  import { AppRuntimeOptionsService } from "./cli/app-runtime-options.service.js";
35
36
  import { AppRuntimeCliService } from "./cli/app-runtime-cli.service.js";
36
- export { AppBundleService, AppGrantService, AppHomeService, AppHostService, AppInstallationService, AppInstanceService, AppManifestService, AppMarketplaceClientService, AppMarketplaceMetadataService, AppPermissionsService, AppPublishService, AppRegistryConfigService, AppRegistryService, AppRemoteRegistryClientService, AppRuntimeCliService, AppRuntimeOptionsService, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCommand, HostBridgeServer, InfoCommand, InstallCommand, ListCommand, MainRunnerService, PackCommand, PermissionsCommand, PublishCommand, RegistryCommand, RevokeCommand, UiServerService, UninstallCommand, UpdateCommand, WasmMainRunnerService, WasmSidecarClientService };
37
+ export { AppBundleService, AppGrantService, AppHomeService, AppHostService, AppInstallationService, AppInstanceService, AppManifestService, AppMarketplaceClientService, AppMarketplaceMetadataService, AppPermissionsService, AppPublishService, AppRegistryConfigService, AppRegistryService, AppRemoteRegistryClientService, AppRuntimeCliService, AppRuntimeOptionsService, CreateCommand, DEFAULT_APP_MARKETPLACE_API_BASE, DEFAULT_APP_REGISTRY_URL, GrantCommand, HostBridgeServer, InfoCommand, InstallCommand, ListCommand, MainRunnerService, PackCommand, PermissionsCommand, PlatformAuthStateService, PublishCommand, RegistryCommand, RevokeCommand, UiServerService, UninstallCommand, UpdateCommand, WasmMainRunnerService, WasmSidecarClientService };
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.4.0";
2
+ var version = "0.4.1";
3
3
  //#endregion
4
4
  export { version };
@@ -3,8 +3,8 @@ import "./app-publish.types.js";
3
3
  var AppMarketplaceClientService = class {
4
4
  publish = async (params) => {
5
5
  const apiBaseUrl = this.normalizeApiBase(params.apiBaseUrl ?? "https://apps-registry.nextclaw.io");
6
- const token = params.token?.trim() || process.env.NEXTCLAW_MARKETPLACE_ADMIN_TOKEN?.trim();
7
- if (!token) throw new Error("缺少 marketplace admin token,请传 --token 或设置 NEXTCLAW_MARKETPLACE_ADMIN_TOKEN。");
6
+ const token = params.token?.trim();
7
+ if (!token) throw new Error("缺少 marketplace publish token。请先登录 NextClaw,或传入 --token。");
8
8
  const response = await fetch(`${apiBaseUrl}/api/v1/apps/publish`, {
9
9
  method: "POST",
10
10
  headers: {
@@ -3,6 +3,7 @@ import { AppBundleService } from "../bundle/app-bundle.service.js";
3
3
  import { AppPublishResult } from "./app-publish.types.js";
4
4
  import { AppMarketplaceClientService } from "./app-marketplace-client.service.js";
5
5
  import { AppMarketplaceMetadataService } from "./app-marketplace-metadata.service.js";
6
+ import { PlatformAuthStateService } from "./platform-auth-state.service.js";
6
7
 
7
8
  //#region src/publish/app-publish.service.d.ts
8
9
  declare class AppPublishService {
@@ -10,13 +11,19 @@ declare class AppPublishService {
10
11
  private readonly bundleService;
11
12
  private readonly metadataService;
12
13
  private readonly marketplaceClient;
13
- constructor(manifestService?: AppManifestService, bundleService?: AppBundleService, metadataService?: AppMarketplaceMetadataService, marketplaceClient?: AppMarketplaceClientService);
14
+ private readonly authStateService;
15
+ constructor(manifestService?: AppManifestService, bundleService?: AppBundleService, metadataService?: AppMarketplaceMetadataService, marketplaceClient?: AppMarketplaceClientService, authStateService?: PlatformAuthStateService);
14
16
  publish: (params: {
15
17
  appDirectory: string;
16
18
  metadataPath?: string;
17
19
  apiBaseUrl?: string;
18
20
  token?: string;
19
21
  }) => Promise<AppPublishResult>;
22
+ private resolvePublishActor;
23
+ private fetchCurrentPlatformUser;
24
+ private resolvePlatformApiBase;
25
+ private buildUserPublisher;
26
+ private buildOfficialPublisher;
20
27
  }
21
28
  //#endregion
22
29
  export { AppPublishService };
@@ -2,16 +2,19 @@ import { AppManifestService } from "../manifest/app-manifest.service.js";
2
2
  import { AppBundleService } from "../bundle/app-bundle.service.js";
3
3
  import { AppMarketplaceClientService } from "./app-marketplace-client.service.js";
4
4
  import { AppMarketplaceMetadataService } from "./app-marketplace-metadata.service.js";
5
+ import { PlatformAuthStateService } from "./platform-auth-state.service.js";
5
6
  import { readFile } from "node:fs/promises";
6
7
  import { createHash } from "node:crypto";
7
8
  import path from "node:path";
8
9
  //#region src/publish/app-publish.service.ts
10
+ const DEFAULT_PLATFORM_API_BASE = "https://ai-gateway-api.nextclaw.io";
9
11
  var AppPublishService = class {
10
- constructor(manifestService = new AppManifestService(), bundleService = new AppBundleService(), metadataService = new AppMarketplaceMetadataService(), marketplaceClient = new AppMarketplaceClientService()) {
12
+ constructor(manifestService = new AppManifestService(), bundleService = new AppBundleService(), metadataService = new AppMarketplaceMetadataService(), marketplaceClient = new AppMarketplaceClientService(), authStateService = new PlatformAuthStateService()) {
11
13
  this.manifestService = manifestService;
12
14
  this.bundleService = bundleService;
13
15
  this.metadataService = metadataService;
14
16
  this.marketplaceClient = marketplaceClient;
17
+ this.authStateService = authStateService;
15
18
  }
16
19
  publish = async (params) => {
17
20
  const { appDirectory: inputAppDirectory, metadataPath, apiBaseUrl, token } = params;
@@ -22,6 +25,11 @@ var AppPublishService = class {
22
25
  manifest: manifestBundle.manifest,
23
26
  metadataPath
24
27
  });
28
+ const actor = await this.resolvePublishActor({
29
+ apiBaseUrl,
30
+ explicitToken: token,
31
+ appId: manifestBundle.manifest.id
32
+ });
25
33
  const bundle = await this.bundleService.packAppDirectory({ appDirectory });
26
34
  const bundleBytes = Buffer.from(await readFile(bundle.bundlePath));
27
35
  const bundleSha256 = createHash("sha256").update(bundleBytes).digest("hex");
@@ -43,11 +51,7 @@ var AppPublishService = class {
43
51
  sourceRepo: metadata.sourceRepo,
44
52
  homepage: metadata.homepage,
45
53
  featured: metadata.featured ?? false,
46
- publisher: metadata.publisher ?? {
47
- id: "nextclaw",
48
- name: "NextClaw",
49
- url: "https://nextclaw.io"
50
- },
54
+ publisher: actor.publisher,
51
55
  manifest: manifestBundle.manifest,
52
56
  permissions: manifestBundle.manifest.permissions ?? {},
53
57
  bundleBase64: bundleBytes.toString("base64"),
@@ -61,7 +65,7 @@ var AppPublishService = class {
61
65
  ...await this.marketplaceClient.publish({
62
66
  payload,
63
67
  apiBaseUrl,
64
- token
68
+ token: actor.token
65
69
  }),
66
70
  bundle: {
67
71
  path: bundle.bundlePath,
@@ -69,6 +73,82 @@ var AppPublishService = class {
69
73
  }
70
74
  };
71
75
  };
76
+ resolvePublishActor = async (params) => {
77
+ const explicitToken = params.explicitToken?.trim();
78
+ const envAdminToken = process.env.NEXTCLAW_MARKETPLACE_ADMIN_TOKEN?.trim();
79
+ if (explicitToken) {
80
+ const token = explicitToken;
81
+ if (!token) throw new Error("缺少 publish token。");
82
+ const me = await this.fetchCurrentPlatformUser({
83
+ token,
84
+ platformApiBase: this.resolvePlatformApiBase()
85
+ });
86
+ return {
87
+ token,
88
+ publisher: this.buildUserPublisher(me, params.appId)
89
+ };
90
+ }
91
+ const authState = this.authStateService.readCurrentAuthState();
92
+ const platformToken = authState.token?.trim();
93
+ if (platformToken) {
94
+ const me = await this.fetchCurrentPlatformUser({
95
+ token: platformToken,
96
+ platformApiBase: this.resolvePlatformApiBase(authState.apiBaseUrl)
97
+ });
98
+ return {
99
+ token: platformToken,
100
+ publisher: this.buildUserPublisher(me, params.appId)
101
+ };
102
+ }
103
+ if (envAdminToken) return {
104
+ token: envAdminToken,
105
+ publisher: this.buildOfficialPublisher()
106
+ };
107
+ throw new Error("发布需要 NextClaw 平台登录态。请先运行 nextclaw login,或传入 --token。");
108
+ };
109
+ fetchCurrentPlatformUser = async (params) => {
110
+ const response = await fetch(`${params.platformApiBase}/platform/auth/me`, { headers: {
111
+ authorization: `Bearer ${params.token}`,
112
+ accept: "application/json"
113
+ } });
114
+ const payload = await response.json().catch(() => null);
115
+ if (!response.ok) {
116
+ const message = typeof payload === "object" && payload && "error" in payload && typeof payload.error?.message === "string" ? payload.error.message : `${response.status} ${response.statusText}`;
117
+ throw new Error(`读取 NextClaw 登录态失败:${message}`);
118
+ }
119
+ const user = typeof payload === "object" && payload && "data" in payload && typeof payload.data?.user === "object" && payload.data.user ? payload.data.user : null;
120
+ const id = typeof user?.id === "string" ? user.id.trim() : "";
121
+ const username = typeof user?.username === "string" ? user.username.trim() : "";
122
+ const role = user?.role === "admin" ? "admin" : "user";
123
+ if (!id) throw new Error("平台登录态缺少用户 id。");
124
+ return {
125
+ id,
126
+ username: username || null,
127
+ role
128
+ };
129
+ };
130
+ resolvePlatformApiBase = (configuredApiBase) => {
131
+ const source = configuredApiBase?.trim() || process.env.NEXTCLAW_PLATFORM_API_BASE?.trim() || DEFAULT_PLATFORM_API_BASE;
132
+ const normalized = new URL(source);
133
+ normalized.pathname = normalized.pathname.replace(/\/v1\/?$/, "/");
134
+ return normalized.toString().replace(/\/+$/, "");
135
+ };
136
+ buildUserPublisher = (user, appId) => {
137
+ if (appId.startsWith("nextclaw.") && user.role === "admin") return this.buildOfficialPublisher();
138
+ if (!user.username) throw new Error("当前 NextClaw 账号还没有 username,无法发布个人 scope app。请先在平台账号页设置用户名。");
139
+ return {
140
+ id: user.username,
141
+ name: user.username,
142
+ url: `https://platform.nextclaw.io/account`
143
+ };
144
+ };
145
+ buildOfficialPublisher = () => {
146
+ return {
147
+ id: "nextclaw",
148
+ name: "NextClaw",
149
+ url: "https://nextclaw.io"
150
+ };
151
+ };
72
152
  };
73
153
  //#endregion
74
154
  export { AppPublishService };
@@ -0,0 +1,11 @@
1
+ //#region src/publish/platform-auth-state.service.d.ts
2
+ type PlatformPublishAuthState = {
3
+ token: string | null;
4
+ apiBaseUrl?: string;
5
+ };
6
+ declare class PlatformAuthStateService {
7
+ readCurrentAuthState: () => PlatformPublishAuthState;
8
+ private resolveConfigPath;
9
+ }
10
+ //#endregion
11
+ export { PlatformAuthStateService, PlatformPublishAuthState };
@@ -0,0 +1,26 @@
1
+ import { resolve } from "node:path";
2
+ import { homedir } from "node:os";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ //#region src/publish/platform-auth-state.service.ts
5
+ var PlatformAuthStateService = class {
6
+ readCurrentAuthState = () => {
7
+ const configPath = this.resolveConfigPath();
8
+ if (!existsSync(configPath)) return { token: null };
9
+ try {
10
+ const raw = readFileSync(configPath, "utf-8");
11
+ const provider = JSON.parse(raw).providers?.nextclaw;
12
+ return {
13
+ token: typeof provider?.apiKey === "string" && provider.apiKey.trim().length > 0 ? provider.apiKey.trim() : null,
14
+ apiBaseUrl: typeof provider?.apiBase === "string" && provider.apiBase.trim().length > 0 ? provider.apiBase.trim() : void 0
15
+ };
16
+ } catch {
17
+ return { token: null };
18
+ }
19
+ };
20
+ resolveConfigPath = () => {
21
+ const nextclawHome = process.env.NEXTCLAW_HOME?.trim();
22
+ return resolve(nextclawHome && nextclawHome.length > 0 ? resolve(nextclawHome) : resolve(homedir(), ".nextclaw"), "config.json");
23
+ };
24
+ };
25
+ //#endregion
26
+ export { PlatformAuthStateService };
@@ -216,12 +216,7 @@ var AppScaffoldService = class {
216
216
  ],
217
217
  sourceRepo: "https://github.com/Peiiii/nextclaw",
218
218
  homepage: "https://nextclaw.io",
219
- featured: false,
220
- publisher: {
221
- id: "nextclaw",
222
- name: "NextClaw",
223
- url: "https://nextclaw.io"
224
- }
219
+ featured: false
225
220
  };
226
221
  };
227
222
  buildReadme = (appName, appId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/app-runtime",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "description": "Standalone micro app runtime and CLI for NextClaw apps.",
6
6
  "type": "module",