@cms.ai/brand_brain 0.0.1

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/src/types.ts ADDED
@@ -0,0 +1,316 @@
1
+ // This package is deliberately self-contained: it imports NO types from
2
+ // @navless/types. That package is a barrel (`export *` over dozens of modules),
3
+ // so importing any symbol drags the whole surface into the bundled .d.ts and the
4
+ // dts bundler chokes on it. The wire-protocol enums below are stable contracts,
5
+ // hand-mirrored here so the published package has zero @navless/* runtime deps
6
+ // and a self-contained declaration file.
7
+
8
+ /** AG-UI protocol frame types written by the guide SSE stream. */
9
+ export const SSEMessageType = {
10
+ RunStarted: "RUN_STARTED",
11
+ RunFinished: "RUN_FINISHED",
12
+ RunError: "RUN_ERROR",
13
+ TextMessageStart: "TEXT_MESSAGE_START",
14
+ TextMessageContent: "TEXT_MESSAGE_CONTENT",
15
+ TextMessageEnd: "TEXT_MESSAGE_END",
16
+ Custom: "CUSTOM",
17
+ } as const;
18
+ export type SSEMessageTypeName = (typeof SSEMessageType)[keyof typeof SSEMessageType];
19
+
20
+ /** The `name` on `CUSTOM` guide events (skill payloads). */
21
+ export const GuideEvent = {
22
+ SkillStart: "skill_start",
23
+ SkillContent: "skill_content",
24
+ SkillDocuments: "skill_documents",
25
+ SkillRecommendations: "skill_recommendations",
26
+ SkillCTAs: "skill_ctas",
27
+ SkillDiagnoseHeader: "skill_diagnose_header",
28
+ SkillDiagnoseQuestion: "skill_diagnose_question",
29
+ SkillPlaylistItems: "skill_playlist_items",
30
+ SkillPlaylistHeader: "skill_playlist_header",
31
+ SkillPlaylistRationale: "skill_playlist_rationale",
32
+ SkillHowToOutline: "skill_howto_outline",
33
+ SkillHowToSteps: "skill_howto_steps",
34
+ SkillBusinessCaseChooser: "skill_businesscase_chooser",
35
+ SkillBusinessCaseDelta: "skill_businesscase_delta",
36
+ SkillSolutionDesignHeader: "skill_solutiondesign_header",
37
+ SkillSolutionDesignDiagram: "skill_solutiondesign_diagram",
38
+ SkillEnd: "skill_end",
39
+ SkillError: "skill_error",
40
+ SkillGate: "skill_gate",
41
+ InputSuggestions: "input_suggestions",
42
+ } as const;
43
+ export type GuideEventName = (typeof GuideEvent)[keyof typeof GuideEvent];
44
+
45
+ /** The guide skill types. `answer` is always on; the rest are enabled per-guide. */
46
+ export const SkillResponseType = {
47
+ Answer: "answer",
48
+ HowTo: "howto",
49
+ Diagnose: "diagnose",
50
+ Recommend: "recommend",
51
+ Playlist: "playlist",
52
+ BusinessCase: "businesscase",
53
+ SolutionDesign: "solutiondesign",
54
+ } as const;
55
+ export type SkillResponseTypeType = (typeof SkillResponseType)[keyof typeof SkillResponseType];
56
+
57
+ /** Consent tiers. `essential` is always granted server-side. */
58
+ export const ConsentTier = {
59
+ Essential: "essential",
60
+ Functional: "functional",
61
+ Analytical: "analytical",
62
+ } as const;
63
+ export type ConsentTierName = (typeof ConsentTier)[keyof typeof ConsentTier];
64
+
65
+ /** Analytics events fired by the SDK bootstrap. */
66
+ export const EmbedTrackingEvent = {
67
+ EmbedLoaded: "embed_loaded",
68
+ EmbedPageView: "embed_page_view",
69
+ EmbedTriggerClicked: "embed_trigger_clicked",
70
+ EmbedSideTabClicked: "embed_side_tab_clicked",
71
+ EmbedSideTabDismissed: "embed_side_tab_dismissed",
72
+ } as const;
73
+ export type EmbedTrackingEventName = (typeof EmbedTrackingEvent)[keyof typeof EmbedTrackingEvent];
74
+
75
+ /**
76
+ * The `eventType` passed to {@link GuideClient.track}. Any server-recognized
77
+ * event string is accepted — use an {@link EmbedTrackingEvent} member for the
78
+ * common cases.
79
+ */
80
+ export type TrackEventType = string;
81
+
82
+ /** Consent tiers a visitor can grant. `essential` is always granted server-side. */
83
+ export interface ConsentLevels {
84
+ functional?: boolean;
85
+ analytical?: boolean;
86
+ }
87
+
88
+ export interface ConsentFlags {
89
+ essential: boolean;
90
+ functional: boolean;
91
+ analytical: boolean;
92
+ }
93
+
94
+ /** Per-guide UI copy overrides. */
95
+ export interface GuideCustomization {
96
+ welcomeMessage?: string;
97
+ chatInputPlaceholders?: string[];
98
+ suggestionsTitle?: string;
99
+ helpTitle?: string;
100
+ pickUpWhereYouLeftOff?: string;
101
+ showGuideName?: boolean;
102
+ sideTabButtonText?: string;
103
+ pdfDisclaimerLine1?: string;
104
+ pdfDisclaimerLine2?: string;
105
+ pdfDownloadDescription?: string;
106
+ }
107
+
108
+ /** Lightweight knowledge-graph snapshot for page-load visualization. */
109
+ export interface GuideGraphSnapshot {
110
+ nodes: Array<{ id: string; name: string; type: string; tier: number }>;
111
+ edges: Array<{ from: string; to: string; relationship: string; strength: number }>;
112
+ }
113
+
114
+ /**
115
+ * Resolved guide metadata returned by `guides.resolve`. `theme` / `skillIconStyle`
116
+ * are left as `unknown` in v1 — read them defensively or narrow as needed.
117
+ */
118
+ export interface ResolvedGuide {
119
+ id: string;
120
+ name: string;
121
+ slug: string;
122
+ brandKitId: string | null;
123
+ magicLinkFormId: string | null;
124
+ accountId: string;
125
+ companyName: string;
126
+ gdprEnabled: boolean;
127
+ advancedSettings: { gatePdfDownload: boolean };
128
+ theme: unknown;
129
+ skillIconStyle: unknown;
130
+ faviconUrl: string | null;
131
+ logoUrl: string | null;
132
+ heroImageUrl: string | null;
133
+ customization: GuideCustomization | null;
134
+ graphSnapshot: GuideGraphSnapshot | null;
135
+ }
136
+
137
+ /** A conversation record. */
138
+ export interface Conversation {
139
+ id: string;
140
+ accountId: string;
141
+ guideId: string;
142
+ visitorId: string;
143
+ sessionId: string;
144
+ title: string | null;
145
+ createdAt: Date;
146
+ deletedAt: Date | null;
147
+ }
148
+
149
+ /** A persisted conversation message. */
150
+ export interface ConversationMessage {
151
+ id: string;
152
+ accountId: string;
153
+ conversationId: string;
154
+ role: "human" | "assistant";
155
+ content: string | null;
156
+ isSynthetic: boolean;
157
+ createdAt: Date;
158
+ deletedAt: Date | null;
159
+ }
160
+
161
+ /** A conversation plus a page of its messages. */
162
+ export interface ConversationWithMessages {
163
+ conversation: Conversation;
164
+ messages: ConversationMessage[];
165
+ }
166
+
167
+ /** A persisted skill deliverable. `data` shape varies by `type`. */
168
+ export interface SkillInstance {
169
+ id: string;
170
+ skillOutputId: string;
171
+ accountId: string;
172
+ conversationId: string;
173
+ type: SkillResponseTypeType;
174
+ visitorId: string;
175
+ sessionId: string;
176
+ title: string | null;
177
+ data: Record<string, unknown>;
178
+ surfacedCta: unknown;
179
+ sharedAt: Date | null;
180
+ createdAt: Date;
181
+ updatedAt: Date;
182
+ deletedAt: Date | null;
183
+ }
184
+
185
+ /** A skill instance as returned in history lists (no `data`/`surfacedCta`). */
186
+ export interface SkillHistoryInstance {
187
+ id: string;
188
+ skillOutputId: string;
189
+ accountId: string;
190
+ conversationId: string;
191
+ type: SkillResponseTypeType;
192
+ visitorId: string;
193
+ sessionId: string;
194
+ title: string | null;
195
+ sharedAt: Date | null;
196
+ createdAt: Date;
197
+ updatedAt: Date;
198
+ deletedAt: Date | null;
199
+ stepsCompleted: number | null;
200
+ totalSteps: number | null;
201
+ }
202
+
203
+ /** Skill history grouped by conversation. */
204
+ export interface SkillHistoryGroup {
205
+ conversationId: string;
206
+ conversationTitle: string | null;
207
+ latestActivityAt: Date;
208
+ instances: SkillHistoryInstance[];
209
+ }
210
+
211
+ export interface UpdateSkillInstanceResult {
212
+ id: string;
213
+ data: Record<string, unknown>;
214
+ updatedAt: Date;
215
+ }
216
+
217
+ export interface SelectDraftResult {
218
+ skillInstanceId: string | null;
219
+ }
220
+
221
+ export interface MarkSharedResult {
222
+ sharedAt: Date;
223
+ }
224
+
225
+ export interface ImportSharedResult {
226
+ skillInstanceId: string;
227
+ type: SkillResponseTypeType;
228
+ conversationId: string;
229
+ }
230
+
231
+ /** The current visitor's tracking + consent + email status. */
232
+ export interface VisitorStatus {
233
+ visitorId: string;
234
+ isTracked: boolean;
235
+ consent: { functional: boolean; analytical: boolean };
236
+ email: string | null;
237
+ verified: boolean;
238
+ }
239
+
240
+ /** Result of an email-gate submission. */
241
+ export interface SubmitGateResult {
242
+ success: boolean;
243
+ needsVerification: boolean;
244
+ }
245
+
246
+ /** Optional lead-capture fields beyond the ones the SDK fills automatically. */
247
+ export interface SubmitGateOptions {
248
+ redirectUrl?: string;
249
+ skill?: string;
250
+ prompt?: string;
251
+ skillInstanceId?: string;
252
+ hostUrl?: string;
253
+ requireVerification?: boolean;
254
+ downloadIntent?: boolean;
255
+ shareIntent?: boolean;
256
+ }
257
+
258
+ export interface InitGuideConfig {
259
+ /**
260
+ * Branded host origin the SDK talks to, e.g. "https://guide.acme.com". Must be
261
+ * on the customer's own root domain so the visitor cookies stay same-site.
262
+ * `/api/v3` is appended automatically.
263
+ */
264
+ baseUrl: string;
265
+ /** Guide slug to resolve (e.g. "default"). */
266
+ slug: string;
267
+ /**
268
+ * Host domain used for account resolution + attribution. Defaults to
269
+ * `window.location.hostname`. Required when running without a browser window.
270
+ */
271
+ domain?: string;
272
+ /**
273
+ * Consent handling on init:
274
+ * - `"auto"` (default): grant all tiers when the guide has GDPR disabled; wait
275
+ * for an explicit `setConsent()` when it is enabled.
276
+ * - explicit levels: submit these immediately.
277
+ * - `false`: submit nothing; call `setConsent()` yourself.
278
+ */
279
+ consent?: "auto" | ConsentLevels | false;
280
+ /** Fire an initial `embed_loaded` + page-view event on init. Default `true`. */
281
+ trackLoad?: boolean;
282
+ /**
283
+ * Custom fetch implementation (SSR/testing). Defaults to `globalThis.fetch`.
284
+ * `credentials: "include"` is always applied so visitor cookies ride along.
285
+ */
286
+ fetch?: typeof globalThis.fetch;
287
+ }
288
+
289
+ /** A message in the SDK's in-memory conversation history. */
290
+ export interface ChatMessage {
291
+ id: string;
292
+ role: "user" | "assistant";
293
+ content: string;
294
+ }
295
+
296
+ export interface AskOptions {
297
+ /** Force a specific skill, bypassing server-side LLM routing. */
298
+ forcedSkill?: SkillResponseTypeType;
299
+ /** Abort the in-flight stream. */
300
+ signal?: AbortSignal;
301
+ }
302
+
303
+ /**
304
+ * A single event yielded by {@link GuideClient.ask}. The common case is `text`
305
+ * (the streamed chat reply); `skill` carries every structured skill payload,
306
+ * discriminated by its {@link GuideEventName} `name`.
307
+ */
308
+ export type GuideStreamEvent =
309
+ | { type: "run-started"; runId: string }
310
+ | { type: "message-start"; messageId: string; role: string }
311
+ | { type: "text"; messageId: string; delta: string }
312
+ | { type: "message-end"; messageId: string }
313
+ | { type: "skill"; name: GuideEventName; value: Record<string, unknown> }
314
+ | { type: "gate"; skill: SkillResponseTypeType; prompt?: string; skillInstanceId?: string }
315
+ | { type: "error"; message: string; code?: string }
316
+ | { type: "run-finished"; finishReason?: string };