@chanl/widget-sdk 0.2.0-canary.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 +257 -0
- package/dist/auth.d.ts +26 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +36 -0
- package/dist/auth.js.map +1 -0
- package/dist/chat/chat-client.d.ts +81 -0
- package/dist/chat/chat-client.d.ts.map +1 -0
- package/dist/chat/chat-client.js +192 -0
- package/dist/chat/chat-client.js.map +1 -0
- package/dist/chat/stream-parser.d.ts +20 -0
- package/dist/chat/stream-parser.d.ts.map +1 -0
- package/dist/chat/stream-parser.js +134 -0
- package/dist/chat/stream-parser.js.map +1 -0
- package/dist/chat/widget-config.d.ts +7 -0
- package/dist/chat/widget-config.d.ts.map +1 -0
- package/dist/chat/widget-config.js +26 -0
- package/dist/chat/widget-config.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +49 -0
- package/dist/client.js.map +1 -0
- package/dist/defaults.d.ts +12 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +27 -0
- package/dist/defaults.js.map +1 -0
- package/dist/embed/loader-types.d.ts +119 -0
- package/dist/embed/loader-types.d.ts.map +1 -0
- package/dist/embed/loader-types.js +20 -0
- package/dist/embed/loader-types.js.map +1 -0
- package/dist/embed/loader.d.ts +101 -0
- package/dist/embed/loader.d.ts.map +1 -0
- package/dist/embed/loader.js +439 -0
- package/dist/embed/loader.js.map +1 -0
- package/dist/embed/v1.global.js +5 -0
- package/dist/embed/v1.global.js.map +1 -0
- package/dist/events.d.ts +10 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +25 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +14 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +3 -0
- package/dist/logger.js.map +1 -0
- package/dist/next/index.d.ts +58 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +83 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.d.ts +16 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +20 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/types.d.ts +27 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +8 -0
- package/dist/react/types.js.map +1 -0
- package/dist/react/use-chanl.d.ts +27 -0
- package/dist/react/use-chanl.d.ts.map +1 -0
- package/dist/react/use-chanl.js +57 -0
- package/dist/react/use-chanl.js.map +1 -0
- package/dist/react/use-chat.d.ts +32 -0
- package/dist/react/use-chat.d.ts.map +1 -0
- package/dist/react/use-chat.js +224 -0
- package/dist/react/use-chat.js.map +1 -0
- package/dist/react/use-voice.d.ts +37 -0
- package/dist/react/use-voice.d.ts.map +1 -0
- package/dist/react/use-voice.js +268 -0
- package/dist/react/use-voice.js.map +1 -0
- package/dist/react/widget.d.ts +43 -0
- package/dist/react/widget.d.ts.map +1 -0
- package/dist/react/widget.js +188 -0
- package/dist/react/widget.js.map +1 -0
- package/dist/storage/session-storage.d.ts +48 -0
- package/dist/storage/session-storage.d.ts.map +1 -0
- package/dist/storage/session-storage.js +84 -0
- package/dist/storage/session-storage.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/voice/audio-recorder.d.ts +43 -0
- package/dist/voice/audio-recorder.d.ts.map +1 -0
- package/dist/voice/audio-recorder.js +127 -0
- package/dist/voice/audio-recorder.js.map +1 -0
- package/dist/voice/index.d.ts +13 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +16 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/mock-mode.d.ts +93 -0
- package/dist/voice/mock-mode.d.ts.map +1 -0
- package/dist/voice/mock-mode.js +375 -0
- package/dist/voice/mock-mode.js.map +1 -0
- package/dist/voice/transports/index.d.ts +5 -0
- package/dist/voice/transports/index.d.ts.map +1 -0
- package/dist/voice/transports/index.js +10 -0
- package/dist/voice/transports/index.js.map +1 -0
- package/dist/voice/transports/transport.d.ts +70 -0
- package/dist/voice/transports/transport.d.ts.map +1 -0
- package/dist/voice/transports/transport.js +12 -0
- package/dist/voice/transports/transport.js.map +1 -0
- package/dist/voice/transports/vapi.d.ts +147 -0
- package/dist/voice/transports/vapi.d.ts.map +1 -0
- package/dist/voice/transports/vapi.js +337 -0
- package/dist/voice/transports/vapi.js.map +1 -0
- package/dist/voice/transports/webrtc.d.ts +58 -0
- package/dist/voice/transports/webrtc.d.ts.map +1 -0
- package/dist/voice/transports/webrtc.js +318 -0
- package/dist/voice/transports/webrtc.js.map +1 -0
- package/dist/voice/transports/websocket.d.ts +39 -0
- package/dist/voice/transports/websocket.d.ts.map +1 -0
- package/dist/voice/transports/websocket.js +280 -0
- package/dist/voice/transports/websocket.js.map +1 -0
- package/dist/voice/types.d.ts +323 -0
- package/dist/voice/types.d.ts.map +1 -0
- package/dist/voice/types.js +41 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/utils.d.ts +22 -0
- package/dist/voice/utils.d.ts.map +1 -0
- package/dist/voice/utils.js +44 -0
- package/dist/voice/utils.js.map +1 -0
- package/dist/voice/voice-client.d.ts +231 -0
- package/dist/voice/voice-client.d.ts.map +1 -0
- package/dist/voice/voice-client.js +1187 -0
- package/dist/voice/voice-client.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Stream protocol parser for chat responses.
|
|
4
|
+
* Ported from platform-sdk/modules/chat.ts.
|
|
5
|
+
*
|
|
6
|
+
* Protocol:
|
|
7
|
+
* 0:"text delta" - text chunk
|
|
8
|
+
* 9:{"toolCallId":"x","toolName":"y","args":{}} - tool call started
|
|
9
|
+
* a:{"toolCallId":"x","result":{...}} - tool result
|
|
10
|
+
* e:{"finishReason":"stop"} - stream finished
|
|
11
|
+
*
|
|
12
|
+
* Falls back to raw text mode if first chunk doesn't match protocol prefix.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.parseStream = parseStream;
|
|
16
|
+
async function parseStream(body, onChunk, onPart) {
|
|
17
|
+
const reader = body.getReader();
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
let fullText = '';
|
|
20
|
+
let lineBuffer = '';
|
|
21
|
+
const parts = [];
|
|
22
|
+
const toolCalls = [];
|
|
23
|
+
const pendingTools = new Map();
|
|
24
|
+
let textIdx = -1;
|
|
25
|
+
const processLine = (line) => {
|
|
26
|
+
if (!line || line.length < 2)
|
|
27
|
+
return;
|
|
28
|
+
const prefix = line.slice(0, 2);
|
|
29
|
+
const payload = line.slice(2);
|
|
30
|
+
switch (prefix) {
|
|
31
|
+
case '0:': {
|
|
32
|
+
try {
|
|
33
|
+
const text = JSON.parse(payload);
|
|
34
|
+
fullText += text;
|
|
35
|
+
onChunk(text);
|
|
36
|
+
if (textIdx >= 0 && parts[textIdx]?.type === 'text') {
|
|
37
|
+
parts[textIdx].text = (parts[textIdx].text || '') + text;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
textIdx = parts.length;
|
|
41
|
+
parts.push({ type: 'text', text });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
fullText += payload;
|
|
46
|
+
onChunk(payload);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case '9:': {
|
|
51
|
+
try {
|
|
52
|
+
const data = JSON.parse(payload);
|
|
53
|
+
textIdx = -1;
|
|
54
|
+
const invocation = {
|
|
55
|
+
toolCallId: data.toolCallId,
|
|
56
|
+
toolName: data.toolName,
|
|
57
|
+
state: 'call',
|
|
58
|
+
args: data.args,
|
|
59
|
+
};
|
|
60
|
+
const part = { type: 'tool-invocation', toolInvocation: invocation };
|
|
61
|
+
pendingTools.set(data.toolCallId, parts.length);
|
|
62
|
+
parts.push(part);
|
|
63
|
+
onPart?.(part);
|
|
64
|
+
}
|
|
65
|
+
catch { /* skip */ }
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'a:': {
|
|
69
|
+
try {
|
|
70
|
+
const data = JSON.parse(payload);
|
|
71
|
+
textIdx = -1;
|
|
72
|
+
const idx = pendingTools.get(data.toolCallId);
|
|
73
|
+
if (idx !== undefined && parts[idx]?.toolInvocation) {
|
|
74
|
+
parts[idx].toolInvocation.state = 'result';
|
|
75
|
+
parts[idx].toolInvocation.result = data.result;
|
|
76
|
+
onPart?.({ ...parts[idx] });
|
|
77
|
+
}
|
|
78
|
+
pendingTools.delete(data.toolCallId);
|
|
79
|
+
toolCalls.push({
|
|
80
|
+
toolName: parts[idx ?? -1]?.toolInvocation?.toolName || 'unknown',
|
|
81
|
+
args: parts[idx ?? -1]?.toolInvocation?.args,
|
|
82
|
+
result: data.result,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch { /* skip */ }
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'e:':
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
fullText += line;
|
|
92
|
+
onChunk(line);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
while (true) {
|
|
98
|
+
const { done, value } = await reader.read();
|
|
99
|
+
if (done)
|
|
100
|
+
break;
|
|
101
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
102
|
+
if (!chunk)
|
|
103
|
+
continue;
|
|
104
|
+
// Detect raw text (non-protocol) mode
|
|
105
|
+
if (fullText === '' && lineBuffer === '' && !chunk.match(/^[0-9a-e]:/)) {
|
|
106
|
+
fullText += chunk;
|
|
107
|
+
onChunk(chunk);
|
|
108
|
+
while (true) {
|
|
109
|
+
const { done: d, value: v } = await reader.read();
|
|
110
|
+
if (d)
|
|
111
|
+
break;
|
|
112
|
+
const c = decoder.decode(v, { stream: true });
|
|
113
|
+
if (c) {
|
|
114
|
+
fullText += c;
|
|
115
|
+
onChunk(c);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
lineBuffer += chunk;
|
|
121
|
+
const lines = lineBuffer.split('\n');
|
|
122
|
+
lineBuffer = lines.pop() || '';
|
|
123
|
+
for (const line of lines)
|
|
124
|
+
processLine(line);
|
|
125
|
+
}
|
|
126
|
+
if (lineBuffer)
|
|
127
|
+
processLine(lineBuffer);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
reader.releaseLock();
|
|
131
|
+
}
|
|
132
|
+
return { text: fullText, parts, toolCalls };
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=stream-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.js","sourceRoot":"","sources":["../../src/chat/stream-parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAUH,kCAiHC;AAjHM,KAAK,UAAU,WAAW,CAC/B,IAAgC,EAChC,OAA+B,EAC/B,MAAoC;IAEpC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,MAAM,SAAS,GAAc,EAAE,CAAC;IAChC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;IAEjB,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;QACnC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAA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,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,UAAU,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAC/B,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,UAAU;YAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch agent widget config from the platform API.
|
|
3
|
+
* Used to get agent name, avatar, style, greeting, etc.
|
|
4
|
+
*/
|
|
5
|
+
import type { WidgetConfig } from '../types';
|
|
6
|
+
export declare function getWidgetConfig(agentId: string, apiKey: string, baseUrl: string): Promise<WidgetConfig | null>;
|
|
7
|
+
//# sourceMappingURL=widget-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-config.d.ts","sourceRoot":"","sources":["../../src/chat/widget-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAe9B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch agent widget config from the platform API.
|
|
4
|
+
* Used to get agent name, avatar, style, greeting, etc.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getWidgetConfig = getWidgetConfig;
|
|
8
|
+
async function getWidgetConfig(agentId, apiKey, baseUrl) {
|
|
9
|
+
try {
|
|
10
|
+
const url = `${baseUrl.replace(/\/$/, '')}/api/v1/agents/widget/by-agent?agentId=${encodeURIComponent(agentId)}&publicKey=${encodeURIComponent(apiKey)}`;
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
'x-public-key': apiKey,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
return null;
|
|
19
|
+
const json = await res.json();
|
|
20
|
+
return json.data || json;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=widget-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-config.js","sourceRoot":"","sources":["../../src/chat/widget-config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAIH,0CAmBC;AAnBM,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,MAAc,EACd,OAAe;IAEf,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,0CAA0C,kBAAkB,CAAC,OAAO,CAAC,cAAc,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;QACzJ,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC3B,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,cAAc,EAAE,MAAM;aACvB;SACF,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createChanlClient — unified text + voice client.
|
|
3
|
+
*
|
|
4
|
+
* One factory, three things: chat, voice, getWidgetConfig.
|
|
5
|
+
* Auto-resolves baseUrl when not provided. Handles pub_/ak_ keys.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const client = createChanlClient({ agentId, apiKey: 'pub_xxx' });
|
|
9
|
+
* await client.chat.createSession();
|
|
10
|
+
* await client.chat.streamMessage(...);
|
|
11
|
+
* await client.voice.start(agentId);
|
|
12
|
+
* const config = await client.getWidgetConfig();
|
|
13
|
+
*/
|
|
14
|
+
import type { WidgetConfig } from './types';
|
|
15
|
+
import type { VoiceClient } from './voice/voice-client';
|
|
16
|
+
export interface ChanlClientConfig {
|
|
17
|
+
agentId: string;
|
|
18
|
+
apiKey: string;
|
|
19
|
+
/** Optional. Defaults to the production Chanl platform; override for local dev or self-hosting. */
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createChanlClient(config: ChanlClientConfig): {
|
|
23
|
+
/** Text chat client (sessions, streaming, history) */
|
|
24
|
+
chat: {
|
|
25
|
+
createSession(agentId: string, input?: import("./types").CreateSessionInput): Promise<import("./types").ChatSession>;
|
|
26
|
+
resumeSession(interactionId: string, sessionToken: string): Promise<import("./types").ResumedChatSession>;
|
|
27
|
+
streamMessage(sessionId: string, message: string, onChunk: (text: string) => void, onPart?: (part: import("./types").MessagePart) => void): Promise<import("./types").ChatMessageResponse>;
|
|
28
|
+
sendMessage(sessionId: string, message: string): Promise<import("./types").ChatMessageResponse>;
|
|
29
|
+
endSession(sessionId: string): Promise<void>;
|
|
30
|
+
identify(sessionId: string, input: {
|
|
31
|
+
user: {
|
|
32
|
+
externalId: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
avatarUrl?: string;
|
|
36
|
+
attributes?: Record<string, unknown>;
|
|
37
|
+
};
|
|
38
|
+
userHash?: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
sessionId: string;
|
|
41
|
+
customerId: string;
|
|
42
|
+
created: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
getMessages(sessionId: string): Promise<{
|
|
45
|
+
sessionId: string;
|
|
46
|
+
messages: Array<{
|
|
47
|
+
role: string;
|
|
48
|
+
content: string;
|
|
49
|
+
timestamp?: string | number;
|
|
50
|
+
}>;
|
|
51
|
+
toolCalls: unknown[];
|
|
52
|
+
} | null>;
|
|
53
|
+
};
|
|
54
|
+
/** Voice client — lazy-loaded on first access (browser only) */
|
|
55
|
+
readonly voice: VoiceClient;
|
|
56
|
+
/** Fetch agent widget config (name, avatar, style, greeting) */
|
|
57
|
+
getWidgetConfig(): Promise<WidgetConfig | null>;
|
|
58
|
+
/** Resolved configuration for inspection */
|
|
59
|
+
config: {
|
|
60
|
+
agentId: string;
|
|
61
|
+
apiKey: string;
|
|
62
|
+
baseUrl: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export type ChanlClient = ReturnType<typeof createChanlClient>;
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,mGAAmG;IACnG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB;IAiBvD,sDAAsD;;;;;;;;;;qBAmB+kJ,CAAC;oBAAc,CAAC;yBAAmB,CAAC;0BAAoB,CAAC;;oBAA6C,CAAC;;;;;;;;;;;yBAA8uC,CAAC;;;;;IAhB39L,gEAAgE;oBACnD,WAAW;IAIxB,gEAAgE;uBAC7C,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAI/C,4CAA4C;;;;;;EAG/C;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* createChanlClient — unified text + voice client.
|
|
4
|
+
*
|
|
5
|
+
* One factory, three things: chat, voice, getWidgetConfig.
|
|
6
|
+
* Auto-resolves baseUrl when not provided. Handles pub_/ak_ keys.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const client = createChanlClient({ agentId, apiKey: 'pub_xxx' });
|
|
10
|
+
* await client.chat.createSession();
|
|
11
|
+
* await client.chat.streamMessage(...);
|
|
12
|
+
* await client.voice.start(agentId);
|
|
13
|
+
* const config = await client.getWidgetConfig();
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.createChanlClient = createChanlClient;
|
|
17
|
+
const chat_client_1 = require("./chat/chat-client");
|
|
18
|
+
const widget_config_1 = require("./chat/widget-config");
|
|
19
|
+
const defaults_1 = require("./defaults");
|
|
20
|
+
function createChanlClient(config) {
|
|
21
|
+
const { agentId, apiKey } = config;
|
|
22
|
+
const baseUrl = (0, defaults_1.resolveBaseUrl)(config.baseUrl);
|
|
23
|
+
// Lazy voice client — require() at access time avoids loading
|
|
24
|
+
// browser-only deps (Worker, extendable-media-recorder) in node.
|
|
25
|
+
let voiceClient = null;
|
|
26
|
+
const getVoice = () => {
|
|
27
|
+
if (!voiceClient) {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
29
|
+
const { VoiceClient: VC } = require('./voice/voice-client');
|
|
30
|
+
voiceClient = new VC(apiKey, { baseUrl });
|
|
31
|
+
}
|
|
32
|
+
return voiceClient;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
/** Text chat client (sessions, streaming, history) */
|
|
36
|
+
chat: (0, chat_client_1.createChatClient)({ apiKey, baseUrl }),
|
|
37
|
+
/** Voice client — lazy-loaded on first access (browser only) */
|
|
38
|
+
get voice() {
|
|
39
|
+
return getVoice();
|
|
40
|
+
},
|
|
41
|
+
/** Fetch agent widget config (name, avatar, style, greeting) */
|
|
42
|
+
getWidgetConfig() {
|
|
43
|
+
return (0, widget_config_1.getWidgetConfig)(agentId, apiKey, baseUrl);
|
|
44
|
+
},
|
|
45
|
+
/** Resolved configuration for inspection */
|
|
46
|
+
config: { agentId, apiKey, baseUrl },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAiBH,8CAiCC;AAhDD,oDAAsD;AACtD,wDAAuD;AACvD,yCAA4C;AAa5C,SAAgB,iBAAiB,CAAC,MAAyB;IACzD,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACnC,MAAM,OAAO,GAAG,IAAA,yBAAc,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE/C,8DAA8D;IAC9D,iEAAiE;IACjE,IAAI,WAAW,GAAuB,IAAI,CAAC;IAC3C,MAAM,QAAQ,GAAG,GAAgB,EAAE;QACjC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,iEAAiE;YACjE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;YAC5D,WAAW,GAAG,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,WAAY,CAAC;IACtB,CAAC,CAAC;IAEF,OAAO;QACL,sDAAsD;QACtD,IAAI,EAAE,IAAA,8BAAgB,EAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAE3C,gEAAgE;QAChE,IAAI,KAAK;YACP,OAAO,QAAQ,EAAE,CAAC;QACpB,CAAC;QAED,gEAAgE;QAChE,eAAe;YACb,OAAO,IAAA,+BAAe,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;QAED,4CAA4C;QAC5C,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart defaults for SDK config.
|
|
3
|
+
* Auto-detects localhost vs production.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the platform API base URL.
|
|
7
|
+
* - Explicit value wins
|
|
8
|
+
* - localhost/127.0.0.1 → dev
|
|
9
|
+
* - Otherwise → production
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveBaseUrl(explicit?: string): string;
|
|
12
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAQxD"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Smart defaults for SDK config.
|
|
4
|
+
* Auto-detects localhost vs production.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveBaseUrl = resolveBaseUrl;
|
|
8
|
+
const PROD_BASE_URL = 'https://platform.channel.tel';
|
|
9
|
+
const DEV_BASE_URL = 'http://localhost:3100';
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the platform API base URL.
|
|
12
|
+
* - Explicit value wins
|
|
13
|
+
* - localhost/127.0.0.1 → dev
|
|
14
|
+
* - Otherwise → production
|
|
15
|
+
*/
|
|
16
|
+
function resolveBaseUrl(explicit) {
|
|
17
|
+
if (explicit)
|
|
18
|
+
return explicit;
|
|
19
|
+
if (typeof window === 'undefined')
|
|
20
|
+
return PROD_BASE_URL;
|
|
21
|
+
const host = window.location.hostname;
|
|
22
|
+
if (host === 'localhost' || host === '127.0.0.1' || host.endsWith('.local')) {
|
|
23
|
+
return DEV_BASE_URL;
|
|
24
|
+
}
|
|
25
|
+
return PROD_BASE_URL;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAWH,wCAQC;AAjBD,MAAM,aAAa,GAAG,8BAA8B,CAAC;AACrD,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAE7C;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAiB;IAC9C,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,aAAa,CAAC;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;IACtC,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader types — extracted from `loader.ts` so React consumers (and any
|
|
3
|
+
* other type consumer) can import these without pulling in the loader's
|
|
4
|
+
* `declare global { interface Window { ChanlChat } }` block.
|
|
5
|
+
*
|
|
6
|
+
* `loader.ts` re-exports these + adds the runtime IIFE + declare global.
|
|
7
|
+
* `widget.tsx` imports from HERE only (types), then dynamically imports
|
|
8
|
+
* `loader.ts` at runtime inside a useEffect.
|
|
9
|
+
*
|
|
10
|
+
* Why: if `widget.tsx` imported types directly from `loader.ts`,
|
|
11
|
+
* TypeScript would process the whole `loader.ts` file during type
|
|
12
|
+
* resolution — including its `declare global` — and that leaks the
|
|
13
|
+
* `window.ChanlChat` type into every transitive consumer of
|
|
14
|
+
* `@chanl/widget-sdk/react`. That conflicts with apps (e.g. chat-host's
|
|
15
|
+
* `widget-config-form.tsx`) that declare their own local simplified
|
|
16
|
+
* `window.ChanlChat` shape.
|
|
17
|
+
*/
|
|
18
|
+
export interface ChanlChatProactiveMessage {
|
|
19
|
+
text: string;
|
|
20
|
+
delay?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Identified end-user (Intercom-style widget identity).
|
|
24
|
+
*
|
|
25
|
+
* The host app's SERVER resolves this user from its own auth system
|
|
26
|
+
* (Firebase, Clerk, NextAuth, Auth0, custom) and passes the stable
|
|
27
|
+
* `externalId` + an HMAC-SHA256 hash computed via `computeUserHash`
|
|
28
|
+
* from `@chanl/widget-sdk/next`.
|
|
29
|
+
*/
|
|
30
|
+
export interface ChanlChatUser {
|
|
31
|
+
externalId: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
avatarUrl?: string;
|
|
35
|
+
/** Custom attributes — flow into the agent prompt as `customer:<key>` vars. */
|
|
36
|
+
attributes?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface ChanlChatInitConfig {
|
|
39
|
+
/** Agent to load. Required. */
|
|
40
|
+
agentId: string;
|
|
41
|
+
/** Public key (`pub_xxx`) for origin-scoped auth. Recommended. */
|
|
42
|
+
apiKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Identified end-user. Activates the widget identity path — the
|
|
45
|
+
* chat.channel.tel iframe forwards these fields to `/interactions/chat`,
|
|
46
|
+
* the backend verifies `userHash` + upserts a Customer by `externalId`,
|
|
47
|
+
* and custom attributes flow into the agent prompt as `customer:<key>`
|
|
48
|
+
* variables. Required if the host workspace has an `identitySecret`.
|
|
49
|
+
*/
|
|
50
|
+
user?: ChanlChatUser;
|
|
51
|
+
/** HMAC-SHA256 of `user.externalId` using workspace identity secret. */
|
|
52
|
+
userHash?: string;
|
|
53
|
+
/** Visual theme for the chat iframe. */
|
|
54
|
+
theme?: 'dark' | 'light';
|
|
55
|
+
/** Launcher position. */
|
|
56
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
57
|
+
/** Launcher button background color. */
|
|
58
|
+
color?: string;
|
|
59
|
+
/** Show the "Powered by Chanl" footer. Default true. */
|
|
60
|
+
branding?: boolean;
|
|
61
|
+
/** Locale code to load localized agent copy. */
|
|
62
|
+
locale?: string;
|
|
63
|
+
/** Link to your privacy policy, shown in the disclaimer. */
|
|
64
|
+
privacyUrl?: string;
|
|
65
|
+
/** Override the agent's display name in the header. */
|
|
66
|
+
agentName?: string;
|
|
67
|
+
/** Subtitle shown under the agent name. */
|
|
68
|
+
agentSubtitle?: string;
|
|
69
|
+
/** 1–2 character initials for the avatar fallback. */
|
|
70
|
+
agentInitials?: string;
|
|
71
|
+
/** Avatar image URL. */
|
|
72
|
+
agentAvatarUrl?: string;
|
|
73
|
+
/** Override the greeting message shown when the chat panel first opens. */
|
|
74
|
+
greeting?: string;
|
|
75
|
+
/** Input placeholder text. */
|
|
76
|
+
placeholder?: string;
|
|
77
|
+
/** Override the dark theme background color. */
|
|
78
|
+
darkBg?: string;
|
|
79
|
+
/** Proactive toast messages shown before the user opens the chat. */
|
|
80
|
+
proactiveMessages?: Array<string | ChanlChatProactiveMessage>;
|
|
81
|
+
/** Override the Chanl platform API base URL (auto-resolved by default). */
|
|
82
|
+
baseUrl?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Override the chat iframe host URL. Defaults to `window.location.origin`,
|
|
85
|
+
* which is the correct value when the loader is served from the same origin
|
|
86
|
+
* as the chat UI (e.g. `chat.channel.tel`).
|
|
87
|
+
*/
|
|
88
|
+
chatHost?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ChanlChatApi {
|
|
91
|
+
_initialized: boolean;
|
|
92
|
+
init: (cfg: ChanlChatInitConfig) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Apply config changes in-place WITHOUT re-mounting the iframe.
|
|
95
|
+
*
|
|
96
|
+
* Launcher-level options (`color`, `position`, `proactiveMessages`) are
|
|
97
|
+
* patched directly on the DOM. Iframe-level options (`theme`, `agentName`,
|
|
98
|
+
* `agentSubtitle`, `agentInitials`, `agentAvatarUrl`, `greeting`,
|
|
99
|
+
* `placeholder`, `privacyUrl`, `branding`, `darkBg`, `locale`) are
|
|
100
|
+
* pushed into the iframe via postMessage. The chat page inside the iframe
|
|
101
|
+
* listens for `chanl:update-config` and patches its own React state.
|
|
102
|
+
*
|
|
103
|
+
* Auth/identity fields (`agentId`, `apiKey`, `chatHost`, `baseUrl`,
|
|
104
|
+
* `user`, `userHash`) cannot be updated live — they change which agent is
|
|
105
|
+
* loaded, which identity the session is for, or where the iframe is
|
|
106
|
+
* served from. Pass those via `init()` + `destroy()` instead.
|
|
107
|
+
*/
|
|
108
|
+
update: (partial: Partial<ChanlChatInitConfig>) => void;
|
|
109
|
+
open: () => void;
|
|
110
|
+
close: () => void;
|
|
111
|
+
toggle: () => void;
|
|
112
|
+
destroy: () => void;
|
|
113
|
+
setUser: (user: Record<string, unknown>) => void;
|
|
114
|
+
setContext: (ctx: Record<string, unknown>) => void;
|
|
115
|
+
sendMessage: (text: string) => void;
|
|
116
|
+
on: (event: string, fn: (data?: unknown) => void) => void;
|
|
117
|
+
off: (event: string, fn: (data?: unknown) => void) => void;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=loader-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-types.d.ts","sourceRoot":"","sources":["../../src/embed/loader-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,mBAAmB;IAClC,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;IAC1C,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,aAAa,CAAC,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E,OAAO,KAAK,IAAI,KAAK,IAAI,CAAC;CAC5D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Loader types — extracted from `loader.ts` so React consumers (and any
|
|
4
|
+
* other type consumer) can import these without pulling in the loader's
|
|
5
|
+
* `declare global { interface Window { ChanlChat } }` block.
|
|
6
|
+
*
|
|
7
|
+
* `loader.ts` re-exports these + adds the runtime IIFE + declare global.
|
|
8
|
+
* `widget.tsx` imports from HERE only (types), then dynamically imports
|
|
9
|
+
* `loader.ts` at runtime inside a useEffect.
|
|
10
|
+
*
|
|
11
|
+
* Why: if `widget.tsx` imported types directly from `loader.ts`,
|
|
12
|
+
* TypeScript would process the whole `loader.ts` file during type
|
|
13
|
+
* resolution — including its `declare global` — and that leaks the
|
|
14
|
+
* `window.ChanlChat` type into every transitive consumer of
|
|
15
|
+
* `@chanl/widget-sdk/react`. That conflicts with apps (e.g. chat-host's
|
|
16
|
+
* `widget-config-form.tsx`) that declare their own local simplified
|
|
17
|
+
* `window.ChanlChat` shape.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
//# sourceMappingURL=loader-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-types.js","sourceRoot":"","sources":["../../src/embed/loader-types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chanl Chat Widget — Embed Loader
|
|
3
|
+
*
|
|
4
|
+
* <script src="https://chat.channel.tel/widget/v1.js"></script>
|
|
5
|
+
* <script>
|
|
6
|
+
* ChanlChat.init({
|
|
7
|
+
* agentId: 'ag_xxx',
|
|
8
|
+
* apiKey: 'pub_xxx',
|
|
9
|
+
* theme: 'dark',
|
|
10
|
+
* proactiveMessages: [
|
|
11
|
+
* { text: 'Hey! Need help?', delay: 2000 },
|
|
12
|
+
* { text: 'Ask me anything.', delay: 4000 },
|
|
13
|
+
* ],
|
|
14
|
+
* });
|
|
15
|
+
* </script>
|
|
16
|
+
*
|
|
17
|
+
* This file is the source of truth for the embed loader. It is bundled to
|
|
18
|
+
* `dist/embed/v1.js` as a self-contained IIFE with zero external deps. Any
|
|
19
|
+
* visual or behavioral change must preserve the current launcher + iframe
|
|
20
|
+
* look & feel — embedders rely on it.
|
|
21
|
+
*/
|
|
22
|
+
export interface ChanlChatProactiveMessage {
|
|
23
|
+
text: string;
|
|
24
|
+
delay?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ChanlChatInitConfig {
|
|
27
|
+
/** Agent to load. Required. */
|
|
28
|
+
agentId: string;
|
|
29
|
+
/** Public key (`pub_xxx`) for origin-scoped auth. Recommended. */
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
/** Visual theme for the chat iframe. */
|
|
32
|
+
theme?: 'dark' | 'light';
|
|
33
|
+
/** Launcher position. */
|
|
34
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
35
|
+
/** Launcher button background color. */
|
|
36
|
+
color?: string;
|
|
37
|
+
/** Show the "Powered by Chanl" footer. Default true. */
|
|
38
|
+
branding?: boolean;
|
|
39
|
+
/** Locale code to load localized agent copy. */
|
|
40
|
+
locale?: string;
|
|
41
|
+
/** Link to your privacy policy, shown in the disclaimer. */
|
|
42
|
+
privacyUrl?: string;
|
|
43
|
+
/** Override the agent's display name in the header. */
|
|
44
|
+
agentName?: string;
|
|
45
|
+
/** Subtitle shown under the agent name. */
|
|
46
|
+
agentSubtitle?: string;
|
|
47
|
+
/** 1–2 character initials for the avatar fallback. */
|
|
48
|
+
agentInitials?: string;
|
|
49
|
+
/** Avatar image URL. */
|
|
50
|
+
agentAvatarUrl?: string;
|
|
51
|
+
/** Override the greeting message shown when the chat panel first opens. */
|
|
52
|
+
greeting?: string;
|
|
53
|
+
/** Input placeholder text. */
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
/** Override the dark theme background color. */
|
|
56
|
+
darkBg?: string;
|
|
57
|
+
/** Proactive toast messages shown before the user opens the chat. */
|
|
58
|
+
proactiveMessages?: Array<string | ChanlChatProactiveMessage>;
|
|
59
|
+
/** Override the Chanl platform API base URL (auto-resolved by default). */
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Override the chat iframe host URL. Defaults to `window.location.origin`,
|
|
63
|
+
* which is the correct value when the loader is served from the same origin
|
|
64
|
+
* as the chat UI (e.g. `chat.channel.tel`).
|
|
65
|
+
*/
|
|
66
|
+
chatHost?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ChanlChatApi {
|
|
69
|
+
_initialized: boolean;
|
|
70
|
+
init: (cfg: ChanlChatInitConfig) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Apply config changes in-place WITHOUT re-mounting the iframe.
|
|
73
|
+
*
|
|
74
|
+
* Launcher-level options (`color`, `position`, `proactiveMessages`) are
|
|
75
|
+
* patched directly on the DOM. Iframe-level options (`theme`, `agentName`,
|
|
76
|
+
* `agentSubtitle`, `agentInitials`, `agentAvatarUrl`, `greeting`,
|
|
77
|
+
* `placeholder`, `privacyUrl`, `branding`, `darkBg`, `locale`) are
|
|
78
|
+
* pushed into the iframe via postMessage. The chat page inside the iframe
|
|
79
|
+
* listens for `chanl:update-config` and patches its own React state.
|
|
80
|
+
*
|
|
81
|
+
* Auth/identity fields (`agentId`, `apiKey`, `chatHost`, `baseUrl`) cannot
|
|
82
|
+
* be updated live — they change which agent is loaded or where the iframe
|
|
83
|
+
* is served from. Pass those via `init()` + `destroy()` instead.
|
|
84
|
+
*/
|
|
85
|
+
update: (partial: Partial<ChanlChatInitConfig>) => void;
|
|
86
|
+
open: () => void;
|
|
87
|
+
close: () => void;
|
|
88
|
+
toggle: () => void;
|
|
89
|
+
destroy: () => void;
|
|
90
|
+
setUser: (user: Record<string, unknown>) => void;
|
|
91
|
+
setContext: (ctx: Record<string, unknown>) => void;
|
|
92
|
+
sendMessage: (text: string) => void;
|
|
93
|
+
on: (event: string, fn: (data?: unknown) => void) => void;
|
|
94
|
+
off: (event: string, fn: (data?: unknown) => void) => void;
|
|
95
|
+
}
|
|
96
|
+
declare global {
|
|
97
|
+
interface Window {
|
|
98
|
+
ChanlChat: ChanlChatApi;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/embed/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC;IAC1C,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,WAAW,CAAC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