mitra-interactions-sdk 1.0.58-beta.4 → 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
@@ -547,6 +547,13 @@ interface GetAgentTaskCreateOptions {
547
547
  projectId?: number;
548
548
  /** Tipo do agente. Default: 'claudecode'. */
549
549
  agentType?: AgentType;
550
+ /**
551
+ * Modelo a usar (value vindo de manageAgentCredentialMitra({action:'list_models'})).
552
+ * Ex: 'openai/gpt-5.5:medium', 'glm/glm-5.1', 'subscription:anthropic:claude-opus-4-7'.
553
+ * O backend deriva agentType/provider/model a partir dele. Vira o default da
554
+ * task; cada send() pode sobrescrever via SendOptions.modelId.
555
+ */
556
+ modelId?: string;
550
557
  /** Nome do chat (default: derivado do prompt). */
551
558
  name?: string;
552
559
  }
@@ -567,6 +574,12 @@ interface QueuedItem {
567
574
  }
568
575
  interface SendOptions {
569
576
  agentType?: AgentType;
577
+ /**
578
+ * Modelo a usar neste turno (value de list_models). Ex: 'openai/gpt-5.5:medium',
579
+ * 'glm/glm-5.1', 'subscription:anthropic:claude-opus-4-7'. Sobrescreve o modelId
580
+ * default da session. Se omitido, usa o default da session / agentType.
581
+ */
582
+ modelId?: string;
570
583
  }
571
584
  interface AgentDeltaEvent {
572
585
  delta: string;
@@ -644,7 +657,58 @@ type CredentialTarget = AgentSubscriptionTarget | AgentApiKeyTarget;
644
657
  * de baixo nível + abre popup + espera autorização):
645
658
  * connect
646
659
  */
647
- type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | '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
+ }
673
+ /** Um modelo selecionável (retornado por action='list_models'). */
674
+ interface AgentModelOption {
675
+ /** Passe direto em send({ modelId }) ou getAgentTaskMitra({ create, modelId }). */
676
+ modelId: string;
677
+ /** Label exibível. */
678
+ name: string;
679
+ }
680
+ /** Grupo de modelos por (tipo × provedor) — só grupos com credencial. */
681
+ interface AgentModelGroup {
682
+ id: string;
683
+ name: string;
684
+ type: CredentialAccessType;
685
+ models: AgentModelOption[];
686
+ }
687
+ /** Retorno de manageAgentCredentialMitra({ action: 'list_models' }). */
688
+ interface ListAgentModelsResult {
689
+ providers: AgentModelGroup[];
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
+ }
648
712
  /**
649
713
  * Opções de baixo nível (RPC direto) de `manageAgentCredentialMitra`. Campos
650
714
  * extras (key, code, codeVerifier, redirectUri, pollId, accessToken,
@@ -653,8 +717,8 @@ type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | 'validate' |
653
717
  * NÃO use com action='connect' — para isso use ConnectAgentCredentialOptions.
654
718
  */
655
719
  interface ManageAgentCredentialOptions {
656
- action: Exclude<CredentialAction, 'connect'>;
657
- /** Obrigatório exceto para action='list'. */
720
+ action: Exclude<CredentialAction, 'connect' | 'auth'>;
721
+ /** Obrigatório exceto para action='list' / 'list_models'. */
658
722
  target?: CredentialTarget;
659
723
  /** Para `save` / `validate` de API key. */
660
724
  key?: string;
@@ -686,46 +750,54 @@ interface AgentSubscriptionAccount {
686
750
  * Orquestra o fluxo OAuth/device ponta-a-ponta no browser (abre popup, espera
687
751
  * autorização, troca por tokens server-side).
688
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;
689
783
  interface ConnectAgentCredentialOptions {
690
784
  action: 'connect';
691
- target: AgentSubscriptionTarget;
692
- /**
693
- * Callback que retorna o código que o usuário copiou da página da Anthropic
694
- * após autorizar. **Obrigatório** para target='claude'.
695
- */
696
- onCodeNeeded?: (info: {
697
- authUrl: string;
698
- state: string;
699
- }) => Promise<string> | string;
700
- /**
701
- * URL no domínio do app publicado que captura o `?code=` da OAuth e faz
702
- * `window.opener.postMessage({ mitraOpenAICode: code }, '*')`.
703
- * **Obrigatório** para target='openai_oauth'.
704
- */
705
- redirectUri?: string;
706
- /** Timeout esperando o postMessage (default 5min). */
707
- messageTimeoutMs?: number;
708
- /**
709
- * Callback opcional que recebe o `userCode` e `verificationUrl` assim que
710
- * o device flow inicia (use pra exibir na UI além do popup automático).
711
- */
712
- onDeviceCode?: (info: {
713
- userCode: string | null;
714
- verificationUrl: string | null;
715
- }) => 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;
716
792
  /** Intervalo de poll do device flow (default 2000ms). */
717
793
  pollIntervalMs?: number;
718
794
  /** Timeout total do device flow (default 15min). */
719
795
  deviceTimeoutMs?: number;
720
- /** Nome da window do popup (default depende do target). */
721
- windowName?: string;
722
- /** `features` string passada para `window.open`. */
723
- windowFeatures?: string;
724
796
  }
725
797
  interface ConnectAgentSubscriptionResult {
726
- target: AgentSubscriptionTarget;
798
+ target: ConnectableSubscriptionTarget;
727
799
  success: boolean;
728
- /** Presente em claude / openai_oauth (epoch ms). */
800
+ /** Presente em claude (epoch ms). */
729
801
  expiresAt?: number;
730
802
  /** Presente apenas em claude. */
731
803
  account?: AgentSubscriptionAccount | null;
@@ -942,48 +1014,48 @@ declare function getAgentTaskMitra(options: GetAgentTaskOptions): AgentTaskSessi
942
1014
  * Função ÚNICA `manageAgentCredentialMitra` sobre /sdk-ws para todas as
943
1015
  * operações de credencial do agente:
944
1016
  * - API keys (8 providers: anthropic, openai, gemini, kimi, minimax, glm, qwen, openrouter)
945
- * - Subscriptions OAuth (Claude / OpenAI / Codex device flow)
1017
+ * - Subscriptions OAuth (Claude paste-código / OpenAI device flow via Codex)
946
1018
  *
947
1019
  * Actions de baixo nível (RPC direto contra o backend):
948
- * status | remove | list | validate | save
1020
+ * status | remove | list | list_models | validate | save
949
1021
  * oauth_start | oauth_exchange | device_start | device_poll | device_cancel
950
1022
  *
951
- * Action de alto nível (orquestra o fluxo ponta-a-ponta no browser):
952
- * 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 });
953
1038
  *
954
1039
  * SEGURANÇA: o token de subscription NUNCA volta cru pro cliente. É salvo
955
- * server-side (Firestore) e injetado no sandbox E2B direto de lá. O retorno
956
- * de `connect`/`oauth_exchange` traz só { connected, expiresAt, account }.
1040
+ * server-side (Firestore) e injetado no sandbox E2B direto de lá.
957
1041
  */
958
1042
 
959
1043
  /**
960
- * Conecta uma subscription ponta-a-ponta (abre popup, espera autorização,
961
- * troca por tokens). Retorno tipado: { target, success, expiresAt?, account? }.
962
- *
963
- * @example
964
- * // Claude — caller mostra modal pedindo o paste do código
965
- * await manageAgentCredentialMitra({
966
- * action: 'connect', target: 'claude',
967
- * onCodeNeeded: async () => prompt('Cole o código:') ?? ''
968
- * });
969
- *
970
- * @example
971
- * // OpenAI — callback page no domínio do app faz postMessage
972
- * await manageAgentCredentialMitra({
973
- * action: 'connect', target: 'openai_oauth',
974
- * redirectUri: window.location.origin + '/auth/openai-callback'
975
- * });
976
- *
977
- * @example
978
- * // Codex — device flow automático (abre verificação, polling)
979
- * 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)
980
1051
  */
981
1052
  declare function manageAgentCredentialMitra(options: ConnectAgentCredentialOptions): Promise<ConnectAgentSubscriptionResult>;
982
1053
  /**
983
- * RPC direto contra o backend. Retorno depende de (action, target) — veja docs.
1054
+ * RPC direto contra o backend. Retorno depende de (action, target).
984
1055
  *
985
1056
  * @example
986
1057
  * await manageAgentCredentialMitra({ action: 'list' });
1058
+ * await manageAgentCredentialMitra({ action: 'list_models' });
987
1059
  * await manageAgentCredentialMitra({ action: 'status', target: 'anthropic' });
988
1060
  * await manageAgentCredentialMitra({ action: 'validate', target: 'openai', key: 'sk-...' });
989
1061
  * await manageAgentCredentialMitra({ action: 'save', target: 'glm', key: '...' });
@@ -1146,4 +1218,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1146
1218
  */
1147
1219
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1148
1220
 
1149
- export { type AgentApiKeyTarget, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, 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 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
@@ -547,6 +547,13 @@ interface GetAgentTaskCreateOptions {
547
547
  projectId?: number;
548
548
  /** Tipo do agente. Default: 'claudecode'. */
549
549
  agentType?: AgentType;
550
+ /**
551
+ * Modelo a usar (value vindo de manageAgentCredentialMitra({action:'list_models'})).
552
+ * Ex: 'openai/gpt-5.5:medium', 'glm/glm-5.1', 'subscription:anthropic:claude-opus-4-7'.
553
+ * O backend deriva agentType/provider/model a partir dele. Vira o default da
554
+ * task; cada send() pode sobrescrever via SendOptions.modelId.
555
+ */
556
+ modelId?: string;
550
557
  /** Nome do chat (default: derivado do prompt). */
551
558
  name?: string;
552
559
  }
@@ -567,6 +574,12 @@ interface QueuedItem {
567
574
  }
568
575
  interface SendOptions {
569
576
  agentType?: AgentType;
577
+ /**
578
+ * Modelo a usar neste turno (value de list_models). Ex: 'openai/gpt-5.5:medium',
579
+ * 'glm/glm-5.1', 'subscription:anthropic:claude-opus-4-7'. Sobrescreve o modelId
580
+ * default da session. Se omitido, usa o default da session / agentType.
581
+ */
582
+ modelId?: string;
570
583
  }
571
584
  interface AgentDeltaEvent {
572
585
  delta: string;
@@ -644,7 +657,58 @@ type CredentialTarget = AgentSubscriptionTarget | AgentApiKeyTarget;
644
657
  * de baixo nível + abre popup + espera autorização):
645
658
  * connect
646
659
  */
647
- type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | '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
+ }
673
+ /** Um modelo selecionável (retornado por action='list_models'). */
674
+ interface AgentModelOption {
675
+ /** Passe direto em send({ modelId }) ou getAgentTaskMitra({ create, modelId }). */
676
+ modelId: string;
677
+ /** Label exibível. */
678
+ name: string;
679
+ }
680
+ /** Grupo de modelos por (tipo × provedor) — só grupos com credencial. */
681
+ interface AgentModelGroup {
682
+ id: string;
683
+ name: string;
684
+ type: CredentialAccessType;
685
+ models: AgentModelOption[];
686
+ }
687
+ /** Retorno de manageAgentCredentialMitra({ action: 'list_models' }). */
688
+ interface ListAgentModelsResult {
689
+ providers: AgentModelGroup[];
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
+ }
648
712
  /**
649
713
  * Opções de baixo nível (RPC direto) de `manageAgentCredentialMitra`. Campos
650
714
  * extras (key, code, codeVerifier, redirectUri, pollId, accessToken,
@@ -653,8 +717,8 @@ type CredentialAction = 'connect' | 'status' | 'remove' | 'list' | 'validate' |
653
717
  * NÃO use com action='connect' — para isso use ConnectAgentCredentialOptions.
654
718
  */
655
719
  interface ManageAgentCredentialOptions {
656
- action: Exclude<CredentialAction, 'connect'>;
657
- /** Obrigatório exceto para action='list'. */
720
+ action: Exclude<CredentialAction, 'connect' | 'auth'>;
721
+ /** Obrigatório exceto para action='list' / 'list_models'. */
658
722
  target?: CredentialTarget;
659
723
  /** Para `save` / `validate` de API key. */
660
724
  key?: string;
@@ -686,46 +750,54 @@ interface AgentSubscriptionAccount {
686
750
  * Orquestra o fluxo OAuth/device ponta-a-ponta no browser (abre popup, espera
687
751
  * autorização, troca por tokens server-side).
688
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;
689
783
  interface ConnectAgentCredentialOptions {
690
784
  action: 'connect';
691
- target: AgentSubscriptionTarget;
692
- /**
693
- * Callback que retorna o código que o usuário copiou da página da Anthropic
694
- * após autorizar. **Obrigatório** para target='claude'.
695
- */
696
- onCodeNeeded?: (info: {
697
- authUrl: string;
698
- state: string;
699
- }) => Promise<string> | string;
700
- /**
701
- * URL no domínio do app publicado que captura o `?code=` da OAuth e faz
702
- * `window.opener.postMessage({ mitraOpenAICode: code }, '*')`.
703
- * **Obrigatório** para target='openai_oauth'.
704
- */
705
- redirectUri?: string;
706
- /** Timeout esperando o postMessage (default 5min). */
707
- messageTimeoutMs?: number;
708
- /**
709
- * Callback opcional que recebe o `userCode` e `verificationUrl` assim que
710
- * o device flow inicia (use pra exibir na UI além do popup automático).
711
- */
712
- onDeviceCode?: (info: {
713
- userCode: string | null;
714
- verificationUrl: string | null;
715
- }) => 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;
716
792
  /** Intervalo de poll do device flow (default 2000ms). */
717
793
  pollIntervalMs?: number;
718
794
  /** Timeout total do device flow (default 15min). */
719
795
  deviceTimeoutMs?: number;
720
- /** Nome da window do popup (default depende do target). */
721
- windowName?: string;
722
- /** `features` string passada para `window.open`. */
723
- windowFeatures?: string;
724
796
  }
725
797
  interface ConnectAgentSubscriptionResult {
726
- target: AgentSubscriptionTarget;
798
+ target: ConnectableSubscriptionTarget;
727
799
  success: boolean;
728
- /** Presente em claude / openai_oauth (epoch ms). */
800
+ /** Presente em claude (epoch ms). */
729
801
  expiresAt?: number;
730
802
  /** Presente apenas em claude. */
731
803
  account?: AgentSubscriptionAccount | null;
@@ -942,48 +1014,48 @@ declare function getAgentTaskMitra(options: GetAgentTaskOptions): AgentTaskSessi
942
1014
  * Função ÚNICA `manageAgentCredentialMitra` sobre /sdk-ws para todas as
943
1015
  * operações de credencial do agente:
944
1016
  * - API keys (8 providers: anthropic, openai, gemini, kimi, minimax, glm, qwen, openrouter)
945
- * - Subscriptions OAuth (Claude / OpenAI / Codex device flow)
1017
+ * - Subscriptions OAuth (Claude paste-código / OpenAI device flow via Codex)
946
1018
  *
947
1019
  * Actions de baixo nível (RPC direto contra o backend):
948
- * status | remove | list | validate | save
1020
+ * status | remove | list | list_models | validate | save
949
1021
  * oauth_start | oauth_exchange | device_start | device_poll | device_cancel
950
1022
  *
951
- * Action de alto nível (orquestra o fluxo ponta-a-ponta no browser):
952
- * 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 });
953
1038
  *
954
1039
  * SEGURANÇA: o token de subscription NUNCA volta cru pro cliente. É salvo
955
- * server-side (Firestore) e injetado no sandbox E2B direto de lá. O retorno
956
- * de `connect`/`oauth_exchange` traz só { connected, expiresAt, account }.
1040
+ * server-side (Firestore) e injetado no sandbox E2B direto de lá.
957
1041
  */
958
1042
 
959
1043
  /**
960
- * Conecta uma subscription ponta-a-ponta (abre popup, espera autorização,
961
- * troca por tokens). Retorno tipado: { target, success, expiresAt?, account? }.
962
- *
963
- * @example
964
- * // Claude — caller mostra modal pedindo o paste do código
965
- * await manageAgentCredentialMitra({
966
- * action: 'connect', target: 'claude',
967
- * onCodeNeeded: async () => prompt('Cole o código:') ?? ''
968
- * });
969
- *
970
- * @example
971
- * // OpenAI — callback page no domínio do app faz postMessage
972
- * await manageAgentCredentialMitra({
973
- * action: 'connect', target: 'openai_oauth',
974
- * redirectUri: window.location.origin + '/auth/openai-callback'
975
- * });
976
- *
977
- * @example
978
- * // Codex — device flow automático (abre verificação, polling)
979
- * 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)
980
1051
  */
981
1052
  declare function manageAgentCredentialMitra(options: ConnectAgentCredentialOptions): Promise<ConnectAgentSubscriptionResult>;
982
1053
  /**
983
- * RPC direto contra o backend. Retorno depende de (action, target) — veja docs.
1054
+ * RPC direto contra o backend. Retorno depende de (action, target).
984
1055
  *
985
1056
  * @example
986
1057
  * await manageAgentCredentialMitra({ action: 'list' });
1058
+ * await manageAgentCredentialMitra({ action: 'list_models' });
987
1059
  * await manageAgentCredentialMitra({ action: 'status', target: 'anthropic' });
988
1060
  * await manageAgentCredentialMitra({ action: 'validate', target: 'openai', key: 'sk-...' });
989
1061
  * await manageAgentCredentialMitra({ action: 'save', target: 'glm', key: '...' });
@@ -1146,4 +1218,4 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1146
1218
  */
1147
1219
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1148
1220
 
1149
- export { type AgentApiKeyTarget, type AgentChat, type AgentDeltaEvent, type AgentErrorEvent, type AgentMessage, 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 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 };