import { ID, UIOptions, UIOptionsSchema } from "../index.node-Cl9AwUCW.js"; import { BuildLog, BuildResult } from "../index-BcKU69uH.js"; import { UIMessage, UIMessageChunk } from "ai"; import * as react0 from "react"; //#region src/agent/client/index.d.ts interface ClientOptions { readonly baseUrl: string; readonly headers?: Record; } type CapabilitiesResponse = Awaited>; /** * Client is a client for the Blink agent HTTP API. */ declare class Client { readonly baseUrl: string; private readonly client; constructor(options: ClientOptions); /** * chat starts chatting with the agent. */ chat(request: { id: ID; messages: UIMessage[]; }, options?: { signal?: AbortSignal; headers?: Record; }): Promise>; /** * capabilities returns the capabilities of the agent. * This is used to check if the agent supports requests and completions. */ capabilities(): Promise<{ ui: boolean; chat: boolean; request: boolean; error: boolean; }>; ui(request: { selectedOptions?: UIOptions; }, options?: { signal?: AbortSignal; }): Promise; /** * health simply returns a 200 response. * This is used to check if the agent is running. */ health(): Promise; private handleError; } //#endregion //#region src/local/rw-lock.d.ts declare class ReadLock { private onRelease; constructor(onRelease: () => void); [Symbol.dispose](): void; } declare class WriteLock { private onRelease; constructor(onRelease: () => void); [Symbol.dispose](): void; } /** * RWLock is a read/write lock that allows multiple concurrent readers * or a single writer. Writers wait for all readers to finish before acquiring * the lock. * * This is designed for in-memory, single-process synchronization using the * explicit resource management pattern (Symbol.dispose). * * Example usage: * ```typescript * const lock = new RWLock(); * * // Multiple readers can acquire the lock concurrently * using readLock = await lock.read(); * // ... do read operations ... * * // Writers wait for all readers to finish * using writeLock = await lock.write(); * // ... do write operations ... * ``` */ declare class RWLock { private _lock; /** * Acquire a read lock. Multiple readers can hold the lock concurrently. * If a writer is waiting, new readers will wait until the writer completes. * * The lock is automatically released when the returned object is disposed. */ read(): Promise; /** * Acquire a write lock. Waits for all readers to finish before acquiring. * Only one writer can hold the lock at a time. * * The lock is automatically released when the returned object is disposed. */ write(): Promise; } //#endregion //#region src/react/use-agent.d.ts interface AgentLog { readonly level: "log" | "error"; readonly message: string; } interface UseAgentOptions { readonly buildResult?: BuildResult; readonly env?: Record; readonly apiServerUrl?: string; } interface Agent { readonly client: Client; readonly lock: RWLock; } declare function useAgent(options: UseAgentOptions): { agent: Agent | undefined; logs: AgentLog[]; error: Error | undefined; capabilities: { ui: boolean; chat: boolean; request: boolean; error: boolean; } | undefined; }; //#endregion //#region src/react/use-auth.d.ts interface UseAuthOptions { /** * Whether to automatically check auth status on mount. * @default true */ readonly autoCheck?: boolean; /** * Callback when authentication status changes. */ readonly onAuthChange?: (user: UserInfo | undefined) => void; /** * Callback when login URL is generated (for custom UI flows). */ readonly onLoginUrl?: (url: string, id: string) => void; /** * Optional test path for auth token file (for testing only). * When set, uses this path instead of the default XDG config path. */ readonly testAuthPath?: string; } interface UserInfo { readonly email: string; } interface UseAuth { /** Current user info if authenticated, undefined if not */ readonly user: UserInfo | undefined; /** Current auth token (if any) */ readonly token: string | undefined; /** Error message if any */ readonly error: string | undefined; /** * Start the login flow. This will: * 1. Generate a login URL via the API * 2. Call onLoginUrl callback (if provided) * 3. Wait for authentication to complete * 4. Save the token and fetch user info * * @returns The authenticated user info */ readonly login: () => Promise; /** * Logout the current user by clearing the token. */ readonly logout: () => void; } /** * Hook for managing Blink authentication state. * This is UI-agnostic and can be used in both TUI and Desktop apps. */ declare function useAuth(options?: UseAuthOptions): UseAuth; //#endregion //#region src/react/use-logger.d.ts type Source = "system" | "agent"; type PrintLog = (level: "error" | "log", source: Source, ...message: unknown[]) => Promise; declare class Logger { private printLog; constructor(printLog: PrintLog); setPrintLog(printLog: PrintLog): void; error(source: Source, ...message: [unknown, ...unknown[]]): void; log(source: Source, ...message: [unknown, ...unknown[]]): void; flush(): Promise; } declare const LoggerContext: react0.Context; //#endregion //#region src/react/use-bundler.d.ts type BundlerStatus = "building" | "success" | "error"; interface BundlerContext { readonly error: BuildLog | undefined; readonly result: BuildResult | undefined; readonly entry: string; readonly outdir: string; readonly status: BundlerStatus; } interface UseBundlerOptions { readonly directory: string; readonly logger: Logger; readonly onBuildStart?: () => void; readonly onBuildSuccess?: (result: BuildResult & { duration: number; }) => void; readonly onBuildError?: (error: BuildLog) => void; } /** * useBundler is a hook that builds the agent and provides the build result. * * @param options - Options for the bundler (or just directory string for backwards compatibility). * @returns Context for the bundler. */ declare function useBundler(options: UseBundlerOptions | string): BundlerContext; //#endregion //#region src/local/disk-store.d.ts interface LockedStoreEntry { get: () => Promise; set: (value: T) => Promise; update: (value: Partial) => Promise; delete: () => Promise; release: () => Promise; } interface StoreEntry { key: string; locked: boolean; pid?: number; mtime: number; } /** * DiskStore is a key-value store that persists to disk. * It works with filesystem locks - so multiple processes can * read and write to the store concurrently. */ //#endregion //#region src/local/types.d.ts interface StoredChat { id: ID; key?: string; created_at: string; updated_at: string; messages: StoredMessage[]; } type StoredMessageMetadata = { __blink_internal: true; }; interface StoredMessage> { readonly id: ID; readonly created_at: string; readonly metadata: T["metadata"]; readonly parts: T["parts"]; readonly role: T["role"]; readonly mode: "run" | "edit"; } /** * Helper to convert UIMessage to StoredMessage */ //#endregion //#region src/local/chat-manager.d.ts type ChatStatus = "idle" | "streaming" | "error"; interface ChatState { readonly id: ID; readonly key?: string; readonly created_at?: string; readonly updated_at?: string; readonly messages: StoredMessage[]; readonly status: ChatStatus; readonly streamingMessage?: StoredMessage; readonly loading: boolean; readonly queuedMessages: StoredMessage[]; readonly queuedLogs: StoredMessage[]; } interface ChatManagerOptions { readonly chatId?: ID; readonly chatsDirectory: string; /** * Optional function to filter messages before persisting them. * Return undefined to skip persisting the message. */ readonly serializeMessage?: (message: UIMessage) => StoredMessage | undefined; /** * Optional function to filter messages before sending to the agent. * Return true to include the message, false to exclude it. */ readonly filterMessages?: (message: StoredMessage) => boolean; /** * Optional callback invoked when an error occurs during chat operations. */ readonly onError?: (error: string) => void; } type StateListener = (state: ChatState) => void; /** * ChatManager handles all chat state and operations outside of React. * This makes it easier to test and reason about race conditions. */ declare class ChatManager { private chatId; private agent; private chatStore; private serializeMessage?; private filterMessages?; private onError?; private chat; private loading; private streamingMessage; private status; private queue; private logQueue; private abortController; private isProcessingQueue; private listeners; private watcher; private disposed; constructor(options: ChatManagerOptions); /** * Update the agent instance to be used for chats */ setAgent(agent: Agent | undefined): void; /** * Get the current state */ getState(): ChatState; /** * Subscribe to state changes */ subscribe(listener: StateListener): () => void; /** * Upsert a message to the chat */ upsertMessages(messages: UIMessage[], lock?: LockedStoreEntry): Promise; deleteMessages(ids: string[]): Promise; queueLogMessage({ message: logMessage, level, source }: { message: string; level: "error" | "log"; source: Source; }): Promise; private flushLogQueue; /** * Send a message to the agent */ sendMessages(messages: StoredMessage[]): Promise; start(): Promise; stop(): Promise; private processQueueOrRun; /** * Stop the current streaming operation */ stopStreaming(): void; /** * Clear all queued messages */ clearQueue(): void; /** * Reset the chat (delete from disk) */ resetChat(): Promise; /** * Dispose of the manager (cleanup) */ dispose(): void; private resetChatState; private notifyListeners; } //#endregion //#region src/react/use-chat.d.ts interface UseChatOptions { readonly chatId: ID; readonly agent: Agent | undefined; readonly chatsDirectory: string; /** * Optional function to filter messages before persisting them. * Return undefined to skip persisting the message. */ readonly serializeMessage?: (message: UIMessage) => StoredMessage | undefined; /** * Optional function to filter messages before sending to the agent. * Return true to include the message, false to exclude it. */ readonly filterMessages?: (message: StoredMessage) => boolean; /** * Optional callback invoked when an error occurs during chat operations. */ readonly onError?: (error: string) => void; } interface UseChat extends ChatState { readonly sendMessage: (message: StoredMessage) => Promise; readonly upsertMessage: (message: StoredMessage) => Promise; readonly queueLogMessage: ChatManager["queueLogMessage"]; readonly deleteMessage: (id: string) => Promise; readonly stopStreaming: () => void; readonly resetChat: () => Promise; readonly clearQueue: () => void; readonly start: () => Promise; } declare function useChat(options: UseChatOptions): UseChat; //#endregion //#region src/local/server.d.ts interface CreateLocalServerOptions { readonly dataDirectory: string; readonly port?: number; readonly getAgent: () => Agent | undefined; } type LocalServer = ReturnType; /** * createLocalServer creates a local control server that * can be used to control the Blink agent. * * This server: * - Provides the control API for agents to interact with chats * - Persists chats to disk using the disk store * - Runs agents when messages are sent */ declare function createLocalServer(options: CreateLocalServerOptions): { url: string; chatsDirectory: string; getChatManager: (chatId: ID) => ChatManager; listChats: () => Promise; dispose: () => void; }; //#endregion //#region src/react/use-dev-mode.d.ts type DevMode = "run" | "edit"; interface UseDevModeOptions { readonly directory: string; readonly logger: Logger; readonly onBuildStart?: () => void; readonly onBuildSuccess?: (result: { duration: number; }) => void; readonly onBuildError?: (error: BuildLog) => void; readonly onEnvLoaded?: (keys: string[]) => void; readonly onDevhookConnected?: (url: string) => void; readonly onAgentLog?: (log: AgentLog) => void; readonly onDevhookRequest?: (request: { method: string; path: string; status: number; }) => void; readonly onError?: (error: string) => void; readonly onModeChange?: (mode: DevMode) => void; readonly onAuthChange?: (user: UserInfo | undefined) => void; readonly onLoginUrl?: (url: string, id: string) => void; } interface BuildStatus { readonly status: BundlerStatus; readonly error: BuildLog | undefined; readonly entrypoint: string; } interface TokenUsage { readonly inputTokens: number; readonly outputTokens: number; readonly totalTokens: number; readonly cachedInputTokens?: number; } interface DevhookStatus { readonly connected: boolean; readonly url: string | undefined; } interface AgentOptions { readonly schema: UIOptionsSchema | undefined; readonly selected: UIOptions | undefined; readonly error: Error | undefined; readonly setOption: (id: string, value: string) => void; } interface ApprovalRequest { readonly message: UIMessage; readonly approve: (autoApprove?: boolean) => Promise; readonly reject: () => Promise; readonly autoApproveEnabled: boolean; } interface UseDevMode { readonly mode: DevMode; readonly setMode: (mode: DevMode) => void; readonly toggleMode: () => void; readonly chat: UseChat; readonly chats: ID[]; readonly switchChat: (id: ID) => void; readonly newChat: () => void; readonly build: BuildStatus; readonly devhook: DevhookStatus; readonly capabilities: CapabilitiesResponse | undefined; readonly options: AgentOptions; readonly approval: ApprovalRequest | undefined; readonly tokenUsage: TokenUsage | undefined; readonly auth: UseAuth; readonly server: LocalServer; readonly showWaitingPlaceholder: boolean; readonly editModeMissingApiKey: boolean; } /** * useDevMode abstracts all the business logic for running/editing an agent. * This hook is UI-agnostic and can be used in both TUI and Desktop apps. */ declare function useDevMode(options: UseDevModeOptions): UseDevMode; //#endregion //#region src/react/use-devhook.d.ts interface UseDevhookOptions { readonly id?: string; readonly disabled?: boolean; readonly onRequest: (request: Request) => Promise; readonly directory: string; readonly logger: Logger; } declare function useDevhook(options: UseDevhookOptions): { id: string | undefined; url: string | undefined; status: "error" | "connected" | "disconnected"; }; //#endregion //#region src/react/use-dotenv.d.ts declare function useDotenv(directory: string, logger: Logger, name?: string): Record; //#endregion //#region src/react/use-edit-agent.d.ts interface UseEditAgentOptions { readonly directory: string; readonly apiServerUrl?: string; readonly env: Record; readonly getDevhookUrl: () => Promise; } interface ClientAndLock { readonly client: Client; readonly lock: RWLock; } declare function useEditAgent(options: UseEditAgentOptions): { agent: ClientAndLock | undefined; error: Error | undefined; missingApiKey: boolean; setUserAgentUrl: (url: string) => void; }; //#endregion //#region src/react/use-options.d.ts /** * useOptions is a hook that provides the selectable and selected options * for a given agent. * * @param agent - The agent to use. * @param messages - The messages to use. * @returns The selectable and selected options. */ declare function useOptions({ agent, capabilities, messages }: { agent?: Pick; capabilities?: CapabilitiesResponse; messages: UIMessage[]; }): { schema: UIOptionsSchema | undefined; options: UIOptions | undefined; setOption: (id: string, value: string) => void; loading: boolean; error: Error | undefined; }; //#endregion export { Logger, LoggerContext, useAgent, useAuth, useBundler, useChat, useDevMode, useDevhook, useDotenv, useEditAgent, useOptions };