katanakit-js 6.2.0 → 6.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/dist/adapters/better-auth/better-auth.service.d.ts +83 -0
- package/dist/adapters/better-auth/better-auth.service.d.ts.map +1 -0
- package/dist/adapters/better-auth/better-auth.service.js +110 -0
- package/dist/adapters/better-auth/better-auth.service.js.map +1 -0
- package/dist/adapters/better-auth/client.d.ts +51 -0
- package/dist/adapters/better-auth/client.d.ts.map +1 -0
- package/dist/adapters/better-auth/client.js +67 -0
- package/dist/adapters/better-auth/client.js.map +1 -0
- package/dist/adapters/better-auth/index.d.ts +3 -0
- package/dist/adapters/better-auth/index.d.ts.map +1 -0
- package/dist/adapters/better-auth/index.js +3 -0
- package/dist/adapters/better-auth/index.js.map +1 -0
- package/dist/adapters/express/server.d.ts +133 -1
- package/dist/adapters/express/server.d.ts.map +1 -1
- package/dist/adapters/express/server.js +199 -97
- package/dist/adapters/express/server.js.map +1 -1
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/insforge/insforge.service.d.ts +139 -4
- package/dist/adapters/insforge/insforge.service.d.ts.map +1 -1
- package/dist/adapters/insforge/insforge.service.js +383 -213
- package/dist/adapters/insforge/insforge.service.js.map +1 -1
- package/dist/adapters/notion/notion.service.d.ts +130 -144
- package/dist/adapters/notion/notion.service.d.ts.map +1 -1
- package/dist/adapters/notion/notion.service.js +330 -341
- package/dist/adapters/notion/notion.service.js.map +1 -1
- package/dist/adapters/photoswipe/index.d.ts +2 -0
- package/dist/adapters/photoswipe/index.d.ts.map +1 -0
- package/dist/adapters/photoswipe/index.js +2 -0
- package/dist/adapters/photoswipe/index.js.map +1 -0
- package/dist/adapters/photoswipe/photoswipe.service.d.ts +99 -0
- package/dist/adapters/photoswipe/photoswipe.service.d.ts.map +1 -0
- package/dist/adapters/photoswipe/photoswipe.service.js +150 -0
- package/dist/adapters/photoswipe/photoswipe.service.js.map +1 -0
- package/dist/adapters/telegram/telegram.service.d.ts +82 -13
- package/dist/adapters/telegram/telegram.service.d.ts.map +1 -1
- package/dist/adapters/telegram/telegram.service.js +133 -55
- package/dist/adapters/telegram/telegram.service.js.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.d.ts +181 -110
- package/dist/adapters/wordpress/wordpress.service.d.ts.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.js +556 -465
- package/dist/adapters/wordpress/wordpress.service.js.map +1 -1
- package/dist/config/seo.service.d.ts +1 -1
- package/dist/config/seo.service.d.ts.map +1 -1
- package/dist/config/seo.service.js +1 -1
- package/dist/config/seo.service.js.map +1 -1
- package/dist/core/services/access.service.d.ts +167 -4
- package/dist/core/services/access.service.d.ts.map +1 -1
- package/dist/core/services/access.service.js +241 -31
- package/dist/core/services/access.service.js.map +1 -1
- package/dist/core/services/agent.service.d.ts +182 -27
- package/dist/core/services/agent.service.d.ts.map +1 -1
- package/dist/core/services/agent.service.js +296 -164
- package/dist/core/services/agent.service.js.map +1 -1
- package/dist/core/services/assistant.service.d.ts +96 -5
- package/dist/core/services/assistant.service.d.ts.map +1 -1
- package/dist/core/services/assistant.service.js +171 -66
- package/dist/core/services/assistant.service.js.map +1 -1
- package/dist/core/services/dates.service.d.ts +183 -11
- package/dist/core/services/dates.service.d.ts.map +1 -1
- package/dist/core/services/dates.service.js +256 -57
- package/dist/core/services/dates.service.js.map +1 -1
- package/dist/core/services/http.service.d.ts +172 -133
- package/dist/core/services/http.service.d.ts.map +1 -1
- package/dist/core/services/http.service.js +367 -310
- package/dist/core/services/http.service.js.map +1 -1
- package/dist/core/services/logger.service.d.ts +96 -34
- package/dist/core/services/logger.service.d.ts.map +1 -1
- package/dist/core/services/logger.service.js +128 -41
- package/dist/core/services/logger.service.js.map +1 -1
- package/dist/core/services/query.service.d.ts +101 -0
- package/dist/core/services/query.service.d.ts.map +1 -1
- package/dist/core/services/query.service.js +131 -14
- package/dist/core/services/query.service.js.map +1 -1
- package/dist/core/services/utils.service.d.ts +286 -131
- package/dist/core/services/utils.service.d.ts.map +1 -1
- package/dist/core/services/utils.service.js +417 -227
- package/dist/core/services/utils.service.js.map +1 -1
- package/dist/core/services/validation.service.d.ts +48 -3
- package/dist/core/services/validation.service.d.ts.map +1 -1
- package/dist/core/services/validation.service.js +75 -23
- package/dist/core/services/validation.service.js.map +1 -1
- package/dist/infrastructure/decorators/cache.decorator.d.ts +53 -0
- package/dist/infrastructure/decorators/cache.decorator.d.ts.map +1 -0
- package/dist/infrastructure/decorators/cache.decorator.js +47 -0
- package/dist/infrastructure/decorators/cache.decorator.js.map +1 -0
- package/dist/infrastructure/decorators/index.d.ts +4 -0
- package/dist/infrastructure/decorators/index.d.ts.map +1 -0
- package/dist/infrastructure/decorators/index.js +4 -0
- package/dist/infrastructure/decorators/index.js.map +1 -0
- package/dist/infrastructure/decorators/logger.decorator.d.ts +38 -0
- package/dist/infrastructure/decorators/logger.decorator.d.ts.map +1 -0
- package/dist/infrastructure/decorators/logger.decorator.js +66 -0
- package/dist/infrastructure/decorators/logger.decorator.js.map +1 -0
- package/dist/infrastructure/decorators/retry.decorator.d.ts +37 -0
- package/dist/infrastructure/decorators/retry.decorator.d.ts.map +1 -0
- package/dist/infrastructure/decorators/retry.decorator.js +54 -0
- package/dist/infrastructure/decorators/retry.decorator.js.map +1 -0
- package/dist/infrastructure/index.d.ts +1 -0
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +1 -0
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/styles.css +2 -0
- package/package.json +49 -14
- package/scss/_flags.scss +179 -0
- package/scss/_functions.scss +168 -0
- package/scss/_mixins.scss +658 -0
- package/scss/_reset.scss +275 -0
- package/scss/_utilities.scss +449 -0
- package/scss/_variables.scss +539 -0
- package/scss/components/_index.scss +50 -0
- package/scss/demo.scss +12 -0
- package/scss/main.scss +56 -0
|
@@ -9,8 +9,6 @@ export const kittPreset = {
|
|
|
9
9
|
baseUrl: KITT_BASE_URL,
|
|
10
10
|
model: KITT_DEFAULT_MODEL,
|
|
11
11
|
};
|
|
12
|
-
/** Module-level provider registry. */
|
|
13
|
-
let provider = null;
|
|
14
12
|
/** Tag that identifies AI HTTP failures without relying on class identity. */
|
|
15
13
|
const AI_HTTP_ERROR_TAG = "AiHttpError";
|
|
16
14
|
/** Creates a tagged Error preserving the HTTP status and response details. */
|
|
@@ -33,13 +31,6 @@ function readEnvKey() {
|
|
|
33
31
|
}
|
|
34
32
|
return undefined;
|
|
35
33
|
}
|
|
36
|
-
/** Retrieves the configured provider or throws. */
|
|
37
|
-
function getProvider() {
|
|
38
|
-
if (!provider) {
|
|
39
|
-
throw new Error("[AiAgent] No provider configured. Call useInitAgent() first.");
|
|
40
|
-
}
|
|
41
|
-
return provider;
|
|
42
|
-
}
|
|
43
34
|
/** Coerces an unknown error into a message string. */
|
|
44
35
|
function toMessage(error) {
|
|
45
36
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -80,54 +71,73 @@ async function executeToolCall(tools, call) {
|
|
|
80
71
|
return { error: `Tool "${tool.name}" failed: ${message}` };
|
|
81
72
|
}
|
|
82
73
|
}
|
|
74
|
+
/* -------------------------------------------------------------------------- */
|
|
75
|
+
/* Concrete strategies */
|
|
76
|
+
/* -------------------------------------------------------------------------- */
|
|
83
77
|
/** Removes a single trailing slash to build the chat completions URL. */
|
|
84
78
|
function buildCompletionsUrl(baseUrl) {
|
|
85
79
|
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
86
80
|
return `${base}/chat/completions`;
|
|
87
81
|
}
|
|
88
82
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
83
|
+
* Estrategia por defecto: proveedor compatible con OpenAI
|
|
84
|
+
* (`POST /chat/completions` con Bearer token). Cubre DashScope en modo
|
|
85
|
+
* compatible, OpenAI, Azure OpenAI y la mayoría de endpoints self-hosted.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const strategy = new OpenAiCompatibleStrategy();
|
|
90
|
+
* const response = await strategy.requestCompletion(config, messages, {});
|
|
91
|
+
* ```
|
|
91
92
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
body
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Authorization: `Bearer ${config.apiKey}`,
|
|
112
|
-
},
|
|
113
|
-
body: JSON.stringify(body),
|
|
114
|
-
signal: options.signal,
|
|
115
|
-
});
|
|
116
|
-
const text = await response.text();
|
|
117
|
-
let parsed = {};
|
|
118
|
-
if (text) {
|
|
119
|
-
try {
|
|
120
|
-
parsed = JSON.parse(text);
|
|
93
|
+
export class OpenAiCompatibleStrategy {
|
|
94
|
+
/**
|
|
95
|
+
* Performs a raw `chat/completions` request against the provider.
|
|
96
|
+
* Throws {@link AiHttpError} on non-2xx responses.
|
|
97
|
+
*/
|
|
98
|
+
async requestCompletion(config, messages, options) {
|
|
99
|
+
const body = {
|
|
100
|
+
model: config.model,
|
|
101
|
+
messages,
|
|
102
|
+
};
|
|
103
|
+
if (options.temperature !== undefined)
|
|
104
|
+
body.temperature = options.temperature;
|
|
105
|
+
if (options.maxTokens !== undefined)
|
|
106
|
+
body.max_tokens = options.maxTokens;
|
|
107
|
+
if (options.topP !== undefined)
|
|
108
|
+
body.top_p = options.topP;
|
|
109
|
+
if (options.tools && options.tools.length > 0) {
|
|
110
|
+
body.tools = options.tools.map(toWireTool);
|
|
111
|
+
body.tool_choice = "auto";
|
|
121
112
|
}
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
const response = await fetch(buildCompletionsUrl(config.baseUrl), {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
118
|
+
},
|
|
119
|
+
body: JSON.stringify(body),
|
|
120
|
+
signal: options.signal,
|
|
121
|
+
});
|
|
122
|
+
const text = await response.text();
|
|
123
|
+
let parsed = {};
|
|
124
|
+
if (text) {
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(text);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
parsed = { error: { message: text.slice(0, 500) } };
|
|
130
|
+
}
|
|
124
131
|
}
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
throw createAiHttpError(parsed.error?.message ?? response.statusText ?? "Unsuccessful response", response.status, parsed);
|
|
134
|
+
}
|
|
135
|
+
return parsed;
|
|
125
136
|
}
|
|
126
|
-
if (!response.ok) {
|
|
127
|
-
throw createAiHttpError(parsed.error?.message ?? response.statusText ?? "Unsuccessful response", response.status, parsed);
|
|
128
|
-
}
|
|
129
|
-
return parsed;
|
|
130
137
|
}
|
|
138
|
+
/* -------------------------------------------------------------------------- */
|
|
139
|
+
/* Context (Singleton facade) */
|
|
140
|
+
/* -------------------------------------------------------------------------- */
|
|
131
141
|
/** Prepends a system message unless the conversation already defines one. */
|
|
132
142
|
function ensureSystem(messages, fallback) {
|
|
133
143
|
if (messages.some((message) => message.role === "system")) {
|
|
@@ -136,10 +146,239 @@ function ensureSystem(messages, fallback) {
|
|
|
136
146
|
return [{ role: "system", content: fallback }, ...messages];
|
|
137
147
|
}
|
|
138
148
|
/**
|
|
139
|
-
*
|
|
149
|
+
* AgentService - Singleton facade con Strategy Pattern.
|
|
140
150
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
151
|
+
* Centraliza el registro del proveedor AI y el bucle de completions,
|
|
152
|
+
* delegando la llamada HTTP en una {@link IAiProviderStrategy}
|
|
153
|
+
* intercambiable. Por defecto usa {@link OpenAiCompatibleStrategy}.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* // Configurar el proveedor
|
|
158
|
+
* AgentService.getInstance().useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY });
|
|
159
|
+
*
|
|
160
|
+
* // Cambiar de estrategia en runtime (p. ej. un mock en tests)
|
|
161
|
+
* AgentService.getInstance().useSetStrategy(new OpenAiCompatibleStrategy());
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export class AgentService {
|
|
165
|
+
static instance;
|
|
166
|
+
provider = null;
|
|
167
|
+
strategy;
|
|
168
|
+
/**
|
|
169
|
+
* Constructor privado - enforce singleton.
|
|
170
|
+
* @param strategy - Estrategia de proveedor a inyectar (opcional).
|
|
171
|
+
*/
|
|
172
|
+
constructor(strategy) {
|
|
173
|
+
this.strategy = strategy ?? new OpenAiCompatibleStrategy();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Obtiene la instancia única del AgentService (Singleton).
|
|
177
|
+
*
|
|
178
|
+
* @returns La instancia única de {@link AgentService}.
|
|
179
|
+
*/
|
|
180
|
+
static getInstance() {
|
|
181
|
+
if (!AgentService.instance) {
|
|
182
|
+
AgentService.instance = new AgentService();
|
|
183
|
+
}
|
|
184
|
+
return AgentService.instance;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Crea una instancia NO-singleton con una estrategia específica.
|
|
188
|
+
* Útil para tests o para aislar varios proveedores.
|
|
189
|
+
*
|
|
190
|
+
* @param strategy - Estrategia a inyectar.
|
|
191
|
+
* @returns Una nueva instancia de {@link AgentService}.
|
|
192
|
+
*/
|
|
193
|
+
static create(strategy) {
|
|
194
|
+
return new AgentService(strategy);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Intercambia la estrategia de proveedor en runtime (Strategy Pattern).
|
|
198
|
+
*
|
|
199
|
+
* @param strategy - La nueva estrategia a utilizar.
|
|
200
|
+
*/
|
|
201
|
+
useSetStrategy(strategy) {
|
|
202
|
+
this.strategy = strategy;
|
|
203
|
+
}
|
|
204
|
+
/** Returns the currently active provider strategy. */
|
|
205
|
+
useGetStrategy() {
|
|
206
|
+
return this.strategy;
|
|
207
|
+
}
|
|
208
|
+
/** Retrieves the configured provider or throws. */
|
|
209
|
+
useGetProvider() {
|
|
210
|
+
if (!this.provider) {
|
|
211
|
+
throw new Error("[AiAgent] No provider configured. Call useInitAgent() first.");
|
|
212
|
+
}
|
|
213
|
+
return this.provider;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Registers the AI provider for the Kitt assistant.
|
|
217
|
+
*
|
|
218
|
+
* `apiKey` falls back to `process.env.DASHSCOPE_API_KEY`; `baseUrl`, `model`
|
|
219
|
+
* and `systemPrompt` fall back to the {@link kittPreset} defaults.
|
|
220
|
+
*
|
|
221
|
+
* @param config - Partial provider configuration.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import { useInitAgent } from "katanakit-js";
|
|
226
|
+
*
|
|
227
|
+
* useInitAgent({
|
|
228
|
+
* apiKey: process.env.DASHSCOPE_API_KEY,
|
|
229
|
+
* model: "qwen3.8-max",
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
useInitAgent(config = {}) {
|
|
234
|
+
const apiKey = config.apiKey ?? readEnvKey() ?? "";
|
|
235
|
+
if (!apiKey) {
|
|
236
|
+
throw new Error("[AiAgent] Missing apiKey. Pass it to useInitAgent() or set DASHSCOPE_API_KEY.");
|
|
237
|
+
}
|
|
238
|
+
const baseUrl = config.baseUrl ?? KITT_BASE_URL;
|
|
239
|
+
if (!baseUrl.startsWith("https://")) {
|
|
240
|
+
throw new Error("[AiAgent] baseUrl must use https:// so the API key is not sent in cleartext.");
|
|
241
|
+
}
|
|
242
|
+
this.provider = {
|
|
243
|
+
baseUrl,
|
|
244
|
+
model: config.model ?? KITT_DEFAULT_MODEL,
|
|
245
|
+
systemPrompt: config.systemPrompt ?? KITT_SYSTEM_PROMPT,
|
|
246
|
+
apiKey,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sends a single chat completion and returns the assistant text as a Safe Result.
|
|
251
|
+
*
|
|
252
|
+
* Use this for review / questioning (single-shot). For autonomous multi-step
|
|
253
|
+
* work with tools, use {@link useRunAgent}.
|
|
254
|
+
*
|
|
255
|
+
* @param messages - Conversation messages (a system prompt is prepended if absent).
|
|
256
|
+
* @param options - Optional completion options.
|
|
257
|
+
* @returns A `AiResult` with the assistant text.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* import { useChat } from "katanakit-js";
|
|
262
|
+
*
|
|
263
|
+
* const result = await useChat([
|
|
264
|
+
* { role: "user", content: "Summarize the benefits of solar energy in three bullet points." },
|
|
265
|
+
* ]);
|
|
266
|
+
* if (result.ok) console.log(result.data);
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
async useChat(messages, options = {}) {
|
|
270
|
+
try {
|
|
271
|
+
const config = this.useGetProvider();
|
|
272
|
+
const { signal, temperature, maxTokens, topP, systemPrompt } = options;
|
|
273
|
+
const withSystem = ensureSystem(messages, systemPrompt ?? config.systemPrompt ?? KITT_SYSTEM_PROMPT);
|
|
274
|
+
const response = await this.strategy.requestCompletion(config, withSystem, {
|
|
275
|
+
signal,
|
|
276
|
+
temperature,
|
|
277
|
+
maxTokens,
|
|
278
|
+
topP,
|
|
279
|
+
});
|
|
280
|
+
const content = response.choices?.[0]?.message?.content ?? "";
|
|
281
|
+
return { data: content, error: null, ok: true };
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
return {
|
|
285
|
+
data: null,
|
|
286
|
+
error: { message: `[AiAgent] ${toMessage(error)}`, status: toStatus(error) },
|
|
287
|
+
ok: false,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Runs the tool-calling agent loop against a goal until it emits a final
|
|
293
|
+
* answer or exhausts `maxSteps`.
|
|
294
|
+
*
|
|
295
|
+
* @param goal - The natural-language objective.
|
|
296
|
+
* @param options - Tools, step budget and completion options.
|
|
297
|
+
* @returns An `AgentResult` with the final message and executed steps.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { useRunAgent } from "katanakit-js";
|
|
302
|
+
*
|
|
303
|
+
* const result = await useRunAgent("Fix the type errors reported by tsc", {
|
|
304
|
+
* tools: [
|
|
305
|
+
* {
|
|
306
|
+
* name: "runCommand",
|
|
307
|
+
* description: "Runs a shell command and returns its output",
|
|
308
|
+
* parameters: { type: "object", properties: { command: { type: "string" } } },
|
|
309
|
+
* execute: (input) => shell.run(input.command),
|
|
310
|
+
* },
|
|
311
|
+
* ],
|
|
312
|
+
* maxSteps: 12,
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
async useRunAgent(goal, options = {}) {
|
|
317
|
+
try {
|
|
318
|
+
const config = this.useGetProvider();
|
|
319
|
+
const { tools = [], maxSteps = 10, signal, temperature, maxTokens, topP, systemPrompt, history = [], } = options;
|
|
320
|
+
const prior = history.filter((message) => message.role !== "system");
|
|
321
|
+
const messages = [
|
|
322
|
+
{ role: "system", content: systemPrompt ?? config.systemPrompt ?? KITT_SYSTEM_PROMPT },
|
|
323
|
+
...prior,
|
|
324
|
+
{ role: "user", content: goal },
|
|
325
|
+
];
|
|
326
|
+
const steps = [];
|
|
327
|
+
for (let step = 0; step < maxSteps; step++) {
|
|
328
|
+
const response = await this.strategy.requestCompletion(config, messages, {
|
|
329
|
+
signal,
|
|
330
|
+
temperature,
|
|
331
|
+
maxTokens,
|
|
332
|
+
topP,
|
|
333
|
+
tools,
|
|
334
|
+
});
|
|
335
|
+
const choice = response.choices?.[0];
|
|
336
|
+
const toolCalls = choice?.message?.tool_calls ?? [];
|
|
337
|
+
if (toolCalls.length > 0) {
|
|
338
|
+
messages.push({
|
|
339
|
+
role: "assistant",
|
|
340
|
+
content: choice?.message?.content ?? null,
|
|
341
|
+
tool_calls: toolCalls,
|
|
342
|
+
});
|
|
343
|
+
const toolResults = [];
|
|
344
|
+
for (const call of toolCalls) {
|
|
345
|
+
const result = await executeToolCall(tools, call);
|
|
346
|
+
toolResults.push(result);
|
|
347
|
+
messages.push({
|
|
348
|
+
role: "tool",
|
|
349
|
+
tool_call_id: call.id,
|
|
350
|
+
content: typeof result === "string" ? result : JSON.stringify(result),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
steps.push({ toolCalls, toolResults });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const finalMessage = choice?.message?.content ?? "";
|
|
357
|
+
return { data: { finalMessage, steps }, error: null, ok: true };
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
data: null,
|
|
361
|
+
error: {
|
|
362
|
+
message: `[AiAgent] Max steps (${maxSteps}) reached without a final answer.`,
|
|
363
|
+
status: 0,
|
|
364
|
+
},
|
|
365
|
+
ok: false,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
return {
|
|
370
|
+
data: null,
|
|
371
|
+
error: { message: `[AiAgent] ${toMessage(error)}`, status: toStatus(error) },
|
|
372
|
+
ok: false,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/* -------------------------------------------------------------------------- */
|
|
378
|
+
/* Wrappers (backward compatibility) */
|
|
379
|
+
/* -------------------------------------------------------------------------- */
|
|
380
|
+
/**
|
|
381
|
+
* Registers the AI provider for the Kitt assistant.
|
|
143
382
|
*
|
|
144
383
|
* @param config - Partial provider configuration.
|
|
145
384
|
*
|
|
@@ -147,69 +386,29 @@ function ensureSystem(messages, fallback) {
|
|
|
147
386
|
* ```ts
|
|
148
387
|
* import { useInitAgent } from "katanakit-js";
|
|
149
388
|
*
|
|
150
|
-
* useInitAgent({
|
|
151
|
-
* apiKey: process.env.DASHSCOPE_API_KEY,
|
|
152
|
-
* model: "qwen3.8-max",
|
|
153
|
-
* });
|
|
389
|
+
* useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY });
|
|
154
390
|
* ```
|
|
155
391
|
*/
|
|
156
392
|
export function useInitAgent(config = {}) {
|
|
157
|
-
|
|
158
|
-
if (!apiKey) {
|
|
159
|
-
throw new Error("[AiAgent] Missing apiKey. Pass it to useInitAgent() or set DASHSCOPE_API_KEY.");
|
|
160
|
-
}
|
|
161
|
-
const baseUrl = config.baseUrl ?? KITT_BASE_URL;
|
|
162
|
-
if (!baseUrl.startsWith("https://")) {
|
|
163
|
-
throw new Error("[AiAgent] baseUrl must use https:// so the API key is not sent in cleartext.");
|
|
164
|
-
}
|
|
165
|
-
provider = {
|
|
166
|
-
baseUrl,
|
|
167
|
-
model: config.model ?? KITT_DEFAULT_MODEL,
|
|
168
|
-
systemPrompt: config.systemPrompt ?? KITT_SYSTEM_PROMPT,
|
|
169
|
-
apiKey,
|
|
170
|
-
};
|
|
393
|
+
AgentService.getInstance().useInitAgent(config);
|
|
171
394
|
}
|
|
172
395
|
/**
|
|
173
396
|
* Sends a single chat completion and returns the assistant text as a Safe Result.
|
|
174
397
|
*
|
|
175
|
-
* Use this for review / questioning (single-shot). For autonomous multi-step
|
|
176
|
-
* work with tools, use {@link useRunAgent}.
|
|
177
|
-
*
|
|
178
398
|
* @param messages - Conversation messages (a system prompt is prepended if absent).
|
|
179
399
|
* @param options - Optional completion options.
|
|
180
|
-
* @returns
|
|
400
|
+
* @returns An `AiResult` with the assistant text.
|
|
181
401
|
*
|
|
182
402
|
* @example
|
|
183
403
|
* ```ts
|
|
184
404
|
* import { useChat } from "katanakit-js";
|
|
185
405
|
*
|
|
186
|
-
* const result = await useChat([
|
|
187
|
-
* { role: "user", content: "Summarize the benefits of solar energy in three bullet points." },
|
|
188
|
-
* ]);
|
|
406
|
+
* const result = await useChat([{ role: "user", content: "Hello" }]);
|
|
189
407
|
* if (result.ok) console.log(result.data);
|
|
190
408
|
* ```
|
|
191
409
|
*/
|
|
192
410
|
export async function useChat(messages, options = {}) {
|
|
193
|
-
|
|
194
|
-
const config = getProvider();
|
|
195
|
-
const { signal, temperature, maxTokens, topP, systemPrompt } = options;
|
|
196
|
-
const withSystem = ensureSystem(messages, systemPrompt ?? config.systemPrompt ?? KITT_SYSTEM_PROMPT);
|
|
197
|
-
const response = await requestCompletion(config, withSystem, {
|
|
198
|
-
signal,
|
|
199
|
-
temperature,
|
|
200
|
-
maxTokens,
|
|
201
|
-
topP,
|
|
202
|
-
});
|
|
203
|
-
const content = response.choices?.[0]?.message?.content ?? "";
|
|
204
|
-
return { data: content, error: null, ok: true };
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
return {
|
|
208
|
-
data: null,
|
|
209
|
-
error: { message: `[AiAgent] ${toMessage(error)}`, status: toStatus(error) },
|
|
210
|
-
ok: false,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
411
|
+
return AgentService.getInstance().useChat(messages, options);
|
|
213
412
|
}
|
|
214
413
|
/**
|
|
215
414
|
* Runs the tool-calling agent loop against a goal until it emits a final
|
|
@@ -217,83 +416,16 @@ export async function useChat(messages, options = {}) {
|
|
|
217
416
|
*
|
|
218
417
|
* @param goal - The natural-language objective.
|
|
219
418
|
* @param options - Tools, step budget and completion options.
|
|
220
|
-
* @returns An
|
|
419
|
+
* @returns An `AgentResult` with the final message and executed steps.
|
|
221
420
|
*
|
|
222
421
|
* @example
|
|
223
422
|
* ```ts
|
|
224
423
|
* import { useRunAgent } from "katanakit-js";
|
|
225
424
|
*
|
|
226
|
-
* const result = await useRunAgent("Fix the type errors reported by tsc"
|
|
227
|
-
* tools: [
|
|
228
|
-
* {
|
|
229
|
-
* name: "runCommand",
|
|
230
|
-
* description: "Runs a shell command and returns its output",
|
|
231
|
-
* parameters: { type: "object", properties: { command: { type: "string" } } },
|
|
232
|
-
* execute: (input) => shell.run(input.command),
|
|
233
|
-
* },
|
|
234
|
-
* ],
|
|
235
|
-
* maxSteps: 12,
|
|
236
|
-
* });
|
|
425
|
+
* const result = await useRunAgent("Fix the type errors reported by tsc");
|
|
237
426
|
* ```
|
|
238
427
|
*/
|
|
239
428
|
export async function useRunAgent(goal, options = {}) {
|
|
240
|
-
|
|
241
|
-
const config = getProvider();
|
|
242
|
-
const { tools = [], maxSteps = 10, signal, temperature, maxTokens, topP, systemPrompt, history = [], } = options;
|
|
243
|
-
const prior = history.filter((message) => message.role !== "system");
|
|
244
|
-
const messages = [
|
|
245
|
-
{ role: "system", content: systemPrompt ?? config.systemPrompt ?? KITT_SYSTEM_PROMPT },
|
|
246
|
-
...prior,
|
|
247
|
-
{ role: "user", content: goal },
|
|
248
|
-
];
|
|
249
|
-
const steps = [];
|
|
250
|
-
for (let step = 0; step < maxSteps; step++) {
|
|
251
|
-
const response = await requestCompletion(config, messages, {
|
|
252
|
-
signal,
|
|
253
|
-
temperature,
|
|
254
|
-
maxTokens,
|
|
255
|
-
topP,
|
|
256
|
-
tools,
|
|
257
|
-
});
|
|
258
|
-
const choice = response.choices?.[0];
|
|
259
|
-
const toolCalls = choice?.message?.tool_calls ?? [];
|
|
260
|
-
if (toolCalls.length > 0) {
|
|
261
|
-
messages.push({
|
|
262
|
-
role: "assistant",
|
|
263
|
-
content: choice?.message?.content ?? null,
|
|
264
|
-
tool_calls: toolCalls,
|
|
265
|
-
});
|
|
266
|
-
const toolResults = [];
|
|
267
|
-
for (const call of toolCalls) {
|
|
268
|
-
const result = await executeToolCall(tools, call);
|
|
269
|
-
toolResults.push(result);
|
|
270
|
-
messages.push({
|
|
271
|
-
role: "tool",
|
|
272
|
-
tool_call_id: call.id,
|
|
273
|
-
content: typeof result === "string" ? result : JSON.stringify(result),
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
steps.push({ toolCalls, toolResults });
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const finalMessage = choice?.message?.content ?? "";
|
|
280
|
-
return { data: { finalMessage, steps }, error: null, ok: true };
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
data: null,
|
|
284
|
-
error: {
|
|
285
|
-
message: `[AiAgent] Max steps (${maxSteps}) reached without a final answer.`,
|
|
286
|
-
status: 0,
|
|
287
|
-
},
|
|
288
|
-
ok: false,
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
catch (error) {
|
|
292
|
-
return {
|
|
293
|
-
data: null,
|
|
294
|
-
error: { message: `[AiAgent] ${toMessage(error)}`, status: toStatus(error) },
|
|
295
|
-
ok: false,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
429
|
+
return AgentService.getInstance().useRunAgent(goal, options);
|
|
298
430
|
}
|
|
299
431
|
//# sourceMappingURL=agent.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.service.js","sourceRoot":"","sources":["../../../src/core/services/agent.service.ts"],"names":[],"mappings":"AAYA,mFAAmF;AACnF,MAAM,CAAC,MAAM,aAAa,GAAG,wDAAwD,CAAC;AAEtF,mDAAmD;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAC9B,kEAAkE,CAAC;AAEpE,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAgD;IACtE,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,kBAAkB;CACzB,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"agent.service.js","sourceRoot":"","sources":["../../../src/core/services/agent.service.ts"],"names":[],"mappings":"AAYA,mFAAmF;AACnF,MAAM,CAAC,MAAM,aAAa,GAAG,wDAAwD,CAAC;AAEtF,mDAAmD;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAC9B,kEAAkE,CA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