Skip to content

Commit c141003

Browse files
123vivekrvick08
authored andcommitted
agents: remove temporary debug logs; fix manual import/export flows
- Frontend: Replace unsupported `read_text_file` with backend import/export; align filters to `.opcode.json` - Backend: Normalize BOM and trim whitespace on file import
1 parent 5871409 commit c141003

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src-tauri/src/commands/agents.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ pub async fn read_session_jsonl(session_id: &str, project_path: &str) -> Result<
179179
let session_file = project_dir.join(format!("{}.jsonl", session_id));
180180

181181
if !session_file.exists() {
182-
return Err(format!(
183-
"Session file not found: {}",
184-
session_file.display()
185-
));
182+
return Err(format!("Session file not found: {}", session_file.display()));
186183
}
187184

188185
match tokio::fs::read_to_string(&session_file).await {
@@ -1762,9 +1759,16 @@ pub async fn import_agent_from_file(
17621759
file_path: String,
17631760
) -> Result<Agent, String> {
17641761
// Read the file
1765-
let json_data =
1762+
let mut json_data =
17661763
std::fs::read_to_string(&file_path).map_err(|e| format!("Failed to read file: {}", e))?;
17671764

1765+
// Normalize potential BOM and whitespace issues
1766+
if json_data.starts_with('\u{feff}') {
1767+
json_data = json_data.trim_start_matches('\u{feff}').to_string();
1768+
}
1769+
// Also trim leading/trailing whitespace to avoid parse surprises
1770+
json_data = json_data.trim().to_string();
1771+
17681772
// Import the agent
17691773
import_agent(db, json_data).await
17701774
}

src/components/Agents.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,14 @@ export const Agents: React.FC = () => {
122122
try {
123123
const selected = await openDialog({
124124
filters: [
125-
{ name: 'JSON Files', extensions: ['json'] },
125+
{ name: 'opcode Agent', extensions: ['opcode.json', 'json'] },
126126
{ name: 'All Files', extensions: ['*'] }
127127
],
128128
multiple: false,
129129
});
130130

131131
if (selected) {
132-
const fileContent = await invoke<string>('read_text_file', { path: selected });
133-
const agentData = JSON.parse(fileContent);
134-
135-
const importedAgent = await api.importAgent(JSON.stringify(agentData));
132+
const importedAgent = await api.importAgentFromFile(selected as string);
136133
setToast({ message: `Imported agent: ${importedAgent.name}`, type: 'success' });
137134
loadAgents();
138135
}
@@ -145,18 +142,14 @@ export const Agents: React.FC = () => {
145142
const handleExportAgent = async (agent: Agent) => {
146143
try {
147144
const path = await save({
148-
defaultPath: `${agent.name}.json`,
145+
defaultPath: `${agent.name.toLowerCase().replace(/\s+/g, '-')}.opcode.json`,
149146
filters: [
150-
{ name: 'JSON Files', extensions: ['json'] }
147+
{ name: 'opcode Agent', extensions: ['opcode.json'] }
151148
]
152149
});
153150

154151
if (path && agent.id) {
155-
const agentData = await api.exportAgent(agent.id);
156-
await invoke('write_text_file', {
157-
path,
158-
contents: agentData
159-
});
152+
await invoke('export_agent_to_file', { id: agent.id, filePath: path });
160153
setToast({ message: `Exported agent: ${agent.name}`, type: 'success' });
161154
}
162155
} catch (error) {
@@ -461,4 +454,4 @@ export const Agents: React.FC = () => {
461454
</div>
462455
</div>
463456
);
464-
};
457+
};

0 commit comments

Comments
 (0)