ngx-json-render 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +37 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # ngx-json-render
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/ngx-json-render)](https://www.npmjs.com/package/ngx-json-render) [![CI](https://github.com/shteynu/ngx-json-render/actions/workflows/ci.yml/badge.svg)](https://github.com/shteynu/ngx-json-render/actions/workflows/ci.yml) [![license](https://img.shields.io/npm/l/ngx-json-render)](https://github.com/shteynu/ngx-json-render/blob/main/LICENSE)
4
+
3
5
  Angular renderer for [json-render](https://github.com/vercel-labs/json-render) — give an LLM a catalog of your components, stream back a JSON spec, and render it as real Angular components. No `innerHTML`, no `eval`, no framework lock-in on the wire format.
4
6
 
5
7
  Built on `@json-render/core` (the same spec format, expressions, state store, actions, and streaming compiler used by the React, Vue, Solid, and Svelte renderers) and idiomatic modern Angular: standalone components, signals, zoneless-friendly, `OnPush` everywhere.
6
8
 
7
- **[Live demo](https://shteynu.github.io/ngx-json-render/)** — interactive spec (bindings, repeat, confirm, watch) and a replayable SpecStream showing progressive rendering ([source](https://github.com/shteynu/ngx-json-render/tree/main/projects/demo)).
9
+ **[Live demo](https://shteynu.github.io/ngx-json-render/)** — interactive spec (bindings, repeat, confirm, watch) and a replayable SpecStream showing progressive rendering ([source](https://github.com/shteynu/ngx-json-render/tree/main/projects/demo)) — or [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/shteynu/ngx-json-render)
10
+
11
+ ![A SpecStream of RFC 6902 patches rendering progressively into an Angular dashboard](https://raw.githubusercontent.com/shteynu/ngx-json-render/main/docs/streaming.gif)
8
12
 
9
13
  ## Install
10
14
 
@@ -138,9 +142,40 @@ export class GeneratePage {
138
142
  }
139
143
  ```
140
144
 
145
+ ### The server side
146
+
147
+ `injectUIStream` POSTs `{ prompt, context, currentSpec }` to your endpoint and expects the response body to be SpecStream JSONL — one RFC 6902 patch per line. Any server that can stream text works; with the [AI SDK](https://ai-sdk.dev) it's a few lines — `catalog.prompt()` teaches the model your component vocabulary and the patch protocol:
148
+
149
+ ```ts
150
+ // server.ts — Express shown; any Node server works the same way
151
+ import express from 'express';
152
+ import { streamText } from 'ai';
153
+ import { anthropic } from '@ai-sdk/anthropic';
154
+ import { catalog } from './catalog';
155
+
156
+ const app = express();
157
+ app.use(express.json());
158
+
159
+ app.post('/api/generate', async (req, res) => {
160
+ const { prompt } = req.body; // injectUIStream sends { prompt, context, currentSpec }
161
+
162
+ const result = streamText({
163
+ model: anthropic('claude-sonnet-5'),
164
+ system: catalog.prompt(),
165
+ prompt,
166
+ });
167
+
168
+ res.setHeader('Content-Type', 'text/plain; charset=utf-8');
169
+ for await (const chunk of result.textStream) res.write(chunk);
170
+ res.end();
171
+ });
172
+ ```
173
+
174
+ The patches apply to the `spec` signal as each line arrives, so the UI assembles on screen while the model is still generating — exactly what the [demo's Streaming tab](https://shteynu.github.io/ngx-json-render/) replays. Prefer structured output? `catalog.jsonSchema()` exports a JSON Schema for `streamObject`/tool calls, and `catalog.validate(spec)` checks a finished spec against the catalog.
175
+
141
176
  Also available:
142
177
 
143
- - `injectChatUI({ api })` — chat + GenUI: assistant messages carrying both prose and specs (` ```spec ` fenced JSONL).
178
+ - `injectChatUI({ api })` — chat + GenUI: the endpoint takes `{ messages }` and streams prose mixed with ` ```spec ` fenced JSONL; each assistant message carries `text` and/or a `spec`.
144
179
  - `applyPatch(spec, patch)` — immutably apply one RFC 6902 patch to a spec.
145
180
  - `buildSpecFromParts` / `getTextFromParts` / `jsonRenderMessage` — derive specs from AI SDK `message.parts`.
146
181
  - `catalog.prompt()` / `buildUserPrompt` (from `@json-render/core`) — generate the system/user prompts for your catalog.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-json-render",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Angular renderer for json-render — stream AI-generated JSON specs into real Angular components with signals.",
5
5
  "keywords": [
6
6
  "angular",