openclaw/apps/web/lib/report-blocks.ts
kumarabhirup a1a54403a5
Gateway: ship Ironclaw web app as a managed sidecar
- Add gateway.webApp config (enabled, port, dev) as the unified toggle
  for both the Next.js web UI and the built-in control UI
- Spawn Next.js app alongside the gateway; stop it on shutdown
- Auto-enable webApp in config for new and existing installs
- Pre-build Next.js in deploy.sh and ship .next/ in the npm package
  so installed users get instant startup (no build step)
- Gateway skips build when pre-built .next/ exists; builds on first
  run for dev/git-checkout users
- Onboarding "Open the Web UI" now opens the Ironclaw web app
- Fix pre-existing Next.js build errors (ES2023 lib, Tiptap v3 types,
  Suspense boundary, ReportConfig type alignment)
- Rename deploy target from openclaw-ai-sdk to ironclaw

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 00:37:56 -08:00

59 lines
1.7 KiB
TypeScript

/**
* Pure utility functions for parsing report-json blocks from chat text.
* Extracted from chat-message.tsx for testability.
*/
import type { ReportConfig } from "../app/components/charts/types";
export type { ReportConfig };
export type ParsedSegment =
| { type: "text"; text: string }
| { type: "report-artifact"; config: ReportConfig };
/**
* Split text containing ```report-json ... ``` fenced blocks into
* alternating text and report-artifact segments.
*/
export function splitReportBlocks(text: string): ParsedSegment[] {
const reportFenceRegex = /```report-json\s*\n([\s\S]*?)```/g;
const segments: ParsedSegment[] = [];
let lastIndex = 0;
for (const match of text.matchAll(reportFenceRegex)) {
const before = text.slice(lastIndex, match.index);
if (before.trim()) {
segments.push({ type: "text", text: before });
}
try {
const config = JSON.parse(match[1]) as ReportConfig;
if (config.panels && Array.isArray(config.panels)) {
segments.push({ type: "report-artifact", config });
} else {
// Invalid report config -- render as plain text
segments.push({ type: "text", text: match[0] });
}
} catch {
// Invalid JSON -- render as plain text
segments.push({ type: "text", text: match[0] });
}
lastIndex = (match.index ?? 0) + match[0].length;
}
const remaining = text.slice(lastIndex);
if (remaining.trim()) {
segments.push({ type: "text", text: remaining });
}
return segments;
}
/**
* Check if text contains any report-json fenced blocks.
*/
export function hasReportBlocks(text: string): boolean {
return text.includes("```report-json");
}