UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

146 lines (145 loc) 7.72 kB
import { Observable } from 'rxjs'; import { AiFunctionMetadata } from '../../internal-common/src/public-types/ai-function.public-types'; import { AiQueryOptions, AiQueryResponse, ExecuteAiApiResponse } from '../../internal-common/src/public-types/ai-query.public-types'; import { AiAgentClientOptions } from './agent/ai-agent-client'; import { AiAgentReference } from './agent/ai-agent-client-reference'; import { AiAudioClient } from './ai-audio-client'; import { AiFilesClient } from './ai-files-client'; import { AiImageClient } from './ai-image-client'; import { AiKnowledgeBaseReference } from './ai-knowledge-base/ai-knowledge-base-client-reference'; import { AiMatchMakingClient } from './ai-matchmaking-client'; import { AiAgent, AiAgentApiIntegrationOptions, AiAgentId, AiFileProviderType, AiKnowledgeBase, AiKnowledgeBaseId, AiProviderType, AiSessionContext, AiStatusMessage, ApplicationAiSettings, IntegrationId, JobId, ListChatModelsRequest, ModelIdSpec, SecretKey } from './public-types'; /** * AiClient class serves as a facade for interacting with different AI services. * It provides simplified access to AI chatbot and assistant functionalities * through its methods. * @category AI */ export declare class AiClient { private readonly socketManager; private readonly rpcManager; private readonly jobClient; private readonly backendFunctionManager; private readonly getMetricAnnotations; private aiAgentClient?; private aiKnowledgeBaseClient?; /** * Returns a reference to the specified AI agent. * If no ID is provided, the built-in agent is used by default. */ agent(agentId?: AiAgentId, options?: AiAgentClientOptions | undefined): AiAgentReference; /** * Returns a reference to the specified AI knowledge base. */ knowledgeBase(knowledgeBaseId: AiKnowledgeBaseId): AiKnowledgeBaseReference; /** * Lists all available AI agents. */ listAgents(): Promise<Array<AiAgent>>; /** * Lists all available AI Knowledge Bases. */ listKnowledgeBases(): Promise<Array<AiKnowledgeBase>>; /** * Lists all available AI functions in the application. * @returns A promise that resolves to an array of AI function metadata. */ listFunctions(): Promise<Array<AiFunctionMetadata>>; /** * Returns a list of all available AI chat models. * Includes both Squid-provided vendor models and custom integration models. * Vendor models carry a human-readable `description`. Deprecated vendor models are * included only when `options.includeDeprecated` is true and are marked with `replacedBy`. */ listChatModels(options?: ListChatModelsRequest): Promise<ModelIdSpec[]>; /** * Retrieves an AI image client. */ image(): AiImageClient; /** * Retrieves an AI audio client. */ audio(): AiAudioClient; /** * Retrieves an AI match-making client. * @deprecated - Use `knowledgebase('kbId').searchContextsWith*()` instead. */ matchMaking(): AiMatchMakingClient; /** * Creates a client to manage files for a specific AI provider. * * @param provider - The AI provider (openai, gemini, or anthropic). * @returns An AiFilesClient bound to the specified provider. * @example * ```typescript * const openaiFiles = squid.ai().files('openai'); * const fileId = await openaiFiles.uploadFile({ file }); * await openaiFiles.deleteFile(fileId); * ``` */ files(provider: AiFileProviderType): AiFilesClient; /** * Executes an AI query using a specific DB integration, sending a prompt to the AI and returning its response. * This function allows for direct interaction with the AI's capabilities by sending text prompts and receiving * the AI's responses, which can be used for various applications such as automating tasks, generating content, * or obtaining information. * * @param integrationId The identifier for the DB integration which is used to direct the query to the * appropriate DB. * @param prompt The text prompt to send to the AI. This should be formulated in a way that the AI can * understand and respond to, taking into account the nature of the task or the information * sought. * @param options Additional options to customize the query execution. * @param abortSignal Optional signal used to abort the underlying request. When the signal aborts, the in-flight * HTTP request is cancelled and its promise rejects, allowing callers to bound a single call * without leaking the request. * @returns A promise that resolves to an `ExecuteAiQueryResponse`. This response includes the AI's * reply to the provided prompt, along with any other relevant information that is part of * the AI's response. The promise can be awaited to handle the response asynchronously. * * @example * ``` * const response = await squid.ai().executeAiQuery(myDbIntegrationId, "How many transactions ran yesterday?"); * console.log(response); * ``` * * Can be used with an API key or using a security rule with @secureAiQuery() decorator. * * For more details on the usage and capabilities of the AI Assistant, refer to the documentation provided at * {@link https://docs.squid.cloud/docs/ai}. */ executeAiQuery(integrationId: IntegrationId, prompt: string, options?: AiQueryOptions, abortSignal?: AbortSignal): Promise<AiQueryResponse>; /** * Executes an AI-powered API call using a specific integration. * The AI will select appropriate endpoints, generate request bodies, * and analyze responses to answer the provided prompt. * * @param integrationId - The API integration to use * @param prompt - Natural language description of what to accomplish * @param options - Optional configuration including allowed endpoints and verbose updates * @param sessionContext - Optional session context for audit trails and tracing * @returns Promise resolving to the API call result with answer and execution details */ executeAiApiCall(integrationId: IntegrationId, prompt: string, options?: AiAgentApiIntegrationOptions, sessionContext?: AiSessionContext): Promise<ExecuteAiApiResponse>; /** * Returns name of the secret that stores API key for the given AI provider type. * This API key is used for all requests to the AI provider done from the application. */ getApplicationAiSettings(): Promise<ApplicationAiSettings>; /** Sets new application AI settings. Overwrites the existing value. */ setApplicationAiSettings(settings: ApplicationAiSettings): Promise<void>; /** * Sets the name of the secret that stores API key for the given AI provider type. * This API key is used for all requests to the AI provider done from the application. * To delete the existing secret key use 'undefined' for the name of the secret. * Returns the updated state of the AI application settings. */ setAiProviderApiKeySecret(providerType: AiProviderType, secretKey: SecretKey | undefined): Promise<ApplicationAiSettings>; /** * Observes live status messages for all AI updates. * @param jobId (Optional) If provided, filters status updates to only those related to the given job ID. */ observeStatusUpdates(jobId?: JobId): Observable<AiStatusMessage>; private getAiAgentClient; private getAiKnowledgeBaseClient; }