@opencx/widget 3.0.38 → 3.0.40
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/designs.cjs +1 -1
- package/dist/designs.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/src/headless/core/__tests__/test-utils.d.ts +43 -79
- package/dist/src/headless/core/api/api-caller.d.ts +12 -51
- package/dist/src/headless/core/api/schema.d.ts +122 -26
- package/dist/src/headless/core/context/active-session-polling.ctx.d.ts +24 -0
- package/dist/src/headless/core/context/message.ctx.d.ts +1 -8
- package/dist/src/headless/core/context/session.ctx.d.ts +2 -6
- package/dist/src/headless/core/context/widget.ctx.d.ts +1 -0
- package/dist/src/headless/core/types/schemas.d.ts +1 -1
- package/dist/{useUploadFiles-N_eAr5ZY.cjs → useUploadFiles-CH6LO6bs.cjs} +2 -2
- package/dist/{useUploadFiles-N_eAr5ZY.cjs.map → useUploadFiles-CH6LO6bs.cjs.map} +1 -1
- package/dist/{useUploadFiles-CzdpkrRu.js → useUploadFiles-CbNwKf9g.js} +3 -3
- package/dist/{useUploadFiles-CzdpkrRu.js.map → useUploadFiles-CbNwKf9g.js.map} +1 -1
- package/dist/widget.ctx-Du1SCswT.cjs +2 -0
- package/dist/widget.ctx-Du1SCswT.cjs.map +1 -0
- package/dist/{widget.ctx-BhkkDE2y.js → widget.ctx-ijfuvINp.js} +313 -316
- package/dist/widget.ctx-ijfuvINp.js.map +1 -0
- package/dist-embed/script.js +59 -59
- package/dist-embed/script.js.map +1 -1
- package/package.json +12 -8
- package/dist/widget.ctx-BhkkDE2y.js.map +0 -1
- package/dist/widget.ctx-fT1XgDYW.cjs +0 -2
- package/dist/widget.ctx-fT1XgDYW.cjs.map +0 -1
|
@@ -92,7 +92,7 @@ export declare class ApiCaller {
|
|
|
92
92
|
};
|
|
93
93
|
requestBody: {
|
|
94
94
|
content: {
|
|
95
|
-
"application/json": import('./schema').components["schemas"]["
|
|
95
|
+
"application/json": import('./schema').components["schemas"]["SendWidgetMessageDto"];
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
responses: {
|
|
@@ -145,51 +145,6 @@ export declare class ApiCaller {
|
|
|
145
145
|
};
|
|
146
146
|
signal: AbortSignal | undefined;
|
|
147
147
|
}, `${string}/${string}`>>;
|
|
148
|
-
getSessionHistory: ({ sessionId, lastMessageTimestamp, abortSignal, }: {
|
|
149
|
-
sessionId: string;
|
|
150
|
-
lastMessageTimestamp?: string;
|
|
151
|
-
abortSignal: AbortSignal;
|
|
152
|
-
}) => Promise<import('openapi-fetch').FetchResponse<{
|
|
153
|
-
parameters: {
|
|
154
|
-
query?: {
|
|
155
|
-
lastMessageTimestamp?: string;
|
|
156
|
-
};
|
|
157
|
-
header?: never;
|
|
158
|
-
path: {
|
|
159
|
-
sessionId: string;
|
|
160
|
-
};
|
|
161
|
-
cookie?: never;
|
|
162
|
-
};
|
|
163
|
-
requestBody?: never;
|
|
164
|
-
responses: {
|
|
165
|
-
200: {
|
|
166
|
-
headers: {
|
|
167
|
-
[name: string]: unknown;
|
|
168
|
-
};
|
|
169
|
-
content: {
|
|
170
|
-
"application/json": import('./schema').components["schemas"]["WidgetHistoryDto"][];
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
500: {
|
|
174
|
-
headers: {
|
|
175
|
-
[name: string]: unknown;
|
|
176
|
-
};
|
|
177
|
-
content: {
|
|
178
|
-
"application/json": import('./schema').components["schemas"]["ErrorDto"];
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
}, {
|
|
183
|
-
params: {
|
|
184
|
-
path: {
|
|
185
|
-
sessionId: string;
|
|
186
|
-
};
|
|
187
|
-
query: {
|
|
188
|
-
lastMessageTimestamp: string;
|
|
189
|
-
} | undefined;
|
|
190
|
-
};
|
|
191
|
-
signal: AbortSignal;
|
|
192
|
-
}, `${string}/${string}`>>;
|
|
193
148
|
createUnverifiedContact: (body: Dto["CreateUnverifiedContactDto"]) => Promise<import('openapi-fetch').FetchResponse<{
|
|
194
149
|
parameters: {
|
|
195
150
|
query?: never;
|
|
@@ -233,7 +188,7 @@ export declare class ApiCaller {
|
|
|
233
188
|
name?: string;
|
|
234
189
|
};
|
|
235
190
|
}, `${string}/${string}`>>;
|
|
236
|
-
createSession: (body: Dto["
|
|
191
|
+
createSession: (body: Dto["CreateWidgetSessionDto"]) => Promise<import('openapi-fetch').FetchResponse<{
|
|
237
192
|
parameters: {
|
|
238
193
|
query?: never;
|
|
239
194
|
header?: never;
|
|
@@ -242,7 +197,7 @@ export declare class ApiCaller {
|
|
|
242
197
|
};
|
|
243
198
|
requestBody: {
|
|
244
199
|
content: {
|
|
245
|
-
"application/json": import('./schema').components["schemas"]["
|
|
200
|
+
"application/json": import('./schema').components["schemas"]["CreateWidgetSessionDto"];
|
|
246
201
|
};
|
|
247
202
|
};
|
|
248
203
|
responses: {
|
|
@@ -270,12 +225,15 @@ export declare class ApiCaller {
|
|
|
270
225
|
};
|
|
271
226
|
};
|
|
272
227
|
}, `${string}/${string}`>>;
|
|
273
|
-
|
|
228
|
+
pollSessionAndHistory: ({ sessionId, lastMessageTimestamp, abortSignal, }: {
|
|
274
229
|
sessionId: string;
|
|
230
|
+
lastMessageTimestamp?: string;
|
|
275
231
|
abortSignal: AbortSignal;
|
|
276
232
|
}) => Promise<import('openapi-fetch').FetchResponse<{
|
|
277
233
|
parameters: {
|
|
278
|
-
query?:
|
|
234
|
+
query?: {
|
|
235
|
+
lastMessageTimestamp?: string;
|
|
236
|
+
};
|
|
279
237
|
header?: never;
|
|
280
238
|
path: {
|
|
281
239
|
sessionId: string;
|
|
@@ -289,7 +247,7 @@ export declare class ApiCaller {
|
|
|
289
247
|
[name: string]: unknown;
|
|
290
248
|
};
|
|
291
249
|
content: {
|
|
292
|
-
"application/json": import('./schema').components["schemas"]["
|
|
250
|
+
"application/json": import('./schema').components["schemas"]["WidgetSessionAndHistoryDto"];
|
|
293
251
|
};
|
|
294
252
|
};
|
|
295
253
|
500: {
|
|
@@ -306,6 +264,9 @@ export declare class ApiCaller {
|
|
|
306
264
|
path: {
|
|
307
265
|
sessionId: string;
|
|
308
266
|
};
|
|
267
|
+
query: {
|
|
268
|
+
lastMessageTimestamp: string;
|
|
269
|
+
} | undefined;
|
|
309
270
|
};
|
|
310
271
|
signal: AbortSignal;
|
|
311
272
|
}, `${string}/${string}`>>;
|
|
@@ -83,6 +83,22 @@ export interface paths {
|
|
|
83
83
|
patch?: never;
|
|
84
84
|
trace?: never;
|
|
85
85
|
};
|
|
86
|
+
"/backend/widget/v2/poll/{sessionId}": {
|
|
87
|
+
parameters: {
|
|
88
|
+
query?: never;
|
|
89
|
+
header?: never;
|
|
90
|
+
path?: never;
|
|
91
|
+
cookie?: never;
|
|
92
|
+
};
|
|
93
|
+
get: operations["pollSessionAndHistory"];
|
|
94
|
+
put?: never;
|
|
95
|
+
post?: never;
|
|
96
|
+
delete?: never;
|
|
97
|
+
options?: never;
|
|
98
|
+
head?: never;
|
|
99
|
+
patch?: never;
|
|
100
|
+
trace?: never;
|
|
101
|
+
};
|
|
86
102
|
"/backend/widget/v2/create-session": {
|
|
87
103
|
parameters: {
|
|
88
104
|
query?: never;
|
|
@@ -171,7 +187,7 @@ export interface components {
|
|
|
171
187
|
email?: string;
|
|
172
188
|
name?: string;
|
|
173
189
|
};
|
|
174
|
-
|
|
190
|
+
CreateWidgetSessionDto: {
|
|
175
191
|
customData?: {
|
|
176
192
|
[key: string]: string | number | boolean | unknown | unknown;
|
|
177
193
|
};
|
|
@@ -215,7 +231,29 @@ export interface components {
|
|
|
215
231
|
message?: string;
|
|
216
232
|
};
|
|
217
233
|
};
|
|
218
|
-
|
|
234
|
+
/** @description Paginated response. */
|
|
235
|
+
PaginatedWidgetSessionsDto: {
|
|
236
|
+
items: {
|
|
237
|
+
/** Format: uuid */
|
|
238
|
+
id: string;
|
|
239
|
+
createdAt: string;
|
|
240
|
+
updatedAt: string;
|
|
241
|
+
isHandedOff: boolean;
|
|
242
|
+
isOpened: boolean;
|
|
243
|
+
assignee: {
|
|
244
|
+
/** @enum {string} */
|
|
245
|
+
kind: "human" | "ai" | "none" | "unknown";
|
|
246
|
+
name: string | null;
|
|
247
|
+
avatarUrl: string | null;
|
|
248
|
+
};
|
|
249
|
+
channel: string;
|
|
250
|
+
isVerified: boolean;
|
|
251
|
+
lastMessage: string | null;
|
|
252
|
+
}[];
|
|
253
|
+
/** @description The `cursor` for the request to get the next set of items. Null if there is no more data. */
|
|
254
|
+
next: string | null;
|
|
255
|
+
};
|
|
256
|
+
SendWidgetMessageDto: {
|
|
219
257
|
/** Format: uuid */
|
|
220
258
|
uuid: string;
|
|
221
259
|
content: string;
|
|
@@ -245,28 +283,6 @@ export interface components {
|
|
|
245
283
|
url: string;
|
|
246
284
|
}[] | null;
|
|
247
285
|
};
|
|
248
|
-
/** @description Paginated response. */
|
|
249
|
-
PaginatedWidgetSessionsDto: {
|
|
250
|
-
items: {
|
|
251
|
-
/** Format: uuid */
|
|
252
|
-
id: string;
|
|
253
|
-
createdAt: string;
|
|
254
|
-
updatedAt: string;
|
|
255
|
-
isHandedOff: boolean;
|
|
256
|
-
isOpened: boolean;
|
|
257
|
-
assignee: {
|
|
258
|
-
/** @enum {string} */
|
|
259
|
-
kind: "human" | "ai" | "none" | "unknown";
|
|
260
|
-
name: string | null;
|
|
261
|
-
avatarUrl: string | null;
|
|
262
|
-
};
|
|
263
|
-
channel: string;
|
|
264
|
-
isVerified: boolean;
|
|
265
|
-
lastMessage: string | null;
|
|
266
|
-
}[];
|
|
267
|
-
/** @description The `cursor` for the request to get the next set of items. Null if there is no more data. */
|
|
268
|
-
next: string | null;
|
|
269
|
-
};
|
|
270
286
|
UploadWidgetFileResponseDto: {
|
|
271
287
|
fileName: string;
|
|
272
288
|
fileUrl: string;
|
|
@@ -350,6 +366,53 @@ export interface components {
|
|
|
350
366
|
officeHoursTimezone: string | null;
|
|
351
367
|
organizationName: string;
|
|
352
368
|
};
|
|
369
|
+
WidgetSessionAndHistoryDto: {
|
|
370
|
+
/** @description WidgetSession */
|
|
371
|
+
session: {
|
|
372
|
+
/** Format: uuid */
|
|
373
|
+
id: string;
|
|
374
|
+
createdAt: string;
|
|
375
|
+
updatedAt: string;
|
|
376
|
+
isHandedOff: boolean;
|
|
377
|
+
isOpened: boolean;
|
|
378
|
+
assignee: {
|
|
379
|
+
/** @enum {string} */
|
|
380
|
+
kind: "human" | "ai" | "none" | "unknown";
|
|
381
|
+
name: string | null;
|
|
382
|
+
avatarUrl: string | null;
|
|
383
|
+
};
|
|
384
|
+
channel: string;
|
|
385
|
+
isVerified: boolean;
|
|
386
|
+
lastMessage: string | null;
|
|
387
|
+
};
|
|
388
|
+
history: {
|
|
389
|
+
publicId: string;
|
|
390
|
+
/** @enum {string} */
|
|
391
|
+
type: "message" | "handoff" | "handoff_to_zendesk" | "agent_message" | "agent_joined" | "agent_comment" | "agent_took_session_from_ai" | "agent_reopened_session" | "ai_decided_to_resolve_the_issue" | "email_draft_message" | "followup" | "ai_assumed_the_session_resolved" | "user_confirmed_the_session_resolved" | "system_message";
|
|
392
|
+
content: {
|
|
393
|
+
text?: string | null;
|
|
394
|
+
};
|
|
395
|
+
sender: {
|
|
396
|
+
/** @enum {string} */
|
|
397
|
+
kind: "user" | "agent" | "ai" | "none" | "unknown";
|
|
398
|
+
name?: string | null;
|
|
399
|
+
avatar?: string | null;
|
|
400
|
+
};
|
|
401
|
+
sentAt?: string | null;
|
|
402
|
+
actionCalls?: {
|
|
403
|
+
actionName: string;
|
|
404
|
+
args?: unknown;
|
|
405
|
+
result?: unknown;
|
|
406
|
+
}[] | null;
|
|
407
|
+
attachments?: {
|
|
408
|
+
id: string;
|
|
409
|
+
name: string;
|
|
410
|
+
size: number;
|
|
411
|
+
type: string;
|
|
412
|
+
url: string;
|
|
413
|
+
}[] | null;
|
|
414
|
+
}[];
|
|
415
|
+
};
|
|
353
416
|
/** @description WidgetSession */
|
|
354
417
|
WidgetSessionDto: {
|
|
355
418
|
/** Format: uuid */
|
|
@@ -548,6 +611,39 @@ export interface operations {
|
|
|
548
611
|
};
|
|
549
612
|
};
|
|
550
613
|
};
|
|
614
|
+
pollSessionAndHistory: {
|
|
615
|
+
parameters: {
|
|
616
|
+
query?: {
|
|
617
|
+
/** @description The timestamp of the last message received by the widget in order to get any messages after. */
|
|
618
|
+
lastMessageTimestamp?: string;
|
|
619
|
+
};
|
|
620
|
+
header?: never;
|
|
621
|
+
path: {
|
|
622
|
+
sessionId: string;
|
|
623
|
+
};
|
|
624
|
+
cookie?: never;
|
|
625
|
+
};
|
|
626
|
+
requestBody?: never;
|
|
627
|
+
responses: {
|
|
628
|
+
200: {
|
|
629
|
+
headers: {
|
|
630
|
+
[name: string]: unknown;
|
|
631
|
+
};
|
|
632
|
+
content: {
|
|
633
|
+
"application/json": components["schemas"]["WidgetSessionAndHistoryDto"];
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
/** @description Internal Server Error */
|
|
637
|
+
500: {
|
|
638
|
+
headers: {
|
|
639
|
+
[name: string]: unknown;
|
|
640
|
+
};
|
|
641
|
+
content: {
|
|
642
|
+
"application/json": components["schemas"]["ErrorDto"];
|
|
643
|
+
};
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
};
|
|
551
647
|
createChatSession: {
|
|
552
648
|
parameters: {
|
|
553
649
|
query?: never;
|
|
@@ -557,7 +653,7 @@ export interface operations {
|
|
|
557
653
|
};
|
|
558
654
|
requestBody: {
|
|
559
655
|
content: {
|
|
560
|
-
"application/json": components["schemas"]["
|
|
656
|
+
"application/json": components["schemas"]["CreateWidgetSessionDto"];
|
|
561
657
|
};
|
|
562
658
|
};
|
|
563
659
|
responses: {
|
|
@@ -589,7 +685,7 @@ export interface operations {
|
|
|
589
685
|
};
|
|
590
686
|
requestBody: {
|
|
591
687
|
content: {
|
|
592
|
-
"application/json": components["schemas"]["
|
|
688
|
+
"application/json": components["schemas"]["SendWidgetMessageDto"];
|
|
593
689
|
};
|
|
594
690
|
};
|
|
595
691
|
responses: {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApiCaller } from '../api/api-caller';
|
|
2
|
+
import { MessageType } from '../types/messages';
|
|
3
|
+
import { MessageDto } from '../types/schemas';
|
|
4
|
+
import { WidgetConfig } from '../types/widget-config';
|
|
5
|
+
import { MessageCtx } from './message.ctx';
|
|
6
|
+
import { SessionCtx } from './session.ctx';
|
|
7
|
+
export declare class ActiveSessionPollingCtx {
|
|
8
|
+
private api;
|
|
9
|
+
private config;
|
|
10
|
+
private sessionCtx;
|
|
11
|
+
private messageCtx;
|
|
12
|
+
private sessionPollingIntervalSeconds;
|
|
13
|
+
private poller;
|
|
14
|
+
constructor({ api, config, sessionCtx, messageCtx, sessionPollingIntervalSeconds, }: {
|
|
15
|
+
api: ApiCaller;
|
|
16
|
+
config: WidgetConfig;
|
|
17
|
+
sessionCtx: SessionCtx;
|
|
18
|
+
messageCtx: MessageCtx;
|
|
19
|
+
sessionPollingIntervalSeconds: number;
|
|
20
|
+
});
|
|
21
|
+
private registerPolling;
|
|
22
|
+
private hackAndSlash;
|
|
23
|
+
mapHistoryToMessage: (history: MessageDto) => MessageType;
|
|
24
|
+
}
|
|
@@ -15,22 +15,15 @@ export declare class MessageCtx {
|
|
|
15
15
|
private config;
|
|
16
16
|
private api;
|
|
17
17
|
private sessionCtx;
|
|
18
|
-
private sessionPollingIntervalSeconds;
|
|
19
|
-
private poller;
|
|
20
18
|
state: PrimitiveState<MessageCtxState>;
|
|
21
19
|
private sendMessageAbortController;
|
|
22
|
-
constructor({ config, api, sessionCtx,
|
|
20
|
+
constructor({ config, api, sessionCtx, }: {
|
|
23
21
|
config: WidgetConfig;
|
|
24
22
|
api: ApiCaller;
|
|
25
23
|
sessionCtx: SessionCtx;
|
|
26
|
-
sessionPollingIntervalSeconds: number;
|
|
27
24
|
});
|
|
28
25
|
reset: () => void;
|
|
29
|
-
private registerPolling;
|
|
30
26
|
sendMessage: (input: SomeOptional<SafeOmit<SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
|
|
31
|
-
private fetchAndSetHistory;
|
|
32
|
-
/** Not the best name but whatever */
|
|
33
|
-
private mapHistoryToMessage;
|
|
34
27
|
private toUserMessage;
|
|
35
28
|
private toBotMessage;
|
|
36
29
|
private toBotErrorMessage;
|
|
@@ -24,22 +24,18 @@ type SessionsState = {
|
|
|
24
24
|
export declare class SessionCtx {
|
|
25
25
|
private api;
|
|
26
26
|
private contactCtx;
|
|
27
|
-
private sessionPollingIntervalSeconds;
|
|
28
27
|
private sessionsPollingIntervalSeconds;
|
|
29
|
-
private activeSessionPoller;
|
|
30
28
|
private sessionsRefresher;
|
|
31
29
|
sessionState: PrimitiveState<SessionState>;
|
|
32
30
|
sessionsState: PrimitiveState<SessionsState>;
|
|
33
|
-
constructor({ api, contactCtx,
|
|
31
|
+
constructor({ api, contactCtx, sessionsPollingIntervalSeconds, }: {
|
|
34
32
|
api: ApiCaller;
|
|
35
33
|
contactCtx: ContactCtx;
|
|
36
|
-
sessionPollingIntervalSeconds: number;
|
|
37
34
|
sessionsPollingIntervalSeconds: number;
|
|
38
35
|
});
|
|
39
36
|
/** Clears the session and stops polling */
|
|
40
37
|
reset: () => Promise<void>;
|
|
41
|
-
private
|
|
42
|
-
private registerInitialSessionsFetch;
|
|
38
|
+
private registerSessionsRefresherWrapper;
|
|
43
39
|
private registerSessionsRefresher;
|
|
44
40
|
createSession: () => Promise<{
|
|
45
41
|
id: string;
|
|
@@ -15,6 +15,7 @@ export declare class WidgetCtx {
|
|
|
15
15
|
routerCtx: RouterCtx;
|
|
16
16
|
storageCtx?: StorageCtx;
|
|
17
17
|
private static pollingIntervalsSeconds;
|
|
18
|
+
private activeSessionPollingCtx;
|
|
18
19
|
private constructor();
|
|
19
20
|
static initialize: ({ config, storage, }: {
|
|
20
21
|
config: WidgetConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dto } from '../api/client';
|
|
2
2
|
export type VoteInputDto = Dto["WidgetVoteDto"];
|
|
3
3
|
export type VoteOutputDto = Dto["WidgetVoteResponseDto"];
|
|
4
|
-
export type SendMessageDto = Dto["
|
|
4
|
+
export type SendMessageDto = Dto["SendWidgetMessageDto"];
|
|
5
5
|
export type SendMessageOutputDto = Dto["HandleContactMessageOutputDto"];
|
|
6
6
|
export type SessionDto = Dto["WidgetSessionDto"];
|
|
7
7
|
export type MessageDto = Dto["WidgetHistoryDto"];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var qt=Object.defineProperty;var Bt=(e,t,n)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ze=(e,t,n)=>Bt(e,typeof t!="symbol"?t+"":t,n);const g=require("react"),Gt=require("react/jsx-runtime"),Ht=require("./widget.ctx-
|
|
1
|
+
"use strict";var qt=Object.defineProperty;var Bt=(e,t,n)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ze=(e,t,n)=>Bt(e,typeof t!="symbol"?t+"":t,n);const g=require("react"),Gt=require("react/jsx-runtime"),Ht=require("./widget.ctx-Du1SCswT.cjs"),$t=require("uuid");class Kt{constructor(t){ze(this,"components",[]);const{components:n}=t;if(n&&n.forEach(r=>this.register(r)),this.components.length===0)throw new Error("No components registered");if(!this.get("fallback"))throw new Error("No fallback component registered")}register(t){const n=this.components.findIndex(r=>r.key===t.key);return n!==-1?this.components[n]=t:this.components.push(t),this}get(t){const n=this.components.find(r=>r.key.toUpperCase()===t.toUpperCase());return n||null}getComponent(t){var n;return(n=this.get(t))==null?void 0:n.component}}function zt(e){const t=g.createContext({});return[()=>{const r=g.useContext(t);if(r===void 0)throw new Error("useSafeContext must be used within a Provider");return r},t.Provider]}const kt="3.0.40",[K,Yt]=zt();function Jt({options:e,children:t,components:n,storage:r}){const o=g.useRef(!1),[s,i]=g.useState(null),d=g.useMemo(()=>new Kt({components:n}),[n]);return g.useEffect(()=>{o.current||(o.current=!0,Ht.WidgetCtx.initialize({config:e,storage:r}).then(i))},[]),s?Gt.jsx(Yt,{value:{widgetCtx:s,components:n,componentStore:d,version:kt},children:t}):null}function Xt(){const{widgetCtx:e}=K();return e.config}function ee(e){return g.useSyncExternalStore(e.subscribe,e.get,e.get)}function Qt(){const{widgetCtx:e}=K();return{contactState:ee(e.contactCtx.state),createUnverifiedContact:e.contactCtx.createUnverifiedContact}}function tt(){const{widgetCtx:e}=K();return{messagesState:ee(e.messageCtx.state),sendMessage:e.messageCtx.sendMessage}}function nt(){const{widgetCtx:e}=K(),t=ee(e.sessionCtx.sessionState),n=ee(e.sessionCtx.sessionsState);return{sessionState:t,sessionsState:n,loadMoreSessions:e.sessionCtx.loadMoreSessions}}function Zt(){var s,i;const{sessionState:e}=nt(),{messagesState:t}=tt(),n=((s=e.session)==null?void 0:s.assignee.kind)==="ai",r=((i=t.messages.at(-1))==null?void 0:i.type)==="FROM_USER";return{isAwaitingBotReply:(n||e.isCreatingSession)&&(t.isSendingMessage||r)}}var en=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function nn(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}),n}var Oe={exports:{}},ye={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* use-sync-external-store-shim.production.min.js
|
|
4
4
|
*
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*/var Ye;function on(){return Ye||(Ye=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=g,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(R){{for(var S=arguments.length,w=new Array(S>1?S-1:0),v=1;v<S;v++)w[v-1]=arguments[v];r("error",R,w)}}function r(R,S,w){{var v=t.ReactDebugCurrentFrame,I=v.getStackAddendum();I!==""&&(S+="%s",w=w.concat([I]));var m=w.map(function(D){return String(D)});m.unshift("Warning: "+S),Function.prototype.apply.call(console[R],console,m)}}function o(R,S){return R===S&&(R!==0||1/R===1/S)||R!==R&&S!==S}var s=typeof Object.is=="function"?Object.is:o,i=e.useState,d=e.useEffect,_=e.useLayoutEffect,f=e.useDebugValue,a=!1,u=!1;function l(R,S,w){a||e.startTransition!==void 0&&(a=!0,n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=S();if(!u){var I=S();s(v,I)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var m=i({inst:{value:v,getSnapshot:S}}),D=m[0].inst,P=m[1];return _(function(){D.value=v,D.getSnapshot=S,c(D)&&P({inst:D})},[R,v,S]),d(function(){c(D)&&P({inst:D});var B=function(){c(D)&&P({inst:D})};return R(B)},[R]),f(v),v}function c(R){var S=R.getSnapshot,w=R.value;try{var v=S();return!s(w,v)}catch{return!0}}function y(R,S,w){return S()}var h=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",T=!h,p=T?y:l,k=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p;ge.useSyncExternalStore=k,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ge}process.env.NODE_ENV==="production"?Oe.exports=rn():Oe.exports=on();var sn=Oe.exports;const H=()=>{},L=H(),Ee=Object,E=e=>e===L,N=e=>typeof e=="function",$=(e,t)=>({...e,...t}),an=e=>N(e.then),ue=new WeakMap;let un=0;const oe=e=>{const t=typeof e,n=e&&e.constructor,r=n==Date;let o,s;if(Ee(e)===e&&!r&&n!=RegExp){if(o=ue.get(e),o)return o;if(o=++un+"~",ue.set(e,o),n==Array){for(o="@",s=0;s<e.length;s++)o+=oe(e[s])+",";ue.set(e,o)}if(n==Ee){o="#";const i=Ee.keys(e).sort();for(;!E(s=i.pop());)E(e[s])||(o+=s+":"+oe(e[s])+",");ue.set(e,o)}}else o=r?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return o},q=new WeakMap,Se={},ce={},Pe="undefined",de=typeof window!=Pe,Re=typeof document!=Pe,cn=()=>de&&typeof window.requestAnimationFrame!=Pe,rt=(e,t)=>{const n=q.get(e);return[()=>!E(t)&&e.get(t)||Se,r=>{if(!E(t)){const o=e.get(t);t in ce||(ce[t]=o),n[5](t,$(o,r),o||Se)}},n[6],()=>!E(t)&&t in ce?ce[t]:!E(t)&&e.get(t)||Se]};let Ce=!0;const fn=()=>Ce,[Te,De]=de&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[H,H],ln=()=>{const e=Re&&document.visibilityState;return E(e)||e!=="hidden"},dn=e=>(Re&&document.addEventListener("visibilitychange",e),Te("focus",e),()=>{Re&&document.removeEventListener("visibilitychange",e),De("focus",e)}),pn=e=>{const t=()=>{Ce=!0,e()},n=()=>{Ce=!1};return Te("online",t),Te("offline",n),()=>{De("online",t),De("offline",n)}},_n={isOnline:fn,isVisible:ln},hn={initFocus:dn,initReconnect:pn},Je=!g.useId,se=!de||"Deno"in window,yn=e=>cn()?window.requestAnimationFrame(e):setTimeout(e,1),ve=se?g.useEffect:g.useLayoutEffect,we=typeof navigator<"u"&&navigator.connection,Xe=!se&&we&&(["slow-2g","2g"].includes(we.effectiveType)||we.saveData),Le=e=>{if(N(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?oe(e):"",[e,t]};let gn=0;const Ae=()=>++gn,ot=0,st=1,it=2,En=3;var re={__proto__:null,ERROR_REVALIDATE_EVENT:En,FOCUS_EVENT:ot,MUTATE_EVENT:it,RECONNECT_EVENT:st};async function at(...e){const[t,n,r,o]=e,s=$({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=s.populateCache;const d=s.rollbackOnError;let _=s.optimisticData;const f=l=>typeof d=="function"?d(l):d!==!1,a=s.throwOnError;if(N(n)){const l=n,c=[],y=t.keys();for(const h of y)!/^\$(inf|sub)\$/.test(h)&&l(t.get(h)._k)&&c.push(h);return Promise.all(c.map(u))}return u(n);async function u(l){const[c]=Le(l);if(!c)return;const[y,h]=rt(t,c),[T,p,k,R]=q.get(t),S=()=>{const M=T[c];return(N(s.revalidate)?s.revalidate(y().data,l):s.revalidate!==!1)&&(delete k[c],delete R[c],M&&M[0])?M[0](it).then(()=>y().data):y().data};if(e.length<3)return S();let w=r,v;const I=Ae();p[c]=[I,0];const m=!E(_),D=y(),P=D.data,B=D._c,z=E(B)?P:B;if(m&&(_=N(_)?_(z,P):_,h({data:_,_c:z})),N(w))try{w=w(z)}catch(M){v=M}if(w&&an(w))if(w=await w.catch(M=>{v=M}),I!==p[c][0]){if(v)throw v;return w}else v&&m&&f(v)&&(i=!0,h({data:z,_c:L}));if(i&&!v)if(N(i)){const M=i(w,z);h({data:M,error:L,_c:L})}else h({data:w,error:L,_c:L});if(p[c][1]=Ae(),Promise.resolve(S()).then(()=>{h({_c:L})}),v){if(a)throw v;return}return w}}const Qe=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},Sn=(e,t)=>{if(!q.has(e)){const n=$(hn,t),r={},o=at.bind(L,e);let s=H;const i={},d=(a,u)=>{const l=i[a]||[];return i[a]=l,l.push(u),()=>l.splice(l.indexOf(u),1)},_=(a,u,l)=>{e.set(a,u);const c=i[a];if(c)for(const y of c)y(u,l)},f=()=>{if(!q.has(e)&&(q.set(e,[r,{},{},{},o,_,d]),!se)){const a=n.initFocus(setTimeout.bind(L,Qe.bind(L,r,ot))),u=n.initReconnect(setTimeout.bind(L,Qe.bind(L,r,st)));s=()=>{a&&a(),u&&u(),q.delete(e)}}};return f(),[e,o,f,s]}return[e,q.get(e)[4]]},vn=(e,t,n,r,o)=>{const s=n.errorRetryCount,i=o.retryCount,d=~~((Math.random()+.5)*(1<<(i<8?i:8)))*n.errorRetryInterval;!E(s)&&i>s||setTimeout(r,d,o)},wn=(e,t)=>oe(e)==oe(t),[ut,mn]=Sn(new Map),bn=$({onLoadingSlow:H,onSuccess:H,onError:H,onErrorRetry:vn,onDiscarded:H,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Xe?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Xe?5e3:3e3,compare:wn,isPaused:()=>!1,cache:ut,mutate:mn,fallback:{}},_n),On=(e,t)=>{const n=$(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:i}=t;r&&s&&(n.use=r.concat(s)),o&&i&&(n.fallback=$(o,i))}return n},Rn=g.createContext({}),Cn="$inf$",ct=de&&window.__SWR_DEVTOOLS_USE__,Tn=ct?window.__SWR_DEVTOOLS_USE__:[],Dn=()=>{ct&&(window.__SWR_DEVTOOLS_REACT__=g)},An=e=>N(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],xn=()=>$(bn,g.useContext(Rn)),jn=e=>(t,n,r)=>e(t,n&&((...s)=>{const[i]=Le(t),[,,,d]=q.get(ut);if(i.startsWith(Cn))return n(...s);const _=d[i];return E(_)?n(...s):(delete d[i],_)}),r),Pn=Tn.concat(jn),Ln=e=>function(...n){const r=xn(),[o,s,i]=An(n),d=On(r,i);let _=e;const{use:f}=d,a=(f||[]).concat(Pn);for(let u=a.length;u--;)_=a[u](_);return _(o,s||d.fetcher||null,d)},In=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};Dn();const Ze=g.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),me={dedupe:!0},Vn=(e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:i,revalidateOnMount:d,revalidateIfStale:_,refreshInterval:f,refreshWhenHidden:a,refreshWhenOffline:u,keepPreviousData:l}=n,[c,y,h,T]=q.get(r),[p,k]=Le(e),R=g.useRef(!1),S=g.useRef(!1),w=g.useRef(p),v=g.useRef(t),I=g.useRef(n),m=()=>I.current,D=()=>m().isVisible()&&m().isOnline(),[P,B,z,M]=rt(r,p),Y=g.useRef({}).current,Mt=E(i)?n.fallback[p]:i,Fe=(b,O)=>{for(const x in Y){const C=x;if(C==="data"){if(!o(b[C],O[C])&&(!E(b[C])||!o(ae,O[C])))return!1}else if(O[C]!==b[C])return!1}return!0},Ne=g.useMemo(()=>{const b=!p||!t?!1:E(d)?m().isPaused()||s?!1:E(_)?!0:_:d,O=j=>{const U=$(j);return delete U._k,b?{isValidating:!0,isLoading:!0,...U}:U},x=P(),C=M(),F=O(x),Z=x===C?F:O(C);let A=F;return[()=>{const j=O(P());return Fe(j,A)?(A.data=j.data,A.isLoading=j.isLoading,A.isValidating=j.isValidating,A.error=j.error,A):(A=j,j)},()=>Z]},[r,p]),J=sn.useSyncExternalStore(g.useCallback(b=>z(p,(O,x)=>{Fe(x,O)||b()}),[r,p]),Ne[0],Ne[1]),Ue=!R.current,Ft=c[p]&&c[p].length>0,X=J.data,Q=E(X)?Mt:X,ie=J.error,We=g.useRef(Q),ae=l?E(X)?We.current:X:Q,qe=Ft&&!E(ie)?!1:Ue&&!E(d)?d:m().isPaused()?!1:s?E(Q)?!1:_:E(Q)||_,Be=!!(p&&t&&Ue&&qe),Nt=E(J.isValidating)?Be:J.isValidating,Ut=E(J.isLoading)?Be:J.isLoading,ne=g.useCallback(async b=>{const O=v.current;if(!p||!O||S.current||m().isPaused())return!1;let x,C,F=!0;const Z=b||{},A=!h[p]||!Z.dedupe,j=()=>Je?!S.current&&p===w.current&&R.current:p===w.current,U={isValidating:!1,isLoading:!1},He=()=>{B(U)},$e=()=>{const V=h[p];V&&V[1]===C&&delete h[p]},Ke={isValidating:!0};E(P().data)&&(Ke.isLoading=!0);try{if(A&&(B(Ke),n.loadingTimeout&&E(P().data)&&setTimeout(()=>{F&&j()&&m().onLoadingSlow(p,n)},n.loadingTimeout),h[p]=[O(k),Ae()]),[x,C]=h[p],x=await x,A&&setTimeout($e,n.dedupingInterval),!h[p]||h[p][1]!==C)return A&&j()&&m().onDiscarded(p),!1;U.error=L;const V=y[p];if(!E(V)&&(C<=V[0]||C<=V[1]||V[1]===0))return He(),A&&j()&&m().onDiscarded(p),!1;const W=P().data;U.data=o(W,x)?W:x,A&&j()&&m().onSuccess(x,p,n)}catch(V){$e();const W=m(),{shouldRetryOnError:_e}=W;W.isPaused()||(U.error=V,A&&j()&&(W.onError(V,p,W),(_e===!0||N(_e)&&_e(V))&&(!m().revalidateOnFocus||!m().revalidateOnReconnect||D())&&W.onErrorRetry(V,p,W,Wt=>{const he=c[p];he&&he[0]&&he[0](re.ERROR_REVALIDATE_EVENT,Wt)},{retryCount:(Z.retryCount||0)+1,dedupe:!0})))}return F=!1,He(),!0},[p,r]),Ge=g.useCallback((...b)=>at(r,w.current,...b),[]);if(ve(()=>{v.current=t,I.current=n,E(X)||(We.current=X)}),ve(()=>{if(!p)return;const b=ne.bind(L,me);let O=0;const C=In(p,c,(F,Z={})=>{if(F==re.FOCUS_EVENT){const A=Date.now();m().revalidateOnFocus&&A>O&&D()&&(O=A+m().focusThrottleInterval,b())}else if(F==re.RECONNECT_EVENT)m().revalidateOnReconnect&&D()&&b();else{if(F==re.MUTATE_EVENT)return ne();if(F==re.ERROR_REVALIDATE_EVENT)return ne(Z)}});return S.current=!1,w.current=p,R.current=!0,B({_k:k}),qe&&(E(Q)||se?b():yn(b)),()=>{S.current=!0,C()}},[p]),ve(()=>{let b;function O(){const C=N(f)?f(P().data):f;C&&b!==-1&&(b=setTimeout(x,C))}function x(){!P().error&&(a||m().isVisible())&&(u||m().isOnline())?ne(me).then(O):O()}return O(),()=>{b&&(clearTimeout(b),b=-1)}},[f,a,u,p]),g.useDebugValue(ae),s&&E(Q)&&p){if(!Je&&se)throw new Error("Fallback data is required when using suspense in SSR.");v.current=t,I.current=n,S.current=!1;const b=T[p];if(!E(b)){const O=Ge(b);Ze(O)}if(E(ie)){const O=ne(me);E(ae)||(O.status="fulfilled",O.value=!0),Ze(O)}else throw ie}return{mutate:Ge,get data(){return Y.data=!0,ae},get error(){return Y.error=!0,ie},get isValidating(){return Y.isValidating=!0,Nt},get isLoading(){return Y.isLoading=!0,Ut}}},Mn=Ln(Vn);function Fn(){const{widgetCtx:e}=K();return Mn([e.config.token],e.api.widgetPrelude,{revalidateOnFocus:!1})}function Nn(){const{widgetCtx:e}=K();return{routerState:ee(e.routerCtx.state),toSessionsScreen:e.routerCtx.toSessionsScreen,toChatScreen:e.routerCtx.toChatScreen}}var ft={},xe=function(e,t){return xe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},xe(e,t)};function lt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");xe(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}exports.__assign=function(){return exports.__assign=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},exports.__assign.apply(this,arguments)};function Ie(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function dt(e,t,n,r){var o=arguments.length,s=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(e,t,n,r);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function pt(e,t){return function(n,r){t(n,r,e)}}function _t(e,t,n,r,o,s){function i(p){if(p!==void 0&&typeof p!="function")throw new TypeError("Function expected");return p}for(var d=r.kind,_=d==="getter"?"get":d==="setter"?"set":"value",f=!t&&e?r.static?e:e.prototype:null,a=t||(f?Object.getOwnPropertyDescriptor(f,r.name):{}),u,l=!1,c=n.length-1;c>=0;c--){var y={};for(var h in r)y[h]=h==="access"?{}:r[h];for(var h in r.access)y.access[h]=r.access[h];y.addInitializer=function(p){if(l)throw new TypeError("Cannot add initializers after decoration has completed");s.push(i(p||null))};var T=(0,n[c])(d==="accessor"?{get:a.get,set:a.set}:a[_],y);if(d==="accessor"){if(T===void 0)continue;if(T===null||typeof T!="object")throw new TypeError("Object expected");(u=i(T.get))&&(a.get=u),(u=i(T.set))&&(a.set=u),(u=i(T.init))&&o.unshift(u)}else(u=i(T))&&(d==="field"?o.unshift(u):a[_]=u)}f&&Object.defineProperty(f,r.name,a),l=!0}function ht(e,t,n){for(var r=arguments.length>2,o=0;o<t.length;o++)n=r?t[o].call(e,n):t[o].call(e);return r?n:void 0}function yt(e){return typeof e=="symbol"?e:"".concat(e)}function gt(e,t,n){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function Et(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function St(e,t,n,r){function o(s){return s instanceof n?s:new n(function(i){i(s)})}return new(n||(n=Promise))(function(s,i){function d(a){try{f(r.next(a))}catch(u){i(u)}}function _(a){try{f(r.throw(a))}catch(u){i(u)}}function f(a){a.done?s(a.value):o(a.value).then(d,_)}f((r=r.apply(e,t||[])).next())})}function vt(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=d(0),i.throw=d(1),i.return=d(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(f){return function(a){return _([f,a])}}function _(f){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,f[0]&&(n=0)),n;)try{if(r=1,o&&(s=f[0]&2?o.return:f[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,f[1])).done)return s;switch(o=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return n.label++,{value:f[1],done:!1};case 5:n.label++,o=f[1],f=[0];continue;case 7:f=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){n=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){n.label=f[1];break}if(f[0]===6&&n.label<s[1]){n.label=s[1],s=f;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(f);break}s[2]&&n.ops.pop(),n.trys.pop();continue}f=t.call(e,n)}catch(a){f=[6,a],o=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}var pe=Object.create?function(e,t,n,r){r===void 0&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]};function wt(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&pe(t,e,n)}function le(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ve(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,s=[],i;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(d){i={error:d}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function mt(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Ve(arguments[t]));return e}function bt(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var s=arguments[t],i=0,d=s.length;i<d;i++,o++)r[o]=s[i];return r}function Me(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function te(e){return this instanceof te?(this.v=e,this):new te(e)}function Ot(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),d("next"),d("throw"),d("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(c){return function(y){return Promise.resolve(y).then(c,u)}}function d(c,y){r[c]&&(o[c]=function(h){return new Promise(function(T,p){s.push([c,h,T,p])>1||_(c,h)})},y&&(o[c]=y(o[c])))}function _(c,y){try{f(r[c](y))}catch(h){l(s[0][3],h)}}function f(c){c.value instanceof te?Promise.resolve(c.value.v).then(a,u):l(s[0][2],c)}function a(c){_("next",c)}function u(c){_("throw",c)}function l(c,y){c(y),s.shift(),s.length&&_(s[0][0],s[0][1])}}function Rt(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,s){t[o]=e[o]?function(i){return(n=!n)?{value:te(e[o](i)),done:!1}:s?s(i):i}:s}}function Ct(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof le=="function"?le(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(i){return new Promise(function(d,_){i=e[s](i),o(d,_,i.done,i.value)})}}function o(s,i,d,_){Promise.resolve(_).then(function(f){s({value:f,done:d})},i)}}function Tt(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var Un=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function Dt(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&pe(t,e,n);return Un(t,e),t}function At(e){return e&&e.__esModule?e:{default:e}}function xt(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)}function jt(e,t,n,r,o){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?o.call(e,n):o?o.value=n:t.set(e,n),n}function Pt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function Lt(e,t,n){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var r,o;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=t[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=t[Symbol.dispose],n&&(o=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");o&&(r=function(){try{o.call(this)}catch(s){return Promise.reject(s)}}),e.stack.push({value:t,dispose:r,async:n})}else n&&e.stack.push({async:!0});return t}var Wn=typeof SuppressedError=="function"?SuppressedError:function(e,t,n){var r=new Error(n);return r.name="SuppressedError",r.error=e,r.suppressed=t,r};function It(e){function t(s){e.error=e.hasError?new Wn(s,e.error,"An error was suppressed during disposal."):s,e.hasError=!0}var n,r=0;function o(){for(;n=e.stack.pop();)try{if(!n.async&&r===1)return r=0,e.stack.push(n),Promise.resolve().then(o);if(n.dispose){var s=n.dispose.call(n.value);if(n.async)return r|=2,Promise.resolve(s).then(o,function(i){return t(i),o()})}else r|=1}catch(i){t(i)}if(r===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return o()}function Vt(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(n,r,o,s,i){return r?t?".jsx":".js":o&&(!s||!i)?n:o+s+"."+i.toLowerCase()+"js"}):e}const qn={__extends:lt,__assign:exports.__assign,__rest:Ie,__decorate:dt,__param:pt,__esDecorate:_t,__runInitializers:ht,__propKey:yt,__setFunctionName:gt,__metadata:Et,__awaiter:St,__generator:vt,__createBinding:pe,__exportStar:wt,__values:le,__read:Ve,__spread:mt,__spreadArrays:bt,__spreadArray:Me,__await:te,__asyncGenerator:Ot,__asyncDelegator:Rt,__asyncValues:Ct,__makeTemplateObject:Tt,__importStar:Dt,__importDefault:At,__classPrivateFieldGet:xt,__classPrivateFieldSet:jt,__classPrivateFieldIn:Pt,__addDisposableResource:Lt,__disposeResources:It,__rewriteRelativeImportExtension:Vt},Bn=Object.freeze(Object.defineProperty({__proto__:null,__addDisposableResource:Lt,get __assign(){return exports.__assign},__asyncDelegator:Rt,__asyncGenerator:Ot,__asyncValues:Ct,__await:te,__awaiter:St,__classPrivateFieldGet:xt,__classPrivateFieldIn:Pt,__classPrivateFieldSet:jt,__createBinding:pe,__decorate:dt,__disposeResources:It,__esDecorate:_t,__exportStar:wt,__extends:lt,__generator:vt,__importDefault:At,__importStar:Dt,__makeTemplateObject:Tt,__metadata:Et,__param:pt,__propKey:yt,__read:Ve,__rest:Ie,__rewriteRelativeImportExtension:Vt,__runInitializers:ht,__setFunctionName:gt,__spread:mt,__spreadArray:Me,__spreadArrays:bt,__values:le,default:qn},Symbol.toStringTag,{value:"Module"})),Gn=nn(Bn);var fe={},et;function Hn(){if(et)return fe;et=1,Object.defineProperty(fe,"__esModule",{value:!0});var e=g;function t(){var n=e.useRef(!1),r=e.useCallback(function(){return n.current},[]);return e.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),r}return fe.default=t,fe}Object.defineProperty(ft,"__esModule",{value:!0});var je=Gn,be=g,$n=je.__importDefault(Hn());function Kn(e,t,n){t===void 0&&(t=[]),n===void 0&&(n={loading:!1});var r=be.useRef(0),o=$n.default(),s=be.useState(n),i=s[0],d=s[1],_=be.useCallback(function(){for(var f=[],a=0;a<arguments.length;a++)f[a]=arguments[a];var u=++r.current;return i.loading||d(function(l){return je.__assign(je.__assign({},l),{loading:!0})}),e.apply(void 0,f).then(function(l){return o()&&u===r.current&&d({value:l,loading:!1}),l},function(l){return o()&&u===r.current&&d({error:l,loading:!1}),l})},t);return[i,_]}var zn=ft.default=Kn;const G=new Map;function kn(){const[e,t]=g.useState([]),{widgetCtx:{api:n}}=K();function r(a){const u=a.map(l=>({file:l,id:$t.v4(),status:"pending",progress:0}));t(l=>[...l,...u]),u.forEach(i)}function o(a,u){t(l=>l.map(c=>c.id===a?{...c,...u}:c))}function s(a){t(u=>u.filter(l=>l.id!==a))}const i=async a=>{const u=new AbortController;G.set(a.id,u);try{t(c=>c.map(y=>y.id===a.id?{...y,status:"uploading",progress:0}:y));const l=await n.uploadFile(a,{signal:u.signal,onUploadProgress:c=>{if(!c.total)return;const y=Math.round(c.loaded*100/c.total);o(a.id,{progress:y})}});o(a.id,{status:"success",fileUrl:l.fileUrl,progress:100})}catch(l){u.signal.aborted||o(a.id,{status:"error",error:l instanceof Error?l.message:"Upload failed",progress:0})}finally{G.delete(a.id)}},d=a=>{const u=G.get(a);u&&(u.abort(),G.delete(a)),s(a)},_=g.useMemo(()=>e.filter(a=>a.status==="success"&&a.fileUrl),[e]);function f(){G.forEach(a=>a.abort()),G.clear(),t([])}return g.useEffect(()=>()=>{G.forEach(a=>a.abort()),G.clear()},[]),{allFiles:e,appendFiles:r,handleCancelUpload:d,successFiles:_,emptyTheFiles:f,getFileById:a=>e.find(u=>u.id===a),getUploadProgress:a=>{var u;return((u=e.find(l=>l.id===a))==null?void 0:u.progress)??0},getUploadStatus:a=>{var u;return(u=e.find(l=>l.id===a))==null?void 0:u.status},hasErrors:e.some(a=>a.status==="error"),isUploading:e.some(a=>a.status==="uploading")}}exports.WidgetProvider=Jt;exports.__rest=Ie;exports.__spreadArray=Me;exports._default=zn;exports.commonjsGlobal=en;exports.getDefaultExportFromCjs=tn;exports.useConfig=Xt;exports.useContact=Qt;exports.useIsAwaitingBotReply=Zt;exports.useMessages=tt;exports.usePreludeData=Fn;exports.usePrimitiveState=ee;exports.useSessions=nt;exports.useUploadFiles=kn;exports.useWidget=K;exports.useWidgetRouter=Nn;
|
|
18
|
-
//# sourceMappingURL=useUploadFiles-
|
|
18
|
+
//# sourceMappingURL=useUploadFiles-CH6LO6bs.cjs.map
|