katanakit-js / AssistantService
Class: AssistantService
Defined in: src/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.
Example
const assistant = AssistantService.getInstance();
assistant.useInitAssistant({ model: "qwen3.8-max" });
const result = await assistant.useReply(undefined, "Hello!");Implements
Methods
useCreateSession()
useCreateSession(channel?): Promise<string>;Defined in: src/core/services/assistant.service.ts:165
Creates a new conversation session.
Parameters
| Parameter | Type | Description |
|---|---|---|
channel? | string | Optional free-form channel tag (e.g. "rest"). |
Returns
Promise<string>
The new session id.
Implementation of
IAssistantService.useCreateSession
useGetHistory()
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: src/core/services/assistant.service.ts:185
Returns the full message history of a session, oldest first.
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The conversation session id. |
Returns
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.
Implementation of
IAssistantService.useGetHistory
useInitAssistant()
useInitAssistant(config?): void;Defined in: src/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).
Parameters
| Parameter | Type | Description |
|---|---|---|
config | AssistantInitConfig | Assistant configuration. |
Returns
void
Example
AssistantService.getInstance().useInitAssistant({ model: "qwen3.8-max" });Implementation of
IAssistantService.useInitAssistant
useReply()
useReply(
sessionId,
text,
options?
): Promise<AssistantResult>;Defined in: src/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.
Parameters
| 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. |
Returns
Promise<AssistantResult>
An AssistantResult with the reply and session id.
Example
const result = await AssistantService.getInstance().useReply(undefined, "Hello!");
if (result.ok) console.log(result.data.reply);Implementation of
useResetSession()
useResetSession(sessionId): Promise<void>;Defined in: src/core/services/assistant.service.ts:194
Deletes a conversation session and its messages.
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The conversation session id to reset. |
Returns
Promise<void>
Implementation of
IAssistantService.useResetSession
useSessionExists()
useSessionExists(sessionId): Promise<boolean>;Defined in: src/core/services/assistant.service.ts:175
Checks whether a conversation session exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
sessionId | string | The conversation session id. |
Returns
Promise<boolean>
true when the session exists.
Implementation of
IAssistantService.useSessionExists
getInstance()
static getInstance(): AssistantService;Defined in: src/core/services/assistant.service.ts:124
Obtiene la instancia única del AssistantService (Singleton).
Returns
AssistantService
La instancia única de AssistantService.