@sandagent/runner-cli 0.9.13 → 0.9.14

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.
Files changed (2) hide show
  1. package/dist/bundle.mjs +42 -16
  2. package/package.json +1 -1
package/dist/bundle.mjs CHANGED
@@ -1523,10 +1523,27 @@ ${options.systemPrompt}` : options.systemPrompt);
1523
1523
  }
1524
1524
  const promptPromise = session.prompt(promptText, images ? { images } : void 0);
1525
1525
  const messageId = `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1526
- const textId = `text_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1527
1526
  let hasStarted = false;
1528
- let hasTextStarted = false;
1529
1527
  let hasFinished = false;
1528
+ const newTextPartId = () => `text_${Date.now()}_${Math.random().toString(36).slice(2)}_${Math.random().toString(36).slice(2)}`;
1529
+ let activeTextPartId = null;
1530
+ let textStreamOpen = false;
1531
+ const endTextStreamIfOpen = function* () {
1532
+ if (textStreamOpen && activeTextPartId != null) {
1533
+ yield `data: ${JSON.stringify({ type: "text-end", id: activeTextPartId })}
1534
+
1535
+ `;
1536
+ textStreamOpen = false;
1537
+ activeTextPartId = null;
1538
+ }
1539
+ };
1540
+ const beginTextStream = function* () {
1541
+ activeTextPartId = newTextPartId();
1542
+ yield `data: ${JSON.stringify({ type: "text-start", id: activeTextPartId })}
1543
+
1544
+ `;
1545
+ textStreamOpen = true;
1546
+ };
1530
1547
  const ensureStartEvent = async function* () {
1531
1548
  if (!hasStarted) {
1532
1549
  yield `data: ${JSON.stringify({ type: "start", messageId })}
@@ -1542,11 +1559,7 @@ ${options.systemPrompt}` : options.systemPrompt);
1542
1559
  }
1543
1560
  };
1544
1561
  const finishSuccess = async function* (usage) {
1545
- if (hasTextStarted) {
1546
- yield `data: ${JSON.stringify({ type: "text-end", id: textId })}
1547
-
1548
- `;
1549
- }
1562
+ yield* endTextStreamIfOpen();
1550
1563
  const finishPayload = { type: "finish", finishReason: "stop" };
1551
1564
  if (usage != null) {
1552
1565
  finishPayload.messageMetadata = {
@@ -1570,22 +1583,35 @@ ${options.systemPrompt}` : options.systemPrompt);
1570
1583
  const event = eventQueue.shift();
1571
1584
  traceRawMessage(cwd, event);
1572
1585
  yield* ensureStartEvent();
1573
- if (event.type === "message_update") {
1574
- if (event.assistantMessageEvent.type === "text_delta") {
1575
- const delta = event.assistantMessageEvent.delta;
1586
+ if (event.type === "message_start") {
1587
+ const msg = event.message;
1588
+ if (msg?.role === "assistant") {
1589
+ yield* endTextStreamIfOpen();
1590
+ }
1591
+ } else if (event.type === "message_update") {
1592
+ const sub = event.assistantMessageEvent;
1593
+ if (sub.type === "text_start") {
1594
+ yield* endTextStreamIfOpen();
1595
+ yield* beginTextStream();
1596
+ } else if (sub.type === "text_delta") {
1597
+ const delta = sub.delta;
1576
1598
  if (delta) {
1577
- if (!hasTextStarted) {
1578
- yield `data: ${JSON.stringify({ type: "text-start", id: textId })}
1579
-
1580
- `;
1581
- hasTextStarted = true;
1599
+ if (!textStreamOpen) {
1600
+ yield* beginTextStream();
1582
1601
  }
1583
- yield `data: ${JSON.stringify({ type: "text-delta", id: textId, delta })}
1602
+ yield `data: ${JSON.stringify({
1603
+ type: "text-delta",
1604
+ id: activeTextPartId,
1605
+ delta
1606
+ })}
1584
1607
 
1585
1608
  `;
1586
1609
  }
1610
+ } else if (sub.type === "toolcall_start") {
1611
+ yield* endTextStreamIfOpen();
1587
1612
  }
1588
1613
  } else if (event.type === "tool_execution_start") {
1614
+ yield* endTextStreamIfOpen();
1589
1615
  yield `data: ${JSON.stringify({ type: "tool-input-start", toolCallId: event.toolCallId, toolName: event.toolName, dynamic: true, providerExecuted: true })}
1590
1616
 
1591
1617
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandagent/runner-cli",
3
- "version": "0.9.13",
3
+ "version": "0.9.14",
4
4
  "description": "SandAgent Runner CLI - Like gemini-cli or claude-code, runs in your local terminal with AI SDK UI streaming",
5
5
  "type": "module",
6
6
  "bin": {