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

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/README.md CHANGED
@@ -297,7 +297,7 @@ await existing.loadHistory({ limit: 50 });
297
297
  | `task` | `AgentChat \| null` | Metadados do chat |
298
298
  | `isNew` | `boolean` | Se foi aberto via `{ create: true }` |
299
299
  | `status` | `AgentTaskStatus` | `opening` · `idle` · `streaming` · `cancelled` · `error` · `closed` |
300
- | `history` | `AgentMessage[]` | Histórico carregado (`{ id, sender, type, content, createdAt }`) |
300
+ | `history` | `AgentTimelineItem[]` | Linha do tempo canônica — `{ id, kind: 'user' \| 'agent', text, at }` ou `{ id, kind: 'tool', tool: AgentToolEvent, at }` (tool já desempacotada, mesmo shape do evento do streaming) |
301
301
  | `content` | `string` | Conteúdo acumulado do turno atual |
302
302
  | `queue` | `QueuedItem[]` | Mensagens enfileiradas (enviadas enquanto streamava) |
303
303
 
@@ -306,7 +306,7 @@ await existing.loadHistory({ limit: 50 });
306
306
  - `send(prompt)` → `void` — dispara um turno (WS `message`). Se já está streamando, **enfileira** (FIFO, máx 10).
307
307
  - `cancel()` → `Promise<void>` — interrompe o turno atual (WS `interrupt`, safety net de 10s).
308
308
  - `respondApproval(approved)` → `void` — responde um pedido de aprovação do agente (WS `approval_response`).
309
- - `loadHistory({ limit? })` → `Promise<AgentMessage[]>` — histórico persistido via REST.
309
+ - `loadHistory({ limit? })` → `Promise<AgentTimelineItem[]>` — histórico persistido via REST, já no formato canônico da timeline (renderizou o streaming, renderizou o histórico).
310
310
  - `editQueueItem(id, text)` / `removeQueueItem(id)` / `clearQueue()` — manipulam a fila.
311
311
  - `on(event, handler)` → função de unsubscribe — assina eventos da session.
312
312
  - `close()` — encerra a session, fecha o WS e libera os listeners.
package/dist/index.d.mts CHANGED
@@ -211,20 +211,31 @@ interface AgentChat {
211
211
  createdAt: string;
212
212
  updatedAt: string;
213
213
  }
214
- /** Mensagem persistida (MessageResponse do copilot). */
214
+ /** Mensagem persistida (MessageResponse do copilot), como chega do BFF. */
215
215
  interface AgentMessage {
216
216
  id: string;
217
217
  sender: 'USER' | 'AGENT' | (string & {});
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;
227
221
  }
222
+ /**
223
+ * Item da linha do tempo do chat — o formato canônico, o MESMO que o streaming produz:
224
+ * um item de ferramenta carrega exatamente o payload do evento `tool`. O histórico sai
225
+ * da SDK já neste formato, então a UI desenha os dois com o mesmo código e não existe
226
+ * tradução para o app errar. Renderizou o streaming, renderizou o histórico.
227
+ */
228
+ type AgentTimelineItem = {
229
+ id: string;
230
+ kind: 'user' | 'agent';
231
+ text: string;
232
+ at: string;
233
+ } | {
234
+ id: string;
235
+ kind: 'tool';
236
+ tool: AgentToolEvent;
237
+ at: string;
238
+ };
228
239
  type ChatManageAction = 'list' | 'rename' | 'delete';
229
240
  interface ManageAgentChatListOptions {
230
241
  action: 'list';
@@ -351,7 +362,7 @@ interface AgentRawEvent {
351
362
  interface AgentTaskEventMap {
352
363
  statusChange: AgentStatusChangeEvent;
353
364
  historyLoaded: {
354
- history: AgentMessage[];
365
+ history: AgentTimelineItem[];
355
366
  };
356
367
  taskCreated: AgentTaskCreatedEvent;
357
368
  turnStart: Record<string, never>;
@@ -369,7 +380,7 @@ interface AgentTaskSession {
369
380
  readonly task: AgentChat | null;
370
381
  readonly isNew: boolean;
371
382
  readonly status: AgentTaskStatus;
372
- readonly history: AgentMessage[];
383
+ readonly history: AgentTimelineItem[];
373
384
  readonly content: string;
374
385
  readonly queue: QueuedItem[];
375
386
  /** Dispara um turno (fire-and-forget; resultado via eventos). Se streaming, enfileira. */
@@ -381,7 +392,7 @@ interface AgentTaskSession {
381
392
  /** Carrega o histórico persistido (REST GET messages). */
382
393
  loadHistory(options?: {
383
394
  limit?: number;
384
- }): Promise<AgentMessage[]>;
395
+ }): Promise<AgentTimelineItem[]>;
385
396
  editQueueItem(id: string, text: string): void;
386
397
  removeQueueItem(id: string): void;
387
398
  clearQueue(): void;
@@ -725,4 +736,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
725
736
  declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
726
737
  declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
727
738
 
728
- export { type AgentChat, type AgentCredentialStatus, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
739
+ export { type AgentChat, type AgentCredentialStatus, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
package/dist/index.d.ts CHANGED
@@ -211,20 +211,31 @@ interface AgentChat {
211
211
  createdAt: string;
212
212
  updatedAt: string;
213
213
  }
214
- /** Mensagem persistida (MessageResponse do copilot). */
214
+ /** Mensagem persistida (MessageResponse do copilot), como chega do BFF. */
215
215
  interface AgentMessage {
216
216
  id: string;
217
217
  sender: 'USER' | 'AGENT' | (string & {});
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;
227
221
  }
222
+ /**
223
+ * Item da linha do tempo do chat — o formato canônico, o MESMO que o streaming produz:
224
+ * um item de ferramenta carrega exatamente o payload do evento `tool`. O histórico sai
225
+ * da SDK já neste formato, então a UI desenha os dois com o mesmo código e não existe
226
+ * tradução para o app errar. Renderizou o streaming, renderizou o histórico.
227
+ */
228
+ type AgentTimelineItem = {
229
+ id: string;
230
+ kind: 'user' | 'agent';
231
+ text: string;
232
+ at: string;
233
+ } | {
234
+ id: string;
235
+ kind: 'tool';
236
+ tool: AgentToolEvent;
237
+ at: string;
238
+ };
228
239
  type ChatManageAction = 'list' | 'rename' | 'delete';
229
240
  interface ManageAgentChatListOptions {
230
241
  action: 'list';
@@ -351,7 +362,7 @@ interface AgentRawEvent {
351
362
  interface AgentTaskEventMap {
352
363
  statusChange: AgentStatusChangeEvent;
353
364
  historyLoaded: {
354
- history: AgentMessage[];
365
+ history: AgentTimelineItem[];
355
366
  };
356
367
  taskCreated: AgentTaskCreatedEvent;
357
368
  turnStart: Record<string, never>;
@@ -369,7 +380,7 @@ interface AgentTaskSession {
369
380
  readonly task: AgentChat | null;
370
381
  readonly isNew: boolean;
371
382
  readonly status: AgentTaskStatus;
372
- readonly history: AgentMessage[];
383
+ readonly history: AgentTimelineItem[];
373
384
  readonly content: string;
374
385
  readonly queue: QueuedItem[];
375
386
  /** Dispara um turno (fire-and-forget; resultado via eventos). Se streaming, enfileira. */
@@ -381,7 +392,7 @@ interface AgentTaskSession {
381
392
  /** Carrega o histórico persistido (REST GET messages). */
382
393
  loadHistory(options?: {
383
394
  limit?: number;
384
- }): Promise<AgentMessage[]>;
395
+ }): Promise<AgentTimelineItem[]>;
385
396
  editQueueItem(id: string, text: string): void;
386
397
  removeQueueItem(id: string): void;
387
398
  clearQueue(): void;
@@ -725,4 +736,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
725
736
  declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
726
737
  declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
727
738
 
728
- export { type AgentChat, type AgentCredentialStatus, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
739
+ export { type AgentChat, type AgentCredentialStatus, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
package/dist/index.js CHANGED
@@ -593,11 +593,8 @@ var AgentTaskSession = class {
593
593
  }
594
594
  async loadHistory(options) {
595
595
  if (!this._taskId) return [];
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
- });
596
+ const messages = await listChatMessages(this._taskId, this._projectId, { size: options == null ? void 0 : options.limit });
597
+ this._history = messages.map((message) => toTimelineItem(message));
601
598
  this._emit("historyLoaded", { history: this._history });
602
599
  return this._history;
603
600
  }
@@ -828,9 +825,18 @@ function errMsg(err) {
828
825
  if (err && typeof err === "object" && "message" in err) return String(err.message);
829
826
  return String(err);
830
827
  }
828
+ function toTimelineItem(message) {
829
+ const tool = message.type === "TOOL_USE" ? toToolEvent(message) : null;
830
+ if (tool) return { id: message.id, kind: "tool", tool, at: message.createdAt };
831
+ return {
832
+ id: message.id,
833
+ kind: message.sender === "USER" ? "user" : "agent",
834
+ text: message.content,
835
+ at: message.createdAt
836
+ };
837
+ }
831
838
  function toToolEvent(message) {
832
839
  var _a, _b;
833
- if (message.type !== "TOOL_USE") return null;
834
840
  let payload;
835
841
  try {
836
842
  payload = JSON.parse(message.content);