Skip to content

Commit

Permalink
feat(shell): only publish docs for agents with DOCUMENTATION service
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Dec 5, 2024
1 parent 09d524d commit a4a8b5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/arl/fjage/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public AgentID add(String name, Agent agent) {
log.warning("Undefined agent name");
return null;
}
if (name.contains("-")) {
log.warning("Agent name '"+name+"' with special character '-' not supported");
return null;
}
AgentID aid = new AgentID(name);
aid.setType(agent.getClass().getName());
if (isDuplicate(aid)) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/arl/fjage/shell/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,19 @@ protected void extract(StringBuilder sb, int pos) {
* Build dynamic documentation by querying agents. Documentation may be
* cached for efficiency. If an agent wishes to avoid caching, it should
* return a documentation string that starts with "[no-cache]".
* <p>
* Agents with names with special characters (e.g. hyphen) are not
* queried for documentation. This is to cater for gateway agents that do not
* support any requests. Such agents should always use special characters in
* their advertised names.
*
* @param agent agent.
*/
protected void build(Agent agent) {
if (agent == null) return;
if (doc.size() > staticSize) doc.subList(staticSize, doc.size()).clear();
Container c = agent.getContainer();
AgentID[] agentIDs = c.getAgents();
AgentID[] agentIDs = c.agentsForService("org.arl.fjage.shell.Services.DOCUMENTATION");
for (AgentID a: agentIDs) {
String key = a.getName();
if (a.getType() != null) key += "::" + a.getType();
Expand All @@ -182,7 +187,7 @@ protected void build(Agent agent) {
ParameterReq req = new ParameterReq();
req.setRecipient(a);
req.get(new NamedParameter("__doc__"));
Message rsp = agent.request(req, 500);
Message rsp = agent.request(req, 1000);
if (rsp != null && rsp instanceof ParameterRsp) {
Object docstr = ((ParameterRsp)rsp).get(new NamedParameter("__doc__"));
if (docstr != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/arl/fjage/shell/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
* Services supported by fjage shell agents.
*/
public enum Services {
SHELL
SHELL,
DOCUMENTATION
}

0 comments on commit a4a8b5e

Please sign in to comment.