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
|
@@ -7,7 +7,63 @@ class AgentSimulator {
|
|
|
7
7
|
this.config = config;
|
|
8
8
|
this.executor = new simulator_executor_1.AgentExecutor(config);
|
|
9
9
|
}
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// NOUVELLE API : testCase(scenario, case)
|
|
12
|
+
// ============================================================================
|
|
10
13
|
/**
|
|
14
|
+
* Exécuter un cas de test avec scénario et paramètres séparés
|
|
15
|
+
*
|
|
16
|
+
* @param scenario - Contexte stable (goals, persona, result)
|
|
17
|
+
* @param testCase - Paramètres du test (query, maxExchanges, model, expectedTools)
|
|
18
|
+
* @returns SimulationResult
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const scenario = {
|
|
23
|
+
* goals: 'Obtenir le nombre secret 1942',
|
|
24
|
+
* persona: PERSONA_PATIENT,
|
|
25
|
+
* result: '{"success": boolean, "error": string}'
|
|
26
|
+
* };
|
|
27
|
+
*
|
|
28
|
+
* const result = await simulator.testCase(scenario, {
|
|
29
|
+
* query: 'À quel nombre penses-tu?',
|
|
30
|
+
* maxExchanges: 3, // défaut: 1 (oneshot)
|
|
31
|
+
* expectedTools: { 'transferAgents': { equal: 1 } } // défaut: {}
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
async testCase(scenario, testCase) {
|
|
36
|
+
// Appliquer les défauts
|
|
37
|
+
const resolvedCase = {
|
|
38
|
+
query: testCase.query,
|
|
39
|
+
maxExchanges: testCase.maxExchanges ?? 1, // Défaut: 1 (oneshot)
|
|
40
|
+
expectedTools: testCase.expectedTools ?? {}, // Défaut: pas de validation
|
|
41
|
+
model: testCase.model,
|
|
42
|
+
onMessage: testCase.onMessage
|
|
43
|
+
};
|
|
44
|
+
// TODO: Support model override (Phase 2)
|
|
45
|
+
// if (resolvedCase.model) {
|
|
46
|
+
// this.overrideModel(resolvedCase.model);
|
|
47
|
+
// }
|
|
48
|
+
// Convertir TestScenario vers SimulationScenario et déléguer
|
|
49
|
+
return this.executeSimulation({
|
|
50
|
+
scenario: {
|
|
51
|
+
goals: scenario.goals,
|
|
52
|
+
persona: scenario.persona,
|
|
53
|
+
result: scenario.result || '{"success": boolean, "explain": string, "error": string}'
|
|
54
|
+
},
|
|
55
|
+
query: resolvedCase.query,
|
|
56
|
+
maxExchanges: resolvedCase.maxExchanges,
|
|
57
|
+
expectedTool: resolvedCase.expectedTools,
|
|
58
|
+
onMessage: resolvedCase.onMessage
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// ANCIENNE API : executeSimulation(options) - deprecated
|
|
63
|
+
// ============================================================================
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Utiliser testCase(scenario, case) à la place
|
|
66
|
+
*
|
|
11
67
|
* Exécuter la simulation complète
|
|
12
68
|
*
|
|
13
69
|
* Architecture :
|
|
@@ -9,6 +9,38 @@ export interface SimulatorConfig {
|
|
|
9
9
|
mockCacheInitializer?: (sessionId: string) => Promise<void>;
|
|
10
10
|
ragConfig?: RAGManagerConfig;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Scénario de test - Contexte stable entre les tests
|
|
14
|
+
* Définit la personnalité du simulateur et les objectifs de validation
|
|
15
|
+
*/
|
|
16
|
+
export interface TestScenario {
|
|
17
|
+
description?: string;
|
|
18
|
+
goals: string;
|
|
19
|
+
persona: string;
|
|
20
|
+
result?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Contrainte de validation pour un outil
|
|
24
|
+
*/
|
|
25
|
+
export interface ToolConstraint {
|
|
26
|
+
equal?: number;
|
|
27
|
+
gte?: number;
|
|
28
|
+
lte?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Cas de test spécifique - Varie pour chaque test
|
|
32
|
+
* Définit la query et les attentes de validation
|
|
33
|
+
*/
|
|
34
|
+
export interface TestCaseInput {
|
|
35
|
+
query: string;
|
|
36
|
+
maxExchanges?: number;
|
|
37
|
+
model?: string;
|
|
38
|
+
expectedTools?: Record<string, ToolConstraint>;
|
|
39
|
+
onMessage?: (message: AgentMessage) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Utiliser TestScenario à la place
|
|
43
|
+
*/
|
|
12
44
|
export interface SimulationScenario {
|
|
13
45
|
goals?: string;
|
|
14
46
|
persona?: string;
|
|
@@ -20,15 +52,14 @@ export interface SimulationScenario {
|
|
|
20
52
|
testQuery?: string;
|
|
21
53
|
testResult?: string;
|
|
22
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Utiliser testCase(scenario, case) à la place de executeSimulation(options)
|
|
57
|
+
*/
|
|
23
58
|
export interface SimulationOptions {
|
|
24
59
|
scenario: SimulationScenario;
|
|
25
60
|
query?: string;
|
|
26
61
|
maxExchanges: number;
|
|
27
|
-
expectedTool?: Record<string,
|
|
28
|
-
equal?: number;
|
|
29
|
-
gte?: number;
|
|
30
|
-
lte?: number;
|
|
31
|
-
}>;
|
|
62
|
+
expectedTool?: Record<string, ToolConstraint>;
|
|
32
63
|
onMessage?: (message: AgentMessage) => void;
|
|
33
64
|
}
|
|
34
65
|
export interface SimulationResult {
|
|
@@ -51,7 +82,8 @@ export interface ExecutionContext {
|
|
|
51
82
|
exchangeCount: number;
|
|
52
83
|
lastExecution: ExecutionResult;
|
|
53
84
|
}
|
|
54
|
-
|
|
85
|
+
/** @deprecated Utiliser TestScenario avec l'API testCase() */
|
|
86
|
+
export interface PRSolverScenario {
|
|
55
87
|
ticketId: string;
|
|
56
88
|
ticketMarkdown: string;
|
|
57
89
|
clientType: 'locataire' | 'proprietaire';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SimulationScenario } from './simulator.types';
|
|
1
|
+
import { SimulationScenario, TestScenario } from './simulator.types';
|
|
2
2
|
import { PERSONA_PATIENT, PERSONA_PRESSE, PERSONA_ENERVE } from './simulator.prompts';
|
|
3
3
|
/**
|
|
4
4
|
* Charger un ticket depuis le filesystem (comme agent-vs-agent.ts)
|
|
@@ -22,4 +22,25 @@ custom?: Partial<SimulationScenario>): {
|
|
|
22
22
|
* Supporte l'ancien format (testGoals, testEnd, etc.) pour rétrocompatibilité
|
|
23
23
|
*/
|
|
24
24
|
export declare function buildGenericScenario(scenario: SimulationScenario): SimulationScenario;
|
|
25
|
+
/**
|
|
26
|
+
* Créer un TestScenario pour la nouvelle API testCase()
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const scenario = createTestScenario({
|
|
31
|
+
* goals: 'Obtenir le nombre secret 1942',
|
|
32
|
+
* persona: PERSONA_PATIENT
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const result = await simulator.testCase(scenario, {
|
|
36
|
+
* query: 'À quel nombre penses-tu?'
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTestScenario(options: {
|
|
41
|
+
description?: string;
|
|
42
|
+
goals: string;
|
|
43
|
+
persona: string;
|
|
44
|
+
result?: string;
|
|
45
|
+
}): TestScenario;
|
|
25
46
|
export { PERSONA_PATIENT, PERSONA_PRESSE, PERSONA_ENERVE };
|
|
@@ -37,6 +37,7 @@ exports.PERSONA_ENERVE = exports.PERSONA_PRESSE = exports.PERSONA_PATIENT = void
|
|
|
37
37
|
exports.loadScenario = loadScenario;
|
|
38
38
|
exports.buildScenarioFromTicket = buildScenarioFromTicket;
|
|
39
39
|
exports.buildGenericScenario = buildGenericScenario;
|
|
40
|
+
exports.createTestScenario = createTestScenario;
|
|
40
41
|
const fs = __importStar(require("fs"));
|
|
41
42
|
const path = __importStar(require("path"));
|
|
42
43
|
const simulator_prompts_1 = require("./simulator.prompts");
|
|
@@ -105,3 +106,29 @@ function buildGenericScenario(scenario) {
|
|
|
105
106
|
result: scenario.result || '{"success": boolean, "error": string, "description": string}'
|
|
106
107
|
};
|
|
107
108
|
}
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// NOUVELLE API : createTestScenario (pour testCase)
|
|
111
|
+
// ============================================================================
|
|
112
|
+
/**
|
|
113
|
+
* Créer un TestScenario pour la nouvelle API testCase()
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const scenario = createTestScenario({
|
|
118
|
+
* goals: 'Obtenir le nombre secret 1942',
|
|
119
|
+
* persona: PERSONA_PATIENT
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* const result = await simulator.testCase(scenario, {
|
|
123
|
+
* query: 'À quel nombre penses-tu?'
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
function createTestScenario(options) {
|
|
128
|
+
return {
|
|
129
|
+
description: options.description,
|
|
130
|
+
goals: options.goals,
|
|
131
|
+
persona: options.persona,
|
|
132
|
+
result: options.result || '{"success": boolean, "explain": string, "error": string}'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.accumulateUsageTokens = accumulateUsageTokens;
|
|
4
4
|
exports.stepsToActions = stepsToActions;
|
|
5
5
|
exports.batchProcessToolCalls = batchProcessToolCalls;
|
|
6
|
-
const
|
|
6
|
+
const pricing_1 = require("../llm/pricing");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
/**
|
|
9
9
|
* OPTIM: Accumule l'usage des tokens et met à jour stateGraph + discussion.usage
|
|
@@ -18,7 +18,7 @@ const utils_1 = require("../utils");
|
|
|
18
18
|
* @param usage - Usage retourné par l'API (prompt_tokens, completion_tokens, total_tokens)
|
|
19
19
|
*/
|
|
20
20
|
function accumulateUsageTokens(stateGraph, discussion, agentName, model, usage) {
|
|
21
|
-
(0,
|
|
21
|
+
(0, pricing_1.accumulateCost)(discussion.usage, model, usage);
|
|
22
22
|
stateGraph.updateTokens(agentName, {
|
|
23
23
|
prompt: usage?.prompt_tokens || 0,
|
|
24
24
|
completion: usage?.completion_tokens || 0,
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { AgentModel } from '../types';
|
|
2
|
+
import { LLMProvider } from '../llm';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration des modèles pour Chat Completions (legacy) et Responses API
|
|
4
5
|
*
|
|
5
6
|
* Gère la configuration des modèles avec migration automatique des paramètres
|
|
6
|
-
*
|
|
7
|
+
* entre les deux APIs.
|
|
7
8
|
*
|
|
8
|
-
* @param model - Alias du modèle (LOW
|
|
9
|
-
* @param custom - Options
|
|
10
|
-
* @param custom.
|
|
11
|
-
* @param
|
|
12
|
-
*
|
|
13
|
-
* - verbosity → text.verbosity
|
|
14
|
-
* @returns Configuration du modèle
|
|
9
|
+
* @param model - Alias du modèle (ex: "LOW", "MEDIUM", "HIGH", "EMBEDDING-small", "VISION")
|
|
10
|
+
* @param custom - Options personnalisées (provider, thinking, temperature, etc.)
|
|
11
|
+
* @param custom.provider - Provider à utiliser ('openai' | 'xai'), default: LLM_PROVIDER env
|
|
12
|
+
* @param custom.thinking - Active le mode raisonnement (reasoning_effort: high)
|
|
13
|
+
* @param forResponses - Si true, adapte pour l'API Responses (sinon Chat Completions)
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Modèle par défaut
|
|
17
|
+
* const config = modelConfig("MEDIUM");
|
|
18
|
+
*
|
|
19
|
+
* // Forcer OpenAI pour embeddings
|
|
20
|
+
* const config = modelConfig("EMBEDDING-small", { provider: 'openai' });
|
|
21
|
+
*
|
|
22
|
+
* // Vision avec xAI
|
|
23
|
+
* const config = modelConfig("VISION", { provider: 'xai' });
|
|
18
24
|
*/
|
|
19
|
-
export declare function modelConfig(model: string, custom?:
|
|
25
|
+
export declare function modelConfig(model: string, custom?: {
|
|
26
|
+
provider?: LLMProvider;
|
|
27
|
+
thinking?: boolean;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}, forResponses?: boolean): AgentModel;
|
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.modelConfig = modelConfig;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const llm_1 = require("../llm");
|
|
5
|
+
const pricing_1 = require("../llm/pricing");
|
|
6
6
|
/**
|
|
7
7
|
* Configuration des modèles pour Chat Completions (legacy) et Responses API
|
|
8
8
|
*
|
|
9
9
|
* Gère la configuration des modèles avec migration automatique des paramètres
|
|
10
|
-
*
|
|
10
|
+
* entre les deux APIs.
|
|
11
11
|
*
|
|
12
|
-
* @param model - Alias du modèle (LOW
|
|
13
|
-
* @param custom - Options
|
|
14
|
-
* @param custom.
|
|
15
|
-
* @param
|
|
16
|
-
*
|
|
17
|
-
* - verbosity → text.verbosity
|
|
18
|
-
* @returns Configuration du modèle
|
|
12
|
+
* @param model - Alias du modèle (ex: "LOW", "MEDIUM", "HIGH", "EMBEDDING-small", "VISION")
|
|
13
|
+
* @param custom - Options personnalisées (provider, thinking, temperature, etc.)
|
|
14
|
+
* @param custom.provider - Provider à utiliser ('openai' | 'xai'), default: LLM_PROVIDER env
|
|
15
|
+
* @param custom.thinking - Active le mode raisonnement (reasoning_effort: high)
|
|
16
|
+
* @param forResponses - Si true, adapte pour l'API Responses (sinon Chat Completions)
|
|
19
17
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Modèle par défaut
|
|
20
|
+
* const config = modelConfig("MEDIUM");
|
|
21
|
+
*
|
|
22
|
+
* // Forcer OpenAI pour embeddings
|
|
23
|
+
* const config = modelConfig("EMBEDDING-small", { provider: 'openai' });
|
|
24
|
+
*
|
|
25
|
+
* // Vision avec xAI
|
|
26
|
+
* const config = modelConfig("VISION", { provider: 'xai' });
|
|
22
27
|
*/
|
|
23
28
|
function modelConfig(model, custom, forResponses = false) {
|
|
29
|
+
//
|
|
30
|
+
// Extraire et supprimer les paramètres spéciaux
|
|
31
|
+
const provider = custom?.provider || (0, llm_1.getDefaultProvider)();
|
|
24
32
|
const thinking = custom?.thinking || false;
|
|
33
|
+
delete custom?.provider;
|
|
25
34
|
delete custom?.thinking;
|
|
26
35
|
const defaultOptions = Object.assign({
|
|
27
36
|
stream_options: { "include_usage": true },
|
|
@@ -29,7 +38,14 @@ function modelConfig(model, custom, forResponses = false) {
|
|
|
29
38
|
//
|
|
30
39
|
// Get mapping based on provider (OpenAI vs xAI)
|
|
31
40
|
// LLM() applique automatiquement reasoning_effort si thinking=true
|
|
32
|
-
const mapping = (0,
|
|
41
|
+
const mapping = (0, pricing_1.LLM)(provider, thinking);
|
|
42
|
+
//
|
|
43
|
+
// Vérifier que le modèle existe pour ce provider
|
|
44
|
+
if (!mapping[model]) {
|
|
45
|
+
const availableModels = Object.keys(mapping).join(', ');
|
|
46
|
+
throw new Error(`Model "${model}" not available for provider "${provider}". ` +
|
|
47
|
+
`Available models: ${availableModels}`);
|
|
48
|
+
}
|
|
33
49
|
const options = Object.assign({}, mapping[model], defaultOptions);
|
|
34
50
|
//
|
|
35
51
|
// Pour Responses API : mapper vers la nouvelle structure et filtrer les paramètres incompatibles
|
|
@@ -36,8 +36,9 @@ exports.executeAgent = executeAgent;
|
|
|
36
36
|
exports.executeQuery = executeQuery;
|
|
37
37
|
const types_1 = require("../types");
|
|
38
38
|
const utils_1 = require("../utils");
|
|
39
|
+
const llm_1 = require("../llm");
|
|
39
40
|
const stategraph_1 = require("../stategraph");
|
|
40
|
-
const
|
|
41
|
+
const pricing_1 = require("../llm/pricing");
|
|
41
42
|
//
|
|
42
43
|
// Import des utilitaires partagés et helpers optimisés
|
|
43
44
|
const shared_1 = require("./shared");
|
|
@@ -95,7 +96,7 @@ async function createResponseStream(openai, options, stdout) {
|
|
|
95
96
|
* - response.completed → finalisation
|
|
96
97
|
*/
|
|
97
98
|
async function readCompletionsStream(params) {
|
|
98
|
-
const openai = (0,
|
|
99
|
+
const openai = (0, llm_1.llmInstance)();
|
|
99
100
|
const { stateGraph, discussion, agentConfig, agents, discussionRootAgent, stdout, final, context, verbose } = params;
|
|
100
101
|
const model = (0, modelconfig_1.modelConfig)(agentConfig.model, {}, true).model; // forResponses=true
|
|
101
102
|
const accumulatedFunctionCall = final.choices[0]?.message.tool_calls || [];
|
|
@@ -313,7 +314,7 @@ async function readCompletionsStream(params) {
|
|
|
313
314
|
*/
|
|
314
315
|
async function executeAgentSet(agentSet, context, params) {
|
|
315
316
|
const { query, verbose } = params;
|
|
316
|
-
const openai = (0,
|
|
317
|
+
const openai = (0, llm_1.llmInstance)();
|
|
317
318
|
const agents = (0, utils_1.injectTransferTools)(agentSet);
|
|
318
319
|
const discussionRootAgent = params.home || agents[0].name;
|
|
319
320
|
const stateGraph = (0, stategraph_1.sessionStateGraphGet)(context);
|
|
@@ -434,7 +435,7 @@ async function executeAgentSet(agentSet, context, params) {
|
|
|
434
435
|
*/
|
|
435
436
|
async function executeAgent(agentSet, params) {
|
|
436
437
|
const { query, verbose, debug } = params;
|
|
437
|
-
const openai = (0,
|
|
438
|
+
const openai = (0, llm_1.llmInstance)();
|
|
438
439
|
const agent = agentSet.find(a => a.name === params.home);
|
|
439
440
|
if (!agent) {
|
|
440
441
|
throw new Error(`Agent ${params.home} not found`);
|
|
@@ -477,7 +478,7 @@ async function executeAgent(agentSet, params) {
|
|
|
477
478
|
// normalizeOutputFromResponses retourne directement le format Chat Completions
|
|
478
479
|
const final = await createResponseStream(openai, options, params.stdout);
|
|
479
480
|
const model = (0, modelconfig_1.modelConfig)(agent.model, {}, true).model;
|
|
480
|
-
(0,
|
|
481
|
+
(0, pricing_1.accumulateCost)(usage, model, final.usage);
|
|
481
482
|
state = final.id;
|
|
482
483
|
const content = final.choices[0]?.message.content || '';
|
|
483
484
|
const toolCalls = final.choices[0]?.message.tool_calls || [];
|
|
@@ -531,7 +532,7 @@ async function executeQuery(params) {
|
|
|
531
532
|
if (!modelName) {
|
|
532
533
|
throw new Error('executeQuery requires "model" parameter');
|
|
533
534
|
}
|
|
534
|
-
const openai = (0,
|
|
535
|
+
const openai = (0, llm_1.llmInstance)();
|
|
535
536
|
const model = (0, modelconfig_1.modelConfig)(modelName, {}, true); // forResponses=true
|
|
536
537
|
// Responses API: response_format → text.format
|
|
537
538
|
// Fusionner avec text.verbosity qui peut venir de modelConfig
|
|
@@ -571,7 +572,7 @@ async function executeQuery(params) {
|
|
|
571
572
|
// Responses API: utiliser responses.stream() avec .on() handlers et .finalResponse()
|
|
572
573
|
// normalizeOutputFromResponses retourne directement le format Chat Completions
|
|
573
574
|
const final = await createResponseStream(openai, options, params.stdout);
|
|
574
|
-
(0,
|
|
575
|
+
(0, pricing_1.accumulateCost)(usage, model.model, final.usage);
|
|
575
576
|
state = final.id || '';
|
|
576
577
|
const content = final.choices[0]?.message.content || '';
|
|
577
578
|
if (verbose) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export * from './utils';
|
|
|
6
6
|
export * from './types';
|
|
7
7
|
export * from './stategraph';
|
|
8
8
|
export * from './execute';
|
|
9
|
-
export
|
|
9
|
+
export { llmInstance, resetInstances, openaiInstance, PROVIDER_MAP, detectProvider, getDefaultProvider } from './llm';
|
|
10
|
+
export type { LLMProvider, LLMConfig, ProviderConfig } from './llm';
|
|
11
|
+
export { modelPricing, calculateCost, accumulateCost, LLM, LLMxai, LLMopenai } from './llm/pricing';
|
|
12
|
+
export { modelConfig } from './execute/modelconfig';
|
|
10
13
|
export * from './scrapper';
|
|
11
14
|
export * from './agents/reducer';
|
|
12
15
|
export * from './agents/semantic';
|
|
@@ -18,3 +21,4 @@ export * from './agents/simulator';
|
|
|
18
21
|
export * from './agents/simulator.types';
|
|
19
22
|
export * from './agents/simulator.prompts';
|
|
20
23
|
export * from './agents/simulator.utils';
|
|
24
|
+
export * from './agents/simulator.dashboard';
|
package/dist/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.modelConfig = exports.LLMopenai = exports.LLMxai = exports.LLM = exports.accumulateCost = exports.calculateCost = exports.modelPricing = exports.getDefaultProvider = exports.detectProvider = exports.PROVIDER_MAP = exports.openaiInstance = exports.resetInstances = exports.llmInstance = void 0;
|
|
21
22
|
// Export des utilitaires
|
|
22
23
|
__exportStar(require("./utils"), exports);
|
|
23
24
|
// Types
|
|
@@ -26,7 +27,24 @@ __exportStar(require("./types"), exports);
|
|
|
26
27
|
__exportStar(require("./stategraph"), exports);
|
|
27
28
|
// Execute (avec feature toggle legacy/responses)
|
|
28
29
|
__exportStar(require("./execute"), exports);
|
|
29
|
-
|
|
30
|
+
// LLM - providers et pricing
|
|
31
|
+
var llm_1 = require("./llm");
|
|
32
|
+
Object.defineProperty(exports, "llmInstance", { enumerable: true, get: function () { return llm_1.llmInstance; } });
|
|
33
|
+
Object.defineProperty(exports, "resetInstances", { enumerable: true, get: function () { return llm_1.resetInstances; } });
|
|
34
|
+
Object.defineProperty(exports, "openaiInstance", { enumerable: true, get: function () { return llm_1.openaiInstance; } });
|
|
35
|
+
Object.defineProperty(exports, "PROVIDER_MAP", { enumerable: true, get: function () { return llm_1.PROVIDER_MAP; } });
|
|
36
|
+
Object.defineProperty(exports, "detectProvider", { enumerable: true, get: function () { return llm_1.detectProvider; } });
|
|
37
|
+
Object.defineProperty(exports, "getDefaultProvider", { enumerable: true, get: function () { return llm_1.getDefaultProvider; } });
|
|
38
|
+
var pricing_1 = require("./llm/pricing");
|
|
39
|
+
Object.defineProperty(exports, "modelPricing", { enumerable: true, get: function () { return pricing_1.modelPricing; } });
|
|
40
|
+
Object.defineProperty(exports, "calculateCost", { enumerable: true, get: function () { return pricing_1.calculateCost; } });
|
|
41
|
+
Object.defineProperty(exports, "accumulateCost", { enumerable: true, get: function () { return pricing_1.accumulateCost; } });
|
|
42
|
+
Object.defineProperty(exports, "LLM", { enumerable: true, get: function () { return pricing_1.LLM; } });
|
|
43
|
+
Object.defineProperty(exports, "LLMxai", { enumerable: true, get: function () { return pricing_1.LLMxai; } });
|
|
44
|
+
Object.defineProperty(exports, "LLMopenai", { enumerable: true, get: function () { return pricing_1.LLMopenai; } });
|
|
45
|
+
// Model config (central pour tous les mappings: responses, embeddings, vision, whisper)
|
|
46
|
+
var modelconfig_1 = require("./execute/modelconfig");
|
|
47
|
+
Object.defineProperty(exports, "modelConfig", { enumerable: true, get: function () { return modelconfig_1.modelConfig; } });
|
|
30
48
|
// Scrapper
|
|
31
49
|
__exportStar(require("./scrapper"), exports);
|
|
32
50
|
// Agents
|
|
@@ -44,3 +62,4 @@ __exportStar(require("./agents/simulator"), exports);
|
|
|
44
62
|
__exportStar(require("./agents/simulator.types"), exports);
|
|
45
63
|
__exportStar(require("./agents/simulator.prompts"), exports);
|
|
46
64
|
__exportStar(require("./agents/simulator.utils"), exports);
|
|
65
|
+
__exportStar(require("./agents/simulator.dashboard"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration des providers LLM
|
|
3
|
+
*
|
|
4
|
+
* Définit les baseURL, clés API et configurations par provider.
|
|
5
|
+
*/
|
|
6
|
+
export type LLMProvider = 'openai' | 'xai';
|
|
7
|
+
export interface LLMConfig {
|
|
8
|
+
provider?: LLMProvider;
|
|
9
|
+
key?: string;
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderConfig {
|
|
13
|
+
baseURL: string;
|
|
14
|
+
keyEnv: string;
|
|
15
|
+
fallbackKeyEnv?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const PROVIDER_MAP: Record<LLMProvider, ProviderConfig>;
|
|
18
|
+
/**
|
|
19
|
+
* Détecte le provider à partir d'une baseURL
|
|
20
|
+
*/
|
|
21
|
+
export declare function detectProvider(baseURL?: string): LLMProvider;
|
|
22
|
+
/**
|
|
23
|
+
* Retourne le provider par défaut depuis les variables d'environnement
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDefaultProvider(): LLMProvider;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration des providers LLM
|
|
4
|
+
*
|
|
5
|
+
* Définit les baseURL, clés API et configurations par provider.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.PROVIDER_MAP = void 0;
|
|
9
|
+
exports.detectProvider = detectProvider;
|
|
10
|
+
exports.getDefaultProvider = getDefaultProvider;
|
|
11
|
+
exports.PROVIDER_MAP = {
|
|
12
|
+
openai: {
|
|
13
|
+
baseURL: 'https://api.openai.com/v1',
|
|
14
|
+
keyEnv: 'OPENAI_API_KEY',
|
|
15
|
+
fallbackKeyEnv: 'LLM_API_KEY'
|
|
16
|
+
},
|
|
17
|
+
xai: {
|
|
18
|
+
baseURL: 'https://api.x.ai/v1',
|
|
19
|
+
keyEnv: 'XAI_API_KEY',
|
|
20
|
+
fallbackKeyEnv: 'LLM_API_KEY'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Détecte le provider à partir d'une baseURL
|
|
25
|
+
*/
|
|
26
|
+
function detectProvider(baseURL) {
|
|
27
|
+
if (!baseURL)
|
|
28
|
+
return process.env.LLM_PROVIDER || 'openai';
|
|
29
|
+
if (baseURL.includes('x.ai'))
|
|
30
|
+
return 'xai';
|
|
31
|
+
return 'openai';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Retourne le provider par défaut depuis les variables d'environnement
|
|
35
|
+
*/
|
|
36
|
+
function getDefaultProvider() {
|
|
37
|
+
return process.env.LLM_PROVIDER || 'openai';
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider Instances
|
|
3
|
+
*
|
|
4
|
+
* Fournit une instance OpenAI configurable par provider:
|
|
5
|
+
* - llmInstance(): utilise LLM_PROVIDER depuis .env
|
|
6
|
+
* - llmInstance({provider: 'openai'}): force OpenAI
|
|
7
|
+
* - llmInstance({provider: 'xai'}): force xAI
|
|
8
|
+
*
|
|
9
|
+
* Configuration via .env:
|
|
10
|
+
* - LLM_PROVIDER: openai | xai (défaut: openai)
|
|
11
|
+
* - OPENAI_API_KEY: clé API OpenAI
|
|
12
|
+
* - XAI_API_KEY: clé API xAI
|
|
13
|
+
* - LLM_API_KEY: fallback pour les deux providers
|
|
14
|
+
*/
|
|
15
|
+
import OpenAI from 'openai';
|
|
16
|
+
import { LLMConfig } from './config';
|
|
17
|
+
declare global {
|
|
18
|
+
var _llmInstances_: Map<string, OpenAI> | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Instance LLM configurable par provider
|
|
22
|
+
*
|
|
23
|
+
* @param config - Configuration optionnelle
|
|
24
|
+
* @param config.provider - Provider à utiliser ('openai' | 'xai')
|
|
25
|
+
* @param config.key - Clé API (optionnel, utilise env par défaut)
|
|
26
|
+
* @param config.baseUrl - Base URL (optionnel, utilise config provider par défaut)
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Utilise le provider par défaut (.env LLM_PROVIDER)
|
|
30
|
+
* const openai = llmInstance();
|
|
31
|
+
*
|
|
32
|
+
* // Force OpenAI (pour embeddings, whisper)
|
|
33
|
+
* const openai = llmInstance({provider: 'openai'});
|
|
34
|
+
*
|
|
35
|
+
* // Force xAI
|
|
36
|
+
* const openai = llmInstance({provider: 'xai'});
|
|
37
|
+
*/
|
|
38
|
+
export declare function llmInstance(config?: LLMConfig): OpenAI;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Utiliser llmInstance() à la place
|
|
41
|
+
* Alias pour rétrocompatibilité
|
|
42
|
+
*/
|
|
43
|
+
export declare function openaiInstance(envKey?: string, baseUrl?: string): OpenAI;
|
|
44
|
+
/**
|
|
45
|
+
* Reset toutes les instances (utile pour les tests)
|
|
46
|
+
*/
|
|
47
|
+
export declare function resetInstances(): void;
|
|
48
|
+
export { PROVIDER_MAP, LLMProvider, LLMConfig, detectProvider, getDefaultProvider, ProviderConfig } from './config';
|