mitra-interactions-sdk 1.0.65 → 1.0.67

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
@@ -290,7 +290,15 @@ interface UploadFileResponse {
290
290
  status: string;
291
291
  result: {
292
292
  fileName: string;
293
+ /** No PUBLIC é a URL completa; no PRIVATE/LOADABLE é a chave relativa. Prefira `key`. */
293
294
  currentPath: string;
295
+ /**
296
+ * Chave relativa do objeto. No PRIVATE: `ai-files/private/{24 chars aleatórios}/nome` — não é
297
+ * adivinhável e dois uploads com o mesmo nome não se sobrescrevem. Guarde-a na tabela da
298
+ * aplicação, na linha do registro dono; é ela que a Server Function usa para liberar o
299
+ * arquivo. (Backends anteriores ao TKT-000a0394 não a enviam.)
300
+ */
301
+ key?: string;
294
302
  publicUrl: string | null;
295
303
  message: string;
296
304
  };
@@ -298,20 +306,59 @@ interface UploadFileResponse {
298
306
  interface DownloadFileOptions {
299
307
  /** ID do projeto (opcional se já configurado via configureSdkMitra) */
300
308
  projectId?: number;
301
- /** Chave do arquivo (o `result.currentPath` retornado no upload) */
309
+ /**
310
+ * Chave do arquivo: `result.key` do upload (`ai-files/private/{aleatório}/nome`, ou
311
+ * `ai-files/{public|loadable}/nome`). Também aceita `result.currentPath`, inclusive a URL
312
+ * pública de um upload PUBLIC do mesmo projeto. Chave fora dessas pastas é recusada com 400.
313
+ *
314
+ * Permissão: só usuário DEV do projeto ou Server Function em execução. Tela de usuário final
315
+ * NÃO chama isto — pede o anexo pelo registro a uma SF (ver README, "Anexos").
316
+ */
302
317
  key: string;
303
318
  }
319
+ interface FileLinkOptions {
320
+ /** ID do projeto (opcional se já configurado via configureSdkMitra) */
321
+ projectId?: number;
322
+ /** Chave do arquivo — mesma regra de `DownloadFileOptions.key` */
323
+ key: string;
324
+ /** Validade em segundos (padrão 300 no backend; máximo configurado no backend, 3600 por padrão) */
325
+ ttlSeconds?: number;
326
+ }
327
+ /**
328
+ * Sucesso: `{ status: "success", result }`. Erro: `{ status: "error", error: { code, message } }`
329
+ * com HTTP 400 (INVALID_KEY/MISSING_*), 403 (ACCESS_DENIED), 404 (FILE_NOT_FOUND), 500.
330
+ */
331
+ interface FileLinkResponse {
332
+ status: string;
333
+ result?: {
334
+ key: string;
335
+ /** URL assinada; vale até `expiresAt` */
336
+ url: string;
337
+ expiresAt: string;
338
+ expiresInSeconds: number;
339
+ };
340
+ error?: {
341
+ code: string;
342
+ message: string;
343
+ };
344
+ }
304
345
  interface DeleteFileOptions {
305
346
  /** ID do projeto (opcional se já configurado via configureSdkMitra) */
306
347
  projectId?: number;
307
- /** Chave do arquivo (o `result.currentPath` retornado no upload) */
348
+ /** Chave do arquivo — mesma regra de `DownloadFileOptions.key`. Exclui exatamente um objeto. */
308
349
  key: string;
309
350
  }
351
+ /**
352
+ * Sucesso: `{ status: "success", result }`. Erro: `{ status: "error", error: { code, message } }`
353
+ * com code MISSING_KEY | INVALID_KEY | ACCESS_DENIED (usuário sem perfil DEV no projeto ou API key
354
+ * BUSINESS) | FILE_NOT_FOUND (nada apagado) | INTERNAL_ERROR.
355
+ */
310
356
  interface DeleteFileResponse {
311
357
  status: string;
312
358
  result: {
313
359
  fileName: string;
314
360
  currentPath: string;
361
+ key?: string;
315
362
  publicUrl: string | null;
316
363
  message: string;
317
364
  };
@@ -916,6 +963,7 @@ interface MitraInstance {
916
963
  uploadFilePrivate(options: UploadFileOptions): Promise<UploadFileResponse>;
917
964
  uploadFileLoadable(options: UploadFileOptions): Promise<UploadFileResponse>;
918
965
  downloadFilePrivate(options: DownloadFileOptions): Promise<Blob>;
966
+ getFileLink(options: FileLinkOptions): Promise<FileLinkResponse>;
919
967
  deleteFile(options: DeleteFileOptions): Promise<DeleteFileResponse>;
920
968
  listIntegrations(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
921
969
  callIntegration(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
@@ -1271,19 +1319,30 @@ declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<Up
1271
1319
  * POST /interactions/uploadFilePrivate (multipart/form-data)
1272
1320
  * Faz upload de um arquivo para a pasta PRIVATE do projeto. O arquivo NAO fica publico
1273
1321
  * no S3 (sem ACL public-read) — este e o modo recomendado/padrao. O acesso e feito por
1274
- * download autenticado; use `result.currentPath` (a chave) para baixar ou excluir depois.
1275
- * `result.publicUrl` sempre vem `null` para upload privado.
1322
+ * download autenticado; guarde `result.key` (a chave relativa) para baixar ou excluir depois.
1323
+ * `result.publicUrl` sempre vem `null` para upload privado. Privado e por PROJETO, nao por
1324
+ * usuario: qualquer usuario do projeto que conheca a chave consegue baixar.
1276
1325
  */
1277
1326
  declare function uploadFilePrivateMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
1278
1327
  /**
1279
1328
  * GET /interactions/downloadFile
1280
- * Baixa (com credencial) um arquivo privado do projeto e retorna o conteúdo como Blob.
1281
- * `key` é a chave retornada no upload (`result.currentPath`).
1329
+ * Baixa (com credencial) um arquivo do projeto e retorna o conteúdo como Blob.
1330
+ * `key` é a chave retornada no upload (`result.key`; `result.currentPath` também é aceito).
1331
+ * Permissão: usuário DEV do projeto ou Server Function em execução (403 para usuário final).
1282
1332
  */
1283
1333
  declare function downloadFilePrivateMitra(options: DownloadFileOptions): Promise<Blob>;
1334
+ /**
1335
+ * GET /interactions/fileLink
1336
+ * Link temporário (assinado) para um arquivo do projeto. Mesma permissão do download: DEV ou
1337
+ * Server Function em execução. Use quando precisar exibir muitas imagens numa tela de DEV ou em
1338
+ * ferramental; para usuário final, a SF é quem emite o link depois de validar o registro.
1339
+ */
1340
+ declare function getFileLinkMitra(options: FileLinkOptions): Promise<FileLinkResponse>;
1284
1341
  /**
1285
1342
  * DELETE /interactions/deleteFile
1286
- * Exclui um arquivo do projeto pela `key` (`result.currentPath` do upload).
1343
+ * Exclui exatamente um arquivo do projeto pela `key` (`result.key` do upload).
1344
+ * Permissão: usuário DEV do projeto ou Server Function em execução (403 para usuário final);
1345
+ * chave inexistente devolve FILE_NOT_FOUND (HTTP 404).
1287
1346
  */
1288
1347
  declare function deleteFileMitra(options: DeleteFileOptions): Promise<DeleteFileResponse>;
1289
1348
  declare function listRecordsMitra(options: ListRecordsOptions): Promise<ListRecordsResponse>;
@@ -1349,4 +1408,27 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1349
1408
  */
1350
1409
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1351
1410
 
1352
- export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, 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 ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, 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 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 ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, 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, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
1411
+ /**
1412
+ * Prova de execução de Server Function (TKT-ecc38de6 / TKT-000a0394).
1413
+ *
1414
+ * O contrato de anexos privados manda a tela de usuário final pedir o arquivo a uma Server
1415
+ * Function, que valida o registro dono e só então pede o link/download ao backend. O backend
1416
+ * libera o acesso por chave quando a requisição traz o header `X-SF-Execution-Token` — um token
1417
+ * assinado que SÓ o sandbox da execução recebe, como variável de ambiente
1418
+ * `MITRA_SF_EXECUTION_TOKEN`. Até aqui nenhuma SDK repassava esse token, então o caminho não
1419
+ * funcionava e quem precisava de tela com anexo caía no upload público.
1420
+ *
1421
+ * Regras:
1422
+ * - só em Node (sem `window`): no navegador a variável não existe e o header nunca deve sair;
1423
+ * - só quando a variável está preenchida; vazio/ausente = nada muda;
1424
+ * - só para o backend principal (baseURL). O serviço de integrações não recebe a prova.
1425
+ */
1426
+ declare const SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
1427
+ declare const SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
1428
+ type EnvLike = Record<string, string | undefined> | undefined;
1429
+ /**
1430
+ * Token de prova da execução corrente, ou null quando não estamos dentro de uma Server Function.
1431
+ */
1432
+ declare function readServerFunctionProof(env?: EnvLike, hasWindow?: boolean): string | null;
1433
+
1434
+ export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, 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 ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteFileOptions, type DeleteFileResponse, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type DownloadFileOptions, 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 FileLinkOptions, type FileLinkResponse, 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 ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, SF_EXECUTION_TOKEN_ENV, SF_EXECUTION_TOKEN_HEADER, 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, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getFileLinkMitra, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, readServerFunctionProof, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
package/dist/index.d.ts CHANGED
@@ -290,7 +290,15 @@ interface UploadFileResponse {
290
290
  status: string;
291
291
  result: {
292
292
  fileName: string;
293
+ /** No PUBLIC é a URL completa; no PRIVATE/LOADABLE é a chave relativa. Prefira `key`. */
293
294
  currentPath: string;
295
+ /**
296
+ * Chave relativa do objeto. No PRIVATE: `ai-files/private/{24 chars aleatórios}/nome` — não é
297
+ * adivinhável e dois uploads com o mesmo nome não se sobrescrevem. Guarde-a na tabela da
298
+ * aplicação, na linha do registro dono; é ela que a Server Function usa para liberar o
299
+ * arquivo. (Backends anteriores ao TKT-000a0394 não a enviam.)
300
+ */
301
+ key?: string;
294
302
  publicUrl: string | null;
295
303
  message: string;
296
304
  };
@@ -298,20 +306,59 @@ interface UploadFileResponse {
298
306
  interface DownloadFileOptions {
299
307
  /** ID do projeto (opcional se já configurado via configureSdkMitra) */
300
308
  projectId?: number;
301
- /** Chave do arquivo (o `result.currentPath` retornado no upload) */
309
+ /**
310
+ * Chave do arquivo: `result.key` do upload (`ai-files/private/{aleatório}/nome`, ou
311
+ * `ai-files/{public|loadable}/nome`). Também aceita `result.currentPath`, inclusive a URL
312
+ * pública de um upload PUBLIC do mesmo projeto. Chave fora dessas pastas é recusada com 400.
313
+ *
314
+ * Permissão: só usuário DEV do projeto ou Server Function em execução. Tela de usuário final
315
+ * NÃO chama isto — pede o anexo pelo registro a uma SF (ver README, "Anexos").
316
+ */
302
317
  key: string;
303
318
  }
319
+ interface FileLinkOptions {
320
+ /** ID do projeto (opcional se já configurado via configureSdkMitra) */
321
+ projectId?: number;
322
+ /** Chave do arquivo — mesma regra de `DownloadFileOptions.key` */
323
+ key: string;
324
+ /** Validade em segundos (padrão 300 no backend; máximo configurado no backend, 3600 por padrão) */
325
+ ttlSeconds?: number;
326
+ }
327
+ /**
328
+ * Sucesso: `{ status: "success", result }`. Erro: `{ status: "error", error: { code, message } }`
329
+ * com HTTP 400 (INVALID_KEY/MISSING_*), 403 (ACCESS_DENIED), 404 (FILE_NOT_FOUND), 500.
330
+ */
331
+ interface FileLinkResponse {
332
+ status: string;
333
+ result?: {
334
+ key: string;
335
+ /** URL assinada; vale até `expiresAt` */
336
+ url: string;
337
+ expiresAt: string;
338
+ expiresInSeconds: number;
339
+ };
340
+ error?: {
341
+ code: string;
342
+ message: string;
343
+ };
344
+ }
304
345
  interface DeleteFileOptions {
305
346
  /** ID do projeto (opcional se já configurado via configureSdkMitra) */
306
347
  projectId?: number;
307
- /** Chave do arquivo (o `result.currentPath` retornado no upload) */
348
+ /** Chave do arquivo — mesma regra de `DownloadFileOptions.key`. Exclui exatamente um objeto. */
308
349
  key: string;
309
350
  }
351
+ /**
352
+ * Sucesso: `{ status: "success", result }`. Erro: `{ status: "error", error: { code, message } }`
353
+ * com code MISSING_KEY | INVALID_KEY | ACCESS_DENIED (usuário sem perfil DEV no projeto ou API key
354
+ * BUSINESS) | FILE_NOT_FOUND (nada apagado) | INTERNAL_ERROR.
355
+ */
310
356
  interface DeleteFileResponse {
311
357
  status: string;
312
358
  result: {
313
359
  fileName: string;
314
360
  currentPath: string;
361
+ key?: string;
315
362
  publicUrl: string | null;
316
363
  message: string;
317
364
  };
@@ -916,6 +963,7 @@ interface MitraInstance {
916
963
  uploadFilePrivate(options: UploadFileOptions): Promise<UploadFileResponse>;
917
964
  uploadFileLoadable(options: UploadFileOptions): Promise<UploadFileResponse>;
918
965
  downloadFilePrivate(options: DownloadFileOptions): Promise<Blob>;
966
+ getFileLink(options: FileLinkOptions): Promise<FileLinkResponse>;
919
967
  deleteFile(options: DeleteFileOptions): Promise<DeleteFileResponse>;
920
968
  listIntegrations(options?: ListIntegrationsOptions): Promise<IntegrationResponse[]>;
921
969
  callIntegration(options: CallIntegrationOptions): Promise<CallIntegrationResponse>;
@@ -1271,19 +1319,30 @@ declare function uploadFileLoadableMitra(options: UploadFileOptions): Promise<Up
1271
1319
  * POST /interactions/uploadFilePrivate (multipart/form-data)
1272
1320
  * Faz upload de um arquivo para a pasta PRIVATE do projeto. O arquivo NAO fica publico
1273
1321
  * no S3 (sem ACL public-read) — este e o modo recomendado/padrao. O acesso e feito por
1274
- * download autenticado; use `result.currentPath` (a chave) para baixar ou excluir depois.
1275
- * `result.publicUrl` sempre vem `null` para upload privado.
1322
+ * download autenticado; guarde `result.key` (a chave relativa) para baixar ou excluir depois.
1323
+ * `result.publicUrl` sempre vem `null` para upload privado. Privado e por PROJETO, nao por
1324
+ * usuario: qualquer usuario do projeto que conheca a chave consegue baixar.
1276
1325
  */
1277
1326
  declare function uploadFilePrivateMitra(options: UploadFileOptions): Promise<UploadFileResponse>;
1278
1327
  /**
1279
1328
  * GET /interactions/downloadFile
1280
- * Baixa (com credencial) um arquivo privado do projeto e retorna o conteúdo como Blob.
1281
- * `key` é a chave retornada no upload (`result.currentPath`).
1329
+ * Baixa (com credencial) um arquivo do projeto e retorna o conteúdo como Blob.
1330
+ * `key` é a chave retornada no upload (`result.key`; `result.currentPath` também é aceito).
1331
+ * Permissão: usuário DEV do projeto ou Server Function em execução (403 para usuário final).
1282
1332
  */
1283
1333
  declare function downloadFilePrivateMitra(options: DownloadFileOptions): Promise<Blob>;
1334
+ /**
1335
+ * GET /interactions/fileLink
1336
+ * Link temporário (assinado) para um arquivo do projeto. Mesma permissão do download: DEV ou
1337
+ * Server Function em execução. Use quando precisar exibir muitas imagens numa tela de DEV ou em
1338
+ * ferramental; para usuário final, a SF é quem emite o link depois de validar o registro.
1339
+ */
1340
+ declare function getFileLinkMitra(options: FileLinkOptions): Promise<FileLinkResponse>;
1284
1341
  /**
1285
1342
  * DELETE /interactions/deleteFile
1286
- * Exclui um arquivo do projeto pela `key` (`result.currentPath` do upload).
1343
+ * Exclui exatamente um arquivo do projeto pela `key` (`result.key` do upload).
1344
+ * Permissão: usuário DEV do projeto ou Server Function em execução (403 para usuário final);
1345
+ * chave inexistente devolve FILE_NOT_FOUND (HTTP 404).
1287
1346
  */
1288
1347
  declare function deleteFileMitra(options: DeleteFileOptions): Promise<DeleteFileResponse>;
1289
1348
  declare function listRecordsMitra(options: ListRecordsOptions): Promise<ListRecordsResponse>;
@@ -1349,4 +1408,27 @@ declare function setProfileScreensMitra(options: SetProfileScreensOptions): Prom
1349
1408
  */
1350
1409
  declare function setProfileServerFunctionsMitra(options: SetProfileServerFunctionsOptions): Promise<SetProfilePermissionResponse>;
1351
1410
 
1352
- export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, 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 ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, 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 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 ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, 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, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
1411
+ /**
1412
+ * Prova de execução de Server Function (TKT-ecc38de6 / TKT-000a0394).
1413
+ *
1414
+ * O contrato de anexos privados manda a tela de usuário final pedir o arquivo a uma Server
1415
+ * Function, que valida o registro dono e só então pede o link/download ao backend. O backend
1416
+ * libera o acesso por chave quando a requisição traz o header `X-SF-Execution-Token` — um token
1417
+ * assinado que SÓ o sandbox da execução recebe, como variável de ambiente
1418
+ * `MITRA_SF_EXECUTION_TOKEN`. Até aqui nenhuma SDK repassava esse token, então o caminho não
1419
+ * funcionava e quem precisava de tela com anexo caía no upload público.
1420
+ *
1421
+ * Regras:
1422
+ * - só em Node (sem `window`): no navegador a variável não existe e o header nunca deve sair;
1423
+ * - só quando a variável está preenchida; vazio/ausente = nada muda;
1424
+ * - só para o backend principal (baseURL). O serviço de integrações não recebe a prova.
1425
+ */
1426
+ declare const SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
1427
+ declare const SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
1428
+ type EnvLike = Record<string, string | undefined> | undefined;
1429
+ /**
1430
+ * Token de prova da execução corrente, ou null quando não estamos dentro de uma Server Function.
1431
+ */
1432
+ declare function readServerFunctionProof(env?: EnvLike, hasWindow?: boolean): string | null;
1433
+
1434
+ export { type AgentApiKeyTarget, type AgentAttachment, type AgentAttachmentType, 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 ChatManageAction, type ConnectAgentCredentialOptions, type ConnectAgentSubscriptionResult, type ConnectableSubscriptionTarget, type CreateProfileOptions, type CreateProfileResponse, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAccessType, type CredentialAction, type CredentialTarget, type DeleteAgentChatResult, type DeleteFileOptions, type DeleteFileResponse, type DeleteProfileOptions, type DeleteProfileResponse, type DeleteRecordOptions, type DownloadFileOptions, 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 FileLinkOptions, type FileLinkResponse, 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 ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type ManageAgentCredentialResult, type MitraConfig, type MitraInstance, type PatchRecordOptions, type ProfileTableRef, type QueuedItem, type RenameAgentChatResult, type ResetPasswordOptions, type RunActionOptions, type RunActionResponse, SF_EXECUTION_TOKEN_ENV, SF_EXECUTION_TOKEN_HEADER, 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, deleteFileMitra, deleteProfileMitra, deleteRecordMitra, downloadFilePrivateMitra, emailLoginMitra, emailResendCodeMitra, emailSignupMitra, emailVerifyCodeMitra, executeDataLoaderMitra, executeDbActionMitra, executePublicServerFunctionAsyncMitra, executePublicServerFunctionMitra, executeServerFunctionAsyncMitra, executeServerFunctionMitra, getAgentTaskMitra, getConfig, getFileLinkMitra, getProfileDetailsMitra, getPublicServerFunctionExecutionMitra, getRecordMitra, getVariableMitra, listIntegrationsMitra, listProfilesMitra, listRecordsMitra, listVariablesMitra, loginMitra, loginWithEmailMitra, loginWithGoogleMitra, loginWithMicrosoftMitra, manageAgentChatMitra, manageAgentCredentialMitra, openChatMitra, patchRecordMitra, readServerFunctionProof, refreshTokenSilently, resetPasswordMitra, resolveProjectId, runActionMitra, sendPasswordResetCodeMitra, setFileStatusMitra, setProfileActionsMitra, setProfileDmlTablesMitra, setProfileScreensMitra, setProfileSelectTablesMitra, setProfileServerFunctionsMitra, setProfileUsersMitra, setVariableMitra, stopServerFunctionExecutionMitra, updateProfileMitra, updateRecordMitra, uploadFileLoadableMitra, uploadFilePrivateMitra, uploadFilePublicMitra, validatePasswordResetCodeMitra };
package/dist/index.js CHANGED
@@ -361,6 +361,28 @@ async function resetPasswordMitra(options) {
361
361
  });
362
362
  }
363
363
 
364
+ // src/sf-proof.ts
365
+ var SF_EXECUTION_TOKEN_ENV = "MITRA_SF_EXECUTION_TOKEN";
366
+ var SF_EXECUTION_TOKEN_HEADER = "X-SF-Execution-Token";
367
+ function defaultEnv() {
368
+ const proc = globalThis.process;
369
+ return proc == null ? void 0 : proc.env;
370
+ }
371
+ function defaultHasWindow() {
372
+ return typeof globalThis.window !== "undefined";
373
+ }
374
+ function readServerFunctionProof(env = defaultEnv(), hasWindow = defaultHasWindow()) {
375
+ if (hasWindow) return null;
376
+ const raw = env == null ? void 0 : env[SF_EXECUTION_TOKEN_ENV];
377
+ if (typeof raw !== "string") return null;
378
+ const token = raw.trim();
379
+ return token.length > 0 ? token : null;
380
+ }
381
+ function withServerFunctionProof(headers, proof = readServerFunctionProof()) {
382
+ if (!proof) return headers;
383
+ return { ...headers, [SF_EXECUTION_TOKEN_HEADER]: proof };
384
+ }
385
+
364
386
  // src/client.ts
365
387
  function getFetch2() {
366
388
  if (typeof globalThis.fetch === "function") {
@@ -375,7 +397,7 @@ function buildHeaders() {
375
397
  const config = getConfig();
376
398
  const headers = { "Content-Type": "application/json" };
377
399
  if (config.token) headers["Authorization"] = formatToken(config.token);
378
- return headers;
400
+ return withServerFunctionProof(headers);
379
401
  }
380
402
  function buildUrl(endpoint, params) {
381
403
  const config = getConfig();
@@ -483,7 +505,7 @@ var http = {
483
505
  if (config.token) headers["Authorization"] = formatToken(config.token);
484
506
  return fetchWithRefresh(buildUrl(endpoint), {
485
507
  method: "POST",
486
- headers,
508
+ headers: withServerFunctionProof(headers),
487
509
  body: formData
488
510
  });
489
511
  },
@@ -724,6 +746,13 @@ async function downloadFilePrivateMitra(options) {
724
746
  key: options.key
725
747
  });
726
748
  }
749
+ async function getFileLinkMitra(options) {
750
+ return http.get("/interactions/fileLink", {
751
+ projectId: resolveProjectId2(options.projectId),
752
+ key: options.key,
753
+ ...options.ttlSeconds !== void 0 ? { ttlSeconds: options.ttlSeconds } : {}
754
+ });
755
+ }
727
756
  async function deleteFileMitra(options) {
728
757
  return http.del("/interactions/deleteFile", {
729
758
  projectId: resolveProjectId2(options.projectId),
@@ -2069,6 +2098,15 @@ function createMitraInstance(initialConfig) {
2069
2098
  key: options.key
2070
2099
  });
2071
2100
  },
2101
+ async getFileLink(options) {
2102
+ return request("GET", "/interactions/fileLink", {
2103
+ params: {
2104
+ projectId: resolveProjectId4(options.projectId),
2105
+ key: options.key,
2106
+ ...options.ttlSeconds !== void 0 ? { ttlSeconds: options.ttlSeconds } : {}
2107
+ }
2108
+ });
2109
+ },
2072
2110
  async deleteFile(options) {
2073
2111
  return request("DELETE", "/interactions/deleteFile", {
2074
2112
  params: { projectId: resolveProjectId4(options.projectId), key: options.key }
@@ -2294,6 +2332,8 @@ function resolveProjectId2(projectId) {
2294
2332
  throw new Error("projectId \xE9 obrigat\xF3rio. Passe nas options ou configure via configureSdkMitra({ projectId }).");
2295
2333
  }
2296
2334
 
2335
+ exports.SF_EXECUTION_TOKEN_ENV = SF_EXECUTION_TOKEN_ENV;
2336
+ exports.SF_EXECUTION_TOKEN_HEADER = SF_EXECUTION_TOKEN_HEADER;
2297
2337
  exports.callIntegrationMitra = callIntegrationMitra;
2298
2338
  exports.closeChatMitra = closeChatMitra;
2299
2339
  exports.configureSdkMitra = configureSdkMitra;
@@ -2317,6 +2357,7 @@ exports.executeServerFunctionAsyncMitra = executeServerFunctionAsyncMitra;
2317
2357
  exports.executeServerFunctionMitra = executeServerFunctionMitra;
2318
2358
  exports.getAgentTaskMitra = getAgentTaskMitra;
2319
2359
  exports.getConfig = getConfig;
2360
+ exports.getFileLinkMitra = getFileLinkMitra;
2320
2361
  exports.getProfileDetailsMitra = getProfileDetailsMitra;
2321
2362
  exports.getPublicServerFunctionExecutionMitra = getPublicServerFunctionExecutionMitra;
2322
2363
  exports.getRecordMitra = getRecordMitra;
@@ -2333,6 +2374,7 @@ exports.manageAgentChatMitra = manageAgentChatMitra;
2333
2374
  exports.manageAgentCredentialMitra = manageAgentCredentialMitra;
2334
2375
  exports.openChatMitra = openChatMitra;
2335
2376
  exports.patchRecordMitra = patchRecordMitra;
2377
+ exports.readServerFunctionProof = readServerFunctionProof;
2336
2378
  exports.refreshTokenSilently = refreshTokenSilently;
2337
2379
  exports.resetPasswordMitra = resetPasswordMitra;
2338
2380
  exports.resolveProjectId = resolveProjectId2;