Hansimov commited on
Commit
84b077e
1 Parent(s): 62b2fed

:zap: [Enhance] Enable RangeNumber widget append and real-time update, generalize widget_id, and check existance before creating modal

Browse files
components/buttons_binder.js CHANGED
@@ -303,8 +303,20 @@ class NewAgentButtonBinder {
303
  const button = $("#new-agent-button");
304
  button.attr("title", "New agent");
305
  button.click(() => {
306
- let new_agent_modal_widget = new NewAgentModalWidget();
307
- new_agent_modal_widget.spawn();
 
 
 
 
 
 
 
 
 
 
 
 
308
  });
309
  }
310
  }
 
303
  const button = $("#new-agent-button");
304
  button.attr("title", "New agent");
305
  button.click(() => {
306
+ let new_agent_modal_widget_id = "new-agent-modal";
307
+ let new_agent_modal_widget_parent = $(
308
+ `#${new_agent_modal_widget_id}`
309
+ );
310
+ if (new_agent_modal_widget_parent.length <= 0) {
311
+ let new_agent_modal_widget = new NewAgentModalWidget({
312
+ widget_id: new_agent_modal_widget_id,
313
+ });
314
+ new_agent_modal_widget.spawn();
315
+ new_agent_modal_widget_parent = $(
316
+ `#${new_agent_modal_widget_id}`
317
+ );
318
+ }
319
+ new_agent_modal_widget_parent.modal("show");
320
  });
321
  }
322
  }
css/default.css CHANGED
@@ -46,11 +46,6 @@ body {
46
  flex: 0 0 auto;
47
  }
48
 
49
- #new-agent-modal-system-prompt {
50
- resize: none;
51
- max-height: 200px;
52
- }
53
-
54
  .message-user,
55
  .message-assistant {
56
  box-shadow: 0px 0px 6px 0px rgba(122, 122, 122, 0.5);
 
46
  flex: 0 0 auto;
47
  }
48
 
 
 
 
 
 
49
  .message-user,
50
  .message-assistant {
51
  box-shadow: 0px 0px 6px 0px rgba(122, 122, 122, 0.5);
index.html CHANGED
@@ -69,8 +69,7 @@
69
  </div>
70
  <div class="offcanvas-body">
71
  <div class="my-0 row no-gutters">
72
- <button id="new-agent-button" type="button" class="explicit-button" data-bs-toggle="modal"
73
- data-bs-target="#new-agent-modal">
74
  <i class="fa fa-plus"></i> New Agent
75
  </button>
76
  </div>
 
69
  </div>
70
  <div class="offcanvas-body">
71
  <div class="my-0 row no-gutters">
72
+ <button id="new-agent-button" type="button" class="explicit-button">
 
73
  <i class="fa fa-plus"></i> New Agent
74
  </button>
75
  </div>
widgets/new_agent_modal_widget.js CHANGED
@@ -1,8 +1,11 @@
1
  import { RangeNumberWidget } from "./range_number_widget.js";
2
 
3
  export class NewAgentModalWidget {
4
- constructor() {
5
- this.widget_id = "new-agent-modal";
 
 
 
6
  }
7
  spawn() {
8
  this.create_widget();
@@ -12,7 +15,6 @@ export class NewAgentModalWidget {
12
  this.widget.remove();
13
  }
14
  create_temperature_widget() {
15
- this.temperature_widget_id = `${this.widget_id}-temperature`;
16
  this.temperature_widget = new RangeNumberWidget({
17
  widget_id: this.temperature_widget_id,
18
  label_text: "Temperature",
@@ -21,12 +23,12 @@ export class NewAgentModalWidget {
21
  max_val: 1,
22
  step_val: 0.1,
23
  });
24
- this.temperature_widget.spawn_in_parent(
25
- this.widget.find(`#${this.temperature_widget_id}`)
26
  );
 
27
  }
28
  create_max_output_tokens_widget() {
29
- this.max_output_tokens_widget_id = `${this.widget_id}-max-output-tokens`;
30
  this.max_output_tokens_widget = new RangeNumberWidget({
31
  widget_id: this.max_output_tokens_widget_id,
32
  label_text: "Max Output Tokens",
@@ -35,8 +37,11 @@ export class NewAgentModalWidget {
35
  max_val: 32768,
36
  step_val: 1,
37
  });
 
 
 
38
  this.max_output_tokens_widget.spawn_in_parent(
39
- this.widget.find(`#${this.temperature_widget_id}`)
40
  );
41
  }
42
  create_widget() {
@@ -54,12 +59,12 @@ export class NewAgentModalWidget {
54
  <!-- nickname -->
55
  <div class="form-floating mb-2">
56
  <input id="${this.widget_id}-nickname" class="form-control" type="text" placeholder="Nickname" />
57
- <label for="new-agent-model-nickname" class="form-label">Nickname</label>
58
  </div>
59
  <!-- model -->
60
  <div class="form-floating mb-2">
61
  <select id="${this.widget_id}-model" class="form-select" type="text"></select>
62
- <label for="${this.widget_id}-model" class="form-label">Model</label>
63
  </div>
64
  <!-- temperature -->
65
  <div id="${this.temperature_widget_id}" class="row mb-0"">
@@ -69,9 +74,9 @@ export class NewAgentModalWidget {
69
  </div>
70
  <!-- system prompt -->
71
  <div class="form-floating mb-2">
72
- <textarea id="${this.widget_id}-system-prompt" class="form-control" placeholder="System Prompt"
73
  rows="3"></textarea>
74
- <label for="${this.widget_id}-system-prompt">System Prompt</label>
75
  </div>
76
  <!-- max token -->
77
  <!-- max history messages token -->
@@ -92,7 +97,7 @@ export class NewAgentModalWidget {
92
  append_to_body() {
93
  $("body").append(this.widget);
94
  document
95
- .getElementById("new-agent-modal-system-prompt")
96
  .addEventListener(
97
  "input",
98
  function () {
@@ -101,5 +106,8 @@ export class NewAgentModalWidget {
101
  },
102
  false
103
  );
 
 
 
104
  }
105
  }
 
1
  import { RangeNumberWidget } from "./range_number_widget.js";
2
 
3
  export class NewAgentModalWidget {
4
+ constructor({ widget_id = null } = {}) {
5
+ this.widget_id = widget_id;
6
+ this.temperature_widget_id = `${this.widget_id}-temperature`;
7
+ this.max_output_tokens_widget_id = `${this.widget_id}-max-output-tokens`;
8
+ this.system_prompt_widget_id = `${this.widget_id}-system-prompt`;
9
  }
10
  spawn() {
11
  this.create_widget();
 
15
  this.widget.remove();
16
  }
17
  create_temperature_widget() {
 
18
  this.temperature_widget = new RangeNumberWidget({
19
  widget_id: this.temperature_widget_id,
20
  label_text: "Temperature",
 
23
  max_val: 1,
24
  step_val: 0.1,
25
  });
26
+ let temperature_widget_parent = this.widget.find(
27
+ `#${this.temperature_widget_id}`
28
  );
29
+ this.temperature_widget.spawn_in_parent(temperature_widget_parent);
30
  }
31
  create_max_output_tokens_widget() {
 
32
  this.max_output_tokens_widget = new RangeNumberWidget({
33
  widget_id: this.max_output_tokens_widget_id,
34
  label_text: "Max Output Tokens",
 
37
  max_val: 32768,
38
  step_val: 1,
39
  });
40
+ let max_output_tokens_widget_parent = this.widget.find(
41
+ `#${this.max_output_tokens_widget_id}`
42
+ );
43
  this.max_output_tokens_widget.spawn_in_parent(
44
+ max_output_tokens_widget_parent
45
  );
46
  }
47
  create_widget() {
 
59
  <!-- nickname -->
60
  <div class="form-floating mb-2">
61
  <input id="${this.widget_id}-nickname" class="form-control" type="text" placeholder="Nickname" />
62
+ <label class="form-label">Nickname</label>
63
  </div>
64
  <!-- model -->
65
  <div class="form-floating mb-2">
66
  <select id="${this.widget_id}-model" class="form-select" type="text"></select>
67
+ <label class="form-label">Model</label>
68
  </div>
69
  <!-- temperature -->
70
  <div id="${this.temperature_widget_id}" class="row mb-0"">
 
74
  </div>
75
  <!-- system prompt -->
76
  <div class="form-floating mb-2">
77
+ <textarea id="${this.system_prompt_widget_id}" class="form-control" placeholder="System Prompt"
78
  rows="3"></textarea>
79
+ <label>System Prompt</label>
80
  </div>
81
  <!-- max token -->
82
  <!-- max history messages token -->
 
97
  append_to_body() {
98
  $("body").append(this.widget);
99
  document
100
+ .getElementById(`${this.system_prompt_widget_id}`)
101
  .addEventListener(
102
  "input",
103
  function () {
 
106
  },
107
  false
108
  );
109
+ $(`#${this.system_prompt_widget_id}`)
110
+ .css("resize", "none")
111
+ .css("max-height", "200px");
112
  }
113
  }
widgets/range_number_widget.js CHANGED
@@ -53,10 +53,10 @@ export class RangeNumberWidget {
53
  }
54
  bind_update_functions() {
55
  let self = this;
56
- this.widget.find(`#${this.widget_id}-range`).change(function () {
57
  self.update_number_widget_value($(this).val());
58
  });
59
- this.widget.find(`#${this.widget_id}-number`).change(function () {
60
  self.update_range_widget_value($(this).val());
61
  });
62
  }
 
53
  }
54
  bind_update_functions() {
55
  let self = this;
56
+ this.widget.find(`#${this.widget_id}-range`).on("input", function () {
57
  self.update_number_widget_value($(this).val());
58
  });
59
+ this.widget.find(`#${this.widget_id}-number`).on("input", function () {
60
  self.update_range_widget_value($(this).val());
61
  });
62
  }