@guideai/react-native 0.9.0 → 0.10.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.
Files changed (49) hide show
  1. package/README.md +6 -3
  2. package/dist/{GuideAIChat-BFu10t6D.cjs → GuideAIChat-BtbkPIvE.cjs} +285 -26
  3. package/dist/GuideAIChat-BtbkPIvE.cjs.map +1 -0
  4. package/dist/{GuideAIChat-Ba6n1ePs.js → GuideAIChat-CKW6dgl_.js} +286 -27
  5. package/dist/GuideAIChat-CKW6dgl_.js.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.ts +58 -6
  8. package/dist/index.mjs +2 -2
  9. package/dist/ui.cjs +2 -2
  10. package/dist/ui.d.ts +13 -3
  11. package/dist/ui.mjs +3 -3
  12. package/dist/{useConversations-C-OmzdeA.js → useConversations-BljCr0Od.js} +1067 -43
  13. package/dist/useConversations-BljCr0Od.js.map +1 -0
  14. package/dist/{useConversations-Chn_GKOz.cjs → useConversations-UiwD_WVF.cjs} +1067 -43
  15. package/dist/useConversations-UiwD_WVF.cjs.map +1 -0
  16. package/dist/voice.cjs +61 -23
  17. package/dist/voice.cjs.map +1 -1
  18. package/dist/voice.d.ts +13 -3
  19. package/dist/voice.mjs +62 -24
  20. package/dist/voice.mjs.map +1 -1
  21. package/package.json +1 -1
  22. package/dist/GuideAIChat-BFu10t6D.cjs.map +0 -1
  23. package/dist/GuideAIChat-BQQ8lUKs.js +0 -2795
  24. package/dist/GuideAIChat-BQQ8lUKs.js.map +0 -1
  25. package/dist/GuideAIChat-Ba6n1ePs.js.map +0 -1
  26. package/dist/GuideAIChat-CNmEo5bZ.cjs +0 -2794
  27. package/dist/GuideAIChat-CNmEo5bZ.cjs.map +0 -1
  28. package/dist/GuideAIChat-CxyWFl_o.cjs +0 -2493
  29. package/dist/GuideAIChat-CxyWFl_o.cjs.map +0 -1
  30. package/dist/GuideAIChat-DOC4zx-a.js +0 -2494
  31. package/dist/GuideAIChat-DOC4zx-a.js.map +0 -1
  32. package/dist/GuideAIChat-SU0CVNby.js +0 -2795
  33. package/dist/GuideAIChat-SU0CVNby.js.map +0 -1
  34. package/dist/GuideAIChat-W8KQ4Y6i.cjs +0 -2794
  35. package/dist/GuideAIChat-W8KQ4Y6i.cjs.map +0 -1
  36. package/dist/useConversations-B_7km_uH.js +0 -4243
  37. package/dist/useConversations-B_7km_uH.js.map +0 -1
  38. package/dist/useConversations-C-OmzdeA.js.map +0 -1
  39. package/dist/useConversations-CJEaVqch.cjs +0 -4290
  40. package/dist/useConversations-CJEaVqch.cjs.map +0 -1
  41. package/dist/useConversations-CTbQBTz-.cjs +0 -4242
  42. package/dist/useConversations-CTbQBTz-.cjs.map +0 -1
  43. package/dist/useConversations-Chn_GKOz.cjs.map +0 -1
  44. package/dist/useConversations-Ckyqbxqi.cjs +0 -4299
  45. package/dist/useConversations-Ckyqbxqi.cjs.map +0 -1
  46. package/dist/useConversations-DzhYCIiY.js +0 -4300
  47. package/dist/useConversations-DzhYCIiY.js.map +0 -1
  48. package/dist/useConversations-SbhtYN_R.js +0 -4291
  49. package/dist/useConversations-SbhtYN_R.js.map +0 -1
package/dist/voice.d.ts CHANGED
@@ -32,6 +32,11 @@ interface GuideAIMessage {
32
32
  * `explainOnWhiteboard(id)`.
33
33
  */
34
34
  whiteboard?: boolean;
35
+ /**
36
+ * This answer can also be taught as a Full lesson (the Blueprint offers
37
+ * it). Draw a button that calls `explainOnWhiteboard(id, { lesson: true })`.
38
+ */
39
+ lesson?: boolean;
35
40
  /**
36
41
  * Pictures the agent drew. They are also in `content` as Markdown
37
42
  * images where they belong; use this list to place them yourself.
@@ -91,11 +96,16 @@ interface UseGuideAIResult {
91
96
  followUps: string[];
92
97
  /** The Blueprint has the whiteboard block. */
93
98
  whiteboardAvailable: boolean;
99
+ /** The Blueprint offers Full lessons beside the whiteboard. */
100
+ lessonsAvailable: boolean;
94
101
  /**
95
- * Explain an answer on the whiteboard, with the question it answered.
96
- * Mount `<GuideAIWhiteboard />` once to show the board.
102
+ * Explain an answer on the whiteboard, with the question it answered;
103
+ * `{ lesson: true }` for the Full lesson. Mount `<GuideAIWhiteboard />`
104
+ * once to show the board.
97
105
  */
98
- explainOnWhiteboard(messageId: string): Promise<boolean>;
106
+ explainOnWhiteboard(messageId: string, options?: {
107
+ lesson?: boolean;
108
+ }): Promise<boolean>;
99
109
  /**
100
110
  * The current input text, and its setter.
101
111
  *
package/dist/voice.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  import { useSyncExternalStore, useEffect, useCallback, useRef, useState } from "react";
2
2
  import { useAudioRecorder, RecordingPresets, setAudioModeAsync, requestRecordingPermissionsAsync, createAudioPlayer } from "expo-audio";
3
- import { r as requireConfigured, G as GuideAI, E as EP } from "./useConversations-C-OmzdeA.js";
3
+ import { r as requireConfigured, G as GuideAI, E as EP } from "./useConversations-BljCr0Od.js";
4
4
  import { File, Paths } from "expo-file-system";
5
5
  import { jsx } from "react/jsx-runtime";
6
- import { G as GuideAIChat } from "./GuideAIChat-SU0CVNby.js";
7
- import { D, a, b, c } from "./GuideAIChat-SU0CVNby.js";
6
+ import { G as GuideAIChat } from "./GuideAIChat-CKW6dgl_.js";
7
+ import { D, a, b, c } from "./GuideAIChat-CKW6dgl_.js";
8
8
  const CATALOG = {
9
9
  en: {
10
10
  label: "English",
11
11
  transcriptionLanguages: ["en"],
12
- transcriptionPrompt: "The selected language is English. Transcribe English exactly as spoken. Do not switch languages, translate, summarize, or answer.",
12
+ transcriptionPrompt: "A website visitor speaking English with the site's assistant.",
13
13
  speechInstructions: "Speak in English only."
14
14
  },
15
15
  // Nigerian Pidgin has no recognizer or voice of its own at our providers.
@@ -19,33 +19,33 @@ const CATALOG = {
19
19
  pcm: {
20
20
  label: "Nigerian Pidgin",
21
21
  transcriptionLanguages: ["en"],
22
- transcriptionPrompt: "The speaker talks Nigerian Pidgin English (Naija). Common words: wetin, abeg, dey, una, oya, wahala, sabi, abi, sef, don, na, dem, pikin, how far, no wahala, I no fit, make I, wey. Transcribe the Pidgin words exactly as spoken; do not convert them to standard English, translate, summarize, or answer.",
22
+ transcriptionPrompt: "A website visitor speaking Nigerian Pidgin English (Naija) with the site's assistant. Common words: wetin, abeg, dey, una, oya, wahala, sabi, abi, sef, don, na, dem, pikin, how far, no wahala, I no fit, make I, wey.",
23
23
  speechInstructions: "Speak in Nigerian Pidgin English with a warm Nigerian accent."
24
24
  },
25
25
  fr: {
26
26
  label: "French",
27
27
  transcriptionLanguages: ["fr"],
28
- transcriptionPrompt: "Transcribe French exactly as spoken. Do not translate, summarize, or answer."
28
+ transcriptionPrompt: "A website visitor speaking French with the site's assistant."
29
29
  },
30
30
  pt: {
31
31
  label: "Portuguese",
32
32
  transcriptionLanguages: ["pt"],
33
- transcriptionPrompt: "Transcribe Portuguese exactly as spoken. Do not translate, summarize, or answer."
33
+ transcriptionPrompt: "A website visitor speaking Portuguese with the site's assistant."
34
34
  },
35
35
  es: {
36
36
  label: "Spanish",
37
37
  transcriptionLanguages: ["es"],
38
- transcriptionPrompt: "Transcribe Spanish exactly as spoken. Do not translate, summarize, or answer."
38
+ transcriptionPrompt: "A website visitor speaking Spanish with the site's assistant."
39
39
  },
40
40
  ar: {
41
41
  label: "Arabic",
42
42
  transcriptionLanguages: ["ar"],
43
- transcriptionPrompt: "Transcribe Arabic exactly as spoken. Do not translate, summarize, or answer."
43
+ transcriptionPrompt: "A website visitor speaking Arabic with the site's assistant."
44
44
  },
45
45
  "zh-cn": {
46
46
  label: "Chinese (Mandarin)",
47
47
  transcriptionLanguages: ["zh-cn"],
48
- transcriptionPrompt: "Transcribe Mandarin Chinese exactly as spoken. Do not translate, summarize, or answer."
48
+ transcriptionPrompt: "A website visitor speaking Mandarin Chinese with the site's assistant."
49
49
  }
50
50
  };
51
51
  function normalizeVoiceLanguageCode(code) {
@@ -62,7 +62,7 @@ function resolveVoiceLanguage(code) {
62
62
  code: canonicalCode(normalized),
63
63
  label: displayLanguageName(normalized),
64
64
  transcriptionLanguages: [primary],
65
- transcriptionPrompt: `The speaker selected ${displayLanguageName(normalized)}. Transcribe exactly as spoken. Do not translate, summarize, or answer.`
65
+ transcriptionPrompt: `A website visitor speaking ${displayLanguageName(normalized)} with the site's assistant.`
66
66
  };
67
67
  }
68
68
  function isUnexpectedTranscriptScript(text, language) {
@@ -1395,6 +1395,11 @@ function isEchoOf(heard, spoken) {
1395
1395
  }
1396
1396
  return inOrder / last >= 0.5;
1397
1397
  }
1398
+ function isPromptEcho(heard, language) {
1399
+ const prompt = language == null ? void 0 : language.transcriptionPrompt;
1400
+ if (!prompt || normalizeUtterance(heard).length < 3) return false;
1401
+ return isEchoOf(heard, prompt);
1402
+ }
1398
1403
  function createFenceFilter() {
1399
1404
  let carry = "";
1400
1405
  let inFence = false;
@@ -1801,7 +1806,7 @@ class PipelineVoiceAgent {
1801
1806
  if (!this.greeting) this.player.cue();
1802
1807
  }
1803
1808
  async handleEvent(event) {
1804
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1809
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1805
1810
  if (SESSION_UPDATED_EVENTS.has(event.type) || SESSION_CREATED_EVENTS.has(event.type) && !this.awaitingSessionUpdate) {
1806
1811
  this.markReady();
1807
1812
  return;
@@ -1864,7 +1869,9 @@ class PipelineVoiceAgent {
1864
1869
  this.fillerDucked = false;
1865
1870
  this.player.duck(1);
1866
1871
  }
1867
- if (text && this.isOwnEcho(text)) {
1872
+ const promptEcho = !!text && isPromptEcho(text, this.options.language);
1873
+ if (promptEcho) this.telemetry.record("prompt_echo_ignored", 1, (_f = this.options.language) == null ? void 0 : _f.code);
1874
+ if (text && (promptEcho || this.isOwnEcho(text))) {
1868
1875
  if (this.pendingInterruption) {
1869
1876
  this.clearPendingInterruption();
1870
1877
  this.player.duck(1);
@@ -1876,7 +1883,7 @@ class PipelineVoiceAgent {
1876
1883
  return;
1877
1884
  }
1878
1885
  if (this.pendingInterruption) {
1879
- const answersQuestion2 = !!text && !!((_g = (_f = this.options.host).hasPendingConfirmation) == null ? void 0 : _g.call(_f)) && isConfirmationAnswer(text);
1886
+ const answersQuestion2 = !!text && !!((_h = (_g = this.options.host).hasPendingConfirmation) == null ? void 0 : _h.call(_g)) && isConfirmationAnswer(text);
1880
1887
  if (!text || isBackchannel(text) && !answersQuestion2) {
1881
1888
  this.clearPendingInterruption();
1882
1889
  this.player.duck(1);
@@ -1886,11 +1893,11 @@ class PipelineVoiceAgent {
1886
1893
  }
1887
1894
  this.confirmInterruption();
1888
1895
  }
1889
- const answersQuestion = this.lastAnswerAsked || !!((_i = (_h = this.options.host).hasPendingConfirmation) == null ? void 0 : _i.call(_h));
1896
+ const answersQuestion = this.lastAnswerAsked || !!((_j = (_i = this.options.host).hasPendingConfirmation) == null ? void 0 : _j.call(_i));
1890
1897
  if (!text || isFillerOnly(text, answersQuestion)) {
1891
1898
  if (text) this.telemetry.record("filler_ignored", 1);
1892
1899
  this.currentTurnId = null;
1893
- if ((_j = this.held) == null ? void 0 : _j.sendIfNothingFollows) {
1900
+ if ((_k = this.held) == null ? void 0 : _k.sendIfNothingFollows) {
1894
1901
  const held = this.held;
1895
1902
  this.clearHeld();
1896
1903
  await this.commitTurn(held.text, held.turnId);
@@ -1905,7 +1912,7 @@ class PipelineVoiceAgent {
1905
1912
  await this.takeTurn(text, null, answersQuestion);
1906
1913
  return;
1907
1914
  }
1908
- const turnId = (_l = (_k = this.held) == null ? void 0 : _k.turnId) != null ? _l : this.currentTurnId;
1915
+ const turnId = (_m = (_l = this.held) == null ? void 0 : _l.turnId) != null ? _m : this.currentTurnId;
1909
1916
  const said = this.held ? `${this.held.text} ${text}` : text;
1910
1917
  this.clearHeld();
1911
1918
  this.currentTurnId = null;
@@ -1913,8 +1920,8 @@ class PipelineVoiceAgent {
1913
1920
  return;
1914
1921
  }
1915
1922
  case "error": {
1916
- const message = ((_m = event.error) == null ? void 0 : _m.message) || "Realtime transcription failed.";
1917
- throw ((_n = event.error) == null ? void 0 : _n.type) === "provider" ? new VoiceProviderError(message) : new Error(message);
1923
+ const message = ((_n = event.error) == null ? void 0 : _n.message) || "Realtime transcription failed.";
1924
+ throw ((_o = event.error) == null ? void 0 : _o.type) === "provider" ? new VoiceProviderError(message) : new Error(message);
1918
1925
  }
1919
1926
  default:
1920
1927
  return;
@@ -2385,6 +2392,7 @@ class SonioxSttTransport {
2385
2392
  this.muted = false;
2386
2393
  this.finalText = "";
2387
2394
  this.utteranceId = null;
2395
+ this.finishWaiter = null;
2388
2396
  this.eventListeners = /* @__PURE__ */ new Set();
2389
2397
  this.stateListeners = /* @__PURE__ */ new Set();
2390
2398
  }
@@ -2440,13 +2448,36 @@ class SonioxSttTransport {
2440
2448
  this.reconnectAttempts += 1;
2441
2449
  await this.openSocket("reconnecting");
2442
2450
  }
2451
+ /**
2452
+ * Stop sending audio and wait for the words still provisional to be made
2453
+ * final: Soniox answers `finalize` with them, then `<fin>`. Dictation calls
2454
+ * this when the visitor taps to send, so their last words are not cut off.
2455
+ * Resolves at `<fin>` or after `timeoutMs`; the caller then disconnects.
2456
+ */
2457
+ finish(timeoutMs = 2e3) {
2458
+ this.muted = true;
2459
+ const socket = this.socket;
2460
+ if (!socket || !this.socketReady || socket.readyState !== WebSocket.OPEN) return Promise.resolve();
2461
+ return new Promise((resolve) => {
2462
+ const done = () => {
2463
+ clearTimeout(timer);
2464
+ if (this.finishWaiter === done) this.finishWaiter = null;
2465
+ resolve();
2466
+ };
2467
+ const timer = setTimeout(done, timeoutMs);
2468
+ this.finishWaiter = done;
2469
+ socket.send(JSON.stringify({ type: "finalize" }));
2470
+ this.lastSentAt = Date.now();
2471
+ });
2472
+ }
2443
2473
  disconnect() {
2444
- var _a;
2474
+ var _a, _b;
2445
2475
  this.userClosed = true;
2476
+ (_a = this.finishWaiter) == null ? void 0 : _a.call(this);
2446
2477
  this.setState("closing");
2447
2478
  if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
2448
2479
  this.reconnectTimer = null;
2449
- (_a = this.connectionAbort) == null ? void 0 : _a.abort();
2480
+ (_b = this.connectionAbort) == null ? void 0 : _b.abort();
2450
2481
  this.connectionAbort = null;
2451
2482
  this.cleanupAll();
2452
2483
  this.setState("closed");
@@ -2571,7 +2602,9 @@ class SonioxSttTransport {
2571
2602
  audio_format: "pcm_s16le",
2572
2603
  sample_rate: INPUT_SAMPLE_RATE,
2573
2604
  num_channels: 1,
2574
- ...this.languageHints.length ? { language_hints: this.languageHints } : {},
2605
+ // A hint alone only biases: on a phone mic, English speech came back
2606
+ // as other languages. Strict holds the visitor's chosen language.
2607
+ ...this.languageHints.length ? { language_hints: this.languageHints, language_hints_strict: true } : {},
2575
2608
  ...terms.length || this.contextText ? { context: { ...terms.length ? { terms } : {}, ...this.contextText ? { text: this.contextText } : {} } } : {},
2576
2609
  enable_endpoint_detection: true,
2577
2610
  endpoint_latency_adjustment_level: (_c = endpoint.latencyAdjustmentLevel) != null ? _c : 2,
@@ -2580,7 +2613,7 @@ class SonioxSttTransport {
2580
2613
  };
2581
2614
  }
2582
2615
  handleMessage(data) {
2583
- var _a, _b, _c;
2616
+ var _a, _b, _c, _d;
2584
2617
  let message;
2585
2618
  try {
2586
2619
  message = JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
@@ -2598,13 +2631,17 @@ class SonioxSttTransport {
2598
2631
  }
2599
2632
  let provisional = "";
2600
2633
  let endOfTurn = false;
2634
+ let finalized = false;
2601
2635
  for (const token of (_a = message.tokens) != null ? _a : []) {
2602
2636
  const text = (_b = token.text) != null ? _b : "";
2603
2637
  if (text === "<end>") {
2604
2638
  endOfTurn = true;
2605
2639
  continue;
2606
2640
  }
2607
- if (text === "<fin>") continue;
2641
+ if (text === "<fin>") {
2642
+ finalized = true;
2643
+ continue;
2644
+ }
2608
2645
  if (token.is_final) this.finalText += text;
2609
2646
  else provisional += text;
2610
2647
  }
@@ -2631,6 +2668,7 @@ class SonioxSttTransport {
2631
2668
  }
2632
2669
  this.resetUtterance();
2633
2670
  }
2671
+ if (finalized) (_d = this.finishWaiter) == null ? void 0 : _d.call(this);
2634
2672
  }
2635
2673
  resetUtterance() {
2636
2674
  this.finalText = "";