@sts-ai/sdk 0.0.0-stage → 1.0.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 +195 -2
- package/dist/controllers.d.ts +79 -0
- package/dist/controllers.js +204 -0
- package/dist/core.d.ts +38 -0
- package/dist/core.js +126 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/react.d.ts +113 -0
- package/dist/react.js +440 -0
- package/dist/types.d.ts +275 -0
- package/dist/types.js +9 -0
- package/dist/vue.d.ts +110 -0
- package/dist/vue.js +211 -0
- package/dist/wizardPlayer.d.ts +38 -0
- package/dist/wizardPlayer.js +242 -0
- package/package.json +70 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
export type StsOptions = {
|
|
2
|
+
/** Your STS-AI app URL, e.g. https://app.sts-ai.com */
|
|
3
|
+
apiBase: string;
|
|
4
|
+
/** Publishable site key (sts_pk_live_…). Safe in the browser; only works on your allowed website. */
|
|
5
|
+
siteKey: string;
|
|
6
|
+
};
|
|
7
|
+
/** `select` is a multiple-choice question; `multiple` says whether several answers are allowed. */
|
|
8
|
+
export type FormFieldType = 'text' | 'textarea' | 'email' | 'phone' | 'number' | 'url' | 'date' | 'select' | 'yesno' | 'rating';
|
|
9
|
+
/** Brand colour picked in the dashboard, as a hex string (e.g. "#8b5cf6"). */
|
|
10
|
+
export type StsAccent = string;
|
|
11
|
+
export type StsFormField = {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
type: FormFieldType;
|
|
15
|
+
required: boolean;
|
|
16
|
+
options: string[];
|
|
17
|
+
/** `select` only: several choices may be picked (send them as a string array). */
|
|
18
|
+
multiple: boolean;
|
|
19
|
+
/** `rating` only: 5 = 1–5 stars, 10 = a 0–10 scale. Send the score as a string. */
|
|
20
|
+
scale: 5 | 10;
|
|
21
|
+
placeholder: string;
|
|
22
|
+
helpText: string;
|
|
23
|
+
};
|
|
24
|
+
/** One answer: a string, or a string array for a multi-answer `select` question. */
|
|
25
|
+
export type StsFormAnswer = string | string[];
|
|
26
|
+
export type StsForm = {
|
|
27
|
+
title: string;
|
|
28
|
+
description: string;
|
|
29
|
+
fields: StsFormField[];
|
|
30
|
+
consentText: string;
|
|
31
|
+
submitLabel: string;
|
|
32
|
+
successMessage: string;
|
|
33
|
+
accent: StsAccent;
|
|
34
|
+
/** Background of the hosted form; use it as a hint for your own design. */
|
|
35
|
+
theme: 'light' | 'dark';
|
|
36
|
+
/** Send the visitor here after a successful submit, when set. */
|
|
37
|
+
redirectUrl: string | null;
|
|
38
|
+
};
|
|
39
|
+
export type StsChatConfig = {
|
|
40
|
+
greeting: string;
|
|
41
|
+
suggestions: string[];
|
|
42
|
+
maxMessageLength: number;
|
|
43
|
+
includeLinks: boolean;
|
|
44
|
+
/** Name for your chat header. */
|
|
45
|
+
assistantName: string;
|
|
46
|
+
inputPlaceholder: string;
|
|
47
|
+
/** Show this when a reply fails. */
|
|
48
|
+
fallbackMessage: string;
|
|
49
|
+
showHumanHandoff: boolean;
|
|
50
|
+
/** Documents the assistant may ask for. Show an attach button when this is not empty. */
|
|
51
|
+
documentRequests: StsDocumentRequest[];
|
|
52
|
+
accent: StsAccent;
|
|
53
|
+
};
|
|
54
|
+
export type StsSpeakConfig = {
|
|
55
|
+
maxCallMinutes: number;
|
|
56
|
+
firstMessage: string | null;
|
|
57
|
+
language: 'en' | 'bn';
|
|
58
|
+
callButtonLabel: string;
|
|
59
|
+
/** Warn the caller this many seconds before the limit (0 = no warning). */
|
|
60
|
+
endWarningSeconds: number;
|
|
61
|
+
showHumanHandoff: boolean;
|
|
62
|
+
};
|
|
63
|
+
export type StsSessionInfo = {
|
|
64
|
+
business: {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string | null;
|
|
67
|
+
aiName: string | null;
|
|
68
|
+
};
|
|
69
|
+
/** `null` = that service is turned off in the STS-AI dashboard. */
|
|
70
|
+
services: {
|
|
71
|
+
chat: StsChatConfig | null;
|
|
72
|
+
speak: StsSpeakConfig | null;
|
|
73
|
+
form: StsForm | null;
|
|
74
|
+
wizards: {
|
|
75
|
+
slug: string;
|
|
76
|
+
name: string;
|
|
77
|
+
language: string;
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export type StsChatLinks = {
|
|
82
|
+
products: {
|
|
83
|
+
name: string;
|
|
84
|
+
url: string;
|
|
85
|
+
buyUrl?: string;
|
|
86
|
+
}[];
|
|
87
|
+
buyNow: string | null;
|
|
88
|
+
social: {
|
|
89
|
+
platform: string;
|
|
90
|
+
label: string;
|
|
91
|
+
url?: string;
|
|
92
|
+
}[];
|
|
93
|
+
} | null;
|
|
94
|
+
export type StsChatReply = {
|
|
95
|
+
reply: string;
|
|
96
|
+
links: StsChatLinks;
|
|
97
|
+
};
|
|
98
|
+
/** One question customers ask and the business's own answer to it. */
|
|
99
|
+
export type StsAnswer = {
|
|
100
|
+
question: string;
|
|
101
|
+
answer: string;
|
|
102
|
+
};
|
|
103
|
+
/** A review the business chose to show. `name` is the customer's first name only. */
|
|
104
|
+
export type StsReview = {
|
|
105
|
+
name: string;
|
|
106
|
+
rating: number;
|
|
107
|
+
text: string;
|
|
108
|
+
date: string | null;
|
|
109
|
+
};
|
|
110
|
+
/** A document the chat may ask for. `accept` tells your file picker what to allow. */
|
|
111
|
+
export type StsDocumentRequest = {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
when: string;
|
|
115
|
+
accept: 'pdf' | 'image' | 'any';
|
|
116
|
+
};
|
|
117
|
+
/** A file saved to the business's Google Drive. `message` is what to send next in the chat. */
|
|
118
|
+
export type StsChatUpload = {
|
|
119
|
+
ok: true;
|
|
120
|
+
file: {
|
|
121
|
+
name: string;
|
|
122
|
+
url: string | null;
|
|
123
|
+
};
|
|
124
|
+
message: string;
|
|
125
|
+
};
|
|
126
|
+
export type StsSpeakConnection = {
|
|
127
|
+
serverUrl: string;
|
|
128
|
+
roomName: string;
|
|
129
|
+
participantName: string;
|
|
130
|
+
participantToken: string;
|
|
131
|
+
maxCallMinutes: number;
|
|
132
|
+
};
|
|
133
|
+
export type StsWizardStep = {
|
|
134
|
+
id: string;
|
|
135
|
+
heading: string;
|
|
136
|
+
body: string;
|
|
137
|
+
narration: string;
|
|
138
|
+
/** `data-sts-step` value of the section on your page, if set. */
|
|
139
|
+
target: string | null;
|
|
140
|
+
ctaLabel: string | null;
|
|
141
|
+
ctaUrl: string | null;
|
|
142
|
+
audioUrl: string | null;
|
|
143
|
+
};
|
|
144
|
+
export type StsWizard = {
|
|
145
|
+
slug: string;
|
|
146
|
+
name: string;
|
|
147
|
+
guideName: string;
|
|
148
|
+
language: 'en' | 'bn';
|
|
149
|
+
steps: StsWizardStep[];
|
|
150
|
+
};
|
|
151
|
+
/** A document customers need (Docs). serviceIds ties it to Menu services ("Used for"); may be empty. */
|
|
152
|
+
export type StsDoc = {
|
|
153
|
+
id: string;
|
|
154
|
+
name: string;
|
|
155
|
+
formCode: string;
|
|
156
|
+
issuer: string;
|
|
157
|
+
pdfUrl: string;
|
|
158
|
+
serviceIds: string[];
|
|
159
|
+
};
|
|
160
|
+
/** One entry on the Menu. Products you sell online come as `offers` instead. */
|
|
161
|
+
export type StsBusinessService = {
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
category: string;
|
|
165
|
+
summary: string;
|
|
166
|
+
price: string;
|
|
167
|
+
};
|
|
168
|
+
/** A product or project from Projects, with every way to order that is on. */
|
|
169
|
+
export type StsOffer = {
|
|
170
|
+
title: string;
|
|
171
|
+
description: string | null;
|
|
172
|
+
kind: 'PRODUCT' | 'PROJECT';
|
|
173
|
+
featured: boolean;
|
|
174
|
+
/** The single link to use for one button. */
|
|
175
|
+
primaryUrl: string;
|
|
176
|
+
links: {
|
|
177
|
+
share: string | null;
|
|
178
|
+
pay: string | null;
|
|
179
|
+
live: string | null;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** An upcoming or running live session (a webinar from Projects). */
|
|
183
|
+
export type StsLiveSession = {
|
|
184
|
+
slug: string;
|
|
185
|
+
title: string;
|
|
186
|
+
description: string | null;
|
|
187
|
+
thumbnail: string | null;
|
|
188
|
+
/** ISO times. */
|
|
189
|
+
startsAt: string;
|
|
190
|
+
endsAt: string | null;
|
|
191
|
+
status: 'scheduled' | 'waiting' | 'live';
|
|
192
|
+
/** Waiting room with a countdown, then the session. */
|
|
193
|
+
joinUrl: string;
|
|
194
|
+
/** Sign up or buy first, when that way to order is on. */
|
|
195
|
+
shareUrl: string | null;
|
|
196
|
+
};
|
|
197
|
+
/** Contact: how visitors reach the business, plus the footer's tagline and legal links. */
|
|
198
|
+
export type StsContactCard = {
|
|
199
|
+
email: string;
|
|
200
|
+
phone: string;
|
|
201
|
+
address: string;
|
|
202
|
+
hours: string;
|
|
203
|
+
mapUrl: string;
|
|
204
|
+
credentials: string[];
|
|
205
|
+
tagline: string;
|
|
206
|
+
copyright: string;
|
|
207
|
+
privacyUrl: string;
|
|
208
|
+
termsUrl: string;
|
|
209
|
+
};
|
|
210
|
+
export type StsBusinessSite = {
|
|
211
|
+
seo: {
|
|
212
|
+
title: string;
|
|
213
|
+
description: string;
|
|
214
|
+
ogImage: string;
|
|
215
|
+
};
|
|
216
|
+
services: StsBusinessService[];
|
|
217
|
+
docs: StsDoc[];
|
|
218
|
+
/** Live settings: the heading and button text to use around `business.live`. */
|
|
219
|
+
live: {
|
|
220
|
+
enabled: boolean;
|
|
221
|
+
title: string;
|
|
222
|
+
joinLabel: string;
|
|
223
|
+
maxSessions: number;
|
|
224
|
+
};
|
|
225
|
+
keyDates: {
|
|
226
|
+
id: string;
|
|
227
|
+
date: string;
|
|
228
|
+
title: string;
|
|
229
|
+
}[];
|
|
230
|
+
social: {
|
|
231
|
+
followLabel: string;
|
|
232
|
+
accounts: {
|
|
233
|
+
id: string;
|
|
234
|
+
platform: string;
|
|
235
|
+
handle: string;
|
|
236
|
+
url: string;
|
|
237
|
+
}[];
|
|
238
|
+
};
|
|
239
|
+
footer: StsContactCard;
|
|
240
|
+
appearance: {
|
|
241
|
+
accent: StsAccent;
|
|
242
|
+
heroAlign: 'center' | 'left';
|
|
243
|
+
show: {
|
|
244
|
+
offers: boolean;
|
|
245
|
+
services: boolean;
|
|
246
|
+
keyDates: boolean;
|
|
247
|
+
social: boolean;
|
|
248
|
+
terms: boolean;
|
|
249
|
+
};
|
|
250
|
+
actions: {
|
|
251
|
+
chat: boolean;
|
|
252
|
+
speak: boolean;
|
|
253
|
+
form: boolean;
|
|
254
|
+
wizard: boolean;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
export type StsBusiness = {
|
|
259
|
+
name: string;
|
|
260
|
+
description: string | null;
|
|
261
|
+
profile: Record<string, unknown> | null;
|
|
262
|
+
publishedAt: string | null;
|
|
263
|
+
/** Products and projects from Projects (added automatically when created). Empty until published. */
|
|
264
|
+
offers: StsOffer[];
|
|
265
|
+
/** Live: upcoming and running webinars with a Join link, soonest first. Empty until published. */
|
|
266
|
+
live: StsLiveSession[];
|
|
267
|
+
/** Published content from Messages → Business; null until the business is published. */
|
|
268
|
+
site: StsBusinessSite | null;
|
|
269
|
+
};
|
|
270
|
+
export declare class StsError extends Error {
|
|
271
|
+
readonly code: string;
|
|
272
|
+
readonly status: number;
|
|
273
|
+
readonly fieldId: string | null;
|
|
274
|
+
constructor(message: string, code: string, status: number, fieldId?: string | null);
|
|
275
|
+
}
|
package/dist/types.js
ADDED
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue 3 / Nuxt 3 bindings. Install the plugin once, then use the composables in any component;
|
|
3
|
+
* every value is a ref your own design binds to.
|
|
4
|
+
*
|
|
5
|
+
* // Nuxt: plugins/sts-ai.client.ts (the sts-ai CLI writes this for you)
|
|
6
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
7
|
+
* nuxtApp.vueApp.use(createStsPlugin({ apiBase: 'https://sudotechserve.com', siteKey: 'sts_pk_live_…' }))
|
|
8
|
+
* })
|
|
9
|
+
*
|
|
10
|
+
* // any component
|
|
11
|
+
* const { messages, send, status } = useStsChat()
|
|
12
|
+
*/
|
|
13
|
+
import { type App } from 'vue';
|
|
14
|
+
import { type StsClient } from './core.js';
|
|
15
|
+
import type { StsAnswer, StsBusiness, StsOptions, StsReview, StsSessionInfo, StsWizard, StsWizardStep } from './types.js';
|
|
16
|
+
/** `app.use(createStsPlugin({ apiBase, siteKey }))`: one client for the whole site. */
|
|
17
|
+
export declare function createStsPlugin(options: StsOptions): {
|
|
18
|
+
install(app: App): void;
|
|
19
|
+
};
|
|
20
|
+
export declare function useSts(): StsClient;
|
|
21
|
+
/** Business name + which services are turned on in sts-ai. */
|
|
22
|
+
export declare function useStsInfo(): {
|
|
23
|
+
info: import("vue").ShallowRef<StsSessionInfo | null, StsSessionInfo | null>;
|
|
24
|
+
error: import("vue").ShallowRef<string | null, string | null>;
|
|
25
|
+
};
|
|
26
|
+
/** Chat AI as a service, for your own floating button, pop-up or page. */
|
|
27
|
+
export declare function useStsChat(): {
|
|
28
|
+
/** false when Chat AI is off in sts-ai. */
|
|
29
|
+
available: import("vue").ComputedRef<boolean>;
|
|
30
|
+
greeting: import("vue").ComputedRef<string>;
|
|
31
|
+
suggestions: import("vue").ComputedRef<string[]>;
|
|
32
|
+
documentRequests: import("vue").ComputedRef<import("./types.js").StsDocumentRequest[]>;
|
|
33
|
+
messages: import("vue").ComputedRef<import("./controllers.js").StsChatMessage[]>;
|
|
34
|
+
status: import("vue").ComputedRef<"idle" | "thinking" | "error">;
|
|
35
|
+
error: import("vue").ComputedRef<string | null>;
|
|
36
|
+
send: (text: string) => Promise<void>;
|
|
37
|
+
attach: (file: File, documentId?: string) => Promise<void>;
|
|
38
|
+
reset: () => void;
|
|
39
|
+
};
|
|
40
|
+
/** Voice AI as a service: call `start()` from your orb or button; `agentLevel` animates it. */
|
|
41
|
+
export declare function useStsSpeak(): {
|
|
42
|
+
state: import("vue").ComputedRef<"live" | "idle" | "error" | "connecting" | "ended">;
|
|
43
|
+
isAgentSpeaking: import("vue").ComputedRef<boolean>;
|
|
44
|
+
muted: import("vue").ComputedRef<boolean>;
|
|
45
|
+
captions: import("vue").ComputedRef<import("./controllers.js").StsCaption[]>;
|
|
46
|
+
agentLevel: import("vue").ComputedRef<number>;
|
|
47
|
+
error: import("vue").ComputedRef<string | null>;
|
|
48
|
+
start: (participantName?: string) => Promise<void>;
|
|
49
|
+
stop: () => Promise<void>;
|
|
50
|
+
setMuted: (value: boolean) => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
/** The business's form as a service: your fields and layout, its questions and inbox. */
|
|
53
|
+
export declare function useStsForm(): {
|
|
54
|
+
form: import("vue").ComputedRef<import("./types.js").StsForm | null>;
|
|
55
|
+
values: import("vue").ComputedRef<Record<string, import("./types.js").StsFormAnswer>>;
|
|
56
|
+
consent: import("vue").ComputedRef<boolean>;
|
|
57
|
+
status: import("vue").ComputedRef<"error" | "loading" | "ready" | "submitting" | "success" | "unavailable">;
|
|
58
|
+
message: import("vue").ComputedRef<string | null>;
|
|
59
|
+
fieldError: import("vue").ComputedRef<string | null>;
|
|
60
|
+
setValue: (fieldId: string, value: import("./types.js").StsFormAnswer) => void;
|
|
61
|
+
setConsent: (consent: boolean) => void;
|
|
62
|
+
submit: () => Promise<void>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The voice tour on your own page. Tag sections with `data-sts-step="…"` and style
|
|
66
|
+
* `[data-sts-active]`. `follow()` speaks each section as the visitor scrolls to it; `play('pricing')`
|
|
67
|
+
* speaks one step from your own event.
|
|
68
|
+
*/
|
|
69
|
+
export declare function useStsWizard(slug?: string): {
|
|
70
|
+
wizard: import("vue").ShallowRef<StsWizard | null, StsWizard | null>;
|
|
71
|
+
ready: import("vue").ComputedRef<boolean>;
|
|
72
|
+
step: import("vue").ShallowRef<StsWizardStep | null, StsWizardStep | null>;
|
|
73
|
+
caption: import("vue").ComputedRef<string>;
|
|
74
|
+
speaking: import("vue").ShallowRef<boolean, boolean>;
|
|
75
|
+
playing: import("vue").ShallowRef<boolean, boolean>;
|
|
76
|
+
error: import("vue").ShallowRef<string | null, string | null>;
|
|
77
|
+
/** The tour leads: scrolls to each section and narrates it. Call from a click. */
|
|
78
|
+
start: () => void;
|
|
79
|
+
/** The visitor leads: each section speaks when they scroll to it. Call from a click first. */
|
|
80
|
+
follow: () => void;
|
|
81
|
+
/** One step from your own event, by id or `data-sts-step` name. */
|
|
82
|
+
play: (name: string) => boolean;
|
|
83
|
+
/** Call from any click so later `play()` calls can make sound. */
|
|
84
|
+
unlock: () => void | undefined;
|
|
85
|
+
stop: () => void;
|
|
86
|
+
setMuted: (value: boolean) => void | undefined;
|
|
87
|
+
};
|
|
88
|
+
/** Business details (name, description, profile) for your own about or footer block. */
|
|
89
|
+
export declare function useStsBusiness(): {
|
|
90
|
+
business: import("vue").ShallowRef<StsBusiness | null, StsBusiness | null>;
|
|
91
|
+
error: import("vue").ShallowRef<string | null, string | null>;
|
|
92
|
+
ready: import("vue").ComputedRef<boolean>;
|
|
93
|
+
};
|
|
94
|
+
/** The business's own answers, for an FAQ block. */
|
|
95
|
+
export declare function useStsAnswers(): {
|
|
96
|
+
answers: import("vue").ComputedRef<StsAnswer[]>;
|
|
97
|
+
error: import("vue").ShallowRef<string | null, string | null>;
|
|
98
|
+
ready: import("vue").ComputedRef<boolean>;
|
|
99
|
+
};
|
|
100
|
+
/** Reviews the business chose to show. */
|
|
101
|
+
export declare function useStsReviews(): {
|
|
102
|
+
reviews: import("vue").ComputedRef<StsReview[]>;
|
|
103
|
+
error: import("vue").ShallowRef<string | null, string | null>;
|
|
104
|
+
ready: import("vue").ComputedRef<boolean>;
|
|
105
|
+
};
|
|
106
|
+
declare module 'vue' {
|
|
107
|
+
interface ComponentCustomProperties {
|
|
108
|
+
$sts: StsClient;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue 3 / Nuxt 3 bindings. Install the plugin once, then use the composables in any component;
|
|
3
|
+
* every value is a ref your own design binds to.
|
|
4
|
+
*
|
|
5
|
+
* // Nuxt: plugins/sts-ai.client.ts (the sts-ai CLI writes this for you)
|
|
6
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
7
|
+
* nuxtApp.vueApp.use(createStsPlugin({ apiBase: 'https://sudotechserve.com', siteKey: 'sts_pk_live_…' }))
|
|
8
|
+
* })
|
|
9
|
+
*
|
|
10
|
+
* // any component
|
|
11
|
+
* const { messages, send, status } = useStsChat()
|
|
12
|
+
*/
|
|
13
|
+
import { computed, inject, onScopeDispose, shallowRef } from 'vue';
|
|
14
|
+
import { createSts } from './core.js';
|
|
15
|
+
import { createChat, createForm, createVoice } from './controllers.js';
|
|
16
|
+
import { createWizardPlayer } from './wizardPlayer.js';
|
|
17
|
+
const STS_KEY = Symbol('sts-ai');
|
|
18
|
+
/** `app.use(createStsPlugin({ apiBase, siteKey }))`: one client for the whole site. */
|
|
19
|
+
export function createStsPlugin(options) {
|
|
20
|
+
return {
|
|
21
|
+
install(app) {
|
|
22
|
+
const client = createSts(options);
|
|
23
|
+
app.provide(STS_KEY, client);
|
|
24
|
+
app.config.globalProperties.$sts = client;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function useSts() {
|
|
29
|
+
const client = inject(STS_KEY, null);
|
|
30
|
+
if (!client)
|
|
31
|
+
throw new Error('Install the sts-ai plugin first: app.use(createStsPlugin({ apiBase, siteKey }))');
|
|
32
|
+
return client;
|
|
33
|
+
}
|
|
34
|
+
const errorMessage = (error) => (error instanceof Error ? error.message : 'Something went wrong');
|
|
35
|
+
/** A ref that follows a controller, unsubscribed when the component goes away. */
|
|
36
|
+
function follow(subscribe) {
|
|
37
|
+
const value = shallowRef();
|
|
38
|
+
const off = subscribe((state) => {
|
|
39
|
+
value.value = state;
|
|
40
|
+
});
|
|
41
|
+
onScopeDispose(off);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
/** Loads something once into a ref (null until it arrives). */
|
|
45
|
+
function load(task) {
|
|
46
|
+
const data = shallowRef(null);
|
|
47
|
+
const error = shallowRef(null);
|
|
48
|
+
task()
|
|
49
|
+
.then((value) => {
|
|
50
|
+
data.value = value;
|
|
51
|
+
})
|
|
52
|
+
.catch((err) => {
|
|
53
|
+
error.value = errorMessage(err);
|
|
54
|
+
});
|
|
55
|
+
return { data, error, ready: computed(() => data.value !== null) };
|
|
56
|
+
}
|
|
57
|
+
/** Business name + which services are turned on in sts-ai. */
|
|
58
|
+
export function useStsInfo() {
|
|
59
|
+
const client = useSts();
|
|
60
|
+
const { data, error } = load(() => client.info());
|
|
61
|
+
return { info: data, error };
|
|
62
|
+
}
|
|
63
|
+
/** Chat AI as a service, for your own floating button, pop-up or page. */
|
|
64
|
+
export function useStsChat() {
|
|
65
|
+
const client = useSts();
|
|
66
|
+
const chat = createChat(client);
|
|
67
|
+
const state = follow(chat.subscribe);
|
|
68
|
+
const { info, error: infoError } = useStsInfo();
|
|
69
|
+
const config = computed(() => info.value?.services.chat ?? null);
|
|
70
|
+
return {
|
|
71
|
+
/** false when Chat AI is off in sts-ai. */
|
|
72
|
+
available: computed(() => Boolean(config.value)),
|
|
73
|
+
greeting: computed(() => config.value?.greeting ?? ''),
|
|
74
|
+
suggestions: computed(() => config.value?.suggestions ?? []),
|
|
75
|
+
documentRequests: computed(() => config.value?.documentRequests ?? []),
|
|
76
|
+
messages: computed(() => state.value.messages),
|
|
77
|
+
status: computed(() => state.value.status),
|
|
78
|
+
error: computed(() => state.value.error ?? infoError.value),
|
|
79
|
+
send: chat.send,
|
|
80
|
+
attach: chat.attach,
|
|
81
|
+
reset: chat.reset,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Voice AI as a service: call `start()` from your orb or button; `agentLevel` animates it. */
|
|
85
|
+
export function useStsSpeak() {
|
|
86
|
+
const voice = createVoice(useSts());
|
|
87
|
+
const state = follow(voice.subscribe);
|
|
88
|
+
onScopeDispose(() => void voice.stop());
|
|
89
|
+
return {
|
|
90
|
+
state: computed(() => state.value.state),
|
|
91
|
+
isAgentSpeaking: computed(() => state.value.isAgentSpeaking),
|
|
92
|
+
muted: computed(() => state.value.muted),
|
|
93
|
+
captions: computed(() => state.value.captions),
|
|
94
|
+
agentLevel: computed(() => state.value.agentLevel),
|
|
95
|
+
error: computed(() => state.value.error),
|
|
96
|
+
start: voice.start,
|
|
97
|
+
stop: voice.stop,
|
|
98
|
+
setMuted: voice.setMuted,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** The business's form as a service: your fields and layout, its questions and inbox. */
|
|
102
|
+
export function useStsForm() {
|
|
103
|
+
const form = createForm(useSts());
|
|
104
|
+
const state = follow(form.subscribe);
|
|
105
|
+
return {
|
|
106
|
+
form: computed(() => state.value.form),
|
|
107
|
+
values: computed(() => state.value.values),
|
|
108
|
+
consent: computed(() => state.value.consent),
|
|
109
|
+
status: computed(() => state.value.status),
|
|
110
|
+
message: computed(() => state.value.message),
|
|
111
|
+
fieldError: computed(() => state.value.fieldError),
|
|
112
|
+
setValue: form.setValue,
|
|
113
|
+
setConsent: form.setConsent,
|
|
114
|
+
submit: form.submit,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The voice tour on your own page. Tag sections with `data-sts-step="…"` and style
|
|
119
|
+
* `[data-sts-active]`. `follow()` speaks each section as the visitor scrolls to it; `play('pricing')`
|
|
120
|
+
* speaks one step from your own event.
|
|
121
|
+
*/
|
|
122
|
+
export function useStsWizard(slug) {
|
|
123
|
+
const client = useSts();
|
|
124
|
+
const wizard = shallowRef(null);
|
|
125
|
+
const error = shallowRef(null);
|
|
126
|
+
const step = shallowRef(null);
|
|
127
|
+
const speaking = shallowRef(false);
|
|
128
|
+
const playing = shallowRef(false);
|
|
129
|
+
let player = null;
|
|
130
|
+
const slugReady = slug
|
|
131
|
+
? Promise.resolve(slug)
|
|
132
|
+
: client.info().then((info) => {
|
|
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))
|
|
140
|
+
.then((value) => {
|
|
141
|
+
wizard.value = value;
|
|
142
|
+
})
|
|
143
|
+
.catch((err) => {
|
|
144
|
+
error.value = errorMessage(err);
|
|
145
|
+
});
|
|
146
|
+
function ensurePlayer() {
|
|
147
|
+
if (!wizard.value)
|
|
148
|
+
return null;
|
|
149
|
+
if (!player) {
|
|
150
|
+
player = createWizardPlayer(wizard.value, {
|
|
151
|
+
onStep: (current) => {
|
|
152
|
+
step.value = current;
|
|
153
|
+
},
|
|
154
|
+
onSpeakingChange: (value) => {
|
|
155
|
+
speaking.value = value;
|
|
156
|
+
},
|
|
157
|
+
onEnd: () => {
|
|
158
|
+
playing.value = false;
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return player;
|
|
163
|
+
}
|
|
164
|
+
onScopeDispose(() => player?.stop());
|
|
165
|
+
return {
|
|
166
|
+
wizard,
|
|
167
|
+
ready: computed(() => Boolean(wizard.value)),
|
|
168
|
+
step,
|
|
169
|
+
caption: computed(() => step.value?.narration ?? ''),
|
|
170
|
+
speaking,
|
|
171
|
+
playing,
|
|
172
|
+
error,
|
|
173
|
+
/** The tour leads: scrolls to each section and narrates it. Call from a click. */
|
|
174
|
+
start: () => {
|
|
175
|
+
playing.value = true;
|
|
176
|
+
ensurePlayer()?.start();
|
|
177
|
+
},
|
|
178
|
+
/** The visitor leads: each section speaks when they scroll to it. Call from a click first. */
|
|
179
|
+
follow: () => {
|
|
180
|
+
playing.value = true;
|
|
181
|
+
ensurePlayer()?.follow();
|
|
182
|
+
},
|
|
183
|
+
/** One step from your own event, by id or `data-sts-step` name. */
|
|
184
|
+
play: (name) => ensurePlayer()?.play(name) ?? false,
|
|
185
|
+
/** Call from any click so later `play()` calls can make sound. */
|
|
186
|
+
unlock: () => ensurePlayer()?.unlock(),
|
|
187
|
+
stop: () => {
|
|
188
|
+
player?.stop();
|
|
189
|
+
playing.value = false;
|
|
190
|
+
},
|
|
191
|
+
setMuted: (value) => ensurePlayer()?.setMuted(value),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** Business details (name, description, profile) for your own about or footer block. */
|
|
195
|
+
export function useStsBusiness() {
|
|
196
|
+
const client = useSts();
|
|
197
|
+
const { data, error, ready } = load(() => client.business.get());
|
|
198
|
+
return { business: data, error, ready };
|
|
199
|
+
}
|
|
200
|
+
/** The business's own answers, for an FAQ block. */
|
|
201
|
+
export function useStsAnswers() {
|
|
202
|
+
const client = useSts();
|
|
203
|
+
const { data, error, ready } = load(() => client.business.answers());
|
|
204
|
+
return { answers: computed(() => data.value ?? []), error, ready };
|
|
205
|
+
}
|
|
206
|
+
/** Reviews the business chose to show. */
|
|
207
|
+
export function useStsReviews() {
|
|
208
|
+
const client = useSts();
|
|
209
|
+
const { data, error, ready } = load(() => client.business.reviews());
|
|
210
|
+
return { reviews: computed(() => data.value ?? []), error, ready };
|
|
211
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { StsWizard, StsWizardStep } from './types.js';
|
|
2
|
+
export type WizardPlayerEvents = {
|
|
3
|
+
onStep?: (step: StsWizardStep, index: number) => void;
|
|
4
|
+
onSpeakingChange?: (speaking: boolean) => void;
|
|
5
|
+
onEnd?: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Plays a tour on the creator's own page, marking the active `[data-sts-step]` section with
|
|
9
|
+
* `data-sts-active` (style it however you like). Two ways to run it:
|
|
10
|
+
* - `start()`: the tour leads. It scrolls to each section in turn and narrates it.
|
|
11
|
+
* - `follow()`: the visitor leads. Nothing scrolls; each section's step plays once, when the
|
|
12
|
+
* visitor scrolls it into the middle of the screen. A step with no target plays at the start.
|
|
13
|
+
* Steps whose target is missing on this page are skipped, so one tour can cover many pages.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createWizardPlayer(wizard: StsWizard, events?: WizardPlayerEvents): {
|
|
16
|
+
readonly steps: StsWizardStep[];
|
|
17
|
+
/** The tour leads. Call from a click handler (browsers block audio without a user gesture). */
|
|
18
|
+
start(index?: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* The visitor leads. Call from a click handler the first time so sound is allowed. Call it
|
|
21
|
+
* again after your site changes page without a reload, to pick up that page's sections.
|
|
22
|
+
*/
|
|
23
|
+
follow(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Plays one step from your own code, by its id or its `data-sts-step` name, for example from
|
|
26
|
+
* `window.addEventListener('my-event', () => tour.play('pricing'))`. Browsers only allow sound
|
|
27
|
+
* after the visitor clicked once on the page, so start or follow the tour from a click first
|
|
28
|
+
* (or call `unlock()` from any click). Returns false when there is no such step.
|
|
29
|
+
*/
|
|
30
|
+
play(step: string): boolean;
|
|
31
|
+
/** Call from any click to allow sound for steps you play later with `play()`. */
|
|
32
|
+
unlock(): void;
|
|
33
|
+
/** Lets every step play again, for example when the visitor restarts the tour. */
|
|
34
|
+
reset(): void;
|
|
35
|
+
stop(): void;
|
|
36
|
+
setMuted(value: boolean): void;
|
|
37
|
+
};
|
|
38
|
+
export type WizardPlayer = ReturnType<typeof createWizardPlayer>;
|