@ragable/sdk 0.7.8 → 0.7.9

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
@@ -1794,6 +1794,99 @@ declare class RagableBrowserStorageClient {
1794
1794
  constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch);
1795
1795
  from(bucketId: string): BrowserStorageBucketClient;
1796
1796
  }
1797
+ interface MailSendParams {
1798
+ to: string[];
1799
+ cc?: string[];
1800
+ bcc?: string[];
1801
+ subject: string;
1802
+ /** Plain-text body. At least one of `bodyText` / `bodyHtml` is required. */
1803
+ bodyText?: string;
1804
+ /** HTML body. If both are set, sent as multipart/alternative. */
1805
+ bodyHtml?: string;
1806
+ /** RFC 822 Message-ID of the message you're replying to (enables threading). */
1807
+ inReplyToMessageId?: string;
1808
+ /** Existing References header value, chained with In-Reply-To. */
1809
+ referencesHeader?: string;
1810
+ }
1811
+ interface MailSendResult {
1812
+ sentMailMessageId: string;
1813
+ gmailMessageId: string;
1814
+ gmailThreadId: string;
1815
+ fromAddress: string;
1816
+ }
1817
+ interface MailSearchParams {
1818
+ /** Gmail search syntax, e.g. `from:alice is:unread newer_than:7d`. */
1819
+ query?: string;
1820
+ /** 1–50; default 20. */
1821
+ maxResults?: number;
1822
+ pageToken?: string;
1823
+ labelIds?: string[];
1824
+ }
1825
+ interface MailMessagePreview {
1826
+ id: string;
1827
+ threadId: string;
1828
+ snippet: string;
1829
+ labelIds: string[];
1830
+ }
1831
+ interface MailMessageDetail {
1832
+ id: string;
1833
+ threadId: string;
1834
+ receivedAt: number;
1835
+ fromAddress: string;
1836
+ fromName: string | null;
1837
+ to: string[];
1838
+ cc: string[];
1839
+ subject: string;
1840
+ snippet: string;
1841
+ bodyText: string | null;
1842
+ bodyHtml: string | null;
1843
+ messageIdHeader: string | null;
1844
+ referencesHeader: string | null;
1845
+ labelIds: string[];
1846
+ }
1847
+ /**
1848
+ * Send and read email through the Gmail account linked to this Ragable
1849
+ * website (via the IDE Infrastructure → Integrations tab).
1850
+ *
1851
+ * All requests require a Bearer token — either an end-user JWT from this
1852
+ * website's auth group (call `client.auth.signIn(...)` first) or the
1853
+ * data-admin key (server-side use).
1854
+ *
1855
+ * The website MUST have:
1856
+ * 1. A Gmail account linked under Integrations
1857
+ * 2. An auth group linked under Auth
1858
+ *
1859
+ * Otherwise calls return a 412 with a clear error message.
1860
+ */
1861
+ declare class RagableBrowserMailClient {
1862
+ private readonly options;
1863
+ private readonly auth;
1864
+ private readonly fetchImpl;
1865
+ constructor(options: RagableBrowserClientOptions, auth: RagableAuth | null);
1866
+ private requireWebsiteId;
1867
+ private pathTo;
1868
+ /**
1869
+ * Get the Bearer token used to authenticate the call:
1870
+ * 1. End-user access token (preferred when an auth group is configured
1871
+ * and the user has signed in)
1872
+ * 2. `dataStaticKey` from createBrowserClient options
1873
+ * 3. Caller-supplied `getAccessToken()`
1874
+ *
1875
+ * If none is available, throws — server-side use should pass the
1876
+ * data-admin key as `dataStaticKey`.
1877
+ */
1878
+ private getBearerToken;
1879
+ private request;
1880
+ /** Send an email from this website's linked Gmail account. */
1881
+ send(params: MailSendParams): Promise<MailSendResult>;
1882
+ /** Search messages with Gmail query syntax. */
1883
+ search(params?: MailSearchParams): Promise<{
1884
+ messages: MailMessagePreview[];
1885
+ nextPageToken: string | null;
1886
+ }>;
1887
+ /** Fetch a single message in full (headers + decoded text/html body). */
1888
+ getMessage(messageId: string): Promise<MailMessageDetail>;
1889
+ }
1797
1890
  interface AgentConversationMessage {
1798
1891
  role: "user" | "assistant";
1799
1892
  content: string;
@@ -1933,6 +2026,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1933
2026
  readonly database: RagableBrowserDatabaseClient<Database>;
1934
2027
  readonly db: RagableBrowserDatabaseClient<Database>;
1935
2028
  readonly storage: RagableBrowserStorageClient;
2029
+ readonly mail: RagableBrowserMailClient;
1936
2030
  readonly transport: Transport;
1937
2031
  private readonly _ragableAuth;
1938
2032
  constructor(options: RagableBrowserClientOptions);
@@ -1973,4 +2067,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
1973
2067
 
1974
2068
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1975
2069
 
1976
- export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
2070
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
package/dist/index.d.ts CHANGED
@@ -1794,6 +1794,99 @@ declare class RagableBrowserStorageClient {
1794
1794
  constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch);
1795
1795
  from(bucketId: string): BrowserStorageBucketClient;
1796
1796
  }
1797
+ interface MailSendParams {
1798
+ to: string[];
1799
+ cc?: string[];
1800
+ bcc?: string[];
1801
+ subject: string;
1802
+ /** Plain-text body. At least one of `bodyText` / `bodyHtml` is required. */
1803
+ bodyText?: string;
1804
+ /** HTML body. If both are set, sent as multipart/alternative. */
1805
+ bodyHtml?: string;
1806
+ /** RFC 822 Message-ID of the message you're replying to (enables threading). */
1807
+ inReplyToMessageId?: string;
1808
+ /** Existing References header value, chained with In-Reply-To. */
1809
+ referencesHeader?: string;
1810
+ }
1811
+ interface MailSendResult {
1812
+ sentMailMessageId: string;
1813
+ gmailMessageId: string;
1814
+ gmailThreadId: string;
1815
+ fromAddress: string;
1816
+ }
1817
+ interface MailSearchParams {
1818
+ /** Gmail search syntax, e.g. `from:alice is:unread newer_than:7d`. */
1819
+ query?: string;
1820
+ /** 1–50; default 20. */
1821
+ maxResults?: number;
1822
+ pageToken?: string;
1823
+ labelIds?: string[];
1824
+ }
1825
+ interface MailMessagePreview {
1826
+ id: string;
1827
+ threadId: string;
1828
+ snippet: string;
1829
+ labelIds: string[];
1830
+ }
1831
+ interface MailMessageDetail {
1832
+ id: string;
1833
+ threadId: string;
1834
+ receivedAt: number;
1835
+ fromAddress: string;
1836
+ fromName: string | null;
1837
+ to: string[];
1838
+ cc: string[];
1839
+ subject: string;
1840
+ snippet: string;
1841
+ bodyText: string | null;
1842
+ bodyHtml: string | null;
1843
+ messageIdHeader: string | null;
1844
+ referencesHeader: string | null;
1845
+ labelIds: string[];
1846
+ }
1847
+ /**
1848
+ * Send and read email through the Gmail account linked to this Ragable
1849
+ * website (via the IDE Infrastructure → Integrations tab).
1850
+ *
1851
+ * All requests require a Bearer token — either an end-user JWT from this
1852
+ * website's auth group (call `client.auth.signIn(...)` first) or the
1853
+ * data-admin key (server-side use).
1854
+ *
1855
+ * The website MUST have:
1856
+ * 1. A Gmail account linked under Integrations
1857
+ * 2. An auth group linked under Auth
1858
+ *
1859
+ * Otherwise calls return a 412 with a clear error message.
1860
+ */
1861
+ declare class RagableBrowserMailClient {
1862
+ private readonly options;
1863
+ private readonly auth;
1864
+ private readonly fetchImpl;
1865
+ constructor(options: RagableBrowserClientOptions, auth: RagableAuth | null);
1866
+ private requireWebsiteId;
1867
+ private pathTo;
1868
+ /**
1869
+ * Get the Bearer token used to authenticate the call:
1870
+ * 1. End-user access token (preferred when an auth group is configured
1871
+ * and the user has signed in)
1872
+ * 2. `dataStaticKey` from createBrowserClient options
1873
+ * 3. Caller-supplied `getAccessToken()`
1874
+ *
1875
+ * If none is available, throws — server-side use should pass the
1876
+ * data-admin key as `dataStaticKey`.
1877
+ */
1878
+ private getBearerToken;
1879
+ private request;
1880
+ /** Send an email from this website's linked Gmail account. */
1881
+ send(params: MailSendParams): Promise<MailSendResult>;
1882
+ /** Search messages with Gmail query syntax. */
1883
+ search(params?: MailSearchParams): Promise<{
1884
+ messages: MailMessagePreview[];
1885
+ nextPageToken: string | null;
1886
+ }>;
1887
+ /** Fetch a single message in full (headers + decoded text/html body). */
1888
+ getMessage(messageId: string): Promise<MailMessageDetail>;
1889
+ }
1797
1890
  interface AgentConversationMessage {
1798
1891
  role: "user" | "assistant";
1799
1892
  content: string;
@@ -1933,6 +2026,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1933
2026
  readonly database: RagableBrowserDatabaseClient<Database>;
1934
2027
  readonly db: RagableBrowserDatabaseClient<Database>;
1935
2028
  readonly storage: RagableBrowserStorageClient;
2029
+ readonly mail: RagableBrowserMailClient;
1936
2030
  readonly transport: Transport;
1937
2031
  private readonly _ragableAuth;
1938
2032
  constructor(options: RagableBrowserClientOptions);
@@ -1973,4 +2067,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
1973
2067
 
1974
2068
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1975
2069
 
1976
- export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
2070
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  RagableBrowserAiClient: () => RagableBrowserAiClient,
48
48
  RagableBrowserAuthClient: () => RagableBrowserAuthClient,
49
49
  RagableBrowserDatabaseClient: () => RagableBrowserDatabaseClient,
50
+ RagableBrowserMailClient: () => RagableBrowserMailClient,
50
51
  RagableBrowserStorageClient: () => RagableBrowserStorageClient,
51
52
  RagableError: () => RagableError,
52
53
  RagableNetworkError: () => RagableNetworkError,
@@ -3874,6 +3875,120 @@ var RagableBrowserStorageClient = class {
3874
3875
  return new BrowserStorageBucketClient(this.options, this.fetchImpl, bucketId);
3875
3876
  }
3876
3877
  };
3878
+ var RagableBrowserMailClient = class {
3879
+ constructor(options, auth) {
3880
+ this.options = options;
3881
+ this.auth = auth;
3882
+ __publicField(this, "fetchImpl");
3883
+ this.fetchImpl = bindFetch(options.fetch);
3884
+ }
3885
+ requireWebsiteId() {
3886
+ const websiteId = this.options.websiteId?.trim();
3887
+ if (!websiteId) {
3888
+ throw new RagableError(
3889
+ "websiteId is required for mail operations. Use createWebsiteRagableClient() or pass createBrowserClient({ websiteId, ... }).",
3890
+ 400,
3891
+ { code: "SDK_MISSING_WEBSITE_ID" }
3892
+ );
3893
+ }
3894
+ return websiteId;
3895
+ }
3896
+ pathTo(p) {
3897
+ const websiteId = this.requireWebsiteId();
3898
+ const orgId = this.options.organizationId;
3899
+ return `${normalizeBrowserApiBase()}/public/organizations/${orgId}/websites/${websiteId}/mail${p.startsWith("/") ? p : `/${p}`}`;
3900
+ }
3901
+ /**
3902
+ * Get the Bearer token used to authenticate the call:
3903
+ * 1. End-user access token (preferred when an auth group is configured
3904
+ * and the user has signed in)
3905
+ * 2. `dataStaticKey` from createBrowserClient options
3906
+ * 3. Caller-supplied `getAccessToken()`
3907
+ *
3908
+ * If none is available, throws — server-side use should pass the
3909
+ * data-admin key as `dataStaticKey`.
3910
+ */
3911
+ async getBearerToken() {
3912
+ if (this.auth) {
3913
+ const token = await this.auth.getValidAccessToken().catch(() => null);
3914
+ if (token) return token;
3915
+ }
3916
+ const callerProvided = await this.options.getAccessToken?.();
3917
+ if (typeof callerProvided === "string" && callerProvided.length > 0) {
3918
+ return callerProvided;
3919
+ }
3920
+ if (this.options.dataStaticKey?.trim()) {
3921
+ return this.options.dataStaticKey.trim();
3922
+ }
3923
+ throw new RagableError(
3924
+ "Mail requests need authentication: either sign in via client.auth.signIn(...) or pass dataStaticKey (the auth group data-admin key) when creating the client.",
3925
+ 401,
3926
+ { code: "SDK_MAIL_NOT_AUTHENTICATED" }
3927
+ );
3928
+ }
3929
+ async request(path, init = {}) {
3930
+ const token = await this.getBearerToken();
3931
+ const headers = new Headers(init.headers ?? this.options.headers);
3932
+ headers.set("Authorization", `Bearer ${token}`);
3933
+ if (init.body && !headers.has("Content-Type")) {
3934
+ headers.set("Content-Type", "application/json");
3935
+ }
3936
+ const response = await this.fetchImpl(this.pathTo(path), {
3937
+ ...init,
3938
+ headers
3939
+ });
3940
+ const payload = await parseMaybeJsonBody(response);
3941
+ if (!response.ok) {
3942
+ const message = extractErrorMessage(payload, response.statusText);
3943
+ throw new RagableError(message, response.status, payload);
3944
+ }
3945
+ return payload;
3946
+ }
3947
+ /** Send an email from this website's linked Gmail account. */
3948
+ async send(params) {
3949
+ if (!params.to?.length) {
3950
+ throw new RagableError(
3951
+ "`to` must contain at least one recipient.",
3952
+ 400,
3953
+ { code: "SDK_MAIL_NO_RECIPIENTS" }
3954
+ );
3955
+ }
3956
+ if (!params.bodyText && !params.bodyHtml) {
3957
+ throw new RagableError(
3958
+ "Provide at least one of `bodyText` or `bodyHtml`.",
3959
+ 400,
3960
+ { code: "SDK_MAIL_NO_BODY" }
3961
+ );
3962
+ }
3963
+ return this.request("/send", {
3964
+ method: "POST",
3965
+ body: JSON.stringify(params)
3966
+ });
3967
+ }
3968
+ /** Search messages with Gmail query syntax. */
3969
+ async search(params = {}) {
3970
+ const qs = new URLSearchParams();
3971
+ if (params.query) qs.set("q", params.query);
3972
+ if (params.maxResults) qs.set("maxResults", String(params.maxResults));
3973
+ if (params.pageToken) qs.set("pageToken", params.pageToken);
3974
+ if (params.labelIds?.length) qs.set("labelIds", params.labelIds.join(","));
3975
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
3976
+ return this.request(`/search${suffix}`, { method: "GET" });
3977
+ }
3978
+ /** Fetch a single message in full (headers + decoded text/html body). */
3979
+ async getMessage(messageId) {
3980
+ if (!messageId) {
3981
+ throw new RagableError("`messageId` is required.", 400, {
3982
+ code: "SDK_MAIL_NO_MESSAGE_ID"
3983
+ });
3984
+ }
3985
+ const { message } = await this.request(
3986
+ `/messages/${encodeURIComponent(messageId)}`,
3987
+ { method: "GET" }
3988
+ );
3989
+ return message;
3990
+ }
3991
+ };
3877
3992
  var RagableBrowserAgentsClient = class {
3878
3993
  constructor(options) {
3879
3994
  this.options = options;
@@ -4200,6 +4315,7 @@ var RagableBrowser = class {
4200
4315
  __publicField(this, "database");
4201
4316
  __publicField(this, "db");
4202
4317
  __publicField(this, "storage");
4318
+ __publicField(this, "mail");
4203
4319
  __publicField(this, "transport");
4204
4320
  __publicField(this, "_ragableAuth");
4205
4321
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
@@ -4245,6 +4361,7 @@ var RagableBrowser = class {
4245
4361
  this.database._setTransport(this.transport);
4246
4362
  this.db = this.database;
4247
4363
  this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
4364
+ this.mail = new RagableBrowserMailClient(options, this._ragableAuth);
4248
4365
  }
4249
4366
  destroy() {
4250
4367
  this._ragableAuth?.destroy();
@@ -4286,6 +4403,7 @@ function createClient(options) {
4286
4403
  RagableBrowserAiClient,
4287
4404
  RagableBrowserAuthClient,
4288
4405
  RagableBrowserDatabaseClient,
4406
+ RagableBrowserMailClient,
4289
4407
  RagableBrowserStorageClient,
4290
4408
  RagableError,
4291
4409
  RagableNetworkError,