152 lines
4.8 KiB
Java
152 lines
4.8 KiB
Java
/*******************************************************************************
|
|
* Imixs Workflow
|
|
* Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,
|
|
* http://www.imixs.com
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You can receive a copy of the GNU General Public
|
|
* License at http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
* Project:
|
|
* http://www.imixs.org
|
|
* http://java.net/projects/imixs-workflow
|
|
*
|
|
* Contributors:
|
|
* Imixs Software Solutions GmbH - initial API and implementation
|
|
* Ralph Soika - Software Developer
|
|
*******************************************************************************/
|
|
|
|
package ai.dynamixs.a2a;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import org.imixs.workflow.ItemCollection;
|
|
import org.imixs.workflow.ModelManager;
|
|
import org.imixs.workflow.engine.ModelService;
|
|
import org.imixs.workflow.engine.WorkflowService;
|
|
import org.imixs.workflow.exceptions.ModelException;
|
|
import org.imixs.workflow.exceptions.PluginException;
|
|
import org.openbpmn.bpmn.BPMNModel;
|
|
|
|
import jakarta.annotation.security.DeclareRoles;
|
|
import jakarta.annotation.security.RolesAllowed;
|
|
import jakarta.ejb.LocalBean;
|
|
import jakarta.ejb.Stateless;
|
|
import jakarta.inject.Inject;
|
|
|
|
/**
|
|
* The A2ASkillService parses the model information to provide A2ASkillCards
|
|
*
|
|
* @author rsoika
|
|
*/
|
|
@DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS",
|
|
"org.imixs.ACCESSLEVEL.READERACCESS",
|
|
"org.imixs.ACCESSLEVEL.AUTHORACCESS",
|
|
"org.imixs.ACCESSLEVEL.EDITORACCESS",
|
|
"org.imixs.ACCESSLEVEL.MANAGERACCESS" })
|
|
@RolesAllowed({ "org.imixs.ACCESSLEVEL.NOACCESS",
|
|
"org.imixs.ACCESSLEVEL.READERACCESS",
|
|
"org.imixs.ACCESSLEVEL.AUTHORACCESS",
|
|
"org.imixs.ACCESSLEVEL.EDITORACCESS",
|
|
"org.imixs.ACCESSLEVEL.MANAGERACCESS" })
|
|
@Stateless
|
|
@LocalBean
|
|
public class A2ASkillService {
|
|
|
|
@Inject
|
|
ModelService modelService;
|
|
|
|
@Inject
|
|
WorkflowService workflowService;
|
|
|
|
private static Logger logger = Logger.getLogger(A2ASkillService.class
|
|
.getName());
|
|
|
|
/**
|
|
* This method iterates over all models and returns a list of skill card objects
|
|
*
|
|
* The method tests if a event has a <imixs-ai name="SKILL"> tag.
|
|
*
|
|
*/
|
|
public List<A2ASkillCard> parseModels() {
|
|
logger.log(Level.INFO, "├── 🔃 parsing A2A SkillCards....");
|
|
List<A2ASkillCard> result = new ArrayList<>();
|
|
ModelManager modelManager = new ModelManager(workflowService);
|
|
List<String> versions = modelService.getVersions();
|
|
|
|
try {
|
|
|
|
for (String version : versions) {
|
|
logger.log(Level.INFO, "│ ├── {0}", version);
|
|
BPMNModel model = modelManager.getModel(version);
|
|
|
|
Set<String> groups = modelManager.findAllGroupsByModel(model);
|
|
for (String group : groups) {
|
|
List<ItemCollection> tasks = modelManager.findTasks(model, group);
|
|
for (ItemCollection task : tasks) {
|
|
int taskID = task.getItemValueInteger("taskid");
|
|
List<ItemCollection> events = modelManager.findEventsByTask(model, taskID);
|
|
|
|
for (ItemCollection event : events) {
|
|
int eventID = event.getItemValueInteger("eventid");
|
|
// test if we have a <imixs-ai name="SKILL">
|
|
try {
|
|
List<ItemCollection> llmPromptDefinitions = workflowService.evalWorkflowResultXML(event,
|
|
"imixs-ai",
|
|
"SKILL", null, false);
|
|
// did we found a skill?
|
|
for (ItemCollection skillItemCol : llmPromptDefinitions) {
|
|
A2ASkillCard skillCard = new A2ASkillCard(version, taskID, eventID);
|
|
|
|
skillCard.setName(event.getItemValueString("name"));
|
|
skillCard.setDescription(skillItemCol.getItemValueString("description"));
|
|
String tags = skillItemCol.getItemValueString("tags");
|
|
if (tags != null && !tags.isBlank()) {
|
|
String[] parts = tags.split(",\\s*");
|
|
skillCard.setTags(Arrays.asList(parts));
|
|
}
|
|
|
|
skillCard.setExamples(skillItemCol.getItemValueList("example", String.class));
|
|
|
|
// skillCard.addMetadata("aea", versions);
|
|
|
|
if (skillCard.isValid()) {
|
|
result.add(skillCard);
|
|
}
|
|
|
|
}
|
|
|
|
} catch (PluginException e) {
|
|
// no match
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
} catch (ModelException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|