paseo-plugin-genui 0.3.1 → 0.3.2
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 +1 -1
- package/server/render-tool.ts +7 -2
- package/shared/actions-only.test.ts +19 -10
- package/shared/fallback.ts +2 -5
package/package.json
CHANGED
package/server/render-tool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineAgentTool } from "@getpaseo/plugin/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { specProblems } from "../shared/fallback";
|
|
3
|
+
import { actionsOnly, specProblems } from "../shared/fallback";
|
|
4
4
|
import { GENUI_BLOCK_KIND, GENUI_TEXT_KIND } from "../shared/segment";
|
|
5
5
|
import { loadAgentFile } from "./data-source";
|
|
6
6
|
|
|
@@ -17,7 +17,12 @@ export const renderUiTool = defineAgentTool({
|
|
|
17
17
|
spec: z.string().describe("The ui spec, without the ``` fence"),
|
|
18
18
|
}),
|
|
19
19
|
async execute({ answer, spec }, { agent, paseo }) {
|
|
20
|
-
const
|
|
20
|
+
const checked = await specProblems(spec, (request) => loadAgentFile(paseo, agent.id, request.path, request));
|
|
21
|
+
// Only here: prose before a render_ui call is often lost in the agent's reasoning, while a ```ui block's prose is in the reply.
|
|
22
|
+
const problems =
|
|
23
|
+
checked.roots !== null && actionsOnly(checked.roots)
|
|
24
|
+
? [...checked.problems, "The card has only buttons. Put what each option does, and the findings behind the choice, in the card itself (Text, Callout, Table, Steps)."]
|
|
25
|
+
: checked.problems;
|
|
21
26
|
if (problems.length > 0) {
|
|
22
27
|
return {
|
|
23
28
|
isError: true,
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { compile, evaluate, initialState } from "./core";
|
|
3
|
+
import { actionsOnly, specProblems } from "./fallback";
|
|
3
4
|
|
|
4
5
|
const load = async () => ({ ok: false as const, error: "no files" });
|
|
5
6
|
|
|
7
|
+
function roots(spec: string) {
|
|
8
|
+
const { program } = compile(spec);
|
|
9
|
+
return evaluate(program!, initialState(program!, new Map()), new Map()).roots;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
describe("cards with only buttons", () => {
|
|
7
|
-
|
|
8
|
-
const decision = `Card("Fix the missing behavior", [
|
|
13
|
+
const decision = `Card("Fix the missing behavior", [
|
|
9
14
|
Button("Do both (recommended)", Send("Do both"), variant: "primary"),
|
|
10
15
|
Button("Only the clearer instructions", Send("Only instructions")),
|
|
11
16
|
Other()
|
|
12
17
|
])`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
const rowOfButtons = `Card("Fix genui instructions?", [Row([Button("Make both edits"), Button("Only one")])])`;
|
|
19
|
+
|
|
20
|
+
it("flags the two cards that hid their explanation", () => {
|
|
21
|
+
expect(actionsOnly(roots(decision))).toBe(true);
|
|
22
|
+
expect(actionsOnly(roots(rowOfButtons))).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("does not flag buttons beside content", () => {
|
|
26
|
+
expect(actionsOnly(roots(`Card("Which queue?", [Text("pg-boss reuses Postgres."), Button("pg-boss"), Button("BullMQ")])`))).toBe(false);
|
|
17
27
|
});
|
|
18
28
|
|
|
19
|
-
it("
|
|
20
|
-
|
|
21
|
-
expect((await specProblems(spec, load)).problems).toEqual([]);
|
|
29
|
+
it("leaves a ```ui block of buttons alone, since its prose is in the reply", async () => {
|
|
30
|
+
expect((await specProblems(decision, load)).problems).toEqual([]);
|
|
22
31
|
});
|
|
23
32
|
});
|
package/shared/fallback.ts
CHANGED
|
@@ -106,8 +106,8 @@ function nodeTypes(value: unknown, types: Set<string>): Set<string> {
|
|
|
106
106
|
return types;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/** Buttons with nothing beside them: the findings and options they act on ended up in the agent's reasoning, which the user never sees. */
|
|
110
|
-
function actionsOnly(roots: readonly UiNode[]): boolean {
|
|
109
|
+
/** Buttons with nothing beside them, in a render_ui card: the findings and options they act on ended up in the agent's reasoning, which the user never sees. */
|
|
110
|
+
export function actionsOnly(roots: readonly UiNode[]): boolean {
|
|
111
111
|
const types = [...nodeTypes(roots, new Set())].filter((type) => !LAYOUT.has(type));
|
|
112
112
|
return types.length > 0 && types.every((type) => type === "Button" || type === "Other");
|
|
113
113
|
}
|
|
@@ -125,9 +125,6 @@ export async function specProblems(spec: string, load: Loader): Promise<{ proble
|
|
|
125
125
|
const problems = [
|
|
126
126
|
...loaded.flatMap(([request, result]) => (result.ok ? [] : [`${request.path}: ${result.error}`])),
|
|
127
127
|
...(diagnostics.length > 0 ? [formatDiagnostics(diagnostics)] : []),
|
|
128
|
-
...(actionsOnly(roots)
|
|
129
|
-
? ["The card has only buttons. Put what each option does, and the findings behind the choice, in the card itself (Text, Callout, Table, Steps)."]
|
|
130
|
-
: []),
|
|
131
128
|
];
|
|
132
129
|
return { problems, roots };
|
|
133
130
|
}
|