@fungi.computer/parakeet 0.11.38 → 0.12.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.
@@ -3,6 +3,48 @@ import { seedSessionQuery } from "./headless.js";
3
3
  import { createShiitakeClient, } from "@fungi.computer/shiitake/client";
4
4
  import { ShiitakeError } from "@fungi.computer/shiitake";
5
5
  import { EventSource as EventSourceImplementation, } from "eventsource";
6
+ /** How long a closing conversation waits for its sends to settle. */
7
+ const sendSettleLimitMs = 30_000;
8
+ /**
9
+ * Track the sends a conversation's Session has in flight, so closing it never
10
+ * aborts one: its client and transport close only once those have settled.
11
+ * Every call is forwarded unchanged; a hung send is given up on after a limit.
12
+ */
13
+ function trackSends(session) {
14
+ const inFlight = new Set();
15
+ const note = (sent) => {
16
+ const ended = sent.then(() => {
17
+ inFlight.delete(ended);
18
+ }, () => {
19
+ inFlight.delete(ended);
20
+ });
21
+ inFlight.add(ended);
22
+ };
23
+ function command(input) {
24
+ const sent = session.command(input);
25
+ note(sent);
26
+ return sent;
27
+ }
28
+ return {
29
+ session: {
30
+ ...session,
31
+ command,
32
+ withdraw: (requestId) => {
33
+ const sent = session.withdraw(requestId);
34
+ note(sent);
35
+ return sent;
36
+ },
37
+ },
38
+ settled: async () => {
39
+ let timer;
40
+ const limit = new Promise((resolve) => {
41
+ timer = setTimeout(resolve, sendSettleLimitMs);
42
+ });
43
+ await Promise.race([Promise.all(inFlight), limit]);
44
+ clearTimeout(timer);
45
+ },
46
+ };
47
+ }
6
48
  /** Seed Parakeet's shared query with the bounded read before mounting its watch. */
7
49
  function prepareConversation(queryClient, session) {
8
50
  let cancelled = false;
@@ -107,11 +149,15 @@ export function createConversationOpeningOwner(options) {
107
149
  eventSource: eventSourceFor(transport.fetch),
108
150
  fetch: transport.fetch,
109
151
  });
110
- const session = client.session(sessionId);
152
+ const tracking = trackSends(client.session(sessionId));
153
+ const session = tracking.session;
111
154
  const observation = prepareConversation(queryClient, session);
112
155
  openedClose = () => {
113
156
  observation.close();
114
- void Promise.allSettled([client.close(), transport.close()]);
157
+ // A send in flight is never aborted by a view change.
158
+ void tracking
159
+ .settled()
160
+ .then(() => Promise.allSettled([client.close(), transport.close()]));
115
161
  };
116
162
  await observation.ready;
117
163
  if (options.reportsSelection !== false) {
@@ -0,0 +1,218 @@
1
+ import type { AppRoot } from "@fungi.computer/agar";
2
+ import type { QueryClient } from "@tanstack/react-query";
3
+ import type { ShiitakeSession } from "@fungi.computer/shiitake/client";
4
+ import { type OpenConversation, type OpeningServices } from "./conversation-opening.js";
5
+ import type { ParakeetSession } from "./headless.js";
6
+ /**
7
+ * Which conversation is in view, decided in one place.
8
+ *
9
+ * Several things can ask Grove to show a conversation: the person (a row, New
10
+ * conversation, a starter), the host (an open request), the route (a history
11
+ * echo or back/forward) and Grove itself (the first conversation it opens when
12
+ * there is nothing to pick up). Each used to act on its own, so any of them
13
+ * could win a race and swap the pane under someone who was already typing.
14
+ *
15
+ * This reducer is the single owner. Its rules:
16
+ *
17
+ * 1. A person's or the host's choice beats every automatic cause, and the
18
+ * newest such choice wins. It also voids any Session still being created.
19
+ * 2. Auto-open starts only from `none`: nothing in view, nothing opening,
20
+ * nothing being created.
21
+ * 3. The route mirrors the view. A route change naming what is in view or
22
+ * opening is a no-op, and while a choice's own route echo is outstanding,
23
+ * other route values are stale echoes and are ignored.
24
+ * 4. The view only ever shows a Session that has finished opening, so a
25
+ * composer is bound to the `open` Session; while another is `opening`, the
26
+ * pane is not typeable.
27
+ */
28
+ export type ConversationTarget = Readonly<{
29
+ agentId: string;
30
+ sessionId: string;
31
+ }>;
32
+ /** Who asked for a conversation to be shown. */
33
+ export type ViewCause = "person" | "host" | "route" | "auto";
34
+ export type ConversationView<Conversation extends ConversationTarget = ConversationTarget> = Readonly<{
35
+ kind: "none";
36
+ }> | Readonly<{
37
+ kind: "opening";
38
+ target: ConversationTarget;
39
+ cause: ViewCause;
40
+ /** What stays in view if opening fails. */
41
+ previous: Conversation | null;
42
+ }> | Readonly<{
43
+ kind: "open";
44
+ conversation: Conversation;
45
+ }>;
46
+ export type ViewState<Conversation extends ConversationTarget = ConversationTarget> = Readonly<{
47
+ view: ConversationView<Conversation>;
48
+ /** A Session being created, and why. Superseded when a choice is made. */
49
+ creating: Readonly<{
50
+ ticket: number;
51
+ cause: "person" | "auto";
52
+ }> | null;
53
+ /**
54
+ * The route value the latest choice is still waiting to see echoed. A
55
+ * target: the route is to become it. `null`: the route is to leave a
56
+ * conversation. `undefined`: nothing outstanding.
57
+ */
58
+ awaitingRoute: ConversationTarget | null | undefined;
59
+ /** The route as last observed, so a navigation to it is never requested. */
60
+ route: ConversationTarget | null;
61
+ nextTicket: number;
62
+ }>;
63
+ export type ViewEvent<Conversation extends ConversationTarget = ConversationTarget> = Readonly<{
64
+ type: "select";
65
+ target: ConversationTarget;
66
+ cause: "person" | "host";
67
+ }> | Readonly<{
68
+ type: "route";
69
+ target: ConversationTarget | null;
70
+ }>
71
+ /**
72
+ * A navigation the view asked for has finished, and the router now shows
73
+ * `target`. The router emits no route change when it was already there or
74
+ * when a newer navigation replaced this one, so this settles the wait.
75
+ */
76
+ | Readonly<{
77
+ type: "route-confirmed";
78
+ target: ConversationTarget | null;
79
+ }> | Readonly<{
80
+ type: "create";
81
+ cause: "person" | "auto";
82
+ }> | Readonly<{
83
+ type: "created";
84
+ ticket: number;
85
+ target: ConversationTarget;
86
+ }> | Readonly<{
87
+ type: "create-failed";
88
+ ticket: number;
89
+ }> | Readonly<{
90
+ type: "opened";
91
+ conversation: Conversation;
92
+ }> | Readonly<{
93
+ type: "open-failed";
94
+ }>
95
+ /** Leave the conversation: deleted, or a website took the pane. */
96
+ | Readonly<{
97
+ type: "leave";
98
+ navigate: boolean;
99
+ }>
100
+ /** The opener changed: nothing it opened is in view any more. */
101
+ | Readonly<{
102
+ type: "reset";
103
+ }>;
104
+ export type ViewEffect = Readonly<{
105
+ type: "open";
106
+ target: ConversationTarget;
107
+ fromHost: boolean;
108
+ }> | Readonly<{
109
+ type: "clear";
110
+ }> | Readonly<{
111
+ type: "navigate";
112
+ target: ConversationTarget | null;
113
+ }>;
114
+ export type ViewTransition<Conversation extends ConversationTarget = ConversationTarget> = Readonly<{
115
+ state: ViewState<Conversation>;
116
+ effects: readonly ViewEffect[];
117
+ /** For `create` and `created`: whether the event took effect. */
118
+ accepted: boolean;
119
+ /** For `create`: the ticket to report the Session's creation under. */
120
+ ticket: number | null;
121
+ }>;
122
+ export declare const initialViewState: ViewState<never>;
123
+ /** The one transition function for the in-view conversation. */
124
+ export declare function transition<Conversation extends ConversationTarget>(state: ViewState<Conversation>, event: ViewEvent<Conversation>): ViewTransition<Conversation>;
125
+ /** The conversation the view shows: the open one, or the one being left. */
126
+ export declare function shownConversation<Conversation extends ConversationTarget>(state: ViewState<Conversation>): Conversation | null;
127
+ /** The conversation being opened, if one is. */
128
+ export declare function openingTarget(state: ViewState): ConversationTarget | null;
129
+ /** What a host reads from the view, replaced as a whole on every change. */
130
+ export type ConversationViewSnapshot<Session extends ParakeetSession = ShiitakeSession> = Readonly<{
131
+ state: ViewState<OpenConversation<Session>>;
132
+ /** Why the last opening failed, until the next one starts. */
133
+ error: string | null;
134
+ }>;
135
+ export type ConversationViewOptions<Session extends ParakeetSession = ShiitakeSession> = Readonly<{
136
+ connection: Pick<AppRoot, "capabilities"> & {
137
+ ui: Pick<AppRoot["ui"], "reportAgentSessionSelection">;
138
+ };
139
+ queryClient: QueryClient;
140
+ services: OpeningServices<Session>;
141
+ /**
142
+ * Mirror the view into a route. Resolves when the navigation has finished,
143
+ * whether or not the router changed anything.
144
+ */
145
+ navigate?: ((target: ConversationTarget | null) => Promise<void>) | undefined;
146
+ /** The route the router shows now; read once a navigation has finished. */
147
+ shownRoute?: (() => ConversationTarget | null) | undefined;
148
+ }>;
149
+ /**
150
+ * The one owner of "which conversation is in view" and of opening it: the
151
+ * reducer above, the opener that reads and watches a Session, and the route
152
+ * mirror. A host dispatches intents and reads {@link snapshot}; it keeps no
153
+ * selection of its own.
154
+ */
155
+ export declare function createConversationView<Session extends ParakeetSession = ShiitakeSession>(options: ConversationViewOptions<Session>): {
156
+ snapshot: () => Readonly<{
157
+ state: Readonly<{
158
+ view: ConversationView<Readonly<{
159
+ agentId: string;
160
+ sessionId: string;
161
+ session: Session;
162
+ }>>;
163
+ /** A Session being created, and why. Superseded when a choice is made. */
164
+ creating: Readonly<{
165
+ ticket: number;
166
+ cause: "person" | "auto";
167
+ }> | null;
168
+ /**
169
+ * The route value the latest choice is still waiting to see echoed. A
170
+ * target: the route is to become it. `null`: the route is to leave a
171
+ * conversation. `undefined`: nothing outstanding.
172
+ */
173
+ awaitingRoute: Readonly<{
174
+ agentId: string;
175
+ sessionId: string;
176
+ }> | null | undefined;
177
+ /** The route as last observed, so a navigation to it is never requested. */
178
+ route: Readonly<{
179
+ agentId: string;
180
+ sessionId: string;
181
+ }> | null;
182
+ nextTicket: number;
183
+ }>;
184
+ /** Why the last opening failed, until the next one starts. */
185
+ error: string | null;
186
+ }>;
187
+ subscribe: (listener: () => void) => () => void;
188
+ /** A person or the host chose a conversation. */
189
+ select: (target: ConversationTarget, cause?: "person" | "host") => {
190
+ accepted: boolean;
191
+ ticket: number | null;
192
+ };
193
+ /** The router now shows `target`, or the list when null. */
194
+ observeRoute: (target: ConversationTarget | null) => {
195
+ accepted: boolean;
196
+ ticket: number | null;
197
+ };
198
+ /** A Session is about to be created; report it under the ticket returned. */
199
+ create: (cause?: "person" | "auto") => {
200
+ accepted: boolean;
201
+ ticket: number | null;
202
+ };
203
+ created: (ticket: number, target: ConversationTarget) => {
204
+ accepted: boolean;
205
+ ticket: number | null;
206
+ };
207
+ createFailed: (ticket: number) => {
208
+ accepted: boolean;
209
+ ticket: number | null;
210
+ };
211
+ /** Leave the conversation (deleted, or something else took the pane). */
212
+ leave: (navigate: boolean) => {
213
+ accepted: boolean;
214
+ ticket: number | null;
215
+ };
216
+ close: () => void;
217
+ };
218
+ export type ConversationViewOwner = ReturnType<typeof createConversationView>;
@@ -0,0 +1,286 @@
1
+ import { createConversationOpeningOwner, } from "./conversation-opening.js";
2
+ export const initialViewState = {
3
+ view: { kind: "none" },
4
+ creating: null,
5
+ awaitingRoute: undefined,
6
+ route: null,
7
+ nextTicket: 1,
8
+ };
9
+ const same = (left, right) => left === right ||
10
+ (!!left &&
11
+ !!right &&
12
+ left.agentId === right.agentId &&
13
+ left.sessionId === right.sessionId);
14
+ /**
15
+ * Make the route show `desired`. A navigation is asked for only when the route
16
+ * is not already there, or when an earlier one is still outstanding and must be
17
+ * overridden; the wait is set only when one is asked for.
18
+ */
19
+ function follow(state, desired) {
20
+ const needed = state.awaitingRoute !== undefined || !same(state.route, desired);
21
+ return needed
22
+ ? {
23
+ awaitingRoute: desired,
24
+ effects: [{ type: "navigate", target: desired }],
25
+ }
26
+ : { awaitingRoute: undefined, effects: [] };
27
+ }
28
+ /** The conversation the view shows or is opening, if any. */
29
+ function viewTarget(view) {
30
+ if (view.kind === "opening")
31
+ return view.target;
32
+ if (view.kind === "open")
33
+ return view.conversation;
34
+ return null;
35
+ }
36
+ function previousOf(view) {
37
+ return view.kind === "open"
38
+ ? view.conversation
39
+ : view.kind === "opening"
40
+ ? view.previous
41
+ : null;
42
+ }
43
+ function result(state, effects = [], accepted = true, ticket = null) {
44
+ return { state, effects, accepted, ticket };
45
+ }
46
+ function choose(state, target, cause) {
47
+ const shown = viewTarget(state.view);
48
+ const fromHost = cause === "host";
49
+ // Re-choosing what is already in view or opening changes nothing, but it
50
+ // still voids a Session being created and makes the route mirror it.
51
+ if (same(shown, target)) {
52
+ const route = follow(state, target);
53
+ return result({ ...state, creating: null, awaitingRoute: route.awaitingRoute }, route.effects);
54
+ }
55
+ // Returning to the conversation that is still open cancels the opening: the
56
+ // opener drops its pending Session and keeps this one.
57
+ const staying = previousOf(state.view);
58
+ if (cause !== "route" && staying !== null && same(staying, target)) {
59
+ const route = follow(state, target);
60
+ return result({
61
+ ...state,
62
+ view: { kind: "open", conversation: staying },
63
+ creating: null,
64
+ awaitingRoute: route.awaitingRoute,
65
+ }, [{ type: "open", target, fromHost }, ...route.effects]);
66
+ }
67
+ const route = cause === "route" ? null : follow(state, target);
68
+ return result({
69
+ ...state,
70
+ view: {
71
+ kind: "opening",
72
+ target,
73
+ cause,
74
+ previous: previousOf(state.view),
75
+ },
76
+ creating: null,
77
+ awaitingRoute: route ? route.awaitingRoute : undefined,
78
+ }, [{ type: "open", target, fromHost }, ...(route ? route.effects : [])]);
79
+ }
80
+ /** The one transition function for the in-view conversation. */
81
+ export function transition(state, event) {
82
+ switch (event.type) {
83
+ case "select":
84
+ return choose(state, event.target, event.cause);
85
+ case "route": {
86
+ // Whatever it means, this is where the router is now.
87
+ const observed = { ...state, route: event.target };
88
+ const awaiting = observed.awaitingRoute;
89
+ if (awaiting !== undefined) {
90
+ // A choice's own echo is outstanding: it settles the wait; anything
91
+ // else is the route as it was before that choice.
92
+ return result(same(awaiting, event.target)
93
+ ? { ...observed, awaitingRoute: undefined }
94
+ : observed);
95
+ }
96
+ if (event.target === null) {
97
+ // Nothing to leave when nothing is in view, and a Session still being
98
+ // created by a person is about to take the pane.
99
+ if (observed.view.kind === "none" ||
100
+ observed.creating?.cause === "person")
101
+ return result(observed);
102
+ return result({ ...observed, view: { kind: "none" }, creating: null }, [
103
+ { type: "clear" },
104
+ ]);
105
+ }
106
+ if (same(viewTarget(observed.view), event.target))
107
+ return result(observed);
108
+ // Back/forward or a deep link, with no person's choice in flight.
109
+ if (observed.creating?.cause === "person")
110
+ return result(observed);
111
+ return choose(observed, event.target, "route");
112
+ }
113
+ case "route-confirmed": {
114
+ // The router finished a navigation the view asked for. It emits no route
115
+ // change when it was already there or a newer navigation replaced this
116
+ // one, so only the wait for what it now shows is over.
117
+ const confirmed = { ...state, route: event.target };
118
+ return result(same(confirmed.awaitingRoute, event.target)
119
+ ? { ...confirmed, awaitingRoute: undefined }
120
+ : confirmed);
121
+ }
122
+ case "create": {
123
+ if (event.cause === "auto") {
124
+ const idle = state.view.kind === "none" &&
125
+ state.creating === null &&
126
+ state.awaitingRoute === undefined;
127
+ if (!idle)
128
+ return result(state, [], false);
129
+ }
130
+ const ticket = state.nextTicket;
131
+ return result({
132
+ ...state,
133
+ creating: { ticket, cause: event.cause },
134
+ nextTicket: ticket + 1,
135
+ }, [], true, ticket);
136
+ }
137
+ case "created": {
138
+ // A Session whose request was superseded is simply not shown, and an
139
+ // automatic one never displaces what is in view or opening.
140
+ if (state.creating?.ticket !== event.ticket)
141
+ return result(state, [], false);
142
+ const cause = state.creating.cause;
143
+ if (cause === "auto" && state.view.kind !== "none")
144
+ return result({ ...state, creating: null }, [], false);
145
+ return choose({ ...state, creating: null }, event.target, cause);
146
+ }
147
+ case "create-failed":
148
+ return state.creating?.ticket === event.ticket
149
+ ? result({ ...state, creating: null })
150
+ : result(state, [], false);
151
+ case "opened": {
152
+ const view = state.view;
153
+ if (view.kind !== "opening" || !same(view.target, event.conversation))
154
+ return result(state, [], false);
155
+ return result({
156
+ ...state,
157
+ view: { kind: "open", conversation: event.conversation },
158
+ });
159
+ }
160
+ case "open-failed": {
161
+ const view = state.view;
162
+ if (view.kind !== "opening")
163
+ return result(state, [], false);
164
+ // Back to what was open, with the route following it: only if the route
165
+ // has actually left it (or an earlier navigation is still outstanding).
166
+ const back = view.previous;
167
+ const route = follow(state, back);
168
+ return result({
169
+ ...state,
170
+ view: back ? { kind: "open", conversation: back } : { kind: "none" },
171
+ awaitingRoute: route.awaitingRoute,
172
+ }, route.effects);
173
+ }
174
+ case "leave": {
175
+ const route = event.navigate ? follow(state, null) : null;
176
+ return result({
177
+ ...state,
178
+ view: { kind: "none" },
179
+ creating: null,
180
+ awaitingRoute: route ? route.awaitingRoute : undefined,
181
+ }, [{ type: "clear" }, ...(route ? route.effects : [])]);
182
+ }
183
+ case "reset":
184
+ return result({
185
+ ...state,
186
+ view: { kind: "none" },
187
+ creating: null,
188
+ awaitingRoute: undefined,
189
+ });
190
+ }
191
+ }
192
+ /** The conversation the view shows: the open one, or the one being left. */
193
+ export function shownConversation(state) {
194
+ return previousOf(state.view);
195
+ }
196
+ /** The conversation being opened, if one is. */
197
+ export function openingTarget(state) {
198
+ return state.view.kind === "opening" ? state.view.target : null;
199
+ }
200
+ /**
201
+ * The one owner of "which conversation is in view" and of opening it: the
202
+ * reducer above, the opener that reads and watches a Session, and the route
203
+ * mirror. A host dispatches intents and reads {@link snapshot}; it keeps no
204
+ * selection of its own.
205
+ */
206
+ export function createConversationView(options) {
207
+ let snapshot = {
208
+ state: initialViewState,
209
+ error: null,
210
+ };
211
+ let closed = false;
212
+ const listeners = new Set();
213
+ const publish = (next) => {
214
+ snapshot = { ...snapshot, ...next };
215
+ for (const listener of listeners)
216
+ listener();
217
+ };
218
+ const opener = createConversationOpeningOwner({
219
+ connection: options.connection,
220
+ queryClient: options.queryClient,
221
+ services: options.services,
222
+ onPending: () => undefined,
223
+ onConversation: (conversation) => {
224
+ if (conversation !== null)
225
+ dispatch({ type: "opened", conversation });
226
+ },
227
+ onError: (message) => {
228
+ publish({ error: message });
229
+ if (message !== null)
230
+ dispatch({ type: "open-failed" });
231
+ },
232
+ });
233
+ const run = (effect) => {
234
+ if (effect.type === "open")
235
+ opener.select(effect.target.agentId, effect.target.sessionId, effect.fromHost);
236
+ else if (effect.type === "clear")
237
+ opener.clear();
238
+ else if (options.navigate !== undefined) {
239
+ // The router emits no route change when it was already there or a newer
240
+ // navigation replaced this one, so its settling is reported either way.
241
+ const settled = () => {
242
+ dispatch({
243
+ type: "route-confirmed",
244
+ target: options.shownRoute?.() ?? null,
245
+ });
246
+ };
247
+ void options.navigate(effect.target).then(settled, settled);
248
+ }
249
+ };
250
+ function dispatch(event) {
251
+ if (closed)
252
+ return { accepted: false, ticket: null };
253
+ const next = transition(snapshot.state, event);
254
+ publish({ state: next.state });
255
+ for (const effect of next.effects)
256
+ run(effect);
257
+ return { accepted: next.accepted, ticket: next.ticket };
258
+ }
259
+ return {
260
+ snapshot: () => snapshot,
261
+ subscribe: (listener) => {
262
+ listeners.add(listener);
263
+ return () => {
264
+ listeners.delete(listener);
265
+ };
266
+ },
267
+ /** A person or the host chose a conversation. */
268
+ select: (target, cause = "person") => dispatch({ type: "select", target, cause }),
269
+ /** The router now shows `target`, or the list when null. */
270
+ observeRoute: (target) => dispatch({ type: "route", target }),
271
+ /** A Session is about to be created; report it under the ticket returned. */
272
+ create: (cause = "person") => dispatch({ type: "create", cause }),
273
+ created: (ticket, target) => dispatch({ type: "created", ticket, target }),
274
+ createFailed: (ticket) => dispatch({ type: "create-failed", ticket }),
275
+ /** Leave the conversation (deleted, or something else took the pane). */
276
+ leave: (navigate) => dispatch({ type: "leave", navigate }),
277
+ close: () => {
278
+ if (closed)
279
+ return;
280
+ dispatch({ type: "reset" });
281
+ closed = true;
282
+ opener.close();
283
+ listeners.clear();
284
+ },
285
+ };
286
+ }
package/dist/parakeet.js CHANGED
@@ -146,6 +146,9 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
146
146
  getScrollElement: () => scrollerRef.current,
147
147
  initialRect: { height: 800, width: 800 },
148
148
  overscan: 6,
149
+ // A last row that grows can leave the scroller a few pixels short of the
150
+ // end before the container catches up; that is still the end.
151
+ scrollEndThreshold: 32,
149
152
  useFlushSync: false,
150
153
  });
151
154
  const virtualItems = timeline.getVirtualItems();
@@ -174,22 +177,22 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
174
177
  loadOlderHistory();
175
178
  }
176
179
  }, [hasMoreHistory, loadOlderHistory, loadingOlderHistory, nearTop]);
177
- // The end of a pinned window is the reader's intent to continue toward the
178
- // latest output, however they got there: wheel, scrollbar drag or End key.
179
- // Each newer page lands below the viewport, and the live tail's rows measure
180
- // after the window resets, so keep scrolling to the end until the reader
181
- // takes the scroller back (wheel up, pointer or a key other than End).
180
+ // Reaching the end of the timeline, however the reader got there (wheel,
181
+ // scrollbar drag or End key), is the choice to follow the latest output:
182
+ // newer pages land below the viewport and the live tail's rows measure
183
+ // after the window resets. Only the reader ends it (wheel up, pointer or a
184
+ // key other than End), never a measurement or a clamped scroll correction.
182
185
  const followingToLatest = useRef(false);
186
+ const totalSize = timeline.getTotalSize();
183
187
  useEffect(() => {
184
188
  if (loadingOlderHistory)
185
189
  return;
186
- if (atBottom && hasNewerHistory) {
190
+ if (atBottom)
187
191
  followingToLatest.current = true;
192
+ if (atBottom && hasNewerHistory)
188
193
  loadNewerHistory();
189
- }
190
- else if (followingToLatest.current && !atBottom) {
191
- timeline.scrollToEnd({ behavior: "smooth" });
192
- }
194
+ else if (followingToLatest.current)
195
+ timeline.scrollToEnd();
193
196
  }, [
194
197
  atBottom,
195
198
  count,
@@ -197,6 +200,7 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
197
200
  loadNewerHistory,
198
201
  loadingOlderHistory,
199
202
  timeline,
203
+ totalSize,
200
204
  ]);
201
205
  const jumpToBottom = useCallback(() => {
202
206
  setUnread(0);
@@ -206,7 +210,10 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
206
210
  }, [timeline, timelineController]);
207
211
  return (_jsxs("div", { className: "prose relative min-h-0 flex-1", children: [_jsx("div", { "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: sessionReadout(sessionStatus.status, sessionStatus.viewState) }), sessionStatus.observation.status === "unavailable" ? (_jsxs("div", { className: "flex items-center justify-between gap-2 px-3 py-1 text-xs text-dim", role: "status", children: [_jsx("span", { children: sessionStatus.observation.reason }), _jsx(Button, { variant: "outline", size: "xs", onClick: () => void sessionStatus.reconnect(), type: "button", children: "Reconnect" })] })) : null, _jsxs("div", { className: "h-full min-h-0 overflow-y-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset caps-focus-color", "data-chat-scroller": true, ref: scrollerRef, onScroll: (event) => {
208
212
  const top = event.currentTarget.scrollTop;
209
- if (previousScrollTop.current !== undefined &&
213
+ // Scrolling up is the reader's only while they are not following:
214
+ // a correction the library makes while following is not.
215
+ if (!followingToLatest.current &&
216
+ previousScrollTop.current !== undefined &&
210
217
  top < previousScrollTop.current)
211
218
  timelineController.pinVisibleHistory();
212
219
  previousScrollTop.current = top;
@@ -231,10 +238,10 @@ function ConversationTimeline({ disambiguateAuthors, clientActions, onOpen, focu
231
238
  hasNewerHistory)
232
239
  loadNewerHistory();
233
240
  }, style: { overscrollBehavior: "contain" }, children: [count > 0 ? (_jsx("div", { className: "relative w-full", style: {
234
- // Room under the last row for the jump-to-bottom control
235
- // (2rem plus its 1rem offset), so the row can scroll clear of
236
- // it. At the end the control is hidden: one gap (the 8px composer inset), not two.
237
- height: `${String(timeline.getTotalSize() + (atBottom ? 8 : 48))}px`,
241
+ // One gap: the 8px composer inset. It must not depend on whether
242
+ // the scroller is at the end, or following would move the end
243
+ // away from the reader.
244
+ height: `${String(totalSize + 8)}px`,
238
245
  }, children: virtualItems.map((virtualItem) => {
239
246
  const item = itemAt(virtualItem.index);
240
247
  if (item === undefined)
package/dist/styles.css CHANGED
@@ -4899,6 +4899,15 @@
4899
4899
  font-size: 0.75rem;
4900
4900
  }
4901
4901
  }
4902
+ .row-7 {
4903
+ grid-row: 7;
4904
+ }
4905
+ .row-18 {
4906
+ grid-row: 18;
4907
+ }
4908
+ .row-29 {
4909
+ grid-row: 29;
4910
+ }
4902
4911
  .\!container {
4903
4912
  width: 100% !important;
4904
4913
  @media (width >= 40rem) {
@@ -7313,6 +7322,11 @@
7313
7322
  .filter {
7314
7323
  filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
7315
7324
  }
7325
+ .transition {
7326
+ transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter, display, content-visibility, overlay, pointer-events;
7327
+ transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
7328
+ transition-duration: var(--tw-duration, var(--default-transition-duration));
7329
+ }
7316
7330
  .transition-colors {
7317
7331
  transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to;
7318
7332
  transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/parakeet",
3
- "version": "0.11.38",
3
+ "version": "0.12.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "private": false,
6
6
  "description": "Standalone React composer for a typed Shiitake Session",
@@ -19,6 +19,10 @@
19
19
  "types": "./dist/headless.d.ts",
20
20
  "import": "./dist/headless.js"
21
21
  },
22
+ "./conversation-view": {
23
+ "types": "./dist/conversation-view.d.ts",
24
+ "import": "./dist/conversation-view.js"
25
+ },
22
26
  "./conversation-opening": {
23
27
  "types": "./dist/conversation-opening.d.ts",
24
28
  "import": "./dist/conversation-opening.js"