mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-16 03:41:41 +00:00
initial work on the code agent, almost works!
This commit is contained in:
parent
e6986bd5fc
commit
746c092d51
1 changed files with 38 additions and 0 deletions
38
app/models/agents/code_agent.rb
Normal file
38
app/models/agents/code_agent.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'date'
|
||||
require 'cgi'
|
||||
module Agents
|
||||
class CodeAgent < Agent
|
||||
def example_js
|
||||
<<-H
|
||||
function Agent(m, e, o, agent){
|
||||
this.memory = JSON.parse(m);
|
||||
this.events = JSON.parse(e);
|
||||
this.options = JSON.parse(o);
|
||||
this.agent = JSON.parse(agent);
|
||||
}
|
||||
Agent.prototype.print_memory = function(){
|
||||
return this.memory;
|
||||
}
|
||||
Agent.prototype.run = function(){
|
||||
//have access to this.memory, this.events, this.options, and this.agent;
|
||||
// do computation...
|
||||
//...
|
||||
var pd = JSON.stringify({hello: "doctor", dil: "chori"});
|
||||
create_event(pd);
|
||||
}
|
||||
H
|
||||
end
|
||||
def execute_js
|
||||
context = V8::Context.new
|
||||
context.eval(example_js)
|
||||
context.eval(options['code']) # should override the run function.
|
||||
#
|
||||
context["create_event"] = lambda {|payload| create_event :payload => {:no => "true"}}
|
||||
context.eval("a = new Agent(1,1,1,1)")
|
||||
context.eval("a.run();")
|
||||
context["create_event"] = lambda {|x,y| puts x; puts y; create_event payload: JSON.parse(y)}
|
||||
#cxt["create_event"] = lambda {|this, payload| puts a.inspect}
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue