@nextclaw/service 0.3.10 → 0.3.12
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.
|
@@ -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":";;;;;;
|
|
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;EACA,wBAAA;AAAA;AAAA,cAGW,oBAAA,YAAgC,mBAAA;EAAA,iBAad,IAAA;EAAA,iBAZZ,MAAA;EAAA,iBACA,MAAA;EAAA,iBACA,eAAA;EAAA,iBACA,UAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;EAAA,QACT,QAAA;EAAA,QACA,UAAA;EAAA,QACA,mBAAA;EAAA,QACA,OAAA;EAAA,iBACS,MAAA;cAEY,IAAA,EAAM,wBAAA;EAyBnC,QAAA,QAAqB,OAAA,CAAQ,cAAA;EAI7B,eAAA,QAA4B,OAAA,CAAQ,cAAA;EAQpC,cAAA,QAA2B,OAAA,CAAQ,cAAA;EAInC,qBAAA,QAAkC,OAAA,CAAQ,cAAA;EAkC1C,aAAA,GAAuB,OAAA,EAAS,cAAA,gBAA4B,OAAA,CAAQ,cAAA;EAgBpE,KAAA;EAQA,OAAA;EAAA,QAKQ,iBAAA;EAAA,YAUI,wBAAA,CAAA;EAAA,QAIJ,0BAAA;EAAA,QAQA,wBAAA;EAAA,QAOA,UAAA;EAAA,QAuBA,aAAA;EAAA,QAsBA,eAAA;EAAA,QAYA,aAAA;EAAA,QAYA,gBAAA;EAAA,QAaA,eAAA;EAAA,QAgBA,WAAA;AAAA"}
|
|
@@ -7,7 +7,7 @@ import { NpmRuntimeUpdateStateStore } from "../../stores/npm-runtime-update-stat
|
|
|
7
7
|
import { NextclawDistributionService } from "./nextclaw-distribution.service.js";
|
|
8
8
|
import { requestManagedServiceRestart } from "../ui/service-remote-access.service.js";
|
|
9
9
|
import { getAppLogger } from "@nextclaw/core";
|
|
10
|
-
import { AUTOMATIC_UPDATE_CHECK_INTERVAL_MS
|
|
10
|
+
import { AUTOMATIC_UPDATE_CHECK_INTERVAL_MS } from "@nextclaw/kernel";
|
|
11
11
|
import { eventKeys } from "@nextclaw/shared";
|
|
12
12
|
//#region src/services/runtime/npm-runtime-update-host.service.ts
|
|
13
13
|
const INITIAL_DOWNLOAD_PROGRESS = {
|
|
@@ -109,7 +109,7 @@ var NpmRuntimeUpdateHost = class {
|
|
|
109
109
|
};
|
|
110
110
|
runAutomaticCheck = async () => {
|
|
111
111
|
try {
|
|
112
|
-
|
|
112
|
+
await this.startCheck();
|
|
113
113
|
} catch (error) {
|
|
114
114
|
this.logger.error("automatic runtime update check failed", {}, error);
|
|
115
115
|
} finally {
|
|
@@ -122,9 +122,7 @@ var NpmRuntimeUpdateHost = class {
|
|
|
122
122
|
scheduleNextAutomaticCheck = () => {
|
|
123
123
|
if (!this.started) return;
|
|
124
124
|
this.clearAutomaticCheckTimer();
|
|
125
|
-
|
|
126
|
-
const delayMs = remainingDelayMs > 0 ? remainingDelayMs : this.automaticCheckIntervalMs;
|
|
127
|
-
this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, delayMs);
|
|
125
|
+
this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, this.automaticCheckIntervalMs);
|
|
128
126
|
};
|
|
129
127
|
clearAutomaticCheckTimer = () => {
|
|
130
128
|
if (this.automaticCheckTimer) {
|
|
@@ -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 { getAppLogger, type AppLogger } from \"@nextclaw/core\";\nimport {\n AUTOMATIC_UPDATE_CHECK_INTERVAL_MS,\n getAutomaticUpdateCheckDelay\n} from \"@nextclaw/kernel\";\nimport {\n eventKeys,\n type EventBus,\n type UpdateFailureStage,\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 automaticCheckIntervalMs?: number;\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 automaticCheckTimer: ReturnType<typeof setTimeout> | null = null;\n private started = 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 }\n\n getState = async (): Promise<UpdateSnapshot> => {\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\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 updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n await this.activeTask;\n }\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n start = (): void => {\n if (this.started) {\n return;\n }\n this.started = true;\n void this.runAutomaticCheck();\n };\n\n dispose = (): void => {\n this.started = false;\n this.clearAutomaticCheckTimer();\n };\n\n private runAutomaticCheck = async (): Promise<void> => {\n try {\n const state = this.stateStore.read();\n if (getAutomaticUpdateCheckDelay(\n state.lastUpdateCheckAt,\n Date.now(),\n this.automaticCheckIntervalMs\n ) === 0) {\n await this.startCheck();\n }\n } catch (error) {\n this.logger.error(\"automatic runtime update check failed\", {}, error);\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n private get automaticCheckIntervalMs(): number {\n return this.deps.automaticCheckIntervalMs ?? AUTOMATIC_UPDATE_CHECK_INTERVAL_MS;\n }\n\n private scheduleNextAutomaticCheck = (): void => {\n if (!this.started) {\n return;\n }\n this.clearAutomaticCheckTimer();\n const remainingDelayMs = getAutomaticUpdateCheckDelay(\n this.stateStore.read().lastUpdateCheckAt,\n Date.now(),\n this.automaticCheckIntervalMs\n );\n const delayMs = remainingDelayMs > 0 ? remainingDelayMs : this.automaticCheckIntervalMs;\n this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, delayMs);\n };\n\n private clearAutomaticCheckTimer = (): void => {\n if (this.automaticCheckTimer) {\n clearTimeout(this.automaticCheckTimer);\n this.automaticCheckTimer = null;\n }\n };\n\n private startCheck = async (): 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 } 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":";;;;;;;;;;;;AAwBA,MAAM,4BAA4C;CAChD,iBAAiB;CACjB,YAAY;CACZ,SAAS;CACV;AAWD,IAAa,uBAAb,MAAiE;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA,aAA2C;CAC3C,sBAAoE;CACpE,UAAkB;CAClB;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;;CAGp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B;EACnD,MAAM,qBAAqB,MAAM,KAAK,eAAe,CAAC,gBAAgB,aAAa;AACjF,QAAK,YAAY;IACf,GAAG,KAAK;IACR,QAAQ;IACR;IACA,cAAc;IACf,CAAC;IACF;AACF,OAAK,YAAY,mBAAmB;;CAGtC,iBAAyB,UAAU,KAAK,WAAW,MAAM,CAAC,YAAkC;AAC1F,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"}
|
|
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 { AUTOMATIC_UPDATE_CHECK_INTERVAL_MS } from \"@nextclaw/kernel\";\nimport {\n eventKeys,\n type EventBus,\n type UpdateFailureStage,\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 automaticCheckIntervalMs?: number;\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 automaticCheckTimer: ReturnType<typeof setTimeout> | null = null;\n private started = 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 }\n\n getState = async (): Promise<UpdateSnapshot> => {\n return this.snapshot;\n };\n\n checkForUpdates = async (): Promise<UpdateSnapshot> => {\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\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 updateChannel = async (channel: UpdateSnapshot[\"channel\"]): Promise<UpdateSnapshot> => {\n if (this.activeTask) {\n await this.activeTask;\n }\n const nextState = this.stateStore.update((current) => ({\n ...current,\n channel\n }));\n this.setSnapshot(this.createManager(nextState.channel).getSnapshot());\n try {\n return await this.startCheck();\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n start = (): void => {\n if (this.started) {\n return;\n }\n this.started = true;\n void this.runAutomaticCheck();\n };\n\n dispose = (): void => {\n this.started = false;\n this.clearAutomaticCheckTimer();\n };\n\n private runAutomaticCheck = async (): Promise<void> => {\n try {\n await this.startCheck();\n } catch (error) {\n this.logger.error(\"automatic runtime update check failed\", {}, error);\n } finally {\n this.scheduleNextAutomaticCheck();\n }\n };\n\n private get automaticCheckIntervalMs(): number {\n return this.deps.automaticCheckIntervalMs ?? AUTOMATIC_UPDATE_CHECK_INTERVAL_MS;\n }\n\n private scheduleNextAutomaticCheck = (): void => {\n if (!this.started) {\n return;\n }\n this.clearAutomaticCheckTimer();\n this.automaticCheckTimer = setTimeout(this.runAutomaticCheck, this.automaticCheckIntervalMs);\n };\n\n private clearAutomaticCheckTimer = (): void => {\n if (this.automaticCheckTimer) {\n clearTimeout(this.automaticCheckTimer);\n this.automaticCheckTimer = null;\n }\n };\n\n private startCheck = async (): 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 } 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, {\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AM;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.
|
|
3
|
+
"version": "0.3.12",
|
|
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-
|
|
46
|
-
"@nextclaw/channel-extension-email": "0.2.
|
|
47
|
-
"@nextclaw/channel-extension-
|
|
48
|
-
"@nextclaw/channel-extension-qq": "0.2.
|
|
49
|
-
"@nextclaw/channel-extension-
|
|
50
|
-
"@nextclaw/channel-extension-telegram": "0.2.
|
|
51
|
-
"@nextclaw/channel-extension-wecom": "0.2.
|
|
52
|
-
"@nextclaw/channel-extension-
|
|
53
|
-
"@nextclaw/
|
|
54
|
-
"@nextclaw/
|
|
55
|
-
"@nextclaw/
|
|
56
|
-
"@nextclaw/
|
|
57
|
-
"@nextclaw/
|
|
58
|
-
"@nextclaw/
|
|
59
|
-
"@nextclaw/ncp-agent-runtime": "0.4.
|
|
60
|
-
"@nextclaw/ncp-mcp": "0.2.
|
|
61
|
-
"@nextclaw/ncp-toolkit": "0.6.
|
|
62
|
-
"@nextclaw/nextclaw-
|
|
63
|
-
"@nextclaw/nextclaw-
|
|
64
|
-
"@nextclaw/
|
|
65
|
-
"@nextclaw/
|
|
66
|
-
"@nextclaw/
|
|
67
|
-
"@nextclaw/
|
|
68
|
-
"@nextclaw/
|
|
69
|
-
"@nextclaw/channel-extension-
|
|
45
|
+
"@nextclaw/channel-extension-discord": "0.2.10",
|
|
46
|
+
"@nextclaw/channel-extension-email": "0.2.10",
|
|
47
|
+
"@nextclaw/channel-extension-slack": "0.2.10",
|
|
48
|
+
"@nextclaw/channel-extension-qq": "0.2.9",
|
|
49
|
+
"@nextclaw/channel-extension-weixin": "0.2.10",
|
|
50
|
+
"@nextclaw/channel-extension-telegram": "0.2.10",
|
|
51
|
+
"@nextclaw/channel-extension-wecom": "0.2.10",
|
|
52
|
+
"@nextclaw/channel-extension-whatsapp": "0.2.10",
|
|
53
|
+
"@nextclaw/client-sdk": "0.5.12",
|
|
54
|
+
"@nextclaw/core": "0.15.10",
|
|
55
|
+
"@nextclaw/kernel": "0.6.12",
|
|
56
|
+
"@nextclaw/mcp": "0.3.10",
|
|
57
|
+
"@nextclaw/ncp": "0.7.8",
|
|
58
|
+
"@nextclaw/channel-extension-dingtalk": "0.2.10",
|
|
59
|
+
"@nextclaw/ncp-agent-runtime": "0.4.8",
|
|
60
|
+
"@nextclaw/ncp-mcp": "0.2.10",
|
|
61
|
+
"@nextclaw/ncp-toolkit": "0.6.9",
|
|
62
|
+
"@nextclaw/nextclaw-ncp-runtime-http-client": "0.3.8",
|
|
63
|
+
"@nextclaw/nextclaw-hermes-acp-bridge": "0.3.8",
|
|
64
|
+
"@nextclaw/remote": "0.3.12",
|
|
65
|
+
"@nextclaw/server": "0.15.12",
|
|
66
|
+
"@nextclaw/shared": "0.4.9",
|
|
67
|
+
"@nextclaw/runtime": "0.4.10",
|
|
68
|
+
"@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.3.11",
|
|
69
|
+
"@nextclaw/channel-extension-feishu": "0.2.10"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/node": "^20.17.6",
|