mitra-interactions-sdk 1.0.60-beta.34 → 1.0.60-beta.36
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 +3 -25
- package/dist/index.d.mts +20 -101
- package/dist/index.d.ts +20 -101
- package/dist/index.js +24 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -104
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -284,7 +284,9 @@ const existing = getAgentTaskMitra({ taskId: 'uuid-da-task' });
|
|
|
284
284
|
await existing.loadHistory({ limit: 50 });
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
-
`getAgentTaskMitra({ create: true, agentType?, name?, agentId?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
|
|
287
|
+
`getAgentTaskMitra({ create: true, agentType?, name?, agentId?, reasoningEffort?, autonomous?, transport? })` ou `getAgentTaskMitra({ taskId, transport? })`.
|
|
288
|
+
|
|
289
|
+
**Chat autônomo (`autonomous: true`)**: cria o chat **sem dono** (`user_id NULL` — a dona é o agente), pra Server Function/webhook/cron dirigir o agente. Exige `agentId` (fail-fast no client) e o agente precisa ter uma **connection anexada** como credencial; auth `AGENT_WRITE` (chave de SF ou token de app EDIT), senão 403. Depois de criado, dirigir/listar é igual ao chat normal (`getAgentTaskMitra({ taskId })`, `send`, `manageAgentChatMitra({ list, agentId })`). Sem o flag, comportamento de sempre (chat com dono = o caller). ⚠️ Depende do backend `impl-autonomous` — antes dele o servidor ignora o flag.
|
|
288
290
|
|
|
289
291
|
- `agentType` vem de `manageAgentCredentialMitra({ action: 'list_models' })` — ex.: `'ANTHROPIC_CLAUDE_OPUS'`, `'OPENAI_GPT5'`. Default: `'ANTHROPIC_CLAUDE_OPUS'`.
|
|
290
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`: 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`.
|
|
@@ -361,30 +363,6 @@ const { authUrl, state } = await manageAgentCredentialMitra({ action: 'auth', ta
|
|
|
361
363
|
const { connected, email } = await manageAgentCredentialMitra({ action: 'connect', target: 'anthropic', code, state });
|
|
362
364
|
```
|
|
363
365
|
|
|
364
|
-
### Connections do app — `manageAgentConnectionMitra`
|
|
365
|
-
|
|
366
|
-
Credencial de agente **compartilhada do app** (tenant+app) — espelho do management de credencial de user, apontando um `connectionId`. Pra sistemas montarem a tela de auth do agente. REST direto no copilot (`{origin}/copilot/api/v1/connections`).
|
|
367
|
-
|
|
368
|
-
Chamável com **token de user** (app-scoped, roles EDIT/OWNER/ADMIN) **ou** com **chave de SF** (`CONNECTION_READ`/`CONNECTION_WRITE`) — o caminho por chave é aditivo. A credencial nunca sai do servidor.
|
|
369
|
-
|
|
370
|
-
```typescript
|
|
371
|
-
import { manageAgentConnectionMitra } from 'mitra-interactions-sdk';
|
|
372
|
-
|
|
373
|
-
const { connections } = await manageAgentConnectionMitra({ action: 'list' });
|
|
374
|
-
const conn = await manageAgentConnectionMitra({ action: 'create', provider: 'anthropic', name: 'shared' });
|
|
375
|
-
|
|
376
|
-
// API key
|
|
377
|
-
await manageAgentConnectionMitra({ action: 'save', connectionId: conn.id, key: 'sk-...' });
|
|
378
|
-
|
|
379
|
-
// OAuth (anthropic)
|
|
380
|
-
const { authUrl, state } = await manageAgentConnectionMitra({ action: 'auth', connectionId: conn.id });
|
|
381
|
-
await manageAgentConnectionMitra({ action: 'connect', connectionId: conn.id, code, state });
|
|
382
|
-
|
|
383
|
-
// Device flow (openai)
|
|
384
|
-
const { deviceAuthId, userCode, verificationUri } = await manageAgentConnectionMitra({ action: 'device_auth', connectionId: conn.id });
|
|
385
|
-
await manageAgentConnectionMitra({ action: 'device_poll', connectionId: conn.id, deviceAuthId });
|
|
386
|
-
```
|
|
387
|
-
|
|
388
366
|
Device flow (só OpenAI) — mostre `userCode` + `verificationUri` e faça polling:
|
|
389
367
|
|
|
390
368
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -305,6 +305,16 @@ interface GetAgentTaskCreateOptions {
|
|
|
305
305
|
* único; na prática, sempre passe agentId.
|
|
306
306
|
*/
|
|
307
307
|
agentId?: string;
|
|
308
|
+
/**
|
|
309
|
+
* Cria o chat SEM dono (user_id NULL — a dona é o agente): a modalidade
|
|
310
|
+
* AUTÔNOMA, onde uma Server Function / webhook / cron dirige o agente.
|
|
311
|
+
* Exige `agentId` e o agente precisa ter uma connection anexada (credencial);
|
|
312
|
+
* auth AGENT_WRITE (chave de SF ou token de app EDIT), senão 403.
|
|
313
|
+
* Omitido = chat com dono (o caller), comportamento de sempre.
|
|
314
|
+
* ATENÇÃO: depende do backend impl-autonomous — antes dele o servidor
|
|
315
|
+
* ignora o flag e cria chat com dono normalmente.
|
|
316
|
+
*/
|
|
317
|
+
autonomous?: boolean;
|
|
308
318
|
/** Transporte do prompt (default 'ws'). */
|
|
309
319
|
transport?: AgentTaskTransport;
|
|
310
320
|
}
|
|
@@ -439,9 +449,15 @@ interface AgentModel {
|
|
|
439
449
|
provider: string;
|
|
440
450
|
agentType: AgentType;
|
|
441
451
|
/**
|
|
442
|
-
* Registro das intensidades de reasoning válidas pra este modelo
|
|
443
|
-
* harness — ex
|
|
444
|
-
*
|
|
452
|
+
* Registro das intensidades de reasoning válidas pra este modelo. Variam por
|
|
453
|
+
* harness — ex. (ilustrativo, sempre leia daqui): claude
|
|
454
|
+
* ['low','medium','high','xhigh','max']; codex
|
|
455
|
+
* ['none','minimal','low','medium','high','xhigh','max','ultra'].
|
|
456
|
+
* A UI monta o seletor a partir DAQUI; valor fora do registro é recusado
|
|
457
|
+
* pelo copilot (INVALID_REASONING_EFFORT).
|
|
458
|
+
* ATENÇÃO: a lista de models vem VAZIA enquanto nenhuma credencial/connection
|
|
459
|
+
* estiver conectada (o catálogo é escopado pelo que dá pra rodar) — o seletor
|
|
460
|
+
* só existe depois de conectar um provider e escolher um modelo.
|
|
445
461
|
*/
|
|
446
462
|
reasoningOptions?: string[];
|
|
447
463
|
}
|
|
@@ -504,43 +520,6 @@ type ManageAgentCredentialOptions = {
|
|
|
504
520
|
deviceAuthId: string;
|
|
505
521
|
projectId?: number | string;
|
|
506
522
|
};
|
|
507
|
-
/** Connection do app (shape do copilot; campos extras passam intactos). */
|
|
508
|
-
interface AgentConnection {
|
|
509
|
-
id: string;
|
|
510
|
-
provider?: string;
|
|
511
|
-
name?: string;
|
|
512
|
-
connected?: boolean;
|
|
513
|
-
[key: string]: unknown;
|
|
514
|
-
}
|
|
515
|
-
type ManageAgentConnectionOptions = {
|
|
516
|
-
action: 'list';
|
|
517
|
-
} | {
|
|
518
|
-
action: 'create';
|
|
519
|
-
provider: AgentProvider;
|
|
520
|
-
name?: string;
|
|
521
|
-
} | {
|
|
522
|
-
action: 'save';
|
|
523
|
-
connectionId: string;
|
|
524
|
-
key: string;
|
|
525
|
-
} | {
|
|
526
|
-
action: 'auth';
|
|
527
|
-
connectionId: string;
|
|
528
|
-
} | {
|
|
529
|
-
action: 'connect';
|
|
530
|
-
connectionId: string;
|
|
531
|
-
code: string;
|
|
532
|
-
state: string;
|
|
533
|
-
} | {
|
|
534
|
-
action: 'device_auth';
|
|
535
|
-
connectionId: string;
|
|
536
|
-
} | {
|
|
537
|
-
action: 'device_poll';
|
|
538
|
-
connectionId: string;
|
|
539
|
-
deviceAuthId: string;
|
|
540
|
-
};
|
|
541
|
-
interface ListAgentConnectionsResult {
|
|
542
|
-
connections: AgentConnection[];
|
|
543
|
-
}
|
|
544
523
|
|
|
545
524
|
/**
|
|
546
525
|
* Mitra Interactions SDK - Instance
|
|
@@ -746,66 +725,6 @@ declare function manageAgentCredentialMitra(options: {
|
|
|
746
725
|
projectId?: number | string;
|
|
747
726
|
}): Promise<ConnectAgentCredentialResult>;
|
|
748
727
|
|
|
749
|
-
/**
|
|
750
|
-
* Mitra Interactions SDK — Agent Connections
|
|
751
|
-
*
|
|
752
|
-
* Management de credencial de agente COMPARTILHADA (connection do app,
|
|
753
|
-
* tenant+app) — espelho do management de credencial de user
|
|
754
|
-
* (agent-credentials.ts), apontando um connectionId. Pra sistemas montarem
|
|
755
|
-
* a tela de auth do agente.
|
|
756
|
-
*
|
|
757
|
-
* REST direto no copilot ({origin}/copilot/api/v1/connections):
|
|
758
|
-
* - list → GET /connections
|
|
759
|
-
* - create → POST /connections
|
|
760
|
-
* - save → PUT /connections/{id}/api-key
|
|
761
|
-
* - auth → POST /connections/{id}/oauth/start
|
|
762
|
-
* - connect → POST /connections/{id}/oauth/exchange
|
|
763
|
-
* - device_auth → POST /connections/{id}/device-authorizations
|
|
764
|
-
* - device_poll → POST /connections/{id}/device-authorizations/{deviceAuthId}/poll
|
|
765
|
-
*
|
|
766
|
-
* Auth: Authorization Bearer com o token da config — funciona com token de
|
|
767
|
-
* user (app-scoped, roles EDIT/OWNER/ADMIN) E com chave de SF
|
|
768
|
-
* (CONNECTION_READ/WRITE). O caminho por chave é aditivo: nada aqui exige
|
|
769
|
-
* tipo específico de credencial — o servidor decide. Só sessão de CONSOLE
|
|
770
|
-
* (JWT token_use=session, sem app_id) é barrada no client, com causa clara.
|
|
771
|
-
*
|
|
772
|
-
* SEGURANÇA: a credencial nunca sai do servidor — as respostas trazem só
|
|
773
|
-
* status/metadados da connection.
|
|
774
|
-
*/
|
|
775
|
-
|
|
776
|
-
declare function manageAgentConnectionMitra(options: {
|
|
777
|
-
action: 'list';
|
|
778
|
-
}): Promise<ListAgentConnectionsResult>;
|
|
779
|
-
declare function manageAgentConnectionMitra(options: {
|
|
780
|
-
action: 'create';
|
|
781
|
-
provider: 'anthropic' | 'openai';
|
|
782
|
-
name?: string;
|
|
783
|
-
}): Promise<AgentConnection>;
|
|
784
|
-
declare function manageAgentConnectionMitra(options: {
|
|
785
|
-
action: 'save';
|
|
786
|
-
connectionId: string;
|
|
787
|
-
key: string;
|
|
788
|
-
}): Promise<void>;
|
|
789
|
-
declare function manageAgentConnectionMitra(options: {
|
|
790
|
-
action: 'auth';
|
|
791
|
-
connectionId: string;
|
|
792
|
-
}): Promise<AuthAgentCredentialResult>;
|
|
793
|
-
declare function manageAgentConnectionMitra(options: {
|
|
794
|
-
action: 'connect';
|
|
795
|
-
connectionId: string;
|
|
796
|
-
code: string;
|
|
797
|
-
state: string;
|
|
798
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
799
|
-
declare function manageAgentConnectionMitra(options: {
|
|
800
|
-
action: 'device_auth';
|
|
801
|
-
connectionId: string;
|
|
802
|
-
}): Promise<DeviceAuthAgentCredentialResult>;
|
|
803
|
-
declare function manageAgentConnectionMitra(options: {
|
|
804
|
-
action: 'device_poll';
|
|
805
|
-
connectionId: string;
|
|
806
|
-
deviceAuthId: string;
|
|
807
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
808
|
-
|
|
809
728
|
/**
|
|
810
729
|
* Mitra Interactions SDK - Services
|
|
811
730
|
*/
|
|
@@ -861,4 +780,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
861
780
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
862
781
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
863
782
|
|
|
864
|
-
export { type AgentChat, type
|
|
783
|
+
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
|
@@ -305,6 +305,16 @@ interface GetAgentTaskCreateOptions {
|
|
|
305
305
|
* único; na prática, sempre passe agentId.
|
|
306
306
|
*/
|
|
307
307
|
agentId?: string;
|
|
308
|
+
/**
|
|
309
|
+
* Cria o chat SEM dono (user_id NULL — a dona é o agente): a modalidade
|
|
310
|
+
* AUTÔNOMA, onde uma Server Function / webhook / cron dirige o agente.
|
|
311
|
+
* Exige `agentId` e o agente precisa ter uma connection anexada (credencial);
|
|
312
|
+
* auth AGENT_WRITE (chave de SF ou token de app EDIT), senão 403.
|
|
313
|
+
* Omitido = chat com dono (o caller), comportamento de sempre.
|
|
314
|
+
* ATENÇÃO: depende do backend impl-autonomous — antes dele o servidor
|
|
315
|
+
* ignora o flag e cria chat com dono normalmente.
|
|
316
|
+
*/
|
|
317
|
+
autonomous?: boolean;
|
|
308
318
|
/** Transporte do prompt (default 'ws'). */
|
|
309
319
|
transport?: AgentTaskTransport;
|
|
310
320
|
}
|
|
@@ -439,9 +449,15 @@ interface AgentModel {
|
|
|
439
449
|
provider: string;
|
|
440
450
|
agentType: AgentType;
|
|
441
451
|
/**
|
|
442
|
-
* Registro das intensidades de reasoning válidas pra este modelo
|
|
443
|
-
* harness — ex
|
|
444
|
-
*
|
|
452
|
+
* Registro das intensidades de reasoning válidas pra este modelo. Variam por
|
|
453
|
+
* harness — ex. (ilustrativo, sempre leia daqui): claude
|
|
454
|
+
* ['low','medium','high','xhigh','max']; codex
|
|
455
|
+
* ['none','minimal','low','medium','high','xhigh','max','ultra'].
|
|
456
|
+
* A UI monta o seletor a partir DAQUI; valor fora do registro é recusado
|
|
457
|
+
* pelo copilot (INVALID_REASONING_EFFORT).
|
|
458
|
+
* ATENÇÃO: a lista de models vem VAZIA enquanto nenhuma credencial/connection
|
|
459
|
+
* estiver conectada (o catálogo é escopado pelo que dá pra rodar) — o seletor
|
|
460
|
+
* só existe depois de conectar um provider e escolher um modelo.
|
|
445
461
|
*/
|
|
446
462
|
reasoningOptions?: string[];
|
|
447
463
|
}
|
|
@@ -504,43 +520,6 @@ type ManageAgentCredentialOptions = {
|
|
|
504
520
|
deviceAuthId: string;
|
|
505
521
|
projectId?: number | string;
|
|
506
522
|
};
|
|
507
|
-
/** Connection do app (shape do copilot; campos extras passam intactos). */
|
|
508
|
-
interface AgentConnection {
|
|
509
|
-
id: string;
|
|
510
|
-
provider?: string;
|
|
511
|
-
name?: string;
|
|
512
|
-
connected?: boolean;
|
|
513
|
-
[key: string]: unknown;
|
|
514
|
-
}
|
|
515
|
-
type ManageAgentConnectionOptions = {
|
|
516
|
-
action: 'list';
|
|
517
|
-
} | {
|
|
518
|
-
action: 'create';
|
|
519
|
-
provider: AgentProvider;
|
|
520
|
-
name?: string;
|
|
521
|
-
} | {
|
|
522
|
-
action: 'save';
|
|
523
|
-
connectionId: string;
|
|
524
|
-
key: string;
|
|
525
|
-
} | {
|
|
526
|
-
action: 'auth';
|
|
527
|
-
connectionId: string;
|
|
528
|
-
} | {
|
|
529
|
-
action: 'connect';
|
|
530
|
-
connectionId: string;
|
|
531
|
-
code: string;
|
|
532
|
-
state: string;
|
|
533
|
-
} | {
|
|
534
|
-
action: 'device_auth';
|
|
535
|
-
connectionId: string;
|
|
536
|
-
} | {
|
|
537
|
-
action: 'device_poll';
|
|
538
|
-
connectionId: string;
|
|
539
|
-
deviceAuthId: string;
|
|
540
|
-
};
|
|
541
|
-
interface ListAgentConnectionsResult {
|
|
542
|
-
connections: AgentConnection[];
|
|
543
|
-
}
|
|
544
523
|
|
|
545
524
|
/**
|
|
546
525
|
* Mitra Interactions SDK - Instance
|
|
@@ -746,66 +725,6 @@ declare function manageAgentCredentialMitra(options: {
|
|
|
746
725
|
projectId?: number | string;
|
|
747
726
|
}): Promise<ConnectAgentCredentialResult>;
|
|
748
727
|
|
|
749
|
-
/**
|
|
750
|
-
* Mitra Interactions SDK — Agent Connections
|
|
751
|
-
*
|
|
752
|
-
* Management de credencial de agente COMPARTILHADA (connection do app,
|
|
753
|
-
* tenant+app) — espelho do management de credencial de user
|
|
754
|
-
* (agent-credentials.ts), apontando um connectionId. Pra sistemas montarem
|
|
755
|
-
* a tela de auth do agente.
|
|
756
|
-
*
|
|
757
|
-
* REST direto no copilot ({origin}/copilot/api/v1/connections):
|
|
758
|
-
* - list → GET /connections
|
|
759
|
-
* - create → POST /connections
|
|
760
|
-
* - save → PUT /connections/{id}/api-key
|
|
761
|
-
* - auth → POST /connections/{id}/oauth/start
|
|
762
|
-
* - connect → POST /connections/{id}/oauth/exchange
|
|
763
|
-
* - device_auth → POST /connections/{id}/device-authorizations
|
|
764
|
-
* - device_poll → POST /connections/{id}/device-authorizations/{deviceAuthId}/poll
|
|
765
|
-
*
|
|
766
|
-
* Auth: Authorization Bearer com o token da config — funciona com token de
|
|
767
|
-
* user (app-scoped, roles EDIT/OWNER/ADMIN) E com chave de SF
|
|
768
|
-
* (CONNECTION_READ/WRITE). O caminho por chave é aditivo: nada aqui exige
|
|
769
|
-
* tipo específico de credencial — o servidor decide. Só sessão de CONSOLE
|
|
770
|
-
* (JWT token_use=session, sem app_id) é barrada no client, com causa clara.
|
|
771
|
-
*
|
|
772
|
-
* SEGURANÇA: a credencial nunca sai do servidor — as respostas trazem só
|
|
773
|
-
* status/metadados da connection.
|
|
774
|
-
*/
|
|
775
|
-
|
|
776
|
-
declare function manageAgentConnectionMitra(options: {
|
|
777
|
-
action: 'list';
|
|
778
|
-
}): Promise<ListAgentConnectionsResult>;
|
|
779
|
-
declare function manageAgentConnectionMitra(options: {
|
|
780
|
-
action: 'create';
|
|
781
|
-
provider: 'anthropic' | 'openai';
|
|
782
|
-
name?: string;
|
|
783
|
-
}): Promise<AgentConnection>;
|
|
784
|
-
declare function manageAgentConnectionMitra(options: {
|
|
785
|
-
action: 'save';
|
|
786
|
-
connectionId: string;
|
|
787
|
-
key: string;
|
|
788
|
-
}): Promise<void>;
|
|
789
|
-
declare function manageAgentConnectionMitra(options: {
|
|
790
|
-
action: 'auth';
|
|
791
|
-
connectionId: string;
|
|
792
|
-
}): Promise<AuthAgentCredentialResult>;
|
|
793
|
-
declare function manageAgentConnectionMitra(options: {
|
|
794
|
-
action: 'connect';
|
|
795
|
-
connectionId: string;
|
|
796
|
-
code: string;
|
|
797
|
-
state: string;
|
|
798
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
799
|
-
declare function manageAgentConnectionMitra(options: {
|
|
800
|
-
action: 'device_auth';
|
|
801
|
-
connectionId: string;
|
|
802
|
-
}): Promise<DeviceAuthAgentCredentialResult>;
|
|
803
|
-
declare function manageAgentConnectionMitra(options: {
|
|
804
|
-
action: 'device_poll';
|
|
805
|
-
connectionId: string;
|
|
806
|
-
deviceAuthId: string;
|
|
807
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
808
|
-
|
|
809
728
|
/**
|
|
810
729
|
* Mitra Interactions SDK - Services
|
|
811
730
|
*/
|
|
@@ -861,4 +780,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
861
780
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
862
781
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
863
782
|
|
|
864
|
-
export { type AgentChat, type
|
|
783
|
+
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
|
@@ -486,6 +486,7 @@ var AgentTaskSession = class {
|
|
|
486
486
|
this._initialName = init.name;
|
|
487
487
|
this._agentId = init.agentId;
|
|
488
488
|
this._reasoningEffort = init.reasoningEffort;
|
|
489
|
+
this._autonomous = init.autonomous;
|
|
489
490
|
this._status = "idle";
|
|
490
491
|
} else {
|
|
491
492
|
this._agentType = DEFAULT_AGENT_TYPE;
|
|
@@ -571,7 +572,8 @@ var AgentTaskSession = class {
|
|
|
571
572
|
projectId: this._projectId,
|
|
572
573
|
title: this._initialName,
|
|
573
574
|
agentType: this._agentType,
|
|
574
|
-
agentId: this._agentId
|
|
575
|
+
agentId: this._agentId,
|
|
576
|
+
autonomous: this._autonomous
|
|
575
577
|
});
|
|
576
578
|
this._task = toAgentChat(t);
|
|
577
579
|
this._taskId = this._task.id;
|
|
@@ -1045,7 +1047,10 @@ async function createChatTask(options) {
|
|
|
1045
1047
|
projectId: resolveProjectId(options.projectId),
|
|
1046
1048
|
...options.title ? { title: options.title } : {},
|
|
1047
1049
|
agentType: options.agentType,
|
|
1048
|
-
...options.agentId ? { agentId: options.agentId } : {}
|
|
1050
|
+
...options.agentId ? { agentId: options.agentId } : {},
|
|
1051
|
+
// Chat autônomo (sem dono; exige agentId + connection no agente).
|
|
1052
|
+
// Só entra no body quando informado — sem o flag, byte a byte como sempre.
|
|
1053
|
+
...options.autonomous ? { autonomous: true } : {}
|
|
1049
1054
|
});
|
|
1050
1055
|
return env.result;
|
|
1051
1056
|
}
|
|
@@ -1119,6 +1124,9 @@ function getAgentTaskMitra(options) {
|
|
|
1119
1124
|
});
|
|
1120
1125
|
}
|
|
1121
1126
|
if ("create" in options && options.create) {
|
|
1127
|
+
if (options.autonomous && !options.agentId) {
|
|
1128
|
+
throw new Error("getAgentTaskMitra: autonomous exige agentId \u2014 o chat aut\xF4nomo pertence ao agente (e o agente precisa ter uma connection anexada).");
|
|
1129
|
+
}
|
|
1122
1130
|
return new AgentTaskSession({
|
|
1123
1131
|
kind: "new",
|
|
1124
1132
|
projectId: options.projectId,
|
|
@@ -1126,7 +1134,8 @@ function getAgentTaskMitra(options) {
|
|
|
1126
1134
|
name: options.name,
|
|
1127
1135
|
agentId: options.agentId,
|
|
1128
1136
|
transport: options.transport,
|
|
1129
|
-
reasoningEffort: options.reasoningEffort
|
|
1137
|
+
reasoningEffort: options.reasoningEffort,
|
|
1138
|
+
autonomous: options.autonomous
|
|
1130
1139
|
});
|
|
1131
1140
|
}
|
|
1132
1141
|
throw new Error("getAgentTaskMitra: passe { create: true } ou { taskId }.");
|
|
@@ -1139,6 +1148,8 @@ function providerParam(target) {
|
|
|
1139
1148
|
async function manageAgentCredentialMitra(options) {
|
|
1140
1149
|
var _a, _b, _c;
|
|
1141
1150
|
const projectId = resolveProjectId(options.projectId);
|
|
1151
|
+
const connectionId = options.connectionId;
|
|
1152
|
+
const withConn = (body) => connectionId ? { ...body, connectionId } : body;
|
|
1142
1153
|
const target = options.target;
|
|
1143
1154
|
if ((options.action === "auth" || options.action === "connect") && target !== "anthropic") {
|
|
1144
1155
|
throw new Error(`manageAgentCredentialMitra(${options.action}): OAuth \xE9 exclusivo do provider 'anthropic'. Pra OpenAI use o device flow (device_auth/device_poll).`);
|
|
@@ -1157,11 +1168,11 @@ async function manageAgentCredentialMitra(options) {
|
|
|
1157
1168
|
}
|
|
1158
1169
|
case "save": {
|
|
1159
1170
|
if (!((_c = options.key) == null ? void 0 : _c.trim())) throw new Error("manageAgentCredentialMitra(save): key obrigat\xF3ria.");
|
|
1160
|
-
await http.post("/agentAiShortcut/saveCredential", {
|
|
1171
|
+
await http.post("/agentAiShortcut/saveCredential", withConn({
|
|
1161
1172
|
projectId,
|
|
1162
1173
|
provider: providerParam(options.target),
|
|
1163
1174
|
key: options.key
|
|
1164
|
-
});
|
|
1175
|
+
}));
|
|
1165
1176
|
return;
|
|
1166
1177
|
}
|
|
1167
1178
|
case "remove": {
|
|
@@ -1172,40 +1183,40 @@ async function manageAgentCredentialMitra(options) {
|
|
|
1172
1183
|
return;
|
|
1173
1184
|
}
|
|
1174
1185
|
case "auth": {
|
|
1175
|
-
const env = await http.post("/agentAiShortcut/oauthStart", {
|
|
1186
|
+
const env = await http.post("/agentAiShortcut/oauthStart", withConn({
|
|
1176
1187
|
projectId,
|
|
1177
1188
|
provider: providerParam(options.target)
|
|
1178
|
-
});
|
|
1189
|
+
}));
|
|
1179
1190
|
return env.result;
|
|
1180
1191
|
}
|
|
1181
1192
|
case "connect": {
|
|
1182
1193
|
if (!options.code || !options.state) {
|
|
1183
1194
|
throw new Error("manageAgentCredentialMitra(connect): code e state obrigat\xF3rios.");
|
|
1184
1195
|
}
|
|
1185
|
-
const env = await http.post("/agentAiShortcut/oauthExchange", {
|
|
1196
|
+
const env = await http.post("/agentAiShortcut/oauthExchange", withConn({
|
|
1186
1197
|
projectId,
|
|
1187
1198
|
provider: providerParam(options.target),
|
|
1188
1199
|
code: options.code,
|
|
1189
1200
|
state: options.state
|
|
1190
|
-
});
|
|
1201
|
+
}));
|
|
1191
1202
|
return env.result;
|
|
1192
1203
|
}
|
|
1193
1204
|
case "device_auth": {
|
|
1194
|
-
const env = await http.post("/agentAiShortcut/deviceStart", {
|
|
1205
|
+
const env = await http.post("/agentAiShortcut/deviceStart", withConn({
|
|
1195
1206
|
projectId,
|
|
1196
1207
|
provider: providerParam(options.target)
|
|
1197
|
-
});
|
|
1208
|
+
}));
|
|
1198
1209
|
return env.result;
|
|
1199
1210
|
}
|
|
1200
1211
|
case "device_poll": {
|
|
1201
1212
|
if (!options.deviceAuthId) {
|
|
1202
1213
|
throw new Error("manageAgentCredentialMitra(device_poll): deviceAuthId obrigat\xF3rio.");
|
|
1203
1214
|
}
|
|
1204
|
-
const env = await http.post("/agentAiShortcut/devicePoll", {
|
|
1215
|
+
const env = await http.post("/agentAiShortcut/devicePoll", withConn({
|
|
1205
1216
|
projectId,
|
|
1206
1217
|
provider: providerParam(options.target),
|
|
1207
1218
|
deviceAuthId: options.deviceAuthId
|
|
1208
|
-
});
|
|
1219
|
+
}));
|
|
1209
1220
|
return env.result;
|
|
1210
1221
|
}
|
|
1211
1222
|
default:
|
|
@@ -1593,96 +1604,6 @@ function resolveProjectId(projectId) {
|
|
|
1593
1604
|
throw new Error("projectId \xE9 obrigat\xF3rio. Passe nas options ou configure via configureSdkMitra({ projectId }).");
|
|
1594
1605
|
}
|
|
1595
1606
|
|
|
1596
|
-
// src/agent-connections.ts
|
|
1597
|
-
function getConnectionsBase() {
|
|
1598
|
-
const config = getConfig();
|
|
1599
|
-
if (!config.baseURL) {
|
|
1600
|
-
throw new Error("Agent Connections: baseURL n\xE3o configurada. Configure via configureSdkMitra({ baseURL }).");
|
|
1601
|
-
}
|
|
1602
|
-
const token = config.token;
|
|
1603
|
-
if (token) {
|
|
1604
|
-
const payload = decodeJwtPayload(token);
|
|
1605
|
-
if (payload && payload.token_use === "session" && !payload.app_id) {
|
|
1606
|
-
throw new Error("Agent Connections: o token configurado \xE9 uma sess\xE3o do console \u2014 use token de app (loginMitra) ou chave de SF.");
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
return `${new URL(config.baseURL).origin}/copilot/api/v1/connections`;
|
|
1610
|
-
}
|
|
1611
|
-
async function connectionsFetch(method, path, body) {
|
|
1612
|
-
var _a, _b, _c;
|
|
1613
|
-
if (isTokenExpiring()) await tryRefreshToken();
|
|
1614
|
-
const config = getConfig();
|
|
1615
|
-
if (!config.token) {
|
|
1616
|
-
throw new Error("Agent Connections: token n\xE3o configurado. Fa\xE7a login ou configure a chave de SF em configureSdkMitra({ token }).");
|
|
1617
|
-
}
|
|
1618
|
-
const doFetch = async () => fetch(`${getConnectionsBase()}${path}`, {
|
|
1619
|
-
method,
|
|
1620
|
-
headers: {
|
|
1621
|
-
"Content-Type": "application/json",
|
|
1622
|
-
"Authorization": `Bearer ${stripBearer(getConfig().token)}`
|
|
1623
|
-
},
|
|
1624
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
1625
|
-
});
|
|
1626
|
-
let response = await doFetch();
|
|
1627
|
-
if (response.status === 401 && await tryRefreshToken()) {
|
|
1628
|
-
response = await doFetch();
|
|
1629
|
-
}
|
|
1630
|
-
const text = await response.text();
|
|
1631
|
-
const { data, isJson } = parseBody(text);
|
|
1632
|
-
if (!response.ok) {
|
|
1633
|
-
const fallback = !isJson && text ? `HTTP ${response.status} \u2014 ${text}` : `HTTP ${response.status}`;
|
|
1634
|
-
const msg = isJson && ((data == null ? void 0 : data.message) || ((_a = data == null ? void 0 : data.error) == null ? void 0 : _a.message) || (data == null ? void 0 : data.error)) || fallback;
|
|
1635
|
-
throw { message: typeof msg === "string" ? msg : fallback, status: response.status, code: (_c = data == null ? void 0 : data.code) != null ? _c : (_b = data == null ? void 0 : data.error) == null ? void 0 : _b.code, details: data };
|
|
1636
|
-
}
|
|
1637
|
-
return data;
|
|
1638
|
-
}
|
|
1639
|
-
async function manageAgentConnectionMitra(options) {
|
|
1640
|
-
var _a;
|
|
1641
|
-
switch (options.action) {
|
|
1642
|
-
case "list": {
|
|
1643
|
-
const connections = await connectionsFetch("GET", "");
|
|
1644
|
-
return { connections: connections != null ? connections : [] };
|
|
1645
|
-
}
|
|
1646
|
-
case "create": {
|
|
1647
|
-
return connectionsFetch("POST", "", {
|
|
1648
|
-
provider: String(options.provider).toUpperCase(),
|
|
1649
|
-
...options.name ? { name: options.name } : {}
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
case "save": {
|
|
1653
|
-
if (!((_a = options.key) == null ? void 0 : _a.trim())) throw new Error("manageAgentConnectionMitra(save): key obrigat\xF3ria.");
|
|
1654
|
-
await connectionsFetch("PUT", `/${encodeURIComponent(options.connectionId)}/api-key`, { apiKey: options.key });
|
|
1655
|
-
return;
|
|
1656
|
-
}
|
|
1657
|
-
case "auth": {
|
|
1658
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/oauth/start`);
|
|
1659
|
-
}
|
|
1660
|
-
case "connect": {
|
|
1661
|
-
if (!options.code || !options.state) {
|
|
1662
|
-
throw new Error("manageAgentConnectionMitra(connect): code e state obrigat\xF3rios.");
|
|
1663
|
-
}
|
|
1664
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/oauth/exchange`, {
|
|
1665
|
-
code: options.code,
|
|
1666
|
-
state: options.state
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
case "device_auth": {
|
|
1670
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/device-authorizations`);
|
|
1671
|
-
}
|
|
1672
|
-
case "device_poll": {
|
|
1673
|
-
if (!options.deviceAuthId) {
|
|
1674
|
-
throw new Error("manageAgentConnectionMitra(device_poll): deviceAuthId obrigat\xF3rio.");
|
|
1675
|
-
}
|
|
1676
|
-
return connectionsFetch(
|
|
1677
|
-
"POST",
|
|
1678
|
-
`/${encodeURIComponent(options.connectionId)}/device-authorizations/${encodeURIComponent(options.deviceAuthId)}/poll`
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1681
|
-
default:
|
|
1682
|
-
throw new Error(`manageAgentConnectionMitra: action inv\xE1lida (${options.action}).`);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
1607
|
// src/services.ts
|
|
1687
1608
|
async function executeServerFunctionMitra(options) {
|
|
1688
1609
|
const body = {
|
|
@@ -1836,7 +1757,6 @@ exports.loginMitra = loginMitra;
|
|
|
1836
1757
|
exports.loginWithGoogleMitra = loginWithGoogleMitra;
|
|
1837
1758
|
exports.loginWithMicrosoftMitra = loginWithMicrosoftMitra;
|
|
1838
1759
|
exports.manageAgentChatMitra = manageAgentChatMitra;
|
|
1839
|
-
exports.manageAgentConnectionMitra = manageAgentConnectionMitra;
|
|
1840
1760
|
exports.manageAgentCredentialMitra = manageAgentCredentialMitra;
|
|
1841
1761
|
exports.patchRecordMitra = patchRecordMitra;
|
|
1842
1762
|
exports.refreshTokenSilently = refreshTokenSilently;
|