@webskill/sdk 0.0.2 → 0.0.4

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,4 +1,4 @@
1
- import { D as normalizeToolContent, G as parseSkillMarkdown, H as isValidSkillName, J as resolveInsideRoot, O as parseBridgeRequest, R as WebSkillError, Y as validateSkills, o as FsArtifactStore, s as FsMemoryStore, x as bridgeError } from "./dist-BbyIk4vG.js";
1
+ import { A as parseBridgeRequest, C as bridgeError, H as WebSkillError, I as SKILLS_LOCKFILE, J as isValidSkillName, L as SKILL_MANIFEST_FILE, W as buildManifest, Z as parseSkillMarkdown, et as resolveInsideRoot, k as normalizeToolContent, nt as verifyManifest, o as FsArtifactStore, s as FsMemoryStore, tt as validateSkills } from "./dist-COsE72Ct.js";
2
2
  import { existsSync, promises, readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -796,10 +796,6 @@ async function removeDirQuiet(fs, dir) {
796
796
  if (await fs.exists(dir)) await fs.remove(dir, { recursive: true });
797
797
  } catch {}
798
798
  }
799
- /** 技能目录内的安装清单文件名(不参与 files 列表与 digest) */
800
- const SKILL_MANIFEST_FILE = "webskill.skill-manifest.json";
801
- /** managed root 下的锁定文件名(不参与 files 列表与 digest) */
802
- const SKILLS_LOCKFILE = "skills.lock.json";
803
799
  const messageOf$3 = (e) => e instanceof Error ? e.message : String(e);
804
800
  /** 导出技能目录全部文件(含 manifest)为 zip/tar 归档,返回 outPath */
805
801
  async function exportArchive(fs, skillRoot, options) {
@@ -824,7 +820,7 @@ async function readArchiveManifest(fs, archivePath) {
824
820
  const data = await fs.readBinary(archivePath);
825
821
  if (isZipArchive(data)) {
826
822
  const entries = unzipSync(data);
827
- const key = Object.keys(entries).find((k) => k === "webskill.skill-manifest.json" || k.endsWith(`/webskill.skill-manifest.json`));
823
+ const key = Object.keys(entries).find((k) => k === "webskill.skill-manifest.json" || k.endsWith(`/${"webskill.skill-manifest.json"}`));
828
824
  if (!key) throw notFound();
829
825
  return JSON.parse(new TextDecoder().decode(entries[key]));
830
826
  }
@@ -833,7 +829,7 @@ async function readArchiveManifest(fs, archivePath) {
833
829
  await tar.t({
834
830
  file: toPlatform(archivePath),
835
831
  onentry: (entry) => {
836
- if (entry.path === "webskill.skill-manifest.json" || entry.path.endsWith(`/webskill.skill-manifest.json`)) {
832
+ if (entry.path === "webskill.skill-manifest.json" || entry.path.endsWith(`/${"webskill.skill-manifest.json"}`)) {
837
833
  const chunks = [];
838
834
  entry.on("data", (chunk) => chunks.push(chunk));
839
835
  entry.on("end", () => {
@@ -903,10 +899,6 @@ async function stageGit(source, ctx) {
903
899
  function sha256Hex(data) {
904
900
  return createHash("sha256").update(data).digest("hex");
905
901
  }
906
- /** 整体 digest:逐文件 "<path>:<sha256>\n" 拼接串(文件按 path 排序)的 sha256 */
907
- function computeDigest(files) {
908
- return sha256Hex([...files].sort((a, b) => a.path.localeCompare(b.path)).map((f) => `${f.path}:${f.sha256}\n`).join(""));
909
- }
910
902
  const messageOf$1 = (e) => e instanceof Error ? e.message : String(e);
911
903
  /** http 源:下载归档(可选 expectedSha256 校验包体)→ 解包 → 定位技能根 */
912
904
  async function stageHttp(source, ctx, expectedSha256) {
@@ -1041,18 +1033,14 @@ async function createManifest(fs, skillRoot, input) {
1041
1033
  sha256: sha256Hex(content)
1042
1034
  });
1043
1035
  }
1044
- const manifest = {
1045
- schemaVersion: 1,
1036
+ const manifest = await buildManifest({
1046
1037
  name: input.name,
1047
1038
  ...input.version !== void 0 ? { version: input.version } : {},
1048
1039
  source: input.source,
1049
1040
  installedAt: input.installedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1050
- integrity: {
1051
- algorithm: "sha256",
1052
- digest: computeDigest(files)
1053
- },
1054
- files
1055
- };
1041
+ files,
1042
+ sha256: sha256Hex
1043
+ });
1056
1044
  await fs.writeText(`${skillRoot}/${SKILL_MANIFEST_FILE}`, JSON.stringify(manifest, null, 2));
1057
1045
  return manifest;
1058
1046
  }
@@ -1066,22 +1054,15 @@ async function readManifest(fs, skillRoot) {
1066
1054
  throw new WebSkillError("INTEGRITY_FAILED", `Skill manifest at ${path} is corrupted: ${e instanceof Error ? e.message : String(e)}`, e);
1067
1055
  }
1068
1056
  }
1069
- /** 按 manifest.files 逐文件重算 sha256 比对 */
1057
+ /** 按 manifest.files 逐文件重算 sha256 比对(core 纯逻辑校验) */
1070
1058
  async function verifyIntegrity(fs, skillRoot) {
1071
1059
  const manifest = await readManifest(fs, skillRoot);
1072
- const mismatches = [];
1060
+ const actualHashes = /* @__PURE__ */ new Map();
1073
1061
  for (const file of manifest.files) {
1074
1062
  const path = `${skillRoot}/${file.path}`;
1075
- if (!await fs.exists(path)) {
1076
- mismatches.push(file.path);
1077
- continue;
1078
- }
1079
- if (sha256Hex(await fs.readBinary(path)) !== file.sha256) mismatches.push(file.path);
1063
+ if (await fs.exists(path)) actualHashes.set(file.path, sha256Hex(await fs.readBinary(path)));
1080
1064
  }
1081
- return {
1082
- ok: mismatches.length === 0,
1083
- mismatches
1084
- };
1065
+ return verifyManifest(manifest, actualHashes);
1085
1066
  }
1086
1067
  const messageOf = (e) => e instanceof Error ? e.message : String(e);
1087
1068
  const asInstallFailed = (e) => e instanceof WebSkillError && e.code === "INSTALL_FAILED" ? e : new WebSkillError("INSTALL_FAILED", `Install failed: ${messageOf(e)}`, e);
@@ -1126,6 +1107,7 @@ var SkillManager = class {
1126
1107
  case "npm":
1127
1108
  staged = await stageNpm(source, ctx);
1128
1109
  break;
1110
+ case "archive": throw new WebSkillError("TOOL_UNSUPPORTED", "The \"archive\" install source is only supported by the browser skill manager");
1129
1111
  }
1130
1112
  let name;
1131
1113
  let version;
@@ -1319,4 +1301,4 @@ async function doProbeLlmCapabilities(config) {
1319
1301
  }
1320
1302
 
1321
1303
  //#endregion
1322
- export { NodeScriptExecutor as a, SKILL_MANIFEST_FILE as c, loadLlmConfigFromEnv as d, probeLlmCapabilities as f, NodeFS as i, SandboxedScriptExecutor as l, FileArtifactStore as n, OxcSchemaInferer as o, readArchiveManifest as p, FileMemoryStore as r, SKILLS_LOCKFILE as s, CliUiBridge as t, SkillManager as u };
1304
+ export { NodeScriptExecutor as a, SkillManager as c, readArchiveManifest as d, NodeFS as i, loadLlmConfigFromEnv as l, FileArtifactStore as n, OxcSchemaInferer as o, FileMemoryStore as r, SandboxedScriptExecutor as s, CliUiBridge as t, probeLlmCapabilities as u };