mitra-interactions-sdk 1.0.60-beta.22 → 1.0.60-beta.24
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 +137 -4
- package/dist/index.d.mts +334 -1
- package/dist/index.d.ts +334 -1
- package/dist/index.js +553 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +551 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -244,6 +244,130 @@ const result2 = await listRecordsMitra({
|
|
|
244
244
|
});
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
+
## Agent Chat (copilot)
|
|
248
|
+
|
|
249
|
+
Chat com o agente de IA embarcado. **REST-first**: chats, histórico, credenciais e modelos são HTTP no gateway `{origin}/copilot/api/v1` (mesmo domínio da `baseURL`, `Authorization: Bearer`). **Só o prompt é streaming** — um WebSocket por task em `wss://{origin}/copilot/ws/tasks/{taskId}?token=JWT`, aberto pela SDK quando a conversa começa.
|
|
250
|
+
|
|
251
|
+
Precisa de `token` e `baseURL` configurados (o login já deixa pronto). O transporte do prompt aceita `transport: 'ws' | 'http'` — `'ws'` é o default; `'http'` é reservado pra ambientes serverless e hoje lança erro claro (o backend ainda não expõe prompt por HTTP).
|
|
252
|
+
|
|
253
|
+
### Gerenciar os chats — `manageAgentChatMitra`
|
|
254
|
+
|
|
255
|
+
Tudo HTTP: listar (com filtros), renomear e deletar (= arquivar).
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import { manageAgentChatMitra } from 'mitra-interactions-sdk';
|
|
259
|
+
|
|
260
|
+
const chats = await manageAgentChatMitra({ action: 'list' }); // AgentChat[]
|
|
261
|
+
const doAgente = await manageAgentChatMitra({ action: 'list', agentId: 'uuid-do-agente' }); // só os chats de um agente business
|
|
262
|
+
const busca = await manageAgentChatMitra({ action: 'list', search: 'vendas', page: 0, size: 20 });
|
|
263
|
+
const renamed = await manageAgentChatMitra({ action: 'rename', taskId, name: 'Novo nome' });
|
|
264
|
+
const deleted = await manageAgentChatMitra({ action: 'delete', taskId }); // arquiva (some da lista default)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
- `action: 'list'` → `AgentChat[]` — `{ id, name, agentType, agentId, archived, createdAt, updatedAt }`. Filtros: `agentId?`, `archived?`, `search?`, `page?`, `size?`.
|
|
268
|
+
- `action: 'rename'` → `{ taskId, name }` (PATCH `/tasks/{id}`)
|
|
269
|
+
- `action: 'delete'` → `{ taskId, deleted }` (PATCH `/tasks/{id}/archive` — o histórico não é destruído)
|
|
270
|
+
|
|
271
|
+
### Abrir uma session — `getAgentTaskMitra`
|
|
272
|
+
|
|
273
|
+
Retorna uma `AgentTaskSession` que encapsula o ciclo de vida do chat. A task é criada via REST (`POST /tasks`) no primeiro `send()`; o WS da task conecta em seguida. Abrir a mesma `taskId` duas vezes devolve a **mesma** instância (cache).
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { getAgentTaskMitra } from 'mitra-interactions-sdk';
|
|
277
|
+
|
|
278
|
+
// Chat novo — taskId é preenchido no primeiro send() (evento taskCreated)
|
|
279
|
+
const session = getAgentTaskMitra({ create: true, agentType: 'ANTHROPIC_CLAUDE_OPUS', name: 'Meu chat' });
|
|
280
|
+
|
|
281
|
+
// Chat com um agente business (system prompt + SFs do agente; token escopado)
|
|
282
|
+
const sales = getAgentTaskMitra({ create: true, agentId: 'uuid-do-agente' });
|
|
283
|
+
|
|
284
|
+
// Chat existente
|
|
285
|
+
const existing = getAgentTaskMitra({ taskId: 'uuid-da-task' });
|
|
286
|
+
await existing.loadHistory({ limit: 50 });
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
`getAgentTaskMitra({ create: true, agentType?, name?, agentId?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
|
|
290
|
+
|
|
291
|
+
- `agentType` vem de `manageAgentCredentialMitra({ action: 'list_models' })` — ex.: `'ANTHROPIC_CLAUDE_OPUS'`, `'OPENAI_GPT5'`, `'GOOGLE_GEMINI_PRO'`. Default: `'ANTHROPIC_CLAUDE_OPUS'`.
|
|
292
|
+
- **`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`, é o chat de desenvolvimento.
|
|
293
|
+
|
|
294
|
+
#### Propriedades (somente leitura)
|
|
295
|
+
|
|
296
|
+
| Propriedade | Tipo | Descrição |
|
|
297
|
+
|-------------|------|-----------|
|
|
298
|
+
| `taskId` | `string \| null` | `null` até o primeiro `send()` num chat novo |
|
|
299
|
+
| `task` | `AgentChat \| null` | Metadados do chat |
|
|
300
|
+
| `isNew` | `boolean` | Se foi aberto via `{ create: true }` |
|
|
301
|
+
| `status` | `AgentTaskStatus` | `opening` · `idle` · `streaming` · `cancelled` · `error` · `closed` |
|
|
302
|
+
| `history` | `AgentMessage[]` | Histórico carregado (`{ id, sender, type, content, createdAt }`) |
|
|
303
|
+
| `content` | `string` | Conteúdo acumulado do turno atual |
|
|
304
|
+
| `queue` | `QueuedItem[]` | Mensagens enfileiradas (enviadas enquanto streamava) |
|
|
305
|
+
|
|
306
|
+
#### Métodos
|
|
307
|
+
|
|
308
|
+
- `send(prompt)` → `void` — dispara um turno (WS `message`). Se já está streamando, **enfileira** (FIFO, máx 10).
|
|
309
|
+
- `cancel()` → `Promise<void>` — interrompe o turno atual (WS `interrupt`, safety net de 10s).
|
|
310
|
+
- `respondApproval(approved)` → `void` — responde um pedido de aprovação do agente (WS `approval_response`).
|
|
311
|
+
- `loadHistory({ limit? })` → `Promise<AgentMessage[]>` — histórico persistido via REST.
|
|
312
|
+
- `editQueueItem(id, text)` / `removeQueueItem(id)` / `clearQueue()` — manipulam a fila.
|
|
313
|
+
- `on(event, handler)` → função de unsubscribe — assina eventos da session.
|
|
314
|
+
- `close()` — encerra a session, fecha o WS e libera os listeners.
|
|
315
|
+
|
|
316
|
+
#### Eventos (`session.on`)
|
|
317
|
+
|
|
318
|
+
`statusChange` · `historyLoaded` · `taskCreated` · `turnStart` · `delta` (`{ delta, kind: 'text' | 'thinking' }`) · `tool` (`{ tool, toolId?, input?, content?, phase: 'call' | 'result' }`) · `turnEnd` (`{ content }`) · `cancelled` · `queueChange` · `error` (`{ code?, error }`) · `raw` (eventos não mapeados do stream, ex.: `workspace`).
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const session = getAgentTaskMitra({ create: true });
|
|
322
|
+
|
|
323
|
+
session.on('delta', ({ delta, kind }) => { if (kind === 'text') process.stdout.write(delta); });
|
|
324
|
+
session.on('tool', ({ tool, phase }) => console.log('🔧', phase, tool));
|
|
325
|
+
session.on('turnEnd', ({ content }) => console.log('\n✓ fim do turno'));
|
|
326
|
+
session.on('taskCreated', ({ task }) => console.log('chat criado:', task.id));
|
|
327
|
+
session.on('error', ({ error }) => console.error(error));
|
|
328
|
+
|
|
329
|
+
session.send('Analise estas vendas e gere um resumo');
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Credenciais do agente — `manageAgentCredentialMitra`
|
|
333
|
+
|
|
334
|
+
Função única, toda HTTP. Providers: `'anthropic'`, `'openai'`, `'google'`. API key via `save`/`remove`; OAuth via `auth`/`connect`; device flow via `device_auth`/`device_poll`.
|
|
335
|
+
|
|
336
|
+
> 🔒 Tokens/keys nunca voltam crus — o backend devolve só status, e-mail da conta e a key mascarada.
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { manageAgentCredentialMitra } from 'mitra-interactions-sdk';
|
|
340
|
+
|
|
341
|
+
// Status por provider (pra montar a UI de conexão)
|
|
342
|
+
const { providers } = await manageAgentCredentialMitra({ action: 'list_providers' });
|
|
343
|
+
// AgentCredentialStatus[]: { provider, connected, credentialType, accountEmail, maskedApiKey }
|
|
344
|
+
|
|
345
|
+
// Modelos selecionáveis → use o agentType em getAgentTaskMitra
|
|
346
|
+
const { models } = await manageAgentCredentialMitra({ action: 'list_models' });
|
|
347
|
+
// AgentModel[]: { model, name, provider, agentType }
|
|
348
|
+
|
|
349
|
+
// API key
|
|
350
|
+
await manageAgentCredentialMitra({ action: 'save', target: 'openai', key: 'sk-...' });
|
|
351
|
+
await manageAgentCredentialMitra({ action: 'remove', target: 'anthropic' });
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
OAuth (ex.: Anthropic) — `auth` devolve o que mostrar, `connect` finaliza:
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
const { authUrl, state } = await manageAgentCredentialMitra({ action: 'auth', target: 'anthropic' });
|
|
358
|
+
// app abre authUrl; usuário autoriza e copia o código
|
|
359
|
+
const { connected, email } = await manageAgentCredentialMitra({ action: 'connect', target: 'anthropic', code, state });
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Device flow (ex.: OpenAI) — mostre `userCode` + `verificationUri` e faça polling:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
const { deviceAuthId, userCode, verificationUri, intervalSeconds } =
|
|
366
|
+
await manageAgentCredentialMitra({ action: 'device_auth', target: 'openai' });
|
|
367
|
+
// app mostra: "abra {verificationUri} e digite {userCode}"; depois, a cada intervalSeconds:
|
|
368
|
+
const { connected } = await manageAgentCredentialMitra({ action: 'device_poll', target: 'openai', deviceAuthId });
|
|
369
|
+
```
|
|
370
|
+
|
|
247
371
|
## Tipos TypeScript
|
|
248
372
|
|
|
249
373
|
Todos os tipos estão incluídos:
|
|
@@ -254,9 +378,6 @@ import type {
|
|
|
254
378
|
// Login
|
|
255
379
|
LoginOptions,
|
|
256
380
|
LoginResponse,
|
|
257
|
-
// Email Auth
|
|
258
|
-
EmailSignupOptions,
|
|
259
|
-
EmailLoginOptions,
|
|
260
381
|
// Options
|
|
261
382
|
ExecuteServerFunctionOptions,
|
|
262
383
|
ExecuteServerFunctionAsyncOptions,
|
|
@@ -272,7 +393,19 @@ import type {
|
|
|
272
393
|
ExecuteServerFunctionResponse,
|
|
273
394
|
ExecuteServerFunctionAsyncResponse,
|
|
274
395
|
StopServerFunctionExecutionResponse,
|
|
275
|
-
ListRecordsResponse
|
|
396
|
+
ListRecordsResponse,
|
|
397
|
+
// Agent Chat
|
|
398
|
+
AgentChat,
|
|
399
|
+
AgentMessage,
|
|
400
|
+
AgentTaskSession,
|
|
401
|
+
AgentTaskStatus,
|
|
402
|
+
SendOptions,
|
|
403
|
+
ManageAgentChatOptions,
|
|
404
|
+
GetAgentTaskOptions,
|
|
405
|
+
// Agent Credentials
|
|
406
|
+
ManageAgentCredentialOptions,
|
|
407
|
+
ListAgentModelsResult,
|
|
408
|
+
ListAgentProvidersResult
|
|
276
409
|
} from 'mitra-interactions-sdk';
|
|
277
410
|
```
|
|
278
411
|
|
package/dist/index.d.mts
CHANGED
|
@@ -195,6 +195,246 @@ interface StopServerFunctionExecutionResponse {
|
|
|
195
195
|
executionStatus: string;
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Tipo/modelo do agente (enum do copilot — vem de list_models).
|
|
200
|
+
* Ex.: 'ANTHROPIC_CLAUDE_OPUS', 'OPENAI_GPT5', 'GOOGLE_GEMINI_PRO'.
|
|
201
|
+
*/
|
|
202
|
+
type AgentType = 'ANTHROPIC_CLAUDE_OPUS' | 'OPENAI_GPT5' | 'GOOGLE_GEMINI_PRO' | (string & {});
|
|
203
|
+
/** Task/chat do copilot (TaskResponse). `name` espelha o `title` do backend. */
|
|
204
|
+
interface AgentChat {
|
|
205
|
+
id: string;
|
|
206
|
+
name: string | null;
|
|
207
|
+
agentType: AgentType;
|
|
208
|
+
/** Agente business dono do chat (null = chat de desenvolvimento). */
|
|
209
|
+
agentId: string | null;
|
|
210
|
+
archived: boolean;
|
|
211
|
+
createdAt: string;
|
|
212
|
+
updatedAt: string;
|
|
213
|
+
}
|
|
214
|
+
/** Mensagem persistida (MessageResponse do copilot). */
|
|
215
|
+
interface AgentMessage {
|
|
216
|
+
id: string;
|
|
217
|
+
sender: 'USER' | 'AGENT' | (string & {});
|
|
218
|
+
type: string;
|
|
219
|
+
content: string;
|
|
220
|
+
createdAt: string;
|
|
221
|
+
}
|
|
222
|
+
type ChatManageAction = 'list' | 'rename' | 'delete';
|
|
223
|
+
interface ManageAgentChatListOptions {
|
|
224
|
+
action: 'list';
|
|
225
|
+
/** Filtra os chats de um agente business específico. Omitido = todos os chats. */
|
|
226
|
+
agentId?: string;
|
|
227
|
+
/** Inclui só arquivados (true) ou só ativos (false, default). */
|
|
228
|
+
archived?: boolean;
|
|
229
|
+
/** Busca por título. */
|
|
230
|
+
search?: string;
|
|
231
|
+
/** Página (0-based, default 0). */
|
|
232
|
+
page?: number;
|
|
233
|
+
/** Tamanho da página (default 20). */
|
|
234
|
+
size?: number;
|
|
235
|
+
}
|
|
236
|
+
interface ManageAgentChatRenameOptions {
|
|
237
|
+
action: 'rename';
|
|
238
|
+
taskId: string;
|
|
239
|
+
name: string;
|
|
240
|
+
}
|
|
241
|
+
interface ManageAgentChatDeleteOptions {
|
|
242
|
+
action: 'delete';
|
|
243
|
+
taskId: string;
|
|
244
|
+
}
|
|
245
|
+
type ManageAgentChatOptions = ManageAgentChatListOptions | ManageAgentChatRenameOptions | ManageAgentChatDeleteOptions;
|
|
246
|
+
interface RenameAgentChatResult {
|
|
247
|
+
taskId: string;
|
|
248
|
+
name: string;
|
|
249
|
+
}
|
|
250
|
+
/** delete = archive no backend (PATCH /tasks/{id}/archive). O chat some da lista default. */
|
|
251
|
+
interface DeleteAgentChatResult {
|
|
252
|
+
taskId: string;
|
|
253
|
+
deleted: boolean;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Transporte do prompt. 'ws' (default) = streaming via WebSocket.
|
|
257
|
+
* 'http' = reservado pra ambientes serverless — o backend ainda não expõe
|
|
258
|
+
* o prompt por HTTP; hoje lança erro claro.
|
|
259
|
+
*/
|
|
260
|
+
type AgentTaskTransport = 'ws' | 'http';
|
|
261
|
+
interface GetAgentTaskCreateOptions {
|
|
262
|
+
/** Cria chat novo. A task é criada via REST no primeiro send(). */
|
|
263
|
+
create: true;
|
|
264
|
+
/** Tipo/modelo do agente (de list_models). Default: 'ANTHROPIC_CLAUDE_OPUS'. */
|
|
265
|
+
agentType?: AgentType;
|
|
266
|
+
/** Nome/título do chat. */
|
|
267
|
+
name?: string;
|
|
268
|
+
/**
|
|
269
|
+
* ID de um agente business (CRUD via mitra-sdk: listAgentsMitra e família).
|
|
270
|
+
* Com agentId, a sessão sobe com o system prompt do agente e um token escopado —
|
|
271
|
+
* as tools enxergam só as Server Functions daquele agente. Sem agentId, é o
|
|
272
|
+
* chat de desenvolvimento de sempre.
|
|
273
|
+
*/
|
|
274
|
+
agentId?: string;
|
|
275
|
+
/** Transporte do prompt (default 'ws'). */
|
|
276
|
+
transport?: AgentTaskTransport;
|
|
277
|
+
}
|
|
278
|
+
interface GetAgentTaskOpenOptions {
|
|
279
|
+
/** Abre chat existente. */
|
|
280
|
+
taskId: string;
|
|
281
|
+
/** Transporte do prompt (default 'ws'). */
|
|
282
|
+
transport?: AgentTaskTransport;
|
|
283
|
+
}
|
|
284
|
+
type GetAgentTaskOptions = GetAgentTaskCreateOptions | GetAgentTaskOpenOptions;
|
|
285
|
+
type AgentTaskStatus = 'opening' | 'idle' | 'streaming' | 'cancelled' | 'error' | 'closed';
|
|
286
|
+
interface QueuedItem {
|
|
287
|
+
id: string;
|
|
288
|
+
text: string;
|
|
289
|
+
seq: number;
|
|
290
|
+
createdAt: number;
|
|
291
|
+
status: 'pending' | 'sending';
|
|
292
|
+
}
|
|
293
|
+
interface SendOptions {
|
|
294
|
+
/** Reservado (o modelo/agentType é fixado na criação da task). */
|
|
295
|
+
_reserved?: never;
|
|
296
|
+
}
|
|
297
|
+
interface AgentDeltaEvent {
|
|
298
|
+
delta: string;
|
|
299
|
+
kind: 'text' | 'thinking';
|
|
300
|
+
}
|
|
301
|
+
interface AgentToolEvent {
|
|
302
|
+
/** Nome da tool (toolCall/toolResult). */
|
|
303
|
+
tool: string;
|
|
304
|
+
toolId?: string;
|
|
305
|
+
input?: unknown;
|
|
306
|
+
/** Presente no toolResult. */
|
|
307
|
+
content?: unknown;
|
|
308
|
+
phase: 'call' | 'result';
|
|
309
|
+
timestamp: number;
|
|
310
|
+
}
|
|
311
|
+
interface AgentTurnEndEvent {
|
|
312
|
+
content: string;
|
|
313
|
+
}
|
|
314
|
+
interface AgentTaskCreatedEvent {
|
|
315
|
+
task: AgentChat;
|
|
316
|
+
}
|
|
317
|
+
interface AgentErrorEvent {
|
|
318
|
+
code?: string;
|
|
319
|
+
error: string;
|
|
320
|
+
}
|
|
321
|
+
interface AgentQueueChangeEvent {
|
|
322
|
+
queue: QueuedItem[];
|
|
323
|
+
}
|
|
324
|
+
interface AgentStatusChangeEvent {
|
|
325
|
+
status: AgentTaskStatus;
|
|
326
|
+
}
|
|
327
|
+
/** Evento cru do WS que a SDK não mapeia (ex.: workspace, approvalRequest). */
|
|
328
|
+
interface AgentRawEvent {
|
|
329
|
+
type: string;
|
|
330
|
+
payload: unknown;
|
|
331
|
+
timestamp: number;
|
|
332
|
+
}
|
|
333
|
+
interface AgentTaskEventMap {
|
|
334
|
+
statusChange: AgentStatusChangeEvent;
|
|
335
|
+
historyLoaded: {
|
|
336
|
+
history: AgentMessage[];
|
|
337
|
+
};
|
|
338
|
+
taskCreated: AgentTaskCreatedEvent;
|
|
339
|
+
turnStart: Record<string, never>;
|
|
340
|
+
delta: AgentDeltaEvent;
|
|
341
|
+
tool: AgentToolEvent;
|
|
342
|
+
turnEnd: AgentTurnEndEvent;
|
|
343
|
+
cancelled: Record<string, never>;
|
|
344
|
+
queueChange: AgentQueueChangeEvent;
|
|
345
|
+
error: AgentErrorEvent;
|
|
346
|
+
raw: AgentRawEvent;
|
|
347
|
+
}
|
|
348
|
+
type AgentTaskEventName = keyof AgentTaskEventMap;
|
|
349
|
+
interface AgentTaskSession {
|
|
350
|
+
readonly taskId: string | null;
|
|
351
|
+
readonly task: AgentChat | null;
|
|
352
|
+
readonly isNew: boolean;
|
|
353
|
+
readonly status: AgentTaskStatus;
|
|
354
|
+
readonly history: AgentMessage[];
|
|
355
|
+
readonly content: string;
|
|
356
|
+
readonly queue: QueuedItem[];
|
|
357
|
+
/** Dispara um turno (fire-and-forget; resultado via eventos). Se streaming, enfileira. */
|
|
358
|
+
send(prompt: string, options?: SendOptions): void;
|
|
359
|
+
/** Interrompe o turno atual (WS interrupt). */
|
|
360
|
+
cancel(): Promise<void>;
|
|
361
|
+
/** Responde um pedido de aprovação do agente (evento raw approvalRequest). */
|
|
362
|
+
respondApproval(approved: boolean): void;
|
|
363
|
+
/** Carrega o histórico persistido (REST GET messages). */
|
|
364
|
+
loadHistory(options?: {
|
|
365
|
+
limit?: number;
|
|
366
|
+
}): Promise<AgentMessage[]>;
|
|
367
|
+
editQueueItem(id: string, text: string): void;
|
|
368
|
+
removeQueueItem(id: string): void;
|
|
369
|
+
clearQueue(): void;
|
|
370
|
+
on<E extends AgentTaskEventName>(event: E, handler: (payload: AgentTaskEventMap[E]) => void): () => void;
|
|
371
|
+
close(): void;
|
|
372
|
+
}
|
|
373
|
+
/** Providers do copilot. */
|
|
374
|
+
type AgentProvider = 'anthropic' | 'openai' | 'google';
|
|
375
|
+
type CredentialAction = 'list_providers' | 'list_models' | 'save' | 'remove' | 'auth' | 'connect' | 'device_auth' | 'device_poll';
|
|
376
|
+
/** GET /credentials — status por provider. */
|
|
377
|
+
interface AgentCredentialStatus {
|
|
378
|
+
provider: string;
|
|
379
|
+
connected: boolean;
|
|
380
|
+
credentialType: string | null;
|
|
381
|
+
accountEmail: string | null;
|
|
382
|
+
maskedApiKey: string | null;
|
|
383
|
+
}
|
|
384
|
+
/** GET /models — modelo selecionável (o value usável é `agentType`). */
|
|
385
|
+
interface AgentModel {
|
|
386
|
+
model: string;
|
|
387
|
+
name: string;
|
|
388
|
+
provider: string;
|
|
389
|
+
agentType: AgentType;
|
|
390
|
+
}
|
|
391
|
+
interface ListAgentProvidersResult {
|
|
392
|
+
providers: AgentCredentialStatus[];
|
|
393
|
+
}
|
|
394
|
+
interface ListAgentModelsResult {
|
|
395
|
+
models: AgentModel[];
|
|
396
|
+
}
|
|
397
|
+
interface AuthAgentCredentialResult {
|
|
398
|
+
authUrl: string;
|
|
399
|
+
state: string;
|
|
400
|
+
}
|
|
401
|
+
interface ConnectAgentCredentialResult {
|
|
402
|
+
connected: boolean;
|
|
403
|
+
email: string | null;
|
|
404
|
+
}
|
|
405
|
+
interface DeviceAuthAgentCredentialResult {
|
|
406
|
+
deviceAuthId: string;
|
|
407
|
+
userCode: string;
|
|
408
|
+
verificationUri: string;
|
|
409
|
+
intervalSeconds: number;
|
|
410
|
+
}
|
|
411
|
+
type ManageAgentCredentialOptions = {
|
|
412
|
+
action: 'list_providers';
|
|
413
|
+
} | {
|
|
414
|
+
action: 'list_models';
|
|
415
|
+
} | {
|
|
416
|
+
action: 'save';
|
|
417
|
+
target: AgentProvider;
|
|
418
|
+
key: string;
|
|
419
|
+
} | {
|
|
420
|
+
action: 'remove';
|
|
421
|
+
target: AgentProvider;
|
|
422
|
+
} | {
|
|
423
|
+
action: 'auth';
|
|
424
|
+
target: AgentProvider;
|
|
425
|
+
} | {
|
|
426
|
+
action: 'connect';
|
|
427
|
+
target: AgentProvider;
|
|
428
|
+
code: string;
|
|
429
|
+
state: string;
|
|
430
|
+
} | {
|
|
431
|
+
action: 'device_auth';
|
|
432
|
+
target: AgentProvider;
|
|
433
|
+
} | {
|
|
434
|
+
action: 'device_poll';
|
|
435
|
+
target: AgentProvider;
|
|
436
|
+
deviceAuthId: string;
|
|
437
|
+
};
|
|
198
438
|
|
|
199
439
|
/**
|
|
200
440
|
* Mitra Interactions SDK - Instance
|
|
@@ -219,6 +459,9 @@ interface MitraInstance {
|
|
|
219
459
|
patchRecord(options: PatchRecordOptions): Promise<Record<string, any>>;
|
|
220
460
|
deleteRecord(options: DeleteRecordOptions): Promise<void>;
|
|
221
461
|
createRecordsBatch(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
462
|
+
getAgentTask(options: GetAgentTaskOptions): AgentTaskSession;
|
|
463
|
+
manageAgentChat(options: ManageAgentChatOptions): Promise<unknown>;
|
|
464
|
+
manageAgentCredential(options: ManageAgentCredentialOptions): Promise<unknown>;
|
|
222
465
|
}
|
|
223
466
|
declare function createMitraInstance(initialConfig: Partial<MitraConfig>): MitraInstance;
|
|
224
467
|
|
|
@@ -282,6 +525,96 @@ declare function exchangeSsoCodeMitra(options: {
|
|
|
282
525
|
state: string;
|
|
283
526
|
}): Promise<LoginResponse>;
|
|
284
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Mitra Interactions SDK — Agent Chat (copilot novo mundo)
|
|
530
|
+
*
|
|
531
|
+
* REST-first: chats (tasks), histórico, credenciais e modelos são HTTP no
|
|
532
|
+
* gateway `{origin}/copilot/api/v1`. SÓ o prompt é streaming — WebSocket por
|
|
533
|
+
* task em `{origin}/copilot/ws/tasks/{taskId}?token=JWT`.
|
|
534
|
+
*
|
|
535
|
+
* API pública:
|
|
536
|
+
* - manageAgentChatMitra({ action: 'list' | 'rename' | 'delete', ... })
|
|
537
|
+
* - getAgentTaskMitra({ create | taskId, ... })
|
|
538
|
+
*/
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Gerencia a coleção de chats do usuário — tudo HTTP:
|
|
542
|
+
* - list → GET /copilot/api/v1/tasks (filtros: agentId, archived, search, page, size)
|
|
543
|
+
* - rename → PATCH /copilot/api/v1/tasks/{id}
|
|
544
|
+
* - delete → PATCH /copilot/api/v1/tasks/{id}/archive (arquiva; some da lista default)
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* const chats = await manageAgentChatMitra({ action: 'list' });
|
|
548
|
+
* const doAgente = await manageAgentChatMitra({ action: 'list', agentId: 'uuid' });
|
|
549
|
+
* await manageAgentChatMitra({ action: 'rename', taskId, name: 'Novo nome' });
|
|
550
|
+
* await manageAgentChatMitra({ action: 'delete', taskId });
|
|
551
|
+
*/
|
|
552
|
+
declare function manageAgentChatMitra(options: ManageAgentChatListOptions): Promise<AgentChat[]>;
|
|
553
|
+
declare function manageAgentChatMitra(options: ManageAgentChatRenameOptions): Promise<RenameAgentChatResult>;
|
|
554
|
+
declare function manageAgentChatMitra(options: ManageAgentChatDeleteOptions): Promise<DeleteAgentChatResult>;
|
|
555
|
+
/**
|
|
556
|
+
* Abre um handle de chat (session). Use:
|
|
557
|
+
* - `{ create: true }` para iniciar um chat novo (a task é criada via REST no 1º send)
|
|
558
|
+
* - `{ taskId: 'X' }` para abrir um chat existente
|
|
559
|
+
*
|
|
560
|
+
* A session expõe histórico, streaming, fila, cancel e eventos. Se a
|
|
561
|
+
* mesma taskId for aberta duas vezes, retorna a MESMA instância (cache).
|
|
562
|
+
*/
|
|
563
|
+
declare function getAgentTaskMitra(options: GetAgentTaskOptions): AgentTaskSession;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Mitra Interactions SDK — Agent Credentials (copilot novo mundo)
|
|
567
|
+
*
|
|
568
|
+
* Função ÚNICA `manageAgentCredentialMitra`, toda HTTP no gateway
|
|
569
|
+
* `{origin}/copilot/api/v1`:
|
|
570
|
+
* - list_providers → GET /credentials
|
|
571
|
+
* - list_models → GET /models
|
|
572
|
+
* - save → PUT /credentials/{provider}/api-key
|
|
573
|
+
* - remove → DELETE /credentials/{provider}
|
|
574
|
+
* - auth → POST /oauth/start (OAuth: { authUrl, state })
|
|
575
|
+
* - connect → POST /oauth/exchange (OAuth: { code, state })
|
|
576
|
+
* - device_auth → POST /credentials/{provider}/device-authorizations
|
|
577
|
+
* - device_poll → POST /credentials/{provider}/device-authorizations/{id}/poll
|
|
578
|
+
*
|
|
579
|
+
* SEGURANÇA: tokens/keys nunca voltam crus — o backend devolve só status,
|
|
580
|
+
* e-mail da conta e a key mascarada.
|
|
581
|
+
*/
|
|
582
|
+
|
|
583
|
+
declare function manageAgentCredentialMitra(options: {
|
|
584
|
+
action: 'list_providers';
|
|
585
|
+
}): Promise<ListAgentProvidersResult>;
|
|
586
|
+
declare function manageAgentCredentialMitra(options: {
|
|
587
|
+
action: 'list_models';
|
|
588
|
+
}): Promise<ListAgentModelsResult>;
|
|
589
|
+
declare function manageAgentCredentialMitra(options: {
|
|
590
|
+
action: 'save';
|
|
591
|
+
target: AgentProvider;
|
|
592
|
+
key: string;
|
|
593
|
+
}): Promise<void>;
|
|
594
|
+
declare function manageAgentCredentialMitra(options: {
|
|
595
|
+
action: 'remove';
|
|
596
|
+
target: AgentProvider;
|
|
597
|
+
}): Promise<void>;
|
|
598
|
+
declare function manageAgentCredentialMitra(options: {
|
|
599
|
+
action: 'auth';
|
|
600
|
+
target: AgentProvider;
|
|
601
|
+
}): Promise<AuthAgentCredentialResult>;
|
|
602
|
+
declare function manageAgentCredentialMitra(options: {
|
|
603
|
+
action: 'connect';
|
|
604
|
+
target: AgentProvider;
|
|
605
|
+
code: string;
|
|
606
|
+
state: string;
|
|
607
|
+
}): Promise<ConnectAgentCredentialResult>;
|
|
608
|
+
declare function manageAgentCredentialMitra(options: {
|
|
609
|
+
action: 'device_auth';
|
|
610
|
+
target: AgentProvider;
|
|
611
|
+
}): Promise<DeviceAuthAgentCredentialResult>;
|
|
612
|
+
declare function manageAgentCredentialMitra(options: {
|
|
613
|
+
action: 'device_poll';
|
|
614
|
+
target: AgentProvider;
|
|
615
|
+
deviceAuthId: string;
|
|
616
|
+
}): Promise<ConnectAgentCredentialResult>;
|
|
617
|
+
|
|
285
618
|
/**
|
|
286
619
|
* Mitra Interactions SDK - Services
|
|
287
620
|
*/
|
|
@@ -337,4 +670,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
337
670
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
338
671
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
339
672
|
|
|
340
|
-
export { type CallIntegrationOptions, type CallIntegrationResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type DeleteRecordOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type IntegrationResponse, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type MitraConfig, type MitraInstance, type PatchRecordOptions, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, callIntegrationMitra, configureSdkMitra, createMitraInstance, createRecordMitra, createRecordsBatchMitra, deleteRecordMitra, exchangeSsoCodeMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getConfig, getPublicServerFunctionExecutionMitra, getRecordMitra, listIntegrationsMitra, listRecordsMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, patchRecordMitra, refreshTokenSilently, resolveProjectId, stopServerFunctionExecutionMitra, updateRecordMitra };
|
|
673
|
+
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 };
|