@digipair/skill-web-chatbot 0.37.5 → 0.38.1

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/index.esm2.js CHANGED
@@ -23,6 +23,526 @@ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedEr
23
23
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
24
24
  };
25
25
 
26
+ function asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, key, arg) {
27
+ try {
28
+ var info = gen[key](arg);
29
+ var value = info.value;
30
+ } catch (error) {
31
+ reject(error);
32
+ return;
33
+ }
34
+ if (info.done) {
35
+ resolve(value);
36
+ } else {
37
+ Promise.resolve(value).then(_next, _throw);
38
+ }
39
+ }
40
+ function _async_to_generator$l(fn) {
41
+ return function() {
42
+ var self = this, args = arguments;
43
+ return new Promise(function(resolve, reject) {
44
+ var gen = fn.apply(self, args);
45
+ function _next(value) {
46
+ asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, "next", value);
47
+ }
48
+ function _throw(err) {
49
+ asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, "throw", err);
50
+ }
51
+ _next(undefined);
52
+ });
53
+ };
54
+ }
55
+ function _ts_generator$m(thisArg, body) {
56
+ var f, y, t, g, _ = {
57
+ label: 0,
58
+ sent: function() {
59
+ if (t[0] & 1) throw t[1];
60
+ return t[1];
61
+ },
62
+ trys: [],
63
+ ops: []
64
+ };
65
+ return g = {
66
+ next: verb(0),
67
+ "throw": verb(1),
68
+ "return": verb(2)
69
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
70
+ return this;
71
+ }), g;
72
+ function verb(n) {
73
+ return function(v) {
74
+ return step([
75
+ n,
76
+ v
77
+ ]);
78
+ };
79
+ }
80
+ function step(op) {
81
+ if (f) throw new TypeError("Generator is already executing.");
82
+ while(_)try {
83
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
84
+ if (y = 0, t) op = [
85
+ op[0] & 2,
86
+ t.value
87
+ ];
88
+ switch(op[0]){
89
+ case 0:
90
+ case 1:
91
+ t = op;
92
+ break;
93
+ case 4:
94
+ _.label++;
95
+ return {
96
+ value: op[1],
97
+ done: false
98
+ };
99
+ case 5:
100
+ _.label++;
101
+ y = op[1];
102
+ op = [
103
+ 0
104
+ ];
105
+ continue;
106
+ case 7:
107
+ op = _.ops.pop();
108
+ _.trys.pop();
109
+ continue;
110
+ default:
111
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
112
+ _ = 0;
113
+ continue;
114
+ }
115
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
116
+ _.label = op[1];
117
+ break;
118
+ }
119
+ if (op[0] === 6 && _.label < t[1]) {
120
+ _.label = t[1];
121
+ t = op;
122
+ break;
123
+ }
124
+ if (t && _.label < t[2]) {
125
+ _.label = t[2];
126
+ _.ops.push(op);
127
+ break;
128
+ }
129
+ if (t[2]) _.ops.pop();
130
+ _.trys.pop();
131
+ continue;
132
+ }
133
+ op = body.call(thisArg, _);
134
+ } catch (e) {
135
+ op = [
136
+ 6,
137
+ e
138
+ ];
139
+ y = 0;
140
+ } finally{
141
+ f = t = 0;
142
+ }
143
+ if (op[0] & 5) throw op[1];
144
+ return {
145
+ value: op[0] ? op[1] : void 0,
146
+ done: true
147
+ };
148
+ }
149
+ }
150
+ function getBytes(stream, onChunk) {
151
+ return _getBytes.apply(this, arguments);
152
+ }
153
+ function _getBytes() {
154
+ _getBytes = _async_to_generator$l(function(stream, onChunk) {
155
+ var reader, result;
156
+ return _ts_generator$m(this, function(_state) {
157
+ switch(_state.label){
158
+ case 0:
159
+ reader = stream.getReader();
160
+ _state.label = 1;
161
+ case 1:
162
+ return [
163
+ 4,
164
+ reader.read()
165
+ ];
166
+ case 2:
167
+ if (!!(result = _state.sent()).done) return [
168
+ 3,
169
+ 3
170
+ ];
171
+ onChunk(result.value);
172
+ return [
173
+ 3,
174
+ 1
175
+ ];
176
+ case 3:
177
+ return [
178
+ 2
179
+ ];
180
+ }
181
+ });
182
+ });
183
+ return _getBytes.apply(this, arguments);
184
+ }
185
+ function getLines(onLine) {
186
+ var buffer;
187
+ var position;
188
+ var fieldLength;
189
+ var discardTrailingNewline = false;
190
+ return function onChunk(arr) {
191
+ if (buffer === undefined) {
192
+ buffer = arr;
193
+ position = 0;
194
+ fieldLength = -1;
195
+ } else {
196
+ buffer = concat(buffer, arr);
197
+ }
198
+ var bufLength = buffer.length;
199
+ var lineStart = 0;
200
+ while(position < bufLength){
201
+ if (discardTrailingNewline) {
202
+ if (buffer[position] === 10) {
203
+ lineStart = ++position;
204
+ }
205
+ discardTrailingNewline = false;
206
+ }
207
+ var lineEnd = -1;
208
+ for(; position < bufLength && lineEnd === -1; ++position){
209
+ switch(buffer[position]){
210
+ case 58:
211
+ if (fieldLength === -1) {
212
+ fieldLength = position - lineStart;
213
+ }
214
+ break;
215
+ case 13:
216
+ discardTrailingNewline = true;
217
+ case 10:
218
+ lineEnd = position;
219
+ break;
220
+ }
221
+ }
222
+ if (lineEnd === -1) {
223
+ break;
224
+ }
225
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
226
+ lineStart = position;
227
+ fieldLength = -1;
228
+ }
229
+ if (lineStart === bufLength) {
230
+ buffer = undefined;
231
+ } else if (lineStart !== 0) {
232
+ buffer = buffer.subarray(lineStart);
233
+ position -= lineStart;
234
+ }
235
+ };
236
+ }
237
+ function getMessages(onId, onRetry, onMessage) {
238
+ var message = newMessage();
239
+ var decoder = new TextDecoder();
240
+ return function onLine(line, fieldLength) {
241
+ if (line.length === 0) {
242
+ onMessage === null || onMessage === void 0 ? void 0 : onMessage(message);
243
+ message = newMessage();
244
+ } else if (fieldLength > 0) {
245
+ var field = decoder.decode(line.subarray(0, fieldLength));
246
+ var valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
247
+ var value = decoder.decode(line.subarray(valueOffset));
248
+ switch(field){
249
+ case "data":
250
+ message.data = message.data ? message.data + "\n" + value : value;
251
+ break;
252
+ case "event":
253
+ message.event = value;
254
+ break;
255
+ case "id":
256
+ onId(message.id = value);
257
+ break;
258
+ case "retry":
259
+ var retry = parseInt(value, 10);
260
+ if (!isNaN(retry)) {
261
+ onRetry(message.retry = retry);
262
+ }
263
+ break;
264
+ }
265
+ }
266
+ };
267
+ }
268
+ function concat(a, b) {
269
+ var res = new Uint8Array(a.length + b.length);
270
+ res.set(a);
271
+ res.set(b, a.length);
272
+ return res;
273
+ }
274
+ function newMessage() {
275
+ return {
276
+ data: "",
277
+ event: "",
278
+ id: "",
279
+ retry: undefined
280
+ };
281
+ }
282
+
283
+ function asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, key, arg) {
284
+ try {
285
+ var info = gen[key](arg);
286
+ var value = info.value;
287
+ } catch (error) {
288
+ reject(error);
289
+ return;
290
+ }
291
+ if (info.done) {
292
+ resolve(value);
293
+ } else {
294
+ Promise.resolve(value).then(_next, _throw);
295
+ }
296
+ }
297
+ function _async_to_generator$k(fn) {
298
+ return function() {
299
+ var self = this, args = arguments;
300
+ return new Promise(function(resolve, reject) {
301
+ var gen = fn.apply(self, args);
302
+ function _next(value) {
303
+ asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "next", value);
304
+ }
305
+ function _throw(err) {
306
+ asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "throw", err);
307
+ }
308
+ _next(undefined);
309
+ });
310
+ };
311
+ }
312
+ function _ts_generator$l(thisArg, body) {
313
+ var f, y, t, g, _ = {
314
+ label: 0,
315
+ sent: function() {
316
+ if (t[0] & 1) throw t[1];
317
+ return t[1];
318
+ },
319
+ trys: [],
320
+ ops: []
321
+ };
322
+ return g = {
323
+ next: verb(0),
324
+ "throw": verb(1),
325
+ "return": verb(2)
326
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
327
+ return this;
328
+ }), g;
329
+ function verb(n) {
330
+ return function(v) {
331
+ return step([
332
+ n,
333
+ v
334
+ ]);
335
+ };
336
+ }
337
+ function step(op) {
338
+ if (f) throw new TypeError("Generator is already executing.");
339
+ while(_)try {
340
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
341
+ if (y = 0, t) op = [
342
+ op[0] & 2,
343
+ t.value
344
+ ];
345
+ switch(op[0]){
346
+ case 0:
347
+ case 1:
348
+ t = op;
349
+ break;
350
+ case 4:
351
+ _.label++;
352
+ return {
353
+ value: op[1],
354
+ done: false
355
+ };
356
+ case 5:
357
+ _.label++;
358
+ y = op[1];
359
+ op = [
360
+ 0
361
+ ];
362
+ continue;
363
+ case 7:
364
+ op = _.ops.pop();
365
+ _.trys.pop();
366
+ continue;
367
+ default:
368
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
369
+ _ = 0;
370
+ continue;
371
+ }
372
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
373
+ _.label = op[1];
374
+ break;
375
+ }
376
+ if (op[0] === 6 && _.label < t[1]) {
377
+ _.label = t[1];
378
+ t = op;
379
+ break;
380
+ }
381
+ if (t && _.label < t[2]) {
382
+ _.label = t[2];
383
+ _.ops.push(op);
384
+ break;
385
+ }
386
+ if (t[2]) _.ops.pop();
387
+ _.trys.pop();
388
+ continue;
389
+ }
390
+ op = body.call(thisArg, _);
391
+ } catch (e) {
392
+ op = [
393
+ 6,
394
+ e
395
+ ];
396
+ y = 0;
397
+ } finally{
398
+ f = t = 0;
399
+ }
400
+ if (op[0] & 5) throw op[1];
401
+ return {
402
+ value: op[0] ? op[1] : void 0,
403
+ done: true
404
+ };
405
+ }
406
+ }
407
+ var __rest = undefined && undefined.__rest || function(s, e) {
408
+ var t = {};
409
+ for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
410
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++){
411
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
412
+ }
413
+ return t;
414
+ };
415
+ var EventStreamContentType = "text/event-stream";
416
+ var DefaultRetryInterval = 1000;
417
+ var LastEventId = "last-event-id";
418
+ function fetchEventSource(input, _a) {
419
+ var inputSignal = _a.signal, inputHeaders = _a.headers, inputOnOpen = _a.onopen, onmessage = _a.onmessage, onclose = _a.onclose, onerror = _a.onerror, openWhenHidden = _a.openWhenHidden, inputFetch = _a.fetch, rest = __rest(_a, [
420
+ "signal",
421
+ "headers",
422
+ "onopen",
423
+ "onmessage",
424
+ "onclose",
425
+ "onerror",
426
+ "openWhenHidden",
427
+ "fetch"
428
+ ]);
429
+ return new Promise(function(resolve, reject) {
430
+ var onVisibilityChange = function onVisibilityChange() {
431
+ curRequestController.abort();
432
+ if (!document.hidden) {
433
+ create();
434
+ }
435
+ };
436
+ var dispose = function dispose() {
437
+ document.removeEventListener("visibilitychange", onVisibilityChange);
438
+ window.clearTimeout(retryTimer);
439
+ curRequestController.abort();
440
+ };
441
+ var create = function create() {
442
+ return _create.apply(this, arguments);
443
+ };
444
+ var headers = Object.assign({}, inputHeaders);
445
+ if (!headers.accept) {
446
+ headers.accept = EventStreamContentType;
447
+ }
448
+ var curRequestController;
449
+ if (!openWhenHidden) {
450
+ document.addEventListener("visibilitychange", onVisibilityChange);
451
+ }
452
+ var retryInterval = DefaultRetryInterval;
453
+ var retryTimer = 0;
454
+ inputSignal === null || inputSignal === void 0 ? void 0 : inputSignal.addEventListener("abort", function() {
455
+ dispose();
456
+ resolve();
457
+ });
458
+ var fetch = inputFetch !== null && inputFetch !== void 0 ? inputFetch : window.fetch;
459
+ var onopen = inputOnOpen !== null && inputOnOpen !== void 0 ? inputOnOpen : defaultOnOpen;
460
+ function _create() {
461
+ _create = _async_to_generator$k(function() {
462
+ var _$_a, response, err, interval;
463
+ return _ts_generator$l(this, function(_state) {
464
+ switch(_state.label){
465
+ case 0:
466
+ curRequestController = new AbortController();
467
+ _state.label = 1;
468
+ case 1:
469
+ _state.trys.push([
470
+ 1,
471
+ 5,
472
+ ,
473
+ 6
474
+ ]);
475
+ return [
476
+ 4,
477
+ fetch(input, Object.assign(Object.assign({}, rest), {
478
+ headers: headers,
479
+ signal: curRequestController.signal
480
+ }))
481
+ ];
482
+ case 2:
483
+ response = _state.sent();
484
+ return [
485
+ 4,
486
+ onopen(response)
487
+ ];
488
+ case 3:
489
+ _state.sent();
490
+ return [
491
+ 4,
492
+ getBytes(response.body, getLines(getMessages(function(id) {
493
+ if (id) {
494
+ headers[LastEventId] = id;
495
+ } else {
496
+ delete headers[LastEventId];
497
+ }
498
+ }, function(retry) {
499
+ retryInterval = retry;
500
+ }, onmessage)))
501
+ ];
502
+ case 4:
503
+ _state.sent();
504
+ onclose === null || onclose === void 0 ? void 0 : onclose();
505
+ dispose();
506
+ resolve();
507
+ return [
508
+ 3,
509
+ 6
510
+ ];
511
+ case 5:
512
+ err = _state.sent();
513
+ if (!curRequestController.signal.aborted) {
514
+ try {
515
+ interval = (_$_a = onerror === null || onerror === void 0 ? void 0 : onerror(err)) !== null && _$_a !== void 0 ? _$_a : retryInterval;
516
+ window.clearTimeout(retryTimer);
517
+ retryTimer = window.setTimeout(create, interval);
518
+ } catch (innerErr) {
519
+ dispose();
520
+ reject(innerErr);
521
+ }
522
+ }
523
+ return [
524
+ 3,
525
+ 6
526
+ ];
527
+ case 6:
528
+ return [
529
+ 2
530
+ ];
531
+ }
532
+ });
533
+ });
534
+ return _create.apply(this, arguments);
535
+ }
536
+ create();
537
+ });
538
+ }
539
+ function defaultOnOpen(response) {
540
+ var contentType = response.headers.get("content-type");
541
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith(EventStreamContentType))) {
542
+ throw new Error("Expected content-type to be ".concat(EventStreamContentType, ", Actual: ").concat(contentType));
543
+ }
544
+ }
545
+
26
546
  /**
27
547
  * Returns a singleton HTML element, inserted in given parent element of HTML page,
28
548
  * used mostly to store and share global resources between multiple UI5 Web Components runtimes.
@@ -56850,7 +57370,9 @@ class ChatElement extends s$3 {
56850
57370
  .context=${_extends({}, this.context, ((_this_currentBoost1 = this.currentBoost) == null ? void 0 : _this_currentBoost1.context) || {})}
56851
57371
  ></digipair-chatbot-inputs>
56852
57372
 
56853
- ${!this.loading ? T : x`<section class="loading"><img src=${WRITTING_IMAGE} /></section>`}
57373
+ ${!this.loading ? T : x`<section class="loading">
57374
+ <span class="step">${this.loadingStep}</span><img src=${WRITTING_IMAGE} />
57375
+ </section>`}
56854
57376
  </section>
56855
57377
 
56856
57378
  <section class="input-container ${this.currentBoost ? 'with-boost' : ''}">
@@ -56893,7 +57415,6 @@ class ChatElement extends s$3 {
56893
57415
  constructor(...args){
56894
57416
  super(...args);
56895
57417
  this.previousMessages = '';
56896
- this.previousCurrentBoostText = undefined;
56897
57418
  }
56898
57419
  }
56899
57420
  ChatElement.styles = [
@@ -57086,6 +57607,7 @@ ChatElement.styles = [
57086
57607
  max-width: 100%;
57087
57608
  width: 235px;
57088
57609
  overflow: hidden;
57610
+ opacity: 0.3;
57089
57611
  }
57090
57612
 
57091
57613
  .input .assistant p {
@@ -57097,6 +57619,21 @@ ChatElement.styles = [
57097
57619
  .button.action {
57098
57620
  float: right;
57099
57621
  }
57622
+
57623
+ .loading {
57624
+ overflow: visible;
57625
+ }
57626
+
57627
+ .loading .step {
57628
+ color: #bfc1c3;
57629
+ margin-left: 45px;
57630
+ padding-top: 15px;
57631
+ display: block;
57632
+ }
57633
+
57634
+ .loading img {
57635
+ float: left;
57636
+ }
57100
57637
  `
57101
57638
  ];
57102
57639
  __decorate$3([
@@ -57131,6 +57668,10 @@ __decorate$3([
57131
57668
  __metadata("design:paramtypes", []),
57132
57669
  __metadata("design:returntype", Array)
57133
57670
  ], ChatElement.prototype, "inputs", null);
57671
+ __decorate$3([
57672
+ n$3(),
57673
+ __metadata("design:type", String)
57674
+ ], ChatElement.prototype, "loadingStep", void 0);
57134
57675
  __decorate$3([
57135
57676
  e$2('#messageInput'),
57136
57677
  __metadata("design:type", typeof HTMLInputElement === "undefined" ? Object : HTMLInputElement)
@@ -58594,14 +59135,24 @@ const config = {
58594
59135
  }
58595
59136
  };
58596
59137
 
58597
- let API_URL$1;
58598
59138
  class ChatbotElement extends s$3 {
59139
+ CHAT_COMMAND(digipair, reasoning) {
59140
+ return {
59141
+ library: '@digipair/actions-chatbot',
59142
+ element: 'executeRemoteReasoning',
59143
+ properties: {
59144
+ digipair,
59145
+ reasoning: reasoning != null ? reasoning : 'conversation',
59146
+ apiUrl: this.apiUrl
59147
+ }
59148
+ };
59149
+ }
58599
59150
  connectedCallback() {
58600
- API_URL$1 = this.apiUrl;
58601
59151
  super.connectedCallback();
58602
59152
  this.loadUser();
58603
59153
  this.boostListener();
58604
59154
  this.externalBoostListener();
59155
+ this.initializeSSE();
58605
59156
  document.addEventListener('click', this.blurEvent);
58606
59157
  }
58607
59158
  disconnectedCallback() {
@@ -58614,6 +59165,40 @@ class ChatbotElement extends s$3 {
58614
59165
  }, detail)), 1);
58615
59166
  });
58616
59167
  }
59168
+ initializeSSE() {
59169
+ const digipair = this.code;
59170
+ const reasoning = 'notification';
59171
+ fetchEventSource(`${this.apiUrl}/${digipair}/${reasoning}`, {
59172
+ method: 'POST',
59173
+ headers: {
59174
+ 'Content-Type': 'application/json'
59175
+ },
59176
+ onmessage: (message)=>{
59177
+ if (message.event !== 'message') {
59178
+ return;
59179
+ }
59180
+ const data = JSON.parse(message.data);
59181
+ if (data.type === 'step') {
59182
+ this.loadingStep = message.content.step;
59183
+ }
59184
+ if (data.type === 'message') {
59185
+ this.pushMessage(data.content);
59186
+ }
59187
+ },
59188
+ body: JSON.stringify({
59189
+ userId: this.userId
59190
+ }),
59191
+ async onopen (response) {
59192
+ console.log('open', response);
59193
+ },
59194
+ onclose () {
59195
+ console.log('close');
59196
+ },
59197
+ onerror (err) {
59198
+ console.error('Error:', err);
59199
+ }
59200
+ });
59201
+ }
58617
59202
  loadUser() {
58618
59203
  this.newUser = false;
58619
59204
  if (this.userId) {
@@ -58706,6 +59291,7 @@ class ChatbotElement extends s$3 {
58706
59291
  }
58707
59292
  async execute(boost, message) {
58708
59293
  var _boost_command_properties_input, _boost_command_properties, _boost_command;
59294
+ this.loadingStep = '';
58709
59295
  this.loading = true;
58710
59296
  if (message || (boost == null ? void 0 : (_boost_command = boost.command) == null ? void 0 : (_boost_command_properties = _boost_command.properties) == null ? void 0 : (_boost_command_properties_input = _boost_command_properties.input) == null ? void 0 : _boost_command_properties_input.prompt)) {
58711
59297
  this.messages.push({
@@ -58760,6 +59346,7 @@ class ChatbotElement extends s$3 {
58760
59346
  content: 'Oops...'
58761
59347
  });
58762
59348
  }
59349
+ this.loadingStep = '';
58763
59350
  this.loading = false;
58764
59351
  }
58765
59352
  executeBoost(boost) {
@@ -58818,6 +59405,7 @@ class ChatbotElement extends s$3 {
58818
59405
  config: this.metadata.config,
58819
59406
  variables: this.metadata.variables
58820
59407
  }}
59408
+ currentStep=${this.loadingStep}
58821
59409
  @prompt=${(event)=>this.execute(this.currentBoost, event.detail.prompt)}
58822
59410
  @boost=${(event)=>this.setBoost(event.detail)}
58823
59411
  ></digipair-chatbot-chat>
@@ -58857,15 +59445,7 @@ class ChatbotElement extends s$3 {
58857
59445
  this.resultState = 'open';
58858
59446
  this.currentBoost = null;
58859
59447
  this.messages = [];
58860
- this.CHAT_COMMAND = (digipair, reasoning)=>({
58861
- library: '@digipair/actions-chatbot',
58862
- element: 'executeRemoteReasoning',
58863
- properties: {
58864
- digipair,
58865
- reasoning: reasoning != null ? reasoning : 'conversation',
58866
- apiUrl: API_URL$1
58867
- }
58868
- });
59448
+ this.loadingStep = '';
58869
59449
  this.alreadyOpened = false;
58870
59450
  this.isDigipairLoading = false;
58871
59451
  this.blurEvent = (event)=>{
@@ -58877,7 +59457,7 @@ class ChatbotElement extends s$3 {
58877
59457
  };
58878
59458
  this.executeScene = async (reasoning, input = {})=>{
58879
59459
  const digipair = this.code;
58880
- const response = await fetch(`${API_URL$1}/${digipair}/${reasoning}`, {
59460
+ const response = await fetch(`${this.apiUrl}/${digipair}/${reasoning}`, {
58881
59461
  method: 'POST',
58882
59462
  headers: {
58883
59463
  'Content-Type': 'application/json'
@@ -58920,6 +59500,9 @@ __decorate$3([
58920
59500
  r$1(),
58921
59501
  __metadata("design:type", Array)
58922
59502
  ], ChatbotElement.prototype, "messages", void 0);
59503
+ __decorate$3([
59504
+ r$1()
59505
+ ], ChatbotElement.prototype, "loadingStep", void 0);
58923
59506
  __decorate$3([
58924
59507
  e$2('digipair-chatbot-chat'),
58925
59508
  __metadata("design:type", typeof ChatElement === "undefined" ? Object : ChatElement)
@@ -59071,13 +59654,57 @@ const styles = i$5`
59071
59654
 
59072
59655
  */
59073
59656
 
59074
- let API_URL;
59075
59657
  class DigipairFullElement extends s$3 {
59658
+ CHAT_COMMAND(digipair, reasoning) {
59659
+ return {
59660
+ library: '@digipair/actions-chatbot',
59661
+ element: 'executeRemoteReasoning',
59662
+ properties: {
59663
+ digipair,
59664
+ reasoning: reasoning != null ? reasoning : 'conversation',
59665
+ apiUrl: this.apiUrl
59666
+ }
59667
+ };
59668
+ }
59076
59669
  connectedCallback() {
59077
- API_URL = this.apiUrl;
59078
59670
  super.connectedCallback();
59079
59671
  this.loadUser();
59080
59672
  this.loadBoosters();
59673
+ this.initializeSSE();
59674
+ }
59675
+ initializeSSE() {
59676
+ const digipair = this.code;
59677
+ const reasoning = 'notification';
59678
+ fetchEventSource(`${this.apiUrl}/${digipair}/${reasoning}`, {
59679
+ method: 'POST',
59680
+ headers: {
59681
+ 'Content-Type': 'application/json'
59682
+ },
59683
+ onmessage: (message)=>{
59684
+ if (message.event !== 'message') {
59685
+ return;
59686
+ }
59687
+ const data = JSON.parse(message.data);
59688
+ if (data.type === 'step') {
59689
+ this.loadingStep = message.content.step;
59690
+ }
59691
+ if (data.type === 'message') {
59692
+ this.pushMessage(data.content);
59693
+ }
59694
+ },
59695
+ body: JSON.stringify({
59696
+ userId: this.userId
59697
+ }),
59698
+ async onopen (response) {
59699
+ console.log('open', response);
59700
+ },
59701
+ onclose () {
59702
+ console.log('close');
59703
+ },
59704
+ onerror (err) {
59705
+ console.error('Error:', err);
59706
+ }
59707
+ });
59081
59708
  }
59082
59709
  loadUser() {
59083
59710
  if (this.userId) {
@@ -59132,6 +59759,7 @@ class DigipairFullElement extends s$3 {
59132
59759
  }
59133
59760
  async execute(boost, message) {
59134
59761
  var _boost_command_properties_input, _boost_command_properties, _boost_command;
59762
+ this.loadingStep = '';
59135
59763
  this.loading = true;
59136
59764
  if (message || (boost == null ? void 0 : (_boost_command = boost.command) == null ? void 0 : (_boost_command_properties = _boost_command.properties) == null ? void 0 : (_boost_command_properties_input = _boost_command_properties.input) == null ? void 0 : _boost_command_properties_input.prompt)) {
59137
59765
  this.messages.push({
@@ -59193,6 +59821,7 @@ class DigipairFullElement extends s$3 {
59193
59821
  content: 'Oops...'
59194
59822
  });
59195
59823
  }
59824
+ this.loadingStep = '';
59196
59825
  this.loading = false;
59197
59826
  }
59198
59827
  executeBoost(boost) {
@@ -59248,6 +59877,7 @@ class DigipairFullElement extends s$3 {
59248
59877
  config: this.metadata.config,
59249
59878
  variables: this.metadata.variables
59250
59879
  }}
59880
+ currentStep=${this.loadingStep}
59251
59881
  @prompt=${(event)=>this.execute(this.currentBoost, event.detail.prompt)}
59252
59882
  @boost=${(event)=>this.setBoost(event.detail)}
59253
59883
  ></digipair-chatbot-chat>
@@ -59299,20 +59929,12 @@ class DigipairFullElement extends s$3 {
59299
59929
  this.loading = false;
59300
59930
  this.currentBoost = null;
59301
59931
  this.messages = [];
59302
- this.CHAT_COMMAND = (digipair, reasoning)=>({
59303
- library: '@digipair/actions-chatbot',
59304
- element: 'executeRemoteReasoning',
59305
- properties: {
59306
- digipair,
59307
- reasoning: reasoning != null ? reasoning : 'conversation',
59308
- apiUrl: API_URL
59309
- }
59310
- });
59932
+ this.loadingStep = '';
59311
59933
  this.cacheBoosters = [];
59312
59934
  this.isDigipairLoading = false;
59313
59935
  this.executeScene = async (reasoning, input = {})=>{
59314
59936
  const digipair = this.code;
59315
- const response = await fetch(`${API_URL}/${digipair}/${reasoning}`, {
59937
+ const response = await fetch(`${this.apiUrl}/${digipair}/${reasoning}`, {
59316
59938
  method: 'POST',
59317
59939
  headers: {
59318
59940
  'Content-Type': 'application/json'
@@ -59349,6 +59971,9 @@ __decorate$3([
59349
59971
  r$1(),
59350
59972
  __metadata("design:type", Array)
59351
59973
  ], DigipairFullElement.prototype, "messages", void 0);
59974
+ __decorate$3([
59975
+ r$1()
59976
+ ], DigipairFullElement.prototype, "loadingStep", void 0);
59352
59977
  __decorate$3([
59353
59978
  e$2('digipair-chatbot-chat'),
59354
59979
  __metadata("design:type", typeof ChatElement === "undefined" ? Object : ChatElement)