@gemies/sdk 9.2.0 → 10.0.1
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 +32 -10
- 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/useAgentRunFailureToast.ts +34 -0
- 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
package/src/realtime/cache.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Realtime events into the conversation runtime's React Query cache (`docs/realtime.mdx`).
|
|
3
|
-
*
|
|
4
|
-
* Every write here is an idempotent upsert of what the server says now — the sidebar row by
|
|
5
|
-
* conversation id, a message by its id, a reaction by its revision — so applying an event twice,
|
|
6
|
-
* or again over a snapshot that predates it (`noteSnapshot`), converges on the same state. Nothing
|
|
7
|
-
* here refetches on a timer: only `reload` (a rewritten thread) and `reset` (a client too far
|
|
8
|
-
* behind) read again, and only what they name.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
12
|
-
import { normalizeConversationMessages } from '../runtime/message-history';
|
|
13
|
-
import { gemieQueryKeys, type ConversationsFilter } from '../runtime/query-keys';
|
|
14
|
-
import { updateReactionCaches } from '../runtime/reaction-cache';
|
|
15
|
-
import type { Conversation, ConversationsInfiniteData, Message } from '../runtime/types';
|
|
16
|
-
import type { RealtimeConnection } from './connection';
|
|
17
|
-
import type { RealtimeConversationRow, RealtimeData, RealtimeFrame } from './contract';
|
|
18
|
-
import { readCollectionsSnapshot } from '../runtime/collections-model';
|
|
19
|
-
|
|
20
|
-
function toConversation(row: RealtimeConversationRow): Conversation {
|
|
21
|
-
return {
|
|
22
|
-
id: row.id,
|
|
23
|
-
title: row.title,
|
|
24
|
-
...(row.lastMessage === null ? {} : { lastMessage: row.lastMessage }),
|
|
25
|
-
source: row.source,
|
|
26
|
-
agentId: row.agentId,
|
|
27
|
-
memberAgentIds: row.memberAgentIds,
|
|
28
|
-
spaceId: row.spaceId,
|
|
29
|
-
...(row.kind === undefined ? {} : { kind: row.kind }),
|
|
30
|
-
...(row.members === undefined ? {} : { members: row.members }),
|
|
31
|
-
threadId: row.threadId,
|
|
32
|
-
app: row.app,
|
|
33
|
-
unreadCount: row.unreadCount,
|
|
34
|
-
createdAt: new Date(row.createdAt),
|
|
35
|
-
updatedAt: new Date(row.updatedAt),
|
|
36
|
-
messages: [],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function matches(filter: ConversationsFilter | undefined, row: Conversation): boolean {
|
|
41
|
-
// The person's own lists never hold a conversation between their gemies, and that list holds
|
|
42
|
-
// nothing else (ADR 0042).
|
|
43
|
-
if ((filter?.kind ?? 'person') !== (row.kind ?? 'person')) return false;
|
|
44
|
-
if (!filter) return true;
|
|
45
|
-
if (filter.agentId !== undefined && row.agentId !== filter.agentId) return false;
|
|
46
|
-
if (filter.app !== undefined && row.app !== filter.app) return false;
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The row where the list's order puts it: newest `updatedAt` first, on the first page. A row whose
|
|
52
|
-
* copy is already newer than this one keeps that copy (an event replayed over a fresher snapshot).
|
|
53
|
-
*/
|
|
54
|
-
export function placeConversation(
|
|
55
|
-
data: ConversationsInfiniteData | undefined,
|
|
56
|
-
row: Conversation,
|
|
57
|
-
): ConversationsInfiniteData | undefined {
|
|
58
|
-
if (!data?.pages?.length) return data;
|
|
59
|
-
let existing: Conversation | undefined;
|
|
60
|
-
const pages = data.pages.map((page) => {
|
|
61
|
-
const index = page.conversations.findIndex((c) => c.id === row.id);
|
|
62
|
-
if (index < 0) return page;
|
|
63
|
-
existing = page.conversations[index];
|
|
64
|
-
return { ...page, conversations: page.conversations.filter((c) => c.id !== row.id) };
|
|
65
|
-
});
|
|
66
|
-
if (existing && new Date(existing.updatedAt).getTime() > row.updatedAt.getTime()) return data;
|
|
67
|
-
const [first, ...rest] = pages;
|
|
68
|
-
if (!first) return data;
|
|
69
|
-
const conversations = [...first.conversations];
|
|
70
|
-
const at = conversations.findIndex(
|
|
71
|
-
(c) => new Date(c.updatedAt).getTime() <= row.updatedAt.getTime(),
|
|
72
|
-
);
|
|
73
|
-
// Older than everything on the first page and not there already: it belongs to a later page,
|
|
74
|
-
// which a scroll will read.
|
|
75
|
-
if (at < 0 && !existing && first.hasMore) return { ...data, pages };
|
|
76
|
-
conversations.splice(at < 0 ? conversations.length : at, 0, row);
|
|
77
|
-
return { ...data, pages: [{ ...first, conversations }, ...rest] };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The person just sent in a conversation: its row goes to the top with their words, now. The
|
|
82
|
-
* server's `conversation` event replaces this with what it stored.
|
|
83
|
-
*/
|
|
84
|
-
export function bumpConversation(client: QueryClient, id: string, preview: string): void {
|
|
85
|
-
for (const query of client
|
|
86
|
-
.getQueryCache()
|
|
87
|
-
.findAll({ queryKey: gemieQueryKeys.conversations.all })) {
|
|
88
|
-
const current = query.state.data as ConversationsInfiniteData | undefined;
|
|
89
|
-
const existing = current?.pages?.flatMap((page) => page.conversations).find((c) => c.id === id);
|
|
90
|
-
if (!existing) continue;
|
|
91
|
-
const next = placeConversation(current, {
|
|
92
|
-
...existing,
|
|
93
|
-
...(preview ? { lastMessage: preview.slice(0, 100) } : {}),
|
|
94
|
-
updatedAt: new Date(),
|
|
95
|
-
});
|
|
96
|
-
if (next !== current) client.setQueryData(query.queryKey, next);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function removeConversation(
|
|
101
|
-
data: ConversationsInfiniteData | undefined,
|
|
102
|
-
id: string,
|
|
103
|
-
): ConversationsInfiniteData | undefined {
|
|
104
|
-
if (!data?.pages) return data;
|
|
105
|
-
return {
|
|
106
|
-
...data,
|
|
107
|
-
pages: data.pages.map((page) => ({
|
|
108
|
-
...page,
|
|
109
|
-
conversations: page.conversations.filter((c) => c.id !== id),
|
|
110
|
-
})),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Messages merged by id: a copy the client drew under the same id is replaced, never doubled. */
|
|
115
|
-
export function mergeMessages(
|
|
116
|
-
previous: readonly Message[],
|
|
117
|
-
incoming: readonly Message[],
|
|
118
|
-
): Message[] {
|
|
119
|
-
if (incoming.length === 0) return [...previous];
|
|
120
|
-
const next = [...previous];
|
|
121
|
-
for (const message of incoming) {
|
|
122
|
-
if (!message?.id) continue;
|
|
123
|
-
const index = next.findIndex((m) => m.id === message.id);
|
|
124
|
-
if (index >= 0) next[index] = { ...next[index], ...message };
|
|
125
|
-
else next.push(message);
|
|
126
|
-
}
|
|
127
|
-
return next;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function applyConversation(client: QueryClient, data: RealtimeData['conversation']): void {
|
|
131
|
-
const row = toConversation(data.conversation);
|
|
132
|
-
for (const query of client
|
|
133
|
-
.getQueryCache()
|
|
134
|
-
.findAll({ queryKey: gemieQueryKeys.conversations.all })) {
|
|
135
|
-
const filter = query.queryKey[1] as ConversationsFilter | undefined;
|
|
136
|
-
const current = query.state.data as ConversationsInfiniteData | undefined;
|
|
137
|
-
const next = matches(filter, row)
|
|
138
|
-
? placeConversation(current, row)
|
|
139
|
-
: removeConversation(current, row.id);
|
|
140
|
-
if (next !== current) client.setQueryData(query.queryKey, next);
|
|
141
|
-
}
|
|
142
|
-
const appended = data.appended ? normalizeConversationMessages(data.appended) : [];
|
|
143
|
-
client.setQueryData<Conversation>(gemieQueryKeys.conversations.detail(row.id), (previous) =>
|
|
144
|
-
previous
|
|
145
|
-
? {
|
|
146
|
-
...previous,
|
|
147
|
-
...row,
|
|
148
|
-
messages: mergeMessages(previous.messages ?? [], appended),
|
|
149
|
-
}
|
|
150
|
-
: previous,
|
|
151
|
-
);
|
|
152
|
-
// A gemie's thread view reads which stretch is active; a message may have started a new one.
|
|
153
|
-
if (appended.length > 0) void client.invalidateQueries({ queryKey: ['agent-thread'] });
|
|
154
|
-
if (data.reload) {
|
|
155
|
-
void client.invalidateQueries({
|
|
156
|
-
queryKey: gemieQueryKeys.conversations.detail(row.id),
|
|
157
|
-
exact: true,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function applyDeleted(client: QueryClient, data: RealtimeData['conversation.deleted']): void {
|
|
163
|
-
for (const query of client
|
|
164
|
-
.getQueryCache()
|
|
165
|
-
.findAll({ queryKey: gemieQueryKeys.conversations.all })) {
|
|
166
|
-
const current = query.state.data as ConversationsInfiniteData | undefined;
|
|
167
|
-
const next = removeConversation(current, data.conversationId);
|
|
168
|
-
if (next !== current) client.setQueryData(query.queryKey, next);
|
|
169
|
-
}
|
|
170
|
-
client.removeQueries({
|
|
171
|
-
queryKey: gemieQueryKeys.conversations.detail(data.conversationId),
|
|
172
|
-
exact: true,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/** Apply one frame to the runtime's own caches. Pure cache writes: safe to call twice. */
|
|
177
|
-
export function applyRealtimeToCache(client: QueryClient, frame: RealtimeFrame): void {
|
|
178
|
-
switch (frame.type) {
|
|
179
|
-
case 'conversation':
|
|
180
|
-
applyConversation(client, frame.data as RealtimeData['conversation']);
|
|
181
|
-
return;
|
|
182
|
-
case 'conversation.deleted':
|
|
183
|
-
applyDeleted(client, frame.data as RealtimeData['conversation.deleted']);
|
|
184
|
-
return;
|
|
185
|
-
case 'message.reaction':
|
|
186
|
-
{
|
|
187
|
-
const update = frame.data as RealtimeData['message.reaction'];
|
|
188
|
-
updateReactionCaches(client, { ...update, reactions: [...update.reactions] });
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
case 'collections':
|
|
192
|
-
client.setQueryData(
|
|
193
|
-
gemieQueryKeys.collections,
|
|
194
|
-
readCollectionsSnapshot(frame.data as RealtimeData['collections']),
|
|
195
|
-
);
|
|
196
|
-
return;
|
|
197
|
-
case 'connections':
|
|
198
|
-
// The person's connected accounts and connectors: their lists are read again, once.
|
|
199
|
-
void client.invalidateQueries({ queryKey: gemieQueryKeys.accounts.all });
|
|
200
|
-
void client.invalidateQueries({ queryKey: ['gemie-connectors', 'connected'] });
|
|
201
|
-
return;
|
|
202
|
-
default:
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** What a client too far behind reads again: the runtime's lists and the open conversations. */
|
|
207
|
-
export function resetRealtimeCache(client: QueryClient): void {
|
|
208
|
-
void client.invalidateQueries({ queryKey: gemieQueryKeys.conversations.all });
|
|
209
|
-
void client.invalidateQueries({ queryKey: ['conversation'] });
|
|
210
|
-
void client.invalidateQueries({ queryKey: gemieQueryKeys.collections });
|
|
211
|
-
void client.invalidateQueries({ queryKey: gemieQueryKeys.accounts.all });
|
|
212
|
-
void client.invalidateQueries({ queryKey: ['gemie-connectors', 'connected'] });
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const attached = new WeakMap<
|
|
216
|
-
QueryClient,
|
|
217
|
-
Map<RealtimeConnection, { refs: number; detach: () => void }>
|
|
218
|
-
>();
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Keep one QueryClient's runtime caches in step with a connection. Nested runtime providers attach
|
|
222
|
-
* the same pair more than once; it is wired once and released with its last holder.
|
|
223
|
-
*/
|
|
224
|
-
export function attachRealtimeCache(
|
|
225
|
-
connection: RealtimeConnection,
|
|
226
|
-
client: QueryClient,
|
|
227
|
-
): () => void {
|
|
228
|
-
let byConnection = attached.get(client);
|
|
229
|
-
if (!byConnection) {
|
|
230
|
-
byConnection = new Map();
|
|
231
|
-
attached.set(client, byConnection);
|
|
232
|
-
}
|
|
233
|
-
const existing = byConnection.get(connection);
|
|
234
|
-
if (existing) {
|
|
235
|
-
existing.refs++;
|
|
236
|
-
} else {
|
|
237
|
-
const offFrames = connection.on('*', (frame) => applyRealtimeToCache(client, frame));
|
|
238
|
-
const offReset = connection.onReset(() => resetRealtimeCache(client));
|
|
239
|
-
byConnection.set(connection, {
|
|
240
|
-
refs: 1,
|
|
241
|
-
detach: () => {
|
|
242
|
-
offFrames();
|
|
243
|
-
offReset();
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
let released = false;
|
|
248
|
-
return () => {
|
|
249
|
-
if (released) return;
|
|
250
|
-
released = true;
|
|
251
|
-
const entry = byConnection?.get(connection);
|
|
252
|
-
if (!entry) return;
|
|
253
|
-
if (--entry.refs > 0) return;
|
|
254
|
-
entry.detach();
|
|
255
|
-
byConnection?.delete(connection);
|
|
256
|
-
};
|
|
257
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ConversationsInfiniteData } from './types';
|
|
2
|
-
|
|
3
|
-
/** A Date, whether it was just fetched or came back from the persisted cache, which keeps JSON. */
|
|
4
|
-
const asDate = (value: Date | string): Date => (value instanceof Date ? value : new Date(value));
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The list as readers see it: its dates are Dates.
|
|
8
|
-
*
|
|
9
|
-
* The list is persisted per account so the sidebar paints from the last session (`ALIA_ACCOUNT_QUERIES`),
|
|
10
|
-
* and persistence is JSON: a hydrated page holds `updatedAt` as an ISO string, not a Date. Reviving
|
|
11
|
-
* them here, where every reader of the list reads it, keeps `Conversation` the type it says it is.
|
|
12
|
-
*/
|
|
13
|
-
export function reviveConversationDates(
|
|
14
|
-
data: ConversationsInfiniteData,
|
|
15
|
-
): ConversationsInfiniteData {
|
|
16
|
-
return {
|
|
17
|
-
...data,
|
|
18
|
-
pages: data.pages.map((page) => ({
|
|
19
|
-
...page,
|
|
20
|
-
conversations: page.conversations.map((conversation) =>
|
|
21
|
-
conversation.updatedAt instanceof Date && conversation.createdAt instanceof Date
|
|
22
|
-
? conversation
|
|
23
|
-
: {
|
|
24
|
-
...conversation,
|
|
25
|
-
createdAt: asDate(conversation.createdAt),
|
|
26
|
-
updatedAt: asDate(conversation.updatedAt),
|
|
27
|
-
},
|
|
28
|
-
),
|
|
29
|
-
})),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The React Query keys of the conversation runtime. The host's persister and its sidebar read
|
|
3
|
-
* the same keys the hooks write, so a list shown anywhere is the list the chat updates.
|
|
4
|
-
*/
|
|
5
|
-
/** What a conversation list may be narrowed to (`GET /v1/conversations?agentId=&app=`). */
|
|
6
|
-
export interface ConversationsFilter {
|
|
7
|
-
/** Only the conversations with this agent. */
|
|
8
|
-
agentId?: string;
|
|
9
|
-
/** Only the conversations started in this app, by its slug (`docs/agent-embedding.md` §6). */
|
|
10
|
-
app?: string;
|
|
11
|
-
/**
|
|
12
|
-
* The conversations the person's gemies have with each other (`gemies`, ADR 0042) instead of the
|
|
13
|
-
* person's own, which are the default and never include them.
|
|
14
|
-
*/
|
|
15
|
-
kind?: 'gemies';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const gemieQueryKeys = {
|
|
19
|
-
/** The person's folders, projects, pins and favourites (`runtime/collections.ts`). */
|
|
20
|
-
collections: ['conversation-collections'] as const,
|
|
21
|
-
conversations: {
|
|
22
|
-
all: ['conversations'] as const,
|
|
23
|
-
detail: (id: string) => ['conversation', id] as const,
|
|
24
|
-
/**
|
|
25
|
-
* The person's conversations narrowed to one agent, one app or both: under `all`, so every
|
|
26
|
-
* write to the list reaches it.
|
|
27
|
-
*/
|
|
28
|
-
filtered: (filter: ConversationsFilter) =>
|
|
29
|
-
['conversations', { agentId: filter.agentId, app: filter.app, kind: filter.kind }] as const,
|
|
30
|
-
},
|
|
31
|
-
/**
|
|
32
|
-
* The person's connected accounts (ADR 0035 as amended): the list with its grants, the code of
|
|
33
|
-
* one being connected and an account's chats. Their own roots, never persisted: phone numbers and
|
|
34
|
-
* a live code stay in memory.
|
|
35
|
-
*/
|
|
36
|
-
accounts: {
|
|
37
|
-
all: ['connected-accounts'] as const,
|
|
38
|
-
qr: (accountId: string) => ['connected-account-qr', accountId] as const,
|
|
39
|
-
chats: (accountId: string) => ['connected-account-chats', accountId] as const,
|
|
40
|
-
},
|
|
41
|
-
/** An agent the chat is opened on: its profile and the state of its feature gates. */
|
|
42
|
-
agents: {
|
|
43
|
-
profile: (id: string) => ['alia-agent-profile', id] as const,
|
|
44
|
-
features: (id: string) => ['alia-agent-features', id] as const,
|
|
45
|
-
},
|
|
46
|
-
/** A conversation somebody shared, by its token. */
|
|
47
|
-
shared: (token: string) => ['alia-shared-conversation', token] as const,
|
|
48
|
-
/**
|
|
49
|
-
* An agent's permanent thread: the stretches behind the open conversation, and finding in them.
|
|
50
|
-
* Keyed by `threadKey(address)`: the handle, or `id:<gemieId>`.
|
|
51
|
-
*/
|
|
52
|
-
threads: {
|
|
53
|
-
/** The thread itself (which conversation is active): the host's own query lives under it. */
|
|
54
|
-
all: (thread: string) => ['agent-thread', thread] as const,
|
|
55
|
-
/**
|
|
56
|
-
* The history, kept apart from the thread itself: re-reading which conversation is active is
|
|
57
|
-
* cheap and happens whenever a new stretch starts, while the pages behind it are immutable and
|
|
58
|
-
* expensive to refetch.
|
|
59
|
-
*/
|
|
60
|
-
messages: (thread: string) => ['agent-thread-messages', thread] as const,
|
|
61
|
-
/** Keyed by the query as typed, so each one is cached and none is re-asked. */
|
|
62
|
-
search: (thread: string, query: string) => ['agent-thread-search', thread, query] as const,
|
|
63
|
-
/** One window of the thread, addressed by the cursor a search hit carries. */
|
|
64
|
-
window: (thread: string, cursor: string) => ['agent-thread-window', thread, cursor] as const,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { InfiniteData, QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { applyMessageReaction, type MessageReactionSnapshot } from './message-reactions';
|
|
3
|
-
import { gemieQueryKeys } from './query-keys';
|
|
4
|
-
import type { ThreadPage } from './thread/thread-history';
|
|
5
|
-
import type { Conversation } from './types';
|
|
6
|
-
|
|
7
|
-
/** Keep already fetched live messages and historical pages consistent with a saved reaction. */
|
|
8
|
-
export function updateReactionCaches(client: QueryClient, update: MessageReactionSnapshot): void {
|
|
9
|
-
client.setQueryData<Conversation>(
|
|
10
|
-
gemieQueryKeys.conversations.detail(update.conversationId),
|
|
11
|
-
(previous) =>
|
|
12
|
-
previous
|
|
13
|
-
? { ...previous, messages: applyMessageReaction(previous.messages ?? [], update) }
|
|
14
|
-
: previous,
|
|
15
|
-
);
|
|
16
|
-
client.setQueriesData<InfiniteData<ThreadPage>>(
|
|
17
|
-
{
|
|
18
|
-
predicate: ({ queryKey }) =>
|
|
19
|
-
queryKey[0] === 'agent-thread-messages' || queryKey[0] === 'agent-thread-window',
|
|
20
|
-
},
|
|
21
|
-
(previous) =>
|
|
22
|
-
previous
|
|
23
|
-
? {
|
|
24
|
-
...previous,
|
|
25
|
-
pages: previous.pages.map((page) => ({
|
|
26
|
-
...page,
|
|
27
|
-
messages: page.messages.map((message) =>
|
|
28
|
-
message.conversationId === update.conversationId &&
|
|
29
|
-
(message.id ?? message.cursor) === update.messageId &&
|
|
30
|
-
(update.revision === undefined ||
|
|
31
|
-
(message.reactionRevision ?? 0) <= update.revision)
|
|
32
|
-
? {
|
|
33
|
-
...message,
|
|
34
|
-
reactions: update.reactions,
|
|
35
|
-
...(update.revision === undefined
|
|
36
|
-
? {}
|
|
37
|
-
: { reactionRevision: update.revision }),
|
|
38
|
-
}
|
|
39
|
-
: message,
|
|
40
|
-
),
|
|
41
|
-
})),
|
|
42
|
-
}
|
|
43
|
-
: previous,
|
|
44
|
-
);
|
|
45
|
-
}
|