使用jingrow统一crud函数重构apps/jingrow/jingrow/ai/pagetype/local_ai_agent/__init__.py
This commit is contained in:
parent
5018c4bead
commit
475a6dfab3
@ -3,14 +3,13 @@
|
||||
|
||||
import jingrow
|
||||
import logging
|
||||
from jingrow.utils.jingrow_api import get_record_list, get_pagetype_module_app, get_record
|
||||
from jingrow.utils.jinja import render_template
|
||||
|
||||
|
||||
def _get_all_local_ai_agents():
|
||||
"""获取所有启用的事件触发 Local Ai Agent,支持按PageType和Module分组缓存返回。
|
||||
"""
|
||||
res = get_record_list(
|
||||
data = jingrow.get_list(
|
||||
"Local Ai Agent",
|
||||
filters=[["enabled", "=", 1], ["trigger_mode", "=", "Event Trigger"]],
|
||||
fields=[
|
||||
@ -23,7 +22,6 @@ def _get_all_local_ai_agents():
|
||||
"condition",
|
||||
],
|
||||
)
|
||||
data = res.get("data", []) if res.get("success") else []
|
||||
|
||||
agents: dict[str, list[dict]] = {}
|
||||
for agent in data:
|
||||
@ -69,8 +67,8 @@ def run_agent(pg=None, method=None, event=None, page=None, **kwargs):
|
||||
# 获取 pagetype 所属 module(通过 API 获取 module/app)
|
||||
module_name = None
|
||||
try:
|
||||
ma = get_pagetype_module_app(pg_pagetype)
|
||||
if ma.get("success"):
|
||||
ma = jingrow.get_module_app(pg_pagetype)
|
||||
if isinstance(ma, dict) and ma.get("success"):
|
||||
module_name = ma.get("module")
|
||||
except Exception:
|
||||
module_name = None
|
||||
@ -120,9 +118,9 @@ def run_agent(pg=None, method=None, event=None, page=None, **kwargs):
|
||||
_nm = base_ctx.get("name") or _get_pg_field(pg, "name")
|
||||
pg_ctx = base_ctx or {}
|
||||
if _pt and _nm:
|
||||
api_res = get_record(str(_pt), str(_nm))
|
||||
if api_res and api_res.get("success") and isinstance(api_res.get("data"), dict):
|
||||
pg_ctx = api_res.get("data")
|
||||
api_res = jingrow.get_pg(str(_pt), str(_nm))
|
||||
if isinstance(api_res, dict):
|
||||
pg_ctx = api_res
|
||||
result = render_template(cond_tpl, {"pg": pg_ctx})
|
||||
if str(result).strip().lower() in ("true", "1", "yes"):
|
||||
trigger = True
|
||||
@ -148,9 +146,9 @@ def enqueue_local_ai_agent(pg, agent_name):
|
||||
此函数会读取本地智能体配置,调用本地任务创建函数以执行远端/本地智能体。
|
||||
"""
|
||||
try:
|
||||
# 通过 API 获取 Local Ai Agent 详情
|
||||
res = get_record_list("Local Ai Agent", filters=[["name", "=", agent_name]], fields=["name", "agent_name"], limit=1)
|
||||
agent = (res.get("data") or [None])[0] if res.get("success") else None
|
||||
# 通过统一 CRUD 获取 Local Ai Agent 详情
|
||||
items = jingrow.get_list("Local Ai Agent", filters=[["name", "=", agent_name]], fields=["name", "agent_name"], limit=1)
|
||||
agent = (items or [None])[0]
|
||||
if not agent:
|
||||
return
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user