feat(scripts): add letta setup script

This commit is contained in:
Finessse
2025-12-19 18:19:07 +07:00
parent 607abf2338
commit e0a7f37d2d
3 changed files with 111 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
& (Join-Path $PSScriptRoot "windows\\repair-droid-config.ps1") @args
+30
View File
@@ -0,0 +1,30 @@
param(
[Parameter(Mandatory = $false)]
[string]$ConfigPath = (Join-Path $env:USERPROFILE ".factory\\config.json")
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
if (-not (Test-Path -LiteralPath $ConfigPath)) {
throw "Droid config not found: $ConfigPath"
}
# Load JSON (tolerates existing UTF-8 BOM)
try {
$obj = Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json
} catch {
throw "config.json is not valid JSON: $($_.Exception.Message)"
}
# Backup existing file
$backupPath = "$ConfigPath.bomfix.$(Get-Date -Format 'yyyyMMdd-HHmmss')"
Copy-Item -LiteralPath $ConfigPath -Destination $backupPath -Force
# Rewrite as UTF-8 WITHOUT BOM to satisfy Droid's JSON parser
$json = $obj | ConvertTo-Json -Depth 50
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($ConfigPath, $json, $utf8NoBom)
Write-Host "Rewrote Droid config as UTF-8 without BOM -> $ConfigPath"
Write-Host "Backup saved to -> $backupPath"
+77
View File
@@ -0,0 +1,77 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
param(
[Parameter(Mandatory = $false)]
[string]$ProxyApiKey = $env:CLIPROXY_API_KEY,
[Parameter(Mandatory = $false)]
[string]$ProxyBaseUrl = "http://127.0.0.1:8317/v1",
[Parameter(Mandatory = $false)]
[string]$Model = "antigravity-claude-sonnet-4-5-thinking",
[Parameter(Mandatory = $false)]
[string]$EmbeddingModel = "text-embedding-004"
)
function Ensure-LettaInstalled {
Write-Host "Checking for Letta installation..."
if (Get-Command "letta" -ErrorAction SilentlyContinue) {
Write-Host "Letta is already installed."
return
}
Write-Host "Letta not found. Attempting to install via pip..."
& pip install letta
if ($LASTEXITCODE -ne 0) {
throw "Failed to install Letta. Please ensure Python and pip are installed and in your PATH."
}
Write-Host "Letta installed successfully."
}
function Configure-Letta {
param($BaseUrl, $ApiKey, $Model, $EmbeddingModel)
Write-Host "Configuring Letta to use ProxyPilot..."
# Set environment variables for the current session to ensure configure works
$env:LETTA_OPENAI_API_BASE = $BaseUrl
$env:LETTA_OPENAI_API_KEY = $ApiKey
# Run Letta configuration
# Note: Letta's config command structure might vary, but setting env vars
# and running a basic init is the most reliable way to bootstrap it.
Write-Host "Setting up Letta with:"
Write-Host " LLM Backend: $BaseUrl"
Write-Host " LLM Model: $Model"
Write-Host " Embed Model: $EmbeddingModel"
# We use the environment variable approach as it's the most robust across Letta versions
# Letta will pick up these variables when started by ProxyPilot.
# Create the .letta directory if it doesn't exist
$lettaDir = Join-Path $env:USERPROFILE ".letta"
if (-not (Test-Path $lettaDir)) {
New-Item -ItemType Directory -Path $lettaDir | Out-Null
}
Write-Host "Letta configuration prepared."
}
if (-not $ProxyApiKey -or $ProxyApiKey.Trim() -eq "") {
$ProxyApiKey = "local-dev-key"
Write-Host "No Proxy API Key provided, using default: $ProxyApiKey"
}
Ensure-LettaInstalled
Configure-Letta -BaseUrl $ProxyBaseUrl -ApiKey $ProxyApiKey -Model $Model -EmbeddingModel $EmbeddingModel
Write-Host ""
Write-Host "Setup Complete!"
Write-Host "1) Restart ProxyPilot to launch the Letta sidecar."
Write-Host "2) Your Letta logs will be available at: logs\letta.log"
Write-Host "3) Use 'letta run' in a new terminal to interact with your memory agent."
Write-Host ""
Write-Host "Note: ProxyPilot now provides REAL embeddings via Gemini text-embedding-004."