Skip to content

Commit

Permalink
Merge pull request #116 from rwth-acis/required-auth
Browse files Browse the repository at this point in the history
Auth headers
  • Loading branch information
Tobasco99 authored Sep 25, 2024
2 parents 25c7325 + af88d05 commit bb0db72
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/bot.manager.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const keyboardEnterPrevent = {
class BotManagerWidget extends LitElement {
storeNameInputEditor;
sbfManagerEndpointEditor;

botModels = [];

guidance = null;
Expand All @@ -51,8 +52,13 @@ class BotManagerWidget extends LitElement {
if (!endpoint) {
return;
}
const accessToken = localStorage.getItem("access_token");

fetch(endpoint + "/models/")
fetch(endpoint + "/models/", {
headers: {
"Authorization": `Bearer ${accessToken}`
}
})
.then((response) => {
if (
response.ok &&
Expand Down Expand Up @@ -94,7 +100,12 @@ class BotManagerWidget extends LitElement {
$(loadStatus).text("Loading...");
spinner.show();
btn.prop("disabled", true);
fetch(endpoint + "/models/" + name)
const accessToken = localStorage.getItem("access_token");
fetch(endpoint + "/models/" + name, {
headers: {
"Authorization": `Bearer ${accessToken}`
}
})
.then((response) => {
if (
response.ok &&
Expand Down Expand Up @@ -193,7 +204,8 @@ class BotManagerWidget extends LitElement {
sendStatus.text("Sending...");
spinner.show();
btn.prop("disabled", true);


const accessToken = localStorage.getItem("access_token");
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.status == 200) {
Expand All @@ -217,6 +229,7 @@ class BotManagerWidget extends LitElement {

xhr.open("POST", endpoint + "/bots");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
xhr.send(JSON.stringify(model));
let botName;
const botNode = Object.values(model["nodes"]).find(
Expand Down Expand Up @@ -268,6 +281,7 @@ class BotManagerWidget extends LitElement {
spinner.show();
btn.prop("disabled", true);

const accessToken = localStorage.getItem("access_token");
var xhr = new XMLHttpRequest();
var agentId = "";
xhr.onload = function () {
Expand All @@ -277,6 +291,7 @@ class BotManagerWidget extends LitElement {
agentId = JSON.parse(xhr.response)[instanceName][botName]["id"];
xhr2.open("DELETE", endpoint + "/bots/" + agentId);
xhr2.setRequestHeader("Content-Type", "application/json");
xhr2.setRequestHeader("Authorization", `Bearer ${accessToken}`);
// delete the chosen bot
xhr2.send(JSON.stringify({ messengers: messengers }));
} catch (error) {
Expand Down Expand Up @@ -316,6 +331,7 @@ class BotManagerWidget extends LitElement {
// first fetch the deployed bots
xhr.open("GET", endpoint + "/bots");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
xhr.send();
}

Expand All @@ -335,11 +351,13 @@ class BotManagerWidget extends LitElement {
storeStatus.text("Storing...");
btn.prop("disabled", true);

const accessToken = localStorage.getItem("access_token");
if (botName && model) {
fetch(endpoint + "/models/" + botName, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`
},
body: JSON.stringify(model),
})
Expand Down Expand Up @@ -466,7 +484,6 @@ class BotManagerWidget extends LitElement {
}
</style>
<div class="m-1">
<h3>Bot Operations</h3>
<div class="row">
Expand Down
15 changes: 15 additions & 0 deletions src/model-training.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class ModelTraining extends LitElement {
markdownTrainingData: _this.editor.getText(),
}),
contentType: "application/json",
headers: {
"Authorization": "Bearer " + localStorage.getItem("access_token"),
},
success: function (data, textStatus, jqXHR) {
$(_this.htmlQuery("#trainingStatus")).text(data);
},
Expand Down Expand Up @@ -413,6 +416,9 @@ class ModelTraining extends LitElement {
type: "GET",
url: trainingStatusUrl,
contentType: "text/plain",
headers: {
"Authorization": "Bearer " + localStorage.getItem("access_token"),
},
success: function (data, textStatus, jqXHR) {
$(_this.htmlQuery("#trainingStatus")).text(data);
},
Expand All @@ -435,6 +441,9 @@ class ModelTraining extends LitElement {
$.ajax({
type: "POST",
url: trainingStatusUrl + name,
headers: {
"Authorization": "Bearer " + localStorage.getItem("access_token"),
},
data: trainingData,
contentType: "text/plain",
success: function (data, textStatus, jqXHR) {
Expand All @@ -460,6 +469,9 @@ class ModelTraining extends LitElement {
type: "GET",
url: trainingStatusUrl + name,
contentType: "text/plain",
headers: {
"Authorization": "Bearer " + localStorage.getItem("access_token"),
},
success: function (data, textStatus, jqXHR) {
$(_this.htmlQuery("#trainingStatus")).text("Data loaded.");
_this.editor.setText(data);
Expand All @@ -480,6 +492,9 @@ class ModelTraining extends LitElement {
type: "GET",
url: trainingStatusUrl + "/training/",
contentType: "application/json",
headers: {
"Authorization": "Bearer " + localStorage.getItem("access_token"),
},
success: function (data, textStatus, jqXHR) {
if (textStatus !== "success") {
return;
Expand Down

0 comments on commit bb0db72

Please sign in to comment.