@blinkdotnew/sdk 2.3.3 → 2.3.5
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 +157 -45
- package/dist/index.d.ts +157 -45
- package/dist/index.js +411 -2907
- package/dist/index.mjs +411 -2908
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -2244,6 +2244,13 @@ interface SandboxCreateOptions {
|
|
|
2244
2244
|
timeoutMs?: number;
|
|
2245
2245
|
/** Custom metadata for tracking */
|
|
2246
2246
|
metadata?: Record<string, string>;
|
|
2247
|
+
/**
|
|
2248
|
+
* Secret names to inject as environment variables.
|
|
2249
|
+
* Secrets are resolved server-side from project secrets vault.
|
|
2250
|
+
* Add secrets via Workspace > Secrets or request_secret tool.
|
|
2251
|
+
* @example ['ANTHROPIC_API_KEY', 'GITHUB_TOKEN']
|
|
2252
|
+
*/
|
|
2253
|
+
secrets?: string[];
|
|
2247
2254
|
}
|
|
2248
2255
|
interface SandboxConnectOptions {
|
|
2249
2256
|
/** Reset inactivity timeout in ms (default: 5 min) */
|
|
@@ -2306,6 +2313,23 @@ declare class BlinkSandboxImpl implements BlinkSandbox {
|
|
|
2306
2313
|
* Factory function and client class for the Blink SDK
|
|
2307
2314
|
*/
|
|
2308
2315
|
|
|
2316
|
+
/**
|
|
2317
|
+
* Get the default Blink client instance.
|
|
2318
|
+
* Returns the client created by createClient().
|
|
2319
|
+
*
|
|
2320
|
+
* @throws Error if createClient() hasn't been called yet
|
|
2321
|
+
* @returns The default BlinkClient instance
|
|
2322
|
+
*
|
|
2323
|
+
* @example
|
|
2324
|
+
* ```ts
|
|
2325
|
+
* // First, create client somewhere in your app
|
|
2326
|
+
* createClient({ projectId: '...', secretKey: '...' })
|
|
2327
|
+
*
|
|
2328
|
+
* // Later, get the default client
|
|
2329
|
+
* const client = getDefaultClient()
|
|
2330
|
+
* ```
|
|
2331
|
+
*/
|
|
2332
|
+
declare function getDefaultClient(): BlinkClientImpl;
|
|
2309
2333
|
interface BlinkClient {
|
|
2310
2334
|
auth: BlinkAuth;
|
|
2311
2335
|
db: BlinkDatabase;
|
|
@@ -2320,8 +2344,39 @@ interface BlinkClient {
|
|
|
2320
2344
|
rag: BlinkRAG;
|
|
2321
2345
|
sandbox: BlinkSandbox;
|
|
2322
2346
|
}
|
|
2347
|
+
declare class BlinkClientImpl implements BlinkClient {
|
|
2348
|
+
auth: BlinkAuth;
|
|
2349
|
+
db: BlinkDatabase;
|
|
2350
|
+
storage: BlinkStorage;
|
|
2351
|
+
ai: BlinkAI;
|
|
2352
|
+
data: BlinkData;
|
|
2353
|
+
realtime: BlinkRealtime;
|
|
2354
|
+
notifications: BlinkNotifications;
|
|
2355
|
+
analytics: BlinkAnalytics;
|
|
2356
|
+
connectors: BlinkConnectors;
|
|
2357
|
+
functions: BlinkFunctions;
|
|
2358
|
+
rag: BlinkRAG;
|
|
2359
|
+
sandbox: BlinkSandbox;
|
|
2360
|
+
/** @internal HTTP client for Agent auto-binding */
|
|
2361
|
+
_httpClient: HttpClient;
|
|
2362
|
+
constructor(config: BlinkClientConfig);
|
|
2363
|
+
}
|
|
2323
2364
|
/**
|
|
2324
|
-
* Create a new Blink client instance
|
|
2365
|
+
* Create a new Blink client instance.
|
|
2366
|
+
* This also sets the default client for Agent auto-binding.
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* ```ts
|
|
2370
|
+
* // Create client (call once in your app)
|
|
2371
|
+
* const blink = createClient({
|
|
2372
|
+
* projectId: 'my-project',
|
|
2373
|
+
* secretKey: 'sk_...',
|
|
2374
|
+
* })
|
|
2375
|
+
*
|
|
2376
|
+
* // Now Agent works without explicit binding
|
|
2377
|
+
* const agent = new Agent({ model: 'openai/gpt-4o' })
|
|
2378
|
+
* await agent.generate({ prompt: 'Hello!' })
|
|
2379
|
+
* ```
|
|
2325
2380
|
*/
|
|
2326
2381
|
declare function createClient(config: BlinkClientConfig): BlinkClient;
|
|
2327
2382
|
|
|
@@ -2620,6 +2675,8 @@ interface AgentResponse {
|
|
|
2620
2675
|
* - Create agent instance with config
|
|
2621
2676
|
* - Call agent.generate() for non-streaming
|
|
2622
2677
|
* - Call agent.stream() for streaming
|
|
2678
|
+
*
|
|
2679
|
+
* Auto-binds to default client when createClient() has been called.
|
|
2623
2680
|
*/
|
|
2624
2681
|
|
|
2625
2682
|
/**
|
|
@@ -2679,34 +2736,38 @@ interface StreamOptions {
|
|
|
2679
2736
|
* - `agent.generate({ prompt })` for non-streaming one-shot generation
|
|
2680
2737
|
* - `agent.stream({ prompt })` for streaming real-time generation
|
|
2681
2738
|
*
|
|
2739
|
+
* **Auto-binding:** After calling `createClient()`, agents automatically
|
|
2740
|
+
* bind to the default client. No need for `blink.ai.createAgent()`.
|
|
2741
|
+
*
|
|
2682
2742
|
* @example
|
|
2683
2743
|
* ```ts
|
|
2684
|
-
* import { Agent, webSearch
|
|
2744
|
+
* import { createClient, Agent, webSearch } from '@blinkdotnew/sdk'
|
|
2745
|
+
*
|
|
2746
|
+
* // Initialize client once
|
|
2747
|
+
* createClient({ projectId: '...', secretKey: '...' })
|
|
2685
2748
|
*
|
|
2749
|
+
* // Create agent - auto-binds to default client
|
|
2686
2750
|
* const weatherAgent = new Agent({
|
|
2687
2751
|
* model: 'anthropic/claude-sonnet-4-20250514',
|
|
2688
2752
|
* system: 'You are a helpful weather assistant.',
|
|
2689
|
-
* tools: [webSearch
|
|
2753
|
+
* tools: [webSearch],
|
|
2690
2754
|
* maxSteps: 10,
|
|
2691
2755
|
* })
|
|
2692
2756
|
*
|
|
2693
|
-
* //
|
|
2757
|
+
* // Works immediately - no binding needed!
|
|
2694
2758
|
* const result = await weatherAgent.generate({
|
|
2695
2759
|
* prompt: 'What is the weather in San Francisco?',
|
|
2696
2760
|
* })
|
|
2697
2761
|
* console.log(result.text)
|
|
2698
|
-
*
|
|
2699
|
-
* // Streaming
|
|
2700
|
-
* const stream = await weatherAgent.stream({
|
|
2701
|
-
* prompt: 'Tell me about weather patterns',
|
|
2702
|
-
* })
|
|
2703
2762
|
* ```
|
|
2704
2763
|
*/
|
|
2705
2764
|
declare class Agent {
|
|
2706
2765
|
private httpClient;
|
|
2707
2766
|
private readonly config;
|
|
2708
2767
|
/**
|
|
2709
|
-
* Create a new Agent instance
|
|
2768
|
+
* Create a new Agent instance.
|
|
2769
|
+
* Auto-binds to default client if createClient() was called.
|
|
2770
|
+
*
|
|
2710
2771
|
* @param options - Agent configuration options
|
|
2711
2772
|
*/
|
|
2712
2773
|
constructor(options: AgentOptions);
|
|
@@ -3427,27 +3488,93 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
3427
3488
|
}
|
|
3428
3489
|
|
|
3429
3490
|
/**
|
|
3430
|
-
* Blink Realtime
|
|
3431
|
-
*
|
|
3491
|
+
* Blink Realtime Connection - Single WebSocket connection manager
|
|
3492
|
+
* Handles connection lifecycle, message routing, and reconnection for all channels
|
|
3432
3493
|
*/
|
|
3433
3494
|
|
|
3434
|
-
|
|
3435
|
-
|
|
3495
|
+
interface ChannelHandler {
|
|
3496
|
+
onMessage: (message: any) => void;
|
|
3497
|
+
onPresence: (users: any[]) => void;
|
|
3498
|
+
onSubscribed: () => void;
|
|
3499
|
+
onError: (error: string) => void;
|
|
3500
|
+
}
|
|
3501
|
+
declare class RealtimeConnection {
|
|
3436
3502
|
private httpClient;
|
|
3437
3503
|
private projectId;
|
|
3438
|
-
private messageCallbacks;
|
|
3439
|
-
private presenceCallbacks;
|
|
3440
3504
|
private websocket;
|
|
3441
|
-
private isSubscribed;
|
|
3442
3505
|
private isConnected;
|
|
3443
3506
|
private isConnecting;
|
|
3444
3507
|
private reconnectTimer;
|
|
3445
3508
|
private heartbeatTimer;
|
|
3446
3509
|
private reconnectAttempts;
|
|
3447
|
-
private messageQueue;
|
|
3448
|
-
private pendingSubscription;
|
|
3449
3510
|
private connectionPromise;
|
|
3450
|
-
|
|
3511
|
+
private channels;
|
|
3512
|
+
private pendingSubscriptions;
|
|
3513
|
+
private messageQueue;
|
|
3514
|
+
constructor(httpClient: HttpClient, projectId: string);
|
|
3515
|
+
/**
|
|
3516
|
+
* Check if connection is ready
|
|
3517
|
+
*/
|
|
3518
|
+
isReady(): boolean;
|
|
3519
|
+
/**
|
|
3520
|
+
* Ensure WebSocket connection is established
|
|
3521
|
+
*/
|
|
3522
|
+
connect(): Promise<void>;
|
|
3523
|
+
/**
|
|
3524
|
+
* Join a channel (subscribe)
|
|
3525
|
+
*/
|
|
3526
|
+
joinChannel(channelName: string, handler: ChannelHandler, options?: {
|
|
3527
|
+
userId?: string;
|
|
3528
|
+
metadata?: Record<string, any>;
|
|
3529
|
+
}): Promise<void>;
|
|
3530
|
+
/**
|
|
3531
|
+
* Leave a channel (unsubscribe)
|
|
3532
|
+
*/
|
|
3533
|
+
leaveChannel(channelName: string): Promise<void>;
|
|
3534
|
+
/**
|
|
3535
|
+
* Send a message to a channel
|
|
3536
|
+
*/
|
|
3537
|
+
send(channelName: string, type: string, data: any, options?: {
|
|
3538
|
+
userId?: string;
|
|
3539
|
+
metadata?: Record<string, any>;
|
|
3540
|
+
}): Promise<string>;
|
|
3541
|
+
/**
|
|
3542
|
+
* Disconnect and cleanup
|
|
3543
|
+
*/
|
|
3544
|
+
disconnect(): void;
|
|
3545
|
+
/**
|
|
3546
|
+
* Get count of active channels
|
|
3547
|
+
*/
|
|
3548
|
+
getChannelCount(): number;
|
|
3549
|
+
private connectWebSocket;
|
|
3550
|
+
private handleMessage;
|
|
3551
|
+
private sendRaw;
|
|
3552
|
+
private sendWithResponse;
|
|
3553
|
+
private flushMessageQueue;
|
|
3554
|
+
private rejectQueuedMessages;
|
|
3555
|
+
private startHeartbeat;
|
|
3556
|
+
private scheduleReconnect;
|
|
3557
|
+
private resubscribeAllChannels;
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
/**
|
|
3561
|
+
* Blink Realtime Module - Real-time messaging and presence
|
|
3562
|
+
* Provides pub/sub messaging, presence tracking, and live updates
|
|
3563
|
+
*
|
|
3564
|
+
* Architecture: Single WebSocket connection per client, multiplexed channels
|
|
3565
|
+
* (Industry standard - matches Supabase, Firebase, Pusher)
|
|
3566
|
+
*/
|
|
3567
|
+
|
|
3568
|
+
declare class BlinkRealtimeChannel implements RealtimeChannel {
|
|
3569
|
+
private channelName;
|
|
3570
|
+
private connection;
|
|
3571
|
+
private httpClient;
|
|
3572
|
+
private projectId;
|
|
3573
|
+
private messageCallbacks;
|
|
3574
|
+
private presenceCallbacks;
|
|
3575
|
+
private isSubscribed;
|
|
3576
|
+
private subscribeOptions;
|
|
3577
|
+
constructor(channelName: string, connection: RealtimeConnection, httpClient: HttpClient, projectId: string);
|
|
3451
3578
|
/**
|
|
3452
3579
|
* Check if channel is ready for publishing
|
|
3453
3580
|
*/
|
|
@@ -3469,35 +3596,12 @@ declare class BlinkRealtimeChannel implements RealtimeChannel {
|
|
|
3469
3596
|
before?: string;
|
|
3470
3597
|
after?: string;
|
|
3471
3598
|
}): Promise<RealtimeMessage[]>;
|
|
3472
|
-
/**
|
|
3473
|
-
* Ensure WebSocket connection is established and ready
|
|
3474
|
-
*/
|
|
3475
|
-
private ensureConnected;
|
|
3476
|
-
/**
|
|
3477
|
-
* Send a message, queuing if socket not ready
|
|
3478
|
-
*/
|
|
3479
|
-
private sendMessage;
|
|
3480
|
-
/**
|
|
3481
|
-
* Send a queued message and set up response handling
|
|
3482
|
-
*/
|
|
3483
|
-
private sendQueuedMessage;
|
|
3484
|
-
/**
|
|
3485
|
-
* Flush all queued messages when connection becomes ready
|
|
3486
|
-
*/
|
|
3487
|
-
private flushMessageQueue;
|
|
3488
|
-
private connectWebSocket;
|
|
3489
|
-
/**
|
|
3490
|
-
* Reject all queued messages with the given error
|
|
3491
|
-
*/
|
|
3492
|
-
private rejectQueuedMessages;
|
|
3493
|
-
private handleWebSocketMessage;
|
|
3494
|
-
private startHeartbeat;
|
|
3495
|
-
private scheduleReconnect;
|
|
3496
3599
|
private cleanup;
|
|
3497
3600
|
}
|
|
3498
3601
|
declare class BlinkRealtimeImpl implements BlinkRealtime {
|
|
3499
3602
|
private httpClient;
|
|
3500
3603
|
private projectId;
|
|
3604
|
+
private connection;
|
|
3501
3605
|
private channels;
|
|
3502
3606
|
private handlers;
|
|
3503
3607
|
constructor(httpClient: HttpClient, projectId: string);
|
|
@@ -3506,6 +3610,14 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
|
|
|
3506
3610
|
publish(channelName: string, type: string, data: any, options?: RealtimePublishOptions): Promise<string>;
|
|
3507
3611
|
presence(channelName: string): Promise<PresenceUser[]>;
|
|
3508
3612
|
onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
|
|
3613
|
+
/**
|
|
3614
|
+
* Get the number of active WebSocket connections (should always be 0 or 1)
|
|
3615
|
+
*/
|
|
3616
|
+
getConnectionCount(): number;
|
|
3617
|
+
/**
|
|
3618
|
+
* Get the number of active channels
|
|
3619
|
+
*/
|
|
3620
|
+
getChannelCount(): number;
|
|
3509
3621
|
}
|
|
3510
3622
|
|
|
3511
3623
|
declare class BlinkConnectorsImpl implements BlinkConnectors {
|
|
@@ -3661,4 +3773,4 @@ declare const mediaTools: readonly ["generate_image", "edit_image", "generate_vi
|
|
|
3661
3773
|
*/
|
|
3662
3774
|
declare function serializeTools(tools: string[]): string[];
|
|
3663
3775
|
|
|
3664
|
-
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 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 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 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, 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 };
|
|
3776
|
+
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 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 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 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -2244,6 +2244,13 @@ interface SandboxCreateOptions {
|
|
|
2244
2244
|
timeoutMs?: number;
|
|
2245
2245
|
/** Custom metadata for tracking */
|
|
2246
2246
|
metadata?: Record<string, string>;
|
|
2247
|
+
/**
|
|
2248
|
+
* Secret names to inject as environment variables.
|
|
2249
|
+
* Secrets are resolved server-side from project secrets vault.
|
|
2250
|
+
* Add secrets via Workspace > Secrets or request_secret tool.
|
|
2251
|
+
* @example ['ANTHROPIC_API_KEY', 'GITHUB_TOKEN']
|
|
2252
|
+
*/
|
|
2253
|
+
secrets?: string[];
|
|
2247
2254
|
}
|
|
2248
2255
|
interface SandboxConnectOptions {
|
|
2249
2256
|
/** Reset inactivity timeout in ms (default: 5 min) */
|
|
@@ -2306,6 +2313,23 @@ declare class BlinkSandboxImpl implements BlinkSandbox {
|
|
|
2306
2313
|
* Factory function and client class for the Blink SDK
|
|
2307
2314
|
*/
|
|
2308
2315
|
|
|
2316
|
+
/**
|
|
2317
|
+
* Get the default Blink client instance.
|
|
2318
|
+
* Returns the client created by createClient().
|
|
2319
|
+
*
|
|
2320
|
+
* @throws Error if createClient() hasn't been called yet
|
|
2321
|
+
* @returns The default BlinkClient instance
|
|
2322
|
+
*
|
|
2323
|
+
* @example
|
|
2324
|
+
* ```ts
|
|
2325
|
+
* // First, create client somewhere in your app
|
|
2326
|
+
* createClient({ projectId: '...', secretKey: '...' })
|
|
2327
|
+
*
|
|
2328
|
+
* // Later, get the default client
|
|
2329
|
+
* const client = getDefaultClient()
|
|
2330
|
+
* ```
|
|
2331
|
+
*/
|
|
2332
|
+
declare function getDefaultClient(): BlinkClientImpl;
|
|
2309
2333
|
interface BlinkClient {
|
|
2310
2334
|
auth: BlinkAuth;
|
|
2311
2335
|
db: BlinkDatabase;
|
|
@@ -2320,8 +2344,39 @@ interface BlinkClient {
|
|
|
2320
2344
|
rag: BlinkRAG;
|
|
2321
2345
|
sandbox: BlinkSandbox;
|
|
2322
2346
|
}
|
|
2347
|
+
declare class BlinkClientImpl implements BlinkClient {
|
|
2348
|
+
auth: BlinkAuth;
|
|
2349
|
+
db: BlinkDatabase;
|
|
2350
|
+
storage: BlinkStorage;
|
|
2351
|
+
ai: BlinkAI;
|
|
2352
|
+
data: BlinkData;
|
|
2353
|
+
realtime: BlinkRealtime;
|
|
2354
|
+
notifications: BlinkNotifications;
|
|
2355
|
+
analytics: BlinkAnalytics;
|
|
2356
|
+
connectors: BlinkConnectors;
|
|
2357
|
+
functions: BlinkFunctions;
|
|
2358
|
+
rag: BlinkRAG;
|
|
2359
|
+
sandbox: BlinkSandbox;
|
|
2360
|
+
/** @internal HTTP client for Agent auto-binding */
|
|
2361
|
+
_httpClient: HttpClient;
|
|
2362
|
+
constructor(config: BlinkClientConfig);
|
|
2363
|
+
}
|
|
2323
2364
|
/**
|
|
2324
|
-
* Create a new Blink client instance
|
|
2365
|
+
* Create a new Blink client instance.
|
|
2366
|
+
* This also sets the default client for Agent auto-binding.
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* ```ts
|
|
2370
|
+
* // Create client (call once in your app)
|
|
2371
|
+
* const blink = createClient({
|
|
2372
|
+
* projectId: 'my-project',
|
|
2373
|
+
* secretKey: 'sk_...',
|
|
2374
|
+
* })
|
|
2375
|
+
*
|
|
2376
|
+
* // Now Agent works without explicit binding
|
|
2377
|
+
* const agent = new Agent({ model: 'openai/gpt-4o' })
|
|
2378
|
+
* await agent.generate({ prompt: 'Hello!' })
|
|
2379
|
+
* ```
|
|
2325
2380
|
*/
|
|
2326
2381
|
declare function createClient(config: BlinkClientConfig): BlinkClient;
|
|
2327
2382
|
|
|
@@ -2620,6 +2675,8 @@ interface AgentResponse {
|
|
|
2620
2675
|
* - Create agent instance with config
|
|
2621
2676
|
* - Call agent.generate() for non-streaming
|
|
2622
2677
|
* - Call agent.stream() for streaming
|
|
2678
|
+
*
|
|
2679
|
+
* Auto-binds to default client when createClient() has been called.
|
|
2623
2680
|
*/
|
|
2624
2681
|
|
|
2625
2682
|
/**
|
|
@@ -2679,34 +2736,38 @@ interface StreamOptions {
|
|
|
2679
2736
|
* - `agent.generate({ prompt })` for non-streaming one-shot generation
|
|
2680
2737
|
* - `agent.stream({ prompt })` for streaming real-time generation
|
|
2681
2738
|
*
|
|
2739
|
+
* **Auto-binding:** After calling `createClient()`, agents automatically
|
|
2740
|
+
* bind to the default client. No need for `blink.ai.createAgent()`.
|
|
2741
|
+
*
|
|
2682
2742
|
* @example
|
|
2683
2743
|
* ```ts
|
|
2684
|
-
* import { Agent, webSearch
|
|
2744
|
+
* import { createClient, Agent, webSearch } from '@blinkdotnew/sdk'
|
|
2745
|
+
*
|
|
2746
|
+
* // Initialize client once
|
|
2747
|
+
* createClient({ projectId: '...', secretKey: '...' })
|
|
2685
2748
|
*
|
|
2749
|
+
* // Create agent - auto-binds to default client
|
|
2686
2750
|
* const weatherAgent = new Agent({
|
|
2687
2751
|
* model: 'anthropic/claude-sonnet-4-20250514',
|
|
2688
2752
|
* system: 'You are a helpful weather assistant.',
|
|
2689
|
-
* tools: [webSearch
|
|
2753
|
+
* tools: [webSearch],
|
|
2690
2754
|
* maxSteps: 10,
|
|
2691
2755
|
* })
|
|
2692
2756
|
*
|
|
2693
|
-
* //
|
|
2757
|
+
* // Works immediately - no binding needed!
|
|
2694
2758
|
* const result = await weatherAgent.generate({
|
|
2695
2759
|
* prompt: 'What is the weather in San Francisco?',
|
|
2696
2760
|
* })
|
|
2697
2761
|
* console.log(result.text)
|
|
2698
|
-
*
|
|
2699
|
-
* // Streaming
|
|
2700
|
-
* const stream = await weatherAgent.stream({
|
|
2701
|
-
* prompt: 'Tell me about weather patterns',
|
|
2702
|
-
* })
|
|
2703
2762
|
* ```
|
|
2704
2763
|
*/
|
|
2705
2764
|
declare class Agent {
|
|
2706
2765
|
private httpClient;
|
|
2707
2766
|
private readonly config;
|
|
2708
2767
|
/**
|
|
2709
|
-
* Create a new Agent instance
|
|
2768
|
+
* Create a new Agent instance.
|
|
2769
|
+
* Auto-binds to default client if createClient() was called.
|
|
2770
|
+
*
|
|
2710
2771
|
* @param options - Agent configuration options
|
|
2711
2772
|
*/
|
|
2712
2773
|
constructor(options: AgentOptions);
|
|
@@ -3427,27 +3488,93 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
3427
3488
|
}
|
|
3428
3489
|
|
|
3429
3490
|
/**
|
|
3430
|
-
* Blink Realtime
|
|
3431
|
-
*
|
|
3491
|
+
* Blink Realtime Connection - Single WebSocket connection manager
|
|
3492
|
+
* Handles connection lifecycle, message routing, and reconnection for all channels
|
|
3432
3493
|
*/
|
|
3433
3494
|
|
|
3434
|
-
|
|
3435
|
-
|
|
3495
|
+
interface ChannelHandler {
|
|
3496
|
+
onMessage: (message: any) => void;
|
|
3497
|
+
onPresence: (users: any[]) => void;
|
|
3498
|
+
onSubscribed: () => void;
|
|
3499
|
+
onError: (error: string) => void;
|
|
3500
|
+
}
|
|
3501
|
+
declare class RealtimeConnection {
|
|
3436
3502
|
private httpClient;
|
|
3437
3503
|
private projectId;
|
|
3438
|
-
private messageCallbacks;
|
|
3439
|
-
private presenceCallbacks;
|
|
3440
3504
|
private websocket;
|
|
3441
|
-
private isSubscribed;
|
|
3442
3505
|
private isConnected;
|
|
3443
3506
|
private isConnecting;
|
|
3444
3507
|
private reconnectTimer;
|
|
3445
3508
|
private heartbeatTimer;
|
|
3446
3509
|
private reconnectAttempts;
|
|
3447
|
-
private messageQueue;
|
|
3448
|
-
private pendingSubscription;
|
|
3449
3510
|
private connectionPromise;
|
|
3450
|
-
|
|
3511
|
+
private channels;
|
|
3512
|
+
private pendingSubscriptions;
|
|
3513
|
+
private messageQueue;
|
|
3514
|
+
constructor(httpClient: HttpClient, projectId: string);
|
|
3515
|
+
/**
|
|
3516
|
+
* Check if connection is ready
|
|
3517
|
+
*/
|
|
3518
|
+
isReady(): boolean;
|
|
3519
|
+
/**
|
|
3520
|
+
* Ensure WebSocket connection is established
|
|
3521
|
+
*/
|
|
3522
|
+
connect(): Promise<void>;
|
|
3523
|
+
/**
|
|
3524
|
+
* Join a channel (subscribe)
|
|
3525
|
+
*/
|
|
3526
|
+
joinChannel(channelName: string, handler: ChannelHandler, options?: {
|
|
3527
|
+
userId?: string;
|
|
3528
|
+
metadata?: Record<string, any>;
|
|
3529
|
+
}): Promise<void>;
|
|
3530
|
+
/**
|
|
3531
|
+
* Leave a channel (unsubscribe)
|
|
3532
|
+
*/
|
|
3533
|
+
leaveChannel(channelName: string): Promise<void>;
|
|
3534
|
+
/**
|
|
3535
|
+
* Send a message to a channel
|
|
3536
|
+
*/
|
|
3537
|
+
send(channelName: string, type: string, data: any, options?: {
|
|
3538
|
+
userId?: string;
|
|
3539
|
+
metadata?: Record<string, any>;
|
|
3540
|
+
}): Promise<string>;
|
|
3541
|
+
/**
|
|
3542
|
+
* Disconnect and cleanup
|
|
3543
|
+
*/
|
|
3544
|
+
disconnect(): void;
|
|
3545
|
+
/**
|
|
3546
|
+
* Get count of active channels
|
|
3547
|
+
*/
|
|
3548
|
+
getChannelCount(): number;
|
|
3549
|
+
private connectWebSocket;
|
|
3550
|
+
private handleMessage;
|
|
3551
|
+
private sendRaw;
|
|
3552
|
+
private sendWithResponse;
|
|
3553
|
+
private flushMessageQueue;
|
|
3554
|
+
private rejectQueuedMessages;
|
|
3555
|
+
private startHeartbeat;
|
|
3556
|
+
private scheduleReconnect;
|
|
3557
|
+
private resubscribeAllChannels;
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
/**
|
|
3561
|
+
* Blink Realtime Module - Real-time messaging and presence
|
|
3562
|
+
* Provides pub/sub messaging, presence tracking, and live updates
|
|
3563
|
+
*
|
|
3564
|
+
* Architecture: Single WebSocket connection per client, multiplexed channels
|
|
3565
|
+
* (Industry standard - matches Supabase, Firebase, Pusher)
|
|
3566
|
+
*/
|
|
3567
|
+
|
|
3568
|
+
declare class BlinkRealtimeChannel implements RealtimeChannel {
|
|
3569
|
+
private channelName;
|
|
3570
|
+
private connection;
|
|
3571
|
+
private httpClient;
|
|
3572
|
+
private projectId;
|
|
3573
|
+
private messageCallbacks;
|
|
3574
|
+
private presenceCallbacks;
|
|
3575
|
+
private isSubscribed;
|
|
3576
|
+
private subscribeOptions;
|
|
3577
|
+
constructor(channelName: string, connection: RealtimeConnection, httpClient: HttpClient, projectId: string);
|
|
3451
3578
|
/**
|
|
3452
3579
|
* Check if channel is ready for publishing
|
|
3453
3580
|
*/
|
|
@@ -3469,35 +3596,12 @@ declare class BlinkRealtimeChannel implements RealtimeChannel {
|
|
|
3469
3596
|
before?: string;
|
|
3470
3597
|
after?: string;
|
|
3471
3598
|
}): Promise<RealtimeMessage[]>;
|
|
3472
|
-
/**
|
|
3473
|
-
* Ensure WebSocket connection is established and ready
|
|
3474
|
-
*/
|
|
3475
|
-
private ensureConnected;
|
|
3476
|
-
/**
|
|
3477
|
-
* Send a message, queuing if socket not ready
|
|
3478
|
-
*/
|
|
3479
|
-
private sendMessage;
|
|
3480
|
-
/**
|
|
3481
|
-
* Send a queued message and set up response handling
|
|
3482
|
-
*/
|
|
3483
|
-
private sendQueuedMessage;
|
|
3484
|
-
/**
|
|
3485
|
-
* Flush all queued messages when connection becomes ready
|
|
3486
|
-
*/
|
|
3487
|
-
private flushMessageQueue;
|
|
3488
|
-
private connectWebSocket;
|
|
3489
|
-
/**
|
|
3490
|
-
* Reject all queued messages with the given error
|
|
3491
|
-
*/
|
|
3492
|
-
private rejectQueuedMessages;
|
|
3493
|
-
private handleWebSocketMessage;
|
|
3494
|
-
private startHeartbeat;
|
|
3495
|
-
private scheduleReconnect;
|
|
3496
3599
|
private cleanup;
|
|
3497
3600
|
}
|
|
3498
3601
|
declare class BlinkRealtimeImpl implements BlinkRealtime {
|
|
3499
3602
|
private httpClient;
|
|
3500
3603
|
private projectId;
|
|
3604
|
+
private connection;
|
|
3501
3605
|
private channels;
|
|
3502
3606
|
private handlers;
|
|
3503
3607
|
constructor(httpClient: HttpClient, projectId: string);
|
|
@@ -3506,6 +3610,14 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
|
|
|
3506
3610
|
publish(channelName: string, type: string, data: any, options?: RealtimePublishOptions): Promise<string>;
|
|
3507
3611
|
presence(channelName: string): Promise<PresenceUser[]>;
|
|
3508
3612
|
onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
|
|
3613
|
+
/**
|
|
3614
|
+
* Get the number of active WebSocket connections (should always be 0 or 1)
|
|
3615
|
+
*/
|
|
3616
|
+
getConnectionCount(): number;
|
|
3617
|
+
/**
|
|
3618
|
+
* Get the number of active channels
|
|
3619
|
+
*/
|
|
3620
|
+
getChannelCount(): number;
|
|
3509
3621
|
}
|
|
3510
3622
|
|
|
3511
3623
|
declare class BlinkConnectorsImpl implements BlinkConnectors {
|
|
@@ -3661,4 +3773,4 @@ declare const mediaTools: readonly ["generate_image", "edit_image", "generate_vi
|
|
|
3661
3773
|
*/
|
|
3662
3774
|
declare function serializeTools(tools: string[]): string[];
|
|
3663
3775
|
|
|
3664
|
-
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 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 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 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, 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 };
|
|
3776
|
+
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 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 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 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 };
|