import type { AgentResult, AgentRunOptions, AiChatOptions, AiMessage, AiProviderConfig, AiResult, AiTool, AiToolCall } from "../../types/index.js"; /** Default endpoint for Alibaba Cloud Model Studio (DashScope) compatible mode. */ export declare const KITT_BASE_URL = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"; /** Default model for the Kitt assistant preset. */ export declare const KITT_DEFAULT_MODEL = "qwen3.8-max"; /** Default system prompt injected when the agent is configured without one. */ export declare const KITT_SYSTEM_PROMPT = "You are Kitt, a helpful assistant. Answer clearly and concisely."; /** Reusable preset (base URL + model) for the Kitt assistant. */ export declare const kittPreset: Pick; /** Shape of a `/chat/completions` response. */ interface ChatCompletionResponse { choices?: Array<{ message?: { content?: string | null; tool_calls?: AiToolCall[]; }; finish_reason?: string | null; }>; error?: { message?: string; }; } /** Request options shared by chat and agent calls. */ interface RequestOptions { temperature?: number; maxTokens?: number; topP?: number; signal?: AbortSignal; tools?: AiTool[]; } /** * Estrategia de proveedor AI - Strategy Pattern. * * Define el contrato que toda implementación de proveedor de completions debe * cumplir. El {@link AgentService} delega la llamada HTTP en una estrategia * concreta, permitiendo intercambiar proveedores (DashScope, OpenAI, * self-hosted, mock en tests) sin tocar el bucle del agente. */ export interface IAiProviderStrategy { /** * Performs a single `chat/completions` request against the provider. * * @param config - Provider configuration (baseUrl, model, apiKey). * @param messages - Conversation messages. * @param options - Sampling options, tools and abort signal. * @returns The parsed provider response. * @throws On non-2xx responses or transport failures. */ requestCompletion(config: AiProviderConfig, messages: AiMessage[], options: RequestOptions): Promise; } /** * Estrategia por defecto: proveedor compatible con OpenAI * (`POST /chat/completions` con Bearer token). Cubre DashScope en modo * compatible, OpenAI, Azure OpenAI y la mayoría de endpoints self-hosted. * * @example * ```ts * const strategy = new OpenAiCompatibleStrategy(); * const response = await strategy.requestCompletion(config, messages, {}); * ``` */ export declare class OpenAiCompatibleStrategy implements IAiProviderStrategy { /** * Performs a raw `chat/completions` request against the provider. * Throws {@link AiHttpError} on non-2xx responses. */ requestCompletion(config: AiProviderConfig, messages: AiMessage[], options: RequestOptions): Promise; } /** * AgentService - Singleton facade con Strategy Pattern. * * Centraliza el registro del proveedor AI y el bucle de completions, * delegando la llamada HTTP en una {@link IAiProviderStrategy} * intercambiable. Por defecto usa {@link OpenAiCompatibleStrategy}. * * @example * ```ts * // Configurar el proveedor * AgentService.getInstance().useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY }); * * // Cambiar de estrategia en runtime (p. ej. un mock en tests) * AgentService.getInstance().useSetStrategy(new OpenAiCompatibleStrategy()); * ``` */ export declare class AgentService { private static instance; private provider; private strategy; /** * Constructor privado - enforce singleton. * @param strategy - Estrategia de proveedor a inyectar (opcional). */ private constructor(); /** * Obtiene la instancia única del AgentService (Singleton). * * @returns La instancia única de {@link AgentService}. */ static getInstance(): AgentService; /** * Crea una instancia NO-singleton con una estrategia específica. * Útil para tests o para aislar varios proveedores. * * @param strategy - Estrategia a inyectar. * @returns Una nueva instancia de {@link AgentService}. */ static create(strategy?: IAiProviderStrategy): AgentService; /** * Intercambia la estrategia de proveedor en runtime (Strategy Pattern). * * @param strategy - La nueva estrategia a utilizar. */ useSetStrategy(strategy: IAiProviderStrategy): void; /** Returns the currently active provider strategy. */ useGetStrategy(): IAiProviderStrategy; /** Retrieves the configured provider or throws. */ private useGetProvider; /** * Registers the AI provider for the Kitt assistant. * * `apiKey` falls back to `process.env.DASHSCOPE_API_KEY`; `baseUrl`, `model` * and `systemPrompt` fall back to the {@link kittPreset} defaults. * * @param config - Partial provider configuration. * * @example * ```ts * import { useInitAgent } from "katanakit-js"; * * useInitAgent({ * apiKey: process.env.DASHSCOPE_API_KEY, * model: "qwen3.8-max", * }); * ``` */ useInitAgent(config?: Partial): void; /** * Sends a single chat completion and returns the assistant text as a Safe Result. * * Use this for review / questioning (single-shot). For autonomous multi-step * work with tools, use {@link useRunAgent}. * * @param messages - Conversation messages (a system prompt is prepended if absent). * @param options - Optional completion options. * @returns A `AiResult` with the assistant text. * * @example * ```ts * import { useChat } from "katanakit-js"; * * const result = await useChat([ * { role: "user", content: "Summarize the benefits of solar energy in three bullet points." }, * ]); * if (result.ok) console.log(result.data); * ``` */ useChat(messages: AiMessage[], options?: AiChatOptions): Promise>; /** * Runs the tool-calling agent loop against a goal until it emits a final * answer or exhausts `maxSteps`. * * @param goal - The natural-language objective. * @param options - Tools, step budget and completion options. * @returns An `AgentResult` with the final message and executed steps. * * @example * ```ts * import { useRunAgent } from "katanakit-js"; * * const result = await useRunAgent("Fix the type errors reported by tsc", { * tools: [ * { * name: "runCommand", * description: "Runs a shell command and returns its output", * parameters: { type: "object", properties: { command: { type: "string" } } }, * execute: (input) => shell.run(input.command), * }, * ], * maxSteps: 12, * }); * ``` */ useRunAgent(goal: string, options?: AgentRunOptions): Promise; } /** * Registers the AI provider for the Kitt assistant. * * @param config - Partial provider configuration. * * @example * ```ts * import { useInitAgent } from "katanakit-js"; * * useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY }); * ``` */ export declare function useInitAgent(config?: Partial): void; /** * Sends a single chat completion and returns the assistant text as a Safe Result. * * @param messages - Conversation messages (a system prompt is prepended if absent). * @param options - Optional completion options. * @returns An `AiResult` with the assistant text. * * @example * ```ts * import { useChat } from "katanakit-js"; * * const result = await useChat([{ role: "user", content: "Hello" }]); * if (result.ok) console.log(result.data); * ``` */ export declare function useChat(messages: AiMessage[], options?: AiChatOptions): Promise>; /** * Runs the tool-calling agent loop against a goal until it emits a final * answer or exhausts `maxSteps`. * * @param goal - The natural-language objective. * @param options - Tools, step budget and completion options. * @returns An `AgentResult` with the final message and executed steps. * * @example * ```ts * import { useRunAgent } from "katanakit-js"; * * const result = await useRunAgent("Fix the type errors reported by tsc"); * ``` */ export declare function useRunAgent(goal: string, options?: AgentRunOptions): Promise; export {}; //# sourceMappingURL=agent.service.d.ts.map