mirror of https://github.com/kortix-ai/suna.git
set hardcoded paths thread_manager & state_manager
This commit is contained in:
parent
7fc57f1dc0
commit
529ff8f7fc
|
@ -7,6 +7,7 @@ import time
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import requests
|
import requests
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
import re
|
||||||
|
|
||||||
MODULES = {
|
MODULES = {
|
||||||
"llm": {
|
"llm": {
|
||||||
|
@ -118,6 +119,19 @@ def copy_example_files(src_dir: str, dest_dir: str, files: Dict[str, str]):
|
||||||
shutil.copy2(src, dst)
|
shutil.copy2(src, dst)
|
||||||
click.echo(f" ✓ Created {dest_path}")
|
click.echo(f" ✓ Created {dest_path}")
|
||||||
|
|
||||||
|
def update_file_paths(file_path: str, replacements: Dict[str, str]):
|
||||||
|
"""Update file paths in the given file"""
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
content = f.read()
|
||||||
|
|
||||||
|
for old, new in replacements.items():
|
||||||
|
# Escape special characters in the old string
|
||||||
|
escaped_old = re.escape(old)
|
||||||
|
content = re.sub(escaped_old, new, content)
|
||||||
|
|
||||||
|
with open(file_path, 'w') as f:
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def cli():
|
def cli():
|
||||||
"""AgentPress CLI - Initialize your AgentPress modules"""
|
"""AgentPress CLI - Initialize your AgentPress modules"""
|
||||||
|
@ -185,6 +199,21 @@ def init():
|
||||||
components_dir_path = os.path.abspath(components_dir)
|
components_dir_path = os.path.abspath(components_dir)
|
||||||
copy_module_files(package_dir, components_dir_path, all_files)
|
copy_module_files(package_dir, components_dir_path, all_files)
|
||||||
|
|
||||||
|
# Update paths in thread_manager.py and state_manager.py
|
||||||
|
project_dir = os.getcwd()
|
||||||
|
thread_manager_path = os.path.join(components_dir_path, "thread_manager.py")
|
||||||
|
state_manager_path = os.path.join(components_dir_path, "state_manager.py")
|
||||||
|
|
||||||
|
if os.path.exists(thread_manager_path):
|
||||||
|
update_file_paths(thread_manager_path, {
|
||||||
|
'threads_dir: str = "threads"': f'threads_dir: str = "{os.path.join(project_dir, "threads")}"'
|
||||||
|
})
|
||||||
|
|
||||||
|
if os.path.exists(state_manager_path):
|
||||||
|
update_file_paths(state_manager_path, {
|
||||||
|
'store_file: str = "state.json"': f'store_file: str = "{os.path.join(project_dir, "state.json")}"'
|
||||||
|
})
|
||||||
|
|
||||||
# Copy example only if a valid example (not None) was selected
|
# Copy example only if a valid example (not None) was selected
|
||||||
if selected_example and selected_example in STARTER_EXAMPLES:
|
if selected_example and selected_example in STARTER_EXAMPLES:
|
||||||
click.echo(f"\n📝 Creating {selected_example}...")
|
click.echo(f"\n📝 Creating {selected_example}...")
|
||||||
|
@ -193,8 +222,8 @@ def init():
|
||||||
os.getcwd(), # Use current working directory
|
os.getcwd(), # Use current working directory
|
||||||
STARTER_EXAMPLES[selected_example]["files"]
|
STARTER_EXAMPLES[selected_example]["files"]
|
||||||
)
|
)
|
||||||
# Create workspace directory
|
# Create threads directory
|
||||||
os.makedirs(os.path.join(os.getcwd(), "workspace"), exist_ok=True)
|
os.makedirs(os.path.join(project_dir, "threads"), exist_ok=True)
|
||||||
|
|
||||||
click.echo("\n✨ Success! Your AgentPress is ready.")
|
click.echo("\n✨ Success! Your AgentPress is ready.")
|
||||||
click.echo(f"\n📁 Components created in: {click.style(components_dir_path, fg='green')}")
|
click.echo(f"\n📁 Components created in: {click.style(components_dir_path, fg='green')}")
|
||||||
|
|
|
@ -9,7 +9,7 @@ from agentpress.tool_registry import ToolRegistry
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
class ThreadManager:
|
class ThreadManager:
|
||||||
def __init__(self, threads_dir: str = 'threads'):
|
def __init__(self, threads_dir: str = "threads"):
|
||||||
self.threads_dir = threads_dir
|
self.threads_dir = threads_dir
|
||||||
self.tool_registry = ToolRegistry()
|
self.tool_registry = ToolRegistry()
|
||||||
os.makedirs(self.threads_dir, exist_ok=True)
|
os.makedirs(self.threads_dir, exist_ok=True)
|
||||||
|
|
Loading…
Reference in New Issue