AI WEB
This application provides HTTP way for interaction with other parts of system. For this time it uses websocket connection to utilize real-time events what happens in system. Websocket protocol
All interaction going via websocket and uses JSON-like messages. The common structure of input command:
{ cmd : 'some_command', params_for_command }
The common struсture of response:
{ type : type_of_response, some_other_data }
Example:
{"cmd":"run_code","code":"create_input(input, [agent1])\ncreate(agent1, [], [ plus_one, plus_one, plus_one, plus_one, ignore ], [\n agent1,\n create_display(display)\n])\n\nmessage_send(input, 1)\n "}
Response:
{ "type":"ok" }
Commands list
There are 2 commands: run_code
code : string - code what should be launched.
stop_code
no params
Responses
{ "type":"ok" } - the previous command was OK.
{ "type":"error", error: error_object } - the previous commands was not ok. error_object is description of error.
{ "type":"event", event: event_object } - event generated in system within process of execution script or working of AI NET.
Event_object describes event. Errors
Error_object describe error happened within process of execution of command.
Basic structure of error:
#{ type => error, error_code => Code, reason => Reason }.
Note: Document can contain description like above. We will think it is JSON. Events
Events shows to client some information what generated in system.
The basic structure of event object:
{ 'type' : type_of_event, other_data }
Type of event says to client what information it received. Client can recognise it and do something depends from event type.
The list of events type presented below: agent_create
Agent was created. Type is type of agent Id is name of agent
#{ event => agent_create, type => Type, id => Id };
agent_destroy
Agent was destroyed. Id is name of agent.
#{ type => agent_destroy, id => Id };
link_create
Link between agents was created. It is just for information. All agents able send informantion to any other agents. LInk just show you possible way of interaction. It desctibed in constructor of agent, who receives information from current agent.
From is sender of message.
To is receiver of message.
From and To can be same agent too.
#{ event => link_create, from => From, to => To };
display_it
Shows some information to client. Client can track type of agent from agent_create and can decide how it can show this information.
#{
event => display_it,
id => Id,
data => serialize(Data)
};
input_confirmation
Just confirmation, that input-agent got message from outside (when client sends something by code or by other API functions).
#{
event => input_confirmation,
id => Id
};
sending
Shows a fact of interaction between 2 agents.
From is sender.
To is receiver.
#{
type => sending,
from => From,
to => To
};
calculation
Shows a fact of calculation for agent.
#{
type => calculation,
agent => Agent,
operation => operation_object
};
Operation is desctiption of operation what was applied for data.
#{ id => Name, type => Module };
Id is name of operation. Type is module, type what shows what operation does. capture
When agent is capturing of result it will generate event with type capture.
#{ type => capture, agent => Agent, message => serialize(Message) };
release
When agent is release inputs it will generate event with type release.
#{ type => release, agent => Agent, inputs => Inputs };
note
Agent changes his own note list.
#{ type => note, agent => Agent, action => add | delete | fire note => Note };
where Inputs is list of messages. environment
Events from environment process.
#{ type => environment, name => Name, action => Action, data => serialize(Data) };
where:
name - name of environment (some identifier, for usage in future)
action - action for environment (as example: create, destroy)
data - specific data for action
Storage HTTP API
There is posiibility to put/delete/get files into server. Client should use REST API protocol for this.
The allowed methods:
GET (get file by path)
POST (put file by path)
DELETE (delete file by path)
Basic URL request is:
/storage/[some_path]
where [some_path] - path to file (with name for GET, DELETE), and without name for POST methods.
User can put [some_path] data to his scripts for AI NET as string. Read file
URI: /storage/path/path/filename.ext
METHOD: GET.
If path is file, it will send 200 OK with content of requested file. Header is presented: result = file_content
If path is directory it will send 200 OK with list of folders and files in JSON format. Header is presented: result = directory_list
If path is not exist then it will send 404 Not found Put file
URI: /storage/path/path/
METHOD: POST
Browser must send multipart-form data (enctype="multipart/form-data" in form tag) with 2 fields:
name - name of saved file
file - content of file
Response is 200 OK with path to file as body. Delete file
URI: /storage/path/path/filename.ext
METHOD: DELETE
Deletes file from server. If action is done, it is sending 200 OK
If file/directory is not found, it is sending 404 Not found