ngx-json-render 0.2.0 → 0.2.1
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.
- package/README.md +25 -2
- package/fesm2022/ngx-json-render.mjs +398 -316
- package/fesm2022/ngx-json-render.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-json-render.d.ts +86 -51
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Built on `@json-render/core` (the same spec format, expressions, state store, ac
|
|
|
8
8
|
|
|
9
9
|
This is an Angular **adapter over the official core**, not a second implementation of it — `@json-render/core` is a peer dependency, and the spec your model emits is the same one the React, Vue, Solid and Svelte renderers consume. A catalog and a spec written here move to another framework unchanged.
|
|
10
10
|
|
|
11
|
-
**[Live demo](https://shteynu.github.io/ngx-json-render/)** — interactive spec (bindings, repeat, confirm, watch) and a
|
|
11
|
+
**[Live demo](https://shteynu.github.io/ngx-json-render/)** — interactive spec (bindings, repeat, confirm, watch), a SpecStream rendering progressively that you can stop mid-generation, and a chat where prose and UI patches arrive in one reply; both streaming tabs replay a recording, or call a real model on your own key ([source](https://github.com/shteynu/ngx-json-render/tree/main/projects/demo)) — or [](https://stackblitz.com/github/shteynu/ngx-json-render)
|
|
12
12
|
|
|
13
13
|

|
|
14
14
|
|
|
@@ -135,6 +135,9 @@ import { injectUIStream } from 'ngx-json-render';
|
|
|
135
135
|
template: `
|
|
136
136
|
<json-render [spec]="ui.spec()" [registry]="registry" [loading]="ui.isStreaming()" />
|
|
137
137
|
<button (click)="ui.send('A dashboard for weekly sales')">Generate</button>
|
|
138
|
+
@if (ui.isStreaming()) {
|
|
139
|
+
<button (click)="ui.stop()">Stop</button>
|
|
140
|
+
}
|
|
138
141
|
`,
|
|
139
142
|
imports: [JsonRenderer],
|
|
140
143
|
})
|
|
@@ -193,10 +196,30 @@ readonly ui = injectUIStream({
|
|
|
193
196
|
|
|
194
197
|
`injectChatUI` takes the same option.
|
|
195
198
|
|
|
199
|
+
### Stopping, clearing and refining
|
|
200
|
+
|
|
201
|
+
`stop()` ends the generation in flight and keeps what has already rendered —
|
|
202
|
+
the user changed their mind, so it is not an error and `error` stays null.
|
|
203
|
+
`clear()` stops it too and then resets `spec`, `error`, `usage` and `rawLines`;
|
|
204
|
+
without the stop the request still running would put its spec back on its very
|
|
205
|
+
next patch. Both are no-ops when nothing is streaming, and `injectChatUI` has
|
|
206
|
+
the same pair.
|
|
207
|
+
|
|
208
|
+
To refine a generated UI instead of starting over, hand `send` the spec to
|
|
209
|
+
build on. It is sent to the endpoint as `currentSpec` and the streamed patches
|
|
210
|
+
apply on top of it:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
ui.send('make the chart a bar chart', { previousSpec: ui.spec()! });
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The second argument also carries `context`, forwarded to the endpoint as-is:
|
|
217
|
+
`ui.send(prompt, { context: { locale }, previousSpec })`.
|
|
218
|
+
|
|
196
219
|
Also available:
|
|
197
220
|
|
|
198
221
|
- `injectChatUI({ api, fetch? })` — chat + GenUI: the endpoint takes `{ messages }` and streams prose mixed with ` ```spec ` fenced JSONL; each assistant message carries `text` and/or a `spec`.
|
|
199
|
-
- `applyPatch(spec, patch)` — immutably apply one RFC 6902 patch to a spec.
|
|
222
|
+
- `applyPatch(spec, patch)` — immutably apply one RFC 6902 patch to a spec, sharing every subtree the patch did not touch. Both hooks and `buildSpecFromParts` apply through it, so the same stream produces the same spec whichever one you reach for. One deliberate deviation from the RFC: a failing `test` op is a no-op rather than an abort, because these patches come off a model's output and dropping a bad line beats killing the generation.
|
|
200
223
|
- `buildSpecFromParts` / `getTextFromParts` / `jsonRenderMessage` — derive specs from AI SDK `message.parts`.
|
|
201
224
|
- `catalog.prompt()` / `buildUserPrompt` (from `@json-render/core`) — generate the system/user prompts for your catalog.
|
|
202
225
|
|