@nogataka/smart-edit 0.1.0 → 1.0.1
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.
- package/LICENSE +0 -1
- package/README.md +143 -66
- package/dist/cli.js +2 -2
- package/dist/devtools/generate_prompt_factory.js +5 -5
- package/dist/index.d.ts +33 -34
- package/dist/index.js +33 -34
- package/dist/interprompt/multilang_prompt.js +2 -2
- package/dist/interprompt/prompt_factory.js +2 -2
- package/dist/interprompt/util/class_decorators.d.ts +1 -1
- package/dist/interprompt/util/class_decorators.js +1 -1
- package/dist/{serena → smart-edit}/agent.d.ts +20 -20
- package/dist/{serena → smart-edit}/agent.js +43 -43
- package/dist/{serena → smart-edit}/analytics.d.ts +1 -1
- package/dist/{serena → smart-edit}/analytics.js +3 -3
- package/dist/smart-edit/cli.d.ts +9 -0
- package/dist/{serena → smart-edit}/cli.js +49 -99
- package/dist/{serena → smart-edit}/code_editor.d.ts +7 -7
- package/dist/{serena → smart-edit}/config/context_mode.d.ts +13 -13
- package/dist/{serena → smart-edit}/config/context_mode.js +12 -12
- package/dist/{serena/config/serena_config.d.ts → smart-edit/config/smart_edit_config.d.ts} +14 -14
- package/dist/{serena/config/serena_config.js → smart-edit/config/smart_edit_config.js} +31 -31
- package/dist/smart-edit/constants.d.ts +18 -0
- package/dist/smart-edit/constants.js +27 -0
- package/dist/{serena → smart-edit}/dashboard.d.ts +3 -3
- package/dist/{serena → smart-edit}/dashboard.js +10 -10
- package/dist/{serena → smart-edit}/gui_log_viewer.js +6 -6
- package/dist/{serena → smart-edit}/mcp.d.ts +40 -40
- package/dist/{serena → smart-edit}/mcp.js +38 -38
- package/dist/{serena → smart-edit}/project.d.ts +7 -7
- package/dist/{serena → smart-edit}/project.js +18 -18
- package/dist/{serena → smart-edit}/prompt_factory.d.ts +3 -3
- package/dist/{serena → smart-edit}/prompt_factory.js +1 -1
- package/dist/{serena → smart-edit}/resources/config/contexts/codex.yml +2 -2
- package/dist/{serena → smart-edit}/resources/config/contexts/context.template.yml +1 -1
- package/dist/{serena → smart-edit}/resources/config/contexts/ide-assistant.yml +2 -2
- package/dist/{serena → smart-edit}/resources/config/modes/mode.template.yml +1 -1
- package/dist/{serena → smart-edit}/resources/config/prompt_templates/simple_tool_outputs.yml +1 -1
- package/dist/smart-edit/resources/dashboard/dashboard.js +13 -0
- package/dist/smart-edit/resources/dashboard/index.css +1 -0
- package/dist/smart-edit/resources/dashboard/index.html +13 -0
- package/dist/{serena → smart-edit}/resources/project.template.yml +6 -6
- package/dist/{serena/resources/serena_config.template.yml → smart-edit/resources/smart_edit_config.template.yml} +14 -14
- package/dist/{serena → smart-edit}/symbol.d.ts +7 -7
- package/dist/{serena → smart-edit}/symbol.js +2 -2
- package/dist/{serena → smart-edit}/text_utils.js +2 -2
- package/dist/{serena → smart-edit}/tools/config_tools.d.ts +1 -1
- package/dist/{serena → smart-edit}/tools/config_tools.js +6 -6
- package/dist/{serena → smart-edit}/tools/memory_tools.d.ts +4 -4
- package/dist/{serena → smart-edit}/tools/memory_tools.js +5 -5
- package/dist/{serena → smart-edit}/tools/tools_base.d.ts +15 -15
- package/dist/{serena → smart-edit}/tools/tools_base.js +7 -7
- package/dist/{serena → smart-edit}/util/exception.d.ts +2 -2
- package/dist/{serena → smart-edit}/util/exception.js +2 -2
- package/dist/{serena → smart-edit}/util/file_system.js +3 -3
- package/dist/{serena → smart-edit}/util/git.js +3 -3
- package/dist/{serena → smart-edit}/util/inspection.d.ts +3 -3
- package/dist/{serena → smart-edit}/util/inspection.js +3 -3
- package/dist/{serena → smart-edit}/util/logging.d.ts +6 -6
- package/dist/{serena → smart-edit}/util/logging.js +7 -7
- package/dist/{serena → smart-edit}/util/shell.js +1 -1
- package/dist/smart-edit/version.d.ts +1 -0
- package/dist/{serena → smart-edit}/version.js +3 -3
- package/dist/{solidlsp → smart-lsp}/language_servers/autoload.js +1 -1
- package/dist/smart-lsp/language_servers/bash_language_server.d.ts +10 -0
- package/dist/{solidlsp → smart-lsp}/language_servers/bash_language_server.js +8 -8
- package/dist/{solidlsp → smart-lsp}/language_servers/clangd_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/clangd_language_server.js +9 -9
- package/dist/{solidlsp → smart-lsp}/language_servers/clojure_lsp.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/clojure_lsp.js +9 -9
- package/dist/{solidlsp → smart-lsp}/language_servers/common.d.ts +2 -2
- package/dist/{solidlsp → smart-lsp}/language_servers/common.js +1 -1
- package/dist/{solidlsp → smart-lsp}/language_servers/csharp_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/csharp_language_server.js +12 -12
- package/dist/smart-lsp/language_servers/dart_language_server.d.ts +10 -0
- package/dist/{solidlsp → smart-lsp}/language_servers/dart_language_server.js +13 -13
- package/dist/{solidlsp → smart-lsp}/language_servers/eclipse_jdtls.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/eclipse_jdtls.js +12 -12
- package/dist/{solidlsp → smart-lsp}/language_servers/erlang_language_server.d.ts +3 -3
- package/dist/{solidlsp → smart-lsp}/language_servers/erlang_language_server.js +6 -6
- package/dist/{solidlsp → smart-lsp}/language_servers/gopls.d.ts +3 -3
- package/dist/{solidlsp → smart-lsp}/language_servers/gopls.js +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/intelephense.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/intelephense.js +11 -11
- package/dist/{solidlsp → smart-lsp}/language_servers/jedi_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/jedi_server.js +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/kotlin_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/kotlin_language_server.js +9 -9
- package/dist/{solidlsp → smart-lsp}/language_servers/lua_ls.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/lua_ls.js +10 -10
- package/dist/{solidlsp → smart-lsp}/language_servers/nixd_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/nixd_language_server.js +7 -7
- package/dist/{solidlsp → smart-lsp}/language_servers/pyright_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/pyright_server.js +3 -3
- package/dist/{solidlsp → smart-lsp}/language_servers/r_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/r_language_server.js +5 -5
- package/dist/smart-lsp/language_servers/ruby_common.d.ts +10 -0
- package/dist/{solidlsp → smart-lsp}/language_servers/ruby_common.js +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/ruby_lsp.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/ruby_lsp.js +10 -10
- package/dist/{solidlsp → smart-lsp}/language_servers/rust_analyzer.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/rust_analyzer.js +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/solargraph.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/solargraph.js +10 -10
- package/dist/{solidlsp → smart-lsp}/language_servers/sourcekit_lsp.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/sourcekit_lsp.js +7 -7
- package/dist/{solidlsp → smart-lsp}/language_servers/terraform_ls.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/terraform_ls.js +14 -14
- package/dist/{solidlsp → smart-lsp}/language_servers/typescript_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/typescript_language_server.js +11 -11
- package/dist/{solidlsp → smart-lsp}/language_servers/vts_language_server.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/vts_language_server.js +10 -10
- package/dist/{solidlsp → smart-lsp}/language_servers/zls.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/language_servers/zls.js +6 -6
- package/dist/{solidlsp → smart-lsp}/ls.d.ts +25 -25
- package/dist/{solidlsp → smart-lsp}/ls.js +19 -19
- package/dist/{solidlsp → smart-lsp}/ls_config.d.ts +0 -5
- package/dist/{solidlsp → smart-lsp}/ls_config.js +0 -5
- package/dist/{solidlsp → smart-lsp}/ls_exceptions.d.ts +1 -1
- package/dist/{solidlsp → smart-lsp}/ls_exceptions.js +2 -2
- package/dist/{solidlsp → smart-lsp}/ls_handler.d.ts +7 -7
- package/dist/{solidlsp → smart-lsp}/ls_handler.js +12 -12
- package/dist/{solidlsp → smart-lsp}/ls_request.d.ts +4 -4
- package/dist/{solidlsp → smart-lsp}/ls_request.js +3 -3
- package/package.json +17 -3
- package/dist/serena/agno.d.ts +0 -111
- package/dist/serena/agno.js +0 -278
- package/dist/serena/cli.d.ts +0 -9
- package/dist/serena/constants.d.ts +0 -18
- package/dist/serena/constants.js +0 -27
- package/dist/serena/resources/dashboard/dashboard.js +0 -816
- package/dist/serena/resources/dashboard/index.html +0 -312
- package/dist/serena/resources/dashboard/jquery.min.js +0 -3
- package/dist/serena/version.d.ts +0 -1
- package/dist/solidlsp/language_servers/bash_language_server.d.ts +0 -10
- package/dist/solidlsp/language_servers/dart_language_server.d.ts +0 -10
- package/dist/solidlsp/language_servers/ruby_common.d.ts +0 -10
- /package/dist/{serena → smart-edit}/code_editor.js +0 -0
- /package/dist/{serena → smart-edit}/generated/generated_prompt_factory.d.ts +0 -0
- /package/dist/{serena → smart-edit}/generated/generated_prompt_factory.js +0 -0
- /package/dist/{serena → smart-edit}/gui_log_viewer.d.ts +0 -0
- /package/dist/{serena → smart-edit}/resources/config/contexts/agent.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/contexts/chatgpt.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/contexts/desktop-app.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/contexts/oaicompat-agent.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/internal_modes/jetbrains.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/editing.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/interactive.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/no-onboarding.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/onboarding.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/one-shot.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/modes/planning.yml +0 -0
- /package/dist/{serena → smart-edit}/resources/config/prompt_templates/system_prompt.yml +0 -0
- /package/dist/{serena/resources/dashboard/serena-icon-16.svg → smart-edit/resources/dashboard/smart-edit-icon-16.svg} +0 -0
- /package/dist/{serena/resources/dashboard/serena-icon-32.svg → smart-edit/resources/dashboard/smart-edit-icon-32.svg} +0 -0
- /package/dist/{serena/resources/dashboard/serena-icon-48.svg → smart-edit/resources/dashboard/smart-edit-icon-48.svg} +0 -0
- /package/dist/{serena/resources/dashboard/serena-logs-dark-mode.svg → smart-edit/resources/dashboard/smart-edit-logs-dark-mode.svg} +0 -0
- /package/dist/{serena/resources/dashboard/serena-logs.svg → smart-edit/resources/dashboard/smart-edit-logs.svg} +0 -0
- /package/dist/{serena → smart-edit}/text_utils.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/cmd_tools.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/cmd_tools.js +0 -0
- /package/dist/{serena → smart-edit}/tools/file_tools.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/file_tools.js +0 -0
- /package/dist/{serena → smart-edit}/tools/index.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/index.js +0 -0
- /package/dist/{serena → smart-edit}/tools/symbol_tools.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/symbol_tools.js +0 -0
- /package/dist/{serena → smart-edit}/tools/workflow_tools.d.ts +0 -0
- /package/dist/{serena → smart-edit}/tools/workflow_tools.js +0 -0
- /package/dist/{serena → smart-edit}/util/class_decorators.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/class_decorators.js +0 -0
- /package/dist/{serena → smart-edit}/util/file_system.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/general.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/general.js +0 -0
- /package/dist/{serena → smart-edit}/util/git.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/shell.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/thread.d.ts +0 -0
- /package/dist/{serena → smart-edit}/util/thread.js +0 -0
- /package/dist/{solidlsp → smart-lsp}/language_servers/autoload.d.ts +0 -0
- /package/dist/{solidlsp → smart-lsp}/ls_types.d.ts +0 -0
- /package/dist/{solidlsp → smart-lsp}/ls_types.js +0 -0
- /package/dist/{solidlsp → smart-lsp}/lsp_protocol_handler/server.d.ts +0 -0
- /package/dist/{solidlsp → smart-lsp}/lsp_protocol_handler/server.js +0 -0
- /package/dist/{solidlsp → smart-lsp}/util/subprocess_util.d.ts +0 -0
- /package/dist/{solidlsp → smart-lsp}/util/subprocess_util.js +0 -0
- /package/dist/{solidlsp → smart-lsp}/util/zip.d.ts +0 -0
- /package/dist/{solidlsp → smart-lsp}/util/zip.js +0 -0
|
@@ -1,816 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
class LogMessage {
|
|
4
|
-
constructor(message, toolNames) {
|
|
5
|
-
message = this.escapeHtml(message);
|
|
6
|
-
const logLevel = this.determineLogLevel(message);
|
|
7
|
-
const highlightedMessage = this.highlightToolNames(message, toolNames);
|
|
8
|
-
this.$elem = $('<div>').addClass('log-' + logLevel).html(highlightedMessage + '\n');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
determineLogLevel(message) {
|
|
12
|
-
if (message.startsWith('DEBUG')) {
|
|
13
|
-
return 'debug';
|
|
14
|
-
} else if (message.startsWith('INFO')) {
|
|
15
|
-
return 'info';
|
|
16
|
-
} else if (message.startsWith('WARNING')) {
|
|
17
|
-
return 'warning';
|
|
18
|
-
} else if (message.startsWith('ERROR')) {
|
|
19
|
-
return 'error';
|
|
20
|
-
} else {
|
|
21
|
-
return 'default';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
highlightToolNames(message, toolNames) {
|
|
26
|
-
let highlightedMessage = message;
|
|
27
|
-
toolNames.forEach(function(toolName) {
|
|
28
|
-
const regex = new RegExp('\\b' + toolName + '\\b', 'gi');
|
|
29
|
-
highlightedMessage = highlightedMessage.replace(regex, '<span class="tool-name">' + toolName + '</span>');
|
|
30
|
-
});
|
|
31
|
-
return highlightedMessage;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
escapeHtml (convertString) {
|
|
35
|
-
if (typeof convertString !== 'string') return convertString;
|
|
36
|
-
|
|
37
|
-
const patterns = {
|
|
38
|
-
'<' : '<',
|
|
39
|
-
'>' : '>',
|
|
40
|
-
'&' : '&',
|
|
41
|
-
'"' : '"',
|
|
42
|
-
'\'' : ''',
|
|
43
|
-
'`' : '`'
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return convertString.replace(/[<>&"'`]/g, match => patterns[match]);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class Dashboard {
|
|
51
|
-
constructor() {
|
|
52
|
-
let self = this;
|
|
53
|
-
|
|
54
|
-
this.toolNames = [];
|
|
55
|
-
this.currentMaxIdx = -1;
|
|
56
|
-
this.pollInterval = null;
|
|
57
|
-
this.failureCount = 0;
|
|
58
|
-
this.useStreaming = false;
|
|
59
|
-
this.eventSource = null;
|
|
60
|
-
this.$logContainer = $('#log-container');
|
|
61
|
-
this.$errorContainer = $('#error-container');
|
|
62
|
-
this.$loadButton = $('#load-logs');
|
|
63
|
-
this.$shutdownButton = $('#shutdown');
|
|
64
|
-
this.$toggleStats = $('#toggle-stats');
|
|
65
|
-
this.$statsSection = $('#stats-section');
|
|
66
|
-
this.$refreshStats = $('#refresh-stats');
|
|
67
|
-
this.$clearStats = $('#clear-stats');
|
|
68
|
-
this.$themeToggle = $('#theme-toggle');
|
|
69
|
-
this.$themeIcon = $('#theme-icon');
|
|
70
|
-
this.$themeText = $('#theme-text');
|
|
71
|
-
this.$toolList = $('#tool-list');
|
|
72
|
-
|
|
73
|
-
this.updateToolList();
|
|
74
|
-
|
|
75
|
-
this.countChart = null;
|
|
76
|
-
this.tokensChart = null;
|
|
77
|
-
this.inputChart = null;
|
|
78
|
-
this.outputChart = null;
|
|
79
|
-
|
|
80
|
-
// register event handlers
|
|
81
|
-
this.$loadButton.click(this.loadLogs.bind(this));
|
|
82
|
-
this.$shutdownButton.click(this.shutdown.bind(this));
|
|
83
|
-
this.$toggleStats.click(this.toggleStats.bind(this));
|
|
84
|
-
this.$refreshStats.click(this.loadStats.bind(this));
|
|
85
|
-
this.$clearStats.click(this.clearStats.bind(this));
|
|
86
|
-
this.$themeToggle.click(this.toggleTheme.bind(this));
|
|
87
|
-
|
|
88
|
-
// initialize theme
|
|
89
|
-
this.initializeTheme();
|
|
90
|
-
|
|
91
|
-
// initialize the application
|
|
92
|
-
this.loadToolNames().then(function() {
|
|
93
|
-
if (!self.setupLogStreaming()) {
|
|
94
|
-
self.loadLogs();
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
displayLogMessage(message) {
|
|
100
|
-
$('#log-container').append(new LogMessage(message, this.toolNames).$elem);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
updateToolList() {
|
|
104
|
-
if (!this.$toolList) return;
|
|
105
|
-
if (!this.toolNames || this.toolNames.length === 0) {
|
|
106
|
-
this.$toolList.text('Tools: なし');
|
|
107
|
-
} else {
|
|
108
|
-
this.$toolList.text('Tools: ' + this.toolNames.join(', '));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
loadToolNames() {
|
|
113
|
-
let self = this;
|
|
114
|
-
return $.ajax({
|
|
115
|
-
url: '/get_tool_names',
|
|
116
|
-
type: 'GET',
|
|
117
|
-
success: function(response) {
|
|
118
|
-
self.toolNames = response.tool_names || response.toolNames || [];
|
|
119
|
-
self.updateToolList();
|
|
120
|
-
console.log('Loaded tool names:', self.toolNames);
|
|
121
|
-
},
|
|
122
|
-
error: function(xhr, status, error) {
|
|
123
|
-
console.error('Error loading tool names:', error);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
setupLogStreaming() {
|
|
129
|
-
if (!window.EventSource) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
this.eventSource = new EventSource('/log_stream');
|
|
135
|
-
} catch (error) {
|
|
136
|
-
console.error('EventSource init failed:', error);
|
|
137
|
-
this.eventSource = null;
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const source = this.eventSource;
|
|
142
|
-
let initialized = false;
|
|
143
|
-
|
|
144
|
-
source.addEventListener('open', () => {
|
|
145
|
-
this.useStreaming = true;
|
|
146
|
-
if (this.pollInterval) {
|
|
147
|
-
clearInterval(this.pollInterval);
|
|
148
|
-
this.pollInterval = null;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
source.addEventListener('history', (event) => {
|
|
153
|
-
initialized = true;
|
|
154
|
-
this.useStreaming = true;
|
|
155
|
-
const payload = this.safeParse(event.data);
|
|
156
|
-
if (payload) {
|
|
157
|
-
this.applyLogHistory(payload);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
source.addEventListener('log', (event) => {
|
|
162
|
-
const payload = this.safeParse(event.data);
|
|
163
|
-
if (payload) {
|
|
164
|
-
this.handleStreamedLog(payload);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
source.addEventListener('toolNames', (event) => {
|
|
169
|
-
const payload = this.safeParse(event.data);
|
|
170
|
-
if (payload) {
|
|
171
|
-
this.toolNames = payload.toolNames || payload.tool_names || [];
|
|
172
|
-
this.updateToolList();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
source.onerror = () => {
|
|
177
|
-
console.error('Log stream encountered an error, falling back to polling.');
|
|
178
|
-
source.close();
|
|
179
|
-
this.eventSource = null;
|
|
180
|
-
this.useStreaming = false;
|
|
181
|
-
if (this.pollInterval) {
|
|
182
|
-
clearInterval(this.pollInterval);
|
|
183
|
-
this.pollInterval = null;
|
|
184
|
-
}
|
|
185
|
-
if (!initialized) {
|
|
186
|
-
this.loadLogs();
|
|
187
|
-
} else {
|
|
188
|
-
this.startPeriodicPolling();
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
applyLogHistory(payload) {
|
|
196
|
-
const messages = payload.messages || [];
|
|
197
|
-
const maxIdx = typeof payload.max_idx === 'number' ? payload.max_idx : payload.maxIdx;
|
|
198
|
-
const activeProject = payload.active_project !== undefined ? payload.active_project : payload.activeProject;
|
|
199
|
-
|
|
200
|
-
this.$logContainer.empty();
|
|
201
|
-
if (messages.length === 0) {
|
|
202
|
-
this.$logContainer.html('<div class="loading">No log messages found.</div>');
|
|
203
|
-
this.currentMaxIdx = typeof maxIdx === 'number' ? maxIdx : -1;
|
|
204
|
-
} else {
|
|
205
|
-
messages.forEach((message) => this.displayLogMessage(message));
|
|
206
|
-
const logContainer = this.$logContainer[0];
|
|
207
|
-
if (logContainer) {
|
|
208
|
-
logContainer.scrollTop = logContainer.scrollHeight;
|
|
209
|
-
}
|
|
210
|
-
this.currentMaxIdx = typeof maxIdx === 'number' ? maxIdx : messages.length - 1;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (activeProject !== undefined) {
|
|
214
|
-
this.updateTitle(activeProject);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
handleStreamedLog(payload) {
|
|
219
|
-
if (!payload || !payload.message) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const logContainer = this.$logContainer[0];
|
|
224
|
-
let wasAtBottom = false;
|
|
225
|
-
if (logContainer) {
|
|
226
|
-
wasAtBottom = (logContainer.scrollTop + logContainer.clientHeight) >= (logContainer.scrollHeight - 10);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
this.displayLogMessage(payload.message);
|
|
230
|
-
|
|
231
|
-
const idx = typeof payload.idx === 'number' ? payload.idx : this.currentMaxIdx + 1;
|
|
232
|
-
if (typeof idx === 'number') {
|
|
233
|
-
this.currentMaxIdx = Math.max(this.currentMaxIdx, idx);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (payload.activeProject !== undefined) {
|
|
237
|
-
this.updateTitle(payload.activeProject);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (wasAtBottom && logContainer) {
|
|
241
|
-
logContainer.scrollTop = logContainer.scrollHeight;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
safeParse(data) {
|
|
246
|
-
try {
|
|
247
|
-
return JSON.parse(data);
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.error('Failed to parse dashboard event payload:', error);
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
updateTitle(activeProject) {
|
|
255
|
-
document.title = activeProject ? `${activeProject} – Smart Edit Dashboard` : 'Smart Edit Dashboard';
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
loadLogs() {
|
|
259
|
-
console.log("Loading logs");
|
|
260
|
-
let self = this;
|
|
261
|
-
|
|
262
|
-
// Disable button and show loading state
|
|
263
|
-
self.$loadButton.prop('disabled', true).text('Loading...');
|
|
264
|
-
self.$errorContainer.empty();
|
|
265
|
-
|
|
266
|
-
// Make API call
|
|
267
|
-
$.ajax({
|
|
268
|
-
url: '/get_log_messages',
|
|
269
|
-
type: 'POST',
|
|
270
|
-
contentType: 'application/json',
|
|
271
|
-
data: JSON.stringify({
|
|
272
|
-
start_idx: 0
|
|
273
|
-
}),
|
|
274
|
-
success: function(response) {
|
|
275
|
-
// Clear existing logs
|
|
276
|
-
self.$logContainer.empty();
|
|
277
|
-
|
|
278
|
-
// Update max_idx
|
|
279
|
-
self.currentMaxIdx = response.max_idx || -1;
|
|
280
|
-
|
|
281
|
-
// Display each log message
|
|
282
|
-
if (response.messages && response.messages.length > 0) {
|
|
283
|
-
response.messages.forEach(function(message) {
|
|
284
|
-
self.displayLogMessage(message);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// Auto-scroll to bottom
|
|
288
|
-
const logContainer = $('#log-container')[0];
|
|
289
|
-
logContainer.scrollTop = logContainer.scrollHeight;
|
|
290
|
-
} else {
|
|
291
|
-
$('#log-container').html('<div class="loading">No log messages found.</div>');
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
self.updateTitle(response.active_project);
|
|
295
|
-
|
|
296
|
-
// Start periodic polling for new logs when streaming is unavailable
|
|
297
|
-
if (!self.useStreaming) {
|
|
298
|
-
self.startPeriodicPolling();
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
error: function(xhr, status, error) {
|
|
302
|
-
console.error('Error loading logs:', error);
|
|
303
|
-
self.$errorContainer.html('<div class="error-message">Error loading logs: ' +
|
|
304
|
-
(xhr.responseJSON ? xhr.responseJSON.detail : error) + '</div>');
|
|
305
|
-
},
|
|
306
|
-
complete: function() {
|
|
307
|
-
// Re-enable button
|
|
308
|
-
self.$loadButton.prop('disabled', false).text('Reload Log');
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
pollForNewLogs() {
|
|
314
|
-
let self = this;
|
|
315
|
-
console.log("Polling logs", this.currentMaxIdx);
|
|
316
|
-
$.ajax({
|
|
317
|
-
url: '/get_log_messages',
|
|
318
|
-
type: 'POST',
|
|
319
|
-
contentType: 'application/json',
|
|
320
|
-
data: JSON.stringify({
|
|
321
|
-
start_idx: self.currentMaxIdx + 1
|
|
322
|
-
}),
|
|
323
|
-
success: function(response) {
|
|
324
|
-
self.failureCount = 0;
|
|
325
|
-
// Only append new messages if we have any
|
|
326
|
-
if (response.messages && response.messages.length > 0) {
|
|
327
|
-
let wasAtBottom = false;
|
|
328
|
-
const logContainer = $('#log-container')[0];
|
|
329
|
-
|
|
330
|
-
// Check if user was at the bottom before adding new logs
|
|
331
|
-
if (logContainer.scrollHeight > 0) {
|
|
332
|
-
wasAtBottom = (logContainer.scrollTop + logContainer.clientHeight) >= (logContainer.scrollHeight - 10);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Append new messages
|
|
336
|
-
response.messages.forEach(function(message) {
|
|
337
|
-
self.displayLogMessage(message);
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// Update max_idx
|
|
341
|
-
self.currentMaxIdx = response.max_idx || self.currentMaxIdx;
|
|
342
|
-
|
|
343
|
-
// Auto-scroll to bottom if user was already at bottom
|
|
344
|
-
if (wasAtBottom) {
|
|
345
|
-
logContainer.scrollTop = logContainer.scrollHeight;
|
|
346
|
-
}
|
|
347
|
-
} else {
|
|
348
|
-
// Update max_idx even if no new messages
|
|
349
|
-
self.currentMaxIdx = response.max_idx || self.currentMaxIdx;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Update window title with active project
|
|
353
|
-
self.updateTitle(response.active_project);
|
|
354
|
-
},
|
|
355
|
-
error: function(xhr, status, error) {
|
|
356
|
-
console.error('Error polling for new logs:', error);
|
|
357
|
-
self.failureCount++;
|
|
358
|
-
if (self.failureCount >= 3) {
|
|
359
|
-
console.log('Server appears to be down, closing tab');
|
|
360
|
-
window.close();
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
startPeriodicPolling() {
|
|
367
|
-
if (this.useStreaming) {
|
|
368
|
-
if (this.pollInterval) {
|
|
369
|
-
clearInterval(this.pollInterval);
|
|
370
|
-
this.pollInterval = null;
|
|
371
|
-
}
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
// Clear any existing interval
|
|
375
|
-
if (this.pollInterval) {
|
|
376
|
-
clearInterval(this.pollInterval);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Start polling every second (1000ms)
|
|
380
|
-
this.pollInterval = setInterval(this.pollForNewLogs.bind(this), 1000);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
toggleStats() {
|
|
384
|
-
if (this.$statsSection.is(':visible')) {
|
|
385
|
-
this.$statsSection.hide();
|
|
386
|
-
this.$toggleStats.text('Show Stats');
|
|
387
|
-
} else {
|
|
388
|
-
this.$statsSection.show();
|
|
389
|
-
this.$toggleStats.text('Hide Stats');
|
|
390
|
-
this.loadStats();
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
loadStats() {
|
|
395
|
-
let self = this;
|
|
396
|
-
$.when(
|
|
397
|
-
$.ajax({ url: '/get_tool_stats', type: 'GET' }),
|
|
398
|
-
$.ajax({ url: '/get_token_count_estimator_name', type: 'GET' })
|
|
399
|
-
).done(function(statsResp, estimatorResp) {
|
|
400
|
-
const stats = statsResp[0].stats;
|
|
401
|
-
const tokenCountEstimatorName = estimatorResp[0].token_count_estimator_name;
|
|
402
|
-
self.displayStats(stats, tokenCountEstimatorName);
|
|
403
|
-
}).fail(function() {
|
|
404
|
-
console.error('Error loading stats or estimator name');
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
clearStats() {
|
|
410
|
-
let self = this;
|
|
411
|
-
$.ajax({
|
|
412
|
-
url: '/clear_tool_stats',
|
|
413
|
-
type: 'POST',
|
|
414
|
-
success: function() {
|
|
415
|
-
self.loadStats();
|
|
416
|
-
},
|
|
417
|
-
error: function(xhr, status, error) {
|
|
418
|
-
console.error('Error clearing stats:', error);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
displayStats(stats, tokenCountEstimatorName) {
|
|
424
|
-
const names = Object.keys(stats);
|
|
425
|
-
// If no stats collected
|
|
426
|
-
if (names.length === 0) {
|
|
427
|
-
// hide summary, charts, estimator name
|
|
428
|
-
$('#stats-summary').hide();
|
|
429
|
-
$('#estimator-name').hide();
|
|
430
|
-
$('.charts-container').hide();
|
|
431
|
-
// show no-stats message
|
|
432
|
-
$('#no-stats-message').show();
|
|
433
|
-
return;
|
|
434
|
-
} else {
|
|
435
|
-
// Ensure everything is visible
|
|
436
|
-
$('#estimator-name').show();
|
|
437
|
-
$('#stats-summary').show();
|
|
438
|
-
$('.charts-container').show();
|
|
439
|
-
$('#no-stats-message').hide();
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
$('#estimator-name').html(`<strong>Token count estimator:</strong> ${tokenCountEstimatorName}`);
|
|
443
|
-
|
|
444
|
-
const counts = names.map(n => stats[n].num_times_called);
|
|
445
|
-
const inputTokens = names.map(n => stats[n].input_tokens);
|
|
446
|
-
const outputTokens = names.map(n => stats[n].output_tokens);
|
|
447
|
-
const totalTokens = names.map(n => stats[n].input_tokens + stats[n].output_tokens);
|
|
448
|
-
|
|
449
|
-
// Calculate totals for summary table
|
|
450
|
-
const totalCalls = counts.reduce((sum, count) => sum + count, 0);
|
|
451
|
-
const totalInputTokens = inputTokens.reduce((sum, tokens) => sum + tokens, 0);
|
|
452
|
-
const totalOutputTokens = outputTokens.reduce((sum, tokens) => sum + tokens, 0);
|
|
453
|
-
|
|
454
|
-
// Generate consistent colors for tools
|
|
455
|
-
const colors = this.generateColors(names.length);
|
|
456
|
-
|
|
457
|
-
const countCtx = document.getElementById('count-chart');
|
|
458
|
-
const tokensCtx = document.getElementById('tokens-chart');
|
|
459
|
-
const inputCtx = document.getElementById('input-chart');
|
|
460
|
-
const outputCtx = document.getElementById('output-chart');
|
|
461
|
-
|
|
462
|
-
if (this.countChart) this.countChart.destroy();
|
|
463
|
-
if (this.tokensChart) this.tokensChart.destroy();
|
|
464
|
-
if (this.inputChart) this.inputChart.destroy();
|
|
465
|
-
if (this.outputChart) this.outputChart.destroy();
|
|
466
|
-
|
|
467
|
-
// Update summary table
|
|
468
|
-
this.updateSummaryTable(totalCalls, totalInputTokens, totalOutputTokens);
|
|
469
|
-
|
|
470
|
-
// Register datalabels plugin
|
|
471
|
-
Chart.register(ChartDataLabels);
|
|
472
|
-
|
|
473
|
-
// Get theme-aware colors
|
|
474
|
-
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
|
475
|
-
const textColor = isDark ? '#ffffff' : '#000000';
|
|
476
|
-
const gridColor = isDark ? '#444' : '#ddd';
|
|
477
|
-
|
|
478
|
-
// Tool calls pie chart
|
|
479
|
-
this.countChart = new Chart(countCtx, {
|
|
480
|
-
type: 'pie',
|
|
481
|
-
data: {
|
|
482
|
-
labels: names,
|
|
483
|
-
datasets: [{
|
|
484
|
-
data: counts,
|
|
485
|
-
backgroundColor: colors
|
|
486
|
-
}]
|
|
487
|
-
},
|
|
488
|
-
options: {
|
|
489
|
-
plugins: {
|
|
490
|
-
legend: {
|
|
491
|
-
display: true,
|
|
492
|
-
labels: {
|
|
493
|
-
color: textColor
|
|
494
|
-
}
|
|
495
|
-
},
|
|
496
|
-
datalabels: {
|
|
497
|
-
display: true,
|
|
498
|
-
color: 'white',
|
|
499
|
-
font: { weight: 'bold' },
|
|
500
|
-
formatter: (value) => value
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
// Input tokens pie chart
|
|
507
|
-
this.inputChart = new Chart(inputCtx, {
|
|
508
|
-
type: 'pie',
|
|
509
|
-
data: {
|
|
510
|
-
labels: names,
|
|
511
|
-
datasets: [{
|
|
512
|
-
data: inputTokens,
|
|
513
|
-
backgroundColor: colors
|
|
514
|
-
}]
|
|
515
|
-
},
|
|
516
|
-
options: {
|
|
517
|
-
plugins: {
|
|
518
|
-
legend: {
|
|
519
|
-
display: true,
|
|
520
|
-
labels: {
|
|
521
|
-
color: textColor
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
datalabels: {
|
|
525
|
-
display: true,
|
|
526
|
-
color: 'white',
|
|
527
|
-
font: { weight: 'bold' },
|
|
528
|
-
formatter: (value) => value
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
// Output tokens pie chart
|
|
535
|
-
this.outputChart = new Chart(outputCtx, {
|
|
536
|
-
type: 'pie',
|
|
537
|
-
data: {
|
|
538
|
-
labels: names,
|
|
539
|
-
datasets: [{
|
|
540
|
-
data: outputTokens,
|
|
541
|
-
backgroundColor: colors
|
|
542
|
-
}]
|
|
543
|
-
},
|
|
544
|
-
options: {
|
|
545
|
-
plugins: {
|
|
546
|
-
legend: {
|
|
547
|
-
display: true,
|
|
548
|
-
labels: {
|
|
549
|
-
color: textColor
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
datalabels: {
|
|
553
|
-
display: true,
|
|
554
|
-
color: 'white',
|
|
555
|
-
font: { weight: 'bold' },
|
|
556
|
-
formatter: (value) => value
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
// Combined input/output tokens bar chart
|
|
563
|
-
this.tokensChart = new Chart(tokensCtx, {
|
|
564
|
-
type: 'bar',
|
|
565
|
-
data: {
|
|
566
|
-
labels: names,
|
|
567
|
-
datasets: [
|
|
568
|
-
{
|
|
569
|
-
label: 'Input Tokens',
|
|
570
|
-
data: inputTokens,
|
|
571
|
-
backgroundColor: colors.map(color => color + '80'), // Semi-transparent
|
|
572
|
-
borderColor: colors,
|
|
573
|
-
borderWidth: 2,
|
|
574
|
-
borderSkipped: false,
|
|
575
|
-
yAxisID: 'y'
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
label: 'Output Tokens',
|
|
579
|
-
data: outputTokens,
|
|
580
|
-
backgroundColor: colors,
|
|
581
|
-
yAxisID: 'y1'
|
|
582
|
-
}
|
|
583
|
-
]
|
|
584
|
-
},
|
|
585
|
-
options: {
|
|
586
|
-
responsive: true,
|
|
587
|
-
plugins: {
|
|
588
|
-
legend: {
|
|
589
|
-
labels: {
|
|
590
|
-
color: textColor
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
scales: {
|
|
595
|
-
x: {
|
|
596
|
-
ticks: {
|
|
597
|
-
color: textColor
|
|
598
|
-
},
|
|
599
|
-
grid: {
|
|
600
|
-
color: gridColor
|
|
601
|
-
}
|
|
602
|
-
},
|
|
603
|
-
y: {
|
|
604
|
-
type: 'linear',
|
|
605
|
-
display: true,
|
|
606
|
-
position: 'left',
|
|
607
|
-
beginAtZero: true,
|
|
608
|
-
title: {
|
|
609
|
-
display: true,
|
|
610
|
-
text: 'Input Tokens',
|
|
611
|
-
color: textColor
|
|
612
|
-
},
|
|
613
|
-
ticks: {
|
|
614
|
-
color: textColor
|
|
615
|
-
},
|
|
616
|
-
grid: {
|
|
617
|
-
color: gridColor
|
|
618
|
-
}
|
|
619
|
-
},
|
|
620
|
-
y1: {
|
|
621
|
-
type: 'linear',
|
|
622
|
-
display: true,
|
|
623
|
-
position: 'right',
|
|
624
|
-
beginAtZero: true,
|
|
625
|
-
title: {
|
|
626
|
-
display: true,
|
|
627
|
-
text: 'Output Tokens',
|
|
628
|
-
color: textColor
|
|
629
|
-
},
|
|
630
|
-
ticks: {
|
|
631
|
-
color: textColor
|
|
632
|
-
},
|
|
633
|
-
grid: {
|
|
634
|
-
drawOnChartArea: false,
|
|
635
|
-
color: gridColor
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
generateColors(count) {
|
|
644
|
-
const palette = [
|
|
645
|
-
'#101010', '#1f1f1f', '#2e2e2e', '#3d3d3d', '#4c4c4c',
|
|
646
|
-
'#5b5b5b', '#6a6a6a', '#797979', '#888888', '#979797',
|
|
647
|
-
'#a6a6a6', '#b5b5b5', '#c4c4c4', '#d3d3d3', '#e2e2e2'
|
|
648
|
-
];
|
|
649
|
-
return Array.from({ length: count }, (_, i) => palette[i % palette.length]);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
updateSummaryTable(totalCalls, totalInputTokens, totalOutputTokens) {
|
|
653
|
-
const tableHtml = `
|
|
654
|
-
<table class="stats-summary">
|
|
655
|
-
<tr><th>Metric</th><th>Total</th></tr>
|
|
656
|
-
<tr><td>Tool Calls</td><td>${totalCalls}</td></tr>
|
|
657
|
-
<tr><td>Input Tokens</td><td>${totalInputTokens}</td></tr>
|
|
658
|
-
<tr><td>Output Tokens</td><td>${totalOutputTokens}</td></tr>
|
|
659
|
-
<tr><td>Total Tokens</td><td>${totalInputTokens + totalOutputTokens}</td></tr>
|
|
660
|
-
</table>
|
|
661
|
-
`;
|
|
662
|
-
$('#stats-summary').html(tableHtml);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
initializeTheme() {
|
|
666
|
-
// Check if user has manually set a theme preference
|
|
667
|
-
const savedTheme = localStorage.getItem('serena-theme');
|
|
668
|
-
|
|
669
|
-
if (savedTheme) {
|
|
670
|
-
// User has manually set a preference, use it
|
|
671
|
-
this.setTheme(savedTheme);
|
|
672
|
-
} else {
|
|
673
|
-
// No manual preference, detect system color scheme
|
|
674
|
-
this.detectSystemTheme();
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// Listen for system theme changes
|
|
678
|
-
this.setupSystemThemeListener();
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
detectSystemTheme() {
|
|
682
|
-
// Check if system prefers dark mode
|
|
683
|
-
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
684
|
-
const theme = prefersDark ? 'dark' : 'light';
|
|
685
|
-
this.setTheme(theme);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
setupSystemThemeListener() {
|
|
689
|
-
// Listen for changes in system color scheme
|
|
690
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
691
|
-
|
|
692
|
-
const handleSystemThemeChange = (e) => {
|
|
693
|
-
// Only auto-switch if user hasn't manually set a preference
|
|
694
|
-
const savedTheme = localStorage.getItem('serena-theme');
|
|
695
|
-
if (!savedTheme) {
|
|
696
|
-
const newTheme = e.matches ? 'dark' : 'light';
|
|
697
|
-
this.setTheme(newTheme);
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
// Add listener for system theme changes
|
|
702
|
-
if (mediaQuery.addEventListener) {
|
|
703
|
-
mediaQuery.addEventListener('change', handleSystemThemeChange);
|
|
704
|
-
} else {
|
|
705
|
-
// Fallback for older browsers
|
|
706
|
-
mediaQuery.addListener(handleSystemThemeChange);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
toggleTheme() {
|
|
711
|
-
const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';
|
|
712
|
-
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
|
|
713
|
-
|
|
714
|
-
// When user manually toggles, save their preference
|
|
715
|
-
localStorage.setItem('serena-theme', newTheme);
|
|
716
|
-
this.setTheme(newTheme);
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
setTheme(theme) {
|
|
720
|
-
// Set the theme on the document element
|
|
721
|
-
document.documentElement.setAttribute('data-theme', theme);
|
|
722
|
-
|
|
723
|
-
// Update the toggle button
|
|
724
|
-
if (theme === 'dark') {
|
|
725
|
-
this.$themeIcon.text('☀️');
|
|
726
|
-
this.$themeText.text('Light');
|
|
727
|
-
} else {
|
|
728
|
-
this.$themeIcon.text('🌙');
|
|
729
|
-
this.$themeText.text('Dark');
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// Update the logo based on theme
|
|
733
|
-
this.updateLogo(theme);
|
|
734
|
-
|
|
735
|
-
// Save to localStorage
|
|
736
|
-
localStorage.setItem('serena-theme', theme);
|
|
737
|
-
|
|
738
|
-
// Update charts if they exist
|
|
739
|
-
this.updateChartsTheme();
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
updateLogo(theme) {
|
|
743
|
-
const logoElement = document.getElementById('serena-logo');
|
|
744
|
-
if (logoElement) {
|
|
745
|
-
if (theme === 'dark') {
|
|
746
|
-
logoElement.src = 'serena-logs-dark-mode.png';
|
|
747
|
-
} else {
|
|
748
|
-
logoElement.src = 'serena-logs.png';
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
updateChartsTheme() {
|
|
754
|
-
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
|
755
|
-
const textColor = isDark ? '#ffffff' : '#000000';
|
|
756
|
-
const gridColor = isDark ? '#444' : '#ddd';
|
|
757
|
-
|
|
758
|
-
// Update existing charts
|
|
759
|
-
if (this.countChart) {
|
|
760
|
-
this.countChart.options.scales.x.ticks.color = textColor;
|
|
761
|
-
this.countChart.options.scales.y.ticks.color = textColor;
|
|
762
|
-
this.countChart.options.scales.x.grid.color = gridColor;
|
|
763
|
-
this.countChart.options.scales.y.grid.color = gridColor;
|
|
764
|
-
this.countChart.update();
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
if (this.inputChart) {
|
|
768
|
-
this.inputChart.options.scales.x.ticks.color = textColor;
|
|
769
|
-
this.inputChart.options.scales.y.ticks.color = textColor;
|
|
770
|
-
this.inputChart.options.scales.x.grid.color = gridColor;
|
|
771
|
-
this.inputChart.options.scales.y.grid.color = gridColor;
|
|
772
|
-
this.inputChart.update();
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
if (this.outputChart) {
|
|
776
|
-
this.outputChart.options.scales.x.ticks.color = textColor;
|
|
777
|
-
this.outputChart.options.scales.y.ticks.color = textColor;
|
|
778
|
-
this.outputChart.options.scales.x.grid.color = gridColor;
|
|
779
|
-
this.outputChart.options.scales.y.grid.color = gridColor;
|
|
780
|
-
this.outputChart.update();
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
if (this.tokensChart) {
|
|
784
|
-
this.tokensChart.options.scales.x.ticks.color = textColor;
|
|
785
|
-
this.tokensChart.options.scales.y.ticks.color = textColor;
|
|
786
|
-
this.tokensChart.options.scales.y1.ticks.color = textColor;
|
|
787
|
-
this.tokensChart.options.scales.x.grid.color = gridColor;
|
|
788
|
-
this.tokensChart.options.scales.y.grid.color = gridColor;
|
|
789
|
-
this.tokensChart.options.scales.y1.grid.color = gridColor;
|
|
790
|
-
this.tokensChart.update();
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
shutdown() {
|
|
795
|
-
const self = this;
|
|
796
|
-
const _shutdown = function () {
|
|
797
|
-
console.log("Triggering shutdown");
|
|
798
|
-
$.ajax({
|
|
799
|
-
url: '/shutdown',
|
|
800
|
-
type: "PUT",
|
|
801
|
-
contentType: 'application/json',
|
|
802
|
-
});
|
|
803
|
-
self.$errorContainer.html('<div class="error-message">Shutting down ...</div>')
|
|
804
|
-
setTimeout(function() {
|
|
805
|
-
window.close();
|
|
806
|
-
}, 2000);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
// ask for confirmation using a dialog
|
|
810
|
-
if (confirm("This will fully terminate the Smart Edit server.")) {
|
|
811
|
-
_shutdown();
|
|
812
|
-
} else {
|
|
813
|
-
console.log("Shutdown cancelled");
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|