@syntrologie/adapt-chatbot 2.8.0-canary.338 → 2.8.0-canary.339
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/ChatAssistantLit.js
CHANGED
|
@@ -7317,6 +7317,13 @@ var _idCounter = 0;
|
|
|
7317
7317
|
function generateId() {
|
|
7318
7318
|
return `agui-${Date.now()}-${++_idCounter}`;
|
|
7319
7319
|
}
|
|
7320
|
+
var MAX_TRANSIENT_RETRIES = 2;
|
|
7321
|
+
var TRANSIENT_RETRY_BACKOFF_MS = [400, 1200];
|
|
7322
|
+
function isTransientRunFailure(status, errorName) {
|
|
7323
|
+
if (errorName === "AbortError") return false;
|
|
7324
|
+
if (status == null) return errorName === "TypeError";
|
|
7325
|
+
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
7326
|
+
}
|
|
7320
7327
|
var AgUiTransport = class {
|
|
7321
7328
|
constructor(options) {
|
|
7322
7329
|
this._agent = null;
|
|
@@ -7326,6 +7333,8 @@ var AgUiTransport = class {
|
|
|
7326
7333
|
this._currentAssistantMessageId = null;
|
|
7327
7334
|
this._toolCallMessageIds = /* @__PURE__ */ new Map();
|
|
7328
7335
|
this._localPendingInterrupts = /* @__PURE__ */ new Map();
|
|
7336
|
+
this._runProducedOutput = false;
|
|
7337
|
+
this._retryTimer = null;
|
|
7329
7338
|
this._url = options.url;
|
|
7330
7339
|
this._headers = options.headers ?? {};
|
|
7331
7340
|
this._threadId = options.threadId;
|
|
@@ -7359,6 +7368,10 @@ var AgUiTransport = class {
|
|
|
7359
7368
|
this._emit({ type: "messages-snapshot", messages: [] });
|
|
7360
7369
|
}
|
|
7361
7370
|
disconnect() {
|
|
7371
|
+
if (this._retryTimer != null) {
|
|
7372
|
+
clearTimeout(this._retryTimer);
|
|
7373
|
+
this._retryTimer = null;
|
|
7374
|
+
}
|
|
7362
7375
|
if (this._agent?.isRunning) {
|
|
7363
7376
|
this._agent.abortRun();
|
|
7364
7377
|
}
|
|
@@ -7468,10 +7481,11 @@ var AgUiTransport = class {
|
|
|
7468
7481
|
// ---------------------------------------------------------------------------
|
|
7469
7482
|
// Private — run agent with subscriber
|
|
7470
7483
|
// ---------------------------------------------------------------------------
|
|
7471
|
-
_runAgent(resume) {
|
|
7484
|
+
_runAgent(resume, attempt = 0) {
|
|
7472
7485
|
const agent = this._agent;
|
|
7473
7486
|
if (!agent) return;
|
|
7474
7487
|
this._currentAssistantMessageId = null;
|
|
7488
|
+
this._runProducedOutput = false;
|
|
7475
7489
|
this._emit({ type: "typing", isTyping: true });
|
|
7476
7490
|
if (typeof this._headers === "function") {
|
|
7477
7491
|
agent.headers = this._headers();
|
|
@@ -7494,6 +7508,15 @@ var AgUiTransport = class {
|
|
|
7494
7508
|
const status = typeof e.status === "number" ? e.status : typeof e.statusCode === "number" ? e.statusCode : typeof e.response?.status === "number" ? e.response.status : null;
|
|
7495
7509
|
const rawBody = e.body ?? e.response?.body ?? null;
|
|
7496
7510
|
const body = typeof rawBody === "string" ? rawBody.slice(0, 500) : rawBody != null ? JSON.stringify(rawBody).slice(0, 500) : null;
|
|
7511
|
+
if (isTransientRunFailure(status, errorName) && !this._runProducedOutput && attempt < MAX_TRANSIENT_RETRIES && this._agent === agent) {
|
|
7512
|
+
const delay = TRANSIENT_RETRY_BACKOFF_MS[attempt] ?? TRANSIENT_RETRY_BACKOFF_MS[TRANSIENT_RETRY_BACKOFF_MS.length - 1];
|
|
7513
|
+
this._currentAssistantMessageId = null;
|
|
7514
|
+
this._retryTimer = setTimeout(() => {
|
|
7515
|
+
this._retryTimer = null;
|
|
7516
|
+
if (this._agent === agent) this._runAgent(resume, attempt + 1);
|
|
7517
|
+
}, delay);
|
|
7518
|
+
return;
|
|
7519
|
+
}
|
|
7497
7520
|
this._pendingResume = false;
|
|
7498
7521
|
this._currentAssistantMessageId = null;
|
|
7499
7522
|
this._resetAgentMessages(agent, sentMessageIds);
|
|
@@ -7554,6 +7577,7 @@ var AgUiTransport = class {
|
|
|
7554
7577
|
return {
|
|
7555
7578
|
onTextMessageStartEvent: (params) => {
|
|
7556
7579
|
const { event } = params;
|
|
7580
|
+
this._runProducedOutput = true;
|
|
7557
7581
|
this._currentAssistantMessageId = event.messageId;
|
|
7558
7582
|
this._emit({ type: "thinking-clear" });
|
|
7559
7583
|
const message = {
|
|
@@ -7594,6 +7618,7 @@ var AgUiTransport = class {
|
|
|
7594
7618
|
},
|
|
7595
7619
|
onToolCallStartEvent: (params) => {
|
|
7596
7620
|
const { event } = params;
|
|
7621
|
+
this._runProducedOutput = true;
|
|
7597
7622
|
this._emit({ type: "thinking-clear" });
|
|
7598
7623
|
const messageId = event.parentMessageId ?? this._currentAssistantMessageId ?? event.toolCallId;
|
|
7599
7624
|
this._toolCallMessageIds.set(event.toolCallId, messageId);
|
|
@@ -7688,6 +7713,7 @@ var AgUiTransport = class {
|
|
|
7688
7713
|
},
|
|
7689
7714
|
onCustomEvent: (params) => {
|
|
7690
7715
|
const { event } = params;
|
|
7716
|
+
this._runProducedOutput = true;
|
|
7691
7717
|
const payload = event.value;
|
|
7692
7718
|
this._onA2UIEvent?.(payload);
|
|
7693
7719
|
this._emit({ type: "a2ui", payload });
|
|
@@ -8803,4 +8829,4 @@ fast-json-patch/module/duplex.mjs:
|
|
|
8803
8829
|
* MIT license
|
|
8804
8830
|
*)
|
|
8805
8831
|
*/
|
|
8806
|
-
//# sourceMappingURL=chunk-
|
|
8832
|
+
//# sourceMappingURL=chunk-33UECBHY.js.map
|