// NewAgentDialog.qml — Dialog for creating a new agent in a session import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 Dialog { id: root title: "New Agent" anchors.centerIn: parent width: 420 modal: true // Session ID to create the agent in property string targetSessionId: "" signal agentCreated() contentItem: ColumnLayout { spacing: 16 Layout.margins: 16 Label { text: "Agent" font.bold: true font.pointSize: theme.fontSize > 0 ? theme.fontSize + 1 : Qt.application.font.pointSize + 1 } Label { id: errorLabel Layout.fillWidth: true visible: text !== "" color: "red" wrapMode: Text.Wrap } RowLayout { Layout.fillWidth: true Label { text: "Directory:"; Layout.preferredWidth: 80 } TextField { id: dirField Layout.fillWidth: true placeholderText: "/path/to/project" } Button { text: "Browse..." onClicked: { var folder = theme.chooseFolder("Select Project Directory", dirField.text || "") if (folder !== "") dirField.text = folder } } } RowLayout { Layout.fillWidth: true Label { text: "Backend:"; Layout.preferredWidth: 80 } ComboBox { id: backendCombo Layout.fillWidth: true enabled: ollie.rootBackendsLoaded model: ollie.availableBackends currentIndex: 0 editable: true onAccepted: backendCombo.editText = backendCombo.currentText } } ListModel { id: modelList } RowLayout { Layout.fillWidth: true Label { text: "Model:"; Layout.preferredWidth: 80 } ComboBox { id: modelCombo Layout.fillWidth: true enabled: backendCombo.currentIndex >= 0 && backendCombo.currentText.trim() !== "" && ollie.rootModelsLoaded model: modelList currentIndex: -1 editable: true onAccepted: modelCombo.editText = modelCombo.currentText } } RowLayout { Layout.fillWidth: true Label { text: "Profile:"; Layout.preferredWidth: 80 } ComboBox { id: agentCombo Layout.fillWidth: true enabled: ollie.rootAgentsLoaded model: ollie.availableAgents currentIndex: 0 } } RowLayout { Layout.fillWidth: true Label { text: "Name:"; Layout.preferredWidth: 80 } TextField { id: aliasField Layout.fillWidth: true placeholderText: "(auto-generated)" } } Component.onCompleted: { if (!ollie.rootBackendsLoaded) ollie.loadRootBackends() if (!ollie.rootAgentsLoaded) ollie.loadRootAgents() } Connections { target: backendCombo function onCurrentTextChanged() { var be = backendCombo.currentText.trim() modelList.clear() if (be !== "" && ollie.rootModelsLoaded) { var models = ollie.getAvailableModels(be) for (var i = 0; i < models.length; ++i) { modelList.append({ modelData: models[i] }) } modelCombo.currentIndex = models.length > 0 ? 0 : -1 } else { modelCombo.currentIndex = -1 } } } } footer: RowLayout { Layout.fillWidth: true Item { Layout.fillWidth: true } Button { text: "OK" onClicked: { errorLabel.text = "" var cwd = dirField.text.trim() if (cwd === "") { errorLabel.text = "Directory is required" return } var backend = backendCombo.currentText.trim() var model = modelCombo.currentIndex >= 0 ? modelCombo.currentText.trim() : "" var agent = agentCombo.currentText var agentAlias = aliasField.text.trim() var newAgentId = ollie.createAgent(root.targetSessionId, cwd, backend, model, agent, "", agentAlias) var err = ollie.lastError() if (err === "") { // Success: refresh then switch to the newly created agent. ollie.refreshSessions() ollie.switchAgent(root.targetSessionId, newAgentId) root.agentCreated() root.close() } else { errorLabel.text = err } } } Button { text: "Cancel" onClicked: root.close() } } onOpened: { errorLabel.text = "" dirField.forceActiveFocus() } }