agentic-api 2.0.491 → 2.0.585
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 +37 -34
- package/dist/src/agents/reducer.core.js +2 -2
- package/dist/src/agents/simulator.d.ts +26 -1
- package/dist/src/agents/simulator.dashboard.d.ts +140 -0
- package/dist/src/agents/simulator.dashboard.js +344 -0
- package/dist/src/agents/simulator.js +56 -0
- package/dist/src/agents/simulator.types.d.ts +38 -6
- package/dist/src/agents/simulator.utils.d.ts +22 -1
- package/dist/src/agents/simulator.utils.js +27 -0
- package/dist/src/execute/helpers.js +2 -2
- package/dist/src/execute/modelconfig.d.ts +21 -11
- package/dist/src/execute/modelconfig.js +29 -13
- package/dist/src/execute/responses.js +8 -7
- package/dist/src/index.d.ts +5 -1
- package/dist/src/index.js +20 -1
- package/dist/src/llm/config.d.ts +25 -0
- package/dist/src/llm/config.js +38 -0
- package/dist/src/llm/index.d.ts +48 -0
- package/dist/src/llm/index.js +115 -0
- package/dist/src/llm/openai.d.ts +6 -0
- package/dist/src/llm/openai.js +154 -0
- package/dist/src/llm/pricing.d.ts +26 -0
- package/dist/src/llm/pricing.js +129 -0
- package/dist/src/llm/xai.d.ts +17 -0
- package/dist/src/llm/xai.js +90 -0
- package/dist/src/pricing.llm.d.ts +3 -15
- package/dist/src/pricing.llm.js +10 -251
- package/dist/src/prompts.d.ts +0 -1
- package/dist/src/prompts.js +51 -118
- package/dist/src/rag/embeddings.d.ts +5 -1
- package/dist/src/rag/embeddings.js +15 -5
- package/dist/src/rag/parser.js +1 -1
- package/dist/src/rag/rag.manager.d.ts +33 -2
- package/dist/src/rag/rag.manager.js +132 -46
- package/dist/src/rag/types.d.ts +2 -0
- package/dist/src/rag/usecase.js +8 -11
- package/dist/src/rules/git/git.health.js +59 -4
- package/dist/src/rules/git/repo.d.ts +11 -4
- package/dist/src/rules/git/repo.js +64 -18
- package/dist/src/rules/git/repo.pr.d.ts +8 -0
- package/dist/src/rules/git/repo.pr.js +45 -1
- package/dist/src/rules/git/repo.tools.d.ts +5 -1
- package/dist/src/rules/git/repo.tools.js +54 -7
- package/dist/src/rules/types.d.ts +14 -0
- package/dist/src/rules/utils.matter.d.ts +0 -20
- package/dist/src/rules/utils.matter.js +42 -74
- package/dist/src/scrapper.js +2 -2
- package/dist/src/utils.d.ts +0 -8
- package/dist/src/utils.js +1 -28
- package/package.json +1 -1
|
@@ -56,7 +56,11 @@ export declare function gitReadFileOutsideRepo(git: SimpleGit, filePath: string)
|
|
|
56
56
|
content: string;
|
|
57
57
|
date: Date;
|
|
58
58
|
}>;
|
|
59
|
-
export declare function gitGetFileHistory(git: SimpleGit, filename: string,
|
|
59
|
+
export declare function gitGetFileHistory(git: SimpleGit, filename: string, options?: {
|
|
60
|
+
hash?: string;
|
|
61
|
+
branch?: string;
|
|
62
|
+
maxCommits?: number;
|
|
63
|
+
}): Promise<GitCommitHistory[]>;
|
|
60
64
|
/**
|
|
61
65
|
* Récupère le dernier commit d'une branche (opération bas niveau atomique)
|
|
62
66
|
* @param git Instance SimpleGit
|
|
@@ -338,10 +338,23 @@ async function gitReadFileOutsideRepo(git, filePath) {
|
|
|
338
338
|
throw error;
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
-
async function gitGetFileHistory(git, filename,
|
|
341
|
+
async function gitGetFileHistory(git, filename, options) {
|
|
342
|
+
// - Normalisation des paramètres pour compatibilité
|
|
342
343
|
try {
|
|
343
|
-
|
|
344
|
-
|
|
344
|
+
// - Utiliser git.log() pour obtenir l'historique des commits
|
|
345
|
+
// - git.log() retourne déjà les commits du plus récent au plus ancien (ordre standard Git)
|
|
346
|
+
const branch = options?.branch || 'HEAD';
|
|
347
|
+
const logArgs = [];
|
|
348
|
+
if (branch !== 'HEAD') {
|
|
349
|
+
logArgs.push(branch);
|
|
350
|
+
}
|
|
351
|
+
logArgs.push('--', filename);
|
|
352
|
+
const log = await git.log(logArgs);
|
|
353
|
+
if (log.all.length === 0) {
|
|
354
|
+
return [];
|
|
355
|
+
}
|
|
356
|
+
// - Construire l'historique (déjà dans l'ordre du plus récent au plus ancien)
|
|
357
|
+
let all = log.all.map(commit => ({
|
|
345
358
|
hash: commit.hash,
|
|
346
359
|
date: new Date(commit.date),
|
|
347
360
|
message: commit.message,
|
|
@@ -350,10 +363,44 @@ async function gitGetFileHistory(git, filename, hash) {
|
|
|
350
363
|
email: commit.author_email
|
|
351
364
|
}
|
|
352
365
|
}));
|
|
353
|
-
// Si un hash est fourni,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
366
|
+
// - Si un hash est fourni, s'assurer qu'il est inclus avant l'échantillonnage
|
|
367
|
+
let requestedHashIndex = -1;
|
|
368
|
+
if (options?.hash) {
|
|
369
|
+
requestedHashIndex = all.findIndex(commit => commit.hash === options.hash);
|
|
370
|
+
}
|
|
371
|
+
// - Limitation du nombre de commits avec échantillonnage uniforme
|
|
372
|
+
// - Garantit que le premier (plus récent) et dernier (plus ancien) commit sont inclus
|
|
373
|
+
// - Si un hash spécifique est demandé, il est aussi garanti d'être inclus
|
|
374
|
+
if (options?.maxCommits && all.length > options.maxCommits) {
|
|
375
|
+
const step = Math.ceil((all.length - 2) / (options.maxCommits - 2)) || 1;
|
|
376
|
+
const sampled = [all[0]]; // Premier commit (plus récent)
|
|
377
|
+
const includedIndices = new Set([0]); // Track des indices déjà inclus
|
|
378
|
+
// - Si un hash spécifique est demandé et n'est pas le premier, l'ajouter
|
|
379
|
+
if (requestedHashIndex > 0 && requestedHashIndex < all.length - 1) {
|
|
380
|
+
sampled.push(all[requestedHashIndex]);
|
|
381
|
+
includedIndices.add(requestedHashIndex);
|
|
382
|
+
}
|
|
383
|
+
// - Échantillonnage des commits intermédiaires
|
|
384
|
+
for (let i = 1; i < all.length - 1; i += step) {
|
|
385
|
+
if (!includedIndices.has(i)) {
|
|
386
|
+
sampled.push(all[i]);
|
|
387
|
+
includedIndices.add(i);
|
|
388
|
+
}
|
|
389
|
+
if (sampled.length >= options.maxCommits - 1)
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
// - Dernier commit (plus ancien) si on a encore de la place
|
|
393
|
+
if (sampled.length < options.maxCommits && all.length > 1 && !includedIndices.has(all.length - 1)) {
|
|
394
|
+
sampled.push(all[all.length - 1]);
|
|
395
|
+
}
|
|
396
|
+
// - Trier par date décroissante pour maintenir l'ordre (plus récent en premier)
|
|
397
|
+
sampled.sort((a, b) => b.date.getTime() - a.date.getTime());
|
|
398
|
+
all = sampled;
|
|
399
|
+
}
|
|
400
|
+
// - Si un hash est fourni, retourner le contenu du fichier à ce hash
|
|
401
|
+
if (options?.hash) {
|
|
402
|
+
const fileContent = await gitGetFileContent(git, filename, options.hash);
|
|
403
|
+
const index = all.findIndex(commit => commit.hash === options.hash);
|
|
357
404
|
if (index !== -1 && fileContent) {
|
|
358
405
|
all[index] = fileContent;
|
|
359
406
|
}
|
|
@@ -334,6 +334,20 @@ export interface GitCommitHistory {
|
|
|
334
334
|
/** Branche où s'est produit ce commit (optionnel) */
|
|
335
335
|
branch?: string;
|
|
336
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Structure simplifiée d'un commit pour la prévisualisation
|
|
339
|
+
*
|
|
340
|
+
* Utilisée dans loadPreview() pour retourner uniquement les informations essentielles
|
|
341
|
+
* sans le contenu complet du commit.
|
|
342
|
+
*/
|
|
343
|
+
export interface CommitPreview {
|
|
344
|
+
/** Hash unique du commit */
|
|
345
|
+
hash: string;
|
|
346
|
+
/** Date et heure du commit */
|
|
347
|
+
date: Date;
|
|
348
|
+
/** Nom de l'auteur du commit */
|
|
349
|
+
author: string;
|
|
350
|
+
}
|
|
337
351
|
/**
|
|
338
352
|
* Résumé d'un fichier Git avec son commit associé
|
|
339
353
|
*
|
|
@@ -40,23 +40,3 @@ export declare function matterParse(markdown: string): {
|
|
|
40
40
|
*/
|
|
41
41
|
export declare function matterSerializeFromRule(rule: Rule): string;
|
|
42
42
|
export declare function matterSerialize(content: string, matter: FrontMatter | any): string;
|
|
43
|
-
/**
|
|
44
|
-
* Extrait le front-matter (entre les deux premiers '---') et le contenu Markdown.
|
|
45
|
-
* Fonction 100% vanilla : aucun paquet externe requis.
|
|
46
|
-
* PROS:
|
|
47
|
-
* Code plus propre et maintenable
|
|
48
|
-
* - Typage TypeScript strict
|
|
49
|
-
* - Plus robuste (ignore lignes indentées)
|
|
50
|
-
* - Séparation des responsabilités
|
|
51
|
-
* - Meilleure architecture (parsing pur)
|
|
52
|
-
* CONS:
|
|
53
|
-
* - Perte de fonctionnalité (slugs/tags)
|
|
54
|
-
*
|
|
55
|
-
* @param markdown Texte Markdown brut
|
|
56
|
-
* @returns Objet avec matter, content et data
|
|
57
|
-
*/
|
|
58
|
-
export declare function matterParse_OTHER(markdown: string): {
|
|
59
|
-
matter: Record<string, any>;
|
|
60
|
-
content: string;
|
|
61
|
-
data: Record<string, any>;
|
|
62
|
-
};
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.matterParse = matterParse;
|
|
4
4
|
exports.matterSerializeFromRule = matterSerializeFromRule;
|
|
5
5
|
exports.matterSerialize = matterSerialize;
|
|
6
|
-
exports.matterParse_OTHER = matterParse_OTHER;
|
|
7
6
|
/**
|
|
8
7
|
* Parse le front-matter YAML et le contenu Markdown d'un document
|
|
9
8
|
*
|
|
@@ -152,85 +151,54 @@ function matterSerialize(content, matter) {
|
|
|
152
151
|
return acc + `${key}: '${value.toISOString()}'\n`;
|
|
153
152
|
}
|
|
154
153
|
else {
|
|
155
|
-
|
|
156
|
-
return acc + `${key}:
|
|
154
|
+
const formatted = formatYAMLString(value.toString());
|
|
155
|
+
return acc + `${key}: ${formatted}\n`;
|
|
157
156
|
}
|
|
158
157
|
}, '');
|
|
159
158
|
return `---
|
|
160
159
|
${result}---
|
|
161
160
|
${content}`;
|
|
162
161
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* Code plus propre et maintenable
|
|
168
|
-
* - Typage TypeScript strict
|
|
169
|
-
* - Plus robuste (ignore lignes indentées)
|
|
170
|
-
* - Séparation des responsabilités
|
|
171
|
-
* - Meilleure architecture (parsing pur)
|
|
172
|
-
* CONS:
|
|
173
|
-
* - Perte de fonctionnalité (slugs/tags)
|
|
174
|
-
*
|
|
175
|
-
* @param markdown Texte Markdown brut
|
|
176
|
-
* @returns Objet avec matter, content et data
|
|
177
|
-
*/
|
|
178
|
-
function matterParse_OTHER(markdown) {
|
|
179
|
-
// 1. Séparer les lignes
|
|
180
|
-
const lines = markdown.split(/\r?\n/);
|
|
181
|
-
if (lines[0].trim() !== '---') {
|
|
182
|
-
return { matter: {}, content: markdown, data: {} }; // Pas de front-matter
|
|
162
|
+
function formatYAMLString(value) {
|
|
163
|
+
const shouldQuote = needsQuotes(value);
|
|
164
|
+
if (!shouldQuote) {
|
|
165
|
+
return value;
|
|
183
166
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
while (end < lines.length && lines[end].trim() !== '---')
|
|
187
|
-
end++;
|
|
188
|
-
// 3. Parser le bloc front-matter (simple clé-valeur)
|
|
189
|
-
const matter = {};
|
|
190
|
-
for (let i = 1; i < end; i++) {
|
|
191
|
-
const line = lines[i];
|
|
192
|
-
if (!line.trim())
|
|
193
|
-
continue; // ignorer les lignes vides
|
|
194
|
-
// Ignorer les lignes indentées (structures complexes non supportées)
|
|
195
|
-
if (line.startsWith(' ') || line.startsWith('\t')) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
const trimmedLine = line.trim();
|
|
199
|
-
if (trimmedLine.includes(':')) {
|
|
200
|
-
const [rawKey, ...rawValue] = trimmedLine.split(':');
|
|
201
|
-
const key = rawKey.trim();
|
|
202
|
-
const value = rawValue.join(':').trim();
|
|
203
|
-
if (value) {
|
|
204
|
-
// Détection et parsing des arrays YAML
|
|
205
|
-
if (value.startsWith('[') && value.endsWith(']')) {
|
|
206
|
-
try {
|
|
207
|
-
const parsed = JSON.parse(value);
|
|
208
|
-
if (Array.isArray(parsed)) {
|
|
209
|
-
matter[key] = parsed;
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
matter[key] = value.replace(/^["']|["']$/g, '');
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (e) {
|
|
216
|
-
matter[key] = value.replace(/^["']|["']$/g, '');
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// Tentative de typage léger : nombre, booléen, sinon chaîne
|
|
220
|
-
else if (/^(true|false)$/i.test(value)) {
|
|
221
|
-
matter[key] = value.toLowerCase() === 'true';
|
|
222
|
-
}
|
|
223
|
-
else if (!isNaN(Number(value)) && value !== '') {
|
|
224
|
-
matter[key] = Number(value);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
matter[key] = value.replace(/^["']|["']$/g, '');
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
167
|
+
if (process.env.DEBUG_YAML === '1') {
|
|
168
|
+
console.warn('[matterSerialize] quoting value:', value);
|
|
231
169
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
170
|
+
const escaped = value.replace(/'/g, "''");
|
|
171
|
+
return `'${escaped}'`;
|
|
172
|
+
}
|
|
173
|
+
function needsQuotes(value) {
|
|
174
|
+
if (value.length === 0) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const firstChar = value[0];
|
|
178
|
+
const lastChar = value[value.length - 1];
|
|
179
|
+
if (firstChar === ' ' || lastChar === ' ') {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
if (/[:#{}\[\],&*?]/.test(value)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (/^-/.test(value)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
if (/^\d/.test(value)) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if (value.includes('\n')) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (value.includes('- ')) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
if (value.includes('"')) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
if (value.includes("'")) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
236
204
|
}
|
package/dist/src/scrapper.js
CHANGED
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const fs_1 = __importDefault(require("fs"));
|
|
14
14
|
const jsdom_1 = require("jsdom");
|
|
15
15
|
const readability_1 = require("@mozilla/readability");
|
|
16
|
-
const
|
|
16
|
+
const pricing_1 = require("./llm/pricing");
|
|
17
17
|
const prompts_1 = require("./prompts");
|
|
18
18
|
const utils_1 = require("./utils");
|
|
19
19
|
const execute_1 = require("./execute");
|
|
@@ -37,7 +37,7 @@ async function extractCaptcha(base64Image, openai) {
|
|
|
37
37
|
messages: [{ role: "user", content }],
|
|
38
38
|
max_completion_tokens: 50,
|
|
39
39
|
});
|
|
40
|
-
const cost = (0,
|
|
40
|
+
const cost = (0, pricing_1.calculateCost)(model, response.usage);
|
|
41
41
|
// Récupérer la réponse markdown
|
|
42
42
|
const number = response.choices[0].message.content;
|
|
43
43
|
return { number, cost };
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { ParsedFunctionToolCall } from "openai/resources/beta/chat/completions";
|
|
2
2
|
import { AgentConfig, AgenticContext } from "./types";
|
|
3
|
-
import OpenAI from "openai";
|
|
4
|
-
/**
|
|
5
|
-
* global openai instance
|
|
6
|
-
*/
|
|
7
|
-
declare global {
|
|
8
|
-
var _openaiInstance_: OpenAI | undefined;
|
|
9
|
-
}
|
|
10
|
-
export declare const openaiInstance: (envKey?: string, baseUrl?: string) => OpenAI;
|
|
11
3
|
/**
|
|
12
4
|
* Converts a string to a URL-friendly slug
|
|
13
5
|
* @param text The text to convert to a slug
|
package/dist/src/utils.js
CHANGED
|
@@ -1,36 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.toSlug =
|
|
3
|
+
exports.toSlug = void 0;
|
|
7
4
|
exports.injectTransferTools = injectTransferTools;
|
|
8
5
|
exports.handleTransferCall = handleTransferCall;
|
|
9
6
|
const prompts_1 = require("./prompts");
|
|
10
|
-
const openai_1 = __importDefault(require("openai"));
|
|
11
|
-
const openaiInstance = function (envKey, baseUrl) {
|
|
12
|
-
if (globalThis._openaiInstance_) {
|
|
13
|
-
return globalThis._openaiInstance_;
|
|
14
|
-
}
|
|
15
|
-
if (!envKey) {
|
|
16
|
-
throw new Error('AI API key is missing');
|
|
17
|
-
}
|
|
18
|
-
//
|
|
19
|
-
// use multiple fallback if envKey is not set
|
|
20
|
-
const options = {
|
|
21
|
-
apiKey: process.env[envKey] || envKey || process.env.API_LLM_KEY || process.env.OPENAI_API_KEY,
|
|
22
|
-
timeout: 60000 * 15
|
|
23
|
-
};
|
|
24
|
-
if (baseUrl) {
|
|
25
|
-
options.baseURL = baseUrl;
|
|
26
|
-
}
|
|
27
|
-
globalThis._openaiInstance_ = new openai_1.default(options);
|
|
28
|
-
if (!globalThis._openaiInstance_) {
|
|
29
|
-
throw new Error('OpenAI instance has not been initialized');
|
|
30
|
-
}
|
|
31
|
-
return globalThis._openaiInstance_;
|
|
32
|
-
};
|
|
33
|
-
exports.openaiInstance = openaiInstance;
|
|
34
7
|
/**
|
|
35
8
|
* Converts a string to a URL-friendly slug
|
|
36
9
|
* @param text The text to convert to a slug
|
package/package.json
CHANGED