@syntrologie/adapt-chatbot 2.8.0-canary.295 → 2.8.0-canary.296
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-ES5JYJA7.js} +59 -2
- package/dist/{chunk-F2INJT5F.js.map → chunk-ES5JYJA7.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
|
@@ -7332,6 +7332,7 @@ var AgUiTransport = class {
|
|
|
7332
7332
|
this._credentials = options.credentials;
|
|
7333
7333
|
this._onA2UIEvent = options.onA2UIEvent;
|
|
7334
7334
|
this._forwardedProps = options.forwardedProps;
|
|
7335
|
+
this._serverOwnedHistory = options.serverOwnedHistory ?? false;
|
|
7335
7336
|
}
|
|
7336
7337
|
get connected() {
|
|
7337
7338
|
return this._connected;
|
|
@@ -7466,12 +7467,18 @@ var AgUiTransport = class {
|
|
|
7466
7467
|
if (typeof this._headers === "function") {
|
|
7467
7468
|
agent.headers = this._headers();
|
|
7468
7469
|
}
|
|
7470
|
+
const sentMessageIds = new Set((agent.messages ?? []).map((m) => m.id));
|
|
7469
7471
|
const fwd = typeof this._forwardedProps === "function" ? this._forwardedProps() : this._forwardedProps;
|
|
7470
7472
|
const runParams = {
|
|
7471
7473
|
...fwd ? { forwardedProps: fwd } : {},
|
|
7472
7474
|
...resume && resume.length > 0 ? { resume: [...resume] } : {}
|
|
7473
7475
|
};
|
|
7474
|
-
agent.runAgent(runParams, this._buildSubscriber())
|
|
7476
|
+
const runPromise = agent.runAgent(runParams, this._buildSubscriber());
|
|
7477
|
+
runPromise.then(() => {
|
|
7478
|
+
this._resetAgentMessages(agent, sentMessageIds);
|
|
7479
|
+
}).catch(() => {
|
|
7480
|
+
});
|
|
7481
|
+
runPromise.catch((err) => {
|
|
7475
7482
|
const message = err instanceof Error ? err.message : "Agent run failed";
|
|
7476
7483
|
const errorName = err instanceof Error ? err.name : null;
|
|
7477
7484
|
const e = err;
|
|
@@ -7480,10 +7487,60 @@ var AgUiTransport = class {
|
|
|
7480
7487
|
const body = typeof rawBody === "string" ? rawBody.slice(0, 500) : rawBody != null ? JSON.stringify(rawBody).slice(0, 500) : null;
|
|
7481
7488
|
this._pendingResume = false;
|
|
7482
7489
|
this._currentAssistantMessageId = null;
|
|
7490
|
+
this._resetAgentMessages(agent, sentMessageIds);
|
|
7483
7491
|
this._emit({ type: "error", message, status, body, errorName });
|
|
7484
7492
|
this._emit({ type: "typing", isTyping: false });
|
|
7485
7493
|
});
|
|
7486
7494
|
}
|
|
7495
|
+
/**
|
|
7496
|
+
* Reset `agent.messages` after a settled run (server-owned history).
|
|
7497
|
+
*
|
|
7498
|
+
* The backend owns conversation state (`chat_threads.native_messages`);
|
|
7499
|
+
* the agent object is only a request builder, so anything that already
|
|
7500
|
+
* shipped in a run is dropped. The ONLY retention is undelivered
|
|
7501
|
+
* client-tool state: an assistant message carrying `toolCalls` for a
|
|
7502
|
+
* tool in `clientTools` whose result either doesn't exist yet (the UI
|
|
7503
|
+
* is still computing/asking) or was queued mid-run and never shipped
|
|
7504
|
+
* (`_sendToolResult` while `isRunning`). The retained pair makes the
|
|
7505
|
+
* next run's wire self-consistent — a `role: "tool"` message without
|
|
7506
|
+
* its matching call in the SAME client list is dropped by the backend
|
|
7507
|
+
* filter and the result would be lost.
|
|
7508
|
+
*
|
|
7509
|
+
* No-op unless `serverOwnedHistory` is set: the adaptive runtime and
|
|
7510
|
+
* editor chat backends still build the model conversation from the
|
|
7511
|
+
* client's `messages` array.
|
|
7512
|
+
*/
|
|
7513
|
+
_resetAgentMessages(agent, sentMessageIds) {
|
|
7514
|
+
if (!this._serverOwnedHistory) return;
|
|
7515
|
+
if (agent !== this._agent) return;
|
|
7516
|
+
const messages = agent.messages ?? [];
|
|
7517
|
+
const resultsByCallId = /* @__PURE__ */ new Map();
|
|
7518
|
+
for (const msg of messages) {
|
|
7519
|
+
if (msg.role === "tool" && typeof msg.toolCallId === "string") {
|
|
7520
|
+
resultsByCallId.set(msg.toolCallId, msg);
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
const retained = [];
|
|
7524
|
+
for (const msg of messages) {
|
|
7525
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.toolCalls)) continue;
|
|
7526
|
+
const pendingCalls = msg.toolCalls.filter((tc) => {
|
|
7527
|
+
if (!this._clientTools.has(tc.function?.name)) return false;
|
|
7528
|
+
const result = resultsByCallId.get(tc.id);
|
|
7529
|
+
return result === void 0 || !sentMessageIds.has(result.id);
|
|
7530
|
+
});
|
|
7531
|
+
if (pendingCalls.length === 0) continue;
|
|
7532
|
+
retained.push({ ...msg, toolCalls: pendingCalls });
|
|
7533
|
+
for (const tc of pendingCalls) {
|
|
7534
|
+
const result = resultsByCallId.get(tc.id);
|
|
7535
|
+
if (result !== void 0) retained.push(result);
|
|
7536
|
+
}
|
|
7537
|
+
}
|
|
7538
|
+
if (typeof agent.setMessages === "function") {
|
|
7539
|
+
agent.setMessages(retained);
|
|
7540
|
+
} else {
|
|
7541
|
+
agent.messages = retained;
|
|
7542
|
+
}
|
|
7543
|
+
}
|
|
7487
7544
|
_buildSubscriber() {
|
|
7488
7545
|
return {
|
|
7489
7546
|
onTextMessageStartEvent: (params) => {
|
|
@@ -8695,4 +8752,4 @@ fast-json-patch/module/duplex.mjs:
|
|
|
8695
8752
|
* MIT license
|
|
8696
8753
|
*)
|
|
8697
8754
|
*/
|
|
8698
|
-
//# sourceMappingURL=chunk-
|
|
8755
|
+
//# sourceMappingURL=chunk-ES5JYJA7.js.map
|