@gemies/sdk 6.2.0 → 6.3.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 6.3.1
4
+
5
+ - **A turn's attachments keep the order they were sent in** (`TurnAttachments`): a document sent
6
+ between two photos is drawn between them. Pictures next to each other still share a row.
7
+ - **No voice call in a group**: `GemieChatContent` offers none when `group` is set. A call has one
8
+ gemie and a group's turns are its members'; the API refuses one there too.
9
+
10
+ ## 6.3.0
11
+
12
+ - **A turn's attachments are drawn as media** (`TurnAttachments`, used by every user turn in the
13
+ thread). A file kept in Oxy Files is drawn from the URL Oxy answers the signed-in caller
14
+ (`useFileDownloadUrl`):
15
+ - a photo is a photo, and a channel's sticker a sticker (an animated one by its still);
16
+ - a voice note or audio is a voice message that plays, with its transcript;
17
+ - any other file is a file chip that opens it.
18
+
19
+ A photo sent inline stays the thumbnail it was. Media that arrived on a gemie's Telegram bot or a
20
+ connected account carries `kind`, `description`, `durationSeconds` and `transcript` on its `file`
21
+ part, so the app shows it as the person sent it, not as a line about it.
22
+
3
23
  ## 6.2.0
4
24
 
5
25
  - **The connectors store also lists Docker's MCP catalogue.** `ConnectorEntry.source` may be `docker`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "6.2.0",
3
+ "version": "6.3.1",
4
4
  "description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -507,10 +507,11 @@ function GemieConversationView({
507
507
  },
508
508
  [composer],
509
509
  );
510
- // Without a call handed down (a text-only entry), the chat is text-only whatever `voice` says.
510
+ // Without a call handed down (a text-only entry), the chat is text-only whatever `voice` says. A
511
+ // group is too: a call has one gemie, and a group's turns are its members' (the server refuses it).
511
512
  const VoiceCall = useContext(VoiceCallContext);
512
513
  const voice = useChatVoice({
513
- options: VoiceCall === null ? false : voiceOptions,
514
+ options: VoiceCall === null || group !== undefined ? false : voiceOptions,
514
515
  conversationId,
515
516
  agentId,
516
517
  isFocused,
@@ -22,7 +22,8 @@ import type { ReadAloudState } from '../../hooks/useReadAloud';
22
22
  import type { Vote } from '../../hooks/useMessageVote';
23
23
  import { readAgentCharacter } from '../../lib/agent-character';
24
24
  import { useBubbles } from '../../lib/bubbles';
25
- import { getImagesFromContent, messageText } from '../../lib/content-utils';
25
+ import { messageText } from '../../lib/content-utils';
26
+ import { hasAttachments, TurnAttachments } from './TurnAttachments';
26
27
  import { ANCHORS, useGemieFlights } from '../../lib/flights';
27
28
  import { useLabels } from '../../lib/labels';
28
29
  import { canvasResultOf } from '../../lib/canvas-result';
@@ -32,7 +33,6 @@ import { isWebInvocation, taskListLog, webSearchLog } from '../../lib/work-log';
32
33
  import { useGemieRuntime } from '../../runtime/config';
33
34
  import { type Message, cardOf, formatElapsed, getToolPillLabel } from '../../runtime/model';
34
35
  import type { OpenThought } from '../../hooks/useOpenThought';
35
- import { Image } from '../Image';
36
36
  import { PlanPreviewCard } from '../PlanPreviewCard';
37
37
  import { AskedQuestions } from '../QuestionCard';
38
38
  import { CanvasComponent } from '../canvas/CanvasComponent';
@@ -127,8 +127,8 @@ export const ThreadRow = memo(function ThreadRow({
127
127
  }: ThreadRowProps) {
128
128
  const { t } = useLabels();
129
129
  const text = messageText(message);
130
- const images = message.content ? getImagesFromContent(message.content) : [];
131
130
  const isReply = message.role === 'assistant';
131
+ const attached = !isReply && hasAttachments(message.content);
132
132
  const storedIn = message.unsaved === true ? undefined : conversationId;
133
133
  const hasText = text.length > 0;
134
134
 
@@ -161,7 +161,7 @@ export const ThreadRow = memo(function ThreadRow({
161
161
  const questionActions = [copyAction, editAction].filter(isPresent);
162
162
  return (
163
163
  <Animated.View onLayout={onLayout}>
164
- {text.length === 0 && images.length === 0 ? null : (
164
+ {text.length === 0 && !attached ? null : (
165
165
  // Bloom's user turn, with the breathing room above it the thread has always had.
166
166
  <View className="mt-2 w-full flex-col items-end">
167
167
  <TurnMenu actions={questionActions} label={t('chat.turnActions')}>
@@ -171,40 +171,23 @@ export const ThreadRow = memo(function ThreadRow({
171
171
  <ChatBubble side="user" menu={questionActions} onReply={onQuestionReply}>
172
172
  {(foreground) => (
173
173
  <>
174
- {images.length > 0 && (
175
- <View className="flex-row flex-wrap gap-2">
176
- {images.map((url) => (
177
- <View key={url} className="size-[120px] overflow-hidden rounded-xl">
178
- <Image
179
- source={{ uri: url }}
180
- className="h-full w-full"
181
- contentFit="cover"
182
- />
183
- </View>
184
- ))}
185
- </View>
186
- )}
187
- <Text variant="body-regular" selectable style={{ color: foreground }}>
188
- {text}
189
- </Text>
174
+ <TurnAttachments
175
+ content={message.content}
176
+ tone="outgoing"
177
+ onColor={foreground}
178
+ />
179
+ {text.length > 0 ? (
180
+ <Text variant="body-regular" selectable style={{ color: foreground }}>
181
+ {text}
182
+ </Text>
183
+ ) : null}
190
184
  </>
191
185
  )}
192
186
  </ChatBubble>
193
187
  ) : (
194
188
  <AiChatUserMessage animate={isNew} actions={questionActions}>
195
- {images.length > 0 && (
196
- <View className="flex-row flex-wrap gap-2">
197
- {images.map((url) => (
198
- <View key={url} className="size-[120px] overflow-hidden rounded-xl">
199
- <Image
200
- source={{ uri: url }}
201
- className="h-full w-full"
202
- contentFit="cover"
203
- />
204
- </View>
205
- ))}
206
- </View>
207
- )}
189
+ {/* Bloom's user turn sits on a neutral surface, not the accent. */}
190
+ <TurnAttachments content={message.content} tone="incoming" />
208
191
  {text}
209
192
  </AiChatUserMessage>
210
193
  )}
@@ -0,0 +1,218 @@
1
+ /**
2
+ * A turn's attachments, drawn as the thread draws every attachment: a photo sent inline, and a file
3
+ * kept in Oxy Files — attached in the app, or media that arrived on a channel (a gemie's Telegram
4
+ * bot, a connected account), which says what it was there.
5
+ *
6
+ * - An image is the photo, and a channel's sticker is a sticker (its still, for an animated one).
7
+ * - A voice note or audio is a voice message that plays, with its transcript under it.
8
+ * - Anything else is a file chip that opens the file.
9
+ *
10
+ * A file is private to its person: its URL is the one Oxy answers the signed-in caller
11
+ * (`useFileDownloadUrl`), never a public one. One component for every turn, so a channel's media
12
+ * and the app's own attachments are drawn the same way.
13
+ */
14
+
15
+ import {
16
+ FileMessage,
17
+ ImageMessage,
18
+ StickerMessage,
19
+ VoiceMessage,
20
+ } from '@oxy.so/bloom/message-media';
21
+ import { useFileDownloadUrl, useOxy } from '@oxy.so/services/ui/client';
22
+ import { useEffect, useMemo, useRef, useState } from 'react';
23
+ import { Linking, View } from 'react-native';
24
+ import { useLabels } from '../../lib/labels';
25
+ import { loadExpoAudio } from '../../lib/deferred/expo-audio';
26
+ import {
27
+ getAttachmentsFromContent,
28
+ type MessageContent,
29
+ type TurnAttachment,
30
+ } from '../../lib/content-utils';
31
+ import { Image } from '../Image';
32
+
33
+ type Tone = 'incoming' | 'outgoing';
34
+ /** The bubble's tone, and its own foreground when the app paints a custom bubble. */
35
+ interface Paint {
36
+ tone: Tone;
37
+ onColor?: string;
38
+ }
39
+ type FileAttachment = Extract<TurnAttachment, { type: 'file' }>;
40
+
41
+ /** A waveform for a voice note whose samples were never measured: steady, from its id. */
42
+ export function placeholderWaveform(seed: string, bars = 32): number[] {
43
+ let h = 0;
44
+ for (const char of seed) h = (Math.imul(h, 31) + char.charCodeAt(0)) | 0;
45
+ return Array.from({ length: bars }, (_, i) => {
46
+ h = (Math.imul(h ^ (h >>> 13), 0x5bd1e995) + i) | 0;
47
+ return 0.25 + ((h >>> 0) % 1000) / 1600;
48
+ });
49
+ }
50
+
51
+ function useFileUrl(fileId: string): string | null {
52
+ const { oxyServices } = useOxy();
53
+ return useFileDownloadUrl(oxyServices, fileId).url;
54
+ }
55
+
56
+ function StoredImage({ file, tone, onColor }: { file: FileAttachment } & Paint) {
57
+ const { t } = useLabels();
58
+ const url = useFileUrl(file.fileId);
59
+ if (file.kind === 'sticker') {
60
+ // A sticker IS its meaning: its words name it for a screen reader.
61
+ return url ? (
62
+ <StickerMessage
63
+ source={url}
64
+ tone={tone}
65
+ onColor={onColor}
66
+ size={128}
67
+ accessibilityLabel={file.description ?? t('chat.attachment.sticker')}
68
+ />
69
+ ) : (
70
+ <View className="size-32 rounded-xl bg-surface-secondary" />
71
+ );
72
+ }
73
+ return url ? (
74
+ <ImageMessage
75
+ source={url}
76
+ tone={tone}
77
+ onColor={onColor}
78
+ maxWidth={240}
79
+ maxHeight={280}
80
+ accessibilityLabel={file.description ?? t('chat.attachment.photo')}
81
+ onPress={() => void Linking.openURL(url)}
82
+ />
83
+ ) : (
84
+ <View className="h-40 w-60 rounded-2xl bg-surface-secondary" />
85
+ );
86
+ }
87
+
88
+ function StoredVoice({ file, tone, onColor }: { file: FileAttachment } & Paint) {
89
+ const { t } = useLabels();
90
+ const url = useFileUrl(file.fileId);
91
+ const samples = useMemo(() => placeholderWaveform(file.fileId), [file.fileId]);
92
+ const [playing, setPlaying] = useState(false);
93
+ const [position, setPosition] = useState(0);
94
+ const player = useRef<{ play(): void; pause(): void; remove(): void } | null>(null);
95
+ useEffect(() => () => player.current?.remove(), []);
96
+
97
+ const toggle = async () => {
98
+ if (!url) return;
99
+ if (player.current && playing) {
100
+ player.current.pause();
101
+ setPlaying(false);
102
+ return;
103
+ }
104
+ if (!player.current) {
105
+ const { createAudioPlayer } = await loadExpoAudio();
106
+ const created = createAudioPlayer({ uri: url });
107
+ created.addListener('playbackStatusUpdate', (status) => {
108
+ setPosition(status.currentTime);
109
+ if (status.didJustFinish) {
110
+ setPlaying(false);
111
+ setPosition(0);
112
+ created.seekTo(0);
113
+ }
114
+ });
115
+ player.current = created;
116
+ }
117
+ player.current.play();
118
+ setPlaying(true);
119
+ };
120
+
121
+ return (
122
+ <VoiceMessage
123
+ tone={tone}
124
+ onColor={onColor}
125
+ samples={samples}
126
+ duration={file.durationSeconds ?? 0}
127
+ position={position}
128
+ playing={playing}
129
+ onPlayPress={() => void toggle()}
130
+ transcript={file.transcript}
131
+ transcribeLabel={t('chat.attachment.transcribe')}
132
+ hideTranscriptLabel={t('chat.attachment.hideTranscript')}
133
+ accessibilityLabel={file.description ?? t('chat.attachment.voice')}
134
+ />
135
+ );
136
+ }
137
+
138
+ function StoredFile({ file, tone, onColor }: { file: FileAttachment } & Paint) {
139
+ const url = useFileUrl(file.fileId);
140
+ return (
141
+ <FileMessage
142
+ tone={tone}
143
+ onColor={onColor}
144
+ name={file.filename}
145
+ mimeType={file.mime}
146
+ accessibilityLabel={file.description ?? file.filename}
147
+ onPress={url ? () => void Linking.openURL(url) : undefined}
148
+ />
149
+ );
150
+ }
151
+
152
+ function Attachment({ item, tone, onColor }: { item: TurnAttachment } & Paint) {
153
+ if (item.type === 'inline-image') {
154
+ return (
155
+ <View className="size-[120px] overflow-hidden rounded-xl">
156
+ <Image source={{ uri: item.url }} className="h-full w-full" contentFit="cover" />
157
+ </View>
158
+ );
159
+ }
160
+ if (item.mime.startsWith('image/')) {
161
+ return <StoredImage file={item} tone={tone} onColor={onColor} />;
162
+ }
163
+ if (item.mime.startsWith('audio/')) {
164
+ return <StoredVoice file={item} tone={tone} onColor={onColor} />;
165
+ }
166
+ return <StoredFile file={item} tone={tone} onColor={onColor} />;
167
+ }
168
+
169
+ /** The turn's attachments, or nothing when it has none. */
170
+ export function TurnAttachments({
171
+ content,
172
+ tone = 'incoming',
173
+ onColor,
174
+ }: {
175
+ content: MessageContent | null | undefined;
176
+ tone?: Tone;
177
+ onColor?: string;
178
+ }) {
179
+ const runs = attachmentRuns(getAttachmentsFromContent(content));
180
+ if (runs.length === 0) return null;
181
+ return (
182
+ <View className="gap-2">
183
+ {runs.map((run) =>
184
+ Array.isArray(run) ? (
185
+ <View key={`images:${run[0]?.url}`} className="flex-row flex-wrap gap-2">
186
+ {run.map((item) => (
187
+ <Attachment key={item.url} item={item} tone={tone} onColor={onColor} />
188
+ ))}
189
+ </View>
190
+ ) : (
191
+ <Attachment key={run.fileId} item={run} tone={tone} onColor={onColor} />
192
+ ),
193
+ )}
194
+ </View>
195
+ );
196
+ }
197
+
198
+ type InlineImage = Extract<TurnAttachment, { type: 'inline-image' }>;
199
+
200
+ /**
201
+ * The attachments in the order they were sent, the pictures next to each other drawn as one row.
202
+ * Drawing every picture first put a document sent between two photos after both of them.
203
+ */
204
+ function attachmentRuns(items: readonly TurnAttachment[]): Array<InlineImage[] | FileAttachment> {
205
+ const runs: Array<InlineImage[] | FileAttachment> = [];
206
+ for (const item of items) {
207
+ const last = runs.at(-1);
208
+ if (item.type === 'file') runs.push(item);
209
+ else if (Array.isArray(last)) last.push(item);
210
+ else runs.push([item]);
211
+ }
212
+ return runs;
213
+ }
214
+
215
+ /** Whether a turn has anything to draw as an attachment. */
216
+ export function hasAttachments(content: MessageContent | null | undefined): boolean {
217
+ return getAttachmentsFromContent(content).length > 0;
218
+ }
@@ -44,3 +44,52 @@ export function getImagesFromContent(content: MessageContent | null | undefined)
44
44
  )
45
45
  .map((p) => p.image_url.url);
46
46
  }
47
+
48
+ /**
49
+ * One attachment of a turn, as the thread draws it: a photo sent inline (`image_url`), or a file kept
50
+ * in Oxy Files (`file`) — attached in the app, or media that arrived on a channel, which says what it
51
+ * was there (`kind`: a sticker, a voice note…), how long it lasts and, for audio, what it says.
52
+ */
53
+ export type TurnAttachment =
54
+ | { readonly type: 'inline-image'; readonly url: string }
55
+ | {
56
+ readonly type: 'file';
57
+ readonly fileId: string;
58
+ readonly filename: string;
59
+ readonly mime: string;
60
+ readonly kind?: string;
61
+ readonly description?: string;
62
+ readonly durationSeconds?: number;
63
+ readonly transcript?: string;
64
+ };
65
+
66
+ /** A turn's attachments, in order. */
67
+ export function getAttachmentsFromContent(
68
+ content: MessageContent | null | undefined,
69
+ ): TurnAttachment[] {
70
+ if (!Array.isArray(content)) return [];
71
+ const out: TurnAttachment[] = [];
72
+ for (const part of content) {
73
+ if (part.type === 'image_url' && typeof part.image_url?.url === 'string') {
74
+ out.push({ type: 'inline-image', url: part.image_url.url });
75
+ continue;
76
+ }
77
+ const file = part.type === 'file' ? (part.file as Record<string, unknown> | undefined) : null;
78
+ if (!file || typeof file.file_id !== 'string' || file.file_id === '') continue;
79
+ const text = (key: string) =>
80
+ typeof file[key] === 'string' ? (file[key] as string) : undefined;
81
+ out.push({
82
+ type: 'file',
83
+ fileId: file.file_id,
84
+ filename: text('filename') ?? file.file_id,
85
+ mime: (text('mime') ?? 'application/octet-stream').toLowerCase(),
86
+ ...(text('kind') ? { kind: text('kind') } : {}),
87
+ ...(text('description') ? { description: text('description') } : {}),
88
+ ...(typeof file.durationSeconds === 'number'
89
+ ? { durationSeconds: file.durationSeconds }
90
+ : {}),
91
+ ...(text('transcript') ? { transcript: text('transcript') } : {}),
92
+ });
93
+ }
94
+ return out;
95
+ }
@@ -71,6 +71,12 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
71
71
  'chat.bloom.taskStopped': "Didn't finish",
72
72
  'chat.bloom.visited': 'Visited',
73
73
  'chat.bloom.writingFile': 'Writing',
74
+ 'chat.attachment.photo': 'Photo',
75
+ 'chat.attachment.sticker': 'Sticker',
76
+ 'chat.attachment.voice': 'Voice note',
77
+ 'chat.attachment.transcribe': 'Transcript',
78
+ 'chat.attachment.hideTranscript': 'Hide transcript',
79
+ 'chat.attachment.unavailable': "This file can't be opened",
74
80
  'chat.copied': 'Copied!',
75
81
  'chat.copiedToClipboard': 'Copied to clipboard',
76
82
  'chat.copy': 'Copy',
@@ -67,6 +67,12 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
67
67
  'chat.bloom.taskStopped': 'No terminó',
68
68
  'chat.bloom.visited': 'Visitó',
69
69
  'chat.bloom.writingFile': 'Escribiendo',
70
+ 'chat.attachment.photo': 'Foto',
71
+ 'chat.attachment.sticker': 'Sticker',
72
+ 'chat.attachment.voice': 'Nota de voz',
73
+ 'chat.attachment.transcribe': 'Transcripción',
74
+ 'chat.attachment.hideTranscript': 'Ocultar transcripción',
75
+ 'chat.attachment.unavailable': 'No se puede abrir este archivo',
70
76
  'chat.copied': '¡Copiado!',
71
77
  'chat.copiedToClipboard': 'Copiado al portapapeles',
72
78
  'chat.copy': 'Copiar',