feat: new integration

This commit is contained in:
Gab
2026-03-27 09:11:17 +11:00
parent 0f62ba8dd5
commit 8e05565e84
7 changed files with 192 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ class ToolType(str, Enum):
CODER_AGENT = "coder_agent"
DATABASE_SCRIPT = "database_script"
API_FUNCTION = "api_function"
PROMPT = "prompt"
class FunctionRequestType(str, Enum):

View File

@@ -6,9 +6,10 @@ SDK Structure:
- agent_functions: API Functions (with request_type)
- connections: Provider connections (openai, anthropic, etc.)
- agents: TF workspace agents
- prompts: Prompt templates (with available_to_agents mapping)
"""
from typing import Any, Optional
from typing import Any, Optional, List
from pydantic import BaseModel
from toothfairyai.types import AgentFunction
@@ -45,11 +46,23 @@ class SyncedTool(BaseModel):
llm_provider: Optional[str] = None
class SyncedPrompt(BaseModel):
"""A prompt template synced from ToothFairyAI workspace."""
id: str
label: str
interpolation_string: str
prompt_type: Optional[str] = None
available_to_agents: Optional[List[str]] = None
description: Optional[str] = None
class ToolSyncResult(BaseModel):
"""Result of tool sync operation."""
success: bool
tools: list[SyncedTool] = []
prompts: list[SyncedPrompt] = []
by_type: dict[str, int] = {}
error: Optional[str] = None
@@ -149,6 +162,26 @@ def parse_agent(agent) -> SyncedTool:
)
def parse_prompt(prompt) -> SyncedPrompt:
"""
Parse Prompt from SDK into SyncedPrompt.
Args:
prompt: Prompt from TF SDK
Returns:
SyncedPrompt instance
"""
return SyncedPrompt(
id=prompt.id,
label=prompt.label,
interpolation_string=prompt.interpolation_string,
prompt_type=getattr(prompt, 'prompt_type', None),
available_to_agents=getattr(prompt, 'available_to_agents', None),
description=getattr(prompt, 'description', None),
)
def sync_tools(config: TFConfig) -> ToolSyncResult:
"""
Sync all tools from ToothFairyAI workspace using SDK.
@@ -157,12 +190,13 @@ def sync_tools(config: TFConfig) -> ToolSyncResult:
- Agent Functions (API Functions with request_type)
- Agent Skills (functions with is_agent_skill=True)
- Coder Agents (agents with mode='coder')
- Prompts (prompt templates with available_to_agents mapping)
Args:
config: TFConfig instance
Returns:
ToolSyncResult with synced tools
ToolSyncResult with synced tools and prompts
"""
try:
client = config.get_client()
@@ -180,14 +214,26 @@ def sync_tools(config: TFConfig) -> ToolSyncResult:
except Exception as e:
pass
# Sync prompts
prompts = []
try:
prompts_result = client.prompts.list()
prompts = [parse_prompt(p) for p in prompts_result.items]
except Exception as e:
pass
by_type = {}
for tool in tools:
type_name = tool.tool_type.value
by_type[type_name] = by_type.get(type_name, 0) + 1
if prompts:
by_type['prompt'] = len(prompts)
return ToolSyncResult(
success=True,
tools=tools,
prompts=prompts,
by_type=by_type,
)