File size: 2,743 Bytes
2ca5874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# ==========================================
# Copyright (c) 2026 Gabriela Berger AI Oberland
# All Rights Reserved.
# This code is subject to the custom NON-COMMERCIAL 
# & ANTI-CORPORATE LICENSE (Maximum 20 PCs) found in the LICENSE file.
# ==========================================
# agent_interface.py
import json
from network_manager import NetworkManager
from workspace_manager import WorkspaceManager

class AstraeusAgent:
    def __init__(self, workspace_manager):
        self.workspace = workspace_manager
        self.network = NetworkManager()
        self.system_prompt = """
        You are Astraeus, a helpful coding assistant.
        You have access to the user's workspace and can:
        - Read and modify files
        - Execute terminal commands
        - Provide code completions
        - Answer questions about the codebase
        Always maintain context of the current workspace.
        """
        self.manifest = {
            "name": "Astraeus",
            "version": "1.0",
            "capabilities": ["file_operations", "terminal", "code_completion"]
        }

    def process_message(self, user_message, history=[]):
        # Build context
        context = {
            "current_file": self.workspace.open_files.get(self.workspace.current_tab, {}),
            "workspace_tree": self.workspace._get_directory_tree(self.workspace.current_path),
            "history": history
        }

        # Format prompt with context
        prompt = f"{self.system_prompt}\n\nContext: {json.dumps(context, indent=2)}\n\nUser: {user_message}\nAstraeus:"

        # Get model response
        response = self.network.send_to_model(prompt)

        # Process response (could include file operations, etc.)
        return self._process_response(response)

    def _process_response(self, response):
        # Check if response contains commands
        if "file_operation" in response:
            return self._handle_file_operation(response["file_operation"])
        return response.get("text", "I processed your request")

    def _handle_file_operation(self, operation):
        if operation["type"] == "edit":
            tab_id = operation.get("tab_id", self.workspace.current_tab)
            if tab_id in self.workspace.open_files:
                self.workspace.open_files[tab_id]["content"] = operation["content"]
                return f"Edited file: {self.workspace.open_files[tab_id]['name']}"
        elif operation["type"] == "create":
            return self.workspace.create_file(operation.get("type", "text"), operation.get("content", ""))
        elif operation["type"] == "execute":
            return self.workspace.execute_command(operation["command"])
        return "Operation not supported"