gui: write name= to session/new, then agent params to session/{name}/agent/new
This commit is contained in:
parent
68a84a2404
commit
153b40cbc7
|
|
@ -268,22 +268,45 @@ bool Ollie9pClient::createSession(const QString &cwd, const QString &name, const
|
|||
{
|
||||
if (cwd.isEmpty()) return false;
|
||||
|
||||
QStringList args;
|
||||
args << "cwd=" + cwd;
|
||||
if (!name.isEmpty()) args << "name=" + name;
|
||||
if (!backend.isEmpty()) args << "backend=" + backend;
|
||||
if (!model.isEmpty()) args << "model=" + model;
|
||||
if (!agent.isEmpty()) args << "agent=" + agent;
|
||||
if (!remote.isEmpty()) args << "remote=" + remote;
|
||||
if (!agentAlias.isEmpty()) args << "agent_alias=" + agentAlias;
|
||||
// Step 1: Create the session (name only)
|
||||
QString sessName = name;
|
||||
{
|
||||
QProcess proc;
|
||||
QStringList args = {"-a", serverAddr(), "write", "session/new"};
|
||||
proc.start(ninepBin(), args);
|
||||
proc.waitForStarted(3000);
|
||||
QString input = "name=" + sessName;
|
||||
proc.write(input.toUtf8());
|
||||
proc.closeWriteChannel();
|
||||
proc.waitForFinished(5000);
|
||||
if (proc.exitCode() != 0) {
|
||||
QString err = QString::fromUtf8(proc.readAllStandardError()).trimmed();
|
||||
if (err.isEmpty())
|
||||
err = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
|
||||
qDebug() << "createSession (step 1) failed:" << err;
|
||||
return false;
|
||||
}
|
||||
// Read the returned session name (may be auto-generated)
|
||||
QByteArray out = proc.readAllStandardOutput().trimmed();
|
||||
if (!out.isEmpty())
|
||||
sessName = QString::fromUtf8(out);
|
||||
}
|
||||
|
||||
// Step 2: Create the agent within the session
|
||||
{
|
||||
QStringList agentArgs;
|
||||
agentArgs << "cwd=" + cwd;
|
||||
if (!backend.isEmpty()) agentArgs << "backend=" + backend;
|
||||
if (!model.isEmpty()) agentArgs << "model=" + model;
|
||||
if (!agent.isEmpty()) agentArgs << "agent=" + agent;
|
||||
if (!remote.isEmpty()) agentArgs << "remote=" + remote;
|
||||
if (!agentAlias.isEmpty()) agentArgs << "agent_alias=" + agentAlias;
|
||||
|
||||
QProcess proc;
|
||||
QStringList fullArgs = {"-a", serverAddr(), "write", "session/new"};
|
||||
proc.start(ninepBin(), fullArgs);
|
||||
QStringList args = {"-a", serverAddr(), "write", "session/" + sessName + "/agent/new"};
|
||||
proc.start(ninepBin(), args);
|
||||
proc.waitForStarted(3000);
|
||||
|
||||
QString input = args.join(" ");
|
||||
proc.write(input.toUtf8());
|
||||
proc.write(agentArgs.join(" ").toUtf8());
|
||||
proc.closeWriteChannel();
|
||||
proc.waitForFinished(5000);
|
||||
|
||||
|
|
@ -291,9 +314,17 @@ bool Ollie9pClient::createSession(const QString &cwd, const QString &name, const
|
|||
QString err = QString::fromUtf8(proc.readAllStandardError()).trimmed();
|
||||
if (err.isEmpty())
|
||||
err = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
|
||||
qDebug() << "createSession failed:" << err;
|
||||
qDebug() << "createSession (step 2) failed:" << err;
|
||||
// Clean up the session
|
||||
QProcess killProc;
|
||||
killProc.start(ninepBin(), {"-a", serverAddr(), "write", "session/" + sessName + "/ctl"});
|
||||
killProc.waitForStarted(3000);
|
||||
killProc.write("kill");
|
||||
killProc.closeWriteChannel();
|
||||
killProc.waitForFinished(3000);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue