@syntrologie/adapt-chatbot 2.8.0-canary.295 → 2.8.0-canary.297
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/AdaptiveChatBar.js +2 -2
- package/dist/AdaptiveChatTrail.js +2 -2
- package/dist/ChatAssistantLit.js +2 -2
- package/dist/{chunk-F2INJT5F.js → chunk-E2H6T7XI.js} +74 -3
- package/dist/{chunk-F2INJT5F.js.map → chunk-E2H6T7XI.js.map} +2 -2
- package/dist/{chunk-3HYMFSO4.js → chunk-TIHH27JQ.js} +2 -2
- package/dist/{chunk-A4X7HEVE.js → chunk-ZZUKH2D6.js} +15 -8
- package/dist/chunk-ZZUKH2D6.js.map +7 -0
- package/dist/runtime.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-A4X7HEVE.js.map +0 -7
- /package/dist/{chunk-3HYMFSO4.js.map → chunk-TIHH27JQ.js.map} +0 -0
package/dist/AdaptiveChatBar.js
CHANGED
package/dist/ChatAssistantLit.js
CHANGED
|
@@ -7325,6 +7325,7 @@ var AgUiTransport = class {
|
|
|
7325
7325
|
this._pendingResume = false;
|
|
7326
7326
|
this._currentAssistantMessageId = null;
|
|
7327
7327
|
this._toolCallMessageIds = /* @__PURE__ */ new Map();
|
|
7328
|
+
this._localPendingInterrupts = /* @__PURE__ */ new Map();
|
|
7328
7329
|
this._url = options.url;
|
|
7329
7330
|
this._headers = options.headers ?? {};
|
|
7330
7331
|
this._threadId = options.threadId;
|
|
@@ -7332,6 +7333,7 @@ var AgUiTransport = class {
|
|
|
7332
7333
|
this._credentials = options.credentials;
|
|
7333
7334
|
this._onA2UIEvent = options.onA2UIEvent;
|
|
7334
7335
|
this._forwardedProps = options.forwardedProps;
|
|
7336
|
+
this._serverOwnedHistory = options.serverOwnedHistory ?? false;
|
|
7335
7337
|
}
|
|
7336
7338
|
get connected() {
|
|
7337
7339
|
return this._connected;
|
|
@@ -7365,6 +7367,7 @@ var AgUiTransport = class {
|
|
|
7365
7367
|
this._pendingResume = false;
|
|
7366
7368
|
this._currentAssistantMessageId = null;
|
|
7367
7369
|
this._toolCallMessageIds.clear();
|
|
7370
|
+
this._localPendingInterrupts.clear();
|
|
7368
7371
|
}
|
|
7369
7372
|
send(action) {
|
|
7370
7373
|
if (!this._agent) return;
|
|
@@ -7394,9 +7397,13 @@ var AgUiTransport = class {
|
|
|
7394
7397
|
// ---------------------------------------------------------------------------
|
|
7395
7398
|
_sendUserMessage(text) {
|
|
7396
7399
|
const agent = this._agent;
|
|
7397
|
-
const
|
|
7400
|
+
const upstream = (agent.pendingInterrupts ?? []).map((i) => i).filter(
|
|
7398
7401
|
(i) => typeof i?.id === "string" && i.id.length > 0
|
|
7399
7402
|
);
|
|
7403
|
+
const byId = /* @__PURE__ */ new Map();
|
|
7404
|
+
for (const i of this._localPendingInterrupts.values()) byId.set(i.id, i);
|
|
7405
|
+
for (const i of upstream) byId.set(i.id, i);
|
|
7406
|
+
const pendingInterrupts = [...byId.values()];
|
|
7400
7407
|
const cancelResume = pendingInterrupts.length > 0 ? pendingInterrupts.map((i) => {
|
|
7401
7408
|
const toolCallId = i.toolCallId ?? i.tool_call_id;
|
|
7402
7409
|
if (toolCallId) {
|
|
@@ -7407,6 +7414,7 @@ var AgUiTransport = class {
|
|
|
7407
7414
|
status: "cancelled"
|
|
7408
7415
|
};
|
|
7409
7416
|
}) : void 0;
|
|
7417
|
+
if (cancelResume) this._localPendingInterrupts.clear();
|
|
7410
7418
|
agent.addMessage({
|
|
7411
7419
|
id: generateId(),
|
|
7412
7420
|
role: "user",
|
|
@@ -7440,6 +7448,7 @@ var AgUiTransport = class {
|
|
|
7440
7448
|
// ---------------------------------------------------------------------------
|
|
7441
7449
|
_sendDeferredToolResume(action) {
|
|
7442
7450
|
let entry;
|
|
7451
|
+
this._localPendingInterrupts.delete(action.interruptId);
|
|
7443
7452
|
if (action.decision === "cancel") {
|
|
7444
7453
|
entry = { interruptId: action.interruptId, status: "cancelled" };
|
|
7445
7454
|
} else if (action.decision === "approve") {
|
|
@@ -7466,12 +7475,18 @@ var AgUiTransport = class {
|
|
|
7466
7475
|
if (typeof this._headers === "function") {
|
|
7467
7476
|
agent.headers = this._headers();
|
|
7468
7477
|
}
|
|
7478
|
+
const sentMessageIds = new Set((agent.messages ?? []).map((m) => m.id));
|
|
7469
7479
|
const fwd = typeof this._forwardedProps === "function" ? this._forwardedProps() : this._forwardedProps;
|
|
7470
7480
|
const runParams = {
|
|
7471
7481
|
...fwd ? { forwardedProps: fwd } : {},
|
|
7472
7482
|
...resume && resume.length > 0 ? { resume: [...resume] } : {}
|
|
7473
7483
|
};
|
|
7474
|
-
agent.runAgent(runParams, this._buildSubscriber())
|
|
7484
|
+
const runPromise = agent.runAgent(runParams, this._buildSubscriber());
|
|
7485
|
+
runPromise.then(() => {
|
|
7486
|
+
this._resetAgentMessages(agent, sentMessageIds);
|
|
7487
|
+
}).catch(() => {
|
|
7488
|
+
});
|
|
7489
|
+
runPromise.catch((err) => {
|
|
7475
7490
|
const message = err instanceof Error ? err.message : "Agent run failed";
|
|
7476
7491
|
const errorName = err instanceof Error ? err.name : null;
|
|
7477
7492
|
const e = err;
|
|
@@ -7480,10 +7495,60 @@ var AgUiTransport = class {
|
|
|
7480
7495
|
const body = typeof rawBody === "string" ? rawBody.slice(0, 500) : rawBody != null ? JSON.stringify(rawBody).slice(0, 500) : null;
|
|
7481
7496
|
this._pendingResume = false;
|
|
7482
7497
|
this._currentAssistantMessageId = null;
|
|
7498
|
+
this._resetAgentMessages(agent, sentMessageIds);
|
|
7483
7499
|
this._emit({ type: "error", message, status, body, errorName });
|
|
7484
7500
|
this._emit({ type: "typing", isTyping: false });
|
|
7485
7501
|
});
|
|
7486
7502
|
}
|
|
7503
|
+
/**
|
|
7504
|
+
* Reset `agent.messages` after a settled run (server-owned history).
|
|
7505
|
+
*
|
|
7506
|
+
* The backend owns conversation state (`chat_threads.native_messages`);
|
|
7507
|
+
* the agent object is only a request builder, so anything that already
|
|
7508
|
+
* shipped in a run is dropped. The ONLY retention is undelivered
|
|
7509
|
+
* client-tool state: an assistant message carrying `toolCalls` for a
|
|
7510
|
+
* tool in `clientTools` whose result either doesn't exist yet (the UI
|
|
7511
|
+
* is still computing/asking) or was queued mid-run and never shipped
|
|
7512
|
+
* (`_sendToolResult` while `isRunning`). The retained pair makes the
|
|
7513
|
+
* next run's wire self-consistent — a `role: "tool"` message without
|
|
7514
|
+
* its matching call in the SAME client list is dropped by the backend
|
|
7515
|
+
* filter and the result would be lost.
|
|
7516
|
+
*
|
|
7517
|
+
* No-op unless `serverOwnedHistory` is set: the adaptive runtime and
|
|
7518
|
+
* editor chat backends still build the model conversation from the
|
|
7519
|
+
* client's `messages` array.
|
|
7520
|
+
*/
|
|
7521
|
+
_resetAgentMessages(agent, sentMessageIds) {
|
|
7522
|
+
if (!this._serverOwnedHistory) return;
|
|
7523
|
+
if (agent !== this._agent) return;
|
|
7524
|
+
const messages = agent.messages ?? [];
|
|
7525
|
+
const resultsByCallId = /* @__PURE__ */ new Map();
|
|
7526
|
+
for (const msg of messages) {
|
|
7527
|
+
if (msg.role === "tool" && typeof msg.toolCallId === "string") {
|
|
7528
|
+
resultsByCallId.set(msg.toolCallId, msg);
|
|
7529
|
+
}
|
|
7530
|
+
}
|
|
7531
|
+
const retained = [];
|
|
7532
|
+
for (const msg of messages) {
|
|
7533
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.toolCalls)) continue;
|
|
7534
|
+
const pendingCalls = msg.toolCalls.filter((tc) => {
|
|
7535
|
+
if (!this._clientTools.has(tc.function?.name)) return false;
|
|
7536
|
+
const result = resultsByCallId.get(tc.id);
|
|
7537
|
+
return result === void 0 || !sentMessageIds.has(result.id);
|
|
7538
|
+
});
|
|
7539
|
+
if (pendingCalls.length === 0) continue;
|
|
7540
|
+
retained.push({ ...msg, toolCalls: pendingCalls });
|
|
7541
|
+
for (const tc of pendingCalls) {
|
|
7542
|
+
const result = resultsByCallId.get(tc.id);
|
|
7543
|
+
if (result !== void 0) retained.push(result);
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
if (typeof agent.setMessages === "function") {
|
|
7547
|
+
agent.setMessages(retained);
|
|
7548
|
+
} else {
|
|
7549
|
+
agent.messages = retained;
|
|
7550
|
+
}
|
|
7551
|
+
}
|
|
7487
7552
|
_buildSubscriber() {
|
|
7488
7553
|
return {
|
|
7489
7554
|
onTextMessageStartEvent: (params) => {
|
|
@@ -7578,6 +7643,12 @@ var AgUiTransport = class {
|
|
|
7578
7643
|
if (outcome?.type === "interrupt" && Array.isArray(outcome.interrupts)) {
|
|
7579
7644
|
for (const interrupt of outcome.interrupts) {
|
|
7580
7645
|
const toolCallId = interrupt.toolCallId ?? interrupt.tool_call_id;
|
|
7646
|
+
if (typeof interrupt.id === "string" && interrupt.id) {
|
|
7647
|
+
this._localPendingInterrupts.set(interrupt.id, {
|
|
7648
|
+
id: interrupt.id,
|
|
7649
|
+
toolCallId: typeof toolCallId === "string" ? toolCallId : void 0
|
|
7650
|
+
});
|
|
7651
|
+
}
|
|
7581
7652
|
if (typeof toolCallId === "string" && typeof interrupt.id === "string") {
|
|
7582
7653
|
this._emit({
|
|
7583
7654
|
type: "tool-call-deferred",
|
|
@@ -8695,4 +8766,4 @@ fast-json-patch/module/duplex.mjs:
|
|
|
8695
8766
|
* MIT license
|
|
8696
8767
|
*)
|
|
8697
8768
|
*/
|
|
8698
|
-
//# sourceMappingURL=chunk-
|
|
8769
|
+
//# sourceMappingURL=chunk-E2H6T7XI.js.map
|