Skip to content

Commit 0d337d5

Browse files
committed
Execute Agent action + lots of improvements
1 parent e6ca146 commit 0d337d5

File tree

5 files changed

+86
-80
lines changed

5 files changed

+86
-80
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { getQuestionProps } from "../../common/utils.mjs";
2+
import app from "../../tess_ai_by_pareto.app.mjs";
3+
4+
export default {
5+
key: "tess_ai_by_pareto-execute-agent",
6+
name: "Execute AI Agent",
7+
description:
8+
"Executes an AI Agent (template) with the given input. [See the documentation](https://tess.pareto.io/api/swagger#/default/f13b3be7386ce63d99fa4bdee0cf6c95)",
9+
version: "0.0.{{ts}}",
10+
type: "action",
11+
props: {
12+
app,
13+
templateId: {
14+
propDefinition: [
15+
app,
16+
"templateId",
17+
],
18+
reloadProps: true,
19+
},
20+
},
21+
methods: {
22+
getQuestionProps,
23+
},
24+
async additionalProps() {
25+
const { questions } = await this.app.getTemplate(this.templateId);
26+
return this.getQuestionProps(questions);
27+
28+
},
29+
async run({ $ }) {
30+
/* eslint-disable no-unused-vars */
31+
const {
32+
app, templateId, getQuestionProps, ...data
33+
} = this;
34+
const response = await this.app.executeTemplate({
35+
$,
36+
templateId,
37+
data,
38+
});
39+
$.export(
40+
"$summary",
41+
`Executed AI agent ${response.id}`,
42+
);
43+
return response;
44+
},
45+
};

components/tess_ai_by_pareto/actions/execute-template/execute-template.mjs

Lines changed: 0 additions & 35 deletions
This file was deleted.

components/tess_ai_by_pareto/actions/search-ai-agents/search-ai-agents.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default {
1414
label: "Search Query",
1515
description:
1616
"Search agents (templates) by title, description and long description.",
17+
optional: true,
1718
},
1819
type: {
1920
type: "string",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export function getQuestionProps(questions) {
2+
function getQuestionPropType(type) {
3+
switch (type) {
4+
case "number":
5+
return "integer";
6+
default:
7+
return "string";
8+
}
9+
}
10+
11+
return (questions ?? []).reduce((obj, question) => {
12+
obj[question.name] = {
13+
type: getQuestionPropType(question.type),
14+
label: `Field: "${question.name}"`,
15+
description: `Type: \`${question.type}\`. Description: "${question.description}"`,
16+
options: question.options,
17+
optional: !question.required,
18+
};
19+
return obj;
20+
}, {});
21+
}

components/tess_ai_by_pareto/tess_ai_by_pareto.app.mjs

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ export default {
66
propDefinitions: {
77
templateId: {
88
type: "string",
9-
label: "AI Template ID",
10-
description: "The ID of the AI template to execute or retrieve details for.",
11-
async options() {
12-
const templates = await this.searchAiTemplates({
13-
query: "",
9+
label: "AI Agent ID",
10+
description: "The ID of the AI Agent (template) to execute.",
11+
useQuery: true,
12+
async options({
13+
page = 0, query,
14+
}) {
15+
const response = await this.searchTemplates({
16+
params: {
17+
page: page + 1,
18+
q: query || undefined,
19+
},
1420
});
15-
return templates.templates.map((template) => ({
16-
label: template.name,
21+
return response?.data?.map((template) => ({
22+
label: template.title,
1723
value: template.id,
1824
}));
1925
},
@@ -30,32 +36,6 @@ export default {
3036
}));
3137
},
3238
},
33-
typeFilter: {
34-
type: "string",
35-
label: "Template Type",
36-
description: "Filter templates by type (image, text, video).",
37-
optional: true,
38-
options: [
39-
{
40-
label: "Image",
41-
value: "image",
42-
},
43-
{
44-
label: "Text",
45-
value: "text",
46-
},
47-
{
48-
label: "Video",
49-
value: "video",
50-
},
51-
],
52-
},
53-
inputs: {
54-
type: "string[]",
55-
label: "Inputs",
56-
description: "An array of JSON strings representing inputs for the template execution.",
57-
optional: true,
58-
},
5939
},
6040
methods: {
6141
_baseUrl() {
@@ -73,28 +53,22 @@ export default {
7353
...otherOpts,
7454
});
7555
},
76-
async executeAiTemplate({
77-
templateId, inputs,
56+
async executeTemplate({
57+
templateId, ...args
7858
}) {
7959
return this._makeRequest({
8060
method: "POST",
81-
path: `/ai-templates/${templateId}/execute`,
82-
data: {
83-
inputs: inputs
84-
? inputs.map((input) => JSON.parse(input))
85-
: [],
86-
},
61+
path: `/templates/${templateId}/execute`,
62+
...args,
8763
});
8864
},
89-
async getAiTemplateDetails({ templateId }) {
65+
async getTemplate(templateId) {
9066
return this._makeRequest({
91-
method: "GET",
92-
path: `/ai-templates/${templateId}`,
67+
path: `/templates/${templateId}`,
9368
});
9469
},
9570
async searchTemplates(args) {
9671
return this._makeRequest({
97-
method: "GET",
9872
path: "/templates",
9973
...args,
10074
});

0 commit comments

Comments
 (0)