refactor: address final code review comments
Co-authored-by: abhi1693 <5083532+abhi1693@users.noreply.github.com>
This commit is contained in:
@@ -49,6 +49,16 @@ from app.services.openclaw.shared import GatewayAgentIdentity
|
|||||||
|
|
||||||
_T = TypeVar("_T")
|
_T = TypeVar("_T")
|
||||||
|
|
||||||
|
# Files that can be edited via the agent file management API
|
||||||
|
EDITABLE_AGENT_FILES = {
|
||||||
|
"IDENTITY.md",
|
||||||
|
"SOUL.md",
|
||||||
|
"BOOTSTRAP.md",
|
||||||
|
"AGENTS.md",
|
||||||
|
"TOOLS.md",
|
||||||
|
"HEARTBEAT.md",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class AbstractGatewayMessagingService(OpenClawDBService, ABC):
|
class AbstractGatewayMessagingService(OpenClawDBService, ABC):
|
||||||
"""Shared gateway messaging primitives with retry semantics."""
|
"""Shared gateway messaging primitives with retry semantics."""
|
||||||
@@ -470,25 +480,17 @@ class GatewayCoordinationService(AbstractGatewayMessagingService):
|
|||||||
else:
|
else:
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
# Define editable files
|
|
||||||
editable_files = {
|
|
||||||
"IDENTITY.md",
|
|
||||||
"SOUL.md",
|
|
||||||
"BOOTSTRAP.md",
|
|
||||||
"AGENTS.md",
|
|
||||||
"TOOLS.md",
|
|
||||||
"HEARTBEAT.md",
|
|
||||||
}
|
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
if isinstance(files, list):
|
if isinstance(files, list):
|
||||||
for file in files:
|
for file in files:
|
||||||
if isinstance(file, str):
|
if isinstance(file, str):
|
||||||
result.append({"name": file, "editable": file in editable_files})
|
result.append({"name": file, "editable": file in EDITABLE_AGENT_FILES})
|
||||||
elif isinstance(file, dict):
|
elif isinstance(file, dict):
|
||||||
name = file.get("name", "")
|
name = file.get("name", "")
|
||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
result.append({"name": name, "editable": name in editable_files})
|
result.append(
|
||||||
|
{"name": name, "editable": name in EDITABLE_AGENT_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"gateway.coordination.files_list.success trace_id=%s board_id=%s target_agent_id=%s "
|
"gateway.coordination.files_list.success trace_id=%s board_id=%s target_agent_id=%s "
|
||||||
@@ -608,14 +610,17 @@ class GatewayCoordinationService(AbstractGatewayMessagingService):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Update database fields for specific files
|
# Update database fields for specific files
|
||||||
|
db_updated = False
|
||||||
if filename == "SOUL.md":
|
if filename == "SOUL.md":
|
||||||
target.soul_template = normalized_content
|
target.soul_template = normalized_content
|
||||||
target.updated_at = utcnow()
|
target.updated_at = utcnow()
|
||||||
self.session.add(target)
|
db_updated = True
|
||||||
await self.session.commit()
|
|
||||||
elif filename == "IDENTITY.md":
|
elif filename == "IDENTITY.md":
|
||||||
target.identity_template = normalized_content
|
target.identity_template = normalized_content
|
||||||
target.updated_at = utcnow()
|
target.updated_at = utcnow()
|
||||||
|
db_updated = True
|
||||||
|
|
||||||
|
if db_updated:
|
||||||
self.session.add(target)
|
self.session.add(target)
|
||||||
await self.session.commit()
|
await self.session.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -99,16 +99,16 @@ export default function AgentFilesPage() {
|
|||||||
`/api/v1/agent/boards/${agent.board_id}/agents/${agentId}/files/${fileName}`,
|
`/api/v1/agent/boards/${agent.board_id}/agents/${agentId}/files/${fileName}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
Accept: "text/plain",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to load file: ${response.statusText}`);
|
throw new Error(`Failed to load file: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
const content = await response.text();
|
const fileContent = await response.text();
|
||||||
setSelectedFile(fileName);
|
setSelectedFile(fileName);
|
||||||
setFileContent(content);
|
setFileContent(fileContent);
|
||||||
setEditDialogOpen(true);
|
setEditDialogOpen(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : "Failed to load file");
|
setError(err instanceof Error ? err.message : "Failed to load file");
|
||||||
|
|||||||
Reference in New Issue
Block a user