From 96f7c057447717c7701ccc37fdbfe4b3d711c5a4 Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 16 Jan 2026 07:06:45 -0400 Subject: [PATCH] Fix publish dialog sending dict instead of YAML string The publish_tool() API expects a YAML config string, but the dialog was passing a dict directly, causing a 500 error on the server. - Update PublishWorker to accept config_yaml string and readme - Build complete tool config from Tool.to_dict() - Convert to YAML string before sending - Also include README.md if it exists in tool directory Co-Authored-By: Claude Opus 4.5 --- src/cmdforge/gui/dialogs/publish_dialog.py | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/cmdforge/gui/dialogs/publish_dialog.py b/src/cmdforge/gui/dialogs/publish_dialog.py index 70c5451..06484dd 100644 --- a/src/cmdforge/gui/dialogs/publish_dialog.py +++ b/src/cmdforge/gui/dialogs/publish_dialog.py @@ -17,9 +17,10 @@ class PublishWorker(QThread): success = Signal(dict) error = Signal(str) - def __init__(self, tool_data: dict): + def __init__(self, config_yaml: str, readme: str = ""): super().__init__() - self.tool_data = tool_data + self.config_yaml = config_yaml + self.readme = readme def run(self): try: @@ -27,7 +28,7 @@ class PublishWorker(QThread): client = RegistryClient() client.token = config.registry.token - result = client.publish_tool(self.tool_data) + result = client.publish_tool(self.config_yaml, self.readme) self.success.emit(result) except Exception as e: self.error.emit(str(e)) @@ -127,6 +128,8 @@ class PublishDialog(QDialog): def _publish(self): """Publish the tool.""" + import yaml + version = self.version_input.text().strip() if not version: QMessageBox.warning(self, "Validation", "Version is required") @@ -140,22 +143,34 @@ class PublishDialog(QDialog): category = self.category_combo.currentText() tags = [t.strip() for t in self.tags_input.text().split(",") if t.strip()] - # Build tool data for publishing - tool_data = { - "name": self._tool.name, - "version": version, - "description": description, - "category": category, - "tags": tags, - "definition": self._tool.to_dict() if hasattr(self._tool, 'to_dict') else {} - } + # Build complete tool config from the Tool object + tool_config = self._tool.to_dict() if hasattr(self._tool, 'to_dict') else {} + + # Update with publish dialog values + tool_config["name"] = self._tool.name + tool_config["version"] = version + tool_config["description"] = description + tool_config["category"] = category + if tags: + tool_config["tags"] = tags + + # Convert to YAML string + config_yaml = yaml.dump(tool_config, default_flow_style=False, sort_keys=False) + + # Get README if it exists + readme = "" + tool_dir = self._tool.path.parent if hasattr(self._tool, 'path') and self._tool.path else None + if tool_dir: + readme_path = tool_dir / "README.md" + if readme_path.exists(): + readme = readme_path.read_text() self.btn_publish.setEnabled(False) self.btn_cancel.setEnabled(False) self.progress.show() self.status_label.setText("Publishing...") - self._worker = PublishWorker(tool_data) + self._worker = PublishWorker(config_yaml, readme) self._worker.success.connect(self._on_success) self._worker.error.connect(self._on_error) self._worker.start()