fix(arch-030,arch-047): workflow steps resolve plugins via contracts at runtime
This commit is contained in:
@@ -218,11 +218,13 @@ async def _handle_mail(
|
||||
return StepResult(error="mail step requires to and subject", abort=True)
|
||||
|
||||
try:
|
||||
from app.plugins.builtins.mail.contracts import MailContract
|
||||
contract = MailContract
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
contract = get_contract("mail")
|
||||
if contract is None:
|
||||
return StepResult(error="mail plugin not available", abort=True)
|
||||
send_fn = contract.get_function("send_email")
|
||||
if send_fn is None:
|
||||
return StepResult(error="mail plugin not available", abort=True)
|
||||
return StepResult(error="mail send_email not exposed via contract yet", abort=True)
|
||||
|
||||
result = await send_fn(
|
||||
db=db,
|
||||
@@ -258,12 +260,14 @@ async def _handle_calendar(
|
||||
action = config.get("action", "create")
|
||||
|
||||
try:
|
||||
from app.plugins.builtins.calendar.contracts import CalendarContract
|
||||
contract = CalendarContract
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
contract = get_contract("calendar")
|
||||
if contract is None:
|
||||
return StepResult(error="calendar plugin not available", abort=True)
|
||||
if action == "create":
|
||||
fn = contract.get_function("create_event")
|
||||
if fn is None:
|
||||
return StepResult(error="calendar plugin not available", abort=True)
|
||||
return StepResult(error="calendar create_event not exposed via contract yet", abort=True)
|
||||
result = await fn(
|
||||
db=db,
|
||||
tenant_id=tenant_id,
|
||||
@@ -275,7 +279,7 @@ async def _handle_calendar(
|
||||
elif action == "delete":
|
||||
fn = contract.get_function("delete_event")
|
||||
if fn is None:
|
||||
return StepResult(error="calendar plugin not available", abort=True)
|
||||
return StepResult(error="calendar delete_event not exposed via contract yet", abort=True)
|
||||
await fn(db=db, tenant_id=tenant_id, event_id=config.get("event_id", ""))
|
||||
return StepResult()
|
||||
else:
|
||||
@@ -303,19 +307,21 @@ async def _handle_dms(
|
||||
action = config.get("action", "search")
|
||||
|
||||
try:
|
||||
from app.plugins.builtins.dms.contracts import DmsContract
|
||||
contract = DmsContract
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
contract = get_contract("dms")
|
||||
if contract is None:
|
||||
return StepResult(error="dms plugin not available", abort=True)
|
||||
|
||||
if action == "search":
|
||||
fn = contract.get_function("search_files")
|
||||
if fn is None:
|
||||
return StepResult(error="dms plugin not available", abort=True)
|
||||
return StepResult(error="dms search_files not exposed via contract yet", abort=True)
|
||||
results = await fn(db=db, tenant_id=tenant_id, query=config.get("query", ""))
|
||||
return StepResult(output={"files": results} if results else {})
|
||||
elif action == "metadata":
|
||||
fn = contract.get_function("get_file_metadata")
|
||||
if fn is None:
|
||||
return StepResult(error="dms plugin not available", abort=True)
|
||||
return StepResult(error="dms get_file_metadata not exposed via contract yet", abort=True)
|
||||
metadata = await fn(db=db, tenant_id=tenant_id, file_id=config.get("file_id", ""))
|
||||
return StepResult(output={"metadata": metadata} if metadata else {})
|
||||
else:
|
||||
@@ -348,17 +354,16 @@ async def _handle_search(
|
||||
return StepResult(error="search step requires query", abort=True)
|
||||
|
||||
try:
|
||||
from app.plugins.builtins.unified_search.contracts import SearchContract
|
||||
contract = SearchContract
|
||||
fn = contract.get_function("unified_search")
|
||||
if fn is None:
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
contract = get_contract("unified_search")
|
||||
if contract is None:
|
||||
return StepResult(error="search plugin not available", abort=True)
|
||||
results = await fn(
|
||||
results = await contract.simple_search(
|
||||
db=db,
|
||||
tenant_id=tenant_id,
|
||||
query=query,
|
||||
entity_type=entity_type,
|
||||
limit=limit,
|
||||
tenant_id=tenant_id,
|
||||
entity_types=[entity_type] if entity_type else None,
|
||||
limit=int(limit),
|
||||
)
|
||||
# Store results in context for later steps
|
||||
instance.context["search_results"] = results
|
||||
@@ -391,17 +396,21 @@ async def _handle_agent(
|
||||
return StepResult(error="agent step requires agent_id", abort=True)
|
||||
|
||||
try:
|
||||
from app.plugins.builtins.automation.contracts import AutomationContract
|
||||
contract = AutomationContract
|
||||
from app.plugins.builtins.contracts import get_contract
|
||||
contract = get_contract("automation")
|
||||
if contract is None:
|
||||
return StepResult(error="automation plugin not available", abort=True)
|
||||
fn = contract.get_function("run_agent")
|
||||
if fn is None:
|
||||
return StepResult(error="automation plugin not available", abort=True)
|
||||
return StepResult(error="automation run_agent not exposed via contract yet", abort=True)
|
||||
# run_agent is an ARQ job function: it opens its own DB session and runs
|
||||
# the agent loop to completion, so ``wait`` always ends up true here.
|
||||
logger.debug("agent step wait_for_completion=%s (step always waits)", wait)
|
||||
result = await fn(
|
||||
db=db,
|
||||
tenant_id=tenant_id,
|
||||
agent_id=uuid.UUID(agent_id),
|
||||
input_data=user_input,
|
||||
wait_for_completion=wait,
|
||||
{},
|
||||
str(agent_id),
|
||||
trigger_type="workflow",
|
||||
trigger_data={"input": user_input},
|
||||
)
|
||||
instance.context["agent_result"] = result
|
||||
return StepResult(output={"agent_result": result} if result else {})
|
||||
|
||||
Reference in New Issue
Block a user