Watch
1
0
Fork
You've already forked Seyyed_arc
0
forked from hesabix/arc
Seyyed_arc/hesabixAPI/app/services/ai/ai_tool_capability.py

277 lines
11 KiB
Python

"""Capability / namespace taxonomy for AI tools — search-friendly, not ranking.
Domain = سطل Intent موجود (financial, warehouse, …)
Capability = کلید نقطه‌ای برای Discovery آینده (financial.invoice)
Namespace = بخش اول Capability (financial) برای جلوگیری از تصادم در ۱۲۰۰+
این ماژول Search Engine را عوض نمی‌کند؛ فقط برچسب پایدار می‌سازد.
"""
from __future__ import annotations
from typing import Dict, Tuple
# مجموعهٔ مجاز — هر Capability باید نقطه‌ای باشد
TOOL_CAPABILITIES: frozenset[str] = frozenset({
"agent.memory",
"agent.plan",
"agent.subagent",
"automation.workflow",
"crm.activity",
"crm.deal",
"crm.lead",
"crm.summary",
"customer_club.loyalty",
"financial.account",
"financial.check",
"financial.credit",
"financial.currency",
"financial.document",
"financial.expense",
"financial.fiscal",
"financial.invoice",
"financial.loan",
"financial.payment",
"financial.transfer",
"financial.wallet",
"integration.basalam",
"integration.connector",
"integration.woocommerce",
"inventory.bom",
"inventory.product",
"inventory.production",
"inventory.stock",
"inventory.warehouse",
"people.person",
"platform.audit",
"platform.hscript",
"platform.marketplace",
"platform.notifications",
"platform.settings",
"query.entity",
"query.meta",
"reports.cashflow",
"reports.crm",
"reports.export",
"reports.financial",
"reports.inventory",
"reports.overview",
"reports.payables",
"reports.purchases",
"reports.receivables",
"reports.sales",
"reports.templates",
"tax.moadian",
"misc.general",
})
# نام دقیق → capability (منبع حقیقت)
_EXACT: Dict[str, str] = {
"adjust_customer_club_points": "customer_club.loyalty",
"await_subagent": "agent.subagent",
"batch_query_business_data": "query.entity",
"cancel_subagent": "agent.subagent",
"create_account": "financial.account",
"create_check": "financial.check",
"create_expense_income": "financial.expense",
"create_invoice": "financial.invoice",
"create_lead": "crm.lead",
"create_person": "people.person",
"create_product": "inventory.product",
"create_product_attribute": "inventory.product",
"create_receipt_payment": "financial.payment",
"create_session_plan": "agent.plan",
"create_transfer": "financial.transfer",
"create_warehouse_document": "inventory.warehouse",
"create_workflow": "automation.workflow",
"delete_account": "financial.account",
"delete_check": "financial.check",
"delete_expense_income": "financial.expense",
"delete_invoice": "financial.invoice",
"delete_memory_entry": "agent.memory",
"delete_person": "people.person",
"delete_product_attribute": "inventory.product",
"delete_receipt_payment": "financial.payment",
"delete_transfer": "financial.transfer",
"delete_workflow": "automation.workflow",
"execute_workflow": "automation.workflow",
"export_business_data": "reports.export",
"get_account": "financial.account",
"get_basalam_overview": "integration.basalam",
"get_bom_details": "inventory.bom",
"get_business_credit_settings": "financial.credit",
"get_business_dashboard": "reports.overview",
"get_business_info": "platform.settings",
"get_cash_flow": "reports.cashflow",
"get_check_details": "financial.check",
"get_creditors_report": "reports.payables",
"get_crm_summary": "crm.summary",
"get_current_fiscal_year": "financial.fiscal",
"get_customer_club_rfm_summary": "customer_club.loyalty",
"get_customer_club_settings": "customer_club.loyalty",
"get_customer_info": "people.person",
"get_deal_details": "crm.deal",
"get_debtors_report": "reports.receivables",
"get_document_details": "financial.document",
"get_document_numbering_settings": "platform.settings",
"get_financial_summary": "reports.financial",
"get_inventory_status": "inventory.stock",
"get_inventory_valuation": "reports.inventory",
"get_invoice_details": "financial.invoice",
"get_invoices_count": "financial.invoice",
"get_lead_details": "crm.lead",
"get_lead_funnel_report": "reports.crm",
"get_loan_facility": "financial.loan",
"get_opening_balance": "financial.account",
"get_person_balance": "people.person",
"get_person_credit": "financial.credit",
"get_person_transactions": "financial.payment",
"get_pipeline_report": "reports.crm",
"get_product_attribute": "inventory.product",
"get_product_info": "inventory.product",
"get_product_kardex": "inventory.stock",
"get_project_summary": "misc.general",
"get_purchase_report": "reports.purchases",
"get_quick_sales_settings": "platform.settings",
"get_repair_order_details": "misc.general",
"get_report": "reports.overview",
"get_report_template": "reports.templates",
"get_report_template_scope_catalog": "reports.templates",
"get_sales_report": "reports.sales",
"get_tax_data_quality": "tax.moadian",
"get_tax_settings": "tax.moadian",
"get_wallet_metrics": "financial.wallet",
"get_wallet_overview": "financial.wallet",
"get_warehouse_document_details": "inventory.warehouse",
"get_warehouse_report": "reports.inventory",
"get_warehouse_stock_summary": "inventory.stock",
"get_workflow": "automation.workflow",
"get_workflow_component_schema": "automation.workflow",
"get_workflow_design_rules": "automation.workflow",
"get_workflow_execution_debug": "automation.workflow",
"hscript_fix_script": "platform.hscript",
"hscript_language_guide": "platform.hscript",
"hscript_read_doc": "platform.hscript",
"hscript_retrieve_docs": "platform.hscript",
"hscript_run_preview": "platform.hscript",
"hscript_search_docs": "platform.hscript",
"hscript_validate_script": "platform.hscript",
"invoke_business_connector": "integration.connector",
"list_accounts": "financial.account",
"list_announcements": "platform.notifications",
"list_available_reports": "reports.overview",
"list_bank_accounts": "financial.account",
"list_basalam_dead_letter": "integration.basalam",
"list_basalam_product_conflicts": "integration.basalam",
"list_basalam_synced_invoices": "integration.basalam",
"list_boms": "inventory.bom",
"list_business_notification_logs": "platform.notifications",
"list_business_notification_templates": "platform.notifications",
"list_business_plugins": "platform.marketplace",
"list_business_users": "platform.settings",
"list_cash_registers": "financial.account",
"list_credit_installment_plans": "financial.credit",
"list_currencies": "financial.currency",
"list_currency_rates": "financial.currency",
"list_customer_club_ledger": "customer_club.loyalty",
"list_customer_club_tiers": "customer_club.loyalty",
"list_distribution_routes": "misc.general",
"list_fiscal_years": "financial.fiscal",
"list_frequent_descriptions": "financial.document",
"list_loan_facilities": "financial.loan",
"list_marketplace_plugins": "platform.marketplace",
"list_my_businesses": "platform.settings",
"list_payment_gateways": "financial.payment",
"list_person_groups": "people.person",
"list_petty_cash": "financial.account",
"list_price_list_items": "inventory.product",
"list_price_lists": "inventory.product",
"list_product_attributes": "inventory.product",
"list_queryable_fields": "query.meta",
"list_report_templates": "reports.templates",
"list_session_todos": "agent.plan",
"list_user_notifications": "platform.notifications",
"list_wallet_transactions": "financial.wallet",
"list_warehouse_locations": "inventory.warehouse",
"list_warehouse_placements": "inventory.warehouse",
"list_warehouses": "inventory.warehouse",
"list_woocommerce_orders": "integration.woocommerce",
"list_woocommerce_products": "integration.woocommerce",
"list_workflow_action_catalog": "automation.workflow",
"list_workflow_builtin_nodes": "automation.workflow",
"list_workflow_executions": "automation.workflow",
"list_workflow_trigger_catalog": "automation.workflow",
"list_workflows": "automation.workflow",
"poll_workflow_execution": "automation.workflow",
"publish_report_template": "reports.templates",
"query_business_data": "query.entity",
"read_memory": "agent.memory",
"recalculate_customer_club_rfm": "customer_club.loyalty",
"resolve_currency_rate": "financial.currency",
"resolve_date_range": "query.meta",
"search_activities": "crm.activity",
"search_activity_logs": "platform.audit",
"search_categories": "inventory.product",
"search_checks": "financial.check",
"search_customer_club_rfm_persons": "customer_club.loyalty",
"search_deals": "crm.deal",
"search_documents": "financial.document",
"search_expense_income": "financial.expense",
"search_invoices": "financial.invoice",
"search_leads": "crm.lead",
"search_persons": "people.person",
"search_product_instances": "inventory.stock",
"search_production_documents": "inventory.production",
"search_products": "inventory.product",
"search_projects": "misc.general",
"search_receipts_payments": "financial.payment",
"search_repair_orders": "misc.general",
"search_tax_workspace": "tax.moadian",
"search_transfers": "financial.transfer",
"search_warehouse_documents": "inventory.warehouse",
"search_warranty_codes": "misc.general",
"set_default_report_template": "reports.templates",
"spawn_subagent": "agent.subagent",
"test_workflow": "automation.workflow",
"update_account": "financial.account",
"update_check": "financial.check",
"update_customer_club_settings": "customer_club.loyalty",
"update_expense_income": "financial.expense",
"update_invoice": "financial.invoice",
"update_person": "people.person",
"update_product": "inventory.product",
"update_product_attribute": "inventory.product",
"update_receipt_payment": "financial.payment",
"update_session_todo": "agent.plan",
"update_transfer": "financial.transfer",
"update_workflow": "automation.workflow",
"upsert_memory_entry": "agent.memory",
"validate_workflow_draft": "automation.workflow",
}
def resolve_tool_capability(name: str, domains: Tuple[str, ...] = ()) -> str:
cap = _EXACT.get(name or "")
if cap:
return cap
if domains:
from app.services.ai.ai_tool_spec import DOMAIN_TO_CAPABILITY
mapped = DOMAIN_TO_CAPABILITY.get(domains[0])
if mapped and "." in mapped:
return mapped
return "misc.general"
def namespace_for_capability(capability: str) -> str:
cap = (capability or "").strip()
if "." in cap:
return cap.split(".", 1)[0]
return cap or "misc"
def capability_matches(tool_capability: str, requested: str) -> bool:
"""مطابقت دقیق یا پیشوند (financial → financial.invoice)."""
req = (requested or "").strip()
cap = (tool_capability or "").strip()
if not req or not cap:
return False
return cap == req or cap.startswith(req + ".")