@sts-ai/sdk 1.0.2 → 1.1.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 +10 -3
- package/dist/core.d.ts +15 -0
- package/dist/core.js +44 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react.d.ts +7 -1
- package/dist/react.js +23 -14
- package/dist/tourPages.d.ts +13 -0
- package/dist/tourPages.js +34 -0
- package/dist/types.d.ts +2 -0
- package/dist/vue.d.ts +3 -1
- package/dist/vue.js +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,12 @@ about ten times a second: use it to animate an orb or bars.
|
|
|
110
110
|
|
|
111
111
|
### Tour that follows the visitor's scroll
|
|
112
112
|
|
|
113
|
+
Each page of your website has its own tour (set in Support → Tour: Home, `/pricing`, or a pattern
|
|
114
|
+
like `/blog/*` for pages that share a layout). `useStsWizard()` plays the one for the page the
|
|
115
|
+
visitor is on, and is `null` on a page with none. In Next.js pass the path so it follows
|
|
116
|
+
client-side navigation: `useStsWizard(undefined, usePathname())`. It also tells your dashboard
|
|
117
|
+
which `data-sts-step` spots the page has, so steps can pick them by name.
|
|
118
|
+
|
|
113
119
|
`start()` lets the tour lead: it scrolls to each section and narrates it. `follow()` lets the
|
|
114
120
|
visitor lead: nothing scrolls, and each `[data-sts-step]` section speaks once when it reaches the
|
|
115
121
|
middle of the screen. Browsers need one click before sound, so call `follow()` from your
|
|
@@ -168,7 +174,7 @@ Play one step whenever your page wants, by its id or its `data-sts-step` name:
|
|
|
168
174
|
```ts
|
|
169
175
|
const tour = useStsWizard() // React or Vue
|
|
170
176
|
button.addEventListener('click', () => tour.unlock()) // one click first: browsers need it for sound
|
|
171
|
-
window.addEventListener('pricing-open', () => tour
|
|
177
|
+
window.addEventListener('pricing-open', () => tour?.play('pricing'))
|
|
172
178
|
```
|
|
173
179
|
|
|
174
180
|
## Without a framework
|
|
@@ -186,8 +192,9 @@ const voice = createVoice(sts)
|
|
|
186
192
|
voice.subscribe((state) => orb.style.setProperty('--level', String(state.agentLevel)))
|
|
187
193
|
orbButton.addEventListener('click', () => voice.start())
|
|
188
194
|
|
|
189
|
-
const
|
|
190
|
-
|
|
195
|
+
const pageTour = await sts.wizard.forPage() // this page's tour, or null
|
|
196
|
+
sts.wizard.reportPage() // lists this page's tour spots in your dashboard
|
|
197
|
+
const tour = pageTour && createWizardPlayer(pageTour)
|
|
191
198
|
document.addEventListener('scroll-into-pricing', () => tour.play('pricing'))
|
|
192
199
|
```
|
|
193
200
|
|
package/dist/core.d.ts
CHANGED
|
@@ -26,6 +26,21 @@ export declare function createSts(options: StsOptions): {
|
|
|
26
26
|
};
|
|
27
27
|
wizard: {
|
|
28
28
|
load(slug: string): Promise<StsWizard>;
|
|
29
|
+
/**
|
|
30
|
+
* Tells your dashboard (Support → Results) how far visitors get: a step played, the tour's
|
|
31
|
+
* end, or a step's button clicked. The React and Vue hooks call it for you; never throws.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The published tour for a page of your website (default: the page the visitor is on), or
|
|
35
|
+
* null when that page has none.
|
|
36
|
+
*/
|
|
37
|
+
forPage(pathname?: string): Promise<StsWizard | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Tells your dashboard which tour spots (`data-sts-step`) this page has, so Support → Tour
|
|
40
|
+
* offers them by name. Once per page per visit; the React and Vue hooks call it. Never throws.
|
|
41
|
+
*/
|
|
42
|
+
reportPage(pathname?: string): void;
|
|
43
|
+
report(slug: string, kind: "step" | "finish" | "click", stepId?: string): void;
|
|
29
44
|
};
|
|
30
45
|
business: {
|
|
31
46
|
get(): Promise<StsBusiness>;
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StsError, } from './types.js';
|
|
2
|
+
import { cleanPath, sectionsOnPage, tourForPage } from './tourPages.js';
|
|
2
3
|
const SESSION_HEADER = 'X-Sts-Session';
|
|
3
4
|
const SITE_KEY_HEADER = 'X-Sts-Site-Key';
|
|
4
5
|
const REFRESH_MARGIN_MS = 60000;
|
|
@@ -128,6 +129,49 @@ export function createSts(options) {
|
|
|
128
129
|
async load(slug) {
|
|
129
130
|
return (await request(`/api/sdk/v1/wizards/${encodeURIComponent(slug)}`)).wizard;
|
|
130
131
|
},
|
|
132
|
+
/**
|
|
133
|
+
* Tells your dashboard (Support → Results) how far visitors get: a step played, the tour's
|
|
134
|
+
* end, or a step's button clicked. The React and Vue hooks call it for you; never throws.
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* The published tour for a page of your website (default: the page the visitor is on), or
|
|
138
|
+
* null when that page has none.
|
|
139
|
+
*/
|
|
140
|
+
async forPage(pathname) {
|
|
141
|
+
const path = pathname ?? (typeof location === 'undefined' ? '/' : location.pathname);
|
|
142
|
+
const match = tourForPage((await ensureSession()).info.services.wizards, path);
|
|
143
|
+
return match ? (await request(`/api/sdk/v1/wizards/${encodeURIComponent(match.slug)}`)).wizard : null;
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Tells your dashboard which tour spots (`data-sts-step`) this page has, so Support → Tour
|
|
147
|
+
* offers them by name. Once per page per visit; the React and Vue hooks call it. Never throws.
|
|
148
|
+
*/
|
|
149
|
+
reportPage(pathname) {
|
|
150
|
+
if (typeof location === 'undefined')
|
|
151
|
+
return;
|
|
152
|
+
const path = cleanPath(pathname ?? location.pathname);
|
|
153
|
+
const key = `sts-page:${path}`;
|
|
154
|
+
try {
|
|
155
|
+
if (sessionStorage.getItem(key))
|
|
156
|
+
return;
|
|
157
|
+
sessionStorage.setItem(key, '1');
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// No storage: report anyway, the server keeps one row per page.
|
|
161
|
+
}
|
|
162
|
+
void request('/api/sdk/v1/pages', {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'Content-Type': 'application/json' },
|
|
165
|
+
body: JSON.stringify({ path, sections: sectionsOnPage() }),
|
|
166
|
+
}).catch(() => undefined);
|
|
167
|
+
},
|
|
168
|
+
report(slug, kind, stepId) {
|
|
169
|
+
void request('/api/sdk/v1/activity', {
|
|
170
|
+
method: 'POST',
|
|
171
|
+
headers: { 'Content-Type': 'application/json' },
|
|
172
|
+
body: JSON.stringify({ kind, tour: slug, step: stepId }),
|
|
173
|
+
}).catch(() => undefined);
|
|
174
|
+
},
|
|
131
175
|
},
|
|
132
176
|
business: {
|
|
133
177
|
async get() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createSts } from './core.js';
|
|
2
2
|
export type { StsClient } from './core.js';
|
|
3
3
|
export { createWizardPlayer } from './wizardPlayer.js';
|
|
4
|
+
export { pageMatches, tourForPage } from './tourPages.js';
|
|
4
5
|
export type { WizardPlayer, WizardPlayerEvents } from './wizardPlayer.js';
|
|
5
6
|
export * from './types.js';
|
|
6
7
|
export { createChat, createForm, createVoice } from './controllers.js';
|
package/dist/index.js
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -72,9 +72,15 @@ export declare function useStsForm(): {
|
|
|
72
72
|
* Voice tour across your own page. Tag sections with `data-sts-step="…"`; style `[data-sts-active]`.
|
|
73
73
|
* Each business has one wizard, so `slug` is optional.
|
|
74
74
|
*/
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The tour for the page the visitor is on (each page of your website has its own, set in
|
|
77
|
+
* Support → Tour). In Next.js pass `usePathname()` so it follows client-side navigation; pass a
|
|
78
|
+
* `slug` to play one tour anywhere. `wizard` stays null on a page with no tour.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useStsWizard(slug?: string, pathname?: string): {
|
|
76
81
|
wizard: StsWizard | null;
|
|
77
82
|
ready: boolean;
|
|
83
|
+
clicked: (clickedStep: StsWizardStep) => void;
|
|
78
84
|
start: () => void;
|
|
79
85
|
follow: () => void;
|
|
80
86
|
savedSound: () => "on" | "off" | null;
|
package/dist/react.js
CHANGED
|
@@ -258,7 +258,12 @@ export function useStsForm() {
|
|
|
258
258
|
* Voice tour across your own page. Tag sections with `data-sts-step="…"`; style `[data-sts-active]`.
|
|
259
259
|
* Each business has one wizard, so `slug` is optional.
|
|
260
260
|
*/
|
|
261
|
-
|
|
261
|
+
/**
|
|
262
|
+
* The tour for the page the visitor is on (each page of your website has its own, set in
|
|
263
|
+
* Support → Tour). In Next.js pass `usePathname()` so it follows client-side navigation; pass a
|
|
264
|
+
* `slug` to play one tour anywhere. `wizard` stays null on a page with no tour.
|
|
265
|
+
*/
|
|
266
|
+
export function useStsWizard(slug, pathname) {
|
|
262
267
|
const client = useSts();
|
|
263
268
|
const [wizard, setWizard] = useState(null);
|
|
264
269
|
const [error, setError] = useState(null);
|
|
@@ -270,23 +275,17 @@ export function useStsWizard(slug) {
|
|
|
270
275
|
const playerRef = useRef(null);
|
|
271
276
|
useEffect(() => {
|
|
272
277
|
let active = true;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (!first)
|
|
278
|
-
throw new Error('No published wizard for this business');
|
|
279
|
-
return first;
|
|
280
|
-
});
|
|
281
|
-
resolveSlug
|
|
282
|
-
.then((wizardSlug) => client.wizard.load(wizardSlug))
|
|
278
|
+
// Each page of your website has its own tour: the one for this page, unless you name one.
|
|
279
|
+
client.wizard.reportPage(pathname);
|
|
280
|
+
setWizard(null);
|
|
281
|
+
(slug ? client.wizard.load(slug) : client.wizard.forPage(pathname))
|
|
283
282
|
.then((value) => active && setWizard(value))
|
|
284
283
|
.catch((err) => active && setError(errorMessage(err)));
|
|
285
284
|
return () => {
|
|
286
285
|
active = false;
|
|
287
286
|
playerRef.current?.stop();
|
|
288
287
|
};
|
|
289
|
-
}, [client, slug]);
|
|
288
|
+
}, [client, slug, pathname]);
|
|
290
289
|
const makePlayer = useCallback(() => {
|
|
291
290
|
if (!wizard)
|
|
292
291
|
return null;
|
|
@@ -295,15 +294,19 @@ export function useStsWizard(slug) {
|
|
|
295
294
|
onStep: (current, index) => {
|
|
296
295
|
setStep(current);
|
|
297
296
|
setStepIndex(index);
|
|
297
|
+
client.wizard.report(wizard.slug, 'step', current.id);
|
|
298
298
|
},
|
|
299
299
|
onSpeakingChange: setSpeaking,
|
|
300
|
-
onEnd: () =>
|
|
300
|
+
onEnd: () => {
|
|
301
|
+
setPlaying(false);
|
|
302
|
+
client.wizard.report(wizard.slug, 'finish');
|
|
303
|
+
},
|
|
301
304
|
});
|
|
302
305
|
player.setMuted(muted);
|
|
303
306
|
playerRef.current = player;
|
|
304
307
|
setPlaying(true);
|
|
305
308
|
return player;
|
|
306
|
-
}, [muted, wizard]);
|
|
309
|
+
}, [client, muted, wizard]);
|
|
307
310
|
/** The tour leads: scrolls to each section and narrates it. Call from a click handler. */
|
|
308
311
|
const start = useCallback(() => {
|
|
309
312
|
makePlayer()?.start();
|
|
@@ -360,9 +363,15 @@ export function useStsWizard(slug) {
|
|
|
360
363
|
setMutedState(value);
|
|
361
364
|
playerRef.current?.setMuted(value);
|
|
362
365
|
}, []);
|
|
366
|
+
/** Call from a step's button (ctaLabel / ctaUrl): counts the click in your dashboard. */
|
|
367
|
+
const clicked = useCallback((clickedStep) => {
|
|
368
|
+
if (wizard)
|
|
369
|
+
client.wizard.report(wizard.slug, 'click', clickedStep.id);
|
|
370
|
+
}, [client, wizard]);
|
|
363
371
|
return {
|
|
364
372
|
wizard,
|
|
365
373
|
ready: Boolean(wizard),
|
|
374
|
+
clicked,
|
|
366
375
|
start,
|
|
367
376
|
follow,
|
|
368
377
|
savedSound,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which tour plays on which page of your website. A tour's page is a path (`/pricing`) or a
|
|
3
|
+
* pattern for pages that share one layout (`/blog/*`). The most specific match wins.
|
|
4
|
+
*/
|
|
5
|
+
/** `/pricing/` → `/pricing`; query and hash dropped. */
|
|
6
|
+
export declare function cleanPath(pathname: string): string;
|
|
7
|
+
export declare function pageMatches(pattern: string, pathname: string): boolean;
|
|
8
|
+
/** The tour for this page: an exact path beats a pattern, a longer pattern beats a shorter one. */
|
|
9
|
+
export declare function tourForPage<T extends {
|
|
10
|
+
pagePath: string | null;
|
|
11
|
+
}>(tours: T[], pathname: string): T | null;
|
|
12
|
+
/** The tour spots on this page: every `data-sts-step` name, in page order. */
|
|
13
|
+
export declare function sectionsOnPage(): string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which tour plays on which page of your website. A tour's page is a path (`/pricing`) or a
|
|
3
|
+
* pattern for pages that share one layout (`/blog/*`). The most specific match wins.
|
|
4
|
+
*/
|
|
5
|
+
/** `/pricing/` → `/pricing`; query and hash dropped. */
|
|
6
|
+
export function cleanPath(pathname) {
|
|
7
|
+
const path = pathname.split(/[?#]/)[0] || '/';
|
|
8
|
+
return path.length > 1 ? path.replace(/\/+$/u, '') || '/' : '/';
|
|
9
|
+
}
|
|
10
|
+
export function pageMatches(pattern, pathname) {
|
|
11
|
+
const path = cleanPath(pathname);
|
|
12
|
+
if (pattern.endsWith('/*')) {
|
|
13
|
+
const base = pattern.slice(0, -2);
|
|
14
|
+
return path.startsWith(`${base}/`) && path.length > base.length + 1;
|
|
15
|
+
}
|
|
16
|
+
return cleanPath(pattern) === path;
|
|
17
|
+
}
|
|
18
|
+
/** The tour for this page: an exact path beats a pattern, a longer pattern beats a shorter one. */
|
|
19
|
+
export function tourForPage(tours, pathname) {
|
|
20
|
+
const matches = tours.filter((tour) => tour.pagePath && pageMatches(tour.pagePath, pathname));
|
|
21
|
+
matches.sort((a, b) => {
|
|
22
|
+
const exactA = a.pagePath.endsWith('/*') ? 0 : 1;
|
|
23
|
+
const exactB = b.pagePath.endsWith('/*') ? 0 : 1;
|
|
24
|
+
return exactB - exactA || b.pagePath.length - a.pagePath.length;
|
|
25
|
+
});
|
|
26
|
+
return matches[0] ?? null;
|
|
27
|
+
}
|
|
28
|
+
/** The tour spots on this page: every `data-sts-step` name, in page order. */
|
|
29
|
+
export function sectionsOnPage() {
|
|
30
|
+
if (typeof document === 'undefined')
|
|
31
|
+
return [];
|
|
32
|
+
const names = Array.from(document.querySelectorAll('[data-sts-step]')).map((el) => el.dataset.stsStep ?? '');
|
|
33
|
+
return [...new Set(names.filter((name) => /^[\w-]{1,60}$/u.test(name)))].slice(0, 50);
|
|
34
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -71,10 +71,12 @@ export type StsSessionInfo = {
|
|
|
71
71
|
chat: StsChatConfig | null;
|
|
72
72
|
speak: StsSpeakConfig | null;
|
|
73
73
|
form: StsForm | null;
|
|
74
|
+
/** Published website tours, one per page (`pagePath`: `/pricing`, or a pattern like `/blog/*`). */
|
|
74
75
|
wizards: {
|
|
75
76
|
slug: string;
|
|
76
77
|
name: string;
|
|
77
78
|
language: string;
|
|
79
|
+
pagePath: string | null;
|
|
78
80
|
}[];
|
|
79
81
|
};
|
|
80
82
|
};
|
package/dist/vue.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare function useStsForm(): {
|
|
|
62
62
|
submit: () => Promise<void>;
|
|
63
63
|
};
|
|
64
64
|
/**
|
|
65
|
-
* The voice tour
|
|
65
|
+
* The voice tour for this page of your website (one tour per page, set in Support → Tour). Tag sections with `data-sts-step="…"` and style
|
|
66
66
|
* `[data-sts-active]`. `follow()` speaks each section as the visitor scrolls to it; `play('pricing')`
|
|
67
67
|
* speaks one step from your own event.
|
|
68
68
|
*/
|
|
@@ -84,6 +84,8 @@ export declare function useStsWizard(slug?: string): {
|
|
|
84
84
|
unlock: () => void | undefined;
|
|
85
85
|
stop: () => void;
|
|
86
86
|
setMuted: (value: boolean) => void | undefined;
|
|
87
|
+
/** Call from a step's button (ctaLabel / ctaUrl): counts the click in your dashboard. */
|
|
88
|
+
clicked: (clickedStep: StsWizardStep) => void;
|
|
87
89
|
};
|
|
88
90
|
/** Business details (name, description, profile) for your own about or footer block. */
|
|
89
91
|
export declare function useStsBusiness(): {
|
package/dist/vue.js
CHANGED
|
@@ -115,7 +115,7 @@ export function useStsForm() {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
* The voice tour
|
|
118
|
+
* The voice tour for this page of your website (one tour per page, set in Support → Tour). Tag sections with `data-sts-step="…"` and style
|
|
119
119
|
* `[data-sts-active]`. `follow()` speaks each section as the visitor scrolls to it; `play('pricing')`
|
|
120
120
|
* speaks one step from your own event.
|
|
121
121
|
*/
|
|
@@ -127,16 +127,9 @@ export function useStsWizard(slug) {
|
|
|
127
127
|
const speaking = shallowRef(false);
|
|
128
128
|
const playing = shallowRef(false);
|
|
129
129
|
let player = null;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const first = info.services.wizards[0]?.slug;
|
|
134
|
-
if (!first)
|
|
135
|
-
throw new Error('No published tour for this business');
|
|
136
|
-
return first;
|
|
137
|
-
});
|
|
138
|
-
slugReady
|
|
139
|
-
.then((value) => client.wizard.load(value))
|
|
130
|
+
// Each page of your website has its own tour: the one for this page, unless you name one.
|
|
131
|
+
client.wizard.reportPage();
|
|
132
|
+
(slug ? client.wizard.load(slug) : client.wizard.forPage())
|
|
140
133
|
.then((value) => {
|
|
141
134
|
wizard.value = value;
|
|
142
135
|
})
|
|
@@ -150,12 +143,14 @@ export function useStsWizard(slug) {
|
|
|
150
143
|
player = createWizardPlayer(wizard.value, {
|
|
151
144
|
onStep: (current) => {
|
|
152
145
|
step.value = current;
|
|
146
|
+
client.wizard.report(wizard.value?.slug ?? '', 'step', current.id);
|
|
153
147
|
},
|
|
154
148
|
onSpeakingChange: (value) => {
|
|
155
149
|
speaking.value = value;
|
|
156
150
|
},
|
|
157
151
|
onEnd: () => {
|
|
158
152
|
playing.value = false;
|
|
153
|
+
client.wizard.report(wizard.value?.slug ?? '', 'finish');
|
|
159
154
|
},
|
|
160
155
|
});
|
|
161
156
|
}
|
|
@@ -189,6 +184,11 @@ export function useStsWizard(slug) {
|
|
|
189
184
|
playing.value = false;
|
|
190
185
|
},
|
|
191
186
|
setMuted: (value) => ensurePlayer()?.setMuted(value),
|
|
187
|
+
/** Call from a step's button (ctaLabel / ctaUrl): counts the click in your dashboard. */
|
|
188
|
+
clicked: (clickedStep) => {
|
|
189
|
+
if (wizard.value)
|
|
190
|
+
client.wizard.report(wizard.value.slug, 'click', clickedStep.id);
|
|
191
|
+
},
|
|
192
192
|
};
|
|
193
193
|
}
|
|
194
194
|
/** Business details (name, description, profile) for your own about or footer block. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sts-ai/sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "One package for every sts-ai service on your own website: Chat AI, Voice AI, Form, Tour and business details. Your design, our services. React, Vue/Nuxt or plain JavaScript.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|