@kibee/contracts 0.2.0 → 0.8.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.mts CHANGED
@@ -1,3 +1,84 @@
1
+ type WidgetDockPreset = "bottom-right" | "bottom-left" | "top-right" | "top-left";
2
+ type WidgetDockPosition = WidgetDockPreset | {
3
+ preset: WidgetDockPreset;
4
+ offsetX?: number;
5
+ offsetY?: number;
6
+ };
7
+ type AvatarMode = "default" | "preset" | "custom" | "vector" | "lottie";
8
+ type AvatarPresetId = "orb" | "ring";
9
+ type AvatarMotion = "breathe" | "pulse" | "spin" | "none";
10
+ /** Relative path — embed apps fetch via API with publishable key (bucket URLs are often private). */
11
+ declare const WIDGET_AVATAR_PROXY_PATH = "/widget-avatar";
12
+ /** Query appended to WIDGET_AVATAR_PROXY_PATH to fetch the tenant's Lottie JSON. */
13
+ declare const WIDGET_AVATAR_LOTTIE_PROXY_PATH = "/widget-avatar?type=lottie";
14
+ type WidgetAvatarConfig = {
15
+ mode: "default";
16
+ } | {
17
+ mode: "preset";
18
+ preset: AvatarPresetId;
19
+ } | {
20
+ mode: "custom";
21
+ assetUrl: string;
22
+ } | {
23
+ mode: "vector";
24
+ svg: string;
25
+ motion: AvatarMotion;
26
+ color?: string;
27
+ } | {
28
+ mode: "lottie";
29
+ assetUrl: string;
30
+ motion: AvatarMotion;
31
+ };
32
+ interface WidgetConfigResponse {
33
+ dockPosition: WidgetDockPosition;
34
+ dockSize: number;
35
+ theme: {
36
+ primary: string;
37
+ tooltipBg: string;
38
+ tooltipColor: string;
39
+ };
40
+ avatar: WidgetAvatarConfig;
41
+ }
42
+ /** Flat keys persisted in tenants.settings JSONB */
43
+ interface WidgetSettingsRecord {
44
+ dockPosition?: WidgetDockPreset;
45
+ dockSize?: number;
46
+ primaryColor?: string;
47
+ tooltipBg?: string;
48
+ tooltipColor?: string;
49
+ avatarMode?: AvatarMode;
50
+ avatarPreset?: AvatarPresetId;
51
+ avatarAssetUrl?: string;
52
+ avatarAssetKey?: string;
53
+ avatarSvg?: string;
54
+ avatarColor?: string;
55
+ avatarLottieKey?: string;
56
+ avatarMotion?: AvatarMotion;
57
+ [key: string]: unknown;
58
+ }
59
+ declare function isAvatarMode(value: unknown): value is AvatarMode;
60
+ declare function isAvatarPresetId(value: unknown): value is AvatarPresetId;
61
+ declare function isAvatarMotion(value: unknown): value is AvatarMotion;
62
+ declare function isWidgetAvatarProxyUrl(url: string): boolean;
63
+ declare function parseWidgetAvatar(settings: WidgetSettingsRecord): WidgetAvatarConfig;
64
+ declare function buildWidgetConfigResponse(settings: WidgetSettingsRecord): WidgetConfigResponse;
65
+ /** Map widget avatar config to ThreeBeeRenderer constructor options. */
66
+ declare function resolveRendererAvatarOptions(avatar: WidgetAvatarConfig): {
67
+ avatarPreset: "bee" | AvatarPresetId;
68
+ assetUrl?: string;
69
+ };
70
+ type BeeVisualState = "idle" | "guiding" | "thinking" | "celebrating";
71
+ type AnimationSpec = {
72
+ kind: "css";
73
+ className: string | null;
74
+ } | {
75
+ kind: "lottie";
76
+ segment: string;
77
+ loop: boolean;
78
+ };
79
+ /** Per-state animation descriptor consumed by DomAvatarRenderer. */
80
+ declare function getAvatarStateAnimations(mode: "vector" | "lottie", motion: AvatarMotion): Record<BeeVisualState, AnimationSpec>;
81
+
1
82
  /**
2
83
  * Frozen Sprint 1 contract. Edits require joint sign-off from Track A
3
84
  * (broker) and Track B (macOS) leads.
@@ -168,6 +249,28 @@ interface IdentityResponse {
168
249
  issuedAt: number;
169
250
  }
170
251
 
252
+ /** Trust scope of a memory write. In Sprint 5, all writes hardcode "personal".
253
+ * Sprint 6 introduces the tenant-scoped writer during the `tenant:attach` flow. */
254
+ type MemoryScope = "personal" | "tenant-scoped";
255
+ /** A single recalled memory entry. Returned by `GET /v1/memory/recent`. */
256
+ interface MemoryRecallItem {
257
+ /** mem0 entry id — opaque, used as React key on the client. */
258
+ id: string;
259
+ /** mem0-derived short summary (e.g. "Asked about carbon credits on Carbon Hub"). */
260
+ topic: string;
261
+ /** Surface where the memory was recorded — drives the "On X yesterday" badge. */
262
+ surface: SurfaceId;
263
+ /** ISO 8601 timestamp of when the memory was created. */
264
+ capturedAt: string;
265
+ }
266
+ /** Response envelope for `GET /v1/memory/recent`. */
267
+ interface MemoryRecallResponse {
268
+ items: MemoryRecallItem[];
269
+ /** True when mem0 was unreachable / timed out and the items list is incomplete or empty.
270
+ * Clients should treat as empty (silent open) rather than show stale data. */
271
+ degraded?: boolean;
272
+ }
273
+
171
274
  type HighlightVariant = "pulse" | "ring" | "soft";
172
275
  interface TargetRef {
173
276
  kibeeId?: string;
@@ -583,6 +686,197 @@ interface WidgetConfig {
583
686
  tooltipBg: string;
584
687
  tooltipColor: string;
585
688
  };
689
+ avatar?: WidgetAvatarConfig;
690
+ }
691
+
692
+ /** A row in the per-workspace allowed-domains table. Shown in the admin UI
693
+ * and consumed by the bridge JWT auth path during the trust handshake. */
694
+ interface AllowedDomain {
695
+ id: string;
696
+ workspaceId: string;
697
+ /** Apex domain only (e.g. "acme.com"). Apex-matches subdomains at runtime. */
698
+ domain: string;
699
+ /** Auth0 sub of the admin who added this entry. */
700
+ createdBy: string;
701
+ /** ISO 8601. */
702
+ createdAt: string;
586
703
  }
704
+ /** Response for `GET /v1/workspace/allowlist/check?domain=X`.
705
+ * When >1 workspace allowlists the same domain for the same visitor,
706
+ * `workspaces` returns all matches and the macOS Buddy shows a picker. */
707
+ interface AllowlistCheckResponse {
708
+ allowed: boolean;
709
+ workspaces?: Array<{
710
+ id: string;
711
+ name: string;
712
+ }>;
713
+ }
714
+ /** Payload carried by `tenant:attach` and `tenant:detach` BridgeEnvelope.
715
+ * `attachedAt` mirrors the original attach time even on detach so telemetry
716
+ * can compute durationMs server-side. */
717
+ interface TenantAttachPayload {
718
+ workspaceId: string;
719
+ domain: string;
720
+ attachedAt: string;
721
+ }
722
+ /** Response for `GET /v1/tenant/flows`. Returns published flows for the
723
+ * workspace identified by `claims.tenantId` on the bridge JWT. */
724
+ interface TenantFlowsResponse {
725
+ flows: FlowDefinition[];
726
+ }
727
+ type FlowStep = {
728
+ kind: "web_tooltip";
729
+ selector: string;
730
+ instruction: string;
731
+ onPageId?: string;
732
+ } | {
733
+ kind: "desktop_click";
734
+ target: {
735
+ role: string;
736
+ label: string;
737
+ axPath: string;
738
+ };
739
+ modifiers: ReadonlyArray<"shift" | "control" | "option" | "command">;
740
+ description?: string;
741
+ fallbackCoord?: {
742
+ x: number;
743
+ y: number;
744
+ };
745
+ };
746
+ type CaptureStatus = "pending" | "promoted" | "rejected" | "withdrawn";
747
+ interface CaptureSummary {
748
+ id: string;
749
+ workspaceId: string;
750
+ captorVisitorId: string;
751
+ signature: string;
752
+ stepCount: number;
753
+ durationMs: number;
754
+ status: CaptureStatus;
755
+ promotedFlowId?: string;
756
+ rejectionReason?: string;
757
+ createdAt: string;
758
+ }
759
+ interface CaptureUploadPayload {
760
+ v: 2;
761
+ visitorId: string;
762
+ scope: "tenant-scoped";
763
+ capturedAt: string;
764
+ durationMs: number;
765
+ aborted: boolean;
766
+ steps: ReadonlyArray<{
767
+ ts: number;
768
+ type: "mousedown";
769
+ button: 0 | 1 | 2;
770
+ modifiers: ReadonlyArray<string>;
771
+ target: {
772
+ role: string;
773
+ label: string;
774
+ axPath: string;
775
+ };
776
+ fallbackCoord: {
777
+ x: number;
778
+ y: number;
779
+ };
780
+ }>;
781
+ }
782
+ interface CaptureUploadResponse {
783
+ captureId: string;
784
+ signature: string;
785
+ }
786
+ interface CaptureUploadEnvelope {
787
+ payload: CaptureUploadPayload;
788
+ warnings?: ReadonlyArray<string>;
789
+ }
790
+ interface CandidateGroup {
791
+ signature: string;
792
+ captures: ReadonlyArray<CaptureSummary>;
793
+ proposedTitle: string;
794
+ representativeId: string;
795
+ }
796
+ interface PromoteCandidatePayload {
797
+ editedSteps: ReadonlyArray<FlowStep>;
798
+ title: string;
799
+ pageId?: string;
800
+ audience?: string;
801
+ introMessage?: string;
802
+ replaceFlowId?: string;
803
+ }
804
+ type AuditAction = "capture.uploaded" | "capture.withdrawn" | "capture.promoted" | "capture.rejected" | "capture.edited" | "flag.flipped" | "slo.token.minted";
805
+ interface AuditEvent {
806
+ id: string;
807
+ workspaceId: string;
808
+ actor: {
809
+ kind: "visitor" | "admin" | "system";
810
+ id: string;
811
+ };
812
+ action: AuditAction;
813
+ target: {
814
+ kind: "capture" | "flow" | "flag";
815
+ id: string;
816
+ };
817
+ metadata?: Record<string, unknown>;
818
+ ts: string;
819
+ }
820
+ interface DiffPreview {
821
+ matchKind: "new" | "update";
822
+ matchedFlowId?: string;
823
+ matchedFlowTitle?: string;
824
+ stepDiff: ReadonlyArray<{
825
+ kind: "added" | "removed" | "changed" | "unchanged";
826
+ step: FlowStep;
827
+ }>;
828
+ }
829
+ interface FeatureFlag {
830
+ key: string;
831
+ defaultValue: boolean;
832
+ description: string;
833
+ createdAt: string;
834
+ updatedAt: string;
835
+ }
836
+ interface FeatureFlagOverride {
837
+ workspaceId: string;
838
+ key: string;
839
+ value: boolean;
840
+ createdAt: string;
841
+ updatedAt: string;
842
+ }
843
+ interface ResolvedFlagSet {
844
+ workspaceId: string;
845
+ flags: Record<string, boolean>;
846
+ fetchedAt: string;
847
+ }
848
+ interface SloWindow {
849
+ captureUploadSuccessRate: number;
850
+ captureUploadCount: number;
851
+ tenantAttachDeniedRate: number;
852
+ tenantAttachAttemptCount: number;
853
+ adminPromotionLatencyP50Ms: number;
854
+ adminPromotionLatencyP95Ms: number;
855
+ bridgeUptimePerVisitorMedian: number;
856
+ replayFallbackRate: number;
857
+ replayAttemptCount: number;
858
+ }
859
+ interface SloSnapshot {
860
+ computedAt: string;
861
+ workspaceId: string;
862
+ windows: {
863
+ last24h: SloWindow;
864
+ last7d: SloWindow;
865
+ };
866
+ }
867
+ declare const SLO_THRESHOLDS: {
868
+ readonly captureUploadSuccessRate: {
869
+ readonly min: 0.99;
870
+ };
871
+ readonly tenantAttachDeniedRate: {
872
+ readonly max: 0.01;
873
+ };
874
+ readonly adminPromotionLatencyP95Ms: {
875
+ readonly max: 2000;
876
+ };
877
+ readonly bridgeUptimePerVisitorMedian: {
878
+ readonly min: 0.99;
879
+ };
880
+ };
587
881
 
588
- export { type AdminSessionSummary, type AnalyticsEvent, BUDDY_TRANSITIONS, type BridgeClaims, type BridgeEnvelope, type BridgeEventType, type BuddyState, type ChatMessage, type ChatMode, type ChatSender, type CrossSiteFlowQueueItem, type CrossSiteFlowStep, type DockInlineAnchor, type DockPositionConfig, type DockPositionPreset, type EventMetadata, type FlowCommand, type FlowDefinition, type FlowMoveOptions, type HighlightVariant, type IdentityRequest, type IdentityResponse, type IntentMatch, type KiBeePairAccept, type KiBeePairReject, type KiBeePairRequest, type MessageTemplate, type PairingState, type PushFlowRequest, type PushTargetsRequest, type RecoveryRequest, type RecoveryResponse, type RegisteredTarget, type ResolveIntentRequest, type SessionState, type StartSessionRequest, type SurfaceId, type TargetRef, type TrackEventRequest, type VisibleTarget, type VisitorIdentity, type VisitorPollResponse, type WidgetConfig, canTransition, isBridgeEnvelope };
882
+ export { type AdminSessionSummary, type AllowedDomain, type AllowlistCheckResponse, type AnalyticsEvent, type AnimationSpec, type AuditAction, type AuditEvent, type AvatarMode, type AvatarMotion, type AvatarPresetId, BUDDY_TRANSITIONS, type BeeVisualState, type BridgeClaims, type BridgeEnvelope, type BridgeEventType, type BuddyState, type CandidateGroup, type CaptureStatus, type CaptureSummary, type CaptureUploadEnvelope, type CaptureUploadPayload, type CaptureUploadResponse, type ChatMessage, type ChatMode, type ChatSender, type CrossSiteFlowQueueItem, type CrossSiteFlowStep, type DiffPreview, type DockInlineAnchor, type DockPositionConfig, type DockPositionPreset, type EventMetadata, type FeatureFlag, type FeatureFlagOverride, type FlowCommand, type FlowDefinition, type FlowMoveOptions, type FlowStep, type HighlightVariant, type IdentityRequest, type IdentityResponse, type IntentMatch, type KiBeePairAccept, type KiBeePairReject, type KiBeePairRequest, type MemoryRecallItem, type MemoryRecallResponse, type MemoryScope, type MessageTemplate, type PairingState, type PromoteCandidatePayload, type PushFlowRequest, type PushTargetsRequest, type RecoveryRequest, type RecoveryResponse, type RegisteredTarget, type ResolveIntentRequest, type ResolvedFlagSet, SLO_THRESHOLDS, type SessionState, type SloSnapshot, type SloWindow, type StartSessionRequest, type SurfaceId, type TargetRef, type TenantAttachPayload, type TenantFlowsResponse, type TrackEventRequest, type VisibleTarget, type VisitorIdentity, type VisitorPollResponse, WIDGET_AVATAR_LOTTIE_PROXY_PATH, WIDGET_AVATAR_PROXY_PATH, type WidgetAvatarConfig, type WidgetConfig, type WidgetConfigResponse, type WidgetDockPosition, type WidgetDockPreset, type WidgetSettingsRecord, buildWidgetConfigResponse, canTransition, getAvatarStateAnimations, isAvatarMode, isAvatarMotion, isAvatarPresetId, isBridgeEnvelope, isWidgetAvatarProxyUrl, parseWidgetAvatar, resolveRendererAvatarOptions };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,84 @@
1
+ type WidgetDockPreset = "bottom-right" | "bottom-left" | "top-right" | "top-left";
2
+ type WidgetDockPosition = WidgetDockPreset | {
3
+ preset: WidgetDockPreset;
4
+ offsetX?: number;
5
+ offsetY?: number;
6
+ };
7
+ type AvatarMode = "default" | "preset" | "custom" | "vector" | "lottie";
8
+ type AvatarPresetId = "orb" | "ring";
9
+ type AvatarMotion = "breathe" | "pulse" | "spin" | "none";
10
+ /** Relative path — embed apps fetch via API with publishable key (bucket URLs are often private). */
11
+ declare const WIDGET_AVATAR_PROXY_PATH = "/widget-avatar";
12
+ /** Query appended to WIDGET_AVATAR_PROXY_PATH to fetch the tenant's Lottie JSON. */
13
+ declare const WIDGET_AVATAR_LOTTIE_PROXY_PATH = "/widget-avatar?type=lottie";
14
+ type WidgetAvatarConfig = {
15
+ mode: "default";
16
+ } | {
17
+ mode: "preset";
18
+ preset: AvatarPresetId;
19
+ } | {
20
+ mode: "custom";
21
+ assetUrl: string;
22
+ } | {
23
+ mode: "vector";
24
+ svg: string;
25
+ motion: AvatarMotion;
26
+ color?: string;
27
+ } | {
28
+ mode: "lottie";
29
+ assetUrl: string;
30
+ motion: AvatarMotion;
31
+ };
32
+ interface WidgetConfigResponse {
33
+ dockPosition: WidgetDockPosition;
34
+ dockSize: number;
35
+ theme: {
36
+ primary: string;
37
+ tooltipBg: string;
38
+ tooltipColor: string;
39
+ };
40
+ avatar: WidgetAvatarConfig;
41
+ }
42
+ /** Flat keys persisted in tenants.settings JSONB */
43
+ interface WidgetSettingsRecord {
44
+ dockPosition?: WidgetDockPreset;
45
+ dockSize?: number;
46
+ primaryColor?: string;
47
+ tooltipBg?: string;
48
+ tooltipColor?: string;
49
+ avatarMode?: AvatarMode;
50
+ avatarPreset?: AvatarPresetId;
51
+ avatarAssetUrl?: string;
52
+ avatarAssetKey?: string;
53
+ avatarSvg?: string;
54
+ avatarColor?: string;
55
+ avatarLottieKey?: string;
56
+ avatarMotion?: AvatarMotion;
57
+ [key: string]: unknown;
58
+ }
59
+ declare function isAvatarMode(value: unknown): value is AvatarMode;
60
+ declare function isAvatarPresetId(value: unknown): value is AvatarPresetId;
61
+ declare function isAvatarMotion(value: unknown): value is AvatarMotion;
62
+ declare function isWidgetAvatarProxyUrl(url: string): boolean;
63
+ declare function parseWidgetAvatar(settings: WidgetSettingsRecord): WidgetAvatarConfig;
64
+ declare function buildWidgetConfigResponse(settings: WidgetSettingsRecord): WidgetConfigResponse;
65
+ /** Map widget avatar config to ThreeBeeRenderer constructor options. */
66
+ declare function resolveRendererAvatarOptions(avatar: WidgetAvatarConfig): {
67
+ avatarPreset: "bee" | AvatarPresetId;
68
+ assetUrl?: string;
69
+ };
70
+ type BeeVisualState = "idle" | "guiding" | "thinking" | "celebrating";
71
+ type AnimationSpec = {
72
+ kind: "css";
73
+ className: string | null;
74
+ } | {
75
+ kind: "lottie";
76
+ segment: string;
77
+ loop: boolean;
78
+ };
79
+ /** Per-state animation descriptor consumed by DomAvatarRenderer. */
80
+ declare function getAvatarStateAnimations(mode: "vector" | "lottie", motion: AvatarMotion): Record<BeeVisualState, AnimationSpec>;
81
+
1
82
  /**
2
83
  * Frozen Sprint 1 contract. Edits require joint sign-off from Track A
3
84
  * (broker) and Track B (macOS) leads.
@@ -168,6 +249,28 @@ interface IdentityResponse {
168
249
  issuedAt: number;
169
250
  }
170
251
 
252
+ /** Trust scope of a memory write. In Sprint 5, all writes hardcode "personal".
253
+ * Sprint 6 introduces the tenant-scoped writer during the `tenant:attach` flow. */
254
+ type MemoryScope = "personal" | "tenant-scoped";
255
+ /** A single recalled memory entry. Returned by `GET /v1/memory/recent`. */
256
+ interface MemoryRecallItem {
257
+ /** mem0 entry id — opaque, used as React key on the client. */
258
+ id: string;
259
+ /** mem0-derived short summary (e.g. "Asked about carbon credits on Carbon Hub"). */
260
+ topic: string;
261
+ /** Surface where the memory was recorded — drives the "On X yesterday" badge. */
262
+ surface: SurfaceId;
263
+ /** ISO 8601 timestamp of when the memory was created. */
264
+ capturedAt: string;
265
+ }
266
+ /** Response envelope for `GET /v1/memory/recent`. */
267
+ interface MemoryRecallResponse {
268
+ items: MemoryRecallItem[];
269
+ /** True when mem0 was unreachable / timed out and the items list is incomplete or empty.
270
+ * Clients should treat as empty (silent open) rather than show stale data. */
271
+ degraded?: boolean;
272
+ }
273
+
171
274
  type HighlightVariant = "pulse" | "ring" | "soft";
172
275
  interface TargetRef {
173
276
  kibeeId?: string;
@@ -583,6 +686,197 @@ interface WidgetConfig {
583
686
  tooltipBg: string;
584
687
  tooltipColor: string;
585
688
  };
689
+ avatar?: WidgetAvatarConfig;
690
+ }
691
+
692
+ /** A row in the per-workspace allowed-domains table. Shown in the admin UI
693
+ * and consumed by the bridge JWT auth path during the trust handshake. */
694
+ interface AllowedDomain {
695
+ id: string;
696
+ workspaceId: string;
697
+ /** Apex domain only (e.g. "acme.com"). Apex-matches subdomains at runtime. */
698
+ domain: string;
699
+ /** Auth0 sub of the admin who added this entry. */
700
+ createdBy: string;
701
+ /** ISO 8601. */
702
+ createdAt: string;
586
703
  }
704
+ /** Response for `GET /v1/workspace/allowlist/check?domain=X`.
705
+ * When >1 workspace allowlists the same domain for the same visitor,
706
+ * `workspaces` returns all matches and the macOS Buddy shows a picker. */
707
+ interface AllowlistCheckResponse {
708
+ allowed: boolean;
709
+ workspaces?: Array<{
710
+ id: string;
711
+ name: string;
712
+ }>;
713
+ }
714
+ /** Payload carried by `tenant:attach` and `tenant:detach` BridgeEnvelope.
715
+ * `attachedAt` mirrors the original attach time even on detach so telemetry
716
+ * can compute durationMs server-side. */
717
+ interface TenantAttachPayload {
718
+ workspaceId: string;
719
+ domain: string;
720
+ attachedAt: string;
721
+ }
722
+ /** Response for `GET /v1/tenant/flows`. Returns published flows for the
723
+ * workspace identified by `claims.tenantId` on the bridge JWT. */
724
+ interface TenantFlowsResponse {
725
+ flows: FlowDefinition[];
726
+ }
727
+ type FlowStep = {
728
+ kind: "web_tooltip";
729
+ selector: string;
730
+ instruction: string;
731
+ onPageId?: string;
732
+ } | {
733
+ kind: "desktop_click";
734
+ target: {
735
+ role: string;
736
+ label: string;
737
+ axPath: string;
738
+ };
739
+ modifiers: ReadonlyArray<"shift" | "control" | "option" | "command">;
740
+ description?: string;
741
+ fallbackCoord?: {
742
+ x: number;
743
+ y: number;
744
+ };
745
+ };
746
+ type CaptureStatus = "pending" | "promoted" | "rejected" | "withdrawn";
747
+ interface CaptureSummary {
748
+ id: string;
749
+ workspaceId: string;
750
+ captorVisitorId: string;
751
+ signature: string;
752
+ stepCount: number;
753
+ durationMs: number;
754
+ status: CaptureStatus;
755
+ promotedFlowId?: string;
756
+ rejectionReason?: string;
757
+ createdAt: string;
758
+ }
759
+ interface CaptureUploadPayload {
760
+ v: 2;
761
+ visitorId: string;
762
+ scope: "tenant-scoped";
763
+ capturedAt: string;
764
+ durationMs: number;
765
+ aborted: boolean;
766
+ steps: ReadonlyArray<{
767
+ ts: number;
768
+ type: "mousedown";
769
+ button: 0 | 1 | 2;
770
+ modifiers: ReadonlyArray<string>;
771
+ target: {
772
+ role: string;
773
+ label: string;
774
+ axPath: string;
775
+ };
776
+ fallbackCoord: {
777
+ x: number;
778
+ y: number;
779
+ };
780
+ }>;
781
+ }
782
+ interface CaptureUploadResponse {
783
+ captureId: string;
784
+ signature: string;
785
+ }
786
+ interface CaptureUploadEnvelope {
787
+ payload: CaptureUploadPayload;
788
+ warnings?: ReadonlyArray<string>;
789
+ }
790
+ interface CandidateGroup {
791
+ signature: string;
792
+ captures: ReadonlyArray<CaptureSummary>;
793
+ proposedTitle: string;
794
+ representativeId: string;
795
+ }
796
+ interface PromoteCandidatePayload {
797
+ editedSteps: ReadonlyArray<FlowStep>;
798
+ title: string;
799
+ pageId?: string;
800
+ audience?: string;
801
+ introMessage?: string;
802
+ replaceFlowId?: string;
803
+ }
804
+ type AuditAction = "capture.uploaded" | "capture.withdrawn" | "capture.promoted" | "capture.rejected" | "capture.edited" | "flag.flipped" | "slo.token.minted";
805
+ interface AuditEvent {
806
+ id: string;
807
+ workspaceId: string;
808
+ actor: {
809
+ kind: "visitor" | "admin" | "system";
810
+ id: string;
811
+ };
812
+ action: AuditAction;
813
+ target: {
814
+ kind: "capture" | "flow" | "flag";
815
+ id: string;
816
+ };
817
+ metadata?: Record<string, unknown>;
818
+ ts: string;
819
+ }
820
+ interface DiffPreview {
821
+ matchKind: "new" | "update";
822
+ matchedFlowId?: string;
823
+ matchedFlowTitle?: string;
824
+ stepDiff: ReadonlyArray<{
825
+ kind: "added" | "removed" | "changed" | "unchanged";
826
+ step: FlowStep;
827
+ }>;
828
+ }
829
+ interface FeatureFlag {
830
+ key: string;
831
+ defaultValue: boolean;
832
+ description: string;
833
+ createdAt: string;
834
+ updatedAt: string;
835
+ }
836
+ interface FeatureFlagOverride {
837
+ workspaceId: string;
838
+ key: string;
839
+ value: boolean;
840
+ createdAt: string;
841
+ updatedAt: string;
842
+ }
843
+ interface ResolvedFlagSet {
844
+ workspaceId: string;
845
+ flags: Record<string, boolean>;
846
+ fetchedAt: string;
847
+ }
848
+ interface SloWindow {
849
+ captureUploadSuccessRate: number;
850
+ captureUploadCount: number;
851
+ tenantAttachDeniedRate: number;
852
+ tenantAttachAttemptCount: number;
853
+ adminPromotionLatencyP50Ms: number;
854
+ adminPromotionLatencyP95Ms: number;
855
+ bridgeUptimePerVisitorMedian: number;
856
+ replayFallbackRate: number;
857
+ replayAttemptCount: number;
858
+ }
859
+ interface SloSnapshot {
860
+ computedAt: string;
861
+ workspaceId: string;
862
+ windows: {
863
+ last24h: SloWindow;
864
+ last7d: SloWindow;
865
+ };
866
+ }
867
+ declare const SLO_THRESHOLDS: {
868
+ readonly captureUploadSuccessRate: {
869
+ readonly min: 0.99;
870
+ };
871
+ readonly tenantAttachDeniedRate: {
872
+ readonly max: 0.01;
873
+ };
874
+ readonly adminPromotionLatencyP95Ms: {
875
+ readonly max: 2000;
876
+ };
877
+ readonly bridgeUptimePerVisitorMedian: {
878
+ readonly min: 0.99;
879
+ };
880
+ };
587
881
 
588
- export { type AdminSessionSummary, type AnalyticsEvent, BUDDY_TRANSITIONS, type BridgeClaims, type BridgeEnvelope, type BridgeEventType, type BuddyState, type ChatMessage, type ChatMode, type ChatSender, type CrossSiteFlowQueueItem, type CrossSiteFlowStep, type DockInlineAnchor, type DockPositionConfig, type DockPositionPreset, type EventMetadata, type FlowCommand, type FlowDefinition, type FlowMoveOptions, type HighlightVariant, type IdentityRequest, type IdentityResponse, type IntentMatch, type KiBeePairAccept, type KiBeePairReject, type KiBeePairRequest, type MessageTemplate, type PairingState, type PushFlowRequest, type PushTargetsRequest, type RecoveryRequest, type RecoveryResponse, type RegisteredTarget, type ResolveIntentRequest, type SessionState, type StartSessionRequest, type SurfaceId, type TargetRef, type TrackEventRequest, type VisibleTarget, type VisitorIdentity, type VisitorPollResponse, type WidgetConfig, canTransition, isBridgeEnvelope };
882
+ export { type AdminSessionSummary, type AllowedDomain, type AllowlistCheckResponse, type AnalyticsEvent, type AnimationSpec, type AuditAction, type AuditEvent, type AvatarMode, type AvatarMotion, type AvatarPresetId, BUDDY_TRANSITIONS, type BeeVisualState, type BridgeClaims, type BridgeEnvelope, type BridgeEventType, type BuddyState, type CandidateGroup, type CaptureStatus, type CaptureSummary, type CaptureUploadEnvelope, type CaptureUploadPayload, type CaptureUploadResponse, type ChatMessage, type ChatMode, type ChatSender, type CrossSiteFlowQueueItem, type CrossSiteFlowStep, type DiffPreview, type DockInlineAnchor, type DockPositionConfig, type DockPositionPreset, type EventMetadata, type FeatureFlag, type FeatureFlagOverride, type FlowCommand, type FlowDefinition, type FlowMoveOptions, type FlowStep, type HighlightVariant, type IdentityRequest, type IdentityResponse, type IntentMatch, type KiBeePairAccept, type KiBeePairReject, type KiBeePairRequest, type MemoryRecallItem, type MemoryRecallResponse, type MemoryScope, type MessageTemplate, type PairingState, type PromoteCandidatePayload, type PushFlowRequest, type PushTargetsRequest, type RecoveryRequest, type RecoveryResponse, type RegisteredTarget, type ResolveIntentRequest, type ResolvedFlagSet, SLO_THRESHOLDS, type SessionState, type SloSnapshot, type SloWindow, type StartSessionRequest, type SurfaceId, type TargetRef, type TenantAttachPayload, type TenantFlowsResponse, type TrackEventRequest, type VisibleTarget, type VisitorIdentity, type VisitorPollResponse, WIDGET_AVATAR_LOTTIE_PROXY_PATH, WIDGET_AVATAR_PROXY_PATH, type WidgetAvatarConfig, type WidgetConfig, type WidgetConfigResponse, type WidgetDockPosition, type WidgetDockPreset, type WidgetSettingsRecord, buildWidgetConfigResponse, canTransition, getAvatarStateAnimations, isAvatarMode, isAvatarMotion, isAvatarPresetId, isBridgeEnvelope, isWidgetAvatarProxyUrl, parseWidgetAvatar, resolveRendererAvatarOptions };
package/dist/index.js CHANGED
@@ -21,11 +21,106 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  BUDDY_TRANSITIONS: () => BUDDY_TRANSITIONS,
24
+ SLO_THRESHOLDS: () => SLO_THRESHOLDS,
25
+ WIDGET_AVATAR_LOTTIE_PROXY_PATH: () => WIDGET_AVATAR_LOTTIE_PROXY_PATH,
26
+ WIDGET_AVATAR_PROXY_PATH: () => WIDGET_AVATAR_PROXY_PATH,
27
+ buildWidgetConfigResponse: () => buildWidgetConfigResponse,
24
28
  canTransition: () => canTransition,
25
- isBridgeEnvelope: () => isBridgeEnvelope
29
+ getAvatarStateAnimations: () => getAvatarStateAnimations,
30
+ isAvatarMode: () => isAvatarMode,
31
+ isAvatarMotion: () => isAvatarMotion,
32
+ isAvatarPresetId: () => isAvatarPresetId,
33
+ isBridgeEnvelope: () => isBridgeEnvelope,
34
+ isWidgetAvatarProxyUrl: () => isWidgetAvatarProxyUrl,
35
+ parseWidgetAvatar: () => parseWidgetAvatar,
36
+ resolveRendererAvatarOptions: () => resolveRendererAvatarOptions
26
37
  });
27
38
  module.exports = __toCommonJS(index_exports);
28
39
 
40
+ // src/widget.ts
41
+ var WIDGET_AVATAR_PROXY_PATH = "/widget-avatar";
42
+ var WIDGET_AVATAR_LOTTIE_PROXY_PATH = "/widget-avatar?type=lottie";
43
+ var AVATAR_MODES = ["default", "preset", "custom", "vector", "lottie"];
44
+ var AVATAR_PRESETS = ["orb", "ring"];
45
+ var AVATAR_MOTIONS = ["breathe", "pulse", "spin", "none"];
46
+ function isAvatarMode(value) {
47
+ return typeof value === "string" && AVATAR_MODES.includes(value);
48
+ }
49
+ function isAvatarPresetId(value) {
50
+ return typeof value === "string" && AVATAR_PRESETS.includes(value);
51
+ }
52
+ function isAvatarMotion(value) {
53
+ return typeof value === "string" && AVATAR_MOTIONS.includes(value);
54
+ }
55
+ function isWidgetAvatarProxyUrl(url) {
56
+ const trimmed = url.trim();
57
+ return trimmed === WIDGET_AVATAR_PROXY_PATH || trimmed.endsWith(WIDGET_AVATAR_PROXY_PATH);
58
+ }
59
+ function parseWidgetAvatar(settings) {
60
+ const mode = isAvatarMode(settings.avatarMode) ? settings.avatarMode : "default";
61
+ const motion = isAvatarMotion(settings.avatarMotion) ? settings.avatarMotion : "breathe";
62
+ if (mode === "preset") {
63
+ const preset = isAvatarPresetId(settings.avatarPreset) ? settings.avatarPreset : "orb";
64
+ return { mode, preset };
65
+ }
66
+ if (mode === "custom") {
67
+ const assetKey = typeof settings.avatarAssetKey === "string" ? settings.avatarAssetKey.trim() : "";
68
+ if (assetKey) return { mode, assetUrl: WIDGET_AVATAR_PROXY_PATH };
69
+ if (typeof settings.avatarAssetUrl === "string" && settings.avatarAssetUrl.trim()) {
70
+ return { mode, assetUrl: settings.avatarAssetUrl.trim() };
71
+ }
72
+ return { mode: "default" };
73
+ }
74
+ if (mode === "vector") {
75
+ const svg = typeof settings.avatarSvg === "string" ? settings.avatarSvg.trim() : "";
76
+ if (!svg) return { mode: "default" };
77
+ const color = typeof settings.avatarColor === "string" && settings.avatarColor.trim() ? settings.avatarColor.trim() : void 0;
78
+ return color ? { mode, svg, motion, color } : { mode, svg, motion };
79
+ }
80
+ if (mode === "lottie") {
81
+ const key = typeof settings.avatarLottieKey === "string" ? settings.avatarLottieKey.trim() : "";
82
+ if (!key) return { mode: "default" };
83
+ return { mode, assetUrl: WIDGET_AVATAR_LOTTIE_PROXY_PATH, motion };
84
+ }
85
+ return { mode: "default" };
86
+ }
87
+ function buildWidgetConfigResponse(settings) {
88
+ const dockPosition = settings.dockPosition ?? "bottom-right";
89
+ const dockSize = typeof settings.dockSize === "number" ? settings.dockSize : 60;
90
+ return {
91
+ dockPosition,
92
+ dockSize,
93
+ theme: {
94
+ primary: typeof settings.primaryColor === "string" ? settings.primaryColor : "#a77a2f",
95
+ tooltipBg: typeof settings.tooltipBg === "string" ? settings.tooltipBg : "#fbf6ec",
96
+ tooltipColor: typeof settings.tooltipColor === "string" ? settings.tooltipColor : "#241b11"
97
+ },
98
+ avatar: parseWidgetAvatar(settings)
99
+ };
100
+ }
101
+ function resolveRendererAvatarOptions(avatar) {
102
+ if (avatar.mode === "preset") return { avatarPreset: avatar.preset };
103
+ if (avatar.mode === "custom") return { avatarPreset: "bee", assetUrl: avatar.assetUrl };
104
+ return { avatarPreset: "bee" };
105
+ }
106
+ function getAvatarStateAnimations(mode, motion) {
107
+ if (mode === "lottie") {
108
+ return {
109
+ idle: { kind: "lottie", segment: "idle", loop: true },
110
+ guiding: { kind: "lottie", segment: "idle", loop: true },
111
+ thinking: { kind: "lottie", segment: "thinking", loop: true },
112
+ celebrating: { kind: "lottie", segment: "celebrate", loop: false }
113
+ };
114
+ }
115
+ const idleClass = motion === "none" ? null : `kibee-2d-motion--${motion}`;
116
+ return {
117
+ idle: { kind: "css", className: idleClass },
118
+ guiding: { kind: "css", className: "kibee-2d-state--guiding" },
119
+ thinking: { kind: "css", className: "kibee-2d-state--thinking" },
120
+ celebrating: { kind: "css", className: "kibee-2d-state--celebrating" }
121
+ };
122
+ }
123
+
29
124
  // src/bridge.ts
30
125
  var SURFACE_IDS = /* @__PURE__ */ new Set(["web", "extension", "desktop"]);
31
126
  var BRIDGE_TARGETS = /* @__PURE__ */ new Set([
@@ -68,9 +163,28 @@ var BUDDY_TRANSITIONS = {
68
163
  function canTransition(from, to) {
69
164
  return BUDDY_TRANSITIONS[from].includes(to);
70
165
  }
166
+
167
+ // src/index.ts
168
+ var SLO_THRESHOLDS = {
169
+ captureUploadSuccessRate: { min: 0.99 },
170
+ tenantAttachDeniedRate: { max: 0.01 },
171
+ adminPromotionLatencyP95Ms: { max: 2e3 },
172
+ bridgeUptimePerVisitorMedian: { min: 0.99 }
173
+ };
71
174
  // Annotate the CommonJS export names for ESM import in node:
72
175
  0 && (module.exports = {
73
176
  BUDDY_TRANSITIONS,
177
+ SLO_THRESHOLDS,
178
+ WIDGET_AVATAR_LOTTIE_PROXY_PATH,
179
+ WIDGET_AVATAR_PROXY_PATH,
180
+ buildWidgetConfigResponse,
74
181
  canTransition,
75
- isBridgeEnvelope
182
+ getAvatarStateAnimations,
183
+ isAvatarMode,
184
+ isAvatarMotion,
185
+ isAvatarPresetId,
186
+ isBridgeEnvelope,
187
+ isWidgetAvatarProxyUrl,
188
+ parseWidgetAvatar,
189
+ resolveRendererAvatarOptions
76
190
  });
package/dist/index.mjs CHANGED
@@ -1,3 +1,87 @@
1
+ // src/widget.ts
2
+ var WIDGET_AVATAR_PROXY_PATH = "/widget-avatar";
3
+ var WIDGET_AVATAR_LOTTIE_PROXY_PATH = "/widget-avatar?type=lottie";
4
+ var AVATAR_MODES = ["default", "preset", "custom", "vector", "lottie"];
5
+ var AVATAR_PRESETS = ["orb", "ring"];
6
+ var AVATAR_MOTIONS = ["breathe", "pulse", "spin", "none"];
7
+ function isAvatarMode(value) {
8
+ return typeof value === "string" && AVATAR_MODES.includes(value);
9
+ }
10
+ function isAvatarPresetId(value) {
11
+ return typeof value === "string" && AVATAR_PRESETS.includes(value);
12
+ }
13
+ function isAvatarMotion(value) {
14
+ return typeof value === "string" && AVATAR_MOTIONS.includes(value);
15
+ }
16
+ function isWidgetAvatarProxyUrl(url) {
17
+ const trimmed = url.trim();
18
+ return trimmed === WIDGET_AVATAR_PROXY_PATH || trimmed.endsWith(WIDGET_AVATAR_PROXY_PATH);
19
+ }
20
+ function parseWidgetAvatar(settings) {
21
+ const mode = isAvatarMode(settings.avatarMode) ? settings.avatarMode : "default";
22
+ const motion = isAvatarMotion(settings.avatarMotion) ? settings.avatarMotion : "breathe";
23
+ if (mode === "preset") {
24
+ const preset = isAvatarPresetId(settings.avatarPreset) ? settings.avatarPreset : "orb";
25
+ return { mode, preset };
26
+ }
27
+ if (mode === "custom") {
28
+ const assetKey = typeof settings.avatarAssetKey === "string" ? settings.avatarAssetKey.trim() : "";
29
+ if (assetKey) return { mode, assetUrl: WIDGET_AVATAR_PROXY_PATH };
30
+ if (typeof settings.avatarAssetUrl === "string" && settings.avatarAssetUrl.trim()) {
31
+ return { mode, assetUrl: settings.avatarAssetUrl.trim() };
32
+ }
33
+ return { mode: "default" };
34
+ }
35
+ if (mode === "vector") {
36
+ const svg = typeof settings.avatarSvg === "string" ? settings.avatarSvg.trim() : "";
37
+ if (!svg) return { mode: "default" };
38
+ const color = typeof settings.avatarColor === "string" && settings.avatarColor.trim() ? settings.avatarColor.trim() : void 0;
39
+ return color ? { mode, svg, motion, color } : { mode, svg, motion };
40
+ }
41
+ if (mode === "lottie") {
42
+ const key = typeof settings.avatarLottieKey === "string" ? settings.avatarLottieKey.trim() : "";
43
+ if (!key) return { mode: "default" };
44
+ return { mode, assetUrl: WIDGET_AVATAR_LOTTIE_PROXY_PATH, motion };
45
+ }
46
+ return { mode: "default" };
47
+ }
48
+ function buildWidgetConfigResponse(settings) {
49
+ const dockPosition = settings.dockPosition ?? "bottom-right";
50
+ const dockSize = typeof settings.dockSize === "number" ? settings.dockSize : 60;
51
+ return {
52
+ dockPosition,
53
+ dockSize,
54
+ theme: {
55
+ primary: typeof settings.primaryColor === "string" ? settings.primaryColor : "#a77a2f",
56
+ tooltipBg: typeof settings.tooltipBg === "string" ? settings.tooltipBg : "#fbf6ec",
57
+ tooltipColor: typeof settings.tooltipColor === "string" ? settings.tooltipColor : "#241b11"
58
+ },
59
+ avatar: parseWidgetAvatar(settings)
60
+ };
61
+ }
62
+ function resolveRendererAvatarOptions(avatar) {
63
+ if (avatar.mode === "preset") return { avatarPreset: avatar.preset };
64
+ if (avatar.mode === "custom") return { avatarPreset: "bee", assetUrl: avatar.assetUrl };
65
+ return { avatarPreset: "bee" };
66
+ }
67
+ function getAvatarStateAnimations(mode, motion) {
68
+ if (mode === "lottie") {
69
+ return {
70
+ idle: { kind: "lottie", segment: "idle", loop: true },
71
+ guiding: { kind: "lottie", segment: "idle", loop: true },
72
+ thinking: { kind: "lottie", segment: "thinking", loop: true },
73
+ celebrating: { kind: "lottie", segment: "celebrate", loop: false }
74
+ };
75
+ }
76
+ const idleClass = motion === "none" ? null : `kibee-2d-motion--${motion}`;
77
+ return {
78
+ idle: { kind: "css", className: idleClass },
79
+ guiding: { kind: "css", className: "kibee-2d-state--guiding" },
80
+ thinking: { kind: "css", className: "kibee-2d-state--thinking" },
81
+ celebrating: { kind: "css", className: "kibee-2d-state--celebrating" }
82
+ };
83
+ }
84
+
1
85
  // src/bridge.ts
2
86
  var SURFACE_IDS = /* @__PURE__ */ new Set(["web", "extension", "desktop"]);
3
87
  var BRIDGE_TARGETS = /* @__PURE__ */ new Set([
@@ -40,8 +124,27 @@ var BUDDY_TRANSITIONS = {
40
124
  function canTransition(from, to) {
41
125
  return BUDDY_TRANSITIONS[from].includes(to);
42
126
  }
127
+
128
+ // src/index.ts
129
+ var SLO_THRESHOLDS = {
130
+ captureUploadSuccessRate: { min: 0.99 },
131
+ tenantAttachDeniedRate: { max: 0.01 },
132
+ adminPromotionLatencyP95Ms: { max: 2e3 },
133
+ bridgeUptimePerVisitorMedian: { min: 0.99 }
134
+ };
43
135
  export {
44
136
  BUDDY_TRANSITIONS,
137
+ SLO_THRESHOLDS,
138
+ WIDGET_AVATAR_LOTTIE_PROXY_PATH,
139
+ WIDGET_AVATAR_PROXY_PATH,
140
+ buildWidgetConfigResponse,
45
141
  canTransition,
46
- isBridgeEnvelope
142
+ getAvatarStateAnimations,
143
+ isAvatarMode,
144
+ isAvatarMotion,
145
+ isAvatarPresetId,
146
+ isBridgeEnvelope,
147
+ isWidgetAvatarProxyUrl,
148
+ parseWidgetAvatar,
149
+ resolveRendererAvatarOptions
47
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kibee/contracts",
3
- "version": "0.2.0",
3
+ "version": "0.8.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -11,12 +11,17 @@
11
11
  "require": "./dist/index.js"
12
12
  }
13
13
  },
14
- "files": ["dist"],
14
+ "files": [
15
+ "dist"
16
+ ],
15
17
  "scripts": {
16
18
  "build": "tsup src/index.ts --format cjs,esm --dts --clean --tsconfig tsconfig.build.json",
17
19
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
18
20
  },
19
21
  "devDependencies": {
20
22
  "tsup": "^8.5.1"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
21
26
  }
22
27
  }