:zap: [Enhance] [WIP] Dynamicly creating NewAgentModal
Browse files- components/buttons_binder.js +12 -1
- components/inputs_binder.js +0 -10
- index.html +0 -78
- storages/agents_storage.js +1 -0
- widgets/new_agent_modal_widget.js +105 -0
- widgets/range_number_widget.js +66 -0
components/buttons_binder.js
CHANGED
@@ -8,6 +8,8 @@ import {
|
|
8 |
create_messager,
|
9 |
} from "./chat_operator.js";
|
10 |
|
|
|
|
|
11 |
import { screen_scroller } from "./screen_scroller.js";
|
12 |
import { chat_history_storage } from "../storages/chat_history_storage.js";
|
13 |
import { endpoint_storage } from "../storages/endpoint_storage.js";
|
@@ -35,6 +37,8 @@ export class ButtonsBinder {
|
|
35 |
let chat_agents_sidebar_toggle_button_binder =
|
36 |
new ChatAgentsSidebarToggleButtonBinder();
|
37 |
chat_agents_sidebar_toggle_button_binder.bind();
|
|
|
|
|
38 |
let clear_chat_history_button_binder =
|
39 |
new ClearChatHistoryButtonBinder();
|
40 |
clear_chat_history_button_binder.bind();
|
@@ -295,7 +299,14 @@ class ChatAgentsSidebarToggleButtonBinder {
|
|
295 |
|
296 |
class NewAgentButtonBinder {
|
297 |
constructor() {}
|
298 |
-
bind() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
}
|
300 |
|
301 |
class ClearChatAgentsButtonBinder {
|
|
|
8 |
create_messager,
|
9 |
} from "./chat_operator.js";
|
10 |
|
11 |
+
import { NewAgentModalWidget } from "../widgets/new_agent_modal_widget.js";
|
12 |
+
|
13 |
import { screen_scroller } from "./screen_scroller.js";
|
14 |
import { chat_history_storage } from "../storages/chat_history_storage.js";
|
15 |
import { endpoint_storage } from "../storages/endpoint_storage.js";
|
|
|
37 |
let chat_agents_sidebar_toggle_button_binder =
|
38 |
new ChatAgentsSidebarToggleButtonBinder();
|
39 |
chat_agents_sidebar_toggle_button_binder.bind();
|
40 |
+
let new_agent_button_binder = new NewAgentButtonBinder();
|
41 |
+
new_agent_button_binder.bind();
|
42 |
let clear_chat_history_button_binder =
|
43 |
new ClearChatHistoryButtonBinder();
|
44 |
clear_chat_history_button_binder.bind();
|
|
|
299 |
|
300 |
class NewAgentButtonBinder {
|
301 |
constructor() {}
|
302 |
+
bind() {
|
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 |
}
|
311 |
|
312 |
class ClearChatAgentsButtonBinder {
|
components/inputs_binder.js
CHANGED
@@ -27,16 +27,6 @@ class UserInputResizer {
|
|
27 |
},
|
28 |
false
|
29 |
);
|
30 |
-
document
|
31 |
-
.getElementById("new-agent-modal-system-prompt")
|
32 |
-
.addEventListener(
|
33 |
-
"input",
|
34 |
-
function () {
|
35 |
-
this.style.height = 0;
|
36 |
-
this.style.height = this.scrollHeight + 3 + "px";
|
37 |
-
},
|
38 |
-
false
|
39 |
-
);
|
40 |
}
|
41 |
}
|
42 |
|
|
|
27 |
},
|
28 |
false
|
29 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
}
|
32 |
|
index.html
CHANGED
@@ -85,70 +85,6 @@
|
|
85 |
</div>
|
86 |
</div>
|
87 |
</div>
|
88 |
-
<div id="new-agent-modal" data-bs-backdrop="static" class="modal" role="dialog">
|
89 |
-
<div class="modal-dialog modal-dialog-centered" role="document">
|
90 |
-
<div class="modal-content">
|
91 |
-
<div class="modal-header">
|
92 |
-
<h4 class="modal-title">Create New Agent</h4>
|
93 |
-
<button class="btn" data-bs-dismiss="modal">
|
94 |
-
<i class="fa fa-close"></i>
|
95 |
-
</button>
|
96 |
-
</div>
|
97 |
-
<div class="modal-body">
|
98 |
-
<!-- nickname -->
|
99 |
-
<div class="form-floating mb-2">
|
100 |
-
<input id="new-agent-modal-nickname" class="form-control" type="text" placeholder="Nickname" />
|
101 |
-
<label for="new-agent-model-nickname" class="form-label">Nickname</label>
|
102 |
-
</div>
|
103 |
-
<!-- model -->
|
104 |
-
<div class="form-floating mb-2">
|
105 |
-
<select id="new-agent-modal-model" class="form-select" type="text"></select>
|
106 |
-
<label for="new-agent-modal-model" class="form-label">Model</label>
|
107 |
-
</div>
|
108 |
-
<!-- temperature -->
|
109 |
-
<div class="row mb-0">
|
110 |
-
<label for="new-agent-modal-temperature" class="col-form-label">Temperature</label>
|
111 |
-
<div class="col-sm-8 d-flex align-items-center">
|
112 |
-
<input id="new-agent-modal-temperature-range" type="range" value="0" min="0" max="1"
|
113 |
-
step="0.1" class="form-range" oninput="updateTemperatureNumber(this.value)" />
|
114 |
-
</div>
|
115 |
-
<div class="col-sm-4">
|
116 |
-
<input id="new-agent-modal-temperature-number" type="number" value="0" min="0" max="1"
|
117 |
-
step="0.1" class="form-control" onchange="updateTemperatureRange(this.value)" />
|
118 |
-
</div>
|
119 |
-
</div>
|
120 |
-
<!-- max output tokens -->
|
121 |
-
<div class="row mb-2">
|
122 |
-
<label for="new-agent-modal-max-output-tokens" class="col-form-label">Max Output
|
123 |
-
Tokens (<code>-1</code>: auto)</label>
|
124 |
-
<div class="col-sm-8 d-flex align-items-center">
|
125 |
-
<input id="new-agent-modal-max-output-tokens-range" type="range" value="-1" min="-1"
|
126 |
-
max="32768" step="1" class="form-range"
|
127 |
-
oninput="updateMaxOutputTokensNumber(this.value)" />
|
128 |
-
</div>
|
129 |
-
<div class="col-sm-4">
|
130 |
-
<input id="new-agent-modal-max-output-tokens-number" type="number" value="-1" min="-1"
|
131 |
-
max="32768" step="1" class="form-control"
|
132 |
-
onchange="updateMaxOutputTokensRange(this.value)" />
|
133 |
-
</div>
|
134 |
-
</div>
|
135 |
-
<!-- system prompt -->
|
136 |
-
<div class="form-floating mb-2">
|
137 |
-
<textarea id="new-agent-modal-system-prompt" class="form-control" placeholder="System Prompt"
|
138 |
-
rows="3"></textarea>
|
139 |
-
<label for="new-agent-modal-system-prompt">System Prompt</label>
|
140 |
-
</div>
|
141 |
-
<!-- max token -->
|
142 |
-
<!-- max history messages token -->
|
143 |
-
</div>
|
144 |
-
<div class="modal-footer justify-content-end">
|
145 |
-
<button id="new-agent-model-save-button" class="btn btn-success">Save</button>
|
146 |
-
<button id="new-agent-model-close-button" class="btn btn-secondary"
|
147 |
-
data-bs-dismiss="modal">Close</button>
|
148 |
-
</div>
|
149 |
-
</div>
|
150 |
-
</div>
|
151 |
-
</div>
|
152 |
<div id="main-container" class="container">
|
153 |
<div id="top-toolbar" class="container mt-2">
|
154 |
<div class="my-1 row no-gutters justify-content-start">
|
@@ -209,20 +145,6 @@
|
|
209 |
</div>
|
210 |
</div>
|
211 |
</body>
|
212 |
-
<script>
|
213 |
-
function updateTemperatureNumber(value) {
|
214 |
-
document.getElementById('new-agent-modal-temperature-number').value = value;
|
215 |
-
}
|
216 |
-
function updateTemperatureRange(value) {
|
217 |
-
document.getElementById('new-agent-modal-temperature-range').value = value;
|
218 |
-
}
|
219 |
-
function updateMaxOutputTokensNumber(value) {
|
220 |
-
document.getElementById('new-agent-modal-max-output-tokens-number').value = value;
|
221 |
-
}
|
222 |
-
function updateMaxOutputTokensRange(value) {
|
223 |
-
document.getElementById('new-agent-modal-max-output-tokens-range').value = value;
|
224 |
-
}
|
225 |
-
</script>
|
226 |
<script type="module" src="./main.js"></script>
|
227 |
|
228 |
</html>
|
|
|
85 |
</div>
|
86 |
</div>
|
87 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
<div id="main-container" class="container">
|
89 |
<div id="top-toolbar" class="container mt-2">
|
90 |
<div class="my-1 row no-gutters justify-content-start">
|
|
|
145 |
</div>
|
146 |
</div>
|
147 |
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
<script type="module" src="./main.js"></script>
|
149 |
|
150 |
</html>
|
storages/agents_storage.js
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
class AgentsStorage {}
|
widgets/new_agent_modal_widget.js
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
9 |
+
this.append_to_body();
|
10 |
+
}
|
11 |
+
remove() {
|
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",
|
19 |
+
default_val: 0,
|
20 |
+
min_val: 0,
|
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",
|
33 |
+
default_val: -1,
|
34 |
+
min_val: -1,
|
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() {
|
43 |
+
this.widget_html = `
|
44 |
+
<div id="${this.widget_id}" data-bs-backdrop="static" class="modal" role="dialog">
|
45 |
+
<div class="modal-dialog modal-dialog-centered" role="document">
|
46 |
+
<div class="modal-content">
|
47 |
+
<div class="modal-header">
|
48 |
+
<h4 class="modal-title">Create New Agent</h4>
|
49 |
+
<button class="btn" data-bs-dismiss="modal">
|
50 |
+
<i class="fa fa-close"></i>
|
51 |
+
</button>
|
52 |
+
</div>
|
53 |
+
<div class="modal-body">
|
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"">
|
66 |
+
</div>
|
67 |
+
<!-- max output tokens -->
|
68 |
+
<div id="${this.max_output_tokens_widget_id}" class="row mb-2">
|
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 -->
|
78 |
+
</div>
|
79 |
+
<div class="modal-footer justify-content-end">
|
80 |
+
<button id="new-agent-model-save-button" class="btn btn-success">Save</button>
|
81 |
+
<button id="new-agent-model-close-button" class="btn btn-secondary"
|
82 |
+
data-bs-dismiss="modal">Close</button>
|
83 |
+
</div>
|
84 |
+
</div>
|
85 |
+
</div>
|
86 |
+
</div>
|
87 |
+
`;
|
88 |
+
this.widget = $(this.widget_html);
|
89 |
+
this.create_temperature_widget();
|
90 |
+
this.create_max_output_tokens_widget();
|
91 |
+
}
|
92 |
+
append_to_body() {
|
93 |
+
$("body").append(this.widget);
|
94 |
+
document
|
95 |
+
.getElementById("new-agent-modal-system-prompt")
|
96 |
+
.addEventListener(
|
97 |
+
"input",
|
98 |
+
function () {
|
99 |
+
this.style.height = 0;
|
100 |
+
this.style.height = this.scrollHeight + 3 + "px";
|
101 |
+
},
|
102 |
+
false
|
103 |
+
);
|
104 |
+
}
|
105 |
+
}
|
widgets/range_number_widget.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export class RangeNumberWidget {
|
2 |
+
constructor({
|
3 |
+
widget_id = null,
|
4 |
+
label_text = null,
|
5 |
+
default_val = null,
|
6 |
+
min_val = null,
|
7 |
+
max_val = null,
|
8 |
+
step_val = null,
|
9 |
+
range_col = 8,
|
10 |
+
number_col = 4,
|
11 |
+
} = {}) {
|
12 |
+
this.widget_id = widget_id;
|
13 |
+
this.label_text = label_text;
|
14 |
+
this.default_val = default_val;
|
15 |
+
this.min_val = min_val;
|
16 |
+
this.max_val = max_val;
|
17 |
+
this.step_val = step_val;
|
18 |
+
this.range_col = range_col;
|
19 |
+
this.number_col = number_col;
|
20 |
+
}
|
21 |
+
spawn_in_parent(parent) {
|
22 |
+
this.create_widget();
|
23 |
+
this.bind_update_functions();
|
24 |
+
this.append_to_parent(parent);
|
25 |
+
}
|
26 |
+
remove() {
|
27 |
+
this.widget.remove();
|
28 |
+
}
|
29 |
+
create_widget() {
|
30 |
+
this.widget_html = `
|
31 |
+
<label class="col-form-label">${this.label_text}</label>
|
32 |
+
<div class="col-sm-${this.range_col} d-flex align-items-center">
|
33 |
+
<input id="${this.widget_id}-range"
|
34 |
+
type="range" value="${this.default_val}"
|
35 |
+
min="${this.min_val}" max="${this.max_val}" step="${this.step_val}"
|
36 |
+
class="form-range"
|
37 |
+
/>
|
38 |
+
</div>
|
39 |
+
<div class="col-sm-${this.number_col}">
|
40 |
+
<input id="${this.widget_id}-number"
|
41 |
+
type="number" value="${this.default_val}"
|
42 |
+
min="${this.min_val}" max="${this.max_val}" step="${this.step_val}"
|
43 |
+
class="form-control"
|
44 |
+
/>
|
45 |
+
</div>`;
|
46 |
+
this.widget = $(this.widget_html);
|
47 |
+
}
|
48 |
+
update_number_widget_value(value) {
|
49 |
+
$(`#${this.widget_id}-number`).val(value);
|
50 |
+
}
|
51 |
+
update_range_widget_value(value) {
|
52 |
+
$(`#${this.widget_id}-range`).val(value);
|
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 |
+
}
|
63 |
+
append_to_parent(parent) {
|
64 |
+
parent.append(this.widget);
|
65 |
+
}
|
66 |
+
}
|