@blinkdotnew/sdk 2.6.2 → 2.7.0
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 +54 -5
- package/dist/index.d.ts +54 -5
- package/dist/index.js +89 -27
- package/dist/index.mjs +89 -28
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -313,6 +313,31 @@ declare class BlinkError extends Error {
|
|
|
313
313
|
details?: any | undefined;
|
|
314
314
|
constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any | undefined);
|
|
315
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* A React Native / Expo local file descriptor.
|
|
318
|
+
*
|
|
319
|
+
* On React Native the networking layer streams the file directly from `uri` when
|
|
320
|
+
* a `{ uri, name, type }` object is appended to FormData. This is the only
|
|
321
|
+
* reliable way to multipart-upload a local file on RN — wrapping the file's bytes
|
|
322
|
+
* in a `Blob` (e.g. `new Blob([blob])`) loses the underlying data and produces a
|
|
323
|
+
* 0-byte upload. Pass the descriptor returned by expo-image-picker /
|
|
324
|
+
* expo-camera (its `uri`) straight to `blink.storage.upload`.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* await blink.storage.upload(
|
|
329
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
330
|
+
* `corrections/${id}`
|
|
331
|
+
* )
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
interface ReactNativeFile {
|
|
335
|
+
uri: string;
|
|
336
|
+
name?: string;
|
|
337
|
+
type?: string;
|
|
338
|
+
}
|
|
339
|
+
/** Anything Blink storage can upload, across web / Node.js / React Native. */
|
|
340
|
+
type BlinkUploadFile = File | Blob | Buffer | ArrayBuffer | ReactNativeFile;
|
|
316
341
|
interface StorageUploadOptions {
|
|
317
342
|
/**
|
|
318
343
|
* @deprecated Blink storage uploads are add-only by default. This option is ignored.
|
|
@@ -341,7 +366,7 @@ interface FileObject {
|
|
|
341
366
|
user_metadata?: Record<string, any>;
|
|
342
367
|
}
|
|
343
368
|
interface BlinkStorage {
|
|
344
|
-
upload(file:
|
|
369
|
+
upload(file: BlinkUploadFile, path: string, options?: StorageUploadOptions): Promise<StorageUploadResponse>;
|
|
345
370
|
download(path: string, options?: {
|
|
346
371
|
filename?: string;
|
|
347
372
|
}): Promise<StorageDownloadResponse>;
|
|
@@ -1013,7 +1038,7 @@ declare class HttpClient {
|
|
|
1013
1038
|
/**
|
|
1014
1039
|
* Upload file with progress tracking
|
|
1015
1040
|
*/
|
|
1016
|
-
uploadFile(path: string, file:
|
|
1041
|
+
uploadFile(path: string, file: BlinkUploadFile, filePath: string, options?: {
|
|
1017
1042
|
upsert?: boolean;
|
|
1018
1043
|
onProgress?: (percent: number) => void;
|
|
1019
1044
|
contentType?: string;
|
|
@@ -1262,7 +1287,13 @@ declare class HttpClient {
|
|
|
1262
1287
|
* Platform detection for cross-platform compatibility
|
|
1263
1288
|
* Detects whether code is running on web, React Native, Node.js, or Deno
|
|
1264
1289
|
*/
|
|
1290
|
+
|
|
1265
1291
|
type Platform = 'web' | 'react-native' | 'node' | 'deno';
|
|
1292
|
+
/**
|
|
1293
|
+
* True when `file` is a React Native / Expo file descriptor (`{ uri, name?, type? }`),
|
|
1294
|
+
* as opposed to a File / Blob / Buffer / ArrayBuffer.
|
|
1295
|
+
*/
|
|
1296
|
+
declare function isReactNativeFile(file: unknown): file is ReactNativeFile;
|
|
1266
1297
|
/**
|
|
1267
1298
|
* Current platform
|
|
1268
1299
|
*/
|
|
@@ -2586,7 +2617,8 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2586
2617
|
/**
|
|
2587
2618
|
* Upload a file to project storage
|
|
2588
2619
|
*
|
|
2589
|
-
* @param file - File, Blob, or
|
|
2620
|
+
* @param file - File, Blob, Buffer, ArrayBuffer, or a React Native file
|
|
2621
|
+
* descriptor (`{ uri, name?, type? }`) to upload
|
|
2590
2622
|
* @param path - Destination path within project storage (extension will be auto-corrected to match file type)
|
|
2591
2623
|
* @param options - Upload options including upsert and progress callback
|
|
2592
2624
|
* @returns Promise resolving to upload response with public URL
|
|
@@ -2601,6 +2633,13 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2601
2633
|
* );
|
|
2602
2634
|
* // If file is PNG, final path will be: avatars/user123.png
|
|
2603
2635
|
*
|
|
2636
|
+
* // React Native / Expo: pass the picker/camera result's uri directly.
|
|
2637
|
+
* // Do NOT wrap it in a Blob — that uploads a 0-byte file on RN.
|
|
2638
|
+
* const { publicUrl } = await blink.storage.upload(
|
|
2639
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
2640
|
+
* `corrections/${id}`
|
|
2641
|
+
* );
|
|
2642
|
+
*
|
|
2604
2643
|
* // Or with extension (will be corrected if wrong)
|
|
2605
2644
|
* const { publicUrl } = await blink.storage.upload(
|
|
2606
2645
|
* pngFile,
|
|
@@ -2610,12 +2649,22 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2610
2649
|
* // Final path will be: avatars/user123.png (auto-corrected!)
|
|
2611
2650
|
* ```
|
|
2612
2651
|
*/
|
|
2613
|
-
upload(file:
|
|
2652
|
+
upload(file: BlinkUploadFile, path: string, options?: StorageUploadOptions): Promise<StorageUploadResponse>;
|
|
2614
2653
|
/**
|
|
2615
2654
|
* Detect file type from actual file content and correct path extension
|
|
2616
2655
|
* This ensures the path extension always matches the actual file type
|
|
2617
2656
|
*/
|
|
2618
2657
|
private detectFileTypeAndCorrectPath;
|
|
2658
|
+
/**
|
|
2659
|
+
* Replace (or append) the extension on the last path segment.
|
|
2660
|
+
*/
|
|
2661
|
+
private rebuildPathWithExtension;
|
|
2662
|
+
/**
|
|
2663
|
+
* Pull a lowercase extension out of a filename, path, or uri (no dot, '' if
|
|
2664
|
+
* none). Strips any query/fragment (RN content:// uris carry them) and only
|
|
2665
|
+
* accepts a sane extension so junk never leaks into the storage path.
|
|
2666
|
+
*/
|
|
2667
|
+
private getExtensionFromName;
|
|
2619
2668
|
/**
|
|
2620
2669
|
* Get the first few bytes of a file to analyze its signature
|
|
2621
2670
|
*/
|
|
@@ -3968,4 +4017,4 @@ declare const mediaTools: readonly ["generate_image", "edit_image", "generate_vi
|
|
|
3968
4017
|
*/
|
|
3969
4018
|
declare function serializeTools(tools: string[]): string[];
|
|
3970
4019
|
|
|
3971
|
-
export { type AISearchOptions, Agent, type AgentBilling, type AgentConfig, type AgentNonStreamMessagesRequest, type AgentNonStreamPromptRequest, type AgentOptions, type AgentRequest, type AgentResponse, type AgentStep, type AgentStreamRequest, type TokenUsage as AgentTokenUsage, type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkQueue, BlinkQueueCreditError, BlinkQueueImpl, type BlinkQueueSchedule, type BlinkQueueStats, type BlinkQueueTask, type BlinkRAG, BlinkRAGImpl, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkSandbox, BlinkSandboxImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkTokenType, type BlinkUser, type ClientTool, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type ContextPolicy, type CreateCollectionOptions, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type GenerateOptions, type ImageGenerationRequest, type ImageGenerationResponse, type JSONSchema, type ListDocumentsOptions, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type QueueOptions, type RAGAISearchResult, type RAGAISearchSource, type RAGCollection, type RAGDocument, type RAGSearchResponse, type RAGSearchResult, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, SANDBOX_TEMPLATES, type Sandbox, type SandboxConnectOptions, SandboxConnectionError, type SandboxCreateOptions, type SandboxTemplate, type ScheduleOptions, type SearchOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StopCondition, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type StreamOptions, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenIntrospectionResult, type TokenUsage$1 as TokenUsage, type ToolCall, type ToolResult, type TranscriptionRequest, type TranscriptionResponse, type UIMessage, type UIMessagePart, type UpdateOptions, type UploadOptions, type UpsertOptions, type WaitForReadyOptions, type WebBrowserModule, WebStorageAdapter, type WebhookTool, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
|
4020
|
+
export { type AISearchOptions, Agent, type AgentBilling, type AgentConfig, type AgentNonStreamMessagesRequest, type AgentNonStreamPromptRequest, type AgentOptions, type AgentRequest, type AgentResponse, type AgentStep, type AgentStreamRequest, type TokenUsage as AgentTokenUsage, type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkQueue, BlinkQueueCreditError, BlinkQueueImpl, type BlinkQueueSchedule, type BlinkQueueStats, type BlinkQueueTask, type BlinkRAG, BlinkRAGImpl, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkSandbox, BlinkSandboxImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkTokenType, type BlinkUploadFile, type BlinkUser, type ClientTool, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type ContextPolicy, type CreateCollectionOptions, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type GenerateOptions, type ImageGenerationRequest, type ImageGenerationResponse, type JSONSchema, type ListDocumentsOptions, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type QueueOptions, type RAGAISearchResult, type RAGAISearchSource, type RAGCollection, type RAGDocument, type RAGSearchResponse, type RAGSearchResult, type ReactNativeFile, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, SANDBOX_TEMPLATES, type Sandbox, type SandboxConnectOptions, SandboxConnectionError, type SandboxCreateOptions, type SandboxTemplate, type ScheduleOptions, type SearchOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StopCondition, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type StreamOptions, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenIntrospectionResult, type TokenUsage$1 as TokenUsage, type ToolCall, type ToolResult, type TranscriptionRequest, type TranscriptionResponse, type UIMessage, type UIMessagePart, type UpdateOptions, type UploadOptions, type UpsertOptions, type WaitForReadyOptions, type WebBrowserModule, WebStorageAdapter, type WebhookTool, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isReactNativeFile, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -313,6 +313,31 @@ declare class BlinkError extends Error {
|
|
|
313
313
|
details?: any | undefined;
|
|
314
314
|
constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any | undefined);
|
|
315
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* A React Native / Expo local file descriptor.
|
|
318
|
+
*
|
|
319
|
+
* On React Native the networking layer streams the file directly from `uri` when
|
|
320
|
+
* a `{ uri, name, type }` object is appended to FormData. This is the only
|
|
321
|
+
* reliable way to multipart-upload a local file on RN — wrapping the file's bytes
|
|
322
|
+
* in a `Blob` (e.g. `new Blob([blob])`) loses the underlying data and produces a
|
|
323
|
+
* 0-byte upload. Pass the descriptor returned by expo-image-picker /
|
|
324
|
+
* expo-camera (its `uri`) straight to `blink.storage.upload`.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* await blink.storage.upload(
|
|
329
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
330
|
+
* `corrections/${id}`
|
|
331
|
+
* )
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
interface ReactNativeFile {
|
|
335
|
+
uri: string;
|
|
336
|
+
name?: string;
|
|
337
|
+
type?: string;
|
|
338
|
+
}
|
|
339
|
+
/** Anything Blink storage can upload, across web / Node.js / React Native. */
|
|
340
|
+
type BlinkUploadFile = File | Blob | Buffer | ArrayBuffer | ReactNativeFile;
|
|
316
341
|
interface StorageUploadOptions {
|
|
317
342
|
/**
|
|
318
343
|
* @deprecated Blink storage uploads are add-only by default. This option is ignored.
|
|
@@ -341,7 +366,7 @@ interface FileObject {
|
|
|
341
366
|
user_metadata?: Record<string, any>;
|
|
342
367
|
}
|
|
343
368
|
interface BlinkStorage {
|
|
344
|
-
upload(file:
|
|
369
|
+
upload(file: BlinkUploadFile, path: string, options?: StorageUploadOptions): Promise<StorageUploadResponse>;
|
|
345
370
|
download(path: string, options?: {
|
|
346
371
|
filename?: string;
|
|
347
372
|
}): Promise<StorageDownloadResponse>;
|
|
@@ -1013,7 +1038,7 @@ declare class HttpClient {
|
|
|
1013
1038
|
/**
|
|
1014
1039
|
* Upload file with progress tracking
|
|
1015
1040
|
*/
|
|
1016
|
-
uploadFile(path: string, file:
|
|
1041
|
+
uploadFile(path: string, file: BlinkUploadFile, filePath: string, options?: {
|
|
1017
1042
|
upsert?: boolean;
|
|
1018
1043
|
onProgress?: (percent: number) => void;
|
|
1019
1044
|
contentType?: string;
|
|
@@ -1262,7 +1287,13 @@ declare class HttpClient {
|
|
|
1262
1287
|
* Platform detection for cross-platform compatibility
|
|
1263
1288
|
* Detects whether code is running on web, React Native, Node.js, or Deno
|
|
1264
1289
|
*/
|
|
1290
|
+
|
|
1265
1291
|
type Platform = 'web' | 'react-native' | 'node' | 'deno';
|
|
1292
|
+
/**
|
|
1293
|
+
* True when `file` is a React Native / Expo file descriptor (`{ uri, name?, type? }`),
|
|
1294
|
+
* as opposed to a File / Blob / Buffer / ArrayBuffer.
|
|
1295
|
+
*/
|
|
1296
|
+
declare function isReactNativeFile(file: unknown): file is ReactNativeFile;
|
|
1266
1297
|
/**
|
|
1267
1298
|
* Current platform
|
|
1268
1299
|
*/
|
|
@@ -2586,7 +2617,8 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2586
2617
|
/**
|
|
2587
2618
|
* Upload a file to project storage
|
|
2588
2619
|
*
|
|
2589
|
-
* @param file - File, Blob, or
|
|
2620
|
+
* @param file - File, Blob, Buffer, ArrayBuffer, or a React Native file
|
|
2621
|
+
* descriptor (`{ uri, name?, type? }`) to upload
|
|
2590
2622
|
* @param path - Destination path within project storage (extension will be auto-corrected to match file type)
|
|
2591
2623
|
* @param options - Upload options including upsert and progress callback
|
|
2592
2624
|
* @returns Promise resolving to upload response with public URL
|
|
@@ -2601,6 +2633,13 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2601
2633
|
* );
|
|
2602
2634
|
* // If file is PNG, final path will be: avatars/user123.png
|
|
2603
2635
|
*
|
|
2636
|
+
* // React Native / Expo: pass the picker/camera result's uri directly.
|
|
2637
|
+
* // Do NOT wrap it in a Blob — that uploads a 0-byte file on RN.
|
|
2638
|
+
* const { publicUrl } = await blink.storage.upload(
|
|
2639
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
2640
|
+
* `corrections/${id}`
|
|
2641
|
+
* );
|
|
2642
|
+
*
|
|
2604
2643
|
* // Or with extension (will be corrected if wrong)
|
|
2605
2644
|
* const { publicUrl } = await blink.storage.upload(
|
|
2606
2645
|
* pngFile,
|
|
@@ -2610,12 +2649,22 @@ declare class BlinkStorageImpl implements BlinkStorage {
|
|
|
2610
2649
|
* // Final path will be: avatars/user123.png (auto-corrected!)
|
|
2611
2650
|
* ```
|
|
2612
2651
|
*/
|
|
2613
|
-
upload(file:
|
|
2652
|
+
upload(file: BlinkUploadFile, path: string, options?: StorageUploadOptions): Promise<StorageUploadResponse>;
|
|
2614
2653
|
/**
|
|
2615
2654
|
* Detect file type from actual file content and correct path extension
|
|
2616
2655
|
* This ensures the path extension always matches the actual file type
|
|
2617
2656
|
*/
|
|
2618
2657
|
private detectFileTypeAndCorrectPath;
|
|
2658
|
+
/**
|
|
2659
|
+
* Replace (or append) the extension on the last path segment.
|
|
2660
|
+
*/
|
|
2661
|
+
private rebuildPathWithExtension;
|
|
2662
|
+
/**
|
|
2663
|
+
* Pull a lowercase extension out of a filename, path, or uri (no dot, '' if
|
|
2664
|
+
* none). Strips any query/fragment (RN content:// uris carry them) and only
|
|
2665
|
+
* accepts a sane extension so junk never leaks into the storage path.
|
|
2666
|
+
*/
|
|
2667
|
+
private getExtensionFromName;
|
|
2619
2668
|
/**
|
|
2620
2669
|
* Get the first few bytes of a file to analyze its signature
|
|
2621
2670
|
*/
|
|
@@ -3968,4 +4017,4 @@ declare const mediaTools: readonly ["generate_image", "edit_image", "generate_vi
|
|
|
3968
4017
|
*/
|
|
3969
4018
|
declare function serializeTools(tools: string[]): string[];
|
|
3970
4019
|
|
|
3971
|
-
export { type AISearchOptions, Agent, type AgentBilling, type AgentConfig, type AgentNonStreamMessagesRequest, type AgentNonStreamPromptRequest, type AgentOptions, type AgentRequest, type AgentResponse, type AgentStep, type AgentStreamRequest, type TokenUsage as AgentTokenUsage, type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkQueue, BlinkQueueCreditError, BlinkQueueImpl, type BlinkQueueSchedule, type BlinkQueueStats, type BlinkQueueTask, type BlinkRAG, BlinkRAGImpl, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkSandbox, BlinkSandboxImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkTokenType, type BlinkUser, type ClientTool, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type ContextPolicy, type CreateCollectionOptions, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type GenerateOptions, type ImageGenerationRequest, type ImageGenerationResponse, type JSONSchema, type ListDocumentsOptions, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type QueueOptions, type RAGAISearchResult, type RAGAISearchSource, type RAGCollection, type RAGDocument, type RAGSearchResponse, type RAGSearchResult, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, SANDBOX_TEMPLATES, type Sandbox, type SandboxConnectOptions, SandboxConnectionError, type SandboxCreateOptions, type SandboxTemplate, type ScheduleOptions, type SearchOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StopCondition, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type StreamOptions, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenIntrospectionResult, type TokenUsage$1 as TokenUsage, type ToolCall, type ToolResult, type TranscriptionRequest, type TranscriptionResponse, type UIMessage, type UIMessagePart, type UpdateOptions, type UploadOptions, type UpsertOptions, type WaitForReadyOptions, type WebBrowserModule, WebStorageAdapter, type WebhookTool, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
|
4020
|
+
export { type AISearchOptions, Agent, type AgentBilling, type AgentConfig, type AgentNonStreamMessagesRequest, type AgentNonStreamPromptRequest, type AgentOptions, type AgentRequest, type AgentResponse, type AgentStep, type AgentStreamRequest, type TokenUsage as AgentTokenUsage, type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkQueue, BlinkQueueCreditError, BlinkQueueImpl, type BlinkQueueSchedule, type BlinkQueueStats, type BlinkQueueTask, type BlinkRAG, BlinkRAGImpl, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkSandbox, BlinkSandboxImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkTokenType, type BlinkUploadFile, type BlinkUser, type ClientTool, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type ContextPolicy, type CreateCollectionOptions, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type GenerateOptions, type ImageGenerationRequest, type ImageGenerationResponse, type JSONSchema, type ListDocumentsOptions, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type QueueOptions, type RAGAISearchResult, type RAGAISearchSource, type RAGCollection, type RAGDocument, type RAGSearchResponse, type RAGSearchResult, type ReactNativeFile, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, SANDBOX_TEMPLATES, type Sandbox, type SandboxConnectOptions, SandboxConnectionError, type SandboxCreateOptions, type SandboxTemplate, type ScheduleOptions, type SearchOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StopCondition, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type StreamOptions, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenIntrospectionResult, type TokenUsage$1 as TokenUsage, type ToolCall, type ToolResult, type TranscriptionRequest, type TranscriptionResponse, type UIMessage, type UIMessagePart, type UpdateOptions, type UploadOptions, type UpsertOptions, type WaitForReadyOptions, type WebBrowserModule, WebStorageAdapter, type WebhookTool, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isReactNativeFile, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// ../core/src/platform.ts
|
|
11
|
+
function isReactNativeFile(file) {
|
|
12
|
+
return typeof file === "object" && file !== null && typeof file.uri === "string";
|
|
13
|
+
}
|
|
11
14
|
function detectPlatform() {
|
|
12
15
|
if (typeof Deno !== "undefined") {
|
|
13
16
|
return "deno";
|
|
@@ -659,11 +662,26 @@ var HttpClient = class {
|
|
|
659
662
|
async uploadFile(path, file, filePath, options = {}) {
|
|
660
663
|
const url = this.buildUrl(path);
|
|
661
664
|
const formData = new FormData();
|
|
662
|
-
|
|
665
|
+
const fallbackName = filePath.split("/").pop() || "file";
|
|
666
|
+
if (isReactNativeFile(file)) {
|
|
667
|
+
const part = {
|
|
668
|
+
uri: file.uri,
|
|
669
|
+
name: file.name || fallbackName,
|
|
670
|
+
type: file.type || options.contentType || "application/octet-stream"
|
|
671
|
+
};
|
|
672
|
+
formData.append("file", part);
|
|
673
|
+
} else if (typeof File !== "undefined" && file instanceof File) {
|
|
663
674
|
formData.append("file", file);
|
|
664
|
-
} else if (file instanceof Blob) {
|
|
665
|
-
|
|
666
|
-
|
|
675
|
+
} else if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
676
|
+
if (isReactNative) {
|
|
677
|
+
formData.append("file", file, fallbackName);
|
|
678
|
+
} else {
|
|
679
|
+
const blobWithType = options.contentType ? new Blob([file], { type: options.contentType }) : file;
|
|
680
|
+
formData.append("file", blobWithType);
|
|
681
|
+
}
|
|
682
|
+
} else if (file instanceof ArrayBuffer) {
|
|
683
|
+
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
684
|
+
formData.append("file", blob);
|
|
667
685
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
668
686
|
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
669
687
|
formData.append("file", blob);
|
|
@@ -3571,12 +3589,13 @@ var BlinkStorageImpl = class {
|
|
|
3571
3589
|
}
|
|
3572
3590
|
/**
|
|
3573
3591
|
* Upload a file to project storage
|
|
3574
|
-
*
|
|
3575
|
-
* @param file - File, Blob, or
|
|
3592
|
+
*
|
|
3593
|
+
* @param file - File, Blob, Buffer, ArrayBuffer, or a React Native file
|
|
3594
|
+
* descriptor (`{ uri, name?, type? }`) to upload
|
|
3576
3595
|
* @param path - Destination path within project storage (extension will be auto-corrected to match file type)
|
|
3577
3596
|
* @param options - Upload options including upsert and progress callback
|
|
3578
3597
|
* @returns Promise resolving to upload response with public URL
|
|
3579
|
-
*
|
|
3598
|
+
*
|
|
3580
3599
|
* @example
|
|
3581
3600
|
* ```ts
|
|
3582
3601
|
* // Extension automatically corrected to match actual file type
|
|
@@ -3586,7 +3605,14 @@ var BlinkStorageImpl = class {
|
|
|
3586
3605
|
* { upsert: true }
|
|
3587
3606
|
* );
|
|
3588
3607
|
* // If file is PNG, final path will be: avatars/user123.png
|
|
3589
|
-
*
|
|
3608
|
+
*
|
|
3609
|
+
* // React Native / Expo: pass the picker/camera result's uri directly.
|
|
3610
|
+
* // Do NOT wrap it in a Blob — that uploads a 0-byte file on RN.
|
|
3611
|
+
* const { publicUrl } = await blink.storage.upload(
|
|
3612
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
3613
|
+
* `corrections/${id}`
|
|
3614
|
+
* );
|
|
3615
|
+
*
|
|
3590
3616
|
* // Or with extension (will be corrected if wrong)
|
|
3591
3617
|
* const { publicUrl } = await blink.storage.upload(
|
|
3592
3618
|
* pngFile,
|
|
@@ -3606,8 +3632,12 @@ var BlinkStorageImpl = class {
|
|
|
3606
3632
|
}
|
|
3607
3633
|
const maxSize = 50 * 1024 * 1024;
|
|
3608
3634
|
let fileSize = 0;
|
|
3609
|
-
if (
|
|
3635
|
+
if (typeof File !== "undefined" && file instanceof File) {
|
|
3610
3636
|
fileSize = file.size;
|
|
3637
|
+
} else if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
3638
|
+
fileSize = file.size;
|
|
3639
|
+
} else if (file instanceof ArrayBuffer) {
|
|
3640
|
+
fileSize = file.byteLength;
|
|
3611
3641
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
3612
3642
|
fileSize = file.length;
|
|
3613
3643
|
}
|
|
@@ -3659,29 +3689,30 @@ var BlinkStorageImpl = class {
|
|
|
3659
3689
|
*/
|
|
3660
3690
|
async detectFileTypeAndCorrectPath(file, originalPath) {
|
|
3661
3691
|
try {
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3692
|
+
let detectedContentType = "";
|
|
3693
|
+
let detectedExtension = "";
|
|
3694
|
+
if (isReactNativeFile(file)) {
|
|
3695
|
+
detectedContentType = file.type || "";
|
|
3696
|
+
const mimeExt = detectedContentType ? this.getExtensionFromMimeType(detectedContentType) : "";
|
|
3697
|
+
detectedExtension = (mimeExt && mimeExt !== "bin" ? mimeExt : "") || this.getExtensionFromName(file.name) || this.getExtensionFromName(file.uri) || this.getExtensionFromName(originalPath);
|
|
3698
|
+
} else {
|
|
3699
|
+
const fileSignature = await this.getFileSignature(file);
|
|
3700
|
+
const detectedType = this.detectFileTypeFromSignature(fileSignature);
|
|
3701
|
+
detectedContentType = detectedType.mimeType;
|
|
3702
|
+
detectedExtension = detectedType.extension;
|
|
3703
|
+
if (!detectedContentType && typeof File !== "undefined" && file instanceof File && file.type) {
|
|
3704
|
+
detectedContentType = file.type;
|
|
3705
|
+
detectedExtension = this.getExtensionFromMimeType(file.type);
|
|
3706
|
+
}
|
|
3669
3707
|
}
|
|
3670
3708
|
if (!detectedContentType) {
|
|
3671
3709
|
detectedContentType = "application/octet-stream";
|
|
3672
|
-
detectedExtension = "bin";
|
|
3673
3710
|
}
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
const directory = pathParts.slice(0, -1).join("/");
|
|
3677
|
-
if (!fileName) {
|
|
3678
|
-
throw new Error("Invalid path: filename cannot be empty");
|
|
3711
|
+
if (!detectedExtension) {
|
|
3712
|
+
detectedExtension = "bin";
|
|
3679
3713
|
}
|
|
3680
|
-
const nameWithoutExt = fileName.includes(".") ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
|
|
3681
|
-
const correctedFileName = `${nameWithoutExt}.${detectedExtension}`;
|
|
3682
|
-
const correctedPath = directory ? `${directory}/${correctedFileName}` : correctedFileName;
|
|
3683
3714
|
return {
|
|
3684
|
-
correctedPath,
|
|
3715
|
+
correctedPath: this.rebuildPathWithExtension(originalPath, detectedExtension),
|
|
3685
3716
|
detectedContentType
|
|
3686
3717
|
};
|
|
3687
3718
|
} catch (error) {
|
|
@@ -3691,15 +3722,45 @@ var BlinkStorageImpl = class {
|
|
|
3691
3722
|
};
|
|
3692
3723
|
}
|
|
3693
3724
|
}
|
|
3725
|
+
/**
|
|
3726
|
+
* Replace (or append) the extension on the last path segment.
|
|
3727
|
+
*/
|
|
3728
|
+
rebuildPathWithExtension(originalPath, extension) {
|
|
3729
|
+
const pathParts = originalPath.split("/");
|
|
3730
|
+
const fileName = pathParts[pathParts.length - 1];
|
|
3731
|
+
const directory = pathParts.slice(0, -1).join("/");
|
|
3732
|
+
if (!fileName) {
|
|
3733
|
+
throw new Error("Invalid path: filename cannot be empty");
|
|
3734
|
+
}
|
|
3735
|
+
const nameWithoutExt = fileName.includes(".") ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
|
|
3736
|
+
const correctedFileName = `${nameWithoutExt}.${extension}`;
|
|
3737
|
+
return directory ? `${directory}/${correctedFileName}` : correctedFileName;
|
|
3738
|
+
}
|
|
3739
|
+
/**
|
|
3740
|
+
* Pull a lowercase extension out of a filename, path, or uri (no dot, '' if
|
|
3741
|
+
* none). Strips any query/fragment (RN content:// uris carry them) and only
|
|
3742
|
+
* accepts a sane extension so junk never leaks into the storage path.
|
|
3743
|
+
*/
|
|
3744
|
+
getExtensionFromName(name) {
|
|
3745
|
+
if (!name) return "";
|
|
3746
|
+
const base = (name.split(/[?#]/)[0] || "").split("/").pop() || "";
|
|
3747
|
+
const dot = base.lastIndexOf(".");
|
|
3748
|
+
if (dot <= 0) return "";
|
|
3749
|
+
const ext = base.substring(dot + 1).toLowerCase();
|
|
3750
|
+
return /^[a-z0-9]{1,8}$/.test(ext) ? ext : "";
|
|
3751
|
+
}
|
|
3694
3752
|
/**
|
|
3695
3753
|
* Get the first few bytes of a file to analyze its signature
|
|
3696
3754
|
*/
|
|
3697
3755
|
async getFileSignature(file) {
|
|
3698
3756
|
const bytesToRead = 12;
|
|
3757
|
+
if (file instanceof ArrayBuffer) {
|
|
3758
|
+
return new Uint8Array(file.slice(0, bytesToRead));
|
|
3759
|
+
}
|
|
3699
3760
|
if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
3700
3761
|
return new Uint8Array(file.slice(0, bytesToRead));
|
|
3701
3762
|
}
|
|
3702
|
-
if (file instanceof File || file instanceof Blob) {
|
|
3763
|
+
if (typeof File !== "undefined" && file instanceof File || typeof Blob !== "undefined" && file instanceof Blob) {
|
|
3703
3764
|
const slice = file.slice(0, bytesToRead);
|
|
3704
3765
|
const arrayBuffer = await slice.arrayBuffer();
|
|
3705
3766
|
return new Uint8Array(arrayBuffer);
|
|
@@ -7107,6 +7168,7 @@ exports.isBrowser = isBrowser;
|
|
|
7107
7168
|
exports.isDeno = isDeno;
|
|
7108
7169
|
exports.isNode = isNode;
|
|
7109
7170
|
exports.isReactNative = isReactNative;
|
|
7171
|
+
exports.isReactNativeFile = isReactNativeFile;
|
|
7110
7172
|
exports.isServer = isServer;
|
|
7111
7173
|
exports.isWeb = isWeb;
|
|
7112
7174
|
exports.listDir = listDir;
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// ../core/src/platform.ts
|
|
9
|
+
function isReactNativeFile(file) {
|
|
10
|
+
return typeof file === "object" && file !== null && typeof file.uri === "string";
|
|
11
|
+
}
|
|
9
12
|
function detectPlatform() {
|
|
10
13
|
if (typeof Deno !== "undefined") {
|
|
11
14
|
return "deno";
|
|
@@ -657,11 +660,26 @@ var HttpClient = class {
|
|
|
657
660
|
async uploadFile(path, file, filePath, options = {}) {
|
|
658
661
|
const url = this.buildUrl(path);
|
|
659
662
|
const formData = new FormData();
|
|
660
|
-
|
|
663
|
+
const fallbackName = filePath.split("/").pop() || "file";
|
|
664
|
+
if (isReactNativeFile(file)) {
|
|
665
|
+
const part = {
|
|
666
|
+
uri: file.uri,
|
|
667
|
+
name: file.name || fallbackName,
|
|
668
|
+
type: file.type || options.contentType || "application/octet-stream"
|
|
669
|
+
};
|
|
670
|
+
formData.append("file", part);
|
|
671
|
+
} else if (typeof File !== "undefined" && file instanceof File) {
|
|
661
672
|
formData.append("file", file);
|
|
662
|
-
} else if (file instanceof Blob) {
|
|
663
|
-
|
|
664
|
-
|
|
673
|
+
} else if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
674
|
+
if (isReactNative) {
|
|
675
|
+
formData.append("file", file, fallbackName);
|
|
676
|
+
} else {
|
|
677
|
+
const blobWithType = options.contentType ? new Blob([file], { type: options.contentType }) : file;
|
|
678
|
+
formData.append("file", blobWithType);
|
|
679
|
+
}
|
|
680
|
+
} else if (file instanceof ArrayBuffer) {
|
|
681
|
+
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
682
|
+
formData.append("file", blob);
|
|
665
683
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
666
684
|
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
667
685
|
formData.append("file", blob);
|
|
@@ -3569,12 +3587,13 @@ var BlinkStorageImpl = class {
|
|
|
3569
3587
|
}
|
|
3570
3588
|
/**
|
|
3571
3589
|
* Upload a file to project storage
|
|
3572
|
-
*
|
|
3573
|
-
* @param file - File, Blob, or
|
|
3590
|
+
*
|
|
3591
|
+
* @param file - File, Blob, Buffer, ArrayBuffer, or a React Native file
|
|
3592
|
+
* descriptor (`{ uri, name?, type? }`) to upload
|
|
3574
3593
|
* @param path - Destination path within project storage (extension will be auto-corrected to match file type)
|
|
3575
3594
|
* @param options - Upload options including upsert and progress callback
|
|
3576
3595
|
* @returns Promise resolving to upload response with public URL
|
|
3577
|
-
*
|
|
3596
|
+
*
|
|
3578
3597
|
* @example
|
|
3579
3598
|
* ```ts
|
|
3580
3599
|
* // Extension automatically corrected to match actual file type
|
|
@@ -3584,7 +3603,14 @@ var BlinkStorageImpl = class {
|
|
|
3584
3603
|
* { upsert: true }
|
|
3585
3604
|
* );
|
|
3586
3605
|
* // If file is PNG, final path will be: avatars/user123.png
|
|
3587
|
-
*
|
|
3606
|
+
*
|
|
3607
|
+
* // React Native / Expo: pass the picker/camera result's uri directly.
|
|
3608
|
+
* // Do NOT wrap it in a Blob — that uploads a 0-byte file on RN.
|
|
3609
|
+
* const { publicUrl } = await blink.storage.upload(
|
|
3610
|
+
* { uri: photo.uri, name: 'photo.jpg', type: 'image/jpeg' },
|
|
3611
|
+
* `corrections/${id}`
|
|
3612
|
+
* );
|
|
3613
|
+
*
|
|
3588
3614
|
* // Or with extension (will be corrected if wrong)
|
|
3589
3615
|
* const { publicUrl } = await blink.storage.upload(
|
|
3590
3616
|
* pngFile,
|
|
@@ -3604,8 +3630,12 @@ var BlinkStorageImpl = class {
|
|
|
3604
3630
|
}
|
|
3605
3631
|
const maxSize = 50 * 1024 * 1024;
|
|
3606
3632
|
let fileSize = 0;
|
|
3607
|
-
if (
|
|
3633
|
+
if (typeof File !== "undefined" && file instanceof File) {
|
|
3608
3634
|
fileSize = file.size;
|
|
3635
|
+
} else if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
3636
|
+
fileSize = file.size;
|
|
3637
|
+
} else if (file instanceof ArrayBuffer) {
|
|
3638
|
+
fileSize = file.byteLength;
|
|
3609
3639
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
3610
3640
|
fileSize = file.length;
|
|
3611
3641
|
}
|
|
@@ -3657,29 +3687,30 @@ var BlinkStorageImpl = class {
|
|
|
3657
3687
|
*/
|
|
3658
3688
|
async detectFileTypeAndCorrectPath(file, originalPath) {
|
|
3659
3689
|
try {
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3690
|
+
let detectedContentType = "";
|
|
3691
|
+
let detectedExtension = "";
|
|
3692
|
+
if (isReactNativeFile(file)) {
|
|
3693
|
+
detectedContentType = file.type || "";
|
|
3694
|
+
const mimeExt = detectedContentType ? this.getExtensionFromMimeType(detectedContentType) : "";
|
|
3695
|
+
detectedExtension = (mimeExt && mimeExt !== "bin" ? mimeExt : "") || this.getExtensionFromName(file.name) || this.getExtensionFromName(file.uri) || this.getExtensionFromName(originalPath);
|
|
3696
|
+
} else {
|
|
3697
|
+
const fileSignature = await this.getFileSignature(file);
|
|
3698
|
+
const detectedType = this.detectFileTypeFromSignature(fileSignature);
|
|
3699
|
+
detectedContentType = detectedType.mimeType;
|
|
3700
|
+
detectedExtension = detectedType.extension;
|
|
3701
|
+
if (!detectedContentType && typeof File !== "undefined" && file instanceof File && file.type) {
|
|
3702
|
+
detectedContentType = file.type;
|
|
3703
|
+
detectedExtension = this.getExtensionFromMimeType(file.type);
|
|
3704
|
+
}
|
|
3667
3705
|
}
|
|
3668
3706
|
if (!detectedContentType) {
|
|
3669
3707
|
detectedContentType = "application/octet-stream";
|
|
3670
|
-
detectedExtension = "bin";
|
|
3671
3708
|
}
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
const directory = pathParts.slice(0, -1).join("/");
|
|
3675
|
-
if (!fileName) {
|
|
3676
|
-
throw new Error("Invalid path: filename cannot be empty");
|
|
3709
|
+
if (!detectedExtension) {
|
|
3710
|
+
detectedExtension = "bin";
|
|
3677
3711
|
}
|
|
3678
|
-
const nameWithoutExt = fileName.includes(".") ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
|
|
3679
|
-
const correctedFileName = `${nameWithoutExt}.${detectedExtension}`;
|
|
3680
|
-
const correctedPath = directory ? `${directory}/${correctedFileName}` : correctedFileName;
|
|
3681
3712
|
return {
|
|
3682
|
-
correctedPath,
|
|
3713
|
+
correctedPath: this.rebuildPathWithExtension(originalPath, detectedExtension),
|
|
3683
3714
|
detectedContentType
|
|
3684
3715
|
};
|
|
3685
3716
|
} catch (error) {
|
|
@@ -3689,15 +3720,45 @@ var BlinkStorageImpl = class {
|
|
|
3689
3720
|
};
|
|
3690
3721
|
}
|
|
3691
3722
|
}
|
|
3723
|
+
/**
|
|
3724
|
+
* Replace (or append) the extension on the last path segment.
|
|
3725
|
+
*/
|
|
3726
|
+
rebuildPathWithExtension(originalPath, extension) {
|
|
3727
|
+
const pathParts = originalPath.split("/");
|
|
3728
|
+
const fileName = pathParts[pathParts.length - 1];
|
|
3729
|
+
const directory = pathParts.slice(0, -1).join("/");
|
|
3730
|
+
if (!fileName) {
|
|
3731
|
+
throw new Error("Invalid path: filename cannot be empty");
|
|
3732
|
+
}
|
|
3733
|
+
const nameWithoutExt = fileName.includes(".") ? fileName.substring(0, fileName.lastIndexOf(".")) : fileName;
|
|
3734
|
+
const correctedFileName = `${nameWithoutExt}.${extension}`;
|
|
3735
|
+
return directory ? `${directory}/${correctedFileName}` : correctedFileName;
|
|
3736
|
+
}
|
|
3737
|
+
/**
|
|
3738
|
+
* Pull a lowercase extension out of a filename, path, or uri (no dot, '' if
|
|
3739
|
+
* none). Strips any query/fragment (RN content:// uris carry them) and only
|
|
3740
|
+
* accepts a sane extension so junk never leaks into the storage path.
|
|
3741
|
+
*/
|
|
3742
|
+
getExtensionFromName(name) {
|
|
3743
|
+
if (!name) return "";
|
|
3744
|
+
const base = (name.split(/[?#]/)[0] || "").split("/").pop() || "";
|
|
3745
|
+
const dot = base.lastIndexOf(".");
|
|
3746
|
+
if (dot <= 0) return "";
|
|
3747
|
+
const ext = base.substring(dot + 1).toLowerCase();
|
|
3748
|
+
return /^[a-z0-9]{1,8}$/.test(ext) ? ext : "";
|
|
3749
|
+
}
|
|
3692
3750
|
/**
|
|
3693
3751
|
* Get the first few bytes of a file to analyze its signature
|
|
3694
3752
|
*/
|
|
3695
3753
|
async getFileSignature(file) {
|
|
3696
3754
|
const bytesToRead = 12;
|
|
3755
|
+
if (file instanceof ArrayBuffer) {
|
|
3756
|
+
return new Uint8Array(file.slice(0, bytesToRead));
|
|
3757
|
+
}
|
|
3697
3758
|
if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
3698
3759
|
return new Uint8Array(file.slice(0, bytesToRead));
|
|
3699
3760
|
}
|
|
3700
|
-
if (file instanceof File || file instanceof Blob) {
|
|
3761
|
+
if (typeof File !== "undefined" && file instanceof File || typeof Blob !== "undefined" && file instanceof Blob) {
|
|
3701
3762
|
const slice = file.slice(0, bytesToRead);
|
|
3702
3763
|
const arrayBuffer = await slice.arrayBuffer();
|
|
3703
3764
|
return new Uint8Array(arrayBuffer);
|
|
@@ -7064,6 +7125,6 @@ function createClient(config) {
|
|
|
7064
7125
|
return client;
|
|
7065
7126
|
}
|
|
7066
7127
|
|
|
7067
|
-
export { Agent, AsyncStorageAdapter, BlinkAIImpl, BlinkAnalyticsImpl, BlinkConnectorsImpl, BlinkDataImpl, BlinkDatabase, BlinkQueueCreditError, BlinkQueueImpl, BlinkRAGImpl, BlinkRealtimeChannel, BlinkRealtimeImpl, BlinkSandboxImpl, BlinkStorageImpl, BlinkTable, NoOpStorageAdapter, SANDBOX_TEMPLATES, SandboxConnectionError, WebStorageAdapter, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
|
7128
|
+
export { Agent, AsyncStorageAdapter, BlinkAIImpl, BlinkAnalyticsImpl, BlinkConnectorsImpl, BlinkDataImpl, BlinkDatabase, BlinkQueueCreditError, BlinkQueueImpl, BlinkRAGImpl, BlinkRealtimeChannel, BlinkRealtimeImpl, BlinkSandboxImpl, BlinkStorageImpl, BlinkTable, NoOpStorageAdapter, SANDBOX_TEMPLATES, SandboxConnectionError, WebStorageAdapter, coreTools, createClient, dbDelete, dbGet, dbInsert, dbList, dbTools, dbUpdate, editImage, fetchUrl, generateImage, generateVideo, getDefaultClient, getDefaultStorageAdapter, getHost, globFileSearch, grep, imageToVideo, isBrowser, isDeno, isNode, isReactNative, isReactNativeFile, isServer, isWeb, listDir, mediaTools, platform, ragSearch, ragTools, readFile, runCode, runTerminalCmd, sandboxTools, searchReplace, serializeTools, stepCountIs, storageCopy, storageDelete, storageDownload, storageList, storageMove, storagePublicUrl, storageTools, storageUpload, webSearch, writeFile };
|
|
7068
7129
|
//# sourceMappingURL=index.mjs.map
|
|
7069
7130
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED