@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,235 @@
|
|
|
1
|
+
import { dragCarriesFiles, nextDragDepth } from '../lib/attachment-intake';
|
|
2
|
+
import { useLabels } from '../lib/labels';
|
|
3
|
+
import { Text } from '@oxy.so/bloom/typography';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Platform, View } from 'react-native';
|
|
6
|
+
/**
|
|
7
|
+
* Dropping files onto the composer, on web, where such a gesture exists.
|
|
8
|
+
*
|
|
9
|
+
* Alia had no drag-and-drop at all — no `onDrop`, no `dataTransfer`, nothing —
|
|
10
|
+
* which on web means the browser's own default ran instead: dropping a file
|
|
11
|
+
* anywhere on the page NAVIGATED THE TAB TO IT, losing the draft, the
|
|
12
|
+
* conversation scroll position and any stream in flight. So the first thing
|
|
13
|
+
* this does is not "accept files"; it is `preventDefault`, and it happens even
|
|
14
|
+
* when the composer is closed, because the least a locked composer owes a
|
|
15
|
+
* dropped file is not to throw the page away over it.
|
|
16
|
+
*
|
|
17
|
+
* ## Why the listeners are attached by hand
|
|
18
|
+
*
|
|
19
|
+
* `View` has no `onDragEnter`. react-native-web forwards a fixed set of
|
|
20
|
+
* handlers and the drag family is not in it, and NativeWind's wrapper means a
|
|
21
|
+
* ref here does not resolve to the DOM node either — the fullscreen grow in
|
|
22
|
+
* old composer ran into the same wall and solved it the same way, by giving
|
|
23
|
+
* the bar an `id` and looking it up. This hook takes that id, and the id now
|
|
24
|
+
* belongs to the `View` the composer wraps Bloom's pill in — Bloom's own pill
|
|
25
|
+
* takes a `style` and a `testID` and no DOM handle at all, which is the right
|
|
26
|
+
* shape for a UI kit and leaves the drop target to its host.
|
|
27
|
+
*/
|
|
28
|
+
export interface ComposerDropTargetOptions {
|
|
29
|
+
/** The DOM id of the element the drop lands on — the composer bar itself. */
|
|
30
|
+
elementId: string;
|
|
31
|
+
/** False while the composer is closed or a turn is streaming. */
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
onFiles: (files: File[]) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Changing this re-attaches the listeners. Fullscreen re-parents the bar
|
|
36
|
+
* through a portal, which destroys the node the listeners were on; without a
|
|
37
|
+
* rebind the composer silently stops taking drops the first time it is
|
|
38
|
+
* expanded.
|
|
39
|
+
*/
|
|
40
|
+
rebindKey?: string | number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Whether a file drag is currently over the composer. */
|
|
44
|
+
export function useComposerDropTarget({
|
|
45
|
+
elementId,
|
|
46
|
+
enabled,
|
|
47
|
+
onFiles,
|
|
48
|
+
rebindKey,
|
|
49
|
+
}: ComposerDropTargetOptions): boolean {
|
|
50
|
+
const [isOver, setIsOver] = React.useState(false);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* How many of the bar's elements the pointer is inside.
|
|
54
|
+
*
|
|
55
|
+
* A ref, and read in the same tick it is written: `dragenter` on a child
|
|
56
|
+
* arrives immediately before `dragleave` on its parent, so the two have to
|
|
57
|
+
* be counted against each other synchronously. State would be one render
|
|
58
|
+
* stale for the pair that matters, which is every pair.
|
|
59
|
+
*/
|
|
60
|
+
const depth = React.useRef(0);
|
|
61
|
+
|
|
62
|
+
// Held in a ref so the effect does not re-attach — and re-attaching matters:
|
|
63
|
+
// a listener swapped out mid-drag loses the depth count with it, and the
|
|
64
|
+
// overlay never clears.
|
|
65
|
+
const latest = React.useRef({ enabled, onFiles });
|
|
66
|
+
latest.current = { enabled, onFiles };
|
|
67
|
+
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
70
|
+
const element = document.getElementById(elementId);
|
|
71
|
+
if (element === null) return;
|
|
72
|
+
|
|
73
|
+
const step = (kind: 'enter' | 'leave' | 'drop') => {
|
|
74
|
+
depth.current = nextDragDepth(depth.current, kind);
|
|
75
|
+
setIsOver(depth.current > 0);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const onDragEnter = (event: globalThis.DragEvent) => {
|
|
79
|
+
if (!dragCarriesFiles(event.dataTransfer?.types)) return;
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
step('enter');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const onDragOver = (event: globalThis.DragEvent) => {
|
|
85
|
+
if (!dragCarriesFiles(event.dataTransfer?.types)) return;
|
|
86
|
+
// Both halves are required. Without `preventDefault` on dragOVER
|
|
87
|
+
// specifically — not just on enter — the element is not a drop target at
|
|
88
|
+
// all and `drop` never fires, which is the single most common way a
|
|
89
|
+
// hand-written drop zone appears to work and then does nothing.
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
if (event.dataTransfer !== null)
|
|
92
|
+
event.dataTransfer.dropEffect = latest.current.enabled ? 'copy' : 'none';
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const onDragLeave = (event: globalThis.DragEvent) => {
|
|
96
|
+
if (!dragCarriesFiles(event.dataTransfer?.types)) return;
|
|
97
|
+
step('leave');
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const onDrop = (event: globalThis.DragEvent) => {
|
|
101
|
+
if (!dragCarriesFiles(event.dataTransfer?.types)) return;
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
// Reset rather than decrement: no `dragleave` follows a drop, so a
|
|
104
|
+
// decrement leaves the count at one and the overlay stuck over the bar.
|
|
105
|
+
step('drop');
|
|
106
|
+
if (!latest.current.enabled) return;
|
|
107
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
108
|
+
if (files.length > 0) latest.current.onFiles(files);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
element.addEventListener('dragenter', onDragEnter);
|
|
112
|
+
element.addEventListener('dragover', onDragOver);
|
|
113
|
+
element.addEventListener('dragleave', onDragLeave);
|
|
114
|
+
element.addEventListener('drop', onDrop);
|
|
115
|
+
return () => {
|
|
116
|
+
element.removeEventListener('dragenter', onDragEnter);
|
|
117
|
+
element.removeEventListener('dragover', onDragOver);
|
|
118
|
+
element.removeEventListener('dragleave', onDragLeave);
|
|
119
|
+
element.removeEventListener('drop', onDrop);
|
|
120
|
+
// A drag that was over the bar when it was torn down would otherwise
|
|
121
|
+
// leave the count — and the overlay — set for the next mount.
|
|
122
|
+
depth.current = 0;
|
|
123
|
+
setIsOver(false);
|
|
124
|
+
};
|
|
125
|
+
}, [elementId, rebindKey]);
|
|
126
|
+
|
|
127
|
+
return isOver;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* What a file drag looks like over the composer.
|
|
132
|
+
*
|
|
133
|
+
* `pointerEvents="none"` is load-bearing rather than tidy: an overlay that
|
|
134
|
+
* takes pointer events is an element the drag ENTERS, so it would fire its own
|
|
135
|
+
* `dragenter`/`dragleave` pair against the same counter it is drawn from, and
|
|
136
|
+
* the affordance would oscillate against itself.
|
|
137
|
+
*
|
|
138
|
+
* It is announced as well as drawn. A drop target that exists only as a
|
|
139
|
+
* dashed outline is a target only for the people who can see it, and while a
|
|
140
|
+
* drag is not a gesture a screen-reader user performs, the composer is shared
|
|
141
|
+
* with people who do both.
|
|
142
|
+
*/
|
|
143
|
+
export function ComposerDropOverlay({ visible, enabled }: { visible: boolean; enabled: boolean }) {
|
|
144
|
+
const labels = useLabels();
|
|
145
|
+
if (!visible) return null;
|
|
146
|
+
return (
|
|
147
|
+
<View
|
|
148
|
+
pointerEvents="none"
|
|
149
|
+
accessibilityRole="alert"
|
|
150
|
+
accessibilityLiveRegion="polite"
|
|
151
|
+
// 26: the corner Bloom's composer pill wears at one line and past it.
|
|
152
|
+
className="absolute inset-0 z-20 items-center justify-center rounded-[26px] border-2 border-dashed border-primary bg-background/90"
|
|
153
|
+
>
|
|
154
|
+
<Text className="text-sm font-medium text-foreground">
|
|
155
|
+
{enabled ? labels.dropHint : labels.dropUnavailable}
|
|
156
|
+
</Text>
|
|
157
|
+
</View>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Files PASTED into the composer, on web, where such a gesture exists.
|
|
163
|
+
*
|
|
164
|
+
* It lives beside the drop target rather than with the field because it is the
|
|
165
|
+
* same question asked with a different gesture: bytes have arrived, they were
|
|
166
|
+
* not typed, and the composer has to decide whether to take them. Both are
|
|
167
|
+
* hand-attached DOM listeners for the same reason — react-native-web forwards
|
|
168
|
+
* neither the drag family nor `onPaste` through `View`, and NativeWind's
|
|
169
|
+
* wrapper means a ref does not resolve to the node either — so both are keyed
|
|
170
|
+
* off the composer's own DOM id.
|
|
171
|
+
*
|
|
172
|
+
* ## Why it is on the composer and not on the field
|
|
173
|
+
*
|
|
174
|
+
* `ChatTextInput` used to own this, listening on `document` and checking that
|
|
175
|
+
* the focused element was inside ITS wrapper. Bloom's pill owns the field now
|
|
176
|
+
* and exposes no DOM handle for it, so the containment test moves out one ring,
|
|
177
|
+
* to the element the pill is mounted inside. That is the same test with a
|
|
178
|
+
* larger box: a paste belongs to this composer when the thing being pasted
|
|
179
|
+
* into is somewhere in this composer.
|
|
180
|
+
*
|
|
181
|
+
* ## Why it takes every file and not only images
|
|
182
|
+
*
|
|
183
|
+
* The old handler filtered `item.type.indexOf('image')`, so pasting a PDF
|
|
184
|
+
* pasted its NAME. The intake queue classifies and refuses on its own terms
|
|
185
|
+
* (`lib/attachment-intake.ts`) and says so in the strip, which is a better
|
|
186
|
+
* answer than a silent drop — and it is the same answer a dropped PDF already
|
|
187
|
+
* got, which is the point: one queue, one set of rules, whichever gesture the
|
|
188
|
+
* file arrived by.
|
|
189
|
+
*/
|
|
190
|
+
export function useComposerPasteTarget({
|
|
191
|
+
elementId,
|
|
192
|
+
enabled,
|
|
193
|
+
onFiles,
|
|
194
|
+
}: Omit<ComposerDropTargetOptions, 'rebindKey'>): void {
|
|
195
|
+
// Held in a ref for the same reason the drop target holds its own: a
|
|
196
|
+
// listener swapped out mid-gesture is a gesture with no handler.
|
|
197
|
+
const latest = React.useRef({ enabled, onFiles });
|
|
198
|
+
latest.current = { enabled, onFiles };
|
|
199
|
+
|
|
200
|
+
React.useEffect(() => {
|
|
201
|
+
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
202
|
+
|
|
203
|
+
const onPaste = (event: globalThis.ClipboardEvent) => {
|
|
204
|
+
// Resolved per EVENT rather than once per mount, which is also why this
|
|
205
|
+
// hook needs no `rebindKey`: the pill re-renders its own subtree as the
|
|
206
|
+
// draft grows, and a node captured at mount is a node the composer may
|
|
207
|
+
// since have replaced.
|
|
208
|
+
const host = document.getElementById(elementId);
|
|
209
|
+
if (!(host instanceof HTMLElement)) return;
|
|
210
|
+
if (!host.contains(document.activeElement)) return;
|
|
211
|
+
|
|
212
|
+
const items = event.clipboardData?.items;
|
|
213
|
+
if (items === undefined) return;
|
|
214
|
+
const files: File[] = [];
|
|
215
|
+
for (const item of Array.from(items)) {
|
|
216
|
+
if (item.kind !== 'file') continue;
|
|
217
|
+
const file = item.getAsFile();
|
|
218
|
+
if (file !== null) files.push(file);
|
|
219
|
+
}
|
|
220
|
+
// Nothing was pasted that this is about. A paste carrying text as well
|
|
221
|
+
// as a picture — which is what copying from a web page produces — must
|
|
222
|
+
// still put its text in the field, so the default is left alone.
|
|
223
|
+
if (files.length === 0) return;
|
|
224
|
+
|
|
225
|
+
// Swallowed even when the composer is closed: the alternative is the
|
|
226
|
+
// browser's own default, which writes the file's bytes into the draft.
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
if (!latest.current.enabled) return;
|
|
229
|
+
latest.current.onFiles(files);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
document.addEventListener('paste', onPaste);
|
|
233
|
+
return () => document.removeEventListener('paste', onPaste);
|
|
234
|
+
}, [elementId]);
|
|
235
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Item } from '@oxy.so/bloom/item';
|
|
2
|
+
import { Text } from '@oxy.so/bloom/typography';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import type { Completion } from '../lib/suggestions';
|
|
5
|
+
import type { GemieSuggestion } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Suggestions over the composer, one line each, the typed part highlighted and the row the
|
|
9
|
+
* keyboard is on marked. The Alia app and the SDK chat draw exactly this.
|
|
10
|
+
*/
|
|
11
|
+
export function ComposerSuggestions<T extends GemieSuggestion>({
|
|
12
|
+
completions,
|
|
13
|
+
selected,
|
|
14
|
+
onPick,
|
|
15
|
+
}: {
|
|
16
|
+
completions: readonly Completion<T>[];
|
|
17
|
+
selected: number;
|
|
18
|
+
onPick: (suggestion: T) => void;
|
|
19
|
+
}) {
|
|
20
|
+
if (completions.length === 0) return null;
|
|
21
|
+
return (
|
|
22
|
+
<View accessibilityRole="list" className="w-full max-w-[768px] self-center">
|
|
23
|
+
{completions.map(({ suggestion, matchStart, matchEnd }, index) => {
|
|
24
|
+
const { text } = suggestion;
|
|
25
|
+
return (
|
|
26
|
+
<Item
|
|
27
|
+
key={suggestion.id}
|
|
28
|
+
density="compact"
|
|
29
|
+
highlighted={index === selected}
|
|
30
|
+
accessibilityRole="button"
|
|
31
|
+
accessibilityLabel={text}
|
|
32
|
+
onPress={() => onPick(suggestion)}
|
|
33
|
+
title={
|
|
34
|
+
<Text numberOfLines={1}>
|
|
35
|
+
{text.slice(0, matchStart)}
|
|
36
|
+
<Text className="font-medium text-primary">{text.slice(matchStart, matchEnd)}</Text>
|
|
37
|
+
{text.slice(matchEnd)}
|
|
38
|
+
</Text>
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
})}
|
|
43
|
+
</View>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Ask Alia", "Ask Sindi": one sheet an app mounts once, opened on any agent from anywhere in it.
|
|
3
|
+
*
|
|
4
|
+
* The app names the agents it offers (`agents`, by a key of its own) and configures the sheet
|
|
5
|
+
* once — its host tools, renderers, words, voice, context, upsell and share. A button calls
|
|
6
|
+
* `useAskGemie().ask(key, turn)`. Signed out, the sheet is not mounted (it could not call Alia):
|
|
7
|
+
* `ask` opens Oxy's sign-in instead, and the person asks again once signed in.
|
|
8
|
+
*
|
|
9
|
+
* This module is the provider without its sheet; each entry builds one with `createAskProvider`:
|
|
10
|
+
* - `@gemies/sdk/ask` (`GemieAskProviderLazy`) loads the sheet with the first `ask`, through
|
|
11
|
+
* the one `import()` that keeps the chat out of the app's entry bundle;
|
|
12
|
+
* - the root entry (`GemieAskProvider`) already holds the whole chat, so its sheet is a static
|
|
13
|
+
* import. A lazy one there would put an async chunk boundary INSIDE the SDK, and on web Metro
|
|
14
|
+
* hoists every module two async chunks share into `__common.js`, loaded at first paint: an app
|
|
15
|
+
* that lazy-loads the root entry would get the chat in its first paint instead of its own chunk.
|
|
16
|
+
* Both read and write the one context below, so `useAskGemie` works under either.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useAuth, useOxy } from '@oxy.so/services/ui/client';
|
|
20
|
+
import {
|
|
21
|
+
type ComponentType,
|
|
22
|
+
createContext,
|
|
23
|
+
forwardRef,
|
|
24
|
+
type ReactNode,
|
|
25
|
+
type RefAttributes,
|
|
26
|
+
useCallback,
|
|
27
|
+
useContext,
|
|
28
|
+
useEffect,
|
|
29
|
+
useImperativeHandle,
|
|
30
|
+
useMemo,
|
|
31
|
+
useRef,
|
|
32
|
+
useState,
|
|
33
|
+
} from 'react';
|
|
34
|
+
import type { GemieTurn } from '../hooks/useChatComposer';
|
|
35
|
+
import type { GemieChatSheetProps, GemieChatSheetRef } from './GemieChatSheet';
|
|
36
|
+
import type { GemieAskOpening, GemieAskSheetProps } from './GemieAskSheet';
|
|
37
|
+
|
|
38
|
+
/** The agents an app offers, by its own key. An entry without `id` is Alia. */
|
|
39
|
+
export type GemieAskAgents = Readonly<Record<string, { id?: string }>>;
|
|
40
|
+
|
|
41
|
+
export interface GemieAskProviderProps
|
|
42
|
+
extends Pick<
|
|
43
|
+
GemieChatSheetProps,
|
|
44
|
+
| 'app'
|
|
45
|
+
| 'hostTools'
|
|
46
|
+
| 'toolRenderers'
|
|
47
|
+
| 'labels'
|
|
48
|
+
| 'voice'
|
|
49
|
+
| 'clientContext'
|
|
50
|
+
| 'onFeatureLocked'
|
|
51
|
+
| 'onShare'
|
|
52
|
+
| 'model'
|
|
53
|
+
| 'apiUrl'
|
|
54
|
+
| 'headerMenu'
|
|
55
|
+
| 'recentConversations'
|
|
56
|
+
> {
|
|
57
|
+
/** The agents `ask` opens, by key. Omitted, the sheet only ever opens on Alia. */
|
|
58
|
+
agents?: GemieAskAgents;
|
|
59
|
+
/** The lines offered over Alia's empty composer; an agent offers its own starters. */
|
|
60
|
+
welcomeSuggestions?: GemieChatSheetProps['welcomeSuggestions'];
|
|
61
|
+
children: ReactNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface GemieAsk {
|
|
65
|
+
/**
|
|
66
|
+
* Open the sheet on the agent `agentKey` (omitted, Alia), with `turn` already sent when given
|
|
67
|
+
* ("ask Sindi about this listing"). Signed out, opens Oxy's sign-in instead.
|
|
68
|
+
*/
|
|
69
|
+
ask: (agentKey?: string, turn?: GemieTurn) => void;
|
|
70
|
+
/** Open the sheet on the agent `agentKey` (omitted, Alia), on its stored conversation `conversationId`. */
|
|
71
|
+
resume: (agentKey: string | undefined, conversationId: string) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Close the sheet — a host tool that changed the page under it shows the person the result, once
|
|
74
|
+
* the turn has been written.
|
|
75
|
+
*/
|
|
76
|
+
dismiss: () => void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const AskContext = createContext<GemieAsk | null>(null);
|
|
80
|
+
|
|
81
|
+
/** The app's way to open its one Alia sheet. Must be used under `GemieAskProvider`. */
|
|
82
|
+
export function useAskGemie(): GemieAsk {
|
|
83
|
+
const ask = useContext(AskContext);
|
|
84
|
+
if (ask === null) throw new Error('useAskGemie must be used within a GemieAskProvider');
|
|
85
|
+
return ask;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The opening that waits for the sheet of agent `key` to be the one mounted. */
|
|
89
|
+
interface Opening extends GemieAskOpening {
|
|
90
|
+
key: string | undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The sheet a provider mounts: `GemieAskSheet`, imported statically or behind `lazy` + `Suspense`. */
|
|
94
|
+
export type AskSheetComponent = ComponentType<
|
|
95
|
+
GemieAskSheetProps & RefAttributes<GemieChatSheetRef>
|
|
96
|
+
>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Builds the provider around `Sheet`. `preload`, when given, fetches the sheet's module in the
|
|
100
|
+
* background once signed in, so the first `ask` does not wait on the network.
|
|
101
|
+
*/
|
|
102
|
+
export function createAskProvider(Sheet: AskSheetComponent, preload?: () => Promise<unknown>) {
|
|
103
|
+
/**
|
|
104
|
+
* Mounts the app's one sheet. Its ref is the same `GemieAsk` as `useAskGemie()`, for the code
|
|
105
|
+
* that configures the sheet and so sits above it — a host-tool executor that closes it.
|
|
106
|
+
*/
|
|
107
|
+
return forwardRef<GemieAsk, GemieAskProviderProps>(function GemieAskProvider(
|
|
108
|
+
{ agents, welcomeSuggestions, children, labels, ...sheet },
|
|
109
|
+
ref,
|
|
110
|
+
) {
|
|
111
|
+
const { canUsePrivateApi, signIn } = useAuth();
|
|
112
|
+
const { currentLanguage } = useOxy();
|
|
113
|
+
const localizedLabels = useMemo(
|
|
114
|
+
() => ({ ...labels, locale: labels?.locale ?? currentLanguage }),
|
|
115
|
+
[labels, currentLanguage],
|
|
116
|
+
);
|
|
117
|
+
const sheetRef = useRef<GemieChatSheetRef>(null);
|
|
118
|
+
const [opening, setOpening] = useState<Opening | null>(null);
|
|
119
|
+
const [current, setCurrent] = useState<string | undefined>(undefined);
|
|
120
|
+
/** Nothing is mounted before the first `ask`. */
|
|
121
|
+
const [asked, setAsked] = useState(false);
|
|
122
|
+
const agentsRef = useRef(agents);
|
|
123
|
+
agentsRef.current = agents;
|
|
124
|
+
|
|
125
|
+
const open = useCallback(
|
|
126
|
+
(agentKey: string | undefined, turn?: GemieTurn, conversationId?: string) => {
|
|
127
|
+
if (agentKey !== undefined && agentsRef.current?.[agentKey] === undefined) {
|
|
128
|
+
throw new Error(`GemieAskProvider has no agent "${agentKey}"`);
|
|
129
|
+
}
|
|
130
|
+
if (!canUsePrivateApi) {
|
|
131
|
+
void signIn().catch(() => undefined);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
setAsked(true);
|
|
135
|
+
setCurrent(agentKey);
|
|
136
|
+
setOpening((previous) => ({
|
|
137
|
+
key: agentKey,
|
|
138
|
+
turn,
|
|
139
|
+
...(conversationId === undefined ? {} : { conversationId }),
|
|
140
|
+
serial: (previous?.serial ?? 0) + 1,
|
|
141
|
+
}));
|
|
142
|
+
},
|
|
143
|
+
[canUsePrivateApi, signIn],
|
|
144
|
+
);
|
|
145
|
+
const ask = useCallback((agentKey?: string, turn?: GemieTurn) => open(agentKey, turn), [open]);
|
|
146
|
+
const resume = useCallback(
|
|
147
|
+
(agentKey: string | undefined, conversationId: string) =>
|
|
148
|
+
open(agentKey, undefined, conversationId),
|
|
149
|
+
[open],
|
|
150
|
+
);
|
|
151
|
+
const dismiss = useCallback(() => sheetRef.current?.dismiss(), []);
|
|
152
|
+
|
|
153
|
+
const opened = useCallback(() => setOpening(null), []);
|
|
154
|
+
|
|
155
|
+
// Signed in, the sheet's module comes down in the background, ahead of the first `ask`.
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (canUsePrivateApi && preload !== undefined) void preload().catch(() => undefined);
|
|
158
|
+
}, [canUsePrivateApi]);
|
|
159
|
+
|
|
160
|
+
const agentId = current === undefined ? undefined : agents?.[current]?.id;
|
|
161
|
+
const agent = useMemo(() => (agentId === undefined ? undefined : { id: agentId }), [agentId]);
|
|
162
|
+
const value = useMemo<GemieAsk>(() => ({ ask, resume, dismiss }), [ask, resume, dismiss]);
|
|
163
|
+
useImperativeHandle(ref, () => value, [value]);
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<AskContext.Provider value={value}>
|
|
167
|
+
{children}
|
|
168
|
+
{canUsePrivateApi && asked ? (
|
|
169
|
+
<Sheet
|
|
170
|
+
key={agentId ?? 'alia'}
|
|
171
|
+
ref={sheetRef}
|
|
172
|
+
{...sheet}
|
|
173
|
+
labels={localizedLabels}
|
|
174
|
+
agent={agent}
|
|
175
|
+
welcomeSuggestions={agent === undefined ? welcomeSuggestions : undefined}
|
|
176
|
+
// A different agent is a new sheet: the opening waits for that one to mount.
|
|
177
|
+
opening={opening !== null && opening.key === current ? opening : null}
|
|
178
|
+
onOpened={opened}
|
|
179
|
+
/>
|
|
180
|
+
) : null}
|
|
181
|
+
</AskContext.Provider>
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ask provider of the root entry (`@gemies/sdk`): its sheet is a static import.
|
|
3
|
+
*
|
|
4
|
+
* The root entry already holds the whole chat, so loading `GemieAskSheet` lazily here would save
|
|
5
|
+
* nothing and cost a lot on web: it is an async chunk boundary inside the SDK, and Metro hoists
|
|
6
|
+
* every module two async chunks share into `__common.js`, which loads at first paint. An app that
|
|
7
|
+
* lazy-loads its Alia sheet would then get the chat (and the Bloom it draws with) in its first
|
|
8
|
+
* paint. An app that wants the chat out of its entry bundle mounts the provider from
|
|
9
|
+
* `@gemies/sdk/ask` (`GemieAskProviderLazy`) instead. See `GemieAskCore` for the provider itself.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createAskProvider } from './GemieAskCore';
|
|
13
|
+
import { GemieAskSheet } from './GemieAskSheetWithVoice';
|
|
14
|
+
|
|
15
|
+
export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
|
|
16
|
+
export { useAskGemie } from './GemieAskCore';
|
|
17
|
+
|
|
18
|
+
export const GemieAskProvider = createAskProvider(GemieAskSheet);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ask provider of `@gemies/sdk/ask`: its sheet is loaded lazily and mounted on the first
|
|
3
|
+
* `ask`, so an app that mounts this provider at its root keeps the chat out of its entry bundle.
|
|
4
|
+
* Signed in, the sheet's module is fetched in the background so the first `ask` does not wait on
|
|
5
|
+
* the network.
|
|
6
|
+
*
|
|
7
|
+
* This `import()` is the ONE async boundary the SDK draws, and only for this entry (and
|
|
8
|
+
* `@gemies/sdk/ask/text`): everything behind it (`GemieAskSheetWithVoice` and the chat) imports statically on web, so Metro emits one chunk for
|
|
9
|
+
* the sheet and hoists nothing of it into `__common.js` (`scripts/check-entry-isolation.mjs`).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { lazy, Suspense } from 'react';
|
|
13
|
+
import { type AskSheetComponent, createAskProvider } from './GemieAskCore';
|
|
14
|
+
|
|
15
|
+
const loadSheet = () => import('./GemieAskSheetWithVoice');
|
|
16
|
+
const LazyAskSheet = lazy(() => loadSheet().then((module) => ({ default: module.GemieAskSheet })));
|
|
17
|
+
|
|
18
|
+
const SuspendedAskSheet: AskSheetComponent = (props) => (
|
|
19
|
+
<Suspense fallback={null}>
|
|
20
|
+
<LazyAskSheet {...props} />
|
|
21
|
+
</Suspense>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
|
|
25
|
+
export { useAskGemie } from './GemieAskCore';
|
|
26
|
+
|
|
27
|
+
export const GemieAskProvider = createAskProvider(SuspendedAskSheet, loadSheet);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ask provider of `@gemies/sdk/ask/text`: `GemieAskProviderLazy` without the voice call. Its
|
|
3
|
+
* sheet is loaded lazily, with the first `ask`, and neither the provider nor the sheet reaches the
|
|
4
|
+
* call's modules, so a text-only app bundles none of them.
|
|
5
|
+
*
|
|
6
|
+
* Its `import()` is the one async boundary of this entry, as in `GemieAskProviderLazy`: behind it
|
|
7
|
+
* everything imports statically on web (`scripts/check-entry-isolation.mjs`).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { lazy, Suspense } from 'react';
|
|
11
|
+
import { type AskSheetComponent, createAskProvider } from './GemieAskCore';
|
|
12
|
+
|
|
13
|
+
const loadSheet = () => import('./GemieAskSheet');
|
|
14
|
+
const LazyAskSheet = lazy(() => loadSheet().then((module) => ({ default: module.GemieAskSheet })));
|
|
15
|
+
|
|
16
|
+
const SuspendedAskSheet: AskSheetComponent = (props) => (
|
|
17
|
+
<Suspense fallback={null}>
|
|
18
|
+
<LazyAskSheet {...props} />
|
|
19
|
+
</Suspense>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
|
|
23
|
+
export { useAskGemie } from './GemieAskCore';
|
|
24
|
+
|
|
25
|
+
export const GemieAskProvider = createAskProvider(SuspendedAskSheet, loadSheet);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sheet `GemieAskProvider` mounts, in its own module so the provider can load it lazily: an app
|
|
3
|
+
* that mounts the provider at its root carries only the provider in its entry bundle, and the
|
|
4
|
+
* chat — thread, composer, voice, renderers — arrives with the first `ask`.
|
|
5
|
+
*
|
|
6
|
+
* It presents the opening it is handed once it is mounted, which is the only moment a lazily
|
|
7
|
+
* loaded sheet can be presented, and tells the provider the opening is spent.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
11
|
+
import type { GemieTurn } from '../hooks/useChatComposer';
|
|
12
|
+
import { GemieChatSheet, type GemieChatSheetProps, type GemieChatSheetRef } from './GemieChatSheet';
|
|
13
|
+
|
|
14
|
+
/** What the person asked for: a turn to send, or a stored conversation to pick up again. */
|
|
15
|
+
export interface GemieAskOpening {
|
|
16
|
+
turn: GemieTurn | undefined;
|
|
17
|
+
conversationId?: string;
|
|
18
|
+
/** Changes on every `ask`, so asking the same agent twice opens twice. */
|
|
19
|
+
serial: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GemieAskSheetProps extends GemieChatSheetProps {
|
|
23
|
+
/** The opening to present once mounted; `null` when there is none waiting. */
|
|
24
|
+
opening: GemieAskOpening | null;
|
|
25
|
+
/** The opening was presented. */
|
|
26
|
+
onOpened: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const GemieAskSheet = forwardRef<GemieChatSheetRef, GemieAskSheetProps>(
|
|
30
|
+
function GemieAskSheet({ opening, onOpened, ...sheet }, ref) {
|
|
31
|
+
const sheetRef = useRef<GemieChatSheetRef>(null);
|
|
32
|
+
useImperativeHandle(
|
|
33
|
+
ref,
|
|
34
|
+
() => ({
|
|
35
|
+
present: (turn?: GemieTurn) => sheetRef.current?.present(turn),
|
|
36
|
+
resume: (conversationId: string) => sheetRef.current?.resume(conversationId),
|
|
37
|
+
dismiss: () => sheetRef.current?.dismiss(),
|
|
38
|
+
}),
|
|
39
|
+
[],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (opening === null) return;
|
|
44
|
+
if (opening.conversationId !== undefined) sheetRef.current?.resume(opening.conversationId);
|
|
45
|
+
else sheetRef.current?.present(opening.turn);
|
|
46
|
+
onOpened();
|
|
47
|
+
}, [opening, onOpened]);
|
|
48
|
+
|
|
49
|
+
return <GemieChatSheet ref={sheetRef} {...sheet} />;
|
|
50
|
+
},
|
|
51
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ask sheet with the voice call: what the root entry's `GemieAskProvider` imports and
|
|
3
|
+
* `@gemies/sdk/ask` loads with the first `ask`. `@gemies/sdk/ask/text` loads `GemieAskSheet`
|
|
4
|
+
* itself, which never reaches the call.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { GemieAskSheet as TextAskSheet } from './GemieAskSheet';
|
|
8
|
+
import { withVoiceCall } from './voice/withVoiceCall';
|
|
9
|
+
|
|
10
|
+
export const GemieAskSheet = withVoiceCall(TextAskSheet, 'GemieAskSheet');
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AgentAvatar } from '@oxy.so/bloom/agent-avatar';
|
|
2
|
+
import { memo, useEffect, useState } from 'react';
|
|
3
|
+
import { ALIA_AVATAR } from '../lib/alia-character';
|
|
4
|
+
|
|
5
|
+
export { ALIA_AVATAR };
|
|
6
|
+
|
|
7
|
+
/** What Alia is doing; the avatar plays a working turn each time it starts to think or work. */
|
|
8
|
+
export type GemieAvatarState = 'idle' | 'thinking' | 'working' | 'writing';
|
|
9
|
+
|
|
10
|
+
const BUSY: ReadonlySet<GemieAvatarState> = new Set(['thinking', 'working']);
|
|
11
|
+
|
|
12
|
+
/** Whether a state is work her avatar shows: thinking or working, not writing. */
|
|
13
|
+
export const gemieIsBusy = (state: GemieAvatarState): boolean => BUSY.has(state);
|
|
14
|
+
|
|
15
|
+
export interface GemieAvatarProps {
|
|
16
|
+
/** Width and height in px. */
|
|
17
|
+
size: number;
|
|
18
|
+
/** What Alia is doing. Default `idle`. */
|
|
19
|
+
state?: GemieAvatarState;
|
|
20
|
+
/** Follows the pointer and reacts to touch, as Bloom's engine does. Default `false`. */
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
/** Change it to replay the avatar's reaction (a wave) — for a button that wraps it. */
|
|
23
|
+
reactionKey?: number;
|
|
24
|
+
/** A still thumbnail instead of a live 3D avatar: for small, permanent spots like a sidebar. */
|
|
25
|
+
portrait?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Bloom's `AgentAvatar` dressed as Alia. Bloom draws characters as SVG, with nothing to host or
|
|
30
|
+
* fetch; the chat components mount Bloom's `AgentAvatarProvider` (the shared capability map) for
|
|
31
|
+
* the avatars they draw, and a host that draws her alone mounts it too.
|
|
32
|
+
*/
|
|
33
|
+
export const GemieAvatar = memo(function GemieAvatar({
|
|
34
|
+
size,
|
|
35
|
+
state = 'idle',
|
|
36
|
+
interactive = false,
|
|
37
|
+
reactionKey,
|
|
38
|
+
portrait = false,
|
|
39
|
+
}: GemieAvatarProps) {
|
|
40
|
+
const [workingKey, setWorkingKey] = useState(0);
|
|
41
|
+
const busy = gemieIsBusy(state);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (busy) setWorkingKey((key) => key + 1);
|
|
44
|
+
}, [busy]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<AgentAvatar
|
|
48
|
+
character={ALIA_AVATAR}
|
|
49
|
+
size={size}
|
|
50
|
+
label="Alia"
|
|
51
|
+
workingKey={workingKey}
|
|
52
|
+
interactive={interactive}
|
|
53
|
+
reactionKey={reactionKey}
|
|
54
|
+
portrait={portrait}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
});
|