@alia.onl/sdk 7.0.0 → 7.2.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 CHANGED
@@ -1,5 +1,42 @@
1
1
  # @alia.onl/sdk
2
2
 
3
+ ## 7.1.1
4
+
5
+ ### A stream either answers or fails
6
+
7
+ Text chat now uses the linked Oxy client, so the session manager performs its
8
+ preflight refresh and its one supported 401 retry. The SDK no longer copies a
9
+ bearer token into a raw `fetch` call.
10
+
11
+ The response must be SSE and must satisfy the Alia/OpenAI stream contract: valid
12
+ UTF-8 and JSON, typed product events, a finish chunk, a visible assistant answer,
13
+ and terminal `[DONE]`. A malformed, truncated, empty or error stream is a failed
14
+ turn and receives the existing visible retry message instead of becoming an
15
+ empty successful assistant bubble.
16
+
17
+ Active text requests are cancelled when their component unmounts, when a sheet
18
+ starts closing, when the user stops the turn, or when another send supersedes
19
+ it. Parser failures cancel the response reader as well. The parser bounds total
20
+ bytes, buffered frame size and line count so a broken stream cannot grow memory
21
+ without limit.
22
+
23
+ The 7.1.0 sampled-audio behavior and the root/voice entry split are unchanged.
24
+
25
+ ## 7.1.0
26
+
27
+ ### The read-aloud field answers the audio
28
+
29
+ `useTTS` drove the ambient field from a four-keyframe loop keyed on "is it
30
+ playing?" — the same animation for every clip, and for silence. It now reads the
31
+ player's own samples through `setAudioSamplingEnabled`, and both sources of the
32
+ field, dictation and playback, share one curve: `levelFromDbfs` in
33
+ `src/lib/audio-level.ts`, the logarithmic -60 dBFS floor dictation already used.
34
+ A linear reading of the same audio puts a normal speaking voice near the bottom
35
+ of the range, which is why the two looked nothing alike.
36
+
37
+ Nothing in the public surface changed shape: the hook keeps its signature and
38
+ its return type. What changed is what the field does while a message plays.
39
+
3
40
  ## 7.0.0
4
41
 
5
42
  ### `AliaMark` is now `IdentityMark`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alia.onl/sdk",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "description": "Alia AI chat SDK — reusable chat UI, voice, and streaming components for Oxy apps",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -24,26 +24,28 @@
24
24
  },
25
25
  "scripts": {
26
26
  "typecheck": "tsc --noEmit",
27
+ "test": "vitest run",
27
28
  "check:entries": "node scripts/check-entry-isolation.mjs"
28
29
  },
29
30
  "dependencies": {
30
31
  "@radix-ui/react-dropdown-menu": "^2.1.20",
31
32
  "@radix-ui/react-icons": "^1.3.2",
32
33
  "@tanstack/query-async-storage-persister": "^5.101.2",
33
- "@tanstack/react-query": "^5.101.2",
34
- "@tanstack/react-query-persist-client": "^5.101.2",
34
+ "@tanstack/react-query": "^5.102.8",
35
+ "@tanstack/react-query-persist-client": "^5.102.8",
35
36
  "class-variance-authority": "^0.7.1",
36
37
  "clsx": "^2.1.1",
37
38
  "lucide-react-native": "^1.24.0",
38
39
  "react-native-markdown-display": "^7.0.2",
39
40
  "tailwind-merge": "^3.6.0",
40
41
  "zeego": "^3.0.6",
41
- "zustand": "^5.0.14"
42
+ "zustand": "^5.0.15"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "react": "^19.2.3",
45
46
  "react-native": "^0.86.0",
46
- "@oxyhq/services": "^30.1.0",
47
+ "@oxyhq/core": "23.3.0",
48
+ "@oxyhq/services": "31.0.0",
47
49
  "@react-native-async-storage/async-storage": "^2.2.0",
48
50
  "socket.io-client": "^4.8.3",
49
51
  "expo-font": "^57.0.0",
@@ -71,6 +73,9 @@
71
73
  }
72
74
  },
73
75
  "devDependencies": {
74
- "typescript": "^5.9.3"
76
+ "@types/react-test-renderer": "^19.1.0",
77
+ "react-test-renderer": "19.2.3",
78
+ "typescript": "^5.9.3",
79
+ "vitest": "^4.1.10"
75
80
  }
76
81
  }
@@ -73,6 +73,8 @@ export interface AliaChatContentProps {
73
73
  * from this module. May be a `React.lazy` component.
74
74
  */
75
75
  voiceSession?: VoiceSessionComponent;
76
+ /** Internal sheet lifecycle bridge: receives the live request canceller. */
77
+ onStopReady?: (stop: (() => void) | null) => void;
76
78
  }
77
79
 
78
80
  /** Adapt a voice message into the chat message format. */
@@ -110,11 +112,17 @@ export function AliaChatContent({
110
112
  primaryColor,
111
113
  isDarkMode,
112
114
  voiceSession: VoiceSession,
115
+ onStopReady,
113
116
  }: AliaChatContentProps) {
114
117
  // ── Chat ──
115
118
  const chatOptions: UseAliaChatOptions = { apiUrl, model, clientContext };
116
119
  const { messages, setMessages, send, isStreaming, stop, clear } = useAliaChat(chatOptions);
117
120
 
121
+ useEffect(() => {
122
+ onStopReady?.(stop);
123
+ return () => onStopReady?.(null);
124
+ }, [onStopReady, stop]);
125
+
118
126
  // ── Input state ──
119
127
  const [inputValue, setInputValue] = useState('');
120
128
 
@@ -28,7 +28,7 @@ import type { VoiceSessionComponent } from '../types';
28
28
  export interface AliaChatScreenProps {
29
29
  /** App context injected into system prompt */
30
30
  clientContext?: string;
31
- /** Alia model. Checked against `GET /catalogue`; omitted, the build's preference is used. */
31
+ /** Kaana routing profile. Checked against `GET /catalogue`; omitted, the build's preference is used. */
32
32
  model?: string;
33
33
  /** API URL override */
34
34
  apiUrl?: string;
@@ -81,7 +81,7 @@ export function AliaChatScreen({
81
81
  <View className="flex-row items-center justify-between px-4 py-3">
82
82
  <View className="flex-row items-center gap-2.5">
83
83
  {headerLeft}
84
- <IdentityMark size={28} state={markState} />
84
+ <IdentityMark size={28} state={markState} spinOnPress />
85
85
  <Text className="text-lg font-semibold text-foreground">Alia</Text>
86
86
  </View>
87
87
  <View className="flex-row items-center gap-2">
@@ -45,7 +45,7 @@ const SPRING_CONFIG = {
45
45
  export interface AliaChatSheetProps {
46
46
  /** App context injected into system prompt */
47
47
  clientContext?: string;
48
- /** Alia model. Checked against `GET /catalogue`; omitted, the build's preference is used. */
48
+ /** Kaana routing profile. Checked against `GET /catalogue`; omitted, the build's preference is used. */
49
49
  model?: string;
50
50
  /** API URL override */
51
51
  apiUrl?: string;
@@ -82,6 +82,7 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
82
82
  const [rendered, setRendered] = useState(false);
83
83
  const hasClosedRef = useRef(false);
84
84
  const closeTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
85
+ const chatStopRef = useRef<(() => void) | null>(null);
85
86
 
86
87
  // Reanimated shared values
87
88
  const translateY = useSharedValue(SCREEN_HEIGHT);
@@ -112,6 +113,14 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
112
113
  setRendered(false);
113
114
  }, []);
114
115
 
116
+ const stopChat = useCallback(() => {
117
+ chatStopRef.current?.();
118
+ }, []);
119
+
120
+ const registerChatStop = useCallback((stop: (() => void) | null) => {
121
+ chatStopRef.current = stop;
122
+ }, []);
123
+
115
124
  const handlePresent = useCallback(() => {
116
125
  hasClosedRef.current = false;
117
126
  if (closeTimeoutRef.current) {
@@ -124,6 +133,7 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
124
133
  }, []);
125
134
 
126
135
  const handleDismiss = useCallback(() => {
136
+ stopChat();
127
137
  backdropOpacity.value = withTiming(0, { duration: 250 }, (finished) => {
128
138
  if (finished) runOnJS(finishDismiss)();
129
139
  });
@@ -136,7 +146,7 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
136
146
  finishDismiss();
137
147
  closeTimeoutRef.current = null;
138
148
  }, 350);
139
- }, [finishDismiss]);
149
+ }, [finishDismiss, stopChat]);
140
150
 
141
151
  useEffect(
142
152
  () => () => {
@@ -181,6 +191,7 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
181
191
  velocity > 900 || (distance > closeThreshold && velocity > -300);
182
192
 
183
193
  if (shouldClose) {
194
+ runOnJS(stopChat)();
184
195
  translateY.value = withSpring(SCREEN_HEIGHT, {
185
196
  ...SPRING_CONFIG,
186
197
  velocity,
@@ -191,7 +202,7 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
191
202
  } else {
192
203
  translateY.value = withSpring(0, { ...SPRING_CONFIG, velocity });
193
204
  }
194
- }), [nativeGesture, finishDismiss]);
205
+ }), [nativeGesture, finishDismiss, stopChat]);
195
206
 
196
207
  // Animated styles
197
208
  const backdropAnimStyle = useAnimatedStyle(() => ({
@@ -258,10 +269,11 @@ export const AliaChatSheet = forwardRef<AliaChatSheetRef, AliaChatSheetProps>(
258
269
  primaryColor={primaryColor}
259
270
  isDarkMode={isDarkMode ?? isDark}
260
271
  voiceSession={voiceSession}
272
+ onStopReady={registerChatStop}
261
273
  header={({ markState, hasMessages, clear }) => (
262
274
  <View style={styles.header}>
263
275
  <View style={styles.headerLeft}>
264
- <IdentityMark size={28} state={markState} />
276
+ <IdentityMark size={28} state={markState} spinOnPress />
265
277
  <Text className="text-lg font-semibold text-foreground">
266
278
  Alia
267
279
  </Text>
@@ -28,7 +28,7 @@ export function AliaWelcomeMessage({
28
28
  {/* Mark + Title */}
29
29
  <View className="items-start mb-8">
30
30
  <View className="mb-4">
31
- <IdentityMark size={markSize} />
31
+ <IdentityMark size={markSize} spinOnPress />
32
32
  </View>
33
33
  <View className="space-y-2">
34
34
  <Text className="text-3xl font-bold tracking-tight text-foreground">
@@ -23,19 +23,39 @@ export interface IdentityMarkProps {
23
23
  /** Layout classes for the outer box (color comes from `color`, not classes). */
24
24
  className?: string;
25
25
  /**
26
- * Who the mark stands for, as a colour. Defaults to the Alia brand purple —
27
- * never a theme token. An agent passes its own colour and gets the same
28
- * artwork at the same size, which is the whole of the difference between
29
- * Alia's mark and an agent's.
26
+ * Who the mark stands for, as a colour. An agent passes its own colour and
27
+ * gets the same artwork at the same size, which is the whole of the
28
+ * difference between Alia's mark and an agent's.
29
+ *
30
+ * The default is the Alia brand purple, and that is what an agent-less
31
+ * surface gets when it passes nothing. But do not read the default as a rule:
32
+ * three of Alia's own surfaces — the sidebar logo, the chat's mark and the
33
+ * welcome message — deliberately pass `colors.primary`, so Alia's face
34
+ * follows the account's accent there and stays brand purple elsewhere
35
+ * (`welcome-intro.tsx`). That split predates this component and is not
36
+ * settled; it is written down here so the next reader picks a side knowingly
37
+ * rather than copying whichever neighbour they happened to open.
30
38
  */
31
39
  color?: string;
32
40
  /**
33
- * Called after the press flourish, and the ONLY thing that makes the mark a
34
- * button. Left off, the mark is drawn inert: no press target, so it can sit
35
- * inside a row that is itself pressable — a sidebar entry, a card — without
36
- * swallowing the tap meant for the row.
41
+ * Called after the press flourish, for a mark that is a control — the sidebar
42
+ * logo, which goes home.
37
43
  */
38
44
  onPress?: () => void;
45
+ /**
46
+ * Take the tap for the flourish alone: spin, haptic, nothing else.
47
+ *
48
+ * For a mark that IS Alia standing on its own — the welcome greeting, a chat
49
+ * header — where the spin has always been the whole of what a tap does. There
50
+ * is no callback to give it, and `onPress={() => {}}` would be a lie about
51
+ * that, so this is how such a mark asks to be pressable.
52
+ *
53
+ * Sibling of `spinOnMount`, and off by default like it. Off is what lets the
54
+ * mark sit inside a row that is itself pressable — a sidebar agent entry, a
55
+ * card — without swallowing the tap meant for the row, which is the whole
56
+ * reason the press target is opt-in.
57
+ */
58
+ spinOnPress?: boolean;
39
59
  /**
40
60
  * Accessible name. A mark standing in for whoever is speaking is not
41
61
  * decoration, so it says who; Alia's own, drawn beside her name, is.
@@ -77,6 +97,7 @@ export function IdentityMark({
77
97
  className,
78
98
  color,
79
99
  onPress,
100
+ spinOnPress = false,
80
101
  accessibilityLabel,
81
102
  spinOnMount = false,
82
103
  }: IdentityMarkProps) {
@@ -157,9 +178,11 @@ export function IdentityMark({
157
178
  );
158
179
 
159
180
  // A `Pressable` captures the touch whether or not the caller wanted one, so
160
- // the inert mark is a plain view. Wrapping it in a pressable that only spins
161
- // is what would stop a sidebar row from opening when you tap the face on it.
162
- if (onPress === undefined) {
181
+ // the inert mark is a plain view — a mark drawn as somebody's face inside a
182
+ // row that is itself pressable must not stop that row from opening. Asking for
183
+ // the touch is therefore explicit, and either prop asks: a callback to run, or
184
+ // the flourish for its own sake.
185
+ if (onPress === undefined && !spinOnPress) {
163
186
  return (
164
187
  <View
165
188
  accessibilityRole="image"
@@ -175,7 +198,10 @@ export function IdentityMark({
175
198
  return (
176
199
  <Pressable
177
200
  onPress={handlePress}
178
- accessibilityRole="button"
201
+ // Pressable, but a button only when the press DOES something beyond the
202
+ // flourish. A screen reader announcing the welcome greeting's mark as a
203
+ // button would promise an action it does not have.
204
+ accessibilityRole={onPress === undefined ? 'image' : 'button'}
179
205
  accessibilityLabel={accessibilityLabel}
180
206
  className={className}
181
207
  style={box}