llm_meta_widget 0.9.1 → 0.10.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6dba4c1cd88e26bde9f0179009ae2f47cdd07a30aae6035e619f0ca5b83d32e
4
- data.tar.gz: 95cca5b804adab95a89dfbdf23b7624cb43304462d4cf6c72a605a7ebef170de
3
+ metadata.gz: bbae9759cecc8cdd66372f7ea040db98c55f3a19877aed2e44f8cdd21baa5815
4
+ data.tar.gz: 55d7003f06b621d67a58d2a6fbd0a072371c8e288a4bf1c33de16dd2cc2bd326
5
5
  SHA512:
6
- metadata.gz: d2c499f1d83a689e52fff3fabb0cc08f359c4d34571295085718f3fa5b8c13ccf565f6f47c9ae73b210f1bea350581e7e1c4ae47ac27a759116364518fce2bd2
7
- data.tar.gz: bb45042dcae5849cf88750d8d6235416fda8e531f0852ed454405c59c4358ff3c31137b78349b6b87be8fc490c3235de62b5b9bebd4f0a61cea790c0cf0925ba
6
+ metadata.gz: e5240c9d3f3033c983f92d82ea3240b24049935cf7c26179f68f057540ada604292908aff6ca3c33ca4a443b42bfd19c181dadd674ec8655f6fe82646e09c0cc
7
+ data.tar.gz: d1d1750ce3d6d13a43be940afca2bb41c8978bc34b371b1c686e60b17c012d47c389462348ddf8c1b721e530ead404a7e66dbcffc9c50db781a6b64b48c48385
data/README.md CHANGED
@@ -424,7 +424,7 @@ an MCP server puts in its Server Card, so the page and the server describe
424
424
  themselves the same way.
425
425
 
426
426
  ```html
427
- <script type="application/json" id="ai-page">
427
+ <script type="application/mcp-static-primitives+json">
428
428
  { "_meta": { "io.modelcontextprotocol/static-primitives": {
429
429
  "tools": [ { "name": "set_text", "description": "…", "inputSchema": { } } ],
430
430
  "prompts": [ { "name": "annotate", "description": "Annotate this page" } ],
@@ -466,6 +466,21 @@ fetch from the web by itself — which page resources are not. The form is
466
466
  `page:<name>` with no path, because a page has only one namespace. Expect this to
467
467
  change.
468
468
 
469
+ **The card is found by its media type.** A client matches
470
+ `script[type="application/mcp-static-primitives+json"]`, so the element needs no
471
+ `id`. This is how a client that was never told about your page can still read
472
+ it, and it follows SEP-0000's "HTML-delivery mode". The `page_card_id:` option
473
+ is kept only for a host that cannot set the type; it is read when no block with
474
+ the media type is present.
475
+
476
+ **A document may hold several blocks.** A page built from components can let
477
+ each component declare its own primitives, and the arrays join by primitive
478
+ type. Declaring the same tool or prompt `name`, or the same resource `uri`,
479
+ twice is an error: every copy is dropped and a message is written to the
480
+ console. The first one does not win, because which block comes first depends on
481
+ the order the page's parts are rendered in, and that is not something the author
482
+ chose.
483
+
469
484
  **The card is optional.** A page that declares nothing keeps working exactly as
470
485
  before, and a page that declares no `tools` still uses its `ai-actions` block.
471
486
 
@@ -25,7 +25,8 @@ import { runChatLoop, fetchMcpManifest, listMcpPrompts, getMcpPrompt,
25
25
  createConversationStore, conversationKeyFor,
26
26
  readStaticPrimitivesCard, getPagePrompt,
27
27
  planPageResources, pageResourceLinesForTurn,
28
- promptArgState } from "./orchestrator.js";
28
+ promptArgState, mergeStaticPrimitivesCards,
29
+ PAGE_CARD_MEDIA_TYPE } from "./orchestrator.js";
29
30
  import { marked } from "./marked.esm.js";
30
31
  import { readConfig } from "./config.js";
31
32
  import conversationCss from "../../stylesheets/llm_meta_widget/conversation.css";
@@ -306,8 +307,24 @@ function boot(cfg) {
306
307
  // older #ai-actions schema tag rather than merging with it: two sources
307
308
  // for one list means a reader has to work out which the page meant, and a
308
309
  // handler in window.aiActions answers to a name either way.
309
- var pageCardEl = document.getElementById(PAGE_CARD_ID);
310
- var pageCard = readStaticPrimitivesCard(pageCardEl ? pageCardEl.textContent : null);
310
+ //
311
+ // Discovery is by MEDIA TYPE, which is the locator the spec defines: an id
312
+ // the page chooses cannot be found by a client that was not told it.
313
+ // Several blocks may appear, so a page built from components can let each
314
+ // one declare its own primitives. `page-card-id` survives only as an escape
315
+ // hatch for a host that cannot set the type, and is read when no typed
316
+ // block is present.
317
+ var typedCards = document.querySelectorAll('script[type="' + PAGE_CARD_MEDIA_TYPE + '"]');
318
+ var pageCard;
319
+ if (typedCards.length) {
320
+ pageCard = mergeStaticPrimitivesCards(
321
+ Array.prototype.map.call(typedCards, function(el) {
322
+ return readStaticPrimitivesCard(el.textContent);
323
+ }));
324
+ } else {
325
+ var pageCardEl = document.getElementById(PAGE_CARD_ID);
326
+ pageCard = readStaticPrimitivesCard(pageCardEl ? pageCardEl.textContent : null);
327
+ }
311
328
  var actionsSchemaEl = document.getElementById(ACTIONS_SCHEMA_ID);
312
329
  var localTools = pageCard.tools.length
313
330
  ? pageCard.tools
@@ -560,6 +560,25 @@ function parseSseFrame(raw) {
560
560
  return { name, data };
561
561
  }
562
562
  var STATIC_PRIMITIVES_META = "io.modelcontextprotocol/static-primitives";
563
+ var PAGE_CARD_MEDIA_TYPE = "application/mcp-static-primitives+json";
564
+ function mergeStaticPrimitivesCards(cards, warn = console.warn) {
565
+ const merged = { tools: [], prompts: [], resources: [] };
566
+ const keyOf = { tools: "name", prompts: "name", resources: "uri" };
567
+ for (const kind of ["tools", "prompts", "resources"]) {
568
+ const key = keyOf[kind];
569
+ const all = [];
570
+ for (const card of cards || []) all.push(...card && card[kind] || []);
571
+ const counts = /* @__PURE__ */ new Map();
572
+ for (const entry of all) counts.set(entry[key], (counts.get(entry[key]) || 0) + 1);
573
+ for (const [id, n] of counts) {
574
+ if (n > 1) {
575
+ warn(`[llm-meta-widget] the page declares ${kind} "${id}" ${n} times; dropping every copy \u2014 remove the duplicate to say which one you mean`);
576
+ }
577
+ }
578
+ merged[kind] = all.filter((entry) => counts.get(entry[key]) === 1);
579
+ }
580
+ return merged;
581
+ }
563
582
  function readStaticPrimitivesCard(text, warn = console.warn) {
564
583
  const empty = { tools: [], prompts: [], resources: [] };
565
584
  if (typeof text !== "string" || text.trim() === "") return empty;
@@ -3900,8 +3919,18 @@ function boot(cfg) {
3900
3919
  model: MODEL
3901
3920
  });
3902
3921
  }
3903
- var pageCardEl = document.getElementById(PAGE_CARD_ID);
3904
- var pageCard = readStaticPrimitivesCard(pageCardEl ? pageCardEl.textContent : null);
3922
+ var typedCards = document.querySelectorAll('script[type="' + PAGE_CARD_MEDIA_TYPE + '"]');
3923
+ var pageCard;
3924
+ if (typedCards.length) {
3925
+ pageCard = mergeStaticPrimitivesCards(
3926
+ Array.prototype.map.call(typedCards, function(el) {
3927
+ return readStaticPrimitivesCard(el.textContent);
3928
+ })
3929
+ );
3930
+ } else {
3931
+ var pageCardEl = document.getElementById(PAGE_CARD_ID);
3932
+ pageCard = readStaticPrimitivesCard(pageCardEl ? pageCardEl.textContent : null);
3933
+ }
3905
3934
  var actionsSchemaEl = document.getElementById(ACTIONS_SCHEMA_ID);
3906
3935
  var localTools = pageCard.tools.length ? pageCard.tools : actionsSchemaEl ? JSON.parse(actionsSchemaEl.textContent) : [];
3907
3936
  var remoteToolsEl = document.getElementById(REMOTE_TOOLS_SCHEMA_ID);
@@ -879,6 +879,43 @@ export const STATIC_PRIMITIVES_META = "io.modelcontextprotocol/static-primitives
879
879
  // typo in it should cost that one entry, not the assistant. Everything
880
880
  // unparseable returns empty arrays and says so on the console, which is how
881
881
  // aiState already treats a reader missing its description.
882
+ // The media type that locates a card inside an HTML document. It is the
883
+ // locator, so it is NOT configurable: a client that has to be told where to
884
+ // look cannot discover anything. SEP-0000, "HTML-delivery mode".
885
+ export const PAGE_CARD_MEDIA_TYPE = "application/mcp-static-primitives+json"
886
+
887
+ // Several blocks may appear in one document, so that a page assembled from
888
+ // components can let each component declare its own primitives. The arrays
889
+ // concatenate by primitive type.
890
+ //
891
+ // A duplicate identifier across blocks is an ERROR, not a precedence puzzle:
892
+ // the spec says a client should report it and should not silently pick one. So
893
+ // every copy of a duplicated identifier is dropped and the author is told.
894
+ // Picking the first would make which component wins depend on DOM order, which
895
+ // is not something a page author controls when the components are partials.
896
+ export function mergeStaticPrimitivesCards(cards, warn = console.warn) {
897
+ const merged = { tools: [], prompts: [], resources: [] }
898
+ const keyOf = { tools: "name", prompts: "name", resources: "uri" }
899
+
900
+ for (const kind of [ "tools", "prompts", "resources" ]) {
901
+ const key = keyOf[kind]
902
+ const all = []
903
+ for (const card of cards || []) all.push(...((card && card[kind]) || []))
904
+
905
+ const counts = new Map()
906
+ for (const entry of all) counts.set(entry[key], (counts.get(entry[key]) || 0) + 1)
907
+
908
+ for (const [ id, n ] of counts) {
909
+ if (n > 1) {
910
+ warn(`[llm-meta-widget] the page declares ${kind} "${id}" ${n} times; ` +
911
+ "dropping every copy — remove the duplicate to say which one you mean")
912
+ }
913
+ }
914
+ merged[kind] = all.filter((entry) => counts.get(entry[key]) === 1)
915
+ }
916
+ return merged
917
+ }
918
+
882
919
  export function readStaticPrimitivesCard(text, warn = console.warn) {
883
920
  const empty = { tools: [], prompts: [], resources: [] }
884
921
  if (typeof text !== "string" || text.trim() === "") return empty
@@ -1,3 +1,3 @@
1
1
  module LlmMetaWidget
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_meta_widget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jdkim