@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.
- package/dist/{bridge-entry-D2u56i8T.d.ts → bridge-entry-BQ6UUSLZ.d.ts} +2 -2
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +3 -3
- package/dist/{chunk-52ZKPX3G.js → chunk-YBNKD5UM.js} +490 -160
- package/dist/chunk-YBNKD5UM.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +3 -2
- package/dist/chunk-52ZKPX3G.js.map +0 -1
|
@@ -1503,160 +1503,507 @@ function toAgentFactory(def, opts) {
|
|
|
1503
1503
|
}
|
|
1504
1504
|
__name(toAgentFactory, "toAgentFactory");
|
|
1505
1505
|
|
|
1506
|
-
//
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
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
|
-
|
|
1520
|
-
|
|
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(
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
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(
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
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
|
-
|
|
1552
|
-
type: "reasoning-delta",
|
|
1553
|
-
id: reasoningId,
|
|
1554
|
-
delta: content
|
|
1555
|
-
};
|
|
1589
|
+
return events;
|
|
1556
1590
|
}
|
|
1557
|
-
__name(
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
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(
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
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
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
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(
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
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(
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
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(
|
|
1625
|
-
async function*
|
|
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
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
yield*
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
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
|
-
}
|
|
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*
|
|
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(
|
|
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
|
|
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
|
|
2616
|
+
function asString3(value, fallback) {
|
|
2287
2617
|
return typeof value === "string" ? value : fallback;
|
|
2288
2618
|
}
|
|
2289
|
-
__name(
|
|
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 =
|
|
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 ??
|
|
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:
|
|
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(
|
|
2393
|
-
name:
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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-
|
|
3478
|
+
//# sourceMappingURL=chunk-YBNKD5UM.js.map
|