refs #732: add dynamic HMM HTML report MCP tool

This commit is contained in:
devmrko
2026-08-10 15:23:36 +09:00
parent cc2c3e3e25
commit c0c5a36ba0
12 changed files with 747 additions and 39 deletions

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Load the approved UTF-8 HTML template into Oracle without SQLcl literal mojibake.
set -Eeuo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${HMM_REPORT_ENV_FILE:-$ROOT/.env}"
TEMPLATE_FILE="${HMM_REPORT_TEMPLATE_FILE:-$ROOT/ai-web-agent-console/assets/hmm-carrier-performance-report.html}"
WALLET_DIR="${HMM_REPORT_WALLET_DIR:-/Users/joungminko/devkit/db_conn/Wallet_HMMAIPOC}"
[[ -f "$ENV_FILE" ]] && { set -a; . "$ENV_FILE"; set +a; }
SQLCL_BIN="${SQLCL_BIN:-$(command -v sql || true)}"
DB_USER="${BACKOFFICE_DB_USERNAME:-${ADB_USER:-}}"
DB_PASSWORD="${BACKOFFICE_DB_PASSWORD:-${ADB_PASSWORD:-}}"
DB_TNS="${ADB_TNS:-}"
DB_URL="${BACKOFFICE_DB_URL:-}"
if [[ -z "$DB_TNS" && "$DB_URL" =~ ^jdbc:oracle:thin:@([^?]+) ]]; then
DB_TNS="${BASH_REMATCH[1]}"
fi
[[ -x "$SQLCL_BIN" && -f "$TEMPLATE_FILE" && -d "$WALLET_DIR" && -n "$DB_USER" && -n "$DB_PASSWORD" && -n "$DB_TNS" ]] || {
echo "SQLCL_BIN, DB credentials, ADB_TNS, and template file are required." >&2; exit 1;
}
REPORT_B64="$(base64 < "$TEMPLATE_FILE" | tr -d '\n')"
[[ ${#REPORT_B64} -le 30000 ]] || { echo "Template is too large for the single-chunk loader." >&2; exit 1; }
"$SQLCL_BIN" -thin -tnsadmin "$WALLET_DIR" -s "$DB_USER/$DB_PASSWORD@$DB_TNS" <<SQL
WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK
DECLARE
l_html CLOB := to_clob(utl_i18n.raw_to_char(
utl_encode.base64_decode(utl_raw.cast_to_raw('$REPORT_B64')), 'AL32UTF8'));
BEGIN
MERGE INTO hmm_report_templates dst
USING (SELECT 'hmm-carrier-performance' template_key FROM dual) src
ON (dst.template_key = src.template_key)
WHEN MATCHED THEN UPDATE SET html_template = l_html, template_version = '1.0.0',
active_yn = 'Y', updated_at = SYSTIMESTAMP
WHEN NOT MATCHED THEN INSERT (template_key, template_version, html_template, active_yn)
VALUES ('hmm-carrier-performance', '1.0.0', l_html, 'Y');
COMMIT;
END;
/
SELECT template_key, template_version, active_yn, dbms_lob.getlength(html_template) html_chars
FROM hmm_report_templates WHERE template_key = 'hmm-carrier-performance';
EXIT
SQL