@copilotkit/shared 1.83.0 → 1.84.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.
Files changed (90) hide show
  1. package/dist/a2ui-envelope.cjs +2 -2
  2. package/dist/a2ui-envelope.cjs.map +1 -1
  3. package/dist/a2ui-envelope.d.cts +1 -1
  4. package/dist/a2ui-envelope.d.cts.map +1 -1
  5. package/dist/a2ui-envelope.d.mts +1 -1
  6. package/dist/a2ui-envelope.d.mts.map +1 -1
  7. package/dist/a2ui-envelope.mjs +2 -2
  8. package/dist/a2ui-envelope.mjs.map +1 -1
  9. package/dist/a2ui-prompts.cjs +21 -62
  10. package/dist/a2ui-prompts.cjs.map +1 -1
  11. package/dist/a2ui-prompts.d.cts +8 -1
  12. package/dist/a2ui-prompts.d.cts.map +1 -1
  13. package/dist/a2ui-prompts.d.mts +8 -1
  14. package/dist/a2ui-prompts.d.mts.map +1 -1
  15. package/dist/a2ui-prompts.mjs +22 -62
  16. package/dist/a2ui-prompts.mjs.map +1 -1
  17. package/dist/generative-ui/basic-functions.cjs +1 -1
  18. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  19. package/dist/generative-ui/basic-functions.mjs +1 -1
  20. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  21. package/dist/generative-ui/compact-schema.cjs +187 -0
  22. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  23. package/dist/generative-ui/compact-schema.d.cts +55 -0
  24. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  25. package/dist/generative-ui/compact-schema.d.mts +55 -0
  26. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  27. package/dist/generative-ui/compact-schema.mjs +185 -0
  28. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  29. package/dist/generative-ui/prompt-spec.cjs +225 -0
  30. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  31. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  32. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  33. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  34. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  35. package/dist/generative-ui/prompt-spec.mjs +220 -0
  36. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  37. package/dist/generative-ui/prompt.cjs +10 -36
  38. package/dist/generative-ui/prompt.cjs.map +1 -1
  39. package/dist/generative-ui/prompt.d.cts +2 -1
  40. package/dist/generative-ui/prompt.d.cts.map +1 -1
  41. package/dist/generative-ui/prompt.d.mts +2 -1
  42. package/dist/generative-ui/prompt.d.mts.map +1 -1
  43. package/dist/generative-ui/prompt.mjs +12 -38
  44. package/dist/generative-ui/prompt.mjs.map +1 -1
  45. package/dist/generative-ui/schema-render.cjs +242 -0
  46. package/dist/generative-ui/schema-render.cjs.map +1 -0
  47. package/dist/generative-ui/schema-render.d.cts +44 -0
  48. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  49. package/dist/generative-ui/schema-render.d.mts +44 -0
  50. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  51. package/dist/generative-ui/schema-render.mjs +239 -0
  52. package/dist/generative-ui/schema-render.mjs.map +1 -0
  53. package/dist/generative-ui/types.cjs +2 -2
  54. package/dist/generative-ui/types.cjs.map +1 -1
  55. package/dist/generative-ui/types.d.cts +7 -7
  56. package/dist/generative-ui/types.d.cts.map +1 -1
  57. package/dist/generative-ui/types.d.mts +7 -7
  58. package/dist/generative-ui/types.d.mts.map +1 -1
  59. package/dist/generative-ui/types.mjs +2 -2
  60. package/dist/generative-ui/types.mjs.map +1 -1
  61. package/dist/index.cjs +14 -0
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +4 -1
  64. package/dist/index.d.cts.map +1 -1
  65. package/dist/index.d.mts +4 -1
  66. package/dist/index.d.mts.map +1 -1
  67. package/dist/index.mjs +4 -1
  68. package/dist/index.mjs.map +1 -1
  69. package/dist/index.umd.js +756 -165
  70. package/dist/index.umd.js.map +1 -1
  71. package/dist/package.cjs +1 -1
  72. package/dist/package.mjs +1 -1
  73. package/package.json +1 -1
  74. package/src/__tests__/a2ui-envelope.test.ts +18 -13
  75. package/src/__tests__/a2ui-prompts.test.ts +47 -14
  76. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  77. package/src/__tests__/prompt-spec.test.ts +191 -0
  78. package/src/__tests__/schema-render.test.ts +245 -0
  79. package/src/a2ui-envelope.ts +5 -5
  80. package/src/a2ui-prompts.ts +47 -96
  81. package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
  82. package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
  83. package/src/generative-ui/basic-functions.ts +1 -1
  84. package/src/generative-ui/compact-schema.ts +277 -0
  85. package/src/generative-ui/index.ts +3 -0
  86. package/src/generative-ui/prompt-spec.ts +335 -0
  87. package/src/generative-ui/prompt.ts +25 -75
  88. package/src/generative-ui/schema-render.ts +374 -0
  89. package/src/generative-ui/types.ts +10 -7
  90. package/src/utils/__tests__/conditions.test.ts +153 -43
package/dist/index.umd.js CHANGED
@@ -815,7 +815,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
815
815
 
816
816
  //#endregion
817
817
  //#region src/utils/inspector-metadata.ts
818
- function isRecord$1(value) {
818
+ function isRecord$3(value) {
819
819
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
820
820
  try {
821
821
  const prototype = Object.getPrototypeOf(value);
@@ -838,7 +838,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
838
838
  return parsed.length > 0 ? parsed : void 0;
839
839
  }
840
840
  function parseIdentity(value) {
841
- if (!isRecord$1(value)) return;
841
+ if (!isRecord$3(value)) return;
842
842
  const organizationName = parseNonBlankString(value.organizationName);
843
843
  const projectName = parseNonBlankString(value.projectName);
844
844
  if (organizationName === void 0 || projectName === void 0) return;
@@ -848,7 +848,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
848
848
  };
849
849
  }
850
850
  function parsePlan(value) {
851
- if (!isRecord$1(value)) return;
851
+ if (!isRecord$3(value)) return;
852
852
  const code = parseNonBlankString(value.code);
853
853
  const label = parseNonBlankString(value.label);
854
854
  if (code === void 0 || label === void 0) return;
@@ -858,7 +858,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
858
858
  };
859
859
  }
860
860
  function parseLicense(value) {
861
- if (!isRecord$1(value)) return;
861
+ if (!isRecord$3(value)) return;
862
862
  switch (value.state) {
863
863
  case "valid":
864
864
  case "none":
@@ -893,7 +893,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
893
893
  return isSafeDashboardUrl(parsed) ? url : void 0;
894
894
  }
895
895
  function parseAction(value) {
896
- if (!isRecord$1(value)) return;
896
+ if (!isRecord$3(value)) return;
897
897
  const kind = parseActionKind(value.kind);
898
898
  const url = parseSafeActionUrl(value.url);
899
899
  if (kind === void 0 || url === void 0) return;
@@ -906,7 +906,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
906
906
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
907
907
  }
908
908
  function parseUsageLimit(value) {
909
- if (!isRecord$1(value)) return;
909
+ if (!isRecord$3(value)) return;
910
910
  if (value.kind === "finite") {
911
911
  if (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 1) return;
912
912
  return {
@@ -918,7 +918,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
918
918
  if (value.kind === "unknown") return { kind: "unknown" };
919
919
  }
920
920
  function parseUsage(value) {
921
- if (!isRecord$1(value)) return;
921
+ if (!isRecord$3(value)) return;
922
922
  const limit = parseUsageLimit(value.limit);
923
923
  const used = value.used;
924
924
  if (!isFiniteNonnegativeInteger(used) || limit === void 0) return;
@@ -939,7 +939,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
939
939
  * top-level payload.
940
940
  */
941
941
  function parseInspectorMetadataV1(value) {
942
- if (!isRecord$1(value) || value.schemaVersion !== 1) return;
942
+ if (!isRecord$3(value) || value.schemaVersion !== 1) return;
943
943
  const identity = parseIdentity(value.identity);
944
944
  const plan = parsePlan(value.plan);
945
945
  const license = parseLicense(value.license);
@@ -2323,7 +2323,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2323
2323
 
2324
2324
  //#endregion
2325
2325
  //#region package.json
2326
- var version = "1.83.0";
2326
+ var version = "1.84.0";
2327
2327
 
2328
2328
  //#endregion
2329
2329
  //#region src/generative-ui/basic-functions.ts
@@ -2451,7 +2451,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2451
2451
  */
2452
2452
  const COPILOTKIT_FUNCTIONS = rendererOnly({
2453
2453
  calc: {
2454
- description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), comparisons, && || !, cond ? a : b, min max round floor ceil abs, 'text' + name",
2454
+ description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), x ^ y (power), comparisons, && || !, cond ? a : b, min max round floor ceil abs pow sqrt exp ln log10, the constants pi and e, 'text' + name",
2455
2455
  parameters: "{ expression: string; [name: string]: number | string | boolean }",
2456
2456
  returnType: "any",
2457
2457
  extension: true
@@ -2494,7 +2494,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2494
2494
  //#endregion
2495
2495
  //#region src/generative-ui/is-record.ts
2496
2496
  /** True for a plain object: not null, not an array. Internal, not exported. */
2497
- function isRecord(value) {
2497
+ function isRecord$2(value) {
2498
2498
  return typeof value === "object" && value !== null && !Array.isArray(value);
2499
2499
  }
2500
2500
 
@@ -2540,7 +2540,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2540
2540
  const visit = (node) => {
2541
2541
  var _marked;
2542
2542
  if (Array.isArray(node)) return node.map(visit);
2543
- if (!isRecord(node)) return node;
2543
+ if (!isRecord$2(node)) return node;
2544
2544
  const reference = (_marked = marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF)) !== null && _marked !== void 0 ? _marked : marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);
2545
2545
  if (reference) return reference;
2546
2546
  return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, visit(value)]));
@@ -2567,12 +2567,12 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2567
2567
  });
2568
2568
  };
2569
2569
  const visit = (node, path) => {
2570
- if (!isRecord(node)) return;
2570
+ if (!isRecord$2(node)) return;
2571
2571
  const kind = childRefKind(node);
2572
2572
  if (kind) return add(path, kind);
2573
2573
  for (const list of [node.anyOf, node.oneOf]) {
2574
2574
  if (!Array.isArray(list) || list.length === 0) continue;
2575
- const kinds = list.map((variant) => isRecord(variant) ? childRefKind(variant) : void 0);
2575
+ const kinds = list.map((variant) => isRecord$2(variant) ? childRefKind(variant) : void 0);
2576
2576
  const [first] = kinds;
2577
2577
  if (first && kinds.every((k) => k === first)) add(path, first);
2578
2578
  else if (kinds.every((k) => k === void 0)) {
@@ -2582,8 +2582,8 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2582
2582
  }
2583
2583
  }
2584
2584
  if (Array.isArray(node.allOf)) node.allOf.forEach((variant) => visit(variant, path));
2585
- if (isRecord(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
2586
- if (isRecord(node.items)) visit(node.items, [...path, "*"]);
2585
+ if (isRecord$2(node.properties)) for (const [key, value] of Object.entries(node.properties)) visit(value, [...path, key]);
2586
+ if (isRecord$2(node.items)) visit(node.items, [...path, "*"]);
2587
2587
  };
2588
2588
  visit(schema, []);
2589
2589
  return refs;
@@ -2598,7 +2598,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2598
2598
  const collect = (value) => {
2599
2599
  if (typeof value === "string") ids.push(value);
2600
2600
  else if (Array.isArray(value)) value.forEach((id) => typeof id === "string" && ids.push(id));
2601
- else if (isRecord(value) && typeof value.componentId === "string") ids.push(value.componentId);
2601
+ else if (isRecord$2(value) && typeof value.componentId === "string") ids.push(value.componentId);
2602
2602
  };
2603
2603
  const visit = (value, path) => {
2604
2604
  if (path.length === 0) return collect(value);
@@ -2607,7 +2607,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2607
2607
  if (Array.isArray(value)) value.forEach((item) => visit(item, rest));
2608
2608
  return;
2609
2609
  }
2610
- if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
2610
+ if (isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head)) visit(value[head], rest);
2611
2611
  };
2612
2612
  for (const ref of refs) visit(component, ref.path);
2613
2613
  return ids;
@@ -2618,13 +2618,13 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2618
2618
  * at render time.
2619
2619
  */
2620
2620
  function hasBoundChildRef(component, refs) {
2621
- const isDynamic = (value) => isRecord(value) && ("@path" in value || "@call" in value);
2621
+ const isDynamic = (value) => isRecord$2(value) && ("@path" in value || "@call" in value);
2622
2622
  const visit = (value, path) => {
2623
2623
  if (isDynamic(value)) return true;
2624
2624
  if (path.length === 0) return false;
2625
2625
  const [head, ...rest] = path;
2626
2626
  if (head === "*") return Array.isArray(value) && value.some((item) => visit(item, rest));
2627
- return isRecord(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
2627
+ return isRecord$2(value) && Object.prototype.hasOwnProperty.call(value, head) && visit(value[head], rest);
2628
2628
  };
2629
2629
  return refs.some((ref) => visit(component, ref.path));
2630
2630
  }
@@ -2640,7 +2640,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2640
2640
  if (!Array.isArray(value)) return value;
2641
2641
  return value.map((item) => mapAtChildRef(item, rest, replace));
2642
2642
  }
2643
- if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
2643
+ if (!isRecord$2(value) || !Object.prototype.hasOwnProperty.call(value, head)) return value;
2644
2644
  return {
2645
2645
  ...value,
2646
2646
  [head]: mapAtChildRef(value[head], rest, replace)
@@ -2650,7 +2650,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2650
2650
  //#endregion
2651
2651
  //#region src/generative-ui/types.ts
2652
2652
  /** A2UI protocol version used on the wire. */
2653
- const A2UI_VERSION = "v1.0";
2653
+ const A2UI_VERSION = "1.0";
2654
2654
  /** Activity type of a generated surface message. */
2655
2655
  const GENERATIVE_UI_ACTIVITY_TYPE = "generative-ui-surface";
2656
2656
  /** Activity type of a function call that the agent asks the client to run. */
@@ -2714,7 +2714,7 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2714
2714
  * @example
2715
2715
  * ```ts
2716
2716
  * toA2UIActionMessage({ name: "buy", surfaceId: "s1", componentId: "b", context: { sku: "a" } });
2717
- * // { version: "v1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
2717
+ * // { version: "1.0", action: { name: "buy", surfaceId: "s1", sourceComponentId: "b", timestamp: "2026-…", context: { sku: "a" } } }
2718
2718
  * ```
2719
2719
  */
2720
2720
  function toA2UIActionMessage(event) {
@@ -2732,6 +2732,222 @@ ${getSeeMoreMarkdown(troubleshootingLink)}`;
2732
2732
  };
2733
2733
  }
2734
2734
 
2735
+ //#endregion
2736
+ //#region src/generative-ui/prompt-spec.ts
2737
+ /**
2738
+ * When UI helps the user, for both transports: a light nudge to reach for UI
2739
+ * where it conveys the answer better than prose, and to stay in prose
2740
+ * otherwise.
2741
+ */
2742
+ const GENERATIVE_UI_WHEN_TO_SHOW = "Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
2743
+ /**
2744
+ * When and how to show UI in the markdown transport: the answer first, a
2745
+ * map from tasks to components, real interactivity, honest data and
2746
+ * restraint. Measured with tools/genui-eval against the earlier text.
2747
+ */
2748
+ const GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = "Answer first: lead with the result or the recommendation in a sentence or two, then show the UI that supports it.\n\nShow UI whenever it makes the answer easier to use, and do not wait for the user to ask for a chart, a calculator or a form. A markdown table or list is not enough when the user would want to change a value, see a shape or a trend, or pick between options. Reply in prose alone only for a greeting or thanks, a one-line fact, a definition, code, or a text the user asked you to write (an email, a message, an update).\n\nMatch the UI to the task:\n- A number that depends on inputs (a price, a loan or mortgage, savings, a conversion, a recipe for N people): a calculator, always. Bind a Slider, TextField or SegmentedControl to the data model and compute the results with calc, so they follow the input. calc has powers, roots and logs, so every input can be a control, also a rate or a term: a monthly payment is rate == 0 ? loan / (years * 12) : loan * (rate / 1200) / (1 - (1 + rate / 1200) ^ -(years * 12)).\n- Choosing between options that share attributes: a Table, or a Grid of EntityCards when each option has a photo, a price or a rating. Plans or offers to pick from: one card each, ending with a Button to choose it.\n- Items with a status, a category or a level: a Badge on each item.\n- Shares, patterns, trends, change over time: a Chart.\n- Places, routes, what is nearby: a Map with the places as markers, next to cards or a List with their details.\n- A sequence or a history: a timeline surface, a List of dated items with a Badge for each era, not a markdown list.\n- How something works, a process, a structure: a diagram drawn with Svg. Draw the real objects as shapes (a cylinder and its piston, a leaf, a server), with arrows for movement or flow and short labels. Labelled boxes of text are not a diagram.\n- A formula or an equation: Math. Solving a math problem: the steps in prose with Math, plus a Chart of the function and a Slider to try values of x.\n- A broad topic (\"tell me about X\"): an overview surface with the key facts, an Image, and a Table or Chart that compares the parts, ending with FollowUp suggestions for what to ask next.\n- Options to choose from (algorithms, products, plans): a Table, plus a SegmentedControl or Select that shows the best option for the user's situation.\n- Research or evidence: a Table of the studies, with a Citation for each source.\n- Things whose look matters (places, products, food): an Image, or the image of an EntityCard.\n- Several inputs, or an action with a side effect (sign-up, booking, contact, scheduling): a Form with fields, checks and a Button. A field with a fixed list of answers (a team size, a topic, a country) is a Select.\n- Practice and learning: a quiz with RadioGroup or ChoicePicker that gives feedback as soon as the user answers, or FlashcardFlip cards. Ask in one language and offer the answers in the other.\n- A plan to follow or tick off: CheckBox items with a progress count that updates as items are ticked.\n- Parallel views (the days of a trip, alternatives): Tabs.\n\nMake interactivity real:\n- Expose the few inputs that change the outcome, with sensible defaults from what the user said.\n- Bind every control to the data model and derive what depends on it with calc or formatString. Controls about the same scenario share the same paths.\n- Every Button does what its label says, and a Link takes \"href\".\n- Never pretend an action happened. For booking, sending or subscribing, show the form and let the user confirm, and say that nothing is sent until they do.\n\nKeep the data honest:\n- Use the facts, places, photos and numbers of the app context when it has them. Never invent prices, availability, ratings, sources or image URLs.\n- Label estimates and assumptions, keep units and currencies consistent, and cite the sources you rely on with Citation.\n\nDesign with restraint:\n- One clear surface beats several. Put the most important result first and make it stand out with a Title, or a Text with size \"lg\". Text sizes go from \"3xs\" to \"lg\"; there is no \"xl\" or \"2xl\".\n- Keep explanations in prose around the surface, not inside it. No decoration, and no surface that only holds text.\n\nBefore you reply, check: does the UI answer the actual question, does every control do something, are the numbers right?";
2749
+ /** The prompts that ship, as a spec. A new object on each call. */
2750
+ /**
2751
+ * The standard components that the default markdown guide names. A guide
2752
+ * line that names one the catalog lacks is left out of the prompt.
2753
+ */
2754
+ const GUIDE_COMPONENTS = new Set([
2755
+ "Grid",
2756
+ "Card",
2757
+ "Tabs",
2758
+ "Title",
2759
+ "Text",
2760
+ "Label",
2761
+ "Badge",
2762
+ "Math",
2763
+ "Link",
2764
+ "Button",
2765
+ "Form",
2766
+ "TextField",
2767
+ "Select",
2768
+ "CheckBox",
2769
+ "RadioGroup",
2770
+ "Slider",
2771
+ "SegmentedControl",
2772
+ "ChoicePicker",
2773
+ "FlashcardFlip",
2774
+ "Table",
2775
+ "List",
2776
+ "Chart",
2777
+ "Map",
2778
+ "Image",
2779
+ "Svg",
2780
+ "Citation",
2781
+ "FollowUp",
2782
+ "EntityCard"
2783
+ ]);
2784
+ function defaultGenerativeUIPromptSpec() {
2785
+ return {
2786
+ markdown: {
2787
+ intro: "You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.",
2788
+ whenToShow: GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,
2789
+ rules: [
2790
+ "Write explanations as normal markdown prose outside the fences.",
2791
+ "Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
2792
+ "Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target limits its components, its surfaces can use only those components.",
2793
+ "Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
2794
+ "Keep each operation whole on its line.",
2795
+ "Give every operation \"version\":\"1.0\".",
2796
+ "Start a surface with one createSurface. Put all the initial data in \"dataModel\" and the \"root\" component in \"components\". Then write the children in updateComponents lines, so that they show while you write:\n ```a2ui\n {\"version\":\"1.0\",\"createSurface\":{\"surfaceId\":\"plan-picker\",\"dataModel\":{ ...initial data... },\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"seats\",\"pick\"]}]}}\n {\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"plan-picker\",\"components\":[ ...the children... ]}}\n ```",
2797
+ "Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.",
2798
+ "Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
2799
+ "Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
2800
+ "Use unique ids. Do not make cycles. A component cannot be its own child.",
2801
+ "Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
2802
+ "Close each component with exactly one }, also when its last prop is a list: {\"id\":\"map\",\"component\":\"Map\",\"markers\":[{\"label\":\"A\",\"lat\":48.2,\"lng\":16.4}]}. A createSurface or updateComponents line ends with }]}} : the last component, the \"components\" list, the operation, the line.",
2803
+ "A prop that holds a call closes with }} : its \"args\", then the call. The component closes with its own single } after its last prop. With a prop after the call: {\"id\":\"count\",\"component\":\"Text\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}},\"size\":\"lg\"}. With the call last: {\"id\":\"count\",\"component\":\"Text\",\"size\":\"lg\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}}}.",
2804
+ "Deep props close every level they open, then the component closes with its own }. An event with a context: \"onSubmit\":{\"event\":{\"name\":\"send\",\"context\":{\"email\":{\"@path\":\"/email\"}}}}} ends with }}}}} : the path, \"context\", \"event\", the prop, the component. A Table: \"rows\":[[\"Mon\",\"9°C\"],[\"Tue\",\"7°C\"]]} ends with ]]} : the last row, \"rows\", the component, and nothing more. A list item with a call: \"items\":[{\"label\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} cups\"}}}]} ends with }}}]} : \"args\", the call, the item, the list, the component.",
2805
+ "Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
2806
+ "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component. \"live\":\"polite\" goes only inside \"accessibility\" ({\"accessibility\":{\"live\":\"polite\"}}), only on text that changes by itself, never as a prop of the component.",
2807
+ "Use only the components, props, events, and slots in the schema. A component marked +common also takes every common prop. A component with a prop that is not in its schema, or a value outside its enum, is dropped with everything inside it, so check each prop against the schema.",
2808
+ "Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
2809
+ "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions in the schema. Write a literal when the value never changes.",
2810
+ "formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: 'EUR')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.",
2811
+ "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: 'seats * 29', seats: /seats), currency: 'USD')}. The UI then follows the user's input with no round trip.",
2812
+ "Inside ${...}, close every ( you open, and write no operators and no ?: : compute with calc. To round a computed number, round inside calc instead of wrapping it in formatNumber: ${calc(expression: 'round(servings * 0.5 * 10) / 10', servings: /servings)} cups. calc has ^ (power), sqrt, exp and ln.",
2813
+ "To show one of two texts, let calc choose: \"text\":{\"@call\":\"calc\",\"args\":{\"expression\":\"billing == 'yearly' ? 'per year' : 'per month'\",\"billing\":{\"@path\":\"/billing\"}}}.",
2814
+ "For a computed list (chart data, template items) use series. Its description under Functions in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
2815
+ "Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
2816
+ "The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.",
2817
+ "To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
2818
+ "Set \"value\":null to delete the key at \"path\".",
2819
+ {
2820
+ when: ["events"],
2821
+ items: ["Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", "Put the action of a Button in its \"onClick\": {\"event\":{...}} to send it back to you, or {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"...\"}}}. Never write \"event\" or \"functionCall\" as a prop of its own."]
2822
+ },
2823
+ {
2824
+ when: ["events", "functions"],
2825
+ items: ["Use {\"functionCall\": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call."]
2826
+ },
2827
+ {
2828
+ when: ["events", "noFunctions"],
2829
+ items: ["Use {\"functionCall\": ...} to open a URL when the user clicks: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call."]
2830
+ },
2831
+ {
2832
+ when: ["events"],
2833
+ items: [
2834
+ "Use {\"event\": ...} to send the interaction back to you as a user message. Put the text of that message in \"userMessage\": {\"event\":{\"name\":\"choose\",\"userMessage\":\"Show me the Team plan\"}}. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".",
2835
+ "To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.",
2836
+ "A button or other event prop without an event or functionCall does nothing."
2837
+ ]
2838
+ },
2839
+ {
2840
+ when: ["checks"],
2841
+ items: ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {\"@path\"}. A failed check shows the message under the input and disables a Button that has the same checks."]
2842
+ },
2843
+ "A prop typed componentId takes the id of another component, and a childList takes ids [\"a\",\"b\"]: \"child\":\"card\", \"children\":[\"a\",\"b\"], \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].",
2844
+ {
2845
+ when: ["templates"],
2846
+ items: [
2847
+ "To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.",
2848
+ "Inside a template, paths are relative to the item (\"name\", not \"/name\").",
2849
+ "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}."
2850
+ ]
2851
+ },
2852
+ "Updating a component replaces all of its props. Send every prop again.",
2853
+ "To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.",
2854
+ "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.",
2855
+ {
2856
+ when: ["agentCalls"],
2857
+ items: [
2858
+ "To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.",
2859
+ "Give every callRendererFunction a new functionCallId. Call only a function that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked agent only is only for callRendererFunction: do not bind an event to it.",
2860
+ "The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.",
2861
+ "Do not guess the result of a callRendererFunction. Wait for the developer message."
2862
+ ]
2863
+ },
2864
+ "The schema lists the surfaces that already exist. \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.",
2865
+ "Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
2866
+ "Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
2867
+ "Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
2868
+ "Never wrap the whole reply in a fence."
2869
+ ]
2870
+ },
2871
+ tool: {
2872
+ intro: `Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
2873
+ whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
2874
+ operations: [
2875
+ "{\"version\":\"1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
2876
+ "{\"version\":\"1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
2877
+ "{\"version\":\"1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
2878
+ "{\"version\":\"1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
2879
+ {
2880
+ when: ["agentCalls"],
2881
+ items: ["{\"version\":\"1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."]
2882
+ }
2883
+ ],
2884
+ rules: [
2885
+ "Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
2886
+ "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
2887
+ "Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
2888
+ "Updating a component replaces all of its props, so resend every prop.",
2889
+ "Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
2890
+ {
2891
+ when: ["events", "functions"],
2892
+ items: ["Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below."]
2893
+ },
2894
+ {
2895
+ when: ["events", "noFunctions"],
2896
+ items: ["Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."]
2897
+ },
2898
+ "To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
2899
+ "Never use a surfaceId again, also after deleteSurface.",
2900
+ "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
2901
+ "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
2902
+ "For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
2903
+ {
2904
+ when: ["checks"],
2905
+ items: ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."]
2906
+ },
2907
+ {
2908
+ when: ["templates"],
2909
+ items: ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."]
2910
+ },
2911
+ {
2912
+ when: ["agentCalls"],
2913
+ items: ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."]
2914
+ }
2915
+ ]
2916
+ },
2917
+ schema: {
2918
+ markdown: {
2919
+ notation: "lines",
2920
+ propDescriptions: true,
2921
+ commonProps: true
2922
+ },
2923
+ tool: {
2924
+ notation: "json-schema",
2925
+ propDescriptions: true,
2926
+ commonProps: false
2927
+ }
2928
+ },
2929
+ descriptions: {}
2930
+ };
2931
+ }
2932
+ /** The rules of `items` whose block conditions hold, in order. */
2933
+ function selectPromptItems(items, features) {
2934
+ return items.flatMap((item) => typeof item === "string" ? [item] : item.when.every((feature) => features[feature]) ? item.items : []);
2935
+ }
2936
+ /**
2937
+ * The prompt features of a run, from the guide features of its manifest
2938
+ * (`generativeUIGuideFeatures`).
2939
+ */
2940
+ function generativeUIPromptFeatures(guide) {
2941
+ return {
2942
+ functions: guide.functions,
2943
+ noFunctions: !guide.functions,
2944
+ events: guide.events,
2945
+ templates: guide.templates,
2946
+ checks: guide.checks,
2947
+ agentCalls: guide.functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS
2948
+ };
2949
+ }
2950
+
2735
2951
  //#endregion
2736
2952
  //#region src/a2ui-prompts.ts
2737
2953
  /**
@@ -2847,12 +3063,6 @@ Design principles:
2847
3063
  action context should reference the same paths to capture user input.
2848
3064
 
2849
3065
  Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
2850
- /**
2851
- * When UI helps the user, for both transports: a light nudge to reach for UI
2852
- * where it conveys the answer better than prose, and to stay in prose
2853
- * otherwise.
2854
- */
2855
- const GENERATIVE_UI_WHEN_TO_SHOW = "Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
2856
3066
  /** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */
2857
3067
  const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = "Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.";
2858
3068
  /**
@@ -2898,6 +3108,7 @@ Use the SAME surfaceId as the main surface. Match action names to button action
2898
3108
  return Object.values(node).some(hasChildList);
2899
3109
  };
2900
3110
  return {
3111
+ components: Object.keys(manifest.components),
2901
3112
  functions: Object.keys(manifest.functions).some((name) => !isA2UIBasicFunction(name)),
2902
3113
  events: components.some((c) => {
2903
3114
  var _c$events;
@@ -2913,43 +3124,21 @@ Use the SAME surfaceId as the main surface. Match action names to button action
2913
3124
  })
2914
3125
  };
2915
3126
  }
2916
- /** The first rules of every markdown guideline, before the optional groups. */
2917
- const MARKDOWN_BASE_RULES = [
2918
- "Write explanations as normal markdown prose outside the fences.",
2919
- "Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
2920
- "Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target has \"components\", its surfaces can use only those components.",
2921
- "Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
2922
- "Keep each operation whole on its line.",
2923
- "Give every operation \"version\":\"v1.0\".",
2924
- `Start a surface with one createSurface. Put all the initial data in "dataModel" and the "root" component in "components". Then write the children in updateComponents lines, so that they show while you write:
2925
- \`\`\`a2ui
2926
- {"version":"v1.0","createSurface":{"surfaceId":"plan-picker","dataModel":{ ...initial data... },"components":[{"id":"root","component":"<Name>","children":["seats","pick"]}]}}
2927
- {"version":"v1.0","updateComponents":{"surfaceId":"plan-picker","components":[ ...the children... ]}}
2928
- \`\`\``,
2929
- "Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.",
2930
- "Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
2931
- "Use unique ids. Do not make cycles. A component cannot be its own child.",
2932
- "Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
2933
- "Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
2934
- "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
2935
- "Use only the components, props, events, and slots in the schema. A component with \"includesCommonProps\" also takes every prop in \"commonProps\".",
2936
- "Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
2937
- "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions under \"functions\" in the schema. Write a literal when the value never changes.",
2938
- "formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: 'EUR')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.",
2939
- "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: 'seats * 29', seats: /seats), currency: 'USD')}. The UI then follows the user's input with no round trip.",
2940
- "For a computed list (chart data, template items) use series. Its description under \"functions\" in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
2941
- "Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
2942
- "To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
2943
- "Set \"value\":null to delete the key at \"path\"."
2944
- ];
2945
- /** The last rules of every markdown guideline, after the optional groups. */
2946
- const MARKDOWN_CLOSING_RULES = [
2947
- "The schema lists the surfaces that already exist under \"surfaces\". \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.",
2948
- "Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
2949
- "Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
2950
- "Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
2951
- "Never wrap the whole reply in a fence."
2952
- ];
3127
+ /**
3128
+ * Whether a guide line names only standard components (`GUIDE_COMPONENTS`,
3129
+ * also in the plural) that the catalog has. With no catalog, every line fits.
3130
+ */
3131
+ function namesOnlyCatalogComponents(catalog) {
3132
+ if (!catalog) return () => true;
3133
+ const has = new Set(catalog);
3134
+ return (line) => {
3135
+ var _line$match;
3136
+ return ((_line$match = line.match(/\b[A-Z][A-Za-z0-9]*\b/g)) !== null && _line$match !== void 0 ? _line$match : []).every((word) => {
3137
+ const name = !GUIDE_COMPONENTS.has(word) && word.endsWith("s") ? word.slice(0, -1) : word;
3138
+ return !GUIDE_COMPONENTS.has(name) || has.has(name);
3139
+ });
3140
+ };
3141
+ }
2953
3142
  /**
2954
3143
  * Builds the markdown-transport guideline. The model writes A2UI v1.0
2955
3144
  * operations inside ```a2ui fences between normal markdown prose. The rules
@@ -2957,25 +3146,15 @@ Use the SAME surfaceId as the main surface. Match action names to button action
2957
3146
  * none of them, so the guideline stays small.
2958
3147
  *
2959
3148
  * @param features - The optional rule groups to include. Defaults to all.
3149
+ * @param spec - The wording. Defaults to the prompts that ship.
2960
3150
  * @returns The guideline text, one rule per line.
2961
3151
  */
2962
- function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES) {
2963
- const { functions, events, templates, checks } = features;
2964
- const rules = [...MARKDOWN_BASE_RULES];
2965
- if (events) rules.push("Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", functions ? "Use {\"functionCall\": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call." : "Use {\"functionCall\": ...} to open a URL when the user clicks: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call.", "Use {\"event\": ...} to send the interaction back to you as a user message. Put the text of that message in \"userMessage\": {\"event\":{\"name\":\"choose\",\"userMessage\":\"Show me the Team plan\"}}. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".", "To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.", "A button or other event prop without an event or functionCall does nothing.");
2966
- if (checks) rules.push("Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {\"@path\"}. A failed check shows the message under the input and disables a Button that has the same checks.");
2967
- rules.push("A prop typed componentId takes the id of another component, and a childList takes ids [\"a\",\"b\"]: \"child\":\"card\", \"children\":[\"a\",\"b\"], \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].");
2968
- if (templates) rules.push("To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.", "Inside a template, paths are relative to the item (\"name\", not \"/name\").", "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}.");
2969
- rules.push("Updating a component replaces all of its props. Send every prop again.", "To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.", "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.");
2970
- if (functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS) rules.push("To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.", "Give every callRendererFunction a new functionCallId. Call only a function from the schema with \"callers\": \"UI or agent\" or \"agent only\"; a function without \"callers\" is for the UI only. A function with \"callers\": \"agent only\" is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.", "Do not guess the result of a callRendererFunction. Wait for the developer message.");
2971
- rules.push(...MARKDOWN_CLOSING_RULES);
2972
- return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.
2973
-
2974
- ${GENERATIVE_UI_WHEN_TO_SHOW}
2975
-
2976
- RULES
2977
- ${rules.map((rule) => `- ${rule}`).join("\n")}
2978
- `;
3152
+ function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES, spec = defaultGenerativeUIPromptSpec()) {
3153
+ const { intro, rules } = spec.markdown;
3154
+ const fits = namesOnlyCatalogComponents(features.components);
3155
+ const selected = selectPromptItems(rules, generativeUIPromptFeatures(features)).filter(fits);
3156
+ const whenToShow = spec.markdown.whenToShow.split("\n").filter(fits).join("\n");
3157
+ return `${intro}\n\n${whenToShow ? `${whenToShow}\n\n` : ""}RULES\n${selected.map((rule) => `- ${rule}`).join("\n")}\n`;
2979
3158
  }
2980
3159
  /**
2981
3160
  * The markdown-transport guideline with every rule group. A run sends
@@ -3003,11 +3182,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3003
3182
  return typeof value === "string" && value !== "";
3004
3183
  }
3005
3184
  function isRecordOf(value, isEntry) {
3006
- return isRecord(value) && Object.values(value).every(isEntry);
3185
+ return isRecord$2(value) && Object.values(value).every(isEntry);
3007
3186
  }
3008
3187
  /** A function, or an event of a component: a description and a parameter schema. */
3009
3188
  function isSchemaEntry(value) {
3010
- return isRecord(value) && isRecord(value.parameters) && isOptionalString(value.description);
3189
+ return isRecord$2(value) && isRecord$2(value.parameters) && isOptionalString(value.description);
3011
3190
  }
3012
3191
  function isSlotKind(value) {
3013
3192
  return value === "single" || value === "multiple";
@@ -3017,11 +3196,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3017
3196
  * so those two must have the right shape when they are there.
3018
3197
  */
3019
3198
  function isPropsSchema(value) {
3020
- return isRecord(value) && (value.properties === void 0 || isRecord(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
3199
+ return isRecord$2(value) && (value.properties === void 0 || isRecord$2(value.properties)) && (value.required === void 0 || Array.isArray(value.required) && value.required.every((name) => typeof name === "string"));
3021
3200
  }
3022
3201
  function isComponentManifest(value) {
3023
3202
  var _value$props$properti, _value$slots, _value$events;
3024
- if (!isRecord(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
3203
+ if (!isRecord$2(value) || !isPropsSchema(value.props) || !isOptionalString(value.description) || value.events !== void 0 && !isRecordOf(value.events, isSchemaEntry) || value.slots !== void 0 && !isRecordOf(value.slots, isSlotKind)) return false;
3025
3204
  const order = value.parameterOrder;
3026
3205
  if (order === void 0) return true;
3027
3206
  const keys = new Set([
@@ -3032,31 +3211,31 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3032
3211
  return Array.isArray(order) && new Set(order).size === order.length && order.every((key) => typeof key === "string" && keys.has(key));
3033
3212
  }
3034
3213
  function isInlineCatalog(value) {
3035
- return isRecord(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
3214
+ return isRecord$2(value) && isNonEmptyString(value.catalogId) && value.protocolVersion === "1.0" && (value.components === void 0 || isRecordOf(value.components, isComponentManifest)) && isRecordOf(value.functions, isSchemaEntry) && isOptionalString(value.instructions);
3036
3215
  }
3037
3216
  function isCapabilities(value) {
3038
- return isRecord(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
3217
+ return isRecord$2(value) && Array.isArray(value.supportedCatalogIds) && value.supportedCatalogIds.length > 0 && value.supportedCatalogIds.every(isNonEmptyString) && (value.inlineCatalogs === void 0 || Array.isArray(value.inlineCatalogs) && value.inlineCatalogs.every(isInlineCatalog));
3039
3218
  }
3040
3219
  /** A short list of component names. */
3041
3220
  function isComponentNameList(value) {
3042
3221
  return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS && value.every(isNonEmptyString);
3043
3222
  }
3044
3223
  function isTarget(value) {
3045
- return isRecord(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
3224
+ return isRecord$2(value) && isNonEmptyString(value.id) && (value.kind === "chat" || value.kind === "inline") && isOptionalString(value.description) && (value.components === void 0 || isComponentNameList(value.components));
3046
3225
  }
3047
3226
  /** A short list of short strings. The summary limits keep the guide small. */
3048
3227
  function isRejectionList(value) {
3049
3228
  return Array.isArray(value) && value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS && value.every((entry) => typeof entry === "string" && entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH);
3050
3229
  }
3051
3230
  function isSurfaceEntry(value) {
3052
- return isRecord(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed");
3231
+ return isRecord$2(value) && isNonEmptyString(value.target) && (value.dataModel === void 0 || isRecord$2(value.dataModel)) && (value.rejected === void 0 || isRejectionList(value.rejected)) && (value.status === void 0 || value.status === "deleted" || value.status === "failed");
3053
3232
  }
3054
3233
  /** Checks the `copilotkit_` keys only. Other extensions can be there too. */
3055
3234
  function isExtensions(value) {
3056
- return isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
3235
+ return isRecord$2(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
3057
3236
  }
3058
3237
  function isEnvelope(value) {
3059
- return isRecord(value) && isCapabilities(value["v1.0"]) && isRecord(value.metadata) && isExtensions(value.metadata.extensions);
3238
+ return isRecord$2(value) && isCapabilities(value["1.0"]) && isRecord$2(value.metadata) && isExtensions(value.metadata.extensions);
3060
3239
  }
3061
3240
  /**
3062
3241
  * Reads the generative UI envelope from the `forwardedProps` of a run.
@@ -3077,9 +3256,9 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3077
3256
  * ```
3078
3257
  */
3079
3258
  function readCopilotKitUIEnvelope(forwardedProps) {
3080
- if (!isRecord(forwardedProps)) return void 0;
3259
+ if (!isRecord$2(forwardedProps)) return void 0;
3081
3260
  const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];
3082
- if (!isRecord(namespace)) return void 0;
3261
+ if (!isRecord$2(namespace)) return void 0;
3083
3262
  const envelope = namespace.ui;
3084
3263
  return isEnvelope(envelope) ? envelope : void 0;
3085
3264
  }
@@ -3112,7 +3291,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3112
3291
  */
3113
3292
  function envelopeToManifest(envelope) {
3114
3293
  var _catalog$components, _catalog$functions;
3115
- const { supportedCatalogIds, inlineCatalogs } = envelope["v1.0"];
3294
+ const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
3116
3295
  const catalogId = supportedCatalogIds[0];
3117
3296
  const catalog = inlineCatalogs === null || inlineCatalogs === void 0 ? void 0 : inlineCatalogs.find((entry) => entry.catalogId === catalogId);
3118
3297
  const extensions = envelope.metadata.extensions;
@@ -3152,7 +3331,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3152
3331
  });
3153
3332
  /** Models write the v0.9 binding from habit. The reason names the v1.0 form. */
3154
3333
  const V09_PATH_REASON = "bind data with {\"@path\": \"/x\"}, not {\"path\": \"/x\"}";
3155
- function hasOwn(record, key) {
3334
+ function hasOwn$1(record, key) {
3156
3335
  return Object.prototype.hasOwnProperty.call(record, key);
3157
3336
  }
3158
3337
  /**
@@ -3160,42 +3339,42 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3160
3339
  * "toString" must not resolve to Object.prototype members.
3161
3340
  */
3162
3341
  function ownValue(record, key) {
3163
- return record && hasOwn(record, key) ? record[key] : void 0;
3342
+ return record && hasOwn$1(record, key) ? record[key] : void 0;
3164
3343
  }
3165
3344
  function getOperationKind(op) {
3166
- if (!isRecord(op)) return void 0;
3345
+ if (!isRecord$2(op)) return void 0;
3167
3346
  const kinds = OPERATION_KINDS.filter((kind) => kind in op);
3168
3347
  return kinds.length === 1 ? kinds[0] : void 0;
3169
3348
  }
3170
3349
  /** The `surfaceId` of a surface operation. `callRendererFunction` has none. */
3171
3350
  function getOperationSurfaceId(op) {
3172
- if (!isRecord(op)) return void 0;
3351
+ if (!isRecord$2(op)) return void 0;
3173
3352
  const kind = getOperationKind(op);
3174
3353
  if (!kind) return void 0;
3175
3354
  const payload = op[kind];
3176
- return isRecord(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
3355
+ return isRecord$2(payload) && typeof payload.surfaceId === "string" ? payload.surfaceId : void 0;
3177
3356
  }
3178
3357
  /** `{ "@path": "/x" }`: a data-model binding. */
3179
3358
  function isPathBinding(value) {
3180
- return isRecord(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
3359
+ return isRecord$2(value) && typeof value["@path"] === "string" && Object.keys(value).length === 1;
3181
3360
  }
3182
3361
  /** `{ "path": "/x" }`: the v0.9 binding, which v1.0 does not accept. */
3183
3362
  function isV09PathBinding(value) {
3184
- return isRecord(value) && typeof value.path === "string" && Object.keys(value).length === 1;
3363
+ return isRecord$2(value) && typeof value.path === "string" && Object.keys(value).length === 1;
3185
3364
  }
3186
3365
  /**
3187
3366
  * `{ "@call": "@index" }` or `{ "@call": "@index", "args": { "offset": 1 } }`:
3188
3367
  * the 0-based position of the item in a template, plus `offset`.
3189
3368
  */
3190
3369
  function isIndexCall(value) {
3191
- if (!isRecord(value) || value["@call"] !== "@index") return false;
3370
+ if (!isRecord$2(value) || value["@call"] !== "@index") return false;
3192
3371
  if (!Object.keys(value).every((key) => key === "@call" || key === "args")) return false;
3193
3372
  const { args } = value;
3194
3373
  if (args === void 0) return true;
3195
- return isRecord(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
3374
+ return isRecord$2(args) && Object.keys(args).every((key) => key === "offset") && (args.offset === void 0 || Number.isFinite(args.offset));
3196
3375
  }
3197
3376
  function isActionBinding(value) {
3198
- return isRecord(value) && Object.keys(value).length === 1 && (isRecord(value.functionCall) || isRecord(value.event));
3377
+ return isRecord$2(value) && Object.keys(value).length === 1 && (isRecord$2(value.functionCall) || isRecord$2(value.event));
3199
3378
  }
3200
3379
  /**
3201
3380
  * Checks one A2UI v1.0 operation against the catalog and the surfaces that
@@ -3213,7 +3392,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3213
3392
  * ```
3214
3393
  */
3215
3394
  function validateOperation(op, options) {
3216
- if (!isRecord(op)) return fail("operation must be a JSON object");
3395
+ if (!isRecord$2(op)) return fail("operation must be a JSON object");
3217
3396
  if (op.version !== A2UI_VERSION) return fail(versionProblem(op.version));
3218
3397
  const kind = getOperationKind(op);
3219
3398
  if (!kind) return fail(`operation must contain exactly one of ${OPERATION_KINDS.join(", ")}`);
@@ -3222,7 +3401,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3222
3401
  if (!GENERATIVE_UI_AGENT_FUNCTION_CALLS) return fail(GENERATIVE_UI_AGENT_FUNCTION_CALLS_OFF_REASON);
3223
3402
  return validateRendererFunctionCall(payload, options);
3224
3403
  }
3225
- if (!isRecord(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
3404
+ if (!isRecord$2(payload) || typeof payload.surfaceId !== "string" || !payload.surfaceId) return fail(`${kind}.surfaceId is required`);
3226
3405
  const surfaceId = payload.surfaceId;
3227
3406
  if (kind === "createSurface") return validateCreateSurface(payload, surfaceId, options);
3228
3407
  if (!options.knownSurfaces.has(surfaceId)) return fail(`surface "${surfaceId}" does not exist; send createSurface first`);
@@ -3251,12 +3430,12 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3251
3430
  const catalogReason = catalogProblem(payload.catalogId, options.manifest);
3252
3431
  if (catalogReason) return fail(catalogReason);
3253
3432
  const { dataModel, components } = payload;
3254
- if (dataModel !== void 0 && !isRecord(dataModel)) return fail("createSurface.dataModel must be a JSON object");
3433
+ if (dataModel !== void 0 && !isRecord$2(dataModel)) return fail("createSurface.dataModel must be a JSON object");
3255
3434
  if (components === void 0) return OK;
3256
3435
  return validateComponents(components, "createSurface.components", options);
3257
3436
  }
3258
3437
  function validateRendererFunctionCall(payload, options) {
3259
- if (!(isRecord(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
3438
+ if (!(isRecord$2(payload) && typeof payload.functionCallId === "string" && payload.functionCallId !== "")) return fail("callRendererFunction.functionCallId must be a non-empty string");
3260
3439
  const reason = functionCallProblem(payload.callFunction, "callRendererFunction.callFunction", options);
3261
3440
  return reason ? fail(reason) : OK;
3262
3441
  }
@@ -3274,7 +3453,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3274
3453
  const path = (_payload$path = payload.path) !== null && _payload$path !== void 0 ? _payload$path : "/";
3275
3454
  if (typeof path !== "string" || !path.startsWith("/")) return fail("updateDataModel.path must be an absolute JSON pointer");
3276
3455
  if (path === "/") {
3277
- if (!isRecord(payload.value)) return fail("a root updateDataModel value must be a JSON object");
3456
+ if (!isRecord$2(payload.value)) return fail("a root updateDataModel value must be a JSON object");
3278
3457
  return OK;
3279
3458
  }
3280
3459
  const reason = pathProblem(path, "updateDataModel.path");
@@ -3294,7 +3473,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3294
3473
  if (!Array.isArray(components) || components.length === 0) return fail(`${label} must be a non-empty array`);
3295
3474
  const ids = /* @__PURE__ */ new Set();
3296
3475
  for (const node of components) {
3297
- if (!isRecord(node)) return fail("component must be a JSON object");
3476
+ if (!isRecord$2(node)) return fail("component must be a JSON object");
3298
3477
  const { id } = node;
3299
3478
  if (typeof id !== "string" || !id) return fail("id is required");
3300
3479
  const reason = nodeProblem(node, id, options);
@@ -3314,7 +3493,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3314
3493
  return `"${node.component}" is not allowed in target "${allowedComponents.target}"; use one of: ${names}`;
3315
3494
  }
3316
3495
  const { properties, required } = entry.props;
3317
- const propNames = isRecord(properties) ? Object.keys(properties) : [];
3496
+ const propNames = isRecord$2(properties) ? Object.keys(properties) : [];
3318
3497
  const props = Object.entries(node);
3319
3498
  for (const [key, value] of props) {
3320
3499
  if (key === "id" || key === "component") continue;
@@ -3324,7 +3503,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3324
3503
  continue;
3325
3504
  }
3326
3505
  if (key === "metadata") {
3327
- if (!(isRecord(value) && (value.extensions === void 0 || isRecord(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
3506
+ if (!(isRecord$2(value) && (value.extensions === void 0 || isRecord$2(value.extensions)))) return "metadata must be { \"extensions\": { ... } }";
3328
3507
  continue;
3329
3508
  }
3330
3509
  if (key === "accessibility") {
@@ -3372,7 +3551,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3372
3551
  * values, `hidden` is a boolean or a dynamic value.
3373
3552
  */
3374
3553
  function accessibilityProblem(value) {
3375
- if (!isRecord(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
3554
+ if (!isRecord$2(value)) return "must be { \"label\": \"...\", \"description\": \"...\", \"live\": \"polite\", \"hidden\": false }";
3376
3555
  const isDynamic = (field) => isPathBinding(field) || isCallBinding(field);
3377
3556
  for (const [key, field] of Object.entries(value)) {
3378
3557
  if (!ACCESSIBILITY_KEYS.includes(key)) return `unknown key "${key}"`;
@@ -3390,7 +3569,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3390
3569
  }
3391
3570
  }
3392
3571
  function actionBindingProblem(value, options) {
3393
- if (!isRecord(value)) return "must be an action object";
3572
+ if (!isRecord$2(value)) return "must be an action object";
3394
3573
  const keys = Object.keys(value);
3395
3574
  if (!(keys.length === 1 && (keys[0] === "functionCall" || keys[0] === "event"))) return "must be { \"event\": ... } or { \"functionCall\": ... }";
3396
3575
  if (keys[0] === "functionCall") return functionCallProblem(value.functionCall, "functionCall", options);
@@ -3401,18 +3580,18 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3401
3580
  * field in the reason.
3402
3581
  */
3403
3582
  function functionCallProblem(call, label, options) {
3404
- if (!isRecord(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
3583
+ if (!isRecord$2(call)) return `${label} must be { "@call": "<function>", "args": { ... } }`;
3405
3584
  const name = call["@call"];
3406
3585
  if (typeof name !== "string" || !name) return typeof call.call === "string" ? `${label} names the function with "@call", not "call"` : `${label}["@call"] must be a function name`;
3407
3586
  const { args } = call;
3408
- if (args !== void 0 && !isRecord(args)) return `${label}.args must be an object`;
3587
+ if (args !== void 0 && !isRecord$2(args)) return `${label}.args must be an object`;
3409
3588
  const catalogReason = catalogProblem(call.catalogId, options.manifest);
3410
3589
  if (catalogReason) return `${label}: ${catalogReason}`;
3411
3590
  const argEntries = Object.entries(args !== null && args !== void 0 ? args : {});
3412
3591
  for (const [key, arg] of argEntries) if (isV09PathBinding(arg)) return `${label}.args.${key}: ${V09_PATH_REASON}`;
3413
3592
  const appFunctions = options.functions;
3414
- const declared = appFunctions !== void 0 && hasOwn(appFunctions, name) ? appFunctions[name] : void 0;
3415
- const builtIn = declared === void 0 && hasOwn(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
3593
+ const declared = appFunctions !== void 0 && hasOwn$1(appFunctions, name) ? appFunctions[name] : void 0;
3594
+ const builtIn = declared === void 0 && hasOwn$1(GENERATIVE_UI_FUNCTIONS, name) ? GENERATIVE_UI_FUNCTIONS[name] : void 0;
3416
3595
  if (declared === void 0 && builtIn === void 0) return appFunctions === void 0 ? void 0 : `function "${name}" is not exposed to generative UI`;
3417
3596
  if (declared === void 0 && appFunctions === void 0) return void 0;
3418
3597
  return callerProblem(name, declared !== null && declared !== void 0 ? declared : builtIn, label.startsWith("callRendererFunction") ? "agent" : "renderer");
@@ -3428,11 +3607,11 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3428
3607
  if (caller === "renderer" && !callers.renderer) return `function "${name}" runs only for the agent (allowedCallers "agentOnly"); the UI cannot call it`;
3429
3608
  }
3430
3609
  function eventProblem(event) {
3431
- if (!isRecord(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
3610
+ if (!isRecord$2(event) || typeof event.name !== "string" || !event.name) return "event.name is required";
3432
3611
  const { userMessage, context } = event;
3433
- if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
3612
+ if (!(userMessage === void 0 || typeof userMessage === "string" || isPathBinding(userMessage) || isRecord$2(userMessage) && typeof userMessage["@call"] === "string" && findForbiddenCall(userMessage, { allowValueFunctions: true }) === void 0)) return isV09PathBinding(userMessage) ? `event.userMessage: ${V09_PATH_REASON}` : "event.userMessage must be a string, {\"@path\": \"/x\"} or a function value";
3434
3613
  if (context === void 0) return void 0;
3435
- if (!isRecord(context)) return "event.context must be an object";
3614
+ if (!isRecord$2(context)) return "event.context must be an object";
3436
3615
  const entries = Object.entries(context);
3437
3616
  for (const [key, entry] of entries) {
3438
3617
  if (isV09PathBinding(entry)) return `event.context.${key}: ${V09_PATH_REASON}`;
@@ -3441,7 +3620,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3441
3620
  }
3442
3621
  }
3443
3622
  function slotProblem(value, kind, ownId) {
3444
- const isTemplate = isRecord(value) && "componentId" in value;
3623
+ const isTemplate = isRecord$2(value) && "componentId" in value;
3445
3624
  if (kind === "single" && isTemplate) return "a template { \"componentId\", \"path\" } is only allowed in a \"multiple\" slot";
3446
3625
  if (kind === "multiple" && isTemplate) return templateProblem(value, ownId);
3447
3626
  if (kind === "multiple" && !Array.isArray(value)) return "must be an array of component ids or a template { \"componentId\", \"path\" }";
@@ -3475,7 +3654,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3475
3654
  }
3476
3655
  return;
3477
3656
  }
3478
- if (!isRecord(value)) return void 0;
3657
+ if (!isRecord$2(value)) return void 0;
3479
3658
  if (isIndexCall(value)) return void 0;
3480
3659
  if (value["@call"] === "@index") return "@index takes only an offset";
3481
3660
  if (typeof value.call === "string") return "name the function with \"@call\", not \"call\"";
@@ -3484,7 +3663,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3484
3663
  if (typeof name === "string") {
3485
3664
  if (!options.allowValueFunctions || !isA2UIValueFunction(name)) return isA2UIBasicFunction(name) ? `"${name}" runs only from an event` : `"${name}" is not a basic function`;
3486
3665
  const args = value.args;
3487
- if (args !== void 0 && !isRecord(args)) return `the args of "${name}" must be an object`;
3666
+ if (args !== void 0 && !isRecord$2(args)) return `the args of "${name}" must be an object`;
3488
3667
  return args === void 0 ? void 0 : findForbiddenCall(args, options);
3489
3668
  }
3490
3669
  for (const item of Object.values(value)) {
@@ -3509,7 +3688,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3509
3688
  */
3510
3689
  function childRefProblem(node, ref, ownId) {
3511
3690
  const label = ref.path.filter((step) => step !== "*").join(".");
3512
- const isDynamic = (value) => isPathBinding(value) || isRecord(value) && "@call" in value;
3691
+ const isDynamic = (value) => isPathBinding(value) || isRecord$2(value) && "@call" in value;
3513
3692
  const visit = (value, steps) => {
3514
3693
  if (isDynamic(value)) return void 0;
3515
3694
  if (steps.length === 0) {
@@ -3525,7 +3704,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3525
3704
  }
3526
3705
  return;
3527
3706
  }
3528
- if (!isRecord(value) || !hasOwn(value, head)) return void 0;
3707
+ if (!isRecord$2(value) || !hasOwn$1(value, head)) return void 0;
3529
3708
  return visit(value[head], rest);
3530
3709
  };
3531
3710
  return visit(node, ref.path);
@@ -3649,7 +3828,7 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3649
3828
  function parseObject(raw) {
3650
3829
  try {
3651
3830
  const value = JSON.parse(raw);
3652
- return isRecord(value) ? value : null;
3831
+ return isRecord$2(value) ? value : null;
3653
3832
  } catch (_unused3) {
3654
3833
  return null;
3655
3834
  }
@@ -3686,6 +3865,434 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3686
3865
  }
3687
3866
  };
3688
3867
 
3868
+ //#endregion
3869
+ //#region src/generative-ui/compact-schema.ts
3870
+ /** Objects nested deeper than this show as `object`. */
3871
+ const MAX_OBJECT_DEPTH = 2;
3872
+ /** A prop must appear verbatim in at least this many components to be hoisted. */
3873
+ const COMMON_PROP_MIN_COMPONENTS = 8;
3874
+ function isRecord$1(value) {
3875
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3876
+ }
3877
+ /** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */
3878
+ function schemaList(value) {
3879
+ return Array.isArray(value) ? value.filter(isRecord$1) : [];
3880
+ }
3881
+ /**
3882
+ * Puts a top-level union in parentheses, so that `[]` applies to all of
3883
+ * it. A union inside braces needs none.
3884
+ */
3885
+ function asArrayItem(type) {
3886
+ let outside = type;
3887
+ for (let inner = outside.replace(/\{[^{}]*\}/g, ""); inner !== outside;) {
3888
+ outside = inner;
3889
+ inner = outside.replace(/\{[^{}]*\}/g, "");
3890
+ }
3891
+ return outside.includes(" | ") ? `(${type})[]` : `${type}[]`;
3892
+ }
3893
+ /**
3894
+ * A JSON Schema as a short TypeScript-like type, for example
3895
+ * `{ label: string; size?: "sm" | "md" }`.
3896
+ */
3897
+ function compactType(schema, depth) {
3898
+ const ref = childRefKind(schema);
3899
+ if (ref === "single") return "componentId";
3900
+ if (ref === "multiple") return "componentId[] | { componentId: string; path: string }";
3901
+ if ("const" in schema) return JSON.stringify(schema.const);
3902
+ if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
3903
+ const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];
3904
+ if (variants.length > 0) return variants.map((variant) => compactType(variant, depth)).join(" | ");
3905
+ return (Array.isArray(schema.type) ? schema.type : [schema.type]).map((type) => {
3906
+ switch (type) {
3907
+ case "string":
3908
+ case "boolean":
3909
+ case "null": return type;
3910
+ case "number":
3911
+ case "integer": return "number";
3912
+ case "array": return isRecord$1(schema.items) ? asArrayItem(compactType(schema.items, depth)) : "unknown[]";
3913
+ case "object": return compactObject(schema, depth);
3914
+ default: return "unknown";
3915
+ }
3916
+ }).join(" | ");
3917
+ }
3918
+ /** An object schema as `{ key: type; other?: type }`. */
3919
+ function compactObject(schema, depth) {
3920
+ const properties = isRecord$1(schema.properties) ? schema.properties : {};
3921
+ const entries = Object.entries(properties);
3922
+ if (entries.length === 0) return isRecord$1(schema.additionalProperties) ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>` : "object";
3923
+ if (depth >= MAX_OBJECT_DEPTH) return "object";
3924
+ const required = Array.isArray(schema.required) ? schema.required : [];
3925
+ return `{ ${entries.map(([key, value]) => {
3926
+ const type = isRecord$1(value) ? compactType(value, depth + 1) : "unknown";
3927
+ return `${key}${required.includes(key) ? "" : "?"}: ${type}`;
3928
+ }).join("; ")} }`;
3929
+ }
3930
+ /** A schema as its type, with its description after `//`. */
3931
+ function describedType(schema, depth) {
3932
+ const type = compactType(schema, depth);
3933
+ return typeof schema.description === "string" ? `${type} // ${schema.description}` : type;
3934
+ }
3935
+ /**
3936
+ * The props of a component: `{ "label": "string", "size?": "..." }`. With
3937
+ * `descriptions`, each type carries its description after `//`.
3938
+ */
3939
+ function compactProps(schema, descriptions = true) {
3940
+ const properties = isRecord$1(schema.properties) ? schema.properties : {};
3941
+ const required = Array.isArray(schema.required) ? schema.required : [];
3942
+ const props = {};
3943
+ for (const [key, value] of Object.entries(properties)) {
3944
+ if (!isRecord$1(value)) continue;
3945
+ const name = required.includes(key) ? key : `${key}?`;
3946
+ props[name] = descriptions ? describedType(value, 1) : compactType(value, 1);
3947
+ }
3948
+ return props;
3949
+ }
3950
+ /**
3951
+ * The prop set worth listing once. Candidates are (key, type) pairs that at
3952
+ * least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The
3953
+ * candidate subset of each component is a possible common set, scored by
3954
+ * the characters it saves (set size times the components that contain all
3955
+ * of it). `undefined` when no set is shared by enough components.
3956
+ */
3957
+ function findCommonProps(propsList) {
3958
+ const pairKey = (key, type) => `${key}\u0000${type}`;
3959
+ const counts = /* @__PURE__ */ new Map();
3960
+ for (const props of propsList) for (const [key, type] of Object.entries(props)) {
3961
+ var _counts$get;
3962
+ const id = pairKey(key, type);
3963
+ counts.set(id, ((_counts$get = counts.get(id)) !== null && _counts$get !== void 0 ? _counts$get : 0) + 1);
3964
+ }
3965
+ let best;
3966
+ let bestScore = 0;
3967
+ const seen = /* @__PURE__ */ new Set();
3968
+ for (const props of propsList) {
3969
+ const subset = Object.entries(props).filter(([key, type]) => {
3970
+ var _counts$get2;
3971
+ return ((_counts$get2 = counts.get(pairKey(key, type))) !== null && _counts$get2 !== void 0 ? _counts$get2 : 0) >= COMMON_PROP_MIN_COMPONENTS;
3972
+ });
3973
+ if (subset.length < 2) continue;
3974
+ const signature = subset.map(([key, type]) => pairKey(key, type)).join("\n");
3975
+ if (seen.has(signature)) continue;
3976
+ seen.add(signature);
3977
+ const members = propsList.filter((other) => subset.every(([key, type]) => other[key] === type)).length;
3978
+ if (members < COMMON_PROP_MIN_COMPONENTS) continue;
3979
+ const score = subset.reduce((total, [key, type]) => total + key.length + type.length, 0) * (members - 1);
3980
+ if (score > bestScore) {
3981
+ bestScore = score;
3982
+ best = Object.fromEntries(subset);
3983
+ }
3984
+ }
3985
+ return best;
3986
+ }
3987
+ /**
3988
+ * The component schema of the markdown transport, from the per-run
3989
+ * manifest. It is smaller than the manifest: each prop is one short type,
3990
+ * and the props that many components share verbatim (the layout props of
3991
+ * the containers) are listed once in `commonProps`; a component that takes
3992
+ * them is flagged `includesCommonProps`.
3993
+ * It has the catalog id, the targets with their descriptions and their
3994
+ * component lists, the functions with their parameters, the components
3995
+ * with their props, events and slots, and the surfaces of the thread. A surface lists the
3996
+ * values that the user set and the operations that the client dropped.
3997
+ *
3998
+ * @param manifest - The manifest from `buildGenerativeUIManifest`.
3999
+ * @param options - `propDescriptions` (default true) writes each prop's
4000
+ * description; `commonProps` (default true) lists shared props once.
4001
+ * @returns A JSON-ready object.
4002
+ *
4003
+ * @example
4004
+ * ```ts
4005
+ * const value = JSON.stringify(
4006
+ * buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),
4007
+ * );
4008
+ * ```
4009
+ */
4010
+ function buildCompactGenerativeUISchema(manifest, options = {}) {
4011
+ const { propDescriptions = true, commonProps = true } = options;
4012
+ const components = {};
4013
+ for (const [name, component] of Object.entries(manifest.components)) {
4014
+ var _component$events;
4015
+ const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => {
4016
+ var _definition$descripti;
4017
+ return [event, (_definition$descripti = definition.description) !== null && _definition$descripti !== void 0 ? _definition$descripti : compactType(definition.parameters, 0)];
4018
+ });
4019
+ components[name] = {
4020
+ ...component.description ? { description: component.description } : {},
4021
+ props: compactProps(component.props, propDescriptions),
4022
+ ...events.length > 0 ? { events: Object.fromEntries(events) } : {},
4023
+ ...component.slots ? { slots: component.slots } : {}
4024
+ };
4025
+ }
4026
+ const common = commonProps ? findCommonProps(Object.values(components).map((component) => component.props)) : void 0;
4027
+ if (common) {
4028
+ const commonKeys = Object.keys(common);
4029
+ for (const component of Object.values(components)) {
4030
+ if (!commonKeys.every((key) => component.props[key] === common[key])) continue;
4031
+ component.includesCommonProps = true;
4032
+ component.props = Object.fromEntries(Object.entries(component.props).filter(([key]) => !(key in common)));
4033
+ }
4034
+ }
4035
+ const functions = Object.fromEntries(Object.entries(manifest.functions).map(([name, fn]) => {
4036
+ const signature = fn.parameters.description;
4037
+ const hasSignature = typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2;
4038
+ const callers = functionCallers(fn);
4039
+ return [name, {
4040
+ ...fn.description ? { description: fn.description } : {},
4041
+ parameters: hasSignature ? signature : compactType(fn.parameters, 0),
4042
+ ...callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? { callers: callers.renderer ? "UI or agent" : "agent only" } : {}
4043
+ }];
4044
+ }));
4045
+ return {
4046
+ catalogId: manifest.catalogId,
4047
+ targets: manifest.targets,
4048
+ functions,
4049
+ ...common ? { commonProps: common } : {},
4050
+ components,
4051
+ surfaces: manifest.surfaces
4052
+ };
4053
+ }
4054
+
4055
+ //#endregion
4056
+ //#region src/generative-ui/schema-render.ts
4057
+ /** An own key (shared compiles to ES2017, which has no Object.hasOwn). */
4058
+ const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
4059
+ function isRecord(value) {
4060
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4061
+ }
4062
+ /** The props schema without the description of each prop. */
4063
+ function withoutPropDescriptions(schema) {
4064
+ if (!isRecord(schema.properties)) return schema;
4065
+ return {
4066
+ ...schema,
4067
+ properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => {
4068
+ if (!isRecord(value)) return [key, value];
4069
+ const { description: _description, ...rest } = value;
4070
+ return [key, rest];
4071
+ }))
4072
+ };
4073
+ }
4074
+ /** The short signature of a function: its built-in signature, or its schema made short. */
4075
+ function functionSignature(fn) {
4076
+ const signature = fn.parameters.description;
4077
+ return typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2 ? signature : compactType(fn.parameters, 0);
4078
+ }
4079
+ /**
4080
+ * A function name with its parameters: `pick{ id: string }`, `clearCart{}`
4081
+ * for no arguments, `setVolume(number)` for a parameter that is not an object.
4082
+ */
4083
+ function nameWithParameters(name, parameters) {
4084
+ if (parameters.startsWith("{")) return `${name}${parameters}`;
4085
+ if (parameters === "object") return `${name}{}`;
4086
+ return `${name}(${parameters})`;
4087
+ }
4088
+ /**
4089
+ * One component as a TypeScript-like signature line, with its events and
4090
+ * slots on the lines below:
4091
+ * `- Text(text?: string // The text): Shows text`.
4092
+ */
4093
+ function signatureLines(name, component, settings) {
4094
+ var _component$events, _component$slots;
4095
+ const lines = [`- ${name}(${Object.entries(compactProps(component.props, settings.propDescriptions)).map(([key, type]) => `${key}: ${type}`).join(", ")})${component.description ? `: ${oneLine(component.description)}` : ""}`];
4096
+ const events = Object.entries((_component$events = component.events) !== null && _component$events !== void 0 ? _component$events : {}).map(([event, definition]) => `${event}(${definition.description ? oneLine(definition.description) : compactType(definition.parameters, 0)})`);
4097
+ if (events.length > 0) lines.push(` events: ${events.join(", ")}`);
4098
+ const slots = Object.entries((_component$slots = component.slots) !== null && _component$slots !== void 0 ? _component$slots : {}).map(([slot, kind]) => `${slot} (${kind})`);
4099
+ if (slots.length > 0) lines.push(` slots: ${slots.join(", ")}`);
4100
+ return lines;
4101
+ }
4102
+ /** The whole schema as signature text: targets, functions, components, surfaces. */
4103
+ function signatureSchema(manifest, settings) {
4104
+ const targets = manifest.targets.map((t) => {
4105
+ const limit = t.components ? `; only ${t.components.join(", ")}` : "";
4106
+ return `- ${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
4107
+ });
4108
+ const functions = Object.entries(manifest.functions).map(([name, fn]) => {
4109
+ const callers = functionCallers(fn);
4110
+ const who = callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? callers.renderer ? " (UI or agent)" : " (agent only)" : "";
4111
+ return `- ${nameWithParameters(name, functionSignature(fn))}${who}${fn.description ? `: ${oneLine(fn.description)}` : ""}`;
4112
+ });
4113
+ const components = Object.entries(manifest.components).flatMap(([name, component]) => signatureLines(name, component, settings));
4114
+ const surfaces = Object.entries(manifest.surfaces).map(([id, s]) => {
4115
+ var _s$rejected;
4116
+ return `- ${id} (target ${s.target})${s.status ? ` status: ${s.status}` : ""}${s.dataModel ? ` user values: ${JSON.stringify(s.dataModel)}` : ""}${((_s$rejected = s.rejected) !== null && _s$rejected !== void 0 ? _s$rejected : []).map((r) => ` rejected: ${r}`).join("")}`;
4117
+ });
4118
+ return [
4119
+ `Catalog: ${manifest.catalogId}`,
4120
+ `Targets:\n${targets.join("\n") || "- none"}`,
4121
+ `Functions:\n${functions.join("\n") || "- none"}`,
4122
+ `Components:\n${components.join("\n") || "- none"}`,
4123
+ `Surfaces:\n${surfaces.join("\n") || "- none"}`
4124
+ ].join("\n\n");
4125
+ }
4126
+ /** A description on one line, so its lines cannot read as new entries. */
4127
+ function oneLine(text) {
4128
+ return text.replace(/\s*\n\s*/g, " ");
4129
+ }
4130
+ /** Values that would read as a type or a number once their quotes are gone. */
4131
+ const AMBIGUOUS_VALUE = /^(?:string|number|integer|boolean|true|false|null|object|array|unknown|any|-?\d[\d.]*)$/;
4132
+ /**
4133
+ * A compact type with bare enum values and tight unions:
4134
+ * `"sm" | "md" | "lg"` becomes `sm|md|lg`. A union keeps its quotes when it
4135
+ * also holds a type (`"sm" | number`) or a value that reads as a type or a
4136
+ * number (`"number" | "currency"`, `"1" | "2"`), and so do values that are
4137
+ * not plain words.
4138
+ */
4139
+ function bareType(type) {
4140
+ return type.replace(/"[A-Za-z0-9_#%.-]+"(?: \| "[A-Za-z0-9_#%.-]+")*(?! \|)/g, (union, offset, whole) => {
4141
+ if (whole.slice(offset - 2, offset) === "| ") return union;
4142
+ const values = union.split(" | ").map((v) => v.slice(1, -1));
4143
+ if (values.some((v) => AMBIGUOUS_VALUE.test(v))) return union;
4144
+ return values.join("|");
4145
+ }).replace(/ \| /g, "|");
4146
+ }
4147
+ /** A compact prop (`type // description`) as `name: type - description`. */
4148
+ function propLine(key, value) {
4149
+ const name = key.endsWith("?") ? key.slice(0, -1) : `${key}*`;
4150
+ const cut = value.indexOf(" // ");
4151
+ const type = bareType(cut < 0 ? value : value.slice(0, cut));
4152
+ const text = cut < 0 ? "" : value.slice(cut + 4).trim();
4153
+ return ` ${name}: ${type}${text ? ` - ${oneLine(text)}` : ""}`;
4154
+ }
4155
+ /**
4156
+ * The whole schema as plain lines: a header line per component and one
4157
+ * indented line per prop: events are `action` props and slots `componentId`
4158
+ * or `childList` props. Props are optional unless marked `*`, enum values
4159
+ * are bare, and the common props are listed once. It carries the same names, types and descriptions as
4160
+ * `compact`, in fewer tokens.
4161
+ */
4162
+ function linesSchema(manifest, settings) {
4163
+ const compact = buildCompactGenerativeUISchema(manifest, {
4164
+ propDescriptions: settings.propDescriptions,
4165
+ commonProps: settings.commonProps
4166
+ });
4167
+ const targets = compact.targets.map((t) => {
4168
+ const limit = t.components ? `, only ${t.components.join(", ")}` : "";
4169
+ return `${t.id} (${t.kind}${limit})${t.description ? `: ${oneLine(t.description)}` : ""}`;
4170
+ }).join("; ");
4171
+ const functions = Object.entries(compact.functions).map(([name, fn]) => `${nameWithParameters(name, fn.parameters)}${"callers" in fn ? ` (${fn.callers})` : ""}${fn.description ? `: ${oneLine(fn.description)}` : ""}`);
4172
+ const common = compact.commonProps ? Object.entries(compact.commonProps).map(([k, v]) => propLine(k, v)) : [];
4173
+ const components = Object.entries(compact.components).map(([name, c]) => {
4174
+ var _c$events;
4175
+ return {
4176
+ name,
4177
+ c,
4178
+ own: [...Object.entries(c.props).map(([k, v]) => propLine(k, v)), ...Object.entries((_c$events = c.events) !== null && _c$events !== void 0 ? _c$events : {}).map(([e, d]) => ` ${e}: action - ${oneLine(d)}`)]
4179
+ };
4180
+ }).flatMap(({ name, c, own }) => {
4181
+ var _c$slots;
4182
+ const lines = [`${name}${c.includesCommonProps ? " +common" : ""}${c.description ? `: ${oneLine(c.description)}` : ""}`, ...own];
4183
+ for (const [slot, kind] of Object.entries((_c$slots = c.slots) !== null && _c$slots !== void 0 ? _c$slots : {})) lines.push(` ${slot}: ${kind === "single" ? "componentId" : "childList"}`);
4184
+ return lines;
4185
+ });
4186
+ const surfaces = Object.keys(compact.surfaces).length ? JSON.stringify(compact.surfaces) : "none";
4187
+ return [
4188
+ `Catalog ${compact.catalogId}. Targets: ${targets || "none"}`,
4189
+ "Props are optional unless marked *. a|b|c is one of those strings, quoted when one reads as a type or a number. A component marked +common also takes every common prop. A prop of type action is an event prop: give it {\"event\":{...}} or {\"functionCall\":{...}}. A componentId prop takes one component id; a childList prop takes a list of ids or a template.",
4190
+ `Functions:\n${functions.join("\n")}`,
4191
+ ...common.length ? [`Common props:\n${common.join("\n")}`] : [],
4192
+ `Components:\n${components.join("\n")}`,
4193
+ `Surfaces: ${surfaces}`
4194
+ ].join("\n\n");
4195
+ }
4196
+ /**
4197
+ * The component schema of the markdown transport, as the text of its
4198
+ * context entry, in the notation of `settings`. `compact` is the schema that
4199
+ * ships (`buildCompactGenerativeUISchema`), `json-schema` the manifest parts
4200
+ * as JSON, `ts-signature` one line per component, `lines` one line per
4201
+ * prop with bare enums (the fewest tokens).
4202
+ *
4203
+ * @example
4204
+ * ```ts
4205
+ * const value = renderGenerativeUISchema(manifest, spec.schema.markdown);
4206
+ * ```
4207
+ */
4208
+ function renderGenerativeUISchema(manifest, settings) {
4209
+ switch (settings.notation) {
4210
+ case "compact": return JSON.stringify(buildCompactGenerativeUISchema(manifest, {
4211
+ propDescriptions: settings.propDescriptions,
4212
+ commonProps: settings.commonProps
4213
+ }));
4214
+ case "json-schema": {
4215
+ const components = Object.fromEntries(Object.entries(manifest.components).map(([name, c]) => [name, settings.propDescriptions ? c : {
4216
+ ...c,
4217
+ props: withoutPropDescriptions(c.props)
4218
+ }]));
4219
+ return JSON.stringify({
4220
+ catalogId: manifest.catalogId,
4221
+ targets: manifest.targets,
4222
+ functions: manifest.functions,
4223
+ components,
4224
+ surfaces: manifest.surfaces
4225
+ });
4226
+ }
4227
+ case "ts-signature": return signatureSchema(manifest, settings);
4228
+ case "lines": return linesSchema(manifest, settings);
4229
+ }
4230
+ }
4231
+ /**
4232
+ * The component list of the tool guide, one entry per component, in the
4233
+ * notation of `settings`. `json-schema` is the list that ships.
4234
+ */
4235
+ function renderGenerativeUIComponentList(components, settings) {
4236
+ return Object.entries(components).map(([name, c]) => {
4237
+ if (settings.notation === "ts-signature" || settings.notation === "lines") return signatureLines(name, c, settings).join("\n");
4238
+ const props = settings.notation === "compact" ? compactProps(c.props, settings.propDescriptions) : settings.propDescriptions ? c.props : withoutPropDescriptions(c.props);
4239
+ const lines = [`- **${name}**${c.description ? `: ${oneLine(c.description)}` : ""}`, ` props: ${JSON.stringify(props)}`];
4240
+ if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
4241
+ if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
4242
+ return lines.join("\n");
4243
+ }).join("\n");
4244
+ }
4245
+ /**
4246
+ * The manifest with replaced descriptions: `"Name"` replaces the
4247
+ * description of a component, `"Name.prop"` the description of one of its
4248
+ * props. Keys that name no component or prop are left out of the result
4249
+ * and listed in `unknown`. The manifest is not changed.
4250
+ */
4251
+ function applyDescriptionOverrides(manifest, overrides) {
4252
+ const components = structuredClone(manifest.components);
4253
+ const unknown = [];
4254
+ for (const [key, description] of Object.entries(overrides)) {
4255
+ const [name, prop, ...rest] = key.split(".");
4256
+ const component = hasOwn(components, name) ? components[name] : void 0;
4257
+ if (!component || rest.length > 0) {
4258
+ unknown.push(key);
4259
+ continue;
4260
+ }
4261
+ if (prop === void 0) {
4262
+ component.description = description;
4263
+ continue;
4264
+ }
4265
+ const properties = component.props.properties;
4266
+ const property = isRecord(properties) && hasOwn(properties, prop) ? properties[prop] : void 0;
4267
+ if (!isRecord(property)) {
4268
+ unknown.push(key);
4269
+ continue;
4270
+ }
4271
+ property.description = description;
4272
+ }
4273
+ return {
4274
+ manifest: {
4275
+ ...manifest,
4276
+ components
4277
+ },
4278
+ unknown
4279
+ };
4280
+ }
4281
+ /**
4282
+ * The components and props of `manifest` whose names do not appear in
4283
+ * `rendered`. A schema notation that leaves one out would hide part of the
4284
+ * catalog from the model.
4285
+ */
4286
+ function schemaCoverage(manifest, rendered) {
4287
+ const missing = [];
4288
+ for (const [name, component] of Object.entries(manifest.components)) {
4289
+ if (!rendered.includes(name)) missing.push(name);
4290
+ const properties = isRecord(component.props.properties) ? component.props.properties : {};
4291
+ for (const prop of Object.keys(properties)) if (!rendered.includes(prop)) missing.push(`${name}.${prop}`);
4292
+ }
4293
+ return { missing };
4294
+ }
4295
+
3689
4296
  //#endregion
3690
4297
  //#region src/generative-ui/prompt.ts
3691
4298
  const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
@@ -3700,19 +4307,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3700
4307
  * the `render_ui` rules, the targets, components, functions, and surfaces of
3701
4308
  * the manifest. It is in shared so that the inspector shows the same text.
3702
4309
  */
3703
- function buildGenerativeUIPrompt(manifest) {
4310
+ function buildGenerativeUIPrompt(manifest, spec = defaultGenerativeUIPromptSpec()) {
4311
+ var _spec$tool$operations;
3704
4312
  const targets = manifest.targets.map((t) => {
3705
4313
  const place = t.kind === "chat" ? "inside the chat transcript" : "a named area of the app";
3706
4314
  const limit = t.components ? `; only ${t.components.join(", ") || "no components"}` : "";
3707
4315
  const description = t.description ? `: ${t.description}` : "";
3708
4316
  return `- "${t.id}" (${place}${limit})${description}`;
3709
4317
  }).join("\n");
3710
- const components = Object.entries(manifest.components).map(([name, c]) => {
3711
- const lines = [`- **${name}**${c.description ? `: ${c.description}` : ""}`, ` props: ${JSON.stringify(c.props)}`];
3712
- if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
3713
- if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
3714
- return lines.join("\n");
3715
- }).join("\n");
4318
+ const components = renderGenerativeUIComponentList(manifest.components, spec.schema.tool);
3716
4319
  const functions = Object.entries(manifest.functions).map(([name, f]) => {
3717
4320
  const signature = f.parameters.description;
3718
4321
  const args = typeof signature === "string" && signature.startsWith("{") && Object.keys(f.parameters).length === 2 ? signature : JSON.stringify(f.parameters);
@@ -3731,38 +4334,15 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
3731
4334
  var _s$rejected$length, _s$rejected2;
3732
4335
  return s.dataModel !== void 0 || ((_s$rejected$length = (_s$rejected2 = s.rejected) === null || _s$rejected2 === void 0 ? void 0 : _s$rejected2.length) !== null && _s$rejected$length !== void 0 ? _s$rejected$length : 0) > 0;
3733
4336
  }) ? "User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\n" : "";
3734
- const { functions: hasFunctions, events, templates, checks } = generativeUIGuideFeatures(manifest);
3735
- const agentCalls = hasFunctions && GENERATIVE_UI_AGENT_FUNCTION_CALLS;
3736
- const operations = [
3737
- "{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
3738
- "{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
3739
- "{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
3740
- "{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
3741
- ...agentCalls ? ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."] : []
3742
- ];
3743
- const rules = [
3744
- "Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
3745
- "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
3746
- "Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
3747
- "Updating a component replaces all of its props, so resend every prop.",
3748
- "Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
3749
- ...events ? [hasFunctions ? "Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below." : "Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."] : [],
3750
- "To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
3751
- "Never use a surfaceId again, also after deleteSurface.",
3752
- "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
3753
- "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
3754
- "For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
3755
- ...checks ? ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."] : [],
3756
- ...templates ? ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."] : [],
3757
- ...agentCalls ? ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."] : []
3758
- ];
4337
+ const features = generativeUIPromptFeatures(generativeUIGuideFeatures(manifest));
4338
+ const { intro, whenToShow } = spec.tool;
4339
+ const operations = selectPromptItems((_spec$tool$operations = spec.tool.operations) !== null && _spec$tool$operations !== void 0 ? _spec$tool$operations : [], features);
4340
+ const rules = selectPromptItems(spec.tool.rules, features);
3759
4341
  return [
3760
4342
  `## Generative UI
3761
- Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).
3762
-
3763
- ${GENERATIVE_UI_WHEN_TO_SHOW}
4343
+ ${intro}
3764
4344
 
3765
- Every operation has "version":"v1.0" and exactly one of:
4345
+ ${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"1.0" and exactly one of:
3766
4346
  ${operations.map((op) => `- ${op}`).join("\n")}
3767
4347
 
3768
4348
  Rules:
@@ -3870,11 +4450,14 @@ exports.GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE = GENERATIVE_UI_FUNCTION_CALL_
3870
4450
  exports.GENERATIVE_UI_MARKDOWN_GUIDELINES = GENERATIVE_UI_MARKDOWN_GUIDELINES;
3871
4451
  exports.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION;
3872
4452
  exports.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION = GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION;
4453
+ exports.GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW;
3873
4454
  exports.GENERATIVE_UI_MAX_REJECTION_LENGTH = GENERATIVE_UI_MAX_REJECTION_LENGTH;
3874
4455
  exports.GENERATIVE_UI_MAX_SUMMARY_REJECTIONS = GENERATIVE_UI_MAX_SUMMARY_REJECTIONS;
3875
4456
  exports.GENERATIVE_UI_MAX_TARGET_COMPONENTS = GENERATIVE_UI_MAX_TARGET_COMPONENTS;
3876
4457
  exports.GENERATIVE_UI_RENDER_TOOL = GENERATIVE_UI_RENDER_TOOL;
3877
4458
  exports.GENERATIVE_UI_ROOT_ID = GENERATIVE_UI_ROOT_ID;
4459
+ exports.GENERATIVE_UI_WHEN_TO_SHOW = GENERATIVE_UI_WHEN_TO_SHOW;
4460
+ exports.GUIDE_COMPONENTS = GUIDE_COMPONENTS;
3878
4461
  exports.MODEL_HOST_CLASSES = MODEL_HOST_CLASSES;
3879
4462
  exports.MissingPublicApiKeyError = MissingPublicApiKeyError;
3880
4463
  exports.RUNTIME_MODE_INTELLIGENCE = RUNTIME_MODE_INTELLIGENCE;
@@ -3893,6 +4476,8 @@ exports.UNSAMPLED_RATE = UNSAMPLED_RATE;
3893
4476
  exports.UpgradeRequiredError = UpgradeRequiredError;
3894
4477
  exports.actionParametersToJsonSchema = actionParametersToJsonSchema;
3895
4478
  exports.applyChildRefMarks = applyChildRefMarks;
4479
+ exports.applyDescriptionOverrides = applyDescriptionOverrides;
4480
+ exports.buildCompactGenerativeUISchema = buildCompactGenerativeUISchema;
3896
4481
  exports.buildGenerativeUIMarkdownGuidelines = buildGenerativeUIMarkdownGuidelines;
3897
4482
  exports.buildGenerativeUIPrompt = buildGenerativeUIPrompt;
3898
4483
  exports.callerProblem = callerProblem;
@@ -3909,6 +4494,7 @@ exports.createLicenseContextValue = createLicenseContextValue;
3909
4494
  exports.createRowKeyStore = createRowKeyStore;
3910
4495
  exports.createRunEventFinalizer = createRunEventFinalizer;
3911
4496
  exports.dataToUUID = dataToUUID;
4497
+ exports.defaultGenerativeUIPromptSpec = defaultGenerativeUIPromptSpec;
3912
4498
  exports.ensureStructuredError = ensureStructuredError;
3913
4499
  exports.envelopeToManifest = envelopeToManifest;
3914
4500
  exports.exceedsMaxSize = exceedsMaxSize;
@@ -3921,6 +4507,7 @@ exports.functionCallers = functionCallers;
3921
4507
  exports.generateVideoThumbnail = generateVideoThumbnail;
3922
4508
  exports.generativeUIFunctionCallMessageId = generativeUIFunctionCallMessageId;
3923
4509
  exports.generativeUIGuideFeatures = generativeUIGuideFeatures;
4510
+ exports.generativeUIPromptFeatures = generativeUIPromptFeatures;
3924
4511
  exports.generativeUISurfaceMessageId = generativeUISurfaceMessageId;
3925
4512
  exports.getDocumentIcon = getDocumentIcon;
3926
4513
  exports.getModalityFromMimeType = getModalityFromMimeType;
@@ -3964,11 +4551,15 @@ exports.randomUUID = randomUUID;
3964
4551
  exports.readBody = readBody;
3965
4552
  exports.readCopilotKitUIEnvelope = readCopilotKitUIEnvelope;
3966
4553
  exports.readFileAsBase64 = readFileAsBase64;
4554
+ exports.renderGenerativeUIComponentList = renderGenerativeUIComponentList;
4555
+ exports.renderGenerativeUISchema = renderGenerativeUISchema;
3967
4556
  exports.resolveDebugConfig = resolveDebugConfig;
3968
4557
  exports.resolveRowRenderKeys = resolveRowRenderKeys;
3969
4558
  exports.resolveRowRenderKeysById = resolveRowRenderKeysById;
3970
4559
  exports.safeParseToolArgs = safeParseToolArgs;
4560
+ exports.schemaCoverage = schemaCoverage;
3971
4561
  exports.schemaToJsonSchema = schemaToJsonSchema;
4562
+ exports.selectPromptItems = selectPromptItems;
3972
4563
  exports.shouldEnableInspector = shouldEnableInspector;
3973
4564
  exports.stripIntelligenceRoutingFields = stripIntelligenceRoutingFields;
3974
4565
  exports.styledConsole = styledConsole;