@ragable/sdk 0.7.9 → 0.7.10

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
@@ -981,10 +981,53 @@ type StreamPart = {
981
981
  type: "error";
982
982
  error: unknown;
983
983
  };
984
- interface Message {
985
- role: "system" | "user" | "assistant";
986
- content: string;
984
+ /** Plain text segment inside a multimodal user message. */
985
+ interface TextPart {
986
+ type: "text";
987
+ text: string;
988
+ }
989
+ /**
990
+ * Image segment inside a multimodal user message. Mirrors Vercel AI SDK's
991
+ * `ImagePart` shape — the discriminator is `"image"` and the data field is
992
+ * `image` (not `image_url`). The SDK converts to the OpenAI `image_url`
993
+ * wire format internally.
994
+ */
995
+ interface ImagePart {
996
+ type: "image";
997
+ /**
998
+ * Accepted forms:
999
+ * - HTTP(S) URL string (`"https://…"`) — passed through; the provider fetches it.
1000
+ * - Data URL string (`"data:image/png;base64,…"`) — passed through.
1001
+ * - Raw base64 string (no `data:` prefix) — `mediaType` then required.
1002
+ * - `Uint8Array` / `ArrayBuffer` — base64-encoded; `mediaType` required.
1003
+ * - `URL` instance — `href` is passed through.
1004
+ */
1005
+ image: string | Uint8Array | ArrayBuffer | URL;
1006
+ /** IANA media type, e.g. `"image/png"`. Required when `image` is binary or a raw base64 string. */
1007
+ mediaType?: string;
1008
+ /** OpenAI-compatible detail hint; forwarded as `image_url.detail`. */
1009
+ detail?: "auto" | "low" | "high";
987
1010
  }
1011
+ /**
1012
+ * Content for a user message — either a plain string (back-compat with the
1013
+ * original text-only shape) or an array of text/image parts.
1014
+ */
1015
+ type UserContent = string | Array<TextPart | ImagePart>;
1016
+ /**
1017
+ * Chat message. `user` messages may carry multimodal content; `system` and
1018
+ * `assistant` are text-only (vision models consume images on user turns,
1019
+ * and image *output* isn't supported here).
1020
+ */
1021
+ type Message = {
1022
+ role: "system";
1023
+ content: string;
1024
+ } | {
1025
+ role: "user";
1026
+ content: UserContent;
1027
+ } | {
1028
+ role: "assistant";
1029
+ content: string;
1030
+ };
988
1031
  /**
989
1032
  * OpenAI/Fireworks SSE chunk shape, only the fields we actually consume.
990
1033
  * Kept as a local type so we don't depend on backend internals.
@@ -2049,6 +2092,45 @@ declare function parseSseDataLine(line: string): SseJsonEvent | null;
2049
2092
  */
2050
2093
  declare function readSseStream(body: ReadableStream<Uint8Array>): AsyncGenerator<SseJsonEvent, void, undefined>;
2051
2094
 
2095
+ /**
2096
+ * Convert SDK-shape multimodal content to the OpenAI/Fireworks `image_url`
2097
+ * wire format the Ragable inference proxy expects. Keeps the public SDK
2098
+ * types Vercel-AI-SDK-shaped (`{ type: "image", image: ... }`) while the
2099
+ * over-the-wire shape stays OpenAI canonical.
2100
+ */
2101
+
2102
+ /** OpenAI/Fireworks image content part — what flows on the wire. */
2103
+ interface WireImagePart {
2104
+ type: "image_url";
2105
+ image_url: {
2106
+ url: string;
2107
+ detail?: "auto" | "low" | "high";
2108
+ };
2109
+ }
2110
+ type WireTextPart = {
2111
+ type: "text";
2112
+ text: string;
2113
+ };
2114
+ type WireContentPart = WireTextPart | WireImagePart;
2115
+ type WireUserContent = string | WireContentPart[];
2116
+ /**
2117
+ * Convert a single `UserContent` value to wire shape. Strings pass through
2118
+ * unchanged so existing callers keep producing byte-identical request bodies.
2119
+ */
2120
+ declare function toWireUserContent(content: UserContent): WireUserContent;
2121
+ /**
2122
+ * Resolve an `ImagePart.image` value into a URL string suitable for
2123
+ * `image_url.url`. URLs pass through; binary and raw base64 are wrapped
2124
+ * into a data URL.
2125
+ */
2126
+ declare function imagePartToUrl(part: ImagePart): string;
2127
+ /**
2128
+ * Cross-runtime `Uint8Array → base64`. `btoa(String.fromCharCode(...bytes))`
2129
+ * trips the JS call-stack limit on large payloads, so we chunk the binary
2130
+ * string. Works in browser, Node 18+, Edge, and Bun.
2131
+ */
2132
+ declare function bytesToBase64(bytes: Uint8Array): string;
2133
+
2052
2134
  /**
2053
2135
  * Best-effort parser for incomplete JSON streamed token-by-token from an LLM.
2054
2136
  *
@@ -2067,4 +2149,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
2067
2149
 
2068
2150
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
2069
2151
 
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 };
2152
+ 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 ImagePart, 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 TextPart, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type UserContent, type WhereInput, type WhereOperatorObject, type WireContentPart, type WireImagePart, type WireTextPart, type WireUserContent, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, bytesToBase64, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, imagePartToUrl, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, toWireUserContent, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
package/dist/index.d.ts CHANGED
@@ -981,10 +981,53 @@ type StreamPart = {
981
981
  type: "error";
982
982
  error: unknown;
983
983
  };
984
- interface Message {
985
- role: "system" | "user" | "assistant";
986
- content: string;
984
+ /** Plain text segment inside a multimodal user message. */
985
+ interface TextPart {
986
+ type: "text";
987
+ text: string;
988
+ }
989
+ /**
990
+ * Image segment inside a multimodal user message. Mirrors Vercel AI SDK's
991
+ * `ImagePart` shape — the discriminator is `"image"` and the data field is
992
+ * `image` (not `image_url`). The SDK converts to the OpenAI `image_url`
993
+ * wire format internally.
994
+ */
995
+ interface ImagePart {
996
+ type: "image";
997
+ /**
998
+ * Accepted forms:
999
+ * - HTTP(S) URL string (`"https://…"`) — passed through; the provider fetches it.
1000
+ * - Data URL string (`"data:image/png;base64,…"`) — passed through.
1001
+ * - Raw base64 string (no `data:` prefix) — `mediaType` then required.
1002
+ * - `Uint8Array` / `ArrayBuffer` — base64-encoded; `mediaType` required.
1003
+ * - `URL` instance — `href` is passed through.
1004
+ */
1005
+ image: string | Uint8Array | ArrayBuffer | URL;
1006
+ /** IANA media type, e.g. `"image/png"`. Required when `image` is binary or a raw base64 string. */
1007
+ mediaType?: string;
1008
+ /** OpenAI-compatible detail hint; forwarded as `image_url.detail`. */
1009
+ detail?: "auto" | "low" | "high";
987
1010
  }
1011
+ /**
1012
+ * Content for a user message — either a plain string (back-compat with the
1013
+ * original text-only shape) or an array of text/image parts.
1014
+ */
1015
+ type UserContent = string | Array<TextPart | ImagePart>;
1016
+ /**
1017
+ * Chat message. `user` messages may carry multimodal content; `system` and
1018
+ * `assistant` are text-only (vision models consume images on user turns,
1019
+ * and image *output* isn't supported here).
1020
+ */
1021
+ type Message = {
1022
+ role: "system";
1023
+ content: string;
1024
+ } | {
1025
+ role: "user";
1026
+ content: UserContent;
1027
+ } | {
1028
+ role: "assistant";
1029
+ content: string;
1030
+ };
988
1031
  /**
989
1032
  * OpenAI/Fireworks SSE chunk shape, only the fields we actually consume.
990
1033
  * Kept as a local type so we don't depend on backend internals.
@@ -2049,6 +2092,45 @@ declare function parseSseDataLine(line: string): SseJsonEvent | null;
2049
2092
  */
2050
2093
  declare function readSseStream(body: ReadableStream<Uint8Array>): AsyncGenerator<SseJsonEvent, void, undefined>;
2051
2094
 
2095
+ /**
2096
+ * Convert SDK-shape multimodal content to the OpenAI/Fireworks `image_url`
2097
+ * wire format the Ragable inference proxy expects. Keeps the public SDK
2098
+ * types Vercel-AI-SDK-shaped (`{ type: "image", image: ... }`) while the
2099
+ * over-the-wire shape stays OpenAI canonical.
2100
+ */
2101
+
2102
+ /** OpenAI/Fireworks image content part — what flows on the wire. */
2103
+ interface WireImagePart {
2104
+ type: "image_url";
2105
+ image_url: {
2106
+ url: string;
2107
+ detail?: "auto" | "low" | "high";
2108
+ };
2109
+ }
2110
+ type WireTextPart = {
2111
+ type: "text";
2112
+ text: string;
2113
+ };
2114
+ type WireContentPart = WireTextPart | WireImagePart;
2115
+ type WireUserContent = string | WireContentPart[];
2116
+ /**
2117
+ * Convert a single `UserContent` value to wire shape. Strings pass through
2118
+ * unchanged so existing callers keep producing byte-identical request bodies.
2119
+ */
2120
+ declare function toWireUserContent(content: UserContent): WireUserContent;
2121
+ /**
2122
+ * Resolve an `ImagePart.image` value into a URL string suitable for
2123
+ * `image_url.url`. URLs pass through; binary and raw base64 are wrapped
2124
+ * into a data URL.
2125
+ */
2126
+ declare function imagePartToUrl(part: ImagePart): string;
2127
+ /**
2128
+ * Cross-runtime `Uint8Array → base64`. `btoa(String.fromCharCode(...bytes))`
2129
+ * trips the JS call-stack limit on large payloads, so we chunk the binary
2130
+ * string. Works in browser, Node 18+, Edge, and Bun.
2131
+ */
2132
+ declare function bytesToBase64(bytes: Uint8Array): string;
2133
+
2052
2134
  /**
2053
2135
  * Best-effort parser for incomplete JSON streamed token-by-token from an LLM.
2054
2136
  *
@@ -2067,4 +2149,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
2067
2149
 
2068
2150
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
2069
2151
 
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 };
2152
+ 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 ImagePart, 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 TextPart, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type UserContent, type WhereInput, type WhereOperatorObject, type WireContentPart, type WireImagePart, type WireTextPart, type WireUserContent, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, bytesToBase64, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, imagePartToUrl, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, toWireUserContent, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ __export(index_exports, {
60
60
  bindFetch: () => bindFetch,
61
61
  buildInferenceRequestBody: () => buildInferenceRequestBody,
62
62
  buildResponseFormat: () => buildResponseFormat,
63
+ bytesToBase64: () => bytesToBase64,
63
64
  collectAssistantTextFromUiSegments: () => collectAssistantTextFromUiSegments,
64
65
  collectionRecordToRowWithMeta: () => collectionRecordToRowWithMeta,
65
66
  collectionRecordsToRowWithMeta: () => collectionRecordsToRowWithMeta,
@@ -75,6 +76,7 @@ __export(index_exports, {
75
76
  formatPostgrestError: () => formatPostgrestError,
76
77
  formatSdkError: () => formatSdkError,
77
78
  generateIdempotencyKey: () => generateIdempotencyKey,
79
+ imagePartToUrl: () => imagePartToUrl,
78
80
  isIncompleteAgentStreamError: () => isIncompleteAgentStreamError,
79
81
  mapAgentEvent: () => mapAgentEvent,
80
82
  mapFireworksChunk: () => mapFireworksChunk,
@@ -89,6 +91,7 @@ __export(index_exports, {
89
91
  runAgentChatStreamLenient: () => runAgentChatStreamLenient,
90
92
  streamObjectFromContext: () => streamObjectFromContext,
91
93
  toRagableResult: () => toRagableResult,
94
+ toWireUserContent: () => toWireUserContent,
92
95
  tryParsePartialJson: () => tryParsePartialJson,
93
96
  unwrapPostgrest: () => unwrapPostgrest,
94
97
  wrapStreamTextAsObject: () => wrapStreamTextAsObject
@@ -2428,6 +2431,95 @@ function stripTrailingCommas(text) {
2428
2431
  return text.replace(/,(\s*[}\]])/g, "$1").replace(/,\s*$/, "");
2429
2432
  }
2430
2433
 
2434
+ // src/content.ts
2435
+ var MAX_IMAGE_BYTES = 5 * 1024 * 1024;
2436
+ function toWireUserContent(content) {
2437
+ if (typeof content === "string") return content;
2438
+ const out = [];
2439
+ for (const part of content) {
2440
+ if (!part) continue;
2441
+ if (part.type === "text") {
2442
+ out.push(toWireTextPart(part));
2443
+ } else if (part.type === "image") {
2444
+ out.push(toWireImagePart(part));
2445
+ }
2446
+ }
2447
+ return out;
2448
+ }
2449
+ function toWireTextPart(part) {
2450
+ return { type: "text", text: part.text };
2451
+ }
2452
+ function toWireImagePart(part) {
2453
+ const url = imagePartToUrl(part);
2454
+ const detail = part.detail;
2455
+ return {
2456
+ type: "image_url",
2457
+ image_url: detail ? { url, detail } : { url }
2458
+ };
2459
+ }
2460
+ function imagePartToUrl(part) {
2461
+ const img = part.image;
2462
+ if (img instanceof URL) return img.href;
2463
+ if (typeof img === "string") {
2464
+ if (img.startsWith("http://") || img.startsWith("https://")) return img;
2465
+ if (img.startsWith("data:")) return img;
2466
+ const mediaType = requireMediaType(part, "raw base64 string");
2467
+ assertBase64SizeOk(img);
2468
+ return `data:${mediaType};base64,${img}`;
2469
+ }
2470
+ if (img instanceof Uint8Array || img instanceof ArrayBuffer) {
2471
+ const bytes = img instanceof Uint8Array ? img : new Uint8Array(img);
2472
+ assertBinarySizeOk(bytes);
2473
+ const mediaType = requireMediaType(part, "binary image data");
2474
+ const b64 = bytesToBase64(bytes);
2475
+ return `data:${mediaType};base64,${b64}`;
2476
+ }
2477
+ throw new RagableError(
2478
+ "ImagePart.image must be a string, URL, Uint8Array, or ArrayBuffer",
2479
+ 400,
2480
+ { code: "SDK_INVALID_IMAGE_PART" }
2481
+ );
2482
+ }
2483
+ function requireMediaType(part, what) {
2484
+ const m = part.mediaType?.trim();
2485
+ if (!m) {
2486
+ throw new RagableError(
2487
+ `ImagePart.mediaType is required for ${what} (e.g. "image/png")`,
2488
+ 400,
2489
+ { code: "SDK_IMAGE_MEDIA_TYPE_REQUIRED" }
2490
+ );
2491
+ }
2492
+ return m;
2493
+ }
2494
+ function assertBinarySizeOk(bytes) {
2495
+ if (bytes.byteLength > MAX_IMAGE_BYTES) {
2496
+ throw new RagableError(
2497
+ `Image exceeds 5MB limit (${bytes.byteLength} bytes)`,
2498
+ 400,
2499
+ { code: "SDK_IMAGE_TOO_LARGE" }
2500
+ );
2501
+ }
2502
+ }
2503
+ function assertBase64SizeOk(b64) {
2504
+ const approxBytes = Math.floor(b64.length * 3 / 4);
2505
+ if (approxBytes > MAX_IMAGE_BYTES) {
2506
+ throw new RagableError(
2507
+ `Image exceeds 5MB limit (~${approxBytes} bytes decoded)`,
2508
+ 400,
2509
+ { code: "SDK_IMAGE_TOO_LARGE" }
2510
+ );
2511
+ }
2512
+ }
2513
+ function bytesToBase64(bytes) {
2514
+ const CHUNK = 32768;
2515
+ let binary = "";
2516
+ for (let i = 0; i < bytes.length; i += CHUNK) {
2517
+ const slice = bytes.subarray(i, i + CHUNK);
2518
+ binary += String.fromCharCode(...slice);
2519
+ }
2520
+ return btoa(binary);
2521
+ }
2522
+
2431
2523
  // src/stream-parts.ts
2432
2524
  function normalizeFinishReason(raw) {
2433
2525
  switch (raw) {
@@ -2640,7 +2732,9 @@ var ZERO_USAGE = {
2640
2732
  function buildInferenceRequestBody(params, responseFormat) {
2641
2733
  const body = {
2642
2734
  model: params.model,
2643
- messages: params.messages
2735
+ messages: params.messages.map(
2736
+ (m) => m.role === "user" ? { role: "user", content: toWireUserContent(m.content) } : m
2737
+ )
2644
2738
  };
2645
2739
  if (params.system !== void 0) body.system = params.system;
2646
2740
  if (typeof params.temperature === "number")
@@ -4416,6 +4510,7 @@ function createClient(options) {
4416
4510
  bindFetch,
4417
4511
  buildInferenceRequestBody,
4418
4512
  buildResponseFormat,
4513
+ bytesToBase64,
4419
4514
  collectAssistantTextFromUiSegments,
4420
4515
  collectionRecordToRowWithMeta,
4421
4516
  collectionRecordsToRowWithMeta,
@@ -4431,6 +4526,7 @@ function createClient(options) {
4431
4526
  formatPostgrestError,
4432
4527
  formatSdkError,
4433
4528
  generateIdempotencyKey,
4529
+ imagePartToUrl,
4434
4530
  isIncompleteAgentStreamError,
4435
4531
  mapAgentEvent,
4436
4532
  mapFireworksChunk,
@@ -4445,6 +4541,7 @@ function createClient(options) {
4445
4541
  runAgentChatStreamLenient,
4446
4542
  streamObjectFromContext,
4447
4543
  toRagableResult,
4544
+ toWireUserContent,
4448
4545
  tryParsePartialJson,
4449
4546
  unwrapPostgrest,
4450
4547
  wrapStreamTextAsObject