@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Entity,
|
|
3
|
+
type EntityOptions,
|
|
4
|
+
entity,
|
|
5
|
+
type RecordSource,
|
|
6
|
+
type RecordSourceOptions,
|
|
7
|
+
type RecordView,
|
|
8
|
+
type Skip,
|
|
9
|
+
skip,
|
|
10
|
+
source,
|
|
11
|
+
useRecord,
|
|
12
|
+
} from '@oxy.so/bloom-data';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A server answer held whole, under the key of the read that returned it.
|
|
16
|
+
*
|
|
17
|
+
* Conversations are records by id (`Conversations`). Most other reads of the runtime return one
|
|
18
|
+
* value that is not: an agent's profile, the person's collections, a thread's search hits, the
|
|
19
|
+
* accounts they connected. Such an answer is one record whose id is the read's key, so it is read,
|
|
20
|
+
* refreshed, shared between callers and dropped with its account's store like any other record.
|
|
21
|
+
* An answer the account holds once is under `ACCOUNT`: every account has its own store.
|
|
22
|
+
*/
|
|
23
|
+
export interface Answer<T> {
|
|
24
|
+
/** The key of the read that returned it. */
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly value: T;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AnswerSourceOptions<A extends unknown[], T>
|
|
30
|
+
extends Omit<RecordSourceOptions<A, Answer<T>>, 'load' | 'index' | 'put'> {
|
|
31
|
+
/** The answer; it is held under `key(...args)`. */
|
|
32
|
+
load: (request: { readonly signal: AbortSignal }, ...args: NoInfer<A>) => Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Copy the answers to the account's durable store; a `version` drops the stored answers when it
|
|
35
|
+
* changes (bump it with any change to the answer's shape).
|
|
36
|
+
*/
|
|
37
|
+
persist?: EntityOptions<Answer<T>>['persist'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A record source whose records are the answers of `load`, one per key. `type` names its entity. */
|
|
41
|
+
export interface AnswerSource<A extends unknown[], T> extends RecordSource<A, Answer<T>> {
|
|
42
|
+
readonly entity: Entity<Answer<T>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function answerSource<A extends unknown[], T>(
|
|
46
|
+
type: string,
|
|
47
|
+
{ load, persist, ...options }: AnswerSourceOptions<A, T>,
|
|
48
|
+
): AnswerSource<A, T> {
|
|
49
|
+
return source(entity<Answer<T>>(type, { id: (answer) => answer.id, persist }), {
|
|
50
|
+
...options,
|
|
51
|
+
load: async (request, ...args) => ({
|
|
52
|
+
id: options.key(...args),
|
|
53
|
+
value: await load(request, ...args),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Observes an answer source for `args` (or nothing, with `skip`) and returns the answer as the
|
|
60
|
+
* view's `value`. An answer held from an earlier read of the key (a disk copy, another screen's)
|
|
61
|
+
* shows at once while the read runs.
|
|
62
|
+
*/
|
|
63
|
+
export function useAnswer<A extends unknown[], T>(
|
|
64
|
+
answers: AnswerSource<A, T>,
|
|
65
|
+
...args: A | [Skip]
|
|
66
|
+
): RecordView<T> {
|
|
67
|
+
const view = useRecord(answers, ...args);
|
|
68
|
+
const observed = args[0] !== skip;
|
|
69
|
+
const value = view.value?.value;
|
|
70
|
+
return {
|
|
71
|
+
...view,
|
|
72
|
+
value,
|
|
73
|
+
isLoading: observed && value === undefined && view.status !== 'error',
|
|
74
|
+
isFetching: view.fetchStatus === 'fetching' || (observed && view.status === 'idle'),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the person files their conversations (folders, projects, pins, favourites), held whole as
|
|
3
|
+
* one answer in the signed-in account's store (Gemies `docs/realtime.mdx`, "Collections").
|
|
4
|
+
*
|
|
5
|
+
* Every change is drawn at once (its optimistic layer), sent, and replaced by the snapshot the
|
|
6
|
+
* server answers; a refusal drops the layer, which puts the server's state back. The other devices
|
|
7
|
+
* receive the same snapshot as the realtime `collections` event.
|
|
8
|
+
*/
|
|
9
|
+
import { action } from '@oxy.so/bloom-data';
|
|
10
|
+
import type { CollectionsSnapshotWire } from '../../realtime/contract';
|
|
11
|
+
import type { GemieApi } from '../api';
|
|
12
|
+
import {
|
|
13
|
+
type CollectionFields,
|
|
14
|
+
type ConversationCollection,
|
|
15
|
+
type ConversationCollectionKind,
|
|
16
|
+
type ConversationCollections,
|
|
17
|
+
type LocalCollections,
|
|
18
|
+
readCollectionsSnapshot,
|
|
19
|
+
} from '../collections-model';
|
|
20
|
+
import { API_ROUTES } from '../routes';
|
|
21
|
+
import { rereadOn } from '../../realtime/reread';
|
|
22
|
+
import { answerSource } from './answer';
|
|
23
|
+
import { ACCOUNT, gemieRead } from './read';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The person's collections: read once per account, then kept by the `collections` event (no timer,
|
|
27
|
+
* no refocus); a realtime reset reads them again.
|
|
28
|
+
*/
|
|
29
|
+
export const conversationCollections = answerSource('gemies.collections', {
|
|
30
|
+
...gemieRead,
|
|
31
|
+
persist: true,
|
|
32
|
+
key: (_api: GemieApi) => ACCOUNT,
|
|
33
|
+
stale: Number.POSITIVE_INFINITY,
|
|
34
|
+
load: async ({ signal }, api) =>
|
|
35
|
+
readCollectionsSnapshot(
|
|
36
|
+
(await api.get<CollectionsSnapshotWire>(API_ROUTES.collections.list, { signal })).data,
|
|
37
|
+
),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
rereadOn('reset', conversationCollections);
|
|
41
|
+
|
|
42
|
+
/** The snapshot as the server (or another device) answered it. */
|
|
43
|
+
export function storeCollections(snapshot: ConversationCollections): void {
|
|
44
|
+
conversationCollections.entity.put({ id: ACCOUNT, value: snapshot });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Draws a change over the held snapshot, as the calling action's layer. */
|
|
48
|
+
function draw(change: (current: ConversationCollections) => ConversationCollections): void {
|
|
49
|
+
conversationCollections.entity.update(ACCOUNT, (held) => ({
|
|
50
|
+
id: ACCOUNT,
|
|
51
|
+
value: change(held.value),
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const settle = ({ data }: { data: CollectionsSnapshotWire }) =>
|
|
56
|
+
storeCollections(readCollectionsSnapshot(data));
|
|
57
|
+
|
|
58
|
+
const edit =
|
|
59
|
+
(id: string, change: (c: ConversationCollection) => ConversationCollection) =>
|
|
60
|
+
(current: ConversationCollections): ConversationCollections => ({
|
|
61
|
+
...current,
|
|
62
|
+
collections: current.collections.map((c) => (c.id === id ? change(c) : c)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/** `ids` with `id` in it (`on`) or out of it, unchanged when it already is. */
|
|
66
|
+
const toggle = (ids: readonly string[], id: string, on: boolean): string[] =>
|
|
67
|
+
on ? (ids.includes(id) ? [...ids] : [...ids, id]) : ids.filter((x) => x !== id);
|
|
68
|
+
|
|
69
|
+
const R = API_ROUTES.collections;
|
|
70
|
+
|
|
71
|
+
export const createCollection = action({
|
|
72
|
+
optimistic: (
|
|
73
|
+
_api: GemieApi,
|
|
74
|
+
kind: ConversationCollectionKind,
|
|
75
|
+
fields: CollectionFields & { name: string },
|
|
76
|
+
) =>
|
|
77
|
+
draw((current) => {
|
|
78
|
+
const now = new Date().toISOString();
|
|
79
|
+
return {
|
|
80
|
+
...current,
|
|
81
|
+
collections: [
|
|
82
|
+
...current.collections,
|
|
83
|
+
{
|
|
84
|
+
id: `pending-${Date.now()}`,
|
|
85
|
+
kind,
|
|
86
|
+
name: fields.name,
|
|
87
|
+
description: fields.description ?? null,
|
|
88
|
+
icon: fields.icon ?? null,
|
|
89
|
+
color: fields.color ?? null,
|
|
90
|
+
isFavorite: false,
|
|
91
|
+
isExpanded: true,
|
|
92
|
+
conversationIds: [],
|
|
93
|
+
createdAt: now,
|
|
94
|
+
updatedAt: now,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
}),
|
|
99
|
+
run: (api, kind, fields) => api.post<CollectionsSnapshotWire>(R.create, { kind, ...fields }),
|
|
100
|
+
settle,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const updateCollection = action({
|
|
104
|
+
optimistic: (_api: GemieApi, id: string, fields: CollectionFields) =>
|
|
105
|
+
draw(edit(id, (c) => ({ ...c, ...fields, name: fields.name ?? c.name }))),
|
|
106
|
+
run: (api, id, fields) => api.patch<CollectionsSnapshotWire>(R.one(id), fields),
|
|
107
|
+
settle,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export const deleteCollection = action({
|
|
111
|
+
optimistic: (_api: GemieApi, id: string) =>
|
|
112
|
+
draw((current) => ({
|
|
113
|
+
...current,
|
|
114
|
+
collections: current.collections.filter((c) => c.id !== id),
|
|
115
|
+
})),
|
|
116
|
+
run: (api, id) => api.delete<CollectionsSnapshotWire>(R.one(id)),
|
|
117
|
+
settle,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/** Files a conversation in a collection (`member: true`) or takes it out. */
|
|
121
|
+
export const setCollectionMember = action({
|
|
122
|
+
optimistic: (_api: GemieApi, id: string, conversationId: string, member: boolean) =>
|
|
123
|
+
draw(
|
|
124
|
+
edit(id, (c) => ({
|
|
125
|
+
...c,
|
|
126
|
+
conversationIds: toggle(c.conversationIds, conversationId, member),
|
|
127
|
+
})),
|
|
128
|
+
),
|
|
129
|
+
run: (api, id, conversationId, member) =>
|
|
130
|
+
member
|
|
131
|
+
? api.put<CollectionsSnapshotWire>(R.member(id, conversationId))
|
|
132
|
+
: api.delete<CollectionsSnapshotWire>(R.member(id, conversationId)),
|
|
133
|
+
settle,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export const setConversationPinned = action({
|
|
137
|
+
optimistic: (_api: GemieApi, conversationId: string, pinned: boolean) =>
|
|
138
|
+
draw((current) => ({ ...current, pinned: toggle(current.pinned, conversationId, pinned) })),
|
|
139
|
+
run: (api, conversationId, pinned) =>
|
|
140
|
+
api.patch<CollectionsSnapshotWire>(API_ROUTES.conversations.marks(conversationId), { pinned }),
|
|
141
|
+
settle,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const setConversationFavorite = action({
|
|
145
|
+
optimistic: (_api: GemieApi, conversationId: string, favorite: boolean) =>
|
|
146
|
+
draw((current) => ({
|
|
147
|
+
...current,
|
|
148
|
+
favorites: toggle(current.favorites, conversationId, favorite),
|
|
149
|
+
})),
|
|
150
|
+
run: (api, conversationId, favorite) =>
|
|
151
|
+
api.patch<CollectionsSnapshotWire>(API_ROUTES.conversations.marks(conversationId), {
|
|
152
|
+
favorite,
|
|
153
|
+
}),
|
|
154
|
+
settle,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Brings what this device filed before collections were the account's into the account (the
|
|
159
|
+
* server merges by name, so every device may bring its own); the account's snapshot it answers is
|
|
160
|
+
* stored and returned.
|
|
161
|
+
*/
|
|
162
|
+
export const importCollections = action({
|
|
163
|
+
run: async (api: GemieApi, local: LocalCollections) => {
|
|
164
|
+
const { data } = await api.post<CollectionsSnapshotWire>(R.import, local);
|
|
165
|
+
return readCollectionsSnapshot(data);
|
|
166
|
+
},
|
|
167
|
+
settle: storeCollections,
|
|
168
|
+
});
|