@aibranch/llm-meta-widget 0.8.4 → 0.8.6

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.
@@ -550,23 +550,33 @@ function parseSseFrame(raw) {
550
550
  }
551
551
  var STATIC_PRIMITIVES_META = "io.modelcontextprotocol/static-primitives";
552
552
  var VOLATILITIES = ["stable", "volatile"];
553
+ var usableSize = (n) => typeof n === "number" && isFinite(n) ? n : null;
553
554
  function resourceHints(entry) {
554
555
  const meta = entry && entry._meta && entry._meta[STATIC_PRIMITIVES_META] || {};
555
556
  return {
556
557
  // A non-numeric or absent size means "unknown", never 0 — 0 would read
557
558
  // as a free resource and sail through every budget check.
558
- sizeBytes: typeof meta.sizeBytes === "number" && isFinite(meta.sizeBytes) ? meta.sizeBytes : null,
559
+ // Base `size` wins; `_meta.sizeBytes` is the earlier draft's spelling and
560
+ // is accepted so a new client keeps its budget gate against an old server.
561
+ size: usableSize(entry && entry.size) ?? usableSize(meta.sizeBytes),
562
+ // Deprecated alias, kept for one release so renaming the field is not a
563
+ // breaking change: orchestrator.js is a published entry point, so anything
564
+ // it returns is public API. Dropped at 0.9.0 together with the
565
+ // `_meta.sizeBytes` fallback above — one deprecation, one bump.
566
+ get sizeBytes() {
567
+ return this.size;
568
+ },
559
569
  volatility: VOLATILITIES.indexOf(meta.volatility) === -1 ? "stable" : meta.volatility,
560
570
  autoAttach: typeof meta.autoAttach === "boolean" ? meta.autoAttach : true
561
571
  };
562
572
  }
563
573
  function planResourceAttachment(entry, budgetBytes) {
564
- const { sizeBytes, volatility, autoAttach } = resourceHints(entry);
565
- const base = { sizeBytes, volatility, uri: entry && entry.uri };
574
+ const { size, volatility, autoAttach } = resourceHints(entry);
575
+ const base = { size, sizeBytes: size, volatility, uri: entry && entry.uri };
566
576
  if (!autoAttach) {
567
577
  return { ...base, fetch: false, autoAttach: false, reason: "not-auto-attach" };
568
578
  }
569
- if (sizeBytes !== null && sizeBytes > budgetBytes) {
579
+ if (size !== null && size > budgetBytes) {
570
580
  return { ...base, fetch: false, autoAttach: false, reason: "over-budget" };
571
581
  }
572
582
  return {
@@ -575,7 +585,7 @@ function planResourceAttachment(entry, budgetBytes) {
575
585
  autoAttach: true,
576
586
  // Unknown size still gets fetched, then trimmed — the trim is the
577
587
  // safety net for servers that do not declare a size.
578
- reason: sizeBytes === null ? "size-unknown" : "within-budget"
588
+ reason: size === null ? "size-unknown" : "within-budget"
579
589
  };
580
590
  }
581
591
  function trimResourceText(text, maxBytes) {
@@ -3868,6 +3878,7 @@ function boot(cfg) {
3868
3878
  (payload.llms || []).forEach(function(llm) {
3869
3879
  if (llm.family !== "ollama") return;
3870
3880
  (llm.available_models || []).forEach(function(m) {
3881
+ if (m.supports_tools === false) return;
3871
3882
  if (anyAllowedByAllowlist(m.value, MODEL_ALLOWLIST)) {
3872
3883
  flat.push({ value: m.value, label: m.label });
3873
3884
  }
@@ -4030,7 +4041,7 @@ function boot(cfg) {
4030
4041
  list: listMcpResources,
4031
4042
  read: readMcpResource,
4032
4043
  onSkip: function(plan) {
4033
- console.info("[llm_meta_widget] not attaching " + plan.uri + " (" + plan.reason + ", sizeBytes=" + plan.sizeBytes + ")");
4044
+ console.info("[llm_meta_widget] not attaching " + plan.uri + " (" + plan.reason + ", size=" + plan.size + ")");
4034
4045
  }
4035
4046
  });
4036
4047
  if (loaded && loaded.plan && loaded.plan.fetch) {
@@ -819,8 +819,13 @@ function parseSseFrame(raw) {
819
819
  // follow-on). Three optional fields a server may declare on a resources/list
820
820
  // entry:
821
821
  //
822
- // sizeBytes - byte length of the payload resources/read would return, so a
822
+ // size - byte count of the payload resources/read would return, so a
823
823
  // client can decide whether to attach it BEFORE fetching it.
824
+ // This is the BASE Resource field, not an extension field: the
825
+ // extension only strengthens it to "MUST be exact when present".
826
+ // Read from `_meta.sizeBytes` too, which is where the earlier
827
+ // draft put it — servers deployed against that draft (PD among
828
+ // them) are still emitting it.
824
829
  // volatility - "stable" (content fixed) or "volatile" (varies between
825
830
  // turns, so a client re-reads it each turn).
826
831
  // autoAttach - may a client attach this without the user asking for it?
@@ -837,12 +842,21 @@ export const STATIC_PRIMITIVES_META = "io.modelcontextprotocol/static-primitives
837
842
 
838
843
  const VOLATILITIES = [ "stable", "volatile" ]
839
844
 
845
+ const usableSize = (n) => (typeof n === "number" && isFinite(n) ? n : null)
846
+
840
847
  export function resourceHints(entry) {
841
848
  const meta = (entry && entry._meta && entry._meta[STATIC_PRIMITIVES_META]) || {}
842
849
  return {
843
850
  // A non-numeric or absent size means "unknown", never 0 — 0 would read
844
851
  // as a free resource and sail through every budget check.
845
- sizeBytes: typeof meta.sizeBytes === "number" && isFinite(meta.sizeBytes) ? meta.sizeBytes : null,
852
+ // Base `size` wins; `_meta.sizeBytes` is the earlier draft's spelling and
853
+ // is accepted so a new client keeps its budget gate against an old server.
854
+ size: usableSize(entry && entry.size) ?? usableSize(meta.sizeBytes),
855
+ // Deprecated alias, kept for one release so renaming the field is not a
856
+ // breaking change: orchestrator.js is a published entry point, so anything
857
+ // it returns is public API. Dropped at 0.9.0 together with the
858
+ // `_meta.sizeBytes` fallback above — one deprecation, one bump.
859
+ get sizeBytes() { return this.size },
846
860
  volatility: VOLATILITIES.indexOf(meta.volatility) === -1 ? "stable" : meta.volatility,
847
861
  autoAttach: typeof meta.autoAttach === "boolean" ? meta.autoAttach : true
848
862
  }
@@ -851,13 +865,16 @@ export function resourceHints(entry) {
851
865
  // The pre-flight decision, made from the resources/list entry alone.
852
866
  // `fetch: false` means the bytes never cross the wire at all.
853
867
  export function planResourceAttachment(entry, budgetBytes) {
854
- const { sizeBytes, volatility, autoAttach } = resourceHints(entry)
855
- const base = { sizeBytes, volatility, uri: entry && entry.uri }
868
+ const { size, volatility, autoAttach } = resourceHints(entry)
869
+ // `sizeBytes` is the deprecated alias again: this function is exported too,
870
+ // and it returned that name before the field was aligned with the base
871
+ // Resource interface. Dropped at 0.9.0 with the rest.
872
+ const base = { size, sizeBytes: size, volatility, uri: entry && entry.uri }
856
873
 
857
874
  if (!autoAttach) {
858
875
  return { ...base, fetch: false, autoAttach: false, reason: "not-auto-attach" }
859
876
  }
860
- if (sizeBytes !== null && sizeBytes > budgetBytes) {
877
+ if (size !== null && size > budgetBytes) {
861
878
  // The client's budget overrides the server's willingness — which is why
862
879
  // autoAttach has to be a boolean here rather than a restatement of a hint.
863
880
  return { ...base, fetch: false, autoAttach: false, reason: "over-budget" }
@@ -868,7 +885,7 @@ export function planResourceAttachment(entry, budgetBytes) {
868
885
  autoAttach: true,
869
886
  // Unknown size still gets fetched, then trimmed — the trim is the
870
887
  // safety net for servers that do not declare a size.
871
- reason: sizeBytes === null ? "size-unknown" : "within-budget"
888
+ reason: size === null ? "size-unknown" : "within-budget"
872
889
  }
873
890
  }
874
891
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibranch/llm-meta-widget",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "//version": "Must stay in step with lib/llm_meta_widget/version.rb. Two independently versioned copies of the same client is the drift docs/custom-element-distribution.md warns about: bump both, release both.",
5
5
  "description": "Embeddable browser chat widget: a custom element that discovers tools at page, origin and hub scope and dispatches each tool call to the right one. Two lines of HTML on any host, Rails or not.",
6
6
  "keywords": [