cmdbox 0.5.3.1__py3-none-any.whl → 0.6.0__py3-none-any.whl
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.
Potentially problematic release.
This version of cmdbox might be problematic. Click here for more details.
- cmdbox/app/auth/__init__.py +0 -0
- cmdbox/app/auth/azure_signin.py +38 -0
- cmdbox/app/auth/azure_signin_saml.py +12 -0
- cmdbox/app/auth/github_signin.py +38 -0
- cmdbox/app/auth/google_signin.py +32 -0
- cmdbox/app/auth/signin.py +490 -287
- cmdbox/app/auth/signin_saml.py +61 -0
- cmdbox/app/common.py +48 -3
- cmdbox/app/edge.py +182 -213
- cmdbox/app/edge_tool.py +177 -0
- cmdbox/app/feature.py +10 -10
- cmdbox/app/features/cli/agent_base.py +477 -0
- cmdbox/app/features/cli/audit_base.py +1 -1
- cmdbox/app/features/cli/cmdbox_audit_search.py +24 -1
- cmdbox/app/features/cli/cmdbox_client_file_download.py +1 -1
- cmdbox/app/features/cli/cmdbox_cmd_list.py +105 -0
- cmdbox/app/features/cli/cmdbox_cmd_load.py +104 -0
- cmdbox/app/features/cli/cmdbox_edge_config.py +21 -7
- cmdbox/app/features/cli/cmdbox_edge_start.py +1 -1
- cmdbox/app/features/cli/cmdbox_gui_start.py +9 -132
- cmdbox/app/features/cli/cmdbox_gui_stop.py +4 -21
- cmdbox/app/features/cli/cmdbox_server_start.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_apikey_add.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_apikey_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_genpass.py +0 -3
- cmdbox/app/features/cli/cmdbox_web_group_add.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_edit.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_group_list.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_start.py +119 -104
- cmdbox/app/features/cli/cmdbox_web_stop.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_user_add.py +4 -4
- cmdbox/app/features/cli/cmdbox_web_user_del.py +1 -1
- cmdbox/app/features/cli/cmdbox_web_user_edit.py +4 -4
- cmdbox/app/features/cli/cmdbox_web_user_list.py +1 -1
- cmdbox/app/features/web/cmdbox_web_agent.py +250 -0
- cmdbox/app/features/web/cmdbox_web_do_signin.py +79 -103
- cmdbox/app/features/web/cmdbox_web_exec_cmd.py +8 -3
- cmdbox/app/features/web/cmdbox_web_signin.py +26 -4
- cmdbox/app/features/web/cmdbox_web_users.py +2 -0
- cmdbox/app/options.py +55 -2
- cmdbox/app/web.py +155 -27
- cmdbox/extensions/features.yml +18 -0
- cmdbox/extensions/sample_project/sample/app/features/cli/__init__.py +0 -0
- cmdbox/extensions/sample_project/sample/app/features/web/__init__.py +0 -0
- cmdbox/extensions/sample_project/sample/extensions/features.yml +23 -0
- cmdbox/extensions/sample_project/sample/extensions/user_list.yml +40 -6
- cmdbox/extensions/user_list.yml +37 -6
- cmdbox/licenses/{LICENSE.starlette.0.41.3(BSD License).txt → LICENSE.Authlib.1.5.2(BSD License).txt } +3 -1
- cmdbox/licenses/{LICENSE.pydantic_core.2.33.0(MIT License).txt → LICENSE.Deprecated.1.2.18(MIT License).txt } +2 -2
- cmdbox/licenses/{LICENSE.more-itertools.10.6.0(MIT License).txt → LICENSE.SQLAlchemy.2.0.40(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.aiohttp.3.11.18(Apache Software License).txt +13 -0
- cmdbox/licenses/LICENSE.aiosignal.1.3.2(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.async-timeout.5.0.1(Apache Software License).txt +13 -0
- cmdbox/licenses/{LICENSE.watchfiles.1.0.0(MIT License).txt → LICENSE.attrs.25.3.0(UNKNOWN).txt} +1 -1
- cmdbox/licenses/{LICENSE.anyio.4.6.2.post1(MIT License).txt → LICENSE.cachetools.5.5.2(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.distro.1.9.0(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.pydantic_core.2.33.1(MIT License).txt → LICENSE.docstring_parser.0.16(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.filelock.3.18.0(The Unlicense (Unlicense)).txt +24 -0
- cmdbox/licenses/LICENSE.frozenlist.1.6.0(Apache-2.0).txt +201 -0
- cmdbox/licenses/{LICENSE.starlette.0.46.1(BSD License).txt → LICENSE.fsspec.2025.3.2(BSD License).txt } +3 -1
- cmdbox/licenses/{LICENSE.argcomplete.3.6.1(Apache Software License).txt → LICENSE.google-adk.0.5.0(Apache Software License).txt } +25 -0
- cmdbox/licenses/LICENSE.google-api-python-client.2.169.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-auth-httplib2.0.2.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-auth.2.40.1(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.google-cloud-aiplatform.1.92.0(Apache 2.0).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-bigquery.3.31.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-core.2.4.3(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-resource-manager.1.14.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-secret-manager.2.23.3(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-speech.2.32.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-storage.2.19.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-cloud-trace.1.16.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-crc32c.1.7.1(Apache 2.0).txt +202 -0
- cmdbox/licenses/LICENSE.google-genai.1.14.0(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.google-resumable-media.2.7.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.googleapis-common-protos.1.70.0(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.fastapi.0.115.5(MIT License).txt → LICENSE.graphviz.0.20.3(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.grpc-google-iam-v1.0.14.2(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.grpcio-status.1.71.0(Apache Software License).txt +610 -0
- cmdbox/licenses/LICENSE.grpcio.1.71.0(Apache Software License).txt +610 -0
- cmdbox/licenses/{LICENSE.uvicorn.0.34.0(BSD License).txt → LICENSE.httpcore.1.0.9(BSD License).txt } +1 -1
- cmdbox/licenses/LICENSE.httplib2.0.22.0(MIT License).txt +23 -0
- cmdbox/licenses/{LICENSE.tomli.2.1.0(MIT License).txt → LICENSE.httpx-sse.0.4.0(MIT).txt} +1 -1
- cmdbox/licenses/LICENSE.httpx.0.28.1(BSD License).txt +12 -0
- cmdbox/licenses/LICENSE.huggingface-hub.0.31.1(Apache Software License).txt +201 -0
- cmdbox/licenses/{LICENSE.charset-normalizer.3.4.0(MIT License).txt → LICENSE.jsonschema-specifications.2025.4.1(UNKNOWN).txt} +5 -7
- cmdbox/licenses/LICENSE.jsonschema.4.23.0(MIT License).txt +19 -0
- cmdbox/licenses/{LICENSE.pkginfo.1.10.0(MIT License).txt → LICENSE.litellm.1.69.0(MIT License).txt } +6 -1
- cmdbox/licenses/{LICENSE.redis.5.2.1(MIT License).txt → LICENSE.mcp.1.8.0(MIT License).txt } +1 -1
- cmdbox/licenses/LICENSE.multidict.6.4.3(Apache Software License).txt +13 -0
- cmdbox/licenses/{LICENSE.argcomplete.3.5.1(Apache Software License).txt → LICENSE.openai.1.75.0(Apache Software License).txt } +25 -1
- cmdbox/licenses/LICENSE.opentelemetry-api.1.33.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-exporter-gcp-trace.1.9.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-resourcedetector-gcp.1.9.0a0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-sdk.1.33.0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.opentelemetry-semantic-conventions.0.54b0(Apache Software License).txt +201 -0
- cmdbox/licenses/LICENSE.propcache.0.3.1(Apache Software License).txt +202 -0
- cmdbox/licenses/LICENSE.proto-plus.1.26.1(Apache Software License).txt +202 -0
- cmdbox/licenses/{LICENSE.Pygments.2.18.0(BSD License).txt → LICENSE.protobuf.5.29.4(3-Clause BSD License).txt } +15 -8
- cmdbox/licenses/LICENSE.pyasn1.0.6.1(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.pyasn1_modules.0.4.2(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.pydantic-settings.2.9.1(MIT License).txt +21 -0
- cmdbox/licenses/{LICENSE.gevent.25.4.1(MIT).txt → LICENSE.pyparsing.3.2.3(MIT License).txt } +5 -12
- cmdbox/licenses/LICENSE.python-dateutil.2.9.0.post0(Apache Software License; BSD License).txt +54 -0
- cmdbox/licenses/LICENSE.referencing.0.36.2(UNKNOWN).txt +19 -0
- cmdbox/licenses/LICENSE.regex.2024.11.6(Apache Software License).txt +208 -0
- cmdbox/licenses/LICENSE.rpds-py.0.24.0(MIT).txt +19 -0
- cmdbox/licenses/{LICENSE.python-multipart.0.0.17(Apache Software License).txt → LICENSE.rsa.4.9.1(Apache Software License).txt } +1 -2
- cmdbox/licenses/{LICENSE.sphinx-intl.2.3.0(BSD License).txt → LICENSE.shapely.2.1.0(BSD License).txt } +6 -2
- cmdbox/licenses/LICENSE.sse-starlette.2.3.4(BSD License).txt +27 -0
- cmdbox/licenses/LICENSE.tiktoken.0.9.0(MIT License).txt +21 -0
- cmdbox/licenses/LICENSE.tokenizers.0.21.1(Apache Software License).txt +1 -0
- cmdbox/licenses/{LICENSE.six.1.16.0(MIT License).txt → LICENSE.tqdm.4.67.1(MIT License; Mozilla Public License 2.0 (MPL 2.0)).txt } +32 -1
- cmdbox/licenses/{LICENSE.rich.13.9.4(MIT License).txt → LICENSE.tzlocal.5.3.1(MIT License).txt } +3 -3
- cmdbox/licenses/LICENSE.uritemplate.4.1.1(Apache Software License; BSD License).txt +3 -0
- cmdbox/licenses/LICENSE.wrapt.1.17.2(BSD License).txt +24 -0
- cmdbox/licenses/LICENSE.yarl.1.20.0(Apache Software License).txt +202 -0
- cmdbox/licenses/files.txt +111 -17
- cmdbox/logconf_agent.yml +38 -0
- cmdbox/logconf_audit.yml +13 -5
- cmdbox/logconf_client.yml +13 -5
- cmdbox/logconf_cmdbox.yml +13 -5
- cmdbox/logconf_edge.yml +13 -5
- cmdbox/logconf_gui.yml +13 -5
- cmdbox/logconf_server.yml +13 -5
- cmdbox/logconf_web.yml +13 -5
- cmdbox/version.py +3 -2
- cmdbox/web/agent.html +263 -0
- cmdbox/web/assets/cmdbox/agent.js +335 -0
- cmdbox/web/assets/cmdbox/common.js +1111 -1020
- cmdbox/web/assets/cmdbox/signin.js +16 -3
- cmdbox/web/assets/cmdbox/users.js +1 -1
- cmdbox/web/assets/filer/filer.js +4 -2
- cmdbox/web/signin.html +10 -6
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/METADATA +132 -35
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/RECORD +161 -123
- cmdbox/app/features/web/cmdbox_web_load_pin.py +0 -43
- cmdbox/app/features/web/cmdbox_web_save_pin.py +0 -42
- cmdbox/licenses/LICENSE.Jinja2.3.1.4(BSD License).txt +0 -28
- cmdbox/licenses/LICENSE.Sphinx.8.1.3(BSD License).txt +0 -31
- cmdbox/licenses/LICENSE.babel.2.16.0(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.certifi.2025.1.31(Mozilla Public License 2.0 (MPL 2.0)).txt +0 -20
- cmdbox/licenses/LICENSE.click.8.1.8(BSD License).txt +0 -28
- cmdbox/licenses/LICENSE.cryptography.44.0.2(Apache Software License; BSD License).txt +0 -3
- cmdbox/licenses/LICENSE.greenlet.3.2.0(MIT AND Python-2.0).txt +0 -30
- cmdbox/licenses/LICENSE.keyring.25.5.0(MIT License).txt +0 -17
- cmdbox/licenses/LICENSE.numpy.2.2.4(BSD License).txt +0 -950
- cmdbox/licenses/LICENSE.pillow.11.0.0(CMU License (MIT-CMU)).txt +0 -1226
- cmdbox/licenses/LICENSE.pillow.11.1.0(CMU License (MIT-CMU)).txt +0 -1213
- cmdbox/licenses/LICENSE.prettytable.3.12.0(BSD License).txt +0 -30
- cmdbox/licenses/LICENSE.prompt_toolkit.3.0.50(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.psycopg.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt +0 -165
- cmdbox/licenses/LICENSE.pydantic.2.11.1(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.pydantic.2.11.3(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.python-dotenv.1.0.1(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.twine.5.1.1(Apache Software License).txt +0 -174
- cmdbox/licenses/LICENSE.typing_extensions.4.13.0(UNKNOWN).txt +0 -279
- cmdbox/licenses/LICENSE.urllib3.2.2.3(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.urllib3.2.3.0(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.uvicorn.0.34.1(BSD License).txt +0 -27
- cmdbox/licenses/LICENSE.watchfiles.1.0.4(MIT License).txt +0 -21
- cmdbox/licenses/LICENSE.websockets.14.1(BSD License).txt +0 -24
- cmdbox/licenses/LICENSE.zope.interface.7.1.1(Zope Public License).txt +0 -44
- /cmdbox/licenses/{LICENSE.typing_extensions.4.12.2(Python Software Foundation License).txt → LICENSE.aiohappyeyeballs.2.6.1(Python Software Foundation License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.certifi.2024.8.30(Mozilla Public License 2.0 (MPL 2.0)).txt → LICENSE.certifi.2025.4.26(Mozilla Public License 2.0 (MPL 2.0)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.charset-normalizer.3.4.1(MIT License).txt → LICENSE.charset-normalizer.3.4.2(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.click.8.1.7(BSD License).txt → LICENSE.click.8.2.0(UNKNOWN).txt} +0 -0
- /cmdbox/licenses/{LICENSE.cryptography.43.0.3(Apache Software License; BSD License).txt → LICENSE.cryptography.44.0.3(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.gevent.24.11.1(MIT License).txt → LICENSE.gevent.25.4.2(MIT).txt} +0 -0
- /cmdbox/licenses/{LICENSE.importlib_metadata.8.5.0(Apache Software License).txt → LICENSE.google-api-core.2.24.2(Apache Software License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.greenlet.3.1.1(MIT License).txt → LICENSE.greenlet.3.2.2(MIT AND Python-2.0).txt} +0 -0
- /cmdbox/licenses/{LICENSE.h11.0.14.0(MIT License).txt → LICENSE.h11.0.16.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.nh3.0.2.18(MIT).txt → LICENSE.jiter.0.9.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.more-itertools.10.5.0(MIT License).txt → LICENSE.more-itertools.10.7.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.numpy.2.1.3(BSD License).txt → LICENSE.numpy.2.2.5(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.packaging.24.2(Apache Software License; BSD License).txt → LICENSE.packaging.25.0(Apache Software License; BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.psycopg-binary.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt → LICENSE.psycopg-binary.3.2.7(GNU Lesser General Public License v3 (LGPLv3)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.psycopg-pool.3.2.6(GNU Lesser General Public License v3 (LGPLv3)).txt → LICENSE.psycopg.3.2.7(GNU Lesser General Public License v3 (LGPLv3)).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic.2.10.2(MIT License).txt → LICENSE.pydantic.2.11.4(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.pydantic_core.2.27.1(MIT License).txt → LICENSE.pydantic_core.2.33.2(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.redis.5.2.0(MIT License).txt → LICENSE.redis.6.0.0(MIT License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.snowballstemmer.2.2.0(BSD License).txt → LICENSE.snowballstemmer.3.0.1(BSD License).txt} +0 -0
- /cmdbox/licenses/{LICENSE.uvicorn.0.32.1(BSD License).txt → LICENSE.uvicorn.0.34.2(BSD License).txt} +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/LICENSE +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/WHEEL +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/entry_points.txt +0 -0
- {cmdbox-0.5.3.1.dist-info → cmdbox-0.6.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
const agent = {};
|
|
2
|
+
agent.chat_reconnectInterval_handler = null;
|
|
3
|
+
agent.chat_callback_ping_handler = null;
|
|
4
|
+
agent.create_user_message = (messages, msg) => {
|
|
5
|
+
const user_msg_row = $(`<div class="message" style="float:right;"></div>`).appendTo(messages);
|
|
6
|
+
const user_message = $(`<div class="message user-message d-inline-block" style="width:calc(100% - 48px);"></div>`).appendTo(user_msg_row);
|
|
7
|
+
$(`<div class="d-inline-block"></div>`).appendTo(user_message).text(msg);
|
|
8
|
+
$(`<a class="d-inline-block align-top" style="fill:gray;"><svg class="align-top ms-3" width="32" height="32" viewBox="0 0 16 16">`
|
|
9
|
+
+`<use href="#svg_signin_ico"></use></svg></a>`).appendTo(user_msg_row);
|
|
10
|
+
};
|
|
11
|
+
agent.create_agent_message = (messages, message_id) => {
|
|
12
|
+
const bot_message = $(`<div class="message bot-message"></div>`).appendTo(messages);
|
|
13
|
+
$(`<img class="icon-logo align-top me-3" src="${cmdbox.logoicon_src}" width="32" height="32"/>`).appendTo(bot_message);
|
|
14
|
+
const txt = $(`<div id="${message_id}" class="d-inline-block" style="width:calc(100% - 48px);"></div>`).appendTo(bot_message);
|
|
15
|
+
return txt;
|
|
16
|
+
}
|
|
17
|
+
agent.format_agent_message = (container, messages, txt, message) => {
|
|
18
|
+
// メッセージが空の場合は何もしない
|
|
19
|
+
if (!message || message.length <= 0) return;
|
|
20
|
+
txt.html('');
|
|
21
|
+
const regs_start = /```json/s;
|
|
22
|
+
const regs_json = /```json(?!```)+/s;
|
|
23
|
+
const regs_end = /```/s;
|
|
24
|
+
while (message && message.length > 0) {
|
|
25
|
+
try {
|
|
26
|
+
// JSON開始部分を探す
|
|
27
|
+
let start = message.match(regs_start);
|
|
28
|
+
if (!start || start.length < 0) {
|
|
29
|
+
// JSON開始部分が無い場合はそのまま表示
|
|
30
|
+
const msg = message.replace(/\n/g, '<br/>');
|
|
31
|
+
txt.append(msg);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
start = message.substring(0, start.index);
|
|
35
|
+
if (start) txt.append(start.replace(/\n/g, '<br/>'));
|
|
36
|
+
message = message.replace(start+regs_start.source, '');
|
|
37
|
+
|
|
38
|
+
// JSON内容部分を探す
|
|
39
|
+
let jbody = message.match(regs_end);
|
|
40
|
+
if (!jbody || jbody.length < 0) {
|
|
41
|
+
// JSON内容部分が無い場合はそのまま表示
|
|
42
|
+
const msg = message.replace(/\n/g, '<br/>');
|
|
43
|
+
txt.append(msg);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
jbody = message.substring(0, jbody.index);
|
|
47
|
+
jobj = eval(`(${jbody})`);
|
|
48
|
+
message = message.replace(jbody+regs_end.source, '');
|
|
49
|
+
const rand = cmdbox.random_string(16);
|
|
50
|
+
txt.append(`<span id="${rand}"/>`);
|
|
51
|
+
agent.recursive_json_parse(jobj);
|
|
52
|
+
render_result_func(txt.find(`#${rand}`), jobj, 100);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
const msg = message.replace(/\n/g, '<br/>');
|
|
55
|
+
txt.append(msg);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// メッセージ一覧を一番下までスクロール
|
|
60
|
+
container.scrollTop(container.prop('scrollHeight'));
|
|
61
|
+
const msg_width = messages.prop('scrollWidth');
|
|
62
|
+
if (msg_width > 800) {
|
|
63
|
+
// メッセージ一覧の幅が800pxを超えたら、メッセージ一覧の幅を調整
|
|
64
|
+
document.documentElement.style.setProperty('--cmdbox-width', `${msg_width}px`);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
agent.recursive_json_parse = (jobj) => {
|
|
68
|
+
Object.keys(jobj).forEach((key) => {
|
|
69
|
+
if (!jobj[key]) return; // nullやundefinedは無視
|
|
70
|
+
if (typeof jobj[key] === 'function') {
|
|
71
|
+
delete jobj[key]; // 関数は削除
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (typeof jobj[key] === 'string') {
|
|
75
|
+
try {
|
|
76
|
+
const val = eval(`(${jobj[key]})`);
|
|
77
|
+
if (val && typeof val === 'object' && !Array.isArray(val))
|
|
78
|
+
for (const v of Object.values(val))
|
|
79
|
+
if (v && typeof v === 'function') return; // 関数は無視
|
|
80
|
+
else if (val && Array.isArray(val))
|
|
81
|
+
for (const v of val)
|
|
82
|
+
if (v && typeof v === 'function') return; // 関数は無視
|
|
83
|
+
jobj[key] = val;
|
|
84
|
+
agent.recursive_json_parse(jobj[key]);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.debug(`Fail parsing JSON string: ${jobj[key]}`, e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (typeof jobj[key] === 'object' && !Array.isArray(jobj[key])) {
|
|
90
|
+
// オブジェクトの場合は再帰的に処理
|
|
91
|
+
agent.recursive_json_parse(jobj[key]);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
agent.init_form = async () => {
|
|
96
|
+
const container = $('#message_container');
|
|
97
|
+
const histories = $('#histories');
|
|
98
|
+
const messages = $('#messages');
|
|
99
|
+
const ping_interval = 5000; // pingの間隔
|
|
100
|
+
const max_reconnect_count = 60000/ping_interval*1; // 最大再接続回数
|
|
101
|
+
agent.chat_reconnect_count = 0;
|
|
102
|
+
agent.chat = (session_id) => {
|
|
103
|
+
// ws再接続のためのインターバル初期化
|
|
104
|
+
if (agent.chat_reconnectInterval_handler) {
|
|
105
|
+
clearInterval(agent.chat_reconnectInterval_handler);
|
|
106
|
+
}
|
|
107
|
+
// wsのpingのためのインターバル初期化
|
|
108
|
+
if (agent.chat_callback_ping_handler) {
|
|
109
|
+
clearInterval(agent.chat_callback_ping_handler);
|
|
110
|
+
}
|
|
111
|
+
messages.attr('data-session_id', session_id);
|
|
112
|
+
const btn_user_msg = $('#btn_user_msg');
|
|
113
|
+
const user_msg = $('#user_msg');
|
|
114
|
+
let message_id = null;
|
|
115
|
+
btn_user_msg.prop('disabled', true); // 初期状態で送信ボタンを無効化
|
|
116
|
+
// 送信ボタンのクリックイベント
|
|
117
|
+
btn_user_msg.off('click').on('click', async () => {
|
|
118
|
+
const msg = user_msg.val();
|
|
119
|
+
if (msg.length <= 0) return;
|
|
120
|
+
user_msg.val('');
|
|
121
|
+
// 入力内容をユーザーメッセージとして表示
|
|
122
|
+
agent.create_user_message(messages, msg);
|
|
123
|
+
agent.create_history(histories, session_id, msg);
|
|
124
|
+
// エージェント側のメッセージ読込中を表示
|
|
125
|
+
if (!message_id) {
|
|
126
|
+
message_id = cmdbox.random_string(16);
|
|
127
|
+
const txt = agent.create_agent_message(messages, message_id);
|
|
128
|
+
cmdbox.show_loading(txt);
|
|
129
|
+
}
|
|
130
|
+
// メッセージを送信
|
|
131
|
+
ws.send(msg);
|
|
132
|
+
// セッション一覧を再表示
|
|
133
|
+
agent.list_sessions();
|
|
134
|
+
// メッセージ一覧を一番下までスクロール
|
|
135
|
+
container.scrollTop(container.prop('scrollHeight'));
|
|
136
|
+
});
|
|
137
|
+
// ws接続
|
|
138
|
+
const protocol = window.location.protocol.endsWith('s:') ? 'wss' : 'ws';
|
|
139
|
+
const host = window.location.hostname;
|
|
140
|
+
const port = window.location.port;
|
|
141
|
+
const path = window.location.pathname;
|
|
142
|
+
const ws = new WebSocket(`${protocol}://${host}:${port}${path}/chat/ws/${session_id}`);
|
|
143
|
+
// エージェントからのメッセージ受信時の処理
|
|
144
|
+
ws.onmessage = (event) => {
|
|
145
|
+
const packet = JSON.parse(event.data);
|
|
146
|
+
console.log(packet);
|
|
147
|
+
if (packet.turn_complete && packet.turn_complete) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
let txt;
|
|
151
|
+
if (!message_id) {
|
|
152
|
+
// エージェント側の表示枠が無かったら追加
|
|
153
|
+
message_id = cmdbox.random_string(16);
|
|
154
|
+
txt = agent.create_agent_message(messages, message_id);
|
|
155
|
+
} else {
|
|
156
|
+
txt = $(`#${message_id}`);
|
|
157
|
+
}
|
|
158
|
+
txt.html('');
|
|
159
|
+
message_id = null;
|
|
160
|
+
agent.format_agent_message(container, messages, txt, packet.message);
|
|
161
|
+
};
|
|
162
|
+
ws.onopen = () => {
|
|
163
|
+
const ping = () => {ws.send('ping');};
|
|
164
|
+
btn_user_msg.prop('disabled', false);
|
|
165
|
+
agent.chat_callback_ping_handler = setInterval(() => {ping();}, ping_interval);
|
|
166
|
+
};
|
|
167
|
+
ws.onerror = (e) => {
|
|
168
|
+
console.error(`Websocket error: ${e}`);
|
|
169
|
+
clearInterval(agent.chat_callback_ping_handler);
|
|
170
|
+
};
|
|
171
|
+
ws.onclose = () => {
|
|
172
|
+
clearInterval(agent.chat_callback_ping_handler);
|
|
173
|
+
if (agent.chat_reconnect_count >= max_reconnect_count) {
|
|
174
|
+
clearInterval(agent.chat_reconnectInterval_handler);
|
|
175
|
+
cmdbox.message({'error':'Connection to the agent has failed for several minutes. Please reload to resume reconnection.'});
|
|
176
|
+
const rand = cmdbox.random_string(8);
|
|
177
|
+
location.href = `signin/agent?r=${rand}`;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
agent.chat_reconnect_count++;
|
|
181
|
+
agent.chat_reconnectInterval_handler = setInterval(() => {
|
|
182
|
+
agent.chat(session_id);
|
|
183
|
+
}, ping_interval);
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
const user_msg = $('#user_msg');
|
|
187
|
+
user_msg.off('keydown').on('keydown', (e) => {
|
|
188
|
+
// Ctrl+Enterで送信
|
|
189
|
+
if (e.key === 'Enter' && e.ctrlKey) {
|
|
190
|
+
e.preventDefault();
|
|
191
|
+
$('#btn_user_msg').click();
|
|
192
|
+
container.css('height', `calc(100% - ${user_msg.prop('scrollHeight')}px - 42px)`);
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
user_msg.off('input').on('input', (e) => {
|
|
197
|
+
// テキストエリアのリサイズに合わせてメッセージ一覧の高さを調整
|
|
198
|
+
container.css('height', `calc(100% - ${user_msg.prop('scrollHeight')}px - 42px)`);
|
|
199
|
+
});
|
|
200
|
+
const btn_newchat = $('#btn_newchat');
|
|
201
|
+
btn_newchat.off('click').on('click', async () => {
|
|
202
|
+
// メッセージ一覧をクリア
|
|
203
|
+
messages.html('');
|
|
204
|
+
// 新しいセッションを作成
|
|
205
|
+
const session_id = cmdbox.random_string(16);
|
|
206
|
+
agent.chat(session_id);
|
|
207
|
+
});
|
|
208
|
+
// テキストエリアのリサイズに合わせてメッセージ一覧の高さを調整
|
|
209
|
+
container.scrollTop(container.prop('scrollHeight'));
|
|
210
|
+
// セッション一覧を表示
|
|
211
|
+
agent.list_sessions();
|
|
212
|
+
// 新しいセッションでチャットを開始
|
|
213
|
+
const session_id = cmdbox.random_string(16);
|
|
214
|
+
agent.chat(session_id);
|
|
215
|
+
};
|
|
216
|
+
agent.list_sessions = async (session_id) => {
|
|
217
|
+
const formData = new FormData();
|
|
218
|
+
session_id && formData.append('session_id', session_id);
|
|
219
|
+
const histories = $('#histories');
|
|
220
|
+
const res = await fetch('agent/session/list', {method: 'POST', body: formData});
|
|
221
|
+
if (res.status != 200) cmdbox.message({'error':`${res.status}: ${res.statusText}`});
|
|
222
|
+
res.json().then((res) => {
|
|
223
|
+
if (!res['success']) return;
|
|
224
|
+
histories.html('');
|
|
225
|
+
res['success'].forEach(async (row) => {
|
|
226
|
+
if (!row['events'] || row['events'].length <= 0) return;
|
|
227
|
+
const msg = row['events'][0]['text'];
|
|
228
|
+
const history = agent.create_history(histories, row['id'], msg);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
agent.create_history = (histories, session_id, msg) => {
|
|
233
|
+
if (histories.find(`#${session_id}`).length > 0) return;
|
|
234
|
+
msg = cell_chop(msg, 300);
|
|
235
|
+
const history = $(`<a id="${session_id}" href="#" class="history pt-2 pb-1 d-block btn_hover"></a>`).appendTo(histories);
|
|
236
|
+
$(`<span class="d-inline-block align-top ms-2 me-2" style="fill:gray;"><svg class="align-top" width="24" height="24" viewBox="0 0 16 16">`
|
|
237
|
+
+`<use href="#svg_justify_left"></use></svg></span>`).appendTo(history);
|
|
238
|
+
$(`<div class="d-inline-block mb-2" style="width:calc(100% - 88px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"></div>`).appendTo(history).text(msg);
|
|
239
|
+
const btn = $(`<button class="btn d-inline-block align-top pt-1 btn_hover" style="fill:gray;"><svg class="align-top" width="16" height="16" viewBox="0 0 16 16">`
|
|
240
|
+
+`<use href="#btn_three_dots_vertical"></use></svg><ul class="dropdown-menu"/></button>`).appendTo(history);
|
|
241
|
+
btn.find('.dropdown-menu').append(`<li><a class="dropdown-item delete" href="#">Delete</a></li>`);
|
|
242
|
+
btn.off('click').on('click', (e) => {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
e.stopPropagation();
|
|
245
|
+
histories.find('.dropdown-menu').hide();
|
|
246
|
+
btn.find('.dropdown-menu').css('left','calc(100% - 180px)').show();
|
|
247
|
+
});
|
|
248
|
+
btn.find('.dropdown-menu .delete').off('click').on('click',(e)=>{
|
|
249
|
+
if (!window.confirm('Are you sure you want to delete this session?')) return;
|
|
250
|
+
// セッション削除ボタンのクリックイベント
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
e.stopPropagation();
|
|
253
|
+
agent.delete_session(session_id).then((res) => {
|
|
254
|
+
if (res['success']) {
|
|
255
|
+
history.remove();
|
|
256
|
+
const sid = messages.attr('data-session_id');
|
|
257
|
+
if (sid == session_id) {
|
|
258
|
+
// 削除したセッションが現在のセッションだった場合は、メッセージ一覧をクリア
|
|
259
|
+
messages.html('');
|
|
260
|
+
agent.chat(cmdbox.random_string(16)); // 新しいセッションを開始
|
|
261
|
+
}
|
|
262
|
+
agent.list_sessions();
|
|
263
|
+
} else {
|
|
264
|
+
cmdbox.message({'error':res['error'] || 'Failed to delete session.'});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
history.off('click').on('click', async (e) => {
|
|
269
|
+
// セッションを選択したときの処理
|
|
270
|
+
e.preventDefault();
|
|
271
|
+
agent.chat(session_id);
|
|
272
|
+
const formData = new FormData();
|
|
273
|
+
formData.append('session_id', session_id);
|
|
274
|
+
const res = await fetch('agent/session/list', {method: 'POST', body: formData});
|
|
275
|
+
if (res.status != 200) cmdbox.message({'error':`${res.status}: ${res.statusText}`});
|
|
276
|
+
res.json().then((res) => {
|
|
277
|
+
if (!res['success'] || res['success'].length<=0) {
|
|
278
|
+
cmdbox.message({'error':'No messages found for this session.'});
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const session = res['success'][0];
|
|
282
|
+
if (!session['events'] || session['events'].length <= 0) {
|
|
283
|
+
cmdbox.message({'error':'No messages found for this session.'});
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const container = $('#message_container');
|
|
287
|
+
const messages = $('#messages');
|
|
288
|
+
messages.html('');
|
|
289
|
+
session['events'].forEach((event) => {
|
|
290
|
+
if (!event['text'] || event['text'].length <= 0) return;
|
|
291
|
+
if (event['author'] == 'user') {
|
|
292
|
+
// ユーザーメッセージ
|
|
293
|
+
agent.create_user_message(messages, event['text']);
|
|
294
|
+
} else {
|
|
295
|
+
// エージェントメッセージ
|
|
296
|
+
txt = agent.create_agent_message(messages, cmdbox.random_string(16));
|
|
297
|
+
agent.format_agent_message(container, messages, txt, event['text']);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
return history;
|
|
303
|
+
};
|
|
304
|
+
agent.delete_session = async (session_id) => {
|
|
305
|
+
const formData = new FormData();
|
|
306
|
+
formData.append('session_id', session_id);
|
|
307
|
+
const res = await fetch('agent/session/delete', {method: 'POST', body: formData});
|
|
308
|
+
if (res.status != 200) cmdbox.message({'error':`${res.status}: ${res.statusText}`});
|
|
309
|
+
return await res.json();
|
|
310
|
+
}
|
|
311
|
+
$(() => {
|
|
312
|
+
// カラーモード対応
|
|
313
|
+
cmdbox.change_color_mode();
|
|
314
|
+
// スプリッター初期化
|
|
315
|
+
$('.split-pane').splitPane();
|
|
316
|
+
// アイコンを表示
|
|
317
|
+
cmdbox.set_logoicon('.navbar-brand');
|
|
318
|
+
// copyright表示
|
|
319
|
+
cmdbox.copyright();
|
|
320
|
+
// バージョン情報モーダル初期化
|
|
321
|
+
cmdbox.init_version_modal();
|
|
322
|
+
// モーダルボタン初期化
|
|
323
|
+
cmdbox.init_modal_button();
|
|
324
|
+
// コマンド実行用のオプション取得
|
|
325
|
+
cmdbox.get_server_opt(true, $('.filer_form')).then(async (opt) => {
|
|
326
|
+
agent.init_form();
|
|
327
|
+
});
|
|
328
|
+
// dropdownメニューを閉じる
|
|
329
|
+
const histories = $('#histories');
|
|
330
|
+
$(document).on('click', (e) => {
|
|
331
|
+
histories.find('.dropdown-menu').hide();
|
|
332
|
+
}).on('contextmenu', (e) => {
|
|
333
|
+
histories.find('.dropdown-menu').hide();
|
|
334
|
+
});
|
|
335
|
+
});
|