@gemies/sdk 0.0.0-stage → 1.1.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 +1678 -0
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +516 -2
- package/package.json +105 -4
- package/src/accounts.ts +29 -0
- 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/GemieAccounts.tsx +433 -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 +141 -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/alia-gemie.ts +6 -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 +333 -0
- package/src/lib/copy-es.ts +330 -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/gemie-accounts.ts +182 -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 +60 -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 +85 -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,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
|
+
}
|
package/src/lib/pcm.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PCM16 in and out of the -1..1 floats audio engines work in, and the level a
|
|
3
|
+
* buffer reads at. No imports, so every engine (and the tests) shares one
|
|
4
|
+
* definition of the conversion and of the meter.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { levelFromFrames } from './audio-level';
|
|
8
|
+
|
|
9
|
+
/** Floats (-1..1) to PCM16 little-endian bytes. */
|
|
10
|
+
export function floatToPcm16(samples: ArrayLike<number>): Uint8Array {
|
|
11
|
+
const bytes = new Uint8Array(samples.length * 2);
|
|
12
|
+
const view = new DataView(bytes.buffer);
|
|
13
|
+
for (let index = 0; index < samples.length; index += 1) {
|
|
14
|
+
const clamped = Math.max(-1, Math.min(1, samples[index] ?? 0));
|
|
15
|
+
view.setInt16(index * 2, clamped < 0 ? clamped * 0x8000 : clamped * 0x7fff, true);
|
|
16
|
+
}
|
|
17
|
+
return bytes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** PCM16 little-endian bytes to floats (-1..1). A trailing odd byte is dropped. */
|
|
21
|
+
export function pcm16ToFloat(bytes: Uint8Array): Float32Array {
|
|
22
|
+
const count = Math.floor(bytes.byteLength / 2);
|
|
23
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, count * 2);
|
|
24
|
+
const samples = new Float32Array(count);
|
|
25
|
+
for (let index = 0; index < count; index += 1) {
|
|
26
|
+
samples[index] = view.getInt16(index * 2, true) / 0x8000;
|
|
27
|
+
}
|
|
28
|
+
return samples;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Linear resampling. Good enough for speech in a call: the model hears 24 kHz
|
|
33
|
+
* and the device plays at its own rate; neither is a recording kept.
|
|
34
|
+
*/
|
|
35
|
+
export function resampleLinear(
|
|
36
|
+
samples: Float32Array,
|
|
37
|
+
fromRate: number,
|
|
38
|
+
toRate: number,
|
|
39
|
+
): Float32Array {
|
|
40
|
+
if (fromRate === toRate || samples.length === 0) return samples;
|
|
41
|
+
const ratio = fromRate / toRate;
|
|
42
|
+
const length = Math.max(1, Math.floor(samples.length / ratio));
|
|
43
|
+
const out = new Float32Array(length);
|
|
44
|
+
for (let index = 0; index < length; index += 1) {
|
|
45
|
+
const position = index * ratio;
|
|
46
|
+
const left = Math.floor(position);
|
|
47
|
+
const right = Math.min(left + 1, samples.length - 1);
|
|
48
|
+
const fraction = position - left;
|
|
49
|
+
out[index] = (samples[left] ?? 0) * (1 - fraction) + (samples[right] ?? 0) * fraction;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The field's 0..1 level of a PCM16 buffer, on the dictation meter's dBFS scale. */
|
|
55
|
+
export function levelOfPcm16(bytes: Uint8Array): number {
|
|
56
|
+
return levelFromFrames(Array.from(pcm16ToFloat(bytes)));
|
|
57
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ComposerPanelPermissionOption } from '@oxy.so/bloom/composer-panel';
|
|
2
|
+
import { RiComputerLine } from '@oxy.so/bloom/icons/RiComputerLine';
|
|
3
|
+
import { RiFireLine } from '@oxy.so/bloom/icons/RiFireLine';
|
|
4
|
+
import { RiFlashlightLine } from '@oxy.so/bloom/icons/RiFlashlightLine';
|
|
5
|
+
import { RiLightbulbLine } from '@oxy.so/bloom/icons/RiLightbulbLine';
|
|
6
|
+
import { RiRocket2Line } from '@oxy.so/bloom/icons/RiRocket2Line';
|
|
7
|
+
import { RiSparkling2Line } from '@oxy.so/bloom/icons/RiSparkling2Line';
|
|
8
|
+
import { RiSpeedUpLine } from '@oxy.so/bloom/icons/RiSpeedUpLine';
|
|
9
|
+
import { RiVipCrownLine } from '@oxy.so/bloom/icons/RiVipCrownLine';
|
|
10
|
+
import { POWER_LEVELS, type PowerLevel } from '../runtime/power-levels';
|
|
11
|
+
import type { Translate } from './copy';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The power-level selector, in the shape Bloom's composer mode selector takes.
|
|
15
|
+
*
|
|
16
|
+
* Alia's users choose how much power a turn gets, never which hosted model answers it: Oxy picks
|
|
17
|
+
* the model of the chosen level for every request. The selector is `ComposerPill`'s mode picker —
|
|
18
|
+
* Bloom's own radio menu of a label, a short description and an icon per mode — so the seven
|
|
19
|
+
* levels read the same way every Bloom mode selector does. Models running on the person's OWN
|
|
20
|
+
* devices follow the levels: that is their machine, not a model Alia offers, and which devices
|
|
21
|
+
* are connected is the host's to say.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type IconComponent = ComposerPanelPermissionOption['icon'];
|
|
25
|
+
|
|
26
|
+
/** One glyph per level, rising with the power it stands for. */
|
|
27
|
+
export const POWER_LEVEL_ICONS: Record<PowerLevel, IconComponent> = {
|
|
28
|
+
auto: RiSparkling2Line,
|
|
29
|
+
instant: RiFlashlightLine,
|
|
30
|
+
medium: RiSpeedUpLine,
|
|
31
|
+
high: RiLightbulbLine,
|
|
32
|
+
xhigh: RiFireLine,
|
|
33
|
+
pro: RiRocket2Line,
|
|
34
|
+
ultra: RiVipCrownLine,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** A model running on one of the person's own devices, offered after the levels. */
|
|
38
|
+
export interface DeviceModel {
|
|
39
|
+
/** What a request carries as `model` (`local/<runtime>/<model>`). */
|
|
40
|
+
id: string;
|
|
41
|
+
/** The tag the person knows it by, e.g. `llama3.1:8b`. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Which of their devices is running it. */
|
|
44
|
+
deviceLabel: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The selector's options: the seven levels, then the person's device models. */
|
|
48
|
+
export function buildPowerLevelOptions(
|
|
49
|
+
t: Translate,
|
|
50
|
+
deviceModels: readonly DeviceModel[],
|
|
51
|
+
): ComposerPanelPermissionOption[] {
|
|
52
|
+
return [
|
|
53
|
+
...POWER_LEVELS.map((level) => ({
|
|
54
|
+
id: level,
|
|
55
|
+
label: t(`powerLevels.${level}.label`),
|
|
56
|
+
description: t(`powerLevels.${level}.description`),
|
|
57
|
+
icon: POWER_LEVEL_ICONS[level],
|
|
58
|
+
})),
|
|
59
|
+
...deviceModels.map((model) => ({
|
|
60
|
+
id: model.id,
|
|
61
|
+
label: model.name,
|
|
62
|
+
description: t('powerLevels.onDevice', { device: model.deviceLabel }),
|
|
63
|
+
icon: RiComputerLine,
|
|
64
|
+
})),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// The clarifying questions an assistant turn asked, read back from the stored tool call.
|
|
2
|
+
//
|
|
3
|
+
// The server's `askUserQuestion` ends the turn at the card, so the question IS the tool
|
|
4
|
+
// call: it is stored with the message, survives a reload, and is answered by the person's
|
|
5
|
+
// next message. Pure functions, no React Native, so a host's models and tests can use them.
|
|
6
|
+
|
|
7
|
+
import type { Message, ToolInvocation } from '../runtime/types';
|
|
8
|
+
|
|
9
|
+
/** The tool's name on the wire. */
|
|
10
|
+
export const ASK_USER_QUESTION_TOOL = 'askUserQuestion';
|
|
11
|
+
|
|
12
|
+
export interface AskedOption {
|
|
13
|
+
label: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AskedQuestion {
|
|
18
|
+
question: string;
|
|
19
|
+
options: AskedOption[];
|
|
20
|
+
multiSelect: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What the person picked for one question: option indexes, in option order, and typed text. */
|
|
24
|
+
export interface QuestionAnswer {
|
|
25
|
+
picked: number[];
|
|
26
|
+
other?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const isQuestionInvocation = (inv: Pick<ToolInvocation, 'toolName'>): boolean =>
|
|
30
|
+
inv.toolName === ASK_USER_QUESTION_TOOL;
|
|
31
|
+
|
|
32
|
+
const text = (value: unknown): string | null =>
|
|
33
|
+
typeof value === 'string' && value.trim() !== '' ? value.trim() : null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The questions of a finished call, or `null` when it is not one or its arguments are not
|
|
37
|
+
* drawable. Model output is data the app did not write: every field is checked, and a
|
|
38
|
+
* malformed card is no card rather than a thrown render.
|
|
39
|
+
*/
|
|
40
|
+
export function askedQuestions(inv: ToolInvocation): AskedQuestion[] | null {
|
|
41
|
+
if (!isQuestionInvocation(inv) || inv.state !== 'result') return null;
|
|
42
|
+
const raw = (inv.args as { questions?: unknown } | undefined)?.questions;
|
|
43
|
+
if (!Array.isArray(raw)) return null;
|
|
44
|
+
|
|
45
|
+
const questions: AskedQuestion[] = [];
|
|
46
|
+
for (const item of raw) {
|
|
47
|
+
const q = item as { question?: unknown; options?: unknown; multiSelect?: unknown };
|
|
48
|
+
const question = text(q.question);
|
|
49
|
+
if (question === null || !Array.isArray(q.options)) return null;
|
|
50
|
+
const options: AskedOption[] = [];
|
|
51
|
+
for (const o of q.options) {
|
|
52
|
+
const label = text((o as { label?: unknown })?.label);
|
|
53
|
+
if (label === null) return null;
|
|
54
|
+
const description = text((o as { description?: unknown }).description);
|
|
55
|
+
options.push(description === null ? { label } : { label, description });
|
|
56
|
+
}
|
|
57
|
+
if (options.length < 2) return null;
|
|
58
|
+
questions.push({ question, options, multiSelect: q.multiSelect === true });
|
|
59
|
+
}
|
|
60
|
+
return questions.length === 0 ? null : questions;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The answers as the message the person "sends": one line per question, so the thread reads
|
|
65
|
+
* as what they said and the model reads the same text. Language-neutral on purpose.
|
|
66
|
+
*/
|
|
67
|
+
export function formatAnswers(questions: AskedQuestion[], answers: QuestionAnswer[]): string {
|
|
68
|
+
return questions
|
|
69
|
+
.map((q, i) => {
|
|
70
|
+
const answer = answers[i];
|
|
71
|
+
const parts = [
|
|
72
|
+
...(answer?.picked ?? []).map((index) => q.options[index]?.label),
|
|
73
|
+
answer?.other?.trim(),
|
|
74
|
+
].filter((part): part is string => !!part);
|
|
75
|
+
return `${q.question}\n→ ${parts.join(', ')}`;
|
|
76
|
+
})
|
|
77
|
+
.join('\n\n');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* What Alia asked in her last turn and the person has not answered yet: the questions of the
|
|
82
|
+
* last message when it is hers and finished. A message after them, typed or sent from the card,
|
|
83
|
+
* is the answer, so nothing is pending then.
|
|
84
|
+
*/
|
|
85
|
+
export function pendingQuestions(
|
|
86
|
+
messages: readonly Pick<Message, 'role' | 'toolInvocations'>[],
|
|
87
|
+
isStreaming: boolean,
|
|
88
|
+
): AskedQuestion[] {
|
|
89
|
+
const last = messages.at(-1);
|
|
90
|
+
if (isStreaming || last?.role !== 'assistant') return [];
|
|
91
|
+
return (last.toolInvocations ?? []).flatMap((invocation) => askedQuestions(invocation) ?? []);
|
|
92
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The language spoken, when the caller names none (dictation and calls).
|
|
3
|
+
*
|
|
4
|
+
* The browser's own language on web; the runtime's resolved locale on native
|
|
5
|
+
* (Hermes implements `Intl`); `en-US` when neither answers. An app should pass
|
|
6
|
+
* its UI locale instead — the Alia app does — because a person who chose
|
|
7
|
+
* Spanish in the app expects to be understood in Spanish whatever the device
|
|
8
|
+
* is set to.
|
|
9
|
+
*/
|
|
10
|
+
export function defaultSpeechLanguage(): string {
|
|
11
|
+
const browser = globalThis.navigator?.language;
|
|
12
|
+
if (typeof browser === 'string' && browser !== '') return browser;
|
|
13
|
+
try {
|
|
14
|
+
const resolved = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
15
|
+
if (resolved) return resolved;
|
|
16
|
+
} catch {
|
|
17
|
+
// No Intl on this runtime.
|
|
18
|
+
}
|
|
19
|
+
return 'en-US';
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { VoiceServerErrorCode } from './voice-protocol';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every way dictation or a voice call can fail that a person is told about,
|
|
5
|
+
* as a stable code (ADR 0017 §3, §7).
|
|
6
|
+
*
|
|
7
|
+
* - **Alia's**, sent by `/v1/voice/session` when it ends a call:
|
|
8
|
+
* `VoiceServerErrorCode` (`plan-required`, `credits-exhausted`,
|
|
9
|
+
* `realtime-*`, …).
|
|
10
|
+
* - **The device's:** `mic-denied`, `mic-unavailable`, `connection-lost`, and
|
|
11
|
+
* `voice-unavailable` where this platform has no audio engine for a call.
|
|
12
|
+
* - **Dictation's** (`POST /v1/audio/transcriptions`): `too-long` and
|
|
13
|
+
* `transcription-*`, beside the shared `mic-*` and `not-authenticated`.
|
|
14
|
+
*
|
|
15
|
+
* The hooks expose the code beside the English sentence so an app can say it in
|
|
16
|
+
* its own language; the sentence stays for a consumer with no translations.
|
|
17
|
+
* Nothing here is a recognizer's: speech is recognized by Kaana, never by the
|
|
18
|
+
* browser or the operating system.
|
|
19
|
+
*/
|
|
20
|
+
export type VoiceErrorCode =
|
|
21
|
+
| VoiceServerErrorCode
|
|
22
|
+
| 'mic-denied'
|
|
23
|
+
| 'mic-unavailable'
|
|
24
|
+
| 'connection-lost'
|
|
25
|
+
| 'voice-unavailable'
|
|
26
|
+
| 'too-long'
|
|
27
|
+
| 'transcription-unavailable'
|
|
28
|
+
| 'transcription-limited'
|
|
29
|
+
| 'transcription-rejected'
|
|
30
|
+
| 'transcription-failed';
|
|
31
|
+
|
|
32
|
+
/** The English copy for each code. */
|
|
33
|
+
export const VOICE_ERROR_MESSAGES: Readonly<Record<VoiceErrorCode, string>> = {
|
|
34
|
+
'not-authenticated': 'Not authenticated',
|
|
35
|
+
'credential-not-supported': 'Voice is only available when you are signed in to Alia',
|
|
36
|
+
'plan-required': 'Voice mode needs a paid plan',
|
|
37
|
+
'credits-exhausted': "You've run out of credits for this call",
|
|
38
|
+
'agent-unavailable': 'This agent is not available for a call',
|
|
39
|
+
'invalid-request': 'The call could not be started',
|
|
40
|
+
'resume-unavailable': 'The call could not be picked up again — start a new one',
|
|
41
|
+
'realtime-unavailable': 'Voice is not available right now — try again later',
|
|
42
|
+
'realtime-limited': 'Voice has reached its limit for now — try again later',
|
|
43
|
+
'realtime-rejected': 'The call could not be started with these settings',
|
|
44
|
+
'realtime-failed': 'The call failed — try again',
|
|
45
|
+
'mic-denied': 'Microphone permission required',
|
|
46
|
+
'mic-unavailable': 'The microphone could not be used — check your input devices',
|
|
47
|
+
'connection-lost': 'The connection was lost',
|
|
48
|
+
'voice-unavailable': 'Voice is not available on this device or browser',
|
|
49
|
+
'too-long': 'That dictation was too long — five minutes at most',
|
|
50
|
+
'transcription-unavailable': 'Dictation is not available right now',
|
|
51
|
+
'transcription-limited': 'Dictation has reached its limit for now — try again later',
|
|
52
|
+
'transcription-rejected': 'That recording could not be transcribed',
|
|
53
|
+
'transcription-failed': 'Dictation failed — try again',
|
|
54
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech out: ask `POST /v1/audio/speech` for a clip, and play one.
|
|
3
|
+
*
|
|
4
|
+
* Shared by read-aloud (`useTTS`) and voice mode (`useVoiceRoom`) so both speak
|
|
5
|
+
* through the one route Alia has for it — Alia → Oxy → Kaana, billed by Oxy per
|
|
6
|
+
* call — with the same request body and the same error copy. Voice names are
|
|
7
|
+
* the PRODUCT's (`male` / `female`); the route maps them, and no upstream voice
|
|
8
|
+
* name ever appears on this side.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AudioRequestAuthentication } from './audio-request-auth';
|
|
12
|
+
|
|
13
|
+
export type ProductVoice = 'male' | 'female';
|
|
14
|
+
|
|
15
|
+
export type SpeechClipRequest = AudioRequestAuthentication & {
|
|
16
|
+
readonly apiUrl: string;
|
|
17
|
+
/** A speech model; omitted, the server's own speech model answers. */
|
|
18
|
+
readonly model?: string;
|
|
19
|
+
readonly input: string;
|
|
20
|
+
readonly voice: ProductVoice;
|
|
21
|
+
readonly speed?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Both or neither: the saved message being read aloud. The route answers 404
|
|
24
|
+
* for one this person does not hold, and files the clip under that
|
|
25
|
+
* conversation, so deleting the conversation deletes it.
|
|
26
|
+
*/
|
|
27
|
+
readonly conversationId?: string;
|
|
28
|
+
readonly messageId?: string;
|
|
29
|
+
readonly signal: AbortSignal;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The codes `/v1/audio/speech` answers a failure with, plus the two this side
|
|
34
|
+
* knows on its own: `NOT_AUTHENTICATED` (no session token, or the route said
|
|
35
|
+
* 401) and `INVALID_REQUEST` (the route refused the body).
|
|
36
|
+
*/
|
|
37
|
+
export type SpeechClipErrorCode =
|
|
38
|
+
| 'SPEECH_UNAVAILABLE'
|
|
39
|
+
| 'SPEECH_REJECTED'
|
|
40
|
+
| 'SPEECH_LIMIT_REACHED'
|
|
41
|
+
| 'SPEECH_PROVIDER_FAILED'
|
|
42
|
+
| 'SPEECH_GENERATION_FAILED'
|
|
43
|
+
| 'INVALID_REQUEST'
|
|
44
|
+
| 'NOT_AUTHENTICATED';
|
|
45
|
+
|
|
46
|
+
const SERVER_CODES: ReadonlySet<string> = new Set<SpeechClipErrorCode>([
|
|
47
|
+
'SPEECH_UNAVAILABLE',
|
|
48
|
+
'SPEECH_REJECTED',
|
|
49
|
+
'SPEECH_LIMIT_REACHED',
|
|
50
|
+
'SPEECH_PROVIDER_FAILED',
|
|
51
|
+
'SPEECH_GENERATION_FAILED',
|
|
52
|
+
'INVALID_REQUEST',
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A clip that could not be made, with what the route said about it: the HTTP
|
|
57
|
+
* status (`null` when no request was answered) and its typed `code` (`null`
|
|
58
|
+
* when the route named none this SDK knows — a network failure, an older or
|
|
59
|
+
* newer server).
|
|
60
|
+
*/
|
|
61
|
+
export class SpeechClipError extends Error {
|
|
62
|
+
readonly status: number | null;
|
|
63
|
+
readonly code: SpeechClipErrorCode | null;
|
|
64
|
+
readonly retryable: boolean;
|
|
65
|
+
/** Oxy's request id, for support, when the route gave one. */
|
|
66
|
+
readonly requestId: string | null;
|
|
67
|
+
|
|
68
|
+
constructor(
|
|
69
|
+
message: string,
|
|
70
|
+
details: {
|
|
71
|
+
status: number | null;
|
|
72
|
+
code: SpeechClipErrorCode | null;
|
|
73
|
+
retryable?: boolean;
|
|
74
|
+
requestId?: string | null;
|
|
75
|
+
},
|
|
76
|
+
) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = 'SpeechClipError';
|
|
79
|
+
this.status = details.status;
|
|
80
|
+
this.code = details.code;
|
|
81
|
+
this.retryable = details.retryable ?? false;
|
|
82
|
+
this.requestId = details.requestId ?? null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function clipErrorFrom(status: number, body: unknown): SpeechClipError {
|
|
87
|
+
const envelope =
|
|
88
|
+
body !== null && typeof body === 'object' ? (body as { error?: unknown }).error : undefined;
|
|
89
|
+
const error =
|
|
90
|
+
envelope !== null && typeof envelope === 'object'
|
|
91
|
+
? (envelope as {
|
|
92
|
+
code?: unknown;
|
|
93
|
+
message?: unknown;
|
|
94
|
+
retryable?: unknown;
|
|
95
|
+
requestId?: unknown;
|
|
96
|
+
})
|
|
97
|
+
: {};
|
|
98
|
+
const named =
|
|
99
|
+
typeof error.code === 'string' && SERVER_CODES.has(error.code)
|
|
100
|
+
? (error.code as SpeechClipErrorCode)
|
|
101
|
+
: null;
|
|
102
|
+
const code = named ?? (status === 401 ? 'NOT_AUTHENTICATED' : null);
|
|
103
|
+
const message =
|
|
104
|
+
status === 504
|
|
105
|
+
? 'Request timed out — please try again'
|
|
106
|
+
: typeof error.message === 'string' && error.message !== ''
|
|
107
|
+
? error.message
|
|
108
|
+
: typeof envelope === 'string' && envelope !== ''
|
|
109
|
+
? envelope
|
|
110
|
+
: 'TTS failed';
|
|
111
|
+
return new SpeechClipError(message, {
|
|
112
|
+
status,
|
|
113
|
+
code,
|
|
114
|
+
retryable: error.retryable === true,
|
|
115
|
+
requestId: typeof error.requestId === 'string' ? error.requestId : null,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Synthesize `input` and return the private link the route answers with.
|
|
121
|
+
*
|
|
122
|
+
* @throws {SpeechClipError} when the route refuses or answers no link; a
|
|
123
|
+
* network failure or an abort is thrown as `fetch` threw it.
|
|
124
|
+
*/
|
|
125
|
+
export async function requestSpeechClip(request: SpeechClipRequest): Promise<string> {
|
|
126
|
+
if (request.token === '')
|
|
127
|
+
throw new SpeechClipError('Not authenticated', { status: null, code: 'NOT_AUTHENTICATED' });
|
|
128
|
+
const response = await (request.transport?.fetch ?? fetch)(`${request.apiUrl}/v1/audio/speech`, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
signal: request.signal,
|
|
131
|
+
redirect: 'error',
|
|
132
|
+
credentials: 'omit',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
...(request.transport ? {} : { Authorization: `Bearer ${request.token}` }),
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify({
|
|
138
|
+
model: request.model,
|
|
139
|
+
input: request.input,
|
|
140
|
+
voice: request.voice,
|
|
141
|
+
speed: request.speed,
|
|
142
|
+
conversationId: request.conversationId,
|
|
143
|
+
messageId: request.messageId,
|
|
144
|
+
}),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
throw clipErrorFrom(response.status, await response.json().catch(() => null));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const data = (await response.json().catch(() => ({}))) as { audioUrl?: unknown };
|
|
152
|
+
request.signal.throwIfAborted();
|
|
153
|
+
if (typeof data.audioUrl !== 'string' || data.audioUrl === '')
|
|
154
|
+
throw new SpeechClipError('TTS failed', { status: response.status, code: null });
|
|
155
|
+
return data.audioUrl;
|
|
156
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { GemieSuggestion } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which suggestions a draft gets, shared by the Alia app and the SDK chat so they offer the
|
|
5
|
+
* same rows: the welcome suggestions while the draft is short, and from two characters the
|
|
6
|
+
* search's matches with the typed part located inside each.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Up to this many rows. */
|
|
10
|
+
const MAX_ROWS = 6;
|
|
11
|
+
/** The draft length at which the search takes over from the welcome list. */
|
|
12
|
+
export const SEARCH_FROM = 2;
|
|
13
|
+
/** How long typing settles before the search is asked. */
|
|
14
|
+
export const SEARCH_DEBOUNCE_MS = 200;
|
|
15
|
+
|
|
16
|
+
export interface Completion<T extends GemieSuggestion = GemieSuggestion> {
|
|
17
|
+
suggestion: T;
|
|
18
|
+
/** The typed text's range inside `suggestion.text`, or an empty range. */
|
|
19
|
+
matchStart: number;
|
|
20
|
+
matchEnd: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Which rows to show for a draft: welcome while short, matches from two characters. */
|
|
24
|
+
export function composerCompletions<T extends GemieSuggestion>(
|
|
25
|
+
draft: string,
|
|
26
|
+
welcome: readonly T[] | undefined,
|
|
27
|
+
matches: readonly T[] | undefined,
|
|
28
|
+
): Completion<T>[] {
|
|
29
|
+
const query = draft.trim();
|
|
30
|
+
if (query.length < SEARCH_FROM) {
|
|
31
|
+
return (welcome ?? []).slice(0, MAX_ROWS).map((suggestion) => ({
|
|
32
|
+
suggestion,
|
|
33
|
+
matchStart: 0,
|
|
34
|
+
matchEnd: 0,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
const lower = query.toLowerCase();
|
|
38
|
+
const seen = new Set<string>();
|
|
39
|
+
const rows: Completion<T>[] = [];
|
|
40
|
+
for (const suggestion of matches ?? []) {
|
|
41
|
+
if (rows.length >= MAX_ROWS) break;
|
|
42
|
+
const text = suggestion.text.toLowerCase();
|
|
43
|
+
if (seen.has(text)) continue;
|
|
44
|
+
seen.add(text);
|
|
45
|
+
const start = text.indexOf(lower);
|
|
46
|
+
rows.push({
|
|
47
|
+
suggestion,
|
|
48
|
+
matchStart: start === -1 ? 0 : start,
|
|
49
|
+
matchEnd: start === -1 ? 0 : start + query.length,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return rows;
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { englishCopy, type Translate } from './copy';
|
|
2
|
+
|
|
3
|
+
/** Whether the catalogue names this tool itself; otherwise the label is made from its id. */
|
|
4
|
+
function isNamed(kind: 'pill' | 'done', toolName: string): boolean {
|
|
5
|
+
const key = `tasks.tool.${kind}.${toolName}`;
|
|
6
|
+
return englishCopy(key) !== key;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A tool's short label, in the reader's language when a translator is given. */
|
|
10
|
+
export function getToolPillLabel(toolName: string, t: Translate = englishCopy): string {
|
|
11
|
+
if (isNamed('pill', toolName)) return t(`tasks.tool.pill.${toolName}`);
|
|
12
|
+
|
|
13
|
+
// Oxy service tools: oxy_serviceName__toolName → "ServiceName"
|
|
14
|
+
if (toolName.startsWith('oxy_')) {
|
|
15
|
+
const parts = toolName.replace('oxy_', '').split('__');
|
|
16
|
+
return (parts[0] ?? '').replace(/[-_]/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Fallback: camelCase → "Camel Case"
|
|
20
|
+
return toolName
|
|
21
|
+
.replace(/([A-Z])/g, ' $1')
|
|
22
|
+
.replace(/^./, (c) => c.toUpperCase())
|
|
23
|
+
.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The finished form of a tool's label, for a task whose call has returned (`TaskList` swaps
|
|
28
|
+
* `runningTitle` for this once the task's steps land). Labels that are already names
|
|
29
|
+
* ("Telegram", "Email") read the same either way, so they fall back to the running label.
|
|
30
|
+
*/
|
|
31
|
+
export function getToolDoneLabel(toolName: string, t: Translate = englishCopy): string {
|
|
32
|
+
return isNamed('done', toolName)
|
|
33
|
+
? t(`tasks.tool.done.${toolName}`)
|
|
34
|
+
: getToolPillLabel(toolName, t);
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentRef } from 'react';
|
|
2
|
+
import type { TextInput } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a ref to a `TextInput` holds. `ComponentRef`, not `TextInput` itself: React Native 0.88
|
|
6
|
+
* types `TextInput` as a function component, so the class is no longer its instance type, and
|
|
7
|
+
* `focus()` is only on the instance. An interface rather than an alias, so a declaration that
|
|
8
|
+
* returns one can name it: on 0.88 the instance type lives in a file React Native does not export.
|
|
9
|
+
*/
|
|
10
|
+
export interface TextInputHandle extends ComponentRef<typeof TextInput> {}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ToolInvocation } from '../runtime/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where a tool call stands:
|
|
5
|
+
* - `running`: still in flight in a live turn.
|
|
6
|
+
* - `done`: it returned a result without an error.
|
|
7
|
+
* - `error`: it returned, and the result carries an `error`.
|
|
8
|
+
* - `interrupted`: it never returned and its turn is over — a stop, a failure, or a
|
|
9
|
+
* persisted turn cut short. It must not read as running.
|
|
10
|
+
*/
|
|
11
|
+
export type ToolCallStatus = 'running' | 'done' | 'error' | 'interrupted';
|
|
12
|
+
|
|
13
|
+
export function toolCallStatus(
|
|
14
|
+
inv: Pick<ToolInvocation, 'state' | 'result'>,
|
|
15
|
+
live: boolean,
|
|
16
|
+
): ToolCallStatus {
|
|
17
|
+
if (inv.state !== 'result') return live ? 'running' : 'interrupted';
|
|
18
|
+
const result: unknown = inv.result;
|
|
19
|
+
if (
|
|
20
|
+
result !== null &&
|
|
21
|
+
typeof result === 'object' &&
|
|
22
|
+
'error' in result &&
|
|
23
|
+
Boolean((result as { error?: unknown }).error)
|
|
24
|
+
) {
|
|
25
|
+
return 'error';
|
|
26
|
+
}
|
|
27
|
+
return 'done';
|
|
28
|
+
}
|