@guideai/react-native 0.2.0 → 0.3.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/dist/index.cjs +114 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +194 -4
- package/dist/index.mjs +113 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{useOnboarding-DWkCW5v0.cjs → setup-Bl0ZLz8B.cjs} +16 -288
- package/dist/setup-Bl0ZLz8B.cjs.map +1 -0
- package/dist/{useOnboarding-DAEGoYSs.js → setup-CkXajERE.js} +17 -289
- package/dist/setup-CkXajERE.js.map +1 -0
- package/dist/ui.cjs +1293 -34
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.ts +7 -2
- package/dist/ui.mjs +1287 -28
- package/dist/ui.mjs.map +1 -1
- package/dist/useOnboarding-BAKQq8T_.js +677 -0
- package/dist/useOnboarding-BAKQq8T_.js.map +1 -0
- package/dist/useOnboarding-CFxofFst.cjs +676 -0
- package/dist/useOnboarding-CFxofFst.cjs.map +1 -0
- package/dist/voice.cjs +89 -0
- package/dist/voice.cjs.map +1 -0
- package/dist/voice.d.ts +161 -0
- package/dist/voice.mjs +89 -0
- package/dist/voice.mjs.map +1 -0
- package/package.json +17 -3
- package/dist/useOnboarding-DAEGoYSs.js.map +0 -1
- package/dist/useOnboarding-DWkCW5v0.cjs.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/react/GuideAIScreen.tsx","../src/react/useGuideAIElement.ts"],"sourcesContent":["// ============================================================\n// @guideai/react-native — screen declaration\n// ============================================================\n//\n// Wraps a screen once. Everything inside can then register itself with\n// useGuideAIElement() from any depth.\n//\n// Two identities per screen, and they are not interchangeable:\n//\n// path — \"/share\" what the mobile scanner emitted. Grounding on\n// the backend is EXACT STRING EQUALITY against\n// this, so a mismatch silently loses all\n// route-level knowledge for the screen.\n// name — \"ShareForm\" the React Navigation screen name, which is what\n// navigate() takes.\n//\n// Mixing them up produces no error — just an assistant that stops\n// knowing anything about the screen. Hence both are required.\n// ============================================================\n\nimport React, { useEffect, useMemo } from 'react';\nimport { RegistryContext, useGuideAIRuntime } from './context';\nimport { ScreenRegistry } from '../screen/screen-registry';\n\nexport interface GuideAIScreenProps {\n /** React Navigation screen name, e.g. \"ShareForm\". Used by navigate(). */\n name: string;\n /** Scanner route path, e.g. \"/share\". Used for grounding. */\n path: string;\n /** Human title shown to the model. Defaults to `name`. */\n title?: string;\n /**\n * Whether this screen is the one currently on top.\n *\n * Defaults to true. React Navigation keeps previous screens MOUNTED in\n * the stack, so without this a backgrounded screen would keep claiming\n * to be active and the model would be told about controls the user\n * cannot see. Hosts using React Navigation should pass\n * `useIsFocused()`.\n */\n active?: boolean;\n children: React.ReactNode;\n}\n\nexport function GuideAIScreen({\n name, path, title, active = true, children,\n}: GuideAIScreenProps): React.ReactElement {\n const runtime = useGuideAIRuntime();\n\n // One registry per mounted screen. Recreated only if the identity\n // changes, so elements registered by children survive re-renders.\n const registry = useMemo(() => new ScreenRegistry(), [name, path]);\n\n useEffect(() => {\n if (!active) return;\n\n runtime.setActiveScreen({ path, title: title ?? name, registry });\n\n return () => {\n // Only stand down if still the active screen. During a transition\n // the next screen's effect may run before this one's cleanup, and\n // clearing then would blank a screen that just became active.\n if (runtime.getActiveScreen()?.registry === registry) {\n runtime.setActiveScreen(undefined);\n }\n };\n }, [runtime, registry, path, title, name, active]);\n\n return (\n <RegistryContext.Provider value={registry}>\n {children}\n </RegistryContext.Provider>\n );\n}\n","// ============================================================\n// @guideai/react-native — element declaration hook\n// ============================================================\n//\n// The manual path: a component declares itself so the assistant can see\n// and act on it.\n//\n// KNOWN LIMIT, stated rather than hidden: this is per-element work. On a\n// screen with 200 controls that is 200 calls, and an element nobody\n// declares is INVISIBLE to the assistant — it does not degrade, it is\n// simply not there, with no warning and no failing test. Automatic\n// harvesting (instrumented components, accessibility props, static\n// extraction) is the intended answer and is being explored separately.\n// Until then this is the escape hatch, and it is honest about being one.\n// ============================================================\n\nimport { useEffect, useRef } from 'react';\nimport { useScreenRegistry } from './context';\nimport type { DeclaredElement, ElementHandlers } from '../screen/screen-registry';\n\nexport type UseGuideAIElementOptions =\n Omit<DeclaredElement, 'id'> & ElementHandlers;\n\n/**\n * Declare one element to the assistant.\n *\n * Registration is an effect, so it runs after mount and unwinds on\n * unmount. Handlers are kept in a ref and read through a stable wrapper:\n * without that, an inline `press={() => …}` would be a new function on\n * every render and re-register the element on every render with it.\n */\nexport function useGuideAIElement(\n id: string,\n options: UseGuideAIElementOptions,\n): void {\n const registry = useScreenRegistry();\n\n // Latest handlers, without making them a dependency of registration.\n const handlers = useRef<ElementHandlers>({});\n handlers.current = {\n press: options.press,\n setValue: options.setValue,\n scrollTo: options.scrollTo,\n };\n\n const {\n label, kind, value, accessibilityLabel, placeholder, hidden, sectionTitle,\n } = options;\n\n // WHICH capabilities exist must be part of registration, not just their\n // implementations. Always installing a wrapper would make every element\n // report itself as pressable, so `element_not_pressable` could never\n // fire and the model would be told a static label is a button.\n const canPress = Boolean(options.press);\n const canSetValue = Boolean(options.setValue);\n const canScrollTo = Boolean(options.scrollTo);\n\n useEffect(() => {\n if (!registry) return;\n\n // Stable indirection: the registry holds these for the element's\n // lifetime, and they read whatever the latest render supplied — so an\n // inline arrow function does not re-register on every render.\n const bound: ElementHandlers = {};\n if (canPress) bound.press = () => handlers.current.press?.();\n if (canSetValue) bound.setValue = (next: string) => handlers.current.setValue?.(next);\n if (canScrollTo) bound.scrollTo = () => handlers.current.scrollTo?.();\n\n return registry.register(\n { id, label, kind, value, accessibilityLabel, placeholder, hidden, sectionTitle },\n bound,\n );\n }, [\n registry, id, label, kind, value,\n accessibilityLabel, placeholder, hidden, sectionTitle,\n canPress, canSetValue, canScrollTo,\n ]);\n}\n"],"names":[],"mappings":";;;;AA4CO,SAAS,cAAc;AAAA,EAC5B;AAAA,EAAM;AAAA,EAAM;AAAA,EA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,IAAI,OAAO,MAAM,OAAO,oBAAoB,aAAa,QAAQ,aAAA;AAAA,MACnE;AAAA,IAAA;AAAA,EAEJ,GAAG;AAAA,IACD;AAAA,IAAU;AAAA,IAAI;AAAA,IAAO;AAAA,IAAM;AAAA,IAC3B;AAAA,IAAoB;AAAA,IAAa;AAAA,IAAQ;AAAA,IACzC;AAAA,IAAU;AAAA,IAAa;AAAA,EAAA,CACxB;AACH;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/react/GuideAIScreen.tsx","../src/react/useGuideAIElement.ts","../../sdk/src/whiteboard/layouts.ts","../src/whiteboard/layouts.ts"],"sourcesContent":["// ============================================================\n// @guideai/react-native — screen declaration\n// ============================================================\n//\n// Wraps a screen once. Everything inside can then register itself with\n// useGuideAIElement() from any depth.\n//\n// Two identities per screen, and they are not interchangeable:\n//\n// path — \"/share\" what the mobile scanner emitted. Grounding on\n// the backend is EXACT STRING EQUALITY against\n// this, so a mismatch silently loses all\n// route-level knowledge for the screen.\n// name — \"ShareForm\" the React Navigation screen name, which is what\n// navigate() takes.\n//\n// Mixing them up produces no error — just an assistant that stops\n// knowing anything about the screen. Hence both are required.\n// ============================================================\n\nimport React, { useEffect, useMemo } from 'react';\nimport { RegistryContext, useGuideAIRuntime } from './context';\nimport { ScreenRegistry } from '../screen/screen-registry';\n\nexport interface GuideAIScreenProps {\n /** React Navigation screen name, e.g. \"ShareForm\". Used by navigate(). */\n name: string;\n /** Scanner route path, e.g. \"/share\". Used for grounding. */\n path: string;\n /** Human title shown to the model. Defaults to `name`. */\n title?: string;\n /**\n * Whether this screen is the one currently on top.\n *\n * Defaults to true. React Navigation keeps previous screens MOUNTED in\n * the stack, so without this a backgrounded screen would keep claiming\n * to be active and the model would be told about controls the user\n * cannot see. Hosts using React Navigation should pass\n * `useIsFocused()`.\n */\n active?: boolean;\n children: React.ReactNode;\n}\n\nexport function GuideAIScreen({\n name, path, title, active = true, children,\n}: GuideAIScreenProps): React.ReactElement {\n const runtime = useGuideAIRuntime();\n\n // One registry per mounted screen. Recreated only if the identity\n // changes, so elements registered by children survive re-renders.\n const registry = useMemo(() => new ScreenRegistry(), [name, path]);\n\n useEffect(() => {\n if (!active) return;\n\n runtime.setActiveScreen({ path, title: title ?? name, registry });\n\n return () => {\n // Only stand down if still the active screen. During a transition\n // the next screen's effect may run before this one's cleanup, and\n // clearing then would blank a screen that just became active.\n if (runtime.getActiveScreen()?.registry === registry) {\n runtime.setActiveScreen(undefined);\n }\n };\n }, [runtime, registry, path, title, name, active]);\n\n return (\n <RegistryContext.Provider value={registry}>\n {children}\n </RegistryContext.Provider>\n );\n}\n","// ============================================================\n// @guideai/react-native — element declaration hook\n// ============================================================\n//\n// The manual path: a component declares itself so the assistant can see\n// and act on it.\n//\n// KNOWN LIMIT, stated rather than hidden: this is per-element work. On a\n// screen with 200 controls that is 200 calls, and an element nobody\n// declares is INVISIBLE to the assistant — it does not degrade, it is\n// simply not there, with no warning and no failing test. Automatic\n// harvesting (instrumented components, accessibility props, static\n// extraction) is the intended answer and is being explored separately.\n// Until then this is the escape hatch, and it is honest about being one.\n// ============================================================\n\nimport { useEffect, useRef } from 'react';\nimport { useScreenRegistry } from './context';\nimport type { DeclaredElement, ElementHandlers } from '../screen/screen-registry';\n\nexport type UseGuideAIElementOptions =\n Omit<DeclaredElement, 'id'> & ElementHandlers;\n\n/**\n * Declare one element to the assistant.\n *\n * Registration is an effect, so it runs after mount and unwinds on\n * unmount. Handlers are kept in a ref and read through a stable wrapper:\n * without that, an inline `press={() => …}` would be a new function on\n * every render and re-register the element on every render with it.\n */\nexport function useGuideAIElement(\n id: string,\n options: UseGuideAIElementOptions,\n): void {\n const registry = useScreenRegistry();\n\n // Latest handlers, without making them a dependency of registration.\n const handlers = useRef<ElementHandlers>({});\n handlers.current = {\n press: options.press,\n setValue: options.setValue,\n scrollTo: options.scrollTo,\n };\n\n const {\n label, kind, value, accessibilityLabel, placeholder, hidden, sectionTitle,\n } = options;\n\n // WHICH capabilities exist must be part of registration, not just their\n // implementations. Always installing a wrapper would make every element\n // report itself as pressable, so `element_not_pressable` could never\n // fire and the model would be told a static label is a button.\n const canPress = Boolean(options.press);\n const canSetValue = Boolean(options.setValue);\n const canScrollTo = Boolean(options.scrollTo);\n\n useEffect(() => {\n if (!registry) return;\n\n // Stable indirection: the registry holds these for the element's\n // lifetime, and they read whatever the latest render supplied — so an\n // inline arrow function does not re-register on every render.\n const bound: ElementHandlers = {};\n if (canPress) bound.press = () => handlers.current.press?.();\n if (canSetValue) bound.setValue = (next: string) => handlers.current.setValue?.(next);\n if (canScrollTo) bound.scrollTo = () => handlers.current.scrollTo?.();\n\n return registry.register(\n { id, label, kind, value, accessibilityLabel, placeholder, hidden, sectionTitle },\n bound,\n );\n }, [\n registry, id, label, kind, value,\n accessibilityLabel, placeholder, hidden, sectionTitle,\n canPress, canSetValue, canScrollTo,\n ]);\n}\n","// ============================================================\n// @guideai/sdk — Whiteboard layouts: boards from the host's own data\n// ============================================================\n//\n// For figures that must be right — what a payment costs, what a customer\n// receives — the host builds the board from its own data and plays it\n// (`GuideAI.whiteboard.play(GuideAI.whiteboard.layouts.feeBreakdown(...))`).\n// No model sees the numbers and none writes them: the sums are done here,\n// in minor units, so the board can only show what the host's data says.\n\nimport type { BoardItem, BoardScene, BoardStep } from './scene';\nimport { LIMITS } from './scene';\n\nexport interface Money {\n /** ISO 4217 code (\"GBP\") or a symbol (\"£\"). */\n currency: string;\n /** Formatting locale; the browser's by default. */\n locale?: string;\n}\n\nexport interface FeeBreakdownInput extends Money {\n /** What the customer pays. */\n amount: number;\n /** Each deduction, in the order it is taken. */\n fees: { label: string; amount: number }[];\n title?: string;\n /** Example figures: the board is labelled as an example. */\n sample?: boolean;\n}\n\nconst cut = (text: string, max: number = LIMITS.text): string => text.replace(/\\s+/g, ' ').trim().slice(0, max);\n\nfunction minor(value: number, what: string): number {\n if (!Number.isFinite(value) || value < 0) throw new RangeError(`${what} must be a number of zero or more.`);\n return Math.round(value * 100);\n}\n\nexport function formatMoney(minorUnits: number, money: Money): string {\n const value = minorUnits / 100;\n if (/^[A-Z]{3}$/.test(money.currency)) {\n try {\n return new Intl.NumberFormat(money.locale, { style: 'currency', currency: money.currency }).format(value);\n } catch {\n // An unknown code falls through to the plain form.\n }\n }\n return `${money.currency}${value.toFixed(2)}`;\n}\n\n/** Amount paid → each fee taken → what is received, with the table to check it. */\nexport function feeBreakdown(input: FeeBreakdownInput): BoardScene {\n const paid = minor(input.amount, 'The amount');\n const fees = input.fees.slice(0, 4).map((fee, i) => ({ label: cut(fee.label || `Fee ${i + 1}`, 18), minor: minor(fee.amount, fee.label || 'A fee') }));\n const taken = fees.reduce((sum, fee) => sum + fee.minor, 0);\n if (taken > paid) throw new RangeError('The fees are more than the amount paid.');\n const received = paid - taken;\n const money = (m: number) => formatMoney(m, input);\n\n const feeItems: BoardItem[] = fees.flatMap((fee, i): BoardItem[] => [\n { kind: 'text', id: `fee${i}`, text: cut(`${fee.label} −${money(fee.minor)}`), at: [58, 18 + i * 9], size: 's', tone: 'red' },\n ]);\n const steps: BoardStep[] = [\n {\n say: `The customer pays ${money(paid)}.`,\n clear: false,\n draw: [\n { kind: 'art', id: 'payer', art: 'user', at: [4, 10, 12, 20], tone: 'ink' },\n { kind: 'text', id: 'paid', text: money(paid), at: [19, 20], size: 'l', tone: 'ink' },\n { kind: 'ink', ink: 'box', at: [17, 13, 26, 14], tone: 'ink' },\n ],\n },\n {\n say: fees.length === 1\n ? `${fees[0].label} of ${money(fees[0].minor)} is taken out.`\n : `${fees.length} fees are taken out: ${fees.map((f) => `${f.label}, ${money(f.minor)}`).join('; ')}.`,\n clear: false,\n draw: [{ kind: 'ink', ink: 'arrow', at: [44, 20], to: [56, 20], tone: 'red' }, ...feeItems],\n },\n {\n say: `So ${money(received)} is received.`,\n clear: false,\n draw: [\n { kind: 'ink', ink: 'arrow', at: [30, 29], to: [30, 45], tone: 'ink' },\n { kind: 'text', id: 'received', text: money(received), at: [19, 52], size: 'l', tone: 'green' },\n { kind: 'ink', ink: 'circle', at: [17, 46, 27, 12], tone: 'green' },\n ],\n },\n {\n say: 'Here it is all together.',\n clear: false,\n draw: [\n {\n kind: 'table',\n id: 'sum',\n rows: [\n ['Paid', money(paid)],\n ...fees.map((fee) => [fee.label, `−${money(fee.minor)}`]),\n ['Received', money(received)],\n ].map((row) => row.map((cell) => cut(cell, LIMITS.cell))),\n at: [56, 56, 38],\n tone: 'ink',\n },\n { kind: 'mark', mark: 'received' },\n ],\n },\n ];\n return { title: cut(input.title || 'Where the money goes', LIMITS.title), sample: input.sample === true, steps, art: { user: { icon: 'user' } } };\n}\n\n/** A few stages in a row, each boxed and joined to the next by an arrow. */\nexport function processFlow(input: { title: string; steps: { label: string; say?: string }[]; sample?: boolean }): BoardScene {\n const stages = input.steps.slice(0, 5);\n if (stages.length < 2) throw new RangeError('A process needs at least two steps.');\n const gap = 4;\n const width = (92 - gap * (stages.length - 1)) / stages.length;\n const steps: BoardStep[] = stages.map((stage, i) => {\n const x = 4 + i * (width + gap);\n const draw: BoardItem[] = [\n { kind: 'ink', ink: 'box', at: [x, 40, width, 18], tone: 'ink' },\n { kind: 'text', id: `s${i}`, text: cut(stage.label, 16), at: [x + 1.5, 49], size: width < 18 ? 's' : 'm', tone: 'ink' },\n ];\n if (i > 0) draw.unshift({ kind: 'ink', ink: 'arrow', at: [x - gap + 0.5, 49], to: [x - 0.5, 49], tone: 'blue' });\n return { say: cut(stage.say || stage.label, LIMITS.say), clear: false, draw };\n });\n return { title: cut(input.title, LIMITS.title), sample: input.sample === true, steps, art: {} };\n}\n\n/** Two options side by side, the points of each under its name. */\nexport function comparison(input: {\n title: string;\n left: { name: string; points: string[] };\n right: { name: string; points: string[] };\n summary?: string;\n sample?: boolean;\n}): BoardScene {\n const column = (side: { name: string; points: string[] }, x: number, key: string): BoardStep => ({\n say: cut(`${side.name}: ${side.points.slice(0, 4).join(', ')}.`, LIMITS.say),\n clear: false,\n draw: [\n { kind: 'text', id: `${key}h`, text: cut(side.name, 24), at: [x, 14], size: 'l', tone: 'blue' },\n { kind: 'ink', ink: 'underline', at: [x, 9, 36, 9], tone: 'blue' },\n ...side.points.slice(0, 4).map((point, i): BoardItem => ({ kind: 'text', text: cut(`• ${point}`, 34), at: [x, 32 + i * 12], size: 's', tone: 'ink' })),\n ],\n });\n const steps: BoardStep[] = [\n { say: cut(input.title, LIMITS.say), clear: false, draw: [{ kind: 'ink', ink: 'line', at: [50, 8], to: [50, 88], tone: 'ink' }] },\n column(input.left, 6, 'l'),\n column(input.right, 56, 'r'),\n ];\n if (input.summary) steps.push({ say: cut(input.summary, LIMITS.say), clear: false, draw: [] });\n return { title: cut(input.title, LIMITS.title), sample: input.sample === true, steps, art: {} };\n}\n","// Boards an app builds from its own data and plays with useWhiteboard().play:\n// the sums are done here, in minor units, and no model sees the figures.\nimport { comparison, feeBreakdown, formatMoney, processFlow } from '@guideai/whiteboard/layouts';\n\nexport const whiteboardLayouts = { feeBreakdown, processFlow, comparison, formatMoney };\n"],"names":[],"mappings":";;;;;;AA4CO,SAAS,cAAc;AAAA,EAC5B;AAAA,EAAM;AAAA,EAAM;AAAA,EAAO,SAAS;AAAA,EAAM;AACpC,GAA2C;AACzC,QAAM,UAAU,kBAAA;AAIhB,QAAM,WAAW,QAAQ,MAAM,IAAI,kBAAkB,CAAC,MAAM,IAAI,CAAC;AAEjE,YAAU,MAAM;AACd,QAAI,CAAC,OAAQ;AAEb,YAAQ,gBAAgB,EAAE,MAAM,OAAO,wBAAS,MAAM,UAAU;AAEhE,WAAO,MAAM;;AAIX,YAAI,aAAQ,sBAAR,mBAA2B,cAAa,UAAU;AACpD,gBAAQ,gBAAgB,MAAS;AAAA,MACnC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,UAAU,MAAM,OAAO,MAAM,MAAM,CAAC;AAEjD,6BACG,gBAAgB,UAAhB,EAAyB,OAAO,UAC9B,UACH;AAEJ;AC1CO,SAAS,kBACd,IACA,SACM;AACN,QAAM,WAAW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,MAAM,OAAO,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,MAAM,MAAA,CAAO,EAAA;AAAA,IAC9H,OAAO,MAAM,MAAM,GAAG,GAAG;AAAA,IACzB,OAAO,MAAM,OAAO,IAAI,GAAG;AAAA,EAAA;AAE7B,MAAI,MAAM,QAAS,OAAM,KAAK,EAAE,KAAK,IAAI,MAAM,SAAS,OAAO,GAAG,GAAG,OAAO,OAAO,MAAM,CAAA,GAAI;AAC7F,SAAO,EAAE,OAAO,IAAI,MAAM,OAAO,OAAO,KAAK,GAAG,QAAQ,MAAM,WAAW,MAAM,OAAO,KAAK,CAAA,EAAC;AAC9F;ACnJO,MAAM,oBAAoB,EAAE,cAAc,aAAa,YAAY,YAAA;"}
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const React = require("react");
|
|
3
|
-
const DRAWING_URL = /^https:\/\/res\.cloudinary\.com\/[\w-]+\/image\/upload\//;
|
|
4
|
-
const IMAGE_BLOCK = /```image[ \t]*\n([\s\S]*?)```/g;
|
|
5
|
-
function headlessImages(text) {
|
|
6
|
-
const images = [];
|
|
7
|
-
const out = (text || "").replace(IMAGE_BLOCK, (_block, raw) => {
|
|
8
|
-
let data;
|
|
9
|
-
try {
|
|
10
|
-
data = JSON.parse(raw.trim());
|
|
11
|
-
} catch {
|
|
12
|
-
return "";
|
|
13
|
-
}
|
|
14
|
-
if (typeof data.url !== "string" || !DRAWING_URL.test(data.url)) return "";
|
|
15
|
-
const image = {
|
|
16
|
-
url: data.url,
|
|
17
|
-
svg: typeof data.svg === "string" && DRAWING_URL.test(data.svg) ? data.svg : null,
|
|
18
|
-
alt: typeof data.alt === "string" ? data.alt.slice(0, 200) : "",
|
|
19
|
-
width: Math.round(Number(data.width)) || 1600,
|
|
20
|
-
height: Math.round(Number(data.height)) || 900
|
|
21
|
-
};
|
|
22
|
-
images.push(image);
|
|
23
|
-
return `![${image.alt.replace(/[[\]]/g, "")}](${image.url})`;
|
|
24
|
-
});
|
|
25
|
-
return { text: out, images };
|
|
26
|
-
}
|
|
27
3
|
const NAME_PREFIXES = [
|
|
28
4
|
/^api[\s_-]*v?\d*[\s_-]*/i,
|
|
29
5
|
/^(get|fetch|list|read|retrieve|show|query|search|find|lookup|look up)[\s_-]+/i,
|
|
@@ -3290,7 +3266,8 @@ function configure(config) {
|
|
|
3290
3266
|
api: baseApi,
|
|
3291
3267
|
debug,
|
|
3292
3268
|
visitorId: (_e = config.visitorId) != null ? _e : null,
|
|
3293
|
-
profile: (_f = config.userProfile) != null ? _f : null
|
|
3269
|
+
profile: (_f = config.userProfile) != null ? _f : null,
|
|
3270
|
+
followUps: cleanFollowUps(config.followUps)
|
|
3294
3271
|
};
|
|
3295
3272
|
}
|
|
3296
3273
|
function identify(userId) {
|
|
@@ -3305,6 +3282,14 @@ function setUserProfile(profile) {
|
|
|
3305
3282
|
if (!configured) throw new Error("Call GuideAI.configure() before setUserProfile().");
|
|
3306
3283
|
configured.profile = profile;
|
|
3307
3284
|
}
|
|
3285
|
+
function setFollowUps(followUps) {
|
|
3286
|
+
if (!configured) throw new Error("Call GuideAI.configure() before setFollowUps().");
|
|
3287
|
+
configured.followUps = cleanFollowUps(followUps != null ? followUps : void 0);
|
|
3288
|
+
}
|
|
3289
|
+
function cleanFollowUps(list) {
|
|
3290
|
+
const clean = (list != null ? list : []).map((text) => text.trim()).filter(Boolean).slice(0, 4);
|
|
3291
|
+
return clean.length ? clean : void 0;
|
|
3292
|
+
}
|
|
3308
3293
|
function requireConfigured() {
|
|
3309
3294
|
if (!configured) {
|
|
3310
3295
|
throw new Error(
|
|
@@ -3319,273 +3304,16 @@ function isConfigured() {
|
|
|
3319
3304
|
function reset() {
|
|
3320
3305
|
configured = null;
|
|
3321
3306
|
}
|
|
3322
|
-
const GuideAI = { configure, identify, setUserProfile, setToolContext, isConfigured, reset };
|
|
3323
|
-
const AUDIO_TYPES = {
|
|
3324
|
-
m4a: "audio/m4a",
|
|
3325
|
-
mp4: "audio/mp4",
|
|
3326
|
-
aac: "audio/aac",
|
|
3327
|
-
caf: "audio/x-caf",
|
|
3328
|
-
wav: "audio/wav",
|
|
3329
|
-
mp3: "audio/mpeg",
|
|
3330
|
-
webm: "audio/webm",
|
|
3331
|
-
ogg: "audio/ogg",
|
|
3332
|
-
"3gp": "audio/3gpp"
|
|
3333
|
-
};
|
|
3334
|
-
function audioType(uri) {
|
|
3335
|
-
var _a, _b;
|
|
3336
|
-
const extension = ((_a = uri.split("?")[0].split(".").pop()) != null ? _a : "").toLowerCase();
|
|
3337
|
-
const type = (_b = AUDIO_TYPES[extension]) != null ? _b : "audio/m4a";
|
|
3338
|
-
return { type, name: `voice.${AUDIO_TYPES[extension] ? extension : "m4a"}` };
|
|
3339
|
-
}
|
|
3340
|
-
function replyFields(result, streamed) {
|
|
3341
|
-
var _a, _b;
|
|
3342
|
-
const { text, images } = headlessImages(answerText(result, streamed));
|
|
3343
|
-
const call = result.confirmationNeeded ? result.pendingToolCall : void 0;
|
|
3344
|
-
return {
|
|
3345
|
-
content: text,
|
|
3346
|
-
images: images.length ? images : void 0,
|
|
3347
|
-
suggestions: ((_a = result.quickReplies) == null ? void 0 : _a.length) ? result.quickReplies.slice(0, 4) : void 0,
|
|
3348
|
-
pendingAction: call ? { label: ((_b = call.label) == null ? void 0 : _b.trim()) || describeToolCall(call), tool: call.tool } : void 0
|
|
3349
|
-
};
|
|
3350
|
-
}
|
|
3351
|
-
let nextId = 0;
|
|
3352
|
-
const nextMessageId = () => `m${nextId += 1}`;
|
|
3353
|
-
function answerText(result, fallback) {
|
|
3354
|
-
var _a, _b;
|
|
3355
|
-
const answer = ((_a = result.answer) != null ? _a : "").trim();
|
|
3356
|
-
if (answer) return answer;
|
|
3357
|
-
const first = (_b = result.guideSteps) == null ? void 0 : _b[0];
|
|
3358
|
-
const body = typeof (first == null ? void 0 : first.body) === "string" ? first.body.trim() : "";
|
|
3359
|
-
if (body) return body;
|
|
3360
|
-
const title = typeof (first == null ? void 0 : first.title) === "string" ? first.title.trim() : "";
|
|
3361
|
-
if (title) return title;
|
|
3362
|
-
return fallback || "Done.";
|
|
3363
|
-
}
|
|
3364
|
-
const FAILURE_MESSAGE = "I'm sorry, I can't complete your request right now. Would you like to talk to a human?";
|
|
3365
|
-
function useGuideAI(options = {}) {
|
|
3366
|
-
var _a, _b;
|
|
3367
|
-
const runtime = useGuideAIRuntime();
|
|
3368
|
-
const configured2 = requireConfigured();
|
|
3369
|
-
const harness = (_a = options.harness) != null ? _a : configured2.harness;
|
|
3370
|
-
const trace = (_b = options.trace) != null ? _b : configured2.debug;
|
|
3371
|
-
const mode = "assistant";
|
|
3372
|
-
const [messages, setMessages] = React.useState([]);
|
|
3373
|
-
const [input, setInput] = React.useState("");
|
|
3374
|
-
const [busy, setBusy] = React.useState(false);
|
|
3375
|
-
const [status, setStatus] = React.useState(null);
|
|
3376
|
-
const [transcribing, setTranscribing] = React.useState(false);
|
|
3377
|
-
const lastQuestion = React.useRef(null);
|
|
3378
|
-
const pending = React.useRef(/* @__PURE__ */ new Map());
|
|
3379
|
-
const mounted = React.useRef(true);
|
|
3380
|
-
React.useEffect(() => () => {
|
|
3381
|
-
mounted.current = false;
|
|
3382
|
-
}, []);
|
|
3383
|
-
React.useEffect(() => {
|
|
3384
|
-
if (typeof harness.hasHistory !== "function" || typeof harness.getConversationHistory !== "function") return;
|
|
3385
|
-
if (!harness.hasHistory()) return;
|
|
3386
|
-
setMessages((previous) => {
|
|
3387
|
-
if (previous.length > 0) return previous;
|
|
3388
|
-
return harness.getConversationHistory().filter((entry) => typeof entry.content === "string" && entry.content.trim()).map((entry, index) => {
|
|
3389
|
-
var _a2;
|
|
3390
|
-
return {
|
|
3391
|
-
id: (_a2 = entry.id) != null ? _a2 : `h${index}`,
|
|
3392
|
-
role: entry.role,
|
|
3393
|
-
content: entry.content
|
|
3394
|
-
};
|
|
3395
|
-
});
|
|
3396
|
-
});
|
|
3397
|
-
}, [harness]);
|
|
3398
|
-
const initialized = React.useRef(null);
|
|
3399
|
-
const ensureInitialized = React.useCallback(() => {
|
|
3400
|
-
if (!initialized.current) initialized.current = harness.initialize();
|
|
3401
|
-
return initialized.current;
|
|
3402
|
-
}, [harness]);
|
|
3403
|
-
const runTurn = React.useCallback(async (replyId, question, work) => {
|
|
3404
|
-
var _a2, _b2;
|
|
3405
|
-
setBusy(true);
|
|
3406
|
-
setStatus(null);
|
|
3407
|
-
let streamed = "";
|
|
3408
|
-
const appendDelta = (delta) => {
|
|
3409
|
-
streamed += delta;
|
|
3410
|
-
if (!mounted.current) return;
|
|
3411
|
-
setMessages((prev) => prev.map((message) => message.id === replyId ? { ...message, content: message.content + delta } : message));
|
|
3412
|
-
};
|
|
3413
|
-
try {
|
|
3414
|
-
await ((_a2 = runtime.auth) == null ? void 0 : _a2.refresh());
|
|
3415
|
-
const result = await work((next2) => {
|
|
3416
|
-
if (mounted.current) setStatus(next2);
|
|
3417
|
-
}, appendDelta);
|
|
3418
|
-
if (trace) traceAssistantAnswer((_b2 = result.answer) != null ? _b2 : "(empty)", result.mode);
|
|
3419
|
-
if (result.confirmationNeeded && result.pendingToolCall) {
|
|
3420
|
-
pending.current.set(replyId, { call: result.pendingToolCall, question });
|
|
3421
|
-
}
|
|
3422
|
-
if (!mounted.current) return;
|
|
3423
|
-
setMessages((prev) => prev.map((message) => message.id === replyId ? { ...message, ...replyFields(result, streamed), streaming: false } : message));
|
|
3424
|
-
} catch (error) {
|
|
3425
|
-
console.log("[GuideAI] ✗ turn failed:", error);
|
|
3426
|
-
if (error instanceof Error && error.stack) {
|
|
3427
|
-
console.log("[GuideAI] stack:", error.stack);
|
|
3428
|
-
}
|
|
3429
|
-
if (!mounted.current) return;
|
|
3430
|
-
setMessages((prev) => prev.map((message) => message.id === replyId ? {
|
|
3431
|
-
...message,
|
|
3432
|
-
content: FAILURE_MESSAGE,
|
|
3433
|
-
streaming: false,
|
|
3434
|
-
error: true
|
|
3435
|
-
} : message));
|
|
3436
|
-
} finally {
|
|
3437
|
-
if (mounted.current) {
|
|
3438
|
-
setBusy(false);
|
|
3439
|
-
setStatus(null);
|
|
3440
|
-
}
|
|
3441
|
-
}
|
|
3442
|
-
}, [runtime, trace]);
|
|
3443
|
-
const send = React.useCallback(async (question) => {
|
|
3444
|
-
const text = (question != null ? question : input).trim();
|
|
3445
|
-
if (!text || busy) return;
|
|
3446
|
-
lastQuestion.current = text;
|
|
3447
|
-
if (question === void 0) setInput("");
|
|
3448
|
-
if (trace) traceUserMessage(text);
|
|
3449
|
-
const replyId = nextMessageId();
|
|
3450
|
-
setMessages((prev) => [
|
|
3451
|
-
...prev,
|
|
3452
|
-
{ id: nextMessageId(), role: "user", content: text },
|
|
3453
|
-
{ id: replyId, role: "assistant", content: "", streaming: true }
|
|
3454
|
-
]);
|
|
3455
|
-
await runTurn(replyId, text, async (onStatus, onDelta) => {
|
|
3456
|
-
await ensureInitialized();
|
|
3457
|
-
const screen = runtime.getActiveScreen();
|
|
3458
|
-
const { profile, visitorId } = requireConfigured();
|
|
3459
|
-
return harness.processMessage(
|
|
3460
|
-
text,
|
|
3461
|
-
screen == null ? void 0 : screen.path,
|
|
3462
|
-
runtime.captureSnapshot(),
|
|
3463
|
-
mode,
|
|
3464
|
-
onStatus,
|
|
3465
|
-
onDelta,
|
|
3466
|
-
void 0,
|
|
3467
|
-
void 0,
|
|
3468
|
-
// Who is asking, as the app knows them; the agent pitches to it.
|
|
3469
|
-
profile ? { profile } : void 0,
|
|
3470
|
-
visitorId != null ? visitorId : void 0
|
|
3471
|
-
);
|
|
3472
|
-
});
|
|
3473
|
-
}, [busy, input, harness, mode, runtime, ensureInitialized, trace, runTurn]);
|
|
3474
|
-
const retry = React.useCallback(async () => {
|
|
3475
|
-
if (!lastQuestion.current || busy) return;
|
|
3476
|
-
setMessages((prev) => prev.slice(0, -2));
|
|
3477
|
-
await send(lastQuestion.current);
|
|
3478
|
-
}, [busy, send]);
|
|
3479
|
-
const clear = React.useCallback(() => {
|
|
3480
|
-
setMessages([]);
|
|
3481
|
-
lastQuestion.current = null;
|
|
3482
|
-
pending.current.clear();
|
|
3483
|
-
}, []);
|
|
3484
|
-
const settleAction = React.useCallback((messageId) => {
|
|
3485
|
-
const action = pending.current.get(messageId);
|
|
3486
|
-
pending.current.delete(messageId);
|
|
3487
|
-
setMessages((prev) => prev.map((message) => message.id === messageId ? { ...message, pendingAction: void 0 } : message));
|
|
3488
|
-
return action;
|
|
3489
|
-
}, []);
|
|
3490
|
-
const confirm = React.useCallback(async (messageId) => {
|
|
3491
|
-
if (busy) return;
|
|
3492
|
-
const action = settleAction(messageId);
|
|
3493
|
-
if (!action) return;
|
|
3494
|
-
const replyId = nextMessageId();
|
|
3495
|
-
setMessages((prev) => [...prev, { id: replyId, role: "assistant", content: "", streaming: true }]);
|
|
3496
|
-
await runTurn(replyId, action.question, async (onStatus, onDelta) => {
|
|
3497
|
-
await ensureInitialized();
|
|
3498
|
-
return harness.executeToolCall(action.call, action.question, onStatus, onDelta);
|
|
3499
|
-
});
|
|
3500
|
-
}, [busy, settleAction, runTurn, ensureInitialized, harness]);
|
|
3501
|
-
const cancel = React.useCallback((messageId) => {
|
|
3502
|
-
if (!settleAction(messageId)) return;
|
|
3503
|
-
setMessages((prev) => [...prev, { id: nextMessageId(), role: "assistant", content: "Okay, I haven't changed anything." }]);
|
|
3504
|
-
}, [settleAction]);
|
|
3505
|
-
const sendVoice = React.useCallback(async (recording) => {
|
|
3506
|
-
var _a2;
|
|
3507
|
-
if (busy || transcribing) return { text: null, error: "Wait for the current reply to finish." };
|
|
3508
|
-
const guessed = audioType(recording.uri);
|
|
3509
|
-
setTranscribing(true);
|
|
3510
|
-
try {
|
|
3511
|
-
const result = await requireConfigured().api.postFile(
|
|
3512
|
-
EP.batchVoiceTranscribe(),
|
|
3513
|
-
"audio",
|
|
3514
|
-
{ uri: recording.uri, name: guessed.name, type: recording.mimeType || guessed.type },
|
|
3515
|
-
{ language_code: recording.languageCode || "en-US" },
|
|
3516
|
-
45e3
|
|
3517
|
-
);
|
|
3518
|
-
const heard = ((_a2 = result == null ? void 0 : result.text) == null ? void 0 : _a2.trim()) || "";
|
|
3519
|
-
if (!heard) return { text: null, error: "I didn't catch that. Please try again." };
|
|
3520
|
-
if (mounted.current) setTranscribing(false);
|
|
3521
|
-
await send(heard);
|
|
3522
|
-
return { text: heard };
|
|
3523
|
-
} catch (error) {
|
|
3524
|
-
console.log("[GuideAI] ✗ voice transcription failed:", error);
|
|
3525
|
-
const message = error instanceof UploadError && error.status === 422 ? error.message : "I couldn't process that recording. Please try again or type your message.";
|
|
3526
|
-
return { text: null, error: message };
|
|
3527
|
-
} finally {
|
|
3528
|
-
if (mounted.current) setTranscribing(false);
|
|
3529
|
-
}
|
|
3530
|
-
}, [busy, transcribing, send]);
|
|
3531
|
-
return {
|
|
3532
|
-
messages,
|
|
3533
|
-
input,
|
|
3534
|
-
setInput,
|
|
3535
|
-
send,
|
|
3536
|
-
busy,
|
|
3537
|
-
canSend: Boolean(input.trim()) && !busy,
|
|
3538
|
-
status,
|
|
3539
|
-
retry,
|
|
3540
|
-
clear,
|
|
3541
|
-
confirm,
|
|
3542
|
-
cancel,
|
|
3543
|
-
sendVoice,
|
|
3544
|
-
transcribing
|
|
3545
|
-
};
|
|
3546
|
-
}
|
|
3547
|
-
function useOnboarding() {
|
|
3548
|
-
const runtime = useGuideAIRuntime();
|
|
3549
|
-
const [checklist, setChecklist] = React.useState(null);
|
|
3550
|
-
const [loading, setLoading] = React.useState(true);
|
|
3551
|
-
const refresh = React.useCallback(async () => {
|
|
3552
|
-
var _a;
|
|
3553
|
-
const { api, visitorId } = requireConfigured();
|
|
3554
|
-
if (!visitorId) {
|
|
3555
|
-
setChecklist(null);
|
|
3556
|
-
setLoading(false);
|
|
3557
|
-
return;
|
|
3558
|
-
}
|
|
3559
|
-
try {
|
|
3560
|
-
const current = await api.get(EP.onboardingCurrent(visitorId));
|
|
3561
|
-
const screen = (_a = runtime.getActiveScreen()) == null ? void 0 : _a.path;
|
|
3562
|
-
const updated = current && !current.completed && !current.dismissed && screen ? await api.post(EP.onboardingObserve(), { user_id: visitorId, screen }) : current;
|
|
3563
|
-
setChecklist(updated);
|
|
3564
|
-
} catch {
|
|
3565
|
-
} finally {
|
|
3566
|
-
setLoading(false);
|
|
3567
|
-
}
|
|
3568
|
-
}, [runtime]);
|
|
3569
|
-
const dismiss = React.useCallback(async () => {
|
|
3570
|
-
const { api, visitorId } = requireConfigured();
|
|
3571
|
-
if (!visitorId) return;
|
|
3572
|
-
const updated = await api.post(EP.onboardingDismiss(), { user_id: visitorId });
|
|
3573
|
-
setChecklist(updated);
|
|
3574
|
-
}, []);
|
|
3575
|
-
React.useEffect(() => {
|
|
3576
|
-
void refresh();
|
|
3577
|
-
const timer = setInterval(() => void refresh(), 5e3);
|
|
3578
|
-
return () => clearInterval(timer);
|
|
3579
|
-
}, [refresh]);
|
|
3580
|
-
return { checklist, loading, refresh, dismiss };
|
|
3581
|
-
}
|
|
3307
|
+
const GuideAI = { configure, identify, setUserProfile, setToolContext, setFollowUps, isConfigured, reset };
|
|
3582
3308
|
exports.EP = EP;
|
|
3583
3309
|
exports.GuideAI = GuideAI;
|
|
3584
3310
|
exports.RegistryContext = RegistryContext;
|
|
3585
3311
|
exports.ScreenRegistry = ScreenRegistry;
|
|
3312
|
+
exports.UploadError = UploadError;
|
|
3313
|
+
exports.describeToolCall = describeToolCall;
|
|
3586
3314
|
exports.requireConfigured = requireConfigured;
|
|
3587
|
-
exports.
|
|
3315
|
+
exports.traceAssistantAnswer = traceAssistantAnswer;
|
|
3316
|
+
exports.traceUserMessage = traceUserMessage;
|
|
3588
3317
|
exports.useGuideAIRuntime = useGuideAIRuntime;
|
|
3589
|
-
exports.useOnboarding = useOnboarding;
|
|
3590
3318
|
exports.useScreenRegistry = useScreenRegistry;
|
|
3591
|
-
//# sourceMappingURL=
|
|
3319
|
+
//# sourceMappingURL=setup-Bl0ZLz8B.cjs.map
|