@gemies/sdk 9.2.0 → 10.0.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/CHANGELOG.md +103 -0
- package/README.md +9 -6
- package/package.json +4 -11
- package/src/accounts.ts +7 -1
- package/src/ask-eager.ts +0 -2
- package/src/ask-text.ts +0 -1
- package/src/ask.ts +0 -1
- package/src/components/AmbientField.tsx +13 -2
- package/src/components/ComposerDropZone.tsx +20 -4
- package/src/components/ComposerSuggestions.tsx +9 -2
- package/src/components/GemieActivityLine.tsx +11 -5
- package/src/components/GemieBetweenGemies.tsx +23 -10
- package/src/components/GemieChatContent.tsx +46 -23
- package/src/components/GemieChatScreen.tsx +7 -4
- package/src/components/GemieChatSheet.tsx +6 -2
- package/src/components/GemieComposer.tsx +17 -7
- package/src/components/GemieGroupWelcome.tsx +16 -2
- package/src/components/GemieRecentConversations.tsx +13 -10
- package/src/components/GemieSharedConversation.tsx +38 -6
- package/src/components/GemieWelcomeMessage.tsx +23 -7
- package/src/components/IdentityMark.tsx +6 -12
- package/src/components/PlanPreviewCard.tsx +18 -7
- package/src/components/QuestionCard.tsx +6 -2
- package/src/components/ReplyMarkdown.tsx +32 -6
- package/src/components/RichBlocks.tsx +20 -15
- package/src/components/accounts/GemieAccountGrants.tsx +27 -10
- package/src/components/accounts/GemieConnectedAccounts.tsx +87 -51
- package/src/components/canvas/CanvasComponent.tsx +6 -2
- package/src/components/canvas/DashboardRenderer.tsx +25 -8
- package/src/components/canvas/DeckRenderer.tsx +23 -6
- package/src/components/canvas/FormRenderer.tsx +8 -3
- package/src/components/connectors/ConnectorLogo.tsx +15 -9
- package/src/components/connectors/GemieConnectedConnectors.tsx +51 -25
- package/src/components/connectors/GemieConnectorsStore.tsx +99 -41
- package/src/components/connectors/GrantSwitchRow.tsx +18 -5
- package/src/components/thought/ThoughtPanel.tsx +26 -12
- package/src/components/thought/ToolStep.tsx +14 -6
- package/src/components/thread/AgentResultCard.tsx +10 -4
- package/src/components/thread/AgentTaskCard.tsx +8 -3
- package/src/components/thread/ApprovalCard.tsx +6 -2
- package/src/components/thread/ChatBubble.tsx +66 -25
- package/src/components/thread/GemieThread.tsx +25 -8
- package/src/components/thread/ThreadRow.tsx +20 -15
- package/src/components/thread/ThreadSearch.tsx +27 -10
- package/src/components/thread/ThreadSkeleton.tsx +12 -6
- package/src/components/thread/ToolResultCard.tsx +10 -4
- package/src/components/thread/TurnAttachments.tsx +17 -8
- package/src/components/voice/VoiceControls.tsx +9 -6
- package/src/connectors.ts +15 -2
- package/src/hooks/useChatVoice.ts +2 -10
- package/src/hooks/useMessageReactions.ts +5 -5
- package/src/hooks/useThoughtScope.ts +9 -8
- package/src/index.ts +2 -3
- package/src/lib/tool-call-status.ts +1 -1
- package/src/lib/utils.ts +1 -8
- package/src/realtime/react.tsx +9 -9
- package/src/realtime/reread.ts +28 -0
- package/src/realtime/store.ts +123 -0
- package/src/runtime/agents.ts +46 -27
- package/src/runtime/collections.ts +35 -136
- package/src/runtime/connected-accounts.ts +175 -88
- package/src/runtime/connectors.ts +244 -127
- package/src/runtime/conversations.ts +181 -607
- package/src/runtime/data/answer.ts +76 -0
- package/src/runtime/data/collections.ts +168 -0
- package/src/runtime/data/conversations.ts +626 -0
- package/src/runtime/data/reactions.ts +29 -0
- package/src/runtime/data/read.ts +37 -0
- package/src/runtime/data/threads.ts +149 -0
- package/src/runtime/index.ts +72 -8
- package/src/runtime/model.ts +0 -2
- package/src/runtime/routes.ts +2 -2
- package/src/runtime/sharing.ts +69 -56
- package/src/runtime/types.ts +8 -16
- package/src/runtime/use-bound-action.ts +27 -0
- package/src/runtime/use-conversation-stream.ts +8 -31
- package/src/runtime/use-conversation-thread.ts +40 -51
- package/src/runtime/use-gemie-thread.ts +32 -43
- package/src/runtime/use-start-conversation.ts +14 -15
- package/src/runtime/use-thread-history.ts +26 -36
- package/src/runtime/use-thread-search.ts +29 -76
- package/src/text.ts +0 -1
- package/src/voice.ts +0 -1
- package/src/components/Image.tsx +0 -12
- package/src/realtime/cache.ts +0 -257
- package/src/runtime/conversation-dates.ts +0 -31
- package/src/runtime/query-keys.ts +0 -66
- package/src/runtime/reaction-cache.ts +0 -45
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toast } from '@oxy.so/bloom/toast';
|
|
2
2
|
import { useOxy } from '@oxy.so/services/ui/client';
|
|
3
|
-
import {
|
|
3
|
+
import { useStore, withStore } from '@oxy.so/bloom-data';
|
|
4
4
|
import { useCallback, useEffect, useId, useMemo, useRef } from 'react';
|
|
5
5
|
import { useGemieActivityStore } from '../lib/activity-store';
|
|
6
6
|
import { turnActivityState } from '../lib/turn-state';
|
|
@@ -14,22 +14,24 @@ import { useGemieRuntime } from './config';
|
|
|
14
14
|
import { releaseAttachments, useComposerDraftStore } from './composer-draft-store';
|
|
15
15
|
import { useConversationStore } from './conversation-store';
|
|
16
16
|
import {
|
|
17
|
-
ConversationNotFoundError,
|
|
18
17
|
useClearConversation,
|
|
19
18
|
useConversation,
|
|
20
19
|
useCreateConversation,
|
|
21
20
|
useDeleteConversation,
|
|
22
21
|
useMarkConversationRead,
|
|
23
|
-
useReadConversation,
|
|
24
22
|
} from './conversations';
|
|
25
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
bumpConversation,
|
|
25
|
+
ConversationNotFoundError,
|
|
26
|
+
forgetConversation,
|
|
27
|
+
mergeMessages,
|
|
28
|
+
} from './data/conversations';
|
|
26
29
|
import { reportDroppedAttachments, useStartConversation } from './use-start-conversation';
|
|
27
30
|
import { createRoomLedger } from './room-events';
|
|
28
31
|
import { applyMessageReaction, type MessageReactionSnapshot } from './message-reactions';
|
|
29
32
|
import { useConversationStream } from './use-conversation-stream';
|
|
30
33
|
import { useRoomEvents } from './use-room-events';
|
|
31
34
|
import { useGemieRealtime } from '../realtime/react';
|
|
32
|
-
import { bumpConversation, mergeMessages } from '../realtime/cache';
|
|
33
35
|
import type { RealtimeData } from '../realtime/contract';
|
|
34
36
|
import { normalizeConversationMessages } from './message-history';
|
|
35
37
|
import type { Message, SendOptions } from './types';
|
|
@@ -102,7 +104,7 @@ export function useConversationThread({
|
|
|
102
104
|
clientContext,
|
|
103
105
|
hostTools,
|
|
104
106
|
}: UseConversationThreadOptions = {}) {
|
|
105
|
-
const
|
|
107
|
+
const store = useStore();
|
|
106
108
|
const labels = useLabels();
|
|
107
109
|
const { host } = useGemieRuntime();
|
|
108
110
|
const { user } = useOxy();
|
|
@@ -114,27 +116,31 @@ export function useConversationThread({
|
|
|
114
116
|
const wasLoadingRef = useRef(false);
|
|
115
117
|
|
|
116
118
|
const pendingInitialMessage = useConversationStore((state) => state.pendingInitialMessage);
|
|
119
|
+
// A rewritten thread (an edit or a regenerate on another device) is read again and replaces
|
|
120
|
+
// the screen's, unless a turn of this device is writing it now.
|
|
121
|
+
const loadingRef = useRef(false);
|
|
117
122
|
const {
|
|
118
|
-
|
|
123
|
+
value: conversation,
|
|
119
124
|
error: conversationQueryError,
|
|
120
125
|
isLoading: conversationQueryLoading,
|
|
121
126
|
isFetching: conversationFetching,
|
|
122
|
-
} = useConversation(conversationId ||
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
} = useConversation(conversationId || undefined, {
|
|
128
|
+
onReload: (fresh) => {
|
|
129
|
+
if (!loadingRef.current) setMessages(fresh.messages ?? []);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const { run: createConversation } = useCreateConversation();
|
|
133
|
+
const { run: deleteConversation } = useDeleteConversation();
|
|
134
|
+
const { run: clearMessages } = useClearConversation();
|
|
126
135
|
|
|
127
136
|
// A missing row is not a transient loading failure and the URL cannot become
|
|
128
|
-
// useful by staying open.
|
|
129
|
-
// valid composer;
|
|
137
|
+
// useful by staying open. Drop it from the account's store (its record and every
|
|
138
|
+
// list) and return to a valid composer; its read is never retried, so this happens once.
|
|
130
139
|
useEffect(() => {
|
|
131
140
|
if (!(conversationQueryError instanceof ConversationNotFoundError)) return;
|
|
132
|
-
|
|
133
|
-
queryKey: gemieQueryKeys.conversations.detail(conversationQueryError.conversationId),
|
|
134
|
-
});
|
|
135
|
-
void queryClient.invalidateQueries({ queryKey: gemieQueryKeys.conversations.all });
|
|
141
|
+
withStore(store, () => forgetConversation(conversationQueryError.conversationId));
|
|
136
142
|
host.closeConversation?.();
|
|
137
|
-
}, [conversationQueryError,
|
|
143
|
+
}, [conversationQueryError, store, host]);
|
|
138
144
|
|
|
139
145
|
// One per open conversation: which speaking turn each message draws (the request's and the room's).
|
|
140
146
|
// biome-ignore lint/correctness/useExhaustiveDependencies: a new conversation is a new ledger
|
|
@@ -220,8 +226,10 @@ export function useConversationThread({
|
|
|
220
226
|
useEffect(() => {
|
|
221
227
|
if (wasLoadingRef.current === isLoading) return;
|
|
222
228
|
wasLoadingRef.current = isLoading;
|
|
223
|
-
if (isLoading && conversationId)
|
|
224
|
-
|
|
229
|
+
if (isLoading && conversationId) {
|
|
230
|
+
withStore(store, () => bumpConversation(conversationId, lastUserText));
|
|
231
|
+
}
|
|
232
|
+
}, [isLoading, conversationId, store, lastUserText]);
|
|
225
233
|
|
|
226
234
|
// Sync chatId and load messages when conversation changes or when
|
|
227
235
|
// seeded cache data upgrades to full data (messages go from empty to populated).
|
|
@@ -251,17 +259,14 @@ export function useConversationThread({
|
|
|
251
259
|
|
|
252
260
|
// What this conversation gained elsewhere — a gemie writing on its own, a group member, another
|
|
253
261
|
// device — arrives as the `conversation` event: merged by id, so the copy this device drew under
|
|
254
|
-
// the same id is replaced, never doubled.
|
|
255
|
-
// device) is read again, unless a turn of this device is writing it now.
|
|
262
|
+
// the same id is replaced, never doubled.
|
|
256
263
|
const realtime = useGemieRealtime();
|
|
257
|
-
const readConversation = useReadConversation();
|
|
258
264
|
const markRead = useMarkConversationRead();
|
|
259
265
|
// Opening a conversation with something unread reads it.
|
|
260
266
|
const openUnread = (conversation?.unreadCount ?? 0) > 0;
|
|
261
267
|
useEffect(() => {
|
|
262
268
|
if (conversationId && openUnread) markRead(conversationId);
|
|
263
269
|
}, [conversationId, openUnread, markRead]);
|
|
264
|
-
const loadingRef = useRef(isLoading);
|
|
265
270
|
loadingRef.current = isLoading;
|
|
266
271
|
useEffect(() => {
|
|
267
272
|
if (!conversationId || !realtime) return;
|
|
@@ -274,20 +279,8 @@ export function useConversationThread({
|
|
|
274
279
|
const incoming = normalizeConversationMessages(data.appended);
|
|
275
280
|
setMessages((prev) => mergeMessages(prev, incoming));
|
|
276
281
|
}
|
|
277
|
-
if (data.reload && !loadingRef.current) {
|
|
278
|
-
void queryClient
|
|
279
|
-
.fetchQuery({
|
|
280
|
-
queryKey: gemieQueryKeys.conversations.detail(conversationId),
|
|
281
|
-
queryFn: () => readConversation(conversationId),
|
|
282
|
-
staleTime: 0,
|
|
283
|
-
})
|
|
284
|
-
.then((fresh) => {
|
|
285
|
-
if (!loadingRef.current) setMessages(fresh.messages);
|
|
286
|
-
})
|
|
287
|
-
.catch(() => undefined);
|
|
288
|
-
}
|
|
289
282
|
});
|
|
290
|
-
}, [conversationId, realtime, setMessages,
|
|
283
|
+
}, [conversationId, realtime, setMessages, markRead]);
|
|
291
284
|
|
|
292
285
|
// Send pending initial message for new conversations
|
|
293
286
|
useEffect(() => {
|
|
@@ -397,15 +390,11 @@ export function useConversationThread({
|
|
|
397
390
|
*/
|
|
398
391
|
const ensureConversation = useCallback(async (): Promise<string | undefined> => {
|
|
399
392
|
if (conversationId) return conversationId;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// useCreateConversation.onError already told the person.
|
|
406
|
-
return undefined;
|
|
407
|
-
}
|
|
408
|
-
}, [conversationId, createConversationMutation, agentId, host]);
|
|
393
|
+
// A refusal was already told (useCreateConversation's toast).
|
|
394
|
+
const created = await createConversation({ agentId }).catch(() => undefined);
|
|
395
|
+
if (created) host.openConversation?.(created.id);
|
|
396
|
+
return created?.id;
|
|
397
|
+
}, [conversationId, createConversation, agentId, host]);
|
|
409
398
|
|
|
410
399
|
/** Leave this thread for an empty one. Nothing is deleted: the conversation stays in the list. */
|
|
411
400
|
const startOver = useCallback(() => {
|
|
@@ -550,9 +539,9 @@ export function useConversationThread({
|
|
|
550
539
|
* and nothing else, and the sync effect above, seeing a cached history and
|
|
551
540
|
* no messages, read that as a data upgrade and hydrated it straight back
|
|
552
541
|
* under a dialog that had just promised the action could not be undone.
|
|
553
|
-
* `useClearConversation` empties the
|
|
554
|
-
*
|
|
555
|
-
*
|
|
542
|
+
* `useClearConversation` empties the conversation's record, settled by the
|
|
543
|
+
* time `run` resolves, so the local reset that follows has nothing left to be
|
|
544
|
+
* undone by.
|
|
556
545
|
*
|
|
557
546
|
* A turn still streaming is stopped first rather than refused: the person
|
|
558
547
|
* has just confirmed they want the thread empty, and an answer that kept
|
|
@@ -564,8 +553,8 @@ export function useConversationThread({
|
|
|
564
553
|
* finished and stored, so the clear removes it — and the clear that follows
|
|
565
554
|
* is of a thread nothing is writing to.
|
|
566
555
|
*
|
|
567
|
-
* A refusal keeps everything: the screen is not reset, the
|
|
568
|
-
*
|
|
556
|
+
* A refusal keeps everything: the screen is not reset, the record is put
|
|
557
|
+
* back as it was, and the error is surfaced — a cleared view whose history returns
|
|
569
558
|
* on the next fetch is exactly the state this exists to end. A turn that
|
|
570
559
|
* could not be stopped is such a refusal.
|
|
571
560
|
*
|
|
@@ -1,54 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type RecordView, skip, useStore, withStore } from '@oxy.so/bloom-data';
|
|
2
|
+
import { useCallback } from 'react';
|
|
2
3
|
import { useGemieApi } from './api';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { useAnswer } from './data/answer';
|
|
5
|
+
import { gemieThread, type GemieThreadInfo, threadHistory } from './data/threads';
|
|
6
|
+
import type { GemieThreadAddress } from './routes';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
export interface GemieThreadInfo {
|
|
9
|
-
/** Who the thread is with. `name`, `handle` and `color` come from Oxy and may be `null` (Alia's do, until her account exists). */
|
|
10
|
-
readonly agent: {
|
|
11
|
-
readonly _id: string;
|
|
12
|
-
readonly name: string | null;
|
|
13
|
-
readonly handle: string | null;
|
|
14
|
-
readonly character: unknown;
|
|
15
|
-
readonly tagline: string;
|
|
16
|
-
readonly description: string;
|
|
17
|
-
};
|
|
18
|
-
/** The active stretch: `GemieChatContent`'s `conversationId`, where the next turn goes. */
|
|
19
|
-
readonly conversationId: string;
|
|
20
|
-
/**
|
|
21
|
-
* The thread row, for a gemie whose chats are loose (Alia): her thread is apart from them, and its
|
|
22
|
-
* next stretch is `useCreateConversation({ threadId })`. `null` for any other gemie, whose thread is
|
|
23
|
-
* every conversation the two hold.
|
|
24
|
-
*/
|
|
25
|
-
readonly threadId: string | null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** How long the open thread is good: it changes when the person starts a stretch, which invalidates it. */
|
|
29
|
-
const THREAD_STALE_MS = 5 * 60 * 1000;
|
|
8
|
+
export type { GemieThreadInfo } from './data/threads';
|
|
30
9
|
|
|
31
10
|
/**
|
|
32
|
-
* Open the person's thread with a gemie by its id
|
|
11
|
+
* Open the person's thread with a gemie by its id: Alia's thread mode, since she has no handle
|
|
33
12
|
* (ADR 0034). The first open CREATES the thread and its first stretch, so ask only when the person
|
|
34
13
|
* opens it, never to prefetch one nobody started.
|
|
35
14
|
*
|
|
36
15
|
* Render the chat with what it answers: `<GemieChatContent conversationId={thread.conversationId}
|
|
37
|
-
* gemieThread={{ gemieId, threadId: thread.threadId }} />`.
|
|
38
|
-
*
|
|
16
|
+
* gemieThread={{ gemieId, threadId: thread.threadId }} />`. A message that may have started a new
|
|
17
|
+
* stretch (a realtime `conversation` event with appended messages) makes it stale, and starting the
|
|
18
|
+
* next stretch from the chat reads it again (`useRefreshGemieThread`).
|
|
19
|
+
*/
|
|
20
|
+
export function useGemieThread(gemieId: string | undefined): RecordView<GemieThreadInfo> {
|
|
21
|
+
const api = useGemieApi();
|
|
22
|
+
return useAnswer(
|
|
23
|
+
gemieThread,
|
|
24
|
+
...((gemieId?.length ?? 0) > 0 ? [api, { gemieId: gemieId as string }] : [skip]),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Read a thread again, with its history: after its next stretch started, the one that was live is
|
|
30
|
+
* history, and the pages held were read before its last turns existed.
|
|
39
31
|
*/
|
|
40
|
-
export function
|
|
32
|
+
export function useRefreshGemieThread(): (thread: GemieThreadAddress) => void {
|
|
41
33
|
const api = useGemieApi();
|
|
42
|
-
const
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// A 404 is an answer: the gemie does not exist or this person cannot open it.
|
|
52
|
-
retry: retryThreadRead,
|
|
53
|
-
});
|
|
34
|
+
const store = useStore();
|
|
35
|
+
return useCallback(
|
|
36
|
+
(thread) =>
|
|
37
|
+
withStore(store, () => {
|
|
38
|
+
void gemieThread.refresh(api, thread);
|
|
39
|
+
void threadHistory.refresh(api, thread);
|
|
40
|
+
}),
|
|
41
|
+
[api, store],
|
|
42
|
+
);
|
|
54
43
|
}
|
|
@@ -63,7 +63,7 @@ export interface StartConversationOptions {
|
|
|
63
63
|
export function useStartConversation({ agentId }: { agentId?: string } = {}) {
|
|
64
64
|
const labels = useLabels();
|
|
65
65
|
const { host } = useGemieRuntime();
|
|
66
|
-
const {
|
|
66
|
+
const { run: createConversation } = useCreateConversation();
|
|
67
67
|
const upload = useDocumentUpload();
|
|
68
68
|
|
|
69
69
|
return useCallback(
|
|
@@ -79,20 +79,9 @@ export function useStartConversation({ agentId }: { agentId?: string } = {}) {
|
|
|
79
79
|
const built =
|
|
80
80
|
attachments.length > 0 ? await buildMessageContent(text, attachments, upload) : null;
|
|
81
81
|
reportDroppedAttachments(built?.dropped, labels);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
conversationId: conversation.id,
|
|
86
|
-
content: built ? built.content : text,
|
|
87
|
-
text,
|
|
88
|
-
attachments,
|
|
89
|
-
mcpServerId: options?.mcpServerId ?? null,
|
|
90
|
-
skillNames: options?.skillNames ?? [],
|
|
91
|
-
});
|
|
92
|
-
host.openConversation?.(conversation.id);
|
|
93
|
-
return true;
|
|
94
|
-
} catch {
|
|
95
|
-
// useCreateConversation.onError already shows the toast.
|
|
82
|
+
// A refusal was already told (useCreateConversation's toast): the draft comes back.
|
|
83
|
+
const conversation = await createConversation({ agentId }).catch(() => undefined);
|
|
84
|
+
if (conversation === undefined) {
|
|
96
85
|
useComposerDraftStore.getState().restore(draft, {
|
|
97
86
|
text,
|
|
98
87
|
attachments,
|
|
@@ -101,6 +90,16 @@ export function useStartConversation({ agentId }: { agentId?: string } = {}) {
|
|
|
101
90
|
});
|
|
102
91
|
return false;
|
|
103
92
|
}
|
|
93
|
+
useConversationStore.getState().setPendingInitialMessage({
|
|
94
|
+
conversationId: conversation.id,
|
|
95
|
+
content: built ? built.content : text,
|
|
96
|
+
text,
|
|
97
|
+
attachments,
|
|
98
|
+
mcpServerId: options?.mcpServerId ?? null,
|
|
99
|
+
skillNames: options?.skillNames ?? [],
|
|
100
|
+
});
|
|
101
|
+
host.openConversation?.(conversation.id);
|
|
102
|
+
return true;
|
|
104
103
|
},
|
|
105
104
|
[labels, host, createConversation, agentId, upload],
|
|
106
105
|
);
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { skip, useEntities, useList } from '@oxy.so/bloom-data';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { useGemieApi } from './api';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { type ThreadPage, threadHistory } from './thread/thread-history';
|
|
4
|
+
import { ThreadMessages, threadHistory as historySource } from './data/threads';
|
|
5
|
+
import type { GemieThreadAddress } from './routes';
|
|
6
|
+
import { type ThreadMessage, type WireThreadMessage, threadHistory } from './thread/thread-history';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Everything said in this thread before the conversation on screen, a page at a time, going back.
|
|
11
10
|
*
|
|
12
11
|
* The screen streams into the most recent conversation of the thread and knows nothing older;
|
|
13
12
|
* the thread's messages route is what crosses the seams into the stretches before it. Pages are
|
|
14
|
-
* pulled as the reader approaches the top, never eagerly
|
|
13
|
+
* pulled as the reader approaches the top, never eagerly: a thread has no end going backwards,
|
|
15
14
|
* and the first page is already everything a reader who does not scroll will see.
|
|
16
15
|
*
|
|
17
16
|
* `nextCursor` is what says whether anything older remains, and it is the server's answer rather
|
|
@@ -20,9 +19,6 @@ import { type ThreadPage, threadHistory } from './thread/thread-history';
|
|
|
20
19
|
* is long.
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
|
-
/** How many messages a page carries. The server clamps its own maximum. */
|
|
24
|
-
const PAGE_SIZE = 50;
|
|
25
|
-
|
|
26
22
|
/** Whether there is a thread to ask about: an address with a non-empty handle or gemie id. */
|
|
27
23
|
export function isThreadAddress(
|
|
28
24
|
thread: GemieThreadAddress | undefined,
|
|
@@ -31,9 +27,18 @@ export function isThreadAddress(
|
|
|
31
27
|
return ('handle' in thread ? thread.handle : thread.gemieId).length > 0;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
/** A
|
|
35
|
-
export function
|
|
36
|
-
|
|
30
|
+
/** A thread list's messages (held newest first) in reading order, the active stretch left out. */
|
|
31
|
+
export function useHeldThreadMessages(
|
|
32
|
+
ids: readonly string[],
|
|
33
|
+
activeConversationId: string,
|
|
34
|
+
): ThreadMessage[] {
|
|
35
|
+
const records = useEntities(ThreadMessages, ids);
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
const oldestFirst = records
|
|
38
|
+
.filter((message): message is WireThreadMessage => message !== undefined)
|
|
39
|
+
.reverse();
|
|
40
|
+
return threadHistory([{ messages: oldestFirst, nextCursor: null }], activeConversationId);
|
|
41
|
+
}, [records, activeConversationId]);
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export function useThreadHistory(
|
|
@@ -41,33 +46,18 @@ export function useThreadHistory(
|
|
|
41
46
|
activeConversationId: string | undefined,
|
|
42
47
|
) {
|
|
43
48
|
const api = useGemieApi();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
params: { limit: PAGE_SIZE, before: pageParam },
|
|
50
|
-
});
|
|
51
|
-
return data;
|
|
52
|
-
},
|
|
53
|
-
initialPageParam: undefined as string | undefined,
|
|
54
|
-
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
|
|
55
|
-
// Nothing to page through until the thread has answered which conversation is the live one:
|
|
56
|
-
// without it every message would be history, including the ones already on screen.
|
|
57
|
-
enabled: isThreadAddress(thread) && activeConversationId !== undefined,
|
|
58
|
-
retry: retryThreadRead,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const messages = useMemo(
|
|
62
|
-
() => threadHistory(query.data?.pages ?? [], activeConversationId ?? ''),
|
|
63
|
-
[query.data?.pages, activeConversationId],
|
|
49
|
+
// Nothing to page through until the thread has answered which conversation is the live one:
|
|
50
|
+
// without it every message would be history, including the ones already on screen.
|
|
51
|
+
const view = useList(
|
|
52
|
+
historySource,
|
|
53
|
+
...(isThreadAddress(thread) && activeConversationId !== undefined ? [api, thread] : [skip]),
|
|
64
54
|
);
|
|
65
|
-
|
|
55
|
+
const messages = useHeldThreadMessages(view.ids, activeConversationId ?? '');
|
|
66
56
|
return {
|
|
67
57
|
messages,
|
|
68
58
|
/** Whether a page older than the ones held remains to be asked for. */
|
|
69
|
-
hasMore:
|
|
70
|
-
isLoadingMore:
|
|
71
|
-
loadMore:
|
|
59
|
+
hasMore: view.hasMore,
|
|
60
|
+
isLoadingMore: view.isFetching && view.list !== undefined,
|
|
61
|
+
loadMore: view.more,
|
|
72
62
|
};
|
|
73
63
|
}
|
|
@@ -1,100 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { type RecordView, skip, useList } from '@oxy.so/bloom-data';
|
|
3
2
|
import { useGemieApi } from './api';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type ThreadSearchHit,
|
|
10
|
-
threadHistory,
|
|
11
|
-
} from './thread/thread-history';
|
|
12
|
-
import { isThreadAddress, retryThreadRead } from './use-thread-history';
|
|
3
|
+
import { useAnswer } from './data/answer';
|
|
4
|
+
import { threadSearch, threadWindow } from './data/threads';
|
|
5
|
+
import type { GemieThreadAddress } from './routes';
|
|
6
|
+
import type { ThreadMessage, ThreadSearchHit } from './thread/thread-history';
|
|
7
|
+
import { isThreadAddress, useHeldThreadMessages } from './use-thread-history';
|
|
13
8
|
|
|
14
9
|
/**
|
|
15
10
|
* Finding something said earlier in a thread, and getting back to it.
|
|
16
11
|
*
|
|
17
12
|
* Two halves, and the second is why the first is worth anything: a hit tells you the message
|
|
18
|
-
* exists, and its CURSOR is what opens the stretch of thread around it
|
|
13
|
+
* exists, and its CURSOR is what opens the stretch of thread around it, however many
|
|
19
14
|
* conversations back it lives. Without that, a result list is a wall you can read and not reach.
|
|
20
15
|
*/
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
export function useThreadSearch(
|
|
18
|
+
thread: GemieThreadAddress | undefined,
|
|
19
|
+
query: string,
|
|
20
|
+
): RecordView<ThreadSearchHit[]> {
|
|
26
21
|
const api = useGemieApi();
|
|
27
22
|
const trimmed = query.trim();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
AGENT_ROUTES.threadSearch(thread),
|
|
35
|
-
{ params: { q: trimmed, limit: HIT_LIMIT } },
|
|
36
|
-
);
|
|
37
|
-
return data.hits;
|
|
38
|
-
},
|
|
39
|
-
// An empty query is not a search, and asking for one would return the thread's most recent
|
|
40
|
-
// everything under the guise of a result.
|
|
41
|
-
enabled: isThreadAddress(thread) && trimmed.length > 0,
|
|
42
|
-
// What was said cannot change, so a query already asked is answered from the cache.
|
|
43
|
-
staleTime: 1000 * 60 * 5,
|
|
44
|
-
retry: retryThreadRead,
|
|
45
|
-
});
|
|
23
|
+
// An empty query is not a search: asking for one would return the thread's most recent
|
|
24
|
+
// everything under the guise of a result.
|
|
25
|
+
return useAnswer(
|
|
26
|
+
threadSearch,
|
|
27
|
+
...(isThreadAddress(thread) && trimmed.length > 0 ? [api, thread, trimmed] : [skip]),
|
|
28
|
+
);
|
|
46
29
|
}
|
|
47
30
|
|
|
48
|
-
/** How many messages a window carries, half of them before the hit. */
|
|
49
|
-
const WINDOW_SIZE = 40;
|
|
50
|
-
|
|
51
31
|
/**
|
|
52
|
-
* The stretch of thread around one message, opened from a search hit.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* reveal would be the one missing from it.
|
|
56
|
-
*
|
|
57
|
-
* Reading further back from here is the same paging as anywhere else — the window's own oldest
|
|
58
|
-
* cursor continues it — so this is an infinite query too, and only its first page is addressed
|
|
59
|
-
* differently. There is no paging FORWARD: the way back to the present is leaving the window, not
|
|
60
|
-
* walking to it.
|
|
32
|
+
* The stretch of thread around one message, opened from a search hit. Reading further back from
|
|
33
|
+
* here is the same paging as anywhere else. There is no paging FORWARD: the way back to the
|
|
34
|
+
* present is leaving the window, not walking to it.
|
|
61
35
|
*/
|
|
62
36
|
export function useThreadWindow(thread: GemieThreadAddress | undefined, cursor: string | null) {
|
|
63
37
|
const api = useGemieApi();
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
),
|
|
69
|
-
queryFn: async ({ pageParam }): Promise<ThreadPage> => {
|
|
70
|
-
if (thread === undefined) throw new Error('No thread to read');
|
|
71
|
-
const { data } = await api.get<ThreadPage>(AGENT_ROUTES.threadMessages(thread), {
|
|
72
|
-
params:
|
|
73
|
-
pageParam === undefined
|
|
74
|
-
? { limit: WINDOW_SIZE, at: cursor ?? undefined }
|
|
75
|
-
: { limit: WINDOW_SIZE, before: pageParam },
|
|
76
|
-
});
|
|
77
|
-
return data;
|
|
78
|
-
},
|
|
79
|
-
initialPageParam: undefined as string | undefined,
|
|
80
|
-
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
|
|
81
|
-
enabled: isThreadAddress(thread) && cursor !== null,
|
|
82
|
-
retry: retryThreadRead,
|
|
83
|
-
});
|
|
84
|
-
|
|
38
|
+
const view = useList(
|
|
39
|
+
threadWindow,
|
|
40
|
+
...(isThreadAddress(thread) && cursor !== null ? [api, thread, cursor] : [skip]),
|
|
41
|
+
);
|
|
85
42
|
// Nothing is dropped here, unlike the tail: a window is a view of the PAST, and the live
|
|
86
43
|
// conversation is not on screen underneath it to be duplicated. The empty string is a
|
|
87
44
|
// conversation id no message has.
|
|
88
|
-
const messages: ThreadMessage[] =
|
|
89
|
-
() => threadHistory(query.data?.pages ?? [], ''),
|
|
90
|
-
[query.data?.pages],
|
|
91
|
-
);
|
|
92
|
-
|
|
45
|
+
const messages: ThreadMessage[] = useHeldThreadMessages(view.ids, '');
|
|
93
46
|
return {
|
|
94
47
|
messages,
|
|
95
|
-
hasMore:
|
|
96
|
-
isLoadingMore:
|
|
97
|
-
loadMore:
|
|
98
|
-
isLoading:
|
|
48
|
+
hasMore: view.hasMore,
|
|
49
|
+
isLoadingMore: view.isFetching && view.list !== undefined,
|
|
50
|
+
loadMore: view.more,
|
|
51
|
+
isLoading: view.isLoading && cursor !== null,
|
|
99
52
|
};
|
|
100
53
|
}
|
package/src/text.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="nativewind/types" />
|
|
2
1
|
// @gemies/sdk/text — the chat without the voice call, and without bundling it
|
|
3
2
|
// The same `GemieChatSheet`, `GemieChatScreen` and `GemieChatContent` as the root entry, but none of
|
|
4
3
|
// them reaches the call's modules (its socket, protocol and audio engine): a text-only app takes
|
package/src/voice.ts
CHANGED
package/src/components/Image.tsx
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Image as ExpoImage, type ImageProps } from 'expo-image';
|
|
2
|
-
import type { ComponentType } from 'react';
|
|
3
|
-
import { styled } from 'react-native-css';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* `expo-image` with `className`. On web the class reaches the DOM either way; on native
|
|
7
|
-
* react-native-css maps classes to styles only for react-native's own primitives, so anything
|
|
8
|
-
* else drops them silently unless it is wrapped once, here, at module scope.
|
|
9
|
-
*/
|
|
10
|
-
export const Image: ComponentType<ImageProps & { className?: string }> = styled(ExpoImage, {
|
|
11
|
-
className: 'style',
|
|
12
|
-
});
|