Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
be8b5b4
feat(core): agent run and governance kit, generative UI catalog to 24…
forge-ui Nov 17, 2026
1da58dc
docs: agent kit demos, scenarios and regenerated references
forge-ui Nov 17, 2026
af283ed
chore: regenerate component inventory and llms docs
forge-ui Nov 17, 2026
898026e
chore: block registry requires core 0.9.0
forge-ui Nov 17, 2026
8656031
chore: refresh llms docs after registry update
forge-ui Nov 17, 2026
9d36357
chore: refresh page SEO descriptions
forge-ui Nov 17, 2026
127a6da
style(core): agent kit follows Forge card, badge and motion conventions
forge-ui Nov 17, 2026
988dade
chore: regenerate API reference, inventory and llms docs
forge-ui Nov 17, 2026
0106352
docs: fold the original agent components into the kit's layers
forge-ui Nov 17, 2026
3aa257c
chore: regenerate component docs and llms
forge-ui Nov 17, 2026
c26e034
refactor(core): drop AgentWelcome capability cards in favour of ChatI…
forge-ui Nov 17, 2026
f1d5e65
chore: regenerate component docs and llms
forge-ui Nov 17, 2026
27dd800
feat(core): merge duplicates, add Composer parts, ConversationList an…
forge-ui Nov 17, 2026
5a0e8c4
chore: regenerate component docs and llms
forge-ui Nov 17, 2026
967ee4d
chore(core): package budget for Composer, ConversationList and Inline…
forge-ui Nov 17, 2026
2f4f163
fix(agent): keep model-written blocks that slip on quotes or limits
forge-ui Nov 17, 2026
fce07e6
fix(agent): bar, donut and form blocks read well in the narrow panel
forge-ui Nov 17, 2026
27bd6d6
fix: polish Forge Agent answers seen in a second browser pass
forge-ui Nov 17, 2026
8f7fe43
chore: regenerate component docs and llms
forge-ui Nov 17, 2026
ed86eef
refactor(agent): draw answer blocks with Forge's own components
forge-ui Nov 18, 2026
762f7a7
fix(core): keep InlineDiff keys unique
forge-ui Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@forge-ui-official/agent",
"version": "0.4.0",
"version": "0.5.0",
"description": "Forge Agent — an embeddable AI agent that understands your product, calls its tools and answers with Forge components",
"license": "MIT",
"private": false,
Expand Down Expand Up @@ -37,7 +37,7 @@
"prepublishOnly": "pnpm build && pnpm typecheck && pnpm test"
},
"peerDependencies": {
"@forge-ui-official/core": ">=0.8.3",
"@forge-ui-official/core": ">=0.9.0",
"react": ">=19",
"react-dom": ">=19"
},
Expand Down
73 changes: 54 additions & 19 deletions agent/src/catalog/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { uiSchemas, type UiToolName } from "./schema";
import { BLOCK_OF, parseBlock, uiToolNames, type UiToolName } from "./schema";

/**
* The model writes components inside its answer as fenced blocks (```forge:cards + JSON), so a whole
* answer, components included, comes from one model step. Splitting the text turns each block into
* a component; plain code fences become code or a copyable command.
*/
export const BLOCK_NAMES: Record<string, UiToolName> = {
"forge:cards": "show_cards",
"forge:steps": "show_steps",
"forge:table": "show_table",
"forge:metrics": "show_metrics",
"forge:chart": "show_chart",
"forge:choices": "show_choices",
"forge:followups": "suggest_followups",
};
export const BLOCK_NAMES: Record<string, UiToolName> = Object.fromEntries(uiToolNames.map(name => [BLOCK_OF[name], name]));

export type Segment =
| { kind: "text"; text: string }
Expand All @@ -24,20 +16,46 @@ export type Segment =
const SHELL = new Set(["bash", "sh", "shell", "zsh", "console", "terminal"]);
const FENCE = /^ {0,3}(`{3,})[ \t]*([^\s`]*)[^\n]*$/;

function blockInput(name: UiToolName, body: string): unknown {
let value: unknown;
/**
* Models often quote words inside a string with plain double quotes (不是"接上就好"). A quote is
* structural only next to JSON punctuation; any other quote inside a string is escaped.
*/
export function repairQuotes(body: string) {
let out = "";
let inString = false;
for (let index = 0; index < body.length; index++) {
const char = body[index];
if (char === "\\" && inString) { out += char + (body[index + 1] ?? ""); index++; continue; }
if (char !== '"') { out += char; continue; }
if (!inString) { inString = true; out += char; continue; }
const next = body.slice(index + 1).trimStart()[0];
if (next === undefined || next === ":" || next === "," || next === "}" || next === "]") { inString = false; out += char; }
else out += '\\"';
}
return out;
}

function parseJson(body: string): unknown {
try {
value = JSON.parse(body);
return JSON.parse(body);
} catch {
return undefined;
try { return JSON.parse(repairQuotes(body)); } catch { return undefined; }
}
}

function blockInput(name: UiToolName, body: string): unknown {
let value = parseJson(body);
if (value === undefined) return undefined;
// A bare list is the obvious shorthand for follow-up questions.
if (name === "suggest_followups" && Array.isArray(value)) value = { questions: value };
const parsed = uiSchemas[name].safeParse(value);
return parsed.success ? parsed.data : undefined;
return parseBlock(name, value);
}

function fenced(language: string, body: string): Segment | undefined {
function fenced(fenceLanguage: string, fenceBody: string): Segment | undefined {
// ```json with "forge:table" on the first line, or a bare ``` followed by it.
const named = fenceBody.match(/^\s*(forge:[a-z]+)\s*\n/);
const language = named && BLOCK_NAMES[named[1]] ? named[1] : fenceLanguage;
const body = named && BLOCK_NAMES[named[1]] ? fenceBody.slice(named[0].length) : fenceBody;
const name = BLOCK_NAMES[language.toLowerCase()];
if (name) {
const input = blockInput(name, body);
Expand All @@ -64,19 +82,36 @@ export function splitBlocks(text: string, streaming = false): Segment[] {
prose = [];
};
for (let index = 0; index < lines.length; index++) {
// The whole block on one line: ```forge:tags {"tags": [...]}```
const inline = lines[index].match(/^ {0,3}`{3,}\s*(forge:[a-z]+)\s+(\{.*\})\s*`{3,}\s*$/);
if (inline) {
flush();
const segment = fenced(inline[1], inline[2]);
if (segment) segments.push(segment);
continue;
}
const open = lines[index].match(FENCE);
if (!open) {
prose.push(lines[index]);
continue;
}
const close = lines.findIndex((line, at) => at > index && new RegExp(`^ {0,3}${open[1]}\`*[ \\t]*$`).test(line));
let close = lines.findIndex((line, at) => at > index && new RegExp(`^ {0,3}${open[1]}\`*[ \\t]*$`).test(line));
let body = lines.slice(index + 1, close).join("\n");
// Models sometimes close a block on the JSON's last line: {"title": "…"}```
if (close < 0 && BLOCK_NAMES[open[2].toLowerCase()]) {
const glued = lines.findIndex((line, at) => at > index && new RegExp(`${open[1]}\\s*$`).test(line));
if (glued > 0) {
close = glued;
body = [...lines.slice(index + 1, glued), lines[glued].replace(new RegExp(`${open[1]}\\s*$`), "")].join("\n");
}
}
if (close < 0) {
if (streaming) break;
prose.push(...lines.slice(index));
break;
}
flush();
const segment = fenced(open[2], lines.slice(index + 1, close).join("\n"));
const segment = fenced(open[2], body);
if (segment) segments.push(segment);
index = close;
}
Expand Down
Loading
Loading