mitra-interactions-sdk 1.0.60-beta.29 → 1.0.60-beta.30
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/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -592,9 +592,23 @@ var AgentTaskSession = class {
|
|
|
592
592
|
ws.send(JSON.stringify({ type: "approval_response", approved }));
|
|
593
593
|
}
|
|
594
594
|
async loadHistory(options) {
|
|
595
|
+
var _a, _b;
|
|
595
596
|
if (!this._taskId) return [];
|
|
596
597
|
this._history = await listChatMessages(this._taskId, this._projectId, { size: options == null ? void 0 : options.limit });
|
|
597
598
|
this._emit("historyLoaded", { history: this._history });
|
|
599
|
+
for (const message of this._history) {
|
|
600
|
+
if (message.type !== "TOOL_USE") continue;
|
|
601
|
+
const payload = parseObject(message.content);
|
|
602
|
+
if (!payload) continue;
|
|
603
|
+
this._emit("tool", {
|
|
604
|
+
tool: (_a = payload.name) != null ? _a : "",
|
|
605
|
+
toolId: payload.toolId,
|
|
606
|
+
input: payload.input,
|
|
607
|
+
content: (_b = payload.content) != null ? _b : payload.output,
|
|
608
|
+
phase: "output" in payload ? "result" : "call",
|
|
609
|
+
timestamp: Date.parse(message.createdAt) || Date.now()
|
|
610
|
+
});
|
|
611
|
+
}
|
|
598
612
|
return this._history;
|
|
599
613
|
}
|
|
600
614
|
close() {
|
|
@@ -824,6 +838,14 @@ function errMsg(err) {
|
|
|
824
838
|
if (err && typeof err === "object" && "message" in err) return String(err.message);
|
|
825
839
|
return String(err);
|
|
826
840
|
}
|
|
841
|
+
function parseObject(raw) {
|
|
842
|
+
try {
|
|
843
|
+
const parsed = JSON.parse(raw);
|
|
844
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
845
|
+
} catch (e) {
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
827
849
|
|
|
828
850
|
// src/agent-chat.ts
|
|
829
851
|
function getGatewayOrigin() {
|