hermes-agent/apps/desktop/src/lib/json-format.ts
Brooklyn Nicholson e0325cf769 feat(desktop): Capabilities foundation — shared utils, master-detail, editors, primitives
The reusable base the Capabilities rework sits on:
- lib/{text,time,format,json-format}: consolidate ~30 hand-rolled string/date/
  number/JSON helpers behind one set of tested utilities.
- master-detail scaffold (MasterDetail / ListColumn / DetailColumn / DetailPane /
  CapRow / ListStrip / ToolChip / ICON_BUTTON) + row-hover; tabs-as-data
  PageSearchShell; EmptyState + ErrorBanner; a shared LogTail terminal surface.
- framed CodeEditor + JsonDocumentEditor, wired into every in-app markdown/JSON
  edit surface (profile SOUL.md, memory nodes, right-click sidebar profile).
- shared React Query cache helper (writeCache) + per-profile-switch/ debounce hooks.
2026-07-03 05:08:13 -05:00

15 lines
433 B
TypeScript

export type FormatJsonResult = { ok: true; text: string } | { ok: false; error: string }
export function tryFormatJson(raw: string): FormatJsonResult {
const text = raw.trim()
if (!text) {
return { ok: true, text: raw }
}
try {
return { ok: true, text: JSON.stringify(JSON.parse(text) as unknown, null, 2) }
} catch (err) {
return { ok: false, error: err instanceof Error ? err.message : String(err) }
}
}