@webskill/sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { H as SkillsLockfile, L as SkillManifest, P as SkillInstallSource, S as FileSystemProvider, W as VerifyResult, _ as RenderResultRequest, a as InteractionPolicy, c as LlmClient, d as LlmResponse, f as LlmStreamEvent, o as InteractionRequest, s as InteractionResponse, v as UiBridge, x as FileStat } from "./types-CgNC-oQu-Dq_A1yA-.js";
2
- import { K as ScriptExecutionContext, Y as ToolDefinition, Z as ToolResult, _ as ExternalToolSource, _t as parseBridgeRequest, c as ApprovalScope, d as BridgeRequest, f as BridgeResponse, g as ExternalSkillProvider, k as NetworkPolicy, l as BridgeCapabilities, ot as bridgeError, q as ScriptExecutor, rt as WebSkillApi } from "./index-oG5Nzgb9.js";
2
+ import { K as ScriptExecutionContext, Y as ToolDefinition, Z as ToolResult, _ as ExternalToolSource, _t as parseBridgeRequest, c as ApprovalScope, d as BridgeRequest, f as BridgeResponse, g as ExternalSkillProvider, k as NetworkPolicy, l as BridgeCapabilities, ot as bridgeError, q as ScriptExecutor, rt as WebSkillApi } from "./index-fjRF4H5o.js";
3
3
  //#region ../browser/dist/index.d.ts
4
4
  //#region src/fs/featureDetection.d.ts
5
5
  /** 检测当前环境是否可用 OPFS(navigator.storage.getDirectory) */
package/dist/browser.js CHANGED
@@ -1,6 +1,6 @@
1
- import { D as verifyManifest, E as validateSkills, S as parseSkillPackManifest, T as resolveInsideRoot, _ as exportSkills, c as SkillDiscovery, d as buildCatalog, f as buildManifest, i as SKILL_MANIFEST_FILE, r as SKILLS_LOCKFILE, s as SKILL_PACK_FILE, u as WebSkillError, v as isValidSkillName, x as parseSkillMarkdown } from "./memoryArtifactStore-C9lFVqPF-U8nXvqL9.js";
2
- import { A as normalizeToolContent, C as createWebSkillApi, D as isNetworkAllowed, O as mergeCatalogEntries, _ as RUN_SNAPSHOT_SCHEMA_VERSION, a as CapabilityApproval, b as bridgeError, c as FsMemoryStore, f as OpenAiCompatibleClient, i as AgentLoop, j as parseBridgeRequest, k as networkUrlHost, l as FsRunSnapshotStore, p as ProgressiveRouter, s as FsArtifactStore } from "./dist-D5fsiETF.js";
3
- import { n as MockLlmClient } from "./testing-pn3NhXSV.js";
1
+ import { E as verifyManifest, T as validateSkills, _ as isValidSkillName, b as parseSkillMarkdown, d as buildManifest, g as exportSkills, l as WebSkillError, n as SKILLS_LOCKFILE, o as SKILL_PACK_FILE, r as SKILL_MANIFEST_FILE, s as SkillDiscovery, u as buildCatalog, w as resolveInsideRoot, x as parseSkillPackManifest } from "./dist-DS1sfgHa.js";
2
+ import { A as normalizeToolContent, C as createWebSkillApi, D as isNetworkAllowed, O as mergeCatalogEntries, _ as RUN_SNAPSHOT_SCHEMA_VERSION, a as CapabilityApproval, b as bridgeError, c as FsMemoryStore, f as OpenAiCompatibleClient, i as AgentLoop, j as parseBridgeRequest, k as networkUrlHost, l as FsRunSnapshotStore, p as ProgressiveRouter, s as FsArtifactStore } from "./dist-DRsnVw6A.js";
3
+ import { n as MockLlmClient } from "./testing-CbM6rJ-E.js";
4
4
  import { unzipSync } from "fflate";
5
5
 
6
6
  //#region ../browser/dist/index.js
@@ -1,4 +1,5 @@
1
- import { C as renderAvailableSkillsXml, E as validateSkills, T as resolveInsideRoot, c as SkillDiscovery, d as buildCatalog, l as SkillReader, t as MemoryArtifactStore, u as WebSkillError, x as parseSkillMarkdown } from "./memoryArtifactStore-C9lFVqPF-U8nXvqL9.js";
1
+ import { S as renderAvailableSkillsXml, T as validateSkills, b as parseSkillMarkdown, c as SkillReader, l as WebSkillError, s as SkillDiscovery, u as buildCatalog, w as resolveInsideRoot } from "./dist-DS1sfgHa.js";
2
+ import { t as MemoryArtifactStore } from "./memoryArtifactStore-C9lFVqPF-yFz6yJj0.js";
2
3
 
3
4
  //#region ../runtime/dist/index.js
4
5
  const toOpenAiMessage = (msg) => {
@@ -421,7 +422,7 @@ const ASK_USER_TOOL = {
421
422
  * 不暴露 fs 本体(沙箱语义,对齐 deferred-items D1)。
422
423
  */
423
424
  function createScriptContext(deps) {
424
- const { fs, artifactStore, skillName, skillRoot, runId, confirm, onWarning } = deps;
425
+ const { fs, artifactStore, skillName, skillRoot, runId, confirm, onWarning, onArtifactCreated } = deps;
425
426
  return {
426
427
  skillName,
427
428
  runId,
@@ -429,17 +430,19 @@ function createScriptContext(deps) {
429
430
  return fs.readText(resolveInsideRoot(skillRoot, `references/${relativePath}`));
430
431
  },
431
432
  async writeArtifact(path, content, options) {
432
- return typeof content === "string" ? artifactStore.createTextArtifact({
433
+ const artifact = typeof content === "string" ? await artifactStore.createTextArtifact({
433
434
  runId,
434
435
  path,
435
436
  content,
436
437
  mimeType: options?.mimeType
437
- }) : artifactStore.createBinaryArtifact({
438
+ }) : await artifactStore.createBinaryArtifact({
438
439
  runId,
439
440
  path,
440
441
  content,
441
442
  mimeType: options?.mimeType
442
443
  });
444
+ onArtifactCreated?.(artifact);
445
+ return artifact;
443
446
  },
444
447
  ...confirm ? { confirm } : {},
445
448
  ...onWarning ? { onWarning } : {}
@@ -1136,7 +1139,7 @@ var AgentLoop = class {
1136
1139
  try {
1137
1140
  const text = await state.reader.readSkillFile(skillName, pathArg);
1138
1141
  let note = "";
1139
- if (pathArg === "SKILL.md" && !state.activated.has(skillName)) note = await this.#activateSkill(skillName, state);
1142
+ if (pathArg === "SKILL.md" && !state.activated.has(skillName)) note = await this.#activateSkill(skillName, state, void 0, text);
1140
1143
  return {
1141
1144
  ok: true,
1142
1145
  content: [{
@@ -1190,7 +1193,7 @@ var AgentLoop = class {
1190
1193
  return toolError("SKILL_NOT_FOUND", `Skill not found via external providers: ${skillKey}`);
1191
1194
  }
1192
1195
  /** 首次读到 SKILL.md 时激活技能:加载其 scripts 工具定义,供后续轮次使用;dependencies 级联激活(via 记录来源) */
1193
- async #activateSkill(skillName, state, via) {
1196
+ async #activateSkill(skillName, state, via, skillMdText) {
1194
1197
  state.activated.add(skillName);
1195
1198
  state.trace.record("skill.activated", { data: {
1196
1199
  skillName,
@@ -1203,11 +1206,11 @@ var AgentLoop = class {
1203
1206
  let allowedTools;
1204
1207
  let dependencies = [];
1205
1208
  try {
1206
- const { metadata } = parseSkillMarkdown(await this.#deps.fs.readText(`${root}/SKILL.md`));
1209
+ const { metadata } = parseSkillMarkdown(skillMdText ?? await this.#deps.fs.readText(`${root}/SKILL.md`));
1207
1210
  const rawDeps = metadata["dependencies"];
1208
1211
  if (Array.isArray(rawDeps)) dependencies = rawDeps.filter((d) => typeof d === "string");
1209
- const raw = metadata["allowed-tools"];
1210
- if (raw !== void 0) if (Array.isArray(raw)) allowedTools = raw.filter((e) => typeof e === "string");
1212
+ const rawAllowed = metadata["allowed-tools"];
1213
+ if (rawAllowed !== void 0) if (Array.isArray(rawAllowed)) allowedTools = rawAllowed.filter((e) => typeof e === "string");
1211
1214
  else state.trace.record("run.warning", { message: `Skill "${skillName}" has a non-array "allowed-tools" metadata entry; ignored` });
1212
1215
  } catch {}
1213
1216
  const executor = this.#deps.executor;
@@ -1290,6 +1293,7 @@ var AgentLoop = class {
1290
1293
  if (e instanceof BridgeRequestError) return toolError("UI_UNAVAILABLE", `Parameter form failed: ${e.message}`);
1291
1294
  throw e;
1292
1295
  }
1296
+ const createdIds = /* @__PURE__ */ new Set();
1293
1297
  const context = createScriptContext({
1294
1298
  fs: this.#deps.fs,
1295
1299
  artifactStore: this.#deps.artifactStore,
@@ -1297,10 +1301,10 @@ var AgentLoop = class {
1297
1301
  skillRoot: root,
1298
1302
  runId: state.runId,
1299
1303
  confirm: (message) => this.#confirm(message, state),
1300
- onWarning: (message) => state.trace.record("run.warning", { message })
1304
+ onWarning: (message) => state.trace.record("run.warning", { message }),
1305
+ onArtifactCreated: (artifact) => createdIds.add(artifact.id)
1301
1306
  });
1302
1307
  try {
1303
- const before = new Set((await this.#deps.artifactStore.listArtifacts(state.runId)).map((a) => a.id));
1304
1308
  const result = await this.#deps.executor.execute({
1305
1309
  skillRoot: root,
1306
1310
  scriptName,
@@ -1308,8 +1312,10 @@ var AgentLoop = class {
1308
1312
  context,
1309
1313
  timeoutMs: state.toolTimeoutMs
1310
1314
  });
1311
- const fresh = (await this.#deps.artifactStore.listArtifacts(state.runId)).filter((a) => !before.has(a.id));
1312
- if (fresh.length > 0) result.artifacts = [...result.artifacts ?? [], ...fresh];
1315
+ if (createdIds.size > 0) {
1316
+ const fresh = (await this.#deps.artifactStore.listArtifacts(state.runId)).filter((a) => createdIds.has(a.id));
1317
+ if (fresh.length > 0) result.artifacts = [...result.artifacts ?? [], ...fresh];
1318
+ }
1313
1319
  await this.#bumpSkillStat(skillName, result.ok ? "successes" : "failures", state);
1314
1320
  return result;
1315
1321
  } catch (e) {
@@ -1623,6 +1629,16 @@ var WebSkillRuntime = class {
1623
1629
  function createWebSkillApi(deps) {
1624
1630
  const { fs, roots } = deps;
1625
1631
  let runtime;
1632
+ const discoveries = /* @__PURE__ */ new Map();
1633
+ const discoveryFor = (paths) => {
1634
+ const key = paths.join("");
1635
+ let discovery = discoveries.get(key);
1636
+ if (!discovery) {
1637
+ discovery = new SkillDiscovery(fs, paths);
1638
+ discoveries.set(key, discovery);
1639
+ }
1640
+ return discovery;
1641
+ };
1626
1642
  const lazyRuntime = () => {
1627
1643
  runtime ??= new WebSkillRuntime({
1628
1644
  fs,
@@ -1640,11 +1656,11 @@ function createWebSkillApi(deps) {
1640
1656
  };
1641
1657
  return {
1642
1658
  async discover(path) {
1643
- const { entries } = await new SkillDiscovery(fs, [path]).discover();
1659
+ const { entries } = await discoveryFor([path]).discover();
1644
1660
  return buildCatalog(entries);
1645
1661
  },
1646
1662
  async read(name) {
1647
- const { entries } = await new SkillDiscovery(fs, roots).discover();
1663
+ const { entries } = await discoveryFor(roots).discover();
1648
1664
  const entry = entries.find((e) => e.name === name);
1649
1665
  if (!entry) throw new WebSkillError("SKILL_NOT_FOUND", `Unknown skill: ${name}`);
1650
1666
  const skillMdPath = `${entry.root}/SKILL.md`;
@@ -1679,13 +1695,21 @@ function createWebSkillApi(deps) {
1679
1695
  }
1680
1696
  };
1681
1697
  }
1682
- /** install URL 分派:http(s)…​.zip → http;…​.git → git(无 git 能力的 manager 自行 TOOL_UNSUPPORTED);其余 → local */
1698
+ /** install URL 分派:http(s)…​.zip → http;…​.git → git(无 git 能力的 manager 自行 TOOL_UNSUPPORTED);
1699
+ * 其余 http(s) URL → INSTALL_FAILED(不静默当 local);非 URL → local */
1683
1700
  function sourceFromUrl(url) {
1684
1701
  const bare = url.split("?")[0] ?? url;
1685
- if (/^https?:\/\//.test(url) && bare.endsWith(".zip")) return {
1686
- type: "http",
1687
- url
1688
- };
1702
+ if (/^https?:\/\//.test(url)) {
1703
+ if (bare.endsWith(".zip")) return {
1704
+ type: "http",
1705
+ url
1706
+ };
1707
+ if (bare.endsWith(".git")) return {
1708
+ type: "git",
1709
+ url
1710
+ };
1711
+ throw new WebSkillError("INSTALL_FAILED", `Unsupported install URL "${url}" (supported: http(s) URLs ending in .zip or .git, or local paths)`);
1712
+ }
1689
1713
  if (bare.endsWith(".git")) return {
1690
1714
  type: "git",
1691
1715
  url
@@ -587,51 +587,4 @@ const xmlRenderer = {
587
587
  };
588
588
 
589
589
  //#endregion
590
- //#region ../runtime/dist/memoryArtifactStore-C9lFVqPF.js
591
- /** 内存 ArtifactStore:测试与浏览器降级用;索引随进程生命周期存在 */
592
- var MemoryArtifactStore = class {
593
- #byRun = /* @__PURE__ */ new Map();
594
- #seq = 0;
595
- async createTextArtifact(input) {
596
- return this.#record({
597
- runId: input.runId,
598
- path: input.path,
599
- type: "text",
600
- size: new TextEncoder().encode(input.content).length,
601
- mimeType: input.mimeType,
602
- metadata: input.metadata
603
- });
604
- }
605
- async createBinaryArtifact(input) {
606
- return this.#record({
607
- runId: input.runId,
608
- path: input.path,
609
- type: "binary",
610
- size: input.content.length,
611
- mimeType: input.mimeType,
612
- metadata: input.metadata
613
- });
614
- }
615
- async listArtifacts(runId) {
616
- return [...this.#byRun.get(runId) ?? []];
617
- }
618
- #record(input) {
619
- const artifact = {
620
- id: `art-${++this.#seq}`,
621
- runId: input.runId,
622
- path: input.path,
623
- type: input.type,
624
- mimeType: input.mimeType,
625
- size: input.size,
626
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
627
- metadata: input.metadata
628
- };
629
- const list = this.#byRun.get(input.runId) ?? [];
630
- list.push(artifact);
631
- this.#byRun.set(input.runId, list);
632
- return artifact;
633
- }
634
- };
635
-
636
- //#endregion
637
- export { renderAvailableSkillsXml as C, verifyManifest as D, validateSkills as E, xmlRenderer as O, parseSkillPackManifest as S, resolveInsideRoot as T, exportSkills as _, SKILL_NAME_MAX_LENGTH as a, normalizePath as b, SkillDiscovery as c, buildCatalog as d, buildManifest as f, escapeXml as g, computeDigest as h, SKILL_MANIFEST_FILE as i, SkillReader as l, checkSkillRules as m, MemoryFS as n, SKILL_NAME_PATTERN as o, checkDependencyCycles as p, SKILLS_LOCKFILE as r, SKILL_PACK_FILE as s, MemoryArtifactStore as t, WebSkillError as u, isValidSkillName as v, renderCatalogJson as w, parseSkillMarkdown as x, jsonRenderer as y };
590
+ export { renderCatalogJson as C, xmlRenderer as D, verifyManifest as E, renderAvailableSkillsXml as S, validateSkills as T, isValidSkillName as _, SKILL_NAME_PATTERN as a, parseSkillMarkdown as b, SkillReader as c, buildManifest as d, checkDependencyCycles as f, exportSkills as g, escapeXml as h, SKILL_NAME_MAX_LENGTH as i, WebSkillError as l, computeDigest as m, SKILLS_LOCKFILE as n, SKILL_PACK_FILE as o, checkSkillRules as p, SKILL_MANIFEST_FILE as r, SkillDiscovery as s, MemoryFS as t, buildCatalog as u, jsonRenderer as v, resolveInsideRoot as w, parseSkillPackManifest as x, normalizePath as y };