mitra-interactions-sdk 1.0.60-beta.30 → 1.0.60-beta.31

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.d.mts CHANGED
@@ -218,6 +218,12 @@ interface AgentMessage {
218
218
  type: string;
219
219
  content: string;
220
220
  createdAt: string;
221
+ /**
222
+ * Presente só em mensagens TOOL_USE: o payload do `content` já desempacotado,
223
+ * no MESMO formato do evento `tool` do streaming — histórico e stream ficam
224
+ * iguais pra quem desenha a UI (card ao vivo e pós-F5 idênticos).
225
+ */
226
+ tool?: AgentToolEvent;
221
227
  }
222
228
  type ChatManageAction = 'list' | 'rename' | 'delete';
223
229
  interface ManageAgentChatListOptions {
package/dist/index.d.ts CHANGED
@@ -218,6 +218,12 @@ interface AgentMessage {
218
218
  type: string;
219
219
  content: string;
220
220
  createdAt: string;
221
+ /**
222
+ * Presente só em mensagens TOOL_USE: o payload do `content` já desempacotado,
223
+ * no MESMO formato do evento `tool` do streaming — histórico e stream ficam
224
+ * iguais pra quem desenha a UI (card ao vivo e pós-F5 idênticos).
225
+ */
226
+ tool?: AgentToolEvent;
221
227
  }
222
228
  type ChatManageAction = 'list' | 'rename' | 'delete';
223
229
  interface ManageAgentChatListOptions {
package/dist/index.js CHANGED
@@ -592,23 +592,13 @@ var AgentTaskSession = class {
592
592
  ws.send(JSON.stringify({ type: "approval_response", approved }));
593
593
  }
594
594
  async loadHistory(options) {
595
- var _a, _b;
596
595
  if (!this._taskId) return [];
597
- this._history = await listChatMessages(this._taskId, this._projectId, { size: options == null ? void 0 : options.limit });
596
+ const history = await listChatMessages(this._taskId, this._projectId, { size: options == null ? void 0 : options.limit });
597
+ this._history = history.map((message) => {
598
+ const tool = toToolEvent(message);
599
+ return tool ? { ...message, tool } : message;
600
+ });
598
601
  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
- }
612
602
  return this._history;
613
603
  }
614
604
  close() {
@@ -838,13 +828,24 @@ function errMsg(err) {
838
828
  if (err && typeof err === "object" && "message" in err) return String(err.message);
839
829
  return String(err);
840
830
  }
841
- function parseObject(raw) {
831
+ function toToolEvent(message) {
832
+ var _a, _b;
833
+ if (message.type !== "TOOL_USE") return null;
834
+ let payload;
842
835
  try {
843
- const parsed = JSON.parse(raw);
844
- return parsed && typeof parsed === "object" ? parsed : null;
836
+ payload = JSON.parse(message.content);
837
+ if (!payload || typeof payload !== "object") return null;
845
838
  } catch (e) {
846
839
  return null;
847
840
  }
841
+ return {
842
+ tool: (_a = payload.name) != null ? _a : "",
843
+ toolId: payload.toolId,
844
+ input: payload.input,
845
+ content: (_b = payload.content) != null ? _b : payload.output,
846
+ phase: "output" in payload ? "result" : "call",
847
+ timestamp: Date.parse(message.createdAt) || Date.now()
848
+ };
848
849
  }
849
850
 
850
851
  // src/agent-chat.ts