aotrautils 0.0.1850 → 0.0.1852
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.
- aotrautils/aotrautils.build.js +188 -58
- aotrautils/package.json +1 -1
aotrautils/aotrautils.build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (
|
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -485,12 +485,19 @@ window.aotestMethods.getScenariiByName=function(allTests, scenariiNames){
|
|
|
485
485
|
}, null, null, scenario=>contains(scenariiNames,scenario.name));
|
|
486
486
|
return results;
|
|
487
487
|
}
|
|
488
|
+
window.aotestMethods.getNumberOfScenariiInApp=function(allTestsBagForClientIdForAppReadOnly, testsType){
|
|
489
|
+
let currentScenariiNumberInApp=0;
|
|
490
|
+
window.aotestMethods.iterateOverScenarii(allTestsBagForClientIdForAppReadOnly, (scenario)=>{
|
|
491
|
+
currentScenariiNumberInApp++;
|
|
492
|
+
}, testsType);
|
|
493
|
+
return currentScenariiNumberInApp;
|
|
494
|
+
}
|
|
488
495
|
window.aotestMethods.getNumberOfScenariiInGlobal=function(allTestsBagForClientReadOnly, testsType){
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
496
|
+
let currentScenariiNumber=0;
|
|
497
|
+
foreach(allTestsBagForClientReadOnly, (allTestsBag, appName)=>{
|
|
498
|
+
currentScenariiNumber+=aotestMethods.getNumberOfScenariiInApp(allTestsBag, testsType);
|
|
499
|
+
});
|
|
500
|
+
return currentScenariiNumber;
|
|
494
501
|
}
|
|
495
502
|
window.aotestMethods.iterateOverScenarii=function(allTests, doOnIteration, testsType=null, filterFunction=null, mustTerminateFunction=null){
|
|
496
503
|
if(!testsType || testsType==="*"){
|
|
@@ -5122,6 +5129,11 @@ window.stringifyObject=function(objectToStringify, prettifierOption=null/*(can b
|
|
|
5122
5129
|
return null;
|
|
5123
5130
|
}
|
|
5124
5131
|
|
|
5132
|
+
window.stringifyIfNeeded=function(objOrString){
|
|
5133
|
+
if(objOrString==null) return "";
|
|
5134
|
+
return (isString(objOrString) ? objOrString : stringifyObject(objOrString));
|
|
5135
|
+
}
|
|
5136
|
+
|
|
5125
5137
|
|
|
5126
5138
|
window.splitURL=(urlOrigin)=>{
|
|
5127
5139
|
let protocol=null;
|
|
@@ -5458,7 +5470,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
|
|
|
5458
5470
|
|
|
5459
5471
|
|
|
5460
5472
|
|
|
5461
|
-
/*utils CLIENT library associated with aotra version : «1_29072022-2359 (
|
|
5473
|
+
/*utils CLIENT library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
5462
5474
|
/*-----------------------------------------------------------------------------*/
|
|
5463
5475
|
/* ## Utility global methods in a browser (htmljs) client environment.
|
|
5464
5476
|
*
|
|
@@ -5571,7 +5583,10 @@ window.getLastPathConcreteSegment=function(urlPath){
|
|
|
5571
5583
|
return (0<segments.length ? segments[segments.length - 1] : null);
|
|
5572
5584
|
}
|
|
5573
5585
|
|
|
5574
|
-
|
|
5586
|
+
window.getNonOriginSegment=function(urlParam){
|
|
5587
|
+
const url=(isString(urlParam) ? new URL(urlParam) : urlParam);
|
|
5588
|
+
return url.pathname+url.search+url.hash;
|
|
5589
|
+
}
|
|
5575
5590
|
|
|
5576
5591
|
// -------------------------------------------------------------------------------------------
|
|
5577
5592
|
|
|
@@ -13279,7 +13294,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
|
|
|
13279
13294
|
|
|
13280
13295
|
|
|
13281
13296
|
|
|
13282
|
-
/*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (
|
|
13297
|
+
/*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
13283
13298
|
/*-----------------------------------------------------------------------------*/
|
|
13284
13299
|
|
|
13285
13300
|
|
|
@@ -14364,10 +14379,10 @@ function rayVsUnitSphereClosestPoint(p, r) {
|
|
|
14364
14379
|
// MUST REMAIN AT THE END OF THIS LIBRARY FILE !
|
|
14365
14380
|
|
|
14366
14381
|
AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
|
|
14367
|
-
/*utils 3D library associated with aotra version : «1_29072022-2359 (
|
|
14382
|
+
/*utils 3D library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
14368
14383
|
/*-----------------------------------------------------------------------------*/
|
|
14369
14384
|
|
|
14370
|
-
/*utils AI library associated with aotra version : «1_29072022-2359 (
|
|
14385
|
+
/*utils AI library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
14371
14386
|
/*-----------------------------------------------------------------------------*/
|
|
14372
14387
|
|
|
14373
14388
|
|
|
@@ -14398,6 +14413,20 @@ if(typeof(window)==="undefined") window=global;
|
|
|
14398
14413
|
//=========================================================================
|
|
14399
14414
|
// GLOBAL CONSTANTS :
|
|
14400
14415
|
|
|
14416
|
+
window.DEFAULT_LLM_PROVIDER_NAME="claude";
|
|
14417
|
+
|
|
14418
|
+
window.LLM_PROVIDERS_PARAMETERS={
|
|
14419
|
+
"openai":{
|
|
14420
|
+
modelName:"gpt-3.5-turbo",
|
|
14421
|
+
apiURL:"https://api.openai.com/v1/chat/completions"
|
|
14422
|
+
},
|
|
14423
|
+
"claude":{
|
|
14424
|
+
modelName:"claude-sonnet-4-8",
|
|
14425
|
+
apiURL:"https://api.anthropic.com/v1/messages"
|
|
14426
|
+
},
|
|
14427
|
+
};
|
|
14428
|
+
|
|
14429
|
+
|
|
14401
14430
|
//=========================================================================
|
|
14402
14431
|
|
|
14403
14432
|
|
|
@@ -14406,22 +14435,20 @@ if(typeof(window)==="undefined") window=global;
|
|
|
14406
14435
|
// AI management :
|
|
14407
14436
|
|
|
14408
14437
|
|
|
14438
|
+
// Commons :
|
|
14439
|
+
|
|
14409
14440
|
|
|
14410
|
-
class
|
|
14441
|
+
window.LLMAPIClient=class LLMAPIClient{
|
|
14411
14442
|
|
|
14412
14443
|
constructor(modelName, apiURL, agentRole, defaultPrompt){
|
|
14413
14444
|
|
|
14414
|
-
//DBG
|
|
14415
|
-
lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
|
|
14416
|
-
|
|
14417
|
-
// this.apiKey=apiKey;
|
|
14418
14445
|
this.modelName=modelName;
|
|
14419
14446
|
this.apiURL=apiURL;
|
|
14420
14447
|
this.agentRole=agentRole;
|
|
14421
14448
|
this.defaultPrompt=defaultPrompt;
|
|
14422
14449
|
}
|
|
14423
14450
|
|
|
14424
|
-
async getAnswer(AIAPIKey,
|
|
14451
|
+
async getAnswer(AIAPIKey, userPrompt, defaultPromptParameters={}){
|
|
14425
14452
|
|
|
14426
14453
|
const PARAMETERS_DELIMITERS=["<",">"];
|
|
14427
14454
|
|
|
@@ -14431,46 +14458,39 @@ class OpenAIAPIClient{
|
|
|
14431
14458
|
newDefaultPrompt=newDefaultPrompt.replace(regexp,value);
|
|
14432
14459
|
});
|
|
14433
14460
|
|
|
14434
|
-
|
|
14435
|
-
const messages = [
|
|
14436
|
-
{ role: "system", content: this.agentRole },
|
|
14437
|
-
{ role: "user", content: (newDefaultPrompt+ "\n" + additionalPrompt) },
|
|
14438
|
-
];
|
|
14461
|
+
const messages=this.getMessages(newDefaultPrompt, userPrompt);
|
|
14439
14462
|
|
|
14440
|
-
//DBG
|
|
14441
|
-
lognow("------------self.apiURL:",self.apiURL);
|
|
14442
|
-
|
|
14443
14463
|
const result=await this.launchRequest(AIAPIKey, messages);
|
|
14444
14464
|
|
|
14445
|
-
// DBG
|
|
14446
|
-
console.log("! RESULT text :",result);
|
|
14447
|
-
|
|
14448
14465
|
return result;
|
|
14449
14466
|
}
|
|
14450
14467
|
|
|
14451
14468
|
|
|
14469
|
+
/*protected*/getMessages(defaultPrompt, userPrompt){
|
|
14470
|
+
return [
|
|
14471
|
+
{ role: "system", content: this.agentRole },
|
|
14472
|
+
{ role: "user", content: (defaultPrompt+"\n"
|
|
14473
|
+
+userPrompt) },
|
|
14474
|
+
];
|
|
14475
|
+
}
|
|
14476
|
+
|
|
14477
|
+
|
|
14452
14478
|
/*private*/launchRequest(AIAPIKey, messages){
|
|
14453
|
-
|
|
14454
|
-
// DBG
|
|
14455
|
-
lognow("! launchRequest messages :",messages);
|
|
14456
14479
|
|
|
14480
|
+
const self=this;
|
|
14457
14481
|
|
|
14458
|
-
|
|
14459
|
-
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
const parameters={
|
|
14463
|
-
model:this.modelName,
|
|
14464
|
-
messages:messages,
|
|
14465
|
-
};
|
|
14482
|
+
|
|
14483
|
+
const headers=this.getAPIRequestHeaders(AIAPIKey);
|
|
14484
|
+
|
|
14485
|
+
const parameters=getAPIRequestParameters(messages);
|
|
14466
14486
|
|
|
14467
14487
|
return new Promise((resolve,reject)=>{
|
|
14468
|
-
performHTTPRequest(this.apiURL,"POST",headers,parameters,true).then((responseObj)=>{
|
|
14488
|
+
performHTTPRequest(this.apiURL, "POST", headers, parameters, true).then((responseObj)=>{
|
|
14469
14489
|
const responseData=responseObj.responseData;
|
|
14470
14490
|
const data=responseData;
|
|
14471
14491
|
|
|
14472
14492
|
// DBG
|
|
14473
|
-
console.log("~~~~~~~~~~~data :",data);
|
|
14493
|
+
console.log("DEBUG : ~~~~~~~~~~~data :",data);
|
|
14474
14494
|
|
|
14475
14495
|
if(data.error){
|
|
14476
14496
|
const error=data.error;
|
|
@@ -14478,42 +14498,151 @@ class OpenAIAPIClient{
|
|
|
14478
14498
|
console.error("Error:", error);
|
|
14479
14499
|
reject(new Error(`${error}`));
|
|
14480
14500
|
}
|
|
14481
|
-
|
|
14482
|
-
const assistantReply
|
|
14483
|
-
|
|
14484
|
-
console.log("~~~~~~~~~~~assistantReply :",assistantReply);
|
|
14485
|
-
|
|
14501
|
+
|
|
14502
|
+
const assistantReply=self.getAssistantReply(data);
|
|
14503
|
+
|
|
14486
14504
|
resolve(assistantReply);
|
|
14487
14505
|
}).catch(errorObj=>{
|
|
14488
14506
|
const error=errorObj.error;
|
|
14489
14507
|
const httpStatus=errorObj.httpStatus;
|
|
14490
14508
|
// TRACE
|
|
14491
|
-
|
|
14509
|
+
lognow("ERROR:", error);
|
|
14492
14510
|
reject(error);
|
|
14493
14511
|
});
|
|
14494
14512
|
});
|
|
14495
14513
|
|
|
14496
14514
|
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
14515
|
}
|
|
14500
14516
|
|
|
14501
14517
|
|
|
14518
|
+
/*protected*/getAPIRequestHeaders(AIAPIKey){
|
|
14519
|
+
return {
|
|
14520
|
+
"Authorization": "Bearer "+AIAPIKey,
|
|
14521
|
+
"Content-Type": "application/json",
|
|
14522
|
+
};
|
|
14523
|
+
}
|
|
14524
|
+
|
|
14525
|
+
/*protected*/getAPIRequestParameters(messages){
|
|
14526
|
+
return{
|
|
14527
|
+
model:this.modelName,
|
|
14528
|
+
messages:messages,
|
|
14529
|
+
};
|
|
14530
|
+
}
|
|
14531
|
+
|
|
14532
|
+
/*protected*/getAssistantReply(data){
|
|
14533
|
+
return data.choices[0].message.content;
|
|
14534
|
+
}
|
|
14535
|
+
|
|
14536
|
+
|
|
14537
|
+
}
|
|
14538
|
+
|
|
14539
|
+
|
|
14540
|
+
|
|
14541
|
+
|
|
14542
|
+
// Claude :
|
|
14543
|
+
|
|
14544
|
+
|
|
14545
|
+
|
|
14546
|
+
window.ClaudeAPIClient=class ClaudeAPIClient extends LLMAPIClient{
|
|
14547
|
+
|
|
14548
|
+
constructor(modelName, apiURL, agentRole, defaultPrompt){
|
|
14549
|
+
super(modelName, apiURL, agentRole, defaultPrompt);
|
|
14550
|
+
|
|
14551
|
+
}
|
|
14552
|
+
|
|
14553
|
+
|
|
14554
|
+
/*protected*/getAPIRequestHeaders(AIAPIKey){
|
|
14555
|
+
return {
|
|
14556
|
+
"x-api-key": AIAPIKey,
|
|
14557
|
+
"anthropic-version": "2023-06-01",
|
|
14558
|
+
"Content-Type": "application/json"
|
|
14559
|
+
};
|
|
14560
|
+
}
|
|
14561
|
+
|
|
14562
|
+
/*protected*/getAPIRequestParameters(messages){
|
|
14563
|
+
return{
|
|
14564
|
+
model:this.modelName,
|
|
14565
|
+
messages:messages,
|
|
14566
|
+
"max_tokens": 2048,
|
|
14567
|
+
system:this.agentRole,
|
|
14568
|
+
};
|
|
14569
|
+
}
|
|
14570
|
+
|
|
14571
|
+
/*protected*/getMessages(defaultPrompt, userPrompt){
|
|
14572
|
+
return [
|
|
14573
|
+
{ role: "user", content: (defaultPrompt+"\n"
|
|
14574
|
+
+userPrompt) },
|
|
14575
|
+
];
|
|
14576
|
+
}
|
|
14577
|
+
|
|
14578
|
+
/*protected*/getAssistantReply(data){
|
|
14579
|
+
const message=data.content.find(message=>message.type==="text");
|
|
14580
|
+
const reply=message?.text ?? "";
|
|
14581
|
+
return reply;
|
|
14582
|
+
}
|
|
14583
|
+
|
|
14584
|
+
}
|
|
14585
|
+
|
|
14586
|
+
|
|
14587
|
+
|
|
14588
|
+
// "Open"AI API :
|
|
14589
|
+
|
|
14590
|
+
|
|
14591
|
+
window.OpenAIAPIClient=class OpenAIAPIClient extends LLMAPIClient{
|
|
14592
|
+
|
|
14593
|
+
constructor(modelName, apiURL, agentRole, defaultPrompt){
|
|
14594
|
+
super(modelName, apiURL, agentRole, defaultPrompt);
|
|
14595
|
+
|
|
14596
|
+
}
|
|
14597
|
+
|
|
14598
|
+
/*protected*/getAPIRequestHeaders(AIAPIKey){
|
|
14599
|
+
return {
|
|
14600
|
+
"Authorization": "Bearer "+AIAPIKey,
|
|
14601
|
+
"Content-Type": "application/json",
|
|
14602
|
+
};
|
|
14603
|
+
}
|
|
14604
|
+
|
|
14605
|
+
/*protected*/getAPIRequestParameters(messages){
|
|
14606
|
+
return {
|
|
14607
|
+
model:this.modelName,
|
|
14608
|
+
messages:messages,
|
|
14609
|
+
};
|
|
14610
|
+
}
|
|
14611
|
+
|
|
14612
|
+
/*protected*/getMessages(defaultPrompt, userPrompt){
|
|
14613
|
+
return [
|
|
14614
|
+
{ role: "system", content: this.agentRole },
|
|
14615
|
+
{ role: "user", content: (defaultPrompt+"\n"
|
|
14616
|
+
+userPrompt) },
|
|
14617
|
+
];
|
|
14618
|
+
}
|
|
14619
|
+
|
|
14620
|
+
/*protected*/getAssistantReply(data){
|
|
14621
|
+
const messageInfo=data.choices.find(choice=>choice.message?.role==="assistant");
|
|
14622
|
+
const reply=messageInfo?.message?.content ?? "";
|
|
14623
|
+
return reply;
|
|
14624
|
+
}
|
|
14502
14625
|
|
|
14503
14626
|
|
|
14504
14627
|
}
|
|
14505
14628
|
|
|
14506
14629
|
|
|
14630
|
+
|
|
14631
|
+
|
|
14632
|
+
// ****************************************************************
|
|
14633
|
+
|
|
14507
14634
|
// Nodejs compatibility :
|
|
14508
|
-
|
|
14509
|
-
|
|
14635
|
+
getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProviderName=DEFAULT_LLM_PROVIDER_NAME)=>{
|
|
14636
|
+
if(llmProviderName=="openai")
|
|
14637
|
+
return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
|
|
14638
|
+
return new ClaudeAPIClient(modelName, apiURL, agentRole, defaultPrompt);
|
|
14510
14639
|
};
|
|
14511
14640
|
|
|
14512
14641
|
|
|
14513
14642
|
|
|
14514
14643
|
|
|
14515
14644
|
|
|
14516
|
-
/*utils CONSOLE library associated with aotra version : «1_29072022-2359 (
|
|
14645
|
+
/*utils CONSOLE library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
|
|
14517
14646
|
/*-----------------------------------------------------------------------------*/
|
|
14518
14647
|
|
|
14519
14648
|
|
|
@@ -17074,9 +17203,10 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
|
|
|
17074
17203
|
|
|
17075
17204
|
if(isURLInExclusionZone){
|
|
17076
17205
|
// TRACE
|
|
17077
|
-
|
|
17078
|
-
|
|
17079
|
-
|
|
17206
|
+
lognow("ERROR 403 forbidden access error :");
|
|
17207
|
+
lognow("ERROR : request:",request);
|
|
17208
|
+
lognow("ERROR : response:",response);
|
|
17209
|
+
|
|
17080
17210
|
response.writeHead(403);
|
|
17081
17211
|
response.end("Sorry, cannot access resource : error: "+error.code+" ..\n");
|
|
17082
17212
|
response.end();
|
|
@@ -17111,9 +17241,9 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
|
|
|
17111
17241
|
|
|
17112
17242
|
}else {
|
|
17113
17243
|
|
|
17114
|
-
|
|
17115
|
-
|
|
17116
|
-
|
|
17244
|
+
// TRACE
|
|
17245
|
+
lognow("ERROR 500 server error :");
|
|
17246
|
+
lognow("ERROR : error:",error);
|
|
17117
17247
|
|
|
17118
17248
|
response.writeHead(500);
|
|
17119
17249
|
response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
|
aotrautils/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1852",
|
|
4
4
|
"main": "aotrautils.build.js",
|
|
5
5
|
"description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
|
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|