feat: sync

This commit is contained in:
Gab
2026-03-24 13:51:14 +11:00
parent 39bd38040c
commit 4596310485
20 changed files with 1356 additions and 101 deletions

View File

@@ -1,7 +1,11 @@
"""
Tool sync module for tfcode.
Syncs MCP servers, Agent Skills, Database Scripts, and API Functions from ToothFairyAI workspace.
Uses the official ToothFairyAI Python SDK.
Syncs tools from ToothFairyAI workspace using the official SDK.
SDK Structure:
- agent_functions: API Functions (with request_type)
- connections: Provider connections (openai, anthropic, etc.)
- agents: TF workspace agents
"""
from typing import Any, Optional
@@ -20,13 +24,10 @@ class SyncedTool(BaseModel):
description: Optional[str] = None
tool_type: ToolType
is_mcp_server: bool = False
is_agent_skill: bool = False
is_database_script: bool = False
request_type: Optional[FunctionRequestType] = None
url: Optional[str] = None
tools: list[str] = []
authorisation_type: Optional[str] = None
auth_via: str = "tf_proxy"
@@ -40,60 +41,57 @@ class ToolSyncResult(BaseModel):
error: Optional[str] = None
def classify_tool(tool: AgentFunction) -> ToolType:
def classify_tool(func: AgentFunction) -> ToolType:
"""
Classify a tool based on its flags and fields.
Classify a tool based on its properties.
Currently the SDK exposes:
- agent_functions: API functions with request_type
Args:
tool: AgentFunction from TF SDK
func: AgentFunction from TF SDK
Returns:
ToolType enum value
"""
if tool.is_mcp_server:
return ToolType.MCP_SERVER
if tool.is_agent_skill:
return ToolType.AGENT_SKILL
if tool.is_database_script:
return ToolType.DATABASE_SCRIPT
if tool.request_type:
# All agent_functions with request_type are API Functions
if func.request_type:
return ToolType.API_FUNCTION
return ToolType.API_FUNCTION
def parse_tool(tool: AgentFunction) -> SyncedTool:
def parse_function(func: AgentFunction) -> SyncedTool:
"""
Parse AgentFunction from SDK into SyncedTool.
Args:
tool: AgentFunction from TF SDK
func: AgentFunction from TF SDK
Returns:
SyncedTool instance
"""
tool_type = classify_tool(tool)
tool_type = classify_tool(func)
request_type_enum = None
if tool.request_type:
if func.request_type:
try:
request_type_enum = FunctionRequestType(tool.request_type)
request_type_enum = FunctionRequestType(func.request_type)
except ValueError:
pass
auth_via = "user_provided" if tool_type == ToolType.API_FUNCTION else "tf_proxy"
# API Functions may have user-provided auth (authorisation_type)
# or may use TF proxy
auth_via = "user_provided" if func.authorisation_type == "api_key" else "tf_proxy"
return SyncedTool(
id=tool.id,
name=tool.name,
description=tool.description,
id=func.id,
name=func.name,
description=func.description,
tool_type=tool_type,
is_mcp_server=tool.is_mcp_server or False,
is_agent_skill=tool.is_agent_skill or False,
is_database_script=tool.is_database_script or False,
request_type=request_type_enum,
url=tool.url,
tools=[],
url=func.url,
authorisation_type=func.authorisation_type,
auth_via=auth_via,
)
@@ -112,7 +110,7 @@ def sync_tools(config: TFConfig) -> ToolSyncResult:
client = config.get_client()
result = client.agent_functions.list()
tools = [parse_tool(f) for f in result.items]
tools = [parse_function(f) for f in result.items]
by_type = {}
for tool in tools:
@@ -165,21 +163,6 @@ def sync_tools_by_type(
)
def sync_mcp_servers_only(config: TFConfig) -> ToolSyncResult:
"""Sync only MCP servers (isMCPServer=true)."""
return sync_tools_by_type(config, [ToolType.MCP_SERVER])
def sync_agent_skills_only(config: TFConfig) -> ToolSyncResult:
"""Sync only Agent Skills (isAgentSkill=true)."""
return sync_tools_by_type(config, [ToolType.AGENT_SKILL])
def sync_database_scripts_only(config: TFConfig) -> ToolSyncResult:
"""Sync only Database Scripts (isDatabaseScript=true)."""
return sync_tools_by_type(config, [ToolType.DATABASE_SCRIPT])
def sync_api_functions_only(config: TFConfig) -> ToolSyncResult:
"""Sync only API Functions (has requestType)."""
return sync_tools_by_type(config, [ToolType.API_FUNCTION])