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/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
|
*/
|
|
@@ -644,8 +710,13 @@ interface UIStreamReturn {
|
|
|
644
710
|
/** Raw JSONL lines received from the stream (JSON patch lines) */
|
|
645
711
|
readonly rawLines: Signal<string[]>;
|
|
646
712
|
/** Send a prompt to generate UI */
|
|
647
|
-
send: (prompt: string,
|
|
648
|
-
/**
|
|
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. */
|
|
649
720
|
clear: () => void;
|
|
650
721
|
}
|
|
651
722
|
/**
|
|
@@ -666,48 +737,7 @@ interface UIStreamReturn {
|
|
|
666
737
|
* ```
|
|
667
738
|
*/
|
|
668
739
|
declare function injectUIStream(options: UIStreamOptions): UIStreamReturn;
|
|
669
|
-
|
|
670
|
-
* Convert a flat element list to a Spec.
|
|
671
|
-
* Input elements use key/parentKey to establish identity and relationships.
|
|
672
|
-
* Output spec uses the map-based format where key is the map entry key
|
|
673
|
-
* and parent-child relationships are expressed through children arrays.
|
|
674
|
-
*/
|
|
675
|
-
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
676
|
-
/**
|
|
677
|
-
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
678
|
-
* structural type so that library helpers do not depend on the AI SDK.
|
|
679
|
-
*/
|
|
680
|
-
interface DataPart {
|
|
681
|
-
type: string;
|
|
682
|
-
text?: string;
|
|
683
|
-
data?: unknown;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Build a `Spec` by replaying all spec data parts from a message's
|
|
687
|
-
* parts array (AI SDK `UIMessage.parts`). Returns `null` if no spec data
|
|
688
|
-
* parts are present.
|
|
689
|
-
*/
|
|
690
|
-
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
691
|
-
/**
|
|
692
|
-
* Extract and join all text content from a message's parts array.
|
|
693
|
-
*/
|
|
694
|
-
declare function getTextFromParts(parts: DataPart[]): string;
|
|
695
|
-
/**
|
|
696
|
-
* Extract both the json-render spec and the text content from a message's
|
|
697
|
-
* parts array, as memoized signals. Angular counterpart of
|
|
698
|
-
* `useJsonRenderMessage` from the other renderers.
|
|
699
|
-
*
|
|
700
|
-
* @example
|
|
701
|
-
* ```ts
|
|
702
|
-
* readonly msg = jsonRenderMessage(() => this.message().parts);
|
|
703
|
-
* // template: @if (msg.hasSpec()) { <json-render [spec]="msg.spec()" ... /> }
|
|
704
|
-
* ```
|
|
705
|
-
*/
|
|
706
|
-
declare function jsonRenderMessage(parts: Signal<DataPart[]> | (() => DataPart[])): {
|
|
707
|
-
spec: Signal<Spec | null>;
|
|
708
|
-
text: Signal<string>;
|
|
709
|
-
hasSpec: Signal<boolean>;
|
|
710
|
-
};
|
|
740
|
+
|
|
711
741
|
/**
|
|
712
742
|
* A single message in the chat, which may contain text, a rendered UI spec,
|
|
713
743
|
* or both.
|
|
@@ -734,7 +764,7 @@ interface ChatUIOptions {
|
|
|
734
764
|
onError?: (error: Error) => void;
|
|
735
765
|
/**
|
|
736
766
|
* Transport, defaulting to the global `fetch`. Same contract as
|
|
737
|
-
*
|
|
767
|
+
* `UIStreamOptions.fetch`: it receives the endpoint and a request
|
|
738
768
|
* carrying the JSON body and the abort signal, and must resolve to a
|
|
739
769
|
* `Response` whose `body` streams the reply.
|
|
740
770
|
*/
|
|
@@ -752,7 +782,12 @@ interface ChatUIReturn {
|
|
|
752
782
|
readonly error: Signal<Error | null>;
|
|
753
783
|
/** Send a user message */
|
|
754
784
|
send: (text: string) => Promise<void>;
|
|
755
|
-
/**
|
|
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. */
|
|
756
791
|
clear: () => void;
|
|
757
792
|
}
|
|
758
793
|
/**
|
|
@@ -842,4 +877,4 @@ type AngularSpec<TCatalog> = typeof schema extends {
|
|
|
842
877
|
declare function injectDevtoolsActive(): Signal<boolean>;
|
|
843
878
|
|
|
844
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 };
|
|
845
|
-
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 };
|