@epam/ai-dial-chat-hooks 1.5.0-dev.35 → 1.5.0-dev.36

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.
Files changed (37) hide show
  1. package/external-services/useExternalServiceLogin.js +7 -7
  2. package/external-services.js +3 -3
  3. package/index.js +247 -247
  4. package/oauth/batch-channel.d.ts +42 -0
  5. package/oauth/batch-channel.d.ts.map +1 -0
  6. package/oauth/batch-channel.js +90 -0
  7. package/oauth/handshake.d.ts +59 -2
  8. package/oauth/handshake.d.ts.map +1 -1
  9. package/oauth/handshake.js +204 -35
  10. package/oauth/models.d.ts +90 -1
  11. package/oauth/models.d.ts.map +1 -1
  12. package/oauth/popup.d.ts +35 -1
  13. package/oauth/popup.d.ts.map +1 -1
  14. package/oauth/popup.js +35 -15
  15. package/oauth/redirect-state.d.ts +12 -0
  16. package/oauth/redirect-state.d.ts.map +1 -0
  17. package/oauth/redirect-state.js +20 -0
  18. package/oauth/types.d.ts +41 -2
  19. package/oauth/types.d.ts.map +1 -1
  20. package/oauth/types.js +9 -3
  21. package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.d.ts +11 -5
  22. package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.d.ts.map +1 -1
  23. package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js +95 -66
  24. package/oauth/useToolsetLogin/useToolsetLogin.d.ts +11 -1
  25. package/oauth/useToolsetLogin/useToolsetLogin.d.ts.map +1 -1
  26. package/oauth/useToolsetLogin/useToolsetLogin.js +96 -45
  27. package/oauth.js +10 -10
  28. package/offline-credentials/useOfflineCredentialsLogin/useOfflineCredentialsLogin.js +5 -5
  29. package/package.json +17 -17
  30. package/signin-interrupt/models.d.ts +25 -1
  31. package/signin-interrupt/models.d.ts.map +1 -1
  32. package/signin-interrupt/types.d.ts +12 -1
  33. package/signin-interrupt/types.d.ts.map +1 -1
  34. package/signin-interrupt/types.js +4 -2
  35. package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.d.ts +29 -5
  36. package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.d.ts.map +1 -1
  37. package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.js +412 -134
@@ -4,188 +4,210 @@ import { buildExternalServiceScopeId as n } from "../../shared/external-services
4
4
  import { ExternalServiceAuthType as r, ExternalServiceLoginOutcomeType as i } from "../../external-services/useExternalServiceLogin.js";
5
5
  import { PendingSigninEventKind as a } from "../../shared/client-channel.js";
6
6
  import { getSigninEventResourceKey as o, resolveExternalServiceSigninRowInfo as s, resolveToolsetSigninRowInfo as c } from "../signin-row-info.js";
7
- import { SigninInterruptAnnouncementKind as l, SigninInterruptRowError as u, SigninInterruptRowStatus as d } from "../types.js";
7
+ import { SigninInterruptAnnouncementKind as l, SigninInterruptRowError as u, SigninInterruptRowStatus as d, SigninInterruptRunPhase as ee } from "../types.js";
8
8
  import { ReportClientChannelDtoResultEnum as f } from "@epam/ai-dial-chat-api-client";
9
9
  import { useCallback as p, useEffect as m, useMemo as h, useRef as g, useState as _ } from "react";
10
10
  //#region src/signin-interrupt/useSigninInterrupt/useSigninInterrupt.ts
11
- var v = {
11
+ var te = {
12
12
  status: d.Idle,
13
13
  apiKey: ""
14
- }, y = (e, t) => e.kind === a.Toolset ? c(e.toolsetId, void 0, t, t) : s(e.serviceName, void 0), b = ({ pendingEvents: b, toolsets: x, activeLocale: S, primaryLocale: C, getToolset: w, getExternalService: T, loginToolset: E, loginExternalService: D, refetchToolsets: O, reportEvent: k }) => {
15
- let [A, j] = _({}), [M, N] = _({}), [P, F] = _({}), [I, L] = _(), [R, z] = _(!0), B = g(/* @__PURE__ */ new Set()), V = g(/* @__PURE__ */ new Set()), H = g(/* @__PURE__ */ new Set()), U = p((e) => A[e] ?? v, [A]);
14
+ }, ne = /* @__PURE__ */ new Set([e.ApiKey, e.OAuth]), re = (e, t) => e.kind === a.Toolset ? c(e.toolsetId, void 0, t, t) : s(e.serviceName, void 0), ie = (e, t) => `${o(e)}::${t.credentialsLevel}`, v = ({ pendingEvents: v, toolsets: y, activeLocale: ae, primaryLocale: b, getToolset: oe, getExternalService: se, loginToolset: x, loginExternalService: ce, refetchToolsets: S, reportEvent: le, channelId: C, isBulkLoginEnabled: w = !1, createBatchSession: T }) => {
15
+ let [E, D] = _({}), [O, ue] = _({}), [k, de] = _({}), [fe, A] = _(), [j, pe] = _(!0), [M, me] = _(), [he, ge] = _(), _e = g(/* @__PURE__ */ new Set()), N = g(/* @__PURE__ */ new Set()), P = g(/* @__PURE__ */ new Set()), F = g(null), I = g({
16
+ pendingEvents: v,
17
+ channelId: C,
18
+ isBulkLoginEnabled: w,
19
+ loginToolset: x,
20
+ refetchToolsets: S,
21
+ reportEvent: le
22
+ });
23
+ I.current = {
24
+ pendingEvents: v,
25
+ channelId: C,
26
+ isBulkLoginEnabled: w,
27
+ loginToolset: x,
28
+ refetchToolsets: S,
29
+ reportEvent: le
30
+ };
31
+ let L = p((e) => E[e] ?? te, [E]);
16
32
  m(() => {
17
- let e = new Set(b.map((e) => e.id));
18
- j((t) => {
33
+ let e = new Set(v.map((e) => e.id));
34
+ D((t) => {
19
35
  let n = !1, r = {};
20
36
  for (let [i, a] of Object.entries(t)) e.has(i) ? r[i] = a : n = !0;
21
37
  return n ? r : t;
22
38
  });
23
- for (let t of Array.from(H.current)) e.has(t) || H.current.delete(t);
24
- }, [b]);
25
- let W = p((e, t) => {
26
- j((n) => ({
39
+ for (let t of Array.from(P.current)) e.has(t) || P.current.delete(t);
40
+ }, [v]);
41
+ let R = p((e, t) => {
42
+ D((n) => ({
27
43
  ...n,
28
44
  [e]: {
29
- ...n[e] ?? v,
45
+ ...n[e] ?? te,
30
46
  ...t
31
47
  }
32
48
  }));
49
+ }, []), z = p((e, t) => {
50
+ e.length !== 0 && D((n) => {
51
+ let r = { ...n };
52
+ for (let i of e) r[i] = {
53
+ ...n[i] ?? te,
54
+ ...t
55
+ };
56
+ return r;
57
+ });
33
58
  }, []);
34
59
  m(() => {
35
60
  let e = async (e) => {
36
61
  try {
37
- let t = await w(e);
38
- N((n) => ({
62
+ let t = await oe(e);
63
+ ue((n) => ({
39
64
  ...n,
40
65
  [e]: t
41
66
  }));
42
67
  } catch {} finally {
43
- B.current.delete(e);
68
+ _e.current.delete(e);
44
69
  }
45
70
  }, t = async (e, t, n) => {
46
71
  try {
47
- let r = await T(e, t);
48
- F((e) => ({
72
+ let r = await se(e, t);
73
+ de((e) => ({
49
74
  ...e,
50
75
  [n]: r
51
76
  }));
52
77
  } catch {} finally {
53
- V.current.delete(n);
78
+ N.current.delete(n);
54
79
  }
55
80
  };
56
- for (let r of b) if (r.kind === a.Toolset) {
57
- if ((x.find((e) => e.id === r.toolsetId) ?? M[r.toolsetId]) || B.current.has(r.toolsetId)) continue;
58
- B.current.add(r.toolsetId), e(r.toolsetId);
81
+ for (let r of v) if (r.kind === a.Toolset) {
82
+ if ((y.find((e) => e.id === r.toolsetId) ?? O[r.toolsetId]) || _e.current.has(r.toolsetId)) continue;
83
+ _e.current.add(r.toolsetId), e(r.toolsetId);
59
84
  } else {
60
85
  let { appId: e, serviceName: i } = r, a = n(e, i);
61
- if (P[a] || V.current.has(a)) continue;
62
- V.current.add(a), t(e, i, a);
86
+ if (k[a] || N.current.has(a)) continue;
87
+ N.current.add(a), t(e, i, a);
63
88
  }
64
89
  }, [
65
- b,
66
- x,
67
- M,
68
- P,
69
- w,
70
- T
90
+ v,
91
+ y,
92
+ O,
93
+ k,
94
+ oe,
95
+ se
71
96
  ]);
72
- let G = h(() => {
97
+ let B = h(() => {
73
98
  let e = /* @__PURE__ */ new Map();
74
- for (let t of b) {
99
+ for (let t of v) {
75
100
  let n = o(t);
76
101
  if (!e.has(n)) {
77
102
  if (t.kind === a.Toolset) {
78
- let r = x.find((e) => e.id === t.toolsetId) ?? M[t.toolsetId];
79
- e.set(n, c(t.toolsetId, r, S, C));
80
- } else e.set(n, s(t.serviceName, P[n]));
103
+ let r = y.find((e) => e.id === t.toolsetId) ?? O[t.toolsetId];
104
+ e.set(n, c(t.toolsetId, r, ae, b));
105
+ } else e.set(n, s(t.serviceName, k[n]));
81
106
  }
82
107
  }
83
108
  return e;
84
109
  }, [
85
- b,
86
- x,
87
- M,
88
- P,
89
- S,
90
- C
91
- ]), K = p((e) => G.get(o(e)) ?? y(e, C), [G, C]), q = p(async (e, t) => {
92
- await k(e, f.Success), L({
110
+ v,
111
+ y,
112
+ O,
113
+ k,
114
+ ae,
115
+ b
116
+ ]), V = p((e) => B.get(o(e)) ?? re(e, b), [B, b]), ve = g(V);
117
+ ve.current = V;
118
+ let H = p((e, t, n) => n === void 0 ? I.current.reportEvent(e, t) : I.current.reportEvent(e, t, n), []), ye = p(async (e, t) => {
119
+ await H(e, f.Success, I.current.channelId), A({
93
120
  kind: l.LoginSucceeded,
94
121
  name: t
95
122
  });
96
- }, [k]);
123
+ }, [H]), U = p(async (e, t, n) => {
124
+ let r = await Promise.allSettled(e.map((e) => H(e, f.Success, t))), i = e.filter((e, t) => r[t].status === "rejected");
125
+ z(i, {
126
+ status: d.Idle,
127
+ error: u.ReportFailed,
128
+ isLoginConfirmed: !0,
129
+ confirmedChannelId: t
130
+ }), i.length < e.length && A({
131
+ kind: l.LoginSucceeded,
132
+ name: n
133
+ });
134
+ }, [H, z]);
97
135
  m(() => {
98
- for (let e of b) {
136
+ for (let e of v) {
99
137
  if (e.kind !== a.ExternalService) continue;
100
- let t = G.get(o(e));
101
- t?.authenticationType === r.None && (H.current.has(e.id) || (H.current.add(e.id), q(e.id, t.displayName)));
138
+ let t = B.get(o(e));
139
+ t?.authenticationType === r.None && (P.current.has(e.id) || (P.current.add(e.id), ye(e.id, t.displayName)));
102
140
  }
103
141
  }, [
104
- b,
105
- G,
106
- q
142
+ v,
143
+ B,
144
+ ye
107
145
  ]);
108
- let ee = p((e, t) => {
109
- W(e, {
146
+ let be = p((e, t) => {
147
+ R(e, {
110
148
  apiKey: t,
111
149
  error: void 0
112
150
  });
113
- }, [W]), J = p(async (e) => {
114
- W(e, {
151
+ }, [R]), xe = p(async (e) => {
152
+ R(e, {
115
153
  status: d.Processing,
116
154
  error: void 0
117
155
  });
118
156
  try {
119
- await k(e, f.Denied);
120
- let t = b.find((t) => t.id === e);
121
- L({
157
+ await H(e, f.Denied, I.current.channelId);
158
+ let t = v.find((t) => t.id === e);
159
+ A({
122
160
  kind: l.Declined,
123
- name: t ? G.get(o(t))?.displayName ?? "" : ""
161
+ name: t ? B.get(o(t))?.displayName ?? "" : ""
124
162
  });
125
163
  } catch {
126
- W(e, {
164
+ R(e, {
127
165
  status: d.Idle,
128
166
  error: u.DeclineFailed
129
167
  });
130
168
  }
131
169
  }, [
132
- k,
133
- W,
134
- b,
135
- G
136
- ]), te = p(() => {
137
- for (let e of b) J(e.id);
138
- }, [b, J]), Y = p((e, t) => b.filter((n) => n.id !== e.id && n.kind === e.kind && o(n) === o(e) && G.get(o(n))?.credentialsLevel === t.credentialsLevel).map((e) => e.id), [b, G]), X = p(async (e, t) => {
139
- let n = Y(e, t);
140
- try {
141
- await q(e.id, t.displayName);
142
- } catch {
143
- W(e.id, {
144
- status: d.Idle,
145
- error: u.LoginFailed
146
- });
147
- return;
148
- }
149
- for (let e of n) k(e, f.Success);
150
- }, [
151
- Y,
152
- q,
153
- k,
154
- W
155
- ]), Z = p((e, t) => {
156
- W(e, {
170
+ H,
171
+ R,
172
+ v,
173
+ B
174
+ ]), Se = p((e, t) => v.filter((n) => n.id !== e.id && n.kind === e.kind && o(n) === o(e) && B.get(o(n))?.credentialsLevel === t.credentialsLevel).map((e) => e.id), [v, B]), W = p(async (e, t, n) => {
175
+ let r = Se(e, t);
176
+ await U([e.id, ...r], n, t.displayName);
177
+ }, [Se, U]), G = p((e, t) => {
178
+ R(e, {
157
179
  status: d.Idle,
158
180
  error: t
159
181
  });
160
- }, [W]), Q = p(async (n, r, i) => {
161
- switch ((await E({
182
+ }, [R]), Ce = p(async (n, r, i, a) => {
183
+ switch ((await x({
162
184
  toolsetId: n.toolsetId,
163
185
  credentialsLevel: r.credentialsLevel,
164
186
  authenticationType: r.authenticationType ?? e.ApiKey,
165
187
  apiKey: i,
166
188
  oauthSettings: r.oauthSettings,
167
189
  forceStale: !0,
168
- offlineUsageConsent: R
190
+ offlineUsageConsent: j
169
191
  })).type) {
170
192
  case t.Success:
171
- await O(), await X(n, r);
193
+ await S(), await W(n, r, a);
172
194
  return;
173
195
  case t.PopupBlocked:
174
- Z(n.id, u.PopupBlocked);
196
+ G(n.id, u.PopupBlocked);
175
197
  return;
176
198
  case t.Failure:
177
- Z(n.id, u.LoginFailed);
199
+ G(n.id, u.LoginFailed);
178
200
  return;
179
- default: Z(n.id);
201
+ default: G(n.id);
180
202
  }
181
203
  }, [
182
- E,
183
- R,
184
- O,
185
- X,
186
- Z
187
- ]), $ = p(async (e, t, n) => {
188
- switch ((await D({
204
+ x,
205
+ j,
206
+ S,
207
+ W,
208
+ G
209
+ ]), we = p(async (e, t, n, a) => {
210
+ switch ((await ce({
189
211
  appId: e.appId,
190
212
  serviceId: e.serviceName,
191
213
  credentialsLevel: t.credentialsLevel,
@@ -193,49 +215,295 @@ var v = {
193
215
  apiKey: n,
194
216
  oauthSettings: t.oauthSettings,
195
217
  forceStale: !0,
196
- offlineUsageConsent: R
218
+ offlineUsageConsent: j
197
219
  })).type) {
198
220
  case i.Success:
199
- await X(e, t);
221
+ await W(e, t, a);
200
222
  return;
201
223
  case i.AdminConsentRequired:
202
- Z(e.id, u.AdminConsentRequired);
224
+ G(e.id, u.AdminConsentRequired);
203
225
  return;
204
226
  case i.OfflineUnavailable:
205
- Z(e.id, u.OfflineUnavailable);
227
+ G(e.id, u.OfflineUnavailable);
206
228
  return;
207
229
  case i.PopupBlocked:
208
- Z(e.id, u.PopupBlocked);
230
+ G(e.id, u.PopupBlocked);
209
231
  return;
210
232
  case i.Failure:
211
- Z(e.id, u.LoginFailed);
233
+ G(e.id, u.LoginFailed);
212
234
  return;
213
- default: Z(e.id);
235
+ default: G(e.id);
214
236
  }
215
237
  }, [
216
- D,
217
- R,
218
- X,
219
- Z
220
- ]), ne = p((e) => {
221
- let t = b.find((t) => t.id === e);
238
+ ce,
239
+ j,
240
+ W,
241
+ G
242
+ ]), Te = p((e) => {
243
+ if (F.current) return;
244
+ let t = v.find((t) => t.id === e);
222
245
  if (!t) return;
223
- let n = K(t), { apiKey: r } = U(e);
224
- W(e, {
246
+ let n = V(t), { apiKey: r } = L(e), i = I.current.channelId;
247
+ R(e, {
225
248
  status: d.Processing,
226
249
  error: void 0
227
- }), t.kind === a.Toolset ? Q(t, n, r) : $(t, n, r);
250
+ }), t.kind === a.Toolset ? Ce(t, n, r, i) : we(t, n, r, i);
228
251
  }, [
229
- b,
252
+ v,
253
+ V,
254
+ L,
255
+ R,
256
+ Ce,
257
+ we
258
+ ]), Ee = p(async (e) => {
259
+ let t = E[e];
260
+ if (!t?.isLoginConfirmed) return;
261
+ let n = v.find((t) => t.id === e);
262
+ R(e, {
263
+ status: d.Processing,
264
+ error: void 0
265
+ });
266
+ try {
267
+ await H(e, f.Success, t.confirmedChannelId), A({
268
+ kind: l.LoginSucceeded,
269
+ name: n ? V(n).displayName : ""
270
+ });
271
+ } catch {
272
+ R(e, {
273
+ status: d.Idle,
274
+ error: u.ReportFailed
275
+ });
276
+ }
277
+ }, [
278
+ E,
279
+ v,
280
+ R,
281
+ H,
282
+ V
283
+ ]), K = p((e) => I.current.pendingEvents.filter((t) => t.kind === a.Toolset && ie(t, ve.current(t)) === e.key).map((e) => e.id), []), q = p((e, t) => {
284
+ let n = e.targets[e.index];
285
+ n && me({
286
+ phase: t,
287
+ name: n.displayName,
288
+ position: e.index + 1,
289
+ total: e.targets.length,
290
+ eventId: K(n)[0]
291
+ });
292
+ }, [K]), J = p((e) => {
293
+ let t = Array.from(e.processingIds);
294
+ e.processingIds.clear(), D((e) => {
295
+ let n = !1, r = { ...e };
296
+ for (let e of t) r[e]?.status === d.Processing && (r[e] = {
297
+ ...r[e],
298
+ status: d.Idle
299
+ }, n = !0);
300
+ return n ? r : e;
301
+ });
302
+ }, []), Y = p(() => {
303
+ let e = F.current;
304
+ e && (F.current = null, e.session?.close(), J(e), me(void 0));
305
+ }, [J]), X = p(async (e, t) => {
306
+ await I.current.refetchToolsets(), await U(K(t), e.channelId, t.displayName);
307
+ }, [K, U]), De = p(async (n, r) => {
308
+ let i = r.authenticationType === e.OAuth;
309
+ if (i && !n.session) return { type: "window-lost" };
310
+ let a = !n.staleApplied.has(r.key);
311
+ switch (n.staleApplied.add(r.key), (await I.current.loginToolset({
312
+ toolsetId: r.toolsetId,
313
+ credentialsLevel: r.credentialsLevel,
314
+ authenticationType: r.authenticationType,
315
+ apiKey: r.apiKey,
316
+ oauthSettings: r.oauthSettings,
317
+ forceStale: a,
318
+ offlineUsageConsent: n.consent,
319
+ batchSession: i ? n.session : void 0
320
+ })).type) {
321
+ case t.Success: return { type: "confirmed" };
322
+ case t.Failure: return {
323
+ type: "failed",
324
+ error: u.LoginFailed
325
+ };
326
+ case t.PopupBlocked:
327
+ case t.WindowLost: return { type: "window-lost" };
328
+ default: return { type: "stopped" };
329
+ }
330
+ }, []), Z = p(async (e) => {
331
+ let t = F.current;
332
+ if (!t || t.token !== e || t.isLooping) return;
333
+ let n = () => F.current?.token === e;
334
+ t.isLooping = !0, t.isPaused = !1;
335
+ try {
336
+ for (; n();) {
337
+ if (!I.current.isBulkLoginEnabled || I.current.channelId !== t.channelId) {
338
+ Y();
339
+ return;
340
+ }
341
+ if (await Promise.all(t.lateReports), !n()) return;
342
+ let e = t.targets[t.index];
343
+ for (; e && (t.confirmed.has(e.key) || K(e).length === 0);) t.index += 1, e = t.targets[t.index];
344
+ if (!e) {
345
+ Y();
346
+ return;
347
+ }
348
+ q(t, ee.Running), t.session?.showProgress({
349
+ name: e.displayName,
350
+ position: t.index + 1,
351
+ total: t.targets.length
352
+ });
353
+ let r = K(e);
354
+ for (let e of r) t.processingIds.add(e);
355
+ z(r, {
356
+ status: d.Processing,
357
+ error: void 0
358
+ });
359
+ let i = await De(t, e);
360
+ if (!n()) return;
361
+ switch (i.type) {
362
+ case "confirmed":
363
+ t.confirmed.has(e.key) || (t.confirmed.add(e.key), await X(t, e)), t.processingIds.clear(), t.index += 1;
364
+ break;
365
+ case "failed":
366
+ J(t), z(K(e), { error: i.error }), t.index += 1;
367
+ break;
368
+ case "window-lost":
369
+ J(t), t.isPaused = !0, q(t, ee.Paused);
370
+ return;
371
+ default: return;
372
+ }
373
+ }
374
+ } finally {
375
+ t.isLooping = !1;
376
+ }
377
+ }, [
378
+ Y,
230
379
  K,
231
- U,
232
- W,
380
+ q,
381
+ J,
382
+ X,
383
+ De,
384
+ z
385
+ ]), Q = p((e) => {
386
+ let t = F.current;
387
+ t && t.token === e && t.isPaused && (t.lateReports.size > 0 || Z(e));
388
+ }, [Z]), Oe = p((e, { toolsetId: t, credentialsLevel: n }) => {
389
+ let r = F.current;
390
+ if (!r || r.token !== e) return;
391
+ let i = r.targets.find((e) => e.toolsetId === t && e.credentialsLevel === n);
392
+ if (!i || r.confirmed.has(i.key)) return;
393
+ r.confirmed.add(i.key);
394
+ let a = X(r, i);
395
+ r.lateReports.add(a), a.finally(() => {
396
+ r.lateReports.delete(a), r.session?.hasWindow() && Q(e);
397
+ });
398
+ }, [X, Q]), $ = h(() => v.filter((e) => e.kind === a.Toolset), [v]), ke = h(() => {
399
+ if (!w || M || v.some((e) => L(e.id).status === d.Processing)) return !1;
400
+ let e = /* @__PURE__ */ new Set();
401
+ for (let t of $) {
402
+ let n = V(t);
403
+ if (n.authenticationType == null) return !1;
404
+ ne.has(n.authenticationType) && e.add(ie(t, n));
405
+ }
406
+ return e.size >= 2;
407
+ }, [
408
+ w,
409
+ M,
410
+ v,
411
+ L,
412
+ $,
413
+ V
414
+ ]), Ae = p(() => {
415
+ if (!ke || F.current) return;
416
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
417
+ for (let i of $) {
418
+ let a = V(i);
419
+ if (!ne.has(a.authenticationType ?? "")) continue;
420
+ let o = ie(i, a), s = L(i.id).apiKey.trim(), c = t.get(o);
421
+ c ? !c.apiKey && s && (c.apiKey = s) : (n.set(o, i.id), t.set(o, {
422
+ key: o,
423
+ toolsetId: i.toolsetId,
424
+ credentialsLevel: a.credentialsLevel,
425
+ authenticationType: a.authenticationType === r.OAuth ? e.OAuth : e.ApiKey,
426
+ displayName: a.displayName,
427
+ oauthSettings: a.oauthSettings,
428
+ apiKey: s
429
+ }));
430
+ }
431
+ let i = Array.from(t.values()), a = i.find((t) => t.authenticationType === e.ApiKey && !t.apiKey);
432
+ if (a) {
433
+ let e = n.get(a.key) ?? "";
434
+ R(e, { error: u.ApiKeyRequired }), ge((t) => ({
435
+ eventId: e,
436
+ requestId: (t?.requestId ?? 0) + 1
437
+ }));
438
+ return;
439
+ }
440
+ let o = [...i.filter((t) => t.authenticationType === e.ApiKey), ...i.filter((t) => t.authenticationType === e.OAuth)], s = Symbol("signin-run"), c = o.some((t) => t.authenticationType === e.OAuth) && T ? T({
441
+ onLateSuccess: (e) => Oe(s, e),
442
+ onWindowAvailable: () => Q(s)
443
+ }) : void 0;
444
+ c?.openWindow(), F.current = {
445
+ token: s,
446
+ channelId: I.current.channelId,
447
+ targets: o,
448
+ index: 0,
449
+ consent: j,
450
+ session: c,
451
+ staleApplied: /* @__PURE__ */ new Set(),
452
+ confirmed: /* @__PURE__ */ new Set(),
453
+ processingIds: /* @__PURE__ */ new Set(),
454
+ lateReports: /* @__PURE__ */ new Set(),
455
+ isLooping: !1,
456
+ isPaused: !1
457
+ }, q(F.current, ee.Running), Z(s);
458
+ }, [
459
+ ke,
460
+ $,
461
+ V,
462
+ L,
463
+ R,
464
+ T,
465
+ Oe,
233
466
  Q,
234
- $
467
+ j,
468
+ q,
469
+ Z
470
+ ]), je = p(() => {
471
+ let t = F.current;
472
+ if (t?.isPaused && !t.isLooping) {
473
+ if (t.targets.slice(t.index).some((n) => n.authenticationType === e.OAuth && !t.confirmed.has(n.key) && K(n).length > 0) && t.session && !t.session.hasWindow() && !t.session.openWindow()) {
474
+ let e = t.targets[t.index];
475
+ e && z(K(e), { error: u.PopupBlocked });
476
+ } else Z(t.token);
477
+ }
478
+ }, [
479
+ K,
480
+ Z,
481
+ z
482
+ ]), Me = p(() => {
483
+ Y();
484
+ }, [Y]), Ne = p(() => {
485
+ Y();
486
+ for (let e of v) xe(e.id);
487
+ }, [
488
+ Y,
489
+ v,
490
+ xe
235
491
  ]);
492
+ m(() => {
493
+ let e = F.current;
494
+ e && (!w || C !== e.channelId) && Y();
495
+ }, [
496
+ w,
497
+ C,
498
+ Y
499
+ ]), m(() => () => {
500
+ let e = F.current;
501
+ F.current = null, e?.session?.close();
502
+ }, []);
503
+ let Pe = M != null;
236
504
  return {
237
- rows: h(() => b.map((e) => {
238
- let t = K(e), { status: n, error: i, apiKey: a } = U(e.id), o = t.authenticationType === r.ApiKey;
505
+ rows: h(() => v.map((e) => {
506
+ let t = V(e), { status: n, error: i, apiKey: a, isLoginConfirmed: o } = L(e.id), s = t.authenticationType === r.ApiKey;
239
507
  return {
240
508
  event: e,
241
509
  info: t,
@@ -243,28 +511,38 @@ var v = {
243
511
  isProcessing: n === d.Processing,
244
512
  error: i,
245
513
  apiKey: a,
246
- requiresApiKey: o,
514
+ requiresApiKey: s,
247
515
  requiresNoCredentials: t.authenticationType === r.None,
248
516
  isDialNative: t.authenticationType === r.DialNative,
249
- canSubmitLogin: !o || a.trim().length > 0
517
+ canSubmitLogin: !s || a.trim().length > 0,
518
+ isLoginDisabled: Pe,
519
+ isReportRetry: o === !0 && i === u.ReportFailed
250
520
  };
251
521
  }), [
252
- b,
253
- K,
254
- U
522
+ v,
523
+ V,
524
+ L,
525
+ Pe
255
526
  ]),
256
- announcement: I,
257
- offlineUsageConsent: R,
258
- setOfflineUsageConsent: z,
259
- isOfflineUsageConsentShown: h(() => b.some((e) => {
260
- let t = G.get(o(e))?.authenticationType;
527
+ announcement: fe,
528
+ offlineUsageConsent: j,
529
+ setOfflineUsageConsent: pe,
530
+ isOfflineUsageConsentShown: h(() => v.some((e) => {
531
+ let t = B.get(o(e))?.authenticationType;
261
532
  return t === r.ApiKey || t === r.OAuth;
262
- }), [b, G]),
263
- changeApiKey: ee,
264
- login: ne,
265
- decline: J,
266
- declineAll: te
533
+ }), [v, B]),
534
+ changeApiKey: be,
535
+ login: Te,
536
+ decline: xe,
537
+ declineAll: Ne,
538
+ retryReport: Ee,
539
+ canLogInAll: ke,
540
+ run: M,
541
+ logInAll: Ae,
542
+ continueRun: je,
543
+ stopRun: Me,
544
+ apiKeyFocusRequest: he
267
545
  };
268
546
  };
269
547
  //#endregion
270
- export { b as useSigninInterrupt };
548
+ export { v as useSigninInterrupt };