@aparte/core 0.9.0 → 0.10.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/dist/components/bubble/aparte-chat-bubble.d.ts +24 -3
- package/dist/components/bubble/aparte-chat-bubble.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-action.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-add-attachment.d.ts +11 -0
- package/dist/components/composer/aparte-composer-add-attachment.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-cancel.d.ts +8 -0
- package/dist/components/composer/aparte-composer-cancel.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-input.d.ts.map +1 -1
- package/dist/components/composer/aparte-composer-send.d.ts +32 -0
- package/dist/components/composer/aparte-composer-send.d.ts.map +1 -1
- package/dist/components/elicitation/aparte-elicitation.d.ts +10 -0
- package/dist/components/elicitation/aparte-elicitation.d.ts.map +1 -1
- package/dist/components/viewport/aparte-chat-viewport.d.ts +3 -1
- package/dist/components/viewport/aparte-chat-viewport.d.ts.map +1 -1
- package/dist/config/aparte-config.d.ts +34 -1
- package/dist/config/aparte-config.d.ts.map +1 -1
- package/dist/config/config-subscribe.d.ts +4 -0
- package/dist/config/config-subscribe.d.ts.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/locale.d.ts +98 -0
- package/dist/config/locale.d.ts.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/custom-elements.json +4588 -4293
- package/dist/elicitation/panel.d.ts +13 -0
- package/dist/elicitation/panel.d.ts.map +1 -1
- package/dist/host/aparte-chat-host.d.ts +3 -1
- package/dist/host/aparte-chat-host.d.ts.map +1 -1
- package/dist/{index-hQQljwfX.js → index-BnKBciDG.js} +515 -232
- package/dist/index-BnKBciDG.js.map +1 -0
- package/dist/index.css +147 -310
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +248 -87
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +3 -2
- package/dist/index.node.d.ts.map +1 -1
- package/dist/index.node.js +60 -57
- package/dist/index.node.js.map +1 -1
- package/dist/parsers/aparte-stream-parser.d.ts.map +1 -1
- package/dist/renderers/highlight-stream.d.ts +17 -0
- package/dist/renderers/highlight-stream.d.ts.map +1 -0
- package/dist/renderers/segment-renderers.d.ts.map +1 -1
- package/dist/renderers/segments/artifact/binary-file.d.ts.map +1 -1
- package/dist/renderers/segments/artifact/card.d.ts.map +1 -1
- package/dist/renderers/segments/artifact/shared.d.ts +19 -2
- package/dist/renderers/segments/artifact/shared.d.ts.map +1 -1
- package/dist/renderers/segments/code.d.ts.map +1 -1
- package/dist/renderers/segments/error.d.ts.map +1 -1
- package/dist/renderers/segments/pipeline-waiting.d.ts.map +1 -1
- package/dist/renderers/segments/thinking.d.ts.map +1 -1
- package/dist/renderers/segments/tool-call.d.ts.map +1 -1
- package/dist/types/event-map.d.ts +1 -2
- package/dist/types/event-map.d.ts.map +1 -1
- package/dist/types/events.d.ts +0 -22
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models.d.ts +1 -6
- package/dist/types/models.d.ts.map +1 -1
- package/dist/types/segments.d.ts +87 -67
- package/dist/types/segments.d.ts.map +1 -1
- package/dist/utils/segments.d.ts +75 -5
- package/dist/utils/segments.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-hQQljwfX.js.map +0 -1
- package/dist/renderers/segments/file-tree.d.ts +0 -3
- package/dist/renderers/segments/file-tree.d.ts.map +0 -1
- package/dist/renderers/segments/terminal.d.ts +0 -3
- package/dist/renderers/segments/terminal.d.ts.map +0 -1
package/dist/types/segments.d.ts
CHANGED
|
@@ -17,41 +17,88 @@ export interface AparteSegmentBase {
|
|
|
17
17
|
* insertions and removals.
|
|
18
18
|
*/
|
|
19
19
|
index?: number;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Extras the producer of the segment knows — token counts, cost, compute
|
|
22
|
+
* device — plus `aparte`, the one sub-object core writes.
|
|
23
|
+
*
|
|
24
|
+
* Everything except `meta.aparte` is yours: fill it with
|
|
25
|
+
* `updateSegment(segmentId, { meta })`, which MERGES rather than replaces.
|
|
26
|
+
* Mirrors `AparteMessage.metadata`.
|
|
27
|
+
*/
|
|
28
|
+
meta?: Record<string, unknown> & {
|
|
29
|
+
aparte?: AparteSegmentTiming;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What core measured about a segment. Lives in `meta.aparte`, not on the segment.
|
|
34
|
+
*
|
|
35
|
+
* These two were first-class fields, and moving them is not tidying. **No protocol
|
|
36
|
+
* carries a timestamp on a content block** — verified rather than assumed: Anthropic's
|
|
37
|
+
* blocks have none (and neither does the message), OpenAI's `output_text` part is
|
|
38
|
+
* `{annotations, logprobs, text, type}` with `created_at` on the item above it, and the
|
|
39
|
+
* AI SDK's `UIMessage.parts` have none either. What the AI SDK does have is a metadata
|
|
40
|
+
* bag whose canonical example is literally `{ createdAt, model, totalTokens }` — at the
|
|
41
|
+
* message level. A per-block `id` has industry precedent; per-block time has none.
|
|
42
|
+
*
|
|
43
|
+
* So this is a **local measurement**, and the shape says so. It stays typed — the bag is
|
|
44
|
+
* where it belongs, opacity is not part of the deal — and it is namespaced under
|
|
45
|
+
* `aparte` because `meta` is the consumer's: a flat `startedAt` there would collide
|
|
46
|
+
* with a key of their own.
|
|
47
|
+
*
|
|
48
|
+
* Core reads it through {@link segmentDuration} and {@link isSegmentSettled}; it never
|
|
49
|
+
* renders either number.
|
|
50
|
+
*/
|
|
51
|
+
export interface AparteSegmentTiming {
|
|
52
|
+
/** Epoch ms when the segment entered a LIVE transcript. Absent for history. */
|
|
21
53
|
startedAt?: number;
|
|
22
54
|
/**
|
|
23
55
|
* Epoch ms when content last arrived on this segment.
|
|
24
56
|
*
|
|
25
|
-
* It ADVANCES while the segment streams and freezes when the segment settles,
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* never renders either.
|
|
57
|
+
* It ADVANCES while the segment streams and freezes when the segment settles, so
|
|
58
|
+
* `endedAt - startedAt` is a live duration during a turn and a final one after it
|
|
59
|
+
* — ask `isSegmentSettled(segment)` which you are looking at.
|
|
29
60
|
*
|
|
30
61
|
* Why not simply "when it finished": the two obvious rules are both wrong, and
|
|
31
62
|
* measurably. Closing at the end of the turn makes a reasoning block span the
|
|
32
|
-
* whole answer that followed it (2s of thinking before a 20s reply reads
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
63
|
+
* whole answer that followed it (2s of thinking before a 20s reply reads "22s").
|
|
64
|
+
* Closing when the next segment opens is the same error, smaller — a gap of ten
|
|
65
|
+
* seconds before the next segment is counted as thinking, while the person
|
|
66
|
+
* watching knows nothing happened. The last delta is the only moment the segment
|
|
67
|
+
* itself can vouch for.
|
|
37
68
|
*/
|
|
38
69
|
endedAt?: number;
|
|
39
|
-
/**
|
|
40
|
-
* Extras only the producer of the segment can know — token counts, cost,
|
|
41
|
-
* compute device. Core writes nothing here: fill it from an app with
|
|
42
|
-
* `updateSegment(segmentId, { meta })`. Mirrors `AparteMessage.metadata`.
|
|
43
|
-
*/
|
|
44
|
-
meta?: Record<string, unknown>;
|
|
45
70
|
}
|
|
46
71
|
/** Text segment - plain text content */
|
|
47
72
|
export interface AparteTextSegment extends AparteSegmentBase {
|
|
48
73
|
type: 'text';
|
|
49
74
|
content: string;
|
|
50
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Field defaults for one segment TYPE, merged when a segment enters a message.
|
|
78
|
+
*
|
|
79
|
+
* A record and not a `Partial<AparteSegment>` on purpose: the type key is a string,
|
|
80
|
+
* a consumer's own segment type is as valid as a built-in one, and its fields cannot
|
|
81
|
+
* be known here. What CANNOT be defaulted is identity — `id`, `type`, `messageId`,
|
|
82
|
+
* `index`, `startedAt`, `endedAt` are refused, because a default `id` would give
|
|
83
|
+
* every segment in a conversation the same one.
|
|
84
|
+
*/
|
|
85
|
+
export type AparteSegmentDefaults = Readonly<Record<string, unknown>>;
|
|
51
86
|
/** Thinking/reasoning segment - collapsible */
|
|
52
87
|
export interface AparteThinkingSegment extends AparteSegmentBase {
|
|
53
88
|
type: 'thinking';
|
|
54
89
|
content: string;
|
|
90
|
+
/**
|
|
91
|
+
* Open the block. **Absent means CLOSED** — a reasoning block is a disclosure,
|
|
92
|
+
* and the reader opens it.
|
|
93
|
+
*
|
|
94
|
+
* It used to be the other way round: absent meant open, and core's own parser
|
|
95
|
+
* emitted `collapsed: false` on every block it produced, so a reasoning block
|
|
96
|
+
* stayed unfolded for the whole conversation and buried the answer under it. No
|
|
97
|
+
* assistant on the market does that — the content is behind a click, streaming
|
|
98
|
+
* or settled.
|
|
99
|
+
*
|
|
100
|
+
* `false` is still how you open one on purpose. Only ABSENT changed meaning.
|
|
101
|
+
*/
|
|
55
102
|
collapsed?: boolean;
|
|
56
103
|
label?: string;
|
|
57
104
|
}
|
|
@@ -63,56 +110,6 @@ export interface AparteCodeSegment extends AparteSegmentBase {
|
|
|
63
110
|
filename?: string;
|
|
64
111
|
showLineNumbers?: boolean;
|
|
65
112
|
}
|
|
66
|
-
/** Diff segment - before/after code comparison */
|
|
67
|
-
export interface AparteDiffSegment extends AparteSegmentBase {
|
|
68
|
-
type: 'diff';
|
|
69
|
-
filename?: string;
|
|
70
|
-
hunks: AparteDiffHunk[];
|
|
71
|
-
}
|
|
72
|
-
export interface AparteDiffHunk {
|
|
73
|
-
oldStart: number;
|
|
74
|
-
newStart: number;
|
|
75
|
-
lines: AparteDiffLine[];
|
|
76
|
-
}
|
|
77
|
-
export interface AparteDiffLine {
|
|
78
|
-
type: 'add' | 'remove' | 'context';
|
|
79
|
-
content: string;
|
|
80
|
-
}
|
|
81
|
-
/** Terminal/console segment - command execution */
|
|
82
|
-
export interface AparteTerminalSegment extends AparteSegmentBase {
|
|
83
|
-
type: 'terminal';
|
|
84
|
-
command?: string;
|
|
85
|
-
output?: string;
|
|
86
|
-
exitCode?: number;
|
|
87
|
-
isRunning?: boolean;
|
|
88
|
-
}
|
|
89
|
-
/** File tree segment - directory structure */
|
|
90
|
-
export interface AparteFileTreeSegment extends AparteSegmentBase {
|
|
91
|
-
type: 'file-tree';
|
|
92
|
-
files: AparteFileNode[];
|
|
93
|
-
title?: string;
|
|
94
|
-
}
|
|
95
|
-
export interface AparteFileNode {
|
|
96
|
-
name: string;
|
|
97
|
-
path: string;
|
|
98
|
-
type: 'file' | 'directory';
|
|
99
|
-
children?: AparteFileNode[];
|
|
100
|
-
status?: 'added' | 'modified' | 'deleted';
|
|
101
|
-
}
|
|
102
|
-
/** Image segment */
|
|
103
|
-
export interface AparteImageSegment extends AparteSegmentBase {
|
|
104
|
-
type: 'image';
|
|
105
|
-
url: string;
|
|
106
|
-
alt?: string;
|
|
107
|
-
caption?: string;
|
|
108
|
-
}
|
|
109
|
-
/** Preview/iframe segment */
|
|
110
|
-
export interface ApartePreviewSegment extends AparteSegmentBase {
|
|
111
|
-
type: 'preview';
|
|
112
|
-
url: string;
|
|
113
|
-
title?: string;
|
|
114
|
-
height?: number;
|
|
115
|
-
}
|
|
116
113
|
/** Error segment */
|
|
117
114
|
export interface AparteErrorSegment extends AparteSegmentBase {
|
|
118
115
|
type: 'error';
|
|
@@ -187,7 +184,7 @@ export interface ApartePipelineWaitingSegment extends AparteSegmentBase {
|
|
|
187
184
|
type: 'pipeline-waiting';
|
|
188
185
|
}
|
|
189
186
|
/** All built-in segment types */
|
|
190
|
-
export type AparteSegment = AparteTextSegment | AparteThinkingSegment | AparteCodeSegment |
|
|
187
|
+
export type AparteSegment = AparteTextSegment | AparteThinkingSegment | AparteCodeSegment | AparteErrorSegment | AparteProgressSegment | AparteCustomSegment | AparteToolCallSegment | AparteArtifactSegment | ApartePipelineWaitingSegment;
|
|
191
188
|
/** Segment type discriminator values */
|
|
192
189
|
export type AparteSegmentType = AparteSegment['type'];
|
|
193
190
|
/**
|
|
@@ -230,6 +227,29 @@ export interface AparteSegmentRenderer<T extends AparteSegmentBase = AparteSegme
|
|
|
230
227
|
* so the MutationObserver (childList) doesn't fire and scroll stays stable.
|
|
231
228
|
*/
|
|
232
229
|
update?(element: HTMLElement, segment: T): void;
|
|
230
|
+
/**
|
|
231
|
+
* Optional: re-read the CONFIG-DERIVED text of an already-rendered segment —
|
|
232
|
+
* an icon from the icon provider, a label from the locale.
|
|
233
|
+
*
|
|
234
|
+
* Called when the config changes (a language switch, a new icon set), on every
|
|
235
|
+
* segment already on screen. Bound by the same rule as `update()`: **must not
|
|
236
|
+
* add or remove child nodes** — only attributes and textContent — so the
|
|
237
|
+
* viewport's childList observer stays quiet and scroll does not move.
|
|
238
|
+
*
|
|
239
|
+
* This exists because the obvious alternative does not work. Re-rendering the
|
|
240
|
+
* segments container to pick up a new locale destroys state the DOM owns and the
|
|
241
|
+
* segment data does not: a mounted sandboxed artifact preview, a reasoning block
|
|
242
|
+
* the reader expanded by clicking `<summary>` (which never writes back to
|
|
243
|
+
* `collapsed`), scroll position inside a long terminal, the focus on an
|
|
244
|
+
* Approve/Reject gate, and the buffered lookahead of the incremental Markdown
|
|
245
|
+
* parser mid-stream. It also fires container-wide childList mutations, which is
|
|
246
|
+
* exactly what the rule above forbids.
|
|
247
|
+
*
|
|
248
|
+
* Implement it only if the rendered output contains text or icons that came from
|
|
249
|
+
* the config. A renderer whose chrome is entirely its own data — `progress`,
|
|
250
|
+
* `text` — correctly does not, exactly as it does not implement `update()`.
|
|
251
|
+
*/
|
|
252
|
+
relabel?(element: HTMLElement, segment: T): void;
|
|
233
253
|
/**
|
|
234
254
|
* Optional: Cleanup when segment is removed
|
|
235
255
|
* @param element - The DOM element being removed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../src/types/segments.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,wDAAwD;AACxD,MAAM,WAAW,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AE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEhD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjD;;;OAGG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CACxC;AAMD,6DAA6D;AAC7D,MAAM,WAAW,8BAA8B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
package/dist/utils/segments.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* Everything here is pure and DOM-free, so a consumer can test their own wiring in
|
|
28
28
|
* Node — the introspectability half of the reachability rule.
|
|
29
29
|
*/
|
|
30
|
-
import type { AparteSegment } from '../types/index.js';
|
|
30
|
+
import type { AparteSegmentDefaults, AparteSegmentTiming, AparteSegment } from '../types/index.js';
|
|
31
31
|
/**
|
|
32
32
|
* Stamp identity and start time on a segment joining `segments` at the tail.
|
|
33
33
|
*
|
|
@@ -38,7 +38,41 @@ import type { AparteSegment } from '../types/index.js';
|
|
|
38
38
|
* A value already present is never overwritten, so a segment rehydrated from a
|
|
39
39
|
* consumer's storage keeps the numbers it was persisted with.
|
|
40
40
|
*/
|
|
41
|
-
export declare function stampSegmentOnInsert(segments: readonly AparteSegment[], segment: AparteSegment, messageId: string): AparteSegment;
|
|
41
|
+
export declare function stampSegmentOnInsert(segments: readonly AparteSegment[], segment: AparteSegment, messageId: string, defaults?: AparteSegmentDefaults): AparteSegment;
|
|
42
|
+
/**
|
|
43
|
+
* A segment arriving from STORAGE or a server, rather than starting now.
|
|
44
|
+
*
|
|
45
|
+
* The counterpart of {@link stampSegmentOnInsert}, and the reason it exists: the two
|
|
46
|
+
* are not the same act, and treating them as one made the library invent history.
|
|
47
|
+
* `stampSegmentOnInsert` ran on every arrival path including a reload, so a
|
|
48
|
+
* conversation from three weeks ago came back claiming each of its segments had
|
|
49
|
+
* started this second — while THREE other load paths did not stamp at all, so the same
|
|
50
|
+
* stored conversation produced different numbers depending on the mode and on whether
|
|
51
|
+
* a branch tree had been saved. Not a lie so much as an incoherence.
|
|
52
|
+
*
|
|
53
|
+
* What it writes, and why each:
|
|
54
|
+
*
|
|
55
|
+
* - `messageId` and `index` are **recomputed**, not preserved. They are derivable
|
|
56
|
+
* facts about the array this segment is joining, so a stored value can only
|
|
57
|
+
* contradict it — and no protocol persists either (Anthropic's block `index` exists
|
|
58
|
+
* only in the streaming envelope, as a position).
|
|
59
|
+
* - **no time, ever.** A measurement nobody took is absent, not zero and not now.
|
|
60
|
+
* `segmentDuration` already answers `undefined` for that, so a consumer reading
|
|
61
|
+
* through the helper degrades correctly.
|
|
62
|
+
* - `isStreaming: false`, unconditionally. A persisted stream is dead: restoring one
|
|
63
|
+
* with `isStreaming: true` would render a caret forever, and — through
|
|
64
|
+
* `openSegmentIds`, which reads exactly this flag — would have the next turn-close
|
|
65
|
+
* stamp it a brand-new `endedAt`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function adoptSegment(segments: readonly AparteSegment[], segment: AparteSegment, messageId: string): AparteSegment;
|
|
68
|
+
/**
|
|
69
|
+
* Read core's own measurements off a segment.
|
|
70
|
+
*
|
|
71
|
+
* A function rather than a property access because it is read from six places, and
|
|
72
|
+
* `segment.meta?.aparte` spelled six times is six chances to spell it differently —
|
|
73
|
+
* which is exactly how this repo's recurring bug starts.
|
|
74
|
+
*/
|
|
75
|
+
export declare function segmentTiming(segment: Pick<AparteSegment, 'meta'>): AparteSegmentTiming | undefined;
|
|
42
76
|
/**
|
|
43
77
|
* Has this segment settled? The trigger for `endedAt`.
|
|
44
78
|
*
|
|
@@ -76,6 +110,21 @@ export declare function isSegmentSettled(segment: AparteSegment): boolean;
|
|
|
76
110
|
* counter that ticks while a model reasons is the same number, read earlier.
|
|
77
111
|
*/
|
|
78
112
|
export declare function stampSegmentOnUpdate(segment: AparteSegment, updates: Partial<AparteSegment>): Partial<AparteSegment>;
|
|
113
|
+
/**
|
|
114
|
+
* Merge an update into a segment without one writer erasing the other's `meta`.
|
|
115
|
+
*
|
|
116
|
+
* `{ ...segment, ...updates }` is wrong now that `meta` has two writers. A consumer's
|
|
117
|
+
* `updateSegment(id, { meta: { cost } })` is presentation, not activity, so it passes
|
|
118
|
+
* through {@link stampSegmentOnUpdate} untouched — and a plain spread would then
|
|
119
|
+
* replace the whole bag and take `meta.aparte` with it. The measurement would vanish
|
|
120
|
+
* the first time an app wrote a token count, which is precisely when it matters.
|
|
121
|
+
*
|
|
122
|
+
* So the bag is merged one level, and `aparte` inside it merged again. Every site that
|
|
123
|
+
* folds an update into a segment goes through here — the viewport, the host and the
|
|
124
|
+
* bubble each had their own spread, which is three chances to fix this twice and miss
|
|
125
|
+
* once.
|
|
126
|
+
*/
|
|
127
|
+
export declare function mergeSegmentUpdate(segment: AparteSegment, updates: Partial<AparteSegment>): AparteSegment;
|
|
79
128
|
/**
|
|
80
129
|
* How long this segment took, or `undefined` when that is not knowable yet.
|
|
81
130
|
*
|
|
@@ -113,9 +162,7 @@ export declare function segmentDuration(segment: AparteSegment): number | undefi
|
|
|
113
162
|
*
|
|
114
163
|
* Empty once the segment has settled, so a late write cannot move a final end.
|
|
115
164
|
*/
|
|
116
|
-
export declare function stampSegmentActivity(segment: AparteSegment):
|
|
117
|
-
endedAt?: number;
|
|
118
|
-
};
|
|
165
|
+
export declare function stampSegmentActivity(segment: AparteSegment): Partial<AparteSegment>;
|
|
119
166
|
/**
|
|
120
167
|
* The update that forwards a parser-emitted segment's content — carrying the fact
|
|
121
168
|
* that it CLOSED, when it did.
|
|
@@ -162,6 +209,29 @@ export declare function isTerminalStatus(status: string | null | undefined): boo
|
|
|
162
209
|
* re-render, a branch switch, a reloaded conversation — cannot move an end.
|
|
163
210
|
*/
|
|
164
211
|
export declare function openSegmentIds(segments: readonly AparteSegment[]): string[];
|
|
212
|
+
/**
|
|
213
|
+
* Adopt every segment of a message arriving from storage or a server.
|
|
214
|
+
*
|
|
215
|
+
* The message-level counterpart of {@link adoptSegment}, and the reason it exists as a
|
|
216
|
+
* function rather than a loop written four times: there are FOUR entry paths for
|
|
217
|
+
* historical data (`setMessages`, `importTree`, `addMessage`, and the framework host's
|
|
218
|
+
* own list setter) and they disagreed. One stamped and invented a start, one wrote
|
|
219
|
+
* straight to the repository, one did nothing, and the host's `appendMessage` — same
|
|
220
|
+
* name as the viewport's, opposite behaviour — did nothing either. The same stored
|
|
221
|
+
* conversation therefore produced different numbers depending on the mode and on
|
|
222
|
+
* whether a branch tree had been saved.
|
|
223
|
+
*
|
|
224
|
+
* Always returns a NEW object, even for a message with no segments. That looks like a
|
|
225
|
+
* missed optimisation and is the invariant of this whole file: the viewport hands the
|
|
226
|
+
* same object to the repository AND to the framework's list, so sharing one makes the
|
|
227
|
+
* immediate paint and the coalesced write land on the same string twice. Returning the
|
|
228
|
+
* caller's message here doubled every streamed reply — caught by the suite that exists
|
|
229
|
+
* for exactly that bug, within minutes of my writing the shortcut.
|
|
230
|
+
*/
|
|
231
|
+
export declare function adoptMessageSegments<T extends {
|
|
232
|
+
id: string;
|
|
233
|
+
segments?: AparteSegment[];
|
|
234
|
+
}>(message: T): T;
|
|
165
235
|
/**
|
|
166
236
|
* Close the gap a removal left, in place.
|
|
167
237
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../src/utils/segments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../src/utils/segments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH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AO,CAAC,aAAa,CAAC,CAMnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE3E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,EAAE,CAE3E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAA;CAAE,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CASxG;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,IAAI,CAMhE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aparte/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "High-performance AI conversation engine - Zero-dependency Web Components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"//sideEffects": "The BROWSER entry defines the custom elements and imports CSS at module scope, so it must never be tree-shaken; the Node entry (`index.node`) and every other module are pure. Listing them explicitly is what lets a bundler drop the rest — the whole package was implicitly side-effectful before, the only one of the 14 without this field.",
|