@gemies/sdk 0.0.0-stage → 1.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 +1662 -0
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +516 -2
- package/package.json +102 -4
- package/src/animations.ts +5 -0
- package/src/ask-eager.ts +8 -0
- package/src/ask-text.ts +11 -0
- package/src/ask.ts +12 -0
- package/src/avatar.ts +13 -0
- package/src/character.ts +1 -0
- package/src/components/AmbientField.tsx +580 -0
- package/src/components/ComposerDropZone.tsx +235 -0
- package/src/components/ComposerSuggestions.tsx +45 -0
- package/src/components/GemieAskCore.tsx +184 -0
- package/src/components/GemieAskProvider.tsx +18 -0
- package/src/components/GemieAskProviderLazy.tsx +27 -0
- package/src/components/GemieAskProviderText.tsx +25 -0
- package/src/components/GemieAskSheet.tsx +51 -0
- package/src/components/GemieAskSheetWithVoice.tsx +10 -0
- package/src/components/GemieAvatar.tsx +57 -0
- package/src/components/GemieAvatarIcon.tsx +35 -0
- package/src/components/GemieChatContent.tsx +900 -0
- package/src/components/GemieChatHeader.tsx +123 -0
- package/src/components/GemieChatScreen.tsx +170 -0
- package/src/components/GemieChatSheet.tsx +368 -0
- package/src/components/GemieChatWithVoice.tsx +13 -0
- package/src/components/GemieComposer.tsx +388 -0
- package/src/components/GemieGroupWelcome.tsx +37 -0
- package/src/components/GemieParticipants.tsx +133 -0
- package/src/components/GemieParticipantsHeader.tsx +27 -0
- package/src/components/GemieRecentConversations.tsx +65 -0
- package/src/components/GemieSharedConversation.tsx +87 -0
- package/src/components/GemieWelcomeMessage.tsx +58 -0
- package/src/components/IdentityMark.tsx +225 -0
- package/src/components/Image.tsx +12 -0
- package/src/components/InertWhen.tsx +48 -0
- package/src/components/PlanPreviewCard.tsx +53 -0
- package/src/components/QuestionCard.tsx +64 -0
- package/src/components/ReplyMarkdown.tsx +373 -0
- package/src/components/RichBlocks.tsx +195 -0
- package/src/components/VoiceModeIcon.tsx +18 -0
- package/src/components/canvas/CanvasComponent.tsx +65 -0
- package/src/components/canvas/ChartRenderer.tsx +73 -0
- package/src/components/canvas/CodeRenderer.tsx +20 -0
- package/src/components/canvas/DashboardRenderer.tsx +70 -0
- package/src/components/canvas/DeckRenderer.tsx +43 -0
- package/src/components/canvas/FormRenderer.tsx +101 -0
- package/src/components/canvas/MarkdownRenderer.tsx +14 -0
- package/src/components/canvas/TableRenderer.tsx +47 -0
- package/src/components/icons/RiEmojiPicker.tsx +39 -0
- package/src/components/icons/RiMoreDots.tsx +32 -0
- package/src/components/icons/RiReplyLine.tsx +25 -0
- package/src/components/thought/FilesAndSources.tsx +120 -0
- package/src/components/thought/ThoughtPanel.tsx +426 -0
- package/src/components/thought/ToolStep.tsx +134 -0
- package/src/components/thread/AgentExchangeView.tsx +112 -0
- package/src/components/thread/AgentResultCard.tsx +125 -0
- package/src/components/thread/AgentTaskCard.tsx +127 -0
- package/src/components/thread/ChatBubble.tsx +256 -0
- package/src/components/thread/GemieThread.tsx +455 -0
- package/src/components/thread/MessageBlockBoundary.tsx +78 -0
- package/src/components/thread/NewConversationOffer.tsx +54 -0
- package/src/components/thread/ThreadRow.tsx +598 -0
- package/src/components/thread/ThreadSearch.tsx +130 -0
- package/src/components/thread/ThreadSkeleton.tsx +30 -0
- package/src/components/thread/ToolResultCard.tsx +254 -0
- package/src/components/thread/TurnMenu.tsx +54 -0
- package/src/components/thread/TurnStatusLine.tsx +34 -0
- package/src/components/voice/GemieVoiceCall.tsx +21 -0
- package/src/components/voice/GemieVoiceCall.web.tsx +17 -0
- package/src/components/voice/VoiceCallContext.ts +13 -0
- package/src/components/voice/VoiceControls.tsx +106 -0
- package/src/components/voice/VoiceSession.tsx +120 -0
- package/src/components/voice/withVoiceCall.tsx +25 -0
- package/src/csp.ts +50 -0
- package/src/dictation.ts +40 -0
- package/src/hooks/useAmbientWave.ts +184 -0
- package/src/hooks/useAtBottom.ts +51 -0
- package/src/hooks/useAttachMenu.ts +93 -0
- package/src/hooks/useAttachmentIntake.ts +401 -0
- package/src/hooks/useAudioLevelMonitor.ts +46 -0
- package/src/hooks/useAudioLevels.ts +51 -0
- package/src/hooks/useChatComposer.ts +309 -0
- package/src/hooks/useChatVoice.ts +129 -0
- package/src/hooks/useComposerSuggestions.ts +84 -0
- package/src/hooks/useDictation.ts +292 -0
- package/src/hooks/useDocumentPicker.ts +11 -0
- package/src/hooks/useFailedTurnToast.ts +43 -0
- package/src/hooks/useFocusWhenPresented.ts +41 -0
- package/src/hooks/useGemieActivity.ts +31 -0
- package/src/hooks/useImagePicker.ts +38 -0
- package/src/hooks/useMessageReactions.ts +119 -0
- package/src/hooks/useMessageVote.ts +50 -0
- package/src/hooks/useOpenThought.ts +79 -0
- package/src/hooks/usePendingQuestions.ts +19 -0
- package/src/hooks/useReadAloud.ts +92 -0
- package/src/hooks/useShareHandler.ts +24 -0
- package/src/hooks/useSoundEffects.ts +137 -0
- package/src/hooks/useTTS.ts +303 -0
- package/src/hooks/useThoughtScope.ts +59 -0
- package/src/hooks/useThreadRows.ts +157 -0
- package/src/hooks/useThreadView.ts +67 -0
- package/src/hooks/useTimelineWindow.ts +256 -0
- package/src/hooks/useVoiceLauncher.ts +180 -0
- package/src/hooks/useVoiceRoom.ts +212 -0
- package/src/index.ts +140 -0
- package/src/lib/activity-socket.ts +102 -0
- package/src/lib/activity-store.ts +53 -0
- package/src/lib/add-menu.ts +7 -0
- package/src/lib/agent-character.ts +28 -0
- package/src/lib/alia-character.ts +14 -0
- package/src/lib/attachment-intake.ts +154 -0
- package/src/lib/attachment-tiles.ts +74 -0
- package/src/lib/audio-level.ts +130 -0
- package/src/lib/audio-request-auth.ts +4 -0
- package/src/lib/audio-session-binding.ts +27 -0
- package/src/lib/bubbles.tsx +16 -0
- package/src/lib/call-thread.ts +33 -0
- package/src/lib/canvas-result.ts +21 -0
- package/src/lib/catalogue-tool.ts +22 -0
- package/src/lib/citations.ts +192 -0
- package/src/lib/clipboard.ts +23 -0
- package/src/lib/content-utils.ts +46 -0
- package/src/lib/copy-en.ts +291 -0
- package/src/lib/copy-es.ts +287 -0
- package/src/lib/copy.ts +38 -0
- package/src/lib/deferred/document-picker.ts +2 -0
- package/src/lib/deferred/document-picker.web.ts +12 -0
- package/src/lib/deferred/expo-audio.ts +2 -0
- package/src/lib/deferred/expo-audio.web.ts +12 -0
- package/src/lib/deferred/image-data-url.ts +5 -0
- package/src/lib/deferred/image-data-url.web.ts +12 -0
- package/src/lib/dictation-protocol.ts +142 -0
- package/src/lib/dictation-recorder-types.ts +37 -0
- package/src/lib/dictation-recorder.native.ts +90 -0
- package/src/lib/dictation-recorder.ts +131 -0
- package/src/lib/dictation-stream.ts +238 -0
- package/src/lib/dictation.ts +216 -0
- package/src/lib/document-picker.ts +31 -0
- package/src/lib/domain.ts +12 -0
- package/src/lib/flights.ts +33 -0
- package/src/lib/focus-return.ts +66 -0
- package/src/lib/greeting.ts +15 -0
- package/src/lib/image-data-url.ts +35 -0
- package/src/lib/keyboard.native.tsx +25 -0
- package/src/lib/keyboard.tsx +55 -0
- package/src/lib/labels-es.ts +113 -0
- package/src/lib/labels.tsx +207 -0
- package/src/lib/origins.ts +28 -0
- package/src/lib/participants.ts +97 -0
- package/src/lib/pcm.ts +57 -0
- package/src/lib/power-level-options.ts +66 -0
- package/src/lib/questions.ts +92 -0
- package/src/lib/speech-language.ts +20 -0
- package/src/lib/speech-messages.ts +54 -0
- package/src/lib/speech-synthesis.ts +156 -0
- package/src/lib/suggestions.ts +53 -0
- package/src/lib/task-labels.ts +35 -0
- package/src/lib/text-input.ts +10 -0
- package/src/lib/tool-call-status.ts +28 -0
- package/src/lib/tool-icons.ts +36 -0
- package/src/lib/tool-registry.ts +71 -0
- package/src/lib/tool-renderers.tsx +32 -0
- package/src/lib/turn-state.ts +15 -0
- package/src/lib/utils.ts +35 -0
- package/src/lib/voice-audio-engine-types.ts +59 -0
- package/src/lib/voice-audio-engine.native.ts +232 -0
- package/src/lib/voice-audio-engine.ts +206 -0
- package/src/lib/voice-call-request.ts +49 -0
- package/src/lib/voice-call.ts +627 -0
- package/src/lib/voice-controls-labels.ts +31 -0
- package/src/lib/voice-levels.ts +64 -0
- package/src/lib/voice-protocol.ts +328 -0
- package/src/lib/voice-worklets.ts +19 -0
- package/src/lib/work-log.ts +370 -0
- package/src/metro/chart-importers.json +18 -0
- package/src/metro/granular-charts.js +3 -0
- package/src/metro/index.cjs +227 -0
- package/src/metro/index.d.cts +5 -0
- package/src/runtime/agents.ts +151 -0
- package/src/runtime/api.ts +144 -0
- package/src/runtime/app-assertion.ts +51 -0
- package/src/runtime/attachment-utils.ts +97 -0
- package/src/runtime/chat-turn-control.ts +74 -0
- package/src/runtime/composer-draft-store.ts +270 -0
- package/src/runtime/config.tsx +222 -0
- package/src/runtime/conversation-dates.ts +31 -0
- package/src/runtime/conversation-store.ts +49 -0
- package/src/runtime/conversations.ts +633 -0
- package/src/runtime/error-utils.ts +144 -0
- package/src/runtime/host-tools.ts +290 -0
- package/src/runtime/index.ts +137 -0
- package/src/runtime/message-history.ts +124 -0
- package/src/runtime/message-reactions.ts +214 -0
- package/src/runtime/model.ts +39 -0
- package/src/runtime/oxy-files.ts +37 -0
- package/src/runtime/power-levels.ts +66 -0
- package/src/runtime/query-keys.ts +49 -0
- package/src/runtime/random-uuid.ts +25 -0
- package/src/runtime/reaction-cache.ts +45 -0
- package/src/runtime/room-events.ts +333 -0
- package/src/runtime/routes.ts +81 -0
- package/src/runtime/sharing.ts +217 -0
- package/src/runtime/sse-frame-reader.ts +88 -0
- package/src/runtime/stream-events.ts +154 -0
- package/src/runtime/stream-outcome.ts +21 -0
- package/src/runtime/thought-store.ts +103 -0
- package/src/runtime/thread/agent-activity.ts +261 -0
- package/src/runtime/thread/agent-exchange.ts +94 -0
- package/src/runtime/thread/automation-labels.ts +79 -0
- package/src/runtime/thread/conversation-export.ts +135 -0
- package/src/runtime/thread/message-days.ts +120 -0
- package/src/runtime/thread/message-processor.ts +93 -0
- package/src/runtime/thread/speaker-changes.ts +66 -0
- package/src/runtime/thread/task-utils.ts +11 -0
- package/src/runtime/thread/thought-utils.ts +750 -0
- package/src/runtime/thread/thread-history.ts +139 -0
- package/src/runtime/thread/timeline.ts +202 -0
- package/src/runtime/thread/title-tags.ts +8 -0
- package/src/runtime/thread/tool-cards.ts +387 -0
- package/src/runtime/turn-failure.ts +108 -0
- package/src/runtime/turn-preparation.ts +21 -0
- package/src/runtime/types.ts +172 -0
- package/src/runtime/usage-limit-error.ts +44 -0
- package/src/runtime/use-agent-activity.ts +80 -0
- package/src/runtime/use-conversation-stream.ts +1669 -0
- package/src/runtime/use-conversation-thread.ts +590 -0
- package/src/runtime/use-gemie-thread.ts +54 -0
- package/src/runtime/use-room-events.ts +75 -0
- package/src/runtime/use-start-conversation.ts +107 -0
- package/src/runtime/use-thread-history.ts +73 -0
- package/src/runtime/use-thread-search.ts +100 -0
- package/src/runtime/use-turn-edit.ts +99 -0
- package/src/text.ts +19 -0
- package/src/theme.ts +16 -0
- package/src/tools.ts +27 -0
- package/src/types.ts +161 -0
- package/src/voice-messages.ts +2 -0
- package/src/voice.ts +67 -0
- package/tsconfig.json +17 -0
- package/worklets/voice-processors.js +152 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where keyboard focus goes back to when the execution panel closes.
|
|
5
|
+
*
|
|
6
|
+
* The panel is opened from a row in the conversation — a tool step, the
|
|
7
|
+
* sources row, the reasoning trigger — and on the web the desktop rail is not
|
|
8
|
+
* a dialog: nothing moves focus into it and nothing would move it back. So a
|
|
9
|
+
* screen-reader or keyboard user who opened it and pressed Escape was left
|
|
10
|
+
* with focus wherever the browser had put it, which after a click on a
|
|
11
|
+
* `Pressable` is `body` in Safari. The opener is remembered here at open time
|
|
12
|
+
* and focused again at close.
|
|
13
|
+
*
|
|
14
|
+
* One slot, module-level: there is one panel, and the store's own selection
|
|
15
|
+
* already says which message it is about. A DOM element in the store would
|
|
16
|
+
* also be a DOM element in a persisted store's state tree, which it must not
|
|
17
|
+
* be.
|
|
18
|
+
*/
|
|
19
|
+
type Focusable = { focus: () => void };
|
|
20
|
+
|
|
21
|
+
let opener: Focusable | null = null;
|
|
22
|
+
|
|
23
|
+
function isFocusable(value: unknown): value is Focusable {
|
|
24
|
+
return (
|
|
25
|
+
typeof value === 'object' &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
typeof (value as { focus?: unknown }).focus === 'function'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Remember what opened the panel. A caller with a ref to its own control
|
|
33
|
+
* passes it; one without (a memoised row whose ref would be one more prop)
|
|
34
|
+
* lets this read the element that is focused right now, which on the web is
|
|
35
|
+
* the button that was just activated by keyboard, and the button or `body`
|
|
36
|
+
* after a pointer press depending on the browser. Nothing is remembered on
|
|
37
|
+
* native, where focus does not work this way.
|
|
38
|
+
*/
|
|
39
|
+
export function rememberOpener(candidate?: unknown): void {
|
|
40
|
+
if (isFocusable(candidate)) {
|
|
41
|
+
opener = candidate;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (
|
|
45
|
+
Platform.OS === 'web' &&
|
|
46
|
+
typeof document !== 'undefined' &&
|
|
47
|
+
isFocusable(document.activeElement)
|
|
48
|
+
) {
|
|
49
|
+
opener = document.activeElement;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
opener = null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Focus the remembered opener, once, and forget it. */
|
|
56
|
+
export function restoreOpenerFocus(): void {
|
|
57
|
+
const target = opener;
|
|
58
|
+
opener = null;
|
|
59
|
+
if (target === null) return;
|
|
60
|
+
try {
|
|
61
|
+
target.focus();
|
|
62
|
+
} catch {
|
|
63
|
+
// An element that has since left the document cannot take focus; there
|
|
64
|
+
// is nowhere better to send it.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Commas of the languages the apps greet in: Latin, fullwidth, ideographic and Arabic. */
|
|
2
|
+
const COMMA = /[,,、،]/;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A greeting in two lines: the address ("Hi Nate,") over the rest ("what's on your mind?"). It
|
|
6
|
+
* breaks after the first comma, which keeps the greeting one string a translator writes once; a
|
|
7
|
+
* greeting without one (or with nothing after it) stays a single line.
|
|
8
|
+
*/
|
|
9
|
+
export function greetingLines(greeting: string): [string] | [string, string] {
|
|
10
|
+
const at = greeting.search(COMMA);
|
|
11
|
+
if (at < 0) return [greeting];
|
|
12
|
+
const first = greeting.slice(0, at + 1);
|
|
13
|
+
const rest = greeting.slice(at + 1).trim();
|
|
14
|
+
return rest === '' ? [greeting] : [first, rest];
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { File } from 'expo-file-system';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads a picked image into a `data:` URL, the one form the chat API accepts as an `image_url`
|
|
6
|
+
* part without the server having to reach the device. The picker's URI means nothing off the
|
|
7
|
+
* device: on web it is a `blob:` URL (a handle into this tab's memory), on native a `file://`
|
|
8
|
+
* path, and sent as it is either arrives as a string the model cannot open.
|
|
9
|
+
*
|
|
10
|
+
* Web reads the blob back; native reads the file with `expo-file-system`, as the Alia app does.
|
|
11
|
+
*/
|
|
12
|
+
export async function imageUriToDataUrl(uri: string, mimeType?: string): Promise<string> {
|
|
13
|
+
if (uri.startsWith('data:')) return uri;
|
|
14
|
+
if (Platform.OS !== 'web') {
|
|
15
|
+
// The `File` API: the legacy `readAsStringAsync` from the package root throws at runtime.
|
|
16
|
+
const base64 = await new File(uri).base64();
|
|
17
|
+
return `data:${mimeType || 'image/jpeg'};base64,${base64}`;
|
|
18
|
+
}
|
|
19
|
+
const blob = await (await fetch(uri)).blob();
|
|
20
|
+
return await new Promise<string>((resolve, reject) => {
|
|
21
|
+
const reader = new FileReader();
|
|
22
|
+
reader.onerror = () => reject(reader.error ?? new Error('Could not read the image'));
|
|
23
|
+
reader.onload = () => {
|
|
24
|
+
const result = String(reader.result);
|
|
25
|
+
// `readAsDataURL` stamps the blob's own type; it is only octet-stream when the blob has
|
|
26
|
+
// none, and then the picker's type is the better guess.
|
|
27
|
+
resolve(
|
|
28
|
+
mimeType && result.startsWith('data:application/octet-stream')
|
|
29
|
+
? result.replace('data:application/octet-stream', `data:${mimeType}`)
|
|
30
|
+
: result,
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
reader.readAsDataURL(blob);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Native: re-export react-native-keyboard-controller components
|
|
2
|
+
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
3
|
+
import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
KeyboardAwareScrollView,
|
|
7
|
+
KeyboardAvoidingView,
|
|
8
|
+
KeyboardProvider,
|
|
9
|
+
} from 'react-native-keyboard-controller';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The room under a bottom-anchored control for the gesture bar, while the gesture bar is what lies
|
|
13
|
+
* under it.
|
|
14
|
+
*
|
|
15
|
+
* With the keyboard up, a keyboard-avoiding host already ends at the keyboard's top edge, and the
|
|
16
|
+
* keyboard covers the gesture bar. Keeping this room then counts the bar twice: the chat's composer
|
|
17
|
+
* floated a bar's height above the keyboard, with the transcript showing through the gap (Pixel 8a).
|
|
18
|
+
* It follows the keyboard's own animation, so the control settles onto the keyboard as it rises
|
|
19
|
+
* instead of jumping after.
|
|
20
|
+
*/
|
|
21
|
+
export function KeyboardSafeAreaFloor({ inset }: { inset: number }) {
|
|
22
|
+
const { progress } = useReanimatedKeyboardAnimation();
|
|
23
|
+
const style = useAnimatedStyle(() => ({ height: inset * (1 - progress.value) }), [inset]);
|
|
24
|
+
return <Animated.View style={style} />;
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Web: re-export React Native built-in components as keyboard-controller substitutes
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
ScrollView,
|
|
5
|
+
type ScrollViewProps,
|
|
6
|
+
KeyboardAvoidingView as RNKeyboardAvoidingView,
|
|
7
|
+
type KeyboardAvoidingViewProps as RNKeyboardAvoidingViewProps,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
|
|
11
|
+
// Accept native-only props so shared components don't cause TS errors
|
|
12
|
+
type KeyboardAwareScrollViewProps = ScrollViewProps & {
|
|
13
|
+
bottomOffset?: number;
|
|
14
|
+
disableScrollOnKeyboardHide?: boolean;
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
extraKeyboardSpace?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// `ComponentRef`, not `ScrollView` itself: React Native 0.88 types `ScrollView` as a function
|
|
20
|
+
// component, so the class is no longer its instance type.
|
|
21
|
+
const KeyboardAwareScrollView = React.forwardRef<
|
|
22
|
+
React.ComponentRef<typeof ScrollView>,
|
|
23
|
+
KeyboardAwareScrollViewProps
|
|
24
|
+
>(({ bottomOffset, disableScrollOnKeyboardHide, enabled, extraKeyboardSpace, ...props }, ref) => (
|
|
25
|
+
<ScrollView ref={ref} {...props} />
|
|
26
|
+
));
|
|
27
|
+
KeyboardAwareScrollView.displayName = 'KeyboardAwareScrollView';
|
|
28
|
+
|
|
29
|
+
// `automaticOffset` is keyboard-controller's: measure the view's position in
|
|
30
|
+
// the window instead of trusting its parent-relative layout. The browser moves
|
|
31
|
+
// its own viewport for the keyboard, so on web it has nothing to do.
|
|
32
|
+
type KeyboardAvoidingViewProps = RNKeyboardAvoidingViewProps & {
|
|
33
|
+
automaticOffset?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const KeyboardAvoidingView = React.forwardRef<
|
|
37
|
+
React.ComponentRef<typeof RNKeyboardAvoidingView>,
|
|
38
|
+
KeyboardAvoidingViewProps
|
|
39
|
+
>(({ automaticOffset, ...props }, ref) => <RNKeyboardAvoidingView ref={ref} {...props} />);
|
|
40
|
+
KeyboardAvoidingView.displayName = 'KeyboardAvoidingView';
|
|
41
|
+
|
|
42
|
+
export { KeyboardAwareScrollView, KeyboardAvoidingView };
|
|
43
|
+
|
|
44
|
+
// No-op provider on web — keyboard-controller is native-only
|
|
45
|
+
export function KeyboardProvider({ children }: { children: React.ReactNode }) {
|
|
46
|
+
return <>{children}</>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The room under a bottom-anchored control for the system's bottom bar. The web's keyboard resizes
|
|
51
|
+
* the page rather than covering it, so that room never has to give way to it (see the native file).
|
|
52
|
+
*/
|
|
53
|
+
export function KeyboardSafeAreaFloor({ inset }: { inset: number }) {
|
|
54
|
+
return <View style={{ height: inset }} />;
|
|
55
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { GemieChatLabels, VoiceBlockReason } from './labels';
|
|
2
|
+
import { spanishCopy } from './copy';
|
|
3
|
+
import type { VoiceCloseReason } from './voice-protocol';
|
|
4
|
+
import type { VoiceErrorCode } from './speech-messages';
|
|
5
|
+
|
|
6
|
+
const VOICE_ERRORS: Record<VoiceErrorCode, string> = {
|
|
7
|
+
'not-authenticated': 'Inicia sesión para usar la voz',
|
|
8
|
+
'credential-not-supported': 'La voz solo está disponible con tu sesión de Alia',
|
|
9
|
+
'plan-required': 'El modo voz necesita un plan de pago',
|
|
10
|
+
'credits-exhausted': 'Te has quedado sin créditos para esta llamada',
|
|
11
|
+
'agent-unavailable': 'Este Gemie no está disponible para una llamada',
|
|
12
|
+
'invalid-request': 'No se pudo iniciar la llamada',
|
|
13
|
+
'resume-unavailable': 'No se pudo retomar la llamada: empieza una nueva',
|
|
14
|
+
'realtime-unavailable': 'La voz no está disponible ahora mismo: inténtalo más tarde',
|
|
15
|
+
'realtime-limited': 'La voz ha llegado a su límite por ahora: inténtalo más tarde',
|
|
16
|
+
'realtime-rejected': 'No se pudo iniciar la llamada con esta configuración',
|
|
17
|
+
'realtime-failed': 'La llamada ha fallado: inténtalo de nuevo',
|
|
18
|
+
'mic-denied': 'Se necesita permiso para usar el micrófono',
|
|
19
|
+
'mic-unavailable': 'No se pudo usar el micrófono: revisa tus dispositivos de entrada',
|
|
20
|
+
'connection-lost': 'Se perdió la conexión',
|
|
21
|
+
'voice-unavailable': 'La voz no está disponible en este dispositivo o navegador',
|
|
22
|
+
'too-long': 'El dictado era demasiado largo: cinco minutos como máximo',
|
|
23
|
+
'transcription-unavailable': 'El dictado no está disponible ahora mismo',
|
|
24
|
+
'transcription-limited': 'El dictado ha llegado a su límite por ahora: inténtalo más tarde',
|
|
25
|
+
'transcription-rejected': 'No se pudo transcribir esa grabación',
|
|
26
|
+
'transcription-failed': 'Falló el dictado: inténtalo de nuevo',
|
|
27
|
+
};
|
|
28
|
+
const VOICE_ENDED: Partial<Record<VoiceCloseReason, string>> = {
|
|
29
|
+
'call-moved-elsewhere': 'La llamada sigue en tu otro dispositivo',
|
|
30
|
+
'max-duration': 'La llamada llegó a su límite de 30 minutos',
|
|
31
|
+
'idle-timeout': 'La llamada terminó tras dos minutos de silencio',
|
|
32
|
+
'credits-exhausted': 'La llamada terminó: te quedaste sin créditos',
|
|
33
|
+
'server-shutdown': 'La llamada terminó mientras Alia se actualizaba: empieza una nueva',
|
|
34
|
+
};
|
|
35
|
+
const VOICE_BLOCKED: Record<VoiceBlockReason, string> = {
|
|
36
|
+
'sign-in': 'Inicia sesión para usar la voz',
|
|
37
|
+
'plan-required': 'El modo voz necesita un plan de pago',
|
|
38
|
+
'credits-exhausted': 'Te has quedado sin créditos',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Built-in Spanish, shared by every app that embeds the chat. */
|
|
42
|
+
export const SPANISH_LABELS: GemieChatLabels = {
|
|
43
|
+
clear: 'Borrar',
|
|
44
|
+
back: 'Volver',
|
|
45
|
+
share: 'Compartir',
|
|
46
|
+
more: 'Más',
|
|
47
|
+
chatActions: 'Acciones de la conversación',
|
|
48
|
+
addMenuGroup: 'Adjuntar',
|
|
49
|
+
addPhotos: 'Fotos',
|
|
50
|
+
addDocuments: 'Archivos',
|
|
51
|
+
startVoice: 'Iniciar llamada',
|
|
52
|
+
voiceEndingSoon: 'Queda un minuto de llamada',
|
|
53
|
+
composerMessage: 'Mensaje',
|
|
54
|
+
composerAddMenu: 'Añadir al chat',
|
|
55
|
+
composerModes: 'Potencia',
|
|
56
|
+
composerVoice: 'Dictar',
|
|
57
|
+
composerSend: 'Enviar mensaje',
|
|
58
|
+
composerStop: 'Detener la generación',
|
|
59
|
+
composerRemove: 'Quitar',
|
|
60
|
+
composerRetry: 'Reintentar',
|
|
61
|
+
composerUntitled: 'sin título',
|
|
62
|
+
dropHint: 'Suelta los archivos aquí para adjuntarlos',
|
|
63
|
+
dropUnavailable: 'Ahora mismo no se pueden adjuntar archivos',
|
|
64
|
+
greeting: 'Hola, ¿qué tienes en mente?',
|
|
65
|
+
copy: 'Copiar',
|
|
66
|
+
helpful: 'Respuesta útil',
|
|
67
|
+
unhelpful: 'Respuesta poco útil',
|
|
68
|
+
copied: 'Copiado',
|
|
69
|
+
edit: 'Editar',
|
|
70
|
+
save: 'Guardar',
|
|
71
|
+
cancel: 'Cancelar',
|
|
72
|
+
readAloud: 'Leer en voz alta',
|
|
73
|
+
stopReading: 'Dejar de leer',
|
|
74
|
+
planTitle: 'Este es mi plan',
|
|
75
|
+
reasoning: 'Razonamiento',
|
|
76
|
+
locale: 'es',
|
|
77
|
+
newChat: 'Nueva conversación',
|
|
78
|
+
recentConversations: 'Recientes',
|
|
79
|
+
sendFailed:
|
|
80
|
+
'No se pudo enviar el mensaje. Lo tienes de vuelta en el cuadro de texto, inténtalo otra vez.',
|
|
81
|
+
signInRequired: 'Inicia sesión para seguir conversando',
|
|
82
|
+
conversationSaveFailed: 'No se pudo guardar la conversación',
|
|
83
|
+
conversationDeleteFailed: 'No se pudo eliminar la conversación',
|
|
84
|
+
conversationCreateFailed: 'No se pudo crear la conversación',
|
|
85
|
+
conversationClearFailed: 'No se pudo borrar la conversación',
|
|
86
|
+
placeholder: (name) => `Pregúntale lo que quieras a ${name}`,
|
|
87
|
+
greetingNamed: (name) => `Hola ${name}, ¿qué tienes en mente?`,
|
|
88
|
+
fileReadFailed: (name) => `No se pudo leer ${name}: selecciona para reintentar`,
|
|
89
|
+
fileTooLarge: (name, limit) => `${name} supera ${limit} y no se ha adjuntado`,
|
|
90
|
+
fileEmpty: (name) => `${name} está vacío: no se pueden adjuntar carpetas`,
|
|
91
|
+
fileUnsupported: (name) => `No se puede enviar ${name} aquí: solo se admiten fotos`,
|
|
92
|
+
dictationRemaining: (seconds) => `Quedan ${seconds} s de dictado`,
|
|
93
|
+
thoughtFor: (seconds) => `Pensó durante ${seconds} segundos`,
|
|
94
|
+
attachmentNotSent: (name) => `No se envió ${name}: solo se pueden enviar fotos`,
|
|
95
|
+
attachmentUnreadable: (name) => `No se pudo leer ${name} y no se envió`,
|
|
96
|
+
voiceError: (code) => VOICE_ERRORS[code],
|
|
97
|
+
voiceEnded: (reason) => VOICE_ENDED[reason] ?? null,
|
|
98
|
+
voiceBlocked: (reason) => VOICE_BLOCKED[reason],
|
|
99
|
+
voiceControls: {
|
|
100
|
+
connecting: 'Conectando…',
|
|
101
|
+
reconnecting: 'Reconectando…',
|
|
102
|
+
connected: 'Conectado',
|
|
103
|
+
listening: 'Escuchando…',
|
|
104
|
+
muted: 'Silenciado',
|
|
105
|
+
thinking: 'Pensando…',
|
|
106
|
+
usingTool: 'Trabajando en ello…',
|
|
107
|
+
speaking: 'Hablando…',
|
|
108
|
+
mute: 'Silenciar',
|
|
109
|
+
unmute: 'Activar micrófono',
|
|
110
|
+
end: 'Colgar',
|
|
111
|
+
},
|
|
112
|
+
t: spanishCopy,
|
|
113
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { createContext, type ReactNode, useContext, useMemo } from 'react';
|
|
2
|
+
import { SPANISH_LABELS } from './labels-es';
|
|
3
|
+
import { VOICE_ERROR_MESSAGES, type VoiceErrorCode } from './speech-messages';
|
|
4
|
+
import { englishCopy, type Translate } from './copy';
|
|
5
|
+
import { VOICE_CONTROLS_LABELS, type VoiceControlsLabels } from './voice-controls-labels';
|
|
6
|
+
import type { VoiceCloseReason } from './voice-protocol';
|
|
7
|
+
|
|
8
|
+
/** Why a call could not be opened; the host's `canStartVoice` answers with one. */
|
|
9
|
+
export type VoiceBlockReason = 'sign-in' | 'plan-required' | 'credits-exhausted';
|
|
10
|
+
|
|
11
|
+
/** Every string the chat UI draws itself. Bloom's own copy follows `BloomProvider locale`. */
|
|
12
|
+
export interface GemieChatLabels {
|
|
13
|
+
// Header
|
|
14
|
+
clear: string;
|
|
15
|
+
back: string;
|
|
16
|
+
share: string;
|
|
17
|
+
more: string;
|
|
18
|
+
chatActions: string;
|
|
19
|
+
// Composer
|
|
20
|
+
/** The empty composer's prompt, naming the conversation's lead ("Ask Sindi..."). */
|
|
21
|
+
placeholder: (leadName: string) => string;
|
|
22
|
+
addMenuGroup: string;
|
|
23
|
+
addPhotos: string;
|
|
24
|
+
/** The add menu's row for documents, where the lead takes them. */
|
|
25
|
+
addDocuments: string;
|
|
26
|
+
startVoice: string;
|
|
27
|
+
/** The call bar's words (status, mute, end). */
|
|
28
|
+
voiceControls: VoiceControlsLabels;
|
|
29
|
+
/** Why a call ended without failing; `null` for a hang-up (the person knows). */
|
|
30
|
+
voiceEnded: (reason: VoiceCloseReason) => string | null;
|
|
31
|
+
/** Said once, and shown in the bar, when the call is about to reach its time limit. */
|
|
32
|
+
voiceEndingSoon: string;
|
|
33
|
+
/** Why a call was not opened, told instead of a button that silently does nothing. */
|
|
34
|
+
voiceBlocked: (reason: VoiceBlockReason) => string;
|
|
35
|
+
/** The field's accessible name. */
|
|
36
|
+
composerMessage: string;
|
|
37
|
+
/** The add button's accessible name. */
|
|
38
|
+
composerAddMenu: string;
|
|
39
|
+
/** The mode selector's accessible name (the host's power levels). */
|
|
40
|
+
composerModes: string;
|
|
41
|
+
/** The dictation button's accessible name. */
|
|
42
|
+
composerVoice: string;
|
|
43
|
+
composerSend: string;
|
|
44
|
+
composerStop: string;
|
|
45
|
+
/** A tile's remove button. */
|
|
46
|
+
composerRemove: string;
|
|
47
|
+
/** Bloom names a retry button "<this> <file name>". */
|
|
48
|
+
composerRetry: string;
|
|
49
|
+
/** What a tile without a file name is called. */
|
|
50
|
+
composerUntitled: string;
|
|
51
|
+
fileReadFailed: (name: string) => string;
|
|
52
|
+
fileTooLarge: (name: string, limit: string) => string;
|
|
53
|
+
fileEmpty: (name: string) => string;
|
|
54
|
+
/** A file of a kind the chat cannot send (a document, where only photos go). */
|
|
55
|
+
fileUnsupported: (name: string) => string;
|
|
56
|
+
/** Over the composer while a file is dragged onto it. */
|
|
57
|
+
dropHint: string;
|
|
58
|
+
dropUnavailable: string;
|
|
59
|
+
/** Why dictation failed, in the host's language. */
|
|
60
|
+
voiceError: (code: VoiceErrorCode) => string;
|
|
61
|
+
/** Over the composer in the last 30 s of a dictation's five minutes. */
|
|
62
|
+
dictationRemaining: (seconds: number) => string;
|
|
63
|
+
// Welcome
|
|
64
|
+
/** The empty chat's greeting for a signed-out visitor. */
|
|
65
|
+
greeting: string;
|
|
66
|
+
/** The empty chat's greeting for a named person. */
|
|
67
|
+
greetingNamed: (name: string) => string;
|
|
68
|
+
// Messages
|
|
69
|
+
copy: string;
|
|
70
|
+
helpful: string;
|
|
71
|
+
unhelpful: string;
|
|
72
|
+
copied: string;
|
|
73
|
+
edit: string;
|
|
74
|
+
save: string;
|
|
75
|
+
cancel: string;
|
|
76
|
+
readAloud: string;
|
|
77
|
+
stopReading: string;
|
|
78
|
+
// Plan
|
|
79
|
+
planTitle: string;
|
|
80
|
+
// Reasoning
|
|
81
|
+
reasoning: string;
|
|
82
|
+
thoughtFor: (seconds: number) => string;
|
|
83
|
+
// The words that are not one fixed field
|
|
84
|
+
/** The words that are not one fixed field (the thread, its cards, the work log), keyed as the Alia app keys them (see `copy.ts`). */
|
|
85
|
+
t: Translate;
|
|
86
|
+
/** The language `t` speaks, as a BCP 47 tag: dates, days and prices in the thread are formatted in it. */
|
|
87
|
+
locale: string;
|
|
88
|
+
// Conversations (the runtime's own words: toasts and the errors it raises)
|
|
89
|
+
/** A conversation's title until it has one. */
|
|
90
|
+
newChat: string;
|
|
91
|
+
/** Over the sheet's recent conversations with its lead. */
|
|
92
|
+
recentConversations: string;
|
|
93
|
+
/** A turn could not be sent and the composer got its text back. */
|
|
94
|
+
sendFailed: string;
|
|
95
|
+
/** The session ended mid-request. */
|
|
96
|
+
signInRequired: string;
|
|
97
|
+
conversationSaveFailed: string;
|
|
98
|
+
conversationDeleteFailed: string;
|
|
99
|
+
conversationCreateFailed: string;
|
|
100
|
+
conversationClearFailed: string;
|
|
101
|
+
/** An attachment of a kind the chat API does not carry was left out of the turn. */
|
|
102
|
+
attachmentNotSent: (name: string) => string;
|
|
103
|
+
/** A photo whose bytes could not be read was left out of the turn. */
|
|
104
|
+
attachmentUnreadable: (name: string) => string;
|
|
105
|
+
// Research
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const ENDED_ENGLISH: Partial<Record<VoiceCloseReason, string>> = {
|
|
109
|
+
'call-moved-elsewhere': 'The call continues on your other device',
|
|
110
|
+
'max-duration': 'The call reached its time limit',
|
|
111
|
+
'idle-timeout': 'The call ended after two minutes of silence',
|
|
112
|
+
'credits-exhausted': 'The call ended: you ran out of credits',
|
|
113
|
+
'server-shutdown': 'The call ended while Alia was updating — start a new one',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const BLOCKED_ENGLISH: Record<VoiceBlockReason, string> = {
|
|
117
|
+
'sign-in': 'Sign in to use voice',
|
|
118
|
+
'plan-required': 'Voice mode needs a paid plan',
|
|
119
|
+
'credits-exhausted': "You've run out of credits",
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const DEFAULT_LABELS: GemieChatLabels = {
|
|
123
|
+
clear: 'Clear',
|
|
124
|
+
back: 'Back',
|
|
125
|
+
share: 'Share',
|
|
126
|
+
more: 'More',
|
|
127
|
+
chatActions: 'Chat actions',
|
|
128
|
+
placeholder: (leadName) => `Ask ${leadName}...`,
|
|
129
|
+
addMenuGroup: 'Add',
|
|
130
|
+
addPhotos: 'Photos',
|
|
131
|
+
addDocuments: 'Files',
|
|
132
|
+
startVoice: 'Start voice',
|
|
133
|
+
voiceControls: VOICE_CONTROLS_LABELS,
|
|
134
|
+
voiceEnded: (reason) => ENDED_ENGLISH[reason] ?? null,
|
|
135
|
+
voiceEndingSoon: 'One minute left in this call',
|
|
136
|
+
voiceBlocked: (reason) => BLOCKED_ENGLISH[reason],
|
|
137
|
+
composerMessage: 'Message',
|
|
138
|
+
composerAddMenu: 'Add to chat',
|
|
139
|
+
composerModes: 'Power level',
|
|
140
|
+
composerVoice: 'Dictate',
|
|
141
|
+
composerSend: 'Send message',
|
|
142
|
+
composerStop: 'Stop generating',
|
|
143
|
+
composerRemove: 'Remove',
|
|
144
|
+
composerRetry: 'Retry',
|
|
145
|
+
composerUntitled: 'untitled',
|
|
146
|
+
fileReadFailed: (name) => `${name} could not be read — select to try again`,
|
|
147
|
+
fileTooLarge: (name, limit) => `${name} is larger than ${limit} and was not attached`,
|
|
148
|
+
fileEmpty: (name) => `${name} is empty — folders can't be attached`,
|
|
149
|
+
fileUnsupported: (name) => `${name} can't be sent here — only photos can`,
|
|
150
|
+
dropHint: 'Drop files here to attach them',
|
|
151
|
+
dropUnavailable: "Files can't be attached right now",
|
|
152
|
+
voiceError: (code) => VOICE_ERROR_MESSAGES[code],
|
|
153
|
+
dictationRemaining: (seconds) => `${seconds}s of dictation left`,
|
|
154
|
+
greeting: "Hi, what's on your mind?",
|
|
155
|
+
greetingNamed: (name) => `Hi ${name}, what's on your mind?`,
|
|
156
|
+
copy: 'Copy',
|
|
157
|
+
helpful: 'Helpful response',
|
|
158
|
+
unhelpful: 'Unhelpful response',
|
|
159
|
+
copied: 'Copied',
|
|
160
|
+
edit: 'Edit',
|
|
161
|
+
save: 'Save',
|
|
162
|
+
cancel: 'Cancel',
|
|
163
|
+
readAloud: 'Read aloud',
|
|
164
|
+
stopReading: 'Stop reading',
|
|
165
|
+
planTitle: "Here's my plan",
|
|
166
|
+
reasoning: 'Reasoning',
|
|
167
|
+
thoughtFor: (seconds) => `Thought for ${seconds} seconds`,
|
|
168
|
+
t: englishCopy,
|
|
169
|
+
locale: 'en',
|
|
170
|
+
newChat: 'New chat',
|
|
171
|
+
recentConversations: 'Recent',
|
|
172
|
+
sendFailed: "Your message couldn't be sent",
|
|
173
|
+
signInRequired: 'Sign in to keep chatting',
|
|
174
|
+
conversationSaveFailed: 'Failed to save conversation',
|
|
175
|
+
conversationDeleteFailed: 'Failed to delete conversation',
|
|
176
|
+
conversationCreateFailed: 'Failed to create conversation',
|
|
177
|
+
conversationClearFailed: "The conversation couldn't be cleared",
|
|
178
|
+
attachmentNotSent: (name) => `${name} wasn't sent — only photos can be sent`,
|
|
179
|
+
attachmentUnreadable: (name) => `${name} couldn't be read and wasn't sent`,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const LabelsContext = createContext<GemieChatLabels | null>(null);
|
|
183
|
+
|
|
184
|
+
/** The chat's labels: the defaults, with whatever the host overrides. */
|
|
185
|
+
export function GemieChatLabelsProvider({
|
|
186
|
+
labels,
|
|
187
|
+
children,
|
|
188
|
+
}: {
|
|
189
|
+
labels?: Partial<GemieChatLabels>;
|
|
190
|
+
children: ReactNode;
|
|
191
|
+
}) {
|
|
192
|
+
// Over whatever labels are already in reach, so a part that takes its own `labels` (the
|
|
193
|
+
// composer) refines the chat's copy instead of resetting it to English.
|
|
194
|
+
const inherited = useContext(LabelsContext);
|
|
195
|
+
const value = useMemo(() => {
|
|
196
|
+
const locale = labels?.locale ?? inherited?.locale ?? 'en';
|
|
197
|
+
const language = locale.toLowerCase().split('-')[0];
|
|
198
|
+
const defaults = language === 'es' ? SPANISH_LABELS : DEFAULT_LABELS;
|
|
199
|
+
const parent = inherited?.locale.toLowerCase().split('-')[0] === language ? inherited : null;
|
|
200
|
+
return { ...defaults, ...parent, ...labels };
|
|
201
|
+
}, [inherited, labels]);
|
|
202
|
+
return <LabelsContext.Provider value={value}>{children}</LabelsContext.Provider>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function useLabels(): GemieChatLabels {
|
|
206
|
+
return useContext(LabelsContext) ?? DEFAULT_LABELS;
|
|
207
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two origins the SDK talks to, defined once. Every URL it builds starts from one of them,
|
|
3
|
+
* and `@gemies/sdk/csp` (`src/csp.ts`) derives the host's CSP from these same values, so an
|
|
4
|
+
* origin the SDK uses is an origin it declares.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Declared here, not taken from the host's globals: Expo apps get `process` from Expo's types, a
|
|
8
|
+
// Vite app has none unless it installs Node's, and every entry that reaches this file must
|
|
9
|
+
// type-check alone (`check:entry-types`). Type-only; Metro still inlines the static access below.
|
|
10
|
+
declare const process: { readonly env: { readonly EXPO_PUBLIC_GEMIES_API_URL?: string } };
|
|
11
|
+
|
|
12
|
+
/** The Gemies API: `EXPO_PUBLIC_GEMIES_API_URL`, then production. Chat, dictation, speech, voice. */
|
|
13
|
+
export const GEMIES_API_URL = process.env.EXPO_PUBLIC_GEMIES_API_URL ?? 'https://api.gemies.ai';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The Gemies web app, which serves the files the SDK shares with every host: the voice call's
|
|
17
|
+
* worklets (`/sdk/voice-worklets/`), with CORS open (`packages/app/worker/index.js`).
|
|
18
|
+
*/
|
|
19
|
+
export const GEMIES_WEB_ORIGIN = 'https://gemies.ai';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The one public page of a shared conversation, on the Gemies web app, for every agent and every app
|
|
23
|
+
* that embeds one (`docs/agent-embedding.md` §6). An app shares this URL rather than a page of its
|
|
24
|
+
* own, so a link reads the same wherever it was minted.
|
|
25
|
+
*/
|
|
26
|
+
export function gemiesSharedConversationUrl(token: string): string {
|
|
27
|
+
return `${GEMIES_WEB_ORIGIN}/shared/${encodeURIComponent(token)}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { AvatarCharacter } from '@oxy.so/bloom/agent-avatar';
|
|
2
|
+
import type { GemieAgentProfile } from '../runtime/agents';
|
|
3
|
+
import type { Message } from '../runtime/types';
|
|
4
|
+
import { readAgentCharacter } from './agent-character';
|
|
5
|
+
import { ALIA_AVATAR } from './alia-character';
|
|
6
|
+
|
|
7
|
+
/** Somebody in the conversation who answers: its lead, or an agent the lead consulted. */
|
|
8
|
+
export interface GemieParticipant {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
handle?: string;
|
|
12
|
+
/** The 3D character it is drawn as. */
|
|
13
|
+
character: AvatarCharacter;
|
|
14
|
+
color?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The conversation's lead: who greets, whose name is on the composer, who the header shows first. */
|
|
18
|
+
export interface GemieLead extends GemieParticipant {
|
|
19
|
+
/** Alia herself, rather than an agent the chat was opened on. */
|
|
20
|
+
isAlia: boolean;
|
|
21
|
+
/** The agent's own greeting; Alia greets with the chat's labels. */
|
|
22
|
+
greeting?: string;
|
|
23
|
+
/** The agent's own starters, offered over the composer of an empty chat. */
|
|
24
|
+
starters: Array<{ title: string; prompt: string }>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Who is in the conversation, as the header draws it: the lead, then whoever has joined. */
|
|
28
|
+
export interface GemieChatParticipants {
|
|
29
|
+
lead: GemieLead;
|
|
30
|
+
/** The consulted agents that have joined the header, in the order they joined. */
|
|
31
|
+
joined: GemieParticipant[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The participants of a GROUP conversation: nobody leads it, so the first member stands in as the
|
|
36
|
+
* lead the chat's frame needs (the header lists them all) and the rest are already in it. Members
|
|
37
|
+
* do not join through flights: they were there when the conversation was made.
|
|
38
|
+
*/
|
|
39
|
+
export function groupParticipants(members: readonly GemieParticipant[]): GemieChatParticipants {
|
|
40
|
+
const [first, ...rest] = members;
|
|
41
|
+
if (first === undefined) return { lead: ALIA_LEAD, joined: [] };
|
|
42
|
+
return { lead: { ...first, isAlia: false, starters: [] }, joined: rest };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Alia as a lead. */
|
|
46
|
+
export const ALIA_LEAD: GemieLead = {
|
|
47
|
+
id: 'alia',
|
|
48
|
+
name: 'Alia',
|
|
49
|
+
handle: 'alia',
|
|
50
|
+
character: ALIA_AVATAR,
|
|
51
|
+
isAlia: true,
|
|
52
|
+
starters: [],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The lead of a chat: the agent it was opened on (`agent={{ id }}`), or Alia. */
|
|
56
|
+
export function leadOf(profile: GemieAgentProfile | null | undefined): GemieLead {
|
|
57
|
+
if (!profile) return ALIA_LEAD;
|
|
58
|
+
return {
|
|
59
|
+
id: profile.id,
|
|
60
|
+
name: profile.name,
|
|
61
|
+
handle: profile.handle,
|
|
62
|
+
character: readAgentCharacter(profile.character),
|
|
63
|
+
color: profile.color,
|
|
64
|
+
isAlia: false,
|
|
65
|
+
greeting: profile.greeting,
|
|
66
|
+
starters: profile.starters,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A consulted agent as a message carries it (`agentInfo`). */
|
|
71
|
+
export function participantOf(agentInfo: NonNullable<Message['agentInfo']>): GemieParticipant {
|
|
72
|
+
return {
|
|
73
|
+
id: agentInfo.id,
|
|
74
|
+
name: agentInfo.name,
|
|
75
|
+
handle: agentInfo.handle,
|
|
76
|
+
character: readAgentCharacter(agentInfo.character),
|
|
77
|
+
color: agentInfo.color,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The agents that answered in `messages`, besides the lead, in the order they first did — each
|
|
83
|
+
* with whether its first answer is the one being streamed now (it is joining) or one already
|
|
84
|
+
* written (it was there when the chat opened).
|
|
85
|
+
*/
|
|
86
|
+
export function consultedAgents(
|
|
87
|
+
messages: readonly Message[],
|
|
88
|
+
leadId: string,
|
|
89
|
+
): Array<{ participant: GemieParticipant; live: boolean }> {
|
|
90
|
+
const seen = new Map<string, { participant: GemieParticipant; live: boolean }>();
|
|
91
|
+
for (const message of messages) {
|
|
92
|
+
const info = message.agentInfo;
|
|
93
|
+
if (!info || info.id === leadId || seen.has(info.id)) continue;
|
|
94
|
+
seen.set(info.id, { participant: participantOf(info), live: message.isStreaming === true });
|
|
95
|
+
}
|
|
96
|
+
return [...seen.values()];
|
|
97
|
+
}
|