Skip to content

Commit 2572d96

Browse files
committed
listSkills sync action defining the available AI agent skills 🤖
eventually the response of this sync action shall be generated dynamically based on component configuration
1 parent bec13f2 commit 2572d96

File tree

2 files changed

+117
-9
lines changed

2 files changed

+117
-9
lines changed

‎.github/workflows/push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
TAG="${GITHUB_REF##*/}"
6868
IS_SEMANTIC_TAG=$(echo "$TAG" | grep -q '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' && echo true || echo false)
6969
echo "is_semantic_tag=$IS_SEMANTIC_TAG" | tee -a $GITHUB_OUTPUT
70-
echo "app_image_tag=$TAG" | tee -a $GITHUB_OUTPUT
70+
echo "app_image_tag=$TAG-${{ github.run_id }}" | tee -a $GITHUB_OUTPUT
7171
7272
- name: Deploy-Ready check
7373
id: deploy_ready

‎src/component.py

+116-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csv
2+
import json
23
import logging
34
import os
45
import shutil
@@ -86,7 +87,7 @@ class Component(ComponentBase):
8687
def __init__(self):
8788
super().__init__()
8889

89-
def run(self, return_data=False):
90+
def run(self, return_json=False):
9091
self.validate_configuration_parameters(REQUIRED_PARAMETERS)
9192
self.validate_image_parameters(REQUIRED_IMAGE_PARS)
9293

@@ -130,7 +131,15 @@ def run(self, return_data=False):
130131
logging.debug([result for result in results])
131132
logging.info(f"Downloaded {total_records} records in total")
132133

133-
if return_data:
134+
if return_json:
135+
for result in results:
136+
if "file" not in result:
137+
result["status"] = "fileError"
138+
continue
139+
result["records"] = list(self._csv_result_to_dict(result.pop("file")))
140+
result["status"] = "ok"
141+
with open("response.json", "w") as f:
142+
json.dump(results, f)
134143
return results
135144

136145
# remove headers and get columns
@@ -180,6 +189,12 @@ def _fix_header_from_csv(results: list[dict]) -> list[str]:
180189
os.replace(temp_file_path, result_file_path)
181190
return expected_header
182191

192+
def _csv_result_to_dict(self, filename: str):
193+
with open(filename) as f:
194+
reader = csv.DictReader(f)
195+
for row in reader:
196+
yield row
197+
183198
def set_proxy(self) -> None:
184199
"""Sets proxy if defined"""
185200
proxy_config = self.configuration.parameters.get(KEY_PROXY, {})
@@ -622,12 +637,105 @@ def load_possible_primary_keys(self) -> list[SelectElement]:
622637
else:
623638
raise UserException(f"Invalid {KEY_QUERY_TYPE}")
624639

625-
# @sync_action("runComponent")
626-
# def sync_run_component(self):
627-
# """
628-
# Run the component as a sync action
629-
# """
630-
# return self.run(return_data=True)
640+
@sync_action("runSkill")
641+
def sync_run_component(self):
642+
"""
643+
Run the component as a skill for an AI agent
644+
"""
645+
return self.run(return_json=True)
646+
647+
@sync_action("listSkills")
648+
def list_skills(self):
649+
return [
650+
{
651+
"name": "Get Salesforce contacts",
652+
"description": "Returns list of Salesforce contacts.",
653+
"parameters": [
654+
{
655+
"name": "action",
656+
"type": "string",
657+
"required": True,
658+
"enum": ["runSkill"],
659+
},
660+
{
661+
"name": "configData",
662+
"type": "object",
663+
"required": True,
664+
"parameters": [
665+
{
666+
"name": "object",
667+
"type": "string",
668+
"required": True,
669+
"enum": ["contacts"],
670+
"description": "String identifer of the agent skill to run.",
671+
},
672+
{
673+
"name": "username",
674+
"type": "string",
675+
"required": True,
676+
"description": "The Salesforce account username.",
677+
},
678+
{
679+
"name": "#password",
680+
"type": "string",
681+
"required": True,
682+
"description": "The Salesforce account password.",
683+
},
684+
{
685+
"name": "#securityToken",
686+
"type": "string",
687+
"required": True,
688+
"description": "Keboola project security token.",
689+
},
690+
],
691+
},
692+
],
693+
},
694+
{
695+
"name": "Get Salesforce reports",
696+
"description": "Returns list of Salesforce reports.",
697+
"parameters": [
698+
{
699+
"name": "action",
700+
"type": "string",
701+
"required": True,
702+
"enum": ["runSkill"],
703+
},
704+
{
705+
"name": "configData",
706+
"type": "object",
707+
"required": True,
708+
"parameters": [
709+
{
710+
"name": "object",
711+
"type": "string",
712+
"required": True,
713+
"enum": ["reports"],
714+
"description": "String identifer of the agent skill to run.",
715+
},
716+
{
717+
"name": "username",
718+
"type": "string",
719+
"required": True,
720+
"description": "The Salesforce account username.",
721+
},
722+
{
723+
"name": "#password",
724+
"type": "string",
725+
"required": True,
726+
"description": "The Salesforce account password.",
727+
},
728+
{
729+
"name": "#securityToken",
730+
"type": "string",
731+
"required": True,
732+
"description": "Keboola project security token.",
733+
},
734+
],
735+
},
736+
],
737+
},
738+
]
631739

632740
def _get_object_name_from_custom_query(self) -> str:
633741
params = self.configuration.parameters

0 commit comments

Comments
 (0)