@pipedream/serenity_ai_hub 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ import app from "../../serenity_ai_hub.app.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ export default {
5
+ key: "serenity_ai_hub-execute-agent",
6
+ name: "Execute Agent",
7
+ description: "Executes an agent by its code with the provided parameters. [See the documentation](https://docs.serenitystar.ai/docs/api/aihub/execute-agent-with-code/)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ annotations: {
11
+ readOnlyHint: false,
12
+ destructiveHint: false,
13
+ openWorldHint: true,
14
+ },
15
+ props: {
16
+ app,
17
+ agentCode: {
18
+ propDefinition: [
19
+ app,
20
+ "agentCode",
21
+ ],
22
+ },
23
+ message: {
24
+ type: "string",
25
+ label: "Message",
26
+ description: "The message to send to the agent",
27
+ },
28
+ culture: {
29
+ propDefinition: [
30
+ app,
31
+ "culture",
32
+ ],
33
+ },
34
+ chatId: {
35
+ type: "string",
36
+ label: "Chat ID",
37
+ description: "The ID of an existing conversation to continue. Leave empty to start a new conversation",
38
+ optional: true,
39
+ },
40
+ additionalParameters: {
41
+ type: "string[]",
42
+ label: "Additional Parameters",
43
+ description: "Array of additional parameters with `key` and `value` properties, or a JSON string representing that array. Example: `[{\"key\": \"param1\", \"value\": \"value1\"}]`",
44
+ optional: true,
45
+ },
46
+ },
47
+ async run({ $ }) {
48
+ const data = [
49
+ {
50
+ Key: "message",
51
+ Value: this.message,
52
+ },
53
+ ];
54
+
55
+ if (this.chatId) {
56
+ data.push({
57
+ Key: "chatId",
58
+ Value: this.chatId,
59
+ });
60
+ }
61
+
62
+ if (this.additionalParameters) {
63
+ const extra = utils.parseInputParameters(this.additionalParameters);
64
+ data.push(...extra.map((item) => ({
65
+ Key: item.key,
66
+ Value: item.value,
67
+ })));
68
+ }
69
+
70
+ const response = await this.app.executeAgent({
71
+ $,
72
+ agentCode: this.agentCode,
73
+ params: {
74
+ culture: this.culture,
75
+ },
76
+ data,
77
+ });
78
+
79
+ $.export("$summary", `Successfully executed agent \`${this.agentCode}\``);
80
+ return response;
81
+ },
82
+ };
@@ -0,0 +1,58 @@
1
+ import app from "../../serenity_ai_hub.app.mjs";
2
+
3
+ export default {
4
+ key: "serenity_ai_hub-get-all-agents",
5
+ name: "Get All Agents",
6
+ description: "Gets a list containing all agents. [See the documentation](https://docs.serenitystar.ai/docs/api/aihub/get-all-agents)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ readOnlyHint: true,
11
+ destructiveHint: false,
12
+ openWorldHint: true,
13
+ },
14
+ props: {
15
+ app,
16
+ term: {
17
+ type: "string",
18
+ label: "Search Term",
19
+ description: "Filter agents by a search term",
20
+ optional: true,
21
+ },
22
+ culture: {
23
+ propDefinition: [
24
+ app,
25
+ "culture",
26
+ ],
27
+ },
28
+ max: {
29
+ type: "integer",
30
+ label: "Max Results",
31
+ description: "Maximum number of agents to return. Defaults to `100`",
32
+ optional: true,
33
+ },
34
+ },
35
+ async run({ $ }) {
36
+ const {
37
+ app,
38
+ max,
39
+ term,
40
+ culture,
41
+ } = this;
42
+
43
+ const agents = await app.getPaginatedResources({
44
+ resourcesFn: app.getAllAgents,
45
+ resourcesFnArgs: {
46
+ $,
47
+ params: {
48
+ term,
49
+ culture,
50
+ },
51
+ },
52
+ max,
53
+ });
54
+
55
+ $.export("$summary", `Successfully retrieved \`${agents.length}\` agent(s)`);
56
+ return agents;
57
+ },
58
+ };
@@ -0,0 +1,67 @@
1
+ import app from "../../serenity_ai_hub.app.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ export default {
5
+ key: "serenity_ai_hub-get-initial-conversation-info",
6
+ name: "Get Initial Conversation Info",
7
+ description: "Gets initial conversation information. [See the documentation](https://docs.serenitystar.ai/docs/api/aihub/get-initial-conversation-info-by-agent-code)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ annotations: {
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ openWorldHint: true,
14
+ },
15
+ props: {
16
+ app,
17
+ agentCode: {
18
+ propDefinition: [
19
+ app,
20
+ "agentCode",
21
+ ],
22
+ },
23
+ culture: {
24
+ propDefinition: [
25
+ app,
26
+ "culture",
27
+ ],
28
+ },
29
+ userIdentifier: {
30
+ type: "string",
31
+ label: "User Identifier",
32
+ description: "An identifier for the user",
33
+ optional: true,
34
+ },
35
+ inputParameters: {
36
+ type: "string[]",
37
+ label: "Input Parameters",
38
+ description: "Array of input parameters with `key` and `value` properties, or a JSON string representing that array. Example: `[{\"key\": \"param1\", \"value\": \"value1\"}]`",
39
+ optional: true,
40
+ },
41
+ channel: {
42
+ type: "string",
43
+ label: "Channel",
44
+ description: "Optional channel information",
45
+ optional: true,
46
+ },
47
+ },
48
+ async run({ $ }) {
49
+ const response = await this.app.getConversationInfo({
50
+ $,
51
+ agentCode: this.agentCode,
52
+ params: {
53
+ culture: this.culture,
54
+ },
55
+ data: {
56
+ userIdentifier: this.userIdentifier,
57
+ inputParameters: this.inputParameters
58
+ ? utils.parseInputParameters(this.inputParameters)
59
+ : undefined,
60
+ channel: this.channel,
61
+ },
62
+ });
63
+
64
+ $.export("$summary", `Successfully retrieved conversation info for agent \`${this.agentCode}\``);
65
+ return response;
66
+ },
67
+ };
@@ -0,0 +1,7 @@
1
+ const DEFAULT_MAX = 100;
2
+ const DEFAULT_LIMIT = 20;
3
+
4
+ export default {
5
+ DEFAULT_MAX,
6
+ DEFAULT_LIMIT,
7
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Parses input parameters into the API's key-value pair format.
3
+ * Accepts either a JSON string (e.g. `'[{"key":"k","value":"v"}]'` or `'[]'`)
4
+ * or an array of objects with `key` and `value` properties.
5
+ * @param {string | { key: string, value: string }[]} params
6
+ * @returns {{ key: string, value: string }[]}
7
+ */
8
+ const parseInputParameters = (params) => {
9
+ const parsed = typeof params === "string"
10
+ ? JSON.parse(params)
11
+ : params;
12
+
13
+ if (!Array.isArray(parsed)) {
14
+ throw new Error("Expected an array of objects with `key` and `value` properties");
15
+ }
16
+
17
+ return parsed.map((item, index) => {
18
+ const entry = typeof item === "string"
19
+ ? JSON.parse(item)
20
+ : item;
21
+ if (entry?.key === undefined || entry?.key === null) {
22
+ throw new Error(`Item at index ${index} is missing the \`key\` property`);
23
+ }
24
+ if (entry?.value === undefined || entry?.value === null) {
25
+ throw new Error(`Item at index ${index} is missing the \`value\` property`);
26
+ }
27
+ return {
28
+ key: entry.key,
29
+ value: entry.value,
30
+ };
31
+ });
32
+ };
33
+
34
+ export default {
35
+ parseInputParameters,
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/serenity_ai_hub",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Serenity* AI Hub Components",
5
5
  "main": "serenity_ai_hub.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.2.5"
14
17
  }
15
18
  }
@@ -1,11 +1,128 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import constants from "./common/constants.mjs";
3
+
1
4
  export default {
2
5
  type: "app",
3
6
  app: "serenity_ai_hub",
4
- propDefinitions: {},
7
+ propDefinitions: {
8
+ agentCode: {
9
+ type: "string",
10
+ label: "Agent Code",
11
+ description: "The unique identifier code of the agent",
12
+ async options({ page }) {
13
+ const response = await this.getAllAgents({
14
+ params: {
15
+ page: page + 1,
16
+ pageSize: 20,
17
+ },
18
+ });
19
+ const agents = response?.items ?? [];
20
+ return agents.map((agent) => ({
21
+ label: agent.name || agent.code,
22
+ value: agent.code,
23
+ }));
24
+ },
25
+ },
26
+ culture: {
27
+ type: "string",
28
+ label: "Culture",
29
+ description: "Overrides the response language",
30
+ optional: true,
31
+ options: [
32
+ {
33
+ label: "English",
34
+ value: "en",
35
+ },
36
+ {
37
+ label: "Spanish",
38
+ value: "es",
39
+ },
40
+ ],
41
+ },
42
+ },
5
43
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
44
+ getUrl(path) {
45
+ return `https://api.serenitystar.ai/api/v2${path}`;
46
+ },
47
+ getHeaders(headers) {
48
+ return {
49
+ "content-type": "application/json-patch+json",
50
+ "x-api-key": this.$auth.api_key,
51
+ ...headers,
52
+ };
53
+ },
54
+ _makeRequest({
55
+ $ = this, path, headers, ...opts
56
+ }) {
57
+ return axios($, {
58
+ url: this.getUrl(path),
59
+ headers: this.getHeaders(headers),
60
+ ...opts,
61
+ });
62
+ },
63
+ getAllAgents(opts = {}) {
64
+ return this._makeRequest({
65
+ path: "/agent",
66
+ ...opts,
67
+ });
68
+ },
69
+ getConversationInfo({
70
+ agentCode, ...opts
71
+ }) {
72
+ return this._makeRequest({
73
+ path: `/Agent/${agentCode}/conversation/info`,
74
+ method: "POST",
75
+ ...opts,
76
+ });
77
+ },
78
+ executeAgent({
79
+ agentCode, ...opts
80
+ }) {
81
+ return this._makeRequest({
82
+ path: `/agent/${agentCode}/execute`,
83
+ method: "POST",
84
+ ...opts,
85
+ });
86
+ },
87
+ async getPaginatedResources(args) {
88
+ const items = [];
89
+ for await (const item of this.paginate(args)) {
90
+ items.push(item);
91
+ }
92
+ return items;
93
+ },
94
+ async *paginate({
95
+ resourcesFn, resourcesFnArgs, max = constants.DEFAULT_MAX,
96
+ }) {
97
+ let page = 1;
98
+ let count = 0;
99
+ const pageSize = constants.DEFAULT_LIMIT;
100
+
101
+ while (true) {
102
+ const response = await resourcesFn({
103
+ ...resourcesFnArgs,
104
+ params: {
105
+ ...resourcesFnArgs?.params,
106
+ page,
107
+ pageSize,
108
+ },
109
+ });
110
+
111
+ const items = response?.items ?? [];
112
+
113
+ for (const item of items) {
114
+ yield item;
115
+ count++;
116
+ if (max && count >= max) {
117
+ return;
118
+ }
119
+ }
120
+
121
+ if (items.length < pageSize) {
122
+ return;
123
+ }
124
+ page++;
125
+ }
9
126
  },
10
127
  },
11
- };
128
+ };