@theokit/agents 0.44.7 → 0.46.0

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.
@@ -1503,160 +1503,507 @@ function toAgentFactory(def, opts) {
1503
1503
  }
1504
1504
  __name(toAgentFactory, "toAgentFactory");
1505
1505
 
1506
- // src/bridge/ui-message-stream-translator.ts
1507
- function* closeOpenBlock(state, textId) {
1508
- if (state.openBlock === "text") {
1509
- yield {
1510
- type: "text-end",
1511
- id: textId
1512
- };
1513
- } else if (state.openBlock === "reasoning" && state.reasoningId) {
1514
- yield {
1515
- type: "reasoning-end",
1516
- id: state.reasoningId
1517
- };
1506
+ // ../presenter/dist/index.js
1507
+ var __defProp = Object.defineProperty;
1508
+ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp(target, "name", {
1509
+ value,
1510
+ configurable: true
1511
+ }), "__name");
1512
+ var UnknownPresenterError = class extends Error {
1513
+ static {
1514
+ __name(this, "UnknownPresenterError");
1518
1515
  }
1519
- state.openBlock = null;
1520
- state.reasoningId = null;
1516
+ static {
1517
+ __name2(this, "UnknownPresenterError");
1518
+ }
1519
+ name = "UnknownPresenterError";
1520
+ constructor(surface, known) {
1521
+ super(`No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`);
1522
+ }
1523
+ };
1524
+ var PresenterRegistry = class {
1525
+ static {
1526
+ __name(this, "PresenterRegistry");
1527
+ }
1528
+ static {
1529
+ __name2(this, "PresenterRegistry");
1530
+ }
1531
+ #presenters = /* @__PURE__ */ new Map();
1532
+ /** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */
1533
+ register(presenter) {
1534
+ this.#presenters.set(presenter.surface, presenter);
1535
+ return this;
1536
+ }
1537
+ /** Whether a presenter is registered for `surface`. */
1538
+ has(surface) {
1539
+ return this.#presenters.has(surface);
1540
+ }
1541
+ /** The registered surface keys. */
1542
+ surfaces() {
1543
+ return [
1544
+ ...this.#presenters.keys()
1545
+ ];
1546
+ }
1547
+ /** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */
1548
+ resolve(surface) {
1549
+ const p = this.#presenters.get(surface);
1550
+ if (p === void 0) throw new UnknownPresenterError(surface, this.surfaces());
1551
+ return p;
1552
+ }
1553
+ };
1554
+ function asString2(value, fallback) {
1555
+ return typeof value === "string" ? value : fallback;
1521
1556
  }
1522
- __name(closeOpenBlock, "closeOpenBlock");
1523
- function* emitTextDelta(state, textId, content) {
1524
- if (state.openBlock !== "text") {
1525
- yield* closeOpenBlock(state, textId);
1526
- yield {
1527
- type: "text-start",
1528
- id: textId
1529
- };
1530
- state.openBlock = "text";
1557
+ __name(asString2, "asString");
1558
+ __name2(asString2, "asString");
1559
+ function serializeToolResult(value, fallback) {
1560
+ if (typeof value === "string") return value;
1561
+ if (value === void 0 || value === null) return fallback;
1562
+ try {
1563
+ return JSON.stringify(value);
1564
+ } catch {
1565
+ return typeof value === "bigint" ? value.toString() : fallback;
1531
1566
  }
1532
- yield {
1533
- type: "text-delta",
1534
- id: textId,
1535
- delta: content
1536
- };
1537
1567
  }
1538
- __name(emitTextDelta, "emitTextDelta");
1539
- function* emitReasoningDelta(state, textId, content) {
1540
- let reasoningId = state.openBlock === "reasoning" ? state.reasoningId : null;
1541
- if (reasoningId === null) {
1542
- yield* closeOpenBlock(state, textId);
1543
- reasoningId = crypto.randomUUID();
1544
- state.reasoningId = reasoningId;
1545
- yield {
1546
- type: "reasoning-start",
1547
- id: reasoningId
1548
- };
1549
- state.openBlock = "reasoning";
1568
+ __name(serializeToolResult, "serializeToolResult");
1569
+ __name2(serializeToolResult, "serializeToolResult");
1570
+ function fromAssistant(msg) {
1571
+ const events = [];
1572
+ const content = msg.message?.content;
1573
+ if (!Array.isArray(content)) return events;
1574
+ for (const block of content) {
1575
+ const b = block;
1576
+ if (b.type === "text" && b.text) events.push({
1577
+ type: "text",
1578
+ text: b.text
1579
+ });
1580
+ if (b.type === "tool_use") {
1581
+ events.push({
1582
+ type: "tool-call",
1583
+ callId: b.id ?? `tc-${Date.now()}`,
1584
+ name: b.name ?? "unknown",
1585
+ input: b.input ?? {}
1586
+ });
1587
+ }
1550
1588
  }
1551
- yield {
1552
- type: "reasoning-delta",
1553
- id: reasoningId,
1554
- delta: content
1555
- };
1589
+ return events;
1556
1590
  }
1557
- __name(emitReasoningDelta, "emitReasoningDelta");
1558
- function* emitToolCall(event, seen) {
1559
- seen.add(event.callId);
1560
- yield {
1561
- type: "tool-input-available",
1562
- toolCallId: event.callId,
1563
- toolName: event.toolName,
1564
- input: event.input,
1565
- dynamic: true
1566
- };
1591
+ __name(fromAssistant, "fromAssistant");
1592
+ __name2(fromAssistant, "fromAssistant");
1593
+ function fromToolUse(msg) {
1594
+ const status = msg.status;
1595
+ const callId = asString2(msg.call_id, `tc-${Date.now()}`);
1596
+ const name = asString2(msg.name, "unknown");
1597
+ if (status === "completed") {
1598
+ return [
1599
+ {
1600
+ type: "tool-result",
1601
+ callId,
1602
+ name,
1603
+ result: serializeToolResult(msg.result, ""),
1604
+ isError: false
1605
+ }
1606
+ ];
1607
+ }
1608
+ if (status === "error") {
1609
+ return [
1610
+ {
1611
+ type: "tool-result",
1612
+ callId,
1613
+ name,
1614
+ result: serializeToolResult(msg.result, "Tool failed"),
1615
+ isError: true
1616
+ }
1617
+ ];
1618
+ }
1619
+ if (status === "running") {
1620
+ return [
1621
+ {
1622
+ type: "tool-call",
1623
+ callId,
1624
+ name,
1625
+ input: msg.args ?? msg.input ?? msg.arguments ?? {}
1626
+ }
1627
+ ];
1628
+ }
1629
+ return [];
1567
1630
  }
1568
- __name(emitToolCall, "emitToolCall");
1569
- function* emitToolResult(event, seen) {
1570
- if (!seen.has(event.callId)) {
1571
- seen.add(event.callId);
1572
- yield {
1573
- type: "tool-input-available",
1574
- toolCallId: event.callId,
1575
- toolName: event.toolName,
1576
- input: {},
1577
- dynamic: true
1578
- };
1631
+ __name(fromToolUse, "fromToolUse");
1632
+ __name2(fromToolUse, "fromToolUse");
1633
+ function fromStatus(msg) {
1634
+ const s = msg.status;
1635
+ if (s === "FINISHED" || s === "CANCELLED") return [
1636
+ {
1637
+ type: "finish",
1638
+ reason: s.toLowerCase()
1639
+ }
1640
+ ];
1641
+ if (s === "ERROR" || s === "EXPIRED") {
1642
+ return [
1643
+ {
1644
+ type: "error",
1645
+ message: asString2(msg.message, "Agent error"),
1646
+ code: "AGENT_ERROR"
1647
+ }
1648
+ ];
1579
1649
  }
1580
- if (event.isError) {
1581
- yield {
1582
- type: "tool-output-error",
1583
- toolCallId: event.callId,
1584
- errorText: event.output
1585
- };
1586
- } else {
1587
- yield {
1588
- type: "tool-output-available",
1589
- toolCallId: event.callId,
1590
- output: event.output
1591
- };
1650
+ return [];
1651
+ }
1652
+ __name(fromStatus, "fromStatus");
1653
+ __name2(fromStatus, "fromStatus");
1654
+ function fromSdkMessage(msg) {
1655
+ switch (msg.type) {
1656
+ case "assistant":
1657
+ return fromAssistant(msg);
1658
+ case "tool_call":
1659
+ return fromToolUse(msg);
1660
+ case "thinking":
1661
+ return [
1662
+ {
1663
+ type: "reasoning",
1664
+ text: asString2(msg.text, "")
1665
+ }
1666
+ ];
1667
+ case "status":
1668
+ return fromStatus(msg);
1669
+ // `system` / run-lifecycle is framework framing, not pure output — intentionally skipped (ADR-4).
1670
+ default:
1671
+ return [];
1592
1672
  }
1593
1673
  }
1594
- __name(emitToolResult, "emitToolResult");
1595
- function* emitApprovalRequest(event, seen) {
1596
- if (!seen.has(event.callId)) {
1597
- seen.add(event.callId);
1598
- yield {
1599
- type: "tool-input-available",
1600
- toolCallId: event.callId,
1601
- toolName: event.toolName,
1602
- input: event.input ?? {},
1603
- dynamic: true
1604
- };
1674
+ __name(fromSdkMessage, "fromSdkMessage");
1675
+ __name2(fromSdkMessage, "fromSdkMessage");
1676
+ function fromInteractionUpdate(update) {
1677
+ switch (update.type) {
1678
+ case "text-delta":
1679
+ return update.text ? [
1680
+ {
1681
+ type: "text",
1682
+ text: update.text
1683
+ }
1684
+ ] : [];
1685
+ case "thinking-delta":
1686
+ return update.text ? [
1687
+ {
1688
+ type: "reasoning",
1689
+ text: update.text
1690
+ }
1691
+ ] : [];
1692
+ case "tool-call-started":
1693
+ return [
1694
+ {
1695
+ type: "tool-call",
1696
+ callId: update.callId,
1697
+ name: update.toolCall.name,
1698
+ input: update.toolCall.args ?? {}
1699
+ }
1700
+ ];
1701
+ case "partial-tool-call":
1702
+ return [
1703
+ {
1704
+ type: "partial-tool-call",
1705
+ callId: update.callId,
1706
+ name: update.toolCall.name,
1707
+ input: update.toolCall.args ?? {}
1708
+ }
1709
+ ];
1710
+ case "tool-call-completed":
1711
+ return [
1712
+ {
1713
+ type: "tool-result",
1714
+ callId: update.callId,
1715
+ name: update.toolCall.name,
1716
+ result: serializeToolResult(update.toolCall.result, ""),
1717
+ isError: false
1718
+ }
1719
+ ];
1720
+ default:
1721
+ return [];
1605
1722
  }
1606
- yield {
1607
- type: "tool-approval-request",
1608
- approvalId: event.callId,
1609
- toolCallId: event.callId
1610
- };
1611
1723
  }
1612
- __name(emitApprovalRequest, "emitApprovalRequest");
1613
- function* emitCheckpointSaved(event) {
1614
- yield {
1615
- type: "data-checkpoint",
1616
- data: {
1617
- checkpointId: event.checkpointId,
1618
- resumeToken: event.resumeToken,
1619
- step: event.step
1620
- },
1621
- transient: true
1724
+ __name(fromInteractionUpdate, "fromInteractionUpdate");
1725
+ __name2(fromInteractionUpdate, "fromInteractionUpdate");
1726
+ var UIMessageStreamPresenter = class {
1727
+ static {
1728
+ __name(this, "UIMessageStreamPresenter");
1729
+ }
1730
+ static {
1731
+ __name2(this, "UIMessageStreamPresenter");
1732
+ }
1733
+ surface = "ui-message-stream";
1734
+ #textId;
1735
+ #openBlock = null;
1736
+ #reasoningId = null;
1737
+ #seen = /* @__PURE__ */ new Set();
1738
+ constructor(options) {
1739
+ this.#textId = options.textId;
1740
+ }
1741
+ /** Emit the opening `start` chunk (exactly once, before any event). */
1742
+ start() {
1743
+ return [
1744
+ {
1745
+ type: "start"
1746
+ }
1747
+ ];
1748
+ }
1749
+ present(event) {
1750
+ switch (event.type) {
1751
+ case "text":
1752
+ return this.#emitTextDelta(event.text);
1753
+ case "reasoning":
1754
+ return this.#emitReasoningDelta(event.text);
1755
+ case "tool-call":
1756
+ return [
1757
+ ...this.#closeOpenBlock(),
1758
+ ...this.#emitToolCall(event.callId, event.name, event.input)
1759
+ ];
1760
+ case "tool-result":
1761
+ return [
1762
+ ...this.#closeOpenBlock(),
1763
+ ...this.#emitToolResult(event.callId, event.name, event.result, event.isError ?? false)
1764
+ ];
1765
+ case "error":
1766
+ return [
1767
+ {
1768
+ type: "error",
1769
+ errorText: event.message
1770
+ }
1771
+ ];
1772
+ // `partial-tool-call` streams incremental args — the current web path emits no chunk for it
1773
+ // (args are shown on the committed `tool-call`); `finish` / `status` are handled by finish()/host.
1774
+ default:
1775
+ return [];
1776
+ }
1777
+ }
1778
+ /**
1779
+ * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
1780
+ * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
1781
+ * finish is bare (error/abort turns), byte-identical to the original translator.
1782
+ */
1783
+ finish(metadata) {
1784
+ const out = this.#closeOpenBlock();
1785
+ out.push(metadata ? {
1786
+ type: "finish",
1787
+ messageMetadata: metadata
1788
+ } : {
1789
+ type: "finish"
1790
+ });
1791
+ return out;
1792
+ }
1793
+ /**
1794
+ * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
1795
+ * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
1796
+ * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
1797
+ */
1798
+ closeBlock() {
1799
+ return this.#closeOpenBlock();
1800
+ }
1801
+ /**
1802
+ * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
1803
+ * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
1804
+ */
1805
+ hasSeen(callId) {
1806
+ return this.#seen.has(callId);
1807
+ }
1808
+ /** Mark a `callId` as introduced (the host synthesized its `tool-input` for a framework chunk). */
1809
+ markSeen(callId) {
1810
+ this.#seen.add(callId);
1811
+ }
1812
+ // --- internal open-block state machine (verbatim from the original translator) ---
1813
+ #closeOpenBlock() {
1814
+ const out = [];
1815
+ if (this.#openBlock === "text") {
1816
+ out.push({
1817
+ type: "text-end",
1818
+ id: this.#textId
1819
+ });
1820
+ } else if (this.#openBlock === "reasoning" && this.#reasoningId) {
1821
+ out.push({
1822
+ type: "reasoning-end",
1823
+ id: this.#reasoningId
1824
+ });
1825
+ }
1826
+ this.#openBlock = null;
1827
+ this.#reasoningId = null;
1828
+ return out;
1829
+ }
1830
+ #emitTextDelta(content) {
1831
+ const out = [];
1832
+ if (this.#openBlock !== "text") {
1833
+ out.push(...this.#closeOpenBlock(), {
1834
+ type: "text-start",
1835
+ id: this.#textId
1836
+ });
1837
+ this.#openBlock = "text";
1838
+ }
1839
+ out.push({
1840
+ type: "text-delta",
1841
+ id: this.#textId,
1842
+ delta: content
1843
+ });
1844
+ return out;
1845
+ }
1846
+ #emitReasoningDelta(content) {
1847
+ const out = [];
1848
+ let reasoningId = this.#openBlock === "reasoning" ? this.#reasoningId : null;
1849
+ if (reasoningId === null) {
1850
+ out.push(...this.#closeOpenBlock());
1851
+ reasoningId = crypto.randomUUID();
1852
+ this.#reasoningId = reasoningId;
1853
+ out.push({
1854
+ type: "reasoning-start",
1855
+ id: reasoningId
1856
+ });
1857
+ this.#openBlock = "reasoning";
1858
+ }
1859
+ out.push({
1860
+ type: "reasoning-delta",
1861
+ id: reasoningId,
1862
+ delta: content
1863
+ });
1864
+ return out;
1865
+ }
1866
+ #emitToolCall(callId, name, input) {
1867
+ this.#seen.add(callId);
1868
+ return [
1869
+ {
1870
+ type: "tool-input-available",
1871
+ toolCallId: callId,
1872
+ toolName: name,
1873
+ input,
1874
+ dynamic: true
1875
+ }
1876
+ ];
1877
+ }
1878
+ #emitToolResult(callId, name, result, isError2) {
1879
+ const out = [];
1880
+ if (!this.#seen.has(callId)) {
1881
+ this.#seen.add(callId);
1882
+ out.push({
1883
+ type: "tool-input-available",
1884
+ toolCallId: callId,
1885
+ toolName: name,
1886
+ input: {},
1887
+ dynamic: true
1888
+ });
1889
+ }
1890
+ const output = typeof result === "string" ? result : "";
1891
+ if (isError2) {
1892
+ out.push({
1893
+ type: "tool-output-error",
1894
+ toolCallId: callId,
1895
+ errorText: output
1896
+ });
1897
+ } else {
1898
+ out.push({
1899
+ type: "tool-output-available",
1900
+ toolCallId: callId,
1901
+ output
1902
+ });
1903
+ }
1904
+ return out;
1905
+ }
1906
+ };
1907
+
1908
+ // src/bridge/present-ui-message-stream.ts
1909
+ function toAgentOutputEvent(e) {
1910
+ switch (e.type) {
1911
+ case "text_delta":
1912
+ return {
1913
+ type: "text",
1914
+ text: e.content
1915
+ };
1916
+ case "thinking":
1917
+ return {
1918
+ type: "reasoning",
1919
+ text: e.content
1920
+ };
1921
+ case "tool_call":
1922
+ return {
1923
+ type: "tool-call",
1924
+ callId: e.callId,
1925
+ name: e.toolName,
1926
+ input: e.input
1927
+ };
1928
+ case "tool_result":
1929
+ return {
1930
+ type: "tool-result",
1931
+ callId: e.callId,
1932
+ name: e.toolName,
1933
+ result: e.output,
1934
+ isError: e.isError
1935
+ };
1936
+ default:
1937
+ return null;
1938
+ }
1939
+ }
1940
+ __name(toAgentOutputEvent, "toAgentOutputEvent");
1941
+ function doneToMetadata(event) {
1942
+ return event.cost === void 0 ? {
1943
+ usage: event.usage,
1944
+ durationMs: event.durationMs
1945
+ } : {
1946
+ usage: event.usage,
1947
+ durationMs: event.durationMs,
1948
+ cost: event.cost
1622
1949
  };
1623
1950
  }
1624
- __name(emitCheckpointSaved, "emitCheckpointSaved");
1625
- async function* translateToUIMessageStream(events, opts) {
1951
+ __name(doneToMetadata, "doneToMetadata");
1952
+ async function* presentUIMessageStream(events, opts) {
1953
+ const presenter = new UIMessageStreamPresenter({
1954
+ textId: opts.textId
1955
+ });
1626
1956
  yield {
1627
1957
  type: "start"
1628
1958
  };
1629
- const state = {
1630
- openBlock: null,
1631
- reasoningId: null
1632
- };
1633
- const seenToolCallIds = /* @__PURE__ */ new Set();
1634
1959
  let turnMetadata;
1635
1960
  try {
1636
1961
  for await (const event of events) {
1637
- if (event.type === "text_delta") {
1638
- yield* emitTextDelta(state, opts.textId, event.content);
1639
- } else if (event.type === "thinking") {
1640
- yield* emitReasoningDelta(state, opts.textId, event.content);
1641
- } else if (event.type === "tool_call") {
1642
- yield* closeOpenBlock(state, opts.textId);
1643
- yield* emitToolCall(event, seenToolCallIds);
1644
- } else if (event.type === "approval_required") {
1645
- yield* closeOpenBlock(state, opts.textId);
1646
- yield* emitApprovalRequest(event, seenToolCallIds);
1647
- } else if (event.type === "tool_result") {
1648
- yield* closeOpenBlock(state, opts.textId);
1649
- yield* emitToolResult(event, seenToolCallIds);
1650
- } else if (event.type === "checkpoint_saved") {
1651
- yield* closeOpenBlock(state, opts.textId);
1652
- yield* emitCheckpointSaved(event);
1653
- } else if (event.type === "error") {
1962
+ const output = toAgentOutputEvent(event);
1963
+ if (output !== null) {
1964
+ yield* presenter.present(output);
1965
+ continue;
1966
+ }
1967
+ if (event.type === "approval_required") {
1968
+ yield* presenter.closeBlock();
1969
+ if (!presenter.hasSeen(event.callId)) {
1970
+ presenter.markSeen(event.callId);
1971
+ yield {
1972
+ type: "tool-input-available",
1973
+ toolCallId: event.callId,
1974
+ toolName: event.toolName,
1975
+ input: event.input ?? {},
1976
+ dynamic: true
1977
+ };
1978
+ }
1979
+ yield {
1980
+ type: "tool-approval-request",
1981
+ approvalId: event.callId,
1982
+ toolCallId: event.callId
1983
+ };
1984
+ continue;
1985
+ }
1986
+ if (event.type === "checkpoint_saved") {
1987
+ yield* presenter.closeBlock();
1988
+ yield {
1989
+ type: "data-checkpoint",
1990
+ data: {
1991
+ checkpointId: event.checkpointId,
1992
+ resumeToken: event.resumeToken,
1993
+ step: event.step
1994
+ },
1995
+ transient: true
1996
+ };
1997
+ continue;
1998
+ }
1999
+ if (event.type === "error") {
1654
2000
  yield {
1655
2001
  type: "error",
1656
2002
  errorText: event.message
1657
2003
  };
1658
2004
  break;
1659
- } else if (event.type === "done") {
2005
+ }
2006
+ if (event.type === "done") {
1660
2007
  turnMetadata = doneToMetadata(event);
1661
2008
  break;
1662
2009
  }
@@ -1667,26 +2014,9 @@ async function* translateToUIMessageStream(events, opts) {
1667
2014
  errorText: String(err)
1668
2015
  };
1669
2016
  }
1670
- yield* closeOpenBlock(state, opts.textId);
1671
- yield turnMetadata ? {
1672
- type: "finish",
1673
- messageMetadata: turnMetadata
1674
- } : {
1675
- type: "finish"
1676
- };
1677
- }
1678
- __name(translateToUIMessageStream, "translateToUIMessageStream");
1679
- function doneToMetadata(event) {
1680
- return event.cost === void 0 ? {
1681
- usage: event.usage,
1682
- durationMs: event.durationMs
1683
- } : {
1684
- usage: event.usage,
1685
- durationMs: event.durationMs,
1686
- cost: event.cost
1687
- };
2017
+ yield* presenter.finish(turnMetadata);
1688
2018
  }
1689
- __name(doneToMetadata, "doneToMetadata");
2019
+ __name(presentUIMessageStream, "presentUIMessageStream");
1690
2020
 
1691
2021
  // src/bridge/agent-builder.ts
1692
2022
  function contextualTool(tool, _requiredContext) {
@@ -1962,7 +2292,7 @@ function streamAgentUIMessages(compiled, apiKey, input) {
1962
2292
  }
1963
2293
  const durableCheckpoint = compiled.checkpoint?.storage === "filesystem";
1964
2294
  const events = durableCheckpoint ? appendCheckpointSaved(source, input.sessionId) : source;
1965
- return translateToUIMessageStream(events, {
2295
+ return presentUIMessageStream(events, {
1966
2296
  textId
1967
2297
  });
1968
2298
  }
@@ -2283,10 +2613,10 @@ var DelegationError = class extends Error {
2283
2613
  };
2284
2614
 
2285
2615
  // src/loop/run-reflective-loop.ts
2286
- function asString2(value, fallback) {
2616
+ function asString3(value, fallback) {
2287
2617
  return typeof value === "string" ? value : fallback;
2288
2618
  }
2289
- __name(asString2, "asString");
2619
+ __name(asString3, "asString");
2290
2620
  function asNumber(value, fallback) {
2291
2621
  return typeof value === "number" ? value : fallback;
2292
2622
  }
@@ -2362,15 +2692,15 @@ function deriveFinishReason(signals) {
2362
2692
  }
2363
2693
  __name(deriveFinishReason, "deriveFinishReason");
2364
2694
  function pushToolResult(event, r, callInputs) {
2365
- const id = asString2(event.callId, "");
2695
+ const id = asString3(event.callId, "");
2366
2696
  const call = callInputs.get(id);
2367
2697
  r.toolCalls.push({
2368
2698
  id,
2369
- name: call?.name ?? asString2(event.toolName, "unknown"),
2699
+ name: call?.name ?? asString3(event.toolName, "unknown"),
2370
2700
  // Prefer the correlated tool_call input (real SDK shape); fall back to an input on the
2371
2701
  // result event itself (some streams/tests carry it there), else {}.
2372
2702
  input: call?.input ?? event.input ?? {},
2373
- output: asString2(event.output, "")
2703
+ output: asString3(event.output, "")
2374
2704
  });
2375
2705
  }
2376
2706
  __name(pushToolResult, "pushToolResult");
@@ -2389,8 +2719,8 @@ function accumulateEvent(event, r, signals, callInputs) {
2389
2719
  if (event.type === "text_delta" && typeof event.content === "string") {
2390
2720
  r.responseText += event.content;
2391
2721
  } else if (event.type === "tool_call") {
2392
- callInputs.set(asString2(event.callId, ""), {
2393
- name: asString2(event.toolName, "unknown"),
2722
+ callInputs.set(asString3(event.callId, ""), {
2723
+ name: asString3(event.toolName, "unknown"),
2394
2724
  input: event.input ?? {}
2395
2725
  });
2396
2726
  } else if (event.type === "tool_result") {
@@ -2398,11 +2728,11 @@ function accumulateEvent(event, r, signals, callInputs) {
2398
2728
  pushToolResult(event, r, callInputs);
2399
2729
  } else if (event.type === "done") {
2400
2730
  signals.sawDone = true;
2401
- signals.doneFinishReason = asString2(event.finishReason, "");
2731
+ signals.doneFinishReason = asString3(event.finishReason, "");
2402
2732
  applyDone(event, r);
2403
2733
  } else if (event.type === "error") {
2404
2734
  signals.sawError = true;
2405
- r.errorMessage = asString2(event.message, "Unknown agent error");
2735
+ r.errorMessage = asString3(event.message, "Unknown agent error");
2406
2736
  }
2407
2737
  }
2408
2738
  __name(accumulateEvent, "accumulateEvent");
@@ -3102,7 +3432,7 @@ export {
3102
3432
  extractThinkTagStream,
3103
3433
  createSdkAgentStream,
3104
3434
  toAgentFactory,
3105
- translateToUIMessageStream,
3435
+ presentUIMessageStream,
3106
3436
  contextualTool,
3107
3437
  agent,
3108
3438
  AgentDefinitionError,
@@ -3145,4 +3475,4 @@ export {
3145
3475
  generateAgentManifest,
3146
3476
  agentsPlugin
3147
3477
  };
3148
- //# sourceMappingURL=chunk-52ZKPX3G.js.map
3478
+ //# sourceMappingURL=chunk-YBNKD5UM.js.map