UNPKG

grok-api-ts

Version:

TypeScript client for interacting with Grok AI with automated login and cookie management

143 lines 4.25 kB
export interface GrokResponseToken { token: string; isThinking: boolean; isSoftStop: boolean; responseId: string; } export interface GrokFinalMetadata { followUpSuggestions: string[]; feedbackLabels: string[]; toolsUsed: Record<string, any>; } export interface GrokModelResponse { responseId: string; message: string; sender: string; createTime: string; parentResponseId: string; manual: boolean; partial: boolean; shared: boolean; query: string; queryType: string; webSearchResults: any[]; xpostIds: string[]; xposts: any[]; generatedImageUrls: string[]; imageAttachments: any[]; fileAttachments: any[]; cardAttachmentsJson: any[]; fileUris: string[]; fileAttachmentsMetadata: any[]; isControl: boolean; steps: any[]; mediaTypes: string[]; } export interface GrokTitle { newTitle: string; } export interface GrokConversation { conversationId: string; title: string; starred: boolean; createTime: string; modifyTime: string; systemPromptName: string; temporary: boolean; mediaTypes: string[]; } export interface GrokResponse { result: { response?: { token?: string; isThinking?: boolean; isSoftStop?: boolean; responseId?: string; finalMetadata?: GrokFinalMetadata; modelResponse?: GrokModelResponse; userResponse?: any; }; title?: GrokTitle; token?: string; isThinking?: boolean; isSoftStop?: boolean; responseId?: string; finalMetadata?: GrokFinalMetadata; modelResponse?: GrokModelResponse; userResponse?: any; conversation?: GrokConversation; }; } export interface ParsedGrokResponse { fullMessage: string; responseId: string | undefined; title: string | undefined; metadata: GrokFinalMetadata | undefined; modelResponse: GrokModelResponse | undefined; conversationId: string | undefined; } export interface GrokSendMessageOptions { message: string; disableSearch?: boolean; enableImageGeneration?: boolean; customInstructions?: string; forceConcise?: boolean; imageAttachments?: GrokImageAttachment[]; conversationId?: string; parentResponseId?: string; isReasoning?: boolean; } export interface GrokImageAttachment { fileMetadataId: string; fileMimeType: string; fileName: string; fileUri: string; parsedFileUri: string; createTime: string; } export interface GrokUploadResponse { fileMetadataId: string; fileMimeType: string; fileName: string; fileUri: string; parsedFileUri: string; createTime: string; } export interface GrokStreamCallbacks { onToken?: (token: string) => void; onComplete?: (response: ParsedGrokResponse) => void; onError?: (error: any) => void; } export declare class GrokAPI { private cookieStrings; private lastConversationId; private lastResponseId; private cookiesPath; constructor(cookieStrings?: string[], cookiesPath?: string); private loadCookiesFromFile; private saveCookiesToFile; /** * Automates the login process using patchright * @param username The Grok username (email) * @param password The Grok password */ login(username: string, password: string): Promise<boolean>; isAuthenticated(): boolean; /** * Ensures the user is authenticated before making API calls * @param username Optional username for login * @param password Optional password for login */ ensureAuthenticated(username?: string, password?: string): Promise<boolean>; sendMessage(options: GrokSendMessageOptions): Promise<ParsedGrokResponse>; continueConversation(message: string, options?: Omit<GrokSendMessageOptions, 'message'>): Promise<ParsedGrokResponse>; getConversationInfo(): { conversationId: string; lastResponseId: string; }; private parseGrokResponse; private setCookies; sendMessageStream(options: GrokSendMessageOptions, callbacks: GrokStreamCallbacks): Promise<void>; private extractEssentialCookies; } //# sourceMappingURL=grokApi.d.ts.map