@aparte/core 0.2.0-alpha.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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/client/aparte-client.d.ts +326 -0
  4. package/dist/client/aparte-client.d.ts.map +1 -0
  5. package/dist/client/stream-adapter.d.ts +197 -0
  6. package/dist/client/stream-adapter.d.ts.map +1 -0
  7. package/dist/components/bubble/aparte-chat-bubble.d.ts +153 -0
  8. package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -0
  9. package/dist/components/bubble/bubble-sync.d.ts +44 -0
  10. package/dist/components/bubble/bubble-sync.d.ts.map +1 -0
  11. package/dist/components/bubble/index.d.ts +4 -0
  12. package/dist/components/bubble/index.d.ts.map +1 -0
  13. package/dist/components/chat/aparte-chat.d.ts +49 -0
  14. package/dist/components/chat/aparte-chat.d.ts.map +1 -0
  15. package/dist/components/chat/index.d.ts +2 -0
  16. package/dist/components/chat/index.d.ts.map +1 -0
  17. package/dist/components/composer/aparte-composer-action.d.ts +37 -0
  18. package/dist/components/composer/aparte-composer-action.d.ts.map +1 -0
  19. package/dist/components/composer/aparte-composer-add-attachment.d.ts +27 -0
  20. package/dist/components/composer/aparte-composer-add-attachment.d.ts.map +1 -0
  21. package/dist/components/composer/aparte-composer-attachments.d.ts +26 -0
  22. package/dist/components/composer/aparte-composer-attachments.d.ts.map +1 -0
  23. package/dist/components/composer/aparte-composer-cancel.d.ts +21 -0
  24. package/dist/components/composer/aparte-composer-cancel.d.ts.map +1 -0
  25. package/dist/components/composer/aparte-composer-input.d.ts +63 -0
  26. package/dist/components/composer/aparte-composer-input.d.ts.map +1 -0
  27. package/dist/components/composer/aparte-composer-send.d.ts +25 -0
  28. package/dist/components/composer/aparte-composer-send.d.ts.map +1 -0
  29. package/dist/components/composer/aparte-composer.d.ts +150 -0
  30. package/dist/components/composer/aparte-composer.d.ts.map +1 -0
  31. package/dist/components/composer/index.d.ts +9 -0
  32. package/dist/components/composer/index.d.ts.map +1 -0
  33. package/dist/components/conversation-list/aparte-conversation-list.d.ts +50 -0
  34. package/dist/components/conversation-list/aparte-conversation-list.d.ts.map +1 -0
  35. package/dist/components/conversation-list/index.d.ts +2 -0
  36. package/dist/components/conversation-list/index.d.ts.map +1 -0
  37. package/dist/components/elicitation/aparte-elicitation.d.ts +29 -0
  38. package/dist/components/elicitation/aparte-elicitation.d.ts.map +1 -0
  39. package/dist/components/index.d.ts +10 -0
  40. package/dist/components/index.d.ts.map +1 -0
  41. package/dist/components/status/aparte-chat-status.d.ts +34 -0
  42. package/dist/components/status/aparte-chat-status.d.ts.map +1 -0
  43. package/dist/components/status/index.d.ts +2 -0
  44. package/dist/components/status/index.d.ts.map +1 -0
  45. package/dist/components/viewport/aparte-chat-viewport.d.ts +358 -0
  46. package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -0
  47. package/dist/components/viewport/index.d.ts +2 -0
  48. package/dist/components/viewport/index.d.ts.map +1 -0
  49. package/dist/config/action-provider.d.ts +59 -0
  50. package/dist/config/action-provider.d.ts.map +1 -0
  51. package/dist/config/aparte-config.d.ts +490 -0
  52. package/dist/config/aparte-config.d.ts.map +1 -0
  53. package/dist/config/attachment-renderer.d.ts +28 -0
  54. package/dist/config/attachment-renderer.d.ts.map +1 -0
  55. package/dist/config/avatar-provider.d.ts +35 -0
  56. package/dist/config/avatar-provider.d.ts.map +1 -0
  57. package/dist/config/bubble-shell-renderer.d.ts +41 -0
  58. package/dist/config/bubble-shell-renderer.d.ts.map +1 -0
  59. package/dist/config/config-context.d.ts +47 -0
  60. package/dist/config/config-context.d.ts.map +1 -0
  61. package/dist/config/error-renderer.d.ts +26 -0
  62. package/dist/config/error-renderer.d.ts.map +1 -0
  63. package/dist/config/icon-provider.d.ts +63 -0
  64. package/dist/config/icon-provider.d.ts.map +1 -0
  65. package/dist/config/index.d.ts +19 -0
  66. package/dist/config/index.d.ts.map +1 -0
  67. package/dist/config/locale.d.ts +60 -0
  68. package/dist/config/locale.d.ts.map +1 -0
  69. package/dist/config/sanitize.d.ts +31 -0
  70. package/dist/config/sanitize.d.ts.map +1 -0
  71. package/dist/config/sibling-nav-renderer.d.ts +27 -0
  72. package/dist/config/sibling-nav-renderer.d.ts.map +1 -0
  73. package/dist/config/skeleton-provider.d.ts +26 -0
  74. package/dist/config/skeleton-provider.d.ts.map +1 -0
  75. package/dist/config/status-renderer.d.ts +23 -0
  76. package/dist/config/status-renderer.d.ts.map +1 -0
  77. package/dist/conversations/conversation-controller.d.ts +126 -0
  78. package/dist/conversations/conversation-controller.d.ts.map +1 -0
  79. package/dist/conversations/conversation-manager.d.ts +98 -0
  80. package/dist/conversations/conversation-manager.d.ts.map +1 -0
  81. package/dist/conversations/index.d.ts +5 -0
  82. package/dist/conversations/index.d.ts.map +1 -0
  83. package/dist/conversations/types.d.ts +172 -0
  84. package/dist/conversations/types.d.ts.map +1 -0
  85. package/dist/custom-elements.json +15833 -0
  86. package/dist/elicitation/index.d.ts +20 -0
  87. package/dist/elicitation/index.d.ts.map +1 -0
  88. package/dist/elicitation/panel.d.ts +18 -0
  89. package/dist/elicitation/panel.d.ts.map +1 -0
  90. package/dist/elicitation/types.d.ts +98 -0
  91. package/dist/elicitation/types.d.ts.map +1 -0
  92. package/dist/host/aparte-chat-host.d.ts +176 -0
  93. package/dist/host/aparte-chat-host.d.ts.map +1 -0
  94. package/dist/host/index.d.ts +2 -0
  95. package/dist/host/index.d.ts.map +1 -0
  96. package/dist/index-D89k-n2Q.js +6294 -0
  97. package/dist/index-D89k-n2Q.js.map +1 -0
  98. package/dist/index.css +2554 -0
  99. package/dist/index.d.ts +62 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +3763 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/index.node.d.ts +53 -0
  104. package/dist/index.node.d.ts.map +1 -0
  105. package/dist/index.node.js +49 -0
  106. package/dist/index.node.js.map +1 -0
  107. package/dist/interop/element-props.d.ts +23 -0
  108. package/dist/interop/element-props.d.ts.map +1 -0
  109. package/dist/parsers/aparte-event-stream.d.ts +13 -0
  110. package/dist/parsers/aparte-event-stream.d.ts.map +1 -0
  111. package/dist/parsers/aparte-stream-parser.d.ts +137 -0
  112. package/dist/parsers/aparte-stream-parser.d.ts.map +1 -0
  113. package/dist/parsers/index.d.ts +4 -0
  114. package/dist/parsers/index.d.ts.map +1 -0
  115. package/dist/primitives/index.d.ts +8 -0
  116. package/dist/primitives/index.d.ts.map +1 -0
  117. package/dist/primitives/progress-spinner/aparte-progress-spinner.d.ts +25 -0
  118. package/dist/primitives/progress-spinner/aparte-progress-spinner.d.ts.map +1 -0
  119. package/dist/primitives/progress-spinner/index.d.ts +2 -0
  120. package/dist/primitives/progress-spinner/index.d.ts.map +1 -0
  121. package/dist/primitives/select/aparte-optgroup.d.ts +32 -0
  122. package/dist/primitives/select/aparte-optgroup.d.ts.map +1 -0
  123. package/dist/primitives/select/aparte-option.d.ts +30 -0
  124. package/dist/primitives/select/aparte-option.d.ts.map +1 -0
  125. package/dist/primitives/select/aparte-select.d.ts +74 -0
  126. package/dist/primitives/select/aparte-select.d.ts.map +1 -0
  127. package/dist/primitives/select/index.d.ts +9 -0
  128. package/dist/primitives/select/index.d.ts.map +1 -0
  129. package/dist/renderers/index.d.ts +5 -0
  130. package/dist/renderers/index.d.ts.map +1 -0
  131. package/dist/renderers/segment-renderers.d.ts +31 -0
  132. package/dist/renderers/segment-renderers.d.ts.map +1 -0
  133. package/dist/runtime/message-repository.d.ts +111 -0
  134. package/dist/runtime/message-repository.d.ts.map +1 -0
  135. package/dist/transport/backend-handler.d.ts +50 -0
  136. package/dist/transport/backend-handler.d.ts.map +1 -0
  137. package/dist/transport/backend-transport.d.ts +39 -0
  138. package/dist/transport/backend-transport.d.ts.map +1 -0
  139. package/dist/transport/direct-transport.d.ts +36 -0
  140. package/dist/transport/direct-transport.d.ts.map +1 -0
  141. package/dist/transport/index.d.ts +6 -0
  142. package/dist/transport/index.d.ts.map +1 -0
  143. package/dist/transport/types.d.ts +73 -0
  144. package/dist/transport/types.d.ts.map +1 -0
  145. package/dist/types/chat.d.ts +223 -0
  146. package/dist/types/chat.d.ts.map +1 -0
  147. package/dist/types/errors.d.ts +25 -0
  148. package/dist/types/errors.d.ts.map +1 -0
  149. package/dist/types/event-map.d.ts +41 -0
  150. package/dist/types/event-map.d.ts.map +1 -0
  151. package/dist/types/events.d.ts +290 -0
  152. package/dist/types/events.d.ts.map +1 -0
  153. package/dist/types/imperative-api.d.ts +38 -0
  154. package/dist/types/imperative-api.d.ts.map +1 -0
  155. package/dist/types/index.d.ts +22 -0
  156. package/dist/types/index.d.ts.map +1 -0
  157. package/dist/types/model-provider.d.ts +229 -0
  158. package/dist/types/model-provider.d.ts.map +1 -0
  159. package/dist/types/models.d.ts +173 -0
  160. package/dist/types/models.d.ts.map +1 -0
  161. package/dist/types/parsers.d.ts +42 -0
  162. package/dist/types/parsers.d.ts.map +1 -0
  163. package/dist/types/providers.d.ts +93 -0
  164. package/dist/types/providers.d.ts.map +1 -0
  165. package/dist/types/segments.d.ts +221 -0
  166. package/dist/types/segments.d.ts.map +1 -0
  167. package/dist/types/theming.d.ts +44 -0
  168. package/dist/types/theming.d.ts.map +1 -0
  169. package/dist/types/tools.d.ts +98 -0
  170. package/dist/types/tools.d.ts.map +1 -0
  171. package/dist/utils/assert-never.d.ts +9 -0
  172. package/dist/utils/assert-never.d.ts.map +1 -0
  173. package/dist/utils/css-escape.d.ts +15 -0
  174. package/dist/utils/css-escape.d.ts.map +1 -0
  175. package/package.json +68 -0
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Elicitation — public surface.
3
+ *
4
+ * `requestUserInput(req)` is the free-function entry a tool handler calls: it
5
+ * resolves the config governing `req.target` (the instance the request belongs
6
+ * to, or the global default) and delegates to that config's presenter. This is
7
+ * what `ask_question` and tool-approval adapters use — they never touch window
8
+ * events, so there is no stringly-typed contract to drift.
9
+ */
10
+ import type { AparteElicitationRequest, AparteElicitationResult } from './types.js';
11
+ export type { AparteElicitationSchema, AparteElicitationField, AparteElicitationEnumField, AparteElicitationBooleanField, AparteElicitationStringField, AparteElicitationObjectSchema, AparteElicitationRequest, AparteElicitationResult, AparteElicitationPresenter, } from './types.js';
12
+ export { buildElicitationPanel } from './panel.js';
13
+ export type { BuiltElicitationPanel } from './panel.js';
14
+ /**
15
+ * Ask the user for typed input and await their response, on the config
16
+ * governing `request.target` (its instance config, or the global default).
17
+ * Resolves `accept` / `decline` / `cancel`.
18
+ */
19
+ export declare function requestUserInput(request: AparteElicitationRequest): Promise<AparteElicitationResult>;
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/elicitation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEpF,YAAY,EACR,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,GAC7B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAEpG"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * buildElicitationPanel — turns an {@link AparteElicitationSchema} into a DOM panel
3
+ * that the presenter mounts into the composer. Zero-dependency; covers all four
4
+ * schema kinds (enum, boolean, string, object). The presenter reads `getContent`
5
+ * on submit and `isComplete` to gate the send button (via `onChange`).
6
+ */
7
+ import type { AparteElicitationSchema } from './types.js';
8
+ export interface BuiltElicitationPanel {
9
+ readonly el: HTMLElement;
10
+ /** The current response content, shaped to match the schema. */
11
+ getContent(): unknown;
12
+ /** True when every required field has a usable value. */
13
+ isComplete(): boolean;
14
+ /** Focus the first input (called after mount). */
15
+ focus(): void;
16
+ }
17
+ export declare function buildElicitationPanel(message: string, schema: AparteElicitationSchema, onChange: () => void): BuiltElicitationPanel;
18
+ //# sourceMappingURL=panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/elicitation/panel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACR,uBAAuB,EAK1B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC;IACzB,gEAAgE;IAChE,UAAU,IAAI,OAAO,CAAC;IACtB,yDAAyD;IACzD,UAAU,IAAI,OAAO,CAAC;IACtB,kDAAkD;IAClD,KAAK,IAAI,IAAI,CAAC;CACjB;AAmLD,wBAAgB,qBAAqB,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,MAAM,IAAI,GACrB,qBAAqB,CAgCvB"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Elicitation — the generic "pause the run and ask the user for typed input"
3
+ * primitive. Generalises the bespoke `ask_question` tool: the KIND of question
4
+ * is carried by a flat schema, not by a dedicated tool. Shape is aligned with
5
+ * MCP elicitation (message + requested schema, accept/decline/cancel), but the
6
+ * mechanism is transport-agnostic and framework-agnostic — a typed presenter
7
+ * registered per config instance, never window events.
8
+ */
9
+ /** A single choice field: radios (default) or checkboxes (`multiple`). */
10
+ export interface AparteElicitationEnumField {
11
+ type: 'enum';
12
+ title?: string;
13
+ description?: string;
14
+ options: Array<{
15
+ value: string;
16
+ label?: string;
17
+ description?: string;
18
+ recommended?: boolean;
19
+ }>;
20
+ /** Checkboxes (multi-select) instead of radios. */
21
+ multiple?: boolean;
22
+ /** Offer a free-text "Other…" fallback. Default true. */
23
+ allowOther?: boolean;
24
+ /** Pre-selected value (or values, when `multiple`). */
25
+ default?: string | string[];
26
+ }
27
+ /** A yes/no field, rendered as two choices. */
28
+ export interface AparteElicitationBooleanField {
29
+ type: 'boolean';
30
+ title?: string;
31
+ description?: string;
32
+ default?: boolean;
33
+ /** Labels for the two choices (fall back to the locale yes/no). */
34
+ trueLabel?: string;
35
+ falseLabel?: string;
36
+ }
37
+ /** A free-text field. */
38
+ export interface AparteElicitationStringField {
39
+ type: 'string';
40
+ title?: string;
41
+ description?: string;
42
+ placeholder?: string;
43
+ default?: string;
44
+ /** Render a multi-line textarea. */
45
+ multiline?: boolean;
46
+ /** Required to accept. Default true. */
47
+ required?: boolean;
48
+ minLength?: number;
49
+ maxLength?: number;
50
+ }
51
+ /** A single input field. */
52
+ export type AparteElicitationField = AparteElicitationEnumField | AparteElicitationBooleanField | AparteElicitationStringField;
53
+ /** A multi-field form: one labelled field per property. */
54
+ export interface AparteElicitationObjectSchema {
55
+ type: 'object';
56
+ properties: Record<string, AparteElicitationField>;
57
+ /** Which keys must be filled to accept. Default: all of them. */
58
+ required?: string[];
59
+ }
60
+ /** The schema for a request: a single field, or an object (form) of fields. */
61
+ export type AparteElicitationSchema = AparteElicitationField | AparteElicitationObjectSchema;
62
+ export interface AparteElicitationRequest {
63
+ /** Human-readable prompt shown above the input(s). */
64
+ message: string;
65
+ /** What to ask for. */
66
+ schema: AparteElicitationSchema;
67
+ /**
68
+ * An element inside the target chat, used to resolve WHICH instance presents
69
+ * the request (its config + composer). Omit for the global/default chat.
70
+ */
71
+ target?: HTMLElement | null;
72
+ /**
73
+ * Aborts the request — the presenter settles `cancel` and closes the panel.
74
+ * Pass a tool handler's signal so a client-side timeout or turn abort tears
75
+ * the panel down instead of leaving it open.
76
+ */
77
+ signal?: AbortSignal;
78
+ }
79
+ /**
80
+ * The user's response. `content` matches the schema:
81
+ * enum→string, enum+multiple→string[], boolean→boolean, string→string,
82
+ * object→Record<key, value>.
83
+ */
84
+ export type AparteElicitationResult = {
85
+ action: 'accept';
86
+ content: unknown;
87
+ } | {
88
+ action: 'decline';
89
+ } | {
90
+ action: 'cancel';
91
+ };
92
+ /**
93
+ * Presents an elicitation request and resolves with the user's response.
94
+ * Registered per config instance via `AparteConfig.setElicitationPresenter`
95
+ * (the `<aparte-elicitation>` Web Component is the default presenter).
96
+ */
97
+ export type AparteElicitationPresenter = (request: AparteElicitationRequest) => Promise<AparteElicitationResult>;
98
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/elicitation/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,0BAA0B;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC/F,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC/B;AAED,+CAA+C;AAC/C,MAAM,WAAW,6BAA6B;IAC1C,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;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AM,MAAM,0BAA0B,GAAG,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC"}
@@ -0,0 +1,176 @@
1
+ import type { AparteMessage, AparteSegment } from '../types/index.js';
2
+ import { AparteConversationController } from '../conversations/conversation-controller.js';
3
+ import type { AparteConfigClass } from '../config/aparte-config.js';
4
+ /**
5
+ * Everything `AparteChatHost` needs from the framework, expressed without any
6
+ * framework types. Each wrapper (Angular signals, React state, Vue refs, Svelte
7
+ * stores) implements these ~10 closures over its own reactive message list.
8
+ */
9
+ export interface AparteChatHostBinding {
10
+ /** Stable id for the host element (used as `targetId` for scoped events). */
11
+ readonly hostId: string;
12
+ /** The element `AparteClient` drives + that emits lifecycle/path events. */
13
+ readonly host: HTMLElement;
14
+ /** The `<aparte-chat-viewport>` element (branch ops, token append, bubbles). */
15
+ readonly viewport: HTMLElement | null;
16
+ /** Read the current message list (a snapshot). */
17
+ getMessages(): AparteMessage[];
18
+ /** Replace the framework's message list (triggers its re-render). */
19
+ setMessages(messages: AparteMessage[]): void;
20
+ /** Notify the consumer that messages changed (drives `messagesChange`). */
21
+ onMessagesChange?(messages: AparteMessage[]): void;
22
+ /** Notify the consumer a message was appended (drives `messageAppended`). */
23
+ onMessageAppended?(message: AparteMessage): void;
24
+ /** Flip the typing/“thinking” indicator. */
25
+ onTypingChange?(isTyping: boolean): void;
26
+ /** Streaming target id changed (drives `isStreaming`). */
27
+ onStreamingChange?(streamingId: string | null): void;
28
+ /** Run a callback after the framework has applied the latest render. */
29
+ afterRender(cb: () => void): void;
30
+ /** Reset the composer (clear text/attachments) on conversation swap. */
31
+ resetComposer?(): void;
32
+ }
33
+ export interface AparteChatHostOptions {
34
+ /** Forwarded to `viewport.configure({ layoutTransitionMs })` when > 0. */
35
+ layoutTransitionMs?: number;
36
+ /** Initial conversation id to load when the controller is created. */
37
+ conversationId?: string | null;
38
+ /** Called when the controller lazily creates a conversation on first send. */
39
+ onConversationCreated?: (id: string) => void;
40
+ /**
41
+ * Instance config for this chat. When provided, {@link bind} marks the host
42
+ * element as a `[data-aparte-host]` boundary so every Aparte component inside it
43
+ * (bubbles, composer, renderers) resolves THIS config instead of the global
44
+ * `AparteConfig` — the seam that lets several independently-configured chats
45
+ * coexist on one page. Omit to keep the global-config behaviour.
46
+ */
47
+ config?: AparteConfigClass;
48
+ }
49
+ /**
50
+ * Framework-agnostic chat-host orchestrator.
51
+ *
52
+ * Owns the streaming/branch/host-method layer that previously lived inline in
53
+ * the Angular wrapper: it installs the imperative method surface `AparteClient`
54
+ * calls onto the host element, tracks the streaming target id from
55
+ * `apartemessage*` lifecycle events, guards writes against orphan streams (late
56
+ * SSE after a conversation switch), handles `aparte-path-changed` branch
57
+ * navigation, keeps the viewport's repo in sync before branch ops, and
58
+ * reconciles bubbles via `populateBubbleFromMessage`.
59
+ *
60
+ * It composes — does not replace — `AparteConversationController` (persistence /
61
+ * load / lazy-create) which it instantiates internally from the same binding.
62
+ *
63
+ * Each framework provides an {@link AparteChatHostBinding} over its reactive
64
+ * message list and calls {@link bind} after the view mounts; the framework is
65
+ * responsible for rendering `<aparte-chat-bubble message-id="…">` elements inside
66
+ * the viewport and calling {@link syncBubbles} whenever its message list
67
+ * changes (its idiomatic reactive hook: Angular effect, React effect, Vue
68
+ * watch, Svelte afterUpdate).
69
+ */
70
+ export declare class AparteChatHost {
71
+ private readonly binding;
72
+ private readonly options;
73
+ /** Id of the assistant message currently streaming (null when idle). */
74
+ private _streamingId;
75
+ /** Message ids already reconciled onto a bubble (skip-rerender cache). */
76
+ private readonly _renderedIds;
77
+ /** Sibling info from the last path-change, applied after the next render. */
78
+ private _pendingSiblings?;
79
+ /** Abort handle for an in-flight {@link streamTokens} loop. */
80
+ private _streamAbort?;
81
+ private _conversationId;
82
+ private _controller?;
83
+ private _teardown;
84
+ private _bound;
85
+ constructor(binding: AparteChatHostBinding, options?: AparteChatHostOptions);
86
+ /**
87
+ * Install the host-method surface + event listeners and create the
88
+ * conversation controller. Returns a teardown function; call once after the
89
+ * view (viewport + composer) has mounted.
90
+ */
91
+ bind(): () => void;
92
+ unbind(): void;
93
+ get streamingId(): string | null;
94
+ get isStreaming(): boolean;
95
+ /** The internally-managed conversation controller (created in {@link bind}). */
96
+ get conversationController(): AparteConversationController | undefined;
97
+ /** Clear the bubble-render cache (e.g. when the host clears messages externally). */
98
+ clearRenderCache(): void;
99
+ private _setStreamingId;
100
+ /** Load / switch the active conversation via the controller. */
101
+ setConversationId(id: string | null): Promise<void>;
102
+ private _unbindController?;
103
+ private _createController;
104
+ /** Drop transient streaming state so a new conversation starts clean. */
105
+ private _beginConversationSwap;
106
+ /**
107
+ * Append a message optimistically (streaming writes target the new last).
108
+ *
109
+ * Deliberately does NOT call `onMessagesChange` (unlike the other mutations):
110
+ * `setMessages` updates the wrapper's OWN render list, but `onMessagesChange`
111
+ * is the OUTBOUND "the user changed the list" notification. During an
112
+ * optimistic append the wrapper's local list can lag a controlled parent's
113
+ * (the parent added a user message that hasn't propagated back yet), so
114
+ * echoing the local list to the parent would overwrite the parent's
115
+ * authoritative list and drop that message — a real race the Angular wrapper
116
+ * spec guards ("optimistic-append + parent-push race"). `onMessageAppended`
117
+ * is the append-specific signal instead.
118
+ */
119
+ appendMessage(message: AparteMessage): void;
120
+ /** Atomic partial update of a message by id. */
121
+ updateMessage(messageId: string, updates: Partial<AparteMessage>): void;
122
+ /** Append/replace the last message content (streaming text). */
123
+ updateLastMessage(content: string, options?: {
124
+ append?: boolean;
125
+ }): void;
126
+ /** Add a segment to the last message (immediate bubble + state sync). */
127
+ addSegment(segment: AparteSegment): void;
128
+ /** Update a segment in the last message in place. */
129
+ updateSegment(segmentId: string, updates: Partial<AparteSegment>): void;
130
+ /** Remove a transient segment (e.g. pipeline-waiting indicator). */
131
+ removeSegment(segmentId: string): void;
132
+ /** Append text to a segment's content in the last message. */
133
+ appendToSegment(segmentId: string, content: string): void;
134
+ /** Read the current message list. */
135
+ getMessages(): AparteMessage[];
136
+ /** Clear all messages + reset viewport state. */
137
+ clearMessages(): void;
138
+ /** Create a new branch from a message (returns the new sibling index). */
139
+ addBranch(messageId: string): number;
140
+ /** Add a sibling of an existing message (returns the new id). */
141
+ addSiblingOf(existingId: string, newMessage: AparteMessage): string | null;
142
+ /** Remove a message and all descendants (edit flow). */
143
+ truncateFrom(messageId: string): void;
144
+ /** Keep up to and including a user message, drop later responses (retry). */
145
+ truncateResponsesAfter(userMessageId: string): void;
146
+ /**
147
+ * Drive a manual token stream into the viewport. Sets the streaming guard,
148
+ * appends each token, completes the message at the end. Per-framework
149
+ * wrappers adapt their native stream type (RxJS Observable, AsyncIterable,
150
+ * ReadableStream) into this.
151
+ */
152
+ streamTokens(messageId: string, tokens: AsyncIterable<string>): Promise<void>;
153
+ /** Abort an in-flight {@link streamTokens} loop. */
154
+ stopTokenStream(): void;
155
+ /**
156
+ * Reconcile rendered bubbles with the current message list. The framework
157
+ * calls this from its reactive message-change hook after rendering; the
158
+ * last message is always re-synced (streaming), others only once.
159
+ */
160
+ syncBubbles(): void;
161
+ /**
162
+ * Rebuild the viewport's internal repo from the message list before branch
163
+ * operations (streaming fills the framework state but not the repo).
164
+ */
165
+ syncRepoFromMessages(): void;
166
+ private _applyPendingSiblings;
167
+ /** Orphan-stream guard: a stream is in flight but the last msg isn't it. */
168
+ private _isOrphan;
169
+ private _vp;
170
+ private _bubbleById;
171
+ private _lastBubble;
172
+ private _installHostMethods;
173
+ private _installLifecycleListeners;
174
+ private _installViewportListeners;
175
+ }
176
+ //# sourceMappingURL=aparte-chat-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aparte-chat-host.d.ts","sourceRoot":"","sources":["../../src/host/aparte-chat-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,aAAa,EACb,aAAa,EAIhB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACH,4BAA4B,EAE/B,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAA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2 @@
1
+ export { AparteChatHost, type AparteChatHostBinding, type AparteChatHostOptions, } from './aparte-chat-host.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC7B,MAAM,uBAAuB,CAAC"}