@mushi-mushi/web 1.14.0 → 1.16.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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiLeaderboardEntry, MushiCrossAppReport, MushiTesterReputation, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
1
+ import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiAssistantReply, MushiWidgetConfig, MushiLeaderboardEntry, MushiCrossAppReport, MushiTesterReputation, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
2
2
  export { MushiApiCascadeConfig, MushiConfig, MushiConsoleEntry, MushiDiagnosticsResult, MushiEnvironment, MushiEventHandler, MushiEventType, MushiNetworkEntry, MushiPerformanceMetrics, MushiReport, MushiReportCategory, MushiSDKInstance, MushiTimelineEntry, MushiTimelineKind, MushiUrlMatcher, MushiWidgetConfig } from '@mushi-mushi/core';
3
3
 
4
4
  declare class Mushi {
@@ -10,18 +10,33 @@ declare class Mushi {
10
10
  }
11
11
 
12
12
  /**
13
- * FILE: packages/web/src/widget.ts
14
- * PURPOSE: The bug-capture widget — floating trigger + multi-step report
15
- * panel — that mounts into a customer's app via `Mushi.init()`.
13
+ * FILE: packages/web/src/widget-helpers.ts
14
+ * PURPOSE: Stateless helpers, constants, and shared types for the bug-capture
15
+ * widget. Extracted verbatim from widget.ts to keep that file focused
16
+ * on the MushiWidget class (DOM structure, state, lifecycle).
16
17
  *
17
- * DESIGN: Visual styling lives in `./styles.ts` ("Mushi Mushi Editorial":
18
- * paper + sumi ink + 朱 vermillion, serif display + monospace
19
- * metadata, ledger-style step counter, hanko stamp animation on
20
- * success). This file owns the DOM structure, state, and all
21
- * user-facing ARIA / keyboard wiring.
18
+ * OVERVIEW:
19
+ * - Pure functions: reporter-status copy mappers, relative-time formatting,
20
+ * the step-number padder, the submit-shortcut detector, and HTML escaping.
21
+ * - Constants: category icon map, the feature-request intent wire string, the
22
+ * total step count, and the per-step ledger number.
23
+ * - Shared types: WidgetStep, the reporter status tone union, and the public
24
+ * WidgetRewardsState / WidgetSubmitOutcome / WidgetCallbacks contracts (these
25
+ * three are re-exported from widget.ts so existing `./widget` import sites and
26
+ * the package barrel keep working unchanged).
27
+ *
28
+ * DEPENDENCIES:
29
+ * - @mushi-mushi/core — report / reporter wire types referenced by the contracts.
30
+ *
31
+ * USAGE:
32
+ * - Imported by widget.ts (the MushiWidget class) and widget-render.ts (the
33
+ * stateless view layer). No DOM/browser state lives here.
34
+ *
35
+ * NOTES:
36
+ * - Behaviour-preserving move: bodies are identical to the pre-split widget.ts.
22
37
  */
23
38
 
24
- type WidgetStep = 'category' | 'intent' | 'details' | 'success' | 'reports' | 'report-detail' | 'leaderboard' | 'roadmap' | 'account' | 'cross-app-reports';
39
+ type WidgetStep = 'category' | 'intent' | 'details' | 'success' | 'reports' | 'report-detail' | 'leaderboard' | 'roadmap' | 'account' | 'cross-app-reports' | 'assistant';
25
40
  interface WidgetRewardsState {
26
41
  tier: {
27
42
  slug: string;
@@ -86,7 +101,19 @@ interface WidgetCallbacks {
86
101
  onGlobalLeaderboardOpen?(): void;
87
102
  /** Fetch cross-app reports for the signed-in tester. */
88
103
  onCrossAppReportsOpen?(): void;
104
+ /** Called when the user signs out of the in-widget community session.
105
+ * Host should clear any persisted tester JWT. */
106
+ onTesterSignOut?(): void;
107
+ /** Whether the assistant tab should be shown at all. */
108
+ assistantEnabled?: boolean;
109
+ /** Tab label + greeting + starter suggestions for the empty thread. */
110
+ assistantLabel?: string;
111
+ assistantGreeting?: string;
112
+ assistantSuggestions?: string[];
113
+ /** Send one assistant turn; resolves with the structured reply. */
114
+ onAssistantAsk?(message: string, threadId: string | null): Promise<MushiAssistantReply | null>;
89
115
  }
116
+
90
117
  declare class MushiWidget {
91
118
  private readonly sdkVersion;
92
119
  private host;
@@ -183,6 +210,11 @@ declare class MushiWidget {
183
210
  private magicLinkSent;
184
211
  private magicLinkEmail;
185
212
  private magicLinkError;
213
+ private magicLinkSending;
214
+ private assistantTurns;
215
+ private assistantThreadId;
216
+ private assistantSending;
217
+ private assistantError;
186
218
  constructor(config: MushiWidgetConfig | undefined, callbacks: WidgetCallbacks, sdkVersion?: string);
187
219
  mount(): void;
188
220
  getIsMounted(): boolean;
@@ -203,6 +235,10 @@ declare class MushiWidget {
203
235
  featureRequest?: boolean;
204
236
  }): void;
205
237
  close(): void;
238
+ /** Open the panel directly on the assistant ("Ask") tab. */
239
+ openAssistantTab(): void;
240
+ /** Send one assistant turn and re-render as the reply streams back. */
241
+ sendAssistantMessage(message: string): Promise<void>;
206
242
  /**
207
243
  * Briefly highlight the trigger button (a soft pulse + tooltip) without
208
244
  * opening the full reporter panel. Use for first-session welcome nudges
@@ -307,6 +343,11 @@ declare class MushiWidget {
307
343
  * sticky nav bars, and sign-in CTAs.
308
344
  */
309
345
  private computeAvoidTopPx;
346
+ /**
347
+ * Minimum bottom-offset in px so a bottom-anchored trigger clears avoided
348
+ * elements (tab bars, fixed CTAs). Mirrors {@link computeAvoidTopPx}.
349
+ */
350
+ private computeAvoidBottomPx;
310
351
  private applyInsetVars;
311
352
  /** Storage key for the FAB position, scoped to projectId when available. */
312
353
  private fabStorageKey;
@@ -325,91 +366,20 @@ declare class MushiWidget {
325
366
  /** Lift the panel above the software keyboard using visualViewport. */
326
367
  private attachViewportHandlers;
327
368
  private teardownViewportHandlers;
328
- private renderStep;
329
- private renderOutdatedBanner;
330
- private renderBrandFooter;
331
- /**
332
- * Editorial masthead. Always carries:
333
- * • the brand mark (虫 kanji on vermillion, "MUSHI" in mono above)
334
- * • the page title (serif display)
335
- * • the close affordance
336
- *
337
- * On sub-steps it additionally renders a back button (replacing the
338
- * "MUSHI" eyebrow with a "← BACK" mono link) and a step counter
339
- * ledger ("02 / 03") on the far right.
340
- */
341
- private renderHeader;
342
- /**
343
- * Numeral step indicator: "01 — 02 — 03", with the active step in
344
- * vermillion serif and completed steps struck through in mono.
345
- * Replaces the original three-dot indicator (a generic SaaS pattern).
346
- */
347
- private renderStepIndicator;
348
- private renderCategoryStep;
349
369
  /**
350
- * First-class "Feature request" entry rendered at the top of the
351
- * category step. Beta apps consistently get more useful signal when
352
- * the user has a no-friction path to say "I wish this did X" — burying
353
- * it as an intent under the "Other" category drops feature submissions
354
- * by ~40% in industry studies (Userpilot, Usersnap 2025).
355
- *
356
- * Wire format: still routes through the standard `other` category with
357
- * a `user_category = 'Feature request'` stamp, so we don't need a DB
358
- * migration. The admin console filters on that string to surface the
359
- * Feature-request swimlane.
370
+ * Minimum description length, lowered for CJK locales where each character
371
+ * carries more meaning. Used by both the view layer (via renderCtx) and the
372
+ * details-step input validation in attachHandlers.
360
373
  */
361
- private renderFeatureRequestEntry;
362
- /** Collapsible "What's new" changelog row. Closes the reporter feedback loop. */
363
- private renderBetaChangelog;
364
- /**
365
- * Discreet beta status strip: communicates "work in progress", invites
366
- * feedback, and sets expectations — reducing user frustration while
367
- * nudging the reciprocity instinct ("your reports help us build this").
368
- */
369
- private renderBetaStrip;
370
- private renderReportsStep;
371
- private renderRoadmapStep;
372
- private renderLeaderboardStep;
373
- private renderAccountStep;
374
- private renderCrossAppReportsStep;
375
- private renderReportDetailStep;
376
- private renderIntentStep;
377
374
  private effectiveMinLength;
378
- private renderDetailsStep;
379
- /**
380
- * Editorial success state: 朱印-style red stamp ring with the kanji
381
- * 受 ("received") at its centre, the localised "thank you" string
382
- * in serif below, and a mono ledger receipt ("REPORT · HH:MM:SS").
383
- * The ring + label animations are defined in styles.ts so this stays
384
- * pure markup and `prefers-reduced-motion` flips them to the final
385
- * frame instantly.
386
- */
387
- private renderSuccessStep;
388
- /**
389
- * Two-way receipt block. Until the host's `onSubmit` resolves with a
390
- * server-confirmed report id, we show a discreet "delivering..." pill so
391
- * the user knows their submission is still in flight. Once we have the
392
- * id, we surface a short monospaced id + a copy button + an optional
393
- * "Track on Mushi" deep link to `dashboardUrl/reports/<id>` so the user
394
- * can watch the status walk through queued -> classified -> fixed in
395
- * real time (Peak-End rule: the last impression sticks). If we never
396
- * get an id (offline retry queue), we say so explicitly rather than
397
- * pretending everything is fine.
398
- */
399
- private renderSuccessReceipt;
400
- private renderSlaLine;
375
+ /** Tier accent colour for the rewards UI. */
376
+ private tierColor;
401
377
  /**
402
- * Reciprocity footer on the success step: closes the feedback loop by
403
- * attributing where the report goes, sets a response expectation, and
404
- * reinforces the "beta tester" identity (Peak-End Rule — the last thing
405
- * the user sees shapes their entire impression of the interaction).
378
+ * Build the read-only snapshot + bound helper closures the stateless view
379
+ * layer (widget-render.ts) renders from. Rebuilt once per render() pass so
380
+ * the HTML always reflects current state.
406
381
  */
407
- private renderBetaSuccessFooter;
408
- private tierColor;
409
- /** Compact rewards nudge rendered at the bottom of the category-step body. */
410
- private renderRewardsNudge;
411
- /** Points earned + tier progress shown on the success step. */
412
- private renderSuccessRewards;
382
+ private renderCtx;
413
383
  private attachHandlers;
414
384
  private trapFocus;
415
385
  private unreadCount;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiWidgetConfig, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiLeaderboardEntry, MushiCrossAppReport, MushiTesterReputation, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
1
+ import { MushiConfig, MushiSDKInstance, MushiDiagnosticsResult, MushiReportCategory, MushiReporterReport, MushiReporterComment, MushiAssistantReply, MushiWidgetConfig, MushiLeaderboardEntry, MushiCrossAppReport, MushiTesterReputation, MushiConsoleEntry, MushiNetworkEntry, MushiUrlMatcher, MushiTracePropagationConfig, MushiPrivacyConfig, MushiPerformanceMetrics, MushiSelectedElement, MushiTimelineEntry, MushiApiCascadeConfig } from '@mushi-mushi/core';
2
2
  export { MushiApiCascadeConfig, MushiConfig, MushiConsoleEntry, MushiDiagnosticsResult, MushiEnvironment, MushiEventHandler, MushiEventType, MushiNetworkEntry, MushiPerformanceMetrics, MushiReport, MushiReportCategory, MushiSDKInstance, MushiTimelineEntry, MushiTimelineKind, MushiUrlMatcher, MushiWidgetConfig } from '@mushi-mushi/core';
3
3
 
4
4
  declare class Mushi {
@@ -10,18 +10,33 @@ declare class Mushi {
10
10
  }
11
11
 
12
12
  /**
13
- * FILE: packages/web/src/widget.ts
14
- * PURPOSE: The bug-capture widget — floating trigger + multi-step report
15
- * panel — that mounts into a customer's app via `Mushi.init()`.
13
+ * FILE: packages/web/src/widget-helpers.ts
14
+ * PURPOSE: Stateless helpers, constants, and shared types for the bug-capture
15
+ * widget. Extracted verbatim from widget.ts to keep that file focused
16
+ * on the MushiWidget class (DOM structure, state, lifecycle).
16
17
  *
17
- * DESIGN: Visual styling lives in `./styles.ts` ("Mushi Mushi Editorial":
18
- * paper + sumi ink + 朱 vermillion, serif display + monospace
19
- * metadata, ledger-style step counter, hanko stamp animation on
20
- * success). This file owns the DOM structure, state, and all
21
- * user-facing ARIA / keyboard wiring.
18
+ * OVERVIEW:
19
+ * - Pure functions: reporter-status copy mappers, relative-time formatting,
20
+ * the step-number padder, the submit-shortcut detector, and HTML escaping.
21
+ * - Constants: category icon map, the feature-request intent wire string, the
22
+ * total step count, and the per-step ledger number.
23
+ * - Shared types: WidgetStep, the reporter status tone union, and the public
24
+ * WidgetRewardsState / WidgetSubmitOutcome / WidgetCallbacks contracts (these
25
+ * three are re-exported from widget.ts so existing `./widget` import sites and
26
+ * the package barrel keep working unchanged).
27
+ *
28
+ * DEPENDENCIES:
29
+ * - @mushi-mushi/core — report / reporter wire types referenced by the contracts.
30
+ *
31
+ * USAGE:
32
+ * - Imported by widget.ts (the MushiWidget class) and widget-render.ts (the
33
+ * stateless view layer). No DOM/browser state lives here.
34
+ *
35
+ * NOTES:
36
+ * - Behaviour-preserving move: bodies are identical to the pre-split widget.ts.
22
37
  */
23
38
 
24
- type WidgetStep = 'category' | 'intent' | 'details' | 'success' | 'reports' | 'report-detail' | 'leaderboard' | 'roadmap' | 'account' | 'cross-app-reports';
39
+ type WidgetStep = 'category' | 'intent' | 'details' | 'success' | 'reports' | 'report-detail' | 'leaderboard' | 'roadmap' | 'account' | 'cross-app-reports' | 'assistant';
25
40
  interface WidgetRewardsState {
26
41
  tier: {
27
42
  slug: string;
@@ -86,7 +101,19 @@ interface WidgetCallbacks {
86
101
  onGlobalLeaderboardOpen?(): void;
87
102
  /** Fetch cross-app reports for the signed-in tester. */
88
103
  onCrossAppReportsOpen?(): void;
104
+ /** Called when the user signs out of the in-widget community session.
105
+ * Host should clear any persisted tester JWT. */
106
+ onTesterSignOut?(): void;
107
+ /** Whether the assistant tab should be shown at all. */
108
+ assistantEnabled?: boolean;
109
+ /** Tab label + greeting + starter suggestions for the empty thread. */
110
+ assistantLabel?: string;
111
+ assistantGreeting?: string;
112
+ assistantSuggestions?: string[];
113
+ /** Send one assistant turn; resolves with the structured reply. */
114
+ onAssistantAsk?(message: string, threadId: string | null): Promise<MushiAssistantReply | null>;
89
115
  }
116
+
90
117
  declare class MushiWidget {
91
118
  private readonly sdkVersion;
92
119
  private host;
@@ -183,6 +210,11 @@ declare class MushiWidget {
183
210
  private magicLinkSent;
184
211
  private magicLinkEmail;
185
212
  private magicLinkError;
213
+ private magicLinkSending;
214
+ private assistantTurns;
215
+ private assistantThreadId;
216
+ private assistantSending;
217
+ private assistantError;
186
218
  constructor(config: MushiWidgetConfig | undefined, callbacks: WidgetCallbacks, sdkVersion?: string);
187
219
  mount(): void;
188
220
  getIsMounted(): boolean;
@@ -203,6 +235,10 @@ declare class MushiWidget {
203
235
  featureRequest?: boolean;
204
236
  }): void;
205
237
  close(): void;
238
+ /** Open the panel directly on the assistant ("Ask") tab. */
239
+ openAssistantTab(): void;
240
+ /** Send one assistant turn and re-render as the reply streams back. */
241
+ sendAssistantMessage(message: string): Promise<void>;
206
242
  /**
207
243
  * Briefly highlight the trigger button (a soft pulse + tooltip) without
208
244
  * opening the full reporter panel. Use for first-session welcome nudges
@@ -307,6 +343,11 @@ declare class MushiWidget {
307
343
  * sticky nav bars, and sign-in CTAs.
308
344
  */
309
345
  private computeAvoidTopPx;
346
+ /**
347
+ * Minimum bottom-offset in px so a bottom-anchored trigger clears avoided
348
+ * elements (tab bars, fixed CTAs). Mirrors {@link computeAvoidTopPx}.
349
+ */
350
+ private computeAvoidBottomPx;
310
351
  private applyInsetVars;
311
352
  /** Storage key for the FAB position, scoped to projectId when available. */
312
353
  private fabStorageKey;
@@ -325,91 +366,20 @@ declare class MushiWidget {
325
366
  /** Lift the panel above the software keyboard using visualViewport. */
326
367
  private attachViewportHandlers;
327
368
  private teardownViewportHandlers;
328
- private renderStep;
329
- private renderOutdatedBanner;
330
- private renderBrandFooter;
331
- /**
332
- * Editorial masthead. Always carries:
333
- * • the brand mark (虫 kanji on vermillion, "MUSHI" in mono above)
334
- * • the page title (serif display)
335
- * • the close affordance
336
- *
337
- * On sub-steps it additionally renders a back button (replacing the
338
- * "MUSHI" eyebrow with a "← BACK" mono link) and a step counter
339
- * ledger ("02 / 03") on the far right.
340
- */
341
- private renderHeader;
342
- /**
343
- * Numeral step indicator: "01 — 02 — 03", with the active step in
344
- * vermillion serif and completed steps struck through in mono.
345
- * Replaces the original three-dot indicator (a generic SaaS pattern).
346
- */
347
- private renderStepIndicator;
348
- private renderCategoryStep;
349
369
  /**
350
- * First-class "Feature request" entry rendered at the top of the
351
- * category step. Beta apps consistently get more useful signal when
352
- * the user has a no-friction path to say "I wish this did X" — burying
353
- * it as an intent under the "Other" category drops feature submissions
354
- * by ~40% in industry studies (Userpilot, Usersnap 2025).
355
- *
356
- * Wire format: still routes through the standard `other` category with
357
- * a `user_category = 'Feature request'` stamp, so we don't need a DB
358
- * migration. The admin console filters on that string to surface the
359
- * Feature-request swimlane.
370
+ * Minimum description length, lowered for CJK locales where each character
371
+ * carries more meaning. Used by both the view layer (via renderCtx) and the
372
+ * details-step input validation in attachHandlers.
360
373
  */
361
- private renderFeatureRequestEntry;
362
- /** Collapsible "What's new" changelog row. Closes the reporter feedback loop. */
363
- private renderBetaChangelog;
364
- /**
365
- * Discreet beta status strip: communicates "work in progress", invites
366
- * feedback, and sets expectations — reducing user frustration while
367
- * nudging the reciprocity instinct ("your reports help us build this").
368
- */
369
- private renderBetaStrip;
370
- private renderReportsStep;
371
- private renderRoadmapStep;
372
- private renderLeaderboardStep;
373
- private renderAccountStep;
374
- private renderCrossAppReportsStep;
375
- private renderReportDetailStep;
376
- private renderIntentStep;
377
374
  private effectiveMinLength;
378
- private renderDetailsStep;
379
- /**
380
- * Editorial success state: 朱印-style red stamp ring with the kanji
381
- * 受 ("received") at its centre, the localised "thank you" string
382
- * in serif below, and a mono ledger receipt ("REPORT · HH:MM:SS").
383
- * The ring + label animations are defined in styles.ts so this stays
384
- * pure markup and `prefers-reduced-motion` flips them to the final
385
- * frame instantly.
386
- */
387
- private renderSuccessStep;
388
- /**
389
- * Two-way receipt block. Until the host's `onSubmit` resolves with a
390
- * server-confirmed report id, we show a discreet "delivering..." pill so
391
- * the user knows their submission is still in flight. Once we have the
392
- * id, we surface a short monospaced id + a copy button + an optional
393
- * "Track on Mushi" deep link to `dashboardUrl/reports/<id>` so the user
394
- * can watch the status walk through queued -> classified -> fixed in
395
- * real time (Peak-End rule: the last impression sticks). If we never
396
- * get an id (offline retry queue), we say so explicitly rather than
397
- * pretending everything is fine.
398
- */
399
- private renderSuccessReceipt;
400
- private renderSlaLine;
375
+ /** Tier accent colour for the rewards UI. */
376
+ private tierColor;
401
377
  /**
402
- * Reciprocity footer on the success step: closes the feedback loop by
403
- * attributing where the report goes, sets a response expectation, and
404
- * reinforces the "beta tester" identity (Peak-End Rule — the last thing
405
- * the user sees shapes their entire impression of the interaction).
378
+ * Build the read-only snapshot + bound helper closures the stateless view
379
+ * layer (widget-render.ts) renders from. Rebuilt once per render() pass so
380
+ * the HTML always reflects current state.
406
381
  */
407
- private renderBetaSuccessFooter;
408
- private tierColor;
409
- /** Compact rewards nudge rendered at the bottom of the category-step body. */
410
- private renderRewardsNudge;
411
- /** Points earned + tier progress shown on the success step. */
412
- private renderSuccessRewards;
382
+ private renderCtx;
413
383
  private attachHandlers;
414
384
  private trapFocus;
415
385
  private unreadCount;