ngx-json-render 0.7.8 → 0.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-json-render",
3
- "version": "0.7.8",
3
+ "version": "0.8.0",
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",
@@ -25,7 +25,17 @@
25
25
  "@angular/common": ">=19.0.0",
26
26
  "@angular/core": ">=19.0.0",
27
27
  "@json-render/core": ">=0.20.0 <0.22.0",
28
- "zod": "^4.0.0"
28
+ "zod": "^4.0.0",
29
+ "@modelcontextprotocol/ext-apps": "^1.7.5",
30
+ "@modelcontextprotocol/sdk": "^1.29.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "@modelcontextprotocol/ext-apps": {
34
+ "optional": true
35
+ },
36
+ "@modelcontextprotocol/sdk": {
37
+ "optional": true
38
+ }
29
39
  },
30
40
  "dependencies": {
31
41
  "tslib": "^2.3.0"
@@ -45,6 +55,14 @@
45
55
  "types": "./types/ngx-json-render.d.ts",
46
56
  "default": "./fesm2022/ngx-json-render.mjs"
47
57
  },
58
+ "./mcp": {
59
+ "types": "./types/ngx-json-render-mcp.d.ts",
60
+ "default": "./fesm2022/ngx-json-render-mcp.mjs"
61
+ },
62
+ "./schema": {
63
+ "types": "./types/ngx-json-render-schema.d.ts",
64
+ "default": "./fesm2022/ngx-json-render-schema.mjs"
65
+ },
48
66
  "./testing": {
49
67
  "types": "./types/ngx-json-render-testing.d.ts",
50
68
  "default": "./fesm2022/ngx-json-render-testing.mjs"
@@ -0,0 +1,93 @@
1
+ import { Signal } from '@angular/core';
2
+ import { Spec } from '@json-render/core';
3
+ import { App } from '@modelcontextprotocol/ext-apps';
4
+ import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
5
+
6
+ /** Options for {@link injectJsonRenderApp}. */
7
+ interface JsonRenderAppOptions {
8
+ /** App name sent to the host during initialization. Defaults to `"json-render"`. */
9
+ name?: string;
10
+ /** App version sent to the host. Defaults to `"1.0.0"`. */
11
+ version?: string;
12
+ /**
13
+ * Render the spec while the model is still writing the tool call, from the
14
+ * host's `toolinputpartial` notifications. The host "heals" the truncated
15
+ * JSON, so each partial spec is valid but may end in a half-written
16
+ * element; the renderer skips children that do not exist yet. Defaults to
17
+ * `true`. `useJsonRenderApp` in `@json-render/mcp/app` has no equivalent —
18
+ * it waits for the tool result.
19
+ */
20
+ streamPartialInput?: boolean;
21
+ /**
22
+ * Transport to the host. Omit it inside a real MCP Apps iframe: `App`
23
+ * then talks to `window.parent` over `postMessage`. Tests pass one end of
24
+ * an in-memory pair here and an `AppBridge` on the other.
25
+ */
26
+ transport?: Transport;
27
+ /**
28
+ * Report the page's size to the host as it changes, so the iframe grows
29
+ * with the rendered UI. Defaults to `true`; needs `ResizeObserver`.
30
+ */
31
+ autoResize?: boolean;
32
+ }
33
+ /**
34
+ * What {@link injectJsonRenderApp} returns — the fields of
35
+ * `UseJsonRenderAppReturn` from `@json-render/mcp/app`, as signals.
36
+ */
37
+ interface JsonRenderApp {
38
+ /** The current spec; `null` until the first tool input or result. */
39
+ readonly spec: Signal<Spec | null>;
40
+ /** Whether the app is still connecting to the host. */
41
+ readonly connecting: Signal<boolean>;
42
+ /** Whether the app is connected to the host. */
43
+ readonly connected: Signal<boolean>;
44
+ /** Connection error, if any. */
45
+ readonly error: Signal<Error | null>;
46
+ /** Whether the spec is still arriving: pass it to `<json-render [loading]>`. */
47
+ readonly loading: Signal<boolean>;
48
+ /** The underlying MCP Apps `App`. */
49
+ readonly app: App;
50
+ /**
51
+ * Call a tool on the MCP server and replace the spec with its result —
52
+ * for refresh and drill-down interactions.
53
+ */
54
+ callServerTool(name: string, args?: Record<string, unknown>): Promise<void>;
55
+ /**
56
+ * Post a user message to the host's chat, so the model answers what the
57
+ * user did in the view. `data`, if given, follows the text as a JSON block.
58
+ * Rejects when the host does not accept messages from views or turns this
59
+ * one down, so an action's `onError` runs.
60
+ */
61
+ sendMessage(text: string, data?: Record<string, unknown>): Promise<void>;
62
+ }
63
+ /** The text of a {@link JsonRenderApp.sendMessage} message. */
64
+ declare function messageText(text: string, data?: Record<string, unknown>): string;
65
+ interface ToolResultLike {
66
+ content?: {
67
+ type: string;
68
+ text?: string;
69
+ }[];
70
+ }
71
+ /**
72
+ * Read a spec out of a tool result. Same rule as `@json-render/mcp/app`: the
73
+ * first text block, parsed as JSON, either a bare spec or `{ spec }`.
74
+ */
75
+ declare function parseSpecFromToolResult(result: ToolResultLike): Spec | null;
76
+ /**
77
+ * Connect an Angular app running inside an MCP Apps iframe to its host and
78
+ * keep the json-render spec the model sent in a signal. The Angular
79
+ * counterpart of `useJsonRenderApp` from `@json-render/mcp/app`; the server
80
+ * side is `createMcpApp` from `@json-render/mcp`, unchanged.
81
+ *
82
+ * Call it in an injection context. The connection closes when the injector
83
+ * that created it is destroyed.
84
+ *
85
+ * ```ts
86
+ * readonly mcp = injectJsonRenderApp();
87
+ * // <json-render [spec]="mcp.spec()" [loading]="mcp.loading()" [registry]="registry" />
88
+ * ```
89
+ */
90
+ declare function injectJsonRenderApp(options?: JsonRenderAppOptions): JsonRenderApp;
91
+
92
+ export { injectJsonRenderApp, messageText, parseSpecFromToolResult };
93
+ export type { JsonRenderApp, JsonRenderAppOptions };
@@ -0,0 +1,74 @@
1
+ import * as _json_render_core from '@json-render/core';
2
+
3
+ /**
4
+ * The schema for ngx-json-render.
5
+ *
6
+ * Defines:
7
+ * - Spec: A flat tree of elements with keys, types, props, and children references
8
+ * - Catalog: Components with props schemas, and optional actions
9
+ *
10
+ * This is the same spec grammar the other json-render renderers use, so
11
+ * catalogs and specs are portable across frameworks.
12
+ */
13
+ declare const schema: _json_render_core.Schema<{
14
+ spec: _json_render_core.SchemaType<"object", {
15
+ /** Root element key */
16
+ root: _json_render_core.SchemaType<"string", unknown>;
17
+ /** Flat map of elements by key */
18
+ elements: _json_render_core.SchemaType<"record", _json_render_core.SchemaType<"object", {
19
+ /** Component type from catalog */
20
+ type: _json_render_core.SchemaType<"ref", string>;
21
+ /** Component props */
22
+ props: _json_render_core.SchemaType<"propsOf", string>;
23
+ /** Child element keys (flat reference) */
24
+ children: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
25
+ /** Visibility condition */
26
+ visible: {
27
+ optional: true;
28
+ kind: "any";
29
+ inner?: unknown;
30
+ };
31
+ /** Repeat children from a state array */
32
+ repeat: {
33
+ optional: true;
34
+ kind: "any";
35
+ inner?: unknown;
36
+ };
37
+ }>>;
38
+ }>;
39
+ catalog: _json_render_core.SchemaType<"object", {
40
+ /** Component definitions */
41
+ components: _json_render_core.SchemaType<"map", {
42
+ /** Zod schema for component props */
43
+ props: _json_render_core.SchemaType<"zod", unknown>;
44
+ /** Slots for this component. Use ['default'] for children, or named slots like ['header', 'footer'] */
45
+ slots: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
46
+ /** Description for AI generation hints */
47
+ description: _json_render_core.SchemaType<"string", unknown>;
48
+ /** Example prop values used in prompt examples (auto-generated from Zod schema if omitted) */
49
+ example: _json_render_core.SchemaType<"any", unknown>;
50
+ }>;
51
+ /** Action definitions (optional) */
52
+ actions: _json_render_core.SchemaType<"map", {
53
+ /** Zod schema for action params */
54
+ params: _json_render_core.SchemaType<"zod", unknown>;
55
+ /** Description for AI generation hints */
56
+ description: _json_render_core.SchemaType<"string", unknown>;
57
+ }>;
58
+ }>;
59
+ }>;
60
+ /**
61
+ * Type for the Angular schema
62
+ */
63
+ type AngularSchema = typeof schema;
64
+ /**
65
+ * Infer the spec type from a catalog
66
+ */
67
+ type AngularSpec<TCatalog> = typeof schema extends {
68
+ createCatalog: (catalog: TCatalog) => {
69
+ _specType: infer S;
70
+ };
71
+ } ? S : never;
72
+
73
+ export { schema };
74
+ export type { AngularSchema, AngularSpec };
@@ -4,6 +4,7 @@ export { ActionBinding, ActionHandler, InferActionParams, InferCatalogComponents
4
4
  import * as _angular_core from '@angular/core';
5
5
  import { Signal, Type, Injector, InjectionToken } from '@angular/core';
6
6
  import * as ngx_json_render from 'ngx-json-render';
7
+ export { AngularSchema, AngularSpec, schema } from 'ngx-json-render/schema';
7
8
 
8
9
  interface PendingConfirmation {
9
10
  action: ResolvedAction;
@@ -1345,81 +1346,11 @@ interface ChatUIReturn {
1345
1346
  */
1346
1347
  declare function injectChatUI(options: ChatUIOptions): ChatUIReturn;
1347
1348
 
1348
- /**
1349
- * The schema for ngx-json-render.
1350
- *
1351
- * Defines:
1352
- * - Spec: A flat tree of elements with keys, types, props, and children references
1353
- * - Catalog: Components with props schemas, and optional actions
1354
- *
1355
- * This is the same spec grammar the other json-render renderers use, so
1356
- * catalogs and specs are portable across frameworks.
1357
- */
1358
- declare const schema: _json_render_core.Schema<{
1359
- spec: _json_render_core.SchemaType<"object", {
1360
- /** Root element key */
1361
- root: _json_render_core.SchemaType<"string", unknown>;
1362
- /** Flat map of elements by key */
1363
- elements: _json_render_core.SchemaType<"record", _json_render_core.SchemaType<"object", {
1364
- /** Component type from catalog */
1365
- type: _json_render_core.SchemaType<"ref", string>;
1366
- /** Component props */
1367
- props: _json_render_core.SchemaType<"propsOf", string>;
1368
- /** Child element keys (flat reference) */
1369
- children: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
1370
- /** Visibility condition */
1371
- visible: {
1372
- optional: true;
1373
- kind: "any";
1374
- inner?: unknown;
1375
- };
1376
- /** Repeat children from a state array */
1377
- repeat: {
1378
- optional: true;
1379
- kind: "any";
1380
- inner?: unknown;
1381
- };
1382
- }>>;
1383
- }>;
1384
- catalog: _json_render_core.SchemaType<"object", {
1385
- /** Component definitions */
1386
- components: _json_render_core.SchemaType<"map", {
1387
- /** Zod schema for component props */
1388
- props: _json_render_core.SchemaType<"zod", unknown>;
1389
- /** Slots for this component. Use ['default'] for children, or named slots like ['header', 'footer'] */
1390
- slots: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
1391
- /** Description for AI generation hints */
1392
- description: _json_render_core.SchemaType<"string", unknown>;
1393
- /** Example prop values used in prompt examples (auto-generated from Zod schema if omitted) */
1394
- example: _json_render_core.SchemaType<"any", unknown>;
1395
- }>;
1396
- /** Action definitions (optional) */
1397
- actions: _json_render_core.SchemaType<"map", {
1398
- /** Zod schema for action params */
1399
- params: _json_render_core.SchemaType<"zod", unknown>;
1400
- /** Description for AI generation hints */
1401
- description: _json_render_core.SchemaType<"string", unknown>;
1402
- }>;
1403
- }>;
1404
- }>;
1405
- /**
1406
- * Type for the Angular schema
1407
- */
1408
- type AngularSchema = typeof schema;
1409
- /**
1410
- * Infer the spec type from a catalog
1411
- */
1412
- type AngularSpec<TCatalog> = typeof schema extends {
1413
- createCatalog: (catalog: TCatalog) => {
1414
- _specType: infer S;
1415
- };
1416
- } ? S : never;
1417
-
1418
1349
  /**
1419
1350
  * Reactive mirror of the json-render devtools-active flag. When active, the
1420
1351
  * renderer wraps each element with a `data-jr-key` attribute for the picker.
1421
1352
  */
1422
1353
  declare function injectDevtoolsActive(): Signal<boolean>;
1423
1354
 
1424
- export { CONFIRM_CONTEXT, ELEMENT_KEY, JR_CONFIRM_DIALOG, JR_CONFIRM_LABELS, JrChildren, JrConfirmDialog, JrElement, JrRepeatScope, JsonRenderActionsService, JsonRenderRootContext, JsonRenderStateService, JsonRenderValidationService, JsonRenderer, RENDER_CONTEXT, REPEAT_SCOPE, applyPatch, buildSpecFromParts, checkSpec, createStoreSetState, defineRegistry, flatToTree, formatSpecCheckIssues, getTextFromParts, injectAction, injectActions, injectBoundProp, injectChatUI, injectConfirmContext, injectDevtoolsActive, injectElementKey, injectFieldValidation, injectRenderContext, injectRepeatScope, injectStateBinding, injectStateStore, injectStateValue, injectUIStream, injectValidation, isActionCancelled, jsonRenderMessage, schema };
1425
- export type { ActionFn, Actions, AngularSchema, AngularSpec, CatalogHasActions, ChatMessage, ChatUIOptions, ChatUIReturn, ComponentRegistry, Components, ConfirmContext, ConfirmLabels, DataPart, DefineRegistryResult, EventHandle, FieldValidationState, PendingConfirmation, RegistryEntry, RenderContext, RenderLimits, RepeatScope, SetState, SpecCatalog, SpecCheck, SpecCheckIssue, SpecCheckIssueCode, SpecCheckOptions, SpecValidationMode, StateChange, TokenUsage, UIStreamOptions, UIStreamReturn, UIStreamSendOptions };
1355
+ export { CONFIRM_CONTEXT, ELEMENT_KEY, JR_CONFIRM_DIALOG, JR_CONFIRM_LABELS, JrChildren, JrConfirmDialog, JrElement, JrRepeatScope, JsonRenderActionsService, JsonRenderRootContext, JsonRenderStateService, JsonRenderValidationService, JsonRenderer, RENDER_CONTEXT, REPEAT_SCOPE, applyPatch, buildSpecFromParts, checkSpec, createStoreSetState, defineRegistry, flatToTree, formatSpecCheckIssues, getTextFromParts, injectAction, injectActions, injectBoundProp, injectChatUI, injectConfirmContext, injectDevtoolsActive, injectElementKey, injectFieldValidation, injectRenderContext, injectRepeatScope, injectStateBinding, injectStateStore, injectStateValue, injectUIStream, injectValidation, isActionCancelled, jsonRenderMessage };
1356
+ export type { ActionFn, Actions, CatalogHasActions, ChatMessage, ChatUIOptions, ChatUIReturn, ComponentRegistry, Components, ConfirmContext, ConfirmLabels, DataPart, DefineRegistryResult, EventHandle, FieldValidationState, PendingConfirmation, RegistryEntry, RenderContext, RenderLimits, RepeatScope, SetState, SpecCatalog, SpecCheck, SpecCheckIssue, SpecCheckIssueCode, SpecCheckOptions, SpecValidationMode, StateChange, TokenUsage, UIStreamOptions, UIStreamReturn, UIStreamSendOptions };