aotrautils-srv 0.0.1849 → 0.0.1851

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 (09/06/2026-14:12:54)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (14/06/2026-23:54:16)»*/
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 AI library associated with aotra version : «1_29072022-2359 (09/06/2026-14:12:54)»*/
5473
+ /*utils AI library associated with aotra version : «1_29072022-2359 (14/06/2026-23:54:16)»*/
5462
5474
  /*-----------------------------------------------------------------------------*/
5463
5475
 
5464
5476
 
@@ -5489,6 +5501,20 @@ if(typeof(window)==="undefined") window=global;
5489
5501
  //=========================================================================
5490
5502
  // GLOBAL CONSTANTS :
5491
5503
 
5504
+ window.DEFAULT_LLM_PROVIDER_NAME="claude";
5505
+
5506
+ window.LLM_PROVIDERS_PARAMETERS={
5507
+ "openai":{
5508
+ modelName:"gpt-3.5-turbo",
5509
+ apiURL:"https://api.openai.com/v1/chat/completions"
5510
+ },
5511
+ "claude":{
5512
+ modelName:"claude-sonnet-4-8",
5513
+ apiURL:"https://api.anthropic.com/v1/messages"
5514
+ },
5515
+ };
5516
+
5517
+
5492
5518
  //=========================================================================
5493
5519
 
5494
5520
 
@@ -5497,22 +5523,20 @@ if(typeof(window)==="undefined") window=global;
5497
5523
  // AI management :
5498
5524
 
5499
5525
 
5526
+ // Commons :
5500
5527
 
5501
- class OpenAIAPIClient{
5528
+
5529
+ window.LLMAPIClient=class LLMAPIClient{
5502
5530
 
5503
5531
  constructor(modelName, apiURL, agentRole, defaultPrompt){
5504
5532
 
5505
- //DBG
5506
- lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
5507
-
5508
- // this.apiKey=apiKey;
5509
5533
  this.modelName=modelName;
5510
5534
  this.apiURL=apiURL;
5511
5535
  this.agentRole=agentRole;
5512
5536
  this.defaultPrompt=defaultPrompt;
5513
5537
  }
5514
5538
 
5515
- async getAnswer(AIAPIKey, additionalPrompt, defaultPromptParameters={}){
5539
+ async getAnswer(AIAPIKey, userPrompt, defaultPromptParameters={}){
5516
5540
 
5517
5541
  const PARAMETERS_DELIMITERS=["<",">"];
5518
5542
 
@@ -5522,46 +5546,39 @@ class OpenAIAPIClient{
5522
5546
  newDefaultPrompt=newDefaultPrompt.replace(regexp,value);
5523
5547
  });
5524
5548
 
5525
- const self=this;
5526
- const messages = [
5527
- { role: "system", content: this.agentRole },
5528
- { role: "user", content: (newDefaultPrompt+ "\n" + additionalPrompt) },
5529
- ];
5549
+ const messages=this.getMessages(newDefaultPrompt, userPrompt);
5530
5550
 
5531
- //DBG
5532
- lognow("------------self.apiURL:",self.apiURL);
5533
-
5534
5551
  const result=await this.launchRequest(AIAPIKey, messages);
5535
5552
 
5536
- // DBG
5537
- console.log("! RESULT text :",result);
5538
-
5539
5553
  return result;
5540
5554
  }
5541
5555
 
5542
5556
 
5557
+ /*protected*/getMessages(defaultPrompt, userPrompt){
5558
+ return [
5559
+ { role: "system", content: this.agentRole },
5560
+ { role: "user", content: (defaultPrompt+"\n"
5561
+ +userPrompt) },
5562
+ ];
5563
+ }
5564
+
5565
+
5543
5566
  /*private*/launchRequest(AIAPIKey, messages){
5544
-
5545
- // DBG
5546
- lognow("! launchRequest messages :",messages);
5547
5567
 
5568
+ const self=this;
5548
5569
 
5549
- const headers={
5550
- "Authorization": "Bearer "+AIAPIKey,
5551
- "Content-Type": "application/json",
5552
- };
5553
- const parameters={
5554
- model:this.modelName,
5555
- messages:messages,
5556
- };
5570
+
5571
+ const headers=this.getAPIRequestHeaders(AIAPIKey);
5572
+
5573
+ const parameters=getAPIRequestParameters(messages);
5557
5574
 
5558
5575
  return new Promise((resolve,reject)=>{
5559
- performHTTPRequest(this.apiURL,"POST",headers,parameters,true).then((responseObj)=>{
5576
+ performHTTPRequest(this.apiURL, "POST", headers, parameters, true).then((responseObj)=>{
5560
5577
  const responseData=responseObj.responseData;
5561
5578
  const data=responseData;
5562
5579
 
5563
5580
  // DBG
5564
- console.log("~~~~~~~~~~~data :",data);
5581
+ console.log("DEBUG : ~~~~~~~~~~~data :",data);
5565
5582
 
5566
5583
  if(data.error){
5567
5584
  const error=data.error;
@@ -5569,42 +5586,151 @@ class OpenAIAPIClient{
5569
5586
  console.error("Error:", error);
5570
5587
  reject(new Error(`${error}`));
5571
5588
  }
5572
-
5573
- const assistantReply = data.choices[0].message.content;
5574
- // DBG
5575
- console.log("~~~~~~~~~~~assistantReply :",assistantReply);
5576
-
5589
+
5590
+ const assistantReply=self.getAssistantReply(data);
5591
+
5577
5592
  resolve(assistantReply);
5578
5593
  }).catch(errorObj=>{
5579
5594
  const error=errorObj.error;
5580
5595
  const httpStatus=errorObj.httpStatus;
5581
5596
  // TRACE
5582
- console.error("Error:", error);
5597
+ lognow("ERROR:", error);
5583
5598
  reject(error);
5584
5599
  });
5585
5600
  });
5586
5601
 
5587
5602
 
5588
-
5589
-
5590
5603
  }
5591
5604
 
5592
5605
 
5606
+ /*protected*/getAPIRequestHeaders(AIAPIKey){
5607
+ return {
5608
+ "Authorization": "Bearer "+AIAPIKey,
5609
+ "Content-Type": "application/json",
5610
+ };
5611
+ }
5612
+
5613
+ /*protected*/getAPIRequestParameters(messages){
5614
+ return{
5615
+ model:this.modelName,
5616
+ messages:messages,
5617
+ };
5618
+ }
5619
+
5620
+ /*protected*/getAssistantReply(data){
5621
+ return data.choices[0].message.content;
5622
+ }
5623
+
5624
+
5625
+ }
5626
+
5627
+
5628
+
5629
+
5630
+ // Claude :
5631
+
5632
+
5633
+
5634
+ window.ClaudeAPIClient=class ClaudeAPIClient extends LLMAPIClient{
5635
+
5636
+ constructor(modelName, apiURL, agentRole, defaultPrompt){
5637
+ super(modelName, apiURL, agentRole, defaultPrompt);
5638
+
5639
+ }
5640
+
5641
+
5642
+ /*protected*/getAPIRequestHeaders(AIAPIKey){
5643
+ return {
5644
+ "x-api-key": AIAPIKey,
5645
+ "anthropic-version": "2023-06-01",
5646
+ "Content-Type": "application/json"
5647
+ };
5648
+ }
5649
+
5650
+ /*protected*/getAPIRequestParameters(messages){
5651
+ return{
5652
+ model:this.modelName,
5653
+ messages:messages,
5654
+ "max_tokens": 2048,
5655
+ system:this.agentRole,
5656
+ };
5657
+ }
5658
+
5659
+ /*protected*/getMessages(defaultPrompt, userPrompt){
5660
+ return [
5661
+ { role: "user", content: (defaultPrompt+"\n"
5662
+ +userPrompt) },
5663
+ ];
5664
+ }
5665
+
5666
+ /*protected*/getAssistantReply(data){
5667
+ const message=data.content.find(message=>message.type==="text");
5668
+ const reply=message?.text ?? "";
5669
+ return reply;
5670
+ }
5671
+
5672
+ }
5673
+
5674
+
5675
+
5676
+ // "Open"AI API :
5677
+
5678
+
5679
+ window.OpenAIAPIClient=class OpenAIAPIClient extends LLMAPIClient{
5680
+
5681
+ constructor(modelName, apiURL, agentRole, defaultPrompt){
5682
+ super(modelName, apiURL, agentRole, defaultPrompt);
5683
+
5684
+ }
5685
+
5686
+ /*protected*/getAPIRequestHeaders(AIAPIKey){
5687
+ return {
5688
+ "Authorization": "Bearer "+AIAPIKey,
5689
+ "Content-Type": "application/json",
5690
+ };
5691
+ }
5692
+
5693
+ /*protected*/getAPIRequestParameters(messages){
5694
+ return {
5695
+ model:this.modelName,
5696
+ messages:messages,
5697
+ };
5698
+ }
5699
+
5700
+ /*protected*/getMessages(defaultPrompt, userPrompt){
5701
+ return [
5702
+ { role: "system", content: this.agentRole },
5703
+ { role: "user", content: (defaultPrompt+"\n"
5704
+ +userPrompt) },
5705
+ ];
5706
+ }
5707
+
5708
+ /*protected*/getAssistantReply(data){
5709
+ const messageInfo=data.choices.find(choice=>choice.message?.role==="assistant");
5710
+ const reply=messageInfo?.message?.content ?? "";
5711
+ return reply;
5712
+ }
5593
5713
 
5594
5714
 
5595
5715
  }
5596
5716
 
5597
5717
 
5718
+
5719
+
5720
+ // ****************************************************************
5721
+
5598
5722
  // Nodejs compatibility :
5599
- getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
5600
- return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
5723
+ getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProviderName=DEFAULT_LLM_PROVIDER_NAME)=>{
5724
+ if(llmProviderName=="openai")
5725
+ return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
5726
+ return new ClaudeAPIClient(modelName, apiURL, agentRole, defaultPrompt);
5601
5727
  };
5602
5728
 
5603
5729
 
5604
5730
 
5605
5731
 
5606
5732
 
5607
- /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (09/06/2026-14:12:54)»*/
5733
+ /*utils CONSOLE library associated with aotra version : «1_29072022-2359 (14/06/2026-23:54:16)»*/
5608
5734
  /*-----------------------------------------------------------------------------*/
5609
5735
 
5610
5736
 
@@ -8165,9 +8291,10 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
8165
8291
 
8166
8292
  if(isURLInExclusionZone){
8167
8293
  // TRACE
8168
- console.log("ERROR 403 forbidden access error :");
8169
- console.log(error);
8170
-
8294
+ lognow("ERROR 403 forbidden access error :");
8295
+ lognow("ERROR : request:",request);
8296
+ lognow("ERROR : response:",response);
8297
+
8171
8298
  response.writeHead(403);
8172
8299
  response.end("Sorry, cannot access resource : error: "+error.code+" ..\n");
8173
8300
  response.end();
@@ -8202,9 +8329,9 @@ launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, d
8202
8329
 
8203
8330
  }else {
8204
8331
 
8205
- // TRACE
8206
- console.log("ERROR 500 server error :");
8207
- console.log(error);
8332
+ // TRACE
8333
+ lognow("ERROR 500 server error :");
8334
+ lognow("ERROR : error:",error);
8208
8335
 
8209
8336
  response.writeHead(500);
8210
8337
  response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1849",
3
+ "version": "0.0.1851",
4
4
  "main": "aotrautils-srv.build.js",
5
5
  "description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",