Skip to content

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

nginx启动web

chen hui06746aa08768
diff --git a/deploy/enterprise/check_handler.sh b/deploy/enterprise/check_handler.sh
index aec4c422e7..5b9e7cc9bc 100755
--- a/deploy/enterprise/check_handler.sh
+++ b/deploy/enterprise/check_handler.sh
@@ -480,8 +480,7 @@ check_runtime_up_dependency(){
if [[ "${DEPLOY_VARS["RENDER_ONLY"]}" != "true" && "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]]; then
info "Preparing JiuwenClaw data directory: ${jiuwenclaw_path}"
local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
- info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${jiuwenclaw_path} && chown 1000:1000 ${jiuwenclaw_path} && chmod 777 ${jiuwenclaw_path}\""
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${jiuwenclaw_path} && chown 1000:1000 ${jiuwenclaw_path} && chmod 777 ${jiuwenclaw_path}"
+ kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${jiuwenclaw_path}"
success "JiuwenClaw directory created successfully in NFS Pod!"
fi
elif [ "${DEPLOY_VARS["CLAW_MOUNT_TYPE"]}" == "pvc" ]; then
diff --git a/deploy/enterprise/gateway_handler.sh b/deploy/enterprise/gateway_handler.sh
index f55fa25893..888224dc58 100755
--- a/deploy/enterprise/gateway_handler.sh
+++ b/deploy/enterprise/gateway_handler.sh
@@ -100,12 +100,6 @@ gen_gateway_file() {
render_gateway_files() {
local mode="${DEPLOY_VARS["MODE"]}"
- if [ "${mode}" == "dev" ]; then
- DEPLOY_VARS["CLAW_HOME"]="/root"
- else
- DEPLOY_VARS["CLAW_HOME"]="/home/app"
- fi
-
render_secret_configmap
gen_gateway_env_file
gen_gateway_config_file
diff --git a/deploy/enterprise/global_vars.sh b/deploy/enterprise/global_vars.sh
index 0dabd84c42..69a336dec7 100755
--- a/deploy/enterprise/global_vars.sh
+++ b/deploy/enterprise/global_vars.sh
@@ -112,6 +112,7 @@ declare -A DEPLOY_VARS=(
["CLAW_STORAGE_SIZE"]="1Gi"
["COLLECT_LOG_MASK_ENABLED"]="false"
["DB_TYPE"]="mysql"
+ ["DB_CONNECT_TIMEOUT"]="15"
["WEB_PORT"]="19000"
["GATEWAY_PORT"]="19001"
["GATEWAY_HTTP_PORT"]="19001"
@@ -236,7 +237,7 @@ declare -A DEPLOY_VARS=(
["AGENT_RUNTIME_LOG_LEVEL"]="INFO"
["WS_ALLOWED_ORIGINS"]=""
["WS_ORIGIN_CHECK_ENABLED"]="false"
- ["CLAW_HOME"]="/home/app"
+ ["CLAW_HOME"]="/root"
["AGENT_SERVER_NAME"]="jiuwenclaw-agentserver"
["AGENT_SERVER_PORT"]="8766"
["AGENT_SERVER_SERVICE_CONCURRENCY"]="10"
@@ -250,6 +251,7 @@ declare -A DEPLOY_VARS=(
["JIUWENBOX_PORT"]="8321"
["JIUWENBOX_HOME"]="/home/app"
["APPLY_PATCH"]="false"
+ ["LOGIN_AUTH_SIMULATE"]="false"
)
declare -A OYR_COMPONENTS=(
diff --git a/deploy/enterprise/patch_handler.sh b/deploy/enterprise/patch_handler.sh
index 37d77a7571..0b45f8b86d 100755
--- a/deploy/enterprise/patch_handler.sh
+++ b/deploy/enterprise/patch_handler.sh
@@ -52,27 +52,48 @@ post_and_validate() {
success "POST ${url} ok (http=${code})"
}
-render_patch_file() {
- local json_template="${CONFIG["AS_JSON_TEMPLATE_FILE"]}"
- local json_file="${CONFIG["AS_JSON_FILE"]}"
-
- info "Rendering AgentServer templates"
- render_config_template "${json_template}" "${json_file}" "DEPLOY_VARS"
-
- if ! jq . "${json_file}" >/dev/null 2>&1; then
- error "AgentServer JSON rendering failed, invalid JSON format: ${json_file}"
+# 按存储模式注入 data 卷(.jiuwenswarm 数据目录):模板里不再预置 PVC 卷,
+# 由本函数按 CLAW_MOUNT_TYPE 二选一注入——
+# pvc: StorageClass 动态供给的持久卷(claimName=CLAW_PVC)
+# nfs: 直连 NFS 共享目录(server=NFS_SERVER_ADDR, path=NFS_SHARE_PATH/jiuwenclaw,
+# 与 check_runtime_up_dependency 预创建的内置 NFS 数据目录同名)
+# 用法: inject_data_volume <json_file>
+inject_data_volume() {
+ local json_file="$1"
+ local mount_type="${DEPLOY_VARS["CLAW_MOUNT_TYPE"]}"
+ local data_volume
+ if [ "${mount_type}" == "pvc" ]; then
+ data_volume="$(jq -n --arg claim "${DEPLOY_VARS["CLAW_PVC"]}" \
+ '{name: "data", persistentVolumeClaim: {claimName: $claim}}')"
+ elif [ "${mount_type}" == "nfs" ]; then
+ if [ -z "${DEPLOY_VARS["NFS_SERVER_ADDR"]:-}" ]; then
+ error "CLAW_MOUNT_TYPE=nfs requires NFS_SERVER_ADDR (external) or a deployed built-in NFS"
+ fi
+ # 规整共享根路径尾部 '/'(内置 NFS 默认 NFS_SHARE_PATH="/",避免拼出 //jiuwenclaw)
+ local nfs_share="${DEPLOY_VARS["NFS_SHARE_PATH"]%/}"
+ data_volume="$(jq -n --arg server "${DEPLOY_VARS["NFS_SERVER_ADDR"]}" \
+ --arg path "${nfs_share}/jiuwenclaw" \
+ '{name: "data", nfs: {server: $server, path: $path}}')"
+ else
+ error "Unsupported CLAW_MOUNT_TYPE '${mount_type}' (expect pvc/nfs)"
fi
+ jq --argjson volume "${data_volume}" \
+ '.rawdata.templates[].volumes += [$volume]' \
+ "${json_file}" > "${json_file}.tmp" && mv -f "${json_file}.tmp" "${json_file}"
+}
- # 计算要剔除的 hostPath 卷(+ 引用它们的 volumeMounts);product 模式额外删主容器 securityContext
- # 及所有容器的 privileged:
- # 规则1(两模式通用):三个代码目录变量(CLAW_CODE_PATH/RUNTIME_CODE_PATH/CORE_CODE_PATH)任一为空,
- # 引用该变量的 hostPath 路径会变坏、不能挂载,一并剔除。映射(按 hostPath path 引用):
- # CLAW_CODE_PATH -> hp-code, hp-jiuwenbox
- # RUNTIME_CODE_PATH -> hp-rt-foundation, hp-rt-management
- # CORE_CODE_PATH -> hp-openjiuwen
- # 规则2(仅 product):agentserver 镜像内置代码,4 个 agentserver 代码挂载,1 个 jiuwenbox代码挂载
- # (hp-code/hp-rt-foundation/hp-rt-management/hp-openjiuwen)无论变量是否为空都删;
- # hp-cgroup(sidecar 系统路径)始终保留。
+# 剔除无效/不需要的 hostPath 卷(+ 引用它们的 volumeMounts):
+# 规则1(两模式通用):三个代码目录变量(CLAW_CODE_PATH/RUNTIME_CODE_PATH/CORE_CODE_PATH)任一为空,
+# 引用该变量的 hostPath 路径会变坏、不能挂载,一并剔除。映射(按 hostPath path 引用):
+# CLAW_CODE_PATH -> hp-code, hp-jiuwenbox
+# RUNTIME_CODE_PATH -> hp-rt-foundation, hp-rt-management
+# CORE_CODE_PATH -> hp-openjiuwen
+# 规则2(仅 product):agentserver 镜像内置代码,4 个 agentserver 代码挂载,1 个 jiuwenbox代码挂载
+# (hp-code/hp-rt-foundation/hp-rt-management/hp-openjiuwen)无论变量是否为空都删;
+# hp-cgroup(sidecar 系统路径)始终保留。
+# 用法: drop_hostpath_volumes <json_file>
+drop_hostpath_volumes() {
+ local json_file="$1"
local drop_names=()
if [[ -z "${DEPLOY_VARS["CLAW_CODE_PATH"]:-}" ]]; then
drop_names+=(hp-code hp-jiuwenbox)
@@ -88,20 +109,31 @@ render_patch_file() {
fi
if [ "${#drop_names[@]}" -gt 0 ]; then
- local jq_drop sec_filter
+ local jq_drop
jq_drop="$(printf '%s\n' "${drop_names[@]}" | jq -R . | jq -s .)"
- sec_filter=""
- if [[ "${DEPLOY_VARS["MODE"]}" == "product" ]]; then
- sec_filter=' | .rawdata.containers |= map(if .container_id == "c-agentserver" then del(.securityContext) else . end) | .rawdata.containers |= map(del(.securityContext.privileged))'
- fi
jq --argjson drop "${jq_drop}" \
- ".rawdata.templates[].volumes |= map(select(.name as \$n | \$drop | map(. == \$n) | any | not))${sec_filter}" \
+ ".rawdata.templates[].volumes |= map(select(.name as \$n | \$drop | map(. == \$n) | any | not))" \
"${json_file}" > "${json_file}.tmp"
jq '(.rawdata.templates[0].volumes | map(.name)) as $keep
| .rawdata.containers[].volumeMounts |= map(select(.name as $n | $keep | map(. == $n) | any))' \
"${json_file}.tmp" > "${json_file}"
rm -f "${json_file}.tmp"
fi
+}
+
+render_patch_file() {
+ local json_template="${CONFIG["AS_JSON_TEMPLATE_FILE"]}"
+ local json_file="${CONFIG["AS_JSON_FILE"]}"
+
+ info "Rendering AgentServer templates"
+ render_config_template "${json_template}" "${json_file}" "DEPLOY_VARS"
+
+ if ! jq . "${json_file}" >/dev/null 2>&1; then
+ error "AgentServer JSON rendering failed, invalid JSON format: ${json_file}"
+ fi
+
+ inject_data_volume "${json_file}"
+ drop_hostpath_volumes "${json_file}"
success "AgentServer configuration rendered"
}
diff --git a/deploy/enterprise/template_handler.sh b/deploy/enterprise/template_handler.sh
index 76cdd59f50..7a8af07e6c 100755
--- a/deploy/enterprise/template_handler.sh
+++ b/deploy/enterprise/template_handler.sh
@@ -115,18 +115,6 @@ mount_core_pkg() {
"${DEPLOY_VARS["CORE_POD_PKG_PATH"]}"
}
-# User Web 挂载代码时先构建静态资源,再走与产品镜像相同的入口。
-# Vite dev HTML 使用根路径资源,不能完整经由 Manager Web 的 /chat 子路径代理。
-run_web_mounted() {
- local file="$1"
- [ -z "${DEPLOY_VARS["CLAW_POD_CODE_PATH"]:-}" ] && return
- local root="${DEPLOY_VARS["CLAW_POD_CODE_PATH"]}"
- local workdir="${root}/jiuwenswarm/channels/web/frontend"
-
- yq eval 'select(.kind == "Deployment").spec.template.spec.containers[0].command = ["/bin/sh", "-c"]' -i "${file}"
- yq eval 'select(.kind == "Deployment").spec.template.spec.containers[0].args = ["cd '"${workdir}"' && npm run build && cd '"${root}"' && exec jiuwenswarm-start web"]' -i "${file}"
-}
-
enable_dev_mode_if_needed() {
[ "${DEPLOY_VARS["MODE"]}" != "dev" ] && return
@@ -140,9 +128,6 @@ enable_dev_mode_if_needed() {
web)
[ "${DEPLOY_VARS["IS_MOUNT_WEB_CODE"]}" != "true" ] && return
mount_claw_code "${file}"
- mount_runtime_pkg "${file}"
- mount_core_pkg "${file}"
- run_web_mounted "${file}"
;;
manager-server | runtime | identity)
mount_runtime_code "${file}"
@@ -162,8 +147,6 @@ enable_dev_mode_if_needed() {
yq eval 'select(.kind == "Deployment").spec.template.spec.nodeName = "'"${DEPLOY_VARS["CURRENT_NODE_NAME"]}"'"' -i "${file}"
yq eval 'select(.kind == "Deployment").spec.template.spec.securityContext.fsGroup = 0' -i "${file}"
yq eval 'select(.kind == "Deployment").spec.template.spec.containers[0].securityContext = {
- "allowPrivilegeEscalation": true,
- "runAsNonRoot": false,
"runAsUser": 0,
"runAsGroup": 0
}' -i "${file}"
diff --git a/deploy/enterprise/templates/agentserver.template.env b/deploy/enterprise/templates/agentserver.template.env
index 0e72925997..030e1fa1bd 100644
--- a/deploy/enterprise/templates/agentserver.template.env
+++ b/deploy/enterprise/templates/agentserver.template.env
@@ -9,6 +9,7 @@ TZ=<<TIMEZONE>>
ROLE=agentserver
HOME=<<CLAW_HOME>>
LOG_ROOT_PATH=<<CLAW_HOME>>
+DB_CONNECT_TIMEOUT=<<DB_CONNECT_TIMEOUT>>
JIUWENSWARM_EDITION=enterprise
# 企业版工具黑名单(覆盖 config.yaml 中 react.disabled_tools 的 ${DISABLED_TOOLS-...})
@@ -31,17 +32,9 @@ CHECKPOINT_DB_TYPE=<<DB_TYPE>>
# 日志
LLM_SSL_VERIFY=False
-LOG_MASK_ENABLED=false
+LOG_MASK_ENABLED=<<LOG_MASK_ENABLED>>
LOG_TO_FILE_ENABLED=true
-# 沙箱配置
-JIUWENCLAW_SANDBOX_ENABLED=true
-JIUWENCLAW_SANDBOX_URL=http://127.0.0.1:<<JIUWENBOX_PORT>>
-JIUWENCLAW_SANDBOX_TYPE=jiuwenbox
-JIUWENCLAW_SANDBOX_STARTUP_MODE=external
-JIUWENCLAW_SANDBOX_PRESERVE_FILE_SHARING_MODE=mount
-JIUWENBOX_FALLBACK_ON_FAILURE=False
-
# 对象存储(与 deploy/.env OBS_* 对齐;企业下载 put / Gateway materialize 共用)
# OBS_URL 为空时由 runtime_handler 填内置 MinIO headless 地址
OBS_URL=<<OBS_URL>>
diff --git a/deploy/enterprise/templates/agentserver.template.json b/deploy/enterprise/templates/agentserver.template.json
index 40212227e0..824a3eeca1 100644
--- a/deploy/enterprise/templates/agentserver.template.json
+++ b/deploy/enterprise/templates/agentserver.template.json
@@ -99,7 +99,8 @@
}
],
"securityContext": {
- "privileged": true,
+ "runAsUser": 0,
+ "runAsGroup": 0,
"capabilities": {
"add": [
"SYS_ADMIN",
@@ -139,6 +140,7 @@
"templates": [
{
"template_id": "default",
+ "fsGroup": 0,
"template_name": "default",
"main_container_id": "c-agentserver",
"sidecar_container_ids": [
@@ -148,7 +150,7 @@
"namespace": "<<NAMESPACE>>",
"nodeName": "<<CURRENT_NODE_NAME>>",
"sse_path": "/api/v1/events/stream",
- "scope_concurrency": 3,
+ "scope_concurrency": 6,
"pod_concurrency": 2,
"session_ttl": 60,
"pod_ttl": 3600,
@@ -183,12 +185,6 @@
"type": "Directory"
}
},
- {
- "name": "data",
- "persistentVolumeClaim": {
- "claimName": "<<CLAW_PVC>>"
- }
- },
{
"name": "agentserver-config",
"configMap": {
diff --git a/deploy/enterprise/templates/gateway.template.yaml b/deploy/enterprise/templates/gateway.template.yaml
index b15b6dc9cc..d97a43d03b 100644
--- a/deploy/enterprise/templates/gateway.template.yaml
+++ b/deploy/enterprise/templates/gateway.template.yaml
@@ -15,6 +15,8 @@ spec:
labels:
app: <<GATEWAY_NAME>>
spec:
+ securityContext:
+ fsGroup: 0
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution: # 软限制:优先把pod分开部署,但如果资源紧张、只有一个节点可用的时候,也允许它们挤在同一台机器上
@@ -31,6 +33,9 @@ spec:
- name: gateway
image: <<GATEWAY_IMAGE>>
imagePullPolicy: IfNotPresent
+ securityContext:
+ runAsUser: 0
+ runAsGroup: 0
# 调试模式:gateway 崩溃后容器不退出(sleep 保活),便于进 Pod 排查。
# command: ["/bin/sh", "-c"]
# args: ["jiuwenswarm-gateway; echo '[debug-keepalive] gateway exited rc=$?, sleeping'; sleep infinity"]
diff --git a/deploy/enterprise/templates/identity.template.yaml b/deploy/enterprise/templates/identity.template.yaml
index 66752579f5..709f650cb3 100644
--- a/deploy/enterprise/templates/identity.template.yaml
+++ b/deploy/enterprise/templates/identity.template.yaml
@@ -29,6 +29,8 @@ spec:
labels:
app: <<IDENTITY_NAME>>
spec:
+ securityContext:
+ fsGroup: 1000
containers:
- name: <<IDENTITY_NAME>>
image: <<IDENTITY_IMAGE>>
diff --git a/deploy/enterprise/templates/manager-server.template.yaml b/deploy/enterprise/templates/manager-server.template.yaml
index 228427cdfc..fb4b9bb19c 100644
--- a/deploy/enterprise/templates/manager-server.template.yaml
+++ b/deploy/enterprise/templates/manager-server.template.yaml
@@ -49,6 +49,8 @@ spec:
labels:
app: <<MANAGER_SERVER_NAME>>
spec:
+ securityContext:
+ fsGroup: 1000
containers:
- name: manager
image: <<MANAGER_SERVER_IMAGE>>
diff --git a/deploy/enterprise/templates/manager-web.template.yaml b/deploy/enterprise/templates/manager-web.template.yaml
index d716d1a4de..bfe318b645 100644
--- a/deploy/enterprise/templates/manager-web.template.yaml
+++ b/deploy/enterprise/templates/manager-web.template.yaml
@@ -15,6 +15,8 @@ spec:
labels:
app: <<MANAGER_WEB_NAME>>
spec:
+ securityContext:
+ fsGroup: 0
containers:
- name: manager-web
image: <<MANAGER_WEB_IMAGE>>
diff --git a/deploy/enterprise/templates/runtime.template.yaml b/deploy/enterprise/templates/runtime.template.yaml
index 0a608c5aea..bab7064c9f 100644
--- a/deploy/enterprise/templates/runtime.template.yaml
+++ b/deploy/enterprise/templates/runtime.template.yaml
@@ -66,6 +66,8 @@ spec:
values:
- <<AGENT_RUNTIME_NAME>>
topologyKey: "kubernetes.io/hostname"
+ securityContext:
+ fsGroup: 1000
containers:
- name: agent-runtime
image: <<AGENT_RUNTIME_IMAGE>>
diff --git a/deploy/enterprise/templates/web.template.yaml b/deploy/enterprise/templates/web.template.yaml
index 10aa5d04e9..fc7a822c52 100644
--- a/deploy/enterprise/templates/web.template.yaml
+++ b/deploy/enterprise/templates/web.template.yaml
@@ -15,6 +15,8 @@ spec:
labels:
app: <<WEB_NAME>>
spec:
+ securityContext:
+ fsGroup: 0
containers:
- name: web
image: <<WEB_IMAGE>>
@@ -30,40 +32,18 @@ spec:
- secretRef:
name: <<SECRET_CM_NAME>>
env:
- - name: JIUWENCLAW_WEB_HOST
- value: "0.0.0.0"
- - name: FRONTEND_HOST
- value: "0.0.0.0"
+ - name: WEB_HTTP_PORT
+ value: "<<WEB_HTTP_PORT>>"
- name: JIUWENSWARM_EDITION
value: "enterprise"
- name: LOGIN_AUTH_SIMULATE
- value: "<<APPLY_PATCH>>"
- - name: FRONTEND_PORT
- value: "<<WEB_HTTP_PORT>>"
+ value: "<<LOGIN_AUTH_SIMULATE>>"
- name: WEB_TRANSPORT
value: "http"
- - name: ENTERPRISE_WEB_WS_HOST
- value: "0.0.0.0"
- - name: ENTERPRISE_WEB_WS_PORT
- value: "<<WEB_WS_PORT>>"
- name: GATEWAY_URL
value: "http://<<GATEWAY_NAME>>:<<WEB_PORT>>"
- name: GATEWAY_WEB_HTTP_URL
value: "http://<<GATEWAY_NAME>>:<<GATEWAY_WEB_HTTP_PORT>>"
- - name: WS_ORIGIN_CHECK_ENABLED
- value: "<<WS_ORIGIN_CHECK_ENABLED>>"
- - name: WS_ALLOWED_ORIGINS
- value: "<<WS_ALLOWED_ORIGINS>>"
- - name: WEB_DB_TYPE
- value: "<<DB_TYPE>>"
- - name: WEB_DB_HOST
- value: "<<DB_HOST>>"
- - name: WEB_DB_PORT
- value: "<<DB_PORT>>"
- - name: WEB_DB_USER
- value: "<<WEB_DB_USER>>"
- - name: WEB_DB_NAME
- value: "<<WEB_DB_NAME>>"
- name: TZ
value: "<<TIMEZONE>>"
- name: OBS_URL
diff --git a/deploy/enterprise/update_conf.sh b/deploy/enterprise/update_conf.sh
index 4283996167..f4a46a85de 100755
--- a/deploy/enterprise/update_conf.sh
+++ b/deploy/enterprise/update_conf.sh
@@ -12,3 +12,7 @@ yq eval '.gateway.edition = "enterprise"' -i "${DEST_FILE}"
yq eval '.gateway.session_map_scope = "<<GATEWAY_SESSION_MAP_SCOPE>>"' -i "${DEST_FILE}"
yq eval '.channels.feishu = {}' -i "${DEST_FILE}"
yq eval '.react.max_iterations = "<<AGENT_SERVER_REACT_MAX_ITER>>"' -i "${DEST_FILE}"
+yq eval '.sandbox.enabled = true' -i "${DEST_FILE}"
+yq eval '.sandbox.startup_mode = "external"' -i "${DEST_FILE}"
+yq eval '.sandbox.url = "http://127.0.0.1:<<JIUWENBOX_PORT>>"' -i "${DEST_FILE}"
+yq eval '.sandbox.type = "jiuwenbox"' -i "${DEST_FILE}"
diff --git a/docker/Dockerfile.claw b/docker/Dockerfile.claw
index 76fd14d5ce..2f8440a655 100644
--- a/docker/Dockerfile.claw
+++ b/docker/Dockerfile.claw
@@ -5,11 +5,12 @@ ARG AGENT_RUNTIME_REPOS
ARG AGENT_RUNTIME_BRANCH
ARG PIP_EXTRA_ARGS="-i https://mirrors.aliyun.com/pypi/simple/"
-RUN useradd --create-home --shell /bin/bash app \
- && mkdir -p /app/jiuwenswarm && chown app:app /app/jiuwenswarm
+# gateway/agentserver 统一以 root 运行(k8s 模板亦显式固化 runAsUser 0):
+# hostPath 代码挂载与 NFS 卷读写不再有属主适配问题
+RUN mkdir -p /app/jiuwenswarm
WORKDIR /app/jiuwenswarm
-COPY --chown=app:app . /app/jiuwenswarm/
+COPY . /app/jiuwenswarm/
RUN sed -i '/openjiuwen_runtime_foundation/d' pyproject.toml
RUN sed -i '/openjiuwen_runtime_management/d' packages/jiuwenclaw-ee/gateway/extensions/runtime_management_extension/pyproject.toml
@@ -25,18 +26,9 @@ RUN uv pip install --system \
# Prefetch tiktoken BPE at build time (avoids sync download on first request).
ENV TIKTOKEN_CACHE_DIR=/opt/tiktoken-cache
RUN mkdir -p /opt/tiktoken-cache \
- && python -c "import tiktoken; tiktoken.get_encoding('cl100k_base')" \
- && chown -R app:app /opt/tiktoken-cache \
- && chmod -R u+rwX,go+rX /opt/tiktoken-cache
+ && python -c "import tiktoken; tiktoken.get_encoding('cl100k_base')"
RUN yq -y -i '.dependencies = {}' jiuwenswarm/extensions/symphony/extension.yaml
-# 预建 workspace(app 属主):product 模式 gateway/agentserver 以 app 运行,
-# kubelet 为 config subPath 挂载创建的中间目录是 root 属主,运行期会 EACCES
-RUN mkdir -p /home/app/.jiuwenswarm/config && chown -R app:app /home/app/.jiuwenswarm
-
-USER app
-ENV PATH=$PATH:/home/app/.local/bin
-
# 启动入口:按 ROLE 环境变量决定运行 gateway / agentserver(见 docker/start.sh)
CMD ["/app/jiuwenswarm/docker/start.sh"]
diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web
index 01d8a936fb..29023e9ab1 100644
--- a/docker/Dockerfile.web
+++ b/docker/Dockerfile.web
@@ -1,15 +1,30 @@
-ARG BASE_IMAGE
-ARG IMAGE_VERSION
-FROM ${BASE_IMAGE}:${IMAGE_VERSION}
+ARG NODE_IMAGE=node:20-alpine
+ARG NGINX_IMAGE=nginx:1.27-alpine
-ARG NPM_REGISTRY=https://registry.npmmirror.com
+# ---------- 阶段1:前端构建 ----------
+FROM ${NODE_IMAGE} AS web-builder
-WORKDIR /app/jiuwenswarm/jiuwenswarm/channels/web/frontend
+ARG NPM_REGISTRY=https://registry.npmmirror.com
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
+
+WORKDIR /build/jiuwenswarm/channels/web/frontend
+COPY jiuwenswarm/channels/web/frontend/package.json \
+ jiuwenswarm/channels/web/frontend/package-lock.json ./
RUN npm install
+
+COPY jiuwenswarm/channels/web/frontend/ ./
+COPY jiuwenswarm/scripts/ /build/jiuwenswarm/scripts/
+COPY jiuwenswarm/resources/ /build/jiuwenswarm/resources/
RUN npm run build
-WORKDIR /app/jiuwenswarm
+# ---------- 阶段2:nginx 运行 ----------
+FROM ${NGINX_IMAGE}
+
+COPY docker/web.nginx.conf.template /etc/nginx/templates/default.conf.template
+COPY docker/web-optional-upstreams.sh /docker-entrypoint.d/40-optional-upstreams.sh
+RUN chmod +x /docker-entrypoint.d/40-optional-upstreams.sh \
+ && mkdir -p /etc/nginx/optional-upstreams
+COPY --from=web-builder /build/jiuwenswarm/channels/web/frontend/dist \
+ /app/jiuwenswarm/jiuwenswarm/channels/web/frontend/dist
EXPOSE 5173
-CMD ["jiuwenswarm-start", "web"]
\ No newline at end of file
diff --git a/docker/web-optional-upstreams.sh b/docker/web-optional-upstreams.sh
new file mode 100755
index 0000000000..56d0ab7b56
--- /dev/null
+++ b/docker/web-optional-upstreams.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# 按 env 生成 User Web 可选自定义上游(/idp、/manager-api)的 location 片段。
+#
+# 语义对齐 jiuwenswarm/channels/web/app_web.py 的 _dispatch_proxy/_proxy_named_http:
+# - /idp 精确 → 上游 /; /idp/x → 上游 /x(前缀剥离)
+# - /manager-api 精确 → 上游 /api;/manager-api/x → 上游 /api/x
+# - target 未设置/为空 → 502 "proxy target not configured"(逐请求,Python 同款)
+# - 查询串由 nginx 自动透传;所有方法均代理
+#
+# 这两个上游是客户自定义钩子(自定义认证中心/管理面),不参与产品默认接线:
+# - env 未设置或为空
+# → 生成 502 兜底 location,保证 nginx 可启动
+# - env 配置了自定义地址 → 生成反向代理 location(域名在 nginx 启动时解析)
+#
+# 由 nginx 官方镜像 entrypoint 在 envsubst(20-envsubst)之后执行,
+# 片段经 /etc/nginx/conf.d 主配置内的 include(位于 server 块中)生效;
+# 代理通用参数(Accept-Encoding 透传、http/1.1、超时)继承主配置 server 级设置。
+
+CONF=/etc/nginx/optional-upstreams/user-web-custom.conf
+: > "$CONF"
+
+if [ -n "$USER_WEB_IDP_TARGET" ]; then
+ cat >> "$CONF" <<EOF
+location = /idp {
+ rewrite ^ / break;
+ proxy_pass ${USER_WEB_IDP_TARGET};
+}
+location ^~ /idp/ {
+ rewrite ^/idp/(.*)\$ /\$1 break;
+ proxy_pass ${USER_WEB_IDP_TARGET};
+}
+EOF
+else
+ cat >> "$CONF" <<'EOF'
+location = /idp { return 502; }
+location ^~ /idp/ { return 502; }
+EOF
+fi
+
+if [ -n "$USER_WEB_MANAGER_TARGET" ]; then
+ cat >> "$CONF" <<EOF
+location = /manager-api {
+ rewrite ^ /api break;
+ proxy_pass ${USER_WEB_MANAGER_TARGET};
+}
+location ^~ /manager-api/ {
+ rewrite ^/manager-api/(.*)\$ /api/\$1 break;
+ proxy_pass ${USER_WEB_MANAGER_TARGET};
+}
+EOF
+else
+ cat >> "$CONF" <<'EOF'
+location = /manager-api { return 502; }
+location ^~ /manager-api/ { return 502; }
+EOF
+fi
diff --git a/docker/web.nginx.conf.template b/docker/web.nginx.conf.template
new file mode 100644
index 0000000000..2fd3a79267
--- /dev/null
+++ b/docker/web.nginx.conf.template
@@ -0,0 +1,121 @@
+# =====================================================================
+# Web(User Web)nginx 配置模板
+#
+# 由 nginx 官方镜像 entrypoint 在启动时 envsubst 渲染:
+# /etc/nginx/templates/default.conf.template → /etc/nginx/conf.d/default.conf
+# 环境变量与 web.template.yaml 注入的同名 env 一致(必须全部提供):
+# WEB_HTTP_PORT / GATEWAY_URL / GATEWAY_WEB_HTTP_URL /
+# USER_WEB_IDP_TARGET / USER_WEB_MANAGER_TARGET /
+# JIUWENSWARM_EDITION / LOGIN_AUTH_SIMULATE / WEB_TRANSPORT
+#
+# 语义对齐 jiuwenswarm/channels/web/app_web.py,已知差异:
+# 1) /api 分流:/api/sessions*、/api/v1* → Gateway Web HTTP;其余 /api/* →
+# Gateway WebChannel(与 _is_web_http_route/_is_api_route 一致)
+# 2) index.html 的运行时配置注入由 sub_filter 完成(占位符与 Python 版相同,
+# 值来自部署期 env,部署期内固定;Python 版是逐请求注入,语义等价)
+# 3) 非常规方法(如 POST /chat/* 类静态路径)会被转发而非 405
+# 4) 上游 Service DNS 需在本容器启动时已可解析(nginx 启动时解析
+# proxy_pass 域名);部署工具先建 Service 后起 pod,天然满足
+# =====================================================================
+
+map $http_upgrade $connection_upgrade {
+ default upgrade;
+ "" "";
+}
+
+server {
+ listen ${WEB_HTTP_PORT};
+ server_name _;
+
+ # Python 版对请求体大小无限制(文件上传走 /file-api)
+ client_max_body_size 0;
+
+ # 上游不做压缩(中继语义:响应原文透传),出口压缩由 nginx 负责
+ proxy_set_header Accept-Encoding "";
+ proxy_http_version 1.1;
+ proxy_connect_timeout 10s;
+ proxy_send_timeout 30s;
+ proxy_read_timeout 30s;
+
+ root /app/jiuwenswarm/jiuwenswarm/channels/web/frontend/dist;
+ index index.html;
+
+ gzip on;
+ gzip_vary on;
+ gzip_types text/css application/javascript application/json image/svg+xml;
+
+ # ---------- index.html 运行时配置注入(_inject_user_web_runtime_config) ----------
+ sub_filter '__JIUWENSWARM_EDITION_VALUE__' '${JIUWENSWARM_EDITION}';
+ sub_filter '__JIUWEN_LOGIN_AUTH_SIMULATE_VALUE__' '${LOGIN_AUTH_SIMULATE}';
+ sub_filter '__JIUWEN_WEB_TRANSPORT_VALUE__' '${WEB_TRANSPORT}';
+ sub_filter_once on;
+ sub_filter_types text/html;
+
+ # ---------- 可选自定义上游(/idp、/manager-api) ----------
+ # 客户自定义认证中心/管理面的挂载点:由 entrypoint 脚本
+ include /etc/nginx/optional-upstreams/*.conf;
+
+ # ---------- Gateway Web HTTP 组(gateway-api/file-api/share-api/sessions/v1) ----------
+ location = /gateway-api { return 307 /gateway-api/; }
+ location ^~ /gateway-api/ {
+ rewrite ^/gateway-api/(.*)$ /api/$1 break;
+ proxy_pass ${GATEWAY_WEB_HTTP_URL};
+ proxy_buffering off;
+ proxy_cache off;
+ proxy_read_timeout 3600s;
+ proxy_send_timeout 3600s;
+ }
+ location ^~ /file-api/ {
+ proxy_pass ${GATEWAY_WEB_HTTP_URL};
+ proxy_read_timeout 300s;
+ proxy_send_timeout 300s;
+ }
+ location ^~ /share-api/ {
+ proxy_pass ${GATEWAY_WEB_HTTP_URL};
+ proxy_read_timeout 300s;
+ proxy_send_timeout 300s;
+ }
+ location ^~ /api/sessions {
+ proxy_pass ${GATEWAY_WEB_HTTP_URL};
+ }
+ location = /api/v1 { proxy_pass ${GATEWAY_WEB_HTTP_URL}; }
+ location ^~ /api/v1/ {
+ proxy_pass ${GATEWAY_WEB_HTTP_URL};
+ }
+
+ # ---------- 其余 /api → Gateway WebChannel ----------
+ location = /api { proxy_pass ${GATEWAY_URL}; }
+ location /api/ {
+ proxy_pass ${GATEWAY_URL};
+ proxy_buffering off;
+ proxy_read_timeout 3600s;
+ proxy_send_timeout 3600s;
+ }
+
+ # ---------- /ws → Gateway WebChannel WebSocket(upgrade 隧道) ----------
+ location = /ws {
+ proxy_pass ${GATEWAY_URL};
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+ proxy_set_header Accept-Encoding "";
+ proxy_read_timeout 3600s;
+ proxy_send_timeout 3600s;
+ }
+ location /ws/ {
+ proxy_pass ${GATEWAY_URL};
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+ proxy_set_header Accept-Encoding "";
+ proxy_read_timeout 3600s;
+ proxy_send_timeout 3600s;
+ }
+
+ # ---------- SPA 静态资源 ----------
+ location = /index.html {
+ add_header Cache-Control "no-cache, must-revalidate";
+ }
+ location / {
+ try_files $uri $uri/ /index.html;
+ add_header Cache-Control "no-cache, must-revalidate";
+ }
+}
diff --git a/jiuwenbox/src/jiuwenbox/server/runtime/process.py b/jiuwenbox/src/jiuwenbox/server/runtime/process.py
index 9bc3e69cac..7a97aff563 100644
--- a/jiuwenbox/src/jiuwenbox/server/runtime/process.py
+++ b/jiuwenbox/src/jiuwenbox/server/runtime/process.py
@@ -11,6 +11,7 @@ from __future__ import annotations
import asyncio
import base64
+import ctypes
import dataclasses
import errno
import json
diff --git a/jiuwenswarm/common/config.py b/jiuwenswarm/common/config.py
index f013d9fc2f..e7fa8e7d3c 100644
--- a/jiuwenswarm/common/config.py
+++ b/jiuwenswarm/common/config.py
@@ -17,6 +17,7 @@ from ruamel.yaml.scalarstring import DoubleQuotedScalarString, PlainScalarString
import yaml
import portalocker
+from jiuwenswarm.edition import is_enterprise
from jiuwenswarm.common.kv_cache_affinity_config import (
ASCEND_AFFINITY_PROVIDER,
get_default_model_provider as resolve_default_model_provider,
@@ -2994,6 +2995,13 @@ def update_sandbox_endpoint(
所有 ``None`` 入参表示"本次不修改该字段, 保留 config.yaml 中既有值",
以方便 ``_handle_sandbox_enable`` 在不同阶段分批落盘。
"""
+ # 企业级:config.yaml 为只读挂载, 不回写
+ if is_enterprise():
+ logger.info(
+ "[config] enterprise: config.yaml 为只读挂载, "
+ "sandbox endpoint 不持久化(仅运行期生效)")
+ return set()
+
url_value = str(url or "").strip()
type_value = str(sandbox_type or "").strip()
if not url_value or not type_value:
@@ -3126,6 +3134,13 @@ def update_sandbox_runtime(patch: dict[str, Any]) -> dict[str, Any]:
``files`` 字典若提供则整体替换;其余键按值合并。 ``idle_*`` 字段
接受整数秒数 (``<= 0`` 归一化为 ``None`` = 禁用淘汰) 或 ``None``。
"""
+ # 企业级:config.yaml 为只读挂载,不回写(返回当前 runtime,未变更)
+ if is_enterprise():
+ logger.info(
+ "[config] enterprise: config.yaml 为只读挂载, "
+ "sandbox runtime 不持久化(仅运行期生效)")
+ return dict(get_sandbox_runtime() or {})
+
if not isinstance(patch, dict):
raise ValueError("patch must be an object")
diff --git a/jiuwenswarm/common/utils.py b/jiuwenswarm/common/utils.py
index 37b9f978bd..6928afa70d 100644
--- a/jiuwenswarm/common/utils.py
+++ b/jiuwenswarm/common/utils.py
@@ -3345,9 +3345,9 @@ async def reload_logging_levels() -> None:
update_log_levels()
return
try:
- from jiuwenswarm.server.runtime.enterprise_config import gateway_db
+ from jiuwenswarm.server.runtime.enterprise_config import db_queries
- rows = await gateway_db.list_records(_LOGGING_CONFIG_TABLE)
+ rows = await db_queries.list_records(_LOGGING_CONFIG_TABLE)
row = rows[0] if rows else None
apply_logging_config_payload(
_logging_config_row_to_dict(row) if row is not None else None,
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.py
index 2088770078..1f3c7ab1f5 100644
--- a/jiuwenswarm/gateway/message_handler/message_handler.py
+++ b/jiuwenswarm/gateway/message_handler/message_handler.py
@@ -173,6 +173,16 @@ class ModeChangeCancelParams:
new_mode_label: str
+@dataclass
+class StreamEmitParams:
+ """流式异常收尾补发(chat.error / chat.final)所需的具名参数(避免过长形参列表)。"""
+
+ request_id: str
+ channel_id: str
+ session_id: str | None
+ request_metadata: dict[str, Any] | None
+
+
if TYPE_CHECKING:
from jiuwenswarm.common.e2a.models import E2AEnvelope
from jiuwenswarm.gateway.routing.agent_client import AgentServerClient
@@ -3555,22 +3565,20 @@ class MessageHandler(FileTransferMixin, ABC):
async def _publish_stream_cancelled_final(
self,
- request_id: str,
- channel_id: str,
- session_id: str | None,
- request_metadata: dict[str, Any] | None,
+ params: StreamEmitParams,
) -> None:
"""流式任务被网关取消时补发 chat.final,带 is_complete(供飞书等通道合并缓冲)。"""
from jiuwenswarm.common.schema.message import Message, EventType
+ request_metadata = params.request_metadata
group_digital_avatar = bool(request_metadata.get("group_digital_avatar", False)) if request_metadata else False
enable_memory = bool(request_metadata.get("enable_memory", True)) if request_metadata else True
out = Message(
- id=request_id,
+ id=params.request_id,
type="event",
- channel_id=channel_id,
- session_id=session_id,
+ channel_id=params.channel_id,
+ session_id=params.session_id,
params={},
timestamp=time.time(),
ok=True,
@@ -3587,42 +3595,40 @@ class MessageHandler(FileTransferMixin, ABC):
await self.publish_robot_messages(out)
logger.info(
"[MessageHandler] 已发送流式取消结束帧: request_id=%s session_id=%s",
- request_id,
- session_id,
+ params.request_id,
+ params.session_id,
)
async def _publish_stream_connection_error(
self,
- request_id: str,
- channel_id: str,
- session_id: str | None,
- request_metadata: dict[str, Any] | None,
+ params: StreamEmitParams,
error: str,
+ code: str = "AGENT_SERVER_CONNECTION_CLOSED",
) -> None:
"""Publish a visible stream error when the AgentServer connection drops."""
from jiuwenswarm.common.schema.message import Message, EventType
out = Message(
- id=request_id,
+ id=params.request_id,
type="event",
- channel_id=channel_id,
- session_id=session_id,
+ channel_id=params.channel_id,
+ session_id=params.session_id,
params={},
timestamp=time.time(),
ok=False,
payload={
"event_type": EventType.CHAT_ERROR.value,
"error": error,
- "code": "AGENT_SERVER_CONNECTION_CLOSED",
+ "code": code,
"is_complete": True,
},
event_type=EventType.CHAT_ERROR,
- metadata=request_metadata,
+ metadata=params.request_metadata,
)
await self.publish_robot_messages(out)
logger.warning(
"[MessageHandler] Stream 因 AgentServer WebSocket 断开而结束: request_id=%s error=%s",
- request_id,
+ params.request_id,
error,
)
@@ -4829,6 +4835,13 @@ class MessageHandler(FileTransferMixin, ABC):
rid = env.request_id or ""
channel_id = env.channel or ""
stream_app_id = self._stream_app_ids.get(rid, "") # 提前捕获,_pop_stream_tracking 后会清除
+ # 流式异常收尾补发(chat.error/chat.final)共用的具名参数
+ emit_params = StreamEmitParams(
+ request_id=rid,
+ channel_id=channel_id,
+ session_id=session_id,
+ request_metadata=request_metadata,
+ )
cancelled = False
has_processing_status_false = False
_proc_count = 0
@@ -4897,10 +4910,7 @@ class MessageHandler(FileTransferMixin, ABC):
if "AgentServer WebSocket connection closed" not in str(exc):
raise
await self._publish_stream_connection_error(
- rid,
- channel_id,
- session_id,
- request_metadata,
+ emit_params,
str(exc),
)
except Exception as exc:
@@ -4910,9 +4920,13 @@ class MessageHandler(FileTransferMixin, ABC):
"[MessageHandler] Stream 异常: request_id=%s total_chunks=%s error=%s",
rid, _proc_count, exc,
)
- await self._publish_stream_cancelled_final(
- rid, channel_id, session_id, request_metadata,
+ # 快失败/路由类异常(如 SCOPE_FULL)必须以 CHAT_ERROR 事件外显,
+ # 否则前端只收到空 chat.final,表现为静默无响应
+ await self._publish_stream_connection_error(
+ emit_params, str(exc),
+ code="GATEWAY_STREAM_ERROR",
)
+ await self._publish_stream_cancelled_final(emit_params)
raise # 重新抛出,让调用者知道任务被取消
finally:
telemetry_outcome["error"] = request_error
diff --git a/jiuwenswarm/infrastructure/log_masking/engine.py b/jiuwenswarm/infrastructure/log_masking/engine.py
index 03e2c75472..69f6abbe62 100644
--- a/jiuwenswarm/infrastructure/log_masking/engine.py
+++ b/jiuwenswarm/infrastructure/log_masking/engine.py
@@ -3,6 +3,7 @@
from __future__ import annotations
from jiuwenswarm.edition import is_enterprise
+from jiuwenswarm.infrastructure.config import settings
import logging
import os
@@ -481,6 +482,10 @@ class LogMaskingEngine:
def sanitize(self, text: str) -> str:
if not text:
return text
+ # 总开关(LOG_MASK_ENABLED):false 时日志脱敏整体关闭,
+ # 消息/identity/兜底层所有路径原样输出
+ if not settings.log_masking_enabled:
+ return text
if len(text) > _MAX_SANITIZE_TEXT_LEN:
text = text[:_MAX_SANITIZE_TEXT_LEN]
masked = text
diff --git a/jiuwenswarm/server/agent_ws_server.py b/jiuwenswarm/server/agent_ws_server.py
index 15d7247a2f..8df058be7c 100644
--- a/jiuwenswarm/server/agent_ws_server.py
+++ b/jiuwenswarm/server/agent_ws_server.py
@@ -22,6 +22,7 @@ from openjiuwen.core.common.logging import server_logger
from websockets.exceptions import ConnectionClosed as WebSocketConnectionClosed
from jiuwenswarm.agents.harness.common.auto_harness import AutoHarnessService, reset_harness_packages_state
+from jiuwenswarm.edition import is_enterprise
from jiuwenswarm.server.gateway_push.wire import build_server_push_wire
from jiuwenswarm.server.ws_send import send_wire_payload
from jiuwenswarm.agents.harness.common.tools.acp_output_tools import get_acp_output_manager
@@ -606,6 +607,15 @@ class AgentWebSocketServer:
产品起不来, 也无从修复)。
"""
try:
+ # 企业级:沙箱由 agentserver Pod 内的 jiuwenbox 容器提供
+ # (K8s 启动,external),不走 internal 子进程拉起;config.yaml 为
+ # 部署工具下发的只读挂载,也不做回写
+ if is_enterprise():
+ logger.info(
+ "[sandbox_lifecycle] enterprise: sandbox 由 jiuwenbox "
+ "sidecar 提供, skipping internal jiuwenbox auto-start"
+ )
+ return
# 非 Linux/Windows 平台直接跳过 auto-start: jiuwenbox 依赖平台专属
# 内核能力 (Linux: bwrap/Landlock/命名空间; Windows: win_setup 用户
# 创建 + WFP + ACL), 其它平台 (macOS 等) 起不来; 即便 spawn 成功后续