foobara-agent-cli 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/src/foobara/agent.rb +1 -1
- data/src/foobara/cli_runner.rb +53 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022f075a6a285b82c16fe16b9b275d408420b64a4536bfec012dde9accdf96b5
|
4
|
+
data.tar.gz: 265bb11c607742f5c49313786d3ebc7f131e20ca13653f0fdeac734391a5602f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7bbffda354cfee3922569a507944c0b392ac4a1f0b4c123b7a581b3b074fed6a7beb09b70c155f5005f01c0a3bc5293f8188edbccb01bb044b1e95c7d398d1c
|
7
|
+
data.tar.gz: db97a6f637ea354ce4133a445ab587e73b6f697d528ab7015784977dded8f603d4a89cf9b933d8e84fa77fceb81daa1fb3f53ba4ed9189d3bcd94419461b48e4
|
data/src/foobara/agent.rb
CHANGED
data/src/foobara/cli_runner.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Foobara
|
2
|
-
class Agent
|
2
|
+
class Agent < CommandConnector
|
3
3
|
class CliRunner
|
4
4
|
attr_accessor :io_in, :io_out, :io_err, :agent
|
5
5
|
|
@@ -11,10 +11,8 @@ module Foobara
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def run
|
14
|
-
|
15
|
-
|
16
|
-
"\nWelcome to the Foobara Agent CLI! Type your goal and press enter to get started.\n\n> "
|
17
|
-
)
|
14
|
+
print_welcome_message
|
15
|
+
print_prompt
|
18
16
|
|
19
17
|
loop do
|
20
18
|
ready = Util.pipe_wait_readable(io_in, 1)
|
@@ -30,22 +28,19 @@ module Foobara
|
|
30
28
|
|
31
29
|
goal = line.strip
|
32
30
|
|
33
|
-
|
31
|
+
if goal =~ /\A\/?(exit|quit|bye)\z/i
|
32
|
+
print_agent_message("Goodbye for now!")
|
33
|
+
agent.kill!
|
34
|
+
break
|
35
|
+
end
|
36
|
+
|
34
37
|
next if goal.empty?
|
35
38
|
|
36
39
|
begin
|
40
|
+
print_agent_message("On it...")
|
37
41
|
outcome = agent.accomplish_goal(goal)
|
38
|
-
|
39
|
-
|
40
|
-
result = outcome.result
|
41
|
-
Util.pipe_writeline(io_out, "\nAgent says: #{result[:message_to_user]}\n")
|
42
|
-
else
|
43
|
-
# :nocov:
|
44
|
-
Util.pipe_writeline(io_err, "\nError: #{outcome.errors_hash}\n")
|
45
|
-
# :nocov:
|
46
|
-
end
|
47
|
-
|
48
|
-
Util.pipe_write_with_flush(io_out, "\n> ")
|
42
|
+
print_outcome(outcome)
|
43
|
+
print_prompt
|
49
44
|
rescue => e
|
50
45
|
# :nocov:
|
51
46
|
Util.pipe_writeline(io_err, e.message)
|
@@ -54,6 +49,47 @@ module Foobara
|
|
54
49
|
end
|
55
50
|
end
|
56
51
|
end
|
52
|
+
|
53
|
+
def print_welcome_message
|
54
|
+
welcome_message = if agent_name
|
55
|
+
"Welcome! I am #{agent_name}!"
|
56
|
+
else
|
57
|
+
"Welcome to the Foobara Agent CLI!"
|
58
|
+
end
|
59
|
+
|
60
|
+
welcome_message << " What would you like me to attempt to accomplish?"
|
61
|
+
|
62
|
+
Util.pipe_writeline(io_out, "\n#{welcome_message}\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_prompt
|
66
|
+
Util.pipe_write_with_flush(io_out, "\n> ")
|
67
|
+
end
|
68
|
+
|
69
|
+
def print_outcome(outcome)
|
70
|
+
message, stream = if outcome.success?
|
71
|
+
[outcome.result[:message_to_user], io_out]
|
72
|
+
else
|
73
|
+
# :nocov:
|
74
|
+
["ERROR: #{outcome.errors_hash}", io_err]
|
75
|
+
# :nocov:
|
76
|
+
end
|
77
|
+
|
78
|
+
print_agent_message(message, stream)
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_agent_message(message, stream = io_out)
|
82
|
+
name = agent_name || "Agent"
|
83
|
+
Util.pipe_writeline(stream, "\n#{name} says: #{message}\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def agent_name
|
87
|
+
name = agent.agent_name
|
88
|
+
|
89
|
+
if name && !name.empty?
|
90
|
+
name
|
91
|
+
end
|
92
|
+
end
|
57
93
|
end
|
58
94
|
end
|
59
95
|
end
|