fix(matrix-mana-bot): correct service method calls and add deploy script

- Fix AiHandler to use correct service methods:
  - setSessionModel instead of setModel
  - clearSessionHistory instead of clearHistory
  - compareModels for model comparison
- Fix TodoHandler to use index-based methods:
  - completeTaskByIndex instead of completeTask
  - deleteTaskByIndex instead of deleteTask
- Add deploy-mana-bot.sh script for full deployment automation

https://claude.ai/code/session_015bwcqVRiFmSydYTjvDJGTc
This commit is contained in:
Claude 2026-01-29 00:42:50 +00:00
parent e96d76ab8e
commit 370b5d3196
No known key found for this signature in database
3 changed files with 141 additions and 22 deletions

View file

@ -0,0 +1,134 @@
#!/bin/bash
# Deploy Matrix Mana Bot (Gateway) to Mac Mini
# This script handles the complete deployment process
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
echo "============================================"
echo " Matrix Mana Bot - Full Deployment"
echo "============================================"
echo ""
cd "$PROJECT_DIR"
# Check if .env exists and has the token
if ! grep -q "MATRIX_MANA_BOT_TOKEN" .env 2>/dev/null; then
echo -e "${YELLOW}Warning: MATRIX_MANA_BOT_TOKEN not found in .env${NC}"
echo "Run ./scripts/mac-mini/setup-mana-bot.sh first to register the bot."
echo ""
read -p "Continue anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Step 1: Pull latest code
echo -e "${CYAN}Step 1: Pulling latest code...${NC}"
git pull --ff-only || {
echo -e "${YELLOW}Git pull failed. You may have local changes.${NC}"
read -p "Continue anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
}
# Step 2: Build shared package
echo ""
echo -e "${CYAN}Step 2: Building @manacore/bot-services...${NC}"
cd "$PROJECT_DIR/packages/bot-services"
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
pnpm build || {
echo -e "${RED}Failed to build bot-services package${NC}"
exit 1
}
echo -e "${GREEN}bot-services built successfully${NC}"
# Step 3: Build gateway bot
echo ""
echo -e "${CYAN}Step 3: Building matrix-mana-bot...${NC}"
cd "$PROJECT_DIR/services/matrix-mana-bot"
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
pnpm build || {
echo -e "${RED}Failed to build matrix-mana-bot${NC}"
exit 1
}
echo -e "${GREEN}matrix-mana-bot built successfully${NC}"
# Step 4: Build Docker image
echo ""
echo -e "${CYAN}Step 4: Building Docker image...${NC}"
cd "$PROJECT_DIR"
docker build -t matrix-mana-bot:latest ./services/matrix-mana-bot || {
echo -e "${RED}Failed to build Docker image${NC}"
exit 1
}
echo -e "${GREEN}Docker image built successfully${NC}"
# Step 5: Stop existing container if running
echo ""
echo -e "${CYAN}Step 5: Stopping existing container...${NC}"
docker compose -f docker-compose.macmini.yml stop matrix-mana-bot 2>/dev/null || true
docker compose -f docker-compose.macmini.yml rm -f matrix-mana-bot 2>/dev/null || true
# Step 6: Start new container
echo ""
echo -e "${CYAN}Step 6: Starting matrix-mana-bot...${NC}"
docker compose -f docker-compose.macmini.yml up -d matrix-mana-bot || {
echo -e "${RED}Failed to start container${NC}"
exit 1
}
# Step 7: Wait for health check
echo ""
echo -e "${CYAN}Step 7: Waiting for health check...${NC}"
for i in {1..30}; do
if curl -s http://localhost:3310/health > /dev/null 2>&1; then
echo -e "${GREEN}Health check passed!${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED}Health check failed after 30 seconds${NC}"
echo "Check logs with: docker logs manacore-matrix-mana-bot"
exit 1
fi
echo -n "."
sleep 1
done
# Step 8: Show status
echo ""
echo "============================================"
echo -e "${GREEN} Deployment Complete!${NC}"
echo "============================================"
echo ""
echo "Container Status:"
docker ps --filter "name=manacore-matrix-mana-bot" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
echo ""
echo "Health Check:"
curl -s http://localhost:3310/health | jq . 2>/dev/null || curl -s http://localhost:3310/health
echo ""
echo ""
echo "Next Steps:"
echo "1. Invite the bot to a Matrix room:"
echo " /invite @mana:mana.how"
echo ""
echo "2. Test with:"
echo " hilfe"
echo " !todo Test aufgabe"
echo " !list"
echo ""
echo "3. View logs with:"
echo " docker logs -f manacore-matrix-mana-bot"
echo ""

View file

@ -51,7 +51,7 @@ export class AiHandler {
return `❌ Modell "${modelName}" nicht gefunden.\n\nVerfügbar: ${available}`;
}
this.aiService.setModel(ctx.userId, modelName);
this.aiService.setSessionModel(ctx.userId, modelName);
this.logger.log(`User ${ctx.userId} switched to model ${modelName}`);
return `✅ Modell gewechselt zu: \`${modelName}\``;
@ -62,27 +62,12 @@ export class AiHandler {
return `**Verwendung:** \`!all [Deine Frage]\`\n\nBeispiel: \`!all Was ist 2+2?\``;
}
const models = await this.aiService.listModels();
if (models.length === 0) {
const results = await this.aiService.compareModels(question);
if (results.length === 0) {
return '❌ Keine Modelle gefunden. Ist Ollama gestartet?';
}
const results: { model: string; response: string; duration: number; error?: string }[] = [];
for (const model of models) {
const startTime = Date.now();
try {
this.logger.debug(`Querying model ${model.name}...`);
const response = await this.aiService.chat(ctx.userId, question, model.name);
const duration = Date.now() - startTime;
results.push({ model: model.name, response, duration });
} catch (error) {
const duration = Date.now() - startTime;
const errorMessage = error instanceof Error ? error.message : 'Unbekannter Fehler';
results.push({ model: model.name, response: '', duration, error: errorMessage });
}
}
let resultText = `**📊 Modellvergleich**\n\n**Frage:** "${question}"\n\n---\n\n`;
for (const result of results) {
@ -102,7 +87,7 @@ export class AiHandler {
}
async clearHistory(ctx: CommandContext): Promise<string> {
this.aiService.clearHistory(ctx.userId);
this.aiService.clearSessionHistory(ctx.userId);
this.logger.log(`User ${ctx.userId} cleared chat history`);
return '✅ Chat-Verlauf gelöscht.';
}

View file

@ -68,7 +68,7 @@ export class TodoHandler {
return '❌ Bitte gib eine gültige Aufgabennummer an.\n\nBeispiel: `!done 1`';
}
const task = await this.todoService.completeTask(ctx.userId, taskNumber);
const task = await this.todoService.completeTaskByIndex(ctx.userId, taskNumber);
if (!task) {
return `❌ Aufgabe #${taskNumber} nicht gefunden.`;
@ -85,7 +85,7 @@ export class TodoHandler {
return '❌ Bitte gib eine gültige Aufgabennummer an.\n\nBeispiel: `!delete 1`';
}
const task = await this.todoService.deleteTask(ctx.userId, taskNumber);
const task = await this.todoService.deleteTaskByIndex(ctx.userId, taskNumber);
if (!task) {
return `❌ Aufgabe #${taskNumber} nicht gefunden.`;