@nextclaw/service 0.2.11-beta.0 → 0.2.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-bundle.service.d.ts","names":[],"sources":["../../src/launcher/npm-runtime-bundle.service.ts"],"mappings":";;;;;;KAQY,wBAAA;EACV,eAAA;EACA,QAAA,EAAU,wBAAA;EACV,iBAAA;AAAA;AAAA,KAGG,8BAAA;EACH,MAAA,EAAQ,2BAAA;EACR,UAAA,EAAY,0BAAA;EACZ,cAAA,GAAiB,8BAAA;EACjB,QAAA,GAAW,MAAA,CAAO,QAAA;EAClB,IAAA;EACA,eAAA;EACA,GAAA;AAAA;AAAA,cAWW,uBAAA;EAAA,iBAOkB,OAAA;EAAA,iBANZ,cAAA;EAAA,iBACA,QAAA;EAAA,iBACA,IAAA;EAAA,iBACA,eAAA;EAAA,iBACA,GAAA;cAEY,OAAA,EAAS,8BAAA;EAQtC,oBAAA,QAA2B,wBAAA;EAQ3B,cAAA,GAAkB,OAAA,aAAkB,wBAAA;EASpC,oBAAA,GAA8B,eAAA,aAA0B,OAAA,CAAQ,wBAAA;EA6BhE,eAAA,GAAmB,OAAA;EAkBnB,sBAAA,QAAmC,OAAA;EAAA,QAyB3B,qBAAA;EAAA,QAKA,YAAA;AAAA;AAAA,iBAuBM,yBAAA,CAA0B,IAAA,UAAc,KAAA;AAAA,iBAcxC,iCAAA,CAAkC,MAAA;EAChD,eAAA;EACA,oBAAA;AAAA;AAAA,iBAec,8BAAA,CAA+B,MAAA;EAC7C,eAAA;EACA,oBAAA;AAAA"}
1
+ {"version":3,"file":"npm-runtime-bundle.service.d.ts","names":[],"sources":["../../src/launcher/npm-runtime-bundle.service.ts"],"mappings":";;;;;;KAQY,wBAAA;EACV,eAAA;EACA,QAAA,EAAU,wBAAA;EACV,iBAAA;AAAA;AAAA,KAGG,8BAAA;EACH,MAAA,EAAQ,2BAAA;EACR,UAAA,EAAY,0BAAA;EACZ,cAAA,GAAiB,8BAAA;EACjB,QAAA,GAAW,MAAA,CAAO,QAAA;EAClB,IAAA;EACA,eAAA;EACA,GAAA;AAAA;AAAA,cAWW,uBAAA;EAAA,iBAOkB,OAAA;EAAA,iBANZ,cAAA;EAAA,iBACA,QAAA;EAAA,iBACA,IAAA;EAAA,iBACA,eAAA;EAAA,iBACA,GAAA;cAEY,OAAA,EAAS,8BAAA;EAQtC,oBAAA,QAA2B,wBAAA;EAQ3B,cAAA,GAAkB,OAAA,aAAkB,wBAAA;EASpC,oBAAA,GAA8B,eAAA,aAA0B,OAAA,CAAQ,wBAAA;EA6BhE,eAAA,GAAmB,OAAA;EAkBnB,sBAAA,QAAmC,OAAA;EAAA,QAyB3B,qBAAA;EAAA,QAKA,YAAA;AAAA;AAAA,iBAuBM,yBAAA,CAA0B,IAAA,UAAc,KAAA;AAAA,iBAkBxC,iCAAA,CAAkC,MAAA;EAChD,eAAA;EACA,oBAAA;AAAA;AAAA,iBAec,8BAAA,CAA+B,MAAA;EAC7C,eAAA;EACA,oBAAA;AAAA"}
@@ -120,15 +120,17 @@ var NpmRuntimeBundleService = class {
120
120
  };
121
121
  };
122
122
  function compareNpmRuntimeVersions(left, right) {
123
- const leftParts = parseVersionParts(left);
124
- const rightParts = parseVersionParts(right);
123
+ const [leftCore = "", leftPrerelease = ""] = left.split("+")[0]?.split("-", 2) ?? [];
124
+ const [rightCore = "", rightPrerelease = ""] = right.split("+")[0]?.split("-", 2) ?? [];
125
+ const leftParts = parseVersionParts(leftCore);
126
+ const rightParts = parseVersionParts(rightCore);
125
127
  const length = Math.max(leftParts.length, rightParts.length);
126
128
  for (let index = 0; index < length; index += 1) {
127
- const leftPart = leftParts[index] ?? 0;
128
- const rightPart = rightParts[index] ?? 0;
129
- if (leftPart !== rightPart) return leftPart - rightPart;
129
+ const compared = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);
130
+ if (compared !== 0) return compared;
130
131
  }
131
- return left.localeCompare(right);
132
+ if (!leftPrerelease || !rightPrerelease) return Number(!leftPrerelease) - Number(!rightPrerelease);
133
+ return leftPrerelease.localeCompare(rightPrerelease, void 0, { numeric: true });
132
134
  }
133
135
  function resolveEffectiveNpmRuntimeVersion(params) {
134
136
  const launcherVersion = params.launcherVersion?.trim() || null;
@@ -139,12 +141,10 @@ function resolveEffectiveNpmRuntimeVersion(params) {
139
141
  }
140
142
  function shouldPreferPackagedNpmRuntime(params) {
141
143
  const launcherVersion = params.launcherVersion?.trim() || null;
142
- const currentBundleVersion = params.currentBundleVersion?.trim() || null;
143
- if (!launcherVersion || !currentBundleVersion) return false;
144
- return resolveEffectiveNpmRuntimeVersion(params) === launcherVersion;
144
+ return Boolean(launcherVersion) && resolveEffectiveNpmRuntimeVersion(params) === launcherVersion;
145
145
  }
146
146
  function parseVersionParts(version) {
147
- return version.split(/[.-]/).map((part) => Number(part)).map((part) => Number.isFinite(part) ? part : 0);
147
+ return version.split(".").map((part) => Number(part)).map((part) => Number.isFinite(part) ? part : 0);
148
148
  }
149
149
  //#endregion
150
150
  export { NpmRuntimeBundleService, compareNpmRuntimeVersions, resolveEffectiveNpmRuntimeVersion, shouldPreferPackagedNpmRuntime };
@@ -1 +1 @@
1
- {"version":3,"file":"npm-runtime-bundle.service.js","names":[],"sources":["../../src/launcher/npm-runtime-bundle.service.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { cp, readdir, rename, rm } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { NpmRuntimeBundleManifestReader } from \"./npm-runtime-bundle-manifest.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"./npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeBundleManifest } from \"./npm-runtime-bundle.types.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"./npm-runtime-update-state.store.js\";\n\nexport type ResolvedNpmRuntimeBundle = {\n bundleDirectory: string;\n manifest: NpmRuntimeBundleManifest;\n runtimeScriptPath: string;\n};\n\ntype NpmRuntimeBundleServiceOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n manifestReader?: NpmRuntimeBundleManifestReader;\n platform?: NodeJS.Platform;\n arch?: string;\n launcherVersion?: string;\n now?: () => number;\n};\n\nfunction shouldRetryInstallWithCopy(error: unknown): boolean {\n if (!error || typeof error !== \"object\") {\n return false;\n }\n const code = \"code\" in error ? String(error.code) : \"\";\n return code === \"EXDEV\" || code === \"EPERM\";\n}\n\nexport class NpmRuntimeBundleService {\n private readonly manifestReader: NpmRuntimeBundleManifestReader;\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly launcherVersion: string | null;\n private readonly now: () => number;\n\n constructor(private readonly options: NpmRuntimeBundleServiceOptions) {\n this.manifestReader = options.manifestReader ?? new NpmRuntimeBundleManifestReader();\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.launcherVersion = options.launcherVersion?.trim() || null;\n this.now = options.now ?? Date.now;\n }\n\n resolveCurrentBundle = (): ResolvedNpmRuntimeBundle | null => {\n const pointer = this.options.layout.readCurrentPointer();\n if (!pointer) {\n return null;\n }\n return this.resolveVersion(pointer.version);\n };\n\n resolveVersion = (version: string): ResolvedNpmRuntimeBundle => {\n const bundleDirectory = this.options.layout.getVersionDir(version);\n const bundle = this.verifyBundle(bundleDirectory);\n if (bundle.manifest.bundleVersion !== version) {\n throw new Error(`runtime bundle version mismatch: pointer expects ${version} but manifest is ${bundle.manifest.bundleVersion}`);\n }\n return bundle;\n };\n\n installFromDirectory = async (sourceDirectory: string): Promise<ResolvedNpmRuntimeBundle> => {\n this.options.layout.ensureLauncherDirs();\n const sourceBundle = this.verifyBundle(sourceDirectory);\n const targetDirectory = this.options.layout.getVersionDir(sourceBundle.manifest.bundleVersion);\n if (existsSync(targetDirectory)) {\n return this.verifyBundle(targetDirectory);\n }\n\n try {\n await rename(sourceDirectory, targetDirectory);\n return this.verifyBundle(targetDirectory);\n } catch (error) {\n if (!shouldRetryInstallWithCopy(error)) {\n throw error;\n }\n }\n\n const stagingDirectory = join(this.options.layout.getStagingDir(), `${sourceBundle.manifest.bundleVersion}-${this.now()}`);\n await rm(stagingDirectory, { recursive: true, force: true });\n try {\n await cp(sourceDirectory, stagingDirectory, { recursive: true });\n await rename(stagingDirectory, targetDirectory);\n return this.verifyBundle(targetDirectory);\n } catch (error) {\n await rm(stagingDirectory, { recursive: true, force: true });\n throw error;\n }\n };\n\n activateVersion = (version: string): void => {\n this.resolveVersion(version);\n const currentPointer = this.options.layout.readCurrentPointer();\n if (currentPointer) {\n this.options.layout.writePreviousPointer(currentPointer);\n }\n this.options.layout.writeCurrentPointer({ version });\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion: version,\n previousVersion: currentPointer?.version ?? state.previousVersion,\n candidateVersion: version,\n candidateLaunchCount: 0,\n downloadedVersion: null,\n downloadedReleaseNotesUrl: null\n }));\n };\n\n pruneRetainedArtifacts = async (): Promise<void> => {\n this.options.layout.ensureLauncherDirs();\n const state = this.options.stateStore.read();\n const retained = new Set(\n [\n state.currentVersion,\n state.previousVersion,\n state.candidateVersion,\n state.lastKnownGoodVersion,\n state.downloadedVersion,\n this.options.layout.readCurrentPointer()?.version,\n this.options.layout.readPreviousPointer()?.version\n ].filter((version): version is string => Boolean(version?.trim()))\n );\n\n const entries = await readdir(this.options.layout.getVersionsDir(), { withFileTypes: true });\n for (const entry of entries.sort((left, right) => compareNpmRuntimeVersions(left.name, right.name))) {\n if (!entry.isDirectory() || retained.has(entry.name)) {\n continue;\n }\n await rm(join(this.options.layout.getVersionsDir(), entry.name), { recursive: true, force: true });\n }\n await this.clearStagingDirectory();\n };\n\n private clearStagingDirectory = async (): Promise<void> => {\n const entries = await readdir(this.options.layout.getStagingDir(), { withFileTypes: true });\n await Promise.all(entries.map(async (entry) => await rm(join(this.options.layout.getStagingDir(), entry.name), { recursive: true, force: true })));\n };\n\n private verifyBundle = (bundleDirectory: string): ResolvedNpmRuntimeBundle => {\n const manifest = this.manifestReader.readFile(resolve(bundleDirectory, \"manifest.json\"));\n if (manifest.platform !== this.platform) {\n throw new Error(`runtime bundle platform mismatch: expected ${this.platform} but got ${manifest.platform}`);\n }\n if (manifest.arch !== this.arch) {\n throw new Error(`runtime bundle arch mismatch: expected ${this.arch} but got ${manifest.arch}`);\n }\n if (this.launcherVersion && compareNpmRuntimeVersions(this.launcherVersion, manifest.launcherCompatibility.minVersion) < 0) {\n throw new Error(`runtime bundle requires launcher >= ${manifest.launcherCompatibility.minVersion} but current launcher is ${this.launcherVersion}`);\n }\n const runtimeScriptPath = resolve(bundleDirectory, manifest.entrypoints.runtimeScript);\n if (!existsSync(runtimeScriptPath)) {\n throw new Error(`runtime bundle script missing: ${runtimeScriptPath}`);\n }\n return {\n bundleDirectory,\n manifest,\n runtimeScriptPath\n };\n };\n}\n\nexport function compareNpmRuntimeVersions(left: string, right: string): number {\n const leftParts = parseVersionParts(left);\n const rightParts = parseVersionParts(right);\n const length = Math.max(leftParts.length, rightParts.length);\n for (let index = 0; index < length; index += 1) {\n const leftPart = leftParts[index] ?? 0;\n const rightPart = rightParts[index] ?? 0;\n if (leftPart !== rightPart) {\n return leftPart - rightPart;\n }\n }\n return left.localeCompare(right);\n}\n\nexport function resolveEffectiveNpmRuntimeVersion(params: {\n launcherVersion: string | null;\n currentBundleVersion: string | null;\n}): string | null {\n const launcherVersion = params.launcherVersion?.trim() || null;\n const currentBundleVersion = params.currentBundleVersion?.trim() || null;\n if (!launcherVersion) {\n return currentBundleVersion;\n }\n if (!currentBundleVersion) {\n return launcherVersion;\n }\n return compareNpmRuntimeVersions(launcherVersion, currentBundleVersion) > 0\n ? launcherVersion\n : currentBundleVersion;\n}\n\nexport function shouldPreferPackagedNpmRuntime(params: {\n launcherVersion: string | null;\n currentBundleVersion: string | null;\n}): boolean {\n const launcherVersion = params.launcherVersion?.trim() || null;\n const currentBundleVersion = params.currentBundleVersion?.trim() || null;\n if (!launcherVersion || !currentBundleVersion) {\n return false;\n }\n return resolveEffectiveNpmRuntimeVersion(params) === launcherVersion;\n}\n\nfunction parseVersionParts(version: string): number[] {\n return version\n .split(/[.-]/)\n .map((part) => Number(part))\n .map((part) => (Number.isFinite(part) ? part : 0));\n}\n"],"mappings":";;;;;AAwBA,SAAS,2BAA2B,OAAyB;AAC3D,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO;CAET,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,KAAK,GAAG;AACpD,QAAO,SAAS,WAAW,SAAS;;AAGtC,IAAa,0BAAb,MAAqC;CACnC;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA0D;AAAzC,OAAA,UAAA;AAC3B,OAAK,iBAAiB,QAAQ,kBAAkB,IAAI,gCAAgC;AACpF,OAAK,WAAW,QAAQ,YAAY,QAAQ;AAC5C,OAAK,OAAO,QAAQ,QAAQ,QAAQ;AACpC,OAAK,kBAAkB,QAAQ,iBAAiB,MAAM,IAAI;AAC1D,OAAK,MAAM,QAAQ,OAAO,KAAK;;CAGjC,6BAA8D;EAC5D,MAAM,UAAU,KAAK,QAAQ,OAAO,oBAAoB;AACxD,MAAI,CAAC,QACH,QAAO;AAET,SAAO,KAAK,eAAe,QAAQ,QAAQ;;CAG7C,kBAAkB,YAA8C;EAC9D,MAAM,kBAAkB,KAAK,QAAQ,OAAO,cAAc,QAAQ;EAClE,MAAM,SAAS,KAAK,aAAa,gBAAgB;AACjD,MAAI,OAAO,SAAS,kBAAkB,QACpC,OAAM,IAAI,MAAM,oDAAoD,QAAQ,mBAAmB,OAAO,SAAS,gBAAgB;AAEjI,SAAO;;CAGT,uBAAuB,OAAO,oBAA+D;AAC3F,OAAK,QAAQ,OAAO,oBAAoB;EACxC,MAAM,eAAe,KAAK,aAAa,gBAAgB;EACvD,MAAM,kBAAkB,KAAK,QAAQ,OAAO,cAAc,aAAa,SAAS,cAAc;AAC9F,MAAI,WAAW,gBAAgB,CAC7B,QAAO,KAAK,aAAa,gBAAgB;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AoB;AAExE,SAAO;GACL;GACA;GACA;GACD;;;AAIL,SAAgB,0BAA0B,MAAc,OAAuB;CAC7E,MAAM,YAAY,kBAAkB,KAAK;CACzC,MAAM,aAAa,kBAAkB,MAAM;CAC3C,MAAM,SAAS,KAAK,IAAI,UAAU,QAAQ,WAAW,OAAO;AAC5D,MAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS,GAAG;EAC9C,MAAM,WAAW,UAAU,UAAU;EACrC,MAAM,YAAY,WAAW,UAAU;AACvC,MAAI,aAAa,UACf,QAAO,WAAW;;AAGtB,QAAO,KAAK,cAAc,MAAM;;AAGlC,SAAgB,kCAAkC,QAGhC;CAChB,MAAM,kBAAkB,OAAO,iBAAiB,MAAM,IAAI;CAC1D,MAAM,uBAAuB,OAAO,sBAAsB,MAAM,IAAI;AACpE,KAAI,CAAC,gBACH,QAAO;AAET,KAAI,CAAC,qBACH,QAAO;AAET,QAAO,0BAA0B,iBAAiB,qBAAqB,GAAG,IACtE,kBACA;;AAGN,SAAgB,+BAA+B,QAGnC;CACV,MAAM,kBAAkB,OAAO,iBAAiB,MAAM,IAAI;CAC1D,MAAM,uBAAuB,OAAO,sBAAsB,MAAM,IAAI;AACpE,KAAI,CAAC,mBAAmB,CAAC,qBACvB,QAAO;AAET,QAAO,kCAAkC,OAAO,KAAK;;AAGvD,SAAS,kBAAkB,SAA2B;AACpD,QAAO,QACJ,MAAM,OAAO,CACb,KAAK,SAAS,OAAO,KAAK,CAAC,CAC3B,KAAK,SAAU,OAAO,SAAS,KAAK,GAAG,OAAO,EAAG"}
1
+ {"version":3,"file":"npm-runtime-bundle.service.js","names":[],"sources":["../../src/launcher/npm-runtime-bundle.service.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { cp, readdir, rename, rm } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { NpmRuntimeBundleManifestReader } from \"./npm-runtime-bundle-manifest.service.js\";\nimport type { NpmRuntimeBundleLayoutStore } from \"./npm-runtime-bundle-layout.store.js\";\nimport type { NpmRuntimeBundleManifest } from \"./npm-runtime-bundle.types.js\";\nimport type { NpmRuntimeUpdateStateStore } from \"./npm-runtime-update-state.store.js\";\n\nexport type ResolvedNpmRuntimeBundle = {\n bundleDirectory: string;\n manifest: NpmRuntimeBundleManifest;\n runtimeScriptPath: string;\n};\n\ntype NpmRuntimeBundleServiceOptions = {\n layout: NpmRuntimeBundleLayoutStore;\n stateStore: NpmRuntimeUpdateStateStore;\n manifestReader?: NpmRuntimeBundleManifestReader;\n platform?: NodeJS.Platform;\n arch?: string;\n launcherVersion?: string;\n now?: () => number;\n};\n\nfunction shouldRetryInstallWithCopy(error: unknown): boolean {\n if (!error || typeof error !== \"object\") {\n return false;\n }\n const code = \"code\" in error ? String(error.code) : \"\";\n return code === \"EXDEV\" || code === \"EPERM\";\n}\n\nexport class NpmRuntimeBundleService {\n private readonly manifestReader: NpmRuntimeBundleManifestReader;\n private readonly platform: NodeJS.Platform;\n private readonly arch: string;\n private readonly launcherVersion: string | null;\n private readonly now: () => number;\n\n constructor(private readonly options: NpmRuntimeBundleServiceOptions) {\n this.manifestReader = options.manifestReader ?? new NpmRuntimeBundleManifestReader();\n this.platform = options.platform ?? process.platform;\n this.arch = options.arch ?? process.arch;\n this.launcherVersion = options.launcherVersion?.trim() || null;\n this.now = options.now ?? Date.now;\n }\n\n resolveCurrentBundle = (): ResolvedNpmRuntimeBundle | null => {\n const pointer = this.options.layout.readCurrentPointer();\n if (!pointer) {\n return null;\n }\n return this.resolveVersion(pointer.version);\n };\n\n resolveVersion = (version: string): ResolvedNpmRuntimeBundle => {\n const bundleDirectory = this.options.layout.getVersionDir(version);\n const bundle = this.verifyBundle(bundleDirectory);\n if (bundle.manifest.bundleVersion !== version) {\n throw new Error(`runtime bundle version mismatch: pointer expects ${version} but manifest is ${bundle.manifest.bundleVersion}`);\n }\n return bundle;\n };\n\n installFromDirectory = async (sourceDirectory: string): Promise<ResolvedNpmRuntimeBundle> => {\n this.options.layout.ensureLauncherDirs();\n const sourceBundle = this.verifyBundle(sourceDirectory);\n const targetDirectory = this.options.layout.getVersionDir(sourceBundle.manifest.bundleVersion);\n if (existsSync(targetDirectory)) {\n return this.verifyBundle(targetDirectory);\n }\n\n try {\n await rename(sourceDirectory, targetDirectory);\n return this.verifyBundle(targetDirectory);\n } catch (error) {\n if (!shouldRetryInstallWithCopy(error)) {\n throw error;\n }\n }\n\n const stagingDirectory = join(this.options.layout.getStagingDir(), `${sourceBundle.manifest.bundleVersion}-${this.now()}`);\n await rm(stagingDirectory, { recursive: true, force: true });\n try {\n await cp(sourceDirectory, stagingDirectory, { recursive: true });\n await rename(stagingDirectory, targetDirectory);\n return this.verifyBundle(targetDirectory);\n } catch (error) {\n await rm(stagingDirectory, { recursive: true, force: true });\n throw error;\n }\n };\n\n activateVersion = (version: string): void => {\n this.resolveVersion(version);\n const currentPointer = this.options.layout.readCurrentPointer();\n if (currentPointer) {\n this.options.layout.writePreviousPointer(currentPointer);\n }\n this.options.layout.writeCurrentPointer({ version });\n this.options.stateStore.update((state) => ({\n ...state,\n currentVersion: version,\n previousVersion: currentPointer?.version ?? state.previousVersion,\n candidateVersion: version,\n candidateLaunchCount: 0,\n downloadedVersion: null,\n downloadedReleaseNotesUrl: null\n }));\n };\n\n pruneRetainedArtifacts = async (): Promise<void> => {\n this.options.layout.ensureLauncherDirs();\n const state = this.options.stateStore.read();\n const retained = new Set(\n [\n state.currentVersion,\n state.previousVersion,\n state.candidateVersion,\n state.lastKnownGoodVersion,\n state.downloadedVersion,\n this.options.layout.readCurrentPointer()?.version,\n this.options.layout.readPreviousPointer()?.version\n ].filter((version): version is string => Boolean(version?.trim()))\n );\n\n const entries = await readdir(this.options.layout.getVersionsDir(), { withFileTypes: true });\n for (const entry of entries.sort((left, right) => compareNpmRuntimeVersions(left.name, right.name))) {\n if (!entry.isDirectory() || retained.has(entry.name)) {\n continue;\n }\n await rm(join(this.options.layout.getVersionsDir(), entry.name), { recursive: true, force: true });\n }\n await this.clearStagingDirectory();\n };\n\n private clearStagingDirectory = async (): Promise<void> => {\n const entries = await readdir(this.options.layout.getStagingDir(), { withFileTypes: true });\n await Promise.all(entries.map(async (entry) => await rm(join(this.options.layout.getStagingDir(), entry.name), { recursive: true, force: true })));\n };\n\n private verifyBundle = (bundleDirectory: string): ResolvedNpmRuntimeBundle => {\n const manifest = this.manifestReader.readFile(resolve(bundleDirectory, \"manifest.json\"));\n if (manifest.platform !== this.platform) {\n throw new Error(`runtime bundle platform mismatch: expected ${this.platform} but got ${manifest.platform}`);\n }\n if (manifest.arch !== this.arch) {\n throw new Error(`runtime bundle arch mismatch: expected ${this.arch} but got ${manifest.arch}`);\n }\n if (this.launcherVersion && compareNpmRuntimeVersions(this.launcherVersion, manifest.launcherCompatibility.minVersion) < 0) {\n throw new Error(`runtime bundle requires launcher >= ${manifest.launcherCompatibility.minVersion} but current launcher is ${this.launcherVersion}`);\n }\n const runtimeScriptPath = resolve(bundleDirectory, manifest.entrypoints.runtimeScript);\n if (!existsSync(runtimeScriptPath)) {\n throw new Error(`runtime bundle script missing: ${runtimeScriptPath}`);\n }\n return {\n bundleDirectory,\n manifest,\n runtimeScriptPath\n };\n };\n}\n\nexport function compareNpmRuntimeVersions(left: string, right: string): number {\n const [leftCore = \"\", leftPrerelease = \"\"] = left.split(\"+\")[0]?.split(\"-\", 2) ?? [];\n const [rightCore = \"\", rightPrerelease = \"\"] = right.split(\"+\")[0]?.split(\"-\", 2) ?? [];\n const leftParts = parseVersionParts(leftCore);\n const rightParts = parseVersionParts(rightCore);\n const length = Math.max(leftParts.length, rightParts.length);\n for (let index = 0; index < length; index += 1) {\n const compared = (leftParts[index] ?? 0) - (rightParts[index] ?? 0);\n if (compared !== 0) {\n return compared;\n }\n }\n if (!leftPrerelease || !rightPrerelease) {\n return Number(!leftPrerelease) - Number(!rightPrerelease);\n }\n return leftPrerelease.localeCompare(rightPrerelease, undefined, { numeric: true });\n}\n\nexport function resolveEffectiveNpmRuntimeVersion(params: {\n launcherVersion: string | null;\n currentBundleVersion: string | null;\n}): string | null {\n const launcherVersion = params.launcherVersion?.trim() || null;\n const currentBundleVersion = params.currentBundleVersion?.trim() || null;\n if (!launcherVersion) {\n return currentBundleVersion;\n }\n if (!currentBundleVersion) {\n return launcherVersion;\n }\n return compareNpmRuntimeVersions(launcherVersion, currentBundleVersion) > 0\n ? launcherVersion\n : currentBundleVersion;\n}\n\nexport function shouldPreferPackagedNpmRuntime(params: {\n launcherVersion: string | null;\n currentBundleVersion: string | null;\n}): boolean {\n const launcherVersion = params.launcherVersion?.trim() || null;\n return Boolean(launcherVersion) && resolveEffectiveNpmRuntimeVersion(params) === launcherVersion;\n}\n\nfunction parseVersionParts(version: string): number[] {\n return version\n .split(\".\")\n .map((part) => Number(part))\n .map((part) => (Number.isFinite(part) ? part : 0));\n}\n"],"mappings":";;;;;AAwBA,SAAS,2BAA2B,OAAyB;AAC3D,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO;CAET,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,KAAK,GAAG;AACpD,QAAO,SAAS,WAAW,SAAS;;AAGtC,IAAa,0BAAb,MAAqC;CACnC;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA0D;AAAzC,OAAA,UAAA;AAC3B,OAAK,iBAAiB,QAAQ,kBAAkB,IAAI,gCAAgC;AACpF,OAAK,WAAW,QAAQ,YAAY,QAAQ;AAC5C,OAAK,OAAO,QAAQ,QAAQ,QAAQ;AACpC,OAAK,kBAAkB,QAAQ,iBAAiB,MAAM,IAAI;AAC1D,OAAK,MAAM,QAAQ,OAAO,KAAK;;CAGjC,6BAA8D;EAC5D,MAAM,UAAU,KAAK,QAAQ,OAAO,oBAAoB;AACxD,MAAI,CAAC,QACH,QAAO;AAET,SAAO,KAAK,eAAe,QAAQ,QAAQ;;CAG7C,kBAAkB,YAA8C;EAC9D,MAAM,kBAAkB,KAAK,QAAQ,OAAO,cAAc,QAAQ;EAClE,MAAM,SA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,KAAI,CAAC,qBACH,QAAO;AAET,QAAO,0BAA0B,iBAAiB,qBAAqB,GAAG,IACtE,kBACA;;AAGN,SAAgB,+BAA+B,QAGnC;CACV,MAAM,kBAAkB,OAAO,iBAAiB,MAAM,IAAI;AAC1D,QAAO,QAAQ,gBAAgB,IAAI,kCAAkC,OAAO,KAAK;;AAGnF,SAAS,kBAAkB,SAA2B;AACpD,QAAO,QACJ,MAAM,IAAI,CACV,KAAK,SAAS,OAAO,KAAK,CAAC,CAC3B,KAAK,SAAU,OAAO,SAAS,KAAK,GAAG,OAAO,EAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/service",
3
- "version": "0.2.11-beta.0",
3
+ "version": "0.2.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-email": "0.1.15-beta.0",
46
- "@nextclaw/channel-extension-slack": "0.1.15-beta.0",
47
- "@nextclaw/channel-extension-discord": "0.1.15-beta.0",
48
- "@nextclaw/channel-extension-feishu": "0.1.22-beta.0",
49
- "@nextclaw/channel-extension-dingtalk": "0.1.15-beta.0",
50
- "@nextclaw/channel-extension-qq": "0.1.19-beta.0",
51
- "@nextclaw/channel-extension-wecom": "0.1.15-beta.0",
52
- "@nextclaw/channel-extension-telegram": "0.1.15-beta.0",
53
- "@nextclaw/channel-extension-whatsapp": "0.1.15-beta.0",
54
- "@nextclaw/core": "0.14.1-beta.0",
55
- "@nextclaw/channel-extension-weixin": "0.1.26-beta.0",
56
- "@nextclaw/client-sdk": "0.4.0-beta.0",
57
- "@nextclaw/kernel": "0.4.1-beta.0",
58
- "@nextclaw/mcp": "0.2.11-beta.0",
59
- "@nextclaw/ncp-agent-runtime": "0.3.41-beta.0",
60
- "@nextclaw/ncp": "0.6.0-beta.0",
61
- "@nextclaw/ncp-mcp": "0.1.106-beta.0",
62
- "@nextclaw/nextclaw-hermes-acp-bridge": "0.2.10-beta.0",
63
- "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.2.10-beta.0",
64
- "@nextclaw/ncp-toolkit": "0.5.35-beta.0",
65
- "@nextclaw/nextclaw-ncp-runtime-http-client": "0.2.10-beta.0",
66
- "@nextclaw/server": "0.14.1-beta.0",
67
- "@nextclaw/runtime": "0.3.11-beta.0",
68
- "@nextclaw/remote": "0.2.11-beta.0",
69
- "@nextclaw/shared": "0.2.10-beta.0"
45
+ "@nextclaw/channel-extension-dingtalk": "0.1.16",
46
+ "@nextclaw/channel-extension-email": "0.1.16",
47
+ "@nextclaw/channel-extension-discord": "0.1.16",
48
+ "@nextclaw/channel-extension-feishu": "0.1.23",
49
+ "@nextclaw/channel-extension-qq": "0.1.20",
50
+ "@nextclaw/channel-extension-slack": "0.1.16",
51
+ "@nextclaw/channel-extension-wecom": "0.1.16",
52
+ "@nextclaw/channel-extension-weixin": "0.1.27",
53
+ "@nextclaw/channel-extension-telegram": "0.1.16",
54
+ "@nextclaw/core": "0.14.2",
55
+ "@nextclaw/client-sdk": "0.4.1",
56
+ "@nextclaw/channel-extension-whatsapp": "0.1.16",
57
+ "@nextclaw/ncp": "0.6.1",
58
+ "@nextclaw/kernel": "0.4.2",
59
+ "@nextclaw/mcp": "0.2.12",
60
+ "@nextclaw/ncp-mcp": "0.1.107",
61
+ "@nextclaw/ncp-agent-runtime": "0.3.42",
62
+ "@nextclaw/nextclaw-hermes-acp-bridge": "0.2.11",
63
+ "@nextclaw/nextclaw-ncp-runtime-http-client": "0.2.11",
64
+ "@nextclaw/runtime": "0.3.12",
65
+ "@nextclaw/ncp-toolkit": "0.5.36",
66
+ "@nextclaw/shared": "0.2.11",
67
+ "@nextclaw/remote": "0.2.12",
68
+ "@nextclaw/server": "0.14.2",
69
+ "@nextclaw/nextclaw-ncp-runtime-stdio-client": "0.2.11"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/node": "^20.17.6",