@aintela/chat 0.2.42 → 0.2.44

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.
@@ -0,0 +1,67 @@
1
+ import { default as React } from 'react';
2
+ import { InteractionPart } from '../../../../models/InteractionPart';
3
+ /**
4
+ * Single-owner rendering for slot-placed UI tool parts (issue #325).
5
+ *
6
+ * A UI render tool's component used to render in TWO possible React subtrees: at its
7
+ * stream position (MessageAgent's part list) the moment its result folded in, and later
8
+ * INSIDE the text part (LlmResponseRender) once the model wrote its `{{Component:<slotId>}}`
9
+ * token. Moving an element between subtrees destroys React identity — the component
10
+ * unmounted/remounted on the hand-off, and flapped when the two token matchers disagreed
11
+ * mid-stream (suppressed positionally while no slot block existed yet).
12
+ *
13
+ * The stage removes the second owner. Each slotted UI part is rendered exactly ONCE, by
14
+ * the owning MessageAgent, through a `createPortal` into a stable DETACHED container
15
+ * element keyed by SlotId. The positional spot and the text slot render `UiPartAnchor`s —
16
+ * empty divs that CLAIM the container; the stage appends the container's DOM node under
17
+ * the winning anchor (slot beats positional). Only the DOM node moves — React's tree
18
+ * never changes shape around the component — so identity is preserved and remounts are
19
+ * impossible by construction:
20
+ *
21
+ * - the positional anchor always exists while the part does, so there is never a
22
+ * "suppressed but not yet slotted" gap (the mid-stream flicker), and
23
+ * - the slot anchor merely re-parents the same DOM node when the token settles into a
24
+ * renderable slot (the hand-off), with zero unmount/remount.
25
+ */
26
+ /** Anchor priorities: the slot placement wins over the positional fallback. */
27
+ export declare const UI_PART_ANCHOR_POSITIONAL = 1;
28
+ export declare const UI_PART_ANCHOR_SLOT = 2;
29
+ export declare class UiPartStage {
30
+ private containers;
31
+ private claims;
32
+ private seq;
33
+ /**
34
+ * Slot ids this stage's MessageAgent is rendering through a portal on the CURRENT
35
+ * render pass. LlmResponseRender consults it to decide between rendering an anchor
36
+ * (the part is staged — adopt its container) and the legacy direct render (the part
37
+ * was filtered out of the positional list, or there is no stage at all).
38
+ */
39
+ stagedKeys: ReadonlySet<string>;
40
+ setStagedKeys(keys: Iterable<string>): void;
41
+ /** The stable detached container a slotted part renders into. Created once per key. */
42
+ container(key: string): HTMLElement;
43
+ claim(key: string, token: symbol, el: HTMLElement, priority: number): void;
44
+ release(key: string, token: symbol): void;
45
+ /** Attach the container under the best current claimant (highest priority, then latest). */
46
+ private place;
47
+ }
48
+ export declare const UiPartStageContext: React.Context<UiPartStage | null>;
49
+ /**
50
+ * The SlotId a part is staged under, or undefined when the stage does not manage it.
51
+ * Mirrors the (pre-stage) `suppressSlottedUiParts` eligibility rule exactly: a UI-flagged
52
+ * function part (or ask-user part) whose RESULT has landed (status Done — the SlotId rides
53
+ * the result, so earlier states can't be referenced by a token anyway).
54
+ */
55
+ export declare function stagedSlotIdOf(part: InteractionPart): string | undefined;
56
+ /** Renders a staged part into its stable container. Call from the OWNING MessageAgent only. */
57
+ export declare function renderStagedPart(stage: UiPartStage, key: string, child: React.ReactNode): React.ReactNode;
58
+ /**
59
+ * An adoption point for a staged part's container. Renders an empty div and claims the
60
+ * container for it; the stage moves the container's DOM node under the highest-priority
61
+ * live anchor. Unclaims on unmount (the container then falls back to the other anchor —
62
+ * it is never destroyed here, so the portal's subtree keeps living untouched).
63
+ */
64
+ export declare const UiPartAnchor: React.FC<{
65
+ slotKey: string;
66
+ priority: number;
67
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aintela/chat",
3
- "version": "0.2.42",
3
+ "version": "0.2.44",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"