|
1 | | -#V06062026 |
| 1 | +#V06092026 |
2 | 2 | # ============================================================================= |
3 | | -# CAIOS Web Bridge — Flask server that connects caios_chat_ui.html to the |
4 | | -# existing orchestrator/caios_chat.py stack. |
| 3 | +# CAIOS Web Bridge — Flask server that connects caios_chat_ui.html to the existing orchestrator/caios_chat.py stack. |
5 | 4 | # |
6 | 5 | # Run from the Project_Andrew directory: |
7 | 6 | # pip install flask |
8 | 7 | # python caios_bridge.py |
9 | 8 | # |
10 | 9 | # Then open http://localhost:5000 in your browser. |
11 | | -# The CLI caios_chat.py continues to work alongside this — they share the |
12 | | -# same orchestrator, shared_memory, and conversation_log.jsonl. |
| 10 | +# The CLI caios_chat.py continues to work alongside this — they share the same orchestrator, shared_memory, and conversation_log.jsonl. |
13 | 11 | # ============================================================================= |
14 | 12 |
|
15 | 13 | import os |
@@ -197,8 +195,7 @@ def favicon(): |
197 | 195 | # ============================================================================= |
198 | 196 | # Route — GET /api/boot |
199 | 197 | # Returns everything the UI needs on first load: |
200 | | -# identity, available models, users list (names only, no hashes), |
201 | | -# KB stats, whether auth is required. |
| 198 | +# identity, available models, users list (names only, no hashes), KB stats, whether auth is required. |
202 | 199 | # ============================================================================= |
203 | 200 |
|
204 | 201 | @app.route('/api/boot') |
@@ -298,7 +295,7 @@ def api_auth(): |
298 | 295 |
|
299 | 296 | # ============================================================================= |
300 | 297 | # Route — POST /api/select_model |
301 | | -# Body: { "token": "...", "model_id": "ollama:qwen3.6:27b" } |
| 298 | +# Body: { "token": "...", "model_id": "ollama:qwen3.6:27b" } <- example |
302 | 299 | # ============================================================================= |
303 | 300 |
|
304 | 301 | @app.route('/api/select_model', methods=['POST']) |
@@ -495,6 +492,47 @@ def api_mcp(): |
495 | 492 | # Return server status if no tool specified |
496 | 493 | return jsonify({'status': mcp_status()}) |
497 | 494 |
|
| 495 | + # KB cleanup commands — routed here so Andrew can call them via tool tags |
| 496 | + if tool == 'kb_sweep': |
| 497 | + try: |
| 498 | + import kb_cleanup |
| 499 | + import io, contextlib |
| 500 | + buf = io.StringIO() |
| 501 | + with contextlib.redirect_stdout(buf): |
| 502 | + kb_cleanup.cmd_sweep(fix=args.get('fix', False)) |
| 503 | + return jsonify({'ok': True, 'content': buf.getvalue()}) |
| 504 | + except Exception as e: |
| 505 | + return jsonify({'ok': False, 'content': f'kb_sweep error: {e}'}) |
| 506 | + |
| 507 | + if tool == 'kb_purge': |
| 508 | + target = args.get('id') or args.get('pattern', '') |
| 509 | + by_pattern = 'pattern' in args |
| 510 | + if not target: |
| 511 | + return jsonify({'ok': False, 'content': 'kb_purge requires id or pattern'}) |
| 512 | + try: |
| 513 | + import kb_cleanup |
| 514 | + import io, contextlib |
| 515 | + buf = io.StringIO() |
| 516 | + with contextlib.redirect_stdout(buf): |
| 517 | + # Auto-confirm in API context (user confirmed via UI) |
| 518 | + import unittest.mock |
| 519 | + with unittest.mock.patch('builtins.input', return_value='yes'): |
| 520 | + kb_cleanup.cmd_purge(target, by_pattern=by_pattern) |
| 521 | + return jsonify({'ok': True, 'content': buf.getvalue()}) |
| 522 | + except Exception as e: |
| 523 | + return jsonify({'ok': False, 'content': f'kb_purge error: {e}'}) |
| 524 | + |
| 525 | + if tool == 'kb_validate': |
| 526 | + try: |
| 527 | + import kb_cleanup |
| 528 | + import io, contextlib |
| 529 | + buf = io.StringIO() |
| 530 | + with contextlib.redirect_stdout(buf): |
| 531 | + kb_cleanup.cmd_validate() |
| 532 | + return jsonify({'ok': True, 'content': buf.getvalue()}) |
| 533 | + except Exception as e: |
| 534 | + return jsonify({'ok': False, 'content': f'kb_validate error: {e}'}) |
| 535 | + |
498 | 536 | result = mcp_tool(tool, args) |
499 | 537 |
|
500 | 538 | # Log to audit trail |
|
0 commit comments