Skip to content

AssistantService

katanakit-js / AssistantService

Defined in: core/services/assistant.service.ts:104

AssistantService - Singleton para el asistente conversacional.

Aplica el patrón Singleton: una única instancia mantiene el store de conversaciones, las herramientas y el presupuesto de pasos del agente. El store es intercambiable (Strategy implícita: in-memory por defecto, Prisma u otro persistente vía useInitAssistant), y la lógica de completado delega en AgentService.

const assistant = AssistantService.getInstance();
assistant.useInitAssistant({ model: "qwen3.8-max" });
const result = await assistant.useReply(undefined, "Hello!");
useCreateSession(channel?): Promise<string>;

Defined in: core/services/assistant.service.ts:165

Creates a new conversation session.

Parameter Type Description
channel? string Optional free-form channel tag (e.g. "rest").

Promise<string>

The new session id.

IAssistantService.useCreateSession


useGetHistory(sessionId): Promise<{
content: string | null;
name?: string;
role: "system" | "user" | "assistant" | "tool";
tool_call_id?: string;
tool_calls?: {
function: {
arguments: string;
name: string;
};
id: string;
type: "function";
}[];
}[]>;

Defined in: core/services/assistant.service.ts:185

Returns the full message history of a session, oldest first.

Parameter Type Description
sessionId string The conversation session id.

Promise<{ content: string | null; name?: string; role: "system" | "user" | "assistant" | "tool"; tool_call_id?: string; tool_calls?: { function: { arguments: string; name: string; }; id: string; type: "function"; }[]; }[]>

The accumulated messages.

IAssistantService.useGetHistory


useInitAssistant(config?): void;

Defined in: core/services/assistant.service.ts:146

Configures the assistant: provider (Kitt) plus an optional conversation store.

Defaults mirror useInitAgent: apiKey falls back to process.env.DASHSCOPE_API_KEY, and baseUrl/model/systemPrompt fall back to the Kitt preset. The default store is in-memory; pass { store } to persist conversations (e.g. a Prisma-backed store).

Parameter Type Description
config? AssistantInitConfig Assistant configuration.

void

AssistantService.getInstance().useInitAssistant({ model: "qwen3.8-max" });

IAssistantService.useInitAssistant


useReply(
sessionId,
text,
options?
): Promise<AssistantResult>;

Defined in: core/services/assistant.service.ts:214

Sends a user message within a conversation and returns the assistant reply. If no sessionId is provided, a new session is created. The user message and the assistant reply are persisted only on success.

Parameter Type Description
sessionId string | undefined Existing session id, or undefined to start a new one.
text string The user’s message.
options? AssistantReplyOptions Optional completion options.

Promise<AssistantResult>

An AssistantResult with the reply and session id.

const result = await AssistantService.getInstance().useReply(
undefined,
"Hello!",
);
if (result.ok) console.log(result.data.reply);

IAssistantService.useReply


useResetSession(sessionId): Promise<void>;

Defined in: core/services/assistant.service.ts:194

Deletes a conversation session and its messages.

Parameter Type Description
sessionId string The conversation session id to reset.

Promise<void>

IAssistantService.useResetSession


useSessionExists(sessionId): Promise<boolean>;

Defined in: core/services/assistant.service.ts:175

Checks whether a conversation session exists.

Parameter Type Description
sessionId string The conversation session id.

Promise<boolean>

true when the session exists.

IAssistantService.useSessionExists


static getInstance(): AssistantService;

Defined in: core/services/assistant.service.ts:124

Obtiene la instancia única del AssistantService (Singleton).

AssistantService

La instancia única de AssistantService.