agentic-api 1.0.5 → 2.0.26

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.
Files changed (104) hide show
  1. package/README.md +118 -22
  2. package/dist/src/agents/agents.example.d.ts +3 -0
  3. package/dist/src/agents/agents.example.js +38 -0
  4. package/dist/src/agents/authentication.js +2 -0
  5. package/dist/src/agents/digestor.js +25 -16
  6. package/dist/src/agents/prompts.d.ts +2 -2
  7. package/dist/src/agents/prompts.js +112 -49
  8. package/dist/src/agents/reducer.core.d.ts +12 -0
  9. package/dist/src/agents/reducer.core.js +207 -0
  10. package/dist/src/agents/reducer.d.ts +3 -0
  11. package/dist/src/agents/reducer.example.d.ts +28 -0
  12. package/dist/src/agents/reducer.example.js +118 -0
  13. package/dist/src/agents/reducer.js +19 -0
  14. package/dist/src/agents/reducer.loaders.d.ts +34 -0
  15. package/dist/src/agents/reducer.loaders.js +122 -0
  16. package/dist/src/agents/reducer.process.d.ts +16 -0
  17. package/dist/src/agents/reducer.process.js +143 -0
  18. package/dist/src/agents/reducer.tools.d.ts +29 -0
  19. package/dist/src/agents/reducer.tools.js +157 -0
  20. package/dist/src/agents/reducer.types.d.ts +50 -0
  21. package/dist/src/agents/reducer.types.js +5 -0
  22. package/dist/src/agents/simulator.d.ts +47 -0
  23. package/dist/src/agents/simulator.executor.d.ts +26 -0
  24. package/dist/src/agents/simulator.executor.js +132 -0
  25. package/dist/src/agents/simulator.js +205 -0
  26. package/dist/src/agents/simulator.prompts.d.ts +16 -0
  27. package/dist/src/agents/simulator.prompts.js +108 -0
  28. package/dist/src/agents/simulator.types.d.ts +42 -0
  29. package/dist/src/agents/simulator.types.js +2 -0
  30. package/dist/src/agents/simulator.utils.d.ts +20 -0
  31. package/dist/src/agents/simulator.utils.js +87 -0
  32. package/dist/src/execute.d.ts +14 -7
  33. package/dist/src/execute.js +359 -84
  34. package/dist/src/index.d.ts +9 -0
  35. package/dist/src/index.js +14 -0
  36. package/dist/src/princing.openai.d.ts +9 -2
  37. package/dist/src/princing.openai.js +16 -11
  38. package/dist/src/prompts.d.ts +3 -2
  39. package/dist/src/prompts.js +207 -72
  40. package/dist/src/rag/embeddings.d.ts +103 -0
  41. package/dist/src/rag/embeddings.js +466 -0
  42. package/dist/src/rag/index.d.ts +12 -0
  43. package/dist/src/rag/index.js +40 -0
  44. package/dist/src/rag/lucene.d.ts +45 -0
  45. package/dist/src/rag/lucene.js +227 -0
  46. package/dist/src/rag/parser.d.ts +68 -0
  47. package/dist/src/rag/parser.js +192 -0
  48. package/dist/src/rag/tools.d.ts +76 -0
  49. package/dist/src/rag/tools.js +196 -0
  50. package/dist/src/rag/types.d.ts +178 -0
  51. package/dist/src/rag/types.js +21 -0
  52. package/dist/src/rag/usecase.d.ts +16 -0
  53. package/dist/src/rag/usecase.js +79 -0
  54. package/dist/src/rules/errors.d.ts +60 -0
  55. package/dist/src/rules/errors.js +97 -0
  56. package/dist/src/rules/git/git.e2e.helper.d.ts +104 -0
  57. package/dist/src/rules/git/git.e2e.helper.js +488 -0
  58. package/dist/src/rules/git/git.health.d.ts +66 -0
  59. package/dist/src/rules/git/git.health.js +354 -0
  60. package/dist/src/rules/git/git.helper.d.ts +129 -0
  61. package/dist/src/rules/git/git.helper.js +53 -0
  62. package/dist/src/rules/git/index.d.ts +6 -0
  63. package/dist/src/rules/git/index.js +76 -0
  64. package/dist/src/rules/git/repo.d.ts +128 -0
  65. package/dist/src/rules/git/repo.js +900 -0
  66. package/dist/src/rules/git/repo.pr.d.ts +137 -0
  67. package/dist/src/rules/git/repo.pr.js +589 -0
  68. package/dist/src/rules/git/repo.tools.d.ts +134 -0
  69. package/dist/src/rules/git/repo.tools.js +730 -0
  70. package/dist/src/rules/index.d.ts +8 -0
  71. package/dist/src/rules/index.js +25 -0
  72. package/dist/src/rules/messages.d.ts +17 -0
  73. package/dist/src/rules/messages.js +21 -0
  74. package/dist/src/rules/types.ctrl.d.ts +28 -0
  75. package/dist/src/rules/types.ctrl.js +2 -0
  76. package/dist/src/rules/types.d.ts +510 -0
  77. package/dist/src/rules/types.helpers.d.ts +132 -0
  78. package/dist/src/rules/types.helpers.js +2 -0
  79. package/dist/src/rules/types.js +33 -0
  80. package/dist/src/rules/user.mapper.d.ts +61 -0
  81. package/dist/src/rules/user.mapper.js +160 -0
  82. package/dist/src/rules/utils/slug.d.ts +22 -0
  83. package/dist/src/rules/utils/slug.js +35 -0
  84. package/dist/src/rules/utils.matter.d.ts +66 -0
  85. package/dist/src/rules/utils.matter.js +208 -0
  86. package/dist/src/rules/utils.slug.d.ts +22 -0
  87. package/dist/src/rules/utils.slug.js +35 -0
  88. package/dist/src/scrapper.d.ts +3 -2
  89. package/dist/src/scrapper.js +33 -37
  90. package/dist/src/stategraph/index.d.ts +8 -0
  91. package/dist/src/stategraph/index.js +21 -0
  92. package/dist/src/stategraph/stategraph.d.ts +91 -0
  93. package/dist/src/stategraph/stategraph.js +241 -0
  94. package/dist/src/stategraph/stategraph.storage.d.ts +41 -0
  95. package/dist/src/stategraph/stategraph.storage.js +166 -0
  96. package/dist/src/stategraph/types.d.ts +139 -0
  97. package/dist/src/stategraph/types.js +19 -0
  98. package/dist/src/types.d.ts +68 -39
  99. package/dist/src/types.js +53 -89
  100. package/dist/src/usecase.d.ts +4 -0
  101. package/dist/src/usecase.js +44 -0
  102. package/dist/src/utils.d.ts +12 -5
  103. package/dist/src/utils.js +30 -13
  104. package/package.json +9 -3
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matterParse = matterParse;
4
+ exports.matterSerializeFromRule = matterSerializeFromRule;
5
+ exports.matterSerialize = matterSerialize;
6
+ exports.matterParse_OTHER = matterParse_OTHER;
7
+ /**
8
+ * Parse le front-matter YAML et le contenu Markdown d'un document
9
+ *
10
+ * Cette fonction extrait et parse le front-matter YAML délimité par '---'
11
+ * au début d'un document Markdown. Elle gère automatiquement :
12
+ * - La conversion des types (nombres, booléens, chaînes)
13
+ * - Le parsing des arrays JSON dans le YAML
14
+ * - La normalisation des champs `slugs` et `tags` en arrays
15
+ * - La suppression des guillemets de délimitation
16
+ *
17
+ * @param markdown - Texte Markdown brut avec front-matter optionnel
18
+ * @returns Objet contenant le front-matter parsé et le contenu
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const doc = `---
23
+ * title: Ma Procédure
24
+ * tags: ["urgent", "finance"]
25
+ * version: 1.2
26
+ * active: true
27
+ * ---
28
+ * # Contenu de la procédure
29
+ *
30
+ * Instructions détaillées...`;
31
+ *
32
+ * const { matter, content } = matterParse(doc);
33
+ * // matter: { title: 'Ma Procédure', tags: ['urgent', 'finance'], version: 1.2, active: true }
34
+ * // content: '# Contenu de la procédure\n\nInstructions détaillées...'
35
+ * ```
36
+ */
37
+ function matterParse(markdown) {
38
+ // 1. Séparer les lignes
39
+ const lines = markdown.split(/\r?\n/);
40
+ if (lines[0].trim() !== '---') {
41
+ return { matter: {}, content: markdown }; // Pas de front-matter
42
+ }
43
+ // 2. Trouver la ligne de fermeture '---'
44
+ let end = 1;
45
+ while (end < lines.length && lines[end].trim() !== '---')
46
+ end++;
47
+ // 3. Parser le bloc front-matter
48
+ const matter = {};
49
+ for (let i = 1; i < end; i++) {
50
+ const line = lines[i];
51
+ if (!line.trim())
52
+ continue; // ignorer les lignes vides
53
+ const [rawKey, ...rawValue] = line.split(':');
54
+ const key = rawKey.trim();
55
+ const value = rawValue.join(':').trim();
56
+ // Détection et parsing des arrays YAML
57
+ if (value.startsWith('[') && value.endsWith(']')) {
58
+ try {
59
+ // Utiliser JSON.parse pour parser l'array
60
+ const parsed = JSON.parse(value);
61
+ // Vérifier que c'est bien un array
62
+ if (Array.isArray(parsed)) {
63
+ matter[key] = parsed;
64
+ }
65
+ else {
66
+ // Si ce n'est pas un array, traiter comme string
67
+ matter[key] = value.replace(/^["']|["']$/g, '');
68
+ }
69
+ }
70
+ catch (e) {
71
+ // Si JSON.parse échoue, garder comme string
72
+ matter[key] = value.replace(/^["']|["']$/g, '');
73
+ }
74
+ }
75
+ // Tentative de typage léger : nombre, booléen, sinon chaîne
76
+ else if (/^(true|false)$/i.test(value)) {
77
+ matter[key] = value.toLowerCase() === 'true';
78
+ }
79
+ else if (!isNaN(Number(value)) && value !== '') {
80
+ matter[key] = Number(value);
81
+ }
82
+ else {
83
+ // Retirer les guillemets éventuels
84
+ matter[key] = value.replace(/^["']|["']$/g, '');
85
+ }
86
+ }
87
+ // 4. parse slugs and tags as arrays
88
+ // Ensure slugs is always an array
89
+ // TODO: this code is not clean enough
90
+ if (matter.slugs && typeof matter.slugs === 'string') {
91
+ matter.slugs = matter.slugs.split(',').map((s) => s.trim()).filter((s) => s.length);
92
+ }
93
+ // Ensure tags is always an array
94
+ if (matter.tags && typeof matter.tags === 'string') {
95
+ const tagsStr = matter.tags;
96
+ matter.tags = tagsStr.split(',').map((s) => s.trim()).filter((s) => s.length > 0);
97
+ }
98
+ if (Object.keys(matter).length) {
99
+ }
100
+ // 5. Restituer le contenu Markdown sans le front-matter
101
+ const content = lines.slice(end + 1).join('\n').trimStart();
102
+ const data = matter;
103
+ return { data, content, matter };
104
+ }
105
+ /**
106
+ * Sérialise une Rule en format Markdown avec front-matter
107
+ * ✅ NOUVELLE FONCTION pour reconstruire le contenu complet
108
+ */
109
+ function matterSerializeFromRule(rule) {
110
+ // Créer un objet propre pour le front-matter (exclure oldfile)
111
+ const matter = { ...rule.matter };
112
+ delete matter.oldfile;
113
+ return matterSerialize(rule.content, matter);
114
+ }
115
+ function matterSerialize(content, matter) {
116
+ // Créer un objet propre pour le front-matter (exclure oldfile)
117
+ const cleanMatter = { ...matter };
118
+ //
119
+ // FIX: Convertir la Date en string pour éviter l'erreur YAML
120
+ cleanMatter.lastModified = (cleanMatter.lastModified instanceof Date) ? `${new Date().toISOString()}` : `${cleanMatter.lastModified}`;
121
+ const result = Object.keys(cleanMatter).reduce((acc, key) => {
122
+ const value = cleanMatter[key];
123
+ if (Array.isArray(value)) {
124
+ return acc + `${key}: '${value.join(',')}'\n`;
125
+ }
126
+ else {
127
+ return acc + `${key}: '${value}'\n`;
128
+ }
129
+ }, '');
130
+ return `---
131
+ ${result}
132
+ ---
133
+ ${content}`;
134
+ }
135
+ /**
136
+ * Extrait le front-matter (entre les deux premiers '---') et le contenu Markdown.
137
+ * Fonction 100% vanilla : aucun paquet externe requis.
138
+ * PROS:
139
+ * Code plus propre et maintenable
140
+ * - Typage TypeScript strict
141
+ * - Plus robuste (ignore lignes indentées)
142
+ * - Séparation des responsabilités
143
+ * - Meilleure architecture (parsing pur)
144
+ * CONS:
145
+ * - Perte de fonctionnalité (slugs/tags)
146
+ *
147
+ * @param markdown Texte Markdown brut
148
+ * @returns Objet avec matter, content et data
149
+ */
150
+ function matterParse_OTHER(markdown) {
151
+ // 1. Séparer les lignes
152
+ const lines = markdown.split(/\r?\n/);
153
+ if (lines[0].trim() !== '---') {
154
+ return { matter: {}, content: markdown, data: {} }; // Pas de front-matter
155
+ }
156
+ // 2. Trouver la ligne de fermeture '---'
157
+ let end = 1;
158
+ while (end < lines.length && lines[end].trim() !== '---')
159
+ end++;
160
+ // 3. Parser le bloc front-matter (simple clé-valeur)
161
+ const matter = {};
162
+ for (let i = 1; i < end; i++) {
163
+ const line = lines[i];
164
+ if (!line.trim())
165
+ continue; // ignorer les lignes vides
166
+ // Ignorer les lignes indentées (structures complexes non supportées)
167
+ if (line.startsWith(' ') || line.startsWith('\t')) {
168
+ continue;
169
+ }
170
+ const trimmedLine = line.trim();
171
+ if (trimmedLine.includes(':')) {
172
+ const [rawKey, ...rawValue] = trimmedLine.split(':');
173
+ const key = rawKey.trim();
174
+ const value = rawValue.join(':').trim();
175
+ if (value) {
176
+ // Détection et parsing des arrays YAML
177
+ if (value.startsWith('[') && value.endsWith(']')) {
178
+ try {
179
+ const parsed = JSON.parse(value);
180
+ if (Array.isArray(parsed)) {
181
+ matter[key] = parsed;
182
+ }
183
+ else {
184
+ matter[key] = value.replace(/^["']|["']$/g, '');
185
+ }
186
+ }
187
+ catch (e) {
188
+ matter[key] = value.replace(/^["']|["']$/g, '');
189
+ }
190
+ }
191
+ // Tentative de typage léger : nombre, booléen, sinon chaîne
192
+ else if (/^(true|false)$/i.test(value)) {
193
+ matter[key] = value.toLowerCase() === 'true';
194
+ }
195
+ else if (!isNaN(Number(value)) && value !== '') {
196
+ matter[key] = Number(value);
197
+ }
198
+ else {
199
+ matter[key] = value.replace(/^["']|["']$/g, '');
200
+ }
201
+ }
202
+ }
203
+ }
204
+ // 4. Restituer le contenu Markdown sans le front-matter
205
+ const content = lines.slice(end + 1).join('\n').trimStart();
206
+ const data = matter;
207
+ return { data, content, matter };
208
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Utility functions for handling slugs in the rules system
3
+ */
4
+ /**
5
+ * Extracts a slug from a file path
6
+ * @param filePath The file path to extract the slug from
7
+ * @returns The slug extracted from the file path
8
+ */
9
+ export declare const slugFromFile: (filePath: string, ext?: string) => string;
10
+ /**
11
+ * Converts a slug back to a file path
12
+ * @param slug The slug to convert to a file path
13
+ * @param ext The file extension to append (default: '.md')
14
+ * @returns The file path created from the slug
15
+ */
16
+ export declare const fileFromSlug: (slug: string, ext?: string) => string;
17
+ /**
18
+ * Validates if a string is a valid slug
19
+ * @param slug The slug to validate
20
+ * @returns True if the slug is valid, false otherwise
21
+ */
22
+ export declare const isValidSlug: (slug: string) => boolean;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for handling slugs in the rules system
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidSlug = exports.fileFromSlug = exports.slugFromFile = void 0;
7
+ const utils_1 = require("../utils");
8
+ /**
9
+ * Extracts a slug from a file path
10
+ * @param filePath The file path to extract the slug from
11
+ * @returns The slug extracted from the file path
12
+ */
13
+ const slugFromFile = (filePath, ext = '.md') => {
14
+ return (0, utils_1.toSlug)(filePath.replace(ext, ''));
15
+ };
16
+ exports.slugFromFile = slugFromFile;
17
+ /**
18
+ * Converts a slug back to a file path
19
+ * @param slug The slug to convert to a file path
20
+ * @param ext The file extension to append (default: '.md')
21
+ * @returns The file path created from the slug
22
+ */
23
+ const fileFromSlug = (slug, ext = '.md') => {
24
+ return `${slug}${ext}`;
25
+ };
26
+ exports.fileFromSlug = fileFromSlug;
27
+ /**
28
+ * Validates if a string is a valid slug
29
+ * @param slug The slug to validate
30
+ * @returns True if the slug is valid, false otherwise
31
+ */
32
+ const isValidSlug = (slug) => {
33
+ return /^[a-z0-9-]+$/.test(slug);
34
+ };
35
+ exports.isValidSlug = isValidSlug;
@@ -16,7 +16,7 @@ export declare function callGPTForParsingPDF(inputfile: string, pdfData: any, op
16
16
  cost: number;
17
17
  }>;
18
18
  /**
19
- * Convertit un document HTML en markdown en appelant le modèle GPT (ex: gpt-4o-mini)
19
+ * Convertit un document HTML en markdown en appelant le modèle GPT (ex: gpt-4.1)
20
20
  * pour analyser et reformater le document.
21
21
  *
22
22
  * @param {any} htmlData - Le document HTML à transformer en markdown.
@@ -48,7 +48,8 @@ export declare function html2markdown(output: string, file: string, service: str
48
48
  * @param {any} openai - L'instance configurée pour appeler l'API OpenAI.
49
49
  * @returns {Promise<any>} - Le markdown structuré (issue de GPT) ou tout autre traitement souhaité.
50
50
  */
51
- export declare function pdf2markdown(output: string, file: string, service: string, openai: any): Promise<{
51
+ export declare function pdf2markdown(folder: string, file: string, service: string, openai: any): Promise<{
52
52
  markdown: any;
53
53
  cost: number;
54
+ outputPath: string;
54
55
  }>;
@@ -30,7 +30,7 @@ async function extractCaptcha(base64Image, openai) {
30
30
  { type: 'image_url', image_url: { url: `data:image/jpeg;base64,${base64Image}` } },
31
31
  ];
32
32
  // Cost per captcha $0.0000696
33
- const model = "gpt-4o-mini";
33
+ const model = "gpt-4.1";
34
34
  const response = await openai.chat.completions.create({
35
35
  model,
36
36
  messages: [{ role: "user", content }],
@@ -55,45 +55,42 @@ async function callGPTForParsingPDF(inputfile, pdfData, openai, links = []) {
55
55
  const pdfDataAsString = JSON.stringify(pdfData, null, 2);
56
56
  // Format: YYYY-MM-DD
57
57
  const today = new Date().toISOString().substring(0, 10);
58
- const linkLabel = ' une liste de liens que tu dois placer dans le document. Si le libellé d\'un lien correspond à un texte existant dans le document, intègre le lien directement dans le texte. Sinon, place ces liens sous forme de liste à puces dans une section annexe (# Références externes) à la fin du document.';
58
+ const linkLabel = 'Voici une liste de liens que tu dois intègrer directement dans le texte si, et seulement si, celui-ci correspond précisément à un texte existant dans le document.';
59
59
  const linkPrefix = linkLabel + links.reduce((acc, link) => {
60
60
  return acc + `- [${link.text}](${link.href})\n`;
61
61
  }, '');
62
62
  // Créer le prompt pour décrire la tâche au LLM
63
63
  const messages = [
64
64
  { role: "system",
65
- content: prompts_1.textToMarkdownPrompt },
65
+ content: prompts_1.htmlToMarkdownPrompt },
66
66
  { role: "user",
67
- content: `Nous sommes le ${today}, voici le nom du document "${inputfile}", et ${linkPrefix}` },
68
- { role: "user",
69
- content: `Voici le document, pour commencer, tu DOIS extrais uniquement la structure (titres et sous-titres) selon les instructions et sans les contenus détaillés:\n\n${pdfDataAsString}` }
67
+ content: `Structure le contenu exhaustif en Markdown sans rien inventer, et avec les liens intégrés correctement.\n Nous sommes le ${today}.\n${linkPrefix}\nLe contenu du document est:\n${pdfDataAsString}`
68
+ }
70
69
  ];
70
+ // console.log('🌶️ DEBUG: callGPTForParsingPDF -- SYSTEM:', messages[0].content);
71
+ // console.log('🌶️ DEBUG: callGPTForParsingPDF -- USER:', messages[1].content);
71
72
  // WARNING: o3-mini is buggy with "Marche à suivre nouveau bail.pdf"
72
- const model = "o3-mini"; // "gpt-4o-mini";
73
+ const model = "gpt-4.1"; // "gpt-4.1";
73
74
  let response = await openai.chat.completions.create({
74
75
  model: model,
75
76
  messages,
76
- max_completion_tokens: 15192,
77
- reasoning_effort: "low",
78
- stop: "|<|james|>|"
79
77
  });
80
78
  // response_format: { type: "json_object" }
81
79
  let cost = (0, princing_openai_1.calculateCost)(model, response.usage);
82
- console.log(`Markdown 💰 cost: ${cost}`);
83
- messages.push({
84
- role: "user",
85
- content: `Maintenant génère le contenu Markdown détaillé et exhaustif correspondant à chaque section avec les liens intégrés correctement.`
86
- });
87
- response = await openai.chat.completions.create({
88
- model: model,
89
- messages,
90
- max_completion_tokens: 15192,
91
- reasoning_effort: "low",
92
- stop: "|<|james|>|"
93
- });
80
+ // messages.push({
81
+ // role: "user",
82
+ // content: `Maintenant génère le contenu Markdown détaillé et exhaustif correspondant à chaque section avec les liens intégrés correctement.`
83
+ // });
84
+ // response = await openai.chat.completions.create({
85
+ // model: model,
86
+ // messages,
87
+ // max_completion_tokens: 15192,
88
+ // reasoning_effort:"low",
89
+ // stop:"|<|james|>|"
90
+ // });
94
91
  // Récupérer la réponse markdown
95
92
  let markdown = response.choices[0].message.content;
96
- cost += (0, princing_openai_1.calculateCost)(model, response.usage);
93
+ console.log(`Markdown 💰 cost: ${cost}`);
97
94
  //
98
95
  // add a regex to extract the markdown content between <thinking></thinking> tags
99
96
  let markdownWithoutThinking = markdown.replace(/<thinking>[\s\S]*?<\/thinking>/g, '');
@@ -160,7 +157,7 @@ async function extractLinksFromPDF(pdfPath, output) {
160
157
  }
161
158
  }
162
159
  /**
163
- * Convertit un document HTML en markdown en appelant le modèle GPT (ex: gpt-4o-mini)
160
+ * Convertit un document HTML en markdown en appelant le modèle GPT (ex: gpt-4.1)
164
161
  * pour analyser et reformater le document.
165
162
  *
166
163
  * @param {any} htmlData - Le document HTML à transformer en markdown.
@@ -183,15 +180,14 @@ async function callGPTForParsingHTML(html, openai) {
183
180
  ];
184
181
  // Appel à l'API ChatCompletion
185
182
  const response = await openai.chat.completions.create({
186
- model: "gpt-4o-mini",
183
+ model: "gpt-4.1",
187
184
  messages,
188
185
  max_completion_tokens: 15192,
189
186
  temperature: 0,
190
187
  frequency_penalty: 0.0,
191
188
  presence_penalty: 0.0,
192
- stop: "|<|james|>|"
193
189
  });
194
- const cost = (0, princing_openai_1.calculateCost)("gpt-4o-mini", response.usage);
190
+ const cost = (0, princing_openai_1.calculateCost)("gpt-4.1", response.usage);
195
191
  console.log(`Markdown 💰 cost: ${cost}`);
196
192
  // Récupérer la réponse markdown
197
193
  const markdown = response.choices[0].message.content;
@@ -218,12 +214,12 @@ function cleanHTML(html) {
218
214
  * @returns {Promise<{markdown: string, cost: number}>} - The generated markdown content and the cost of the GPT API call.
219
215
  */
220
216
  async function html2markdown(output, file, service, openai) {
221
- const filename = (0, utils_1.slug)(path_1.default.basename(file, path_1.default.extname(file)));
217
+ const filename = (0, utils_1.toSlug)(path_1.default.basename(file, path_1.default.extname(file)));
222
218
  const htmlraw = fs_1.default.readFileSync(file, "utf8");
223
219
  const html = cleanHTML(htmlraw);
224
220
  const outputfile = html.indexOf('Please sign in') > -1 ? 'unauthorized-' : (service.toLocaleLowerCase() + '-');
225
221
  const { markdown, cost } = await callGPTForParsingPDF(file, html, openai);
226
- fs_1.default.writeFileSync(path_1.default.join(output, `${outputfile + filename}.md`), markdown);
222
+ fs_1.default.writeFileSync(path_1.default.join(output, `${outputfile + filename}.md`), markdown, { encoding: 'utf8', flag: 'w' });
227
223
  return { markdown, cost };
228
224
  }
229
225
  /**
@@ -236,14 +232,14 @@ async function html2markdown(output, file, service, openai) {
236
232
  * @param {any} openai - L'instance configurée pour appeler l'API OpenAI.
237
233
  * @returns {Promise<any>} - Le markdown structuré (issue de GPT) ou tout autre traitement souhaité.
238
234
  */
239
- async function pdf2markdown(output, file, service, openai) {
240
- const filename = (0, utils_1.slug)(path_1.default.basename(file, path_1.default.extname(file)));
235
+ async function pdf2markdown(folder, file, service, openai) {
236
+ const filename = (0, utils_1.toSlug)(path_1.default.basename(file, path_1.default.extname(file)));
241
237
  // Créez des noms de fichiers temporaires pour le PDF nettoyé et le XML généré.
242
- const tempPdf = path_1.default.join(output, `cleaned-${randomFile()}.pdf`);
243
- const tempOut = path_1.default.join(output, `${filename}.txt`);
238
+ const tempPdf = path_1.default.join(folder, `cleaned-${randomFile()}.pdf`);
239
+ const tempOut = path_1.default.join(folder, `${filename}.txt`);
244
240
  //
245
- // generated output path
246
- const outputPath = path_1.default.join(output, `${service.toLocaleLowerCase()}-${filename}.md`);
241
+ // generated folder path
242
+ const outputPath = path_1.default.join(folder, `${(0, utils_1.toSlug)(service.toLocaleLowerCase())}-${filename}.md`);
247
243
  try {
248
244
  //
249
245
  // replace pdftotext with python script PyMuPDF
@@ -251,11 +247,11 @@ async function pdf2markdown(output, file, service, openai) {
251
247
  // const { stdout } = await execFileAsync("python3", ["./bin/extract_text_with_links.py", file]);
252
248
  // const { text, links } = JSON.parse(stdout);
253
249
  await execAsync(`pdftotext -nodiag -nopgbrk "${file}" "${outputPath}"`);
254
- const links = await extractLinksFromPDF(file, output);
250
+ const links = await extractLinksFromPDF(file, folder);
255
251
  const text = fs_1.default.readFileSync(outputPath, "utf8");
256
252
  const { markdown, cost } = await callGPTForParsingPDF(file, text, openai, links);
257
253
  fs_1.default.writeFileSync(outputPath, markdown);
258
- return { markdown, cost };
254
+ return { markdown, cost, outputPath };
259
255
  /**
260
256
 
261
257
  // STEP 1: Clean the PDF using Ghostscript.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Point d'entrée du module AgentStateGraph
3
+ * Exports principaux pour le système de gestion des discussions par agent
4
+ */
5
+ export type { AgentMessage, TokenUsage, AgentDiscussion, AgentStateGraph as IAgentStateGraph, ClientDiscussion } from './types';
6
+ export { getSpecializedAgent } from './types';
7
+ export { AgentStateGraph } from './stategraph';
8
+ export { sessionStateGraphGet, sessionStateGraphSet, sessionStateGraphClear, sessionStateGraphExists, sessionStateGraphSize, migrateFromLegacySession } from './stategraph.storage';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Point d'entrée du module AgentStateGraph
4
+ * Exports principaux pour le système de gestion des discussions par agent
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.migrateFromLegacySession = exports.sessionStateGraphSize = exports.sessionStateGraphExists = exports.sessionStateGraphClear = exports.sessionStateGraphSet = exports.sessionStateGraphGet = exports.AgentStateGraph = exports.getSpecializedAgent = void 0;
8
+ // Fonction utilitaire
9
+ var types_1 = require("./types");
10
+ Object.defineProperty(exports, "getSpecializedAgent", { enumerable: true, get: function () { return types_1.getSpecializedAgent; } });
11
+ // Classe principale
12
+ var stategraph_1 = require("./stategraph");
13
+ Object.defineProperty(exports, "AgentStateGraph", { enumerable: true, get: function () { return stategraph_1.AgentStateGraph; } });
14
+ // Fonctions de stockage
15
+ var stategraph_storage_1 = require("./stategraph.storage");
16
+ Object.defineProperty(exports, "sessionStateGraphGet", { enumerable: true, get: function () { return stategraph_storage_1.sessionStateGraphGet; } });
17
+ Object.defineProperty(exports, "sessionStateGraphSet", { enumerable: true, get: function () { return stategraph_storage_1.sessionStateGraphSet; } });
18
+ Object.defineProperty(exports, "sessionStateGraphClear", { enumerable: true, get: function () { return stategraph_storage_1.sessionStateGraphClear; } });
19
+ Object.defineProperty(exports, "sessionStateGraphExists", { enumerable: true, get: function () { return stategraph_storage_1.sessionStateGraphExists; } });
20
+ Object.defineProperty(exports, "sessionStateGraphSize", { enumerable: true, get: function () { return stategraph_storage_1.sessionStateGraphSize; } });
21
+ Object.defineProperty(exports, "migrateFromLegacySession", { enumerable: true, get: function () { return stategraph_storage_1.migrateFromLegacySession; } });
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @fileoverview Implémentation du système AgentStateGraph
3
+ * Classe principale pour gérer les discussions par agent
4
+ */
5
+ import { AgentStateGraph as IAgentStateGraph, AgentDiscussion, AgentMessage, TokenUsage, ClientDiscussion } from './types';
6
+ /**
7
+ * Implémentation du StateGraph pour la gestion des discussions par agent
8
+ * Remplace AgenticMemoryManager avec une architecture simplifiée
9
+ */
10
+ export declare class AgentStateGraph implements IAgentStateGraph {
11
+ discussions: AgentDiscussion[];
12
+ /**
13
+ * Crée ou restaure une discussion pour un agent donné
14
+ * @param agentName Nom de l'agent
15
+ * @returns Discussion existante ou nouvelle discussion créée
16
+ */
17
+ createOrRestore(agentName: string, description?: string): AgentDiscussion;
18
+ /**
19
+ * Ajoute un message à la discussion d'un agent
20
+ * @param agentName Nom de l'agent
21
+ * @param message Message sans ID ni timestamp (auto-générés)
22
+ */
23
+ push(agentName: string, message: Omit<AgentMessage, 'id' | 'timestamp'>): void;
24
+ /**
25
+ * Écrase le message system de la discussion avec un nouvel agent
26
+ * Le message system est toujours messages[0] avec role: "system"
27
+ * @param agentName Nom de l'agent
28
+ * @param content Nouveau contenu du message system
29
+ */
30
+ set(agentName: string, content: string): void;
31
+ /**
32
+ * Additionne l'usage des tokens pour un agent
33
+ * @param agentName Nom de l'agent
34
+ * @param usage Ajout aux valeurs existantes (addition)
35
+ */
36
+ updateTokens(agentName: string, usage: Partial<TokenUsage>): void;
37
+ /**
38
+ * Retourne une vue filtrée pour le client
39
+ * Supprime les messages system et les métadonnées d'outils
40
+ * @param agentName Nom de l'agent
41
+ * @returns Discussion filtrée pour l'affichage client
42
+ */
43
+ toClientView(agentName: string): ClientDiscussion;
44
+ /**
45
+ * Trouve une discussion par son ID
46
+ * @param discussionId ID de la discussion
47
+ * @returns Discussion trouvée ou undefined
48
+ */
49
+ findDiscussionById(discussionId: string): AgentDiscussion | undefined;
50
+ /**
51
+ * Supprime une discussion
52
+ * @param discussionId ID de la discussion à supprimer
53
+ * @returns true si supprimée, false si non trouvée
54
+ */
55
+ deleteDiscussion(discussionId: string): boolean;
56
+ /**
57
+ * Vide une discussion en gardant uniquement le message system
58
+ * @param agentName Nom de l'agent
59
+ */
60
+ clearDiscussion(agentName: string): void;
61
+ /**
62
+ * Supprime un message spécifique d'une discussion
63
+ * @param agentName Nom de l'agent
64
+ * @param messageId ID du message à supprimer
65
+ * @returns true si le message a été supprimé, false s'il n'a pas été trouvé
66
+ */
67
+ deleteMessage(agentName: string, messageId: string): boolean;
68
+ /**
69
+ * Renomme une discussion
70
+ * @param discussionId ID de la discussion
71
+ * @param name Nouveau nom
72
+ * @param description Nouvelle description (optionnel)
73
+ */
74
+ renameDiscussion(discussionId: string, name: string, description?: string): void;
75
+ /**
76
+ * Retourne l'agent spécialisé pour une discussion
77
+ * @param agentName Nom de l'agent
78
+ * @returns Nom de l'agent spécialisé
79
+ */
80
+ getSpecializedAgent(agentName: string): string;
81
+ /**
82
+ * Sérialise le StateGraph en JSON
83
+ * @returns Représentation JSON
84
+ */
85
+ toJSON(): any;
86
+ /**
87
+ * Restaure le StateGraph depuis JSON
88
+ * @param data Données JSON
89
+ */
90
+ fromJSON(data: any): void;
91
+ }