Skip to content
0

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 ​

ts
const assistant = AssistantService.getInstance();
assistant.useInitAssistant({ model: "qwen3.8-max" });
const result = await assistant.useReply(undefined, "Hello!");

Implements ​

Methods ​

useCreateSession() ​

ts
useCreateSession(channel?): Promise<string>;

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

Creates a new conversation session.

Parameters ​

ParameterTypeDescription
channel?stringOptional free-form channel tag (e.g. "rest").

Returns ​

Promise<string>

The new session id.

Implementation of ​

IAssistantService.useCreateSession


useGetHistory() ​

ts
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 ​

ParameterTypeDescription
sessionIdstringThe 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() ​

ts
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 ​

ParameterTypeDescription
configAssistantInitConfigAssistant configuration.

Returns ​

void

Example ​

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

Implementation of ​

IAssistantService.useInitAssistant


useReply() ​

ts
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 ​

ParameterTypeDescription
sessionIdstring | undefinedExisting session id, or undefined to start a new one.
textstringThe user's message.
optionsAssistantReplyOptionsOptional completion options.

Returns ​

Promise<AssistantResult>

An AssistantResult with the reply and session id.

Example ​

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

Implementation of ​

IAssistantService.useReply


useResetSession() ​

ts
useResetSession(sessionId): Promise<void>;

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

Deletes a conversation session and its messages.

Parameters ​

ParameterTypeDescription
sessionIdstringThe conversation session id to reset.

Returns ​

Promise<void>

Implementation of ​

IAssistantService.useResetSession


useSessionExists() ​

ts
useSessionExists(sessionId): Promise<boolean>;

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

Checks whether a conversation session exists.

Parameters ​

ParameterTypeDescription
sessionIdstringThe conversation session id.

Returns ​

Promise<boolean>

true when the session exists.

Implementation of ​

IAssistantService.useSessionExists


getInstance() ​

ts
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.

Released under the MIT License.