@getaster/elements-preview 0.0.0-stage → 0.1.0-preview.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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +6 -2
- package/dist/conversation/session.d.ts +85 -0
- package/dist/conversation/session.js +201 -0
- package/dist/conversation/view.d.ts +100 -0
- package/dist/conversation/view.js +576 -0
- package/dist/hierarchy/hierarchy.d.ts +34 -0
- package/dist/hierarchy/hierarchy.js +93 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +45 -4
- package/styles/conversation.css +115 -0
- package/styles/hierarchy.css +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Aster UI
|
|
2
|
+
Copyright 2026 Aster UI contributors
|
|
3
|
+
|
|
4
|
+
Aster UI source and the separately supplied OData mock WebAssembly binary are
|
|
5
|
+
licensed under the Apache License, Version 2.0. Third-party components retain
|
|
6
|
+
their respective licenses. The binary's attribution inventory and license texts
|
|
7
|
+
are supplied in packages/mock/wasm/; packages include those notices when shipped.
|
|
8
|
+
|
|
9
|
+
Geist and IBM Plex Mono fonts retain their SIL Open Font License notices.
|
|
10
|
+
ECharts is an optional separately loaded third-party runtime.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @getaster/elements-preview
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Aster UI experimental controls (API may change).
|
|
4
|
+
|
|
5
|
+
Documentation: https://ui.getaster.now/docs/guide/library.html
|
|
6
|
+
|
|
7
|
+
Licensed under Apache-2.0. See LICENSE and NOTICE.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Lifetime } from "@getaster/data";
|
|
2
|
+
/** Adapter-provided ordering and boundary cursors; display time is independent. */
|
|
3
|
+
export interface ConversationEntry {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly order: string;
|
|
6
|
+
readonly cursor: string;
|
|
7
|
+
readonly author: string;
|
|
8
|
+
readonly time: string;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly kind?: "message" | "note" | "event";
|
|
11
|
+
readonly discussion?: string;
|
|
12
|
+
readonly contexts?: readonly {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly label: string;
|
|
15
|
+
}[];
|
|
16
|
+
readonly revision?: string;
|
|
17
|
+
readonly data?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export type ConversationTarget = "latest" | {
|
|
20
|
+
readonly entryId: string;
|
|
21
|
+
};
|
|
22
|
+
export interface ConversationWindow {
|
|
23
|
+
readonly entries: readonly ConversationEntry[];
|
|
24
|
+
readonly hasOlder: boolean;
|
|
25
|
+
readonly hasNewer: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface ConversationAdapter {
|
|
28
|
+
open(request: {
|
|
29
|
+
scope: string;
|
|
30
|
+
at: ConversationTarget;
|
|
31
|
+
signal: AbortSignal;
|
|
32
|
+
}): Promise<ConversationWindow>;
|
|
33
|
+
older(request: {
|
|
34
|
+
scope: string;
|
|
35
|
+
before: string;
|
|
36
|
+
signal: AbortSignal;
|
|
37
|
+
}): Promise<ConversationWindow>;
|
|
38
|
+
newer(request: {
|
|
39
|
+
scope: string;
|
|
40
|
+
after: string;
|
|
41
|
+
signal: AbortSignal;
|
|
42
|
+
}): Promise<ConversationWindow>;
|
|
43
|
+
/** Must return the confirmed server entry; replay/idempotency belongs to the adapter. */
|
|
44
|
+
send?(request: {
|
|
45
|
+
scope: string;
|
|
46
|
+
text: string;
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
}): Promise<ConversationEntry>;
|
|
49
|
+
}
|
|
50
|
+
export interface ConversationSessionOptions {
|
|
51
|
+
readonly scope: string;
|
|
52
|
+
readonly title: string;
|
|
53
|
+
readonly adapter: ConversationAdapter;
|
|
54
|
+
readonly maxEntries?: number;
|
|
55
|
+
}
|
|
56
|
+
export type ConversationOperation = "open" | "older" | "newer";
|
|
57
|
+
/** One bounded conversation window and draft. No DOM or implicit read receipts. */
|
|
58
|
+
export declare class ConversationSession {
|
|
59
|
+
#private;
|
|
60
|
+
readonly lifetime: Lifetime;
|
|
61
|
+
readonly scope: string;
|
|
62
|
+
readonly title: string;
|
|
63
|
+
readonly adapter: ConversationAdapter;
|
|
64
|
+
readonly maxEntries: number;
|
|
65
|
+
readonly entries: import("@preact/signals-core").ReadonlySignal<readonly ConversationEntry[]>;
|
|
66
|
+
readonly busy: import("@preact/signals-core").ReadonlySignal<ConversationOperation | undefined>;
|
|
67
|
+
readonly error: import("@preact/signals-core").ReadonlySignal<string | undefined>;
|
|
68
|
+
readonly hasOlder: import("@preact/signals-core").ReadonlySignal<boolean>;
|
|
69
|
+
readonly hasNewer: import("@preact/signals-core").ReadonlySignal<boolean>;
|
|
70
|
+
readonly sending: import("@preact/signals-core").ReadonlySignal<boolean>;
|
|
71
|
+
readonly sendError: import("@preact/signals-core").ReadonlySignal<string | undefined>;
|
|
72
|
+
readonly draft: import("@preact/signals-core").Signal<string>;
|
|
73
|
+
get updateKind(): "history" | "receive";
|
|
74
|
+
constructor(options: ConversationSessionOptions);
|
|
75
|
+
open(at?: ConversationTarget): Promise<boolean>;
|
|
76
|
+
loadOlder(protectedIds?: readonly string[]): Promise<boolean>;
|
|
77
|
+
loadNewer(protectedIds?: readonly string[]): Promise<boolean>;
|
|
78
|
+
retry(protectedIds?: readonly string[]): Promise<boolean>;
|
|
79
|
+
/** Confirmed updates merge by ID. Older revision conflicts must be resolved by the host. */
|
|
80
|
+
receive(entry: ConversationEntry, protectedIds?: readonly string[]): boolean;
|
|
81
|
+
/** Applies a confirmed deletion/access revocation without retaining a hidden copy. */
|
|
82
|
+
remove(entryId: string): void;
|
|
83
|
+
send(protectedIds?: () => readonly string[]): Promise<boolean>;
|
|
84
|
+
dispose(): void;
|
|
85
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Lifetime } from "@getaster/data";
|
|
2
|
+
import { batch, signal } from "@preact/signals-core";
|
|
3
|
+
/** One bounded conversation window and draft. No DOM or implicit read receipts. */
|
|
4
|
+
export class ConversationSession {
|
|
5
|
+
lifetime = new Lifetime();
|
|
6
|
+
scope;
|
|
7
|
+
title;
|
|
8
|
+
adapter;
|
|
9
|
+
maxEntries;
|
|
10
|
+
#entries = signal([]);
|
|
11
|
+
entries = this.#entries;
|
|
12
|
+
#busy = signal(undefined);
|
|
13
|
+
busy = this.#busy;
|
|
14
|
+
#error = signal(undefined);
|
|
15
|
+
error = this.#error;
|
|
16
|
+
#hasOlder = signal(false);
|
|
17
|
+
hasOlder = this.#hasOlder;
|
|
18
|
+
#hasNewer = signal(false);
|
|
19
|
+
hasNewer = this.#hasNewer;
|
|
20
|
+
#sending = signal(false);
|
|
21
|
+
sending = this.#sending;
|
|
22
|
+
#sendError = signal(undefined);
|
|
23
|
+
sendError = this.#sendError;
|
|
24
|
+
draft = signal("");
|
|
25
|
+
#request;
|
|
26
|
+
#generation = 0;
|
|
27
|
+
#retry;
|
|
28
|
+
#send;
|
|
29
|
+
#updateKind = "history";
|
|
30
|
+
get updateKind() { return this.#updateKind; }
|
|
31
|
+
constructor(options) {
|
|
32
|
+
if (!options.scope.trim())
|
|
33
|
+
throw new Error("Conversation scope is required.");
|
|
34
|
+
const maximum = options.maxEntries ?? 120;
|
|
35
|
+
if (!Number.isInteger(maximum) || maximum < 10)
|
|
36
|
+
throw new Error("maxEntries must be an integer of at least 10.");
|
|
37
|
+
this.scope = options.scope;
|
|
38
|
+
this.title = options.title;
|
|
39
|
+
this.adapter = options.adapter;
|
|
40
|
+
this.maxEntries = maximum;
|
|
41
|
+
this.lifetime.defer(() => { this.#generation++; this.#request?.abort(); this.#busy.value = undefined; });
|
|
42
|
+
}
|
|
43
|
+
open(at = "latest") { return this.#load("open", at, []); }
|
|
44
|
+
loadOlder(protectedIds = []) {
|
|
45
|
+
if (!this.#hasOlder.peek() || this.#busy.peek())
|
|
46
|
+
return Promise.resolve(false);
|
|
47
|
+
return this.#load("older", "latest", protectedIds);
|
|
48
|
+
}
|
|
49
|
+
loadNewer(protectedIds = []) {
|
|
50
|
+
if (!this.#hasNewer.peek() || this.#busy.peek())
|
|
51
|
+
return Promise.resolve(false);
|
|
52
|
+
return this.#load("newer", "latest", protectedIds);
|
|
53
|
+
}
|
|
54
|
+
retry(protectedIds) {
|
|
55
|
+
const attempt = this.#retry;
|
|
56
|
+
return attempt ? this.#load(attempt.operation, attempt.at, protectedIds ?? attempt.protectedIds) : Promise.resolve(false);
|
|
57
|
+
}
|
|
58
|
+
/** Confirmed updates merge by ID. Older revision conflicts must be resolved by the host. */
|
|
59
|
+
receive(entry, protectedIds = []) {
|
|
60
|
+
if (this.lifetime.disposed)
|
|
61
|
+
return false;
|
|
62
|
+
validateEntries([entry]);
|
|
63
|
+
const previous = this.#entries.peek();
|
|
64
|
+
const existing = previous.find(item => item.id === entry.id);
|
|
65
|
+
// A notification is not proof that the unloaded gap before it is contiguous.
|
|
66
|
+
if (!existing && this.#hasNewer.peek())
|
|
67
|
+
return false;
|
|
68
|
+
const merged = mergeEntries(previous, [entry]);
|
|
69
|
+
const retained = merged.slice(-this.maxEntries);
|
|
70
|
+
if (protectedIds.some(id => merged.some(item => item.id === id) && !retained.some(item => item.id === id))) {
|
|
71
|
+
this.#hasNewer.value = true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
batch(() => {
|
|
75
|
+
this.#updateKind = "receive";
|
|
76
|
+
if (merged.length > retained.length)
|
|
77
|
+
this.#hasOlder.value = true;
|
|
78
|
+
this.#entries.value = retained;
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/** Applies a confirmed deletion/access revocation without retaining a hidden copy. */
|
|
83
|
+
remove(entryId) {
|
|
84
|
+
if (this.lifetime.disposed)
|
|
85
|
+
return;
|
|
86
|
+
const previous = this.#entries.peek();
|
|
87
|
+
const retained = previous.filter(entry => entry.id !== entryId);
|
|
88
|
+
if (retained.length !== previous.length)
|
|
89
|
+
this.#entries.value = retained;
|
|
90
|
+
}
|
|
91
|
+
send(protectedIds = () => []) {
|
|
92
|
+
if (this.#send)
|
|
93
|
+
return this.#send;
|
|
94
|
+
const send = this.adapter.send, text = this.draft.peek();
|
|
95
|
+
if (!send || !text.trim() || this.lifetime.disposed)
|
|
96
|
+
return Promise.resolve(false);
|
|
97
|
+
this.#sending.value = true;
|
|
98
|
+
this.#sendError.value = undefined;
|
|
99
|
+
const pending = (async () => {
|
|
100
|
+
try {
|
|
101
|
+
const entry = await Promise.resolve().then(() => send.call(this.adapter, { scope: this.scope, text, signal: this.lifetime.signal }));
|
|
102
|
+
if (this.lifetime.disposed)
|
|
103
|
+
return false;
|
|
104
|
+
this.receive(entry, protectedIds());
|
|
105
|
+
if (this.draft.peek() === text)
|
|
106
|
+
this.draft.value = "";
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (!this.lifetime.disposed)
|
|
111
|
+
this.#sendError.value = errorText(error);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
this.#sending.value = false;
|
|
116
|
+
this.#send = undefined;
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
this.#send = pending;
|
|
120
|
+
return pending;
|
|
121
|
+
}
|
|
122
|
+
dispose() { this.lifetime.dispose(); }
|
|
123
|
+
async #load(operation, at, protectedIds) {
|
|
124
|
+
if (this.lifetime.disposed)
|
|
125
|
+
return false;
|
|
126
|
+
this.#request?.abort();
|
|
127
|
+
const request = new AbortController(), generation = ++this.#generation;
|
|
128
|
+
this.#request = request;
|
|
129
|
+
this.#busy.value = operation;
|
|
130
|
+
this.#error.value = undefined;
|
|
131
|
+
const abort = () => request.abort();
|
|
132
|
+
this.lifetime.signal.addEventListener("abort", abort, { once: true });
|
|
133
|
+
try {
|
|
134
|
+
const current = this.#entries.peek();
|
|
135
|
+
let page;
|
|
136
|
+
switch (operation) {
|
|
137
|
+
case "open":
|
|
138
|
+
page = await this.adapter.open({ scope: this.scope, at, signal: request.signal });
|
|
139
|
+
break;
|
|
140
|
+
case "older":
|
|
141
|
+
page = await this.adapter.older({ scope: this.scope, before: current[0].cursor, signal: request.signal });
|
|
142
|
+
break;
|
|
143
|
+
case "newer":
|
|
144
|
+
page = await this.adapter.newer({ scope: this.scope, after: current.at(-1).cursor, signal: request.signal });
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (request.signal.aborted || generation !== this.#generation)
|
|
148
|
+
return false;
|
|
149
|
+
validateEntries(page.entries);
|
|
150
|
+
if (operation === "open" && at !== "latest" && !page.entries.some(entry => entry.id === at.entryId))
|
|
151
|
+
throw new Error("That message is no longer available. Return or open the latest messages.");
|
|
152
|
+
const merged = operation === "open" ? mergeEntries([], page.entries) : mergeEntries(this.#entries.peek(), page.entries);
|
|
153
|
+
let start = operation === "older" ? 0 : Math.max(0, merged.length - this.maxEntries);
|
|
154
|
+
if (operation === "open" && at !== "latest")
|
|
155
|
+
start = Math.max(0, Math.min(merged.findIndex(entry => entry.id === at.entryId) - Math.floor(this.maxEntries / 2), merged.length - this.maxEntries));
|
|
156
|
+
const retained = merged.slice(start, start + this.maxEntries);
|
|
157
|
+
const trimmedOlder = start > 0, trimmedNewer = start + retained.length < merged.length;
|
|
158
|
+
if (operation !== "open" && page.entries.every(entry => this.#entries.peek().some(existing => existing.id === entry.id)) && (operation === "older" ? page.hasOlder : page.hasNewer))
|
|
159
|
+
throw new Error("The history adapter did not advance. Retry after checking its boundary cursor.");
|
|
160
|
+
if (operation !== "open" && protectedIds.some(id => merged.some(entry => entry.id === id) && !retained.some(entry => entry.id === id)))
|
|
161
|
+
throw new Error("Finish reading or editing this message before loading another window.");
|
|
162
|
+
batch(() => {
|
|
163
|
+
this.#updateKind = "history";
|
|
164
|
+
this.#entries.value = retained;
|
|
165
|
+
this.#hasOlder.value = operation === "newer" ? this.#hasOlder.peek() || trimmedOlder : page.hasOlder || trimmedOlder;
|
|
166
|
+
this.#hasNewer.value = operation === "older" ? this.#hasNewer.peek() || trimmedNewer : page.hasNewer || trimmedNewer;
|
|
167
|
+
});
|
|
168
|
+
this.#retry = undefined;
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (!request.signal.aborted && generation === this.#generation) {
|
|
173
|
+
this.#error.value = errorText(error);
|
|
174
|
+
this.#retry = { operation, at, protectedIds };
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
this.lifetime.signal.removeEventListener("abort", abort);
|
|
180
|
+
if (generation === this.#generation) {
|
|
181
|
+
this.#busy.value = undefined;
|
|
182
|
+
this.#request = undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function validateEntries(entries) {
|
|
188
|
+
const ids = new Set();
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
if (!entry.id || !entry.cursor || typeof entry.order !== "string" || typeof entry.text !== "string" || ids.has(entry.id))
|
|
191
|
+
throw new Error("Conversation entries require unique IDs, boundary cursors and text.");
|
|
192
|
+
ids.add(entry.id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function mergeEntries(previous, incoming) {
|
|
196
|
+
const entries = new Map(previous.map(entry => [entry.id, entry]));
|
|
197
|
+
for (const entry of incoming)
|
|
198
|
+
entries.set(entry.id, entry);
|
|
199
|
+
return [...entries.values()].sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
200
|
+
}
|
|
201
|
+
function errorText(error) { return error instanceof Error ? error.message : "The conversation could not be updated."; }
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AsterElement, type View } from "@getaster/elements";
|
|
2
|
+
import type { Command } from "@getaster/data";
|
|
3
|
+
import { ConversationSession, type ConversationEntry, type ConversationSessionOptions } from "./session.ts";
|
|
4
|
+
export interface ConversationPassage {
|
|
5
|
+
readonly scope: string;
|
|
6
|
+
readonly entry: ConversationEntry;
|
|
7
|
+
readonly exact: string;
|
|
8
|
+
readonly start: number;
|
|
9
|
+
readonly end: number;
|
|
10
|
+
}
|
|
11
|
+
export type ConversationEntryRenderer = (entry: ConversationEntry) => View;
|
|
12
|
+
export type ConversationContextProvider = (entry: ConversationEntry, scope: string, signal: AbortSignal) => ConversationSessionOptions | undefined | Promise<ConversationSessionOptions | undefined>;
|
|
13
|
+
export type ConversationPassageProvider = (passage: ConversationPassage, signal: AbortSignal) => ConversationSessionOptions | undefined | Promise<ConversationSessionOptions | undefined>;
|
|
14
|
+
export type ConversationReaderActions = (session: ConversationSession) => readonly Command[];
|
|
15
|
+
export interface ConversationReadingLocation {
|
|
16
|
+
readonly entryId?: string;
|
|
17
|
+
readonly offset: number;
|
|
18
|
+
readonly following: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The independently retained reading region used by ConversationReader. */
|
|
21
|
+
export declare class ConversationPane extends AsterElement {
|
|
22
|
+
#private;
|
|
23
|
+
get session(): ConversationSession | undefined;
|
|
24
|
+
set session(value: ConversationSession | undefined);
|
|
25
|
+
get entryRenderer(): ConversationEntryRenderer | undefined;
|
|
26
|
+
set entryRenderer(value: ConversationEntryRenderer | undefined);
|
|
27
|
+
get contextEnabled(): boolean;
|
|
28
|
+
set contextEnabled(value: boolean);
|
|
29
|
+
get passagesEnabled(): boolean;
|
|
30
|
+
set passagesEnabled(value: boolean);
|
|
31
|
+
get autoLoadHistory(): boolean;
|
|
32
|
+
set autoLoadHistory(value: boolean);
|
|
33
|
+
get focusEnabled(): boolean;
|
|
34
|
+
set focusEnabled(value: boolean);
|
|
35
|
+
get readingOnly(): boolean;
|
|
36
|
+
set readingOnly(value: boolean);
|
|
37
|
+
connectedCallback(): void;
|
|
38
|
+
/** Restore after a hidden region or responsive layout becomes visible. */
|
|
39
|
+
restore(): void;
|
|
40
|
+
focusReading(): void;
|
|
41
|
+
location(): ConversationReadingLocation;
|
|
42
|
+
restoreLocation(location: ConversationReadingLocation): Promise<void>;
|
|
43
|
+
focusSource(entryId: string): void;
|
|
44
|
+
receive(entry: ConversationEntry): boolean;
|
|
45
|
+
reveal(entryId: string): void;
|
|
46
|
+
protected render(): View;
|
|
47
|
+
protected updated(): void;
|
|
48
|
+
}
|
|
49
|
+
/** Root session is borrowed. Context sessions created through providers are owned. */
|
|
50
|
+
export declare class ConversationReader extends AsterElement {
|
|
51
|
+
#private;
|
|
52
|
+
static readonly tag = "aster-conversation-reader";
|
|
53
|
+
static readonly contract: Readonly<{
|
|
54
|
+
session: Omit<import("@getaster/elements").CompositeType<ConversationSession>, "validate"> & import("@getaster/elements").CompositeType<ConversationSession | undefined> & {
|
|
55
|
+
readonly optional: true;
|
|
56
|
+
};
|
|
57
|
+
contextProvider: Omit<import("@getaster/elements").CompositeType<ConversationContextProvider>, "validate"> & import("@getaster/elements").CompositeType<ConversationContextProvider | undefined> & {
|
|
58
|
+
readonly optional: true;
|
|
59
|
+
};
|
|
60
|
+
passageProvider: Omit<import("@getaster/elements").CompositeType<ConversationPassageProvider>, "validate"> & import("@getaster/elements").CompositeType<ConversationPassageProvider | undefined> & {
|
|
61
|
+
readonly optional: true;
|
|
62
|
+
};
|
|
63
|
+
entryRenderer: Omit<import("@getaster/elements").CompositeType<ConversationEntryRenderer>, "validate"> & import("@getaster/elements").CompositeType<ConversationEntryRenderer | undefined> & {
|
|
64
|
+
readonly optional: true;
|
|
65
|
+
};
|
|
66
|
+
autoLoadHistory: Omit<import("@getaster/elements").CompositeType<boolean>, "validate"> & import("@getaster/elements").CompositeType<boolean | undefined> & {
|
|
67
|
+
readonly optional: true;
|
|
68
|
+
};
|
|
69
|
+
focusModeEnabled: Omit<import("@getaster/elements").CompositeType<boolean>, "validate"> & import("@getaster/elements").CompositeType<boolean | undefined> & {
|
|
70
|
+
readonly optional: true;
|
|
71
|
+
};
|
|
72
|
+
readerActions: Omit<import("@getaster/elements").CompositeType<ConversationReaderActions>, "validate"> & import("@getaster/elements").CompositeType<ConversationReaderActions | undefined> & {
|
|
73
|
+
readonly optional: true;
|
|
74
|
+
};
|
|
75
|
+
}>;
|
|
76
|
+
get session(): ConversationSession | undefined;
|
|
77
|
+
set session(value: ConversationSession | undefined);
|
|
78
|
+
get contextProvider(): ConversationContextProvider | undefined;
|
|
79
|
+
set contextProvider(value: ConversationContextProvider | undefined);
|
|
80
|
+
get passageProvider(): ConversationPassageProvider | undefined;
|
|
81
|
+
set passageProvider(value: ConversationPassageProvider | undefined);
|
|
82
|
+
get entryRenderer(): ConversationEntryRenderer | undefined;
|
|
83
|
+
set entryRenderer(value: ConversationEntryRenderer | undefined);
|
|
84
|
+
get autoLoadHistory(): boolean;
|
|
85
|
+
set autoLoadHistory(value: boolean);
|
|
86
|
+
get focusModeEnabled(): boolean;
|
|
87
|
+
set focusModeEnabled(value: boolean);
|
|
88
|
+
get readerActions(): ConversationReaderActions | undefined;
|
|
89
|
+
set readerActions(value: ConversationReaderActions | undefined);
|
|
90
|
+
get contextCount(): number;
|
|
91
|
+
/** Routes confirmed notifications through the viewport's focus/selection protection. */
|
|
92
|
+
receive(scope: string, entry: ConversationEntry): boolean;
|
|
93
|
+
connectedCallback(): void;
|
|
94
|
+
/** Opens a reading-only view of the active discussion or an explicitly retained scope. */
|
|
95
|
+
showReader(scope?: string | undefined, opener?: HTMLElement | null): void;
|
|
96
|
+
closeReader(): void;
|
|
97
|
+
returnToSource(): void;
|
|
98
|
+
protected render(): View;
|
|
99
|
+
protected updated(): void;
|
|
100
|
+
}
|