mitra-interactions-sdk 1.0.60-beta.35 → 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 +0 -24
- package/dist/index.d.mts +10 -101
- package/dist/index.d.ts +10 -101
- package/dist/index.js +12 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -363,30 +363,6 @@ const { authUrl, state } = await manageAgentCredentialMitra({ action: 'auth', ta
|
|
|
363
363
|
const { connected, email } = await manageAgentCredentialMitra({ action: 'connect', target: 'anthropic', code, state });
|
|
364
364
|
```
|
|
365
365
|
|
|
366
|
-
### Connections do app — `manageAgentConnectionMitra`
|
|
367
|
-
|
|
368
|
-
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`).
|
|
369
|
-
|
|
370
|
-
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.
|
|
371
|
-
|
|
372
|
-
```typescript
|
|
373
|
-
import { manageAgentConnectionMitra } from 'mitra-interactions-sdk';
|
|
374
|
-
|
|
375
|
-
const { connections } = await manageAgentConnectionMitra({ action: 'list' });
|
|
376
|
-
const conn = await manageAgentConnectionMitra({ action: 'create', provider: 'anthropic', name: 'shared' });
|
|
377
|
-
|
|
378
|
-
// API key
|
|
379
|
-
await manageAgentConnectionMitra({ action: 'save', connectionId: conn.id, key: 'sk-...' });
|
|
380
|
-
|
|
381
|
-
// OAuth (anthropic)
|
|
382
|
-
const { authUrl, state } = await manageAgentConnectionMitra({ action: 'auth', connectionId: conn.id });
|
|
383
|
-
await manageAgentConnectionMitra({ action: 'connect', connectionId: conn.id, code, state });
|
|
384
|
-
|
|
385
|
-
// Device flow (openai)
|
|
386
|
-
const { deviceAuthId, userCode, verificationUri } = await manageAgentConnectionMitra({ action: 'device_auth', connectionId: conn.id });
|
|
387
|
-
await manageAgentConnectionMitra({ action: 'device_poll', connectionId: conn.id, deviceAuthId });
|
|
388
|
-
```
|
|
389
|
-
|
|
390
366
|
Device flow (só OpenAI) — mostre `userCode` + `verificationUri` e faça polling:
|
|
391
367
|
|
|
392
368
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -449,9 +449,15 @@ interface AgentModel {
|
|
|
449
449
|
provider: string;
|
|
450
450
|
agentType: AgentType;
|
|
451
451
|
/**
|
|
452
|
-
* Registro das intensidades de reasoning válidas pra este modelo
|
|
453
|
-
* harness — ex
|
|
454
|
-
*
|
|
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.
|
|
455
461
|
*/
|
|
456
462
|
reasoningOptions?: string[];
|
|
457
463
|
}
|
|
@@ -514,43 +520,6 @@ type ManageAgentCredentialOptions = {
|
|
|
514
520
|
deviceAuthId: string;
|
|
515
521
|
projectId?: number | string;
|
|
516
522
|
};
|
|
517
|
-
/** Connection do app (shape do copilot; campos extras passam intactos). */
|
|
518
|
-
interface AgentConnection {
|
|
519
|
-
id: string;
|
|
520
|
-
provider?: string;
|
|
521
|
-
name?: string;
|
|
522
|
-
connected?: boolean;
|
|
523
|
-
[key: string]: unknown;
|
|
524
|
-
}
|
|
525
|
-
type ManageAgentConnectionOptions = {
|
|
526
|
-
action: 'list';
|
|
527
|
-
} | {
|
|
528
|
-
action: 'create';
|
|
529
|
-
provider: AgentProvider;
|
|
530
|
-
name?: string;
|
|
531
|
-
} | {
|
|
532
|
-
action: 'save';
|
|
533
|
-
connectionId: string;
|
|
534
|
-
key: string;
|
|
535
|
-
} | {
|
|
536
|
-
action: 'auth';
|
|
537
|
-
connectionId: string;
|
|
538
|
-
} | {
|
|
539
|
-
action: 'connect';
|
|
540
|
-
connectionId: string;
|
|
541
|
-
code: string;
|
|
542
|
-
state: string;
|
|
543
|
-
} | {
|
|
544
|
-
action: 'device_auth';
|
|
545
|
-
connectionId: string;
|
|
546
|
-
} | {
|
|
547
|
-
action: 'device_poll';
|
|
548
|
-
connectionId: string;
|
|
549
|
-
deviceAuthId: string;
|
|
550
|
-
};
|
|
551
|
-
interface ListAgentConnectionsResult {
|
|
552
|
-
connections: AgentConnection[];
|
|
553
|
-
}
|
|
554
523
|
|
|
555
524
|
/**
|
|
556
525
|
* Mitra Interactions SDK - Instance
|
|
@@ -756,66 +725,6 @@ declare function manageAgentCredentialMitra(options: {
|
|
|
756
725
|
projectId?: number | string;
|
|
757
726
|
}): Promise<ConnectAgentCredentialResult>;
|
|
758
727
|
|
|
759
|
-
/**
|
|
760
|
-
* Mitra Interactions SDK — Agent Connections
|
|
761
|
-
*
|
|
762
|
-
* Management de credencial de agente COMPARTILHADA (connection do app,
|
|
763
|
-
* tenant+app) — espelho do management de credencial de user
|
|
764
|
-
* (agent-credentials.ts), apontando um connectionId. Pra sistemas montarem
|
|
765
|
-
* a tela de auth do agente.
|
|
766
|
-
*
|
|
767
|
-
* REST direto no copilot ({origin}/copilot/api/v1/connections):
|
|
768
|
-
* - list → GET /connections
|
|
769
|
-
* - create → POST /connections
|
|
770
|
-
* - save → PUT /connections/{id}/api-key
|
|
771
|
-
* - auth → POST /connections/{id}/oauth/start
|
|
772
|
-
* - connect → POST /connections/{id}/oauth/exchange
|
|
773
|
-
* - device_auth → POST /connections/{id}/device-authorizations
|
|
774
|
-
* - device_poll → POST /connections/{id}/device-authorizations/{deviceAuthId}/poll
|
|
775
|
-
*
|
|
776
|
-
* Auth: Authorization Bearer com o token da config — funciona com token de
|
|
777
|
-
* user (app-scoped, roles EDIT/OWNER/ADMIN) E com chave de SF
|
|
778
|
-
* (CONNECTION_READ/WRITE). O caminho por chave é aditivo: nada aqui exige
|
|
779
|
-
* tipo específico de credencial — o servidor decide. Só sessão de CONSOLE
|
|
780
|
-
* (JWT token_use=session, sem app_id) é barrada no client, com causa clara.
|
|
781
|
-
*
|
|
782
|
-
* SEGURANÇA: a credencial nunca sai do servidor — as respostas trazem só
|
|
783
|
-
* status/metadados da connection.
|
|
784
|
-
*/
|
|
785
|
-
|
|
786
|
-
declare function manageAgentConnectionMitra(options: {
|
|
787
|
-
action: 'list';
|
|
788
|
-
}): Promise<ListAgentConnectionsResult>;
|
|
789
|
-
declare function manageAgentConnectionMitra(options: {
|
|
790
|
-
action: 'create';
|
|
791
|
-
provider: 'anthropic' | 'openai';
|
|
792
|
-
name?: string;
|
|
793
|
-
}): Promise<AgentConnection>;
|
|
794
|
-
declare function manageAgentConnectionMitra(options: {
|
|
795
|
-
action: 'save';
|
|
796
|
-
connectionId: string;
|
|
797
|
-
key: string;
|
|
798
|
-
}): Promise<void>;
|
|
799
|
-
declare function manageAgentConnectionMitra(options: {
|
|
800
|
-
action: 'auth';
|
|
801
|
-
connectionId: string;
|
|
802
|
-
}): Promise<AuthAgentCredentialResult>;
|
|
803
|
-
declare function manageAgentConnectionMitra(options: {
|
|
804
|
-
action: 'connect';
|
|
805
|
-
connectionId: string;
|
|
806
|
-
code: string;
|
|
807
|
-
state: string;
|
|
808
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
809
|
-
declare function manageAgentConnectionMitra(options: {
|
|
810
|
-
action: 'device_auth';
|
|
811
|
-
connectionId: string;
|
|
812
|
-
}): Promise<DeviceAuthAgentCredentialResult>;
|
|
813
|
-
declare function manageAgentConnectionMitra(options: {
|
|
814
|
-
action: 'device_poll';
|
|
815
|
-
connectionId: string;
|
|
816
|
-
deviceAuthId: string;
|
|
817
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
818
|
-
|
|
819
728
|
/**
|
|
820
729
|
* Mitra Interactions SDK - Services
|
|
821
730
|
*/
|
|
@@ -871,4 +780,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
871
780
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
872
781
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
873
782
|
|
|
874
|
-
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
|
@@ -449,9 +449,15 @@ interface AgentModel {
|
|
|
449
449
|
provider: string;
|
|
450
450
|
agentType: AgentType;
|
|
451
451
|
/**
|
|
452
|
-
* Registro das intensidades de reasoning válidas pra este modelo
|
|
453
|
-
* harness — ex
|
|
454
|
-
*
|
|
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.
|
|
455
461
|
*/
|
|
456
462
|
reasoningOptions?: string[];
|
|
457
463
|
}
|
|
@@ -514,43 +520,6 @@ type ManageAgentCredentialOptions = {
|
|
|
514
520
|
deviceAuthId: string;
|
|
515
521
|
projectId?: number | string;
|
|
516
522
|
};
|
|
517
|
-
/** Connection do app (shape do copilot; campos extras passam intactos). */
|
|
518
|
-
interface AgentConnection {
|
|
519
|
-
id: string;
|
|
520
|
-
provider?: string;
|
|
521
|
-
name?: string;
|
|
522
|
-
connected?: boolean;
|
|
523
|
-
[key: string]: unknown;
|
|
524
|
-
}
|
|
525
|
-
type ManageAgentConnectionOptions = {
|
|
526
|
-
action: 'list';
|
|
527
|
-
} | {
|
|
528
|
-
action: 'create';
|
|
529
|
-
provider: AgentProvider;
|
|
530
|
-
name?: string;
|
|
531
|
-
} | {
|
|
532
|
-
action: 'save';
|
|
533
|
-
connectionId: string;
|
|
534
|
-
key: string;
|
|
535
|
-
} | {
|
|
536
|
-
action: 'auth';
|
|
537
|
-
connectionId: string;
|
|
538
|
-
} | {
|
|
539
|
-
action: 'connect';
|
|
540
|
-
connectionId: string;
|
|
541
|
-
code: string;
|
|
542
|
-
state: string;
|
|
543
|
-
} | {
|
|
544
|
-
action: 'device_auth';
|
|
545
|
-
connectionId: string;
|
|
546
|
-
} | {
|
|
547
|
-
action: 'device_poll';
|
|
548
|
-
connectionId: string;
|
|
549
|
-
deviceAuthId: string;
|
|
550
|
-
};
|
|
551
|
-
interface ListAgentConnectionsResult {
|
|
552
|
-
connections: AgentConnection[];
|
|
553
|
-
}
|
|
554
523
|
|
|
555
524
|
/**
|
|
556
525
|
* Mitra Interactions SDK - Instance
|
|
@@ -756,66 +725,6 @@ declare function manageAgentCredentialMitra(options: {
|
|
|
756
725
|
projectId?: number | string;
|
|
757
726
|
}): Promise<ConnectAgentCredentialResult>;
|
|
758
727
|
|
|
759
|
-
/**
|
|
760
|
-
* Mitra Interactions SDK — Agent Connections
|
|
761
|
-
*
|
|
762
|
-
* Management de credencial de agente COMPARTILHADA (connection do app,
|
|
763
|
-
* tenant+app) — espelho do management de credencial de user
|
|
764
|
-
* (agent-credentials.ts), apontando um connectionId. Pra sistemas montarem
|
|
765
|
-
* a tela de auth do agente.
|
|
766
|
-
*
|
|
767
|
-
* REST direto no copilot ({origin}/copilot/api/v1/connections):
|
|
768
|
-
* - list → GET /connections
|
|
769
|
-
* - create → POST /connections
|
|
770
|
-
* - save → PUT /connections/{id}/api-key
|
|
771
|
-
* - auth → POST /connections/{id}/oauth/start
|
|
772
|
-
* - connect → POST /connections/{id}/oauth/exchange
|
|
773
|
-
* - device_auth → POST /connections/{id}/device-authorizations
|
|
774
|
-
* - device_poll → POST /connections/{id}/device-authorizations/{deviceAuthId}/poll
|
|
775
|
-
*
|
|
776
|
-
* Auth: Authorization Bearer com o token da config — funciona com token de
|
|
777
|
-
* user (app-scoped, roles EDIT/OWNER/ADMIN) E com chave de SF
|
|
778
|
-
* (CONNECTION_READ/WRITE). O caminho por chave é aditivo: nada aqui exige
|
|
779
|
-
* tipo específico de credencial — o servidor decide. Só sessão de CONSOLE
|
|
780
|
-
* (JWT token_use=session, sem app_id) é barrada no client, com causa clara.
|
|
781
|
-
*
|
|
782
|
-
* SEGURANÇA: a credencial nunca sai do servidor — as respostas trazem só
|
|
783
|
-
* status/metadados da connection.
|
|
784
|
-
*/
|
|
785
|
-
|
|
786
|
-
declare function manageAgentConnectionMitra(options: {
|
|
787
|
-
action: 'list';
|
|
788
|
-
}): Promise<ListAgentConnectionsResult>;
|
|
789
|
-
declare function manageAgentConnectionMitra(options: {
|
|
790
|
-
action: 'create';
|
|
791
|
-
provider: 'anthropic' | 'openai';
|
|
792
|
-
name?: string;
|
|
793
|
-
}): Promise<AgentConnection>;
|
|
794
|
-
declare function manageAgentConnectionMitra(options: {
|
|
795
|
-
action: 'save';
|
|
796
|
-
connectionId: string;
|
|
797
|
-
key: string;
|
|
798
|
-
}): Promise<void>;
|
|
799
|
-
declare function manageAgentConnectionMitra(options: {
|
|
800
|
-
action: 'auth';
|
|
801
|
-
connectionId: string;
|
|
802
|
-
}): Promise<AuthAgentCredentialResult>;
|
|
803
|
-
declare function manageAgentConnectionMitra(options: {
|
|
804
|
-
action: 'connect';
|
|
805
|
-
connectionId: string;
|
|
806
|
-
code: string;
|
|
807
|
-
state: string;
|
|
808
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
809
|
-
declare function manageAgentConnectionMitra(options: {
|
|
810
|
-
action: 'device_auth';
|
|
811
|
-
connectionId: string;
|
|
812
|
-
}): Promise<DeviceAuthAgentCredentialResult>;
|
|
813
|
-
declare function manageAgentConnectionMitra(options: {
|
|
814
|
-
action: 'device_poll';
|
|
815
|
-
connectionId: string;
|
|
816
|
-
deviceAuthId: string;
|
|
817
|
-
}): Promise<ConnectAgentCredentialResult>;
|
|
818
|
-
|
|
819
728
|
/**
|
|
820
729
|
* Mitra Interactions SDK - Services
|
|
821
730
|
*/
|
|
@@ -871,4 +780,4 @@ declare function patchRecordMitra(options: PatchRecordOptions): Promise<Record<s
|
|
|
871
780
|
declare function deleteRecordMitra(options: DeleteRecordOptions): Promise<void>;
|
|
872
781
|
declare function createRecordsBatchMitra(options: CreateRecordsBatchOptions): Promise<Record<string, any>[]>;
|
|
873
782
|
|
|
874
|
-
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
|
@@ -1148,6 +1148,8 @@ function providerParam(target) {
|
|
|
1148
1148
|
async function manageAgentCredentialMitra(options) {
|
|
1149
1149
|
var _a, _b, _c;
|
|
1150
1150
|
const projectId = resolveProjectId(options.projectId);
|
|
1151
|
+
const connectionId = options.connectionId;
|
|
1152
|
+
const withConn = (body) => connectionId ? { ...body, connectionId } : body;
|
|
1151
1153
|
const target = options.target;
|
|
1152
1154
|
if ((options.action === "auth" || options.action === "connect") && target !== "anthropic") {
|
|
1153
1155
|
throw new Error(`manageAgentCredentialMitra(${options.action}): OAuth \xE9 exclusivo do provider 'anthropic'. Pra OpenAI use o device flow (device_auth/device_poll).`);
|
|
@@ -1166,11 +1168,11 @@ async function manageAgentCredentialMitra(options) {
|
|
|
1166
1168
|
}
|
|
1167
1169
|
case "save": {
|
|
1168
1170
|
if (!((_c = options.key) == null ? void 0 : _c.trim())) throw new Error("manageAgentCredentialMitra(save): key obrigat\xF3ria.");
|
|
1169
|
-
await http.post("/agentAiShortcut/saveCredential", {
|
|
1171
|
+
await http.post("/agentAiShortcut/saveCredential", withConn({
|
|
1170
1172
|
projectId,
|
|
1171
1173
|
provider: providerParam(options.target),
|
|
1172
1174
|
key: options.key
|
|
1173
|
-
});
|
|
1175
|
+
}));
|
|
1174
1176
|
return;
|
|
1175
1177
|
}
|
|
1176
1178
|
case "remove": {
|
|
@@ -1181,40 +1183,40 @@ async function manageAgentCredentialMitra(options) {
|
|
|
1181
1183
|
return;
|
|
1182
1184
|
}
|
|
1183
1185
|
case "auth": {
|
|
1184
|
-
const env = await http.post("/agentAiShortcut/oauthStart", {
|
|
1186
|
+
const env = await http.post("/agentAiShortcut/oauthStart", withConn({
|
|
1185
1187
|
projectId,
|
|
1186
1188
|
provider: providerParam(options.target)
|
|
1187
|
-
});
|
|
1189
|
+
}));
|
|
1188
1190
|
return env.result;
|
|
1189
1191
|
}
|
|
1190
1192
|
case "connect": {
|
|
1191
1193
|
if (!options.code || !options.state) {
|
|
1192
1194
|
throw new Error("manageAgentCredentialMitra(connect): code e state obrigat\xF3rios.");
|
|
1193
1195
|
}
|
|
1194
|
-
const env = await http.post("/agentAiShortcut/oauthExchange", {
|
|
1196
|
+
const env = await http.post("/agentAiShortcut/oauthExchange", withConn({
|
|
1195
1197
|
projectId,
|
|
1196
1198
|
provider: providerParam(options.target),
|
|
1197
1199
|
code: options.code,
|
|
1198
1200
|
state: options.state
|
|
1199
|
-
});
|
|
1201
|
+
}));
|
|
1200
1202
|
return env.result;
|
|
1201
1203
|
}
|
|
1202
1204
|
case "device_auth": {
|
|
1203
|
-
const env = await http.post("/agentAiShortcut/deviceStart", {
|
|
1205
|
+
const env = await http.post("/agentAiShortcut/deviceStart", withConn({
|
|
1204
1206
|
projectId,
|
|
1205
1207
|
provider: providerParam(options.target)
|
|
1206
|
-
});
|
|
1208
|
+
}));
|
|
1207
1209
|
return env.result;
|
|
1208
1210
|
}
|
|
1209
1211
|
case "device_poll": {
|
|
1210
1212
|
if (!options.deviceAuthId) {
|
|
1211
1213
|
throw new Error("manageAgentCredentialMitra(device_poll): deviceAuthId obrigat\xF3rio.");
|
|
1212
1214
|
}
|
|
1213
|
-
const env = await http.post("/agentAiShortcut/devicePoll", {
|
|
1215
|
+
const env = await http.post("/agentAiShortcut/devicePoll", withConn({
|
|
1214
1216
|
projectId,
|
|
1215
1217
|
provider: providerParam(options.target),
|
|
1216
1218
|
deviceAuthId: options.deviceAuthId
|
|
1217
|
-
});
|
|
1219
|
+
}));
|
|
1218
1220
|
return env.result;
|
|
1219
1221
|
}
|
|
1220
1222
|
default:
|
|
@@ -1602,96 +1604,6 @@ function resolveProjectId(projectId) {
|
|
|
1602
1604
|
throw new Error("projectId \xE9 obrigat\xF3rio. Passe nas options ou configure via configureSdkMitra({ projectId }).");
|
|
1603
1605
|
}
|
|
1604
1606
|
|
|
1605
|
-
// src/agent-connections.ts
|
|
1606
|
-
function getConnectionsBase() {
|
|
1607
|
-
const config = getConfig();
|
|
1608
|
-
if (!config.baseURL) {
|
|
1609
|
-
throw new Error("Agent Connections: baseURL n\xE3o configurada. Configure via configureSdkMitra({ baseURL }).");
|
|
1610
|
-
}
|
|
1611
|
-
const token = config.token;
|
|
1612
|
-
if (token) {
|
|
1613
|
-
const payload = decodeJwtPayload(token);
|
|
1614
|
-
if (payload && payload.token_use === "session" && !payload.app_id) {
|
|
1615
|
-
throw new Error("Agent Connections: o token configurado \xE9 uma sess\xE3o do console \u2014 use token de app (loginMitra) ou chave de SF.");
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
return `${new URL(config.baseURL).origin}/copilot/api/v1/connections`;
|
|
1619
|
-
}
|
|
1620
|
-
async function connectionsFetch(method, path, body) {
|
|
1621
|
-
var _a, _b, _c;
|
|
1622
|
-
if (isTokenExpiring()) await tryRefreshToken();
|
|
1623
|
-
const config = getConfig();
|
|
1624
|
-
if (!config.token) {
|
|
1625
|
-
throw new Error("Agent Connections: token n\xE3o configurado. Fa\xE7a login ou configure a chave de SF em configureSdkMitra({ token }).");
|
|
1626
|
-
}
|
|
1627
|
-
const doFetch = async () => fetch(`${getConnectionsBase()}${path}`, {
|
|
1628
|
-
method,
|
|
1629
|
-
headers: {
|
|
1630
|
-
"Content-Type": "application/json",
|
|
1631
|
-
"Authorization": `Bearer ${stripBearer(getConfig().token)}`
|
|
1632
|
-
},
|
|
1633
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
1634
|
-
});
|
|
1635
|
-
let response = await doFetch();
|
|
1636
|
-
if (response.status === 401 && await tryRefreshToken()) {
|
|
1637
|
-
response = await doFetch();
|
|
1638
|
-
}
|
|
1639
|
-
const text = await response.text();
|
|
1640
|
-
const { data, isJson } = parseBody(text);
|
|
1641
|
-
if (!response.ok) {
|
|
1642
|
-
const fallback = !isJson && text ? `HTTP ${response.status} \u2014 ${text}` : `HTTP ${response.status}`;
|
|
1643
|
-
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;
|
|
1644
|
-
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 };
|
|
1645
|
-
}
|
|
1646
|
-
return data;
|
|
1647
|
-
}
|
|
1648
|
-
async function manageAgentConnectionMitra(options) {
|
|
1649
|
-
var _a;
|
|
1650
|
-
switch (options.action) {
|
|
1651
|
-
case "list": {
|
|
1652
|
-
const connections = await connectionsFetch("GET", "");
|
|
1653
|
-
return { connections: connections != null ? connections : [] };
|
|
1654
|
-
}
|
|
1655
|
-
case "create": {
|
|
1656
|
-
return connectionsFetch("POST", "", {
|
|
1657
|
-
provider: String(options.provider).toUpperCase(),
|
|
1658
|
-
...options.name ? { name: options.name } : {}
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
case "save": {
|
|
1662
|
-
if (!((_a = options.key) == null ? void 0 : _a.trim())) throw new Error("manageAgentConnectionMitra(save): key obrigat\xF3ria.");
|
|
1663
|
-
await connectionsFetch("PUT", `/${encodeURIComponent(options.connectionId)}/api-key`, { apiKey: options.key });
|
|
1664
|
-
return;
|
|
1665
|
-
}
|
|
1666
|
-
case "auth": {
|
|
1667
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/oauth/start`);
|
|
1668
|
-
}
|
|
1669
|
-
case "connect": {
|
|
1670
|
-
if (!options.code || !options.state) {
|
|
1671
|
-
throw new Error("manageAgentConnectionMitra(connect): code e state obrigat\xF3rios.");
|
|
1672
|
-
}
|
|
1673
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/oauth/exchange`, {
|
|
1674
|
-
code: options.code,
|
|
1675
|
-
state: options.state
|
|
1676
|
-
});
|
|
1677
|
-
}
|
|
1678
|
-
case "device_auth": {
|
|
1679
|
-
return connectionsFetch("POST", `/${encodeURIComponent(options.connectionId)}/device-authorizations`);
|
|
1680
|
-
}
|
|
1681
|
-
case "device_poll": {
|
|
1682
|
-
if (!options.deviceAuthId) {
|
|
1683
|
-
throw new Error("manageAgentConnectionMitra(device_poll): deviceAuthId obrigat\xF3rio.");
|
|
1684
|
-
}
|
|
1685
|
-
return connectionsFetch(
|
|
1686
|
-
"POST",
|
|
1687
|
-
`/${encodeURIComponent(options.connectionId)}/device-authorizations/${encodeURIComponent(options.deviceAuthId)}/poll`
|
|
1688
|
-
);
|
|
1689
|
-
}
|
|
1690
|
-
default:
|
|
1691
|
-
throw new Error(`manageAgentConnectionMitra: action inv\xE1lida (${options.action}).`);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
1607
|
// src/services.ts
|
|
1696
1608
|
async function executeServerFunctionMitra(options) {
|
|
1697
1609
|
const body = {
|
|
@@ -1845,7 +1757,6 @@ exports.loginMitra = loginMitra;
|
|
|
1845
1757
|
exports.loginWithGoogleMitra = loginWithGoogleMitra;
|
|
1846
1758
|
exports.loginWithMicrosoftMitra = loginWithMicrosoftMitra;
|
|
1847
1759
|
exports.manageAgentChatMitra = manageAgentChatMitra;
|
|
1848
|
-
exports.manageAgentConnectionMitra = manageAgentConnectionMitra;
|
|
1849
1760
|
exports.manageAgentCredentialMitra = manageAgentCredentialMitra;
|
|
1850
1761
|
exports.patchRecordMitra = patchRecordMitra;
|
|
1851
1762
|
exports.refreshTokenSilently = refreshTokenSilently;
|