paseo-plugin-genui 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-plugin-genui",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Paseo plugin: agents answer with charts, diagrams, maps, plans and forms rendered inline in the chat.",
5
5
  "keywords": [
6
6
  "paseo",
@@ -703,6 +703,8 @@ export const METHODS = {
703
703
  "toLowerCase",
704
704
  "startsWith",
705
705
  "endsWith",
706
+ "replace",
707
+ "replaceAll",
706
708
  ],
707
709
  number: ["toFixed"],
708
710
  } as const;
@@ -519,6 +519,10 @@ const Interpreter = defineClass(
519
519
  for (const child of item) visit(child);
520
520
  } else if (isNode(item)) {
521
521
  out.push(item);
522
+ } else if (isAction(item) && item.type !== "set") {
523
+ // A bare action where a component belongs: render it as the Button the agent meant.
524
+ const text = item.type === "openUrl" ? `Open ${new URL(item.url).host}` : item.type === "copy" ? "Copy" : item.text;
525
+ out.push(this.node("Button", `${key}.${out.length}`, { label: text, action: [item], variant: null, icon: null }, pos));
522
526
  } else {
523
527
  throw new RuntimeError(pos, `${label} must be components or text, got ${describe(item)}`);
524
528
  }
@@ -692,6 +696,11 @@ const Interpreter = defineClass(
692
696
  return receiver.toUpperCase();
693
697
  case "toLowerCase":
694
698
  return receiver.toLowerCase();
699
+ // A function replacement keeps `$&` and similar patterns literal.
700
+ case "replace":
701
+ return checkString(receiver.replace(textAt(0), () => textAt(1)), call.pos);
702
+ case "replaceAll":
703
+ return checkString(receiver.replaceAll(textAt(0), () => textAt(1)), call.pos);
695
704
  }
696
705
  } else if (typeof receiver === "number" && call.name === "toFixed") {
697
706
  const digits = args.length > 0 ? this.digits(args[0], call.args[0].pos, label) : 0;
@@ -33,7 +33,7 @@ const METHOD_ARITY: ReadonlyMap<string, Arity> = new Map(
33
33
  map: [1, 1], filter: [1, 1], find: [1, 1], some: [1, 1], every: [1, 1],
34
34
  join: [0, 1], slice: [0, 2], includes: [1, 1], indexOf: [1, 1], concat: [1, Infinity], sort: [0, 1],
35
35
  split: [1, 1], trim: [0, 0], toUpperCase: [0, 0], toLowerCase: [0, 0],
36
- startsWith: [1, 1], endsWith: [1, 1], toFixed: [0, 1],
36
+ startsWith: [1, 1], endsWith: [1, 1], replace: [2, 2], replaceAll: [2, 2], toFixed: [0, 1],
37
37
  } satisfies Record<MethodName, Arity>),
38
38
  );
39
39
 
@@ -60,6 +60,27 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
60
60
  expect(roots.map((root) => root.props.text)).toEqual(["x,z,y", "1,9,10", "x,y"]);
61
61
  });
62
62
 
63
+ it("renders a bare Send, OpenUrl or Copy among children as a Button", () => {
64
+ const compiled = compile('Card("x", [Text("a"), OpenUrl("https://docs.google.com/x"), Send("Go"), Copy("id")])');
65
+ expect(compiled.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
66
+ const { roots, diagnostics } = evaluate(compiled.program!, initialState(compiled.program!));
67
+ expect(diagnostics).toEqual([]);
68
+ const buttons = (roots[0]!.props.children as { type: string; props: { label: string } }[]).filter((c) => c.type === "Button");
69
+ expect(buttons.map((b) => b.props.label)).toEqual(["Open docs.google.com", "Go", "Copy"]);
70
+ });
71
+
72
+ it("supports .replace() and .replaceAll() on text", () => {
73
+ const compiled = compile(
74
+ [
75
+ "Text(\"katalon-studio/a-b-b\".replace(\"katalon-studio/\", \"\").replaceAll(\"-\", \" \"))",
76
+ "Text(\"a.b\".replace(\".\", \"$&!\"))",
77
+ ].join("\n"),
78
+ );
79
+ expect(compiled.diagnostics).toEqual([]);
80
+ const { roots } = evaluate(compiled.program!, initialState(compiled.program!));
81
+ expect(roots.map((root) => root.props.text)).toEqual(["a b b", "a$&!b"]);
82
+ });
83
+
63
84
  it("covers all 86 catalog components in the gallery and compiles + evaluates every gallery spec", async () => {
64
85
  const files = await listGallery();
65
86
  expect(files.length).toBeGreaterThanOrEqual(170);
@@ -24,7 +24,7 @@ export const REFERENCE_MORE_GROUPS: readonly ComponentGroup[] = ["Inputs", "Widg
24
24
 
25
25
  export const UI_REFERENCE = `# Inline UI reference
26
26
  The \`\`\`ui language used by the Inline UI section below.
27
- Syntax: one statement per line. \`$x = 8\` is state inputs bind to; \`name = expr\` names a value and \`f = (a, b) => expr\` a function; each bare expression renders. JS expressions incl. ** ?: ?? \`\${x}\` [lists] {objects} x.y map/filter/find/sort/concat/join/length, plus round(x, d), fmt(x, d), sum, min, max, abs, entries, Load(path). Named args go last: Slider($n, 0, 10, label: "N").
27
+ Syntax: one statement per line. \`$x = 8\` is state inputs bind to; \`name = expr\` names a value and \`f = (a, b) => expr\` a function; each bare expression renders. JS expressions incl. ** ?: ?? \`\${x}\` [lists] {objects} x.y map/filter/find/sort/concat/join/replace/length, plus round(x, d), fmt(x, d), sum, min, max, abs, entries, Load(path). Named args go last: Slider($n, 0, 10, label: "N").
28
28
  Components (? optional; tone: neutral|good|warn|bad|info if meaningful; more in the next section):
29
29
  ${componentLines(REFERENCE_GROUPS)}
30
30
  Actions: ${actionList}; a list runs in order; Send posts as the user.