Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion LilAgents/ClaudeSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ClaudeSession {
private var lineBuffer = ""
private(set) var isRunning = false
private(set) var isBusy = false // true between send() and result
private var currentStreamingResponse = ""
private static var claudePath: String?
private static var shellEnvironment: [String: String]?

Expand Down Expand Up @@ -262,6 +263,7 @@ class ClaudeSession {
for block in content {
let blockType = block["type"] as? String ?? ""
if blockType == "text", let text = block["text"] as? String {
currentStreamingResponse += text
onText?(text)
} else if blockType == "tool_use" {
let toolName = block["name"] as? String ?? "Tool"
Expand Down Expand Up @@ -304,9 +306,13 @@ class ClaudeSession {

case "result":
isBusy = false
if let result = json["result"] as? String, !result.isEmpty {
let responseText = currentStreamingResponse.trimmingCharacters(in: .whitespacesAndNewlines)
if !responseText.isEmpty {
history.append(Message(role: .assistant, text: responseText))
} else if let result = json["result"] as? String, !result.isEmpty {
history.append(Message(role: .assistant, text: result))
}
currentStreamingResponse = ""
onTurnComplete?()

default:
Expand Down