JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feat: 增加用户面统一登录开关与 Identity 部署适配
u0102401954366c1e984a1
diff --git a/deploy/enterprise/.env.example b/deploy/enterprise/.env.exampleindex 342ecb37ff..19c18e6eb4 100644--- a/deploy/enterprise/.env.example+++ b/deploy/enterprise/.env.example@@ -451,6 +451,12 @@ MANAGER_WEB_IMAGE=""# 控制是否启动Manager 前端模块IS_UP_MANAGER_WEB=false+# 是否由 Manager Web 作为用户面统一登录入口+# false:User Web 保持独立 NodePort 入口+# true:用户登录 Manager Web 后通过 /user 内嵌 User Web,且不再暴露 User Web NodePort+# 启用时必须同时设置 IS_UP_MANAGER_WEB=true+ENABLE_USER_WEB_EMBEDDING=false+# Manager 前端模块对外暴露的主机端口# 不设置就自动寻找空闲端口,如需要设置,请确保该端口的唯一性(范围: 30000-32767)# IS_UP_MANAGER_WEB=false的时候,该参数失效@@ -515,4 +521,3 @@ EMBED_API_KEY=""#"FEISHU_BOTS=""-diff --git a/deploy/enterprise/README.md b/deploy/enterprise/README.mdindex 7d62265ebc..ec26fda421 100644--- a/deploy/enterprise/README.md+++ b/deploy/enterprise/README.md@@ -655,6 +655,67 @@ Web 为 JiuwenSwarm 企业版面向终端用户的对话可视化前端,用于```+#### 4.3.1 用户面入口模式++用户面支持独立入口和 Manager Web 统一登录入口两种部署方式。通过 `.env.custom` 配置:++```bash+# false:保留 User Web 独立 NodePort 入口(默认,兼容原有部署)+# true:用户登录 Manager Web 后从 /user 进入内嵌 User Web,不暴露 User Web NodePort+ENABLE_USER_WEB_EMBEDDING=false+```++启用统一入口时,Manager Web 是用户面唯一的集群外入口,User Web 仍会部署并保留+ClusterIP,供 Manager Web 转发文件请求等内部调用。配置必须同时满足:++```bash+ENABLE_USER_WEB_EMBEDDING=true+IS_UP_MANAGER_WEB=true+```++统一入口使用以下同源路由,不需要额外暴露 Identity、Manager Server、Gateway 或+User Server:++| 路径 | 目标服务 | 用途 |+|---|---|---|+| `/idp/*` | Identity Center | 登录、刷新令牌和用户信息 |+| `/api/*` | Manager Server | 管理面与用户目录接口 |+| `/chat/*` | Manager Web 内置 User Web | 用户面对话界面 |+| `/web/invoke` | Gateway HTTP/SSE | 对话请求与流式响应 |+| `/file-api/*` | User Server | 文件相关接口 |++从独立入口切换为统一入口时,部署脚本会删除同命名空间中已有的 User Web NodePort+Service,避免用户绕过统一登录入口;切回独立入口并重新部署 Web 后会恢复 NodePort。++#### 4.3.2 升级已有 MySQL 数据库++全新数据库会按当前表定义自动建表,不需要手工迁移。复用旧版 Manager MySQL+数据库并升级到包含 Agent 工作区策略的版本时,先检查策略表是否已有+`workspace_dir`:++```sql+SELECT COLUMN_NAME+FROM information_schema.COLUMNS+WHERE TABLE_SCHEMA = '<manager数据库名>'+ AND TABLE_NAME = 'config_effective_agent_policy'+ AND COLUMN_NAME = 'workspace_dir';+```++仅当表存在且查询结果为空时执行:++```sql+ALTER TABLE <manager数据库名>.config_effective_agent_policy+ADD COLUMN workspace_dir VARCHAR(512) NULL;+```++`workspace_dir` 是 Agent 策略的数据目录逻辑键,可使用 `${user_id}`、+`${group_id}`、`${bot_id}` 等模板变量。它不参与用户登录或 JWT 验签。++Identity Center 使用全新 MySQL 数据库时不需要迁移。若复用曾运行旧版联合认证的+数据库,应先确认 `federated_identity` 表已经包含 `identity_key`;该字段需要根据+原三元组生成摘要并建立唯一索引,不能只增加一个空字段。存在旧联合身份数据时应先+备份并使用对应 Runtime 版本的迁移流程,部署工具不会自动修改业务身份数据。+## 5 服务异常排查系统服务运行异常时,可按以下步骤逐层定位故障根因:@@ -902,4 +963,3 @@ RUNTIME_CODE_PATH=""# 注意:Web源代码代码需要npm run build之后,才能mount进容器,IS_MOUNT_WEB_CODE="false"```-diff --git a/deploy/enterprise/check_handler.sh b/deploy/enterprise/check_handler.shindex 9c7db484e5..23f1e6e209 100755--- a/deploy/enterprise/check_handler.sh+++ b/deploy/enterprise/check_handler.sh@@ -9,6 +9,35 @@ check_cmd() {fi}+check_boolean_value() {+ local name="$1"+ local value="${DEPLOY_VARS["${name}"]:-}"+ if [[ "${value}" != "true" && "${value}" != "false" ]]; then+ error "${name} must be true or false, current value: ${value}"+ fi+}++check_user_web_embedding_config() {+ check_boolean_value "ENABLE_USER_WEB_EMBEDDING"+ check_boolean_value "IS_UP_MANAGER_WEB"++ if [[ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" \+ && "${DEPLOY_VARS["IS_UP_MANAGER_WEB"]}" != "true" ]]; then+ error "ENABLE_USER_WEB_EMBEDDING=true requires IS_UP_MANAGER_WEB=true"+ fi+}++module_is_selected() {+ local expected="$1"+ local module=""+ for module in "${MODULES[@]}"; do+ if [ "${module}" == "${expected}" ]; then+ return 0+ fi+ done+ return 1+}+check_yq() {local YQ_VERSION=$(yq --version 2>&1)@@ -412,6 +441,14 @@ check_gateway_up_dependency(){}check_web_up_dependency(){+ check_user_web_embedding_config+ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" ] \+ && ! module_is_selected "MANAGER"; then+ if ! check_k8s_resource_exists \+ "deployment" "${DEPLOY_VARS["MANAGER_WEB_NAME"]}" "${DEPLOY_VARS["NAMESPACE"]}"; then+ error "Embedded User Web requires the Manager Web module to be deployed"+ fi+ ficheck_if_db_upcheck_if_obs_up@@ -421,6 +458,14 @@ check_web_up_dependency(){}check_manager_up_dependency(){+ check_user_web_embedding_config+ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" ] \+ && ! module_is_selected "WEB"; then+ if ! check_k8s_resource_exists \+ "deployment" "${DEPLOY_VARS["WEB_NAME"]}" "${DEPLOY_VARS["NAMESPACE"]}"; then+ error "Embedded User Web requires the Web module to be deployed"+ fi+ fi#check_if_rabbitmq_upcheck_if_db_up}diff --git a/deploy/enterprise/example/manager-server.yaml b/deploy/enterprise/example/manager-server.yamlindex 40ed058908..82fe50222f 100644--- a/deploy/enterprise/example/manager-server.yaml+++ b/deploy/enterprise/example/manager-server.yaml@@ -77,6 +77,8 @@ spec:value: "<<DB_USER>>"- name: MANAGER_DB_NAMEvalue: "manager"+ - name: IDENTITY_PUBLIC_KEY_URL+ value: "http://jiuwenclaw-identity:8770/v1/auth/public_key"- name: MANAGER_WS_ENABLEDvalue: "true"- name: MANAGER_WS_HOSTdiff --git a/deploy/enterprise/example/manager-web.yaml b/deploy/enterprise/example/manager-web.yamlindex 525f6ae45d..fc863fad5b 100644--- a/deploy/enterprise/example/manager-web.yaml+++ b/deploy/enterprise/example/manager-web.yaml@@ -30,6 +30,12 @@ spec:value: "5273"- name: MANAGER_WEB_PROXY_TARGETvalue: "http://jiuwenclaw-manager-server:8765"+ - name: MANAGER_WEB_IDP_TARGET+ value: "http://jiuwenclaw-identity:8770"+ - name: MANAGER_WEB_GATEWAY_SSE+ value: "http://jiuwenclaw-gateway:19001/web/invoke"+ - name: MANAGER_WEB_USER_SERVER_TARGET+ value: "http://jiuwenclaw-web:19000"- name: TZvalue: "Asia/Shanghai"diff --git a/deploy/enterprise/example/web.yaml b/deploy/enterprise/example/web.yamlindex 491aac0b16..9571a4916a 100644--- a/deploy/enterprise/example/web.yaml+++ b/deploy/enterprise/example/web.yaml@@ -32,6 +32,8 @@ spec:env:- name: JIUWENCLAW_WEB_HOSTvalue: "0.0.0.0"+ - name: FRONTEND_HOST+ value: "0.0.0.0"- name: JIUWENCLAW_WEB_PORTvalue: "5173"- name: ENTERPRISE_WEB_WS_HOSTdiff --git a/deploy/enterprise/global_vars.sh b/deploy/enterprise/global_vars.shindex 2ed219cfc4..7bcbb6142f 100755--- a/deploy/enterprise/global_vars.sh+++ b/deploy/enterprise/global_vars.sh@@ -113,6 +113,7 @@ declare -A DEPLOY_VARS=(["ENABLE_EXTERNAL_PVC"]="false"["ENABLE_EXTERNAL_RABBITMQ"]="false"["ENABLE_EXTERNAL_REDIS"]="false"+ ["ENABLE_USER_WEB_EMBEDDING"]="false"["FLUENT_BIT_NAME"]="fluent-bit"["FLUENT_BIT_IMAGE"]="fluent/fluent-bit:3.0.0"["FUNC_SVC_NAME"]="0@jiuwen@clawtest"diff --git a/deploy/enterprise/manager_handler.sh b/deploy/enterprise/manager_handler.shindex 53f22040a5..7dded64a2d 100755--- a/deploy/enterprise/manager_handler.sh+++ b/deploy/enterprise/manager_handler.sh@@ -87,6 +87,11 @@ deploy_manager() {wait_k8s_resource_ready "deployment" "${manager_web_name}" "${namespace}"success "MANAGER_WEB_NODE_PORT: ${DEPLOY_VARS["MANAGER_WEB_NODE_PORT"]}"fi++ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" ]; then+ delete_k8s_resource \+ "service" "${DEPLOY_VARS["WEB_NAME"]}-nodeport" "${namespace}"+ fi}uninstall_manager() {diff --git a/deploy/enterprise/templates/.env.custom.template b/deploy/enterprise/templates/.env.custom.templateindex e5a12d7250..a0fe6015d0 100644--- a/deploy/enterprise/templates/.env.custom.template+++ b/deploy/enterprise/templates/.env.custom.template@@ -13,6 +13,7 @@ AGENT_SERVER_IMAGE="<<AGENT_SERVER_IMAGE>>"WEB_IMAGE="<<WEB_IMAGE>>"MANAGER_SERVER_IMAGE="<<MANAGER_SERVER_IMAGE>>"MANAGER_WEB_IMAGE="<<MANAGER_WEB_IMAGE>>"+IDENTITY_IMAGE="<<IDENTITY_IMAGE>>"JIUWENBOX_IMAGE="<<JIUWENBOX_IMAGE>>"AGENT_RUNTIME="jiuwen"@@ -21,6 +22,12 @@ GATEWAY_EDITION="enterprise"GATEWAY_SESSION_MAP_SCOPE="per_chat_bot_user"JIUWENBOX_ENABLED=true+# 是否启动 Manager Web;启用用户面内嵌模式时必须为 true+IS_UP_MANAGER_WEB=true++# false:User Web 保持独立入口;true:通过 Manager Web 登录后内嵌访问+ENABLE_USER_WEB_EMBEDDING=false+# 设置空闲端口,请确保该端口的唯一性(范围: 30000-32767)MYSQL_NODE_PORT="<<MYSQL_NODE_PORT>>"@@ -76,4 +83,4 @@ OBS_URL="<<OBS_URL>>"OBS_ACCESS_KEY="<<OBS_ACCESS_KEY>>"OBS_SECRET_KEY="<<OBS_SECRET_KEY>>"OBS_SECURE="<<OBS_SECURE>>"-OBS_REGION="<<OBS_REGION>>"\ No newline at end of file+OBS_REGION="<<OBS_REGION>>"diff --git a/deploy/enterprise/templates/manager-server.template.yaml b/deploy/enterprise/templates/manager-server.template.yamlindex 0daa5bcfd5..3c2d8cb944 100644--- a/deploy/enterprise/templates/manager-server.template.yaml+++ b/deploy/enterprise/templates/manager-server.template.yaml@@ -79,6 +79,8 @@ spec:value: "<<MANAGER_DB_USER>>"- name: MANAGER_DB_NAMEvalue: "<<MANAGER_DB_NAME>>"+ - name: IDENTITY_PUBLIC_KEY_URL+ value: "http://<<IDENTITY_NAME>>:<<IDENTITY_REST_PORT>>/v1/auth/public_key"- name: MANAGER_WS_ENABLEDvalue: "true"- name: MANAGER_WS_HOSTdiff --git a/deploy/enterprise/templates/manager-web.template.yaml b/deploy/enterprise/templates/manager-web.template.yamlindex 2ca962adac..5f3b416b50 100644--- a/deploy/enterprise/templates/manager-web.template.yaml+++ b/deploy/enterprise/templates/manager-web.template.yaml@@ -36,8 +36,6 @@ spec:value: "http://<<GATEWAY_NAME>>:<<GATEWAY_HTTP_PORT>>/web/invoke"- name: MANAGER_WEB_USER_SERVER_TARGETvalue: "http://<<WEB_NAME>>:<<WEB_WS_PORT>>"- - name: IDENTITY_PUBLIC_KEY_URL- value: "http://<<IDENTITY_NAME>>:<<IDENTITY_REST_PORT>>/v1/auth/public_key"- name: TZvalue: "<<TIMEZONE>>"diff --git a/deploy/enterprise/templates/web.template.yaml b/deploy/enterprise/templates/web.template.yamlindex a44537bcda..20ac9367de 100644--- a/deploy/enterprise/templates/web.template.yaml+++ b/deploy/enterprise/templates/web.template.yaml@@ -32,6 +32,8 @@ spec:env:- name: JIUWENCLAW_WEB_HOSTvalue: "0.0.0.0"+ - name: FRONTEND_HOST+ value: "0.0.0.0"- name: FRONTEND_PORTvalue: "<<WEB_HTTP_PORT>>"- name: ENTERPRISE_WEB_WS_HOSTdiff --git a/deploy/enterprise/tests/test_identity_user_web_deploy.sh b/deploy/enterprise/tests/test_identity_user_web_deploy.shnew file mode 100755index 0000000000..836a271886--- /dev/null+++ b/deploy/enterprise/tests/test_identity_user_web_deploy.sh@@ -0,0 +1,141 @@+#!/usr/bin/env bash+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"++source "${SCRIPT_DIR}/common.sh"+source "${SCRIPT_DIR}/global_vars.sh"+source "${SCRIPT_DIR}/cmd_handler.sh"+source "${SCRIPT_DIR}/envfile_handler.sh"+source "${SCRIPT_DIR}/template_handler.sh"+source "${SCRIPT_DIR}/check_handler.sh"+source "${SCRIPT_DIR}/web_handler.sh"+source "${SCRIPT_DIR}/manager_handler.sh"++TEST_DIR=""++cleanup() {+ if [ -n "${TEST_DIR}" ] && [ -d "${TEST_DIR}" ]; then+ rm -rf -- "${TEST_DIR}"+ fi+}++assert_equal() {+ local expected="$1"+ local actual="$2"+ local message="$3"+ if [ "${actual}" != "${expected}" ]; then+ echo "FAIL: ${message}: expected=${expected}, actual=${actual}" >&2+ exit 1+ fi+}++main() {+ check_cmd "yq"++ TEST_DIR="$(mktemp -d)"+ local test_dir="${TEST_DIR}"+ trap cleanup EXIT++ DEPLOY_VARS["OS_TYPE"]="linux"+ DEPLOY_VARS["MODE"]="product"+ DEPLOY_VARS["WEB_NODE_PORT"]="31001"+ DEPLOY_VARS["MANAGER_SERVER_NODE_PORT"]="31002"+ DEPLOY_VARS["MANAGER_WEB_NODE_PORT"]="31003"++ assert_equal \+ "false" \+ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" \+ "User Web embedding must be disabled by default"+ printf '%s\n' 'ENABLE_USER_WEB_EMBEDDING=true' > "${test_dir}/.env.custom"+ read_env_from_file "${test_dir}/.env.custom" "DEPLOY_VARS"+ assert_equal \+ "true" \+ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" \+ ".env.custom must override the embedding default"++ CONFIG["WEB_FILE"]="${test_dir}/web.yaml"++ DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]="false"+ gen_web_file+ assert_equal \+ "NodePort" \+ "$(yq eval-all 'select(.metadata.name == "jiuwenclaw-web-nodeport") | .spec.type' "${CONFIG["WEB_FILE"]}")" \+ "standalone mode must expose the User Web NodePort"+ assert_equal \+ "0.0.0.0" \+ "$(yq eval-all 'select(.kind == "Deployment").spec.template.spec.containers[0].env[] | select(.name == "FRONTEND_HOST").value' "${CONFIG["WEB_FILE"]}")" \+ "User Web frontend must listen on all interfaces"++ DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]="true"+ gen_web_file+ assert_equal \+ "0" \+ "$(yq eval-all '[select(.metadata.name == "jiuwenclaw-web-nodeport")] | length' "${CONFIG["WEB_FILE"]}")" \+ "embedded mode must remove the User Web NodePort"+ assert_equal \+ "ClusterIP" \+ "$(yq eval-all 'select(.kind == "Service") | .spec.type' "${CONFIG["WEB_FILE"]}")" \+ "embedded mode must retain the internal User Web service"++ DEPLOY_VARS["IS_UP_MANAGER_WEB"]="false"+ if (check_user_web_embedding_config) >/dev/null 2>&1; then+ echo "FAIL: embedded mode must require Manager Web" >&2+ exit 1+ fi++ DEPLOY_VARS["IS_UP_MANAGER_WEB"]="true"+ check_user_web_embedding_config++ DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]="invalid"+ if (check_user_web_embedding_config) >/dev/null 2>&1; then+ echo "FAIL: invalid boolean value must be rejected" >&2+ exit 1+ fi++ CONFIG["MANAGER_SERVER_FILE"]="${test_dir}/manager-server.yaml"+ render_config_template \+ "${CONFIG["MANAGER_SERVER_TEMPLATE_FILE"]}" \+ "${CONFIG["MANAGER_SERVER_FILE"]}" \+ "DEPLOY_VARS"+ assert_equal \+ "http://jiuwenclaw-identity:8770/v1/auth/public_key" \+ "$(yq eval 'select(.kind == "Deployment").spec.template.spec.containers[0].env[] | select(.name == "IDENTITY_PUBLIC_KEY_URL").value' "${CONFIG["MANAGER_SERVER_FILE"]}")" \+ "Manager Server must receive the Identity public-key URL"++ CONFIG["MANAGER_WEB_FILE"]="${test_dir}/manager-web.yaml"+ render_config_template \+ "${CONFIG["MANAGER_WEB_TEMPLATE_FILE"]}" \+ "${CONFIG["MANAGER_WEB_FILE"]}" \+ "DEPLOY_VARS"+ assert_equal \+ "0" \+ "$(yq eval-all '[select(.kind == "Deployment").spec.template.spec.containers[0].env[] | select(.name == "IDENTITY_PUBLIC_KEY_URL")] | length' "${CONFIG["MANAGER_WEB_FILE"]}")" \+ "Manager Web must not receive the unused public-key URL"++ local deleted_service=""+ ensure_secret_configmap() { :; }+ exec_cmd() { :; }+ wait_k8s_resource_ready() { :; }+ success() { :; }+ delete_k8s_resource() { deleted_service="$1/$2/$3"; }++ DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]="true"+ deploy_web+ assert_equal \+ "service/jiuwenclaw-web-nodeport/default" \+ "${deleted_service}" \+ "embedded deployment must remove a stale User Web NodePort"++ deleted_service=""+ DEPLOY_VARS["IS_UP_MANAGER_WEB"]="true"+ deploy_manager+ assert_equal \+ "service/jiuwenclaw-web-nodeport/default" \+ "${deleted_service}" \+ "Manager deployment must also remove a stale User Web NodePort"++ echo "PASS: identity and User Web deployment checks"+}++main "$@"diff --git a/deploy/enterprise/web_handler.sh b/deploy/enterprise/web_handler.shindex 8053c372c7..07e505ae00 100755--- a/deploy/enterprise/web_handler.sh+++ b/deploy/enterprise/web_handler.sh@@ -9,6 +9,11 @@ gen_web_file() {render_config_template "${template_file}" "${file}" "DEPLOY_VARS"+ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" ]; then+ local nodeport_name="${DEPLOY_VARS["WEB_NAME"]}-nodeport"+ yq eval 'select(.metadata.name != "'"${nodeport_name}"'")' -i "${file}"+ fi+if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_OBS"]}" == "true" ]; thenobs_url="${DEPLOY_VARS["OBS_URL"]}"fi@@ -48,7 +53,9 @@ gen_web_file() {render_web_files() {render_secret_configmap- ensure_available_port "WEB_NODE_PORT"+ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" != "true" ]; then+ ensure_available_port "WEB_NODE_PORT"+ figen_web_file}@@ -60,7 +67,12 @@ deploy_web() {ensure_secret_configmapexec_cmd kubectl apply -f ${file}wait_k8s_resource_ready "deployment" "${name}" "${namespace}"- success "WEB_NODE_PORT: ${DEPLOY_VARS["WEB_NODE_PORT"]}"+ if [ "${DEPLOY_VARS["ENABLE_USER_WEB_EMBEDDING"]}" == "true" ]; then+ delete_k8s_resource "service" "${name}-nodeport" "${namespace}"+ success "User Web is available through Manager Web; standalone NodePort is disabled"+ else+ success "WEB_NODE_PORT: ${DEPLOY_VARS["WEB_NODE_PORT"]}"+ fi}uninstall_web() {@@ -69,6 +81,7 @@ uninstall_web() {local file="${CONFIG["WEB_FILE"]}"exec_cmd kubectl delete -f ${file} --ignore-not-found=true+ delete_k8s_resource "service" "${name}-nodeport" "${namespace}"wait_pod_terminated "${name}" "${namespace}"uninstall_secret_configmap-}\ No newline at end of file+}