@nextclaw/service 0.3.6 → 0.3.8

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.
@@ -173,6 +173,8 @@ var RuntimeUpdateManager = class {
173
173
  blockReason: null,
174
174
  recoveryCommand: null,
175
175
  errorMessage: null,
176
+ failureStage: null,
177
+ diagnosticCommand: null,
176
178
  preferences: { ...state.updatePreferences },
177
179
  ...patch,
178
180
  status
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-update.manager.js","names":[],"sources":["../../src/managers/runtime-update.manager.ts"],"sourcesContent":["import type { UpdateManifest, UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\nimport { getPackageVersion } from \"@nextclaw-service/utils/cli.utils.js\";\nimport { resolveEffectiveNpmRuntimeVersion } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeUpdateService, NpmRuntimeAvailableUpdate } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport type { NpmRuntimeReleaseChannel } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport type { NpmRuntimeUpdateState } from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype RuntimeUpdateManagerOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n bundleService: NpmRuntimeBundleService;\n updateService: NpmRuntimeUpdateService;\n resolveManifestUrl: (channel: NpmRuntimeReleaseChannel) => string | null;\n launcherVersion?: string;\n channel: NpmRuntimeReleaseChannel;\n now?: () => Date;\n};\n\ntype NpmRuntimeUpdateActionOptions = {\n apply?: boolean;\n applyAfterDownload?: boolean;\n checkOnly?: boolean;\n onProgress?: (progress: UpdateProgress) => void;\n};\n\nexport class RuntimeUpdateManager {\n private readonly launcherVersion: string;\n private readonly now: () => Date;\n private availableManifest: UpdateManifest | null = null;\n\n constructor(private readonly options: RuntimeUpdateManagerOptions) {\n this.launcherVersion = options.launcherVersion ?? getPackageVersion();\n this.now = options.now ?? (() => new Date());\n this.options.layout.ensureLauncherDirs();\n this.syncStateFromCurrentPointer();\n }\n\n getSnapshot = (): UpdateSnapshot => this.toSnapshotFromState(this.options.stateStore.read(), {\n status: this.options.stateStore.read().downloadedVersion ? \"downloaded\" : \"idle\"\n });\n\n run = async (options: NpmRuntimeUpdateActionOptions = {}): Promise<UpdateSnapshot> => {\n if (options.apply) {\n return this.applyDownloadedUpdate();\n }\n\n const applyAfterDownload = options.applyAfterDownload ?? true;\n const checkedSnapshot = await this.checkForUpdate();\n if (options.checkOnly) {\n return checkedSnapshot;\n }\n if (applyAfterDownload && checkedSnapshot.status === \"downloaded\") {\n return this.applyDownloadedUpdate();\n }\n if (checkedSnapshot.status !== \"update-available\") {\n return checkedSnapshot;\n }\n const downloadedSnapshot = await this.downloadUpdate(options.onProgress);\n if (!applyAfterDownload || downloadedSnapshot.status !== \"downloaded\") {\n return downloadedSnapshot;\n }\n return this.applyDownloadedUpdate();\n };\n\n checkForUpdate = async (): Promise<UpdateSnapshot> => {\n const manifestUrl = this.options.resolveManifestUrl(this.options.channel);\n if (!this.options.updateService.hasSignatureVerifier()) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"signature-verification-unavailable\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY or NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH\",\n errorMessage: \"Runtime bundle updates require a configured update public key.\"\n });\n }\n if (!manifestUrl) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_MANIFEST_URL or NEXTCLAW_UPDATE_MANIFEST_BASE_URL\",\n errorMessage: \"Runtime bundle update manifest URL is not configured.\"\n });\n }\n\n const checkedAt = this.now().toISOString();\n const state = this.options.stateStore.update((current) => ({\n ...current,\n channel: this.options.channel,\n lastUpdateCheckAt: checkedAt\n }));\n const availableUpdate = await this.options.updateService.checkForUpdate(manifestUrl, state.currentVersion, state.badVersions);\n return this.toSnapshotAfterCheck(availableUpdate, this.options.stateStore.read());\n };\n\n downloadUpdate = async (onProgress?: (progress: UpdateProgress) => void): Promise<UpdateSnapshot> => {\n const manifest = this.availableManifest ?? await this.ensureAvailableManifest();\n const downloaded = await this.options.updateService.downloadAndInstallUpdate(manifest, onProgress);\n const state = this.options.stateStore.update((current) => ({\n ...current,\n downloadedVersion: downloaded.downloadedVersion,\n downloadedReleaseNotesUrl: downloaded.manifest.releaseNotesUrl\n }));\n await this.options.bundleService.pruneRetainedArtifacts();\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: downloaded.downloadedVersion,\n downloadedVersion: downloaded.downloadedVersion,\n minimumHostVersion: downloaded.manifest.minimumLauncherVersion,\n releaseNotesUrl: downloaded.manifest.releaseNotesUrl,\n canApplyInApp: true,\n requiresRestart: false\n });\n };\n\n applyDownloadedUpdate = (): UpdateSnapshot => {\n const downloadedVersion = this.options.stateStore.read().downloadedVersion?.trim();\n if (!downloadedVersion) {\n throw new Error(\"No downloaded npm runtime update is ready to apply.\");\n }\n this.options.bundleService.activateVersion(downloadedVersion);\n this.availableManifest = null;\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"restart-required\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null,\n canApplyInApp: false,\n requiresRestart: true\n });\n };\n\n private ensureAvailableManifest = async (): Promise<UpdateManifest> => {\n const snapshot = await this.checkForUpdate();\n if (!this.availableManifest) {\n if (snapshot.downloadedVersion) {\n throw new Error(`Version ${snapshot.downloadedVersion} has already been downloaded and is ready to apply.`);\n }\n throw new Error(\"No npm runtime update is currently available.\");\n }\n return this.availableManifest;\n };\n\n private toSnapshotAfterCheck = (\n availableUpdate: NpmRuntimeAvailableUpdate | null,\n state: NpmRuntimeUpdateState\n ): UpdateSnapshot => {\n if (state.downloadedVersion) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : this.availableManifest;\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.latestVersion : state.downloadedVersion,\n minimumHostVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.minimumLauncherVersion : null,\n canApplyInApp: true,\n requiresRestart: false\n });\n }\n if (!availableUpdate) {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"up-to-date\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null\n });\n }\n if (availableUpdate.kind === \"host-update-required\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"blocked\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n blockReason: \"host-too-old\",\n recoveryCommand: \"npm install -g nextclaw@latest\",\n errorMessage: `NextClaw npm launcher ${this.launcherVersion} is too old for runtime bundle ${availableUpdate.manifest.latestVersion}.`\n });\n }\n if (availableUpdate.kind === \"quarantined-bad-version\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"failed\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n errorMessage: `Version ${availableUpdate.manifest.latestVersion} was quarantined after a failed launch.`\n });\n }\n this.availableManifest = availableUpdate.manifest;\n return this.toSnapshotFromState(state, {\n status: \"update-available\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl\n });\n };\n\n private syncStateFromCurrentPointer = (): void => {\n const currentPointer = this.options.layout.readCurrentPointer();\n const effectiveCurrentVersion = resolveEffectiveNpmRuntimeVersion({\n launcherVersion: this.launcherVersion,\n currentBundleVersion: currentPointer?.version ?? null\n });\n if (!effectiveCurrentVersion) {\n return;\n }\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion: effectiveCurrentVersion\n }));\n };\n\n private toSnapshotFromState = (\n state: NpmRuntimeUpdateState,\n patch: Partial<UpdateSnapshot> & Pick<UpdateSnapshot, \"status\">\n ): UpdateSnapshot => {\n const hasDownloadedVersion = Boolean(state.downloadedVersion);\n const { status } = patch;\n return {\n installationKind: \"npm-runtime-bundle\",\n channel: state.channel,\n hostVersion: this.launcherVersion,\n currentVersion: state.currentVersion,\n availableVersion: null,\n downloadedVersion: state.downloadedVersion,\n minimumHostVersion: null,\n releaseNotesUrl: state.downloadedReleaseNotesUrl,\n lastCheckedAt: state.lastUpdateCheckAt,\n progress: null,\n canAutoDownload: state.updatePreferences.autoDownload,\n canApplyInApp: hasDownloadedVersion,\n requiresRestart: false,\n blockReason: null,\n recoveryCommand: null,\n errorMessage: null,\n preferences: { ...state.updatePreferences },\n ...patch,\n status\n };\n };\n}\n"],"mappings":";;;;AA4BA,IAAa,uBAAb,MAAkC;CAChC;CACA;CACA,oBAAmD;CAEnD,YAAY,SAAuD;AAAtC,OAAA,UAAA;AAC3B,OAAK,kBAAkB,QAAQ,mBAAmB,mBAAmB;AACrE,OAAK,MAAM,QAAQ,8BAAc,IAAI,MAAM;AAC3C,OAAK,QAAQ,OAAO,oBAAoB;AACxC,OAAK,6BAA6B;;CAGpC,oBAAoC,KAAK,oBAAoB,KAAK,QAAQ,WAAW,MAAM,EAAE,EAC3F,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gBAAgB;GACjB,EAAE;;CAGL,uBACE,OACA,UACmB;EACnB,MAAM,uBAAuB,QAAQ,MAAM,kBAAkB;EAC7D,MAAM,EAAE,WAAW;AACnB,SAAO;GACL,kBAAkB;GAClB,SAAS,MAAM;GACf,aAAa,KAAK;GAClB,gBAAgB,MAAM;GACtB,kBAAkB;GAClB,mBAAmB,MAAM;GACzB,oBAAoB;GACpB,iBAAiB,MAAM;GACvB,eAAe,MAAM;GACrB,UAAU;GACV,iBAAiB,MAAM,kBAAkB;GACzC,eAAe;GACf,iBAAiB;GACjB,aAAa;GACb,iBAAiB;GACjB,cAAc;GACd,aAAa,EAAE,GAAG,MAAM,mBAAmB;GAC3C,GAAG;GACH;GACD"}
1
+ {"version":3,"file":"runtime-update.manager.js","names":[],"sources":["../../src/managers/runtime-update.manager.ts"],"sourcesContent":["import type { UpdateManifest, UpdateProgress, UpdateSnapshot } from \"@nextclaw/kernel\";\nimport { getPackageVersion } from \"@nextclaw-service/utils/cli.utils.js\";\nimport { resolveEffectiveNpmRuntimeVersion } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeUpdateService, NpmRuntimeAvailableUpdate } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport type { NpmRuntimeReleaseChannel } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport type { NpmRuntimeUpdateState } from \"@nextclaw-service/types/npm-runtime-bundle.types.js\";\n\ntype RuntimeUpdateManagerOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n bundleService: NpmRuntimeBundleService;\n updateService: NpmRuntimeUpdateService;\n resolveManifestUrl: (channel: NpmRuntimeReleaseChannel) => string | null;\n launcherVersion?: string;\n channel: NpmRuntimeReleaseChannel;\n now?: () => Date;\n};\n\ntype NpmRuntimeUpdateActionOptions = {\n apply?: boolean;\n applyAfterDownload?: boolean;\n checkOnly?: boolean;\n onProgress?: (progress: UpdateProgress) => void;\n};\n\nexport class RuntimeUpdateManager {\n private readonly launcherVersion: string;\n private readonly now: () => Date;\n private availableManifest: UpdateManifest | null = null;\n\n constructor(private readonly options: RuntimeUpdateManagerOptions) {\n this.launcherVersion = options.launcherVersion ?? getPackageVersion();\n this.now = options.now ?? (() => new Date());\n this.options.layout.ensureLauncherDirs();\n this.syncStateFromCurrentPointer();\n }\n\n getSnapshot = (): UpdateSnapshot => this.toSnapshotFromState(this.options.stateStore.read(), {\n status: this.options.stateStore.read().downloadedVersion ? \"downloaded\" : \"idle\"\n });\n\n run = async (options: NpmRuntimeUpdateActionOptions = {}): Promise<UpdateSnapshot> => {\n if (options.apply) {\n return this.applyDownloadedUpdate();\n }\n\n const applyAfterDownload = options.applyAfterDownload ?? true;\n const checkedSnapshot = await this.checkForUpdate();\n if (options.checkOnly) {\n return checkedSnapshot;\n }\n if (applyAfterDownload && checkedSnapshot.status === \"downloaded\") {\n return this.applyDownloadedUpdate();\n }\n if (checkedSnapshot.status !== \"update-available\") {\n return checkedSnapshot;\n }\n const downloadedSnapshot = await this.downloadUpdate(options.onProgress);\n if (!applyAfterDownload || downloadedSnapshot.status !== \"downloaded\") {\n return downloadedSnapshot;\n }\n return this.applyDownloadedUpdate();\n };\n\n checkForUpdate = async (): Promise<UpdateSnapshot> => {\n const manifestUrl = this.options.resolveManifestUrl(this.options.channel);\n if (!this.options.updateService.hasSignatureVerifier()) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"signature-verification-unavailable\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY or NEXTCLAW_UPDATE_BUNDLE_PUBLIC_KEY_PATH\",\n errorMessage: \"Runtime bundle updates require a configured update public key.\"\n });\n }\n if (!manifestUrl) {\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"blocked\",\n installationKind: \"npm-runtime-bundle\",\n blockReason: \"unsupported-installation\",\n recoveryCommand: \"Set NEXTCLAW_UPDATE_MANIFEST_URL or NEXTCLAW_UPDATE_MANIFEST_BASE_URL\",\n errorMessage: \"Runtime bundle update manifest URL is not configured.\"\n });\n }\n\n const checkedAt = this.now().toISOString();\n const state = this.options.stateStore.update((current) => ({\n ...current,\n channel: this.options.channel,\n lastUpdateCheckAt: checkedAt\n }));\n const availableUpdate = await this.options.updateService.checkForUpdate(manifestUrl, state.currentVersion, state.badVersions);\n return this.toSnapshotAfterCheck(availableUpdate, this.options.stateStore.read());\n };\n\n downloadUpdate = async (onProgress?: (progress: UpdateProgress) => void): Promise<UpdateSnapshot> => {\n const manifest = this.availableManifest ?? await this.ensureAvailableManifest();\n const downloaded = await this.options.updateService.downloadAndInstallUpdate(manifest, onProgress);\n const state = this.options.stateStore.update((current) => ({\n ...current,\n downloadedVersion: downloaded.downloadedVersion,\n downloadedReleaseNotesUrl: downloaded.manifest.releaseNotesUrl\n }));\n await this.options.bundleService.pruneRetainedArtifacts();\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: downloaded.downloadedVersion,\n downloadedVersion: downloaded.downloadedVersion,\n minimumHostVersion: downloaded.manifest.minimumLauncherVersion,\n releaseNotesUrl: downloaded.manifest.releaseNotesUrl,\n canApplyInApp: true,\n requiresRestart: false\n });\n };\n\n applyDownloadedUpdate = (): UpdateSnapshot => {\n const downloadedVersion = this.options.stateStore.read().downloadedVersion?.trim();\n if (!downloadedVersion) {\n throw new Error(\"No downloaded npm runtime update is ready to apply.\");\n }\n this.options.bundleService.activateVersion(downloadedVersion);\n this.availableManifest = null;\n return this.toSnapshotFromState(this.options.stateStore.read(), {\n status: \"restart-required\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null,\n canApplyInApp: false,\n requiresRestart: true\n });\n };\n\n private ensureAvailableManifest = async (): Promise<UpdateManifest> => {\n const snapshot = await this.checkForUpdate();\n if (!this.availableManifest) {\n if (snapshot.downloadedVersion) {\n throw new Error(`Version ${snapshot.downloadedVersion} has already been downloaded and is ready to apply.`);\n }\n throw new Error(\"No npm runtime update is currently available.\");\n }\n return this.availableManifest;\n };\n\n private toSnapshotAfterCheck = (\n availableUpdate: NpmRuntimeAvailableUpdate | null,\n state: NpmRuntimeUpdateState\n ): UpdateSnapshot => {\n if (state.downloadedVersion) {\n this.availableManifest = availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest : this.availableManifest;\n return this.toSnapshotFromState(state, {\n status: \"downloaded\",\n availableVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.latestVersion : state.downloadedVersion,\n minimumHostVersion: availableUpdate?.kind === \"runtime-bundle-update\" ? availableUpdate.manifest.minimumLauncherVersion : null,\n canApplyInApp: true,\n requiresRestart: false\n });\n }\n if (!availableUpdate) {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"up-to-date\",\n availableVersion: null,\n downloadedVersion: null,\n releaseNotesUrl: null\n });\n }\n if (availableUpdate.kind === \"host-update-required\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"blocked\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n blockReason: \"host-too-old\",\n recoveryCommand: \"npm install -g nextclaw@latest\",\n errorMessage: `NextClaw npm launcher ${this.launcherVersion} is too old for runtime bundle ${availableUpdate.manifest.latestVersion}.`\n });\n }\n if (availableUpdate.kind === \"quarantined-bad-version\") {\n this.availableManifest = null;\n return this.toSnapshotFromState(state, {\n status: \"failed\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl,\n errorMessage: `Version ${availableUpdate.manifest.latestVersion} was quarantined after a failed launch.`\n });\n }\n this.availableManifest = availableUpdate.manifest;\n return this.toSnapshotFromState(state, {\n status: \"update-available\",\n availableVersion: availableUpdate.manifest.latestVersion,\n minimumHostVersion: availableUpdate.manifest.minimumLauncherVersion,\n releaseNotesUrl: availableUpdate.manifest.releaseNotesUrl\n });\n };\n\n private syncStateFromCurrentPointer = (): void => {\n const currentPointer = this.options.layout.readCurrentPointer();\n const effectiveCurrentVersion = resolveEffectiveNpmRuntimeVersion({\n launcherVersion: this.launcherVersion,\n currentBundleVersion: currentPointer?.version ?? null\n });\n if (!effectiveCurrentVersion) {\n return;\n }\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion: effectiveCurrentVersion\n }));\n };\n\n private toSnapshotFromState = (\n state: NpmRuntimeUpdateState,\n patch: Partial<UpdateSnapshot> & Pick<UpdateSnapshot, \"status\">\n ): UpdateSnapshot => {\n const hasDownloadedVersion = Boolean(state.downloadedVersion);\n const { status } = patch;\n return {\n installationKind: \"npm-runtime-bundle\",\n channel: state.channel,\n hostVersion: this.launcherVersion,\n currentVersion: state.currentVersion,\n availableVersion: null,\n downloadedVersion: state.downloadedVersion,\n minimumHostVersion: null,\n releaseNotesUrl: state.downloadedReleaseNotesUrl,\n lastCheckedAt: state.lastUpdateCheckAt,\n progress: null,\n canAutoDownload: state.updatePreferences.autoDownload,\n canApplyInApp: hasDownloadedVersion,\n requiresRestart: false,\n blockReason: null,\n recoveryCommand: null,\n errorMessage: null,\n failureStage: null,\n diagnosticCommand: null,\n preferences: { ...state.updatePreferences },\n ...patch,\n status\n };\n };\n}\n"],"mappings":";;;;AA4BA,IAAa,uBAAb,MAAkC;CAChC;CACA;CACA,oBAAmD;CAEnD,YAAY,SAAuD;AAAtC,OAAA,UAAA;AAC3B,OAAK,kBAAkB,QAAQ,mBAAmB,mB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AAoB;EAC/D,MAAM,0BAA0B,kCAAkC;GAChE,iBAAiB,KAAK;GACtB,sBAAsB,gBAAgB,WAAW;GAClD,CAAC;AACF,MAAI,CAAC,wBACH;AAEF,OAAK,QAAQ,WAAW,QAAQ,WAAW;GACzC,GAAG;GACH,gBAAgB;GACjB,EAAE;;CAGL,uBACE,OACA,UACmB;EACnB,MAAM,uBAAuB,QAAQ,MAAM,kBAAkB;EAC7D,MAAM,EAAE,WAAW;AACnB,SAAO;GACL,kBAAkB;GAClB,SAAS,MAAM;GACf,aAAa,KAAK;GAClB,gBAAgB,MAAM;GACtB,kBAAkB;GAClB,mBAAmB,MAAM;GACzB,oBAAoB;GACpB,iBAAiB,MAAM;GACvB,eAAe,MAAM;GACrB,UAAU;GACV,iBAAiB,MAAM,kBAAkB;GACzC,eAAe;GACf,iBAAiB;GACjB,aAAa;GACb,iBAAiB;GACjB,cAAc;GACd,cAAc;GACd,mBAAmB;GACnB,aAAa,EAAE,GAAG,MAAM,mBAAmB;GAC3C,GAAG;GACH;GACD"}
@@ -1,11 +1,12 @@
1
1
  import { RequestRestartParams } from "../../types/cli.types.js";
2
- import { Config } from "@nextclaw/core";
2
+ import { AppLogger, Config } from "@nextclaw/core";
3
3
  import { UiRuntimeUpdateHost } from "@nextclaw/server";
4
4
  import { EventBus, UpdatePreferences, UpdateSnapshot } from "@nextclaw/shared";
5
5
 
6
6
  //#region src/services/runtime/npm-runtime-update-host.service.d.ts
7
7
  type NpmRuntimeUpdateHostDeps = {
8
8
  eventBus: EventBus;
9
+ logger?: Pick<AppLogger, "error">;
9
10
  requestRestart: (params: RequestRestartParams) => Promise<void>;
10
11
  uiConfig: Pick<Config["ui"], "port">;
11
12
  applyRestartMode: "managed-service-restart" | "manual-process-restart";
@@ -21,6 +22,7 @@ declare class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {
21
22
  private snapshot;
22
23
  private activeTask;
23
24
  private automaticSyncStarted;
25
+ private readonly logger;
24
26
  constructor(deps: NpmRuntimeUpdateHostDeps);
25
27
  getState: () => Promise<UpdateSnapshot>;
26
28
  checkForUpdates: () => Promise<UpdateSnapshot>;
@@ -34,6 +36,7 @@ declare class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {
34
36
  private runDownloadTask;
35
37
  private createManager;
36
38
  private toFailedSnapshot;
39
+ private describeFailure;
37
40
  private setSnapshot;
38
41
  }
39
42
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-host.service.d.ts","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"mappings":";;;;;;KAyBK,wBAAA;EACH,QAAA,EAAU,QAAA;EACV,cAAA,GAAiB,MAAA,EAAQ,oBAAA,KAAyB,OAAA;EAClD,QAAA,EAAU,IAAA,CAAK,MAAA;EACf,gBAAA;AAAA;AAAA,cAGW,oBAAA,YAAgC,mBAAA;EAAA,iBAWd,IAAA;EAAA,iBAVZ,MAAA;EAAA,iBACA,MAAA;EAAA,iBACA,eAAA;EAAA,iBACA,UAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;EAAA,QACT,QAAA;EAAA,QACA,UAAA;EAAA,QACA,oBAAA;cAEqB,IAAA,EAAM,wBAAA;EAyBnC,QAAA,QAAqB,OAAA,CAAQ,cAAA;EAK7B,eAAA,QAA4B,OAAA,CAAQ,cAAA;EAIpC,cAAA,QAA2B,OAAA,CAAQ,cAAA;EAInC,qBAAA,QAAkC,OAAA,CAAQ,cAAA;EAkC1C,iBAAA,GAA2B,WAAA,EAAa,OAAA,CAAQ,iBAAA,MAAqB,OAAA,CAAQ,cAAA;EAe7E,aAAA,GAAuB,OAAA,EAAS,cAAA,gBAA4B,OAAA,CAAQ,cAAA;EAAA,QAY5D,kBAAA;EAAA,QAeA,UAAA;EAAA,QA0BA,aAAA;EAAA,QAsBA,eAAA;EAAA,QAYA,aAAA;EAAA,QAYA,gBAAA;EAAA,QASA,WAAA;AAAA"}
1
+ {"version":3,"file":"npm-runtime-update-host.service.d.ts","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"mappings":";;;;;;KA2BK,wBAAA;EACH,QAAA,EAAU,QAAA;EACV,MAAA,GAAS,IAAA,CAAK,SAAA;EACd,cAAA,GAAiB,MAAA,EAAQ,oBAAA,KAAyB,OAAA;EAClD,QAAA,EAAU,IAAA,CAAK,MAAA;EACf,gBAAA;AAAA;AAAA,cAGW,oBAAA,YAAgC,mBAAA;EAAA,iBAYd,IAAA;EAAA,iBAXZ,MAAA;EAAA,iBACA,MAAA;EAAA,iBACA,eAAA;EAAA,iBACA,UAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;EAAA,QACT,QAAA;EAAA,QACA,UAAA;EAAA,QACA,oBAAA;EAAA,iBACS,MAAA;cAEY,IAAA,EAAM,wBAAA;EA0BnC,QAAA,QAAqB,OAAA,CAAQ,cAAA;EAK7B,eAAA,QAA4B,OAAA,CAAQ,cAAA;EAIpC,cAAA,QAA2B,OAAA,CAAQ,cAAA;EAInC,qBAAA,QAAkC,OAAA,CAAQ,cAAA;EAkC1C,iBAAA,GAA2B,WAAA,EAAa,OAAA,CAAQ,iBAAA,MAAqB,OAAA,CAAQ,cAAA;EAe7E,aAAA,GAAuB,OAAA,EAAS,cAAA,gBAA4B,OAAA,CAAQ,cAAA;EAAA,QAY5D,kBAAA;EAAA,QAeA,UAAA;EAAA,QA0BA,aAAA;EAAA,QAsBA,eAAA;EAAA,QAYA,aAAA;EAAA,QAYA,gBAAA;EAAA,QAaA,eAAA;EAAA,QAgBA,WAAA;AAAA"}
@@ -6,6 +6,7 @@ import { NpmRuntimeUpdateSourceService } from "./npm-runtime-update-source.servi
6
6
  import { NpmRuntimeUpdateStateStore } from "../../stores/npm-runtime-update-state.store.js";
7
7
  import { NextclawDistributionService } from "./nextclaw-distribution.service.js";
8
8
  import { requestManagedServiceRestart } from "../ui/service-remote-access.service.js";
9
+ import { getAppLogger } from "@nextclaw/core";
9
10
  import { eventKeys } from "@nextclaw/shared";
10
11
  //#region src/services/runtime/npm-runtime-update-host.service.ts
11
12
  const INITIAL_DOWNLOAD_PROGRESS = {
@@ -23,8 +24,10 @@ var NpmRuntimeUpdateHost = class {
23
24
  snapshot;
24
25
  activeTask = null;
25
26
  automaticSyncStarted = false;
27
+ logger;
26
28
  constructor(deps) {
27
29
  this.deps = deps;
30
+ this.logger = deps.logger ?? getAppLogger("service.runtime-update");
28
31
  const distribution = NextclawDistributionService.get();
29
32
  this.source = new NpmRuntimeUpdateSourceService({ packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath });
30
33
  this.layout = new NpmRuntimeBundleLayoutStore();
@@ -74,7 +77,7 @@ var NpmRuntimeUpdateHost = class {
74
77
  });
75
78
  return this.snapshot;
76
79
  } catch (error) {
77
- this.setSnapshot(this.toFailedSnapshot(error));
80
+ this.setSnapshot(this.toFailedSnapshot("apply", error));
78
81
  throw error;
79
82
  }
80
83
  };
@@ -121,7 +124,7 @@ var NpmRuntimeUpdateHost = class {
121
124
  this.setSnapshot(checkedSnapshot);
122
125
  if (options.autoDownload && checkedSnapshot.status === "update-available") await this.runDownloadTask();
123
126
  } catch (error) {
124
- this.setSnapshot(this.toFailedSnapshot(error));
127
+ this.setSnapshot(this.toFailedSnapshot("check", error));
125
128
  } finally {
126
129
  this.activeTask = null;
127
130
  }
@@ -142,7 +145,7 @@ var NpmRuntimeUpdateHost = class {
142
145
  try {
143
146
  await this.runDownloadTask();
144
147
  } catch (error) {
145
- this.setSnapshot(this.toFailedSnapshot(error));
148
+ this.setSnapshot(this.toFailedSnapshot("download", error));
146
149
  } finally {
147
150
  this.activeTask = null;
148
151
  }
@@ -173,14 +176,32 @@ var NpmRuntimeUpdateHost = class {
173
176
  channel
174
177
  });
175
178
  };
176
- toFailedSnapshot = (error) => {
179
+ toFailedSnapshot = (failureStage, error) => {
180
+ const errorMessage = this.describeFailure(error);
181
+ this.logger.error("runtime update operation failed", {
182
+ failureStage,
183
+ errorMessage
184
+ }, error);
177
185
  return {
178
186
  ...this.createManager().getSnapshot(),
179
187
  status: "failed",
180
188
  progress: null,
181
- errorMessage: error instanceof Error ? error.message : String(error ?? "Unknown error")
189
+ errorMessage,
190
+ failureStage,
191
+ diagnosticCommand: "nextclaw logs path"
182
192
  };
183
193
  };
194
+ describeFailure = (error) => {
195
+ const messages = [];
196
+ let cause = error;
197
+ while (cause instanceof Error && messages.length < 4) {
198
+ const message = cause.message.trim();
199
+ if (message && messages.at(-1) !== message) messages.push(message);
200
+ cause = cause.cause;
201
+ }
202
+ if (messages.length === 0) messages.push(String(error ?? "Unknown error"));
203
+ return messages.join(": ");
204
+ };
184
205
  setSnapshot = (snapshot) => {
185
206
  this.snapshot = snapshot;
186
207
  this.deps.eventBus.emit(eventKeys.runtimeUpdateSnapshot, snapshot, { source: "backend" });
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-update-host.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"sourcesContent":["import type { Config } from \"@nextclaw/core\";\nimport {\n eventKeys,\n type EventBus,\n type UpdatePreferences,\n type UpdateProgress,\n type UpdateSnapshot,\n} from \"@nextclaw/shared\";\nimport type { UiRuntimeUpdateHost } from \"@nextclaw/server\";\nimport { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport { requestManagedServiceRestart } from \"@nextclaw-service/services/ui/service-remote-access.service.js\";\nimport type { RequestRestartParams } from \"@nextclaw-service/types/cli.types.js\";\n\nconst INITIAL_DOWNLOAD_PROGRESS: UpdateProgress = {\n downloadedBytes: 0,\n totalBytes: null,\n percent: null\n};\n\ntype NpmRuntimeUpdateHostDeps = {\n eventBus: EventBus;\n requestRestart: (params: RequestRestartParams) => Promise<void>;\n uiConfig: Pick<Config[\"ui\"], \"port\">;\n applyRestartMode: \"managed-service-restart\" | \"manual-process-restart\";\n};\n\nexport class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {\n private readonly source: NpmRuntimeUpdateSourceService;\n private readonly layout: NpmRuntimeBundleLayoutStore;\n private readonly launcherVersion: string;\n private readonly stateStore: NpmRuntimeUpdateStateStore;\n private readonly bundleService: NpmRuntimeBundleService;\n private readonly updateService: NpmRuntimeUpdateService;\n private snapshot: UpdateSnapshot;\n private activeTask: Promise<void> | null = null;\n private automaticSyncStarted = false;\n\n constructor(private readonly deps: NpmRuntimeUpdateHostDeps) {\n const distribution = NextclawDistributionService.get();\n this.source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath\n });\n this.layout = new NpmRuntimeBundleLayoutStore();\n this.launcherVersion = distribution.version;\n this.stateStore = new NpmRuntimeUpdateStateStore(this.layout.getStatePath(), {\n defaultChannel: this.source.resolveChannel(undefined, this.launcherVersion)\n });\n this.bundleService = new NpmRuntimeBundleService({\n layout: this.layout,\n stateStore: this.stateStore,\n launcherVersion: this.launcherVersion\n });\n this.updateService = new NpmRuntimeUpdateService({\n layout: this.layout,\n bundleService: this.bundleService,\n launcherVersion: this.launcherVersion,\n bundlePublicKey: this.source.resolveBundlePublicKey() ?? undefined\n });\n this.snapshot = this.createManager().getSnapshot();\n this.startAutomaticSync();\n }\n\n getState = async (): Promise<UpdateSnapshot> => {\n this.startAutomaticSync();\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n return this.startCheck({ autoDownload: false });\n };\n\n downloadUpdate = async (): Promise<UpdateSnapshot> => {\n return this.startDownload();\n };\n\n applyDownloadedUpdate = async (): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n return this.snapshot;\n }\n\n this.setSnapshot({\n ...this.snapshot,\n status: \"applying\",\n progress: null,\n errorMessage: null\n });\n try {\n const snapshot = this.createManager().applyDownloadedUpdate();\n this.setSnapshot(\n this.deps.applyRestartMode === \"managed-service-restart\"\n ? snapshot\n : {\n ...snapshot,\n recoveryCommand: \"Restart this NextClaw process to launch the downloaded runtime.\"\n },\n );\n if (this.deps.applyRestartMode === \"managed-service-restart\") {\n await requestManagedServiceRestart(this.deps.requestRestart, {\n reason: \"runtime update apply\",\n uiPort: this.deps.uiConfig.port\n });\n }\n return this.snapshot;\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(error));\n throw error;\n }\n };\n\n updatePreferences = async (preferences: Partial<UpdatePreferences>): Promise<UpdateSnapshot> => {\n const nextState = this.stateStore.update((current) => ({\n ...current,\n updatePreferences: {\n ...current.updatePreferences,\n ...preferences\n }\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n if (nextState.updatePreferences.automaticChecks) {\n this.startAutomaticSync({ force: true });\n }\n return this.snapshot;\n };\n\n updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n if (nextState.updatePreferences.automaticChecks) {\n return this.startCheck({ autoDownload: nextState.updatePreferences.autoDownload });\n }\n return this.snapshot;\n };\n\n private startAutomaticSync = (options: { force?: boolean } = {}): void => {\n if (this.activeTask) {\n return;\n }\n if (this.automaticSyncStarted && !options.force) {\n return;\n }\n this.automaticSyncStarted = true;\n const state = this.stateStore.read();\n if (!state.updatePreferences.automaticChecks || state.downloadedVersion) {\n return;\n }\n void this.startCheck({ autoDownload: state.updatePreferences.autoDownload });\n };\n\n private startCheck = async (options: { autoDownload: boolean }): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"checking\",\n progress: null,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n const checkedSnapshot = await this.createManager().checkForUpdate();\n this.setSnapshot(checkedSnapshot);\n if (options.autoDownload && checkedSnapshot.status === \"update-available\") {\n await this.runDownloadTask();\n }\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private startDownload = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"downloading\",\n progress: INITIAL_DOWNLOAD_PROGRESS,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n await this.runDownloadTask();\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private runDownloadTask = async (): Promise<void> => {\n const downloadedSnapshot = await this.createManager().downloadUpdate((progress) => {\n this.setSnapshot({\n ...this.snapshot,\n status: \"downloading\",\n progress,\n errorMessage: null\n });\n });\n this.setSnapshot(downloadedSnapshot);\n };\n\n private createManager = (channel = this.stateStore.read().channel): RuntimeUpdateManager => {\n return new RuntimeUpdateManager({\n layout: this.layout,\n stateStore: this.stateStore,\n bundleService: this.bundleService,\n updateService: this.updateService,\n resolveManifestUrl: (resolvedChannel) => this.source.resolveManifestUrl(resolvedChannel),\n launcherVersion: this.launcherVersion,\n channel\n });\n };\n\n private toFailedSnapshot = (error: unknown): UpdateSnapshot => {\n return {\n ...this.createManager().getSnapshot(),\n status: \"failed\",\n progress: null,\n errorMessage: error instanceof Error ? error.message : String(error ?? \"Unknown error\")\n };\n };\n\n private setSnapshot = (snapshot: UpdateSnapshot): UpdateSnapshot => {\n this.snapshot = snapshot;\n this.deps.eventBus.emit(eventKeys.runtimeUp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a;GACrC,QAAQ;GACR,UAAU;GACV,cAAc,iBAAiB,QAAQ,MAAM,UAAU,OAAO,SAAS,gBAAgB;GACxF;;CAGH,eAAuB,aAA6C;AAClE,OAAK,WAAW;AAChB,OAAK,KAAK,SAAS,KAAK,UAAU,uBAAuB,UAAU,EACjE,QAAQ,WACT,CAAC;AACF,SAAO"}
1
+ {"version":3,"file":"npm-runtime-update-host.service.js","names":[],"sources":["../../../src/services/runtime/npm-runtime-update-host.service.ts"],"sourcesContent":["import type { Config } from \"@nextclaw/core\";\nimport { getAppLogger, type AppLogger } from \"@nextclaw/core\";\nimport {\n eventKeys,\n type EventBus,\n type UpdateFailureStage,\n type UpdatePreferences,\n type UpdateProgress,\n type UpdateSnapshot,\n} from \"@nextclaw/shared\";\nimport type { UiRuntimeUpdateHost } from \"@nextclaw/server\";\nimport { NpmRuntimeBundleLayoutStore } from \"@nextclaw-service/stores/npm-runtime-bundle-layout.store.js\";\nimport { NpmRuntimeBundleService } from \"@nextclaw-service/services/runtime/npm-runtime-bundle.service.js\";\nimport { RuntimeUpdateManager } from \"@nextclaw-service/managers/runtime-update.manager.js\";\nimport { NpmRuntimeUpdateService } from \"@nextclaw-service/services/runtime/npm-runtime-update.service.js\";\nimport { NpmRuntimeUpdateSourceService } from \"@nextclaw-service/services/runtime/npm-runtime-update-source.service.js\";\nimport { NpmRuntimeUpdateStateStore } from \"@nextclaw-service/stores/npm-runtime-update-state.store.js\";\nimport { NextclawDistributionService } from \"@nextclaw-service/services/runtime/nextclaw-distribution.service.js\";\nimport { requestManagedServiceRestart } from \"@nextclaw-service/services/ui/service-remote-access.service.js\";\nimport type { RequestRestartParams } from \"@nextclaw-service/types/cli.types.js\";\n\nconst INITIAL_DOWNLOAD_PROGRESS: UpdateProgress = {\n downloadedBytes: 0,\n totalBytes: null,\n percent: null\n};\n\ntype NpmRuntimeUpdateHostDeps = {\n eventBus: EventBus;\n logger?: Pick<AppLogger, \"error\">;\n requestRestart: (params: RequestRestartParams) => Promise<void>;\n uiConfig: Pick<Config[\"ui\"], \"port\">;\n applyRestartMode: \"managed-service-restart\" | \"manual-process-restart\";\n};\n\nexport class NpmRuntimeUpdateHost implements UiRuntimeUpdateHost {\n private readonly source: NpmRuntimeUpdateSourceService;\n private readonly layout: NpmRuntimeBundleLayoutStore;\n private readonly launcherVersion: string;\n private readonly stateStore: NpmRuntimeUpdateStateStore;\n private readonly bundleService: NpmRuntimeBundleService;\n private readonly updateService: NpmRuntimeUpdateService;\n private snapshot: UpdateSnapshot;\n private activeTask: Promise<void> | null = null;\n private automaticSyncStarted = false;\n private readonly logger: Pick<AppLogger, \"error\">;\n\n constructor(private readonly deps: NpmRuntimeUpdateHostDeps) {\n this.logger = deps.logger ?? getAppLogger(\"service.runtime-update\");\n const distribution = NextclawDistributionService.get();\n this.source = new NpmRuntimeUpdateSourceService({\n packagedPublicKeyPath: distribution.runtimeUpdatePublicKeyPath\n });\n this.layout = new NpmRuntimeBundleLayoutStore();\n this.launcherVersion = distribution.version;\n this.stateStore = new NpmRuntimeUpdateStateStore(this.layout.getStatePath(), {\n defaultChannel: this.source.resolveChannel(undefined, this.launcherVersion)\n });\n this.bundleService = new NpmRuntimeBundleService({\n layout: this.layout,\n stateStore: this.stateStore,\n launcherVersion: this.launcherVersion\n });\n this.updateService = new NpmRuntimeUpdateService({\n layout: this.layout,\n bundleService: this.bundleService,\n launcherVersion: this.launcherVersion,\n bundlePublicKey: this.source.resolveBundlePublicKey() ?? undefined\n });\n this.snapshot = this.createManager().getSnapshot();\n this.startAutomaticSync();\n }\n\n getState = async (): Promise<UpdateSnapshot> => {\n this.startAutomaticSync();\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n return this.startCheck({ autoDownload: false });\n };\n\n downloadUpdate = async (): Promise<UpdateSnapshot> => {\n return this.startDownload();\n };\n\n applyDownloadedUpdate = async (): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n return this.snapshot;\n }\n\n this.setSnapshot({\n ...this.snapshot,\n status: \"applying\",\n progress: null,\n errorMessage: null\n });\n try {\n const snapshot = this.createManager().applyDownloadedUpdate();\n this.setSnapshot(\n this.deps.applyRestartMode === \"managed-service-restart\"\n ? snapshot\n : {\n ...snapshot,\n recoveryCommand: \"Restart this NextClaw process to launch the downloaded runtime.\"\n },\n );\n if (this.deps.applyRestartMode === \"managed-service-restart\") {\n await requestManagedServiceRestart(this.deps.requestRestart, {\n reason: \"runtime update apply\",\n uiPort: this.deps.uiConfig.port\n });\n }\n return this.snapshot;\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"apply\", error));\n throw error;\n }\n };\n\n updatePreferences = async (preferences: Partial<UpdatePreferences>): Promise<UpdateSnapshot> => {\n const nextState = this.stateStore.update((current) => ({\n ...current,\n updatePreferences: {\n ...current.updatePreferences,\n ...preferences\n }\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n if (nextState.updatePreferences.automaticChecks) {\n this.startAutomaticSync({ force: true });\n }\n return this.snapshot;\n };\n\n updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n if (nextState.updatePreferences.automaticChecks) {\n return this.startCheck({ autoDownload: nextState.updatePreferences.autoDownload });\n }\n return this.snapshot;\n };\n\n private startAutomaticSync = (options: { force?: boolean } = {}): void => {\n if (this.activeTask) {\n return;\n }\n if (this.automaticSyncStarted && !options.force) {\n return;\n }\n this.automaticSyncStarted = true;\n const state = this.stateStore.read();\n if (!state.updatePreferences.automaticChecks || state.downloadedVersion) {\n return;\n }\n void this.startCheck({ autoDownload: state.updatePreferences.autoDownload });\n };\n\n private startCheck = async (options: { autoDownload: boolean }): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"checking\",\n progress: null,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n const checkedSnapshot = await this.createManager().checkForUpdate();\n this.setSnapshot(checkedSnapshot);\n if (options.autoDownload && checkedSnapshot.status === \"update-available\") {\n await this.runDownloadTask();\n }\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"check\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private startDownload = async (): Promise<UpdateSnapshot> => {\n if (!this.activeTask) {\n this.setSnapshot({\n ...this.createManager().getSnapshot(),\n status: \"downloading\",\n progress: INITIAL_DOWNLOAD_PROGRESS,\n errorMessage: null\n });\n this.activeTask = (async () => {\n try {\n await this.runDownloadTask();\n } catch (error) {\n this.setSnapshot(this.toFailedSnapshot(\"download\", error));\n } finally {\n this.activeTask = null;\n }\n })();\n }\n await this.activeTask;\n return this.snapshot;\n };\n\n private runDownloadTask = async (): Promise<void> => {\n const downloadedSnapshot = await this.createManager().downloadUpdate((progress) => {\n this.setSnapshot({\n ...this.snapshot,\n status: \"downloading\",\n progress,\n errorMessage: null\n });\n });\n this.setSnapshot(downloadedSnapshot);\n };\n\n private createManager = (channel = this.stateStore.read().channel): RuntimeUpdateManager => {\n return new RuntimeUpdateManager({\n layout: this.layout,\n stateStore: this.stateStore,\n bundleService: this.bundleService,\n updateService: this.updateService,\n resolveManifestUrl: (resolvedChannel) => this.source.resolveManifestUrl(resolvedChannel),\n launcherVersion: this.launcherVersion,\n channel\n });\n };\n\n private toFailedSnapshot = (failureStage: UpdateFailureStage, error: unknown): UpdateSnapshot => {\n const errorMessage = this.describeFailure(error);\n this.logger.error(\"runtime update operation failed\", { failureStage, errorMessage }, error);\n return {\n ...this.createManager().getSnapshot(),\n status: \"failed\",\n progress: null,\n errorMessage,\n failureStage,\n diagnosticCommand: \"nextclaw logs path\"\n };\n };\n\n private describeFailure = (error: unknown): string => {\n const messages: string[] = [];\n let cause = error;\n while (cause instanceof Error && messages.length < 4) {\n const message = cause.message.trim();\n if (message && messages.at(-1) !== message) {\n messages.push(message);\n }\n cause = cause.cause;\n }\n if (messages.length === 0) {\n messages.push(String(error ?? \"Unknown error\"));\n }\n return messages.join(\": \");\n };\n\n private setSnapshot = (snapshot: UpdateSnapshot): UpdateSnapshot => {\n this.snapshot = snapshot;\n this.deps.eventBus.emit(eventKeys.runtimeUpdateSnapshot, snapshot, {\n source: \"backend\"\n });\n return snapshot;\n };\n}\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,4BAA4C;CAChD,iBAAiB;CACjB,YAAY;CACZ,SAAS;CACV;AAUD,IAAa,uBAAb,MAAiE;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA,aAA2C;CAC3C,uBAA+B;CAC/B;CAEA,YAAY,MAAiD;AAAhC,OAAA,OAAA;AAC3B,OAAK,SAAS,KAAK,UAAU,aAAa,yBAAyB;EACnE,MAAM,eAAe,4BAA4B,KAAK;AACtD,OAAK,SAAS,IAAI,8BAA8B,EAC9C,uBAAuB,aAAa,4BACrC,CAAC;AACF,OAAK,SAAS,IAAI,6BAA6B;AAC/C,OAAK,kBAAkB,aAAa;AACpC,OAAK,aAAa,IAAI,2BAA2B,KAAK,OAAO,cAAc,EAAE,EAC3E,gBAAgB,KAAK,OAAO,eAAe,KAAA,GAAW,KAAK,gBAAgB,EAC5E,CAAC;AACF,OAAK,gBAAgB,IAAI,wBAAwB;GAC/C,QAAQ,KAAK;GACb,YAAY,KAAK;GACjB,iBAAiB,KAAK;GACvB,CAAC;AACF,OAAK,gBAAgB,IAAI,wBAAwB;GAC/C,QAAQ,KAAK;GACb,eAAe,KAAK;GACpB,iBAAiB,KAAK;GACtB,iBAAiB,KAAK,OAAO,wBAAwB,IAAI,KAAA;GAC1D,CAAC;AACF,OAAK,WAAW,KAAK,eAAe,CAAC,aAAa;AAClD,OAAK,oBAAoB;;CAG3B,WAAW,YAAqC;AAC9C,OAAK,oBAAoB;AACzB,SAAO,KAAK;;CAGd,kBAAkB,YAAqC;AACrD,SAAO,KAAK,WAAW,EAAE,cAAc,OAA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,SAAO,IAAI,qBAAqB;GAC9B,QAAQ,KAAK;GACb,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,eAAe,KAAK;GACpB,qBAAqB,oBAAoB,KAAK,OAAO,mBAAmB,gBAAgB;GACxF,iBAAiB,KAAK;GACtB;GACD,CAAC;;CAGJ,oBAA4B,cAAkC,UAAmC;EAC/F,MAAM,eAAe,KAAK,gBAAgB,MAAM;AAChD,OAAK,OAAO,MAAM,mCAAmC;GAAE;GAAc;GAAc,EAAE,MAAM;AAC3F,SAAO;GACL,GAAG,KAAK,eAAe,CAAC,aAAa;GACrC,QAAQ;GACR,UAAU;GACV;GACA;GACA,mBAAmB;GACpB;;CAGH,mBAA2B,UAA2B;EACpD,MAAM,WAAqB,EAAE;EAC7B,IAAI,QAAQ;AACZ,SAAO,iBAAiB,SAAS,SAAS,SAAS,GAAG;GACpD,MAAM,UAAU,MAAM,QAAQ,MAAM;AACpC,OAAI,WAAW,SAAS,GAAG,GAAG,KAAK,QACjC,UAAS,KAAK,QAAQ;AAExB,WAAQ,MAAM;;AAEhB,MAAI,SAAS,WAAW,EACtB,UAAS,KAAK,OAAO,SAAS,gBAAgB,CAAC;AAEjD,SAAO,SAAS,KAAK,KAAK;;CAG5B,eAAuB,aAA6C;AAClE,OAAK,WAAW;AAChB,OAAK,KAAK,SAAS,KAAK,UAAU,uBAAuB,UAAU,EACjE,QAAQ,WACT,CAAC;AACF,SAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/service",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "private": false,
5
5
  "description": "NextClaw long-running service host and runtime lifecycle.",
6
6
  "type": "module",
@@ -42,31 +42,31 @@
42
42
  "chokidar": "^3.6.0",
43
43
  "commander": "^12.1.0",
44
44
  "jszip": "^3.10.1",
45
- "@nextclaw/channel-extension-discord": "0.2.5",
46
- "@nextclaw/channel-extension-dingtalk": "0.2.5",
47
- "@nextclaw/channel-extension-email": "0.2.5",
48
- "@nextclaw/channel-extension-feishu": "0.2.5",
49
- "@nextclaw/channel-extension-qq": "0.2.4",
50
- "@nextclaw/channel-extension-slack": "0.2.5",
51
- "@nextclaw/channel-extension-telegram": "0.2.5",
52
- "@nextclaw/channel-extension-whatsapp": "0.2.5",
53
- "@nextclaw/core": "0.15.5",
54
- "@nextclaw/channel-extension-weixin": "0.2.5",
55
- "@nextclaw/client-sdk": "0.5.6",
56
- "@nextclaw/mcp": "0.3.5",
45
+ "@nextclaw/channel-extension-qq": "0.2.5",
46
+ "@nextclaw/channel-extension-dingtalk": "0.2.6",
47
+ "@nextclaw/channel-extension-email": "0.2.6",
48
+ "@nextclaw/channel-extension-slack": "0.2.6",
49
+ "@nextclaw/channel-extension-telegram": "0.2.6",
50
+ "@nextclaw/channel-extension-weixin": "0.2.6",
51
+ "@nextclaw/channel-extension-feishu": "0.2.6",
52
+ "@nextclaw/channel-extension-whatsapp": "0.2.6",
53
+ "@nextclaw/mcp": "0.3.6",
54
+ "@nextclaw/kernel": "0.6.8",
57
55
  "@nextclaw/ncp": "0.7.4",
58
- "@nextclaw/kernel": "0.6.6",
59
- "@nextclaw/ncp-agent-runtime": "0.4.4",
56
+ "@nextclaw/core": "0.15.6",
57
+ "@nextclaw/ncp-mcp": "0.2.6",
60
58
  "@nextclaw/nextclaw-hermes-acp-bridge": "0.3.4",
59
+ "@nextclaw/ncp-agent-runtime": "0.4.4",
60
+ "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.3.7",
61
61
  "@nextclaw/ncp-toolkit": "0.6.5",
62
- "@nextclaw/ncp-mcp": "0.2.5",
63
- "@nextclaw/nextclaw-ncp-runtime-http-client": "0.3.4",
64
- "@nextclaw/runtime": "0.4.5",
65
- "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.3.6",
66
- "@nextclaw/remote": "0.3.6",
67
- "@nextclaw/shared": "0.4.4",
68
- "@nextclaw/server": "0.15.6",
69
- "@nextclaw/channel-extension-wecom": "0.2.5"
62
+ "@nextclaw/remote": "0.3.8",
63
+ "@nextclaw/runtime": "0.4.6",
64
+ "@nextclaw/server": "0.15.8",
65
+ "@nextclaw/shared": "0.4.5",
66
+ "@nextclaw/client-sdk": "0.5.8",
67
+ "@nextclaw/channel-extension-wecom": "0.2.6",
68
+ "@nextclaw/channel-extension-discord": "0.2.6",
69
+ "@nextclaw/nextclaw-ncp-runtime-http-client": "0.3.4"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/node": "^20.17.6",