@frontmcp/sdk 1.11.0 → 1.11.1-rc.1

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.
Files changed (131) hide show
  1. package/browser/common/entries/scope.entry.mjs +16 -0
  2. package/browser/common/metadata/plugin.metadata.mjs +2 -1
  3. package/browser/common/schemas/http-output.schema.mjs +12 -1
  4. package/browser/common/tokens/plugin.tokens.mjs +2 -1
  5. package/browser/common/types/options/skills-http/schema.mjs +13 -0
  6. package/browser/direct/direct-client.mjs +8 -0
  7. package/browser/direct/token-auth-info.mjs +31 -0
  8. package/browser/errors/http-route.errors.mjs +9 -0
  9. package/browser/errors/index.mjs +3 -1
  10. package/browser/errors/misconfiguration.mjs +2 -1
  11. package/browser/errors/plugin.errors.mjs +10 -0
  12. package/browser/front-mcp/front-mcp.mjs +6 -2
  13. package/browser/health/health.service.mjs +4 -0
  14. package/browser/http-route/flows/http.route.flow.mjs +47 -19
  15. package/browser/index.cjs +1404 -835
  16. package/browser/index.mjs +12 -2
  17. package/browser/job/enclave/browser-enclave-core.mjs +9 -0
  18. package/browser/job/enclave/job-enclave.bridge.mjs +3 -20
  19. package/browser/plugin/plugin.registry.mjs +17 -1
  20. package/browser/resource/flows/resources-list.flow.mjs +31 -1
  21. package/browser/scope/scope.instance.mjs +6 -4
  22. package/browser/server/server.validation.mjs +3 -6
  23. package/browser/skill/decision/decisions-api.decider.mjs +62 -0
  24. package/browser/skill/decision/skill-decision.ranker.mjs +96 -0
  25. package/browser/skill/flows/load-skill.flow.mjs +15 -10
  26. package/browser/skill/index.mjs +4 -0
  27. package/browser/skill/providers/memory-skill.provider.mjs +41 -135
  28. package/browser/skill/sep-2640/resources/skill-md.resource.mjs +3 -3
  29. package/browser/skill/sep-2640/sep-2640.builders.mjs +24 -2
  30. package/browser/skill/sep-2640/sep-2640.per-skill.mjs +3 -4
  31. package/browser/skill/sep-2640/sep-2640.resource-helpers.mjs +10 -1
  32. package/browser/skill/skill-catalog-source.mjs +23 -0
  33. package/browser/skill/skill-instructions.helper.mjs +23 -5
  34. package/browser/skill/skill-search-text.mjs +166 -0
  35. package/browser/skill/skill.registry.mjs +58 -3
  36. package/browser/subsystems.mjs +14 -1
  37. package/browser/transport/mcp-handlers/skills-mcp.types.mjs +5 -3
  38. package/browser/transport/relay/relay-http.mjs +2 -1
  39. package/browser/transport/web-response.renderer.mjs +6 -2
  40. package/browser/utils/http-location.utils.mjs +8 -0
  41. package/common/decorators/tool.decorator.d.ts +2 -1
  42. package/common/decorators/tool.decorator.d.ts.map +1 -1
  43. package/common/entries/scope.entry.d.ts +8 -0
  44. package/common/entries/scope.entry.d.ts.map +1 -1
  45. package/common/interfaces/skill.interface.d.ts +5 -0
  46. package/common/interfaces/skill.interface.d.ts.map +1 -1
  47. package/common/metadata/front-mcp.metadata.d.ts +90 -0
  48. package/common/metadata/front-mcp.metadata.d.ts.map +1 -1
  49. package/common/metadata/plugin.metadata.d.ts +8 -0
  50. package/common/metadata/plugin.metadata.d.ts.map +1 -1
  51. package/common/schemas/http-output.schema.d.ts.map +1 -1
  52. package/common/tokens/plugin.tokens.d.ts +1 -0
  53. package/common/tokens/plugin.tokens.d.ts.map +1 -1
  54. package/common/types/options/skills-http/interfaces.d.ts +16 -0
  55. package/common/types/options/skills-http/interfaces.d.ts.map +1 -1
  56. package/common/types/options/skills-http/schema.d.ts +11 -0
  57. package/common/types/options/skills-http/schema.d.ts.map +1 -1
  58. package/direct/client.types.d.ts +27 -8
  59. package/direct/client.types.d.ts.map +1 -1
  60. package/direct/create.types.d.ts +6 -1
  61. package/direct/create.types.d.ts.map +1 -1
  62. package/direct/token-auth-info.d.ts +5 -0
  63. package/direct/token-auth-info.d.ts.map +1 -0
  64. package/errors/http-route.errors.d.ts +4 -0
  65. package/errors/http-route.errors.d.ts.map +1 -1
  66. package/errors/index.d.ts +1 -1
  67. package/errors/index.d.ts.map +1 -1
  68. package/errors/misconfiguration.d.ts.map +1 -1
  69. package/errors/plugin.errors.d.ts +4 -0
  70. package/errors/plugin.errors.d.ts.map +1 -1
  71. package/esm/index.mjs +30 -22
  72. package/front-mcp/front-mcp.d.ts +3 -0
  73. package/front-mcp/front-mcp.d.ts.map +1 -1
  74. package/health/health.service.d.ts +4 -1
  75. package/health/health.service.d.ts.map +1 -1
  76. package/http-route/flows/http.route.flow.d.ts +6 -0
  77. package/http-route/flows/http.route.flow.d.ts.map +1 -1
  78. package/index.d.ts +9 -9
  79. package/index.d.ts.map +1 -1
  80. package/index.js +43 -35
  81. package/job/enclave/browser-enclave-core.d.ts +3 -0
  82. package/job/enclave/browser-enclave-core.d.ts.map +1 -0
  83. package/job/enclave/enclave-core.d.ts +3 -0
  84. package/job/enclave/enclave-core.d.ts.map +1 -0
  85. package/job/enclave/job-enclave.bridge.d.ts +1 -9
  86. package/job/enclave/job-enclave.bridge.d.ts.map +1 -1
  87. package/package.json +16 -11
  88. package/plugin/plugin.registry.d.ts +2 -0
  89. package/plugin/plugin.registry.d.ts.map +1 -1
  90. package/resource/flows/resources-list.flow.d.ts +3 -1
  91. package/resource/flows/resources-list.flow.d.ts.map +1 -1
  92. package/scope/scope.instance.d.ts.map +1 -1
  93. package/server/server.validation.d.ts.map +1 -1
  94. package/skill/decision/decisions-api.decider.d.ts +26 -0
  95. package/skill/decision/decisions-api.decider.d.ts.map +1 -0
  96. package/skill/decision/index.d.ts +4 -0
  97. package/skill/decision/index.d.ts.map +1 -0
  98. package/skill/decision/skill-decision.ranker.d.ts +28 -0
  99. package/skill/decision/skill-decision.ranker.d.ts.map +1 -0
  100. package/skill/decision/skill-decision.types.d.ts +63 -0
  101. package/skill/decision/skill-decision.types.d.ts.map +1 -0
  102. package/skill/flows/load-skill.flow.d.ts +6 -4
  103. package/skill/flows/load-skill.flow.d.ts.map +1 -1
  104. package/skill/index.d.ts +5 -0
  105. package/skill/index.d.ts.map +1 -1
  106. package/skill/providers/memory-skill.provider.d.ts +10 -12
  107. package/skill/providers/memory-skill.provider.d.ts.map +1 -1
  108. package/skill/sep-2640/sep-2640.builders.d.ts +7 -2
  109. package/skill/sep-2640/sep-2640.builders.d.ts.map +1 -1
  110. package/skill/sep-2640/sep-2640.per-skill.d.ts.map +1 -1
  111. package/skill/sep-2640/sep-2640.resource-helpers.d.ts +5 -0
  112. package/skill/sep-2640/sep-2640.resource-helpers.d.ts.map +1 -1
  113. package/skill/skill-catalog-source.d.ts +47 -0
  114. package/skill/skill-catalog-source.d.ts.map +1 -0
  115. package/skill/skill-instructions.helper.d.ts +10 -0
  116. package/skill/skill-instructions.helper.d.ts.map +1 -1
  117. package/skill/skill-search-text.d.ts +60 -0
  118. package/skill/skill-search-text.d.ts.map +1 -0
  119. package/skill/skill-storage.interface.d.ts +5 -0
  120. package/skill/skill-storage.interface.d.ts.map +1 -1
  121. package/skill/skill.registry.d.ts +20 -0
  122. package/skill/skill.registry.d.ts.map +1 -1
  123. package/subsystems.d.ts +1 -1
  124. package/subsystems.d.ts.map +1 -1
  125. package/transport/mcp-handlers/index.d.ts +1 -1
  126. package/transport/mcp-handlers/skills-mcp.types.d.ts +3 -2
  127. package/transport/mcp-handlers/skills-mcp.types.d.ts.map +1 -1
  128. package/transport/relay/relay-http.d.ts.map +1 -1
  129. package/transport/web-response.renderer.d.ts.map +1 -1
  130. package/utils/http-location.utils.d.ts +8 -0
  131. package/utils/http-location.utils.d.ts.map +1 -0
@@ -11,78 +11,14 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  // libs/sdk/src/skill/providers/memory-skill.provider.ts
12
12
  import { sha256Hex } from "@frontmcp/utils";
13
13
  import { importWithRequireFallback } from "../../utils/dynamic-import.utils.mjs";
14
- var STOP_WORDS = /* @__PURE__ */ new Set([
15
- // Articles & Determiners
16
- "the",
17
- "a",
18
- "an",
19
- "this",
20
- "that",
21
- "these",
22
- "those",
23
- // Prepositions
24
- "in",
25
- "on",
26
- "at",
27
- "to",
28
- "for",
29
- "of",
30
- "with",
31
- "by",
32
- "from",
33
- "into",
34
- // Conjunctions
35
- "and",
36
- "or",
37
- "but",
38
- "so",
39
- "as",
40
- "if",
41
- "when",
42
- "where",
43
- // Pronouns
44
- "i",
45
- "me",
46
- "my",
47
- "you",
48
- "your",
49
- "it",
50
- "its",
51
- "we",
52
- "our",
53
- "they",
54
- "their",
55
- // Auxiliary verbs
56
- "is",
57
- "was",
58
- "are",
59
- "were",
60
- "be",
61
- "been",
62
- "being",
63
- "have",
64
- "has",
65
- "had",
66
- "do",
67
- "does",
68
- "did",
69
- "will",
70
- "would",
71
- "can",
72
- "could",
73
- "should",
74
- "may",
75
- "might",
76
- // Common fillers
77
- "please",
78
- "help",
79
- "want",
80
- "need",
81
- "like",
82
- "just",
83
- "how",
84
- "what"
85
- ]);
14
+ import {
15
+ negativeQueryShare,
16
+ queryTerms,
17
+ queryTermShare,
18
+ SKILL_TOKENIZER_ID,
19
+ skillSearchText,
20
+ skillTokenizer
21
+ } from "../skill-search-text.mjs";
86
22
  function isSnapshotCapable(db) {
87
23
  const d = db;
88
24
  return typeof d.toSnapshot === "function" && typeof d.loadSnapshot === "function";
@@ -101,6 +37,13 @@ var MemorySkillProvider = class {
101
37
  scoring;
102
38
  /** Optional snapshot cache for fast cold-start (e.g. KV-backed on the edge). */
103
39
  indexCache;
40
+ /**
41
+ * The index's tokenizer, set when the index is created: vectoriadb's (2.3.4 and later), without stop words. The
42
+ * text fallback matches with it too. Unset on an older vectoriadb, which tokenizes ASCII only.
43
+ */
44
+ tokenizer;
45
+ /** The id of {@link tokenizer}, part of the snapshot cache key; unset with an older vectoriadb's tokenizer. */
46
+ tokenizerId;
104
47
  /**
105
48
  * The index is rebuilt from `skills` when it is stale: adds/removes bump
106
49
  * `skillsVersion`, and the FIRST search after a mutation builds (or restores)
@@ -117,15 +60,23 @@ var MemorySkillProvider = class {
117
60
  this.indexCache = options.indexCache;
118
61
  }
119
62
  async createVectorDB() {
120
- const { TFIDFVectoria } = await importWithRequireFallback(
63
+ const vectoriadb = await importWithRequireFallback(
121
64
  () => import("vectoriadb"),
122
65
  () => __require("vectoriadb")
123
66
  );
67
+ const { TFIDFVectoria } = vectoriadb;
124
68
  const dbConfig = {
125
69
  defaultTopK: this.defaultTopK,
126
70
  defaultSimilarityThreshold: this.defaultMinScore
127
71
  };
128
72
  if (this.scoring !== "cosine") dbConfig.scoring = this.scoring;
73
+ const { defaultTokenizer, DEFAULT_TOKENIZER_ID } = vectoriadb;
74
+ if (typeof defaultTokenizer === "function") {
75
+ this.tokenizer = skillTokenizer(defaultTokenizer);
76
+ dbConfig.tokenizer = this.tokenizer;
77
+ dbConfig.tokenizerId = `${SKILL_TOKENIZER_ID}+${DEFAULT_TOKENIZER_ID ?? "unknown"}`;
78
+ this.tokenizerId = dbConfig.tokenizerId;
79
+ }
129
80
  return new TFIDFVectoria(dbConfig);
130
81
  }
131
82
  /**
@@ -197,18 +148,19 @@ var MemorySkillProvider = class {
197
148
  toDocument(skill) {
198
149
  return {
199
150
  id: skill.id,
200
- text: this.buildSearchableText(skill),
151
+ text: skillSearchText(skill),
201
152
  metadata: { id: skill.id, skillId: skill.id, skill }
202
153
  };
203
154
  }
204
155
  /**
205
- * Stable content hash of the indexed skill set + scoring mode. Changing any
206
- * skill's searchable text, the set of skills, or the scoring mode changes the
207
- * key, so a stale snapshot is never restored.
156
+ * Stable content hash of the indexed skill set, scoring mode and tokenizer. Changing any skill's searchable text,
157
+ * the set of skills, the scoring mode or the tokenizer changes the key, so a stale snapshot is never restored, and
158
+ * the snapshot built for a new tokenizer is saved under a key the next cold start finds.
208
159
  */
209
160
  async computeIndexKey() {
210
- const parts = Array.from(this.skills.values()).map((s) => `${s.id}\0${this.buildSearchableText(s)}`).sort();
211
- const canonical = `frontmcp-skill-index:v1|${this.scoring}|${this.skills.size}|${parts.join("")}`;
161
+ const parts = Array.from(this.skills.values()).map((s) => `${s.id}\0${s.bundleVersion ?? ""}\0${skillSearchText(s)}`).sort();
162
+ const tokenizer = this.tokenizerId ?? "ascii";
163
+ const canonical = `frontmcp-skill-index:v1|${this.scoring}|${tokenizer}|${this.skills.size}|${parts.join("")}`;
212
164
  return sha256Hex(canonical);
213
165
  }
214
166
  async db() {
@@ -278,7 +230,7 @@ var MemorySkillProvider = class {
278
230
  ...options.negativeWeight !== void 0 ? { negativeWeight: options.negativeWeight } : {}
279
231
  });
280
232
  if (results.length === 0 && query.trim().length > 0 && this.skills.size > 0) {
281
- results = this.fallbackTextSearch(query, topK, filter);
233
+ results = this.fallbackTextSearch(query, topK, filter, options.negativeQuery, options.negativeWeight);
282
234
  }
283
235
  const searchResults = [];
284
236
  for (const result of results) {
@@ -296,7 +248,8 @@ var MemorySkillProvider = class {
296
248
  score: result.score,
297
249
  availableTools: validation?.available ?? toolNames,
298
250
  missingTools: validation?.missing ?? [],
299
- source: "local"
251
+ source: "local",
252
+ ...skill.bundleVersion !== void 0 && { bundleVersion: skill.bundleVersion }
300
253
  });
301
254
  }
302
255
  return searchResults;
@@ -412,60 +365,13 @@ var MemorySkillProvider = class {
412
365
  for (const skill of skills) this.skills.set(skill.id, skill);
413
366
  this.markStale();
414
367
  }
415
- /**
416
- * Build searchable text for TF-IDF indexing.
417
- * Uses term weighting to improve relevance:
418
- * - Description: 3x weight (most important for matching)
419
- * - Tags: 2x weight
420
- * - Tools: 1x weight
421
- * - Name: 1x weight
422
- */
423
- buildSearchableText(skill) {
424
- const parts = [];
425
- if (skill.name) {
426
- const nameParts = skill.name.split(/[:\-_.\s]/).filter(Boolean);
427
- parts.push(...nameParts);
428
- }
429
- if (skill.description) {
430
- parts.push(skill.description, skill.description, skill.description);
431
- const keyTerms = skill.description.toLowerCase().split(/\s+/).filter((word) => word.length >= 4 && !STOP_WORDS.has(word));
432
- parts.push(...keyTerms);
433
- }
434
- const tags = this.getSkillTags(skill);
435
- for (const tag of tags) {
436
- parts.push(tag, tag);
437
- }
438
- for (const tool of skill.tools) {
439
- parts.push(tool.name);
440
- if (tool.purpose) {
441
- parts.push(tool.purpose);
442
- }
443
- }
444
- if (skill.parameters) {
445
- for (const param of skill.parameters) {
446
- parts.push(param.name);
447
- if (param.description) {
448
- parts.push(param.description);
449
- }
450
- }
451
- }
452
- if (skill.examples) {
453
- for (const example of skill.examples) {
454
- parts.push(example.scenario);
455
- if (example.expectedOutcome) {
456
- parts.push(example.expectedOutcome);
457
- }
458
- }
459
- }
460
- return parts.join(" ");
461
- }
462
368
  /**
463
369
  * Fallback text search when TF-IDF produces no results (e.g., single-document corpus).
464
370
  * Performs case-insensitive substring matching on the searchable text.
465
371
  */
466
- fallbackTextSearch(query, topK, filter) {
467
- const queryTerms = query.toLowerCase().split(/\s+/).filter((t) => t.length > 0 && !STOP_WORDS.has(t));
468
- if (queryTerms.length === 0) {
372
+ fallbackTextSearch(query, topK, filter, negativeQuery, negativeWeight = 1) {
373
+ const terms = queryTerms(query, this.tokenizer);
374
+ if (terms.length === 0) {
469
375
  return [];
470
376
  }
471
377
  const matches = [];
@@ -474,13 +380,13 @@ var MemorySkillProvider = class {
474
380
  if (!filter(metadata)) {
475
381
  return;
476
382
  }
477
- const searchableText = this.buildSearchableText(skill);
478
- const matchCount = queryTerms.filter((term) => searchableText.toLowerCase().includes(term)).length;
479
- if (matchCount > 0) {
383
+ const searchableText = skillSearchText(skill);
384
+ const score = queryTermShare(terms, searchableText, this.tokenizer) - negativeWeight * negativeQueryShare(negativeQuery, searchableText, this.tokenizer);
385
+ if (score > 0) {
480
386
  matches.push({
481
387
  id: skill.id,
482
388
  text: searchableText,
483
- score: matchCount / queryTerms.length,
389
+ score,
484
390
  metadata
485
391
  });
486
392
  }
@@ -14,13 +14,13 @@ import { ResourceTemplate } from "../../../common/index.mjs";
14
14
  import { ResourceContext } from "../../../common/interfaces/index.mjs";
15
15
  import { assertSkillAuthorized, filterSkillsByAuthorities } from "../../skill-authorities.helper.mjs";
16
16
  import { filterServableSkills } from "../../skill-filter.helper.mjs";
17
- import { serializeSkillMd } from "../sep-2640.builders.mjs";
18
17
  import { SKILL_MD_MIME_TYPE } from "../sep-2640.constants.mjs";
19
18
  import {
20
19
  findAndLoadSkillByPath,
21
20
  findSkillByPath,
22
21
  getSepVisibleSkills,
23
- loadExternalProviderSkill
22
+ loadExternalProviderSkill,
23
+ renderSkillMd
24
24
  } from "../sep-2640.resource-helpers.mjs";
25
25
  var Sep2640SkillMdResource = class extends ResourceContext {
26
26
  async skillPathCompleter(partial) {
@@ -36,7 +36,7 @@ var Sep2640SkillMdResource = class extends ResourceContext {
36
36
  return { values: filtered, total: filtered.length };
37
37
  }
38
38
  async execute(uri, params) {
39
- const raw = serializeSkillMd(await this.readSkill(params.skillPath));
39
+ const raw = await renderSkillMd(this.scope, await this.readSkill(params.skillPath), this.getAuthInfo());
40
40
  return {
41
41
  contents: [
42
42
  {
@@ -61,7 +61,7 @@ function buildFrontmatter(skill) {
61
61
  }
62
62
  return fm;
63
63
  }
64
- function serializeSkillMd(skill, rawInstructions) {
64
+ function serializeSkillMd(skill, rawInstructions, actions) {
65
65
  const fm = buildFrontmatter(skill);
66
66
  const yamlBlock = yaml.dump(fm, {
67
67
  lineWidth: -1,
@@ -70,13 +70,35 @@ function serializeSkillMd(skill, rawInstructions) {
70
70
  sortKeys: false
71
71
  }).trimEnd();
72
72
  const body = (rawInstructions ?? skill.instructions).trimEnd();
73
+ const actionsSection = actions && actions.actions.length > 0 ? `
74
+
75
+ ${buildActionsSection(actions)}` : "";
73
76
  return `---
74
77
  ${yamlBlock}
75
78
  ---
76
79
 
77
- ${body}
80
+ ${body}${actionsSection}
78
81
  `;
79
82
  }
83
+ function buildActionsSection({ hint, actions }) {
84
+ const sections = actions.map(
85
+ (action) => [
86
+ `### ${action.actionId}`,
87
+ action.summary,
88
+ ...action.description ? [action.description.trimEnd()] : [],
89
+ `Input:
90
+
91
+ ${jsonBlock(action.inputJsonSchema)}`,
92
+ `Output:
93
+
94
+ ${jsonBlock(action.outputJsonSchema)}`
95
+ ].join("\n\n")
96
+ );
97
+ return ["## Actions", hint, ...sections].join("\n\n");
98
+ }
99
+ function jsonBlock(value) {
100
+ return "```json\n" + JSON.stringify(value, null, 2) + "\n```";
101
+ }
80
102
  function metadataToContentStub(metadata) {
81
103
  return {
82
104
  name: metadata.name,
@@ -4,9 +4,8 @@ import {
4
4
  FrontMcpSkillTokens
5
5
  } from "../../common/index.mjs";
6
6
  import { ResourceKind } from "../../common/records/resource.record.mjs";
7
- import { serializeSkillMd } from "./sep-2640.builders.mjs";
8
7
  import { SEP_2640_META_NAMESPACE, SKILL_MD_MIME_TYPE, SKILL_MD_PRIORITY } from "./sep-2640.constants.mjs";
9
- import { findAndLoadSkillByPath } from "./sep-2640.resource-helpers.mjs";
8
+ import { findAndLoadSkillByPath, renderSkillMd } from "./sep-2640.resource-helpers.mjs";
10
9
  import { buildSkillUri } from "./sep-2640.uri.mjs";
11
10
  function skillExtensionMetadata(skill) {
12
11
  const extensions = {};
@@ -36,14 +35,14 @@ function buildPerSkillResourceRecord(scope, skill, opts = {}) {
36
35
  // on the surfaces that offer the skill, and answer others as for an unknown resource.
37
36
  ...skill.metadata.availableWhen !== void 0 && { availableWhen: skill.metadata.availableWhen }
38
37
  };
39
- const handler = async () => {
38
+ const handler = async (_uri, _params, ctx) => {
40
39
  const { loadResult } = await findAndLoadSkillByPath(scope, skillPath);
41
40
  return {
42
41
  contents: [
43
42
  {
44
43
  uri,
45
44
  mimeType: SKILL_MD_MIME_TYPE,
46
- text: serializeSkillMd(loadResult.skill)
45
+ text: await renderSkillMd(scope, loadResult.skill, ctx.getAuthInfo())
47
46
  }
48
47
  ]
49
48
  };
@@ -1,8 +1,10 @@
1
1
  // libs/sdk/src/skill/sep-2640/sep-2640.resource-helpers.ts
2
2
  import { isAbsolute, joinPath, pathResolve, readFileBuffer } from "@frontmcp/utils";
3
3
  import { PublicMcpError, ResourceNotFoundError } from "../../errors/index.mjs";
4
+ import { findSkillCatalogSource } from "../skill-catalog-source.mjs";
4
5
  import { isSkillServable } from "../skill-filter.helper.mjs";
5
6
  import { parseSkillMdFrontmatter } from "../skill-md-parser.mjs";
7
+ import { serializeSkillMd } from "./sep-2640.builders.mjs";
6
8
  function getSepVisibleSkills(scope) {
7
9
  const registry = scope.skills;
8
10
  if (!registry || !registry.hasAny()) return [];
@@ -50,6 +52,12 @@ async function findAndLoadSkillByPath(scope, skillPath) {
50
52
  }
51
53
  return { loadResult, instance: entry };
52
54
  }
55
+ async function renderSkillMd(scope, skill, authInfo) {
56
+ const catalogActions = findSkillCatalogSource(scope)?.actions;
57
+ if (!catalogActions || !skill.actions?.length) return serializeSkillMd(skill);
58
+ const actions = await catalogActions.visibleTo(skill, authInfo);
59
+ return serializeSkillMd(skill, void 0, { hint: catalogActions.hint, actions });
60
+ }
53
61
  function isTextMimeType(mimeType) {
54
62
  if (mimeType.startsWith("text/")) return true;
55
63
  if (mimeType.startsWith("application/json")) return true;
@@ -226,5 +234,6 @@ export {
226
234
  getExternalProviderSkills,
227
235
  getSepVisibleSkills,
228
236
  loadExternalProviderSkill,
229
- readSkillFileByPath
237
+ readSkillFileByPath,
238
+ renderSkillMd
230
239
  };
@@ -0,0 +1,23 @@
1
+ // libs/sdk/src/skill/skill-catalog-source.ts
2
+ import { DependencyNotFoundError, ProviderNotAvailableError, ProviderNotRegisteredError } from "../errors/index.mjs";
3
+ var SkillCatalogSourceToken = /* @__PURE__ */ Symbol.for(
4
+ "frontmcp:SKILL_CATALOG_SOURCE"
5
+ );
6
+ function findSkillCatalogSource(scope) {
7
+ if (!scope.providers) return void 0;
8
+ try {
9
+ return scope.providers.get(SkillCatalogSourceToken);
10
+ } catch (error) {
11
+ if (error instanceof ProviderNotRegisteredError || error instanceof ProviderNotAvailableError || error instanceof DependencyNotFoundError) {
12
+ return void 0;
13
+ }
14
+ scope.logger.warn("the skill source provider failed; serving skills without it", {
15
+ error: error instanceof Error ? error.message : String(error)
16
+ });
17
+ return void 0;
18
+ }
19
+ }
20
+ export {
21
+ SkillCatalogSourceToken,
22
+ findSkillCatalogSource
23
+ };
@@ -4,10 +4,14 @@ import { callSurfaceOf } from "../common/availability/index.mjs";
4
4
  import { mcpRequestSurface } from "../transport/mcp-handlers/mcp-surface.mjs";
5
5
  import { SKILL_INDEX_URI } from "./sep-2640/sep-2640.constants.mjs";
6
6
  import { filterSkillsByAuthorities } from "./skill-authorities.helper.mjs";
7
+ import { findSkillCatalogSource } from "./skill-catalog-source.mjs";
7
8
  import { filterServableSkills } from "./skill-filter.helper.mjs";
8
9
  var DEFAULT_POLICY = "compact";
9
10
  var MAX_SKILL_CATALOG_CHARS = 16e3;
10
11
  var TRUNCATION_FOOTER_RESERVE = 160;
12
+ function pointersFor(options) {
13
+ return options.pointers ?? (options.mcpResources === false ? METHOD_POINTERS : RESOURCE_POINTERS);
14
+ }
11
15
  var RESOURCE_POINTERS = {
12
16
  header: `Available skills (read the \`${SKILL_INDEX_URI}\` resource for each skill's \`SKILL.md\` URI):`,
13
17
  truncationHint: `read \`${SKILL_INDEX_URI}\` to browse`,
@@ -35,7 +39,7 @@ function sanitizeName(raw) {
35
39
  function buildSkillsCatalogSummary(skillRegistry, options = {}) {
36
40
  const skills = listedSkills(skillRegistry, options);
37
41
  if (skills.length === 0) return "";
38
- const pointers = options.mcpResources === false ? METHOD_POINTERS : RESOURCE_POINTERS;
42
+ const pointers = pointersFor(options);
39
43
  const lines = [pointers.header, ""];
40
44
  let truncated = false;
41
45
  let shownCount = 0;
@@ -67,8 +71,7 @@ function buildCompactSkillsLine(skillRegistry, options) {
67
71
  if (count === 0 && !servesExternalSkills) return "";
68
72
  let skills = count === 1 ? "1 skill" : `${count} skills`;
69
73
  if (servesExternalSkills) skills = "skills";
70
- const pointers = options.mcpResources === false ? METHOD_POINTERS : RESOURCE_POINTERS;
71
- return `This server has ${skills}: ${pointers.compact}`;
74
+ return `This server has ${skills}: ${pointersFor(options).compact}`;
72
75
  }
73
76
  function composeInitializeInstructions(options) {
74
77
  const policy = options.policy ?? DEFAULT_POLICY;
@@ -82,7 +85,11 @@ function composeInitializeInstructions(options) {
82
85
  if (policy === "off") {
83
86
  return joinSections([user, channel]);
84
87
  }
85
- const summaryOptions = { mcpResources: options.mcpResources, skills: options.skills };
88
+ const summaryOptions = {
89
+ mcpResources: options.mcpResources,
90
+ skills: options.skills,
91
+ pointers: options.pointers
92
+ };
86
93
  if (policy === "compact") {
87
94
  return joinSections([user, channel, buildCompactSkillsLine(options.skillRegistry, summaryOptions)]);
88
95
  }
@@ -104,12 +111,23 @@ function instructionsPolicyFor(scope, clientName) {
104
111
  }
105
112
  async function composeCallerInstructions(scope, options = {}) {
106
113
  const skillsConfig = scope.metadata.skillsConfig;
114
+ const source = findSkillCatalogSource(scope);
115
+ if (source) {
116
+ try {
117
+ await source.ready();
118
+ } catch (error) {
119
+ scope.logger.warn("initialize instructions: a skill source failed to load; composed without its skills", {
120
+ error: error instanceof Error ? error.message : String(error)
121
+ });
122
+ }
123
+ }
107
124
  const composeOptions = {
108
125
  userInstructions: scope.metadata.instructions,
109
126
  channelInstructions: buildChannelInstructions(scope.channels),
110
127
  skillRegistry: scope.skills,
111
128
  policy: instructionsPolicyFor(scope, options.clientName),
112
- mcpResources: skillsConfig?.mcpResources
129
+ mcpResources: skillsConfig?.mcpResources,
130
+ pointers: source?.pointers
113
131
  };
114
132
  const withUriHints = options.skillUriHints === true && skillUriHintsEnabled(scope);
115
133
  const listsSkills = withUriHints || includesSkillCatalog(composeOptions);
@@ -0,0 +1,166 @@
1
+ // libs/sdk/src/skill/skill-search-text.ts
2
+ var SKILL_STOP_WORDS = /* @__PURE__ */ new Set([
3
+ // Articles & Determiners
4
+ "the",
5
+ "a",
6
+ "an",
7
+ "this",
8
+ "that",
9
+ "these",
10
+ "those",
11
+ // Prepositions
12
+ "in",
13
+ "on",
14
+ "at",
15
+ "to",
16
+ "for",
17
+ "of",
18
+ "with",
19
+ "by",
20
+ "from",
21
+ "into",
22
+ // Conjunctions
23
+ "and",
24
+ "or",
25
+ "but",
26
+ "so",
27
+ "as",
28
+ "if",
29
+ "when",
30
+ "where",
31
+ // Pronouns
32
+ "i",
33
+ "me",
34
+ "my",
35
+ "you",
36
+ "your",
37
+ "it",
38
+ "its",
39
+ "we",
40
+ "our",
41
+ "they",
42
+ "their",
43
+ // Auxiliary verbs
44
+ "is",
45
+ "was",
46
+ "are",
47
+ "were",
48
+ "be",
49
+ "been",
50
+ "being",
51
+ "have",
52
+ "has",
53
+ "had",
54
+ "do",
55
+ "does",
56
+ "did",
57
+ "will",
58
+ "would",
59
+ "can",
60
+ "could",
61
+ "should",
62
+ "may",
63
+ "might",
64
+ // Common fillers
65
+ "please",
66
+ "help",
67
+ "want",
68
+ "need",
69
+ "like",
70
+ "just",
71
+ "how",
72
+ "what"
73
+ ]);
74
+ var MAX_INSTRUCTION_TERMS = 48;
75
+ function identifierWords(identifier) {
76
+ return identifier.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2").replace(/(\p{L})(\p{N})/gu, "$1 $2").replace(/[_\-.:/]+/g, " ").trim();
77
+ }
78
+ function instructionTerms(instructions) {
79
+ const terms = /* @__PURE__ */ new Set();
80
+ for (const raw of instructions.split(/[^\p{L}\p{M}\p{N}_]+/u)) {
81
+ if (raw.length === 0) continue;
82
+ for (const word of [raw, ...identifierWords(raw).split(" ")]) {
83
+ const term = word.toLowerCase();
84
+ if (term.length < 4 || SKILL_STOP_WORDS.has(term)) continue;
85
+ terms.add(term);
86
+ if (terms.size >= MAX_INSTRUCTION_TERMS) return [...terms];
87
+ }
88
+ }
89
+ return [...terms];
90
+ }
91
+ function skillSearchText(skill) {
92
+ const parts = [];
93
+ if (skill.name) {
94
+ const nameParts = skill.name.split(/[:\-_.\s]/).filter(Boolean);
95
+ parts.push(...nameParts);
96
+ }
97
+ if (skill.description) {
98
+ parts.push(skill.description, skill.description, skill.description);
99
+ const keyTerms = skill.description.toLowerCase().split(/\s+/).filter((word) => word.length >= 4 && !SKILL_STOP_WORDS.has(word));
100
+ parts.push(...keyTerms);
101
+ }
102
+ for (const tag of skill.tags ?? []) {
103
+ parts.push(tag, tag);
104
+ }
105
+ for (const tool of skill.tools) {
106
+ parts.push(tool.name);
107
+ if (tool.purpose) {
108
+ parts.push(tool.purpose);
109
+ }
110
+ }
111
+ for (const action of skill.actions ?? []) {
112
+ parts.push(action.actionId, identifierWords(action.actionId));
113
+ if (action.summary) parts.push(action.summary);
114
+ if (action.description) parts.push(action.description);
115
+ }
116
+ if (skill.parameters) {
117
+ for (const param of skill.parameters) {
118
+ parts.push(param.name);
119
+ if (param.description) {
120
+ parts.push(param.description);
121
+ }
122
+ }
123
+ }
124
+ if (skill.examples) {
125
+ for (const example of skill.examples) {
126
+ parts.push(example.scenario);
127
+ if (example.expectedOutcome) {
128
+ parts.push(example.expectedOutcome);
129
+ }
130
+ }
131
+ }
132
+ if (skill.instructions) {
133
+ parts.push(...instructionTerms(skill.instructions));
134
+ }
135
+ return parts.join(" ");
136
+ }
137
+ var SKILL_TOKENIZER_ID = "frontmcp-skills-1";
138
+ function skillTokenizer(tokenize) {
139
+ return (text) => tokenize(text).filter((term) => !SKILL_STOP_WORDS.has(term));
140
+ }
141
+ function queryTerms(query, tokenize) {
142
+ if (tokenize) return [...new Set(tokenize(query))];
143
+ return query.toLowerCase().split(/\s+/).filter((term) => term.length > 0 && !SKILL_STOP_WORDS.has(term));
144
+ }
145
+ function queryTermShare(terms, text, tokenize) {
146
+ if (terms.length === 0) return 0;
147
+ const haystack = tokenize ? ` ${tokenize(text).join(" ")} ` : text.toLowerCase();
148
+ return terms.filter((term) => haystack.includes(term)).length / terms.length;
149
+ }
150
+ function negativeQueryShare(negativeQuery, text, tokenize) {
151
+ if (negativeQuery === void 0) return 0;
152
+ const queries = typeof negativeQuery === "string" ? [negativeQuery] : negativeQuery;
153
+ return queries.reduce((max, query) => Math.max(max, queryTermShare(queryTerms(query, tokenize), text, tokenize)), 0);
154
+ }
155
+ export {
156
+ MAX_INSTRUCTION_TERMS,
157
+ SKILL_STOP_WORDS,
158
+ SKILL_TOKENIZER_ID,
159
+ identifierWords,
160
+ instructionTerms,
161
+ negativeQueryShare,
162
+ queryTermShare,
163
+ queryTerms,
164
+ skillSearchText,
165
+ skillTokenizer
166
+ };