mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
feat: sync
This commit is contained in:
115
docs/sync-implementation.md
Normal file
115
docs/sync-implementation.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# tfcode Sync Implementation Summary
|
||||
|
||||
## What's Implemented
|
||||
|
||||
### 1. Postinstall Script (`packages/tfcode/scripts/postinstall.cjs`)
|
||||
- Checks for Python 3.10+ installation
|
||||
- Auto-installs ToothFairyAI Python SDK on `npm install tfcode`
|
||||
- Handles externally-managed environments (Homebrew, etc.)
|
||||
- Shows clear error messages if Python is missing
|
||||
|
||||
### 2. Python Sync Module (`packages/tf-sync/src/tf_sync/`)
|
||||
- `config.py` - Configuration management, credential validation, multi-region support
|
||||
- `tools.py` - Sync API functions from TF workspace
|
||||
- `mcp.py` - Reserved for future MCP support (not in SDK yet)
|
||||
|
||||
### 3. CLI Commands (`packages/tfcode/src/cli/cmd/tools.ts`)
|
||||
- `tfcode validate` - Validate TF credentials
|
||||
- `tfcode sync` - Sync tools from workspace
|
||||
- `tfcode tools list [--type]` - List synced tools
|
||||
- `tfcode tools credentials <name> --set/--show` - Manage API keys
|
||||
- `tfcode tools debug <name>` - Debug tool configuration
|
||||
|
||||
### 4. Region Support
|
||||
| Region | Base URL | Use Case |
|
||||
|--------|----------|----------|
|
||||
| `dev` | api.toothfairylab.link | Development |
|
||||
| `au` | api.toothfairyai.com | Australia (Default) |
|
||||
| `eu` | api.eu.toothfairyai.com | Europe |
|
||||
| `us` | api.us.toothfairyai.com | United States |
|
||||
|
||||
## Test Results
|
||||
|
||||
```bash
|
||||
$ python3 scripts/test-sync.py
|
||||
|
||||
============================================================
|
||||
tfcode Sync Test
|
||||
============================================================
|
||||
|
||||
Test 1: Load Configuration
|
||||
----------------------------------------
|
||||
✓ Workspace ID: 6586b7e6-683e-4ee6-a6cf-24c19729b5ff
|
||||
✓ Region: dev
|
||||
✓ API URL: https://api.toothfairylab.link
|
||||
|
||||
Test 2: Validate Credentials
|
||||
----------------------------------------
|
||||
✓ Credentials valid
|
||||
Workspace: Connected
|
||||
ID: 6586b7e6-683e-4ee6-a6cf-24c19729b5ff
|
||||
|
||||
Test 3: Sync Tools
|
||||
----------------------------------------
|
||||
✓ Synced 100 tools
|
||||
|
||||
By type:
|
||||
api_function: 100
|
||||
|
||||
Sample tools:
|
||||
🌐 get_kanban_projects (api_function)
|
||||
🌐 azure_costs_test_official (api_function)
|
||||
... and 95 more
|
||||
```
|
||||
|
||||
## SDK Capabilities (Current)
|
||||
|
||||
The ToothFairyAI Python SDK currently exposes:
|
||||
- `agent_functions` - API Functions with `request_type` (get/post/put/delete/etc.)
|
||||
- `connections` - Provider connections (openai, anthropic, groq, etc.)
|
||||
- `agents` - TF workspace agents
|
||||
|
||||
**Not yet exposed:**
|
||||
- MCP servers (`isMCPServer`)
|
||||
- Agent skills (`isAgentSkill`)
|
||||
- Database scripts (`isDatabaseScript`)
|
||||
|
||||
These will be added to the SDK in the future. For now, MCP servers must be configured manually in `tfcode.json`.
|
||||
|
||||
## Environment Setup
|
||||
|
||||
```bash
|
||||
export TF_WORKSPACE_ID="your-workspace-id"
|
||||
export TF_API_KEY="your-api-key"
|
||||
export TF_REGION="dev" # or au, eu, us
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# Install
|
||||
npm install -g tfcode
|
||||
|
||||
# Or with bun
|
||||
cd packages/tf-sync && python3 -m pip install -e . --break-system-packages
|
||||
cd packages/tfcode && bun install
|
||||
|
||||
# Validate
|
||||
tfcode validate
|
||||
|
||||
# Sync
|
||||
tfcode sync
|
||||
|
||||
# List tools
|
||||
tfcode tools list
|
||||
```
|
||||
|
||||
## Files Created/Modified
|
||||
|
||||
- `packages/tfcode/scripts/postinstall.cjs` - Postinstall script
|
||||
- `packages/tfcode/src/cli/cmd/tools.ts` - CLI commands
|
||||
- `packages/tf-sync/src/tf_sync/config.py` - Config + regions
|
||||
- `packages/tf-sync/src/tf_sync/tools.py` - Tool sync
|
||||
- `packages/tf-sync/src/tf_sync/mcp.py` - MCP placeholder
|
||||
- `scripts/test-sync.py` - Test script
|
||||
- `scripts/setup-tf-dev.sh` - Dev environment setup
|
||||
129
docs/testing-sync.md
Normal file
129
docs/testing-sync.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# Step-by-Step Guide: Testing tfcode Sync
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Python 3.10+ with `toothfairyai` SDK installed
|
||||
2. Node.js/Bun for running tfcode
|
||||
|
||||
## Step 1: Set Environment Variables
|
||||
|
||||
```bash
|
||||
# In your terminal
|
||||
export TF_WORKSPACE_ID="6586b7e6-683e-4ee6-a6cf-24c19729b5ff"
|
||||
export TF_API_KEY="EWZooLROIS57EVW3BKGu7Pv6LNe4D6m4gkDjukx3"
|
||||
export TF_REGION="au"
|
||||
```
|
||||
|
||||
Or use the setup script:
|
||||
```bash
|
||||
source scripts/setup-tf-dev.sh
|
||||
```
|
||||
|
||||
## Step 2: Install Python Dependencies
|
||||
|
||||
```bash
|
||||
cd packages/tf-sync
|
||||
pip install -e .
|
||||
|
||||
# Or manually install the required packages:
|
||||
pip install toothfairyai pydantic httpx rich
|
||||
```
|
||||
|
||||
## Step 3: Build tfcode CLI
|
||||
|
||||
```bash
|
||||
cd packages/tfcode
|
||||
bun install
|
||||
bun run build
|
||||
```
|
||||
|
||||
## Step 4: Test Credential Validation
|
||||
|
||||
```bash
|
||||
# From repo root with environment set
|
||||
cd packages/tfcode
|
||||
bun run src/index.ts validate
|
||||
```
|
||||
|
||||
Expected output:
|
||||
```
|
||||
Validating ToothFairyAI credentials...
|
||||
✓ Credentials valid
|
||||
Workspace: <workspace_name>
|
||||
ID: 6586b7e6-683e-4ee6-a6cf-24c19729b5ff
|
||||
```
|
||||
|
||||
## Step 5: Sync Tools from Workspace
|
||||
|
||||
```bash
|
||||
bun run src/index.ts sync
|
||||
```
|
||||
|
||||
Expected output:
|
||||
```
|
||||
Syncing tools from ToothFairyAI workspace...
|
||||
✓ Synced X tools
|
||||
|
||||
By type:
|
||||
mcp_server: X
|
||||
agent_skill: X
|
||||
database_script: X
|
||||
api_function: X
|
||||
```
|
||||
|
||||
## Step 6: List Synced Tools
|
||||
|
||||
```bash
|
||||
# List all tools
|
||||
bun run src/index.ts tools list
|
||||
|
||||
# Filter by type
|
||||
bun run src/index.ts tools list --type mcp
|
||||
bun run src/index.ts tools list --type skill
|
||||
bun run src/index.ts tools list --type database
|
||||
bun run src/index.ts tools list --type function
|
||||
```
|
||||
|
||||
## Step 7: Debug a Tool
|
||||
|
||||
```bash
|
||||
bun run src/index.ts tools debug <tool-name>
|
||||
```
|
||||
|
||||
## Step 8: Set API Function Credentials (if needed)
|
||||
|
||||
For tools with `auth_via: user_provided`:
|
||||
|
||||
```bash
|
||||
bun run src/index.ts tools credentials <tool-name> --set
|
||||
# Enter API key when prompted
|
||||
|
||||
bun run src/index.ts tools credentials <tool-name> --show
|
||||
# Shows masked key
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Python SDK not found
|
||||
```
|
||||
Error: Failed to validate: Python sync failed: ModuleNotFoundError: No module named 'toothfairyai'
|
||||
```
|
||||
Solution: `pip install toothfairyai`
|
||||
|
||||
### Environment not set
|
||||
```
|
||||
Error: TF_WORKSPACE_ID not set
|
||||
```
|
||||
Solution: Export environment variables or source the setup script
|
||||
|
||||
### Invalid credentials
|
||||
```
|
||||
✗ Validation failed: Invalid API key
|
||||
```
|
||||
Solution: Check your TF_API_KEY is correct
|
||||
|
||||
### Workspace not found
|
||||
```
|
||||
✗ Validation failed: Workspace not found
|
||||
```
|
||||
Solution: Check your TF_WORKSPACE_ID is correct
|
||||
Reference in New Issue
Block a user