paseo-plugin-genui 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { Icon as PaseoIcon, Modal } from "@getpaseo/plugin/client/react-native";
2
2
  import { ImageLightbox } from "./image-lightbox";
3
3
  import { ExternalLink } from "@getpaseo/plugin/client/ui";
4
4
  import React, { useContext, useEffect, useState } from "react";
5
- import { Image as RNImage, Pressable, StyleSheet, Text as RNText, View } from "react-native";
5
+ import { Image as RNImage, Platform, Pressable, StyleSheet, Text as RNText, View } from "react-native";
6
6
  import { keyValuePairs } from "../../shared/logic/content-model";
7
7
  import { parseListRows } from "../../shared/logic/explain-logic";
8
8
  import { resolveIconName } from "../../shared/logic/icons";
@@ -275,11 +275,12 @@ export function File({ props }: { props: Props }) {
275
275
  const line = finiteNumber(props.line);
276
276
  const label = line !== null ? `${filePath}:${Math.round(line)}` : filePath;
277
277
 
278
- return (
278
+ const onWeb = Platform.OS === "web";
279
+ const chip = (
279
280
  <Pressable
280
281
  accessibilityRole="button"
281
282
  onPress={() => {
282
- if (openFile) void openFile(filePath, line ?? undefined);
283
+ if (!onWeb && openFile) void openFile(filePath, line ?? undefined);
283
284
  }}
284
285
  style={{
285
286
  alignSelf: "flex-start",
@@ -300,6 +301,23 @@ export function File({ props }: { props: Props }) {
300
301
  </RNText>
301
302
  </Pressable>
302
303
  );
304
+ if (!onWeb) return chip;
305
+
306
+ // Paseo renders chat file links as `<a style="display: contents">`. Plugins such as
307
+ // wiki-viewer catch clicks on those and replay the click when they decline, so the
308
+ // anchor's own handler is the fallback that opens a Paseo file tab.
309
+ return React.createElement(
310
+ "a",
311
+ {
312
+ href: label,
313
+ style: { display: "contents" },
314
+ onClick: (event: { preventDefault(): void }) => {
315
+ event.preventDefault();
316
+ if (openFile) void openFile(filePath, line ?? undefined);
317
+ },
318
+ },
319
+ chip,
320
+ );
303
321
  }
304
322
 
305
323
  export function Entity({ props }: { props: Props }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-plugin-genui",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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",
@@ -691,6 +691,8 @@ export const METHODS = {
691
691
  "slice",
692
692
  "includes",
693
693
  "indexOf",
694
+ "concat",
695
+ "sort",
694
696
  ],
695
697
  string: [
696
698
  "includes",
@@ -287,7 +287,7 @@ const Interpreter = defineClass(
287
287
  case "arrow":
288
288
  throw new RuntimeError(
289
289
  expr.pos,
290
- "arrow functions can only be declared as a named function (`share = p => ...`) or passed to map, filter, find, some or every",
290
+ "arrow functions can only be declared as a named function (`share = p => ...`) or passed to map, filter, find, some, every or sort",
291
291
  );
292
292
  }
293
293
  },
@@ -653,6 +653,7 @@ const Interpreter = defineClass(
653
653
  method(call: Extract<Expr, { type: "method" }>, scope: Scope | null): Value {
654
654
  const receiver = this.expr(call.object, scope);
655
655
  if (isList(receiver) && LAMBDA_METHODS.has(call.name)) return this.lambdaMethod(receiver, call, scope);
656
+ if (isList(receiver) && call.name === "sort") return this.sort(receiver, call, scope);
656
657
  const args = call.args.map((arg) => this.expr(arg, scope));
657
658
  const label = `.${call.name}()`;
658
659
  const textAt = (index: number) => this.text(args[index], call.args[index].pos, label);
@@ -670,6 +671,8 @@ const Interpreter = defineClass(
670
671
  return receiver.includes(args[0]);
671
672
  case "indexOf":
672
673
  return receiver.indexOf(args[0]);
674
+ case "concat":
675
+ return checkLength(receiver.concat(...args), call.pos);
673
676
  }
674
677
  } else if (typeof receiver === "string") {
675
678
  switch (call.name) {
@@ -697,6 +700,25 @@ const Interpreter = defineClass(
697
700
  throw new RuntimeError(call.pos, `\`${label}\` is not available on ${describe(receiver)}`);
698
701
  },
699
702
 
703
+ /** A sorted copy; without a comparator, numbers sort numerically and anything else as text. */
704
+ sort(list: readonly Value[], call: Extract<Expr, { type: "method" }>, scope: Scope | null): Value {
705
+ checkLength(list, call.pos);
706
+ const fn = call.args[0];
707
+ if (fn === undefined) {
708
+ return [...list].sort((a, b) =>
709
+ typeof a === "number" && typeof b === "number" ? a - b : toText(a, call.pos).localeCompare(toText(b, call.pos)),
710
+ );
711
+ }
712
+ if (fn.type !== "arrow") throw new RuntimeError(call.pos, "`.sort()` takes a function, as in `(a, b) => a.price - b.price`");
713
+ const [aName, bName] = fn.params;
714
+ return [...list].sort((a, b) => {
715
+ let inner = scope;
716
+ if (aName !== undefined) inner = { name: aName, value: a, parent: inner };
717
+ if (bName !== undefined) inner = { name: bName, value: b, parent: inner };
718
+ return this.number(this.expr(fn.body, inner), fn.body.pos, ".sort()");
719
+ });
720
+ },
721
+
700
722
  lambdaMethod(list: readonly Value[], call: Extract<Expr, { type: "method" }>, scope: Scope | null): Value {
701
723
  checkLength(list, call.pos);
702
724
  const fn = call.args[0];
@@ -31,7 +31,7 @@ type Arity = readonly [min: number, max: number];
31
31
  const METHOD_ARITY: ReadonlyMap<string, Arity> = new Map(
32
32
  Object.entries({
33
33
  map: [1, 1], filter: [1, 1], find: [1, 1], some: [1, 1], every: [1, 1],
34
- join: [0, 1], slice: [0, 2], includes: [1, 1], indexOf: [1, 1],
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
36
  startsWith: [1, 1], endsWith: [1, 1], toFixed: [0, 1],
37
37
  } satisfies Record<MethodName, Arity>),
@@ -46,7 +46,7 @@ const FUNCTION_ARITY: ReadonlyMap<string, Arity> = new Map(
46
46
 
47
47
  const ACTION_LIST = [...ACTION_SPECS].map(([name, spec]) => signature(name, spec)).join(", ");
48
48
  const ARROW_ONLY =
49
- "arrow functions can only be declared as a named function (`share = p => ...`) or passed to map, filter, find, some or every";
49
+ "arrow functions can only be declared as a named function (`share = p => ...`) or passed to map, filter, find, some, every or sort";
50
50
 
51
51
  /** The type of a value, as named in diagnostics. */
52
52
  export type Kind = "null" | "boolean" | "number" | "string" | "list" | "object" | "node" | "action" | "binding";
@@ -432,13 +432,16 @@ const Validator = defineClass(
432
432
  this.diagnostics.report(expr.pos, `\`.${expr.name}()\` takes ${arityText(arity)}`);
433
433
  }
434
434
  const [first, ...rest] = expr.args;
435
- if (LAMBDA_METHODS.has(expr.name) && first !== undefined) {
435
+ const sort = expr.name === "sort";
436
+ if ((LAMBDA_METHODS.has(expr.name) || sort) && first !== undefined) {
436
437
  if (first.type !== "arrow") {
437
- this.diagnostics.report(first.pos, `\`.${expr.name}()\` takes a function, as in \`x => x.price\``);
438
+ const example = sort ? "(a, b) => a.price - b.price" : "x => x.price";
439
+ this.diagnostics.report(first.pos, `\`.${expr.name}()\` takes a function, as in \`${example}\``);
438
440
  this.check(first, params, refs);
439
441
  } else {
440
442
  if (first.params.length > 2) {
441
- this.diagnostics.report(first.pos, `\`.${expr.name}()\` passes (item, index); use at most 2 parameters`);
443
+ const passes = sort ? "(a, b)" : "(item, index)";
444
+ this.diagnostics.report(first.pos, `\`.${expr.name}()\` passes ${passes}; use at most 2 parameters`);
442
445
  }
443
446
  this.check(first.body, [...params, ...first.params], refs);
444
447
  }
@@ -45,6 +45,21 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
45
45
  }
46
46
  });
47
47
 
48
+ it("supports .concat() and .sort() on lists", () => {
49
+ const compiled = compile(
50
+ [
51
+ "a = [{n: \"x\", v: 3}, {n: \"y\", v: 1}]",
52
+ "all = a.concat([{n: \"z\", v: 2}])",
53
+ "Text(all.sort((p, q) => q.v - p.v).map(p => p.n).join(\",\"))",
54
+ "Text([10, 9, 1].sort().join(\",\"))",
55
+ "Text(a.map(p => p.n).join(\",\"))",
56
+ ].join("\n"),
57
+ );
58
+ expect(compiled.diagnostics).toEqual([]);
59
+ const { roots } = evaluate(compiled.program!, initialState(compiled.program!));
60
+ expect(roots.map((root) => root.props.text)).toEqual(["x,z,y", "1,9,10", "x,y"]);
61
+ });
62
+
48
63
  it("covers all 86 catalog components in the gallery and compiles + evaluates every gallery spec", async () => {
49
64
  const files = await listGallery();
50
65
  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/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/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.