ironbay / jarvis

A pluggable AI to manage all the redundant tasks in your life
1 stars 0 forks source link

Distributed Jarvis Spec #1

Open thdxr opened 9 years ago

thdxr commented 9 years ago

Example in pseudocode

API

registerRegexModel string:regex, string:modelType

registerStringable string:modelType, string:template

subscribeModel string:modelType -> string:modelType, obj:model, obj:context

subscribeContext string:contextType -> string:modelType, obj:model, obj:context

subscribeStringableContext string:contextType -> string:modelType, string: message, obj:context

emitModel string:modelType, obj:model, obj:context

emitString string:message, obj:context

// Will do a shallow check on the context object to see if new emitted models are a match and then release
waitFor string:modelType, obj:context -> obj:model, obj: context

Hangout Microservice

module Hangout

    async for type, message, context = Jarvis.subscribeStringableContext("hangouts")
        Hangout.send(context.group, context.user + ": " + message)

    async for user, group, message = Hangout.listenMessages
        Jarvis.emitString(message, { type : "hangouts", user : user, group : group })

endmodule

Weather Microservice

module Weather

    Jarvis.registerStringable("event.weather", "It is $status and $temperature degrees in $location")
    Jarvis.registerRegexModel("how is the weather in (<location>.+) ", "request.weather")

    for model, context = Jarvis.subscribeModel("request.weather") 
        result = { status : 'sunny', temperature : 50, location : model.location }
        Jarvis.emitModel("event.weather", result, context)
endmodule
thdxr commented 9 years ago

Conversation Microservice

module Conversation

    Jarvis.registerRegexModel("conversation.hello", "^hello$")
    Jarvis.registerRegexModel("conversation.status", "^how are you$")
    Jarvis.registerStringable('conversation.response", "$message")

    async for model, context = Jarvis.subscribeModel("conversation.hello")
        Jarvis.emitModel("conversation.response", { message : "hello"}, context)
        next, context = Jarvis.waitFor("conversation.status", context)
        Jarvis.emitModel("conversation.response", { message : "I'm great"}, context)

endmodule