polymorph-sdk 0.2.3 → 0.2.5
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.css +1 -1
- package/dist/index.d.ts +46 -22
- package/dist/index.js +6276 -5929
- package/package.json +1 -1
- package/src/ChatThread.tsx +15 -2
- package/src/IdentityForm.tsx +135 -0
- package/src/PolymorphWidget.tsx +44 -18
- package/src/RoomHandler.tsx +22 -2
- package/src/VoiceOverlay.tsx +60 -11
- package/src/WidgetPanel.tsx +86 -60
- package/src/__tests__/IdentityForm.test.tsx +146 -0
- package/src/__tests__/PolymorphWidget.test.tsx +173 -0
- package/src/__tests__/integration.test.ts +58 -0
- package/src/__tests__/usePolymorphSession.test.ts +422 -0
- package/src/index.ts +4 -1
- package/src/styles.module.css +440 -41
- package/src/types.ts +28 -18
- package/src/usePolymorphSession.ts +338 -78
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,33 @@ export declare interface ChatMessage {
|
|
|
7
7
|
text: string;
|
|
8
8
|
source: "chat" | "voice";
|
|
9
9
|
timestamp: number;
|
|
10
|
+
senderName?: string;
|
|
11
|
+
senderType?: "human";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare type FieldRequirement = "required" | "optional" | "hidden";
|
|
15
|
+
|
|
16
|
+
export declare interface IdentityCollection {
|
|
17
|
+
collectEmail: FieldRequirement;
|
|
18
|
+
collectPhone: FieldRequirement;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
export declare function PolymorphWidget(props: WidgetConfig): JSX.Element;
|
|
13
22
|
|
|
23
|
+
/** Resolved from the backend via /widget-configs/resolve. */
|
|
24
|
+
export declare interface ResolvedWidgetConfig {
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
subtitle: string;
|
|
28
|
+
primaryColor: string;
|
|
29
|
+
position: "bottom-right" | "bottom-left";
|
|
30
|
+
darkMode: boolean;
|
|
31
|
+
enableVoice: boolean;
|
|
32
|
+
greeting: string;
|
|
33
|
+
collectEmail: FieldRequirement;
|
|
34
|
+
collectPhone: FieldRequirement;
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
declare interface RoomConnection {
|
|
15
38
|
token: string;
|
|
16
39
|
livekitUrl: string;
|
|
@@ -24,48 +47,49 @@ export declare function usePolymorphSession(config: WidgetConfig): {
|
|
|
24
47
|
messages: ChatMessage[];
|
|
25
48
|
isVoiceEnabled: boolean;
|
|
26
49
|
isMicActive: boolean;
|
|
50
|
+
isScreenSharing: boolean;
|
|
51
|
+
hasObserver: boolean;
|
|
52
|
+
hasUnread: boolean;
|
|
53
|
+
wiggleKey: number;
|
|
27
54
|
error: string | null;
|
|
55
|
+
needsIdentityForm: boolean;
|
|
56
|
+
identityCollection: IdentityCollection | null;
|
|
57
|
+
resolvedConfig: ResolvedWidgetConfig | null;
|
|
28
58
|
connect: () => Promise<void>;
|
|
29
59
|
disconnect: () => void;
|
|
30
|
-
addMessage: (role: "user" | "agent", text: string, source: "chat" | "voice") => void;
|
|
60
|
+
addMessage: (role: "user" | "agent", text: string, source: "chat" | "voice", senderName?: string, senderType?: "human") => void;
|
|
31
61
|
sendMessage: (text: string) => void;
|
|
32
62
|
toggleMic: () => Promise<void>;
|
|
33
63
|
toggleVoice: () => Promise<void>;
|
|
64
|
+
toggleScreenShare: () => Promise<void>;
|
|
34
65
|
setRoom: (room: Room | null) => void;
|
|
66
|
+
setUser: (user: WidgetUser) => void;
|
|
67
|
+
clearUnread: () => void;
|
|
68
|
+
setPanelOpen: (open: boolean) => void;
|
|
35
69
|
};
|
|
36
70
|
|
|
37
|
-
export declare interface WidgetBranding {
|
|
38
|
-
/** FAB and accent color (default: "#171717") */
|
|
39
|
-
primaryColor?: string;
|
|
40
|
-
/** Panel header title (default: "Hi there") */
|
|
41
|
-
title?: string;
|
|
42
|
-
/** Panel subheader */
|
|
43
|
-
subtitle?: string;
|
|
44
|
-
/** Initial message shown before agent connects */
|
|
45
|
-
greeting?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
71
|
export declare interface WidgetConfig {
|
|
49
|
-
|
|
72
|
+
/** Backend API URL. Defaults to https://api.usepolymorph.com in production, http://localhost:8080 on localhost. */
|
|
73
|
+
apiBaseUrl?: string;
|
|
50
74
|
apiKey?: string;
|
|
51
|
-
/** Server-side widget config ID. When
|
|
75
|
+
/** Server-side widget config ID. When omitted, the org's default config is used. */
|
|
52
76
|
configId?: string;
|
|
53
77
|
/** LiveKit dispatched agent name (default: "custom-voice-agent"). */
|
|
54
78
|
agentName?: string;
|
|
79
|
+
/** Inline metadata (only used when no server-side config is resolved). */
|
|
55
80
|
metadata?: Record<string, string | string[]>;
|
|
56
|
-
/** Pre-filled user identity. When provided, the
|
|
81
|
+
/** Pre-filled user identity. When provided, the identity form is skipped. */
|
|
57
82
|
user?: WidgetUser;
|
|
58
|
-
branding?: WidgetBranding;
|
|
59
|
-
position?: "bottom-right" | "bottom-left";
|
|
60
|
-
/** Enable voice call (default: true). When false, widget is chat-only. */
|
|
61
|
-
enableVoice?: boolean;
|
|
62
83
|
/** Extra options passed to fetch (e.g. { credentials: "include" }) */
|
|
63
84
|
fetchOptions?: RequestInit;
|
|
64
|
-
/**
|
|
65
|
-
|
|
85
|
+
/** Called when a session starts with room info for constructing join URLs. */
|
|
86
|
+
onSessionStart?: (info: {
|
|
87
|
+
roomId: string;
|
|
88
|
+
joinToken: string;
|
|
89
|
+
}) => void;
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
declare interface WidgetUser {
|
|
92
|
+
export declare interface WidgetUser {
|
|
69
93
|
/** Display name (e.g. "Jane Smith") */
|
|
70
94
|
name?: string;
|
|
71
95
|
/** Email address */
|