aotrautils 0.0.1848 → 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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (02/06/2026-01:07:25)»*/
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
- let currentScenariiNumber=0;
490
- window.aotestMethods.iterateOverScenarii(allTestsBagForClientReadOnly, (scenario)=>{
491
- currentScenariiNumber++;
492
- }, testsType);
493
- return currentScenariiNumber;
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 (02/06/2026-01:07:25)»*/
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
  *
@@ -5514,7 +5526,7 @@ if(typeof monitorProgression === "undefined"){
5514
5526
  // -------------------------------------------------------------------------------------------
5515
5527
 
5516
5528
 
5517
-
5529
+ // URLs management :
5518
5530
 
5519
5531
 
5520
5532
 
@@ -5571,8 +5583,10 @@ window.getLastPathConcreteSegment=function(urlPath){
5571
5583
  return (0<segments.length ? segments[segments.length - 1] : null);
5572
5584
  }
5573
5585
 
5574
-
5575
-
5586
+ window.getNonOriginSegment=function(urlParam){
5587
+ const url=(isString(urlParam) ? new URL(urlParam) : urlParam);
5588
+ return url.pathname+url.search+url.hash;
5589
+ }
5576
5590
 
5577
5591
  // -------------------------------------------------------------------------------------------
5578
5592
 
@@ -13280,7 +13294,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13280
13294
 
13281
13295
 
13282
13296
 
13283
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (02/06/2026-01:07:25)»*/
13297
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
13284
13298
  /*-----------------------------------------------------------------------------*/
13285
13299
 
13286
13300
 
@@ -14365,10 +14379,10 @@ function rayVsUnitSphereClosestPoint(p, r) {
14365
14379
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14366
14380
 
14367
14381
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14368
- /*utils 3D library associated with aotra version : «1_29072022-2359 (02/06/2026-01:07:25)»*/
14382
+ /*utils 3D library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
14369
14383
  /*-----------------------------------------------------------------------------*/
14370
14384
 
14371
- /*utils AI library associated with aotra version : «1_29072022-2359 (02/06/2026-01:07:25)»*/
14385
+ /*utils AI library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
14372
14386
  /*-----------------------------------------------------------------------------*/
14373
14387
 
14374
14388
 
@@ -14399,6 +14413,20 @@ if(typeof(window)==="undefined") window=global;
14399
14413
  //=========================================================================
14400
14414
  // GLOBAL CONSTANTS :
14401
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
+
14402
14430
  //=========================================================================
14403
14431
 
14404
14432
 
@@ -14407,22 +14435,20 @@ if(typeof(window)==="undefined") window=global;
14407
14435
  // AI management :
14408
14436
 
14409
14437
 
14438
+ // Commons :
14439
+
14410
14440
 
14411
- class OpenAIAPIClient{
14441
+ window.LLMAPIClient=class LLMAPIClient{
14412
14442
 
14413
14443
  constructor(modelName, apiURL, agentRole, defaultPrompt){
14414
14444
 
14415
- //DBG
14416
- lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
14417
-
14418
- // this.apiKey=apiKey;
14419
14445
  this.modelName=modelName;
14420
14446
  this.apiURL=apiURL;
14421
14447
  this.agentRole=agentRole;
14422
14448
  this.defaultPrompt=defaultPrompt;
14423
14449
  }
14424
14450
 
14425
- async getAnswer(AIAPIKey, additionalPrompt, defaultPromptParameters={}){
14451
+ async getAnswer(AIAPIKey, userPrompt, defaultPromptParameters={}){
14426
14452
 
14427
14453
  const PARAMETERS_DELIMITERS=["<",">"];
14428
14454
 
@@ -14432,46 +14458,39 @@ class OpenAIAPIClient{
14432
14458
  newDefaultPrompt=newDefaultPrompt.replace(regexp,value);
14433
14459
  });
14434
14460
 
14435
- const self=this;
14436
- const messages = [
14437
- { role: "system", content: this.agentRole },
14438
- { role: "user", content: (newDefaultPrompt+ "\n" + additionalPrompt) },
14439
- ];
14461
+ const messages=this.getMessages(newDefaultPrompt, userPrompt);
14440
14462
 
14441
- //DBG
14442
- lognow("------------self.apiURL:",self.apiURL);
14443
-
14444
14463
  const result=await this.launchRequest(AIAPIKey, messages);
14445
14464
 
14446
- // DBG
14447
- console.log("! RESULT text :",result);
14448
-
14449
14465
  return result;
14450
14466
  }
14451
14467
 
14452
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
+
14453
14478
  /*private*/launchRequest(AIAPIKey, messages){
14454
-
14455
- // DBG
14456
- lognow("! launchRequest messages :",messages);
14479
+
14480
+ const self=this;
14457
14481
 
14458
14482
 
14459
- const headers={
14460
- "Authorization": "Bearer "+AIAPIKey,
14461
- "Content-Type": "application/json",
14462
- };
14463
- const parameters={
14464
- model:this.modelName,
14465
- messages:messages,
14466
- };
14483
+ const headers=this.getAPIRequestHeaders(AIAPIKey);
14484
+
14485
+ const parameters=getAPIRequestParameters(messages);
14467
14486
 
14468
14487
  return new Promise((resolve,reject)=>{
14469
- performHTTPRequest(this.apiURL,"POST",headers,parameters,true).then((responseObj)=>{
14488
+ performHTTPRequest(this.apiURL, "POST", headers, parameters, true).then((responseObj)=>{
14470
14489
  const responseData=responseObj.responseData;
14471
14490
  const data=responseData;
14472
14491
 
14473
14492
  // DBG
14474
- console.log("~~~~~~~~~~~data :",data);
14493
+ console.log("DEBUG : ~~~~~~~~~~~data :",data);
14475
14494
 
14476
14495
  if(data.error){
14477
14496
  const error=data.error;
@@ -14479,42 +14498,151 @@ class OpenAIAPIClient{
14479
14498
  console.error("Error:", error);
14480
14499
  reject(new Error(`${error}`));
14481
14500
  }
14482
-
14483
- const assistantReply = data.choices[0].message.content;
14484
- // DBG
14485
- console.log("~~~~~~~~~~~assistantReply :",assistantReply);
14486
-
14501
+
14502
+ const assistantReply=self.getAssistantReply(data);
14503
+
14487
14504
  resolve(assistantReply);
14488
14505
  }).catch(errorObj=>{
14489
14506
  const error=errorObj.error;
14490
14507
  const httpStatus=errorObj.httpStatus;
14491
14508
  // TRACE
14492
- console.error("Error:", error);
14509
+ lognow("ERROR:", error);
14493
14510
  reject(error);
14494
14511
  });
14495
14512
  });
14496
14513
 
14497
14514
 
14498
-
14499
-
14500
14515
  }
14501
14516
 
14502
14517
 
14518
+ /*protected*/getAPIRequestHeaders(AIAPIKey){
14519
+ return {
14520
+ "Authorization": "Bearer "+AIAPIKey,
14521
+ "Content-Type": "application/json",
14522
+ };
14523
+ }
14503
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
+
14504
14536
 
14505
14537
  }
14506
14538
 
14507
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
+ }
14625
+
14626
+
14627
+ }
14628
+
14629
+
14630
+
14631
+
14632
+ // ****************************************************************
14633
+
14508
14634
  // Nodejs compatibility :
14509
- getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
14510
- return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
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);
14511
14639
  };
14512
14640
 
14513
14641
 
14514
14642
 
14515
14643
 
14516
14644
 
14517
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (02/06/2026-01:07:25)»*/
14645
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (14/06/2026-23:53:49)»*/
14518
14646
  /*-----------------------------------------------------------------------------*/
14519
14647
 
14520
14648
 
@@ -17075,9 +17203,10 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
17075
17203
 
17076
17204
  if(isURLInExclusionZone){
17077
17205
  // TRACE
17078
- console.log("ERROR 403 forbidden access error :");
17079
- console.log(error);
17080
-
17206
+ lognow("ERROR 403 forbidden access error :");
17207
+ lognow("ERROR : request:",request);
17208
+ lognow("ERROR : response:",response);
17209
+
17081
17210
  response.writeHead(403);
17082
17211
  response.end("Sorry, cannot access resource : error: "+error.code+" ..\n");
17083
17212
  response.end();
@@ -17112,9 +17241,9 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
17112
17241
 
17113
17242
  }else {
17114
17243
 
17115
- // TRACE
17116
- console.log("ERROR 500 server error :");
17117
- console.log(error);
17244
+ // TRACE
17245
+ lognow("ERROR 500 server error :");
17246
+ lognow("ERROR : error:",error);
17118
17247
 
17119
17248
  response.writeHead(500);
17120
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.1848",
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)",