Pre-release 0.44.152 · Geeklab225/CopilotForXcode@c9d0ce9 · GitHub
Skip to content

Commit c9d0ce9

Browse files
committed
Pre-release 0.44.152
1 parent 8770b9e commit c9d0ce9

26 files changed

Lines changed: 494 additions & 103 deletions

‎Core/Sources/ChatService/ChatService.swift‎

Lines changed: 91 additions & 62 deletions
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import ChatAPIService
2+
import ConversationServiceProvider
3+
import Foundation
4+
5+
/// Helper methods for updating tool call status in chat history
6+
/// Handles both main turn tool calls and subagent tool calls
7+
struct ToolCallStatusUpdater {
8+
/// Finds the message containing the tool call, handling both main turns and subturns
9+
static func findMessageContainingToolCall(
10+
_ toolCallRequest: ToolCallRequest?,
11+
conversationTurnTracking: ConversationTurnTrackingState,
12+
history: [ChatMessage]
13+
) async -> ChatMessage? {
14+
guard let request = toolCallRequest else { return nil }
15+
16+
// If this is a subturn, find the parent turn; otherwise use the request's turnId
17+
let turnIdToFind = conversationTurnTracking.turnParentMap[request.turnId] ?? request.turnId
18+
19+
return history.first(where: { $0.id == turnIdToFind && $0.role == .assistant })
20+
}
21+
22+
/// Searches for a tool call in agent rounds (including nested subagent rounds) and creates an update
23+
///
24+
/// Note: Parent turns can have multiple sequential subturns, but they don't appear simultaneously.
25+
/// Subturns are merged into the parent's last round's subAgentRounds array by ChatMemory.
26+
static func findAndUpdateToolCall(
27+
toolCallId: String,
28+
newStatus: AgentToolCall.ToolCallStatus,
29+
in agentRounds: [AgentRound]
30+
) -> AgentRound? {
31+
// First, search in main rounds (for regular tool calls)
32+
for round in agentRounds {
33+
if let toolCalls = round.toolCalls {
34+
for toolCall in toolCalls where toolCall.id == toolCallId {
35+
return AgentRound(
36+
roundId: round.roundId,
37+
reply: "",
38+
toolCalls: [
39+
AgentToolCall(
40+
id: toolCallId,
41+
name: toolCall.name,
42+
status: newStatus
43+
),
44+
]
45+
)
46+
}
47+
}
48+
}
49+
50+
// If not found in main rounds, search in subagent rounds (for subturn tool calls)
51+
// Subturns are nested under the parent round's subAgentRounds
52+
for round in agentRounds {
53+
guard let subAgentRounds = round.subAgentRounds else { continue }
54+
55+
for subRound in subAgentRounds {
56+
guard let toolCalls = subRound.toolCalls else { continue }
57+
58+
for toolCall in toolCalls where toolCall.id == toolCallId {
59+
// Create an update that will be merged into the parent's subAgentRounds
60+
// ChatMemory.appendMessage will handle the merging logic
61+
let subagentRound = AgentRound(
62+
roundId: subRound.roundId,
63+
reply: "",
64+
toolCalls: [
65+
AgentToolCall(
66+
id: toolCallId,
67+
name: toolCall.name,
68+
status: newStatus
69+
),
70+
]
71+
)
72+
return AgentRound(
73+
roundId: round.roundId,
74+
reply: "",
75+
toolCalls: [],
76+
subAgentRounds: [subagentRound]
77+
)
78+
}
79+
}
80+
}
81+
82+
return nil
83+
}
84+
85+
/// Creates a message update with the new tool call status
86+
static func createMessageUpdate(
87+
targetMessage: ChatMessage,
88+
updatedRound: AgentRound
89+
) -> ChatMessage {
90+
return ChatMessage(
91+
id: targetMessage.id,
92+
chatTabID: targetMessage.chatTabID,
93+
clsTurnID: targetMessage.clsTurnID,
94+
role: .assistant,
95+
content: "",
96+
references: [],
97+
steps: [],
98+
editAgentRounds: [updatedRound],
99+
turnStatus: .inProgress
100+
)
101+
}
102+
}

‎Core/Sources/ConversationTab/ModeAndModelPicker/ModePicker/AgentModeButton.swift‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ import Persist
44
import SharedUIComponents
55
import SwiftUI
66

7+
// MARK: - Custom NSButton that accepts clicks anywhere within its bounds
8+
class ClickThroughButton: NSButton {
9+
override func hitTest(_ point: NSPoint) -> NSView? {
10+
// If the point is within our bounds, return self (the button)
11+
// This ensures clicks on subviews are handled by the button
12+
if self.bounds.contains(point) {
13+
return self
14+
}
15+
return super.hitTest(point)
16+
}
17+
}
18+
719
// MARK: - Agent Mode Button
820

921
struct AgentModeButton: NSViewRepresentable {
@@ -33,7 +45,7 @@ struct AgentModeButton: NSViewRepresentable {
3345
let containerView = NSView()
3446
containerView.translatesAutoresizingMaskIntoConstraints = false
3547

36-
let button = NSButton()
48+
let button = ClickThroughButton()
3749
button.title = ""
3850
button.bezelStyle = .inline
3951
button.setButtonType(.momentaryPushIn)

‎Core/Sources/ConversationTab/ModeAndModelPicker/ModePicker/AgentModeButtonMenuItem.swift‎

Lines changed: 4 additions & 3 deletions

0 commit comments

Comments
 (0)