feat: Implement daemon support for piping LLM output to stdout or clipboard via an extended socket protocol and update project documentation.
This commit is contained in:
@@ -77,18 +77,21 @@ public static class DaemonService
|
||||
{
|
||||
try
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var buffer = new byte[3];
|
||||
int bytesRead = await client.ReceiveAsync(buffer, SocketFlags.None);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
byte cmd = buffer[0];
|
||||
bool pipeToStdout = bytesRead > 1 && buffer[1] == 1;
|
||||
bool copyToClipboard = bytesRead > 2 && buffer[2] == 1;
|
||||
|
||||
if (cmd == 1) // START
|
||||
{
|
||||
await ProcessStartRecordingAsync();
|
||||
}
|
||||
else if (cmd == 2) // STOP
|
||||
{
|
||||
await ProcessStopRecordingAsync();
|
||||
await ProcessStopRecordingAsync(client, pipeToStdout, copyToClipboard);
|
||||
}
|
||||
else if (cmd == 3) // ABORT
|
||||
{
|
||||
@@ -97,7 +100,7 @@ public static class DaemonService
|
||||
else if (cmd == 4) // TOGGLE
|
||||
{
|
||||
if (StateTracker.IsRecording())
|
||||
await ProcessStopRecordingAsync();
|
||||
await ProcessStopRecordingAsync(client, pipeToStdout, copyToClipboard);
|
||||
else
|
||||
await ProcessStartRecordingAsync();
|
||||
}
|
||||
@@ -123,7 +126,7 @@ public static class DaemonService
|
||||
AudioRecorder.StartRecording();
|
||||
}
|
||||
|
||||
private static async Task ProcessStopRecordingAsync()
|
||||
private static async Task ProcessStopRecordingAsync(Socket client, bool pipeToStdout, bool copyToClipboard)
|
||||
{
|
||||
if (!StateTracker.IsRecording()) return;
|
||||
|
||||
@@ -173,9 +176,31 @@ public static class DaemonService
|
||||
{
|
||||
Logger.LogDebug("Starting LLM text refinement (streaming)...");
|
||||
var tokenStream = _groqClient.RefineTextStreamAsync(transcript, systemPrompt, config.LlmModel);
|
||||
await TextInjector.InjectStreamAsync(tokenStream, config.TypingBackend);
|
||||
stopWatch.Stop();
|
||||
Notifications.Notify("Toak", $"Done in {stopWatch.ElapsedMilliseconds}ms");
|
||||
|
||||
if (pipeToStdout || copyToClipboard)
|
||||
{
|
||||
string fullText = "";
|
||||
await foreach (var token in tokenStream)
|
||||
{
|
||||
fullText += token;
|
||||
if (pipeToStdout)
|
||||
{
|
||||
await client.SendAsync(System.Text.Encoding.UTF8.GetBytes(token), SocketFlags.None);
|
||||
}
|
||||
}
|
||||
stopWatch.Stop();
|
||||
if (copyToClipboard)
|
||||
{
|
||||
ClipboardManager.Copy(fullText);
|
||||
Notifications.Notify("Toak", $"Copied to clipboard in {stopWatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await TextInjector.InjectStreamAsync(tokenStream, config.TypingBackend);
|
||||
stopWatch.Stop();
|
||||
Notifications.Notify("Toak", $"Done in {stopWatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user