@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 CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const useOnboarding = require("./useOnboarding-DWkCW5v0.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,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M,kCAAS,SAAQ,aAAjB;AAAA;AAExC,WAAO,SAAS;AAAA,MACd,EAAE,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.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,E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AAM,IAAI,KAAK,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE,GAAG,MAAM,KAAK,MAAM,QAAQ;AAAA,IAAA;AAAA,EACvJ;AAEF,QAAM,QAAqB;AAAA,IACzB,EAAE,KAAK,IAAI,MAAM,OAAOA,cAAAA,OAAO,GAAG,GAAG,OAAO,OAAO,MAAM,CAAC,EAAE,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,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
@@ -907,6 +907,12 @@ interface GuideAIConfig {
907
907
  * Sent with every turn; change it with GuideAI.setUserProfile().
908
908
  */
909
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[];
910
916
  /**
911
917
  * Log the full conversation and every request. Development only —
912
918
  * it prints message content to the console.
@@ -929,6 +935,8 @@ declare function identify(userId: string | null): void;
929
935
  declare function setToolContext(values: Record<string, string> | null): void;
930
936
  /** Replace what the agent knows about the user (after login, or a profile edit). */
931
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;
932
940
  /** Whether configure() has run. Lets a host render its own fallback. */
933
941
  declare function isConfigured(): boolean;
934
942
  /** Test seam, and for hosts that switch sites at runtime. */
@@ -938,6 +946,7 @@ declare const GuideAI: {
938
946
  identify: typeof identify;
939
947
  setUserProfile: typeof setUserProfile;
940
948
  setToolContext: typeof setToolContext;
949
+ setFollowUps: typeof setFollowUps;
941
950
  isConfigured: typeof isConfigured;
942
951
  reset: typeof reset;
943
952
  };
@@ -978,14 +987,25 @@ interface GuideAIMessage {
978
987
  id: string;
979
988
  role: 'user' | 'assistant';
980
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;
981
994
  /** True while tokens are still arriving for this message. */
982
995
  streaming?: boolean;
983
996
  error?: boolean;
984
997
  /**
985
998
  * Follow-up suggestions to draw as chips. A tap is just
986
- * `send(suggestion)`.
999
+ * `send(suggestion)`. The site's own when the agent offered some,
1000
+ * otherwise the `followUps` the app configured.
987
1001
  */
988
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;
989
1009
  /**
990
1010
  * Pictures the agent drew. They are also in `content` as Markdown
991
1011
  * images where they belong; use this list to place them yourself.
@@ -1024,8 +1044,25 @@ interface GuideAIVoiceResult {
1024
1044
  * underneath a host's UI without them changing a line.
1025
1045
  */
1026
1046
  interface UseGuideAIResult {
1027
- /** 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
+ */
1028
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>;
1029
1066
  /**
1030
1067
  * The current input text, and its setter.
1031
1068
  *
@@ -1076,6 +1113,12 @@ interface UseGuideAIOptions {
1076
1113
  * so a host never holds a reference to it.
1077
1114
  */
1078
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[];
1079
1122
  }
1080
1123
  declare function useGuideAI(options?: UseGuideAIOptions): UseGuideAIResult;
1081
1124
 
@@ -1087,5 +1130,152 @@ declare function useOnboarding(): {
1087
1130
  dismiss: () => Promise<void>;
1088
1131
  };
1089
1132
 
1090
- export { GuideAI, GuideAIScreen, useGuideAI, useGuideAIElement, useOnboarding };
1091
- export type { AuthTokenGetter, DeclaredElement, ElementHandlers, GuideAIConfig, HeadlessImage as GuideAIImage, GuideAIMessage, GuideAIScreenProps, GuideAIUserProfile, GuideAIVoiceRecording, GuideAIVoiceResult, NavigationRefLike, OnboardingState, OnboardingStepState, RequestHeadersGetter, 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 };
package/dist/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import { u as useGuideAIRuntime, S as ScreenRegistry, R as RegistryContext, a as useScreenRegistry } from "./useOnboarding-DAEGoYSs.js";
2
- import { G, b, c } from "./useOnboarding-DAEGoYSs.js";
1
+ import { u as useGuideAIRuntime, S as ScreenRegistry, R as RegistryContext, a as useScreenRegistry } from "./setup-CkXajERE.js";
2
+ import { G } from "./setup-CkXajERE.js";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { useMemo, useEffect, useRef } from "react";
5
+ import { L as LIMITS } from "./useOnboarding-BAKQq8T_.js";
6
+ import { u, a, b } from "./useOnboarding-BAKQq8T_.js";
5
7
  function GuideAIScreen({
6
8
  name,
7
9
  path,
@@ -77,11 +79,118 @@ function useGuideAIElement(id, options) {
77
79
  canScrollTo
78
80
  ]);
79
81
  }
82
+ const cut = (text, max = 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, 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", 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, LIMITS.say), clear: false, draw };
165
+ });
166
+ return { title: cut(input.title, 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(", ")}.`, 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, 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, LIMITS.say), clear: false, draw: [] });
184
+ return { title: cut(input.title, LIMITS.title), sample: input.sample === true, steps, art: {} };
185
+ }
186
+ const whiteboardLayouts = { feeBreakdown, processFlow, comparison, formatMoney };
80
187
  export {
81
188
  G as GuideAI,
82
189
  GuideAIScreen,
83
- b as useGuideAI,
190
+ u as useGuideAI,
84
191
  useGuideAIElement,
85
- c as useOnboarding
192
+ a as useOnboarding,
193
+ b as useWhiteboard,
194
+ whiteboardLayouts
86
195
  };
87
196
  //# sourceMappingURL=index.mjs.map