@tangle-network/agent-app 0.60.160 → 0.60.161

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.
@@ -123,6 +123,8 @@ export interface ChatTurnMessageStore {
123
123
  * drain. `createSandboxChatProducer` returns this; a router-lane producer
124
124
  * may omit the optional members (finalText persists as a single text part). */
125
125
  export interface ChatTurnRouteProducer extends ChatTurnProducer {
126
+ /** Actual backend result/done was observed; transport EOF/error alone is not completion. */
127
+ terminalObserved?(): boolean;
126
128
  assistantParts?(): Array<Record<string, unknown>>;
127
129
  /** MID-STREAM snapshot of the same projection, safe to call while the turn
128
130
  * is running: no dangling-tool terminalization, no pending-ask settlement
@@ -500,12 +500,14 @@ function createChatTurnRoutes(options) {
500
500
  });
501
501
  if (!prepared.ok) return prepared.response;
502
502
  }
503
- const existingMessages = (await options.store.listMessages(payload.threadId)).map((m) => ({
503
+ const readHistory = async () => (await options.store.listMessages(payload.threadId)).map((m) => ({
504
504
  id: m.id,
505
505
  role: m.role,
506
506
  content: m.content,
507
507
  parts: m.parts ?? null
508
508
  }));
509
+ const existingMessages = await readHistory();
510
+ const historyBeforeLock = options.turnLock ? JSON.stringify(existingMessages) : void 0;
509
511
  let hasRunningTurn = false;
510
512
  if (draftTuning && existingMessages.at(-1)?.role === "assistant") {
511
513
  try {
@@ -647,6 +649,13 @@ function createChatTurnRoutes(options) {
647
649
  }
648
650
  };
649
651
  try {
652
+ if (lockAcquired && JSON.stringify(await readHistory()) !== historyBeforeLock) {
653
+ await releaseLock();
654
+ return Response.json({
655
+ code: "chat_history_changed",
656
+ error: "The conversation changed while this turn was acquiring its lock. Refresh the conversation before starting new work."
657
+ }, { status: 409 });
658
+ }
650
659
  const insertUserMessage = chatTurn.shouldInsertUserMessage && (auth.insertUserMessage ?? true);
651
660
  let userMessageId = chatTurn.reusedUserMessageId ?? null;
652
661
  if (insertUserMessage) {
@@ -1261,4 +1270,4 @@ export {
1261
1270
  createChatTurnRoutes,
1262
1271
  streamChatRouteAsSandboxEvents
1263
1272
  };
1264
- //# sourceMappingURL=chunk-N5M7YT6P.js.map
1273
+ //# sourceMappingURL=chunk-PYPWEXTD.js.map