repoburg 1.3.307 → 1.3.309

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.
@@ -41379,6 +41379,11 @@ function getWss() {
41379
41379
  return wss;
41380
41380
  }
41381
41381
 
41382
+ // ../shared/stream-protocol.ts
41383
+ function fallbackStreamItemId(turnId) {
41384
+ return `stream-text-${turnId}`;
41385
+ }
41386
+
41382
41387
  // src/ws/streams.ts
41383
41388
  var TURN_ENDS = /* @__PURE__ */ new Set(["turn:completed", "turn:failed", "turn:cancelled", "turn:interrupted", "turn:resuming"]);
41384
41389
  var streams = /* @__PURE__ */ new Map();
@@ -41404,6 +41409,7 @@ function noteItem(p) {
41404
41409
  return;
41405
41410
  }
41406
41411
  streams.delete(key);
41412
+ if (p.item?.type === "agent_message") streams.delete(keyOf(p.sessionId, p.turnId, fallbackStreamItemId(p.turnId)));
41407
41413
  }
41408
41414
  function dropTurn(p) {
41409
41415
  for (const [key, stream] of streams) {
@@ -42368,10 +42374,13 @@ async function registerSessionRoutes(fastify) {
42368
42374
  if (!session) {
42369
42375
  return reply.code(404).send({ error: "Session not found" });
42370
42376
  }
42371
- const targetTurn = db2.prepare("SELECT created_at FROM turns WHERE id = ? AND session_id = ?").get(turn_id, id);
42377
+ const targetTurn = db2.prepare("SELECT created_at, thread_id FROM turns WHERE id = ? AND session_id = ?").get(turn_id, id);
42372
42378
  if (!targetTurn) {
42373
42379
  return reply.code(404).send({ error: "Turn not found" });
42374
42380
  }
42381
+ if (targetTurn.thread_id != null) {
42382
+ return reply.code(400).send({ error: "Cannot branch from a discussion thread turn" });
42383
+ }
42375
42384
  const newSessionId = v4_default();
42376
42385
  const now = (/* @__PURE__ */ new Date()).toISOString();
42377
42386
  const newTitle = title || `Branch of ${session.title || session.id.slice(0, 8)}`;
@@ -42389,7 +42398,9 @@ async function registerSessionRoutes(fastify) {
42389
42398
  now,
42390
42399
  session.runtime_config
42391
42400
  );
42392
- const turnRows = db2.prepare("SELECT * FROM turns WHERE session_id = ? AND created_at <= ? ORDER BY created_at ASC").all(id, targetTurn.created_at);
42401
+ const turnRows = db2.prepare(
42402
+ "SELECT * FROM turns WHERE session_id = ? AND thread_id IS NULL AND created_at <= ? ORDER BY created_at ASC"
42403
+ ).all(id, targetTurn.created_at);
42393
42404
  for (const turn of turnRows) {
42394
42405
  const newTurnId = v4_default();
42395
42406
  db2.prepare(
@@ -121883,7 +121894,6 @@ function handleAssistantMessage(message, sessionId, turnId, entry, db2) {
121883
121894
  if (desc.type === "agent_message") desc.externalId = anthropicMsgId;
121884
121895
  }
121885
121896
  if (thinkingTexts) thinkingAccumulator.delete(messageId);
121886
- streamingMessageIds.delete(turnId);
121887
121897
  for (const desc of descriptors) {
121888
121898
  const isToolCall = TOOL_ITEM_TYPES.has(desc.type);
121889
121899
  const status = isToolCall ? "in_progress" : "completed";
@@ -121937,6 +121947,9 @@ function handleStreamEvent(message, sessionId, turnId, entry, db2) {
121937
121947
  if (rawEvent.type === "message_start" && rawEvent.message?.id && !parentToolUseId) {
121938
121948
  streamingMessageIds.set(turnId, rawEvent.message.id);
121939
121949
  }
121950
+ if (rawEvent.type === "message_stop" && !parentToolUseId) {
121951
+ streamingMessageIds.delete(turnId);
121952
+ }
121940
121953
  if (!parentToolUseId) {
121941
121954
  if (rawEvent.type === "message_start" && rawEvent.message?.id) {
121942
121955
  recordApiUsage(entry, sessionId, db2, rawEvent.message.id, rawEvent.message.usage);
@@ -121951,7 +121964,7 @@ function handleStreamEvent(message, sessionId, turnId, entry, db2) {
121951
121964
  if (!delta) return;
121952
121965
  if (parentToolUseId) return;
121953
121966
  if (delta.kind === "text") {
121954
- const msgId = streamingMessageIds.get(turnId) ?? `stream-text-${turnId}`;
121967
+ const msgId = streamingMessageIds.get(turnId) ?? fallbackStreamItemId(turnId);
121955
121968
  const payload = { sessionId, turnId, itemId: msgId, delta: delta.text };
121956
121969
  if (entry.replaying) noteDelta(payload);
121957
121970
  else broadcast("item:delta", payload);
@@ -41366,6 +41366,11 @@ function broadcast(event, data) {
41366
41366
  }
41367
41367
  }
41368
41368
 
41369
+ // ../shared/stream-protocol.ts
41370
+ function fallbackStreamItemId(turnId) {
41371
+ return `stream-text-${turnId}`;
41372
+ }
41373
+
41369
41374
  // src/ws/streams.ts
41370
41375
  var TURN_ENDS = /* @__PURE__ */ new Set(["turn:completed", "turn:failed", "turn:cancelled", "turn:interrupted", "turn:resuming"]);
41371
41376
  var streams = /* @__PURE__ */ new Map();
@@ -41391,6 +41396,7 @@ function noteItem(p) {
41391
41396
  return;
41392
41397
  }
41393
41398
  streams.delete(key);
41399
+ if (p.item?.type === "agent_message") streams.delete(keyOf(p.sessionId, p.turnId, fallbackStreamItemId(p.turnId)));
41394
41400
  }
41395
41401
  function dropTurn(p) {
41396
41402
  for (const [key, stream] of streams) {
@@ -42351,10 +42357,13 @@ async function registerSessionRoutes(fastify) {
42351
42357
  if (!session) {
42352
42358
  return reply.code(404).send({ error: "Session not found" });
42353
42359
  }
42354
- const targetTurn = db2.prepare("SELECT created_at FROM turns WHERE id = ? AND session_id = ?").get(turn_id, id);
42360
+ const targetTurn = db2.prepare("SELECT created_at, thread_id FROM turns WHERE id = ? AND session_id = ?").get(turn_id, id);
42355
42361
  if (!targetTurn) {
42356
42362
  return reply.code(404).send({ error: "Turn not found" });
42357
42363
  }
42364
+ if (targetTurn.thread_id != null) {
42365
+ return reply.code(400).send({ error: "Cannot branch from a discussion thread turn" });
42366
+ }
42358
42367
  const newSessionId = v4_default();
42359
42368
  const now = (/* @__PURE__ */ new Date()).toISOString();
42360
42369
  const newTitle = title || `Branch of ${session.title || session.id.slice(0, 8)}`;
@@ -42372,7 +42381,9 @@ async function registerSessionRoutes(fastify) {
42372
42381
  now,
42373
42382
  session.runtime_config
42374
42383
  );
42375
- const turnRows = db2.prepare("SELECT * FROM turns WHERE session_id = ? AND created_at <= ? ORDER BY created_at ASC").all(id, targetTurn.created_at);
42384
+ const turnRows = db2.prepare(
42385
+ "SELECT * FROM turns WHERE session_id = ? AND thread_id IS NULL AND created_at <= ? ORDER BY created_at ASC"
42386
+ ).all(id, targetTurn.created_at);
42376
42387
  for (const turn of turnRows) {
42377
42388
  const newTurnId = v4_default();
42378
42389
  db2.prepare(
@@ -121896,7 +121907,6 @@ function handleAssistantMessage(message, sessionId, turnId, entry, db2) {
121896
121907
  if (desc.type === "agent_message") desc.externalId = anthropicMsgId;
121897
121908
  }
121898
121909
  if (thinkingTexts) thinkingAccumulator.delete(messageId);
121899
- streamingMessageIds.delete(turnId);
121900
121910
  for (const desc of descriptors) {
121901
121911
  const isToolCall = TOOL_ITEM_TYPES.has(desc.type);
121902
121912
  const status = isToolCall ? "in_progress" : "completed";
@@ -121950,6 +121960,9 @@ function handleStreamEvent(message, sessionId, turnId, entry, db2) {
121950
121960
  if (rawEvent.type === "message_start" && rawEvent.message?.id && !parentToolUseId) {
121951
121961
  streamingMessageIds.set(turnId, rawEvent.message.id);
121952
121962
  }
121963
+ if (rawEvent.type === "message_stop" && !parentToolUseId) {
121964
+ streamingMessageIds.delete(turnId);
121965
+ }
121953
121966
  if (!parentToolUseId) {
121954
121967
  if (rawEvent.type === "message_start" && rawEvent.message?.id) {
121955
121968
  recordApiUsage(entry, sessionId, db2, rawEvent.message.id, rawEvent.message.usage);
@@ -121964,7 +121977,7 @@ function handleStreamEvent(message, sessionId, turnId, entry, db2) {
121964
121977
  if (!delta) return;
121965
121978
  if (parentToolUseId) return;
121966
121979
  if (delta.kind === "text") {
121967
- const msgId = streamingMessageIds.get(turnId) ?? `stream-text-${turnId}`;
121980
+ const msgId = streamingMessageIds.get(turnId) ?? fallbackStreamItemId(turnId);
121968
121981
  const payload = { sessionId, turnId, itemId: msgId, delta: delta.text };
121969
121982
  if (entry.replaying) noteDelta(payload);
121970
121983
  else broadcast("item:delta", payload);
@@ -1,4 +1,4 @@
1
- var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-Cko45vc_.js";/**
1
+ var en=Object.defineProperty;var tn=(e,t,i)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var Ye=(e,t,i)=>tn(e,typeof t!="symbol"?t+"":t,i);import{c as sn,b as rn,u as gi,r as lt,j as Ee,R as nn,X as on}from"./index-YjXfH1jk.js";/**
2
2
  * @license lucide-react v0.469.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.