@dudousxd/nestjs-agent-core 0.42.0 → 0.43.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.
@@ -34,6 +34,7 @@ __export(genui_exports, {
34
34
  defineCatalog: () => defineCatalog,
35
35
  defineComponent: () => defineComponent,
36
36
  fillTemplate: () => fillTemplate,
37
+ flatComponents: () => flatComponents,
37
38
  formatIssues: () => formatIssues,
38
39
  genuiTools: () => genuiTools,
39
40
  getPath: () => getPath,
@@ -416,6 +417,10 @@ function defineComponent(definition) {
416
417
  return definition;
417
418
  }
418
419
  __name(defineComponent, "defineComponent");
420
+ function flatComponents(catalog) {
421
+ return catalog.modelComponents().filter((component) => component.children !== true);
422
+ }
423
+ __name(flatComponents, "flatComponents");
419
424
  function defineCatalog(components, options = {}) {
420
425
  const byName = /* @__PURE__ */ new Map();
421
426
  for (const component of components) {
@@ -718,32 +723,31 @@ function componentToText(catalog, component, props) {
718
723
  const root = props.root;
719
724
  return root === void 0 ? "" : treeToText(catalog, root);
720
725
  }
721
- const fallback = catalog.get(component)?.fallbackText;
726
+ return ownText(catalog, component, props) ?? "";
727
+ }
728
+ __name(componentToText, "componentToText");
729
+ function ownText(catalog, component, props) {
730
+ const definition = catalog.get(component);
731
+ const fallback = definition?.fallbackText;
732
+ let failed = false;
722
733
  if (fallback !== void 0) {
723
734
  try {
724
735
  const text = fallback(props);
725
736
  if (typeof text === "string" && text.trim().length > 0) return text;
726
737
  } catch {
738
+ failed = true;
727
739
  }
728
740
  }
741
+ if (definition?.children === true && !failed) return void 0;
729
742
  return jsonBlock(props);
730
743
  }
731
- __name(componentToText, "componentToText");
744
+ __name(ownText, "ownText");
732
745
  function treeToText(catalog, root) {
733
746
  const out = [];
734
747
  const visit = /* @__PURE__ */ __name((node, depth) => {
735
748
  if (depth > 32) return;
736
- const definition = catalog.get(node.type);
737
- if (definition?.fallbackText !== void 0) {
738
- try {
739
- const text = definition.fallbackText(node.props);
740
- out.push(typeof text === "string" && text.trim().length > 0 ? text : jsonBlock(node.props));
741
- } catch {
742
- out.push(jsonBlock(node.props));
743
- }
744
- } else if (definition?.children !== true) {
745
- out.push(jsonBlock(node.props));
746
- }
749
+ const text = ownText(catalog, node.type, node.props);
750
+ if (text !== void 0) out.push(text);
747
751
  for (const child of node.children ?? []) visit(child, depth + 1);
748
752
  }, "visit");
749
753
  visit(root, 0);
@@ -768,7 +772,8 @@ function catalogToModelText(catalog, options = {}) {
768
772
  } else {
769
773
  lines.push("Components you can show (one tool each):");
770
774
  }
771
- for (const component of catalog.modelComponents()) {
775
+ const components = mode === "tree" ? catalog.modelComponents() : flatComponents(catalog);
776
+ for (const component of components) {
772
777
  const schema = toJsonSchema(component.props);
773
778
  const head = mode === "per-component" ? `- ${component.name} (tool \`${toolNameFor(component.name, options.namePrefix)}\`)` : `- ${component.name}`;
774
779
  lines.push(`${head}: ${component.description}`);
@@ -925,7 +930,7 @@ var GENUI_SHOW_TOOL = "ui__show";
925
930
  function genuiTools(catalog, options = {}) {
926
931
  const tools = options.mode === "tree" ? [
927
932
  treeTool(catalog, options)
928
- ] : catalog.modelComponents().map((component) => componentTool(catalog, component, options));
933
+ ] : flatComponents(catalog).map((component) => componentTool(catalog, component, options));
929
934
  if (options.showTool !== void 0 && options.showTool !== false) {
930
935
  tools.push(showTool(catalog, options));
931
936
  }
@@ -979,7 +984,7 @@ function componentTool(catalog, component, options) {
979
984
  const handler = {
980
985
  async execute(input, ctx) {
981
986
  const resolved = await catalogFor(catalog, options, scopeOf(ctx));
982
- const definition = modelComponent(resolved, component.name);
987
+ const definition = flatComponent(resolved, component.name);
983
988
  if (definition === void 0) {
984
989
  throw new Error(`component "${component.name}" is not available here`);
985
990
  }
@@ -992,7 +997,7 @@ function componentTool(catalog, component, options) {
992
997
  };
993
998
  handler.describe = async (scope) => {
994
999
  const resolved = negotiateCatalog(await catalogFor(catalog, options, scopeOf(scope)), scope.uiCapabilities);
995
- const definition = modelComponent(resolved, component.name);
1000
+ const definition = flatComponent(resolved, component.name);
996
1001
  if (definition === void 0) {
997
1002
  return {
998
1003
  available: false,
@@ -1083,7 +1088,7 @@ function showToolJsonSchema(catalog) {
1083
1088
  properties: {
1084
1089
  component: {
1085
1090
  type: "string",
1086
- enum: catalog.modelComponents().map((component) => component.name),
1091
+ enum: flatComponents(catalog).map((component) => component.name),
1087
1092
  description: "Component name from the catalog"
1088
1093
  },
1089
1094
  props: {
@@ -1124,9 +1129,9 @@ async function validateShow(catalog, input, phase = "input") {
1124
1129
  ]
1125
1130
  };
1126
1131
  }
1127
- const definition = modelComponent(catalog, component);
1132
+ const definition = flatComponent(catalog, component);
1128
1133
  if (definition === void 0) {
1129
- const allowed = catalog.modelComponents().map((each) => each.name).join(", ");
1134
+ const allowed = flatComponents(catalog).map((each) => each.name).join(", ");
1130
1135
  return {
1131
1136
  ok: false,
1132
1137
  issues: [
@@ -1189,7 +1194,7 @@ function showTool(catalog, options) {
1189
1194
  handler.describe = async (scope) => {
1190
1195
  const resolved = negotiateCatalog(await catalogFor(catalog, options, scopeOf(scope)), scope.uiCapabilities);
1191
1196
  return {
1192
- available: resolved.modelComponents().length > 0,
1197
+ available: flatComponents(resolved).length > 0,
1193
1198
  description: describeFor(resolved),
1194
1199
  inputSchema: permissiveSchema(showToolJsonSchema(resolved))
1195
1200
  };
@@ -1217,11 +1222,11 @@ function showTool(catalog, options) {
1217
1222
  };
1218
1223
  }
1219
1224
  __name(showTool, "showTool");
1220
- function modelComponent(catalog, name) {
1225
+ function flatComponent(catalog, name) {
1221
1226
  const definition = catalog.get(name);
1222
- return definition === void 0 || definition.internal === true ? void 0 : definition;
1227
+ return definition === void 0 || definition.internal === true || definition.children === true ? void 0 : definition;
1223
1228
  }
1224
- __name(modelComponent, "modelComponent");
1229
+ __name(flatComponent, "flatComponent");
1225
1230
  async function push(ctx, component, props, version) {
1226
1231
  const { id } = await ctx.emitUi(component, props, version !== void 0 ? {
1227
1232
  version
@@ -1466,18 +1471,49 @@ var Chart = defineComponent({
1466
1471
  "series",
1467
1472
  "data"
1468
1473
  ]),
1469
- fallbackText: /* @__PURE__ */ __name((props) => {
1470
- const series = props.series ?? [];
1471
- const data = props.data ?? [];
1472
- const first = series[0]?.key ?? "";
1473
- const max = Math.max(0, ...data.map((point) => Math.abs(Number(point[first]) || 0)));
1474
- const unit = props.unit ? ` ${s(props.unit)}` : "";
1475
- const lines = data.slice(0, 20).map((point) => `${s(point[props.xKey]).slice(0, 18).padEnd(18)} ${bar(Number(point[first]) || 0, max)} ${s(point[first])}${unit}`);
1476
- return `${heading(props)}\`\`\`
1474
+ fallbackText: /* @__PURE__ */ __name((props) => chartText(props), "fallbackText")
1475
+ });
1476
+ function chartText(props) {
1477
+ const series = (props.series ?? []).filter((each) => typeof each?.key === "string");
1478
+ const data = props.data ?? [];
1479
+ const unit = props.unit ? ` ${s(props.unit)}` : "";
1480
+ const labelOf = /* @__PURE__ */ __name((each) => s(each.label) || each.key, "labelOf");
1481
+ if (props.type === "line") {
1482
+ const columns = [
1483
+ {
1484
+ key: s(props.xKey),
1485
+ label: s(props.xKey)
1486
+ },
1487
+ ...series.map((each) => ({
1488
+ key: each.key,
1489
+ label: `${labelOf(each)}${unit}`
1490
+ }))
1491
+ ];
1492
+ return `${heading(props)}${textTable(columns, data, 20)}`;
1493
+ }
1494
+ const max = Math.max(0, ...data.flatMap((point) => series.map((each) => Math.abs(Number(point[each.key]) || 0))));
1495
+ const shown = data.slice(0, 20);
1496
+ const lines = [];
1497
+ if (series.length <= 1) {
1498
+ const key = series[0]?.key ?? "";
1499
+ for (const point of shown) {
1500
+ lines.push(`${s(point[props.xKey]).slice(0, 18).padEnd(18)} ${bar(Number(point[key]) || 0, max)} ${s(point[key])}${unit}`);
1501
+ }
1502
+ } else {
1503
+ const width = Math.min(18, Math.max(...series.map((each) => labelOf(each).length)));
1504
+ for (const point of shown) {
1505
+ lines.push(s(point[props.xKey]).slice(0, 18));
1506
+ for (const each of series) {
1507
+ lines.push(` ${labelOf(each).slice(0, width).padEnd(width)} ${bar(Number(point[each.key]) || 0, max)} ${s(point[each.key])}${unit}`);
1508
+ }
1509
+ }
1510
+ }
1511
+ if (data.length > shown.length) lines.push(`\u2026 ${data.length - shown.length} more points`);
1512
+ return `${heading(props)}\`\`\`
1477
1513
  ${lines.join("\n")}
1478
1514
  \`\`\``;
1479
- }, "fallbackText")
1480
- });
1515
+ }
1516
+ __name(chartText, "chartText");
1481
1517
  var KpiCards = defineComponent({
1482
1518
  name: "KpiCards",
1483
1519
  title: "KPI cards",
@@ -1873,6 +1909,7 @@ __name(canonicalJson, "canonicalJson");
1873
1909
  defineCatalog,
1874
1910
  defineComponent,
1875
1911
  fillTemplate,
1912
+ flatComponents,
1876
1913
  formatIssues,
1877
1914
  genuiTools,
1878
1915
  getPath,