@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,53 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import type { GemieAvatarState } from '../components/GemieAvatar';
|
|
3
|
+
|
|
4
|
+
type Sources = Readonly<Record<string, GemieAvatarState>>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What Alia is doing, from every place that can know. Two sources feed it and neither owns it:
|
|
8
|
+
*
|
|
9
|
+
* - `local`: the turns running in THIS app, one entry per `useConversationThread` instance;
|
|
10
|
+
* - `remote`: runs the server reports for the person, one entry per agent session, so a button
|
|
11
|
+
* reacts to work that is not in any open chat.
|
|
12
|
+
*
|
|
13
|
+
* An idle source holds no entry, so neither map grows with use.
|
|
14
|
+
*/
|
|
15
|
+
interface GemieActivityStore {
|
|
16
|
+
local: Sources;
|
|
17
|
+
remote: Sources;
|
|
18
|
+
setLocal(source: string, state: GemieAvatarState): void;
|
|
19
|
+
setRemote(session: string, state: GemieAvatarState): void;
|
|
20
|
+
clearRemote(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function put(map: Sources, key: string, state: GemieAvatarState): Sources {
|
|
24
|
+
if (state === 'idle') {
|
|
25
|
+
if (!(key in map)) return map;
|
|
26
|
+
const { [key]: _gone, ...rest } = map;
|
|
27
|
+
return rest;
|
|
28
|
+
}
|
|
29
|
+
return map[key] === state ? map : { ...map, [key]: state };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const useGemieActivityStore = create<GemieActivityStore>((set) => ({
|
|
33
|
+
local: {},
|
|
34
|
+
remote: {},
|
|
35
|
+
setLocal: (source, state) => set((s) => ({ local: put(s.local, source, state) })),
|
|
36
|
+
setRemote: (session, state) => set((s) => ({ remote: put(s.remote, session, state) })),
|
|
37
|
+
clearRemote: () => set((s) => (Object.keys(s.remote).length === 0 ? s : { remote: {} })),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
/** The most telling thing any source is doing: a tool call outranks thinking, thinking outranks writing. */
|
|
41
|
+
const RANK: Record<GemieAvatarState, number> = { idle: 0, writing: 1, thinking: 2, working: 3 };
|
|
42
|
+
|
|
43
|
+
export function busiest(...maps: ReadonlyArray<Sources>): GemieAvatarState {
|
|
44
|
+
let top: GemieAvatarState = 'idle';
|
|
45
|
+
for (const map of maps) {
|
|
46
|
+
for (const state of Object.values(map)) if (RANK[state] > RANK[top]) top = state;
|
|
47
|
+
}
|
|
48
|
+
return top;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A primitive, so a subscriber re-renders when the state changes and not when a session does. */
|
|
52
|
+
export const selectGemieActivity = (s: GemieActivityStore): GemieAvatarState =>
|
|
53
|
+
busiest(s.local, s.remote);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComposerPanelAddMenuGroup } from '@oxy.so/bloom/composer-panel';
|
|
2
|
+
|
|
3
|
+
/** The rows of the composer's add menu, and what pressing one does. */
|
|
4
|
+
export interface GemieAddMenu {
|
|
5
|
+
groups: readonly ComposerPanelAddMenuGroup[];
|
|
6
|
+
onSelect: (rowId: string) => void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { parseAvatarCharacter, type AvatarCharacter } from '@oxy.so/bloom/agent-avatar';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The look of an agent whose own is not known: a server that does not send one yet, an agent that
|
|
5
|
+
* has since been deleted, a stored character this Bloom cannot draw. One neutral character, the same
|
|
6
|
+
* everywhere, so an unknown look is recognisably "not chosen" and never one that belongs to somebody.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_AGENT_CHARACTER: AvatarCharacter = {
|
|
9
|
+
shape: 'rounded_cube',
|
|
10
|
+
eyes: 'oval',
|
|
11
|
+
eyewear: 'none',
|
|
12
|
+
accessory: 'none',
|
|
13
|
+
color: 'violet',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The character an agent is drawn as, from the JSON the server stores for it
|
|
18
|
+
* (`agents.character`): Bloom's own parser decides what it can draw, and anything else is the
|
|
19
|
+
* default look rather than an avatar that fails to render.
|
|
20
|
+
*/
|
|
21
|
+
export function readAgentCharacter(value: unknown): AvatarCharacter {
|
|
22
|
+
if (value === null || value === undefined) return DEFAULT_AGENT_CHARACTER;
|
|
23
|
+
try {
|
|
24
|
+
return parseAvatarCharacter(value);
|
|
25
|
+
} catch {
|
|
26
|
+
return DEFAULT_AGENT_CHARACTER;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AvatarCharacter } from '@oxy.so/bloom/agent-avatar';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Alia's likeness in Bloom's character renderer: the six-lobed flower in orchid, plain oval
|
|
5
|
+
* eyes, nothing on its head. It is `blue_beret` with the hat taken off and the paint changed,
|
|
6
|
+
* so Bloom retargets that preset's animation onto it; change it here and nowhere else.
|
|
7
|
+
*
|
|
8
|
+
* A module of its own, without React.
|
|
9
|
+
*/
|
|
10
|
+
export const ALIA_AVATAR: AvatarCharacter = {
|
|
11
|
+
preset: 'blue_beret',
|
|
12
|
+
accessory: 'none',
|
|
13
|
+
color: 'orchid',
|
|
14
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alia's gemie: the official, global `agents` row everybody uses (ADR 0034 §2), seeded with this
|
|
3
|
+
* fixed id. A client that addresses her by id — her thread, her connected accounts — uses it. A
|
|
4
|
+
* leaf: imports nothing.
|
|
5
|
+
*/
|
|
6
|
+
export const ALIA_GEMIE_ID = '01a1cf00-cecf-7a24-868b-42b452105a6f';
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the composer will take in, and how far a file has actually got.
|
|
3
|
+
*
|
|
4
|
+
* Alia had no answer to either question. A file reached the attachment strip
|
|
5
|
+
* by exactly one route — a picker that hands back a `uri` and asks nothing —
|
|
6
|
+
* so there was no size it would refuse, no kind it would separate, and, once
|
|
7
|
+
* drag-and-drop existed, no shared place to state those rules for a second
|
|
8
|
+
* route. Worse, a drag is a stateful gesture: the browser fires `dragenter`
|
|
9
|
+
* and `dragleave` for every element the pointer crosses, so a drop affordance
|
|
10
|
+
* driven by a boolean flickers off the instant the pointer moves from the bar
|
|
11
|
+
* onto the textarea INSIDE it. The counter that fixes that is four lines of
|
|
12
|
+
* arithmetic guarding a visible effect, which is precisely the kind of thing
|
|
13
|
+
* that is easy to get subtly wrong and almost impossible to watch going wrong.
|
|
14
|
+
*
|
|
15
|
+
* So it lives here, beside `turn-selection.ts`, under the same rule: nothing
|
|
16
|
+
* in this file may import react-native, read a store, or touch the DOM. The
|
|
17
|
+
* reader that moves the bytes is a platform adapter and lives with the
|
|
18
|
+
* composer; what can be decided by arithmetic is decided here, where it can be
|
|
19
|
+
* checked without mounting a composer or staging a drag.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The largest file the composer will take.
|
|
24
|
+
*
|
|
25
|
+
* An attached image is not uploaded anywhere — the app's `attachment-utils.ts`
|
|
26
|
+
* inlines it into the request as a `data:` URL — so its bytes are carried in
|
|
27
|
+
* memory as a base64 string roughly a third larger than the file, twice over
|
|
28
|
+
* while the request is built. 20 MiB is the point past which that stops being
|
|
29
|
+
* a message and starts being a reason the tab dies.
|
|
30
|
+
*/
|
|
31
|
+
export const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
32
|
+
|
|
33
|
+
export type IntakeKind = 'image' | 'document';
|
|
34
|
+
|
|
35
|
+
/** Why a file was turned away. Each one has its own sentence to the user. */
|
|
36
|
+
export type IntakeRefusal = 'empty' | 'too-large' | 'unsupported';
|
|
37
|
+
|
|
38
|
+
export type IntakeVerdict =
|
|
39
|
+
| { accepted: true; kind: IntakeKind }
|
|
40
|
+
| { accepted: false; refusal: IntakeRefusal };
|
|
41
|
+
|
|
42
|
+
export interface IntakeCandidate {
|
|
43
|
+
name: string;
|
|
44
|
+
mimeType: string;
|
|
45
|
+
size: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Extensions that name a picture when the browser will not.
|
|
50
|
+
*
|
|
51
|
+
* A dragged file's `type` is filled in from the OS, and it comes through empty
|
|
52
|
+
* often enough to matter — from an archive manager, from a file manager with a
|
|
53
|
+
* thin mime database, from anything that drops a path rather than a handle.
|
|
54
|
+
* Falling back to the name is not a nicety: without it a dropped `.png` is
|
|
55
|
+
* filed as a document, and a document is never inlined into the request at all.
|
|
56
|
+
*/
|
|
57
|
+
const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'avif', 'heic', 'heif'];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether a candidate is a picture, by what the browser says first and by its
|
|
61
|
+
* name only when the browser said nothing.
|
|
62
|
+
*/
|
|
63
|
+
export function intakeKind(candidate: IntakeCandidate): IntakeKind {
|
|
64
|
+
if (candidate.mimeType.startsWith('image/')) return 'image';
|
|
65
|
+
const extension = candidate.name.split('.').pop()?.toLowerCase() ?? '';
|
|
66
|
+
return IMAGE_EXTENSIONS.includes(extension) ? 'image' : 'document';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The one gate both web routes pass through — pasted files and dropped ones —
|
|
71
|
+
* so a rule cannot hold for one and not the other.
|
|
72
|
+
*
|
|
73
|
+
* The zero-byte refusal is not pedantry about empty files. Dropping a FOLDER
|
|
74
|
+
* on web yields a `File` with size 0 and no type, in every browser; without
|
|
75
|
+
* this the composer accepts a tile named after a directory whose contents it
|
|
76
|
+
* will never have, and whose read completes with nothing in it.
|
|
77
|
+
*/
|
|
78
|
+
export function classifyIntake(candidate: IntakeCandidate): IntakeVerdict {
|
|
79
|
+
if (candidate.size <= 0) return { accepted: false, refusal: 'empty' };
|
|
80
|
+
if (candidate.size > MAX_ATTACHMENT_BYTES) return { accepted: false, refusal: 'too-large' };
|
|
81
|
+
return { accepted: true, kind: intakeKind(candidate) };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The four things that can happen to the count of drags over the composer. */
|
|
85
|
+
export type DragStep = 'enter' | 'leave' | 'drop' | 'reset';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* How many dragged-over elements deep the pointer is.
|
|
89
|
+
*
|
|
90
|
+
* `dragenter` and `dragleave` fire per ELEMENT, not per target, and they fire
|
|
91
|
+
* in that order: moving from the bar onto the textarea inside it produces
|
|
92
|
+
* `dragenter` (textarea) then `dragleave` (bar). A boolean set by enter and
|
|
93
|
+
* cleared by leave therefore ends that move switched OFF while the pointer is
|
|
94
|
+
* still over the composer, and the affordance strobes as the pointer crosses
|
|
95
|
+
* each child on the way in. Counting elements instead is the standard answer,
|
|
96
|
+
* and the depth only reaches zero when the pointer has genuinely left
|
|
97
|
+
* everything.
|
|
98
|
+
*
|
|
99
|
+
* `drop` resets rather than decrements: the browser does not send the matching
|
|
100
|
+
* `dragleave` for the element the file landed on, so a decrement leaves the
|
|
101
|
+
* count stuck at one and the overlay pinned over the composer for good.
|
|
102
|
+
*/
|
|
103
|
+
export function nextDragDepth(depth: number, step: DragStep): number {
|
|
104
|
+
switch (step) {
|
|
105
|
+
case 'enter':
|
|
106
|
+
return depth + 1;
|
|
107
|
+
case 'leave':
|
|
108
|
+
// Clamped, because a `dragleave` can arrive without its `dragenter` — a
|
|
109
|
+
// drag that began before the listener was attached, or one whose
|
|
110
|
+
// `dragenter` was swallowed by an element that stopped propagation. A
|
|
111
|
+
// negative depth would then need two full entries before the overlay
|
|
112
|
+
// came back.
|
|
113
|
+
return Math.max(0, depth - 1);
|
|
114
|
+
case 'drop':
|
|
115
|
+
case 'reset':
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether this drag is carrying files at all.
|
|
122
|
+
*
|
|
123
|
+
* `DataTransfer.types` contains the literal `"Files"` when it is; dragging
|
|
124
|
+
* selected text or a link gives `"text/plain"` and `"text/uri-list"` instead.
|
|
125
|
+
* Without the question the composer lights up when the user drags a word
|
|
126
|
+
* across it, and then swallows the drop.
|
|
127
|
+
*/
|
|
128
|
+
export function dragCarriesFiles(types: readonly string[] | undefined): boolean {
|
|
129
|
+
return types !== undefined && types.includes('Files');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* How far a read has got, as a fraction — or `null` when nothing measurable
|
|
134
|
+
* was reported.
|
|
135
|
+
*
|
|
136
|
+
* `null` is the important return, and it is why this is a function rather than
|
|
137
|
+
* a division at the call site. #608 §7: "Cuando no hay avance medible, mostrar
|
|
138
|
+
* actividad indeterminada. No inventar porcentajes." A `ProgressEvent` whose
|
|
139
|
+
* `lengthComputable` is false carries a `total` of 0, and dividing by it gives
|
|
140
|
+
* `NaN` or `Infinity` — both of which render as SOMETHING once handed to a
|
|
141
|
+
* bar, and that something is invented. Bloom's `use-attachment-queue.ts`
|
|
142
|
+
* invents its number outright, from a `Math.random()` ramp on a 50ms tick;
|
|
143
|
+
* nothing in this file may grow a timer.
|
|
144
|
+
*/
|
|
145
|
+
export function readFraction(progress: {
|
|
146
|
+
lengthComputable: boolean;
|
|
147
|
+
loaded: number;
|
|
148
|
+
total: number;
|
|
149
|
+
}): number | null {
|
|
150
|
+
if (!progress.lengthComputable) return null;
|
|
151
|
+
if (!Number.isFinite(progress.total) || progress.total <= 0) return null;
|
|
152
|
+
if (!Number.isFinite(progress.loaded) || progress.loaded < 0) return null;
|
|
153
|
+
return Math.min(1, progress.loaded / progress.total);
|
|
154
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ComposerPanelAttachment } from '@oxy.so/bloom/composer-panel';
|
|
2
|
+
import type { IntakeItem } from '../hooks/useAttachmentIntake';
|
|
3
|
+
import type { GemieAttachment } from '../types';
|
|
4
|
+
import { MAX_ATTACHMENT_BYTES } from './attachment-intake';
|
|
5
|
+
import type { GemieChatLabels } from './labels';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The composer's tiles: landed files, then the ones the intake still holds.
|
|
9
|
+
*
|
|
10
|
+
* A file whose read failed, or that was refused, stays in the strip with the
|
|
11
|
+
* sentence that says why — a drop of six where one did not make it is a
|
|
12
|
+
* sentence the user needs beside the five that did, not a toast that slides
|
|
13
|
+
* away. `retryable` marks the ones a second read could fix: a failed read,
|
|
14
|
+
* whose `File` the intake kept. A refusal is not: the same 30 MB file reaches
|
|
15
|
+
* the same verdict — and since Bloom's retry button is the panel's, drawn on
|
|
16
|
+
* every error tile once `onAttachmentRetry` is set, the composer shows a
|
|
17
|
+
* refusal as a toast rather than as a tile it would offer to retry.
|
|
18
|
+
*/
|
|
19
|
+
export interface ComposerTile extends ComposerPanelAttachment {
|
|
20
|
+
error?: string;
|
|
21
|
+
retryable?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The words a tile and a refusal use. */
|
|
25
|
+
type TileLabels = Pick<
|
|
26
|
+
GemieChatLabels,
|
|
27
|
+
'composerUntitled' | 'fileReadFailed' | 'fileTooLarge' | 'fileEmpty' | 'fileUnsupported'
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
/** Why an intake item is not an attachment, or `undefined` while it is being read. */
|
|
31
|
+
export function intakeError(item: IntakeItem, labels: TileLabels): string | undefined {
|
|
32
|
+
const name = item.name || labels.composerUntitled;
|
|
33
|
+
switch (item.status) {
|
|
34
|
+
case 'reading':
|
|
35
|
+
return undefined;
|
|
36
|
+
case 'failed':
|
|
37
|
+
return labels.fileReadFailed(name);
|
|
38
|
+
case 'refused':
|
|
39
|
+
if (item.refusal === 'unsupported') return labels.fileUnsupported(name);
|
|
40
|
+
return item.refusal === 'too-large'
|
|
41
|
+
? labels.fileTooLarge(name, `${Math.round(MAX_ATTACHMENT_BYTES / (1024 * 1024))} MB`)
|
|
42
|
+
: labels.fileEmpty(name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function composerTiles(
|
|
47
|
+
attachments: readonly GemieAttachment[],
|
|
48
|
+
items: readonly IntakeItem[],
|
|
49
|
+
labels: TileLabels,
|
|
50
|
+
): ComposerTile[] {
|
|
51
|
+
return [
|
|
52
|
+
...attachments.map((a) => ({
|
|
53
|
+
id: a.id,
|
|
54
|
+
name: a.name,
|
|
55
|
+
kind: a.type === 'image' ? ('image' as const) : ('document' as const),
|
|
56
|
+
src: a.type === 'image' ? a.uri : undefined,
|
|
57
|
+
})),
|
|
58
|
+
...items.map((item): ComposerTile => {
|
|
59
|
+
const tile: ComposerTile = {
|
|
60
|
+
id: item.id,
|
|
61
|
+
name: item.name || labels.composerUntitled,
|
|
62
|
+
kind: item.kind === 'image' ? 'image' : 'document',
|
|
63
|
+
};
|
|
64
|
+
if (item.status === 'reading') {
|
|
65
|
+
// Real progress only; an unmeasured read is an empty ring, not a guess.
|
|
66
|
+
tile.progress = item.fraction === null ? 0 : Math.round(item.fraction * 100);
|
|
67
|
+
return tile;
|
|
68
|
+
}
|
|
69
|
+
tile.error = intakeError(item, labels);
|
|
70
|
+
tile.retryable = item.status === 'failed';
|
|
71
|
+
return tile;
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How audio becomes the ambient field's 0..1 level — one curve, one pair of
|
|
3
|
+
* time constants, for every source that drives it.
|
|
4
|
+
*
|
|
5
|
+
* Dictation got here first and is the reference: the microphone's level is
|
|
6
|
+
* taken as dBFS (on web, from an analyser beside the recorder —
|
|
7
|
+
* `dictation-recorder.ts`), normalised against a -60 floor, and `useAmbientWave`
|
|
8
|
+
* smooths it with a fast attack and a slow decay before it reaches
|
|
9
|
+
* `AmbientField`. That is the behaviour people like, so it is the behaviour
|
|
10
|
+
* everything else adopts rather than re-invents — including "read aloud", which
|
|
11
|
+
* until now drove the same field from a canned `withRepeat` loop that had never
|
|
12
|
+
* heard the clip.
|
|
13
|
+
*
|
|
14
|
+
* The two sources differ only in what they can measure and how fast:
|
|
15
|
+
*
|
|
16
|
+
* - A **recorder** publishes dBFS on a 100ms poll, through React state, and
|
|
17
|
+
* `levelFromDbfs` is the whole conversion.
|
|
18
|
+
* - A **player** publishes raw PCM as fast as the platform samples, so it needs
|
|
19
|
+
* `levelFromFrames` to reach the same dBFS first, and it cannot go through
|
|
20
|
+
* React at all — a render per audio buffer is not affordable. That is why the
|
|
21
|
+
* smoothing here is a time integration it can run per buffer rather than the
|
|
22
|
+
* `withTiming` the 10Hz path uses. The constants are the same; the CURVES are
|
|
23
|
+
* not. `withTiming` is at its target after `LEVEL_ATTACK_MS`, and this is an
|
|
24
|
+
* exponential whose time constant that is — 63% of the way at 60ms, ~95% at
|
|
25
|
+
* 180. Sharing the number keeps one knob for one feel; it does not make the
|
|
26
|
+
* two settle alike, and anyone tuning it should expect the two paths to move
|
|
27
|
+
* by different amounts.
|
|
28
|
+
*
|
|
29
|
+
* This module deliberately imports nothing. It is the part of the metering that
|
|
30
|
+
* can be driven with a buffer and asserted on, and `react-native-reanimated`
|
|
31
|
+
* does not load outside a bundler — a level that could only be observed by
|
|
32
|
+
* playing a real clip could not have a positive control.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The quietest the field can hear, in dBFS.
|
|
37
|
+
*
|
|
38
|
+
* Silence is -160 on a real meter and negative infinity on a computed one, so a
|
|
39
|
+
* practical floor is what makes the scale usable. -60 is dictation's, and the
|
|
40
|
+
* compression it produces is most of why that field reads well: it answers
|
|
41
|
+
* quiet speech nearly as much as loud, which is what a person watching a
|
|
42
|
+
* background wants, and unlike a linear reading it does not sit near zero for
|
|
43
|
+
* everything below a shout.
|
|
44
|
+
*/
|
|
45
|
+
const LEVEL_FLOOR_DBFS = -60;
|
|
46
|
+
|
|
47
|
+
/** Rise fast enough to catch the front of a syllable… */
|
|
48
|
+
export const LEVEL_ATTACK_MS = 60;
|
|
49
|
+
/** …and fall slowly enough that the field does not strobe between them. */
|
|
50
|
+
export const LEVEL_RELEASE_MS = 200;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* dBFS, as a recorder reports it, to the field's 0..1.
|
|
54
|
+
*
|
|
55
|
+
* `Number.NEGATIVE_INFINITY` is a legitimate input — it is what digital silence
|
|
56
|
+
* computes to — and clamps to 0 like anything below the floor.
|
|
57
|
+
*/
|
|
58
|
+
export function levelFromDbfs(dbfs: number): number {
|
|
59
|
+
const level = (dbfs - LEVEL_FLOOR_DBFS) / -LEVEL_FLOOR_DBFS;
|
|
60
|
+
return Math.min(1, Math.max(0, level));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One buffer of PCM frames, as a player reports them, to the field's 0..1.
|
|
65
|
+
*
|
|
66
|
+
* The frames are -1..1 on every platform `expo-audio` supports, so their RMS is
|
|
67
|
+
* an amplitude ratio and `20·log₁₀` is the dBFS a recorder would have reported
|
|
68
|
+
* for the same sound. Both sources end up on one scale.
|
|
69
|
+
*/
|
|
70
|
+
export function levelFromFrames(frames: readonly number[]): number {
|
|
71
|
+
if (frames.length === 0) return 0;
|
|
72
|
+
|
|
73
|
+
let sumSquares = 0;
|
|
74
|
+
for (const frame of frames) {
|
|
75
|
+
sumSquares += frame * frame;
|
|
76
|
+
}
|
|
77
|
+
const rms = Math.sqrt(sumSquares / frames.length);
|
|
78
|
+
|
|
79
|
+
// log₁₀(0) is -Infinity, which `levelFromDbfs` clamps — but only because it
|
|
80
|
+
// is asked to. Digital silence is exactly this case, so it is the one that
|
|
81
|
+
// matters most.
|
|
82
|
+
return levelFromDbfs(20 * Math.log10(rms));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface AudioLevelMeter {
|
|
86
|
+
/**
|
|
87
|
+
* Fold one buffer into the running level and return it.
|
|
88
|
+
*
|
|
89
|
+
* @param frames PCM frames, each -1..1, from `AudioSample.channels[n].frames`.
|
|
90
|
+
* @param nowMs A wall clock in milliseconds. The buffer rate is not fixed —
|
|
91
|
+
* web samples once per animation frame, the native taps run at the audio
|
|
92
|
+
* hardware's rate — so the smoothing is integrated against real elapsed
|
|
93
|
+
* time. The same sentence has to read the same at 30Hz and at 90Hz.
|
|
94
|
+
*/
|
|
95
|
+
push(frames: readonly number[], nowMs: number): number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A meter per clip: the level starts from silence and carries no history from
|
|
100
|
+
* whatever was playing before.
|
|
101
|
+
*/
|
|
102
|
+
export function createAudioLevelMeter(): AudioLevelMeter {
|
|
103
|
+
let level = 0;
|
|
104
|
+
let lastMs: number | null = null;
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
push(frames, nowMs) {
|
|
108
|
+
// A platform that cannot sample sends nothing rather than zeroes, but an
|
|
109
|
+
// empty buffer is the same statement: no new evidence, so no new level.
|
|
110
|
+
if (frames.length === 0) return level;
|
|
111
|
+
|
|
112
|
+
const target = levelFromFrames(frames);
|
|
113
|
+
|
|
114
|
+
if (lastMs === null) {
|
|
115
|
+
// Nothing to smooth against on the first buffer of a clip. Smoothing it
|
|
116
|
+
// from an invented zero would put a fade-in at the start of every clip
|
|
117
|
+
// that the audio does not have.
|
|
118
|
+
lastMs = nowMs;
|
|
119
|
+
level = target;
|
|
120
|
+
return level;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const elapsed = Math.max(0, nowMs - lastMs);
|
|
124
|
+
lastMs = nowMs;
|
|
125
|
+
const tau = target > level ? LEVEL_ATTACK_MS : LEVEL_RELEASE_MS;
|
|
126
|
+
level += (target - level) * (1 - Math.exp(-elapsed / tau));
|
|
127
|
+
return level;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Own audio calls share Oxy's session transport; explicit external bearers remain supported. */
|
|
2
|
+
export type AudioRequestAuthentication =
|
|
3
|
+
| { readonly transport: { fetch: typeof globalThis.fetch }; readonly token?: never }
|
|
4
|
+
| { readonly token: string; readonly transport?: never };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OxyServices } from '@oxy.so/core';
|
|
2
|
+
|
|
3
|
+
/** Bind an audio operation to core's session context while allowing token rotation. */
|
|
4
|
+
export function bindAudioSession(
|
|
5
|
+
oxy: Pick<OxyServices, 'createLinkedClient'>,
|
|
6
|
+
baseURL: string,
|
|
7
|
+
onInvalidated: () => void,
|
|
8
|
+
) {
|
|
9
|
+
const linked = oxy.createLinkedClient({ baseURL });
|
|
10
|
+
const epoch = linked.client.getSessionEpoch();
|
|
11
|
+
let disposed = false;
|
|
12
|
+
const current = () => !disposed && linked.client.getSessionEpoch() === epoch;
|
|
13
|
+
const unsubscribe = linked.client.addTokenChangeListener(() => {
|
|
14
|
+
if (!current()) onInvalidated();
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
fetch: linked.fetch,
|
|
18
|
+
getToken: (target: string, options?: { signal?: AbortSignal }) =>
|
|
19
|
+
current() ? linked.getAccessToken(target, options) : Promise.resolve(null),
|
|
20
|
+
dispose: () => {
|
|
21
|
+
if (disposed) return;
|
|
22
|
+
disposed = true;
|
|
23
|
+
unsubscribe();
|
|
24
|
+
linked.dispose();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a thread draws its turns as chat bubbles, as an agent's thread does.
|
|
5
|
+
*
|
|
6
|
+
* `false` is the thread's ordinary look, where the person's question is Bloom's own bubble and the
|
|
7
|
+
* replies are plain. `true`: the person's turn is a bubble in the theme's primary (which the app
|
|
8
|
+
* seeds with the agent's colour) and every reply is a neutral one.
|
|
9
|
+
*/
|
|
10
|
+
const BubblesContext = createContext(false);
|
|
11
|
+
|
|
12
|
+
export const BubblesProvider = BubblesContext.Provider;
|
|
13
|
+
|
|
14
|
+
export function useBubbles(): boolean {
|
|
15
|
+
return useContext(BubblesContext);
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the thread shows while a call is open: the text messages it held when
|
|
3
|
+
* the call started, then the call's messages.
|
|
4
|
+
*
|
|
5
|
+
* A call message the server has stored is shown AS STORED — the copy a reload
|
|
6
|
+
* or a resume shows, with its tools' arguments and results, which the call's
|
|
7
|
+
* socket never carries. Same id either way (the call names every message by the
|
|
8
|
+
* id it is stored under), so swapping one for the other never adds a message.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Message } from '../runtime/types';
|
|
12
|
+
import type { VoiceMessage } from '../types';
|
|
13
|
+
|
|
14
|
+
export function callThread(
|
|
15
|
+
before: readonly Message[],
|
|
16
|
+
call: readonly VoiceMessage[],
|
|
17
|
+
stored: readonly Message[] | undefined,
|
|
18
|
+
): Message[] {
|
|
19
|
+
const storedById = new Map((stored ?? []).map((message) => [message.id, message]));
|
|
20
|
+
return [...before, ...call.map((message) => storedById.get(message.id) ?? fromCall(message))];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fromCall(message: VoiceMessage): Message {
|
|
24
|
+
return {
|
|
25
|
+
id: message.id,
|
|
26
|
+
role: message.role,
|
|
27
|
+
content: message.content,
|
|
28
|
+
toolInvocations: message.toolInvocations,
|
|
29
|
+
createdAt: new Date(message.timestamp).toISOString(),
|
|
30
|
+
source: 'voice' as const,
|
|
31
|
+
speaker: message.speaker,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolInvocation } from '../runtime/types';
|
|
2
|
+
|
|
3
|
+
/** A canvas artifact as `CanvasComponent` draws it. */
|
|
4
|
+
export interface CanvasResult {
|
|
5
|
+
type: string;
|
|
6
|
+
title: string;
|
|
7
|
+
data: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A finished canvas call's artifact; `null` for any other call, one still running, or one the tool
|
|
12
|
+
* refused (`{ error }`). An artifact without a title is titled by its type.
|
|
13
|
+
*/
|
|
14
|
+
export function canvasResultOf(call: ToolInvocation): CanvasResult | null {
|
|
15
|
+
if (call.toolName !== 'canvas' || call.state !== 'result') return null;
|
|
16
|
+
const result: unknown = call.result;
|
|
17
|
+
if (result === null || typeof result !== 'object') return null;
|
|
18
|
+
const { type, title, data } = result as Record<string, unknown>;
|
|
19
|
+
if (typeof type !== 'string' || type === '' || data === undefined || data === null) return null;
|
|
20
|
+
return { type, title: typeof title === 'string' && title !== '' ? title : type, data };
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical name of an app's catalogue tool — `oxy_<app>__<tool>` for the person's
|
|
3
|
+
* account, `self_<app>__<tool>` for the agent's own — read back into its app and tool.
|
|
4
|
+
*
|
|
5
|
+
* Pure (no React, no React Native), so a host's own models and tests can tell which
|
|
6
|
+
* app a tool call belongs to: it is the `@gemies/sdk/tools` entry's, and the renderers
|
|
7
|
+
* (`tool-renderers.tsx`) key on it. The app part is an Oxy app slug; the tool part is
|
|
8
|
+
* whatever follows the separator. Nothing else names a renderer — never the model's text.
|
|
9
|
+
*/
|
|
10
|
+
const CANONICAL_TOOL = /^(?:oxy|self)_([a-z][a-z0-9-]{0,63})__([A-Za-z0-9_-]+)$/;
|
|
11
|
+
|
|
12
|
+
/** The app and tool of a canonical catalogue tool name, or `null` for any other name. */
|
|
13
|
+
export function parseCatalogueTool(toolName: string): { app: string; tool: string } | null {
|
|
14
|
+
const match = CANONICAL_TOOL.exec(toolName);
|
|
15
|
+
return match ? { app: match[1] ?? '', tool: match[2] ?? '' } : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The renderer key of a tool name (`<app>:<tool>`), or `null` when it is not a catalogue tool. */
|
|
19
|
+
export function toolRendererKey(toolName: string): string | null {
|
|
20
|
+
const parsed = parseCatalogueTool(toolName);
|
|
21
|
+
return parsed ? `${parsed.app}:${parsed.tool}` : null;
|
|
22
|
+
}
|