Skip to content

Commit 490c781

Browse files
committed
Update ChatAgentResponse
1 parent 84244c0 commit 490c781

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

ChatPlugins/Sources/ShortcutChatPlugin/ShortcutChatPlugin.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ public final class ShortcutChatPlugin: ChatPlugin {
6262
task: "Run shortcut \(shortcutName)"
6363
))
6464

65-
let result = try await terminal.runCommand(
66-
shell,
67-
arguments: ["-i", "-l", "-c", command],
68-
currentDirectoryURL: nil,
69-
environment: [:]
70-
)
71-
72-
continuation.yield(.finishAction(id: "run", result: result))
65+
do {
66+
let result = try await terminal.runCommand(
67+
shell,
68+
arguments: ["-i", "-l", "-c", command],
69+
currentDirectoryURL: nil,
70+
environment: [:]
71+
)
72+
continuation.yield(.finishAction(id: "run", result: .success(result)))
73+
} catch {
74+
continuation.yield(.finishAction(
75+
id: "run",
76+
result: .failure(error.localizedDescription)
77+
))
78+
throw error
79+
}
7380

7481
await Task.yield()
7582
try Task.checkCancellation()

ChatPlugins/Sources/TerminalChatPlugin/TerminalChatPlugin.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public final class TerminalChatPlugin: ChatPlugin {
4242
id: "run",
4343
task: "Continue `\(request.text)`"
4444
))
45-
continuation.yield(.finishAction(id: "run", result: "Printing output..."))
45+
continuation.yield(.finishAction(
46+
id: "run",
47+
result: .success("Printing output...")
48+
))
4649
continuation.yield(.content(.text("[continue]\n")))
4750
continuation.yield(.content(.text(content)))
4851
} else {
@@ -76,7 +79,10 @@ public final class TerminalChatPlugin: ChatPlugin {
7679
environment: environment
7780
)
7881

79-
continuation.yield(.finishAction(id: "run", result: "Printing output..."))
82+
continuation.yield(.finishAction(
83+
id: "run",
84+
result: .success("Printing output...")
85+
))
8086

8187
for try await content in output {
8288
try Task.checkCancellation()

Tool/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ let package = Package(
355355
dependencies: [
356356
"XcodeInspector",
357357
"Preferences",
358+
"ChatBasic",
359+
"ModificationBasic",
358360
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
359361
]
360362
),

Tool/Sources/ChatBasic/ChatAgent.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ public enum ChatAgentResponse {
44
public enum Content {
55
case text(String)
66
}
7+
8+
public enum ActionResult {
9+
case success(String)
10+
case failure(String)
11+
}
712

813
/// Post the status of the current message.
914
case status([String])
@@ -14,7 +19,7 @@ public enum ChatAgentResponse {
1419
/// start a new action.
1520
case startAction(id: String, task: String)
1621
/// Finish the current action.
17-
case finishAction(id: String, result: String)
22+
case finishAction(id: String, result: ActionResult)
1823
/// Update the references of the current message.
1924
case references([ChatMessage.Reference])
2025
/// End the current message. The next contents will be sent as a new message.

0 commit comments

Comments
 (0)