ngx-json-render 0.1.4 → 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 +76 -35
- package/fesm2022/ngx-json-render.mjs +444 -304
- package/fesm2022/ngx-json-render.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-json-render.d.ts +103 -50
package/package.json
CHANGED
|
@@ -593,6 +593,66 @@ declare function defineRegistry<C extends Catalog>(catalog: C, options: DefineRe
|
|
|
593
593
|
*/
|
|
594
594
|
declare function createStoreSetState(store: Pick<StateStore, 'getSnapshot' | 'update'>): SetState;
|
|
595
595
|
|
|
596
|
+
/**
|
|
597
|
+
* Apply an RFC 6902 JSON patch to a spec, returning a new spec object and
|
|
598
|
+
* sharing every subtree the patch did not touch.
|
|
599
|
+
*
|
|
600
|
+
* This is the only patch engine in the package: `injectUIStream`,
|
|
601
|
+
* `injectChatUI` and `buildSpecFromParts` all route through it, so the same
|
|
602
|
+
* stream produces the same spec whichever one an app reached for. The write
|
|
603
|
+
* primitives come from `@json-render/core`, so `add` splices into an array
|
|
604
|
+
* where `replace` overwrites, exactly as the other renderers do.
|
|
605
|
+
*
|
|
606
|
+
* One deliberate deviation from RFC 6902: a failing `test` op is a no-op
|
|
607
|
+
* rather than an abort. These patches come off a model's output, where the
|
|
608
|
+
* established behaviour — see the line parser — is to drop what does not make
|
|
609
|
+
* sense and keep rendering rather than kill a generation mid-flight.
|
|
610
|
+
*/
|
|
611
|
+
declare function applyPatch(spec: Spec, patch: JsonPatch): Spec;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Convert a flat element list to a Spec.
|
|
615
|
+
* Input elements use key/parentKey to establish identity and relationships.
|
|
616
|
+
* Output spec uses the map-based format where key is the map entry key
|
|
617
|
+
* and parent-child relationships are expressed through children arrays.
|
|
618
|
+
*/
|
|
619
|
+
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
620
|
+
/**
|
|
621
|
+
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
622
|
+
* structural type so that library helpers do not depend on the AI SDK.
|
|
623
|
+
*/
|
|
624
|
+
interface DataPart {
|
|
625
|
+
type: string;
|
|
626
|
+
text?: string;
|
|
627
|
+
data?: unknown;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Build a `Spec` by replaying all spec data parts from a message's
|
|
631
|
+
* parts array (AI SDK `UIMessage.parts`). Returns `null` if no spec data
|
|
632
|
+
* parts are present.
|
|
633
|
+
*/
|
|
634
|
+
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
635
|
+
/**
|
|
636
|
+
* Extract and join all text content from a message's parts array.
|
|
637
|
+
*/
|
|
638
|
+
declare function getTextFromParts(parts: DataPart[]): string;
|
|
639
|
+
/**
|
|
640
|
+
* Extract both the json-render spec and the text content from a message's
|
|
641
|
+
* parts array, as memoized signals. Angular counterpart of
|
|
642
|
+
* `useJsonRenderMessage` from the other renderers.
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
* ```ts
|
|
646
|
+
* readonly msg = jsonRenderMessage(() => this.message().parts);
|
|
647
|
+
* // template: @if (msg.hasSpec()) { <json-render [spec]="msg.spec()" ... /> }
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
declare function jsonRenderMessage(parts: Signal<DataPart[]> | (() => DataPart[])): {
|
|
651
|
+
spec: Signal<Spec | null>;
|
|
652
|
+
text: Signal<string>;
|
|
653
|
+
hasSpec: Signal<boolean>;
|
|
654
|
+
};
|
|
655
|
+
|
|
596
656
|
/**
|
|
597
657
|
* Token usage metadata from AI generation.
|
|
598
658
|
*/
|
|
@@ -602,11 +662,17 @@ interface TokenUsage {
|
|
|
602
662
|
totalTokens: number;
|
|
603
663
|
}
|
|
604
664
|
/**
|
|
605
|
-
*
|
|
606
|
-
* object (structural sharing for untouched elements).
|
|
607
|
-
* Supports add, remove, replace, move, copy, and test operations.
|
|
665
|
+
* Per-call options for {@link UIStreamReturn.send}.
|
|
608
666
|
*/
|
|
609
|
-
|
|
667
|
+
interface UIStreamSendOptions {
|
|
668
|
+
/** Arbitrary context forwarded to the endpoint as `context`. */
|
|
669
|
+
context?: Record<string, unknown>;
|
|
670
|
+
/**
|
|
671
|
+
* Spec to refine instead of starting from an empty one. It is sent to the
|
|
672
|
+
* endpoint as `currentSpec` and the streamed patches apply on top of it.
|
|
673
|
+
*/
|
|
674
|
+
previousSpec?: Spec;
|
|
675
|
+
}
|
|
610
676
|
/**
|
|
611
677
|
* Options for {@link injectUIStream}.
|
|
612
678
|
*/
|
|
@@ -617,6 +683,17 @@ interface UIStreamOptions {
|
|
|
617
683
|
onComplete?: (spec: Spec) => void;
|
|
618
684
|
/** Callback on error */
|
|
619
685
|
onError?: (error: Error) => void;
|
|
686
|
+
/**
|
|
687
|
+
* Transport, defaulting to the global `fetch`.
|
|
688
|
+
*
|
|
689
|
+
* Anything with fetch's shape works, so a test, a demo replaying a recorded
|
|
690
|
+
* generation, or an app that has to add auth headers or route through its
|
|
691
|
+
* own HTTP layer can supply one instead of patching the global. It is called
|
|
692
|
+
* with the endpoint and a request carrying the JSON body and the abort
|
|
693
|
+
* signal, and must resolve to a `Response` whose `body` is a readable
|
|
694
|
+
* stream of the JSONL patches.
|
|
695
|
+
*/
|
|
696
|
+
fetch?: typeof globalThis.fetch;
|
|
620
697
|
}
|
|
621
698
|
/**
|
|
622
699
|
* Return type for {@link injectUIStream}.
|
|
@@ -633,8 +710,13 @@ interface UIStreamReturn {
|
|
|
633
710
|
/** Raw JSONL lines received from the stream (JSON patch lines) */
|
|
634
711
|
readonly rawLines: Signal<string[]>;
|
|
635
712
|
/** Send a prompt to generate UI */
|
|
636
|
-
send: (prompt: string,
|
|
637
|
-
/**
|
|
713
|
+
send: (prompt: string, options?: UIStreamSendOptions) => Promise<void>;
|
|
714
|
+
/**
|
|
715
|
+
* Stop the in-flight generation, keeping whatever has rendered so far.
|
|
716
|
+
* A no-op when nothing is streaming.
|
|
717
|
+
*/
|
|
718
|
+
stop: () => void;
|
|
719
|
+
/** Stop any generation and clear the spec, error, usage and raw lines. */
|
|
638
720
|
clear: () => void;
|
|
639
721
|
}
|
|
640
722
|
/**
|
|
@@ -655,48 +737,7 @@ interface UIStreamReturn {
|
|
|
655
737
|
* ```
|
|
656
738
|
*/
|
|
657
739
|
declare function injectUIStream(options: UIStreamOptions): UIStreamReturn;
|
|
658
|
-
|
|
659
|
-
* Convert a flat element list to a Spec.
|
|
660
|
-
* Input elements use key/parentKey to establish identity and relationships.
|
|
661
|
-
* Output spec uses the map-based format where key is the map entry key
|
|
662
|
-
* and parent-child relationships are expressed through children arrays.
|
|
663
|
-
*/
|
|
664
|
-
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
665
|
-
/**
|
|
666
|
-
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
667
|
-
* structural type so that library helpers do not depend on the AI SDK.
|
|
668
|
-
*/
|
|
669
|
-
interface DataPart {
|
|
670
|
-
type: string;
|
|
671
|
-
text?: string;
|
|
672
|
-
data?: unknown;
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Build a `Spec` by replaying all spec data parts from a message's
|
|
676
|
-
* parts array (AI SDK `UIMessage.parts`). Returns `null` if no spec data
|
|
677
|
-
* parts are present.
|
|
678
|
-
*/
|
|
679
|
-
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
680
|
-
/**
|
|
681
|
-
* Extract and join all text content from a message's parts array.
|
|
682
|
-
*/
|
|
683
|
-
declare function getTextFromParts(parts: DataPart[]): string;
|
|
684
|
-
/**
|
|
685
|
-
* Extract both the json-render spec and the text content from a message's
|
|
686
|
-
* parts array, as memoized signals. Angular counterpart of
|
|
687
|
-
* `useJsonRenderMessage` from the other renderers.
|
|
688
|
-
*
|
|
689
|
-
* @example
|
|
690
|
-
* ```ts
|
|
691
|
-
* readonly msg = jsonRenderMessage(() => this.message().parts);
|
|
692
|
-
* // template: @if (msg.hasSpec()) { <json-render [spec]="msg.spec()" ... /> }
|
|
693
|
-
* ```
|
|
694
|
-
*/
|
|
695
|
-
declare function jsonRenderMessage(parts: Signal<DataPart[]> | (() => DataPart[])): {
|
|
696
|
-
spec: Signal<Spec | null>;
|
|
697
|
-
text: Signal<string>;
|
|
698
|
-
hasSpec: Signal<boolean>;
|
|
699
|
-
};
|
|
740
|
+
|
|
700
741
|
/**
|
|
701
742
|
* A single message in the chat, which may contain text, a rendered UI spec,
|
|
702
743
|
* or both.
|
|
@@ -721,6 +762,13 @@ interface ChatUIOptions {
|
|
|
721
762
|
onComplete?: (message: ChatMessage) => void;
|
|
722
763
|
/** Callback on error */
|
|
723
764
|
onError?: (error: Error) => void;
|
|
765
|
+
/**
|
|
766
|
+
* Transport, defaulting to the global `fetch`. Same contract as
|
|
767
|
+
* `UIStreamOptions.fetch`: it receives the endpoint and a request
|
|
768
|
+
* carrying the JSON body and the abort signal, and must resolve to a
|
|
769
|
+
* `Response` whose `body` streams the reply.
|
|
770
|
+
*/
|
|
771
|
+
fetch?: typeof globalThis.fetch;
|
|
724
772
|
}
|
|
725
773
|
/**
|
|
726
774
|
* Return type for {@link injectChatUI}.
|
|
@@ -734,7 +782,12 @@ interface ChatUIReturn {
|
|
|
734
782
|
readonly error: Signal<Error | null>;
|
|
735
783
|
/** Send a user message */
|
|
736
784
|
send: (text: string) => Promise<void>;
|
|
737
|
-
/**
|
|
785
|
+
/**
|
|
786
|
+
* Stop the in-flight reply, keeping whatever the assistant has said so far.
|
|
787
|
+
* A no-op when nothing is streaming.
|
|
788
|
+
*/
|
|
789
|
+
stop: () => void;
|
|
790
|
+
/** Stop any reply and clear all messages and the error. */
|
|
738
791
|
clear: () => void;
|
|
739
792
|
}
|
|
740
793
|
/**
|
|
@@ -824,4 +877,4 @@ type AngularSpec<TCatalog> = typeof schema extends {
|
|
|
824
877
|
declare function injectDevtoolsActive(): Signal<boolean>;
|
|
825
878
|
|
|
826
879
|
export { JrChildren, JrConfirmDialog, JrElement, JrRepeatScope, JsonRenderActionsService, JsonRenderRootContext, JsonRenderStateService, JsonRenderValidationService, JsonRenderer, RENDER_CONTEXT, REPEAT_SCOPE, applyPatch, buildSpecFromParts, createStoreSetState, defineRegistry, flatToTree, getTextFromParts, injectAction, injectActions, injectBoundProp, injectChatUI, injectDevtoolsActive, injectFieldValidation, injectRenderContext, injectRepeatScope, injectStateBinding, injectStateStore, injectStateValue, injectUIStream, injectValidation, jsonRenderMessage, schema };
|
|
827
|
-
export type { ActionFn, Actions, AngularSchema, AngularSpec, CatalogHasActions, ChatMessage, ChatUIOptions, ChatUIReturn, ComponentRegistry, Components, DataPart, DefineRegistryResult, EventHandle, FieldValidationState, PendingConfirmation, RegistryEntry, RenderContext, RepeatScope, SetState, StateChange, TokenUsage, UIStreamOptions, UIStreamReturn };
|
|
880
|
+
export type { ActionFn, Actions, AngularSchema, AngularSpec, CatalogHasActions, ChatMessage, ChatUIOptions, ChatUIReturn, ComponentRegistry, Components, DataPart, DefineRegistryResult, EventHandle, FieldValidationState, PendingConfirmation, RegistryEntry, RenderContext, RepeatScope, SetState, StateChange, TokenUsage, UIStreamOptions, UIStreamReturn, UIStreamSendOptions };
|