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,12 @@
1
+ /**
2
+ * MapLLM - Simple hierarchical reducer with native loaders
3
+ */
4
+ import type { NativeLoader, StatefulReducerConfig, MapLLMReduceResult } from './reducer.types';
5
+ /**
6
+ * MapLLM - Orchestrateur principal pour le reduce hiérarchique
7
+ */
8
+ export declare class MapLLM {
9
+ private loader;
10
+ constructor(loader: NativeLoader);
11
+ reduce(config: StatefulReducerConfig, callback: (result: MapLLMReduceResult, currentValue: string | object) => MapLLMReduceResult, init: MapLLMReduceResult): Promise<MapLLMReduceResult>;
12
+ }
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ /**
3
+ * MapLLM - Simple hierarchical reducer with native loaders
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MapLLM = void 0;
7
+ const execute_1 = require("../execute");
8
+ const utils_1 = require("../utils");
9
+ /**
10
+ * MapLLM - Orchestrateur principal pour le reduce hiérarchique
11
+ */
12
+ class MapLLM {
13
+ constructor(loader) {
14
+ this.loader = loader;
15
+ }
16
+ async reduce(config, callback, init) {
17
+ const startTime = Date.now();
18
+ // Merge init with defaults
19
+ let result = { ...init, ...{
20
+ continue: false,
21
+ model: init.model || (0, execute_1.modelConfig)("LOW-fast"),
22
+ metadata: {
23
+ iterations: 0,
24
+ averageChunkSize: 0,
25
+ processingTimeMs: 0
26
+ }
27
+ } };
28
+ const verbose = init.verbose || false;
29
+ if (verbose) {
30
+ console.log('🚀 MapLLM: Starting reduce process...');
31
+ }
32
+ let position = 0;
33
+ let totalChunkSize = 0;
34
+ let totalReduce = 0;
35
+ const openai = (0, utils_1.openaiInstance)();
36
+ const llm = Object.assign({}, result.model);
37
+ llm.stream = false;
38
+ delete llm.stream_options;
39
+ //
40
+ // maxIterations is set by the callback
41
+ while (!result.maxIterations) {
42
+ if (result.metadata) {
43
+ result.metadata.iterations++;
44
+ }
45
+ try {
46
+ // 1. Load chunk
47
+ const chunk = await this.loader.loadNativeChunk(position);
48
+ if (verbose) {
49
+ console.log(`📦 Processing chunk ${result.metadata?.iterations} position ${position} is eof ${chunk.eof}`);
50
+ }
51
+ totalChunkSize += chunk.content.length;
52
+ // Update position immediately after loading (before any continue)
53
+ position = chunk.position;
54
+ // 2. Digest chunk
55
+ // Simple message array without memory manager - but preserve conversation
56
+ // Prepare messages based on acc type and content
57
+ const isFirstChunk = (typeof result.acc === 'string' && result.acc.length === 0) ||
58
+ (typeof result.acc === 'object' && Object.keys(result.acc).length === 0);
59
+ const accContent = typeof result.acc === 'string' ? result.acc : JSON.stringify(result.acc);
60
+ const messages = isFirstChunk ? [
61
+ { role: "system", content: config.digestPrompt },
62
+ { role: "user", content: chunk.content }
63
+ ] : [
64
+ { role: "system", content: config.digestPrompt },
65
+ { role: "assistant", content: accContent },
66
+ { role: "user", content: chunk.content }
67
+ ];
68
+ llm.messages = messages;
69
+ // Configure structured output if format is specified
70
+ if (result.format) {
71
+ llm.response_format = {
72
+ type: "json_schema",
73
+ json_schema: {
74
+ name: result.format.name,
75
+ schema: result.format.schema,
76
+ strict: result.format.strict ?? true
77
+ }
78
+ };
79
+ }
80
+ const chat = await openai.chat.completions.create(llm);
81
+ const digestMessage = chat.choices[0]?.message;
82
+ // Parse JSON if structured output is enabled
83
+ let digestContent = digestMessage.content;
84
+ if (result.format && digestContent) {
85
+ try {
86
+ digestContent = JSON.parse(digestContent);
87
+ }
88
+ catch (e) {
89
+ console.warn('Failed to parse structured output as JSON:', digestContent);
90
+ }
91
+ }
92
+ //
93
+ // the reduce callback operates the process of digesting and accumulating
94
+ result = callback(result, digestContent);
95
+ if (result.maxIterations) {
96
+ throw new Error(`Maximum iterations (${result.metadata?.iterations}) reached without completion`);
97
+ }
98
+ // Check EOF BEFORE any continue to ensure we exit the loop
99
+ if (chunk.eof) {
100
+ if (verbose) {
101
+ console.log('🏁 End of document reached after processing final chunk');
102
+ }
103
+ break;
104
+ }
105
+ // Décision de réduction basée sur callback
106
+ if (!result.continue) {
107
+ continue;
108
+ }
109
+ const accForReduce = typeof result.acc === 'string' ? result.acc : JSON.stringify(result.acc);
110
+ llm.messages = [
111
+ { role: "system", content: config.reducePrompt },
112
+ { role: "user", content: accForReduce }
113
+ ];
114
+ // Configure structured output if format is specified
115
+ if (result.format) {
116
+ llm.response_format = {
117
+ type: "json_schema",
118
+ json_schema: {
119
+ name: result.format.name,
120
+ schema: result.format.schema,
121
+ strict: result.format.strict ?? true
122
+ }
123
+ };
124
+ }
125
+ const reduce = await openai.chat.completions.create(llm);
126
+ const reduceMessage = reduce.choices[0]?.message;
127
+ //
128
+ // should not happen
129
+ if (!reduceMessage.content) {
130
+ continue;
131
+ }
132
+ // 3. Reduce with system - Update result.acc (replace)
133
+ totalReduce++;
134
+ // Parse JSON if structured output is enabled
135
+ if (result.format) {
136
+ try {
137
+ result.acc = JSON.parse(reduceMessage.content);
138
+ }
139
+ catch (e) {
140
+ console.warn('Failed to parse reduce result as JSON:', reduceMessage.content);
141
+ result.acc = reduceMessage.content;
142
+ }
143
+ }
144
+ else {
145
+ result.acc = reduceMessage.content;
146
+ }
147
+ if (verbose) {
148
+ console.log(`✅ Reduce ${result.metadata?.iterations} processed (${chunk.content.length} chars)`);
149
+ console.log("✅ Reduce result:", result.acc);
150
+ }
151
+ // EOF check is now handled earlier in the loop
152
+ }
153
+ catch (error) {
154
+ if (verbose) {
155
+ console.log(`❌ Chunk ${result.metadata?.iterations} failed: ${error}`);
156
+ }
157
+ throw new Error(`Failed to process chunk ${result.metadata?.iterations}: ${error}`);
158
+ }
159
+ }
160
+ // Final reduce
161
+ const finalAccContent = typeof result.acc === 'string' ? result.acc : JSON.stringify(result.acc);
162
+ const messages = [
163
+ { role: "system", content: config.reducePrompt },
164
+ { role: "user", content: finalAccContent }
165
+ ];
166
+ llm.messages = messages;
167
+ // Configure structured output if format is specified
168
+ if (result.format) {
169
+ llm.response_format = {
170
+ type: "json_schema",
171
+ json_schema: {
172
+ name: result.format.name,
173
+ schema: result.format.schema,
174
+ strict: result.format.strict ?? true
175
+ }
176
+ };
177
+ }
178
+ const reduce = await openai.chat.completions.create(llm);
179
+ const finalContent = reduce.choices[0]?.message.content || '';
180
+ // Parse JSON if structured output is enabled
181
+ if (result.format && finalContent) {
182
+ try {
183
+ result.acc = JSON.parse(finalContent);
184
+ }
185
+ catch (e) {
186
+ console.warn('Failed to parse final result as JSON:', finalContent);
187
+ result.acc = finalContent;
188
+ }
189
+ }
190
+ else {
191
+ result.acc = finalContent;
192
+ }
193
+ const endTime = Date.now();
194
+ const processingTimeMs = endTime - startTime;
195
+ if (verbose) {
196
+ console.log(`🎉 MapLLM completed: ${result.metadata?.iterations} chunks in ${processingTimeMs}ms`);
197
+ }
198
+ // Update final metadata
199
+ result.continue = false; // Terminé
200
+ if (result.metadata) {
201
+ result.metadata.processingTimeMs = processingTimeMs;
202
+ result.metadata.averageChunkSize = Math.round(totalChunkSize / result.metadata.iterations);
203
+ }
204
+ return result;
205
+ }
206
+ }
207
+ exports.MapLLM = MapLLM;
@@ -0,0 +1,3 @@
1
+ export * from './reducer.core';
2
+ export * from './reducer.loaders';
3
+ export * from './reducer.types';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * MapLLM Reducer - Simple hierarchical reducer
3
+ *
4
+ * Main export file for the MapLLM reducer functionality
5
+ */
6
+ export { MapLLM } from './reducer.core';
7
+ export { FileNativeLoader, StringNativeLoader } from './reducer.loaders';
8
+ export type { NativeLoader, StatefulReducerConfig, MapLLMOptions, ReduceResult, ChunkStrategy } from './reducer.types';
9
+ export declare const exampleConfigs: {
10
+ weather: {
11
+ digestPrompt: string;
12
+ reducePrompt: string;
13
+ };
14
+ foods: {
15
+ digestPrompt: string;
16
+ reducePrompt: string;
17
+ };
18
+ };
19
+ export declare const examples: {
20
+ /**
21
+ * Example: Weather data analysis
22
+ */
23
+ weatherAnalysis(weatherFilePath: string): Promise<import("./reducer.types").ReduceResult>;
24
+ /**
25
+ * Example: Food selection from string content
26
+ */
27
+ foodSelection(foodListContent: string): Promise<import("./reducer.types").ReduceResult>;
28
+ };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * MapLLM Reducer - Simple hierarchical reducer
4
+ *
5
+ * Main export file for the MapLLM reducer functionality
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.examples = exports.exampleConfigs = exports.StringNativeLoader = exports.FileNativeLoader = exports.MapLLM = void 0;
42
+ // Core classes
43
+ var reducer_core_1 = require("./reducer.core");
44
+ Object.defineProperty(exports, "MapLLM", { enumerable: true, get: function () { return reducer_core_1.MapLLM; } });
45
+ var reducer_loaders_1 = require("./reducer.loaders");
46
+ Object.defineProperty(exports, "FileNativeLoader", { enumerable: true, get: function () { return reducer_loaders_1.FileNativeLoader; } });
47
+ Object.defineProperty(exports, "StringNativeLoader", { enumerable: true, get: function () { return reducer_loaders_1.StringNativeLoader; } });
48
+ // Example configurations
49
+ exports.exampleConfigs = {
50
+ weather: {
51
+ digestPrompt: `Tu es un expert en analyse de données météorologiques.
52
+ Analyse ce chunk de données météo et extrais:
53
+ - Les types de météo présents (ensoleillé, pluvieux, nuageux, neigeux, orageux)
54
+ - Le nombre d'entrées par type
55
+ - Les IDs associés à chaque type
56
+
57
+ Réponds en JSON strict avec la structure:
58
+ {
59
+ "weatherTypes": {
60
+ "ensoleillé": {"count": N, "ids": [...]},
61
+ "pluvieux": {"count": N, "ids": [...]}
62
+ }
63
+ }`,
64
+ reducePrompt: `Tu es un expert en consolidation de données météorologiques.
65
+ Synthétise toutes les analyses météo en un résultat consolidé:
66
+ - Fusionne tous les types de météo
67
+ - Additionne les counts
68
+ - Combine les IDs (sans doublons)
69
+ - Calcule les totaux par type
70
+
71
+ Réponds en JSON avec la structure finale consolidée.`
72
+ },
73
+ foods: {
74
+ digestPrompt: `Tu es un expert en nutrition végétarienne.
75
+ Analyse cette liste d'aliments et identifie:
76
+ - Les aliments végétariens/vegan
77
+ - Leur catégorie (légumes, fruits, céréales, légumineuses, etc.)
78
+ - Leur valeur nutritionnelle approximative
79
+
80
+ Réponds en JSON strict avec les aliments sélectionnés.`,
81
+ reducePrompt: `Tu es un expert en nutrition végétarienne.
82
+ Crée une sélection équilibrée d'aliments végétariens/vegan:
83
+ - Distribution équilibrée entre catégories
84
+ - Maximum 50 aliments
85
+ - Priorité aux aliments nutritifs et variés
86
+
87
+ Réponds avec la liste finale sélectionnée en JSON.`
88
+ }
89
+ };
90
+ // Usage examples
91
+ exports.examples = {
92
+ /**
93
+ * Example: Weather data analysis
94
+ */
95
+ async weatherAnalysis(weatherFilePath) {
96
+ const { FileNativeLoader } = await Promise.resolve().then(() => __importStar(require('./reducer.loaders')));
97
+ const { MapLLM } = await Promise.resolve().then(() => __importStar(require('./reducer.core')));
98
+ const loader = new FileNativeLoader(weatherFilePath, { type: 'lines', size: 50 });
99
+ const mapper = new MapLLM(loader);
100
+ return await mapper.reduce(exports.exampleConfigs.weather, {
101
+ verbose: true,
102
+ maxRetries: 3
103
+ });
104
+ },
105
+ /**
106
+ * Example: Food selection from string content
107
+ */
108
+ async foodSelection(foodListContent) {
109
+ const { StringNativeLoader } = await Promise.resolve().then(() => __importStar(require('./reducer.loaders')));
110
+ const { MapLLM } = await Promise.resolve().then(() => __importStar(require('./reducer.core')));
111
+ const loader = new StringNativeLoader(foodListContent, { type: 'lines', size: 100 });
112
+ const mapper = new MapLLM(loader);
113
+ return await mapper.reduce(exports.exampleConfigs.foods, {
114
+ verbose: true,
115
+ maxDigestSize: 3000
116
+ });
117
+ }
118
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./reducer.core"), exports);
18
+ __exportStar(require("./reducer.loaders"), exports);
19
+ __exportStar(require("./reducer.types"), exports);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Native Loaders for MapLLM
3
+ */
4
+ import type { NativeLoader, ChunkStrategy } from './reducer.types';
5
+ /**
6
+ * FileNativeLoader - Loader pour fichiers avec chunking par lignes
7
+ */
8
+ export declare class FileNativeLoader implements NativeLoader {
9
+ private chunks;
10
+ constructor(filePath: string, strategy?: ChunkStrategy);
11
+ loadNativeChunk(position: number): Promise<{
12
+ content: string;
13
+ eof: boolean;
14
+ position: number;
15
+ }>;
16
+ private createChunks;
17
+ private chunkByLines;
18
+ private chunkByParagraphs;
19
+ }
20
+ /**
21
+ * StringNativeLoader - Loader pour contenu en mémoire
22
+ */
23
+ export declare class StringNativeLoader implements NativeLoader {
24
+ private chunks;
25
+ constructor(content: string, strategy?: ChunkStrategy);
26
+ loadNativeChunk(position: number): Promise<{
27
+ content: string;
28
+ eof: boolean;
29
+ position: number;
30
+ }>;
31
+ private createChunks;
32
+ private chunkByLines;
33
+ private chunkByParagraphs;
34
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * Native Loaders for MapLLM
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StringNativeLoader = exports.FileNativeLoader = void 0;
7
+ const fs_1 = require("fs");
8
+ /**
9
+ * FileNativeLoader - Loader pour fichiers avec chunking par lignes
10
+ */
11
+ class FileNativeLoader {
12
+ constructor(filePath, strategy = { type: 'lines', size: 50 }) {
13
+ this.chunks = [];
14
+ const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
15
+ this.chunks = this.createChunks(content, strategy);
16
+ }
17
+ async loadNativeChunk(position) {
18
+ if (position >= this.chunks.length) {
19
+ throw new Error(`Position ${position} out of bounds (max: ${this.chunks.length - 1})`);
20
+ }
21
+ const content = this.chunks[position];
22
+ const nextPosition = position + 1;
23
+ const eof = nextPosition >= this.chunks.length;
24
+ return {
25
+ content,
26
+ eof,
27
+ position: nextPosition
28
+ };
29
+ }
30
+ createChunks(content, strategy) {
31
+ switch (strategy.type) {
32
+ case 'lines':
33
+ return this.chunkByLines(content, strategy.size);
34
+ case 'paragraphs':
35
+ return this.chunkByParagraphs(content, strategy.size);
36
+ default:
37
+ throw new Error(`Unsupported chunk strategy: ${strategy.type}`);
38
+ }
39
+ }
40
+ chunkByLines(content, linesPerChunk) {
41
+ const lines = content.split('\n');
42
+ const chunks = [];
43
+ for (let i = 0; i < lines.length; i += linesPerChunk) {
44
+ const chunkLines = lines.slice(i, i + linesPerChunk);
45
+ const chunkContent = chunkLines.join('\n').trim();
46
+ if (chunkContent) {
47
+ chunks.push(chunkContent);
48
+ }
49
+ }
50
+ return chunks;
51
+ }
52
+ chunkByParagraphs(content, paragraphsPerChunk) {
53
+ const paragraphs = content.split(/\n\s*\n/).filter(p => p.trim());
54
+ const chunks = [];
55
+ for (let i = 0; i < paragraphs.length; i += paragraphsPerChunk) {
56
+ const chunkParagraphs = paragraphs.slice(i, i + paragraphsPerChunk);
57
+ const chunkContent = chunkParagraphs.join('\n\n').trim();
58
+ if (chunkContent) {
59
+ chunks.push(chunkContent);
60
+ }
61
+ }
62
+ return chunks;
63
+ }
64
+ }
65
+ exports.FileNativeLoader = FileNativeLoader;
66
+ /**
67
+ * StringNativeLoader - Loader pour contenu en mémoire
68
+ */
69
+ class StringNativeLoader {
70
+ constructor(content, strategy = { type: 'lines', size: 50 }) {
71
+ this.chunks = [];
72
+ this.chunks = this.createChunks(content, strategy);
73
+ }
74
+ async loadNativeChunk(position) {
75
+ if (position >= this.chunks.length) {
76
+ throw new Error(`Position ${position} out of bounds (max: ${this.chunks.length - 1})`);
77
+ }
78
+ const content = this.chunks[position];
79
+ const nextPosition = position + 1;
80
+ const eof = nextPosition >= this.chunks.length;
81
+ return {
82
+ content,
83
+ eof,
84
+ position: nextPosition
85
+ };
86
+ }
87
+ createChunks(content, strategy) {
88
+ switch (strategy.type) {
89
+ case 'lines':
90
+ return this.chunkByLines(content, strategy.size);
91
+ case 'paragraphs':
92
+ return this.chunkByParagraphs(content, strategy.size);
93
+ default:
94
+ throw new Error(`Unsupported chunk strategy: ${strategy.type}`);
95
+ }
96
+ }
97
+ chunkByLines(content, linesPerChunk) {
98
+ const lines = content.split('\n');
99
+ const chunks = [];
100
+ for (let i = 0; i < lines.length; i += linesPerChunk) {
101
+ const chunkLines = lines.slice(i, i + linesPerChunk);
102
+ const chunkContent = chunkLines.join('\n').trim();
103
+ if (chunkContent) {
104
+ chunks.push(chunkContent);
105
+ }
106
+ }
107
+ return chunks;
108
+ }
109
+ chunkByParagraphs(content, paragraphsPerChunk) {
110
+ const paragraphs = content.split(/\n\s*\n/).filter(p => p.trim());
111
+ const chunks = [];
112
+ for (let i = 0; i < paragraphs.length; i += paragraphsPerChunk) {
113
+ const chunkParagraphs = paragraphs.slice(i, i + paragraphsPerChunk);
114
+ const chunkContent = chunkParagraphs.join('\n\n').trim();
115
+ if (chunkContent) {
116
+ chunks.push(chunkContent);
117
+ }
118
+ }
119
+ return chunks;
120
+ }
121
+ }
122
+ exports.StringNativeLoader = StringNativeLoader;
@@ -0,0 +1,16 @@
1
+ import { StatefulReducerConfig, StatefulReduceResult, StatefulProcessOptions, ChunkLoader } from "./reducer.types";
2
+ /**
3
+ * Main function to process a document using the stateful agent reduce pattern
4
+ *
5
+ * @param sessionId - Session ID for the discussion/document to process
6
+ * @param config - Stateful reducer configuration
7
+ * @param loader - ChunkLoader interface for loading content chunks
8
+ * @param options - Additional options
9
+ * @returns Promise resolving to the stateful reduce result
10
+ */
11
+ export declare function statefulReduceProcess<T = any>(sessionId: string, config: StatefulReducerConfig, loader: ChunkLoader, options?: StatefulProcessOptions): Promise<StatefulReduceResult<T>>;
12
+ /**
13
+ * Legacy function name for backward compatibility
14
+ * @deprecated Use statefulReduceProcess instead
15
+ */
16
+ export declare function agentReduceProcess<T = any>(sessionId: string, config: any, loader: ChunkLoader, options?: any): Promise<any>;