修复智能体事件触发模式Target Module无效的问题
This commit is contained in:
parent
af9a9095a4
commit
fa01e3c5ff
@ -4,7 +4,7 @@
|
||||
import jingrow
|
||||
import logging
|
||||
from jingrow.utils.jinja import render_template
|
||||
from jingrow.utils.jingrow_api import get_record_list, get_page_meta
|
||||
from jingrow.utils.jingrow_api import get_record_list, get_pagetype_module_app
|
||||
|
||||
|
||||
def _get_all_local_ai_agents():
|
||||
@ -32,7 +32,7 @@ def _get_all_local_ai_agents():
|
||||
if tp:
|
||||
agents.setdefault(tp, []).append(agent)
|
||||
elif tm:
|
||||
key = f"module:{str(tm).strip().lower()}"
|
||||
key = f"module:{tm}"
|
||||
agents.setdefault(key, []).append(agent)
|
||||
return agents
|
||||
|
||||
@ -57,17 +57,17 @@ def run_agent(pg=None, method=None, event=None, page=None, **kwargs):
|
||||
agents_by_pagetype = ai_agents.get(pg.pagetype, []) or []
|
||||
|
||||
# module 分组
|
||||
# 获取 pagetype 所属 module(通过 API 获取 meta)
|
||||
# 获取 pagetype 所属 module(通过 API 获取 module/app)
|
||||
module_name = None
|
||||
try:
|
||||
meta_res = get_page_meta(pg.pagetype)
|
||||
if meta_res.get("success"):
|
||||
module_name = (meta_res.get("data") or {}).get("module")
|
||||
ma = get_pagetype_module_app(pg.pagetype)
|
||||
if ma.get("success"):
|
||||
module_name = ma.get("module")
|
||||
except Exception:
|
||||
module_name = None
|
||||
agents_by_module = []
|
||||
if module_name:
|
||||
key = f"module:{str(module_name).strip().lower()}"
|
||||
key = f"module:{module_name}"
|
||||
agents_by_module = ai_agents.get(key, []) or []
|
||||
|
||||
# 合并去重
|
||||
|
||||
@ -458,6 +458,32 @@ def get_page_meta(pagetype: str):
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': f"获取Meta异常: {str(e)}"}
|
||||
|
||||
|
||||
def get_pagetype_module_app(pagetype: str):
|
||||
"""
|
||||
获取指定PageType的 module 与 app。
|
||||
"""
|
||||
try:
|
||||
api_url = f"{Config.jingrow_server_url}/api/action/jingrow.ai.utils.jlocal.get_pagetype_module_app"
|
||||
headers = get_jingrow_api_headers()
|
||||
if not headers:
|
||||
return {'success': False, 'error': 'JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置'}
|
||||
payload = {"pagetype": pagetype}
|
||||
response = requests.post(api_url, json=payload, headers=headers, timeout=10)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if isinstance(data, dict) and 'message' in data:
|
||||
data = data['message']
|
||||
if isinstance(data, dict) and data.get('success'):
|
||||
# 兼容直接返回结构或嵌套 data
|
||||
module_val = data.get('module') or (data.get('data') or {}).get('module')
|
||||
app_val = data.get('app') or (data.get('data') or {}).get('app')
|
||||
return {'success': True, 'module': module_val, 'app': app_val}
|
||||
return {'success': False, 'error': data.get('error', '获取失败') if isinstance(data, dict) else '获取失败'}
|
||||
return {'success': False, 'error': f"HTTP {response.status_code}: {response.text}"}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': f"获取模块信息异常: {str(e)}"}
|
||||
|
||||
def get_record_id(pagetype: str, filters: list = None, field: str = None, value: str = None, site: str = None):
|
||||
"""
|
||||
按条件获取单条记录的 name 值。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user