@guideai/react-native 0.1.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/README.md CHANGED
@@ -24,6 +24,33 @@ GuideAI.configure({
24
24
  });
25
25
  ```
26
26
 
27
+ ### What else your API needs
28
+
29
+ Declare it once in the dashboard (**Copilot Tools → your API → Supplied by your app**), then supply the values:
30
+
31
+ ```ts
32
+ GuideAI.configure({
33
+ …,
34
+ getRequestHeaders: async () => ({ 'device-id': await getDeviceId() }), // declared headers
35
+ toolContext: { course: openCourseId }, // declared values; or GuideAI.setToolContext(…) later
36
+ });
37
+ ```
38
+
39
+ - **Headers:** sent on every call the assistant makes to your API, never to GuideAI. Only names declared in Copilot Tools are sent, and the app's value wins over anything the model sets. `Authorization` comes from `getAuthToken`, never from here.
40
+ - **Values:** each one fills the API inputs it's declared to fill (app key `course` fills `content_id`), so the assistant never asks the user for them.
41
+
42
+ The dashboard shows the exact snippet for your declarations.
43
+
44
+ ### Local or staging GuideAI
45
+
46
+ Production is the default. Point a development build somewhere else with `baseUrl`:
47
+
48
+ ```ts
49
+ GuideAI.configure({ …, baseUrl: __DEV__ ? 'http://localhost:8000' : undefined });
50
+ ```
51
+
52
+ Use `http://10.0.2.2:8000` from an Android emulator.
53
+
27
54
  `userProfile` is a few facts the agent pitches answers to (level, curriculum, language). Update it after login with `GuideAI.setUserProfile(profile)`.
28
55
 
29
56
  `getAuthToken` is read before every turn and may be async. The assistant calls your endpoints (the site's Copilot toolset) from the device with that token, so your API enforces the user's access exactly as it does for your own screens. A `401` asks `onAuthExpired` once and repeats the call. The token is sent only to your API, never to GuideAI, unless the toolset has `forward_user_token` switched on.
package/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const useOnboarding = require("./useOnboarding-C7eFhp2o.cjs");
3
+ const setup = require("./setup-Bl0ZLz8B.cjs");
4
4
  const jsxRuntime = require("react/jsx-runtime");
5
5
  const React = require("react");
6
+ const useOnboarding = require("./useOnboarding-CFxofFst.cjs");
6
7
  function GuideAIScreen({
7
8
  name,
8
9
  path,
@@ -10,8 +11,8 @@ function GuideAIScreen({
10
11
  active = true,
11
12
  children
12
13
  }) {
13
- const runtime = useOnboarding.useGuideAIRuntime();
14
- const registry = React.useMemo(() => new useOnboarding.ScreenRegistry(), [name, path]);
14
+ const runtime = setup.useGuideAIRuntime();
15
+ const registry = React.useMemo(() => new setup.ScreenRegistry(), [name, path]);
15
16
  React.useEffect(() => {
16
17
  if (!active) return;
17
18
  runtime.setActiveScreen({ path, title: title != null ? title : name, registry });
@@ -22,10 +23,10 @@ function GuideAIScreen({
22
23
  }
23
24
  };
24
25
  }, [runtime, registry, path, title, name, active]);
25
- return /* @__PURE__ */ jsxRuntime.jsx(useOnboarding.RegistryContext.Provider, { value: registry, children });
26
+ return /* @__PURE__ */ jsxRuntime.jsx(setup.RegistryContext.Provider, { value: registry, children });
26
27
  }
27
28
  function useGuideAIElement(id, options) {
28
- const registry = useOnboarding.useScreenRegistry();
29
+ const registry = setup.useScreenRegistry();
29
30
  const handlers = React.useRef({});
30
31
  handlers.current = {
31
32
  press: options.press,
@@ -78,9 +79,116 @@ function useGuideAIElement(id, options) {
78
79
  canScrollTo
79
80
  ]);
80
81
  }
81
- exports.GuideAI = useOnboarding.GuideAI;
82
+ const cut = (text, max = useOnboarding.LIMITS.text) => text.replace(/\s+/g, " ").trim().slice(0, max);
83
+ function minor(value, what) {
84
+ if (!Number.isFinite(value) || value < 0) throw new RangeError(`${what} must be a number of zero or more.`);
85
+ return Math.round(value * 100);
86
+ }
87
+ function formatMoney(minorUnits, money) {
88
+ const value = minorUnits / 100;
89
+ if (/^[A-Z]{3}$/.test(money.currency)) {
90
+ try {
91
+ return new Intl.NumberFormat(money.locale, { style: "currency", currency: money.currency }).format(value);
92
+ } catch {
93
+ }
94
+ }
95
+ return `${money.currency}${value.toFixed(2)}`;
96
+ }
97
+ function feeBreakdown(input) {
98
+ const paid = minor(input.amount, "The amount");
99
+ 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") }));
100
+ const taken = fees.reduce((sum, fee) => sum + fee.minor, 0);
101
+ if (taken > paid) throw new RangeError("The fees are more than the amount paid.");
102
+ const received = paid - taken;
103
+ const money = (m) => formatMoney(m, input);
104
+ const feeItems = fees.flatMap((fee, i) => [
105
+ { kind: "text", id: `fee${i}`, text: cut(`${fee.label} −${money(fee.minor)}`), at: [58, 18 + i * 9], size: "s", tone: "red" }
106
+ ]);
107
+ const steps = [
108
+ {
109
+ say: `The customer pays ${money(paid)}.`,
110
+ clear: false,
111
+ draw: [
112
+ { kind: "art", id: "payer", art: "user", at: [4, 10, 12, 20], tone: "ink" },
113
+ { kind: "text", id: "paid", text: money(paid), at: [19, 20], size: "l", tone: "ink" },
114
+ { kind: "ink", ink: "box", at: [17, 13, 26, 14], tone: "ink" }
115
+ ]
116
+ },
117
+ {
118
+ say: fees.length === 1 ? `${fees[0].label} of ${money(fees[0].minor)} is taken out.` : `${fees.length} fees are taken out: ${fees.map((f) => `${f.label}, ${money(f.minor)}`).join("; ")}.`,
119
+ clear: false,
120
+ draw: [{ kind: "ink", ink: "arrow", at: [44, 20], to: [56, 20], tone: "red" }, ...feeItems]
121
+ },
122
+ {
123
+ say: `So ${money(received)} is received.`,
124
+ clear: false,
125
+ draw: [
126
+ { kind: "ink", ink: "arrow", at: [30, 29], to: [30, 45], tone: "ink" },
127
+ { kind: "text", id: "received", text: money(received), at: [19, 52], size: "l", tone: "green" },
128
+ { kind: "ink", ink: "circle", at: [17, 46, 27, 12], tone: "green" }
129
+ ]
130
+ },
131
+ {
132
+ say: "Here it is all together.",
133
+ clear: false,
134
+ draw: [
135
+ {
136
+ kind: "table",
137
+ id: "sum",
138
+ rows: [
139
+ ["Paid", money(paid)],
140
+ ...fees.map((fee) => [fee.label, `−${money(fee.minor)}`]),
141
+ ["Received", money(received)]
142
+ ].map((row) => row.map((cell) => cut(cell, useOnboarding.LIMITS.cell))),
143
+ at: [56, 56, 38],
144
+ tone: "ink"
145
+ },
146
+ { kind: "mark", mark: "received" }
147
+ ]
148
+ }
149
+ ];
150
+ return { title: cut(input.title || "Where the money goes", useOnboarding.LIMITS.title), sample: input.sample === true, steps, art: { user: { icon: "user" } } };
151
+ }
152
+ function processFlow(input) {
153
+ const stages = input.steps.slice(0, 5);
154
+ if (stages.length < 2) throw new RangeError("A process needs at least two steps.");
155
+ const gap = 4;
156
+ const width = (92 - gap * (stages.length - 1)) / stages.length;
157
+ const steps = stages.map((stage, i) => {
158
+ const x = 4 + i * (width + gap);
159
+ const draw = [
160
+ { kind: "ink", ink: "box", at: [x, 40, width, 18], tone: "ink" },
161
+ { kind: "text", id: `s${i}`, text: cut(stage.label, 16), at: [x + 1.5, 49], size: width < 18 ? "s" : "m", tone: "ink" }
162
+ ];
163
+ if (i > 0) draw.unshift({ kind: "ink", ink: "arrow", at: [x - gap + 0.5, 49], to: [x - 0.5, 49], tone: "blue" });
164
+ return { say: cut(stage.say || stage.label, useOnboarding.LIMITS.say), clear: false, draw };
165
+ });
166
+ return { title: cut(input.title, useOnboarding.LIMITS.title), sample: input.sample === true, steps, art: {} };
167
+ }
168
+ function comparison(input) {
169
+ const column = (side, x, key) => ({
170
+ say: cut(`${side.name}: ${side.points.slice(0, 4).join(", ")}.`, useOnboarding.LIMITS.say),
171
+ clear: false,
172
+ draw: [
173
+ { kind: "text", id: `${key}h`, text: cut(side.name, 24), at: [x, 14], size: "l", tone: "blue" },
174
+ { kind: "ink", ink: "underline", at: [x, 9, 36, 9], tone: "blue" },
175
+ ...side.points.slice(0, 4).map((point, i) => ({ kind: "text", text: cut(`• ${point}`, 34), at: [x, 32 + i * 12], size: "s", tone: "ink" }))
176
+ ]
177
+ });
178
+ const steps = [
179
+ { say: cut(input.title, useOnboarding.LIMITS.say), clear: false, draw: [{ kind: "ink", ink: "line", at: [50, 8], to: [50, 88], tone: "ink" }] },
180
+ column(input.left, 6, "l"),
181
+ column(input.right, 56, "r")
182
+ ];
183
+ if (input.summary) steps.push({ say: cut(input.summary, useOnboarding.LIMITS.say), clear: false, draw: [] });
184
+ return { title: cut(input.title, useOnboarding.LIMITS.title), sample: input.sample === true, steps, art: {} };
185
+ }
186
+ const whiteboardLayouts = { feeBreakdown, processFlow, comparison, formatMoney };
187
+ exports.GuideAI = setup.GuideAI;
82
188
  exports.useGuideAI = useOnboarding.useGuideAI;
83
189
  exports.useOnboarding = useOnboarding.useOnboarding;
190
+ exports.useWhiteboard = useOnboarding.useWhiteboard;
84
191
  exports.GuideAIScreen = GuideAIScreen;
85
192
  exports.useGuideAIElement = useGuideAIElement;
193
+ exports.whiteboardLayouts = whiteboardLayouts;
86
194
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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":["useGuideAIRuntime","useMemo","ScreenRegistry","useEffect","RegistryContext","useScreenRegistry","useRef"],"mappings":";;;;;AA4CO,SAAS,cAAc;AAAA,EAC5B;AAAA,EAAM;AAAA,EAAM;AAAA,EAAO,SAAS;AAAA,EAAM;AACpC,GAA2C;AACzC,QAAM,UAAUA,cAAAA,kBAAA;AAIhB,QAAM,WAAWC,MAAAA,QAAQ,MAAM,IAAIC,cAAAA,kBAAkB,CAAC,MAAM,IAAI,CAAC;AAEjEC,QAAAA,UAAU,MAAM;AACd,QAAI,CAAC,OAAQ;AAEb,YAAQ,gBAAgB,EAAE,MAAM,OAAO,wBAAS,MAAM,UAAU;AAEhE,WAAO,MAAM;;AA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A,IAAU;AAAA,IAAa;AAAA,EAAA,CACxB;AACH;;;;;;"}
1
+ {"version":3,"file":"index.cjs","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":["useGuideAIRuntime","useMemo","ScreenRegistry","useEffect","RegistryContext","useScreenRegistry","useRef","LIMITS"],"mappings":";;;;;;AA4CO,SAAS,cAAc;AAAA,EAC5B;AAAA,EAAM;AAAA,EAAM;AAAA,EAAO,SAAS;AAAA,EAAM;AACpC,GAA2C;AACzC,QAAM,UAAUA,MAAAA,kBAAA;AAIhB,QAAM,WAAWC,MAAAA,QAAQ,MAAM,IAAIC,MAAAA,kBAAkB,CAAC,MAAM,IAAI,CAAC;AAEjEC,QAAAA,UAAU,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,wCACGC,MAAAA,gBAAgB,UAAhB,EAAyB,OAAO,UAC9B,UACH;AAEJ;AC1CO,SAAS,kBACd,IACA,SACM;AACN,QAAM,WAAWC,MAAAA,kBAAA;AAGjB,QAAM,WAAWC,MAAAA,OAAwB,EAAE;AAC3C,WAAS,UAAU;AAAA,IACjB,OAAO,QAAQ;AAAA,IACf,U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C,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,SAASA,cAAAA,OAAO,GAAG,GAAG,OAAO,OAAO,MAAM,CAAA,GAAI;AAC7F,SAAO,EAAE,OAAO,IAAI,MAAM,OAAOA,cAAAA,OAAO,KAAK,GAAG,QAAQ,MAAM,WAAW,MAAM,OAAO,KAAK,CAAA,EAAC;AAC9F;ACnJO,MAAM,oBAAoB,EAAE,cAAc,aAAa,YAAY,YAAA;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -342,6 +342,9 @@ interface OnboardingLauncher {
342
342
  interface OnboardingAppearance {
343
343
  template: 'classic' | 'minimal' | 'bold';
344
344
  accent_color: string;
345
+ /** Optional checklist surface and text colours; missing values use the SDK theme. */
346
+ background_color?: string | null;
347
+ text_color?: string | null;
345
348
  /** Missing means the default card; position missing means left. */
346
349
  layout?: 'card' | 'modal' | 'side';
347
350
  position?: 'left' | 'right';
@@ -471,7 +474,8 @@ interface KVStore {
471
474
  }
472
475
  /**
473
476
  * Where a host keeps credentials the copilot may read, named by the
474
- * source a site configured (`localStorage`, `sessionStorage`, `cookie`).
477
+ * source a site configured (`localStorage`, `sessionStorage`, `cookie`),
478
+ * or `app` for values the host app hands over itself (declared headers).
475
479
  *
476
480
  * Returns null for a source this platform does not have. A mobile app has
477
481
  * no cookie jar, and saying so plainly is better than returning an empty
@@ -479,6 +483,15 @@ interface KVStore {
479
483
  */
480
484
  interface CredentialSource {
481
485
  read(source: string, key: string): string | null;
486
+ /**
487
+ * The signed-in user's bearer token, when the host hands it over itself.
488
+ *
489
+ * A native app keeps its token where it chooses (SecureStore,
490
+ * AsyncStorage), not in a store the site's dashboard can name. When this
491
+ * returns a token it wins over the configured storage lookup for a
492
+ * `bearer` toolset; null falls back to that lookup.
493
+ */
494
+ authToken?(): string | null;
482
495
  }
483
496
 
484
497
  /**
@@ -639,6 +652,12 @@ declare class CopilotHarness {
639
652
  distinct_id?: string;
640
653
  }): void;
641
654
  setToolContext(values: Record<string, string> | undefined): void;
655
+ /**
656
+ * The app's tool inputs as the API names them. A value declared in Copilot
657
+ * Tools as filling other inputs (app key `course` fills `content_id`) is
658
+ * sent under those names too; one the app set by that name already wins.
659
+ */
660
+ private contextForTools;
642
661
  /** Whether copilot action tools are available for this site. */
643
662
  isEnabled(): boolean;
644
663
  /**
@@ -726,6 +745,12 @@ declare class CopilotHarness {
726
745
  private hasAnyLocalTools;
727
746
  private canExecuteTool;
728
747
  private executeLocalTool;
748
+ /**
749
+ * An MCP tool, after the user approved it: we cannot call it — it is
750
+ * reached from GuideAI's network with a secret the client never holds —
751
+ * so the backend runs it, told who the user is by their token.
752
+ */
753
+ private executeOnServer;
729
754
  private executeLocalToolBatch;
730
755
  private _formatToolResult;
731
756
  private _readFormatToolResultStream;
@@ -755,6 +780,12 @@ interface SyncNativeStore {
755
780
 
756
781
  /** Returns the signed-in user's token, or null when signed out. May be async. */
757
782
  type AuthTokenGetter = () => string | null | undefined | Promise<string | null | undefined>;
783
+ /**
784
+ * Values for the headers the site's toolset declares as supplied by the app
785
+ * (Copilot Tools → "Supplied by your app"). May be async. Only declared
786
+ * names are ever sent.
787
+ */
788
+ type RequestHeadersGetter = () => Record<string, string> | null | undefined | Promise<Record<string, string> | null | undefined>;
758
789
 
759
790
  /** What a host says about one control on screen. */
760
791
  interface DeclaredElement {
@@ -820,8 +851,8 @@ interface GuideAIConfig {
820
851
  */
821
852
  origin?: string;
822
853
  /**
823
- * Where the GuideAI backend lives. Defaults to the hosted service, so
824
- * only self-hosted deployments set it.
854
+ * Where the GuideAI backend lives. Defaults to production; set it to test
855
+ * against a local or staging GuideAI (`http://localhost:8000`).
825
856
  */
826
857
  baseUrl?: string;
827
858
  /**
@@ -856,12 +887,32 @@ interface GuideAIConfig {
856
887
  * Omitted: getAuthToken() is asked again.
857
888
  */
858
889
  onAuthExpired?: AuthTokenGetter;
890
+ /**
891
+ * Values for the headers your toolset declares in Copilot Tools as
892
+ * "Supplied by your app" — a device id, a tenant: `async () => ({
893
+ * 'device-id': id })`. Read before every turn; sent only to your API,
894
+ * never to GuideAI, and only for declared names.
895
+ */
896
+ getRequestHeaders?: RequestHeadersGetter;
897
+ /**
898
+ * Values the app knows right now — the course open on screen: `{ course:
899
+ * '42' }`. Each fills the API inputs of the same name, or those the
900
+ * toolset declares it fills (Copilot Tools → "Supplied by your app").
901
+ * Change it with GuideAI.setToolContext().
902
+ */
903
+ toolContext?: Record<string, string>;
859
904
  /**
860
905
  * Facts about the signed-in user for the agent to pitch answers to —
861
906
  * `{ age: 12, class: 'JSS1', country: 'Nigeria', language: 'en' }`.
862
907
  * Sent with every turn; change it with GuideAI.setUserProfile().
863
908
  */
864
909
  userProfile?: GuideAIUserProfile;
910
+ /**
911
+ * Follow-ups offered under an answer that came without suggestions of
912
+ * its own, in the app's language: ['Explain it differently', 'Give me an
913
+ * example']. Change them with GuideAI.setFollowUps().
914
+ */
915
+ followUps?: string[];
865
916
  /**
866
917
  * Log the full conversation and every request. Development only —
867
918
  * it prints message content to the console.
@@ -880,8 +931,12 @@ type GuideAIUserProfile = Record<string, string | number | boolean | Array<strin
880
931
  declare function configure(config: GuideAIConfig): void;
881
932
  /** Call after login so chat and the checklist use the same person. */
882
933
  declare function identify(userId: string | null): void;
934
+ /** Replace the tool inputs the app knows now (e.g. when another course opens). */
935
+ declare function setToolContext(values: Record<string, string> | null): void;
883
936
  /** Replace what the agent knows about the user (after login, or a profile edit). */
884
937
  declare function setUserProfile(profile: GuideAIUserProfile | null): void;
938
+ /** Replace the app's follow-ups (after a language change). */
939
+ declare function setFollowUps(followUps: string[] | null): void;
885
940
  /** Whether configure() has run. Lets a host render its own fallback. */
886
941
  declare function isConfigured(): boolean;
887
942
  /** Test seam, and for hosts that switch sites at runtime. */
@@ -890,6 +945,8 @@ declare const GuideAI: {
890
945
  configure: typeof configure;
891
946
  identify: typeof identify;
892
947
  setUserProfile: typeof setUserProfile;
948
+ setToolContext: typeof setToolContext;
949
+ setFollowUps: typeof setFollowUps;
893
950
  isConfigured: typeof isConfigured;
894
951
  reset: typeof reset;
895
952
  };
@@ -930,14 +987,25 @@ interface GuideAIMessage {
930
987
  id: string;
931
988
  role: 'user' | 'assistant';
932
989
  content: string;
990
+ /** When the message was sent or the answer started (ms since epoch). */
991
+ createdAt: number;
992
+ /** On an answer: the user message it replied to. */
993
+ question?: string;
933
994
  /** True while tokens are still arriving for this message. */
934
995
  streaming?: boolean;
935
996
  error?: boolean;
936
997
  /**
937
998
  * Follow-up suggestions to draw as chips. A tap is just
938
- * `send(suggestion)`.
999
+ * `send(suggestion)`. The site's own when the agent offered some,
1000
+ * otherwise the `followUps` the app configured.
939
1001
  */
940
1002
  suggestions?: string[];
1003
+ /**
1004
+ * This answer can be explained on the whiteboard (the Blueprint has the
1005
+ * block, and the answer is finished). Draw a button that calls
1006
+ * `explainOnWhiteboard(id)`.
1007
+ */
1008
+ whiteboard?: boolean;
941
1009
  /**
942
1010
  * Pictures the agent drew. They are also in `content` as Markdown
943
1011
  * images where they belong; use this list to place them yourself.
@@ -976,8 +1044,25 @@ interface GuideAIVoiceResult {
976
1044
  * underneath a host's UI without them changing a line.
977
1045
  */
978
1046
  interface UseGuideAIResult {
979
- /** The conversation so far, oldest first. */
1047
+ /**
1048
+ * The conversation so far, oldest first, ready to draw. An answer that
1049
+ * has not produced any text yet is left out; `typing` covers it.
1050
+ */
980
1051
  messages: GuideAIMessage[];
1052
+ /** An answer is on its way but has no text yet: draw a typing indicator. */
1053
+ typing: boolean;
1054
+ /**
1055
+ * Chips to draw under the latest answer: its suggestions, or the app's
1056
+ * `followUps`. Empty while a turn runs and before the first answer.
1057
+ */
1058
+ followUps: string[];
1059
+ /** The Blueprint has the whiteboard block. */
1060
+ whiteboardAvailable: boolean;
1061
+ /**
1062
+ * Explain an answer on the whiteboard, with the question it answered.
1063
+ * Mount `<GuideAIWhiteboard />` once to show the board.
1064
+ */
1065
+ explainOnWhiteboard(messageId: string): Promise<boolean>;
981
1066
  /**
982
1067
  * The current input text, and its setter.
983
1068
  *
@@ -1028,6 +1113,12 @@ interface UseGuideAIOptions {
1028
1113
  * so a host never holds a reference to it.
1029
1114
  */
1030
1115
  harness?: CopilotHarness;
1116
+ /**
1117
+ * Follow-ups offered under an answer that came without suggestions of
1118
+ * its own ("Explain it differently", "Give me an example"). Defaults to
1119
+ * GuideAI.configure({ followUps }).
1120
+ */
1121
+ followUps?: string[];
1031
1122
  }
1032
1123
  declare function useGuideAI(options?: UseGuideAIOptions): UseGuideAIResult;
1033
1124
 
@@ -1039,5 +1130,152 @@ declare function useOnboarding(): {
1039
1130
  dismiss: () => Promise<void>;
1040
1131
  };
1041
1132
 
1042
- export { GuideAI, GuideAIScreen, useGuideAI, useGuideAIElement, useOnboarding };
1043
- export type { AuthTokenGetter, DeclaredElement, ElementHandlers, GuideAIConfig, HeadlessImage as GuideAIImage, GuideAIMessage, GuideAIScreenProps, GuideAIUserProfile, GuideAIVoiceRecording, GuideAIVoiceResult, NavigationRefLike, OnboardingState, OnboardingStepState, SyncNativeStore, UseGuideAIElementOptions, UseGuideAIResult };
1133
+ declare const INK_KINDS: readonly ["line", "arrow", "poly", "curve", "free", "oval", "corner", "arc", "dot", "circle", "box", "underline", "cross", "tick", "bracket"];
1134
+ /** How a point marks the real page. */
1135
+ declare const POINT_MARKS: readonly ["circle", "underline", "box"];
1136
+ type PointMark = (typeof POINT_MARKS)[number];
1137
+ type InkKind = (typeof INK_KINDS)[number];
1138
+ type Size = 's' | 'm' | 'l';
1139
+ type Tone = 'ink' | 'blue' | 'red' | 'green';
1140
+ type Point = [number, number];
1141
+ type Box = [number, number, number, number];
1142
+ type BoardItem = {
1143
+ kind: 'art';
1144
+ id?: string;
1145
+ art: string;
1146
+ at: Box;
1147
+ tone: Tone;
1148
+ } | {
1149
+ kind: 'text';
1150
+ id?: string;
1151
+ text: string;
1152
+ at: Point;
1153
+ size: Size;
1154
+ tone: Tone;
1155
+ } | {
1156
+ kind: 'ink';
1157
+ id?: string;
1158
+ ink: InkKind;
1159
+ at?: Point | Box;
1160
+ to?: Point;
1161
+ pts?: Point[];
1162
+ closed?: boolean;
1163
+ tone: Tone;
1164
+ } | {
1165
+ kind: 'table';
1166
+ id?: string;
1167
+ rows: string[][];
1168
+ at: [number, number, number];
1169
+ tone: Tone;
1170
+ } | {
1171
+ kind: 'mark';
1172
+ mark: string;
1173
+ } | {
1174
+ kind: 'point';
1175
+ point: string;
1176
+ as: PointMark;
1177
+ } | {
1178
+ kind: 'erase';
1179
+ erase: string;
1180
+ };
1181
+ interface BoardStep {
1182
+ say: string;
1183
+ clear: boolean;
1184
+ draw: BoardItem[];
1185
+ }
1186
+ /** Ink for a picture: traced contours (SVG path data) in their own box. */
1187
+ interface ArtInk {
1188
+ view_box: string;
1189
+ transform: string;
1190
+ contours: string[];
1191
+ }
1192
+ interface BoardScene {
1193
+ /** 3: the even 160 x 100 grid. Absent (a host's board): 0-100 both ways. */
1194
+ v?: 2 | 3;
1195
+ title: string;
1196
+ /** Example numbers: the board says so. */
1197
+ sample: boolean;
1198
+ steps: BoardStep[];
1199
+ /** Pictures by description: a built-in icon, or traced ink. */
1200
+ art: Record<string, {
1201
+ icon: string;
1202
+ } | ArtInk>;
1203
+ }
1204
+
1205
+ type WhiteboardStatus = 'closed' | 'loading' | 'playing' | 'error';
1206
+ interface WhiteboardState {
1207
+ status: WhiteboardStatus;
1208
+ scene: BoardScene | null;
1209
+ error: string | null;
1210
+ /** What was asked, for the loading title and Try again. */
1211
+ question: string;
1212
+ answer?: string;
1213
+ }
1214
+
1215
+ interface UseWhiteboardResult {
1216
+ /** The Blueprint has "Explain on a whiteboard". False until the server says so. */
1217
+ available: boolean;
1218
+ state: WhiteboardState;
1219
+ /** Explain an answer on the board: the question asked, and the answer given. */
1220
+ explain(question: string, answer?: string): Promise<boolean>;
1221
+ /** Draw a board the host built (see `whiteboardLayouts`). Throws SceneError if it cannot be drawn. */
1222
+ play(scene: unknown): void;
1223
+ retry(): void;
1224
+ close(): void;
1225
+ }
1226
+ declare function useWhiteboard(): UseWhiteboardResult;
1227
+
1228
+ interface Money {
1229
+ /** ISO 4217 code ("GBP") or a symbol ("£"). */
1230
+ currency: string;
1231
+ /** Formatting locale; the browser's by default. */
1232
+ locale?: string;
1233
+ }
1234
+ interface FeeBreakdownInput extends Money {
1235
+ /** What the customer pays. */
1236
+ amount: number;
1237
+ /** Each deduction, in the order it is taken. */
1238
+ fees: {
1239
+ label: string;
1240
+ amount: number;
1241
+ }[];
1242
+ title?: string;
1243
+ /** Example figures: the board is labelled as an example. */
1244
+ sample?: boolean;
1245
+ }
1246
+ declare function formatMoney(minorUnits: number, money: Money): string;
1247
+ /** Amount paid → each fee taken → what is received, with the table to check it. */
1248
+ declare function feeBreakdown(input: FeeBreakdownInput): BoardScene;
1249
+ /** A few stages in a row, each boxed and joined to the next by an arrow. */
1250
+ declare function processFlow(input: {
1251
+ title: string;
1252
+ steps: {
1253
+ label: string;
1254
+ say?: string;
1255
+ }[];
1256
+ sample?: boolean;
1257
+ }): BoardScene;
1258
+ /** Two options side by side, the points of each under its name. */
1259
+ declare function comparison(input: {
1260
+ title: string;
1261
+ left: {
1262
+ name: string;
1263
+ points: string[];
1264
+ };
1265
+ right: {
1266
+ name: string;
1267
+ points: string[];
1268
+ };
1269
+ summary?: string;
1270
+ sample?: boolean;
1271
+ }): BoardScene;
1272
+
1273
+ declare const whiteboardLayouts: {
1274
+ feeBreakdown: typeof feeBreakdown;
1275
+ processFlow: typeof processFlow;
1276
+ comparison: typeof comparison;
1277
+ formatMoney: typeof formatMoney;
1278
+ };
1279
+
1280
+ export { GuideAI, GuideAIScreen, useGuideAI, useGuideAIElement, useOnboarding, useWhiteboard, whiteboardLayouts };
1281
+ export type { AuthTokenGetter, DeclaredElement, ElementHandlers, GuideAIConfig, HeadlessImage as GuideAIImage, GuideAIMessage, GuideAIScreenProps, GuideAIUserProfile, GuideAIVoiceRecording, GuideAIVoiceResult, NavigationRefLike, OnboardingState, OnboardingStepState, RequestHeadersGetter, SyncNativeStore, UseGuideAIElementOptions, UseGuideAIResult, UseWhiteboardResult, WhiteboardState, WhiteboardStatus };