fix: enhance error handling in BlueBubbles message processing
This commit is contained in:
parent
b3a60af71c
commit
bc4ec8e9d4
265
docs/providers/ollama-testing.md
Normal file
265
docs/providers/ollama-testing.md
Normal file
@ -0,0 +1,265 @@
|
||||
# Testing Ollama Integration
|
||||
|
||||
This guide covers how to test that Ollama models work correctly with Clawdbot.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Ollama is running:**
|
||||
```bash
|
||||
ollama serve
|
||||
# Or check if it's already running:
|
||||
curl http://localhost:11434/api/tags
|
||||
```
|
||||
|
||||
2. **Ollama models are installed:**
|
||||
```bash
|
||||
ollama list
|
||||
# Pull a model if needed:
|
||||
ollama pull llama3.2
|
||||
```
|
||||
|
||||
3. **Ollama is configured in Clawdbot:**
|
||||
```bash
|
||||
# Set API key (any value works for local Ollama)
|
||||
export OLLAMA_API_KEY="ollama-local"
|
||||
# Or configure in config file:
|
||||
clawdbot config set models.providers.ollama.apiKey "ollama-local"
|
||||
```
|
||||
|
||||
## Step 1: Verify Configuration
|
||||
|
||||
### Check baseUrl is correct
|
||||
```bash
|
||||
clawdbot config get models.providers.ollama.baseUrl
|
||||
# Should output: http://localhost:11434/v1
|
||||
# (or http://127.0.0.1:11434/v1)
|
||||
```
|
||||
|
||||
### Verify models.json has correct baseUrl
|
||||
```bash
|
||||
cat ~/.clawdbot/agents/main/agent/models.json | jq '.providers.ollama.baseUrl'
|
||||
# Should output: "http://localhost:11434/v1"
|
||||
```
|
||||
|
||||
### Test Ollama API directly
|
||||
```bash
|
||||
curl -s http://localhost:11434/v1/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model":"llama3.2:latest","prompt":"test","max_tokens":5}' \
|
||||
| jq -r '.choices[0].text // .error.message'
|
||||
# Should return text, not an error
|
||||
```
|
||||
|
||||
## Step 2: Verify Model Discovery
|
||||
|
||||
### List available Ollama models
|
||||
```bash
|
||||
clawdbot models list | grep ollama
|
||||
# Should show your Ollama models, e.g.:
|
||||
# ollama/llama3.2:latest text 195k yes yes default,configured
|
||||
```
|
||||
|
||||
### Check model details
|
||||
```bash
|
||||
clawdbot models list --json | jq '.[] | select(.id | startswith("ollama/"))'
|
||||
```
|
||||
|
||||
## Step 3: Test Model Execution
|
||||
|
||||
### Test via CLI (local/embedded mode)
|
||||
```bash
|
||||
# Simple test
|
||||
clawdbot agent \
|
||||
--message "Say hello in one word" \
|
||||
--local \
|
||||
--session-id test-ollama-$(date +%s) \
|
||||
--thinking low
|
||||
|
||||
# With specific model
|
||||
clawdbot agent \
|
||||
--message "What is 2+2?" \
|
||||
--local \
|
||||
--model ollama/llama3.2:latest \
|
||||
--session-id test-ollama-$(date +%s)
|
||||
```
|
||||
|
||||
### Test via Gateway (if gateway is running)
|
||||
```bash
|
||||
# Check gateway status
|
||||
./scripts/gateway-status.sh
|
||||
|
||||
# Send message via gateway
|
||||
clawdbot agent \
|
||||
--message "Hello from Ollama" \
|
||||
--session-id test-gateway-$(date +%s)
|
||||
```
|
||||
|
||||
### Test with default model set
|
||||
```bash
|
||||
# Set Ollama as default
|
||||
clawdbot config set agents.defaults.model.primary "ollama/llama3.2:latest"
|
||||
|
||||
# Test (will use default)
|
||||
clawdbot agent \
|
||||
--message "Count to 3" \
|
||||
--local \
|
||||
--session-id test-default-$(date +%s)
|
||||
```
|
||||
|
||||
## Step 4: Verify Logs
|
||||
|
||||
### Check for successful model initialization
|
||||
```bash
|
||||
tail -100 /tmp/clawdbot/clawdbot-*.log | grep -i "ollama\|llama3.2"
|
||||
# Should see:
|
||||
# - "agent model: ollama/llama3.2:latest"
|
||||
# - "embedded run start: ... provider=ollama model=llama3.2:latest"
|
||||
```
|
||||
|
||||
### Check for API errors
|
||||
```bash
|
||||
tail -100 /tmp/clawdbot/clawdbot-*.log | grep -i "error\|fail" | grep -i "ollama\|11434"
|
||||
# Should NOT see connection errors or 404 errors
|
||||
```
|
||||
|
||||
## Step 5: Test Different Models
|
||||
|
||||
### Test multiple Ollama models
|
||||
```bash
|
||||
# Test different models
|
||||
for model in llama3.2:latest qwen2.5:7b deepseek-r1:32b; do
|
||||
echo "Testing $model..."
|
||||
clawdbot agent \
|
||||
--message "Say hi" \
|
||||
--local \
|
||||
--model "ollama/$model" \
|
||||
--session-id "test-$model-$(date +%s)" \
|
||||
--thinking low
|
||||
done
|
||||
```
|
||||
|
||||
## Step 6: Test Tool Calling (if model supports it)
|
||||
|
||||
### Test with tools enabled
|
||||
```bash
|
||||
clawdbot agent \
|
||||
--message "What's the weather like?" \
|
||||
--local \
|
||||
--model ollama/llama3.2:latest \
|
||||
--session-id test-tools-$(date +%s)
|
||||
# Models with tool support should attempt to use tools
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Issue: Models not listed
|
||||
- **Check:** `OLLAMA_API_KEY` is set or configured
|
||||
- **Check:** Ollama is running: `curl http://localhost:11434/api/tags`
|
||||
- **Check:** Models are installed: `ollama list`
|
||||
|
||||
### Issue: baseUrl error
|
||||
- **Check:** baseUrl includes `/v1`: `clawdbot config get models.providers.ollama.baseUrl`
|
||||
- **Fix:** `clawdbot config set models.providers.ollama.baseUrl "http://localhost:11434/v1"`
|
||||
|
||||
### Issue: Connection refused
|
||||
- **Check:** Ollama is running: `ps aux | grep ollama`
|
||||
- **Check:** Port is correct: `lsof -iTCP:11434 -sTCP:LISTEN`
|
||||
- **Restart:** `ollama serve`
|
||||
|
||||
### Issue: Model not found
|
||||
- **Check:** Model exists: `ollama list | grep <model-name>`
|
||||
- **Pull model:** `ollama pull <model-name>`
|
||||
- **Verify:** `clawdbot models list | grep ollama`
|
||||
|
||||
### Issue: Timeout or slow response
|
||||
- **Check:** Model size and system resources
|
||||
- **Try:** Smaller model or increase timeout
|
||||
- **Check logs:** Look for timeout errors
|
||||
|
||||
## Expected Results
|
||||
|
||||
✅ **Success indicators:**
|
||||
- Models appear in `clawdbot models list`
|
||||
- baseUrl is `http://localhost:11434/v1` (with `/v1`)
|
||||
- API test returns text, not errors
|
||||
- Logs show "provider=ollama model=..." without errors
|
||||
- Agent commands complete successfully
|
||||
- Responses are generated from Ollama models
|
||||
|
||||
❌ **Failure indicators:**
|
||||
- baseUrl missing `/v1` → 404 errors
|
||||
- Connection refused → Ollama not running
|
||||
- Model not found → Model not installed
|
||||
- Timeout → Model too slow or system overloaded
|
||||
|
||||
## Quick Test Script
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# Quick Ollama integration test
|
||||
|
||||
echo "=== Testing Ollama Integration ==="
|
||||
|
||||
# 1. Check Ollama is running
|
||||
echo "1. Checking Ollama..."
|
||||
if curl -s http://localhost:11434/api/tags > /dev/null; then
|
||||
echo " ✓ Ollama is running"
|
||||
else
|
||||
echo " ✗ Ollama is not running. Start with: ollama serve"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Check baseUrl
|
||||
echo "2. Checking baseUrl..."
|
||||
BASE_URL=$(clawdbot config get models.providers.ollama.baseUrl 2>/dev/null | grep -v "punycode\|DEP0040\|Use node" | tail -1)
|
||||
if [[ "$BASE_URL" == *"/v1"* ]]; then
|
||||
echo " ✓ baseUrl is correct: $BASE_URL"
|
||||
else
|
||||
echo " ✗ baseUrl is missing /v1: $BASE_URL"
|
||||
echo " Fix with: clawdbot config set models.providers.ollama.baseUrl 'http://localhost:11434/v1'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Test API
|
||||
echo "3. Testing Ollama API..."
|
||||
API_TEST=$(curl -s http://localhost:11434/v1/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model":"llama3.2:latest","prompt":"test","max_tokens":2}' \
|
||||
| jq -r 'if .choices then "ok" else "error" end')
|
||||
if [ "$API_TEST" = "ok" ]; then
|
||||
echo " ✓ Ollama API is working"
|
||||
else
|
||||
echo " ✗ Ollama API test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Check models are listed
|
||||
echo "4. Checking model discovery..."
|
||||
MODEL_COUNT=$(clawdbot models list 2>/dev/null | grep -c "ollama/" || echo "0")
|
||||
if [ "$MODEL_COUNT" -gt 0 ]; then
|
||||
echo " ✓ Found $MODEL_COUNT Ollama model(s)"
|
||||
else
|
||||
echo " ✗ No Ollama models found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 5. Test model execution
|
||||
echo "5. Testing model execution..."
|
||||
SESSION_ID="test-$(date +%s)"
|
||||
RESULT=$(timeout 30 clawdbot agent \
|
||||
--message "Say hello" \
|
||||
--local \
|
||||
--session-id "$SESSION_ID" \
|
||||
--thinking low 2>&1)
|
||||
|
||||
if echo "$RESULT" | grep -q "error\|Error\|ERROR"; then
|
||||
echo " ✗ Model execution failed"
|
||||
echo "$RESULT" | tail -5
|
||||
exit 1
|
||||
else
|
||||
echo " ✓ Model execution successful"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== All tests passed! ==="
|
||||
```
|
||||
55
scripts/gateway-restart.sh
Executable file
55
scripts/gateway-restart.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# Restart the Clawdbot gateway
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "Restarting Clawdbot gateway..."
|
||||
RESTART_OUTPUT=$(pnpm clawdbot gateway restart 2>&1)
|
||||
RESTART_EXIT=$?
|
||||
|
||||
if [ $RESTART_EXIT -eq 0 ] || echo "$RESTART_OUTPUT" | grep -q "not loaded"; then
|
||||
# If service is not loaded, try to bootstrap it
|
||||
if echo "$RESTART_OUTPUT" | grep -q "not loaded"; then
|
||||
echo "Gateway service not loaded. Installing and starting..."
|
||||
if pnpm clawdbot gateway install 2>&1; then
|
||||
echo "Gateway service installed. Starting..."
|
||||
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.clawdbot.gateway.plist 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Gateway restart command completed."
|
||||
echo "Waiting for gateway to be ready..."
|
||||
|
||||
# Wait up to 30 seconds for the gateway to start listening
|
||||
PORT=$(pnpm clawdbot config get gateway.port 2>/dev/null | grep -E "^[0-9]+$" | head -1 || echo "18789")
|
||||
GATEWAY_READY=false
|
||||
# Give the service a moment to start
|
||||
sleep 2
|
||||
for i in {1..28}; do
|
||||
sleep 1
|
||||
if lsof -iTCP:${PORT} -sTCP:LISTEN >/dev/null 2>&1; then
|
||||
GATEWAY_READY=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify gateway is actually listening on the port
|
||||
if [ "$GATEWAY_READY" = true ]; then
|
||||
echo "✓ Gateway restarted and is listening on port ${PORT}!"
|
||||
echo ""
|
||||
echo "Access the Control UI at:"
|
||||
echo " http://localhost:${PORT}/"
|
||||
else
|
||||
echo "⚠ Gateway restart command succeeded, but gateway is not listening on port ${PORT}."
|
||||
echo ""
|
||||
echo "The gateway service may need to be installed or there may be a startup error."
|
||||
echo "Try:"
|
||||
echo " 1. Install service: pnpm clawdbot gateway install"
|
||||
echo " 2. Check logs: ./scripts/clawlog.sh"
|
||||
echo " 3. Check service status: ./scripts/gateway-status.sh"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "✗ Gateway restart failed."
|
||||
exit 1
|
||||
fi
|
||||
116
scripts/gateway-start.sh
Executable file
116
scripts/gateway-start.sh
Executable file
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# Start the Clawdbot gateway
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "Starting Clawdbot gateway..."
|
||||
|
||||
# Check if gateway is already running
|
||||
if lsof -iTCP:18789 -sTCP:LISTEN >/dev/null 2>&1; then
|
||||
echo "✓ Gateway is already running on port 18789"
|
||||
PORT=$(pnpm clawdbot config get gateway.port 2>/dev/null | grep -E "^[0-9]+$" | head -1 || echo "18789")
|
||||
echo ""
|
||||
echo "Access the Control UI at:"
|
||||
echo " http://localhost:${PORT}/"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Try to start via service
|
||||
START_OUTPUT=$(pnpm clawdbot gateway start 2>&1)
|
||||
START_EXIT=$?
|
||||
|
||||
if [ $START_EXIT -eq 0 ]; then
|
||||
echo "Gateway start command completed."
|
||||
echo "Waiting for gateway to be ready..."
|
||||
|
||||
# Wait up to 30 seconds for the gateway to start listening
|
||||
PORT=$(pnpm clawdbot config get gateway.port 2>/dev/null | grep -E "^[0-9]+$" | head -1 || echo "18789")
|
||||
GATEWAY_READY=false
|
||||
# Give the service a moment to start
|
||||
sleep 2
|
||||
for i in {1..28}; do
|
||||
sleep 1
|
||||
if lsof -iTCP:${PORT} -sTCP:LISTEN >/dev/null 2>&1; then
|
||||
GATEWAY_READY=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify gateway is actually listening on the port
|
||||
if [ "$GATEWAY_READY" = true ]; then
|
||||
echo "✓ Gateway is running and listening on port ${PORT}!"
|
||||
echo ""
|
||||
echo "Access the Control UI at:"
|
||||
echo " http://localhost:${PORT}/"
|
||||
echo ""
|
||||
echo "If the UI doesn't load in your browser:"
|
||||
echo " 1. Ensure Control UI assets are built: pnpm ui:build"
|
||||
echo " 2. Check gateway logs: ./scripts/clawlog.sh"
|
||||
echo " 3. Verify gateway status: ./scripts/gateway-status.sh"
|
||||
else
|
||||
echo "⚠ Gateway start command succeeded, but gateway is not listening on port ${PORT}."
|
||||
echo ""
|
||||
echo "The gateway service may need to be installed or there may be a startup error."
|
||||
echo "Try:"
|
||||
echo " 1. Install service: pnpm clawdbot gateway install"
|
||||
echo " 2. Or run directly (foreground): pnpm clawdbot gateway run"
|
||||
echo " 3. Check logs: ./scripts/clawlog.sh"
|
||||
echo " 4. Check service status: ./scripts/gateway-status.sh"
|
||||
exit 1
|
||||
fi
|
||||
elif echo "$START_OUTPUT" | grep -q "service not loaded\|not installed"; then
|
||||
echo "Gateway service not installed. Installing..."
|
||||
if pnpm clawdbot gateway install 2>&1; then
|
||||
echo "Gateway service installed. Starting..."
|
||||
if pnpm clawdbot gateway start 2>&1; then
|
||||
echo "Gateway start command completed."
|
||||
echo "Waiting for gateway to be ready..."
|
||||
PORT=$(pnpm clawdbot config get gateway.port 2>/dev/null | grep -E "^[0-9]+$" | head -1 || echo "18789")
|
||||
GATEWAY_READY=false
|
||||
sleep 2
|
||||
for i in {1..28}; do
|
||||
sleep 1
|
||||
if lsof -iTCP:${PORT} -sTCP:LISTEN >/dev/null 2>&1; then
|
||||
GATEWAY_READY=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$GATEWAY_READY" = true ]; then
|
||||
echo "✓ Gateway is running and listening on port ${PORT}!"
|
||||
echo ""
|
||||
echo "Access the Control UI at:"
|
||||
echo " http://localhost:${PORT}/"
|
||||
else
|
||||
echo "⚠ Gateway start command succeeded, but gateway is not listening on port ${PORT}."
|
||||
echo "Check logs: ./scripts/clawlog.sh"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
EXIT_CODE=$?
|
||||
echo "✗ Gateway start failed after install (exit code: $EXIT_CODE)."
|
||||
echo ""
|
||||
echo "Troubleshooting:"
|
||||
echo " 1. Check service status: ./scripts/gateway-status.sh"
|
||||
echo " 2. Run directly (foreground): pnpm clawdbot gateway run"
|
||||
echo " 3. Check logs: ./scripts/clawlog.sh"
|
||||
exit $EXIT_CODE
|
||||
fi
|
||||
else
|
||||
echo "✗ Gateway service installation failed."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
EXIT_CODE=$START_EXIT
|
||||
echo "✗ Gateway start failed (exit code: $EXIT_CODE)."
|
||||
echo ""
|
||||
echo "Output:"
|
||||
echo "$START_OUTPUT"
|
||||
echo ""
|
||||
echo "Troubleshooting:"
|
||||
echo " 1. Check service status: ./scripts/gateway-status.sh"
|
||||
echo " 2. Install service: pnpm clawdbot gateway install"
|
||||
echo " 3. Run directly (foreground): pnpm clawdbot gateway run"
|
||||
echo " 4. Check logs: ./scripts/clawlog.sh"
|
||||
exit $EXIT_CODE
|
||||
fi
|
||||
12
scripts/gateway-status.sh
Executable file
12
scripts/gateway-status.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Check the status of the Clawdbot gateway
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if pnpm clawdbot gateway status; then
|
||||
PORT=$(pnpm clawdbot config get gateway.port 2>/dev/null | grep -E "^[0-9]+$" | head -1 || echo "18789")
|
||||
echo ""
|
||||
echo "Control UI URL: http://localhost:${PORT}/"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
12
scripts/gateway-stop.sh
Executable file
12
scripts/gateway-stop.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# Stop the Clawdbot gateway
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "Stopping Clawdbot gateway..."
|
||||
if pnpm clawdbot gateway stop; then
|
||||
echo "✓ Gateway stopped."
|
||||
else
|
||||
echo "✗ Gateway stop failed or gateway was not running."
|
||||
exit 1
|
||||
fi
|
||||
147
scripts/gateway-update.sh
Executable file
147
scripts/gateway-update.sh
Executable file
@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env bash
|
||||
# Update, rebuild, and restart the Clawdbot gateway
|
||||
# This script pulls latest changes, rebuilds, and restarts while preserving gateway state/memory
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
echo "🔄 Updating Clawdbot gateway..."
|
||||
echo ""
|
||||
|
||||
# Step 1: Check git status
|
||||
echo "📥 Step 1: Checking git status..."
|
||||
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
|
||||
echo "⚠️ You have unstaged changes. Handling them..."
|
||||
|
||||
# Check if there are only dist/ changes (build artifacts)
|
||||
UNSTAGED=$(git diff --name-only)
|
||||
if echo "$UNSTAGED" | grep -q "^dist/" && ! echo "$UNSTAGED" | grep -qv "^dist/"; then
|
||||
echo " Only dist/ changes detected (build artifacts). Restoring them..."
|
||||
git restore dist/ 2>/dev/null || true
|
||||
else
|
||||
# Check for .gitignore changes (common and safe to restore)
|
||||
if echo "$UNSTAGED" | grep -q "^\.gitignore$" && [ "$(echo "$UNSTAGED" | wc -l | tr -d ' ')" = "1" ]; then
|
||||
echo " Only .gitignore changes detected. Restoring..."
|
||||
git restore .gitignore 2>/dev/null || true
|
||||
else
|
||||
echo "⚠️ You have unstaged changes that may be important:"
|
||||
echo "$UNSTAGED" | sed 's/^/ - /'
|
||||
echo ""
|
||||
echo " These changes will be preserved, but you may need to resolve conflicts."
|
||||
echo " Continuing with pull (will attempt rebase)..."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 2: Pull latest changes
|
||||
echo ""
|
||||
echo "📥 Step 2: Pulling latest changes from git..."
|
||||
|
||||
# Store current HEAD before pull to detect changes
|
||||
PREV_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "")
|
||||
|
||||
PULL_OUTPUT=$(git pull --rebase 2>&1) || {
|
||||
PULL_EXIT=$?
|
||||
echo "✗ Git pull failed (exit code: $PULL_EXIT)"
|
||||
echo ""
|
||||
echo "Output:"
|
||||
echo "$PULL_OUTPUT"
|
||||
echo ""
|
||||
echo "Please resolve any conflicts manually and try again."
|
||||
exit $PULL_EXIT
|
||||
}
|
||||
|
||||
# Check if there were any new commits
|
||||
CURRENT_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "")
|
||||
if [ -n "$PREV_HEAD" ] && [ "$PREV_HEAD" = "$CURRENT_HEAD" ]; then
|
||||
echo "✓ Repository is already up to date"
|
||||
NEW_COMMITS=false
|
||||
else
|
||||
echo "✓ Successfully pulled latest changes"
|
||||
NEW_COMMITS=true
|
||||
# Show what changed
|
||||
if [ -n "$PREV_HEAD" ] && [ "$PREV_HEAD" != "$CURRENT_HEAD" ]; then
|
||||
echo ""
|
||||
echo "Recent commits:"
|
||||
git log --oneline "$PREV_HEAD..HEAD" 2>/dev/null | head -5 | sed 's/^/ /' || git log --oneline -5 | sed 's/^/ /'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 3: Check if rebuild is needed
|
||||
echo ""
|
||||
echo "🔨 Step 3: Checking if rebuild is needed..."
|
||||
|
||||
# Count TypeScript source files that changed
|
||||
if [ "$NEW_COMMITS" = true ] && [ -n "$PREV_HEAD" ] && [ "$PREV_HEAD" != "$CURRENT_HEAD" ]; then
|
||||
# Compare with previous HEAD before pull
|
||||
TS_CHANGES=$(git diff --name-only "$PREV_HEAD" HEAD 2>/dev/null | grep -E '\.(ts|tsx)$|^src/' | wc -l | tr -d ' ' || echo "0")
|
||||
|
||||
if [ "$TS_CHANGES" -gt 0 ]; then
|
||||
echo " Found $TS_CHANGES TypeScript source file(s) changed. Rebuild required."
|
||||
NEEDS_REBUILD=true
|
||||
else
|
||||
echo " No TypeScript source files changed. Checking if dist/ is up to date..."
|
||||
# Check if dist exists and is newer than any source file
|
||||
if [ -d "dist" ] && [ -f "dist/.buildstamp" ]; then
|
||||
NEEDS_REBUILD=false
|
||||
else
|
||||
NEEDS_REBUILD=true
|
||||
echo " dist/ directory missing or incomplete. Rebuild required."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# No new commits, but check if dist/ exists
|
||||
if [ ! -d "dist" ] || [ ! -f "dist/.buildstamp" ]; then
|
||||
NEEDS_REBUILD=true
|
||||
echo " dist/ directory missing or incomplete. Rebuild required."
|
||||
else
|
||||
NEEDS_REBUILD=false
|
||||
echo " No new commits and dist/ exists. Skipping rebuild."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 4: Rebuild if needed
|
||||
if [ "$NEEDS_REBUILD" = true ]; then
|
||||
echo ""
|
||||
echo "🔨 Step 4: Rebuilding application..."
|
||||
if pnpm build; then
|
||||
echo "✓ Build completed successfully"
|
||||
else
|
||||
BUILD_EXIT=$?
|
||||
echo "✗ Build failed (exit code: $BUILD_EXIT)"
|
||||
echo ""
|
||||
echo "Please fix build errors and try again."
|
||||
exit $BUILD_EXIT
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo "⏭️ Step 4: Skipping rebuild (not needed)"
|
||||
fi
|
||||
|
||||
# Step 5: Restart gateway
|
||||
echo ""
|
||||
echo "🔄 Step 5: Restarting gateway..."
|
||||
echo ""
|
||||
echo " Note: Gateway state and memory are preserved during restart."
|
||||
echo " Sessions, config, and agent state are stored in ~/.clawdbot/ and persist automatically."
|
||||
echo ""
|
||||
|
||||
# Use the existing restart script (it will print the Control UI URL)
|
||||
if bash "$SCRIPT_DIR/gateway-restart.sh"; then
|
||||
echo ""
|
||||
echo "✅ Gateway update complete!"
|
||||
else
|
||||
RESTART_EXIT=$?
|
||||
echo ""
|
||||
echo "✗ Gateway restart failed (exit code: $RESTART_EXIT)"
|
||||
echo ""
|
||||
echo "Troubleshooting:"
|
||||
echo " 1. Check gateway status: ./scripts/gateway-status.sh"
|
||||
echo " 2. Check logs: ./scripts/clawlog.sh"
|
||||
echo " 3. Try manual restart: ./scripts/gateway-restart.sh"
|
||||
exit $RESTART_EXIT
|
||||
fi
|
||||
82
scripts/test-ollama.sh
Executable file
82
scripts/test-ollama.sh
Executable file
@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
# Quick test script for Ollama integration
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "=== Testing Ollama Integration ==="
|
||||
echo ""
|
||||
|
||||
# 1. Check Ollama is running
|
||||
echo "1. Checking Ollama is running..."
|
||||
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
|
||||
echo " ✓ Ollama is running"
|
||||
else
|
||||
echo " ✗ Ollama is not running. Start with: ollama serve"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Check baseUrl
|
||||
echo "2. Checking baseUrl configuration..."
|
||||
BASE_URL=$(pnpm clawdbot config get models.providers.ollama.baseUrl 2>/dev/null | grep -v "punycode\|DEP0040\|Use node\|trace-deprecation" | tail -1 | xargs)
|
||||
if [[ "$BASE_URL" == *"/v1"* ]]; then
|
||||
echo " ✓ baseUrl is correct: $BASE_URL"
|
||||
else
|
||||
echo " ✗ baseUrl is missing /v1: $BASE_URL"
|
||||
echo " Fix with: pnpm clawdbot config set models.providers.ollama.baseUrl 'http://localhost:11434/v1'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Test API directly
|
||||
echo "3. Testing Ollama API directly..."
|
||||
API_TEST=$(curl -s http://localhost:11434/v1/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model":"llama3.2:latest","prompt":"test","max_tokens":2}' 2>/dev/null \
|
||||
| jq -r 'if .choices then "ok" else "error" end' 2>/dev/null || echo "error")
|
||||
if [ "$API_TEST" = "ok" ]; then
|
||||
echo " ✓ Ollama API is working"
|
||||
else
|
||||
echo " ✗ Ollama API test failed"
|
||||
echo " Make sure Ollama is running and llama3.2:latest is installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Check models are discovered
|
||||
echo "4. Checking model discovery..."
|
||||
MODEL_COUNT=$(pnpm clawdbot models list 2>/dev/null | grep -c "ollama/" || echo "0")
|
||||
if [ "$MODEL_COUNT" -gt 0 ]; then
|
||||
echo " ✓ Found $MODEL_COUNT Ollama model(s)"
|
||||
pnpm clawdbot models list 2>/dev/null | grep "ollama/" | head -3 | sed 's/^/ /'
|
||||
else
|
||||
echo " ✗ No Ollama models found"
|
||||
echo " Make sure OLLAMA_API_KEY is set or configured"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 5. Test model execution (optional, can be slow)
|
||||
if [ "${TEST_EXECUTION:-}" = "1" ]; then
|
||||
echo "5. Testing model execution..."
|
||||
SESSION_ID="test-ollama-$(date +%s)"
|
||||
if timeout 30 pnpm clawdbot agent \
|
||||
--message "Say hello in one word" \
|
||||
--local \
|
||||
--session-id "$SESSION_ID" \
|
||||
--thinking low > /tmp/ollama-test-output.log 2>&1; then
|
||||
echo " ✓ Model execution successful"
|
||||
echo " Response preview:"
|
||||
tail -5 /tmp/ollama-test-output.log | sed 's/^/ /'
|
||||
else
|
||||
echo " ⚠ Model execution had issues (check /tmp/ollama-test-output.log)"
|
||||
echo " This might be normal if the model is slow or requires more setup"
|
||||
fi
|
||||
else
|
||||
echo "5. Skipping model execution test (set TEST_EXECUTION=1 to enable)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Basic tests passed! ==="
|
||||
echo ""
|
||||
echo "To test model execution, run:"
|
||||
echo " TEST_EXECUTION=1 ./scripts/test-ollama.sh"
|
||||
echo ""
|
||||
echo "Or test manually:"
|
||||
echo " pnpm clawdbot agent --message 'Hello' --local --session-id test-$(date +%s)"
|
||||
Loading…
Reference in New Issue
Block a user