mitra-interactions-sdk 1.0.58-beta.5 → 1.0.58-beta.6

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/dist/index.d.mts CHANGED
@@ -657,7 +657,19 @@ type CredentialTarget = AgentSubscriptionTarget | AgentApiKeyTarget;
657
657
  * de baixo nível + abre popup + espera autorização):
658
658
  * connect
659
659
  */
660
- type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | 'list_models' | 'validate' | 'save' | 'oauth_start' | 'oauth_exchange' | 'device_start' | 'device_poll' | 'device_cancel';
660
+ type CredentialAction = 'auth' | 'connect' | 'status' | 'remove' | 'list' | 'list_models' | 'list_providers' | 'validate' | 'save' | 'oauth_start' | 'oauth_exchange' | 'device_start' | 'device_poll' | 'device_cancel';
661
+ /** Forma de acesso a uma credencial. */
662
+ type CredentialAccessType = 'subscription' | 'api_key';
663
+ /** Método de conexão — diz ao app/agent qual UI montar. */
664
+ type AuthMethod = 'api_key' | 'paste_code' | 'device';
665
+ /** Metadados pra montar a UI de conexão (vem em cada provider de list_providers). */
666
+ interface AgentAuthMeta {
667
+ method: AuthMethod;
668
+ /** Só para method='api_key'. */
669
+ keyLabel?: string;
670
+ /** Só para method='api_key'. */
671
+ keyPlaceholder?: string;
672
+ }
661
673
  /** Um modelo selecionável (retornado por action='list_models'). */
662
674
  interface AgentModelOption {
663
675
  /** Passe direto em send({ modelId }) ou getAgentTaskMitra({ create, modelId }). */
@@ -669,13 +681,34 @@ interface AgentModelOption {
669
681
  interface AgentModelGroup {
670
682
  id: string;
671
683
  name: string;
672
- kind: 'subscription' | 'api_key';
684
+ type: CredentialAccessType;
673
685
  models: AgentModelOption[];
674
686
  }
675
687
  /** Retorno de manageAgentCredentialMitra({ action: 'list_models' }). */
676
688
  interface ListAgentModelsResult {
677
689
  providers: AgentModelGroup[];
678
690
  }
691
+ /** Um provedor suportado + status (retornado por action='list_providers'). */
692
+ interface AgentProviderListItem {
693
+ id: string;
694
+ name: string;
695
+ type: CredentialAccessType;
696
+ /** Passe direto em auth/connect/save/remove. */
697
+ target: string;
698
+ /** Como conectar: method (api_key|paste_code|device) + label/placeholder. */
699
+ auth: AgentAuthMeta;
700
+ connected: boolean;
701
+ /** Presente em subscription Claude conectada. */
702
+ account?: AgentSubscriptionAccount;
703
+ expiresAt?: number;
704
+ /** Presente em API key conectada. */
705
+ maskedKey?: string;
706
+ updatedAt?: string | Date;
707
+ }
708
+ /** Retorno de manageAgentCredentialMitra({ action: 'list_providers' }). */
709
+ interface ListAgentProvidersResult {
710
+ providers: AgentProviderListItem[];
711
+ }
679
712
  /**
680
713
  * Opções de baixo nível (RPC direto) de `manageAgentCredentialMitra`. Campos
681
714
  * extras (key, code, codeVerifier, redirectUri, pollId, accessToken,
@@ -684,8 +717,8 @@ interface ListAgentModelsResult {
684
717
  * NÃO use com action='connect' — para isso use ConnectAgentCredentialOptions.
685
718
  */
686
719
  interface ManageAgentCredentialOptions {
687
- action: Exclude<CredentialAction, 'connect'>;
688
- /** Obrigatório exceto para action='list'. */
720
+ action: Exclude<CredentialAction, 'connect' | 'auth'>;
721
+ /** Obrigatório exceto para action='list' / 'list_models'. */
689
722
  target?: CredentialTarget;
690
723
  /** Para `save` / `validate` de API key. */
691
724
  key?: string;
@@ -717,46 +750,54 @@ interface AgentSubscriptionAccount {
717
750
  * Orquestra o fluxo OAuth/device ponta-a-ponta no browser (abre popup, espera
718
751
  * autorização, troca por tokens server-side).
719
752
  */
753
+ /**
754
+ * Targets que conectam SEM redirect (paste código / device flow). O
755
+ * 'openai_oauth' fica de fora porque depende de redirect localhost:1455
756
+ * (client OAuth compartilhado da OpenAI) — inviável em domínio de cliente.
757
+ * OpenAI subscription conecta via 'codex' (device flow).
758
+ */
759
+ type ConnectableSubscriptionTarget = 'claude' | 'codex';
760
+ interface AuthAgentCredentialOptions {
761
+ action: 'auth';
762
+ target: ConnectableSubscriptionTarget;
763
+ }
764
+ /** Resultado de auth(claude): abra a authUrl, depois connect com o código. */
765
+ interface AuthClaudeResult {
766
+ target: 'claude';
767
+ /** URL pra abrir (a Anthropic mostra o código na própria tela). */
768
+ authUrl: string;
769
+ /** Passe de volta no connect junto com o código. */
770
+ state: string;
771
+ }
772
+ /** Resultado de auth(codex): mostre userCode/verificationUrl, depois connect com pollId. */
773
+ interface AuthCodexResult {
774
+ target: 'codex';
775
+ /** Código que o user digita no site da OpenAI. */
776
+ userCode: string | null;
777
+ /** URL que o user abre pra autorizar. */
778
+ verificationUrl: string | null;
779
+ /** Passe de volta no connect; a SDK faz o polling. */
780
+ pollId: string;
781
+ }
782
+ type AuthAgentCredentialResult = AuthClaudeResult | AuthCodexResult;
720
783
  interface ConnectAgentCredentialOptions {
721
784
  action: 'connect';
722
- target: AgentSubscriptionTarget;
723
- /**
724
- * Callback que retorna o código que o usuário copiou da página da Anthropic
725
- * após autorizar. **Obrigatório** para target='claude'.
726
- */
727
- onCodeNeeded?: (info: {
728
- authUrl: string;
729
- state: string;
730
- }) => Promise<string> | string;
731
- /**
732
- * URL no domínio do app publicado que captura o `?code=` da OAuth e faz
733
- * `window.opener.postMessage({ mitraOpenAICode: code }, '*')`.
734
- * **Obrigatório** para target='openai_oauth'.
735
- */
736
- redirectUri?: string;
737
- /** Timeout esperando o postMessage (default 5min). */
738
- messageTimeoutMs?: number;
739
- /**
740
- * Callback opcional que recebe o `userCode` e `verificationUrl` assim que
741
- * o device flow inicia (use pra exibir na UI além do popup automático).
742
- */
743
- onDeviceCode?: (info: {
744
- userCode: string | null;
745
- verificationUrl: string | null;
746
- }) => void;
785
+ target: ConnectableSubscriptionTarget;
786
+ /** Código que o user copiou da página da Anthropic. Obrigatório p/ claude. */
787
+ code?: string;
788
+ /** O `state` devolvido por auth(claude). Obrigatório p/ claude. */
789
+ state?: string;
790
+ /** O `pollId` devolvido por auth(codex). Obrigatório p/ codex. */
791
+ pollId?: string;
747
792
  /** Intervalo de poll do device flow (default 2000ms). */
748
793
  pollIntervalMs?: number;
749
794
  /** Timeout total do device flow (default 15min). */
750
795
  deviceTimeoutMs?: number;
751
- /** Nome da window do popup (default depende do target). */
752
- windowName?: string;
753
- /** `features` string passada para `window.open`. */
754
- windowFeatures?: string;
755
796
  }
756
797
  interface ConnectAgentSubscriptionResult {
757
- target: AgentSubscriptionTarget;
798
+ target: ConnectableSubscriptionTarget;
758
799
  success: boolean;
759
- /** Presente em claude / openai_oauth (epoch ms). */
800
+ /** Presente em claude (epoch ms). */
760
801
  expiresAt?: number;
761
802
  /** Presente apenas em claude. */
762
803
  account?: AgentSubscriptionAccount | null;
@@ -973,48 +1014,48 @@ declare function getAgentTaskMitra(options: GetAgentTaskOptions): AgentTaskSessi
973
1014
  * Função ÚNICA `manageAgentCredentialMitra` sobre /sdk-ws para todas as
974
1015
  * operações de credencial do agente:
975
1016
  * - API keys (8 providers: anthropic, openai, gemini, kimi, minimax, glm, qwen, openrouter)
976
- * - Subscriptions OAuth (Claude / OpenAI / Codex device flow)
1017
+ * - Subscriptions OAuth (Claude paste-código / OpenAI device flow via Codex)
977
1018
  *
978
1019
  * Actions de baixo nível (RPC direto contra o backend):
979
- * status | remove | list | validate | save
1020
+ * status | remove | list | list_models | validate | save
980
1021
  * oauth_start | oauth_exchange | device_start | device_poll | device_cancel
981
1022
  *
982
- * Action de alto nível (orquestra o fluxo ponta-a-ponta no browser):
983
- * connect abre popup, espera código/postMessage/poll, troca por tokens.
1023
+ * Actions de alto nível (orquestradas na SDK — o app controla UI/popup/timing):
1024
+ * auth inicia o fluxo e retorna o que a UI mostra (sem efeito colateral
1025
+ * de janela). claude → { authUrl, state }; codex → { userCode,
1026
+ * verificationUrl, pollId }.
1027
+ * connect — finaliza/salva. claude → passa { code, state }; codex → passa
1028
+ * { pollId } e a SDK faz o polling até autorizar.
1029
+ *
1030
+ * Fluxo típico (sem callbacks, sem redirect, sem callback page):
1031
+ * const { authUrl, state } = await manageAgentCredentialMitra({ action:'auth', target:'claude' });
1032
+ * // app abre authUrl + coleta o código do user
1033
+ * await manageAgentCredentialMitra({ action:'connect', target:'claude', code, state });
1034
+ *
1035
+ * const { userCode, verificationUrl, pollId } = await manageAgentCredentialMitra({ action:'auth', target:'codex' });
1036
+ * // app mostra "abra {verificationUrl}, digite {userCode}"
1037
+ * await manageAgentCredentialMitra({ action:'connect', target:'codex', pollId });
984
1038
  *
985
1039
  * SEGURANÇA: o token de subscription NUNCA volta cru pro cliente. É salvo
986
- * server-side (Firestore) e injetado no sandbox E2B direto de lá. O retorno
987
- * de `connect`/`oauth_exchange` traz só { connected, expiresAt, account }.
1040
+ * server-side (Firestore) e injetado no sandbox E2B direto de lá.
988
1041
  */
989
1042
 
990
1043
  /**
991
- * Conecta uma subscription ponta-a-ponta (abre popup, espera autorização,
992
- * troca por tokens). Retorno tipado: { target, success, expiresAt?, account? }.
993
- *
994
- * @example
995
- * // Claude — caller mostra modal pedindo o paste do código
996
- * await manageAgentCredentialMitra({
997
- * action: 'connect', target: 'claude',
998
- * onCodeNeeded: async () => prompt('Cole o código:') ?? ''
999
- * });
1000
- *
1001
- * @example
1002
- * // OpenAI — callback page no domínio do app faz postMessage
1003
- * await manageAgentCredentialMitra({
1004
- * action: 'connect', target: 'openai_oauth',
1005
- * redirectUri: window.location.origin + '/auth/openai-callback'
1006
- * });
1007
- *
1008
- * @example
1009
- * // Codex — device flow automático (abre verificação, polling)
1010
- * await manageAgentCredentialMitra({ action: 'connect', target: 'codex' });
1044
+ * Inicia um fluxo de subscription. Não abre janelas retorna os dados pra UI:
1045
+ * claude { authUrl, state } codex { userCode, verificationUrl, pollId }
1046
+ */
1047
+ declare function manageAgentCredentialMitra(options: AuthAgentCredentialOptions): Promise<AuthAgentCredentialResult>;
1048
+ /**
1049
+ * Finaliza/salva uma subscription:
1050
+ * claude → { code, state } codex → { pollId } (a SDK faz o polling)
1011
1051
  */
1012
1052
  declare function manageAgentCredentialMitra(options: ConnectAgentCredentialOptions): Promise<ConnectAgentSubscriptionResult>;
1013
1053
  /**
1014
- * RPC direto contra o backend. Retorno depende de (action, target) — veja docs.
1054
+ * RPC direto contra o backend. Retorno depende de (action, target).
1015
1055
  *
1016
1056
  * @example
1017
1057
  * await manageAgentCredentialMitra({ action: 'list' });
1058
+ * await manageAgentCredentialMitra({ action: 'list_models' });
1018
1059
  * await manageAgentCredentialMitra({ action: 'status', target: 'anthropic' });
1019
1060
  * await manageAgentCredentialMitra({ action: 'validate', target: 'openai', key: 'sk-...' });
1020
1061
  * await manageAgentCredentialMitra({ action: 'save', target: 'glm', key: '...' });
@@ -1177,4 +1218,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1177
1218
  */
1178
1219
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1179
1220
 
1180
- export { type AgentApiKeyTarget, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type CallIntegrationOptions, type CallIntegrationResponse, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type CredentialTarget, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentChatsOptions, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentChatsMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
1221
+ export { type AgentApiKeyTarget, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentChatsOptions, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentChatsMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
package/dist/index.d.ts CHANGED
@@ -657,7 +657,19 @@ type CredentialTarget = AgentSubscriptionTarget | AgentApiKeyTarget;
657
657
  * de baixo nível + abre popup + espera autorização):
658
658
  * connect
659
659
  */
660
- type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | 'list_models' | 'validate' | 'save' | 'oauth_start' | 'oauth_exchange' | 'device_start' | 'device_poll' | 'device_cancel';
660
+ type CredentialAction = 'auth' | 'connect' | 'status' | 'remove' | 'list' | 'list_models' | 'list_providers' | 'validate' | 'save' | 'oauth_start' | 'oauth_exchange' | 'device_start' | 'device_poll' | 'device_cancel';
661
+ /** Forma de acesso a uma credencial. */
662
+ type CredentialAccessType = 'subscription' | 'api_key';
663
+ /** Método de conexão — diz ao app/agent qual UI montar. */
664
+ type AuthMethod = 'api_key' | 'paste_code' | 'device';
665
+ /** Metadados pra montar a UI de conexão (vem em cada provider de list_providers). */
666
+ interface AgentAuthMeta {
667
+ method: AuthMethod;
668
+ /** Só para method='api_key'. */
669
+ keyLabel?: string;
670
+ /** Só para method='api_key'. */
671
+ keyPlaceholder?: string;
672
+ }
661
673
  /** Um modelo selecionável (retornado por action='list_models'). */
662
674
  interface AgentModelOption {
663
675
  /** Passe direto em send({ modelId }) ou getAgentTaskMitra({ create, modelId }). */
@@ -669,13 +681,34 @@ interface AgentModelOption {
669
681
  interface AgentModelGroup {
670
682
  id: string;
671
683
  name: string;
672
- kind: 'subscription' | 'api_key';
684
+ type: CredentialAccessType;
673
685
  models: AgentModelOption[];
674
686
  }
675
687
  /** Retorno de manageAgentCredentialMitra({ action: 'list_models' }). */
676
688
  interface ListAgentModelsResult {
677
689
  providers: AgentModelGroup[];
678
690
  }
691
+ /** Um provedor suportado + status (retornado por action='list_providers'). */
692
+ interface AgentProviderListItem {
693
+ id: string;
694
+ name: string;
695
+ type: CredentialAccessType;
696
+ /** Passe direto em auth/connect/save/remove. */
697
+ target: string;
698
+ /** Como conectar: method (api_key|paste_code|device) + label/placeholder. */
699
+ auth: AgentAuthMeta;
700
+ connected: boolean;
701
+ /** Presente em subscription Claude conectada. */
702
+ account?: AgentSubscriptionAccount;
703
+ expiresAt?: number;
704
+ /** Presente em API key conectada. */
705
+ maskedKey?: string;
706
+ updatedAt?: string | Date;
707
+ }
708
+ /** Retorno de manageAgentCredentialMitra({ action: 'list_providers' }). */
709
+ interface ListAgentProvidersResult {
710
+ providers: AgentProviderListItem[];
711
+ }
679
712
  /**
680
713
  * Opções de baixo nível (RPC direto) de `manageAgentCredentialMitra`. Campos
681
714
  * extras (key, code, codeVerifier, redirectUri, pollId, accessToken,
@@ -684,8 +717,8 @@ interface ListAgentModelsResult {
684
717
  * NÃO use com action='connect' — para isso use ConnectAgentCredentialOptions.
685
718
  */
686
719
  interface ManageAgentCredentialOptions {
687
- action: Exclude<CredentialAction, 'connect'>;
688
- /** Obrigatório exceto para action='list'. */
720
+ action: Exclude<CredentialAction, 'connect' | 'auth'>;
721
+ /** Obrigatório exceto para action='list' / 'list_models'. */
689
722
  target?: CredentialTarget;
690
723
  /** Para `save` / `validate` de API key. */
691
724
  key?: string;
@@ -717,46 +750,54 @@ interface AgentSubscriptionAccount {
717
750
  * Orquestra o fluxo OAuth/device ponta-a-ponta no browser (abre popup, espera
718
751
  * autorização, troca por tokens server-side).
719
752
  */
753
+ /**
754
+ * Targets que conectam SEM redirect (paste código / device flow). O
755
+ * 'openai_oauth' fica de fora porque depende de redirect localhost:1455
756
+ * (client OAuth compartilhado da OpenAI) — inviável em domínio de cliente.
757
+ * OpenAI subscription conecta via 'codex' (device flow).
758
+ */
759
+ type ConnectableSubscriptionTarget = 'claude' | 'codex';
760
+ interface AuthAgentCredentialOptions {
761
+ action: 'auth';
762
+ target: ConnectableSubscriptionTarget;
763
+ }
764
+ /** Resultado de auth(claude): abra a authUrl, depois connect com o código. */
765
+ interface AuthClaudeResult {
766
+ target: 'claude';
767
+ /** URL pra abrir (a Anthropic mostra o código na própria tela). */
768
+ authUrl: string;
769
+ /** Passe de volta no connect junto com o código. */
770
+ state: string;
771
+ }
772
+ /** Resultado de auth(codex): mostre userCode/verificationUrl, depois connect com pollId. */
773
+ interface AuthCodexResult {
774
+ target: 'codex';
775
+ /** Código que o user digita no site da OpenAI. */
776
+ userCode: string | null;
777
+ /** URL que o user abre pra autorizar. */
778
+ verificationUrl: string | null;
779
+ /** Passe de volta no connect; a SDK faz o polling. */
780
+ pollId: string;
781
+ }
782
+ type AuthAgentCredentialResult = AuthClaudeResult | AuthCodexResult;
720
783
  interface ConnectAgentCredentialOptions {
721
784
  action: 'connect';
722
- target: AgentSubscriptionTarget;
723
- /**
724
- * Callback que retorna o código que o usuário copiou da página da Anthropic
725
- * após autorizar. **Obrigatório** para target='claude'.
726
- */
727
- onCodeNeeded?: (info: {
728
- authUrl: string;
729
- state: string;
730
- }) => Promise<string> | string;
731
- /**
732
- * URL no domínio do app publicado que captura o `?code=` da OAuth e faz
733
- * `window.opener.postMessage({ mitraOpenAICode: code }, '*')`.
734
- * **Obrigatório** para target='openai_oauth'.
735
- */
736
- redirectUri?: string;
737
- /** Timeout esperando o postMessage (default 5min). */
738
- messageTimeoutMs?: number;
739
- /**
740
- * Callback opcional que recebe o `userCode` e `verificationUrl` assim que
741
- * o device flow inicia (use pra exibir na UI além do popup automático).
742
- */
743
- onDeviceCode?: (info: {
744
- userCode: string | null;
745
- verificationUrl: string | null;
746
- }) => void;
785
+ target: ConnectableSubscriptionTarget;
786
+ /** Código que o user copiou da página da Anthropic. Obrigatório p/ claude. */
787
+ code?: string;
788
+ /** O `state` devolvido por auth(claude). Obrigatório p/ claude. */
789
+ state?: string;
790
+ /** O `pollId` devolvido por auth(codex). Obrigatório p/ codex. */
791
+ pollId?: string;
747
792
  /** Intervalo de poll do device flow (default 2000ms). */
748
793
  pollIntervalMs?: number;
749
794
  /** Timeout total do device flow (default 15min). */
750
795
  deviceTimeoutMs?: number;
751
- /** Nome da window do popup (default depende do target). */
752
- windowName?: string;
753
- /** `features` string passada para `window.open`. */
754
- windowFeatures?: string;
755
796
  }
756
797
  interface ConnectAgentSubscriptionResult {
757
- target: AgentSubscriptionTarget;
798
+ target: ConnectableSubscriptionTarget;
758
799
  success: boolean;
759
- /** Presente em claude / openai_oauth (epoch ms). */
800
+ /** Presente em claude (epoch ms). */
760
801
  expiresAt?: number;
761
802
  /** Presente apenas em claude. */
762
803
  account?: AgentSubscriptionAccount | null;
@@ -973,48 +1014,48 @@ declare function getAgentTaskMitra(options: GetAgentTaskOptions): AgentTaskSessi
973
1014
  * Função ÚNICA `manageAgentCredentialMitra` sobre /sdk-ws para todas as
974
1015
  * operações de credencial do agente:
975
1016
  * - API keys (8 providers: anthropic, openai, gemini, kimi, minimax, glm, qwen, openrouter)
976
- * - Subscriptions OAuth (Claude / OpenAI / Codex device flow)
1017
+ * - Subscriptions OAuth (Claude paste-código / OpenAI device flow via Codex)
977
1018
  *
978
1019
  * Actions de baixo nível (RPC direto contra o backend):
979
- * status | remove | list | validate | save
1020
+ * status | remove | list | list_models | validate | save
980
1021
  * oauth_start | oauth_exchange | device_start | device_poll | device_cancel
981
1022
  *
982
- * Action de alto nível (orquestra o fluxo ponta-a-ponta no browser):
983
- * connect abre popup, espera código/postMessage/poll, troca por tokens.
1023
+ * Actions de alto nível (orquestradas na SDK — o app controla UI/popup/timing):
1024
+ * auth inicia o fluxo e retorna o que a UI mostra (sem efeito colateral
1025
+ * de janela). claude → { authUrl, state }; codex → { userCode,
1026
+ * verificationUrl, pollId }.
1027
+ * connect — finaliza/salva. claude → passa { code, state }; codex → passa
1028
+ * { pollId } e a SDK faz o polling até autorizar.
1029
+ *
1030
+ * Fluxo típico (sem callbacks, sem redirect, sem callback page):
1031
+ * const { authUrl, state } = await manageAgentCredentialMitra({ action:'auth', target:'claude' });
1032
+ * // app abre authUrl + coleta o código do user
1033
+ * await manageAgentCredentialMitra({ action:'connect', target:'claude', code, state });
1034
+ *
1035
+ * const { userCode, verificationUrl, pollId } = await manageAgentCredentialMitra({ action:'auth', target:'codex' });
1036
+ * // app mostra "abra {verificationUrl}, digite {userCode}"
1037
+ * await manageAgentCredentialMitra({ action:'connect', target:'codex', pollId });
984
1038
  *
985
1039
  * SEGURANÇA: o token de subscription NUNCA volta cru pro cliente. É salvo
986
- * server-side (Firestore) e injetado no sandbox E2B direto de lá. O retorno
987
- * de `connect`/`oauth_exchange` traz só { connected, expiresAt, account }.
1040
+ * server-side (Firestore) e injetado no sandbox E2B direto de lá.
988
1041
  */
989
1042
 
990
1043
  /**
991
- * Conecta uma subscription ponta-a-ponta (abre popup, espera autorização,
992
- * troca por tokens). Retorno tipado: { target, success, expiresAt?, account? }.
993
- *
994
- * @example
995
- * // Claude — caller mostra modal pedindo o paste do código
996
- * await manageAgentCredentialMitra({
997
- * action: 'connect', target: 'claude',
998
- * onCodeNeeded: async () => prompt('Cole o código:') ?? ''
999
- * });
1000
- *
1001
- * @example
1002
- * // OpenAI — callback page no domínio do app faz postMessage
1003
- * await manageAgentCredentialMitra({
1004
- * action: 'connect', target: 'openai_oauth',
1005
- * redirectUri: window.location.origin + '/auth/openai-callback'
1006
- * });
1007
- *
1008
- * @example
1009
- * // Codex — device flow automático (abre verificação, polling)
1010
- * await manageAgentCredentialMitra({ action: 'connect', target: 'codex' });
1044
+ * Inicia um fluxo de subscription. Não abre janelas retorna os dados pra UI:
1045
+ * claude { authUrl, state } codex { userCode, verificationUrl, pollId }
1046
+ */
1047
+ declare function manageAgentCredentialMitra(options: AuthAgentCredentialOptions): Promise<AuthAgentCredentialResult>;
1048
+ /**
1049
+ * Finaliza/salva uma subscription:
1050
+ * claude → { code, state } codex → { pollId } (a SDK faz o polling)
1011
1051
  */
1012
1052
  declare function manageAgentCredentialMitra(options: ConnectAgentCredentialOptions): Promise<ConnectAgentSubscriptionResult>;
1013
1053
  /**
1014
- * RPC direto contra o backend. Retorno depende de (action, target) — veja docs.
1054
+ * RPC direto contra o backend. Retorno depende de (action, target).
1015
1055
  *
1016
1056
  * @example
1017
1057
  * await manageAgentCredentialMitra({ action: 'list' });
1058
+ * await manageAgentCredentialMitra({ action: 'list_models' });
1018
1059
  * await manageAgentCredentialMitra({ action: 'status', target: 'anthropic' });
1019
1060
  * await manageAgentCredentialMitra({ action: 'validate', target: 'openai', key: 'sk-...' });
1020
1061
  * await manageAgentCredentialMitra({ action: 'save', target: 'glm', key: '...' });
@@ -1177,4 +1218,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1177
1218
  */
1178
1219
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1179
1220
 
1180
- export { type AgentApiKeyTarget, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type CallIntegrationOptions, type CallIntegrationResponse, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type CredentialTarget, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentChatsOptions, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentChatsMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
1221
+ export { type AgentApiKeyTarget, type AgentAuthMeta, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, type AgentModelGroup, type AgentModelOption, type AgentProviderListItem, type AgentQueueChangeEvent, type AgentStatusChangeEvent, type AgentSubscriptionAccount, type AgentSubscriptionTarget, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialOptions, type AuthAgentCredentialResult, type AuthClaudeResult, type AuthCodexResult, type AuthMethod, type CallIntegrationOptions, type CallIntegrationResponse, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type EmailLoginOptions, type EmailResendCodeOptions, type EmailSignupOptions, type EmailVerifyCodeOptions, type ExecuteDataLoaderOptions, type ExecuteDataLoaderResponse, type ExecuteDbActionOptions, type ExecuteDbActionResponse, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentChatsOptions, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetProfileDetailsOptions, type GetProfileDetailsResponse, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GetVariableOptions, type GetVariableResponse, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListProfilesOptions, type ListProfilesResponse, type ListRecordsOptions, type ListRecordsResponse, type ListVariablesOptions, type ListVariablesResponse, type LoginOptions, type LoginResponse, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, type SendOptions, type SendPasswordResetCodeOptions, type SetFileStatusOptions, type SetFileStatusResponse, type SetProfileActionsOptions, type SetProfileDmlTablesOptions, type SetProfilePermissionResponse, type SetProfileScreensOptions, type SetProfileSelectTablesOptions, type SetProfileServerFunctionsOptions, type SetProfileUsersOptions, type SetVariableOptions, type SetVariableResponse, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateProfileOptions, type UpdateProfileResponse, type UpdateRecordOptions, type UploadFileOptions, type UploadFileResponse, type ValidatePasswordResetCodeOptions, callIntegrationMitra, closeChatMitra, configureSdkMitra, createMitraInstance, createProfileMitra, createRecordMitra, createRecordsBatchMitra, deleteProfileMitra, deleteRecordMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentChatsMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };