@vivix-labs/studio-chat-mcp 0.1.2 → 0.1.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.
package/dist/server.js CHANGED
@@ -514,11 +514,11 @@ var require_codegen = __commonJS({
514
514
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
515
515
  return `${varKind} ${this.name}${rhs};` + _n;
516
516
  }
517
- optimizeNames(names, constants) {
517
+ optimizeNames(names, constants2) {
518
518
  if (!names[this.name.str])
519
519
  return;
520
520
  if (this.rhs)
521
- this.rhs = optimizeExpr(this.rhs, names, constants);
521
+ this.rhs = optimizeExpr(this.rhs, names, constants2);
522
522
  return this;
523
523
  }
524
524
  get names() {
@@ -535,10 +535,10 @@ var require_codegen = __commonJS({
535
535
  render({ _n }) {
536
536
  return `${this.lhs} = ${this.rhs};` + _n;
537
537
  }
538
- optimizeNames(names, constants) {
538
+ optimizeNames(names, constants2) {
539
539
  if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
540
540
  return;
541
- this.rhs = optimizeExpr(this.rhs, names, constants);
541
+ this.rhs = optimizeExpr(this.rhs, names, constants2);
542
542
  return this;
543
543
  }
544
544
  get names() {
@@ -599,8 +599,8 @@ var require_codegen = __commonJS({
599
599
  optimizeNodes() {
600
600
  return `${this.code}` ? this : void 0;
601
601
  }
602
- optimizeNames(names, constants) {
603
- this.code = optimizeExpr(this.code, names, constants);
602
+ optimizeNames(names, constants2) {
603
+ this.code = optimizeExpr(this.code, names, constants2);
604
604
  return this;
605
605
  }
606
606
  get names() {
@@ -629,12 +629,12 @@ var require_codegen = __commonJS({
629
629
  }
630
630
  return nodes.length > 0 ? this : void 0;
631
631
  }
632
- optimizeNames(names, constants) {
632
+ optimizeNames(names, constants2) {
633
633
  const { nodes } = this;
634
634
  let i = nodes.length;
635
635
  while (i--) {
636
636
  const n = nodes[i];
637
- if (n.optimizeNames(names, constants))
637
+ if (n.optimizeNames(names, constants2))
638
638
  continue;
639
639
  subtractNames(names, n.names);
640
640
  nodes.splice(i, 1);
@@ -687,12 +687,12 @@ var require_codegen = __commonJS({
687
687
  return void 0;
688
688
  return this;
689
689
  }
690
- optimizeNames(names, constants) {
690
+ optimizeNames(names, constants2) {
691
691
  var _a3;
692
- this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants);
693
- if (!(super.optimizeNames(names, constants) || this.else))
692
+ this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants2);
693
+ if (!(super.optimizeNames(names, constants2) || this.else))
694
694
  return;
695
- this.condition = optimizeExpr(this.condition, names, constants);
695
+ this.condition = optimizeExpr(this.condition, names, constants2);
696
696
  return this;
697
697
  }
698
698
  get names() {
@@ -715,10 +715,10 @@ var require_codegen = __commonJS({
715
715
  render(opts) {
716
716
  return `for(${this.iteration})` + super.render(opts);
717
717
  }
718
- optimizeNames(names, constants) {
719
- if (!super.optimizeNames(names, constants))
718
+ optimizeNames(names, constants2) {
719
+ if (!super.optimizeNames(names, constants2))
720
720
  return;
721
- this.iteration = optimizeExpr(this.iteration, names, constants);
721
+ this.iteration = optimizeExpr(this.iteration, names, constants2);
722
722
  return this;
723
723
  }
724
724
  get names() {
@@ -754,10 +754,10 @@ var require_codegen = __commonJS({
754
754
  render(opts) {
755
755
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
756
756
  }
757
- optimizeNames(names, constants) {
758
- if (!super.optimizeNames(names, constants))
757
+ optimizeNames(names, constants2) {
758
+ if (!super.optimizeNames(names, constants2))
759
759
  return;
760
- this.iterable = optimizeExpr(this.iterable, names, constants);
760
+ this.iterable = optimizeExpr(this.iterable, names, constants2);
761
761
  return this;
762
762
  }
763
763
  get names() {
@@ -799,11 +799,11 @@ var require_codegen = __commonJS({
799
799
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
800
800
  return this;
801
801
  }
802
- optimizeNames(names, constants) {
802
+ optimizeNames(names, constants2) {
803
803
  var _a3, _b;
804
- super.optimizeNames(names, constants);
805
- (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants);
806
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);
804
+ super.optimizeNames(names, constants2);
805
+ (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants2);
806
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants2);
807
807
  return this;
808
808
  }
809
809
  get names() {
@@ -1104,7 +1104,7 @@ var require_codegen = __commonJS({
1104
1104
  function addExprNames(names, from) {
1105
1105
  return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
1106
1106
  }
1107
- function optimizeExpr(expr, names, constants) {
1107
+ function optimizeExpr(expr, names, constants2) {
1108
1108
  if (expr instanceof code_1.Name)
1109
1109
  return replaceName(expr);
1110
1110
  if (!canOptimize(expr))
@@ -1119,14 +1119,14 @@ var require_codegen = __commonJS({
1119
1119
  return items;
1120
1120
  }, []));
1121
1121
  function replaceName(n) {
1122
- const c = constants[n.str];
1122
+ const c = constants2[n.str];
1123
1123
  if (c === void 0 || names[n.str] !== 1)
1124
1124
  return n;
1125
1125
  delete names[n.str];
1126
1126
  return c;
1127
1127
  }
1128
1128
  function canOptimize(e) {
1129
- return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== void 0);
1129
+ return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants2[c.str] !== void 0);
1130
1130
  }
1131
1131
  }
1132
1132
  function subtractNames(names, from) {
@@ -20736,9 +20736,9 @@ function generateBigIntFormatCheck(doc, def, accessor) {
20736
20736
  }
20737
20737
  }
20738
20738
  function generateMimeTypeCheck(doc, ctx, def, accessor) {
20739
- const mimeTypes = def.mime;
20740
- if (mimeTypes && mimeTypes.length > 0) {
20741
- const mimeSet = addConstant(ctx, new Set(mimeTypes));
20739
+ const mimeTypes2 = def.mime;
20740
+ if (mimeTypes2 && mimeTypes2.length > 0) {
20741
+ const mimeSet = addConstant(ctx, new Set(mimeTypes2));
20742
20742
  doc.write(`if (!${mimeSet}.has(${accessor}.type)) return INVALID;`);
20743
20743
  }
20744
20744
  }
@@ -29429,7 +29429,7 @@ data:
29429
29429
  // package.json
29430
29430
  var package_default = {
29431
29431
  name: "@vivix-labs/studio-chat-mcp",
29432
- version: "0.1.2",
29432
+ version: "0.1.4",
29433
29433
  type: "module",
29434
29434
  engines: {
29435
29435
  node: ">=22.12.0"
@@ -36608,6 +36608,228 @@ var McpZodTypeKind;
36608
36608
  McpZodTypeKind2["Completable"] = "McpCompletable";
36609
36609
  })(McpZodTypeKind || (McpZodTypeKind = {}));
36610
36610
 
36611
+ // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.2_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/uriTemplate.js
36612
+ var MAX_TEMPLATE_LENGTH = 1e6;
36613
+ var MAX_VARIABLE_LENGTH = 1e6;
36614
+ var MAX_TEMPLATE_EXPRESSIONS = 1e4;
36615
+ var MAX_REGEX_LENGTH = 1e6;
36616
+ var UriTemplate = class _UriTemplate {
36617
+ /**
36618
+ * Returns true if the given string contains any URI template expressions.
36619
+ * A template expression is a sequence of characters enclosed in curly braces,
36620
+ * like {foo} or {?bar}.
36621
+ */
36622
+ static isTemplate(str) {
36623
+ return /\{[^}\s]+\}/.test(str);
36624
+ }
36625
+ static validateLength(str, max, context) {
36626
+ if (str.length > max) {
36627
+ throw new Error(`${context} exceeds maximum length of ${max} characters (got ${str.length})`);
36628
+ }
36629
+ }
36630
+ get variableNames() {
36631
+ return this.parts.flatMap((part) => typeof part === "string" ? [] : part.names);
36632
+ }
36633
+ constructor(template) {
36634
+ _UriTemplate.validateLength(template, MAX_TEMPLATE_LENGTH, "Template");
36635
+ this.template = template;
36636
+ this.parts = this.parse(template);
36637
+ }
36638
+ toString() {
36639
+ return this.template;
36640
+ }
36641
+ parse(template) {
36642
+ const parts = [];
36643
+ let currentText = "";
36644
+ let i = 0;
36645
+ let expressionCount = 0;
36646
+ while (i < template.length) {
36647
+ if (template[i] === "{") {
36648
+ if (currentText) {
36649
+ parts.push(currentText);
36650
+ currentText = "";
36651
+ }
36652
+ const end = template.indexOf("}", i);
36653
+ if (end === -1)
36654
+ throw new Error("Unclosed template expression");
36655
+ expressionCount++;
36656
+ if (expressionCount > MAX_TEMPLATE_EXPRESSIONS) {
36657
+ throw new Error(`Template contains too many expressions (max ${MAX_TEMPLATE_EXPRESSIONS})`);
36658
+ }
36659
+ const expr = template.slice(i + 1, end);
36660
+ const operator = this.getOperator(expr);
36661
+ const exploded = expr.includes("*");
36662
+ const names = this.getNames(expr);
36663
+ const name = names[0];
36664
+ for (const name2 of names) {
36665
+ _UriTemplate.validateLength(name2, MAX_VARIABLE_LENGTH, "Variable name");
36666
+ }
36667
+ parts.push({ name, operator, names, exploded });
36668
+ i = end + 1;
36669
+ } else {
36670
+ currentText += template[i];
36671
+ i++;
36672
+ }
36673
+ }
36674
+ if (currentText) {
36675
+ parts.push(currentText);
36676
+ }
36677
+ return parts;
36678
+ }
36679
+ getOperator(expr) {
36680
+ const operators = ["+", "#", ".", "/", "?", "&"];
36681
+ return operators.find((op) => expr.startsWith(op)) || "";
36682
+ }
36683
+ getNames(expr) {
36684
+ const operator = this.getOperator(expr);
36685
+ return expr.slice(operator.length).split(",").map((name) => name.replace("*", "").trim()).filter((name) => name.length > 0);
36686
+ }
36687
+ encodeValue(value, operator) {
36688
+ _UriTemplate.validateLength(value, MAX_VARIABLE_LENGTH, "Variable value");
36689
+ if (operator === "+" || operator === "#") {
36690
+ return encodeURI(value);
36691
+ }
36692
+ return encodeURIComponent(value);
36693
+ }
36694
+ expandPart(part, variables) {
36695
+ if (part.operator === "?" || part.operator === "&") {
36696
+ const pairs = part.names.map((name) => {
36697
+ const value2 = variables[name];
36698
+ if (value2 === void 0)
36699
+ return "";
36700
+ const encoded2 = Array.isArray(value2) ? value2.map((v) => this.encodeValue(v, part.operator)).join(",") : this.encodeValue(value2.toString(), part.operator);
36701
+ return `${name}=${encoded2}`;
36702
+ }).filter((pair) => pair.length > 0);
36703
+ if (pairs.length === 0)
36704
+ return "";
36705
+ const separator = part.operator === "?" ? "?" : "&";
36706
+ return separator + pairs.join("&");
36707
+ }
36708
+ if (part.names.length > 1) {
36709
+ const values2 = part.names.map((name) => variables[name]).filter((v) => v !== void 0);
36710
+ if (values2.length === 0)
36711
+ return "";
36712
+ return values2.map((v) => Array.isArray(v) ? v[0] : v).join(",");
36713
+ }
36714
+ const value = variables[part.name];
36715
+ if (value === void 0)
36716
+ return "";
36717
+ const values = Array.isArray(value) ? value : [value];
36718
+ const encoded = values.map((v) => this.encodeValue(v, part.operator));
36719
+ switch (part.operator) {
36720
+ case "":
36721
+ return encoded.join(",");
36722
+ case "+":
36723
+ return encoded.join(",");
36724
+ case "#":
36725
+ return "#" + encoded.join(",");
36726
+ case ".":
36727
+ return "." + encoded.join(".");
36728
+ case "/":
36729
+ return "/" + encoded.join("/");
36730
+ default:
36731
+ return encoded.join(",");
36732
+ }
36733
+ }
36734
+ expand(variables) {
36735
+ let result = "";
36736
+ let hasQueryParam = false;
36737
+ for (const part of this.parts) {
36738
+ if (typeof part === "string") {
36739
+ result += part;
36740
+ continue;
36741
+ }
36742
+ const expanded = this.expandPart(part, variables);
36743
+ if (!expanded)
36744
+ continue;
36745
+ if ((part.operator === "?" || part.operator === "&") && hasQueryParam) {
36746
+ result += expanded.replace("?", "&");
36747
+ } else {
36748
+ result += expanded;
36749
+ }
36750
+ if (part.operator === "?" || part.operator === "&") {
36751
+ hasQueryParam = true;
36752
+ }
36753
+ }
36754
+ return result;
36755
+ }
36756
+ escapeRegExp(str) {
36757
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
36758
+ }
36759
+ partToRegExp(part) {
36760
+ const patterns = [];
36761
+ for (const name2 of part.names) {
36762
+ _UriTemplate.validateLength(name2, MAX_VARIABLE_LENGTH, "Variable name");
36763
+ }
36764
+ if (part.operator === "?" || part.operator === "&") {
36765
+ for (let i = 0; i < part.names.length; i++) {
36766
+ const name2 = part.names[i];
36767
+ const prefix = i === 0 ? "\\" + part.operator : "&";
36768
+ patterns.push({
36769
+ pattern: prefix + this.escapeRegExp(name2) + "=([^&]+)",
36770
+ name: name2
36771
+ });
36772
+ }
36773
+ return patterns;
36774
+ }
36775
+ let pattern;
36776
+ const name = part.name;
36777
+ switch (part.operator) {
36778
+ case "":
36779
+ pattern = part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)";
36780
+ break;
36781
+ case "+":
36782
+ case "#":
36783
+ pattern = "(.+)";
36784
+ break;
36785
+ case ".":
36786
+ pattern = "\\.([^/,]+)";
36787
+ break;
36788
+ case "/":
36789
+ pattern = "/" + (part.exploded ? "([^/,]+(?:,[^/,]+)*)" : "([^/,]+)");
36790
+ break;
36791
+ default:
36792
+ pattern = "([^/]+)";
36793
+ }
36794
+ patterns.push({ pattern, name });
36795
+ return patterns;
36796
+ }
36797
+ match(uri) {
36798
+ _UriTemplate.validateLength(uri, MAX_TEMPLATE_LENGTH, "URI");
36799
+ let pattern = "^";
36800
+ const names = [];
36801
+ for (const part of this.parts) {
36802
+ if (typeof part === "string") {
36803
+ pattern += this.escapeRegExp(part);
36804
+ } else {
36805
+ const patterns = this.partToRegExp(part);
36806
+ for (const { pattern: partPattern2, name } of patterns) {
36807
+ pattern += partPattern2;
36808
+ names.push({ name, exploded: part.exploded });
36809
+ }
36810
+ }
36811
+ }
36812
+ pattern += "$";
36813
+ _UriTemplate.validateLength(pattern, MAX_REGEX_LENGTH, "Generated regex pattern");
36814
+ const regex = new RegExp(pattern);
36815
+ const match = uri.match(regex);
36816
+ if (!match)
36817
+ return null;
36818
+ const result = {};
36819
+ for (let i = 0; i < names.length; i++) {
36820
+ const { name, exploded } = names[i];
36821
+ const value = match[i + 1];
36822
+ const cleanName = name.replace("*", "");
36823
+ if (exploded && value.includes(",")) {
36824
+ result[cleanName] = value.split(",");
36825
+ } else {
36826
+ result[cleanName] = value;
36827
+ }
36828
+ }
36829
+ return result;
36830
+ }
36831
+ };
36832
+
36611
36833
  // ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.2_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
36612
36834
  var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
36613
36835
  function validateToolName(name) {
@@ -37446,6 +37668,30 @@ var McpServer = class {
37446
37668
  }
37447
37669
  }
37448
37670
  };
37671
+ var ResourceTemplate = class {
37672
+ constructor(uriTemplate, _callbacks) {
37673
+ this._callbacks = _callbacks;
37674
+ this._uriTemplate = typeof uriTemplate === "string" ? new UriTemplate(uriTemplate) : uriTemplate;
37675
+ }
37676
+ /**
37677
+ * Gets the URI template pattern.
37678
+ */
37679
+ get uriTemplate() {
37680
+ return this._uriTemplate;
37681
+ }
37682
+ /**
37683
+ * Gets the list callback, if one was provided.
37684
+ */
37685
+ get listCallback() {
37686
+ return this._callbacks.list;
37687
+ }
37688
+ /**
37689
+ * Gets the callback for completing a specific URI template variable, if one was provided.
37690
+ */
37691
+ completeCallback(variable) {
37692
+ return this._callbacks.complete?.[variable];
37693
+ }
37694
+ };
37449
37695
  var EMPTY_OBJECT_JSON_SCHEMA = {
37450
37696
  type: "object",
37451
37697
  properties: {}
@@ -37594,6 +37840,8 @@ function normalizeChat(definition, source, context) {
37594
37840
  );
37595
37841
  if (typeof definition.projectResult !== "function" || !definition.actions || typeof definition.actions !== "object" || Array.isArray(definition.actions))
37596
37842
  throw Error("Invalid chat declaration.");
37843
+ if (definition.dynamicActions !== void 0 && typeof definition.dynamicActions !== "function")
37844
+ throw Error("Invalid dynamic chat action resolver.");
37597
37845
  const actions = {};
37598
37846
  for (const [name, raw] of Object.entries(definition.actions)) {
37599
37847
  operationId.parse(name);
@@ -37623,15 +37871,35 @@ function normalizeChat(definition, source, context) {
37623
37871
  component: definition.component,
37624
37872
  projectResult: definition.projectResult,
37625
37873
  actions,
37874
+ dynamicActions: definition.dynamicActions,
37626
37875
  description: {
37627
37876
  component: definition.component,
37628
37877
  actions: Object.fromEntries(
37629
37878
  Object.entries(actions).map(([name, binding]) => [name, binding.target])
37630
37879
  ),
37631
- messageActions: Object.entries(actions).filter(([, binding]) => binding.prepareMessage).map(([name]) => name)
37880
+ messageActions: Object.entries(actions).filter(([, binding]) => binding.prepareMessage).map(([name]) => name),
37881
+ ...definition.dynamicActions && { dynamicActions: true }
37632
37882
  }
37633
37883
  };
37634
37884
  }
37885
+ function actionsFor(chat, source, context) {
37886
+ const actions = { ...chat.actions };
37887
+ const dynamic = chat.dynamicActions?.(context) ?? {};
37888
+ if (!dynamic || typeof dynamic !== "object" || Array.isArray(dynamic))
37889
+ throw Error("Invalid resolved chat actions.");
37890
+ for (const [name, binding] of Object.entries(dynamic)) {
37891
+ operationId.parse(name);
37892
+ if (Object.hasOwn(actions, name) || !binding || typeof binding !== "object" || "prepareMessage" in binding)
37893
+ throw Error("A dynamic action must declare a unique native target.");
37894
+ const target2 = targetSchema.parse(destination(source, binding.target));
37895
+ if ([binding.mapInput, binding.validate, binding.projectResult].some(
37896
+ (fn) => fn !== void 0 && typeof fn !== "function"
37897
+ ))
37898
+ throw Error("Invalid dynamic chat action callback.");
37899
+ Object.defineProperty(actions, name, { value: { ...binding, target: target2 }, enumerable: true });
37900
+ }
37901
+ return actions;
37902
+ }
37635
37903
  function sourceOperation(runtime, target2) {
37636
37904
  const operation = readOperation(runtime, target2);
37637
37905
  if (!operation?.chat) unavailable();
@@ -37650,7 +37918,7 @@ function readyDestination(runtime, target2) {
37650
37918
  async function actionBindings(runtime, source, chat, context) {
37651
37919
  return Object.fromEntries(
37652
37920
  await Promise.all(
37653
- Object.entries(chat.actions).map(async ([name, binding]) => [
37921
+ Object.entries(actionsFor(chat, source, context)).map(async ([name, binding]) => [
37654
37922
  name,
37655
37923
  await runtime.bind(binding.target, [source], context)
37656
37924
  ])
@@ -37701,15 +37969,33 @@ async function project(runtime, source, chat, result, projector, ui, action, bin
37701
37969
  } : void 0
37702
37970
  };
37703
37971
  }
37704
- function chatTargets(catalog, source) {
37972
+ function chatTargets(catalog, source, context) {
37705
37973
  const chat = readOperation(catalog, source)?.chat;
37706
- return [source, ...Object.values(chat?.description.actions ?? {})];
37974
+ return [
37975
+ source,
37976
+ ...Object.values(chat ? actionsFor(chat, source, context) : {}).map(
37977
+ (binding) => binding.target
37978
+ )
37979
+ ];
37980
+ }
37981
+ function readChatBundle(host, scope, target2, digest) {
37982
+ return host.withOperations(
37983
+ scope,
37984
+ () => [target2],
37985
+ async (runtime) => {
37986
+ const source = sourceOperation(runtime, target2);
37987
+ const bundle = await runtime.component(target2, source.chat.component);
37988
+ if (bundle.sha256 !== digest)
37989
+ throw new Error("The original Studio card script is unavailable.");
37990
+ return bundle.javascript;
37991
+ }
37992
+ );
37707
37993
  }
37708
37994
  async function runChat(host, projectId, raw) {
37709
37995
  const request = chatRunSchema.parse(raw);
37710
37996
  return host.withOperations(
37711
37997
  typeof projectId === "string" ? { kind: "project", id: projectId } : projectId,
37712
- (catalog) => chatTargets(catalog, request.target),
37998
+ (catalog) => chatTargets(catalog, request.target, request.input),
37713
37999
  async (runtime) => {
37714
38000
  const source = sourceOperation(runtime, request.target);
37715
38001
  const ui = await runtime.component(request.target, source.chat.component);
@@ -37736,7 +38022,14 @@ async function actionChat(host, projectId, raw) {
37736
38022
  (catalog) => {
37737
38023
  const targets = catalog.bindingTargets(request.binding);
37738
38024
  destinationTarget = targets[0];
37739
- return [...targets, ...chatTargets(catalog, request.target)];
38025
+ try {
38026
+ return [
38027
+ ...targets,
38028
+ ...chatTargets(catalog, request.target, catalog.bindingContext(request.binding))
38029
+ ];
38030
+ } catch {
38031
+ return [...targets, request.target];
38032
+ }
37740
38033
  },
37741
38034
  async (runtime) => {
37742
38035
  const bindingContext = runtime.bindingContext(request.binding);
@@ -37773,7 +38066,12 @@ async function actionChat(host, projectId, raw) {
37773
38066
  { requestKey: request.requestKey, approval: request.approval },
37774
38067
  async () => {
37775
38068
  const source2 = sourceOperation(runtime, request.target);
37776
- const binding2 = declaredAction(source2.chat, request.action);
38069
+ const binding2 = declaredAction(
38070
+ source2.chat,
38071
+ request.target,
38072
+ request.action,
38073
+ bindingContext
38074
+ );
37777
38075
  const target2 = binding2.target;
37778
38076
  if (target2.instanceId !== destinationTarget.instanceId || target2.operationId !== destinationTarget.operationId)
37779
38077
  throw inputError(
@@ -37818,7 +38116,7 @@ async function actionChat(host, projectId, raw) {
37818
38116
  }
37819
38117
  };
37820
38118
  }
37821
- const binding = declaredAction(source.chat, request.action);
38119
+ const binding = declaredAction(source.chat, request.target, request.action, bindingContext);
37822
38120
  const operation = readyDestination(runtime, invocation.target);
37823
38121
  const ui = await runtime.component(request.target, source.chat.component);
37824
38122
  return project(
@@ -37834,8 +38132,9 @@ async function actionChat(host, projectId, raw) {
37834
38132
  }
37835
38133
  );
37836
38134
  }
37837
- function declaredAction(chat, action) {
37838
- const binding = Object.hasOwn(chat.actions, action) ? chat.actions[action] : void 0;
38135
+ function declaredAction(chat, source, action, context) {
38136
+ const actions = actionsFor(chat, source, context);
38137
+ const binding = Object.hasOwn(actions, action) ? actions[action] : void 0;
37839
38138
  if (!binding)
37840
38139
  throw inputError(
37841
38140
  "CHAT_ACTION_DENIED",
@@ -37845,6 +38144,81 @@ function declaredAction(chat, action) {
37845
38144
  return binding;
37846
38145
  }
37847
38146
 
38147
+ // src/local-media.ts
38148
+ import { constants } from "node:fs";
38149
+ import { open as open2 } from "node:fs/promises";
38150
+ import { extname, isAbsolute } from "node:path";
38151
+ var snapshot = external_exports.object({
38152
+ sizeBytes: external_exports.number().int().positive().max(2147483648),
38153
+ mtimeMs: external_exports.number().finite(),
38154
+ inode: external_exports.number().int().nonnegative(),
38155
+ device: external_exports.number().int().nonnegative()
38156
+ }).strict();
38157
+ var localMediaInput = external_exports.object({
38158
+ path: external_exports.string().min(1).max(32768).refine(
38159
+ (path) => isAbsolute(path) && !path.includes("\0"),
38160
+ "Use an absolute path on this MCP Host."
38161
+ ),
38162
+ offset: external_exports.number().int().nonnegative(),
38163
+ expected: snapshot.optional()
38164
+ }).strict();
38165
+ var mimeTypes = {
38166
+ ".png": "image/png",
38167
+ ".jpg": "image/jpeg",
38168
+ ".jpeg": "image/jpeg",
38169
+ ".webp": "image/webp",
38170
+ ".mp4": "video/mp4",
38171
+ ".m4v": "video/mp4",
38172
+ ".mov": "video/quicktime",
38173
+ ".webm": "video/webm",
38174
+ ".ogv": "video/ogg",
38175
+ ".mp3": "audio/mpeg",
38176
+ ".wav": "audio/wav",
38177
+ ".m4a": "audio/mp4",
38178
+ ".aac": "audio/aac",
38179
+ ".ogg": "audio/ogg",
38180
+ ".opus": "audio/ogg",
38181
+ ".flac": "audio/flac"
38182
+ };
38183
+ async function readLocalMedia(raw) {
38184
+ const input2 = localMediaInput.parse(raw);
38185
+ const mimeType = mimeTypes[extname(input2.path).toLowerCase()];
38186
+ if (!mimeType) throw Error("Choose a supported local image, audio or video file.");
38187
+ const file2 = await open2(input2.path, constants.O_RDONLY | constants.O_NONBLOCK);
38188
+ try {
38189
+ const before = await file2.stat();
38190
+ if (!before.isFile() || before.size === 0 || before.size > 2147483648)
38191
+ throw Error(
38192
+ "Choose a nonempty regular media file up to 2 GiB. Whole-file preview requires loading all bytes."
38193
+ );
38194
+ const actual = {
38195
+ sizeBytes: before.size,
38196
+ mtimeMs: before.mtimeMs,
38197
+ inode: before.ino,
38198
+ device: before.dev
38199
+ };
38200
+ if (input2.expected && Object.entries(actual).some(
38201
+ ([key, value]) => value !== input2.expected[key]
38202
+ ))
38203
+ throw Error("The local file changed while loading. Reopen the preview.");
38204
+ if (input2.offset >= before.size) throw Error("The requested media offset is outside the file.");
38205
+ const bytes = Buffer.alloc(Math.min(262144, before.size - input2.offset));
38206
+ const { bytesRead } = await file2.read(bytes, 0, bytes.length, input2.offset);
38207
+ const after = await file2.stat();
38208
+ if (bytesRead !== bytes.length || before.size !== after.size || before.mtimeMs !== after.mtimeMs)
38209
+ throw Error("The local file changed while loading. Reopen the preview.");
38210
+ return {
38211
+ base64: bytes.toString("base64"),
38212
+ nextOffset: input2.offset + bytesRead,
38213
+ totalBytes: before.size,
38214
+ mimeType,
38215
+ snapshot: actual
38216
+ };
38217
+ } finally {
38218
+ await file2.close();
38219
+ }
38220
+ }
38221
+
37848
38222
  // src/discovery.ts
37849
38223
  import { PluginError as PluginError2 } from "vivix-studio/sdk/shared";
37850
38224
  var id = external_exports.string().min(1).refine((value) => value !== "." && value !== "..");
@@ -37932,8 +38306,34 @@ async function read(host, scope, target2, input2) {
37932
38306
  (lease) => lease.invoke(target2, input2)
37933
38307
  );
37934
38308
  }
37935
- async function listChatCapabilities(host, scope) {
38309
+ async function listChatCapabilities(host, scope, filter) {
37936
38310
  const operations = await descriptions(host, scope);
38311
+ if (filter?.kind === "nativeOperation") {
38312
+ const query = (filter.query ?? "").trim().toLowerCase();
38313
+ const matches = operations.filter(
38314
+ (item) => `${item.instanceId} ${item.id} ${item.title} ${item.description}`.toLowerCase().includes(query)
38315
+ ).sort((a, b) => `${a.instanceId}/${a.id}`.localeCompare(`${b.instanceId}/${b.id}`));
38316
+ const offset = filter.offset ?? 0;
38317
+ const limit = filter.limit ?? 20;
38318
+ if (!Number.isInteger(offset) || offset < 0 || !Number.isInteger(limit) || limit < 1 || limit > 100)
38319
+ fail("INVALID_DISCOVERY_QUERY", "Use a nonnegative offset and a limit from 1 to 100.");
38320
+ return {
38321
+ scope,
38322
+ total: matches.length,
38323
+ offset,
38324
+ ...offset + limit < matches.length && { nextOffset: offset + limit },
38325
+ items: matches.slice(offset, offset + limit).map((item) => ({
38326
+ kind: "nativeOperation",
38327
+ scope,
38328
+ target: route(item),
38329
+ title: item.title,
38330
+ description: item.description,
38331
+ effects: item.effects,
38332
+ confirm: item.confirm,
38333
+ contract: item.contract
38334
+ }))
38335
+ };
38336
+ }
37937
38337
  const items = [];
37938
38338
  for (const item of operations) {
37939
38339
  const target2 = route(item);
@@ -37982,12 +38382,17 @@ async function listChatCapabilities(host, scope) {
37982
38382
  }
37983
38383
  return { scope, items };
37984
38384
  }
37985
- async function describeChatCapability(host, scope, target2, componentId) {
38385
+ async function describeChatCapability(host, scope, target2, componentId, kind) {
37986
38386
  const operations = await descriptions(host, scope);
37987
38387
  const item = operations.find(
37988
38388
  (item2) => item2.instanceId === target2.instanceId && item2.id === target2.operationId
37989
38389
  );
37990
38390
  if (!item) fail("CAPABILITY_UNAVAILABLE", "This capability is not ready in the selected scope.");
38391
+ if (kind === "nativeOperation") {
38392
+ if (componentId)
38393
+ fail("INVALID_DISCOVERY_QUERY", "Describe either a native operation or a component.");
38394
+ return { ...item, kind, scope, target: target2 };
38395
+ }
37991
38396
  if (componentId) {
37992
38397
  if (item.id !== "components.render" || !record2(item.chat))
37993
38398
  fail("COMPONENT_UNAVAILABLE", "This operation is not a component renderer.");
@@ -38057,11 +38462,15 @@ async function resolveChatMedia(host, scope, ref, fileId) {
38057
38462
  }
38058
38463
 
38059
38464
  // src/chat-server.ts
38060
- var chatResourceUri = "ui://studio/chat/v4.html";
38465
+ var chatResourceUri = "ui://studio/chat/v8.html";
38061
38466
  var historicalChatResourceUris = [
38062
38467
  "ui://studio/chat/v1.html",
38063
38468
  "ui://studio/chat/v2.html",
38064
- "ui://studio/chat/v3.html"
38469
+ "ui://studio/chat/v3.html",
38470
+ "ui://studio/chat/v4.html",
38471
+ "ui://studio/chat/v5.html",
38472
+ "ui://studio/chat/v6.html",
38473
+ "ui://studio/chat/v7.html"
38065
38474
  ];
38066
38475
  var chatMimeType = "text/html;profile=mcp-app";
38067
38476
  var defaultResourceDomains = ["https://static.vivi-x.ai"];
@@ -38095,7 +38504,12 @@ function mapChatResult(result) {
38095
38504
  structuredContent,
38096
38505
  ...(result.view || result.message) && {
38097
38506
  _meta: {
38098
- ...result.view && { "studio/view": result.view },
38507
+ ...result.view && {
38508
+ "studio/view": {
38509
+ ...result.view,
38510
+ ui: { format: result.view.ui.format, sha256: result.view.ui.sha256 }
38511
+ }
38512
+ },
38099
38513
  ...result.message && { "studio/message": result.message }
38100
38514
  }
38101
38515
  }
@@ -38109,6 +38523,35 @@ function createChatServer(options2) {
38109
38523
  instructions: "Discover capabilities on this same connection with list_chat_capabilities and describe_chat_capability. General interactions default to user scope and do not need a business project. Use an explicit project scope for saved project operations. Read media through query_studio_media and resolve_chat_media. Preserve requestKey and original arguments for recovery; never automatically resubmit an uncertain action."
38110
38524
  }
38111
38525
  );
38526
+ server.registerTool(
38527
+ "read_local_media",
38528
+ {
38529
+ title: "Read local media bytes",
38530
+ description: "Read a bounded chunk of a local image, audio or video path supplied to this card. Bytes are private App metadata, not model context. Does not upload or import files.",
38531
+ inputSchema: localMediaInput,
38532
+ annotations: { readOnlyHint: true, openWorldHint: false },
38533
+ _meta: { ui: { visibility: ["app"] } }
38534
+ },
38535
+ async (input2) => {
38536
+ try {
38537
+ return {
38538
+ content: [{ type: "text", text: "Local media chunk read." }],
38539
+ _meta: { "studio/media": await readLocalMedia(input2) }
38540
+ };
38541
+ } catch (error62) {
38542
+ const code = error62 && typeof error62 === "object" && "code" in error62 ? String(error62.code) : void 0;
38543
+ return {
38544
+ isError: true,
38545
+ content: [
38546
+ {
38547
+ type: "text",
38548
+ text: code ? `Local media is unavailable (${code}).` : error62 instanceof Error ? error62.message : "Local media could not be read."
38549
+ }
38550
+ ]
38551
+ };
38552
+ }
38553
+ }
38554
+ );
38112
38555
  const invoke = async (name, args, signal) => {
38113
38556
  const { projectId, scope: requestedScope, ...body } = args;
38114
38557
  const scope = requestedScope ?? (projectId ? { kind: "project", id: projectId } : userScope);
@@ -38167,11 +38610,21 @@ function createChatServer(options2) {
38167
38610
  "list_chat_capabilities",
38168
38611
  {
38169
38612
  title: "Discover chat capabilities",
38170
- description: "Read ready components, project cards and media queries from this connected Host. Defaults to user scope; no business project is needed for general choices or drafts. Returned scope and targets are the actual routes. This lists capabilities, not saved media.",
38171
- inputSchema: external_exports.object({ scope: scopeSchema.default(userScope) }).strict()
38613
+ description: "Read ready components, project cards and media queries from this connected Host. Set kind=nativeOperation to search paginated operation targets for native card actions, including operations without a chat view. Describe their input schema before binding. Defaults to user scope. This lists capabilities, not saved media.",
38614
+ inputSchema: external_exports.object({
38615
+ scope: scopeSchema.default(userScope),
38616
+ kind: external_exports.literal("nativeOperation").optional(),
38617
+ query: external_exports.string().max(500).optional(),
38618
+ offset: external_exports.number().int().nonnegative().optional(),
38619
+ limit: external_exports.number().int().min(1).max(100).optional()
38620
+ }).strict()
38172
38621
  },
38173
- ({ scope }) => readResult("Chat capabilities discovered.", async () => ({
38174
- ...await listChatCapabilities(host, scope),
38622
+ ({ scope, kind, query, offset, limit }) => readResult("Chat capabilities discovered.", async () => ({
38623
+ ...await listChatCapabilities(
38624
+ host,
38625
+ scope,
38626
+ kind ? { kind, query, offset, limit } : void 0
38627
+ ),
38175
38628
  resourceDomains: [...options2.resourceDomains ?? defaultResourceDomains]
38176
38629
  }))
38177
38630
  );
@@ -38179,16 +38632,17 @@ function createChatServer(options2) {
38179
38632
  "describe_chat_capability",
38180
38633
  {
38181
38634
  title: "Read a chat contract",
38182
- description: "Read the exact input and interaction schemas and examples for a route returned by list_chat_capabilities. Pass componentId for a reusable component. Default card interface text to English unless explicitly requested otherwise; preserve story names, story text and user input in their original language. Do not invent fields or operation targets.",
38635
+ description: "Read exact schemas for a discovered route. Pass componentId for a reusable component, or kind=nativeOperation for an operation to bind using target.mode=native. Native operation schemas do not imply a chat view or execution permission. Default interface text to English and preserve original creative content.",
38183
38636
  inputSchema: external_exports.object({
38184
38637
  scope: scopeSchema.default(userScope),
38185
38638
  target,
38186
- componentId: identifier.optional()
38639
+ componentId: identifier.optional(),
38640
+ kind: external_exports.literal("nativeOperation").optional()
38187
38641
  }).strict()
38188
38642
  },
38189
- ({ scope, target: selected, componentId }) => readResult(
38643
+ ({ scope, target: selected, componentId, kind }) => readResult(
38190
38644
  "Capability contract ready.",
38191
- () => describeChatCapability(host, scope, selected, componentId)
38645
+ () => describeChatCapability(host, scope, selected, componentId, kind)
38192
38646
  )
38193
38647
  );
38194
38648
  server.registerTool(
@@ -38233,6 +38687,21 @@ function createChatServer(options2) {
38233
38687
  },
38234
38688
  (args, extra) => invoke("studio_card_action", args, extra.signal)
38235
38689
  );
38690
+ server.registerResource(
38691
+ "Registered Studio card script",
38692
+ new ResourceTemplate("studio://chat-bundles/{kind}/{scopeId}/{instance}/{operation}/{digest}", {
38693
+ list: void 0
38694
+ }),
38695
+ { mimeType: "text/javascript" },
38696
+ async (uri, variables) => {
38697
+ const part = (key) => decodeURIComponent(external_exports.string().parse(variables[key]));
38698
+ const scope = scopeSchema.parse({ kind: part("kind"), id: part("scopeId") });
38699
+ const source = target.parse({ instanceId: part("instance"), operationId: part("operation") });
38700
+ const digest = external_exports.string().regex(/^[a-f0-9]{64}$/).parse(variables.digest);
38701
+ const script = await readChatBundle(host, scope, source, digest);
38702
+ return { contents: [{ uri: uri.href, mimeType: "text/javascript", text: script }] };
38703
+ }
38704
+ );
38236
38705
  const metadata = {
38237
38706
  // The component's CSP restricts HTTPS media to its declared media origins.
38238
38707
  // This outer policy must permit those origins before the component can narrow them.