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

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
@@ -286,7 +286,7 @@ await existing.loadHistory({ limit: 50 });
286
286
 
287
287
  `getAgentTaskMitra({ create: true, agentType?, name?, agentId?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
288
288
 
289
- - `agentType` vem de `manageAgentCredentialMitra({ action: 'list_models' })` — ex.: `'ANTHROPIC_CLAUDE_OPUS'`, `'OPENAI_GPT5'`, `'GOOGLE_GEMINI_PRO'`. Default: `'ANTHROPIC_CLAUDE_OPUS'`.
289
+ - `agentType` vem de `manageAgentCredentialMitra({ action: 'list_models' })` — ex.: `'ANTHROPIC_CLAUDE_OPUS'`, `'OPENAI_GPT5'`. Default: `'ANTHROPIC_CLAUDE_OPUS'`.
290
290
  - **`agentId`**: id de um agente business (CRUD via `mitra-sdk`: `listAgentsMitra` e família). A sessão sobe com o system prompt do agente e um token escopado — as tools enxergam só as Server Functions dele. **Sem `agentId`: sessão business sem agente** — sem system prompt e sem acesso às Server Functions (as tools recusam); não há adoção automática de agente único. Na prática, sempre passe `agentId`.
291
291
 
292
292
  #### Propriedades (somente leitura)
@@ -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.
@@ -329,7 +329,7 @@ session.send('Analise estas vendas e gere um resumo');
329
329
 
330
330
  ### Credenciais do agente — `manageAgentCredentialMitra`
331
331
 
332
- Função única, toda HTTP **via BFF** (`/agentAiShortcut/listProviders`, `saveCredential`, `oauthStart`...). Providers: `'anthropic'`, `'openai'`, `'google'`. API key via `save`/`remove`; OAuth via `auth`/`connect`; device flow via `device_auth`/`device_poll`.
332
+ Função única, toda HTTP **via BFF** (`/agentAiShortcut/listProviders`, `saveCredential`, `oauthStart`...). Providers: `'anthropic'` e `'openai'`. API key via `save`/`remove` (ambos); **OAuth (`auth`/`connect`) é exclusivo do anthropic; device flow (`device_auth`/`device_poll`) é exclusivo do openai** — fluxo trocado falha rápido com erro claro.
333
333
 
334
334
  **`projectId` é obrigatório** em todas as actions (opcional na chamada se já veio do `configureSdkMitra`) — é ele que define de qual app é a credencial; o BFF resolve `projectId → appId` e cunha o token de app.
335
335
 
@@ -351,7 +351,7 @@ await manageAgentCredentialMitra({ action: 'save', target: 'openai', key: 'sk-..
351
351
  await manageAgentCredentialMitra({ action: 'remove', target: 'anthropic' });
352
352
  ```
353
353
 
354
- OAuth (ex.: Anthropic) — `auth` devolve o que mostrar, `connect` finaliza:
354
+ OAuth (só Anthropic) — `auth` devolve o que mostrar, `connect` finaliza:
355
355
 
356
356
  ```typescript
357
357
  const { authUrl, state } = await manageAgentCredentialMitra({ action: 'auth', target: 'anthropic' });
@@ -359,7 +359,7 @@ const { authUrl, state } = await manageAgentCredentialMitra({ action: 'auth', ta
359
359
  const { connected, email } = await manageAgentCredentialMitra({ action: 'connect', target: 'anthropic', code, state });
360
360
  ```
361
361
 
362
- Device flow (ex.: OpenAI) — mostre `userCode` + `verificationUri` e faça polling:
362
+ Device flow (só OpenAI) — mostre `userCode` + `verificationUri` e faça polling:
363
363
 
364
364
  ```typescript
365
365
  const { deviceAuthId, userCode, verificationUri, intervalSeconds } =
package/dist/index.d.mts CHANGED
@@ -197,9 +197,9 @@ interface StopServerFunctionExecutionResponse {
197
197
  }
198
198
  /**
199
199
  * Tipo/modelo do agente (enum do copilot — vem de list_models).
200
- * Ex.: 'ANTHROPIC_CLAUDE_OPUS', 'OPENAI_GPT5', 'GOOGLE_GEMINI_PRO'.
200
+ * Ex.: 'ANTHROPIC_CLAUDE_OPUS', 'OPENAI_GPT5'.
201
201
  */
202
- type AgentType = 'ANTHROPIC_CLAUDE_OPUS' | 'OPENAI_GPT5' | 'GOOGLE_GEMINI_PRO' | (string & {});
202
+ type AgentType = 'ANTHROPIC_CLAUDE_OPUS' | 'OPENAI_GPT5' | (string & {});
203
203
  /** Task/chat do copilot (TaskResponse). `name` espelha o `title` do backend. */
204
204
  interface AgentChat {
205
205
  id: string;
@@ -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;
@@ -389,7 +400,7 @@ interface AgentTaskSession {
389
400
  close(): void;
390
401
  }
391
402
  /** Providers do copilot. */
392
- type AgentProvider = 'anthropic' | 'openai' | 'google';
403
+ type AgentProvider = 'anthropic' | 'openai';
393
404
  type CredentialAction = 'list_providers' | 'list_models' | 'save' | 'remove' | 'auth' | 'connect' | 'device_auth' | 'device_poll';
394
405
  /** GET /credentials — status por provider. */
395
406
  interface AgentCredentialStatus {
@@ -447,21 +458,21 @@ type ManageAgentCredentialOptions = {
447
458
  projectId?: number | string;
448
459
  } | {
449
460
  action: 'auth';
450
- target: AgentProvider;
461
+ target: 'anthropic';
451
462
  projectId?: number | string;
452
463
  } | {
453
464
  action: 'connect';
454
- target: AgentProvider;
465
+ target: 'anthropic';
455
466
  code: string;
456
467
  state: string;
457
468
  projectId?: number | string;
458
469
  } | {
459
470
  action: 'device_auth';
460
- target: AgentProvider;
471
+ target: 'openai';
461
472
  projectId?: number | string;
462
473
  } | {
463
474
  action: 'device_poll';
464
- target: AgentProvider;
475
+ target: 'openai';
465
476
  deviceAuthId: string;
466
477
  projectId?: number | string;
467
478
  };
@@ -648,24 +659,24 @@ declare function manageAgentCredentialMitra(options: {
648
659
  }): Promise<void>;
649
660
  declare function manageAgentCredentialMitra(options: {
650
661
  action: 'auth';
651
- target: AgentProvider;
662
+ target: 'anthropic';
652
663
  projectId?: number | string;
653
664
  }): Promise<AuthAgentCredentialResult>;
654
665
  declare function manageAgentCredentialMitra(options: {
655
666
  action: 'connect';
656
- target: AgentProvider;
667
+ target: 'anthropic';
657
668
  code: string;
658
669
  state: string;
659
670
  projectId?: number | string;
660
671
  }): Promise<ConnectAgentCredentialResult>;
661
672
  declare function manageAgentCredentialMitra(options: {
662
673
  action: 'device_auth';
663
- target: AgentProvider;
674
+ target: 'openai';
664
675
  projectId?: number | string;
665
676
  }): Promise<DeviceAuthAgentCredentialResult>;
666
677
  declare function manageAgentCredentialMitra(options: {
667
678
  action: 'device_poll';
668
- target: AgentProvider;
679
+ target: 'openai';
669
680
  deviceAuthId: string;
670
681
  projectId?: number | string;
671
682
  }): Promise<ConnectAgentCredentialResult>;
@@ -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
@@ -197,9 +197,9 @@ interface StopServerFunctionExecutionResponse {
197
197
  }
198
198
  /**
199
199
  * Tipo/modelo do agente (enum do copilot — vem de list_models).
200
- * Ex.: 'ANTHROPIC_CLAUDE_OPUS', 'OPENAI_GPT5', 'GOOGLE_GEMINI_PRO'.
200
+ * Ex.: 'ANTHROPIC_CLAUDE_OPUS', 'OPENAI_GPT5'.
201
201
  */
202
- type AgentType = 'ANTHROPIC_CLAUDE_OPUS' | 'OPENAI_GPT5' | 'GOOGLE_GEMINI_PRO' | (string & {});
202
+ type AgentType = 'ANTHROPIC_CLAUDE_OPUS' | 'OPENAI_GPT5' | (string & {});
203
203
  /** Task/chat do copilot (TaskResponse). `name` espelha o `title` do backend. */
204
204
  interface AgentChat {
205
205
  id: string;
@@ -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;
@@ -389,7 +400,7 @@ interface AgentTaskSession {
389
400
  close(): void;
390
401
  }
391
402
  /** Providers do copilot. */
392
- type AgentProvider = 'anthropic' | 'openai' | 'google';
403
+ type AgentProvider = 'anthropic' | 'openai';
393
404
  type CredentialAction = 'list_providers' | 'list_models' | 'save' | 'remove' | 'auth' | 'connect' | 'device_auth' | 'device_poll';
394
405
  /** GET /credentials — status por provider. */
395
406
  interface AgentCredentialStatus {
@@ -447,21 +458,21 @@ type ManageAgentCredentialOptions = {
447
458
  projectId?: number | string;
448
459
  } | {
449
460
  action: 'auth';
450
- target: AgentProvider;
461
+ target: 'anthropic';
451
462
  projectId?: number | string;
452
463
  } | {
453
464
  action: 'connect';
454
- target: AgentProvider;
465
+ target: 'anthropic';
455
466
  code: string;
456
467
  state: string;
457
468
  projectId?: number | string;
458
469
  } | {
459
470
  action: 'device_auth';
460
- target: AgentProvider;
471
+ target: 'openai';
461
472
  projectId?: number | string;
462
473
  } | {
463
474
  action: 'device_poll';
464
- target: AgentProvider;
475
+ target: 'openai';
465
476
  deviceAuthId: string;
466
477
  projectId?: number | string;
467
478
  };
@@ -648,24 +659,24 @@ declare function manageAgentCredentialMitra(options: {
648
659
  }): Promise<void>;
649
660
  declare function manageAgentCredentialMitra(options: {
650
661
  action: 'auth';
651
- target: AgentProvider;
662
+ target: 'anthropic';
652
663
  projectId?: number | string;
653
664
  }): Promise<AuthAgentCredentialResult>;
654
665
  declare function manageAgentCredentialMitra(options: {
655
666
  action: 'connect';
656
- target: AgentProvider;
667
+ target: 'anthropic';
657
668
  code: string;
658
669
  state: string;
659
670
  projectId?: number | string;
660
671
  }): Promise<ConnectAgentCredentialResult>;
661
672
  declare function manageAgentCredentialMitra(options: {
662
673
  action: 'device_auth';
663
- target: AgentProvider;
674
+ target: 'openai';
664
675
  projectId?: number | string;
665
676
  }): Promise<DeviceAuthAgentCredentialResult>;
666
677
  declare function manageAgentCredentialMitra(options: {
667
678
  action: 'device_poll';
668
- target: AgentProvider;
679
+ target: 'openai';
669
680
  deviceAuthId: string;
670
681
  projectId?: number | string;
671
682
  }): Promise<ConnectAgentCredentialResult>;
@@ -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);
@@ -977,6 +983,13 @@ function providerParam(target) {
977
983
  async function manageAgentCredentialMitra(options) {
978
984
  var _a, _b, _c;
979
985
  const projectId = resolveProjectId(options.projectId);
986
+ const target = options.target;
987
+ if ((options.action === "auth" || options.action === "connect") && target !== "anthropic") {
988
+ throw new Error(`manageAgentCredentialMitra(${options.action}): OAuth \xE9 exclusivo do provider 'anthropic'. Pra OpenAI use o device flow (device_auth/device_poll).`);
989
+ }
990
+ if ((options.action === "device_auth" || options.action === "device_poll") && target !== "openai") {
991
+ throw new Error(`manageAgentCredentialMitra(${options.action}): device flow \xE9 exclusivo do provider 'openai'. Pra Anthropic use OAuth (auth/connect).`);
992
+ }
980
993
  switch (options.action) {
981
994
  case "list_providers": {
982
995
  const env = await http.get("/agentAiShortcut/listProviders", { projectId });