Part V — The Modern Experience Layer · Chapter 31 · Lesson 2 of 2
React hooks, data grids and OpenAPI import
The frontend half of the SDK story — generate TypeScript source text, then commit it to your app. These generators are available from the built-in analysis namespace; the hooks and adapters they emit are React code, not PeaLang syntax.
React hooks from routes
let hooks = analysis.generate_react_hooks()
write("src/hooks/peaHooks.ts", hooks)
generate_react_hooks() takes no arguments. It returns one TypeScript string with a fixed set of hooks: usePeaRuntime, usePeaScript, usePeaDataFrame, usePeaQuery and usePeaValidation. They wrap a browser WASM runtime and expose loading/error/result state where it applies. Route-to-client typing is a separate generator: analysis.generate_typescript_client(routes, base_url, module_name) returns a TS client with one function per route definition.
Data grid and chart adapters
let grid = analysis.generate_data_grid_adapter()
let charts = analysis.generate_chart_adapter()
write("src/adapters/grid.ts", grid)
write("src/adapters/charts.ts", charts)
Both generators take no arguments and return TypeScript source. The grid adapter exports peaFrameToGridRows, peaFrameToColumnDefs, peaFilterRows and peaSortRows for ag-Grid / TanStack-style tables. The chart adapter exports peaToVegaLite and peaToChartJs. They are starting points, not frameworks — read the generated code and wire it to your own components.
Streaming and middleware sources
analysis.sse_endpoint_source()/analysis.websocket_handler_source()— live endpoint boilerplate for dashboards and consoles.analysis.jwt_middleware_source()/analysis.rate_limiter_source()/analysis.api_versioning_source()— middleware skeletons, each returned as source text.
Vector, RAG and ONNX export (v1.7.0)
let vec = analysis.create_vector([0.1, 0.2, 0.3])
let score = analysis.cosine_similarity(vec["values"], query_vec)
let hits = analysis.hybrid_search("refund policy", docs, embeddings,
vec["values"], 0.5, 5)
let onnx = analysis.model_to_onnx(model)
analysis.onnx_export_json(model, "model.onnx.json")
VectorStore, chunk_text, bm25_score and hybrid_search are in the analysis namespace and work on in-memory data — no external vector database required. cosine_similarity takes two value lists, so unwrap create_vector(...)["values"]. model_to_onnx / tree_to_onnx return an ONNX-like dict; onnx_export_json(model, path) writes that representation as JSON. It is not a compiled binary ONNX artifact.
Notebook to webapp (v1.8.0)
analysis.publish_as_webapp(source, title, template) takes .pea source text and returns a record with html, files, title and template. analysis.generate_notebook_html(cells) takes a list of cell dicts (source and optional output) and returns an HTML string. Both produce text you host yourself — useful for the "here is what the data said" deliverable that used to be a PDF nobody read.
Guided practice
- Call
analysis.generate_react_hooks(), write the returned string into a scratch app and mountusePeaScript; note that hook names are fixed by the SDK, not derived from your routes. - Export a small model with
analysis.model_to_onnx, inspect the returned graph, and compare its parameters with the source model on five inputs. - Publish a script with
analysis.publish_as_webapp(source, "Weekly report")and read the generatedhtmlbefore you host it.